address parsing of deprecated opts

This commit is contained in:
dr7ana 2023-12-19 09:25:56 -08:00
parent 9cc053608a
commit 1cbec988fc
3 changed files with 20 additions and 38 deletions

View File

@ -933,39 +933,24 @@ namespace llarp
auto parse_addr_for_link = [net_ptr](const std::string& arg) { auto parse_addr_for_link = [net_ptr](const std::string& arg) {
std::optional<oxen::quic::Address> maybe = std::nullopt; std::optional<oxen::quic::Address> 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 (auto pos = arg_v.find(':'); pos != arg_v.npos)
if (not arg.empty())
{ {
arg_v = std::string_view{arg}; host = arg_v.substr(0, pos);
if (not llarp::parse_int<uint16_t>(arg_v.substr(pos + 1), p))
throw std::invalid_argument{"Failed to parse port in arg:{}"_format(arg)};
} }
if (arg_v[0] == ':') if (host.empty())
{ maybe = net_ptr->get_best_public_address(true, p);
uint16_t res; else
if (auto rv = llarp::parse_int<uint16_t>(arg_v.substr(1), res); not rv) maybe = oxen::quic::Address{std::string{host}, p};
res = DEFAULT_LISTEN_PORT;
maybe = oxen::quic::Address{""s, res}; if (maybe and maybe->is_loopback())
} throw std::invalid_argument{"{} is a loopback address"_format(arg)};
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<uint16_t>(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);
return maybe; return maybe;
}; };

View File

@ -764,6 +764,9 @@ namespace llarp
out, out,
num_client_connections(), num_client_connections(),
router_contact.time_to_expiry(now)); router_contact.time_to_expiry(now));
if (num_router_connections() >= _node_db->num_rcs())
log::critical(logcat, "SERVICE NODE IS FULLY MESHED");
} }
else else
{ {
@ -780,6 +783,8 @@ namespace llarp
log::info(logcat, "Last reported stats time {}", now - _last_stats_report); log::info(logcat, "Last reported stats time {}", now - _last_stats_report);
_last_stats_report = now; _last_stats_report = now;
oxen::log::flush();
} }
std::string std::string
@ -880,15 +885,11 @@ namespace llarp
// TESTNET: 1 to 5 minutes before testnet gossip interval // TESTNET: 1 to 5 minutes before testnet gossip interval
auto delta = auto delta =
std::chrono::seconds{std::uniform_int_distribution<size_t>{60, 300}(llarp::csrng)}; std::chrono::seconds{std::uniform_int_distribution<size_t>{60, 300}(llarp::csrng)};
// 1min to 5min before "stale time" is next gossip time
// auto random_delta =
// std::chrono::seconds{std::uniform_int_distribution<size_t>{60, 300}(llarp::csrng)};
next_rc_gossip = now_timepoint + TESTNET_GOSSIP_INTERVAL - delta; 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) if (needs_rebootstrap() and now_timepoint > next_bootstrap_attempt)
@ -1008,8 +1009,6 @@ namespace llarp
FULL_MESH_ITERATION); FULL_MESH_ITERATION);
_link_manager->connect_to_random(FULL_MESH_ITERATION); _link_manager->connect_to_random(FULL_MESH_ITERATION);
} }
else
log::critical(logcat, "SERVICE NODE IS FULLY MESHED");
} }
else else
{ {
@ -1129,8 +1128,6 @@ namespace llarp
_node_db->load_from_disk(); _node_db->load_from_disk();
_node_db->store_bootstraps(); _node_db->store_bootstraps();
oxen::log::flush();
log::info(logcat, "Creating Introset Contacts..."); log::info(logcat, "Creating Introset Contacts...");
_contacts = std::make_unique<Contacts>(*this); _contacts = std::make_unique<Contacts>(*this);

View File

@ -59,7 +59,7 @@ namespace llarp
// how big of a time skip before we reset network state // 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 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}; inline constexpr std::chrono::milliseconds DECOMM_WARNING_INTERVAL{5min};