Take 21820 from config

This commit is contained in:
Owen
2025-12-16 18:32:31 -05:00
parent 9bc35433ef
commit 1cbf41e094
4 changed files with 19 additions and 6 deletions

View File

@@ -63,7 +63,7 @@ func closeClients() {
} }
} }
func clientsHandleNewtConnection(publicKey string, endpoint string) { func clientsHandleNewtConnection(publicKey string, endpoint string, relayPort uint16) {
if !ready { if !ready {
return return
} }
@@ -77,7 +77,7 @@ func clientsHandleNewtConnection(publicKey string, endpoint string) {
endpoint = strings.Join(parts[:len(parts)-1], ":") endpoint = strings.Join(parts[:len(parts)-1], ":")
if wgService != nil { if wgService != nil {
wgService.StartHolepunch(publicKey, endpoint) wgService.StartHolepunch(publicKey, endpoint, relayPort)
} }
} }

View File

@@ -270,16 +270,21 @@ func (s *WireGuardService) SetOnNetstackClose(callback func()) {
} }
// StartHolepunch starts hole punching to a specific endpoint // StartHolepunch starts hole punching to a specific endpoint
func (s *WireGuardService) StartHolepunch(publicKey string, endpoint string) { func (s *WireGuardService) StartHolepunch(publicKey string, endpoint string, relayPort uint16) {
if s.holePunchManager == nil { if s.holePunchManager == nil {
logger.Warn("Hole punch manager not initialized") logger.Warn("Hole punch manager not initialized")
return return
} }
if relayPort == 0 {
relayPort = 21820
}
// Convert websocket.ExitNode to holepunch.ExitNode // Convert websocket.ExitNode to holepunch.ExitNode
hpExitNodes := []holepunch.ExitNode{ hpExitNodes := []holepunch.ExitNode{
{ {
Endpoint: endpoint, Endpoint: endpoint,
RelayPort: relayPort,
PublicKey: publicKey, PublicKey: publicKey,
}, },
} }

View File

@@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net" "net"
"strconv"
"sync" "sync"
"time" "time"
@@ -19,6 +20,7 @@ import (
// ExitNode represents a WireGuard exit node for hole punching // ExitNode represents a WireGuard exit node for hole punching
type ExitNode struct { type ExitNode struct {
Endpoint string `json:"endpoint"` Endpoint string `json:"endpoint"`
RelayPort uint16 `json:"relayPort"`
PublicKey string `json:"publicKey"` PublicKey string `json:"publicKey"`
} }
@@ -202,7 +204,7 @@ func (m *Manager) TriggerHolePunch() error {
continue continue
} }
serverAddr := net.JoinHostPort(host, "21820") serverAddr := net.JoinHostPort(host, strconv.Itoa(int(exitNode.RelayPort)))
remoteAddr, err := net.ResolveUDPAddr("udp", serverAddr) remoteAddr, err := net.ResolveUDPAddr("udp", serverAddr)
if err != nil { if err != nil {
logger.Error("Failed to resolve UDP address %s: %v", serverAddr, err) logger.Error("Failed to resolve UDP address %s: %v", serverAddr, err)
@@ -313,7 +315,7 @@ func (m *Manager) runMultipleExitNodes() {
continue continue
} }
serverAddr := net.JoinHostPort(host, "21820") serverAddr := net.JoinHostPort(host, strconv.Itoa(int(exitNode.RelayPort)))
remoteAddr, err := net.ResolveUDPAddr("udp", serverAddr) remoteAddr, err := net.ResolveUDPAddr("udp", serverAddr)
if err != nil { if err != nil {
logger.Error("Failed to resolve UDP address %s: %v", serverAddr, err) logger.Error("Failed to resolve UDP address %s: %v", serverAddr, err)

View File

@@ -37,6 +37,7 @@ import (
type WgData struct { type WgData struct {
Endpoint string `json:"endpoint"` Endpoint string `json:"endpoint"`
RelayPort uint16 `json:"relayPort"`
PublicKey string `json:"publicKey"` PublicKey string `json:"publicKey"`
ServerIP string `json:"serverIP"` ServerIP string `json:"serverIP"`
TunnelIP string `json:"tunnelIP"` TunnelIP string `json:"tunnelIP"`
@@ -691,7 +692,12 @@ func runNewtMain(ctx context.Context) {
return return
} }
clientsHandleNewtConnection(wgData.PublicKey, endpoint) relayPort := wgData.RelayPort
if relayPort == 0 {
relayPort = 21820
}
clientsHandleNewtConnection(wgData.PublicKey, endpoint, relayPort)
// Configure WireGuard // Configure WireGuard
config := fmt.Sprintf(`private_key=%s config := fmt.Sprintf(`private_key=%s