pull/2232/head
dr7ana 5 months ago
parent 1e1f4dd40b
commit 90a530a114

@ -37,6 +37,9 @@ namespace llarp
const RemoteRC&
next()
{
if (size() < 2)
return *_curr;
++_curr;
if (_curr == this->end())

@ -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));

@ -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<Opt>(opts)...);

@ -55,7 +55,7 @@ namespace llarp::net
{
std::optional<sockaddr*> 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)

@ -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

@ -346,7 +346,7 @@ namespace llarp
}
void
set_bootstrap_routers(BootstrapList from_router);
set_bootstrap_routers(BootstrapList& from_router);
const std::set<RouterID>&
whitelist() const

@ -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<Contacts>(*this);

@ -105,7 +105,7 @@ namespace llarp
std::shared_ptr<NodeDB> _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;

@ -17,52 +17,43 @@ namespace llarp
if (int rc_ver = data.require<uint8_t>(""); 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<std::string_view>("4");
if (addr_key == "4")
{
auto ipv4_port = data.consume<std::string_view>();
if (ipv4_port.size() != 6)
throw std::runtime_error{
"Invalid RC address: expected 6-byte IPv4 IP/port, got {}"_format(ipv4_port.size())};
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;
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);
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};
_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<std::string_view>();
if (!_addr.is_public())
throw std::runtime_error{"Invalid RC: IPv4 address is not a publicly routable IP"};
if (ipv6_port.size() != 18)
if (auto ipv6_port = data.maybe<std::string_view>("6"))
{
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<std::string_view>("i").value_or(llarp::LOKINET_DEFAULT_NETID);

Loading…
Cancel
Save