fix: add ipv6 endpoint formatter

Former-commit-id: 5b443a41a3
This commit is contained in:
FranceNuage
2025-09-04 14:09:58 +02:00
parent 35b48cd8e5
commit d48acfba39

View File

@@ -3,6 +3,7 @@ package peermonitor
import ( import (
"context" "context"
"fmt" "fmt"
"strings"
"sync" "sync"
"time" "time"
@@ -204,12 +205,18 @@ func (pm *PeerMonitor) HandleFailover(siteID int, relayEndpoint string) {
return return
} }
// Check for IPv6 and format the endpoint correctly
formattedEndpoint := relayEndpoint
if strings.Contains(relayEndpoint, ":") {
formattedEndpoint = fmt.Sprintf("[%s]", relayEndpoint)
}
// Configure WireGuard to use the relay // Configure WireGuard to use the relay
wgConfig := fmt.Sprintf(`private_key=%s wgConfig := fmt.Sprintf(`private_key=%s
public_key=%s public_key=%s
allowed_ip=%s/32 allowed_ip=%s/32
endpoint=%s:21820 endpoint=%s:21820
persistent_keepalive_interval=1`, pm.privateKey, config.PublicKey, config.ServerIP, relayEndpoint) persistent_keepalive_interval=1`, pm.privateKey, config.PublicKey, config.ServerIP, formattedEndpoint) // Use the correctly formatted endpoint here
err := pm.device.IpcSet(wgConfig) err := pm.device.IpcSet(wgConfig)
if err != nil { if err != nil {