testnet prep

- disable reachability testing with config option; required to be done on testnet
- reachability testing pipeline through link_manager executes pings similar to storage server. connection established hook reports successful reachability, while connection closed callback (with non-default error code) reports unsuccessful testing
pull/2227/head
dr7ana 6 months ago
parent 70e9c1ae25
commit 62c37825b0

@ -46,10 +46,8 @@ int
main(int argc, char* argv[])
{
const std::unordered_map<std::string, std::string> bootstrap_urls = {
{"mainnet", "https://seed.lokinet.org/lokinet.signed"},
{"lokinet", "https://seed.lokinet.org/lokinet.signed"},
{"testnet", "https://seed.lokinet.org/testnet.signed"},
{"gamma", "https://seed.lokinet.org/testnet.signed"}};
{"testnet", "https://seed.lokinet.org/testnet.signed"}};
std::string bootstrap_url = bootstrap_urls.at("lokinet");
fs::path outputfile{llarp::GetDefaultBootstrap()};

@ -181,7 +181,7 @@ foreach(bs IN ITEMS MAINNET TESTNET)
message(STATUS "Building with ${bs} fallback bootstrap path \"${BOOTSTRAP_FALLBACK_${bs}}\"")
file(READ "${BOOTSTRAP_FALLBACK_${bs}}" bs_data HEX)
if(bs STREQUAL TESTNET)
set(network "gamma")
set(network "testnet")
elseif(bs STREQUAL MAINNET)
set(network "lokinet")
else()

@ -61,8 +61,8 @@ namespace llarp
"netid",
Default{llarp::LOKINET_DEFAULT_NETID},
Comment{
"Network ID; this is '"s + llarp::LOKINET_DEFAULT_NETID
+ "' for mainnet, 'gamma' for testnet.",
"Network ID; this is '"s + llarp::LOKINET_DEFAULT_NETID + "' for mainnet, "s
+ llarp::LOKINET_TESTNET_NETID + "for testnet."s,
},
[this](std::string arg) {
if (arg.size() > NETID_SIZE)
@ -1007,7 +1007,7 @@ 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;
addr = *a;
else
addr = oxen::quic::Address{""s, DEFAULT_LISTEN_PORT};
@ -1021,7 +1021,8 @@ namespace llarp
MultiValue,
Hidden,
Comment{
"********** DEPRECATED **********",
"********** THIS PARAMETER IS DEPRECATED -- USE 'LISTEN' INSTEAD **********",
"",
"Note: the new API dictates the lokinet bind address through the 'listen' config",
"parameter. Only ONE address will be read (no more lists of inbounds). Any address",
"passed to `listen` will supersede the",
@ -1046,7 +1047,7 @@ 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;
addr = *a;
else
addr = oxen::quic::Address{""s, DEFAULT_LISTEN_PORT};
});
@ -1096,7 +1097,7 @@ 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;
addr = *a;
else
addr = oxen::quic::Address{""s, DEFAULT_LISTEN_PORT};
});
@ -1221,17 +1222,16 @@ namespace llarp
LokidConfig::define_config_options(ConfigDefinition& conf, const ConfigGenParameters& params)
{
(void)params;
conf.define_option<bool>("lokid", "enabled", RelayOnly, Deprecated);
conf.define_option<std::string>("lokid", "jsonrpc", RelayOnly, [](std::string arg) {
if (arg.empty())
return;
throw std::invalid_argument(
"the [lokid]:jsonrpc option is no longer supported; please use the [lokid]:rpc config "
"option instead with oxend's lmq-local-control address -- typically a value such as "
"rpc=ipc:///var/lib/oxen/oxend.sock or rpc=ipc:///home/snode/.oxen/oxend.sock");
});
conf.define_option<bool>(
"lokid",
"disable-testing",
Default{true},
Hidden,
RelayOnly,
Comment{
"Development option: set to true to disable reachability testing when using ",
"testnet"},
assignment_acceptor(disable_testing));
conf.define_option<std::string>(
"lokid",
@ -1250,6 +1250,15 @@ namespace llarp
[this](std::string arg) { rpc_addr = oxenmq::address(arg); });
// Deprecated options:
conf.define_option<std::string>("lokid", "jsonrpc", RelayOnly, Deprecated, [](std::string arg) {
if (arg.empty())
return;
throw std::invalid_argument(
"the [lokid]:jsonrpc option is no longer supported; please use the [lokid]:rpc config "
"option instead with oxend's lmq-local-control address -- typically a value such as "
"rpc=ipc:///var/lib/oxen/oxend.sock or rpc=ipc:///home/snode/.oxen/oxend.sock");
});
conf.define_option<bool>("lokid", "enabled", RelayOnly, Deprecated);
conf.define_option<std::string>("lokid", "username", Deprecated);
conf.define_option<std::string>("lokid", "password", Deprecated);
conf.define_option<std::string>("lokid", "service-node-seed", Deprecated);

@ -173,7 +173,7 @@ namespace llarp
std::optional<net::ipaddr_t> public_addr;
std::optional<net::port_t> public_port;
std::optional<oxen::quic::Address> addr;
oxen::quic::Address addr;
bool using_new_api = false;
void
@ -202,6 +202,7 @@ namespace llarp
{
fs::path id_keyfile;
oxenmq::address rpc_addr;
bool disable_testing = true;
void
define_config_options(ConfigDefinition& conf, const ConfigGenParameters& params);

@ -10,5 +10,6 @@ namespace llarp
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
} // namespace llarp

@ -12,4 +12,5 @@ namespace llarp
extern const char* const LOKINET_RELEASE_MOTTO;
extern const char* const LOKINET_DEFAULT_NETID;
extern const char* const LOKINET_TESTNET_NETID;
} // namespace llarp

