2021-03-09 22:24:35 +00:00
|
|
|
#pragma once
|
2018-05-25 17:52:10 +00:00
|
|
|
|
2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/link/session.hpp>
|
|
|
|
#include <llarp/router_id.hpp>
|
|
|
|
#include <llarp/util/bencode.hpp>
|
|
|
|
#include <llarp/path/path_types.hpp>
|
2018-05-25 17:52:10 +00:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
2018-09-02 18:25:42 +00:00
|
|
|
struct ILinkSession;
|
2019-02-11 19:45:42 +00:00
|
|
|
struct AbstractRouter;
|
2018-06-01 14:08:54 +00:00
|
|
|
|
|
|
|
/// parsed link layer message
|
2019-05-24 02:01:36 +00:00
|
|
|
struct ILinkMessage
|
2018-05-25 17:52:10 +00:00
|
|
|
{
|
2018-09-02 18:25:42 +00:00
|
|
|
/// who did this message come from or is going to
|
2018-12-20 16:49:05 +00:00
|
|
|
ILinkSession* session = nullptr;
|
2020-04-07 18:38:56 +00:00
|
|
|
uint64_t version = LLARP_PROTO_VERSION;
|
2018-06-01 14:08:54 +00:00
|
|
|
|
2019-10-25 21:13:11 +00:00
|
|
|
PathID_t pathid;
|
|
|
|
|
2018-12-20 16:49:05 +00:00
|
|
|
ILinkMessage() = default;
|
2018-09-02 18:25:42 +00:00
|
|
|
|
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)
|
|
|
|
{
|
2019-11-03 15:31:01 +00:00
|
|
|
// default version if not specified is 0
|
|
|
|
uint64_t v = 0;
|
|
|
|
// seek for version and set it if we got it
|
2020-04-07 18:38:56 +00:00
|
|
|
if (BEncodeSeekDictVersion(v, buf, 'v'))
|
2019-11-03 15:31:01 +00:00
|
|
|
{
|
|
|
|
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
|
2019-02-11 19:45:42 +00:00
|
|
|
HandleMessage(AbstractRouter* router) const = 0;
|
2018-05-25 17:52:10 +00:00
|
|
|
|
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-05-25 17:52:10 +00:00
|
|
|
};
|
2018-12-20 16:49:05 +00:00
|
|
|
|
2018-06-23 00:00:44 +00:00
|
|
|
} // namespace llarp
|