gossip storage, logs

pull/2228/head
dr7ana 6 months ago
parent 6fdfb4cef6
commit 9e31300d0f

@ -5,7 +5,7 @@ namespace llarp::link
Connection::Connection( Connection::Connection(
const std::shared_ptr<oxen::quic::connection_interface>& c, const std::shared_ptr<oxen::quic::connection_interface>& c,
std::shared_ptr<oxen::quic::BTRequestStream>& s) std::shared_ptr<oxen::quic::BTRequestStream>& s)
: conn{c}, control_stream{s} /* , remote_rc{std::move(rc)} */ : conn{c}, control_stream{s}, inbound{conn->is_inbound()}
{} {}
} // namespace llarp::link } // namespace llarp::link

@ -67,6 +67,22 @@ namespace llarp
return active_conns.count(remote) or pending_conns.count(remote); return active_conns.count(remote) or pending_conns.count(remote);
} }
std::pair<size_t, size_t>
Endpoint::num_in_out() const
{
size_t in{0}, out{0};
for (const auto& c : active_conns)
{
if (c.second->inbound)
++in;
else
++out;
}
return {in, out};
}
size_t size_t
Endpoint::num_connected(bool clients_only) const Endpoint::num_connected(bool clients_only) const
{ {
@ -494,16 +510,17 @@ namespace llarp
void void
LinkManager::connect_to(const RemoteRC& rc, conn_open_hook on_open, conn_closed_hook on_close) LinkManager::connect_to(const RemoteRC& rc, conn_open_hook on_open, conn_closed_hook on_close)
{ {
if (auto conn = ep.get_conn(rc.router_id()); conn) const auto& rid = rc.router_id();
if (ep.have_conn(rid))
{ {
log::error(logcat, "We should not be here!"); log::warning(logcat, "We already have a connection to {}!", rid);
// TODO: should implement some connection failed logic, but not the same logic that // TODO: should implement some connection failed logic, but not the same logic that
// would be executed for another failure case // would be executed for another failure case
return; return;
} }
const auto& remote_addr = rc.addr(); const auto& remote_addr = rc.addr();
const auto& rid = rc.router_id();
// TODO: confirm remote end is using the expected pubkey (RouterID). // TODO: confirm remote end is using the expected pubkey (RouterID).
// TODO: ALPN for "client" vs "relay" (could just be set on endpoint creation) // TODO: ALPN for "client" vs "relay" (could just be set on endpoint creation)
@ -560,6 +577,12 @@ namespace llarp
} }
} }
std::pair<size_t, size_t>
LinkManager::num_in_out() const
{
return ep.num_in_out();
}
size_t size_t
LinkManager::get_num_connected(bool clients_only) const LinkManager::get_num_connected(bool clients_only) const
{ {
@ -613,7 +636,7 @@ namespace llarp
auto res = auto res =
client_only ? not ep.have_client_conn(rc.router_id()) : not ep.have_conn(rc.router_id()); client_only ? not ep.have_client_conn(rc.router_id()) : not ep.have_conn(rc.router_id());
log::critical(logcat, "RID:{} {}", rc.router_id(), res ? "ACCEPTED" : "REJECTED"); log::debug(logcat, "RID:{} {}", rc.router_id(), res ? "ACCEPTED" : "REJECTED");
return res; return res;
}; };
@ -640,6 +663,8 @@ namespace llarp
LinkManager::gossip_rc( LinkManager::gossip_rc(
const RouterID& gossip_src, const RouterID& last_sender, std::string serialized_rc) const RouterID& gossip_src, const RouterID& last_sender, std::string serialized_rc)
{ {
int count = 0;
for (auto& [rid, conn] : ep.active_conns) for (auto& [rid, conn] : ep.active_conns)
{ {
// don't send back to the gossip source or the last sender // don't send back to the gossip source or the last sender
@ -650,8 +675,6 @@ namespace llarp
if (not conn->remote_is_relay) if (not conn->remote_is_relay)
continue; continue;
log::critical(logcat, "Dispatching gossip_rc to {}", rid);
send_control_message( send_control_message(
rid, rid,
"gossip_rc"s, "gossip_rc"s,
@ -659,7 +682,10 @@ namespace llarp
[](oxen::quic::message) mutable { [](oxen::quic::message) mutable {
log::critical(logcat, "PLACEHOLDER FOR GOSSIP RC RESPONSE HANDLER"); log::critical(logcat, "PLACEHOLDER FOR GOSSIP RC RESPONSE HANDLER");
}); });
++count;
} }
log::critical(logcat, "Dispatched {} GossipRC requests!", count);
} }
void void

@ -72,6 +72,9 @@ namespace llarp
bool bool
have_conn(const RouterID& remote) const; have_conn(const RouterID& remote) const;
std::pair<size_t, size_t>
num_in_out() const;
size_t size_t
num_connected(bool clients_only) const; num_connected(bool clients_only) const;
@ -291,6 +294,9 @@ namespace llarp
void void
set_conn_persist(const RouterID& remote, llarp_time_t until); set_conn_persist(const RouterID& remote, llarp_time_t until);
std::pair<size_t, size_t>
num_in_out() const;
size_t size_t
get_num_connected(bool clients_only = false) const; get_num_connected(bool clients_only = false) const;

