Compare commits

...

4 Commits

Author SHA1 Message Date
dr7ana 4e28bca984
Merge ea614ed141 into c693569c00 2023-12-12 19:57:35 +00:00
dr7ana ea614ed141 better! 2023-12-12 11:57:15 -08:00
dr7ana 49dbdf1062 doofus 2023-12-12 10:45:14 -08:00
Jason Rhinelander 2f1917040c
Fix std::set move semantics
This is, apparently, the only way to move an element out of a std::set.
2023-12-12 14:31:26 -04:00
9 changed files with 73 additions and 59 deletions

View File

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

View File

@ -11,7 +11,7 @@ namespace llarp::link
{
std::shared_ptr<oxen::quic::connection_interface> conn;
std::shared_ptr<oxen::quic::BTRequestStream> control_stream;
RemoteRC remote_rc;
// std::optional<RemoteRC> remote_rc;
// one side of a connection will be responsible for some things, e.g. heartbeat
bool inbound{false};
@ -19,8 +19,7 @@ namespace llarp::link
Connection(
const std::shared_ptr<oxen::quic::connection_interface>& c,
std::shared_ptr<oxen::quic::BTRequestStream>& s,
const RemoteRC& rc);
std::shared_ptr<oxen::quic::BTRequestStream>& s);
};
} // namespace llarp::link

View File

