Skip to content

Commit 22500a6

Browse files
neildgopherbot
authored andcommitted
quic: decode packet numbers >255 in tests
Decoding QUIC packet numbers requires keeping track of the largest packet number received so far from the peer. Our tests haven't bothered doing that so far, so tests can't work with packet numbers past 255. Fix that so we can write tests that use more packets. Change-Id: Icb795e5cf69794381c12a3a03b0da6bcf47a69c0 Reviewed-on: https://go-review.googlesource.com/c/net/+/664296 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Jonathan Amsterdam <[email protected]> Auto-Submit: Damien Neil <[email protected]>
1 parent dd0b200 commit 22500a6

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

quic/conn_test.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ type testConn struct {
161161
peerConnID []byte // source conn id of peer's packets
162162
peerNextPacketNum [numberSpaceCount]packetNumber // next packet number to use
163163

164+
// Maximum packet number received from the conn.
165+
pnumMax [numberSpaceCount]packetNumber
166+
164167
// Datagrams, packets, and frames sent by the conn,
165168
// but not yet processed by the test.
166169
sentDatagrams [][]byte
@@ -845,6 +848,7 @@ func parseTestDatagram(t *testing.T, te *testEndpoint, tc *testConn, buf []byte)
845848
}
846849
case packetTypeInitial, packetTypeHandshake:
847850
var k fixedKeys
851+
var pnumMax packetNumber
848852
if tc == nil {
849853
if ptype == packetTypeInitial {
850854
p, _ := parseGenericLongHeaderPacket(buf)
@@ -856,18 +860,27 @@ func parseTestDatagram(t *testing.T, te *testEndpoint, tc *testConn, buf []byte)
856860
switch ptype {
857861
case packetTypeInitial:
858862
k = tc.keysInitial.r
863+
pnumMax = tc.pnumMax[initialSpace]
859864
case packetTypeHandshake:
860865
k = tc.keysHandshake.r
866+
pnumMax = tc.pnumMax[handshakeSpace]
861867
}
862868
}
863869
if !k.isSet() {
864870
t.Fatalf("reading %v packet with no read key", ptype)
865871
}
866-
var pnumMax packetNumber // TODO: Track packet numbers.
867872
p, n := parseLongHeaderPacket(buf, k, pnumMax)
868873
if n < 0 {
869874
t.Fatalf("packet parse error")
870875
}
876+
if tc != nil {
877+
switch ptype {
878+
case packetTypeInitial:
879+
tc.pnumMax[initialSpace] = max(pnumMax, p.num)
880+
case packetTypeHandshake:
881+
tc.pnumMax[handshakeSpace] = max(pnumMax, p.num)
882+
}
883+
}
871884
frames, err := parseTestFrames(t, p.payload)
872885
if err != nil {
873886
t.Fatal(err)
@@ -891,7 +904,10 @@ func parseTestDatagram(t *testing.T, te *testEndpoint, tc *testConn, buf []byte)
891904
if tc == nil || !tc.rkeyAppData.hdr.isSet() {
892905
t.Fatalf("reading 1-RTT packet with no read key")
893906
}
894-
var pnumMax packetNumber // TODO: Track packet numbers.
907+
var pnumMax packetNumber
908+
if tc != nil {
909+
pnumMax = tc.pnumMax[appDataSpace]
910+
}
895911
pnumOff := 1 + len(tc.peerConnID)
896912
// Try unprotecting the packet with the first maxTestKeyPhases keys.
897913
var phase int
@@ -914,6 +930,9 @@ func parseTestDatagram(t *testing.T, te *testEndpoint, tc *testConn, buf []byte)
914930
if err != nil {
915931
t.Fatalf("1-RTT packet payload parse error")
916932
}
933+
if tc != nil {
934+
tc.pnumMax[appDataSpace] = max(pnumMax, pnum)
935+
}
917936
frames, err := parseTestFrames(t, pay)
918937
if err != nil {
919938
t.Fatal(err)

0 commit comments

Comments
 (0)