@ -185,7 +185,7 @@ namespace llarp
- will return a BTRequestStream on the first call to get_new_stream<BTRequestStream>
*/
auto ep = quic->endpoint(
_router.public_ip(),
_router.local_addr(),
[this](oxen::quic::connection_interface& ci) { return on_conn_open(ci); },
[this](oxen::quic::connection_interface& ci, uint64_t ec) {
return on_conn_closed(ci, ec);
@ -298,20 +298,29 @@ namespace llarp
}
void
LinkManager::connect_to(const RouterID& rid)
LinkManager::test_reachability(
const RouterID& rid, conn_open_hook on_open, conn_closed_hook on_close)
{
auto rc = node_db->get_rc(rid);
if (rc)
if (auto rc = node_db->get_rc(rid))
{
connect_to(*rc);
connect_to(*rc, std::move(on_open), std::move(on_close));
}
else
log::warning(quic_cat, "Do something intelligent here for error handling");
log::warning(quic_cat, "Could not find RouterContact for connection to rid:{}", rid);
}
void
LinkManager::connect_to(const RouterID& rid, conn_open_hook hook)
{
if (auto rc = node_db->get_rc(rid))
connect_to(*rc, std::move(hook));
else
log::warning(quic_cat, "Could not find RouterContact for connection to rid:{}", rid);
}
// This function assumes the RC has already had its signature verified and connection is allowed.
void
LinkManager::connect_to(const RemoteRC& rc)
LinkManager::connect_to(const RemoteRC& rc, conn_open_hook on_open, conn_closed_hook on_close)
{
if (auto conn = ep.get_conn(rc.router_id()); conn)
{
@ -325,7 +334,10 @@ namespace llarp
// TODO: confirm remote end is using the expected pubkey (RouterID).
// TODO: ALPN for "client" vs "relay" (could just be set on endpoint creation)
if (auto rv = ep.establish_connection(
oxen::quic::RemoteAddress{rc.router_id().ToView(), remote_addr}, rc);
oxen::quic::RemoteAddress{rc.router_id().ToView(), remote_addr},
rc,
std::move(on_open),
std::move(on_close));
rv)
{
log::info(quic_cat, "Connection to {} successfully established!", remote_addr);

@ -28,6 +28,9 @@ namespace llarp
struct LinkManager;
class NodeDB;
using conn_open_hook = oxen::quic::connection_established_callback;
using conn_closed_hook = oxen::quic::connection_closed_callback;
namespace link
{
struct Connection;
@ -261,10 +264,13 @@ namespace llarp
deregister_peer(RouterID remote);
void
connect_to(const RouterID& router);
test_reachability(const RouterID& rid, conn_open_hook, conn_closed_hook);
void
connect_to(const RouterID& router, conn_open_hook = nullptr);
void
connect_to(const RemoteRC& rc);
connect_to(const RemoteRC& rc, conn_open_hook = nullptr, conn_closed_hook = nullptr);
void
close_connection(RouterID rid);

@ -78,7 +78,6 @@ namespace llarp
llarp::LogTrace("Router::PumpLL() end");
}
// TOFIX: this
util::StatusObject
Router::ExtractStatus() const
{
@ -91,8 +90,7 @@ namespace llarp
{"contacts", _contacts->ExtractStatus()},
{"services", _hidden_service_context.ExtractStatus()},
{"exit", _exit_context.ExtractStatus()},
{"links", _link_manager.extract_status()},
/* {"outboundMessages", _outboundMessageHandler.ExtractStatus()} */};
{"links", _link_manager.extract_status()}};
}
// TODO: investigate changes needed for libquic integration
@ -417,6 +415,7 @@ namespace llarp
throw std::runtime_error("KeyManager failed to initialize");
log::debug(logcat, "Initializing from configuration");
if (!from_config(conf))
throw std::runtime_error("FromConfig() failed");
@ -460,14 +459,6 @@ namespace llarp
is_running.store(false);
}
bool
Router::ParseRoutingMessageBuffer(
const llarp_buffer_t&, path::AbstractHopHandler&, const PathID_t&)
{
// TODO: will go away with the removal of flush upstream/downstream
return false;
}
bool
Router::have_snode_whitelist() const
{
@ -497,7 +488,7 @@ namespace llarp
bool
Router::can_test_routers() const
{
return appears_funded();
return appears_funded() and not _testing_disabled;
}
bool
@ -542,18 +533,22 @@ namespace llarp
// Set netid before anything else
log::debug(logcat, "Network ID set to {}", conf.router.net_id);
if (!conf.router.net_id.empty()
&& strcmp(conf.router.net_id.c_str(), llarp::LOKINET_DEFAULT_NETID) != 0)
const auto& netid = conf.router.net_id;
if (not netid.empty() and netid != llarp::LOKINET_DEFAULT_NETID)
{
const auto& netid = conf.router.net_id;
llarp::LogWarn(
"!!!! you have manually set netid to be '",
log::critical(
logcat,
"Network ID set to {}, which is not {}! Lokinet will attempt to run on the specified "
"network",
netid,
"' which does not equal '",
llarp::LOKINET_DEFAULT_NETID,
"' you will run as a different network, good luck "
"and don't forget: something something traffic shape "
"correlation!!");
llarp::LOKINET_DEFAULT_NETID);
_testnet = netid == llarp::LOKINET_TESTNET_NETID;
_testing_disabled = conf.lokid.disable_testing;
if (_testing_disabled and not _testnet)
throw std::runtime_error{"Error: reachability testing can only be disabled on testnet!"};
}
// Router config
@ -583,6 +578,8 @@ namespace llarp
else
log::debug(logcat, "No explicit public address given; will auto-detect during link setup");
_local_addr = conf.links.addr;
RouterContact::BLOCK_BOGONS = conf.router.block_bogons;
auto& networkConfig = conf.network;
@ -1060,7 +1057,9 @@ namespace llarp
if (is_running || is_stopping)
return false;
router_contact = LocalRC::make(identity(), public_ip());
// TODO: look at _ourAddress
router_contact = LocalRC::make(identity(), local_addr());
if (is_service_node() and not router_contact.is_public_router())
{
@ -1133,7 +1132,9 @@ namespace llarp
// yet when we expect to have one.
if (not can_test_routers())
return;
auto tests = router_testing.get_failing();
if (auto maybe = router_testing.next_random(this))
{
tests.emplace_back(*maybe, 0);
@ -1154,51 +1155,30 @@ namespace llarp
// try to make a session to this random router
// this will do a dht lookup if needed
_link_manager.connect_to(router);
/*
* TODO: container of pending snode test routers to be queried on
* connection success/failure, then do this stuff there.
_outboundSessionMaker.CreateSessionTo(
router, [previous_fails = fails, this](const auto& router, const auto result) {
auto rpc = RpcClient();
if (result != SessionResult::Establish)
{
// failed connection mark it as so
m_routerTesting.add_failing_node(router, previous_fails);
LogInfo(
"FAILED SN connection test to ",
router,
" (",
previous_fails + 1,
" consecutive failures) result=",
result);
}
else
{
m_routerTesting.remove_node_from_failing(router);
if (previous_fails > 0)
{
LogInfo(
"Successful SN connection test to ",
router,
" after ",
previous_fails,
" failures");
}
else
{
LogDebug("Successful SN connection test to ", router);
}
}
if (rpc)
_link_manager.test_reachability(
router,
[this, rid = router, previous = fails](oxen::quic::connection_interface& conn) {
log::info(
logcat,
"Successful SN reachability test to {}{}",
rid,
previous ? "after {} previous failures"_format(previous) : "");
router_testing.remove_node_from_failing(rid);
_rpc_client->InformConnection(rid, true);
conn.close_connection();
},
[this, rid = router, previous = fails](
oxen::quic::connection_interface&, uint64_t ec) {
if (ec != 0)
{
// inform as needed
rpc->InformConnection(router, result == SessionResult::Establish);
log::info(
logcat,
"Unsuccessful SN reachability test to {} after {} previous failures",
rid,
previous);
router_testing.add_failing_node(rid, previous);
}
});
*/
}
});
}
@ -1358,7 +1338,7 @@ namespace llarp
}
oxen::quic::Address
Router::public_ip() const
Router::local_addr() const
{
return _local_addr;
}

