mirror of
https://github.com/SagerNet/sing-box.git
synced 2025-03-20 21:39:30 +00:00
Let vmess use zero instead of auto if TLS enabled
This commit is contained in:
parent
a940703ae1
commit
fd5ac69a35
1 changed files with 20 additions and 12 deletions
|
@ -32,17 +32,6 @@ type VMess struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewVMess(ctx context.Context, router adapter.Router, logger log.ContextLogger, tag string, options option.VMessOutboundOptions) (*VMess, error) {
|
func NewVMess(ctx context.Context, router adapter.Router, logger log.ContextLogger, tag string, options option.VMessOutboundOptions) (*VMess, error) {
|
||||||
var clientOptions []vmess.ClientOption
|
|
||||||
if options.GlobalPadding {
|
|
||||||
clientOptions = append(clientOptions, vmess.ClientWithGlobalPadding())
|
|
||||||
}
|
|
||||||
if options.AuthenticatedLength {
|
|
||||||
clientOptions = append(clientOptions, vmess.ClientWithAuthenticatedLength())
|
|
||||||
}
|
|
||||||
client, err := vmess.NewClient(options.UUID, options.Security, options.AlterId, clientOptions...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
outbound := &VMess{
|
outbound := &VMess{
|
||||||
myOutboundAdapter: myOutboundAdapter{
|
myOutboundAdapter: myOutboundAdapter{
|
||||||
protocol: C.TypeVMess,
|
protocol: C.TypeVMess,
|
||||||
|
@ -52,9 +41,9 @@ func NewVMess(ctx context.Context, router adapter.Router, logger log.ContextLogg
|
||||||
tag: tag,
|
tag: tag,
|
||||||
},
|
},
|
||||||
dialer: dialer.NewOutbound(router, options.OutboundDialerOptions),
|
dialer: dialer.NewOutbound(router, options.OutboundDialerOptions),
|
||||||
client: client,
|
|
||||||
serverAddr: options.ServerOptions.Build(),
|
serverAddr: options.ServerOptions.Build(),
|
||||||
}
|
}
|
||||||
|
var err error
|
||||||
if options.TLS != nil {
|
if options.TLS != nil {
|
||||||
outbound.tlsConfig, err = dialer.TLSConfig(options.Server, common.PtrValueOrDefault(options.TLS))
|
outbound.tlsConfig, err = dialer.TLSConfig(options.Server, common.PtrValueOrDefault(options.TLS))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -71,6 +60,25 @@ func NewVMess(ctx context.Context, router adapter.Router, logger log.ContextLogg
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
var clientOptions []vmess.ClientOption
|
||||||
|
if options.GlobalPadding {
|
||||||
|
clientOptions = append(clientOptions, vmess.ClientWithGlobalPadding())
|
||||||
|
}
|
||||||
|
if options.AuthenticatedLength {
|
||||||
|
clientOptions = append(clientOptions, vmess.ClientWithAuthenticatedLength())
|
||||||
|
}
|
||||||
|
security := options.Security
|
||||||
|
if security == "" {
|
||||||
|
security = "auto"
|
||||||
|
}
|
||||||
|
if security == "auto" && outbound.tlsConfig != nil {
|
||||||
|
security = "zero"
|
||||||
|
}
|
||||||
|
client, err := vmess.NewClient(options.UUID, security, options.AlterId, clientOptions...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
outbound.client = client
|
||||||
return outbound, nil
|
return outbound, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue