2022-07-03 12:59:25 +00:00
|
|
|
package dialer
|
|
|
|
|
|
|
|
import (
|
2022-07-08 04:58:43 +00:00
|
|
|
"time"
|
|
|
|
|
2022-07-03 12:59:25 +00:00
|
|
|
"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"
|
2022-07-03 12:59:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func New(router adapter.Router, options option.DialerOptions) N.Dialer {
|
|
|
|
if options.Detour == "" {
|
2022-07-07 15:36:32 +00:00
|
|
|
return NewDefault(options)
|
2022-07-03 12:59:25 +00:00
|
|
|
} 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)
|
2022-07-03 12:59:25 +00:00
|
|
|
}
|
2022-07-03 15:23:18 +00:00
|
|
|
if options.OverrideOptions.IsValid() {
|
2022-07-06 15:11:48 +00:00
|
|
|
dialer = NewOverride(dialer, common.PtrValueOrDefault(options.OverrideOptions))
|
2022-07-03 12:59:25 +00:00
|
|
|
}
|
|
|
|
return dialer
|
|
|
|
}
|