MCPcopy Create free account
hub / github.com/HyBuildNet/quic-relay / ClassifyPacket

Function ClassifyPacket

internal/proxy/parser.go:55–82  ·  view source on GitHub ↗

ClassifyPacket determines the type of a QUIC packet from its first byte This is a fast check that doesn't parse the entire packet

(packet []byte)

Source from the content-addressed store, hash-verified

53// ClassifyPacket determines the type of a QUIC packet from its first byte
54// This is a fast check that doesn't parse the entire packet
55func ClassifyPacket(packet []byte) PacketType {
56 if len(packet) < 1 {
57 return PacketUnknown
58 }
59
60 // Check Header Form bit (bit 7)
61 // Short Header: Form bit = 0
62 // Long Header: Form bit = 1
63 if packet[0]&0x80 == 0 {
64 return PacketShortHeader
65 }
66
67 // Long Header - check Type bits (bits 4-5)
68 // The type is encoded in bits 4-5 of the first byte
69 longType := (packet[0] & 0x30) >> 4
70 switch longType {
71 case 0x00:
72 return PacketInitial
73 case 0x01:
74 return PacketZeroRTT
75 case 0x02:
76 return PacketHandshake
77 case 0x03:
78 return PacketRetry
79 }
80
81 return PacketUnknown
82}
83
84// ExtractDCID extracts the Destination Connection ID from any QUIC packet.
85// For Long Header packets, DCID length is encoded in the packet.

Callers 3

handlePacketMethod · 0.85
TestClassifyPacketFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestClassifyPacketFunction · 0.68