diff --git a/llarp/link/link_manager.cpp b/llarp/link/link_manager.cpp index ac99d38c0..655cefa50 100644 --- a/llarp/link/link_manager.cpp +++ b/llarp/link/link_manager.cpp @@ -225,38 +225,24 @@ namespace llarp }, [this](oxen::quic::dgram_interface& di, bstring dgram) { recv_data_message(di, dgram); }); tls_creds->set_key_verify_callback([this](const ustring_view& key, const ustring_view&) { - bool result = true; RouterID other{key.data()}; - if (_router.is_bootstrap_seed()) - { - if (node_db->registered_routers().count(other)) - { - log::critical(logcat, "Saving bootstrap seed requester..."); - auto [it, b] = node_db->seeds().insert(other); - result &= b; - } - - log::critical( - logcat, - "Bootstrap seed node was {} to confirm remote is registered; {}successfully " - "saved RID", - result ? "able" : "unable", - result ? "" : "un"); - return result; - } - - result = node_db->has_rc(other); + bool result = node_db->registered_routers().count(other); log::critical( - logcat, "{}uccessfully verified connection to {}!", result ? "S" : "Uns", other); + logcat, + "{} node was {} to confirm remote (RID:{}) is registered; allowing connection!", + router().is_bootstrap_seed() ? "Bootstrap seed node" : "Service node", + other, + result ? "able" : "unable"); + return result; }); if (_router.is_service_node()) { ep->listen( tls_creds, - ROUTER_KEEP_ALIVE, + ROUTER_KEEP_ALIVE/* , [&](oxen::quic::Connection& c, oxen::quic::Endpoint& e, std::optional id) -> std::shared_ptr { @@ -278,7 +264,7 @@ namespace llarp log::critical(logcat, "Stream constructor constructing Stream (ID:{})!", id); return e.make_shared(c, e); - }); + } */); } return ep; } @@ -293,11 +279,11 @@ namespace llarp log::critical(logcat, "Queueing BTStream to be opened..."); - auto control_stream = ci.queue_stream([](oxen::quic::Stream& s, + auto control_stream = ci.queue_stream([this, rid = rid](oxen::quic::Stream&, uint64_t error_code) { log::warning( logcat, "BTRequestStream closed unexpectedly (ec:{}); closing connection...", error_code); - s.conn.close_connection(error_code); + ep.close_connection(rid); }); log::critical(logcat, "Queued BTStream to be opened ID:{}", control_stream->stream_id()); @@ -789,13 +775,13 @@ namespace llarp if (is_seed) { // we already insert the - auto& seeds = node_db->seeds(); + auto& registered = node_db->registered_routers(); - if (auto itr = seeds.find(rid); itr != seeds.end()) + if (auto itr = registered.find(rid); itr != registered.end()) { log::critical( logcat, - "Bootstrap seed confirmed RID:{} is white-listed seeds; approving fetch request and " + "Bootstrap seed confirmed RID:{} is registered; approving fetch request and " "saving RC!", rid); node_db->put_rc(remote); @@ -805,12 +791,9 @@ namespace llarp auto& src = node_db->get_known_rcs(); auto count = src.size(); - if (count == 0) - { - log::error(logcat, "No known RCs locally to send!"); - m.respond(messages::ERROR_RESPONSE, true); - return; - } + // if quantity is 0, then the service node requesting this wants all the RC's; otherwise, + // send the amount requested in the message + quantity = quantity == 0 ? count : quantity; auto now = llarp::time_now_ms(); size_t i = 0; @@ -820,13 +803,18 @@ namespace llarp { auto sublist = btdp.append_list("rcs"); - for (const auto& rc : src) + if (count == 0) + log::error(logcat, "No known RCs locally to send!"); + else { - if (not rc.is_expired(now)) - sublist.append_encoded(rc.view()); + for (const auto& rc : src) + { + if (not rc.is_expired(now)) + sublist.append_encoded(rc.view()); - if (++i >= quantity) - break; + if (++i >= quantity) + break; + } } } @@ -837,6 +825,9 @@ namespace llarp LinkManager::fetch_rcs( const RouterID& source, std::string payload, std::function func) { + // this handler should not be registered for service nodes + assert(not _router.is_service_node()); + send_control_message(source, "fetch_rcs", std::move(payload), std::move(func)); } diff --git a/llarp/link/link_manager.hpp b/llarp/link/link_manager.hpp index 88adc56e6..54d06eb1e 100644 --- a/llarp/link/link_manager.hpp +++ b/llarp/link/link_manager.hpp @@ -424,12 +424,12 @@ namespace llarp auto [itr, b] = pending_conns.emplace(rid, nullptr); auto control_stream = conn_interface->template get_new_stream( - [](oxen::quic::Stream& s, uint64_t error_code) { + [this, rid = rid](oxen::quic::Stream&, uint64_t error_code) { log::warning( logcat, "BTRequestStream closed unexpectedly (ec:{}); closing connection...", error_code); - s.conn.close_connection(error_code); + close_connection(rid); }); link_manager.register_commands(control_stream, rid); diff --git a/llarp/nodedb.cpp b/llarp/nodedb.cpp index 6244d104a..4a7eb7fee 100644 --- a/llarp/nodedb.cpp +++ b/llarp/nodedb.cpp @@ -678,7 +678,7 @@ namespace llarp _router.link_manager().fetch_bootstrap_rcs( rc, - BootstrapFetchMessage::serialize(_router.router_contact, BOOTSTRAP_SOURCE_COUNT), + BootstrapFetchMessage::serialize(_router.router_contact, CLIENT_BOOTSTRAP_SOURCE_COUNT), [this, is_snode = _router.is_service_node()](oxen::quic::message m) mutable { log::critical(logcat, "Received response to BootstrapRC fetch request..."); @@ -740,7 +740,7 @@ namespace llarp "BootstrapRC fetch response from {} returned {}/{} needed RCs", fetch_source, num, - BOOTSTRAP_SOURCE_COUNT); + CLIENT_BOOTSTRAP_SOURCE_COUNT); if (not is_snode) { diff --git a/llarp/nodedb.hpp b/llarp/nodedb.hpp index 5f4588edf..3f6b73e31 100644 --- a/llarp/nodedb.hpp +++ b/llarp/nodedb.hpp @@ -45,9 +45,12 @@ namespace llarp inline constexpr size_t MIN_GOOD_RID_FETCH_TOTAL{}; // the ratio of accepted:rejected rids must be above this ratio inline constexpr double GOOD_RID_FETCH_THRESHOLD{}; + /* Bootstrap Constants */ - // the number of rc's we query the bootstrap for - inline constexpr size_t BOOTSTRAP_SOURCE_COUNT{10}; + // the number of rc's we query the bootstrap for; service nodes pass 0, which means + // gimme all dat RCs + inline constexpr size_t SERVICE_NODE_BOOTSTRAP_SOURCE_COUNT{0}; + inline constexpr size_t CLIENT_BOOTSTRAP_SOURCE_COUNT{10}; // the maximum number of fetch requests we make across all bootstraps inline constexpr int MAX_BOOTSTRAP_FETCH_ATTEMPTS{5}; // if all bootstraps fail, router will trigger re-bootstrapping after this cooldown @@ -136,8 +139,6 @@ namespace llarp std::map rc_lookup; - std::set _bootstrap_seeds; - std::set _seeds; BootstrapList _bootstraps{}; /** RouterID lists // TODO: get rid of all these, replace with better decom/not staked sets @@ -195,12 +196,6 @@ namespace llarp /// in memory nodedb NodeDB(); - std::set& - seeds() - { - return _seeds; - } - const std::set& get_known_rids() const { @@ -345,18 +340,6 @@ namespace llarp return _bootstraps; } - const std::set& - bootstrap_seeds() const - { - return _bootstrap_seeds; - } - - std::set& - bootstrap_seeds() - { - return _bootstrap_seeds; - } - void set_bootstrap_routers(BootstrapList& from_router);