2021-03-09 22:24:35 +00:00
|
|
|
#pragma once
|
2019-01-13 16:30:07 +00:00
|
|
|
|
2021-03-09 22:24:35 +00:00
|
|
|
#include "router_id.hpp"
|
|
|
|
#include "util/buffer.hpp"
|
2018-06-18 22:03:50 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
/// proof of work
|
2019-05-24 02:01:36 +00:00
|
|
|
struct PoW
|
2018-06-18 22:03:50 +00:00
|
|
|
{
|
|
|
|
static constexpr size_t MaxSize = 128;
|
2020-04-07 18:38:56 +00:00
|
|
|
llarp_time_t timestamp = 0s;
|
|
|
|
llarp_time_t extendedLifetime = 0s;
|
|
|
|
AlignedBuffer<32> nonce;
|
2022-05-26 15:59:44 +00:00
|
|
|
uint64_t version = llarp::constants::proto_version;
|
2018-06-18 22:03:50 +00:00
|
|
|
|
2018-07-09 17:32:11 +00:00
|
|
|
~PoW();
|
|
|
|
|
2018-06-18 22:03:50 +00:00
|
|
|
bool
|
2019-05-28 19:45:08 +00:00
|
|
|
IsValid(llarp_time_t now) const;
|
2018-06-18 22:03:50 +00:00
|
|
|
|
|
|
|
bool
|
2019-05-24 02:01:36 +00:00
|
|
|
DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* val);
|
2018-07-09 17:32:11 +00:00
|
|
|
|
|
|
|
bool
|
2019-05-24 02:01:36 +00:00
|
|
|
BEncode(llarp_buffer_t* buf) const;
|
2018-06-21 12:55:02 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
operator==(const PoW& other) const
|
|
|
|
{
|
2018-07-09 17:32:11 +00:00
|
|
|
return timestamp == other.timestamp && version == other.version
|
2018-06-21 12:55:02 +00:00
|
|
|
&& extendedLifetime == other.extendedLifetime && nonce == other.nonce;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
operator!=(const PoW& other) const
|
|
|
|
{
|
|
|
|
return !(*this == other);
|
|
|
|
}
|
2018-07-18 20:58:16 +00:00
|
|
|
|
2019-02-24 23:46:37 +00:00
|
|
|
std::ostream&
|
|
|
|
print(std::ostream& stream, int level, int spaces) const;
|
2018-06-18 22:03:50 +00:00
|
|
|
};
|
2019-02-24 23:46:37 +00:00
|
|
|
|
|
|
|
inline std::ostream&
|
|
|
|
operator<<(std::ostream& out, const PoW& p)
|
|
|
|
{
|
|
|
|
return p.print(out, -1, -1);
|
|
|
|
}
|
2018-06-18 22:03:50 +00:00
|
|
|
} // namespace llarp
|