@ -915,15 +915,6 @@ namespace llarp
return rc_lookup.count(pk); return rc_lookup.count(pk);
} }
std::optional<RemoteRC>
NodeDB::get_rc(const RemoteRC& pk) const
{
if (auto itr = known_rcs.find(pk); itr != known_rcs.end())
return *itr;
return std::nullopt;
}
std::optional<RemoteRC> std::optional<RemoteRC>
NodeDB::get_rc(const RouterID& pk) const NodeDB::get_rc(const RouterID& pk) const
{ {
@ -997,7 +988,7 @@ namespace llarp
bool bool
NodeDB::verify_store_gossip_rc(const RemoteRC& rc) NodeDB::verify_store_gossip_rc(const RemoteRC& rc)
{ {
if (not registered_routers().count(rc.router_id())) if (registered_routers().count(rc.router_id()))
return put_rc_if_newer(rc); return put_rc_if_newer(rc);
return false; return false;
@ -1006,13 +997,15 @@ namespace llarp
bool bool
NodeDB::put_rc_if_newer(RemoteRC rc) NodeDB::put_rc_if_newer(RemoteRC rc)
{ {
if (auto maybe = get_rc(rc)) if (auto maybe = get_rc(rc.router_id()))
{ {
if (maybe->other_is_newer(rc)) if (maybe->other_is_newer(rc))
return put_rc(rc); return put_rc(rc);
return false;
} }
return false; return put_rc(rc);
} }
void void

@ -423,9 +423,6 @@ namespace llarp
std::optional<RemoteRC> std::optional<RemoteRC>
get_rc(const RouterID& pk) const; get_rc(const RouterID& pk) const;
std::optional<RemoteRC>
get_rc(const RemoteRC& pk) const;
std::optional<RemoteRC> std::optional<RemoteRC>
get_random_rc() const; get_random_rc() const;
@ -450,7 +447,8 @@ namespace llarp
get_random_rc_conditional(std::function<bool(RemoteRC)> hook) const; get_random_rc_conditional(std::function<bool(RemoteRC)> hook) const;
std::optional<std::vector<RemoteRC>> std::optional<std::vector<RemoteRC>>
get_n_random_rcs_conditional(size_t n, std::function<bool(RemoteRC)> hook, bool exact = false) const; get_n_random_rcs_conditional(
size_t n, std::function<bool(RemoteRC)> hook, bool exact = false) const;
// Updates `current` to not contain any of the elements of `replace` and resamples (up to // Updates `current` to not contain any of the elements of `replace` and resamples (up to
// `target_size`) from population to refill it. // `target_size`) from population to refill it.

@ -750,14 +750,18 @@ namespace llarp
if (is_service_node()) if (is_service_node())
{ {
auto [in, out] = _link_manager->num_in_out();
log::critical( log::critical(
logcat, logcat,
"Local Service Node has {} RCs, {} RIDs, {} bootstrap peers, {} router " "Local Service Node has {} RCs, {} RIDs, {} bootstrap peers, {}:{} (inbound:outbound) "
"router "
"connections, and {} client connections since last RC update ({} to expiry)", "connections, and {} client connections since last RC update ({} to expiry)",
_node_db->num_rcs(), _node_db->num_rcs(),
_node_db->num_rids(), _node_db->num_rids(),
_node_db->num_bootstraps(), _node_db->num_bootstraps(),
num_router_connections(), in,
out,
num_client_connections(), num_client_connections(),
router_contact.time_to_expiry(now)); router_contact.time_to_expiry(now));
} }
@ -874,7 +878,7 @@ namespace llarp
last_rc_gossip = now_timepoint; last_rc_gossip = now_timepoint;
// TESTNET: 1 to 2 minutes before testnet gossip interval // TESTNET: 1 to 4 minutes before testnet gossip interval
auto random_delta = auto random_delta =
std::chrono::seconds{std::uniform_int_distribution<size_t>{60, 300}(llarp::csrng)}; std::chrono::seconds{std::uniform_int_distribution<size_t>{60, 300}(llarp::csrng)};
// 1min to 5min before "stale time" is next gossip time // 1min to 5min before "stale time" is next gossip time

@ -49,7 +49,7 @@ namespace llarp
(INTROSET_RELAY_REDUNDANCY * INTROSET_REQS_PER_RELAY)}; (INTROSET_RELAY_REDUNDANCY * INTROSET_REQS_PER_RELAY)};
// TESTNET: these constants are shortened for testing purposes // TESTNET: these constants are shortened for testing purposes
inline constexpr std::chrono::milliseconds TESTNET_GOSSIP_INTERVAL{4min}; inline constexpr std::chrono::milliseconds TESTNET_GOSSIP_INTERVAL{10min};
inline constexpr std::chrono::milliseconds RC_UPDATE_INTERVAL{4min}; inline constexpr std::chrono::milliseconds RC_UPDATE_INTERVAL{4min};
// as we advance towards full mesh, we try to connect to this number per tick // as we advance towards full mesh, we try to connect to this number per tick
inline constexpr int FULL_MESH_ITERATION{1}; inline constexpr int FULL_MESH_ITERATION{1};

Loading…
Cancel
Save