TUN-6726: Fix maxDatagramPayloadSize for Windows QUIC datagrams
This commit is contained in:
parent
4ac68711cd
commit
7ca5f7569a
|
@ -14,14 +14,15 @@ import (
|
||||||
type datagramV2Type byte
|
type datagramV2Type byte
|
||||||
|
|
||||||
const (
|
const (
|
||||||
udp datagramV2Type = iota
|
typeIDLen = 1
|
||||||
|
udp datagramV2Type = iota
|
||||||
ip
|
ip
|
||||||
// Same as sessionDemuxChan capacity
|
// Same as sessionDemuxChan capacity
|
||||||
packetChanCapacity = 16
|
packetChanCapacity = 16
|
||||||
)
|
)
|
||||||
|
|
||||||
func suffixType(b []byte, datagramType datagramV2Type) ([]byte, error) {
|
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)
|
return nil, fmt.Errorf("datagram size %d exceeds max frame size %d", len(b), MaxDatagramFrameSize)
|
||||||
}
|
}
|
||||||
b = append(b, byte(datagramType))
|
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 {
|
func (dm *DatagramMuxerV2) demux(ctx context.Context, msgWithType []byte) error {
|
||||||
if len(msgWithType) < 1 {
|
if len(msgWithType) < typeIDLen {
|
||||||
return fmt.Errorf("QUIC datagram should have at least 1 byte")
|
return fmt.Errorf("QUIC datagram should have at least %d byte", typeIDLen)
|
||||||
}
|
}
|
||||||
msgType := datagramV2Type(msgWithType[len(msgWithType)-1])
|
msgType := datagramV2Type(msgWithType[len(msgWithType)-typeIDLen])
|
||||||
msg := msgWithType[0 : len(msgWithType)-1]
|
msg := msgWithType[0 : len(msgWithType)-typeIDLen]
|
||||||
switch msgType {
|
switch msgType {
|
||||||
case udp:
|
case udp:
|
||||||
return dm.handleSession(ctx, msg)
|
return dm.handleSession(ctx, msg)
|
||||||
|
|
|
@ -7,5 +7,5 @@ const (
|
||||||
// 1220 is the default value https://github.com/lucas-clemente/quic-go/blob/84e03e59760ceee37359688871bb0688fcc4e98f/internal/protocol/params.go#L138
|
// 1220 is the default value https://github.com/lucas-clemente/quic-go/blob/84e03e59760ceee37359688871bb0688fcc4e98f/internal/protocol/params.go#L138
|
||||||
MaxDatagramFrameSize = 1220
|
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
|
// 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
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue