lokinet/llarp/messages/link_message.hpp

64 lines
1.3 KiB
C++
Raw Normal View History

#pragma once
2023-08-29 14:26:59 +00:00
#include "common.hpp"
#include <llarp/path/path_types.hpp>
#include <llarp/router_id.hpp>
#include <llarp/util/bencode.hpp>
#include <vector>
namespace llarp
{
namespace link
{
struct Connection;
}
struct Router;
2018-06-01 14:08:54 +00:00
/// parsed link layer message
2023-08-29 14:26:59 +00:00
struct AbstractLinkMessage : private AbstractSerializable
{
std::shared_ptr<link::Connection> conn;
PathID_t pathid;
uint64_t version = llarp::constants::proto_version;
2023-08-29 14:26:59 +00:00
AbstractLinkMessage() = default;
2023-08-29 14:26:59 +00:00
virtual ~AbstractLinkMessage() = default;
2018-06-01 14:08:54 +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
virtual bool
handle_message(Router* router) const = 0;
2019-05-24 02:01:36 +00:00
2018-06-01 14:08:54 +00:00
virtual bool
2023-08-29 14:26:59 +00:00
decode_key(const llarp_buffer_t& key, llarp_buffer_t* buf) = 0;
2018-12-20 16:49:05 +00:00
virtual void
2023-08-29 14:26:59 +00:00
clear() = 0;
2019-03-26 20:04:41 +00:00
// the name of this kind of message
virtual const char*
2023-08-29 14:26:59 +00:00
name() const = 0;
2020-01-17 16:33:37 +00:00
/// get message prority, higher value means more important
virtual uint16_t
2023-08-29 14:26:59 +00:00
priority() const
2020-01-17 16:33:37 +00:00
{
return 1;
}
2023-08-29 14:26:59 +00:00
// methods we do not want to inherit onwards from AbstractSerializable
void
bt_encode(oxenc::bt_dict_producer&) const final
{
throw std::runtime_error{
"Error: Link messages should not encode directly to a bt list producer!"};
}
};
2018-06-23 00:00:44 +00:00
} // namespace llarp