Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 125 additions & 2 deletions deps/ngtcp2/nghttp3/lib/includes/nghttp3/nghttp3.h
Original file line number Diff line number Diff line change
Expand Up @@ -1961,7 +1961,7 @@ typedef int (*nghttp3_acked_stream_data)(nghttp3_conn *conn, int64_t stream_id,
/**
* @functypedef
*
* :type:`nghttp3_conn_stream_close` is a callback function which is
* :type:`nghttp3_stream_close` is a callback function which is
* invoked when a stream identified by |stream_id| is closed. QUIC
* application error code |app_error_code| indicates the reason of
* this closure.
Expand All @@ -1970,6 +1970,9 @@ typedef int (*nghttp3_acked_stream_data)(nghttp3_conn *conn, int64_t stream_id,
* Returning :macro:`NGHTTP3_ERR_CALLBACK_FAILURE` will return to the
* caller immediately. Any values other than 0 is treated as
* :macro:`NGHTTP3_ERR_CALLBACK_FAILURE`.
*
* .. seealso::
* :type:`nghttp3_stream_close2`
*/
typedef int (*nghttp3_stream_close)(nghttp3_conn *conn, int64_t stream_id,
uint64_t app_error_code,
Expand Down Expand Up @@ -2240,10 +2243,80 @@ typedef int (*nghttp3_recv_settings2)(nghttp3_conn *conn,
const nghttp3_proto_settings *settings,
void *conn_user_data);

/**
* @macrosection
*
* Stream close flags
*/

/**
* @macro
*
* :macro:`NGHTTP3_STREAM_CLOSE_FLAG_NONE` indicates no flag set.
*
* .. version-added:: 1.18.0
*/
#define NGHTTP3_STREAM_CLOSE_FLAG_NONE 0x00U

/**
* @macro
*
* :macro:`NGHTTP3_STREAM_CLOSE_FLAG_RX_APP_ERROR_CODE_SET` indicates
* that rx_app_error_code parameter is set.
*
* .. version-added:: 1.18.0
*/
#define NGHTTP3_STREAM_CLOSE_FLAG_RX_APP_ERROR_CODE_SET 0x01U

/**
* @macro
*
* :macro:`NGHTTP3_STREAM_CLOSE_FLAG_TX_APP_ERROR_CODE_SET` indicates
* that tx_app_error_code parameter is set.
*
* .. version-added:: 1.18.0
*/
#define NGHTTP3_STREAM_CLOSE_FLAG_TX_APP_ERROR_CODE_SET 0x02U

/**
* @functypedef
*
* :type:`nghttp3_stream_close2` is a callback function which is
* invoked when a stream identified by |stream_id| is closed. If
* :macro:`NGHTTP3_STREAM_CLOSE_FLAG_RX_APP_ERROR_CODE_SET` is set in
* |flags|, |rx_app_error_code| is the QUIC application error code
* that shut down the receiving side of the stream. If
* :macro:`NGHTTP3_STREAM_CLOSE_FLAG_TX_APP_ERROR_CODE_SET` is set in
* |flags|, |tx_app_error_code| is the QUIC application error code
* that shut down the sending side of the stream. No application code
* means that direction of stream is closed without any error.
*
* This callback should be used with `nghttp3_conn_close_stream2`. If
* `nghttp3_conn_close_stream` is used, the app_error_code is set to
* both |rx_app_error_code| and |tx_app_error_code|, and
* :macro:`NGHTTP3_STREAM_CLOSE_FLAG_RX_APP_ERROR_CODE_SET` and
* :macro:`NGHTTP3_STREAM_CLOSE_FLAG_TX_APP_ERROR_CODE_SET` are set in
* |flags|.
*
* The implementation of this callback must return 0 if it succeeds.
* Returning :macro:`NGHTTP3_ERR_CALLBACK_FAILURE` will return to the
* caller immediately. Any values other than 0 is treated as
* :macro:`NGHTTP3_ERR_CALLBACK_FAILURE`.
*
* .. version-added:: 1.18.0
*/
typedef int (*nghttp3_stream_close2)(nghttp3_conn *conn, uint32_t flags,
int64_t stream_id,
uint64_t rx_app_error_code,
uint64_t tx_app_error_code,
void *conn_user_data,
void *stream_user_data);

#define NGHTTP3_CALLBACKS_V1 1
#define NGHTTP3_CALLBACKS_V2 2
#define NGHTTP3_CALLBACKS_V3 3
#define NGHTTP3_CALLBACKS_VERSION NGHTTP3_CALLBACKS_V3
#define NGHTTP3_CALLBACKS_V4 4
#define NGHTTP3_CALLBACKS_VERSION NGHTTP3_CALLBACKS_V4

/**
* @struct
Expand All @@ -2260,6 +2333,9 @@ typedef struct nghttp3_callbacks {
/**
* :member:`stream_close` is a callback function which is invoked
* when a particular stream has closed.
*
* .. seealso::
* :member:`stream_close2`
*/
nghttp3_stream_close stream_close;
/**
Expand Down Expand Up @@ -2368,13 +2444,24 @@ typedef struct nghttp3_callbacks {
* .. version-added:: 1.11.0
*/
nghttp3_rand rand;
/* The following fields have been added since
NGHTTP3_CALLBACKS_V3. */
/**
* :member:`recv_settings2` is a callback function which is invoked
* when SETTINGS frame is received.
*
* .. version-added:: 1.14.0
*/
nghttp3_recv_settings2 recv_settings2;
/* The following fields have been added since
NGHTTP3_CALLBACKS_V4. */
/**
* :member:`stream_close2` is a callback function which is invoked
* when a particular stream has closed.
*
* .. version-added:: 1.18.0
*/
nghttp3_stream_close2 stream_close2;
} nghttp3_callbacks;

/**
Expand Down Expand Up @@ -2837,11 +2924,47 @@ NGHTTP3_EXTERN int nghttp3_conn_resume_stream(nghttp3_conn *conn,
* A critical stream is closed.
* :macro:`NGHTTP3_ERR_CALLBACK_FAILURE`
* User callback failed
*
* .. seealso::
* `nghttp3_conn_close_stream2`
*/
NGHTTP3_EXTERN int nghttp3_conn_close_stream(nghttp3_conn *conn,
int64_t stream_id,
uint64_t app_error_code);

/**
* @function
*
* `nghttp3_conn_close_stream2` tells the library that a stream
* identified by |stream_id| has been closed. If
* :macro:`NGHTTP3_STREAM_CLOSE_FLAG_RX_APP_ERROR_CODE_SET` is set in
* |flags|, |rx_app_error_code| is the QUIC application error code
* that shut down the receiving side of the stream. Similarly,
* :macro:`NGHTTP3_STREAM_CLOSE_FLAG_TX_APP_ERROR_CODE_SET` is set in
* |flags|, |tx_app_error_code| is the QUIC application error code
* that shut down the sending side of the stream.
*
* For stream close callback, prefer
* :member:`nghttp3_callbacks.stream_close2` to
* :member:`nghttp3_callbacks.stream_close`.
*
* This function returns 0 if it succeeds, or one of the following
* negative error codes:
*
* :macro:`NGHTTP3_ERR_STREAM_NOT_FOUND`
* Stream not found.
* :macro:`NGHTTP3_ERR_H3_CLOSED_CRITICAL_STREAM`
* A critical stream is closed.
* :macro:`NGHTTP3_ERR_CALLBACK_FAILURE`
* User callback failed
*
* .. version-added:: 1.18.0
*/
NGHTTP3_EXTERN int nghttp3_conn_close_stream2(nghttp3_conn *conn,
uint32_t flags, int64_t stream_id,
uint64_t rx_app_error_code,
uint64_t tx_app_error_code);

/**
* @macrosection
*
Expand Down
4 changes: 2 additions & 2 deletions deps/ngtcp2/nghttp3/lib/includes/nghttp3/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*
* Version number of the nghttp3 library release.
*/
#define NGHTTP3_VERSION "1.17.0"
#define NGHTTP3_VERSION "1.18.0"

/**
* @macro
Expand All @@ -41,6 +41,6 @@
* number, 8 bits for minor and 8 bits for patch. Version 1.2.3
* becomes 0x010203.
*/
#define NGHTTP3_VERSION_NUM 0x011100
#define NGHTTP3_VERSION_NUM 0x011200

#endif /* !defined(NGHTTP3_VERSION_H) */
3 changes: 3 additions & 0 deletions deps/ngtcp2/nghttp3/lib/nghttp3_callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ size_t nghttp3_callbackslen_version(int callbacks_version) {
switch (callbacks_version) {
case NGHTTP3_CALLBACKS_VERSION:
return sizeof(callbacks);
case NGHTTP3_CALLBACKS_V3:
return offsetof(nghttp3_callbacks, recv_settings2) +
sizeof(callbacks.recv_settings2);
case NGHTTP3_CALLBACKS_V2:
return offsetof(nghttp3_callbacks, rand) + sizeof(callbacks.rand);
case NGHTTP3_CALLBACKS_V1:
Expand Down
51 changes: 42 additions & 9 deletions deps/ngtcp2/nghttp3/lib/nghttp3_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,9 @@ static nghttp3_ssize conn_read_type(nghttp3_conn *conn, nghttp3_stream *stream,
return nread;
}

static int conn_delete_stream(nghttp3_conn *conn, nghttp3_stream *stream);
static int conn_delete_stream(nghttp3_conn *conn, nghttp3_stream *stream,
uint32_t flags, uint64_t rx_app_error_code,
uint64_t tx_app_error_code);

nghttp3_ssize nghttp3_conn_read_uni(nghttp3_conn *conn, nghttp3_stream *stream,
const uint8_t *src, size_t srclen, int fin,
Expand All @@ -649,7 +651,8 @@ nghttp3_ssize nghttp3_conn_read_uni(nghttp3_conn *conn, nghttp3_stream *stream,
return NGHTTP3_ERR_H3_EXCESSIVE_LOAD;
}

return conn_delete_stream(conn, stream);
return conn_delete_stream(conn, stream, NGHTTP3_STREAM_CLOSE_FLAG_NONE, 0,
0);
}
nread = conn_read_type(conn, stream, src, srclen, fin);
if (nread < 0) {
Expand Down Expand Up @@ -1200,7 +1203,7 @@ nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn,
for (; conn->rx.originlen_offset < sizeof(conn->rx.originlen) &&
(size_t)nread < len;
++conn->rx.originlen_offset, ++nread) {
conn->rx.originlen <<= 8;
conn->rx.originlen *= 256;
conn->rx.originlen += *p++;
}

Expand Down Expand Up @@ -1335,8 +1338,11 @@ nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn,
return (nghttp3_ssize)nconsumed;
}

static int conn_delete_stream(nghttp3_conn *conn, nghttp3_stream *stream) {
static int conn_delete_stream(nghttp3_conn *conn, nghttp3_stream *stream,
uint32_t flags, uint64_t rx_app_error_code,
uint64_t tx_app_error_code) {
int rv;
uint64_t app_error_code;

rv = conn_call_deferred_consume(conn, stream,
nghttp3_stream_get_buffered_datalen(stream));
Expand All @@ -1353,8 +1359,26 @@ static int conn_delete_stream(nghttp3_conn *conn, nghttp3_stream *stream) {
}
}

if (conn->callbacks.stream_close) {
rv = conn->callbacks.stream_close(conn, stream->node.id, stream->error_code,
if (conn->callbacks.stream_close2) {
rv = conn->callbacks.stream_close2(conn, flags, stream->node.id,
rx_app_error_code, tx_app_error_code,
conn->user_data, stream->user_data);
if (rv != 0) {
return NGHTTP3_ERR_CALLBACK_FAILURE;
}
} else if (conn->callbacks.stream_close) {
app_error_code = NGHTTP3_H3_NO_ERROR;

if (flags & NGHTTP3_STREAM_CLOSE_FLAG_RX_APP_ERROR_CODE_SET) {
app_error_code = rx_app_error_code;
}

if (app_error_code == NGHTTP3_H3_NO_ERROR &&
(flags & NGHTTP3_STREAM_CLOSE_FLAG_TX_APP_ERROR_CODE_SET)) {
app_error_code = tx_app_error_code;
}

rv = conn->callbacks.stream_close(conn, stream->node.id, app_error_code,
conn->user_data, stream->user_data);
if (rv != 0) {
return NGHTTP3_ERR_CALLBACK_FAILURE;
Expand Down Expand Up @@ -2725,6 +2749,16 @@ int nghttp3_conn_resume_stream(nghttp3_conn *conn, int64_t stream_id) {

int nghttp3_conn_close_stream(nghttp3_conn *conn, int64_t stream_id,
uint64_t app_error_code) {
return nghttp3_conn_close_stream2(
conn,
NGHTTP3_STREAM_CLOSE_FLAG_RX_APP_ERROR_CODE_SET |
NGHTTP3_STREAM_CLOSE_FLAG_TX_APP_ERROR_CODE_SET,
stream_id, app_error_code, app_error_code);
}

int nghttp3_conn_close_stream2(nghttp3_conn *conn, uint32_t flags,
int64_t stream_id, uint64_t rx_app_error_code,
uint64_t tx_app_error_code) {
nghttp3_stream *stream = nghttp3_conn_find_stream(conn, stream_id);

if (stream == NULL) {
Expand All @@ -2736,11 +2770,10 @@ int nghttp3_conn_close_stream(nghttp3_conn *conn, int64_t stream_id,
return NGHTTP3_ERR_H3_CLOSED_CRITICAL_STREAM;
}

stream->error_code = app_error_code;

nghttp3_conn_unschedule_stream(conn, stream);

return conn_delete_stream(conn, stream);
return conn_delete_stream(conn, stream, flags, rx_app_error_code,
tx_app_error_code);
}

int nghttp3_conn_shutdown_stream_read(nghttp3_conn *conn, int64_t stream_id) {
Expand Down
22 changes: 12 additions & 10 deletions deps/ngtcp2/nghttp3/lib/nghttp3_ksl.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ static nghttp3_ksl_blk null_blk;

nghttp3_objalloc_def(ksl_blk, nghttp3_ksl_blk, oplent)

#define NGHTTP3_KSL_ALIGNED_BLKLEN \
((sizeof(nghttp3_ksl_blk) + 0x7U) & ~(size_t)0x7U)

static size_t ksl_blklen(size_t aligned_keylen) {
return sizeof(nghttp3_ksl_blk) + NGHTTP3_KSL_MAX_NBLK * aligned_keylen;
return NGHTTP3_KSL_ALIGNED_BLKLEN + NGHTTP3_KSL_MAX_NBLK * aligned_keylen;
}

/*
Expand Down Expand Up @@ -80,7 +83,7 @@ static nghttp3_ksl_blk *ksl_blk_objalloc_new(nghttp3_ksl *ksl) {
return NULL;
}

blk->keys = (uint8_t *)blk + sizeof(*blk);
blk->keys = (uint8_t *)blk + NGHTTP3_KSL_ALIGNED_BLKLEN;
blk->aligned_keylen = (uint16_t)ksl->aligned_keylen;

return blk;
Expand Down Expand Up @@ -223,22 +226,21 @@ static int ksl_split_node(nghttp3_ksl *ksl, nghttp3_ksl_blk *blk, size_t i) {
* Out of memory.
*/
static int ksl_split_root(nghttp3_ksl *ksl) {
nghttp3_ksl_blk *rblk = NULL, *lblk, *nroot = NULL;
nghttp3_ksl_blk *rblk, *lblk, *nroot;

nroot = ksl_blk_objalloc_new(ksl);
if (nroot == NULL) {
return NGHTTP3_ERR_NOMEM;
}

rblk = ksl_split_blk(ksl, ksl->root);
if (rblk == NULL) {
ksl_blk_objalloc_del(ksl, nroot);
return NGHTTP3_ERR_NOMEM;
}

lblk = ksl->root;

nroot = ksl_blk_objalloc_new(ksl);

if (nroot == NULL) {
ksl_blk_objalloc_del(ksl, rblk);
return NGHTTP3_ERR_NOMEM;
}

nroot->next = nroot->prev = NULL;
nroot->n = 2;
nroot->leaf = 0;
Expand Down
Loading
Loading