mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-09-15 21:00:27 +00:00
masque: add address/port option to override endpoint
This commit is contained in:
@@ -36,6 +36,9 @@
|
||||
"auth_token": "",
|
||||
"license_key": ""
|
||||
},
|
||||
// Optional: override the endpoint instead of using the one returned by Cloudflare
|
||||
"address": "",
|
||||
"port": 0,
|
||||
"udp_timeout": "5m0s",
|
||||
"udp_keepalive_period": "30s",
|
||||
"udp_initial_packet_size": 0,
|
||||
|
||||
@@ -14,6 +14,8 @@ type MASQUEOutboundOptions struct {
|
||||
UseHTTP2 bool `json:"use_http2,omitempty"`
|
||||
UseIPv6 bool `json:"use_ipv6,omitempty"`
|
||||
Profile CloudflareProfile `json:"profile,omitempty"`
|
||||
Address string `json:"address,omitempty"`
|
||||
Port uint16 `json:"port,omitempty"`
|
||||
UDPTimeout badoption.Duration `json:"udp_timeout,omitempty"`
|
||||
UDPKeepalivePeriod badoption.Duration `json:"udp_keepalive_period,omitempty"`
|
||||
UDPInitialPacketSize uint16 `json:"udp_initial_packet_size,omitempty"`
|
||||
|
||||
@@ -111,10 +111,28 @@ func NewOutbound(ctx context.Context, router adapter.Router, logger log.ContextL
|
||||
logger.ErrorContext(ctx, E.New("failed to prepare TLS config: ", err))
|
||||
return
|
||||
}
|
||||
endpoint, err := appConfig.SelectEndpointFromConfig(options.UseHTTP2, options.UseIPv6, 443)
|
||||
if err != nil {
|
||||
logger.ErrorContext(ctx, E.New("failed to select endpoint: ", err))
|
||||
return
|
||||
var endpoint net.Addr
|
||||
if options.Address != "" {
|
||||
endpointPort := options.Port
|
||||
if endpointPort == 0 {
|
||||
endpointPort = 443
|
||||
}
|
||||
endpointIP := net.ParseIP(options.Address)
|
||||
if endpointIP == nil {
|
||||
logger.ErrorContext(ctx, E.New("invalid endpoint address: ", options.Address))
|
||||
return
|
||||
}
|
||||
if options.UseHTTP2 {
|
||||
endpoint = &net.TCPAddr{IP: endpointIP, Port: int(endpointPort)}
|
||||
} else {
|
||||
endpoint = &net.UDPAddr{IP: endpointIP, Port: int(endpointPort)}
|
||||
}
|
||||
} else {
|
||||
endpoint, err = appConfig.SelectEndpointFromConfig(options.UseHTTP2, options.UseIPv6, 443)
|
||||
if err != nil {
|
||||
logger.ErrorContext(ctx, E.New("failed to select endpoint: ", err))
|
||||
return
|
||||
}
|
||||
}
|
||||
var udpTimeout time.Duration
|
||||
if options.UDPTimeout != 0 {
|
||||
|
||||
Reference in New Issue
Block a user