mirror of
https://github.com/golang/net.git
synced 2026-03-31 10:27:08 +09:00
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 <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Jonathan Amsterdam <jba@google.com> Auto-Submit: Damien Neil <dneil@google.com>
This commit is contained in:
committed by
Gopher Robot
parent
dd0b200aed
commit
22500a668c
@@ -161,6 +161,9 @@ type testConn struct {
|
||||
peerConnID []byte // source conn id of peer's packets
|
||||
peerNextPacketNum [numberSpaceCount]packetNumber // next packet number to use
|
||||
|
||||
// Maximum packet number received from the conn.
|
||||
pnumMax [numberSpaceCount]packetNumber
|
||||
|
||||
// Datagrams, packets, and frames sent by the conn,
|
||||
// but not yet processed by the test.
|
||||
sentDatagrams [][]byte
|
||||
@@ -845,6 +848,7 @@ func parseTestDatagram(t *testing.T, te *testEndpoint, tc *testConn, buf []byte)
|
||||
}
|
||||
case packetTypeInitial, packetTypeHandshake:
|
||||
var k fixedKeys
|
||||
var pnumMax packetNumber
|
||||
if tc == nil {
|
||||
if ptype == packetTypeInitial {
|
||||
p, _ := parseGenericLongHeaderPacket(buf)
|
||||
@@ -856,18 +860,27 @@ func parseTestDatagram(t *testing.T, te *testEndpoint, tc *testConn, buf []byte)
|
||||
switch ptype {
|
||||
case packetTypeInitial:
|
||||
k = tc.keysInitial.r
|
||||
pnumMax = tc.pnumMax[initialSpace]
|
||||
case packetTypeHandshake:
|
||||
k = tc.keysHandshake.r
|
||||
pnumMax = tc.pnumMax[handshakeSpace]
|
||||
}
|
||||
}
|
||||
if !k.isSet() {
|
||||
t.Fatalf("reading %v packet with no read key", ptype)
|
||||
}
|
||||
var pnumMax packetNumber // TODO: Track packet numbers.
|
||||
p, n := parseLongHeaderPacket(buf, k, pnumMax)
|
||||
if n < 0 {
|
||||
t.Fatalf("packet parse error")
|
||||
}
|
||||
if tc != nil {
|
||||
switch ptype {
|
||||
case packetTypeInitial:
|
||||
tc.pnumMax[initialSpace] = max(pnumMax, p.num)
|
||||
case packetTypeHandshake:
|
||||
tc.pnumMax[handshakeSpace] = max(pnumMax, p.num)
|
||||
}
|
||||
}
|
||||
frames, err := parseTestFrames(t, p.payload)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -891,7 +904,10 @@ func parseTestDatagram(t *testing.T, te *testEndpoint, tc *testConn, buf []byte)
|
||||
if tc == nil || !tc.rkeyAppData.hdr.isSet() {
|
||||
t.Fatalf("reading 1-RTT packet with no read key")
|
||||
}
|
||||
var pnumMax packetNumber // TODO: Track packet numbers.
|
||||
var pnumMax packetNumber
|
||||
if tc != nil {
|
||||
pnumMax = tc.pnumMax[appDataSpace]
|
||||
}
|
||||
pnumOff := 1 + len(tc.peerConnID)
|
||||
// Try unprotecting the packet with the first maxTestKeyPhases keys.
|
||||
var phase int
|
||||
@@ -914,6 +930,9 @@ func parseTestDatagram(t *testing.T, te *testEndpoint, tc *testConn, buf []byte)
|
||||
if err != nil {
|
||||
t.Fatalf("1-RTT packet payload parse error")
|
||||
}
|
||||
if tc != nil {
|
||||
tc.pnumMax[appDataSpace] = max(pnumMax, pnum)
|
||||
}
|
||||
frames, err := parseTestFrames(t, pay)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
Reference in New Issue
Block a user