diff --git a/include/quicly.h b/include/quicly.h index 0e18b90c..d021e1ab 100644 --- a/include/quicly.h +++ b/include/quicly.h @@ -117,17 +117,17 @@ 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. */ - int (*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); /** * */ - int (*update_state)(struct st_quicly_stream_scheduler_t *sched, quicly_stream_t *stream); + void (*update_state)(struct st_quicly_stream_scheduler_t *sched, quicly_stream_t *stream); } 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(int, 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, int 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(int, 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(int, 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, int 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, int 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, int 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); /** * */ -int 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); /** * */ -int 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. */ -int quicly_close(quicly_conn_t *conn, int 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. */ -int 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_ /** * */ -int 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. */ -int 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 /** * */ -int quicly_send_resumption_token(quicly_conn_t *conn); +quicly_error_t quicly_send_resumption_token(quicly_conn_t *conn); /** * */ -int 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. */ -int 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)` */ -int 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 @@ int quicly_connect(quicly_conn_t **conn, quicly_context_t *ctx, const char *serv * validated. * @param appdata initial value to be set to `*quicly_get_data(conn)` */ -int 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); /** * */ @@ -1256,7 +1258,7 @@ quicly_stream_id_t quicly_get_ingress_max_streams(quicly_conn_t *conn, int uni); * Iterates through each stream. When the callback returns a non-zero value, bails out from the iteration, returning the returned * value. */ -int quicly_foreach_stream(quicly_conn_t *conn, void *thunk, int (*cb)(void *thunk, quicly_stream_t *stream)); +int64_t quicly_foreach_stream(quicly_conn_t *conn, void *thunk, int64_t (*cb)(void *thunk, quicly_stream_t *stream)); /** * */ @@ -1264,7 +1266,7 @@ quicly_stream_t *quicly_get_stream(quicly_conn_t *conn, quicly_stream_id_t strea /** * */ -int 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 @@ int quicly_open_stream(quicly_conn_t *conn, quicly_stream_t **stream, int unidir * 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. */ -int 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, int err); +void quicly_reset_stream(quicly_stream_t *stream, quicly_error_t err); /** * */ -void quicly_request_stop(quicly_stream_t *stream, int 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 */ -int 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. */ -int 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, int 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, int 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, int 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 151af360..03f2fa70 100644 --- a/include/quicly/constants.h +++ b/include/quicly/constants.h @@ -66,13 +66,23 @@ extern "C" { #define QUICLY_EPOCH_1RTT 3 #define QUICLY_NUM_EPOCHS 4 -/* coexists with picotls error codes, assuming that int is at least 32-bits */ -#define QUICLY_ERROR_IS_QUIC(e) (((e) & ~0x1ffff) == 0x20000) -#define QUICLY_ERROR_IS_QUIC_TRANSPORT(e) (((e) & ~0xffff) == 0x20000) -#define QUICLY_ERROR_IS_QUIC_APPLICATION(e) (((e) & ~0xffff) == 0x30000) -#define QUICLY_ERROR_GET_ERROR_CODE(e) ((uint16_t)(e)) -#define QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(e) ((uint16_t)(e) + 0x20000) -#define QUICLY_ERROR_FROM_APPLICATION_ERROR_CODE(e) ((uint16_t)(e) + 0x30000) +/** + * Error code used by quicly. The code coalesces the following to an int64_t. + * * 0..0x2ff: picotls error codes (of type int) + * * 0x30000..0x400000000002ffff: QUIC application error codes + * * 0x4000000000030000..0x800000000002ffff...: QUIC protocol error codes + * Internal error codes should be allocated from the unused space below 0x30000 (i.e., unused space of picotls error codes); + * quicly itself uses 0xffxx. `quicly_error_t` is defined as a signed type so that the picotls error code space can be mapped + * without sign conversion. + */ +typedef int64_t quicly_error_t; + +#define QUICLY_ERROR_IS_QUIC(e) ((uint64_t)(quicly_error_t)(e) - 0x30000u < 0x8000000000000000u) +#define QUICLY_ERROR_IS_QUIC_TRANSPORT(e) ((uint64_t)(quicly_error_t)(e) - 0x4000000000030000u < 0x4000000000000000u) +#define QUICLY_ERROR_IS_QUIC_APPLICATION(e) ((uint64_t)(quicly_error_t)(e) - 0x30000u < 0x4000000000000000u) +#define QUICLY_ERROR_GET_ERROR_CODE(e) (((uint64_t)(quicly_error_t)(e) - 0x30000u) & 0x3fffffffffffffffu) +#define QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(e) ((quicly_error_t)((uint64_t)(e) + 0x4000000000030000u)) +#define QUICLY_ERROR_FROM_APPLICATION_ERROR_CODE(e) ((quicly_error_t)(uint64_t)(e) + 0x30000) /** * PTLS_ERROR_NO_MEMORY and QUICLY_ERROR_STATE_EXHAUSTION are special error codes that are internal but can be passed to * quicly_close. These are converted to QUICLY_TRANSPORT_ERROR_INTERNAL when sent over the wire. @@ -96,7 +106,7 @@ extern "C" { #define QUICLY_TRANSPORT_ERROR_CRYPTO_BUFFER_EXCEEDED QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0xd) #define QUICLY_TRANSPORT_ERROR_KEY_UPDATE QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0xe) #define QUICLY_TRANSPORT_ERROR_AEAD_LIMIT_REACHED QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0xf) -#define QUICLY_TRANSPORT_ERROR_TLS_ALERT_BASE QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0x100) +#define QUICLY_TRANSPORT_ERROR_CRYPTO(tls_alert) QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0x100 + (tls_alert)) /* internal error codes, used purely for signaling status to the application */ #define QUICLY_ERROR_PACKET_IGNORED 0xff01 diff --git a/include/quicly/frame.h b/include/quicly/frame.h index 6689be6e..fc6fc07e 100644 --- a/include/quicly/frame.h +++ b/include/quicly/frame.h @@ -105,34 +105,37 @@ typedef struct st_quicly_stream_frame_t { ptls_iovec_t data; } quicly_stream_frame_t; -static int 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 int 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); +static uint8_t *quicly_encode_reset_stream_frame(uint8_t *dst, uint64_t stream_id, uint64_t app_error_code, uint64_t final_size); typedef struct st_quicly_reset_stream_frame_t { uint64_t stream_id; - uint16_t app_error_code; + uint64_t app_error_code; uint64_t final_size; } quicly_reset_stream_frame_t; -static int 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; + uint64_t error_code; uint64_t frame_type; ptls_iovec_t reason_phrase; } quicly_transport_close_frame_t; -static int 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; + uint64_t error_code; ptls_iovec_t reason_phrase; } quicly_application_close_frame_t; -static int 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); /** @@ -147,7 +150,7 @@ typedef struct st_quicly_max_data_frame_t { uint64_t max_data; } quicly_max_data_frame_t; -static int 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); @@ -156,7 +159,8 @@ typedef struct st_quicly_max_stream_data_frame_t { uint64_t max_stream_data; } quicly_max_stream_data_frame_t; -static int 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); @@ -164,7 +168,7 @@ typedef struct st_quicly_max_streams_frame_t { uint64_t count; } quicly_max_streams_frame_t; -static int 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 @@ -174,7 +178,8 @@ typedef struct st_quicly_path_challenge_frame_t { const uint8_t *data; } quicly_path_challenge_frame_t; -static int 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); @@ -182,7 +187,7 @@ typedef struct st_quicly_data_blocked_frame_t { uint64_t offset; } quicly_data_blocked_frame_t; -static int 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); @@ -191,8 +196,8 @@ typedef struct st_quicly_stream_data_blocked_frame_t { uint64_t offset; } quicly_stream_data_blocked_frame_t; -static int 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); @@ -200,7 +205,8 @@ typedef struct st_quicly_streams_blocked_frame_t { uint64_t count; } quicly_streams_blocked_frame_t; -static int 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, @@ -216,23 +222,24 @@ typedef struct st_quicly_new_connection_id_frame_t { const uint8_t *stateless_reset_token; } quicly_new_connection_id_frame_t; -static int 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 int 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); +static uint8_t *quicly_encode_stop_sending_frame(uint8_t *dst, uint64_t stream_id, uint64_t app_error_code); typedef struct st_quicly_stop_sending_frame_t { uint64_t stream_id; - uint16_t app_error_code; + uint64_t app_error_code; } quicly_stop_sending_frame_t; -static int 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); @@ -246,7 +253,7 @@ typedef struct st_quicly_ack_frame_t { uint64_t ecn_counts[3]; } quicly_ack_frame_t; -int 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); @@ -255,7 +262,7 @@ typedef struct st_quicly_new_token_frame_t { ptls_iovec_t token; } quicly_new_token_frame_t; -static int 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); @@ -264,8 +271,8 @@ typedef struct st_quicly_datagram_frame_t { ptls_iovec_t payload; } quicly_datagram_frame_t; -static int 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; @@ -281,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 int 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 */ @@ -368,7 +376,8 @@ inline unsigned quicly_clz64(uint64_t v) return v != 0 ? __builtin_clzll(v) : 64; } -inline int 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) @@ -428,7 +437,7 @@ inline uint8_t *quicly_encode_crypto_frame_header(uint8_t *dst, uint8_t *dst_end return dst; } -inline int 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; @@ -449,7 +458,7 @@ inline int quicly_decode_crypto_frame(const uint8_t **src, const uint8_t *end, q return QUICLY_TRANSPORT_ERROR_FRAME_ENCODING; } -inline uint8_t *quicly_encode_reset_stream_frame(uint8_t *dst, uint64_t stream_id, uint16_t app_error_code, uint64_t final_size) +inline uint8_t *quicly_encode_reset_stream_frame(uint8_t *dst, uint64_t stream_id, uint64_t app_error_code, uint64_t final_size) { *dst++ = QUICLY_FRAME_TYPE_RESET_STREAM; dst = quicly_encodev(dst, stream_id); @@ -458,28 +467,25 @@ inline uint8_t *quicly_encode_reset_stream_frame(uint8_t *dst, uint64_t stream_i return dst; } -inline int 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; - if ((frame->stream_id = quicly_decodev(src, end)) == UINT64_MAX) goto Error; - if ((error_code = quicly_decodev(src, end)) == UINT64_MAX) + if ((frame->app_error_code = quicly_decodev(src, end)) == UINT64_MAX) goto Error; - frame->app_error_code = (uint16_t)error_code; frame->final_size = quicly_decodev(src, end); return 0; Error: return QUICLY_TRANSPORT_ERROR_FRAME_ENCODING; } -inline int 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; + uint64_t reason_len; - if ((error_code = quicly_decodev(src, end)) == UINT64_MAX) + if ((frame->error_code = quicly_decodev(src, end)) == UINT64_MAX) goto Error; - frame->error_code = (uint16_t)error_code; if ((reason_len = quicly_decodev(src, end)) == UINT64_MAX) goto Error; if ((uint64_t)(end - *src) < reason_len) @@ -491,13 +497,13 @@ inline int quicly_decode_application_close_frame(const uint8_t **src, const uint return QUICLY_TRANSPORT_ERROR_FRAME_ENCODING; } -inline int 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; + uint64_t reason_len; - if ((error_code = quicly_decodev(src, end)) == UINT64_MAX) + if ((frame->error_code = quicly_decodev(src, end)) == UINT64_MAX) goto Error; - frame->error_code = (uint16_t)error_code; if ((frame->frame_type = quicly_decodev(src, end)) == UINT64_MAX) goto Error; if ((reason_len = quicly_decodev(src, end)) == UINT64_MAX) @@ -523,7 +529,7 @@ inline uint8_t *quicly_encode_max_data_frame(uint8_t *dst, uint64_t max_data) return dst; } -inline int 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; @@ -538,7 +544,8 @@ inline uint8_t *quicly_encode_max_stream_data_frame(uint8_t *dst, uint64_t strea return dst; } -inline int 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; @@ -556,7 +563,7 @@ inline uint8_t *quicly_encode_max_streams_frame(uint8_t *dst, int uni, uint64_t return dst; } -inline int 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; @@ -565,7 +572,8 @@ inline int quicly_decode_max_streams_frame(const uint8_t **src, const uint8_t *e return 0; } -inline int 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; @@ -585,7 +593,7 @@ inline uint8_t *quicly_encode_data_blocked_frame(uint8_t *dst, uint64_t offset) return dst; } -inline int 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; @@ -600,8 +608,8 @@ inline uint8_t *quicly_encode_stream_data_blocked_frame(uint8_t *dst, quicly_str return dst; } -inline int 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; @@ -619,7 +627,8 @@ inline uint8_t *quicly_encode_streams_blocked_frame(uint8_t *dst, int uni, uint6 return dst; } -inline int 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; @@ -664,7 +673,8 @@ inline uint8_t *quicly_encode_retire_connection_id_frame(uint8_t *dst, uint64_t return dst; } -inline int 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) @@ -696,8 +706,8 @@ inline int quicly_decode_new_connection_id_frame(const uint8_t **src, const uint return QUICLY_TRANSPORT_ERROR_FRAME_ENCODING; } -inline int 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) @@ -708,7 +718,7 @@ inline int quicly_decode_retire_connection_id_frame(const uint8_t **src, const u return QUICLY_TRANSPORT_ERROR_FRAME_ENCODING; } -inline uint8_t *quicly_encode_stop_sending_frame(uint8_t *dst, uint64_t stream_id, uint16_t app_error_code) +inline uint8_t *quicly_encode_stop_sending_frame(uint8_t *dst, uint64_t stream_id, uint64_t app_error_code) { *dst++ = QUICLY_FRAME_TYPE_STOP_SENDING; dst = quicly_encodev(dst, stream_id); @@ -716,15 +726,12 @@ inline uint8_t *quicly_encode_stop_sending_frame(uint8_t *dst, uint64_t stream_i return dst; } -inline int 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; - if ((frame->stream_id = quicly_decodev(src, end)) == UINT64_MAX) goto Error; - if ((error_code = quicly_decodev(src, end)) == UINT64_MAX) + if ((frame->app_error_code = quicly_decodev(src, end)) == UINT64_MAX) goto Error; - frame->app_error_code = (uint16_t)error_code; return 0; Error: return QUICLY_TRANSPORT_ERROR_FRAME_ENCODING; @@ -744,7 +751,7 @@ inline uint8_t *quicly_encode_new_token_frame(uint8_t *dst, ptls_iovec_t token) return dst; } -inline int 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) @@ -774,8 +781,8 @@ inline uint8_t *quicly_encode_datagram_frame(uint8_t *dst, ptls_iovec_t payload) return dst; } -inline int 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; @@ -805,7 +812,8 @@ inline uint8_t *quicly_encode_ack_frequency_frame(uint8_t *dst, uint64_t sequenc return dst; } -inline int 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 e901be0f..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 */ -int 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 ec20602f..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 int 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); /** * */ -int 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. */ -int 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 int 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 d934526d..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). */ -int quicly_recvstate_update(quicly_recvstate_t *state, uint64_t off, size_t *len, int is_fin, size_t max_ranges); -int 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 3be8c180..7f4dac75 100644 --- a/include/quicly/remote_cid.h +++ b/include/quicly/remote_cid.h @@ -96,9 +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 */ -int 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 c12e2c2a..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 int (*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 */ -int 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_ */ -int 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); -int 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 40313972..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 int (*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, int 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 cdf8d8a2..af295039 100644 --- a/lib/defaults.c +++ b/lib/defaults.c @@ -309,10 +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 int 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), ret = 0; + int conn_is_blocked = quicly_is_blocked(conn); + quicly_error_t ret = 0; if (!conn_is_blocked) quicly_linklist_insert_list(&sched->active, &sched->blocked); @@ -349,7 +351,7 @@ static int default_stream_scheduler_do_send(quicly_stream_scheduler_t *self, qui /** * See doc-comment of `st_quicly_default_scheduler_state_t` to understand the logic. */ -static int default_stream_scheduler_update_state(quicly_stream_scheduler_t *self, quicly_stream_t *stream) +static void default_stream_scheduler_update_state(quicly_stream_scheduler_t *self, quicly_stream_t *stream) { struct st_quicly_default_scheduler_state_t *sched = &((struct _st_quicly_conn_public_t *)stream->conn)->_default_scheduler; @@ -361,8 +363,6 @@ static int default_stream_scheduler_update_state(quicly_stream_scheduler_t *self if (quicly_linklist_is_linked(&stream->_send_aux.pending_link.default_scheduler)) quicly_linklist_unlink(&stream->_send_aux.pending_link.default_scheduler); } - - return 0; } quicly_stream_scheduler_t quicly_default_stream_scheduler = {default_stream_scheduler_can_send, default_stream_scheduler_do_send, diff --git a/lib/frame.c b/lib/frame.c index dca34d41..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 } -int 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 7d0ee5a6..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; } -int 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 eb5da86f..236495b4 100644 --- a/lib/loss.c +++ b/lib/loss.c @@ -21,8 +21,8 @@ */ #include "quicly/loss.h" -int 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); @@ -33,7 +33,6 @@ int quicly_loss_init_sentmap_iter(quicly_loss_t *loss, quicly_sentmap_iter_t *it * heavy loss; in such case, 32 is more than enough, yet small enough that the memory footprint does not matter. */ const quicly_sent_packet_t *sent; while ((sent = quicly_sentmap_get(iter))->sent_at <= retire_before) { - int ret; if (!is_closing && loss->sentmap.num_packets < 32) break; if (sent->cc_bytes_in_flight != 0) { @@ -41,6 +40,7 @@ int quicly_loss_init_sentmap_iter(quicly_loss_t *loss, quicly_sentmap_iter_t *it quicly_sentmap_skip(iter); continue; } + quicly_error_t ret; if ((ret = quicly_sentmap_update(&loss->sentmap, iter, QUICLY_SENTMAP_EVENT_EXPIRED)) != 0) return ret; } @@ -51,8 +51,8 @@ int quicly_loss_init_sentmap_iter(quicly_loss_t *loss, quicly_sentmap_iter_t *it return 0; } -int 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 @@ int quicly_loss_detect_loss(quicly_loss_t *loss, int64_t now, uint32_t max_ack_d 1024; quicly_sentmap_iter_t iter; const quicly_sent_packet_t *sent; - int 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 169b2ddf..cb09ee79 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 int initiate_close(quicly_conn_t *conn, int err, uint64_t frame_type, const char *reason_phrase); -static int handle_close(quicly_conn_t *conn, int err, uint64_t frame_type, ptls_iovec_t reason_phrase); -static int 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 int 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 int 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; @@ -1058,6 +1058,29 @@ static int write_crypto_data(quicly_conn_t *conn, ptls_buffer_t *tlsbuf, size_t return 0; } +/** + * compresses a quicly error code into an int, converting QUIC transport error codes into negative ints + */ +static int compress_handshake_result(quicly_error_t quicly_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 <= quicly_err && quicly_err < INT_MAX); + return (int)quicly_err; + } +} + +static quicly_error_t expand_handshake_result(int compressed_err) +{ + if (compressed_err < 0) { + return QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(-compressed_err); + } else { + return compressed_err; + } +} + static void crypto_handshake(quicly_conn_t *conn, size_t in_epoch, ptls_iovec_t input) { ptls_buffer_t output; @@ -1067,8 +1090,8 @@ static void crypto_handshake(quicly_conn_t *conn, size_t in_epoch, ptls_iovec_t ptls_buffer_init(&output, "", 0); - int handshake_result = ptls_handle_message(conn->crypto.tls, &output, epoch_offsets, in_epoch, input.base, input.len, - &conn->crypto.handshake_properties); + 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); }); switch (handshake_result) { @@ -1083,8 +1106,10 @@ static void crypto_handshake(quicly_conn_t *conn, size_t in_epoch, ptls_iovec_t break; default: initiate_close(conn, - PTLS_ERROR_GET_CLASS(handshake_result) == PTLS_ERROR_CLASS_SELF_ALERT ? handshake_result - : QUICLY_TRANSPORT_ERROR_INTERNAL, + QUICLY_ERROR_IS_QUIC_TRANSPORT(handshake_result) || + PTLS_ERROR_GET_CLASS(handshake_result) == PTLS_ERROR_CLASS_SELF_ALERT + ? handshake_result + : QUICLY_TRANSPORT_ERROR_INTERNAL, QUICLY_FRAME_TYPE_CRYPTO, NULL); goto Exit; } @@ -1095,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 */ - int 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; @@ -1264,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, int err) +static void destroy_stream(quicly_stream_t *stream, quicly_error_t err) { quicly_conn_t *conn = stream->conn; @@ -1297,7 +1322,7 @@ static void destroy_stream(quicly_stream_t *stream, int err) free(stream); } -static void destroy_all_streams(quicly_conn_t *conn, int 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, { @@ -1308,12 +1333,12 @@ static void destroy_all_streams(quicly_conn_t *conn, int err, int including_cryp assert(quicly_num_streams(conn) == 0); } -int quicly_foreach_stream(quicly_conn_t *conn, void *thunk, int (*cb)(void *thunk, quicly_stream_t *stream)) +int64_t quicly_foreach_stream(quicly_conn_t *conn, void *thunk, int64_t (*cb)(void *thunk, quicly_stream_t *stream)) { quicly_stream_t *stream; kh_foreach_value(conn->streams, stream, { if (stream->stream_id >= 0) { - int ret = cb(thunk, stream); + int64_t ret = cb(thunk, stream); if (ret != 0) return ret; } @@ -1351,7 +1376,7 @@ struct sockaddr *quicly_get_peername(quicly_conn_t *conn) return &conn->paths[0]->address.remote.sa; } -int 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)); @@ -1372,7 +1397,7 @@ int quicly_get_stats(quicly_conn_t *conn, quicly_stats_t *stats) return 0; } -int 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; @@ -1523,9 +1548,9 @@ static void do_free_pn_space(struct st_quicly_pn_space_t *space) free(space); } -static int 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) { - int ret; + quicly_error_t ret; *is_out_of_order = 0; @@ -1547,10 +1572,11 @@ static int record_pn(quicly_ranges_t *ranges, uint64_t pn, int *is_out_of_order) return 0; } -static int 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 ret, ack_now, is_out_of_order; + int ack_now, is_out_of_order; + quicly_error_t ret; if ((ret = record_pn(&space->ack_queue, pn, &is_out_of_order)) != 0) goto Exit; @@ -1647,9 +1673,9 @@ static int setup_application_space(quicly_conn_t *conn) return create_handshake_flow(conn, QUICLY_EPOCH_1RTT); } -static int discard_handshake_context(quicly_conn_t *conn, size_t epoch) +static quicly_error_t discard_handshake_context(quicly_conn_t *conn, size_t epoch) { - int ret; + quicly_error_t ret; assert(epoch == QUICLY_EPOCH_INITIAL || epoch == QUICLY_EPOCH_HANDSHAKE); @@ -1665,9 +1691,9 @@ static int discard_handshake_context(quicly_conn_t *conn, size_t epoch) return 0; } -static int apply_remote_transport_params(quicly_conn_t *conn) +static quicly_error_t apply_remote_transport_params(quicly_conn_t *conn) { - int 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) @@ -1877,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 int 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; - int 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; @@ -2094,7 +2120,7 @@ static int setup_initial_encryption(ptls_cipher_suite_t *cs, struct st_quicly_ci return ret; } -static int reinstall_initial_encryption(quicly_conn_t *conn, int 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; @@ -2113,9 +2139,9 @@ static int reinstall_initial_encryption(quicly_conn_t *conn, int err_code_if_unk ptls_iovec_init(salt->initial, sizeof(salt->initial)), NULL); } -static int 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) { - int 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, { @@ -2263,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) -int 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, @@ -2302,7 +2328,7 @@ int quicly_decode_transport_parameter_list(quicly_transport_parameters_t *params }); uint64_t found_bits = 0; - int ret; + quicly_error_t ret; /* set parameters to their default values */ *params = default_transport_params; @@ -2632,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)); - int ret; + quicly_error_t ret; assert(properties->client.early_data_acceptance != PTLS_EARLY_DATA_ACCEPTANCE_UNKNOWN); @@ -2699,13 +2725,13 @@ static int client_collected_extensions(ptls_t *tls, ptls_handshake_properties_t ack_frequency_set_next_update_at(conn); Exit: - return ret; /* negative error codes used to transmit QUIC errors through picotls */ + return compress_handshake_result(ret); } -int 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; @@ -2713,7 +2739,7 @@ int quicly_connect(quicly_conn_t **_conn, quicly_context_t *ctx, const char *ser ptls_buffer_t buf; size_t epoch_offsets[5] = {0}; size_t max_early_data_size = 0; - int ret; + quicly_error_t ret; if ((salt = quicly_get_salt(ctx->initial_version)) == NULL) { if ((ctx->initial_version & 0x0f0f0f0f) == 0x0a0a0a0a) { @@ -2775,7 +2801,8 @@ int quicly_connect(quicly_conn_t **_conn, quicly_context_t *ctx, const char *ser ptls_buffer_init(&buf, "", 0); if (resumed_transport_params != NULL) conn->crypto.handshake_properties.client.max_early_data_size = &max_early_data_size; - ret = ptls_handle_message(conn->crypto.tls, &buf, epoch_offsets, 0, NULL, 0, &conn->crypto.handshake_properties); + ret = expand_handshake_result( + ptls_handle_message(conn->crypto.tls, &buf, epoch_offsets, 0, NULL, 0, &conn->crypto.handshake_properties)); conn->crypto.handshake_properties.client.max_early_data_size = NULL; if (ret != PTLS_ERROR_IN_PROGRESS) { assert(ret > 0); /* no QUIC errors */ @@ -2816,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; - int ret; + quicly_error_t ret; if (slots[0].type == UINT16_MAX) { ret = PTLS_ALERT_MISSING_EXTENSION; @@ -2875,7 +2902,7 @@ static int server_collected_extensions(ptls_t *tls, ptls_handshake_properties_t ret = 0; Exit: - return ret; + return compress_handshake_result(ret); } static size_t aead_decrypt_core(ptls_aead_context_t *aead, uint64_t pn, quicly_decoded_packet_t *packet, size_t aead_off) @@ -2946,15 +2973,15 @@ static int aead_decrypt_1rtt(void *ctx, uint64_t pn, quicly_decoded_packet_t *pa return 0; } -static int 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}; uint32_t pnbits = 0; size_t pnlen, ptlen, i; - int ret; /* decipher the header protection, as well as obtaining pnbits, pnlen */ if (encrypted_len < header_protection->algo->iv_size + QUICLY_MAX_PN_SIZE) { @@ -2974,6 +3001,7 @@ static int do_decrypt_packet(ptls_cipher_context_t *header_protection, *pn = quicly_determine_packet_number(pnbits, pnlen * 8, *next_expected_pn); /* AEAD decryption */ + int ret; if ((ret = (*aead_cb)(aead_ctx, *pn, packet, aead_off, &ptlen)) != 0) { return ret; } @@ -2984,11 +3012,12 @@ static int do_decrypt_packet(ptls_cipher_context_t *header_protection, return 0; } -static int 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) { - int ret; + quicly_error_t ret; /* decrypt ourselves, or use the pre-decrypted input */ if (packet->decrypted.pn == UINT64_MAX) { @@ -3021,8 +3050,8 @@ static int decrypt_packet(ptls_cipher_context_t *header_protection, return 0; } -static int 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; @@ -3065,7 +3094,7 @@ static int do_on_ack_ack(quicly_conn_t *conn, const quicly_sent_packet_t *packet return 0; } -static int 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)); @@ -3076,7 +3105,7 @@ static int on_ack_ack_ranges64(quicly_sentmap_t *map, const quicly_sent_packet_t : 0; } -static int 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)); @@ -3087,15 +3116,15 @@ static int on_ack_ack_ranges8(quicly_sentmap_t *map, const quicly_sent_packet_t : 0; } -static int 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; - int ret; if ((stream = quicly_get_stream(conn, stream_id)) == NULL) return 0; size_t bytes_to_shift; + int ret; if ((ret = quicly_sendstate_acked(&stream->sendstate, sent, &bytes_to_shift)) != 0) return ret; if (bytes_to_shift != 0) { @@ -3115,22 +3144,20 @@ static int on_ack_stream_ack_one(quicly_conn_t *conn, quicly_stream_id_t stream_ return 0; } -static int on_ack_stream_ack_cached(quicly_conn_t *conn) +static quicly_error_t on_ack_stream_ack_cached(quicly_conn_t *conn) { - int ret; - if (conn->stash.on_ack_stream.active_acked_cache.stream_id == INT64_MIN) return 0; - ret = on_ack_stream_ack_one(conn, conn->stash.on_ack_stream.active_acked_cache.stream_id, - &conn->stash.on_ack_stream.active_acked_cache.args); + quicly_error_t ret = on_ack_stream_ack_one(conn, conn->stash.on_ack_stream.active_acked_cache.stream_id, + &conn->stash.on_ack_stream.active_acked_cache.args); conn->stash.on_ack_stream.active_acked_cache.stream_id = INT64_MIN; return ret; } -static int 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)); - int ret; + quicly_error_t ret; if (acked) { @@ -3183,7 +3210,8 @@ static int on_ack_stream(quicly_sentmap_t *map, const quicly_sent_packet_t *pack return 0; } -static int 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; @@ -3201,7 +3229,7 @@ static int on_ack_max_stream_data(quicly_sentmap_t *map, const quicly_sent_packe return 0; } -static int 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)); @@ -3214,7 +3242,7 @@ static int on_ack_max_data(quicly_sentmap_t *map, const quicly_sent_packet_t *pa return 0; } -static int 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; @@ -3234,7 +3262,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 int 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; @@ -3248,7 +3276,7 @@ static int on_ack_reset_stream(quicly_sentmap_t *map, const quicly_sent_packet_t return 0; } -static int 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; @@ -3262,7 +3290,8 @@ static int on_ack_stop_sending(quicly_sentmap_t *map, const quicly_sent_packet_t return 0; } -static int 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 = @@ -3277,7 +3306,8 @@ static int on_ack_streams_blocked(quicly_sentmap_t *map, const quicly_sent_packe return 0; } -static int 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)); @@ -3290,7 +3320,7 @@ static int on_ack_handshake_done(quicly_sentmap_t *map, const quicly_sent_packet return 0; } -static int 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)); @@ -3306,8 +3336,8 @@ static int on_ack_data_blocked(quicly_sentmap_t *map, const quicly_sent_packet_t return 0; } -static int 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; @@ -3327,7 +3357,7 @@ static int on_ack_stream_data_blocked_frame(quicly_sentmap_t *map, const quicly_ return 0; } -static int 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)); @@ -3348,7 +3378,8 @@ static int on_ack_new_token(quicly_sentmap_t *map, const quicly_sent_packet_t *p return 0; } -static int 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; @@ -3363,7 +3394,8 @@ static int on_ack_new_connection_id(quicly_sentmap_t *map, const quicly_sent_pac return 0; } -static int 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; @@ -3640,7 +3672,7 @@ struct st_quicly_send_context_t { unsigned recalc_send_probe_at : 1; }; -static int 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; @@ -3746,7 +3778,7 @@ static int commit_send_packet(quicly_conn_t *conn, quicly_send_context_t *s, int * 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) { - int 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; @@ -3776,9 +3808,11 @@ enum allocate_frame_type { ALLOCATE_FRAME_TYPE_ACK_ELICITING_NO_CC, }; -static int 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, ret; + int coalescible; + quicly_error_t ret; assert((s->current.first_byte & QUICLY_QUIC_BIT) != 0); @@ -3906,10 +3940,10 @@ static int do_allocate_frame(quicly_conn_t *conn, quicly_send_context_t *s, size return 0; } -static int 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) { - int ret; + quicly_error_t ret; if ((ret = do_allocate_frame(conn, s, min_space, ALLOCATE_FRAME_TYPE_ACK_ELICITING)) != 0) return ret; @@ -3919,10 +3953,10 @@ static int allocate_ack_eliciting_frame(quicly_conn_t *conn, quicly_send_context return ret; } -static int 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; - int ret; + quicly_error_t ret; if (space->ack_queue.num_ranges == 0) return 0; @@ -4016,11 +4050,11 @@ static int send_ack(quicly_conn_t *conn, struct st_quicly_pn_space_t *space, qui return ret; } -static int 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; - int ret; + quicly_error_t ret; if ((ret = allocate_ack_eliciting_frame(stream->conn, s, min_space, &sent, ack_cb)) != 0) return ret; @@ -4030,9 +4064,9 @@ static int prepare_stream_state_sender(quicly_stream_t *stream, quicly_sender_st return 0; } -static int 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) { - int ret; + quicly_error_t ret; /* send STOP_SENDING if necessary */ if (stream->_send_aux.stop_sending.sender_state == QUICLY_SENDER_STATE_SEND) { @@ -4111,9 +4145,9 @@ static int send_control_frames_of_stream(quicly_stream_t *stream, quicly_send_co return 0; } -static int 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) { - int 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 = @@ -4210,14 +4244,15 @@ static inline void adjust_stream_frame_layout(uint8_t **dst, uint8_t *const dst_ *dst += *len; } -int 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; uint8_t *dst; /* this pointer points to the current write position within the frame being built, while `s->dst` points to the * beginning of the frame. */ size_t len; - int ret, wrote_all, is_fin; + int wrote_all, is_fin; + quicly_error_t ret; /* write frame type, stream_id and offset, calculate capacity (and store that in `len`) */ if (stream->stream_id < 0) { @@ -4359,18 +4394,18 @@ int quicly_send_stream(quicly_stream_t *stream, quicly_send_context_t *s) return 0; } -static inline int 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); } -int 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; - int ret; + quicly_error_t ret; if ((ret = init_acks_iter(conn, &iter)) != 0) return ret; @@ -4390,11 +4425,11 @@ int 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 int 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; - int ret; + quicly_error_t ret; if ((ret = init_acks_iter(conn, &iter)) != 0) return ret; @@ -4450,14 +4485,14 @@ static void on_loss_detected(quicly_loss_t *loss, const quicly_sent_packet_t *lo conn->egress.loss.sentmap.bytes_in_flight); } -static int 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; - int ret; + quicly_error_t ret; uint64_t new_count = group->next_stream_id / 4 + @@ -4485,10 +4520,10 @@ static int send_max_streams(quicly_conn_t *conn, int uni, quicly_send_context_t return 0; } -static int 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; - int ret; + quicly_error_t ret; if (!quicly_linklist_is_linked(blocked_list)) return 0; @@ -4547,10 +4582,10 @@ static void open_blocked_streams(quicly_conn_t *conn, int uni) } } -static int 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; - int ret; + quicly_error_t ret; if ((ret = allocate_ack_eliciting_frame(conn, s, 1, &sent, on_ack_handshake_done)) != 0) goto Exit; @@ -4565,10 +4600,10 @@ static int send_handshake_done(quicly_conn_t *conn, quicly_send_context_t *s) return ret; } -static int 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; - int 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) @@ -4676,7 +4711,7 @@ static size_t encode_resumption_info(quicly_conn_t *conn, uint8_t *dst, size_t c return buf.off; } -static int 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); @@ -4685,7 +4720,7 @@ static int send_resumption_token(quicly_conn_t *conn, quicly_send_context_t *s) ptls_buffer_t tokenbuf; uint8_t tokenbuf_small[128]; quicly_sent_t *sent; - int ret; + quicly_error_t ret; ptls_buffer_init(&tokenbuf, tokenbuf_small, sizeof(tokenbuf_small)); @@ -4758,7 +4793,8 @@ size_t quicly_send_version_negotiation(quicly_context_t *ctx, ptls_iovec_t dest_ return dst - (uint8_t *)payload; } -int 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; @@ -4785,7 +4821,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; - int ret; + quicly_error_t ret; assert(!(src_cid.len == odcid.len && memcmp(src_cid.base, odcid.base, src_cid.len) == 0)); @@ -4884,10 +4920,10 @@ static struct st_quicly_pn_space_t *setup_send_space(quicly_conn_t *conn, size_t return space; } -static int 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; - int 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) @@ -4925,11 +4961,11 @@ static int send_handshake_flow(quicly_conn_t *conn, size_t epoch, quicly_send_co return ret; } -static int 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; - int 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) @@ -4977,16 +5013,15 @@ static int send_connection_close(quicly_conn_t *conn, size_t epoch, quicly_send_ return 0; } -static int 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) { - int ret; quicly_sent_t *sent; uint64_t retire_prior_to = 0; /* TODO */ + quicly_error_t ret; - ret = allocate_ack_eliciting_frame( - conn, s, quicly_new_connection_id_frame_capacity(new_cid->sequence, retire_prior_to, new_cid->cid.len), &sent, - on_ack_new_connection_id); - if (ret != 0) + 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, + on_ack_new_connection_id)) != 0) return ret; sent->data.new_connection_id.sequence = new_cid->sequence; @@ -5007,14 +5042,13 @@ static int send_new_connection_id(quicly_conn_t *conn, quicly_send_context_t *s, return 0; } -static int 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) { - int ret; quicly_sent_t *sent; + quicly_error_t ret; - ret = allocate_ack_eliciting_frame(conn, s, quicly_retire_connection_id_frame_capacity(sequence), &sent, - on_ack_retire_connection_id); - if (ret != 0) + if ((ret = allocate_ack_eliciting_frame(conn, s, quicly_retire_connection_id_frame_capacity(sequence), &sent, + on_ack_retire_connection_id)) != 0) return ret; sent->data.retire_connection_id.sequence = sequence; @@ -5027,9 +5061,9 @@ static int send_retire_connection_id(quicly_conn_t *conn, quicly_send_context_t return 0; } -static int 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) { - int 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; @@ -5103,7 +5137,7 @@ static int update_traffic_key_cb(ptls_update_traffic_key_t *self, ptls_t *tls, i break; case QUICLY_EPOCH_1RTT: { if (is_enc) - if ((ret = apply_remote_transport_params(conn)) != 0) + if ((ret = compress_handshake_result(apply_remote_transport_params(conn))) != 0) return ret; if (conn->application == NULL && (ret = setup_application_space(conn)) != 0) return ret; @@ -5140,8 +5174,8 @@ 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) { - ret = quicly_send_resumption_token(conn); - assert(ret == 0); + quicly_error_t ret64 = quicly_send_resumption_token(conn); + assert(ret64 == 0); } /* schedule NEW_CONNECTION_IDs */ @@ -5153,9 +5187,9 @@ static int update_traffic_key_cb(ptls_update_traffic_key_t *self, ptls_t *tls, i return 0; } -static int 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) { - int ret; + quicly_error_t ret; /* MAX_STREAMS */ if ((ret = send_max_streams(conn, 1, s)) != 0) @@ -5216,10 +5250,11 @@ static int send_other_control_frames(quicly_conn_t *conn, quicly_send_context_t return 0; } -static int 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, ret = 0; + int restrict_sending = 0, ack_only = 0; size_t min_packets_to_send = 0, orig_bytes_inflight = 0; + quicly_error_t ret = 0; /* handle timeouts */ if (conn->idle_timeout.at <= conn->stash.now) { @@ -5508,15 +5543,15 @@ int quicly_set_cc(quicly_conn_t *conn, quicly_cc_type_t *cc) return cc->cc_switch(&conn->egress.cc); } -int 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}; - int ret; + quicly_error_t ret; lock_now(conn, 0); @@ -5698,7 +5733,7 @@ size_t quicly_send_stateless_reset(quicly_context_t *ctx, const void *src_cid, v return QUICLY_STATELESS_RESET_PACKET_MIN_LEN; } -int quicly_send_resumption_token(quicly_conn_t *conn) +quicly_error_t quicly_send_resumption_token(quicly_conn_t *conn) { assert(!quicly_is_client(conn)); @@ -5709,16 +5744,16 @@ int quicly_send_resumption_token(quicly_conn_t *conn) return 0; } -static int 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 int 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) { - int ret; + quicly_error_t ret; assert(conn->super.state < QUICLY_STATE_CLOSING); @@ -5746,7 +5781,7 @@ static int enter_close(quicly_conn_t *conn, int local_is_initiating, int wait_dr return 0; } -int initiate_close(quicly_conn_t *conn, int 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; @@ -5766,7 +5801,7 @@ int initiate_close(quicly_conn_t *conn, int err, uint64_t frame_type, const char quic_error_code = QUICLY_ERROR_GET_ERROR_CODE(err); frame_type = UINT64_MAX; } else if (PTLS_ERROR_GET_CLASS(err) == PTLS_ERROR_CLASS_SELF_ALERT) { - quic_error_code = QUICLY_TRANSPORT_ERROR_TLS_ALERT_BASE + PTLS_ERROR_TO_ALERT(err); + quic_error_code = QUICLY_TRANSPORT_ERROR_CRYPTO(PTLS_ERROR_TO_ALERT(err)); } else { quic_error_code = QUICLY_ERROR_GET_ERROR_CODE(QUICLY_TRANSPORT_ERROR_INTERNAL); } @@ -5777,9 +5812,9 @@ int initiate_close(quicly_conn_t *conn, int err, uint64_t frame_type, const char return enter_close(conn, 1, 0); } -int quicly_close(quicly_conn_t *conn, int err, const char *reason_phrase) +quicly_error_t quicly_close(quicly_conn_t *conn, quicly_error_t err, const char *reason_phrase) { - int ret; + quicly_error_t ret; assert(err == 0 || QUICLY_ERROR_IS_QUIC_APPLICATION(err) || QUICLY_ERROR_IS_CONCEALED(err)); @@ -5790,9 +5825,9 @@ int quicly_close(quicly_conn_t *conn, int err, const char *reason_phrase) return ret; } -int 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) { - int ret = 0; + quicly_error_t ret = 0; if ((*stream = quicly_get_stream(conn, stream_id)) != NULL) goto Exit; @@ -5836,11 +5871,11 @@ int quicly_get_or_open_stream(quicly_conn_t *conn, uint64_t stream_id, quicly_st return ret; } -static int 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; - int ret; + quicly_error_t ret; if ((ret = quicly_decode_crypto_frame(&state->src, state->end, &frame)) != 0) return ret; @@ -5849,11 +5884,11 @@ static int handle_crypto_frame(quicly_conn_t *conn, struct st_quicly_handle_payl return apply_stream_frame(stream, &frame); } -static int 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; - int ret; + quicly_error_t ret; if ((ret = quicly_decode_stream_frame(state->frame_type, &state->src, state->end, &frame)) != 0) return ret; @@ -5863,11 +5898,11 @@ static int handle_stream_frame(quicly_conn_t *conn, struct st_quicly_handle_payl return apply_stream_frame(stream, &frame); } -static int 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; - int ret; + quicly_error_t ret; if ((ret = quicly_decode_reset_stream_frame(&state->src, state->end, &frame)) != 0) return ret; @@ -5886,7 +5921,7 @@ static int handle_reset_stream_frame(quicly_conn_t *conn, struct st_quicly_handl if ((ret = quicly_recvstate_reset(&stream->recvstate, frame.final_size, &bytes_missing)) != 0) return ret; stream->conn->ingress.max_data.bytes_consumed += bytes_missing; - int 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); @@ -5902,7 +5937,7 @@ static int handle_reset_stream_frame(quicly_conn_t *conn, struct st_quicly_handl return 0; } -static int 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; @@ -5911,7 +5946,8 @@ static int handle_ack_frame(quicly_conn_t *conn, struct st_quicly_handle_payload int64_t sent_at; } largest_newly_acked = {UINT64_MAX, INT64_MAX}; size_t bytes_acked = 0; - int includes_ack_eliciting = 0, includes_late_ack = 0, ret; + int includes_ack_eliciting = 0, includes_late_ack = 0; + 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 @@ -6095,11 +6131,11 @@ static int handle_ack_frame(quicly_conn_t *conn, struct st_quicly_handle_payload return 0; } -static int 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; - int ret; + quicly_error_t ret; if ((ret = quicly_decode_max_stream_data_frame(&state->src, state->end, &frame)) != 0) return ret; @@ -6127,10 +6163,10 @@ static int handle_max_stream_data_frame(quicly_conn_t *conn, struct st_quicly_ha return 0; } -static int 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; - int ret; + quicly_error_t ret; if ((ret = quicly_decode_data_blocked_frame(&state->src, state->end, &frame)) != 0) return ret; @@ -6145,11 +6181,11 @@ static int handle_data_blocked_frame(quicly_conn_t *conn, struct st_quicly_handl return 0; } -static int 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; - int ret; + quicly_error_t ret; if ((ret = quicly_decode_stream_data_blocked_frame(&state->src, state->end, &frame)) != 0) return ret; @@ -6172,10 +6208,11 @@ static int handle_stream_data_blocked_frame(quicly_conn_t *conn, struct st_quicl return 0; } -static int 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, ret; + int uni = state->frame_type == QUICLY_FRAME_TYPE_STREAMS_BLOCKED_UNI; + quicly_error_t ret; if ((ret = quicly_decode_streams_blocked_frame(&state->src, state->end, &frame)) != 0) return ret; @@ -6195,10 +6232,10 @@ static int handle_streams_blocked_frame(quicly_conn_t *conn, struct st_quicly_ha return 0; } -static int 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; - int ret; + quicly_error_t ret; if ((ret = quicly_decode_max_streams_frame(&state->src, state->end, &frame)) != 0) return ret; @@ -6217,20 +6254,20 @@ static int handle_max_streams_frame(quicly_conn_t *conn, struct st_quicly_handle return 0; } -static int 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 int 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 int 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; - int ret; + quicly_error_t ret; if ((ret = quicly_decode_path_challenge_frame(&state->src, state->end, &frame)) != 0) return ret; @@ -6247,10 +6284,10 @@ static int handle_path_challenge_frame(quicly_conn_t *conn, struct st_quicly_han return 0; } -static int 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; - int ret; + quicly_error_t ret; if ((ret = quicly_decode_path_challenge_frame(&state->src, state->end, &frame)) != 0) return ret; @@ -6270,10 +6307,10 @@ static int handle_path_response_frame(quicly_conn_t *conn, struct st_quicly_hand return 0; } -static int 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; - int ret; + quicly_error_t ret; if (!quicly_is_client(conn)) return QUICLY_TRANSPORT_ERROR_PROTOCOL_VIOLATION; @@ -6286,11 +6323,11 @@ static int handle_new_token_frame(quicly_conn_t *conn, struct st_quicly_handle_p return conn->super.ctx->save_resumption_token->cb(conn->super.ctx->save_resumption_token, conn, frame.token); } -static int 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; - int ret; + quicly_error_t ret; if ((ret = quicly_decode_stop_sending_frame(&state->src, state->end, &frame)) != 0) return ret; @@ -6305,7 +6342,7 @@ static int handle_stop_sending_frame(quicly_conn_t *conn, struct st_quicly_handl if (quicly_sendstate_is_open(&stream->sendstate)) { /* reset the stream, then notify the application */ - int 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, { @@ -6320,10 +6357,10 @@ static int handle_stop_sending_frame(quicly_conn_t *conn, struct st_quicly_handl return 0; } -static int 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; - int ret; + quicly_error_t ret; if ((ret = quicly_decode_max_data_frame(&state->src, state->end, &frame)) != 0) return ret; @@ -6339,9 +6376,9 @@ static int handle_max_data_frame(quicly_conn_t *conn, struct st_quicly_handle_pa return 0; } -static int negotiate_using_version(quicly_conn_t *conn, uint32_t version) +static quicly_error_t negotiate_using_version(quicly_conn_t *conn, uint32_t version) { - int ret; + quicly_error_t ret; /* set selected version, update transport parameters extension ID */ conn->super.version = version; @@ -6359,7 +6396,7 @@ static int negotiate_using_version(quicly_conn_t *conn, uint32_t version) return 0; } -static int 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; @@ -6494,9 +6531,9 @@ int quicly_is_destination(quicly_conn_t *conn, struct sockaddr *dest_addr, struc return 1; } -int handle_close(quicly_conn_t *conn, int 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) { - int ret; + quicly_error_t ret; if (conn->super.state >= QUICLY_STATE_CLOSING) return 0; @@ -6513,10 +6550,10 @@ int handle_close(quicly_conn_t *conn, int err, uint64_t frame_type, ptls_iovec_t return 0; } -static int 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; - int ret; + quicly_error_t ret; if ((ret = quicly_decode_transport_close_frame(&state->src, state->end, &frame)) != 0) return ret; @@ -6531,10 +6568,10 @@ static int handle_transport_close_frame(quicly_conn_t *conn, struct st_quicly_ha return handle_close(conn, QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(frame.error_code), frame.frame_type, frame.reason_phrase); } -static int 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; - int ret; + quicly_error_t ret; if ((ret = quicly_decode_application_close_frame(&state->src, state->end, &frame)) != 0) return ret; @@ -6548,12 +6585,12 @@ static int handle_application_close_frame(quicly_conn_t *conn, struct st_quicly_ return handle_close(conn, QUICLY_ERROR_FROM_APPLICATION_ERROR_CODE(frame.error_code), UINT64_MAX, frame.reason_phrase); } -static int 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 int 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, {}); @@ -6561,10 +6598,10 @@ static int handle_ping_frame(quicly_conn_t *conn, struct st_quicly_handle_payloa return 0; } -static int 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) { - int ret; quicly_new_connection_id_frame_t frame; + quicly_error_t ret; /* TODO: return error when using zero-length CID */ @@ -6594,10 +6631,11 @@ static int handle_new_connection_id_frame(quicly_conn_t *conn, struct st_quicly_ return 0; } -static int 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 ret, has_pending; + int has_pending; quicly_retire_connection_id_frame_t frame; + quicly_error_t ret; if ((ret = quicly_decode_retire_connection_id_frame(&state->src, state->end, &frame)) != 0) return ret; @@ -6619,9 +6657,9 @@ static int handle_retire_connection_id_frame(quicly_conn_t *conn, struct st_quic return 0; } -static int 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) { - int ret; + quicly_error_t ret; QUICLY_PROBE(HANDSHAKE_DONE_RECEIVE, conn, conn->stash.now); QUICLY_LOG_CONN(handshake_done_receive, conn, {}); @@ -6640,10 +6678,10 @@ static int handle_handshake_done_frame(quicly_conn_t *conn, struct st_quicly_han return 0; } -static int 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; - int 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) @@ -6661,10 +6699,10 @@ static int handle_datagram_frame(quicly_conn_t *conn, struct st_quicly_handle_pa return 0; } -static int 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; - int 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) @@ -6697,14 +6735,15 @@ static int handle_ack_frequency_frame(quicly_conn_t *conn, struct st_quicly_hand return 0; } -static int 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 { - int (*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" */ @@ -6788,7 +6827,7 @@ static int handle_payload(quicly_conn_t *conn, size_t epoch, size_t path_index, 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; - int ret; + quicly_error_t ret; do { /* determine the frame type; fast path is available for frame types below 64 */ @@ -6835,7 +6874,7 @@ static int handle_payload(quicly_conn_t *conn, size_t epoch, size_t path_index, return ret; } -static int 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, {}); @@ -6853,9 +6892,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; } -int 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 { @@ -6864,7 +6904,8 @@ int quicly_accept(quicly_conn_t **conn, quicly_context_t *ctx, struct sockaddr * } cipher = {}; ptls_iovec_t payload; uint64_t next_expected_pn, pn, offending_frame_type = QUICLY_FRAME_TYPE_PADDING; - int is_ack_only, is_probe_only, ret; + int is_ack_only, is_probe_only; + quicly_error_t ret; *conn = NULL; @@ -6981,7 +7022,8 @@ int quicly_accept(quicly_conn_t **conn, quicly_context_t *ctx, struct sockaddr * return ret; } -int 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 { @@ -6992,7 +7034,8 @@ int quicly_receive(quicly_conn_t *conn, struct sockaddr *dest_addr, struct socka size_t epoch, path_index; ptls_iovec_t payload; uint64_t pn, offending_frame_type = QUICLY_FRAME_TYPE_PADDING; - int is_ack_only, is_probe_only, ret; + int is_ack_only, is_probe_only; + quicly_error_t ret; assert(src_addr->sa_family == AF_INET || src_addr->sa_family == AF_INET6); @@ -7331,14 +7374,14 @@ int quicly_receive(quicly_conn_t *conn, struct sockaddr *dest_addr, struct socka return ret; } -int 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; - int ret; + quicly_error_t ret; /* determine the states */ if (uni) { @@ -7381,7 +7424,7 @@ int quicly_open_stream(quicly_conn_t *conn, quicly_stream_t **_stream, int uni) return 0; } -void quicly_reset_stream(quicly_stream_t *stream, int 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)); @@ -7400,7 +7443,7 @@ void quicly_reset_stream(quicly_stream_t *stream, int err) resched_stream_data(stream); } -void quicly_request_stop(quicly_stream_t *stream, int 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)); @@ -7510,10 +7553,10 @@ void quicly_amend_ptls_context(ptls_context_t *ptls) ptls->max_early_data_size = UINT32_MAX; } -int 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) { - int ret; + quicly_error_t ret; /* type and IV */ if ((ret = ptls_buffer_reserve(buf, 1 + aead->algo->iv_size)) != 0) @@ -7576,8 +7619,8 @@ int quicly_encrypt_address_token(void (*random_bytes)(void *, size_t), ptls_aead return ret; } -int 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]; @@ -7609,7 +7652,7 @@ int quicly_decrypt_address_token(ptls_aead_context_t *aead, quicly_address_token } /* `goto Exit` can only happen below this line, and that is guaranteed by declaring `ret` here */ - int ret; + quicly_error_t ret; /* decrypt */ ptls_aead_set_iv(aead, token + prefix_len + 1); @@ -7735,7 +7778,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, int err) +void quicly_stream_noop_on_destroy(quicly_stream_t *stream, quicly_error_t err) { } @@ -7747,7 +7790,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, int err) +void quicly_stream_noop_on_send_stop(quicly_stream_t *stream, quicly_error_t err) { } @@ -7755,7 +7798,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, int 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 e5c18438..2d8a69e7 100644 --- a/lib/recvstate.c +++ b/lib/recvstate.c @@ -41,10 +41,8 @@ void quicly_recvstate_dispose(quicly_recvstate_t *state) quicly_ranges_clear(&state->received); } -int 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) { - int ret; - assert(!quicly_recvstate_transfer_complete(state)); /* eos handling */ @@ -76,6 +74,7 @@ int quicly_recvstate_update(quicly_recvstate_t *state, uint64_t off, size_t *len /* update received range */ if (*len != 0) { + int ret; if ((ret = quicly_ranges_add(&state->received, off, off + *len)) != 0) return ret; if (state->received.num_ranges > max_ranges) @@ -91,7 +90,7 @@ int quicly_recvstate_update(quicly_recvstate_t *state, uint64_t off, size_t *len return 0; } -int 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 ff7f57c3..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 int 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,12 +123,13 @@ static size_t unregister_prior_to(quicly_remote_cid_set_t *set, uint64_t seq_unr return num_unregistered; } -int 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 */ - int ret; + quicly_error_t ret; assert(sequence >= retire_prior_to); diff --git a/lib/sentmap.c b/lib/sentmap.c index 64b2bfdd..71220f0d 100644 --- a/lib/sentmap.c +++ b/lib/sentmap.c @@ -92,7 +92,7 @@ void quicly_sentmap_dispose(quicly_sentmap_t *map) } } -int 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); } -int 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; - int 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 @@ int quicly_sentmap_update(quicly_sentmap_t *map, quicly_sentmap_iter_t *iter, qu return ret; } -int 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 9e4f4ed1..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, int 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; - int 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 int 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, int err) +void quicly_streambuf_destroy(quicly_stream_t *stream, quicly_error_t err) { quicly_streambuf_t *sbuf = stream->data; diff --git a/quicly-probes.d b/quicly-probes.d index a3967adc..90ac936b 100644 --- a/quicly-probes.d +++ b/quicly-probes.d @@ -55,7 +55,7 @@ provider quicly { probe promote_path(struct st_quicly_conn_t *conn, int64_t at, size_t path_index); probe elicit_path_migration(struct st_quicly_conn_t *conn, int64_t at, size_t path_index); - probe crypto_handshake(struct st_quicly_conn_t *conn, int64_t at, int ret); + probe crypto_handshake(struct st_quicly_conn_t *conn, int64_t at, int64_t ret); probe crypto_update_secret(struct st_quicly_conn_t *conn, int64_t at, int is_enc, uint8_t epoch, const char *label, const char *secret); probe crypto_send_key_update(struct st_quicly_conn_t *conn, int64_t at, uint64_t phase, const char *secret); probe crypto_send_key_update_confirmed(struct st_quicly_conn_t *conn, int64_t at, uint64_t next_pn); @@ -94,11 +94,11 @@ provider quicly { probe stream_acked(struct st_quicly_conn_t *conn, int64_t at, int64_t stream_id, uint64_t off, size_t len); probe stream_lost(struct st_quicly_conn_t *conn, int64_t at, int64_t stream_id, uint64_t off, size_t len); - probe reset_stream_send(struct st_quicly_conn_t *conn, int64_t at, int64_t stream_id, uint16_t error_code, uint64_t final_size); - probe reset_stream_receive(struct st_quicly_conn_t *conn, int64_t at, int64_t stream_id, uint16_t error_code, uint64_t final_size); + probe reset_stream_send(struct st_quicly_conn_t *conn, int64_t at, int64_t stream_id, int64_t error_code, uint64_t final_size); + probe reset_stream_receive(struct st_quicly_conn_t *conn, int64_t at, int64_t stream_id, int64_t error_code, uint64_t final_size); - probe stop_sending_send(struct st_quicly_conn_t *conn, int64_t at, int64_t stream_id, uint16_t error_code); - probe stop_sending_receive(struct st_quicly_conn_t *conn, int64_t at, int64_t stream_id, uint16_t error_code); + probe stop_sending_send(struct st_quicly_conn_t *conn, int64_t at, int64_t stream_id, int64_t error_code); + probe stop_sending_receive(struct st_quicly_conn_t *conn, int64_t at, int64_t stream_id, int64_t error_code); probe max_data_send(struct st_quicly_conn_t *conn, int64_t at, uint64_t maximum); probe max_data_receive(struct st_quicly_conn_t *conn, int64_t at, uint64_t maximum); @@ -153,14 +153,14 @@ provider quicly { probe quictrace_cc_lost(struct st_quicly_conn_t *conn, int64_t at, struct quicly_rtt_t *rtt, uint32_t cwnd, size_t inflight); probe stream_on_open(struct st_quicly_conn_t *conn, int64_t at, struct st_quicly_stream_t *stream); - probe stream_on_destroy(struct st_quicly_conn_t *conn, int64_t at, struct st_quicly_stream_t *stream, int err); + probe stream_on_destroy(struct st_quicly_conn_t *conn, int64_t at, struct st_quicly_stream_t *stream, int64_t err); probe stream_on_send_shift(struct st_quicly_conn_t *conn, int64_t at, struct st_quicly_stream_t *stream, size_t delta); probe stream_on_send_emit(struct st_quicly_conn_t *conn, int64_t at, struct st_quicly_stream_t *stream, size_t off, size_t capacity); - probe stream_on_send_stop(struct st_quicly_conn_t *conn, int64_t at, struct st_quicly_stream_t *stream, int err); + probe stream_on_send_stop(struct st_quicly_conn_t *conn, int64_t at, struct st_quicly_stream_t *stream, int64_t err); probe stream_on_receive(struct st_quicly_conn_t *conn, int64_t at, struct st_quicly_stream_t *stream, size_t off, const void *src, size_t src_len); - probe stream_on_receive_reset(struct st_quicly_conn_t *conn, int64_t at, struct st_quicly_stream_t *stream, int err); + probe stream_on_receive_reset(struct st_quicly_conn_t *conn, int64_t at, struct st_quicly_stream_t *stream, int64_t err); probe enter_cc_limited(struct st_quicly_conn_t *conn, int64_t at, uint64_t pn); probe exit_cc_limited(struct st_quicly_conn_t *conn, int64_t at, uint64_t pn); diff --git a/src/cli.c b/src/cli.c index 15ff179c..56d1f387 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, int err); -static void on_receive_reset(quicly_stream_t *stream, int 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 int 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 int 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,16 +316,16 @@ 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, int 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: %" PRIu16 "\n", QUICLY_ERROR_GET_ERROR_CODE(err)); + fprintf(stderr, "received STOP_SENDING: %" PRIu64 "\n", QUICLY_ERROR_GET_ERROR_CODE(err)); } -static void on_receive_reset(quicly_stream_t *stream, int 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: %" PRIu16 "\n", QUICLY_ERROR_GET_ERROR_CODE(err)); + fprintf(stderr, "received RESET_STREAM: %" PRIu64 "\n", QUICLY_ERROR_GET_ERROR_CODE(err)); } static void server_on_receive(quicly_stream_t *stream, size_t off, const void *src, size_t len) @@ -389,7 +389,7 @@ static void client_on_receive(quicly_stream_t *stream, size_t off, const void *s } } -static int 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) { int ret; @@ -401,28 +401,28 @@ static int on_stream_open(quicly_stream_open_t *self, quicly_stream_t *stream) 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, int 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)) { - fprintf(stderr, "transport close:code=0x%" PRIx16 ";frame=%" PRIu64 ";reason=%.*s\n", QUICLY_ERROR_GET_ERROR_CODE(err), + fprintf(stderr, "transport close:code=0x%" PRIx64 ";frame=%" PRIu64 ";reason=%.*s\n", QUICLY_ERROR_GET_ERROR_CODE(err), frame_type, (int)reason_len, reason); } else if (QUICLY_ERROR_IS_QUIC_APPLICATION(err)) { - fprintf(stderr, "application close:code=0x%" PRIx16 ";reason=%.*s\n", QUICLY_ERROR_GET_ERROR_CODE(err), (int)reason_len, + fprintf(stderr, "application close:code=0x%" PRIx64 ";reason=%.*s\n", QUICLY_ERROR_GET_ERROR_CODE(err), (int)reason_len, reason); } else if (err == QUICLY_ERROR_RECEIVED_STATELESS_RESET) { fprintf(stderr, "stateless reset\n"); } else if (err == QUICLY_ERROR_NO_COMPATIBLE_VERSION) { fprintf(stderr, "no compatible version\n"); } else { - fprintf(stderr, "unexpected close:code=%d\n", err); + fprintf(stderr, "unexpected close:code=%" PRId64 "\n", err); } } static quicly_closed_by_remote_t closed_by_remote = {&on_closed_by_remote}; -static int 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 int 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; - int 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; - int ret; + quicly_error_t ret; for (i = 0; reqs[i].path != NULL; ++i) { char req[1024], destfile[1024]; @@ -691,7 +691,7 @@ static void on_client_signal(int signo) static int run_client(int fd, struct sockaddr *sa, const char *host) { quicly_address_t local; - int ret; + quicly_error_t ret; quicly_conn_t *conn = NULL; signal(SIGTERM, on_client_signal); @@ -781,7 +781,7 @@ static int run_client(int fd, struct sockaddr *sa, const char *host) if (ret == QUICLY_ERROR_FREE_CONNECTION) { return 0; } else { - fprintf(stderr, "quicly_send returned %d\n", ret); + fprintf(stderr, "quicly_send returned %" PRId64 "\n", ret); return 1; } } @@ -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; - int 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 */ - int 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; - int 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 int 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); @@ -1160,7 +1161,7 @@ static int on_client_hello_cb(ptls_on_client_hello_t *_self, ptls_t *tls, ptls_o return 0; } -static int stream_has_more_to_send(void *unused, quicly_stream_t *stream) +static int64_t stream_has_more_to_send(void *unused, quicly_stream_t *stream) { int is_fully_inflight = !quicly_stream_has_send_side(0, stream->stream_id) || quicly_sendstate_is_fully_inflight(&stream->sendstate); @@ -1172,9 +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 int 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 ret, had_more_to_send = conn_has_more_to_send(conn); + int had_more_to_send = conn_has_more_to_send(conn); + 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/lossy.c b/t/lossy.c index 194e6106..6da2e3e8 100644 --- a/t/lossy.c +++ b/t/lossy.c @@ -102,17 +102,17 @@ static void init_cond_rand(struct loss_cond_t *cond, unsigned nloss, unsigned nt cond->data.rand_.ratio.ntotal = ntotal; } -static int transmit_cond(quicly_conn_t *src, quicly_conn_t *dst, size_t *num_sent, size_t *num_received, struct loss_cond_t *cond, - int64_t latency, ptls_buffer_t *logger) +static quicly_error_t transmit_cond(quicly_conn_t *src, quicly_conn_t *dst, size_t *num_sent, size_t *num_received, + struct loss_cond_t *cond, int64_t latency, ptls_buffer_t *logger) { quicly_address_t destaddr, srcaddr; struct iovec packets[32]; uint8_t packetsbuf[PTLS_ELEMENTSOF(packets) * quicly_get_context(src)->transport_params.max_udp_payload_size]; - int ret; + quicly_error_t ret; *num_sent = PTLS_ELEMENTSOF(packets); if ((ret = quicly_send(src, &destaddr, &srcaddr, packets, num_sent, packetsbuf, sizeof(packetsbuf))) != 0) { - fprintf(stderr, "%s: quicly_send: ret=%d\n", __FUNCTION__, ret); + fprintf(stderr, "%s: quicly_send: ret=%" PRId64 "\n", __FUNCTION__, ret); return ret; } quic_now += latency; @@ -137,7 +137,7 @@ static int transmit_cond(quicly_conn_t *src, quicly_conn_t *dst, size_t *num_sen if (pass) { ret = quicly_receive(dst, NULL, &fake_address.sa, decoded + j); if (!(ret == 0 || ret == QUICLY_ERROR_PACKET_IGNORED)) { - fprintf(stderr, "%s: quicly_receive: i=%zu, j=%zu, ret=%d\n", __FUNCTION__, i, j, ret); + fprintf(stderr, "%s: quicly_receive: i=%zu, j=%zu, ret=%" PRId64 "\n", __FUNCTION__, i, j, ret); return ret; } } @@ -160,7 +160,7 @@ static void test_even(void) quicly_loss_conf_t lossconf = QUICLY_LOSS_SPEC_CONF; struct loss_cond_t cond_down, cond_up; size_t num_sent, num_received; - int ret; + quicly_error_t ret; quic_ctx.loss = lossconf; init_cond_even(&cond_down); @@ -271,7 +271,7 @@ static unsigned num_failures_in_loss_core; static void loss_core(void) { size_t num_sent_up, num_sent_down, num_received; - int ret; + quicly_error_t ret; quic_now = 1; @@ -330,7 +330,7 @@ static void loss_core(void) if (quicly_get_state(client) == QUICLY_STATE_CONNECTED && quicly_connection_is_ready(client)) { if (client_stream == NULL) { if ((ret = quicly_open_stream(client, &client_stream, 0)) != 0) { - fprintf(stderr, "%s: quicly_open_stream: ret=%d\n", __FUNCTION__, ret); + fprintf(stderr, "%s: quicly_open_stream: ret=%" PRId64 "\n", __FUNCTION__, ret); goto Fail; } client_streambuf = client_stream->data; diff --git a/t/sentmap.c b/t/sentmap.c index 908b0592..6e5b4034 100644 --- a/t/sentmap.c +++ b/t/sentmap.c @@ -24,7 +24,7 @@ static int on_acked_callcnt, on_acked_ackcnt; -static int 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 40b70b69..ba507f4b 100644 --- a/t/simple.c +++ b/t/simple.c @@ -32,7 +32,8 @@ static void test_handshake(void) uint8_t packetsbuf[PTLS_ELEMENTSOF(packets) * quic_ctx.transport_params.max_udp_payload_size]; size_t num_packets, num_decoded; quicly_decoded_packet_t decoded[PTLS_ELEMENTSOF(packets) * 4]; - int ret, i; + int i; + quicly_error_t ret; /* send CH */ ret = quicly_connect(&client, &quic_ctx, "example.com", &fake_address.sa, NULL, new_master_id(), ptls_iovec_init(NULL, 0), NULL, @@ -115,7 +116,7 @@ static void simple_http(void) const char *req = "GET / HTTP/1.0\r\n\r\n", *resp = "HTTP/1.0 200 OK\r\n\r\nhello world"; quicly_stream_t *client_stream, *server_stream; test_streambuf_t *client_streambuf, *server_streambuf; - int ret; + quicly_error_t ret; ret = quicly_open_stream(client, &client_stream, 0); ok(ret == 0); @@ -159,7 +160,7 @@ static void test_reset_then_close(void) quicly_stream_t *client_stream, *server_stream; test_streambuf_t *client_streambuf, *server_streambuf; uint64_t stream_id; - int ret; + quicly_error_t ret; /* client sends STOP_SENDING and RESET_STREAM */ ret = quicly_open_stream(client, &client_stream, 0); @@ -201,7 +202,7 @@ static void test_send_then_close(void) { quicly_stream_t *client_stream, *server_stream; test_streambuf_t *client_streambuf, *server_streambuf; - int ret; + quicly_error_t ret; ret = quicly_open_stream(client, &client_stream, 0); ok(ret == 0); @@ -246,7 +247,7 @@ static void test_reset_after_close(void) { quicly_stream_t *client_stream, *server_stream; test_streambuf_t *client_streambuf, *server_streambuf; - int ret; + quicly_error_t ret; ret = quicly_open_stream(client, &client_stream, 0); ok(ret == 0); @@ -293,7 +294,7 @@ static void tiny_stream_window(void) quicly_stream_t *client_stream, *server_stream; test_streambuf_t *client_streambuf, *server_streambuf; quicly_stats_t stats; - int ret; + quicly_error_t ret; quic_ctx.transport_params.max_stream_data = (quicly_max_stream_data_t){4, 4, 4}; @@ -378,7 +379,7 @@ static void test_reset_during_loss(void) test_streambuf_t *client_streambuf, *server_streambuf; struct iovec reordered_packet; uint8_t reordered_packet_buf[quic_ctx.transport_params.max_udp_payload_size]; - int ret; + quicly_error_t ret; uint64_t max_data_at_start, tmp; quic_ctx.transport_params.max_stream_data = (quicly_max_stream_data_t){4, 4, 4}; @@ -460,7 +461,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, int 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 +479,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; - int ret; + quicly_error_t ret; quic_ctx.closed_by_remote = &closed_by_remote; @@ -532,7 +533,7 @@ static void tiny_connection_window(void) quicly_stream_t *client_stream, *server_stream; test_streambuf_t *client_streambuf, *server_streambuf; size_t i; - int ret; + quicly_error_t ret; char testdata[1025]; quic_ctx.transport_params.max_data = 1024; diff --git a/t/stream-concurrency.c b/t/stream-concurrency.c index fc4f534d..dd37a025 100644 --- a/t/stream-concurrency.c +++ b/t/stream-concurrency.c @@ -30,7 +30,7 @@ void test_stream_concurrency(void) quicly_stream_t *client_streams[limit + 2], *server_stream; test_streambuf_t *client_streambufs[limit + 1], *server_streambuf; size_t i; - int ret; + quicly_error_t ret; { /* connect */ quicly_address_t dest, src; diff --git a/t/test.c b/t/test.c index 05264c22..8f2375cb 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, int err); -static void on_egress_stop(quicly_stream_t *stream, int 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, int err); +static void on_ingress_reset(quicly_stream_t *stream, quicly_error_t err); quicly_address_t fake_address; int64_t quic_now = 1; @@ -98,6 +98,60 @@ quicly_stream_callbacks_t stream_callbacks = { on_destroy, quicly_streambuf_egress_shift, quicly_streambuf_egress_emit, on_egress_stop, on_ingress_receive, on_ingress_reset}; size_t on_destroy_callcnt; +static void test_error_codes(void) +{ + quicly_error_t a; + + a = QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0); + ok(QUICLY_ERROR_IS_QUIC(a)); + ok(QUICLY_ERROR_IS_QUIC_TRANSPORT(a)); + ok(!QUICLY_ERROR_IS_QUIC_APPLICATION(a)); + ok(QUICLY_ERROR_GET_ERROR_CODE(a) == 0); + + a = QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0x3fffffffffffffff); + ok(QUICLY_ERROR_IS_QUIC(a)); + ok(QUICLY_ERROR_IS_QUIC_TRANSPORT(a)); + ok(!QUICLY_ERROR_IS_QUIC_APPLICATION(a)); + ok(QUICLY_ERROR_GET_ERROR_CODE(a) == 0x3fffffffffffffff); + + a = QUICLY_ERROR_FROM_APPLICATION_ERROR_CODE(0); + ok(QUICLY_ERROR_IS_QUIC(a)); + ok(!QUICLY_ERROR_IS_QUIC_TRANSPORT(a)); + ok(QUICLY_ERROR_IS_QUIC_APPLICATION(a)); + ok(QUICLY_ERROR_GET_ERROR_CODE(a) == 0); + + a = QUICLY_ERROR_FROM_APPLICATION_ERROR_CODE(0x3fffffffffffffff); + ok(QUICLY_ERROR_IS_QUIC(a)); + ok(!QUICLY_ERROR_IS_QUIC_TRANSPORT(a)); + ok(QUICLY_ERROR_IS_QUIC_APPLICATION(a)); + ok(QUICLY_ERROR_GET_ERROR_CODE(a) == 0x3fffffffffffffff); + + a = 0; + ok(!QUICLY_ERROR_IS_QUIC(a)); + ok(!QUICLY_ERROR_IS_QUIC_TRANSPORT(a)); + ok(!QUICLY_ERROR_IS_QUIC_APPLICATION(a)); + + a = PTLS_ALERT_UNKNOWN_CA; /* arbitrary alert */ + ok(!QUICLY_ERROR_IS_QUIC(a)); + ok(!QUICLY_ERROR_IS_QUIC_TRANSPORT(a)); + ok(!QUICLY_ERROR_IS_QUIC_APPLICATION(a)); + + a = 0x2ffff; /* max outside QUIC errors */ + ok(!QUICLY_ERROR_IS_QUIC(a)); + ok(!QUICLY_ERROR_IS_QUIC_TRANSPORT(a)); + ok(!QUICLY_ERROR_IS_QUIC_APPLICATION(a)); + + a = (int64_t)0x8000000000030000; /* min outside QUIC errors */ + ok(!QUICLY_ERROR_IS_QUIC(a)); + ok(!QUICLY_ERROR_IS_QUIC_TRANSPORT(a)); + ok(!QUICLY_ERROR_IS_QUIC_APPLICATION(a)); + + a = QUICLY_ERROR_PACKET_IGNORED; /* arbrary internal error */ + ok(!QUICLY_ERROR_IS_QUIC(a)); + ok(!QUICLY_ERROR_IS_QUIC_TRANSPORT(a)); + ok(!QUICLY_ERROR_IS_QUIC_APPLICATION(a)); +} + static void test_adjust_stream_frame_layout(void) { #define TEST(_is_crypto, _capacity, check) \ @@ -169,14 +223,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, int 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, int 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 +242,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, int 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 +256,7 @@ const quicly_cid_plaintext_t *new_master_id(void) return &master; } -static int 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; @@ -393,7 +447,7 @@ size_t transmit(quicly_conn_t *src, quicly_conn_t *dst) uint8_t datagramsbuf[PTLS_ELEMENTSOF(datagrams) * quicly_get_context(src)->transport_params.max_udp_payload_size]; size_t num_datagrams, i; quicly_decoded_packet_t decoded[PTLS_ELEMENTSOF(datagrams) * 2]; - int ret; + quicly_error_t ret; num_datagrams = PTLS_ELEMENTSOF(datagrams); ret = quicly_send(src, &destaddr, &srcaddr, datagrams, &num_datagrams, datagramsbuf, sizeof(datagramsbuf)); @@ -633,7 +687,7 @@ static void test_nondecryptable_initial(void) struct iovec packet = {.iov_base = packetbuf, .iov_len = sizeof(packetbuf)}; size_t num_decoded; quicly_decoded_packet_t decoded; - int ret; + quicly_error_t ret; /* create an Initial packet, with its payload all set to zero */ memcpy(packetbuf, header, sizeof(header)); @@ -653,7 +707,7 @@ static void test_nondecryptable_initial(void) static void test_set_cc(void) { quicly_conn_t *conn; - int ret; + quicly_error_t ret; ret = quicly_connect(&conn, &quic_ctx, "example.com", &fake_address.sa, NULL, new_master_id(), ptls_iovec_init(NULL, 0), NULL, NULL, NULL); @@ -751,7 +805,7 @@ static void do_test_migration_during_handshake(int second_flight_from_orig_addre uint8_t buf[quic_ctx.transport_params.max_udp_payload_size * 10]; quicly_decoded_packet_t packets[40]; size_t num_datagrams, num_packets; - int ret; + quicly_error_t ret; /* client send first flight */ ret = quicly_connect(&client, &quic_ctx, "example.com", (void *)&serveraddr, NULL, new_master_id(), ptls_iovec_init(NULL, 0), @@ -872,6 +926,7 @@ int main(int argc, char **argv) quicly_amend_ptls_context(quic_ctx.tls); + subtest("error-codes", test_error_codes); subtest("next-packet-number", test_next_packet_number); subtest("address-token-codec", test_address_token_codec); subtest("ranges", test_ranges); diff --git a/t/test.h b/t/test.h index e3ea36c6..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 { - int stop_sending; - int reset_stream; + quicly_error_t stop_sending; + quicly_error_t reset_stream; } error_received; int is_detached; } test_streambuf_t;