Compare commits

...

10 Commits

Author SHA1 Message Date
Jason Rhinelander 07eb288bd5
Remove release motto
This doesn't really have a purpose.
2023-12-07 22:50:31 -04:00
Jason Rhinelander 47a7c2698e
Update logging in daemon.cpp
Some of these were wrong (trying to use formats that didn't work); this
updates them all to new-style logging.
2023-12-07 22:50:31 -04:00
dr7ana 416ba97af5 sorry testnet (and jason) 2023-12-07 18:43:21 -08:00
dr7ana a3474127c9 D 2023-12-07 18:15:38 -08:00
dr7ana c8553736a5 i am dumb 2023-12-07 17:47:46 -08:00
dr7ana 5803393bff once more with feeling 2023-12-07 17:21:26 -08:00
Jason Rhinelander bc2cb46d9c
testnet: don't give oxend and error when testing is disabled 2023-12-07 20:53:09 -04:00
dr7ana 8af38d3d44 TELL ME WHEN IT WORKS 2023-12-07 16:48:40 -08:00
dr7ana d00257b9f0 address parsing
- straightened out setting of public addr and public port in config vs listen ("bind") addr
- fixed small bug in router contact writing and saving
2023-12-07 16:15:20 -08:00
dr7ana aaf284b39f libquic vbump
- now pointing to jason/void-listen
2023-12-07 16:15:17 -08:00
19 changed files with 251 additions and 184 deletions

View File

@ -41,8 +41,6 @@ if(APPLE)
set(LOKINET_APPLE_BUILD 5)
endif()
set(LOKINET_RELEASE_MOTTO "Anonymous, decentralized, IP-based overlay network" CACHE STRING "Release motto")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
set(DEFAULT_WITH_BOOTSTRAP ON)

View File

@ -125,7 +125,7 @@ namespace
if (!GetModuleFileName(nullptr, szPath.data(), MAX_PATH))
{
llarp::LogError("Cannot install service ", GetLastError());
llarp::log::error(logcat, "Cannot install service {}", GetLastError());
return;
}
@ -137,7 +137,7 @@ namespace
if (nullptr == schSCManager)
{
llarp::LogError("OpenSCManager failed ", GetLastError());
llarp::log::error(logcat, "OpenSCManager failed {}", GetLastError());
return;
}
@ -159,12 +159,12 @@ namespace
if (schService == nullptr)
{
llarp::LogError("CreateService failed ", GetLastError());
llarp::log::error(logcat, "CreateService failed {}", GetLastError());
CloseServiceHandle(schSCManager);
return;
}
else
llarp::LogInfo("Service installed successfully");
llarp::log::info(logcat, "Service installed successfully");
CloseServiceHandle(schService);
CloseServiceHandle(schSCManager);
@ -189,7 +189,7 @@ namespace
if (nullptr == schSCManager)
{
llarp::LogError("OpenSCManager failed ", GetLastError());
llarp::log::error(logcat, "OpenSCManager failed {}", GetLastError());
return;
}
@ -201,7 +201,7 @@ namespace
if (schService == nullptr)
{
llarp::LogError("OpenService failed ", GetLastError());
llarp::log::error(logcat, "OpenService failed {}", GetLastError());
CloseServiceHandle(schSCManager);
return;
}
@ -214,10 +214,10 @@ namespace
SERVICE_CONFIG_DESCRIPTION, // change: description
&sd)) // new description
{
llarp::LogError("ChangeServiceConfig2 failed");
llarp::log::error(logcat, "ChangeServiceConfig2 failed");
}
else
llarp::LogInfo("Service description updated successfully.");
llarp::log::info(log_cat, "Service description updated successfully.");
CloseServiceHandle(schService);
CloseServiceHandle(schSCManager);
@ -237,7 +237,7 @@ namespace
if (nullptr == schSCManager)
{
llarp::LogError("OpenSCManager failed ", GetLastError());
llarp::log::error(logcat, "OpenSCManager failed {}", GetLastError());
return;
}
@ -249,7 +249,7 @@ namespace
if (schService == nullptr)
{
llarp::LogError("OpenService failed ", GetLastError());
llarp::log::error(logcat, "OpenService failed {}", GetLastError());
CloseServiceHandle(schSCManager);
return;
}
@ -257,10 +257,10 @@ namespace
// Delete the service.
if (!DeleteService(schService))
{
llarp::LogError("DeleteService failed ", GetLastError());
llarp::log::error(logcat, "DeleteService failed {}", GetLastError());
}
else
llarp::LogInfo("Service deleted successfully\n");
llarp::log::info(logcat, "Service deleted successfully");
CloseServiceHandle(schService);
CloseServiceHandle(schSCManager);
@ -337,7 +337,7 @@ namespace
if (svc->handle == nullptr)
{
llarp::LogError("failed to register daemon control handler");
llarp::log::error(logcat, "failed to register daemon control handler");
return;
}
@ -454,7 +454,7 @@ namespace
}
catch (std::exception& ex)
{
llarp::LogError("cannot generate config at ", *configFile, ": ", ex.what());
llarp::log::error(logcat, "cannot generate config at {}: {}", *configFile, ex.what());
return 1;
}
}
@ -464,13 +464,13 @@ namespace
{
if (!fs::exists(*configFile))
{
llarp::LogError("Config file not found ", *configFile);
llarp::log::error(logcat, "Config file not found {}", *configFile);
return 1;
}
}
catch (std::exception& ex)
{
llarp::LogError("cannot check if ", *configFile, " exists: ", ex.what());
llarp::log::error(logcat, "cannot check if ", *configFile, " exists: ", ex.what());
return 1;
}
}
@ -487,7 +487,7 @@ namespace
}
catch (std::exception& ex)
{
llarp::LogError("cannot ensure config: ", ex.what());
llarp::log::error(logcat, "cannot ensure config: {}", ex.what());
return 1;
}
configFile = llarp::GetDefaultConfigPath();
@ -548,14 +548,13 @@ namespace
static void
run_main_context(std::optional<fs::path> confFile, const llarp::RuntimeOptions opts)
{
llarp::LogInfo(fmt::format(
"starting up {} {}", llarp::LOKINET_VERSION_FULL, llarp::LOKINET_RELEASE_MOTTO));
llarp::log::info(logcat, "starting up {}", llarp::LOKINET_VERSION_FULL);
try
{
std::shared_ptr<llarp::Config> conf;
if (confFile)
{
llarp::LogInfo("Using config file: ", *confFile);
llarp::log::info(logcat, "Using config file: {}", *confFile);
conf = std::make_shared<llarp::Config>(confFile->parent_path());
}
else
@ -564,7 +563,7 @@ namespace
}
if (not conf->load(confFile, opts.isSNode))
{
llarp::LogError("failed to parse configuration");
llarp::log::error(logcat, "failed to parse configuration");
exit_code.set_value(1);
return;
}
@ -589,13 +588,13 @@ namespace
}
catch (llarp::util::bind_socket_error& ex)
{
llarp::LogError(fmt::format("{}, is lokinet already running? 🤔", ex.what()));
llarp::log::error(logcat, "{}; is lokinet already running?", ex.what());
exit_code.set_value(1);
return;
}
catch (std::exception& ex)
catch (const std::exception& ex)
{
llarp::LogError(fmt::format("failed to start up lokinet: {}", ex.what()));
llarp::log::error(logcat, "failed to start up lokinet: {}", ex.what());
exit_code.set_value(1);
return;
}
@ -604,14 +603,14 @@ namespace
auto result = ctx->Run(opts);
exit_code.set_value(result);
}
catch (std::exception& e)
catch (const std::exception& e)
{
llarp::LogError("Fatal: caught exception while running: ", e.what());
llarp::log::error(logcat, "Fatal: caught exception while running: {}", e.what());
exit_code.set_exception(std::current_exception());
}
catch (...)
{
llarp::LogError("Fatal: caught non-standard exception while running");
llarp::log::error(logcat, "Fatal: caught non-standard exception while running");
exit_code.set_exception(std::current_exception());
}
}

