lokinet/llarp/routing/path_transfer_message.cpp

59 lines
1.5 KiB
C++
Raw Normal View History

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