diff --git a/PSync/full-producer.cpp b/PSync/full-producer.cpp index 968154a..4390a26 100644 --- a/PSync/full-producer.cpp +++ b/PSync/full-producer.cpp @@ -41,15 +41,14 @@ FullProducer::FullProducer(const size_t expectedNumEntries, : ProducerBase(expectedNumEntries, face, syncPrefix, userPrefix, syncReplyFreshness) , m_syncInterestLifetime(syncInterestLifetime) , m_onUpdate(onUpdateCallBack) - , m_scheduledSyncInterestId(m_scheduler) { int jitter = m_syncInterestLifetime.count() * .20; m_jitter = std::uniform_int_distribution<>(-jitter, jitter); - m_registerPrefixId = - m_face.setInterestFilter(ndn::InterestFilter(m_syncPrefix).allowLoopback(false), - std::bind(&FullProducer::onSyncInterest, this, _1, _2), - std::bind(&FullProducer::onRegisterFailed, this, _1, _2)); + m_registeredPrefix = m_face.setInterestFilter( + ndn::InterestFilter(m_syncPrefix).allowLoopback(false), + std::bind(&FullProducer::onSyncInterest, this, _1, _2), + std::bind(&FullProducer::onRegisterFailed, this, _1, _2)); // Should we do this after setInterestFilter success call back // (Currently following ChronoSync's way) @@ -61,8 +60,6 @@ FullProducer::~FullProducer() if (m_fetcher) { m_fetcher->stop(); } - - m_face.unsetInterestFilter(m_registerPrefixId); } void @@ -209,16 +206,12 @@ FullProducer::onSyncInterest(const ndn::Name& prefixName, const ndn::Interest& i return; } - ndn::util::scheduler::ScopedEventId scopedEventId(m_scheduler); - auto it = m_pendingEntries.emplace(interestName, - PendingEntryInfoFull{iblt, std::move(scopedEventId)}); - - it.first->second.expirationEvent = - m_scheduler.scheduleEvent(interest.getInterestLifetime(), - [this, interest] { - NDN_LOG_TRACE("Erase Pending Interest " << interest.getNonce()); - m_pendingEntries.erase(interest.getName()); - }); + auto& entry = m_pendingEntries.emplace(interestName, PendingEntryInfoFull{iblt, {}}).first->second; + entry.expirationEvent = m_scheduler.scheduleEvent(interest.getInterestLifetime(), + [this, interest] { + NDN_LOG_TRACE("Erase Pending Interest " << interest.getNonce()); + m_pendingEntries.erase(interest.getName()); + }); } void diff --git a/PSync/full-producer.hpp b/PSync/full-producer.hpp index ec0ba4a..b5eb55f 100644 --- a/PSync/full-producer.hpp +++ b/PSync/full-producer.hpp @@ -28,11 +28,10 @@ #include #include -#include -#include -#include #include +#include #include +#include namespace psync { @@ -171,7 +170,6 @@ private: /** * @brief Delete pending sync interests that match given name - * */ void deletePendingInterests(const ndn::Name& interestName); @@ -186,20 +184,13 @@ private: isFutureHash(const ndn::Name& prefix, const std::set& negative); private: - std::map m_pendingEntries; - + std::map m_pendingEntries; ndn::time::milliseconds m_syncInterestLifetime; - UpdateCallback m_onUpdate; - ndn::util::scheduler::ScopedEventId m_scheduledSyncInterestId; - std::uniform_int_distribution<> m_jitter; - ndn::Name m_outstandingInterestName; - - const ndn::RegisteredPrefixId* m_registerPrefixId; - + ndn::ScopedRegisteredPrefixHandle m_registeredPrefix; std::shared_ptr m_fetcher; }; diff --git a/PSync/partial-producer.cpp b/PSync/partial-producer.cpp index ed54175..87f648d 100644 --- a/PSync/partial-producer.cpp +++ b/PSync/partial-producer.cpp @@ -38,21 +38,14 @@ PartialProducer::PartialProducer(size_t expectedNumEntries, : ProducerBase(expectedNumEntries, face, syncPrefix, userPrefix, syncReplyFreshness, helloReplyFreshness) { - m_registerPrefixId = - m_face.registerPrefix(m_syncPrefix, - [this] (const ndn::Name& syncPrefix) { - m_face.setInterestFilter(ndn::Name(m_syncPrefix).append("hello"), - std::bind(&PartialProducer::onHelloInterest, this, _1, _2)); - - m_face.setInterestFilter(ndn::Name(m_syncPrefix).append("sync"), - std::bind(&PartialProducer::onSyncInterest, this, _1, _2)); - }, - std::bind(&PartialProducer::onRegisterFailed, this, _1, _2)); -} - -PartialProducer::~PartialProducer() -{ - m_face.unregisterPrefix(m_registerPrefixId, nullptr, nullptr); + m_registeredPrefix = m_face.registerPrefix(m_syncPrefix, + [this] (const ndn::Name& syncPrefix) { + m_face.setInterestFilter(ndn::Name(m_syncPrefix).append("hello"), + std::bind(&PartialProducer::onHelloInterest, this, _1, _2)); + m_face.setInterestFilter(ndn::Name(m_syncPrefix).append("sync"), + std::bind(&PartialProducer::onSyncInterest, this, _1, _2)); + }, + std::bind(&PartialProducer::onRegisterFailed, this, _1, _2)); } void @@ -199,16 +192,12 @@ PartialProducer::onSyncInterest(const ndn::Name& prefix, const ndn::Interest& in return; } - ndn::util::scheduler::ScopedEventId scopedEventId(m_scheduler); - auto it = m_pendingEntries.emplace(interestName, - PendingEntryInfo{bf, iblt, std::move(scopedEventId)}); - - it.first->second.expirationEvent = - m_scheduler.scheduleEvent(interest.getInterestLifetime(), - [this, interest] { - NDN_LOG_TRACE("Erase Pending Interest " << interest.getNonce()); - m_pendingEntries.erase(interest.getName()); - }); + auto& entry = m_pendingEntries.emplace(interestName, PendingEntryInfo{bf, iblt, {}}).first->second; + entry.expirationEvent = m_scheduler.scheduleEvent(interest.getInterestLifetime(), + [this, interest] { + NDN_LOG_TRACE("Erase Pending Interest " << interest.getNonce()); + m_pendingEntries.erase(interest.getName()); + }); } void diff --git a/PSync/partial-producer.hpp b/PSync/partial-producer.hpp index cec1079..94f5672 100644 --- a/PSync/partial-producer.hpp +++ b/PSync/partial-producer.hpp @@ -27,10 +27,9 @@ #include #include -#include -#include -#include #include +#include +#include namespace psync { @@ -72,8 +71,6 @@ public: ndn::time::milliseconds helloReplyFreshness = HELLO_REPLY_FRESHNESS, ndn::time::milliseconds syncReplyFreshness = SYNC_REPLY_FRESHNESS); - ~PartialProducer(); - /** * @brief Publish name to let subscribed consumers know * @@ -122,9 +119,8 @@ PUBLIC_WITH_TESTS_ELSE_PRIVATE: onSyncInterest(const ndn::Name& prefix, const ndn::Interest& interest); PUBLIC_WITH_TESTS_ELSE_PRIVATE: - std::map m_pendingEntries; - - const ndn::RegisteredPrefixId* m_registerPrefixId; + std::map m_pendingEntries; + ndn::ScopedRegisteredPrefixHandle m_registeredPrefix; }; } // namespace psync diff --git a/PSync/segment-publisher.hpp b/PSync/segment-publisher.hpp index f28e31d..f00acff 100644 --- a/PSync/segment-publisher.hpp +++ b/PSync/segment-publisher.hpp @@ -24,11 +24,10 @@ #include #include +#include #include -#include #include #include -#include namespace psync {