From 5c2f459eef5ce54a75cf231a45f60accff9746bb Mon Sep 17 00:00:00 2001 From: Kazuho Oku Date: Sat, 11 Jan 2025 11:17:19 +0900 Subject: [PATCH] use typename --- include/quicly.h | 80 +++---- include/quicly/constants.h | 13 +- include/quicly/frame.h | 107 +++++---- include/quicly/local_cid.h | 2 +- include/quicly/loss.h | 18 +- include/quicly/recvstate.h | 4 +- include/quicly/remote_cid.h | 8 +- include/quicly/sentmap.h | 10 +- include/quicly/streambuf.h | 4 +- lib/defaults.c | 5 +- lib/frame.c | 2 +- lib/local_cid.c | 2 +- lib/loss.c | 12 +- lib/quicly.c | 441 ++++++++++++++++++------------------ lib/recvstate.c | 4 +- lib/remote_cid.c | 14 +- lib/sentmap.c | 9 +- lib/streambuf.c | 8 +- src/cli.c | 39 ++-- t/sentmap.c | 2 +- t/simple.c | 4 +- t/test.c | 14 +- t/test.h | 4 +- 23 files changed, 422 insertions(+), 384 deletions(-) diff --git a/include/quicly.h b/include/quicly.h index db925c4e..d021e1ab 100644 --- a/include/quicly.h +++ b/include/quicly.h @@ -117,7 +117,7 @@ typedef struct st_quicly_stream_scheduler_t { * Called by quicly to emit stream data. The scheduler should repeatedly choose a stream and call `quicly_send_stream` until * `quicly_can_send_stream` returns false. */ - int64_t (*do_send)(struct st_quicly_stream_scheduler_t *sched, quicly_conn_t *conn, quicly_send_context_t *s); + quicly_error_t (*do_send)(struct st_quicly_stream_scheduler_t *sched, quicly_conn_t *conn, quicly_send_context_t *s); /** * */ @@ -127,7 +127,7 @@ typedef struct st_quicly_stream_scheduler_t { /** * called when stream is being open. Application is expected to create it's corresponding state and tie it to stream->data. */ -QUICLY_CALLBACK_TYPE(int64_t, stream_open, quicly_stream_t *stream); +QUICLY_CALLBACK_TYPE(quicly_error_t, stream_open, quicly_stream_t *stream); /** * */ @@ -135,7 +135,7 @@ QUICLY_CALLBACK_TYPE(void, receive_datagram_frame, quicly_conn_t *conn, ptls_iov /** * called when the connection is closed by remote peer */ -QUICLY_CALLBACK_TYPE(void, closed_by_remote, quicly_conn_t *conn, int64_t err, uint64_t frame_type, const char *reason, +QUICLY_CALLBACK_TYPE(void, closed_by_remote, quicly_conn_t *conn, quicly_error_t err, uint64_t frame_type, const char *reason, size_t reason_len); /** * Returns current time in milliseconds. The returned value MUST monotonically increase (i.e., it is the responsibility of the @@ -145,11 +145,11 @@ QUICLY_CALLBACK_TYPE0(int64_t, now); /** * called when a NEW_TOKEN token is received on a connection */ -QUICLY_CALLBACK_TYPE(int64_t, save_resumption_token, quicly_conn_t *conn, ptls_iovec_t token); +QUICLY_CALLBACK_TYPE(quicly_error_t, save_resumption_token, quicly_conn_t *conn, ptls_iovec_t token); /** * */ -QUICLY_CALLBACK_TYPE(int64_t, generate_resumption_token, quicly_conn_t *conn, ptls_buffer_t *buf, +QUICLY_CALLBACK_TYPE(quicly_error_t, generate_resumption_token, quicly_conn_t *conn, ptls_buffer_t *buf, quicly_address_token_plaintext_t *token); /** * called to initialize a congestion controller for a new connection. @@ -764,7 +764,7 @@ typedef struct st_quicly_stream_callbacks_t { /** * called when the stream is destroyed */ - void (*on_destroy)(quicly_stream_t *stream, int64_t err); + void (*on_destroy)(quicly_stream_t *stream, quicly_error_t err); /** * called whenever data can be retired from the send buffer, specifying the amount that can be newly removed */ @@ -781,7 +781,7 @@ typedef struct st_quicly_stream_callbacks_t { * called when a STOP_SENDING frame is received. Do not call `quicly_reset_stream` in response. The stream will be * automatically reset by quicly. */ - void (*on_send_stop)(quicly_stream_t *stream, int64_t err); + void (*on_send_stop)(quicly_stream_t *stream, quicly_error_t err); /** * called when data is newly received. `off` is the offset within the buffer (the beginning position changes as the application * calls `quicly_stream_sync_recvbuf`. Applications should consult `quicly_stream_t::recvstate` to see if it has contiguous @@ -791,7 +791,7 @@ typedef struct st_quicly_stream_callbacks_t { /** * called when a RESET_STREAM frame is received */ - void (*on_receive_reset)(quicly_stream_t *stream, int64_t err); + void (*on_receive_reset)(quicly_stream_t *stream, quicly_error_t err); } quicly_stream_callbacks_t; struct st_quicly_stream_t { @@ -1063,11 +1063,11 @@ struct sockaddr *quicly_get_peername(quicly_conn_t *conn); /** * */ -int64_t quicly_get_stats(quicly_conn_t *conn, quicly_stats_t *stats); +quicly_error_t quicly_get_stats(quicly_conn_t *conn, quicly_stats_t *stats); /** * */ -int64_t quicly_get_delivery_rate(quicly_conn_t *conn, quicly_rate_t *delivery_rate); +quicly_error_t quicly_get_delivery_rate(quicly_conn_t *conn, quicly_rate_t *delivery_rate); /** * */ @@ -1093,7 +1093,7 @@ void quicly_free(quicly_conn_t *conn); * error; indicating idle close). An application should continue calling quicly_receive and quicly_send, until they return * QUICLY_ERROR_FREE_CONNECTION. At this point, it is should call quicly_free. */ -int64_t quicly_close(quicly_conn_t *conn, int64_t err, const char *reason_phrase); +quicly_error_t quicly_close(quicly_conn_t *conn, quicly_error_t err, const char *reason_phrase); /** * */ @@ -1122,7 +1122,7 @@ int quicly_can_send_data(quicly_conn_t *conn, quicly_send_context_t *s); * Sends data of given stream. Called by stream scheduler. Only streams that can send some data or EOS should be specified. It is * the responsibility of the stream scheduler to maintain a list of such streams. */ -int64_t quicly_send_stream(quicly_stream_t *stream, quicly_send_context_t *s); +quicly_error_t quicly_send_stream(quicly_stream_t *stream, quicly_send_context_t *s); /** * Builds a Version Negotiation packet. The generated packet might include a greasing version. * * @param versions zero-terminated list of versions to advertise; use `quicly_supported_versions` for sending the list of @@ -1133,8 +1133,8 @@ size_t quicly_send_version_negotiation(quicly_context_t *ctx, ptls_iovec_t dest_ /** * */ -int64_t quicly_retry_calc_cidpair_hash(ptls_hash_algorithm_t *sha256, ptls_iovec_t client_cid, ptls_iovec_t server_cid, - uint64_t *value); +quicly_error_t quicly_retry_calc_cidpair_hash(ptls_hash_algorithm_t *sha256, ptls_iovec_t client_cid, ptls_iovec_t server_cid, + uint64_t *value); /** * Builds a UDP datagram containing a Retry packet. * @param retry_aead_cache pointer to `ptls_aead_context_t *` that the function can store a AEAD context for future reuse. The @@ -1161,8 +1161,8 @@ size_t quicly_send_retry(quicly_context_t *ctx, ptls_aead_context_t *token_encry * @return 0 if successful, otherwise an error. When an error is returned, the caller must call `quicly_close` to discard the * connection context. */ -int64_t quicly_send(quicly_conn_t *conn, quicly_address_t *dest, quicly_address_t *src, struct iovec *datagrams, - size_t *num_datagrams, void *buf, size_t bufsize); +quicly_error_t quicly_send(quicly_conn_t *conn, quicly_address_t *dest, quicly_address_t *src, struct iovec *datagrams, + size_t *num_datagrams, void *buf, size_t bufsize); /** * returns ECN bits to be set for the packets built by the last invocation of `quicly_send` */ @@ -1179,11 +1179,12 @@ size_t quicly_send_stateless_reset(quicly_context_t *ctx, const void *src_cid, v /** * */ -int64_t quicly_send_resumption_token(quicly_conn_t *conn); +quicly_error_t quicly_send_resumption_token(quicly_conn_t *conn); /** * */ -int64_t quicly_receive(quicly_conn_t *conn, struct sockaddr *dest_addr, struct sockaddr *src_addr, quicly_decoded_packet_t *packet); +quicly_error_t quicly_receive(quicly_conn_t *conn, struct sockaddr *dest_addr, struct sockaddr *src_addr, + quicly_decoded_packet_t *packet); /** * consults if the incoming packet identified by (dest_addr, src_addr, decoded) belongs to the given connection */ @@ -1214,18 +1215,18 @@ int quicly_encode_transport_parameter_list(ptls_buffer_t *buf, const quicly_tran * pre-fills the vector with an unpredictable value (i.e. random), then calls this function to set the stateless reset token to the * value supplied by peer. */ -int64_t quicly_decode_transport_parameter_list(quicly_transport_parameters_t *params, quicly_cid_t *original_dcid, - quicly_cid_t *initial_scid, quicly_cid_t *retry_scid, void *stateless_reset_token, - const uint8_t *src, const uint8_t *end); +quicly_error_t quicly_decode_transport_parameter_list(quicly_transport_parameters_t *params, quicly_cid_t *original_dcid, + quicly_cid_t *initial_scid, quicly_cid_t *retry_scid, + void *stateless_reset_token, const uint8_t *src, const uint8_t *end); /** * Initiates a new connection. * @param new_cid the CID to be used for the connection. path_id is ignored. * @param appdata initial value to be set to `*quicly_get_data(conn)` */ -int64_t quicly_connect(quicly_conn_t **conn, quicly_context_t *ctx, const char *server_name, struct sockaddr *dest_addr, - struct sockaddr *src_addr, const quicly_cid_plaintext_t *new_cid, ptls_iovec_t address_token, - ptls_handshake_properties_t *handshake_properties, - const quicly_transport_parameters_t *resumed_transport_params, void *appdata); +quicly_error_t quicly_connect(quicly_conn_t **conn, quicly_context_t *ctx, const char *server_name, struct sockaddr *dest_addr, + struct sockaddr *src_addr, const quicly_cid_plaintext_t *new_cid, ptls_iovec_t address_token, + ptls_handshake_properties_t *handshake_properties, + const quicly_transport_parameters_t *resumed_transport_params, void *appdata); /** * accepts a new connection * @param new_cid The CID to be used for the connection. When an error is being returned, the application can reuse the CID @@ -1236,9 +1237,10 @@ int64_t quicly_connect(quicly_conn_t **conn, quicly_context_t *ctx, const char * * validated. * @param appdata initial value to be set to `*quicly_get_data(conn)` */ -int64_t quicly_accept(quicly_conn_t **conn, quicly_context_t *ctx, struct sockaddr *dest_addr, struct sockaddr *src_addr, - quicly_decoded_packet_t *packet, quicly_address_token_plaintext_t *address_token, - const quicly_cid_plaintext_t *new_cid, ptls_handshake_properties_t *handshake_properties, void *appdata); +quicly_error_t quicly_accept(quicly_conn_t **conn, quicly_context_t *ctx, struct sockaddr *dest_addr, struct sockaddr *src_addr, + quicly_decoded_packet_t *packet, quicly_address_token_plaintext_t *address_token, + const quicly_cid_plaintext_t *new_cid, ptls_handshake_properties_t *handshake_properties, + void *appdata); /** * */ @@ -1264,7 +1266,7 @@ quicly_stream_t *quicly_get_stream(quicly_conn_t *conn, quicly_stream_id_t strea /** * */ -int64_t quicly_open_stream(quicly_conn_t *conn, quicly_stream_t **stream, int unidirectional); +quicly_error_t quicly_open_stream(quicly_conn_t *conn, quicly_stream_t **stream, int unidirectional); /** * This function returns a stream that is already open, or if the given ID refers to a stream that can be opened by the peer but is * yet-to-be opened, the functions opens that stream and returns it. Otherwise, `*stream` is set to NULL. @@ -1273,15 +1275,15 @@ int64_t quicly_open_stream(quicly_conn_t *conn, quicly_stream_t **stream, int un * initiated stream for which the peer has not yet sent anything. * Invocation of this function might open not only the stream that is referred to by the `stream_id` but also other streams. */ -int64_t quicly_get_or_open_stream(quicly_conn_t *conn, uint64_t stream_id, quicly_stream_t **stream); +quicly_error_t quicly_get_or_open_stream(quicly_conn_t *conn, uint64_t stream_id, quicly_stream_t **stream); /** * */ -void quicly_reset_stream(quicly_stream_t *stream, int64_t err); +void quicly_reset_stream(quicly_stream_t *stream, quicly_error_t err); /** * */ -void quicly_request_stop(quicly_stream_t *stream, int64_t err); +void quicly_request_stop(quicly_stream_t *stream, quicly_error_t err); /** * */ @@ -1348,15 +1350,15 @@ void quicly_amend_ptls_context(ptls_context_t *ptls); * the identifier of the AEAD key being used. * @param plaintext the token to be encrypted */ -int64_t quicly_encrypt_address_token(void (*random_bytes)(void *, size_t), ptls_aead_context_t *aead, ptls_buffer_t *buf, - size_t start_off, const quicly_address_token_plaintext_t *plaintext); +quicly_error_t quicly_encrypt_address_token(void (*random_bytes)(void *, size_t), ptls_aead_context_t *aead, ptls_buffer_t *buf, + size_t start_off, const quicly_address_token_plaintext_t *plaintext); /** * Decrypts an address token. * If decryption succeeds, returns zero. If the token is unusable due to decryption failure, returns PTLS_DECODE_ERROR. If the token * is unusable and the connection should be reset, returns QUICLY_ERROR_INVALID_TOKEN. */ -int64_t quicly_decrypt_address_token(ptls_aead_context_t *aead, quicly_address_token_plaintext_t *plaintext, const void *src, - size_t len, size_t prefix_len, const char **err_desc); +quicly_error_t quicly_decrypt_address_token(ptls_aead_context_t *aead, quicly_address_token_plaintext_t *plaintext, const void *src, + size_t len, size_t prefix_len, const char **err_desc); /** * Builds authentication data for TLS session ticket. 0-RTT can be accepted only when the auth_data of the original connection and * the new connection are identical. @@ -1381,7 +1383,7 @@ char *quicly_hexdump(const uint8_t *bytes, size_t len, size_t indent); /** * */ -void quicly_stream_noop_on_destroy(quicly_stream_t *stream, int64_t err); +void quicly_stream_noop_on_destroy(quicly_stream_t *stream, quicly_error_t err); /** * */ @@ -1393,7 +1395,7 @@ void quicly_stream_noop_on_send_emit(quicly_stream_t *stream, size_t off, void * /** * */ -void quicly_stream_noop_on_send_stop(quicly_stream_t *stream, int64_t err); +void quicly_stream_noop_on_send_stop(quicly_stream_t *stream, quicly_error_t err); /** * */ @@ -1401,7 +1403,7 @@ void quicly_stream_noop_on_receive(quicly_stream_t *stream, size_t off, const vo /** * */ -void quicly_stream_noop_on_receive_reset(quicly_stream_t *stream, int64_t err); +void quicly_stream_noop_on_receive_reset(quicly_stream_t *stream, quicly_error_t err); extern const quicly_stream_callbacks_t quicly_stream_noop_callbacks; diff --git a/include/quicly/constants.h b/include/quicly/constants.h index 74878632..8654a9de 100644 --- a/include/quicly/constants.h +++ b/include/quicly/constants.h @@ -66,8 +66,17 @@ extern "C" { #define QUICLY_EPOCH_1RTT 3 #define QUICLY_NUM_EPOCHS 4 -/* picotls error codes (of type int) use _INT_MIN ... INT_MAX, while QUIC application error codes use 0b01yyyy... and QUIC protocol - * error codes use 0b10yyyy..., where yyyy is a 62-bit QUIC integer */ +/** + * Error code used by quicly. The code coalesces the following to an int64_t. + * * INT_MIN ... INT_MAX: picotls error codes (of type int) + * * 0b01xxxx...: QUIC application error codes + * * 0b10xxxx...: QUIC protocol error codes + * Internal error codes should be allocated from the unused space in the `int` space (i.e., unused space of picotls error codes); + * quicly itselfy uses 0xffxx. `quicly_error_t` is defined a signed type so that picotls error codes can be mapped without sign + * conversion. + */ +typedef int64_t quicly_error_t; + #define QUICLY_ERROR_IS_QUIC(e) (((int64_t)(e) & 0x4000000000000000) != 0) #define QUICLY_ERROR_IS_QUIC_TRANSPORT(e) (((uint64_t)(int64_t)(e) & (uint64_t)0xc000000000000000) == 0x8000000000000000) #define QUICLY_ERROR_IS_QUIC_APPLICATION(e) (((uint64_t)(int64_t)(e) & (uint64_t)0xc000000000000000) == 0x4000000000000000) diff --git a/include/quicly/frame.h b/include/quicly/frame.h index 0fb5b012..d431bbb1 100644 --- a/include/quicly/frame.h +++ b/include/quicly/frame.h @@ -105,10 +105,10 @@ typedef struct st_quicly_stream_frame_t { ptls_iovec_t data; } quicly_stream_frame_t; -static int64_t quicly_decode_stream_frame(uint8_t type_flags, const uint8_t **src, const uint8_t *end, - quicly_stream_frame_t *frame); +static quicly_error_t quicly_decode_stream_frame(uint8_t type_flags, const uint8_t **src, const uint8_t *end, + quicly_stream_frame_t *frame); static uint8_t *quicly_encode_crypto_frame_header(uint8_t *dst, uint8_t *dst_end, uint64_t offset, size_t *data_len); -static int64_t quicly_decode_crypto_frame(const uint8_t **src, const uint8_t *end, quicly_stream_frame_t *frame); +static quicly_error_t quicly_decode_crypto_frame(const uint8_t **src, const uint8_t *end, quicly_stream_frame_t *frame); static uint8_t *quicly_encode_reset_stream_frame(uint8_t *dst, uint64_t stream_id, uint16_t app_error_code, uint64_t final_size); @@ -118,7 +118,7 @@ typedef struct st_quicly_reset_stream_frame_t { uint64_t final_size; } quicly_reset_stream_frame_t; -static int64_t quicly_decode_reset_stream_frame(const uint8_t **src, const uint8_t *end, quicly_reset_stream_frame_t *frame); +static quicly_error_t quicly_decode_reset_stream_frame(const uint8_t **src, const uint8_t *end, quicly_reset_stream_frame_t *frame); typedef struct st_quicly_transport_close_frame_t { uint16_t error_code; @@ -126,15 +126,16 @@ typedef struct st_quicly_transport_close_frame_t { ptls_iovec_t reason_phrase; } quicly_transport_close_frame_t; -static int64_t quicly_decode_transport_close_frame(const uint8_t **src, const uint8_t *end, quicly_transport_close_frame_t *frame); +static quicly_error_t quicly_decode_transport_close_frame(const uint8_t **src, const uint8_t *end, + quicly_transport_close_frame_t *frame); typedef struct st_quicly_application_close_frame_t { uint16_t error_code; ptls_iovec_t reason_phrase; } quicly_application_close_frame_t; -static int64_t quicly_decode_application_close_frame(const uint8_t **src, const uint8_t *end, - quicly_application_close_frame_t *frame); +static quicly_error_t quicly_decode_application_close_frame(const uint8_t **src, const uint8_t *end, + quicly_application_close_frame_t *frame); static size_t quicly_close_frame_capacity(uint64_t error_code, uint64_t offending_frame_type, const char *reason_phrase); /** @@ -149,7 +150,7 @@ typedef struct st_quicly_max_data_frame_t { uint64_t max_data; } quicly_max_data_frame_t; -static int64_t quicly_decode_max_data_frame(const uint8_t **src, const uint8_t *end, quicly_max_data_frame_t *frame); +static quicly_error_t quicly_decode_max_data_frame(const uint8_t **src, const uint8_t *end, quicly_max_data_frame_t *frame); static uint8_t *quicly_encode_max_stream_data_frame(uint8_t *dst, uint64_t stream_id, uint64_t max_stream_data); @@ -158,7 +159,8 @@ typedef struct st_quicly_max_stream_data_frame_t { uint64_t max_stream_data; } quicly_max_stream_data_frame_t; -static int64_t quicly_decode_max_stream_data_frame(const uint8_t **src, const uint8_t *end, quicly_max_stream_data_frame_t *frame); +static quicly_error_t quicly_decode_max_stream_data_frame(const uint8_t **src, const uint8_t *end, + quicly_max_stream_data_frame_t *frame); static uint8_t *quicly_encode_max_streams_frame(uint8_t *dst, int uni, uint64_t count); @@ -166,7 +168,7 @@ typedef struct st_quicly_max_streams_frame_t { uint64_t count; } quicly_max_streams_frame_t; -static int64_t quicly_decode_max_streams_frame(const uint8_t **src, const uint8_t *end, quicly_max_streams_frame_t *frame); +static quicly_error_t quicly_decode_max_streams_frame(const uint8_t **src, const uint8_t *end, quicly_max_streams_frame_t *frame); #define QUICLY_PATH_CHALLENGE_DATA_LEN 8 @@ -176,7 +178,8 @@ typedef struct st_quicly_path_challenge_frame_t { const uint8_t *data; } quicly_path_challenge_frame_t; -static int64_t quicly_decode_path_challenge_frame(const uint8_t **src, const uint8_t *end, quicly_path_challenge_frame_t *frame); +static quicly_error_t quicly_decode_path_challenge_frame(const uint8_t **src, const uint8_t *end, + quicly_path_challenge_frame_t *frame); static uint8_t *quicly_encode_data_blocked_frame(uint8_t *dst, uint64_t offset); @@ -184,7 +187,7 @@ typedef struct st_quicly_data_blocked_frame_t { uint64_t offset; } quicly_data_blocked_frame_t; -static int64_t quicly_decode_data_blocked_frame(const uint8_t **src, const uint8_t *end, quicly_data_blocked_frame_t *frame); +static quicly_error_t quicly_decode_data_blocked_frame(const uint8_t **src, const uint8_t *end, quicly_data_blocked_frame_t *frame); static uint8_t *quicly_encode_stream_data_blocked_frame(uint8_t *dst, quicly_stream_id_t stream_id, uint64_t offset); @@ -193,8 +196,8 @@ typedef struct st_quicly_stream_data_blocked_frame_t { uint64_t offset; } quicly_stream_data_blocked_frame_t; -static int64_t quicly_decode_stream_data_blocked_frame(const uint8_t **src, const uint8_t *end, - quicly_stream_data_blocked_frame_t *frame); +static quicly_error_t quicly_decode_stream_data_blocked_frame(const uint8_t **src, const uint8_t *end, + quicly_stream_data_blocked_frame_t *frame); static uint8_t *quicly_encode_streams_blocked_frame(uint8_t *dst, int uni, uint64_t count); @@ -202,7 +205,8 @@ typedef struct st_quicly_streams_blocked_frame_t { uint64_t count; } quicly_streams_blocked_frame_t; -static int64_t quicly_decode_streams_blocked_frame(const uint8_t **src, const uint8_t *end, quicly_streams_blocked_frame_t *frame); +static quicly_error_t quicly_decode_streams_blocked_frame(const uint8_t **src, const uint8_t *end, + quicly_streams_blocked_frame_t *frame); static size_t quicly_new_connection_id_frame_capacity(uint64_t sequence, uint64_t retire_prior_to, uint8_t cid_len); static uint8_t *quicly_encode_new_connection_id_frame(uint8_t *dst, uint64_t sequence, uint64_t retire_prior_to, const uint8_t *cid, @@ -218,15 +222,15 @@ typedef struct st_quicly_new_connection_id_frame_t { const uint8_t *stateless_reset_token; } quicly_new_connection_id_frame_t; -static int64_t quicly_decode_new_connection_id_frame(const uint8_t **src, const uint8_t *end, - quicly_new_connection_id_frame_t *frame); +static quicly_error_t quicly_decode_new_connection_id_frame(const uint8_t **src, const uint8_t *end, + quicly_new_connection_id_frame_t *frame); typedef struct st_quicly_retire_connection_id_frame_t { uint64_t sequence; } quicly_retire_connection_id_frame_t; -static int64_t quicly_decode_retire_connection_id_frame(const uint8_t **src, const uint8_t *end, - quicly_retire_connection_id_frame_t *frame); +static quicly_error_t quicly_decode_retire_connection_id_frame(const uint8_t **src, const uint8_t *end, + quicly_retire_connection_id_frame_t *frame); static uint8_t *quicly_encode_stop_sending_frame(uint8_t *dst, uint64_t stream_id, uint16_t app_error_code); @@ -235,7 +239,7 @@ typedef struct st_quicly_stop_sending_frame_t { uint16_t app_error_code; } quicly_stop_sending_frame_t; -static int64_t quicly_decode_stop_sending_frame(const uint8_t **src, const uint8_t *end, quicly_stop_sending_frame_t *frame); +static quicly_error_t quicly_decode_stop_sending_frame(const uint8_t **src, const uint8_t *end, quicly_stop_sending_frame_t *frame); uint8_t *quicly_encode_ack_frame(uint8_t *dst, uint8_t *dst_end, quicly_ranges_t *ranges, uint64_t *ecn_counts, uint64_t ack_delay); @@ -249,7 +253,7 @@ typedef struct st_quicly_ack_frame_t { uint64_t ecn_counts[3]; } quicly_ack_frame_t; -int64_t quicly_decode_ack_frame(const uint8_t **src, const uint8_t *end, quicly_ack_frame_t *frame, int is_ack_ecn); +quicly_error_t quicly_decode_ack_frame(const uint8_t **src, const uint8_t *end, quicly_ack_frame_t *frame, int is_ack_ecn); static size_t quicly_new_token_frame_capacity(ptls_iovec_t token); static uint8_t *quicly_encode_new_token_frame(uint8_t *dst, ptls_iovec_t token); @@ -258,7 +262,7 @@ typedef struct st_quicly_new_token_frame_t { ptls_iovec_t token; } quicly_new_token_frame_t; -static int64_t quicly_decode_new_token_frame(const uint8_t **src, const uint8_t *end, quicly_new_token_frame_t *frame); +static quicly_error_t quicly_decode_new_token_frame(const uint8_t **src, const uint8_t *end, quicly_new_token_frame_t *frame); static size_t quicly_datagram_frame_capacity(ptls_iovec_t payload); static uint8_t *quicly_encode_datagram_frame(uint8_t *dst, ptls_iovec_t payload); @@ -267,8 +271,8 @@ typedef struct st_quicly_datagram_frame_t { ptls_iovec_t payload; } quicly_datagram_frame_t; -static int64_t quicly_decode_datagram_frame(uint64_t frame_type, const uint8_t **src, const uint8_t *end, - quicly_datagram_frame_t *frame); +static quicly_error_t quicly_decode_datagram_frame(uint64_t frame_type, const uint8_t **src, const uint8_t *end, + quicly_datagram_frame_t *frame); typedef struct st_quicly_ack_frequency_frame_t { uint64_t sequence; @@ -284,7 +288,8 @@ typedef struct st_quicly_ack_frequency_frame_t { static uint8_t *quicly_encode_ack_frequency_frame(uint8_t *dst, uint64_t sequence, uint64_t packet_tolerance, uint64_t max_ack_delay, int ignore_order); -static int64_t quicly_decode_ack_frequency_frame(const uint8_t **src, const uint8_t *end, quicly_ack_frequency_frame_t *frame); +static quicly_error_t quicly_decode_ack_frequency_frame(const uint8_t **src, const uint8_t *end, + quicly_ack_frequency_frame_t *frame); /* inline definitions */ @@ -371,7 +376,8 @@ inline unsigned quicly_clz64(uint64_t v) return v != 0 ? __builtin_clzll(v) : 64; } -inline int64_t quicly_decode_stream_frame(uint8_t type_flags, const uint8_t **src, const uint8_t *end, quicly_stream_frame_t *frame) +inline quicly_error_t quicly_decode_stream_frame(uint8_t type_flags, const uint8_t **src, const uint8_t *end, + quicly_stream_frame_t *frame) { /* obtain stream id */ if ((frame->stream_id = quicly_decodev(src, end)) == UINT64_MAX) @@ -431,7 +437,7 @@ inline uint8_t *quicly_encode_crypto_frame_header(uint8_t *dst, uint8_t *dst_end return dst; } -inline int64_t quicly_decode_crypto_frame(const uint8_t **src, const uint8_t *end, quicly_stream_frame_t *frame) +inline quicly_error_t quicly_decode_crypto_frame(const uint8_t **src, const uint8_t *end, quicly_stream_frame_t *frame) { uint64_t len; @@ -461,7 +467,7 @@ inline uint8_t *quicly_encode_reset_stream_frame(uint8_t *dst, uint64_t stream_i return dst; } -inline int64_t quicly_decode_reset_stream_frame(const uint8_t **src, const uint8_t *end, quicly_reset_stream_frame_t *frame) +inline quicly_error_t quicly_decode_reset_stream_frame(const uint8_t **src, const uint8_t *end, quicly_reset_stream_frame_t *frame) { uint64_t error_code; @@ -476,8 +482,8 @@ inline int64_t quicly_decode_reset_stream_frame(const uint8_t **src, const uint8 return QUICLY_TRANSPORT_ERROR_FRAME_ENCODING; } -inline int64_t quicly_decode_application_close_frame(const uint8_t **src, const uint8_t *end, - quicly_application_close_frame_t *frame) +inline quicly_error_t quicly_decode_application_close_frame(const uint8_t **src, const uint8_t *end, + quicly_application_close_frame_t *frame) { uint64_t error_code, reason_len; @@ -495,7 +501,8 @@ inline int64_t quicly_decode_application_close_frame(const uint8_t **src, const return QUICLY_TRANSPORT_ERROR_FRAME_ENCODING; } -inline int64_t quicly_decode_transport_close_frame(const uint8_t **src, const uint8_t *end, quicly_transport_close_frame_t *frame) +inline quicly_error_t quicly_decode_transport_close_frame(const uint8_t **src, const uint8_t *end, + quicly_transport_close_frame_t *frame) { uint64_t error_code, reason_len; @@ -527,7 +534,7 @@ inline uint8_t *quicly_encode_max_data_frame(uint8_t *dst, uint64_t max_data) return dst; } -inline int64_t quicly_decode_max_data_frame(const uint8_t **src, const uint8_t *end, quicly_max_data_frame_t *frame) +inline quicly_error_t quicly_decode_max_data_frame(const uint8_t **src, const uint8_t *end, quicly_max_data_frame_t *frame) { if ((frame->max_data = quicly_decodev(src, end)) == UINT64_MAX) return QUICLY_TRANSPORT_ERROR_FRAME_ENCODING; @@ -542,7 +549,8 @@ inline uint8_t *quicly_encode_max_stream_data_frame(uint8_t *dst, uint64_t strea return dst; } -inline int64_t quicly_decode_max_stream_data_frame(const uint8_t **src, const uint8_t *end, quicly_max_stream_data_frame_t *frame) +inline quicly_error_t quicly_decode_max_stream_data_frame(const uint8_t **src, const uint8_t *end, + quicly_max_stream_data_frame_t *frame) { if ((frame->stream_id = quicly_decodev(src, end)) == UINT64_MAX) goto Error; @@ -560,7 +568,7 @@ inline uint8_t *quicly_encode_max_streams_frame(uint8_t *dst, int uni, uint64_t return dst; } -inline int64_t quicly_decode_max_streams_frame(const uint8_t **src, const uint8_t *end, quicly_max_streams_frame_t *frame) +inline quicly_error_t quicly_decode_max_streams_frame(const uint8_t **src, const uint8_t *end, quicly_max_streams_frame_t *frame) { if ((frame->count = quicly_decodev(src, end)) == UINT64_MAX) return QUICLY_TRANSPORT_ERROR_FRAME_ENCODING; @@ -569,7 +577,8 @@ inline int64_t quicly_decode_max_streams_frame(const uint8_t **src, const uint8_ return 0; } -inline int64_t quicly_decode_path_challenge_frame(const uint8_t **src, const uint8_t *end, quicly_path_challenge_frame_t *frame) +inline quicly_error_t quicly_decode_path_challenge_frame(const uint8_t **src, const uint8_t *end, + quicly_path_challenge_frame_t *frame) { if (end - *src < 1) goto Error; @@ -589,7 +598,7 @@ inline uint8_t *quicly_encode_data_blocked_frame(uint8_t *dst, uint64_t offset) return dst; } -inline int64_t quicly_decode_data_blocked_frame(const uint8_t **src, const uint8_t *end, quicly_data_blocked_frame_t *frame) +inline quicly_error_t quicly_decode_data_blocked_frame(const uint8_t **src, const uint8_t *end, quicly_data_blocked_frame_t *frame) { if ((frame->offset = quicly_decodev(src, end)) == UINT64_MAX) return QUICLY_TRANSPORT_ERROR_FRAME_ENCODING; @@ -604,8 +613,8 @@ inline uint8_t *quicly_encode_stream_data_blocked_frame(uint8_t *dst, quicly_str return dst; } -inline int64_t quicly_decode_stream_data_blocked_frame(const uint8_t **src, const uint8_t *end, - quicly_stream_data_blocked_frame_t *frame) +inline quicly_error_t quicly_decode_stream_data_blocked_frame(const uint8_t **src, const uint8_t *end, + quicly_stream_data_blocked_frame_t *frame) { if ((frame->stream_id = quicly_decodev(src, end)) == -1) goto Error; @@ -623,7 +632,8 @@ inline uint8_t *quicly_encode_streams_blocked_frame(uint8_t *dst, int uni, uint6 return dst; } -inline int64_t quicly_decode_streams_blocked_frame(const uint8_t **src, const uint8_t *end, quicly_streams_blocked_frame_t *frame) +inline quicly_error_t quicly_decode_streams_blocked_frame(const uint8_t **src, const uint8_t *end, + quicly_streams_blocked_frame_t *frame) { if ((frame->count = quicly_decodev(src, end)) == UINT64_MAX) return QUICLY_TRANSPORT_ERROR_FRAME_ENCODING; @@ -668,8 +678,8 @@ inline uint8_t *quicly_encode_retire_connection_id_frame(uint8_t *dst, uint64_t return dst; } -inline int64_t quicly_decode_new_connection_id_frame(const uint8_t **src, const uint8_t *end, - quicly_new_connection_id_frame_t *frame) +inline quicly_error_t quicly_decode_new_connection_id_frame(const uint8_t **src, const uint8_t *end, + quicly_new_connection_id_frame_t *frame) { /* sequence */ if ((frame->sequence = quicly_decodev(src, end)) == UINT64_MAX) @@ -701,8 +711,8 @@ inline int64_t quicly_decode_new_connection_id_frame(const uint8_t **src, const return QUICLY_TRANSPORT_ERROR_FRAME_ENCODING; } -inline int64_t quicly_decode_retire_connection_id_frame(const uint8_t **src, const uint8_t *end, - quicly_retire_connection_id_frame_t *frame) +inline quicly_error_t quicly_decode_retire_connection_id_frame(const uint8_t **src, const uint8_t *end, + quicly_retire_connection_id_frame_t *frame) { /* sequence */ if ((frame->sequence = quicly_decodev(src, end)) == UINT64_MAX) @@ -721,7 +731,7 @@ inline uint8_t *quicly_encode_stop_sending_frame(uint8_t *dst, uint64_t stream_i return dst; } -inline int64_t quicly_decode_stop_sending_frame(const uint8_t **src, const uint8_t *end, quicly_stop_sending_frame_t *frame) +inline quicly_error_t quicly_decode_stop_sending_frame(const uint8_t **src, const uint8_t *end, quicly_stop_sending_frame_t *frame) { uint64_t error_code; @@ -749,7 +759,7 @@ inline uint8_t *quicly_encode_new_token_frame(uint8_t *dst, ptls_iovec_t token) return dst; } -inline int64_t quicly_decode_new_token_frame(const uint8_t **src, const uint8_t *end, quicly_new_token_frame_t *frame) +inline quicly_error_t quicly_decode_new_token_frame(const uint8_t **src, const uint8_t *end, quicly_new_token_frame_t *frame) { uint64_t token_len; if ((token_len = quicly_decodev(src, end)) == UINT64_MAX) @@ -779,8 +789,8 @@ inline uint8_t *quicly_encode_datagram_frame(uint8_t *dst, ptls_iovec_t payload) return dst; } -inline int64_t quicly_decode_datagram_frame(uint64_t frame_type, const uint8_t **src, const uint8_t *end, - quicly_datagram_frame_t *frame) +inline quicly_error_t quicly_decode_datagram_frame(uint64_t frame_type, const uint8_t **src, const uint8_t *end, + quicly_datagram_frame_t *frame) { if (frame_type == QUICLY_FRAME_TYPE_DATAGRAM_WITHLEN) { uint64_t len; @@ -810,7 +820,8 @@ inline uint8_t *quicly_encode_ack_frequency_frame(uint8_t *dst, uint64_t sequenc return dst; } -inline int64_t quicly_decode_ack_frequency_frame(const uint8_t **src, const uint8_t *end, quicly_ack_frequency_frame_t *frame) +inline quicly_error_t quicly_decode_ack_frequency_frame(const uint8_t **src, const uint8_t *end, + quicly_ack_frequency_frame_t *frame) { if ((frame->sequence = quicly_decodev(src, end)) == UINT64_MAX) goto Error; diff --git a/include/quicly/local_cid.h b/include/quicly/local_cid.h index a0c8fc00..f727042f 100644 --- a/include/quicly/local_cid.h +++ b/include/quicly/local_cid.h @@ -122,7 +122,7 @@ int quicly_local_cid_on_lost(quicly_local_cid_set_t *set, uint64_t sequence); * This makes one slot for CIDs empty. The CID generator callback is then called to fill the slot with a new CID. * @return 0 if the request was legal, otherwise an error code */ -int64_t quicly_local_cid_retire(quicly_local_cid_set_t *set, uint64_t sequence, int *has_pending); +quicly_error_t quicly_local_cid_retire(quicly_local_cid_set_t *set, uint64_t sequence, int *has_pending); /* inline definitions */ diff --git a/include/quicly/loss.h b/include/quicly/loss.h index 5c654010..04861100 100644 --- a/include/quicly/loss.h +++ b/include/quicly/loss.h @@ -184,18 +184,19 @@ static void quicly_loss_on_ack_received(quicly_loss_t *r, uint64_t largest_newly * * if restrict_sending is true, limit sending to min_packets_to_send, otherwise as limited by congestion/flow control * and then call quicly_loss_update_alarm and update the alarm */ -static int64_t quicly_loss_on_alarm(quicly_loss_t *r, int64_t now, uint32_t max_ack_delay, int is_1rtt_only, - size_t *min_packets_to_send, int *restrict_sending, quicly_loss_on_detect_cb on_loss_detected); +static quicly_error_t quicly_loss_on_alarm(quicly_loss_t *r, int64_t now, uint32_t max_ack_delay, int is_1rtt_only, + size_t *min_packets_to_send, int *restrict_sending, + quicly_loss_on_detect_cb on_loss_detected); /** * */ -int64_t quicly_loss_detect_loss(quicly_loss_t *r, int64_t now, uint32_t max_ack_delay, int is_1rtt_only, - quicly_loss_on_detect_cb on_loss_detected); +quicly_error_t quicly_loss_detect_loss(quicly_loss_t *r, int64_t now, uint32_t max_ack_delay, int is_1rtt_only, + quicly_loss_on_detect_cb on_loss_detected); /** * initializes the sentmap iterator, evicting the entries considered too old. */ -int64_t quicly_loss_init_sentmap_iter(quicly_loss_t *loss, quicly_sentmap_iter_t *iter, int64_t now, uint32_t max_ack_delay, - int is_closing); +quicly_error_t quicly_loss_init_sentmap_iter(quicly_loss_t *loss, quicly_sentmap_iter_t *iter, int64_t now, uint32_t max_ack_delay, + int is_closing); /** * Returns the timeout for sentmap entries. This timeout is also used as the duration of CLOSING / DRAINING state, and therefore be * longer than 3PTO. At the moment, the value is 4PTO. @@ -372,8 +373,9 @@ inline void quicly_loss_on_ack_received(quicly_loss_t *r, uint64_t largest_newly } } -inline int64_t quicly_loss_on_alarm(quicly_loss_t *r, int64_t now, uint32_t max_ack_delay, int is_1rtt_only, - size_t *min_packets_to_send, int *restrict_sending, quicly_loss_on_detect_cb on_loss_detected) +inline quicly_error_t quicly_loss_on_alarm(quicly_loss_t *r, int64_t now, uint32_t max_ack_delay, int is_1rtt_only, + size_t *min_packets_to_send, int *restrict_sending, + quicly_loss_on_detect_cb on_loss_detected) { r->alarm_at = INT64_MAX; *min_packets_to_send = 1; diff --git a/include/quicly/recvstate.h b/include/quicly/recvstate.h index 65c0f893..81a334a4 100644 --- a/include/quicly/recvstate.h +++ b/include/quicly/recvstate.h @@ -56,8 +56,8 @@ static size_t quicly_recvstate_bytes_available(quicly_recvstate_t *state); * bytes that might have been newly received and therefore need to be written to the receive buffer (this number of bytes counts * backward from the end of given range). */ -int64_t quicly_recvstate_update(quicly_recvstate_t *state, uint64_t off, size_t *len, int is_fin, size_t max_ranges); -int64_t quicly_recvstate_reset(quicly_recvstate_t *state, uint64_t eos_at, uint64_t *bytes_missing); +quicly_error_t quicly_recvstate_update(quicly_recvstate_t *state, uint64_t off, size_t *len, int is_fin, size_t max_ranges); +quicly_error_t quicly_recvstate_reset(quicly_recvstate_t *state, uint64_t eos_at, uint64_t *bytes_missing); /* inline definitions */ diff --git a/include/quicly/remote_cid.h b/include/quicly/remote_cid.h index 52a957ee..7f4dac75 100644 --- a/include/quicly/remote_cid.h +++ b/include/quicly/remote_cid.h @@ -96,10 +96,10 @@ void quicly_remote_cid_init_set(quicly_remote_cid_set_t *set, ptls_iovec_t *init * registers received connection ID * returns 0 if successful (registered or ignored because of duplication/stale information), transport error code otherwise */ -int64_t quicly_remote_cid_register(quicly_remote_cid_set_t *set, uint64_t sequence, const uint8_t *cid, size_t cid_len, - const uint8_t srt[QUICLY_STATELESS_RESET_TOKEN_LEN], uint64_t retire_prior_to, - uint64_t unregistered_seqs[QUICLY_LOCAL_ACTIVE_CONNECTION_ID_LIMIT], - size_t *num_unregistered_seqs); +quicly_error_t quicly_remote_cid_register(quicly_remote_cid_set_t *set, uint64_t sequence, const uint8_t *cid, size_t cid_len, + const uint8_t srt[QUICLY_STATELESS_RESET_TOKEN_LEN], uint64_t retire_prior_to, + uint64_t unregistered_seqs[QUICLY_LOCAL_ACTIVE_CONNECTION_ID_LIMIT], + size_t *num_unregistered_seqs); /** * unregisters specified CID from the store */ diff --git a/include/quicly/sentmap.h b/include/quicly/sentmap.h index 64221cdc..ea737c00 100644 --- a/include/quicly/sentmap.h +++ b/include/quicly/sentmap.h @@ -97,7 +97,8 @@ typedef enum en_quicly_sentmap_event_t { * @param acked true if acked, false if the information has to be scheduled for retransmission * @param data data */ -typedef int64_t (*quicly_sent_acked_cb)(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, quicly_sent_t *data); +typedef quicly_error_t (*quicly_sent_acked_cb)(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, + quicly_sent_t *data); struct st_quicly_sent_ack_additional_t { uint8_t gap; @@ -256,7 +257,7 @@ static int quicly_sentmap_is_open(quicly_sentmap_t *map); /** * prepares a write */ -int64_t quicly_sentmap_prepare(quicly_sentmap_t *map, uint64_t packet_number, int64_t now, uint8_t ack_epoch); +quicly_error_t quicly_sentmap_prepare(quicly_sentmap_t *map, uint64_t packet_number, int64_t now, uint8_t ack_epoch); /** * commits a write */ @@ -281,10 +282,11 @@ void quicly_sentmap_skip(quicly_sentmap_iter_t *iter); /** * updates the state of the packet being pointed to by the iterator, _and advances to the next packet_ */ -int64_t quicly_sentmap_update(quicly_sentmap_t *map, quicly_sentmap_iter_t *iter, quicly_sentmap_event_t event); +quicly_error_t quicly_sentmap_update(quicly_sentmap_t *map, quicly_sentmap_iter_t *iter, quicly_sentmap_event_t event); struct st_quicly_sent_block_t *quicly_sentmap__new_block(quicly_sentmap_t *map); -int64_t quicly_sentmap__type_packet(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, quicly_sent_t *sent); +quicly_error_t quicly_sentmap__type_packet(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, + quicly_sent_t *sent); /* inline definitions */ diff --git a/include/quicly/streambuf.h b/include/quicly/streambuf.h index c31b368e..ca9dd80a 100644 --- a/include/quicly/streambuf.h +++ b/include/quicly/streambuf.h @@ -42,7 +42,7 @@ typedef struct st_quicly_sendbuf_vec_t quicly_sendbuf_vec_t; * @param len number of bytes to serialize * @return 0 if successful, otherwise an error code */ -typedef int64_t (*quicly_sendbuf_flatten_vec_cb)(quicly_sendbuf_vec_t *vec, void *dst, size_t off, size_t len); +typedef quicly_error_t (*quicly_sendbuf_flatten_vec_cb)(quicly_sendbuf_vec_t *vec, void *dst, size_t off, size_t len); /** * An optional callback that is called when an iovec is discarded. */ @@ -122,7 +122,7 @@ typedef struct st_quicly_streambuf_t { } quicly_streambuf_t; int quicly_streambuf_create(quicly_stream_t *stream, size_t sz); -void quicly_streambuf_destroy(quicly_stream_t *stream, int64_t err); +void quicly_streambuf_destroy(quicly_stream_t *stream, quicly_error_t err); static void quicly_streambuf_egress_shift(quicly_stream_t *stream, size_t delta); void quicly_streambuf_egress_emit(quicly_stream_t *stream, size_t off, void *dst, size_t *len, int *wrote_all); static int quicly_streambuf_egress_write(quicly_stream_t *stream, const void *src, size_t len); diff --git a/lib/defaults.c b/lib/defaults.c index 1a5ea0f7..af295039 100644 --- a/lib/defaults.c +++ b/lib/defaults.c @@ -309,11 +309,12 @@ static void link_stream(struct st_quicly_default_scheduler_state_t *sched, quicl /** * See doc-comment of `st_quicly_default_scheduler_state_t` to understand the logic. */ -static int64_t default_stream_scheduler_do_send(quicly_stream_scheduler_t *self, quicly_conn_t *conn, quicly_send_context_t *s) +static quicly_error_t default_stream_scheduler_do_send(quicly_stream_scheduler_t *self, quicly_conn_t *conn, + quicly_send_context_t *s) { struct st_quicly_default_scheduler_state_t *sched = &((struct _st_quicly_conn_public_t *)conn)->_default_scheduler; int conn_is_blocked = quicly_is_blocked(conn); - int64_t ret = 0; + quicly_error_t ret = 0; if (!conn_is_blocked) quicly_linklist_insert_list(&sched->active, &sched->blocked); diff --git a/lib/frame.c b/lib/frame.c index 236b360a..4c922135 100644 --- a/lib/frame.c +++ b/lib/frame.c @@ -78,7 +78,7 @@ uint8_t *quicly_encode_ack_frame(uint8_t *dst, uint8_t *dst_end, quicly_ranges_t #undef WRITE_BLOCK } -int64_t quicly_decode_ack_frame(const uint8_t **src, const uint8_t *end, quicly_ack_frame_t *frame, int is_ack_ecn) +quicly_error_t quicly_decode_ack_frame(const uint8_t **src, const uint8_t *end, quicly_ack_frame_t *frame, int is_ack_ecn) { uint64_t i, num_gaps, gap, ack_range; diff --git a/lib/local_cid.c b/lib/local_cid.c index c69f1efa..40ea6454 100644 --- a/lib/local_cid.c +++ b/lib/local_cid.c @@ -179,7 +179,7 @@ int quicly_local_cid_on_lost(quicly_local_cid_set_t *set, uint64_t sequence) return 1; } -int64_t quicly_local_cid_retire(quicly_local_cid_set_t *set, uint64_t sequence, int *_has_pending) +quicly_error_t quicly_local_cid_retire(quicly_local_cid_set_t *set, uint64_t sequence, int *_has_pending) { /* find the CID to be retired, also check if there is at least one CID that has been issued */ size_t retired_at = set->_size; diff --git a/lib/loss.c b/lib/loss.c index 46949070..236495b4 100644 --- a/lib/loss.c +++ b/lib/loss.c @@ -21,8 +21,8 @@ */ #include "quicly/loss.h" -int64_t quicly_loss_init_sentmap_iter(quicly_loss_t *loss, quicly_sentmap_iter_t *iter, int64_t now, uint32_t max_ack_delay, - int is_closing) +quicly_error_t quicly_loss_init_sentmap_iter(quicly_loss_t *loss, quicly_sentmap_iter_t *iter, int64_t now, uint32_t max_ack_delay, + int is_closing) { quicly_sentmap_init_iter(&loss->sentmap, iter); @@ -40,7 +40,7 @@ int64_t quicly_loss_init_sentmap_iter(quicly_loss_t *loss, quicly_sentmap_iter_t quicly_sentmap_skip(iter); continue; } - int64_t ret; + quicly_error_t ret; if ((ret = quicly_sentmap_update(&loss->sentmap, iter, QUICLY_SENTMAP_EVENT_EXPIRED)) != 0) return ret; } @@ -51,8 +51,8 @@ int64_t quicly_loss_init_sentmap_iter(quicly_loss_t *loss, quicly_sentmap_iter_t return 0; } -int64_t quicly_loss_detect_loss(quicly_loss_t *loss, int64_t now, uint32_t max_ack_delay, int is_1rtt_only, - quicly_loss_on_detect_cb on_loss_detected) +quicly_error_t quicly_loss_detect_loss(quicly_loss_t *loss, int64_t now, uint32_t max_ack_delay, int is_1rtt_only, + quicly_loss_on_detect_cb on_loss_detected) { /* This function ensures that the value returned in loss_time is when the next application timer should be set for loss * detection. if no timer is required, loss_time is set to INT64_MAX. */ @@ -63,7 +63,7 @@ int64_t quicly_loss_detect_loss(quicly_loss_t *loss, int64_t now, uint32_t max_a 1024; quicly_sentmap_iter_t iter; const quicly_sent_packet_t *sent; - int64_t ret; + quicly_error_t ret; #define CHECK_TIME_THRESHOLD(sent) ((sent)->sent_at <= now - delay_until_lost) #define CHECK_PACKET_THRESHOLD(sent) \ diff --git a/lib/quicly.c b/lib/quicly.c index 02f16e34..59032431 100644 --- a/lib/quicly.c +++ b/lib/quicly.c @@ -514,9 +514,9 @@ static const quicly_stream_callbacks_t crypto_stream_callbacks = {quicly_streamb quicly_streambuf_egress_emit, NULL, crypto_stream_receive}; static int update_traffic_key_cb(ptls_update_traffic_key_t *self, ptls_t *tls, int is_enc, size_t epoch, const void *secret); -static int64_t initiate_close(quicly_conn_t *conn, int64_t err, uint64_t frame_type, const char *reason_phrase); -static int64_t handle_close(quicly_conn_t *conn, int64_t err, uint64_t frame_type, ptls_iovec_t reason_phrase); -static int64_t discard_sentmap_by_epoch(quicly_conn_t *conn, unsigned ack_epochs); +static quicly_error_t initiate_close(quicly_conn_t *conn, quicly_error_t err, uint64_t frame_type, const char *reason_phrase); +static quicly_error_t handle_close(quicly_conn_t *conn, quicly_error_t err, uint64_t frame_type, ptls_iovec_t reason_phrase); +static quicly_error_t discard_sentmap_by_epoch(quicly_conn_t *conn, unsigned ack_epochs); quicly_cid_plaintext_t quicly_cid_plaintext_invalid = {.node_id = UINT64_MAX, .thread_id = 0xffffff}; @@ -861,7 +861,7 @@ static void assert_consistency(quicly_conn_t *conn, int timer_must_be_in_future) assert(conn->stash.now < conn->egress.loss.alarm_at); } -static int64_t on_invalid_ack(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, quicly_sent_t *sent) +static quicly_error_t on_invalid_ack(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, quicly_sent_t *sent) { if (acked) return QUICLY_TRANSPORT_ERROR_PROTOCOL_VIOLATION; @@ -894,7 +894,7 @@ static void init_max_streams(struct st_quicly_max_streams_t *m) quicly_maxsender_init(&m->blocked_sender, -1); } -static int64_t update_max_streams(struct st_quicly_max_streams_t *m, uint64_t count) +static quicly_error_t update_max_streams(struct st_quicly_max_streams_t *m, uint64_t count) { if (count > (uint64_t)1 << 60) return QUICLY_TRANSPORT_ERROR_STREAM_LIMIT; @@ -1061,18 +1061,18 @@ static int write_crypto_data(quicly_conn_t *conn, ptls_buffer_t *tlsbuf, size_t /** * compresses a quicly error code into an int, converting QUIC transport error codes into negative ints */ -static int compress_handshake_result(int64_t native_err) +static int compress_handshake_result(quicly_error_t quicly_err) { - if (QUICLY_ERROR_IS_QUIC_TRANSPORT(native_err)) { - assert(QUICLY_ERROR_GET_ERROR_CODE(native_err) <= INT32_MAX); - return (int)-QUICLY_ERROR_GET_ERROR_CODE(native_err); + if (QUICLY_ERROR_IS_QUIC_TRANSPORT(quicly_err)) { + assert(QUICLY_ERROR_GET_ERROR_CODE(quicly_err) <= INT32_MAX); + return (int)-QUICLY_ERROR_GET_ERROR_CODE(quicly_err); } else { - assert(0 <= native_err && native_err < INT_MAX); - return (int)native_err; + assert(0 <= quicly_err && quicly_err < INT_MAX); + return (int)quicly_err; } } -static int64_t expand_handshake_result(int compressed_err) +static quicly_error_t expand_handshake_result(int compressed_err) { if (compressed_err < 0) { return QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(-compressed_err); @@ -1090,7 +1090,7 @@ static void crypto_handshake(quicly_conn_t *conn, size_t in_epoch, ptls_iovec_t ptls_buffer_init(&output, "", 0); - int64_t handshake_result = expand_handshake_result(ptls_handle_message( + quicly_error_t handshake_result = expand_handshake_result(ptls_handle_message( conn->crypto.tls, &output, epoch_offsets, in_epoch, input.base, input.len, &conn->crypto.handshake_properties)); QUICLY_PROBE(CRYPTO_HANDSHAKE, conn, conn->stash.now, handshake_result); QUICLY_LOG_CONN(crypto_handshake, conn, { PTLS_LOG_ELEMENT_SIGNED(ret, handshake_result); }); @@ -1120,7 +1120,7 @@ static void crypto_handshake(quicly_conn_t *conn, size_t in_epoch, ptls_iovec_t dispose_cipher(&conn->application->cipher.egress.key); conn->application->cipher.egress.key = (struct st_quicly_cipher_context_t){NULL}; /* retire all packets with ack_epoch == 3; they are all 0-RTT packets */ - int64_t ret; + quicly_error_t ret; if ((ret = discard_sentmap_by_epoch(conn, 1u << QUICLY_EPOCH_1RTT)) != 0) { initiate_close(conn, ret, QUICLY_FRAME_TYPE_CRYPTO, NULL); goto Exit; @@ -1289,7 +1289,7 @@ static int should_send_max_streams(quicly_conn_t *conn, int uni) return 1; } -static void destroy_stream(quicly_stream_t *stream, int64_t err) +static void destroy_stream(quicly_stream_t *stream, quicly_error_t err) { quicly_conn_t *conn = stream->conn; @@ -1322,7 +1322,7 @@ static void destroy_stream(quicly_stream_t *stream, int64_t err) free(stream); } -static void destroy_all_streams(quicly_conn_t *conn, int64_t err, int including_crypto_streams) +static void destroy_all_streams(quicly_conn_t *conn, quicly_error_t err, int including_crypto_streams) { quicly_stream_t *stream; kh_foreach_value(conn->streams, stream, { @@ -1376,7 +1376,7 @@ struct sockaddr *quicly_get_peername(quicly_conn_t *conn) return &conn->paths[0]->address.remote.sa; } -int64_t quicly_get_stats(quicly_conn_t *conn, quicly_stats_t *stats) +quicly_error_t quicly_get_stats(quicly_conn_t *conn, quicly_stats_t *stats) { /* copy the pre-built stats fields */ memcpy(stats, &conn->super.stats, sizeof(conn->super.stats)); @@ -1397,7 +1397,7 @@ int64_t quicly_get_stats(quicly_conn_t *conn, quicly_stats_t *stats) return 0; } -int64_t quicly_get_delivery_rate(quicly_conn_t *conn, quicly_rate_t *delivery_rate) +quicly_error_t quicly_get_delivery_rate(quicly_conn_t *conn, quicly_rate_t *delivery_rate) { quicly_ratemeter_report(&conn->egress.ratemeter, delivery_rate); return 0; @@ -1548,9 +1548,9 @@ static void do_free_pn_space(struct st_quicly_pn_space_t *space) free(space); } -static int64_t record_pn(quicly_ranges_t *ranges, uint64_t pn, int *is_out_of_order) +static quicly_error_t record_pn(quicly_ranges_t *ranges, uint64_t pn, int *is_out_of_order) { - int64_t ret; + quicly_error_t ret; *is_out_of_order = 0; @@ -1572,11 +1572,11 @@ static int64_t record_pn(quicly_ranges_t *ranges, uint64_t pn, int *is_out_of_or return 0; } -static int64_t record_receipt(struct st_quicly_pn_space_t *space, uint64_t pn, uint8_t ecn, int is_ack_only, int64_t now, - int64_t *send_ack_at, uint64_t *received_out_of_order) +static quicly_error_t record_receipt(struct st_quicly_pn_space_t *space, uint64_t pn, uint8_t ecn, int is_ack_only, int64_t now, + int64_t *send_ack_at, uint64_t *received_out_of_order) { int ack_now, is_out_of_order; - int64_t ret; + quicly_error_t ret; if ((ret = record_pn(&space->ack_queue, pn, &is_out_of_order)) != 0) goto Exit; @@ -1673,9 +1673,9 @@ static int setup_application_space(quicly_conn_t *conn) return create_handshake_flow(conn, QUICLY_EPOCH_1RTT); } -static int64_t discard_handshake_context(quicly_conn_t *conn, size_t epoch) +static quicly_error_t discard_handshake_context(quicly_conn_t *conn, size_t epoch) { - int64_t ret; + quicly_error_t ret; assert(epoch == QUICLY_EPOCH_INITIAL || epoch == QUICLY_EPOCH_HANDSHAKE); @@ -1691,9 +1691,9 @@ static int64_t discard_handshake_context(quicly_conn_t *conn, size_t epoch) return 0; } -static int64_t apply_remote_transport_params(quicly_conn_t *conn) +static quicly_error_t apply_remote_transport_params(quicly_conn_t *conn) { - int64_t ret; + quicly_error_t ret; conn->egress.max_data.permitted = conn->super.remote.transport_params.max_data; if ((ret = update_max_streams(&conn->egress.max_streams.uni, conn->super.remote.transport_params.max_streams_uni)) != 0) @@ -1903,14 +1903,14 @@ static void delete_path(quicly_conn_t *conn, size_t path_index) /** * paths[0] (the default path) is freed and the path specified by `path_index` is promoted */ -static int64_t promote_path(quicly_conn_t *conn, size_t path_index) +static quicly_error_t promote_path(quicly_conn_t *conn, size_t path_index) { QUICLY_PROBE(PROMOTE_PATH, conn, conn->stash.now, path_index); QUICLY_LOG_CONN(promote_path, conn, { PTLS_LOG_ELEMENT_UNSIGNED(path_index, path_index); }); { /* mark all packets as lost, as it is unlikely that packets sent on the old path wound be acknowledged */ quicly_sentmap_iter_t iter; - int64_t ret; + quicly_error_t ret; if ((ret = quicly_loss_init_sentmap_iter(&conn->egress.loss, &iter, conn->stash.now, conn->super.remote.transport_params.max_ack_delay, 0)) != 0) return ret; @@ -2120,7 +2120,7 @@ static int setup_initial_encryption(ptls_cipher_suite_t *cs, struct st_quicly_ci return ret; } -static int64_t reinstall_initial_encryption(quicly_conn_t *conn, int64_t err_code_if_unknown_version) +static quicly_error_t reinstall_initial_encryption(quicly_conn_t *conn, quicly_error_t err_code_if_unknown_version) { const quicly_salt_t *salt; @@ -2139,9 +2139,9 @@ static int64_t reinstall_initial_encryption(quicly_conn_t *conn, int64_t err_cod ptls_iovec_init(salt->initial, sizeof(salt->initial)), NULL); } -static int64_t apply_stream_frame(quicly_stream_t *stream, quicly_stream_frame_t *frame) +static quicly_error_t apply_stream_frame(quicly_stream_t *stream, quicly_stream_frame_t *frame) { - int64_t ret; + quicly_error_t ret; QUICLY_PROBE(STREAM_RECEIVE, stream->conn, stream->conn->stash.now, stream, frame->offset, frame->data.len); QUICLY_LOG_CONN(stream_receive, stream->conn, { @@ -2289,9 +2289,9 @@ int quicly_encode_transport_parameter_list(ptls_buffer_t *buf, const quicly_tran static const quicly_cid_t _tp_cid_ignore; #define tp_cid_ignore (*(quicly_cid_t *)&_tp_cid_ignore) -int64_t quicly_decode_transport_parameter_list(quicly_transport_parameters_t *params, quicly_cid_t *original_dcid, - quicly_cid_t *initial_scid, quicly_cid_t *retry_scid, void *stateless_reset_token, - const uint8_t *src, const uint8_t *end) +quicly_error_t quicly_decode_transport_parameter_list(quicly_transport_parameters_t *params, quicly_cid_t *original_dcid, + quicly_cid_t *initial_scid, quicly_cid_t *retry_scid, + void *stateless_reset_token, const uint8_t *src, const uint8_t *end) { /* When non-negative, tp_index contains the literal position within the list of transport parameters recognized by this function. * That index is being used to find duplicates using a 64-bit bitmap (found_bits). When the transport parameter is being processed, @@ -2328,7 +2328,7 @@ int64_t quicly_decode_transport_parameter_list(quicly_transport_parameters_t *pa }); uint64_t found_bits = 0; - int64_t ret; + quicly_error_t ret; /* set parameters to their default values */ *params = default_transport_params; @@ -2658,7 +2658,7 @@ static quicly_conn_t *create_connection(quicly_context_t *ctx, uint32_t protocol static int client_collected_extensions(ptls_t *tls, ptls_handshake_properties_t *properties, ptls_raw_extension_t *slots) { quicly_conn_t *conn = (void *)((char *)properties - offsetof(quicly_conn_t, crypto.handshake_properties)); - int64_t ret; + quicly_error_t ret; assert(properties->client.early_data_acceptance != PTLS_EARLY_DATA_ACCEPTANCE_UNKNOWN); @@ -2728,10 +2728,10 @@ static int client_collected_extensions(ptls_t *tls, ptls_handshake_properties_t return compress_handshake_result(ret); } -int64_t quicly_connect(quicly_conn_t **_conn, quicly_context_t *ctx, const char *server_name, struct sockaddr *dest_addr, - struct sockaddr *src_addr, const quicly_cid_plaintext_t *new_cid, ptls_iovec_t address_token, - ptls_handshake_properties_t *handshake_properties, - const quicly_transport_parameters_t *resumed_transport_params, void *appdata) +quicly_error_t quicly_connect(quicly_conn_t **_conn, quicly_context_t *ctx, const char *server_name, struct sockaddr *dest_addr, + struct sockaddr *src_addr, const quicly_cid_plaintext_t *new_cid, ptls_iovec_t address_token, + ptls_handshake_properties_t *handshake_properties, + const quicly_transport_parameters_t *resumed_transport_params, void *appdata) { const quicly_salt_t *salt; quicly_conn_t *conn = NULL; @@ -2739,7 +2739,7 @@ int64_t quicly_connect(quicly_conn_t **_conn, quicly_context_t *ctx, const char ptls_buffer_t buf; size_t epoch_offsets[5] = {0}; size_t max_early_data_size = 0; - int64_t ret; + quicly_error_t ret; if ((salt = quicly_get_salt(ctx->initial_version)) == NULL) { if ((ctx->initial_version & 0x0f0f0f0f) == 0x0a0a0a0a) { @@ -2843,7 +2843,7 @@ static int server_collected_extensions(ptls_t *tls, ptls_handshake_properties_t { quicly_conn_t *conn = (void *)((char *)properties - offsetof(quicly_conn_t, crypto.handshake_properties)); quicly_cid_t initial_scid; - int64_t ret; + quicly_error_t ret; if (slots[0].type == UINT16_MAX) { ret = PTLS_ALERT_MISSING_EXTENSION; @@ -2973,9 +2973,10 @@ static int aead_decrypt_1rtt(void *ctx, uint64_t pn, quicly_decoded_packet_t *pa return 0; } -static int64_t do_decrypt_packet(ptls_cipher_context_t *header_protection, - int (*aead_cb)(void *, uint64_t, quicly_decoded_packet_t *, size_t, size_t *), void *aead_ctx, - uint64_t *next_expected_pn, quicly_decoded_packet_t *packet, uint64_t *pn, ptls_iovec_t *payload) +static quicly_error_t do_decrypt_packet(ptls_cipher_context_t *header_protection, + int (*aead_cb)(void *, uint64_t, quicly_decoded_packet_t *, size_t, size_t *), + void *aead_ctx, uint64_t *next_expected_pn, quicly_decoded_packet_t *packet, uint64_t *pn, + ptls_iovec_t *payload) { size_t encrypted_len = packet->octets.len - packet->encrypted_off; uint8_t hpmask[5] = {0}; @@ -3011,11 +3012,12 @@ static int64_t do_decrypt_packet(ptls_cipher_context_t *header_protection, return 0; } -static int64_t decrypt_packet(ptls_cipher_context_t *header_protection, - int (*aead_cb)(void *, uint64_t, quicly_decoded_packet_t *, size_t, size_t *), void *aead_ctx, - uint64_t *next_expected_pn, quicly_decoded_packet_t *packet, uint64_t *pn, ptls_iovec_t *payload) +static quicly_error_t decrypt_packet(ptls_cipher_context_t *header_protection, + int (*aead_cb)(void *, uint64_t, quicly_decoded_packet_t *, size_t, size_t *), void *aead_ctx, + uint64_t *next_expected_pn, quicly_decoded_packet_t *packet, uint64_t *pn, + ptls_iovec_t *payload) { - int64_t ret; + quicly_error_t ret; /* decrypt ourselves, or use the pre-decrypted input */ if (packet->decrypted.pn == UINT64_MAX) { @@ -3048,8 +3050,8 @@ static int64_t decrypt_packet(ptls_cipher_context_t *header_protection, return 0; } -static int64_t do_on_ack_ack(quicly_conn_t *conn, const quicly_sent_packet_t *packet, uint64_t start, uint64_t start_length, - struct st_quicly_sent_ack_additional_t *additional, size_t additional_capacity) +static quicly_error_t do_on_ack_ack(quicly_conn_t *conn, const quicly_sent_packet_t *packet, uint64_t start, uint64_t start_length, + struct st_quicly_sent_ack_additional_t *additional, size_t additional_capacity) { /* find the pn space */ struct st_quicly_pn_space_t *space; @@ -3069,7 +3071,7 @@ static int64_t do_on_ack_ack(quicly_conn_t *conn, const quicly_sent_packet_t *pa } /* subtract given ACK ranges */ - int64_t ret; + quicly_error_t ret; uint64_t end = start + start_length; if ((ret = quicly_ranges_subtract(&space->ack_queue, start, end)) != 0) return ret; @@ -3092,7 +3094,7 @@ static int64_t do_on_ack_ack(quicly_conn_t *conn, const quicly_sent_packet_t *pa return 0; } -static int64_t on_ack_ack_ranges64(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, quicly_sent_t *sent) +static quicly_error_t on_ack_ack_ranges64(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, quicly_sent_t *sent) { quicly_conn_t *conn = (quicly_conn_t *)((char *)map - offsetof(quicly_conn_t, egress.loss.sentmap)); @@ -3103,7 +3105,7 @@ static int64_t on_ack_ack_ranges64(quicly_sentmap_t *map, const quicly_sent_pack : 0; } -static int64_t on_ack_ack_ranges8(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, quicly_sent_t *sent) +static quicly_error_t on_ack_ack_ranges8(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, quicly_sent_t *sent) { quicly_conn_t *conn = (quicly_conn_t *)((char *)map - offsetof(quicly_conn_t, egress.loss.sentmap)); @@ -3114,10 +3116,10 @@ static int64_t on_ack_ack_ranges8(quicly_sentmap_t *map, const quicly_sent_packe : 0; } -static int64_t on_ack_stream_ack_one(quicly_conn_t *conn, quicly_stream_id_t stream_id, quicly_sendstate_sent_t *sent) +static quicly_error_t on_ack_stream_ack_one(quicly_conn_t *conn, quicly_stream_id_t stream_id, quicly_sendstate_sent_t *sent) { quicly_stream_t *stream; - int64_t ret; + quicly_error_t ret; if ((stream = quicly_get_stream(conn, stream_id)) == NULL) return 0; @@ -3142,9 +3144,9 @@ static int64_t on_ack_stream_ack_one(quicly_conn_t *conn, quicly_stream_id_t str return 0; } -static int64_t on_ack_stream_ack_cached(quicly_conn_t *conn) +static quicly_error_t on_ack_stream_ack_cached(quicly_conn_t *conn) { - int64_t ret; + quicly_error_t ret; if (conn->stash.on_ack_stream.active_acked_cache.stream_id == INT64_MIN) return 0; @@ -3154,10 +3156,10 @@ static int64_t on_ack_stream_ack_cached(quicly_conn_t *conn) return ret; } -static int64_t on_ack_stream(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, quicly_sent_t *sent) +static quicly_error_t on_ack_stream(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, quicly_sent_t *sent) { quicly_conn_t *conn = (quicly_conn_t *)((char *)map - offsetof(quicly_conn_t, egress.loss.sentmap)); - int64_t ret; + quicly_error_t ret; if (acked) { @@ -3210,7 +3212,8 @@ static int64_t on_ack_stream(quicly_sentmap_t *map, const quicly_sent_packet_t * return 0; } -static int64_t on_ack_max_stream_data(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, quicly_sent_t *sent) +static quicly_error_t on_ack_max_stream_data(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, + quicly_sent_t *sent) { quicly_conn_t *conn = (quicly_conn_t *)((char *)map - offsetof(quicly_conn_t, egress.loss.sentmap)); quicly_stream_t *stream; @@ -3228,7 +3231,7 @@ static int64_t on_ack_max_stream_data(quicly_sentmap_t *map, const quicly_sent_p return 0; } -static int64_t on_ack_max_data(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, quicly_sent_t *sent) +static quicly_error_t on_ack_max_data(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, quicly_sent_t *sent) { quicly_conn_t *conn = (quicly_conn_t *)((char *)map - offsetof(quicly_conn_t, egress.loss.sentmap)); @@ -3241,7 +3244,7 @@ static int64_t on_ack_max_data(quicly_sentmap_t *map, const quicly_sent_packet_t return 0; } -static int64_t on_ack_max_streams(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, quicly_sent_t *sent) +static quicly_error_t on_ack_max_streams(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, quicly_sent_t *sent) { quicly_conn_t *conn = (quicly_conn_t *)((char *)map - offsetof(quicly_conn_t, egress.loss.sentmap)); quicly_maxsender_t *maxsender = sent->data.max_streams.uni ? &conn->ingress.max_streams.uni : &conn->ingress.max_streams.bidi; @@ -3261,7 +3264,7 @@ static void on_ack_stream_state_sender(quicly_sender_state_t *sender_state, int *sender_state = acked ? QUICLY_SENDER_STATE_ACKED : QUICLY_SENDER_STATE_SEND; } -static int64_t on_ack_reset_stream(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, quicly_sent_t *sent) +static quicly_error_t on_ack_reset_stream(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, quicly_sent_t *sent) { quicly_conn_t *conn = (quicly_conn_t *)((char *)map - offsetof(quicly_conn_t, egress.loss.sentmap)); quicly_stream_t *stream; @@ -3275,7 +3278,7 @@ static int64_t on_ack_reset_stream(quicly_sentmap_t *map, const quicly_sent_pack return 0; } -static int64_t on_ack_stop_sending(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, quicly_sent_t *sent) +static quicly_error_t on_ack_stop_sending(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, quicly_sent_t *sent) { quicly_conn_t *conn = (quicly_conn_t *)((char *)map - offsetof(quicly_conn_t, egress.loss.sentmap)); quicly_stream_t *stream; @@ -3289,7 +3292,8 @@ static int64_t on_ack_stop_sending(quicly_sentmap_t *map, const quicly_sent_pack return 0; } -static int64_t on_ack_streams_blocked(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, quicly_sent_t *sent) +static quicly_error_t on_ack_streams_blocked(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, + quicly_sent_t *sent) { quicly_conn_t *conn = (quicly_conn_t *)((char *)map - offsetof(quicly_conn_t, egress.loss.sentmap)); struct st_quicly_max_streams_t *m = @@ -3304,7 +3308,8 @@ static int64_t on_ack_streams_blocked(quicly_sentmap_t *map, const quicly_sent_p return 0; } -static int64_t on_ack_handshake_done(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, quicly_sent_t *sent) +static quicly_error_t on_ack_handshake_done(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, + quicly_sent_t *sent) { quicly_conn_t *conn = (quicly_conn_t *)((char *)map - offsetof(quicly_conn_t, egress.loss.sentmap)); @@ -3317,7 +3322,7 @@ static int64_t on_ack_handshake_done(quicly_sentmap_t *map, const quicly_sent_pa return 0; } -static int64_t on_ack_data_blocked(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, quicly_sent_t *sent) +static quicly_error_t on_ack_data_blocked(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, quicly_sent_t *sent) { quicly_conn_t *conn = (quicly_conn_t *)((char *)map - offsetof(quicly_conn_t, egress.loss.sentmap)); @@ -3333,8 +3338,8 @@ static int64_t on_ack_data_blocked(quicly_sentmap_t *map, const quicly_sent_pack return 0; } -static int64_t on_ack_stream_data_blocked_frame(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, - quicly_sent_t *sent) +static quicly_error_t on_ack_stream_data_blocked_frame(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, + quicly_sent_t *sent) { quicly_conn_t *conn = (quicly_conn_t *)((char *)map - offsetof(quicly_conn_t, egress.loss.sentmap)); quicly_stream_t *stream; @@ -3354,7 +3359,7 @@ static int64_t on_ack_stream_data_blocked_frame(quicly_sentmap_t *map, const qui return 0; } -static int64_t on_ack_new_token(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, quicly_sent_t *sent) +static quicly_error_t on_ack_new_token(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, quicly_sent_t *sent) { quicly_conn_t *conn = (quicly_conn_t *)((char *)map - offsetof(quicly_conn_t, egress.loss.sentmap)); @@ -3375,7 +3380,8 @@ static int64_t on_ack_new_token(quicly_sentmap_t *map, const quicly_sent_packet_ return 0; } -static int64_t on_ack_new_connection_id(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, quicly_sent_t *sent) +static quicly_error_t on_ack_new_connection_id(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, + quicly_sent_t *sent) { quicly_conn_t *conn = (quicly_conn_t *)((char *)map - offsetof(quicly_conn_t, egress.loss.sentmap)); uint64_t sequence = sent->data.new_connection_id.sequence; @@ -3390,8 +3396,8 @@ static int64_t on_ack_new_connection_id(quicly_sentmap_t *map, const quicly_sent return 0; } -static int64_t on_ack_retire_connection_id(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, - quicly_sent_t *sent) +static quicly_error_t on_ack_retire_connection_id(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, + quicly_sent_t *sent) { quicly_conn_t *conn = (quicly_conn_t *)((char *)map - offsetof(quicly_conn_t, egress.loss.sentmap)); uint64_t sequence = sent->data.retire_connection_id.sequence; @@ -3668,7 +3674,7 @@ struct st_quicly_send_context_t { unsigned recalc_send_probe_at : 1; }; -static int64_t commit_send_packet(quicly_conn_t *conn, quicly_send_context_t *s, int coalesced) +static quicly_error_t commit_send_packet(quicly_conn_t *conn, quicly_send_context_t *s, int coalesced) { size_t datagram_size, packet_bytes_in_flight; @@ -3774,7 +3780,7 @@ static int64_t commit_send_packet(quicly_conn_t *conn, quicly_send_context_t *s, * an ACK for that gap. */ if (conn->egress.packet_number >= conn->egress.next_pn_to_skip && !QUICLY_PACKET_IS_LONG_HEADER(s->current.first_byte) && conn->super.state < QUICLY_STATE_CLOSING) { - int64_t ret; + quicly_error_t ret; if ((ret = quicly_sentmap_prepare(&conn->egress.loss.sentmap, conn->egress.packet_number, conn->stash.now, QUICLY_EPOCH_1RTT)) != 0) return ret; @@ -3804,11 +3810,11 @@ enum allocate_frame_type { ALLOCATE_FRAME_TYPE_ACK_ELICITING_NO_CC, }; -static int64_t do_allocate_frame(quicly_conn_t *conn, quicly_send_context_t *s, size_t min_space, - enum allocate_frame_type frame_type) +static quicly_error_t do_allocate_frame(quicly_conn_t *conn, quicly_send_context_t *s, size_t min_space, + enum allocate_frame_type frame_type) { int coalescible; - int64_t ret; + quicly_error_t ret; assert((s->current.first_byte & QUICLY_QUIC_BIT) != 0); @@ -3936,10 +3942,10 @@ static int64_t do_allocate_frame(quicly_conn_t *conn, quicly_send_context_t *s, return 0; } -static int64_t allocate_ack_eliciting_frame(quicly_conn_t *conn, quicly_send_context_t *s, size_t min_space, quicly_sent_t **sent, - quicly_sent_acked_cb acked) +static quicly_error_t allocate_ack_eliciting_frame(quicly_conn_t *conn, quicly_send_context_t *s, size_t min_space, + quicly_sent_t **sent, quicly_sent_acked_cb acked) { - int64_t ret; + quicly_error_t ret; if ((ret = do_allocate_frame(conn, s, min_space, ALLOCATE_FRAME_TYPE_ACK_ELICITING)) != 0) return ret; @@ -3949,10 +3955,10 @@ static int64_t allocate_ack_eliciting_frame(quicly_conn_t *conn, quicly_send_con return ret; } -static int64_t send_ack(quicly_conn_t *conn, struct st_quicly_pn_space_t *space, quicly_send_context_t *s) +static quicly_error_t send_ack(quicly_conn_t *conn, struct st_quicly_pn_space_t *space, quicly_send_context_t *s) { uint64_t ack_delay; - int64_t ret; + quicly_error_t ret; if (space->ack_queue.num_ranges == 0) return 0; @@ -4046,11 +4052,11 @@ static int64_t send_ack(quicly_conn_t *conn, struct st_quicly_pn_space_t *space, return ret; } -static int64_t prepare_stream_state_sender(quicly_stream_t *stream, quicly_sender_state_t *sender, quicly_send_context_t *s, - size_t min_space, quicly_sent_acked_cb ack_cb) +static quicly_error_t prepare_stream_state_sender(quicly_stream_t *stream, quicly_sender_state_t *sender, quicly_send_context_t *s, + size_t min_space, quicly_sent_acked_cb ack_cb) { quicly_sent_t *sent; - int64_t ret; + quicly_error_t ret; if ((ret = allocate_ack_eliciting_frame(stream->conn, s, min_space, &sent, ack_cb)) != 0) return ret; @@ -4060,9 +4066,9 @@ static int64_t prepare_stream_state_sender(quicly_stream_t *stream, quicly_sende return 0; } -static int64_t send_control_frames_of_stream(quicly_stream_t *stream, quicly_send_context_t *s) +static quicly_error_t send_control_frames_of_stream(quicly_stream_t *stream, quicly_send_context_t *s) { - int64_t ret; + quicly_error_t ret; /* send STOP_SENDING if necessary */ if (stream->_send_aux.stop_sending.sender_state == QUICLY_SENDER_STATE_SEND) { @@ -4141,9 +4147,9 @@ static int64_t send_control_frames_of_stream(quicly_stream_t *stream, quicly_sen return 0; } -static int64_t send_stream_control_frames(quicly_conn_t *conn, quicly_send_context_t *s) +static quicly_error_t send_stream_control_frames(quicly_conn_t *conn, quicly_send_context_t *s) { - int64_t ret = 0; + quicly_error_t ret = 0; while (s->num_datagrams != s->max_datagrams && quicly_linklist_is_linked(&conn->egress.pending_streams.control)) { quicly_stream_t *stream = @@ -4240,7 +4246,7 @@ static inline void adjust_stream_frame_layout(uint8_t **dst, uint8_t *const dst_ *dst += *len; } -int64_t quicly_send_stream(quicly_stream_t *stream, quicly_send_context_t *s) +quicly_error_t quicly_send_stream(quicly_stream_t *stream, quicly_send_context_t *s) { uint64_t off = stream->sendstate.pending.ranges[0].start; quicly_sent_t *sent; @@ -4248,7 +4254,7 @@ int64_t quicly_send_stream(quicly_stream_t *stream, quicly_send_context_t *s) * beginning of the frame. */ size_t len; int wrote_all, is_fin; - int64_t ret; + quicly_error_t ret; /* write frame type, stream_id and offset, calculate capacity (and store that in `len`) */ if (stream->stream_id < 0) { @@ -4390,18 +4396,18 @@ int64_t quicly_send_stream(quicly_stream_t *stream, quicly_send_context_t *s) return 0; } -static inline int64_t init_acks_iter(quicly_conn_t *conn, quicly_sentmap_iter_t *iter) +static inline quicly_error_t init_acks_iter(quicly_conn_t *conn, quicly_sentmap_iter_t *iter) { return quicly_loss_init_sentmap_iter(&conn->egress.loss, iter, conn->stash.now, conn->super.remote.transport_params.max_ack_delay, conn->super.state >= QUICLY_STATE_CLOSING); } -int64_t discard_sentmap_by_epoch(quicly_conn_t *conn, unsigned ack_epochs) +quicly_error_t discard_sentmap_by_epoch(quicly_conn_t *conn, unsigned ack_epochs) { quicly_sentmap_iter_t iter; const quicly_sent_packet_t *sent; - int64_t ret; + quicly_error_t ret; if ((ret = init_acks_iter(conn, &iter)) != 0) return ret; @@ -4421,11 +4427,11 @@ int64_t discard_sentmap_by_epoch(quicly_conn_t *conn, unsigned ack_epochs) /** * Mark frames of given epoch as pending, until `*bytes_to_mark` becomes zero. */ -static int64_t mark_frames_on_pto(quicly_conn_t *conn, uint8_t ack_epoch, size_t *bytes_to_mark) +static quicly_error_t mark_frames_on_pto(quicly_conn_t *conn, uint8_t ack_epoch, size_t *bytes_to_mark) { quicly_sentmap_iter_t iter; const quicly_sent_packet_t *sent; - int64_t ret; + quicly_error_t ret; if ((ret = init_acks_iter(conn, &iter)) != 0) return ret; @@ -4481,14 +4487,14 @@ static void on_loss_detected(quicly_loss_t *loss, const quicly_sent_packet_t *lo conn->egress.loss.sentmap.bytes_in_flight); } -static int64_t send_max_streams(quicly_conn_t *conn, int uni, quicly_send_context_t *s) +static quicly_error_t send_max_streams(quicly_conn_t *conn, int uni, quicly_send_context_t *s) { if (!should_send_max_streams(conn, uni)) return 0; quicly_maxsender_t *maxsender = uni ? &conn->ingress.max_streams.uni : &conn->ingress.max_streams.bidi; struct st_quicly_conn_streamgroup_state_t *group = uni ? &conn->super.remote.uni : &conn->super.remote.bidi; - int64_t ret; + quicly_error_t ret; uint64_t new_count = group->next_stream_id / 4 + @@ -4516,10 +4522,10 @@ static int64_t send_max_streams(quicly_conn_t *conn, int uni, quicly_send_contex return 0; } -static int64_t send_streams_blocked(quicly_conn_t *conn, int uni, quicly_send_context_t *s) +static quicly_error_t send_streams_blocked(quicly_conn_t *conn, int uni, quicly_send_context_t *s) { quicly_linklist_t *blocked_list = uni ? &conn->egress.pending_streams.blocked.uni : &conn->egress.pending_streams.blocked.bidi; - int64_t ret; + quicly_error_t ret; if (!quicly_linklist_is_linked(blocked_list)) return 0; @@ -4578,10 +4584,10 @@ static void open_blocked_streams(quicly_conn_t *conn, int uni) } } -static int64_t send_handshake_done(quicly_conn_t *conn, quicly_send_context_t *s) +static quicly_error_t send_handshake_done(quicly_conn_t *conn, quicly_send_context_t *s) { quicly_sent_t *sent; - int64_t ret; + quicly_error_t ret; if ((ret = allocate_ack_eliciting_frame(conn, s, 1, &sent, on_ack_handshake_done)) != 0) goto Exit; @@ -4596,10 +4602,10 @@ static int64_t send_handshake_done(quicly_conn_t *conn, quicly_send_context_t *s return ret; } -static int64_t send_data_blocked(quicly_conn_t *conn, quicly_send_context_t *s) +static quicly_error_t send_data_blocked(quicly_conn_t *conn, quicly_send_context_t *s) { quicly_sent_t *sent; - int64_t ret; + quicly_error_t ret; uint64_t offset = conn->egress.max_data.permitted; if ((ret = allocate_ack_eliciting_frame(conn, s, QUICLY_DATA_BLOCKED_FRAME_CAPACITY, &sent, on_ack_data_blocked)) != 0) @@ -4707,7 +4713,7 @@ static size_t encode_resumption_info(quicly_conn_t *conn, uint8_t *dst, size_t c return buf.off; } -static int64_t send_resumption_token(quicly_conn_t *conn, quicly_send_context_t *s) +static quicly_error_t send_resumption_token(quicly_conn_t *conn, quicly_send_context_t *s) { /* fill conn->super.stats.token_sent the information we are sending now */ calc_resume_sendrate(conn, &conn->super.stats.token_sent.rate, &conn->super.stats.token_sent.rtt); @@ -4716,7 +4722,7 @@ static int64_t send_resumption_token(quicly_conn_t *conn, quicly_send_context_t ptls_buffer_t tokenbuf; uint8_t tokenbuf_small[128]; quicly_sent_t *sent; - int64_t ret; + quicly_error_t ret; ptls_buffer_init(&tokenbuf, tokenbuf_small, sizeof(tokenbuf_small)); @@ -4789,8 +4795,8 @@ size_t quicly_send_version_negotiation(quicly_context_t *ctx, ptls_iovec_t dest_ return dst - (uint8_t *)payload; } -int64_t quicly_retry_calc_cidpair_hash(ptls_hash_algorithm_t *sha256, ptls_iovec_t client_cid, ptls_iovec_t server_cid, - uint64_t *value) +quicly_error_t quicly_retry_calc_cidpair_hash(ptls_hash_algorithm_t *sha256, ptls_iovec_t client_cid, ptls_iovec_t server_cid, + uint64_t *value) { uint8_t digest[PTLS_SHA256_DIGEST_SIZE], buf[(QUICLY_MAX_CID_LEN_V1 + 1) * 2], *p = buf; int ret; @@ -4817,7 +4823,7 @@ size_t quicly_send_retry(quicly_context_t *ctx, ptls_aead_context_t *token_encry { quicly_address_token_plaintext_t token; ptls_buffer_t buf; - int64_t ret; + quicly_error_t ret; assert(!(src_cid.len == odcid.len && memcmp(src_cid.base, odcid.base, src_cid.len) == 0)); @@ -4916,10 +4922,10 @@ static struct st_quicly_pn_space_t *setup_send_space(quicly_conn_t *conn, size_t return space; } -static int64_t send_handshake_flow(quicly_conn_t *conn, size_t epoch, quicly_send_context_t *s, int ack_only, int send_probe) +static quicly_error_t send_handshake_flow(quicly_conn_t *conn, size_t epoch, quicly_send_context_t *s, int ack_only, int send_probe) { struct st_quicly_pn_space_t *space; - int64_t ret = 0; + quicly_error_t ret = 0; /* setup send epoch, or return if it's impossible to send in this epoch */ if ((space = setup_send_space(conn, epoch, s)) == NULL) @@ -4957,11 +4963,11 @@ static int64_t send_handshake_flow(quicly_conn_t *conn, size_t epoch, quicly_sen return ret; } -static int64_t send_connection_close(quicly_conn_t *conn, size_t epoch, quicly_send_context_t *s) +static quicly_error_t send_connection_close(quicly_conn_t *conn, size_t epoch, quicly_send_context_t *s) { uint64_t error_code, offending_frame_type; const char *reason_phrase; - int64_t ret; + quicly_error_t ret; /* setup send epoch, or return if it's impossible to send in this epoch */ if (setup_send_space(conn, epoch, s) == NULL) @@ -5009,11 +5015,11 @@ static int64_t send_connection_close(quicly_conn_t *conn, size_t epoch, quicly_s return 0; } -static int64_t send_new_connection_id(quicly_conn_t *conn, quicly_send_context_t *s, struct st_quicly_local_cid_t *new_cid) +static quicly_error_t send_new_connection_id(quicly_conn_t *conn, quicly_send_context_t *s, struct st_quicly_local_cid_t *new_cid) { quicly_sent_t *sent; uint64_t retire_prior_to = 0; /* TODO */ - int64_t ret; + quicly_error_t ret; if ((ret = allocate_ack_eliciting_frame( conn, s, quicly_new_connection_id_frame_capacity(new_cid->sequence, retire_prior_to, new_cid->cid.len), &sent, @@ -5038,10 +5044,10 @@ static int64_t send_new_connection_id(quicly_conn_t *conn, quicly_send_context_t return 0; } -static int64_t send_retire_connection_id(quicly_conn_t *conn, quicly_send_context_t *s, uint64_t sequence) +static quicly_error_t send_retire_connection_id(quicly_conn_t *conn, quicly_send_context_t *s, uint64_t sequence) { quicly_sent_t *sent; - int64_t ret; + quicly_error_t ret; if ((ret = allocate_ack_eliciting_frame(conn, s, quicly_retire_connection_id_frame_capacity(sequence), &sent, on_ack_retire_connection_id)) != 0) @@ -5057,9 +5063,9 @@ static int64_t send_retire_connection_id(quicly_conn_t *conn, quicly_send_contex return 0; } -static int64_t send_path_challenge(quicly_conn_t *conn, quicly_send_context_t *s, int is_response, const uint8_t *data) +static quicly_error_t send_path_challenge(quicly_conn_t *conn, quicly_send_context_t *s, int is_response, const uint8_t *data) { - int64_t ret; + quicly_error_t ret; if ((ret = do_allocate_frame(conn, s, QUICLY_PATH_CHALLENGE_FRAME_CAPACITY, ALLOCATE_FRAME_TYPE_NON_ACK_ELICITING)) != 0) return ret; @@ -5170,7 +5176,7 @@ static int update_traffic_key_cb(ptls_update_traffic_key_t *self, ptls_t *tls, i conn->egress.pending_flows |= QUICLY_PENDING_FLOW_OTHERS_BIT; /* send the first resumption token using the 0.5 RTT window */ if (!quicly_is_client(conn) && conn->super.ctx->generate_resumption_token != NULL) { - int64_t ret64 = quicly_send_resumption_token(conn); + quicly_error_t ret64 = quicly_send_resumption_token(conn); assert(ret64 == 0); } @@ -5183,9 +5189,9 @@ static int update_traffic_key_cb(ptls_update_traffic_key_t *self, ptls_t *tls, i return 0; } -static int64_t send_other_control_frames(quicly_conn_t *conn, quicly_send_context_t *s) +static quicly_error_t send_other_control_frames(quicly_conn_t *conn, quicly_send_context_t *s) { - int64_t ret; + quicly_error_t ret; /* MAX_STREAMS */ if ((ret = send_max_streams(conn, 1, s)) != 0) @@ -5246,11 +5252,11 @@ static int64_t send_other_control_frames(quicly_conn_t *conn, quicly_send_contex return 0; } -static int64_t do_send(quicly_conn_t *conn, quicly_send_context_t *s) +static quicly_error_t do_send(quicly_conn_t *conn, quicly_send_context_t *s) { int restrict_sending = 0, ack_only = 0; size_t min_packets_to_send = 0, orig_bytes_inflight = 0; - int64_t ret = 0; + quicly_error_t ret = 0; /* handle timeouts */ if (conn->idle_timeout.at <= conn->stash.now) { @@ -5539,15 +5545,15 @@ int quicly_set_cc(quicly_conn_t *conn, quicly_cc_type_t *cc) return cc->cc_switch(&conn->egress.cc); } -int64_t quicly_send(quicly_conn_t *conn, quicly_address_t *dest, quicly_address_t *src, struct iovec *datagrams, - size_t *num_datagrams, void *buf, size_t bufsize) +quicly_error_t quicly_send(quicly_conn_t *conn, quicly_address_t *dest, quicly_address_t *src, struct iovec *datagrams, + size_t *num_datagrams, void *buf, size_t bufsize) { quicly_send_context_t s = {.current = {.first_byte = -1}, .datagrams = datagrams, .max_datagrams = *num_datagrams, .payload_buf = {.datagram = buf, .end = (uint8_t *)buf + bufsize}, .first_packet_number = conn->egress.packet_number}; - int64_t ret; + quicly_error_t ret; lock_now(conn, 0); @@ -5729,7 +5735,7 @@ size_t quicly_send_stateless_reset(quicly_context_t *ctx, const void *src_cid, v return QUICLY_STATELESS_RESET_PACKET_MIN_LEN; } -int64_t quicly_send_resumption_token(quicly_conn_t *conn) +quicly_error_t quicly_send_resumption_token(quicly_conn_t *conn) { assert(!quicly_is_client(conn)); @@ -5740,16 +5746,16 @@ int64_t quicly_send_resumption_token(quicly_conn_t *conn) return 0; } -static int64_t on_end_closing(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, quicly_sent_t *sent) +static quicly_error_t on_end_closing(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, quicly_sent_t *sent) { /* we stop accepting frames by the time this ack callback is being registered */ assert(!acked); return 0; } -static int64_t enter_close(quicly_conn_t *conn, int local_is_initiating, int wait_draining) +static quicly_error_t enter_close(quicly_conn_t *conn, int local_is_initiating, int wait_draining) { - int64_t ret; + quicly_error_t ret; assert(conn->super.state < QUICLY_STATE_CLOSING); @@ -5777,7 +5783,7 @@ static int64_t enter_close(quicly_conn_t *conn, int local_is_initiating, int wai return 0; } -int64_t initiate_close(quicly_conn_t *conn, int64_t err, uint64_t frame_type, const char *reason_phrase) +quicly_error_t initiate_close(quicly_conn_t *conn, quicly_error_t err, uint64_t frame_type, const char *reason_phrase) { uint16_t quic_error_code; @@ -5808,9 +5814,9 @@ int64_t initiate_close(quicly_conn_t *conn, int64_t err, uint64_t frame_type, co return enter_close(conn, 1, 0); } -int64_t quicly_close(quicly_conn_t *conn, int64_t err, const char *reason_phrase) +quicly_error_t quicly_close(quicly_conn_t *conn, quicly_error_t err, const char *reason_phrase) { - int64_t ret; + quicly_error_t ret; assert(err == 0 || QUICLY_ERROR_IS_QUIC_APPLICATION(err) || QUICLY_ERROR_IS_CONCEALED(err)); @@ -5821,9 +5827,9 @@ int64_t quicly_close(quicly_conn_t *conn, int64_t err, const char *reason_phrase return ret; } -int64_t quicly_get_or_open_stream(quicly_conn_t *conn, uint64_t stream_id, quicly_stream_t **stream) +quicly_error_t quicly_get_or_open_stream(quicly_conn_t *conn, uint64_t stream_id, quicly_stream_t **stream) { - int64_t ret = 0; + quicly_error_t ret = 0; if ((*stream = quicly_get_stream(conn, stream_id)) != NULL) goto Exit; @@ -5867,11 +5873,11 @@ int64_t quicly_get_or_open_stream(quicly_conn_t *conn, uint64_t stream_id, quicl return ret; } -static int64_t handle_crypto_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) +static quicly_error_t handle_crypto_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) { quicly_stream_frame_t frame; quicly_stream_t *stream; - int64_t ret; + quicly_error_t ret; if ((ret = quicly_decode_crypto_frame(&state->src, state->end, &frame)) != 0) return ret; @@ -5880,11 +5886,11 @@ static int64_t handle_crypto_frame(quicly_conn_t *conn, struct st_quicly_handle_ return apply_stream_frame(stream, &frame); } -static int64_t handle_stream_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) +static quicly_error_t handle_stream_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) { quicly_stream_frame_t frame; quicly_stream_t *stream; - int64_t ret; + quicly_error_t ret; if ((ret = quicly_decode_stream_frame(state->frame_type, &state->src, state->end, &frame)) != 0) return ret; @@ -5894,11 +5900,11 @@ static int64_t handle_stream_frame(quicly_conn_t *conn, struct st_quicly_handle_ return apply_stream_frame(stream, &frame); } -static int64_t handle_reset_stream_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) +static quicly_error_t handle_reset_stream_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) { quicly_reset_stream_frame_t frame; quicly_stream_t *stream; - int64_t ret; + quicly_error_t ret; if ((ret = quicly_decode_reset_stream_frame(&state->src, state->end, &frame)) != 0) return ret; @@ -5917,7 +5923,7 @@ static int64_t handle_reset_stream_frame(quicly_conn_t *conn, struct st_quicly_h if ((ret = quicly_recvstate_reset(&stream->recvstate, frame.final_size, &bytes_missing)) != 0) return ret; stream->conn->ingress.max_data.bytes_consumed += bytes_missing; - int64_t err = QUICLY_ERROR_FROM_APPLICATION_ERROR_CODE(frame.app_error_code); + quicly_error_t err = QUICLY_ERROR_FROM_APPLICATION_ERROR_CODE(frame.app_error_code); QUICLY_PROBE(STREAM_ON_RECEIVE_RESET, stream->conn, stream->conn->stash.now, stream, err); QUICLY_LOG_CONN(stream_on_receive_reset, stream->conn, { PTLS_LOG_ELEMENT_SIGNED(stream_id, stream->stream_id); @@ -5933,7 +5939,7 @@ static int64_t handle_reset_stream_frame(quicly_conn_t *conn, struct st_quicly_h return 0; } -static int64_t handle_ack_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) +static quicly_error_t handle_ack_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) { quicly_ack_frame_t frame; quicly_sentmap_iter_t iter; @@ -5943,7 +5949,7 @@ static int64_t handle_ack_frame(quicly_conn_t *conn, struct st_quicly_handle_pay } largest_newly_acked = {UINT64_MAX, INT64_MAX}; size_t bytes_acked = 0; int includes_ack_eliciting = 0, includes_late_ack = 0; - int64_t ret; + quicly_error_t ret; /* The flow is considered CC-limited if the packet was sent while `inflight >= 1/2 * CNWD` or acked under the same condition. * 1/2 of CWND is adopted for fairness with RFC 7661, and also provides correct increase; i.e., if an idle flow goes into @@ -6127,11 +6133,11 @@ static int64_t handle_ack_frame(quicly_conn_t *conn, struct st_quicly_handle_pay return 0; } -static int64_t handle_max_stream_data_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) +static quicly_error_t handle_max_stream_data_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) { quicly_max_stream_data_frame_t frame; quicly_stream_t *stream; - int64_t ret; + quicly_error_t ret; if ((ret = quicly_decode_max_stream_data_frame(&state->src, state->end, &frame)) != 0) return ret; @@ -6159,10 +6165,10 @@ static int64_t handle_max_stream_data_frame(quicly_conn_t *conn, struct st_quicl return 0; } -static int64_t handle_data_blocked_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) +static quicly_error_t handle_data_blocked_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) { quicly_data_blocked_frame_t frame; - int64_t ret; + quicly_error_t ret; if ((ret = quicly_decode_data_blocked_frame(&state->src, state->end, &frame)) != 0) return ret; @@ -6177,11 +6183,11 @@ static int64_t handle_data_blocked_frame(quicly_conn_t *conn, struct st_quicly_h return 0; } -static int64_t handle_stream_data_blocked_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) +static quicly_error_t handle_stream_data_blocked_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) { quicly_stream_data_blocked_frame_t frame; quicly_stream_t *stream; - int64_t ret; + quicly_error_t ret; if ((ret = quicly_decode_stream_data_blocked_frame(&state->src, state->end, &frame)) != 0) return ret; @@ -6204,11 +6210,11 @@ static int64_t handle_stream_data_blocked_frame(quicly_conn_t *conn, struct st_q return 0; } -static int64_t handle_streams_blocked_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) +static quicly_error_t handle_streams_blocked_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) { quicly_streams_blocked_frame_t frame; int uni = state->frame_type == QUICLY_FRAME_TYPE_STREAMS_BLOCKED_UNI; - int64_t ret; + quicly_error_t ret; if ((ret = quicly_decode_streams_blocked_frame(&state->src, state->end, &frame)) != 0) return ret; @@ -6228,10 +6234,10 @@ static int64_t handle_streams_blocked_frame(quicly_conn_t *conn, struct st_quicl return 0; } -static int64_t handle_max_streams_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state, int uni) +static quicly_error_t handle_max_streams_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state, int uni) { quicly_max_streams_frame_t frame; - int64_t ret; + quicly_error_t ret; if ((ret = quicly_decode_max_streams_frame(&state->src, state->end, &frame)) != 0) return ret; @@ -6250,20 +6256,20 @@ static int64_t handle_max_streams_frame(quicly_conn_t *conn, struct st_quicly_ha return 0; } -static int64_t handle_max_streams_bidi_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) +static quicly_error_t handle_max_streams_bidi_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) { return handle_max_streams_frame(conn, state, 0); } -static int64_t handle_max_streams_uni_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) +static quicly_error_t handle_max_streams_uni_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) { return handle_max_streams_frame(conn, state, 1); } -static int64_t handle_path_challenge_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) +static quicly_error_t handle_path_challenge_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) { quicly_path_challenge_frame_t frame; - int64_t ret; + quicly_error_t ret; if ((ret = quicly_decode_path_challenge_frame(&state->src, state->end, &frame)) != 0) return ret; @@ -6280,10 +6286,10 @@ static int64_t handle_path_challenge_frame(quicly_conn_t *conn, struct st_quicly return 0; } -static int64_t handle_path_response_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) +static quicly_error_t handle_path_response_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) { quicly_path_challenge_frame_t frame; - int64_t ret; + quicly_error_t ret; if ((ret = quicly_decode_path_challenge_frame(&state->src, state->end, &frame)) != 0) return ret; @@ -6303,10 +6309,10 @@ static int64_t handle_path_response_frame(quicly_conn_t *conn, struct st_quicly_ return 0; } -static int64_t handle_new_token_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) +static quicly_error_t handle_new_token_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) { quicly_new_token_frame_t frame; - int64_t ret; + quicly_error_t ret; if (!quicly_is_client(conn)) return QUICLY_TRANSPORT_ERROR_PROTOCOL_VIOLATION; @@ -6319,11 +6325,11 @@ static int64_t handle_new_token_frame(quicly_conn_t *conn, struct st_quicly_hand return conn->super.ctx->save_resumption_token->cb(conn->super.ctx->save_resumption_token, conn, frame.token); } -static int64_t handle_stop_sending_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) +static quicly_error_t handle_stop_sending_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) { quicly_stop_sending_frame_t frame; quicly_stream_t *stream; - int64_t ret; + quicly_error_t ret; if ((ret = quicly_decode_stop_sending_frame(&state->src, state->end, &frame)) != 0) return ret; @@ -6338,7 +6344,7 @@ static int64_t handle_stop_sending_frame(quicly_conn_t *conn, struct st_quicly_h if (quicly_sendstate_is_open(&stream->sendstate)) { /* reset the stream, then notify the application */ - int64_t err = QUICLY_ERROR_FROM_APPLICATION_ERROR_CODE(frame.app_error_code); + quicly_error_t err = QUICLY_ERROR_FROM_APPLICATION_ERROR_CODE(frame.app_error_code); quicly_reset_stream(stream, err); QUICLY_PROBE(STREAM_ON_SEND_STOP, stream->conn, stream->conn->stash.now, stream, err); QUICLY_LOG_CONN(stream_on_send_stop, stream->conn, { @@ -6353,10 +6359,10 @@ static int64_t handle_stop_sending_frame(quicly_conn_t *conn, struct st_quicly_h return 0; } -static int64_t handle_max_data_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) +static quicly_error_t handle_max_data_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) { quicly_max_data_frame_t frame; - int64_t ret; + quicly_error_t ret; if ((ret = quicly_decode_max_data_frame(&state->src, state->end, &frame)) != 0) return ret; @@ -6372,9 +6378,9 @@ static int64_t handle_max_data_frame(quicly_conn_t *conn, struct st_quicly_handl return 0; } -static int64_t negotiate_using_version(quicly_conn_t *conn, uint32_t version) +static quicly_error_t negotiate_using_version(quicly_conn_t *conn, uint32_t version) { - int64_t ret; + quicly_error_t ret; /* set selected version, update transport parameters extension ID */ conn->super.version = version; @@ -6392,7 +6398,7 @@ static int64_t negotiate_using_version(quicly_conn_t *conn, uint32_t version) return 0; } -static int64_t handle_version_negotiation_packet(quicly_conn_t *conn, quicly_decoded_packet_t *packet) +static quicly_error_t handle_version_negotiation_packet(quicly_conn_t *conn, quicly_decoded_packet_t *packet) { const uint8_t *src = packet->octets.base + packet->encrypted_off, *end = packet->octets.base + packet->octets.len; uint32_t selected_version = 0; @@ -6527,9 +6533,9 @@ int quicly_is_destination(quicly_conn_t *conn, struct sockaddr *dest_addr, struc return 1; } -int64_t handle_close(quicly_conn_t *conn, int64_t err, uint64_t frame_type, ptls_iovec_t reason_phrase) +quicly_error_t handle_close(quicly_conn_t *conn, quicly_error_t err, uint64_t frame_type, ptls_iovec_t reason_phrase) { - int64_t ret; + quicly_error_t ret; if (conn->super.state >= QUICLY_STATE_CLOSING) return 0; @@ -6546,10 +6552,10 @@ int64_t handle_close(quicly_conn_t *conn, int64_t err, uint64_t frame_type, ptls return 0; } -static int64_t handle_transport_close_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) +static quicly_error_t handle_transport_close_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) { quicly_transport_close_frame_t frame; - int64_t ret; + quicly_error_t ret; if ((ret = quicly_decode_transport_close_frame(&state->src, state->end, &frame)) != 0) return ret; @@ -6564,10 +6570,10 @@ static int64_t handle_transport_close_frame(quicly_conn_t *conn, struct st_quicl return handle_close(conn, QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(frame.error_code), frame.frame_type, frame.reason_phrase); } -static int64_t handle_application_close_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) +static quicly_error_t handle_application_close_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) { quicly_application_close_frame_t frame; - int64_t ret; + quicly_error_t ret; if ((ret = quicly_decode_application_close_frame(&state->src, state->end, &frame)) != 0) return ret; @@ -6581,12 +6587,12 @@ static int64_t handle_application_close_frame(quicly_conn_t *conn, struct st_qui return handle_close(conn, QUICLY_ERROR_FROM_APPLICATION_ERROR_CODE(frame.error_code), UINT64_MAX, frame.reason_phrase); } -static int64_t handle_padding_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) +static quicly_error_t handle_padding_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) { return 0; } -static int64_t handle_ping_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) +static quicly_error_t handle_ping_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) { QUICLY_PROBE(PING_RECEIVE, conn, conn->stash.now); QUICLY_LOG_CONN(ping_receive, conn, {}); @@ -6594,10 +6600,10 @@ static int64_t handle_ping_frame(quicly_conn_t *conn, struct st_quicly_handle_pa return 0; } -static int64_t handle_new_connection_id_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) +static quicly_error_t handle_new_connection_id_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) { quicly_new_connection_id_frame_t frame; - int64_t ret; + quicly_error_t ret; /* TODO: return error when using zero-length CID */ @@ -6627,11 +6633,11 @@ static int64_t handle_new_connection_id_frame(quicly_conn_t *conn, struct st_qui return 0; } -static int64_t handle_retire_connection_id_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) +static quicly_error_t handle_retire_connection_id_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) { int has_pending; quicly_retire_connection_id_frame_t frame; - int64_t ret; + quicly_error_t ret; if ((ret = quicly_decode_retire_connection_id_frame(&state->src, state->end, &frame)) != 0) return ret; @@ -6653,9 +6659,9 @@ static int64_t handle_retire_connection_id_frame(quicly_conn_t *conn, struct st_ return 0; } -static int64_t handle_handshake_done_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) +static quicly_error_t handle_handshake_done_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) { - int64_t ret; + quicly_error_t ret; QUICLY_PROBE(HANDSHAKE_DONE_RECEIVE, conn, conn->stash.now); QUICLY_LOG_CONN(handshake_done_receive, conn, {}); @@ -6674,10 +6680,10 @@ static int64_t handle_handshake_done_frame(quicly_conn_t *conn, struct st_quicly return 0; } -static int64_t handle_datagram_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) +static quicly_error_t handle_datagram_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) { quicly_datagram_frame_t frame; - int64_t ret; + quicly_error_t ret; /* check if we advertised support for DATAGRAM frames on this connection */ if (conn->super.ctx->transport_params.max_datagram_frame_size == 0) @@ -6695,10 +6701,10 @@ static int64_t handle_datagram_frame(quicly_conn_t *conn, struct st_quicly_handl return 0; } -static int64_t handle_ack_frequency_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) +static quicly_error_t handle_ack_frequency_frame(quicly_conn_t *conn, struct st_quicly_handle_payload_state_t *state) { quicly_ack_frequency_frame_t frame; - int64_t ret; + quicly_error_t ret; /* recognize the frame only when the support has been advertised */ if (conn->super.ctx->transport_params.min_ack_delay_usec == UINT64_MAX) @@ -6731,14 +6737,15 @@ static int64_t handle_ack_frequency_frame(quicly_conn_t *conn, struct st_quicly_ return 0; } -static int64_t handle_payload(quicly_conn_t *conn, size_t epoch, size_t path_index, const uint8_t *_src, size_t _len, - uint64_t *offending_frame_type, int *is_ack_only, int *is_probe_only) +static quicly_error_t handle_payload(quicly_conn_t *conn, size_t epoch, size_t path_index, const uint8_t *_src, size_t _len, + uint64_t *offending_frame_type, int *is_ack_only, int *is_probe_only) { /* clang-format off */ /* `frame_handlers` is an array of frame handlers and the properties of the frames, indexed by the ID of the frame. */ static const struct st_quicly_frame_handler_t { - int64_t (*cb)(quicly_conn_t *, struct st_quicly_handle_payload_state_t *); /* callback function that handles the frame */ + quicly_error_t (*cb)(quicly_conn_t *, struct st_quicly_handle_payload_state_t *); /* callback function that handles the + * frame */ uint8_t permitted_epochs; /* the epochs the frame can appear, calculated as bitwise-or of `1 << epoch` */ uint8_t ack_eliciting; /* boolean indicating if the frame is ack-eliciting */ uint8_t probing; /* boolean indicating if the frame is a "probing frame" */ @@ -6822,7 +6829,7 @@ static int64_t handle_payload(quicly_conn_t *conn, size_t epoch, size_t path_ind struct st_quicly_handle_payload_state_t state = {.epoch = epoch, .path_index = path_index, .src = _src, .end = _src + _len}; size_t num_frames_ack_eliciting = 0, num_frames_non_probing = 0; - int64_t ret; + quicly_error_t ret; do { /* determine the frame type; fast path is available for frame types below 64 */ @@ -6869,7 +6876,7 @@ static int64_t handle_payload(quicly_conn_t *conn, size_t epoch, size_t path_ind return ret; } -static int64_t handle_stateless_reset(quicly_conn_t *conn) +static quicly_error_t handle_stateless_reset(quicly_conn_t *conn) { QUICLY_PROBE(STATELESS_RESET_RECEIVE, conn, conn->stash.now); QUICLY_LOG_CONN(stateless_reset_receive, conn, {}); @@ -6887,9 +6894,10 @@ static int validate_retry_tag(quicly_decoded_packet_t *packet, quicly_cid_t *odc PTLS_AESGCM_TAG_SIZE, 0, pseudo_packet, pseudo_packet_len) == 0; } -int64_t quicly_accept(quicly_conn_t **conn, quicly_context_t *ctx, struct sockaddr *dest_addr, struct sockaddr *src_addr, - quicly_decoded_packet_t *packet, quicly_address_token_plaintext_t *address_token, - const quicly_cid_plaintext_t *new_cid, ptls_handshake_properties_t *handshake_properties, void *appdata) +quicly_error_t quicly_accept(quicly_conn_t **conn, quicly_context_t *ctx, struct sockaddr *dest_addr, struct sockaddr *src_addr, + quicly_decoded_packet_t *packet, quicly_address_token_plaintext_t *address_token, + const quicly_cid_plaintext_t *new_cid, ptls_handshake_properties_t *handshake_properties, + void *appdata) { const quicly_salt_t *salt; struct { @@ -6899,7 +6907,7 @@ int64_t quicly_accept(quicly_conn_t **conn, quicly_context_t *ctx, struct sockad ptls_iovec_t payload; uint64_t next_expected_pn, pn, offending_frame_type = QUICLY_FRAME_TYPE_PADDING; int is_ack_only, is_probe_only; - int64_t ret; + quicly_error_t ret; *conn = NULL; @@ -7016,7 +7024,8 @@ int64_t quicly_accept(quicly_conn_t **conn, quicly_context_t *ctx, struct sockad return ret; } -int64_t quicly_receive(quicly_conn_t *conn, struct sockaddr *dest_addr, struct sockaddr *src_addr, quicly_decoded_packet_t *packet) +quicly_error_t quicly_receive(quicly_conn_t *conn, struct sockaddr *dest_addr, struct sockaddr *src_addr, + quicly_decoded_packet_t *packet) { ptls_cipher_context_t *header_protection; struct { @@ -7028,7 +7037,7 @@ int64_t quicly_receive(quicly_conn_t *conn, struct sockaddr *dest_addr, struct s ptls_iovec_t payload; uint64_t pn, offending_frame_type = QUICLY_FRAME_TYPE_PADDING; int is_ack_only, is_probe_only; - int64_t ret; + quicly_error_t ret; assert(src_addr->sa_family == AF_INET || src_addr->sa_family == AF_INET6); @@ -7367,14 +7376,14 @@ int64_t quicly_receive(quicly_conn_t *conn, struct sockaddr *dest_addr, struct s return ret; } -int64_t quicly_open_stream(quicly_conn_t *conn, quicly_stream_t **_stream, int uni) +quicly_error_t quicly_open_stream(quicly_conn_t *conn, quicly_stream_t **_stream, int uni) { quicly_stream_t *stream; struct st_quicly_conn_streamgroup_state_t *group; uint64_t *max_stream_count; uint32_t max_stream_data_local; uint64_t max_stream_data_remote; - int64_t ret; + quicly_error_t ret; /* determine the states */ if (uni) { @@ -7417,7 +7426,7 @@ int64_t quicly_open_stream(quicly_conn_t *conn, quicly_stream_t **_stream, int u return 0; } -void quicly_reset_stream(quicly_stream_t *stream, int64_t err) +void quicly_reset_stream(quicly_stream_t *stream, quicly_error_t err) { assert(quicly_stream_has_send_side(quicly_is_client(stream->conn), stream->stream_id)); assert(QUICLY_ERROR_IS_QUIC_APPLICATION(err)); @@ -7436,7 +7445,7 @@ void quicly_reset_stream(quicly_stream_t *stream, int64_t err) resched_stream_data(stream); } -void quicly_request_stop(quicly_stream_t *stream, int64_t err) +void quicly_request_stop(quicly_stream_t *stream, quicly_error_t err) { assert(quicly_stream_has_receive_side(quicly_is_client(stream->conn), stream->stream_id)); assert(QUICLY_ERROR_IS_QUIC_APPLICATION(err)); @@ -7546,10 +7555,10 @@ void quicly_amend_ptls_context(ptls_context_t *ptls) ptls->max_early_data_size = UINT32_MAX; } -int64_t quicly_encrypt_address_token(void (*random_bytes)(void *, size_t), ptls_aead_context_t *aead, ptls_buffer_t *buf, - size_t start_off, const quicly_address_token_plaintext_t *plaintext) +quicly_error_t quicly_encrypt_address_token(void (*random_bytes)(void *, size_t), ptls_aead_context_t *aead, ptls_buffer_t *buf, + size_t start_off, const quicly_address_token_plaintext_t *plaintext) { - int64_t ret; + quicly_error_t ret; /* type and IV */ if ((ret = ptls_buffer_reserve(buf, 1 + aead->algo->iv_size)) != 0) @@ -7612,8 +7621,8 @@ int64_t quicly_encrypt_address_token(void (*random_bytes)(void *, size_t), ptls_ return ret; } -int64_t quicly_decrypt_address_token(ptls_aead_context_t *aead, quicly_address_token_plaintext_t *plaintext, const void *_token, - size_t len, size_t prefix_len, const char **err_desc) +quicly_error_t quicly_decrypt_address_token(ptls_aead_context_t *aead, quicly_address_token_plaintext_t *plaintext, + const void *_token, size_t len, size_t prefix_len, const char **err_desc) { const uint8_t *const token = _token; uint8_t ptbuf[QUICLY_MIN_CLIENT_INITIAL_SIZE]; @@ -7645,7 +7654,7 @@ int64_t quicly_decrypt_address_token(ptls_aead_context_t *aead, quicly_address_t } /* `goto Exit` can only happen below this line, and that is guaranteed by declaring `ret` here */ - int64_t ret; + quicly_error_t ret; /* decrypt */ ptls_aead_set_iv(aead, token + prefix_len + 1); @@ -7771,7 +7780,7 @@ int quicly_build_session_ticket_auth_data(ptls_buffer_t *auth_data, const quicly return ret; } -void quicly_stream_noop_on_destroy(quicly_stream_t *stream, int64_t err) +void quicly_stream_noop_on_destroy(quicly_stream_t *stream, quicly_error_t err) { } @@ -7783,7 +7792,7 @@ void quicly_stream_noop_on_send_emit(quicly_stream_t *stream, size_t off, void * { } -void quicly_stream_noop_on_send_stop(quicly_stream_t *stream, int64_t err) +void quicly_stream_noop_on_send_stop(quicly_stream_t *stream, quicly_error_t err) { } @@ -7791,7 +7800,7 @@ void quicly_stream_noop_on_receive(quicly_stream_t *stream, size_t off, const vo { } -void quicly_stream_noop_on_receive_reset(quicly_stream_t *stream, int64_t err) +void quicly_stream_noop_on_receive_reset(quicly_stream_t *stream, quicly_error_t err) { } diff --git a/lib/recvstate.c b/lib/recvstate.c index 826e1f17..2d8a69e7 100644 --- a/lib/recvstate.c +++ b/lib/recvstate.c @@ -41,7 +41,7 @@ void quicly_recvstate_dispose(quicly_recvstate_t *state) quicly_ranges_clear(&state->received); } -int64_t quicly_recvstate_update(quicly_recvstate_t *state, uint64_t off, size_t *len, int is_fin, size_t max_ranges) +quicly_error_t quicly_recvstate_update(quicly_recvstate_t *state, uint64_t off, size_t *len, int is_fin, size_t max_ranges) { assert(!quicly_recvstate_transfer_complete(state)); @@ -90,7 +90,7 @@ int64_t quicly_recvstate_update(quicly_recvstate_t *state, uint64_t off, size_t return 0; } -int64_t quicly_recvstate_reset(quicly_recvstate_t *state, uint64_t eos_at, uint64_t *bytes_missing) +quicly_error_t quicly_recvstate_reset(quicly_recvstate_t *state, uint64_t eos_at, uint64_t *bytes_missing) { assert(!quicly_recvstate_transfer_complete(state)); diff --git a/lib/remote_cid.c b/lib/remote_cid.c index 1b868f6a..e8b9ea8d 100644 --- a/lib/remote_cid.c +++ b/lib/remote_cid.c @@ -46,8 +46,8 @@ void quicly_remote_cid_init_set(quicly_remote_cid_set_t *set, ptls_iovec_t *init set->_largest_sequence_expected = PTLS_ELEMENTSOF(set->cids) - 1; } -static int64_t do_register(quicly_remote_cid_set_t *set, uint64_t sequence, const uint8_t *cid, size_t cid_len, - const uint8_t srt[QUICLY_STATELESS_RESET_TOKEN_LEN]) +static quicly_error_t do_register(quicly_remote_cid_set_t *set, uint64_t sequence, const uint8_t *cid, size_t cid_len, + const uint8_t srt[QUICLY_STATELESS_RESET_TOKEN_LEN]) { int was_stored = 0; @@ -123,13 +123,13 @@ static size_t unregister_prior_to(quicly_remote_cid_set_t *set, uint64_t seq_unr return num_unregistered; } -int64_t quicly_remote_cid_register(quicly_remote_cid_set_t *set, uint64_t sequence, const uint8_t *cid, size_t cid_len, - const uint8_t srt[QUICLY_STATELESS_RESET_TOKEN_LEN], uint64_t retire_prior_to, - uint64_t unregistered_seqs[QUICLY_LOCAL_ACTIVE_CONNECTION_ID_LIMIT], - size_t *num_unregistered_seqs) +quicly_error_t quicly_remote_cid_register(quicly_remote_cid_set_t *set, uint64_t sequence, const uint8_t *cid, size_t cid_len, + const uint8_t srt[QUICLY_STATELESS_RESET_TOKEN_LEN], uint64_t retire_prior_to, + uint64_t unregistered_seqs[QUICLY_LOCAL_ACTIVE_CONNECTION_ID_LIMIT], + size_t *num_unregistered_seqs) { quicly_remote_cid_set_t backup = *set; /* preserve current state so that it can be restored to notify protocol violation */ - int64_t ret; + quicly_error_t ret; assert(sequence >= retire_prior_to); diff --git a/lib/sentmap.c b/lib/sentmap.c index 65c4c983..71220f0d 100644 --- a/lib/sentmap.c +++ b/lib/sentmap.c @@ -92,7 +92,7 @@ void quicly_sentmap_dispose(quicly_sentmap_t *map) } } -int64_t quicly_sentmap_prepare(quicly_sentmap_t *map, uint64_t packet_number, int64_t now, uint8_t ack_epoch) +quicly_error_t quicly_sentmap_prepare(quicly_sentmap_t *map, uint64_t packet_number, int64_t now, uint8_t ack_epoch) { assert(map->_pending_packet == NULL); @@ -129,10 +129,10 @@ void quicly_sentmap_skip(quicly_sentmap_iter_t *iter) } while (iter->p->acked != quicly_sentmap__type_packet); } -int64_t quicly_sentmap_update(quicly_sentmap_t *map, quicly_sentmap_iter_t *iter, quicly_sentmap_event_t event) +quicly_error_t quicly_sentmap_update(quicly_sentmap_t *map, quicly_sentmap_iter_t *iter, quicly_sentmap_event_t event) { quicly_sent_packet_t packet; - int64_t ret = 0; + quicly_error_t ret = 0; assert(iter->p != &quicly_sentmap__end_iter); assert(iter->p->acked == quicly_sentmap__type_packet); @@ -169,7 +169,8 @@ int64_t quicly_sentmap_update(quicly_sentmap_t *map, quicly_sentmap_iter_t *iter return ret; } -int64_t quicly_sentmap__type_packet(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, quicly_sent_t *sent) +quicly_error_t quicly_sentmap__type_packet(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, + quicly_sent_t *sent) { assert(!"quicly_sentmap__type_packet cannot be called"); return QUICLY_TRANSPORT_ERROR_INTERNAL; diff --git a/lib/streambuf.c b/lib/streambuf.c index 977faf94..1e110eb8 100644 --- a/lib/streambuf.c +++ b/lib/streambuf.c @@ -24,7 +24,7 @@ #include #include "quicly/streambuf.h" -static void convert_error(quicly_stream_t *stream, int64_t err) +static void convert_error(quicly_stream_t *stream, quicly_error_t err) { assert(err != 0); if (QUICLY_ERROR_IS_QUIC_APPLICATION(err)) { @@ -84,7 +84,7 @@ void quicly_sendbuf_shift(quicly_stream_t *stream, quicly_sendbuf_t *sb, size_t void quicly_sendbuf_emit(quicly_stream_t *stream, quicly_sendbuf_t *sb, size_t off, void *dst, size_t *len, int *wrote_all) { size_t vec_index, capacity = *len; - int64_t ret; + quicly_error_t ret; off += sb->off_in_first_vec; for (vec_index = 0; capacity != 0 && vec_index < sb->vecs.size; ++vec_index) { @@ -118,7 +118,7 @@ void quicly_sendbuf_emit(quicly_stream_t *stream, quicly_sendbuf_t *sb, size_t o } } -static int64_t flatten_raw(quicly_sendbuf_vec_t *vec, void *dst, size_t off, size_t len) +static quicly_error_t flatten_raw(quicly_sendbuf_vec_t *vec, void *dst, size_t off, size_t len) { memcpy(dst, (uint8_t *)vec->cbdata + off, len); return 0; @@ -226,7 +226,7 @@ int quicly_streambuf_create(quicly_stream_t *stream, size_t sz) return 0; } -void quicly_streambuf_destroy(quicly_stream_t *stream, int64_t err) +void quicly_streambuf_destroy(quicly_stream_t *stream, quicly_error_t err) { quicly_streambuf_t *sbuf = stream->data; diff --git a/src/cli.c b/src/cli.c index 4817ed9a..22d3d5f9 100644 --- a/src/cli.c +++ b/src/cli.c @@ -124,8 +124,8 @@ struct st_stream_data_t { FILE *outfp; }; -static void on_stop_sending(quicly_stream_t *stream, int64_t err); -static void on_receive_reset(quicly_stream_t *stream, int64_t err); +static void on_stop_sending(quicly_stream_t *stream, quicly_error_t err); +static void on_receive_reset(quicly_stream_t *stream, quicly_error_t err); static void server_on_receive(quicly_stream_t *stream, size_t off, const void *src, size_t len); static void client_on_receive(quicly_stream_t *stream, size_t off, const void *src, size_t len); @@ -222,7 +222,7 @@ static void send_header(quicly_stream_t *stream, int is_http1, int status, const send_str(stream, buf); } -static int64_t flatten_file_vec(quicly_sendbuf_vec_t *vec, void *dst, size_t off, size_t len) +static quicly_error_t flatten_file_vec(quicly_sendbuf_vec_t *vec, void *dst, size_t off, size_t len) { int fd = (intptr_t)vec->cbdata; ssize_t rret; @@ -263,7 +263,7 @@ static int send_file(quicly_stream_t *stream, int is_http1, const char *fn, cons * This function is an implementation of the quicly_sendbuf_flatten_vec_cb callback. Refer to the doc-comments of the callback type * for the API. */ -static int64_t flatten_sized_text(quicly_sendbuf_vec_t *vec, void *dst, size_t off, size_t len) +static quicly_error_t flatten_sized_text(quicly_sendbuf_vec_t *vec, void *dst, size_t off, size_t len) { static const char pattern[] = "hello world\nhello world\nhello world\nhello world\nhello world\nhello world\nhello world\nhello world\nhello " @@ -316,13 +316,13 @@ static int send_sized_text(quicly_stream_t *stream, const char *path, int is_htt return 1; } -static void on_stop_sending(quicly_stream_t *stream, int64_t err) +static void on_stop_sending(quicly_stream_t *stream, quicly_error_t err) { assert(QUICLY_ERROR_IS_QUIC_APPLICATION(err)); fprintf(stderr, "received STOP_SENDING: %" PRIu64 "\n", QUICLY_ERROR_GET_ERROR_CODE(err)); } -static void on_receive_reset(quicly_stream_t *stream, int64_t err) +static void on_receive_reset(quicly_stream_t *stream, quicly_error_t err) { assert(QUICLY_ERROR_IS_QUIC_APPLICATION(err)); fprintf(stderr, "received RESET_STREAM: %" PRIu64 "\n", QUICLY_ERROR_GET_ERROR_CODE(err)); @@ -401,7 +401,7 @@ static int64_t on_stream_open(quicly_stream_open_t *self, quicly_stream_t *strea static quicly_stream_open_t stream_open = {&on_stream_open}; -static void on_closed_by_remote(quicly_closed_by_remote_t *self, quicly_conn_t *conn, int64_t err, uint64_t frame_type, +static void on_closed_by_remote(quicly_closed_by_remote_t *self, quicly_conn_t *conn, quicly_error_t err, uint64_t frame_type, const char *reason, size_t reason_len) { if (QUICLY_ERROR_IS_QUIC_TRANSPORT(err)) { @@ -421,8 +421,8 @@ static void on_closed_by_remote(quicly_closed_by_remote_t *self, quicly_conn_t * static quicly_closed_by_remote_t closed_by_remote = {&on_closed_by_remote}; -static int64_t on_generate_resumption_token(quicly_generate_resumption_token_t *self, quicly_conn_t *conn, ptls_buffer_t *buf, - quicly_address_token_plaintext_t *token) +static quicly_error_t on_generate_resumption_token(quicly_generate_resumption_token_t *self, quicly_conn_t *conn, + ptls_buffer_t *buf, quicly_address_token_plaintext_t *token) { return quicly_encrypt_address_token(tlsctx.random_bytes, address_token_aead.enc, buf, buf->off, token); } @@ -632,13 +632,13 @@ static void send_one_packet(int fd, quicly_address_t *dest, quicly_address_t *sr send_packets(fd, dest, src, &vec, 1, 0); } -static int64_t send_pending(int fd, quicly_conn_t *conn) +static quicly_error_t send_pending(int fd, quicly_conn_t *conn) { quicly_address_t dest, src; struct iovec packets[MAX_BURST_PACKETS]; uint8_t buf[MAX_BURST_PACKETS * quicly_get_context(conn)->transport_params.max_udp_payload_size]; size_t num_packets = MAX_BURST_PACKETS; - int64_t ret; + quicly_error_t ret; if ((ret = quicly_send(conn, &dest, &src, packets, &num_packets, buf, sizeof(buf))) == 0 && num_packets != 0) send_packets(fd, &dest, &src, packets, num_packets, quicly_send_get_ecn_bits(conn)); @@ -657,7 +657,7 @@ static void on_receive_datagram_frame(quicly_receive_datagram_frame_t *self, qui static void enqueue_requests(quicly_conn_t *conn) { size_t i; - int64_t ret; + quicly_error_t ret; for (i = 0; reqs[i].path != NULL; ++i) { char req[1024], destfile[1024]; @@ -958,8 +958,8 @@ static int run_server(int fd, struct sockaddr *sa, socklen_t salen) quicly_address_token_plaintext_t *token = NULL, token_buf; if (packet.token.len != 0) { const char *err_desc = NULL; - int64_t ret = quicly_decrypt_address_token(address_token_aead.dec, &token_buf, packet.token.base, - packet.token.len, 0, &err_desc); + quicly_error_t ret = quicly_decrypt_address_token(address_token_aead.dec, &token_buf, packet.token.base, + packet.token.len, 0, &err_desc); if (ret == 0 && validate_token(&remote.sa, packet.cid.src, packet.cid.dest.encrypted, &token_buf, &err_desc)) { token = &token_buf; @@ -990,7 +990,8 @@ static int run_server(int fd, struct sockaddr *sa, socklen_t salen) break; } else { /* new connection */ - int64_t ret = quicly_accept(&conn, &ctx, &local.sa, &remote.sa, &packet, token, &next_cid, NULL, NULL); + quicly_error_t ret = + quicly_accept(&conn, &ctx, &local.sa, &remote.sa, &packet, token, &next_cid, NULL, NULL); if (ret == 0) { assert(conn != NULL); ++next_cid.master_id; @@ -1036,7 +1037,7 @@ static void load_session(void) { static uint8_t buf[65536]; size_t len; - int64_t ret; + quicly_error_t ret; { FILE *fp; @@ -1125,7 +1126,7 @@ int save_session_ticket_cb(ptls_save_ticket_t *_self, ptls_t *tls, ptls_iovec_t return save_session(quicly_get_remote_transport_parameters(conn)); } -static int64_t save_resumption_token_cb(quicly_save_resumption_token_t *_self, quicly_conn_t *conn, ptls_iovec_t token) +static quicly_error_t save_resumption_token_cb(quicly_save_resumption_token_t *_self, quicly_conn_t *conn, ptls_iovec_t token) { free(session_info.address_token.base); session_info.address_token = ptls_iovec_init(malloc(token.len), token.len); @@ -1172,10 +1173,10 @@ static int conn_has_more_to_send(quicly_conn_t *conn) return quicly_foreach_stream(conn, NULL, stream_has_more_to_send) != 0; } -static int64_t scheduler_do_send(quicly_stream_scheduler_t *sched, quicly_conn_t *conn, quicly_send_context_t *s) +static quicly_error_t scheduler_do_send(quicly_stream_scheduler_t *sched, quicly_conn_t *conn, quicly_send_context_t *s) { int had_more_to_send = conn_has_more_to_send(conn); - int64_t ret; + quicly_error_t ret; /* call the default scheduler */ if ((ret = quicly_default_stream_scheduler.do_send(&quicly_default_stream_scheduler, conn, s)) != 0) diff --git a/t/sentmap.c b/t/sentmap.c index 0d0df16f..6e5b4034 100644 --- a/t/sentmap.c +++ b/t/sentmap.c @@ -24,7 +24,7 @@ static int on_acked_callcnt, on_acked_ackcnt; -static int64_t on_acked(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, quicly_sent_t *sent) +static quicly_error_t on_acked(quicly_sentmap_t *map, const quicly_sent_packet_t *packet, int acked, quicly_sent_t *sent) { ++on_acked_callcnt; if (acked) diff --git a/t/simple.c b/t/simple.c index 76d090e1..6cd11d4b 100644 --- a/t/simple.c +++ b/t/simple.c @@ -460,7 +460,7 @@ static void test_reset_during_loss(void) static uint16_t test_close_error_code; -static void test_closed_by_remote(quicly_closed_by_remote_t *self, quicly_conn_t *conn, int64_t err, uint64_t frame_type, +static void test_closed_by_remote(quicly_closed_by_remote_t *self, quicly_conn_t *conn, quicly_error_t err, uint64_t frame_type, const char *reason, size_t reason_len) { ok(QUICLY_ERROR_IS_QUIC_APPLICATION(err)); @@ -478,7 +478,7 @@ static void test_close(void) uint8_t datagram_buf[quic_ctx.transport_params.max_udp_payload_size]; size_t num_datagrams; int64_t client_timeout, server_timeout; - int64_t ret; + quicly_error_t ret; quic_ctx.closed_by_remote = &closed_by_remote; diff --git a/t/test.c b/t/test.c index a6713e01..2cc035c5 100644 --- a/t/test.c +++ b/t/test.c @@ -86,10 +86,10 @@ "Vw6RN5S/14SQnMYWr7E=\n" \ "-----END CERTIFICATE-----\n" -static void on_destroy(quicly_stream_t *stream, int64_t err); -static void on_egress_stop(quicly_stream_t *stream, int64_t err); +static void on_destroy(quicly_stream_t *stream, quicly_error_t err); +static void on_egress_stop(quicly_stream_t *stream, quicly_error_t err); static void on_ingress_receive(quicly_stream_t *stream, size_t off, const void *src, size_t len); -static void on_ingress_reset(quicly_stream_t *stream, int64_t err); +static void on_ingress_reset(quicly_stream_t *stream, quicly_error_t err); quicly_address_t fake_address; int64_t quic_now = 1; @@ -169,14 +169,14 @@ static int64_t get_now_cb(quicly_now_t *self) static quicly_now_t get_now = {get_now_cb}; -void on_destroy(quicly_stream_t *stream, int64_t err) +void on_destroy(quicly_stream_t *stream, quicly_error_t err) { test_streambuf_t *sbuf = stream->data; sbuf->is_detached = 1; ++on_destroy_callcnt; } -void on_egress_stop(quicly_stream_t *stream, int64_t err) +void on_egress_stop(quicly_stream_t *stream, quicly_error_t err) { assert(QUICLY_ERROR_IS_QUIC_APPLICATION(err)); test_streambuf_t *sbuf = stream->data; @@ -188,7 +188,7 @@ void on_ingress_receive(quicly_stream_t *stream, size_t off, const void *src, si quicly_streambuf_ingress_receive(stream, off, src, len); } -void on_ingress_reset(quicly_stream_t *stream, int64_t err) +void on_ingress_reset(quicly_stream_t *stream, quicly_error_t err) { assert(QUICLY_ERROR_IS_QUIC_APPLICATION(err)); test_streambuf_t *sbuf = stream->data; @@ -202,7 +202,7 @@ const quicly_cid_plaintext_t *new_master_id(void) return &master; } -static int64_t on_stream_open(quicly_stream_open_t *self, quicly_stream_t *stream) +static quicly_error_t on_stream_open(quicly_stream_open_t *self, quicly_stream_t *stream) { test_streambuf_t *sbuf; int ret; diff --git a/t/test.h b/t/test.h index ea927c54..b7168fed 100644 --- a/t/test.h +++ b/t/test.h @@ -29,8 +29,8 @@ typedef struct st_test_streambuf_t { quicly_streambuf_t super; struct { - int64_t stop_sending; - int64_t reset_stream; + quicly_error_t stop_sending; + quicly_error_t reset_stream; } error_received; int is_detached; } test_streambuf_t;