2023-08-29 14:26:59 +00:00
|
|
|
#pragma once
|
|
|
|
|
2023-10-04 13:25:25 +00:00
|
|
|
#include <llarp/crypto/crypto.hpp>
|
2023-10-03 20:00:23 +00:00
|
|
|
#include <llarp/dht/key.hpp>
|
|
|
|
#include <llarp/path/path_types.hpp>
|
|
|
|
#include <llarp/router_id.hpp>
|
|
|
|
#include <llarp/service/tag.hpp>
|
|
|
|
#include <llarp/util/bencode.hpp>
|
2023-08-29 14:26:59 +00:00
|
|
|
#include <llarp/util/buffer.hpp>
|
2023-09-14 14:54:51 +00:00
|
|
|
#include <llarp/util/logging.hpp>
|
|
|
|
|
2023-10-03 20:00:23 +00:00
|
|
|
#include <oxenc/bt.h>
|
|
|
|
|
2023-09-14 14:54:51 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
static auto link_cat = llarp::log::Cat("lokinet.link");
|
|
|
|
} // namespace
|
|
|
|
|
2023-08-29 14:26:59 +00:00
|
|
|
namespace llarp
|
|
|
|
{
|
2023-11-06 17:46:42 +00:00
|
|
|
namespace messages
|
|
|
|
{
|
|
|
|
inline std::string
|
|
|
|
serialize_response(oxenc::bt_dict supplement = {})
|
|
|
|
{
|
|
|
|
return oxenc::bt_serialize(supplement);
|
|
|
|
}
|
|
|
|
|
2023-11-27 17:15:36 +00:00
|
|
|
// ideally STATUS is the first key in a bt-dict, so use a single, early ascii char
|
|
|
|
inline const auto STATUS_KEY = "!"s;
|
|
|
|
inline const auto TIMEOUT_RESPONSE = serialize_response({{STATUS_KEY, "TIMEOUT"}});
|
|
|
|
inline const auto ERROR_RESPONSE = serialize_response({{STATUS_KEY, "ERROR"}});
|
|
|
|
inline const auto OK_RESPONSE = serialize_response({{STATUS_KEY, "OK"}});
|
|
|
|
} // namespace messages
|
2023-11-06 17:46:42 +00:00
|
|
|
|
2023-08-29 14:26:59 +00:00
|
|
|
/// abstract base class for serialized messages
|
|
|
|
struct AbstractSerializable
|
|
|
|
{
|
|
|
|
virtual std::string
|
|
|
|
bt_encode() const = 0;
|
|
|
|
virtual void
|
|
|
|
bt_encode(oxenc::bt_dict_producer& btdp) const = 0;
|
|
|
|
};
|
2023-09-13 15:57:29 +00:00
|
|
|
|
|
|
|
struct AbstractMessageHandler
|
|
|
|
{
|
|
|
|
virtual bool
|
|
|
|
handle_message(AbstractSerializable&) = 0;
|
|
|
|
};
|
2023-08-29 14:26:59 +00:00
|
|
|
} // namespace llarp
|