lokinet/llarp/dht/messages/gotintro.hpp

75 lines
1.9 KiB
C++
Raw Normal View History

#ifndef LLARP_DHT_MESSAGES_GOT_INTRO_HPP
#define LLARP_DHT_MESSAGES_GOT_INTRO_HPP
2018-12-12 02:15:08 +00:00
2018-12-12 00:48:54 +00:00
#include <dht/message.hpp>
#include <service/intro_set.hpp>
2019-05-03 13:15:03 +00:00
#include <util/copy_or_nullptr.hpp>
2018-12-12 02:15:08 +00:00
2018-07-20 04:50:28 +00:00
#include <vector>
namespace llarp
{
namespace dht
{
2018-11-08 15:15:02 +00:00
/// acknowledgement to PublishIntroMessage or reply to FindIntroMessage
struct GotIntroMessage : public IMessage
{
2018-11-08 15:15:02 +00:00
/// the found introsets
2018-07-20 04:50:28 +00:00
std::vector< llarp::service::IntroSet > I;
2018-11-08 15:15:02 +00:00
/// txid
uint64_t T = 0;
2018-11-08 15:15:02 +00:00
/// the key of a router closer in keyspace if iterative lookup
std::unique_ptr< Key_t > K;
GotIntroMessage(const Key_t& from) : IMessage(from)
{
}
2019-05-03 13:15:03 +00:00
GotIntroMessage(const GotIntroMessage& other)
: IMessage(other.From)
, I(other.I)
, T(other.T)
, K(copy_or_nullptr(other.K))
{
version = other.version;
}
2018-11-08 15:15:02 +00:00
/// for iterative reply
GotIntroMessage(const Key_t& from, const Key_t& closer, uint64_t txid)
: IMessage(from), T(txid), K(new Key_t(closer))
{
}
/// for recursive reply
2018-07-20 04:50:28 +00:00
GotIntroMessage(const std::vector< llarp::service::IntroSet >& results,
2018-07-18 03:10:21 +00:00
uint64_t txid);
~GotIntroMessage();
bool
BEncode(llarp_buffer_t* buf) const override;
bool
2019-02-05 00:41:33 +00:00
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* val) override;
virtual bool
2019-05-03 13:15:03 +00:00
HandleMessage(llarp_dht_context* ctx,
std::vector< IMessage::Ptr_t >& replies) const override;
};
struct RelayedGotIntroMessage final : public GotIntroMessage
{
RelayedGotIntroMessage() : GotIntroMessage({})
{
}
bool
2019-05-03 13:15:03 +00:00
HandleMessage(llarp_dht_context* ctx,
std::vector< IMessage::Ptr_t >& replies) const override;
};
2019-05-03 13:15:03 +00:00
using GotIntroMessage_constptr = std::shared_ptr< const GotIntroMessage >;
} // namespace dht
} // namespace llarp
2018-08-29 20:40:26 +00:00
#endif