|
1 | 1 | libp2p.transport.quic package |
2 | 2 | ============================= |
3 | 3 |
|
| 4 | +Connection ID Management |
| 5 | +------------------------ |
| 6 | + |
| 7 | +The QUIC transport implementation uses a sophisticated Connection ID (CID) management system |
| 8 | +inspired by the `quinn` Rust QUIC library. This system ensures proper packet routing and |
| 9 | +handles connection migration scenarios. |
| 10 | + |
| 11 | +Key Features |
| 12 | +~~~~~~~~~~~~ |
| 13 | + |
| 14 | +**Sequence Number Tracking** |
| 15 | + Each Connection ID is assigned a sequence number, starting at 0 for the initial CID. |
| 16 | + Sequence numbers are used to ensure proper retirement ordering per the QUIC specification. |
| 17 | + |
| 18 | +**Initial vs. Established CIDs** |
| 19 | + Initial CIDs (used during handshake) are tracked separately from established connection CIDs. |
| 20 | + This separation allows for efficient packet routing and proper handling of handshake packets. |
| 21 | + |
| 22 | +**Fallback Routing** |
| 23 | + When packets arrive with new Connection IDs before ``ConnectionIdIssued`` events are processed, |
| 24 | + the system uses O(1) fallback routing based on address mappings. This handles race conditions |
| 25 | + gracefully and ensures packets are routed correctly. |
| 26 | + |
| 27 | +**Retirement Ordering** |
| 28 | + Connection IDs are retired in sequence order, ensuring compliance with the QUIC specification. |
| 29 | + The ``ConnectionIDRegistry`` maintains sequence number mappings to enable proper retirement. |
| 30 | + |
| 31 | +Architecture |
| 32 | +~~~~~~~~~~~~ |
| 33 | + |
| 34 | +The ``ConnectionIDRegistry`` class manages all Connection ID routing state: |
| 35 | + |
| 36 | +- **Established connections**: Maps Connection IDs to ``QUICConnection`` instances |
| 37 | +- **Pending connections**: Maps Connection IDs to ``QuicConnection`` (aioquic) instances during handshake |
| 38 | +- **Initial CIDs**: Separate tracking for handshake packet routing |
| 39 | +- **Sequence tracking**: Maps Connection IDs to sequence numbers and connections to sequence ranges |
| 40 | +- **Address mappings**: Bidirectional mappings between Connection IDs and addresses for O(1) fallback routing |
| 41 | + |
| 42 | +Performance Monitoring |
| 43 | +~~~~~~~~~~~~~~~~~~~~~~ |
| 44 | + |
| 45 | +The registry tracks performance metrics including: |
| 46 | + |
| 47 | +- Fallback routing usage count |
| 48 | +- Sequence number distribution |
| 49 | +- Operation timings (when debug mode is enabled) |
| 50 | + |
| 51 | +These metrics can be accessed via the ``get_stats()`` method and reset using ``reset_stats()``. |
| 52 | + |
4 | 53 | Submodules |
5 | 54 | ---------- |
6 | 55 |
|
|
0 commit comments