Skip to content

Commit 4332436

Browse files
committedAug 29, 2023
quic: send more transport parameters
Send various transport parameters that we weren't sending yet, but should have been. Add a test for transport parameters sent by us. For golang/go#58547 Change-Id: Id16c46ee39040b091633aca8d4cff4c60562a603 Reviewed-on: https://go-review.googlesource.com/c/net/+/523575 Run-TryBot: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Jonathan Amsterdam <jba@google.com>
1 parent 52fbe37 commit 4332436

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed
 

‎internal/quic/config_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2023 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
//go:build go1.21
6+
7+
package quic
8+
9+
import "testing"
10+
11+
func TestConfigTransportParameters(t *testing.T) {
12+
const (
13+
wantInitialMaxStreamData = int64(2)
14+
)
15+
tc := newTestConn(t, clientSide, func(c *Config) {
16+
c.StreamReadBufferSize = wantInitialMaxStreamData
17+
})
18+
tc.handshake()
19+
if tc.sentTransportParameters == nil {
20+
t.Fatalf("conn didn't send transport parameters during handshake")
21+
}
22+
p := tc.sentTransportParameters
23+
if got, want := p.initialMaxStreamDataBidiLocal, wantInitialMaxStreamData; got != want {
24+
t.Errorf("initial_max_stream_data_bidi_local = %v, want %v", got, want)
25+
}
26+
if got, want := p.initialMaxStreamDataBidiRemote, wantInitialMaxStreamData; got != want {
27+
t.Errorf("initial_max_stream_data_bidi_remote = %v, want %v", got, want)
28+
}
29+
if got, want := p.initialMaxStreamDataUni, wantInitialMaxStreamData; got != want {
30+
t.Errorf("initial_max_stream_data_uni = %v, want %v", got, want)
31+
}
32+
}

‎internal/quic/conn.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,17 @@ func newConn(now time.Time, side connSide, initialConnID []byte, peerAddr netip.
111111
c.loss.init(c.side, maxDatagramSize, now)
112112
c.streamsInit()
113113

114+
// TODO: initial_source_connection_id, retry_source_connection_id
114115
c.startTLS(now, initialConnID, transportParameters{
115-
initialSrcConnID: c.connIDState.srcConnID(),
116-
ackDelayExponent: ackDelayExponent,
117-
maxUDPPayloadSize: maxUDPPayloadSize,
118-
maxAckDelay: maxAckDelay,
116+
initialSrcConnID: c.connIDState.srcConnID(),
117+
ackDelayExponent: ackDelayExponent,
118+
maxUDPPayloadSize: maxUDPPayloadSize,
119+
maxAckDelay: maxAckDelay,
120+
disableActiveMigration: true,
121+
initialMaxStreamDataBidiLocal: config.streamReadBufferSize(),
122+
initialMaxStreamDataBidiRemote: config.streamReadBufferSize(),
123+
initialMaxStreamDataUni: config.streamReadBufferSize(),
124+
activeConnIDLimit: activeConnIDLimit,
119125
})
120126

121127
go c.loop(now)

‎internal/quic/conn_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ type testConn struct {
142142
sentFrames []debugFrame
143143
lastPacket *testPacket
144144

145+
// Transport parameters sent by the conn.
146+
sentTransportParameters *transportParameters
147+
145148
// Frame types to ignore in tests.
146149
ignoreFrames map[byte]bool
147150

@@ -719,6 +722,13 @@ func (tc *testConnHooks) handleTLSEvent(e tls.QUICEvent) {
719722
setKey(&tc.rkeys, e)
720723
case tls.QUICWriteData:
721724
tc.cryptoDataIn[e.Level] = append(tc.cryptoDataIn[e.Level], e.Data...)
725+
case tls.QUICTransportParameters:
726+
p, err := unmarshalTransportParams(e.Data)
727+
if err != nil {
728+
tc.t.Logf("sent unparseable transport parameters %x %v", e.Data, err)
729+
} else {
730+
tc.sentTransportParameters = &p
731+
}
722732
}
723733
}
724734
}

0 commit comments

Comments
 (0)