@ -1 +1 @@
Subproject commit 3ced484e8cc543b90c5fc554ccc0ea2e54ec8d37
Subproject commit 92fa0e987e0513dfcd4efc683cb4dbff21de9622

View File

@ -85,5 +85,7 @@ namespace llarp
}
insert(rc);
}
_curr = begin();
}
} // namespace llarp

View File

@ -12,8 +12,13 @@ namespace llarp
{
struct BootstrapList final : public std::set<RemoteRC>
{
size_t index;
std::set<RemoteRC>::iterator current;
std::set<RemoteRC>::iterator _curr;
const RemoteRC&
current()
{
return *_curr;
}
bool
bt_decode(std::string_view buf);
@ -32,12 +37,12 @@ namespace llarp
const RemoteRC&
next()
{
++current;
++_curr;
if (current == this->end())
current = this->begin();
if (_curr == this->end())
_curr = this->begin();
return *current;
return *_curr;
}
bool
@ -46,7 +51,8 @@ namespace llarp
void
randomize()
{
current = std::next(begin(), std::uniform_int_distribution<size_t>{0, size() - 1}(csrng));
if (size() > 1)
_curr = std::next(begin(), std::uniform_int_distribution<size_t>{0, size() - 1}(csrng));
}
void

View File

@ -19,8 +19,6 @@
namespace llarp
{
constexpr int DEFAULT_PUBLIC_PORT = 1090;
using namespace config;
namespace
{
@ -134,19 +132,7 @@ namespace llarp
"this setting specifies the public IP at which this router is reachable. When",
"provided the public-port option must also be specified.",
},
[this, net = params.Net_ptr()](std::string arg) {
if (arg.empty())
return;
nuint32_t addr{};
if (not addr.FromString(arg))
throw std::invalid_argument{fmt::format("{} is not a valid IPv4 address", arg)};
if (net->IsBogonIP(addr))
throw std::invalid_argument{
fmt::format("{} is not a publicly routable ip address", addr)};
public_ip = addr;
});
[this](std::string arg) { public_ip = std::move(arg); });
conf.define_option<std::string>("router", "public-address", Hidden, [](std::string) {
throw std::invalid_argument{
@ -154,19 +140,18 @@ namespace llarp
"[router]:public-port instead"};
});
conf.define_option<int>(
conf.define_option<uint16_t>(
"router",
"public-port",
RelayOnly,
Default{DEFAULT_PUBLIC_PORT},
Comment{
"When specifying public-ip=, this specifies the public UDP port at which this lokinet",
"router is reachable. Required when public-ip is used.",
},
[this](int arg) {
[this](uint16_t arg) {
if (arg <= 0 || arg > std::numeric_limits<uint16_t>::max())
throw std::invalid_argument("public-port must be >= 0 and <= 65536");
public_port = ToNet(huint16_t{static_cast<uint16_t>(arg)});
public_port = arg;
});
conf.define_option<int>(
@ -912,27 +897,38 @@ namespace llarp
conf.define_option<std::string>(
"bind",
"public-ip",
Hidden,
RelayOnly,
Comment{
"The IP address to advertise to the network instead of the incoming= or auto-detected",
"IP. This is typically required only when incoming= is used to listen on an internal",
"private range IP address that received traffic forwarded from the public IP.",
},
[this](std::string_view arg) {
SockAddr pubaddr{arg};
public_addr = pubaddr.getIP();
[this](std::string arg) {
public_addr = std::move(arg);
log::warning(
logcat,
"Using deprecated option; pass this value to [Router]:public-ip instead PLEASE");
});
conf.define_option<uint16_t>(
"bind",
"public-port",
Hidden,
RelayOnly,
Comment{
"The port to advertise to the network instead of the incoming= (or default) port.",
"This is typically required only when incoming= is used to listen on an internal",
"private range IP address/port that received traffic forwarded from the public IP.",
},
[this](uint16_t arg) { public_port = net::port_t::from_host(arg); });
[this](uint16_t arg) {
if (arg <= 0 || arg > std::numeric_limits<uint16_t>::max())
throw std::invalid_argument("public-port must be >= 0 and <= 65536");
public_port = arg;
log::warning(
logcat,
"Using deprecated option; pass this value to [Router]:public-port instead PLEASE");
});
auto parse_addr_for_link = [net_ptr](const std::string& arg) {
std::optional<oxen::quic::Address> maybe = std::nullopt;
@ -1004,11 +1000,13 @@ namespace llarp
},
[this, parse_addr_for_link](const std::string& arg) {
if (auto a = parse_addr_for_link(arg); a and a->is_addressable())
addr = *a;
{
listen_addr = *a;
using_user_value = true;
using_new_api = true;
}
else
throw std::invalid_argument{"Could not parse listen address!"};
using_new_api = true;
});
conf.define_option<std::string>(
@ -1022,21 +1020,17 @@ namespace llarp
throw std::runtime_error{"USE THE NEW API -- SPECIFY LOCAL ADDRESS UNDER [LISTEN]"};
if (auto a = parse_addr_for_link(arg); a and a->is_addressable())
addr = *a;
{
log::warning(
logcat,
"Loaded address from deprecated [inbound] options; update your config to use "
"[bind]:listen instead PLEASE");
listen_addr = *a;
using_user_value = true;
}
});
conf.define_option<std::string>(
"bind",
"outbound",
MultiValue,
Hidden,
[this, parse_addr_for_link](const std::string& arg) {
if (using_new_api)
throw std::runtime_error{"USE THE NEW API -- SPECIFY LOCAL ADDRESS UNDER [LISTEN]"};
if (auto a = parse_addr_for_link(arg); a and a->is_addressable())
addr = *a;
});
conf.define_option<std::string>("bind", "outbound", MultiValue, Deprecated, Hidden);
conf.add_undeclared_handler(
"bind", [this](std::string_view, std::string_view key, std::string_view val) {
@ -1055,7 +1049,11 @@ namespace llarp
// special case: wildcard for outbound
if (key == "*")
{
addr = oxen::quic::Address{port};
log::warning(
logcat,
"Wildcat address referencing port {} is referencing deprecated outbound config "
"options; use [bind]:listen instead",
port);
return;
}
@ -1074,16 +1072,17 @@ namespace llarp
e.what())};
}
if (temp.is_addressable())
if (not temp.is_addressable())
{
addr = std::move(temp);
return;
throw std::runtime_error{fmt::format(
"Invalid address: {}; stop using this deprecated handler, update your config to "
"use "
"[bind]:listen instead PLEASE",
temp)};
}
throw std::runtime_error{fmt::format(
"Invalid address: {}; stop using this deprecated handler, update your config to use "
"[bind]:listen instead PLEASE",
temp)};
listen_addr = std::move(temp);
using_user_value = true;
});
}

