2022-07-03 20:59:25 +08:00
|
|
|
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"
|
2022-07-03 20:59:25 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func New(router adapter.Router, options option.DialerOptions) N.Dialer {
|
2022-07-07 21:47:21 +08:00
|
|
|
domainStrategy := C.DomainStrategy(options.DomainStrategy)
|
2022-07-03 20:59:25 +08:00
|
|
|
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)
|
2022-07-03 20:59:25 +08:00
|
|
|
} 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)
|
|
|
|
}
|
2022-07-03 20:59:25 +08:00
|
|
|
}
|
2022-07-03 23:23:18 +08:00
|
|
|
if options.OverrideOptions.IsValid() {
|
2022-07-06 23:11:48 +08:00
|
|
|
dialer = NewOverride(dialer, common.PtrValueOrDefault(options.OverrideOptions))
|
2022-07-03 20:59:25 +08:00
|
|
|
}
|
|
|
|
return dialer
|
|
|
|
}
|