REVERT: verbose close logging

- misc libquic fixes squashed into this
- thread-safe wrapping
pull/2232/head
dr7ana 4 months ago
parent 6073377171
commit 261fc6be83

@ -444,6 +444,7 @@ namespace
// TESTNET:
oxen::log::set_level("quic", oxen::log::Level::critical);
oxen::log::set_level("quicverbose", oxen::log::Level::debug);
if (configFile.has_value())
{

@ -1 +1 @@
Subproject commit ce1b3c9372c317ab2914870cbd44c8630eaa96a5
Subproject commit 84721f477f5dfa52e04a43072cc176a117dfdc58

@ -5,6 +5,7 @@
#include <llarp/constants/version.hpp>
#include <llarp/crypto/crypto.hpp>
#include <llarp/ev/ev.hpp>
#include <llarp/link/link_manager.hpp>
#include <llarp/router/router.hpp>
#include <llarp/util/logging.hpp>
#include <llarp/util/service_manager.hpp>

@ -9,8 +9,8 @@
#include <llarp/service/convotag.hpp>
#include <llarp/service/protocol_type.hpp>
#include <oxenc/variant.h>
#include <oxen/quic.hpp>
#include <oxenc/variant.h>
#include <functional>
#include <memory>

@ -100,9 +100,9 @@ namespace llarp::exit
// TODO: add callback here
if (p->obtain_exit(
exit_key, std::is_same_v<decltype(p), ExitSession> ? 1 : 0, p->TXID().bt_encode()))
log::info(link_cat, "Asking {} for exit", exit_router);
log::info(logcat, "Asking {} for exit", exit_router);
else
log::warning(link_cat, "Failed to send exit request");
log::warning(logcat, "Failed to send exit request");
}
void
@ -150,7 +150,7 @@ namespace llarp::exit
const static auto roles = llarp::path::ePathRoleExit | llarp::path::ePathRoleSVC;
if (p->SupportsAnyRoles(roles))
{
log::info(link_cat, "{} closing exit path", p->name());
log::info(logcat, "{} closing exit path", p->name());
if (p->close_exit(exit_key, p->TXID().bt_encode()))
p->ClearRoles(roles);
else
@ -173,9 +173,9 @@ namespace llarp::exit
// TODO: add callback here
if (p->close_exit(exit_key, p->TXID().bt_encode()))
log::info(link_cat, "");
log::info(logcat, "");
else
log::warning(link_cat, "{} failed to send exit close message", p->name());
log::warning(logcat, "{} failed to send exit close message", p->name());
}
};
ForEachPath(sendExitClose);

@ -269,12 +269,12 @@ namespace llarp::handlers
if (conf.is_reachable)
{
_publish_introset = true;
log::info(link_cat, "TunEndpoint setting to be reachable by default");
log::info(logcat, "TunEndpoint setting to be reachable by default");
}
else
{
_publish_introset = false;
log::info(link_cat, "TunEndpoint setting to be not reachable by default");
log::info(logcat, "TunEndpoint setting to be not reachable by default");
}
if (conf.auth_type == service::AuthType::FILE)

