2021-03-09 22:24:35 +00:00
|
|
|
#pragma once
|
2020-01-25 16:29:01 +00:00
|
|
|
|
|
|
|
#include <array>
|
2021-03-09 22:24:35 +00:00
|
|
|
#include "util/bencode.hpp"
|
|
|
|
#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
|
|
|
{
|
2020-04-07 18:38:56 +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;
|
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
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
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
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
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
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:
|
2020-04-07 18:38:56 +00:00
|
|
|
Version_t m_Version = {{0, 0, 0}};
|
2020-01-31 20:23:48 +00:00
|
|
|
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();
|
|
|
|
}
|
2020-01-31 20:23:48 +00:00
|
|
|
|
|
|
|
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
|