View File

@ -34,8 +34,9 @@ namespace llarp
using SectionValues = llarp::ConfigParser::SectionValues;
using ConfigMap = llarp::ConfigParser::ConfigMap;
inline static constexpr uint16_t DEFAULT_LISTEN_PORT{1090};
constexpr int CLIENT_ROUTER_CONNECTIONS = 4;
inline const std::string QUAD_ZERO{"0.0.0.0"};
inline constexpr uint16_t DEFAULT_LISTEN_PORT{1090};
inline constexpr int CLIENT_ROUTER_CONNECTIONS = 4;
// TODO: don't use these maps. they're sloppy and difficult to follow
/// Small struct to gather all parameters needed for config generation to reduce the number of
@ -77,10 +78,9 @@ namespace llarp
std::string transkey_file;
bool is_relay = false;
/// deprecated
std::optional<net::ipaddr_t> public_ip;
/// deprecated
std::optional<net::port_t> public_port;
std::optional<std::string> public_ip;
std::optional<uint16_t> public_port;
void
define_config_options(ConfigDefinition& conf, const ConfigGenParameters& params);
@ -170,10 +170,14 @@ namespace llarp
struct LinksConfig
{
std::optional<net::ipaddr_t> public_addr;
std::optional<net::port_t> public_port;
// DEPRECATED -- use [Router]:public_addr
std::optional<std::string> public_addr;
// DEPRECATED -- use [Router]:public_port
std::optional<uint16_t> public_port;
oxen::quic::Address addr{""s, DEFAULT_LISTEN_PORT};
std::optional<oxen::quic::Address> listen_addr;
bool using_user_value = false;
bool using_new_api = false;
void

View File

@ -8,7 +8,6 @@ namespace llarp
const char* const LOKINET_VERSION_TAG = "@VERSIONTAG@";
const char* const LOKINET_VERSION_FULL = "lokinet-@lokinet_VERSION_MAJOR@.@lokinet_VERSION_MINOR@.@lokinet_VERSION_PATCH@-@LOKINET_VERSION_TAG@";
const char* const LOKINET_RELEASE_MOTTO = "@RELEASE_MOTTO@";
const char* const LOKINET_DEFAULT_NETID = "lokinet";
const char* const LOKINET_TESTNET_NETID = "testnet";
// clang-format on

View File

@ -10,7 +10,6 @@ namespace llarp
extern const char* const LOKINET_VERSION_TAG;
extern const char* const LOKINET_VERSION_FULL;
extern const char* const LOKINET_RELEASE_MOTTO;
extern const char* const LOKINET_DEFAULT_NETID;
extern const char* const LOKINET_TESTNET_NETID;
} // namespace llarp

