2018-09-06 20:31:58 +00:00
|
|
|
#ifndef LLARP_MESSAGES_DISCARD_HPP
|
|
|
|
#define LLARP_MESSAGES_DISCARD_HPP
|
2018-12-12 02:04:32 +00:00
|
|
|
|
2018-12-12 02:52:51 +00:00
|
|
|
#include <bencode.hpp>
|
2018-12-12 01:32:10 +00:00
|
|
|
#include <link_message.hpp>
|
2018-12-12 02:04:32 +00:00
|
|
|
#include <routing/handler.hpp>
|
|
|
|
#include <routing/message.hpp>
|
2018-09-11 15:28:36 +00:00
|
|
|
|
2018-09-06 20:31:58 +00:00
|
|
|
namespace llarp
|
|
|
|
{
|
2018-11-05 11:27:12 +00:00
|
|
|
struct DiscardMessage final : public ILinkMessage
|
2018-09-06 20:31:58 +00:00
|
|
|
{
|
2018-12-20 16:49:05 +00:00
|
|
|
DiscardMessage() : ILinkMessage()
|
2018-09-06 20:31:58 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2018-11-05 11:27:12 +00:00
|
|
|
BEncode(llarp_buffer_t* buf) const override
|
2018-09-06 20:31:58 +00:00
|
|
|
{
|
|
|
|
if(!bencode_start_dict(buf))
|
|
|
|
return false;
|
|
|
|
if(!bencode_write_bytestring(buf, "a", 1))
|
|
|
|
return false;
|
|
|
|
if(!bencode_write_bytestring(buf, "x", 1))
|
|
|
|
return false;
|
|
|
|
return bencode_end(buf);
|
|
|
|
}
|
|
|
|
|
2018-12-20 16:49:05 +00:00
|
|
|
void
|
|
|
|
Clear() override
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-09-06 20:31:58 +00:00
|
|
|
bool
|
2018-11-07 15:30:22 +00:00
|
|
|
DecodeKey(__attribute__((unused)) llarp_buffer_t key,
|
|
|
|
__attribute__((unused)) llarp_buffer_t* buf) override
|
2018-09-06 20:31:58 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2018-12-10 16:26:46 +00:00
|
|
|
HandleMessage(__attribute__((unused)) llarp::Router* router) const override
|
2018-09-06 20:31:58 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2018-09-11 15:28:36 +00:00
|
|
|
|
|
|
|
namespace routing
|
|
|
|
{
|
2018-11-05 11:27:12 +00:00
|
|
|
struct DataDiscardMessage final : public IMessage
|
2018-09-11 15:28:36 +00:00
|
|
|
{
|
|
|
|
PathID_t P;
|
|
|
|
|
|
|
|
DataDiscardMessage() : IMessage()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-09-11 15:34:12 +00:00
|
|
|
DataDiscardMessage(const PathID_t& dst, uint64_t s) : P(dst)
|
2018-09-11 15:28:36 +00:00
|
|
|
{
|
|
|
|
S = s;
|
|
|
|
version = LLARP_PROTO_VERSION;
|
|
|
|
}
|
|
|
|
|
2018-12-27 14:32:37 +00:00
|
|
|
void Clear() override {}
|
|
|
|
|
2018-09-11 15:28:36 +00:00
|
|
|
bool
|
2018-12-10 16:26:46 +00:00
|
|
|
HandleMessage(IMessageHandler* h, llarp::Router* r) const override
|
2018-09-11 15:28:36 +00:00
|
|
|
{
|
|
|
|
return h->HandleDataDiscardMessage(this, r);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2018-11-05 11:27:12 +00:00
|
|
|
DecodeKey(llarp_buffer_t k, llarp_buffer_t* buf) override
|
2018-09-11 15:28:36 +00:00
|
|
|
{
|
|
|
|
bool read = false;
|
|
|
|
if(!BEncodeMaybeReadDictEntry("P", P, read, k, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeMaybeReadDictInt("S", S, read, k, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeMaybeReadDictInt("V", version, read, k, buf))
|
|
|
|
return false;
|
|
|
|
return read;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2018-11-05 11:27:12 +00:00
|
|
|
BEncode(llarp_buffer_t* buf) const override
|
2018-09-11 15:28:36 +00:00
|
|
|
{
|
|
|
|
if(!bencode_start_dict(buf))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(!BEncodeWriteDictMsgType(buf, "A", "D"))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeWriteDictEntry("P", P, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeWriteDictInt("S", S, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeWriteDictInt("V", version, buf))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return bencode_end(buf);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // namespace routing
|
|
|
|
|
2018-09-06 20:31:58 +00:00
|
|
|
} // namespace llarp
|
|
|
|
|
|
|
|
#endif
|