mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-22 00:21:30 +00:00
Merge dialer options
This commit is contained in:
parent
b206d0889b
commit
62fa48293a
|
@ -10,15 +10,12 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func New(router adapter.Router, options option.DialerOptions) N.Dialer {
|
func New(router adapter.Router, options option.DialerOptions) N.Dialer {
|
||||||
|
var dialer N.Dialer
|
||||||
if options.Detour == "" {
|
if options.Detour == "" {
|
||||||
return NewDefault(router, options)
|
dialer = NewDefault(router, options)
|
||||||
} else {
|
} else {
|
||||||
return NewDetour(router, options.Detour)
|
dialer = NewDetour(router, options.Detour)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func NewOutbound(router adapter.Router, options option.OutboundDialerOptions) N.Dialer {
|
|
||||||
dialer := New(router, options.DialerOptions)
|
|
||||||
domainStrategy := dns.DomainStrategy(options.DomainStrategy)
|
domainStrategy := dns.DomainStrategy(options.DomainStrategy)
|
||||||
if domainStrategy != dns.DomainStrategyAsIS || options.Detour == "" {
|
if domainStrategy != dns.DomainStrategyAsIS || options.Detour == "" {
|
||||||
dialer = NewResolveDialer(router, dialer, domainStrategy, time.Duration(options.FallbackDelay))
|
dialer = NewResolveDialer(router, dialer, domainStrategy, time.Duration(options.FallbackDelay))
|
||||||
|
|
|
@ -8,7 +8,7 @@ type DirectInboundOptions struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type DirectOutboundOptions struct {
|
type DirectOutboundOptions struct {
|
||||||
OutboundDialerOptions
|
DialerOptions
|
||||||
OverrideAddress string `json:"override_address,omitempty"`
|
OverrideAddress string `json:"override_address,omitempty"`
|
||||||
OverridePort uint16 `json:"override_port,omitempty"`
|
OverridePort uint16 `json:"override_port,omitempty"`
|
||||||
ProxyProtocol uint8 `json:"proxy_protocol,omitempty"`
|
ProxyProtocol uint8 `json:"proxy_protocol,omitempty"`
|
||||||
|
|
|
@ -17,7 +17,7 @@ type HysteriaInboundOptions struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type HysteriaOutboundOptions struct {
|
type HysteriaOutboundOptions struct {
|
||||||
OutboundDialerOptions
|
DialerOptions
|
||||||
ServerOptions
|
ServerOptions
|
||||||
Up string `json:"up,omitempty"`
|
Up string `json:"up,omitempty"`
|
||||||
UpMbps int `json:"up_mbps,omitempty"`
|
UpMbps int `json:"up_mbps,omitempty"`
|
||||||
|
|
|
@ -113,10 +113,6 @@ type DialerOptions struct {
|
||||||
ReuseAddr bool `json:"reuse_addr,omitempty"`
|
ReuseAddr bool `json:"reuse_addr,omitempty"`
|
||||||
ConnectTimeout Duration `json:"connect_timeout,omitempty"`
|
ConnectTimeout Duration `json:"connect_timeout,omitempty"`
|
||||||
TCPFastOpen bool `json:"tcp_fast_open,omitempty"`
|
TCPFastOpen bool `json:"tcp_fast_open,omitempty"`
|
||||||
}
|
|
||||||
|
|
||||||
type OutboundDialerOptions struct {
|
|
||||||
DialerOptions
|
|
||||||
DomainStrategy DomainStrategy `json:"domain_strategy,omitempty"`
|
DomainStrategy DomainStrategy `json:"domain_strategy,omitempty"`
|
||||||
FallbackDelay Duration `json:"fallback_delay,omitempty"`
|
FallbackDelay Duration `json:"fallback_delay,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ type ShadowsocksDestination struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ShadowsocksOutboundOptions struct {
|
type ShadowsocksOutboundOptions struct {
|
||||||
OutboundDialerOptions
|
DialerOptions
|
||||||
ServerOptions
|
ServerOptions
|
||||||
Method string `json:"method"`
|
Method string `json:"method"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
|
|
|
@ -11,7 +11,7 @@ type ShadowTLSHandshakeOptions struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ShadowTLSOutboundOptions struct {
|
type ShadowTLSOutboundOptions struct {
|
||||||
OutboundDialerOptions
|
DialerOptions
|
||||||
ServerOptions
|
ServerOptions
|
||||||
TLS *OutboundTLSOptions `json:"tls,omitempty"`
|
TLS *OutboundTLSOptions `json:"tls,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ type HTTPMixedInboundOptions struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type SocksOutboundOptions struct {
|
type SocksOutboundOptions struct {
|
||||||
OutboundDialerOptions
|
DialerOptions
|
||||||
ServerOptions
|
ServerOptions
|
||||||
Version string `json:"version,omitempty"`
|
Version string `json:"version,omitempty"`
|
||||||
Username string `json:"username,omitempty"`
|
Username string `json:"username,omitempty"`
|
||||||
|
@ -25,7 +25,7 @@ type SocksOutboundOptions struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type HTTPOutboundOptions struct {
|
type HTTPOutboundOptions struct {
|
||||||
OutboundDialerOptions
|
DialerOptions
|
||||||
ServerOptions
|
ServerOptions
|
||||||
Username string `json:"username,omitempty"`
|
Username string `json:"username,omitempty"`
|
||||||
Password string `json:"password,omitempty"`
|
Password string `json:"password,omitempty"`
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package option
|
package option
|
||||||
|
|
||||||
type SSHOutboundOptions struct {
|
type SSHOutboundOptions struct {
|
||||||
OutboundDialerOptions
|
DialerOptions
|
||||||
ServerOptions
|
ServerOptions
|
||||||
User string `json:"user,omitempty"`
|
User string `json:"user,omitempty"`
|
||||||
Password string `json:"password,omitempty"`
|
Password string `json:"password,omitempty"`
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package option
|
package option
|
||||||
|
|
||||||
type TorOutboundOptions struct {
|
type TorOutboundOptions struct {
|
||||||
OutboundDialerOptions
|
DialerOptions
|
||||||
ExecutablePath string `json:"executable_path,omitempty"`
|
ExecutablePath string `json:"executable_path,omitempty"`
|
||||||
ExtraArgs []string `json:"extra_args,omitempty"`
|
ExtraArgs []string `json:"extra_args,omitempty"`
|
||||||
DataDirectory string `json:"data_directory,omitempty"`
|
DataDirectory string `json:"data_directory,omitempty"`
|
||||||
|
|
|
@ -15,7 +15,7 @@ type TrojanUser struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type TrojanOutboundOptions struct {
|
type TrojanOutboundOptions struct {
|
||||||
OutboundDialerOptions
|
DialerOptions
|
||||||
ServerOptions
|
ServerOptions
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
Network NetworkList `json:"network,omitempty"`
|
Network NetworkList `json:"network,omitempty"`
|
||||||
|
|
|
@ -14,7 +14,7 @@ type VMessUser struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type VMessOutboundOptions struct {
|
type VMessOutboundOptions struct {
|
||||||
OutboundDialerOptions
|
DialerOptions
|
||||||
ServerOptions
|
ServerOptions
|
||||||
UUID string `json:"uuid"`
|
UUID string `json:"uuid"`
|
||||||
Security string `json:"security"`
|
Security string `json:"security"`
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package option
|
package option
|
||||||
|
|
||||||
type WireGuardOutboundOptions struct {
|
type WireGuardOutboundOptions struct {
|
||||||
OutboundDialerOptions
|
DialerOptions
|
||||||
ServerOptions
|
ServerOptions
|
||||||
LocalAddress Listable[string] `json:"local_address"`
|
LocalAddress Listable[string] `json:"local_address"`
|
||||||
PrivateKey string `json:"private_key"`
|
PrivateKey string `json:"private_key"`
|
||||||
|
|
|
@ -45,7 +45,7 @@ func NewDirect(router adapter.Router, logger log.ContextLogger, tag string, opti
|
||||||
},
|
},
|
||||||
domainStrategy: dns.DomainStrategy(options.DomainStrategy),
|
domainStrategy: dns.DomainStrategy(options.DomainStrategy),
|
||||||
fallbackDelay: time.Duration(options.FallbackDelay),
|
fallbackDelay: time.Duration(options.FallbackDelay),
|
||||||
dialer: dialer.NewOutbound(router, options.OutboundDialerOptions),
|
dialer: dialer.New(router, options.DialerOptions),
|
||||||
proxyProto: options.ProxyProtocol,
|
proxyProto: options.ProxyProtocol,
|
||||||
}
|
}
|
||||||
if options.ProxyProtocol > 2 {
|
if options.ProxyProtocol > 2 {
|
||||||
|
|
|
@ -24,7 +24,7 @@ type HTTP struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHTTP(router adapter.Router, logger log.ContextLogger, tag string, options option.HTTPOutboundOptions) (*HTTP, error) {
|
func NewHTTP(router adapter.Router, logger log.ContextLogger, tag string, options option.HTTPOutboundOptions) (*HTTP, error) {
|
||||||
detour, err := dialer.NewTLS(dialer.NewOutbound(router, options.OutboundDialerOptions), options.Server, common.PtrValueOrDefault(options.TLS))
|
detour, err := dialer.NewTLS(dialer.New(router, options.DialerOptions), options.Server, common.PtrValueOrDefault(options.TLS))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,7 +117,7 @@ func NewHysteria(ctx context.Context, router adapter.Router, logger log.ContextL
|
||||||
tag: tag,
|
tag: tag,
|
||||||
},
|
},
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
dialer: dialer.NewOutbound(router, options.OutboundDialerOptions),
|
dialer: dialer.New(router, options.DialerOptions),
|
||||||
serverAddr: options.ServerOptions.Build(),
|
serverAddr: options.ServerOptions.Build(),
|
||||||
tlsConfig: tlsConfig,
|
tlsConfig: tlsConfig,
|
||||||
quicConfig: quicConfig,
|
quicConfig: quicConfig,
|
||||||
|
|
|
@ -44,7 +44,7 @@ func NewShadowsocks(ctx context.Context, router adapter.Router, logger log.Conte
|
||||||
logger: logger,
|
logger: logger,
|
||||||
tag: tag,
|
tag: tag,
|
||||||
},
|
},
|
||||||
dialer: dialer.NewOutbound(router, options.OutboundDialerOptions),
|
dialer: dialer.New(router, options.DialerOptions),
|
||||||
method: method,
|
method: method,
|
||||||
serverAddr: options.ServerOptions.Build(),
|
serverAddr: options.ServerOptions.Build(),
|
||||||
uot: options.UoT,
|
uot: options.UoT,
|
||||||
|
|
|
@ -34,7 +34,7 @@ func NewShadowTLS(ctx context.Context, router adapter.Router, logger log.Context
|
||||||
logger: logger,
|
logger: logger,
|
||||||
tag: tag,
|
tag: tag,
|
||||||
},
|
},
|
||||||
dialer: dialer.NewOutbound(router, options.OutboundDialerOptions),
|
dialer: dialer.New(router, options.DialerOptions),
|
||||||
serverAddr: options.ServerOptions.Build(),
|
serverAddr: options.ServerOptions.Build(),
|
||||||
}
|
}
|
||||||
if options.TLS == nil || !options.TLS.Enabled {
|
if options.TLS == nil || !options.TLS.Enabled {
|
||||||
|
|
|
@ -25,7 +25,7 @@ type Socks struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSocks(router adapter.Router, logger log.ContextLogger, tag string, options option.SocksOutboundOptions) (*Socks, error) {
|
func NewSocks(router adapter.Router, logger log.ContextLogger, tag string, options option.SocksOutboundOptions) (*Socks, error) {
|
||||||
detour := dialer.NewOutbound(router, options.OutboundDialerOptions)
|
detour := dialer.New(router, options.DialerOptions)
|
||||||
var version socks.Version
|
var version socks.Version
|
||||||
var err error
|
var err error
|
||||||
if options.Version != "" {
|
if options.Version != "" {
|
||||||
|
|
|
@ -47,7 +47,7 @@ func NewSSH(ctx context.Context, router adapter.Router, logger log.ContextLogger
|
||||||
tag: tag,
|
tag: tag,
|
||||||
},
|
},
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
dialer: dialer.NewOutbound(router, options.OutboundDialerOptions),
|
dialer: dialer.New(router, options.DialerOptions),
|
||||||
serverAddr: options.ServerOptions.Build(),
|
serverAddr: options.ServerOptions.Build(),
|
||||||
user: options.User,
|
user: options.User,
|
||||||
hostKeyAlgorithms: options.HostKeyAlgorithms,
|
hostKeyAlgorithms: options.HostKeyAlgorithms,
|
||||||
|
|
|
@ -66,7 +66,7 @@ func NewTor(ctx context.Context, router adapter.Router, logger log.ContextLogger
|
||||||
tag: tag,
|
tag: tag,
|
||||||
},
|
},
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
proxy: NewProxyListener(ctx, logger, dialer.NewOutbound(router, options.OutboundDialerOptions)),
|
proxy: NewProxyListener(ctx, logger, dialer.New(router, options.DialerOptions)),
|
||||||
startConf: &startConf,
|
startConf: &startConf,
|
||||||
options: options.Options,
|
options: options.Options,
|
||||||
}, nil
|
}, nil
|
||||||
|
|
|
@ -40,7 +40,7 @@ func NewTrojan(ctx context.Context, router adapter.Router, logger log.ContextLog
|
||||||
logger: logger,
|
logger: logger,
|
||||||
tag: tag,
|
tag: tag,
|
||||||
},
|
},
|
||||||
dialer: dialer.NewOutbound(router, options.OutboundDialerOptions),
|
dialer: dialer.New(router, options.DialerOptions),
|
||||||
serverAddr: options.ServerOptions.Build(),
|
serverAddr: options.ServerOptions.Build(),
|
||||||
key: trojan.Key(options.Password),
|
key: trojan.Key(options.Password),
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ func NewVMess(ctx context.Context, router adapter.Router, logger log.ContextLogg
|
||||||
logger: logger,
|
logger: logger,
|
||||||
tag: tag,
|
tag: tag,
|
||||||
},
|
},
|
||||||
dialer: dialer.NewOutbound(router, options.OutboundDialerOptions),
|
dialer: dialer.New(router, options.DialerOptions),
|
||||||
serverAddr: options.ServerOptions.Build(),
|
serverAddr: options.ServerOptions.Build(),
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
|
|
|
@ -64,7 +64,7 @@ func NewWireGuard(ctx context.Context, router adapter.Router, logger log.Context
|
||||||
},
|
},
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
serverAddr: options.ServerOptions.Build(),
|
serverAddr: options.ServerOptions.Build(),
|
||||||
dialer: dialer.NewOutbound(router, options.OutboundDialerOptions),
|
dialer: dialer.New(router, options.DialerOptions),
|
||||||
}
|
}
|
||||||
var endpointIp netip.Addr
|
var endpointIp netip.Addr
|
||||||
if !outbound.serverAddr.IsFqdn() {
|
if !outbound.serverAddr.IsFqdn() {
|
||||||
|
|
|
@ -59,13 +59,11 @@ func TestChainedInbound(t *testing.T) {
|
||||||
ShadowsocksOptions: option.ShadowsocksOutboundOptions{
|
ShadowsocksOptions: option.ShadowsocksOutboundOptions{
|
||||||
Method: method,
|
Method: method,
|
||||||
Password: password,
|
Password: password,
|
||||||
OutboundDialerOptions: option.OutboundDialerOptions{
|
|
||||||
DialerOptions: option.DialerOptions{
|
DialerOptions: option.DialerOptions{
|
||||||
Detour: "detour-out",
|
Detour: "detour-out",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
{
|
{
|
||||||
Type: C.TypeShadowsocks,
|
Type: C.TypeShadowsocks,
|
||||||
Tag: "detour-out",
|
Tag: "detour-out",
|
||||||
|
|
|
@ -60,13 +60,11 @@ func TestShadowTLS(t *testing.T) {
|
||||||
ShadowsocksOptions: option.ShadowsocksOutboundOptions{
|
ShadowsocksOptions: option.ShadowsocksOutboundOptions{
|
||||||
Method: method,
|
Method: method,
|
||||||
Password: password,
|
Password: password,
|
||||||
OutboundDialerOptions: option.OutboundDialerOptions{
|
|
||||||
DialerOptions: option.DialerOptions{
|
DialerOptions: option.DialerOptions{
|
||||||
Detour: "detour",
|
Detour: "detour",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
{
|
{
|
||||||
Type: C.TypeShadowTLS,
|
Type: C.TypeShadowTLS,
|
||||||
Tag: "detour",
|
Tag: "detour",
|
||||||
|
@ -131,13 +129,11 @@ func TestShadowTLSOutbound(t *testing.T) {
|
||||||
{
|
{
|
||||||
Type: C.TypeSocks,
|
Type: C.TypeSocks,
|
||||||
SocksOptions: option.SocksOutboundOptions{
|
SocksOptions: option.SocksOutboundOptions{
|
||||||
OutboundDialerOptions: option.OutboundDialerOptions{
|
|
||||||
DialerOptions: option.DialerOptions{
|
DialerOptions: option.DialerOptions{
|
||||||
Detour: "detour",
|
Detour: "detour",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
{
|
{
|
||||||
Type: C.TypeShadowTLS,
|
Type: C.TypeShadowTLS,
|
||||||
Tag: "detour",
|
Tag: "detour",
|
||||||
|
|
Loading…
Reference in a new issue