lokinet/include/llarp/service/IntroSet.hpp

84 lines
1.7 KiB
C++
Raw Normal View History

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
#include <list>
namespace llarp
{
namespace service
{
constexpr std::size_t MAX_INTROSET_SIZE = 1024;
struct IntroSet : public llarp::IBEncodeMessage
{
ServiceInfo A;
std::list< Introduction > I;
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;
~IntroSet();
IntroSet&
operator=(const IntroSet& other)
{
A = other.A;
I = other.I;
version = other.version;
if(W)
delete W;
W = other.W;
Z = other.Z;
return *this;
}
2018-07-18 03:10:21 +00:00
bool
operator<(const IntroSet& other) const
{
return A < other.A || topic < other.topic;
}
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 << "]";
auto topic = i.topic.ToString();
if(topic.size())
{
out << " topic=" << topic;
}
return out << " V=" << i.version << " Z=" << i.Z;
2018-07-09 17:32:11 +00:00
}
2018-07-17 06:17:13 +00:00
bool
HasExpiredIntros() const;
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
VerifySignature(llarp_crypto* crypto) const;
};
} // namespace service
} // namespace llarp
#endif