@ -60,13 +60,15 @@ namespace llarp
bool
Endpoint::have_client_conn(const RouterID& remote) const
{
return client_conns.count(remote);
return link_manager.router().loop()->call_get(
[this, remote]() { return client_conns.count(remote); });
}
bool
Endpoint::have_service_conn(const RouterID& remote) const
{
return service_conns.count(remote);
return link_manager.router().loop()->call_get(
[this, remote]() { return service_conns.count(remote); });
}
std::pair<size_t, size_t>
@ -156,7 +158,7 @@ namespace llarp
void
LinkManager::register_commands(
std::shared_ptr<oxen::quic::BTRequestStream>& s, const RouterID& router_id, bool)
const std::shared_ptr<oxen::quic::BTRequestStream>& s, const RouterID& router_id, bool)
{
log::debug(logcat, "{} called", __PRETTY_FUNCTION__);
@ -251,44 +253,54 @@ namespace llarp
// callback set. It will reject any attempted inbound connection to a lokinet client prior to
// handshake completion
tls_creds->set_key_verify_callback([this](const ustring_view& key, const ustring_view& alpn) {
RouterID other{key.data()};
auto us = router().is_bootstrap_seed() ? "Bootstrap seed node"s : "Service node"s;
auto is_snode = is_service_node();
return _router.loop()->call_get([&]() {
RouterID other{key.data()};
auto us = router().is_bootstrap_seed() ? "Bootstrap seed node"s : "Service node"s;
auto is_snode = is_service_node();
if (is_snode)
{
if (alpn == alpns::C_ALPNS)
if (is_snode)
{
log::critical(logcat, "{} node accepting client connection (remote ID:{})!", us, other);
ep.client_conns.emplace(other, nullptr);
return true;
}
if (alpn == alpns::SN_ALPNS)
{
// verify as service node!
bool result = node_db->registered_routers().count(other);
if (alpn == alpns::C_ALPNS)
{
log::critical(logcat, "{} node accepting client connection (remote ID:{})!", us, other);
ep.client_conns.emplace(other, nullptr);
return true;
}
if (alpn == alpns::SN_ALPNS)
{
// verify as service node!
bool result = node_db->registered_routers().count(other);
log::critical(
logcat,
"{} node was {} to confirm remote (RID:{}) is registered; {} connection!",
us,
result ? "able" : "unable",
other,
result ? "allowing" : "rejecting");
if (result)
{
auto [_, b] = ep.service_conns.try_emplace(other, nullptr);
log::critical(
logcat,
"{} node was {} to confirm remote (RID:{}) is registered; {} connection!",
us,
result ? "able" : "unable",
other,
result ? "allowing" : "rejecting");
if (not b)
log::critical(
logcat, "{} node rejecting inbound -- already have connection to remote!", us);
if (result)
ep.service_conns.emplace(other, nullptr);
return result and b;
}
return result;
}
return result;
}
log::critical(logcat, "{} node received unknown ALPN; rejecting connection!", us);
return false;
}
log::critical(logcat, "{} node received unknown ALPN; rejecting connection!", us);
return false;
}
// TESTNET: change this to an error message later; just because someone tries to erroneously
// connect to a local lokinet client doesn't mean we should kill the program?
throw std::runtime_error{"Clients should not be validating inbound connections!"};
// TESTNET: change this to an error message later; just because someone tries to erroneously
// connect to a local lokinet client doesn't mean we should kill the program?
throw std::runtime_error{"Clients should not be validating inbound connections!"};
});
});
if (_router.is_service_node())
{
@ -301,12 +313,12 @@ namespace llarp
LinkManager::make_control(oxen::quic::connection_interface& ci, const RouterID& rid)
{
auto control_stream = ci.queue_incoming_stream<oxen::quic::BTRequestStream>(
[this, rid = rid](oxen::quic::Stream&, uint64_t error_code) {
[/* this, */ rid = rid](oxen::quic::Stream&, uint64_t error_code) {
log::warning(
logcat,
"BTRequestStream closed unexpectedly (ec:{}); closing inbound connection...",
error_code);
ep.close_connection(rid);
// ep.close_connection(rid);
});
log::critical(logcat, "Queued BTStream to be opened (ID:{})", control_stream->stream_id());
@ -325,7 +337,10 @@ namespace llarp
if (auto it = ep.service_conns.find(rid); it != ep.service_conns.end())
{
log::critical(logcat, "Configuring inbound connection from relay RID:{}", rid);
it->second = std::make_shared<link::Connection>(ci.shared_from_this(), make_control(ci, rid));
if (!it->second)
it->second =
std::make_shared<link::Connection>(ci.shared_from_this(), make_control(ci, rid));
}
else if (auto it = ep.client_conns.find(rid); it != ep.client_conns.end())
{
@ -357,7 +372,8 @@ namespace llarp
{
log::critical(
logcat,
"ERROR: connection established to RID:{} that was not logged in key verifrication!",
"ERROR: connection established to RID:{} that was not logged in connection "
"establishment!",
rid);
}
}
@ -384,7 +400,7 @@ namespace llarp
}
else
{
log::critical(logcat, "Outbound connection from {} (remote:{})", rid, remote);
log::critical(logcat, "Outbound connection to {} (remote:{})", rid, remote);
on_outbound_conn(conn_interface);
}
});