View File

@ -57,8 +57,7 @@ namespace llarp
throw std::runtime_error("Cannot call Setup() on context without a Config");
if (opts.showBanner)
llarp::LogInfo(
fmt::format("{} {}", llarp::LOKINET_VERSION_FULL, llarp::LOKINET_RELEASE_MOTTO));
llarp::LogInfo(fmt::format("{}", llarp::LOKINET_VERSION_FULL));
if (!loop)
{

View File

@ -193,26 +193,43 @@ namespace llarp
return on_conn_closed(ci, ec);
},
[this](oxen::quic::dgram_interface& di, bstring dgram) { recv_data_message(di, dgram); });
ep->listen(
tls_creds,
[&](oxen::quic::Connection& c,
oxen::quic::Endpoint& e,
std::optional<int64_t> id) -> std::shared_ptr<oxen::quic::Stream> {
if (id && id == 0)
{
auto s = std::make_shared<oxen::quic::BTRequestStream>(
c, e, [](oxen::quic::Stream& s, uint64_t error_code) {
log::warning(
logcat,
"BTRequestStream closed unexpectedly (ec:{}); closing connection...",
error_code);
s.conn.close_connection(error_code);
});
register_commands(s);
return s;
}
return std::make_shared<oxen::quic::Stream>(c, e);
});
tls_creds->set_key_verify_callback([this](const ustring_view& key, const ustring_view&) {
bool result = false;
RouterID other{key.data()};
if (auto itr = rids_pending_verification.find(other); itr != rids_pending_verification.end())
{
rids_pending_verification.erase(itr);
result = true;
}
if (_router.node_db()->has_rc(other))
result = true;
log::critical(logcat, "{}uccessfully verified connection to {}!", result ? "S" : "Un", other);
return result;
});
if (_router.is_service_node())
{
ep->listen(
tls_creds,
[&](oxen::quic::Connection& c,
oxen::quic::Endpoint& e,
std::optional<int64_t> id) -> std::shared_ptr<oxen::quic::Stream> {
if (id && id == 0)
{
auto s = std::make_shared<oxen::quic::BTRequestStream>(
c, e, [](oxen::quic::Stream& s, uint64_t error_code) {
log::warning(
logcat,
"BTRequestStream closed unexpectedly (ec:{}); closing connection...",
error_code);
s.conn.close_connection(error_code);
});
register_commands(s);
return s;
}
return std::make_shared<oxen::quic::Stream>(c, e);
});
}
return ep;
}
@ -346,6 +363,9 @@ namespace llarp
}
const auto& remote_addr = rc.addr();
const auto& rid = rc.router_id();
rids_pending_verification.insert(rid);
// TODO: confirm remote end is using the expected pubkey (RouterID).
// TODO: ALPN for "client" vs "relay" (could just be set on endpoint creation)
@ -356,10 +376,10 @@ namespace llarp
std::move(on_close));
rv)
{
log::info(quic_cat, "Connection to {} successfully established!", remote_addr);
log::info(quic_cat, "Begun establishing connection to {}", remote_addr);
return;
}
log::warning(quic_cat, "Connection to {} successfully established!", remote_addr);
log::warning(quic_cat, "Failed to begin establishing connection to {}", remote_addr);
}
// TODO: should we add routes here now that Router::SessionOpen is gone?
@ -370,6 +390,12 @@ namespace llarp
const auto& scid = conn_interface.scid();
const auto& rid = ep.connid_map[scid];
log::critical(
logcat,
"SERVICE NODE (RID:{}) ESTABLISHED CONNECTION TO RID:{}",
_router.local_rid(),
rid);
// check to see if this connection was established while we were attempting to queue
// messages to the remote
if (auto itr = pending_conn_msg_queue.find(rid); itr != pending_conn_msg_queue.end())
@ -409,6 +435,10 @@ namespace llarp
{
const auto& rid = c_itr->second;
if (auto maybe = rids_pending_verification.find(rid);
maybe != rids_pending_verification.end())
rids_pending_verification.erase(maybe);
// in case this didn't clear earlier, do it now
if (auto p_itr = pending_conn_msg_queue.find(rid); p_itr != pending_conn_msg_queue.end())
pending_conn_msg_queue.erase(p_itr);
@ -576,9 +606,16 @@ namespace llarp
void
LinkManager::fetch_bootstrap_rcs(
const RouterID& source, std::string payload, std::function<void(oxen::quic::message m)> func)
const RemoteRC& source, std::string payload, std::function<void(oxen::quic::message m)> func)
{
send_control_message(source, "bfetch_rcs", std::move(payload), std::move(func));
_router.loop()->call([this, source, payload, f = std::move(func)]() {
auto pending = PendingControlMessage(std::move(payload), "bfetch_rcs"s, f);
auto [itr, b] = pending_conn_msg_queue.emplace(source.router_id(), MessageQueue());
itr->second.push_back(std::move(pending));
connect_to(source);
});
}
void

