2018-05-25 17:52:10 +00:00
|
|
|
#ifndef LLARP_LINK_MESSAGE_HPP
|
|
|
|
#define LLARP_LINK_MESSAGE_HPP
|
|
|
|
|
2018-12-12 01:32:10 +00:00
|
|
|
#include <link/session.hpp>
|
2018-12-12 02:52:51 +00:00
|
|
|
#include <router_id.hpp>
|
2019-01-10 19:41:51 +00:00
|
|
|
#include <util/bencode.hpp>
|
2019-10-25 21:13:11 +00:00
|
|
|
#include <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;
|
2019-05-24 02:01:36 +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
|
|
|
|
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
|
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;
|
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
|
2018-05-25 17:52:10 +00:00
|
|
|
|
|
|
|
#endif
|