lokinet/llarp/router_version.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

71 lines
1.5 KiB
C++

#pragma once
#include <array>
#include "util/bencode.hpp"
#include "constants/version.hpp"
#include "constants/proto.hpp"
#include "util/formattable.hpp"
namespace llarp
{
struct RouterVersion
{
using Version_t = std::array<uint16_t, 3>;
RouterVersion() = default;
explicit RouterVersion(const Version_t& routerVersion, uint64_t protoVersion);
bool
BEncode(llarp_buffer_t* buf) const;
bool
BDecode(llarp_buffer_t* buf);
/// return true if this router version is all zeros
bool
IsEmpty() const;
/// set to be empty
void
Clear();
std::string
ToString() const;
/// return true if the other router version is compatible with ours
bool
IsCompatableWith(const RouterVersion& other) const;
/// compare router versions
bool
operator<(const RouterVersion& other) const
{
return m_ProtoVersion < other.m_ProtoVersion || m_Version < other.m_Version;
}
bool
operator!=(const RouterVersion& other) const
{
return !(*this == other);
}
bool
operator==(const RouterVersion& other) const
{
return m_ProtoVersion == other.m_ProtoVersion && m_Version == other.m_Version;
}
private:
Version_t m_Version = {{0, 0, 0}};
int64_t m_ProtoVersion = llarp::constants::proto_version;
};
template <>
constexpr inline bool IsToStringFormattable<RouterVersion> = true;
static constexpr int64_t INVALID_VERSION = -1;
static const RouterVersion emptyRouterVersion({0, 0, 0}, INVALID_VERSION);
} // namespace llarp