diff --git a/examples/warp/client.json b/examples/warp/client.json index 6307374f..6480f413 100644 --- a/examples/warp/client.json +++ b/examples/warp/client.json @@ -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 } ], diff --git a/option/warp.go b/option/warp.go index 399e944e..b60f9b9b 100644 --- a/option/warp.go +++ b/option/warp.go @@ -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 } diff --git a/protocol/warp/endpoint.go b/protocol/warp/endpoint.go index cb581414..321f4815 100644 --- a/protocol/warp/endpoint.go +++ b/protocol/warp/endpoint.go @@ -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"),