1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00

Don't do func(a, std::move(a))...

also includes some log statement improvements and changes to the quic
tcp_connect test program
This commit is contained in:
Thomas Winget 2023-01-19 20:21:29 -05:00
parent ebcb44ae3a
commit b15e6b752b
3 changed files with 24 additions and 11 deletions

View file

@ -29,12 +29,21 @@ signal_handler(int)
int
main(int argc, char* argv[])
{
if (argc != 2)
if (argc < 3 || argc > 4)
{
std::cout << "Usage: " << argv[0] << " something.loki\n";
std::cout << "Usage: " << argv[0] << " something.{loki,snode} port [testnet]\n";
return 0;
}
std::string netid = "lokinet";
std::string data_dir = "./tcp_connect_data_dir";
if (argc == 4) // if testnet
{
netid = "gamma"; // testnet netid
data_dir += "/testnet";
}
signal(SIGINT, signal_handler);
signal(SIGTERM, signal_handler);
@ -45,9 +54,10 @@ main(int argc, char* argv[])
std::cout << "starting up\n";
lokinet_set_netid(netid.c_str());
auto shared_ctx = std::shared_ptr<lokinet_context>(lokinet_context_new(), lokinet_context_free);
auto* ctx = shared_ctx.get();
lokinet_set_data_dir("./tcp_connect_data_dir", ctx);
lokinet_set_data_dir(data_dir.c_str(), ctx);
if (lokinet_context_start(ctx))
throw std::runtime_error{"could not start context"};
@ -70,6 +80,7 @@ main(int argc, char* argv[])
// log level debug for quic
llarp::log::set_level("quic", llarp::log::Level::trace);
//llarp::log::set_level("quic", llarp::log::Level::debug);
std::cout << "\n\nquic log level: " << llarp::log::to_string(llarp::log::get_level("quic")) << "\n\n";
auto addr_c = lokinet_address(ctx);
@ -84,7 +95,8 @@ main(int argc, char* argv[])
lokinet_stream_result stream_res;
std::string target{argv[1]};
target += ":12345";
target = target + ":" + argv[2];
lokinet_outbound_stream(&stream_res, target.c_str(), "127.0.0.1:54321", ctx);
if (stream_res.error)

View file

@ -538,7 +538,7 @@ namespace llarp::quic
[this,
after_path = std::move(after_path),
pport = pport,
remote_addr = std::move(remote_addr)](auto maybe_remote) {
remote_addr = remote_addr](auto maybe_remote) {
if (not continue_connecting(
pport, (bool)maybe_remote, "endpoint ONS lookup", remote_addr))
return;

View file

@ -1057,26 +1057,27 @@ namespace llarp
{
if (not NameIsValid(name))
{
handler(ParseAddress(name));
log::warning(logcat, "\"{}\" is not a valid ONS name", name);
handler(std::nullopt);
return;
}
auto& cache = m_state->nameCache;
const auto maybe = cache.Get(name);
if (maybe.has_value())
{
log::debug(logcat, "Returning cached result for ONS name \"{}\"", name);
handler(maybe);
return;
}
LogInfo(Name(), " looking up LNS name: ", name);
log::info(logcat, "{} looking up ONS name \"{}\"", Name(), name);
auto paths = GetUniqueEndpointsForLookup();
// not enough paths
if (not ReadyToDoLookup(paths.size()))
{
LogWarn(
log::warning(logcat,
"{} not enough paths for ONS lookup, have {} need {}",
Name(),
" not enough paths for lns lookup, have ",
paths.size(),
" need ",
MIN_ENDPOINTS_FOR_LNS_LOOKUP);
handler(std::nullopt);
return;
@ -1114,7 +1115,7 @@ namespace llarp
for (const auto& path : chosenpaths)
{
LogInfo(Name(), " lookup ", name, " from ", path->Endpoint());
log::info(logcat, "{} lookup \"{}\" via {}", Name(), name, path->Endpoint());
auto job = new LookupNameJob{this, GenTXID(), name, resultHandler};
job->SendRequestViaPath(path, m_router);
}