lokinet/include/llarp/pow.hpp

51 lines
1.1 KiB
C++
Raw Normal View History

2018-06-18 22:03:50 +00:00
#ifndef LLARP_POW_HPP
#define LLARP_POW_HPP
#include <llarp/crypto.h>
2018-07-09 17:32:11 +00:00
#include <llarp/bencode.hpp>
2018-06-18 22:03:50 +00:00
#include <llarp/router_id.hpp>
namespace llarp
{
/// proof of work
2018-07-09 17:32:11 +00:00
struct PoW : public IBEncodeMessage
2018-06-18 22:03:50 +00:00
{
static constexpr size_t MaxSize = 128;
2018-07-09 17:32:11 +00:00
uint64_t timestamp = 0;
uint32_t extendedLifetime = 0;
2018-06-21 12:55:02 +00:00
AlignedBuffer< 32 > nonce;
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
2018-07-09 17:32:11 +00:00
IsValid(llarp_shorthash_func hashfunc) const;
2018-06-18 22:03:50 +00:00
bool
2018-07-09 17:32:11 +00:00
DecodeKey(llarp_buffer_t k, llarp_buffer_t* val);
bool
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);
}
friend std::ostream&
operator<<(std::ostream& out, const PoW& p)
{
return out << "[pow timestamp=" << p.timestamp
<< " lifetime=" << p.extendedLifetime << " nonce=" << p.nonce
<< "]";
}
2018-06-18 22:03:50 +00:00
};
} // namespace llarp
#endif