lokinet/include/llarp/service/protocol.hpp

78 lines
1.8 KiB
C++
Raw Normal View History

2018-07-19 04:58:39 +00:00
#ifndef LLARP_SERVICE_PROTOCOL_HPP
#define LLARP_SERVICE_PROTOCOL_HPP
#include <llarp/time.h>
#include <llarp/bencode.hpp>
#include <llarp/crypto.hpp>
2018-07-22 23:14:29 +00:00
#include <llarp/encrypted.hpp>
#include <llarp/routing/message.hpp>
2018-07-22 23:14:29 +00:00
#include <llarp/service/Info.hpp>
#include <llarp/service/Intro.hpp>
2018-07-19 04:58:39 +00:00
#include <vector>
namespace llarp
{
namespace service
{
2018-07-22 23:14:29 +00:00
constexpr std::size_t MAX_PROTOCOL_MESSAGE_SIZE = 2048;
2018-07-19 04:58:39 +00:00
enum ProtocolType
{
eProtocolText = 0,
eProtocolTraffic = 1
};
2018-07-22 23:14:29 +00:00
/// inner message
2018-07-19 04:58:39 +00:00
struct ProtocolMessage : public llarp::IBEncodeMessage
{
2018-07-22 23:14:29 +00:00
ProtocolMessage();
2018-07-19 04:58:39 +00:00
~ProtocolMessage();
ProtocolType proto;
llarp_time_t queued = 0;
std::vector< byte_t > payload;
2018-07-22 23:14:29 +00:00
Introduction introReply;
ServiceInfo sender;
2018-07-19 04:58:39 +00:00
bool
DecodeKey(llarp_buffer_t key, llarp_buffer_t* val);
bool
BEncode(llarp_buffer_t* buf) const;
void
PutBuffer(llarp_buffer_t payload);
2018-07-22 23:14:29 +00:00
};
/// outer message
struct ProtocolFrame : public llarp::routing::IMessage
2018-07-22 23:14:29 +00:00
{
llarp::Encrypted D;
uint64_t S = 0;
llarp::PubKey H;
llarp::KeyExchangeNonce N;
llarp::Signature Z;
~ProtocolFrame();
bool
EncryptAndSign(llarp_crypto* c, const ProtocolMessage* msg,
byte_t* sharedkey, byte_t* signingkey);
bool
DecryptPayloadInto(llarp_crypto* c, byte_t* sharedkey,
ProtocolMessage* into) const;
2018-07-19 04:58:39 +00:00
2018-07-22 23:14:29 +00:00
bool
DecodeKey(llarp_buffer_t key, llarp_buffer_t* val);
2018-07-20 04:50:28 +00:00
2018-07-22 23:14:29 +00:00
bool
BEncode(llarp_buffer_t* buf) const;
2018-07-19 04:58:39 +00:00
2018-07-22 23:14:29 +00:00
bool
Verify(llarp_crypto* c, byte_t* signingkey);
bool
HandleMessage(llarp::routing::IMessageHandler* h, llarp_router* r) const;
2018-07-19 04:58:39 +00:00
};
} // namespace service
} // namespace llarp
#endif