mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-03 23:15:52 +00:00
b81f7025c9
Replaces custom logging system with spdlog-based oxen logging. This commit mainly replaces the backend logging with the spdlog-based system, but doesn't (yet) convert all the existing LogWarn, etc. to use the new format-based logging. New logging statements will look like: llarp::log::warning(cat, "blah: {}", val); where `cat` should be set up in each .cpp or cluster of .cpp files, as described in the oxen-logging README. As part of spdlog we get fmt, which gives us nice format strings, where are applied generously in this commit. Making types printable now requires two steps: - add a ToString() method - add this specialization: template <> constexpr inline bool llarp::IsToStringFormattable<llarp::Whatever> = true; This will then allow the type to be printed as a "{}" value in a fmt::format string. This is applied to all our printable types here, and all of the `operator<<` are removed. This commit also: - replaces various uses of `operator<<` to ToString() - replaces various uses of std::stringstream with either fmt::format or plain std::string - Rename some to_string and toString() methods to ToString() for consistency (and to work with fmt) - Replace `stringify(...)` and `make_exception` usage with fmt::format (and remove stringify/make_exception from util/str.hpp).
62 lines
1.8 KiB
C++
62 lines
1.8 KiB
C++
#include "localserviceaddresslookup.hpp"
|
|
|
|
#include "context.hpp"
|
|
#include <llarp/dht/messages/gotintro.hpp>
|
|
#include <llarp/path/path_context.hpp>
|
|
#include <llarp/router/abstractrouter.hpp>
|
|
#include <llarp/routing/dht_message.hpp>
|
|
#include <llarp/util/logging.hpp>
|
|
|
|
namespace llarp
|
|
{
|
|
namespace dht
|
|
{
|
|
LocalServiceAddressLookup::LocalServiceAddressLookup(
|
|
const PathID_t& pathid,
|
|
uint64_t txid,
|
|
uint64_t relayOrder,
|
|
const Key_t& addr,
|
|
AbstractContext* ctx,
|
|
[[maybe_unused]] const Key_t& askpeer)
|
|
: ServiceAddressLookup(TXOwner{ctx->OurKey(), txid}, addr, ctx, relayOrder, nullptr)
|
|
, localPath(pathid)
|
|
{}
|
|
|
|
void
|
|
LocalServiceAddressLookup::SendReply()
|
|
{
|
|
auto path =
|
|
parent->GetRouter()->pathContext().GetByUpstream(parent->OurKey().as_array(), localPath);
|
|
if (!path)
|
|
{
|
|
llarp::LogWarn(
|
|
"did not send reply for relayed dht request, no such local path "
|
|
"for pathid=",
|
|
localPath);
|
|
return;
|
|
}
|
|
// pick newest if we have more than 1 result
|
|
if (valuesFound.size())
|
|
{
|
|
service::EncryptedIntroSet found;
|
|
for (const auto& introset : valuesFound)
|
|
{
|
|
if (found.OtherIsNewer(introset))
|
|
found = introset;
|
|
}
|
|
valuesFound.clear();
|
|
valuesFound.emplace_back(found);
|
|
}
|
|
routing::DHTMessage msg;
|
|
msg.M.emplace_back(new GotIntroMessage(valuesFound, whoasked.txid));
|
|
if (!path->SendRoutingMessage(msg, parent->GetRouter()))
|
|
{
|
|
llarp::LogWarn(
|
|
"failed to send routing message when informing result of dht "
|
|
"request, pathid=",
|
|
localPath);
|
|
}
|
|
}
|
|
} // namespace dht
|
|
} // namespace llarp
|