2018-05-25 17:52:10 +00:00
|
|
|
#ifndef LLARP_LINK_MESSAGE_HPP
|
|
|
|
#define LLARP_LINK_MESSAGE_HPP
|
|
|
|
|
|
|
|
#include <llarp/bencode.h>
|
|
|
|
#include <llarp/link.h>
|
2018-06-01 14:08:54 +00:00
|
|
|
#include <llarp/aligned.hpp>
|
2018-05-25 17:52:10 +00:00
|
|
|
|
|
|
|
#include <queue>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
2018-06-01 14:08:54 +00:00
|
|
|
typedef AlignedBuffer< 32 > RouterID;
|
2018-05-25 17:52:10 +00:00
|
|
|
|
2018-06-01 14:08:54 +00:00
|
|
|
struct ILinkMessage;
|
|
|
|
|
|
|
|
typedef std::queue< ILinkMessage* > SendQueue;
|
|
|
|
|
|
|
|
/// parsed link layer message
|
|
|
|
struct ILinkMessage
|
2018-05-25 17:52:10 +00:00
|
|
|
{
|
2018-06-01 14:08:54 +00:00
|
|
|
/// who did this message come from (rc.k)
|
2018-06-01 17:47:37 +00:00
|
|
|
RouterID remote = {};
|
2018-06-01 14:08:54 +00:00
|
|
|
uint64_t version = 0;
|
|
|
|
|
2018-06-06 12:46:26 +00:00
|
|
|
ILinkMessage() = default;
|
2018-06-01 17:47:37 +00:00
|
|
|
ILinkMessage(const RouterID& id);
|
2018-06-01 14:08:54 +00:00
|
|
|
|
|
|
|
virtual ~ILinkMessage(){};
|
|
|
|
|
|
|
|
virtual bool
|
|
|
|
DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf) = 0;
|
|
|
|
|
|
|
|
virtual bool
|
|
|
|
BEncode(llarp_buffer_t* buf) const = 0;
|
|
|
|
|
|
|
|
virtual bool
|
|
|
|
HandleMessage(llarp_router* router) const = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct InboundMessageParser
|
|
|
|
{
|
|
|
|
InboundMessageParser(llarp_router* router);
|
2018-05-25 17:52:10 +00:00
|
|
|
dict_reader reader;
|
|
|
|
|
|
|
|
static bool
|
|
|
|
OnKey(dict_reader* r, llarp_buffer_t* buf);
|
|
|
|
|
2018-05-26 18:31:45 +00:00
|
|
|
/// start processig message from a link session
|
2018-05-25 17:52:10 +00:00
|
|
|
bool
|
|
|
|
ProcessFrom(llarp_link_session* from, llarp_buffer_t buf);
|
|
|
|
|
2018-05-26 18:31:45 +00:00
|
|
|
/// called when the message is fully read
|
|
|
|
/// return true when the message was accepted otherwise returns false
|
|
|
|
bool
|
|
|
|
MessageDone();
|
|
|
|
|
|
|
|
private:
|
2018-06-01 14:08:54 +00:00
|
|
|
RouterID
|
|
|
|
GetCurrentFrom();
|
2018-05-26 18:31:45 +00:00
|
|
|
|
2018-05-25 17:52:10 +00:00
|
|
|
private:
|
|
|
|
bool firstkey;
|
|
|
|
llarp_router* router;
|
|
|
|
llarp_link_session* from;
|
2018-06-01 14:08:54 +00:00
|
|
|
ILinkMessage* msg = nullptr;
|
2018-05-25 17:52:10 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|