sing-box/common/dialer/dialer.go

31 lines
906 B
Go
Raw Normal View History

package dialer
import (
"github.com/sagernet/sing/common"
N "github.com/sagernet/sing/common/network"
2022-07-06 15:01:09 +08:00
"github.com/sagernet/sing-box/adapter"
2022-07-07 21:47:21 +08:00
C "github.com/sagernet/sing-box/constant"
2022-07-06 15:01:09 +08:00
"github.com/sagernet/sing-box/option"
)
func New(router adapter.Router, options option.DialerOptions) N.Dialer {
if options.Detour == "" {
2022-07-07 23:36:32 +08:00
return NewDefault(options)
} else {
2022-07-07 23:36:32 +08:00
return NewDetour(router, options.Detour)
}
}
func NewOutbound(router adapter.Router, options option.OutboundDialerOptions) N.Dialer {
dialer := New(router, options.DialerOptions)
domainStrategy := C.DomainStrategy(options.DomainStrategy)
if domainStrategy != C.DomainStrategyAsIS || options.Detour == "" && !C.CGO_ENABLED {
dialer = NewResolveDialer(router, dialer, domainStrategy)
}
if options.OverrideOptions.IsValid() {
2022-07-06 23:11:48 +08:00
dialer = NewOverride(dialer, common.PtrValueOrDefault(options.OverrideOptions))
}
return dialer
}