lokinet/llarp/routing/path_transfer_message.cpp
dr7ana 11e54f6552 More message refactoring
- routing messages and surrounding code
- shim code in place for iteration and optimization after deciding what to do with buffer, string handling, and subsequent function calls
2023-08-31 09:28:16 -07:00

53 lines
1.3 KiB
C++

#include "path_transfer_message.hpp"
#include "handler.hpp"
#include <llarp/util/buffer.hpp>
namespace llarp::routing
{
bool
PathTransferMessage::decode_key(const llarp_buffer_t& key, llarp_buffer_t* val)
{
bool read = false;
if (!BEncodeMaybeReadDictEntry("P", path_id, read, key, val))
return false;
if (!BEncodeMaybeReadDictInt("S", sequence_number, read, key, val))
return false;
if (!BEncodeMaybeReadDictEntry("T", protocol_frame_msg, read, key, val))
return false;
if (!BEncodeMaybeReadDictInt("V", version, read, key, val))
return false;
if (!BEncodeMaybeReadDictEntry("Y", nonce, read, key, val))
return false;
return read;
}
std::string
PathTransferMessage::bt_encode() const
{
oxenc::bt_dict_producer btdp;
try
{
btdp.append("A", "T");
btdp.append("P", path_id.ToView());
btdp.append("T", protocol_frame_msg.bt_encode());
btdp.append("V", version);
btdp.append("Y", nonce.ToView());
}
catch (...)
{
log::critical(route_cat, "Error: PathTransferMessage failed to bt encode contents!");
}
return std::move(btdp).str();
}
bool
PathTransferMessage::handle_message(AbstractRoutingMessageHandler* h, AbstractRouter* r) const
{
return h->HandlePathTransferMessage(*this, r);
}
} // namespace llarp::routing