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)
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;
179 if (m_lastNackSequenceNum == nackSequenceNum) {
186 m_lastNackSequenceNum = nackSequenceNum;
188 return time::milliseconds(static_cast<time::milliseconds::rep>(std::pow(2, m_attempts) * 100 +
void start()
start or resume receiving notifications
uint64_t toSequenceNumber() const
Interpret as sequence number component using NDN naming conventions.
virtual ~NotificationSubscriberBase()
const Name & getName() const
Get name.
const Component & get(ssize_t i) const
Returns an immutable reference to the component at the specified index.
Represents an Interest packet.
EventId schedule(time::nanoseconds after, EventCallback callback)
Schedule a one-time event after the specified delay.
represents a Network Nack
uint32_t generateWord32()
Generate a non-cryptographically-secure random integer in the range [0, 2^32)
signal::Signal< NotificationSubscriberBase, lp::Nack > onNack
fires when a NACK is received
signal::Signal< NotificationSubscriberBase > onTimeout
fires when no Notification is received within .getInterestLifetime period
Provide a communication channel with local or remote NDN forwarder.
Name & appendSequenceNumber(uint64_t seqNo)
Append a sequence number component.
Represents an absolute name.
PendingInterestHandle expressInterest(const Interest &interest, const DataCallback &afterSatisfied, const NackCallback &afterNacked, const TimeoutCallback &afterTimeout)
Express Interest.
const Name & getName() const noexcept
void cancel()
Cancel the operation.
signal::Signal< NotificationSubscriberBase, Data > onDecodeError
fires when a Data packet in the Notification Stream cannot be decoded as Notification ...
Represents a Data packet.
const Interest & getInterest() const
represents an error in TLV encoding or decoding
NotificationSubscriberBase(Face &face, const Name &prefix, time::milliseconds interestLifetime)
construct a NotificationSubscriber
void stop()
stop receiving notifications