Skip to content

Commit

Permalink
quic: nits
Browse files Browse the repository at this point in the history
  • Loading branch information
two-heart authored and ripatel-fd committed Nov 15, 2024
1 parent 4d74603 commit 39248e7
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/tango/fd_tango_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ FD_FN_CONST static inline long fd_seq_diff( ulong a, ulong b ) { return (long)(a
chunk whose index is 0 (chunk0). fd_chunk_to_laddr_const is for
const-correctness.
fd_laddr_to_chunk: vica versa. */
fd_laddr_to_chunk: vice versa. */

FD_FN_CONST static inline void * /* Will be aligned FD_CHUNK_ALIGN and in [ chunk0, chunk0 + FD_CHUNK_SZ*(UINT_MAX+1) ) */
fd_chunk_to_laddr( void * chunk0, /* Assumed aligned FD_CHUNK_ALIGN */
Expand Down
43 changes: 15 additions & 28 deletions src/waltz/quic/fd_quic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,7 @@ fd_quic_send_retry( fd_quic_t * quic,
dst_udp_port,
1 ) == FD_QUIC_FAILED ) ) {
return FD_QUIC_PARSE_FAIL;
};
}
return 0UL;
}

Expand Down Expand Up @@ -1531,11 +1531,11 @@ fd_quic_handle_v1_initial( fd_quic_t * quic,
ulong pn_offset = initial->pkt_num_pnoff;

ulong body_sz = initial->len; /* not a protected field */
/* length of payload + num packet bytes */
/* length of payload + num packet bytes */

ulong pkt_number = (ulong)ULONG_MAX;
ulong pkt_number_sz = (ulong)ULONG_MAX;
ulong tot_sz = (ulong)ULONG_MAX;
ulong pkt_number = ULONG_MAX;
ulong pkt_number_sz = ULONG_MAX;
ulong tot_sz = ULONG_MAX;

# if !FD_QUIC_DISABLE_CRYPTO
/* this decrypts the header */
Expand Down Expand Up @@ -1704,9 +1704,9 @@ fd_quic_handle_v1_handshake(
ulong body_sz = handshake->len; /* not a protected field */
/* length of payload + num packet bytes */

ulong pkt_number = (ulong)-1;
ulong pkt_number_sz = (ulong)-1;
ulong tot_sz = (ulong)-1;
ulong pkt_number = ULONG_MAX;
ulong pkt_number_sz = ULONG_MAX;
ulong tot_sz = ULONG_MAX;

# if !FD_QUIC_DISABLE_CRYPTO
/* this decrypts the header */
Expand Down Expand Up @@ -1858,7 +1858,7 @@ fd_quic_handle_v1_retry(
fd_memcpy( &conn->token, retry_token, conn->token_len );

/* have to rewind the handshake data */
uint enc_level = 0;
uint enc_level = fd_quic_enc_level_initial_id;
conn->hs_sent_bytes[enc_level] = 0;
conn->hs_data_empty = 0;

Expand Down Expand Up @@ -2369,7 +2369,7 @@ fd_quic_process_packet( fd_quic_t * quic,

/* 0UL means no progress, so fail */
if( FD_UNLIKELY( ( rc == FD_QUIC_PARSE_FAIL ) |
( rc == 0UL ) )) {
( rc == 0UL ) ) ) {
FD_DEBUG( FD_LOG_DEBUG(( "fd_quic_process_quic_packet_v1 failed (stuck=%d)", rc==0UL )) );
return;
}
Expand Down Expand Up @@ -2675,7 +2675,7 @@ fd_quic_frame_handle_crypto_frame( void * vp_context,

if( !conn->tls_hs ) {
/* Handshake already completed. Ignore frame */
/* TODO consider aborting conn if too many unsoliticted crypto frames arrive */
/* TODO consider aborting conn if too many unsolicited crypto frames arrive */
} else if( FD_UNLIKELY( rcv_offset > exp_offset ) ) {
/* if data arrived early, we could buffer, but for now we simply won't ack */
/* TODO buffer handshake data */
Expand Down Expand Up @@ -4097,7 +4097,7 @@ fd_quic_conn_free( fd_quic_t * quic,
this should not occur, so this branch should not execute
but if a stream doesn't get cleaned up properly, this fixes
the stream map */
if( fd_quic_stream_map_key_cnt( conn->stream_map ) > 0 ) {
if( FD_UNLIKELY( fd_quic_stream_map_key_cnt( conn->stream_map ) > 0 ) ) {
FD_LOG_WARNING(( "stream_map not empty. cnt: %lu",
(ulong)fd_quic_stream_map_key_cnt( conn->stream_map ) ));
while( fd_quic_stream_map_key_cnt( conn->stream_map ) > 0 ) {
Expand Down Expand Up @@ -4126,12 +4126,7 @@ fd_quic_conn_free( fd_quic_t * quic,

/* remove connection from service queue */
if( FD_LIKELY( conn->svc_type != UINT_MAX ) ) {
uint prev_idx = conn->svc_prev;
uint next_idx = conn->svc_next;
fd_quic_conn_t * prev = fd_quic_conn_at_idx( state, prev_idx );
fd_quic_conn_t * next = fd_quic_conn_at_idx( state, next_idx );
*fd_ptr_if( prev_idx!=UINT_MAX, &prev->svc_next, &state->svc_queue[ conn->svc_type ].tail ) = next_idx;
*fd_ptr_if( next_idx!=UINT_MAX, &next->svc_prev, &state->svc_queue[ conn->svc_type ].head ) = prev_idx;
fd_quic_svc_unqueue( state, conn );
}

/* put connection back in free list */
Expand Down Expand Up @@ -5069,11 +5064,6 @@ fd_quic_frame_handle_ack_frame(
fd_quic_ack_frame_t * data,
uchar const * p,
ulong p_sz) {
(void)vp_context;
(void)data;
(void)p;
(void)p_sz;

fd_quic_frame_context_t context = *(fd_quic_frame_context_t*)vp_context;

uint enc_level = context.pkt->enc_level;
Expand All @@ -5084,7 +5074,7 @@ fd_quic_frame_handle_ack_frame(
return FD_QUIC_PARSE_FAIL;
}

/* track lowest packet ack'd */
/* track lowest packet acked */
ulong low_ack_pkt_number = data->largest_ack - data->first_ack_range;

/* ack packets are not ack-eliciting (they are acked with other things) */
Expand Down Expand Up @@ -5316,9 +5306,6 @@ fd_quic_frame_handle_stream_frame(
fd_quic_stream_frame_t * data,
uchar const * p,
ulong p_sz ) {
(void)data;
(void)p;
(void)p_sz;

fd_quic_frame_context_t * context = (fd_quic_frame_context_t *)vp_context;
fd_quic_t * quic = context->quic;
Expand Down Expand Up @@ -5440,7 +5427,7 @@ fd_quic_frame_handle_stream_frame(

/* peer created a stream, we cannot send on it */
stream->state = FD_QUIC_STREAM_STATE_TX_FIN;
stream->stream_flags = 0UL;
stream->stream_flags = 0u;

/* flow control */
stream->tx_max_stream_data = 0; /* can't send since peer initiated */
Expand Down
6 changes: 3 additions & 3 deletions src/waltz/quic/fd_quic_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,9 @@ fd_quic_lazy_ack_pkt( fd_quic_t * quic,
/* fd_quic_conn_error sets the connection state to aborted. This does
not destroy the connection object. Rather, it will eventually cause
the connection to be freed during a later fd_quic_service call.
reason is a RFC 9000 QUIC error code. error_line is a implementation
defined error code for internal use (usually the source line of code
in fd_quic.c) */
reason is an RFC 9000 QUIC error code. error_line is an
implementation defined error code for internal use (usually the
source line of code in fd_quic.c) */

void
fd_quic_conn_error( fd_quic_conn_t * conn,
Expand Down
4 changes: 2 additions & 2 deletions src/waltz/quic/fd_quic_retry.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ FD_PROTOTYPES_BEGIN
/* fd_quic_retry_integrity_tag_{sign,verify} implement the RFC 9001
"Retry Integrity Tag" AEAD scheme.
This is a standard and mandatory step in the QUIC retry proces, both
This is a standard and mandatory step in the QUIC retry process, both
on the server (sign) and client (verify) side. Confusingly, all
inputs to these functions are either public constants (e.g. the
hardcoded encryption key) or sent in plain text over the wire. Thus,
Expand All @@ -43,7 +43,7 @@ FD_PROTOTYPES_BEGIN
fd_quic_retry_integrity_tag_decrypt checks whether a Retry Integrity
Tag matches the byte range at retry_pseudo_pkt. It returns
FD_QUIC_SUCCESS if the integrity tag is vaild, and FD_QUIC_FAILURE
FD_QUIC_SUCCESS if the integrity tag is valid, and FD_QUIC_FAILURE
otherwise. */

static inline void
Expand Down
2 changes: 0 additions & 2 deletions src/waltz/quic/fd_quic_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ struct fd_quic_stream {
(stream)->next = (stream)->prev = stream; \
} while(0)



/* stream map for use in fd_map_dynamic map */
struct fd_quic_stream_map {
ulong stream_id; /* key */
Expand Down
2 changes: 1 addition & 1 deletion src/waltz/quic/templ/fd_quic_templ.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ FD_TEMPL_DEF_STRUCT_END(retry_hdr)
}
Figure 19: 1-RTT Packet */
FD_TEMPL_DEF_STRUCT_BEGIN(one_rtt)
FD_TEMPL_MBR_ELEM ( h0, uchar )
FD_TEMPL_MBR_ELEM ( h0, uchar )
FD_TEMPL_MBR_ELEM_HIDDEN( dst_conn_id_len, uint )
FD_TEMPL_MBR_ELEM_VAR ( dst_conn_id, 0,160, dst_conn_id_len )

Expand Down
8 changes: 8 additions & 0 deletions src/waltz/tls/fd_tls_estate.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ FD_PROTOTYPES_END
Finished" verify data. */

struct fd_tls_estate_srv {
/* TLS base (hs) handles are deliberately placed at the start.
Allows for type punning between fd_quic_tls_hs_t and
fd_tls_estate_{srv,cli}_t. DO NOT MOVE.
Type of handshake object depends on is_server. */
fd_tls_estate_base_t base;

uchar server_cert_rpk : 1; /* 0: X.509 1: raw public key */
Expand Down Expand Up @@ -181,6 +185,10 @@ FD_PROTOTYPES_END
Thus, estate_cli is not optimized for memory use. */

struct fd_tls_estate_cli {
/* TLS handshake handles are deliberately placed at the start.
Allows for type punning between fd_quic_tls_hs_t and
fd_tls_estate_{srv,cli}_t. DO NOT MOVE.
Type of handshake object depends on is_server. */
fd_tls_estate_base_t base;

uchar server_pubkey [ 32 ];
Expand Down
4 changes: 2 additions & 2 deletions src/waltz/tls/test_tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ test_tls_client_respond( fd_tls_t * client,
while( (rec = test_record_recv( &test_server_out )) ) {
long res = fd_tls_client_handshake( client, hs, rec->buf, rec->cur, rec->level );
if( res<0L ) {
fd_halt();
FD_LOG_ERR(( "fd_tls_client_handshake failed (alert %ld-%s; reason %u-%s)",
res, fd_tls_alert_cstr( (uint)-res ),
hs->base.reason, fd_tls_reason_cstr( hs->base.reason ) ));
fd_halt();
}
}
}
Expand All @@ -149,10 +149,10 @@ test_tls_server_respond( fd_tls_t * server,
while( (rec = test_record_recv( &test_client_out )) ) {
long res = fd_tls_server_handshake( server, hs, rec->buf, rec->cur, rec->level );
if( res<0L ) {
fd_halt();
FD_LOG_ERR(( "fd_tls_server_handshake failed (alert %ld-%s; reason %u-%s)",
res, fd_tls_alert_cstr( (uint)-res ),
hs->base.reason, fd_tls_reason_cstr( hs->base.reason ) ));
fd_halt();
}
}
}
Expand Down

0 comments on commit 39248e7

Please sign in to comment.