From 49f70c0c9f7db31dc2df320b20eea90cbb5913a3 Mon Sep 17 00:00:00 2001 From: boban Date: Sun, 21 Jun 2026 00:04:07 +0200 Subject: [PATCH] =?UTF-8?q?fix(wg):=20WgTraffic=20up=20=3D=20throughput=20?= =?UTF-8?q?delta=20(not=20raw=20tx)=20=E2=80=94=20consistent=20with=20down?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 --- app/Services/WgTraffic.php | 2 +- tests/Feature/WgTrafficTest.php | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/Services/WgTraffic.php b/app/Services/WgTraffic.php index ce3f6d1..08c9892 100644 --- a/app/Services/WgTraffic.php +++ b/app/Services/WgTraffic.php @@ -42,7 +42,7 @@ class WgTraffic $idx = (int) floor(($t - $from) / $width); if ($idx >= 0 && $idx < $buckets) { $down[$idx] += $dRx; - $up[$idx] += (int) $r->tx; + $up[$idx] += $dTx; } } $prev[$pk] = ['rx' => (int) $r->rx, 'tx' => (int) $r->tx]; diff --git a/tests/Feature/WgTrafficTest.php b/tests/Feature/WgTrafficTest.php index 983f221..8ce4465 100644 --- a/tests/Feature/WgTrafficTest.php +++ b/tests/Feature/WgTrafficTest.php @@ -37,8 +37,10 @@ class WgTrafficTest extends TestCase $this->sample('B', 50, 5, 600); $s = app(WgTraffic::class)->series(3600, 6); + // Both directions are THROUGHPUT (sum of positive per-peer deltas), not raw counters: + // down = A(100+200)+B(50) = 350 ; up = A(10+20)+B(5) = 35. $this->assertSame(350, $s['total_down']); - $this->assertSame(45, $s['total_up']); + $this->assertSame(35, $s['total_up']); $this->assertGreaterThan(0, $s['peak_down']); }