From cd3ec0b259e8635015303b88ddadb745ab481521 Mon Sep 17 00:00:00 2001 From: Owen Date: Sun, 23 Feb 2025 20:18:25 -0500 Subject: [PATCH] Support relay switch --- wg/wg.go | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/wg/wg.go b/wg/wg.go index f77bdcd..bcb7cda 100644 --- a/wg/wg.go +++ b/wg/wg.go @@ -419,18 +419,29 @@ func (s *WireGuardService) addPeer(peer Peer) error { } // add keep alive using *time.Duration of 1 second keepalive := time.Second - // endpoint, err := net.ResolveUDPAddr("udp", peer.Endpoint) - // if err != nil { - // return fmt.Errorf("failed to resolve endpoint address: %w", err) - // } - // make the endpoint localhost to test + var peerConfig wgtypes.PeerConfig + if peer.Endpoint != "" { + endpoint, err := net.ResolveUDPAddr("udp", peer.Endpoint) + if err != nil { + return fmt.Errorf("failed to resolve endpoint address: %w", err) + } - peerConfig := wgtypes.PeerConfig{ - PublicKey: pubKey, - AllowedIPs: allowedIPs, - PersistentKeepaliveInterval: &keepalive, - // Endpoint: endpoint, + // make the endpoint localhost to test + + peerConfig = wgtypes.PeerConfig{ + PublicKey: pubKey, + AllowedIPs: allowedIPs, + PersistentKeepaliveInterval: &keepalive, + Endpoint: endpoint, + } + } else { + peerConfig = wgtypes.PeerConfig{ + PublicKey: pubKey, + AllowedIPs: allowedIPs, + PersistentKeepaliveInterval: &keepalive, + } + logger.Info("Added peer with no endpoint!") } config := wgtypes.Config{