diff --git a/quic/datagramv2.go b/quic/datagramv2.go index 7e2fce89..5a3e998c 100644 --- a/quic/datagramv2.go +++ b/quic/datagramv2.go @@ -14,14 +14,15 @@ import ( type datagramV2Type byte const ( - udp datagramV2Type = iota + typeIDLen = 1 + udp datagramV2Type = iota ip // Same as sessionDemuxChan capacity packetChanCapacity = 16 ) func suffixType(b []byte, datagramType datagramV2Type) ([]byte, error) { - if len(b)+1 > MaxDatagramFrameSize { + if len(b)+typeIDLen > MaxDatagramFrameSize { return nil, fmt.Errorf("datagram size %d exceeds max frame size %d", len(b), MaxDatagramFrameSize) } b = append(b, byte(datagramType)) @@ -114,11 +115,11 @@ func (dm *DatagramMuxerV2) ReceivePacket(ctx context.Context) (packet.RawPacket, } func (dm *DatagramMuxerV2) demux(ctx context.Context, msgWithType []byte) error { - if len(msgWithType) < 1 { - return fmt.Errorf("QUIC datagram should have at least 1 byte") + if len(msgWithType) < typeIDLen { + return fmt.Errorf("QUIC datagram should have at least %d byte", typeIDLen) } - msgType := datagramV2Type(msgWithType[len(msgWithType)-1]) - msg := msgWithType[0 : len(msgWithType)-1] + msgType := datagramV2Type(msgWithType[len(msgWithType)-typeIDLen]) + msg := msgWithType[0 : len(msgWithType)-typeIDLen] switch msgType { case udp: return dm.handleSession(ctx, msg) diff --git a/quic/param_windows.go b/quic/param_windows.go index 246e83de..13b29ed0 100644 --- a/quic/param_windows.go +++ b/quic/param_windows.go @@ -7,5 +7,5 @@ const ( // 1220 is the default value https://github.com/lucas-clemente/quic-go/blob/84e03e59760ceee37359688871bb0688fcc4e98f/internal/protocol/params.go#L138 MaxDatagramFrameSize = 1220 // 3 more bytes are reserved at https://github.com/lucas-clemente/quic-go/blob/v0.24.0/internal/wire/datagram_frame.go#L61 - maxDatagramPayloadSize = MaxDatagramFrameSize - 3 - sessionIDLen + maxDatagramPayloadSize = MaxDatagramFrameSize - 3 - sessionIDLen - typeIDLen )