void afterFetchedFaceStatusInformation(const shared_ptr<OBufferStream>& buffer, const Name& remoteName) { ConstBufferPtr buf = buffer->buf(); Block block; size_t offset = 0; std::string currentTime; std::tm ctime; std::stringstream realEpochTime; ndn::time::system_clock::TimePoint realCurrentTime = ndn::time::system_clock::now(); std::string currentTimeStr = ndn::time::toString(realCurrentTime, "%Y-%m-%dT%H:%M:%S%F"); strptime(currentTimeStr.c_str(), "%FT%T%Z", &ctime); std::string stime(currentTimeStr); std::time_t realEpochSeconds = std::mktime(&ctime); std::size_t pos = stime.find("."); std::string realEpochMilli = stime.substr(pos+1); realEpochTime << realEpochSeconds << "." << realEpochMilli; CollectorData content; currentTime = realEpochTime.str(); while (offset < buf->size()) { bool ok = Block::fromBuffer(buf, offset, block); if (!ok) { std::cerr << "ERROR: cannot decode FaceStatus TLV" << std::endl; break; } offset += block.size(); nfd::FaceStatus faceStatus(block); // take only udp4 and tcp4 faces at the moment std::string remoteUri = faceStatus.getRemoteUri(); if(remoteUri.compare(0,4,"tcp4") != 0 && remoteUri.compare(0,4,"udp4") != 0) continue; // take the ip from uri (remove tcp4:// and everything after ':' std::size_t strPos = remoteUri.find_last_of(":"); std::string remoteIp = remoteUri.substr(7,strPos - 7); std::unordered_set<std::string>::const_iterator got = m_remoteLinks.find(remoteIp); // the link is not requested by the server if(got == m_remoteLinks.end()) continue; FaceStatus linkStatus; linkStatus.setTx(faceStatus.getNOutBytes()); linkStatus.setRx(faceStatus.getNInBytes()); linkStatus.setFaceId(faceStatus.getFaceId()); linkStatus.setLinkIp(remoteIp); linkStatus.setTimestamp(currentTime); // remove the remoteIP from the list of links to search and add it to the data packet m_remoteLinks.erase(remoteIp); content.add(linkStatus); if (DEBUG) std::cout << "about to send back " << linkStatus.getFaceId() << ": " << linkStatus.getRx() << ", " << linkStatus.getTx() << ", " << linkStatus.getLinkIp() << std::endl; } if (content.size() != 0) { ndn::shared_ptr<ndn::Data> data = ndn::make_shared<ndn::Data>(remoteName); data->setContent(content.wireEncode()); data->setFreshnessPeriod(time::seconds(0)); m_keyChain.sign(*data); m_face.put(*data); } }