2018-07-09 17:32:11 +00:00
|
|
|
#ifndef LLARP_SERVICE_INTRO_HPP
|
|
|
|
#define LLARP_SERVICE_INTRO_HPP
|
2018-12-12 02:52:51 +00:00
|
|
|
|
2019-01-13 16:30:07 +00:00
|
|
|
#include <crypto/types.hpp>
|
2019-01-11 01:19:36 +00:00
|
|
|
#include <path/path_types.hpp>
|
2019-01-10 19:41:51 +00:00
|
|
|
#include <util/bencode.hpp>
|
2019-02-08 19:43:25 +00:00
|
|
|
#include <util/status.hpp>
|
2018-07-09 17:32:11 +00:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace service
|
|
|
|
{
|
2019-02-08 19:43:25 +00:00
|
|
|
struct Introduction final : public llarp::IBEncodeMessage,
|
|
|
|
public util::IStateful
|
2018-07-09 17:32:11 +00:00
|
|
|
{
|
|
|
|
llarp::PubKey router;
|
|
|
|
llarp::PathID_t pathID;
|
2018-07-12 13:43:37 +00:00
|
|
|
uint64_t latency = 0;
|
|
|
|
uint64_t version = 0;
|
|
|
|
uint64_t expiresAt = 0;
|
2018-07-09 17:32:11 +00:00
|
|
|
|
2018-07-11 16:11:19 +00:00
|
|
|
Introduction() = default;
|
2018-11-07 15:30:22 +00:00
|
|
|
Introduction(const Introduction& other) : IBEncodeMessage(other.version)
|
2018-07-11 16:11:19 +00:00
|
|
|
{
|
|
|
|
router = other.router;
|
|
|
|
pathID = other.pathID;
|
|
|
|
latency = other.latency;
|
|
|
|
version = other.version;
|
|
|
|
expiresAt = other.expiresAt;
|
|
|
|
}
|
|
|
|
|
2019-02-08 19:43:25 +00:00
|
|
|
void
|
|
|
|
ExtractStatus(util::StatusObject& obj) const override;
|
|
|
|
|
2018-09-10 16:36:36 +00:00
|
|
|
bool
|
|
|
|
IsExpired(llarp_time_t now) const
|
|
|
|
{
|
2018-09-11 13:21:35 +00:00
|
|
|
return now >= expiresAt;
|
2018-09-10 16:36:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2018-09-30 12:42:28 +00:00
|
|
|
ExpiresSoon(llarp_time_t now, llarp_time_t dlt = 15000) const
|
2018-09-10 16:36:36 +00:00
|
|
|
{
|
|
|
|
if(dlt)
|
2018-09-30 12:42:28 +00:00
|
|
|
return now >= (expiresAt - dlt);
|
2018-09-10 16:36:36 +00:00
|
|
|
return IsExpired(now);
|
|
|
|
}
|
|
|
|
|
2018-07-09 17:32:11 +00:00
|
|
|
~Introduction();
|
|
|
|
|
|
|
|
friend std::ostream&
|
|
|
|
operator<<(std::ostream& out, const Introduction& i)
|
|
|
|
{
|
|
|
|
return out << "k=" << i.router << " p=" << i.pathID
|
|
|
|
<< " v=" << i.version << " x=" << i.expiresAt;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2018-07-22 23:14:29 +00:00
|
|
|
void
|
|
|
|
Clear();
|
|
|
|
|
2018-07-09 17:32:11 +00:00
|
|
|
bool
|
|
|
|
operator<(const Introduction& other) const
|
|
|
|
{
|
2018-09-24 11:36:47 +00:00
|
|
|
return expiresAt < other.expiresAt || pathID < other.pathID
|
|
|
|
|| router < other.router || version < other.version
|
|
|
|
|| latency < other.latency;
|
2018-07-09 17:32:11 +00:00
|
|
|
}
|
2018-09-17 15:32:37 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
operator==(const Introduction& other) const
|
|
|
|
{
|
2018-09-27 17:51:42 +00:00
|
|
|
return pathID == other.pathID && router == other.router;
|
2018-09-17 15:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
operator!=(const Introduction& other) const
|
|
|
|
{
|
2018-10-08 21:23:45 +00:00
|
|
|
return pathID != other.pathID || router != other.router;
|
2018-09-17 15:32:37 +00:00
|
|
|
}
|
2018-09-24 11:36:47 +00:00
|
|
|
|
|
|
|
struct Hash
|
|
|
|
{
|
|
|
|
size_t
|
|
|
|
operator()(const Introduction& i) const
|
|
|
|
{
|
2018-12-20 14:18:03 +00:00
|
|
|
return PubKey::Hash()(i.router) ^ PathID_t::Hash()(i.pathID);
|
2018-09-24 11:36:47 +00:00
|
|
|
}
|
|
|
|
};
|
2018-07-09 17:32:11 +00:00
|
|
|
};
|
|
|
|
} // namespace service
|
|
|
|
} // namespace llarp
|
|
|
|
|
2018-09-10 16:36:36 +00:00
|
|
|
#endif
|