@ -86,6 +86,11 @@ namespace llarp
int _outbound_udp_socket = -1;
bool _is_service_node = false;
bool _testnet = false;
bool _testing_disabled = false;
consensus::reachability_testing router_testing;
std::optional<SockAddr> _ourAddress;
oxen::quic::Address _local_addr;
@ -124,8 +129,6 @@ namespace llarp
service::Context _hidden_service_context;
consensus::reachability_testing router_testing;
bool
should_report_stats(llarp_time_t now) const;
@ -273,7 +276,7 @@ namespace llarp
}
oxen::quic::Address
public_ip() const;
local_addr() const;
util::StatusObject
ExtractStatus() const;
@ -476,13 +479,6 @@ namespace llarp
return llarp::time_now_ms();
}
/// parse a routing message in a buffer and handle it with a handler if
/// successful parsing return true on parse and handle success otherwise
/// return false
bool
ParseRoutingMessageBuffer(
const llarp_buffer_t& buf, path::AbstractHopHandler& p, const PathID_t& rxid);
void
ConnectToRandomRouters(int N);

@ -33,7 +33,7 @@ namespace llarp
/// "6" -- optional 18 byte IPv6 address & port: 16 byte raw IPv6 address followed by 2 bytes
/// of port in network order.
/// "i" -- optional network ID string of up to 8 bytes; this is omitted for the default network
/// ID ("lokinet") but included for others (such as "gamma" for testnet).
/// ID ("lokinet") but included for others (such as "testnet" for testnet).
/// "p" -- 32-byte router pubkey
/// "t" -- timestamp when this RC record was created (which also implicitly determines when it
/// goes stale and when it expires).

@ -1398,7 +1398,7 @@ namespace llarp::service
while (not _inbound_queue.empty())
{
// succ it out
// suck it out
queue.emplace(std::move(*_inbound_queue.popFront()));
}

Loading…
Cancel
Save