lokinet/llarp/exit/exit_messages.hpp

220 lines
4.2 KiB
C++
Raw Normal View History

2019-06-15 14:55:14 +00:00
#ifndef LLARP_EXIT_MESSAGES_HPP
#define LLARP_EXIT_MESSAGES_HPP
2019-01-13 14:00:50 +00:00
#include <crypto/types.hpp>
2018-12-12 01:06:46 +00:00
#include <exit/policy.hpp>
2018-12-12 02:04:32 +00:00
#include <routing/message.hpp>
2018-12-12 01:06:46 +00:00
#include <vector>
namespace llarp
{
namespace routing
{
struct ObtainExitMessage final : public IMessage
{
std::vector< llarp::exit::Policy > B;
2019-07-30 23:42:13 +00:00
uint64_t E{0};
llarp::PubKey I;
2019-07-30 23:42:13 +00:00
uint64_t T{0};
std::vector< llarp::exit::Policy > W;
2019-07-30 23:42:13 +00:00
llarp_time_t X{0};
llarp::Signature Z;
2019-07-30 23:42:13 +00:00
ObtainExitMessage() : IMessage()
{
}
2019-07-30 23:42:13 +00:00
~ObtainExitMessage() override = default;
void
Clear() override
{
B.clear();
E = 0;
I.Zero();
T = 0;
W.clear();
X = 0;
Z.Zero();
}
/// populates I and signs
bool
Sign(const llarp::SecretKey& sk);
bool
Verify() const;
bool
BEncode(llarp_buffer_t* buf) const override;
bool
2019-02-05 00:41:33 +00:00
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf) override;
bool
HandleMessage(IMessageHandler* h, AbstractRouter* r) const override;
};
struct GrantExitMessage final : public IMessage
{
2018-11-14 18:02:27 +00:00
using Nonce_t = llarp::AlignedBuffer< 16 >;
2019-05-19 22:11:07 +00:00
2018-11-14 12:23:08 +00:00
uint64_t T;
2018-11-14 18:02:27 +00:00
Nonce_t Y;
llarp::Signature Z;
bool
BEncode(llarp_buffer_t* buf) const override;
2018-11-14 18:02:27 +00:00
bool
Sign(const llarp::SecretKey& sk);
2018-11-14 18:02:27 +00:00
bool
Verify(const llarp::PubKey& pk) const;
2018-11-14 18:02:27 +00:00
bool
2019-02-05 00:41:33 +00:00
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf) override;
bool
HandleMessage(IMessageHandler* h, AbstractRouter* r) const override;
void
Clear() override
{
T = 0;
Y.Zero();
Z.Zero();
}
};
struct RejectExitMessage final : public IMessage
{
2018-11-14 18:02:27 +00:00
using Nonce_t = llarp::AlignedBuffer< 16 >;
2018-11-14 12:23:08 +00:00
uint64_t B;
std::vector< llarp::exit::Policy > R;
uint64_t T;
2018-11-14 18:02:27 +00:00
Nonce_t Y;
llarp::Signature Z;
2018-11-14 12:23:08 +00:00
void
Clear() override
{
B = 0;
R.clear();
T = 0;
Y.Zero();
Z.Zero();
}
2018-11-14 18:02:27 +00:00
bool
Sign(const llarp::SecretKey& sk);
2018-11-14 18:02:27 +00:00
bool
Verify(const llarp::PubKey& pk) const;
2018-11-14 18:02:27 +00:00
bool
BEncode(llarp_buffer_t* buf) const override;
bool
2019-02-05 00:41:33 +00:00
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf) override;
bool
HandleMessage(IMessageHandler* h, AbstractRouter* r) const override;
};
2018-11-14 12:23:08 +00:00
struct UpdateExitVerifyMessage final : public IMessage
{
2018-11-14 18:02:27 +00:00
using Nonce_t = llarp::AlignedBuffer< 16 >;
2018-11-14 12:23:08 +00:00
uint64_t T;
2018-11-14 18:02:27 +00:00
Nonce_t Y;
llarp::Signature Z;
2018-11-14 12:23:08 +00:00
2019-07-30 23:42:13 +00:00
~UpdateExitVerifyMessage() override = default;
2018-11-14 12:23:08 +00:00
void
Clear() override
{
T = 0;
Y.Zero();
Z.Zero();
}
2018-11-14 12:23:08 +00:00
bool
BEncode(llarp_buffer_t* buf) const override;
bool
2019-02-05 00:41:33 +00:00
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf) override;
2018-11-14 12:23:08 +00:00
bool
HandleMessage(IMessageHandler* h, AbstractRouter* r) const override;
2018-11-14 12:23:08 +00:00
};
struct UpdateExitMessage final : public IMessage
{
2018-11-14 18:02:27 +00:00
using Nonce_t = llarp::AlignedBuffer< 16 >;
2018-11-14 12:23:08 +00:00
llarp::PathID_t P;
uint64_t T;
2018-11-14 18:02:27 +00:00
Nonce_t Y;
2018-11-14 12:23:08 +00:00
llarp::Signature Z;
bool
Sign(const llarp::SecretKey& sk);
2018-11-14 12:23:08 +00:00
bool
Verify(const llarp::PubKey& pk) const;
2018-11-14 12:23:08 +00:00
bool
BEncode(llarp_buffer_t* buf) const override;
bool
2019-02-05 00:41:33 +00:00
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf) override;
bool
HandleMessage(IMessageHandler* h, AbstractRouter* r) const override;
void
Clear() override
{
P.Zero();
T = 0;
Y.Zero();
Z.Zero();
}
};
struct CloseExitMessage final : public IMessage
{
2018-11-14 18:02:27 +00:00
using Nonce_t = llarp::AlignedBuffer< 16 >;
Nonce_t Y;
llarp::Signature Z;
bool
BEncode(llarp_buffer_t* buf) const override;
bool
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf) override;
bool
HandleMessage(IMessageHandler* h, AbstractRouter* r) const override;
2018-11-14 18:02:27 +00:00
bool
Sign(const llarp::SecretKey& sk);
2018-11-14 18:02:27 +00:00
bool
Verify(const llarp::PubKey& pk) const;
void
Clear() override
{
Y.Zero();
Z.Zero();
}
};
} // namespace routing
} // namespace llarp
#endif