lokinet/llarp/dht/messages/findrouter.hpp

66 lines
1.6 KiB
C++
Raw Normal View History

#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>
namespace llarp
{
namespace dht
{
struct FindRouterMessage : public IMessage
{
// inbound parsing
FindRouterMessage(const Key_t& from) : IMessage(from)
{
}
// find by routerid
FindRouterMessage(uint64_t id, const RouterID& target)
: IMessage({}), K(target), txid(id)
{
}
// exploritory
FindRouterMessage(uint64_t id) : IMessage({}), exploritory(true), txid(id)
{
K.Randomize();
}
~FindRouterMessage();
bool
BEncode(llarp_buffer_t* buf) const override;
bool
DecodeKey(llarp_buffer_t key, llarp_buffer_t* val) override;
virtual bool
HandleMessage(
llarp_dht_context* ctx,
std::vector< std::unique_ptr< IMessage > >& replies) const override;
2018-08-29 20:40:26 +00:00
RouterID K;
bool iterative = false;
bool exploritory = false;
uint64_t txid = 0;
uint64_t version = 0;
};
/// variant of FindRouterMessage relayed via path
struct RelayedFindRouterMessage final : public FindRouterMessage
{
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
virtual bool
HandleMessage(
llarp_dht_context* ctx,
std::vector< std::unique_ptr< IMessage > >& replies) const override;
};
2018-07-17 04:37:50 +00:00
} // namespace dht
} // namespace llarp
#endif