2021-03-09 22:24:35 +00:00
|
|
|
#pragma once
|
2018-06-22 13:59:28 +00:00
|
|
|
|
2023-08-29 14:26:59 +00:00
|
|
|
#include <llarp/messages/common.hpp>
|
2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/constants/proto.hpp>
|
|
|
|
#include <llarp/path/path_types.hpp>
|
|
|
|
#include <llarp/util/bencode.hpp>
|
|
|
|
#include <llarp/util/buffer.hpp>
|
2018-06-22 13:59:28 +00:00
|
|
|
|
2023-08-29 14:26:59 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
static auto route_cat = llarp::log::Cat("lokinet.routing");
|
|
|
|
} // namespace
|
|
|
|
|
2018-06-22 13:59:28 +00:00
|
|
|
namespace llarp
|
|
|
|
{
|
2019-02-11 19:45:42 +00:00
|
|
|
struct AbstractRouter;
|
2018-06-22 13:59:28 +00:00
|
|
|
namespace routing
|
|
|
|
{
|
2023-08-29 14:26:59 +00:00
|
|
|
struct AbstractRoutingMessageHandler;
|
2018-06-22 13:59:28 +00:00
|
|
|
|
2023-08-29 14:26:59 +00:00
|
|
|
struct AbstractRoutingMessage : private AbstractSerializable
|
2018-06-22 13:59:28 +00:00
|
|
|
{
|
2019-02-11 19:45:42 +00:00
|
|
|
PathID_t from;
|
2019-07-30 23:42:13 +00:00
|
|
|
uint64_t S{0};
|
2022-05-26 15:59:44 +00:00
|
|
|
uint64_t version = llarp::constants::proto_version;
|
2018-09-17 15:32:37 +00:00
|
|
|
|
2023-08-29 14:26:59 +00:00
|
|
|
AbstractRoutingMessage() = default;
|
2018-09-17 15:32:37 +00:00
|
|
|
|
2023-08-29 14:26:59 +00:00
|
|
|
virtual ~AbstractRoutingMessage() = default;
|
2018-09-17 15:32:37 +00:00
|
|
|
|
2019-05-24 02:01:36 +00:00
|
|
|
virtual bool
|
2023-08-29 14:26:59 +00:00
|
|
|
decode_key(const llarp_buffer_t& key, llarp_buffer_t* buf) = 0;
|
2019-05-24 02:01:36 +00:00
|
|
|
|
2023-08-29 14:26:59 +00:00
|
|
|
std::string
|
|
|
|
bt_encode() const override = 0;
|
2019-05-24 02:01:36 +00:00
|
|
|
|
2018-06-22 13:59:28 +00:00
|
|
|
virtual bool
|
2023-08-29 14:26:59 +00:00
|
|
|
handle_message(AbstractRoutingMessageHandler* h, AbstractRouter* r) const = 0;
|
2018-06-22 13:59:28 +00:00
|
|
|
|
2019-01-02 01:04:04 +00:00
|
|
|
virtual void
|
2023-08-29 14:26:59 +00:00
|
|
|
clear() = 0;
|
|
|
|
|
|
|
|
// methods we do not want to inherit onwards from AbstractSerializable
|
|
|
|
void
|
|
|
|
bt_encode(oxenc::bt_list_producer&) const final
|
|
|
|
{
|
|
|
|
throw std::runtime_error{
|
|
|
|
"Error: Routing messages should not encode directly to a bt list producer!"};
|
|
|
|
}
|
|
|
|
void
|
|
|
|
bt_encode(llarp_buffer&) const final
|
|
|
|
{
|
|
|
|
throw std::runtime_error{"Error: Routing messages should not encode directly to a buffer!"};
|
|
|
|
}
|
|
|
|
void
|
|
|
|
bt_encode(oxenc::bt_dict_producer&) const final
|
|
|
|
{
|
|
|
|
throw std::runtime_error{
|
|
|
|
"Error: Routing messages should not encode directly to a bt dict producer!"};
|
|
|
|
}
|
2021-03-31 16:06:50 +00:00
|
|
|
|
|
|
|
bool
|
2023-08-29 14:26:59 +00:00
|
|
|
operator<(const AbstractRoutingMessage& other) const
|
2021-03-31 16:06:50 +00:00
|
|
|
{
|
|
|
|
return other.S < S;
|
|
|
|
}
|
2018-06-22 13:59:28 +00:00
|
|
|
};
|
2018-12-27 14:32:37 +00:00
|
|
|
|
2018-06-22 13:59:28 +00:00
|
|
|
} // namespace routing
|
|
|
|
} // namespace llarp
|