File: conn_send_test.go

package info (click to toggle)
golang-golang-x-net 1%3A0.27.0-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • size: 8,636 kB
  • sloc: asm: 18; makefile: 12; sh: 7
file content (83 lines) | stat: -rw-r--r-- 2,373 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.21

package quic

import (
	"testing"
	"time"
)

func TestAckElicitingAck(t *testing.T) {
	// "A receiver that sends only non-ack-eliciting packets [...] might not receive
	// an acknowledgment for a long period of time.
	// [...] a receiver could send a [...] ack-eliciting frame occasionally [...]
	// to elicit an ACK from the peer."
	// https://www.rfc-editor.org/rfc/rfc9000#section-13.2.4-2
	//
	// Send a bunch of ack-eliciting packets, verify that the conn doesn't just
	// send ACKs in response.
	tc := newTestConn(t, clientSide, permissiveTransportParameters)
	tc.handshake()
	const count = 100
	for i := 0; i < count; i++ {
		tc.advance(1 * time.Millisecond)
		tc.writeFrames(packetType1RTT,
			debugFramePing{},
		)
		got, _ := tc.readFrame()
		switch got.(type) {
		case debugFrameAck:
			continue
		case debugFramePing:
			return
		}
	}
	t.Errorf("after sending %v PINGs, got no ack-eliciting response", count)
}

func TestSendPacketNumberSize(t *testing.T) {
	tc := newTestConn(t, clientSide, permissiveTransportParameters)
	tc.handshake()

	recvPing := func() *testPacket {
		t.Helper()
		tc.conn.ping(appDataSpace)
		p := tc.readPacket()
		if p == nil {
			t.Fatalf("want packet containing PING, got none")
		}
		return p
	}

	// Desynchronize the packet numbers the conn is sending and the ones it is receiving,
	// by having the conn send a number of unacked packets.
	for i := 0; i < 16; i++ {
		recvPing()
	}

	// Establish the maximum packet number the conn has received an ACK for.
	maxAcked := recvPing().num
	tc.writeAckForAll()

	// Make the conn send a sequence of packets.
	// Check that the packet number is encoded with two bytes once the difference between the
	// current packet and the max acked one is sufficiently large.
	for want := maxAcked + 1; want < maxAcked+0x100; want++ {
		p := recvPing()
		if p.num != want {
			t.Fatalf("received packet number %v, want %v", p.num, want)
		}
		gotPnumLen := int(p.header&0x03) + 1
		wantPnumLen := 1
		if p.num-maxAcked >= 0x80 {
			wantPnumLen = 2
		}
		if gotPnumLen != wantPnumLen {
			t.Fatalf("packet number 0x%x encoded with %v bytes, want %v (max acked = %v)", p.num, gotPnumLen, wantPnumLen, maxAcked)
		}
	}
}