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

62 lines
1.2 KiB
C++

4 years ago
#ifndef LLARP_ROUTER_VERSION_HPP
#define LLARP_ROUTER_VERSION_HPP
#include <array>
#include <util/bencode.hpp>
#include <constants/version.hpp>
#include <constants/proto.hpp>
4 years ago
namespace llarp
{
struct RouterVersion
4 years ago
{
using Version_t = std::array< uint16_t, 3 >;
4 years ago
RouterVersion() = default;
explicit RouterVersion(const Version_t& routerVersion,
uint64_t protoVersion);
4 years ago
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;
}
private:
Version_t m_Version = {0, 0, 0};
uint64_t m_ProtoVersion = LLARP_PROTO_VERSION;
4 years ago
};
inline std::ostream&
operator<<(std::ostream& out, const RouterVersion& rv)
{
return out << rv.ToString();
}
} // namespace llarp
#endif