2019-06-19 22:30:07 +00:00
|
|
|
#include <routing/path_transfer_message.hpp>
|
2019-06-15 14:55:13 +00:00
|
|
|
|
|
|
|
#include <routing/handler.hpp>
|
|
|
|
#include <util/buffer.hpp>
|
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace routing
|
|
|
|
{
|
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
PathTransferMessage::DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* val)
|
2019-06-15 14:55:13 +00:00
|
|
|
{
|
|
|
|
bool read = false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictEntry("P", P, read, key, val))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictInt("S", S, read, key, val))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictEntry("T", T, read, key, val))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictInt("V", version, read, key, val))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictEntry("Y", Y, read, key, val))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
|
|
|
return read;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PathTransferMessage::BEncode(llarp_buffer_t* buf) const
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!bencode_start_dict(buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictMsgType(buf, "A", "T"))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictEntry("P", P, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictInt("S", S, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictEntry("T", T, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictInt("V", LLARP_PROTO_VERSION, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictEntry("Y", Y, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return bencode_end(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
PathTransferMessage::HandleMessage(IMessageHandler* h, AbstractRouter* r) const
|
2019-06-15 14:55:13 +00:00
|
|
|
{
|
|
|
|
return h->HandlePathTransferMessage(*this, r);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace routing
|
|
|
|
} // namespace llarp
|