sing-box/common/dialer/dialer.go

36 lines
1.0 KiB
Go
Raw Normal View History

package dialer
import (
2022-07-08 12:58:43 +08:00
"time"
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"
2022-07-08 23:03:57 +08: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 == "" {
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 {
2022-07-08 12:58:43 +08:00
fallbackDelay := time.Duration(options.FallbackDelay)
if fallbackDelay == 0 {
fallbackDelay = time.Millisecond * 300
}
dialer = NewResolveDialer(router, dialer, domainStrategy, fallbackDelay)
}
if options.OverrideOptions.IsValid() {
2022-07-06 23:11:48 +08:00
dialer = NewOverride(dialer, common.PtrValueOrDefault(options.OverrideOptions))
}
return dialer
}