@ -72,8 +72,16 @@ namespace llarp
{
auto itr = conns.begin();
std::advance(itr, randint() % size);
router = itr->second->remote_rc;
return true;
RouterID rid{itr->second->conn->remote_key()};
if (auto maybe = link_manager.node_db->get_rc(rid))
{
router = *maybe;
return true;
}
return false;
}
log::warning(quic_cat, "Error: failed to fetch random connection");
@ -118,24 +126,24 @@ namespace llarp
LinkManager::register_commands(std::shared_ptr<oxen::quic::BTRequestStream>& s)
{
assert(ep.connid_map.count(s->conn_id()));
const RouterID& rid = ep.connid_map[s->conn_id()];
const RouterID& router_id = ep.connid_map[s->conn_id()];
s->register_command("path_build"s, [this, rid](oxen::quic::message m) {
s->register_command("path_build"s, [this, rid = router_id](oxen::quic::message m) {
_router.loop()->call(
[this, &rid, msg = std::move(m)]() mutable { handle_path_build(std::move(msg), rid); });
});
s->register_command("path_control"s, [this, rid](oxen::quic::message m) {
s->register_command("path_control"s, [this, rid = router_id](oxen::quic::message m) {
_router.loop()->call(
[this, &rid, msg = std::move(m)]() mutable { handle_path_control(std::move(msg), rid); });
});
s->register_command("gossip_rc"s, [this, rid](oxen::quic::message m) {
s->register_command("gossip_rc"s, [this](oxen::quic::message m) {
_router.loop()->call(
[this, msg = std::move(m)]() mutable { handle_gossip_rc(std::move(msg)); });
});
s->register_command("bfetch_rcs"s, [this, rid](oxen::quic::message m) {
s->register_command("bfetch_rcs"s, [this](oxen::quic::message m) {
_router.loop()->call(
[this, msg = std::move(m)]() mutable { handle_fetch_bootstrap_rcs(std::move(msg)); });
});
@ -143,7 +151,7 @@ namespace llarp
for (auto& method : direct_requests)
{
s->register_command(
std::string{method.first}, [this, func = method.second](oxen::quic::message m) {
std::string{method.first}, [this, func = std::move(method.second)](oxen::quic::message m) {
_router.loop()->call([this, msg = std::move(m), func = std::move(func)]() mutable {
auto body = msg.body_str();
auto respond = [m = std::move(msg)](std::string response) mutable {
@ -178,24 +186,23 @@ namespace llarp
bool result = false;
RouterID other{key.data()};
// if (auto itr = rids_pending_verification.find(other); itr !=
// rids_pending_verification.end())
// {
// verified_rids[other] = itr->second;
// rids_pending_verification.erase(itr);
// result = true;
// }
if (_router.node_db()->has_rc(other))
result = true;
// TODO: discuss pubkey verification for bootstraps connecting to seed node
if (_router.is_bootstrap_seed())
{
log::warning(logcat, "Allowing connection -- we are bootstrap seed");
result = true;
if (node_db->whitelist().count(other))
{
auto [it, b] = node_db->seeds().emplace(other);
result &= b;
}
log::critical(
logcat,
"Bootstrap seed node was {} to confirm fetch requester is white-listed; saving RID",
result ? "able" : "unable");
return result;
}
if (node_db->has_rc(other))
result = true;
log::critical(
logcat, "{}uccessfully verified connection to {}!", result ? "S" : "Uns", other);
return result;
@ -383,8 +390,6 @@ namespace llarp
{
const auto& scid = ci.scid();
RouterID rid{ci.remote_key()};
const auto& rc = verified_rids[rid];
ep.connid_map.emplace(scid, rid);
auto [itr, b] = ep.conns.emplace(rid, nullptr);
@ -394,11 +399,10 @@ namespace llarp
logcat, "BTRequestStream closed unexpectedly (ec:{}); closing connection...", error_code);
s.conn.close_connection(error_code);
});
register_commands(control_stream);
log::critical(logcat, "Opened BTStream ID:{}", control_stream->stream_id());
itr->second = std::make_shared<link::Connection>(ci.shared_from_this(), control_stream, rc);
log::critical(logcat, "Successfully configured inbound connection fom {}; storing RC...", rid);
node_db->put_rc(rc);
itr->second = std::make_shared<link::Connection>(ci.shared_from_this(), control_stream);
log::critical(logcat, "Successfully configured inbound connection fom {}...", rid);
}
// TODO: should we add routes here now that Router::SessionOpen is gone?
@ -627,13 +631,11 @@ namespace llarp
const RemoteRC& source, std::string payload, std::function<void(oxen::quic::message m)> func)
{
_router.loop()->call([this, source, payload, f = std::move(func)]() mutable {
if (f)
{
f = [this, func = std::move(f)](oxen::quic::message m) mutable {
_router.loop()->call([f = std::move(func), msg = std::move(m)]() mutable {
f(std::move(msg));
});
_router.loop()->call(
[f = std::move(func), msg = std::move(m)]() mutable { f(std::move(msg)); });
};
}
@ -681,14 +683,23 @@ namespace llarp
}
auto is_seed = _router.is_bootstrap_seed();
auto& rid = remote.router_id();
// TODO: if we are not the seed, how do we check the requester
if (is_seed)
{
// we already insert the
auto& seeds = node_db->seeds();
if (auto itr = seeds.find(rid); itr != seeds.end())
{
log::critical(logcat, "Bootstrap seed confirmed RID:{} is white-listed seeds; approving fetch request and saving RC!", rid);
node_db->put_rc(remote);
}
}
auto& src = is_seed ? node_db->bootstrap_seeds() : node_db->get_known_rcs();
auto count = src.size();
if (is_seed)
node_db->bootstrap_seeds().insert(remote);
else
node_db->put_rc(remote);
if (count == 0)
{
@ -715,7 +726,6 @@ namespace llarp
}
}
m.respond(std::move(btdp).str());
}

View File

@ -404,8 +404,6 @@ namespace llarp
{
try
{
std::this_thread::sleep_for(5s);
oxen::log::flush();
log::critical(logcat, "Establishing connection to {}", remote);
auto conn_interface =
@ -427,7 +425,7 @@ namespace llarp
});
link_manager.register_commands(control_stream);
itr->second = std::make_shared<link::Connection>(conn_interface, control_stream, rc);
itr->second = std::make_shared<link::Connection>(conn_interface, control_stream);
return true;
}

View File

@ -254,8 +254,8 @@ namespace llarp
return false;
}
for (auto& rc : rcs)
put_rc_if_newer(std::move(rc), timestamp);
while (!rcs.empty())
put_rc_if_newer(std::move(rcs.extract(rcs.begin()).value()), timestamp);
return true;
}
@ -779,12 +779,16 @@ namespace llarp
router_greenlist.clear();
router_greenlist.insert(greenlist.begin(), greenlist.end());
log::info(logcat, "lokinet service node list now has {} active router RIDs", known_rids.size());
log::info(
logcat,
"lokinet service node whitelist now has {} active router RIDs",
router_whitelist.size());
}
std::optional<RouterID>
NodeDB::get_random_whitelist_router() const
{
// TODO: this should be checking whitelist not known_rcs
if (auto rc = get_random_rc())
return rc->router_id();

View File

@ -134,6 +134,7 @@ namespace llarp
std::map<RouterID, const RemoteRC&> rc_lookup;
std::set<RemoteRC> _bootstrap_seeds;
std::set<RouterID> _seeds;
BootstrapList _bootstraps{};
/** RouterID lists // TODO: get rid of all these, replace with better decom/not staked sets
@ -191,6 +192,12 @@ namespace llarp
/// in memory nodedb
NodeDB();
std::set<RouterID>&
seeds()
{
return _seeds;
}
const std::set<RouterID>&
get_known_rids() const
{

View File

@ -220,8 +220,7 @@ namespace llarp
{
std::optional<RemoteRC> found = std::nullopt;
router->for_each_connection([&](link::Connection& conn) {
const auto& rc = conn.remote_rc;
const auto& rid = rc.router_id();
RouterID rid{conn.conn->remote_key()};
#ifndef TESTNET
if (router->is_bootstrap_node(rid))
@ -236,7 +235,7 @@ namespace llarp
if (router->router_profiling().IsBadForPath(rid))
return;
found = rc;
found = router->node_db()->get_rc(rid);
});
return found;
}

View File

@ -219,7 +219,7 @@ namespace llarp
// explicit route pokes for first hops
router.for_each_connection(
[this](link::Connection conn) { add_route(conn.remote_rc.addr()); });
[this](link::Connection conn) { add_route(conn.conn->remote()); });
add_route(router.link_manager().local());
// add default route
@ -238,7 +238,7 @@ namespace llarp
{
// unpoke routes for first hops
router.for_each_connection(
[this](link::Connection conn) { delete_route(conn.remote_rc.addr()); });
[this](link::Connection conn) { delete_route(conn.conn->remote()); });
if (is_enabled() and is_up)
{
vpn::AbstractRouteManager& route = router.vpn_platform()->RouteManager();

View File

@ -219,7 +219,7 @@ namespace llarp
std::unordered_set<RouterID> peer_pubkeys;
for_each_connection([&peer_pubkeys](link::Connection& conn) {
peer_pubkeys.emplace(conn.remote_rc.router_id());
peer_pubkeys.emplace(conn.conn->remote_key());
});
loop()->call([this, &peer_pubkeys]() {
@ -652,7 +652,6 @@ namespace llarp
}
};
for (const auto& router : configRouters)
{
log::debug(logcat, "Loading bootstrap router list from {}", defaultBootstrapFile);
@ -695,8 +694,7 @@ namespace llarp
throw std::runtime_error("No bootstrap nodes available.");
}
log::critical(
logcat, "Loaded {} default fallback bootstrap routers!", node_bstrap.size());
log::critical(logcat, "Loaded {} default fallback bootstrap routers!", node_bstrap.size());
}
clear_bad_rcs();