2019-03-29 15:17:49 +00:00
|
|
|
#ifndef LLARP_IWP_OUTERMESSAGE_HPP
|
|
|
|
#define LLARP_IWP_OUTERMESSAGE_HPP
|
2019-01-13 16:30:07 +00:00
|
|
|
|
|
|
|
#include <crypto/types.hpp>
|
2019-03-29 14:30:19 +00:00
|
|
|
#include <router_contact.hpp>
|
|
|
|
#include <util/aligned.hpp>
|
2019-01-02 14:14:02 +00:00
|
|
|
|
2019-03-07 15:17:29 +00:00
|
|
|
#include <array>
|
2019-01-02 14:14:02 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
2019-01-05 13:45:05 +00:00
|
|
|
namespace iwp
|
2019-01-02 14:14:02 +00:00
|
|
|
{
|
2019-03-29 12:19:59 +00:00
|
|
|
using FlowID_t = AlignedBuffer< 32 >;
|
2019-02-18 19:44:41 +00:00
|
|
|
|
|
|
|
using OuterCommand_t = byte_t;
|
|
|
|
|
|
|
|
constexpr OuterCommand_t eOCMD_ObtainFlowID = 'O';
|
|
|
|
constexpr OuterCommand_t eOCMD_GiveFlowID = 'G';
|
|
|
|
constexpr OuterCommand_t eOCMD_Reject = 'R';
|
|
|
|
constexpr OuterCommand_t eOCMD_SessionNegotiate = 'S';
|
|
|
|
constexpr OuterCommand_t eOCMD_TransmitData = 'D';
|
|
|
|
|
|
|
|
using InnerCommand_t = byte_t;
|
|
|
|
|
|
|
|
constexpr InnerCommand_t eICMD_KeepAlive = 'k';
|
|
|
|
constexpr InnerCommand_t eICMD_KeepAliveAck = 'l';
|
|
|
|
constexpr InnerCommand_t eICMD_Congestion = 'c';
|
|
|
|
constexpr InnerCommand_t eICMD_AntiCongestion = 'd';
|
|
|
|
constexpr InnerCommand_t eICMD_Transmit = 't';
|
|
|
|
constexpr InnerCommand_t eICMD_Ack = 'a';
|
|
|
|
constexpr InnerCommand_t eICMD_RotateKeys = 'r';
|
|
|
|
constexpr InnerCommand_t eICMD_UpgradeProtocol = 'u';
|
|
|
|
constexpr InnerCommand_t eICMD_VersionUpgrade = 'v';
|
|
|
|
|
|
|
|
struct OuterMessage
|
|
|
|
{
|
2019-03-29 12:19:59 +00:00
|
|
|
// required members
|
2019-02-18 19:44:41 +00:00
|
|
|
byte_t command;
|
|
|
|
FlowID_t flow;
|
|
|
|
|
2019-03-07 15:17:29 +00:00
|
|
|
OuterMessage();
|
|
|
|
~OuterMessage();
|
|
|
|
|
|
|
|
// static members
|
|
|
|
static std::array< byte_t, 6 > obtain_flow_id_magic;
|
|
|
|
static std::array< byte_t, 6 > give_flow_id_magic;
|
|
|
|
|
|
|
|
void
|
|
|
|
CreateReject(const char *msg, llarp_time_t now, const PubKey &pk);
|
|
|
|
|
2019-03-29 12:19:59 +00:00
|
|
|
// optional members follow
|
2019-03-07 15:17:29 +00:00
|
|
|
std::array< byte_t, 6 > magic;
|
2019-02-18 19:44:41 +00:00
|
|
|
NetID netid;
|
2019-03-07 15:17:29 +00:00
|
|
|
// either timestamp or counter
|
|
|
|
uint64_t uinteger;
|
|
|
|
std::array< byte_t, 14 > reject;
|
2019-02-18 19:44:41 +00:00
|
|
|
AlignedBuffer< 24 > N;
|
2019-03-07 15:17:29 +00:00
|
|
|
PubKey pubkey;
|
|
|
|
|
|
|
|
std::unique_ptr< AlignedBuffer< 32 > > A;
|
|
|
|
|
|
|
|
static constexpr size_t ipv6_mtu = 1280;
|
|
|
|
static constexpr size_t overhead_size = 16 + 24 + 32;
|
|
|
|
static constexpr size_t payload_size = ipv6_mtu - overhead_size;
|
|
|
|
|
|
|
|
AlignedBuffer< payload_size > X;
|
2019-02-18 19:44:41 +00:00
|
|
|
size_t Xsize;
|
2019-03-07 15:17:29 +00:00
|
|
|
ShortHash Zhash;
|
|
|
|
Signature Zsig;
|
2019-02-18 19:44:41 +00:00
|
|
|
|
|
|
|
/// encode to buffer
|
|
|
|
bool
|
|
|
|
Encode(llarp_buffer_t *buf) const;
|
|
|
|
|
|
|
|
/// decode from buffer
|
|
|
|
bool
|
|
|
|
Decode(llarp_buffer_t *buf);
|
|
|
|
|
|
|
|
/// clear members
|
|
|
|
void
|
|
|
|
Clear();
|
|
|
|
};
|
2019-01-05 13:45:05 +00:00
|
|
|
} // namespace iwp
|
2019-01-02 14:14:02 +00:00
|
|
|
} // namespace llarp
|
|
|
|
#endif
|