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>
84 Consumer(ndn::Face& face,
const ndn::Name& syncPrefix,
const Options& opts);
87 Consumer(
const ndn::Name& syncPrefix,
92 double falsePositive = 0.001,
125 addSubscription(
const ndn::Name& prefix, uint64_t seqNo,
bool callSyncDataCb =
true);
139 return m_subscriptionList;
145 return m_subscriptionList.find(prefix) != m_subscriptionList.end();
148 std::optional<uint64_t>
151 auto it = m_prefixes.find(prefix);
152 if (it == m_prefixes.end()) {
178 onHelloData(
const ndn::ConstBufferPtr& bufferPtr);
191 onSyncData(
const ndn::ConstBufferPtr& bufferPtr);
195 ndn::Scheduler m_scheduler;
197 ndn::Name m_syncPrefix;
198 ndn::Name m_helloInterestPrefix;
199 ndn::Name m_syncInterestPrefix;
201 ndn::Name m_helloDataName;
202 ndn::Name m_syncDataName;
203 uint32_t m_syncDataContentType;
213 ndn::time::milliseconds m_helloInterestLifetime;
214 ndn::time::milliseconds m_syncInterestLifetime;
217 std::map<ndn::Name, uint64_t> m_prefixes;
218 std::set<ndn::Name> m_subscriptionList;
220 ndn::random::RandomNumberEngine& m_rng;
221 std::uniform_int_distribution<> m_rangeUniformRandom;
222 std::shared_ptr<ndn::SegmentFetcher> m_helloFetcher;
223 std::shared_ptr<ndn::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.
std::optional< uint64_t > getSeqNo(const ndn::Name &prefix) const
void sendHelloInterest()
send hello interest /<sync-prefix>/hello/
std::set< ndn::Name > getSubscriptionList() const
Consumer(ndn::Face &face, const ndn::Name &syncPrefix, const Options &opts)
Constructor.
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
double bfFalsePositive
Bloom filter false positive probability.
ReceiveHelloCallback onHelloData
Callback to give hello data back to application.
uint32_t bfCount
Number of expected elements (subscriptions) in Bloom filter.
ndn::time::milliseconds syncInterestLifetime
Lifetime of sync Interest.
ndn::time::milliseconds helloInterestLifetime
Lifetime of hello Interest.
UpdateCallback onUpdate
Callback to give sync data back to application.