From 1cbec988fc2118c90d7daf63d71b51d6d6c93c22 Mon Sep 17 00:00:00 2001 From: dr7ana Date: Tue, 19 Dec 2023 09:25:56 -0800 Subject: [PATCH] address parsing of deprecated opts --- llarp/config/config.cpp | 41 +++++++++++++---------------------------- llarp/router/router.cpp | 15 ++++++--------- llarp/router/router.hpp | 2 +- 3 files changed, 20 insertions(+), 38 deletions(-) diff --git a/llarp/config/config.cpp b/llarp/config/config.cpp index 4dbc60fc7..a26159eeb 100644 --- a/llarp/config/config.cpp +++ b/llarp/config/config.cpp @@ -933,39 +933,24 @@ namespace llarp auto parse_addr_for_link = [net_ptr](const std::string& arg) { std::optional maybe = std::nullopt; - std::string_view arg_v; + std::string_view arg_v{arg}, host; + uint16_t p{DEFAULT_LISTEN_PORT}; - // explicitly provided value - if (not arg.empty()) + if (auto pos = arg_v.find(':'); pos != arg_v.npos) { - arg_v = std::string_view{arg}; + host = arg_v.substr(0, pos); + + if (not llarp::parse_int(arg_v.substr(pos + 1), p)) + throw std::invalid_argument{"Failed to parse port in arg:{}"_format(arg)}; } - if (arg_v[0] == ':') - { - uint16_t res; - if (auto rv = llarp::parse_int(arg_v.substr(1), res); not rv) - res = DEFAULT_LISTEN_PORT; + if (host.empty()) + maybe = net_ptr->get_best_public_address(true, p); + else + maybe = oxen::quic::Address{std::string{host}, p}; - maybe = oxen::quic::Address{""s, res}; - } - else if (auto pos = arg_v.find(':'); pos != arg_v.npos) - { - auto h = arg_v.substr(0, pos); - uint16_t p; - if (auto rv = llarp::parse_int(arg_v.substr(pos + 1), p); not rv) - p = DEFAULT_LISTEN_PORT; - - maybe = oxen::quic::Address{std::string{h}, p}; - - if (maybe->is_loopback()) - throw std::invalid_argument{fmt::format("{} is a loopback address", arg)}; - } - if (not maybe) - // infer public address - maybe = net_ptr->get_best_public_address(true, DEFAULT_LISTEN_PORT); - else if (maybe && maybe->port() == 0) - maybe->set_port(DEFAULT_LISTEN_PORT); + if (maybe and maybe->is_loopback()) + throw std::invalid_argument{"{} is a loopback address"_format(arg)}; return maybe; }; diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index 5f8289f56..fc9d17ed6 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -764,6 +764,9 @@ namespace llarp out, num_client_connections(), router_contact.time_to_expiry(now)); + + if (num_router_connections() >= _node_db->num_rcs()) + log::critical(logcat, "SERVICE NODE IS FULLY MESHED"); } else { @@ -780,6 +783,8 @@ namespace llarp log::info(logcat, "Last reported stats time {}", now - _last_stats_report); _last_stats_report = now; + + oxen::log::flush(); } std::string @@ -880,15 +885,11 @@ namespace llarp // TESTNET: 1 to 5 minutes before testnet gossip interval auto delta = std::chrono::seconds{std::uniform_int_distribution{60, 300}(llarp::csrng)}; - // 1min to 5min before "stale time" is next gossip time - // auto random_delta = - // std::chrono::seconds{std::uniform_int_distribution{60, 300}(llarp::csrng)}; next_rc_gossip = now_timepoint + TESTNET_GOSSIP_INTERVAL - delta; - // next_rc_gossip = now_timepoint + RouterContact::STALE_AGE - random_delta; } - report_stats(); + // report_stats(); } if (needs_rebootstrap() and now_timepoint > next_bootstrap_attempt) @@ -1008,8 +1009,6 @@ namespace llarp FULL_MESH_ITERATION); _link_manager->connect_to_random(FULL_MESH_ITERATION); } - else - log::critical(logcat, "SERVICE NODE IS FULLY MESHED"); } else { @@ -1129,8 +1128,6 @@ 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 beeae1edf..045553551 100644 --- a/llarp/router/router.hpp +++ b/llarp/router/router.hpp @@ -59,7 +59,7 @@ namespace llarp // how big of a time skip before we reset network state inline constexpr std::chrono::milliseconds NETWORK_RESET_SKIP_INTERVAL{1min}; - inline constexpr std::chrono::milliseconds REPORT_STATS_INTERVAL{1h}; + inline constexpr std::chrono::milliseconds REPORT_STATS_INTERVAL{10s}; inline constexpr std::chrono::milliseconds DECOMM_WARNING_INTERVAL{5min};