lokinet/llarp/link_message.hpp

74 lines
1.4 KiB
C++
Raw Normal View History

#ifndef LLARP_LINK_MESSAGE_HPP
#define LLARP_LINK_MESSAGE_HPP
#include <bencode.hpp>
2018-12-12 01:32:10 +00:00
#include <link/session.hpp>
#include <router_id.hpp>
#include <queue>
#include <vector>
namespace llarp
{
struct ILinkSession;
struct Router;
2018-06-01 14:08:54 +00:00
using SendQueue = std::queue< ILinkMessage* >;
2018-06-01 14:08:54 +00:00
/// parsed link layer message
2018-06-23 00:00:44 +00:00
struct ILinkMessage : public IBEncodeMessage
{
/// who did this message come from or is going to
ILinkSession* session;
2018-06-01 14:08:54 +00:00
uint64_t version = 0;
ILinkMessage() : ILinkMessage(nullptr)
{
}
ILinkMessage(ILinkSession* from) : session(from)
{
}
virtual ~ILinkMessage()
{
}
2018-06-01 14:08:54 +00:00
virtual bool
HandleMessage(Router* router) const = 0;
2018-06-01 14:08:54 +00:00
};
struct InboundMessageParser
{
InboundMessageParser(Router* router);
dict_reader reader;
static bool
OnKey(dict_reader* r, llarp_buffer_t* buf);
/// start processig message from a link session
bool
ProcessFrom(ILinkSession* from, llarp_buffer_t buf);
/// 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();
private:
2018-06-01 14:08:54 +00:00
RouterID
GetCurrentFrom();
private:
bool firstkey;
Router* router;
ILinkSession* from = nullptr;
2018-09-06 11:46:19 +00:00
std::unique_ptr< ILinkMessage > msg;
};
2018-06-23 00:00:44 +00:00
} // namespace llarp
#endif