gossip storage, logs

pull/2232/head
dr7ana 5 months ago
parent 687d6556d5
commit ae38dc7110

@ -5,7 +5,7 @@ namespace llarp::link
Connection::Connection(
const std::shared_ptr<oxen::quic::connection_interface>& c,
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

@ -67,6 +67,22 @@ namespace llarp
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
Endpoint::num_connected(bool clients_only) const
{
@ -494,16 +510,17 @@ namespace llarp
void
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
// would be executed for another failure case
return;
}
const auto& remote_addr = rc.addr();
const auto& rid = rc.router_id();
// TODO: confirm remote end is using the expected pubkey (RouterID).
// 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
LinkManager::get_num_connected(bool clients_only) const
{
@ -613,7 +636,7 @@ namespace llarp
auto res =
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;
};
@ -640,6 +663,8 @@ namespace llarp
LinkManager::gossip_rc(
const RouterID& gossip_src, const RouterID& last_sender, std::string serialized_rc)
{
int count = 0;
for (auto& [rid, conn] : ep.active_conns)
{
// don't send back to the gossip source or the last sender
@ -650,8 +675,6 @@ namespace llarp
if (not conn->remote_is_relay)
continue;
log::critical(logcat, "Dispatching gossip_rc to {}", rid);
send_control_message(
rid,
"gossip_rc"s,
@ -659,7 +682,10 @@ namespace llarp
[](oxen::quic::message) mutable {
log::critical(logcat, "PLACEHOLDER FOR GOSSIP RC RESPONSE HANDLER");
});
++count;
}
log::critical(logcat, "Dispatched {} GossipRC requests!", count);
}
void

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

@ -915,15 +915,6 @@ namespace llarp
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>
NodeDB::get_rc(const RouterID& pk) const
{
@ -997,7 +988,7 @@ namespace llarp
bool
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 false;
@ -1006,13 +997,15 @@ namespace llarp
bool
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))
return put_rc(rc);
return false;
}
return false;
return put_rc(rc);
}
void

@ -423,9 +423,6 @@ namespace llarp
std::optional<RemoteRC>
get_rc(const RouterID& pk) const;
std::optional<RemoteRC>
get_rc(const RemoteRC& pk) const;
std::optional<RemoteRC>
get_random_rc() const;
@ -450,7 +447,8 @@ namespace llarp
get_random_rc_conditional(std::function<bool(RemoteRC)> hook) const;
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
// `target_size`) from population to refill it.

@ -750,14 +750,18 @@ namespace llarp
if (is_service_node())
{
auto [in, out] = _link_manager->num_in_out();
log::critical(
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)",
_node_db->num_rcs(),
_node_db->num_rids(),
_node_db->num_bootstraps(),
num_router_connections(),
in,
out,
num_client_connections(),
router_contact.time_to_expiry(now));
}
@ -874,7 +878,7 @@ namespace llarp
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 =
std::chrono::seconds{std::uniform_int_distribution<size_t>{60, 300}(llarp::csrng)};
// 1min to 5min before "stale time" is next gossip time

@ -49,7 +49,7 @@ namespace llarp
(INTROSET_RELAY_REDUNDANCY * INTROSET_REQS_PER_RELAY)};
// 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};
// as we advance towards full mesh, we try to connect to this number per tick
inline constexpr int FULL_MESH_ITERATION{1};

Loading…
Cancel
Save