producer: use ScopedRegisteredPrefixHandle

Also, don't pass Scheduler to ScopedEventId because it's no
longer necessary.

refs #3919, #4698

Change-Id: I8af3ece977a6ab3a623c0ed7c63a424449df6a82
This commit is contained in:
Junxiao Shi
2019-01-23 16:48:54 +00:00
committed by Ashlesh Gawande
parent e5ee7a0c78
commit e5fdcc3744
5 changed files with 33 additions and 65 deletions
+10 -17
View File
@@ -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
+4 -13
View File
@@ -28,11 +28,10 @@
#include <random>
#include <ndn-cxx/face.hpp>
#include <ndn-cxx/util/scheduler.hpp>
#include <ndn-cxx/util/scheduler-scoped-event-id.hpp>
#include <ndn-cxx/util/time.hpp>
#include <ndn-cxx/security/key-chain.hpp>
#include <ndn-cxx/util/scheduler.hpp>
#include <ndn-cxx/util/segment-fetcher.hpp>
#include <ndn-cxx/util/time.hpp>
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<uint32_t>& negative);
private:
std::map <ndn::Name, PendingEntryInfoFull> m_pendingEntries;
std::map<ndn::Name, PendingEntryInfoFull> 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<ndn::util::SegmentFetcher> m_fetcher;
};
+14 -25
View File
@@ -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
+4 -8
View File
@@ -27,10 +27,9 @@
#include <unordered_set>
#include <ndn-cxx/face.hpp>
#include <ndn-cxx/util/scheduler.hpp>
#include <ndn-cxx/util/scheduler-scoped-event-id.hpp>
#include <ndn-cxx/util/time.hpp>
#include <ndn-cxx/security/key-chain.hpp>
#include <ndn-cxx/util/scheduler.hpp>
#include <ndn-cxx/util/time.hpp>
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 <ndn::Name, PendingEntryInfo> m_pendingEntries;
const ndn::RegisteredPrefixId* m_registerPrefixId;
std::map<ndn::Name, PendingEntryInfo> m_pendingEntries;
ndn::ScopedRegisteredPrefixHandle m_registeredPrefix;
};
} // namespace psync
+1 -2
View File
@@ -24,11 +24,10 @@
#include <ndn-cxx/face.hpp>
#include <ndn-cxx/name.hpp>
#include <ndn-cxx/ims/in-memory-storage-fifo.hpp>
#include <ndn-cxx/security/key-chain.hpp>
#include <ndn-cxx/util/scheduler-scoped-event-id.hpp>
#include <ndn-cxx/util/scheduler.hpp>
#include <ndn-cxx/util/time.hpp>
#include <ndn-cxx/ims/in-memory-storage-fifo.hpp>
namespace psync {