2018-07-09 17:32:11 +00:00
|
|
|
#ifndef LLARP_SERVICE_INTROSET_HPP
|
|
|
|
#define LLARP_SERVICE_INTROSET_HPP
|
2018-07-18 00:25:24 +00:00
|
|
|
#include <llarp/time.h>
|
2018-07-09 17:32:11 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <llarp/bencode.hpp>
|
|
|
|
#include <llarp/crypto.hpp>
|
|
|
|
#include <llarp/pow.hpp>
|
|
|
|
#include <llarp/service/Info.hpp>
|
|
|
|
#include <llarp/service/Intro.hpp>
|
2018-07-17 07:30:03 +00:00
|
|
|
#include <llarp/service/tag.hpp>
|
2018-07-09 17:32:11 +00:00
|
|
|
|
2018-07-20 04:50:28 +00:00
|
|
|
#include <vector>
|
2018-07-09 17:32:11 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace service
|
|
|
|
{
|
2018-08-13 23:22:31 +00:00
|
|
|
constexpr std::size_t MAX_INTROSET_SIZE = 4096;
|
2018-09-21 15:24:00 +00:00
|
|
|
// 10 seconds clock skew permitted for introset expiration
|
|
|
|
constexpr llarp_time_t MAX_INTROSET_TIME_DELTA = (10 * 1000);
|
2018-07-09 17:32:11 +00:00
|
|
|
struct IntroSet : public llarp::IBEncodeMessage
|
|
|
|
{
|
|
|
|
ServiceInfo A;
|
2018-07-20 04:50:28 +00:00
|
|
|
std::vector< Introduction > I;
|
2018-08-13 23:22:31 +00:00
|
|
|
PQPubKey K;
|
2018-07-17 07:30:03 +00:00
|
|
|
Tag topic;
|
2018-07-09 17:32:11 +00:00
|
|
|
llarp::PoW* W = nullptr;
|
|
|
|
llarp::Signature Z;
|
|
|
|
|
2018-08-10 21:34:11 +00:00
|
|
|
IntroSet() = default;
|
|
|
|
|
2018-09-09 11:23:21 +00:00
|
|
|
IntroSet(IntroSet&& other)
|
2018-08-10 21:34:11 +00:00
|
|
|
{
|
|
|
|
A = std::move(other.A);
|
|
|
|
I = std::move(other.I);
|
2018-08-13 23:22:31 +00:00
|
|
|
K = std::move(other.K);
|
2018-08-10 21:34:11 +00:00
|
|
|
version = std::move(other.version);
|
|
|
|
topic = std::move(other.topic);
|
|
|
|
W = std::move(other.W);
|
|
|
|
Z = std::move(other.Z);
|
|
|
|
}
|
|
|
|
|
|
|
|
IntroSet(const IntroSet& other)
|
|
|
|
{
|
|
|
|
A = other.A;
|
|
|
|
I = other.I;
|
2018-08-13 23:22:31 +00:00
|
|
|
K = other.K;
|
2018-08-10 21:34:11 +00:00
|
|
|
version = other.version;
|
|
|
|
topic = other.topic;
|
|
|
|
if(other.W)
|
|
|
|
W = new llarp::PoW(*other.W);
|
|
|
|
Z = other.Z;
|
|
|
|
}
|
|
|
|
|
2018-07-09 17:32:11 +00:00
|
|
|
~IntroSet();
|
|
|
|
|
|
|
|
IntroSet&
|
|
|
|
operator=(const IntroSet& other)
|
|
|
|
{
|
|
|
|
A = other.A;
|
|
|
|
I = other.I;
|
2018-08-13 23:22:31 +00:00
|
|
|
K = other.K;
|
2018-07-09 17:32:11 +00:00
|
|
|
version = other.version;
|
2018-07-18 20:58:16 +00:00
|
|
|
topic = other.topic;
|
2018-07-09 17:32:11 +00:00
|
|
|
if(W)
|
|
|
|
delete W;
|
2018-08-10 03:51:38 +00:00
|
|
|
if(other.W)
|
|
|
|
W = new llarp::PoW(*other.W);
|
2018-07-09 17:32:11 +00:00
|
|
|
Z = other.Z;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2018-07-18 03:10:21 +00:00
|
|
|
bool
|
|
|
|
operator<(const IntroSet& other) const
|
|
|
|
{
|
2018-07-19 04:58:39 +00:00
|
|
|
return A < other.A;
|
2018-07-18 03:10:21 +00:00
|
|
|
}
|
|
|
|
|
2018-09-10 17:37:28 +00:00
|
|
|
bool
|
|
|
|
OtherIsNewer(const IntroSet& other) const
|
|
|
|
{
|
|
|
|
return GetNewestIntroExpiration() < other.GetNewestIntroExpiration();
|
|
|
|
}
|
|
|
|
|
2018-07-09 17:32:11 +00:00
|
|
|
friend std::ostream&
|
|
|
|
operator<<(std::ostream& out, const IntroSet& i)
|
|
|
|
{
|
|
|
|
out << "A=[" << i.A << "] I=[";
|
|
|
|
for(const auto& intro : i.I)
|
|
|
|
{
|
|
|
|
out << intro << ",";
|
|
|
|
}
|
2018-07-17 07:30:03 +00:00
|
|
|
out << "]";
|
2018-08-13 23:22:31 +00:00
|
|
|
out << "K=" << i.K;
|
2018-07-17 07:30:03 +00:00
|
|
|
auto topic = i.topic.ToString();
|
|
|
|
if(topic.size())
|
|
|
|
{
|
|
|
|
out << " topic=" << topic;
|
|
|
|
}
|
2018-07-18 20:58:16 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
out << " topic=" << i.topic;
|
|
|
|
}
|
|
|
|
if(i.W)
|
|
|
|
{
|
|
|
|
out << " W=" << *i.W;
|
|
|
|
}
|
2018-07-17 07:30:03 +00:00
|
|
|
return out << " V=" << i.version << " Z=" << i.Z;
|
2018-07-09 17:32:11 +00:00
|
|
|
}
|
|
|
|
|
2018-09-10 16:36:36 +00:00
|
|
|
llarp_time_t
|
|
|
|
GetNewestIntroExpiration() const
|
2018-08-10 21:34:11 +00:00
|
|
|
{
|
2018-09-10 16:36:36 +00:00
|
|
|
llarp_time_t t = 0;
|
2018-08-10 21:34:11 +00:00
|
|
|
for(const auto& intro : I)
|
2018-09-10 16:36:36 +00:00
|
|
|
t = std::max(intro.expiresAt, t);
|
|
|
|
return t;
|
2018-08-10 21:34:11 +00:00
|
|
|
}
|
|
|
|
|
2018-07-17 06:17:13 +00:00
|
|
|
bool
|
2018-07-18 22:50:05 +00:00
|
|
|
HasExpiredIntros(llarp_time_t now) const;
|
2018-07-17 06:17:13 +00:00
|
|
|
|
2018-07-18 00:25:24 +00:00
|
|
|
bool
|
|
|
|
IsExpired(llarp_time_t now) const;
|
|
|
|
|
2018-07-09 17:32:11 +00:00
|
|
|
bool
|
|
|
|
BEncode(llarp_buffer_t* buf) const;
|
|
|
|
|
|
|
|
bool
|
|
|
|
DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf);
|
|
|
|
|
|
|
|
bool
|
2018-09-20 11:27:18 +00:00
|
|
|
Verify(llarp_crypto* crypto) const;
|
2018-07-09 17:32:11 +00:00
|
|
|
};
|
|
|
|
} // namespace service
|
|
|
|
} // namespace llarp
|
|
|
|
|
2018-09-09 11:23:21 +00:00
|
|
|
#endif
|