sing-box/common/dialer/dialer.go

37 lines
1 KiB
Go
Raw Normal View History

package dialer
import (
2022-07-08 04:58:43 +00:00
"time"
"github.com/sagernet/sing/common"
N "github.com/sagernet/sing/common/network"
2022-07-06 07:01:09 +00:00
"github.com/sagernet/sing-box/adapter"
2022-07-07 13:47:21 +00:00
C "github.com/sagernet/sing-box/constant"
2022-07-06 07:01:09 +00:00
"github.com/sagernet/sing-box/option"
)
func New(router adapter.Router, options option.DialerOptions) N.Dialer {
if options.Detour == "" {
2022-07-07 15:36:32 +00:00
return NewDefault(options)
} else {
2022-07-07 15:36:32 +00: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 04:58:43 +00: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 15:11:48 +00:00
dialer = NewOverride(dialer, common.PtrValueOrDefault(options.OverrideOptions))
}
return dialer
}