mirror of https://github.com/oxen-io/lokinet
fix up log statements
* make socket bind errors have a distinct message reported when caught using their own exception type * omit printing banner in setup when we run from the lokinet executable (but not the liblokinet.so entry point)
This commit is contained in:
parent
a9abeb33cc
commit
4c897f583c
|
@ -2,6 +2,7 @@
|
||||||
#include <llarp/constants/version.hpp>
|
#include <llarp/constants/version.hpp>
|
||||||
#include <llarp.hpp>
|
#include <llarp.hpp>
|
||||||
#include <llarp/util/lokinet_init.h>
|
#include <llarp/util/lokinet_init.h>
|
||||||
|
#include <llarp/util/exceptions.hpp>
|
||||||
#include <llarp/util/fs.hpp>
|
#include <llarp/util/fs.hpp>
|
||||||
#include <llarp/util/str.hpp>
|
#include <llarp/util/str.hpp>
|
||||||
|
|
||||||
|
@ -227,7 +228,7 @@ uninstall_win32_daemon()
|
||||||
static void
|
static void
|
||||||
run_main_context(std::optional<fs::path> confFile, const llarp::RuntimeOptions opts)
|
run_main_context(std::optional<fs::path> confFile, const llarp::RuntimeOptions opts)
|
||||||
{
|
{
|
||||||
llarp::LogTrace("start of run_main_context()");
|
llarp::LogInfo(fmt::format("starting up {} {}", llarp::VERSION_FULL, llarp::RELEASE_MOTTO));
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
std::shared_ptr<llarp::Config> conf;
|
std::shared_ptr<llarp::Config> conf;
|
||||||
|
@ -261,14 +262,18 @@ run_main_context(std::optional<fs::path> confFile, const llarp::RuntimeOptions o
|
||||||
{
|
{
|
||||||
ctx->Setup(opts);
|
ctx->Setup(opts);
|
||||||
}
|
}
|
||||||
catch (std::exception& ex)
|
catch (llarp::util::bind_socket_error& ex)
|
||||||
{
|
{
|
||||||
llarp::LogError(
|
llarp::LogError(fmt::format("{}, is lokinet already running? 🤔", ex.what()));
|
||||||
"failed to set up lokinet: ", ex.what(), ", is lokinet already running? 🤔");
|
exit_code.set_value(1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
catch (std::exception& ex)
|
||||||
|
{
|
||||||
|
llarp::LogError("failed to start up lokinet: {}", ex.what());
|
||||||
exit_code.set_value(1);
|
exit_code.set_value(1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
llarp::util::SetThreadName("llarp-mainloop");
|
llarp::util::SetThreadName("llarp-mainloop");
|
||||||
|
|
||||||
auto result = ctx->Run(opts);
|
auto result = ctx->Run(opts);
|
||||||
|
@ -385,6 +390,7 @@ lokinet_main(int argc, char* argv[])
|
||||||
llarp::log::reset_level(llarp::log::Level::info);
|
llarp::log::reset_level(llarp::log::Level::info);
|
||||||
|
|
||||||
llarp::RuntimeOptions opts;
|
llarp::RuntimeOptions opts;
|
||||||
|
opts.showBanner = false;
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
WindowsServiceStopped stopped_raii;
|
WindowsServiceStopped stopped_raii;
|
||||||
|
@ -428,7 +434,6 @@ lokinet_main(int argc, char* argv[])
|
||||||
std::cout << options.help() << std::endl;
|
std::cout << options.help() << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.count("version"))
|
if (result.count("version"))
|
||||||
{
|
{
|
||||||
std::cout << llarp::VERSION_FULL << std::endl;
|
std::cout << llarp::VERSION_FULL << std::endl;
|
||||||
|
|
|
@ -31,7 +31,7 @@ namespace llarp
|
||||||
|
|
||||||
struct RuntimeOptions
|
struct RuntimeOptions
|
||||||
{
|
{
|
||||||
bool background = false;
|
bool showBanner = true;
|
||||||
bool debug = false;
|
bool debug = false;
|
||||||
bool isSNode = false;
|
bool isSNode = false;
|
||||||
};
|
};
|
||||||
|
|
|
@ -61,8 +61,9 @@ namespace llarp
|
||||||
if (not config)
|
if (not config)
|
||||||
throw std::runtime_error("Cannot call Setup() on context without a Config");
|
throw std::runtime_error("Cannot call Setup() on context without a Config");
|
||||||
|
|
||||||
llarp::LogInfo(llarp::VERSION_FULL, " ", llarp::RELEASE_MOTTO);
|
if (opts.showBanner)
|
||||||
llarp::LogInfo("starting up");
|
llarp::LogInfo(fmt::format("{} {}", llarp::VERSION_FULL, llarp::RELEASE_MOTTO));
|
||||||
|
|
||||||
if (!loop)
|
if (!loop)
|
||||||
{
|
{
|
||||||
auto jobQueueSize = std::max(event_loop_queue_size, config->router.m_JobQueueSize);
|
auto jobQueueSize = std::max(event_loop_queue_size, config->router.m_JobQueueSize);
|
||||||
|
@ -104,7 +105,7 @@ namespace llarp
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
Context::Run(const RuntimeOptions& opts)
|
Context::Run(const RuntimeOptions&)
|
||||||
{
|
{
|
||||||
if (router == nullptr)
|
if (router == nullptr)
|
||||||
{
|
{
|
||||||
|
@ -113,11 +114,8 @@ namespace llarp
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!opts.background)
|
if (not router->Run())
|
||||||
{
|
return 2;
|
||||||
if (!router->Run())
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
// run net io thread
|
// run net io thread
|
||||||
llarp::LogInfo("running mainloop");
|
llarp::LogInfo("running mainloop");
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include <llarp/util/exceptions.hpp>
|
||||||
#include <llarp/util/thread/queue.hpp>
|
#include <llarp/util/thread/queue.hpp>
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include "ev.hpp"
|
#include "ev.hpp"
|
||||||
|
|
||||||
|
@ -315,16 +315,14 @@ namespace llarp::uv
|
||||||
if (handle->active())
|
if (handle->active())
|
||||||
reset_handle(handle->loop());
|
reset_handle(handle->loop());
|
||||||
|
|
||||||
bool good = true;
|
auto err = handle->on<uvw::ErrorEvent>([addr](auto& event, auto&) {
|
||||||
auto err = handle->on<uvw::ErrorEvent>([&](auto& event, auto&) {
|
throw llarp::util::bind_socket_error{
|
||||||
llarp::LogError("failed to bind and start receiving on ", addr, ": ", event.what());
|
fmt::format("failed to bind udp socket on {}: {}", addr, event.what())};
|
||||||
good = false;
|
|
||||||
});
|
});
|
||||||
handle->bind(*static_cast<const sockaddr*>(addr));
|
handle->bind(*static_cast<const sockaddr*>(addr));
|
||||||
if (good)
|
handle->recv();
|
||||||
handle->recv();
|
|
||||||
handle->erase(err);
|
handle->erase(err);
|
||||||
return good;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace llarp::util
|
||||||
|
{
|
||||||
|
class bind_socket_error : public std::runtime_error
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using std::runtime_error::runtime_error;
|
||||||
|
};
|
||||||
|
} // namespace llarp::util
|
Loading…
Reference in New Issue