2022-07-03 12:59:25 +00:00
|
|
|
package dialer
|
|
|
|
|
|
|
|
import (
|
2022-07-08 04:58:43 +00:00
|
|
|
"time"
|
|
|
|
|
2022-07-06 07:01:09 +00:00
|
|
|
"github.com/sagernet/sing-box/adapter"
|
|
|
|
"github.com/sagernet/sing-box/option"
|
2022-07-11 10:44:59 +00:00
|
|
|
"github.com/sagernet/sing-dns"
|
2022-07-08 15:03:57 +00:00
|
|
|
N "github.com/sagernet/sing/common/network"
|
2022-07-03 12:59:25 +00:00
|
|
|
)
|
|
|
|
|
2023-08-08 08:14:03 +00:00
|
|
|
func New(router adapter.Router, options option.DialerOptions) (N.Dialer, error) {
|
2023-12-20 12:00:00 +00:00
|
|
|
if options.IsWireGuardListener {
|
|
|
|
return NewDefault(router, options)
|
|
|
|
}
|
2023-08-08 08:14:03 +00:00
|
|
|
var (
|
|
|
|
dialer N.Dialer
|
|
|
|
err error
|
|
|
|
)
|
2022-07-03 12:59:25 +00:00
|
|
|
if options.Detour == "" {
|
2023-08-08 08:14:03 +00:00
|
|
|
dialer, err = NewDefault(router, options)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-07-03 12:59:25 +00:00
|
|
|
} else {
|
2022-09-03 04:55:10 +00:00
|
|
|
dialer = NewDetour(router, options.Detour)
|
2022-07-07 15:36:32 +00:00
|
|
|
}
|
2022-07-11 10:44:59 +00:00
|
|
|
domainStrategy := dns.DomainStrategy(options.DomainStrategy)
|
|
|
|
if domainStrategy != dns.DomainStrategyAsIS || options.Detour == "" {
|
2023-09-27 05:17:16 +00:00
|
|
|
dialer = NewResolveDialer(
|
|
|
|
router,
|
|
|
|
dialer,
|
|
|
|
options.Detour == "" && !options.TCPFastOpen,
|
|
|
|
domainStrategy,
|
|
|
|
time.Duration(options.FallbackDelay))
|
2022-07-03 12:59:25 +00:00
|
|
|
}
|
2023-08-08 08:14:03 +00:00
|
|
|
return dialer, nil
|
2022-07-03 12:59:25 +00:00
|
|
|
}
|