2018-06-19 00:03:50 +02:00
|
|
|
#ifndef LLARP_POW_HPP
|
|
|
|
#define LLARP_POW_HPP
|
2019-01-13 17:30:07 +01:00
|
|
|
|
2019-01-13 15:00:50 +01:00
|
|
|
#include <crypto/crypto.hpp>
|
2018-12-12 03:52:51 +01:00
|
|
|
#include <router_id.hpp>
|
2019-01-10 20:41:51 +01:00
|
|
|
#include <util/bencode.hpp>
|
2018-06-19 00:03:50 +02:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
/// proof of work
|
2018-11-05 12:27:12 +01:00
|
|
|
struct PoW final : public IBEncodeMessage
|
2018-06-19 00:03:50 +02:00
|
|
|
{
|
|
|
|
static constexpr size_t MaxSize = 128;
|
2018-07-09 19:32:11 +02:00
|
|
|
uint64_t timestamp = 0;
|
|
|
|
uint32_t extendedLifetime = 0;
|
2018-06-21 14:55:02 +02:00
|
|
|
AlignedBuffer< 32 > nonce;
|
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
|
2018-12-11 01:53:11 +01:00
|
|
|
IsValid(shorthash_func hashfunc, llarp_time_t now) const;
|
2018-06-19 00:03:50 +02:00
|
|
|
|
|
|
|
bool
|
2019-02-05 01:41:33 +01:00
|
|
|
DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* val) override;
|
2018-07-09 19:32:11 +02:00
|
|
|
|
|
|
|
bool
|
2018-11-05 12:27:12 +01:00
|
|
|
BEncode(llarp_buffer_t* buf) const override;
|
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);
|
|
|
|
}
|
2018-07-18 22:58:16 +02:00
|
|
|
|
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
|
|
|
|
|
2018-11-05 12:27:12 +01:00
|
|
|
#endif
|