lokinet/llarp/router_version.hpp

71 lines
1.5 KiB
C++
Raw Normal View History

#pragma once
2020-01-25 16:29:01 +00:00
#include <array>
#include "util/bencode.hpp"
#include "constants/version.hpp"
#include "constants/proto.hpp"
#include "util/formattable.hpp"
2020-01-25 16:29:01 +00:00
namespace llarp
{
2020-01-25 17:21:28 +00:00
struct RouterVersion
2020-01-25 16:29:01 +00:00
{
using Version_t = std::array<uint16_t, 3>;
2020-01-25 17:21:28 +00:00
2020-01-25 16:29:01 +00:00
RouterVersion() = default;
explicit RouterVersion(const Version_t& routerVersion, uint64_t protoVersion);
2020-01-25 16:29:01 +00:00
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;
2020-01-25 17:21:28 +00:00
/// 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;
2020-01-25 17:21:28 +00:00
}
2020-01-25 17:39:00 +00:00
bool
2020-01-25 17:41:34 +00:00
operator!=(const RouterVersion& other) const
2020-01-25 17:39:00 +00:00
{
return !(*this == other);
}
2020-01-25 17:38:12 +00:00
bool
operator==(const RouterVersion& other) const
{
return m_ProtoVersion == other.m_ProtoVersion && m_Version == other.m_Version;
2020-01-25 17:38:12 +00:00
}
2020-01-25 17:21:28 +00:00
private:
Version_t m_Version = {{0, 0, 0}};
2022-05-26 15:59:44 +00:00
int64_t m_ProtoVersion = llarp::constants::proto_version;
2020-01-25 16:29:01 +00:00
};
template <>
constexpr inline bool IsToStringFormattable<RouterVersion> = true;
static constexpr int64_t INVALID_VERSION = -1;
static const RouterVersion emptyRouterVersion({0, 0, 0}, INVALID_VERSION);
2020-01-25 16:29:01 +00:00
} // namespace llarp