feat: evect inactive peers

This commit is contained in:
HeshamTB 2024-03-24 18:26:48 +03:00
parent a9c728355b
commit d6aa213461

View File

@ -26,18 +26,22 @@ func monitor(wg *WGLink, log slog.Logger) {
} }
sb := strings.Builder{} sb := strings.Builder{}
var activePeers int
var totalRx int64 var totalRx int64
var totalTx int64 var totalTx int64
for _, peer := range peers { for _, peer := range peers {
totalRx += peer.ReceiveBytes totalRx += peer.ReceiveBytes
totalTx += peer.TransmitBytes totalTx += peer.TransmitBytes
if isActive(peer) { if !isActive(peer) {
activePeers += 1 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("Peers: %d ", len(peers)))
sb.WriteString(fmt.Sprintf("Active peers: %d ", activePeers))
sb.WriteString(fmt.Sprintf("TX: %d RX: %d", totalTx, totalRx)) sb.WriteString(fmt.Sprintf("TX: %d RX: %d", totalTx, totalRx))
log.Info("[WGMonitor] " + sb.String()) log.Info("[WGMonitor] " + sb.String())