mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
deps: update ngtcp2 and nghttp3
PR-URL: https://github.com/nodejs/node/pull/51291 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
This commit is contained in:
1 parent
07f3df4453
commit
86ca72a4f0
92 files changed
+10586
-8813
No files matched your search
+531
-266
File diff suppressed because it is too large.
Load diff
+201
-120
@@ -33,11 +33,14 @@
|
||||
#include "nghttp3_err.h"
|
||||
#include "nghttp3_conv.h"
|
||||
#include "nghttp3_http.h"
|
||||
#include "nghttp3_unreachable.h"
|
||||
|
||||
/* NGHTTP3_QPACK_ENCODER_MAX_DTABLE_CAPACITY is the upper bound of the
|
||||
dynamic table capacity that QPACK encoder is willing to use. */
|
||||
#define NGHTTP3_QPACK_ENCODER_MAX_DTABLE_CAPACITY 4096
|
||||
|
||||
nghttp3_objalloc_def(chunk, nghttp3_chunk, oplent);
|
||||
|
||||
/*
|
||||
* conn_remote_stream_uni returns nonzero if |stream_id| is remote
|
||||
* unidirectional stream ID.
|
||||
@@ -56,7 +59,7 @@ static int conn_call_begin_headers(nghttp3_conn *conn, nghttp3_stream *stream) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
rv = conn->callbacks.begin_headers(conn, stream->node.nid.id, conn->user_data,
|
||||
rv = conn->callbacks.begin_headers(conn, stream->node.id, conn->user_data,
|
||||
stream->user_data);
|
||||
if (rv != 0) {
|
||||
/* TODO Allow ignore headers */
|
||||
@@ -74,8 +77,8 @@ static int conn_call_end_headers(nghttp3_conn *conn, nghttp3_stream *stream,
|
||||
return 0;
|
||||
}
|
||||
|
||||
rv = conn->callbacks.end_headers(conn, stream->node.nid.id, fin,
|
||||
conn->user_data, stream->user_data);
|
||||
rv = conn->callbacks.end_headers(conn, stream->node.id, fin, conn->user_data,
|
||||
stream->user_data);
|
||||
if (rv != 0) {
|
||||
/* TODO Allow ignore headers */
|
||||
return NGHTTP3_ERR_CALLBACK_FAILURE;
|
||||
@@ -92,8 +95,8 @@ static int conn_call_begin_trailers(nghttp3_conn *conn,
|
||||
return 0;
|
||||
}
|
||||
|
||||
rv = conn->callbacks.begin_trailers(conn, stream->node.nid.id,
|
||||
conn->user_data, stream->user_data);
|
||||
rv = conn->callbacks.begin_trailers(conn, stream->node.id, conn->user_data,
|
||||
stream->user_data);
|
||||
if (rv != 0) {
|
||||
/* TODO Allow ignore headers */
|
||||
return NGHTTP3_ERR_CALLBACK_FAILURE;
|
||||
@@ -110,8 +113,8 @@ static int conn_call_end_trailers(nghttp3_conn *conn, nghttp3_stream *stream,
|
||||
return 0;
|
||||
}
|
||||
|
||||
rv = conn->callbacks.end_trailers(conn, stream->node.nid.id, fin,
|
||||
conn->user_data, stream->user_data);
|
||||
rv = conn->callbacks.end_trailers(conn, stream->node.id, fin, conn->user_data,
|
||||
stream->user_data);
|
||||
if (rv != 0) {
|
||||
/* TODO Allow ignore headers */
|
||||
return NGHTTP3_ERR_CALLBACK_FAILURE;
|
||||
@@ -127,7 +130,7 @@ static int conn_call_end_stream(nghttp3_conn *conn, nghttp3_stream *stream) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
rv = conn->callbacks.end_stream(conn, stream->node.nid.id, conn->user_data,
|
||||
rv = conn->callbacks.end_stream(conn, stream->node.id, conn->user_data,
|
||||
stream->user_data);
|
||||
if (rv != 0) {
|
||||
return NGHTTP3_ERR_CALLBACK_FAILURE;
|
||||
@@ -144,7 +147,7 @@ static int conn_call_stop_sending(nghttp3_conn *conn, nghttp3_stream *stream,
|
||||
return 0;
|
||||
}
|
||||
|
||||
rv = conn->callbacks.stop_sending(conn, stream->node.nid.id, app_error_code,
|
||||
rv = conn->callbacks.stop_sending(conn, stream->node.id, app_error_code,
|
||||
conn->user_data, stream->user_data);
|
||||
if (rv != 0) {
|
||||
return NGHTTP3_ERR_CALLBACK_FAILURE;
|
||||
@@ -161,7 +164,7 @@ static int conn_call_reset_stream(nghttp3_conn *conn, nghttp3_stream *stream,
|
||||
return 0;
|
||||
}
|
||||
|
||||
rv = conn->callbacks.reset_stream(conn, stream->node.nid.id, app_error_code,
|
||||
rv = conn->callbacks.reset_stream(conn, stream->node.id, app_error_code,
|
||||
conn->user_data, stream->user_data);
|
||||
if (rv != 0) {
|
||||
return NGHTTP3_ERR_CALLBACK_FAILURE;
|
||||
@@ -179,7 +182,7 @@ static int conn_call_deferred_consume(nghttp3_conn *conn,
|
||||
return 0;
|
||||
}
|
||||
|
||||
rv = conn->callbacks.deferred_consume(conn, stream->node.nid.id, nconsumed,
|
||||
rv = conn->callbacks.deferred_consume(conn, stream->node.id, nconsumed,
|
||||
conn->user_data, stream->user_data);
|
||||
if (rv != 0) {
|
||||
return NGHTTP3_ERR_CALLBACK_FAILURE;
|
||||
@@ -188,6 +191,22 @@ static int conn_call_deferred_consume(nghttp3_conn *conn,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int conn_call_recv_settings(nghttp3_conn *conn) {
|
||||
int rv;
|
||||
|
||||
if (!conn->callbacks.recv_settings) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
rv = conn->callbacks.recv_settings(conn, &conn->remote.settings,
|
||||
conn->user_data);
|
||||
if (rv != 0) {
|
||||
return NGHTTP3_ERR_CALLBACK_FAILURE;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ricnt_less(const nghttp3_pq_entry *lhsx,
|
||||
const nghttp3_pq_entry *rhsx) {
|
||||
nghttp3_stream *lhs =
|
||||
@@ -204,7 +223,7 @@ static int cycle_less(const nghttp3_pq_entry *lhsx,
|
||||
const nghttp3_tnode *rhs = nghttp3_struct_of(rhsx, nghttp3_tnode, pe);
|
||||
|
||||
if (lhs->cycle == rhs->cycle) {
|
||||
return lhs->seq < rhs->seq;
|
||||
return lhs->id < rhs->id;
|
||||
}
|
||||
|
||||
return rhs->cycle - lhs->cycle <= NGHTTP3_TNODE_MAX_CYCLE_GAP;
|
||||
@@ -264,7 +283,6 @@ static int conn_new(nghttp3_conn **pconn, int server, int callbacks_version,
|
||||
nghttp3_settings_default(&conn->remote.settings);
|
||||
conn->mem = mem;
|
||||
conn->user_data = user_data;
|
||||
conn->next_seq = 0;
|
||||
conn->server = server;
|
||||
conn->rx.goaway_id = NGHTTP3_VARINT_MAX + 1;
|
||||
conn->tx.goaway_id = NGHTTP3_VARINT_MAX + 1;
|
||||
@@ -454,12 +472,6 @@ nghttp3_ssize nghttp3_conn_read_stream(nghttp3_conn *conn, int64_t stream_id,
|
||||
stream->tx.hstate = NGHTTP3_HTTP_STATE_REQ_INITIAL;
|
||||
}
|
||||
}
|
||||
} else if (nghttp3_stream_uni(stream_id) &&
|
||||
stream->type == NGHTTP3_STREAM_TYPE_PUSH) {
|
||||
if (stream->rx.hstate == NGHTTP3_HTTP_STATE_NONE) {
|
||||
stream->rx.hstate = NGHTTP3_HTTP_STATE_RESP_INITIAL;
|
||||
stream->tx.hstate = NGHTTP3_HTTP_STATE_RESP_INITIAL;
|
||||
}
|
||||
}
|
||||
|
||||
if (srclen == 0 && !fin) {
|
||||
@@ -603,8 +615,7 @@ nghttp3_ssize nghttp3_conn_read_uni(nghttp3_conn *conn, nghttp3_stream *stream,
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/* unreachable */
|
||||
assert(0);
|
||||
nghttp3_unreachable();
|
||||
}
|
||||
|
||||
if (nconsumed < 0) {
|
||||
@@ -686,6 +697,11 @@ nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn,
|
||||
case NGHTTP3_FRAME_SETTINGS:
|
||||
/* SETTINGS frame might be empty. */
|
||||
if (rstate->left == 0) {
|
||||
rv = conn_call_recv_settings(conn);
|
||||
if (rv != 0) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nghttp3_stream_read_state_reset(rstate);
|
||||
break;
|
||||
}
|
||||
@@ -735,11 +751,21 @@ nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn,
|
||||
}
|
||||
break;
|
||||
case NGHTTP3_CTRL_STREAM_STATE_SETTINGS:
|
||||
for (; p != end;) {
|
||||
for (;;) {
|
||||
if (rstate->left == 0) {
|
||||
rv = conn_call_recv_settings(conn);
|
||||
if (rv != 0) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nghttp3_stream_read_state_reset(rstate);
|
||||
break;
|
||||
}
|
||||
|
||||
if (p == end) {
|
||||
return (nghttp3_ssize)nconsumed;
|
||||
}
|
||||
|
||||
/* Read Identifier */
|
||||
len = (size_t)nghttp3_min(rstate->left, (int64_t)(end - p));
|
||||
assert(len > 0);
|
||||
@@ -845,6 +871,11 @@ nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn,
|
||||
break;
|
||||
}
|
||||
|
||||
rv = conn_call_recv_settings(conn);
|
||||
if (rv != 0) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nghttp3_stream_read_state_reset(rstate);
|
||||
break;
|
||||
case NGHTTP3_CTRL_STREAM_STATE_GOAWAY:
|
||||
@@ -1013,8 +1044,7 @@ nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn,
|
||||
nghttp3_stream_read_state_reset(rstate);
|
||||
break;
|
||||
default:
|
||||
/* unreachable */
|
||||
assert(0);
|
||||
nghttp3_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1022,7 +1052,7 @@ nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn,
|
||||
}
|
||||
|
||||
static int conn_delete_stream(nghttp3_conn *conn, nghttp3_stream *stream) {
|
||||
int bidi = nghttp3_client_stream_bidi(stream->node.nid.id);
|
||||
int bidi = nghttp3_client_stream_bidi(stream->node.id);
|
||||
int rv;
|
||||
|
||||
rv = conn_call_deferred_consume(conn, stream,
|
||||
@@ -1032,16 +1062,21 @@ static int conn_delete_stream(nghttp3_conn *conn, nghttp3_stream *stream) {
|
||||
}
|
||||
|
||||
if (bidi && conn->callbacks.stream_close) {
|
||||
rv = conn->callbacks.stream_close(conn, stream->node.nid.id,
|
||||
stream->error_code, conn->user_data,
|
||||
stream->user_data);
|
||||
rv = conn->callbacks.stream_close(conn, stream->node.id, stream->error_code,
|
||||
conn->user_data, stream->user_data);
|
||||
if (rv != 0) {
|
||||
return NGHTTP3_ERR_CALLBACK_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
rv = nghttp3_map_remove(&conn->streams,
|
||||
(nghttp3_map_key_type)stream->node.nid.id);
|
||||
if (conn->server && nghttp3_client_stream_bidi(stream->node.id)) {
|
||||
assert(conn->remote.bidi.num_streams > 0);
|
||||
|
||||
--conn->remote.bidi.num_streams;
|
||||
}
|
||||
|
||||
rv =
|
||||
nghttp3_map_remove(&conn->streams, (nghttp3_map_key_type)stream->node.id);
|
||||
|
||||
assert(0 == rv);
|
||||
|
||||
@@ -1058,7 +1093,7 @@ static int conn_process_blocked_stream_data(nghttp3_conn *conn,
|
||||
int rv;
|
||||
size_t len;
|
||||
|
||||
assert(nghttp3_client_stream_bidi(stream->node.nid.id));
|
||||
assert(nghttp3_client_stream_bidi(stream->node.id));
|
||||
|
||||
for (;;) {
|
||||
len = nghttp3_ringbuf_len(&stream->inq);
|
||||
@@ -1149,16 +1184,17 @@ static nghttp3_tnode *stream_get_sched_node(nghttp3_stream *stream) {
|
||||
}
|
||||
|
||||
static int conn_update_stream_priority(nghttp3_conn *conn,
|
||||
nghttp3_stream *stream, uint8_t pri) {
|
||||
assert(nghttp3_client_stream_bidi(stream->node.nid.id));
|
||||
nghttp3_stream *stream,
|
||||
const nghttp3_pri *pri) {
|
||||
assert(nghttp3_client_stream_bidi(stream->node.id));
|
||||
|
||||
if (stream->node.pri == pri) {
|
||||
if (nghttp3_pri_eq(&stream->node.pri, pri)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
nghttp3_conn_unschedule_stream(conn, stream);
|
||||
|
||||
stream->node.pri = pri;
|
||||
stream->node.pri = *pri;
|
||||
|
||||
if (nghttp3_stream_require_schedule(stream)) {
|
||||
return nghttp3_conn_schedule_stream(conn, stream);
|
||||
@@ -1286,8 +1322,7 @@ nghttp3_ssize nghttp3_conn_read_bidi(nghttp3_conn *conn, size_t *pnproc,
|
||||
rv = conn_call_begin_trailers(conn, stream);
|
||||
break;
|
||||
default:
|
||||
/* Unreachable */
|
||||
assert(0);
|
||||
nghttp3_unreachable();
|
||||
}
|
||||
|
||||
if (rv != 0) {
|
||||
@@ -1377,9 +1412,7 @@ nghttp3_ssize nghttp3_conn_read_bidi(nghttp3_conn *conn, size_t *pnproc,
|
||||
rv = 0;
|
||||
break;
|
||||
default:
|
||||
/* Unreachable */
|
||||
assert(0);
|
||||
abort();
|
||||
nghttp3_unreachable();
|
||||
}
|
||||
|
||||
if (rv != 0) {
|
||||
@@ -1398,7 +1431,7 @@ nghttp3_ssize nghttp3_conn_read_bidi(nghttp3_conn *conn, size_t *pnproc,
|
||||
(stream->rx.http.flags & NGHTTP3_HTTP_FLAG_PRIORITY) &&
|
||||
!(stream->flags & NGHTTP3_STREAM_FLAG_PRIORITY_UPDATE_RECVED) &&
|
||||
!(stream->flags & NGHTTP3_STREAM_FLAG_SERVER_PRIORITY_SET)) {
|
||||
rv = conn_update_stream_priority(conn, stream, stream->rx.http.pri);
|
||||
rv = conn_update_stream_priority(conn, stream, &stream->rx.http.pri);
|
||||
if (rv != 0) {
|
||||
return rv;
|
||||
}
|
||||
@@ -1412,8 +1445,7 @@ nghttp3_ssize nghttp3_conn_read_bidi(nghttp3_conn *conn, size_t *pnproc,
|
||||
rv = conn_call_end_trailers(conn, stream, p == end && fin);
|
||||
break;
|
||||
default:
|
||||
/* Unreachable */
|
||||
assert(0);
|
||||
nghttp3_unreachable();
|
||||
}
|
||||
|
||||
if (rv != 0) {
|
||||
@@ -1505,7 +1537,7 @@ int nghttp3_conn_on_data(nghttp3_conn *conn, nghttp3_stream *stream,
|
||||
return 0;
|
||||
}
|
||||
|
||||
rv = conn->callbacks.recv_data(conn, stream->node.nid.id, data, datalen,
|
||||
rv = conn->callbacks.recv_data(conn, stream->node.id, data, datalen,
|
||||
conn->user_data, stream->user_data);
|
||||
if (rv != 0) {
|
||||
return NGHTTP3_ERR_CALLBACK_FAILURE;
|
||||
@@ -1515,11 +1547,9 @@ int nghttp3_conn_on_data(nghttp3_conn *conn, nghttp3_stream *stream,
|
||||
}
|
||||
|
||||
static nghttp3_pq *conn_get_sched_pq(nghttp3_conn *conn, nghttp3_tnode *tnode) {
|
||||
uint32_t urgency = nghttp3_pri_uint8_urgency(tnode->pri);
|
||||
assert(tnode->pri.urgency < NGHTTP3_URGENCY_LEVELS);
|
||||
|
||||
assert(urgency < NGHTTP3_URGENCY_LEVELS);
|
||||
|
||||
return &conn->sched[urgency].spq;
|
||||
return &conn->sched[tnode->pri.urgency].spq;
|
||||
}
|
||||
|
||||
static nghttp3_ssize conn_decode_headers(nghttp3_conn *conn,
|
||||
@@ -1552,8 +1582,7 @@ static nghttp3_ssize conn_decode_headers(nghttp3_conn *conn,
|
||||
recv_header = conn->callbacks.recv_trailer;
|
||||
break;
|
||||
default:
|
||||
/* Unreachable */
|
||||
assert(0);
|
||||
nghttp3_unreachable();
|
||||
}
|
||||
http = &stream->rx.http;
|
||||
|
||||
@@ -1606,17 +1635,15 @@ static nghttp3_ssize conn_decode_headers(nghttp3_conn *conn,
|
||||
break;
|
||||
case 0:
|
||||
if (recv_header) {
|
||||
rv = recv_header(conn, stream->node.nid.id, nv.token, nv.name,
|
||||
nv.value, nv.flags, conn->user_data,
|
||||
stream->user_data);
|
||||
rv = recv_header(conn, stream->node.id, nv.token, nv.name, nv.value,
|
||||
nv.flags, conn->user_data, stream->user_data);
|
||||
if (rv != 0) {
|
||||
rv = NGHTTP3_ERR_CALLBACK_FAILURE;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/* Unreachable */
|
||||
assert(0);
|
||||
nghttp3_unreachable();
|
||||
}
|
||||
|
||||
nghttp3_rcbuf_decref(nv.name);
|
||||
@@ -1684,13 +1711,32 @@ int nghttp3_conn_on_settings_entry_received(nghttp3_conn *conn,
|
||||
if (!conn->server) {
|
||||
break;
|
||||
}
|
||||
if (ent->value != 0 && ent->value != 1) {
|
||||
|
||||
switch (ent->value) {
|
||||
case 0:
|
||||
if (dest->enable_connect_protocol) {
|
||||
return NGHTTP3_ERR_H3_SETTINGS_ERROR;
|
||||
}
|
||||
|
||||
break;
|
||||
case 1:
|
||||
break;
|
||||
default:
|
||||
return NGHTTP3_ERR_H3_SETTINGS_ERROR;
|
||||
}
|
||||
if (ent->value == 0 && dest->enable_connect_protocol) {
|
||||
|
||||
dest->enable_connect_protocol = (uint8_t)ent->value;
|
||||
break;
|
||||
case NGHTTP3_SETTINGS_ID_H3_DATAGRAM:
|
||||
switch (ent->value) {
|
||||
case 0:
|
||||
case 1:
|
||||
break;
|
||||
default:
|
||||
return NGHTTP3_ERR_H3_SETTINGS_ERROR;
|
||||
}
|
||||
dest->enable_connect_protocol = (int)ent->value;
|
||||
|
||||
dest->h3_datagram = (uint8_t)ent->value;
|
||||
break;
|
||||
case NGHTTP3_H2_SETTINGS_ID_ENABLE_PUSH:
|
||||
case NGHTTP3_H2_SETTINGS_ID_MAX_CONCURRENT_STREAMS:
|
||||
@@ -1744,7 +1790,7 @@ conn_on_priority_update_stream(nghttp3_conn *conn,
|
||||
return rv;
|
||||
}
|
||||
|
||||
stream->node.pri = nghttp3_pri_to_uint8(&fr->pri);
|
||||
stream->node.pri = fr->pri;
|
||||
stream->flags |= NGHTTP3_STREAM_FLAG_PRIORITY_UPDATE_RECVED;
|
||||
|
||||
return 0;
|
||||
@@ -1756,8 +1802,7 @@ conn_on_priority_update_stream(nghttp3_conn *conn,
|
||||
|
||||
stream->flags |= NGHTTP3_STREAM_FLAG_PRIORITY_UPDATE_RECVED;
|
||||
|
||||
return conn_update_stream_priority(conn, stream,
|
||||
nghttp3_pri_to_uint8(&fr->pri));
|
||||
return conn_update_stream_priority(conn, stream, &fr->pri);
|
||||
}
|
||||
|
||||
int nghttp3_conn_on_priority_update(nghttp3_conn *conn,
|
||||
@@ -1794,7 +1839,7 @@ int nghttp3_conn_create_stream(nghttp3_conn *conn, nghttp3_stream **pstream,
|
||||
conn_stream_acked_data,
|
||||
};
|
||||
|
||||
rv = nghttp3_stream_new(&stream, stream_id, conn->next_seq, &callbacks,
|
||||
rv = nghttp3_stream_new(&stream, stream_id, &callbacks,
|
||||
&conn->out_chunk_objalloc, &conn->stream_objalloc,
|
||||
conn->mem);
|
||||
if (rv != 0) {
|
||||
@@ -1803,14 +1848,17 @@ int nghttp3_conn_create_stream(nghttp3_conn *conn, nghttp3_stream **pstream,
|
||||
|
||||
stream->conn = conn;
|
||||
|
||||
rv = nghttp3_map_insert(&conn->streams,
|
||||
(nghttp3_map_key_type)stream->node.nid.id, stream);
|
||||
rv = nghttp3_map_insert(&conn->streams, (nghttp3_map_key_type)stream->node.id,
|
||||
stream);
|
||||
if (rv != 0) {
|
||||
nghttp3_stream_del(stream);
|
||||
return rv;
|
||||
}
|
||||
|
||||
++conn->next_seq;
|
||||
if (conn->server && nghttp3_client_stream_bidi(stream_id)) {
|
||||
++conn->remote.bidi.num_streams;
|
||||
}
|
||||
|
||||
*pstream = stream;
|
||||
|
||||
return 0;
|
||||
@@ -1897,7 +1945,7 @@ static nghttp3_ssize conn_writev_stream(nghttp3_conn *conn, int64_t *pstream_id,
|
||||
int *pfin, nghttp3_vec *vec,
|
||||
size_t veccnt, nghttp3_stream *stream) {
|
||||
int rv;
|
||||
nghttp3_ssize n;
|
||||
size_t n;
|
||||
|
||||
assert(veccnt > 0);
|
||||
|
||||
@@ -1910,31 +1958,25 @@ static nghttp3_ssize conn_writev_stream(nghttp3_conn *conn, int64_t *pstream_id,
|
||||
}
|
||||
}
|
||||
|
||||
if (!nghttp3_stream_uni(stream->node.nid.id) && conn->tx.qenc &&
|
||||
if (!nghttp3_stream_uni(stream->node.id) && conn->tx.qenc &&
|
||||
!nghttp3_stream_is_blocked(conn->tx.qenc)) {
|
||||
n = nghttp3_stream_writev(conn->tx.qenc, pfin, vec, veccnt);
|
||||
if (n < 0) {
|
||||
return n;
|
||||
}
|
||||
if (n) {
|
||||
*pstream_id = conn->tx.qenc->node.nid.id;
|
||||
return n;
|
||||
*pstream_id = conn->tx.qenc->node.id;
|
||||
return (nghttp3_ssize)n;
|
||||
}
|
||||
}
|
||||
|
||||
n = nghttp3_stream_writev(stream, pfin, vec, veccnt);
|
||||
if (n < 0) {
|
||||
return n;
|
||||
}
|
||||
/* We might just want to write stream fin without sending any stream
|
||||
data. */
|
||||
if (n == 0 && *pfin == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
*pstream_id = stream->node.nid.id;
|
||||
*pstream_id = stream->node.id;
|
||||
|
||||
return n;
|
||||
return (nghttp3_ssize)n;
|
||||
}
|
||||
|
||||
nghttp3_ssize nghttp3_conn_writev_stream(nghttp3_conn *conn,
|
||||
@@ -1990,7 +2032,7 @@ nghttp3_ssize nghttp3_conn_writev_stream(nghttp3_conn *conn,
|
||||
return ncnt;
|
||||
}
|
||||
|
||||
if (nghttp3_client_stream_bidi(stream->node.nid.id) &&
|
||||
if (nghttp3_client_stream_bidi(stream->node.id) &&
|
||||
!nghttp3_stream_require_schedule(stream)) {
|
||||
nghttp3_conn_unschedule_stream(conn, stream);
|
||||
}
|
||||
@@ -2020,20 +2062,16 @@ nghttp3_stream *nghttp3_conn_get_next_tx_stream(nghttp3_conn *conn) {
|
||||
int nghttp3_conn_add_write_offset(nghttp3_conn *conn, int64_t stream_id,
|
||||
size_t n) {
|
||||
nghttp3_stream *stream = nghttp3_conn_find_stream(conn, stream_id);
|
||||
int rv;
|
||||
|
||||
if (stream == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
rv = nghttp3_stream_add_outq_offset(stream, n);
|
||||
if (rv != 0) {
|
||||
return rv;
|
||||
}
|
||||
nghttp3_stream_add_outq_offset(stream, n);
|
||||
|
||||
stream->unscheduled_nwrite += n;
|
||||
|
||||
if (!nghttp3_client_stream_bidi(stream->node.nid.id)) {
|
||||
if (!nghttp3_client_stream_bidi(stream->node.id)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2065,7 +2103,7 @@ static int conn_submit_headers_data(nghttp3_conn *conn, nghttp3_stream *stream,
|
||||
const nghttp3_data_reader *dr) {
|
||||
int rv;
|
||||
nghttp3_nv *nnva;
|
||||
nghttp3_frame_entry frent;
|
||||
nghttp3_frame_entry frent = {0};
|
||||
|
||||
rv = nghttp3_nva_copy(&nnva, nva, nvlen, conn->mem);
|
||||
if (rv != 0) {
|
||||
@@ -2235,7 +2273,7 @@ int nghttp3_conn_submit_trailers(nghttp3_conn *conn, int64_t stream_id,
|
||||
}
|
||||
|
||||
int nghttp3_conn_submit_shutdown_notice(nghttp3_conn *conn) {
|
||||
nghttp3_frame_entry frent;
|
||||
nghttp3_frame_entry frent = {0};
|
||||
int rv;
|
||||
|
||||
assert(conn->tx.ctrl);
|
||||
@@ -2258,7 +2296,7 @@ int nghttp3_conn_submit_shutdown_notice(nghttp3_conn *conn) {
|
||||
}
|
||||
|
||||
int nghttp3_conn_shutdown(nghttp3_conn *conn) {
|
||||
nghttp3_frame_entry frent;
|
||||
nghttp3_frame_entry frent = {0};
|
||||
int rv;
|
||||
|
||||
assert(conn->tx.ctrl);
|
||||
@@ -2279,7 +2317,8 @@ int nghttp3_conn_shutdown(nghttp3_conn *conn) {
|
||||
}
|
||||
|
||||
conn->tx.goaway_id = frent.fr.goaway.id;
|
||||
conn->flags |= NGHTTP3_CONN_FLAG_GOAWAY_QUEUED;
|
||||
conn->flags |=
|
||||
NGHTTP3_CONN_FLAG_GOAWAY_QUEUED | NGHTTP3_CONN_FLAG_SHUTDOWN_COMMENCED;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -2305,7 +2344,7 @@ void nghttp3_conn_block_stream(nghttp3_conn *conn, int64_t stream_id) {
|
||||
stream->flags |= NGHTTP3_STREAM_FLAG_FC_BLOCKED;
|
||||
stream->unscheduled_nwrite = 0;
|
||||
|
||||
if (nghttp3_client_stream_bidi(stream->node.nid.id)) {
|
||||
if (nghttp3_client_stream_bidi(stream->node.id)) {
|
||||
nghttp3_conn_unschedule_stream(conn, stream);
|
||||
}
|
||||
}
|
||||
@@ -2320,7 +2359,7 @@ void nghttp3_conn_shutdown_stream_write(nghttp3_conn *conn, int64_t stream_id) {
|
||||
stream->flags |= NGHTTP3_STREAM_FLAG_SHUT_WR;
|
||||
stream->unscheduled_nwrite = 0;
|
||||
|
||||
if (nghttp3_client_stream_bidi(stream->node.nid.id)) {
|
||||
if (nghttp3_client_stream_bidi(stream->node.id)) {
|
||||
nghttp3_conn_unschedule_stream(conn, stream);
|
||||
}
|
||||
}
|
||||
@@ -2334,7 +2373,7 @@ int nghttp3_conn_unblock_stream(nghttp3_conn *conn, int64_t stream_id) {
|
||||
|
||||
stream->flags &= (uint16_t)~NGHTTP3_STREAM_FLAG_FC_BLOCKED;
|
||||
|
||||
if (nghttp3_client_stream_bidi(stream->node.nid.id) &&
|
||||
if (nghttp3_client_stream_bidi(stream->node.id) &&
|
||||
nghttp3_stream_require_schedule(stream)) {
|
||||
return nghttp3_conn_ensure_stream_scheduled(conn, stream);
|
||||
}
|
||||
@@ -2364,7 +2403,7 @@ int nghttp3_conn_resume_stream(nghttp3_conn *conn, int64_t stream_id) {
|
||||
|
||||
stream->flags &= (uint16_t)~NGHTTP3_STREAM_FLAG_READ_DATA_BLOCKED;
|
||||
|
||||
if (nghttp3_client_stream_bidi(stream->node.nid.id) &&
|
||||
if (nghttp3_client_stream_bidi(stream->node.id) &&
|
||||
nghttp3_stream_require_schedule(stream)) {
|
||||
return nghttp3_conn_ensure_stream_scheduled(conn, stream);
|
||||
}
|
||||
@@ -2381,7 +2420,6 @@ int nghttp3_conn_close_stream(nghttp3_conn *conn, int64_t stream_id,
|
||||
}
|
||||
|
||||
if (nghttp3_stream_uni(stream_id) &&
|
||||
stream->type != NGHTTP3_STREAM_TYPE_PUSH &&
|
||||
stream->type != NGHTTP3_STREAM_TYPE_UNKNOWN) {
|
||||
return NGHTTP3_ERR_H3_CLOSED_CRITICAL_STREAM;
|
||||
}
|
||||
@@ -2459,18 +2497,34 @@ int nghttp3_conn_set_stream_user_data(nghttp3_conn *conn, int64_t stream_id,
|
||||
|
||||
uint64_t nghttp3_conn_get_frame_payload_left(nghttp3_conn *conn,
|
||||
int64_t stream_id) {
|
||||
nghttp3_stream *stream = nghttp3_conn_find_stream(conn, stream_id);
|
||||
nghttp3_stream *stream;
|
||||
int uni = 0;
|
||||
|
||||
if (!nghttp3_client_stream_bidi(stream_id)) {
|
||||
uni = conn_remote_stream_uni(conn, stream_id);
|
||||
if (!uni) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
stream = nghttp3_conn_find_stream(conn, stream_id);
|
||||
if (stream == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (uni && stream->type != NGHTTP3_STREAM_TYPE_CONTROL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (uint64_t)stream->rstate.left;
|
||||
}
|
||||
|
||||
int nghttp3_conn_get_stream_priority(nghttp3_conn *conn, nghttp3_pri *dest,
|
||||
int64_t stream_id) {
|
||||
int nghttp3_conn_get_stream_priority_versioned(nghttp3_conn *conn,
|
||||
int pri_version,
|
||||
nghttp3_pri *dest,
|
||||
int64_t stream_id) {
|
||||
nghttp3_stream *stream;
|
||||
(void)pri_version;
|
||||
|
||||
assert(conn->server);
|
||||
|
||||
@@ -2483,17 +2537,55 @@ int nghttp3_conn_get_stream_priority(nghttp3_conn *conn, nghttp3_pri *dest,
|
||||
return NGHTTP3_ERR_STREAM_NOT_FOUND;
|
||||
}
|
||||
|
||||
dest->urgency = nghttp3_pri_uint8_urgency(stream->node.pri);
|
||||
dest->inc = nghttp3_pri_uint8_inc(stream->node.pri);
|
||||
*dest = stream->node.pri;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nghttp3_conn_set_stream_priority(nghttp3_conn *conn, int64_t stream_id,
|
||||
const nghttp3_pri *pri) {
|
||||
int nghttp3_conn_set_client_stream_priority(nghttp3_conn *conn,
|
||||
int64_t stream_id,
|
||||
const uint8_t *data,
|
||||
size_t datalen) {
|
||||
nghttp3_stream *stream;
|
||||
nghttp3_frame_entry frent;
|
||||
nghttp3_frame_entry frent = {0};
|
||||
uint8_t *buf = NULL;
|
||||
|
||||
assert(!conn->server);
|
||||
|
||||
if (!nghttp3_client_stream_bidi(stream_id)) {
|
||||
return NGHTTP3_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
stream = nghttp3_conn_find_stream(conn, stream_id);
|
||||
if (stream == NULL) {
|
||||
return NGHTTP3_ERR_STREAM_NOT_FOUND;
|
||||
}
|
||||
|
||||
if (datalen) {
|
||||
buf = nghttp3_mem_malloc(conn->mem, datalen);
|
||||
if (buf == NULL) {
|
||||
return NGHTTP3_ERR_NOMEM;
|
||||
}
|
||||
|
||||
memcpy(buf, data, datalen);
|
||||
}
|
||||
|
||||
frent.fr.hd.type = NGHTTP3_FRAME_PRIORITY_UPDATE;
|
||||
frent.fr.priority_update.pri_elem_id = stream_id;
|
||||
frent.fr.priority_update.data = buf;
|
||||
frent.fr.priority_update.datalen = datalen;
|
||||
|
||||
return nghttp3_stream_frq_add(conn->tx.ctrl, &frent);
|
||||
}
|
||||
|
||||
int nghttp3_conn_set_server_stream_priority_versioned(nghttp3_conn *conn,
|
||||
int64_t stream_id,
|
||||
int pri_version,
|
||||
const nghttp3_pri *pri) {
|
||||
nghttp3_stream *stream;
|
||||
(void)pri_version;
|
||||
|
||||
assert(conn->server);
|
||||
assert(pri->urgency < NGHTTP3_URGENCY_LEVELS);
|
||||
assert(pri->inc == 0 || pri->inc == 1);
|
||||
|
||||
@@ -2506,29 +2598,18 @@ int nghttp3_conn_set_stream_priority(nghttp3_conn *conn, int64_t stream_id,
|
||||
return NGHTTP3_ERR_STREAM_NOT_FOUND;
|
||||
}
|
||||
|
||||
if (conn->server) {
|
||||
stream->flags |= NGHTTP3_STREAM_FLAG_SERVER_PRIORITY_SET;
|
||||
stream->flags |= NGHTTP3_STREAM_FLAG_SERVER_PRIORITY_SET;
|
||||
|
||||
return conn_update_stream_priority(conn, stream, nghttp3_pri_to_uint8(pri));
|
||||
}
|
||||
|
||||
frent.fr.hd.type = NGHTTP3_FRAME_PRIORITY_UPDATE;
|
||||
frent.fr.priority_update.pri_elem_id = stream_id;
|
||||
frent.fr.priority_update.pri = *pri;
|
||||
|
||||
return nghttp3_stream_frq_add(conn->tx.ctrl, &frent);
|
||||
return conn_update_stream_priority(conn, stream, pri);
|
||||
}
|
||||
|
||||
int nghttp3_conn_is_remote_qpack_encoder_stream(nghttp3_conn *conn,
|
||||
int64_t stream_id) {
|
||||
nghttp3_stream *stream;
|
||||
int nghttp3_conn_is_drained(nghttp3_conn *conn) {
|
||||
assert(conn->server);
|
||||
|
||||
if (!conn_remote_stream_uni(conn, stream_id)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
stream = nghttp3_conn_find_stream(conn, stream_id);
|
||||
return stream && stream->type == NGHTTP3_STREAM_TYPE_QPACK_ENCODER;
|
||||
return (conn->flags & NGHTTP3_CONN_FLAG_SHUTDOWN_COMMENCED) &&
|
||||
conn->remote.bidi.num_streams == 0 &&
|
||||
nghttp3_stream_outq_write_done(conn->tx.ctrl) &&
|
||||
nghttp3_ringbuf_len(&conn->tx.ctrl->frq) == 0;
|
||||
}
|
||||
|
||||
void nghttp3_settings_default_versioned(int settings_version,
|
||||
|
||||
+8
-2
@@ -62,6 +62,9 @@
|
||||
/* NGHTTP3_CONN_FLAG_QPACK_DECODER_OPENED is set when a QPACK decoder
|
||||
stream has opened. */
|
||||
#define NGHTTP3_CONN_FLAG_QPACK_DECODER_OPENED 0x0008u
|
||||
/* NGHTTP3_CONN_FLAG_SHUTDOWN_COMMENCED is set when graceful shutdown
|
||||
has started. */
|
||||
#define NGHTTP3_CONN_FLAG_SHUTDOWN_COMMENCED 0x0010u
|
||||
/* NGHTTP3_CONN_FLAG_GOAWAY_RECVED indicates that GOAWAY frame has
|
||||
received. */
|
||||
#define NGHTTP3_CONN_FLAG_GOAWAY_RECVED 0x0020u
|
||||
@@ -73,7 +76,7 @@ typedef struct nghttp3_chunk {
|
||||
nghttp3_opl_entry oplent;
|
||||
} nghttp3_chunk;
|
||||
|
||||
nghttp3_objalloc_def(chunk, nghttp3_chunk, oplent);
|
||||
nghttp3_objalloc_decl(chunk, nghttp3_chunk, oplent);
|
||||
|
||||
struct nghttp3_conn {
|
||||
nghttp3_objalloc out_chunk_objalloc;
|
||||
@@ -90,7 +93,6 @@ struct nghttp3_conn {
|
||||
void *user_data;
|
||||
int server;
|
||||
uint16_t flags;
|
||||
uint64_t next_seq;
|
||||
|
||||
struct {
|
||||
nghttp3_settings settings;
|
||||
@@ -109,6 +111,10 @@ struct nghttp3_conn {
|
||||
initiated bidirectional stream ID the remote endpoint can
|
||||
issue. This field is used on server side only. */
|
||||
uint64_t max_client_streams;
|
||||
/* num_streams is the number of client initiated bidirectional
|
||||
streams that are currently open. This field is for server
|
||||
use only. */
|
||||
size_t num_streams;
|
||||
} bidi;
|
||||
nghttp3_settings settings;
|
||||
} remote;
|
||||
|
||||
+7
-19
@@ -29,6 +29,7 @@
|
||||
#include <assert.h>
|
||||
|
||||
#include "nghttp3_str.h"
|
||||
#include "nghttp3_unreachable.h"
|
||||
|
||||
int64_t nghttp3_get_varint(size_t *plen, const uint8_t *p) {
|
||||
union {
|
||||
@@ -38,7 +39,7 @@ int64_t nghttp3_get_varint(size_t *plen, const uint8_t *p) {
|
||||
uint64_t n64;
|
||||
} n;
|
||||
|
||||
*plen = 1u << (*p >> 6);
|
||||
*plen = (size_t)(1u << (*p >> 6));
|
||||
|
||||
switch (*plen) {
|
||||
case 1:
|
||||
@@ -57,34 +58,25 @@ int64_t nghttp3_get_varint(size_t *plen, const uint8_t *p) {
|
||||
return (int64_t)nghttp3_ntohl64(n.n64);
|
||||
}
|
||||
|
||||
assert(0);
|
||||
abort();
|
||||
nghttp3_unreachable();
|
||||
}
|
||||
|
||||
int64_t nghttp3_get_varint_fb(const uint8_t *p) { return *p & 0x3f; }
|
||||
|
||||
size_t nghttp3_get_varint_len(const uint8_t *p) { return 1u << (*p >> 6); }
|
||||
size_t nghttp3_get_varintlen(const uint8_t *p) {
|
||||
return (size_t)(1u << (*p >> 6));
|
||||
}
|
||||
|
||||
uint8_t *nghttp3_put_uint64be(uint8_t *p, uint64_t n) {
|
||||
n = nghttp3_htonl64(n);
|
||||
return nghttp3_cpymem(p, (const uint8_t *)&n, sizeof(n));
|
||||
}
|
||||
|
||||
uint8_t *nghttp3_put_uint48be(uint8_t *p, uint64_t n) {
|
||||
n = nghttp3_htonl64(n);
|
||||
return nghttp3_cpymem(p, ((const uint8_t *)&n) + 2, 6);
|
||||
}
|
||||
|
||||
uint8_t *nghttp3_put_uint32be(uint8_t *p, uint32_t n) {
|
||||
n = htonl(n);
|
||||
return nghttp3_cpymem(p, (const uint8_t *)&n, sizeof(n));
|
||||
}
|
||||
|
||||
uint8_t *nghttp3_put_uint24be(uint8_t *p, uint32_t n) {
|
||||
n = htonl(n);
|
||||
return nghttp3_cpymem(p, ((const uint8_t *)&n) + 1, 3);
|
||||
}
|
||||
|
||||
uint8_t *nghttp3_put_uint16be(uint8_t *p, uint16_t n) {
|
||||
n = htons(n);
|
||||
return nghttp3_cpymem(p, (const uint8_t *)&n, sizeof(n));
|
||||
@@ -112,7 +104,7 @@ uint8_t *nghttp3_put_varint(uint8_t *p, int64_t n) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
size_t nghttp3_put_varint_len(int64_t n) {
|
||||
size_t nghttp3_put_varintlen(int64_t n) {
|
||||
if (n < 64) {
|
||||
return 1;
|
||||
}
|
||||
@@ -129,7 +121,3 @@ size_t nghttp3_put_varint_len(int64_t n) {
|
||||
uint64_t nghttp3_ord_stream_id(int64_t stream_id) {
|
||||
return (uint64_t)(stream_id >> 2) + 1;
|
||||
}
|
||||
|
||||
uint8_t nghttp3_pri_to_uint8(const nghttp3_pri *pri) {
|
||||
return (uint8_t)((uint32_t)pri->inc << 7 | pri->urgency);
|
||||
}
|
||||
+23
-48
@@ -50,15 +50,11 @@
|
||||
# include <sys/endian.h>
|
||||
#endif /* HAVE_SYS_ENDIAN_H */
|
||||
|
||||
#include <nghttp3/nghttp3.h>
|
||||
#if defined(__APPLE__)
|
||||
# include <libkern/OSByteOrder.h>
|
||||
#endif // __APPLE__
|
||||
|
||||
#if defined(HAVE_BSWAP_64) || \
|
||||
(defined(HAVE_DECL_BSWAP_64) && HAVE_DECL_BSWAP_64 > 0)
|
||||
# define nghttp3_bswap64 bswap_64
|
||||
#else /* !HAVE_BSWAP_64 */
|
||||
# define nghttp3_bswap64(N) \
|
||||
((uint64_t)(ntohl((uint32_t)(N))) << 32 | ntohl((uint32_t)((N) >> 32)))
|
||||
#endif /* !HAVE_BSWAP_64 */
|
||||
#include <nghttp3/nghttp3.h>
|
||||
|
||||
#if defined(HAVE_BE64TOH) || \
|
||||
(defined(HAVE_DECL_BE64TOH) && HAVE_DECL_BE64TOH > 0)
|
||||
@@ -69,6 +65,17 @@
|
||||
# define nghttp3_ntohl64(N) (N)
|
||||
# define nghttp3_htonl64(N) (N)
|
||||
# else /* !WORDS_BIGENDIAN */
|
||||
# if defined(HAVE_BSWAP_64) || \
|
||||
(defined(HAVE_DECL_BSWAP_64) && HAVE_DECL_BSWAP_64 > 0)
|
||||
# define nghttp3_bswap64 bswap_64
|
||||
# elif defined(WIN32)
|
||||
# define nghttp3_bswap64 _byteswap_uint64
|
||||
# elif defined(__APPLE__)
|
||||
# define nghttp3_bswap64 OSSwapInt64
|
||||
# else /* !HAVE_BSWAP_64 && !WIN32 && !__APPLE__ */
|
||||
# define nghttp3_bswap64(N) \
|
||||
((uint64_t)(ntohl((uint32_t)(N))) << 32 | ntohl((uint32_t)((N) >> 32)))
|
||||
# endif /* !HAVE_BSWAP_64 && !WIN32 && !__APPLE__ */
|
||||
# define nghttp3_ntohl64(N) nghttp3_bswap64(N)
|
||||
# define nghttp3_htonl64(N) nghttp3_bswap64(N)
|
||||
# endif /* !WORDS_BIGENDIAN */
|
||||
@@ -106,9 +113,9 @@ STIN uint16_t htons(uint16_t hostshort) {
|
||||
STIN uint32_t ntohl(uint32_t netlong) {
|
||||
uint32_t res;
|
||||
unsigned char *p = (unsigned char *)&netlong;
|
||||
res = *p++ << 24;
|
||||
res += *p++ << 16;
|
||||
res += *p++ << 8;
|
||||
res = (uint32_t)(*p++ << 24);
|
||||
res += (uint32_t)(*p++ << 16);
|
||||
res += (uint32_t)(*p++ << 8);
|
||||
res += *p;
|
||||
return res;
|
||||
}
|
||||
@@ -116,7 +123,7 @@ STIN uint32_t ntohl(uint32_t netlong) {
|
||||
STIN uint16_t ntohs(uint16_t netshort) {
|
||||
uint16_t res;
|
||||
unsigned char *p = (unsigned char *)&netshort;
|
||||
res = *p++ << 8;
|
||||
res = (uint16_t)(*p++ << 8);
|
||||
res += *p;
|
||||
return res;
|
||||
}
|
||||
@@ -137,10 +144,10 @@ int64_t nghttp3_get_varint(size_t *plen, const uint8_t *p);
|
||||
int64_t nghttp3_get_varint_fb(const uint8_t *p);
|
||||
|
||||
/*
|
||||
* nghttp3_get_varint_len returns the required number of bytes to read
|
||||
* nghttp3_get_varintlen returns the required number of bytes to read
|
||||
* variable-length integer starting at |p|.
|
||||
*/
|
||||
size_t nghttp3_get_varint_len(const uint8_t *p);
|
||||
size_t nghttp3_get_varintlen(const uint8_t *p);
|
||||
|
||||
/*
|
||||
* nghttp3_put_uint64be writes |n| in host byte order in |p| in
|
||||
@@ -149,13 +156,6 @@ size_t nghttp3_get_varint_len(const uint8_t *p);
|
||||
*/
|
||||
uint8_t *nghttp3_put_uint64be(uint8_t *p, uint64_t n);
|
||||
|
||||
/*
|
||||
* nghttp3_put_uint48be writes |n| in host byte order in |p| in
|
||||
* network byte order. It writes only least significant 48 bits. It
|
||||
* returns the one beyond of the last written position.
|
||||
*/
|
||||
uint8_t *nghttp3_put_uint48be(uint8_t *p, uint64_t n);
|
||||
|
||||
/*
|
||||
* nghttp3_put_uint32be writes |n| in host byte order in |p| in
|
||||
* network byte order. It returns the one beyond of the last written
|
||||
@@ -163,13 +163,6 @@ uint8_t *nghttp3_put_uint48be(uint8_t *p, uint64_t n);
|
||||
*/
|
||||
uint8_t *nghttp3_put_uint32be(uint8_t *p, uint32_t n);
|
||||
|
||||
/*
|
||||
* nghttp3_put_uint24be writes |n| in host byte order in |p| in
|
||||
* network byte order. It writes only least significant 24 bits. It
|
||||
* returns the one beyond of the last written position.
|
||||
*/
|
||||
uint8_t *nghttp3_put_uint24be(uint8_t *p, uint32_t n);
|
||||
|
||||
/*
|
||||
* nghttp3_put_uint16be writes |n| in host byte order in |p| in
|
||||
* network byte order. It returns the one beyond of the last written
|
||||
@@ -184,10 +177,10 @@ uint8_t *nghttp3_put_uint16be(uint8_t *p, uint16_t n);
|
||||
uint8_t *nghttp3_put_varint(uint8_t *p, int64_t n);
|
||||
|
||||
/*
|
||||
* nghttp3_put_varint_len returns the required number of bytes to
|
||||
* nghttp3_put_varintlen returns the required number of bytes to
|
||||
* encode |n|.
|
||||
*/
|
||||
size_t nghttp3_put_varint_len(int64_t n);
|
||||
size_t nghttp3_put_varintlen(int64_t n);
|
||||
|
||||
/*
|
||||
* nghttp3_ord_stream_id returns the ordinal number of |stream_id|.
|
||||
@@ -200,22 +193,4 @@ uint64_t nghttp3_ord_stream_id(int64_t stream_id);
|
||||
*/
|
||||
#define NGHTTP3_PRI_INC_MASK (1 << 7)
|
||||
|
||||
/*
|
||||
* nghttp3_pri_to_uint8 encodes |pri| into uint8_t variable.
|
||||
*/
|
||||
uint8_t nghttp3_pri_to_uint8(const nghttp3_pri *pri);
|
||||
|
||||
/*
|
||||
* nghttp3_pri_uint8_urgency extracts urgency from |PRI| which is
|
||||
* supposed to be constructed by nghttp3_pri_to_uint8.
|
||||
*/
|
||||
#define nghttp3_pri_uint8_urgency(PRI) \
|
||||
((uint32_t)((PRI) & ~NGHTTP3_PRI_INC_MASK))
|
||||
|
||||
/*
|
||||
* nghttp3_pri_uint8_inc extracts inc from |PRI| which is supposed to
|
||||
* be constructed by nghttp3_pri_to_uint8.
|
||||
*/
|
||||
#define nghttp3_pri_uint8_inc(PRI) (((PRI)&NGHTTP3_PRI_INC_MASK) != 0)
|
||||
|
||||
#endif /* NGHTTP3_CONV_H */
|
||||
+3
-2
@@ -28,8 +28,6 @@ const char *nghttp3_strerror(int liberr) {
|
||||
switch (liberr) {
|
||||
case NGHTTP3_ERR_INVALID_ARGUMENT:
|
||||
return "ERR_INVALID_ARGUMENT";
|
||||
case NGHTTP3_ERR_NOBUF:
|
||||
return "ERR_NOBUF";
|
||||
case NGHTTP3_ERR_INVALID_STATE:
|
||||
return "ERR_INVALID_STATE";
|
||||
case NGHTTP3_ERR_WOULDBLOCK:
|
||||
@@ -104,6 +102,9 @@ uint64_t nghttp3_err_infer_quic_app_error_code(int liberr) {
|
||||
case NGHTTP3_ERR_H3_INTERNAL_ERROR:
|
||||
case NGHTTP3_ERR_NOMEM:
|
||||
case NGHTTP3_ERR_CALLBACK_FAILURE:
|
||||
case NGHTTP3_ERR_QPACK_FATAL:
|
||||
case NGHTTP3_ERR_QPACK_HEADER_TOO_LARGE:
|
||||
case NGHTTP3_ERR_STREAM_DATA_OVERFLOW:
|
||||
return NGHTTP3_H3_INTERNAL_ERROR;
|
||||
case NGHTTP3_ERR_H3_CLOSED_CRITICAL_STREAM:
|
||||
return NGHTTP3_H3_CLOSED_CRITICAL_STREAM;
|
||||
|
||||
+23
-24
@@ -38,7 +38,7 @@ uint8_t *nghttp3_frame_write_hd(uint8_t *p, const nghttp3_frame_hd *hd) {
|
||||
}
|
||||
|
||||
size_t nghttp3_frame_write_hd_len(const nghttp3_frame_hd *hd) {
|
||||
return nghttp3_put_varint_len(hd->type) + nghttp3_put_varint_len(hd->length);
|
||||
return nghttp3_put_varintlen(hd->type) + nghttp3_put_varintlen(hd->length);
|
||||
}
|
||||
|
||||
uint8_t *nghttp3_frame_write_settings(uint8_t *p,
|
||||
@@ -61,14 +61,14 @@ size_t nghttp3_frame_write_settings_len(int64_t *ppayloadlen,
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < fr->niv; ++i) {
|
||||
payloadlen += nghttp3_put_varint_len((int64_t)fr->iv[i].id) +
|
||||
nghttp3_put_varint_len((int64_t)fr->iv[i].value);
|
||||
payloadlen += nghttp3_put_varintlen((int64_t)fr->iv[i].id) +
|
||||
nghttp3_put_varintlen((int64_t)fr->iv[i].value);
|
||||
}
|
||||
|
||||
*ppayloadlen = (int64_t)payloadlen;
|
||||
|
||||
return nghttp3_put_varint_len(NGHTTP3_FRAME_SETTINGS) +
|
||||
nghttp3_put_varint_len((int64_t)payloadlen) + payloadlen;
|
||||
return nghttp3_put_varintlen(NGHTTP3_FRAME_SETTINGS) +
|
||||
nghttp3_put_varintlen((int64_t)payloadlen) + payloadlen;
|
||||
}
|
||||
|
||||
uint8_t *nghttp3_frame_write_goaway(uint8_t *p,
|
||||
@@ -81,12 +81,12 @@ uint8_t *nghttp3_frame_write_goaway(uint8_t *p,
|
||||
|
||||
size_t nghttp3_frame_write_goaway_len(int64_t *ppayloadlen,
|
||||
const nghttp3_frame_goaway *fr) {
|
||||
size_t payloadlen = nghttp3_put_varint_len(fr->id);
|
||||
size_t payloadlen = nghttp3_put_varintlen(fr->id);
|
||||
|
||||
*ppayloadlen = (int64_t)payloadlen;
|
||||
|
||||
return nghttp3_put_varint_len(NGHTTP3_FRAME_GOAWAY) +
|
||||
nghttp3_put_varint_len((int64_t)payloadlen) + payloadlen;
|
||||
return nghttp3_put_varintlen(NGHTTP3_FRAME_GOAWAY) +
|
||||
nghttp3_put_varintlen((int64_t)payloadlen) + payloadlen;
|
||||
}
|
||||
|
||||
uint8_t *
|
||||
@@ -94,17 +94,8 @@ nghttp3_frame_write_priority_update(uint8_t *p,
|
||||
const nghttp3_frame_priority_update *fr) {
|
||||
p = nghttp3_frame_write_hd(p, &fr->hd);
|
||||
p = nghttp3_put_varint(p, fr->pri_elem_id);
|
||||
|
||||
assert(fr->pri.urgency <= NGHTTP3_URGENCY_LOW);
|
||||
|
||||
*p++ = 'u';
|
||||
*p++ = '=';
|
||||
*p++ = (uint8_t)('0' + fr->pri.urgency);
|
||||
|
||||
if (fr->pri.inc) {
|
||||
#define NGHTTP3_PRIORITY_INCREMENTAL ", i"
|
||||
p = nghttp3_cpymem(p, (const uint8_t *)NGHTTP3_PRIORITY_INCREMENTAL,
|
||||
sizeof(NGHTTP3_PRIORITY_INCREMENTAL) - 1);
|
||||
if (fr->datalen) {
|
||||
p = nghttp3_cpymem(p, fr->data, fr->datalen);
|
||||
}
|
||||
|
||||
return p;
|
||||
@@ -112,13 +103,12 @@ nghttp3_frame_write_priority_update(uint8_t *p,
|
||||
|
||||
size_t nghttp3_frame_write_priority_update_len(
|
||||
int64_t *ppayloadlen, const nghttp3_frame_priority_update *fr) {
|
||||
size_t payloadlen = nghttp3_put_varint_len(fr->pri_elem_id) + sizeof("u=U") -
|
||||
1 + (fr->pri.inc ? sizeof(", i") - 1 : 0);
|
||||
size_t payloadlen = nghttp3_put_varintlen(fr->pri_elem_id) + fr->datalen;
|
||||
|
||||
*ppayloadlen = (int64_t)payloadlen;
|
||||
|
||||
return nghttp3_put_varint_len(fr->hd.type) +
|
||||
nghttp3_put_varint_len((int64_t)payloadlen) + payloadlen;
|
||||
return nghttp3_put_varintlen(fr->hd.type) +
|
||||
nghttp3_put_varintlen((int64_t)payloadlen) + payloadlen;
|
||||
}
|
||||
|
||||
int nghttp3_nva_copy(nghttp3_nv **pnva, const nghttp3_nv *nva, size_t nvlen,
|
||||
@@ -164,11 +154,11 @@ int nghttp3_nva_copy(nghttp3_nv **pnva, const nghttp3_nv *nva, size_t nvlen,
|
||||
} else {
|
||||
if (nva[i].namelen) {
|
||||
memcpy(data, nva[i].name, nva[i].namelen);
|
||||
nghttp3_downcase(data, nva[i].namelen);
|
||||
}
|
||||
p->name = data;
|
||||
p->namelen = nva[i].namelen;
|
||||
data[p->namelen] = '\0';
|
||||
nghttp3_downcase(p->name, p->namelen);
|
||||
data += nva[i].namelen + 1;
|
||||
}
|
||||
|
||||
@@ -202,3 +192,12 @@ void nghttp3_frame_headers_free(nghttp3_frame_headers *fr,
|
||||
|
||||
nghttp3_nva_del(fr->nva, mem);
|
||||
}
|
||||
|
||||
void nghttp3_frame_priority_update_free(nghttp3_frame_priority_update *fr,
|
||||
const nghttp3_mem *mem) {
|
||||
if (fr == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
nghttp3_mem_free(mem, fr->data);
|
||||
}
|
||||
+35
-20
@@ -34,26 +34,23 @@
|
||||
|
||||
#include "nghttp3_buf.h"
|
||||
|
||||
typedef enum nghttp3_frame_type {
|
||||
NGHTTP3_FRAME_DATA = 0x00,
|
||||
NGHTTP3_FRAME_HEADERS = 0x01,
|
||||
NGHTTP3_FRAME_CANCEL_PUSH = 0x03,
|
||||
NGHTTP3_FRAME_SETTINGS = 0x04,
|
||||
NGHTTP3_FRAME_PUSH_PROMISE = 0x05,
|
||||
NGHTTP3_FRAME_GOAWAY = 0x07,
|
||||
NGHTTP3_FRAME_MAX_PUSH_ID = 0x0d,
|
||||
/* PRIORITY_UPDATE:
|
||||
https://tools.ietf.org/html/draft-ietf-httpbis-priority-03 */
|
||||
NGHTTP3_FRAME_PRIORITY_UPDATE = 0x0f0700,
|
||||
NGHTTP3_FRAME_PRIORITY_UPDATE_PUSH_ID = 0x0f0701,
|
||||
} nghttp3_frame_type;
|
||||
#define NGHTTP3_FRAME_DATA 0x00
|
||||
#define NGHTTP3_FRAME_HEADERS 0x01
|
||||
#define NGHTTP3_FRAME_CANCEL_PUSH 0x03
|
||||
#define NGHTTP3_FRAME_SETTINGS 0x04
|
||||
#define NGHTTP3_FRAME_PUSH_PROMISE 0x05
|
||||
#define NGHTTP3_FRAME_GOAWAY 0x07
|
||||
#define NGHTTP3_FRAME_MAX_PUSH_ID 0x0d
|
||||
/* PRIORITY_UPDATE: https://datatracker.ietf.org/doc/html/rfc9218 */
|
||||
#define NGHTTP3_FRAME_PRIORITY_UPDATE 0x0f0700
|
||||
#define NGHTTP3_FRAME_PRIORITY_UPDATE_PUSH_ID 0x0f0701
|
||||
|
||||
typedef enum nghttp3_h2_reserved_type {
|
||||
NGHTTP3_H2_FRAME_PRIORITY = 0x02,
|
||||
NGHTTP3_H2_FRAME_PING = 0x06,
|
||||
NGHTTP3_H2_FRAME_WINDOW_UPDATE = 0x08,
|
||||
NGHTTP3_H2_FRAME_CONTINUATION = 0x9,
|
||||
} nghttp3_h2_reserved_type;
|
||||
/* Frame types that are reserved for HTTP/2, and must not be used in
|
||||
HTTP/3. */
|
||||
#define NGHTTP3_H2_FRAME_PRIORITY 0x02
|
||||
#define NGHTTP3_H2_FRAME_PING 0x06
|
||||
#define NGHTTP3_H2_FRAME_WINDOW_UPDATE 0x08
|
||||
#define NGHTTP3_H2_FRAME_CONTINUATION 0x9
|
||||
|
||||
typedef struct nghttp3_frame_hd {
|
||||
int64_t type;
|
||||
@@ -74,6 +71,7 @@ typedef struct nghttp3_frame_headers {
|
||||
#define NGHTTP3_SETTINGS_ID_QPACK_MAX_TABLE_CAPACITY 0x01
|
||||
#define NGHTTP3_SETTINGS_ID_QPACK_BLOCKED_STREAMS 0x07
|
||||
#define NGHTTP3_SETTINGS_ID_ENABLE_CONNECT_PROTOCOL 0x08
|
||||
#define NGHTTP3_SETTINGS_ID_H3_DATAGRAM 0x33
|
||||
|
||||
#define NGHTTP3_H2_SETTINGS_ID_ENABLE_PUSH 0x2
|
||||
#define NGHTTP3_H2_SETTINGS_ID_MAX_CONCURRENT_STREAMS 0x3
|
||||
@@ -103,7 +101,17 @@ typedef struct nghttp3_frame_priority_update {
|
||||
NGHTTP3_FRAME_PRIORITY_UPDATE_PUSH_ID. It is undefined
|
||||
otherwise. */
|
||||
int64_t pri_elem_id;
|
||||
nghttp3_pri pri;
|
||||
/* When sending this frame, data should point to the buffer
|
||||
containing a serialized priority field value and its length is
|
||||
set to datalen. On reception, pri contains the decoded priority
|
||||
header value. */
|
||||
union {
|
||||
nghttp3_pri pri;
|
||||
struct {
|
||||
uint8_t *data;
|
||||
size_t datalen;
|
||||
};
|
||||
};
|
||||
} nghttp3_frame_priority_update;
|
||||
|
||||
typedef union nghttp3_frame {
|
||||
@@ -212,4 +220,11 @@ void nghttp3_nva_del(nghttp3_nv *nva, const nghttp3_mem *mem);
|
||||
void nghttp3_frame_headers_free(nghttp3_frame_headers *fr,
|
||||
const nghttp3_mem *mem);
|
||||
|
||||
/*
|
||||
* nghttp3_frame_priority_update_free frees memory allocated for |fr|.
|
||||
* This function should only be called for an outgoing frame.
|
||||
*/
|
||||
void nghttp3_frame_priority_update_free(nghttp3_frame_priority_update *fr,
|
||||
const nghttp3_mem *mem);
|
||||
|
||||
#endif /* NGHTTP3_FRAME_H */
|
||||
+56
-700
@@ -31,6 +31,8 @@
|
||||
#include "nghttp3_stream.h"
|
||||
#include "nghttp3_macro.h"
|
||||
#include "nghttp3_conv.h"
|
||||
#include "nghttp3_unreachable.h"
|
||||
#include "sfparse.h"
|
||||
|
||||
static uint8_t downcase(uint8_t c) {
|
||||
return 'A' <= c && c <= 'Z' ? (uint8_t)(c - 'A' + 'a') : c;
|
||||
@@ -105,722 +107,74 @@ static int check_path_flags(nghttp3_http_state *http) {
|
||||
(http->flags & NGHTTP3_HTTP_FLAG_PATH_ASTERISK)));
|
||||
}
|
||||
|
||||
/* Generated by genchartbl.py */
|
||||
static const int SF_KEY_CHARS[] = {
|
||||
0 /* NUL */, 0 /* SOH */, 0 /* STX */, 0 /* ETX */, 0 /* EOT */,
|
||||
0 /* ENQ */, 0 /* ACK */, 0 /* BEL */, 0 /* BS */, 0 /* HT */,
|
||||
0 /* LF */, 0 /* VT */, 0 /* FF */, 0 /* CR */, 0 /* SO */,
|
||||
0 /* SI */, 0 /* DLE */, 0 /* DC1 */, 0 /* DC2 */, 0 /* DC3 */,
|
||||
0 /* DC4 */, 0 /* NAK */, 0 /* SYN */, 0 /* ETB */, 0 /* CAN */,
|
||||
0 /* EM */, 0 /* SUB */, 0 /* ESC */, 0 /* FS */, 0 /* GS */,
|
||||
0 /* RS */, 0 /* US */, 0 /* SPC */, 0 /* ! */, 0 /* " */,
|
||||
0 /* # */, 0 /* $ */, 0 /* % */, 0 /* & */, 0 /* ' */,
|
||||
0 /* ( */, 0 /* ) */, 1 /* * */, 0 /* + */, 0 /* , */,
|
||||
1 /* - */, 1 /* . */, 0 /* / */, 1 /* 0 */, 1 /* 1 */,
|
||||
1 /* 2 */, 1 /* 3 */, 1 /* 4 */, 1 /* 5 */, 1 /* 6 */,
|
||||
1 /* 7 */, 1 /* 8 */, 1 /* 9 */, 0 /* : */, 0 /* ; */,
|
||||
0 /* < */, 0 /* = */, 0 /* > */, 0 /* ? */, 0 /* @ */,
|
||||
0 /* A */, 0 /* B */, 0 /* C */, 0 /* D */, 0 /* E */,
|
||||
0 /* F */, 0 /* G */, 0 /* H */, 0 /* I */, 0 /* J */,
|
||||
0 /* K */, 0 /* L */, 0 /* M */, 0 /* N */, 0 /* O */,
|
||||
0 /* P */, 0 /* Q */, 0 /* R */, 0 /* S */, 0 /* T */,
|
||||
0 /* U */, 0 /* V */, 0 /* W */, 0 /* X */, 0 /* Y */,
|
||||
0 /* Z */, 0 /* [ */, 0 /* \ */, 0 /* ] */, 0 /* ^ */,
|
||||
1 /* _ */, 0 /* ` */, 1 /* a */, 1 /* b */, 1 /* c */,
|
||||
1 /* d */, 1 /* e */, 1 /* f */, 1 /* g */, 1 /* h */,
|
||||
1 /* i */, 1 /* j */, 1 /* k */, 1 /* l */, 1 /* m */,
|
||||
1 /* n */, 1 /* o */, 1 /* p */, 1 /* q */, 1 /* r */,
|
||||
1 /* s */, 1 /* t */, 1 /* u */, 1 /* v */, 1 /* w */,
|
||||
1 /* x */, 1 /* y */, 1 /* z */, 0 /* { */, 0 /* | */,
|
||||
0 /* } */, 0 /* ~ */, 0 /* DEL */, 0 /* 0x80 */, 0 /* 0x81 */,
|
||||
0 /* 0x82 */, 0 /* 0x83 */, 0 /* 0x84 */, 0 /* 0x85 */, 0 /* 0x86 */,
|
||||
0 /* 0x87 */, 0 /* 0x88 */, 0 /* 0x89 */, 0 /* 0x8a */, 0 /* 0x8b */,
|
||||
0 /* 0x8c */, 0 /* 0x8d */, 0 /* 0x8e */, 0 /* 0x8f */, 0 /* 0x90 */,
|
||||
0 /* 0x91 */, 0 /* 0x92 */, 0 /* 0x93 */, 0 /* 0x94 */, 0 /* 0x95 */,
|
||||
0 /* 0x96 */, 0 /* 0x97 */, 0 /* 0x98 */, 0 /* 0x99 */, 0 /* 0x9a */,
|
||||
0 /* 0x9b */, 0 /* 0x9c */, 0 /* 0x9d */, 0 /* 0x9e */, 0 /* 0x9f */,
|
||||
0 /* 0xa0 */, 0 /* 0xa1 */, 0 /* 0xa2 */, 0 /* 0xa3 */, 0 /* 0xa4 */,
|
||||
0 /* 0xa5 */, 0 /* 0xa6 */, 0 /* 0xa7 */, 0 /* 0xa8 */, 0 /* 0xa9 */,
|
||||
0 /* 0xaa */, 0 /* 0xab */, 0 /* 0xac */, 0 /* 0xad */, 0 /* 0xae */,
|
||||
0 /* 0xaf */, 0 /* 0xb0 */, 0 /* 0xb1 */, 0 /* 0xb2 */, 0 /* 0xb3 */,
|
||||
0 /* 0xb4 */, 0 /* 0xb5 */, 0 /* 0xb6 */, 0 /* 0xb7 */, 0 /* 0xb8 */,
|
||||
0 /* 0xb9 */, 0 /* 0xba */, 0 /* 0xbb */, 0 /* 0xbc */, 0 /* 0xbd */,
|
||||
0 /* 0xbe */, 0 /* 0xbf */, 0 /* 0xc0 */, 0 /* 0xc1 */, 0 /* 0xc2 */,
|
||||
0 /* 0xc3 */, 0 /* 0xc4 */, 0 /* 0xc5 */, 0 /* 0xc6 */, 0 /* 0xc7 */,
|
||||
0 /* 0xc8 */, 0 /* 0xc9 */, 0 /* 0xca */, 0 /* 0xcb */, 0 /* 0xcc */,
|
||||
0 /* 0xcd */, 0 /* 0xce */, 0 /* 0xcf */, 0 /* 0xd0 */, 0 /* 0xd1 */,
|
||||
0 /* 0xd2 */, 0 /* 0xd3 */, 0 /* 0xd4 */, 0 /* 0xd5 */, 0 /* 0xd6 */,
|
||||
0 /* 0xd7 */, 0 /* 0xd8 */, 0 /* 0xd9 */, 0 /* 0xda */, 0 /* 0xdb */,
|
||||
0 /* 0xdc */, 0 /* 0xdd */, 0 /* 0xde */, 0 /* 0xdf */, 0 /* 0xe0 */,
|
||||
0 /* 0xe1 */, 0 /* 0xe2 */, 0 /* 0xe3 */, 0 /* 0xe4 */, 0 /* 0xe5 */,
|
||||
0 /* 0xe6 */, 0 /* 0xe7 */, 0 /* 0xe8 */, 0 /* 0xe9 */, 0 /* 0xea */,
|
||||
0 /* 0xeb */, 0 /* 0xec */, 0 /* 0xed */, 0 /* 0xee */, 0 /* 0xef */,
|
||||
0 /* 0xf0 */, 0 /* 0xf1 */, 0 /* 0xf2 */, 0 /* 0xf3 */, 0 /* 0xf4 */,
|
||||
0 /* 0xf5 */, 0 /* 0xf6 */, 0 /* 0xf7 */, 0 /* 0xf8 */, 0 /* 0xf9 */,
|
||||
0 /* 0xfa */, 0 /* 0xfb */, 0 /* 0xfc */, 0 /* 0xfd */, 0 /* 0xfe */,
|
||||
0 /* 0xff */,
|
||||
};
|
||||
|
||||
static nghttp3_ssize sf_parse_key(const uint8_t *begin, const uint8_t *end) {
|
||||
const uint8_t *p = begin;
|
||||
|
||||
if ((*p < 'a' || 'z' < *p) && *p != '*') {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (; p != end && SF_KEY_CHARS[*p]; ++p)
|
||||
;
|
||||
|
||||
return p - begin;
|
||||
}
|
||||
|
||||
static nghttp3_ssize sf_parse_integer_or_decimal(nghttp3_sf_value *dest,
|
||||
const uint8_t *begin,
|
||||
const uint8_t *end) {
|
||||
const uint8_t *p = begin;
|
||||
int sign = 1;
|
||||
int64_t value = 0;
|
||||
int type = NGHTTP3_SF_VALUE_TYPE_INTEGER;
|
||||
size_t len = 0;
|
||||
size_t fpos = 0;
|
||||
size_t i;
|
||||
|
||||
if (*p == '-') {
|
||||
if (++p == end) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
sign = -1;
|
||||
}
|
||||
|
||||
if (*p < '0' || '9' < *p) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (; p != end; ++p) {
|
||||
switch (*p) {
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
value *= 10;
|
||||
value += *p - '0';
|
||||
|
||||
if (++len > 15) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
break;
|
||||
case '.':
|
||||
if (type != NGHTTP3_SF_VALUE_TYPE_INTEGER) {
|
||||
goto fin;
|
||||
}
|
||||
|
||||
if (len > 12) {
|
||||
return -1;
|
||||
}
|
||||
fpos = len;
|
||||
type = NGHTTP3_SF_VALUE_TYPE_DECIMAL;
|
||||
|
||||
break;
|
||||
default:
|
||||
goto fin;
|
||||
};
|
||||
}
|
||||
|
||||
fin:
|
||||
switch (type) {
|
||||
case NGHTTP3_SF_VALUE_TYPE_INTEGER:
|
||||
if (dest) {
|
||||
dest->type = (uint8_t)type;
|
||||
dest->i = value * sign;
|
||||
}
|
||||
|
||||
return p - begin;
|
||||
case NGHTTP3_SF_VALUE_TYPE_DECIMAL:
|
||||
if (fpos == len || len - fpos > 3) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dest) {
|
||||
dest->type = (uint8_t)type;
|
||||
dest->d = (double)value;
|
||||
for (i = len - fpos; i > 0; --i) {
|
||||
dest->d /= (double)10;
|
||||
}
|
||||
dest->d *= sign;
|
||||
}
|
||||
|
||||
return p - begin;
|
||||
static int is_ws(uint8_t c) {
|
||||
switch (c) {
|
||||
case ' ':
|
||||
case '\t':
|
||||
return 1;
|
||||
default:
|
||||
assert(0);
|
||||
abort();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Generated by genchartbl.py */
|
||||
static const int SF_DQUOTE_CHARS[] = {
|
||||
0 /* NUL */, 0 /* SOH */, 0 /* STX */, 0 /* ETX */, 0 /* EOT */,
|
||||
0 /* ENQ */, 0 /* ACK */, 0 /* BEL */, 0 /* BS */, 0 /* HT */,
|
||||
0 /* LF */, 0 /* VT */, 0 /* FF */, 0 /* CR */, 0 /* SO */,
|
||||
0 /* SI */, 0 /* DLE */, 0 /* DC1 */, 0 /* DC2 */, 0 /* DC3 */,
|
||||
0 /* DC4 */, 0 /* NAK */, 0 /* SYN */, 0 /* ETB */, 0 /* CAN */,
|
||||
0 /* EM */, 0 /* SUB */, 0 /* ESC */, 0 /* FS */, 0 /* GS */,
|
||||
0 /* RS */, 0 /* US */, 1 /* SPC */, 1 /* ! */, 0 /* " */,
|
||||
1 /* # */, 1 /* $ */, 1 /* % */, 1 /* & */, 1 /* ' */,
|
||||
1 /* ( */, 1 /* ) */, 1 /* * */, 1 /* + */, 1 /* , */,
|
||||
1 /* - */, 1 /* . */, 1 /* / */, 1 /* 0 */, 1 /* 1 */,
|
||||
1 /* 2 */, 1 /* 3 */, 1 /* 4 */, 1 /* 5 */, 1 /* 6 */,
|
||||
1 /* 7 */, 1 /* 8 */, 1 /* 9 */, 1 /* : */, 1 /* ; */,
|
||||
1 /* < */, 1 /* = */, 1 /* > */, 1 /* ? */, 1 /* @ */,
|
||||
1 /* A */, 1 /* B */, 1 /* C */, 1 /* D */, 1 /* E */,
|
||||
1 /* F */, 1 /* G */, 1 /* H */, 1 /* I */, 1 /* J */,
|
||||
1 /* K */, 1 /* L */, 1 /* M */, 1 /* N */, 1 /* O */,
|
||||
1 /* P */, 1 /* Q */, 1 /* R */, 1 /* S */, 1 /* T */,
|
||||
1 /* U */, 1 /* V */, 1 /* W */, 1 /* X */, 1 /* Y */,
|
||||
1 /* Z */, 1 /* [ */, 0 /* \ */, 1 /* ] */, 1 /* ^ */,
|
||||
1 /* _ */, 1 /* ` */, 1 /* a */, 1 /* b */, 1 /* c */,
|
||||
1 /* d */, 1 /* e */, 1 /* f */, 1 /* g */, 1 /* h */,
|
||||
1 /* i */, 1 /* j */, 1 /* k */, 1 /* l */, 1 /* m */,
|
||||
1 /* n */, 1 /* o */, 1 /* p */, 1 /* q */, 1 /* r */,
|
||||
1 /* s */, 1 /* t */, 1 /* u */, 1 /* v */, 1 /* w */,
|
||||
1 /* x */, 1 /* y */, 1 /* z */, 1 /* { */, 1 /* | */,
|
||||
1 /* } */, 1 /* ~ */, 0 /* DEL */, 0 /* 0x80 */, 0 /* 0x81 */,
|
||||
0 /* 0x82 */, 0 /* 0x83 */, 0 /* 0x84 */, 0 /* 0x85 */, 0 /* 0x86 */,
|
||||
0 /* 0x87 */, 0 /* 0x88 */, 0 /* 0x89 */, 0 /* 0x8a */, 0 /* 0x8b */,
|
||||
0 /* 0x8c */, 0 /* 0x8d */, 0 /* 0x8e */, 0 /* 0x8f */, 0 /* 0x90 */,
|
||||
0 /* 0x91 */, 0 /* 0x92 */, 0 /* 0x93 */, 0 /* 0x94 */, 0 /* 0x95 */,
|
||||
0 /* 0x96 */, 0 /* 0x97 */, 0 /* 0x98 */, 0 /* 0x99 */, 0 /* 0x9a */,
|
||||
0 /* 0x9b */, 0 /* 0x9c */, 0 /* 0x9d */, 0 /* 0x9e */, 0 /* 0x9f */,
|
||||
0 /* 0xa0 */, 0 /* 0xa1 */, 0 /* 0xa2 */, 0 /* 0xa3 */, 0 /* 0xa4 */,
|
||||
0 /* 0xa5 */, 0 /* 0xa6 */, 0 /* 0xa7 */, 0 /* 0xa8 */, 0 /* 0xa9 */,
|
||||
0 /* 0xaa */, 0 /* 0xab */, 0 /* 0xac */, 0 /* 0xad */, 0 /* 0xae */,
|
||||
0 /* 0xaf */, 0 /* 0xb0 */, 0 /* 0xb1 */, 0 /* 0xb2 */, 0 /* 0xb3 */,
|
||||
0 /* 0xb4 */, 0 /* 0xb5 */, 0 /* 0xb6 */, 0 /* 0xb7 */, 0 /* 0xb8 */,
|
||||
0 /* 0xb9 */, 0 /* 0xba */, 0 /* 0xbb */, 0 /* 0xbc */, 0 /* 0xbd */,
|
||||
0 /* 0xbe */, 0 /* 0xbf */, 0 /* 0xc0 */, 0 /* 0xc1 */, 0 /* 0xc2 */,
|
||||
0 /* 0xc3 */, 0 /* 0xc4 */, 0 /* 0xc5 */, 0 /* 0xc6 */, 0 /* 0xc7 */,
|
||||
0 /* 0xc8 */, 0 /* 0xc9 */, 0 /* 0xca */, 0 /* 0xcb */, 0 /* 0xcc */,
|
||||
0 /* 0xcd */, 0 /* 0xce */, 0 /* 0xcf */, 0 /* 0xd0 */, 0 /* 0xd1 */,
|
||||
0 /* 0xd2 */, 0 /* 0xd3 */, 0 /* 0xd4 */, 0 /* 0xd5 */, 0 /* 0xd6 */,
|
||||
0 /* 0xd7 */, 0 /* 0xd8 */, 0 /* 0xd9 */, 0 /* 0xda */, 0 /* 0xdb */,
|
||||
0 /* 0xdc */, 0 /* 0xdd */, 0 /* 0xde */, 0 /* 0xdf */, 0 /* 0xe0 */,
|
||||
0 /* 0xe1 */, 0 /* 0xe2 */, 0 /* 0xe3 */, 0 /* 0xe4 */, 0 /* 0xe5 */,
|
||||
0 /* 0xe6 */, 0 /* 0xe7 */, 0 /* 0xe8 */, 0 /* 0xe9 */, 0 /* 0xea */,
|
||||
0 /* 0xeb */, 0 /* 0xec */, 0 /* 0xed */, 0 /* 0xee */, 0 /* 0xef */,
|
||||
0 /* 0xf0 */, 0 /* 0xf1 */, 0 /* 0xf2 */, 0 /* 0xf3 */, 0 /* 0xf4 */,
|
||||
0 /* 0xf5 */, 0 /* 0xf6 */, 0 /* 0xf7 */, 0 /* 0xf8 */, 0 /* 0xf9 */,
|
||||
0 /* 0xfa */, 0 /* 0xfb */, 0 /* 0xfc */, 0 /* 0xfd */, 0 /* 0xfe */,
|
||||
0 /* 0xff */,
|
||||
};
|
||||
|
||||
static nghttp3_ssize sf_parse_string(nghttp3_sf_value *dest,
|
||||
const uint8_t *begin, const uint8_t *end) {
|
||||
const uint8_t *p = begin;
|
||||
|
||||
if (*p++ != '"') {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (; p != end; ++p) {
|
||||
switch (*p) {
|
||||
case '\\':
|
||||
if (++p == end) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch (*p) {
|
||||
case '"':
|
||||
case '\\':
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
break;
|
||||
case '"':
|
||||
if (dest) {
|
||||
dest->type = NGHTTP3_SF_VALUE_TYPE_STRING;
|
||||
dest->s.base = begin + 1;
|
||||
dest->s.len = (size_t)(p - dest->s.base);
|
||||
}
|
||||
|
||||
++p;
|
||||
|
||||
return p - begin;
|
||||
default:
|
||||
if (!SF_DQUOTE_CHARS[*p]) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Generated by genchartbl.py */
|
||||
static const int SF_TOKEN_CHARS[] = {
|
||||
0 /* NUL */, 0 /* SOH */, 0 /* STX */, 0 /* ETX */, 0 /* EOT */,
|
||||
0 /* ENQ */, 0 /* ACK */, 0 /* BEL */, 0 /* BS */, 0 /* HT */,
|
||||
0 /* LF */, 0 /* VT */, 0 /* FF */, 0 /* CR */, 0 /* SO */,
|
||||
0 /* SI */, 0 /* DLE */, 0 /* DC1 */, 0 /* DC2 */, 0 /* DC3 */,
|
||||
0 /* DC4 */, 0 /* NAK */, 0 /* SYN */, 0 /* ETB */, 0 /* CAN */,
|
||||
0 /* EM */, 0 /* SUB */, 0 /* ESC */, 0 /* FS */, 0 /* GS */,
|
||||
0 /* RS */, 0 /* US */, 0 /* SPC */, 1 /* ! */, 0 /* " */,
|
||||
1 /* # */, 1 /* $ */, 1 /* % */, 1 /* & */, 1 /* ' */,
|
||||
0 /* ( */, 0 /* ) */, 1 /* * */, 1 /* + */, 0 /* , */,
|
||||
1 /* - */, 1 /* . */, 1 /* / */, 1 /* 0 */, 1 /* 1 */,
|
||||
1 /* 2 */, 1 /* 3 */, 1 /* 4 */, 1 /* 5 */, 1 /* 6 */,
|
||||
1 /* 7 */, 1 /* 8 */, 1 /* 9 */, 1 /* : */, 0 /* ; */,
|
||||
0 /* < */, 0 /* = */, 0 /* > */, 0 /* ? */, 0 /* @ */,
|
||||
1 /* A */, 1 /* B */, 1 /* C */, 1 /* D */, 1 /* E */,
|
||||
1 /* F */, 1 /* G */, 1 /* H */, 1 /* I */, 1 /* J */,
|
||||
1 /* K */, 1 /* L */, 1 /* M */, 1 /* N */, 1 /* O */,
|
||||
1 /* P */, 1 /* Q */, 1 /* R */, 1 /* S */, 1 /* T */,
|
||||
1 /* U */, 1 /* V */, 1 /* W */, 1 /* X */, 1 /* Y */,
|
||||
1 /* Z */, 0 /* [ */, 0 /* \ */, 0 /* ] */, 1 /* ^ */,
|
||||
1 /* _ */, 1 /* ` */, 1 /* a */, 1 /* b */, 1 /* c */,
|
||||
1 /* d */, 1 /* e */, 1 /* f */, 1 /* g */, 1 /* h */,
|
||||
1 /* i */, 1 /* j */, 1 /* k */, 1 /* l */, 1 /* m */,
|
||||
1 /* n */, 1 /* o */, 1 /* p */, 1 /* q */, 1 /* r */,
|
||||
1 /* s */, 1 /* t */, 1 /* u */, 1 /* v */, 1 /* w */,
|
||||
1 /* x */, 1 /* y */, 1 /* z */, 0 /* { */, 1 /* | */,
|
||||
0 /* } */, 1 /* ~ */, 0 /* DEL */, 0 /* 0x80 */, 0 /* 0x81 */,
|
||||
0 /* 0x82 */, 0 /* 0x83 */, 0 /* 0x84 */, 0 /* 0x85 */, 0 /* 0x86 */,
|
||||
0 /* 0x87 */, 0 /* 0x88 */, 0 /* 0x89 */, 0 /* 0x8a */, 0 /* 0x8b */,
|
||||
0 /* 0x8c */, 0 /* 0x8d */, 0 /* 0x8e */, 0 /* 0x8f */, 0 /* 0x90 */,
|
||||
0 /* 0x91 */, 0 /* 0x92 */, 0 /* 0x93 */, 0 /* 0x94 */, 0 /* 0x95 */,
|
||||
0 /* 0x96 */, 0 /* 0x97 */, 0 /* 0x98 */, 0 /* 0x99 */, 0 /* 0x9a */,
|
||||
0 /* 0x9b */, 0 /* 0x9c */, 0 /* 0x9d */, 0 /* 0x9e */, 0 /* 0x9f */,
|
||||
0 /* 0xa0 */, 0 /* 0xa1 */, 0 /* 0xa2 */, 0 /* 0xa3 */, 0 /* 0xa4 */,
|
||||
0 /* 0xa5 */, 0 /* 0xa6 */, 0 /* 0xa7 */, 0 /* 0xa8 */, 0 /* 0xa9 */,
|
||||
0 /* 0xaa */, 0 /* 0xab */, 0 /* 0xac */, 0 /* 0xad */, 0 /* 0xae */,
|
||||
0 /* 0xaf */, 0 /* 0xb0 */, 0 /* 0xb1 */, 0 /* 0xb2 */, 0 /* 0xb3 */,
|
||||
0 /* 0xb4 */, 0 /* 0xb5 */, 0 /* 0xb6 */, 0 /* 0xb7 */, 0 /* 0xb8 */,
|
||||
0 /* 0xb9 */, 0 /* 0xba */, 0 /* 0xbb */, 0 /* 0xbc */, 0 /* 0xbd */,
|
||||
0 /* 0xbe */, 0 /* 0xbf */, 0 /* 0xc0 */, 0 /* 0xc1 */, 0 /* 0xc2 */,
|
||||
0 /* 0xc3 */, 0 /* 0xc4 */, 0 /* 0xc5 */, 0 /* 0xc6 */, 0 /* 0xc7 */,
|
||||
0 /* 0xc8 */, 0 /* 0xc9 */, 0 /* 0xca */, 0 /* 0xcb */, 0 /* 0xcc */,
|
||||
0 /* 0xcd */, 0 /* 0xce */, 0 /* 0xcf */, 0 /* 0xd0 */, 0 /* 0xd1 */,
|
||||
0 /* 0xd2 */, 0 /* 0xd3 */, 0 /* 0xd4 */, 0 /* 0xd5 */, 0 /* 0xd6 */,
|
||||
0 /* 0xd7 */, 0 /* 0xd8 */, 0 /* 0xd9 */, 0 /* 0xda */, 0 /* 0xdb */,
|
||||
0 /* 0xdc */, 0 /* 0xdd */, 0 /* 0xde */, 0 /* 0xdf */, 0 /* 0xe0 */,
|
||||
0 /* 0xe1 */, 0 /* 0xe2 */, 0 /* 0xe3 */, 0 /* 0xe4 */, 0 /* 0xe5 */,
|
||||
0 /* 0xe6 */, 0 /* 0xe7 */, 0 /* 0xe8 */, 0 /* 0xe9 */, 0 /* 0xea */,
|
||||
0 /* 0xeb */, 0 /* 0xec */, 0 /* 0xed */, 0 /* 0xee */, 0 /* 0xef */,
|
||||
0 /* 0xf0 */, 0 /* 0xf1 */, 0 /* 0xf2 */, 0 /* 0xf3 */, 0 /* 0xf4 */,
|
||||
0 /* 0xf5 */, 0 /* 0xf6 */, 0 /* 0xf7 */, 0 /* 0xf8 */, 0 /* 0xf9 */,
|
||||
0 /* 0xfa */, 0 /* 0xfb */, 0 /* 0xfc */, 0 /* 0xfd */, 0 /* 0xfe */,
|
||||
0 /* 0xff */,
|
||||
};
|
||||
|
||||
static nghttp3_ssize sf_parse_token(nghttp3_sf_value *dest,
|
||||
const uint8_t *begin, const uint8_t *end) {
|
||||
const uint8_t *p = begin;
|
||||
|
||||
if ((*p < 'A' || 'Z' < *p) && (*p < 'a' || 'z' < *p) && *p != '*') {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (; p != end && SF_TOKEN_CHARS[*p]; ++p)
|
||||
;
|
||||
|
||||
if (dest) {
|
||||
dest->type = NGHTTP3_SF_VALUE_TYPE_TOKEN;
|
||||
dest->s.base = begin;
|
||||
dest->s.len = (size_t)(p - begin);
|
||||
}
|
||||
|
||||
return p - begin;
|
||||
}
|
||||
|
||||
/* Generated by genchartbl.py */
|
||||
static const int SF_BYTESEQ_CHARS[] = {
|
||||
0 /* NUL */, 0 /* SOH */, 0 /* STX */, 0 /* ETX */, 0 /* EOT */,
|
||||
0 /* ENQ */, 0 /* ACK */, 0 /* BEL */, 0 /* BS */, 0 /* HT */,
|
||||
0 /* LF */, 0 /* VT */, 0 /* FF */, 0 /* CR */, 0 /* SO */,
|
||||
0 /* SI */, 0 /* DLE */, 0 /* DC1 */, 0 /* DC2 */, 0 /* DC3 */,
|
||||
0 /* DC4 */, 0 /* NAK */, 0 /* SYN */, 0 /* ETB */, 0 /* CAN */,
|
||||
0 /* EM */, 0 /* SUB */, 0 /* ESC */, 0 /* FS */, 0 /* GS */,
|
||||
0 /* RS */, 0 /* US */, 0 /* SPC */, 0 /* ! */, 0 /* " */,
|
||||
0 /* # */, 0 /* $ */, 0 /* % */, 0 /* & */, 0 /* ' */,
|
||||
0 /* ( */, 0 /* ) */, 0 /* * */, 1 /* + */, 0 /* , */,
|
||||
0 /* - */, 0 /* . */, 1 /* / */, 1 /* 0 */, 1 /* 1 */,
|
||||
1 /* 2 */, 1 /* 3 */, 1 /* 4 */, 1 /* 5 */, 1 /* 6 */,
|
||||
1 /* 7 */, 1 /* 8 */, 1 /* 9 */, 0 /* : */, 0 /* ; */,
|
||||
0 /* < */, 1 /* = */, 0 /* > */, 0 /* ? */, 0 /* @ */,
|
||||
1 /* A */, 1 /* B */, 1 /* C */, 1 /* D */, 1 /* E */,
|
||||
1 /* F */, 1 /* G */, 1 /* H */, 1 /* I */, 1 /* J */,
|
||||
1 /* K */, 1 /* L */, 1 /* M */, 1 /* N */, 1 /* O */,
|
||||
1 /* P */, 1 /* Q */, 1 /* R */, 1 /* S */, 1 /* T */,
|
||||
1 /* U */, 1 /* V */, 1 /* W */, 1 /* X */, 1 /* Y */,
|
||||
1 /* Z */, 0 /* [ */, 0 /* \ */, 0 /* ] */, 0 /* ^ */,
|
||||
0 /* _ */, 0 /* ` */, 1 /* a */, 1 /* b */, 1 /* c */,
|
||||
1 /* d */, 1 /* e */, 1 /* f */, 1 /* g */, 1 /* h */,
|
||||
1 /* i */, 1 /* j */, 1 /* k */, 1 /* l */, 1 /* m */,
|
||||
1 /* n */, 1 /* o */, 1 /* p */, 1 /* q */, 1 /* r */,
|
||||
1 /* s */, 1 /* t */, 1 /* u */, 1 /* v */, 1 /* w */,
|
||||
1 /* x */, 1 /* y */, 1 /* z */, 0 /* { */, 0 /* | */,
|
||||
0 /* } */, 0 /* ~ */, 0 /* DEL */, 0 /* 0x80 */, 0 /* 0x81 */,
|
||||
0 /* 0x82 */, 0 /* 0x83 */, 0 /* 0x84 */, 0 /* 0x85 */, 0 /* 0x86 */,
|
||||
0 /* 0x87 */, 0 /* 0x88 */, 0 /* 0x89 */, 0 /* 0x8a */, 0 /* 0x8b */,
|
||||
0 /* 0x8c */, 0 /* 0x8d */, 0 /* 0x8e */, 0 /* 0x8f */, 0 /* 0x90 */,
|
||||
0 /* 0x91 */, 0 /* 0x92 */, 0 /* 0x93 */, 0 /* 0x94 */, 0 /* 0x95 */,
|
||||
0 /* 0x96 */, 0 /* 0x97 */, 0 /* 0x98 */, 0 /* 0x99 */, 0 /* 0x9a */,
|
||||
0 /* 0x9b */, 0 /* 0x9c */, 0 /* 0x9d */, 0 /* 0x9e */, 0 /* 0x9f */,
|
||||
0 /* 0xa0 */, 0 /* 0xa1 */, 0 /* 0xa2 */, 0 /* 0xa3 */, 0 /* 0xa4 */,
|
||||
0 /* 0xa5 */, 0 /* 0xa6 */, 0 /* 0xa7 */, 0 /* 0xa8 */, 0 /* 0xa9 */,
|
||||
0 /* 0xaa */, 0 /* 0xab */, 0 /* 0xac */, 0 /* 0xad */, 0 /* 0xae */,
|
||||
0 /* 0xaf */, 0 /* 0xb0 */, 0 /* 0xb1 */, 0 /* 0xb2 */, 0 /* 0xb3 */,
|
||||
0 /* 0xb4 */, 0 /* 0xb5 */, 0 /* 0xb6 */, 0 /* 0xb7 */, 0 /* 0xb8 */,
|
||||
0 /* 0xb9 */, 0 /* 0xba */, 0 /* 0xbb */, 0 /* 0xbc */, 0 /* 0xbd */,
|
||||
0 /* 0xbe */, 0 /* 0xbf */, 0 /* 0xc0 */, 0 /* 0xc1 */, 0 /* 0xc2 */,
|
||||
0 /* 0xc3 */, 0 /* 0xc4 */, 0 /* 0xc5 */, 0 /* 0xc6 */, 0 /* 0xc7 */,
|
||||
0 /* 0xc8 */, 0 /* 0xc9 */, 0 /* 0xca */, 0 /* 0xcb */, 0 /* 0xcc */,
|
||||
0 /* 0xcd */, 0 /* 0xce */, 0 /* 0xcf */, 0 /* 0xd0 */, 0 /* 0xd1 */,
|
||||
0 /* 0xd2 */, 0 /* 0xd3 */, 0 /* 0xd4 */, 0 /* 0xd5 */, 0 /* 0xd6 */,
|
||||
0 /* 0xd7 */, 0 /* 0xd8 */, 0 /* 0xd9 */, 0 /* 0xda */, 0 /* 0xdb */,
|
||||
0 /* 0xdc */, 0 /* 0xdd */, 0 /* 0xde */, 0 /* 0xdf */, 0 /* 0xe0 */,
|
||||
0 /* 0xe1 */, 0 /* 0xe2 */, 0 /* 0xe3 */, 0 /* 0xe4 */, 0 /* 0xe5 */,
|
||||
0 /* 0xe6 */, 0 /* 0xe7 */, 0 /* 0xe8 */, 0 /* 0xe9 */, 0 /* 0xea */,
|
||||
0 /* 0xeb */, 0 /* 0xec */, 0 /* 0xed */, 0 /* 0xee */, 0 /* 0xef */,
|
||||
0 /* 0xf0 */, 0 /* 0xf1 */, 0 /* 0xf2 */, 0 /* 0xf3 */, 0 /* 0xf4 */,
|
||||
0 /* 0xf5 */, 0 /* 0xf6 */, 0 /* 0xf7 */, 0 /* 0xf8 */, 0 /* 0xf9 */,
|
||||
0 /* 0xfa */, 0 /* 0xfb */, 0 /* 0xfc */, 0 /* 0xfd */, 0 /* 0xfe */,
|
||||
0 /* 0xff */,
|
||||
};
|
||||
|
||||
static nghttp3_ssize sf_parse_byteseq(nghttp3_sf_value *dest,
|
||||
const uint8_t *begin,
|
||||
const uint8_t *end) {
|
||||
const uint8_t *p = begin;
|
||||
|
||||
if (*p++ != ':') {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (; p != end; ++p) {
|
||||
switch (*p) {
|
||||
case ':':
|
||||
if (dest) {
|
||||
dest->type = NGHTTP3_SF_VALUE_TYPE_BYTESEQ;
|
||||
dest->s.base = begin + 1;
|
||||
dest->s.len = (size_t)(p - dest->s.base);
|
||||
}
|
||||
|
||||
++p;
|
||||
|
||||
return p - begin;
|
||||
default:
|
||||
if (!SF_BYTESEQ_CHARS[*p]) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static nghttp3_ssize sf_parse_boolean(nghttp3_sf_value *dest,
|
||||
const uint8_t *begin,
|
||||
const uint8_t *end) {
|
||||
const uint8_t *p = begin;
|
||||
int b;
|
||||
|
||||
if (*p++ != '?') {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (p == end) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch (*p++) {
|
||||
case '0':
|
||||
b = 0;
|
||||
break;
|
||||
case '1':
|
||||
b = 1;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dest) {
|
||||
dest->type = NGHTTP3_SF_VALUE_TYPE_BOOLEAN;
|
||||
dest->b = b;
|
||||
}
|
||||
|
||||
return p - begin;
|
||||
}
|
||||
|
||||
static nghttp3_ssize sf_parse_bare_item(nghttp3_sf_value *dest,
|
||||
const uint8_t *begin,
|
||||
const uint8_t *end) {
|
||||
switch (*begin) {
|
||||
case '-':
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
return sf_parse_integer_or_decimal(dest, begin, end);
|
||||
case '"':
|
||||
return sf_parse_string(dest, begin, end);
|
||||
case '*':
|
||||
return sf_parse_token(dest, begin, end);
|
||||
case ':':
|
||||
return sf_parse_byteseq(dest, begin, end);
|
||||
case '?':
|
||||
return sf_parse_boolean(dest, begin, end);
|
||||
default:
|
||||
if (('A' <= *begin && *begin <= 'Z') || ('a' <= *begin && *begin <= 'z')) {
|
||||
return sf_parse_token(dest, begin, end);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
#define sf_discard_sp_end_err(BEGIN, END, ERR) \
|
||||
for (;; ++(BEGIN)) { \
|
||||
if ((BEGIN) == (END)) { \
|
||||
return (ERR); \
|
||||
} \
|
||||
if (*(BEGIN) != ' ') { \
|
||||
break; \
|
||||
} \
|
||||
}
|
||||
|
||||
static nghttp3_ssize sf_parse_params(const uint8_t *begin, const uint8_t *end) {
|
||||
const uint8_t *p = begin;
|
||||
nghttp3_ssize slen;
|
||||
|
||||
for (; p != end && *p == ';';) {
|
||||
++p;
|
||||
|
||||
sf_discard_sp_end_err(p, end, -1);
|
||||
|
||||
slen = sf_parse_key(p, end);
|
||||
if (slen < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
p += slen;
|
||||
|
||||
if (p == end || *p != '=') {
|
||||
/* Boolean true */
|
||||
} else if (++p == end) {
|
||||
return -1;
|
||||
} else {
|
||||
slen = sf_parse_bare_item(NULL, p, end);
|
||||
if (slen < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
p += slen;
|
||||
}
|
||||
}
|
||||
|
||||
return p - begin;
|
||||
}
|
||||
|
||||
static nghttp3_ssize sf_parse_item(nghttp3_sf_value *dest, const uint8_t *begin,
|
||||
const uint8_t *end) {
|
||||
const uint8_t *p = begin;
|
||||
nghttp3_ssize slen;
|
||||
|
||||
slen = sf_parse_bare_item(dest, p, end);
|
||||
if (slen < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
p += slen;
|
||||
|
||||
slen = sf_parse_params(p, end);
|
||||
if (slen < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
p += slen;
|
||||
|
||||
return p - begin;
|
||||
}
|
||||
|
||||
nghttp3_ssize nghttp3_sf_parse_item(nghttp3_sf_value *dest,
|
||||
const uint8_t *begin, const uint8_t *end) {
|
||||
return sf_parse_item(dest, begin, end);
|
||||
}
|
||||
|
||||
static nghttp3_ssize sf_parse_inner_list(nghttp3_sf_value *dest,
|
||||
const uint8_t *begin,
|
||||
const uint8_t *end) {
|
||||
const uint8_t *p = begin;
|
||||
nghttp3_ssize slen;
|
||||
|
||||
if (*p++ != '(') {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
sf_discard_sp_end_err(p, end, -1);
|
||||
|
||||
if (*p == ')') {
|
||||
++p;
|
||||
|
||||
slen = sf_parse_params(p, end);
|
||||
if (slen < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
p += slen;
|
||||
|
||||
if (dest) {
|
||||
dest->type = NGHTTP3_SF_VALUE_TYPE_INNER_LIST;
|
||||
}
|
||||
|
||||
return p - begin;
|
||||
}
|
||||
|
||||
slen = sf_parse_item(NULL, p, end);
|
||||
if (slen < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
p += slen;
|
||||
|
||||
if (p == end || (*p != ' ' && *p != ')')) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nghttp3_ssize nghttp3_sf_parse_inner_list(nghttp3_sf_value *dest,
|
||||
const uint8_t *begin,
|
||||
const uint8_t *end) {
|
||||
return sf_parse_inner_list(dest, begin, end);
|
||||
}
|
||||
|
||||
static nghttp3_ssize sf_parse_item_or_inner_list(nghttp3_sf_value *dest,
|
||||
const uint8_t *begin,
|
||||
const uint8_t *end) {
|
||||
if (*begin == '(') {
|
||||
return sf_parse_inner_list(dest, begin, end);
|
||||
}
|
||||
|
||||
return sf_parse_item(dest, begin, end);
|
||||
}
|
||||
|
||||
#define sf_discard_ows(BEGIN, END) \
|
||||
for (;; ++(BEGIN)) { \
|
||||
if ((BEGIN) == (END)) { \
|
||||
goto fin; \
|
||||
} \
|
||||
if (*(BEGIN) != ' ' && *(BEGIN) != '\t') { \
|
||||
break; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define sf_discard_ows_end_err(BEGIN, END, ERR) \
|
||||
for (;; ++(BEGIN)) { \
|
||||
if ((BEGIN) == (END)) { \
|
||||
return (ERR); \
|
||||
} \
|
||||
if (*(BEGIN) != ' ' && *(BEGIN) != '\t') { \
|
||||
break; \
|
||||
} \
|
||||
}
|
||||
|
||||
int nghttp3_http_parse_priority(nghttp3_pri *dest, const uint8_t *value,
|
||||
size_t valuelen) {
|
||||
const uint8_t *p = value, *end = value + valuelen;
|
||||
nghttp3_ssize slen;
|
||||
nghttp3_sf_value val;
|
||||
nghttp3_pri pri = *dest;
|
||||
const uint8_t *key;
|
||||
size_t keylen;
|
||||
sf_parser sfp;
|
||||
sf_vec key;
|
||||
sf_value val;
|
||||
int rv;
|
||||
|
||||
for (; p != end && *p == ' '; ++p)
|
||||
;
|
||||
|
||||
for (; p != end;) {
|
||||
slen = sf_parse_key(p, end);
|
||||
if (slen < 0) {
|
||||
return NGHTTP3_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
key = p;
|
||||
keylen = (size_t)slen;
|
||||
|
||||
p += slen;
|
||||
|
||||
if (p == end || *p != '=') {
|
||||
/* Boolean true */
|
||||
val.type = NGHTTP3_SF_VALUE_TYPE_BOOLEAN;
|
||||
val.b = 1;
|
||||
|
||||
slen = sf_parse_params(p, end);
|
||||
if (slen < 0) {
|
||||
return NGHTTP3_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
} else if (++p == end) {
|
||||
return NGHTTP3_ERR_INVALID_ARGUMENT;
|
||||
} else {
|
||||
slen = sf_parse_item_or_inner_list(&val, p, end);
|
||||
if (slen < 0) {
|
||||
return NGHTTP3_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
}
|
||||
|
||||
p += slen;
|
||||
|
||||
if (keylen == 1) {
|
||||
switch (key[0]) {
|
||||
case 'i':
|
||||
if (val.type != NGHTTP3_SF_VALUE_TYPE_BOOLEAN) {
|
||||
return NGHTTP3_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
pri.inc = val.b;
|
||||
|
||||
break;
|
||||
case 'u':
|
||||
if (val.type != NGHTTP3_SF_VALUE_TYPE_INTEGER ||
|
||||
val.i < NGHTTP3_URGENCY_HIGH || NGHTTP3_URGENCY_LOW < val.i) {
|
||||
return NGHTTP3_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
pri.urgency = (uint32_t)val.i;
|
||||
sf_parser_init(&sfp, value, valuelen);
|
||||
|
||||
for (;;) {
|
||||
rv = sf_parser_dict(&sfp, &key, &val);
|
||||
if (rv != 0) {
|
||||
if (rv == SF_ERR_EOF) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
sf_discard_ows(p, end);
|
||||
|
||||
if (*p++ != ',') {
|
||||
return NGHTTP3_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
sf_discard_ows_end_err(p, end, NGHTTP3_ERR_INVALID_ARGUMENT);
|
||||
if (key.len != 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (key.base[0]) {
|
||||
case 'i':
|
||||
if (val.type != SF_TYPE_BOOLEAN) {
|
||||
return NGHTTP3_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
pri.inc = (uint8_t)val.boolean;
|
||||
|
||||
break;
|
||||
case 'u':
|
||||
if (val.type != SF_TYPE_INTEGER || val.integer < NGHTTP3_URGENCY_HIGH ||
|
||||
NGHTTP3_URGENCY_LOW < val.integer) {
|
||||
return NGHTTP3_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
pri.urgency = (uint32_t)val.integer;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fin:
|
||||
*dest = pri;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nghttp3_pri_parse_priority_versioned(int pri_version, nghttp3_pri *dest,
|
||||
const uint8_t *value,
|
||||
size_t valuelen) {
|
||||
(void)pri_version;
|
||||
|
||||
return nghttp3_http_parse_priority(dest, value, valuelen);
|
||||
}
|
||||
|
||||
static int http_request_on_header(nghttp3_http_state *http,
|
||||
nghttp3_qpack_nv *nv, int trailers,
|
||||
int connect_protocol) {
|
||||
@@ -931,11 +285,10 @@ static int http_request_on_header(nghttp3_http_state *http,
|
||||
break;
|
||||
case NGHTTP3_QPACK_TOKEN_PRIORITY:
|
||||
if (!trailers && !(http->flags & NGHTTP3_HTTP_FLAG_BAD_PRIORITY)) {
|
||||
pri.urgency = nghttp3_pri_uint8_urgency(http->pri);
|
||||
pri.inc = nghttp3_pri_uint8_inc(http->pri);
|
||||
pri = http->pri;
|
||||
if (nghttp3_http_parse_priority(&pri, nv->value->base, nv->value->len) ==
|
||||
0) {
|
||||
http->pri = nghttp3_pri_to_uint8(&pri);
|
||||
http->pri = pri;
|
||||
http->flags |= NGHTTP3_HTTP_FLAG_PRIORITY;
|
||||
} else {
|
||||
http->flags &= ~NGHTTP3_HTTP_FLAG_PRIORITY;
|
||||
@@ -1637,10 +990,9 @@ int nghttp3_check_header_value(const uint8_t *value, size_t len) {
|
||||
case 0:
|
||||
return 1;
|
||||
case 1:
|
||||
return !(*value == ' ' || *value == '\t');
|
||||
return !is_ws(*value);
|
||||
default:
|
||||
if (*value == ' ' || *value == '\t' || *(value + len - 1) == ' ' ||
|
||||
*(value + len - 1) == '\t') {
|
||||
if (is_ws(*value) || is_ws(*(value + len - 1))) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1652,3 +1004,7 @@ int nghttp3_check_header_value(const uint8_t *value, size_t len) {
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int nghttp3_pri_eq(const nghttp3_pri *a, const nghttp3_pri *b) {
|
||||
return a->urgency == b->urgency && a->inc == b->inc;
|
||||
}
|
||||
+17
-46
@@ -150,53 +150,24 @@ int nghttp3_http_on_data_chunk(nghttp3_stream *stream, size_t n);
|
||||
void nghttp3_http_record_request_method(nghttp3_stream *stream,
|
||||
const nghttp3_nv *nva, size_t nvlen);
|
||||
|
||||
/*
|
||||
* RFC 8941 Structured Field Values.
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* `nghttp3_http_parse_priority` parses priority HTTP header field
|
||||
* stored in the buffer pointed by |value| of length |len|. If it
|
||||
* successfully processed header field value, it stores the result
|
||||
* into |*dest|. This function just overwrites what it sees in the
|
||||
* header field value and does not initialize any field in |*dest|.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* :macro:`NGHTTP3_ERR_INVALID_ARGUMENT`
|
||||
* The function could not parse the provided value.
|
||||
*/
|
||||
typedef enum nghttp3_sf_value_type {
|
||||
NGHTTP3_SF_VALUE_TYPE_BOOLEAN,
|
||||
NGHTTP3_SF_VALUE_TYPE_INTEGER,
|
||||
NGHTTP3_SF_VALUE_TYPE_DECIMAL,
|
||||
NGHTTP3_SF_VALUE_TYPE_STRING,
|
||||
NGHTTP3_SF_VALUE_TYPE_TOKEN,
|
||||
NGHTTP3_SF_VALUE_TYPE_BYTESEQ,
|
||||
NGHTTP3_SF_VALUE_TYPE_INNER_LIST,
|
||||
} nghttp3_sf_value_type;
|
||||
int nghttp3_http_parse_priority(nghttp3_pri *dest, const uint8_t *value,
|
||||
size_t len);
|
||||
|
||||
/*
|
||||
* nghttp3_sf_value stores Structured Field Values item. For Inner
|
||||
* List, only type is set to NGHTTP3_SF_VALUE_TYPE_INNER_LIST.
|
||||
*/
|
||||
typedef struct nghttp3_sf_value {
|
||||
uint8_t type;
|
||||
union {
|
||||
int b;
|
||||
int64_t i;
|
||||
double d;
|
||||
struct {
|
||||
const uint8_t *base;
|
||||
size_t len;
|
||||
} s;
|
||||
};
|
||||
} nghttp3_sf_value;
|
||||
|
||||
/*
|
||||
* nghttp3_sf_parse_item parses the input sequence [|begin|, |end|)
|
||||
* and stores the parsed an Item in |dest|. It returns the number of
|
||||
* bytes consumed if it succeeds, or -1. This function is declared
|
||||
* here for unit tests.
|
||||
*/
|
||||
nghttp3_ssize nghttp3_sf_parse_item(nghttp3_sf_value *dest,
|
||||
const uint8_t *begin, const uint8_t *end);
|
||||
|
||||
/*
|
||||
* nghttp3_sf_parse_inner_list parses the input sequence [|begin|, |end|)
|
||||
* and stores the parsed an Inner List in |dest|. It returns the number of
|
||||
* bytes consumed if it succeeds, or -1. This function is declared
|
||||
* here for unit tests.
|
||||
*/
|
||||
nghttp3_ssize nghttp3_sf_parse_inner_list(nghttp3_sf_value *dest,
|
||||
const uint8_t *begin,
|
||||
const uint8_t *end);
|
||||
int nghttp3_pri_eq(const nghttp3_pri *a, const nghttp3_pri *b);
|
||||
|
||||
#endif /* NGHTTP3_HTTP_H */
|
||||
+21
-17
@@ -36,6 +36,8 @@
|
||||
|
||||
static nghttp3_ksl_blk null_blk = {{{NULL, NULL, 0, 0, {0}}}};
|
||||
|
||||
nghttp3_objalloc_def(ksl_blk, nghttp3_ksl_blk, oplent);
|
||||
|
||||
static size_t ksl_nodelen(size_t keylen) {
|
||||
return (sizeof(nghttp3_ksl_node) + keylen - sizeof(uint64_t) + 0xfu) &
|
||||
~(uintptr_t)0xfu;
|
||||
@@ -722,6 +724,24 @@ void nghttp3_ksl_update_key(nghttp3_ksl *ksl, const nghttp3_ksl_key *old_key,
|
||||
}
|
||||
}
|
||||
|
||||
size_t nghttp3_ksl_len(nghttp3_ksl *ksl) { return ksl->n; }
|
||||
|
||||
void nghttp3_ksl_clear(nghttp3_ksl *ksl) {
|
||||
if (!ksl->head) {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef NOMEMPOOL
|
||||
ksl_free_blk(ksl, ksl->head);
|
||||
#endif /* NOMEMPOOL */
|
||||
|
||||
ksl->front = ksl->back = ksl->head = NULL;
|
||||
ksl->n = 0;
|
||||
|
||||
nghttp3_objalloc_clear(&ksl->blkalloc);
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
static void ksl_print(nghttp3_ksl *ksl, nghttp3_ksl_blk *blk, size_t level) {
|
||||
size_t i;
|
||||
nghttp3_ksl_node *node;
|
||||
@@ -742,23 +762,6 @@ static void ksl_print(nghttp3_ksl *ksl, nghttp3_ksl_blk *blk, size_t level) {
|
||||
}
|
||||
}
|
||||
|
||||
size_t nghttp3_ksl_len(nghttp3_ksl *ksl) { return ksl->n; }
|
||||
|
||||
void nghttp3_ksl_clear(nghttp3_ksl *ksl) {
|
||||
if (!ksl->head) {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef NOMEMPOOL
|
||||
ksl_free_blk(ksl, ksl->head);
|
||||
#endif /* NOMEMPOOL */
|
||||
|
||||
ksl->front = ksl->back = ksl->head = NULL;
|
||||
ksl->n = 0;
|
||||
|
||||
nghttp3_objalloc_clear(&ksl->blkalloc);
|
||||
}
|
||||
|
||||
void nghttp3_ksl_print(nghttp3_ksl *ksl) {
|
||||
if (!ksl->head) {
|
||||
return;
|
||||
@@ -766,6 +769,7 @@ void nghttp3_ksl_print(nghttp3_ksl *ksl) {
|
||||
|
||||
ksl_print(ksl, ksl->head, 0);
|
||||
}
|
||||
#endif /* !WIN32 */
|
||||
|
||||
nghttp3_ksl_it nghttp3_ksl_begin(const nghttp3_ksl *ksl) {
|
||||
nghttp3_ksl_it it;
|
||||
|
||||
+3
-1
@@ -108,7 +108,7 @@ struct nghttp3_ksl_blk {
|
||||
};
|
||||
};
|
||||
|
||||
nghttp3_objalloc_def(ksl_blk, nghttp3_ksl_blk, oplent);
|
||||
nghttp3_objalloc_decl(ksl_blk, nghttp3_ksl_blk, oplent);
|
||||
|
||||
/*
|
||||
* nghttp3_ksl_compar is a function type which returns nonzero if key
|
||||
@@ -265,12 +265,14 @@ void nghttp3_ksl_clear(nghttp3_ksl *ksl);
|
||||
#define nghttp3_ksl_nth_node(KSL, BLK, N) \
|
||||
((nghttp3_ksl_node *)(void *)((BLK)->nodes + (KSL)->nodelen * (N)))
|
||||
|
||||
#ifndef WIN32
|
||||
/*
|
||||
* nghttp3_ksl_print prints its internal state in stderr. It assumes
|
||||
* that the key is of type int64_t. This function should be used for
|
||||
* the debugging purpose only.
|
||||
*/
|
||||
void nghttp3_ksl_print(nghttp3_ksl *ksl);
|
||||
#endif /* !WIN32 */
|
||||
|
||||
/*
|
||||
* nghttp3_ksl_it_init initializes |it|.
|
||||
|
||||
+2
@@ -127,6 +127,7 @@ static void map_bucket_set_data(nghttp3_map_bucket *bkt, uint32_t hash,
|
||||
bkt->data = data;
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
void nghttp3_map_print_distance(nghttp3_map *map) {
|
||||
uint32_t i;
|
||||
size_t idx;
|
||||
@@ -146,6 +147,7 @@ void nghttp3_map_print_distance(nghttp3_map *map) {
|
||||
distance(map->tablelen, map->tablelenbits, bkt, idx));
|
||||
}
|
||||
}
|
||||
#endif /* !WIN32 */
|
||||
|
||||
static int insert(nghttp3_map_bucket *table, uint32_t tablelen,
|
||||
uint32_t tablelenbits, uint32_t hash,
|
||||
|
||||
+2
@@ -132,6 +132,8 @@ size_t nghttp3_map_size(nghttp3_map *map);
|
||||
int nghttp3_map_each(nghttp3_map *map, int (*func)(void *data, void *ptr),
|
||||
void *ptr);
|
||||
|
||||
#ifndef WIN32
|
||||
void nghttp3_map_print_distance(nghttp3_map *map);
|
||||
#endif /* !WIN32 */
|
||||
|
||||
#endif /* NGHTTP3_MAP_H */
|
||||
+18
-11
@@ -66,15 +66,25 @@ void nghttp3_objalloc_free(nghttp3_objalloc *objalloc);
|
||||
void nghttp3_objalloc_clear(nghttp3_objalloc *objalloc);
|
||||
|
||||
#ifndef NOMEMPOOL
|
||||
# define nghttp3_objalloc_def(NAME, TYPE, OPLENTFIELD) \
|
||||
# define nghttp3_objalloc_decl(NAME, TYPE, OPLENTFIELD) \
|
||||
inline static void nghttp3_objalloc_##NAME##_init( \
|
||||
nghttp3_objalloc *objalloc, size_t nmemb, const nghttp3_mem *mem) { \
|
||||
nghttp3_objalloc_init( \
|
||||
objalloc, ((sizeof(TYPE) + 0xfu) & ~(uintptr_t)0xfu) * nmemb, mem); \
|
||||
} \
|
||||
\
|
||||
inline static TYPE *nghttp3_objalloc_##NAME##_get( \
|
||||
nghttp3_objalloc *objalloc) { \
|
||||
TYPE *nghttp3_objalloc_##NAME##_get(nghttp3_objalloc *objalloc); \
|
||||
\
|
||||
TYPE *nghttp3_objalloc_##NAME##_len_get(nghttp3_objalloc *objalloc, \
|
||||
size_t len); \
|
||||
\
|
||||
inline static void nghttp3_objalloc_##NAME##_release( \
|
||||
nghttp3_objalloc *objalloc, TYPE *obj) { \
|
||||
nghttp3_opl_push(&objalloc->opl, &obj->OPLENTFIELD); \
|
||||
}
|
||||
|
||||
# define nghttp3_objalloc_def(NAME, TYPE, OPLENTFIELD) \
|
||||
TYPE *nghttp3_objalloc_##NAME##_get(nghttp3_objalloc *objalloc) { \
|
||||
nghttp3_opl_entry *oplent = nghttp3_opl_pop(&objalloc->opl); \
|
||||
TYPE *obj; \
|
||||
int rv; \
|
||||
@@ -92,8 +102,8 @@ void nghttp3_objalloc_clear(nghttp3_objalloc *objalloc);
|
||||
return nghttp3_struct_of(oplent, TYPE, OPLENTFIELD); \
|
||||
} \
|
||||
\
|
||||
inline static TYPE *nghttp3_objalloc_##NAME##_len_get( \
|
||||
nghttp3_objalloc *objalloc, size_t len) { \
|
||||
TYPE *nghttp3_objalloc_##NAME##_len_get(nghttp3_objalloc *objalloc, \
|
||||
size_t len) { \
|
||||
nghttp3_opl_entry *oplent = nghttp3_opl_pop(&objalloc->opl); \
|
||||
TYPE *obj; \
|
||||
int rv; \
|
||||
@@ -108,14 +118,9 @@ void nghttp3_objalloc_clear(nghttp3_objalloc *objalloc);
|
||||
} \
|
||||
\
|
||||
return nghttp3_struct_of(oplent, TYPE, OPLENTFIELD); \
|
||||
} \
|
||||
\
|
||||
inline static void nghttp3_objalloc_##NAME##_release( \
|
||||
nghttp3_objalloc *objalloc, TYPE *obj) { \
|
||||
nghttp3_opl_push(&objalloc->opl, &obj->OPLENTFIELD); \
|
||||
}
|
||||
#else /* NOMEMPOOL */
|
||||
# define nghttp3_objalloc_def(NAME, TYPE, OPLENTFIELD) \
|
||||
# define nghttp3_objalloc_decl(NAME, TYPE, OPLENTFIELD) \
|
||||
inline static void nghttp3_objalloc_##NAME##_init( \
|
||||
nghttp3_objalloc *objalloc, size_t nmemb, const nghttp3_mem *mem) { \
|
||||
nghttp3_objalloc_init( \
|
||||
@@ -136,6 +141,8 @@ void nghttp3_objalloc_clear(nghttp3_objalloc *objalloc);
|
||||
nghttp3_objalloc *objalloc, TYPE *obj) { \
|
||||
nghttp3_mem_free(objalloc->balloc.mem, obj); \
|
||||
}
|
||||
|
||||
# define nghttp3_objalloc_def(NAME, TYPE, OPLENTFIELD)
|
||||
#endif /* NOMEMPOOL */
|
||||
|
||||
#endif /* NGHTTP3_OBJALLOC_H */
|
||||
+52
-37
@@ -32,6 +32,7 @@
|
||||
#include "nghttp3_str.h"
|
||||
#include "nghttp3_macro.h"
|
||||
#include "nghttp3_debug.h"
|
||||
#include "nghttp3_unreachable.h"
|
||||
|
||||
/* NGHTTP3_QPACK_MAX_QPACK_STREAMS is the maximum number of concurrent
|
||||
nghttp3_qpack_stream object to handle a client which never cancel
|
||||
@@ -1099,7 +1100,7 @@ static void qpack_encoder_remove_stream(nghttp3_qpack_encoder *encoder,
|
||||
/*
|
||||
* reserve_buf_internal ensures that |buf| contains at least
|
||||
* |extra_size| of free space. In other words, if this function
|
||||
* succeeds, nghttp2_buf_left(buf) >= extra_size holds. |min_size| is
|
||||
* succeeds, nghttp3_buf_left(buf) >= extra_size holds. |min_size| is
|
||||
* the minimum size of buffer. The allocated buffer has at least
|
||||
* |min_size| bytes.
|
||||
*
|
||||
@@ -1281,6 +1282,19 @@ int nghttp3_qpack_encoder_stream_is_blocked(nghttp3_qpack_encoder *encoder,
|
||||
return stream && encoder->krcnt < nghttp3_qpack_stream_get_max_cnt(stream);
|
||||
}
|
||||
|
||||
static uint32_t qpack_hash_name(const nghttp3_nv *nv) {
|
||||
/* 32 bit FNV-1a: http://isthe.com/chongo/tech/comp/fnv/ */
|
||||
uint32_t h = 2166136261u;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < nv->namelen; ++i) {
|
||||
h ^= nv->name[i];
|
||||
h += (h << 1) + (h << 4) + (h << 7) + (h << 8) + (h << 24);
|
||||
}
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
/*
|
||||
* qpack_encoder_decide_indexing_mode determines and returns indexing
|
||||
* mode for header field |nv|. |token| is a token of header field
|
||||
@@ -1310,6 +1324,10 @@ qpack_encoder_decide_indexing_mode(nghttp3_qpack_encoder *encoder,
|
||||
case NGHTTP3_QPACK_TOKEN_IF_NONE_MATCH:
|
||||
case NGHTTP3_QPACK_TOKEN_LOCATION:
|
||||
case NGHTTP3_QPACK_TOKEN_SET_COOKIE:
|
||||
if (nv->flags & NGHTTP3_NV_FLAG_TRY_INDEX) {
|
||||
break;
|
||||
}
|
||||
|
||||
return NGHTTP3_QPACK_INDEXING_MODE_LITERAL;
|
||||
case NGHTTP3_QPACK_TOKEN_HOST:
|
||||
case NGHTTP3_QPACK_TOKEN_TE:
|
||||
@@ -1317,6 +1335,10 @@ qpack_encoder_decide_indexing_mode(nghttp3_qpack_encoder *encoder,
|
||||
case NGHTTP3_QPACK_TOKEN_PRIORITY:
|
||||
break;
|
||||
default:
|
||||
if (nv->flags & NGHTTP3_NV_FLAG_TRY_INDEX) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (token >= 1000) {
|
||||
return NGHTTP3_QPACK_INDEXING_MODE_LITERAL;
|
||||
}
|
||||
@@ -1428,6 +1450,17 @@ int nghttp3_qpack_encoder_encode_nv(nghttp3_qpack_encoder *encoder,
|
||||
|
||||
token = qpack_lookup_token(nv->name, nv->namelen);
|
||||
static_entry = token != -1 && (size_t)token < nghttp3_arraylen(token_stable);
|
||||
|
||||
indexing_mode = qpack_encoder_decide_indexing_mode(encoder, nv, token);
|
||||
|
||||
if (static_entry) {
|
||||
sres = nghttp3_qpack_lookup_stable(nv, token, indexing_mode);
|
||||
if (sres.index != -1 && sres.name_value_match) {
|
||||
return nghttp3_qpack_encoder_write_static_indexed(encoder, rbuf,
|
||||
(size_t)sres.index);
|
||||
}
|
||||
}
|
||||
|
||||
if (static_entry) {
|
||||
hash = token_stable[token].hash;
|
||||
} else {
|
||||
@@ -1444,21 +1477,12 @@ int nghttp3_qpack_encoder_encode_nv(nghttp3_qpack_encoder *encoder,
|
||||
case NGHTTP3_QPACK_TOKEN_PRIORITY:
|
||||
hash = 2498028297u;
|
||||
break;
|
||||
default:
|
||||
hash = qpack_hash_name(nv);
|
||||
}
|
||||
}
|
||||
|
||||
indexing_mode = qpack_encoder_decide_indexing_mode(encoder, nv, token);
|
||||
|
||||
if (static_entry) {
|
||||
sres = nghttp3_qpack_lookup_stable(nv, token, indexing_mode);
|
||||
if (sres.index != -1 && sres.name_value_match) {
|
||||
return nghttp3_qpack_encoder_write_static_indexed(encoder, rbuf,
|
||||
(size_t)sres.index);
|
||||
}
|
||||
}
|
||||
|
||||
if (hash &&
|
||||
nghttp3_map_size(&encoder->streams) < NGHTTP3_QPACK_MAX_QPACK_STREAMS) {
|
||||
if (nghttp3_map_size(&encoder->streams) < NGHTTP3_QPACK_MAX_QPACK_STREAMS) {
|
||||
dres = nghttp3_qpack_encoder_lookup_dtable(encoder, nv, token, hash,
|
||||
indexing_mode, encoder->krcnt,
|
||||
allow_blocking);
|
||||
@@ -2552,18 +2576,14 @@ nghttp3_ssize nghttp3_qpack_encoder_read_decoder(nghttp3_qpack_encoder *encoder,
|
||||
(int64_t)encoder->rstate.left);
|
||||
break;
|
||||
default:
|
||||
/* unreachable */
|
||||
assert(0);
|
||||
break;
|
||||
nghttp3_unreachable();
|
||||
}
|
||||
|
||||
encoder->state = NGHTTP3_QPACK_DS_STATE_OPCODE;
|
||||
nghttp3_qpack_read_state_reset(&encoder->rstate);
|
||||
break;
|
||||
default:
|
||||
/* unreachable */
|
||||
assert(0);
|
||||
break;
|
||||
nghttp3_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2838,24 +2858,26 @@ nghttp3_ssize nghttp3_qpack_decoder_read_encoder(nghttp3_qpack_decoder *decoder,
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (decoder->opcode == NGHTTP3_QPACK_ES_OPCODE_DUPLICATE) {
|
||||
switch (decoder->opcode) {
|
||||
case NGHTTP3_QPACK_ES_OPCODE_DUPLICATE:
|
||||
rv = nghttp3_qpack_decoder_dtable_duplicate_add(decoder);
|
||||
if (rv != 0) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
decoder->state = NGHTTP3_QPACK_ES_STATE_OPCODE;
|
||||
nghttp3_qpack_read_state_reset(&decoder->rstate);
|
||||
break;
|
||||
}
|
||||
|
||||
if (decoder->opcode == NGHTTP3_QPACK_ES_OPCODE_INSERT_INDEXED) {
|
||||
break;
|
||||
case NGHTTP3_QPACK_ES_OPCODE_INSERT_INDEXED:
|
||||
decoder->rstate.prefix = 7;
|
||||
decoder->state = NGHTTP3_QPACK_ES_STATE_CHECK_VALUE_HUFFMAN;
|
||||
|
||||
break;
|
||||
default:
|
||||
nghttp3_unreachable();
|
||||
}
|
||||
|
||||
/* Unreachable */
|
||||
assert(0);
|
||||
break;
|
||||
case NGHTTP3_QPACK_ES_STATE_CHECK_NAME_HUFFMAN:
|
||||
qpack_read_state_check_huffman(&decoder->rstate, *p);
|
||||
@@ -3010,9 +3032,7 @@ nghttp3_ssize nghttp3_qpack_decoder_read_encoder(nghttp3_qpack_decoder *decoder,
|
||||
rv = nghttp3_qpack_decoder_dtable_literal_add(decoder);
|
||||
break;
|
||||
default:
|
||||
/* Unreachable */
|
||||
assert(0);
|
||||
abort();
|
||||
nghttp3_unreachable();
|
||||
}
|
||||
if (rv != 0) {
|
||||
goto fail;
|
||||
@@ -3045,9 +3065,7 @@ nghttp3_ssize nghttp3_qpack_decoder_read_encoder(nghttp3_qpack_decoder *decoder,
|
||||
rv = nghttp3_qpack_decoder_dtable_literal_add(decoder);
|
||||
break;
|
||||
default:
|
||||
/* Unreachable */
|
||||
assert(0);
|
||||
abort();
|
||||
nghttp3_unreachable();
|
||||
}
|
||||
if (rv != 0) {
|
||||
goto fail;
|
||||
@@ -3430,8 +3448,7 @@ nghttp3_qpack_decoder_read_request(nghttp3_qpack_decoder *decoder,
|
||||
sctx->state = NGHTTP3_QPACK_RS_STATE_CHECK_VALUE_HUFFMAN;
|
||||
break;
|
||||
default:
|
||||
/* Unreachable */
|
||||
assert(0);
|
||||
nghttp3_unreachable();
|
||||
}
|
||||
break;
|
||||
case NGHTTP3_QPACK_RS_STATE_CHECK_NAME_HUFFMAN:
|
||||
@@ -3589,8 +3606,7 @@ nghttp3_qpack_decoder_read_request(nghttp3_qpack_decoder *decoder,
|
||||
nghttp3_qpack_decoder_emit_literal(decoder, sctx, nv);
|
||||
break;
|
||||
default:
|
||||
/* Unreachable */
|
||||
assert(0);
|
||||
nghttp3_unreachable();
|
||||
}
|
||||
|
||||
*pflags |= NGHTTP3_QPACK_DECODE_FLAG_EMIT;
|
||||
@@ -3627,8 +3643,7 @@ nghttp3_qpack_decoder_read_request(nghttp3_qpack_decoder *decoder,
|
||||
nghttp3_qpack_decoder_emit_literal(decoder, sctx, nv);
|
||||
break;
|
||||
default:
|
||||
/* Unreachable */
|
||||
assert(0);
|
||||
nghttp3_unreachable();
|
||||
}
|
||||
|
||||
*pflags |= NGHTTP3_QPACK_DECODE_FLAG_EMIT;
|
||||
|
||||
+2
-1
@@ -33,7 +33,8 @@
|
||||
|
||||
#include "nghttp3_macro.h"
|
||||
|
||||
#if defined(_MSC_VER) && !defined(__clang__) && (defined(_M_ARM) || defined(_M_ARM64))
|
||||
#if defined(_MSC_VER) && !defined(__clang__) && \
|
||||
(defined(_M_ARM) || defined(_M_ARM64))
|
||||
unsigned int __popcnt(unsigned int x) {
|
||||
unsigned int c = 0;
|
||||
for (; x; ++c) {
|
||||
|
||||
+54
-54
@@ -35,6 +35,7 @@
|
||||
#include "nghttp3_str.h"
|
||||
#include "nghttp3_http.h"
|
||||
#include "nghttp3_vec.h"
|
||||
#include "nghttp3_unreachable.h"
|
||||
|
||||
/* NGHTTP3_STREAM_MAX_COPY_THRES is the maximum size of buffer which
|
||||
makes a copy to outq. */
|
||||
@@ -43,13 +44,14 @@
|
||||
/* NGHTTP3_MIN_RBLEN is the minimum length of nghttp3_ringbuf */
|
||||
#define NGHTTP3_MIN_RBLEN 4
|
||||
|
||||
nghttp3_objalloc_def(stream, nghttp3_stream, oplent);
|
||||
|
||||
int nghttp3_stream_new(nghttp3_stream **pstream, int64_t stream_id,
|
||||
uint64_t seq, const nghttp3_stream_callbacks *callbacks,
|
||||
const nghttp3_stream_callbacks *callbacks,
|
||||
nghttp3_objalloc *out_chunk_objalloc,
|
||||
nghttp3_objalloc *stream_objalloc,
|
||||
const nghttp3_mem *mem) {
|
||||
nghttp3_stream *stream = nghttp3_objalloc_stream_get(stream_objalloc);
|
||||
nghttp3_node_id nid;
|
||||
|
||||
if (stream == NULL) {
|
||||
return NGHTTP3_ERR_NOMEM;
|
||||
@@ -60,10 +62,7 @@ int nghttp3_stream_new(nghttp3_stream **pstream, int64_t stream_id,
|
||||
stream->out_chunk_objalloc = out_chunk_objalloc;
|
||||
stream->stream_objalloc = stream_objalloc;
|
||||
|
||||
nghttp3_tnode_init(
|
||||
&stream->node,
|
||||
nghttp3_node_id_init(&nid, NGHTTP3_NODE_ID_TYPE_STREAM, stream_id), seq,
|
||||
NGHTTP3_DEFAULT_URGENCY);
|
||||
nghttp3_tnode_init(&stream->node, stream_id);
|
||||
|
||||
nghttp3_ringbuf_init(&stream->frq, 0, sizeof(nghttp3_frame_entry), mem);
|
||||
nghttp3_ringbuf_init(&stream->chunks, 0, sizeof(nghttp3_buf), mem);
|
||||
@@ -77,7 +76,7 @@ int nghttp3_stream_new(nghttp3_stream **pstream, int64_t stream_id,
|
||||
stream->tx.offset = 0;
|
||||
stream->rx.http.status_code = -1;
|
||||
stream->rx.http.content_length = -1;
|
||||
stream->rx.http.pri = NGHTTP3_DEFAULT_URGENCY;
|
||||
stream->rx.http.pri.urgency = NGHTTP3_DEFAULT_URGENCY;
|
||||
stream->error_code = NGHTTP3_H3_NO_ERROR;
|
||||
|
||||
if (callbacks) {
|
||||
@@ -146,6 +145,9 @@ static void delete_frq(nghttp3_ringbuf *frq, const nghttp3_mem *mem) {
|
||||
case NGHTTP3_FRAME_HEADERS:
|
||||
nghttp3_frame_headers_free(&frent->fr.headers, mem);
|
||||
break;
|
||||
case NGHTTP3_FRAME_PRIORITY_UPDATE:
|
||||
nghttp3_frame_priority_update_free(&frent->fr.priority_update, mem);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -188,7 +190,7 @@ nghttp3_ssize nghttp3_read_varint(nghttp3_varint_read_state *rvint,
|
||||
if (rvint->left == 0) {
|
||||
assert(rvint->acc == 0);
|
||||
|
||||
rvint->left = nghttp3_get_varint_len(src);
|
||||
rvint->left = nghttp3_get_varintlen(src);
|
||||
if (rvint->left <= srclen) {
|
||||
rvint->acc = nghttp3_get_varint(&nread, src);
|
||||
rvint->left = 0;
|
||||
@@ -248,7 +250,7 @@ int nghttp3_stream_fill_outq(nghttp3_stream *stream) {
|
||||
int data_eof;
|
||||
int rv;
|
||||
|
||||
for (; nghttp3_ringbuf_len(frq) && !nghttp3_stream_outq_is_full(stream) &&
|
||||
for (; nghttp3_ringbuf_len(frq) &&
|
||||
stream->unsent_bytes < NGHTTP3_MIN_UNSENT_BYTES;) {
|
||||
frent = nghttp3_ringbuf_get(frq, 0);
|
||||
|
||||
@@ -289,6 +291,8 @@ int nghttp3_stream_fill_outq(nghttp3_stream *stream) {
|
||||
if (rv != 0) {
|
||||
return rv;
|
||||
}
|
||||
nghttp3_frame_priority_update_free(&frent->fr.priority_update,
|
||||
stream->mem);
|
||||
break;
|
||||
default:
|
||||
/* TODO Not implemented */
|
||||
@@ -308,7 +312,7 @@ static void typed_buf_shared_init(nghttp3_typed_buf *tbuf,
|
||||
}
|
||||
|
||||
int nghttp3_stream_write_stream_type(nghttp3_stream *stream) {
|
||||
size_t len = nghttp3_put_varint_len((int64_t)stream->type);
|
||||
size_t len = nghttp3_put_varintlen((int64_t)stream->type);
|
||||
nghttp3_buf *chunk;
|
||||
nghttp3_typed_buf tbuf;
|
||||
int rv;
|
||||
@@ -351,10 +355,18 @@ int nghttp3_stream_write_settings(nghttp3_stream *stream,
|
||||
iv[2].id = NGHTTP3_SETTINGS_ID_QPACK_BLOCKED_STREAMS;
|
||||
iv[2].value = local_settings->qpack_blocked_streams;
|
||||
|
||||
if (local_settings->h3_datagram) {
|
||||
iv[fr.settings.niv].id = NGHTTP3_SETTINGS_ID_H3_DATAGRAM;
|
||||
iv[fr.settings.niv].value = 1;
|
||||
|
||||
++fr.settings.niv;
|
||||
}
|
||||
|
||||
if (local_settings->enable_connect_protocol) {
|
||||
iv[fr.settings.niv].id = NGHTTP3_SETTINGS_ID_ENABLE_CONNECT_PROTOCOL;
|
||||
iv[fr.settings.niv].value = 1;
|
||||
|
||||
++fr.settings.niv;
|
||||
iv[3].id = NGHTTP3_SETTINGS_ID_ENABLE_CONNECT_PROTOCOL;
|
||||
iv[3].value = 1;
|
||||
}
|
||||
|
||||
len = nghttp3_frame_write_settings_len(&fr.settings.hd.length, &fr.settings);
|
||||
@@ -453,8 +465,8 @@ int nghttp3_stream_write_header_block(nghttp3_stream *stream,
|
||||
|
||||
nghttp3_buf_wrap_init(&pbuf, raw_pbuf, sizeof(raw_pbuf));
|
||||
|
||||
rv = nghttp3_qpack_encoder_encode(qenc, &pbuf, rbuf, ebuf,
|
||||
stream->node.nid.id, nva, nvlen);
|
||||
rv = nghttp3_qpack_encoder_encode(qenc, &pbuf, rbuf, ebuf, stream->node.id,
|
||||
nva, nvlen);
|
||||
if (rv != 0) {
|
||||
goto fail;
|
||||
}
|
||||
@@ -574,8 +586,8 @@ int nghttp3_stream_write_data(nghttp3_stream *stream, int *peof,
|
||||
|
||||
*peof = 0;
|
||||
|
||||
sveccnt = read_data(conn, stream->node.nid.id, vec, nghttp3_arraylen(vec),
|
||||
&flags, conn->user_data, stream->user_data);
|
||||
sveccnt = read_data(conn, stream->node.id, vec, nghttp3_arraylen(vec), &flags,
|
||||
conn->user_data, stream->user_data);
|
||||
if (sveccnt < 0) {
|
||||
if (sveccnt == NGHTTP3_ERR_WOULDBLOCK) {
|
||||
stream->flags |= NGHTTP3_STREAM_FLAG_READ_DATA_BLOCKED;
|
||||
@@ -691,11 +703,6 @@ int nghttp3_stream_write_qpack_decoder_stream(nghttp3_stream *stream) {
|
||||
return nghttp3_stream_outq_add(stream, &tbuf);
|
||||
}
|
||||
|
||||
int nghttp3_stream_outq_is_full(nghttp3_stream *stream) {
|
||||
/* TODO Verify that the limit is reasonable. */
|
||||
return nghttp3_ringbuf_len(&stream->outq) >= 1024;
|
||||
}
|
||||
|
||||
int nghttp3_stream_outq_add(nghttp3_stream *stream,
|
||||
const nghttp3_typed_buf *tbuf) {
|
||||
nghttp3_ringbuf *outq = &stream->outq;
|
||||
@@ -809,11 +816,11 @@ int nghttp3_stream_require_schedule(nghttp3_stream *stream) {
|
||||
!(stream->flags & NGHTTP3_STREAM_FLAG_READ_DATA_BLOCKED));
|
||||
}
|
||||
|
||||
nghttp3_ssize nghttp3_stream_writev(nghttp3_stream *stream, int *pfin,
|
||||
nghttp3_vec *vec, size_t veccnt) {
|
||||
size_t nghttp3_stream_writev(nghttp3_stream *stream, int *pfin,
|
||||
nghttp3_vec *vec, size_t veccnt) {
|
||||
nghttp3_ringbuf *outq = &stream->outq;
|
||||
size_t len = nghttp3_ringbuf_len(outq);
|
||||
size_t i;
|
||||
size_t i = stream->outq_idx;
|
||||
uint64_t offset = stream->outq_offset;
|
||||
size_t buflen;
|
||||
nghttp3_vec *vbegin = vec, *vend = vec + veccnt;
|
||||
@@ -821,25 +828,27 @@ nghttp3_ssize nghttp3_stream_writev(nghttp3_stream *stream, int *pfin,
|
||||
|
||||
assert(veccnt > 0);
|
||||
|
||||
for (i = stream->outq_idx; i < len; ++i) {
|
||||
if (i < len) {
|
||||
tbuf = nghttp3_ringbuf_get(outq, i);
|
||||
buflen = nghttp3_buf_len(&tbuf->buf);
|
||||
if (offset >= buflen) {
|
||||
offset -= buflen;
|
||||
continue;
|
||||
|
||||
if (offset < buflen) {
|
||||
vec->base = tbuf->buf.pos + offset;
|
||||
vec->len = (size_t)(buflen - offset);
|
||||
++vec;
|
||||
} else {
|
||||
/* This is the only case that satisfies offset >= buflen */
|
||||
assert(0 == offset);
|
||||
assert(0 == buflen);
|
||||
}
|
||||
|
||||
vec->base = tbuf->buf.pos + offset;
|
||||
vec->len = (size_t)(buflen - offset);
|
||||
++vec;
|
||||
++i;
|
||||
break;
|
||||
}
|
||||
|
||||
for (; i < len && vec != vend; ++i, ++vec) {
|
||||
tbuf = nghttp3_ringbuf_get(outq, i);
|
||||
vec->base = tbuf->buf.pos;
|
||||
vec->len = nghttp3_buf_len(&tbuf->buf);
|
||||
for (; i < len && vec != vend; ++i, ++vec) {
|
||||
tbuf = nghttp3_ringbuf_get(outq, i);
|
||||
vec->base = tbuf->buf.pos;
|
||||
vec->len = nghttp3_buf_len(&tbuf->buf);
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO Rework this if we have finished implementing HTTP
|
||||
@@ -847,10 +856,10 @@ nghttp3_ssize nghttp3_stream_writev(nghttp3_stream *stream, int *pfin,
|
||||
*pfin = nghttp3_ringbuf_len(&stream->frq) == 0 && i == len &&
|
||||
(stream->flags & NGHTTP3_STREAM_FLAG_WRITE_END_STREAM);
|
||||
|
||||
return vec - vbegin;
|
||||
return (size_t)(vec - vbegin);
|
||||
}
|
||||
|
||||
int nghttp3_stream_add_outq_offset(nghttp3_stream *stream, size_t n) {
|
||||
void nghttp3_stream_add_outq_offset(nghttp3_stream *stream, size_t n) {
|
||||
nghttp3_ringbuf *outq = &stream->outq;
|
||||
size_t i;
|
||||
size_t len = nghttp3_ringbuf_len(outq);
|
||||
@@ -874,8 +883,6 @@ int nghttp3_stream_add_outq_offset(nghttp3_stream *stream, size_t n) {
|
||||
stream->unsent_bytes -= n;
|
||||
stream->outq_idx = i;
|
||||
stream->outq_offset = offset;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nghttp3_stream_outq_write_done(nghttp3_stream *stream) {
|
||||
@@ -885,8 +892,8 @@ int nghttp3_stream_outq_write_done(nghttp3_stream *stream) {
|
||||
return len == 0 || stream->outq_idx >= len;
|
||||
}
|
||||
|
||||
static int stream_pop_outq_entry(nghttp3_stream *stream,
|
||||
nghttp3_typed_buf *tbuf) {
|
||||
static void stream_pop_outq_entry(nghttp3_stream *stream,
|
||||
nghttp3_typed_buf *tbuf) {
|
||||
nghttp3_ringbuf *chunks = &stream->chunks;
|
||||
nghttp3_buf *chunk;
|
||||
|
||||
@@ -915,13 +922,10 @@ static int stream_pop_outq_entry(nghttp3_stream *stream,
|
||||
}
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
abort();
|
||||
nghttp3_unreachable();
|
||||
};
|
||||
|
||||
nghttp3_ringbuf_pop_front(&stream->outq);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nghttp3_stream_add_ack_offset(nghttp3_stream *stream, uint64_t n) {
|
||||
@@ -940,7 +944,7 @@ int nghttp3_stream_add_ack_offset(nghttp3_stream *stream, uint64_t n) {
|
||||
if (tbuf->type == NGHTTP3_BUF_TYPE_ALIEN) {
|
||||
nack = nghttp3_min(offset, (uint64_t)buflen) - stream->ack_done;
|
||||
if (stream->callbacks.acked_data) {
|
||||
rv = stream->callbacks.acked_data(stream, stream->node.nid.id, nack,
|
||||
rv = stream->callbacks.acked_data(stream, stream->node.id, nack,
|
||||
stream->user_data);
|
||||
if (rv != 0) {
|
||||
return NGHTTP3_ERR_CALLBACK_FAILURE;
|
||||
@@ -950,10 +954,7 @@ int nghttp3_stream_add_ack_offset(nghttp3_stream *stream, uint64_t n) {
|
||||
}
|
||||
|
||||
if (offset >= buflen) {
|
||||
rv = stream_pop_outq_entry(stream, tbuf);
|
||||
if (rv != 0) {
|
||||
return rv;
|
||||
}
|
||||
stream_pop_outq_entry(stream, tbuf);
|
||||
|
||||
offset -= buflen;
|
||||
++npopped;
|
||||
@@ -1221,8 +1222,7 @@ int nghttp3_stream_transit_rx_http_state(nghttp3_stream *stream,
|
||||
case NGHTTP3_HTTP_STATE_RESP_END:
|
||||
return NGHTTP3_ERR_MALFORMED_HTTP_MESSAGING;
|
||||
default:
|
||||
assert(0);
|
||||
abort();
|
||||
nghttp3_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+13
-16
@@ -50,13 +50,13 @@
|
||||
#define NGHTTP3_STREAM_MIN_WRITELEN 800
|
||||
|
||||
/* nghttp3_stream_type is unidirectional stream type. */
|
||||
typedef enum nghttp3_stream_type {
|
||||
NGHTTP3_STREAM_TYPE_CONTROL = 0x00,
|
||||
NGHTTP3_STREAM_TYPE_PUSH = 0x01,
|
||||
NGHTTP3_STREAM_TYPE_QPACK_ENCODER = 0x02,
|
||||
NGHTTP3_STREAM_TYPE_QPACK_DECODER = 0x03,
|
||||
NGHTTP3_STREAM_TYPE_UNKNOWN = UINT64_MAX,
|
||||
} nghttp3_stream_type;
|
||||
typedef uint64_t nghttp3_stream_type;
|
||||
|
||||
#define NGHTTP3_STREAM_TYPE_CONTROL 0x00
|
||||
#define NGHTTP3_STREAM_TYPE_PUSH 0x01
|
||||
#define NGHTTP3_STREAM_TYPE_QPACK_ENCODER 0x02
|
||||
#define NGHTTP3_STREAM_TYPE_QPACK_DECODER 0x03
|
||||
#define NGHTTP3_STREAM_TYPE_UNKNOWN UINT64_MAX
|
||||
|
||||
typedef enum nghttp3_ctrl_stream_state {
|
||||
NGHTTP3_CTRL_STREAM_STATE_FRAME_TYPE,
|
||||
@@ -195,9 +195,8 @@ typedef struct nghttp3_http_state {
|
||||
/* recv_content_length is the number of body bytes received so
|
||||
far. */
|
||||
int64_t recv_content_length;
|
||||
nghttp3_pri pri;
|
||||
uint32_t flags;
|
||||
/* pri is a stream priority produced by nghttp3_pri_to_uint8. */
|
||||
uint8_t pri;
|
||||
} nghttp3_http_state;
|
||||
|
||||
struct nghttp3_stream {
|
||||
@@ -257,7 +256,7 @@ struct nghttp3_stream {
|
||||
};
|
||||
};
|
||||
|
||||
nghttp3_objalloc_def(stream, nghttp3_stream, oplent);
|
||||
nghttp3_objalloc_decl(stream, nghttp3_stream, oplent);
|
||||
|
||||
typedef struct nghttp3_frame_entry {
|
||||
nghttp3_frame fr;
|
||||
@@ -272,7 +271,7 @@ typedef struct nghttp3_frame_entry {
|
||||
} nghttp3_frame_entry;
|
||||
|
||||
int nghttp3_stream_new(nghttp3_stream **pstream, int64_t stream_id,
|
||||
uint64_t seq, const nghttp3_stream_callbacks *callbacks,
|
||||
const nghttp3_stream_callbacks *callbacks,
|
||||
nghttp3_objalloc *out_chunk_objalloc,
|
||||
nghttp3_objalloc *stream_objalloc,
|
||||
const nghttp3_mem *mem);
|
||||
@@ -293,13 +292,11 @@ int nghttp3_stream_fill_outq(nghttp3_stream *stream);
|
||||
|
||||
int nghttp3_stream_write_stream_type(nghttp3_stream *stream);
|
||||
|
||||
nghttp3_ssize nghttp3_stream_writev(nghttp3_stream *stream, int *pfin,
|
||||
nghttp3_vec *vec, size_t veccnt);
|
||||
size_t nghttp3_stream_writev(nghttp3_stream *stream, int *pfin,
|
||||
nghttp3_vec *vec, size_t veccnt);
|
||||
|
||||
int nghttp3_stream_write_qpack_decoder_stream(nghttp3_stream *stream);
|
||||
|
||||
int nghttp3_stream_outq_is_full(nghttp3_stream *stream);
|
||||
|
||||
int nghttp3_stream_outq_add(nghttp3_stream *stream,
|
||||
const nghttp3_typed_buf *tbuf);
|
||||
|
||||
@@ -331,7 +328,7 @@ nghttp3_buf *nghttp3_stream_get_chunk(nghttp3_stream *stream);
|
||||
|
||||
int nghttp3_stream_is_blocked(nghttp3_stream *stream);
|
||||
|
||||
int nghttp3_stream_add_outq_offset(nghttp3_stream *stream, size_t n);
|
||||
void nghttp3_stream_add_outq_offset(nghttp3_stream *stream, size_t n);
|
||||
|
||||
/*
|
||||
* nghttp3_stream_outq_write_done returns nonzero if all contents in
|
||||
|
||||
+8
-23
@@ -31,26 +31,12 @@
|
||||
#include "nghttp3_conn.h"
|
||||
#include "nghttp3_conv.h"
|
||||
|
||||
nghttp3_node_id *nghttp3_node_id_init(nghttp3_node_id *nid,
|
||||
nghttp3_node_id_type type, int64_t id) {
|
||||
nid->type = type;
|
||||
nid->id = id;
|
||||
return nid;
|
||||
}
|
||||
|
||||
int nghttp3_node_id_eq(const nghttp3_node_id *a, const nghttp3_node_id *b) {
|
||||
return a->type == b->type && a->id == b->id;
|
||||
}
|
||||
|
||||
void nghttp3_tnode_init(nghttp3_tnode *tnode, const nghttp3_node_id *nid,
|
||||
uint64_t seq, uint8_t pri) {
|
||||
assert(nghttp3_pri_uint8_urgency(pri) < NGHTTP3_URGENCY_LEVELS);
|
||||
|
||||
void nghttp3_tnode_init(nghttp3_tnode *tnode, int64_t id) {
|
||||
tnode->pe.index = NGHTTP3_PQ_BAD_INDEX;
|
||||
tnode->nid = *nid;
|
||||
tnode->seq = seq;
|
||||
tnode->id = id;
|
||||
tnode->cycle = 0;
|
||||
tnode->pri = pri;
|
||||
tnode->pri.urgency = NGHTTP3_DEFAULT_URGENCY;
|
||||
tnode->pri.inc = 0;
|
||||
}
|
||||
|
||||
void nghttp3_tnode_free(nghttp3_tnode *tnode) { (void)tnode; }
|
||||
@@ -86,12 +72,11 @@ int nghttp3_tnode_schedule(nghttp3_tnode *tnode, nghttp3_pq *pq,
|
||||
uint64_t penalty = nwrite / NGHTTP3_STREAM_MIN_WRITELEN;
|
||||
|
||||
if (tnode->pe.index == NGHTTP3_PQ_BAD_INDEX) {
|
||||
tnode->cycle = pq_get_first_cycle(pq) +
|
||||
((nwrite == 0 || !nghttp3_pri_uint8_inc(tnode->pri))
|
||||
? 0
|
||||
: nghttp3_max(1, penalty));
|
||||
tnode->cycle =
|
||||
pq_get_first_cycle(pq) +
|
||||
((nwrite == 0 || !tnode->pri.inc) ? 0 : nghttp3_max(1, penalty));
|
||||
} else if (nwrite > 0) {
|
||||
if (!nghttp3_pri_uint8_inc(tnode->pri) || nghttp3_pq_size(pq) == 1) {
|
||||
if (!tnode->pri.inc || nghttp3_pq_size(pq) == 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+3
-20
@@ -35,33 +35,16 @@
|
||||
|
||||
#define NGHTTP3_TNODE_MAX_CYCLE_GAP (1llu << 24)
|
||||
|
||||
typedef enum nghttp3_node_id_type {
|
||||
NGHTTP3_NODE_ID_TYPE_STREAM = 0x00,
|
||||
NGHTTP3_NODE_ID_TYPE_PUSH = 0x01,
|
||||
} nghttp3_node_id_type;
|
||||
|
||||
typedef struct nghttp3_node_id {
|
||||
nghttp3_node_id_type type;
|
||||
int64_t id;
|
||||
} nghttp3_node_id;
|
||||
|
||||
nghttp3_node_id *nghttp3_node_id_init(nghttp3_node_id *nid,
|
||||
nghttp3_node_id_type type, int64_t id);
|
||||
|
||||
int nghttp3_node_id_eq(const nghttp3_node_id *a, const nghttp3_node_id *b);
|
||||
|
||||
typedef struct nghttp3_tnode {
|
||||
nghttp3_pq_entry pe;
|
||||
size_t num_children;
|
||||
nghttp3_node_id nid;
|
||||
uint64_t seq;
|
||||
int64_t id;
|
||||
uint64_t cycle;
|
||||
/* pri is a stream priority produced by nghttp3_pri_to_uint8. */
|
||||
uint8_t pri;
|
||||
nghttp3_pri pri;
|
||||
} nghttp3_tnode;
|
||||
|
||||
void nghttp3_tnode_init(nghttp3_tnode *tnode, const nghttp3_node_id *nid,
|
||||
uint64_t seq, uint8_t pri);
|
||||
void nghttp3_tnode_init(nghttp3_tnode *tnode, int64_t id);
|
||||
|
||||
void nghttp3_tnode_free(nghttp3_tnode *tnode);
|
||||
|
||||
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* nghttp3
|
||||
*
|
||||
* Copyright (c) 2022 nghttp3 contributors
|
||||
* Copyright (c) 2022 ngtcp2 contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#include "nghttp3_unreachable.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#endif /* HAVE_UNISTD_H */
|
||||
#include <stdlib.h>
|
||||
#ifdef WIN32
|
||||
# include <io.h>
|
||||
#endif /* WIN32 */
|
||||
|
||||
void nghttp3_unreachable_fail(const char *file, int line, const char *func) {
|
||||
char *buf;
|
||||
size_t buflen;
|
||||
int rv;
|
||||
|
||||
#define NGHTTP3_UNREACHABLE_TEMPLATE "%s:%d %s: Unreachable.\n"
|
||||
|
||||
rv = snprintf(NULL, 0, NGHTTP3_UNREACHABLE_TEMPLATE, file, line, func);
|
||||
if (rv < 0) {
|
||||
abort();
|
||||
}
|
||||
|
||||
/* here we explicitly use system malloc */
|
||||
buflen = (size_t)rv + 1;
|
||||
buf = malloc(buflen);
|
||||
if (buf == NULL) {
|
||||
abort();
|
||||
}
|
||||
|
||||
rv = snprintf(buf, buflen, NGHTTP3_UNREACHABLE_TEMPLATE, file, line, func);
|
||||
if (rv < 0) {
|
||||
abort();
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
while (write(STDERR_FILENO, buf, (size_t)rv) == -1 && errno == EINTR)
|
||||
;
|
||||
#else /* WIN32 */
|
||||
_write(_fileno(stderr), buf, (unsigned int)rv);
|
||||
#endif /* WIN32 */
|
||||
|
||||
free(buf);
|
||||
|
||||
abort();
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* nghttp3
|
||||
*
|
||||
* Copyright (c) 2022 nghttp3 contributors
|
||||
* Copyright (c) 2022 ngtcp2 contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef NGHTTP3_UNREACHABLE_H
|
||||
#define NGHTTP3_UNREACHABLE_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
||||
#include <nghttp3/nghttp3.h>
|
||||
|
||||
#ifdef __FILE_NAME__
|
||||
# define NGHTTP3_FILE_NAME __FILE_NAME__
|
||||
#else /* !__FILE_NAME__ */
|
||||
# define NGHTTP3_FILE_NAME "(file)"
|
||||
#endif /* !__FILE_NAME__ */
|
||||
|
||||
#define nghttp3_unreachable() \
|
||||
nghttp3_unreachable_fail(NGHTTP3_FILE_NAME, __LINE__, __func__)
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(noreturn)
|
||||
#endif /* _MSC_VER */
|
||||
void nghttp3_unreachable_fail(const char *file, int line, const char *func)
|
||||
#ifndef _MSC_VER
|
||||
__attribute__((noreturn))
|
||||
#endif /* !_MSC_VER */
|
||||
;
|
||||
|
||||
#endif /* NGHTTP3_UNREACHABLE_H */
|
||||
Vendored
+1146
File diff suppressed because it is too large.
Load diff
Vendored
+409
@@ -0,0 +1,409 @@
|
||||
/*
|
||||
* sfparse
|
||||
*
|
||||
* Copyright (c) 2023 sfparse contributors
|
||||
* Copyright (c) 2019 nghttp3 contributors
|
||||
* Copyright (c) 2015 nghttp2 contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef SFPARSE_H
|
||||
#define SFPARSE_H
|
||||
|
||||
/* Define WIN32 when build target is Win32 API (borrowed from
|
||||
libcurl) */
|
||||
#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
|
||||
# define WIN32
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER < 1800)
|
||||
/* MSVC < 2013 does not have inttypes.h because it is not C99
|
||||
compliant. See compiler macros and version number in
|
||||
https://sourceforge.net/p/predef/wiki/Compilers/ */
|
||||
# include <stdint.h>
|
||||
#else /* !defined(_MSC_VER) || (_MSC_VER >= 1800) */
|
||||
# include <inttypes.h>
|
||||
#endif /* !defined(_MSC_VER) || (_MSC_VER >= 1800) */
|
||||
#include <sys/types.h>
|
||||
#include <stddef.h>
|
||||
|
||||
/**
|
||||
* @enum
|
||||
*
|
||||
* :type:`sf_type` defines value type.
|
||||
*/
|
||||
typedef enum sf_type {
|
||||
/**
|
||||
* :enum:`SF_TYPE_BOOLEAN` indicates boolean type.
|
||||
*/
|
||||
SF_TYPE_BOOLEAN,
|
||||
/**
|
||||
* :enum:`SF_TYPE_INTEGER` indicates integer type.
|
||||
*/
|
||||
SF_TYPE_INTEGER,
|
||||
/**
|
||||
* :enum:`SF_TYPE_DECIMAL` indicates decimal type.
|
||||
*/
|
||||
SF_TYPE_DECIMAL,
|
||||
/**
|
||||
* :enum:`SF_TYPE_STRING` indicates string type.
|
||||
*/
|
||||
SF_TYPE_STRING,
|
||||
/**
|
||||
* :enum:`SF_TYPE_TOKEN` indicates token type.
|
||||
*/
|
||||
SF_TYPE_TOKEN,
|
||||
/**
|
||||
* :enum:`SF_TYPE_BYTESEQ` indicates byte sequence type.
|
||||
*/
|
||||
SF_TYPE_BYTESEQ,
|
||||
/**
|
||||
* :enum:`SF_TYPE_INNER_LIST` indicates inner list type.
|
||||
*/
|
||||
SF_TYPE_INNER_LIST,
|
||||
/**
|
||||
* :enum:`SF_TYPE_DATE` indicates date type.
|
||||
*/
|
||||
SF_TYPE_DATE
|
||||
} sf_type;
|
||||
|
||||
/**
|
||||
* @macro
|
||||
*
|
||||
* :macro:`SF_ERR_PARSE_ERROR` indicates fatal parse error has
|
||||
* occurred, and it is not possible to continue the processing.
|
||||
*/
|
||||
#define SF_ERR_PARSE_ERROR -1
|
||||
|
||||
/**
|
||||
* @macro
|
||||
*
|
||||
* :macro:`SF_ERR_EOF` indicates that there is nothing left to read.
|
||||
* The context of this error varies depending on the function that
|
||||
* returns this error code.
|
||||
*/
|
||||
#define SF_ERR_EOF -2
|
||||
|
||||
/**
|
||||
* @struct
|
||||
*
|
||||
* :type:`sf_vec` stores sequence of bytes.
|
||||
*/
|
||||
typedef struct sf_vec {
|
||||
/**
|
||||
* :member:`base` points to the beginning of the sequence of bytes.
|
||||
*/
|
||||
uint8_t *base;
|
||||
/**
|
||||
* :member:`len` is the number of bytes contained in this sequence.
|
||||
*/
|
||||
size_t len;
|
||||
} sf_vec;
|
||||
|
||||
/**
|
||||
* @macro
|
||||
*
|
||||
* :macro:`SF_VALUE_FLAG_NONE` indicates no flag set.
|
||||
*/
|
||||
#define SF_VALUE_FLAG_NONE 0x0u
|
||||
|
||||
/**
|
||||
* @macro
|
||||
*
|
||||
* :macro:`SF_VALUE_FLAG_ESCAPED_STRING` indicates that a string
|
||||
* contains escaped character(s).
|
||||
*/
|
||||
#define SF_VALUE_FLAG_ESCAPED_STRING 0x1u
|
||||
|
||||
/**
|
||||
* @struct
|
||||
*
|
||||
* :type:`sf_decimal` contains decimal value.
|
||||
*/
|
||||
typedef struct sf_decimal {
|
||||
/**
|
||||
* :member:`numer` contains numerator of the decimal value.
|
||||
*/
|
||||
int64_t numer;
|
||||
/**
|
||||
* :member:`denom` contains denominator of the decimal value.
|
||||
*/
|
||||
int64_t denom;
|
||||
} sf_decimal;
|
||||
|
||||
/**
|
||||
* @struct
|
||||
*
|
||||
* :type:`sf_value` stores a Structured Field item. For Inner List,
|
||||
* only type is set to :enum:`sf_type.SF_TYPE_INNER_LIST`. In order
|
||||
* to read the items contained in an inner list, call
|
||||
* `sf_parser_inner_list`.
|
||||
*/
|
||||
typedef struct sf_value {
|
||||
/**
|
||||
* :member:`type` is the type of the value contained in this
|
||||
* particular object.
|
||||
*/
|
||||
sf_type type;
|
||||
/**
|
||||
* :member:`flags` is bitwise OR of one or more of
|
||||
* :macro:`SF_VALUE_FLAG_* <SF_VALUE_FLAG_NONE>`.
|
||||
*/
|
||||
uint32_t flags;
|
||||
/**
|
||||
* @anonunion_start
|
||||
*
|
||||
* @sf_value_value
|
||||
*/
|
||||
union {
|
||||
/**
|
||||
* :member:`boolean` contains boolean value if :member:`type` ==
|
||||
* :enum:`sf_type.SF_TYPE_BOOLEAN`. 1 indicates true, and 0
|
||||
* indicates false.
|
||||
*/
|
||||
int boolean;
|
||||
/**
|
||||
* :member:`integer` contains integer value if :member:`type` is
|
||||
* either :enum:`sf_type.SF_TYPE_INTEGER` or
|
||||
* :enum:`sf_type.SF_TYPE_DATE`.
|
||||
*/
|
||||
int64_t integer;
|
||||
/**
|
||||
* :member:`decimal` contains decimal value if :member:`type` ==
|
||||
* :enum:`sf_type.SF_TYPE_DECIMAL`.
|
||||
*/
|
||||
sf_decimal decimal;
|
||||
/**
|
||||
* :member:`vec` contains sequence of bytes if :member:`type` is
|
||||
* either :enum:`sf_type.SF_TYPE_STRING`,
|
||||
* :enum:`sf_type.SF_TYPE_TOKEN`, or
|
||||
* :enum:`sf_type.SF_TYPE_BYTESEQ`.
|
||||
*
|
||||
* For :enum:`sf_type.SF_TYPE_STRING`, this field contains one or
|
||||
* more escaped characters if :member:`flags` has
|
||||
* :macro:`SF_VALUE_FLAG_ESCAPED_STRING` set. To unescape the
|
||||
* string, use `sf_unescape`.
|
||||
*
|
||||
* For :enum:`sf_type.SF_TYPE_BYTESEQ`, this field contains base64
|
||||
* encoded string. To decode this byte string, use
|
||||
* `sf_base64decode`.
|
||||
*
|
||||
* If :member:`vec.len <sf_vec.len>` == 0, :member:`vec.base
|
||||
* <sf_vec.base>` is guaranteed to be NULL.
|
||||
*/
|
||||
sf_vec vec;
|
||||
/**
|
||||
* @anonunion_end
|
||||
*/
|
||||
};
|
||||
} sf_value;
|
||||
|
||||
/**
|
||||
* @struct
|
||||
*
|
||||
* :type:`sf_parser` is the Structured Field Values parser. Use
|
||||
* `sf_parser_init` to initialize it.
|
||||
*/
|
||||
typedef struct sf_parser {
|
||||
/* all fields are private */
|
||||
const uint8_t *pos;
|
||||
const uint8_t *end;
|
||||
uint32_t state;
|
||||
} sf_parser;
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* `sf_parser_init` initializes |sfp| with the given buffer pointed by
|
||||
* |data| of length |datalen|.
|
||||
*/
|
||||
void sf_parser_init(sf_parser *sfp, const uint8_t *data, size_t datalen);
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* `sf_parser_param` reads a parameter. If this function returns 0,
|
||||
* it stores parameter key and value in |dest_key| and |dest_value|
|
||||
* respectively, if they are not NULL.
|
||||
*
|
||||
* This function does no effort to find duplicated keys. Same key may
|
||||
* be reported more than once.
|
||||
*
|
||||
* Caller should keep calling this function until it returns negative
|
||||
* error code. If it returns :macro:`SF_ERR_EOF`, all parameters have
|
||||
* read, and caller can continue to read rest of the values. If it
|
||||
* returns :macro:`SF_ERR_PARSE_ERROR`, it encountered fatal error
|
||||
* while parsing field value.
|
||||
*/
|
||||
int sf_parser_param(sf_parser *sfp, sf_vec *dest_key, sf_value *dest_value);
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* `sf_parser_dict` reads the next dictionary key and value pair. If
|
||||
* this function returns 0, it stores the key and value in |dest_key|
|
||||
* and |dest_value| respectively, if they are not NULL.
|
||||
*
|
||||
* Caller can optionally read parameters attached to the pair by
|
||||
* calling `sf_parser_param`.
|
||||
*
|
||||
* This function does no effort to find duplicated keys. Same key may
|
||||
* be reported more than once.
|
||||
*
|
||||
* Caller should keep calling this function until it returns negative
|
||||
* error code. If it returns :macro:`SF_ERR_EOF`, all key and value
|
||||
* pairs have been read, and there is nothing left to read.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* :macro:`SF_ERR_EOF`
|
||||
* All values in the dictionary have read.
|
||||
* :macro:`SF_ERR_PARSE_ERROR`
|
||||
* It encountered fatal error while parsing field value.
|
||||
*/
|
||||
int sf_parser_dict(sf_parser *sfp, sf_vec *dest_key, sf_value *dest_value);
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* `sf_parser_list` reads the next list item. If this function
|
||||
* returns 0, it stores the item in |dest| if it is not NULL.
|
||||
*
|
||||
* Caller can optionally read parameters attached to the item by
|
||||
* calling `sf_parser_param`.
|
||||
*
|
||||
* Caller should keep calling this function until it returns negative
|
||||
* error code. If it returns :macro:`SF_ERR_EOF`, all values in the
|
||||
* list have been read, and there is nothing left to read.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* :macro:`SF_ERR_EOF`
|
||||
* All values in the list have read.
|
||||
* :macro:`SF_ERR_PARSE_ERROR`
|
||||
* It encountered fatal error while parsing field value.
|
||||
*/
|
||||
int sf_parser_list(sf_parser *sfp, sf_value *dest);
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* `sf_parser_item` reads a single item. If this function returns 0,
|
||||
* it stores the item in |dest| if it is not NULL.
|
||||
*
|
||||
* This function is only used for the field value that consists of a
|
||||
* single item.
|
||||
*
|
||||
* Caller can optionally read parameters attached to the item by
|
||||
* calling `sf_parser_param`.
|
||||
*
|
||||
* Caller should call this function again to make sure that there is
|
||||
* nothing left to read. If this 2nd function call returns
|
||||
* :macro:`SF_ERR_EOF`, all data have been processed successfully.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* :macro:`SF_ERR_EOF`
|
||||
* There is nothing left to read.
|
||||
* :macro:`SF_ERR_PARSE_ERROR`
|
||||
* It encountered fatal error while parsing field value.
|
||||
*/
|
||||
int sf_parser_item(sf_parser *sfp, sf_value *dest);
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* `sf_parser_inner_list` reads the next inner list item. If this
|
||||
* function returns 0, it stores the item in |dest| if it is not NULL.
|
||||
*
|
||||
* Caller can optionally read parameters attached to the item by
|
||||
* calling `sf_parser_param`.
|
||||
*
|
||||
* Caller should keep calling this function until it returns negative
|
||||
* error code. If it returns :macro:`SF_ERR_EOF`, all values in this
|
||||
* inner list have been read, and caller can optionally read
|
||||
* parameters attached to this inner list by calling
|
||||
* `sf_parser_param`. Then caller can continue to read rest of the
|
||||
* values.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* :macro:`SF_ERR_EOF`
|
||||
* All values in the inner list have read.
|
||||
* :macro:`SF_ERR_PARSE_ERROR`
|
||||
* It encountered fatal error while parsing field value.
|
||||
*/
|
||||
int sf_parser_inner_list(sf_parser *sfp, sf_value *dest);
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* `sf_unescape` copies |src| to |dest| by removing escapes (``\``).
|
||||
* |src| should be the pointer to :member:`sf_value.vec` of type
|
||||
* :enum:`sf_type.SF_TYPE_STRING` produced by either `sf_parser_dict`,
|
||||
* `sf_parser_list`, `sf_parser_inner_list`, `sf_parser_item`, or
|
||||
* `sf_parser_param`, otherwise the behavior is undefined.
|
||||
*
|
||||
* :member:`dest->base <sf_vec.base>` must point to the buffer that
|
||||
* has sufficient space to store the unescaped string.
|
||||
*
|
||||
* If there is no escape character in |src|, |*src| is assigned to
|
||||
* |*dest|. This includes the case that :member:`src->len
|
||||
* <sf_vec.len>` == 0.
|
||||
*
|
||||
* This function sets the length of unescaped string to
|
||||
* :member:`dest->len <sf_vec.len>`.
|
||||
*/
|
||||
void sf_unescape(sf_vec *dest, const sf_vec *src);
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* `sf_base64decode` decodes Base64 encoded string |src| and writes
|
||||
* the result into |dest|. |src| should be the pointer to
|
||||
* :member:`sf_value.vec` of type :enum:`sf_type.SF_TYPE_BYTESEQ`
|
||||
* produced by either `sf_parser_dict`, `sf_parser_list`,
|
||||
* `sf_parser_inner_list`, `sf_parser_item`, or `sf_parser_param`,
|
||||
* otherwise the behavior is undefined.
|
||||
*
|
||||
* :member:`dest->base <sf_vec.base>` must point to the buffer that
|
||||
* has sufficient space to store the decoded byte string.
|
||||
*
|
||||
* If :member:`src->len <sf_vec.len>` == 0, |*src| is assigned to
|
||||
* |*dest|.
|
||||
*
|
||||
* This function sets the length of decoded byte string to
|
||||
* :member:`dest->len <sf_vec.len>`.
|
||||
*/
|
||||
void sf_base64decode(sf_vec *dest, const sf_vec *src);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SFPARSE_H */
|
||||
Vendored
+17
-6
@@ -8,14 +8,15 @@
|
||||
'ngtcp2/lib/ngtcp2_addr.c',
|
||||
'ngtcp2/lib/ngtcp2_balloc.c',
|
||||
'ngtcp2/lib/ngtcp2_bbr.c',
|
||||
'ngtcp2/lib/ngtcp2_bbr2.c',
|
||||
'ngtcp2/lib/ngtcp2_buf.c',
|
||||
'ngtcp2/lib/ngtcp2_cc.c',
|
||||
'ngtcp2/lib/ngtcp2_cid.c',
|
||||
'ngtcp2/lib/ngtcp2_conn.c',
|
||||
'ngtcp2/lib/ngtcp2_conv.c',
|
||||
'ngtcp2/lib/ngtcp2_conversion.c',
|
||||
'ngtcp2/lib/ngtcp2_crypto.c',
|
||||
'ngtcp2/lib/ngtcp2_err.c',
|
||||
'ngtcp2/lib/ngtcp2_frame_chain.c',
|
||||
'ngtcp2/lib/ngtcp2_gaptr.c',
|
||||
'ngtcp2/lib/ngtcp2_idtr.c',
|
||||
'ngtcp2/lib/ngtcp2_ksl.c',
|
||||
@@ -38,13 +39,14 @@
|
||||
'ngtcp2/lib/ngtcp2_rtb.c',
|
||||
'ngtcp2/lib/ngtcp2_str.c',
|
||||
'ngtcp2/lib/ngtcp2_strm.c',
|
||||
'ngtcp2/lib/ngtcp2_unreachable.c',
|
||||
'ngtcp2/lib/ngtcp2_vec.c',
|
||||
'ngtcp2/lib/ngtcp2_version.c',
|
||||
'ngtcp2/lib/ngtcp2_window_filter.c',
|
||||
'ngtcp2/crypto/shared.c'
|
||||
],
|
||||
'ngtcp2_sources_openssl': [
|
||||
'ngtcp2/crypto/openssl/openssl.c'
|
||||
'ngtcp2_sources_quictls': [
|
||||
'ngtcp2/crypto/quictls/quictls.c'
|
||||
],
|
||||
'ngtcp2_sources_boringssl': [
|
||||
'ngtcp2/crypto/boringssl/boringssl.c'
|
||||
@@ -75,8 +77,11 @@
|
||||
'nghttp3/lib/nghttp3_str.c',
|
||||
'nghttp3/lib/nghttp3_stream.c',
|
||||
'nghttp3/lib/nghttp3_tnode.c',
|
||||
'nghttp3/lib/nghttp3_unreachable.c',
|
||||
'nghttp3/lib/nghttp3_vec.c',
|
||||
'nghttp3/lib/nghttp3_version.c'
|
||||
'nghttp3/lib/nghttp3_version.c',
|
||||
# sfparse is also used by nghttp2 and is included by nghttp2.gyp
|
||||
# 'nghttp3/lib/sfparse.c'
|
||||
]
|
||||
},
|
||||
'targets': [
|
||||
@@ -100,6 +105,9 @@
|
||||
'../openssl/openssl.gyp:openssl'
|
||||
]
|
||||
}],
|
||||
['OS!="win"', {
|
||||
'defines': ['HAVE_UNISTD_H']
|
||||
}],
|
||||
['OS=="win"', {
|
||||
'defines': [
|
||||
'WIN32',
|
||||
@@ -132,7 +140,7 @@
|
||||
},
|
||||
'sources': [
|
||||
'<@(ngtcp2_sources)',
|
||||
'<@(ngtcp2_sources_openssl)',
|
||||
'<@(ngtcp2_sources_quictls)',
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -144,7 +152,7 @@
|
||||
],
|
||||
'defines': [
|
||||
'BUILDING_NGHTTP3',
|
||||
'NGHTTP3_STATICLIB'
|
||||
'NGHTTP3_STATICLIB',
|
||||
],
|
||||
'dependencies': [
|
||||
'ngtcp2'
|
||||
@@ -162,6 +170,9 @@
|
||||
},
|
||||
},
|
||||
}],
|
||||
['OS!="win"', {
|
||||
'defines': ['HAVE_UNISTD_H']
|
||||
}],
|
||||
['OS=="linux" or OS=="android"', {
|
||||
'defines': [
|
||||
'HAVE_ARPA_INET_H',
|
||||
|
||||
+78
-38
@@ -92,8 +92,8 @@ ngtcp2_crypto_aead *ngtcp2_crypto_aead_retry(ngtcp2_crypto_aead *aead) {
|
||||
return ngtcp2_crypto_aead_init(aead, (void *)EVP_aead_aes_128_gcm());
|
||||
}
|
||||
|
||||
static const EVP_AEAD *crypto_ssl_get_aead(SSL *ssl) {
|
||||
switch (SSL_CIPHER_get_id(SSL_get_current_cipher(ssl))) {
|
||||
static const EVP_AEAD *crypto_cipher_id_get_aead(uint32_t cipher_id) {
|
||||
switch (cipher_id) {
|
||||
case TLS1_CK_AES_128_GCM_SHA256:
|
||||
return EVP_aead_aes_128_gcm();
|
||||
case TLS1_CK_AES_256_GCM_SHA384:
|
||||
@@ -105,8 +105,8 @@ static const EVP_AEAD *crypto_ssl_get_aead(SSL *ssl) {
|
||||
}
|
||||
}
|
||||
|
||||
static uint64_t crypto_ssl_get_aead_max_encryption(SSL *ssl) {
|
||||
switch (SSL_CIPHER_get_id(SSL_get_current_cipher(ssl))) {
|
||||
static uint64_t crypto_cipher_id_get_aead_max_encryption(uint32_t cipher_id) {
|
||||
switch (cipher_id) {
|
||||
case TLS1_CK_AES_128_GCM_SHA256:
|
||||
case TLS1_CK_AES_256_GCM_SHA384:
|
||||
return NGTCP2_CRYPTO_MAX_ENCRYPTION_AES_GCM;
|
||||
@@ -117,8 +117,9 @@ static uint64_t crypto_ssl_get_aead_max_encryption(SSL *ssl) {
|
||||
}
|
||||
}
|
||||
|
||||
static uint64_t crypto_ssl_get_aead_max_decryption_failure(SSL *ssl) {
|
||||
switch (SSL_CIPHER_get_id(SSL_get_current_cipher(ssl))) {
|
||||
static uint64_t
|
||||
crypto_cipher_id_get_aead_max_decryption_failure(uint32_t cipher_id) {
|
||||
switch (cipher_id) {
|
||||
case TLS1_CK_AES_128_GCM_SHA256:
|
||||
case TLS1_CK_AES_256_GCM_SHA384:
|
||||
return NGTCP2_CRYPTO_MAX_DECRYPTION_FAILURE_AES_GCM;
|
||||
@@ -129,8 +130,9 @@ static uint64_t crypto_ssl_get_aead_max_decryption_failure(SSL *ssl) {
|
||||
}
|
||||
}
|
||||
|
||||
static const ngtcp2_crypto_boringssl_cipher *crypto_ssl_get_hp(SSL *ssl) {
|
||||
switch (SSL_CIPHER_get_id(SSL_get_current_cipher(ssl))) {
|
||||
static const ngtcp2_crypto_boringssl_cipher *
|
||||
crypto_cipher_id_get_hp(uint32_t cipher_id) {
|
||||
switch (cipher_id) {
|
||||
case TLS1_CK_AES_128_GCM_SHA256:
|
||||
return &crypto_cipher_aes_128;
|
||||
case TLS1_CK_AES_256_GCM_SHA384:
|
||||
@@ -142,8 +144,8 @@ static const ngtcp2_crypto_boringssl_cipher *crypto_ssl_get_hp(SSL *ssl) {
|
||||
}
|
||||
}
|
||||
|
||||
static const EVP_MD *crypto_ssl_get_md(SSL *ssl) {
|
||||
switch (SSL_CIPHER_get_id(SSL_get_current_cipher(ssl))) {
|
||||
static const EVP_MD *crypto_cipher_id_get_md(uint32_t cipher_id) {
|
||||
switch (cipher_id) {
|
||||
case TLS1_CK_AES_128_GCM_SHA256:
|
||||
case TLS1_CK_CHACHA20_POLY1305_SHA256:
|
||||
return EVP_sha256();
|
||||
@@ -154,15 +156,47 @@ static const EVP_MD *crypto_ssl_get_md(SSL *ssl) {
|
||||
}
|
||||
}
|
||||
|
||||
static int supported_cipher_id(uint32_t cipher_id) {
|
||||
switch (cipher_id) {
|
||||
case TLS1_CK_AES_128_GCM_SHA256:
|
||||
case TLS1_CK_AES_256_GCM_SHA384:
|
||||
case TLS1_CK_CHACHA20_POLY1305_SHA256:
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static ngtcp2_crypto_ctx *crypto_ctx_cipher_id(ngtcp2_crypto_ctx *ctx,
|
||||
uint32_t cipher_id) {
|
||||
ngtcp2_crypto_aead_init(&ctx->aead,
|
||||
(void *)crypto_cipher_id_get_aead(cipher_id));
|
||||
ctx->md.native_handle = (void *)crypto_cipher_id_get_md(cipher_id);
|
||||
ctx->hp.native_handle = (void *)crypto_cipher_id_get_hp(cipher_id);
|
||||
ctx->max_encryption = crypto_cipher_id_get_aead_max_encryption(cipher_id);
|
||||
ctx->max_decryption_failure =
|
||||
crypto_cipher_id_get_aead_max_decryption_failure(cipher_id);
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
ngtcp2_crypto_ctx *ngtcp2_crypto_ctx_tls(ngtcp2_crypto_ctx *ctx,
|
||||
void *tls_native_handle) {
|
||||
SSL *ssl = tls_native_handle;
|
||||
ngtcp2_crypto_aead_init(&ctx->aead, (void *)crypto_ssl_get_aead(ssl));
|
||||
ctx->md.native_handle = (void *)crypto_ssl_get_md(ssl);
|
||||
ctx->hp.native_handle = (void *)crypto_ssl_get_hp(ssl);
|
||||
ctx->max_encryption = crypto_ssl_get_aead_max_encryption(ssl);
|
||||
ctx->max_decryption_failure = crypto_ssl_get_aead_max_decryption_failure(ssl);
|
||||
return ctx;
|
||||
const SSL_CIPHER *cipher = SSL_get_current_cipher(ssl);
|
||||
uint32_t cipher_id;
|
||||
|
||||
if (cipher == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cipher_id = SSL_CIPHER_get_id(cipher);
|
||||
|
||||
if (!supported_cipher_id(cipher_id)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return crypto_ctx_cipher_id(ctx, cipher_id);
|
||||
}
|
||||
|
||||
ngtcp2_crypto_ctx *ngtcp2_crypto_ctx_tls_early(ngtcp2_crypto_ctx *ctx,
|
||||
@@ -394,15 +428,17 @@ int ngtcp2_crypto_hp_mask(uint8_t *dest, const ngtcp2_crypto_cipher *hp,
|
||||
}
|
||||
}
|
||||
|
||||
int ngtcp2_crypto_read_write_crypto_data(ngtcp2_conn *conn,
|
||||
ngtcp2_crypto_level crypto_level,
|
||||
const uint8_t *data, size_t datalen) {
|
||||
int ngtcp2_crypto_read_write_crypto_data(
|
||||
ngtcp2_conn *conn, ngtcp2_encryption_level encryption_level,
|
||||
const uint8_t *data, size_t datalen) {
|
||||
SSL *ssl = ngtcp2_conn_get_tls_native_handle(conn);
|
||||
int rv;
|
||||
int err;
|
||||
|
||||
if (SSL_provide_quic_data(
|
||||
ssl, ngtcp2_crypto_boringssl_from_ngtcp2_crypto_level(crypto_level),
|
||||
ssl,
|
||||
ngtcp2_crypto_boringssl_from_ngtcp2_encryption_level(
|
||||
encryption_level),
|
||||
data, datalen) != 1) {
|
||||
return -1;
|
||||
}
|
||||
@@ -423,7 +459,10 @@ int ngtcp2_crypto_read_write_crypto_data(ngtcp2_conn *conn,
|
||||
|
||||
SSL_reset_early_data_reject(ssl);
|
||||
|
||||
ngtcp2_conn_early_data_rejected(conn);
|
||||
rv = ngtcp2_conn_tls_early_data_rejected(conn);
|
||||
if (rv != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
goto retry;
|
||||
default:
|
||||
@@ -435,7 +474,7 @@ int ngtcp2_crypto_read_write_crypto_data(ngtcp2_conn *conn,
|
||||
return 0;
|
||||
}
|
||||
|
||||
ngtcp2_conn_handshake_completed(conn);
|
||||
ngtcp2_conn_tls_handshake_completed(conn);
|
||||
}
|
||||
|
||||
rv = SSL_process_quic_post_handshake(ssl);
|
||||
@@ -464,7 +503,7 @@ int ngtcp2_crypto_set_remote_transport_params(ngtcp2_conn *conn, void *tls) {
|
||||
|
||||
SSL_get_peer_quic_transport_params(ssl, &tp, &tplen);
|
||||
|
||||
rv = ngtcp2_conn_decode_remote_transport_params(conn, tp, tplen);
|
||||
rv = ngtcp2_conn_decode_and_set_remote_transport_params(conn, tp, tplen);
|
||||
if (rv != 0) {
|
||||
ngtcp2_conn_set_tls_error(conn, rv);
|
||||
return -1;
|
||||
@@ -482,33 +521,34 @@ int ngtcp2_crypto_set_local_transport_params(void *tls, const uint8_t *buf,
|
||||
return 0;
|
||||
}
|
||||
|
||||
ngtcp2_crypto_level ngtcp2_crypto_boringssl_from_ssl_encryption_level(
|
||||
ngtcp2_encryption_level ngtcp2_crypto_boringssl_from_ssl_encryption_level(
|
||||
enum ssl_encryption_level_t ssl_level) {
|
||||
switch (ssl_level) {
|
||||
case ssl_encryption_initial:
|
||||
return NGTCP2_CRYPTO_LEVEL_INITIAL;
|
||||
return NGTCP2_ENCRYPTION_LEVEL_INITIAL;
|
||||
case ssl_encryption_early_data:
|
||||
return NGTCP2_CRYPTO_LEVEL_EARLY;
|
||||
return NGTCP2_ENCRYPTION_LEVEL_0RTT;
|
||||
case ssl_encryption_handshake:
|
||||
return NGTCP2_CRYPTO_LEVEL_HANDSHAKE;
|
||||
return NGTCP2_ENCRYPTION_LEVEL_HANDSHAKE;
|
||||
case ssl_encryption_application:
|
||||
return NGTCP2_CRYPTO_LEVEL_APPLICATION;
|
||||
return NGTCP2_ENCRYPTION_LEVEL_1RTT;
|
||||
default:
|
||||
assert(0);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
enum ssl_encryption_level_t ngtcp2_crypto_boringssl_from_ngtcp2_crypto_level(
|
||||
ngtcp2_crypto_level crypto_level) {
|
||||
switch (crypto_level) {
|
||||
case NGTCP2_CRYPTO_LEVEL_INITIAL:
|
||||
enum ssl_encryption_level_t
|
||||
ngtcp2_crypto_boringssl_from_ngtcp2_encryption_level(
|
||||
ngtcp2_encryption_level encryption_level) {
|
||||
switch (encryption_level) {
|
||||
case NGTCP2_ENCRYPTION_LEVEL_INITIAL:
|
||||
return ssl_encryption_initial;
|
||||
case NGTCP2_CRYPTO_LEVEL_HANDSHAKE:
|
||||
case NGTCP2_ENCRYPTION_LEVEL_HANDSHAKE:
|
||||
return ssl_encryption_handshake;
|
||||
case NGTCP2_CRYPTO_LEVEL_APPLICATION:
|
||||
case NGTCP2_ENCRYPTION_LEVEL_1RTT:
|
||||
return ssl_encryption_application;
|
||||
case NGTCP2_CRYPTO_LEVEL_EARLY:
|
||||
case NGTCP2_ENCRYPTION_LEVEL_0RTT:
|
||||
return ssl_encryption_early_data;
|
||||
default:
|
||||
assert(0);
|
||||
@@ -541,7 +581,7 @@ static int set_read_secret(SSL *ssl, enum ssl_encryption_level_t bssl_level,
|
||||
size_t secretlen) {
|
||||
ngtcp2_crypto_conn_ref *conn_ref = SSL_get_app_data(ssl);
|
||||
ngtcp2_conn *conn = conn_ref->get_conn(conn_ref);
|
||||
ngtcp2_crypto_level level =
|
||||
ngtcp2_encryption_level level =
|
||||
ngtcp2_crypto_boringssl_from_ssl_encryption_level(bssl_level);
|
||||
(void)cipher;
|
||||
|
||||
@@ -558,7 +598,7 @@ static int set_write_secret(SSL *ssl, enum ssl_encryption_level_t bssl_level,
|
||||
size_t secretlen) {
|
||||
ngtcp2_crypto_conn_ref *conn_ref = SSL_get_app_data(ssl);
|
||||
ngtcp2_conn *conn = conn_ref->get_conn(conn_ref);
|
||||
ngtcp2_crypto_level level =
|
||||
ngtcp2_encryption_level level =
|
||||
ngtcp2_crypto_boringssl_from_ssl_encryption_level(bssl_level);
|
||||
(void)cipher;
|
||||
|
||||
@@ -574,7 +614,7 @@ static int add_handshake_data(SSL *ssl, enum ssl_encryption_level_t bssl_level,
|
||||
const uint8_t *data, size_t datalen) {
|
||||
ngtcp2_crypto_conn_ref *conn_ref = SSL_get_app_data(ssl);
|
||||
ngtcp2_conn *conn = conn_ref->get_conn(conn_ref);
|
||||
ngtcp2_crypto_level level =
|
||||
ngtcp2_encryption_level level =
|
||||
ngtcp2_crypto_boringssl_from_ssl_encryption_level(bssl_level);
|
||||
int rv;
|
||||
|
||||
|
||||
+126
-178
@@ -38,39 +38,16 @@ extern "C" {
|
||||
# include <ws2tcpip.h>
|
||||
#endif /* WIN32 */
|
||||
|
||||
/**
|
||||
* @macro
|
||||
*
|
||||
* :macro:`NGTCP2_CRYPTO_INITIAL_SECRETLEN` is the length of secret
|
||||
* for Initial packets.
|
||||
*/
|
||||
#define NGTCP2_CRYPTO_INITIAL_SECRETLEN 32
|
||||
|
||||
/**
|
||||
* @macro
|
||||
*
|
||||
* :macro:`NGTCP2_CRYPTO_INITIAL_KEYLEN` is the length of key for
|
||||
* Initial packets.
|
||||
*/
|
||||
#define NGTCP2_CRYPTO_INITIAL_KEYLEN 16
|
||||
|
||||
/**
|
||||
* @macro
|
||||
*
|
||||
* :macro:`NGTCP2_CRYPTO_INITIAL_IVLEN` is the length of IV for
|
||||
* Initial packets.
|
||||
*/
|
||||
#define NGTCP2_CRYPTO_INITIAL_IVLEN 12
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* `ngtcp2_crypto_ctx_tls` initializes |ctx| by extracting negotiated
|
||||
* ciphers and message digests from native TLS session
|
||||
* |tls_native_handle|. This is used for encrypting/decrypting
|
||||
* Handshake and Short header packets.
|
||||
* Handshake and 1-RTT packets. If it is unable to obtain necessary
|
||||
* data from |tls_native_handle|, this function returns NULL.
|
||||
*
|
||||
* If libngtcp2_crypto_openssl is linked, |tls_native_handle| must be
|
||||
* If libngtcp2_crypto_quictls is linked, |tls_native_handle| must be
|
||||
* a pointer to SSL object.
|
||||
*/
|
||||
NGTCP2_EXTERN ngtcp2_crypto_ctx *ngtcp2_crypto_ctx_tls(ngtcp2_crypto_ctx *ctx,
|
||||
@@ -81,10 +58,11 @@ NGTCP2_EXTERN ngtcp2_crypto_ctx *ngtcp2_crypto_ctx_tls(ngtcp2_crypto_ctx *ctx,
|
||||
*
|
||||
* `ngtcp2_crypto_ctx_tls_early` initializes |ctx| by extracting early
|
||||
* ciphers and message digests from native TLS session
|
||||
* |tls_native_handle|. This is used for encrypting/decrypting 0RTT
|
||||
* packets.
|
||||
* |tls_native_handle|. This is used for encrypting/decrypting 0-RTT
|
||||
* packets. If it is unable to obtain necessary data from
|
||||
* |tls_native_handle|, this function returns NULL.
|
||||
*
|
||||
* If libngtcp2_crypto_openssl is linked, |tls_native_handle| must be
|
||||
* If libngtcp2_crypto_quictls is linked, |tls_native_handle| must be
|
||||
* a pointer to SSL object.
|
||||
*/
|
||||
NGTCP2_EXTERN ngtcp2_crypto_ctx *
|
||||
@@ -96,7 +74,7 @@ ngtcp2_crypto_ctx_tls_early(ngtcp2_crypto_ctx *ctx, void *tls_native_handle);
|
||||
* `ngtcp2_crypto_md_init` initializes |md| with the provided
|
||||
* |md_native_handle| which is an underlying message digest object.
|
||||
*
|
||||
* If libngtcp2_crypto_openssl is linked, |md_native_handle| must be a
|
||||
* If libngtcp2_crypto_quictls is linked, |md_native_handle| must be a
|
||||
* pointer to EVP_MD.
|
||||
*
|
||||
* If libngtcp2_crypto_gnutls is linked, |md_native_handle| must be
|
||||
@@ -134,10 +112,12 @@ ngtcp2_crypto_aead_noncelen(const ngtcp2_crypto_aead *aead);
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* `ngtcp2_crypto_hkdf_extract` performs HKDF extract operation. The
|
||||
* result is the length of |md| and is stored to the buffer pointed by
|
||||
* |dest|. The caller is responsible to specify the buffer that can
|
||||
* store the output.
|
||||
* `ngtcp2_crypto_hkdf_extract` performs HKDF extract operation.
|
||||
*
|
||||
* The length of output is `ngtcp2_crypto_md_hashlen(md)
|
||||
* <ngtcp2_crypto_md_hashlen>`. The output is stored in the buffer
|
||||
* pointed by |dest|. The caller is responsible to specify the buffer
|
||||
* that has enough capacity to store the output.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or -1.
|
||||
*/
|
||||
@@ -150,7 +130,7 @@ ngtcp2_crypto_hkdf_extract(uint8_t *dest, const ngtcp2_crypto_md *md,
|
||||
* @function
|
||||
*
|
||||
* `ngtcp2_crypto_hkdf_expand` performs HKDF expand operation. The
|
||||
* result is |destlen| bytes long and is stored to the buffer pointed
|
||||
* result is |destlen| bytes long, and is stored in the buffer pointed
|
||||
* by |dest|.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or -1.
|
||||
@@ -166,7 +146,8 @@ NGTCP2_EXTERN int ngtcp2_crypto_hkdf_expand(uint8_t *dest, size_t destlen,
|
||||
* @function
|
||||
*
|
||||
* `ngtcp2_crypto_hkdf` performs HKDF operation. The result is
|
||||
* |destlen| bytes long and is stored to the buffer pointed by |dest|.
|
||||
* |destlen| bytes long, and is stored in the buffer pointed by
|
||||
* |dest|.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or -1.
|
||||
*/
|
||||
@@ -176,41 +157,6 @@ NGTCP2_EXTERN int ngtcp2_crypto_hkdf(uint8_t *dest, size_t destlen,
|
||||
const uint8_t *salt, size_t saltlen,
|
||||
const uint8_t *info, size_t infolen);
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* `ngtcp2_crypto_hkdf_expand_label` performs HKDF expand label. The
|
||||
* result is |destlen| bytes long and is stored to the buffer pointed
|
||||
* by |dest|.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or -1.
|
||||
*/
|
||||
NGTCP2_EXTERN int ngtcp2_crypto_hkdf_expand_label(uint8_t *dest, size_t destlen,
|
||||
const ngtcp2_crypto_md *md,
|
||||
const uint8_t *secret,
|
||||
size_t secretlen,
|
||||
const uint8_t *label,
|
||||
size_t labellen);
|
||||
|
||||
/**
|
||||
* @enum
|
||||
*
|
||||
* :type:`ngtcp2_crypto_side` indicates which side the application
|
||||
* implements; client or server.
|
||||
*/
|
||||
typedef enum ngtcp2_crypto_side {
|
||||
/**
|
||||
* :enum:`NGTCP2_CRYPTO_SIDE_CLIENT` indicates that the application
|
||||
* is client.
|
||||
*/
|
||||
NGTCP2_CRYPTO_SIDE_CLIENT,
|
||||
/**
|
||||
* :enum:`NGTCP2_CRYPTO_SIDE_SERVER` indicates that the application
|
||||
* is server.
|
||||
*/
|
||||
NGTCP2_CRYPTO_SIDE_SERVER
|
||||
} ngtcp2_crypto_side;
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
@@ -225,11 +171,10 @@ ngtcp2_crypto_packet_protection_ivlen(const ngtcp2_crypto_aead *aead);
|
||||
*
|
||||
* `ngtcp2_crypto_encrypt` encrypts |plaintext| of length
|
||||
* |plaintextlen| and writes the ciphertext into the buffer pointed by
|
||||
* |dest|. The length of ciphertext is plaintextlen +
|
||||
* |dest|. The length of ciphertext is |plaintextlen| +
|
||||
* :member:`aead->max_overhead <ngtcp2_crypto_aead.max_overhead>`
|
||||
* bytes long. |dest| must have enough capacity to store the
|
||||
* ciphertext. It is allowed to specify the same value to |dest| and
|
||||
* |plaintext|.
|
||||
* ciphertext. |dest| and |plaintext| may point to the same buffer.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or -1.
|
||||
*/
|
||||
@@ -263,11 +208,10 @@ ngtcp2_crypto_encrypt_cb(uint8_t *dest, const ngtcp2_crypto_aead *aead,
|
||||
*
|
||||
* `ngtcp2_crypto_decrypt` decrypts |ciphertext| of length
|
||||
* |ciphertextlen| and writes the plaintext into the buffer pointed by
|
||||
* |dest|. The length of plaintext is ciphertextlen -
|
||||
* |dest|. The length of plaintext is |ciphertextlen| -
|
||||
* :member:`aead->max_overhead <ngtcp2_crypto_aead.max_overhead>`
|
||||
* bytes long. |dest| must have enough capacity to store the
|
||||
* plaintext. It is allowed to specify the same value to |dest| and
|
||||
* |ciphertext|.
|
||||
* plaintext. |dest| and |ciphertext| may point to the same buffer.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or -1.
|
||||
*/
|
||||
@@ -299,7 +243,7 @@ ngtcp2_crypto_decrypt_cb(uint8_t *dest, const ngtcp2_crypto_aead *aead,
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* `ngtcp2_crypto_hp_mask` generates mask which is used in packet
|
||||
* `ngtcp2_crypto_hp_mask` generates a mask which is used in packet
|
||||
* header encryption. The mask is written to the buffer pointed by
|
||||
* |dest|. The sample is passed as |sample| which is
|
||||
* :macro:`NGTCP2_HP_SAMPLELEN` bytes long. The length of mask must
|
||||
@@ -333,15 +277,14 @@ ngtcp2_crypto_hp_mask_cb(uint8_t *dest, const ngtcp2_crypto_cipher *hp,
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* `ngtcp2_crypto_derive_and_install_rx_key` derives the rx keys from
|
||||
* |secret| and installs new keys to |conn|.
|
||||
* `ngtcp2_crypto_derive_and_install_rx_key` derives the decryption
|
||||
* keying materials from |secret|, and installs them to |conn|.
|
||||
*
|
||||
* If |key| is not NULL, the derived packet protection key for
|
||||
* decryption is written to the buffer pointed by |key|. If |iv| is
|
||||
* not NULL, the derived packet protection IV for decryption is
|
||||
* written to the buffer pointed by |iv|. If |hp| is not NULL, the
|
||||
* derived header protection key for decryption is written to the
|
||||
* buffer pointed by |hp|.
|
||||
* If |key| is not NULL, the derived packet protection key is written
|
||||
* to the buffer pointed by |key|. If |iv| is not NULL, the derived
|
||||
* packet protection IV is written to the buffer pointed by |iv|. If
|
||||
* |hp| is not NULL, the derived header protection key is written to
|
||||
* the buffer pointed by |hp|.
|
||||
*
|
||||
* |secretlen| specifies the length of |secret|.
|
||||
*
|
||||
@@ -351,44 +294,44 @@ ngtcp2_crypto_hp_mask_cb(uint8_t *dest, const ngtcp2_crypto_cipher *hp,
|
||||
* `ngtcp2_crypto_packet_protection_ivlen(ctx->aead)
|
||||
* <ngtcp2_crypto_packet_protection_ivlen>` where ctx is obtained by
|
||||
* `ngtcp2_crypto_ctx_tls` (or `ngtcp2_crypto_ctx_tls_early` if
|
||||
* |level| == :enum:`ngtcp2_crypto_level.NGTCP2_CRYPTO_LEVEL_EARLY`).
|
||||
* |level| ==
|
||||
* :enum:`ngtcp2_encryption_level.NGTCP2_ENCRYPTION_LEVEL_0RTT`).
|
||||
*
|
||||
* In the first call of this function, it calls
|
||||
* `ngtcp2_conn_set_crypto_ctx` (or `ngtcp2_conn_set_early_crypto_ctx`
|
||||
* if |level| ==
|
||||
* :enum:`ngtcp2_crypto_level.NGTCP2_CRYPTO_LEVEL_EARLY`) to set
|
||||
* negotiated AEAD and message digest algorithm. After the successful
|
||||
* call of this function, application can use
|
||||
* :enum:`ngtcp2_encryption_level.NGTCP2_ENCRYPTION_LEVEL_0RTT`) to
|
||||
* set negotiated AEAD and message digest algorithm. After the
|
||||
* successful call of this function, application can use
|
||||
* `ngtcp2_conn_get_crypto_ctx` (or `ngtcp2_conn_get_early_crypto_ctx`
|
||||
* if |level| ==
|
||||
* :enum:`ngtcp2_crypto_level.NGTCP2_CRYPTO_LEVEL_EARLY`) to get
|
||||
* :type:`ngtcp2_crypto_ctx`.
|
||||
* :enum:`ngtcp2_encryption_level.NGTCP2_ENCRYPTION_LEVEL_0RTT`) to
|
||||
* get :type:`ngtcp2_crypto_ctx`.
|
||||
*
|
||||
* If |conn| is initialized as client, and |level| is
|
||||
* :enum:`ngtcp2_crypto_level.NGTCP2_CRYPTO_LEVEL_APPLICATION`, this
|
||||
* :enum:`ngtcp2_encryption_level.NGTCP2_ENCRYPTION_LEVEL_1RTT`, this
|
||||
* function retrieves a remote QUIC transport parameters extension
|
||||
* from an object obtained by `ngtcp2_conn_get_tls_native_handle` and
|
||||
* from an object obtained by `ngtcp2_conn_get_tls_native_handle`, and
|
||||
* sets it to |conn| by calling
|
||||
* `ngtcp2_conn_decode_remote_transport_params`.
|
||||
* `ngtcp2_conn_decode_and_set_remote_transport_params`.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or -1.
|
||||
*/
|
||||
NGTCP2_EXTERN int ngtcp2_crypto_derive_and_install_rx_key(
|
||||
ngtcp2_conn *conn, uint8_t *key, uint8_t *iv, uint8_t *hp,
|
||||
ngtcp2_crypto_level level, const uint8_t *secret, size_t secretlen);
|
||||
ngtcp2_encryption_level level, const uint8_t *secret, size_t secretlen);
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* `ngtcp2_crypto_derive_and_install_tx_key` derives the tx keys from
|
||||
* |secret| and installs new keys to |conn|.
|
||||
* `ngtcp2_crypto_derive_and_install_tx_key` derives the encryption
|
||||
* keying materials from |secret|, and installs new keys to |conn|.
|
||||
*
|
||||
* If |key| is not NULL, the derived packet protection key for
|
||||
* encryption is written to the buffer pointed by |key|. If |iv| is
|
||||
* not NULL, the derived packet protection IV for encryption is
|
||||
* written to the buffer pointed by |iv|. If |hp| is not NULL, the
|
||||
* derived header protection key for encryption is written to the
|
||||
* buffer pointed by |hp|.
|
||||
* If |key| is not NULL, the derived packet protection key is written
|
||||
* to the buffer pointed by |key|. If |iv| is not NULL, the derived
|
||||
* packet protection IV is written to the buffer pointed by |iv|. If
|
||||
* |hp| is not NULL, the derived header protection key is written to
|
||||
* the buffer pointed by |hp|.
|
||||
*
|
||||
* |secretlen| specifies the length of |secret|.
|
||||
*
|
||||
@@ -398,58 +341,59 @@ NGTCP2_EXTERN int ngtcp2_crypto_derive_and_install_rx_key(
|
||||
* `ngtcp2_crypto_packet_protection_ivlen(ctx->aead)
|
||||
* <ngtcp2_crypto_packet_protection_ivlen>` where ctx is obtained by
|
||||
* `ngtcp2_crypto_ctx_tls` (or `ngtcp2_crypto_ctx_tls_early` if
|
||||
* |level| == :enum:`ngtcp2_crypto_level.NGTCP2_CRYPTO_LEVEL_EARLY`).
|
||||
* |level| ==
|
||||
* :enum:`ngtcp2_encryption_level.NGTCP2_ENCRYPTION_LEVEL_0RTT`).
|
||||
*
|
||||
* In the first call of this function, it calls
|
||||
* `ngtcp2_conn_set_crypto_ctx` (or `ngtcp2_conn_set_early_crypto_ctx`
|
||||
* if |level| ==
|
||||
* :enum:`ngtcp2_crypto_level.NGTCP2_CRYPTO_LEVEL_EARLY`) to set
|
||||
* negotiated AEAD and message digest algorithm. After the successful
|
||||
* call of this function, application can use
|
||||
* :enum:`ngtcp2_encryption_level.NGTCP2_ENCRYPTION_LEVEL_0RTT`) to
|
||||
* set negotiated AEAD and message digest algorithm. After the
|
||||
* successful call of this function, application can use
|
||||
* `ngtcp2_conn_get_crypto_ctx` (or `ngtcp2_conn_get_early_crypto_ctx`
|
||||
* if |level| ==
|
||||
* :enum:`ngtcp2_crypto_level.NGTCP2_CRYPTO_LEVEL_EARLY`) to get
|
||||
* :type:`ngtcp2_crypto_ctx`.
|
||||
* :enum:`ngtcp2_encryption_level.NGTCP2_ENCRYPTION_LEVEL_0RTT`) to
|
||||
* get :type:`ngtcp2_crypto_ctx`.
|
||||
*
|
||||
* If |conn| is initialized as server, and |level| is
|
||||
* :enum:`ngtcp2_crypto_level.NGTCP2_CRYPTO_LEVEL_APPLICATION`, this
|
||||
* :enum:`ngtcp2_encryption_level.NGTCP2_ENCRYPTION_LEVEL_1RTT`, this
|
||||
* function retrieves a remote QUIC transport parameters extension
|
||||
* from an object obtained by `ngtcp2_conn_get_tls_native_handle` and
|
||||
* from an object obtained by `ngtcp2_conn_get_tls_native_handle`, and
|
||||
* sets it to |conn| by calling
|
||||
* `ngtcp2_conn_decode_remote_transport_params`.
|
||||
* `ngtcp2_conn_decode_and_set_remote_transport_params`.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or -1.
|
||||
*/
|
||||
NGTCP2_EXTERN int ngtcp2_crypto_derive_and_install_tx_key(
|
||||
ngtcp2_conn *conn, uint8_t *key, uint8_t *iv, uint8_t *hp,
|
||||
ngtcp2_crypto_level level, const uint8_t *secret, size_t secretlen);
|
||||
ngtcp2_encryption_level level, const uint8_t *secret, size_t secretlen);
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* `ngtcp2_crypto_update_key` updates traffic keying materials.
|
||||
*
|
||||
* The new traffic secret for decryption is written to the buffer
|
||||
* pointed by |rx_secret|. The length of secret is |secretlen| bytes,
|
||||
* and |rx_secret| must point to the buffer which has enough capacity.
|
||||
* The new decryption traffic secret is written to the buffer pointed
|
||||
* by |rx_secret|. The length of secret is |secretlen| bytes, and
|
||||
* |rx_secret| must point to the buffer which has enough capacity.
|
||||
*
|
||||
* The new traffic secret for encryption is written to the buffer
|
||||
* pointed by |tx_secret|. The length of secret is |secretlen| bytes,
|
||||
* and |tx_secret| must point to the buffer which has enough capacity.
|
||||
* The new encryption traffic secret is written to the buffer pointed
|
||||
* by |tx_secret|. The length of secret is |secretlen| bytes, and
|
||||
* |tx_secret| must point to the buffer which has enough capacity.
|
||||
*
|
||||
* The derived packet protection key for decryption is written to the
|
||||
* buffer pointed by |rx_key|. The derived packet protection IV for
|
||||
* decryption is written to the buffer pointed by |rx_iv|.
|
||||
* |rx_aead_ctx| must be constructed with |rx_key|.
|
||||
* The derived decryption packet protection key is written to the
|
||||
* buffer pointed by |rx_key|. The derived decryption packet
|
||||
* protection IV is written to the buffer pointed by |rx_iv|.
|
||||
* |rx_aead_ctx| is initialized with the derived key and IV.
|
||||
*
|
||||
* The derived packet protection key for encryption is written to the
|
||||
* buffer pointed by |tx_key|. The derived packet protection IV for
|
||||
* encryption is written to the buffer pointed by |tx_iv|.
|
||||
* |tx_aead_ctx| must be constructed with |rx_key|.
|
||||
* The derived encryption packet protection key is written to the
|
||||
* buffer pointed by |tx_key|. The derived encryption packet
|
||||
* protection IV is written to the buffer pointed by |tx_iv|.
|
||||
* |tx_aead_ctx| is initialized with the derived key and IV.
|
||||
*
|
||||
* |current_rx_secret| and |current_tx_secret| are the current traffic
|
||||
* secrets for decryption and encryption. |secretlen| specifies the
|
||||
* length of |rx_secret| and |tx_secret|.
|
||||
* |current_rx_secret| and |current_tx_secret| are the current
|
||||
* decryption and encryption traffic secrets respectively. They share
|
||||
* the same length with |rx_secret| and |tx_secret|.
|
||||
*
|
||||
* The length of packet protection key and header protection key is
|
||||
* `ngtcp2_crypto_aead_keylen(ctx->aead) <ngtcp2_crypto_aead_keylen>`,
|
||||
@@ -488,7 +432,7 @@ NGTCP2_EXTERN int ngtcp2_crypto_update_key_cb(
|
||||
* @function
|
||||
*
|
||||
* `ngtcp2_crypto_client_initial_cb` installs initial secrets and
|
||||
* encryption keys and sets QUIC transport parameters.
|
||||
* encryption keys, and sets QUIC transport parameters.
|
||||
*
|
||||
* This function can be directly passed to
|
||||
* :member:`ngtcp2_callbacks.client_initial` field. It is only used
|
||||
@@ -507,8 +451,8 @@ NGTCP2_EXTERN int ngtcp2_crypto_client_initial_cb(ngtcp2_conn *conn,
|
||||
* response to incoming Retry packet.
|
||||
*
|
||||
* This function can be directly passed to
|
||||
* :member:`ngtcp2_callbacks.recv_retry` field. It is only used
|
||||
* by client.
|
||||
* :member:`ngtcp2_callbacks.recv_retry` field. It is only used by
|
||||
* client.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or
|
||||
* :macro:`NGTCP2_ERR_CALLBACK_FAILURE`.
|
||||
@@ -525,8 +469,8 @@ NGTCP2_EXTERN int ngtcp2_crypto_recv_retry_cb(ngtcp2_conn *conn,
|
||||
* transport parameters.
|
||||
*
|
||||
* This function can be directly passed to
|
||||
* :member:`ngtcp2_callbacks.recv_client_initial` field. It is
|
||||
* only used by server.
|
||||
* :member:`ngtcp2_callbacks.recv_client_initial` field. It is only
|
||||
* used by server.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or
|
||||
* :macro:`NGTCP2_ERR_CALLBACK_FAILURE`.
|
||||
@@ -539,21 +483,21 @@ NGTCP2_EXTERN int ngtcp2_crypto_recv_client_initial_cb(ngtcp2_conn *conn,
|
||||
* @function
|
||||
*
|
||||
* `ngtcp2_crypto_read_write_crypto_data` reads CRYPTO data |data| of
|
||||
* length |datalen| in encryption level |crypto_level| and may feed
|
||||
* outgoing CRYPTO data to |conn|. This function can drive handshake.
|
||||
* This function can be also used after handshake completes. It is
|
||||
* allowed to call this function with |datalen| == 0. In this case,
|
||||
* no additional read operation is done.
|
||||
* length |datalen| in an encryption level |encryption_level|, and may
|
||||
* feed outgoing CRYPTO data to |conn|. This function can drive
|
||||
* handshake. This function can be also used after handshake
|
||||
* completes. It is allowed to call this function with |datalen| ==
|
||||
* 0. In this case, no additional read operation is done.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or a negative error code.
|
||||
* The generic error code is -1 if a specific error code is not
|
||||
* suitable. The error codes less than -10000 are specific to
|
||||
* underlying TLS implementation. For OpenSSL, the error codes are
|
||||
* defined in *ngtcp2_crypto_openssl.h*.
|
||||
* underlying TLS implementation. For quictls, the error codes are
|
||||
* defined in *ngtcp2_crypto_quictls.h*.
|
||||
*/
|
||||
NGTCP2_EXTERN int
|
||||
ngtcp2_crypto_read_write_crypto_data(ngtcp2_conn *conn,
|
||||
ngtcp2_crypto_level crypto_level,
|
||||
ngtcp2_encryption_level encryption_level,
|
||||
const uint8_t *data, size_t datalen);
|
||||
|
||||
/**
|
||||
@@ -570,17 +514,17 @@ ngtcp2_crypto_read_write_crypto_data(ngtcp2_conn *conn,
|
||||
* codes.
|
||||
*/
|
||||
NGTCP2_EXTERN int ngtcp2_crypto_recv_crypto_data_cb(
|
||||
ngtcp2_conn *conn, ngtcp2_crypto_level crypto_level, uint64_t offset,
|
||||
const uint8_t *data, size_t datalen, void *user_data);
|
||||
ngtcp2_conn *conn, ngtcp2_encryption_level encryption_level,
|
||||
uint64_t offset, const uint8_t *data, size_t datalen, void *user_data);
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* `ngtcp2_crypto_generate_stateless_reset_token` generates a
|
||||
* stateless reset token using HKDF extraction using the given |cid|
|
||||
* and static key |secret| as input. The token will be written to
|
||||
* the buffer pointed by |token| and it must have a capacity of at
|
||||
* least :macro:`NGTCP2_STATELESS_RESET_TOKENLEN` bytes.
|
||||
* and |secret| as input. The token will be written to the buffer
|
||||
* pointed by |token|, and it must have a capacity of at least
|
||||
* :macro:`NGTCP2_STATELESS_RESET_TOKENLEN` bytes.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or -1.
|
||||
*/
|
||||
@@ -644,12 +588,12 @@ NGTCP2_EXTERN int ngtcp2_crypto_generate_stateless_reset_token(
|
||||
* :macro:`NGTCP2_CRYPTO_MAX_RETRY_TOKENLEN` bytes long. The
|
||||
* successfully generated token starts with
|
||||
* :macro:`NGTCP2_CRYPTO_TOKEN_MAGIC_RETRY`. |secret| of length
|
||||
* |secretlen| is an initial keying material to generate keys to
|
||||
* encrypt the token. |version| is QUIC version. |remote_addr| of
|
||||
* length |remote_addrlen| is an address of client. |retry_scid| is a
|
||||
* Source Connection ID chosen by server and set in Retry packet.
|
||||
* |odcid| is a Destination Connection ID in Initial packet sent by
|
||||
* client. |ts| is the timestamp when the token is generated.
|
||||
* |secretlen| is a keying material to generate keys to encrypt the
|
||||
* token. |version| is QUIC version. |remote_addr| of length
|
||||
* |remote_addrlen| is an address of client. |retry_scid| is a Source
|
||||
* Connection ID chosen by server, and set in Retry packet. |odcid|
|
||||
* is a Destination Connection ID in Initial packet sent by client.
|
||||
* |ts| is the timestamp when the token is generated.
|
||||
*
|
||||
* This function returns the length of generated token if it succeeds,
|
||||
* or -1.
|
||||
@@ -664,16 +608,16 @@ NGTCP2_EXTERN ngtcp2_ssize ngtcp2_crypto_generate_retry_token(
|
||||
*
|
||||
* `ngtcp2_crypto_verify_retry_token` verifies Retry token stored in
|
||||
* the buffer pointed by |token| of length |tokenlen|. |secret| of
|
||||
* length |secretlen| is an initial keying material to generate keys
|
||||
* to decrypt the token. |version| is QUIC version of the Initial
|
||||
* packet that contains this token. |remote_addr| of length
|
||||
* |remote_addrlen| is an address of client. |dcid| is a Destination
|
||||
* Connection ID in Initial packet sent by client. |timeout| is the
|
||||
* period during which the token is valid. |ts| is the current
|
||||
* timestamp. When validation succeeds, the extracted Destination
|
||||
* Connection ID (which is the Destination Connection ID in Initial
|
||||
* packet sent by client that triggered Retry packet) is stored to the
|
||||
* buffer pointed by |odcid|.
|
||||
* length |secretlen| is a keying material to generate keys to decrypt
|
||||
* the token. |version| is QUIC version of the Initial packet that
|
||||
* contains this token. |remote_addr| of length |remote_addrlen| is
|
||||
* an address of client. |dcid| is a Destination Connection ID in
|
||||
* Initial packet sent by client. |timeout| is the period during
|
||||
* which the token is valid. |ts| is the current timestamp. When
|
||||
* validation succeeds, the extracted Destination Connection ID (which
|
||||
* is the Destination Connection ID in Initial packet sent by client
|
||||
* that triggered Retry packet) is stored in the buffer pointed by
|
||||
* |odcid|.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or -1.
|
||||
*/
|
||||
@@ -692,10 +636,9 @@ NGTCP2_EXTERN int ngtcp2_crypto_verify_retry_token(
|
||||
* :macro:`NGTCP2_CRYPTO_MAX_REGULAR_TOKENLEN` bytes long. The
|
||||
* successfully generated token starts with
|
||||
* :macro:`NGTCP2_CRYPTO_TOKEN_MAGIC_REGULAR`. |secret| of length
|
||||
* |secretlen| is an initial keying material to generate keys to
|
||||
* encrypt the token. |remote_addr| of length |remote_addrlen| is an
|
||||
* address of client. |ts| is the timestamp when the token is
|
||||
* generated.
|
||||
* |secretlen| is a keying material to generate keys to encrypt the
|
||||
* token. |remote_addr| of length |remote_addrlen| is an address of
|
||||
* client. |ts| is the timestamp when the token is generated.
|
||||
*
|
||||
* This function returns the length of generated token if it succeeds,
|
||||
* or -1.
|
||||
@@ -710,8 +653,8 @@ NGTCP2_EXTERN ngtcp2_ssize ngtcp2_crypto_generate_regular_token(
|
||||
*
|
||||
* `ngtcp2_crypto_verify_regular_token` verifies a regular token
|
||||
* stored in the buffer pointed by |token| of length |tokenlen|.
|
||||
* |secret| of length |secretlen| is an initial keying material to
|
||||
* generate keys to decrypt the token. |remote_addr| of length
|
||||
* |secret| of length |secretlen| is a keying material to generate
|
||||
* keys to decrypt the token. |remote_addr| of length
|
||||
* |remote_addrlen| is an address of client. |timeout| is the period
|
||||
* during which the token is valid. |ts| is the current timestamp.
|
||||
*
|
||||
@@ -750,9 +693,12 @@ NGTCP2_EXTERN ngtcp2_ssize ngtcp2_crypto_write_connection_close(
|
||||
* @function
|
||||
*
|
||||
* `ngtcp2_crypto_write_retry` writes Retry packet to the buffer
|
||||
* pointed by |dest| of length |destlen|. |odcid| specifies Original
|
||||
* Destination Connection ID. |token| specifies Retry Token, and
|
||||
* |tokenlen| specifies its length.
|
||||
* pointed by |dest| of length |destlen|. |dcid| is the Connection ID
|
||||
* which appeared in a packet as a Source Connection ID sent by
|
||||
* client. |scid| is a server chosen Source Connection ID. |odcid|
|
||||
* specifies Original Destination Connection ID which appeared in a
|
||||
* packet as a Destination Connection ID sent by client. |token|
|
||||
* specifies Retry Token, and |tokenlen| specifies its length.
|
||||
*
|
||||
* This function wraps around `ngtcp2_pkt_write_retry` for easier use.
|
||||
*
|
||||
@@ -783,7 +729,7 @@ ngtcp2_crypto_aead_ctx_encrypt_init(ngtcp2_crypto_aead_ctx *aead_ctx,
|
||||
*
|
||||
* `ngtcp2_crypto_aead_ctx_decrypt_init` initializes |aead_ctx| with
|
||||
* new AEAD cipher context object for decryption which is constructed
|
||||
* to use |key| as encryption key. |aead| specifies AEAD cipher to
|
||||
* to use |key| as decryption key. |aead| specifies AEAD cipher to
|
||||
* use. |noncelen| is the length of nonce.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or -1.
|
||||
@@ -806,7 +752,8 @@ ngtcp2_crypto_aead_ctx_free(ngtcp2_crypto_aead_ctx *aead_ctx);
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* `ngtcp2_crypto_delete_crypto_aead_ctx_cb` deletes the given |aead_ctx|.
|
||||
* `ngtcp2_crypto_delete_crypto_aead_ctx_cb` deletes the given
|
||||
* |aead_ctx|.
|
||||
*
|
||||
* This function can be directly passed to
|
||||
* :member:`ngtcp2_callbacks.delete_crypto_aead_ctx` field.
|
||||
@@ -845,7 +792,8 @@ NGTCP2_EXTERN int ngtcp2_crypto_get_path_challenge_data_cb(ngtcp2_conn *conn,
|
||||
*
|
||||
* `ngtcp2_crypto_version_negotiation_cb` installs Initial keys for
|
||||
* |version| which is negotiated or being negotiated. |client_dcid|
|
||||
* is the destination connection ID in first Initial packet of client.
|
||||
* is the destination connection ID in first Initial packet from
|
||||
* client.
|
||||
*
|
||||
* This function can be directly passed to
|
||||
* :member:`ngtcp2_callbacks.version_negotiation` field.
|
||||
@@ -872,7 +820,7 @@ typedef ngtcp2_conn *(*ngtcp2_crypto_get_conn)(
|
||||
*
|
||||
* :type:`ngtcp2_crypto_conn_ref` is a structure to get a pointer to
|
||||
* :type:`ngtcp2_conn`. It is meant to be set to TLS native handle as
|
||||
* an application specific data (e.g. SSL_set_app_data in OpenSSL).
|
||||
* an application specific data (e.g. SSL_set_app_data in quictls).
|
||||
*/
|
||||
typedef struct ngtcp2_crypto_conn_ref {
|
||||
/**
|
||||
|
||||
@@ -37,23 +37,23 @@ extern "C" {
|
||||
* @function
|
||||
*
|
||||
* `ngtcp2_crypto_boringssl_from_ssl_encryption_level` translates
|
||||
* |ssl_level| to :type:`ngtcp2_crypto_level`. This function is only
|
||||
* available for BoringSSL backend.
|
||||
* |ssl_level| to :type:`ngtcp2_encryption_level`. This function is
|
||||
* only available for BoringSSL backend.
|
||||
*/
|
||||
NGTCP2_EXTERN ngtcp2_crypto_level
|
||||
NGTCP2_EXTERN ngtcp2_encryption_level
|
||||
ngtcp2_crypto_boringssl_from_ssl_encryption_level(
|
||||
enum ssl_encryption_level_t ssl_level);
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* `ngtcp2_crypto_boringssl_from_ngtcp2_crypto_level` translates
|
||||
* |crypto_level| to ssl_encryption_level_t. This function is only
|
||||
* available for BoringSSL backend.
|
||||
* `ngtcp2_crypto_boringssl_from_ngtcp2_encryption_level` translates
|
||||
* |encryption_level| to ssl_encryption_level_t. This function is
|
||||
* only available for BoringSSL backend.
|
||||
*/
|
||||
NGTCP2_EXTERN enum ssl_encryption_level_t
|
||||
ngtcp2_crypto_boringssl_from_ngtcp2_crypto_level(
|
||||
ngtcp2_crypto_level crypto_level);
|
||||
ngtcp2_crypto_boringssl_from_ngtcp2_encryption_level(
|
||||
ngtcp2_encryption_level encryption_level);
|
||||
|
||||
/**
|
||||
* @function
|
||||
|
||||
@@ -36,8 +36,8 @@ extern "C" {
|
||||
/**
|
||||
* @struct
|
||||
*
|
||||
* :type:`ngtcp2_crypto_picotls_ctx` contains per-connection state
|
||||
* of Picotls objects and must be an object to bet set to
|
||||
* :type:`ngtcp2_crypto_picotls_ctx` contains per-connection state of
|
||||
* Picotls objects and must be an object to bet set to
|
||||
* `ngtcp2_conn_set_tls_native_handle`.
|
||||
*/
|
||||
typedef struct ngtcp2_crypto_picotls_ctx {
|
||||
@@ -65,21 +65,21 @@ ngtcp2_crypto_picotls_ctx_init(ngtcp2_crypto_picotls_ctx *cptls);
|
||||
* @function
|
||||
*
|
||||
* `ngtcp2_crypto_picotls_from_epoch` translates |epoch| to
|
||||
* :type:`ngtcp2_crypto_level`. This function is only available for
|
||||
* Picotls backend.
|
||||
* :type:`ngtcp2_encryption_level`. This function is only available
|
||||
* for Picotls backend.
|
||||
*/
|
||||
NGTCP2_EXTERN ngtcp2_crypto_level
|
||||
NGTCP2_EXTERN ngtcp2_encryption_level
|
||||
ngtcp2_crypto_picotls_from_epoch(size_t epoch);
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* `ngtcp2_crypto_picotls_from_ngtcp2_crypto_level` translates
|
||||
* |crypto_level| to epoch. This function is only available for
|
||||
* `ngtcp2_crypto_picotls_from_ngtcp2_encryption_level` translates
|
||||
* |encryption_level| to epoch. This function is only available for
|
||||
* Picotls backend.
|
||||
*/
|
||||
NGTCP2_EXTERN size_t ngtcp2_crypto_picotls_from_ngtcp2_crypto_level(
|
||||
ngtcp2_crypto_level crypto_level);
|
||||
NGTCP2_EXTERN size_t ngtcp2_crypto_picotls_from_ngtcp2_encryption_level(
|
||||
ngtcp2_encryption_level encryption_level);
|
||||
|
||||
/**
|
||||
* @function
|
||||
@@ -206,7 +206,7 @@ ngtcp2_crypto_picotls_configure_client_session(ngtcp2_crypto_picotls_ctx *cptls,
|
||||
*
|
||||
* `ngtcp2_crypto_picotls_deconfigure_session` frees the resources
|
||||
* allocated for |cptls| during QUIC connection. It frees the
|
||||
* following data using :manpage:`free(3)`.
|
||||
* following data using :manpage:`free(3)`:
|
||||
*
|
||||
* - handshake_properties.max_early_data_size
|
||||
* - handshake_properties.additional_extensions[0].data.base
|
||||
|
||||
+37
-22
@@ -22,8 +22,8 @@
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef NGTCP2_CRYPTO_OPENSSL_H
|
||||
#define NGTCP2_CRYPTO_OPENSSL_H
|
||||
#ifndef NGTCP2_CRYPTO_QUICTLS_H
|
||||
#define NGTCP2_CRYPTO_QUICTLS_H
|
||||
|
||||
#include <ngtcp2/ngtcp2.h>
|
||||
|
||||
@@ -36,57 +36,57 @@ extern "C" {
|
||||
/**
|
||||
* @macrosection
|
||||
*
|
||||
* OpenSSL specific error codes
|
||||
* quictls specific error codes
|
||||
*/
|
||||
|
||||
/**
|
||||
* @macro
|
||||
*
|
||||
* :macro:`NGTCP2_CRYPTO_OPENSSL_ERR_TLS_WANT_X509_LOOKUP` is the
|
||||
* :macro:`NGTCP2_CRYPTO_QUICTLS_ERR_TLS_WANT_X509_LOOKUP` is the
|
||||
* error code which indicates that TLS handshake routine is
|
||||
* interrupted by X509 certificate lookup. See
|
||||
* :macro:`SSL_ERROR_WANT_X509_LOOKUP` error description from
|
||||
* `SSL_do_handshake`.
|
||||
*/
|
||||
#define NGTCP2_CRYPTO_OPENSSL_ERR_TLS_WANT_X509_LOOKUP -10001
|
||||
#define NGTCP2_CRYPTO_QUICTLS_ERR_TLS_WANT_X509_LOOKUP -10001
|
||||
|
||||
/**
|
||||
* @macro
|
||||
*
|
||||
* :macro:`NGTCP2_CRYPTO_OPENSSL_ERR_TLS_WANT_CLIENT_HELLO_CB` is the
|
||||
* :macro:`NGTCP2_CRYPTO_QUICTLS_ERR_TLS_WANT_CLIENT_HELLO_CB` is the
|
||||
* error code which indicates that TLS handshake routine is
|
||||
* interrupted by client hello callback. See
|
||||
* :macro:`SSL_ERROR_WANT_CLIENT_HELLO_CB` error description from
|
||||
* `SSL_do_handshake`.
|
||||
*/
|
||||
#define NGTCP2_CRYPTO_OPENSSL_ERR_TLS_WANT_CLIENT_HELLO_CB -10002
|
||||
#define NGTCP2_CRYPTO_QUICTLS_ERR_TLS_WANT_CLIENT_HELLO_CB -10002
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* `ngtcp2_crypto_openssl_from_ossl_encryption_level` translates
|
||||
* |ossl_level| to :type:`ngtcp2_crypto_level`. This function is only
|
||||
* available for OpenSSL backend.
|
||||
* `ngtcp2_crypto_quictls_from_ossl_encryption_level` translates
|
||||
* |ossl_level| to :type:`ngtcp2_encryption_level`. This function is
|
||||
* only available for quictls backend.
|
||||
*/
|
||||
NGTCP2_EXTERN ngtcp2_crypto_level
|
||||
ngtcp2_crypto_openssl_from_ossl_encryption_level(
|
||||
NGTCP2_EXTERN ngtcp2_encryption_level
|
||||
ngtcp2_crypto_quictls_from_ossl_encryption_level(
|
||||
OSSL_ENCRYPTION_LEVEL ossl_level);
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* `ngtcp2_crypto_openssl_from_ngtcp2_crypto_level` translates
|
||||
* |crypto_level| to OSSL_ENCRYPTION_LEVEL. This function is only
|
||||
* available for OpenSSL backend.
|
||||
* `ngtcp2_crypto_quictls_from_ngtcp2_encryption_level` translates
|
||||
* |encryption_level| to OSSL_ENCRYPTION_LEVEL. This function is only
|
||||
* available for quictls backend.
|
||||
*/
|
||||
NGTCP2_EXTERN OSSL_ENCRYPTION_LEVEL
|
||||
ngtcp2_crypto_openssl_from_ngtcp2_crypto_level(
|
||||
ngtcp2_crypto_level crypto_level);
|
||||
ngtcp2_crypto_quictls_from_ngtcp2_encryption_level(
|
||||
ngtcp2_encryption_level encryption_level);
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* `ngtcp2_crypto_openssl_configure_server_context` configures
|
||||
* `ngtcp2_crypto_quictls_configure_server_context` configures
|
||||
* |ssl_ctx| for server side QUIC connection. It performs the
|
||||
* following modifications:
|
||||
*
|
||||
@@ -102,12 +102,12 @@ ngtcp2_crypto_openssl_from_ngtcp2_crypto_level(
|
||||
* It returns 0 if it succeeds, or -1.
|
||||
*/
|
||||
NGTCP2_EXTERN int
|
||||
ngtcp2_crypto_openssl_configure_server_context(SSL_CTX *ssl_ctx);
|
||||
ngtcp2_crypto_quictls_configure_server_context(SSL_CTX *ssl_ctx);
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* `ngtcp2_crypto_openssl_configure_client_context` configures
|
||||
* `ngtcp2_crypto_quictls_configure_client_context` configures
|
||||
* |ssl_ctx| for client side QUIC connection. It performs the
|
||||
* following modifications:
|
||||
*
|
||||
@@ -123,10 +123,25 @@ ngtcp2_crypto_openssl_configure_server_context(SSL_CTX *ssl_ctx);
|
||||
* It returns 0 if it succeeds, or -1.
|
||||
*/
|
||||
NGTCP2_EXTERN int
|
||||
ngtcp2_crypto_openssl_configure_client_context(SSL_CTX *ssl_ctx);
|
||||
ngtcp2_crypto_quictls_configure_client_context(SSL_CTX *ssl_ctx);
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* `ngtcp2_crypto_quictls_init` initializes libngtcp2_crypto_quictls
|
||||
* library. This initialization is optional. For quictls >= 3.0, it
|
||||
* is highly recommended to call this function before any use of
|
||||
* libngtcp2_crypto library API to workaround the performance
|
||||
* regression. Note that calling this function does not solve all
|
||||
* performance issues introduced in 3.x. For quictls 1.1.1, this
|
||||
* function does nothing, and always succeeds.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or -1.
|
||||
*/
|
||||
NGTCP2_EXTERN int ngtcp2_crypto_quictls_init(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NGTCP2_CRYPTO_OPENSSL_H */
|
||||
#endif /* NGTCP2_CRYPTO_QUICTLS_H */
|
||||
@@ -39,23 +39,23 @@ extern "C" {
|
||||
* @function
|
||||
*
|
||||
* `ngtcp2_crypto_wolfssl_from_wolfssl_encryption_level` translates
|
||||
* |wolfssl_level| to :type:`ngtcp2_crypto_level`. This function is only
|
||||
* available for wolfSSL backend.
|
||||
* |wolfssl_level| to :type:`ngtcp2_encryption_level`. This function
|
||||
* is only available for wolfSSL backend.
|
||||
*/
|
||||
NGTCP2_EXTERN ngtcp2_crypto_level
|
||||
NGTCP2_EXTERN ngtcp2_encryption_level
|
||||
ngtcp2_crypto_wolfssl_from_wolfssl_encryption_level(
|
||||
WOLFSSL_ENCRYPTION_LEVEL wolfssl_level);
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* `ngtcp2_crypto_wolfssl_from_ngtcp2_crypto_level` translates
|
||||
* |crypto_level| to WOLFSSL_ENCRYPTION_LEVEL. This function is only
|
||||
* available for wolfSSL backend.
|
||||
* `ngtcp2_crypto_wolfssl_from_ngtcp2_encryption_level` translates
|
||||
* |encryption_level| to WOLFSSL_ENCRYPTION_LEVEL. This function is
|
||||
* only available for wolfSSL backend.
|
||||
*/
|
||||
NGTCP2_EXTERN WOLFSSL_ENCRYPTION_LEVEL
|
||||
ngtcp2_crypto_wolfssl_from_ngtcp2_crypto_level(
|
||||
ngtcp2_crypto_level crypto_level);
|
||||
ngtcp2_crypto_wolfssl_from_ngtcp2_encryption_level(
|
||||
ngtcp2_encryption_level encryption_level);
|
||||
|
||||
/**
|
||||
* @function
|
||||
|
||||
+63
-49
@@ -68,45 +68,40 @@ ngtcp2_crypto_aead *ngtcp2_crypto_aead_retry(ngtcp2_crypto_aead *aead) {
|
||||
return ngtcp2_crypto_aead_init(aead, (void *)&ptls_openssl_aes128gcm);
|
||||
}
|
||||
|
||||
static const ptls_aead_algorithm_t *crypto_ptls_get_aead(ptls_t *ptls) {
|
||||
ptls_cipher_suite_t *cs = ptls_get_cipher(ptls);
|
||||
|
||||
return cs->aead;
|
||||
}
|
||||
|
||||
static uint64_t crypto_ptls_get_aead_max_encryption(ptls_t *ptls) {
|
||||
ptls_cipher_suite_t *cs = ptls_get_cipher(ptls);
|
||||
|
||||
static uint64_t
|
||||
crypto_cipher_suite_get_aead_max_encryption(ptls_cipher_suite_t *cs) {
|
||||
if (cs->aead == &ptls_openssl_aes128gcm ||
|
||||
cs->aead == &ptls_openssl_aes256gcm) {
|
||||
return NGTCP2_CRYPTO_MAX_ENCRYPTION_AES_GCM;
|
||||
}
|
||||
|
||||
#ifdef PTLS_OPENSSL_HAVE_CHACHA20_POLY1305
|
||||
if (cs->aead == &ptls_openssl_chacha20poly1305) {
|
||||
return NGTCP2_CRYPTO_MAX_ENCRYPTION_CHACHA20_POLY1305;
|
||||
}
|
||||
#endif /* PTLS_OPENSSL_HAVE_CHACHA20_POLY1305 */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint64_t crypto_ptls_get_aead_max_decryption_failure(ptls_t *ptls) {
|
||||
ptls_cipher_suite_t *cs = ptls_get_cipher(ptls);
|
||||
|
||||
static uint64_t
|
||||
crypto_cipher_suite_get_aead_max_decryption_failure(ptls_cipher_suite_t *cs) {
|
||||
if (cs->aead == &ptls_openssl_aes128gcm ||
|
||||
cs->aead == &ptls_openssl_aes256gcm) {
|
||||
return NGTCP2_CRYPTO_MAX_DECRYPTION_FAILURE_AES_GCM;
|
||||
}
|
||||
|
||||
#ifdef PTLS_OPENSSL_HAVE_CHACHA20_POLY1305
|
||||
if (cs->aead == &ptls_openssl_chacha20poly1305) {
|
||||
return NGTCP2_CRYPTO_MAX_DECRYPTION_FAILURE_CHACHA20_POLY1305;
|
||||
}
|
||||
#endif /* PTLS_OPENSSL_HAVE_CHACHA20_POLY1305 */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const ptls_cipher_algorithm_t *crypto_ptls_get_hp(ptls_t *ptls) {
|
||||
ptls_cipher_suite_t *cs = ptls_get_cipher(ptls);
|
||||
|
||||
static const ptls_cipher_algorithm_t *
|
||||
crypto_cipher_suite_get_hp(ptls_cipher_suite_t *cs) {
|
||||
if (cs->aead == &ptls_openssl_aes128gcm) {
|
||||
return &ptls_openssl_aes128ctr;
|
||||
}
|
||||
@@ -115,29 +110,43 @@ static const ptls_cipher_algorithm_t *crypto_ptls_get_hp(ptls_t *ptls) {
|
||||
return &ptls_openssl_aes256ctr;
|
||||
}
|
||||
|
||||
#ifdef PTLS_OPENSSL_HAVE_CHACHA20_POLY1305
|
||||
if (cs->aead == &ptls_openssl_chacha20poly1305) {
|
||||
return &ptls_openssl_chacha20;
|
||||
}
|
||||
#endif /* PTLS_OPENSSL_HAVE_CHACHA20_POLY1305 */
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const ptls_hash_algorithm_t *crypto_ptls_get_md(ptls_t *ptls) {
|
||||
ptls_cipher_suite_t *cs = ptls_get_cipher(ptls);
|
||||
|
||||
return cs->hash;
|
||||
static int supported_cipher_suite(ptls_cipher_suite_t *cs) {
|
||||
return cs->aead == &ptls_openssl_aes128gcm ||
|
||||
cs->aead == &ptls_openssl_aes256gcm
|
||||
#ifdef PTLS_OPENSSL_HAVE_CHACHA20_POLY1305
|
||||
|| cs->aead == &ptls_openssl_chacha20poly1305
|
||||
#endif /* PTLS_OPENSSL_HAVE_CHACHA20_POLY1305 */
|
||||
;
|
||||
}
|
||||
|
||||
ngtcp2_crypto_ctx *ngtcp2_crypto_ctx_tls(ngtcp2_crypto_ctx *ctx,
|
||||
void *tls_native_handle) {
|
||||
ngtcp2_crypto_picotls_ctx *cptls = tls_native_handle;
|
||||
ngtcp2_crypto_aead_init(&ctx->aead,
|
||||
(void *)crypto_ptls_get_aead(cptls->ptls));
|
||||
ctx->md.native_handle = (void *)crypto_ptls_get_md(cptls->ptls);
|
||||
ctx->hp.native_handle = (void *)crypto_ptls_get_hp(cptls->ptls);
|
||||
ctx->max_encryption = crypto_ptls_get_aead_max_encryption(cptls->ptls);
|
||||
ptls_cipher_suite_t *cs = ptls_get_cipher(cptls->ptls);
|
||||
|
||||
if (cs == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!supported_cipher_suite(cs)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ngtcp2_crypto_aead_init(&ctx->aead, (void *)cs->aead);
|
||||
ctx->md.native_handle = (void *)cs->hash;
|
||||
ctx->hp.native_handle = (void *)crypto_cipher_suite_get_hp(cs);
|
||||
ctx->max_encryption = crypto_cipher_suite_get_aead_max_encryption(cs);
|
||||
ctx->max_decryption_failure =
|
||||
crypto_ptls_get_aead_max_decryption_failure(cptls->ptls);
|
||||
crypto_cipher_suite_get_aead_max_decryption_failure(cs);
|
||||
return ctx;
|
||||
}
|
||||
|
||||
@@ -350,13 +359,14 @@ int ngtcp2_crypto_hp_mask(uint8_t *dest, const ngtcp2_crypto_cipher *hp,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ngtcp2_crypto_read_write_crypto_data(ngtcp2_conn *conn,
|
||||
ngtcp2_crypto_level crypto_level,
|
||||
const uint8_t *data, size_t datalen) {
|
||||
int ngtcp2_crypto_read_write_crypto_data(
|
||||
ngtcp2_conn *conn, ngtcp2_encryption_level encryption_level,
|
||||
const uint8_t *data, size_t datalen) {
|
||||
ngtcp2_crypto_picotls_ctx *cptls = ngtcp2_conn_get_tls_native_handle(conn);
|
||||
ptls_buffer_t sendbuf;
|
||||
size_t epoch_offsets[5] = {0};
|
||||
size_t epoch = ngtcp2_crypto_picotls_from_ngtcp2_crypto_level(crypto_level);
|
||||
size_t epoch =
|
||||
ngtcp2_crypto_picotls_from_ngtcp2_encryption_level(encryption_level);
|
||||
size_t epoch_datalen;
|
||||
size_t i;
|
||||
int rv;
|
||||
@@ -379,7 +389,11 @@ int ngtcp2_crypto_read_write_crypto_data(ngtcp2_conn *conn,
|
||||
if (!ngtcp2_conn_is_server(conn) &&
|
||||
cptls->handshake_properties.client.early_data_acceptance ==
|
||||
PTLS_EARLY_DATA_REJECTED) {
|
||||
ngtcp2_conn_early_data_rejected(conn);
|
||||
rv = ngtcp2_conn_tls_early_data_rejected(conn);
|
||||
if (rv != 0) {
|
||||
rv = -1;
|
||||
goto fin;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < 4; ++i) {
|
||||
@@ -399,7 +413,7 @@ int ngtcp2_crypto_read_write_crypto_data(ngtcp2_conn *conn,
|
||||
}
|
||||
|
||||
if (rv == 0) {
|
||||
ngtcp2_conn_handshake_completed(conn);
|
||||
ngtcp2_conn_tls_handshake_completed(conn);
|
||||
}
|
||||
|
||||
rv = 0;
|
||||
@@ -432,32 +446,32 @@ int ngtcp2_crypto_set_local_transport_params(void *tls, const uint8_t *buf,
|
||||
return 0;
|
||||
}
|
||||
|
||||
ngtcp2_crypto_level ngtcp2_crypto_picotls_from_epoch(size_t epoch) {
|
||||
ngtcp2_encryption_level ngtcp2_crypto_picotls_from_epoch(size_t epoch) {
|
||||
switch (epoch) {
|
||||
case 0:
|
||||
return NGTCP2_CRYPTO_LEVEL_INITIAL;
|
||||
return NGTCP2_ENCRYPTION_LEVEL_INITIAL;
|
||||
case 1:
|
||||
return NGTCP2_CRYPTO_LEVEL_EARLY;
|
||||
return NGTCP2_ENCRYPTION_LEVEL_0RTT;
|
||||
case 2:
|
||||
return NGTCP2_CRYPTO_LEVEL_HANDSHAKE;
|
||||
return NGTCP2_ENCRYPTION_LEVEL_HANDSHAKE;
|
||||
case 3:
|
||||
return NGTCP2_CRYPTO_LEVEL_APPLICATION;
|
||||
return NGTCP2_ENCRYPTION_LEVEL_1RTT;
|
||||
default:
|
||||
assert(0);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
size_t ngtcp2_crypto_picotls_from_ngtcp2_crypto_level(
|
||||
ngtcp2_crypto_level crypto_level) {
|
||||
switch (crypto_level) {
|
||||
case NGTCP2_CRYPTO_LEVEL_INITIAL:
|
||||
size_t ngtcp2_crypto_picotls_from_ngtcp2_encryption_level(
|
||||
ngtcp2_encryption_level encryption_level) {
|
||||
switch (encryption_level) {
|
||||
case NGTCP2_ENCRYPTION_LEVEL_INITIAL:
|
||||
return 0;
|
||||
case NGTCP2_CRYPTO_LEVEL_EARLY:
|
||||
case NGTCP2_ENCRYPTION_LEVEL_0RTT:
|
||||
return 1;
|
||||
case NGTCP2_CRYPTO_LEVEL_HANDSHAKE:
|
||||
case NGTCP2_ENCRYPTION_LEVEL_HANDSHAKE:
|
||||
return 2;
|
||||
case NGTCP2_CRYPTO_LEVEL_APPLICATION:
|
||||
case NGTCP2_ENCRYPTION_LEVEL_1RTT:
|
||||
return 3;
|
||||
default:
|
||||
assert(0);
|
||||
@@ -543,8 +557,8 @@ int ngtcp2_crypto_picotls_collected_extensions(
|
||||
conn_ref = *ptls_get_data_ptr(ptls);
|
||||
conn = conn_ref->get_conn(conn_ref);
|
||||
|
||||
rv = ngtcp2_conn_decode_remote_transport_params(conn, extensions->data.base,
|
||||
extensions->data.len);
|
||||
rv = ngtcp2_conn_decode_and_set_remote_transport_params(
|
||||
conn, extensions->data.base, extensions->data.len);
|
||||
if (rv != 0) {
|
||||
ngtcp2_conn_set_tls_error(conn, rv);
|
||||
return -1;
|
||||
@@ -561,7 +575,7 @@ static int update_traffic_key_server_cb(ptls_update_traffic_key_t *self,
|
||||
const void *secret) {
|
||||
ngtcp2_crypto_conn_ref *conn_ref = *ptls_get_data_ptr(ptls);
|
||||
ngtcp2_conn *conn = conn_ref->get_conn(conn_ref);
|
||||
ngtcp2_crypto_level level = ngtcp2_crypto_picotls_from_epoch(epoch);
|
||||
ngtcp2_encryption_level level = ngtcp2_crypto_picotls_from_epoch(epoch);
|
||||
ptls_cipher_suite_t *cipher = ptls_get_cipher(ptls);
|
||||
size_t secretlen = cipher->hash->digest_size;
|
||||
ngtcp2_crypto_picotls_ctx *cptls;
|
||||
@@ -574,7 +588,7 @@ static int update_traffic_key_server_cb(ptls_update_traffic_key_t *self,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (level == NGTCP2_CRYPTO_LEVEL_HANDSHAKE) {
|
||||
if (level == NGTCP2_ENCRYPTION_LEVEL_HANDSHAKE) {
|
||||
/* libngtcp2 allows an application to change QUIC transport
|
||||
* parameters before installing Handshake tx key. We need to
|
||||
* wait for the key to get the correct local transport
|
||||
@@ -606,7 +620,7 @@ static int update_traffic_key_cb(ptls_update_traffic_key_t *self, ptls_t *ptls,
|
||||
int is_enc, size_t epoch, const void *secret) {
|
||||
ngtcp2_crypto_conn_ref *conn_ref = *ptls_get_data_ptr(ptls);
|
||||
ngtcp2_conn *conn = conn_ref->get_conn(conn_ref);
|
||||
ngtcp2_crypto_level level = ngtcp2_crypto_picotls_from_epoch(epoch);
|
||||
ngtcp2_encryption_level level = ngtcp2_crypto_picotls_from_epoch(epoch);
|
||||
ptls_cipher_suite_t *cipher = ptls_get_cipher(ptls);
|
||||
size_t secretlen = cipher->hash->digest_size;
|
||||
|
||||
@@ -660,7 +674,7 @@ int ngtcp2_crypto_picotls_configure_client_session(
|
||||
ngtcp2_crypto_picotls_ctx *cptls, ngtcp2_conn *conn) {
|
||||
ptls_handshake_properties_t *hsprops = &cptls->handshake_properties;
|
||||
|
||||
hsprops->client.max_early_data_size = calloc(1, sizeof(uint32_t));
|
||||
hsprops->client.max_early_data_size = calloc(1, sizeof(size_t));
|
||||
if (hsprops->client.max_early_data_size == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
+274
-67
@@ -29,7 +29,7 @@
|
||||
#include <assert.h>
|
||||
|
||||
#include <ngtcp2/ngtcp2_crypto.h>
|
||||
#include <ngtcp2/ngtcp2_crypto_openssl.h>
|
||||
#include <ngtcp2/ngtcp2_crypto_quictls.h>
|
||||
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/evp.h>
|
||||
@@ -42,6 +42,168 @@
|
||||
|
||||
#include "shared.h"
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
static int crypto_initialized;
|
||||
static EVP_CIPHER *crypto_aes_128_gcm;
|
||||
static EVP_CIPHER *crypto_aes_256_gcm;
|
||||
static EVP_CIPHER *crypto_chacha20_poly1305;
|
||||
static EVP_CIPHER *crypto_aes_128_ccm;
|
||||
static EVP_CIPHER *crypto_aes_128_ctr;
|
||||
static EVP_CIPHER *crypto_aes_256_ctr;
|
||||
static EVP_CIPHER *crypto_chacha20;
|
||||
static EVP_MD *crypto_sha256;
|
||||
static EVP_MD *crypto_sha384;
|
||||
static EVP_KDF *crypto_hkdf;
|
||||
|
||||
int ngtcp2_crypto_quictls_init(void) {
|
||||
crypto_aes_128_gcm = EVP_CIPHER_fetch(NULL, "AES-128-GCM", NULL);
|
||||
if (crypto_aes_128_gcm == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
crypto_aes_256_gcm = EVP_CIPHER_fetch(NULL, "AES-256-GCM", NULL);
|
||||
if (crypto_aes_256_gcm == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
crypto_chacha20_poly1305 = EVP_CIPHER_fetch(NULL, "ChaCha20-Poly1305", NULL);
|
||||
if (crypto_chacha20_poly1305 == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
crypto_aes_128_ccm = EVP_CIPHER_fetch(NULL, "AES-128-CCM", NULL);
|
||||
if (crypto_aes_128_ccm == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
crypto_aes_128_ctr = EVP_CIPHER_fetch(NULL, "AES-128-CTR", NULL);
|
||||
if (crypto_aes_128_ctr == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
crypto_aes_256_ctr = EVP_CIPHER_fetch(NULL, "AES-256-CTR", NULL);
|
||||
if (crypto_aes_256_ctr == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
crypto_chacha20 = EVP_CIPHER_fetch(NULL, "ChaCha20", NULL);
|
||||
if (crypto_chacha20 == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
crypto_sha256 = EVP_MD_fetch(NULL, "sha256", NULL);
|
||||
if (crypto_sha256 == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
crypto_sha384 = EVP_MD_fetch(NULL, "sha384", NULL);
|
||||
if (crypto_sha384 == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
crypto_hkdf = EVP_KDF_fetch(NULL, "hkdf", NULL);
|
||||
if (crypto_hkdf == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
crypto_initialized = 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const EVP_CIPHER *crypto_aead_aes_128_gcm(void) {
|
||||
if (crypto_aes_128_gcm) {
|
||||
return crypto_aes_128_gcm;
|
||||
}
|
||||
|
||||
return EVP_aes_128_gcm();
|
||||
}
|
||||
|
||||
static const EVP_CIPHER *crypto_aead_aes_256_gcm(void) {
|
||||
if (crypto_aes_256_gcm) {
|
||||
return crypto_aes_256_gcm;
|
||||
}
|
||||
|
||||
return EVP_aes_256_gcm();
|
||||
}
|
||||
|
||||
static const EVP_CIPHER *crypto_aead_chacha20_poly1305(void) {
|
||||
if (crypto_chacha20_poly1305) {
|
||||
return crypto_chacha20_poly1305;
|
||||
}
|
||||
|
||||
return EVP_chacha20_poly1305();
|
||||
}
|
||||
|
||||
static const EVP_CIPHER *crypto_aead_aes_128_ccm(void) {
|
||||
if (crypto_aes_128_ccm) {
|
||||
return crypto_aes_128_ccm;
|
||||
}
|
||||
|
||||
return EVP_aes_128_ccm();
|
||||
}
|
||||
|
||||
static const EVP_CIPHER *crypto_cipher_aes_128_ctr(void) {
|
||||
if (crypto_aes_128_ctr) {
|
||||
return crypto_aes_128_ctr;
|
||||
}
|
||||
|
||||
return EVP_aes_128_ctr();
|
||||
}
|
||||
|
||||
static const EVP_CIPHER *crypto_cipher_aes_256_ctr(void) {
|
||||
if (crypto_aes_256_ctr) {
|
||||
return crypto_aes_256_ctr;
|
||||
}
|
||||
|
||||
return EVP_aes_256_ctr();
|
||||
}
|
||||
|
||||
static const EVP_CIPHER *crypto_cipher_chacha20(void) {
|
||||
if (crypto_chacha20) {
|
||||
return crypto_chacha20;
|
||||
}
|
||||
|
||||
return EVP_chacha20();
|
||||
}
|
||||
|
||||
static const EVP_MD *crypto_md_sha256(void) {
|
||||
if (crypto_sha256) {
|
||||
return crypto_sha256;
|
||||
}
|
||||
|
||||
return EVP_sha256();
|
||||
}
|
||||
|
||||
static const EVP_MD *crypto_md_sha384(void) {
|
||||
if (crypto_sha384) {
|
||||
return crypto_sha384;
|
||||
}
|
||||
|
||||
return EVP_sha384();
|
||||
}
|
||||
|
||||
static EVP_KDF *crypto_kdf_hkdf(void) {
|
||||
if (crypto_hkdf) {
|
||||
return crypto_hkdf;
|
||||
}
|
||||
|
||||
return EVP_KDF_fetch(NULL, "hkdf", NULL);
|
||||
}
|
||||
#else /* !(OPENSSL_VERSION_NUMBER >= 0x30000000L) */
|
||||
# define crypto_aead_aes_128_gcm EVP_aes_128_gcm
|
||||
# define crypto_aead_aes_256_gcm EVP_aes_256_gcm
|
||||
# define crypto_aead_chacha20_poly1305 EVP_chacha20_poly1305
|
||||
# define crypto_aead_aes_128_ccm EVP_aes_128_ccm
|
||||
# define crypto_cipher_aes_128_ctr EVP_aes_128_ctr
|
||||
# define crypto_cipher_aes_256_ctr EVP_aes_256_ctr
|
||||
# define crypto_cipher_chacha20 EVP_chacha20
|
||||
# define crypto_md_sha256 EVP_sha256
|
||||
# define crypto_md_sha384 EVP_sha384
|
||||
|
||||
int ngtcp2_crypto_quictls_init(void) { return 0; }
|
||||
#endif /* !(OPENSSL_VERSION_NUMBER >= 0x30000000L) */
|
||||
|
||||
static size_t crypto_aead_max_overhead(const EVP_CIPHER *aead) {
|
||||
switch (EVP_CIPHER_nid(aead)) {
|
||||
case NID_aes_128_gcm:
|
||||
@@ -58,18 +220,18 @@ static size_t crypto_aead_max_overhead(const EVP_CIPHER *aead) {
|
||||
}
|
||||
|
||||
ngtcp2_crypto_aead *ngtcp2_crypto_aead_aes_128_gcm(ngtcp2_crypto_aead *aead) {
|
||||
return ngtcp2_crypto_aead_init(aead, (void *)EVP_aes_128_gcm());
|
||||
return ngtcp2_crypto_aead_init(aead, (void *)crypto_aead_aes_128_gcm());
|
||||
}
|
||||
|
||||
ngtcp2_crypto_md *ngtcp2_crypto_md_sha256(ngtcp2_crypto_md *md) {
|
||||
md->native_handle = (void *)EVP_sha256();
|
||||
md->native_handle = (void *)crypto_md_sha256();
|
||||
return md;
|
||||
}
|
||||
|
||||
ngtcp2_crypto_ctx *ngtcp2_crypto_ctx_initial(ngtcp2_crypto_ctx *ctx) {
|
||||
ngtcp2_crypto_aead_init(&ctx->aead, (void *)EVP_aes_128_gcm());
|
||||
ctx->md.native_handle = (void *)EVP_sha256();
|
||||
ctx->hp.native_handle = (void *)EVP_aes_128_ctr();
|
||||
ngtcp2_crypto_aead_init(&ctx->aead, (void *)crypto_aead_aes_128_gcm());
|
||||
ctx->md.native_handle = (void *)crypto_md_sha256();
|
||||
ctx->hp.native_handle = (void *)crypto_cipher_aes_128_ctr();
|
||||
ctx->max_encryption = 0;
|
||||
ctx->max_decryption_failure = 0;
|
||||
return ctx;
|
||||
@@ -83,26 +245,26 @@ ngtcp2_crypto_aead *ngtcp2_crypto_aead_init(ngtcp2_crypto_aead *aead,
|
||||
}
|
||||
|
||||
ngtcp2_crypto_aead *ngtcp2_crypto_aead_retry(ngtcp2_crypto_aead *aead) {
|
||||
return ngtcp2_crypto_aead_init(aead, (void *)EVP_aes_128_gcm());
|
||||
return ngtcp2_crypto_aead_init(aead, (void *)crypto_aead_aes_128_gcm());
|
||||
}
|
||||
|
||||
static const EVP_CIPHER *crypto_ssl_get_aead(SSL *ssl) {
|
||||
switch (SSL_CIPHER_get_id(SSL_get_current_cipher(ssl))) {
|
||||
static const EVP_CIPHER *crypto_cipher_id_get_aead(uint32_t cipher_id) {
|
||||
switch (cipher_id) {
|
||||
case TLS1_3_CK_AES_128_GCM_SHA256:
|
||||
return EVP_aes_128_gcm();
|
||||
return crypto_aead_aes_128_gcm();
|
||||
case TLS1_3_CK_AES_256_GCM_SHA384:
|
||||
return EVP_aes_256_gcm();
|
||||
return crypto_aead_aes_256_gcm();
|
||||
case TLS1_3_CK_CHACHA20_POLY1305_SHA256:
|
||||
return EVP_chacha20_poly1305();
|
||||
return crypto_aead_chacha20_poly1305();
|
||||
case TLS1_3_CK_AES_128_CCM_SHA256:
|
||||
return EVP_aes_128_ccm();
|
||||
return crypto_aead_aes_128_ccm();
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static uint64_t crypto_ssl_get_aead_max_encryption(SSL *ssl) {
|
||||
switch (SSL_CIPHER_get_id(SSL_get_current_cipher(ssl))) {
|
||||
static uint64_t crypto_cipher_id_get_aead_max_encryption(uint32_t cipher_id) {
|
||||
switch (cipher_id) {
|
||||
case TLS1_3_CK_AES_128_GCM_SHA256:
|
||||
case TLS1_3_CK_AES_256_GCM_SHA384:
|
||||
return NGTCP2_CRYPTO_MAX_ENCRYPTION_AES_GCM;
|
||||
@@ -115,8 +277,9 @@ static uint64_t crypto_ssl_get_aead_max_encryption(SSL *ssl) {
|
||||
}
|
||||
}
|
||||
|
||||
static uint64_t crypto_ssl_get_aead_max_decryption_failure(SSL *ssl) {
|
||||
switch (SSL_CIPHER_get_id(SSL_get_current_cipher(ssl))) {
|
||||
static uint64_t
|
||||
crypto_cipher_id_get_aead_max_decryption_failure(uint32_t cipher_id) {
|
||||
switch (cipher_id) {
|
||||
case TLS1_3_CK_AES_128_GCM_SHA256:
|
||||
case TLS1_3_CK_AES_256_GCM_SHA384:
|
||||
return NGTCP2_CRYPTO_MAX_DECRYPTION_FAILURE_AES_GCM;
|
||||
@@ -129,42 +292,75 @@ static uint64_t crypto_ssl_get_aead_max_decryption_failure(SSL *ssl) {
|
||||
}
|
||||
}
|
||||
|
||||
static const EVP_CIPHER *crypto_ssl_get_hp(SSL *ssl) {
|
||||
switch (SSL_CIPHER_get_id(SSL_get_current_cipher(ssl))) {
|
||||
static const EVP_CIPHER *crypto_cipher_id_get_hp(uint32_t cipher_id) {
|
||||
switch (cipher_id) {
|
||||
case TLS1_3_CK_AES_128_GCM_SHA256:
|
||||
case TLS1_3_CK_AES_128_CCM_SHA256:
|
||||
return EVP_aes_128_ctr();
|
||||
return crypto_cipher_aes_128_ctr();
|
||||
case TLS1_3_CK_AES_256_GCM_SHA384:
|
||||
return EVP_aes_256_ctr();
|
||||
return crypto_cipher_aes_256_ctr();
|
||||
case TLS1_3_CK_CHACHA20_POLY1305_SHA256:
|
||||
return EVP_chacha20();
|
||||
return crypto_cipher_chacha20();
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static const EVP_MD *crypto_ssl_get_md(SSL *ssl) {
|
||||
switch (SSL_CIPHER_get_id(SSL_get_current_cipher(ssl))) {
|
||||
static const EVP_MD *crypto_cipher_id_get_md(uint32_t cipher_id) {
|
||||
switch (cipher_id) {
|
||||
case TLS1_3_CK_AES_128_GCM_SHA256:
|
||||
case TLS1_3_CK_CHACHA20_POLY1305_SHA256:
|
||||
case TLS1_3_CK_AES_128_CCM_SHA256:
|
||||
return EVP_sha256();
|
||||
return crypto_md_sha256();
|
||||
case TLS1_3_CK_AES_256_GCM_SHA384:
|
||||
return EVP_sha384();
|
||||
return crypto_md_sha384();
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static int supported_cipher_id(uint32_t cipher_id) {
|
||||
switch (cipher_id) {
|
||||
case TLS1_3_CK_AES_128_GCM_SHA256:
|
||||
case TLS1_3_CK_AES_256_GCM_SHA384:
|
||||
case TLS1_3_CK_CHACHA20_POLY1305_SHA256:
|
||||
case TLS1_3_CK_AES_128_CCM_SHA256:
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static ngtcp2_crypto_ctx *crypto_ctx_cipher_id(ngtcp2_crypto_ctx *ctx,
|
||||
uint32_t cipher_id) {
|
||||
ngtcp2_crypto_aead_init(&ctx->aead,
|
||||
(void *)crypto_cipher_id_get_aead(cipher_id));
|
||||
ctx->md.native_handle = (void *)crypto_cipher_id_get_md(cipher_id);
|
||||
ctx->hp.native_handle = (void *)crypto_cipher_id_get_hp(cipher_id);
|
||||
ctx->max_encryption = crypto_cipher_id_get_aead_max_encryption(cipher_id);
|
||||
ctx->max_decryption_failure =
|
||||
crypto_cipher_id_get_aead_max_decryption_failure(cipher_id);
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
ngtcp2_crypto_ctx *ngtcp2_crypto_ctx_tls(ngtcp2_crypto_ctx *ctx,
|
||||
void *tls_native_handle) {
|
||||
SSL *ssl = tls_native_handle;
|
||||
ngtcp2_crypto_aead_init(&ctx->aead, (void *)crypto_ssl_get_aead(ssl));
|
||||
ctx->md.native_handle = (void *)crypto_ssl_get_md(ssl);
|
||||
ctx->hp.native_handle = (void *)crypto_ssl_get_hp(ssl);
|
||||
ctx->max_encryption = crypto_ssl_get_aead_max_encryption(ssl);
|
||||
ctx->max_decryption_failure = crypto_ssl_get_aead_max_decryption_failure(ssl);
|
||||
return ctx;
|
||||
const SSL_CIPHER *cipher = SSL_get_current_cipher(ssl);
|
||||
uint32_t cipher_id;
|
||||
|
||||
if (cipher == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cipher_id = (uint32_t)SSL_CIPHER_get_id(cipher);
|
||||
|
||||
if (!supported_cipher_id(cipher_id)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return crypto_ctx_cipher_id(ctx, cipher_id);
|
||||
}
|
||||
|
||||
ngtcp2_crypto_ctx *ngtcp2_crypto_ctx_tls_early(ngtcp2_crypto_ctx *ctx,
|
||||
@@ -327,7 +523,7 @@ int ngtcp2_crypto_hkdf_extract(uint8_t *dest, const ngtcp2_crypto_md *md,
|
||||
const uint8_t *salt, size_t saltlen) {
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
const EVP_MD *prf = md->native_handle;
|
||||
EVP_KDF *kdf = EVP_KDF_fetch(NULL, "hkdf", NULL);
|
||||
EVP_KDF *kdf = crypto_kdf_hkdf();
|
||||
EVP_KDF_CTX *kctx = EVP_KDF_CTX_new(kdf);
|
||||
int mode = EVP_KDF_HKDF_MODE_EXTRACT_ONLY;
|
||||
OSSL_PARAM params[] = {
|
||||
@@ -342,7 +538,9 @@ int ngtcp2_crypto_hkdf_extract(uint8_t *dest, const ngtcp2_crypto_md *md,
|
||||
};
|
||||
int rv = 0;
|
||||
|
||||
EVP_KDF_free(kdf);
|
||||
if (!crypto_initialized) {
|
||||
EVP_KDF_free(kdf);
|
||||
}
|
||||
|
||||
if (EVP_KDF_derive(kctx, dest, (size_t)EVP_MD_size(prf), params) <= 0) {
|
||||
rv = -1;
|
||||
@@ -382,7 +580,7 @@ int ngtcp2_crypto_hkdf_expand(uint8_t *dest, size_t destlen,
|
||||
size_t infolen) {
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
const EVP_MD *prf = md->native_handle;
|
||||
EVP_KDF *kdf = EVP_KDF_fetch(NULL, "hkdf", NULL);
|
||||
EVP_KDF *kdf = crypto_kdf_hkdf();
|
||||
EVP_KDF_CTX *kctx = EVP_KDF_CTX_new(kdf);
|
||||
int mode = EVP_KDF_HKDF_MODE_EXPAND_ONLY;
|
||||
OSSL_PARAM params[] = {
|
||||
@@ -397,7 +595,9 @@ int ngtcp2_crypto_hkdf_expand(uint8_t *dest, size_t destlen,
|
||||
};
|
||||
int rv = 0;
|
||||
|
||||
EVP_KDF_free(kdf);
|
||||
if (!crypto_initialized) {
|
||||
EVP_KDF_free(kdf);
|
||||
}
|
||||
|
||||
if (EVP_KDF_derive(kctx, dest, destlen, params) <= 0) {
|
||||
rv = -1;
|
||||
@@ -436,7 +636,7 @@ int ngtcp2_crypto_hkdf(uint8_t *dest, size_t destlen,
|
||||
const uint8_t *info, size_t infolen) {
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
const EVP_MD *prf = md->native_handle;
|
||||
EVP_KDF *kdf = EVP_KDF_fetch(NULL, "hkdf", NULL);
|
||||
EVP_KDF *kdf = crypto_kdf_hkdf();
|
||||
EVP_KDF_CTX *kctx = EVP_KDF_CTX_new(kdf);
|
||||
OSSL_PARAM params[] = {
|
||||
OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST,
|
||||
@@ -451,7 +651,9 @@ int ngtcp2_crypto_hkdf(uint8_t *dest, size_t destlen,
|
||||
};
|
||||
int rv = 0;
|
||||
|
||||
EVP_KDF_free(kdf);
|
||||
if (!crypto_initialized) {
|
||||
EVP_KDF_free(kdf);
|
||||
}
|
||||
|
||||
if (EVP_KDF_derive(kctx, dest, destlen, params) <= 0) {
|
||||
rv = -1;
|
||||
@@ -591,15 +793,16 @@ int ngtcp2_crypto_hp_mask(uint8_t *dest, const ngtcp2_crypto_cipher *hp,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ngtcp2_crypto_read_write_crypto_data(ngtcp2_conn *conn,
|
||||
ngtcp2_crypto_level crypto_level,
|
||||
const uint8_t *data, size_t datalen) {
|
||||
int ngtcp2_crypto_read_write_crypto_data(
|
||||
ngtcp2_conn *conn, ngtcp2_encryption_level encryption_level,
|
||||
const uint8_t *data, size_t datalen) {
|
||||
SSL *ssl = ngtcp2_conn_get_tls_native_handle(conn);
|
||||
int rv;
|
||||
int err;
|
||||
|
||||
if (SSL_provide_quic_data(
|
||||
ssl, ngtcp2_crypto_openssl_from_ngtcp2_crypto_level(crypto_level),
|
||||
ssl,
|
||||
ngtcp2_crypto_quictls_from_ngtcp2_encryption_level(encryption_level),
|
||||
data, datalen) != 1) {
|
||||
return -1;
|
||||
}
|
||||
@@ -613,9 +816,9 @@ int ngtcp2_crypto_read_write_crypto_data(ngtcp2_conn *conn,
|
||||
case SSL_ERROR_WANT_WRITE:
|
||||
return 0;
|
||||
case SSL_ERROR_WANT_CLIENT_HELLO_CB:
|
||||
return NGTCP2_CRYPTO_OPENSSL_ERR_TLS_WANT_CLIENT_HELLO_CB;
|
||||
return NGTCP2_CRYPTO_QUICTLS_ERR_TLS_WANT_CLIENT_HELLO_CB;
|
||||
case SSL_ERROR_WANT_X509_LOOKUP:
|
||||
return NGTCP2_CRYPTO_OPENSSL_ERR_TLS_WANT_X509_LOOKUP;
|
||||
return NGTCP2_CRYPTO_QUICTLS_ERR_TLS_WANT_X509_LOOKUP;
|
||||
case SSL_ERROR_SSL:
|
||||
return -1;
|
||||
default:
|
||||
@@ -623,7 +826,7 @@ int ngtcp2_crypto_read_write_crypto_data(ngtcp2_conn *conn,
|
||||
}
|
||||
}
|
||||
|
||||
ngtcp2_conn_handshake_completed(conn);
|
||||
ngtcp2_conn_tls_handshake_completed(conn);
|
||||
}
|
||||
|
||||
rv = SSL_process_quic_post_handshake(ssl);
|
||||
@@ -652,7 +855,7 @@ int ngtcp2_crypto_set_remote_transport_params(ngtcp2_conn *conn, void *tls) {
|
||||
|
||||
SSL_get_peer_quic_transport_params(ssl, &tp, &tplen);
|
||||
|
||||
rv = ngtcp2_conn_decode_remote_transport_params(conn, tp, tplen);
|
||||
rv = ngtcp2_conn_decode_and_set_remote_transport_params(conn, tp, tplen);
|
||||
if (rv != 0) {
|
||||
ngtcp2_conn_set_tls_error(conn, rv);
|
||||
return -1;
|
||||
@@ -670,17 +873,17 @@ int ngtcp2_crypto_set_local_transport_params(void *tls, const uint8_t *buf,
|
||||
return 0;
|
||||
}
|
||||
|
||||
ngtcp2_crypto_level ngtcp2_crypto_openssl_from_ossl_encryption_level(
|
||||
ngtcp2_encryption_level ngtcp2_crypto_quictls_from_ossl_encryption_level(
|
||||
OSSL_ENCRYPTION_LEVEL ossl_level) {
|
||||
switch (ossl_level) {
|
||||
case ssl_encryption_initial:
|
||||
return NGTCP2_CRYPTO_LEVEL_INITIAL;
|
||||
return NGTCP2_ENCRYPTION_LEVEL_INITIAL;
|
||||
case ssl_encryption_early_data:
|
||||
return NGTCP2_CRYPTO_LEVEL_EARLY;
|
||||
return NGTCP2_ENCRYPTION_LEVEL_0RTT;
|
||||
case ssl_encryption_handshake:
|
||||
return NGTCP2_CRYPTO_LEVEL_HANDSHAKE;
|
||||
return NGTCP2_ENCRYPTION_LEVEL_HANDSHAKE;
|
||||
case ssl_encryption_application:
|
||||
return NGTCP2_CRYPTO_LEVEL_APPLICATION;
|
||||
return NGTCP2_ENCRYPTION_LEVEL_1RTT;
|
||||
default:
|
||||
assert(0);
|
||||
abort(); /* if NDEBUG is set */
|
||||
@@ -688,16 +891,16 @@ ngtcp2_crypto_level ngtcp2_crypto_openssl_from_ossl_encryption_level(
|
||||
}
|
||||
|
||||
OSSL_ENCRYPTION_LEVEL
|
||||
ngtcp2_crypto_openssl_from_ngtcp2_crypto_level(
|
||||
ngtcp2_crypto_level crypto_level) {
|
||||
switch (crypto_level) {
|
||||
case NGTCP2_CRYPTO_LEVEL_INITIAL:
|
||||
ngtcp2_crypto_quictls_from_ngtcp2_encryption_level(
|
||||
ngtcp2_encryption_level encryption_level) {
|
||||
switch (encryption_level) {
|
||||
case NGTCP2_ENCRYPTION_LEVEL_INITIAL:
|
||||
return ssl_encryption_initial;
|
||||
case NGTCP2_CRYPTO_LEVEL_HANDSHAKE:
|
||||
case NGTCP2_ENCRYPTION_LEVEL_HANDSHAKE:
|
||||
return ssl_encryption_handshake;
|
||||
case NGTCP2_CRYPTO_LEVEL_APPLICATION:
|
||||
case NGTCP2_ENCRYPTION_LEVEL_1RTT:
|
||||
return ssl_encryption_application;
|
||||
case NGTCP2_CRYPTO_LEVEL_EARLY:
|
||||
case NGTCP2_ENCRYPTION_LEVEL_0RTT:
|
||||
return ssl_encryption_early_data;
|
||||
default:
|
||||
assert(0);
|
||||
@@ -730,8 +933,8 @@ static int set_encryption_secrets(SSL *ssl, OSSL_ENCRYPTION_LEVEL ossl_level,
|
||||
const uint8_t *tx_secret, size_t secretlen) {
|
||||
ngtcp2_crypto_conn_ref *conn_ref = SSL_get_app_data(ssl);
|
||||
ngtcp2_conn *conn = conn_ref->get_conn(conn_ref);
|
||||
ngtcp2_crypto_level level =
|
||||
ngtcp2_crypto_openssl_from_ossl_encryption_level(ossl_level);
|
||||
ngtcp2_encryption_level level =
|
||||
ngtcp2_crypto_quictls_from_ossl_encryption_level(ossl_level);
|
||||
|
||||
if (rx_secret &&
|
||||
ngtcp2_crypto_derive_and_install_rx_key(conn, NULL, NULL, NULL, level,
|
||||
@@ -752,8 +955,8 @@ static int add_handshake_data(SSL *ssl, OSSL_ENCRYPTION_LEVEL ossl_level,
|
||||
const uint8_t *data, size_t datalen) {
|
||||
ngtcp2_crypto_conn_ref *conn_ref = SSL_get_app_data(ssl);
|
||||
ngtcp2_conn *conn = conn_ref->get_conn(conn_ref);
|
||||
ngtcp2_crypto_level level =
|
||||
ngtcp2_crypto_openssl_from_ossl_encryption_level(ossl_level);
|
||||
ngtcp2_encryption_level level =
|
||||
ngtcp2_crypto_quictls_from_ossl_encryption_level(ossl_level);
|
||||
int rv;
|
||||
|
||||
rv = ngtcp2_conn_submit_crypto_data(conn, level, data, datalen);
|
||||
@@ -786,22 +989,26 @@ static SSL_QUIC_METHOD quic_method = {
|
||||
add_handshake_data,
|
||||
flush_flight,
|
||||
send_alert,
|
||||
#ifdef LIBRESSL_VERSION_NUMBER
|
||||
NULL,
|
||||
NULL,
|
||||
#endif /* LIBRESSL_VERSION_NUMBER */
|
||||
};
|
||||
|
||||
static void crypto_openssl_configure_context(SSL_CTX *ssl_ctx) {
|
||||
static void crypto_quictls_configure_context(SSL_CTX *ssl_ctx) {
|
||||
SSL_CTX_set_min_proto_version(ssl_ctx, TLS1_3_VERSION);
|
||||
SSL_CTX_set_max_proto_version(ssl_ctx, TLS1_3_VERSION);
|
||||
SSL_CTX_set_quic_method(ssl_ctx, &quic_method);
|
||||
}
|
||||
|
||||
int ngtcp2_crypto_openssl_configure_server_context(SSL_CTX *ssl_ctx) {
|
||||
crypto_openssl_configure_context(ssl_ctx);
|
||||
int ngtcp2_crypto_quictls_configure_server_context(SSL_CTX *ssl_ctx) {
|
||||
crypto_quictls_configure_context(ssl_ctx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ngtcp2_crypto_openssl_configure_client_context(SSL_CTX *ssl_ctx) {
|
||||
crypto_openssl_configure_context(ssl_ctx);
|
||||
int ngtcp2_crypto_quictls_configure_client_context(SSL_CTX *ssl_ctx) {
|
||||
crypto_quictls_configure_context(ssl_ctx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Vendored
+110
-80
@@ -64,11 +64,9 @@ int ngtcp2_crypto_hkdf_expand_label(uint8_t *dest, size_t destlen,
|
||||
(size_t)(p - info));
|
||||
}
|
||||
|
||||
#define NGTCP2_CRYPTO_INITIAL_SECRETLEN 32
|
||||
|
||||
int ngtcp2_crypto_derive_initial_secrets(uint32_t version, uint8_t *rx_secret,
|
||||
uint8_t *tx_secret,
|
||||
int ngtcp2_crypto_derive_initial_secrets(uint8_t *rx_secret, uint8_t *tx_secret,
|
||||
uint8_t *initial_secret,
|
||||
uint32_t version,
|
||||
const ngtcp2_cid *client_dcid,
|
||||
ngtcp2_crypto_side side) {
|
||||
static const uint8_t CLABEL[] = "client in";
|
||||
@@ -88,16 +86,14 @@ int ngtcp2_crypto_derive_initial_secrets(uint32_t version, uint8_t *rx_secret,
|
||||
|
||||
switch (version) {
|
||||
case NGTCP2_PROTO_VER_V1:
|
||||
default:
|
||||
salt = (const uint8_t *)NGTCP2_INITIAL_SALT_V1;
|
||||
saltlen = sizeof(NGTCP2_INITIAL_SALT_V1) - 1;
|
||||
break;
|
||||
case NGTCP2_PROTO_VER_V2_DRAFT:
|
||||
salt = (const uint8_t *)NGTCP2_INITIAL_SALT_V2_DRAFT;
|
||||
saltlen = sizeof(NGTCP2_INITIAL_SALT_V2_DRAFT) - 1;
|
||||
case NGTCP2_PROTO_VER_V2:
|
||||
salt = (const uint8_t *)NGTCP2_INITIAL_SALT_V2;
|
||||
saltlen = sizeof(NGTCP2_INITIAL_SALT_V2) - 1;
|
||||
break;
|
||||
default:
|
||||
salt = (const uint8_t *)NGTCP2_INITIAL_SALT_DRAFT;
|
||||
saltlen = sizeof(NGTCP2_INITIAL_SALT_DRAFT) - 1;
|
||||
}
|
||||
|
||||
if (ngtcp2_crypto_hkdf_extract(initial_secret, &ctx.md, client_dcid->data,
|
||||
@@ -139,9 +135,9 @@ int ngtcp2_crypto_derive_packet_protection_key(
|
||||
static const uint8_t KEY_LABEL_V1[] = "quic key";
|
||||
static const uint8_t IV_LABEL_V1[] = "quic iv";
|
||||
static const uint8_t HP_KEY_LABEL_V1[] = "quic hp";
|
||||
static const uint8_t KEY_LABEL_V2_DRAFT[] = "quicv2 key";
|
||||
static const uint8_t IV_LABEL_V2_DRAFT[] = "quicv2 iv";
|
||||
static const uint8_t HP_KEY_LABEL_V2_DRAFT[] = "quicv2 hp";
|
||||
static const uint8_t KEY_LABEL_V2[] = "quicv2 key";
|
||||
static const uint8_t IV_LABEL_V2[] = "quicv2 iv";
|
||||
static const uint8_t HP_KEY_LABEL_V2[] = "quicv2 hp";
|
||||
size_t keylen = ngtcp2_crypto_aead_keylen(aead);
|
||||
size_t ivlen = ngtcp2_crypto_packet_protection_ivlen(aead);
|
||||
const uint8_t *key_label;
|
||||
@@ -152,13 +148,13 @@ int ngtcp2_crypto_derive_packet_protection_key(
|
||||
size_t hp_key_labellen;
|
||||
|
||||
switch (version) {
|
||||
case NGTCP2_PROTO_VER_V2_DRAFT:
|
||||
key_label = KEY_LABEL_V2_DRAFT;
|
||||
key_labellen = sizeof(KEY_LABEL_V2_DRAFT) - 1;
|
||||
iv_label = IV_LABEL_V2_DRAFT;
|
||||
iv_labellen = sizeof(IV_LABEL_V2_DRAFT) - 1;
|
||||
hp_key_label = HP_KEY_LABEL_V2_DRAFT;
|
||||
hp_key_labellen = sizeof(HP_KEY_LABEL_V2_DRAFT) - 1;
|
||||
case NGTCP2_PROTO_VER_V2:
|
||||
key_label = KEY_LABEL_V2;
|
||||
key_labellen = sizeof(KEY_LABEL_V2) - 1;
|
||||
iv_label = IV_LABEL_V2;
|
||||
iv_labellen = sizeof(IV_LABEL_V2) - 1;
|
||||
hp_key_label = HP_KEY_LABEL_V2;
|
||||
hp_key_labellen = sizeof(HP_KEY_LABEL_V2) - 1;
|
||||
break;
|
||||
default:
|
||||
key_label = KEY_LABEL_V1;
|
||||
@@ -188,14 +184,27 @@ int ngtcp2_crypto_derive_packet_protection_key(
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ngtcp2_crypto_update_traffic_secret(uint8_t *dest,
|
||||
int ngtcp2_crypto_update_traffic_secret(uint8_t *dest, uint32_t version,
|
||||
const ngtcp2_crypto_md *md,
|
||||
const uint8_t *secret,
|
||||
size_t secretlen) {
|
||||
static const uint8_t LABEL[] = "quic ku";
|
||||
static const uint8_t LABEL_V2[] = "quicv2 ku";
|
||||
const uint8_t *label;
|
||||
size_t labellen;
|
||||
|
||||
switch (version) {
|
||||
case NGTCP2_PROTO_VER_V2:
|
||||
label = LABEL_V2;
|
||||
labellen = sizeof(LABEL_V2) - 1;
|
||||
break;
|
||||
default:
|
||||
label = LABEL;
|
||||
labellen = sizeof(LABEL) - 1;
|
||||
}
|
||||
|
||||
if (ngtcp2_crypto_hkdf_expand_label(dest, secretlen, md, secret, secretlen,
|
||||
LABEL, sizeof(LABEL) - 1) != 0) {
|
||||
label, labellen) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -204,7 +213,7 @@ int ngtcp2_crypto_update_traffic_secret(uint8_t *dest,
|
||||
|
||||
int ngtcp2_crypto_derive_and_install_rx_key(ngtcp2_conn *conn, uint8_t *key,
|
||||
uint8_t *iv, uint8_t *hp_key,
|
||||
ngtcp2_crypto_level level,
|
||||
ngtcp2_encryption_level level,
|
||||
const uint8_t *secret,
|
||||
size_t secretlen) {
|
||||
const ngtcp2_crypto_ctx *ctx;
|
||||
@@ -220,7 +229,7 @@ int ngtcp2_crypto_derive_and_install_rx_key(ngtcp2_conn *conn, uint8_t *key,
|
||||
ngtcp2_crypto_ctx cctx;
|
||||
uint32_t version;
|
||||
|
||||
if (level == NGTCP2_CRYPTO_LEVEL_EARLY && !ngtcp2_conn_is_server(conn)) {
|
||||
if (level == NGTCP2_ENCRYPTION_LEVEL_0RTT && !ngtcp2_conn_is_server(conn)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -235,13 +244,16 @@ int ngtcp2_crypto_derive_and_install_rx_key(ngtcp2_conn *conn, uint8_t *key,
|
||||
}
|
||||
|
||||
switch (level) {
|
||||
case NGTCP2_CRYPTO_LEVEL_EARLY:
|
||||
ngtcp2_crypto_ctx_tls_early(&cctx, tls);
|
||||
ngtcp2_conn_set_early_crypto_ctx(conn, &cctx);
|
||||
ctx = ngtcp2_conn_get_early_crypto_ctx(conn);
|
||||
case NGTCP2_ENCRYPTION_LEVEL_0RTT:
|
||||
if (ngtcp2_crypto_ctx_tls_early(&cctx, tls) == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ngtcp2_conn_set_0rtt_crypto_ctx(conn, &cctx);
|
||||
ctx = ngtcp2_conn_get_0rtt_crypto_ctx(conn);
|
||||
version = ngtcp2_conn_get_client_chosen_version(conn);
|
||||
break;
|
||||
case NGTCP2_CRYPTO_LEVEL_HANDSHAKE:
|
||||
case NGTCP2_ENCRYPTION_LEVEL_HANDSHAKE:
|
||||
if (ngtcp2_conn_is_server(conn) &&
|
||||
!ngtcp2_conn_get_negotiated_version(conn)) {
|
||||
rv = ngtcp2_crypto_set_remote_transport_params(conn, tls);
|
||||
@@ -250,15 +262,21 @@ int ngtcp2_crypto_derive_and_install_rx_key(ngtcp2_conn *conn, uint8_t *key,
|
||||
}
|
||||
}
|
||||
/* fall through */
|
||||
default:
|
||||
case NGTCP2_ENCRYPTION_LEVEL_1RTT:
|
||||
ctx = ngtcp2_conn_get_crypto_ctx(conn);
|
||||
version = ngtcp2_conn_get_negotiated_version(conn);
|
||||
|
||||
if (!ctx->aead.native_handle) {
|
||||
ngtcp2_crypto_ctx_tls(&cctx, tls);
|
||||
if (ngtcp2_crypto_ctx_tls(&cctx, tls) == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ngtcp2_conn_set_crypto_ctx(conn, &cctx);
|
||||
ctx = ngtcp2_conn_get_crypto_ctx(conn);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
aead = &ctx->aead;
|
||||
@@ -280,20 +298,20 @@ int ngtcp2_crypto_derive_and_install_rx_key(ngtcp2_conn *conn, uint8_t *key,
|
||||
}
|
||||
|
||||
switch (level) {
|
||||
case NGTCP2_CRYPTO_LEVEL_EARLY:
|
||||
rv = ngtcp2_conn_install_early_key(conn, &aead_ctx, iv, ivlen, &hp_ctx);
|
||||
case NGTCP2_ENCRYPTION_LEVEL_0RTT:
|
||||
rv = ngtcp2_conn_install_0rtt_key(conn, &aead_ctx, iv, ivlen, &hp_ctx);
|
||||
if (rv != 0) {
|
||||
goto fail;
|
||||
}
|
||||
break;
|
||||
case NGTCP2_CRYPTO_LEVEL_HANDSHAKE:
|
||||
case NGTCP2_ENCRYPTION_LEVEL_HANDSHAKE:
|
||||
rv = ngtcp2_conn_install_rx_handshake_key(conn, &aead_ctx, iv, ivlen,
|
||||
&hp_ctx);
|
||||
if (rv != 0) {
|
||||
goto fail;
|
||||
}
|
||||
break;
|
||||
case NGTCP2_CRYPTO_LEVEL_APPLICATION:
|
||||
case NGTCP2_ENCRYPTION_LEVEL_1RTT:
|
||||
if (!ngtcp2_conn_is_server(conn)) {
|
||||
rv = ngtcp2_crypto_set_remote_transport_params(conn, tls);
|
||||
if (rv != 0) {
|
||||
@@ -345,7 +363,7 @@ static int crypto_set_local_transport_params(ngtcp2_conn *conn, void *tls) {
|
||||
|
||||
int ngtcp2_crypto_derive_and_install_tx_key(ngtcp2_conn *conn, uint8_t *key,
|
||||
uint8_t *iv, uint8_t *hp_key,
|
||||
ngtcp2_crypto_level level,
|
||||
ngtcp2_encryption_level level,
|
||||
const uint8_t *secret,
|
||||
size_t secretlen) {
|
||||
const ngtcp2_crypto_ctx *ctx;
|
||||
@@ -361,7 +379,7 @@ int ngtcp2_crypto_derive_and_install_tx_key(ngtcp2_conn *conn, uint8_t *key,
|
||||
ngtcp2_crypto_ctx cctx;
|
||||
uint32_t version;
|
||||
|
||||
if (level == NGTCP2_CRYPTO_LEVEL_EARLY && ngtcp2_conn_is_server(conn)) {
|
||||
if (level == NGTCP2_ENCRYPTION_LEVEL_0RTT && ngtcp2_conn_is_server(conn)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -376,13 +394,16 @@ int ngtcp2_crypto_derive_and_install_tx_key(ngtcp2_conn *conn, uint8_t *key,
|
||||
}
|
||||
|
||||
switch (level) {
|
||||
case NGTCP2_CRYPTO_LEVEL_EARLY:
|
||||
ngtcp2_crypto_ctx_tls_early(&cctx, tls);
|
||||
ngtcp2_conn_set_early_crypto_ctx(conn, &cctx);
|
||||
ctx = ngtcp2_conn_get_early_crypto_ctx(conn);
|
||||
case NGTCP2_ENCRYPTION_LEVEL_0RTT:
|
||||
if (ngtcp2_crypto_ctx_tls_early(&cctx, tls) == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ngtcp2_conn_set_0rtt_crypto_ctx(conn, &cctx);
|
||||
ctx = ngtcp2_conn_get_0rtt_crypto_ctx(conn);
|
||||
version = ngtcp2_conn_get_client_chosen_version(conn);
|
||||
break;
|
||||
case NGTCP2_CRYPTO_LEVEL_HANDSHAKE:
|
||||
case NGTCP2_ENCRYPTION_LEVEL_HANDSHAKE:
|
||||
if (ngtcp2_conn_is_server(conn) &&
|
||||
!ngtcp2_conn_get_negotiated_version(conn)) {
|
||||
rv = ngtcp2_crypto_set_remote_transport_params(conn, tls);
|
||||
@@ -391,15 +412,21 @@ int ngtcp2_crypto_derive_and_install_tx_key(ngtcp2_conn *conn, uint8_t *key,
|
||||
}
|
||||
}
|
||||
/* fall through */
|
||||
default:
|
||||
case NGTCP2_ENCRYPTION_LEVEL_1RTT:
|
||||
ctx = ngtcp2_conn_get_crypto_ctx(conn);
|
||||
version = ngtcp2_conn_get_negotiated_version(conn);
|
||||
|
||||
if (!ctx->aead.native_handle) {
|
||||
ngtcp2_crypto_ctx_tls(&cctx, tls);
|
||||
if (ngtcp2_crypto_ctx_tls(&cctx, tls) == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ngtcp2_conn_set_crypto_ctx(conn, &cctx);
|
||||
ctx = ngtcp2_conn_get_crypto_ctx(conn);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
aead = &ctx->aead;
|
||||
@@ -421,13 +448,13 @@ int ngtcp2_crypto_derive_and_install_tx_key(ngtcp2_conn *conn, uint8_t *key,
|
||||
}
|
||||
|
||||
switch (level) {
|
||||
case NGTCP2_CRYPTO_LEVEL_EARLY:
|
||||
rv = ngtcp2_conn_install_early_key(conn, &aead_ctx, iv, ivlen, &hp_ctx);
|
||||
case NGTCP2_ENCRYPTION_LEVEL_0RTT:
|
||||
rv = ngtcp2_conn_install_0rtt_key(conn, &aead_ctx, iv, ivlen, &hp_ctx);
|
||||
if (rv != 0) {
|
||||
goto fail;
|
||||
}
|
||||
break;
|
||||
case NGTCP2_CRYPTO_LEVEL_HANDSHAKE:
|
||||
case NGTCP2_ENCRYPTION_LEVEL_HANDSHAKE:
|
||||
rv = ngtcp2_conn_install_tx_handshake_key(conn, &aead_ctx, iv, ivlen,
|
||||
&hp_ctx);
|
||||
if (rv != 0) {
|
||||
@@ -440,7 +467,7 @@ int ngtcp2_crypto_derive_and_install_tx_key(ngtcp2_conn *conn, uint8_t *key,
|
||||
}
|
||||
|
||||
break;
|
||||
case NGTCP2_CRYPTO_LEVEL_APPLICATION:
|
||||
case NGTCP2_ENCRYPTION_LEVEL_1RTT:
|
||||
rv = ngtcp2_conn_install_tx_key(conn, secret, secretlen, &aead_ctx, iv,
|
||||
ivlen, &hp_ctx);
|
||||
if (rv != 0) {
|
||||
@@ -521,7 +548,7 @@ int ngtcp2_crypto_derive_and_install_initial_key(
|
||||
ngtcp2_conn_set_initial_crypto_ctx(conn, &ctx);
|
||||
|
||||
if (ngtcp2_crypto_derive_initial_secrets(
|
||||
version, rx_secret, tx_secret, initial_secret, client_dcid,
|
||||
rx_secret, tx_secret, initial_secret, version, client_dcid,
|
||||
server ? NGTCP2_CRYPTO_SIDE_SERVER : NGTCP2_CRYPTO_SIDE_CLIENT) !=
|
||||
0) {
|
||||
return -1;
|
||||
@@ -564,16 +591,14 @@ int ngtcp2_crypto_derive_and_install_initial_key(
|
||||
|
||||
switch (version) {
|
||||
case NGTCP2_PROTO_VER_V1:
|
||||
default:
|
||||
retry_key = (const uint8_t *)NGTCP2_RETRY_KEY_V1;
|
||||
retry_noncelen = sizeof(NGTCP2_RETRY_NONCE_V1) - 1;
|
||||
break;
|
||||
case NGTCP2_PROTO_VER_V2_DRAFT:
|
||||
retry_key = (const uint8_t *)NGTCP2_RETRY_KEY_V2_DRAFT;
|
||||
retry_noncelen = sizeof(NGTCP2_RETRY_NONCE_V2_DRAFT) - 1;
|
||||
case NGTCP2_PROTO_VER_V2:
|
||||
retry_key = (const uint8_t *)NGTCP2_RETRY_KEY_V2;
|
||||
retry_noncelen = sizeof(NGTCP2_RETRY_NONCE_V2) - 1;
|
||||
break;
|
||||
default:
|
||||
retry_key = (const uint8_t *)NGTCP2_RETRY_KEY_DRAFT;
|
||||
retry_noncelen = sizeof(NGTCP2_RETRY_NONCE_DRAFT) - 1;
|
||||
}
|
||||
|
||||
if (ngtcp2_crypto_aead_ctx_encrypt_init(&retry_aead_ctx, &retry_aead,
|
||||
@@ -657,7 +682,7 @@ int ngtcp2_crypto_derive_and_install_vneg_initial_key(
|
||||
}
|
||||
|
||||
if (ngtcp2_crypto_derive_initial_secrets(
|
||||
version, rx_secret, tx_secret, initial_secret, client_dcid,
|
||||
rx_secret, tx_secret, initial_secret, version, client_dcid,
|
||||
server ? NGTCP2_CRYPTO_SIDE_SERVER : NGTCP2_CRYPTO_SIDE_CLIENT) !=
|
||||
0) {
|
||||
return -1;
|
||||
@@ -725,8 +750,8 @@ int ngtcp2_crypto_update_key(
|
||||
size_t ivlen = ngtcp2_crypto_packet_protection_ivlen(aead);
|
||||
uint32_t version = ngtcp2_conn_get_negotiated_version(conn);
|
||||
|
||||
if (ngtcp2_crypto_update_traffic_secret(rx_secret, md, current_rx_secret,
|
||||
secretlen) != 0) {
|
||||
if (ngtcp2_crypto_update_traffic_secret(rx_secret, version, md,
|
||||
current_rx_secret, secretlen) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -735,8 +760,8 @@ int ngtcp2_crypto_update_key(
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ngtcp2_crypto_update_traffic_secret(tx_secret, md, current_tx_secret,
|
||||
secretlen) != 0) {
|
||||
if (ngtcp2_crypto_update_traffic_secret(tx_secret, version, md,
|
||||
current_tx_secret, secretlen) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -883,6 +908,7 @@ static size_t crypto_generate_retry_token_aad(uint8_t *dest, uint32_t version,
|
||||
|
||||
version = ngtcp2_htonl(version);
|
||||
memcpy(p, &version, sizeof(version));
|
||||
p += sizeof(version);
|
||||
memcpy(p, sa, (size_t)salen);
|
||||
p += salen;
|
||||
memcpy(p, retry_scid->data, retry_scid->datalen);
|
||||
@@ -907,13 +933,15 @@ ngtcp2_ssize ngtcp2_crypto_generate_retry_token(
|
||||
ngtcp2_crypto_md md;
|
||||
ngtcp2_crypto_aead_ctx aead_ctx;
|
||||
size_t plaintextlen;
|
||||
uint8_t aad[sizeof(version) + sizeof(ngtcp2_sockaddr_storage) +
|
||||
NGTCP2_MAX_CIDLEN];
|
||||
uint8_t
|
||||
aad[sizeof(version) + sizeof(ngtcp2_sockaddr_union) + NGTCP2_MAX_CIDLEN];
|
||||
size_t aadlen;
|
||||
uint8_t *p = plaintext;
|
||||
ngtcp2_tstamp ts_be = ngtcp2_htonl64(ts);
|
||||
int rv;
|
||||
|
||||
assert((size_t)remote_addrlen <= sizeof(ngtcp2_sockaddr_union));
|
||||
|
||||
memset(plaintext, 0, sizeof(plaintext));
|
||||
|
||||
*p++ = (uint8_t)odcid->datalen;
|
||||
@@ -984,8 +1012,8 @@ int ngtcp2_crypto_verify_retry_token(
|
||||
ngtcp2_crypto_aead_ctx aead_ctx;
|
||||
ngtcp2_crypto_aead aead;
|
||||
ngtcp2_crypto_md md;
|
||||
uint8_t aad[sizeof(version) + sizeof(ngtcp2_sockaddr_storage) +
|
||||
NGTCP2_MAX_CIDLEN];
|
||||
uint8_t
|
||||
aad[sizeof(version) + sizeof(ngtcp2_sockaddr_union) + NGTCP2_MAX_CIDLEN];
|
||||
size_t aadlen;
|
||||
const uint8_t *rand_data;
|
||||
const uint8_t *ciphertext;
|
||||
@@ -994,6 +1022,8 @@ int ngtcp2_crypto_verify_retry_token(
|
||||
int rv;
|
||||
ngtcp2_tstamp gen_ts;
|
||||
|
||||
assert((size_t)remote_addrlen <= sizeof(ngtcp2_sockaddr_union));
|
||||
|
||||
if (tokenlen != NGTCP2_CRYPTO_MAX_RETRY_TOKENLEN ||
|
||||
token[0] != NGTCP2_CRYPTO_TOKEN_MAGIC_RETRY) {
|
||||
return -1;
|
||||
@@ -1034,7 +1064,9 @@ int ngtcp2_crypto_verify_retry_token(
|
||||
|
||||
cil = plaintext[0];
|
||||
|
||||
assert(cil == 0 || (cil >= NGTCP2_MIN_CIDLEN && cil <= NGTCP2_MAX_CIDLEN));
|
||||
if (cil != 0 && (cil < NGTCP2_MIN_CIDLEN || cil > NGTCP2_MAX_CIDLEN)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(&gen_ts, plaintext + /* cid len = */ 1 + NGTCP2_MAX_CIDLEN,
|
||||
sizeof(gen_ts));
|
||||
@@ -1055,11 +1087,11 @@ static size_t crypto_generate_regular_token_aad(uint8_t *dest,
|
||||
size_t addrlen;
|
||||
|
||||
switch (sa->sa_family) {
|
||||
case AF_INET:
|
||||
case NGTCP2_AF_INET:
|
||||
addr = (const uint8_t *)&((const ngtcp2_sockaddr_in *)(void *)sa)->sin_addr;
|
||||
addrlen = sizeof(((const ngtcp2_sockaddr_in *)(void *)sa)->sin_addr);
|
||||
break;
|
||||
case AF_INET6:
|
||||
case NGTCP2_AF_INET6:
|
||||
addr =
|
||||
(const uint8_t *)&((const ngtcp2_sockaddr_in6 *)(void *)sa)->sin6_addr;
|
||||
addrlen = sizeof(((const ngtcp2_sockaddr_in6 *)(void *)sa)->sin6_addr);
|
||||
@@ -1234,8 +1266,8 @@ ngtcp2_ssize ngtcp2_crypto_write_connection_close(
|
||||
|
||||
ngtcp2_crypto_ctx_initial(&ctx);
|
||||
|
||||
if (ngtcp2_crypto_derive_initial_secrets(version, rx_secret, tx_secret,
|
||||
initial_secret, scid,
|
||||
if (ngtcp2_crypto_derive_initial_secrets(rx_secret, tx_secret, initial_secret,
|
||||
version, scid,
|
||||
NGTCP2_CRYPTO_SIDE_SERVER) != 0) {
|
||||
return -1;
|
||||
}
|
||||
@@ -1287,16 +1319,14 @@ ngtcp2_ssize ngtcp2_crypto_write_retry(uint8_t *dest, size_t destlen,
|
||||
|
||||
switch (version) {
|
||||
case NGTCP2_PROTO_VER_V1:
|
||||
default:
|
||||
key = (const uint8_t *)NGTCP2_RETRY_KEY_V1;
|
||||
noncelen = sizeof(NGTCP2_RETRY_NONCE_V1) - 1;
|
||||
break;
|
||||
case NGTCP2_PROTO_VER_V2_DRAFT:
|
||||
key = (const uint8_t *)NGTCP2_RETRY_KEY_V2_DRAFT;
|
||||
noncelen = sizeof(NGTCP2_RETRY_NONCE_V2_DRAFT) - 1;
|
||||
case NGTCP2_PROTO_VER_V2:
|
||||
key = (const uint8_t *)NGTCP2_RETRY_KEY_V2;
|
||||
noncelen = sizeof(NGTCP2_RETRY_NONCE_V2) - 1;
|
||||
break;
|
||||
default:
|
||||
key = (const uint8_t *)NGTCP2_RETRY_KEY_DRAFT;
|
||||
noncelen = sizeof(NGTCP2_RETRY_NONCE_DRAFT) - 1;
|
||||
}
|
||||
|
||||
if (ngtcp2_crypto_aead_ctx_encrypt_init(&aead_ctx, &aead, key, noncelen) !=
|
||||
@@ -1331,8 +1361,8 @@ int ngtcp2_crypto_client_initial_cb(ngtcp2_conn *conn, void *user_data) {
|
||||
return NGTCP2_ERR_CALLBACK_FAILURE;
|
||||
}
|
||||
|
||||
if (ngtcp2_crypto_read_write_crypto_data(conn, NGTCP2_CRYPTO_LEVEL_INITIAL,
|
||||
NULL, 0) != 0) {
|
||||
if (ngtcp2_crypto_read_write_crypto_data(
|
||||
conn, NGTCP2_ENCRYPTION_LEVEL_INITIAL, NULL, 0) != 0) {
|
||||
return NGTCP2_ERR_CALLBACK_FAILURE;
|
||||
}
|
||||
|
||||
@@ -1398,15 +1428,15 @@ void ngtcp2_crypto_delete_crypto_cipher_ctx_cb(
|
||||
}
|
||||
|
||||
int ngtcp2_crypto_recv_crypto_data_cb(ngtcp2_conn *conn,
|
||||
ngtcp2_crypto_level crypto_level,
|
||||
ngtcp2_encryption_level encryption_level,
|
||||
uint64_t offset, const uint8_t *data,
|
||||
size_t datalen, void *user_data) {
|
||||
int rv;
|
||||
(void)offset;
|
||||
(void)user_data;
|
||||
|
||||
if (ngtcp2_crypto_read_write_crypto_data(conn, crypto_level, data, datalen) !=
|
||||
0) {
|
||||
if (ngtcp2_crypto_read_write_crypto_data(conn, encryption_level, data,
|
||||
datalen) != 0) {
|
||||
rv = ngtcp2_conn_get_tls_error(conn);
|
||||
if (rv) {
|
||||
return rv;
|
||||
|
||||
Vendored
+68
-21
@@ -31,16 +31,6 @@
|
||||
|
||||
#include <ngtcp2/ngtcp2_crypto.h>
|
||||
|
||||
/**
|
||||
* @macro
|
||||
*
|
||||
* :macro:`NGTCP2_INITIAL_SALT_DRAFT` is a salt value which is used to
|
||||
* derive initial secret. It is used for QUIC draft versions.
|
||||
*/
|
||||
#define NGTCP2_INITIAL_SALT_DRAFT \
|
||||
"\xaf\xbf\xec\x28\x99\x93\xd2\x4c\x9e\x97\x86\xf1\x9c\x61\x11\xe0\x43\x90" \
|
||||
"\xa8\x99"
|
||||
|
||||
/**
|
||||
* @macro
|
||||
*
|
||||
@@ -54,12 +44,12 @@
|
||||
/**
|
||||
* @macro
|
||||
*
|
||||
* :macro:`NGTCP2_INITIAL_SALT_V2_DRAFT` is a salt value which is used to
|
||||
* derive initial secret. It is used for QUIC v2 draft.
|
||||
* :macro:`NGTCP2_INITIAL_SALT_V2` is a salt value which is used to
|
||||
* derive initial secret. It is used for QUIC v2.
|
||||
*/
|
||||
#define NGTCP2_INITIAL_SALT_V2_DRAFT \
|
||||
"\xa7\x07\xc2\x03\xa5\x9b\x47\x18\x4a\x1d\x62\xca\x57\x04\x06\xea\x7a\xe3" \
|
||||
"\xe5\xd3"
|
||||
#define NGTCP2_INITIAL_SALT_V2 \
|
||||
"\x0d\xed\xe3\xde\xf7\x00\xa6\xdb\x81\x93\x81\xbe\x6e\x26\x9d\xcb\xf9\xbd" \
|
||||
"\x2e\xd9"
|
||||
|
||||
/* Maximum key usage (encryption) limits */
|
||||
#define NGTCP2_CRYPTO_MAX_ENCRYPTION_AES_GCM (1ULL << 23)
|
||||
@@ -72,6 +62,30 @@
|
||||
#define NGTCP2_CRYPTO_MAX_DECRYPTION_FAILURE_CHACHA20_POLY1305 (1ULL << 36)
|
||||
#define NGTCP2_CRYPTO_MAX_DECRYPTION_FAILURE_AES_CCM (2965820ULL)
|
||||
|
||||
/**
|
||||
* @macro
|
||||
*
|
||||
* :macro:`NGTCP2_CRYPTO_INITIAL_SECRETLEN` is the length of secret
|
||||
* for Initial packets.
|
||||
*/
|
||||
#define NGTCP2_CRYPTO_INITIAL_SECRETLEN 32
|
||||
|
||||
/**
|
||||
* @macro
|
||||
*
|
||||
* :macro:`NGTCP2_CRYPTO_INITIAL_KEYLEN` is the length of key for
|
||||
* Initial packets.
|
||||
*/
|
||||
#define NGTCP2_CRYPTO_INITIAL_KEYLEN 16
|
||||
|
||||
/**
|
||||
* @macro
|
||||
*
|
||||
* :macro:`NGTCP2_CRYPTO_INITIAL_IVLEN` is the length of IV for
|
||||
* Initial packets.
|
||||
*/
|
||||
#define NGTCP2_CRYPTO_INITIAL_IVLEN 12
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
@@ -86,7 +100,7 @@ ngtcp2_crypto_ctx *ngtcp2_crypto_ctx_initial(ngtcp2_crypto_ctx *ctx);
|
||||
* `ngtcp2_crypto_aead_init` initializes |aead| with the provided
|
||||
* |aead_native_handle| which is an underlying AEAD object.
|
||||
*
|
||||
* If libngtcp2_crypto_openssl is linked, |aead_native_handle| must be
|
||||
* If libngtcp2_crypto_quictls is linked, |aead_native_handle| must be
|
||||
* a pointer to EVP_CIPHER.
|
||||
*
|
||||
* If libngtcp2_crypto_gnutls is linked, |aead_native_handle| must be
|
||||
@@ -106,6 +120,25 @@ ngtcp2_crypto_aead *ngtcp2_crypto_aead_init(ngtcp2_crypto_aead *aead,
|
||||
*/
|
||||
ngtcp2_crypto_aead *ngtcp2_crypto_aead_retry(ngtcp2_crypto_aead *aead);
|
||||
|
||||
/**
|
||||
* @enum
|
||||
*
|
||||
* :type:`ngtcp2_crypto_side` indicates which side the application
|
||||
* implements; client or server.
|
||||
*/
|
||||
typedef enum ngtcp2_crypto_side {
|
||||
/**
|
||||
* :enum:`NGTCP2_CRYPTO_SIDE_CLIENT` indicates that the application
|
||||
* is client.
|
||||
*/
|
||||
NGTCP2_CRYPTO_SIDE_CLIENT,
|
||||
/**
|
||||
* :enum:`NGTCP2_CRYPTO_SIDE_SERVER` indicates that the application
|
||||
* is server.
|
||||
*/
|
||||
NGTCP2_CRYPTO_SIDE_SERVER
|
||||
} ngtcp2_crypto_side;
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
@@ -122,9 +155,9 @@ ngtcp2_crypto_aead *ngtcp2_crypto_aead_retry(ngtcp2_crypto_aead *aead);
|
||||
*
|
||||
* This function returns 0 if it succeeds, or -1.
|
||||
*/
|
||||
int ngtcp2_crypto_derive_initial_secrets(uint32_t version, uint8_t *rx_secret,
|
||||
uint8_t *tx_secret,
|
||||
int ngtcp2_crypto_derive_initial_secrets(uint8_t *rx_secret, uint8_t *tx_secret,
|
||||
uint8_t *initial_secret,
|
||||
uint32_t version,
|
||||
const ngtcp2_cid *client_dcid,
|
||||
ngtcp2_crypto_side side);
|
||||
|
||||
@@ -168,7 +201,7 @@ int ngtcp2_crypto_derive_packet_protection_key(uint8_t *key, uint8_t *iv,
|
||||
*
|
||||
* This function returns 0 if it succeeds, or -1.
|
||||
*/
|
||||
int ngtcp2_crypto_update_traffic_secret(uint8_t *dest,
|
||||
int ngtcp2_crypto_update_traffic_secret(uint8_t *dest, uint32_t version,
|
||||
const ngtcp2_crypto_md *md,
|
||||
const uint8_t *secret,
|
||||
size_t secretlen);
|
||||
@@ -181,7 +214,7 @@ int ngtcp2_crypto_update_traffic_secret(uint8_t *dest,
|
||||
* pointed by |buf| of length |len|, to the native handle |tls|.
|
||||
*
|
||||
* |tls| points to a implementation dependent TLS session object. If
|
||||
* libngtcp2_crypto_openssl is linked, |tls| must be a pointer to SSL
|
||||
* libngtcp2_crypto_quictls is linked, |tls| must be a pointer to SSL
|
||||
* object.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or -1.
|
||||
@@ -197,7 +230,7 @@ int ngtcp2_crypto_set_local_transport_params(void *tls, const uint8_t *buf,
|
||||
* `ngtcp2_conn_set_remote_transport_params`.
|
||||
*
|
||||
* |tls| points to a implementation dependent TLS session object. If
|
||||
* libngtcp2_crypto_openssl is linked, |tls| must be a pointer to SSL
|
||||
* libngtcp2_crypto_quictls is linked, |tls| must be a pointer to SSL
|
||||
* object.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or -1.
|
||||
@@ -347,4 +380,18 @@ ngtcp2_crypto_aead *ngtcp2_crypto_aead_aes_128_gcm(ngtcp2_crypto_aead *aead);
|
||||
*/
|
||||
int ngtcp2_crypto_random(uint8_t *data, size_t datalen);
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* `ngtcp2_crypto_hkdf_expand_label` performs HKDF expand label. The
|
||||
* result is |destlen| bytes long, and is stored to the buffer pointed
|
||||
* by |dest|.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or -1.
|
||||
*/
|
||||
int ngtcp2_crypto_hkdf_expand_label(uint8_t *dest, size_t destlen,
|
||||
const ngtcp2_crypto_md *md,
|
||||
const uint8_t *secret, size_t secretlen,
|
||||
const uint8_t *label, size_t labellen);
|
||||
|
||||
#endif /* NGTCP2_SHARED_H */
|
||||
+52
-30
@@ -73,9 +73,8 @@ ngtcp2_crypto_aead *ngtcp2_crypto_aead_retry(ngtcp2_crypto_aead *aead) {
|
||||
return ngtcp2_crypto_aead_init(aead, (void *)wolfSSL_EVP_aes_128_gcm());
|
||||
}
|
||||
|
||||
static uint64_t crypto_wolfssl_get_aead_max_encryption(WOLFSSL *ssl) {
|
||||
const WOLFSSL_EVP_CIPHER *aead = wolfSSL_quic_get_aead(ssl);
|
||||
|
||||
static uint64_t
|
||||
crypto_aead_get_aead_max_encryption(const WOLFSSL_EVP_CIPHER *aead) {
|
||||
if (wolfSSL_quic_aead_is_gcm(aead)) {
|
||||
return NGTCP2_CRYPTO_MAX_ENCRYPTION_AES_GCM;
|
||||
}
|
||||
@@ -88,9 +87,8 @@ static uint64_t crypto_wolfssl_get_aead_max_encryption(WOLFSSL *ssl) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint64_t crypto_wolfssl_get_aead_max_decryption_failure(WOLFSSL *ssl) {
|
||||
const WOLFSSL_EVP_CIPHER *aead = wolfSSL_quic_get_aead(ssl);
|
||||
|
||||
static uint64_t
|
||||
crypto_aead_get_aead_max_decryption_failure(const WOLFSSL_EVP_CIPHER *aead) {
|
||||
if (wolfSSL_quic_aead_is_gcm(aead)) {
|
||||
return NGTCP2_CRYPTO_MAX_DECRYPTION_FAILURE_AES_GCM;
|
||||
}
|
||||
@@ -103,16 +101,30 @@ static uint64_t crypto_wolfssl_get_aead_max_decryption_failure(WOLFSSL *ssl) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int supported_aead(const WOLFSSL_EVP_CIPHER *aead) {
|
||||
return wolfSSL_quic_aead_is_gcm(aead) ||
|
||||
wolfSSL_quic_aead_is_chacha20(aead) || wolfSSL_quic_aead_is_ccm(aead);
|
||||
}
|
||||
|
||||
ngtcp2_crypto_ctx *ngtcp2_crypto_ctx_tls(ngtcp2_crypto_ctx *ctx,
|
||||
void *tls_native_handle) {
|
||||
WOLFSSL *ssl = tls_native_handle;
|
||||
const WOLFSSL_EVP_CIPHER *aead = wolfSSL_quic_get_aead(ssl);
|
||||
|
||||
ngtcp2_crypto_aead_init(&ctx->aead, (void *)wolfSSL_quic_get_aead(ssl));
|
||||
if (aead == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!supported_aead(aead)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ngtcp2_crypto_aead_init(&ctx->aead, (void *)aead);
|
||||
ctx->md.native_handle = (void *)wolfSSL_quic_get_md(ssl);
|
||||
ctx->hp.native_handle = (void *)wolfSSL_quic_get_hp(ssl);
|
||||
ctx->max_encryption = crypto_wolfssl_get_aead_max_encryption(ssl);
|
||||
ctx->max_encryption = crypto_aead_get_aead_max_encryption(aead);
|
||||
ctx->max_decryption_failure =
|
||||
crypto_wolfssl_get_aead_max_decryption_failure(ssl);
|
||||
crypto_aead_get_aead_max_decryption_failure(aead);
|
||||
return ctx;
|
||||
}
|
||||
|
||||
@@ -211,6 +223,7 @@ int ngtcp2_crypto_hkdf_extract(uint8_t *dest, const ngtcp2_crypto_md *md,
|
||||
const uint8_t *salt, size_t saltlen) {
|
||||
if (wolfSSL_quic_hkdf_extract(dest, md->native_handle, secret, secretlen,
|
||||
salt, saltlen) != WOLFSSL_SUCCESS) {
|
||||
DEBUG_MSG("WOLFSSL: wolfSSL_quic_hkdf_extract FAILED\n");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
@@ -222,6 +235,7 @@ int ngtcp2_crypto_hkdf_expand(uint8_t *dest, size_t destlen,
|
||||
size_t infolen) {
|
||||
if (wolfSSL_quic_hkdf_expand(dest, destlen, md->native_handle, secret,
|
||||
secretlen, info, infolen) != WOLFSSL_SUCCESS) {
|
||||
DEBUG_MSG("WOLFSSL: wolfSSL_quic_hkdf_expand FAILED\n");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
@@ -233,6 +247,7 @@ int ngtcp2_crypto_hkdf(uint8_t *dest, size_t destlen,
|
||||
const uint8_t *info, size_t infolen) {
|
||||
if (wolfSSL_quic_hkdf(dest, destlen, md->native_handle, secret, secretlen,
|
||||
salt, saltlen, info, infolen) != WOLFSSL_SUCCESS) {
|
||||
DEBUG_MSG("WOLFSSL: wolfSSL_quic_hkdf FAILED\n");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
@@ -286,18 +301,19 @@ int ngtcp2_crypto_hp_mask(uint8_t *dest, const ngtcp2_crypto_cipher *hp,
|
||||
sizeof(PLAINTEXT) - 1) != WOLFSSL_SUCCESS ||
|
||||
wolfSSL_EVP_EncryptFinal_ex(actx, dest + sizeof(PLAINTEXT) - 1, &len) !=
|
||||
WOLFSSL_SUCCESS) {
|
||||
DEBUG_MSG("WOLFSSL: hp_mask FAILED\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ngtcp2_crypto_read_write_crypto_data(ngtcp2_conn *conn,
|
||||
ngtcp2_crypto_level crypto_level,
|
||||
const uint8_t *data, size_t datalen) {
|
||||
int ngtcp2_crypto_read_write_crypto_data(
|
||||
ngtcp2_conn *conn, ngtcp2_encryption_level encryption_level,
|
||||
const uint8_t *data, size_t datalen) {
|
||||
WOLFSSL *ssl = ngtcp2_conn_get_tls_native_handle(conn);
|
||||
WOLFSSL_ENCRYPTION_LEVEL level =
|
||||
ngtcp2_crypto_wolfssl_from_ngtcp2_crypto_level(crypto_level);
|
||||
ngtcp2_crypto_wolfssl_from_ngtcp2_encryption_level(encryption_level);
|
||||
int rv;
|
||||
int err;
|
||||
|
||||
@@ -313,9 +329,9 @@ int ngtcp2_crypto_read_write_crypto_data(ngtcp2_conn *conn,
|
||||
|
||||
if (!ngtcp2_conn_get_handshake_completed(conn)) {
|
||||
rv = wolfSSL_quic_do_handshake(ssl);
|
||||
DEBUG_MSG("WOLFSSL: do_handshake, rv=%d\n", rv);
|
||||
if (rv <= 0) {
|
||||
err = wolfSSL_get_error(ssl, rv);
|
||||
DEBUG_MSG("WOLFSSL: do_handshake, rv=%d, err=%d\n", rv, err);
|
||||
switch (err) {
|
||||
case SSL_ERROR_WANT_READ:
|
||||
case SSL_ERROR_WANT_WRITE:
|
||||
@@ -328,7 +344,7 @@ int ngtcp2_crypto_read_write_crypto_data(ngtcp2_conn *conn,
|
||||
}
|
||||
|
||||
DEBUG_MSG("WOLFSSL: handshake done\n");
|
||||
ngtcp2_conn_handshake_completed(conn);
|
||||
ngtcp2_conn_tls_handshake_completed(conn);
|
||||
}
|
||||
|
||||
rv = wolfSSL_process_quic_post_handshake(ssl);
|
||||
@@ -359,7 +375,7 @@ int ngtcp2_crypto_set_remote_transport_params(ngtcp2_conn *conn, void *tls) {
|
||||
wolfSSL_get_peer_quic_transport_params(ssl, &tp, &tplen);
|
||||
DEBUG_MSG("WOLFSSL: get peer transport params, len=%lu\n", tplen);
|
||||
|
||||
rv = ngtcp2_conn_decode_remote_transport_params(conn, tp, tplen);
|
||||
rv = ngtcp2_conn_decode_and_set_remote_transport_params(conn, tp, tplen);
|
||||
if (rv != 0) {
|
||||
DEBUG_MSG("WOLFSSL: decode peer transport params failed, rv=%d\n", rv);
|
||||
ngtcp2_conn_set_tls_error(conn, rv);
|
||||
@@ -380,17 +396,17 @@ int ngtcp2_crypto_set_local_transport_params(void *tls, const uint8_t *buf,
|
||||
return 0;
|
||||
}
|
||||
|
||||
ngtcp2_crypto_level ngtcp2_crypto_wolfssl_from_wolfssl_encryption_level(
|
||||
ngtcp2_encryption_level ngtcp2_crypto_wolfssl_from_wolfssl_encryption_level(
|
||||
WOLFSSL_ENCRYPTION_LEVEL wolfssl_level) {
|
||||
switch (wolfssl_level) {
|
||||
case wolfssl_encryption_initial:
|
||||
return NGTCP2_CRYPTO_LEVEL_INITIAL;
|
||||
return NGTCP2_ENCRYPTION_LEVEL_INITIAL;
|
||||
case wolfssl_encryption_early_data:
|
||||
return NGTCP2_CRYPTO_LEVEL_EARLY;
|
||||
return NGTCP2_ENCRYPTION_LEVEL_0RTT;
|
||||
case wolfssl_encryption_handshake:
|
||||
return NGTCP2_CRYPTO_LEVEL_HANDSHAKE;
|
||||
return NGTCP2_ENCRYPTION_LEVEL_HANDSHAKE;
|
||||
case wolfssl_encryption_application:
|
||||
return NGTCP2_CRYPTO_LEVEL_APPLICATION;
|
||||
return NGTCP2_ENCRYPTION_LEVEL_1RTT;
|
||||
default:
|
||||
assert(0);
|
||||
abort(); /* if NDEBUG is set */
|
||||
@@ -398,16 +414,16 @@ ngtcp2_crypto_level ngtcp2_crypto_wolfssl_from_wolfssl_encryption_level(
|
||||
}
|
||||
|
||||
WOLFSSL_ENCRYPTION_LEVEL
|
||||
ngtcp2_crypto_wolfssl_from_ngtcp2_crypto_level(
|
||||
ngtcp2_crypto_level crypto_level) {
|
||||
switch (crypto_level) {
|
||||
case NGTCP2_CRYPTO_LEVEL_INITIAL:
|
||||
ngtcp2_crypto_wolfssl_from_ngtcp2_encryption_level(
|
||||
ngtcp2_encryption_level encryption_level) {
|
||||
switch (encryption_level) {
|
||||
case NGTCP2_ENCRYPTION_LEVEL_INITIAL:
|
||||
return wolfssl_encryption_initial;
|
||||
case NGTCP2_CRYPTO_LEVEL_HANDSHAKE:
|
||||
case NGTCP2_ENCRYPTION_LEVEL_HANDSHAKE:
|
||||
return wolfssl_encryption_handshake;
|
||||
case NGTCP2_CRYPTO_LEVEL_APPLICATION:
|
||||
case NGTCP2_ENCRYPTION_LEVEL_1RTT:
|
||||
return wolfssl_encryption_application;
|
||||
case NGTCP2_CRYPTO_LEVEL_EARLY:
|
||||
case NGTCP2_ENCRYPTION_LEVEL_0RTT:
|
||||
return wolfssl_encryption_early_data;
|
||||
default:
|
||||
assert(0);
|
||||
@@ -441,7 +457,7 @@ static int set_encryption_secrets(WOLFSSL *ssl,
|
||||
const uint8_t *tx_secret, size_t secretlen) {
|
||||
ngtcp2_crypto_conn_ref *conn_ref = SSL_get_app_data(ssl);
|
||||
ngtcp2_conn *conn = conn_ref->get_conn(conn_ref);
|
||||
ngtcp2_crypto_level level =
|
||||
ngtcp2_encryption_level level =
|
||||
ngtcp2_crypto_wolfssl_from_wolfssl_encryption_level(wolfssl_level);
|
||||
|
||||
DEBUG_MSG("WOLFSSL: set encryption secrets, level=%d, rxlen=%lu, txlen=%lu\n",
|
||||
@@ -467,7 +483,7 @@ static int add_handshake_data(WOLFSSL *ssl,
|
||||
const uint8_t *data, size_t datalen) {
|
||||
ngtcp2_crypto_conn_ref *conn_ref = SSL_get_app_data(ssl);
|
||||
ngtcp2_conn *conn = conn_ref->get_conn(conn_ref);
|
||||
ngtcp2_crypto_level level =
|
||||
ngtcp2_encryption_level level =
|
||||
ngtcp2_crypto_wolfssl_from_wolfssl_encryption_level(wolfssl_level);
|
||||
int rv;
|
||||
|
||||
@@ -514,11 +530,17 @@ static void crypto_wolfssl_configure_context(WOLFSSL_CTX *ssl_ctx) {
|
||||
|
||||
int ngtcp2_crypto_wolfssl_configure_server_context(WOLFSSL_CTX *ssl_ctx) {
|
||||
crypto_wolfssl_configure_context(ssl_ctx);
|
||||
#if PRINTF_DEBUG
|
||||
wolfSSL_Debugging_ON();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ngtcp2_crypto_wolfssl_configure_client_context(WOLFSSL_CTX *ssl_ctx) {
|
||||
crypto_wolfssl_configure_context(ssl_ctx);
|
||||
wolfSSL_CTX_UseSessionTicket(ssl_ctx);
|
||||
#if PRINTF_DEBUG
|
||||
wolfSSL_Debugging_ON();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
+1207
-1165
File diff suppressed because it is too large.
Load diff
+13
-7
@@ -27,6 +27,9 @@
|
||||
#include <assert.h>
|
||||
|
||||
#include "ngtcp2_macro.h"
|
||||
#include "ngtcp2_tstamp.h"
|
||||
|
||||
ngtcp2_objalloc_def(acktr_entry, ngtcp2_acktr_entry, oplent);
|
||||
|
||||
static void acktr_entry_init(ngtcp2_acktr_entry *ent, int64_t pkt_num,
|
||||
ngtcp2_tstamp tstamp) {
|
||||
@@ -66,7 +69,7 @@ int ngtcp2_acktr_init(ngtcp2_acktr *acktr, ngtcp2_log *log,
|
||||
rv = ngtcp2_ringbuf_init(&acktr->acks, 32, sizeof(ngtcp2_acktr_ack_entry),
|
||||
mem);
|
||||
if (rv != 0) {
|
||||
return rv;
|
||||
goto fail_acks_init;
|
||||
}
|
||||
|
||||
ngtcp2_ksl_init(&acktr->ents, greater, sizeof(int64_t), mem);
|
||||
@@ -78,6 +81,10 @@ int ngtcp2_acktr_init(ngtcp2_acktr *acktr, ngtcp2_log *log,
|
||||
acktr->rx_npkt = 0;
|
||||
|
||||
return 0;
|
||||
|
||||
fail_acks_init:
|
||||
ngtcp2_objalloc_free(&acktr->objalloc);
|
||||
return rv;
|
||||
}
|
||||
|
||||
void ngtcp2_acktr_free(ngtcp2_acktr *acktr) {
|
||||
@@ -286,16 +293,16 @@ void ngtcp2_acktr_recv_ack(ngtcp2_acktr *acktr, const ngtcp2_ack *fr) {
|
||||
return;
|
||||
}
|
||||
|
||||
min_ack = largest_ack - (int64_t)fr->first_ack_blklen;
|
||||
min_ack = largest_ack - (int64_t)fr->first_ack_range;
|
||||
|
||||
if (min_ack <= ent->pkt_num && ent->pkt_num <= largest_ack) {
|
||||
acktr_on_ack(acktr, rb, j);
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < fr->num_blks && j < nacks; ++i) {
|
||||
largest_ack = min_ack - (int64_t)fr->blks[i].gap - 2;
|
||||
min_ack = largest_ack - (int64_t)fr->blks[i].blklen;
|
||||
for (i = 0; i < fr->rangecnt && j < nacks; ++i) {
|
||||
largest_ack = min_ack - (int64_t)fr->ranges[i].gap - 2;
|
||||
min_ack = largest_ack - (int64_t)fr->ranges[i].len;
|
||||
|
||||
for (;;) {
|
||||
if (ent->pkt_num > largest_ack) {
|
||||
@@ -326,8 +333,7 @@ void ngtcp2_acktr_commit_ack(ngtcp2_acktr *acktr) {
|
||||
int ngtcp2_acktr_require_active_ack(ngtcp2_acktr *acktr,
|
||||
ngtcp2_duration max_ack_delay,
|
||||
ngtcp2_tstamp ts) {
|
||||
return acktr->first_unacked_ts != UINT64_MAX &&
|
||||
acktr->first_unacked_ts + max_ack_delay <= ts;
|
||||
return ngtcp2_tstamp_elapsed(acktr->first_unacked_ts, max_ack_delay, ts);
|
||||
}
|
||||
|
||||
void ngtcp2_acktr_immediate_ack(ngtcp2_acktr *acktr) {
|
||||
|
||||
+3
-2
@@ -65,7 +65,7 @@ typedef struct ngtcp2_acktr_entry {
|
||||
};
|
||||
} ngtcp2_acktr_entry;
|
||||
|
||||
ngtcp2_objalloc_def(acktr_entry, ngtcp2_acktr_entry, oplent);
|
||||
ngtcp2_objalloc_decl(acktr_entry, ngtcp2_acktr_entry, oplent);
|
||||
|
||||
/*
|
||||
* ngtcp2_acktr_entry_objalloc_new allocates memory for ent, and
|
||||
@@ -124,7 +124,8 @@ typedef struct ngtcp2_acktr {
|
||||
/* first_unacked_ts is timestamp when ngtcp2_acktr_entry is added
|
||||
first time after the last outgoing ACK frame. */
|
||||
ngtcp2_tstamp first_unacked_ts;
|
||||
/* rx_npkt is the number of packets received without sending ACK. */
|
||||
/* rx_npkt is the number of ACK eliciting packets received without
|
||||
sending ACK. */
|
||||
size_t rx_npkt;
|
||||
} ngtcp2_acktr;
|
||||
|
||||
|
||||
Vendored
+4
-4
@@ -27,6 +27,8 @@
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "ngtcp2_unreachable.h"
|
||||
|
||||
ngtcp2_addr *ngtcp2_addr_init(ngtcp2_addr *dest, const ngtcp2_sockaddr *addr,
|
||||
ngtcp2_socklen addrlen) {
|
||||
dest->addrlen = addrlen;
|
||||
@@ -66,8 +68,7 @@ static int sockaddr_eq(const ngtcp2_sockaddr *a, const ngtcp2_sockaddr *b) {
|
||||
memcmp(&ai->sin6_addr, &bi->sin6_addr, sizeof(ai->sin6_addr)) == 0;
|
||||
}
|
||||
default:
|
||||
assert(0);
|
||||
abort();
|
||||
ngtcp2_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,8 +110,7 @@ uint32_t ngtcp2_addr_compare(const ngtcp2_addr *aa, const ngtcp2_addr *bb) {
|
||||
return flags;
|
||||
}
|
||||
default:
|
||||
assert(0);
|
||||
abort();
|
||||
ngtcp2_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vendored
+4
-2
@@ -38,8 +38,10 @@
|
||||
*/
|
||||
void ngtcp2_addr_copy(ngtcp2_addr *dest, const ngtcp2_addr *src);
|
||||
|
||||
/*
|
||||
* ngtcp2_addr_eq returns nonzero if |a| equals |b|.
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* `ngtcp2_addr_eq` returns nonzero if |a| equals |b|.
|
||||
*/
|
||||
int ngtcp2_addr_eq(const ngtcp2_addr *a, const ngtcp2_addr *b);
|
||||
|
||||
|
||||
Vendored
+1352
-594
File diff suppressed because it is too large.
Load diff
Vendored
+86
-96
@@ -39,118 +39,108 @@ typedef struct ngtcp2_rst ngtcp2_rst;
|
||||
typedef enum ngtcp2_bbr_state {
|
||||
NGTCP2_BBR_STATE_STARTUP,
|
||||
NGTCP2_BBR_STATE_DRAIN,
|
||||
NGTCP2_BBR_STATE_PROBE_BW,
|
||||
NGTCP2_BBR_STATE_PROBE_BW_DOWN,
|
||||
NGTCP2_BBR_STATE_PROBE_BW_CRUISE,
|
||||
NGTCP2_BBR_STATE_PROBE_BW_REFILL,
|
||||
NGTCP2_BBR_STATE_PROBE_BW_UP,
|
||||
NGTCP2_BBR_STATE_PROBE_RTT,
|
||||
} ngtcp2_bbr_state;
|
||||
|
||||
typedef enum ngtcp2_bbr_ack_phase {
|
||||
NGTCP2_BBR_ACK_PHASE_ACKS_PROBE_STARTING,
|
||||
NGTCP2_BBR_ACK_PHASE_ACKS_PROBE_STOPPING,
|
||||
NGTCP2_BBR_ACK_PHASE_ACKS_PROBE_FEEDBACK,
|
||||
NGTCP2_BBR_ACK_PHASE_ACKS_REFILLING,
|
||||
} ngtcp2_bbr_ack_phase;
|
||||
|
||||
/*
|
||||
* ngtcp2_bbr_cc is BBR congestion controller, described in
|
||||
* https://tools.ietf.org/html/draft-cardwell-iccrg-bbr-congestion-control-00
|
||||
* ngtcp2_cc_bbr is BBR v2 congestion controller, described in
|
||||
* https://datatracker.ietf.org/doc/html/draft-cardwell-iccrg-bbr-congestion-control-01
|
||||
*/
|
||||
typedef struct ngtcp2_bbr_cc {
|
||||
ngtcp2_cc_base ccb;
|
||||
typedef struct ngtcp2_cc_bbr {
|
||||
ngtcp2_cc cc;
|
||||
|
||||
/* The max filter used to estimate BBR.BtlBw. */
|
||||
ngtcp2_window_filter btl_bw_filter;
|
||||
uint64_t initial_cwnd;
|
||||
ngtcp2_rst *rst;
|
||||
ngtcp2_rand rand;
|
||||
ngtcp2_rand_ctx rand_ctx;
|
||||
|
||||
/* BBR variables */
|
||||
/* max_bw_filter for tracking the maximum recent delivery rate
|
||||
samples for estimating max_bw. */
|
||||
ngtcp2_window_filter max_bw_filter;
|
||||
|
||||
/* The dynamic gain factor used to scale BBR.BtlBw to
|
||||
produce BBR.pacing_rate. */
|
||||
double pacing_gain;
|
||||
/* The dynamic gain factor used to scale the estimated BDP to produce a
|
||||
congestion window (cwnd). */
|
||||
double cwnd_gain;
|
||||
uint64_t full_bw;
|
||||
/* packet.delivered value denoting the end of a packet-timed round trip. */
|
||||
uint64_t next_round_delivered;
|
||||
/* Count of packet-timed round trips. */
|
||||
uint64_t round_count;
|
||||
uint64_t prior_cwnd;
|
||||
/* target_cwnd is the upper bound on the volume of data BBR
|
||||
allows in flight. */
|
||||
uint64_t target_cwnd;
|
||||
/* BBR's estimated bottleneck bandwidth available to the
|
||||
transport flow, estimated from the maximum delivery rate sample in a
|
||||
sliding window. */
|
||||
uint64_t btl_bw;
|
||||
/* BBR's estimated two-way round-trip propagation delay of
|
||||
the path, estimated from the windowed minimum recent round-trip delay
|
||||
sample. */
|
||||
ngtcp2_duration rt_prop;
|
||||
/* The wall clock time at which the current BBR.RTProp
|
||||
sample was obtained. */
|
||||
ngtcp2_tstamp rtprop_stamp;
|
||||
ngtcp2_tstamp cycle_stamp;
|
||||
ngtcp2_window_filter extra_acked_filter;
|
||||
|
||||
ngtcp2_duration min_rtt;
|
||||
ngtcp2_tstamp min_rtt_stamp;
|
||||
ngtcp2_tstamp probe_rtt_done_stamp;
|
||||
/* congestion_recovery_start_ts is the time when congestion recovery
|
||||
period started.*/
|
||||
int probe_rtt_round_done;
|
||||
uint64_t prior_cwnd;
|
||||
int idle_restart;
|
||||
ngtcp2_tstamp extra_acked_interval_start;
|
||||
uint64_t extra_acked_delivered;
|
||||
|
||||
/* Congestion signals */
|
||||
int loss_in_round;
|
||||
uint64_t bw_latest;
|
||||
uint64_t inflight_latest;
|
||||
|
||||
/* Lower bounds */
|
||||
uint64_t bw_lo;
|
||||
uint64_t inflight_lo;
|
||||
|
||||
/* Round counting */
|
||||
uint64_t next_round_delivered;
|
||||
int round_start;
|
||||
uint64_t round_count;
|
||||
|
||||
/* Full pipe */
|
||||
int filled_pipe;
|
||||
uint64_t full_bw;
|
||||
size_t full_bw_count;
|
||||
|
||||
/* Pacing rate */
|
||||
uint64_t pacing_gain_h;
|
||||
|
||||
ngtcp2_bbr_state state;
|
||||
uint64_t cwnd_gain_h;
|
||||
|
||||
int loss_round_start;
|
||||
uint64_t loss_round_delivered;
|
||||
uint64_t rounds_since_bw_probe;
|
||||
uint64_t max_bw;
|
||||
uint64_t bw;
|
||||
uint64_t cycle_count;
|
||||
uint64_t extra_acked;
|
||||
uint64_t bytes_lost_in_round;
|
||||
size_t loss_events_in_round;
|
||||
uint64_t offload_budget;
|
||||
uint64_t probe_up_cnt;
|
||||
ngtcp2_tstamp cycle_stamp;
|
||||
ngtcp2_bbr_ack_phase ack_phase;
|
||||
ngtcp2_duration bw_probe_wait;
|
||||
int bw_probe_samples;
|
||||
size_t bw_probe_up_rounds;
|
||||
uint64_t bw_probe_up_acks;
|
||||
uint64_t inflight_hi;
|
||||
uint64_t bw_hi;
|
||||
int probe_rtt_expired;
|
||||
ngtcp2_duration probe_rtt_min_delay;
|
||||
ngtcp2_tstamp probe_rtt_min_stamp;
|
||||
int in_loss_recovery;
|
||||
int packet_conservation;
|
||||
uint64_t max_inflight;
|
||||
ngtcp2_tstamp congestion_recovery_start_ts;
|
||||
uint64_t congestion_recovery_next_round_delivered;
|
||||
size_t full_bw_count;
|
||||
size_t cycle_index;
|
||||
ngtcp2_bbr_state state;
|
||||
/* A boolean that records whether BBR estimates that it has ever fully
|
||||
utilized its available bandwidth ("filled the pipe"). */
|
||||
int filled_pipe;
|
||||
/* A boolean that BBR sets to true once per packet-timed round trip,
|
||||
on ACKs that advance BBR.round_count. */
|
||||
int round_start;
|
||||
int rtprop_expired;
|
||||
int idle_restart;
|
||||
int packet_conservation;
|
||||
int probe_rtt_round_done;
|
||||
/* in_loss_recovery becomes nonzero when BBR enters loss recovery
|
||||
period. */
|
||||
int in_loss_recovery;
|
||||
} ngtcp2_bbr_cc;
|
||||
|
||||
int ngtcp2_cc_bbr_cc_init(ngtcp2_cc *cc, ngtcp2_log *log,
|
||||
ngtcp2_conn_stat *cstat, ngtcp2_rst *rst,
|
||||
ngtcp2_tstamp initial_ts, ngtcp2_rand rand,
|
||||
const ngtcp2_rand_ctx *rand_ctx,
|
||||
const ngtcp2_mem *mem);
|
||||
uint64_t prior_inflight_lo;
|
||||
uint64_t prior_inflight_hi;
|
||||
uint64_t prior_bw_lo;
|
||||
} ngtcp2_cc_bbr;
|
||||
|
||||
void ngtcp2_cc_bbr_cc_free(ngtcp2_cc *cc, const ngtcp2_mem *mem);
|
||||
|
||||
void ngtcp2_bbr_cc_init(ngtcp2_bbr_cc *bbr_cc, ngtcp2_conn_stat *cstat,
|
||||
ngtcp2_rst *rst, ngtcp2_tstamp initial_ts,
|
||||
ngtcp2_rand rand, const ngtcp2_rand_ctx *rand_ctx,
|
||||
ngtcp2_log *log);
|
||||
|
||||
void ngtcp2_bbr_cc_free(ngtcp2_bbr_cc *cc);
|
||||
|
||||
void ngtcp2_cc_bbr_cc_on_pkt_acked(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
|
||||
const ngtcp2_cc_pkt *pkt, ngtcp2_tstamp ts);
|
||||
|
||||
void ngtcp2_cc_bbr_cc_congestion_event(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
|
||||
ngtcp2_tstamp sent_ts, ngtcp2_tstamp ts);
|
||||
|
||||
void ngtcp2_cc_bbr_cc_on_spurious_congestion(ngtcp2_cc *ccx,
|
||||
ngtcp2_conn_stat *cstat,
|
||||
ngtcp2_tstamp ts);
|
||||
|
||||
void ngtcp2_cc_bbr_cc_on_persistent_congestion(ngtcp2_cc *cc,
|
||||
ngtcp2_conn_stat *cstat,
|
||||
ngtcp2_tstamp ts);
|
||||
|
||||
void ngtcp2_cc_bbr_cc_on_ack_recv(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
|
||||
const ngtcp2_cc_ack *ack, ngtcp2_tstamp ts);
|
||||
|
||||
void ngtcp2_cc_bbr_cc_on_pkt_sent(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
|
||||
const ngtcp2_cc_pkt *pkt);
|
||||
|
||||
void ngtcp2_cc_bbr_cc_new_rtt_sample(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
|
||||
ngtcp2_tstamp ts);
|
||||
|
||||
void ngtcp2_cc_bbr_cc_reset(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
|
||||
ngtcp2_tstamp ts);
|
||||
|
||||
void ngtcp2_cc_bbr_cc_event(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
|
||||
ngtcp2_cc_event_type event, ngtcp2_tstamp ts);
|
||||
void ngtcp2_cc_bbr_init(ngtcp2_cc_bbr *bbr, ngtcp2_log *log,
|
||||
ngtcp2_conn_stat *cstat, ngtcp2_rst *rst,
|
||||
ngtcp2_tstamp initial_ts, ngtcp2_rand rand,
|
||||
const ngtcp2_rand_ctx *rand_ctx);
|
||||
|
||||
#endif /* NGTCP2_BBR_H */
|
||||
Vendored
-1486
File diff suppressed because it is too large.
Load diff
Vendored
-149
@@ -1,149 +0,0 @@
|
||||
/*
|
||||
* ngtcp2
|
||||
*
|
||||
* Copyright (c) 2021 ngtcp2 contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef NGTCP2_BBR2_H
|
||||
#define NGTCP2_BBR2_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
||||
#include <ngtcp2/ngtcp2.h>
|
||||
|
||||
#include "ngtcp2_cc.h"
|
||||
#include "ngtcp2_window_filter.h"
|
||||
|
||||
typedef struct ngtcp2_rst ngtcp2_rst;
|
||||
|
||||
typedef enum ngtcp2_bbr2_state {
|
||||
NGTCP2_BBR2_STATE_STARTUP,
|
||||
NGTCP2_BBR2_STATE_DRAIN,
|
||||
NGTCP2_BBR2_STATE_PROBE_BW_DOWN,
|
||||
NGTCP2_BBR2_STATE_PROBE_BW_CRUISE,
|
||||
NGTCP2_BBR2_STATE_PROBE_BW_REFILL,
|
||||
NGTCP2_BBR2_STATE_PROBE_BW_UP,
|
||||
NGTCP2_BBR2_STATE_PROBE_RTT,
|
||||
} ngtcp2_bbr2_state;
|
||||
|
||||
typedef enum ngtcp2_bbr2_ack_phase {
|
||||
NGTCP2_BBR2_ACK_PHASE_ACKS_PROBE_STARTING,
|
||||
NGTCP2_BBR2_ACK_PHASE_ACKS_PROBE_STOPPING,
|
||||
NGTCP2_BBR2_ACK_PHASE_ACKS_PROBE_FEEDBACK,
|
||||
NGTCP2_BBR2_ACK_PHASE_ACKS_REFILLING,
|
||||
} ngtcp2_bbr2_ack_phase;
|
||||
|
||||
/*
|
||||
* ngtcp2_bbr2_cc is BBR v2 congestion controller, described in
|
||||
* https://datatracker.ietf.org/doc/html/draft-cardwell-iccrg-bbr-congestion-control-01
|
||||
*/
|
||||
typedef struct ngtcp2_bbr2_cc {
|
||||
ngtcp2_cc_base ccb;
|
||||
|
||||
uint64_t initial_cwnd;
|
||||
ngtcp2_rst *rst;
|
||||
ngtcp2_rand rand;
|
||||
ngtcp2_rand_ctx rand_ctx;
|
||||
|
||||
/* max_bw_filter for tracking the maximum recent delivery rate
|
||||
samples for estimating max_bw. */
|
||||
ngtcp2_window_filter max_bw_filter;
|
||||
|
||||
ngtcp2_window_filter extra_acked_filter;
|
||||
|
||||
ngtcp2_duration min_rtt;
|
||||
ngtcp2_tstamp min_rtt_stamp;
|
||||
ngtcp2_tstamp probe_rtt_done_stamp;
|
||||
int probe_rtt_round_done;
|
||||
uint64_t prior_cwnd;
|
||||
int idle_restart;
|
||||
ngtcp2_tstamp extra_acked_interval_start;
|
||||
uint64_t extra_acked_delivered;
|
||||
|
||||
/* Congestion signals */
|
||||
int loss_in_round;
|
||||
uint64_t bw_latest;
|
||||
uint64_t inflight_latest;
|
||||
|
||||
/* Lower bounds */
|
||||
uint64_t bw_lo;
|
||||
uint64_t inflight_lo;
|
||||
|
||||
/* Round counting */
|
||||
uint64_t next_round_delivered;
|
||||
int round_start;
|
||||
uint64_t round_count;
|
||||
|
||||
/* Full pipe */
|
||||
int filled_pipe;
|
||||
uint64_t full_bw;
|
||||
size_t full_bw_count;
|
||||
|
||||
/* Pacing rate */
|
||||
double pacing_gain;
|
||||
|
||||
ngtcp2_bbr2_state state;
|
||||
double cwnd_gain;
|
||||
|
||||
int loss_round_start;
|
||||
uint64_t loss_round_delivered;
|
||||
uint64_t rounds_since_bw_probe;
|
||||
uint64_t max_bw;
|
||||
uint64_t bw;
|
||||
uint64_t cycle_count;
|
||||
uint64_t extra_acked;
|
||||
uint64_t bytes_lost_in_round;
|
||||
size_t loss_events_in_round;
|
||||
uint64_t offload_budget;
|
||||
uint64_t probe_up_cnt;
|
||||
ngtcp2_tstamp cycle_stamp;
|
||||
ngtcp2_bbr2_ack_phase ack_phase;
|
||||
ngtcp2_duration bw_probe_wait;
|
||||
int bw_probe_samples;
|
||||
size_t bw_probe_up_rounds;
|
||||
uint64_t bw_probe_up_acks;
|
||||
uint64_t inflight_hi;
|
||||
uint64_t bw_hi;
|
||||
int probe_rtt_expired;
|
||||
ngtcp2_duration probe_rtt_min_delay;
|
||||
ngtcp2_tstamp probe_rtt_min_stamp;
|
||||
int in_loss_recovery;
|
||||
int packet_conservation;
|
||||
uint64_t max_inflight;
|
||||
ngtcp2_tstamp congestion_recovery_start_ts;
|
||||
uint64_t congestion_recovery_next_round_delivered;
|
||||
|
||||
uint64_t prior_inflight_lo;
|
||||
uint64_t prior_inflight_hi;
|
||||
uint64_t prior_bw_lo;
|
||||
} ngtcp2_bbr2_cc;
|
||||
|
||||
int ngtcp2_cc_bbr2_cc_init(ngtcp2_cc *cc, ngtcp2_log *log,
|
||||
ngtcp2_conn_stat *cstat, ngtcp2_rst *rst,
|
||||
ngtcp2_tstamp initial_ts, ngtcp2_rand rand,
|
||||
const ngtcp2_rand_ctx *rand_ctx,
|
||||
const ngtcp2_mem *mem);
|
||||
|
||||
void ngtcp2_cc_bbr2_cc_free(ngtcp2_cc *cc, const ngtcp2_mem *mem);
|
||||
|
||||
#endif /* NGTCP2_BBR2_H */
|
||||
Vendored
+251
-265
@@ -25,6 +25,7 @@
|
||||
#include "ngtcp2_cc.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
# include <intrin.h>
|
||||
@@ -34,6 +35,11 @@
|
||||
#include "ngtcp2_macro.h"
|
||||
#include "ngtcp2_mem.h"
|
||||
#include "ngtcp2_rcvry.h"
|
||||
#include "ngtcp2_conn_stat.h"
|
||||
|
||||
/* NGTCP2_CC_DELIVERY_RATE_SEC_FILTERLEN is the window length of
|
||||
delivery rate filter driven by ACK clocking. */
|
||||
#define NGTCP2_CC_DELIVERY_RATE_SEC_FILTERLEN 10
|
||||
|
||||
uint64_t ngtcp2_cc_compute_initcwnd(size_t max_udp_payload_size) {
|
||||
uint64_t n = 2 * max_udp_payload_size;
|
||||
@@ -56,45 +62,26 @@ ngtcp2_cc_pkt *ngtcp2_cc_pkt_init(ngtcp2_cc_pkt *pkt, int64_t pkt_num,
|
||||
return pkt;
|
||||
}
|
||||
|
||||
static void reno_cc_reset(ngtcp2_reno_cc *cc) {
|
||||
cc->max_delivery_rate_sec = 0;
|
||||
cc->target_cwnd = 0;
|
||||
cc->pending_add = 0;
|
||||
static void reno_cc_reset(ngtcp2_cc_reno *reno) {
|
||||
ngtcp2_window_filter_init(&reno->delivery_rate_sec_filter,
|
||||
NGTCP2_CC_DELIVERY_RATE_SEC_FILTERLEN);
|
||||
reno->ack_count = 0;
|
||||
reno->target_cwnd = 0;
|
||||
reno->pending_add = 0;
|
||||
}
|
||||
|
||||
void ngtcp2_reno_cc_init(ngtcp2_reno_cc *cc, ngtcp2_log *log) {
|
||||
cc->ccb.log = log;
|
||||
reno_cc_reset(cc);
|
||||
}
|
||||
void ngtcp2_cc_reno_init(ngtcp2_cc_reno *reno, ngtcp2_log *log) {
|
||||
memset(reno, 0, sizeof(*reno));
|
||||
|
||||
void ngtcp2_reno_cc_free(ngtcp2_reno_cc *cc) { (void)cc; }
|
||||
reno->cc.log = log;
|
||||
reno->cc.on_pkt_acked = ngtcp2_cc_reno_cc_on_pkt_acked;
|
||||
reno->cc.congestion_event = ngtcp2_cc_reno_cc_congestion_event;
|
||||
reno->cc.on_persistent_congestion =
|
||||
ngtcp2_cc_reno_cc_on_persistent_congestion;
|
||||
reno->cc.on_ack_recv = ngtcp2_cc_reno_cc_on_ack_recv;
|
||||
reno->cc.reset = ngtcp2_cc_reno_cc_reset;
|
||||
|
||||
int ngtcp2_cc_reno_cc_init(ngtcp2_cc *cc, ngtcp2_log *log,
|
||||
const ngtcp2_mem *mem) {
|
||||
ngtcp2_reno_cc *reno_cc;
|
||||
|
||||
reno_cc = ngtcp2_mem_calloc(mem, 1, sizeof(ngtcp2_reno_cc));
|
||||
if (reno_cc == NULL) {
|
||||
return NGTCP2_ERR_NOMEM;
|
||||
}
|
||||
|
||||
ngtcp2_reno_cc_init(reno_cc, log);
|
||||
|
||||
cc->ccb = &reno_cc->ccb;
|
||||
cc->on_pkt_acked = ngtcp2_cc_reno_cc_on_pkt_acked;
|
||||
cc->congestion_event = ngtcp2_cc_reno_cc_congestion_event;
|
||||
cc->on_persistent_congestion = ngtcp2_cc_reno_cc_on_persistent_congestion;
|
||||
cc->on_ack_recv = ngtcp2_cc_reno_cc_on_ack_recv;
|
||||
cc->reset = ngtcp2_cc_reno_cc_reset;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ngtcp2_cc_reno_cc_free(ngtcp2_cc *cc, const ngtcp2_mem *mem) {
|
||||
ngtcp2_reno_cc *reno_cc = ngtcp2_struct_of(cc->ccb, ngtcp2_reno_cc, ccb);
|
||||
|
||||
ngtcp2_reno_cc_free(reno_cc);
|
||||
ngtcp2_mem_free(mem, reno_cc);
|
||||
reno_cc_reset(reno);
|
||||
}
|
||||
|
||||
static int in_congestion_recovery(const ngtcp2_conn_stat *cstat,
|
||||
@@ -103,10 +90,10 @@ static int in_congestion_recovery(const ngtcp2_conn_stat *cstat,
|
||||
sent_time <= cstat->congestion_recovery_start_ts;
|
||||
}
|
||||
|
||||
void ngtcp2_cc_reno_cc_on_pkt_acked(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
|
||||
void ngtcp2_cc_reno_cc_on_pkt_acked(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
|
||||
const ngtcp2_cc_pkt *pkt,
|
||||
ngtcp2_tstamp ts) {
|
||||
ngtcp2_reno_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_reno_cc, ccb);
|
||||
ngtcp2_cc_reno *reno = ngtcp2_struct_of(cc, ngtcp2_cc_reno, cc);
|
||||
uint64_t m;
|
||||
(void)ts;
|
||||
|
||||
@@ -114,28 +101,28 @@ void ngtcp2_cc_reno_cc_on_pkt_acked(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
|
||||
return;
|
||||
}
|
||||
|
||||
if (cc->target_cwnd && cc->target_cwnd < cstat->cwnd) {
|
||||
if (reno->target_cwnd && reno->target_cwnd < cstat->cwnd) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (cstat->cwnd < cstat->ssthresh) {
|
||||
cstat->cwnd += pkt->pktlen;
|
||||
ngtcp2_log_info(cc->ccb.log, NGTCP2_LOG_EVENT_RCV,
|
||||
ngtcp2_log_info(reno->cc.log, NGTCP2_LOG_EVENT_CCA,
|
||||
"pkn=%" PRId64 " acked, slow start cwnd=%" PRIu64,
|
||||
pkt->pkt_num, cstat->cwnd);
|
||||
return;
|
||||
}
|
||||
|
||||
m = cstat->max_udp_payload_size * pkt->pktlen + cc->pending_add;
|
||||
cc->pending_add = m % cstat->cwnd;
|
||||
m = cstat->max_tx_udp_payload_size * pkt->pktlen + reno->pending_add;
|
||||
reno->pending_add = m % cstat->cwnd;
|
||||
|
||||
cstat->cwnd += m / cstat->cwnd;
|
||||
}
|
||||
|
||||
void ngtcp2_cc_reno_cc_congestion_event(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
|
||||
void ngtcp2_cc_reno_cc_congestion_event(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
|
||||
ngtcp2_tstamp sent_ts,
|
||||
ngtcp2_tstamp ts) {
|
||||
ngtcp2_reno_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_reno_cc, ccb);
|
||||
ngtcp2_cc_reno *reno = ngtcp2_struct_of(cc, ngtcp2_cc_reno, cc);
|
||||
uint64_t min_cwnd;
|
||||
|
||||
if (in_congestion_recovery(cstat, sent_ts)) {
|
||||
@@ -144,123 +131,109 @@ void ngtcp2_cc_reno_cc_congestion_event(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
|
||||
|
||||
cstat->congestion_recovery_start_ts = ts;
|
||||
cstat->cwnd >>= NGTCP2_LOSS_REDUCTION_FACTOR_BITS;
|
||||
min_cwnd = 2 * cstat->max_udp_payload_size;
|
||||
min_cwnd = 2 * cstat->max_tx_udp_payload_size;
|
||||
cstat->cwnd = ngtcp2_max(cstat->cwnd, min_cwnd);
|
||||
cstat->ssthresh = cstat->cwnd;
|
||||
|
||||
cc->pending_add = 0;
|
||||
reno->pending_add = 0;
|
||||
|
||||
ngtcp2_log_info(cc->ccb.log, NGTCP2_LOG_EVENT_RCV,
|
||||
ngtcp2_log_info(reno->cc.log, NGTCP2_LOG_EVENT_CCA,
|
||||
"reduce cwnd because of packet loss cwnd=%" PRIu64,
|
||||
cstat->cwnd);
|
||||
}
|
||||
|
||||
void ngtcp2_cc_reno_cc_on_persistent_congestion(ngtcp2_cc *ccx,
|
||||
void ngtcp2_cc_reno_cc_on_persistent_congestion(ngtcp2_cc *cc,
|
||||
ngtcp2_conn_stat *cstat,
|
||||
ngtcp2_tstamp ts) {
|
||||
(void)ccx;
|
||||
(void)cc;
|
||||
(void)ts;
|
||||
|
||||
cstat->cwnd = 2 * cstat->max_udp_payload_size;
|
||||
cstat->cwnd = 2 * cstat->max_tx_udp_payload_size;
|
||||
cstat->congestion_recovery_start_ts = UINT64_MAX;
|
||||
}
|
||||
|
||||
void ngtcp2_cc_reno_cc_on_ack_recv(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
|
||||
void ngtcp2_cc_reno_cc_on_ack_recv(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
|
||||
const ngtcp2_cc_ack *ack, ngtcp2_tstamp ts) {
|
||||
ngtcp2_reno_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_reno_cc, ccb);
|
||||
ngtcp2_cc_reno *reno = ngtcp2_struct_of(cc, ngtcp2_cc_reno, cc);
|
||||
uint64_t target_cwnd, initcwnd;
|
||||
uint64_t max_delivery_rate_sec;
|
||||
(void)ack;
|
||||
(void)ts;
|
||||
|
||||
/* TODO Use sliding window for min rtt measurement */
|
||||
/* TODO Use sliding window */
|
||||
cc->max_delivery_rate_sec =
|
||||
ngtcp2_max(cc->max_delivery_rate_sec, cstat->delivery_rate_sec);
|
||||
++reno->ack_count;
|
||||
|
||||
if (cstat->min_rtt != UINT64_MAX && cc->max_delivery_rate_sec) {
|
||||
target_cwnd = cc->max_delivery_rate_sec * cstat->min_rtt / NGTCP2_SECONDS;
|
||||
initcwnd = ngtcp2_cc_compute_initcwnd(cstat->max_udp_payload_size);
|
||||
cc->target_cwnd = ngtcp2_max(initcwnd, target_cwnd) * 289 / 100;
|
||||
ngtcp2_window_filter_update(&reno->delivery_rate_sec_filter,
|
||||
cstat->delivery_rate_sec, reno->ack_count);
|
||||
|
||||
ngtcp2_log_info(cc->ccb.log, NGTCP2_LOG_EVENT_RCV,
|
||||
max_delivery_rate_sec =
|
||||
ngtcp2_window_filter_get_best(&reno->delivery_rate_sec_filter);
|
||||
|
||||
if (cstat->min_rtt != UINT64_MAX && max_delivery_rate_sec) {
|
||||
target_cwnd = max_delivery_rate_sec * cstat->smoothed_rtt / NGTCP2_SECONDS;
|
||||
initcwnd = ngtcp2_cc_compute_initcwnd(cstat->max_tx_udp_payload_size);
|
||||
reno->target_cwnd = ngtcp2_max(initcwnd, target_cwnd) * 289 / 100;
|
||||
|
||||
ngtcp2_log_info(reno->cc.log, NGTCP2_LOG_EVENT_CCA,
|
||||
"target_cwnd=%" PRIu64 " max_delivery_rate_sec=%" PRIu64
|
||||
" min_rtt=%" PRIu64,
|
||||
cc->target_cwnd, cc->max_delivery_rate_sec, cstat->min_rtt);
|
||||
" smoothed_rtt=%" PRIu64,
|
||||
reno->target_cwnd, max_delivery_rate_sec,
|
||||
cstat->smoothed_rtt);
|
||||
}
|
||||
}
|
||||
|
||||
void ngtcp2_cc_reno_cc_reset(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
|
||||
void ngtcp2_cc_reno_cc_reset(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
|
||||
ngtcp2_tstamp ts) {
|
||||
ngtcp2_reno_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_reno_cc, ccb);
|
||||
ngtcp2_cc_reno *reno = ngtcp2_struct_of(cc, ngtcp2_cc_reno, cc);
|
||||
(void)cstat;
|
||||
(void)ts;
|
||||
|
||||
reno_cc_reset(cc);
|
||||
reno_cc_reset(reno);
|
||||
}
|
||||
|
||||
static void cubic_cc_reset(ngtcp2_cubic_cc *cc) {
|
||||
cc->max_delivery_rate_sec = 0;
|
||||
cc->target_cwnd = 0;
|
||||
cc->w_last_max = 0;
|
||||
cc->w_tcp = 0;
|
||||
cc->origin_point = 0;
|
||||
cc->epoch_start = UINT64_MAX;
|
||||
cc->k = 0;
|
||||
static void cubic_cc_reset(ngtcp2_cc_cubic *cubic) {
|
||||
ngtcp2_window_filter_init(&cubic->delivery_rate_sec_filter,
|
||||
NGTCP2_CC_DELIVERY_RATE_SEC_FILTERLEN);
|
||||
cubic->ack_count = 0;
|
||||
cubic->target_cwnd = 0;
|
||||
cubic->w_last_max = 0;
|
||||
cubic->w_tcp = 0;
|
||||
cubic->origin_point = 0;
|
||||
cubic->epoch_start = UINT64_MAX;
|
||||
cubic->k = 0;
|
||||
|
||||
cc->prior.cwnd = 0;
|
||||
cc->prior.ssthresh = 0;
|
||||
cc->prior.w_last_max = 0;
|
||||
cc->prior.w_tcp = 0;
|
||||
cc->prior.origin_point = 0;
|
||||
cc->prior.epoch_start = UINT64_MAX;
|
||||
cc->prior.k = 0;
|
||||
cubic->prior.cwnd = 0;
|
||||
cubic->prior.ssthresh = 0;
|
||||
cubic->prior.w_last_max = 0;
|
||||
cubic->prior.w_tcp = 0;
|
||||
cubic->prior.origin_point = 0;
|
||||
cubic->prior.epoch_start = UINT64_MAX;
|
||||
cubic->prior.k = 0;
|
||||
|
||||
cc->rtt_sample_count = 0;
|
||||
cc->current_round_min_rtt = UINT64_MAX;
|
||||
cc->last_round_min_rtt = UINT64_MAX;
|
||||
cc->window_end = -1;
|
||||
cubic->rtt_sample_count = 0;
|
||||
cubic->current_round_min_rtt = UINT64_MAX;
|
||||
cubic->last_round_min_rtt = UINT64_MAX;
|
||||
cubic->window_end = -1;
|
||||
}
|
||||
|
||||
void ngtcp2_cubic_cc_init(ngtcp2_cubic_cc *cc, ngtcp2_log *log) {
|
||||
cc->ccb.log = log;
|
||||
cubic_cc_reset(cc);
|
||||
void ngtcp2_cc_cubic_init(ngtcp2_cc_cubic *cubic, ngtcp2_log *log) {
|
||||
memset(cubic, 0, sizeof(*cubic));
|
||||
|
||||
cubic->cc.log = log;
|
||||
cubic->cc.on_pkt_acked = ngtcp2_cc_cubic_cc_on_pkt_acked;
|
||||
cubic->cc.congestion_event = ngtcp2_cc_cubic_cc_congestion_event;
|
||||
cubic->cc.on_spurious_congestion = ngtcp2_cc_cubic_cc_on_spurious_congestion;
|
||||
cubic->cc.on_persistent_congestion =
|
||||
ngtcp2_cc_cubic_cc_on_persistent_congestion;
|
||||
cubic->cc.on_ack_recv = ngtcp2_cc_cubic_cc_on_ack_recv;
|
||||
cubic->cc.on_pkt_sent = ngtcp2_cc_cubic_cc_on_pkt_sent;
|
||||
cubic->cc.new_rtt_sample = ngtcp2_cc_cubic_cc_new_rtt_sample;
|
||||
cubic->cc.reset = ngtcp2_cc_cubic_cc_reset;
|
||||
cubic->cc.event = ngtcp2_cc_cubic_cc_event;
|
||||
|
||||
cubic_cc_reset(cubic);
|
||||
}
|
||||
|
||||
void ngtcp2_cubic_cc_free(ngtcp2_cubic_cc *cc) { (void)cc; }
|
||||
|
||||
int ngtcp2_cc_cubic_cc_init(ngtcp2_cc *cc, ngtcp2_log *log,
|
||||
const ngtcp2_mem *mem) {
|
||||
ngtcp2_cubic_cc *cubic_cc;
|
||||
|
||||
cubic_cc = ngtcp2_mem_calloc(mem, 1, sizeof(ngtcp2_cubic_cc));
|
||||
if (cubic_cc == NULL) {
|
||||
return NGTCP2_ERR_NOMEM;
|
||||
}
|
||||
|
||||
ngtcp2_cubic_cc_init(cubic_cc, log);
|
||||
|
||||
cc->ccb = &cubic_cc->ccb;
|
||||
cc->on_pkt_acked = ngtcp2_cc_cubic_cc_on_pkt_acked;
|
||||
cc->congestion_event = ngtcp2_cc_cubic_cc_congestion_event;
|
||||
cc->on_spurious_congestion = ngtcp2_cc_cubic_cc_on_spurious_congestion;
|
||||
cc->on_persistent_congestion = ngtcp2_cc_cubic_cc_on_persistent_congestion;
|
||||
cc->on_ack_recv = ngtcp2_cc_cubic_cc_on_ack_recv;
|
||||
cc->on_pkt_sent = ngtcp2_cc_cubic_cc_on_pkt_sent;
|
||||
cc->new_rtt_sample = ngtcp2_cc_cubic_cc_new_rtt_sample;
|
||||
cc->reset = ngtcp2_cc_cubic_cc_reset;
|
||||
cc->event = ngtcp2_cc_cubic_cc_event;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ngtcp2_cc_cubic_cc_free(ngtcp2_cc *cc, const ngtcp2_mem *mem) {
|
||||
ngtcp2_cubic_cc *cubic_cc = ngtcp2_struct_of(cc->ccb, ngtcp2_cubic_cc, ccb);
|
||||
|
||||
ngtcp2_cubic_cc_free(cubic_cc);
|
||||
ngtcp2_mem_free(mem, cubic_cc);
|
||||
}
|
||||
|
||||
static uint64_t ngtcp2_cbrt(uint64_t n) {
|
||||
uint64_t ngtcp2_cbrt(uint64_t n) {
|
||||
int d;
|
||||
uint64_t a;
|
||||
|
||||
@@ -269,26 +242,23 @@ static uint64_t ngtcp2_cbrt(uint64_t n) {
|
||||
}
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
# if defined(_M_X64)
|
||||
d = (int)__lzcnt64(n);
|
||||
# elif defined(_M_ARM64)
|
||||
{
|
||||
unsigned long index;
|
||||
d = sizeof(uint64_t) * CHAR_BIT;
|
||||
# if defined(_WIN64)
|
||||
if (_BitScanReverse64(&index, n)) {
|
||||
d = d - 1 - index;
|
||||
d = 61 - index;
|
||||
}
|
||||
# else /* !defined(_WIN64) */
|
||||
if (_BitScanReverse(&index, (unsigned int)(n >> 32))) {
|
||||
d = 31 - index;
|
||||
} else {
|
||||
d = 32 + 31 - _BitScanReverse(&index, (unsigned int)n);
|
||||
}
|
||||
# endif /* !defined(_WIN64) */
|
||||
}
|
||||
# else
|
||||
if ((n >> 32) != 0) {
|
||||
d = __lzcnt((unsigned int)(n >> 32));
|
||||
} else {
|
||||
d = 32 + __lzcnt((unsigned int)n);
|
||||
}
|
||||
# endif
|
||||
#else
|
||||
#else /* !defined(_MSC_VER) */
|
||||
d = __builtin_clzll(n);
|
||||
#endif
|
||||
#endif /* !defined(_MSC_VER) */
|
||||
a = 1ULL << ((64 - d) / 3 + 1);
|
||||
|
||||
for (; a * a * a > n;) {
|
||||
@@ -303,42 +273,41 @@ static uint64_t ngtcp2_cbrt(uint64_t n) {
|
||||
#define NGTCP2_HS_MIN_ETA (4 * NGTCP2_MILLISECONDS)
|
||||
#define NGTCP2_HS_MAX_ETA (16 * NGTCP2_MILLISECONDS)
|
||||
|
||||
void ngtcp2_cc_cubic_cc_on_pkt_acked(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
|
||||
void ngtcp2_cc_cubic_cc_on_pkt_acked(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
|
||||
const ngtcp2_cc_pkt *pkt,
|
||||
ngtcp2_tstamp ts) {
|
||||
ngtcp2_cubic_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_cubic_cc, ccb);
|
||||
ngtcp2_duration t, min_rtt, eta;
|
||||
uint64_t target;
|
||||
ngtcp2_cc_cubic *cubic = ngtcp2_struct_of(cc, ngtcp2_cc_cubic, cc);
|
||||
ngtcp2_duration t, eta;
|
||||
uint64_t target, cwnd_thres;
|
||||
uint64_t tx, kx, time_delta, delta;
|
||||
uint64_t add, tcp_add;
|
||||
uint64_t m;
|
||||
|
||||
if (pkt->pktns_id == NGTCP2_PKTNS_ID_APPLICATION && cc->window_end != -1 &&
|
||||
cc->window_end <= pkt->pkt_num) {
|
||||
cc->window_end = -1;
|
||||
if (pkt->pktns_id == NGTCP2_PKTNS_ID_APPLICATION && cubic->window_end != -1 &&
|
||||
cubic->window_end <= pkt->pkt_num) {
|
||||
cubic->window_end = -1;
|
||||
}
|
||||
|
||||
if (in_congestion_recovery(cstat, pkt->sent_ts)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (cc->target_cwnd && cc->target_cwnd < cstat->cwnd) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (cstat->cwnd < cstat->ssthresh) {
|
||||
/* slow-start */
|
||||
cstat->cwnd += pkt->pktlen;
|
||||
if (cubic->target_cwnd == 0 || cubic->target_cwnd > cstat->cwnd) {
|
||||
cstat->cwnd += pkt->pktlen;
|
||||
}
|
||||
|
||||
ngtcp2_log_info(cc->ccb.log, NGTCP2_LOG_EVENT_RCV,
|
||||
ngtcp2_log_info(cubic->cc.log, NGTCP2_LOG_EVENT_CCA,
|
||||
"pkn=%" PRId64 " acked, slow start cwnd=%" PRIu64,
|
||||
pkt->pkt_num, cstat->cwnd);
|
||||
|
||||
if (cc->last_round_min_rtt != UINT64_MAX &&
|
||||
cc->current_round_min_rtt != UINT64_MAX &&
|
||||
cstat->cwnd >= NGTCP2_HS_MIN_SSTHRESH * cstat->max_udp_payload_size &&
|
||||
cc->rtt_sample_count >= NGTCP2_HS_N_RTT_SAMPLE) {
|
||||
eta = cc->last_round_min_rtt / 8;
|
||||
if (cubic->last_round_min_rtt != UINT64_MAX &&
|
||||
cubic->current_round_min_rtt != UINT64_MAX &&
|
||||
cstat->cwnd >=
|
||||
NGTCP2_HS_MIN_SSTHRESH * cstat->max_tx_udp_payload_size &&
|
||||
cubic->rtt_sample_count >= NGTCP2_HS_N_RTT_SAMPLE) {
|
||||
eta = cubic->last_round_min_rtt / 8;
|
||||
|
||||
if (eta < NGTCP2_HS_MIN_ETA) {
|
||||
eta = NGTCP2_HS_MIN_ETA;
|
||||
@@ -346,11 +315,11 @@ void ngtcp2_cc_cubic_cc_on_pkt_acked(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
|
||||
eta = NGTCP2_HS_MAX_ETA;
|
||||
}
|
||||
|
||||
if (cc->current_round_min_rtt >= cc->last_round_min_rtt + eta) {
|
||||
ngtcp2_log_info(cc->ccb.log, NGTCP2_LOG_EVENT_RCV,
|
||||
if (cubic->current_round_min_rtt >= cubic->last_round_min_rtt + eta) {
|
||||
ngtcp2_log_info(cubic->cc.log, NGTCP2_LOG_EVENT_CCA,
|
||||
"HyStart++ exit slow start");
|
||||
|
||||
cc->w_last_max = cstat->cwnd;
|
||||
cubic->w_last_max = cstat->cwnd;
|
||||
cstat->ssthresh = cstat->cwnd;
|
||||
}
|
||||
}
|
||||
@@ -360,34 +329,32 @@ void ngtcp2_cc_cubic_cc_on_pkt_acked(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
|
||||
|
||||
/* congestion avoidance */
|
||||
|
||||
if (cc->epoch_start == UINT64_MAX) {
|
||||
cc->epoch_start = ts;
|
||||
if (cstat->cwnd < cc->w_last_max) {
|
||||
cc->k = ngtcp2_cbrt((cc->w_last_max - cstat->cwnd) * 10 / 4 /
|
||||
cstat->max_udp_payload_size);
|
||||
cc->origin_point = cc->w_last_max;
|
||||
if (cubic->epoch_start == UINT64_MAX) {
|
||||
cubic->epoch_start = ts;
|
||||
if (cstat->cwnd < cubic->w_last_max) {
|
||||
cubic->k = ngtcp2_cbrt((cubic->w_last_max - cstat->cwnd) * 10 / 4 /
|
||||
cstat->max_tx_udp_payload_size);
|
||||
cubic->origin_point = cubic->w_last_max;
|
||||
} else {
|
||||
cc->k = 0;
|
||||
cc->origin_point = cstat->cwnd;
|
||||
cubic->k = 0;
|
||||
cubic->origin_point = cstat->cwnd;
|
||||
}
|
||||
|
||||
cc->w_tcp = cstat->cwnd;
|
||||
cubic->w_tcp = cstat->cwnd;
|
||||
|
||||
ngtcp2_log_info(cc->ccb.log, NGTCP2_LOG_EVENT_RCV,
|
||||
ngtcp2_log_info(cubic->cc.log, NGTCP2_LOG_EVENT_CCA,
|
||||
"cubic-ca epoch_start=%" PRIu64 " k=%" PRIu64
|
||||
" origin_point=%" PRIu64,
|
||||
cc->epoch_start, cc->k, cc->origin_point);
|
||||
cubic->epoch_start, cubic->k, cubic->origin_point);
|
||||
|
||||
cc->pending_add = 0;
|
||||
cc->pending_w_add = 0;
|
||||
cubic->pending_add = 0;
|
||||
cubic->pending_w_add = 0;
|
||||
}
|
||||
|
||||
min_rtt = cstat->min_rtt == UINT64_MAX ? cstat->initial_rtt : cstat->min_rtt;
|
||||
t = ts - cubic->epoch_start;
|
||||
|
||||
t = ts + min_rtt - cc->epoch_start;
|
||||
|
||||
tx = (t << 4) / NGTCP2_SECONDS;
|
||||
kx = (cc->k << 4);
|
||||
tx = (t << 10) / NGTCP2_SECONDS;
|
||||
kx = (cubic->k << 10);
|
||||
|
||||
if (tx > kx) {
|
||||
time_delta = tx - kx;
|
||||
@@ -395,210 +362,229 @@ void ngtcp2_cc_cubic_cc_on_pkt_acked(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
|
||||
time_delta = kx - tx;
|
||||
}
|
||||
|
||||
delta = cstat->max_udp_payload_size *
|
||||
((((time_delta * time_delta) >> 4) * time_delta) >> 8) * 4 / 10;
|
||||
delta = cstat->max_tx_udp_payload_size *
|
||||
((((time_delta * time_delta) >> 10) * time_delta) >> 10) * 4 / 10;
|
||||
delta >>= 10;
|
||||
|
||||
if (tx > kx) {
|
||||
target = cc->origin_point + delta;
|
||||
target = cubic->origin_point + delta;
|
||||
} else {
|
||||
target = cc->origin_point - delta;
|
||||
target = cubic->origin_point - delta;
|
||||
}
|
||||
|
||||
cwnd_thres =
|
||||
(target * (((t + cstat->smoothed_rtt) << 10) / NGTCP2_SECONDS)) >> 10;
|
||||
if (cwnd_thres < cstat->cwnd) {
|
||||
target = cstat->cwnd;
|
||||
} else if (2 * cwnd_thres > 3 * cstat->cwnd) {
|
||||
target = cstat->cwnd * 3 / 2;
|
||||
} else {
|
||||
target = cwnd_thres;
|
||||
}
|
||||
|
||||
if (target > cstat->cwnd) {
|
||||
m = cc->pending_add + cstat->max_udp_payload_size * (target - cstat->cwnd);
|
||||
m = cubic->pending_add +
|
||||
cstat->max_tx_udp_payload_size * (target - cstat->cwnd);
|
||||
add = m / cstat->cwnd;
|
||||
cc->pending_add = m % cstat->cwnd;
|
||||
cubic->pending_add = m % cstat->cwnd;
|
||||
} else {
|
||||
m = cc->pending_add + cstat->max_udp_payload_size;
|
||||
m = cubic->pending_add + cstat->max_tx_udp_payload_size;
|
||||
add = m / (100 * cstat->cwnd);
|
||||
cc->pending_add = m % (100 * cstat->cwnd);
|
||||
cubic->pending_add = m % (100 * cstat->cwnd);
|
||||
}
|
||||
|
||||
m = cc->pending_w_add + cstat->max_udp_payload_size * pkt->pktlen;
|
||||
m = cubic->pending_w_add + cstat->max_tx_udp_payload_size * pkt->pktlen;
|
||||
|
||||
cc->w_tcp += m / cstat->cwnd;
|
||||
cc->pending_w_add = m % cstat->cwnd;
|
||||
cubic->w_tcp += m / cstat->cwnd;
|
||||
cubic->pending_w_add = m % cstat->cwnd;
|
||||
|
||||
if (cc->w_tcp > cstat->cwnd) {
|
||||
tcp_add =
|
||||
cstat->max_udp_payload_size * (cc->w_tcp - cstat->cwnd) / cstat->cwnd;
|
||||
if (cubic->w_tcp > cstat->cwnd) {
|
||||
tcp_add = cstat->max_tx_udp_payload_size * (cubic->w_tcp - cstat->cwnd) /
|
||||
cstat->cwnd;
|
||||
if (tcp_add > add) {
|
||||
add = tcp_add;
|
||||
}
|
||||
}
|
||||
|
||||
cstat->cwnd += add;
|
||||
if (cubic->target_cwnd == 0 || cubic->target_cwnd > cstat->cwnd) {
|
||||
cstat->cwnd += add;
|
||||
}
|
||||
|
||||
ngtcp2_log_info(cc->ccb.log, NGTCP2_LOG_EVENT_RCV,
|
||||
ngtcp2_log_info(cubic->cc.log, NGTCP2_LOG_EVENT_CCA,
|
||||
"pkn=%" PRId64 " acked, cubic-ca cwnd=%" PRIu64 " t=%" PRIu64
|
||||
" k=%" PRIi64 " time_delta=%" PRIu64 " delta=%" PRIu64
|
||||
" target=%" PRIu64 " w_tcp=%" PRIu64,
|
||||
pkt->pkt_num, cstat->cwnd, t, cc->k, time_delta >> 4, delta,
|
||||
target, cc->w_tcp);
|
||||
pkt->pkt_num, cstat->cwnd, t, cubic->k, time_delta >> 4,
|
||||
delta, target, cubic->w_tcp);
|
||||
}
|
||||
|
||||
void ngtcp2_cc_cubic_cc_congestion_event(ngtcp2_cc *ccx,
|
||||
ngtcp2_conn_stat *cstat,
|
||||
void ngtcp2_cc_cubic_cc_congestion_event(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
|
||||
ngtcp2_tstamp sent_ts,
|
||||
ngtcp2_tstamp ts) {
|
||||
ngtcp2_cubic_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_cubic_cc, ccb);
|
||||
ngtcp2_cc_cubic *cubic = ngtcp2_struct_of(cc, ngtcp2_cc_cubic, cc);
|
||||
uint64_t min_cwnd;
|
||||
|
||||
if (in_congestion_recovery(cstat, sent_ts)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (cc->prior.cwnd < cstat->cwnd) {
|
||||
cc->prior.cwnd = cstat->cwnd;
|
||||
cc->prior.ssthresh = cstat->ssthresh;
|
||||
cc->prior.w_last_max = cc->w_last_max;
|
||||
cc->prior.w_tcp = cc->w_tcp;
|
||||
cc->prior.origin_point = cc->origin_point;
|
||||
cc->prior.epoch_start = cc->epoch_start;
|
||||
cc->prior.k = cc->k;
|
||||
if (cubic->prior.cwnd < cstat->cwnd) {
|
||||
cubic->prior.cwnd = cstat->cwnd;
|
||||
cubic->prior.ssthresh = cstat->ssthresh;
|
||||
cubic->prior.w_last_max = cubic->w_last_max;
|
||||
cubic->prior.w_tcp = cubic->w_tcp;
|
||||
cubic->prior.origin_point = cubic->origin_point;
|
||||
cubic->prior.epoch_start = cubic->epoch_start;
|
||||
cubic->prior.k = cubic->k;
|
||||
}
|
||||
|
||||
cstat->congestion_recovery_start_ts = ts;
|
||||
|
||||
cc->epoch_start = UINT64_MAX;
|
||||
if (cstat->cwnd < cc->w_last_max) {
|
||||
cc->w_last_max = cstat->cwnd * 17 / 10 / 2;
|
||||
cubic->epoch_start = UINT64_MAX;
|
||||
if (cstat->cwnd < cubic->w_last_max) {
|
||||
cubic->w_last_max = cstat->cwnd * 17 / 10 / 2;
|
||||
} else {
|
||||
cc->w_last_max = cstat->cwnd;
|
||||
cubic->w_last_max = cstat->cwnd;
|
||||
}
|
||||
|
||||
min_cwnd = 2 * cstat->max_udp_payload_size;
|
||||
min_cwnd = 2 * cstat->max_tx_udp_payload_size;
|
||||
cstat->ssthresh = cstat->cwnd * 7 / 10;
|
||||
cstat->ssthresh = ngtcp2_max(cstat->ssthresh, min_cwnd);
|
||||
cstat->cwnd = cstat->ssthresh;
|
||||
|
||||
ngtcp2_log_info(cc->ccb.log, NGTCP2_LOG_EVENT_RCV,
|
||||
ngtcp2_log_info(cubic->cc.log, NGTCP2_LOG_EVENT_CCA,
|
||||
"reduce cwnd because of packet loss cwnd=%" PRIu64,
|
||||
cstat->cwnd);
|
||||
}
|
||||
|
||||
void ngtcp2_cc_cubic_cc_on_spurious_congestion(ngtcp2_cc *ccx,
|
||||
void ngtcp2_cc_cubic_cc_on_spurious_congestion(ngtcp2_cc *cc,
|
||||
ngtcp2_conn_stat *cstat,
|
||||
ngtcp2_tstamp ts) {
|
||||
ngtcp2_cubic_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_cubic_cc, ccb);
|
||||
ngtcp2_cc_cubic *cubic = ngtcp2_struct_of(cc, ngtcp2_cc_cubic, cc);
|
||||
(void)ts;
|
||||
|
||||
if (cstat->cwnd >= cc->prior.cwnd) {
|
||||
if (cstat->cwnd >= cubic->prior.cwnd) {
|
||||
return;
|
||||
}
|
||||
|
||||
cstat->congestion_recovery_start_ts = UINT64_MAX;
|
||||
|
||||
cstat->cwnd = cc->prior.cwnd;
|
||||
cstat->ssthresh = cc->prior.ssthresh;
|
||||
cc->w_last_max = cc->prior.w_last_max;
|
||||
cc->w_tcp = cc->prior.w_tcp;
|
||||
cc->origin_point = cc->prior.origin_point;
|
||||
cc->epoch_start = cc->prior.epoch_start;
|
||||
cc->k = cc->prior.k;
|
||||
cstat->cwnd = cubic->prior.cwnd;
|
||||
cstat->ssthresh = cubic->prior.ssthresh;
|
||||
cubic->w_last_max = cubic->prior.w_last_max;
|
||||
cubic->w_tcp = cubic->prior.w_tcp;
|
||||
cubic->origin_point = cubic->prior.origin_point;
|
||||
cubic->epoch_start = cubic->prior.epoch_start;
|
||||
cubic->k = cubic->prior.k;
|
||||
|
||||
cc->prior.cwnd = 0;
|
||||
cc->prior.ssthresh = 0;
|
||||
cc->prior.w_last_max = 0;
|
||||
cc->prior.w_tcp = 0;
|
||||
cc->prior.origin_point = 0;
|
||||
cc->prior.epoch_start = UINT64_MAX;
|
||||
cc->prior.k = 0;
|
||||
cubic->prior.cwnd = 0;
|
||||
cubic->prior.ssthresh = 0;
|
||||
cubic->prior.w_last_max = 0;
|
||||
cubic->prior.w_tcp = 0;
|
||||
cubic->prior.origin_point = 0;
|
||||
cubic->prior.epoch_start = UINT64_MAX;
|
||||
cubic->prior.k = 0;
|
||||
|
||||
ngtcp2_log_info(cc->ccb.log, NGTCP2_LOG_EVENT_RCV,
|
||||
ngtcp2_log_info(cubic->cc.log, NGTCP2_LOG_EVENT_CCA,
|
||||
"spurious congestion is detected and congestion state is "
|
||||
"restored cwnd=%" PRIu64,
|
||||
cstat->cwnd);
|
||||
}
|
||||
|
||||
void ngtcp2_cc_cubic_cc_on_persistent_congestion(ngtcp2_cc *ccx,
|
||||
void ngtcp2_cc_cubic_cc_on_persistent_congestion(ngtcp2_cc *cc,
|
||||
ngtcp2_conn_stat *cstat,
|
||||
ngtcp2_tstamp ts) {
|
||||
(void)ccx;
|
||||
(void)cc;
|
||||
(void)ts;
|
||||
|
||||
cstat->cwnd = 2 * cstat->max_udp_payload_size;
|
||||
cstat->cwnd = 2 * cstat->max_tx_udp_payload_size;
|
||||
cstat->congestion_recovery_start_ts = UINT64_MAX;
|
||||
}
|
||||
|
||||
void ngtcp2_cc_cubic_cc_on_ack_recv(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
|
||||
void ngtcp2_cc_cubic_cc_on_ack_recv(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
|
||||
const ngtcp2_cc_ack *ack,
|
||||
ngtcp2_tstamp ts) {
|
||||
ngtcp2_cubic_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_cubic_cc, ccb);
|
||||
ngtcp2_cc_cubic *cubic = ngtcp2_struct_of(cc, ngtcp2_cc_cubic, cc);
|
||||
uint64_t target_cwnd, initcwnd;
|
||||
uint64_t max_delivery_rate_sec;
|
||||
(void)ack;
|
||||
(void)ts;
|
||||
|
||||
/* TODO Use sliding window for min rtt measurement */
|
||||
/* TODO Use sliding window */
|
||||
cc->max_delivery_rate_sec =
|
||||
ngtcp2_max(cc->max_delivery_rate_sec, cstat->delivery_rate_sec);
|
||||
++cubic->ack_count;
|
||||
|
||||
if (cstat->min_rtt != UINT64_MAX && cc->max_delivery_rate_sec) {
|
||||
target_cwnd = cc->max_delivery_rate_sec * cstat->min_rtt / NGTCP2_SECONDS;
|
||||
initcwnd = ngtcp2_cc_compute_initcwnd(cstat->max_udp_payload_size);
|
||||
cc->target_cwnd = ngtcp2_max(initcwnd, target_cwnd) * 289 / 100;
|
||||
ngtcp2_window_filter_update(&cubic->delivery_rate_sec_filter,
|
||||
cstat->delivery_rate_sec, cubic->ack_count);
|
||||
|
||||
ngtcp2_log_info(cc->ccb.log, NGTCP2_LOG_EVENT_RCV,
|
||||
max_delivery_rate_sec =
|
||||
ngtcp2_window_filter_get_best(&cubic->delivery_rate_sec_filter);
|
||||
|
||||
if (cstat->min_rtt != UINT64_MAX && max_delivery_rate_sec) {
|
||||
target_cwnd = max_delivery_rate_sec * cstat->smoothed_rtt / NGTCP2_SECONDS;
|
||||
initcwnd = ngtcp2_cc_compute_initcwnd(cstat->max_tx_udp_payload_size);
|
||||
cubic->target_cwnd = ngtcp2_max(initcwnd, target_cwnd) * 289 / 100;
|
||||
|
||||
ngtcp2_log_info(cubic->cc.log, NGTCP2_LOG_EVENT_CCA,
|
||||
"target_cwnd=%" PRIu64 " max_delivery_rate_sec=%" PRIu64
|
||||
" min_rtt=%" PRIu64,
|
||||
cc->target_cwnd, cc->max_delivery_rate_sec, cstat->min_rtt);
|
||||
" smoothed_rtt=%" PRIu64,
|
||||
cubic->target_cwnd, max_delivery_rate_sec,
|
||||
cstat->smoothed_rtt);
|
||||
}
|
||||
}
|
||||
|
||||
void ngtcp2_cc_cubic_cc_on_pkt_sent(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
|
||||
void ngtcp2_cc_cubic_cc_on_pkt_sent(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
|
||||
const ngtcp2_cc_pkt *pkt) {
|
||||
ngtcp2_cubic_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_cubic_cc, ccb);
|
||||
ngtcp2_cc_cubic *cubic = ngtcp2_struct_of(cc, ngtcp2_cc_cubic, cc);
|
||||
(void)cstat;
|
||||
|
||||
if (pkt->pktns_id != NGTCP2_PKTNS_ID_APPLICATION || cc->window_end != -1) {
|
||||
if (pkt->pktns_id != NGTCP2_PKTNS_ID_APPLICATION || cubic->window_end != -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
cc->window_end = pkt->pkt_num;
|
||||
cc->last_round_min_rtt = cc->current_round_min_rtt;
|
||||
cc->current_round_min_rtt = UINT64_MAX;
|
||||
cc->rtt_sample_count = 0;
|
||||
cubic->window_end = pkt->pkt_num;
|
||||
cubic->last_round_min_rtt = cubic->current_round_min_rtt;
|
||||
cubic->current_round_min_rtt = UINT64_MAX;
|
||||
cubic->rtt_sample_count = 0;
|
||||
}
|
||||
|
||||
void ngtcp2_cc_cubic_cc_new_rtt_sample(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
|
||||
void ngtcp2_cc_cubic_cc_new_rtt_sample(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
|
||||
ngtcp2_tstamp ts) {
|
||||
ngtcp2_cubic_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_cubic_cc, ccb);
|
||||
ngtcp2_cc_cubic *cubic = ngtcp2_struct_of(cc, ngtcp2_cc_cubic, cc);
|
||||
(void)ts;
|
||||
|
||||
if (cc->window_end == -1) {
|
||||
if (cubic->window_end == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
cc->current_round_min_rtt =
|
||||
ngtcp2_min(cc->current_round_min_rtt, cstat->latest_rtt);
|
||||
++cc->rtt_sample_count;
|
||||
cubic->current_round_min_rtt =
|
||||
ngtcp2_min(cubic->current_round_min_rtt, cstat->latest_rtt);
|
||||
++cubic->rtt_sample_count;
|
||||
}
|
||||
|
||||
void ngtcp2_cc_cubic_cc_reset(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
|
||||
void ngtcp2_cc_cubic_cc_reset(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
|
||||
ngtcp2_tstamp ts) {
|
||||
ngtcp2_cubic_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_cubic_cc, ccb);
|
||||
ngtcp2_cc_cubic *cubic = ngtcp2_struct_of(cc, ngtcp2_cc_cubic, cc);
|
||||
(void)cstat;
|
||||
(void)ts;
|
||||
|
||||
cubic_cc_reset(cc);
|
||||
cubic_cc_reset(cubic);
|
||||
}
|
||||
|
||||
void ngtcp2_cc_cubic_cc_event(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
|
||||
void ngtcp2_cc_cubic_cc_event(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
|
||||
ngtcp2_cc_event_type event, ngtcp2_tstamp ts) {
|
||||
ngtcp2_cubic_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_cubic_cc, ccb);
|
||||
ngtcp2_cc_cubic *cubic = ngtcp2_struct_of(cc, ngtcp2_cc_cubic, cc);
|
||||
ngtcp2_tstamp last_ts;
|
||||
|
||||
if (event != NGTCP2_CC_EVENT_TYPE_TX_START || cc->epoch_start == UINT64_MAX) {
|
||||
if (event != NGTCP2_CC_EVENT_TYPE_TX_START ||
|
||||
cubic->epoch_start == UINT64_MAX) {
|
||||
return;
|
||||
}
|
||||
|
||||
last_ts = cstat->last_tx_pkt_ts[NGTCP2_PKTNS_ID_APPLICATION];
|
||||
if (last_ts == UINT64_MAX || last_ts <= cc->epoch_start) {
|
||||
if (last_ts == UINT64_MAX || last_ts <= cubic->epoch_start) {
|
||||
return;
|
||||
}
|
||||
|
||||
assert(ts >= last_ts);
|
||||
|
||||
cc->epoch_start += ts - last_ts;
|
||||
cubic->epoch_start += ts - last_ts;
|
||||
}
|
||||
Vendored
+27
-48
@@ -31,24 +31,14 @@
|
||||
|
||||
#include <ngtcp2/ngtcp2.h>
|
||||
|
||||
#include "ngtcp2_pktns_id.h"
|
||||
#include "ngtcp2_window_filter.h"
|
||||
|
||||
#define NGTCP2_LOSS_REDUCTION_FACTOR_BITS 1
|
||||
#define NGTCP2_PERSISTENT_CONGESTION_THRESHOLD 3
|
||||
|
||||
typedef struct ngtcp2_log ngtcp2_log;
|
||||
|
||||
/**
|
||||
* @struct
|
||||
*
|
||||
* :type:`ngtcp2_cc_base` is the base structure of custom congestion
|
||||
* control algorithm. It must be the first field of custom congestion
|
||||
* controller.
|
||||
*/
|
||||
typedef struct ngtcp2_cc_base {
|
||||
/**
|
||||
* :member:`log` is ngtcp2 library internal logger.
|
||||
*/
|
||||
ngtcp2_log *log;
|
||||
} ngtcp2_cc_base;
|
||||
typedef struct ngtcp2_conn_stat ngtcp2_conn_stat;
|
||||
|
||||
/**
|
||||
* @struct
|
||||
@@ -117,10 +107,10 @@ typedef struct ngtcp2_cc_ack {
|
||||
*/
|
||||
uint64_t pkt_delivered;
|
||||
/**
|
||||
* :member:`largest_acked_sent_ts` is the time when the largest
|
||||
* acknowledged packet was sent.
|
||||
* :member:`largest_pkt_sent_ts` is the time when the largest
|
||||
* acknowledged packet was sent. It is UINT64_MAX if it is unknown.
|
||||
*/
|
||||
ngtcp2_tstamp largest_acked_sent_ts;
|
||||
ngtcp2_tstamp largest_pkt_sent_ts;
|
||||
/**
|
||||
* :member:`rtt` is the RTT sample. It is UINT64_MAX if no RTT
|
||||
* sample is available.
|
||||
@@ -242,15 +232,14 @@ typedef void (*ngtcp2_cc_event)(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
|
||||
/**
|
||||
* @struct
|
||||
*
|
||||
* :type:`ngtcp2_cc` is congestion control algorithm interface to
|
||||
* allow custom implementation.
|
||||
* :type:`ngtcp2_cc` is congestion control algorithm interface shared
|
||||
* by implementations. All callback functions are optional.
|
||||
*/
|
||||
typedef struct ngtcp2_cc {
|
||||
/**
|
||||
* :member:`ccb` is a pointer to :type:`ngtcp2_cc_base` which
|
||||
* usually contains a state.
|
||||
* :member:`log` is ngtcp2 library internal logger.
|
||||
*/
|
||||
ngtcp2_cc_base *ccb;
|
||||
ngtcp2_log *log;
|
||||
/**
|
||||
* :member:`on_pkt_acked` is a callback function which is called
|
||||
* when a packet is acknowledged.
|
||||
@@ -313,22 +302,16 @@ ngtcp2_cc_pkt *ngtcp2_cc_pkt_init(ngtcp2_cc_pkt *pkt, int64_t pkt_num,
|
||||
ngtcp2_tstamp sent_ts, uint64_t lost,
|
||||
uint64_t tx_in_flight, int is_app_limited);
|
||||
|
||||
/* ngtcp2_reno_cc is the RENO congestion controller. */
|
||||
typedef struct ngtcp2_reno_cc {
|
||||
ngtcp2_cc_base ccb;
|
||||
uint64_t max_delivery_rate_sec;
|
||||
/* ngtcp2_cc_reno is the RENO congestion controller. */
|
||||
typedef struct ngtcp2_cc_reno {
|
||||
ngtcp2_cc cc;
|
||||
ngtcp2_window_filter delivery_rate_sec_filter;
|
||||
uint64_t ack_count;
|
||||
uint64_t target_cwnd;
|
||||
uint64_t pending_add;
|
||||
} ngtcp2_reno_cc;
|
||||
} ngtcp2_cc_reno;
|
||||
|
||||
int ngtcp2_cc_reno_cc_init(ngtcp2_cc *cc, ngtcp2_log *log,
|
||||
const ngtcp2_mem *mem);
|
||||
|
||||
void ngtcp2_cc_reno_cc_free(ngtcp2_cc *cc, const ngtcp2_mem *mem);
|
||||
|
||||
void ngtcp2_reno_cc_init(ngtcp2_reno_cc *cc, ngtcp2_log *log);
|
||||
|
||||
void ngtcp2_reno_cc_free(ngtcp2_reno_cc *cc);
|
||||
void ngtcp2_cc_reno_init(ngtcp2_cc_reno *reno, ngtcp2_log *log);
|
||||
|
||||
void ngtcp2_cc_reno_cc_on_pkt_acked(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
|
||||
const ngtcp2_cc_pkt *pkt, ngtcp2_tstamp ts);
|
||||
@@ -347,10 +330,11 @@ void ngtcp2_cc_reno_cc_on_ack_recv(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
|
||||
void ngtcp2_cc_reno_cc_reset(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
|
||||
ngtcp2_tstamp ts);
|
||||
|
||||
/* ngtcp2_cubic_cc is CUBIC congestion controller. */
|
||||
typedef struct ngtcp2_cubic_cc {
|
||||
ngtcp2_cc_base ccb;
|
||||
uint64_t max_delivery_rate_sec;
|
||||
/* ngtcp2_cc_cubic is CUBIC congestion controller. */
|
||||
typedef struct ngtcp2_cc_cubic {
|
||||
ngtcp2_cc cc;
|
||||
ngtcp2_window_filter delivery_rate_sec_filter;
|
||||
uint64_t ack_count;
|
||||
uint64_t target_cwnd;
|
||||
uint64_t w_last_max;
|
||||
uint64_t w_tcp;
|
||||
@@ -376,16 +360,9 @@ typedef struct ngtcp2_cubic_cc {
|
||||
int64_t window_end;
|
||||
uint64_t pending_add;
|
||||
uint64_t pending_w_add;
|
||||
} ngtcp2_cubic_cc;
|
||||
} ngtcp2_cc_cubic;
|
||||
|
||||
int ngtcp2_cc_cubic_cc_init(ngtcp2_cc *cc, ngtcp2_log *log,
|
||||
const ngtcp2_mem *mem);
|
||||
|
||||
void ngtcp2_cc_cubic_cc_free(ngtcp2_cc *cc, const ngtcp2_mem *mem);
|
||||
|
||||
void ngtcp2_cubic_cc_init(ngtcp2_cubic_cc *cc, ngtcp2_log *log);
|
||||
|
||||
void ngtcp2_cubic_cc_free(ngtcp2_cubic_cc *cc);
|
||||
void ngtcp2_cc_cubic_init(ngtcp2_cc_cubic *cc, ngtcp2_log *log);
|
||||
|
||||
void ngtcp2_cc_cubic_cc_on_pkt_acked(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
|
||||
const ngtcp2_cc_pkt *pkt,
|
||||
@@ -418,4 +395,6 @@ void ngtcp2_cc_cubic_cc_reset(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
|
||||
void ngtcp2_cc_cubic_cc_event(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
|
||||
ngtcp2_cc_event_type event, ngtcp2_tstamp ts);
|
||||
|
||||
uint64_t ngtcp2_cbrt(uint64_t n);
|
||||
|
||||
#endif /* NGTCP2_CC_H */
|
||||
Vendored
+1729
-1428
File diff suppressed because it is too large.
Load diff
Vendored
+119
-75
@@ -43,7 +43,6 @@
|
||||
#include "ngtcp2_pq.h"
|
||||
#include "ngtcp2_cc.h"
|
||||
#include "ngtcp2_bbr.h"
|
||||
#include "ngtcp2_bbr2.h"
|
||||
#include "ngtcp2_pv.h"
|
||||
#include "ngtcp2_pmtud.h"
|
||||
#include "ngtcp2_cid.h"
|
||||
@@ -51,16 +50,15 @@
|
||||
#include "ngtcp2_ppe.h"
|
||||
#include "ngtcp2_qlog.h"
|
||||
#include "ngtcp2_rst.h"
|
||||
#include "ngtcp2_conn_stat.h"
|
||||
|
||||
typedef enum {
|
||||
/* Client specific handshake states */
|
||||
NGTCP2_CS_CLIENT_INITIAL,
|
||||
NGTCP2_CS_CLIENT_WAIT_HANDSHAKE,
|
||||
NGTCP2_CS_CLIENT_TLS_HANDSHAKE_FAILED,
|
||||
/* Server specific handshake states */
|
||||
NGTCP2_CS_SERVER_INITIAL,
|
||||
NGTCP2_CS_SERVER_WAIT_HANDSHAKE,
|
||||
NGTCP2_CS_SERVER_TLS_HANDSHAKE_FAILED,
|
||||
/* Shared by both client and server */
|
||||
NGTCP2_CS_POST_HANDSHAKE,
|
||||
NGTCP2_CS_CLOSING,
|
||||
@@ -111,18 +109,14 @@ typedef enum {
|
||||
to put the sane limit.*/
|
||||
#define NGTCP2_MAX_SCID_POOL_SIZE 8
|
||||
|
||||
/* NGTCP2_MAX_NON_ACK_TX_PKT is the maximum number of continuous non
|
||||
ACK-eliciting packets. */
|
||||
#define NGTCP2_MAX_NON_ACK_TX_PKT 3
|
||||
|
||||
/* NGTCP2_ECN_MAX_NUM_VALIDATION_PKTS is the maximum number of ECN marked
|
||||
packets sent in NGTCP2_ECN_STATE_TESTING period. */
|
||||
#define NGTCP2_ECN_MAX_NUM_VALIDATION_PKTS 10
|
||||
|
||||
/* NGTCP2_CONNECTION_CLOSE_ERROR_MAX_REASONLEN is the maximum length
|
||||
of reason phrase to remember. If the received reason phrase is
|
||||
longer than this value, it is truncated. */
|
||||
#define NGTCP2_CONNECTION_CLOSE_ERROR_MAX_REASONLEN 1024
|
||||
/* NGTCP2_CCERR_MAX_REASONLEN is the maximum length of reason phrase
|
||||
to remember. If the received reason phrase is longer than this
|
||||
value, it is truncated. */
|
||||
#define NGTCP2_CCERR_MAX_REASONLEN 1024
|
||||
|
||||
/* NGTCP2_WRITE_PKT_FLAG_NONE indicates that no flag is set. */
|
||||
#define NGTCP2_WRITE_PKT_FLAG_NONE 0x00u
|
||||
@@ -142,8 +136,8 @@ typedef union ngtcp2_max_frame {
|
||||
ngtcp2_frame fr;
|
||||
struct {
|
||||
ngtcp2_ack ack;
|
||||
/* ack includes 1 ngtcp2_ack_blk. */
|
||||
ngtcp2_ack_blk blks[NGTCP2_MAX_ACK_BLKS - 1];
|
||||
/* ack includes 1 ngtcp2_ack_range. */
|
||||
ngtcp2_ack_range ranges[NGTCP2_MAX_ACK_RANGES - 1];
|
||||
} ackfr;
|
||||
} ngtcp2_max_frame;
|
||||
|
||||
@@ -158,17 +152,17 @@ void ngtcp2_path_challenge_entry_init(ngtcp2_path_challenge_entry *pcent,
|
||||
|
||||
/* NGTCP2_CONN_FLAG_NONE indicates that no flag is set. */
|
||||
#define NGTCP2_CONN_FLAG_NONE 0x00u
|
||||
/* NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED is set when TLS stack declares
|
||||
that TLS handshake has completed. The condition of this
|
||||
/* NGTCP2_CONN_FLAG_TLS_HANDSHAKE_COMPLETED is set when TLS stack
|
||||
declares that TLS handshake has completed. The condition of this
|
||||
declaration varies between TLS implementations and this flag does
|
||||
not indicate the completion of QUIC handshake. Some
|
||||
implementations declare TLS handshake completion as server when
|
||||
they write off Server Finished and before deriving application rx
|
||||
secret. */
|
||||
#define NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED 0x01u
|
||||
/* NGTCP2_CONN_FLAG_CONN_ID_NEGOTIATED is set if connection ID is
|
||||
negotiated. This is only used for client. */
|
||||
#define NGTCP2_CONN_FLAG_CONN_ID_NEGOTIATED 0x02u
|
||||
#define NGTCP2_CONN_FLAG_TLS_HANDSHAKE_COMPLETED 0x01u
|
||||
/* NGTCP2_CONN_FLAG_INITIAL_PKT_PROCESSED is set when the first
|
||||
Initial packet has successfully been processed. */
|
||||
#define NGTCP2_CONN_FLAG_INITIAL_PKT_PROCESSED 0x02u
|
||||
/* NGTCP2_CONN_FLAG_TRANSPORT_PARAM_RECVED is set if transport
|
||||
parameters are received. */
|
||||
#define NGTCP2_CONN_FLAG_TRANSPORT_PARAM_RECVED 0x04u
|
||||
@@ -187,9 +181,9 @@ void ngtcp2_path_challenge_entry_init(ngtcp2_path_challenge_entry *pcent,
|
||||
/* NGTCP2_CONN_FLAG_HANDSHAKE_CONFIRMED is set when an endpoint
|
||||
confirmed completion of handshake. */
|
||||
#define NGTCP2_CONN_FLAG_HANDSHAKE_CONFIRMED 0x80u
|
||||
/* NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED_HANDLED is set when the
|
||||
library transitions its state to "post handshake". */
|
||||
#define NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED_HANDLED 0x0100u
|
||||
/* NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED is set when the library
|
||||
transitions its state to "post handshake". */
|
||||
#define NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED 0x0100u
|
||||
/* NGTCP2_CONN_FLAG_HANDSHAKE_EARLY_RETRANSMIT is set when the early
|
||||
handshake retransmission has done when server receives overlapping
|
||||
Initial crypto data. */
|
||||
@@ -221,23 +215,15 @@ void ngtcp2_path_challenge_entry_init(ngtcp2_path_challenge_entry *pcent,
|
||||
endpoint has initiated key update. */
|
||||
#define NGTCP2_CONN_FLAG_KEY_UPDATE_INITIATOR 0x10000u
|
||||
|
||||
typedef struct ngtcp2_crypto_data {
|
||||
ngtcp2_buf buf;
|
||||
/* pkt_type is the type of packet to send data in buf. If it is 0,
|
||||
it must be sent in Short packet. Otherwise, it is sent the long
|
||||
packet type denoted by pkt_type. */
|
||||
uint8_t pkt_type;
|
||||
} ngtcp2_crypto_data;
|
||||
|
||||
typedef struct ngtcp2_pktns {
|
||||
struct {
|
||||
/* last_pkt_num is the packet number which the local endpoint sent
|
||||
last time.*/
|
||||
int64_t last_pkt_num;
|
||||
ngtcp2_frame_chain *frq;
|
||||
/* num_non_ack_pkt is the number of continuous non ACK-eliciting
|
||||
packets. */
|
||||
size_t num_non_ack_pkt;
|
||||
/* non_ack_pkt_start_ts is the timestamp since the local endpoint
|
||||
starts sending continuous non ACK-eliciting packets. */
|
||||
ngtcp2_tstamp non_ack_pkt_start_ts;
|
||||
|
||||
struct {
|
||||
/* ect0 is the number of QUIC packets, not UDP datagram, which
|
||||
@@ -307,8 +293,6 @@ typedef struct ngtcp2_pktns {
|
||||
|
||||
struct {
|
||||
struct {
|
||||
/* frq contains crypto data sorted by their offset. */
|
||||
ngtcp2_ksl frq;
|
||||
/* offset is the offset of crypto stream in this packet number
|
||||
space. */
|
||||
uint64_t offset;
|
||||
@@ -344,6 +328,19 @@ typedef enum ngtcp2_ecn_state {
|
||||
NGTCP2_ECN_STATE_CAPABLE,
|
||||
} ngtcp2_ecn_state;
|
||||
|
||||
/* ngtcp2_early_transport_params is the values remembered by client
|
||||
from the previous session. */
|
||||
typedef struct ngtcp2_early_transport_params {
|
||||
uint64_t initial_max_streams_bidi;
|
||||
uint64_t initial_max_streams_uni;
|
||||
uint64_t initial_max_stream_data_bidi_local;
|
||||
uint64_t initial_max_stream_data_bidi_remote;
|
||||
uint64_t initial_max_stream_data_uni;
|
||||
uint64_t initial_max_data;
|
||||
uint64_t active_connection_id_limit;
|
||||
uint64_t max_datagram_frame_size;
|
||||
} ngtcp2_early_transport_params;
|
||||
|
||||
ngtcp2_static_ringbuf_def(dcid_bound, NGTCP2_MAX_BOUND_DCID_POOL_SIZE,
|
||||
sizeof(ngtcp2_dcid));
|
||||
ngtcp2_static_ringbuf_def(dcid_unused, NGTCP2_MAX_DCID_POOL_SIZE,
|
||||
@@ -353,7 +350,7 @@ ngtcp2_static_ringbuf_def(dcid_retired, NGTCP2_MAX_DCID_RETIRED_SIZE,
|
||||
ngtcp2_static_ringbuf_def(path_challenge, 4,
|
||||
sizeof(ngtcp2_path_challenge_entry));
|
||||
|
||||
ngtcp2_objalloc_def(strm, ngtcp2_strm, oplent);
|
||||
ngtcp2_objalloc_decl(strm, ngtcp2_strm, oplent);
|
||||
|
||||
struct ngtcp2_conn {
|
||||
ngtcp2_objalloc frc_objalloc;
|
||||
@@ -421,25 +418,28 @@ struct ngtcp2_conn {
|
||||
/* num_retired is the number of retired Connection ID still
|
||||
included in set. */
|
||||
size_t num_retired;
|
||||
/* num_in_flight is the number of NEW_CONNECTION_ID frames that
|
||||
are in-flight and not acknowledged yet. */
|
||||
size_t num_in_flight;
|
||||
} scid;
|
||||
|
||||
struct {
|
||||
/* strmq contains ngtcp2_strm which has frames to send. */
|
||||
ngtcp2_pq strmq;
|
||||
/* strmq_nretrans is the number of entries in strmq which has
|
||||
stream data to resent. */
|
||||
size_t strmq_nretrans;
|
||||
/* ack is ACK frame. The underlying buffer is reused. */
|
||||
ngtcp2_frame *ack;
|
||||
/* max_ack_blks is the number of additional ngtcp2_ack_blk which
|
||||
ack can contain. */
|
||||
size_t max_ack_blks;
|
||||
/* max_ack_ranges is the number of additional ngtcp2_ack_range
|
||||
which ack can contain. */
|
||||
size_t max_ack_ranges;
|
||||
/* offset is the offset the local endpoint has sent to the remote
|
||||
endpoint. */
|
||||
uint64_t offset;
|
||||
/* max_offset is the maximum offset that local endpoint can
|
||||
send. */
|
||||
uint64_t max_offset;
|
||||
/* last_blocked_offset is the largest offset where the
|
||||
transmission of stream data is blocked. */
|
||||
uint64_t last_blocked_offset;
|
||||
/* last_max_data_ts is the timestamp when last MAX_DATA frame is
|
||||
sent. */
|
||||
ngtcp2_tstamp last_max_data_ts;
|
||||
@@ -482,7 +482,7 @@ struct ngtcp2_conn {
|
||||
/* path_challenge stores received PATH_CHALLENGE data. */
|
||||
ngtcp2_static_ringbuf_path_challenge path_challenge;
|
||||
/* ccerr is the received connection close error. */
|
||||
ngtcp2_connection_close_error ccerr;
|
||||
ngtcp2_ccerr ccerr;
|
||||
} rx;
|
||||
|
||||
struct {
|
||||
@@ -497,16 +497,7 @@ struct ngtcp2_conn {
|
||||
ngtcp2_conn_set_early_remote_transport_params(). Server does
|
||||
not use this field. Server must not set values for these
|
||||
parameters that are smaller than the remembered values. */
|
||||
struct {
|
||||
uint64_t initial_max_streams_bidi;
|
||||
uint64_t initial_max_streams_uni;
|
||||
uint64_t initial_max_stream_data_bidi_local;
|
||||
uint64_t initial_max_stream_data_bidi_remote;
|
||||
uint64_t initial_max_stream_data_uni;
|
||||
uint64_t initial_max_data;
|
||||
uint64_t active_connection_id_limit;
|
||||
uint64_t max_datagram_frame_size;
|
||||
} transport_params;
|
||||
ngtcp2_early_transport_params transport_params;
|
||||
} early;
|
||||
|
||||
struct {
|
||||
@@ -658,14 +649,14 @@ struct ngtcp2_conn {
|
||||
array pointed by preferred_versions. This field is only used
|
||||
by server. */
|
||||
size_t preferred_versionslen;
|
||||
/* other_versions is the versions that the local endpoint sends in
|
||||
version_information transport parameter. This is the wire
|
||||
image of other_versions field of version_information transport
|
||||
parameter. */
|
||||
uint8_t *other_versions;
|
||||
/* other_versionslen is the length of data pointed by
|
||||
other_versions field. */
|
||||
size_t other_versionslen;
|
||||
/* available_versions is the versions that the local endpoint
|
||||
sends in version_information transport parameter. This is the
|
||||
wire image of available_versions field of version_information
|
||||
transport parameter. */
|
||||
uint8_t *available_versions;
|
||||
/* available_versionslen is the length of data pointed by
|
||||
available_versions field. */
|
||||
size_t available_versionslen;
|
||||
} vneg;
|
||||
|
||||
ngtcp2_map strms;
|
||||
@@ -676,7 +667,12 @@ struct ngtcp2_conn {
|
||||
ngtcp2_qlog qlog;
|
||||
ngtcp2_rst rst;
|
||||
ngtcp2_cc_algo cc_algo;
|
||||
ngtcp2_cc cc;
|
||||
union {
|
||||
ngtcp2_cc cc;
|
||||
ngtcp2_cc_reno reno;
|
||||
ngtcp2_cc_cubic cubic;
|
||||
ngtcp2_cc_bbr bbr;
|
||||
};
|
||||
const ngtcp2_mem *mem;
|
||||
/* idle_ts is the time instant when idle timer started. */
|
||||
ngtcp2_tstamp idle_ts;
|
||||
@@ -913,19 +909,6 @@ ngtcp2_tstamp ngtcp2_conn_lost_pkt_expiry(ngtcp2_conn *conn);
|
||||
*/
|
||||
void ngtcp2_conn_remove_lost_pkt(ngtcp2_conn *conn, ngtcp2_tstamp ts);
|
||||
|
||||
/*
|
||||
* ngtcp2_conn_resched_frames reschedules frames linked from |*pfrc|
|
||||
* for retransmission.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGTCP2_ERR_NOMEM
|
||||
* Out of memory.
|
||||
*/
|
||||
int ngtcp2_conn_resched_frames(ngtcp2_conn *conn, ngtcp2_pktns *pktns,
|
||||
ngtcp2_frame_chain **pfrc);
|
||||
|
||||
uint64_t ngtcp2_conn_tx_strmq_first_cycle(ngtcp2_conn *conn);
|
||||
|
||||
/**
|
||||
@@ -1112,4 +1095,65 @@ void ngtcp2_conn_stop_pmtud(ngtcp2_conn *conn);
|
||||
int ngtcp2_conn_set_remote_transport_params(
|
||||
ngtcp2_conn *conn, const ngtcp2_transport_params *params);
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* `ngtcp2_conn_set_0rtt_remote_transport_params` sets |params| as
|
||||
* transport parameters previously received from a server. The
|
||||
* parameters are used to send early data. QUIC requires that client
|
||||
* application should remember transport parameters along with a
|
||||
* session ticket.
|
||||
*
|
||||
* At least following fields should be set:
|
||||
*
|
||||
* - initial_max_stream_id_bidi
|
||||
* - initial_max_stream_id_uni
|
||||
* - initial_max_stream_data_bidi_local
|
||||
* - initial_max_stream_data_bidi_remote
|
||||
* - initial_max_stream_data_uni
|
||||
* - initial_max_data
|
||||
* - active_connection_id_limit
|
||||
* - max_datagram_frame_size (if DATAGRAM extension was negotiated)
|
||||
*
|
||||
* The following fields are ignored:
|
||||
*
|
||||
* - ack_delay_exponent
|
||||
* - max_ack_delay
|
||||
* - initial_scid
|
||||
* - original_dcid
|
||||
* - preferred_address and preferred_address_present
|
||||
* - retry_scid and retry_scid_present
|
||||
* - stateless_reset_token and stateless_reset_token_present
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* :macro:`NGTCP2_ERR_NOMEM`
|
||||
* Out of memory.
|
||||
*/
|
||||
int ngtcp2_conn_set_0rtt_remote_transport_params(
|
||||
ngtcp2_conn *conn, const ngtcp2_transport_params *params);
|
||||
|
||||
/*
|
||||
* ngtcp2_conn_create_ack_frame creates ACK frame, and assigns its
|
||||
* pointer to |*pfr| if there are any received packets to acknowledge.
|
||||
* If there are no packets to acknowledge, this function returns 0,
|
||||
* and |*pfr| is untouched. The caller is advised to set |*pfr| to
|
||||
* NULL before calling this function, and check it after this function
|
||||
* returns.
|
||||
*
|
||||
* Call ngtcp2_acktr_commit_ack after a created ACK frame is
|
||||
* successfully serialized into a packet.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGTCP2_ERR_NOMEM
|
||||
* Out of memory.
|
||||
*/
|
||||
int ngtcp2_conn_create_ack_frame(ngtcp2_conn *conn, ngtcp2_frame **pfr,
|
||||
ngtcp2_pktns *pktns, uint8_t type,
|
||||
ngtcp2_tstamp ts, ngtcp2_duration ack_delay,
|
||||
uint64_t ack_delay_exponent);
|
||||
|
||||
#endif /* NGTCP2_CONN_H */
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* ngtcp2
|
||||
*
|
||||
* Copyright (c) 2023 ngtcp2 contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef NGTCP2_CONN_STAT_H
|
||||
#define NGTCP2_CONN_STAT_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
||||
#include <ngtcp2/ngtcp2.h>
|
||||
|
||||
/**
|
||||
* @struct
|
||||
*
|
||||
* :type:`ngtcp2_conn_stat` holds various connection statistics, and
|
||||
* computed data for recovery and congestion controller.
|
||||
*/
|
||||
typedef struct ngtcp2_conn_stat {
|
||||
/**
|
||||
* :member:`latest_rtt` is the latest RTT sample which is not
|
||||
* adjusted by acknowledgement delay.
|
||||
*/
|
||||
ngtcp2_duration latest_rtt;
|
||||
/**
|
||||
* :member:`min_rtt` is the minimum RTT seen so far. It is not
|
||||
* adjusted by acknowledgement delay.
|
||||
*/
|
||||
ngtcp2_duration min_rtt;
|
||||
/**
|
||||
* :member:`smoothed_rtt` is the smoothed RTT.
|
||||
*/
|
||||
ngtcp2_duration smoothed_rtt;
|
||||
/**
|
||||
* :member:`rttvar` is a mean deviation of observed RTT.
|
||||
*/
|
||||
ngtcp2_duration rttvar;
|
||||
/**
|
||||
* :member:`initial_rtt` is the initial RTT which is used when no
|
||||
* RTT sample is available.
|
||||
*/
|
||||
ngtcp2_duration initial_rtt;
|
||||
/**
|
||||
* :member:`first_rtt_sample_ts` is the timestamp when the first RTT
|
||||
* sample is obtained.
|
||||
*/
|
||||
ngtcp2_tstamp first_rtt_sample_ts;
|
||||
/**
|
||||
* :member:`pto_count` is the count of successive PTO timer
|
||||
* expiration.
|
||||
*/
|
||||
size_t pto_count;
|
||||
/**
|
||||
* :member:`loss_detection_timer` is the deadline of the current
|
||||
* loss detection timer.
|
||||
*/
|
||||
ngtcp2_tstamp loss_detection_timer;
|
||||
/**
|
||||
* :member:`last_tx_pkt_ts` corresponds to
|
||||
* time_of_last_ack_eliciting_packet in :rfc:`9002`.
|
||||
*/
|
||||
ngtcp2_tstamp last_tx_pkt_ts[NGTCP2_PKTNS_ID_MAX];
|
||||
/**
|
||||
* :member:`loss_time` corresponds to loss_time in :rfc:`9002`.
|
||||
*/
|
||||
ngtcp2_tstamp loss_time[NGTCP2_PKTNS_ID_MAX];
|
||||
/**
|
||||
* :member:`cwnd` is the size of congestion window.
|
||||
*/
|
||||
uint64_t cwnd;
|
||||
/**
|
||||
* :member:`ssthresh` is slow start threshold.
|
||||
*/
|
||||
uint64_t ssthresh;
|
||||
/**
|
||||
* :member:`congestion_recovery_start_ts` is the timestamp when
|
||||
* congestion recovery started.
|
||||
*/
|
||||
ngtcp2_tstamp congestion_recovery_start_ts;
|
||||
/**
|
||||
* :member:`bytes_in_flight` is the number in bytes of all sent
|
||||
* packets which have not been acknowledged.
|
||||
*/
|
||||
uint64_t bytes_in_flight;
|
||||
/**
|
||||
* :member:`max_tx_udp_payload_size` is the maximum size of UDP
|
||||
* datagram payload that this endpoint transmits. It is used by
|
||||
* congestion controller to compute congestion window.
|
||||
*/
|
||||
size_t max_tx_udp_payload_size;
|
||||
/**
|
||||
* :member:`delivery_rate_sec` is the current sending rate measured
|
||||
* in byte per second.
|
||||
*/
|
||||
uint64_t delivery_rate_sec;
|
||||
/**
|
||||
* :member:`pacing_interval` is the inverse of pacing rate, which is
|
||||
* the current packet sending rate computed by a congestion
|
||||
* controller. 0 if a congestion controller does not set pacing
|
||||
* interval. Even if this value is set to 0, the library paces
|
||||
* packets.
|
||||
*/
|
||||
ngtcp2_duration pacing_interval;
|
||||
/**
|
||||
* :member:`send_quantum` is the maximum size of a data aggregate
|
||||
* scheduled and transmitted together.
|
||||
*/
|
||||
size_t send_quantum;
|
||||
} ngtcp2_conn_stat;
|
||||
|
||||
#endif /* NGTCP2_CONN_STAT_H */
|
||||
Vendored
+64
-31
@@ -30,40 +30,51 @@
|
||||
#include "ngtcp2_str.h"
|
||||
#include "ngtcp2_pkt.h"
|
||||
#include "ngtcp2_net.h"
|
||||
#include "ngtcp2_unreachable.h"
|
||||
|
||||
uint64_t ngtcp2_get_uint64(const uint8_t *p) {
|
||||
const uint8_t *ngtcp2_get_uint64(uint64_t *dest, const uint8_t *p) {
|
||||
uint64_t n;
|
||||
memcpy(&n, p, 8);
|
||||
return ngtcp2_ntohl64(n);
|
||||
memcpy(&n, p, sizeof(n));
|
||||
*dest = ngtcp2_ntohl64(n);
|
||||
return p + sizeof(n);
|
||||
}
|
||||
|
||||
uint64_t ngtcp2_get_uint48(const uint8_t *p) {
|
||||
const uint8_t *ngtcp2_get_uint48(uint64_t *dest, const uint8_t *p) {
|
||||
uint64_t n = 0;
|
||||
memcpy(((uint8_t *)&n) + 2, p, 6);
|
||||
return ngtcp2_ntohl64(n);
|
||||
*dest = ngtcp2_ntohl64(n);
|
||||
return p + 6;
|
||||
}
|
||||
|
||||
uint32_t ngtcp2_get_uint32(const uint8_t *p) {
|
||||
const uint8_t *ngtcp2_get_uint32(uint32_t *dest, const uint8_t *p) {
|
||||
uint32_t n;
|
||||
memcpy(&n, p, 4);
|
||||
return ngtcp2_ntohl(n);
|
||||
memcpy(&n, p, sizeof(n));
|
||||
*dest = ngtcp2_ntohl(n);
|
||||
return p + sizeof(n);
|
||||
}
|
||||
|
||||
uint32_t ngtcp2_get_uint24(const uint8_t *p) {
|
||||
const uint8_t *ngtcp2_get_uint24(uint32_t *dest, const uint8_t *p) {
|
||||
uint32_t n = 0;
|
||||
memcpy(((uint8_t *)&n) + 1, p, 3);
|
||||
return ngtcp2_ntohl(n);
|
||||
*dest = ngtcp2_ntohl(n);
|
||||
return p + 3;
|
||||
}
|
||||
|
||||
uint16_t ngtcp2_get_uint16(const uint8_t *p) {
|
||||
const uint8_t *ngtcp2_get_uint16(uint16_t *dest, const uint8_t *p) {
|
||||
uint16_t n;
|
||||
memcpy(&n, p, 2);
|
||||
return ngtcp2_ntohs(n);
|
||||
memcpy(&n, p, sizeof(n));
|
||||
*dest = ngtcp2_ntohs(n);
|
||||
return p + sizeof(n);
|
||||
}
|
||||
|
||||
uint64_t ngtcp2_get_varint(size_t *plen, const uint8_t *p) {
|
||||
const uint8_t *ngtcp2_get_uint16be(uint16_t *dest, const uint8_t *p) {
|
||||
memcpy(dest, p, sizeof(*dest));
|
||||
return p + sizeof(*dest);
|
||||
}
|
||||
|
||||
static uint64_t get_uvarint(size_t *plen, const uint8_t *p) {
|
||||
union {
|
||||
char b[8];
|
||||
uint8_t n8;
|
||||
uint16_t n16;
|
||||
uint32_t n32;
|
||||
uint64_t n64;
|
||||
@@ -76,36 +87,55 @@ uint64_t ngtcp2_get_varint(size_t *plen, const uint8_t *p) {
|
||||
return *p;
|
||||
case 2:
|
||||
memcpy(&n, p, 2);
|
||||
n.b[0] &= 0x3f;
|
||||
n.n8 &= 0x3f;
|
||||
return ngtcp2_ntohs(n.n16);
|
||||
case 4:
|
||||
memcpy(&n, p, 4);
|
||||
n.b[0] &= 0x3f;
|
||||
n.n8 &= 0x3f;
|
||||
return ngtcp2_ntohl(n.n32);
|
||||
case 8:
|
||||
memcpy(&n, p, 8);
|
||||
n.b[0] &= 0x3f;
|
||||
n.n8 &= 0x3f;
|
||||
return ngtcp2_ntohl64(n.n64);
|
||||
default:
|
||||
assert(0);
|
||||
ngtcp2_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
const uint8_t *ngtcp2_get_uvarint(uint64_t *dest, const uint8_t *p) {
|
||||
size_t len;
|
||||
|
||||
*dest = get_uvarint(&len, p);
|
||||
|
||||
return p + len;
|
||||
}
|
||||
|
||||
const uint8_t *ngtcp2_get_varint(int64_t *dest, const uint8_t *p) {
|
||||
size_t len;
|
||||
|
||||
*dest = (int64_t)get_uvarint(&len, p);
|
||||
|
||||
return p + len;
|
||||
}
|
||||
|
||||
int64_t ngtcp2_get_pkt_num(const uint8_t *p, size_t pkt_numlen) {
|
||||
uint32_t l;
|
||||
uint16_t s;
|
||||
|
||||
switch (pkt_numlen) {
|
||||
case 1:
|
||||
return *p;
|
||||
case 2:
|
||||
return (int64_t)ngtcp2_get_uint16(p);
|
||||
ngtcp2_get_uint16(&s, p);
|
||||
return (int64_t)s;
|
||||
case 3:
|
||||
return (int64_t)ngtcp2_get_uint24(p);
|
||||
ngtcp2_get_uint24(&l, p);
|
||||
return (int64_t)l;
|
||||
case 4:
|
||||
return (int64_t)ngtcp2_get_uint32(p);
|
||||
ngtcp2_get_uint32(&l, p);
|
||||
return (int64_t)l;
|
||||
default:
|
||||
assert(0);
|
||||
abort();
|
||||
ngtcp2_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +164,11 @@ uint8_t *ngtcp2_put_uint16be(uint8_t *p, uint16_t n) {
|
||||
return ngtcp2_cpymem(p, (const uint8_t *)&n, sizeof(n));
|
||||
}
|
||||
|
||||
uint8_t *ngtcp2_put_varint(uint8_t *p, uint64_t n) {
|
||||
uint8_t *ngtcp2_put_uint16(uint8_t *p, uint16_t n) {
|
||||
return ngtcp2_cpymem(p, (const uint8_t *)&n, sizeof(n));
|
||||
}
|
||||
|
||||
uint8_t *ngtcp2_put_uvarint(uint8_t *p, uint64_t n) {
|
||||
uint8_t *rv;
|
||||
if (n < 64) {
|
||||
*p++ = (uint8_t)n;
|
||||
@@ -156,7 +190,7 @@ uint8_t *ngtcp2_put_varint(uint8_t *p, uint64_t n) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
uint8_t *ngtcp2_put_varint30(uint8_t *p, uint32_t n) {
|
||||
uint8_t *ngtcp2_put_uvarint30(uint8_t *p, uint32_t n) {
|
||||
uint8_t *rv;
|
||||
|
||||
assert(n < 1073741824);
|
||||
@@ -182,16 +216,15 @@ uint8_t *ngtcp2_put_pkt_num(uint8_t *p, int64_t pkt_num, size_t len) {
|
||||
ngtcp2_put_uint32be(p, (uint32_t)pkt_num);
|
||||
return p + 4;
|
||||
default:
|
||||
assert(0);
|
||||
abort();
|
||||
ngtcp2_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
size_t ngtcp2_get_varint_len(const uint8_t *p) {
|
||||
size_t ngtcp2_get_uvarintlen(const uint8_t *p) {
|
||||
return (size_t)(1u << (*p >> 6));
|
||||
}
|
||||
|
||||
size_t ngtcp2_put_varint_len(uint64_t n) {
|
||||
size_t ngtcp2_put_uvarintlen(uint64_t n) {
|
||||
if (n < 64) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
Vendored
+53
-31
@@ -33,45 +33,61 @@
|
||||
|
||||
/*
|
||||
* ngtcp2_get_uint64 reads 8 bytes from |p| as 64 bits unsigned
|
||||
* integer encoded as network byte order, and returns it in host byte
|
||||
* order.
|
||||
* integer encoded as network byte order, and stores it in the buffer
|
||||
* pointed by |dest| in host byte order. It returns |p| + 8.
|
||||
*/
|
||||
uint64_t ngtcp2_get_uint64(const uint8_t *p);
|
||||
const uint8_t *ngtcp2_get_uint64(uint64_t *dest, const uint8_t *p);
|
||||
|
||||
/*
|
||||
* ngtcp2_get_uint48 reads 6 bytes from |p| as 48 bits unsigned
|
||||
* integer encoded as network byte order, and returns it in host byte
|
||||
* order.
|
||||
* integer encoded as network byte order, and stores it in the buffer
|
||||
* pointed by |dest| in host byte order. It returns |p| + 6.
|
||||
*/
|
||||
uint64_t ngtcp2_get_uint48(const uint8_t *p);
|
||||
const uint8_t *ngtcp2_get_uint48(uint64_t *dest, const uint8_t *p);
|
||||
|
||||
/*
|
||||
* ngtcp2_get_uint32 reads 4 bytes from |p| as 32 bits unsigned
|
||||
* integer encoded as network byte order, and returns it in host byte
|
||||
* order.
|
||||
* integer encoded as network byte order, and stores it in the buffer
|
||||
* pointed by |dest| in host byte order. It returns |p| + 4.
|
||||
*/
|
||||
uint32_t ngtcp2_get_uint32(const uint8_t *p);
|
||||
const uint8_t *ngtcp2_get_uint32(uint32_t *dest, const uint8_t *p);
|
||||
|
||||
/*
|
||||
* ngtcp2_get_uint24 reads 3 bytes from |p| as 24 bits unsigned
|
||||
* integer encoded as network byte order, and returns it in host byte
|
||||
* order.
|
||||
* integer encoded as network byte order, and stores it in the buffer
|
||||
* pointed by |dest| in host byte order. It returns |p| + 3.
|
||||
*/
|
||||
uint32_t ngtcp2_get_uint24(const uint8_t *p);
|
||||
const uint8_t *ngtcp2_get_uint24(uint32_t *dest, const uint8_t *p);
|
||||
|
||||
/*
|
||||
* ngtcp2_get_uint16 reads 2 bytes from |p| as 16 bits unsigned
|
||||
* integer encoded as network byte order, and returns it in host byte
|
||||
* order.
|
||||
* integer encoded as network byte order, and stores it in the buffer
|
||||
* pointed by |dest| in host byte order. It returns |p| + 2.
|
||||
*/
|
||||
uint16_t ngtcp2_get_uint16(const uint8_t *p);
|
||||
const uint8_t *ngtcp2_get_uint16(uint16_t *dest, const uint8_t *p);
|
||||
|
||||
/*
|
||||
* ngtcp2_get_varint reads variable-length integer from |p|, and
|
||||
* returns it in host byte order. The number of bytes read is stored
|
||||
* in |*plen|.
|
||||
* ngtcp2_get_uint16be reads 2 bytes from |p| as 16 bits unsigned
|
||||
* integer encoded as network byte order, and stores it in the buffer
|
||||
* pointed by |dest| as is. It returns |p| + 2.
|
||||
*/
|
||||
uint64_t ngtcp2_get_varint(size_t *plen, const uint8_t *p);
|
||||
const uint8_t *ngtcp2_get_uint16be(uint16_t *dest, const uint8_t *p);
|
||||
|
||||
/*
|
||||
* ngtcp2_get_uvarint reads variable-length unsigned integer from |p|,
|
||||
* and stores it in the buffer pointed by |dest| in host byte order.
|
||||
* It returns |p| plus the number of bytes read from |p|.
|
||||
*/
|
||||
const uint8_t *ngtcp2_get_uvarint(uint64_t *dest, const uint8_t *p);
|
||||
|
||||
/*
|
||||
* ngtcp2_get_varint reads variable-length unsigned integer from |p|,
|
||||
* and casts it to the signed integer, and stores it in the buffer
|
||||
* pointed by |dest| in host byte order. No information should be
|
||||
* lost in this cast, because the variable-length integer is 62
|
||||
* bits. It returns |p| plus the number of bytes read from |p|.
|
||||
*/
|
||||
const uint8_t *ngtcp2_get_varint(int64_t *dest, const uint8_t *p);
|
||||
|
||||
/*
|
||||
* ngtcp2_get_pkt_num reads encoded packet number from |p|. The
|
||||
@@ -115,18 +131,24 @@ uint8_t *ngtcp2_put_uint24be(uint8_t *p, uint32_t n);
|
||||
uint8_t *ngtcp2_put_uint16be(uint8_t *p, uint16_t n);
|
||||
|
||||
/*
|
||||
* ngtcp2_put_varint writes |n| in |p| using variable-length integer
|
||||
* encoding. It returns the one beyond of the last written position.
|
||||
* ngtcp2_put_uint16 writes |n| as is in |p|. It returns the one
|
||||
* beyond of the last written position.
|
||||
*/
|
||||
uint8_t *ngtcp2_put_varint(uint8_t *p, uint64_t n);
|
||||
uint8_t *ngtcp2_put_uint16(uint8_t *p, uint16_t n);
|
||||
|
||||
/*
|
||||
* ngtcp2_put_varint30 writes |n| in |p| using variable-length integer
|
||||
* encoding. |n| must be strictly less than 1073741824. The function
|
||||
* always encodes |n| in 4 bytes. It returns the one beyond of the
|
||||
* last written position.
|
||||
* ngtcp2_put_uvarint writes |n| in |p| using variable-length integer
|
||||
* encoding. It returns the one beyond of the last written position.
|
||||
*/
|
||||
uint8_t *ngtcp2_put_varint30(uint8_t *p, uint32_t n);
|
||||
uint8_t *ngtcp2_put_uvarint(uint8_t *p, uint64_t n);
|
||||
|
||||
/*
|
||||
* ngtcp2_put_uvarint30 writes |n| in |p| using variable-length
|
||||
* integer encoding. |n| must be strictly less than 1073741824. The
|
||||
* function always encodes |n| in 4 bytes. It returns the one beyond
|
||||
* of the last written position.
|
||||
*/
|
||||
uint8_t *ngtcp2_put_uvarint30(uint8_t *p, uint32_t n);
|
||||
|
||||
/*
|
||||
* ngtcp2_put_pkt_num encodes |pkt_num| using |len| bytes. It
|
||||
@@ -135,16 +157,16 @@ uint8_t *ngtcp2_put_varint30(uint8_t *p, uint32_t n);
|
||||
uint8_t *ngtcp2_put_pkt_num(uint8_t *p, int64_t pkt_num, size_t len);
|
||||
|
||||
/*
|
||||
* ngtcp2_get_varint_len returns the required number of bytes to read
|
||||
* ngtcp2_get_uvarintlen returns the required number of bytes to read
|
||||
* variable-length integer starting at |p|.
|
||||
*/
|
||||
size_t ngtcp2_get_varint_len(const uint8_t *p);
|
||||
size_t ngtcp2_get_uvarintlen(const uint8_t *p);
|
||||
|
||||
/*
|
||||
* ngtcp2_put_varint_len returns the required number of bytes to
|
||||
* ngtcp2_put_uvarintlen returns the required number of bytes to
|
||||
* encode |n|.
|
||||
*/
|
||||
size_t ngtcp2_put_varint_len(uint64_t n);
|
||||
size_t ngtcp2_put_uvarintlen(uint64_t n);
|
||||
|
||||
/*
|
||||
* ngtcp2_nth_server_bidi_id returns |n|-th server bidirectional
|
||||
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* ngtcp2
|
||||
*
|
||||
* Copyright (c) 2023 ngtcp2 contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#include "ngtcp2_conversion.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
static void transport_params_copy(int transport_params_version,
|
||||
ngtcp2_transport_params *dest,
|
||||
const ngtcp2_transport_params *src) {
|
||||
assert(transport_params_version != NGTCP2_TRANSPORT_PARAMS_VERSION);
|
||||
|
||||
switch (transport_params_version) {
|
||||
case NGTCP2_TRANSPORT_PARAMS_V1:
|
||||
memcpy(dest, src,
|
||||
offsetof(ngtcp2_transport_params, version_info_present) +
|
||||
sizeof(src->version_info_present));
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const ngtcp2_transport_params *
|
||||
ngtcp2_transport_params_convert_to_latest(ngtcp2_transport_params *dest,
|
||||
int transport_params_version,
|
||||
const ngtcp2_transport_params *src) {
|
||||
if (transport_params_version == NGTCP2_TRANSPORT_PARAMS_VERSION) {
|
||||
return src;
|
||||
}
|
||||
|
||||
ngtcp2_transport_params_default(dest);
|
||||
|
||||
transport_params_copy(transport_params_version, dest, src);
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
void ngtcp2_transport_params_convert_to_old(
|
||||
int transport_params_version, ngtcp2_transport_params *dest,
|
||||
const ngtcp2_transport_params *src) {
|
||||
assert(transport_params_version != NGTCP2_TRANSPORT_PARAMS_VERSION);
|
||||
|
||||
transport_params_copy(transport_params_version, dest, src);
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* ngtcp2
|
||||
*
|
||||
* Copyright (c) 2023 ngtcp2 contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef NGTCP2_CONVERSION_H
|
||||
#define NGTCP2_CONVERSION_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
||||
#include <ngtcp2/ngtcp2.h>
|
||||
|
||||
/*
|
||||
* ngtcp2_transport_params_convert_to_latest converts |src| of version
|
||||
* |transport_params_version| to the latest version
|
||||
* NGTCP2_TRANSPORT_PARAMS_VERSION.
|
||||
*
|
||||
* |dest| must point to the latest version. |src| may be the older
|
||||
* version, and if so, it may have fewer fields. Accessing those
|
||||
* fields causes undefined behavior.
|
||||
*
|
||||
* If |transport_params_version| == NGTCP2_TRANSPORT_PARAMS_VERSION,
|
||||
* no conversion is made, and |src| is returned. Otherwise, first
|
||||
* |dest| is initialized via ngtcp2_transport_params_default, and then
|
||||
* all valid fields in |src| are copied into |dest|. Finally, |dest|
|
||||
* is returned.
|
||||
*/
|
||||
const ngtcp2_transport_params *
|
||||
ngtcp2_transport_params_convert_to_latest(ngtcp2_transport_params *dest,
|
||||
int transport_params_version,
|
||||
const ngtcp2_transport_params *src);
|
||||
|
||||
/*
|
||||
* ngtcp2_transport_params_convert_to_old converts |src| of the latest
|
||||
* version to |dest| of version |transport_params_version|.
|
||||
*
|
||||
* |transport_params_version| must not be the latest version
|
||||
* NGTCP2_TRANSPORT_PARAMS_VERSION.
|
||||
*
|
||||
* |dest| points to the older version, and it may have fewer fields.
|
||||
* Accessing those fields causes undefined behavior.
|
||||
*
|
||||
* This function copies all valid fields in version
|
||||
* |transport_params_version| from |src| to |dest|.
|
||||
*/
|
||||
void ngtcp2_transport_params_convert_to_old(int transport_params_version,
|
||||
ngtcp2_transport_params *dest,
|
||||
const ngtcp2_transport_params *src);
|
||||
|
||||
#endif /* NGTCP2_CONVERSION_H */
|
||||
+253
-293
@@ -31,6 +31,7 @@
|
||||
#include "ngtcp2_conv.h"
|
||||
#include "ngtcp2_conn.h"
|
||||
#include "ngtcp2_net.h"
|
||||
#include "ngtcp2_conversion.h"
|
||||
|
||||
int ngtcp2_crypto_km_new(ngtcp2_crypto_km **pckm, const uint8_t *secret,
|
||||
size_t secretlen,
|
||||
@@ -107,8 +108,8 @@ void ngtcp2_crypto_create_nonce(uint8_t *dest, const uint8_t *iv, size_t ivlen,
|
||||
* which has variable integer in its parameter.
|
||||
*/
|
||||
static size_t varint_paramlen(ngtcp2_transport_param_id id, uint64_t param) {
|
||||
size_t valuelen = ngtcp2_put_varint_len(param);
|
||||
return ngtcp2_put_varint_len(id) + ngtcp2_put_varint_len(valuelen) + valuelen;
|
||||
size_t valuelen = ngtcp2_put_uvarintlen(param);
|
||||
return ngtcp2_put_uvarintlen(id) + ngtcp2_put_uvarintlen(valuelen) + valuelen;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -117,9 +118,9 @@ static size_t varint_paramlen(ngtcp2_transport_param_id id, uint64_t param) {
|
||||
*/
|
||||
static uint8_t *write_varint_param(uint8_t *p, ngtcp2_transport_param_id id,
|
||||
uint64_t value) {
|
||||
p = ngtcp2_put_varint(p, id);
|
||||
p = ngtcp2_put_varint(p, ngtcp2_put_varint_len(value));
|
||||
return ngtcp2_put_varint(p, value);
|
||||
p = ngtcp2_put_uvarint(p, id);
|
||||
p = ngtcp2_put_uvarint(p, ngtcp2_put_uvarintlen(value));
|
||||
return ngtcp2_put_uvarint(p, value);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -128,7 +129,7 @@ static uint8_t *write_varint_param(uint8_t *p, ngtcp2_transport_param_id id,
|
||||
*/
|
||||
static size_t cid_paramlen(ngtcp2_transport_param_id id,
|
||||
const ngtcp2_cid *cid) {
|
||||
return ngtcp2_put_varint_len(id) + ngtcp2_put_varint_len(cid->datalen) +
|
||||
return ngtcp2_put_uvarintlen(id) + ngtcp2_put_uvarintlen(cid->datalen) +
|
||||
cid->datalen;
|
||||
}
|
||||
|
||||
@@ -141,8 +142,8 @@ static uint8_t *write_cid_param(uint8_t *p, ngtcp2_transport_param_id id,
|
||||
assert(cid->datalen == 0 || cid->datalen >= NGTCP2_MIN_CIDLEN);
|
||||
assert(cid->datalen <= NGTCP2_MAX_CIDLEN);
|
||||
|
||||
p = ngtcp2_put_varint(p, id);
|
||||
p = ngtcp2_put_varint(p, cid->datalen);
|
||||
p = ngtcp2_put_uvarint(p, id);
|
||||
p = ngtcp2_put_uvarint(p, cid->datalen);
|
||||
if (cid->datalen) {
|
||||
p = ngtcp2_cpymem(p, cid->data, cid->datalen);
|
||||
}
|
||||
@@ -151,52 +152,52 @@ static uint8_t *write_cid_param(uint8_t *p, ngtcp2_transport_param_id id,
|
||||
|
||||
static const uint8_t empty_address[16];
|
||||
|
||||
ngtcp2_ssize ngtcp2_encode_transport_params_versioned(
|
||||
uint8_t *dest, size_t destlen, ngtcp2_transport_params_type exttype,
|
||||
int transport_params_version, const ngtcp2_transport_params *params) {
|
||||
ngtcp2_ssize ngtcp2_transport_params_encode_versioned(
|
||||
uint8_t *dest, size_t destlen, int transport_params_version,
|
||||
const ngtcp2_transport_params *params) {
|
||||
uint8_t *p;
|
||||
size_t len = 0;
|
||||
/* For some reason, gcc 7.3.0 requires this initialization. */
|
||||
size_t preferred_addrlen = 0;
|
||||
size_t version_infolen = 0;
|
||||
(void)transport_params_version;
|
||||
const ngtcp2_sockaddr_in *sa_in;
|
||||
const ngtcp2_sockaddr_in6 *sa_in6;
|
||||
ngtcp2_transport_params paramsbuf;
|
||||
|
||||
switch (exttype) {
|
||||
case NGTCP2_TRANSPORT_PARAMS_TYPE_CLIENT_HELLO:
|
||||
break;
|
||||
case NGTCP2_TRANSPORT_PARAMS_TYPE_ENCRYPTED_EXTENSIONS:
|
||||
params = ngtcp2_transport_params_convert_to_latest(
|
||||
¶msbuf, transport_params_version, params);
|
||||
|
||||
if (params->original_dcid_present) {
|
||||
len +=
|
||||
cid_paramlen(NGTCP2_TRANSPORT_PARAM_ORIGINAL_DESTINATION_CONNECTION_ID,
|
||||
¶ms->original_dcid);
|
||||
|
||||
if (params->stateless_reset_token_present) {
|
||||
len +=
|
||||
ngtcp2_put_varint_len(NGTCP2_TRANSPORT_PARAM_STATELESS_RESET_TOKEN) +
|
||||
ngtcp2_put_varint_len(NGTCP2_STATELESS_RESET_TOKENLEN) +
|
||||
NGTCP2_STATELESS_RESET_TOKENLEN;
|
||||
}
|
||||
if (params->preferred_address_present) {
|
||||
assert(params->preferred_address.cid.datalen >= NGTCP2_MIN_CIDLEN);
|
||||
assert(params->preferred_address.cid.datalen <= NGTCP2_MAX_CIDLEN);
|
||||
preferred_addrlen = 4 /* ipv4Address */ + 2 /* ipv4Port */ +
|
||||
16 /* ipv6Address */ + 2 /* ipv6Port */
|
||||
+ 1 +
|
||||
params->preferred_address.cid.datalen /* CID */ +
|
||||
NGTCP2_STATELESS_RESET_TOKENLEN;
|
||||
len += ngtcp2_put_varint_len(NGTCP2_TRANSPORT_PARAM_PREFERRED_ADDRESS) +
|
||||
ngtcp2_put_varint_len(preferred_addrlen) + preferred_addrlen;
|
||||
}
|
||||
if (params->retry_scid_present) {
|
||||
len += cid_paramlen(NGTCP2_TRANSPORT_PARAM_RETRY_SOURCE_CONNECTION_ID,
|
||||
¶ms->retry_scid);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return NGTCP2_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
len += cid_paramlen(NGTCP2_TRANSPORT_PARAM_INITIAL_SOURCE_CONNECTION_ID,
|
||||
¶ms->initial_scid);
|
||||
if (params->stateless_reset_token_present) {
|
||||
len += ngtcp2_put_uvarintlen(NGTCP2_TRANSPORT_PARAM_STATELESS_RESET_TOKEN) +
|
||||
ngtcp2_put_uvarintlen(NGTCP2_STATELESS_RESET_TOKENLEN) +
|
||||
NGTCP2_STATELESS_RESET_TOKENLEN;
|
||||
}
|
||||
|
||||
if (params->preferred_addr_present) {
|
||||
assert(params->preferred_addr.cid.datalen >= NGTCP2_MIN_CIDLEN);
|
||||
assert(params->preferred_addr.cid.datalen <= NGTCP2_MAX_CIDLEN);
|
||||
preferred_addrlen = 4 /* ipv4Address */ + 2 /* ipv4Port */ +
|
||||
16 /* ipv6Address */ + 2 /* ipv6Port */
|
||||
+ 1 + params->preferred_addr.cid.datalen /* CID */ +
|
||||
NGTCP2_STATELESS_RESET_TOKENLEN;
|
||||
len += ngtcp2_put_uvarintlen(NGTCP2_TRANSPORT_PARAM_PREFERRED_ADDRESS) +
|
||||
ngtcp2_put_uvarintlen(preferred_addrlen) + preferred_addrlen;
|
||||
}
|
||||
if (params->retry_scid_present) {
|
||||
len += cid_paramlen(NGTCP2_TRANSPORT_PARAM_RETRY_SOURCE_CONNECTION_ID,
|
||||
¶ms->retry_scid);
|
||||
}
|
||||
|
||||
if (params->initial_scid_present) {
|
||||
len += cid_paramlen(NGTCP2_TRANSPORT_PARAM_INITIAL_SOURCE_CONNECTION_ID,
|
||||
¶ms->initial_scid);
|
||||
}
|
||||
|
||||
if (params->initial_max_stream_data_bidi_local) {
|
||||
len += varint_paramlen(
|
||||
@@ -235,8 +236,8 @@ ngtcp2_ssize ngtcp2_encode_transport_params_versioned(
|
||||
}
|
||||
if (params->disable_active_migration) {
|
||||
len +=
|
||||
ngtcp2_put_varint_len(NGTCP2_TRANSPORT_PARAM_DISABLE_ACTIVE_MIGRATION) +
|
||||
ngtcp2_put_varint_len(0);
|
||||
ngtcp2_put_uvarintlen(NGTCP2_TRANSPORT_PARAM_DISABLE_ACTIVE_MIGRATION) +
|
||||
ngtcp2_put_uvarintlen(0);
|
||||
}
|
||||
if (params->max_ack_delay != NGTCP2_DEFAULT_MAX_ACK_DELAY) {
|
||||
len += varint_paramlen(NGTCP2_TRANSPORT_PARAM_MAX_ACK_DELAY,
|
||||
@@ -257,14 +258,14 @@ ngtcp2_ssize ngtcp2_encode_transport_params_versioned(
|
||||
params->max_datagram_frame_size);
|
||||
}
|
||||
if (params->grease_quic_bit) {
|
||||
len += ngtcp2_put_varint_len(NGTCP2_TRANSPORT_PARAM_GREASE_QUIC_BIT) +
|
||||
ngtcp2_put_varint_len(0);
|
||||
len += ngtcp2_put_uvarintlen(NGTCP2_TRANSPORT_PARAM_GREASE_QUIC_BIT) +
|
||||
ngtcp2_put_uvarintlen(0);
|
||||
}
|
||||
if (params->version_info_present) {
|
||||
version_infolen = sizeof(uint32_t) + params->version_info.other_versionslen;
|
||||
len += ngtcp2_put_varint_len(
|
||||
NGTCP2_TRANSPORT_PARAM_VERSION_INFORMATION_DRAFT) +
|
||||
ngtcp2_put_varint_len(version_infolen) + version_infolen;
|
||||
version_infolen =
|
||||
sizeof(uint32_t) + params->version_info.available_versionslen;
|
||||
len += ngtcp2_put_uvarintlen(NGTCP2_TRANSPORT_PARAM_VERSION_INFORMATION) +
|
||||
ngtcp2_put_uvarintlen(version_infolen) + version_infolen;
|
||||
}
|
||||
|
||||
if (dest == NULL && destlen == 0) {
|
||||
@@ -277,58 +278,59 @@ ngtcp2_ssize ngtcp2_encode_transport_params_versioned(
|
||||
|
||||
p = dest;
|
||||
|
||||
if (exttype == NGTCP2_TRANSPORT_PARAMS_TYPE_ENCRYPTED_EXTENSIONS) {
|
||||
if (params->original_dcid_present) {
|
||||
p = write_cid_param(
|
||||
p, NGTCP2_TRANSPORT_PARAM_ORIGINAL_DESTINATION_CONNECTION_ID,
|
||||
¶ms->original_dcid);
|
||||
|
||||
if (params->stateless_reset_token_present) {
|
||||
p = ngtcp2_put_varint(p, NGTCP2_TRANSPORT_PARAM_STATELESS_RESET_TOKEN);
|
||||
p = ngtcp2_put_varint(p, sizeof(params->stateless_reset_token));
|
||||
p = ngtcp2_cpymem(p, params->stateless_reset_token,
|
||||
sizeof(params->stateless_reset_token));
|
||||
}
|
||||
if (params->preferred_address_present) {
|
||||
p = ngtcp2_put_varint(p, NGTCP2_TRANSPORT_PARAM_PREFERRED_ADDRESS);
|
||||
p = ngtcp2_put_varint(p, preferred_addrlen);
|
||||
|
||||
if (params->preferred_address.ipv4_present) {
|
||||
p = ngtcp2_cpymem(p, params->preferred_address.ipv4_addr,
|
||||
sizeof(params->preferred_address.ipv4_addr));
|
||||
p = ngtcp2_put_uint16be(p, params->preferred_address.ipv4_port);
|
||||
} else {
|
||||
p = ngtcp2_cpymem(p, empty_address,
|
||||
sizeof(params->preferred_address.ipv4_addr));
|
||||
p = ngtcp2_put_uint16be(p, 0);
|
||||
}
|
||||
|
||||
if (params->preferred_address.ipv6_present) {
|
||||
p = ngtcp2_cpymem(p, params->preferred_address.ipv6_addr,
|
||||
sizeof(params->preferred_address.ipv6_addr));
|
||||
p = ngtcp2_put_uint16be(p, params->preferred_address.ipv6_port);
|
||||
} else {
|
||||
p = ngtcp2_cpymem(p, empty_address,
|
||||
sizeof(params->preferred_address.ipv6_addr));
|
||||
p = ngtcp2_put_uint16be(p, 0);
|
||||
}
|
||||
|
||||
*p++ = (uint8_t)params->preferred_address.cid.datalen;
|
||||
if (params->preferred_address.cid.datalen) {
|
||||
p = ngtcp2_cpymem(p, params->preferred_address.cid.data,
|
||||
params->preferred_address.cid.datalen);
|
||||
}
|
||||
p = ngtcp2_cpymem(
|
||||
p, params->preferred_address.stateless_reset_token,
|
||||
sizeof(params->preferred_address.stateless_reset_token));
|
||||
}
|
||||
if (params->retry_scid_present) {
|
||||
p = write_cid_param(p, NGTCP2_TRANSPORT_PARAM_RETRY_SOURCE_CONNECTION_ID,
|
||||
¶ms->retry_scid);
|
||||
}
|
||||
}
|
||||
|
||||
p = write_cid_param(p, NGTCP2_TRANSPORT_PARAM_INITIAL_SOURCE_CONNECTION_ID,
|
||||
¶ms->initial_scid);
|
||||
if (params->stateless_reset_token_present) {
|
||||
p = ngtcp2_put_uvarint(p, NGTCP2_TRANSPORT_PARAM_STATELESS_RESET_TOKEN);
|
||||
p = ngtcp2_put_uvarint(p, sizeof(params->stateless_reset_token));
|
||||
p = ngtcp2_cpymem(p, params->stateless_reset_token,
|
||||
sizeof(params->stateless_reset_token));
|
||||
}
|
||||
|
||||
if (params->preferred_addr_present) {
|
||||
p = ngtcp2_put_uvarint(p, NGTCP2_TRANSPORT_PARAM_PREFERRED_ADDRESS);
|
||||
p = ngtcp2_put_uvarint(p, preferred_addrlen);
|
||||
|
||||
if (params->preferred_addr.ipv4_present) {
|
||||
sa_in = ¶ms->preferred_addr.ipv4;
|
||||
p = ngtcp2_cpymem(p, &sa_in->sin_addr, sizeof(sa_in->sin_addr));
|
||||
p = ngtcp2_put_uint16(p, sa_in->sin_port);
|
||||
} else {
|
||||
p = ngtcp2_cpymem(p, empty_address, sizeof(sa_in->sin_addr));
|
||||
p = ngtcp2_put_uint16(p, 0);
|
||||
}
|
||||
|
||||
if (params->preferred_addr.ipv6_present) {
|
||||
sa_in6 = ¶ms->preferred_addr.ipv6;
|
||||
p = ngtcp2_cpymem(p, &sa_in6->sin6_addr, sizeof(sa_in6->sin6_addr));
|
||||
p = ngtcp2_put_uint16(p, sa_in6->sin6_port);
|
||||
} else {
|
||||
p = ngtcp2_cpymem(p, empty_address, sizeof(sa_in6->sin6_addr));
|
||||
p = ngtcp2_put_uint16(p, 0);
|
||||
}
|
||||
|
||||
*p++ = (uint8_t)params->preferred_addr.cid.datalen;
|
||||
if (params->preferred_addr.cid.datalen) {
|
||||
p = ngtcp2_cpymem(p, params->preferred_addr.cid.data,
|
||||
params->preferred_addr.cid.datalen);
|
||||
}
|
||||
p = ngtcp2_cpymem(p, params->preferred_addr.stateless_reset_token,
|
||||
sizeof(params->preferred_addr.stateless_reset_token));
|
||||
}
|
||||
|
||||
if (params->retry_scid_present) {
|
||||
p = write_cid_param(p, NGTCP2_TRANSPORT_PARAM_RETRY_SOURCE_CONNECTION_ID,
|
||||
¶ms->retry_scid);
|
||||
}
|
||||
|
||||
if (params->initial_scid_present) {
|
||||
p = write_cid_param(p, NGTCP2_TRANSPORT_PARAM_INITIAL_SOURCE_CONNECTION_ID,
|
||||
¶ms->initial_scid);
|
||||
}
|
||||
|
||||
if (params->initial_max_stream_data_bidi_local) {
|
||||
p = write_varint_param(
|
||||
@@ -375,8 +377,8 @@ ngtcp2_ssize ngtcp2_encode_transport_params_versioned(
|
||||
}
|
||||
|
||||
if (params->disable_active_migration) {
|
||||
p = ngtcp2_put_varint(p, NGTCP2_TRANSPORT_PARAM_DISABLE_ACTIVE_MIGRATION);
|
||||
p = ngtcp2_put_varint(p, 0);
|
||||
p = ngtcp2_put_uvarint(p, NGTCP2_TRANSPORT_PARAM_DISABLE_ACTIVE_MIGRATION);
|
||||
p = ngtcp2_put_uvarint(p, 0);
|
||||
}
|
||||
|
||||
if (params->max_ack_delay != NGTCP2_DEFAULT_MAX_ACK_DELAY) {
|
||||
@@ -402,17 +404,17 @@ ngtcp2_ssize ngtcp2_encode_transport_params_versioned(
|
||||
}
|
||||
|
||||
if (params->grease_quic_bit) {
|
||||
p = ngtcp2_put_varint(p, NGTCP2_TRANSPORT_PARAM_GREASE_QUIC_BIT);
|
||||
p = ngtcp2_put_varint(p, 0);
|
||||
p = ngtcp2_put_uvarint(p, NGTCP2_TRANSPORT_PARAM_GREASE_QUIC_BIT);
|
||||
p = ngtcp2_put_uvarint(p, 0);
|
||||
}
|
||||
|
||||
if (params->version_info_present) {
|
||||
p = ngtcp2_put_varint(p, NGTCP2_TRANSPORT_PARAM_VERSION_INFORMATION_DRAFT);
|
||||
p = ngtcp2_put_varint(p, version_infolen);
|
||||
p = ngtcp2_put_uvarint(p, NGTCP2_TRANSPORT_PARAM_VERSION_INFORMATION);
|
||||
p = ngtcp2_put_uvarint(p, version_infolen);
|
||||
p = ngtcp2_put_uint32be(p, params->version_info.chosen_version);
|
||||
if (params->version_info.other_versionslen) {
|
||||
p = ngtcp2_cpymem(p, params->version_info.other_versions,
|
||||
params->version_info.other_versionslen);
|
||||
if (params->version_info.available_versionslen) {
|
||||
p = ngtcp2_cpymem(p, params->version_info.available_versions,
|
||||
params->version_info.available_versionslen);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -423,49 +425,46 @@ ngtcp2_ssize ngtcp2_encode_transport_params_versioned(
|
||||
|
||||
/*
|
||||
* decode_varint decodes a single varint from the buffer pointed by
|
||||
* |p| of length |end - p|. If it decodes an integer successfully, it
|
||||
* stores the integer in |*pdest| and returns 0. Otherwise it returns
|
||||
* -1.
|
||||
* |*pp| of length |end - *pp|. If it decodes an integer
|
||||
* successfully, it stores the integer in |*pdest|, increment |*pp| by
|
||||
* the number of bytes read from |*pp|, and returns 0. Otherwise it
|
||||
* returns -1.
|
||||
*/
|
||||
static ngtcp2_ssize decode_varint(uint64_t *pdest, const uint8_t *p,
|
||||
const uint8_t *end) {
|
||||
static int decode_varint(uint64_t *pdest, const uint8_t **pp,
|
||||
const uint8_t *end) {
|
||||
const uint8_t *p = *pp;
|
||||
size_t len;
|
||||
|
||||
if (p == end) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
len = ngtcp2_get_varint_len(p);
|
||||
len = ngtcp2_get_uvarintlen(p);
|
||||
if ((uint64_t)(end - p) < len) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*pdest = ngtcp2_get_varint(&len, p);
|
||||
*pp = ngtcp2_get_uvarint(pdest, p);
|
||||
|
||||
return (ngtcp2_ssize)len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* decode_varint_param decodes length prefixed value from the buffer
|
||||
* pointed by |p| of length |end - p|. The length and value are
|
||||
* pointed by |*pp| of length |end - *pp|. The length and value are
|
||||
* encoded in varint form. If it decodes a value successfully, it
|
||||
* stores the value in |*pdest| and returns 0. Otherwise it returns
|
||||
* -1.
|
||||
* stores the value in |*pdest|, increment |*pp| by the number of
|
||||
* bytes read from |*pp|, and returns 0. Otherwise it returns -1.
|
||||
*/
|
||||
static ngtcp2_ssize decode_varint_param(uint64_t *pdest, const uint8_t *p,
|
||||
const uint8_t *end) {
|
||||
const uint8_t *begin = p;
|
||||
ngtcp2_ssize nread;
|
||||
static int decode_varint_param(uint64_t *pdest, const uint8_t **pp,
|
||||
const uint8_t *end) {
|
||||
const uint8_t *p = *pp;
|
||||
uint64_t valuelen;
|
||||
size_t n;
|
||||
|
||||
nread = decode_varint(&valuelen, p, end);
|
||||
if (nread < 0) {
|
||||
if (decode_varint(&valuelen, &p, end) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
p += nread;
|
||||
|
||||
if (p == end) {
|
||||
return -1;
|
||||
}
|
||||
@@ -474,36 +473,35 @@ static ngtcp2_ssize decode_varint_param(uint64_t *pdest, const uint8_t *p,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ngtcp2_get_varint_len(p) != valuelen) {
|
||||
if (ngtcp2_get_uvarintlen(p) != valuelen) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*pdest = ngtcp2_get_varint(&n, p);
|
||||
*pp = ngtcp2_get_uvarint(pdest, p);
|
||||
|
||||
p += valuelen;
|
||||
|
||||
return (ngtcp2_ssize)(p - begin);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* decode_cid_param decodes length prefixed ngtcp2_cid from the buffer
|
||||
* pointed by |p| of length |end - p|. The length is encoded in
|
||||
* pointed by |*pp| of length |end - *pp|. The length is encoded in
|
||||
* varint form. If it decodes a value successfully, it stores the
|
||||
* value in |*pdest| and returns the number of bytes read. Otherwise
|
||||
* it returns -1.
|
||||
* value in |*pdest|, increment |*pp| by the number of read from
|
||||
* |*pp|, and returns the number of bytes read. Otherwise it returns
|
||||
* the one of the negative error code:
|
||||
*
|
||||
* NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM
|
||||
* Could not decode Connection ID.
|
||||
*/
|
||||
static ngtcp2_ssize decode_cid_param(ngtcp2_cid *pdest, const uint8_t *p,
|
||||
const uint8_t *end) {
|
||||
const uint8_t *begin = p;
|
||||
static int decode_cid_param(ngtcp2_cid *pdest, const uint8_t **pp,
|
||||
const uint8_t *end) {
|
||||
const uint8_t *p = *pp;
|
||||
uint64_t valuelen;
|
||||
ngtcp2_ssize nread = decode_varint(&valuelen, p, end);
|
||||
|
||||
if (nread < 0) {
|
||||
if (decode_varint(&valuelen, &p, end) != 0) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
|
||||
p += nread;
|
||||
|
||||
if ((valuelen != 0 && valuelen < NGTCP2_MIN_CIDLEN) ||
|
||||
valuelen > NGTCP2_MAX_CIDLEN || (size_t)(end - p) < valuelen) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
@@ -513,28 +511,35 @@ static ngtcp2_ssize decode_cid_param(ngtcp2_cid *pdest, const uint8_t *p,
|
||||
|
||||
p += valuelen;
|
||||
|
||||
return (ngtcp2_ssize)(p - begin);
|
||||
*pp = p;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ngtcp2_decode_transport_params_versioned(
|
||||
int transport_params_version, ngtcp2_transport_params *params,
|
||||
ngtcp2_transport_params_type exttype, const uint8_t *data, size_t datalen) {
|
||||
const uint8_t *p, *end;
|
||||
int ngtcp2_transport_params_decode_versioned(int transport_params_version,
|
||||
ngtcp2_transport_params *dest,
|
||||
const uint8_t *data,
|
||||
size_t datalen) {
|
||||
const uint8_t *p, *end, *lend;
|
||||
size_t len;
|
||||
uint64_t param_type;
|
||||
uint64_t valuelen;
|
||||
ngtcp2_ssize nread;
|
||||
int initial_scid_present = 0;
|
||||
int original_dcid_present = 0;
|
||||
size_t i;
|
||||
(void)transport_params_version;
|
||||
int rv;
|
||||
ngtcp2_sockaddr_in *sa_in;
|
||||
ngtcp2_sockaddr_in6 *sa_in6;
|
||||
uint32_t version;
|
||||
ngtcp2_transport_params *params, paramsbuf;
|
||||
|
||||
if (datalen == 0) {
|
||||
return NGTCP2_ERR_REQUIRED_TRANSPORT_PARAM;
|
||||
if (transport_params_version == NGTCP2_TRANSPORT_PARAMS_VERSION) {
|
||||
params = dest;
|
||||
} else {
|
||||
params = ¶msbuf;
|
||||
}
|
||||
|
||||
/* Set default values */
|
||||
memset(params, 0, sizeof(*params));
|
||||
params->original_dcid_present = 0;
|
||||
params->initial_scid_present = 0;
|
||||
params->initial_max_streams_bidi = 0;
|
||||
params->initial_max_streams_uni = 0;
|
||||
params->initial_max_stream_data_bidi_local = 0;
|
||||
@@ -543,7 +548,7 @@ int ngtcp2_decode_transport_params_versioned(
|
||||
params->max_udp_payload_size = NGTCP2_DEFAULT_MAX_RECV_UDP_PAYLOAD_SIZE;
|
||||
params->ack_delay_exponent = NGTCP2_DEFAULT_ACK_DELAY_EXPONENT;
|
||||
params->stateless_reset_token_present = 0;
|
||||
params->preferred_address_present = 0;
|
||||
params->preferred_addr_present = 0;
|
||||
params->disable_active_migration = 0;
|
||||
params->max_ack_delay = NGTCP2_DEFAULT_MAX_ACK_DELAY;
|
||||
params->max_idle_timeout = 0;
|
||||
@@ -560,87 +565,66 @@ int ngtcp2_decode_transport_params_versioned(
|
||||
end = data + datalen;
|
||||
|
||||
for (; (size_t)(end - p) >= 2;) {
|
||||
nread = decode_varint(¶m_type, p, end);
|
||||
if (nread < 0) {
|
||||
if (decode_varint(¶m_type, &p, end) != 0) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
p += nread;
|
||||
|
||||
switch (param_type) {
|
||||
case NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAM_DATA_BIDI_LOCAL:
|
||||
nread = decode_varint_param(¶ms->initial_max_stream_data_bidi_local,
|
||||
p, end);
|
||||
if (nread < 0) {
|
||||
if (decode_varint_param(¶ms->initial_max_stream_data_bidi_local, &p,
|
||||
end) != 0) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
p += nread;
|
||||
break;
|
||||
case NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAM_DATA_BIDI_REMOTE:
|
||||
nread = decode_varint_param(¶ms->initial_max_stream_data_bidi_remote,
|
||||
p, end);
|
||||
if (nread < 0) {
|
||||
if (decode_varint_param(¶ms->initial_max_stream_data_bidi_remote, &p,
|
||||
end) != 0) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
p += nread;
|
||||
break;
|
||||
case NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAM_DATA_UNI:
|
||||
nread = decode_varint_param(¶ms->initial_max_stream_data_uni, p, end);
|
||||
if (nread < 0) {
|
||||
if (decode_varint_param(¶ms->initial_max_stream_data_uni, &p, end) !=
|
||||
0) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
p += nread;
|
||||
break;
|
||||
case NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_DATA:
|
||||
nread = decode_varint_param(¶ms->initial_max_data, p, end);
|
||||
if (nread < 0) {
|
||||
if (decode_varint_param(¶ms->initial_max_data, &p, end) != 0) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
p += nread;
|
||||
break;
|
||||
case NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAMS_BIDI:
|
||||
nread = decode_varint_param(¶ms->initial_max_streams_bidi, p, end);
|
||||
if (nread < 0) {
|
||||
if (decode_varint_param(¶ms->initial_max_streams_bidi, &p, end) !=
|
||||
0) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
if (params->initial_max_streams_bidi > NGTCP2_MAX_STREAMS) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
p += nread;
|
||||
break;
|
||||
case NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAMS_UNI:
|
||||
nread = decode_varint_param(¶ms->initial_max_streams_uni, p, end);
|
||||
if (nread < 0) {
|
||||
if (decode_varint_param(¶ms->initial_max_streams_uni, &p, end) != 0) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
if (params->initial_max_streams_uni > NGTCP2_MAX_STREAMS) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
p += nread;
|
||||
break;
|
||||
case NGTCP2_TRANSPORT_PARAM_MAX_IDLE_TIMEOUT:
|
||||
nread = decode_varint_param(¶ms->max_idle_timeout, p, end);
|
||||
if (nread < 0) {
|
||||
if (decode_varint_param(¶ms->max_idle_timeout, &p, end) != 0) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
params->max_idle_timeout *= NGTCP2_MILLISECONDS;
|
||||
p += nread;
|
||||
break;
|
||||
case NGTCP2_TRANSPORT_PARAM_MAX_UDP_PAYLOAD_SIZE:
|
||||
nread = decode_varint_param(¶ms->max_udp_payload_size, p, end);
|
||||
if (nread < 0) {
|
||||
if (decode_varint_param(¶ms->max_udp_payload_size, &p, end) != 0) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
p += nread;
|
||||
break;
|
||||
case NGTCP2_TRANSPORT_PARAM_STATELESS_RESET_TOKEN:
|
||||
if (exttype != NGTCP2_TRANSPORT_PARAMS_TYPE_ENCRYPTED_EXTENSIONS) {
|
||||
if (decode_varint(&valuelen, &p, end) != 0) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
nread = decode_varint(&valuelen, p, end);
|
||||
if (nread < 0) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
p += nread;
|
||||
if ((size_t)valuelen != sizeof(params->stateless_reset_token)) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
@@ -648,28 +632,23 @@ int ngtcp2_decode_transport_params_versioned(
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
|
||||
memcpy(params->stateless_reset_token, p,
|
||||
sizeof(params->stateless_reset_token));
|
||||
p = ngtcp2_get_bytes(params->stateless_reset_token, p,
|
||||
sizeof(params->stateless_reset_token));
|
||||
params->stateless_reset_token_present = 1;
|
||||
|
||||
p += sizeof(params->stateless_reset_token);
|
||||
break;
|
||||
case NGTCP2_TRANSPORT_PARAM_ACK_DELAY_EXPONENT:
|
||||
nread = decode_varint_param(¶ms->ack_delay_exponent, p, end);
|
||||
if (nread < 0 || params->ack_delay_exponent > 20) {
|
||||
if (decode_varint_param(¶ms->ack_delay_exponent, &p, end) != 0) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
if (params->ack_delay_exponent > 20) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
p += nread;
|
||||
break;
|
||||
case NGTCP2_TRANSPORT_PARAM_PREFERRED_ADDRESS:
|
||||
if (exttype != NGTCP2_TRANSPORT_PARAMS_TYPE_ENCRYPTED_EXTENSIONS) {
|
||||
if (decode_varint(&valuelen, &p, end) != 0) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
nread = decode_varint(&valuelen, p, end);
|
||||
if (nread < 0) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
p += nread;
|
||||
if ((size_t)(end - p) < valuelen) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
@@ -680,143 +659,128 @@ int ngtcp2_decode_transport_params_versioned(
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
|
||||
memcpy(params->preferred_address.ipv4_addr, p,
|
||||
sizeof(params->preferred_address.ipv4_addr));
|
||||
p += sizeof(params->preferred_address.ipv4_addr);
|
||||
params->preferred_address.ipv4_port = ngtcp2_get_uint16(p);
|
||||
p += sizeof(uint16_t);
|
||||
sa_in = ¶ms->preferred_addr.ipv4;
|
||||
|
||||
if (params->preferred_address.ipv4_port ||
|
||||
memcmp(empty_address, params->preferred_address.ipv4_addr,
|
||||
sizeof(params->preferred_address.ipv4_addr)) != 0) {
|
||||
params->preferred_address.ipv4_present = 1;
|
||||
p = ngtcp2_get_bytes(&sa_in->sin_addr, p, sizeof(sa_in->sin_addr));
|
||||
p = ngtcp2_get_uint16be(&sa_in->sin_port, p);
|
||||
|
||||
if (sa_in->sin_port || memcmp(empty_address, &sa_in->sin_addr,
|
||||
sizeof(sa_in->sin_addr)) != 0) {
|
||||
sa_in->sin_family = NGTCP2_AF_INET;
|
||||
params->preferred_addr.ipv4_present = 1;
|
||||
}
|
||||
|
||||
memcpy(params->preferred_address.ipv6_addr, p,
|
||||
sizeof(params->preferred_address.ipv6_addr));
|
||||
p += sizeof(params->preferred_address.ipv6_addr);
|
||||
params->preferred_address.ipv6_port = ngtcp2_get_uint16(p);
|
||||
p += sizeof(uint16_t);
|
||||
sa_in6 = ¶ms->preferred_addr.ipv6;
|
||||
|
||||
if (params->preferred_address.ipv6_port ||
|
||||
memcmp(empty_address, params->preferred_address.ipv6_addr,
|
||||
sizeof(params->preferred_address.ipv6_addr)) != 0) {
|
||||
params->preferred_address.ipv6_present = 1;
|
||||
p = ngtcp2_get_bytes(&sa_in6->sin6_addr, p, sizeof(sa_in6->sin6_addr));
|
||||
p = ngtcp2_get_uint16be(&sa_in6->sin6_port, p);
|
||||
|
||||
if (sa_in6->sin6_port || memcmp(empty_address, &sa_in6->sin6_addr,
|
||||
sizeof(sa_in6->sin6_addr)) != 0) {
|
||||
sa_in6->sin6_family = NGTCP2_AF_INET6;
|
||||
params->preferred_addr.ipv6_present = 1;
|
||||
}
|
||||
|
||||
/* cid */
|
||||
params->preferred_address.cid.datalen = *p++;
|
||||
len += params->preferred_address.cid.datalen;
|
||||
params->preferred_addr.cid.datalen = *p++;
|
||||
len += params->preferred_addr.cid.datalen;
|
||||
if (valuelen != len ||
|
||||
params->preferred_address.cid.datalen > NGTCP2_MAX_CIDLEN ||
|
||||
params->preferred_address.cid.datalen < NGTCP2_MIN_CIDLEN) {
|
||||
params->preferred_addr.cid.datalen > NGTCP2_MAX_CIDLEN ||
|
||||
params->preferred_addr.cid.datalen < NGTCP2_MIN_CIDLEN) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
if (params->preferred_address.cid.datalen) {
|
||||
memcpy(params->preferred_address.cid.data, p,
|
||||
params->preferred_address.cid.datalen);
|
||||
p += params->preferred_address.cid.datalen;
|
||||
if (params->preferred_addr.cid.datalen) {
|
||||
p = ngtcp2_get_bytes(params->preferred_addr.cid.data, p,
|
||||
params->preferred_addr.cid.datalen);
|
||||
}
|
||||
|
||||
/* stateless reset token */
|
||||
memcpy(params->preferred_address.stateless_reset_token, p,
|
||||
sizeof(params->preferred_address.stateless_reset_token));
|
||||
p += sizeof(params->preferred_address.stateless_reset_token);
|
||||
params->preferred_address_present = 1;
|
||||
p = ngtcp2_get_bytes(
|
||||
params->preferred_addr.stateless_reset_token, p,
|
||||
sizeof(params->preferred_addr.stateless_reset_token));
|
||||
params->preferred_addr_present = 1;
|
||||
break;
|
||||
case NGTCP2_TRANSPORT_PARAM_DISABLE_ACTIVE_MIGRATION:
|
||||
nread = decode_varint(&valuelen, p, end);
|
||||
if (nread < 0 || valuelen != 0) {
|
||||
if (decode_varint(&valuelen, &p, end) != 0) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
if (valuelen != 0) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
p += nread;
|
||||
params->disable_active_migration = 1;
|
||||
break;
|
||||
case NGTCP2_TRANSPORT_PARAM_ORIGINAL_DESTINATION_CONNECTION_ID:
|
||||
if (exttype != NGTCP2_TRANSPORT_PARAMS_TYPE_ENCRYPTED_EXTENSIONS) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
rv = decode_cid_param(¶ms->original_dcid, &p, end);
|
||||
if (rv != 0) {
|
||||
return rv;
|
||||
}
|
||||
nread = decode_cid_param(¶ms->original_dcid, p, end);
|
||||
if (nread < 0) {
|
||||
return (int)nread;
|
||||
}
|
||||
original_dcid_present = 1;
|
||||
p += nread;
|
||||
params->original_dcid_present = 1;
|
||||
break;
|
||||
case NGTCP2_TRANSPORT_PARAM_RETRY_SOURCE_CONNECTION_ID:
|
||||
if (exttype != NGTCP2_TRANSPORT_PARAMS_TYPE_ENCRYPTED_EXTENSIONS) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
nread = decode_cid_param(¶ms->retry_scid, p, end);
|
||||
if (nread < 0) {
|
||||
return (int)nread;
|
||||
rv = decode_cid_param(¶ms->retry_scid, &p, end);
|
||||
if (rv != 0) {
|
||||
return rv;
|
||||
}
|
||||
params->retry_scid_present = 1;
|
||||
p += nread;
|
||||
break;
|
||||
case NGTCP2_TRANSPORT_PARAM_INITIAL_SOURCE_CONNECTION_ID:
|
||||
nread = decode_cid_param(¶ms->initial_scid, p, end);
|
||||
if (nread < 0) {
|
||||
return (int)nread;
|
||||
rv = decode_cid_param(¶ms->initial_scid, &p, end);
|
||||
if (rv != 0) {
|
||||
return rv;
|
||||
}
|
||||
initial_scid_present = 1;
|
||||
p += nread;
|
||||
params->initial_scid_present = 1;
|
||||
break;
|
||||
case NGTCP2_TRANSPORT_PARAM_MAX_ACK_DELAY:
|
||||
nread = decode_varint_param(¶ms->max_ack_delay, p, end);
|
||||
if (nread < 0 || params->max_ack_delay >= 16384) {
|
||||
if (decode_varint_param(¶ms->max_ack_delay, &p, end) != 0) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
if (params->max_ack_delay >= 16384) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
params->max_ack_delay *= NGTCP2_MILLISECONDS;
|
||||
p += nread;
|
||||
break;
|
||||
case NGTCP2_TRANSPORT_PARAM_ACTIVE_CONNECTION_ID_LIMIT:
|
||||
nread = decode_varint_param(¶ms->active_connection_id_limit, p, end);
|
||||
if (nread < 0) {
|
||||
if (decode_varint_param(¶ms->active_connection_id_limit, &p, end) !=
|
||||
0) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
p += nread;
|
||||
break;
|
||||
case NGTCP2_TRANSPORT_PARAM_MAX_DATAGRAM_FRAME_SIZE:
|
||||
nread = decode_varint_param(¶ms->max_datagram_frame_size, p, end);
|
||||
if (nread < 0) {
|
||||
if (decode_varint_param(¶ms->max_datagram_frame_size, &p, end) != 0) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
p += nread;
|
||||
break;
|
||||
case NGTCP2_TRANSPORT_PARAM_GREASE_QUIC_BIT:
|
||||
nread = decode_varint(&valuelen, p, end);
|
||||
if (nread < 0 || valuelen != 0) {
|
||||
if (decode_varint(&valuelen, &p, end) != 0) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
if (valuelen != 0) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
p += nread;
|
||||
params->grease_quic_bit = 1;
|
||||
break;
|
||||
case NGTCP2_TRANSPORT_PARAM_VERSION_INFORMATION_DRAFT:
|
||||
nread = decode_varint(&valuelen, p, end);
|
||||
if (nread < 0) {
|
||||
case NGTCP2_TRANSPORT_PARAM_VERSION_INFORMATION:
|
||||
if (decode_varint(&valuelen, &p, end) != 0) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
p += nread;
|
||||
if ((size_t)(end - p) < valuelen) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
if (valuelen < sizeof(uint32_t) || (valuelen & 0x3)) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
params->version_info.chosen_version = ngtcp2_get_uint32(p);
|
||||
p = ngtcp2_get_uint32(¶ms->version_info.chosen_version, p);
|
||||
if (params->version_info.chosen_version == 0) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
p += sizeof(uint32_t);
|
||||
if (valuelen > sizeof(uint32_t)) {
|
||||
params->version_info.other_versions = (uint8_t *)p;
|
||||
params->version_info.other_versionslen =
|
||||
params->version_info.available_versions = (uint8_t *)p;
|
||||
params->version_info.available_versionslen =
|
||||
(size_t)valuelen - sizeof(uint32_t);
|
||||
|
||||
for (i = sizeof(uint32_t); i < valuelen;
|
||||
i += sizeof(uint32_t), p += sizeof(uint32_t)) {
|
||||
if (ngtcp2_get_uint32(p) == 0) {
|
||||
for (lend = p + (valuelen - sizeof(uint32_t)); p != lend;) {
|
||||
p = ngtcp2_get_uint32(&version, p);
|
||||
if (version == 0) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
}
|
||||
@@ -825,11 +789,9 @@ int ngtcp2_decode_transport_params_versioned(
|
||||
break;
|
||||
default:
|
||||
/* Ignore unknown parameter */
|
||||
nread = decode_varint(&valuelen, p, end);
|
||||
if (nread < 0) {
|
||||
if (decode_varint(&valuelen, &p, end) != 0) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
p += nread;
|
||||
if ((size_t)(end - p) < valuelen) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
@@ -842,10 +804,9 @@ int ngtcp2_decode_transport_params_versioned(
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
|
||||
if (!initial_scid_present ||
|
||||
(exttype == NGTCP2_TRANSPORT_PARAMS_TYPE_ENCRYPTED_EXTENSIONS &&
|
||||
!original_dcid_present)) {
|
||||
return NGTCP2_ERR_REQUIRED_TRANSPORT_PARAM;
|
||||
if (transport_params_version != NGTCP2_TRANSPORT_PARAMS_VERSION) {
|
||||
ngtcp2_transport_params_convert_to_old(transport_params_version, dest,
|
||||
params);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -859,7 +820,7 @@ static int transport_params_copy_new(ngtcp2_transport_params **pdest,
|
||||
uint8_t *p;
|
||||
|
||||
if (src->version_info_present) {
|
||||
len += src->version_info.other_versionslen;
|
||||
len += src->version_info.available_versionslen;
|
||||
}
|
||||
|
||||
dest = ngtcp2_mem_malloc(mem, len);
|
||||
@@ -869,11 +830,11 @@ static int transport_params_copy_new(ngtcp2_transport_params **pdest,
|
||||
|
||||
*dest = *src;
|
||||
|
||||
if (src->version_info_present && src->version_info.other_versionslen) {
|
||||
if (src->version_info_present && src->version_info.available_versionslen) {
|
||||
p = (uint8_t *)dest + sizeof(*dest);
|
||||
memcpy(p, src->version_info.other_versions,
|
||||
src->version_info.other_versionslen);
|
||||
dest->version_info.other_versions = p;
|
||||
memcpy(p, src->version_info.available_versions,
|
||||
src->version_info.available_versionslen);
|
||||
dest->version_info.available_versions = p;
|
||||
}
|
||||
|
||||
*pdest = dest;
|
||||
@@ -881,14 +842,13 @@ static int transport_params_copy_new(ngtcp2_transport_params **pdest,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ngtcp2_decode_transport_params_new(ngtcp2_transport_params **pparams,
|
||||
ngtcp2_transport_params_type exttype,
|
||||
int ngtcp2_transport_params_decode_new(ngtcp2_transport_params **pparams,
|
||||
const uint8_t *data, size_t datalen,
|
||||
const ngtcp2_mem *mem) {
|
||||
int rv;
|
||||
ngtcp2_transport_params params;
|
||||
|
||||
rv = ngtcp2_decode_transport_params(¶ms, exttype, data, datalen);
|
||||
rv = ngtcp2_transport_params_decode(¶ms, data, datalen);
|
||||
if (rv < 0) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
+24
-24
@@ -43,30 +43,30 @@
|
||||
|
||||
/* ngtcp2_transport_param_id is the registry of QUIC transport
|
||||
parameter ID. */
|
||||
typedef enum ngtcp2_transport_param_id {
|
||||
NGTCP2_TRANSPORT_PARAM_ORIGINAL_DESTINATION_CONNECTION_ID = 0x0000,
|
||||
NGTCP2_TRANSPORT_PARAM_MAX_IDLE_TIMEOUT = 0x0001,
|
||||
NGTCP2_TRANSPORT_PARAM_STATELESS_RESET_TOKEN = 0x0002,
|
||||
NGTCP2_TRANSPORT_PARAM_MAX_UDP_PAYLOAD_SIZE = 0x0003,
|
||||
NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_DATA = 0x0004,
|
||||
NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAM_DATA_BIDI_LOCAL = 0x0005,
|
||||
NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAM_DATA_BIDI_REMOTE = 0x0006,
|
||||
NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAM_DATA_UNI = 0x0007,
|
||||
NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAMS_BIDI = 0x0008,
|
||||
NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAMS_UNI = 0x0009,
|
||||
NGTCP2_TRANSPORT_PARAM_ACK_DELAY_EXPONENT = 0x000a,
|
||||
NGTCP2_TRANSPORT_PARAM_MAX_ACK_DELAY = 0x000b,
|
||||
NGTCP2_TRANSPORT_PARAM_DISABLE_ACTIVE_MIGRATION = 0x000c,
|
||||
NGTCP2_TRANSPORT_PARAM_PREFERRED_ADDRESS = 0x000d,
|
||||
NGTCP2_TRANSPORT_PARAM_ACTIVE_CONNECTION_ID_LIMIT = 0x000e,
|
||||
NGTCP2_TRANSPORT_PARAM_INITIAL_SOURCE_CONNECTION_ID = 0x000f,
|
||||
NGTCP2_TRANSPORT_PARAM_RETRY_SOURCE_CONNECTION_ID = 0x0010,
|
||||
/* https://datatracker.ietf.org/doc/html/rfc9221 */
|
||||
NGTCP2_TRANSPORT_PARAM_MAX_DATAGRAM_FRAME_SIZE = 0x0020,
|
||||
NGTCP2_TRANSPORT_PARAM_GREASE_QUIC_BIT = 0x2ab2,
|
||||
/* https://quicwg.org/quic-v2/draft-ietf-quic-v2.html */
|
||||
NGTCP2_TRANSPORT_PARAM_VERSION_INFORMATION_DRAFT = 0xff73db,
|
||||
} ngtcp2_transport_param_id;
|
||||
typedef uint64_t ngtcp2_transport_param_id;
|
||||
|
||||
#define NGTCP2_TRANSPORT_PARAM_ORIGINAL_DESTINATION_CONNECTION_ID 0x00
|
||||
#define NGTCP2_TRANSPORT_PARAM_MAX_IDLE_TIMEOUT 0x01
|
||||
#define NGTCP2_TRANSPORT_PARAM_STATELESS_RESET_TOKEN 0x02
|
||||
#define NGTCP2_TRANSPORT_PARAM_MAX_UDP_PAYLOAD_SIZE 0x03
|
||||
#define NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_DATA 0x04
|
||||
#define NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAM_DATA_BIDI_LOCAL 0x05
|
||||
#define NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAM_DATA_BIDI_REMOTE 0x06
|
||||
#define NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAM_DATA_UNI 0x07
|
||||
#define NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAMS_BIDI 0x08
|
||||
#define NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAMS_UNI 0x09
|
||||
#define NGTCP2_TRANSPORT_PARAM_ACK_DELAY_EXPONENT 0x0a
|
||||
#define NGTCP2_TRANSPORT_PARAM_MAX_ACK_DELAY 0x0b
|
||||
#define NGTCP2_TRANSPORT_PARAM_DISABLE_ACTIVE_MIGRATION 0x0c
|
||||
#define NGTCP2_TRANSPORT_PARAM_PREFERRED_ADDRESS 0x0d
|
||||
#define NGTCP2_TRANSPORT_PARAM_ACTIVE_CONNECTION_ID_LIMIT 0x0e
|
||||
#define NGTCP2_TRANSPORT_PARAM_INITIAL_SOURCE_CONNECTION_ID 0x0f
|
||||
#define NGTCP2_TRANSPORT_PARAM_RETRY_SOURCE_CONNECTION_ID 0x10
|
||||
/* https://datatracker.ietf.org/doc/html/rfc9221 */
|
||||
#define NGTCP2_TRANSPORT_PARAM_MAX_DATAGRAM_FRAME_SIZE 0x20
|
||||
#define NGTCP2_TRANSPORT_PARAM_GREASE_QUIC_BIT 0x2ab2
|
||||
/* https://datatracker.ietf.org/doc/html/rfc9368 */
|
||||
#define NGTCP2_TRANSPORT_PARAM_VERSION_INFORMATION 0x11
|
||||
|
||||
/* NGTCP2_CRYPTO_KM_FLAG_NONE indicates that no flag is set. */
|
||||
#define NGTCP2_CRYPTO_KM_FLAG_NONE 0x00u
|
||||
|
||||
Vendored
+4
-1
@@ -137,6 +137,9 @@ uint64_t ngtcp2_err_infer_quic_transport_error_code(int liberr) {
|
||||
case NGTCP2_ERR_INVALID_ARGUMENT:
|
||||
case NGTCP2_ERR_NOMEM:
|
||||
case NGTCP2_ERR_CALLBACK_FAILURE:
|
||||
case NGTCP2_ERR_HANDSHAKE_TIMEOUT:
|
||||
case NGTCP2_ERR_PKT_NUM_EXHAUSTED:
|
||||
case NGTCP2_ERR_INTERNAL:
|
||||
return NGTCP2_INTERNAL_ERROR;
|
||||
case NGTCP2_ERR_STREAM_STATE:
|
||||
return NGTCP2_STREAM_STATE_ERROR;
|
||||
@@ -147,7 +150,7 @@ uint64_t ngtcp2_err_infer_quic_transport_error_code(int liberr) {
|
||||
case NGTCP2_ERR_NO_VIABLE_PATH:
|
||||
return NGTCP2_NO_VIABLE_PATH;
|
||||
case NGTCP2_ERR_VERSION_NEGOTIATION_FAILURE:
|
||||
return NGTCP2_VERSION_NEGOTIATION_ERROR_DRAFT;
|
||||
return NGTCP2_VERSION_NEGOTIATION_ERROR;
|
||||
default:
|
||||
return NGTCP2_PROTOCOL_VIOLATION;
|
||||
}
|
||||
|
||||
+220
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
* ngtcp2
|
||||
*
|
||||
* Copyright (c) 2023 ngtcp2 contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#include "ngtcp2_frame_chain.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
ngtcp2_objalloc_def(frame_chain, ngtcp2_frame_chain, oplent);
|
||||
|
||||
int ngtcp2_frame_chain_new(ngtcp2_frame_chain **pfrc, const ngtcp2_mem *mem) {
|
||||
*pfrc = ngtcp2_mem_malloc(mem, sizeof(ngtcp2_frame_chain));
|
||||
if (*pfrc == NULL) {
|
||||
return NGTCP2_ERR_NOMEM;
|
||||
}
|
||||
|
||||
ngtcp2_frame_chain_init(*pfrc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ngtcp2_frame_chain_objalloc_new(ngtcp2_frame_chain **pfrc,
|
||||
ngtcp2_objalloc *objalloc) {
|
||||
*pfrc = ngtcp2_objalloc_frame_chain_get(objalloc);
|
||||
if (*pfrc == NULL) {
|
||||
return NGTCP2_ERR_NOMEM;
|
||||
}
|
||||
|
||||
ngtcp2_frame_chain_init(*pfrc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ngtcp2_frame_chain_extralen_new(ngtcp2_frame_chain **pfrc, size_t extralen,
|
||||
const ngtcp2_mem *mem) {
|
||||
*pfrc = ngtcp2_mem_malloc(mem, sizeof(ngtcp2_frame_chain) + extralen);
|
||||
if (*pfrc == NULL) {
|
||||
return NGTCP2_ERR_NOMEM;
|
||||
}
|
||||
|
||||
ngtcp2_frame_chain_init(*pfrc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ngtcp2_frame_chain_stream_datacnt_objalloc_new(ngtcp2_frame_chain **pfrc,
|
||||
size_t datacnt,
|
||||
ngtcp2_objalloc *objalloc,
|
||||
const ngtcp2_mem *mem) {
|
||||
size_t need, avail = sizeof(ngtcp2_frame) - sizeof(ngtcp2_stream);
|
||||
|
||||
if (datacnt > 1) {
|
||||
need = sizeof(ngtcp2_vec) * (datacnt - 1);
|
||||
|
||||
if (need > avail) {
|
||||
return ngtcp2_frame_chain_extralen_new(pfrc, need - avail, mem);
|
||||
}
|
||||
}
|
||||
|
||||
return ngtcp2_frame_chain_objalloc_new(pfrc, objalloc);
|
||||
}
|
||||
|
||||
int ngtcp2_frame_chain_new_token_objalloc_new(ngtcp2_frame_chain **pfrc,
|
||||
const uint8_t *token,
|
||||
size_t tokenlen,
|
||||
ngtcp2_objalloc *objalloc,
|
||||
const ngtcp2_mem *mem) {
|
||||
size_t avail = sizeof(ngtcp2_frame) - sizeof(ngtcp2_new_token);
|
||||
int rv;
|
||||
uint8_t *p;
|
||||
ngtcp2_frame *fr;
|
||||
|
||||
if (tokenlen > avail) {
|
||||
rv = ngtcp2_frame_chain_extralen_new(pfrc, tokenlen - avail, mem);
|
||||
} else {
|
||||
rv = ngtcp2_frame_chain_objalloc_new(pfrc, objalloc);
|
||||
}
|
||||
if (rv != 0) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
fr = &(*pfrc)->fr;
|
||||
fr->type = NGTCP2_FRAME_NEW_TOKEN;
|
||||
|
||||
p = (uint8_t *)fr + sizeof(ngtcp2_new_token);
|
||||
memcpy(p, token, tokenlen);
|
||||
|
||||
fr->new_token.token = p;
|
||||
fr->new_token.tokenlen = tokenlen;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ngtcp2_frame_chain_del(ngtcp2_frame_chain *frc, const ngtcp2_mem *mem) {
|
||||
ngtcp2_frame_chain_binder *binder;
|
||||
|
||||
if (frc == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
binder = frc->binder;
|
||||
if (binder && --binder->refcount == 0) {
|
||||
ngtcp2_mem_free(mem, binder);
|
||||
}
|
||||
|
||||
ngtcp2_mem_free(mem, frc);
|
||||
}
|
||||
|
||||
void ngtcp2_frame_chain_objalloc_del(ngtcp2_frame_chain *frc,
|
||||
ngtcp2_objalloc *objalloc,
|
||||
const ngtcp2_mem *mem) {
|
||||
ngtcp2_frame_chain_binder *binder;
|
||||
|
||||
if (frc == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (frc->fr.type) {
|
||||
case NGTCP2_FRAME_CRYPTO:
|
||||
case NGTCP2_FRAME_STREAM:
|
||||
if (frc->fr.stream.datacnt &&
|
||||
sizeof(ngtcp2_vec) * (frc->fr.stream.datacnt - 1) >
|
||||
sizeof(ngtcp2_frame) - sizeof(ngtcp2_stream)) {
|
||||
ngtcp2_frame_chain_del(frc, mem);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
case NGTCP2_FRAME_NEW_TOKEN:
|
||||
if (frc->fr.new_token.tokenlen >
|
||||
sizeof(ngtcp2_frame) - sizeof(ngtcp2_new_token)) {
|
||||
ngtcp2_frame_chain_del(frc, mem);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
binder = frc->binder;
|
||||
if (binder && --binder->refcount == 0) {
|
||||
ngtcp2_mem_free(mem, binder);
|
||||
}
|
||||
|
||||
frc->binder = NULL;
|
||||
|
||||
ngtcp2_objalloc_frame_chain_release(objalloc, frc);
|
||||
}
|
||||
|
||||
void ngtcp2_frame_chain_init(ngtcp2_frame_chain *frc) {
|
||||
frc->next = NULL;
|
||||
frc->binder = NULL;
|
||||
}
|
||||
|
||||
void ngtcp2_frame_chain_list_objalloc_del(ngtcp2_frame_chain *frc,
|
||||
ngtcp2_objalloc *objalloc,
|
||||
const ngtcp2_mem *mem) {
|
||||
ngtcp2_frame_chain *next;
|
||||
|
||||
for (; frc; frc = next) {
|
||||
next = frc->next;
|
||||
|
||||
ngtcp2_frame_chain_objalloc_del(frc, objalloc, mem);
|
||||
}
|
||||
}
|
||||
|
||||
int ngtcp2_frame_chain_binder_new(ngtcp2_frame_chain_binder **pbinder,
|
||||
const ngtcp2_mem *mem) {
|
||||
*pbinder = ngtcp2_mem_calloc(mem, 1, sizeof(ngtcp2_frame_chain_binder));
|
||||
if (*pbinder == NULL) {
|
||||
return NGTCP2_ERR_NOMEM;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ngtcp2_bind_frame_chains(ngtcp2_frame_chain *a, ngtcp2_frame_chain *b,
|
||||
const ngtcp2_mem *mem) {
|
||||
ngtcp2_frame_chain_binder *binder;
|
||||
int rv;
|
||||
|
||||
assert(b->binder == NULL);
|
||||
|
||||
if (a->binder == NULL) {
|
||||
rv = ngtcp2_frame_chain_binder_new(&binder, mem);
|
||||
if (rv != 0) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
a->binder = binder;
|
||||
++a->binder->refcount;
|
||||
}
|
||||
|
||||
b->binder = a->binder;
|
||||
++b->binder->refcount;
|
||||
|
||||
return 0;
|
||||
}
|
||||
+171
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
* ngtcp2
|
||||
*
|
||||
* Copyright (c) 2023 ngtcp2 contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef NGTCP2_FRAME_CHAIN_H
|
||||
#define NGTCP2_FRAME_CHAIN_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
||||
#include <ngtcp2/ngtcp2.h>
|
||||
|
||||
#include "ngtcp2_pkt.h"
|
||||
#include "ngtcp2_objalloc.h"
|
||||
|
||||
/* NGTCP2_FRAME_CHAIN_BINDER_FLAG_NONE indicates that no flag is
|
||||
set. */
|
||||
#define NGTCP2_FRAME_CHAIN_BINDER_FLAG_NONE 0x00u
|
||||
/* NGTCP2_FRAME_CHAIN_BINDER_FLAG_ACK indicates that an information
|
||||
which a frame carries has been acknowledged. */
|
||||
#define NGTCP2_FRAME_CHAIN_BINDER_FLAG_ACK 0x01u
|
||||
|
||||
/*
|
||||
* ngtcp2_frame_chain_binder binds 2 or more of ngtcp2_frame_chain to
|
||||
* share the acknowledgement state. In general, all
|
||||
* ngtcp2_frame_chains bound to the same binder must have the same
|
||||
* information.
|
||||
*/
|
||||
typedef struct ngtcp2_frame_chain_binder {
|
||||
size_t refcount;
|
||||
/* flags is bitwise OR of zero or more of
|
||||
NGTCP2_FRAME_CHAIN_BINDER_FLAG_*. */
|
||||
uint32_t flags;
|
||||
} ngtcp2_frame_chain_binder;
|
||||
|
||||
int ngtcp2_frame_chain_binder_new(ngtcp2_frame_chain_binder **pbinder,
|
||||
const ngtcp2_mem *mem);
|
||||
|
||||
typedef struct ngtcp2_frame_chain ngtcp2_frame_chain;
|
||||
|
||||
/*
|
||||
* ngtcp2_frame_chain chains frames in a single packet.
|
||||
*/
|
||||
struct ngtcp2_frame_chain {
|
||||
union {
|
||||
struct {
|
||||
ngtcp2_frame_chain *next;
|
||||
ngtcp2_frame_chain_binder *binder;
|
||||
ngtcp2_frame fr;
|
||||
};
|
||||
|
||||
ngtcp2_opl_entry oplent;
|
||||
};
|
||||
};
|
||||
|
||||
ngtcp2_objalloc_decl(frame_chain, ngtcp2_frame_chain, oplent);
|
||||
|
||||
/*
|
||||
* ngtcp2_bind_frame_chains binds two frame chains |a| and |b| using
|
||||
* new or existing ngtcp2_frame_chain_binder. |a| might have non-NULL
|
||||
* a->binder. |b| must not have non-NULL b->binder.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGTCP2_ERR_NOMEM
|
||||
* Out of memory
|
||||
*/
|
||||
int ngtcp2_bind_frame_chains(ngtcp2_frame_chain *a, ngtcp2_frame_chain *b,
|
||||
const ngtcp2_mem *mem);
|
||||
|
||||
/* NGTCP2_MAX_STREAM_DATACNT is the maximum number of ngtcp2_vec that
|
||||
a ngtcp2_stream can include. */
|
||||
#define NGTCP2_MAX_STREAM_DATACNT 256
|
||||
|
||||
/*
|
||||
* ngtcp2_frame_chain_new allocates ngtcp2_frame_chain object and
|
||||
* assigns its pointer to |*pfrc|.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGTCP2_ERR_NOMEM
|
||||
* Out of memory.
|
||||
*/
|
||||
int ngtcp2_frame_chain_new(ngtcp2_frame_chain **pfrc, const ngtcp2_mem *mem);
|
||||
|
||||
/*
|
||||
* ngtcp2_frame_chain_objalloc_new behaves like
|
||||
* ngtcp2_frame_chain_new, but it uses |objalloc| to allocate the object.
|
||||
*/
|
||||
int ngtcp2_frame_chain_objalloc_new(ngtcp2_frame_chain **pfrc,
|
||||
ngtcp2_objalloc *objalloc);
|
||||
|
||||
/*
|
||||
* ngtcp2_frame_chain_extralen_new works like ngtcp2_frame_chain_new,
|
||||
* but it allocates extra memory |extralen| in order to extend
|
||||
* ngtcp2_frame.
|
||||
*/
|
||||
int ngtcp2_frame_chain_extralen_new(ngtcp2_frame_chain **pfrc, size_t extralen,
|
||||
const ngtcp2_mem *mem);
|
||||
|
||||
/*
|
||||
* ngtcp2_frame_chain_stream_datacnt_objalloc_new works like
|
||||
* ngtcp2_frame_chain_new, but it allocates enough data to store
|
||||
* additional |datacnt| - 1 ngtcp2_vec object after ngtcp2_stream
|
||||
* object. If no additional space is required,
|
||||
* ngtcp2_frame_chain_objalloc_new is called internally.
|
||||
*/
|
||||
int ngtcp2_frame_chain_stream_datacnt_objalloc_new(ngtcp2_frame_chain **pfrc,
|
||||
size_t datacnt,
|
||||
ngtcp2_objalloc *objalloc,
|
||||
const ngtcp2_mem *mem);
|
||||
|
||||
int ngtcp2_frame_chain_new_token_objalloc_new(ngtcp2_frame_chain **pfrc,
|
||||
const uint8_t *token,
|
||||
size_t tokenlen,
|
||||
ngtcp2_objalloc *objalloc,
|
||||
const ngtcp2_mem *mem);
|
||||
|
||||
/*
|
||||
* ngtcp2_frame_chain_del deallocates |frc|. It also deallocates the
|
||||
* memory pointed by |frc|.
|
||||
*/
|
||||
void ngtcp2_frame_chain_del(ngtcp2_frame_chain *frc, const ngtcp2_mem *mem);
|
||||
|
||||
/*
|
||||
* ngtcp2_frame_chain_objalloc_del adds |frc| to |objalloc| for reuse.
|
||||
* It might just delete |frc| depending on the frame type and the size
|
||||
* of |frc|.
|
||||
*/
|
||||
void ngtcp2_frame_chain_objalloc_del(ngtcp2_frame_chain *frc,
|
||||
ngtcp2_objalloc *objalloc,
|
||||
const ngtcp2_mem *mem);
|
||||
|
||||
/*
|
||||
* ngtcp2_frame_chain_init initializes |frc|.
|
||||
*/
|
||||
void ngtcp2_frame_chain_init(ngtcp2_frame_chain *frc);
|
||||
|
||||
/*
|
||||
* ngtcp2_frame_chain_list_objalloc_del adds all ngtcp2_frame_chain
|
||||
* linked from |frc| to |objalloc| for reuse. Depending on the frame type
|
||||
* and its size, ngtcp2_frame_chain might be deleted instead.
|
||||
*/
|
||||
void ngtcp2_frame_chain_list_objalloc_del(ngtcp2_frame_chain *frc,
|
||||
ngtcp2_objalloc *objalloc,
|
||||
const ngtcp2_mem *mem);
|
||||
|
||||
#endif /* NGTCP2_FRAME_CHAIN_H */
|
||||
Vendored
+21
-17
@@ -35,6 +35,8 @@
|
||||
|
||||
static ngtcp2_ksl_blk null_blk = {{{NULL, NULL, 0, 0, {0}}}};
|
||||
|
||||
ngtcp2_objalloc_def(ksl_blk, ngtcp2_ksl_blk, oplent);
|
||||
|
||||
static size_t ksl_nodelen(size_t keylen) {
|
||||
return (sizeof(ngtcp2_ksl_node) + keylen - sizeof(uint64_t) + 0xfu) &
|
||||
~(uintptr_t)0xfu;
|
||||
@@ -714,6 +716,24 @@ void ngtcp2_ksl_update_key(ngtcp2_ksl *ksl, const ngtcp2_ksl_key *old_key,
|
||||
}
|
||||
}
|
||||
|
||||
size_t ngtcp2_ksl_len(ngtcp2_ksl *ksl) { return ksl->n; }
|
||||
|
||||
void ngtcp2_ksl_clear(ngtcp2_ksl *ksl) {
|
||||
if (!ksl->head) {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef NOMEMPOOL
|
||||
ksl_free_blk(ksl, ksl->head);
|
||||
#endif /* NOMEMPOOL */
|
||||
|
||||
ksl->front = ksl->back = ksl->head = NULL;
|
||||
ksl->n = 0;
|
||||
|
||||
ngtcp2_objalloc_clear(&ksl->blkalloc);
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
static void ksl_print(ngtcp2_ksl *ksl, ngtcp2_ksl_blk *blk, size_t level) {
|
||||
size_t i;
|
||||
ngtcp2_ksl_node *node;
|
||||
@@ -734,23 +754,6 @@ static void ksl_print(ngtcp2_ksl *ksl, ngtcp2_ksl_blk *blk, size_t level) {
|
||||
}
|
||||
}
|
||||
|
||||
size_t ngtcp2_ksl_len(ngtcp2_ksl *ksl) { return ksl->n; }
|
||||
|
||||
void ngtcp2_ksl_clear(ngtcp2_ksl *ksl) {
|
||||
if (!ksl->head) {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef NOMEMPOOL
|
||||
ksl_free_blk(ksl, ksl->head);
|
||||
#endif /* NOMEMPOOL */
|
||||
|
||||
ksl->front = ksl->back = ksl->head = NULL;
|
||||
ksl->n = 0;
|
||||
|
||||
ngtcp2_objalloc_clear(&ksl->blkalloc);
|
||||
}
|
||||
|
||||
void ngtcp2_ksl_print(ngtcp2_ksl *ksl) {
|
||||
if (!ksl->head) {
|
||||
return;
|
||||
@@ -758,6 +761,7 @@ void ngtcp2_ksl_print(ngtcp2_ksl *ksl) {
|
||||
|
||||
ksl_print(ksl, ksl->head, 0);
|
||||
}
|
||||
#endif /* !WIN32 */
|
||||
|
||||
ngtcp2_ksl_it ngtcp2_ksl_begin(const ngtcp2_ksl *ksl) {
|
||||
ngtcp2_ksl_it it;
|
||||
|
||||
Vendored
+3
-1
@@ -106,7 +106,7 @@ struct ngtcp2_ksl_blk {
|
||||
};
|
||||
};
|
||||
|
||||
ngtcp2_objalloc_def(ksl_blk, ngtcp2_ksl_blk, oplent);
|
||||
ngtcp2_objalloc_decl(ksl_blk, ngtcp2_ksl_blk, oplent);
|
||||
|
||||
/*
|
||||
* ngtcp2_ksl_compar is a function type which returns nonzero if key
|
||||
@@ -263,12 +263,14 @@ void ngtcp2_ksl_clear(ngtcp2_ksl *ksl);
|
||||
#define ngtcp2_ksl_nth_node(KSL, BLK, N) \
|
||||
((ngtcp2_ksl_node *)(void *)((BLK)->nodes + (KSL)->nodelen * (N)))
|
||||
|
||||
#ifndef WIN32
|
||||
/*
|
||||
* ngtcp2_ksl_print prints its internal state in stderr. It assumes
|
||||
* that the key is of type int64_t. This function should be used for
|
||||
* the debugging purpose only.
|
||||
*/
|
||||
void ngtcp2_ksl_print(ngtcp2_ksl *ksl);
|
||||
#endif /* !WIN32 */
|
||||
|
||||
/*
|
||||
* ngtcp2_ksl_it_init initializes |it|.
|
||||
|
||||
Vendored
+152
-121
@@ -35,6 +35,8 @@
|
||||
#include "ngtcp2_vec.h"
|
||||
#include "ngtcp2_macro.h"
|
||||
#include "ngtcp2_conv.h"
|
||||
#include "ngtcp2_unreachable.h"
|
||||
#include "ngtcp2_net.h"
|
||||
|
||||
void ngtcp2_log_init(ngtcp2_log *log, const ngtcp2_cid *scid,
|
||||
ngtcp2_printf log_printf, ngtcp2_tstamp ts,
|
||||
@@ -45,6 +47,7 @@ void ngtcp2_log_init(ngtcp2_log *log, const ngtcp2_cid *scid,
|
||||
log->scid[0] = '\0';
|
||||
}
|
||||
log->log_printf = log_printf;
|
||||
log->events = 0xff;
|
||||
log->ts = log->last_ts = ts;
|
||||
log->user_data = user_data;
|
||||
}
|
||||
@@ -65,7 +68,7 @@ void ngtcp2_log_init(ngtcp2_log *log, const ngtcp2_cid *scid,
|
||||
* Source Connection ID in hex string.
|
||||
*
|
||||
* <EVENT>:
|
||||
* Event. pkt=packet, frm=frame, rcv=recovery, cry=crypto,
|
||||
* Event. pkt=packet, frm=frame, ldc=loss-detection, cry=crypto,
|
||||
* con=connection(catch all)
|
||||
*
|
||||
* # Frame event
|
||||
@@ -138,7 +141,7 @@ static const char *strerrorcode(uint64_t error_code) {
|
||||
return "CRYPTO_BUFFER_EXCEEDED";
|
||||
case NGTCP2_KEY_UPDATE_ERROR:
|
||||
return "KEY_UPDATE_ERROR";
|
||||
case NGTCP2_VERSION_NEGOTIATION_ERROR_DRAFT:
|
||||
case NGTCP2_VERSION_NEGOTIATION_ERROR:
|
||||
return "VERSION_NEGOTIATION_ERROR";
|
||||
default:
|
||||
if (0x100u <= error_code && error_code <= 0x1ffu) {
|
||||
@@ -202,12 +205,14 @@ static const char *strevent(ngtcp2_log_event ev) {
|
||||
return "pkt";
|
||||
case NGTCP2_LOG_EVENT_FRM:
|
||||
return "frm";
|
||||
case NGTCP2_LOG_EVENT_RCV:
|
||||
return "rcv";
|
||||
case NGTCP2_LOG_EVENT_LDC:
|
||||
return "ldc";
|
||||
case NGTCP2_LOG_EVENT_CRY:
|
||||
return "cry";
|
||||
case NGTCP2_LOG_EVENT_PTV:
|
||||
return "ptv";
|
||||
case NGTCP2_LOG_EVENT_CCA:
|
||||
return "cca";
|
||||
case NGTCP2_LOG_EVENT_NONE:
|
||||
default:
|
||||
return "non";
|
||||
@@ -220,8 +225,8 @@ static void log_fr_stream(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
|
||||
const ngtcp2_stream *fr, const char *dir) {
|
||||
log->log_printf(
|
||||
log->user_data,
|
||||
(NGTCP2_LOG_PKT " STREAM(0x%02x) id=0x%" PRIx64 " fin=%d offset=%" PRIu64
|
||||
" len=%" PRIu64 " uni=%d"),
|
||||
(NGTCP2_LOG_PKT " STREAM(0x%02" PRIx64 ") id=0x%" PRIx64
|
||||
" fin=%d offset=%" PRIu64 " len=%" PRIu64 " uni=%d"),
|
||||
NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type | fr->flags, fr->stream_id,
|
||||
fr->fin, fr->offset, ngtcp2_vec_len(fr->data, fr->datacnt),
|
||||
(fr->stream_id & 0x2) != 0);
|
||||
@@ -233,36 +238,37 @@ static void log_fr_ack(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
|
||||
size_t i;
|
||||
|
||||
log->log_printf(log->user_data,
|
||||
(NGTCP2_LOG_PKT " ACK(0x%02x) largest_ack=%" PRId64
|
||||
(NGTCP2_LOG_PKT " ACK(0x%02" PRIx64 ") largest_ack=%" PRId64
|
||||
" ack_delay=%" PRIu64 "(%" PRIu64
|
||||
") ack_block_count=%zu"),
|
||||
") ack_range_count=%zu"),
|
||||
NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->largest_ack,
|
||||
fr->ack_delay_unscaled / NGTCP2_MILLISECONDS, fr->ack_delay,
|
||||
fr->num_blks);
|
||||
fr->rangecnt);
|
||||
|
||||
largest_ack = fr->largest_ack;
|
||||
min_ack = fr->largest_ack - (int64_t)fr->first_ack_blklen;
|
||||
min_ack = fr->largest_ack - (int64_t)fr->first_ack_range;
|
||||
|
||||
log->log_printf(log->user_data,
|
||||
(NGTCP2_LOG_PKT " ACK(0x%02x) block=[%" PRId64 "..%" PRId64
|
||||
"] block_count=%" PRIu64),
|
||||
(NGTCP2_LOG_PKT " ACK(0x%02" PRIx64 ") range=[%" PRId64
|
||||
"..%" PRId64 "] len=%" PRIu64),
|
||||
NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, largest_ack, min_ack,
|
||||
fr->first_ack_blklen);
|
||||
fr->first_ack_range);
|
||||
|
||||
for (i = 0; i < fr->num_blks; ++i) {
|
||||
const ngtcp2_ack_blk *blk = &fr->blks[i];
|
||||
largest_ack = min_ack - (int64_t)blk->gap - 2;
|
||||
min_ack = largest_ack - (int64_t)blk->blklen;
|
||||
for (i = 0; i < fr->rangecnt; ++i) {
|
||||
const ngtcp2_ack_range *range = &fr->ranges[i];
|
||||
largest_ack = min_ack - (int64_t)range->gap - 2;
|
||||
min_ack = largest_ack - (int64_t)range->len;
|
||||
log->log_printf(log->user_data,
|
||||
(NGTCP2_LOG_PKT " ACK(0x%02x) block=[%" PRId64 "..%" PRId64
|
||||
"] gap=%" PRIu64 " block_count=%" PRIu64),
|
||||
(NGTCP2_LOG_PKT " ACK(0x%02" PRIx64 ") range=[%" PRId64
|
||||
"..%" PRId64 "] gap=%" PRIu64
|
||||
" len=%" PRIu64),
|
||||
NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, largest_ack,
|
||||
min_ack, blk->gap, blk->blklen);
|
||||
min_ack, range->gap, range->len);
|
||||
}
|
||||
|
||||
if (fr->type == NGTCP2_FRAME_ACK_ECN) {
|
||||
log->log_printf(log->user_data,
|
||||
(NGTCP2_LOG_PKT " ACK(0x%02x) ect0=%" PRIu64
|
||||
(NGTCP2_LOG_PKT " ACK(0x%02" PRIx64 ") ect0=%" PRIu64
|
||||
" ect1=%" PRIu64 " ce=%" PRIu64),
|
||||
NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->ecn.ect0,
|
||||
fr->ecn.ect1, fr->ecn.ce);
|
||||
@@ -271,7 +277,8 @@ static void log_fr_ack(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
|
||||
|
||||
static void log_fr_padding(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
|
||||
const ngtcp2_padding *fr, const char *dir) {
|
||||
log->log_printf(log->user_data, (NGTCP2_LOG_PKT " PADDING(0x%02x) len=%zu"),
|
||||
log->log_printf(log->user_data,
|
||||
(NGTCP2_LOG_PKT " PADDING(0x%02" PRIx64 ") len=%zu"),
|
||||
NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->len);
|
||||
}
|
||||
|
||||
@@ -280,7 +287,7 @@ static void log_fr_reset_stream(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
|
||||
const char *dir) {
|
||||
log->log_printf(
|
||||
log->user_data,
|
||||
(NGTCP2_LOG_PKT " RESET_STREAM(0x%02x) id=0x%" PRIx64
|
||||
(NGTCP2_LOG_PKT " RESET_STREAM(0x%02" PRIx64 ") id=0x%" PRIx64
|
||||
" app_error_code=%s(0x%" PRIx64 ") final_size=%" PRIu64),
|
||||
NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->stream_id,
|
||||
strapperrorcode(fr->app_error_code), fr->app_error_code, fr->final_size);
|
||||
@@ -293,9 +300,10 @@ static void log_fr_connection_close(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
|
||||
size_t reasonlen = ngtcp2_min(sizeof(reason) - 1, fr->reasonlen);
|
||||
|
||||
log->log_printf(log->user_data,
|
||||
(NGTCP2_LOG_PKT
|
||||
" CONNECTION_CLOSE(0x%02x) error_code=%s(0x%" PRIx64 ") "
|
||||
"frame_type=%" PRIx64 " reason_len=%zu reason=[%s]"),
|
||||
(NGTCP2_LOG_PKT " CONNECTION_CLOSE(0x%02" PRIx64
|
||||
") error_code=%s(0x%" PRIx64 ") "
|
||||
"frame_type=%" PRIx64
|
||||
" reason_len=%zu reason=[%s]"),
|
||||
NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type,
|
||||
fr->type == NGTCP2_FRAME_CONNECTION_CLOSE
|
||||
? strerrorcode(fr->error_code)
|
||||
@@ -306,16 +314,18 @@ static void log_fr_connection_close(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
|
||||
|
||||
static void log_fr_max_data(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
|
||||
const ngtcp2_max_data *fr, const char *dir) {
|
||||
log->log_printf(log->user_data,
|
||||
(NGTCP2_LOG_PKT " MAX_DATA(0x%02x) max_data=%" PRIu64),
|
||||
NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->max_data);
|
||||
log->log_printf(
|
||||
log->user_data,
|
||||
(NGTCP2_LOG_PKT " MAX_DATA(0x%02" PRIx64 ") max_data=%" PRIu64),
|
||||
NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->max_data);
|
||||
}
|
||||
|
||||
static void log_fr_max_stream_data(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
|
||||
const ngtcp2_max_stream_data *fr,
|
||||
const char *dir) {
|
||||
log->log_printf(log->user_data,
|
||||
(NGTCP2_LOG_PKT " MAX_STREAM_DATA(0x%02x) id=0x%" PRIx64
|
||||
(NGTCP2_LOG_PKT " MAX_STREAM_DATA(0x%02" PRIx64
|
||||
") id=0x%" PRIx64
|
||||
" max_stream_data=%" PRIu64),
|
||||
NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->stream_id,
|
||||
fr->max_stream_data);
|
||||
@@ -323,31 +333,33 @@ static void log_fr_max_stream_data(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
|
||||
|
||||
static void log_fr_max_streams(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
|
||||
const ngtcp2_max_streams *fr, const char *dir) {
|
||||
log->log_printf(log->user_data,
|
||||
(NGTCP2_LOG_PKT " MAX_STREAMS(0x%02x) max_streams=%" PRIu64),
|
||||
NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->max_streams);
|
||||
log->log_printf(
|
||||
log->user_data,
|
||||
(NGTCP2_LOG_PKT " MAX_STREAMS(0x%02" PRIx64 ") max_streams=%" PRIu64),
|
||||
NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->max_streams);
|
||||
}
|
||||
|
||||
static void log_fr_ping(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
|
||||
const ngtcp2_ping *fr, const char *dir) {
|
||||
log->log_printf(log->user_data, (NGTCP2_LOG_PKT " PING(0x%02x)"),
|
||||
log->log_printf(log->user_data, (NGTCP2_LOG_PKT " PING(0x%02" PRIx64 ")"),
|
||||
NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type);
|
||||
}
|
||||
|
||||
static void log_fr_data_blocked(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
|
||||
const ngtcp2_data_blocked *fr,
|
||||
const char *dir) {
|
||||
log->log_printf(log->user_data,
|
||||
(NGTCP2_LOG_PKT " DATA_BLOCKED(0x%02x) offset=%" PRIu64),
|
||||
NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->offset);
|
||||
log->log_printf(
|
||||
log->user_data,
|
||||
(NGTCP2_LOG_PKT " DATA_BLOCKED(0x%02" PRIx64 ") offset=%" PRIu64),
|
||||
NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->offset);
|
||||
}
|
||||
|
||||
static void log_fr_stream_data_blocked(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
|
||||
const ngtcp2_stream_data_blocked *fr,
|
||||
const char *dir) {
|
||||
log->log_printf(log->user_data,
|
||||
(NGTCP2_LOG_PKT " STREAM_DATA_BLOCKED(0x%02x) id=0x%" PRIx64
|
||||
" offset=%" PRIu64),
|
||||
(NGTCP2_LOG_PKT " STREAM_DATA_BLOCKED(0x%02" PRIx64
|
||||
") id=0x%" PRIx64 " offset=%" PRIu64),
|
||||
NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->stream_id,
|
||||
fr->offset);
|
||||
}
|
||||
@@ -357,7 +369,7 @@ static void log_fr_streams_blocked(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
|
||||
const char *dir) {
|
||||
log->log_printf(
|
||||
log->user_data,
|
||||
(NGTCP2_LOG_PKT " STREAMS_BLOCKED(0x%02x) max_streams=%" PRIu64),
|
||||
(NGTCP2_LOG_PKT " STREAMS_BLOCKED(0x%02" PRIx64 ") max_streams=%" PRIu64),
|
||||
NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->max_streams);
|
||||
}
|
||||
|
||||
@@ -369,7 +381,7 @@ static void log_fr_new_connection_id(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
|
||||
|
||||
log->log_printf(
|
||||
log->user_data,
|
||||
(NGTCP2_LOG_PKT " NEW_CONNECTION_ID(0x%02x) seq=%" PRIu64
|
||||
(NGTCP2_LOG_PKT " NEW_CONNECTION_ID(0x%02" PRIx64 ") seq=%" PRIu64
|
||||
" cid=0x%s retire_prior_to=%" PRIu64
|
||||
" stateless_reset_token=0x%s"),
|
||||
NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->seq,
|
||||
@@ -383,7 +395,7 @@ static void log_fr_stop_sending(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
|
||||
const ngtcp2_stop_sending *fr,
|
||||
const char *dir) {
|
||||
log->log_printf(log->user_data,
|
||||
(NGTCP2_LOG_PKT " STOP_SENDING(0x%02x) id=0x%" PRIx64
|
||||
(NGTCP2_LOG_PKT " STOP_SENDING(0x%02" PRIx64 ") id=0x%" PRIx64
|
||||
" app_error_code=%s(0x%" PRIx64 ")"),
|
||||
NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->stream_id,
|
||||
strapperrorcode(fr->app_error_code), fr->app_error_code);
|
||||
@@ -395,7 +407,8 @@ static void log_fr_path_challenge(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
|
||||
uint8_t buf[sizeof(fr->data) * 2 + 1];
|
||||
|
||||
log->log_printf(
|
||||
log->user_data, (NGTCP2_LOG_PKT " PATH_CHALLENGE(0x%02x) data=0x%s"),
|
||||
log->user_data,
|
||||
(NGTCP2_LOG_PKT " PATH_CHALLENGE(0x%02" PRIx64 ") data=0x%s"),
|
||||
NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type,
|
||||
(const char *)ngtcp2_encode_hex(buf, fr->data, sizeof(fr->data)));
|
||||
}
|
||||
@@ -406,18 +419,19 @@ static void log_fr_path_response(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
|
||||
uint8_t buf[sizeof(fr->data) * 2 + 1];
|
||||
|
||||
log->log_printf(
|
||||
log->user_data, (NGTCP2_LOG_PKT " PATH_RESPONSE(0x%02x) data=0x%s"),
|
||||
log->user_data,
|
||||
(NGTCP2_LOG_PKT " PATH_RESPONSE(0x%02" PRIx64 ") data=0x%s"),
|
||||
NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type,
|
||||
(const char *)ngtcp2_encode_hex(buf, fr->data, sizeof(fr->data)));
|
||||
}
|
||||
|
||||
static void log_fr_crypto(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
|
||||
const ngtcp2_crypto *fr, const char *dir) {
|
||||
log->log_printf(
|
||||
log->user_data,
|
||||
(NGTCP2_LOG_PKT " CRYPTO(0x%02x) offset=%" PRIu64 " len=%" PRIu64),
|
||||
NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->offset,
|
||||
ngtcp2_vec_len(fr->data, fr->datacnt));
|
||||
const ngtcp2_stream *fr, const char *dir) {
|
||||
log->log_printf(log->user_data,
|
||||
(NGTCP2_LOG_PKT " CRYPTO(0x%02" PRIx64 ") offset=%" PRIu64
|
||||
" len=%" PRIu64),
|
||||
NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->offset,
|
||||
ngtcp2_vec_len(fr->data, fr->datacnt));
|
||||
}
|
||||
|
||||
static void log_fr_new_token(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
|
||||
@@ -427,38 +441,41 @@ static void log_fr_new_token(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
|
||||
uint8_t buf[128 + 1 + 1];
|
||||
uint8_t *p;
|
||||
|
||||
if (fr->token.len > 64) {
|
||||
p = ngtcp2_encode_hex(buf, fr->token.base, 64);
|
||||
if (fr->tokenlen > 64) {
|
||||
p = ngtcp2_encode_hex(buf, fr->token, 64);
|
||||
p[128] = '*';
|
||||
p[129] = '\0';
|
||||
} else {
|
||||
p = ngtcp2_encode_hex(buf, fr->token.base, fr->token.len);
|
||||
p = ngtcp2_encode_hex(buf, fr->token, fr->tokenlen);
|
||||
}
|
||||
log->log_printf(
|
||||
log->user_data, (NGTCP2_LOG_PKT " NEW_TOKEN(0x%02x) token=0x%s len=%zu"),
|
||||
NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, (const char *)p, fr->token.len);
|
||||
log->user_data,
|
||||
(NGTCP2_LOG_PKT " NEW_TOKEN(0x%02" PRIx64 ") token=0x%s len=%zu"),
|
||||
NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, (const char *)p, fr->tokenlen);
|
||||
}
|
||||
|
||||
static void log_fr_retire_connection_id(ngtcp2_log *log,
|
||||
const ngtcp2_pkt_hd *hd,
|
||||
const ngtcp2_retire_connection_id *fr,
|
||||
const char *dir) {
|
||||
log->log_printf(log->user_data,
|
||||
(NGTCP2_LOG_PKT " RETIRE_CONNECTION_ID(0x%02x) seq=%" PRIu64),
|
||||
NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->seq);
|
||||
log->log_printf(
|
||||
log->user_data,
|
||||
(NGTCP2_LOG_PKT " RETIRE_CONNECTION_ID(0x%02" PRIx64 ") seq=%" PRIu64),
|
||||
NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->seq);
|
||||
}
|
||||
|
||||
static void log_fr_handshake_done(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
|
||||
const ngtcp2_handshake_done *fr,
|
||||
const char *dir) {
|
||||
log->log_printf(log->user_data, (NGTCP2_LOG_PKT " HANDSHAKE_DONE(0x%02x)"),
|
||||
log->log_printf(log->user_data,
|
||||
(NGTCP2_LOG_PKT " HANDSHAKE_DONE(0x%02" PRIx64 ")"),
|
||||
NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type);
|
||||
}
|
||||
|
||||
static void log_fr_datagram(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
|
||||
const ngtcp2_datagram *fr, const char *dir) {
|
||||
log->log_printf(log->user_data,
|
||||
(NGTCP2_LOG_PKT " DATAGRAM(0x%02x) len=%" PRIu64),
|
||||
(NGTCP2_LOG_PKT " DATAGRAM(0x%02" PRIx64 ") len=%" PRIu64),
|
||||
NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type,
|
||||
ngtcp2_vec_len(fr->data, fr->datacnt));
|
||||
}
|
||||
@@ -519,7 +536,7 @@ static void log_fr(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
|
||||
log_fr_path_response(log, hd, &fr->path_response, dir);
|
||||
break;
|
||||
case NGTCP2_FRAME_CRYPTO:
|
||||
log_fr_crypto(log, hd, &fr->crypto, dir);
|
||||
log_fr_crypto(log, hd, &fr->stream, dir);
|
||||
break;
|
||||
case NGTCP2_FRAME_NEW_TOKEN:
|
||||
log_fr_new_token(log, hd, &fr->new_token, dir);
|
||||
@@ -535,13 +552,13 @@ static void log_fr(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
|
||||
log_fr_datagram(log, hd, &fr->datagram, dir);
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
ngtcp2_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
void ngtcp2_log_rx_fr(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
|
||||
const ngtcp2_frame *fr) {
|
||||
if (!log->log_printf) {
|
||||
if (!log->log_printf || !(log->events & NGTCP2_LOG_EVENT_FRM)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -550,7 +567,7 @@ void ngtcp2_log_rx_fr(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
|
||||
|
||||
void ngtcp2_log_tx_fr(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
|
||||
const ngtcp2_frame *fr) {
|
||||
if (!log->log_printf) {
|
||||
if (!log->log_printf || !(log->events & NGTCP2_LOG_EVENT_FRM)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -561,7 +578,7 @@ void ngtcp2_log_rx_vn(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
|
||||
const uint32_t *sv, size_t nsv) {
|
||||
size_t i;
|
||||
|
||||
if (!log->log_printf) {
|
||||
if (!log->log_printf || !(log->events & NGTCP2_LOG_EVENT_PKT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -576,7 +593,7 @@ void ngtcp2_log_rx_sr(ngtcp2_log *log, const ngtcp2_pkt_stateless_reset *sr) {
|
||||
ngtcp2_pkt_hd shd;
|
||||
ngtcp2_pkt_hd *hd = &shd;
|
||||
|
||||
if (!log->log_printf) {
|
||||
if (!log->log_printf || !(log->events & NGTCP2_LOG_EVENT_PKT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -592,82 +609,94 @@ void ngtcp2_log_rx_sr(ngtcp2_log *log, const ngtcp2_pkt_stateless_reset *sr) {
|
||||
sr->randlen);
|
||||
}
|
||||
|
||||
void ngtcp2_log_remote_tp(ngtcp2_log *log, uint8_t exttype,
|
||||
void ngtcp2_log_remote_tp(ngtcp2_log *log,
|
||||
const ngtcp2_transport_params *params) {
|
||||
uint8_t token[NGTCP2_STATELESS_RESET_TOKENLEN * 2 + 1];
|
||||
uint8_t addr[16 * 2 + 7 + 1];
|
||||
uint8_t cid[NGTCP2_MAX_CIDLEN * 2 + 1];
|
||||
size_t i;
|
||||
const ngtcp2_sockaddr_in *sa_in;
|
||||
const ngtcp2_sockaddr_in6 *sa_in6;
|
||||
const uint8_t *p;
|
||||
uint32_t version;
|
||||
|
||||
if (!log->log_printf) {
|
||||
if (!log->log_printf || !(log->events & NGTCP2_LOG_EVENT_CRY)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (exttype == NGTCP2_TRANSPORT_PARAMS_TYPE_ENCRYPTED_EXTENSIONS) {
|
||||
if (params->stateless_reset_token_present) {
|
||||
log->log_printf(log->user_data,
|
||||
(NGTCP2_LOG_TP " stateless_reset_token=0x%s"),
|
||||
NGTCP2_LOG_TP_HD_FIELDS,
|
||||
(const char *)ngtcp2_encode_hex(
|
||||
token, params->stateless_reset_token,
|
||||
sizeof(params->stateless_reset_token)));
|
||||
}
|
||||
if (params->stateless_reset_token_present) {
|
||||
log->log_printf(
|
||||
log->user_data, (NGTCP2_LOG_TP " stateless_reset_token=0x%s"),
|
||||
NGTCP2_LOG_TP_HD_FIELDS,
|
||||
(const char *)ngtcp2_encode_hex(token, params->stateless_reset_token,
|
||||
sizeof(params->stateless_reset_token)));
|
||||
}
|
||||
|
||||
if (params->preferred_addr_present) {
|
||||
if (params->preferred_addr.ipv4_present) {
|
||||
sa_in = ¶ms->preferred_addr.ipv4;
|
||||
|
||||
if (params->preferred_address_present) {
|
||||
log->log_printf(log->user_data,
|
||||
(NGTCP2_LOG_TP " preferred_address.ipv4_addr=%s"),
|
||||
NGTCP2_LOG_TP_HD_FIELDS,
|
||||
(const char *)ngtcp2_encode_ipv4(
|
||||
addr, params->preferred_address.ipv4_addr));
|
||||
log->log_printf(
|
||||
log->user_data, (NGTCP2_LOG_TP " preferred_address.ipv4_port=%u"),
|
||||
NGTCP2_LOG_TP_HD_FIELDS, params->preferred_address.ipv4_port);
|
||||
addr, (const uint8_t *)&sa_in->sin_addr));
|
||||
log->log_printf(log->user_data,
|
||||
(NGTCP2_LOG_TP " preferred_address.ipv4_port=%u"),
|
||||
NGTCP2_LOG_TP_HD_FIELDS, ngtcp2_ntohs(sa_in->sin_port));
|
||||
}
|
||||
|
||||
if (params->preferred_addr.ipv6_present) {
|
||||
sa_in6 = ¶ms->preferred_addr.ipv6;
|
||||
|
||||
log->log_printf(log->user_data,
|
||||
(NGTCP2_LOG_TP " preferred_address.ipv6_addr=%s"),
|
||||
NGTCP2_LOG_TP_HD_FIELDS,
|
||||
(const char *)ngtcp2_encode_ipv6(
|
||||
addr, params->preferred_address.ipv6_addr));
|
||||
log->log_printf(
|
||||
log->user_data, (NGTCP2_LOG_TP " preferred_address.ipv6_port=%u"),
|
||||
NGTCP2_LOG_TP_HD_FIELDS, params->preferred_address.ipv6_port);
|
||||
|
||||
addr, (const uint8_t *)&sa_in6->sin6_addr));
|
||||
log->log_printf(log->user_data,
|
||||
(NGTCP2_LOG_TP " preferred_address.cid=0x%s"),
|
||||
NGTCP2_LOG_TP_HD_FIELDS,
|
||||
(const char *)ngtcp2_encode_hex(
|
||||
cid, params->preferred_address.cid.data,
|
||||
params->preferred_address.cid.datalen));
|
||||
log->log_printf(
|
||||
log->user_data,
|
||||
(NGTCP2_LOG_TP " preferred_address.stateless_reset_token=0x%s"),
|
||||
NGTCP2_LOG_TP_HD_FIELDS,
|
||||
(const char *)ngtcp2_encode_hex(
|
||||
token, params->preferred_address.stateless_reset_token,
|
||||
sizeof(params->preferred_address.stateless_reset_token)));
|
||||
(NGTCP2_LOG_TP " preferred_address.ipv6_port=%u"),
|
||||
NGTCP2_LOG_TP_HD_FIELDS, ngtcp2_ntohs(sa_in6->sin6_port));
|
||||
}
|
||||
|
||||
log->log_printf(
|
||||
log->user_data, (NGTCP2_LOG_TP " preferred_address.cid=0x%s"),
|
||||
NGTCP2_LOG_TP_HD_FIELDS,
|
||||
(const char *)ngtcp2_encode_hex(cid, params->preferred_addr.cid.data,
|
||||
params->preferred_addr.cid.datalen));
|
||||
log->log_printf(
|
||||
log->user_data,
|
||||
(NGTCP2_LOG_TP " preferred_address.stateless_reset_token=0x%s"),
|
||||
NGTCP2_LOG_TP_HD_FIELDS,
|
||||
(const char *)ngtcp2_encode_hex(
|
||||
token, params->preferred_addr.stateless_reset_token,
|
||||
sizeof(params->preferred_addr.stateless_reset_token)));
|
||||
}
|
||||
|
||||
if (params->original_dcid_present) {
|
||||
log->log_printf(
|
||||
log->user_data,
|
||||
(NGTCP2_LOG_TP " original_destination_connection_id=0x%s"),
|
||||
NGTCP2_LOG_TP_HD_FIELDS,
|
||||
(const char *)ngtcp2_encode_hex(cid, params->original_dcid.data,
|
||||
params->original_dcid.datalen));
|
||||
|
||||
if (params->retry_scid_present) {
|
||||
log->log_printf(
|
||||
log->user_data, (NGTCP2_LOG_TP " retry_source_connection_id=0x%s"),
|
||||
NGTCP2_LOG_TP_HD_FIELDS,
|
||||
(const char *)ngtcp2_encode_hex(cid, params->retry_scid.data,
|
||||
params->retry_scid.datalen));
|
||||
}
|
||||
}
|
||||
|
||||
log->log_printf(
|
||||
log->user_data, (NGTCP2_LOG_TP " initial_source_connection_id=0x%s"),
|
||||
NGTCP2_LOG_TP_HD_FIELDS,
|
||||
(const char *)ngtcp2_encode_hex(cid, params->initial_scid.data,
|
||||
params->initial_scid.datalen));
|
||||
if (params->retry_scid_present) {
|
||||
log->log_printf(
|
||||
log->user_data, (NGTCP2_LOG_TP " retry_source_connection_id=0x%s"),
|
||||
NGTCP2_LOG_TP_HD_FIELDS,
|
||||
(const char *)ngtcp2_encode_hex(cid, params->retry_scid.data,
|
||||
params->retry_scid.datalen));
|
||||
}
|
||||
|
||||
if (params->initial_scid_present) {
|
||||
log->log_printf(
|
||||
log->user_data, (NGTCP2_LOG_TP " initial_source_connection_id=0x%s"),
|
||||
NGTCP2_LOG_TP_HD_FIELDS,
|
||||
(const char *)ngtcp2_encode_hex(cid, params->initial_scid.data,
|
||||
params->initial_scid.datalen));
|
||||
}
|
||||
|
||||
log->log_printf(
|
||||
log->user_data,
|
||||
@@ -718,26 +747,28 @@ void ngtcp2_log_remote_tp(ngtcp2_log *log, uint8_t exttype,
|
||||
(NGTCP2_LOG_TP " version_information.chosen_version=0x%08x"),
|
||||
NGTCP2_LOG_TP_HD_FIELDS, params->version_info.chosen_version);
|
||||
|
||||
assert(!(params->version_info.other_versionslen & 0x3));
|
||||
assert(!(params->version_info.available_versionslen & 0x3));
|
||||
|
||||
for (i = 0; i < params->version_info.other_versionslen;
|
||||
for (i = 0, p = params->version_info.available_versions;
|
||||
i < params->version_info.available_versionslen;
|
||||
i += sizeof(uint32_t)) {
|
||||
p = ngtcp2_get_uint32(&version, p);
|
||||
|
||||
log->log_printf(
|
||||
log->user_data,
|
||||
(NGTCP2_LOG_TP " version_information.other_versions[%zu]=0x%08x"),
|
||||
NGTCP2_LOG_TP_HD_FIELDS, i >> 2,
|
||||
ngtcp2_get_uint32(¶ms->version_info.other_versions[i]));
|
||||
(NGTCP2_LOG_TP " version_information.available_versions[%zu]=0x%08x"),
|
||||
NGTCP2_LOG_TP_HD_FIELDS, i >> 2, version);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ngtcp2_log_pkt_lost(ngtcp2_log *log, int64_t pkt_num, uint8_t type,
|
||||
uint8_t flags, ngtcp2_tstamp sent_ts) {
|
||||
if (!log->log_printf) {
|
||||
if (!log->log_printf || !(log->events & NGTCP2_LOG_EVENT_LDC)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ngtcp2_log_info(log, NGTCP2_LOG_EVENT_RCV,
|
||||
ngtcp2_log_info(log, NGTCP2_LOG_EVENT_LDC,
|
||||
"pkn=%" PRId64 " lost type=%s sent_ts=%" PRIu64, pkt_num,
|
||||
strpkttype_type_flags(type, flags), sent_ts);
|
||||
}
|
||||
@@ -747,7 +778,7 @@ static void log_pkt_hd(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
|
||||
uint8_t dcid[sizeof(hd->dcid.data) * 2 + 1];
|
||||
uint8_t scid[sizeof(hd->scid.data) * 2 + 1];
|
||||
|
||||
if (!log->log_printf) {
|
||||
if (!log->log_printf || !(log->events & NGTCP2_LOG_EVENT_PKT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -782,7 +813,7 @@ void ngtcp2_log_info(ngtcp2_log *log, ngtcp2_log_event ev, const char *fmt,
|
||||
int n;
|
||||
char buf[NGTCP2_LOG_BUFLEN];
|
||||
|
||||
if (!log->log_printf) {
|
||||
if (!log->log_printf || !(log->events & ev)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Vendored
+17
-8
@@ -37,6 +37,9 @@ typedef struct ngtcp2_log {
|
||||
/* log_printf is a sink to write log. NULL means no logging
|
||||
output. */
|
||||
ngtcp2_printf log_printf;
|
||||
/* events is an event filter. Only events set in this field are
|
||||
emitted. */
|
||||
uint8_t events;
|
||||
/* ts is the time point used to write time delta in the log. */
|
||||
ngtcp2_tstamp ts;
|
||||
/* last_ts is the most recent time point that this object is
|
||||
@@ -63,27 +66,33 @@ typedef enum ngtcp2_log_event {
|
||||
/**
|
||||
* :enum:`NGTCP2_LOG_EVENT_CON` is a connection (catch-all) event
|
||||
*/
|
||||
NGTCP2_LOG_EVENT_CON,
|
||||
NGTCP2_LOG_EVENT_CON = 0x1,
|
||||
/**
|
||||
* :enum:`NGTCP2_LOG_EVENT_PKT` is a packet event.
|
||||
*/
|
||||
NGTCP2_LOG_EVENT_PKT,
|
||||
NGTCP2_LOG_EVENT_PKT = 0x2,
|
||||
/**
|
||||
* :enum:`NGTCP2_LOG_EVENT_FRM` is a QUIC frame event.
|
||||
*/
|
||||
NGTCP2_LOG_EVENT_FRM,
|
||||
NGTCP2_LOG_EVENT_FRM = 0x4,
|
||||
/**
|
||||
* :enum:`NGTCP2_LOG_EVENT_RCV` is a congestion and recovery event.
|
||||
* :enum:`NGTCP2_LOG_EVENT_LDC` is a loss detection and congestion
|
||||
* control event.
|
||||
*/
|
||||
NGTCP2_LOG_EVENT_RCV,
|
||||
NGTCP2_LOG_EVENT_LDC = 0x8,
|
||||
/**
|
||||
* :enum:`NGTCP2_LOG_EVENT_CRY` is a crypto event.
|
||||
*/
|
||||
NGTCP2_LOG_EVENT_CRY,
|
||||
NGTCP2_LOG_EVENT_CRY = 0x10,
|
||||
/**
|
||||
* :enum:`NGTCP2_LOG_EVENT_PTV` is a path validation event.
|
||||
*/
|
||||
NGTCP2_LOG_EVENT_PTV,
|
||||
NGTCP2_LOG_EVENT_PTV = 0x20,
|
||||
/**
|
||||
* :enum:`NGTCP2_LOG_EVENT_CCA` is a congestion controller algorithm
|
||||
* event.
|
||||
*/
|
||||
NGTCP2_LOG_EVENT_CCA = 0x40,
|
||||
} ngtcp2_log_event;
|
||||
|
||||
void ngtcp2_log_init(ngtcp2_log *log, const ngtcp2_cid *scid,
|
||||
@@ -100,7 +109,7 @@ void ngtcp2_log_rx_vn(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
|
||||
|
||||
void ngtcp2_log_rx_sr(ngtcp2_log *log, const ngtcp2_pkt_stateless_reset *sr);
|
||||
|
||||
void ngtcp2_log_remote_tp(ngtcp2_log *log, uint8_t exttype,
|
||||
void ngtcp2_log_remote_tp(ngtcp2_log *log,
|
||||
const ngtcp2_transport_params *params);
|
||||
|
||||
void ngtcp2_log_pkt_lost(ngtcp2_log *log, int64_t pkt_num, uint8_t type,
|
||||
|
||||
+5
@@ -50,4 +50,9 @@
|
||||
*(PD) = (T); \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* ngtcp2_arraylen returns the number of elements in array |A|.
|
||||
*/
|
||||
#define ngtcp2_arraylen(A) (sizeof(A) / sizeof(A[0]))
|
||||
|
||||
#endif /* NGTCP2_MACRO_H */
|
||||
Vendored
+2
@@ -126,6 +126,7 @@ static void map_bucket_set_data(ngtcp2_map_bucket *bkt, uint32_t hash,
|
||||
bkt->data = data;
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
void ngtcp2_map_print_distance(ngtcp2_map *map) {
|
||||
uint32_t i;
|
||||
size_t idx;
|
||||
@@ -145,6 +146,7 @@ void ngtcp2_map_print_distance(ngtcp2_map *map) {
|
||||
distance(map->tablelen, map->tablelenbits, bkt, idx));
|
||||
}
|
||||
}
|
||||
#endif /* !WIN32 */
|
||||
|
||||
static int insert(ngtcp2_map_bucket *table, uint32_t tablelen,
|
||||
uint32_t tablelenbits, uint32_t hash, ngtcp2_map_key_type key,
|
||||
|
||||
Vendored
+2
@@ -131,6 +131,8 @@ size_t ngtcp2_map_size(ngtcp2_map *map);
|
||||
int ngtcp2_map_each(ngtcp2_map *map, int (*func)(void *data, void *ptr),
|
||||
void *ptr);
|
||||
|
||||
#ifndef WIN32
|
||||
void ngtcp2_map_print_distance(ngtcp2_map *map);
|
||||
#endif /* !WIN32 */
|
||||
|
||||
#endif /* NGTCP2_MAP_H */
|
||||
Vendored
+20
-13
@@ -52,16 +52,11 @@
|
||||
# include <sys/endian.h>
|
||||
#endif /* HAVE_SYS_ENDIAN_H */
|
||||
|
||||
#include <ngtcp2/ngtcp2.h>
|
||||
#if defined(__APPLE__)
|
||||
# include <libkern/OSByteOrder.h>
|
||||
#endif // __APPLE__
|
||||
|
||||
#if defined(HAVE_BSWAP_64) || \
|
||||
(defined(HAVE_DECL_BSWAP_64) && HAVE_DECL_BSWAP_64 > 0)
|
||||
# define ngtcp2_bswap64 bswap_64
|
||||
#else /* !HAVE_BSWAP_64 */
|
||||
# define ngtcp2_bswap64(N) \
|
||||
((uint64_t)(ngtcp2_ntohl((uint32_t)(N))) << 32 | \
|
||||
ngtcp2_ntohl((uint32_t)((N) >> 32)))
|
||||
#endif /* !HAVE_BSWAP_64 */
|
||||
#include <ngtcp2/ngtcp2.h>
|
||||
|
||||
#if defined(HAVE_BE64TOH) || \
|
||||
(defined(HAVE_DECL_BE64TOH) && HAVE_DECL_BE64TOH > 0)
|
||||
@@ -72,6 +67,18 @@
|
||||
# define ngtcp2_ntohl64(N) (N)
|
||||
# define ngtcp2_htonl64(N) (N)
|
||||
# else /* !WORDS_BIGENDIAN */
|
||||
# if defined(HAVE_BSWAP_64) || \
|
||||
(defined(HAVE_DECL_BSWAP_64) && HAVE_DECL_BSWAP_64 > 0)
|
||||
# define ngtcp2_bswap64 bswap_64
|
||||
# elif defined(WIN32)
|
||||
# define ngtcp2_bswap64 _byteswap_uint64
|
||||
# elif defined(__APPLE__)
|
||||
# define ngtcp2_bswap64 OSSwapInt64
|
||||
# else /* !HAVE_BSWAP_64 && !WIN32 && !__APPLE__ */
|
||||
# define ngtcp2_bswap64(N) \
|
||||
((uint64_t)(ngtcp2_ntohl((uint32_t)(N))) << 32 | \
|
||||
ngtcp2_ntohl((uint32_t)((N) >> 32)))
|
||||
# endif /* !HAVE_BSWAP_64 && !WIN32 && !__APPLE__ */
|
||||
# define ngtcp2_ntohl64(N) ngtcp2_bswap64(N)
|
||||
# define ngtcp2_htonl64(N) ngtcp2_bswap64(N)
|
||||
# endif /* !WORDS_BIGENDIAN */
|
||||
@@ -109,9 +116,9 @@ STIN uint16_t ngtcp2_htons(uint16_t hostshort) {
|
||||
STIN uint32_t ngtcp2_ntohl(uint32_t netlong) {
|
||||
uint32_t res;
|
||||
unsigned char *p = (unsigned char *)&netlong;
|
||||
res = *p++ << 24;
|
||||
res += *p++ << 16;
|
||||
res += *p++ << 8;
|
||||
res = (uint32_t)(*p++ << 24);
|
||||
res += (uint32_t)(*p++ << 16);
|
||||
res += (uint32_t)(*p++ << 8);
|
||||
res += *p;
|
||||
return res;
|
||||
}
|
||||
@@ -119,7 +126,7 @@ STIN uint32_t ngtcp2_ntohl(uint32_t netlong) {
|
||||
STIN uint16_t ngtcp2_ntohs(uint16_t netshort) {
|
||||
uint16_t res;
|
||||
unsigned char *p = (unsigned char *)&netshort;
|
||||
res = *p++ << 8;
|
||||
res = (uint16_t)(*p++ << 8);
|
||||
res += *p;
|
||||
return res;
|
||||
}
|
||||
|
||||
+18
-11
@@ -65,15 +65,25 @@ void ngtcp2_objalloc_free(ngtcp2_objalloc *objalloc);
|
||||
void ngtcp2_objalloc_clear(ngtcp2_objalloc *objalloc);
|
||||
|
||||
#ifndef NOMEMPOOL
|
||||
# define ngtcp2_objalloc_def(NAME, TYPE, OPLENTFIELD) \
|
||||
# define ngtcp2_objalloc_decl(NAME, TYPE, OPLENTFIELD) \
|
||||
inline static void ngtcp2_objalloc_##NAME##_init( \
|
||||
ngtcp2_objalloc *objalloc, size_t nmemb, const ngtcp2_mem *mem) { \
|
||||
ngtcp2_objalloc_init( \
|
||||
objalloc, ((sizeof(TYPE) + 0xfu) & ~(uintptr_t)0xfu) * nmemb, mem); \
|
||||
} \
|
||||
\
|
||||
inline static TYPE *ngtcp2_objalloc_##NAME##_get( \
|
||||
ngtcp2_objalloc *objalloc) { \
|
||||
TYPE *ngtcp2_objalloc_##NAME##_get(ngtcp2_objalloc *objalloc); \
|
||||
\
|
||||
TYPE *ngtcp2_objalloc_##NAME##_len_get(ngtcp2_objalloc *objalloc, \
|
||||
size_t len); \
|
||||
\
|
||||
inline static void ngtcp2_objalloc_##NAME##_release( \
|
||||
ngtcp2_objalloc *objalloc, TYPE *obj) { \
|
||||
ngtcp2_opl_push(&objalloc->opl, &obj->OPLENTFIELD); \
|
||||
}
|
||||
|
||||
# define ngtcp2_objalloc_def(NAME, TYPE, OPLENTFIELD) \
|
||||
TYPE *ngtcp2_objalloc_##NAME##_get(ngtcp2_objalloc *objalloc) { \
|
||||
ngtcp2_opl_entry *oplent = ngtcp2_opl_pop(&objalloc->opl); \
|
||||
TYPE *obj; \
|
||||
int rv; \
|
||||
@@ -91,8 +101,8 @@ void ngtcp2_objalloc_clear(ngtcp2_objalloc *objalloc);
|
||||
return ngtcp2_struct_of(oplent, TYPE, OPLENTFIELD); \
|
||||
} \
|
||||
\
|
||||
inline static TYPE *ngtcp2_objalloc_##NAME##_len_get( \
|
||||
ngtcp2_objalloc *objalloc, size_t len) { \
|
||||
TYPE *ngtcp2_objalloc_##NAME##_len_get(ngtcp2_objalloc *objalloc, \
|
||||
size_t len) { \
|
||||
ngtcp2_opl_entry *oplent = ngtcp2_opl_pop(&objalloc->opl); \
|
||||
TYPE *obj; \
|
||||
int rv; \
|
||||
@@ -107,14 +117,9 @@ void ngtcp2_objalloc_clear(ngtcp2_objalloc *objalloc);
|
||||
} \
|
||||
\
|
||||
return ngtcp2_struct_of(oplent, TYPE, OPLENTFIELD); \
|
||||
} \
|
||||
\
|
||||
inline static void ngtcp2_objalloc_##NAME##_release( \
|
||||
ngtcp2_objalloc *objalloc, TYPE *obj) { \
|
||||
ngtcp2_opl_push(&objalloc->opl, &obj->OPLENTFIELD); \
|
||||
}
|
||||
#else /* NOMEMPOOL */
|
||||
# define ngtcp2_objalloc_def(NAME, TYPE, OPLENTFIELD) \
|
||||
# define ngtcp2_objalloc_decl(NAME, TYPE, OPLENTFIELD) \
|
||||
inline static void ngtcp2_objalloc_##NAME##_init( \
|
||||
ngtcp2_objalloc *objalloc, size_t nmemb, const ngtcp2_mem *mem) { \
|
||||
ngtcp2_objalloc_init( \
|
||||
@@ -135,6 +140,8 @@ void ngtcp2_objalloc_clear(ngtcp2_objalloc *objalloc);
|
||||
ngtcp2_objalloc *objalloc, TYPE *obj) { \
|
||||
ngtcp2_mem_free(objalloc->balloc.mem, obj); \
|
||||
}
|
||||
|
||||
# define ngtcp2_objalloc_def(NAME, TYPE, OPLENTFIELD)
|
||||
#endif /* NOMEMPOOL */
|
||||
|
||||
#endif /* NGTCP2_OBJALLOC_H */
|
||||
Vendored
+262
-303
File diff suppressed because it is too large.
Load diff
Vendored
+94
-102
@@ -88,9 +88,9 @@
|
||||
client stream ID. */
|
||||
#define NGTCP2_MAX_CLIENT_STREAM_ID_UNI ((int64_t)0x3ffffffffffffffell)
|
||||
|
||||
/* NGTCP2_MAX_NUM_ACK_BLK is the maximum number of Additional ACK
|
||||
blocks which this library can create, or decode. */
|
||||
#define NGTCP2_MAX_ACK_BLKS 32
|
||||
/* NGTCP2_MAX_NUM_ACK_RANGES is the maximum number of Additional ACK
|
||||
ranges which this library can create, or decode. */
|
||||
#define NGTCP2_MAX_ACK_RANGES 32
|
||||
|
||||
/* NGTCP2_MAX_PKT_NUM is the maximum packet number. */
|
||||
#define NGTCP2_MAX_PKT_NUM ((int64_t)((1ll << 62) - 1))
|
||||
@@ -124,62 +124,67 @@
|
||||
v1. */
|
||||
#define NGTCP2_PKT_TYPE_RETRY_V1 0x3
|
||||
|
||||
/* NGTCP2_PKT_TYPE_INITIAL_V2_DRAFT is Initial long header packet type
|
||||
for QUIC v2 draft. */
|
||||
#define NGTCP2_PKT_TYPE_INITIAL_V2_DRAFT 0x1
|
||||
/* NGTCP2_PKT_TYPE_0RTT_V2_DRAFT is 0RTT long header packet type for
|
||||
QUIC v2 draft. */
|
||||
#define NGTCP2_PKT_TYPE_0RTT_V2_DRAFT 0x2
|
||||
/* NGTCP2_PKT_TYPE_HANDSHAKE_V2_DRAFT is Handshake long header packet
|
||||
type for QUIC v2 draft. */
|
||||
#define NGTCP2_PKT_TYPE_HANDSHAKE_V2_DRAFT 0x3
|
||||
/* NGTCP2_PKT_TYPE_RETRY_V2_DRAFT is Retry long header packet type for
|
||||
QUIC v2 draft. */
|
||||
#define NGTCP2_PKT_TYPE_RETRY_V2_DRAFT 0x0
|
||||
/* NGTCP2_PKT_TYPE_INITIAL_V2 is Initial long header packet type for
|
||||
QUIC v2. */
|
||||
#define NGTCP2_PKT_TYPE_INITIAL_V2 0x1
|
||||
/* NGTCP2_PKT_TYPE_0RTT_V2 is 0RTT long header packet type for QUIC
|
||||
v2. */
|
||||
#define NGTCP2_PKT_TYPE_0RTT_V2 0x2
|
||||
/* NGTCP2_PKT_TYPE_HANDSHAKE_V2 is Handshake long header packet type
|
||||
for QUIC v2. */
|
||||
#define NGTCP2_PKT_TYPE_HANDSHAKE_V2 0x3
|
||||
/* NGTCP2_PKT_TYPE_RETRY_V2 is Retry long header packet type for QUIC
|
||||
v2. */
|
||||
#define NGTCP2_PKT_TYPE_RETRY_V2 0x0
|
||||
|
||||
typedef struct ngtcp2_pkt_retry {
|
||||
ngtcp2_cid odcid;
|
||||
ngtcp2_vec token;
|
||||
uint8_t *token;
|
||||
size_t tokenlen;
|
||||
uint8_t tag[NGTCP2_RETRY_TAGLEN];
|
||||
} ngtcp2_pkt_retry;
|
||||
|
||||
typedef enum {
|
||||
NGTCP2_FRAME_PADDING = 0x00,
|
||||
NGTCP2_FRAME_PING = 0x01,
|
||||
NGTCP2_FRAME_ACK = 0x02,
|
||||
NGTCP2_FRAME_ACK_ECN = 0x03,
|
||||
NGTCP2_FRAME_RESET_STREAM = 0x04,
|
||||
NGTCP2_FRAME_STOP_SENDING = 0x05,
|
||||
NGTCP2_FRAME_CRYPTO = 0x06,
|
||||
NGTCP2_FRAME_NEW_TOKEN = 0x07,
|
||||
NGTCP2_FRAME_STREAM = 0x08,
|
||||
NGTCP2_FRAME_MAX_DATA = 0x10,
|
||||
NGTCP2_FRAME_MAX_STREAM_DATA = 0x11,
|
||||
NGTCP2_FRAME_MAX_STREAMS_BIDI = 0x12,
|
||||
NGTCP2_FRAME_MAX_STREAMS_UNI = 0x13,
|
||||
NGTCP2_FRAME_DATA_BLOCKED = 0x14,
|
||||
NGTCP2_FRAME_STREAM_DATA_BLOCKED = 0x15,
|
||||
NGTCP2_FRAME_STREAMS_BLOCKED_BIDI = 0x16,
|
||||
NGTCP2_FRAME_STREAMS_BLOCKED_UNI = 0x17,
|
||||
NGTCP2_FRAME_NEW_CONNECTION_ID = 0x18,
|
||||
NGTCP2_FRAME_RETIRE_CONNECTION_ID = 0x19,
|
||||
NGTCP2_FRAME_PATH_CHALLENGE = 0x1a,
|
||||
NGTCP2_FRAME_PATH_RESPONSE = 0x1b,
|
||||
NGTCP2_FRAME_CONNECTION_CLOSE = 0x1c,
|
||||
NGTCP2_FRAME_CONNECTION_CLOSE_APP = 0x1d,
|
||||
NGTCP2_FRAME_HANDSHAKE_DONE = 0x1e,
|
||||
NGTCP2_FRAME_DATAGRAM = 0x30,
|
||||
NGTCP2_FRAME_DATAGRAM_LEN = 0x31,
|
||||
} ngtcp2_frame_type;
|
||||
#define NGTCP2_FRAME_PADDING 0x00
|
||||
#define NGTCP2_FRAME_PING 0x01
|
||||
#define NGTCP2_FRAME_ACK 0x02
|
||||
#define NGTCP2_FRAME_ACK_ECN 0x03
|
||||
#define NGTCP2_FRAME_RESET_STREAM 0x04
|
||||
#define NGTCP2_FRAME_STOP_SENDING 0x05
|
||||
#define NGTCP2_FRAME_CRYPTO 0x06
|
||||
#define NGTCP2_FRAME_NEW_TOKEN 0x07
|
||||
#define NGTCP2_FRAME_STREAM 0x08
|
||||
#define NGTCP2_FRAME_MAX_DATA 0x10
|
||||
#define NGTCP2_FRAME_MAX_STREAM_DATA 0x11
|
||||
#define NGTCP2_FRAME_MAX_STREAMS_BIDI 0x12
|
||||
#define NGTCP2_FRAME_MAX_STREAMS_UNI 0x13
|
||||
#define NGTCP2_FRAME_DATA_BLOCKED 0x14
|
||||
#define NGTCP2_FRAME_STREAM_DATA_BLOCKED 0x15
|
||||
#define NGTCP2_FRAME_STREAMS_BLOCKED_BIDI 0x16
|
||||
#define NGTCP2_FRAME_STREAMS_BLOCKED_UNI 0x17
|
||||
#define NGTCP2_FRAME_NEW_CONNECTION_ID 0x18
|
||||
#define NGTCP2_FRAME_RETIRE_CONNECTION_ID 0x19
|
||||
#define NGTCP2_FRAME_PATH_CHALLENGE 0x1a
|
||||
#define NGTCP2_FRAME_PATH_RESPONSE 0x1b
|
||||
#define NGTCP2_FRAME_CONNECTION_CLOSE 0x1c
|
||||
#define NGTCP2_FRAME_CONNECTION_CLOSE_APP 0x1d
|
||||
#define NGTCP2_FRAME_HANDSHAKE_DONE 0x1e
|
||||
#define NGTCP2_FRAME_DATAGRAM 0x30
|
||||
#define NGTCP2_FRAME_DATAGRAM_LEN 0x31
|
||||
|
||||
/* ngtcp2_stream represents STREAM and CRYPTO frames. */
|
||||
typedef struct ngtcp2_stream {
|
||||
uint8_t type;
|
||||
uint64_t type;
|
||||
/**
|
||||
* flags of decoded STREAM frame. This gets ignored when encoding
|
||||
* STREAM frame.
|
||||
* STREAM frame. CRYPTO frame does not include this field, and must
|
||||
* set it to 0.
|
||||
*/
|
||||
uint8_t flags;
|
||||
/* CRYPTO frame does not include this field, and must set it to
|
||||
0. */
|
||||
uint8_t fin;
|
||||
/* CRYPTO frame does not include this field, and must set it to
|
||||
0. */
|
||||
int64_t stream_id;
|
||||
uint64_t offset;
|
||||
/* datacnt is the number of elements that data contains. Although
|
||||
@@ -190,13 +195,13 @@ typedef struct ngtcp2_stream {
|
||||
ngtcp2_vec data[1];
|
||||
} ngtcp2_stream;
|
||||
|
||||
typedef struct ngtcp2_ack_blk {
|
||||
typedef struct ngtcp2_ack_range {
|
||||
uint64_t gap;
|
||||
uint64_t blklen;
|
||||
} ngtcp2_ack_blk;
|
||||
uint64_t len;
|
||||
} ngtcp2_ack_range;
|
||||
|
||||
typedef struct ngtcp2_ack {
|
||||
uint8_t type;
|
||||
uint64_t type;
|
||||
int64_t largest_ack;
|
||||
uint64_t ack_delay;
|
||||
/**
|
||||
@@ -209,13 +214,13 @@ typedef struct ngtcp2_ack {
|
||||
uint64_t ect1;
|
||||
uint64_t ce;
|
||||
} ecn;
|
||||
uint64_t first_ack_blklen;
|
||||
size_t num_blks;
|
||||
ngtcp2_ack_blk blks[1];
|
||||
uint64_t first_ack_range;
|
||||
size_t rangecnt;
|
||||
ngtcp2_ack_range ranges[1];
|
||||
} ngtcp2_ack;
|
||||
|
||||
typedef struct ngtcp2_padding {
|
||||
uint8_t type;
|
||||
uint64_t type;
|
||||
/**
|
||||
* The length of contiguous PADDING frames.
|
||||
*/
|
||||
@@ -223,14 +228,14 @@ typedef struct ngtcp2_padding {
|
||||
} ngtcp2_padding;
|
||||
|
||||
typedef struct ngtcp2_reset_stream {
|
||||
uint8_t type;
|
||||
uint64_t type;
|
||||
int64_t stream_id;
|
||||
uint64_t app_error_code;
|
||||
uint64_t final_size;
|
||||
} ngtcp2_reset_stream;
|
||||
|
||||
typedef struct ngtcp2_connection_close {
|
||||
uint8_t type;
|
||||
uint64_t type;
|
||||
uint64_t error_code;
|
||||
uint64_t frame_type;
|
||||
size_t reasonlen;
|
||||
@@ -238,7 +243,7 @@ typedef struct ngtcp2_connection_close {
|
||||
} ngtcp2_connection_close;
|
||||
|
||||
typedef struct ngtcp2_max_data {
|
||||
uint8_t type;
|
||||
uint64_t type;
|
||||
/**
|
||||
* max_data is Maximum Data.
|
||||
*/
|
||||
@@ -246,38 +251,38 @@ typedef struct ngtcp2_max_data {
|
||||
} ngtcp2_max_data;
|
||||
|
||||
typedef struct ngtcp2_max_stream_data {
|
||||
uint8_t type;
|
||||
uint64_t type;
|
||||
int64_t stream_id;
|
||||
uint64_t max_stream_data;
|
||||
} ngtcp2_max_stream_data;
|
||||
|
||||
typedef struct ngtcp2_max_streams {
|
||||
uint8_t type;
|
||||
uint64_t type;
|
||||
uint64_t max_streams;
|
||||
} ngtcp2_max_streams;
|
||||
|
||||
typedef struct ngtcp2_ping {
|
||||
uint8_t type;
|
||||
uint64_t type;
|
||||
} ngtcp2_ping;
|
||||
|
||||
typedef struct ngtcp2_data_blocked {
|
||||
uint8_t type;
|
||||
uint64_t type;
|
||||
uint64_t offset;
|
||||
} ngtcp2_data_blocked;
|
||||
|
||||
typedef struct ngtcp2_stream_data_blocked {
|
||||
uint8_t type;
|
||||
uint64_t type;
|
||||
int64_t stream_id;
|
||||
uint64_t offset;
|
||||
} ngtcp2_stream_data_blocked;
|
||||
|
||||
typedef struct ngtcp2_streams_blocked {
|
||||
uint8_t type;
|
||||
uint64_t type;
|
||||
uint64_t max_streams;
|
||||
} ngtcp2_streams_blocked;
|
||||
|
||||
typedef struct ngtcp2_new_connection_id {
|
||||
uint8_t type;
|
||||
uint64_t type;
|
||||
uint64_t seq;
|
||||
uint64_t retire_prior_to;
|
||||
ngtcp2_cid cid;
|
||||
@@ -285,48 +290,38 @@ typedef struct ngtcp2_new_connection_id {
|
||||
} ngtcp2_new_connection_id;
|
||||
|
||||
typedef struct ngtcp2_stop_sending {
|
||||
uint8_t type;
|
||||
uint64_t type;
|
||||
int64_t stream_id;
|
||||
uint64_t app_error_code;
|
||||
} ngtcp2_stop_sending;
|
||||
|
||||
typedef struct ngtcp2_path_challenge {
|
||||
uint8_t type;
|
||||
uint64_t type;
|
||||
uint8_t data[NGTCP2_PATH_CHALLENGE_DATALEN];
|
||||
} ngtcp2_path_challenge;
|
||||
|
||||
typedef struct ngtcp2_path_response {
|
||||
uint8_t type;
|
||||
uint64_t type;
|
||||
uint8_t data[NGTCP2_PATH_CHALLENGE_DATALEN];
|
||||
} ngtcp2_path_response;
|
||||
|
||||
typedef struct ngtcp2_crypto {
|
||||
uint8_t type;
|
||||
uint64_t offset;
|
||||
/* datacnt is the number of elements that data contains. Although
|
||||
the length of data is 1 in this definition, the library may
|
||||
allocate extra bytes to hold more elements. */
|
||||
size_t datacnt;
|
||||
/* data is the array of ngtcp2_vec which references data. */
|
||||
ngtcp2_vec data[1];
|
||||
} ngtcp2_crypto;
|
||||
|
||||
typedef struct ngtcp2_new_token {
|
||||
uint8_t type;
|
||||
ngtcp2_vec token;
|
||||
uint64_t type;
|
||||
uint8_t *token;
|
||||
size_t tokenlen;
|
||||
} ngtcp2_new_token;
|
||||
|
||||
typedef struct ngtcp2_retire_connection_id {
|
||||
uint8_t type;
|
||||
uint64_t type;
|
||||
uint64_t seq;
|
||||
} ngtcp2_retire_connection_id;
|
||||
|
||||
typedef struct ngtcp2_handshake_done {
|
||||
uint8_t type;
|
||||
uint64_t type;
|
||||
} ngtcp2_handshake_done;
|
||||
|
||||
typedef struct ngtcp2_datagram {
|
||||
uint8_t type;
|
||||
uint64_t type;
|
||||
/* dgram_id is an opaque identifier chosen by an application. */
|
||||
uint64_t dgram_id;
|
||||
/* datacnt is the number of elements that data contains. */
|
||||
@@ -341,7 +336,7 @@ typedef struct ngtcp2_datagram {
|
||||
} ngtcp2_datagram;
|
||||
|
||||
typedef union ngtcp2_frame {
|
||||
uint8_t type;
|
||||
uint64_t type;
|
||||
ngtcp2_stream stream;
|
||||
ngtcp2_ack ack;
|
||||
ngtcp2_padding padding;
|
||||
@@ -358,7 +353,6 @@ typedef union ngtcp2_frame {
|
||||
ngtcp2_stop_sending stop_sending;
|
||||
ngtcp2_path_challenge path_challenge;
|
||||
ngtcp2_path_response path_response;
|
||||
ngtcp2_crypto crypto;
|
||||
ngtcp2_new_token new_token;
|
||||
ngtcp2_retire_connection_id retire_connection_id;
|
||||
ngtcp2_handshake_done handshake_done;
|
||||
@@ -454,7 +448,8 @@ ngtcp2_ssize ngtcp2_pkt_encode_hd_short(uint8_t *out, size_t outlen,
|
||||
* frame if it succeeds, or one of the following negative error codes:
|
||||
*
|
||||
* :enum:`NGTCP2_ERR_FRAME_ENCODING`
|
||||
* Frame is badly formatted; or frame type is unknown.
|
||||
* Frame is badly formatted; or frame type is unknown; or
|
||||
* |payloadlen| is 0.
|
||||
*/
|
||||
ngtcp2_ssize ngtcp2_pkt_decode_frame(ngtcp2_frame *dest, const uint8_t *payload,
|
||||
size_t payloadlen);
|
||||
@@ -554,9 +549,9 @@ ngtcp2_ssize ngtcp2_pkt_decode_ack_frame(ngtcp2_ack *dest,
|
||||
* This function returns the exact number of bytes read to decode
|
||||
* PADDING frames.
|
||||
*/
|
||||
size_t ngtcp2_pkt_decode_padding_frame(ngtcp2_padding *dest,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen);
|
||||
ngtcp2_ssize ngtcp2_pkt_decode_padding_frame(ngtcp2_padding *dest,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen);
|
||||
|
||||
/*
|
||||
* ngtcp2_pkt_decode_reset_stream_frame decodes RESET_STREAM frame
|
||||
@@ -639,11 +634,7 @@ ngtcp2_ssize ngtcp2_pkt_decode_max_streams_frame(ngtcp2_max_streams *dest,
|
||||
* length |payloadlen|. The result is stored in the object pointed by
|
||||
* |dest|. PING frame must start at payload[0]. This function
|
||||
* finishes when it decodes one PING frame, and returns the exact
|
||||
* number of bytes read to decode a frame if it succeeds, or one of
|
||||
* the following negative error codes:
|
||||
*
|
||||
* NGTCP2_ERR_FRAME_ENCODING
|
||||
* Payload is too short to include PING frame.
|
||||
* number of bytes read to decode a frame.
|
||||
*/
|
||||
ngtcp2_ssize ngtcp2_pkt_decode_ping_frame(ngtcp2_ping *dest,
|
||||
const uint8_t *payload,
|
||||
@@ -773,7 +764,7 @@ ngtcp2_ssize ngtcp2_pkt_decode_path_response_frame(ngtcp2_path_response *dest,
|
||||
* NGTCP2_ERR_FRAME_ENCODING
|
||||
* Payload is too short to include CRYPTO frame.
|
||||
*/
|
||||
ngtcp2_ssize ngtcp2_pkt_decode_crypto_frame(ngtcp2_crypto *dest,
|
||||
ngtcp2_ssize ngtcp2_pkt_decode_crypto_frame(ngtcp2_stream *dest,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen);
|
||||
|
||||
@@ -814,11 +805,7 @@ ngtcp2_pkt_decode_retire_connection_id_frame(ngtcp2_retire_connection_id *dest,
|
||||
* object pointed by |dest|. HANDSHAKE_DONE frame must start at
|
||||
* payload[0]. This function finishes when it decodes one
|
||||
* HANDSHAKE_DONE frame, and returns the exact number of bytes read to
|
||||
* decode a frame if it succeeds, or one of the following negative
|
||||
* error codes:
|
||||
*
|
||||
* NGTCP2_ERR_FRAME_ENCODING
|
||||
* Payload is too short to include HANDSHAKE_DONE frame.
|
||||
* decode a frame.
|
||||
*/
|
||||
ngtcp2_ssize ngtcp2_pkt_decode_handshake_done_frame(ngtcp2_handshake_done *dest,
|
||||
const uint8_t *payload,
|
||||
@@ -1076,7 +1063,7 @@ ngtcp2_pkt_encode_path_response_frame(uint8_t *out, size_t outlen,
|
||||
* Buffer does not have enough capacity to write a frame.
|
||||
*/
|
||||
ngtcp2_ssize ngtcp2_pkt_encode_crypto_frame(uint8_t *out, size_t outlen,
|
||||
const ngtcp2_crypto *fr);
|
||||
const ngtcp2_stream *fr);
|
||||
|
||||
/*
|
||||
* ngtcp2_pkt_encode_new_token_frame encodes NEW_TOKEN frame |fr| into
|
||||
@@ -1142,14 +1129,19 @@ int64_t ngtcp2_pkt_adjust_pkt_num(int64_t max_pkt_num, int64_t pkt_num,
|
||||
|
||||
/*
|
||||
* ngtcp2_pkt_validate_ack checks that ack is malformed or not.
|
||||
* |min_pkt_num| is the minimum packet number that an endpoint sends.
|
||||
* It is an error to receive acknowledgements for a packet less than
|
||||
* |min_pkt_num|.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGTCP2_ERR_ACK_FRAME
|
||||
* ACK frame is malformed
|
||||
* NGTCP2_ERR_PROTO
|
||||
* |fr| contains a packet number less than |min_pkt_num|.
|
||||
*/
|
||||
int ngtcp2_pkt_validate_ack(ngtcp2_ack *fr);
|
||||
int ngtcp2_pkt_validate_ack(ngtcp2_ack *fr, int64_t min_pkt_num);
|
||||
|
||||
/*
|
||||
* ngtcp2_pkt_stream_max_datalen returns the maximum number of bytes
|
||||
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* ngtcp2
|
||||
*
|
||||
* Copyright (c) 2023 ngtcp2 contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef NGTCP2_PKTNS_ID_H
|
||||
#define NGTCP2_PKTNS_ID_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
||||
#include <ngtcp2/ngtcp2.h>
|
||||
|
||||
/**
|
||||
* @enum
|
||||
*
|
||||
* :type:`ngtcp2_pktns_id` defines packet number space identifier.
|
||||
*/
|
||||
typedef enum ngtcp2_pktns_id {
|
||||
/**
|
||||
* :enum:`NGTCP2_PKTNS_ID_INITIAL` is the Initial packet number
|
||||
* space.
|
||||
*/
|
||||
NGTCP2_PKTNS_ID_INITIAL,
|
||||
/**
|
||||
* :enum:`NGTCP2_PKTNS_ID_HANDSHAKE` is the Handshake packet number
|
||||
* space.
|
||||
*/
|
||||
NGTCP2_PKTNS_ID_HANDSHAKE,
|
||||
/**
|
||||
* :enum:`NGTCP2_PKTNS_ID_APPLICATION` is the Application data
|
||||
* packet number space.
|
||||
*/
|
||||
NGTCP2_PKTNS_ID_APPLICATION,
|
||||
/**
|
||||
* :enum:`NGTCP2_PKTNS_ID_MAX` is defined to get the number of
|
||||
* packet number spaces.
|
||||
*/
|
||||
NGTCP2_PKTNS_ID_MAX
|
||||
} ngtcp2_pktns_id;
|
||||
|
||||
#endif /* NGTCP2_PKTNS_ID_H */
|
||||
+7
-7
@@ -41,7 +41,7 @@ static size_t mtu_probes[] = {
|
||||
1492 - 48, /* PPPoE */
|
||||
};
|
||||
|
||||
static size_t mtu_probeslen = sizeof(mtu_probes) / sizeof(mtu_probes[0]);
|
||||
#define NGTCP2_MTU_PROBESLEN ngtcp2_arraylen(mtu_probes)
|
||||
|
||||
int ngtcp2_pmtud_new(ngtcp2_pmtud **ppmtud, size_t max_udp_payload_size,
|
||||
size_t hard_max_udp_payload_size, int64_t tx_pkt_num,
|
||||
@@ -61,7 +61,7 @@ int ngtcp2_pmtud_new(ngtcp2_pmtud **ppmtud, size_t max_udp_payload_size,
|
||||
pmtud->hard_max_udp_payload_size = hard_max_udp_payload_size;
|
||||
pmtud->min_fail_udp_payload_size = SIZE_MAX;
|
||||
|
||||
for (; pmtud->mtu_idx < mtu_probeslen; ++pmtud->mtu_idx) {
|
||||
for (; pmtud->mtu_idx < NGTCP2_MTU_PROBESLEN; ++pmtud->mtu_idx) {
|
||||
if (mtu_probes[pmtud->mtu_idx] > pmtud->hard_max_udp_payload_size) {
|
||||
continue;
|
||||
}
|
||||
@@ -84,7 +84,7 @@ void ngtcp2_pmtud_del(ngtcp2_pmtud *pmtud) {
|
||||
}
|
||||
|
||||
size_t ngtcp2_pmtud_probelen(ngtcp2_pmtud *pmtud) {
|
||||
assert(pmtud->mtu_idx < mtu_probeslen);
|
||||
assert(pmtud->mtu_idx < NGTCP2_MTU_PROBESLEN);
|
||||
|
||||
return mtu_probes[pmtud->mtu_idx];
|
||||
}
|
||||
@@ -107,13 +107,13 @@ int ngtcp2_pmtud_require_probe(ngtcp2_pmtud *pmtud) {
|
||||
}
|
||||
|
||||
static void pmtud_next_probe(ngtcp2_pmtud *pmtud) {
|
||||
assert(pmtud->mtu_idx < mtu_probeslen);
|
||||
assert(pmtud->mtu_idx < NGTCP2_MTU_PROBESLEN);
|
||||
|
||||
++pmtud->mtu_idx;
|
||||
pmtud->num_pkts_sent = 0;
|
||||
pmtud->expiry = UINT64_MAX;
|
||||
|
||||
for (; pmtud->mtu_idx < mtu_probeslen; ++pmtud->mtu_idx) {
|
||||
for (; pmtud->mtu_idx < NGTCP2_MTU_PROBESLEN; ++pmtud->mtu_idx) {
|
||||
if (mtu_probes[pmtud->mtu_idx] <= pmtud->max_udp_payload_size ||
|
||||
mtu_probes[pmtud->mtu_idx] > pmtud->hard_max_udp_payload_size) {
|
||||
continue;
|
||||
@@ -129,7 +129,7 @@ void ngtcp2_pmtud_probe_success(ngtcp2_pmtud *pmtud, size_t payloadlen) {
|
||||
pmtud->max_udp_payload_size =
|
||||
ngtcp2_max(pmtud->max_udp_payload_size, payloadlen);
|
||||
|
||||
assert(pmtud->mtu_idx < mtu_probeslen);
|
||||
assert(pmtud->mtu_idx < NGTCP2_MTU_PROBESLEN);
|
||||
|
||||
if (mtu_probes[pmtud->mtu_idx] > pmtud->max_udp_payload_size) {
|
||||
return;
|
||||
@@ -156,5 +156,5 @@ void ngtcp2_pmtud_handle_expiry(ngtcp2_pmtud *pmtud, ngtcp2_tstamp ts) {
|
||||
}
|
||||
|
||||
int ngtcp2_pmtud_finished(ngtcp2_pmtud *pmtud) {
|
||||
return pmtud->mtu_idx >= mtu_probeslen;
|
||||
return pmtud->mtu_idx >= NGTCP2_MTU_PROBESLEN;
|
||||
}
|
||||
Vendored
+2
-2
@@ -55,7 +55,7 @@ int ngtcp2_ppe_encode_hd(ngtcp2_ppe *ppe, const ngtcp2_pkt_hd *hd) {
|
||||
if (hd->flags & NGTCP2_PKT_FLAG_LONG_FORM) {
|
||||
ppe->len_offset = 1 + 4 + 1 + hd->dcid.datalen + 1 + hd->scid.datalen;
|
||||
if (hd->type == NGTCP2_PKT_INITIAL) {
|
||||
ppe->len_offset += ngtcp2_put_varint_len(hd->token.len) + hd->token.len;
|
||||
ppe->len_offset += ngtcp2_put_uvarintlen(hd->tokenlen) + hd->tokenlen;
|
||||
}
|
||||
ppe->pkt_num_offset = ppe->len_offset + NGTCP2_PKT_LENGTHLEN;
|
||||
rv = ngtcp2_pkt_encode_hd_long(
|
||||
@@ -115,7 +115,7 @@ ngtcp2_ssize ngtcp2_ppe_final(ngtcp2_ppe *ppe, const uint8_t **ppkt) {
|
||||
assert(cc->hp_mask);
|
||||
|
||||
if (ppe->len_offset) {
|
||||
ngtcp2_put_varint30(
|
||||
ngtcp2_put_uvarint30(
|
||||
buf->begin + ppe->len_offset,
|
||||
(uint16_t)(payloadlen + ppe->pkt_numlen + cc->aead.max_overhead));
|
||||
}
|
||||
|
||||
Vendored
-4
@@ -76,10 +76,6 @@ void ngtcp2_pv_entry_init(ngtcp2_pv_entry *pvent, const uint8_t *data,
|
||||
fallback DCID. If path validation succeeds, fallback DCID is
|
||||
retired if it does not equal to the current DCID. */
|
||||
#define NGTCP2_PV_FLAG_FALLBACK_ON_FAILURE 0x04u
|
||||
/* NGTCP2_PV_FLAG_MTU_PROBE indicates that a validation must probe
|
||||
least MTU that QUIC requires, which is 1200 bytes. If it fails, a
|
||||
path is not viable. */
|
||||
#define NGTCP2_PV_FLAG_MTU_PROBE 0x08u
|
||||
/* NGTCP2_PV_FLAG_PREFERRED_ADDR indicates that client is migrating to
|
||||
server's preferred address. This flag is only used by client. */
|
||||
#define NGTCP2_PV_FLAG_PREFERRED_ADDR 0x10u
|
||||
|
||||
Vendored
+73
-49
@@ -30,6 +30,8 @@
|
||||
#include "ngtcp2_vec.h"
|
||||
#include "ngtcp2_conv.h"
|
||||
#include "ngtcp2_net.h"
|
||||
#include "ngtcp2_unreachable.h"
|
||||
#include "ngtcp2_conn_stat.h"
|
||||
|
||||
void ngtcp2_qlog_init(ngtcp2_qlog *qlog, ngtcp2_qlog_write write,
|
||||
ngtcp2_tstamp ts, void *user_data) {
|
||||
@@ -284,9 +286,9 @@ static uint8_t *write_pkt_hd(uint8_t *p, const ngtcp2_pkt_hd *hd) {
|
||||
p = write_pair(p, "packet_type", qlog_pkt_type(hd));
|
||||
*p++ = ',';
|
||||
p = write_pair_number(p, "packet_number", (uint64_t)hd->pkt_num);
|
||||
if (hd->type == NGTCP2_PKT_INITIAL && hd->token.len) {
|
||||
if (hd->type == NGTCP2_PKT_INITIAL && hd->tokenlen) {
|
||||
p = write_verbatim(p, ",\"token\":{");
|
||||
p = write_pair_hex(p, "data", hd->token.base, hd->token.len);
|
||||
p = write_pair_hex(p, "data", hd->token, hd->tokenlen);
|
||||
*p++ = '}';
|
||||
}
|
||||
/* TODO Write DCIL and DCID */
|
||||
@@ -316,7 +318,7 @@ static uint8_t *write_ping_frame(uint8_t *p, const ngtcp2_ping *fr) {
|
||||
static uint8_t *write_ack_frame(uint8_t *p, const ngtcp2_ack *fr) {
|
||||
int64_t largest_ack, min_ack;
|
||||
size_t i;
|
||||
const ngtcp2_ack_blk *blk;
|
||||
const ngtcp2_ack_range *range;
|
||||
|
||||
/*
|
||||
* {"frame_type":"ack","ack_delay":0000000000000000000,"acked_ranges":[]}
|
||||
@@ -336,7 +338,7 @@ static uint8_t *write_ack_frame(uint8_t *p, const ngtcp2_ack *fr) {
|
||||
p = write_verbatim(p, ",\"acked_ranges\":[");
|
||||
|
||||
largest_ack = fr->largest_ack;
|
||||
min_ack = fr->largest_ack - (int64_t)fr->first_ack_blklen;
|
||||
min_ack = fr->largest_ack - (int64_t)fr->first_ack_range;
|
||||
|
||||
*p++ = '[';
|
||||
p = write_number(p, (uint64_t)min_ack);
|
||||
@@ -346,10 +348,10 @@ static uint8_t *write_ack_frame(uint8_t *p, const ngtcp2_ack *fr) {
|
||||
}
|
||||
*p++ = ']';
|
||||
|
||||
for (i = 0; i < fr->num_blks; ++i) {
|
||||
blk = &fr->blks[i];
|
||||
largest_ack = min_ack - (int64_t)blk->gap - 2;
|
||||
min_ack = largest_ack - (int64_t)blk->blklen;
|
||||
for (i = 0; i < fr->rangecnt; ++i) {
|
||||
range = &fr->ranges[i];
|
||||
largest_ack = min_ack - (int64_t)range->gap - 2;
|
||||
min_ack = largest_ack - (int64_t)range->len;
|
||||
*p++ = ',';
|
||||
*p++ = '[';
|
||||
p = write_number(p, (uint64_t)min_ack);
|
||||
@@ -410,7 +412,7 @@ static uint8_t *write_stop_sending_frame(uint8_t *p,
|
||||
return p;
|
||||
}
|
||||
|
||||
static uint8_t *write_crypto_frame(uint8_t *p, const ngtcp2_crypto *fr) {
|
||||
static uint8_t *write_crypto_frame(uint8_t *p, const ngtcp2_stream *fr) {
|
||||
/*
|
||||
* {"frame_type":"crypto","offset":0000000000000000000,"length":0000000000000000000}
|
||||
*/
|
||||
@@ -432,9 +434,9 @@ static uint8_t *write_new_token_frame(uint8_t *p, const ngtcp2_new_token *fr) {
|
||||
#define NGTCP2_QLOG_NEW_TOKEN_FRAME_OVERHEAD 75
|
||||
|
||||
p = write_verbatim(p, "{\"frame_type\":\"new_token\",");
|
||||
p = write_pair_number(p, "length", fr->token.len);
|
||||
p = write_pair_number(p, "length", fr->tokenlen);
|
||||
p = write_verbatim(p, ",\"token\":{");
|
||||
p = write_pair_hex(p, "data", fr->token.base, fr->token.len);
|
||||
p = write_pair_hex(p, "data", fr->token, fr->tokenlen);
|
||||
*p++ = '}';
|
||||
*p++ = '}';
|
||||
|
||||
@@ -513,45 +515,53 @@ static uint8_t *write_max_streams_frame(uint8_t *p,
|
||||
|
||||
static uint8_t *write_data_blocked_frame(uint8_t *p,
|
||||
const ngtcp2_data_blocked *fr) {
|
||||
(void)fr;
|
||||
|
||||
/*
|
||||
* {"frame_type":"data_blocked"}
|
||||
* {"frame_type":"data_blocked","limit":0000000000000000000}
|
||||
*/
|
||||
#define NGTCP2_QLOG_DATA_BLOCKED_FRAME_OVERHEAD 29
|
||||
#define NGTCP2_QLOG_DATA_BLOCKED_FRAME_OVERHEAD 57
|
||||
|
||||
/* TODO log limit */
|
||||
p = write_verbatim(p, "{\"frame_type\":\"data_blocked\",");
|
||||
p = write_pair_number(p, "limit", fr->offset);
|
||||
*p++ = '}';
|
||||
|
||||
return write_verbatim(p, "{\"frame_type\":\"data_blocked\"}");
|
||||
return p;
|
||||
}
|
||||
|
||||
static uint8_t *
|
||||
write_stream_data_blocked_frame(uint8_t *p,
|
||||
const ngtcp2_stream_data_blocked *fr) {
|
||||
(void)fr;
|
||||
|
||||
/*
|
||||
* {"frame_type":"stream_data_blocked"}
|
||||
* {"frame_type":"stream_data_blocked","stream_id":0000000000000000000,"limit":0000000000000000000}
|
||||
*/
|
||||
#define NGTCP2_QLOG_STREAM_DATA_BLOCKED_FRAME_OVERHEAD 36
|
||||
#define NGTCP2_QLOG_STREAM_DATA_BLOCKED_FRAME_OVERHEAD 96
|
||||
|
||||
/* TODO log limit */
|
||||
p = write_verbatim(p, "{\"frame_type\":\"stream_data_blocked\",");
|
||||
p = write_pair_number(p, "stream_id", (uint64_t)fr->stream_id);
|
||||
*p++ = ',';
|
||||
p = write_pair_number(p, "limit", fr->offset);
|
||||
*p++ = '}';
|
||||
|
||||
return write_verbatim(p, "{\"frame_type\":\"stream_data_blocked\"}");
|
||||
return p;
|
||||
}
|
||||
|
||||
static uint8_t *write_streams_blocked_frame(uint8_t *p,
|
||||
const ngtcp2_streams_blocked *fr) {
|
||||
(void)fr;
|
||||
|
||||
/*
|
||||
* {"frame_type":"streams_blocked"}
|
||||
* {"frame_type":"streams_blocked","stream_type":"unidirectional","limit":0000000000000000000}
|
||||
*/
|
||||
#define NGTCP2_QLOG_STREAMS_BLOCKED_FRAME_OVERHEAD 32
|
||||
#define NGTCP2_QLOG_STREAMS_BLOCKED_FRAME_OVERHEAD 91
|
||||
|
||||
/* TODO Log stream_type and limit */
|
||||
p = write_verbatim(p, "{\"frame_type\":\"streams_blocked\",\"stream_type\":");
|
||||
if (fr->type == NGTCP2_FRAME_STREAMS_BLOCKED_BIDI) {
|
||||
p = write_string(p, "bidirectional");
|
||||
} else {
|
||||
p = write_string(p, "unidirectional");
|
||||
}
|
||||
*p++ = ',';
|
||||
p = write_pair_number(p, "limit", fr->max_streams);
|
||||
*p++ = '}';
|
||||
|
||||
return write_verbatim(p, "{\"frame_type\":\"streams_blocked\"}");
|
||||
return p;
|
||||
}
|
||||
|
||||
static uint8_t *
|
||||
@@ -715,7 +725,7 @@ static void qlog_pkt_write_end(ngtcp2_qlog *qlog, const ngtcp2_pkt_hd *hd,
|
||||
(1 + 50 + NGTCP2_QLOG_PKT_HD_OVERHEAD)
|
||||
|
||||
if (ngtcp2_buf_left(&qlog->buf) <
|
||||
NGTCP2_QLOG_PKT_WRITE_END_OVERHEAD + hd->token.len * 2) {
|
||||
NGTCP2_QLOG_PKT_WRITE_END_OVERHEAD + hd->tokenlen * 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -765,7 +775,7 @@ void ngtcp2_qlog_write_frame(ngtcp2_qlog *qlog, const ngtcp2_frame *fr) {
|
||||
(size_t)(fr->type == NGTCP2_FRAME_ACK_ECN
|
||||
? NGTCP2_QLOG_ACK_FRAME_ECN_OVERHEAD
|
||||
: 0) +
|
||||
NGTCP2_QLOG_ACK_FRAME_RANGE_OVERHEAD * (1 + fr->ack.num_blks) + 1) {
|
||||
NGTCP2_QLOG_ACK_FRAME_RANGE_OVERHEAD * (1 + fr->ack.rangecnt) + 1) {
|
||||
return;
|
||||
}
|
||||
p = write_ack_frame(p, &fr->ack);
|
||||
@@ -788,11 +798,11 @@ void ngtcp2_qlog_write_frame(ngtcp2_qlog *qlog, const ngtcp2_frame *fr) {
|
||||
if (ngtcp2_buf_left(&qlog->buf) < NGTCP2_QLOG_CRYPTO_FRAME_OVERHEAD + 1) {
|
||||
return;
|
||||
}
|
||||
p = write_crypto_frame(p, &fr->crypto);
|
||||
p = write_crypto_frame(p, &fr->stream);
|
||||
break;
|
||||
case NGTCP2_FRAME_NEW_TOKEN:
|
||||
if (ngtcp2_buf_left(&qlog->buf) < NGTCP2_QLOG_NEW_TOKEN_FRAME_OVERHEAD +
|
||||
fr->new_token.token.len * 2 + 1) {
|
||||
if (ngtcp2_buf_left(&qlog->buf) <
|
||||
NGTCP2_QLOG_NEW_TOKEN_FRAME_OVERHEAD + fr->new_token.tokenlen * 2 + 1) {
|
||||
return;
|
||||
}
|
||||
p = write_new_token_frame(p, &fr->new_token);
|
||||
@@ -897,7 +907,7 @@ void ngtcp2_qlog_write_frame(ngtcp2_qlog *qlog, const ngtcp2_frame *fr) {
|
||||
p = write_datagram_frame(p, &fr->datagram);
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
ngtcp2_unreachable();
|
||||
}
|
||||
|
||||
*p++ = ',';
|
||||
@@ -929,6 +939,8 @@ void ngtcp2_qlog_parameters_set_transport_params(
|
||||
uint8_t buf[1024];
|
||||
uint8_t *p = buf;
|
||||
const ngtcp2_preferred_addr *paddr;
|
||||
const ngtcp2_sockaddr_in *sa_in;
|
||||
const ngtcp2_sockaddr_in6 *sa_in6;
|
||||
|
||||
if (!qlog->write) {
|
||||
return;
|
||||
@@ -996,20 +1008,33 @@ void ngtcp2_qlog_parameters_set_transport_params(
|
||||
*p++ = ',';
|
||||
p = write_pair_number(p, "initial_max_streams_uni",
|
||||
params->initial_max_streams_uni);
|
||||
if (params->preferred_address_present) {
|
||||
if (params->preferred_addr_present) {
|
||||
*p++ = ',';
|
||||
paddr = ¶ms->preferred_address;
|
||||
paddr = ¶ms->preferred_addr;
|
||||
p = write_string(p, "preferred_address");
|
||||
*p++ = ':';
|
||||
*p++ = '{';
|
||||
p = write_pair_hex(p, "ip_v4", paddr->ipv4_addr, sizeof(paddr->ipv4_addr));
|
||||
*p++ = ',';
|
||||
p = write_pair_number(p, "port_v4", paddr->ipv4_port);
|
||||
*p++ = ',';
|
||||
p = write_pair_hex(p, "ip_v6", paddr->ipv6_addr, sizeof(paddr->ipv6_addr));
|
||||
*p++ = ',';
|
||||
p = write_pair_number(p, "port_v6", paddr->ipv6_port);
|
||||
*p++ = ',';
|
||||
|
||||
if (paddr->ipv4_present) {
|
||||
sa_in = &paddr->ipv4;
|
||||
|
||||
p = write_pair_hex(p, "ip_v4", (const uint8_t *)&sa_in->sin_addr,
|
||||
sizeof(sa_in->sin_addr));
|
||||
*p++ = ',';
|
||||
p = write_pair_number(p, "port_v4", ngtcp2_ntohs(sa_in->sin_port));
|
||||
*p++ = ',';
|
||||
}
|
||||
|
||||
if (paddr->ipv6_present) {
|
||||
sa_in6 = &paddr->ipv6;
|
||||
|
||||
p = write_pair_hex(p, "ip_v6", (const uint8_t *)&sa_in6->sin6_addr,
|
||||
sizeof(sa_in6->sin6_addr));
|
||||
*p++ = ',';
|
||||
p = write_pair_number(p, "port_v6", ngtcp2_ntohs(sa_in6->sin6_port));
|
||||
*p++ = ',';
|
||||
}
|
||||
|
||||
p = write_pair_cid(p, "connection_id", &paddr->cid);
|
||||
p = write_verbatim(p, ",\"stateless_reset_token\":{");
|
||||
p = write_pair_hex(p, "data", paddr->stateless_reset_token,
|
||||
@@ -1113,16 +1138,15 @@ void ngtcp2_qlog_retry_pkt_received(ngtcp2_qlog *qlog, const ngtcp2_pkt_hd *hd,
|
||||
",\"name\":\"transport:packet_received\",\"data\":{\"header\":");
|
||||
|
||||
if (ngtcp2_buf_left(&buf) <
|
||||
NGTCP2_QLOG_PKT_HD_OVERHEAD + hd->token.len * 2 +
|
||||
NGTCP2_QLOG_PKT_HD_OVERHEAD + hd->tokenlen * 2 +
|
||||
sizeof(",\"retry_token\":{\"data\":\"\"}}}\n") - 1 +
|
||||
retry->token.len * 2) {
|
||||
retry->tokenlen * 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
buf.last = write_pkt_hd(buf.last, hd);
|
||||
buf.last = write_verbatim(buf.last, ",\"retry_token\":{");
|
||||
buf.last =
|
||||
write_pair_hex(buf.last, "data", retry->token.base, retry->token.len);
|
||||
buf.last = write_pair_hex(buf.last, "data", retry->token, retry->tokenlen);
|
||||
buf.last = write_verbatim(buf.last, "}}}\n");
|
||||
|
||||
qlog->write(qlog->user_data, NGTCP2_QLOG_WRITE_FLAG_NONE, buf.pos,
|
||||
|
||||
+15
-12
@@ -31,8 +31,9 @@
|
||||
|
||||
#include "ngtcp2_macro.h"
|
||||
|
||||
#if defined(_MSC_VER) && !defined(__clang__) && (defined(_M_ARM) || defined(_M_ARM64))
|
||||
unsigned int __popcnt(unsigned int x) {
|
||||
#if defined(_MSC_VER) && !defined(__clang__) && \
|
||||
(defined(_M_ARM) || defined(_M_ARM64))
|
||||
static unsigned int __popcnt(unsigned int x) {
|
||||
unsigned int c = 0;
|
||||
for (; x; ++c) {
|
||||
x &= x - 1;
|
||||
@@ -63,7 +64,7 @@ void ngtcp2_ringbuf_buf_init(ngtcp2_ringbuf *rb, size_t nmemb, size_t size,
|
||||
|
||||
rb->buf = buf;
|
||||
rb->mem = mem;
|
||||
rb->nmemb = nmemb;
|
||||
rb->mask = nmemb - 1;
|
||||
rb->size = size;
|
||||
rb->first = 0;
|
||||
rb->len = 0;
|
||||
@@ -78,17 +79,19 @@ void ngtcp2_ringbuf_free(ngtcp2_ringbuf *rb) {
|
||||
}
|
||||
|
||||
void *ngtcp2_ringbuf_push_front(ngtcp2_ringbuf *rb) {
|
||||
rb->first = (rb->first - 1) & (rb->nmemb - 1);
|
||||
rb->len = ngtcp2_min(rb->nmemb, rb->len + 1);
|
||||
rb->first = (rb->first - 1) & rb->mask;
|
||||
if (rb->len < rb->mask + 1) {
|
||||
++rb->len;
|
||||
}
|
||||
|
||||
return (void *)&rb->buf[rb->first * rb->size];
|
||||
}
|
||||
|
||||
void *ngtcp2_ringbuf_push_back(ngtcp2_ringbuf *rb) {
|
||||
size_t offset = (rb->first + rb->len) & (rb->nmemb - 1);
|
||||
size_t offset = (rb->first + rb->len) & rb->mask;
|
||||
|
||||
if (rb->len == rb->nmemb) {
|
||||
rb->first = (rb->first + 1) & (rb->nmemb - 1);
|
||||
if (rb->len == rb->mask + 1) {
|
||||
rb->first = (rb->first + 1) & rb->mask;
|
||||
} else {
|
||||
++rb->len;
|
||||
}
|
||||
@@ -97,7 +100,7 @@ void *ngtcp2_ringbuf_push_back(ngtcp2_ringbuf *rb) {
|
||||
}
|
||||
|
||||
void ngtcp2_ringbuf_pop_front(ngtcp2_ringbuf *rb) {
|
||||
rb->first = (rb->first + 1) & (rb->nmemb - 1);
|
||||
rb->first = (rb->first + 1) & rb->mask;
|
||||
--rb->len;
|
||||
}
|
||||
|
||||
@@ -107,14 +110,14 @@ void ngtcp2_ringbuf_pop_back(ngtcp2_ringbuf *rb) {
|
||||
}
|
||||
|
||||
void ngtcp2_ringbuf_resize(ngtcp2_ringbuf *rb, size_t len) {
|
||||
assert(len <= rb->nmemb);
|
||||
assert(len <= rb->mask + 1);
|
||||
rb->len = len;
|
||||
}
|
||||
|
||||
void *ngtcp2_ringbuf_get(ngtcp2_ringbuf *rb, size_t offset) {
|
||||
assert(offset < rb->len);
|
||||
offset = (rb->first + offset) & (rb->nmemb - 1);
|
||||
offset = (rb->first + offset) & rb->mask;
|
||||
return &rb->buf[offset * rb->size];
|
||||
}
|
||||
|
||||
int ngtcp2_ringbuf_full(ngtcp2_ringbuf *rb) { return rb->len == rb->nmemb; }
|
||||
int ngtcp2_ringbuf_full(ngtcp2_ringbuf *rb) { return rb->len == rb->mask + 1; }
|
||||
+3
-3
@@ -37,9 +37,9 @@ typedef struct ngtcp2_ringbuf {
|
||||
/* buf points to the underlying buffer. */
|
||||
uint8_t *buf;
|
||||
const ngtcp2_mem *mem;
|
||||
/* nmemb is the number of elements that can be stored in this ring
|
||||
buffer. */
|
||||
size_t nmemb;
|
||||
/* mask is the bit mask to cover all bits for the maximum number of
|
||||
elements. The maximum number of elements is mask + 1. */
|
||||
size_t mask;
|
||||
/* size is the size of each element. */
|
||||
size_t size;
|
||||
/* first is the offset to the first element. */
|
||||
|
||||
Vendored
+2
-4
@@ -218,7 +218,7 @@ int ngtcp2_rob_push(ngtcp2_rob *rob, uint64_t offset, const uint8_t *data,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ngtcp2_rob_remove_prefix(ngtcp2_rob *rob, uint64_t offset) {
|
||||
void ngtcp2_rob_remove_prefix(ngtcp2_rob *rob, uint64_t offset) {
|
||||
ngtcp2_rob_gap *g;
|
||||
ngtcp2_rob_data *d;
|
||||
ngtcp2_ksl_it it;
|
||||
@@ -245,13 +245,11 @@ int ngtcp2_rob_remove_prefix(ngtcp2_rob *rob, uint64_t offset) {
|
||||
for (; !ngtcp2_ksl_it_end(&it);) {
|
||||
d = ngtcp2_ksl_it_get(&it);
|
||||
if (offset < d->range.begin + rob->chunk) {
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
ngtcp2_ksl_remove_hint(&rob->dataksl, &it, &it, &d->range);
|
||||
ngtcp2_rob_data_del(d, rob->mem);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t ngtcp2_rob_data_at(ngtcp2_rob *rob, const uint8_t **pdest,
|
||||
|
||||
Vendored
+1
-7
@@ -152,14 +152,8 @@ int ngtcp2_rob_push(ngtcp2_rob *rob, uint64_t offset, const uint8_t *data,
|
||||
/*
|
||||
* ngtcp2_rob_remove_prefix removes gap up to |offset|, exclusive. It
|
||||
* also removes data buffer if it is completely included in |offset|.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGTCP2_ERR_NOMEM
|
||||
* Out of memory
|
||||
*/
|
||||
int ngtcp2_rob_remove_prefix(ngtcp2_rob *rob, uint64_t offset);
|
||||
void ngtcp2_rob_remove_prefix(ngtcp2_rob *rob, uint64_t offset);
|
||||
|
||||
/*
|
||||
* ngtcp2_rob_data_at stores the pointer to the buffer of stream
|
||||
|
||||
Vendored
+6
-7
@@ -29,6 +29,7 @@
|
||||
#include "ngtcp2_rtb.h"
|
||||
#include "ngtcp2_cc.h"
|
||||
#include "ngtcp2_macro.h"
|
||||
#include "ngtcp2_conn_stat.h"
|
||||
|
||||
void ngtcp2_rs_init(ngtcp2_rs *rs) {
|
||||
rs->interval = UINT64_MAX;
|
||||
@@ -69,8 +70,8 @@ void ngtcp2_rst_on_pkt_sent(ngtcp2_rst *rst, ngtcp2_rtb_entry *ent,
|
||||
ent->rst.lost = rst->lost;
|
||||
}
|
||||
|
||||
int ngtcp2_rst_on_ack_recv(ngtcp2_rst *rst, ngtcp2_conn_stat *cstat,
|
||||
uint64_t pkt_delivered) {
|
||||
void ngtcp2_rst_on_ack_recv(ngtcp2_rst *rst, ngtcp2_conn_stat *cstat,
|
||||
uint64_t pkt_delivered) {
|
||||
ngtcp2_rs *rs = &rst->rs;
|
||||
uint64_t rate;
|
||||
|
||||
@@ -84,7 +85,7 @@ int ngtcp2_rst_on_ack_recv(ngtcp2_rst *rst, ngtcp2_conn_stat *cstat,
|
||||
}
|
||||
|
||||
if (rs->prior_ts == 0) {
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
|
||||
rs->interval = ngtcp2_max(rs->send_elapsed, rs->ack_elapsed);
|
||||
@@ -94,11 +95,11 @@ int ngtcp2_rst_on_ack_recv(ngtcp2_rst *rst, ngtcp2_conn_stat *cstat,
|
||||
|
||||
if (rs->interval < cstat->min_rtt) {
|
||||
rs->interval = UINT64_MAX;
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!rs->interval) {
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
|
||||
rate = rs->delivered * NGTCP2_SECONDS / rs->interval;
|
||||
@@ -107,8 +108,6 @@ int ngtcp2_rst_on_ack_recv(ngtcp2_rst *rst, ngtcp2_conn_stat *cstat,
|
||||
ngtcp2_window_filter_update(&rst->wf, rate, rst->round_count);
|
||||
cstat->delivery_rate_sec = ngtcp2_window_filter_get_best(&rst->wf);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ngtcp2_rst_update_rate_sample(ngtcp2_rst *rst, const ngtcp2_rtb_entry *ent,
|
||||
|
||||
Vendored
+3
-2
@@ -34,6 +34,7 @@
|
||||
#include "ngtcp2_window_filter.h"
|
||||
|
||||
typedef struct ngtcp2_rtb_entry ngtcp2_rtb_entry;
|
||||
typedef struct ngtcp2_conn_stat ngtcp2_conn_stat;
|
||||
|
||||
/**
|
||||
* @struct
|
||||
@@ -76,8 +77,8 @@ void ngtcp2_rst_init(ngtcp2_rst *rst);
|
||||
|
||||
void ngtcp2_rst_on_pkt_sent(ngtcp2_rst *rst, ngtcp2_rtb_entry *ent,
|
||||
const ngtcp2_conn_stat *cstat);
|
||||
int ngtcp2_rst_on_ack_recv(ngtcp2_rst *rst, ngtcp2_conn_stat *cstat,
|
||||
uint64_t pkt_delivered);
|
||||
void ngtcp2_rst_on_ack_recv(ngtcp2_rst *rst, ngtcp2_conn_stat *cstat,
|
||||
uint64_t pkt_delivered);
|
||||
void ngtcp2_rst_update_rate_sample(ngtcp2_rst *rst, const ngtcp2_rtb_entry *ent,
|
||||
ngtcp2_tstamp ts);
|
||||
void ngtcp2_rst_update_app_limited(ngtcp2_rst *rst, ngtcp2_conn_stat *cstat);
|
||||
|
||||
Vendored
+69
-277
@@ -34,220 +34,11 @@
|
||||
#include "ngtcp2_cc.h"
|
||||
#include "ngtcp2_rcvry.h"
|
||||
#include "ngtcp2_rst.h"
|
||||
#include "ngtcp2_unreachable.h"
|
||||
#include "ngtcp2_tstamp.h"
|
||||
#include "ngtcp2_frame_chain.h"
|
||||
|
||||
int ngtcp2_frame_chain_new(ngtcp2_frame_chain **pfrc, const ngtcp2_mem *mem) {
|
||||
*pfrc = ngtcp2_mem_malloc(mem, sizeof(ngtcp2_frame_chain));
|
||||
if (*pfrc == NULL) {
|
||||
return NGTCP2_ERR_NOMEM;
|
||||
}
|
||||
|
||||
ngtcp2_frame_chain_init(*pfrc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ngtcp2_frame_chain_objalloc_new(ngtcp2_frame_chain **pfrc,
|
||||
ngtcp2_objalloc *objalloc) {
|
||||
*pfrc = ngtcp2_objalloc_frame_chain_get(objalloc);
|
||||
if (*pfrc == NULL) {
|
||||
return NGTCP2_ERR_NOMEM;
|
||||
}
|
||||
|
||||
ngtcp2_frame_chain_init(*pfrc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ngtcp2_frame_chain_extralen_new(ngtcp2_frame_chain **pfrc, size_t extralen,
|
||||
const ngtcp2_mem *mem) {
|
||||
*pfrc = ngtcp2_mem_malloc(mem, sizeof(ngtcp2_frame_chain) + extralen);
|
||||
if (*pfrc == NULL) {
|
||||
return NGTCP2_ERR_NOMEM;
|
||||
}
|
||||
|
||||
ngtcp2_frame_chain_init(*pfrc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ngtcp2_frame_chain_stream_datacnt_objalloc_new(ngtcp2_frame_chain **pfrc,
|
||||
size_t datacnt,
|
||||
ngtcp2_objalloc *objalloc,
|
||||
const ngtcp2_mem *mem) {
|
||||
size_t need, avail = sizeof(ngtcp2_frame) - sizeof(ngtcp2_stream);
|
||||
|
||||
if (datacnt > 1) {
|
||||
need = sizeof(ngtcp2_vec) * (datacnt - 1);
|
||||
|
||||
if (need > avail) {
|
||||
return ngtcp2_frame_chain_extralen_new(pfrc, need - avail, mem);
|
||||
}
|
||||
}
|
||||
|
||||
return ngtcp2_frame_chain_objalloc_new(pfrc, objalloc);
|
||||
}
|
||||
|
||||
int ngtcp2_frame_chain_crypto_datacnt_objalloc_new(ngtcp2_frame_chain **pfrc,
|
||||
size_t datacnt,
|
||||
ngtcp2_objalloc *objalloc,
|
||||
const ngtcp2_mem *mem) {
|
||||
size_t need, avail = sizeof(ngtcp2_frame) - sizeof(ngtcp2_crypto);
|
||||
|
||||
if (datacnt > 1) {
|
||||
need = sizeof(ngtcp2_vec) * (datacnt - 1);
|
||||
|
||||
if (need > avail) {
|
||||
return ngtcp2_frame_chain_extralen_new(pfrc, need - avail, mem);
|
||||
}
|
||||
}
|
||||
|
||||
return ngtcp2_frame_chain_objalloc_new(pfrc, objalloc);
|
||||
}
|
||||
|
||||
int ngtcp2_frame_chain_new_token_objalloc_new(ngtcp2_frame_chain **pfrc,
|
||||
const ngtcp2_vec *token,
|
||||
ngtcp2_objalloc *objalloc,
|
||||
const ngtcp2_mem *mem) {
|
||||
size_t avail = sizeof(ngtcp2_frame) - sizeof(ngtcp2_new_token);
|
||||
int rv;
|
||||
uint8_t *p;
|
||||
ngtcp2_frame *fr;
|
||||
|
||||
if (token->len > avail) {
|
||||
rv = ngtcp2_frame_chain_extralen_new(pfrc, token->len - avail, mem);
|
||||
} else {
|
||||
rv = ngtcp2_frame_chain_objalloc_new(pfrc, objalloc);
|
||||
}
|
||||
if (rv != 0) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
fr = &(*pfrc)->fr;
|
||||
fr->type = NGTCP2_FRAME_NEW_TOKEN;
|
||||
|
||||
p = (uint8_t *)fr + sizeof(ngtcp2_new_token);
|
||||
memcpy(p, token->base, token->len);
|
||||
|
||||
ngtcp2_vec_init(&fr->new_token.token, p, token->len);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ngtcp2_frame_chain_del(ngtcp2_frame_chain *frc, const ngtcp2_mem *mem) {
|
||||
ngtcp2_frame_chain_binder *binder;
|
||||
|
||||
if (frc == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
binder = frc->binder;
|
||||
if (binder && --binder->refcount == 0) {
|
||||
ngtcp2_mem_free(mem, binder);
|
||||
}
|
||||
|
||||
ngtcp2_mem_free(mem, frc);
|
||||
}
|
||||
|
||||
void ngtcp2_frame_chain_objalloc_del(ngtcp2_frame_chain *frc,
|
||||
ngtcp2_objalloc *objalloc,
|
||||
const ngtcp2_mem *mem) {
|
||||
ngtcp2_frame_chain_binder *binder;
|
||||
|
||||
if (frc == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (frc->fr.type) {
|
||||
case NGTCP2_FRAME_STREAM:
|
||||
if (frc->fr.stream.datacnt &&
|
||||
sizeof(ngtcp2_vec) * (frc->fr.stream.datacnt - 1) >
|
||||
sizeof(ngtcp2_frame) - sizeof(ngtcp2_stream)) {
|
||||
ngtcp2_frame_chain_del(frc, mem);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
case NGTCP2_FRAME_CRYPTO:
|
||||
if (frc->fr.crypto.datacnt &&
|
||||
sizeof(ngtcp2_vec) * (frc->fr.crypto.datacnt - 1) >
|
||||
sizeof(ngtcp2_frame) - sizeof(ngtcp2_crypto)) {
|
||||
ngtcp2_frame_chain_del(frc, mem);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
case NGTCP2_FRAME_NEW_TOKEN:
|
||||
if (frc->fr.new_token.token.len >
|
||||
sizeof(ngtcp2_frame) - sizeof(ngtcp2_new_token)) {
|
||||
ngtcp2_frame_chain_del(frc, mem);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
binder = frc->binder;
|
||||
if (binder && --binder->refcount == 0) {
|
||||
ngtcp2_mem_free(mem, binder);
|
||||
}
|
||||
|
||||
frc->binder = NULL;
|
||||
|
||||
ngtcp2_objalloc_frame_chain_release(objalloc, frc);
|
||||
}
|
||||
|
||||
void ngtcp2_frame_chain_init(ngtcp2_frame_chain *frc) {
|
||||
frc->next = NULL;
|
||||
frc->binder = NULL;
|
||||
}
|
||||
|
||||
void ngtcp2_frame_chain_list_objalloc_del(ngtcp2_frame_chain *frc,
|
||||
ngtcp2_objalloc *objalloc,
|
||||
const ngtcp2_mem *mem) {
|
||||
ngtcp2_frame_chain *next;
|
||||
|
||||
for (; frc; frc = next) {
|
||||
next = frc->next;
|
||||
|
||||
ngtcp2_frame_chain_objalloc_del(frc, objalloc, mem);
|
||||
}
|
||||
}
|
||||
|
||||
int ngtcp2_frame_chain_binder_new(ngtcp2_frame_chain_binder **pbinder,
|
||||
const ngtcp2_mem *mem) {
|
||||
*pbinder = ngtcp2_mem_calloc(mem, 1, sizeof(ngtcp2_frame_chain_binder));
|
||||
if (*pbinder == NULL) {
|
||||
return NGTCP2_ERR_NOMEM;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ngtcp2_bind_frame_chains(ngtcp2_frame_chain *a, ngtcp2_frame_chain *b,
|
||||
const ngtcp2_mem *mem) {
|
||||
ngtcp2_frame_chain_binder *binder;
|
||||
int rv;
|
||||
|
||||
assert(b->binder == NULL);
|
||||
|
||||
if (a->binder == NULL) {
|
||||
rv = ngtcp2_frame_chain_binder_new(&binder, mem);
|
||||
if (rv != 0) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
a->binder = binder;
|
||||
++a->binder->refcount;
|
||||
}
|
||||
|
||||
b->binder = a->binder;
|
||||
++b->binder->refcount;
|
||||
|
||||
return 0;
|
||||
}
|
||||
ngtcp2_objalloc_def(rtb_entry, ngtcp2_rtb_entry, oplent);
|
||||
|
||||
static void rtb_entry_init(ngtcp2_rtb_entry *ent, const ngtcp2_pkt_hd *hd,
|
||||
ngtcp2_frame_chain *frc, ngtcp2_tstamp ts,
|
||||
@@ -297,7 +88,7 @@ static int greater(const ngtcp2_ksl_key *lhs, const ngtcp2_ksl_key *rhs) {
|
||||
|
||||
void ngtcp2_rtb_init(ngtcp2_rtb *rtb, ngtcp2_pktns_id pktns_id,
|
||||
ngtcp2_strm *crypto, ngtcp2_rst *rst, ngtcp2_cc *cc,
|
||||
ngtcp2_log *log, ngtcp2_qlog *qlog,
|
||||
int64_t cc_pkt_num, ngtcp2_log *log, ngtcp2_qlog *qlog,
|
||||
ngtcp2_objalloc *rtb_entry_objalloc,
|
||||
ngtcp2_objalloc *frc_objalloc, const ngtcp2_mem *mem) {
|
||||
rtb->rtb_entry_objalloc = rtb_entry_objalloc;
|
||||
@@ -315,7 +106,7 @@ void ngtcp2_rtb_init(ngtcp2_rtb *rtb, ngtcp2_pktns_id pktns_id,
|
||||
rtb->num_pto_eliciting = 0;
|
||||
rtb->probe_pkt_left = 0;
|
||||
rtb->pktns_id = pktns_id;
|
||||
rtb->cc_pkt_num = 0;
|
||||
rtb->cc_pkt_num = cc_pkt_num;
|
||||
rtb->cc_bytes_in_flight = 0;
|
||||
rtb->persistent_congestion_start_ts = UINT64_MAX;
|
||||
rtb->num_lost_pkts = 0;
|
||||
@@ -432,7 +223,6 @@ static ngtcp2_ssize rtb_reclaim_frame(ngtcp2_rtb *rtb, uint8_t flags,
|
||||
ngtcp2_range gap, range;
|
||||
size_t num_reclaimed = 0;
|
||||
int rv;
|
||||
int streamfrq_empty;
|
||||
|
||||
assert(ent->flags & NGTCP2_RTB_ENTRY_FLAG_RETRANSMITTABLE);
|
||||
|
||||
@@ -487,7 +277,6 @@ static ngtcp2_ssize rtb_reclaim_frame(ngtcp2_rtb *rtb, uint8_t flags,
|
||||
ngtcp2_vec_copy(nfrc->fr.stream.data, fr->stream.data,
|
||||
fr->stream.datacnt);
|
||||
|
||||
streamfrq_empty = ngtcp2_strm_streamfrq_empty(strm);
|
||||
rv = ngtcp2_strm_streamfrq_push(strm, nfrc);
|
||||
if (rv != 0) {
|
||||
ngtcp2_frame_chain_objalloc_del(nfrc, rtb->frc_objalloc, rtb->mem);
|
||||
@@ -500,9 +289,6 @@ static ngtcp2_ssize rtb_reclaim_frame(ngtcp2_rtb *rtb, uint8_t flags,
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
if (streamfrq_empty) {
|
||||
++conn->tx.strmq_nretrans;
|
||||
}
|
||||
|
||||
++num_reclaimed;
|
||||
|
||||
@@ -510,28 +296,27 @@ static ngtcp2_ssize rtb_reclaim_frame(ngtcp2_rtb *rtb, uint8_t flags,
|
||||
case NGTCP2_FRAME_CRYPTO:
|
||||
/* Don't resend CRYPTO frame if the whole region it contains has
|
||||
been acknowledged */
|
||||
gap = ngtcp2_strm_get_unacked_range_after(rtb->crypto, fr->crypto.offset);
|
||||
gap = ngtcp2_strm_get_unacked_range_after(rtb->crypto, fr->stream.offset);
|
||||
|
||||
range.begin = fr->crypto.offset;
|
||||
range.end = fr->crypto.offset +
|
||||
ngtcp2_vec_len(fr->crypto.data, fr->crypto.datacnt);
|
||||
range.begin = fr->stream.offset;
|
||||
range.end = fr->stream.offset +
|
||||
ngtcp2_vec_len(fr->stream.data, fr->stream.datacnt);
|
||||
range = ngtcp2_range_intersect(&range, &gap);
|
||||
if (ngtcp2_range_len(&range) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
rv = ngtcp2_frame_chain_crypto_datacnt_objalloc_new(
|
||||
&nfrc, fr->crypto.datacnt, rtb->frc_objalloc, rtb->mem);
|
||||
rv = ngtcp2_frame_chain_stream_datacnt_objalloc_new(
|
||||
&nfrc, fr->stream.datacnt, rtb->frc_objalloc, rtb->mem);
|
||||
if (rv != 0) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nfrc->fr = *fr;
|
||||
ngtcp2_vec_copy(nfrc->fr.crypto.data, fr->crypto.data,
|
||||
fr->crypto.datacnt);
|
||||
ngtcp2_vec_copy(nfrc->fr.stream.data, fr->stream.data,
|
||||
fr->stream.datacnt);
|
||||
|
||||
rv = ngtcp2_ksl_insert(&pktns->crypto.tx.frq, NULL,
|
||||
&nfrc->fr.crypto.offset, nfrc);
|
||||
rv = ngtcp2_strm_streamfrq_push(&pktns->crypto.strm, nfrc);
|
||||
if (rv != 0) {
|
||||
assert(ngtcp2_err_is_fatal(rv));
|
||||
ngtcp2_frame_chain_objalloc_del(nfrc, rtb->frc_objalloc, rtb->mem);
|
||||
@@ -543,7 +328,8 @@ static ngtcp2_ssize rtb_reclaim_frame(ngtcp2_rtb *rtb, uint8_t flags,
|
||||
continue;
|
||||
case NGTCP2_FRAME_NEW_TOKEN:
|
||||
rv = ngtcp2_frame_chain_new_token_objalloc_new(
|
||||
&nfrc, &fr->new_token.token, rtb->frc_objalloc, rtb->mem);
|
||||
&nfrc, fr->new_token.token, fr->new_token.tokenlen, rtb->frc_objalloc,
|
||||
rtb->mem);
|
||||
if (rv != 0) {
|
||||
return rv;
|
||||
}
|
||||
@@ -638,7 +424,7 @@ static int rtb_on_pkt_lost(ngtcp2_rtb *rtb, ngtcp2_ksl_it *it,
|
||||
}
|
||||
|
||||
if (ent->flags & NGTCP2_RTB_ENTRY_FLAG_PTO_RECLAIMED) {
|
||||
ngtcp2_log_info(rtb->log, NGTCP2_LOG_EVENT_RCV,
|
||||
ngtcp2_log_info(rtb->log, NGTCP2_LOG_EVENT_LDC,
|
||||
"pkn=%" PRId64 " has already been reclaimed on PTO",
|
||||
ent->hd.pkt_num);
|
||||
assert(!(ent->flags & NGTCP2_RTB_ENTRY_FLAG_LOST_RETRANSMITTED));
|
||||
@@ -770,6 +556,10 @@ static int rtb_process_acked_pkt(ngtcp2_rtb *rtb, ngtcp2_rtb_entry *ent,
|
||||
|
||||
for (frc = ent->frc; frc; frc = frc->next) {
|
||||
if (frc->binder) {
|
||||
if (frc->binder->flags & NGTCP2_FRAME_CHAIN_BINDER_FLAG_ACK) {
|
||||
continue;
|
||||
}
|
||||
|
||||
frc->binder->flags |= NGTCP2_FRAME_CHAIN_BINDER_FLAG_ACK;
|
||||
}
|
||||
|
||||
@@ -817,8 +607,8 @@ static int rtb_process_acked_pkt(ngtcp2_rtb *rtb, ngtcp2_rtb_entry *ent,
|
||||
case NGTCP2_FRAME_CRYPTO:
|
||||
prev_stream_offset = ngtcp2_strm_get_acked_offset(crypto);
|
||||
rv = ngtcp2_strm_ack_data(
|
||||
crypto, frc->fr.crypto.offset,
|
||||
ngtcp2_vec_len(frc->fr.crypto.data, frc->fr.crypto.datacnt));
|
||||
crypto, frc->fr.stream.offset,
|
||||
ngtcp2_vec_len(frc->fr.stream.data, frc->fr.stream.datacnt));
|
||||
if (rv != 0) {
|
||||
return rv;
|
||||
}
|
||||
@@ -840,7 +630,7 @@ static int rtb_process_acked_pkt(ngtcp2_rtb *rtb, ngtcp2_rtb_entry *ent,
|
||||
pktns = &conn->pktns;
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
ngtcp2_unreachable();
|
||||
}
|
||||
|
||||
conn_ack_crypto_data(conn, pktns, datalen);
|
||||
@@ -851,7 +641,7 @@ static int rtb_process_acked_pkt(ngtcp2_rtb *rtb, ngtcp2_rtb_entry *ent,
|
||||
if (strm == NULL) {
|
||||
break;
|
||||
}
|
||||
strm->flags |= NGTCP2_STRM_FLAG_RST_ACKED;
|
||||
strm->flags |= NGTCP2_STRM_FLAG_RESET_STREAM_ACKED;
|
||||
rv = ngtcp2_conn_close_stream_if_shut_rdwr(conn, strm);
|
||||
if (rv != 0) {
|
||||
return rv;
|
||||
@@ -861,6 +651,12 @@ static int rtb_process_acked_pkt(ngtcp2_rtb *rtb, ngtcp2_rtb_entry *ent,
|
||||
ngtcp2_conn_untrack_retired_dcid_seq(conn,
|
||||
frc->fr.retire_connection_id.seq);
|
||||
break;
|
||||
case NGTCP2_FRAME_NEW_CONNECTION_ID:
|
||||
assert(conn->scid.num_in_flight);
|
||||
|
||||
--conn->scid.num_in_flight;
|
||||
|
||||
break;
|
||||
case NGTCP2_FRAME_DATAGRAM:
|
||||
case NGTCP2_FRAME_DATAGRAM_LEN:
|
||||
if (!conn->callbacks.ack_datagram) {
|
||||
@@ -885,12 +681,14 @@ static void rtb_on_pkt_acked(ngtcp2_rtb *rtb, ngtcp2_rtb_entry *ent,
|
||||
|
||||
ngtcp2_rst_update_rate_sample(rtb->rst, ent, ts);
|
||||
|
||||
cc->on_pkt_acked(cc, cstat,
|
||||
ngtcp2_cc_pkt_init(&pkt, ent->hd.pkt_num, ent->pktlen,
|
||||
rtb->pktns_id, ent->ts, ent->rst.lost,
|
||||
ent->rst.tx_in_flight,
|
||||
ent->rst.is_app_limited),
|
||||
ts);
|
||||
if (cc->on_pkt_acked) {
|
||||
cc->on_pkt_acked(cc, cstat,
|
||||
ngtcp2_cc_pkt_init(&pkt, ent->hd.pkt_num, ent->pktlen,
|
||||
rtb->pktns_id, ent->ts, ent->rst.lost,
|
||||
ent->rst.tx_in_flight,
|
||||
ent->rst.is_app_limited),
|
||||
ts);
|
||||
}
|
||||
|
||||
if (!(ent->flags & NGTCP2_RTB_ENTRY_FLAG_PROBE) &&
|
||||
(ent->flags & NGTCP2_RTB_ENTRY_FLAG_ACK_ELICITING)) {
|
||||
@@ -901,7 +699,7 @@ static void rtb_on_pkt_acked(ngtcp2_rtb *rtb, ngtcp2_rtb_entry *ent,
|
||||
static void conn_verify_ecn(ngtcp2_conn *conn, ngtcp2_pktns *pktns,
|
||||
ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
|
||||
const ngtcp2_ack *fr, size_t ecn_acked,
|
||||
ngtcp2_tstamp largest_acked_sent_ts,
|
||||
ngtcp2_tstamp largest_pkt_sent_ts,
|
||||
ngtcp2_tstamp ts) {
|
||||
if (conn->tx.ecn.state == NGTCP2_ECN_STATE_FAILED) {
|
||||
return;
|
||||
@@ -928,9 +726,9 @@ static void conn_verify_ecn(ngtcp2_conn *conn, ngtcp2_pktns *pktns,
|
||||
}
|
||||
|
||||
if (fr->type == NGTCP2_FRAME_ACK_ECN) {
|
||||
if (largest_acked_sent_ts != UINT64_MAX &&
|
||||
if (cc->congestion_event && largest_pkt_sent_ts != UINT64_MAX &&
|
||||
fr->ecn.ce > pktns->rx.ecn.ack.ce) {
|
||||
cc->congestion_event(cc, cstat, largest_acked_sent_ts, ts);
|
||||
cc->congestion_event(cc, cstat, largest_pkt_sent_ts, ts);
|
||||
}
|
||||
|
||||
pktns->rx.ecn.ack.ect0 = fr->ecn.ect0;
|
||||
@@ -954,7 +752,6 @@ ngtcp2_ssize ngtcp2_rtb_recv_ack(ngtcp2_rtb *rtb, const ngtcp2_ack *fr,
|
||||
ngtcp2_ksl_it it;
|
||||
ngtcp2_ssize num_acked = 0;
|
||||
ngtcp2_tstamp largest_pkt_sent_ts = UINT64_MAX;
|
||||
ngtcp2_tstamp largest_acked_sent_ts = UINT64_MAX;
|
||||
int64_t pkt_num;
|
||||
ngtcp2_cc *cc = rtb->cc;
|
||||
ngtcp2_rtb_entry *acked_ent = NULL;
|
||||
@@ -987,12 +784,12 @@ ngtcp2_ssize ngtcp2_rtb_recv_ack(ngtcp2_rtb *rtb, const ngtcp2_ack *fr,
|
||||
if (ngtcp2_ksl_it_end(&it)) {
|
||||
if (conn && verify_ecn) {
|
||||
conn_verify_ecn(conn, pktns, rtb->cc, cstat, fr, ecn_acked,
|
||||
largest_acked_sent_ts, ts);
|
||||
largest_pkt_sent_ts, ts);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
min_ack = largest_ack - (int64_t)fr->first_ack_blklen;
|
||||
min_ack = largest_ack - (int64_t)fr->first_ack_range;
|
||||
|
||||
for (; !ngtcp2_ksl_it_end(&it);) {
|
||||
pkt_num = *(int64_t *)ngtcp2_ksl_it_key(&it);
|
||||
@@ -1017,9 +814,9 @@ ngtcp2_ssize ngtcp2_rtb_recv_ack(ngtcp2_rtb *rtb, const ngtcp2_ack *fr,
|
||||
++num_acked;
|
||||
}
|
||||
|
||||
for (i = 0; i < fr->num_blks;) {
|
||||
largest_ack = min_ack - (int64_t)fr->blks[i].gap - 2;
|
||||
min_ack = largest_ack - (int64_t)fr->blks[i].blklen;
|
||||
for (i = 0; i < fr->rangecnt;) {
|
||||
largest_ack = min_ack - (int64_t)fr->ranges[i].gap - 2;
|
||||
min_ack = largest_ack - (int64_t)fr->ranges[i].len;
|
||||
|
||||
it = ngtcp2_ksl_lower_bound(&rtb->ents, &largest_ack);
|
||||
if (ngtcp2_ksl_it_end(&it)) {
|
||||
@@ -1060,11 +857,6 @@ ngtcp2_ssize ngtcp2_rtb_recv_ack(ngtcp2_rtb *rtb, const ngtcp2_ack *fr,
|
||||
++ecn_acked;
|
||||
}
|
||||
|
||||
assert(largest_acked_sent_ts == UINT64_MAX ||
|
||||
largest_acked_sent_ts <= ent->ts);
|
||||
|
||||
largest_acked_sent_ts = ent->ts;
|
||||
|
||||
rv = rtb_process_acked_pkt(rtb, ent, conn);
|
||||
if (rv != 0) {
|
||||
goto fail;
|
||||
@@ -1085,7 +877,7 @@ ngtcp2_ssize ngtcp2_rtb_recv_ack(ngtcp2_rtb *rtb, const ngtcp2_ack *fr,
|
||||
|
||||
if (verify_ecn) {
|
||||
conn_verify_ecn(conn, pktns, rtb->cc, cstat, fr, ecn_acked,
|
||||
largest_acked_sent_ts, ts);
|
||||
largest_pkt_sent_ts, ts);
|
||||
}
|
||||
} else {
|
||||
/* For unit tests */
|
||||
@@ -1113,8 +905,10 @@ ngtcp2_ssize ngtcp2_rtb_recv_ack(ngtcp2_rtb *rtb, const ngtcp2_ack *fr,
|
||||
|
||||
rtb->rst->lost += cc_ack.bytes_lost;
|
||||
|
||||
cc_ack.largest_acked_sent_ts = largest_acked_sent_ts;
|
||||
cc->on_ack_recv(cc, cstat, &cc_ack, ts);
|
||||
cc_ack.largest_pkt_sent_ts = largest_pkt_sent_ts;
|
||||
if (cc->on_ack_recv) {
|
||||
cc->on_ack_recv(cc, cstat, &cc_ack, ts);
|
||||
}
|
||||
|
||||
return num_acked;
|
||||
|
||||
@@ -1133,7 +927,7 @@ static int rtb_pkt_lost(ngtcp2_rtb *rtb, ngtcp2_conn_stat *cstat,
|
||||
size_t pkt_thres, ngtcp2_tstamp ts) {
|
||||
ngtcp2_tstamp loss_time;
|
||||
|
||||
if (ent->ts + loss_delay <= ts ||
|
||||
if (ngtcp2_tstamp_elapsed(ent->ts, loss_delay, ts) ||
|
||||
rtb->largest_acked_tx_pkt_num >= ent->hd.pkt_num + (int64_t)pkt_thres) {
|
||||
return 1;
|
||||
}
|
||||
@@ -1189,7 +983,7 @@ static int rtb_detect_lost_pkt(ngtcp2_rtb *rtb, uint64_t *ppkt_lost,
|
||||
ngtcp2_cc *cc = rtb->cc;
|
||||
int rv;
|
||||
uint64_t pkt_thres =
|
||||
rtb->cc_bytes_in_flight / cstat->max_udp_payload_size / 2;
|
||||
rtb->cc_bytes_in_flight / cstat->max_tx_udp_payload_size / 2;
|
||||
size_t ecn_pkt_lost = 0;
|
||||
ngtcp2_tstamp start_ts;
|
||||
ngtcp2_duration pto = ngtcp2_conn_compute_pto(conn, pktns);
|
||||
@@ -1288,7 +1082,9 @@ static int rtb_detect_lost_pkt(ngtcp2_rtb *rtb, uint64_t *ppkt_lost,
|
||||
break;
|
||||
}
|
||||
|
||||
cc->congestion_event(cc, cstat, latest_ts, ts);
|
||||
if (cc->congestion_event) {
|
||||
cc->congestion_event(cc, cstat, latest_ts, ts);
|
||||
}
|
||||
|
||||
loss_window = latest_ts - oldest_ts;
|
||||
/* Persistent congestion situation is only evaluated for app
|
||||
@@ -1300,7 +1096,7 @@ static int rtb_detect_lost_pkt(ngtcp2_rtb *rtb, uint64_t *ppkt_lost,
|
||||
*/
|
||||
if (rtb->pktns_id == NGTCP2_PKTNS_ID_APPLICATION && loss_window > 0) {
|
||||
if (loss_window >= congestion_period) {
|
||||
ngtcp2_log_info(rtb->log, NGTCP2_LOG_EVENT_RCV,
|
||||
ngtcp2_log_info(rtb->log, NGTCP2_LOG_EVENT_LDC,
|
||||
"persistent congestion loss_window=%" PRIu64
|
||||
" congestion_period=%" PRIu64,
|
||||
loss_window, congestion_period);
|
||||
@@ -1312,7 +1108,9 @@ static int rtb_detect_lost_pkt(ngtcp2_rtb *rtb, uint64_t *ppkt_lost,
|
||||
cstat->rttvar = conn->local.settings.initial_rtt / 2;
|
||||
cstat->first_rtt_sample_ts = UINT64_MAX;
|
||||
|
||||
cc->on_persistent_congestion(cc, cstat, ts);
|
||||
if (cc->on_persistent_congestion) {
|
||||
cc->on_persistent_congestion(cc, cstat, ts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1349,7 +1147,7 @@ void ngtcp2_rtb_remove_excessive_lost_pkt(ngtcp2_rtb *rtb, size_t n) {
|
||||
|
||||
assert(ent->flags & NGTCP2_RTB_ENTRY_FLAG_LOST_RETRANSMITTED);
|
||||
|
||||
ngtcp2_log_info(rtb->log, NGTCP2_LOG_EVENT_RCV,
|
||||
ngtcp2_log_info(rtb->log, NGTCP2_LOG_EVENT_LDC,
|
||||
"removing stale lost pkn=%" PRId64, ent->hd.pkt_num);
|
||||
|
||||
--rtb->num_lost_pkts;
|
||||
@@ -1389,7 +1187,7 @@ void ngtcp2_rtb_remove_expired_lost_pkt(ngtcp2_rtb *rtb, ngtcp2_duration pto,
|
||||
return;
|
||||
}
|
||||
|
||||
ngtcp2_log_info(rtb->log, NGTCP2_LOG_EVENT_RCV,
|
||||
ngtcp2_log_info(rtb->log, NGTCP2_LOG_EVENT_LDC,
|
||||
"removing stale lost pkn=%" PRId64, ent->hd.pkt_num);
|
||||
|
||||
--rtb->num_lost_pkts;
|
||||
@@ -1435,7 +1233,6 @@ static int rtb_on_pkt_lost_resched_move(ngtcp2_rtb *rtb, ngtcp2_conn *conn,
|
||||
ngtcp2_stream *sfr;
|
||||
ngtcp2_strm *strm;
|
||||
int rv;
|
||||
int streamfrq_empty;
|
||||
|
||||
ngtcp2_log_pkt_lost(rtb->log, ent->hd.pkt_num, ent->hd.type, ent->hd.flags,
|
||||
ent->ts);
|
||||
@@ -1445,7 +1242,7 @@ static int rtb_on_pkt_lost_resched_move(ngtcp2_rtb *rtb, ngtcp2_conn *conn,
|
||||
}
|
||||
|
||||
if (ent->flags & NGTCP2_RTB_ENTRY_FLAG_PROBE) {
|
||||
ngtcp2_log_info(rtb->log, NGTCP2_LOG_EVENT_RCV,
|
||||
ngtcp2_log_info(rtb->log, NGTCP2_LOG_EVENT_LDC,
|
||||
"pkn=%" PRId64
|
||||
" is a probe packet, no retransmission is necessary",
|
||||
ent->hd.pkt_num);
|
||||
@@ -1453,7 +1250,7 @@ static int rtb_on_pkt_lost_resched_move(ngtcp2_rtb *rtb, ngtcp2_conn *conn,
|
||||
}
|
||||
|
||||
if (ent->flags & NGTCP2_RTB_ENTRY_FLAG_PMTUD_PROBE) {
|
||||
ngtcp2_log_info(rtb->log, NGTCP2_LOG_EVENT_RCV,
|
||||
ngtcp2_log_info(rtb->log, NGTCP2_LOG_EVENT_LDC,
|
||||
"pkn=%" PRId64
|
||||
" is a PMTUD probe packet, no retransmission is necessary",
|
||||
ent->hd.pkt_num);
|
||||
@@ -1467,7 +1264,7 @@ static int rtb_on_pkt_lost_resched_move(ngtcp2_rtb *rtb, ngtcp2_conn *conn,
|
||||
--rtb->num_lost_pmtud_pkts;
|
||||
}
|
||||
|
||||
ngtcp2_log_info(rtb->log, NGTCP2_LOG_EVENT_RCV,
|
||||
ngtcp2_log_info(rtb->log, NGTCP2_LOG_EVENT_LDC,
|
||||
"pkn=%" PRId64
|
||||
" was declared lost and has already been retransmitted",
|
||||
ent->hd.pkt_num);
|
||||
@@ -1475,7 +1272,7 @@ static int rtb_on_pkt_lost_resched_move(ngtcp2_rtb *rtb, ngtcp2_conn *conn,
|
||||
}
|
||||
|
||||
if (ent->flags & NGTCP2_RTB_ENTRY_FLAG_PTO_RECLAIMED) {
|
||||
ngtcp2_log_info(rtb->log, NGTCP2_LOG_EVENT_RCV,
|
||||
ngtcp2_log_info(rtb->log, NGTCP2_LOG_EVENT_LDC,
|
||||
"pkn=%" PRId64 " has already been reclaimed on PTO",
|
||||
ent->hd.pkt_num);
|
||||
return 0;
|
||||
@@ -1505,7 +1302,6 @@ static int rtb_on_pkt_lost_resched_move(ngtcp2_rtb *rtb, ngtcp2_conn *conn,
|
||||
ngtcp2_frame_chain_objalloc_del(frc, rtb->frc_objalloc, rtb->mem);
|
||||
break;
|
||||
}
|
||||
streamfrq_empty = ngtcp2_strm_streamfrq_empty(strm);
|
||||
rv = ngtcp2_strm_streamfrq_push(strm, frc);
|
||||
if (rv != 0) {
|
||||
ngtcp2_frame_chain_objalloc_del(frc, rtb->frc_objalloc, rtb->mem);
|
||||
@@ -1518,9 +1314,6 @@ static int rtb_on_pkt_lost_resched_move(ngtcp2_rtb *rtb, ngtcp2_conn *conn,
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
if (streamfrq_empty) {
|
||||
++conn->tx.strmq_nretrans;
|
||||
}
|
||||
break;
|
||||
case NGTCP2_FRAME_CRYPTO:
|
||||
frc = *pfrc;
|
||||
@@ -1528,8 +1321,7 @@ static int rtb_on_pkt_lost_resched_move(ngtcp2_rtb *rtb, ngtcp2_conn *conn,
|
||||
*pfrc = frc->next;
|
||||
frc->next = NULL;
|
||||
|
||||
rv = ngtcp2_ksl_insert(&pktns->crypto.tx.frq, NULL,
|
||||
&frc->fr.crypto.offset, frc);
|
||||
rv = ngtcp2_strm_streamfrq_push(&pktns->crypto.strm, frc);
|
||||
if (rv != 0) {
|
||||
assert(ngtcp2_err_is_fatal(rv));
|
||||
ngtcp2_frame_chain_objalloc_del(frc, rtb->frc_objalloc, rtb->mem);
|
||||
|
||||
Vendored
+4
-150
@@ -35,6 +35,7 @@
|
||||
#include "ngtcp2_ksl.h"
|
||||
#include "ngtcp2_pq.h"
|
||||
#include "ngtcp2_objalloc.h"
|
||||
#include "ngtcp2_pktns_id.h"
|
||||
|
||||
typedef struct ngtcp2_conn ngtcp2_conn;
|
||||
typedef struct ngtcp2_pktns ngtcp2_pktns;
|
||||
@@ -43,156 +44,9 @@ typedef struct ngtcp2_qlog ngtcp2_qlog;
|
||||
typedef struct ngtcp2_strm ngtcp2_strm;
|
||||
typedef struct ngtcp2_rst ngtcp2_rst;
|
||||
typedef struct ngtcp2_cc ngtcp2_cc;
|
||||
|
||||
/* NGTCP2_FRAME_CHAIN_BINDER_FLAG_NONE indicates that no flag is
|
||||
set. */
|
||||
#define NGTCP2_FRAME_CHAIN_BINDER_FLAG_NONE 0x00u
|
||||
/* NGTCP2_FRAME_CHAIN_BINDER_FLAG_ACK indicates that an information
|
||||
which a frame carries has been acknowledged. */
|
||||
#define NGTCP2_FRAME_CHAIN_BINDER_FLAG_ACK 0x01u
|
||||
|
||||
/*
|
||||
* ngtcp2_frame_chain_binder binds 2 or more of ngtcp2_frame_chain to
|
||||
* share the acknowledgement state. In general, all
|
||||
* ngtcp2_frame_chains bound to the same binder must have the same
|
||||
* information.
|
||||
*/
|
||||
typedef struct ngtcp2_frame_chain_binder {
|
||||
size_t refcount;
|
||||
/* flags is bitwise OR of zero or more of
|
||||
NGTCP2_FRAME_CHAIN_BINDER_FLAG_*. */
|
||||
uint32_t flags;
|
||||
} ngtcp2_frame_chain_binder;
|
||||
|
||||
int ngtcp2_frame_chain_binder_new(ngtcp2_frame_chain_binder **pbinder,
|
||||
const ngtcp2_mem *mem);
|
||||
|
||||
typedef struct ngtcp2_conn_stat ngtcp2_conn_stat;
|
||||
typedef struct ngtcp2_frame_chain ngtcp2_frame_chain;
|
||||
|
||||
/*
|
||||
* ngtcp2_frame_chain chains frames in a single packet.
|
||||
*/
|
||||
struct ngtcp2_frame_chain {
|
||||
union {
|
||||
struct {
|
||||
ngtcp2_frame_chain *next;
|
||||
ngtcp2_frame_chain_binder *binder;
|
||||
ngtcp2_frame fr;
|
||||
};
|
||||
|
||||
ngtcp2_opl_entry oplent;
|
||||
};
|
||||
};
|
||||
|
||||
ngtcp2_objalloc_def(frame_chain, ngtcp2_frame_chain, oplent);
|
||||
|
||||
/*
|
||||
* ngtcp2_bind_frame_chains binds two frame chains |a| and |b| using
|
||||
* new or existing ngtcp2_frame_chain_binder. |a| might have non-NULL
|
||||
* a->binder. |b| must not have non-NULL b->binder.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGTCP2_ERR_NOMEM
|
||||
* Out of memory
|
||||
*/
|
||||
int ngtcp2_bind_frame_chains(ngtcp2_frame_chain *a, ngtcp2_frame_chain *b,
|
||||
const ngtcp2_mem *mem);
|
||||
|
||||
/* NGTCP2_MAX_STREAM_DATACNT is the maximum number of ngtcp2_vec that
|
||||
a ngtcp2_stream can include. */
|
||||
#define NGTCP2_MAX_STREAM_DATACNT 256
|
||||
|
||||
/* NGTCP2_MAX_CRYPTO_DATACNT is the maximum number of ngtcp2_vec that
|
||||
a ngtcp2_crypto can include. */
|
||||
#define NGTCP2_MAX_CRYPTO_DATACNT 8
|
||||
|
||||
/*
|
||||
* ngtcp2_frame_chain_new allocates ngtcp2_frame_chain object and
|
||||
* assigns its pointer to |*pfrc|.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGTCP2_ERR_NOMEM
|
||||
* Out of memory.
|
||||
*/
|
||||
int ngtcp2_frame_chain_new(ngtcp2_frame_chain **pfrc, const ngtcp2_mem *mem);
|
||||
|
||||
/*
|
||||
* ngtcp2_frame_chain_objalloc_new behaves like
|
||||
* ngtcp2_frame_chain_new, but it uses |objalloc| to allocate the object.
|
||||
*/
|
||||
int ngtcp2_frame_chain_objalloc_new(ngtcp2_frame_chain **pfrc,
|
||||
ngtcp2_objalloc *objalloc);
|
||||
|
||||
/*
|
||||
* ngtcp2_frame_chain_extralen_new works like ngtcp2_frame_chain_new,
|
||||
* but it allocates extra memory |extralen| in order to extend
|
||||
* ngtcp2_frame.
|
||||
*/
|
||||
int ngtcp2_frame_chain_extralen_new(ngtcp2_frame_chain **pfrc, size_t extralen,
|
||||
const ngtcp2_mem *mem);
|
||||
|
||||
/*
|
||||
* ngtcp2_frame_chain_stream_datacnt_objalloc_new works like
|
||||
* ngtcp2_frame_chain_new, but it allocates enough data to store
|
||||
* additional |datacnt| - 1 ngtcp2_vec object after ngtcp2_stream
|
||||
* object. If no additional space is required,
|
||||
* ngtcp2_frame_chain_objalloc_new is called internally.
|
||||
*/
|
||||
int ngtcp2_frame_chain_stream_datacnt_objalloc_new(ngtcp2_frame_chain **pfrc,
|
||||
size_t datacnt,
|
||||
ngtcp2_objalloc *objalloc,
|
||||
const ngtcp2_mem *mem);
|
||||
|
||||
/*
|
||||
* ngtcp2_frame_chain_crypto_datacnt_objalloc_new works like
|
||||
* ngtcp2_frame_chain_new, but it allocates enough data to store
|
||||
* additional |datacnt| - 1 ngtcp2_vec object after ngtcp2_crypto
|
||||
* object. If no additional space is required,
|
||||
* ngtcp2_frame_chain_objalloc_new is called internally.
|
||||
*/
|
||||
int ngtcp2_frame_chain_crypto_datacnt_objalloc_new(ngtcp2_frame_chain **pfrc,
|
||||
size_t datacnt,
|
||||
ngtcp2_objalloc *objalloc,
|
||||
const ngtcp2_mem *mem);
|
||||
|
||||
int ngtcp2_frame_chain_new_token_objalloc_new(ngtcp2_frame_chain **pfrc,
|
||||
const ngtcp2_vec *token,
|
||||
ngtcp2_objalloc *objalloc,
|
||||
const ngtcp2_mem *mem);
|
||||
|
||||
/*
|
||||
* ngtcp2_frame_chain_del deallocates |frc|. It also deallocates the
|
||||
* memory pointed by |frc|.
|
||||
*/
|
||||
void ngtcp2_frame_chain_del(ngtcp2_frame_chain *frc, const ngtcp2_mem *mem);
|
||||
|
||||
/*
|
||||
* ngtcp2_frame_chain_objalloc_del adds |frc| to |objalloc| for reuse.
|
||||
* It might just delete |frc| depending on the frame type and the size
|
||||
* of |frc|.
|
||||
*/
|
||||
void ngtcp2_frame_chain_objalloc_del(ngtcp2_frame_chain *frc,
|
||||
ngtcp2_objalloc *objalloc,
|
||||
const ngtcp2_mem *mem);
|
||||
|
||||
/*
|
||||
* ngtcp2_frame_chain_init initializes |frc|.
|
||||
*/
|
||||
void ngtcp2_frame_chain_init(ngtcp2_frame_chain *frc);
|
||||
|
||||
/*
|
||||
* ngtcp2_frame_chain_list_objalloc_del adds all ngtcp2_frame_chain
|
||||
* linked from |frc| to |objalloc| for reuse. Depending on the frame type
|
||||
* and its size, ngtcp2_frame_chain might be deleted instead.
|
||||
*/
|
||||
void ngtcp2_frame_chain_list_objalloc_del(ngtcp2_frame_chain *frc,
|
||||
ngtcp2_objalloc *objalloc,
|
||||
const ngtcp2_mem *mem);
|
||||
|
||||
/* NGTCP2_RTB_ENTRY_FLAG_NONE indicates that no flag is set. */
|
||||
#define NGTCP2_RTB_ENTRY_FLAG_NONE 0x00u
|
||||
/* NGTCP2_RTB_ENTRY_FLAG_PROBE indicates that the entry includes a
|
||||
@@ -268,7 +122,7 @@ struct ngtcp2_rtb_entry {
|
||||
};
|
||||
};
|
||||
|
||||
ngtcp2_objalloc_def(rtb_entry, ngtcp2_rtb_entry, oplent);
|
||||
ngtcp2_objalloc_decl(rtb_entry, ngtcp2_rtb_entry, oplent);
|
||||
|
||||
/*
|
||||
* ngtcp2_rtb_entry_new allocates ngtcp2_rtb_entry object, and assigns
|
||||
@@ -347,7 +201,7 @@ typedef struct ngtcp2_rtb {
|
||||
*/
|
||||
void ngtcp2_rtb_init(ngtcp2_rtb *rtb, ngtcp2_pktns_id pktns_id,
|
||||
ngtcp2_strm *crypto, ngtcp2_rst *rst, ngtcp2_cc *cc,
|
||||
ngtcp2_log *log, ngtcp2_qlog *qlog,
|
||||
int64_t cc_pkt_num, ngtcp2_log *log, ngtcp2_qlog *qlog,
|
||||
ngtcp2_objalloc *rtb_entry_objalloc,
|
||||
ngtcp2_objalloc *frc_objalloc, const ngtcp2_mem *mem);
|
||||
|
||||
|
||||
Vendored
+5
@@ -38,6 +38,11 @@ uint8_t *ngtcp2_setmem(uint8_t *dest, uint8_t b, size_t n) {
|
||||
return dest + n;
|
||||
}
|
||||
|
||||
const void *ngtcp2_get_bytes(void *dest, const void *src, size_t n) {
|
||||
memcpy(dest, src, n);
|
||||
return (uint8_t *)src + n;
|
||||
}
|
||||
|
||||
#define LOWER_XDIGITS "0123456789abcdef"
|
||||
|
||||
uint8_t *ngtcp2_encode_hex(uint8_t *dest, const uint8_t *data, size_t len) {
|
||||
|
||||
Vendored
+7
@@ -38,6 +38,13 @@ void *ngtcp2_cpymem(void *dest, const void *src, size_t n);
|
||||
* the buffer pointed by |dest|. It returns dest + n;
|
||||
*/
|
||||
uint8_t *ngtcp2_setmem(uint8_t *dest, uint8_t b, size_t n);
|
||||
|
||||
/*
|
||||
* ngtcp2_get_bytes copies |n| bytes from |src| to |dest|, and returns
|
||||
* |src| + |n|.
|
||||
*/
|
||||
const void *ngtcp2_get_bytes(void *dest, const void *src, size_t n);
|
||||
|
||||
/*
|
||||
* ngtcp2_encode_hex encodes |data| of length |len| in hex string. It
|
||||
* writes additional NULL bytes at the end of the buffer. The buffer
|
||||
|
||||
Vendored
+22
-22
@@ -30,6 +30,7 @@
|
||||
#include "ngtcp2_rtb.h"
|
||||
#include "ngtcp2_pkt.h"
|
||||
#include "ngtcp2_vec.h"
|
||||
#include "ngtcp2_frame_chain.h"
|
||||
|
||||
static int offset_less(const ngtcp2_ksl_key *lhs, const ngtcp2_ksl_key *rhs) {
|
||||
return *(int64_t *)lhs < *(int64_t *)rhs;
|
||||
@@ -46,9 +47,12 @@ void ngtcp2_strm_init(ngtcp2_strm *strm, int64_t stream_id, uint32_t flags,
|
||||
strm->tx.streamfrq = NULL;
|
||||
strm->tx.offset = 0;
|
||||
strm->tx.max_offset = max_tx_offset;
|
||||
strm->tx.last_blocked_offset = UINT64_MAX;
|
||||
strm->tx.last_max_stream_data_ts = UINT64_MAX;
|
||||
strm->tx.loss_count = 0;
|
||||
strm->tx.last_lost_pkt_num = -1;
|
||||
strm->tx.stop_sending_app_error_code = 0;
|
||||
strm->tx.reset_stream_app_error_code = 0;
|
||||
strm->rx.rob = NULL;
|
||||
strm->rx.cont_offset = 0;
|
||||
strm->rx.last_offset = 0;
|
||||
@@ -120,7 +124,7 @@ uint64_t ngtcp2_strm_rx_offset(ngtcp2_strm *strm) {
|
||||
/* strm_rob_heavily_fragmented returns nonzero if the number of gaps
|
||||
in |rob| exceeds the limit. */
|
||||
static int strm_rob_heavily_fragmented(ngtcp2_rob *rob) {
|
||||
return ngtcp2_ksl_len(&rob->gapksl) >= 1000;
|
||||
return ngtcp2_ksl_len(&rob->gapksl) >= 5000;
|
||||
}
|
||||
|
||||
int ngtcp2_strm_recv_reordering(ngtcp2_strm *strm, const uint8_t *data,
|
||||
@@ -134,10 +138,7 @@ int ngtcp2_strm_recv_reordering(ngtcp2_strm *strm, const uint8_t *data,
|
||||
}
|
||||
|
||||
if (strm->rx.cont_offset) {
|
||||
rv = ngtcp2_rob_remove_prefix(strm->rx.rob, strm->rx.cont_offset);
|
||||
if (rv != 0) {
|
||||
return rv;
|
||||
}
|
||||
ngtcp2_rob_remove_prefix(strm->rx.rob, strm->rx.cont_offset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,13 +149,13 @@ int ngtcp2_strm_recv_reordering(ngtcp2_strm *strm, const uint8_t *data,
|
||||
return ngtcp2_rob_push(strm->rx.rob, offset, data, datalen);
|
||||
}
|
||||
|
||||
int ngtcp2_strm_update_rx_offset(ngtcp2_strm *strm, uint64_t offset) {
|
||||
void ngtcp2_strm_update_rx_offset(ngtcp2_strm *strm, uint64_t offset) {
|
||||
if (strm->rx.rob == NULL) {
|
||||
strm->rx.cont_offset = offset;
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
|
||||
return ngtcp2_rob_remove_prefix(strm->rx.rob, offset);
|
||||
ngtcp2_rob_remove_prefix(strm->rx.rob, offset);
|
||||
}
|
||||
|
||||
void ngtcp2_strm_shutdown(ngtcp2_strm *strm, uint32_t flags) {
|
||||
@@ -177,7 +178,8 @@ static int strm_streamfrq_init(ngtcp2_strm *strm) {
|
||||
int ngtcp2_strm_streamfrq_push(ngtcp2_strm *strm, ngtcp2_frame_chain *frc) {
|
||||
int rv;
|
||||
|
||||
assert(frc->fr.type == NGTCP2_FRAME_STREAM);
|
||||
assert(frc->fr.type == NGTCP2_FRAME_STREAM ||
|
||||
frc->fr.type == NGTCP2_FRAME_CRYPTO);
|
||||
assert(frc->next == NULL);
|
||||
|
||||
if (strm->tx.streamfrq == NULL) {
|
||||
@@ -308,7 +310,7 @@ static int strm_streamfrq_unacked_pop(ngtcp2_strm *strm,
|
||||
|
||||
assert(nfr->data[0].len > end_base_offset);
|
||||
|
||||
nfr->type = NGTCP2_FRAME_STREAM;
|
||||
nfr->type = fr->type;
|
||||
nfr->flags = 0;
|
||||
nfr->fin = fr->fin;
|
||||
nfr->stream_id = fr->stream_id;
|
||||
@@ -379,18 +381,16 @@ int ngtcp2_strm_streamfrq_pop(ngtcp2_strm *strm, ngtcp2_frame_chain **pfrc,
|
||||
fr = &frc->fr.stream;
|
||||
datalen = ngtcp2_vec_len(fr->data, fr->datacnt);
|
||||
|
||||
if (left == 0) {
|
||||
/* datalen could be zero if 0 length STREAM has been sent */
|
||||
if (datalen || ngtcp2_ksl_len(strm->tx.streamfrq) > 1) {
|
||||
rv = ngtcp2_ksl_insert(strm->tx.streamfrq, NULL, &fr->offset, frc);
|
||||
if (rv != 0) {
|
||||
assert(ngtcp2_err_is_fatal(rv));
|
||||
ngtcp2_frame_chain_objalloc_del(frc, strm->frc_objalloc, strm->mem);
|
||||
return rv;
|
||||
}
|
||||
*pfrc = NULL;
|
||||
return 0;
|
||||
/* datalen could be zero if 0 length STREAM has been sent */
|
||||
if (left == 0 && datalen) {
|
||||
rv = ngtcp2_ksl_insert(strm->tx.streamfrq, NULL, &fr->offset, frc);
|
||||
if (rv != 0) {
|
||||
assert(ngtcp2_err_is_fatal(rv));
|
||||
ngtcp2_frame_chain_objalloc_del(frc, strm->frc_objalloc, strm->mem);
|
||||
return rv;
|
||||
}
|
||||
*pfrc = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (datalen > left) {
|
||||
@@ -412,7 +412,7 @@ int ngtcp2_strm_streamfrq_pop(ngtcp2_strm *strm, ngtcp2_frame_chain **pfrc,
|
||||
}
|
||||
|
||||
nfr = &nfrc->fr.stream;
|
||||
nfr->type = NGTCP2_FRAME_STREAM;
|
||||
nfr->type = fr->type;
|
||||
nfr->flags = 0;
|
||||
nfr->fin = fr->fin;
|
||||
nfr->stream_id = fr->stream_id;
|
||||
|
||||
Vendored
+31
-22
@@ -49,20 +49,20 @@ typedef struct ngtcp2_frame_chain ngtcp2_frame_chain;
|
||||
#define NGTCP2_STRM_FLAG_SHUT_WR 0x02u
|
||||
#define NGTCP2_STRM_FLAG_SHUT_RDWR \
|
||||
(NGTCP2_STRM_FLAG_SHUT_RD | NGTCP2_STRM_FLAG_SHUT_WR)
|
||||
/* NGTCP2_STRM_FLAG_SENT_RST indicates that RST_STREAM is sent from
|
||||
the local endpoint. In this case, NGTCP2_STRM_FLAG_SHUT_WR is also
|
||||
set. */
|
||||
#define NGTCP2_STRM_FLAG_SENT_RST 0x04u
|
||||
/* NGTCP2_STRM_FLAG_SENT_RST indicates that RST_STREAM is received
|
||||
from the remote endpoint. In this case, NGTCP2_STRM_FLAG_SHUT_RD
|
||||
is also set. */
|
||||
#define NGTCP2_STRM_FLAG_RECV_RST 0x08u
|
||||
/* NGTCP2_STRM_FLAG_RESET_STREAM indicates that RESET_STREAM is sent
|
||||
from the local endpoint. In this case, NGTCP2_STRM_FLAG_SHUT_WR is
|
||||
also set. */
|
||||
#define NGTCP2_STRM_FLAG_RESET_STREAM 0x04u
|
||||
/* NGTCP2_STRM_FLAG_RESET_STREAM_RECVED indicates that RESET_STREAM is
|
||||
received from the remote endpoint. In this case,
|
||||
NGTCP2_STRM_FLAG_SHUT_RD is also set. */
|
||||
#define NGTCP2_STRM_FLAG_RESET_STREAM_RECVED 0x08u
|
||||
/* NGTCP2_STRM_FLAG_STOP_SENDING indicates that STOP_SENDING is sent
|
||||
from the local endpoint. */
|
||||
#define NGTCP2_STRM_FLAG_STOP_SENDING 0x10u
|
||||
/* NGTCP2_STRM_FLAG_RST_ACKED indicates that the outgoing RST_STREAM
|
||||
is acknowledged by peer. */
|
||||
#define NGTCP2_STRM_FLAG_RST_ACKED 0x20u
|
||||
/* NGTCP2_STRM_FLAG_RESET_STREAM_ACKED indicates that the outgoing
|
||||
RESET_STREAM is acknowledged by peer. */
|
||||
#define NGTCP2_STRM_FLAG_RESET_STREAM_ACKED 0x20u
|
||||
/* NGTCP2_STRM_FLAG_FIN_ACKED indicates that a STREAM with FIN bit set
|
||||
is acknowledged by a remote endpoint. */
|
||||
#define NGTCP2_STRM_FLAG_FIN_ACKED 0x40u
|
||||
@@ -75,9 +75,12 @@ typedef struct ngtcp2_frame_chain ngtcp2_frame_chain;
|
||||
In this case, without this flag, we are unable to distinguish
|
||||
assigned value from unassigned one. */
|
||||
#define NGTCP2_STRM_FLAG_APP_ERROR_CODE_SET 0x100u
|
||||
/* NGTCP2_STRM_FLAG_STREAM_STOP_SENDING_CALLED is set when
|
||||
stream_stop_sending callback is called. */
|
||||
#define NGTCP2_STRM_FLAG_STREAM_STOP_SENDING_CALLED 0x200u
|
||||
/* NGTCP2_STRM_FLAG_SEND_STOP_SENDING is set when STOP_SENDING frame
|
||||
should be sent. */
|
||||
#define NGTCP2_STRM_FLAG_SEND_STOP_SENDING 0x200u
|
||||
/* NGTCP2_STRM_FLAG_SEND_RESET_STREAM is set when RESET_STREAM frame
|
||||
should be sent. */
|
||||
#define NGTCP2_STRM_FLAG_SEND_RESET_STREAM 0x400u
|
||||
|
||||
typedef struct ngtcp2_strm ngtcp2_strm;
|
||||
|
||||
@@ -96,10 +99,10 @@ struct ngtcp2_strm {
|
||||
remote endpoint acknowledges data in out-of-order. After that,
|
||||
acked_offset is used instead. */
|
||||
uint64_t cont_acked_offset;
|
||||
/* streamfrq contains STREAM frame for retransmission. The flow
|
||||
control credits have been paid when they are transmitted first
|
||||
time. There are no restriction regarding flow control for
|
||||
retransmission. */
|
||||
/* streamfrq contains STREAM or CRYPTO frame for
|
||||
retransmission. The flow control credits have been paid
|
||||
when they are transmitted first time. There are no
|
||||
restriction regarding flow control for retransmission. */
|
||||
ngtcp2_ksl *streamfrq;
|
||||
/* offset is the next offset of outgoing data. In other words, it
|
||||
is the number of bytes sent in this stream without
|
||||
@@ -108,6 +111,9 @@ struct ngtcp2_strm {
|
||||
/* max_tx_offset is the maximum offset that local endpoint can
|
||||
send for this stream. */
|
||||
uint64_t max_offset;
|
||||
/* last_blocked_offset is the largest offset where the
|
||||
transmission of stream data is blocked. */
|
||||
uint64_t last_blocked_offset;
|
||||
/* last_max_stream_data_ts is the timestamp when last
|
||||
MAX_STREAM_DATA frame is sent. */
|
||||
ngtcp2_tstamp last_max_stream_data_ts;
|
||||
@@ -123,6 +129,12 @@ struct ngtcp2_strm {
|
||||
is counted to loss_count. It is used to avoid to count
|
||||
multiple STREAM frames in one lost packet. */
|
||||
int64_t last_lost_pkt_num;
|
||||
/* stop_sending_app_error_code is the application specific
|
||||
error code that is sent along with STOP_SENDING. */
|
||||
uint64_t stop_sending_app_error_code;
|
||||
/* reset_stream_app_error_code is the application specific
|
||||
error code that is sent along with RESET_STREAM. */
|
||||
uint64_t reset_stream_app_error_code;
|
||||
} tx;
|
||||
|
||||
struct {
|
||||
@@ -200,11 +212,8 @@ int ngtcp2_strm_recv_reordering(ngtcp2_strm *strm, const uint8_t *data,
|
||||
/*
|
||||
* ngtcp2_strm_update_rx_offset tells that data up to offset bytes are
|
||||
* received in order.
|
||||
*
|
||||
* NGTCP2_ERR_NOMEM
|
||||
* Out of memory
|
||||
*/
|
||||
int ngtcp2_strm_update_rx_offset(ngtcp2_strm *strm, uint64_t offset);
|
||||
void ngtcp2_strm_update_rx_offset(ngtcp2_strm *strm, uint64_t offset);
|
||||
|
||||
/*
|
||||
* ngtcp2_strm_shutdown shutdowns |strm|. |flags| should be
|
||||
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* ngtcp2
|
||||
*
|
||||
* Copyright (c) 2023 ngtcp2 contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef NGTCP2_TSTAMP_H
|
||||
#define NGTCP2_TSTAMP_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
||||
#include <ngtcp2/ngtcp2.h>
|
||||
|
||||
/*
|
||||
* ngtcp2_tstamp_elapsed returns nonzero if at least |d| has passed
|
||||
* since |base|. |ts| expresses a current time, and must not be
|
||||
* UINT64_MAX.
|
||||
*
|
||||
* If |base| is UINT64_MAX, this function returns 0 because UINT64_MAX
|
||||
* is an invalid timestamp. Otherwise, if |base| + |d| >= UINT64_MAX,
|
||||
* this function returns 0.
|
||||
*
|
||||
* !ngtcp2_tstamp_elapsed() == ngtcp2_tstamp_not_elapsed() does not
|
||||
* hold when |base| is UINT64_MAX. If you need nonzero if |base| is
|
||||
* UINT64_MAX, use !ngtcp2_tstamp_elapsed. Otherwise, use
|
||||
* ngtcp2_tstamp_not_elapsed.
|
||||
*/
|
||||
static inline int ngtcp2_tstamp_elapsed(ngtcp2_tstamp base, ngtcp2_duration d,
|
||||
ngtcp2_tstamp ts) {
|
||||
return base != UINT64_MAX && base < UINT64_MAX - d && base + d <= ts;
|
||||
}
|
||||
|
||||
/*
|
||||
* ngtcp2_tstamp_not_elapsed returns nonzero if |d| has not passed
|
||||
* since |base|. |ts| expresses a current time, and must not be
|
||||
* UINT64_MAX.
|
||||
*
|
||||
* If |base| is UINT64_MAX, this function returns 0 because UINT64_MAX
|
||||
* is an invalid timestamp. Otherwise, if |base| + |d| >= UINT64_MAX,
|
||||
* this function returns nonzero.
|
||||
*/
|
||||
static inline int ngtcp2_tstamp_not_elapsed(ngtcp2_tstamp base,
|
||||
ngtcp2_duration d,
|
||||
ngtcp2_tstamp ts) {
|
||||
return base != UINT64_MAX && (base >= UINT64_MAX - d || base + d > ts);
|
||||
}
|
||||
|
||||
#endif /* NGTCP2_TSTAMP_H */
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* ngtcp2
|
||||
*
|
||||
* Copyright (c) 2022 ngtcp2 contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#include "ngtcp2_unreachable.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#endif /* HAVE_UNISTD_H */
|
||||
#include <stdlib.h>
|
||||
#ifdef WIN32
|
||||
# include <io.h>
|
||||
#endif /* WIN32 */
|
||||
|
||||
void ngtcp2_unreachable_fail(const char *file, int line, const char *func) {
|
||||
char *buf;
|
||||
size_t buflen;
|
||||
int rv;
|
||||
|
||||
#define NGTCP2_UNREACHABLE_TEMPLATE "%s:%d %s: Unreachable.\n"
|
||||
|
||||
rv = snprintf(NULL, 0, NGTCP2_UNREACHABLE_TEMPLATE, file, line, func);
|
||||
if (rv < 0) {
|
||||
abort();
|
||||
}
|
||||
|
||||
/* here we explicitly use system malloc */
|
||||
buflen = (size_t)rv + 1;
|
||||
buf = malloc(buflen);
|
||||
if (buf == NULL) {
|
||||
abort();
|
||||
}
|
||||
|
||||
rv = snprintf(buf, buflen, NGTCP2_UNREACHABLE_TEMPLATE, file, line, func);
|
||||
if (rv < 0) {
|
||||
abort();
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
while (write(STDERR_FILENO, buf, (size_t)rv) == -1 && errno == EINTR)
|
||||
;
|
||||
#else /* WIN32 */
|
||||
_write(_fileno(stderr), buf, (unsigned int)rv);
|
||||
#endif /* WIN32 */
|
||||
|
||||
free(buf);
|
||||
|
||||
abort();
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* ngtcp2
|
||||
*
|
||||
* Copyright (c) 2022 ngtcp2 contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef NGTCP2_UNREACHABLE_H
|
||||
#define NGTCP2_UNREACHABLE_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
||||
#include <ngtcp2/ngtcp2.h>
|
||||
|
||||
#ifdef __FILE_NAME__
|
||||
# define NGTCP2_FILE_NAME __FILE_NAME__
|
||||
#else /* !__FILE_NAME__ */
|
||||
# define NGTCP2_FILE_NAME "(file)"
|
||||
#endif /* !__FILE_NAME__ */
|
||||
|
||||
#define ngtcp2_unreachable() \
|
||||
ngtcp2_unreachable_fail(NGTCP2_FILE_NAME, __LINE__, __func__)
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(noreturn)
|
||||
#endif /* _MSC_VER */
|
||||
void ngtcp2_unreachable_fail(const char *file, int line, const char *func)
|
||||
#ifndef _MSC_VER
|
||||
__attribute__((noreturn))
|
||||
#endif /* !_MSC_VER */
|
||||
;
|
||||
|
||||
#endif /* NGTCP2_UNREACHABLE_H */
|
||||
Vendored
+21
-24
@@ -145,7 +145,7 @@ ngtcp2_ssize ngtcp2_vec_split(ngtcp2_vec *src, size_t *psrccnt, ngtcp2_vec *dst,
|
||||
size_t ngtcp2_vec_merge(ngtcp2_vec *dst, size_t *pdstcnt, ngtcp2_vec *src,
|
||||
size_t *psrccnt, size_t left, size_t maxcnt) {
|
||||
size_t orig_left = left;
|
||||
size_t i;
|
||||
size_t i = 0;
|
||||
ngtcp2_vec *a, *b;
|
||||
|
||||
assert(maxcnt);
|
||||
@@ -158,12 +158,7 @@ size_t ngtcp2_vec_merge(ngtcp2_vec *dst, size_t *pdstcnt, ngtcp2_vec *src,
|
||||
a = &dst[0];
|
||||
b = &src[0];
|
||||
|
||||
if (left >= b->len) {
|
||||
*a = *b;
|
||||
++*pdstcnt;
|
||||
left -= b->len;
|
||||
i = 1;
|
||||
} else {
|
||||
if (left < b->len) {
|
||||
a->len = left;
|
||||
a->base = b->base;
|
||||
|
||||
@@ -172,41 +167,43 @@ size_t ngtcp2_vec_merge(ngtcp2_vec *dst, size_t *pdstcnt, ngtcp2_vec *src,
|
||||
|
||||
return left;
|
||||
}
|
||||
} else {
|
||||
i = 0;
|
||||
|
||||
*a = *b;
|
||||
++*pdstcnt;
|
||||
left -= b->len;
|
||||
i = 1;
|
||||
}
|
||||
|
||||
for (; left && i < *psrccnt; ++i) {
|
||||
a = &dst[*pdstcnt - 1];
|
||||
b = &src[i];
|
||||
|
||||
if (left >= b->len) {
|
||||
if (left < b->len) {
|
||||
if (a->base + a->len == b->base) {
|
||||
a->len += b->len;
|
||||
a->len += left;
|
||||
} else if (*pdstcnt == maxcnt) {
|
||||
break;
|
||||
} else {
|
||||
dst[(*pdstcnt)++] = *b;
|
||||
dst[*pdstcnt].len = left;
|
||||
dst[*pdstcnt].base = b->base;
|
||||
++*pdstcnt;
|
||||
}
|
||||
left -= b->len;
|
||||
continue;
|
||||
|
||||
b->len -= left;
|
||||
b->base += left;
|
||||
left = 0;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (a->base + a->len == b->base) {
|
||||
a->len += left;
|
||||
a->len += b->len;
|
||||
} else if (*pdstcnt == maxcnt) {
|
||||
break;
|
||||
} else {
|
||||
dst[*pdstcnt].len = left;
|
||||
dst[*pdstcnt].base = b->base;
|
||||
++*pdstcnt;
|
||||
dst[(*pdstcnt)++] = *b;
|
||||
}
|
||||
|
||||
b->len -= left;
|
||||
b->base += left;
|
||||
left = 0;
|
||||
|
||||
break;
|
||||
left -= b->len;
|
||||
}
|
||||
|
||||
memmove(src, src + i, sizeof(ngtcp2_vec) * (*psrccnt - i));
|
||||
|
||||
Reference in new issue
Block a user