2018-05-25 17:52:10 +00:00
|
|
|
#ifndef LLARP_LINK_MESSAGE_HPP
|
|
|
|
#define LLARP_LINK_MESSAGE_HPP
|
|
|
|
|
2018-06-23 00:00:44 +00:00
|
|
|
#include <llarp/bencode.hpp>
|
2018-06-10 14:05:48 +00:00
|
|
|
#include <llarp/router_id.hpp>
|
2018-09-02 18:25:42 +00:00
|
|
|
#include <llarp/link/session.hpp>
|
2018-05-25 17:52:10 +00:00
|
|
|
|
|
|
|
#include <queue>
|
|
|
|
#include <vector>
|
|
|
|
|
2018-07-09 04:26:27 +00:00
|
|
|
struct llarp_router;
|
|
|
|
|
2018-05-25 17:52:10 +00:00
|
|
|
namespace llarp
|
|
|
|
{
|
2018-09-02 18:25:42 +00:00
|
|
|
struct ILinkSession;
|
2018-06-01 14:08:54 +00:00
|
|
|
|
|
|
|
typedef std::queue< ILinkMessage* > SendQueue;
|
|
|
|
|
|
|
|
/// parsed link layer message
|
2018-06-23 00:00:44 +00:00
|
|
|
struct ILinkMessage : public IBEncodeMessage
|
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
|
|
|
|
ILinkSession* session;
|
2018-06-01 14:08:54 +00:00
|
|
|
uint64_t version = 0;
|
|
|
|
|
2018-09-02 18:25:42 +00:00
|
|
|
ILinkMessage() : ILinkMessage(nullptr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ILinkMessage(ILinkSession* from) : session(from)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
virtual ~ILinkMessage()
|
|
|
|
{
|
|
|
|
}
|
2018-06-01 14:08:54 +00:00
|
|
|
|
|
|
|
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
|
2018-09-02 18:25:42 +00:00
|
|
|
ProcessFrom(ILinkSession* from, llarp_buffer_t buf);
|
2018-05-25 17:52:10 +00:00
|
|
|
|
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();
|
|
|
|
|
2018-09-06 11:46:19 +00:00
|
|
|
/// resets internal state
|
|
|
|
void
|
|
|
|
Reset();
|
|
|
|
|
2018-05-26 18:31:45 +00:00
|
|
|
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;
|
2018-09-02 18:25:42 +00:00
|
|
|
ILinkSession* from = nullptr;
|
2018-09-06 11:46:19 +00:00
|
|
|
std::unique_ptr< ILinkMessage > msg;
|
2018-05-25 17:52:10 +00:00
|
|
|
};
|
2018-06-23 00:00:44 +00:00
|
|
|
} // namespace llarp
|
2018-05-25 17:52:10 +00:00
|
|
|
|
|
|
|
#endif
|