2019-06-19 22:30:07 +00:00
|
|
|
#include <routing/transfer_traffic_message.hpp>
|
2019-06-15 14:55:13 +00:00
|
|
|
|
|
|
|
#include <routing/handler.hpp>
|
|
|
|
#include <util/bencode.hpp>
|
|
|
|
#include <util/endian.hpp>
|
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace routing
|
|
|
|
{
|
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
TransferTrafficMessage::PutBuffer(const llarp_buffer_t& buf, uint64_t counter)
|
2019-06-15 14:55:13 +00:00
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
if (buf.sz > MaxExitMTU)
|
2019-06-15 14:55:13 +00:00
|
|
|
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
|
|
|
|
{
|
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", "I"))
|
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 (!BEncodeWriteDictInt("V", version, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictList("X", X, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
|
|
|
return bencode_end(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
TransferTrafficMessage::DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf)
|
2019-06-15 14:55:13 +00:00
|
|
|
{
|
|
|
|
bool read = false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictInt("S", S, read, key, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictInt("V", version, read, key, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictList("X", X, read, key, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
|
|
|
return read;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
TransferTrafficMessage::HandleMessage(IMessageHandler* h, AbstractRouter* r) const
|
2019-06-15 14:55:13 +00:00
|
|
|
{
|
|
|
|
return h->HandleTransferTrafficMessage(*this, r);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace routing
|
|
|
|
} // namespace llarp
|