Merge pull request #539 from michael-loki/introset_unique_pow

Make IntroSet PoW be a unique_ptr
pull/540/head
Jeff 5 years ago committed by GitHub
commit 385dfe68bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -6,12 +6,6 @@ namespace llarp
{
namespace service
{
IntroSet::~IntroSet()
{
if(W)
delete W;
}
util::StatusObject
IntroSet::ExtractStatus() const
{
@ -49,9 +43,7 @@ namespace llarp
if(key == "w")
{
if(W)
delete W;
W = new PoW();
W = std::make_unique< PoW >();
return W->BDecode(buf);
}
@ -156,7 +148,9 @@ namespace llarp
{
if(W
&& intro.expiresAt - W->extendedLifetime > path::default_lifetime)
{
return false;
}
else if(W == nullptr)
{
llarp::LogWarn("intro has too high expire time");
@ -201,7 +195,7 @@ namespace llarp
}
printer.printAttribute("T", T);
printer.printAttribute("W", W);
printer.printAttribute("W", W.get());
printer.printAttribute("V", version);
printer.printAttribute("Z", Z);

@ -24,48 +24,32 @@ namespace llarp
constexpr std::size_t MAX_INTROSET_SIZE = 4096;
// 10 seconds clock skew permitted for introset expiration
constexpr llarp_time_t MAX_INTROSET_TIME_DELTA = (10 * 1000);
struct IntroSet final : public llarp::IBEncodeMessage
struct IntroSet final : public IBEncodeMessage
{
util::StatusObject
ExtractStatus() const;
ServiceInfo A;
std::vector< Introduction > I;
PQPubKey K;
Tag topic;
llarp_time_t T = 0;
llarp::PoW* W = nullptr;
llarp::Signature Z;
std::unique_ptr< PoW > W;
Signature Z;
IntroSet() = default;
IntroSet(IntroSet&& other) : IBEncodeMessage(other.version)
IntroSet(IntroSet&& other) = default;
IntroSet(const IntroSet& other)
: IBEncodeMessage(other.version)
, A(other.A)
, I(other.I)
, K(other.K)
, topic(other.topic)
, T(other.T)
, W(std::make_unique< PoW >(*other.W))
, Z(other.Z)
{
A = std::move(other.A);
I = std::move(other.I);
K = std::move(other.K);
T = std::move(other.T);
version = std::move(other.version);
topic = std::move(other.topic);
W = std::move(other.W);
Z = std::move(other.Z);
}
IntroSet(const IntroSet& other) : IBEncodeMessage(other.version)
{
A = other.A;
I = other.I;
K = other.K;
T = other.T;
version = other.version;
topic = other.topic;
if(other.W)
W = new llarp::PoW(*other.W);
Z = other.Z;
}
~IntroSet();
IntroSet&
operator=(const IntroSet& other)
{
@ -76,13 +60,11 @@ namespace llarp
T = other.T;
version = other.version;
topic = other.topic;
if(W)
W.reset();
if(other.W)
{
delete W;
W = nullptr;
W = std::make_unique< PoW >(*other.W);
}
if(other.W)
W = new llarp::PoW(*other.W);
Z = other.Z;
return *this;
}
@ -96,9 +78,20 @@ namespace llarp
bool
operator==(const IntroSet& other) const
{
return A == other.A && I == other.I && K == other.K && T == other.T
&& version == other.version && topic == other.topic && W == other.W
&& Z == other.Z;
if(std::tie(A, I, K, T, version, topic, Z)
!= std::tie(other.A, other.I, other.K, other.T, other.version,
other.topic, other.Z))
{
return false;
}
else if(W && other.W) // both PoW have a valid ptr
{
return *W == *other.W;
}
else
{
return W == other.W; // if one is null, verify the other is null
}
}
bool
@ -132,7 +125,10 @@ namespace llarp
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf) override;
bool
Verify(llarp::Crypto* crypto, llarp_time_t now) const;
Verify(Crypto* crypto, llarp_time_t now) const;
util::StatusObject
ExtractStatus() const;
};
inline std::ostream&

Loading…
Cancel
Save