lokinet/llarp/dht/key.hpp
Jason Rhinelander b81f7025c9
Replace logging with oxen-logger
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).
2022-07-15 22:17:59 -03:00

78 lines
1.5 KiB
C++

#pragma once
#include <llarp/util/aligned.hpp>
#include <llarp/router_id.hpp>
#include <llarp/util/formattable.hpp>
#include <array>
namespace llarp
{
namespace dht
{
struct Key_t : public AlignedBuffer<32>
{
explicit Key_t(const byte_t* buf) : AlignedBuffer<SIZE>(buf)
{}
explicit Key_t(const Data& data) : AlignedBuffer<SIZE>(data)
{}
explicit Key_t(const AlignedBuffer<SIZE>& data) : AlignedBuffer<SIZE>(data)
{}
Key_t() : AlignedBuffer<SIZE>()
{}
/// get snode address string
std::string
SNode() const
{
const RouterID rid{as_array()};
return rid.ToString();
}
util::StatusObject
ExtractStatus() const;
std::string
ToString() const
{
return SNode();
}
Key_t
operator^(const Key_t& other) const
{
Key_t dist;
std::transform(begin(), end(), other.begin(), dist.begin(), std::bit_xor<byte_t>());
return dist;
}
bool
operator==(const Key_t& other) const
{
return as_array() == other.as_array();
}
bool
operator!=(const Key_t& other) const
{
return as_array() != other.as_array();
}
bool
operator<(const Key_t& other) const
{
return as_array() < other.as_array();
}
bool
operator>(const Key_t& other) const
{
return as_array() > other.as_array();
}
};
} // namespace dht
} // namespace llarp