diff --git a/llarp/address/address.hpp b/llarp/address/address.hpp index cc77961f7..7b4302de8 100644 --- a/llarp/address/address.hpp +++ b/llarp/address/address.hpp @@ -37,7 +37,7 @@ namespace llarp } explicit RemoteAddress(PubKey pk, std::string_view tld, std::optional n = std::nullopt) - : _pubkey{std::move(pk)}, _name{std::move(n)}, _tld{tld} + : _pubkey{pk.data()}, _name{std::move(n)}, _tld{tld} {} RemoteAddress(const RemoteAddress& other) : RemoteAddress{other._pubkey, other._tld, other._name} {} @@ -94,17 +94,20 @@ namespace llarp template , int> = 0> std::optional> from_pubkey_addr(const std::string& arg) { - if (service::is_valid_ons(arg)) + if constexpr (std::is_same_v || std::is_same_v) { - return RemoteAddress(arg, true); - } - if (auto maybe_addr = parse_addr_string(arg, TLD::CLIENT)) - { - return RemoteAddress(*maybe_addr); + if (service::is_valid_ons(arg)) + { + return std::make_optional(RemoteAddress(arg, true)); + } + if (auto maybe_addr = parse_addr_string(arg, TLD::CLIENT)) + { + return std::make_optional(RemoteAddress(*maybe_addr)); + } } if (auto maybe_addr = parse_addr_string(arg, TLD::RELAY)) { - return RemoteAddress(*maybe_addr); + return std::make_optional(RemoteAddress(*maybe_addr)); } return std::nullopt; diff --git a/llarp/address/keys.hpp b/llarp/address/keys.hpp index 4134be86f..024bb0762 100644 --- a/llarp/address/keys.hpp +++ b/llarp/address/keys.hpp @@ -55,6 +55,8 @@ namespace llarp {} explicit RelayPubKey(const RelayPubKey& other) : RelayPubKey{other.data()} {} + RelayPubKey(RelayPubKey&& other) : RelayPubKey{other.data()} + {} std::string to_string() const; @@ -79,6 +81,8 @@ namespace llarp {} explicit ClientPubKey(const ClientPubKey& other) : ClientPubKey{other.data()} {} + ClientPubKey(ClientPubKey&& other) : ClientPubKey{other.data()} + {} std::string to_string() const; diff --git a/llarp/auth/rpc_auth.cpp b/llarp/auth/rpc_auth.cpp index 021e0910f..f19294393 100644 --- a/llarp/auth/rpc_auth.cpp +++ b/llarp/auth/rpc_auth.cpp @@ -5,6 +5,8 @@ namespace llarp::auth { + static auto logcat = log::Cat("rpc.auth"); + RPCAuthPolicy::RPCAuthPolicy( Router& r, std::string url, diff --git a/llarp/bootstrap.cpp b/llarp/bootstrap.cpp index ad1bfafe6..2f90a5f22 100644 --- a/llarp/bootstrap.cpp +++ b/llarp/bootstrap.cpp @@ -1,5 +1,6 @@ #include "bootstrap.hpp" +#include "util/file.hpp" #include "util/logging.hpp" #include "util/logging/buffer.hpp" diff --git a/llarp/config/definition.hpp b/llarp/config/definition.hpp index c2648b617..9b1943c9f 100644 --- a/llarp/config/definition.hpp +++ b/llarp/config/definition.hpp @@ -279,7 +279,7 @@ namespace llarp if (default_values.empty()) return {}; if constexpr (std::is_same_v) - return {{default_values.front().u8string()}}; + return {{default_values.front().string()}}; else { std::vector def_strs; diff --git a/llarp/context.cpp b/llarp/context.cpp index 59ed832b2..5c1e603ae 100644 --- a/llarp/context.cpp +++ b/llarp/context.cpp @@ -21,6 +21,8 @@ namespace llarp { + static auto logcat = log::Cat("context"); + bool Context::call_safe(std::function f) { if (!_loop) diff --git a/llarp/dns/name.cpp b/llarp/dns/name.cpp index cf1a36171..93a79c467 100644 --- a/llarp/dns/name.cpp +++ b/llarp/dns/name.cpp @@ -114,13 +114,15 @@ namespace llarp::dns // our string right now is the little endian representation, so load it as such on // little endian, or in reverse on big endian. + + std::string arg; + if constexpr (oxenc::little_endian) - { - auto hex = oxenc::from_hex(in.begin(), in.end()); - return ipv6{reinterpret_cast(hex.data())}; - } + arg = oxenc::from_hex(in.begin(), in.end()); else - return ipv6{reinterpret_cast(in.data())}; + arg = std::string{in.data(), in.size()}; + + return ipv6{arg}; } return std::nullopt; } diff --git a/llarp/dns/sd_platform.cpp b/llarp/dns/sd_platform.cpp index dc42b2023..acb7816b4 100644 --- a/llarp/dns/sd_platform.cpp +++ b/llarp/dns/sd_platform.cpp @@ -21,7 +21,7 @@ namespace llarp::dns::sd const bool isStandardDNSPort = dns.port() == 53; if (dns.is_ipv6()) { - ipv6 ipv6{dns.in6().sin6_addr.s6_addr}; + ipv6 ipv6{&dns.in6().sin6_addr}; static_assert(sizeof(ipv6) == 16); auto* a = reinterpret_cast(&ipv6); diff --git a/llarp/dns/server.cpp b/llarp/dns/server.cpp index 01cdc5563..51ad3d9a8 100644 --- a/llarp/dns/server.cpp +++ b/llarp/dns/server.cpp @@ -356,7 +356,7 @@ namespace llarp::dns // add host files for (const auto& file : conf.hostfiles) { - const auto str = file.u8string(); + const auto str = file.string(); if (auto ret = ub_ctx_hosts(m_ctx, str.c_str())) { throw std::runtime_error{fmt::format("Failed to add host file {}: {}", file, ub_strerror(ret))}; diff --git a/llarp/ev/loop.hpp b/llarp/ev/loop.hpp index 735fb778e..d7dee6b8a 100644 --- a/llarp/ev/loop.hpp +++ b/llarp/ev/loop.hpp @@ -62,20 +62,20 @@ namespace llarp bool add_network_interface(std::shared_ptr netif, udp_pkt_hook handler); template - void call(Callable&& f, source_location src = source_location::current()) + void call(Callable&& f) { - _loop->call(std::forward(f), src); + _loop->call(std::forward(f)); } template ()())> - Ret call_get(Callable&& f, source_location src = source_location::current()) + Ret call_get(Callable&& f) { - return _loop->call_get(std::forward(f), src); + return _loop->call_get(std::forward(f)); } - void call_soon(std::function f, source_location src = source_location::current()) + void call_soon(std::function f) { - _loop->call_soon(std::move(f), src); + _loop->call_soon(std::move(f)); } void call_later(loop_time delay, std::function hook); diff --git a/llarp/messages/common.hpp b/llarp/messages/common.hpp index 0932d51c4..a8aab3df5 100644 --- a/llarp/messages/common.hpp +++ b/llarp/messages/common.hpp @@ -14,6 +14,8 @@ namespace llarp { namespace messages { + static auto logcat = log::Cat("messages"); + inline std::string serialize_response(oxenc::bt_dict supplement = {}) { return oxenc::bt_serialize(supplement); diff --git a/llarp/messages/dht.hpp b/llarp/messages/dht.hpp index 6b22c9d52..8e35c075f 100644 --- a/llarp/messages/dht.hpp +++ b/llarp/messages/dht.hpp @@ -22,7 +22,7 @@ namespace llarp } catch (...) { - log::error(link_cat, "Error: FindIntroMessage failed to bt encode contents!"); + log::error(messages::logcat, "Error: FindIntroMessage failed to bt encode contents!"); } return std::move(btdp).str(); @@ -43,7 +43,7 @@ namespace llarp } catch (...) { - log::error(link_cat, "Error: FindNameMessage failed to bt encode contents!"); + log::error(messages::logcat, "Error: FindNameMessage failed to bt encode contents!"); } return std::move(btdp).str(); @@ -59,7 +59,7 @@ namespace llarp } catch (...) { - log::error(link_cat, "Error: FindNameMessage failed to bt encode contents!"); + log::error(messages::logcat, "Error: FindNameMessage failed to bt encode contents!"); } return std::move(btdp).str(); @@ -85,7 +85,7 @@ namespace llarp } catch (...) { - log::error(link_cat, "Error: FindNameMessage failed to bt encode contents!"); + log::error(messages::logcat, "Error: FindNameMessage failed to bt encode contents!"); } return std::move(btdp).str(); diff --git a/llarp/messages/fetch.hpp b/llarp/messages/fetch.hpp index 14338add9..85b4e6c83 100644 --- a/llarp/messages/fetch.hpp +++ b/llarp/messages/fetch.hpp @@ -19,7 +19,7 @@ namespace llarp } catch (...) { - log::error(link_cat, "Error: GossipRCMessage failed to bt encode contents"); + log::error(messages::logcat, "Error: GossipRCMessage failed to bt encode contents"); } return std::move(btdp).str(); @@ -49,7 +49,7 @@ namespace llarp } catch (...) { - log::error(link_cat, "Error: RCFetchMessage failed to bt encode contents!"); + log::error(messages::logcat, "Error: RCFetchMessage failed to bt encode contents!"); } return std::move(btdp).str(); @@ -65,7 +65,7 @@ namespace llarp if (local_rc) { - log::critical(link_cat, "Serializing localRC: {}", oxenc::to_hex(local_rc->view())); + log::critical(messages::logcat, "Serializing localRC: {}", oxenc::to_hex(local_rc->view())); btdp.append_encoded("local", oxen::quic::to_sv(local_rc->view())); } @@ -87,7 +87,7 @@ namespace llarp } catch (...) { - log::error(link_cat, "Error: BootstrapFetchMessage failed to bt encode contents!"); + log::error(messages::logcat, "Error: BootstrapFetchMessage failed to bt encode contents!"); } return std::move(btdp).str(); @@ -108,7 +108,7 @@ namespace llarp } catch (...) { - log::error(link_cat, "Error: FetchRIDMessage failed to bt encode contents!"); + log::error(messages::logcat, "Error: FetchRIDMessage failed to bt encode contents!"); } return std::move(btdp).str(); diff --git a/llarp/messages/path.hpp b/llarp/messages/path.hpp index 2ade7b2d7..4abe67fff 100644 --- a/llarp/messages/path.hpp +++ b/llarp/messages/path.hpp @@ -51,7 +51,7 @@ namespace llarp if (!crypto::dh_client(hop.shared, hop.rc.router_id(), hop.commkey, hop.nonce)) { auto err = fmt::format("Failed to generate shared key for path build!"); - log::warning(path_cat, err); + log::warning(messages::logcat, "{}", err); throw std::runtime_error{std::move(err)}; } // generate nonceXOR value self->hop->pathKey @@ -89,7 +89,7 @@ namespace llarp // derive (outer) shared key if (!crypto::dh_client(shared, hop.rc.router_id(), framekey, outer_nonce)) { - log::warning(path_cat, "DH client failed during hop info encryption!"); + log::warning(messages::logcat, "DH client failed during hop info encryption!"); throw std::runtime_error{"DH failed during hop info encryption"}; } @@ -97,7 +97,7 @@ namespace llarp if (!crypto::xchacha20( reinterpret_cast(hop_info.data()), hop_info.size(), shared, outer_nonce)) { - log::warning(path_cat, "Hop info encryption failed!"); + log::warning(messages::logcat, "Hop info encryption failed!"); throw std::runtime_error{"Hop info encryption failed"}; } @@ -122,7 +122,7 @@ namespace llarp hashed_data.size(), shared)) { - log::warning(path_cat, "Failed to generate HMAC for hop info"); + log::warning(messages::logcat, "Failed to generate HMAC for hop info"); throw std::runtime_error{"Failed to generate HMAC for hop info"}; } diff --git a/llarp/net/net_int.hpp b/llarp/net/net_int.hpp index 164bc755d..a99819155 100644 --- a/llarp/net/net_int.hpp +++ b/llarp/net/net_int.hpp @@ -176,7 +176,7 @@ namespace llarp { nuint_t x{}; if (not x.FromString(str)) - throw std::invalid_argument{fmt::format("{} is not a valid value")}; + throw std::invalid_argument{fmt::format("{} is not a valid value", str)}; return x; } diff --git a/llarp/nodedb.cpp b/llarp/nodedb.cpp index 1ce982fea..ced443c78 100644 --- a/llarp/nodedb.cpp +++ b/llarp/nodedb.cpp @@ -15,6 +15,8 @@ static const std::string RC_FILE_EXT = ".signed"; namespace llarp { + static auto logcat = llarp::log::Cat("nodedb"); + static void EnsureSkiplist(fs::path nodedbDir) { if (not fs::exists(nodedbDir)) @@ -450,7 +452,7 @@ namespace llarp { auto err = "RID fetch from {} via {} {}"_format(target, source, m.timed_out ? "timed out" : "failed"); - log::critical(link_cat, err); + log::critical(logcat, "{}", err); ingest_rid_fetch_responses(target); fetch_rids_result(initial); return; @@ -476,8 +478,7 @@ namespace llarp { if (s.size() != RouterID::SIZE) { - log::critical( - link_cat, "RID fetch from {} via {} returned bad RouterID", target, source); + log::critical(logcat, "RID fetch from {} via {} returned bad RouterID", target, source); ingest_rid_fetch_responses(target); fetch_rids_result(initial); return; @@ -492,7 +493,7 @@ namespace llarp } catch (const std::exception& e) { - log::critical(link_cat, "Error handling fetch RouterIDs response: {}", e.what()); + log::critical(logcat, "Error handling fetch RouterIDs response: {}", e.what()); ingest_rid_fetch_responses(target); fetch_rids_result(initial); } @@ -634,7 +635,7 @@ namespace llarp if (_using_bootstrap_fallback) { auto err = fmt::format("ERROR: ALL BOOTSTRAPS ARE BAD... REATTEMPTING IN {}...", BOOTSTRAP_COOLDOWN); - log::error(logcat, err); + log::error(logcat, "{}", err); bootstrap_cooldown(); return; diff --git a/llarp/path/path.cpp b/llarp/path/path.cpp index 1e997baf9..3425b68b6 100644 --- a/llarp/path/path.cpp +++ b/llarp/path/path.cpp @@ -91,6 +91,18 @@ namespace llarp::path return send_path_control_message("find_name", FindNameMessage::serialize(std::move(name)), std::move(func)); } + void Path::enable_exit_traffic() + { + log::info(logcat, "{} {} granted exit", name(), pivot_router_id()); + // _role |= ePathRoleExit; + } + + void Path::mark_exit_closed() + { + log::info(logcat, "{} hd its exit closed", name()); + // _role &= ePathRoleExit; + } + std::string Path::make_outer_payload(std::string payload) { SymmNonce nonce; diff --git a/llarp/path/path.hpp b/llarp/path/path.hpp index fd9f9ca97..6f713d37a 100644 --- a/llarp/path/path.hpp +++ b/llarp/path/path.hpp @@ -95,17 +95,9 @@ namespace llarp return now >= (ExpireTime() - dlt); } - void enable_exit_traffic() - { - log::info(path_cat, "{} {} granted exit", name(), pivot_router_id()); - // _role |= ePathRoleExit; - } + void enable_exit_traffic(); - void mark_exit_closed() - { - log::info(path_cat, "{} hd its exit closed", name()); - // _role &= ePathRoleExit; - } + void mark_exit_closed(); bool update_exit(uint64_t tx_id); diff --git a/llarp/path/pathhandler.cpp b/llarp/path/pathhandler.cpp index 5d8d67a18..74fe5844f 100644 --- a/llarp/path/pathhandler.cpp +++ b/llarp/path/pathhandler.cpp @@ -13,13 +13,10 @@ #include -namespace llarp -{ - auto path_cat = log::Cat("path"); -} - namespace llarp::path { + static auto logcat = log::Cat("pathhandler"); + bool BuildLimiter::Attempt(const RouterID& router) { return _edge_limiter.Insert(router); @@ -104,7 +101,7 @@ namespace llarp::path if (!crypto::dh_client(hop.shared, hop.rc.router_id(), hop.commkey, hop.nonce)) { auto err = fmt::format("{} failed to generate shared key for path build!", name()); - log::error(path_cat, err); + log::error(logcat, "{}", err); throw std::runtime_error{std::move(err)}; } // generate nonceXOR value self->hop->pathKey @@ -263,14 +260,14 @@ namespace llarp::path // derive (outer) shared key if (!crypto::dh_client(shared, hop.rc.router_id(), framekey, outer_nonce)) { - log::error(path_cat, "DH client failed during hop info encryption!"); + log::error(logcat, "DH client failed during hop info encryption!"); throw std::runtime_error{"DH failed during hop info encryption"}; } // encrypt hop_info (mutates in-place) if (!crypto::xchacha20(reinterpret_cast(hop_info.data()), hop_info.size(), shared, outer_nonce)) { - log::error(path_cat, "Hop info encryption failed!"); + log::error(logcat, "Hop info encryption failed!"); throw std::runtime_error{"Hop info encryption failed"}; } @@ -295,7 +292,7 @@ namespace llarp::path hashed_data.size(), shared)) { - log::error(path_cat, "Failed to generate HMAC for hop info"); + log::error(logcat, "Failed to generate HMAC for hop info"); throw std::runtime_error{"Failed to generate HMAC for hop info"}; } @@ -551,7 +548,7 @@ namespace llarp::path hops.push_back(*maybe); else { - log::warning(path_cat, "{} has no first hop candidate", name()); + log::warning(logcat, "{} has no first hop candidate", name()); return std::nullopt; } @@ -623,7 +620,7 @@ namespace llarp::path { if (is_stopped()) { - log::info(path_cat, "Path builder is stopped, aborting path build..."); + log::info(logcat, "Path builder is stopped, aborting path build..."); return; } @@ -633,7 +630,7 @@ namespace llarp::path if (not _router.pathbuild_limiter().Attempt(edge)) { - log::warning(path_cat, "{} building too quickly to edge router {}", name(), edge); + log::warning(logcat, "{} building too quickly to edge router {}", name(), edge); return; } @@ -652,7 +649,7 @@ namespace llarp::path auto path = std::make_shared(_router, hops, get_weak(), std::move(path_shortName)); - log::info(path_cat, "{} building path -> {} : {}", name(), path->short_name(), path->HopsString()); + log::info(logcat, "{} building path -> {} : {}", name(), path->short_name(), path->HopsString()); oxenc::bt_list_producer frames; std::vector frame_str(path::MAX_LEN); @@ -743,27 +740,27 @@ namespace llarp::path // TODO: inform failure (what this means needs revisiting, badly) if (m.timed_out) { - log::warning(path_cat, "Path build request timed out!"); + log::warning(logcat, "Path build request timed out!"); path_build_failed(terminus, path, true); } else { oxenc::bt_dict_consumer d{m.body()}; auto status = d.require(messages::STATUS_KEY); - log::warning(path_cat, "Path build returned failure status: {}", status); + log::warning(logcat, "Path build returned failure status: {}", status); path_build_failed(terminus, path); } } catch (const std::exception& e) { - log::warning(path_cat, "Exception caught parsing path build response: {}", e.what()); + log::warning(logcat, "Exception caught parsing path build response: {}", e.what()); } }; if (not _router.send_control_message( path->upstream(), "path_build", std::move(frames).str(), std::move(response_cb))) { - log::warning(path_cat, "Error sending path_build control message"); + log::warning(logcat, "Error sending path_build control message"); path_build_failed(terminus, path); } } diff --git a/llarp/profiling.cpp b/llarp/profiling.cpp index 3533d39c8..9f603f2a4 100644 --- a/llarp/profiling.cpp +++ b/llarp/profiling.cpp @@ -285,7 +285,10 @@ namespace llarp void Profiling::BEncode(bt_dict_producer& dict) const { for (const auto& [r_id, profile] : _profiles) - profile.BEncode(dict.append_dict(r_id.ToView())); + { + auto subdict = dict.append_dict(r_id.ToView()); + profile.bt_encode(subdict); + } } void Profiling::BDecode(bt_dict_consumer dict) diff --git a/llarp/router/route_poker.cpp b/llarp/router/route_poker.cpp index bc8d9cc9a..e4a2899c4 100644 --- a/llarp/router/route_poker.cpp +++ b/llarp/router/route_poker.cpp @@ -6,6 +6,8 @@ namespace llarp { + static auto logcat = log::Cat("route_poker"); + void RoutePoker::add_route(oxen::quic::Address ip) { if (not is_up) diff --git a/llarp/router_contact.cpp b/llarp/router_contact.cpp index 21e449bf8..2c65d8785 100644 --- a/llarp/router_contact.cpp +++ b/llarp/router_contact.cpp @@ -24,7 +24,7 @@ namespace llarp if (not addr().is_public() and BLOCK_BOGONS) { auto err = "Unable to verify expired RemoteRC address!"; - log::info(logcat, err); + log::info(logcat, "{}", err); throw std::runtime_error{err}; } diff --git a/llarp/rpc/lokid_rpc_client.cpp b/llarp/rpc/lokid_rpc_client.cpp index 061615779..290a9929f 100644 --- a/llarp/rpc/lokid_rpc_client.cpp +++ b/llarp/rpc/lokid_rpc_client.cpp @@ -251,7 +251,7 @@ namespace llarp::rpc if (activeNodeList.empty()) { - LogWarn("got empty service node list, ignoring."); + log::warning(logcat, "Received empty service node list, ignoring."); return; } diff --git a/llarp/service/intro.cpp b/llarp/service/intro.cpp index dddea2b9e..7cc608172 100644 --- a/llarp/service/intro.cpp +++ b/llarp/service/intro.cpp @@ -76,6 +76,8 @@ namespace llarp::service log::warning(logcat, "{}", err); throw std::runtime_error{err}; } + + return true; } void Introduction::bt_decode(oxenc::bt_dict_consumer& btdc) diff --git a/llarp/session/base_session.cpp b/llarp/session/base_session.cpp index c4e9fbfcc..19b1451f0 100644 --- a/llarp/session/base_session.cpp +++ b/llarp/session/base_session.cpp @@ -10,6 +10,8 @@ namespace llarp::session { + static auto logcat = log::Cat("session.base"); + BaseSession::BaseSession( RouterID _router, Router& r, size_t hoplen, EndpointBase& parent, std::shared_ptr a) : PathHandler{r, NUM_SESSION_PATHS, hoplen}, diff --git a/llarp/util/logging/buffer.cpp b/llarp/util/logging/buffer.cpp index 240b2c237..0ffc1946b 100644 --- a/llarp/util/logging/buffer.cpp +++ b/llarp/util/logging/buffer.cpp @@ -24,18 +24,18 @@ namespace llarp else fmt::format_to(ins, "{:02x}", std::to_integer(b[k])); } - out.append(u8" ┃"); + out.append(" ┃"); for (size_t j = i; j < stop; j++) { auto c = std::to_integer(b[j]); if (c == 0x00) - out.append(u8"∅"); + out.append("∅"); else if (c < 0x20 || c > 0x7e) - out.append(u8"·"); + out.append("·"); else out.push_back(c); } - out.append(u8"┃"); + out.append("┃"); } return out; } diff --git a/llarp/vpn/linux.hpp b/llarp/vpn/linux.hpp index 36b8f5526..3bc6eed5f 100644 --- a/llarp/vpn/linux.hpp +++ b/llarp/vpn/linux.hpp @@ -24,6 +24,8 @@ namespace llarp::vpn { + static auto logcat = log::Cat("vpn.linux"); + struct in6_ifreq { in6_addr addr;