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)
| 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 |
| 55 | func 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. |
no outgoing calls