From 6cb2f57abd6b867c3c972631c5cebaa8c1a8ccaa Mon Sep 17 00:00:00 2001 From: dr7ana Date: Tue, 12 Dec 2023 09:01:02 -0800 Subject: [PATCH] whatever --- llarp/bootstrap.hpp | 3 ++ llarp/link/link_manager.cpp | 7 +++-- llarp/link/link_manager.hpp | 4 +++ llarp/net/posix.cpp | 2 +- llarp/nodedb.cpp | 19 +++++++------ llarp/nodedb.hpp | 2 +- llarp/router/router.cpp | 39 +++++++++++++++----------- llarp/router/router.hpp | 2 +- llarp/router_contact.cpp | 55 ++++++++++++++++--------------------- 9 files changed, 70 insertions(+), 63 deletions(-) diff --git a/llarp/bootstrap.hpp b/llarp/bootstrap.hpp index b2cad4205..7d037ff55 100644 --- a/llarp/bootstrap.hpp +++ b/llarp/bootstrap.hpp @@ -37,6 +37,9 @@ namespace llarp const RemoteRC& next() { + if (size() < 2) + return *_curr; + ++_curr; if (_curr == this->end()) diff --git a/llarp/link/link_manager.cpp b/llarp/link/link_manager.cpp index 71137e381..a49a310b6 100644 --- a/llarp/link/link_manager.cpp +++ b/llarp/link/link_manager.cpp @@ -352,6 +352,7 @@ namespace llarp { if (auto conn = ep.get_conn(rc.router_id()); conn) { + log::error(logcat, "We should not be here!"); // TODO: should implement some connection failed logic, but not the same logic that // would be executed for another failure case return; @@ -628,13 +629,13 @@ namespace llarp _router.loop()->call([this, source, payload, f = std::move(func)]() { if (auto conn = ep.get_conn(source); conn) { - log::critical(logcat, "Dispatched bootstrap fetch request!"); conn->control_stream->command("bfetch_rcs"s, std::move(payload), std::move(f)); + log::critical(logcat, "Dispatched bootstrap fetch request!"); return; } - log::critical(logcat, "Queuing bootstrap fetch request"); - auto pending = PendingControlMessage(std::move(payload), "bfetch_rcs"s, f); + log::critical(logcat, "Queuing bootstrap fetch request to {}", source.router_id()); + auto pending = PendingControlMessage(std::move(payload), "bfetch_rcs"s, std::move(f)); auto [itr, b] = pending_conn_msg_queue.emplace(source.router_id(), MessageQueue()); itr->second.push_back(std::move(pending)); diff --git a/llarp/link/link_manager.hpp b/llarp/link/link_manager.hpp index e8b9c9431..64ef45b11 100644 --- a/llarp/link/link_manager.hpp +++ b/llarp/link/link_manager.hpp @@ -404,6 +404,10 @@ namespace llarp { try { + std::this_thread::sleep_for(5s); + oxen::log::flush(); + log::critical(logcat, "Establishing connection to {}", remote); + auto conn_interface = endpoint->connect(remote, link_manager.tls_creds, std::forward(opts)...); diff --git a/llarp/net/posix.cpp b/llarp/net/posix.cpp index d48fbb39e..3715e1571 100644 --- a/llarp/net/posix.cpp +++ b/llarp/net/posix.cpp @@ -55,7 +55,7 @@ namespace llarp::net { std::optional found; - iter_all([this, &found, af](auto i) { + iter_all([this, &found, af](ifaddrs* i) { if (found) return; if (i and i->ifa_addr and i->ifa_addr->sa_family == af) diff --git a/llarp/nodedb.cpp b/llarp/nodedb.cpp index 674af63d3..c2eb9f559 100644 --- a/llarp/nodedb.cpp +++ b/llarp/nodedb.cpp @@ -192,7 +192,7 @@ namespace llarp } void - NodeDB::set_bootstrap_routers(BootstrapList from_router) + NodeDB::set_bootstrap_routers(BootstrapList& from_router) { _bootstraps.merge(from_router); _bootstraps.randomize(); @@ -339,9 +339,9 @@ namespace llarp void NodeDB::fetch_initial() { - if (known_rcs.empty()) + if (known_rids.empty()) { - log::critical(logcat, "No RC's held locally... BOOTSTRAP TIME"); + log::critical(logcat, "No RouterID's held locally... BOOTSTRAP TIME"); fallback_to_bootstrap(); } else @@ -658,20 +658,21 @@ namespace llarp bootstrap_cooldown(); return; } - - auto rc = (_using_bootstrap_fallback) ? _bootstraps.next() : _bootstraps.current(); - fetch_source = rc.router_id(); } + auto& rc = (_using_bootstrap_fallback) ? _bootstraps.next() : _bootstraps.current(); + fetch_source = rc.router_id(); + // By passing the last conditional, we ensure this is set to true _using_bootstrap_fallback = true; _needs_rebootstrap = false; ++bootstrap_attempts; - log::critical(logcat, "Dispatching BootstrapRC fetch request to {}", _bootstraps.current().view()); + log::critical( + logcat, "Dispatching BootstrapRC fetch request to {}", _bootstraps.current().view()); _router.link_manager().fetch_bootstrap_rcs( - _bootstraps.current(), + rc, BootstrapFetchMessage::serialize(_router.router_contact, BOOTSTRAP_SOURCE_COUNT), [this](oxen::quic::message m) mutable { if (not m) @@ -823,7 +824,7 @@ namespace llarp put_rc(rc); } - log::critical(logcat, "NodeDB populated with {} routers", num_rcs()); + log::critical(logcat, "NodeDB stored {} bootstrap routers", _bootstraps.size()); } void diff --git a/llarp/nodedb.hpp b/llarp/nodedb.hpp index db1b98ef5..6644c4b05 100644 --- a/llarp/nodedb.hpp +++ b/llarp/nodedb.hpp @@ -346,7 +346,7 @@ namespace llarp } void - set_bootstrap_routers(BootstrapList from_router); + set_bootstrap_routers(BootstrapList& from_router); const std::set& whitelist() const diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index 426e8397a..c1ea59519 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -631,13 +631,14 @@ namespace llarp configRouters.push_back(defaultBootstrapFile); } - BootstrapList _bootstrap_rc_list; + // BootstrapList _bootstrap_rc_list; + auto& node_bstrap = _node_db->bootstrap_list(); auto clear_bad_rcs = [&]() mutable { log::critical(logcat, "Clearing bad RCs..."); // in case someone has an old bootstrap file and is trying to use a bootstrap // that no longer exists - for (auto it = _bootstrap_rc_list.begin(); it != _bootstrap_rc_list.end();) + for (auto it = node_bstrap.begin(); it != node_bstrap.end();) { if (it->is_obsolete_bootstrap()) log::critical(logcat, "ignoring obsolete bootstrap RC: {}", it->router_id()); @@ -650,19 +651,22 @@ namespace llarp } // we are in one of the above error cases that we warned about: - it = _bootstrap_rc_list.erase(it); + it = node_bstrap.erase(it); } }; + for (const auto& router : configRouters) { log::debug(logcat, "Loading bootstrap router list from {}", defaultBootstrapFile); - _bootstrap_rc_list.read_from_file(router); + node_bstrap.read_from_file(router); + // _bootstrap_rc_list.read_from_file(router); } for (const auto& rc : conf.bootstrap.routers) { - _bootstrap_rc_list.emplace(rc); + // _bootstrap_rc_list.emplace(rc); + node_bstrap.emplace(rc); } _bootstrap_seed = conf.bootstrap.seednode; @@ -670,7 +674,7 @@ namespace llarp if (_bootstrap_seed) log::critical(logcat, "We are a bootstrap seed node!"); - if (_bootstrap_rc_list.empty() and not _bootstrap_seed) + if (node_bstrap.empty() and not _bootstrap_seed) { log::warning(logcat, "Warning: bootstrap list is empty and we are not a seed node"); @@ -678,10 +682,11 @@ namespace llarp if (auto itr = fallbacks.find(RouterContact::ACTIVE_NETID); itr != fallbacks.end()) { - _bootstrap_rc_list.merge(itr->second); + // _bootstrap_rc_list.merge(itr->second); + node_bstrap.merge(itr->second); } - if (_bootstrap_rc_list.empty()) + if (node_bstrap.empty()) { // empty after trying fallback, if set log::error( @@ -694,19 +699,19 @@ namespace llarp } log::critical( - logcat, "Loaded {} default fallback bootstrap routers!", _bootstrap_rc_list.size()); + logcat, "Loaded {} default fallback bootstrap routers!", node_bstrap.size()); } clear_bad_rcs(); - log::critical(logcat, "We have {} bootstrap routers!", _bootstrap_rc_list.size()); + log::critical(logcat, "We have {} bootstrap routers!", node_bstrap.size()); - node_db()->set_bootstrap_routers(std::move(_bootstrap_rc_list)); + // node_db()->set_bootstrap_routers(_bootstrap_rc_list); // TODO: RC refactor here - if (_is_service_node) - init_inbounds(); - else - init_outbounds(); + // if (_is_service_node) + // init_inbounds(); + // else + // init_outbounds(); // profiling _profile_file = conf.router.data_dir / "profiles.dat"; @@ -1117,7 +1122,7 @@ namespace llarp } log::info(logcat, "Router initialized as service node!"); - const RouterID us = pubkey(); + // relays do not use profiling router_profiling().Disable(); } @@ -1141,6 +1146,8 @@ namespace llarp _node_db->load_from_disk(); _node_db->store_bootstraps(); + oxen::log::flush(); + log::info(logcat, "Creating Introset Contacts..."); _contacts = std::make_unique(*this); diff --git a/llarp/router/router.hpp b/llarp/router/router.hpp index 86eb5de13..87affae61 100644 --- a/llarp/router/router.hpp +++ b/llarp/router/router.hpp @@ -105,7 +105,7 @@ namespace llarp std::shared_ptr _node_db; llarp_time_t _started_at; const oxenmq::TaggedThreadID _disk_thread; - oxen::quic::Network _net; + // oxen::quic::Network _net; // DISCUSS: we don't use this anywhere..? llarp_time_t _last_stats_report = 0s; llarp_time_t _next_decomm_warning = time_now_ms() + 15s; diff --git a/llarp/router_contact.cpp b/llarp/router_contact.cpp index b660c7990..d75c5625e 100644 --- a/llarp/router_contact.cpp +++ b/llarp/router_contact.cpp @@ -17,52 +17,43 @@ namespace llarp if (int rc_ver = data.require(""); rc_ver != RC_VERSION) throw std::runtime_error{"Invalid RC: do not know how to parse v{} RCs"_format(rc_ver)}; - auto addr_key = data.key(); - bool addr_set = false; + auto ipv4_port = data.require("4"); - if (addr_key == "4") + if (ipv4_port.size() != 6) + throw std::runtime_error{ + "Invalid RC address: expected 6-byte IPv4 IP/port, got {}"_format(ipv4_port.size())}; + + sockaddr_in s4; + s4.sin_family = AF_INET; + + std::memcpy(&s4.sin_addr.s_addr, ipv4_port.data(), 4); + std::memcpy(&s4.sin_port, ipv4_port.data() + 4, 2); + + _addr = oxen::quic::Address{&s4}; + + if (!_addr.is_public()) + throw std::runtime_error{"Invalid RC: IPv4 address is not a publicly routable IP"}; + + if (auto ipv6_port = data.maybe("6")) { - auto ipv4_port = data.consume(); - - if (ipv4_port.size() != 6) + if (ipv6_port->size() != 18) throw std::runtime_error{ - "Invalid RC address: expected 6-byte IPv4 IP/port, got {}"_format(ipv4_port.size())}; - - sockaddr_in s4; - s4.sin_family = AF_INET; - - std::memcpy(&s4.sin_addr.s_addr, ipv4_port.data(), 4); - std::memcpy(&s4.sin_port, ipv4_port.data() + 4, 2); - - _addr = oxen::quic::Address{&s4}; - // advance in case ipv4 and ipv6 are included - addr_key = data.key(); - addr_set = true; - } - if (addr_key == "6") - { - auto ipv6_port = data.consume(); - - if (ipv6_port.size() != 18) - throw std::runtime_error{ - "Invalid RC address: expected 18-byte IPv6 IP/port, got {}"_format(ipv6_port.size())}; + "Invalid RC address: expected 18-byte IPv6 IP/port, got {}"_format(ipv6_port->size())}; sockaddr_in6 s6{}; s6.sin6_family = AF_INET6; - std::memcpy(&s6.sin6_addr.s6_addr, ipv6_port.data(), 16); - std::memcpy(&s6.sin6_port, ipv6_port.data() + 16, 2); + std::memcpy(&s6.sin6_addr.s6_addr, ipv6_port->data(), 16); + std::memcpy(&s6.sin6_port, ipv6_port->data() + 16, 2); _addr6.emplace(&s6); - if (!_addr6->is_public()) throw std::runtime_error{"Invalid RC: IPv6 address is not a publicly routable IP"}; } else + { _addr6.reset(); - - if (not addr_set) - throw std::runtime_error{"Invalid RC: could not discern ipv4 vs ipv6 in payload"}; + } auto netid = data.maybe("i").value_or(llarp::LOKINET_DEFAULT_NETID);