Skip to content

Commit

Permalink
quic: correct rttvar updates
Browse files Browse the repository at this point in the history
RFC errata 7539 adjusts RFC 9002 Section 5.3 to update
rttvar before smoothed_rtt.

https://www.rfc-editor.org/errata/eid7539

For golang/go#58547

Change-Id: I154ed54d3d693c3b42355de39c5907c7cc906fde
Reviewed-on: https://go-review.googlesource.com/c/net/+/502215
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
  • Loading branch information
neild committed Jun 21, 2023
1 parent ab184e6 commit ee81e8c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion internal/quic/rtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (r *rttState) updateSample(now time.Time, handshakeConfirmed bool, spaceID
if adjustedRTT < r.minRTT {
adjustedRTT = latestRTT
}
r.smoothedRTT = ((7 * r.smoothedRTT) + adjustedRTT) / 8
rttvarSample := abs(r.smoothedRTT - adjustedRTT)
r.rttvar = (3*r.rttvar + rttvarSample) / 4
r.smoothedRTT = ((7 * r.smoothedRTT) + adjustedRTT) / 8
}
16 changes: 8 additions & 8 deletions internal/quic/rtt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,15 @@ func TestRTTInitialRTT(t *testing.T) {
handshakeConfirmed = true
rtt.updateSample(now, handshakeConfirmed, handshakeSpace, 40*time.Millisecond, ackDelay, maxAckDelay)
adjustedRTT = 15 * time.Millisecond // latest_rtt (40ms) - max_ack_delay (25ms)
smoothedRTT = (7*smoothedRTT + adjustedRTT) / 8
if got, want := rtt.smoothedRTT, smoothedRTT; got != want {
t.Errorf("smoothed_rtt = %v, want %v", got, want)
}
rttvarSample = abs(smoothedRTT - adjustedRTT)
rttvar = (3*rttvar + rttvarSample) / 4
if got, want := rtt.rttvar, rttvar; got != want {
t.Errorf("rttvar = %v, want %v", got, want)
}
smoothedRTT = (7*smoothedRTT + adjustedRTT) / 8
if got, want := rtt.smoothedRTT, smoothedRTT; got != want {
t.Errorf("smoothed_rtt = %v, want %v", got, want)
}

// "[...] MUST NOT subtract the acknowledgment delay from
// the RTT sample if the resulting value is smaller than the min_rtt."
Expand All @@ -156,13 +156,13 @@ func TestRTTInitialRTT(t *testing.T) {
}
// latest_rtt (30ms) - ack_delay (25ms) = 5ms, which is less than min_rtt (10ms)
adjustedRTT = 30 * time.Millisecond // latest_rtt
smoothedRTT = (7*smoothedRTT + adjustedRTT) / 8
if got, want := rtt.smoothedRTT, smoothedRTT; got != want {
t.Errorf("smoothed_rtt = %v, want %v", got, want)
}
rttvarSample = abs(smoothedRTT - adjustedRTT)
rttvar = (3*rttvar + rttvarSample) / 4
if got, want := rtt.rttvar, rttvar; got != want {
t.Errorf("rttvar = %v, want %v", got, want)
}
smoothedRTT = (7*smoothedRTT + adjustedRTT) / 8
if got, want := rtt.smoothedRTT, smoothedRTT; got != want {
t.Errorf("smoothed_rtt = %v, want %v", got, want)
}
}

0 comments on commit ee81e8c

Please sign in to comment.