@ -6,6 +6,7 @@
#include <llarp/crypto/crypto.hpp>
#include <llarp/messages/common.hpp>
#include <llarp/path/transit_hop.hpp>
#include <llarp/router/router.hpp>
#include <llarp/router_contact.hpp>
#include <llarp/util/compare_ptr.hpp>
#include <llarp/util/decaying_hashset.hpp>
@ -245,7 +246,7 @@ namespace llarp
void
register_commands(
std::shared_ptr<oxen::quic::BTRequestStream>& s,
const std::shared_ptr<oxen::quic::BTRequestStream>& s,
const RouterID& rid,
bool client_only = false);
@ -437,59 +438,71 @@ namespace llarp
std::function<void(oxen::quic::message m)> func,
Opt&&... opts)
{
try
{
const auto& rid = rc.router_id();
const auto& is_snode = _is_service_node;
const auto& is_control = ep.has_value();
const auto us = is_snode ? "Relay"s : "Client"s;
log::critical(logcat, "Establishing connection to RID:{}", rid);
// add to service conns
auto [itr, b] = service_conns.emplace(rid, nullptr);
auto conn_interface = endpoint->connect(
remote,
link_manager.tls_creds,
is_snode ? ROUTER_KEEP_ALIVE : CLIENT_KEEP_ALIVE,
std::forward<Opt>(opts)...);
// auto
std::shared_ptr<oxen::quic::BTRequestStream> control_stream =
conn_interface->template open_stream<oxen::quic::BTRequestStream>(
[this, rid = rid](oxen::quic::Stream&, uint64_t error_code) {
log::warning(
logcat,
"BTRequestStream closed unexpectedly (ec:{}); closing outbound connection...",
error_code);
close_connection(rid);
});
if (is_snode)
link_manager.register_commands(control_stream, rid);
else
log::critical(logcat, "Client NOT registering BTStream commands!");
log::critical(
logcat,
"{} dispatching {} on outbound connection to remote (rid:{})",
us,
is_control ? "control message (ep:{})"_format(ep) : "data message",
rid);
(is_control) ? control_stream->command(std::move(*ep), std::move(body), std::move(func))
: conn_interface->send_datagram(std::move(body));
itr->second = std::make_shared<link::Connection>(conn_interface, control_stream, true);
log::critical(logcat, "Outbound connection to RID:{} added to service conns...", rid);
return true;
}
catch (...)
{
log::error(quic_cat, "Error: failed to establish connection to {}", remote);
return false;
}
return link_manager.router().loop()->call_get([&]() {
try
{
const auto& rid = rc.router_id();
const auto& is_snode = _is_service_node;
const auto& is_control = ep.has_value();
const auto us = is_snode ? "Relay"s : "Client"s;
log::critical(logcat, "Establishing connection to RID:{}", rid);
// add to service conns
auto [itr, b] = service_conns.try_emplace(rid, nullptr);
if (not b)
{
log::critical(logcat, "ERROR: attempting to establish an already-existing connection");
(is_control) ? itr->second->control_stream->command(
std::move(*ep), std::move(body), std::move(func))
: itr->second->conn->send_datagram(std::move(body));
return true;
}
auto conn_interface = endpoint->connect(
remote,
link_manager.tls_creds,
is_snode ? ROUTER_KEEP_ALIVE : CLIENT_KEEP_ALIVE,
std::forward<Opt>(opts)...);
// auto
std::shared_ptr<oxen::quic::BTRequestStream> control_stream =
conn_interface->template open_stream<oxen::quic::BTRequestStream>(
[rid = rid](oxen::quic::Stream&, uint64_t error_code) {
log::warning(
logcat,
"BTRequestStream closed unexpectedly (ec:{}); closing outbound "
"connection...",
error_code);
// close_connection(rid);
});
if (is_snode)
link_manager.register_commands(control_stream, rid);
else
log::critical(logcat, "Client NOT registering BTStream commands!");
log::critical(
logcat,
"{} dispatching {} on outbound connection to remote (rid:{})",
us,
is_control ? "control message (ep:{})"_format(ep) : "data message",
rid);
(is_control) ? control_stream->command(std::move(*ep), std::move(body), std::move(func))
: conn_interface->send_datagram(std::move(body));
itr->second = std::make_shared<link::Connection>(conn_interface, control_stream, true);
log::critical(logcat, "Outbound connection to RID:{} added to service conns...", rid);
return true;
}
catch (...)
{
log::error(quic_cat, "Error: failed to establish connection to {}", remote);
return false;
}
});
}
template <typename... Opt>
@ -497,44 +510,52 @@ namespace llarp
Endpoint::establish_connection(
const oxen::quic::RemoteAddress& remote, const RemoteRC& rc, Opt&&... opts)
{
try
{
const auto& rid = rc.router_id();
const auto& is_snode = _is_service_node;
log::critical(logcat, "Establishing connection to RID:{}", rid);
// add to service conns
auto [itr, b] = service_conns.emplace(rid, nullptr);
auto conn_interface = endpoint->connect(
remote,
link_manager.tls_creds,
is_snode ? ROUTER_KEEP_ALIVE : CLIENT_KEEP_ALIVE,
std::forward<Opt>(opts)...);
auto control_stream = conn_interface->template open_stream<oxen::quic::BTRequestStream>(
[this, rid = rid](oxen::quic::Stream&, uint64_t error_code) {
log::warning(
logcat,
"BTRequestStream closed unexpectedly (ec:{}); closing outbound connection...",
error_code);
close_connection(rid);
});
if (is_snode)
link_manager.register_commands(control_stream, rid);
else
log::critical(logcat, "Client NOT registering BTStream commands!");
itr->second = std::make_shared<link::Connection>(conn_interface, control_stream, true);
log::critical(logcat, "Outbound connection to RID:{} added to service conns...", rid);
return true;
}
catch (...)
{
log::error(quic_cat, "Error: failed to establish connection to {}", remote);
return false;
}
return link_manager.router().loop()->call_get([&]() {
try
{
const auto& rid = rc.router_id();
const auto& is_snode = _is_service_node;
log::critical(logcat, "Establishing connection to RID:{}", rid);
// add to service conns
auto [itr, b] = service_conns.try_emplace(rid, nullptr);
if (not b)
{
log::critical(logcat, "ERROR: attempting to establish an already-existing connection");
return b;
}
auto conn_interface = endpoint->connect(
remote,
link_manager.tls_creds,
is_snode ? ROUTER_KEEP_ALIVE : CLIENT_KEEP_ALIVE,
std::forward<Opt>(opts)...);
auto control_stream = conn_interface->template open_stream<oxen::quic::BTRequestStream>(
[rid = rid](oxen::quic::Stream&, uint64_t error_code) {
log::warning(
logcat,
"BTRequestStream closed unexpectedly (ec:{}); closing outbound connection...",
error_code);
// close_connection(rid);
});
if (is_snode)
link_manager.register_commands(control_stream, rid);
else
log::critical(logcat, "Client NOT registering BTStream commands!");
itr->second = std::make_shared<link::Connection>(conn_interface, control_stream, true);
log::critical(logcat, "Outbound connection to RID:{} added to service conns...", rid);
return true;
}
catch (...)
{
log::error(quic_cat, "Error: failed to establish connection to {}", remote);
return false;
}
});
}
} // namespace link
} // namespace llarp

