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
|
|
|
|
2019-01-14 21:46:07 +00:00
|
|
|
#include <messages/link_message.hpp>
|
2018-12-12 02:04:32 +00:00
|
|
|
#include <routing/handler.hpp>
|
|
|
|
#include <routing/message.hpp>
|
2019-01-10 19:41:51 +00:00
|
|
|
#include <util/bencode.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
|
|
|
|
{
|
2019-11-03 15:31:01 +00:00
|
|
|
version = 0;
|
2018-12-20 16:49:05 +00:00
|
|
|
}
|
|
|
|
|
2019-03-26 20:04:41 +00:00
|
|
|
const char*
|
|
|
|
Name() const override
|
|
|
|
{
|
|
|
|
return "Discard";
|
|
|
|
}
|
|
|
|
|
2018-09-06 20:31:58 +00:00
|
|
|
bool
|
2019-11-14 16:48:02 +00:00
|
|
|
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf) override
|
2018-09-06 20:31:58 +00:00
|
|
|
{
|
2019-11-14 16:48:02 +00:00
|
|
|
if(key == "a")
|
|
|
|
{
|
|
|
|
llarp_buffer_t strbuf;
|
|
|
|
if(!bencode_read_string(buf, &strbuf))
|
|
|
|
return false;
|
|
|
|
if(strbuf.sz != 1)
|
|
|
|
return false;
|
|
|
|
return *strbuf.cur == 'x';
|
|
|
|
}
|
2018-09-06 20:31:58 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2019-04-19 18:24:33 +00:00
|
|
|
HandleMessage(ABSL_ATTRIBUTE_UNUSED AbstractRouter* 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;
|
|
|
|
|
2019-06-15 14:55:13 +00:00
|
|
|
DataDiscardMessage() = default;
|
2018-09-11 15:28:36 +00:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-01-14 21:46:07 +00:00
|
|
|
void
|
|
|
|
Clear() override
|
|
|
|
{
|
2019-11-03 15:31:01 +00:00
|
|
|
version = 0;
|
2019-01-14 21:46:07 +00:00
|
|
|
}
|
2018-12-27 14:32:37 +00:00
|
|
|
|
2018-09-11 15:28:36 +00:00
|
|
|
bool
|
2019-02-11 19:45:42 +00:00
|
|
|
HandleMessage(IMessageHandler* h, AbstractRouter* r) const override
|
2018-09-11 15:28:36 +00:00
|
|
|
{
|
2019-04-22 17:38:29 +00:00
|
|
|
return h->HandleDataDiscardMessage(*this, r);
|
2018-09-11 15:28:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2019-02-01 01:58:06 +00:00
|
|
|
DecodeKey(const 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
|