Skip to content

Commit

Permalink
it works?
Browse files Browse the repository at this point in the history
  • Loading branch information
kazuho committed Jan 10, 2025
1 parent f336bd8 commit 189d1c0
Show file tree
Hide file tree
Showing 22 changed files with 352 additions and 306 deletions.
56 changes: 28 additions & 28 deletions include/quicly.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ typedef struct st_quicly_stream_scheduler_t {
* Called by quicly to emit stream data. The scheduler should repeatedly choose a stream and call `quicly_send_stream` until
* `quicly_can_send_stream` returns false.
*/
int (*do_send)(struct st_quicly_stream_scheduler_t *sched, quicly_conn_t *conn, quicly_send_context_t *s);
int64_t (*do_send)(struct st_quicly_stream_scheduler_t *sched, quicly_conn_t *conn, quicly_send_context_t *s);
/**
*
*/
Expand All @@ -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, int64_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
Expand Down Expand Up @@ -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, int64_t err);
/**
* called whenever data can be retired from the send buffer, specifying the amount that can be newly removed
*/
Expand All @@ -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, int64_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
Expand All @@ -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, int64_t err);
} quicly_stream_callbacks_t;

struct st_quicly_stream_t {
Expand Down Expand Up @@ -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);
int64_t quicly_close(quicly_conn_t *conn, int64_t err, const char *reason_phrase);
/**
*
*/
Expand Down Expand Up @@ -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);
int64_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
Expand Down Expand Up @@ -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);
int64_t quicly_send(quicly_conn_t *conn, quicly_address_t *dest, quicly_address_t *src, struct iovec *datagrams,
size_t *num_datagrams, void *buf, size_t bufsize);
/**
* returns ECN bits to be set for the packets built by the last invocation of `quicly_send`
*/
Expand All @@ -1183,7 +1183,7 @@ int 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);
int64_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
*/
Expand Down Expand Up @@ -1214,18 +1214,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);
int64_t quicly_decode_transport_parameter_list(quicly_transport_parameters_t *params, quicly_cid_t *original_dcid,
quicly_cid_t *initial_scid, quicly_cid_t *retry_scid, void *stateless_reset_token,
const uint8_t *src, const uint8_t *end);
/**
* 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);
int64_t quicly_connect(quicly_conn_t **conn, quicly_context_t *ctx, const char *server_name, struct sockaddr *dest_addr,
struct sockaddr *src_addr, const quicly_cid_plaintext_t *new_cid, ptls_iovec_t address_token,
ptls_handshake_properties_t *handshake_properties,
const quicly_transport_parameters_t *resumed_transport_params, void *appdata);
/**
* 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
Expand All @@ -1236,9 +1236,9 @@ 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);
int64_t quicly_accept(quicly_conn_t **conn, quicly_context_t *ctx, struct sockaddr *dest_addr, struct sockaddr *src_addr,
quicly_decoded_packet_t *packet, quicly_address_token_plaintext_t *address_token,
const quicly_cid_plaintext_t *new_cid, ptls_handshake_properties_t *handshake_properties, void *appdata);
/**
*
*/
Expand Down Expand Up @@ -1273,15 +1273,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);
int64_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, int64_t err);
/**
*
*/
void quicly_request_stop(quicly_stream_t *stream, int err);
void quicly_request_stop(quicly_stream_t *stream, int64_t err);
/**
*
*/
Expand Down Expand Up @@ -1355,8 +1355,8 @@ int quicly_encrypt_address_token(void (*random_bytes)(void *, size_t), ptls_aead
* 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);
int64_t quicly_decrypt_address_token(ptls_aead_context_t *aead, quicly_address_token_plaintext_t *plaintext, const void *src,
size_t len, size_t prefix_len, const char **err_desc);
/**
* 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.
Expand All @@ -1381,7 +1381,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, int64_t err);
/**
*
*/
Expand All @@ -1393,15 +1393,15 @@ 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, int64_t err);
/**
*
*/
void quicly_stream_noop_on_receive(quicly_stream_t *stream, size_t off, const void *src, size_t len);
/**
*
*/
void quicly_stream_noop_on_receive_reset(quicly_stream_t *stream, int err);
void quicly_stream_noop_on_receive_reset(quicly_stream_t *stream, int64_t err);

extern const quicly_stream_callbacks_t quicly_stream_noop_callbacks;

Expand Down
15 changes: 8 additions & 7 deletions include/quicly/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,14 @@ 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)
/* picotls error codes (of type int) use 0x00000000xxxxxxxx, while QUIC application error codes use 0b01yyyy... and QUIC protocol
* error codes use 0b11yyyy..., where yyyy is a 62-bit QUIC integer */
#define QUICLY_ERROR_IS_QUIC(e) (((int64_t)(e) & 0x4000000000000000) != 0)
#define QUICLY_ERROR_IS_QUIC_TRANSPORT(e) (((int64_t)(e) & 0xc000000000000000) == 0x8000000000000000)
#define QUICLY_ERROR_IS_QUIC_APPLICATION(e) (((int64_t)(e) & 0xc000000000000000) == 0x4000000000000000)
#define QUICLY_ERROR_GET_ERROR_CODE(e) ((uint64_t)((int64_t)(e) & 0x3fffffffffffffff))
#define QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(e) ((int64_t)((int64_t)(e) | 0x8000000000000000))
#define QUICLY_ERROR_FROM_APPLICATION_ERROR_CODE(e) ((int64_t)((int64_t)(e) | 0x4000000000000000))
/**
* 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.
Expand Down
Loading

0 comments on commit 189d1c0

Please sign in to comment.