LCOV - code coverage report
Current view: top level - waltz/quic - fd_quic_conn_id.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 12 12 100.0 %
Date: 2026-10-21 04:28:53 Functions: 5 84 6.0 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_waltz_quic_fd_quic_conn_id_h
       2             : #define HEADER_fd_src_waltz_quic_fd_quic_conn_id_h
       3             : 
       4             : #include "../../util/bits/fd_bits.h"
       5             : #include <string.h>
       6             : 
       7             : /* TODO move this into more reasonable place */
       8    18017283 : #define FD_QUIC_MAX_CONN_ID_SZ 20
       9             : 
      10             : /* Firedancer connection ids will sized thus */
      11     8939978 : #define FD_QUIC_CONN_ID_SZ 8
      12             : 
      13             : /* pad fd_quic_conn_id struct */
      14             : #define FD_QUIC_CONN_ID_PAD (24 - 1 - FD_QUIC_MAX_CONN_ID_SZ)
      15             : 
      16             : /* fd_quic_conn_id_t contains a QUIC connection ID with size in [0,20]
      17             :    bytes.  The unused conn_id high bytes MUST be zeroed. */
      18             : 
      19             : struct fd_quic_conn_id {
      20             :   uchar sz;
      21             :   uchar conn_id[FD_QUIC_MAX_CONN_ID_SZ];
      22             : 
      23             :   /* explicitly pad for alignment */
      24             :   uchar pad[FD_QUIC_CONN_ID_PAD];
      25             : };
      26             : typedef struct fd_quic_conn_id fd_quic_conn_id_t;
      27             : 
      28             : FD_PROTOTYPES_BEGIN
      29             : 
      30             : static inline fd_quic_conn_id_t
      31             : fd_quic_conn_id_new( void const * conn_id,
      32      361239 :                      ulong        sz /* in [0,20] */ ) {
      33             :   /* TODO debug assertion verifying sz */
      34      361239 :   fd_quic_conn_id_t id = { .sz = (uchar)sz };
      35      361239 :   fd_memcpy( id.conn_id, conn_id, sz );
      36      361239 :   return id;
      37      361239 : }
      38             : 
      39             : static inline fd_quic_conn_id_t *
      40             : fd_quic_conn_id_from_u64( fd_quic_conn_id_t * conn_id,
      41        6147 :                           ulong               v ) {
      42        6147 :   *conn_id = (fd_quic_conn_id_t){ .sz = 8u, .conn_id = {0u}, .pad = {0u} };
      43        6147 :   FD_STORE( ulong, conn_id->conn_id, v );
      44        6147 :   return conn_id;
      45        6147 : }
      46             : 
      47             : FD_PROTOTYPES_END
      48             : 
      49             : /* Defines a NULL connection id
      50             :    Used as a NULL key in hash maps
      51             :    Note that the QUIC protocol supports zero-length connection ids.
      52             :    Hence, an all-zero fd_quic_conn_id_t wouldn't work as a NULL key */
      53             : #define FD_QUIC_CONN_ID_NULL ((fd_quic_conn_id_t){ .sz = 0xff })
      54             : 
      55             : /* define some functions for using fd_quic_conn_id as a key */
      56             : 
      57             : /* is this an invalid connection id */
      58             : #define FD_QUIC_CONN_ID_INVAL(CONN_ID) ((CONN_ID).sz > FD_QUIC_MAX_CONN_ID_SZ)
      59             : 
      60             : /* are these connection ids the same connection id
      61             :    for this to work properly, all unused bytes are set to zero */
      62             : #define FD_QUIC_CONN_ID_EQUAL(LHS,RHS) \
      63             :   (memcmp(&(LHS),&(RHS),sizeof(fd_quic_conn_id_t))==0)
      64             : 
      65             : /* fd_quic_net_endpoint_t identifies a UDP/IP network endpoint.
      66             :     May change during the lifetime of the conn. */
      67             : 
      68             : struct fd_quic_net_endpoint {
      69             :   uint   ip_addr;  /* net */
      70             :   ushort udp_port; /* host */
      71             : };
      72             : typedef struct fd_quic_net_endpoint fd_quic_net_endpoint_t;
      73             : 
      74             : #endif /* HEADER_fd_src_waltz_quic_fd_quic_conn_id_h */
      75             : 

Generated by: LCOV version 1.14