mirror of https://github.com/oxen-io/lokinet
Review fixes
- cleaned up include-what-you-use errors (mostly quoted includes) - misc fixespull/2213/head
parent
5c3467ecb0
commit
2abe2d9363
@ -1,56 +0,0 @@
|
||||
#include "pow.hpp"
|
||||
|
||||
#include "crypto/crypto.hpp"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
PoW::~PoW() = default;
|
||||
|
||||
bool
|
||||
PoW::decode_key(const llarp_buffer_t& /*k*/, llarp_buffer_t* /*val*/)
|
||||
{
|
||||
// TODO: implement me
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string
|
||||
PoW::bt_encode() const
|
||||
{
|
||||
return ""s;
|
||||
}
|
||||
|
||||
bool
|
||||
PoW::IsValid(llarp_time_t now) const
|
||||
{
|
||||
if (now - timestamp > extendedLifetime)
|
||||
return false;
|
||||
|
||||
ShortHash digest;
|
||||
auto buf = bt_encode();
|
||||
|
||||
// hash
|
||||
if (!crypto::shorthash(digest, reinterpret_cast<uint8_t*>(buf.data()), buf.size()))
|
||||
return false;
|
||||
// check bytes required
|
||||
uint32_t required = std::floor(std::log(extendedLifetime.count()));
|
||||
for (uint32_t idx = 0; idx < required; ++idx)
|
||||
{
|
||||
if (digest[idx])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string
|
||||
PoW::ToString() const
|
||||
{
|
||||
return fmt::format(
|
||||
"[PoW timestamp={} lifetime={} nonce={}]",
|
||||
timestamp.count(),
|
||||
extendedLifetime.count(),
|
||||
nonce);
|
||||
}
|
||||
|
||||
} // namespace llarp
|
@ -1,48 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "router_id.hpp"
|
||||
#include "util/buffer.hpp"
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
/// proof of work
|
||||
struct PoW
|
||||
{
|
||||
static constexpr size_t MaxSize = 128;
|
||||
llarp_time_t timestamp = 0s;
|
||||
llarp_time_t extendedLifetime = 0s;
|
||||
AlignedBuffer<32> nonce;
|
||||
uint64_t version = llarp::constants::proto_version;
|
||||
|
||||
~PoW();
|
||||
|
||||
bool
|
||||
IsValid(llarp_time_t now) const;
|
||||
|
||||
bool
|
||||
decode_key(const llarp_buffer_t& k, llarp_buffer_t* val);
|
||||
|
||||
std::string
|
||||
bt_encode() const;
|
||||
|
||||
bool
|
||||
operator==(const PoW& other) const
|
||||
{
|
||||
return timestamp == other.timestamp && version == other.version
|
||||
&& extendedLifetime == other.extendedLifetime && nonce == other.nonce;
|
||||
}
|
||||
|
||||
bool
|
||||
operator!=(const PoW& other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
std::string
|
||||
ToString() const;
|
||||
};
|
||||
|
||||
template <>
|
||||
constexpr inline bool IsToStringFormattable<PoW> = true;
|
||||
|
||||
} // namespace llarp
|
Loading…
Reference in New Issue