lokinet/llarp/dht/messages/gotrouter.hpp

74 lines
2.0 KiB
C++
Raw Normal View History

#ifndef LLARP_DHT_MESSAGES_GOT_ROUTER_HPP
#define LLARP_DHT_MESSAGES_GOT_ROUTER_HPP
2019-07-30 23:42:13 +00:00
2018-12-12 00:48:54 +00:00
#include <dht/message.hpp>
2018-12-12 01:55:30 +00:00
#include <router_contact.hpp>
2019-05-03 13:15:03 +00:00
#include <util/copy_or_nullptr.hpp>
2019-07-30 23:42:13 +00:00
#include <utility>
#include <vector>
namespace llarp
{
namespace dht
{
struct GotRouterMessage final : public IMessage
{
2018-08-10 21:34:11 +00:00
GotRouterMessage(const Key_t& from, bool tunneled)
: IMessage(from), relayed(tunneled)
{
}
2018-08-30 18:48:43 +00:00
GotRouterMessage(const Key_t& from, uint64_t id,
2020-01-15 15:41:43 +00:00
const std::vector< RouterContact >& results,
bool tunneled)
: IMessage(from), R(results), txid(id), relayed(tunneled)
{
}
2018-11-08 15:15:02 +00:00
GotRouterMessage(const Key_t& from, const Key_t& closer, uint64_t id,
bool tunneled)
: IMessage(from), K(new Key_t(closer)), txid(id), relayed(tunneled)
{
}
2019-07-30 23:42:13 +00:00
GotRouterMessage(uint64_t id, std::vector< RouterID > _near,
bool tunneled)
2019-07-30 23:42:13 +00:00
: IMessage({}), N(std::move(_near)), txid(id), relayed(tunneled)
{
}
2019-05-03 13:15:03 +00:00
GotRouterMessage(const GotRouterMessage& other)
: IMessage(other.From)
, R(other.R)
, N(other.N)
, K(copy_or_nullptr(other.K))
, txid(other.txid)
, relayed(other.relayed)
{
version = other.version;
}
2019-07-30 23:42:13 +00:00
~GotRouterMessage() override;
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;
2019-07-30 23:42:13 +00:00
bool
HandleMessage(
llarp_dht_context* ctx,
std::vector< std::unique_ptr< IMessage > >& replies) const override;
2018-08-30 18:48:43 +00:00
std::vector< RouterContact > R;
std::vector< RouterID > N;
2018-11-08 15:15:02 +00:00
std::unique_ptr< Key_t > K;
2019-05-03 13:15:03 +00:00
uint64_t txid = 0;
bool relayed = false;
};
2019-05-03 13:15:03 +00:00
using GotRouterMessage_constptr = std::shared_ptr< const GotRouterMessage >;
2018-07-17 04:37:50 +00:00
} // namespace dht
} // namespace llarp
#endif