lokinet/include/llarp/link_message.hpp

61 lines
1.2 KiB
C++
Raw Normal View History

#ifndef LLARP_LINK_MESSAGE_HPP
#define LLARP_LINK_MESSAGE_HPP
#include <llarp/link.h>
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>
#include <queue>
#include <vector>
namespace llarp
{
2018-06-01 14:08:54 +00:00
struct ILinkMessage;
typedef std::queue< ILinkMessage* > SendQueue;
/// parsed link layer message
2018-06-23 00:00:44 +00:00
struct ILinkMessage : public IBEncodeMessage
{
2018-06-01 14:08:54 +00:00
/// who did this message come from (rc.k)
RouterID remote = {};
2018-06-01 14:08:54 +00:00
uint64_t version = 0;
2018-06-06 12:46:26 +00:00
ILinkMessage() = default;
ILinkMessage(const RouterID& id);
2018-06-01 14:08:54 +00:00
virtual bool
HandleMessage(llarp_router* router) const = 0;
};
struct InboundMessageParser
{
InboundMessageParser(llarp_router* router);
dict_reader reader;
static bool
OnKey(dict_reader* r, llarp_buffer_t* buf);
/// start processig message from a link session
bool
ProcessFrom(llarp_link_session* from, llarp_buffer_t buf);
/// 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();
private:
bool firstkey;
llarp_router* router;
llarp_link_session* from;
2018-06-01 14:08:54 +00:00
ILinkMessage* msg = nullptr;
};
2018-06-23 00:00:44 +00:00
} // namespace llarp
#endif