Small adjustments

This commit is contained in:
Owen
2025-12-10 14:06:36 -05:00
parent 61065def17
commit df1c2c18e0
2 changed files with 20 additions and 10 deletions

View File

@@ -471,7 +471,7 @@ func StartTunnel(config TunnelConfig) {
// Get existing peer from PeerManager // Get existing peer from PeerManager
existingPeer, exists := peerManager.GetPeer(updateData.SiteId) existingPeer, exists := peerManager.GetPeer(updateData.SiteId)
if !exists { if !exists {
logger.Error("Peer with site ID %d not found", updateData.SiteId) logger.Warn("Peer with site ID %d not found", updateData.SiteId)
return return
} }
@@ -785,6 +785,13 @@ func StartTunnel(config TunnelConfig) {
return return
} }
// Get existing peer from PeerManager
_, exists := peerManager.GetPeer(handshakeData.SiteId)
if exists {
logger.Warn("Peer with site ID %d already added", handshakeData.SiteId)
return
}
exitNode := holepunch.ExitNode{ exitNode := holepunch.ExitNode{
Endpoint: handshakeData.ExitNode.Endpoint, Endpoint: handshakeData.ExitNode.Endpoint,
PublicKey: handshakeData.ExitNode.PublicKey, PublicKey: handshakeData.ExitNode.PublicKey,

View File

@@ -191,15 +191,12 @@ func (pm *PeerMonitor) AddPeer(siteID int, endpoint string, holepunchEndpoint st
// update holepunch endpoint for a peer // update holepunch endpoint for a peer
func (pm *PeerMonitor) UpdateHolepunchEndpoint(siteID int, endpoint string) { func (pm *PeerMonitor) UpdateHolepunchEndpoint(siteID int, endpoint string) {
go func() { // Short delay to allow WireGuard peer reconfiguration to complete
// Short delay to allow WireGuard peer reconfiguration to complete // The NAT mapping refresh is handled separately by TriggerHolePunch in olm.go
// The NAT mapping refresh is handled separately by TriggerHolePunch in olm.go pm.mutex.Lock()
time.Sleep(500 * time.Millisecond) defer pm.mutex.Unlock()
pm.mutex.Lock() pm.holepunchEndpoints[siteID] = endpoint
defer pm.mutex.Unlock() logger.Debug("Updated holepunch endpoint for site %d to %s", siteID, endpoint)
pm.holepunchEndpoints[siteID] = endpoint
logger.Debug("Updated holepunch endpoint for site %d to %s", siteID, endpoint)
}()
} }
// RapidTestPeer performs a rapid connectivity test for a newly added peer. // RapidTestPeer performs a rapid connectivity test for a newly added peer.
@@ -297,6 +294,12 @@ func (pm *PeerMonitor) RemovePeer(siteID int) {
pm.removePeerUnlocked(siteID) pm.removePeerUnlocked(siteID)
} }
func (pm *PeerMonitor) RemoveHolepunchEndpoint(siteID int) {
pm.mutex.Lock()
defer pm.mutex.Unlock()
delete(pm.holepunchEndpoints, siteID)
}
// Start begins monitoring all peers // Start begins monitoring all peers
func (pm *PeerMonitor) Start() { func (pm *PeerMonitor) Start() {
pm.mutex.Lock() pm.mutex.Lock()