lokinet/llarp/messages/link_message.hpp

67 lines
1.4 KiB
C++
Raw Normal View History

#pragma once
#include <llarp/link/session.hpp>
#include <llarp/router_id.hpp>
#include <llarp/util/bencode.hpp>
#include <llarp/path/path_types.hpp>
#include <vector>
namespace llarp
{
struct ILinkSession;
struct AbstractRouter;
2018-06-01 14:08:54 +00:00
/// parsed link layer message
2019-05-24 02:01:36 +00:00
struct ILinkMessage
{
/// who did this message come from or is going to
2018-12-20 16:49:05 +00:00
ILinkSession* session = nullptr;
2022-05-26 15:59:44 +00:00
uint64_t version = llarp::constants::proto_version;
2018-06-01 14:08:54 +00:00
PathID_t pathid;
2018-12-20 16:49:05 +00:00
ILinkMessage() = default;
2019-06-15 14:55:13 +00:00
virtual ~ILinkMessage() = default;
2018-06-01 14:08:54 +00:00
2019-05-24 02:01:36 +00:00
virtual bool
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* val) = 0;
bool
BDecode(llarp_buffer_t* buf)
{
// default version if not specified is 0
uint64_t v = 0;
// seek for version and set it if we got it
if (BEncodeSeekDictVersion(v, buf, 'v'))
{
version = v;
}
// when we hit the code path version is set and we can tell how to decode
2019-05-24 02:01:36 +00:00
return bencode_decode_dict(*this, buf);
}
virtual bool
BEncode(llarp_buffer_t* buf) const = 0;
2018-06-01 14:08:54 +00:00
virtual bool
HandleMessage(AbstractRouter* router) const = 0;
2018-12-20 16:49:05 +00:00
virtual void
Clear() = 0;
2019-03-26 20:04:41 +00:00
// the name of this kind of message
virtual const char*
Name() const = 0;
2020-01-17 16:33:37 +00:00
/// get message prority, higher value means more important
virtual uint16_t
Priority() const
{
return 1;
}
};
2018-12-20 16:49:05 +00:00
2018-06-23 00:00:44 +00:00
} // namespace llarp