View File

@ -181,6 +181,9 @@ namespace llarp
// holds any messages we attempt to send while connections are establishing
std::unordered_map<RouterID, MessageQueue> pending_conn_msg_queue;
// when establishing a connection, the rid of the remote is placed here to be cross-
// checked by the tls verification callback
std::set<RouterID> rids_pending_verification;
util::DecayingHashSet<RouterID> clients{path::DEFAULT_LIFETIME};
@ -252,7 +255,7 @@ namespace llarp
void
fetch_bootstrap_rcs(
const RouterID& source,
const RemoteRC& source,
std::string payload,
std::function<void(oxen::quic::message m)> func);
@ -417,8 +420,14 @@ namespace llarp
connid_map.emplace(conn_interface->scid(), rc.router_id());
auto [itr, b] = conns.emplace(rc.router_id(), nullptr);
auto control_stream =
conn_interface->template get_new_stream<oxen::quic::BTRequestStream>();
auto control_stream = conn_interface->template get_new_stream<oxen::quic::BTRequestStream>(
[](oxen::quic::Stream& s, uint64_t error_code) {
log::warning(
logcat,
"BTRequestStream closed unexpectedly (ec:{}); closing connection...",
error_code);
s.conn.close_connection(error_code);
});
itr->second = std::make_shared<link::Connection>(conn_interface, control_stream, rc);
return true;

