lokinet/llarp/dht/txowner.hpp

65 lines
1.3 KiB
C++
Raw Normal View History

2019-01-19 19:16:40 +01:00
#ifndef LLARP_DHT_TXOWNER_HPP
#define LLARP_DHT_TXOWNER_HPP
#include <dht/key.hpp>
2019-02-11 18:14:43 +01:00
#include <util/status.hpp>
2019-01-19 19:16:40 +01:00
#include <cstdint>
namespace llarp
{
namespace dht
{
2019-04-19 17:10:26 +02:00
struct TXOwner
2019-01-19 19:16:40 +01:00
{
Key_t node;
uint64_t txid = 0;
TXOwner() = default;
2019-01-19 19:16:40 +01:00
TXOwner(const TXOwner&) = default;
TXOwner(TXOwner&&) = default;
2019-01-19 19:16:40 +01:00
TXOwner&
operator=(const TXOwner&) = default;
TXOwner(const Key_t& k, uint64_t id) : node(k), txid(id)
{
}
2019-02-11 18:14:43 +01:00
util::StatusObject
2019-04-19 17:10:26 +02:00
ExtractStatus() const
2019-02-11 18:14:43 +01:00
{
util::StatusObject obj{
{"txid", txid},
{"node", node.ToHex()},
};
return obj;
}
2019-01-19 19:16:40 +01:00
bool
operator==(const TXOwner& other) const
{
return std::tie(txid, node) == std::tie(other.txid, other.node);
}
bool
operator<(const TXOwner& other) const
{
return std::tie(txid, node) < std::tie(other.txid, other.node);
}
struct Hash
{
std::size_t
operator()(const TXOwner& o) const noexcept
{
std::size_t sz2;
2020-05-21 16:26:51 +02:00
memcpy(&sz2, o.node.data(), sizeof(std::size_t));
2019-01-19 19:16:40 +01:00
return o.txid ^ (sz2 << 1);
}
};
};
} // namespace dht
} // namespace llarp
#endif