lokinet/llarp/router_version.hpp

76 lines
1.6 KiB
C++
Raw Normal View History

2020-01-25 16:29:01 +00:00
#ifndef LLARP_ROUTER_VERSION_HPP
#define LLARP_ROUTER_VERSION_HPP
#include <array>
#include <util/bencode.hpp>
2020-01-25 17:21:28 +00:00
#include <constants/version.hpp>
#include <constants/proto.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}};
int64_t m_ProtoVersion = LLARP_PROTO_VERSION;
2020-01-25 16:29:01 +00:00
};
inline std::ostream&
operator<<(std::ostream& out, const RouterVersion& rv)
{
return out << rv.ToString();
}
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
#endif