lokinet/llarp/messages/link_message_parser.hpp

58 lines
1.2 KiB
C++
Raw Normal View History

2018-12-20 16:49:05 +00:00
#ifndef LLARP_LINK_MESSAGE_PARSER_HPP
#define LLARP_LINK_MESSAGE_PARSER_HPP
2019-01-11 01:19:36 +00:00
#include <messages/discard.hpp>
#include <messages/dht_immediate.hpp>
#include <messages/link_intro.hpp>
#include <messages/link_message.hpp>
2019-01-11 01:19:36 +00:00
#include <messages/relay.hpp>
#include <messages/relay_commit.hpp>
2018-12-20 16:49:05 +00:00
namespace llarp
{
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, const llarp_buffer_t& buf);
2018-12-20 16:49:05 +00:00
/// called when the message is fully read
/// return true when the message was accepted otherwise returns false
bool
MessageDone();
/// resets internal state
void
Reset();
private:
RouterID
GetCurrentFrom();
private:
bool firstkey;
Router* router;
ILinkSession* from = nullptr;
ILinkMessage* msg = nullptr;
struct msg_holder_t
{
LinkIntroMessage i;
RelayDownstreamMessage d;
RelayUpstreamMessage u;
2019-01-19 13:54:50 +00:00
DHTImmediateMessage m;
2018-12-20 16:49:05 +00:00
LR_CommitMessage c;
DiscardMessage x;
};
msg_holder_t holder;
};
} // namespace llarp
#endif