From 5886b3c4e7924775d129efe143c67e044a3f73b0 Mon Sep 17 00:00:00 2001 From: Philipp Hancke Date: Tue, 6 Oct 2026 20:28:10 +0200 Subject: [PATCH] Use 64 bit candidate pair packet counters packetsSent and packetsReceived are unsigned long long in the specification since https://github.com/w3c/webrtc-stats/pull/494 --- agent.go | 4 ++-- agent_test.go | 8 ++++---- candidatepair.go | 16 ++++++++-------- stats.go | 4 ++-- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/agent.go b/agent.go index 2ec9026b..127bd2f7 100644 --- a/agent.go +++ b/agent.go @@ -1104,8 +1104,8 @@ func replacePairRemote(pair *CandidatePair, remote Candidate) *CandidatePair { atomic.StoreInt64(&replacement.currentRoundTripTime, atomic.LoadInt64(&pair.currentRoundTripTime)) atomic.StoreInt64(&replacement.totalRoundTripTime, atomic.LoadInt64(&pair.totalRoundTripTime)) - atomic.StoreUint32(&replacement.packetsSent, atomic.LoadUint32(&pair.packetsSent)) - atomic.StoreUint32(&replacement.packetsReceived, atomic.LoadUint32(&pair.packetsReceived)) + atomic.StoreUint64(&replacement.packetsSent, atomic.LoadUint64(&pair.packetsSent)) + atomic.StoreUint64(&replacement.packetsReceived, atomic.LoadUint64(&pair.packetsReceived)) atomic.StoreUint64(&replacement.bytesSent, atomic.LoadUint64(&pair.bytesSent)) atomic.StoreUint64(&replacement.bytesReceived, atomic.LoadUint64(&pair.bytesReceived)) atomic.StoreUint64(&replacement.requestsReceived, atomic.LoadUint64(&pair.requestsReceived)) diff --git a/agent_test.go b/agent_test.go index df41d9f4..5ff297a9 100644 --- a/agent_test.go +++ b/agent_test.go @@ -1436,8 +1436,8 @@ func TestCandidatePairsStats(t *testing.T) { //nolint:cyclop,gocyclo require.False(t, cps.FirstRequestReceivedTimestamp.IsZero()) require.False(t, cps.LastRequestReceivedTimestamp.IsZero()) - require.Equal(t, uint32(1), cps.PacketsSent) - require.Equal(t, uint32(1), cps.PacketsReceived) + require.Equal(t, uint64(1), cps.PacketsSent) + require.Equal(t, uint64(1), cps.PacketsReceived) require.Equal(t, uint64(100), cps.BytesSent) require.Equal(t, uint64(200), cps.BytesReceived) require.False(t, cps.LastPacketSentTimestamp.IsZero()) @@ -1504,8 +1504,8 @@ func TestSelectedCandidatePairStats(t *testing.T) { //nolint:cyclop require.Equal(t, float64(55), stats.TotalRoundTripTime) require.Equal(t, uint64(10), stats.ResponsesReceived) - require.Equal(t, uint32(1), stats.PacketsSent) - require.Equal(t, uint32(1), stats.PacketsReceived) + require.Equal(t, uint64(1), stats.PacketsSent) + require.Equal(t, uint64(1), stats.PacketsReceived) require.Equal(t, uint64(150), stats.BytesSent) require.Equal(t, uint64(250), stats.BytesReceived) require.False(t, stats.LastPacketSentTimestamp.IsZero()) diff --git a/candidatepair.go b/candidatepair.go index db24d3d1..5f7d7298 100644 --- a/candidatepair.go +++ b/candidatepair.go @@ -37,8 +37,8 @@ type CandidatePair struct { currentRoundTripTime int64 // in ns totalRoundTripTime int64 // in ns - packetsSent uint32 - packetsReceived uint32 + packetsSent uint64 + packetsReceived uint64 bytesSent uint64 bytesReceived uint64 lastPacketSentAt atomic.Int64 // monotonic nanos since timeRef, see getMonoNanos @@ -196,13 +196,13 @@ func (p *CandidatePair) ResponsesSent() uint64 { } // PacketsSent returns total application (non-STUN) packets sent on this pair. -func (p *CandidatePair) PacketsSent() uint32 { - return atomic.LoadUint32(&p.packetsSent) +func (p *CandidatePair) PacketsSent() uint64 { + return atomic.LoadUint64(&p.packetsSent) } // PacketsReceived returns total application (non-STUN) packets received on this pair. -func (p *CandidatePair) PacketsReceived() uint32 { - return atomic.LoadUint32(&p.packetsReceived) +func (p *CandidatePair) PacketsReceived() uint64 { + return atomic.LoadUint64(&p.packetsReceived) } // BytesSent returns total application bytes sent on this pair. @@ -239,7 +239,7 @@ func (p *CandidatePair) UpdatePacketSent(n int) { return } - atomic.AddUint32(&p.packetsSent, 1) + atomic.AddUint64(&p.packetsSent, 1) atomic.AddUint64(&p.bytesSent, uint64(n)) // #nosec G115 -- n > 0 validated above p.lastPacketSentAt.Store(getMonoNanos(time.Now())) } @@ -250,7 +250,7 @@ func (p *CandidatePair) UpdatePacketReceived(n int) { return } - atomic.AddUint32(&p.packetsReceived, 1) + atomic.AddUint64(&p.packetsReceived, 1) atomic.AddUint64(&p.bytesReceived, uint64(n)) // #nosec G115 -- n > 0 validated above p.lastPacketReceivedAt.Store(getMonoNanos(time.Now())) } diff --git a/stats.go b/stats.go index 4b5ad013..8c819a77 100644 --- a/stats.go +++ b/stats.go @@ -27,10 +27,10 @@ type CandidatePairStats struct { Nominated bool // PacketsSent represents the total number of packets sent on this candidate pair. - PacketsSent uint32 + PacketsSent uint64 // PacketsReceived represents the total number of packets received on this candidate pair. - PacketsReceived uint32 + PacketsReceived uint64 // BytesSent represents the total number of payload bytes sent on this candidate pair // not including headers or padding.