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