39 , m_linkService(linkService)
43 std::tuple<bool, Block, lp::Packet>
48 static auto FALSE_RETURN = std::make_tuple(
false,
Block(),
lp::Packet());
51 uint64_t fragIndex = 0;
52 uint64_t fragCount = 1;
60 if (fragIndex >= fragCount) {
71 if (fragIndex == 0 && fragCount == 1) {
72 ndn::Buffer::const_iterator fragBegin, fragEnd;
74 Block netPkt(&*fragBegin, std::distance(fragBegin, fragEnd));
75 return std::make_tuple(
true, netPkt, packet);
84 Key key = std::make_tuple(remoteEndpoint, messageIdentifier);
87 PartialPacket& pp = m_partialPackets[key];
88 if (pp.fragCount == 0) {
89 pp.fragCount = fragCount;
90 pp.nReceivedFragments = 0;
91 pp.fragments.resize(fragCount);
94 if (fragCount != pp.fragCount) {
105 pp.fragments[fragIndex] = packet;
106 ++pp.nReceivedFragments;
109 if (pp.nReceivedFragments == pp.fragCount) {
110 Block reassembled = doReassembly(key);
112 m_partialPackets.erase(key);
113 return std::make_tuple(
true, reassembled, firstFrag);
123 LpReassembler::doReassembly(
const Key& key)
125 PartialPacket& pp = m_partialPackets[key];
127 size_t payloadSize = std::accumulate(pp.fragments.begin(), pp.fragments.end(), 0U,
128 [&] (
size_t sum,
const lp::Packet& pkt) ->
size_t {
129 ndn::Buffer::const_iterator fragBegin, fragEnd;
130 std::tie(fragBegin, fragEnd) = pkt.get<lp::FragmentField>();
131 return sum + std::distance(fragBegin, fragEnd);
135 auto it = fragBuffer.begin();
138 ndn::Buffer::const_iterator fragBegin, fragEnd;
140 it = std::copy(fragBegin, fragEnd, it);
143 return Block(&*(fragBuffer.cbegin()), std::distance(fragBuffer.cbegin(), fragBuffer.cend()));
147 LpReassembler::timeoutPartialPacket(
const Key& key)
149 auto it = m_partialPackets.find(key);
150 if (it == m_partialPackets.end()) {
154 this->
beforeTimeout(std::get<0>(key), it->second.nReceivedFragments);
155 m_partialPackets.erase(it);
162 os <<
"[id=0,local=unknown,remote=unknown] ";