Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wire: write configured value of max_udp_payload_size transport parameter #4501

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ var newConnection = func(
MaxUniStreamNum: protocol.StreamNum(s.config.MaxIncomingUniStreams),
MaxAckDelay: protocol.MaxAckDelayInclGranularity,
AckDelayExponent: protocol.AckDelayExponent,
MaxUDPPayloadSize: protocol.MaxPacketBufferSize,
DisableActiveMigration: true,
StatelessResetToken: &statelessResetToken,
OriginalDestinationConnectionID: origDestConnID,
Expand Down Expand Up @@ -410,6 +411,7 @@ var newClientConnection = func(
MaxBidiStreamNum: protocol.StreamNum(s.config.MaxIncomingStreams),
MaxUniStreamNum: protocol.StreamNum(s.config.MaxIncomingUniStreams),
MaxAckDelay: protocol.MaxAckDelayInclGranularity,
MaxUDPPayloadSize: protocol.MaxPacketBufferSize,
AckDelayExponent: protocol.AckDelayExponent,
DisableActiveMigration: true,
// For interoperability with quic-go versions before May 2023, this value must be set to a value
Expand Down
14 changes: 8 additions & 6 deletions internal/wire/transport_parameter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func getRandomValueUpTo(max int64) uint64 {
}

func getRandomValue() uint64 {
return getRandomValueUpTo(math.MaxInt64)
return getRandomValueUpTo(quicvarint.Max)
}

var _ = Describe("Transport Parameters", func() {
Expand Down Expand Up @@ -102,7 +102,8 @@ var _ = Describe("Transport Parameters", func() {
RetrySourceConnectionID: &rcid,
AckDelayExponent: 13,
MaxAckDelay: 42 * time.Millisecond,
ActiveConnectionIDLimit: 2 + getRandomValueUpTo(math.MaxInt64-2),
ActiveConnectionIDLimit: 2 + getRandomValueUpTo(quicvarint.Max-2),
MaxUDPPayloadSize: 1200 + protocol.ByteCount(getRandomValueUpTo(quicvarint.Max-1200)),
MaxDatagramFrameSize: protocol.ByteCount(getRandomValue()),
}
data := params.Marshal(protocol.PerspectiveServer)
Expand All @@ -124,6 +125,7 @@ var _ = Describe("Transport Parameters", func() {
Expect(p.AckDelayExponent).To(Equal(uint8(13)))
Expect(p.MaxAckDelay).To(Equal(42 * time.Millisecond))
Expect(p.ActiveConnectionIDLimit).To(Equal(params.ActiveConnectionIDLimit))
Expect(p.MaxUDPPayloadSize).To(Equal(params.MaxUDPPayloadSize))
Expect(p.MaxDatagramFrameSize).To(Equal(params.MaxDatagramFrameSize))
})

Expand Down Expand Up @@ -176,13 +178,13 @@ var _ = Describe("Transport Parameters", func() {
}))
})

It("errors when the max_packet_size is too small", func() {
It("errors when the max_udp_payload_size is too small", func() {
b := quicvarint.Append(nil, uint64(maxUDPPayloadSizeParameterID))
b = quicvarint.Append(b, uint64(quicvarint.Len(1199)))
b = quicvarint.Append(b, 1199)
Expect((&TransportParameters{}).Unmarshal(b, protocol.PerspectiveServer)).To(MatchError(&qerr.TransportError{
ErrorCode: qerr.TransportParameterError,
ErrorMessage: "invalid value for max_packet_size: 1199 (minimum 1200)",
ErrorMessage: "invalid value for max_udp_payload_size: 1199 (minimum 1200)",
}))
})

Expand Down Expand Up @@ -499,7 +501,7 @@ var _ = Describe("Transport Parameters", func() {
InitialMaxData: protocol.ByteCount(getRandomValue()),
MaxBidiStreamNum: protocol.StreamNum(getRandomValueUpTo(int64(protocol.MaxStreamCount))),
MaxUniStreamNum: protocol.StreamNum(getRandomValueUpTo(int64(protocol.MaxStreamCount))),
ActiveConnectionIDLimit: 2 + getRandomValueUpTo(math.MaxInt64-2),
ActiveConnectionIDLimit: 2 + getRandomValueUpTo(quicvarint.Max-2),
MaxDatagramFrameSize: protocol.ByteCount(getRandomValueUpTo(int64(MaxDatagramSize))),
}
Expect(params.ValidFor0RTT(params)).To(BeTrue())
Expand Down Expand Up @@ -748,7 +750,7 @@ func benchmarkTransportParameters(b *testing.B, withPreferredAddress bool) {
RetrySourceConnectionID: &rcid,
AckDelayExponent: 13,
MaxAckDelay: 42 * time.Millisecond,
ActiveConnectionIDLimit: 2 + getRandomValueUpTo(math.MaxInt64-2),
ActiveConnectionIDLimit: 2 + getRandomValueUpTo(quicvarint.Max-2),
MaxDatagramFrameSize: protocol.ByteCount(getRandomValue()),
}
var token2 protocol.StatelessResetToken
Expand Down
8 changes: 5 additions & 3 deletions internal/wire/transport_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func (p *TransportParameters) readNumericTransportParameter(b []byte, paramID tr
p.MaxIdleTimeout = max(protocol.MinRemoteIdleTimeout, time.Duration(val)*time.Millisecond)
case maxUDPPayloadSizeParameterID:
if val < 1200 {
return fmt.Errorf("invalid value for max_packet_size: %d (minimum 1200)", val)
return fmt.Errorf("invalid value for max_udp_payload_size: %d (minimum 1200)", val)
}
p.MaxUDPPayloadSize = protocol.ByteCount(val)
case ackDelayExponentParameterID:
Expand Down Expand Up @@ -357,8 +357,10 @@ func (p *TransportParameters) Marshal(pers protocol.Perspective) []byte {
b = p.marshalVarintParam(b, initialMaxStreamsUniParameterID, uint64(p.MaxUniStreamNum))
// idle_timeout
b = p.marshalVarintParam(b, maxIdleTimeoutParameterID, uint64(p.MaxIdleTimeout/time.Millisecond))
// max_packet_size
b = p.marshalVarintParam(b, maxUDPPayloadSizeParameterID, uint64(protocol.MaxPacketBufferSize))
// max_udp_payload_size
if p.MaxUDPPayloadSize > 0 {
b = p.marshalVarintParam(b, maxUDPPayloadSizeParameterID, uint64(p.MaxUDPPayloadSize))
}
// max_ack_delay
// Only send it if is different from the default value.
if p.MaxAckDelay != protocol.DefaultMaxAckDelay {
Expand Down
Loading