You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lokinet/llarp/router_version.hpp

69 lines
1.7 KiB
C++

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