sing-box/common/dialer/dialer.go

32 lines
935 B
Go
Raw Normal View History

package dialer
import (
2022-07-08 04:58:43 +00:00
"time"
2022-07-06 07:01:09 +00:00
"github.com/sagernet/sing-box/adapter"
"github.com/sagernet/sing-box/option"
2022-07-11 10:44:59 +00:00
"github.com/sagernet/sing-dns"
2022-07-08 15:03:57 +00:00
"github.com/sagernet/sing/common"
N "github.com/sagernet/sing/common/network"
)
func New(router adapter.Router, options option.DialerOptions) N.Dialer {
if options.Detour == "" {
return NewDefault(router, options)
} else {
2022-07-07 15:36:32 +00:00
return NewDetour(router, options.Detour)
}
}
func NewOutbound(router adapter.Router, options option.OutboundDialerOptions) N.Dialer {
dialer := New(router, options.DialerOptions)
2022-07-11 10:44:59 +00:00
domainStrategy := dns.DomainStrategy(options.DomainStrategy)
if domainStrategy != dns.DomainStrategyAsIS || options.Detour == "" {
dialer = NewResolveDialer(router, dialer, domainStrategy, time.Duration(options.FallbackDelay))
}
if options.OverrideOptions.IsValid() {
2022-07-06 15:11:48 +00:00
dialer = NewOverride(dialer, common.PtrValueOrDefault(options.OverrideOptions))
}
return dialer
}