2018-07-09 17:32:11 +00:00
|
|
|
#ifndef LLARP_SERVICE_INTROSET_HPP
|
|
|
|
#define LLARP_SERVICE_INTROSET_HPP
|
2018-12-12 02:52:51 +00:00
|
|
|
|
2019-01-13 16:30:07 +00:00
|
|
|
#include <crypto/types.hpp>
|
2018-12-12 02:52:51 +00:00
|
|
|
#include <pow.hpp>
|
2018-12-12 02:15:08 +00:00
|
|
|
#include <service/Info.hpp>
|
|
|
|
#include <service/Intro.hpp>
|
|
|
|
#include <service/tag.hpp>
|
2019-01-10 19:41:51 +00:00
|
|
|
#include <util/bencode.hpp>
|
|
|
|
#include <util/time.hpp>
|
2019-02-08 19:43:25 +00:00
|
|
|
#include <util/status.hpp>
|
2018-07-09 17:32:11 +00:00
|
|
|
|
2018-09-29 08:16:54 +00:00
|
|
|
#include <algorithm>
|
2019-01-22 01:14:02 +00:00
|
|
|
#include <functional>
|
2018-12-12 02:15:08 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <vector>
|
2018-07-09 17:32:11 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
2019-01-13 16:30:07 +00:00
|
|
|
struct Crypto;
|
|
|
|
|
2018-07-09 17:32:11 +00:00
|
|
|
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);
|
2019-02-08 19:43:25 +00:00
|
|
|
struct IntroSet final : public llarp::IBEncodeMessage,
|
|
|
|
public util::IStateful
|
2018-07-09 17:32:11 +00:00
|
|
|
{
|
2019-02-11 17:14:43 +00:00
|
|
|
util::StatusObject
|
|
|
|
ExtractStatus() const override;
|
2019-02-08 19:43:25 +00:00
|
|
|
|
2018-07-09 17:32:11 +00:00
|
|
|
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-09-23 13:57:21 +00:00
|
|
|
llarp_time_t T = 0;
|
|
|
|
llarp::PoW* W = nullptr;
|
2018-07-09 17:32:11 +00:00
|
|
|
llarp::Signature Z;
|
|
|
|
|
2018-08-10 21:34:11 +00:00
|
|
|
IntroSet() = default;
|
|
|
|
|
2018-11-07 15:30:22 +00:00
|
|
|
IntroSet(IntroSet&& other) : IBEncodeMessage(other.version)
|
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-09-23 13:57:21 +00:00
|
|
|
T = std::move(other.T);
|
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);
|
|
|
|
}
|
|
|
|
|
2018-11-07 15:30:22 +00:00
|
|
|
IntroSet(const IntroSet& other) : IBEncodeMessage(other.version)
|
2018-08-10 21:34:11 +00:00
|
|
|
{
|
|
|
|
A = other.A;
|
|
|
|
I = other.I;
|
2018-08-13 23:22:31 +00:00
|
|
|
K = other.K;
|
2018-09-23 13:57:21 +00:00
|
|
|
T = other.T;
|
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)
|
|
|
|
{
|
2018-10-01 17:16:15 +00:00
|
|
|
I.clear();
|
2018-07-09 17:32:11 +00:00
|
|
|
A = other.A;
|
|
|
|
I = other.I;
|
2018-08-13 23:22:31 +00:00
|
|
|
K = other.K;
|
2018-09-23 13:57:21 +00:00
|
|
|
T = other.T;
|
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)
|
2018-10-10 11:48:44 +00:00
|
|
|
{
|
2018-07-09 17:32:11 +00:00
|
|
|
delete W;
|
2018-10-10 11:48:44 +00:00
|
|
|
W = nullptr;
|
|
|
|
}
|
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-10-11 11:41:10 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
operator!=(const IntroSet& other) const
|
|
|
|
{
|
|
|
|
return !(*this == other);
|
|
|
|
}
|
|
|
|
|
2018-09-10 17:37:28 +00:00
|
|
|
bool
|
|
|
|
OtherIsNewer(const IntroSet& other) const
|
|
|
|
{
|
2018-09-23 13:57:21 +00:00
|
|
|
return T < other.T;
|
2018-09-10 17:37:28 +00:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2018-09-23 13:57:21 +00:00
|
|
|
out << intro << ", ";
|
2018-07-09 17:32:11 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|
2018-09-23 13:57:21 +00:00
|
|
|
out << " T=" << i.T;
|
2018-07-18 20:58:16 +00:00
|
|
|
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
|
2018-10-11 11:41:10 +00:00
|
|
|
GetNewestIntroExpiration() const;
|
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
|
2018-11-05 11:27:12 +00:00
|
|
|
BEncode(llarp_buffer_t* buf) const override;
|
2018-07-09 17:32:11 +00:00
|
|
|
|
|
|
|
bool
|
2019-02-05 00:41:33 +00:00
|
|
|
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf) override;
|
2018-07-09 17:32:11 +00:00
|
|
|
|
|
|
|
bool
|
2018-12-11 00:53:11 +00:00
|
|
|
Verify(llarp::Crypto* crypto, llarp_time_t now) const;
|
2018-07-09 17:32:11 +00:00
|
|
|
};
|
2019-01-22 01:14:02 +00:00
|
|
|
|
|
|
|
using IntroSetLookupHandler =
|
|
|
|
std::function< void(const std::vector< IntroSet >&) >;
|
|
|
|
|
2018-07-09 17:32:11 +00:00
|
|
|
} // namespace service
|
|
|
|
} // namespace llarp
|
|
|
|
|
2018-09-09 11:23:21 +00:00
|
|
|
#endif
|