@ -2,6 +2,7 @@
#include "crypto/types.hpp"
#include "dht/kademlia.hpp"
#include "link/link_manager.hpp"
#include "messages/fetch.hpp"
#include "router_contact.hpp"
#include "util/time.hpp"

@ -2,6 +2,7 @@
#include "router.hpp"
#include <llarp/link/link_manager.hpp>
#include <llarp/service/context.hpp>
namespace llarp

@ -7,6 +7,7 @@
#include <llarp/dht/node.hpp>
#include <llarp/ev/ev.hpp>
#include <llarp/link/contacts.hpp>
#include <llarp/link/link_manager.hpp>
#include <llarp/messages/dht.hpp>
#include <llarp/net/net.hpp>
#include <llarp/nodedb.hpp>
@ -381,6 +382,7 @@ namespace llarp
// TESTNET:
oxen::log::set_level("quic", oxen::log::Level::critical);
oxen::log::set_level("quicverbose", oxen::log::Level::debug);
log::debug(logcat, "Configuring router");
@ -1076,7 +1078,7 @@ namespace llarp
continue;
}
log::debug(logcat, "Establishing session to {} for service node testing", router);
log::critical(logcat, "Establishing session to {} for service node testing", router);
// try to make a session to this random router
// this will do a dht lookup if needed

