-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathconn_loss_test.go
726 lines (667 loc) · 21.5 KB
/
conn_loss_test.go
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
// 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 (
"context"
"crypto/tls"
"fmt"
"testing"
)
// Frames may be retransmitted either when the packet containing the frame is lost, or on PTO.
// lostFrameTest runs a test in both configurations.
func lostFrameTest(t *testing.T, f func(t *testing.T, pto bool)) {
t.Run("lost", func(t *testing.T) {
f(t, false)
})
t.Run("pto", func(t *testing.T) {
f(t, true)
})
}
// triggerLossOrPTO causes the conn to declare the last sent packet lost,
// or advances to the PTO timer.
func (tc *testConn) triggerLossOrPTO(ptype packetType, pto bool) {
tc.t.Helper()
if pto {
if !tc.conn.loss.ptoTimerArmed {
tc.t.Fatalf("PTO timer not armed, expected it to be")
}
if *testVV {
tc.t.Logf("advancing to PTO timer")
}
tc.advanceTo(tc.conn.loss.timer)
return
}
if *testVV {
*testVV = false
defer func() {
tc.t.Logf("cause conn to declare last packet lost")
*testVV = true
}()
}
defer func(ignoreFrames map[byte]bool) {
tc.ignoreFrames = ignoreFrames
}(tc.ignoreFrames)
tc.ignoreFrames = map[byte]bool{
frameTypeAck: true,
frameTypePadding: true,
}
// Send three packets containing PINGs, and then respond with an ACK for the
// last one. This puts the last packet before the PINGs outside the packet
// reordering threshold, and it will be declared lost.
const lossThreshold = 3
var num packetNumber
for i := 0; i < lossThreshold; i++ {
tc.conn.ping(spaceForPacketType(ptype))
d := tc.readDatagram()
if d == nil {
tc.t.Fatalf("conn is idle; want PING frame")
}
if d.packets[0].ptype != ptype {
tc.t.Fatalf("conn sent %v packet; want %v", d.packets[0].ptype, ptype)
}
num = d.packets[0].num
}
tc.writeFrames(ptype, debugFrameAck{
ranges: []i64range[packetNumber]{
{num, num + 1},
},
})
}
func TestLostResetStreamFrame(t *testing.T) {
// "Cancellation of stream transmission, as carried in a RESET_STREAM frame,
// is sent until acknowledged or until all stream data is acknowledged by the peer [...]"
// https://www.rfc-editor.org/rfc/rfc9000.html#section-13.3-3.4
lostFrameTest(t, func(t *testing.T, pto bool) {
tc, s := newTestConnAndLocalStream(t, serverSide, uniStream, permissiveTransportParameters)
tc.ignoreFrame(frameTypeAck)
s.Reset(1)
tc.wantFrame("reset stream",
packetType1RTT, debugFrameResetStream{
id: s.id,
code: 1,
})
tc.triggerLossOrPTO(packetType1RTT, pto)
tc.wantFrame("resent RESET_STREAM frame",
packetType1RTT, debugFrameResetStream{
id: s.id,
code: 1,
})
})
}
func TestLostStopSendingFrame(t *testing.T) {
// "[...] a request to cancel stream transmission, as encoded in a STOP_SENDING frame,
// is sent until the receiving part of the stream enters either a "Data Recvd" or
// "Reset Recvd" state [...]"
// https://www.rfc-editor.org/rfc/rfc9000.html#section-13.3-3.5
//
// Technically, we can stop sending a STOP_SENDING frame if the peer sends
// us all the data for the stream or resets it. We don't bother tracking this,
// however, so we'll keep sending the frame until it is acked. This is harmless.
lostFrameTest(t, func(t *testing.T, pto bool) {
tc, s := newTestConnAndRemoteStream(t, serverSide, uniStream, permissiveTransportParameters)
tc.ignoreFrame(frameTypeAck)
s.CloseRead()
tc.wantFrame("stream is read-closed",
packetType1RTT, debugFrameStopSending{
id: s.id,
})
tc.triggerLossOrPTO(packetType1RTT, pto)
tc.wantFrame("resent STOP_SENDING frame",
packetType1RTT, debugFrameStopSending{
id: s.id,
})
})
}
func TestLostCryptoFrame(t *testing.T) {
// "Data sent in CRYPTO frames is retransmitted [...] until all data has been acknowledged."
// https://www.rfc-editor.org/rfc/rfc9000.html#section-13.3-3.1
lostFrameTest(t, func(t *testing.T, pto bool) {
tc := newTestConn(t, clientSide)
tc.ignoreFrame(frameTypeAck)
tc.wantFrame("client sends Initial CRYPTO frame",
packetTypeInitial, debugFrameCrypto{
data: tc.cryptoDataOut[tls.QUICEncryptionLevelInitial],
})
tc.triggerLossOrPTO(packetTypeInitial, pto)
tc.wantFrame("client resends Initial CRYPTO frame",
packetTypeInitial, debugFrameCrypto{
data: tc.cryptoDataOut[tls.QUICEncryptionLevelInitial],
})
tc.writeFrames(packetTypeInitial,
debugFrameCrypto{
data: tc.cryptoDataIn[tls.QUICEncryptionLevelInitial],
})
tc.writeFrames(packetTypeHandshake,
debugFrameCrypto{
data: tc.cryptoDataIn[tls.QUICEncryptionLevelHandshake],
})
tc.wantFrame("client sends Handshake CRYPTO frame",
packetTypeHandshake, debugFrameCrypto{
data: tc.cryptoDataOut[tls.QUICEncryptionLevelHandshake],
})
tc.wantFrame("client provides server with an additional connection ID",
packetType1RTT, debugFrameNewConnectionID{
seq: 1,
connID: testLocalConnID(1),
token: testLocalStatelessResetToken(1),
})
tc.triggerLossOrPTO(packetTypeHandshake, pto)
tc.wantFrame("client resends Handshake CRYPTO frame",
packetTypeHandshake, debugFrameCrypto{
data: tc.cryptoDataOut[tls.QUICEncryptionLevelHandshake],
})
})
}
func TestLostStreamFrameEmpty(t *testing.T) {
// A STREAM frame opening a stream, but containing no stream data, should
// be retransmitted if lost.
lostFrameTest(t, func(t *testing.T, pto bool) {
ctx := canceledContext()
tc := newTestConn(t, clientSide, permissiveTransportParameters)
tc.handshake()
tc.ignoreFrame(frameTypeAck)
c, err := tc.conn.NewStream(ctx)
if err != nil {
t.Fatalf("NewStream: %v", err)
}
c.Flush() // open the stream
tc.wantFrame("created bidirectional stream 0",
packetType1RTT, debugFrameStream{
id: newStreamID(clientSide, bidiStream, 0),
data: []byte{},
})
tc.triggerLossOrPTO(packetType1RTT, pto)
tc.wantFrame("resent stream frame",
packetType1RTT, debugFrameStream{
id: newStreamID(clientSide, bidiStream, 0),
data: []byte{},
})
})
}
func TestLostStreamWithData(t *testing.T) {
// "Application data sent in STREAM frames is retransmitted in new STREAM
// frames unless the endpoint has sent a RESET_STREAM for that stream."
// https://www.rfc-editor.org/rfc/rfc9000#section-13.3-3.2
//
// TODO: Lost stream frame after RESET_STREAM
lostFrameTest(t, func(t *testing.T, pto bool) {
data := []byte{0, 1, 2, 3, 4, 5, 6, 7}
tc, s := newTestConnAndLocalStream(t, serverSide, uniStream, func(p *transportParameters) {
p.initialMaxStreamsUni = 1
p.initialMaxData = 1 << 20
p.initialMaxStreamDataUni = 1 << 20
})
s.Write(data[:4])
s.Flush()
tc.wantFrame("send [0,4)",
packetType1RTT, debugFrameStream{
id: s.id,
off: 0,
data: data[:4],
})
s.Write(data[4:8])
s.Flush()
tc.wantFrame("send [4,8)",
packetType1RTT, debugFrameStream{
id: s.id,
off: 4,
data: data[4:8],
})
s.CloseWrite()
tc.wantFrame("send FIN",
packetType1RTT, debugFrameStream{
id: s.id,
off: 8,
fin: true,
data: []byte{},
})
tc.triggerLossOrPTO(packetType1RTT, pto)
tc.wantFrame("resend data",
packetType1RTT, debugFrameStream{
id: s.id,
off: 0,
fin: true,
data: data[:8],
})
})
}
func TestLostStreamPartialLoss(t *testing.T) {
// Conn sends four STREAM packets.
// ACKs are received for the packets containing bytes 0 and 2.
// The remaining packets are declared lost.
// The Conn resends only the lost data.
//
// This test doesn't have a PTO mode, because the ACK for the packet containing byte 2
// starts the loss timer for the packet containing byte 1, and the PTO timer is not
// armed when the loss timer is.
data := []byte{0, 1, 2, 3}
tc, s := newTestConnAndLocalStream(t, serverSide, uniStream, func(p *transportParameters) {
p.initialMaxStreamsUni = 1
p.initialMaxData = 1 << 20
p.initialMaxStreamDataUni = 1 << 20
})
for i := range data {
s.Write(data[i : i+1])
s.Flush()
tc.wantFrame(fmt.Sprintf("send STREAM frame with byte %v", i),
packetType1RTT, debugFrameStream{
id: s.id,
off: int64(i),
data: data[i : i+1],
})
if i%2 == 0 {
tc.writeAckForLatest()
}
}
const pto = false
tc.triggerLossOrPTO(packetType1RTT, pto)
tc.wantFrame("resend byte 1",
packetType1RTT, debugFrameStream{
id: s.id,
off: 1,
data: data[1:2],
})
tc.wantFrame("resend byte 3",
packetType1RTT, debugFrameStream{
id: s.id,
off: 3,
data: data[3:4],
})
tc.wantIdle("no more frames sent after packet loss")
}
func TestLostMaxDataFrame(t *testing.T) {
// "An updated value is sent in a MAX_DATA frame if the packet
// containing the most recently sent MAX_DATA frame is declared lost [...]"
// https://www.rfc-editor.org/rfc/rfc9000#section-13.3-3.7
lostFrameTest(t, func(t *testing.T, pto bool) {
const maxWindowSize = 32
buf := make([]byte, maxWindowSize)
tc, s := newTestConnAndRemoteStream(t, serverSide, uniStream, func(c *Config) {
c.MaxConnReadBufferSize = 32
})
// We send MAX_DATA = 63.
tc.writeFrames(packetType1RTT, debugFrameStream{
id: s.id,
off: 0,
data: make([]byte, maxWindowSize-1),
})
if n, err := s.Read(buf[:maxWindowSize]); err != nil || n != maxWindowSize-1 {
t.Fatalf("Read() = %v, %v; want %v, nil", n, err, maxWindowSize-1)
}
tc.wantFrame("conn window is extended after reading data",
packetType1RTT, debugFrameMaxData{
max: (maxWindowSize * 2) - 1,
})
// MAX_DATA = 64, which is only one more byte, so we don't send the frame.
tc.writeFrames(packetType1RTT, debugFrameStream{
id: s.id,
off: maxWindowSize - 1,
data: make([]byte, 1),
})
if n, err := s.Read(buf[:1]); err != nil || n != 1 {
t.Fatalf("Read() = %v, %v; want %v, nil", n, err, 1)
}
tc.wantIdle("read doesn't extend window enough to send another MAX_DATA")
// The MAX_DATA = 63 packet was lost, so we send 64.
tc.triggerLossOrPTO(packetType1RTT, pto)
tc.wantFrame("resent MAX_DATA includes most current value",
packetType1RTT, debugFrameMaxData{
max: maxWindowSize * 2,
})
})
}
func TestLostMaxStreamDataFrame(t *testing.T) {
// "[...] an updated value is sent when the packet containing
// the most recent MAX_STREAM_DATA frame for a stream is lost"
// https://www.rfc-editor.org/rfc/rfc9000#section-13.3-3.8
lostFrameTest(t, func(t *testing.T, pto bool) {
const maxWindowSize = 32
buf := make([]byte, maxWindowSize)
tc, s := newTestConnAndRemoteStream(t, serverSide, uniStream, func(c *Config) {
c.MaxStreamReadBufferSize = maxWindowSize
})
// We send MAX_STREAM_DATA = 63.
tc.writeFrames(packetType1RTT, debugFrameStream{
id: s.id,
off: 0,
data: make([]byte, maxWindowSize-1),
})
if n, err := s.Read(buf[:maxWindowSize]); err != nil || n != maxWindowSize-1 {
t.Fatalf("Read() = %v, %v; want %v, nil", n, err, maxWindowSize-1)
}
tc.wantFrame("stream window is extended after reading data",
packetType1RTT, debugFrameMaxStreamData{
id: s.id,
max: (maxWindowSize * 2) - 1,
})
// MAX_STREAM_DATA = 64, which is only one more byte, so we don't send the frame.
tc.writeFrames(packetType1RTT, debugFrameStream{
id: s.id,
off: maxWindowSize - 1,
data: make([]byte, 1),
})
if n, err := s.Read(buf); err != nil || n != 1 {
t.Fatalf("Read() = %v, %v; want %v, nil", n, err, 1)
}
tc.wantIdle("read doesn't extend window enough to send another MAX_STREAM_DATA")
// The MAX_STREAM_DATA = 63 packet was lost, so we send 64.
tc.triggerLossOrPTO(packetType1RTT, pto)
tc.wantFrame("resent MAX_STREAM_DATA includes most current value",
packetType1RTT, debugFrameMaxStreamData{
id: s.id,
max: maxWindowSize * 2,
})
})
}
func TestLostMaxStreamDataFrameAfterStreamFinReceived(t *testing.T) {
// "An endpoint SHOULD stop sending MAX_STREAM_DATA frames when
// the receiving part of the stream enters a "Size Known" or "Reset Recvd" state."
// https://www.rfc-editor.org/rfc/rfc9000#section-13.3-3.8
lostFrameTest(t, func(t *testing.T, pto bool) {
const maxWindowSize = 10
buf := make([]byte, maxWindowSize)
tc, s := newTestConnAndRemoteStream(t, serverSide, uniStream, func(c *Config) {
c.MaxStreamReadBufferSize = maxWindowSize
})
tc.writeFrames(packetType1RTT, debugFrameStream{
id: s.id,
off: 0,
data: make([]byte, maxWindowSize),
})
if n, err := s.Read(buf); err != nil || n != maxWindowSize {
t.Fatalf("Read() = %v, %v; want %v, nil", n, err, maxWindowSize)
}
tc.wantFrame("stream window is extended after reading data",
packetType1RTT, debugFrameMaxStreamData{
id: s.id,
max: 2 * maxWindowSize,
})
tc.writeFrames(packetType1RTT, debugFrameStream{
id: s.id,
off: maxWindowSize,
fin: true,
})
tc.ignoreFrame(frameTypePing)
tc.triggerLossOrPTO(packetType1RTT, pto)
tc.wantIdle("lost MAX_STREAM_DATA not resent for stream in 'size known'")
})
}
func TestLostMaxStreamsFrameMostRecent(t *testing.T) {
// "[...] an updated value is sent when a packet containing the
// most recent MAX_STREAMS for a stream type frame is declared lost [...]"
// https://www.rfc-editor.org/rfc/rfc9000#section-13.3-3.9
testStreamTypes(t, "", func(t *testing.T, styp streamType) {
lostFrameTest(t, func(t *testing.T, pto bool) {
ctx := canceledContext()
tc := newTestConn(t, serverSide, func(c *Config) {
c.MaxUniRemoteStreams = 1
c.MaxBidiRemoteStreams = 1
})
tc.handshake()
tc.ignoreFrame(frameTypeAck)
tc.writeFrames(packetType1RTT, debugFrameStream{
id: newStreamID(clientSide, styp, 0),
fin: true,
})
s, err := tc.conn.AcceptStream(ctx)
if err != nil {
t.Fatalf("AcceptStream() = %v", err)
}
s.SetWriteContext(ctx)
s.Close()
if styp == bidiStream {
tc.wantFrame("stream is closed",
packetType1RTT, debugFrameStream{
id: s.id,
data: []byte{},
fin: true,
})
tc.writeAckForAll()
}
tc.wantFrame("closing stream updates peer's MAX_STREAMS",
packetType1RTT, debugFrameMaxStreams{
streamType: styp,
max: 2,
})
tc.triggerLossOrPTO(packetType1RTT, pto)
tc.wantFrame("lost MAX_STREAMS is resent",
packetType1RTT, debugFrameMaxStreams{
streamType: styp,
max: 2,
})
})
})
}
func TestLostMaxStreamsFrameNotMostRecent(t *testing.T) {
// Send two MAX_STREAMS frames, lose the first one.
//
// No PTO mode for this test: The ack that causes the first frame
// to be lost arms the loss timer for the second, so the PTO timer is not armed.
const pto = false
ctx := canceledContext()
tc := newTestConn(t, serverSide, func(c *Config) {
c.MaxUniRemoteStreams = 2
})
tc.handshake()
tc.ignoreFrame(frameTypeAck)
for i := int64(0); i < 2; i++ {
tc.writeFrames(packetType1RTT, debugFrameStream{
id: newStreamID(clientSide, uniStream, i),
fin: true,
})
s, err := tc.conn.AcceptStream(ctx)
if err != nil {
t.Fatalf("AcceptStream() = %v", err)
}
if err := s.Close(); err != nil {
t.Fatalf("stream.Close() = %v", err)
}
tc.wantFrame("closing stream updates peer's MAX_STREAMS",
packetType1RTT, debugFrameMaxStreams{
streamType: uniStream,
max: 3 + i,
})
}
// The second MAX_STREAMS frame is acked.
tc.writeAckForLatest()
// The first MAX_STREAMS frame is lost.
tc.conn.ping(appDataSpace)
tc.wantFrame("connection should send a PING frame",
packetType1RTT, debugFramePing{})
tc.triggerLossOrPTO(packetType1RTT, pto)
tc.wantIdle("superseded MAX_DATA is not resent on loss")
}
func TestLostStreamDataBlockedFrame(t *testing.T) {
// "A new [STREAM_DATA_BLOCKED] frame is sent if a packet containing
// the most recent frame for a scope is lost [...]"
// https://www.rfc-editor.org/rfc/rfc9000#section-13.3-3.10
lostFrameTest(t, func(t *testing.T, pto bool) {
tc, s := newTestConnAndLocalStream(t, serverSide, uniStream, func(p *transportParameters) {
p.initialMaxStreamsUni = 1
p.initialMaxData = 1 << 20
})
w := runAsync(tc, func(ctx context.Context) (int, error) {
return s.Write([]byte{0, 1, 2, 3})
})
defer w.cancel()
tc.wantFrame("write is blocked by flow control",
packetType1RTT, debugFrameStreamDataBlocked{
id: s.id,
max: 0,
})
tc.writeFrames(packetType1RTT, debugFrameMaxStreamData{
id: s.id,
max: 1,
})
tc.wantFrame("write makes some progress, but is still blocked by flow control",
packetType1RTT, debugFrameStreamDataBlocked{
id: s.id,
max: 1,
})
tc.wantFrame("write consuming available window",
packetType1RTT, debugFrameStream{
id: s.id,
off: 0,
data: []byte{0},
})
tc.triggerLossOrPTO(packetType1RTT, pto)
tc.wantFrame("STREAM_DATA_BLOCKED is resent",
packetType1RTT, debugFrameStreamDataBlocked{
id: s.id,
max: 1,
})
tc.wantFrame("STREAM is resent as well",
packetType1RTT, debugFrameStream{
id: s.id,
off: 0,
data: []byte{0},
})
})
}
func TestLostStreamDataBlockedFrameAfterStreamUnblocked(t *testing.T) {
// "A new [STREAM_DATA_BLOCKED] frame is sent [...] only while
// the endpoint is blocked on the corresponding limit."
// https://www.rfc-editor.org/rfc/rfc9000#section-13.3-3.10
lostFrameTest(t, func(t *testing.T, pto bool) {
tc, s := newTestConnAndLocalStream(t, serverSide, uniStream, func(p *transportParameters) {
p.initialMaxStreamsUni = 1
p.initialMaxData = 1 << 20
})
data := []byte{0, 1, 2, 3}
w := runAsync(tc, func(ctx context.Context) (int, error) {
return s.Write(data)
})
defer w.cancel()
tc.wantFrame("write is blocked by flow control",
packetType1RTT, debugFrameStreamDataBlocked{
id: s.id,
max: 0,
})
tc.writeFrames(packetType1RTT, debugFrameMaxStreamData{
id: s.id,
max: 10,
})
tc.wantFrame("write completes after flow control available",
packetType1RTT, debugFrameStream{
id: s.id,
off: 0,
data: data,
})
tc.triggerLossOrPTO(packetType1RTT, pto)
tc.wantFrame("STREAM data is resent",
packetType1RTT, debugFrameStream{
id: s.id,
off: 0,
data: data,
})
tc.wantIdle("STREAM_DATA_BLOCKED is not resent, since the stream is not blocked")
})
}
func TestLostNewConnectionIDFrame(t *testing.T) {
// "New connection IDs are [...] retransmitted if the packet containing them is lost."
// https://www.rfc-editor.org/rfc/rfc9000#section-13.3-3.13
lostFrameTest(t, func(t *testing.T, pto bool) {
tc := newTestConn(t, serverSide)
tc.handshake()
tc.ignoreFrame(frameTypeAck)
tc.writeFrames(packetType1RTT,
debugFrameRetireConnectionID{
seq: 1,
})
tc.wantFrame("provide a new connection ID after peer retires old one",
packetType1RTT, debugFrameNewConnectionID{
seq: 2,
connID: testLocalConnID(2),
token: testLocalStatelessResetToken(2),
})
tc.triggerLossOrPTO(packetType1RTT, pto)
tc.wantFrame("resend new connection ID",
packetType1RTT, debugFrameNewConnectionID{
seq: 2,
connID: testLocalConnID(2),
token: testLocalStatelessResetToken(2),
})
})
}
func TestLostRetireConnectionIDFrame(t *testing.T) {
// "[...] retired connection IDs are [...] retransmitted
// if the packet containing them is lost."
// https://www.rfc-editor.org/rfc/rfc9000#section-13.3-3.13
lostFrameTest(t, func(t *testing.T, pto bool) {
tc := newTestConn(t, clientSide)
tc.handshake()
tc.ignoreFrame(frameTypeAck)
tc.writeFrames(packetType1RTT,
debugFrameNewConnectionID{
seq: 2,
retirePriorTo: 1,
connID: testPeerConnID(2),
})
tc.wantFrame("peer requested connection id be retired",
packetType1RTT, debugFrameRetireConnectionID{
seq: 0,
})
tc.triggerLossOrPTO(packetType1RTT, pto)
tc.wantFrame("resend RETIRE_CONNECTION_ID",
packetType1RTT, debugFrameRetireConnectionID{
seq: 0,
})
})
}
func TestLostPathResponseFrame(t *testing.T) {
// "Responses to path validation using PATH_RESPONSE frames are sent just once."
// https://www.rfc-editor.org/rfc/rfc9000.html#section-13.3-3.12
lostFrameTest(t, func(t *testing.T, pto bool) {
tc := newTestConn(t, clientSide)
tc.handshake()
tc.ignoreFrame(frameTypeAck)
tc.ignoreFrame(frameTypePing)
data := pathChallengeData{0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}
tc.writeFrames(packetType1RTT, debugFramePathChallenge{
data: data,
})
tc.wantFrame("response to PATH_CHALLENGE",
packetType1RTT, debugFramePathResponse{
data: data,
})
tc.triggerLossOrPTO(packetType1RTT, pto)
tc.wantIdle("lost PATH_RESPONSE frame is not retransmitted")
})
}
func TestLostHandshakeDoneFrame(t *testing.T) {
// "The HANDSHAKE_DONE frame MUST be retransmitted until it is acknowledged."
// https://www.rfc-editor.org/rfc/rfc9000.html#section-13.3-3.16
lostFrameTest(t, func(t *testing.T, pto bool) {
tc := newTestConn(t, serverSide)
tc.ignoreFrame(frameTypeAck)
tc.writeFrames(packetTypeInitial,
debugFrameCrypto{
data: tc.cryptoDataIn[tls.QUICEncryptionLevelInitial],
})
tc.wantFrame("server sends Initial CRYPTO frame",
packetTypeInitial, debugFrameCrypto{
data: tc.cryptoDataOut[tls.QUICEncryptionLevelInitial],
})
tc.wantFrame("server sends Handshake CRYPTO frame",
packetTypeHandshake, debugFrameCrypto{
data: tc.cryptoDataOut[tls.QUICEncryptionLevelHandshake],
})
tc.wantFrame("server provides an additional connection ID",
packetType1RTT, debugFrameNewConnectionID{
seq: 1,
connID: testLocalConnID(1),
token: testLocalStatelessResetToken(1),
})
tc.writeFrames(packetTypeHandshake,
debugFrameCrypto{
data: tc.cryptoDataIn[tls.QUICEncryptionLevelHandshake],
})
tc.wantFrame("server sends HANDSHAKE_DONE after handshake completes",
packetType1RTT, debugFrameHandshakeDone{})
tc.triggerLossOrPTO(packetType1RTT, pto)
tc.wantFrame("server resends HANDSHAKE_DONE",
packetType1RTT, debugFrameHandshakeDone{})
})
}