mirror of
https://github.com/oxen-io/lokinet
synced 2023-12-14 06:53:00 +01:00
bump ngtcp2 version, working but incomplete
bump ngtcp2 dep to the latest tagged version. The changes to get liblokinet/quic back to "working" (insofar as it was before) are complete in this commit, but there appear to be further changes in ngtcp2 apart from simple API changes which could merit reworking how we use it somewhat.
This commit is contained in:
parent
c20d114027
commit
63a3a5056f
2
external/ngtcp2
vendored
2
external/ngtcp2
vendored
|
@ -1 +1 @@
|
|||
Subproject commit 026b8434ebcbeec48939d1c7671a0a4d5c75202b
|
||||
Subproject commit 0cc9e1cc8a6650d3b656cb98cba0edb54040510c
|
|
@ -60,7 +60,7 @@ namespace llarp::quic
|
|||
return a;
|
||||
}
|
||||
|
||||
size_t
|
||||
ngtcp2_socklen
|
||||
sockaddr_size() const
|
||||
{
|
||||
return sizeof(sockaddr_in6);
|
||||
|
|
|
@ -375,7 +375,7 @@ namespace llarp::quic
|
|||
{
|
||||
log::warning(
|
||||
logcat, "expiry handler invocation returned an error: {}", ngtcp2_strerror(rv));
|
||||
endpoint.close_connection(*this, ngtcp2_err_infer_quic_transport_error_code(rv), false);
|
||||
endpoint.close_connection(*this, ngtcp2_err_infer_quic_transport_error_code(rv));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -407,7 +407,7 @@ namespace llarp::quic
|
|||
|
||||
settings.initial_ts = get_timestamp();
|
||||
// FIXME: IPv6
|
||||
settings.max_udp_payload_size = Endpoint::max_pkt_size_v4;
|
||||
settings.max_tx_udp_payload_size = Endpoint::max_pkt_size_v4;
|
||||
settings.cc_algo = NGTCP2_CC_ALGO_CUBIC;
|
||||
// settings.initial_rtt = ???; # NGTCP2's default is 333ms
|
||||
|
||||
|
@ -1150,26 +1150,11 @@ namespace llarp::quic
|
|||
}
|
||||
}
|
||||
|
||||
ngtcp2_transport_params params;
|
||||
|
||||
auto exttype = is_server ? NGTCP2_TRANSPORT_PARAMS_TYPE_CLIENT_HELLO
|
||||
: NGTCP2_TRANSPORT_PARAMS_TYPE_ENCRYPTED_EXTENSIONS;
|
||||
|
||||
auto rv = ngtcp2_decode_transport_params(¶ms, exttype, data.data(), data.size());
|
||||
auto rv = ngtcp2_conn_decode_remote_transport_params(*this, data.data(), data.size());
|
||||
log::debug(
|
||||
logcat,
|
||||
"Decode transport params {}",
|
||||
rv == 0 ? "success" : "fail: "s + ngtcp2_strerror(rv));
|
||||
log::trace(logcat, "params orig dcid = {}", ConnectionID(params.original_dcid));
|
||||
log::trace(logcat, "params init scid = {}", ConnectionID(params.initial_scid));
|
||||
if (rv == 0)
|
||||
{
|
||||
rv = ngtcp2_conn_set_remote_transport_params(*this, ¶ms);
|
||||
log::debug(
|
||||
logcat,
|
||||
"Set remote transport params {}",
|
||||
rv == 0 ? "success" : "fail: "s + ngtcp2_strerror(rv));
|
||||
}
|
||||
|
||||
if (rv != 0)
|
||||
{
|
||||
|
@ -1177,6 +1162,17 @@ namespace llarp::quic
|
|||
return rv;
|
||||
}
|
||||
|
||||
const auto* params = ngtcp2_conn_get_remote_transport_params(*this);
|
||||
if (params == nullptr)
|
||||
log::error(
|
||||
logcat,
|
||||
"conn_get_remote_transport_params returned NULL after decode_remote_transport_params");
|
||||
else
|
||||
{
|
||||
log::trace(logcat, "params orig dcid = {}", ConnectionID(params->original_dcid));
|
||||
log::trace(logcat, "params init scid = {}", ConnectionID(params->initial_scid));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1203,8 +1199,11 @@ namespace llarp::quic
|
|||
int
|
||||
Connection::send_transport_params(ngtcp2_crypto_level level)
|
||||
{
|
||||
ngtcp2_transport_params tparams;
|
||||
ngtcp2_conn_get_local_transport_params(*this, &tparams);
|
||||
const auto* tparams = ngtcp2_conn_get_local_transport_params(*this);
|
||||
|
||||
if (tparams == nullptr)
|
||||
throw std::runtime_error{
|
||||
"conn_get_local_transport_params returned NULL, local params not set?"};
|
||||
|
||||
assert(conn_buffer.empty());
|
||||
conn_buffer.resize(Endpoint::max_pkt_size_v4);
|
||||
|
@ -1230,7 +1229,7 @@ namespace llarp::quic
|
|||
auto exttype = is_server ? NGTCP2_TRANSPORT_PARAMS_TYPE_ENCRYPTED_EXTENSIONS
|
||||
: NGTCP2_TRANSPORT_PARAMS_TYPE_CLIENT_HELLO;
|
||||
|
||||
if (ngtcp2_ssize nwrite = ngtcp2_encode_transport_params(buf, bufend - buf, exttype, &tparams);
|
||||
if (ngtcp2_ssize nwrite = ngtcp2_encode_transport_params(buf, bufend - buf, exttype, tparams);
|
||||
nwrite >= 0)
|
||||
{
|
||||
assert(nwrite > 0);
|
||||
|
|
|
@ -100,16 +100,8 @@ namespace llarp::quic
|
|||
std::optional<ConnectionID>
|
||||
Endpoint::handle_packet_init(const Packet& p)
|
||||
{
|
||||
version_info vi;
|
||||
auto rv = ngtcp2_pkt_decode_version_cid(
|
||||
&vi.version,
|
||||
&vi.dcid,
|
||||
&vi.dcid_len,
|
||||
&vi.scid,
|
||||
&vi.scid_len,
|
||||
u8data(p.data),
|
||||
p.data.size(),
|
||||
NGTCP2_MAX_CIDLEN);
|
||||
ngtcp2_version_cid vi;
|
||||
auto rv = ngtcp2_pkt_decode_version_cid(&vi, u8data(p.data), p.data.size(), NGTCP2_MAX_CIDLEN);
|
||||
if (rv == 1)
|
||||
{ // 1 means Version Negotiation should be sent and otherwise the packet should be ignored
|
||||
send_version_negotiation(vi, p.path.remote);
|
||||
|
@ -121,13 +113,13 @@ namespace llarp::quic
|
|||
return std::nullopt;
|
||||
}
|
||||
|
||||
if (vi.dcid_len > ConnectionID::max_size())
|
||||
if (vi.dcidlen > ConnectionID::max_size())
|
||||
{
|
||||
log::warning(logcat, "Internal error: destination ID is longer than should be allowed");
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return std::make_optional<ConnectionID>(vi.dcid, vi.dcid_len);
|
||||
return std::make_optional<ConnectionID>(vi.dcid, vi.dcidlen);
|
||||
}
|
||||
void
|
||||
Endpoint::handle_conn_packet(Connection& conn, const Packet& p)
|
||||
|
@ -202,7 +194,7 @@ namespace llarp::quic
|
|||
}
|
||||
|
||||
void
|
||||
Endpoint::send_version_negotiation(const version_info& vi, const Address& source)
|
||||
Endpoint::send_version_negotiation(const ngtcp2_version_cid& vi, const Address& source)
|
||||
{
|
||||
std::array<std::byte, Endpoint::max_pkt_size_v4> buf;
|
||||
std::array<uint32_t, NGTCP2_PROTO_VER_MAX - NGTCP2_PROTO_VER_MIN + 2> versions;
|
||||
|
@ -216,9 +208,9 @@ namespace llarp::quic
|
|||
buf.size(),
|
||||
std::uniform_int_distribution<uint8_t>{0, 255}(rng),
|
||||
vi.dcid,
|
||||
vi.dcid_len,
|
||||
vi.dcidlen,
|
||||
vi.scid,
|
||||
vi.scid_len,
|
||||
vi.scidlen,
|
||||
versions.data(),
|
||||
versions.size());
|
||||
if (nwrote < 0)
|
||||
|
@ -231,29 +223,31 @@ namespace llarp::quic
|
|||
}
|
||||
|
||||
void
|
||||
Endpoint::close_connection(
|
||||
Connection& conn, uint64_t code, bool application, std::string_view close_reason)
|
||||
Endpoint::close_connection(Connection& conn, uint64_t code, std::string_view close_reason)
|
||||
{
|
||||
log::debug(logcat, "Closing connection {}", conn.base_cid);
|
||||
|
||||
const ngtcp2_connection_close_error err{
|
||||
// FIXME: propagate which type this should be to here; defaulting
|
||||
NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_TRANSPORT,
|
||||
code,
|
||||
0, // 0 == unknown
|
||||
reinterpret_cast<uint8_t*>(const_cast<char*>(close_reason.data())),
|
||||
close_reason.size()};
|
||||
if (!conn.closing)
|
||||
{
|
||||
conn.conn_buffer.resize(max_pkt_size_v4);
|
||||
Path path;
|
||||
ngtcp2_pkt_info pi;
|
||||
|
||||
auto write_close_func = application ? ngtcp2_conn_write_application_close_versioned
|
||||
: ngtcp2_conn_write_connection_close_versioned;
|
||||
|
||||
auto written = write_close_func(
|
||||
auto written = ngtcp2_conn_write_connection_close_versioned(
|
||||
conn,
|
||||
path,
|
||||
NGTCP2_PKT_INFO_VERSION,
|
||||
&pi,
|
||||
u8data(conn.conn_buffer),
|
||||
conn.conn_buffer.size(),
|
||||
code,
|
||||
reinterpret_cast<const uint8_t*>(close_reason.data()),
|
||||
close_reason.size(),
|
||||
&err,
|
||||
get_timestamp());
|
||||
if (written <= 0)
|
||||
{
|
||||
|
@ -324,7 +318,7 @@ namespace llarp::quic
|
|||
if (auto* conn_ptr = std::get_if<primary_conn_ptr>(&it->second))
|
||||
{
|
||||
Connection& conn = **conn_ptr;
|
||||
auto exp = ngtcp2_conn_get_idle_expiry(conn);
|
||||
auto exp = ngtcp2_conn_get_expiry(conn);
|
||||
if (exp >= now_ts || conn.draining)
|
||||
continue;
|
||||
start_draining(conn);
|
||||
|
|
|
@ -109,16 +109,6 @@ namespace llarp::quic
|
|||
|
||||
virtual ~Endpoint();
|
||||
|
||||
// Version & connection id info that we can potentially extract when decoding a packet
|
||||
struct version_info
|
||||
{
|
||||
uint32_t version;
|
||||
const uint8_t* dcid;
|
||||
size_t dcid_len;
|
||||
const uint8_t* scid;
|
||||
size_t scid_len;
|
||||
};
|
||||
|
||||
// Called to handle an incoming packet
|
||||
void
|
||||
handle_packet(const Packet& p);
|
||||
|
@ -185,7 +175,7 @@ namespace llarp::quic
|
|||
}
|
||||
|
||||
void
|
||||
send_version_negotiation(const version_info& vi, const Address& source);
|
||||
send_version_negotiation(const ngtcp2_version_cid& vi, const Address& source);
|
||||
|
||||
// Looks up a connection. Returns a shared_ptr (either copied for a primary connection, or
|
||||
// locked from an alias's weak pointer) if the connection was found or nullptr if not; and a
|
||||
|
@ -206,10 +196,7 @@ namespace llarp::quic
|
|||
// values.
|
||||
void
|
||||
close_connection(
|
||||
Connection& conn,
|
||||
uint64_t code = NGTCP2_NO_ERROR,
|
||||
bool application = false,
|
||||
std::string_view close_reason = ""sv);
|
||||
Connection& conn, uint64_t code = NGTCP2_NO_ERROR, std::string_view close_reason = ""sv);
|
||||
|
||||
/// Puts a connection into draining mode (i.e. after getting a connection close). This will
|
||||
/// keep the connection registered for the recommended 3*Probe Timeout, during which we drop
|
||||
|
|
|
@ -33,7 +33,8 @@ namespace llarp::quic
|
|||
{ // Invalid/unexpected version, send a version negotiation
|
||||
log::debug(logcat, "Invalid/unsupported version; sending version negotiation");
|
||||
send_version_negotiation(
|
||||
version_info{hd.version, hd.dcid.data, hd.dcid.datalen, hd.scid.data, hd.scid.datalen},
|
||||
ngtcp2_version_cid{
|
||||
hd.version, hd.dcid.data, hd.dcid.datalen, hd.scid.data, hd.scid.datalen},
|
||||
p.path.remote);
|
||||
return nullptr;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue