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