mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-09-15 21:00:27 +00:00
warp: add address/port option to override peer endpoint
This commit is contained in:
@@ -46,7 +46,10 @@
|
||||
"auth_token": "",
|
||||
"license_key": "",
|
||||
"recreate": false
|
||||
}
|
||||
},
|
||||
// Optional: override the peer endpoint instead of using the one returned by Cloudflare
|
||||
"address": "engage.cloudflareclient.com",
|
||||
"port": 2408
|
||||
// Dial Fields
|
||||
}
|
||||
],
|
||||
|
||||
@@ -13,6 +13,8 @@ type WARPEndpointOptions struct {
|
||||
DisablePauses bool `json:"disable_pauses,omitempty"`
|
||||
Amnezia *WARPAmnezia `json:"amnezia,omitempty"`
|
||||
Profile CloudflareProfile `json:"profile,omitempty"`
|
||||
Address string `json:"address,omitempty"`
|
||||
Port uint16 `json:"port,omitempty"`
|
||||
DialerOptions
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +87,14 @@ func NewEndpoint(ctx context.Context, router adapter.Router, logger log.ContextL
|
||||
}
|
||||
}
|
||||
peer := config.Peers[0]
|
||||
hostParts := strings.Split(peer.Endpoint.Host, ":")
|
||||
peerAddress := strings.Split(peer.Endpoint.Host, ":")[0]
|
||||
peerPort := uint16(peer.Endpoint.Ports[rand.Intn(len(peer.Endpoint.Ports))])
|
||||
if options.Address != "" {
|
||||
peerAddress = options.Address
|
||||
if options.Port != 0 {
|
||||
peerPort = options.Port
|
||||
}
|
||||
}
|
||||
var amnezia *option.WireGuardAmnezia
|
||||
if options.Amnezia != nil {
|
||||
amnezia = &option.WireGuardAmnezia{
|
||||
@@ -130,8 +137,8 @@ func NewEndpoint(ctx context.Context, router adapter.Router, logger log.ContextL
|
||||
PrivateKey: config.PrivateKey,
|
||||
Peers: []option.WireGuardPeer{
|
||||
{
|
||||
Address: hostParts[0],
|
||||
Port: uint16(peer.Endpoint.Ports[rand.Intn(len(peer.Endpoint.Ports))]),
|
||||
Address: peerAddress,
|
||||
Port: peerPort,
|
||||
PublicKey: peer.PublicKey,
|
||||
AllowedIPs: badoption.Listable[netip.Prefix]{
|
||||
netip.MustParsePrefix("0.0.0.0/0"),
|
||||
|
||||
Reference in New Issue
Block a user