2019-04-22 18:35:19 +00:00
|
|
|
#ifndef LLARP_SERVICE_INTRO_SET_HPP
|
|
|
|
#define LLARP_SERVICE_INTRO_SET_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>
|
2019-04-22 18:35:19 +00:00
|
|
|
#include <service/info.hpp>
|
|
|
|
#include <service/intro.hpp>
|
2018-12-12 02:15:08 +00:00
|
|
|
#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
|
|
|
|
2019-04-23 09:25:03 +00:00
|
|
|
#include <absl/types/optional.h>
|
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-04-22 17:55:04 +00:00
|
|
|
struct IntroSet final : public IBEncodeMessage
|
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;
|
2019-04-23 09:25:03 +00:00
|
|
|
absl::optional< PoW > W;
|
2019-04-22 17:55:04 +00:00
|
|
|
Signature Z;
|
2018-07-09 17:32:11 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-02-24 23:46:37 +00:00
|
|
|
std::ostream&
|
|
|
|
print(std::ostream& stream, int level, int spaces) const;
|
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
|
2019-04-22 17:55:04 +00:00
|
|
|
Verify(Crypto* crypto, llarp_time_t now) const;
|
|
|
|
|
|
|
|
util::StatusObject
|
|
|
|
ExtractStatus() const;
|
2018-07-09 17:32:11 +00:00
|
|
|
};
|
2019-01-22 01:14:02 +00:00
|
|
|
|
2019-04-23 09:25:03 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-02-24 23:46:37 +00:00
|
|
|
inline std::ostream&
|
|
|
|
operator<<(std::ostream& out, const IntroSet& i)
|
|
|
|
{
|
|
|
|
return i.print(out, -1, -1);
|
|
|
|
}
|
|
|
|
|
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
|