mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-10-31 09:20:21 +00:00
7caa87862e
All #ifndef guards on headers have been removed, I think, in favor of #pragma once Headers are now included as `#include "filename"` if the included file resides in the same directory as the file including it, or any subdirectory therein. Otherwise they are included as `#include <project/top/dir/relative/path/filename>` The above does not include system/os headers.
77 lines
1.5 KiB
C++
77 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include <llarp/util/aligned.hpp>
|
|
#include <llarp/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)
|
|
{}
|
|
|
|
explicit Key_t(const Data& data) : AlignedBuffer<SIZE>(data)
|
|
{}
|
|
|
|
explicit Key_t(const AlignedBuffer<SIZE>& data) : AlignedBuffer<SIZE>(data)
|
|
{}
|
|
|
|
Key_t() : AlignedBuffer<SIZE>()
|
|
{}
|
|
|
|
/// get snode address string
|
|
std::string
|
|
SNode() const
|
|
{
|
|
const RouterID rid{as_array()};
|
|
return rid.ToString();
|
|
}
|
|
|
|
util::StatusObject
|
|
ExtractStatus() const;
|
|
|
|
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;
|
|
}
|
|
|
|
bool
|
|
operator==(const Key_t& other) const
|
|
{
|
|
return as_array() == other.as_array();
|
|
}
|
|
|
|
bool
|
|
operator!=(const Key_t& other) const
|
|
{
|
|
return as_array() != other.as_array();
|
|
}
|
|
|
|
bool
|
|
operator<(const Key_t& other) const
|
|
{
|
|
return as_array() < other.as_array();
|
|
}
|
|
|
|
bool
|
|
operator>(const Key_t& other) const
|
|
{
|
|
return as_array() > other.as_array();
|
|
}
|
|
};
|
|
} // namespace dht
|
|
} // namespace llarp
|