2018-12-12 02:52:51 +00:00
|
|
|
#include <messages/transfer_traffic.hpp>
|
2019-01-10 19:41:51 +00:00
|
|
|
|
2018-12-12 02:04:32 +00:00
|
|
|
#include <routing/handler.hpp>
|
2019-01-10 19:41:51 +00:00
|
|
|
#include <util/endian.hpp>
|
2018-11-12 16:43:40 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace routing
|
|
|
|
{
|
|
|
|
bool
|
2019-02-01 01:58:06 +00:00
|
|
|
TransferTrafficMessage::PutBuffer(const llarp_buffer_t& buf,
|
|
|
|
uint64_t counter)
|
2018-11-12 16:43:40 +00:00
|
|
|
{
|
|
|
|
if(buf.sz > MaxExitMTU)
|
|
|
|
return false;
|
2018-11-29 21:19:20 +00:00
|
|
|
X.emplace_back(buf.sz + 8);
|
2018-12-02 18:07:07 +00:00
|
|
|
byte_t* ptr = X.back().data();
|
2018-11-29 21:19:20 +00:00
|
|
|
htobe64buf(ptr, counter);
|
|
|
|
ptr += 8;
|
|
|
|
memcpy(ptr, buf.base, buf.sz);
|
|
|
|
// 8 bytes encoding overhead and 8 bytes counter
|
|
|
|
_size += buf.sz + 16;
|
2018-11-12 16:43:40 +00:00
|
|
|
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;
|
2018-11-28 16:38:20 +00:00
|
|
|
if(!BEncodeWriteDictList("X", X, buf))
|
2018-11-12 16:43:40 +00:00
|
|
|
return false;
|
|
|
|
return bencode_end(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2019-02-01 01:58:06 +00:00
|
|
|
TransferTrafficMessage::DecodeKey(const llarp_buffer_t& key,
|
|
|
|
llarp_buffer_t* buf)
|
2018-11-12 16:43:40 +00:00
|
|
|
{
|
|
|
|
bool read = false;
|
|
|
|
if(!BEncodeMaybeReadDictInt("S", S, read, key, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeMaybeReadDictInt("V", version, read, key, buf))
|
|
|
|
return false;
|
2018-11-28 16:38:20 +00:00
|
|
|
if(!BEncodeMaybeReadDictList("X", X, read, key, buf))
|
|
|
|
return false;
|
2018-11-12 16:43:40 +00:00
|
|
|
return read;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
TransferTrafficMessage::HandleMessage(IMessageHandler* h,
|
2019-02-11 19:45:42 +00:00
|
|
|
AbstractRouter* r) const
|
2018-11-12 16:43:40 +00:00
|
|
|
{
|
2019-04-22 17:38:29 +00:00
|
|
|
return h->HandleTransferTrafficMessage(*this, r);
|
2018-11-12 16:43:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace routing
|
2018-12-10 16:26:46 +00:00
|
|
|
} // namespace llarp
|