learnServerSCID extracts server's SCID(s) from a Long Header response datagram and registers them as aliases for the original DCID. This enables routing subsequent client packets that use server's CID as DCID. Handles coalesced packets where Initial and Handshake may have different SCIDs.
(originalDCID string, ctx *handler.Context, datagram []byte)
| 617 | // This enables routing subsequent client packets that use server's CID as DCID. |
| 618 | // Handles coalesced packets where Initial and Handshake may have different SCIDs. |
| 619 | func (p *Proxy) learnServerSCID(originalDCID string, ctx *handler.Context, datagram []byte) { |
| 620 | // Debug: show both DCID and SCID in the packet |
| 621 | if dcid, scid, err := ExtractDCIDAndSCID(datagram); err == nil { |
| 622 | debug.Printf(" learnServerSCID: packet DCID=%x, SCID=%x (datagram %d bytes)", dcid, scid, len(datagram)) |
| 623 | // Hex dump first 20 bytes for debugging |
| 624 | hexDump := datagram[:min(20, len(datagram))] |
| 625 | debug.Printf(" learnServerSCID: first 20 bytes: % x", hexDump) |
| 626 | } |
| 627 | |
| 628 | // Extract all SCIDs from potentially coalesced packets |
| 629 | scids := ExtractAllSCIDs(datagram) |
| 630 | |
| 631 | for _, scid := range scids { |
| 632 | scidKey := string(scid) |
| 633 | if scidKey == originalDCID { |
| 634 | continue // Same as original, no need for alias |
| 635 | } |
| 636 | |
| 637 | // Check if we already have this alias (avoid duplicate logging) |
| 638 | if _, exists := p.dcidAliases.Load(scidKey); exists { |
| 639 | continue |
| 640 | } |
| 641 | |
| 642 | // Store alias: server's SCID -> original DCID |
| 643 | p.dcidAliases.Store(scidKey, originalDCID) |
| 644 | |
| 645 | // Track SCID length for Short Header parsing |
| 646 | p.registerDCIDLength(len(scid)) |
| 647 | |
| 648 | log.Printf("[proxy] learned server SCID=%x for session (original DCID=%s)", scid, originalDCID[:min(8, len(originalDCID))]) |
| 649 | } |
| 650 | } |
| 651 | |
| 652 | // Stop stops the proxy server gracefully. |
| 653 | func (p *Proxy) Stop() { |
no test coverage detected