2018-07-11 13:20:14 +00:00
|
|
|
#ifndef LLARP_DHT_MESSAGES_FIND_ROUTER_HPP
|
|
|
|
#define LLARP_DHT_MESSAGES_FIND_ROUTER_HPP
|
2018-12-12 00:48:54 +00:00
|
|
|
#include <dht/message.hpp>
|
2018-07-11 13:20:14 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace dht
|
|
|
|
{
|
|
|
|
struct FindRouterMessage : public IMessage
|
|
|
|
{
|
2018-12-10 17:22:59 +00:00
|
|
|
// inbound parsing
|
2018-07-11 13:20:14 +00:00
|
|
|
FindRouterMessage(const Key_t& from) : IMessage(from)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-12-10 17:22:59 +00:00
|
|
|
// find by routerid
|
|
|
|
FindRouterMessage(uint64_t id, const RouterID& target)
|
|
|
|
: IMessage({}), K(target), txid(id)
|
2018-07-11 13:20:14 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-08-27 13:44:16 +00:00
|
|
|
// exploritory
|
2018-12-10 17:22:59 +00:00
|
|
|
FindRouterMessage(uint64_t id) : IMessage({}), exploritory(true), txid(id)
|
2018-08-27 13:44:16 +00:00
|
|
|
{
|
|
|
|
K.Randomize();
|
|
|
|
}
|
|
|
|
|
2019-07-30 23:42:13 +00:00
|
|
|
~FindRouterMessage() override;
|
2018-07-11 13:20:14 +00:00
|
|
|
|
|
|
|
bool
|
2018-11-05 11:27:12 +00:00
|
|
|
BEncode(llarp_buffer_t* buf) const override;
|
2018-07-11 13:20:14 +00:00
|
|
|
|
|
|
|
bool
|
2019-02-05 00:41:33 +00:00
|
|
|
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* val) override;
|
2018-07-11 13:20:14 +00:00
|
|
|
|
2019-07-30 23:42:13 +00:00
|
|
|
bool
|
2018-11-05 11:27:12 +00:00
|
|
|
HandleMessage(
|
|
|
|
llarp_dht_context* ctx,
|
|
|
|
std::vector< std::unique_ptr< IMessage > >& replies) const override;
|
2018-07-11 13:20:14 +00:00
|
|
|
|
2018-08-29 20:40:26 +00:00
|
|
|
RouterID K;
|
2018-07-11 13:20:14 +00:00
|
|
|
bool iterative = false;
|
2018-08-27 13:44:16 +00:00
|
|
|
bool exploritory = false;
|
2018-07-11 13:20:14 +00:00
|
|
|
uint64_t txid = 0;
|
|
|
|
uint64_t version = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// variant of FindRouterMessage relayed via path
|
2018-11-05 11:27:12 +00:00
|
|
|
struct RelayedFindRouterMessage final : public FindRouterMessage
|
2018-07-11 13:20:14 +00:00
|
|
|
{
|
|
|
|
RelayedFindRouterMessage(const Key_t& from) : FindRouterMessage(from)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// handle a relayed FindRouterMessage, do a lookup on the dht and inform
|
|
|
|
/// the path of the result
|
|
|
|
/// TODO: smart path expiration logic needs to be implemented
|
2019-07-30 23:42:13 +00:00
|
|
|
bool
|
2019-05-03 13:15:03 +00:00
|
|
|
HandleMessage(llarp_dht_context* ctx,
|
|
|
|
std::vector< IMessage::Ptr_t >& replies) const override;
|
2018-07-11 13:20:14 +00:00
|
|
|
};
|
2018-07-17 04:37:50 +00:00
|
|
|
} // namespace dht
|
|
|
|
} // namespace llarp
|
2018-08-27 13:44:16 +00:00
|
|
|
#endif
|