@@ -14,14 +14,15 @@ import (
1414type datagramV2Type byte
1515
1616const (
17- udp datagramV2Type = iota
17+ typeIDLen = 1
18+ udp datagramV2Type = iota
1819 ip
1920 // Same as sessionDemuxChan capacity
2021 packetChanCapacity = 16
2122)
2223
2324func suffixType (b []byte , datagramType datagramV2Type ) ([]byte , error ) {
24- if len (b )+ 1 > MaxDatagramFrameSize {
25+ if len (b )+ typeIDLen > MaxDatagramFrameSize {
2526 return nil , fmt .Errorf ("datagram size %d exceeds max frame size %d" , len (b ), MaxDatagramFrameSize )
2627 }
2728 b = append (b , byte (datagramType ))
@@ -114,11 +115,11 @@ func (dm *DatagramMuxerV2) ReceivePacket(ctx context.Context) (packet.RawPacket,
114115}
115116
116117func (dm * DatagramMuxerV2 ) demux (ctx context.Context , msgWithType []byte ) error {
117- if len (msgWithType ) < 1 {
118- return fmt .Errorf ("QUIC datagram should have at least 1 byte" )
118+ if len (msgWithType ) < typeIDLen {
119+ return fmt .Errorf ("QUIC datagram should have at least %d byte" , typeIDLen )
119120 }
120- msgType := datagramV2Type (msgWithType [len (msgWithType )- 1 ])
121- msg := msgWithType [0 : len (msgWithType )- 1 ]
121+ msgType := datagramV2Type (msgWithType [len (msgWithType )- typeIDLen ])
122+ msg := msgWithType [0 : len (msgWithType )- typeIDLen ]
122123 switch msgType {
123124 case udp :
124125 return dm .handleSession (ctx , msg )
0 commit comments