warp: add address/port option to override peer endpoint

This commit is contained in:
Shtorm
2026-09-04 01:42:45 +03:00
parent 04922b1898
commit 673a408dca
3 changed files with 16 additions and 4 deletions
+4 -1
View File
@@ -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
}
],
+2
View File
@@ -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
}
+10 -3
View File
@@ -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"),