2018-06-03 13:04:51 +00:00
|
|
|
#ifndef LLARP_MESSAGES_DISCARD_HPP
|
|
|
|
#define LLARP_MESSAGES_DISCARD_HPP
|
|
|
|
#include <llarp/link_message.hpp>
|
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
2018-06-06 12:46:26 +00:00
|
|
|
const std::size_t MAX_DISCARD_SIZE = 10000;
|
|
|
|
|
2018-06-03 13:04:51 +00:00
|
|
|
/// a dummy link message that is discarded
|
|
|
|
struct DiscardMessage : public ILinkMessage
|
|
|
|
{
|
2018-06-06 12:46:26 +00:00
|
|
|
byte_t pad[MAX_DISCARD_SIZE];
|
|
|
|
size_t sz = 0;
|
2018-06-03 13:04:51 +00:00
|
|
|
|
|
|
|
DiscardMessage(const RouterID& id) : ILinkMessage(id)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-06-06 12:46:26 +00:00
|
|
|
DiscardMessage(std::size_t padding) : ILinkMessage()
|
2018-06-03 13:04:51 +00:00
|
|
|
{
|
2018-06-06 12:46:26 +00:00
|
|
|
sz = padding;
|
|
|
|
memset(pad, 'z', sz);
|
2018-06-03 13:04:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool
|
|
|
|
DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf)
|
|
|
|
{
|
|
|
|
llarp_buffer_t strbuf;
|
|
|
|
if(llarp_buffer_eq(key, "v"))
|
|
|
|
{
|
|
|
|
if(!bencode_read_integer(buf, &version))
|
|
|
|
return false;
|
|
|
|
return version == LLARP_PROTO_VERSION;
|
|
|
|
}
|
|
|
|
if(llarp_buffer_eq(key, "z"))
|
|
|
|
{
|
|
|
|
if(!bencode_read_string(buf, &strbuf))
|
|
|
|
return false;
|
2018-06-06 12:46:26 +00:00
|
|
|
if(strbuf.sz > MAX_DISCARD_SIZE)
|
|
|
|
return false;
|
|
|
|
sz = strbuf.sz;
|
|
|
|
memcpy(pad, strbuf.base, sz);
|
2018-06-03 13:04:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool
|
|
|
|
BEncode(llarp_buffer_t* buf) const
|
|
|
|
{
|
|
|
|
if(!bencode_start_dict(buf))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(!bencode_write_bytestring(buf, "a", 1))
|
|
|
|
return false;
|
|
|
|
if(!bencode_write_bytestring(buf, "z", 1))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(!bencode_write_version_entry(buf))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(!bencode_write_bytestring(buf, "z", 1))
|
|
|
|
return false;
|
2018-06-06 12:46:26 +00:00
|
|
|
if(!bencode_write_bytestring(buf, pad, sz))
|
2018-06-03 13:04:51 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return bencode_end(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool
|
|
|
|
HandleMessage(llarp_router* router) const
|
|
|
|
{
|
|
|
|
(void)router;
|
2018-07-05 15:44:06 +00:00
|
|
|
llarp::LogInfo("got discard message of size ", sz, " bytes");
|
2018-06-03 13:04:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2018-07-05 15:44:06 +00:00
|
|
|
} // namespace llarp
|
2018-06-03 13:04:51 +00:00
|
|
|
|
|
|
|
#endif
|