2018-07-09 17:32:11 +00:00
|
|
|
#ifndef LLARP_SERVICE_INTRO_HPP
|
|
|
|
#define LLARP_SERVICE_INTRO_HPP
|
|
|
|
#include <llarp/bencode.hpp>
|
|
|
|
#include <llarp/crypto.hpp>
|
|
|
|
#include <llarp/path_types.hpp>
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace service
|
|
|
|
{
|
|
|
|
struct Introduction : public llarp::IBEncodeMessage
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
Introduction(const Introduction& other)
|
|
|
|
{
|
|
|
|
router = other.router;
|
|
|
|
pathID = other.pathID;
|
|
|
|
latency = other.latency;
|
|
|
|
version = other.version;
|
|
|
|
expiresAt = other.expiresAt;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
ExpiresSoon(llarp_time_t now, llarp_time_t dlt = 5000) const
|
|
|
|
{
|
|
|
|
if(dlt)
|
2018-09-11 13:21:35 +00:00
|
|
|
return now >= (expiresAt - (llarp_randint() % 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
|
|
|
|
BEncode(llarp_buffer_t* buf) const;
|
|
|
|
|
|
|
|
bool
|
|
|
|
DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf);
|
|
|
|
|
2018-07-22 23:14:29 +00:00
|
|
|
void
|
|
|
|
Clear();
|
|
|
|
|
2018-07-09 17:32:11 +00:00
|
|
|
bool
|
|
|
|
operator<(const Introduction& other) const
|
|
|
|
{
|
|
|
|
return expiresAt < other.expiresAt || pathID < other.pathID;
|
|
|
|
}
|
2018-09-17 15:32:37 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
operator==(const Introduction& other) const
|
|
|
|
{
|
|
|
|
return expiresAt == other.expiresAt && version == other.version
|
|
|
|
&& pathID == other.pathID && router == other.router
|
|
|
|
&& latency == other.latency;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
operator!=(const Introduction& other) const
|
|
|
|
{
|
|
|
|
return !(*this == other);
|
|
|
|
}
|
2018-07-09 17:32:11 +00:00
|
|
|
};
|
|
|
|
} // namespace service
|
|
|
|
} // namespace llarp
|
|
|
|
|
2018-09-10 16:36:36 +00:00
|
|
|
#endif
|