ExtractAllSCIDs extracts SCIDs from all coalesced packets in a UDP datagram. QUIC allows multiple packets to be coalesced in a single datagram. The server may use different SCIDs for Initial and Handshake phases.
(datagram []byte)
| 196 | // QUIC allows multiple packets to be coalesced in a single datagram. |
| 197 | // The server may use different SCIDs for Initial and Handshake phases. |
| 198 | func ExtractAllSCIDs(datagram []byte) [][]byte { |
| 199 | var scids [][]byte |
| 200 | seen := make(map[string]bool) |
| 201 | |
| 202 | offset := 0 |
| 203 | for offset < len(datagram) { |
| 204 | if offset+1 > len(datagram) { |
| 205 | break |
| 206 | } |
| 207 | |
| 208 | // Check if Long Header (first bit = 1) |
| 209 | if datagram[offset]&0x80 == 0 { |
| 210 | // Short Header - no more Long Header packets possible |
| 211 | break |
| 212 | } |
| 213 | |
| 214 | // Parse Long Header to extract SCID and find packet length |
| 215 | pkt := datagram[offset:] |
| 216 | if len(pkt) < 6 { |
| 217 | break |
| 218 | } |
| 219 | |
| 220 | // Skip header byte (1) + version (4) |
| 221 | headerOffset := 5 |
| 222 | dcidLen := int(pkt[headerOffset]) |
| 223 | headerOffset++ |
| 224 | headerOffset += dcidLen |
| 225 | |
| 226 | if headerOffset >= len(pkt) { |
| 227 | break |
| 228 | } |
| 229 | |
| 230 | scidLen := int(pkt[headerOffset]) |
| 231 | headerOffset++ |
| 232 | |
| 233 | if headerOffset+scidLen > len(pkt) { |
| 234 | break |
| 235 | } |
| 236 | |
| 237 | scid := pkt[headerOffset : headerOffset+scidLen] |
| 238 | scidKey := string(scid) |
| 239 | if !seen[scidKey] && len(scid) > 0 { |
| 240 | seen[scidKey] = true |
| 241 | scidCopy := make([]byte, len(scid)) |
| 242 | copy(scidCopy, scid) |
| 243 | scids = append(scids, scidCopy) |
| 244 | } |
| 245 | headerOffset += scidLen |
| 246 | |
| 247 | // Read variable-length packet length field |
| 248 | if headerOffset >= len(pkt) { |
| 249 | break |
| 250 | } |
| 251 | pktLen, lenBytes, err := readVarInt(pkt[headerOffset:]) |
| 252 | if err != nil || lenBytes == 0 { |
| 253 | break |
| 254 | } |
| 255 | headerOffset += lenBytes |
no test coverage detected