37 time::milliseconds interestLifetime)
41 , m_lastSequenceNum(std::numeric_limits<uint64_t>::max())
42 , m_lastNackSequenceNum(std::numeric_limits<uint64_t>::max())
44 , m_scheduler(face.getIoService())
45 , m_interestLifetime(interestLifetime)
58 sendInitialInterest();
72 NotificationSubscriberBase::sendInitialInterest()
77 auto interest = make_shared<Interest>(m_prefix);
78 interest->setCanBePrefix(
true);
79 interest->setMustBeFresh(
true);
80 interest->setInterestLifetime(m_interestLifetime);
81 sendInterest(*interest);
85 NotificationSubscriberBase::sendNextInterest()
90 Name nextName = m_prefix;
93 auto interest = make_shared<Interest>(nextName);
94 interest->setCanBePrefix(
false);
95 interest->setInterestLifetime(m_interestLifetime);
96 sendInterest(*interest);
100 NotificationSubscriberBase::sendInterest(
const Interest& interest)
103 [
this] (
const auto&,
const auto& d) { this->afterReceiveData(d); },
104 [
this] (
const auto&,
const auto& n) { this->afterReceiveNack(n); },
105 [
this] (
const auto&) { this->afterTimeout(); });
109 NotificationSubscriberBase::shouldStop()
114 if (!hasSubscriber() &&
onNack.isEmpty()) {
122 NotificationSubscriberBase::afterReceiveData(
const Data& data)
128 m_lastSequenceNum = data.getName().get(-1).toSequenceNumber();
130 catch (
const tlv::Error&) {
132 sendInitialInterest();
136 if (!decodeAndDeliver(data)) {
138 sendInitialInterest();
146 NotificationSubscriberBase::afterReceiveNack(
const lp::Nack& nack)
153 time::milliseconds delay = exponentialBackoff(nack);
154 m_nackEvent = m_scheduler.
schedule(delay, [
this] { sendInitialInterest(); });
158 NotificationSubscriberBase::afterTimeout()
165 sendInitialInterest();
169 NotificationSubscriberBase::exponentialBackoff(
lp::Nack nack)
171 uint64_t nackSequenceNum;
175 catch (
const tlv::Error&) {
179 if (m_lastNackSequenceNum == nackSequenceNum) {
186 m_lastNackSequenceNum = nackSequenceNum;
188 return time::milliseconds(
static_cast<time::milliseconds::rep
>(std::pow(2, m_attempts) * 100 +