From d6aa213461f400415a5787e831cb1a98145d54ae Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Sun, 24 Mar 2024 18:26:48 +0300 Subject: [PATCH] feat: evect inactive peers --- monitor.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/monitor.go b/monitor.go index a7896f3..1b88146 100644 --- a/monitor.go +++ b/monitor.go @@ -26,18 +26,22 @@ func monitor(wg *WGLink, log slog.Logger) { } sb := strings.Builder{} - var activePeers int var totalRx int64 var totalTx int64 for _, peer := range peers { totalRx += peer.ReceiveBytes totalTx += peer.TransmitBytes - if isActive(peer) { - activePeers += 1 + if !isActive(peer) { + log.Info( + fmt.Sprintf("[WGMonitor] Evecting peer %s", peer.PublicKey.String()), + ) + if err := wg.DeletePeer(peer.PublicKey.String()); err != nil { + log.Error(err.Error()) + log.Warn("[WGMonitor] Could not evect peer") + } } } sb.WriteString(fmt.Sprintf("Peers: %d ", len(peers))) - sb.WriteString(fmt.Sprintf("Active peers: %d ", activePeers)) sb.WriteString(fmt.Sprintf("TX: %d RX: %d", totalTx, totalRx)) log.Info("[WGMonitor] " + sb.String())