Fix introset tests

pull/545/head
Michael 5 years ago
parent e36ddfb093
commit 3a8715d8e4
No known key found for this signature in database
GPG Key ID: 2D51757B47E2434C

@ -35,6 +35,7 @@ namespace llarp
{
std::set< service::IntroSet > found(valuesFound.begin(),
valuesFound.end());
// collect our local values if we haven't hit a limit
if(found.size() < 2)
{

@ -43,7 +43,7 @@ namespace llarp
if(key == "w")
{
W = std::make_unique< PoW >();
W = absl::make_optional< PoW >();
return W->BDecode(buf);
}
@ -151,7 +151,7 @@ namespace llarp
{
return false;
}
else if(W == nullptr)
else if(!W.has_value())
{
LogWarn("intro has too high expire time");
return false;
@ -195,7 +195,14 @@ namespace llarp
}
printer.printAttribute("T", T);
printer.printAttribute("W", W.get());
if(W)
{
printer.printAttribute("W", W.value());
}
else
{
printer.printAttribute("W", "NULL");
}
printer.printAttribute("V", version);
printer.printAttribute("Z", Z);

@ -10,6 +10,7 @@
#include <util/time.hpp>
#include <util/status.hpp>
#include <absl/types/optional.h>
#include <algorithm>
#include <functional>
#include <iostream>
@ -31,75 +32,9 @@ namespace llarp
PQPubKey K;
Tag topic;
llarp_time_t T = 0;
std::unique_ptr< PoW > W;
absl::optional< PoW > W;
Signature Z;
IntroSet() = default;
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)
{
}
IntroSet&
operator=(const IntroSet& other)
{
I.clear();
A = other.A;
I = other.I;
K = other.K;
T = other.T;
version = other.version;
topic = other.topic;
W.reset();
if(other.W)
{
W = std::make_unique< PoW >(*other.W);
}
Z = other.Z;
return *this;
}
bool
operator<(const IntroSet& other) const
{
return A < other.A;
}
bool
operator==(const IntroSet& other) const
{
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
operator!=(const IntroSet& other) const
{
return !(*this == other);
}
bool
OtherIsNewer(const IntroSet& other) const
{
@ -131,6 +66,27 @@ namespace llarp
ExtractStatus() const;
};
inline bool
operator<(const IntroSet& lhs, const IntroSet& rhs)
{
return lhs.A < rhs.A;
}
inline bool
operator==(const IntroSet& lhs, const IntroSet& rhs)
{
return std::tie(lhs.A, lhs.I, lhs.K, lhs.T, lhs.version, lhs.topic, lhs.W,
lhs.Z)
== std::tie(rhs.A, rhs.I, rhs.K, rhs.T, rhs.version, rhs.topic, rhs.W,
rhs.Z);
}
inline bool
operator!=(const IntroSet& lhs, const IntroSet& rhs)
{
return !(lhs == rhs);
}
inline std::ostream&
operator<<(std::ostream& out, const IntroSet& i)
{

@ -204,9 +204,13 @@ TEST_F(TestDhtTagLookup, send_reply)
{
tagLookup.valuesFound.clear();
tagLookup.valuesFound.emplace_back();
tagLookup.valuesFound.back().T = 1;
tagLookup.valuesFound.back().T = 1;
tagLookup.valuesFound.back().A.vanity[0] = 1;
tagLookup.valuesFound.back().A.UpdateAddr();
tagLookup.valuesFound.emplace_back();
tagLookup.valuesFound.back().T = 2;
tagLookup.valuesFound.back().T = 2;
tagLookup.valuesFound.back().A.vanity[0] = 2;
tagLookup.valuesFound.back().A.UpdateAddr();
// clang-format off
EXPECT_CALL(context, FindRandomIntroSetsWithTagExcluding(_, _, _)).Times(0);

Loading…
Cancel
Save