View File

@ -196,7 +196,8 @@ namespace llarp
{
// TODO: if this needs to be called more than once (ex: drastic failures), then
// change this assert to a bootstraps.clear() call
assert(_bootstraps->empty());
if (_bootstraps)
assert(_bootstraps->empty());
_bootstraps = std::move(from_router);
_bootstraps->randomize();
@ -343,8 +344,9 @@ namespace llarp
void
NodeDB::fetch_initial()
{
if (known_rids.empty())
if (known_rcs.empty())
{
log::critical(logcat, "No RC's held locally... BOOTSTRAP TIME");
fallback_to_bootstrap();
}
else
@ -368,7 +370,6 @@ namespace llarp
}
std::vector<RouterID> needed;
const auto now = time_point_now();
for (const auto& [rid, rc] : rc_lookup)
@ -606,6 +607,14 @@ namespace llarp
{
_router.last_rc_fetch = llarp::time_point_now();
if (_router.is_service_node())
{
_needs_rebootstrap = false;
fail_sources.clear();
fetch_failures = 0;
return;
}
if (initial)
fetch_rids(initial);
}
@ -620,7 +629,10 @@ namespace llarp
_needs_rebootstrap = false;
if (initial)
{
_needs_initial_fetch = false;
_initial_completed = true;
}
}
void
@ -657,7 +669,7 @@ namespace llarp
_needs_rebootstrap = false;
_router.link_manager().fetch_bootstrap_rcs(
fetch_source,
_bootstraps->current(),
BootstrapFetchMessage::serialize(BOOTSTRAP_SOURCE_COUNT),
[this](oxen::quic::message m) mutable {
if (not m)
@ -756,9 +768,6 @@ namespace llarp
registered_routers.insert(greylist.begin(), greylist.end());
registered_routers.insert(greenlist.begin(), greenlist.end());
for (const auto& rid : whitelist)
known_rids.insert(rid);
router_whitelist.clear();
router_whitelist.insert(whitelist.begin(), whitelist.end());
router_greylist.clear();

View File

@ -135,9 +135,9 @@ namespace llarp
- gray: fully funded, but decommissioned routers
- green: registered, but not fully-staked routers
*/
std::unordered_set<RouterID> router_whitelist;
std::unordered_set<RouterID> router_greylist;
std::unordered_set<RouterID> router_greenlist;
std::set<RouterID> router_whitelist{};
std::set<RouterID> router_greylist{};
std::set<RouterID> router_greenlist{};
// All registered relays (service nodes)
std::set<RouterID> registered_routers;
@ -165,7 +165,7 @@ namespace llarp
std::atomic<int> fetch_failures{0}, bootstrap_failures{0};
std::atomic<bool> _using_bootstrap_fallback{false}, _needs_rebootstrap{false},
_needs_initial_fetch{false};
_needs_initial_fetch{true}, _initial_completed{false};
bool
want_rc(const RouterID& rid) const;
@ -332,7 +332,7 @@ namespace llarp
return known_rids;
}
const std::unordered_set<RouterID>&
const std::set<RouterID>&
greylist() const
{
return router_greylist;

View File

@ -446,7 +446,7 @@ namespace llarp
{
// If we're in the white or gray list then we *should* be establishing connections to other
// routers, so if we have almost no peers then something is almost certainly wrong.
if (appears_funded() and insufficient_peers())
if (appears_funded() and insufficient_peers() and not _testing_disabled)
return "too few peer connections; lokinet is not adequately connected to the network";
return std::nullopt;
}
@ -526,7 +526,7 @@ namespace llarp
void
Router::save_rc()
{
_node_db->put_rc(router_contact.view());
// _node_db->put_rc(router_contact.view());
log::info(logcat, "Saving RC file to {}", our_rc_file);
queue_disk_io([&]() { router_contact.write(our_rc_file); });
}
@ -563,38 +563,39 @@ namespace llarp
transport_keyfile = _key_manager->transkey_path;
identity_keyfile = _key_manager->idkey_path;
std::optional<SockAddr> _ourAddress;
std::optional<std::string> paddr = (conf.router.public_ip) ? conf.router.public_ip
: (conf.links.public_addr) ? conf.links.public_addr
: std::nullopt;
std::optional<uint16_t> pport = (conf.router.public_port) ? conf.router.public_port
: (conf.links.public_port) ? conf.links.public_port
: std::nullopt;
if (auto maybe_ip = conf.links.public_addr)
_ourAddress = var::visit([](auto&& ip) { return SockAddr{ip}; }, *maybe_ip);
else if (auto maybe_ip = conf.router.public_ip)
_ourAddress = var::visit([](auto&& ip) { return SockAddr{ip}; }, *maybe_ip);
if (pport.has_value() and not paddr.has_value())
throw std::runtime_error{"If public-port is specified, public-addr must be as well!"};
if (_ourAddress)
if (conf.links.listen_addr)
{
if (auto maybe_port = conf.links.public_port)
_ourAddress->setPort(*maybe_port);
else if (auto maybe_port = conf.router.public_port)
_ourAddress->setPort(*maybe_port);
else
throw std::runtime_error{"public ip provided without public port"};
log::debug(logcat, "Using {} for our public address", *_ourAddress);
_public_address = oxen::quic::Address{static_cast<const sockaddr*>(*_ourAddress)};
log::critical(logcat, "PUBLIC ADDR: {}", *_public_address);
_listen_address = *conf.links.listen_addr;
}
else
{
log::debug(logcat, "No explicit public address given; inferring now...");
if (paddr or pport)
throw std::runtime_error{"Must specify [bind]:listen in config with public ip/addr!"};
if (auto maybe_addr = net().GetBestNetIF())
{
_public_address = oxen::quic::Address{static_cast<const sockaddr*>(*maybe_addr)};
log::critical(logcat, "PUBLIC ADDR: {}", *_public_address);
_listen_address = oxen::quic::Address{static_cast<const sockaddr*>(*maybe_addr)};
_listen_address.set_port(DEFAULT_LISTEN_PORT);
}
else
throw std::runtime_error{"Could not find net interface on current platform!"};
}
_listen_addr = conf.links.addr;
_public_address = (not paddr and not pport)
? _listen_address
: oxen::quic::Address{*paddr, pport ? *pport : DEFAULT_LISTEN_PORT};
log::critical(logcat, "listen_addr:{} \t public_addr:{}", _listen_address, _public_address);
RouterContact::BLOCK_BOGONS = conf.router.block_bogons;
@ -669,6 +670,8 @@ namespace llarp
if (_bootstrap_rc_list->empty() and not conf.bootstrap.seednode)
{
log::warning(logcat, "Warning: bootstrap list is empty and we are not a seed node");
auto fallbacks = llarp::load_bootstrap_fallbacks();
if (auto itr = fallbacks.find(RouterContact::ACTIVE_NETID); itr != fallbacks.end())
@ -691,9 +694,12 @@ namespace llarp
log::info(
logcat, "Loaded {} default fallback bootstrap routers!", _bootstrap_rc_list->size());
clear_bad_rcs();
node_db()->set_bootstrap_routers(std::move(_bootstrap_rc_list));
}
log::critical(logcat, "We have {} bootstrap routers!", _bootstrap_rc_list->size());
node_db()->set_bootstrap_routers(std::move(_bootstrap_rc_list));
if (conf.bootstrap.seednode)
log::critical(logcat, "We are a bootstrap seed node!");
@ -886,29 +892,28 @@ namespace llarp
next_rc_gossip = now_timepoint + RouterContact::STALE_AGE - random_delta;
}
}
if (needs_initial_fetch())
{
if (not _config->bootstrap.seednode)
node_db()->fetch_initial();
}
else if (needs_rebootstrap() and next_bootstrap_attempt > now_timepoint)
{
node_db()->fallback_to_bootstrap();
}
else
{
if (needs_initial_fetch())
// (client-only) periodically fetch updated RCs
if (now_timepoint - last_rc_fetch > RC_UPDATE_INTERVAL)
{
node_db()->fetch_initial();
node_db()->fetch_rcs();
}
else if (needs_rebootstrap() and next_bootstrap_attempt > now_timepoint)
{
node_db()->fallback_to_bootstrap();
}
else
{
// (client-only) periodically fetch updated RCs
if (now_timepoint - last_rc_fetch > RC_UPDATE_INTERVAL)
{
node_db()->fetch_rcs();
}
// (client-only) periodically fetch updated RouterID list
if (now_timepoint - last_rid_fetch > ROUTERID_UPDATE_INTERVAL)
{
node_db()->fetch_rids();
}
// (client-only) periodically fetch updated RouterID list
if (now_timepoint - last_rid_fetch > ROUTERID_UPDATE_INTERVAL)
{
node_db()->fetch_rids();
}
}
@ -1084,7 +1089,7 @@ namespace llarp
return false;
router_contact = LocalRC::make(
identity(), _is_service_node and _public_address ? *_public_address : _listen_addr);
identity(), _is_service_node and _public_address ? *_public_address : _listen_address);
_link_manager = LinkManager::make(*this);
@ -1374,7 +1379,7 @@ namespace llarp
oxen::quic::Address
Router::listen_addr() const
{
return _listen_addr;
return _listen_address;
}
void

