lokinet/llarp/dht/key.hpp

83 lines
1.5 KiB
C++
Raw Normal View History

#ifndef LLARP_DHT_KEY_HPP
#define LLARP_DHT_KEY_HPP
#include <util/aligned.hpp>
2019-07-17 14:51:42 +00:00
#include <router_id.hpp>
#include <array>
namespace llarp
{
namespace dht
{
struct Key_t : public AlignedBuffer< 32 >
{
explicit Key_t(const byte_t* buf) : AlignedBuffer< SIZE >(buf)
{
}
2019-08-02 09:27:27 +00:00
explicit Key_t(const Data& data) : AlignedBuffer< SIZE >(data)
{
}
2019-08-02 09:27:27 +00:00
explicit Key_t(const AlignedBuffer< SIZE >& data)
: AlignedBuffer< SIZE >(data)
{
}
Key_t() : AlignedBuffer< SIZE >()
{
}
2019-07-17 12:25:51 +00:00
/// get snode address string
std::string
SNode() const
{
const RouterID rid{as_array()};
return rid.ToString();
}
2019-08-19 21:26:34 +00:00
std::string
ToString() const
{
return SNode();
}
Key_t
operator^(const Key_t& other) const
{
Key_t dist;
std::transform(begin(), end(), other.begin(), dist.begin(),
std::bit_xor< byte_t >());
return dist;
}
2018-11-01 12:47:14 +00:00
bool
operator==(const Key_t& other) const
{
2018-12-30 18:56:28 +00:00
return as_array() == other.as_array();
2018-11-01 12:47:14 +00:00
}
bool
operator!=(const Key_t& other) const
{
2018-12-30 18:56:28 +00:00
return as_array() != other.as_array();
2018-11-01 12:47:14 +00:00
}
bool
operator<(const Key_t& other) const
{
2018-12-30 18:56:28 +00:00
return as_array() < other.as_array();
2018-08-10 03:51:38 +00:00
}
bool
operator>(const Key_t& other) const
{
2018-12-30 18:56:28 +00:00
return as_array() > other.as_array();
}
};
2018-07-17 04:37:50 +00:00
} // namespace dht
} // namespace llarp
#endif