2018-07-11 15:20:14 +02:00
|
|
|
#ifndef LLARP_DHT_MESSAGE_HPP
|
|
|
|
#define LLARP_DHT_MESSAGE_HPP
|
2018-11-05 12:27:12 +01:00
|
|
|
|
2019-01-13 23:39:10 +01:00
|
|
|
#include <dht/dht.h>
|
2018-12-12 01:48:54 +01:00
|
|
|
#include <dht/key.hpp>
|
2019-01-11 02:19:36 +01:00
|
|
|
#include <path/path_types.hpp>
|
2019-01-10 20:41:51 +01:00
|
|
|
#include <util/bencode.hpp>
|
2018-12-12 03:52:51 +01:00
|
|
|
|
2018-07-11 15:20:14 +02:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace dht
|
|
|
|
{
|
|
|
|
constexpr size_t MAX_MSG_SIZE = 2048;
|
|
|
|
|
2019-05-24 04:01:36 +02:00
|
|
|
struct IMessage
|
2018-07-11 15:20:14 +02:00
|
|
|
{
|
2019-07-31 01:42:13 +02:00
|
|
|
virtual ~IMessage() = default;
|
2018-07-11 15:20:14 +02:00
|
|
|
|
|
|
|
/// construct
|
|
|
|
IMessage(const Key_t& from) : From(from)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-05-03 15:15:03 +02:00
|
|
|
using Ptr_t = std::unique_ptr< IMessage >;
|
|
|
|
|
2018-07-11 15:20:14 +02:00
|
|
|
virtual bool
|
2019-05-03 15:15:03 +02:00
|
|
|
HandleMessage(struct llarp_dht_context* dht,
|
|
|
|
std::vector< Ptr_t >& replies) const = 0;
|
2018-07-11 15:20:14 +02:00
|
|
|
|
2019-05-24 04:01:36 +02:00
|
|
|
virtual bool
|
|
|
|
BEncode(llarp_buffer_t* buf) const = 0;
|
|
|
|
|
|
|
|
virtual bool
|
|
|
|
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* val) = 0;
|
|
|
|
|
2018-07-11 15:20:14 +02:00
|
|
|
Key_t From;
|
|
|
|
PathID_t pathID;
|
2019-05-24 04:01:36 +02:00
|
|
|
uint64_t version = LLARP_PROTO_VERSION;
|
2018-07-11 15:20:14 +02:00
|
|
|
};
|
|
|
|
|
2019-05-03 15:15:03 +02:00
|
|
|
IMessage::Ptr_t
|
2018-07-11 15:20:14 +02:00
|
|
|
DecodeMessage(const Key_t& from, llarp_buffer_t* buf, bool relayed = false);
|
|
|
|
|
|
|
|
bool
|
2018-09-02 20:25:42 +02:00
|
|
|
DecodeMesssageList(Key_t from, llarp_buffer_t* buf,
|
2019-05-03 15:15:03 +02:00
|
|
|
std::vector< IMessage::Ptr_t >& dst,
|
2018-09-02 20:25:42 +02:00
|
|
|
bool relayed = false);
|
2018-07-17 06:37:50 +02:00
|
|
|
} // namespace dht
|
|
|
|
} // namespace llarp
|
2018-07-11 15:20:14 +02:00
|
|
|
|
2018-08-29 22:40:26 +02:00
|
|
|
#endif
|