mirror of
https://github.com/oxen-io/lokinet
synced 2023-12-14 06:53:00 +01:00
updated cmake to have lokinet-embedded-api build deps
- pkt tx timer update + max pkt count - added pkt tx time updates to message handling logic - setting destlen param to at least max_tx_UDP_Payload size
This commit is contained in:
parent
7850343f9a
commit
d84c64f342
|
@ -525,7 +525,22 @@ if(WITH_EMBEDDED_LOKINET)
|
|||
|
||||
if(BUILD_STATIC_DEPS)
|
||||
get_target_property(embedded-libs lokinet-amalgum INTERFACE_LINK_LIBRARIES)
|
||||
combine_archives(lokinet-embedded ${embedded-libs})
|
||||
combine_archives(lokinet-embedded
|
||||
${embedded-libs}
|
||||
lokinet-embedded-api
|
||||
ngtcp2_static
|
||||
uv_a::uv_a
|
||||
sodium
|
||||
zlib
|
||||
OpenSSL::SSL
|
||||
OpenSSL::Crypto
|
||||
expat
|
||||
libunbound
|
||||
libzmq
|
||||
fmt::fmt
|
||||
spdlog::spdlog
|
||||
oxen::logging
|
||||
oxenmq::oxenmq)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
|
|
|
@ -629,6 +629,7 @@ extern "C"
|
|||
lokinet_set_data_dir(const char* path, struct lokinet_context* ctx)
|
||||
{
|
||||
fs::path dir{path};
|
||||
dir = fs::canonical(dir);
|
||||
fs::current_path(dir);
|
||||
|
||||
if (not ctx)
|
||||
|
|
|
@ -187,20 +187,16 @@ namespace llarp::quic
|
|||
return 0;
|
||||
}
|
||||
|
||||
int version_negotiation(
|
||||
ngtcp2_conn *conn,
|
||||
uint32_t version,
|
||||
const ngtcp2_cid *client_dcid,
|
||||
void *user_data)
|
||||
int
|
||||
version_negotiation(
|
||||
ngtcp2_conn* conn, uint32_t version, const ngtcp2_cid* client_dcid, void* user_data)
|
||||
{
|
||||
log::info(logcat, "{} called", __PRETTY_FUNCTION__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
handshake_completed(
|
||||
ngtcp2_conn* _conn,
|
||||
void* user_data)
|
||||
int
|
||||
handshake_completed(ngtcp2_conn* _conn, void* user_data)
|
||||
{
|
||||
log::info(logcat, "{} called", __PRETTY_FUNCTION__);
|
||||
|
||||
|
@ -283,8 +279,8 @@ namespace llarp::quic
|
|||
void* user_data,
|
||||
void* stream_user_data)
|
||||
{
|
||||
log::trace(logcat, "{} called", __PRETTY_FUNCTION__);
|
||||
log::trace(logcat, "Ack [{},{})", offset, offset + datalen);
|
||||
log::debug(logcat, "{} called", __PRETTY_FUNCTION__);
|
||||
log::debug(logcat, "Ack [{},{})", offset, offset + datalen);
|
||||
return static_cast<Connection*>(user_data)->stream_ack({stream_id}, datalen);
|
||||
}
|
||||
|
||||
|
@ -434,7 +430,7 @@ namespace llarp::quic
|
|||
retransmit_timer = loop->resource<uvw::TimerHandle>();
|
||||
retransmit_timer->on<uvw::TimerEvent>([this](auto&, auto&) {
|
||||
log::debug(logcat, "Retransmit timer fired!");
|
||||
if (auto rv = ngtcp2_conn_handle_expiry(*this, get_timestamp()); rv != 0)
|
||||
if (auto rv = ngtcp2_conn_handle_expiry(conn.get(), get_timestamp()); rv != 0)
|
||||
{
|
||||
log::warning(
|
||||
logcat, "expiry handler invocation returned an error: {}", ngtcp2_strerror(rv));
|
||||
|
@ -627,63 +623,26 @@ namespace llarp::quic
|
|||
void
|
||||
Connection::flush_streams()
|
||||
{
|
||||
log::trace(logcat, "Connection::flush_streams()");
|
||||
// debug
|
||||
log::info(logcat, "Connection::flush_streams()");
|
||||
// conn, path, pi, dest, destlen, and ts
|
||||
log::debug(logcat, "Connection::flush_streams()");
|
||||
// Maximum number of stream data packets to send out at once; if we reach this then we'll
|
||||
// schedule another event loop call of ourselves (so that we don't starve the loop).
|
||||
auto max_udp_payload_size = ngtcp2_conn_get_max_tx_udp_payload_size(conn.get());
|
||||
auto max_stream_packets = ngtcp2_conn_get_send_quantum(conn.get()) / max_udp_payload_size;
|
||||
ngtcp2_ssize ndatalen;
|
||||
uint16_t stream_packets = 0;
|
||||
uint32_t flags = NGTCP2_WRITE_STREAM_FLAG_MORE;
|
||||
std::optional<uint64_t> ts;
|
||||
|
||||
send_pkt_info = {};
|
||||
|
||||
auto add_stream_data = [&](StreamID stream_id,
|
||||
const ngtcp2_vec* datav,
|
||||
size_t datalen,
|
||||
uint32_t flags = 0) {
|
||||
std::array<ngtcp2_ssize, 2> result;
|
||||
auto& [nwrite, consumed] = result;
|
||||
if (!ts)
|
||||
ts = get_timestamp();
|
||||
|
||||
for (size_t i = 0; i < datalen; i++)
|
||||
{
|
||||
if (datav[i].base)
|
||||
{
|
||||
log::debug(logcat, "bunch of crap: {}", buffer_printer{datav[i].base, datav[i].len});
|
||||
// debug
|
||||
log::info(logcat, "bunch of crap: {}", buffer_printer{datav[i].base, datav[i].len});
|
||||
}
|
||||
}
|
||||
|
||||
log::trace(
|
||||
logcat, "send_buffer size={}, datalen={}, flags={}", send_buffer.size(), datalen, flags);
|
||||
// debug
|
||||
log::info(
|
||||
logcat, "send_buffer size={}, datalen={}, flags={}", send_buffer.size(), datalen, flags);
|
||||
nwrite = ngtcp2_conn_writev_stream(
|
||||
conn.get(),
|
||||
&path.path,
|
||||
&send_pkt_info,
|
||||
u8data(send_buffer),
|
||||
send_buffer.size(),
|
||||
&consumed,
|
||||
NGTCP2_WRITE_STREAM_FLAG_MORE | flags,
|
||||
stream_id.id,
|
||||
datav,
|
||||
datalen,
|
||||
*ts);
|
||||
return result;
|
||||
};
|
||||
|
||||
auto send_packet = [&](auto nwrite) -> bool {
|
||||
send_buffer_size = nwrite;
|
||||
log::trace(logcat, "Sending {}B packet", send_buffer_size);
|
||||
// debug
|
||||
log::info(logcat, "Sending {}B packet", send_buffer_size);
|
||||
|
||||
auto sent = send();
|
||||
if (sent.blocked())
|
||||
{
|
||||
log::info(logcat, "Packet send blocked, scheduling retransmit");
|
||||
ngtcp2_conn_update_pkt_tx_time(conn.get(), *ts);
|
||||
schedule_retransmit();
|
||||
return false;
|
||||
}
|
||||
|
@ -693,11 +652,10 @@ namespace llarp::quic
|
|||
{
|
||||
log::warning(logcat, "I/O error while trying to send packet: {}", sent.str());
|
||||
// FIXME: disconnect?
|
||||
ngtcp2_conn_update_pkt_tx_time(conn.get(), *ts);
|
||||
return false;
|
||||
}
|
||||
log::trace(logcat, "packet away!");
|
||||
// debug
|
||||
log::debug(logcat, "packet away!");
|
||||
return true;
|
||||
};
|
||||
|
||||
|
@ -707,26 +665,34 @@ namespace llarp::quic
|
|||
if (stream_ptr and not stream_ptr->sent_fin)
|
||||
{
|
||||
// debug
|
||||
log::info(logcat, "A: Appending streamID {} to stream list", stream_id);
|
||||
try {
|
||||
fprintf(stderr, "A: Appending streamID %lld to stream list\n", stream_id.id);
|
||||
try
|
||||
{
|
||||
// debug
|
||||
log::info(logcat, "B: Appending streamID {} to stream list", stream_id);
|
||||
fprintf(stderr, "B: Appending streamID %lld to stream list\n", stream_id.id);
|
||||
strs.push_back(stream_ptr.get());
|
||||
} catch (std::exception& e) {
|
||||
log::info(logcat, "Exception caught: {}", e.what());
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
log::warning(logcat, "Exception caught: {}", e.what());
|
||||
fprintf(stderr, "Exception caught: %s\n", e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
// Maximum number of stream data packets to send out at once; if we reach this then we'll
|
||||
// schedule another event loop call of ourselves (so that we don't starve the loop).
|
||||
constexpr int max_stream_packets = 15;
|
||||
int stream_packets = 0;
|
||||
|
||||
while (!strs.empty() && stream_packets < max_stream_packets)
|
||||
{
|
||||
log::debug(logcat, "Max stream packets: {}\nCurrent stream packets: {}", max_stream_packets, stream_packets);
|
||||
|
||||
for (auto it = strs.begin(); it != strs.end();)
|
||||
{
|
||||
auto& stream = **it;
|
||||
auto bufs = stream.pending();
|
||||
|
||||
if (bufs.empty()) {
|
||||
log::debug(logcat, "Stream buffer empty, have you considered moving on");
|
||||
}
|
||||
|
||||
std::vector<ngtcp2_vec> vecs;
|
||||
vecs.reserve(bufs.size());
|
||||
std::transform(bufs.begin(), bufs.end(), std::back_inserter(vecs), [](const auto& buf) {
|
||||
|
@ -750,93 +716,117 @@ namespace llarp::quic
|
|||
}
|
||||
#endif
|
||||
|
||||
uint32_t extra_flags = 0;
|
||||
// debug
|
||||
fprintf(
|
||||
stderr, "Calling add_stream_data for vector<ngtcp2_vec> of size %zu\n", vecs.size());
|
||||
|
||||
if (stream.is_closing && !stream.sent_fin)
|
||||
{
|
||||
log::debug(logcat, "Sending FIN");
|
||||
extra_flags |= NGTCP2_WRITE_STREAM_FLAG_FIN;
|
||||
flags |= NGTCP2_WRITE_STREAM_FLAG_FIN;
|
||||
stream.sent_fin = true;
|
||||
}
|
||||
else if (stream.is_new)
|
||||
{
|
||||
stream.is_new = false;
|
||||
}
|
||||
// TODO: how can we be in this position and call this fxn with invalid
|
||||
// or stale ptrs
|
||||
|
||||
// debug
|
||||
fprintf(stderr, "Calling add_stream_data for vector<ngtcp2_vec> of size %zu\n", vecs.size());
|
||||
|
||||
auto [nwrite, consumed] =
|
||||
add_stream_data(stream.id(), vecs.data(), vecs.size(), extra_flags);
|
||||
log::trace(
|
||||
logcat,
|
||||
auto nwrite = ngtcp2_conn_writev_stream(
|
||||
conn.get(),
|
||||
&path.path,
|
||||
&send_pkt_info,
|
||||
u8data(send_buffer),
|
||||
send_buffer.size(),
|
||||
&ndatalen,
|
||||
flags,
|
||||
stream.id().id,
|
||||
reinterpret_cast<const ngtcp2_vec*>(vecs.data()),
|
||||
vecs.size(),
|
||||
(!ts) ? get_timestamp() : *ts);
|
||||
|
||||
log::debug(logcat,
|
||||
"add_stream_data for stream {} returned [{},{}]",
|
||||
stream.id(),
|
||||
nwrite,
|
||||
consumed);
|
||||
// debug
|
||||
fprintf(
|
||||
stderr,
|
||||
"add_stream_data for stream %d returned [%ld,%ld]",
|
||||
stream.id(),
|
||||
nwrite,
|
||||
consumed);
|
||||
ndatalen);
|
||||
|
||||
if (nwrite > 0)
|
||||
if (nwrite == 0) // we are congestion limited
|
||||
{
|
||||
if (consumed >= 0)
|
||||
{
|
||||
//debug
|
||||
fprintf(stderr, "Consumed %ld bytes from stream %d", consumed, stream.id());
|
||||
log::trace(logcat, "consumed {} bytes from stream {}", consumed, stream.id());
|
||||
stream.wrote(consumed);
|
||||
}
|
||||
|
||||
log::trace(logcat, "Sending stream data packet");
|
||||
if (!send_packet(nwrite))
|
||||
return;
|
||||
++stream_packets;
|
||||
++it;
|
||||
log::debug(logcat,
|
||||
"Done stream writing to {} (either stream is congested or we have nothing else to "
|
||||
"send right now)",
|
||||
stream.id());
|
||||
ngtcp2_conn_update_pkt_tx_time(conn.get(), *ts);
|
||||
it = strs.erase(it);
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (nwrite)
|
||||
if (nwrite > 0)
|
||||
{
|
||||
case 0:
|
||||
log::trace(
|
||||
logcat,
|
||||
"Done stream writing to {} (either stream is congested or we have nothing else to "
|
||||
"send right now)",
|
||||
if (ndatalen >= 0)
|
||||
{
|
||||
log::debug(logcat, "consumed {} bytes from stream {}", ndatalen, stream.id());
|
||||
stream.wrote(ndatalen);
|
||||
}
|
||||
|
||||
log::debug(logcat, "Sending stream data packet");
|
||||
if (!send_packet(nwrite))
|
||||
return;
|
||||
|
||||
ngtcp2_conn_update_pkt_tx_time(conn.get(), *ts);
|
||||
++stream_packets;
|
||||
it = strs.erase(it);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (nwrite < 0)
|
||||
{
|
||||
if (nwrite == -240) // NGTCP2_ERR_WRITE_MORE
|
||||
{
|
||||
log::debug(logcat,
|
||||
"Consumed {} bytes from stream {} and have space left",
|
||||
ndatalen,
|
||||
stream.id());
|
||||
assert(consumed <= 0);
|
||||
break;
|
||||
case NGTCP2_ERR_WRITE_MORE:
|
||||
log::trace(
|
||||
logcat,
|
||||
"consumed {} bytes from stream {} and have space left",
|
||||
consumed,
|
||||
stream.id());
|
||||
stream.wrote(consumed);
|
||||
stream.wrote(ndatalen);
|
||||
assert(ndatalen >= 0);
|
||||
if (stream.unsent() > 0)
|
||||
{
|
||||
// We have more to send on this stream, so keep us in the queue
|
||||
++it;
|
||||
log::debug(logcat, "We have more to write on stream {}, proceeding", stream.id());
|
||||
std::advance(it, 1);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case NGTCP2_ERR_STREAM_DATA_BLOCKED:
|
||||
log::debug(logcat, "cannot add to stream {} right now: stream is blocked", stream.id());
|
||||
break;
|
||||
case NGTCP2_ERR_STREAM_SHUT_WR:
|
||||
log::trace(logcat, "cannot write to {}: stream is shut down", stream.id());
|
||||
break;
|
||||
default:
|
||||
assert(consumed <= 0);
|
||||
log::warning(
|
||||
logcat, "Error writing to stream {}: {}", stream.id(), ngtcp2_strerror(nwrite));
|
||||
}
|
||||
if (nwrite == -230) // NGTCP2_ERR_CLOSING
|
||||
{
|
||||
log::debug(logcat, "Cannot write to {}: stream is closing", stream.id());
|
||||
continue;
|
||||
}
|
||||
if (nwrite == -221) // NGTCP2_ERR_STREAM_SHUT_WR
|
||||
{
|
||||
log::debug(logcat, "Cannot add to stream {}: stream is shut, proceeding", stream.id());
|
||||
assert(ndatalen == -1);
|
||||
it = strs.erase(it);
|
||||
continue;
|
||||
}
|
||||
if (nwrite == -210) // NGTCP2_ERR_STREAM_DATA_BLOCKED
|
||||
{
|
||||
log::debug(logcat, "Cannot add to stream {}: stream is blocked", stream.id());
|
||||
break;
|
||||
}
|
||||
|
||||
log::warning(logcat, "Error writing non-stream data: {}", ngtcp2_strerror(nwrite));
|
||||
break;
|
||||
}
|
||||
|
||||
if (++stream_packets == max_stream_packets)
|
||||
{
|
||||
log::debug(logcat, "Max stream packets ({}) reached", max_stream_packets);
|
||||
ngtcp2_conn_update_pkt_tx_time(conn.get(), *ts);
|
||||
return;
|
||||
}
|
||||
|
||||
log::debug(logcat, "Ding");
|
||||
it = strs.erase(it);
|
||||
}
|
||||
}
|
||||
|
@ -845,59 +835,83 @@ namespace llarp::quic
|
|||
// packets, and also finishes off any partially-filled packet from above.
|
||||
for (;;)
|
||||
{
|
||||
// debug
|
||||
log::info(logcat, "Calling add_stream_data for empty stream");
|
||||
fprintf(stderr, "Calling add_stream_data for empty stream");
|
||||
fprintf(stderr, "Calling add_stream_data for empty stream\n");
|
||||
|
||||
auto [nwrite, consumed] = add_stream_data(StreamID{}, nullptr, 0);
|
||||
log::trace(logcat, "add_stream_data for non-stream returned [{},{}]", nwrite, consumed);
|
||||
auto nwrite = ngtcp2_conn_writev_stream(
|
||||
conn.get(),
|
||||
&path.path,
|
||||
&send_pkt_info,
|
||||
u8data(send_buffer),
|
||||
send_buffer.size(),
|
||||
&ndatalen,
|
||||
flags,
|
||||
-1,
|
||||
nullptr,
|
||||
0,
|
||||
(!ts) ? get_timestamp() : *ts);
|
||||
|
||||
log::debug(logcat, "add_stream_data for non-stream returned [{},{}]", nwrite, ndatalen);
|
||||
// debug
|
||||
fprintf(stderr, "add_stream_data for non-stream returned [%ld,%ld]", nwrite, consumed);
|
||||
assert(consumed <= 0);
|
||||
if (nwrite == NGTCP2_ERR_WRITE_MORE)
|
||||
fprintf(stderr, "add_stream_data for non-stream returned [%ld,%ld]\n", nwrite, ndatalen);
|
||||
assert(ndatalen <= 0);
|
||||
|
||||
if (nwrite == 0)
|
||||
{
|
||||
log::trace(logcat, "Writing non-stream data frames, and have space left");
|
||||
// debug
|
||||
fprintf(stderr, "Writing non-stream data frames, and have space left");
|
||||
continue;
|
||||
log::debug(
|
||||
logcat, "Nothing else to write for non-stream data for now (or we are congested)");
|
||||
|
||||
ngtcp2_conn_stat cstat;
|
||||
ngtcp2_conn_get_conn_stat(conn.get(), &cstat);
|
||||
log::debug(logcat, "Current unacked bytes in flight: {}, Congestion window: {}",
|
||||
cstat.bytes_in_flight, cstat.cwnd);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (nwrite < 0)
|
||||
{
|
||||
if (nwrite == -240) // NGTCP2_ERR_WRITE_MORE
|
||||
{
|
||||
log::debug(logcat, "Writing non-stream data frames, and have space left");
|
||||
ngtcp2_conn_update_pkt_tx_time(conn.get(), *ts);
|
||||
continue;
|
||||
}
|
||||
if (nwrite == -230) // NGTCP2_ERR_CLOSING
|
||||
{
|
||||
log::warning(logcat, "Error writing non-stream data: {}", ngtcp2_strerror(nwrite));
|
||||
break;
|
||||
}
|
||||
if (nwrite == -210) // NGTCP2_ERR_STREAM_DATA_BLOCKED
|
||||
{
|
||||
log::debug(logcat, "cannot add to empty stream right now: stream is blocked");
|
||||
break;
|
||||
}
|
||||
|
||||
log::warning(logcat, "Error writing non-stream data: {}", ngtcp2_strerror(nwrite));
|
||||
break;
|
||||
}
|
||||
if (nwrite == 0)
|
||||
{
|
||||
log::trace(
|
||||
logcat, "Nothing else to write for non-stream data for now (or we are congested)");
|
||||
// debug
|
||||
fprintf(
|
||||
stderr, "Nothing else to write for non-stream data for now (or we are congested)");
|
||||
ngtcp2_conn_stat cstat;
|
||||
ngtcp2_conn_get_conn_stat(*this, &cstat);
|
||||
log::trace(logcat, "Current unacked bytes in flight: {}", cstat.bytes_in_flight);
|
||||
break;
|
||||
}
|
||||
|
||||
log::trace(logcat, "Sending data packet with non-stream data frames");
|
||||
// debug
|
||||
fprintf(stderr, "Sending data packet with non-stream data frames");
|
||||
if (!send_packet(nwrite))
|
||||
log::debug(logcat, "Sending data packet with non-stream data frames");
|
||||
if (auto rv = send_packet(nwrite); rv != 0)
|
||||
return;
|
||||
ngtcp2_conn_update_pkt_tx_time(conn.get(), *ts);
|
||||
}
|
||||
|
||||
ngtcp2_conn_update_pkt_tx_time(conn.get(), *ts);
|
||||
schedule_retransmit();
|
||||
}
|
||||
|
||||
void
|
||||
Connection::schedule_retransmit()
|
||||
{
|
||||
auto exp = ngtcp2_conn_get_expiry(*this);
|
||||
auto exp = ngtcp2_conn_get_expiry(conn.get());
|
||||
auto expiry = std::chrono::nanoseconds{static_cast<std::chrono::nanoseconds::rep>(exp)};
|
||||
auto ngtcp2_expiry_delta = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
expiry - get_time().time_since_epoch());
|
||||
|
||||
log::debug(logcat, "ngtcp2_conn_get_expiry: {} from now", ngtcp2_expiry_delta);
|
||||
fprintf(stderr, "ngtcp2_conn_get_expiry: %ld from now\n", ngtcp2_expiry_delta.count());
|
||||
|
||||
if (exp == std::numeric_limits<decltype(exp)>::max())
|
||||
{
|
||||
|
@ -908,6 +922,7 @@ namespace llarp::quic
|
|||
|
||||
auto expires_in = std::max(0ms, ngtcp2_expiry_delta);
|
||||
log::debug(logcat, "Next retransmit in {}ms", expires_in.count());
|
||||
fprintf(stderr, "Next retransmit in %ldms\n", expires_in.count());
|
||||
retransmit_timer->stop();
|
||||
retransmit_timer->start(expires_in, 0ms);
|
||||
}
|
||||
|
@ -931,7 +946,7 @@ namespace llarp::quic
|
|||
if (!good)
|
||||
{
|
||||
log::debug(logcat, "stream_open_callback returned failure, dropping stream {}", id);
|
||||
ngtcp2_conn_shutdown_stream(*this, id.id, 1);
|
||||
ngtcp2_conn_shutdown_stream(conn.get(), id.id, 1);
|
||||
io_ready();
|
||||
return NGTCP2_ERR_CALLBACK_FAILURE;
|
||||
}
|
||||
|
@ -989,8 +1004,8 @@ namespace llarp::quic
|
|||
}
|
||||
else
|
||||
{
|
||||
ngtcp2_conn_extend_max_stream_offset(*this, id.id, data.size());
|
||||
ngtcp2_conn_extend_max_offset(*this, data.size());
|
||||
ngtcp2_conn_extend_max_stream_offset(conn.get(), id.id, data.size());
|
||||
ngtcp2_conn_extend_max_offset(conn.get(), data.size());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -1018,8 +1033,8 @@ namespace llarp::quic
|
|||
log::debug(logcat, "Erasing stream {} from {}", id, (void*)it->second.get());
|
||||
streams.erase(it);
|
||||
|
||||
if (!ngtcp2_conn_is_local_stream(*this, id.id))
|
||||
ngtcp2_conn_extend_max_streams_bidi(*this, 1);
|
||||
if (!ngtcp2_conn_is_local_stream(conn.get(), id.id))
|
||||
ngtcp2_conn_extend_max_streams_bidi(conn.get(), 1);
|
||||
|
||||
io_ready(); // Probably superfluous but sometimes we might need to send a FIN or something.
|
||||
}
|
||||
|
@ -1052,7 +1067,7 @@ namespace llarp::quic
|
|||
{
|
||||
auto* s = server();
|
||||
assert(s);
|
||||
s->null_crypto.server_initial(*this);
|
||||
s->null_crypto.server_initial(conn.get());
|
||||
io_ready();
|
||||
return 0;
|
||||
}
|
||||
|
@ -1066,13 +1081,13 @@ namespace llarp::quic
|
|||
bool
|
||||
Connection::get_handshake_completed()
|
||||
{
|
||||
return ngtcp2_conn_get_handshake_completed(*this) != 0;
|
||||
return ngtcp2_conn_get_handshake_completed(conn.get()) != 0;
|
||||
}
|
||||
|
||||
int
|
||||
Connection::get_streams_available()
|
||||
{
|
||||
uint64_t left = ngtcp2_conn_get_streams_bidi_left(*this);
|
||||
uint64_t left = ngtcp2_conn_get_streams_bidi_left(conn.get());
|
||||
constexpr int max_int = std::numeric_limits<int>::max();
|
||||
if (left > static_cast<uint64_t>(max_int))
|
||||
return max_int;
|
||||
|
@ -1084,7 +1099,7 @@ namespace llarp::quic
|
|||
{
|
||||
std::shared_ptr<Stream> stream{new Stream{
|
||||
*this, std::move(data_cb), std::move(close_cb), endpoint.default_stream_buffer_size}};
|
||||
if (int rv = ngtcp2_conn_open_bidi_stream(*this, &stream->stream_id.id, stream.get()); rv != 0)
|
||||
if (int rv = ngtcp2_conn_open_bidi_stream(conn.get(), &stream->stream_id.id, stream.get()); rv != 0)
|
||||
throw std::runtime_error{"Stream creation failed: "s + ngtcp2_strerror(rv)};
|
||||
|
||||
auto& str = streams[stream->stream_id];
|
||||
|
@ -1102,7 +1117,7 @@ namespace llarp::quic
|
|||
int
|
||||
Connection::init_client()
|
||||
{
|
||||
endpoint.null_crypto.client_initial(*this);
|
||||
endpoint.null_crypto.client_initial(conn.get());
|
||||
|
||||
if (int rv = send_magic(NGTCP2_CRYPTO_LEVEL_INITIAL); rv != 0)
|
||||
return rv;
|
||||
|
@ -1123,7 +1138,7 @@ namespace llarp::quic
|
|||
}
|
||||
data.remove_prefix(handshake_magic.size());
|
||||
|
||||
const bool is_server = ngtcp2_conn_is_server(*this);
|
||||
const bool is_server = ngtcp2_conn_is_server(conn.get());
|
||||
if (is_server)
|
||||
{
|
||||
// For a server, we receive the transport parameters in the initial packet (prepended by the
|
||||
|
@ -1143,13 +1158,13 @@ namespace llarp::quic
|
|||
}
|
||||
}
|
||||
|
||||
if (not endpoint.null_crypto.install_rx_handshake_key(*this))
|
||||
if (not endpoint.null_crypto.install_rx_handshake_key(conn.get()))
|
||||
log::debug(logcat, "Call to install_rx_handshake_key unsuccessful at {}", __LINE__);
|
||||
if (not endpoint.null_crypto.install_tx_handshake_key(*this))
|
||||
if (not endpoint.null_crypto.install_tx_handshake_key(conn.get()))
|
||||
log::debug(logcat, "Call to install_tx_handshake_key unsuccessful at {}", __LINE__);
|
||||
if (is_server)
|
||||
{
|
||||
if (not endpoint.null_crypto.install_tx_key(*this))
|
||||
if (not endpoint.null_crypto.install_tx_key(conn.get()))
|
||||
log::debug(logcat, "Call to install_tx_key unsuccessful at {}", __LINE__);
|
||||
}
|
||||
return 0;
|
||||
|
@ -1161,13 +1176,13 @@ namespace llarp::quic
|
|||
log::trace(logcat, "QUIC connection call ngtcp2_conn_handshake_completed");
|
||||
// debug
|
||||
log::debug(logcat, "QUIC connection call ngtcp2_conn_handshake_completed");
|
||||
endpoint.null_crypto.install_rx_key(*this);
|
||||
if (not ngtcp2_conn_is_server(*this))
|
||||
endpoint.null_crypto.install_rx_key(conn.get());
|
||||
if (not ngtcp2_conn_is_server(conn.get()))
|
||||
{
|
||||
if (not endpoint.null_crypto.install_tx_key(*this))
|
||||
if (not endpoint.null_crypto.install_tx_key(conn.get()))
|
||||
log::debug(logcat, "Call to install_tx_key unsuccessful at {}", __LINE__);
|
||||
}
|
||||
ngtcp2_conn_handshake_completed(*this);
|
||||
ngtcp2_conn_handshake_completed(conn.get());
|
||||
|
||||
if (on_handshake_complete)
|
||||
{
|
||||
|
@ -1279,7 +1294,7 @@ namespace llarp::quic
|
|||
return NGTCP2_ERR_TRANSPORT_PARAM;
|
||||
}
|
||||
|
||||
const bool is_server = ngtcp2_conn_is_server(*this);
|
||||
const bool is_server = ngtcp2_conn_is_server(conn.get());
|
||||
|
||||
if (is_server)
|
||||
{
|
||||
|
@ -1296,7 +1311,7 @@ namespace llarp::quic
|
|||
}
|
||||
}
|
||||
|
||||
auto rv = ngtcp2_conn_decode_remote_transport_params(*this, data.data(), data.size());
|
||||
auto rv = ngtcp2_conn_decode_remote_transport_params(conn.get(), data.data(), data.size());
|
||||
log::debug(
|
||||
logcat,
|
||||
"Decode transport params {}",
|
||||
|
@ -1304,11 +1319,11 @@ namespace llarp::quic
|
|||
|
||||
if (rv != 0)
|
||||
{
|
||||
ngtcp2_conn_set_tls_error(*this, rv);
|
||||
ngtcp2_conn_set_tls_error(conn.get(), rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
const auto* params = ngtcp2_conn_get_remote_transport_params(*this);
|
||||
const auto* params = ngtcp2_conn_get_remote_transport_params(conn.get());
|
||||
if (params == nullptr)
|
||||
log::error(
|
||||
logcat,
|
||||
|
@ -1328,7 +1343,7 @@ namespace llarp::quic
|
|||
Connection::send_magic(ngtcp2_crypto_level level)
|
||||
{
|
||||
return ngtcp2_conn_submit_crypto_data(
|
||||
*this, level, handshake_magic.data(), handshake_magic.size());
|
||||
conn.get(), level, handshake_magic.data(), handshake_magic.size());
|
||||
}
|
||||
|
||||
template <typename String>
|
||||
|
@ -1345,7 +1360,7 @@ namespace llarp::quic
|
|||
int
|
||||
Connection::send_transport_params(ngtcp2_crypto_level level)
|
||||
{
|
||||
const auto* tparams = ngtcp2_conn_get_local_transport_params(*this);
|
||||
const auto* tparams = ngtcp2_conn_get_local_transport_params(conn.get());
|
||||
|
||||
if (tparams == nullptr)
|
||||
throw std::runtime_error{
|
||||
|
@ -1371,7 +1386,7 @@ namespace llarp::quic
|
|||
assert(buf < bufend);
|
||||
}
|
||||
|
||||
const bool is_server = ngtcp2_conn_is_server(*this);
|
||||
const bool is_server = ngtcp2_conn_is_server(conn.get());
|
||||
auto exttype = is_server ? NGTCP2_TRANSPORT_PARAMS_TYPE_ENCRYPTED_EXTENSIONS
|
||||
: NGTCP2_TRANSPORT_PARAMS_TYPE_CLIENT_HELLO;
|
||||
|
||||
|
@ -1387,7 +1402,7 @@ namespace llarp::quic
|
|||
return nwrite;
|
||||
}
|
||||
log::debug(logcat, "encoded transport params: {}", buffer_printer{conn_buffer});
|
||||
return ngtcp2_conn_submit_crypto_data(*this, level, u8data(conn_buffer), conn_buffer.size());
|
||||
return ngtcp2_conn_submit_crypto_data(conn.get(), level, u8data(conn_buffer), conn_buffer.size());
|
||||
}
|
||||
|
||||
} // namespace llarp::quic
|
||||
|
|
1452
llarp/quic/connection_old.cpp
Normal file
1452
llarp/quic/connection_old.cpp
Normal file
File diff suppressed because it is too large
Load diff
|
@ -180,7 +180,8 @@ namespace llarp::quic
|
|||
"Immediate Close-ing connection {} due to error {}",
|
||||
conn.base_cid,
|
||||
ngtcp2_strerror(rv));
|
||||
close_connection(conn, rv, "ERR_PROTO"sv);
|
||||
//close_connection(conn, rv, "ERR_PROTO"sv);
|
||||
close_connection(conn, ngtcp2_err_infer_quic_transport_error_code(rv), "ERR_PROTO"sv);
|
||||
}
|
||||
else if (rv == NGTCP2_ERR_DROP_CONN)
|
||||
{
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace llarp::quic
|
|||
}
|
||||
|
||||
void
|
||||
NullCrypto::client_initial(Connection& conn)
|
||||
NullCrypto::client_initial(ngtcp2_conn* conn)
|
||||
{
|
||||
log::debug(logcat, "Client initial null crypto setup");
|
||||
ngtcp2_conn_set_initial_crypto_ctx(conn, &null_ctx);
|
||||
|
@ -48,7 +48,7 @@ namespace llarp::quic
|
|||
}
|
||||
|
||||
void
|
||||
NullCrypto::server_initial(Connection& conn)
|
||||
NullCrypto::server_initial(ngtcp2_conn* conn)
|
||||
{
|
||||
log::debug(logcat, "Server initial null crypto setup");
|
||||
ngtcp2_conn_set_initial_crypto_ctx(conn, &null_ctx);
|
||||
|
@ -69,21 +69,21 @@ namespace llarp::quic
|
|||
}
|
||||
|
||||
bool
|
||||
NullCrypto::install_tx_handshake_key(Connection& conn)
|
||||
NullCrypto::install_tx_handshake_key(ngtcp2_conn* conn)
|
||||
{
|
||||
return ngtcp2_conn_install_tx_handshake_key(
|
||||
conn, &null_aead_ctx, null_iv.data(), null_iv.size(), &null_cipher_ctx)
|
||||
== 0;
|
||||
}
|
||||
bool
|
||||
NullCrypto::install_rx_handshake_key(Connection& conn)
|
||||
NullCrypto::install_rx_handshake_key(ngtcp2_conn* conn)
|
||||
{
|
||||
return ngtcp2_conn_install_rx_handshake_key(
|
||||
conn, &null_aead_ctx, null_iv.data(), null_iv.size(), &null_cipher_ctx)
|
||||
== 0;
|
||||
}
|
||||
bool
|
||||
NullCrypto::install_tx_key(Connection& conn)
|
||||
NullCrypto::install_tx_key(ngtcp2_conn* conn)
|
||||
{
|
||||
return ngtcp2_conn_install_tx_key(
|
||||
conn,
|
||||
|
@ -96,7 +96,7 @@ namespace llarp::quic
|
|||
== 0;
|
||||
}
|
||||
bool
|
||||
NullCrypto::install_rx_key(Connection& conn)
|
||||
NullCrypto::install_rx_key(ngtcp2_conn* conn)
|
||||
{
|
||||
return ngtcp2_conn_install_rx_key(
|
||||
conn, nullptr, 0, &null_aead_ctx, null_iv.data(), null_iv.size(), &null_cipher_ctx)
|
||||
|
|
|
@ -16,20 +16,20 @@ namespace llarp::quic
|
|||
NullCrypto();
|
||||
|
||||
void
|
||||
client_initial(Connection& conn);
|
||||
client_initial(ngtcp2_conn* conn);
|
||||
|
||||
void
|
||||
server_initial(Connection& conn);
|
||||
server_initial(ngtcp2_conn* conn);
|
||||
|
||||
bool
|
||||
install_tx_handshake_key(Connection& conn);
|
||||
install_tx_handshake_key(ngtcp2_conn* conn);
|
||||
bool
|
||||
install_tx_key(Connection& conn);
|
||||
install_tx_key(ngtcp2_conn* conn);
|
||||
|
||||
bool
|
||||
install_rx_handshake_key(Connection& conn);
|
||||
install_rx_handshake_key(ngtcp2_conn* conn);
|
||||
bool
|
||||
install_rx_key(Connection& conn);
|
||||
install_rx_key(ngtcp2_conn* conn);
|
||||
|
||||
private:
|
||||
std::array<uint8_t, 8> null_iv{};
|
||||
|
|
|
@ -179,7 +179,7 @@ namespace llarp::quic
|
|||
//
|
||||
assert(bytes <= unacked_size && unacked_size <= size);
|
||||
|
||||
log::trace(logcat, "Acked {} bytes of {}/{} unacked/total", bytes, unacked_size, size);
|
||||
log::debug(logcat, "Acked {} bytes of {}/{} unacked/total", bytes, unacked_size, size);
|
||||
|
||||
unacked_size -= bytes;
|
||||
size -= bytes;
|
||||
|
@ -310,7 +310,7 @@ namespace llarp::quic
|
|||
// [ áaarrrrrr ] or [rr áaar]
|
||||
// to:
|
||||
// [ áaaaaarrr ] or [aa áaaa]
|
||||
log::trace(logcat, "wrote {}, unsent={}", bytes, unsent());
|
||||
log::debug(logcat, "wrote {}, unsent={}", bytes, unsent());
|
||||
assert(bytes <= unsent());
|
||||
unacked_size += bytes;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
rm -rf build && \
|
||||
mkdir build && \
|
||||
cd build && \
|
||||
cmake .. -DCMAKE_BUILD_TYPE=Release -DWITH_EMBEDDED_LOKINET=ON -DLIBLOKINET_TEST_UTILS=ON -DOXEN_LOGGING_RELEASE_TRACE=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=1 && \
|
||||
cmake .. -DCMAKE_BUILD_TYPE=Debug -DWITH_EMBEDDED_LOKINET=ON -DLIBLOKINET_TEST_UTILS=ON -DOXEN_LOGGING_RELEASE_TRACE=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=1 && \
|
||||
make -j6 && \
|
||||
mkdir -p tcp_connect_data_dir/testnet && \
|
||||
cp ../contrib/bootstrap/mainnet.signed ./tcp_connect_data_dir/bootstrap.signed && \
|
||||
|
|
Loading…
Reference in a new issue