lokinet/llarp/routing/path_transfer.cpp

69 lines
1.7 KiB
C++
Raw Normal View History

#include <messages/path_transfer.hpp>
#include <routing/handler.hpp>
#include <util/buffer.hpp>
namespace llarp
{
namespace routing
{
PathTransferMessage::PathTransferMessage() : IMessage()
{
}
PathTransferMessage::~PathTransferMessage()
{
}
bool
2019-02-05 00:41:33 +00:00
PathTransferMessage::DecodeKey(const llarp_buffer_t& key,
llarp_buffer_t* val)
{
bool read = false;
if(!BEncodeMaybeReadDictEntry("P", P, read, key, val))
return false;
if(!BEncodeMaybeReadDictInt("S", S, read, key, val))
return false;
2018-08-12 17:22:29 +00:00
if(!BEncodeMaybeReadDictEntry("T", T, read, key, val))
return false;
if(!BEncodeMaybeReadDictInt("V", version, read, key, val))
return false;
if(!BEncodeMaybeReadDictEntry("Y", Y, read, key, val))
return false;
2018-08-12 17:22:29 +00:00
return read;
}
bool
PathTransferMessage::BEncode(llarp_buffer_t* buf) const
{
if(!bencode_start_dict(buf))
return false;
if(!BEncodeWriteDictMsgType(buf, "A", "T"))
return false;
if(!BEncodeWriteDictEntry("P", P, buf))
return false;
2018-07-22 23:14:29 +00:00
if(!BEncodeWriteDictInt("S", S, buf))
return false;
2018-08-12 17:22:29 +00:00
if(!BEncodeWriteDictEntry("T", T, buf))
return false;
2018-07-22 23:14:29 +00:00
if(!BEncodeWriteDictInt("V", LLARP_PROTO_VERSION, buf))
return false;
if(!BEncodeWriteDictEntry("Y", Y, buf))
return false;
return bencode_end(buf);
}
bool
PathTransferMessage::HandleMessage(IMessageHandler* h,
AbstractRouter* r) const
{
2018-08-12 17:22:29 +00:00
return h->HandlePathTransferMessage(this, r);
}
2018-07-22 23:14:29 +00:00
} // namespace routing
} // namespace llarp