@ -11,7 +11,7 @@
#include <llarp/ev/ev.hpp>
#include <llarp/exit/context.hpp>
#include <llarp/handlers/tun.hpp>
#include <llarp/link/link_manager.hpp>
// #include <llarp/link/link_manager.hpp>
#include <llarp/path/path_context.hpp>
#include <llarp/profiling.hpp>
#include <llarp/router_contact.hpp>
@ -37,8 +37,15 @@
#include <unordered_map>
#include <vector>
namespace llarp::link
{
struct Connection;
}
namespace llarp
{
struct LinkManager;
/// number of routers to publish to
inline constexpr size_t INTROSET_RELAY_REDUNDANCY{2};

@ -12,8 +12,8 @@
#include <llarp/util/time.hpp>
#include <nlohmann/json.hpp>
#include <oxenc/bt_producer.h>
#include <oxen/quic.hpp>
#include <oxenc/bt_producer.h>
#include <functional>
#include <vector>

@ -11,6 +11,7 @@
#include <llarp/dht/key.hpp>
#include <llarp/link/contacts.hpp>
#include <llarp/link/tunnel.hpp>
#include <llarp/messages/common.hpp>
#include <llarp/net/ip.hpp>
#include <llarp/net/ip_range.hpp>
#include <llarp/nodedb.hpp>
@ -214,7 +215,7 @@ namespace llarp::service
}
catch (...)
{
log::warning(link_cat, "Failed to parse find name response!");
log::warning(logcat, "Failed to parse find name response!");
return resultHandler({});
}
@ -797,7 +798,7 @@ namespace llarp::service
// return;
// }
log::info(link_cat, "{} looking up ONS name {}", Name(), name);
log::info(logcat, "{} looking up ONS name {}", Name(), name);
auto paths = GetUniqueEndpointsForLookup();
// // not enough paths
@ -828,14 +829,14 @@ namespace llarp::service
auto status = btdc.require<std::string_view>(messages::STATUS_KEY);
if (status != "OK"sv)
{
log::info(link_cat, "Error on ONS lookup: {}", status);
log::info(logcat, "Error on ONS lookup: {}", status);
func(std::string{status}, false);
}
name = btdc.require<std::string>("NAME");
}
catch (...)
{
log::warning(link_cat, "Failed to parse find name response!");
log::warning(logcat, "Failed to parse find name response!");
func("ERROR"s, false);
}
@ -844,7 +845,7 @@ namespace llarp::service
for (const auto& path : chosenpaths)
{
log::info(link_cat, "{} lookup {} from {}", Name(), name, path->Endpoint());
log::info(logcat, "{} lookup {} from {}", Name(), name, path->Endpoint());
path->find_name(name, response_cb);
}
}
@ -1329,14 +1330,14 @@ namespace llarp::service
auto status = btdc.require<std::string_view>(messages::STATUS_KEY);
if (status != "OK"sv)
{
log::info(link_cat, "Error in find intro set response: {}", status);
log::info(logcat, "Error in find intro set response: {}", status);
return;
}
introset = btdc.require<std::string>("INTROSET");
}
catch (...)
{
log::warning(link_cat, "Failed to parse find name response!");
log::warning(logcat, "Failed to parse find name response!");
throw;
}
@ -1369,11 +1370,11 @@ namespace llarp::service
{
if (tag.IsZero())
{
log::warning(link_cat, "SendToOrQueue failed: convo tag is zero");
log::warning(logcat, "SendToOrQueue failed: convo tag is zero");
return false;
}
log::debug(link_cat, "{} sending {} bytes (Tag: {})", Name(), payload.size(), tag);
log::debug(logcat, "{} sending {} bytes (Tag: {})", Name(), payload.size(), tag);
if (auto maybe = GetEndpointWithConvoTag(tag))
{
@ -1387,7 +1388,7 @@ namespace llarp::service
}
}
log::debug(link_cat, "SendToOrQueue failed: no endpoint for convo tag {}", tag);
log::debug(logcat, "SendToOrQueue failed: no endpoint for convo tag {}", tag);
return false;
}

