mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-10-29 11:05:43 +00:00
71 lines
1.8 KiB
C++
71 lines
1.8 KiB
C++
#include <endian.hpp>
|
|
#include <messages/transfer_traffic.hpp>
|
|
#include <routing/handler.hpp>
|
|
|
|
namespace llarp
|
|
{
|
|
namespace routing
|
|
{
|
|
TransferTrafficMessage&
|
|
TransferTrafficMessage::operator=(const TransferTrafficMessage& other)
|
|
{
|
|
S = other.S;
|
|
version = other.version;
|
|
X = other.X;
|
|
return *this;
|
|
}
|
|
|
|
bool
|
|
TransferTrafficMessage::PutBuffer(llarp_buffer_t buf, uint64_t counter)
|
|
{
|
|
if(buf.sz > MaxExitMTU)
|
|
return false;
|
|
X.emplace_back(buf.sz + 8);
|
|
byte_t* ptr = X.back().data();
|
|
htobe64buf(ptr, counter);
|
|
ptr += 8;
|
|
memcpy(ptr, buf.base, buf.sz);
|
|
// 8 bytes encoding overhead and 8 bytes counter
|
|
_size += buf.sz + 16;
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
TransferTrafficMessage::BEncode(llarp_buffer_t* buf) const
|
|
{
|
|
if(!bencode_start_dict(buf))
|
|
return false;
|
|
if(!BEncodeWriteDictMsgType(buf, "A", "I"))
|
|
return false;
|
|
if(!BEncodeWriteDictInt("S", S, buf))
|
|
return false;
|
|
if(!BEncodeWriteDictInt("V", version, buf))
|
|
return false;
|
|
if(!BEncodeWriteDictList("X", X, buf))
|
|
return false;
|
|
return bencode_end(buf);
|
|
}
|
|
|
|
bool
|
|
TransferTrafficMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf)
|
|
{
|
|
bool read = false;
|
|
if(!BEncodeMaybeReadDictInt("S", S, read, key, buf))
|
|
return false;
|
|
if(!BEncodeMaybeReadDictInt("V", version, read, key, buf))
|
|
return false;
|
|
if(!BEncodeMaybeReadDictList("X", X, read, key, buf))
|
|
return false;
|
|
return read;
|
|
}
|
|
|
|
bool
|
|
TransferTrafficMessage::HandleMessage(IMessageHandler* h,
|
|
llarp::Router* r) const
|
|
{
|
|
return h->HandleTransferTrafficMessage(this, r);
|
|
}
|
|
|
|
} // namespace routing
|
|
} // namespace llarp
|