table: simplify pit::Entry API
refs #3546
Change-Id: I6a9cb83b9e56ce1d1bb6047049378c51781605af
diff --git a/daemon/fw/forwarder.cpp b/daemon/fw/forwarder.cpp
index ef792ae..b575e3b 100644
--- a/daemon/fw/forwarder.cpp
+++ b/daemon/fw/forwarder.cpp
@@ -142,9 +142,7 @@
this->cancelUnsatisfyAndStragglerTimer(pitEntry);
// is pending?
- const pit::InRecordCollection& inRecords = pitEntry->getInRecords();
- bool isPending = inRecords.begin() != inRecords.end();
- if (!isPending) {
+ if (!pitEntry->hasInRecords()) {
m_cs.find(interest,
bind(&Forwarder::onContentStoreHit, this, ref(inFace), pitEntry, _1, _2),
bind(&Forwarder::onContentStoreMiss, this, ref(inFace), pitEntry, _1));
@@ -184,7 +182,7 @@
NFD_LOG_DEBUG("onContentStoreMiss interest=" << interest.getName());
shared_ptr<Face> face = const_pointer_cast<Face>(inFace.shared_from_this());
- // insert InRecord
+ // insert in-record
pitEntry->insertOrUpdateInRecord(face, interest);
// set PIT unsatisfy timer
@@ -261,14 +259,14 @@
this->onOutgoingData(data, *const_pointer_cast<Face>(inFace.shared_from_this()));
}
-/** \brief compare two InRecords for picking outgoing Interest
+/** \brief compare two in-records for picking outgoing Interest
* \return true if b is preferred over a
*
* This function should be passed to std::max_element over InRecordCollection.
* The outgoing Interest picked is the last incoming Interest
* that does not come from outFace.
- * If all InRecords come from outFace, it's fine to pick that. This happens when
- * there's only one InRecord that comes from outFace. The legit use is for
+ * If all in-records come from outFace, it's fine to pick that. This happens when
+ * there's only one in-record that comes from outFace. The legit use is for
* vehicular network; otherwise, strategy shouldn't send to the sole inFace.
*/
static inline bool
@@ -306,12 +304,10 @@
}
// pick Interest
- const pit::InRecordCollection& inRecords = pitEntry->getInRecords();
- pit::InRecordCollection::const_iterator pickedInRecord = std::max_element(
- inRecords.begin(), inRecords.end(), bind(&compare_pickInterest, _1, _2, &outFace));
- BOOST_ASSERT(pickedInRecord != inRecords.end());
- shared_ptr<Interest> interest = const_pointer_cast<Interest>(
- pickedInRecord->getInterest().shared_from_this());
+ pit::InRecordCollection::iterator pickedInRecord = std::max_element(
+ pitEntry->in_begin(), pitEntry->in_end(), bind(&compare_pickInterest, _1, _2, &outFace));
+ BOOST_ASSERT(pickedInRecord != pitEntry->in_end());
+ auto interest = const_pointer_cast<Interest>(pickedInRecord->getInterest().shared_from_this());
if (wantNewNonce) {
interest = make_shared<Interest>(*interest);
@@ -319,7 +315,7 @@
interest->setNonce(dist(getGlobalRng()));
}
- // insert OutRecord
+ // insert out-record
pitEntry->insertOrUpdateOutRecord(outFace.shared_from_this(), *interest);
// send Interest
@@ -403,6 +399,7 @@
std::set<Face*> pendingDownstreams;
// foreach PitEntry
+ auto now = time::steady_clock::now();
for (const shared_ptr<pit::Entry>& pitEntry : pitMatches) {
NFD_LOG_DEBUG("onIncomingData matching=" << pitEntry->getName());
@@ -410,9 +407,8 @@
this->cancelUnsatisfyAndStragglerTimer(pitEntry);
// remember pending downstreams
- const pit::InRecordCollection& inRecords = pitEntry->getInRecords();
- for (const pit::InRecord& inRecord : inRecords) {
- if (inRecord.getExpiry() > time::steady_clock::now()) {
+ for (const pit::InRecord& inRecord : pitEntry->getInRecords()) {
+ if (inRecord.getExpiry() > now) {
pendingDownstreams.insert(inRecord.getFace().get());
}
}
@@ -421,11 +417,11 @@
this->dispatchToStrategy(pitEntry, bind(&Strategy::beforeSatisfyInterest, _1,
pitEntry, cref(inFace), cref(data)));
- // Dead Nonce List insert if necessary (for OutRecord of inFace)
+ // Dead Nonce List insert if necessary (for out-record of inFace)
this->insertDeadNonceList(*pitEntry, true, data.getFreshnessPeriod(), &inFace);
// mark PIT satisfied
- pitEntry->deleteInRecords();
+ pitEntry->clearInRecords();
pitEntry->deleteOutRecord(inFace);
// set PIT straggler timer
@@ -511,7 +507,7 @@
// has out-record?
pit::OutRecordCollection::iterator outRecord = pitEntry->getOutRecord(inFace);
// if no out-record found, drop
- if (outRecord == pitEntry->getOutRecords().end()) {
+ if (outRecord == pitEntry->out_end()) {
NFD_LOG_DEBUG("onIncomingNack face=" << inFace.getId() <<
" nack=" << nack.getInterest().getName() <<
"~" << nack.getReason() << " no-out-record");
@@ -552,10 +548,10 @@
}
// has in-record?
- pit::InRecordCollection::const_iterator inRecord = pitEntry->getInRecord(outFace);
+ pit::InRecordCollection::iterator inRecord = pitEntry->getInRecord(outFace);
// if no in-record found, drop
- if (inRecord == pitEntry->getInRecords().end()) {
+ if (inRecord == pitEntry->in_end()) {
NFD_LOG_DEBUG("onOutgoingNack face=" << outFace.getId() <<
" nack=" << pitEntry->getInterest().getName() <<
"~" << nack.getReason() << " no-in-record");
@@ -595,15 +591,13 @@
void
Forwarder::setUnsatisfyTimer(shared_ptr<pit::Entry> pitEntry)
{
- const pit::InRecordCollection& inRecords = pitEntry->getInRecords();
- pit::InRecordCollection::const_iterator lastExpiring =
- std::max_element(inRecords.begin(), inRecords.end(),
- &compare_InRecord_expiry);
+ pit::InRecordCollection::iterator lastExpiring =
+ std::max_element(pitEntry->in_begin(), pitEntry->in_end(), &compare_InRecord_expiry);
time::steady_clock::TimePoint lastExpiry = lastExpiring->getExpiry();
- time::nanoseconds lastExpiryFromNow = lastExpiry - time::steady_clock::now();
- if (lastExpiryFromNow <= time::seconds(0)) {
- // TODO all InRecords are already expired; will this happen?
+ time::nanoseconds lastExpiryFromNow = lastExpiry - time::steady_clock::now();
+ if (lastExpiryFromNow <= time::seconds::zero()) {
+ // TODO all in-records are already expired; will this happen?
}
scheduler::cancel(pitEntry->m_unsatisfyTimer);
@@ -666,7 +660,7 @@
}
else {
// insert outgoing Nonce of a specific face
- pit::OutRecordCollection::const_iterator outRecord = pitEntry.getOutRecord(*upstream);
+ pit::OutRecordCollection::iterator outRecord = pitEntry.getOutRecord(*upstream);
if (outRecord != pitEntry.getOutRecords().end()) {
m_deadNonceList.add(pitEntry.getName(), outRecord->getLastNonce());
}