sing-box/common/dialer/dialer.go

29 lines
814 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 {
2022-07-07 21:47:21 +08:00
domainStrategy := C.DomainStrategy(options.DomainStrategy)
var dialer N.Dialer
if options.Detour == "" {
2022-07-06 23:11:48 +08:00
dialer = NewDefault(options)
2022-07-07 21:47:21 +08:00
dialer = NewResolveDialer(router, dialer, domainStrategy)
} else {
2022-07-06 23:11:48 +08:00
dialer = NewDetour(router, options.Detour)
2022-07-07 21:47:21 +08:00
if domainStrategy != C.DomainStrategyAsIS {
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
}