1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00
lokinet/llarp/pow.hpp

54 lines
1 KiB
C++
Raw Normal View History

2018-06-19 00:03:50 +02:00
#ifndef LLARP_POW_HPP
#define LLARP_POW_HPP
#include <router_id.hpp>
2019-05-24 04:01:36 +02:00
#include <util/buffer.hpp>
2018-06-19 00:03:50 +02:00
namespace llarp
{
/// proof of work
2019-05-24 04:01:36 +02:00
struct PoW
2018-06-19 00:03:50 +02:00
{
static constexpr size_t MaxSize = 128;
llarp_time_t timestamp = 0s;
llarp_time_t extendedLifetime = 0s;
AlignedBuffer<32> nonce;
2019-05-24 04:01:36 +02:00
uint64_t version = LLARP_PROTO_VERSION;
2018-06-19 00:03:50 +02:00
2018-07-09 19:32:11 +02:00
~PoW();
2018-06-19 00:03:50 +02:00
bool
IsValid(llarp_time_t now) const;
2018-06-19 00:03:50 +02:00
bool
2019-05-24 04:01:36 +02:00
DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* val);
2018-07-09 19:32:11 +02:00
bool
2019-05-24 04:01:36 +02:00
BEncode(llarp_buffer_t* buf) const;
2018-06-21 14:55:02 +02:00
bool
operator==(const PoW& other) const
{
2018-07-09 19:32:11 +02:00
return timestamp == other.timestamp && version == other.version
2018-06-21 14:55:02 +02:00
&& extendedLifetime == other.extendedLifetime && nonce == other.nonce;
}
bool
operator!=(const PoW& other) const
{
return !(*this == other);
}
2019-02-25 00:46:37 +01:00
std::ostream&
print(std::ostream& stream, int level, int spaces) const;
2018-06-19 00:03:50 +02:00
};
2019-02-25 00:46:37 +01:00
inline std::ostream&
operator<<(std::ostream& out, const PoW& p)
{
return p.print(out, -1, -1);
}
2018-06-19 00:03:50 +02:00
} // namespace llarp
#endif