2019-06-04 18:31:17 +00:00
|
|
|
#ifndef LLARP_RELAY_STATUS_HPP
|
|
|
|
#define LLARP_RELAY_STATUS_HPP
|
|
|
|
|
|
|
|
#include <crypto/encrypted_frame.hpp>
|
|
|
|
#include <crypto/types.hpp>
|
|
|
|
#include <messages/link_message.hpp>
|
|
|
|
#include <path/path_types.hpp>
|
|
|
|
#include <pow.hpp>
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <memory>
|
2019-07-30 23:42:13 +00:00
|
|
|
#include <utility>
|
2019-06-04 18:31:17 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
// forward declare
|
|
|
|
struct AbstractRouter;
|
|
|
|
namespace path
|
|
|
|
{
|
|
|
|
struct PathContext;
|
|
|
|
struct IHopHandler;
|
|
|
|
} // namespace path
|
|
|
|
|
|
|
|
struct LR_StatusRecord
|
|
|
|
{
|
2019-09-04 12:24:17 +00:00
|
|
|
static constexpr uint64_t SUCCESS = 1 << 0;
|
2019-06-04 18:31:17 +00:00
|
|
|
static constexpr uint64_t FAIL_TIMEOUT = 1 << 1;
|
|
|
|
static constexpr uint64_t FAIL_CONGESTION = 1 << 2;
|
|
|
|
static constexpr uint64_t FAIL_DEST_UNKNOWN = 1 << 3;
|
|
|
|
static constexpr uint64_t FAIL_DECRYPT_ERROR = 1 << 4;
|
|
|
|
static constexpr uint64_t FAIL_MALFORMED_RECORD = 1 << 5;
|
|
|
|
static constexpr uint64_t FAIL_DEST_INVALID = 1 << 6;
|
|
|
|
static constexpr uint64_t FAIL_CANNOT_CONNECT = 1 << 7;
|
2019-09-04 12:24:17 +00:00
|
|
|
static constexpr uint64_t FAIL_DUPLICATE_HOP = 1 << 8;
|
2019-06-04 18:31:17 +00:00
|
|
|
|
|
|
|
uint64_t status = 0;
|
|
|
|
uint64_t version = 0;
|
|
|
|
|
|
|
|
bool
|
|
|
|
BDecode(llarp_buffer_t *buf);
|
|
|
|
|
|
|
|
bool
|
|
|
|
BEncode(llarp_buffer_t *buf) const;
|
|
|
|
|
|
|
|
bool
|
|
|
|
operator==(const LR_StatusRecord &other) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool
|
|
|
|
OnKey(llarp_buffer_t *buffer, llarp_buffer_t *key);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct LR_StatusMessage : public ILinkMessage
|
|
|
|
{
|
|
|
|
std::array< EncryptedFrame, 8 > frames;
|
|
|
|
|
|
|
|
PathID_t pathid;
|
|
|
|
|
|
|
|
uint64_t status = 0;
|
|
|
|
|
2019-07-30 23:42:13 +00:00
|
|
|
LR_StatusMessage(std::array< EncryptedFrame, 8 > _frames)
|
|
|
|
: ILinkMessage(), frames(std::move(_frames))
|
2019-06-04 18:31:17 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
LR_StatusMessage() = default;
|
|
|
|
|
2019-07-30 23:42:13 +00:00
|
|
|
~LR_StatusMessage() override = default;
|
2019-06-04 18:31:17 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
Clear() override;
|
|
|
|
|
|
|
|
bool
|
|
|
|
DecodeKey(const llarp_buffer_t &key, llarp_buffer_t *buf) override;
|
|
|
|
|
|
|
|
bool
|
|
|
|
BEncode(llarp_buffer_t *buf) const override;
|
|
|
|
|
|
|
|
bool
|
|
|
|
HandleMessage(AbstractRouter *router) const override;
|
|
|
|
|
|
|
|
void
|
|
|
|
SetDummyFrames();
|
|
|
|
|
|
|
|
static bool
|
|
|
|
CreateAndSend(AbstractRouter *router, const PathID_t pathid,
|
|
|
|
const RouterID nextHop, const SharedSecret pathKey,
|
|
|
|
uint64_t status);
|
|
|
|
|
|
|
|
bool
|
2019-08-01 07:44:26 +00:00
|
|
|
AddFrame(const SharedSecret &pathKey, uint64_t newStatus);
|
2019-06-04 18:31:17 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
QueueSendMessage(AbstractRouter *router, const RouterID nextHop,
|
|
|
|
std::shared_ptr< LR_StatusMessage > msg);
|
|
|
|
|
|
|
|
static void
|
|
|
|
SendMessage(AbstractRouter *router, const RouterID nextHop,
|
|
|
|
std::shared_ptr< LR_StatusMessage > msg);
|
|
|
|
|
|
|
|
const char *
|
|
|
|
Name() const override
|
|
|
|
{
|
|
|
|
return "RelayStatus";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // namespace llarp
|
|
|
|
|
|
|
|
#endif
|