Skip to content

Commit

Permalink
Make max datagram frame size configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
DevinCarr committed May 2, 2023
1 parent 6b74a9a commit d1f4eda
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
5 changes: 5 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ func populateConfig(config *Config) *Config {
} else if maxIncomingUniStreams < 0 {
maxIncomingUniStreams = 0
}
maxDatagrameFrameSize := config.MaxDatagramFrameSize
if maxDatagrameFrameSize == 0 {
maxDatagrameFrameSize = int64(protocol.DefaultMaxDatagramFrameSize)
}

return &Config{
GetConfigForClient: config.GetConfigForClient,
Expand All @@ -120,6 +124,7 @@ func populateConfig(config *Config) *Config {
MaxIncomingUniStreams: maxIncomingUniStreams,
TokenStore: config.TokenStore,
EnableDatagrams: config.EnableDatagrams,
MaxDatagramFrameSize: maxDatagrameFrameSize,
DisablePathMTUDiscovery: config.DisablePathMTUDiscovery,
DisableVersionNegotiationPackets: config.DisableVersionNegotiationPackets,
Allow0RTT: config.Allow0RTT,
Expand Down
3 changes: 3 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ var _ = Describe("Config", func() {
f.Set(reflect.ValueOf(time.Second))
case "EnableDatagrams":
f.Set(reflect.ValueOf(true))
case "MaxDatagramFrameSize":
f.Set(reflect.ValueOf(int64(1200)))
case "DisableVersionNegotiationPackets":
f.Set(reflect.ValueOf(true))
case "DisablePathMTUDiscovery":
Expand Down Expand Up @@ -175,6 +177,7 @@ var _ = Describe("Config", func() {
Expect(c.MaxIncomingUniStreams).To(BeEquivalentTo(protocol.DefaultMaxIncomingUniStreams))
Expect(c.DisableVersionNegotiationPackets).To(BeFalse())
Expect(c.DisablePathMTUDiscovery).To(BeFalse())
Expect(c.MaxDatagramFrameSize).To(BeEquivalentTo(protocol.DefaultMaxDatagramFrameSize))
Expect(c.GetConfigForClient).To(BeNil())
})

Expand Down
6 changes: 3 additions & 3 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ var newConnection = func(
RetrySourceConnectionID: retrySrcConnID,
}
if s.config.EnableDatagrams {
params.MaxDatagramFrameSize = protocol.MaxDatagramFrameSize
params.MaxDatagramFrameSize = protocol.ByteCount(s.config.MaxDatagramFrameSize)
} else {
params.MaxDatagramFrameSize = protocol.InvalidByteCount
}
Expand Down Expand Up @@ -430,7 +430,7 @@ var newClientConnection = func(
InitialSourceConnectionID: srcConnID,
}
if s.config.EnableDatagrams {
params.MaxDatagramFrameSize = protocol.MaxDatagramFrameSize
params.MaxDatagramFrameSize = protocol.ByteCount(s.config.MaxDatagramFrameSize)
} else {
params.MaxDatagramFrameSize = protocol.InvalidByteCount
}
Expand Down Expand Up @@ -1493,7 +1493,7 @@ func (s *connection) handleAckFrame(frame *wire.AckFrame, encLevel protocol.Encr
}

func (s *connection) handleDatagramFrame(f *wire.DatagramFrame) error {
if f.Length(s.version) > protocol.MaxDatagramFrameSize {
if f.Length(s.version) > protocol.ByteCount(s.config.MaxDatagramFrameSize) {
return &qerr.TransportError{
ErrorCode: qerr.ProtocolViolation,
ErrorMessage: "DATAGRAM frame too large",
Expand Down
4 changes: 3 additions & 1 deletion interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,9 @@ type Config struct {
Allow0RTT bool
// Enable QUIC datagram support (RFC 9221).
EnableDatagrams bool
Tracer func(context.Context, logging.Perspective, ConnectionID) logging.ConnectionTracer
// Maximum size of QUIC datagram frames (RFC 9221).
MaxDatagramFrameSize int64
Tracer func(context.Context, logging.Perspective, ConnectionID) logging.ConnectionTracer
}

type ClientHelloInfo struct {
Expand Down
4 changes: 2 additions & 2 deletions internal/protocol/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ const MaxPostHandshakeCryptoFrameSize = 1000
// but must ensure that a maximum size ACK frame fits into one packet.
const MaxAckFrameSize ByteCount = 1000

// MaxDatagramFrameSize is the maximum size of a DATAGRAM frame (RFC 9221).
// DefaultMaxDatagramFrameSize is the maximum size of a DATAGRAM frame (RFC 9221).
// The size is chosen such that a DATAGRAM frame fits into a QUIC packet.
const MaxDatagramFrameSize ByteCount = 1200
const DefaultMaxDatagramFrameSize ByteCount = 1200

// DatagramRcvQueueLen is the length of the receive queue for DATAGRAM frames (RFC 9221)
const DatagramRcvQueueLen = 128
Expand Down

0 comments on commit d1f4eda

Please sign in to comment.