Skip to content

Commit

Permalink
quic: simplify fd_rng_t usage
Browse files Browse the repository at this point in the history
Statically allocates fd_rng_t instead of dynamically.
This is possible because fd_rng.h explicitly allows allocation via
declaration.
  • Loading branch information
riptl authored and ripatel-fd committed Mar 29, 2024
1 parent 063ed7c commit 31a9d12
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
18 changes: 6 additions & 12 deletions src/waltz/quic/fd_quic.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ struct fd_quic_layout {
ulong tls_off; /* offset of fd_quic_tls_t */
ulong stream_pool_off; /* offset of the stream pool */
ulong cs_tree_off; /* offset of the cs_tree */
ulong rng_off; /* offset of the rng */
};
typedef struct fd_quic_layout fd_quic_layout_t;

Expand Down Expand Up @@ -142,13 +141,6 @@ fd_quic_footprint_ext( fd_quic_limits_t const * limits,
if( FD_UNLIKELY( !cs_tree_footprint ) ) { FD_LOG_WARNING(( "invalid fd_quic_cs_tree_footprint" )); return 0UL; }
offs += cs_tree_footprint;

/* allocate space for fd_rng_t */
offs = fd_ulong_align_up( offs, fd_rng_align() );
layout->rng_off = offs;
ulong rng_footprint = fd_rng_footprint();
if( FD_UNLIKELY( !rng_footprint ) ) { FD_LOG_WARNING(( "invalid fd_rng_t" )); return 0UL; }
offs += rng_footprint;

return offs;
}

Expand Down Expand Up @@ -485,8 +477,7 @@ fd_quic_init( fd_quic_t * quic ) {
state->cs_tree = (fd_quic_cs_tree_t*)cs_tree_laddr;
fd_quic_cs_tree_init( state->cs_tree, ( limits->conn_cnt << 1UL ) + 1UL );

ulong rng_laddr = (ulong)quic + layout.rng_off;
state->rng = fd_rng_join( fd_rng_new( (void*)rng_laddr, 0UL, 0UL ) );
fd_rng_new( state->_rng, 0UL, 0UL );

/* Initialize crypto */

Expand Down Expand Up @@ -6854,7 +6845,7 @@ fd_quic_assign_streams( fd_quic_t * quic ) {
fd_quic_state_t * state = fd_quic_get_state( quic );
fd_quic_cs_tree_t * cs_tree = state->cs_tree;
fd_quic_stream_pool_t * stream_pool = state->stream_pool;
fd_rng_t * rng = state->rng;
fd_rng_t * rng = fd_rng_join( state->_rng );

/* we want to reserve 1 stream for each connection */
/* TODO could add a config for larger reservations */
Expand Down Expand Up @@ -6907,6 +6898,8 @@ fd_quic_assign_streams( fd_quic_t * quic ) {

avail_streams--;
}

fd_rng_leave( rng );
}


Expand Down Expand Up @@ -7026,7 +7019,8 @@ fd_quic_cs_tree_update( fd_quic_cs_tree_t * cs_tree, ulong idx, ulong new_value


ulong
fd_quic_choose_weighted_index( fd_quic_cs_tree_t * cs_tree, fd_rng_t * rng ) {
fd_quic_choose_weighted_index( fd_quic_cs_tree_t * cs_tree,
fd_rng_t * rng ) {
ulong cnt = cs_tree->cnt;
ulong * values = cs_tree->values;
ulong node_idx = 1UL;
Expand Down
2 changes: 0 additions & 2 deletions src/waltz/quic/fd_quic.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@

#include "../aio/fd_aio.h"
#include "../tls/fd_tls.h"
#include "../../util/fd_util.h"
#include "../../util/rng/fd_rng.h"

/* FD_QUIC_API marks public API declarations. No-op for now. */
#define FD_QUIC_API
Expand Down
2 changes: 1 addition & 1 deletion src/waltz/quic/fd_quic_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ struct __attribute__((aligned(16UL))) fd_quic_state_private {
fd_quic_stream_pool_t * stream_pool; /* stream pool */

fd_quic_cs_tree_t * cs_tree; /* cummulative summation tree */
fd_rng_t * rng; /* random number generator */
fd_rng_t _rng[1]; /* random number generator */

/* need to be able to access connections by index */
ulong conn_base; /* address of array of all connections */
Expand Down

0 comments on commit 31a9d12

Please sign in to comment.