From 97410d5f131d2de60ff4fb29ce2575378eb577a3 Mon Sep 17 00:00:00 2001 From: dr7ana Date: Thu, 14 Nov 2024 11:12:45 -0800 Subject: [PATCH] who actually even knows (squash) - do not use hops with the same /24 masked ip-address - RPC find_cc endpoint --- llarp/CMakeLists.txt | 2 +- llarp/config/config.cpp | 3 +- llarp/constants/path.hpp | 2 +- llarp/contact/keys.hpp | 1 - llarp/contact/relay_contact.cpp | 16 ++---- llarp/contact/relay_contact.hpp | 2 + llarp/handlers/session.cpp | 14 +++++ llarp/handlers/tun.hpp | 1 - llarp/link/link_manager.hpp | 1 - llarp/nodedb.cpp | 14 ++--- llarp/nodedb.hpp | 13 ++--- llarp/path/path.cpp | 81 +-------------------------- llarp/path/path.hpp | 2 - llarp/path/path_handler.cpp | 81 +++++++++++++++++---------- llarp/path/transit_hop.hpp | 1 - llarp/router/router.cpp | 18 +++--- llarp/router/router.hpp | 2 +- llarp/rpc/rpc_request.hpp | 2 +- llarp/rpc/rpc_request_definitions.hpp | 19 +++++++ llarp/rpc/rpc_request_parser.cpp | 5 ++ llarp/rpc/rpc_request_parser.hpp | 1 + llarp/rpc/rpc_server.cpp | 78 +++++++++++++++++++------- llarp/rpc/rpc_server.hpp | 3 +- llarp/util/priority_queue.hpp | 11 ---- llarp/util/thread/queue.hpp | 2 +- 25 files changed, 186 insertions(+), 189 deletions(-) delete mode 100644 llarp/util/priority_queue.hpp diff --git a/llarp/CMakeLists.txt b/llarp/CMakeLists.txt index 6be549e3b3..addad643cf 100644 --- a/llarp/CMakeLists.txt +++ b/llarp/CMakeLists.txt @@ -223,7 +223,7 @@ target_link_libraries(lokinet-wire PUBLIC lokinet-addressing) target_link_libraries(lokinet-dns PUBLIC lokinet-utils lokinet-cryptography lokinet-config) target_link_libraries(lokinet-nodedb PUBLIC lokinet-addressing lokinet-cryptography) target_link_libraries(lokinet-platform PUBLIC lokinet-cryptography) -target_link_libraries(lokinet-rpc PUBLIC lokinet-wire) +target_link_libraries(lokinet-rpc PUBLIC lokinet-wire lokinet-contact) target_link_libraries(lokinet-addressing PUBLIC lokinet-utils lokinet-cryptography lokinet-contact) target_link_libraries(lokinet-wire PUBLIC lokinet-cryptography) target_link_libraries(lokinet-config PUBLIC lokinet-cryptography) diff --git a/llarp/config/config.cpp b/llarp/config/config.cpp index 1ddce712d5..6345bef5c7 100644 --- a/llarp/config/config.cpp +++ b/llarp/config/config.cpp @@ -1544,7 +1544,8 @@ namespace llarp { (void)params; - constexpr Default DefaultUniqueCIDR{32}; + constexpr Default DefaultUniqueCIDR{24}; + conf.define_option( "paths", "unique-range-size", diff --git a/llarp/constants/path.hpp b/llarp/constants/path.hpp index 4b57dbd54e..7b2e1dbdcd 100644 --- a/llarp/constants/path.hpp +++ b/llarp/constants/path.hpp @@ -15,7 +15,7 @@ namespace llarp::path constexpr std::size_t PAD_SIZE = 128; /// default path lifetime in ms; // TESTNET: reduced value - constexpr std::chrono::milliseconds DEFAULT_LIFETIME{5min}; + constexpr std::chrono::milliseconds DEFAULT_LIFETIME{10min}; /// minimum intro lifetime we will advertise constexpr std::chrono::milliseconds MIN_INTRO_LIFETIME = DEFAULT_LIFETIME / 2; /// number of slices of path lifetime to spread intros out via diff --git a/llarp/contact/keys.hpp b/llarp/contact/keys.hpp index 36aa127dea..f0b7471a2a 100644 --- a/llarp/contact/keys.hpp +++ b/llarp/contact/keys.hpp @@ -7,7 +7,6 @@ /** TODO: - re-configure string_view and ustring_view methods after deprecating RouterID - */ namespace llarp diff --git a/llarp/contact/relay_contact.cpp b/llarp/contact/relay_contact.cpp index b6c01aa8a2..13a6b46438 100644 --- a/llarp/contact/relay_contact.cpp +++ b/llarp/contact/relay_contact.cpp @@ -122,17 +122,6 @@ namespace llarp {"identity", _router_id.to_string()}, {"address", _addr.to_string()}}; - // if (routerVersion) - // { - // obj["routerVersion"] = routerVersion->to_string(); - // } - // std::vector srv; - // for (const auto& record : srvRecords) - // { - // srv.emplace_back(record.ExtractStatus()); - // } - // obj["srvRecords"] = srv; - return obj; } @@ -144,6 +133,11 @@ namespace llarp return _addr.is_addressable(); } + bool RelayContact::has_ip_overlap(const RelayContact& other, uint8_t netmask) const + { + return (_addr.to_ipv4() / netmask).contains(other._addr.to_ipv4()); + } + bool RelayContact::is_outdated(std::chrono::milliseconds now) const { return now >= _timestamp.time_since_epoch() + OUTDATED_AGE; diff --git a/llarp/contact/relay_contact.hpp b/llarp/contact/relay_contact.hpp index 23dc5221fa..14f39b37bd 100644 --- a/llarp/contact/relay_contact.hpp +++ b/llarp/contact/relay_contact.hpp @@ -125,6 +125,8 @@ namespace llarp bool is_public_addressable() const; + bool has_ip_overlap(const RelayContact& other, uint8_t netmask) const; + /// does this RC expire soon? default delta is 1 minute bool expires_within_delta(std::chrono::milliseconds now, std::chrono::milliseconds dlt = 1min) const; diff --git a/llarp/handlers/session.cpp b/llarp/handlers/session.cpp index c5451bbf69..7fc08e0afc 100644 --- a/llarp/handlers/session.cpp +++ b/llarp/handlers/session.cpp @@ -22,6 +22,8 @@ namespace llarp::handlers return _router.loop(); } + // static std::atomic testnet_trigger = false; + void SessionEndpoint::tick(std::chrono::milliseconds now) { log::trace(logcat, "{} called", __PRETTY_FUNCTION__); @@ -30,6 +32,18 @@ namespace llarp::handlers _sessions.tick_outbounds(now); path::PathHandler::tick(now); + + // if (not testnet_trigger) + // { + // testnet_trigger = true; + // if (auto rclient = + // NetworkAddress::from_network_addr("4odrxxn5rekt99yb5jqksb3gncpb91s1ue56kpx58p3doen5cxey.loki"sv)) + // { + // initiate_remote_exit_session(*rclient, [](ip_v) { log::critical(logcat, "FUCK YEAH"); }); + // } + // else + // log::critical(logcat, "Failed to parse client netaddr!"); + // } } bool SessionEndpoint::stop(bool send_close) diff --git a/llarp/handlers/tun.hpp b/llarp/handlers/tun.hpp index 94d1bd58c2..36e24d2dc1 100644 --- a/llarp/handlers/tun.hpp +++ b/llarp/handlers/tun.hpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include diff --git a/llarp/link/link_manager.hpp b/llarp/link/link_manager.hpp index 5df56f8024..d407dc26d4 100644 --- a/llarp/link/link_manager.hpp +++ b/llarp/link/link_manager.hpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include diff --git a/llarp/nodedb.cpp b/llarp/nodedb.cpp index ce598ab74b..58bf824576 100644 --- a/llarp/nodedb.cpp +++ b/llarp/nodedb.cpp @@ -144,8 +144,6 @@ namespace llarp return false; } - // TODO: make this its own ticker - // purge_rcs(now); return true; } @@ -153,7 +151,7 @@ namespace llarp { remove_if([&](const RemoteRC& rc) -> bool { // don't purge bootstrap nodes from nodedb - if (is_bootstrap_node(rc.router_id())) + if (is_bootstrap_node(rc)) { log::trace(logcat, "Not removing {}: is bootstrap node", rc.router_id()); return false; @@ -189,6 +187,7 @@ namespace llarp log::debug(logcat, "Skipping check on {}: don't have whitelist yet", rc.router_id()); return false; } + // if we have no whitelist enabled or we have // the whitelist enabled and we got the whitelist // check against the whitelist and remove if it's not @@ -198,6 +197,7 @@ namespace llarp log::debug(logcat, "Removing {}: not a valid router", rc.router_id()); return true; } + return false; }); @@ -429,7 +429,7 @@ namespace llarp if (process_fetched_rcs(*result)) { - log::info(logcat, "Accumulated RID's accepted by trust model"); + log::info(logcat, "Accumulated RC's accepted by trust model"); return stop_rc_fetch(true); } @@ -565,9 +565,9 @@ namespace llarp reselect_router_id_sources(fail_sources); } - bool NodeDB::is_bootstrap_node(RouterID rid) const + bool NodeDB::is_bootstrap_node(const RemoteRC& rc) const { - return has_bootstraps() ? _bootstraps.contains(rid) : false; + return has_bootstraps() ? _bootstraps.contains(rc) : false; } void NodeDB::start_tickers() @@ -580,7 +580,7 @@ namespace llarp }); _purge_ticker = _router.loop()->call_every( - 5min, [this]() { purge_rcs(); }, not _needs_bootstrap); + PURGE_INTERVAL, [this]() mutable { purge_rcs(); }, not _needs_bootstrap); if (not _is_service_node) { diff --git a/llarp/nodedb.hpp b/llarp/nodedb.hpp index 4af8ceac3e..fe0657d0b7 100644 --- a/llarp/nodedb.hpp +++ b/llarp/nodedb.hpp @@ -23,6 +23,8 @@ namespace llarp // TESTNET: the following constants have been shortened for testing purposes inline constexpr auto FETCH_INTERVAL{10min}; + inline constexpr auto PURGE_INTERVAL{5min}; + inline constexpr auto FLUSH_INTERVAL{15min}; /* RC Fetch Constants */ // fallback to bootstrap if we have less than this many RCs @@ -62,9 +64,6 @@ namespace llarp // threshold amount of verifications to promote an unconfirmed rc/rid inline constexpr int CONFIRMATION_THRESHOLD{3}; - inline constexpr auto PURGE_INTERVAL{1min}; - inline constexpr auto FLUSH_INTERVAL{15min}; - template < typename ID_t, std::enable_if_t || std::is_same_v, int> = 0> @@ -93,12 +92,9 @@ namespace llarp Router& _router; const fs::path _root; - // const std::function)> _disk_hook; bool _is_service_node{false}; - std::chrono::milliseconds _next_flush_time{}; - /******** RouterID/RelayContacts ********/ using Lock_t = util::NullLock; @@ -198,8 +194,7 @@ namespace llarp return std::make_shared(std::move(rootdir), r); } - explicit NodeDB(fs::path rootdir, Router* r) - : _router{*r}, _root{std::move(rootdir)}, _next_flush_time{time_now_ms() + FLUSH_INTERVAL} + explicit NodeDB(fs::path rootdir, Router* r) : _router{*r}, _root{std::move(rootdir)} { _ensure_skiplist(_root); rid_result_counters.clear(); @@ -242,7 +237,7 @@ namespace llarp bool is_bootstrapping() const { return _is_bootstrapping; } bool needs_bootstrap() const { return _needs_bootstrap; } bool bootstrap_completed() const { return not(_is_bootstrapping or _needs_bootstrap); } - bool is_bootstrap_node(RouterID rid) const; + bool is_bootstrap_node(const RemoteRC& rc) const; void purge_rcs(std::chrono::milliseconds now = llarp::time_now_ms()); // Bootstrap fallback fetching diff --git a/llarp/path/path.cpp b/llarp/path/path.cpp index 1bea574097..725b8d1e51 100644 --- a/llarp/path/path.cpp +++ b/llarp/path/path.cpp @@ -230,16 +230,6 @@ namespace llarp::path return nullptr; } - // std::shared_ptr Path::local_hop() - // { - // return _local_hop; - // } - - // const std::shared_ptr& Path::local_hop() const - // { - // return _local_hop; - // } - RouterID Path::upstream_rid() { return hops.front().router_id(); @@ -339,22 +329,6 @@ namespace llarp::path return obj; } - bool Path::SendLatencyMessage(Router*) - { - // const auto now = r->now(); - // // send path latency test - // routing::PathLatencyMessage latency{}; - // latency.sent_time = randint(); - // latency.sequence_number = NextSeqNo(); - // m_LastLatencyTestID = latency.sent_time; - // m_LastLatencyTestTime = now; - // LogDebug(name(), " send latency test id=", latency.sent_time); - // if (not SendRoutingMessage(latency, r)) - // return false; - // FlushUpstream(r); - return true; - } - bool Path::update_exit(uint64_t) { // TODO: do we still want this concept? @@ -372,60 +346,7 @@ namespace llarp::path if (_is_linked) { } - - // m_LastRXRate = m_RXRate; - // m_LastTXRate = m_TXRate; - - // m_RXRate = 0; - // m_TXRate = 0; - - // if (_status == PathStatus::BUILDING) - // { - // if (buildStarted == 0s) - // return; - // if (now >= buildStarted) - // { - // const auto dlt = now - buildStarted; - // if (dlt >= path::BUILD_TIMEOUT) - // { - // LogWarn(name(), " waited for ", to_string(dlt), " and no path was built"); - // r->router_profiling().MarkPathFail(this); - // EnterState(PathStatus::EXPIRED, now); - // return; - // } - // } - // } - // check to see if this path is dead - // if (_status == PathStatus::ESTABLISHED) - // { - // auto dlt = now - last_latency_test; - // if (dlt > path::LATENCY_INTERVAL && last_latency_test_id == 0) - // { - // SendLatencyMessage(r); - // // latency test FEC - // r->loop()->call_later(2s, [self = shared_from_this(), r]() { - // if (self->last_latency_test_id) - // self->SendLatencyMessage(r); - // }); - // return; - // } - // dlt = now - last_recv_msg; - // if (dlt >= path::ALIVE_TIMEOUT) - // { - // LogWarn(name(), " waited for ", to_string(dlt), " and path looks dead"); - // r->router_profiling().MarkPathFail(this); - // EnterState(PathStatus::TIMEOUT, now); - // } - // } - // if (_status == PathStatus::IGNORE and now - last_recv_msg >= path::ALIVE_TIMEOUT) - // { - // // clean up this path as we dont use it anymore - // EnterState(PathStatus::EXPIRED, now); - // } - } - - /// how long we wait for a path to become active again after it times out - // constexpr auto PathReanimationTimeout = 45s; + } void Path::set_established() { diff --git a/llarp/path/path.hpp b/llarp/path/path.hpp index 83d4dc6123..b11570c49e 100644 --- a/llarp/path/path.hpp +++ b/llarp/path/path.hpp @@ -164,8 +164,6 @@ namespace llarp void populate_internals(const std::vector& _hops); - bool SendLatencyMessage(Router* r); - /// call obtained exit hooks bool InformExitResult(std::chrono::milliseconds b); diff --git a/llarp/path/path_handler.cpp b/llarp/path/path_handler.cpp index 6a41d82072..b32d5ee4da 100644 --- a/llarp/path/path_handler.cpp +++ b/llarp/path/path_handler.cpp @@ -413,64 +413,87 @@ namespace llarp::path { log::trace(logcat, "{} called", __PRETTY_FUNCTION__); - const auto& path_config = _router.config()->paths; + assert(num_hops); - // make a copy here to reference rather than creating one in the lambda every iteration - std::set to_exclude{exclude.begin(), exclude.end()}; - to_exclude.insert(pivot); + auto hops_needed = num_hops; - std::vector hops; + std::vector hops{}; + RemoteRC pivot_rc{}; - if (auto maybe = select_first_hop(exclude)) - hops.push_back(*maybe); - else + if (auto maybe = _router.node_db()->get_rc(pivot)) { - log::warning(logcat, "No first hop candidate for aligned hops!"); - return std::nullopt; + // if we only need one hop, return + if (hops_needed == 1) + { + hops.emplace_back(std::move(*maybe)); + return hops; + } + + // leave space to add the pivot last + --hops_needed; + pivot_rc = *maybe; } + else + return std::nullopt; - to_exclude.insert(hops.back().router_id()); + auto netmask = _router.config()->paths.unique_hop_netmask; - RemoteRC pivot_rc; + // make a copy here to reference rather than creating one in the lambda every iteration + std::set to_exclude{exclude.begin(), exclude.end()}; + to_exclude.insert(pivot); - if (auto maybe = _router.node_db()->get_rc(pivot)) + if (auto maybe = select_first_hop(to_exclude)) { - pivot_rc = *maybe; + hops.push_back(*maybe); + --hops_needed; } else + { + log::warning(logcat, "No first hop candidate for aligned hops!"); return std::nullopt; + } - // leave one extra spot for the terminal node - auto hops_needed = num_hops - hops.size() - 1; + to_exclude.insert(hops.back().router_id()); - auto filter = [&r = _router, &to_exclude](const RemoteRC& rc) -> bool { + auto filter = [&](const RemoteRC& rc) -> bool { const auto& rid = rc.router_id(); // if its already excluded, fail; (we want it added even on success) if (not to_exclude.insert(rid).second) return false; - if (r.router_profiling().is_bad_for_path(rid, 1)) + if (_router.router_profiling().is_bad_for_path(rid, 1)) return false; - return true; + if (pivot_rc.has_ip_overlap(rc, netmask)) + return false; + + return not std::any_of(hops.begin(), hops.end(), [&](const RemoteRC& other) -> bool { + return other.has_ip_overlap(rc, netmask); + }); }; - if (auto maybe_rcs = _router.node_db()->get_n_random_rcs_conditional(hops_needed, filter, true)) + while (hops_needed) { - auto& rcs = *maybe_rcs; - hops.insert(hops.end(), rcs.begin(), rcs.end()); - hops.emplace_back(pivot_rc); - -#ifndef TESTNET - if (not path_config.check_rcs({hops.begin(), hops.end()})) + // do this 1 at a time so we can check for IP range overlap + if (auto maybe_rc = _router.node_db()->get_random_rc_conditional(filter)) + { + hops.emplace_back(std::move(*maybe_rc)); + } + else + { + log::warning( + logcat, "Failed to find RC for aligned path! (needed:{}, found:{})", num_hops, hops_needed); return std::nullopt; -#endif + } - return hops; + --hops_needed; } - return std::nullopt; + // add pivot rc last + hops.emplace_back(std::move(pivot_rc)); + + return hops; } bool PathHandler::build_path_to_random() diff --git a/llarp/path/transit_hop.hpp b/llarp/path/transit_hop.hpp index eb5ba2cd44..66c4d00366 100644 --- a/llarp/path/transit_hop.hpp +++ b/llarp/path/transit_hop.hpp @@ -5,7 +5,6 @@ #include #include #include -#include namespace llarp { diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index 5e47e72cf9..51014d3d71 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -67,7 +67,6 @@ namespace llarp {"running", true}, {"numNodesKnown", _node_db->num_rcs()}, {"links", _link_manager->extract_status()}}; } - // TODO: investigate changes needed for libquic integration nlohmann::json Router::ExtractSummaryStatus() const { // if (!is_running) @@ -634,10 +633,11 @@ namespace llarp init_rpc(); + log::trace(logcat, "Starting OMQ server"); + _lmq->start(); + if (_is_service_node) { - log::trace(logcat, "Starting OMQ server"); - _lmq->start(); log::trace(logcat, "RPC client connecting to RPC bind address"); _rpc_client->connect_async(rpc_addr); } @@ -762,10 +762,10 @@ namespace llarp queue_disk_io([&]() { relay_contact.write(our_rc_file); }); } - bool Router::is_bootstrap_node(const RouterID r) const - { - return _node_db->is_bootstrap_node(r); - } + // bool Router::is_bootstrap_node(const RouterID r) const + // { + // return _node_db->is_bootstrap_node(r); + // } bool Router::should_report_stats(std::chrono::milliseconds now) const { @@ -794,7 +794,7 @@ namespace llarp } if (_last_stats_report > 0s) - log::info(logcat, "Last reported stats time {}", now - _last_stats_report); + log::trace(logcat, "Last reported stats time {}", now - _last_stats_report); _last_stats_report = now; @@ -919,9 +919,7 @@ namespace llarp } } else - { initial_client_connect_complete = true; - } if (initial_client_connect_complete) _session_endpoint->tick(now); diff --git a/llarp/router/router.hpp b/llarp/router/router.hpp index 5c2243f9f8..0cc5519ca9 100644 --- a/llarp/router/router.hpp +++ b/llarp/router/router.hpp @@ -351,7 +351,7 @@ namespace llarp std::string body, std::function func = nullptr); - bool is_bootstrap_node(RouterID rid) const; + // bool is_bootstrap_node(RouterID rid) const; std::chrono::milliseconds now() const { return llarp::time_now_ms(); } diff --git a/llarp/rpc/rpc_request.hpp b/llarp/rpc/rpc_request.hpp index 7da29c8453..d1b96a0e63 100644 --- a/llarp/rpc/rpc_request.hpp +++ b/llarp/rpc/rpc_request.hpp @@ -60,7 +60,7 @@ namespace llarp::rpc if (not std::is_base_of_v) { - server.m_Router.loop()->call_soon(std::move(handler)); + server._router.loop()->call_soon(std::move(handler)); } else { diff --git a/llarp/rpc/rpc_request_definitions.hpp b/llarp/rpc/rpc_request_definitions.hpp index 4908392ec2..53d2bbcd4e 100644 --- a/llarp/rpc/rpc_request_definitions.hpp +++ b/llarp/rpc/rpc_request_definitions.hpp @@ -291,6 +291,24 @@ namespace llarp::rpc } request; }; + // RPC: find_cc + // Lookup client contact via path request + // + // Inputs: + // "pk" : client pubkey + // + // Returns: + // "cc" : client contact + struct FindCC : RPCRequest + { + static constexpr auto name = "find_cc"sv; + + struct request_parameterss + { + std::string pk; + } request; + }; + // List of all RPC request structs to allow compile-time enumeration of all supported types using rpc_request_types = tools::type_list< Halt, @@ -300,6 +318,7 @@ namespace llarp::rpc QuicConnect, // debug QuicListener, // debug LookupSnode, + FindCC, MapExit, ListExits, SwapExits, diff --git a/llarp/rpc/rpc_request_parser.cpp b/llarp/rpc/rpc_request_parser.cpp index 7eafc4cd83..0d5b6e45df 100644 --- a/llarp/rpc/rpc_request_parser.cpp +++ b/llarp/rpc/rpc_request_parser.cpp @@ -38,6 +38,11 @@ namespace llarp::rpc quiclistener.request.srvProto); } + void parse_request(FindCC& findcc, rpc_input input) + { + get_values(input, "pk", findcc.request.pk); + } + void parse_request(LookupSnode& lookupsnode, rpc_input input) { get_values(input, "routerID", lookupsnode.request.routerID); diff --git a/llarp/rpc/rpc_request_parser.hpp b/llarp/rpc/rpc_request_parser.hpp index 3c10fe2739..bc0b6c7a81 100644 --- a/llarp/rpc/rpc_request_parser.hpp +++ b/llarp/rpc/rpc_request_parser.hpp @@ -17,6 +17,7 @@ namespace llarp::rpc void parse_request(QuicConnect& quicconnect, rpc_input input); void parse_request(QuicListener& quiclistener, rpc_input input); + void parse_request(FindCC& findcc, rpc_input input); void parse_request(LookupSnode& lookupsnode, rpc_input input); void parse_request(MapExit& mapexit, rpc_input input); void parse_request(UnmapExit& unmapexit, rpc_input input); diff --git a/llarp/rpc/rpc_server.cpp b/llarp/rpc/rpc_server.cpp index d84a199a91..19a4d047a8 100644 --- a/llarp/rpc/rpc_server.cpp +++ b/llarp/rpc/rpc_server.cpp @@ -5,9 +5,11 @@ #include #include #include +#include #include #include #include +#include #include @@ -71,7 +73,7 @@ namespace llarp::rpc } RPCServer::RPCServer(LMQ_ptr lmq, Router& r) - : m_LMQ{std::move(lmq)}, m_Router(r), log_subs{*m_LMQ, llarp::logRingBuffer} + : m_LMQ{std::move(lmq)}, _router(r), log_subs{*m_LMQ, llarp::logRingBuffer} { // copied logic loop as placeholder for (const auto& addr : r.config()->api.rpc_bind_addrs) @@ -113,31 +115,31 @@ namespace llarp::rpc void RPCServer::invoke(Halt& halt) { - if (not m_Router.is_running()) + if (not _router.is_running()) { SetJSONError("Router is not running", halt.response); return; } SetJSONResponse("OK", halt.response); - m_Router.stop(); + _router.stop(); } void RPCServer::invoke(Version& version) { - nlohmann::json result{{"version", llarp::LOKINET_VERSION_FULL}, {"uptime", to_json(m_Router.Uptime())}}; + nlohmann::json result{{"version", llarp::LOKINET_VERSION_FULL}, {"uptime", to_json(_router.Uptime())}}; SetJSONResponse(result, version.response); } void RPCServer::invoke(Status& status) { - (m_Router.is_running()) ? SetJSONResponse(m_Router.ExtractStatus(), status.response) - : SetJSONError("Router is not yet ready", status.response); + (_router.is_running()) ? SetJSONResponse(_router.ExtractStatus(), status.response) + : SetJSONError("Router is not yet ready", status.response); } void RPCServer::invoke(GetStatus& getstatus) { - SetJSONResponse(m_Router.ExtractSummaryStatus(), getstatus.response); + SetJSONResponse(_router.ExtractSummaryStatus(), getstatus.response); } void RPCServer::invoke(QuicConnect& quicconnect) @@ -157,7 +159,7 @@ namespace llarp::rpc } // auto endpoint = - // (req.endpoint.empty()) ? GetEndpointByName(m_Router, "default") : GetEndpointByName(m_Router, + // (req.endpoint.empty()) ? GetEndpointByName(_router, "default") : GetEndpointByName(_router, // req.endpoint); // if (not endpoint) @@ -213,7 +215,7 @@ namespace llarp::rpc } // auto endpoint = - // (req.endpoint.empty()) ? GetEndpointByName(m_Router, "default") : GetEndpointByName(m_Router, + // (req.endpoint.empty()) ? GetEndpointByName(_router, "default") : GetEndpointByName(_router, // req.endpoint); // if (not endpoint) @@ -270,10 +272,48 @@ namespace llarp::rpc } } + void RPCServer::invoke(FindCC& findcc) + { + if (_router.is_service_node()) + { + SetJSONError("Not supported", findcc.response); + return; + } + + RouterID pk; + + if (findcc.request.pk.empty()) + { + SetJSONError("No pubkey provided!", findcc.response); + return; + } + + if (not pk.from_string(oxenc::from_base32z(findcc.request.pk))) + { + SetJSONError("Invalid pubkey provided: " + findcc.request.pk, findcc.response); + return; + } + + _router.loop()->call([&]() { + _router.session_endpoint()->lookup_client_intro(pk, [&](std::optional cc) { + if (cc) + { + // log::info(logcat, "RPC call to `find_cc` returned successfully: {}", cc->to_string()); + // SetJSONResponse(cc->to_string(), findcc.response); + } + else + { + log::warning(logcat, "RPC call to `find_cc` failed!"); + SetJSONError("ERROR", findcc.response); + } + }); + }); + } + // TODO: fix this because it's bad void RPCServer::invoke(LookupSnode& lookupsnode) { - if (not m_Router.is_service_node()) + if (not _router.is_service_node()) { SetJSONError("Not supported", lookupsnode.response); return; @@ -292,8 +332,8 @@ namespace llarp::rpc return; } - // m_Router.loop()->call([&]() { - // auto endpoint = m_Router.exit_context().get_exit_endpoint("default"); + // _router.loop()->call([&]() { + // auto endpoint = _router.exit_context().get_exit_endpoint("default"); // if (endpoint == nullptr) // { @@ -323,7 +363,7 @@ namespace llarp::rpc exit_request.replier.emplace(mapexit.move()); // TODO: connect this to remote service session management (service::Handler) - // m_Router.hidden_service_context().GetDefault()->map_exit( + // _router.hidden_service_context().GetDefault()->map_exit( // mapexit.request.address, // mapexit.request.token, // mapexit.request.ip_range, @@ -338,13 +378,13 @@ namespace llarp::rpc void RPCServer::invoke(ListExits& listexits) { (void)listexits; - // if (not m_Router.hidden_service_context().hasEndpoints()) + // if (not _router.hidden_service_context().hasEndpoints()) // { // SetJSONError("No mapped endpoints found", listexits.response); // return; // } - // auto status = m_Router.hidden_service_context().GetDefault()->ExtractStatus()["exitMap"]; + // auto status = _router.hidden_service_context().GetDefault()->ExtractStatus()["exitMap"]; // SetJSONResponse((status.empty()) ? "No exits" : status, listexits.response); } @@ -354,7 +394,7 @@ namespace llarp::rpc try { // for (auto& ip : unmapexit.request.ip_range) - // m_Router.hidden_service_context().GetDefault()->UnmapExitRange(ip); + // _router.hidden_service_context().GetDefault()->UnmapExitRange(ip); } catch (std::exception& e) { @@ -375,7 +415,7 @@ namespace llarp::rpc (void)swapexits; // MapExit map_request; // UnmapExit unmap_request; - // auto endpoint = m_Router.hidden_service_context().GetDefault(); + // auto endpoint = _router.hidden_service_context().GetDefault(); // auto current_exits = endpoint->ExtractStatus()["exitMap"]; // if (current_exits.empty()) @@ -452,8 +492,8 @@ namespace llarp::rpc dns::Message msg{dns::Question{qname, qtype}}; - // auto endpoint = (dnsquery.request.endpoint.empty()) ? GetEndpointByName(m_Router, "default") - // : GetEndpointByName(m_Router, dnsquery.request.endpoint); + // auto endpoint = (dnsquery.request.endpoint.empty()) ? GetEndpointByName(_router, "default") + // : GetEndpointByName(_router, dnsquery.request.endpoint); // if (endpoint == nullptr) // { diff --git a/llarp/rpc/rpc_server.hpp b/llarp/rpc/rpc_server.hpp index 0a3da79657..76d28f44bb 100644 --- a/llarp/rpc/rpc_server.hpp +++ b/llarp/rpc/rpc_server.hpp @@ -92,6 +92,7 @@ namespace llarp::rpc void invoke(QuicConnect& quicconnect); void invoke(QuicListener& quiclistener); void invoke(LookupSnode& lookupsnode); + void invoke(FindCC& findcc); void invoke(MapExit& mapexit); void invoke(ListExits& listexits); void invoke(UnmapExit& unmapexit); @@ -100,7 +101,7 @@ namespace llarp::rpc void invoke(Config& config); LMQ_ptr m_LMQ; - Router& m_Router; + Router& _router; oxen::log::PubsubLogger log_subs; }; diff --git a/llarp/util/priority_queue.hpp b/llarp/util/priority_queue.hpp deleted file mode 100644 index cc87382a69..0000000000 --- a/llarp/util/priority_queue.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include -#include - -namespace llarp::util -{ - /// priority queue that uses operator > instead of operator < - template > - using ascending_priority_queue = std::priority_queue>; -} // namespace llarp::util diff --git a/llarp/util/thread/queue.hpp b/llarp/util/thread/queue.hpp index c627762b02..db2968e272 100644 --- a/llarp/util/thread/queue.hpp +++ b/llarp/util/thread/queue.hpp @@ -19,7 +19,7 @@ namespace llarp::thread { // This class provides a thread-safe, lock-free, fixed-size queue. public: - static constexpr size_t Alignment = 64; + static constexpr size_t Alignment{64}; private: Type* m_data;