mgmt: re-added expiration time to FaceStatus
refs #3381
Change-Id: I57d3166fc6ed52a54c442a80faffe7a7f4051e1d
diff --git a/daemon/mgmt/face-manager.cpp b/daemon/mgmt/face-manager.cpp
index 0cc40d5..0c94fea 100644
--- a/daemon/mgmt/face-manager.cpp
+++ b/daemon/mgmt/face-manager.cpp
@@ -248,10 +248,9 @@
FaceManager::listFaces(const Name& topPrefix, const Interest& interest,
ndn::mgmt::StatusDatasetContext& context)
{
+ auto now = time::steady_clock::now();
for (const auto& face : m_faceTable) {
- ndn::nfd::FaceStatus status;
- collectFaceProperties(*face, status);
- collectFaceCounters(*face, status);
+ ndn::nfd::FaceStatus status = collectFaceStatus(*face, now);
context.append(status.wireEncode());
}
context.end();
@@ -294,13 +293,12 @@
return context.reject(ControlResponse(400, "Malformed filter"));
}
+ auto now = time::steady_clock::now();
for (const auto& face : m_faceTable) {
if (!doesMatchFilter(faceFilter, face)) {
continue;
}
- ndn::nfd::FaceStatus status;
- collectFaceProperties(*face, status);
- collectFaceCounters(*face, status);
+ ndn::nfd::FaceStatus status = collectFaceStatus(*face, now);
context.append(status.wireEncode());
}
@@ -349,6 +347,32 @@
return true;
}
+ndn::nfd::FaceStatus
+FaceManager::collectFaceStatus(const Face& face, const time::steady_clock::TimePoint& now)
+{
+ ndn::nfd::FaceStatus status;
+
+ collectFaceProperties(face, status);
+
+ time::steady_clock::TimePoint expirationTime = face.getExpirationTime();
+ if (expirationTime != time::steady_clock::TimePoint::max()) {
+ status.setExpirationPeriod(std::max(time::milliseconds(0),
+ time::duration_cast<time::milliseconds>(expirationTime - now)));
+ }
+
+ const face::FaceCounters& counters = face.getCounters();
+ status.setNInInterests(counters.nInInterests)
+ .setNOutInterests(counters.nOutInterests)
+ .setNInDatas(counters.nInData)
+ .setNOutDatas(counters.nOutData)
+ .setNInNacks(counters.nInNacks)
+ .setNOutNacks(counters.nOutNacks)
+ .setNInBytes(counters.nInBytes)
+ .setNOutBytes(counters.nOutBytes);
+
+ return status;
+}
+
template<typename FaceTraits>
void
FaceManager::collectFaceProperties(const Face& face, FaceTraits& traits)
@@ -362,20 +386,6 @@
}
void
-FaceManager::collectFaceCounters(const Face& face, ndn::nfd::FaceStatus& status)
-{
- const face::FaceCounters& counters = face.getCounters();
- status.setNInInterests(counters.nInInterests)
- .setNOutInterests(counters.nOutInterests)
- .setNInDatas(counters.nInData)
- .setNOutDatas(counters.nOutData)
- .setNInNacks(counters.nInNacks)
- .setNOutNacks(counters.nOutNacks)
- .setNInBytes(counters.nInBytes)
- .setNOutBytes(counters.nOutBytes);
-}
-
-void
FaceManager::afterFaceAdded(shared_ptr<Face> face,
const ndn::mgmt::PostNotification& post)
{