Skip to content

Commit

Permalink
quic: send more transport parameters
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
neild committed Aug 29, 2023
1 parent 52fbe37 commit 4332436
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
32 changes: 32 additions & 0 deletions internal/quic/config_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
14 changes: 10 additions & 4 deletions internal/quic/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions internal/quic/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}
}
}
}
Expand Down

0 comments on commit 4332436

Please sign in to comment.