37 , reassemblyTimeout(
time::milliseconds(500))
43 , m_linkService(linkService)
47 std::tuple<bool, Block, lp::Packet>
52 static auto FALSE_RETURN = std::make_tuple(
false,
Block(),
lp::Packet());
55 uint64_t fragIndex = 0;
56 uint64_t fragCount = 1;
64 if (fragIndex >= fragCount) {
75 if (fragIndex == 0 && fragCount == 1) {
76 ndn::Buffer::const_iterator fragBegin, fragEnd;
78 Block netPkt(&*fragBegin, std::distance(fragBegin, fragEnd));
79 return std::make_tuple(
true, netPkt, packet);
88 Key key = std::make_tuple(remoteEndpoint, messageIdentifier);
91 PartialPacket& pp = m_partialPackets[key];
92 if (pp.fragCount == 0) {
93 pp.fragCount = fragCount;
94 pp.nReceivedFragments = 0;
95 pp.fragments.resize(fragCount);
98 if (fragCount != pp.fragCount) {
109 pp.fragments[fragIndex] = packet;
110 ++pp.nReceivedFragments;
113 if (pp.nReceivedFragments == pp.fragCount) {
114 Block reassembled = doReassembly(key);
115 lp::Packet firstFrag(std::move(pp.fragments[0]));
116 m_partialPackets.erase(key);
117 return std::make_tuple(
true, reassembled, firstFrag);
122 bind(&LpReassembler::timeoutPartialPacket,
this, key));
128 LpReassembler::doReassembly(
const Key& key)
130 PartialPacket& pp = m_partialPackets[key];
132 size_t payloadSize = std::accumulate(pp.fragments.begin(), pp.fragments.end(), 0,
133 [&] (
size_t sum,
const lp::Packet& pkt) ->
size_t {
134 ndn::Buffer::const_iterator fragBegin, fragEnd;
136 return sum + std::distance(fragBegin, fragEnd);
143 ndn::Buffer::const_iterator fragBegin, fragEnd;
145 it = std::copy(fragBegin, fragEnd, it);
148 return Block(&*(fragBuffer.cbegin()), std::distance(fragBuffer.cbegin(), fragBuffer.cend()));
152 LpReassembler::timeoutPartialPacket(
const Key& key)
154 auto it = m_partialPackets.find(key);
155 if (it == m_partialPackets.end()) {
159 this->
beforeTimeout(std::get<0>(key), it->second.nReceivedFragments);
160 m_partialPackets.erase(it);
164 operator<<(std::ostream& os, const FaceLogHelper<LpReassembler>& flh)
166 if (flh.obj.getLinkService() ==
nullptr) {
167 os <<
"[id=0,local=unknown,remote=unknown] ";
170 os << FaceLogHelper<LinkService>(*flh.obj.getLinkService());
signal::Signal< LpReassembler, Transport::EndpointId, size_t > beforeTimeout
signals before a partial packet is dropped due to timeout
#define NFD_LOG_FACE_TRACE(msg)
Log a message at TRACE level.
size_t nMaxFragments
maximum number of fragments in a packet
LpReassembler(const Options &options=Options(), const LinkService *linkService=nullptr)
Class representing a wire element of NDN-TLV packet format.
uint64_t Sequence
represents a sequence number
Table::const_iterator iterator
FIELD::ValueType get(size_t index=0) const
Copyright (c) 2011-2015 Regents of the University of California.
Options that control the behavior of LpReassembler.
EventId schedule(const time::nanoseconds &after, const Scheduler::Event &event)
schedule an event
time::nanoseconds reassemblyTimeout
timeout before a partially reassembled packet is dropped
std::tuple< bool, Block, lp::Packet > receiveFragment(Transport::EndpointId remoteEndpoint, const lp::Packet &packet)
adds received fragment to buffer
#define NFD_LOG_INIT(name)
uint64_t EndpointId
identifies an endpoint on the link
Class representing a general-use automatically managed/resized buffer.
#define NFD_LOG_FACE_WARN(msg)
Log a message at WARN level.