LCOV - code coverage report
Current view: top level - waltz/quic - fd_quic_conn.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 102 0.0 %
Date: 2026-03-19 18:19:27 Functions: 0 8 0.0 %

          Line data    Source code
       1             : #include "fd_quic_conn.h"
       2             : #include "fd_quic_common.h"
       3             : #include "fd_quic_enum.h"
       4             : #include "fd_quic_pkt_meta.h"
       5             : #include "fd_quic_private.h"
       6             : 
       7             : /* define a map for stream_id -> stream* */
       8             : #define MAP_NAME              fd_quic_stream_map
       9           0 : #define MAP_KEY               stream_id
      10           0 : #define MAP_T                 fd_quic_stream_map_t
      11           0 : #define MAP_KEY_NULL          FD_QUIC_STREAM_ID_UNUSED
      12             : #define MAP_KEY_INVAL(key)    ((key)==MAP_KEY_NULL)
      13             : #define MAP_QUERY_OPT         1
      14             : 
      15             : #include "../../util/tmpl/fd_map_dynamic.c"
      16             : 
      17             : struct fd_quic_conn_layout {
      18             :   int   stream_map_lg;
      19             :   ulong stream_map_off;
      20             : };
      21             : typedef struct fd_quic_conn_layout fd_quic_conn_layout_t;
      22             : 
      23             : ulong
      24           0 : fd_quic_conn_align( void ) {
      25           0 :   ulong align = fd_ulong_max( alignof( fd_quic_conn_t ), alignof( fd_quic_stream_t ) );
      26           0 :   align = fd_ulong_max( align, fd_quic_stream_map_align() );
      27           0 :   return align;
      28           0 : }
      29             : 
      30             : static ulong
      31             : fd_quic_conn_footprint_ext( fd_quic_limits_t const * limits,
      32           0 :                             fd_quic_conn_layout_t *  layout ) {
      33             : 
      34           0 :   ulong stream_id_cnt = limits->stream_id_cnt;
      35             : 
      36           0 :   ulong off  = 0;
      37             : 
      38           0 :   off += sizeof( fd_quic_conn_t );
      39             : 
      40           0 :   if( stream_id_cnt ) {
      41             :     /* allocate space for stream hash map */
      42             :     /* about a million seems like a decent bound, with expected values up to 20,000 */
      43           0 :     ulong lg = 0;
      44           0 :     while( lg < 20 && (1ul<<lg) < (ulong)((double)stream_id_cnt*FD_QUIC_DEFAULT_SPARSITY) ) {
      45           0 :       lg++;
      46           0 :     }
      47           0 :     layout->stream_map_lg = (int)lg;
      48             : 
      49           0 :     off                     = fd_ulong_align_up( off, fd_quic_stream_map_align() );
      50           0 :     layout->stream_map_off  = off;
      51           0 :     off                    += fd_quic_stream_map_footprint( (int)lg );
      52           0 :   } else {
      53           0 :     layout->stream_map_lg  = 0;
      54           0 :     layout->stream_map_off = 0UL;
      55           0 :   }
      56             : 
      57           0 :   return fd_ulong_align_up( off, fd_quic_conn_align() );
      58           0 : }
      59             : 
      60             : ulong
      61           0 : fd_quic_conn_footprint( fd_quic_limits_t const * limits ) {
      62           0 :   fd_quic_conn_layout_t layout;
      63           0 :   return fd_quic_conn_footprint_ext( limits, &layout );
      64           0 : }
      65             : 
      66             : fd_quic_conn_t *
      67             : fd_quic_conn_new( void *                   mem,
      68             :                   fd_quic_t *              quic,
      69           0 :                   fd_quic_limits_t const * limits ) {
      70             : 
      71             :   /* Argument checks */
      72             : 
      73           0 :   if( FD_UNLIKELY( !mem ) ) {
      74           0 :     FD_LOG_WARNING(( "NULL mem" ));
      75           0 :     return NULL;
      76           0 :   }
      77             : 
      78           0 :   ulong align = fd_quic_conn_align();
      79           0 :   if( FD_UNLIKELY( !fd_ulong_is_aligned( (ulong)mem, align ) ) ) {
      80           0 :     FD_LOG_WARNING(( "misaligned mem" ));
      81           0 :     return NULL;
      82           0 :   }
      83             : 
      84           0 :   if( FD_UNLIKELY( !quic ) ) {
      85           0 :     FD_LOG_WARNING(( "NULL quic" ));
      86           0 :     return NULL;
      87           0 :   }
      88             : 
      89           0 :   if( FD_UNLIKELY( !limits ) ) {
      90           0 :     FD_LOG_WARNING(( "NULL limits" ));
      91           0 :     return NULL;
      92           0 :   }
      93             : 
      94           0 :   fd_quic_conn_layout_t layout = {0};
      95           0 :   ulong footprint = fd_quic_conn_footprint_ext( limits, &layout );
      96           0 :   if( FD_UNLIKELY( !footprint ) ) {
      97           0 :     FD_LOG_WARNING(( "invalid footprint for limits" ));
      98           0 :     return NULL;
      99           0 :   }
     100             : 
     101             :   /* Initialize conn */
     102             : 
     103           0 :   fd_quic_conn_t * conn = (fd_quic_conn_t *)mem;
     104           0 :   fd_memset( conn, 0, sizeof(fd_quic_conn_t) );
     105             : 
     106           0 :   conn->quic     = quic;
     107           0 :   conn->state    = FD_QUIC_CONN_STATE_INVALID;
     108             : 
     109           0 :   quic->metrics.conn_state_cnt[ FD_QUIC_CONN_STATE_INVALID ]++;
     110             : 
     111             :   /* Initialize streams */
     112             : 
     113           0 :   FD_QUIC_STREAM_LIST_SENTINEL( conn->send_streams );
     114           0 :   FD_QUIC_STREAM_LIST_SENTINEL( conn->used_streams );
     115             : 
     116             :   /* Initialize stream hash map */
     117             : 
     118           0 :   if( layout.stream_map_off ) {
     119           0 :     ulong stream_map_laddr = (ulong)mem + layout.stream_map_off;
     120           0 :     conn->stream_map = fd_quic_stream_map_join( fd_quic_stream_map_new( (void *)stream_map_laddr, layout.stream_map_lg, (ulong)fd_tickcount() ) );
     121           0 :     if( FD_UNLIKELY( !conn->stream_map ) ) return NULL;
     122           0 :   }
     123             : 
     124             :   /* Initialize packet meta tracker */
     125           0 :   fd_quic_state_t * state = fd_quic_get_state( quic );
     126           0 :   fd_quic_pkt_meta_tracker_init( &conn->pkt_meta_tracker,
     127           0 :                                  quic->limits.inflight_frame_cnt,
     128           0 :                                  state->pkt_meta_pool );
     129             : 
     130             : 
     131             :   /* Initialize service timers */
     132           0 :   fd_quic_svc_timers_init_conn( conn );
     133             : 
     134           0 :   return conn;
     135           0 : }
     136             : 
     137             : /* set the user-defined context value on the connection */
     138             : void
     139           0 : fd_quic_conn_set_context( fd_quic_conn_t * conn, void * context ) {
     140           0 :   conn->context = context;
     141           0 : }
     142             : 
     143             : 
     144             : /* get the user-defined context value from a connection */
     145             : void *
     146           0 : fd_quic_conn_get_context( fd_quic_conn_t * conn ) {
     147           0 :   return conn->context;
     148           0 : }
     149             : 
     150             : char const *
     151           0 : fd_quic_conn_reason_name( uint reason ) {
     152             :   /* define mapping from reason code to name as a c-string */
     153           0 :   static char const * fd_quic_conn_reason_names[] = {
     154           0 : #   define COMMA ,
     155           0 : #   define _(NAME,CODE,DESC) \
     156           0 :     [CODE] = #NAME
     157           0 :     FD_QUIC_REASON_CODES(_,COMMA)
     158           0 : #   undef _
     159           0 : #   undef COMMA
     160           0 :   };
     161             : 
     162           0 : # define ELEMENTS ( sizeof(fd_quic_conn_reason_names) / sizeof(fd_quic_conn_reason_names[0]) )
     163             : 
     164           0 :   if( FD_UNLIKELY( reason >= ELEMENTS ) ) return "N/A";
     165             : 
     166           0 :   char const * name = fd_quic_conn_reason_names[reason];
     167             : 
     168           0 :   return name ? name : "N/A";
     169           0 : }
     170             : 
     171             : void
     172           0 : fd_quic_conn_validate_init( fd_quic_t * quic ) {
     173           0 :   fd_quic_state_t * state    = fd_quic_get_state( quic );
     174           0 :   ulong             conn_cnt = quic->limits.conn_cnt;
     175           0 :   for( ulong j=0UL; j<conn_cnt; j++ ) {
     176           0 :     fd_quic_conn_t * conn = fd_quic_conn_at_idx( state, j );
     177           0 :     conn->visited         = 0U;
     178           0 :   }
     179           0 : }

Generated by: LCOV version 1.14