mirror of https://github.com/oxen-io/lokinet
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.5 KiB
C++
63 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include "key.hpp"
|
|
#include <llarp/messages/link_message.hpp>
|
|
#include <llarp/path/path_types.hpp>
|
|
#include <llarp/util/bencode.hpp>
|
|
|
|
#include <vector>
|
|
|
|
namespace
|
|
{
|
|
static auto dht_cat = llarp::log::Cat("lokinet.dht");
|
|
} // namespace
|
|
|
|
namespace llarp::dht
|
|
{
|
|
constexpr size_t MAX_MSG_SIZE = 2048;
|
|
|
|
struct AbstractDHTMessageHandler;
|
|
|
|
struct AbstractDHTMessage : private AbstractSerializable
|
|
{
|
|
virtual ~AbstractDHTMessage() = default;
|
|
|
|
/// construct
|
|
AbstractDHTMessage(const Key_t& from) : From(from)
|
|
{}
|
|
|
|
virtual bool
|
|
handle_message(
|
|
AbstractDHTMessageHandler& dht,
|
|
std::vector<std::unique_ptr<AbstractDHTMessage>>& replies) const = 0;
|
|
|
|
void
|
|
bt_encode(oxenc::bt_dict_producer& btdp) const override = 0;
|
|
|
|
virtual bool
|
|
decode_key(const llarp_buffer_t& key, llarp_buffer_t* val) = 0;
|
|
|
|
// methods we do not want to inherit onwards from AbstractSerializable
|
|
std::string
|
|
bt_encode() const final
|
|
{
|
|
throw std::runtime_error{"Error: DHT messages should encode directly to a bt dict producer!"};
|
|
}
|
|
|
|
Key_t From;
|
|
PathID_t pathID;
|
|
uint64_t version = llarp::constants::proto_version;
|
|
};
|
|
|
|
std::unique_ptr<AbstractDHTMessage>
|
|
DecodeMessage(const Key_t& from, llarp_buffer_t* buf, bool relayed = false);
|
|
|
|
bool
|
|
DecodeMessageList(
|
|
Key_t from,
|
|
llarp_buffer_t* buf,
|
|
std::vector<std::unique_ptr<AbstractDHTMessage>>& list,
|
|
bool relayed = false);
|
|
|
|
} // namespace llarp::dht
|