@ -5,6 +5,7 @@
#include "endpoint_util.hpp"
#include "protocol_type.hpp"
#include <llarp/messages/common.hpp>
#include <llarp/nodedb.hpp>
#include <llarp/router/router.hpp>
@ -167,7 +168,7 @@ namespace llarp::service
if (updatingIntroSet or marked_bad or now < last_introset_update + IntrosetUpdateInterval)
return;
log::info(link_cat, "{} updating introset", Name());
log::info(logcat, "{} updating introset", Name());
last_introset_update = now;
const auto paths = GetManyPathsWithUniqueEndpoints(&ep, 2, location);
@ -178,7 +179,7 @@ namespace llarp::service
path->find_intro(location, false, relayOrder, [this](std::string resp) mutable {
if (marked_bad)
{
log::info(link_cat, "Outbound context has been marked bad (whatever that means)");
log::info(logcat, "Outbound context has been marked bad (whatever that means)");
return;
}
@ -192,14 +193,14 @@ namespace llarp::service
auto status = btdc.require<std::string_view>(messages::STATUS_KEY);
if (status != "OK"sv)
{
log::info(link_cat, "Error in find intro set response: {}", status);
log::info(logcat, "Error in find intro set response: {}", status);
return;
}
introset = btdc.require<std::string>("INTROSET");
}
catch (...)
{
log::warning(link_cat, "Failed to parse find name response!");
log::warning(logcat, "Failed to parse find name response!");
throw;
}
@ -208,12 +209,12 @@ namespace llarp::service
if (intro.time_signed == 0s)
{
log::warning(link_cat, "{} recieved introset with zero timestamp");
log::warning(logcat, "{} recieved introset with zero timestamp");
return;
}
if (current_intro.time_signed > intro.time_signed)
{
log::info(link_cat, "{} received outdated introset; dropping", Name());
log::info(logcat, "{} received outdated introset; dropping", Name());
return;
}
@ -223,7 +224,7 @@ namespace llarp::service
if (intro.IsExpired(llarp::time_now_ms()))
{
log::warning(link_cat, "{} received expired introset", Name());
log::warning(logcat, "{} received expired introset", Name());
return;
}
@ -605,7 +606,7 @@ namespace llarp::service
if (generated_convo_intro)
{
log::warning(link_cat, "{} has generated an unsent initial handshake; dropping packet");
log::warning(logcat, "{} has generated an unsent initial handshake; dropping packet");
return;
}

@ -5,8 +5,8 @@
#include <llarp/net/ip_packet.hpp>
#include <llarp/net/ip_range.hpp>
#include <oxenc/variant.h>
#include <oxen/quic.hpp>
#include <oxenc/variant.h>
#include <set>

Loading…
Cancel
Save