From 63f3d202b6600a59319b2e0a9603dba261e86293 Mon Sep 17 00:00:00 2001 From: infosave2007 Date: Fri, 24 Apr 2026 07:16:09 +0300 Subject: [PATCH] fix: correct AIVPN byte counter mapping to match server-to-client and client-to-server traffic semantics --- inc/ServerMonitoring.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/inc/ServerMonitoring.php b/inc/ServerMonitoring.php index e716cab..501f2dd 100644 --- a/inc/ServerMonitoring.php +++ b/inc/ServerMonitoring.php @@ -367,18 +367,20 @@ class ServerMonitoring $rawOutNow = (int) ($aivpn['bytes_out'] ?? 0); // Detect counter rollover/reset in AIVPN source and preserve cumulative totals. + // bytes_in -> received (download), bytes_out -> sent (upload) if ($rawInNow < $rawInPrev) { - $offsetIn = max($offsetIn + $rawInPrev, $prevSent); + $offsetIn = max($offsetIn + $rawInPrev, $prevReceived); } if ($rawOutNow < $rawOutPrev) { - $offsetOut = max($offsetOut + $rawOutPrev, $prevReceived); + $offsetOut = max($offsetOut + $rawOutPrev, $prevSent); } - $candidateSent = $offsetIn + $rawInNow; - $candidateReceived = $offsetOut + $rawOutNow; + $candidateReceived = $offsetIn + $rawInNow; + $candidateSent = $offsetOut + $rawOutNow; - // AIVPN stores per-client counters as bytes_in/bytes_out. - // Map to panel semantics: sent=client upload, received=client download. + // AIVPN bytes_in = data downloaded BY client (server→client) + // AIVPN bytes_out = data uploaded BY client (client→server) + // Verified via `aivpn-server --list-clients` where bytes_in = DOWNLOAD column $bytesSent = max($prevSent, $candidateSent); $bytesReceived = max($prevReceived, $candidateReceived);