Reconnect to newt

Former-commit-id: ee7948f3d5
This commit is contained in:
Owen
2025-07-24 20:45:17 -07:00
parent 848ac6b0c4
commit 29235f6100
3 changed files with 34 additions and 6 deletions

View File

@@ -103,7 +103,7 @@ func (pm *PeerMonitor) AddPeer(siteID int, endpoint string, wgConfig *WireGuardC
// Check if we're already monitoring this peer
if _, exists := pm.monitors[siteID]; exists {
// Update the endpoint instead of creating a new monitor
pm.RemovePeer(siteID)
pm.removePeerUnlocked(siteID)
}
client, err := wgtester.NewClient(endpoint)
@@ -131,11 +131,9 @@ func (pm *PeerMonitor) AddPeer(siteID int, endpoint string, wgConfig *WireGuardC
return err
}
// RemovePeer stops monitoring a peer and removes it from the monitor
func (pm *PeerMonitor) RemovePeer(siteID int) {
pm.mutex.Lock()
defer pm.mutex.Unlock()
// removePeerUnlocked stops monitoring a peer and removes it from the monitor
// This function assumes the mutex is already held by the caller
func (pm *PeerMonitor) removePeerUnlocked(siteID int) {
client, exists := pm.monitors[siteID]
if !exists {
return
@@ -147,6 +145,14 @@ func (pm *PeerMonitor) RemovePeer(siteID int) {
delete(pm.configs, siteID)
}
// RemovePeer stops monitoring a peer and removes it from the monitor
func (pm *PeerMonitor) RemovePeer(siteID int) {
pm.mutex.Lock()
defer pm.mutex.Unlock()
pm.removePeerUnlocked(siteID)
}
// Start begins monitoring all peers
func (pm *PeerMonitor) Start() {
pm.mutex.Lock()