fw: outgoing Interest pipeline prefers newest in-record
refs #3642
Change-Id: I591a9a9c2efdcb4607b69f2c3be584110f9e14aa
diff --git a/daemon/fw/forwarder.cpp b/daemon/fw/forwarder.cpp
index 612b3e2..3578bb7 100644
--- a/daemon/fw/forwarder.cpp
+++ b/daemon/fw/forwarder.cpp
@@ -257,32 +257,6 @@
this->onOutgoingData(data, *const_pointer_cast<Face>(inFace.shared_from_this()));
}
-/** \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 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
-compare_pickInterest(const pit::InRecord& a, const pit::InRecord& b, const Face* outFace)
-{
- bool isOutFaceA = a.getFace().get() == outFace;
- bool isOutFaceB = b.getFace().get() == outFace;
-
- if (!isOutFaceA && isOutFaceB) {
- return false;
- }
- if (isOutFaceA && !isOutFaceB) {
- return true;
- }
-
- return a.getLastRenewed() > b.getLastRenewed();
-}
-
void
Forwarder::onOutgoingInterest(shared_ptr<pit::Entry> pitEntry, Face& outFace,
bool wantNewNonce)
@@ -302,8 +276,18 @@
}
// pick Interest
+ // The outgoing Interest picked is the last incoming Interest that does not come from outFace.
+ // 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.
pit::InRecordCollection::iterator pickedInRecord = std::max_element(
- pitEntry->in_begin(), pitEntry->in_end(), bind(&compare_pickInterest, _1, _2, &outFace));
+ pitEntry->in_begin(), pitEntry->in_end(),
+ [&outFace] (const pit::InRecord& a, const pit::InRecord& b) {
+ bool isOutFaceA = a.getFace().get() == &outFace;
+ bool isOutFaceB = b.getFace().get() == &outFace;
+ return (isOutFaceA > isOutFaceB) ||
+ (isOutFaceA == isOutFaceB && a.getLastRenewed() < b.getLastRenewed());
+ });
BOOST_ASSERT(pickedInRecord != pitEntry->in_end());
auto interest = const_pointer_cast<Interest>(pickedInRecord->getInterest().shared_from_this());