tools: ndn-autoconfig MulticastDiscovery uses FaceQueryDataset
refs #2426
Change-Id: Ib9dcd77564d80b403199e9079d4753dadb96e350
diff --git a/tools/ndn-autoconfig/base.hpp b/tools/ndn-autoconfig/base.hpp
index 7cdfcca..66d1b8e 100644
--- a/tools/ndn-autoconfig/base.hpp
+++ b/tools/ndn-autoconfig/base.hpp
@@ -29,7 +29,6 @@
#include "core/common.hpp"
#include <ndn-cxx/face.hpp>
-#include <ndn-cxx/encoding/buffer-stream.hpp>
#include <ndn-cxx/mgmt/nfd/controller.hpp>
#include <ndn-cxx/mgmt/nfd/face-status.hpp>
#include <ndn-cxx/security/key-chain.hpp>
diff --git a/tools/ndn-autoconfig/multicast-discovery.cpp b/tools/ndn-autoconfig/multicast-discovery.cpp
index 4efcec6..c1ec0c5 100644
--- a/tools/ndn-autoconfig/multicast-discovery.cpp
+++ b/tools/ndn-autoconfig/multicast-discovery.cpp
@@ -25,8 +25,6 @@
#include "multicast-discovery.hpp"
-#include <ndn-cxx/util/segment-fetcher.hpp>
-
namespace ndn {
namespace tools {
namespace autoconfig {
@@ -46,45 +44,27 @@
{
std::cerr << "Trying multicast discovery..." << std::endl;
- util::SegmentFetcher::fetch(
- m_face, Interest("/localhost/nfd/faces/list"),
- m_validator,
- [this] (const ConstBufferPtr& data) { registerHubDiscoveryPrefix(data); },
- [this] (uint32_t code, const std::string& msg) { m_nextStageOnFailure(msg); });
+ this->collectMulticastFaces();
}
void
-MulticastDiscovery::registerHubDiscoveryPrefix(const ConstBufferPtr& buffer)
+MulticastDiscovery::collectMulticastFaces()
+{
+ ndn::nfd::FaceQueryFilter filter;
+ filter.setLinkType(ndn::nfd::LINK_TYPE_MULTI_ACCESS);
+ m_controller.fetch<ndn::nfd::FaceQueryDataset>(
+ filter,
+ bind(&MulticastDiscovery::registerHubDiscoveryPrefix, this, _1),
+ bind(m_nextStageOnFailure, _2)
+ );
+}
+
+void
+MulticastDiscovery::registerHubDiscoveryPrefix(const std::vector<ndn::nfd::FaceStatus>& dataset)
{
std::vector<uint64_t> multicastFaces;
-
- size_t offset = 0;
- while (offset < buffer->size()) {
- bool isOk = false;
- Block block;
- std::tie(isOk, block) = Block::fromBuffer(buffer, offset);
- if (!isOk) {
- std::cerr << "ERROR: cannot decode FaceStatus TLV" << std::endl;
- break;
- }
-
- offset += block.size();
-
- ndn::nfd::FaceStatus faceStatus(block);
-
- FaceUri uri(faceStatus.getRemoteUri());
- if (uri.getScheme() == "udp4") {
- namespace ip = boost::asio::ip;
- boost::system::error_code ec;
- ip::address address = ip::address::from_string(uri.getHost(), ec);
-
- if (!ec && address.is_multicast()) {
- multicastFaces.push_back(faceStatus.getFaceId());
- }
- else
- continue;
- }
- }
+ std::transform(dataset.begin(), dataset.end(), std::back_inserter(multicastFaces),
+ [] (const ndn::nfd::FaceStatus& faceStatus) { return faceStatus.getFaceId(); });
if (multicastFaces.empty()) {
m_nextStageOnFailure("No multicast faces available, skipping multicast discovery stage");
diff --git a/tools/ndn-autoconfig/multicast-discovery.hpp b/tools/ndn-autoconfig/multicast-discovery.hpp
index b437aee..5d03e43 100644
--- a/tools/ndn-autoconfig/multicast-discovery.hpp
+++ b/tools/ndn-autoconfig/multicast-discovery.hpp
@@ -28,8 +28,6 @@
#include "base.hpp"
-#include <ndn-cxx/security/validator-null.hpp>
-
namespace ndn {
namespace tools {
namespace autoconfig {
@@ -63,7 +61,10 @@
private:
void
- registerHubDiscoveryPrefix(const ConstBufferPtr& buffer);
+ collectMulticastFaces();
+
+ void
+ registerHubDiscoveryPrefix(const std::vector<ndn::nfd::FaceStatus>& dataset);
void
onRegisterSuccess();
@@ -87,8 +88,6 @@
private:
size_t m_nRequestedRegs;
size_t m_nFinishedRegs;
-
- ndn::ValidatorNull m_validator;
};
} // namespace autoconfig