2021-03-09 22:24:35 +00:00
|
|
|
#include "path_transfer_message.hpp"
|
2019-06-15 14:55:13 +00:00
|
|
|
|
2021-03-09 22:24:35 +00:00
|
|
|
#include "handler.hpp"
|
|
|
|
#include <llarp/util/buffer.hpp>
|
2019-06-15 14:55:13 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2022-05-26 15:59:44 +00:00
|
|
|
if (!BEncodeWriteDictInt("V", llarp::constants::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
|