View File

@ -92,7 +92,7 @@ namespace llarp
consensus::reachability_testing router_testing;
std::optional<oxen::quic::Address> _public_address; // public addr for relays
oxen::quic::Address _listen_addr;
oxen::quic::Address _listen_address;
EventLoop_ptr _loop;
std::shared_ptr<vpn::Platform> _vpn;

View File

@ -312,7 +312,9 @@ namespace llarp
public:
RemoteRC() = default;
RemoteRC(std::string_view data) : RemoteRC{oxenc::bt_dict_consumer{data}}
{}
{
_payload = {reinterpret_cast<const unsigned char*>(data.data()), data.size()};
}
RemoteRC(ustring_view data) : RemoteRC{oxenc::bt_dict_consumer{data}}
{
_payload = data;

View File

@ -79,7 +79,7 @@ namespace llarp
return sig;
});
_payload = btdp.view<unsigned char>();
_payload = ustring{btdp.view<unsigned char>()};
}
void

View File

@ -75,11 +75,11 @@ namespace llarp
RemoteRC::read(const fs::path& fname)
{
ustring buf;
buf.reserve(MAX_RC_SIZE);
buf.resize(MAX_RC_SIZE);
try
{
util::file_to_buffer(fname, buf.data(), MAX_RC_SIZE);
util::file_to_buffer(fname, buf.data(), buf.size());
oxenc::bt_dict_consumer btdc{buf};
bt_load(btdc);