From 4332436fd1223b60e3127494d5ff771fba2c0adf Mon Sep 17 00:00:00 2001 From: Damien Neil Date: Wed, 16 Aug 2023 08:57:37 -0400 Subject: [PATCH] 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 TryBot-Result: Gopher Robot Reviewed-by: Jonathan Amsterdam --- internal/quic/config_test.go | 32 ++++++++++++++++++++++++++++++++ internal/quic/conn.go | 14 ++++++++++---- internal/quic/conn_test.go | 10 ++++++++++ 3 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 internal/quic/config_test.go diff --git a/internal/quic/config_test.go b/internal/quic/config_test.go new file mode 100644 index 0000000000..cec57c5e36 --- /dev/null +++ b/internal/quic/config_test.go @@ -0,0 +1,32 @@ +// 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" + +func TestConfigTransportParameters(t *testing.T) { + const ( + wantInitialMaxStreamData = int64(2) + ) + tc := newTestConn(t, clientSide, func(c *Config) { + c.StreamReadBufferSize = wantInitialMaxStreamData + }) + tc.handshake() + if tc.sentTransportParameters == nil { + t.Fatalf("conn didn't send transport parameters during handshake") + } + p := tc.sentTransportParameters + if got, want := p.initialMaxStreamDataBidiLocal, wantInitialMaxStreamData; got != want { + t.Errorf("initial_max_stream_data_bidi_local = %v, want %v", got, want) + } + if got, want := p.initialMaxStreamDataBidiRemote, wantInitialMaxStreamData; got != want { + t.Errorf("initial_max_stream_data_bidi_remote = %v, want %v", got, want) + } + if got, want := p.initialMaxStreamDataUni, wantInitialMaxStreamData; got != want { + t.Errorf("initial_max_stream_data_uni = %v, want %v", got, want) + } +} diff --git a/internal/quic/conn.go b/internal/quic/conn.go index ee8f011f8a..04dcd7b6bb 100644 --- a/internal/quic/conn.go +++ b/internal/quic/conn.go @@ -111,11 +111,17 @@ func newConn(now time.Time, side connSide, initialConnID []byte, peerAddr netip. c.loss.init(c.side, maxDatagramSize, now) c.streamsInit() + // TODO: initial_source_connection_id, retry_source_connection_id c.startTLS(now, initialConnID, transportParameters{ - initialSrcConnID: c.connIDState.srcConnID(), - ackDelayExponent: ackDelayExponent, - maxUDPPayloadSize: maxUDPPayloadSize, - maxAckDelay: maxAckDelay, + initialSrcConnID: c.connIDState.srcConnID(), + ackDelayExponent: ackDelayExponent, + maxUDPPayloadSize: maxUDPPayloadSize, + maxAckDelay: maxAckDelay, + disableActiveMigration: true, + initialMaxStreamDataBidiLocal: config.streamReadBufferSize(), + initialMaxStreamDataBidiRemote: config.streamReadBufferSize(), + initialMaxStreamDataUni: config.streamReadBufferSize(), + activeConnIDLimit: activeConnIDLimit, }) go c.loop(now) diff --git a/internal/quic/conn_test.go b/internal/quic/conn_test.go index 2aa38fcf3d..8ebe49e0e5 100644 --- a/internal/quic/conn_test.go +++ b/internal/quic/conn_test.go @@ -142,6 +142,9 @@ type testConn struct { sentFrames []debugFrame lastPacket *testPacket + // Transport parameters sent by the conn. + sentTransportParameters *transportParameters + // Frame types to ignore in tests. ignoreFrames map[byte]bool @@ -719,6 +722,13 @@ func (tc *testConnHooks) handleTLSEvent(e tls.QUICEvent) { setKey(&tc.rkeys, e) case tls.QUICWriteData: tc.cryptoDataIn[e.Level] = append(tc.cryptoDataIn[e.Level], e.Data...) + case tls.QUICTransportParameters: + p, err := unmarshalTransportParams(e.Data) + if err != nil { + tc.t.Logf("sent unparseable transport parameters %x %v", e.Data, err) + } else { + tc.sentTransportParameters = &p + } } } }