fix: correct AIVPN byte counter mapping to match server-to-client and client-to-server traffic semantics

This commit is contained in:
infosave2007
2026-04-24 07:16:09 +03:00
parent 8eed687f66
commit 63f3d202b6
+8 -6
View File
@@ -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);