20 #ifndef PSYNC_CONSUMER_HPP
21 #define PSYNC_CONSUMER_HPP
27 #include <ndn-cxx/face.hpp>
28 #include <ndn-cxx/util/random.hpp>
29 #include <ndn-cxx/util/scheduler.hpp>
30 #include <ndn-cxx/util/segment-fetcher.hpp>
70 Consumer(
const ndn::Name& syncPrefix,
75 double false_positive,
108 addSubscription(
const ndn::Name& prefix, uint64_t seqNo,
bool callSyncDataCb =
true);
122 return m_subscriptionList;
128 return m_subscriptionList.find(prefix) != m_subscriptionList.end();
131 std::optional<uint64_t>
134 auto it = m_prefixes.find(prefix);
135 if (it == m_prefixes.end()) {
161 onHelloData(
const ndn::ConstBufferPtr& bufferPtr);
174 onSyncData(
const ndn::ConstBufferPtr& bufferPtr);
178 ndn::Scheduler m_scheduler;
180 ndn::Name m_syncPrefix;
181 ndn::Name m_helloInterestPrefix;
182 ndn::Name m_syncInterestPrefix;
184 ndn::Name m_helloDataName;
185 ndn::Name m_syncDataName;
186 uint32_t m_syncDataContentType;
196 ndn::time::milliseconds m_helloInterestLifetime;
197 ndn::time::milliseconds m_syncInterestLifetime;
200 std::map<ndn::Name, uint64_t> m_prefixes;
201 std::set<ndn::Name> m_subscriptionList;
203 ndn::random::RandomNumberEngine& m_rng;
204 std::uniform_int_distribution<> m_rangeUniformRandom;
205 std::shared_ptr<ndn::util::SegmentFetcher> m_helloFetcher;
206 std::shared_ptr<ndn::util::SegmentFetcher> m_syncFetcher;
#define PSYNC_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Consumer logic to subscribe to producer's data.
bool addSubscription(const ndn::Name &prefix, uint64_t seqNo, bool callSyncDataCb=true)
Add prefix to subscription list.
bool removeSubscription(const ndn::Name &prefix)
Remove prefix from subscription list.
void stop()
Stop segment fetcher to stop the sync and free resources.
Consumer(const ndn::Name &syncPrefix, ndn::Face &face, const ReceiveHelloCallback &onReceiveHelloData, const UpdateCallback &onUpdate, unsigned int count, double false_positive, ndn::time::milliseconds helloInterestLifetime=HELLO_INTEREST_LIFETIME, ndn::time::milliseconds syncInterestLifetime=SYNC_INTEREST_LIFETIME)
constructor
std::optional< uint64_t > getSeqNo(const ndn::Name &prefix) const
void sendHelloInterest()
send hello interest /<sync-prefix>/hello/
std::set< ndn::Name > getSubscriptionList() const
void sendSyncInterest()
send sync interest /<sync-prefix>/sync/<BF>/<producers-IBF>
bool isSubscribed(const ndn::Name &prefix) const
constexpr ndn::time::milliseconds SYNC_INTEREST_LIFETIME
constexpr ndn::time::milliseconds HELLO_INTEREST_LIFETIME
std::function< void(const std::vector< MissingDataInfo > &)> UpdateCallback
std::function< void(const std::map< ndn::Name, uint64_t > &)> ReceiveHelloCallback