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{}
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())