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.hpp>
|
||||
#include <llarp/util/lokinet_init.h>
|
||||
#include <llarp/util/exceptions.hpp>
|
||||
#include <llarp/util/fs.hpp>
|
||||
#include <llarp/util/str.hpp>
|
||||
|
||||
|
@ -227,7 +228,7 @@ uninstall_win32_daemon()
|
|||
static void
|
||||
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
|
||||
{
|
||||
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);
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
catch (llarp::util::bind_socket_error& ex)
|
||||
{
|
||||
llarp::LogError(
|
||||
"failed to set up lokinet: ", ex.what(), ", is lokinet already running? 🤔");
|
||||
llarp::LogError(fmt::format("{}, is lokinet already running? 🤔", ex.what()));
|
||||
exit_code.set_value(1);
|
||||
return;
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
llarp::LogError("failed to start up lokinet: {}", ex.what());
|
||||
exit_code.set_value(1);
|
||||
return;
|
||||
}
|
||||
|
||||
llarp::util::SetThreadName("llarp-mainloop");
|
||||
|
||||
auto result = ctx->Run(opts);
|
||||
|
@ -385,6 +390,7 @@ lokinet_main(int argc, char* argv[])
|
|||
llarp::log::reset_level(llarp::log::Level::info);
|
||||
|
||||
llarp::RuntimeOptions opts;
|
||||
opts.showBanner = false;
|
||||
|
||||
#ifdef _WIN32
|
||||
WindowsServiceStopped stopped_raii;
|
||||
|
@ -428,7 +434,6 @@ lokinet_main(int argc, char* argv[])
|
|||
std::cout << options.help() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (result.count("version"))
|
||||
{
|
||||
std::cout << llarp::VERSION_FULL << std::endl;
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace llarp
|
|||
|
||||
struct RuntimeOptions
|
||||
{
|
||||
bool background = false;
|
||||
bool showBanner = true;
|
||||
bool debug = false;
|
||||
bool isSNode = false;
|
||||
};
|
||||
|
|
|
@ -61,8 +61,9 @@ namespace llarp
|
|||
if (not config)
|
||||
throw std::runtime_error("Cannot call Setup() on context without a Config");
|
||||
|
||||
llarp::LogInfo(llarp::VERSION_FULL, " ", llarp::RELEASE_MOTTO);
|
||||
llarp::LogInfo("starting up");
|
||||
if (opts.showBanner)
|
||||
llarp::LogInfo(fmt::format("{} {}", llarp::VERSION_FULL, llarp::RELEASE_MOTTO));
|
||||
|
||||
if (!loop)
|
||||
{
|
||||
auto jobQueueSize = std::max(event_loop_queue_size, config->router.m_JobQueueSize);
|
||||
|
@ -104,7 +105,7 @@ namespace llarp
|
|||
}
|
||||
|
||||
int
|
||||
Context::Run(const RuntimeOptions& opts)
|
||||
Context::Run(const RuntimeOptions&)
|
||||
{
|
||||
if (router == nullptr)
|
||||
{
|
||||
|
@ -113,11 +114,8 @@ namespace llarp
|
|||
return 1;
|
||||
}
|
||||
|
||||
if (!opts.background)
|
||||
{
|
||||
if (!router->Run())
|
||||
return 2;
|
||||
}
|
||||
if (not router->Run())
|
||||
return 2;
|
||||
|
||||
// run net io thread
|
||||
llarp::LogInfo("running mainloop");
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
#include <memory>
|
||||
#include <thread>
|
||||
#include <type_traits>
|
||||
#include <llarp/util/exceptions.hpp>
|
||||
#include <llarp/util/thread/queue.hpp>
|
||||
|
||||
#include <cstring>
|
||||
#include "ev.hpp"
|
||||
|
||||
|
@ -315,16 +315,14 @@ namespace llarp::uv
|
|||
if (handle->active())
|
||||
reset_handle(handle->loop());
|
||||
|
||||
bool good = true;
|
||||
auto err = handle->on<uvw::ErrorEvent>([&](auto& event, auto&) {
|
||||
llarp::LogError("failed to bind and start receiving on ", addr, ": ", event.what());
|
||||
good = false;
|
||||
auto err = handle->on<uvw::ErrorEvent>([addr](auto& event, auto&) {
|
||||
throw llarp::util::bind_socket_error{
|
||||
fmt::format("failed to bind udp socket on {}: {}", addr, event.what())};
|
||||
});
|
||||
handle->bind(*static_cast<const sockaddr*>(addr));
|
||||
if (good)
|
||||
handle->recv();
|
||||
handle->recv();
|
||||
handle->erase(err);
|
||||
return good;
|
||||
return true;
|
||||
}
|
||||
|
||||
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