github.com/inazumav/sing-box@v0.0.0-20230926072359-ab51429a14f1/common/dialer/dialer.go (about) 1 package dialer 2 3 import ( 4 "time" 5 6 "github.com/inazumav/sing-box/adapter" 7 "github.com/inazumav/sing-box/option" 8 "github.com/sagernet/sing-dns" 9 "github.com/sagernet/sing/common" 10 N "github.com/sagernet/sing/common/network" 11 ) 12 13 func MustNew(router adapter.Router, options option.DialerOptions) N.Dialer { 14 return common.Must1(New(router, options)) 15 } 16 17 func New(router adapter.Router, options option.DialerOptions) (N.Dialer, error) { 18 var ( 19 dialer N.Dialer 20 err error 21 ) 22 if options.Detour == "" { 23 dialer, err = NewDefault(router, options) 24 if err != nil { 25 return nil, err 26 } 27 } else { 28 dialer = NewDetour(router, options.Detour) 29 } 30 domainStrategy := dns.DomainStrategy(options.DomainStrategy) 31 if domainStrategy != dns.DomainStrategyAsIS || options.Detour == "" { 32 dialer = NewResolveDialer(router, dialer, domainStrategy, time.Duration(options.FallbackDelay)) 33 } 34 return dialer, nil 35 }