src: move and simplify canonize functionality to ConfFileProcessor
refs: #4817
Change-Id: I0a7f448f50994906d0403bcb97a3973dc1a25917
diff --git a/src/conf-file-processor.cpp b/src/conf-file-processor.cpp
index c893e39..18108b7 100644
--- a/src/conf-file-processor.cpp
+++ b/src/conf-file-processor.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2018, The University of Memphis,
+ * Copyright (c) 2014-2019, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -458,7 +458,24 @@
ndn::FaceUri faceUri;
if (! faceUri.parse(uriString)) {
- std::cerr << "parsing failed!" << std::endl;
+ std::cerr << "Parsing failed!" << std::endl;
+ return false;
+ }
+
+ bool failedToCanonize = false;
+ faceUri.canonize([&faceUri] (ndn::FaceUri canonicalUri) {
+ faceUri = canonicalUri;
+ },
+ [&faceUri, &failedToCanonize] (const std::string& reason) {
+ failedToCanonize = true;
+ std::cerr << "Could not canonize URI: " << faceUri
+ << "because: " << reason << std::endl;
+ },
+ m_io,
+ TIME_ALLOWED_FOR_CANONIZATION);
+ m_io.run();
+
+ if (failedToCanonize) {
return false;
}
diff --git a/src/conf-file-processor.hpp b/src/conf-file-processor.hpp
index 4218657..0bcb7e8 100644
--- a/src/conf-file-processor.hpp
+++ b/src/conf-file-processor.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2018, The University of Memphis,
+ * Copyright (c) 2014-2019, The University of Memphis,
* Regents of the University of California
*
* This file is part of NLSR (Named-data Link State Routing).
@@ -127,6 +127,8 @@
std::string m_confFileName;
/*! m_nlsr The NLSR object to configure upon successful parsing. */
Nlsr& m_nlsr;
+ /*! m_io For canonization of faceUri. */
+ boost::asio::io_service m_io;
};
} // namespace nlsr
diff --git a/src/nlsr-runner.cpp b/src/nlsr-runner.cpp
index 57066e9..b5ff594 100644
--- a/src/nlsr-runner.cpp
+++ b/src/nlsr-runner.cpp
@@ -41,15 +41,7 @@
BOOST_THROW_EXCEPTION(ConfFileError("Error in configuration file processing"));
}
- // Because URI canonization needs to occur before initialization,
- // we have to pass initialize as the finally() in neighbor canonization.
- m_nlsr.canonizeNeighborUris(m_nlsr.getAdjacencyList().getAdjList().begin(),
- [this] (std::list<Adjacent>::iterator iterator) {
- m_nlsr.canonizeContinuation(iterator, [this] { m_nlsr.initialize(); });
- },
- [this] {
- m_nlsr.initialize();
- });
+ m_nlsr.initialize();
try {
m_nlsr.startEventLoop();
diff --git a/src/nlsr.cpp b/src/nlsr.cpp
index 6045935..214e6ec 100644
--- a/src/nlsr.cpp
+++ b/src/nlsr.cpp
@@ -151,43 +151,6 @@
}
void
-Nlsr::canonizeContinuation(std::list<Adjacent>::iterator iterator,
- std::function<void(void)> finally)
-{
- canonizeNeighborUris(iterator, [this, finally] (std::list<Adjacent>::iterator iterator) {
- canonizeContinuation(iterator, finally);
- },
- finally);
-}
-
-void
-Nlsr::canonizeNeighborUris(std::list<Adjacent>::iterator currentNeighbor,
- std::function<void(std::list<Adjacent>::iterator)> then,
- std::function<void(void)> finally)
-{
- if (currentNeighbor != m_adjacencyList.getAdjList().end()) {
- ndn::FaceUri uri(currentNeighbor->getFaceUri());
- uri.canonize([then, currentNeighbor] (ndn::FaceUri canonicalUri) {
- NLSR_LOG_DEBUG("Canonized URI: " << currentNeighbor->getFaceUri()
- << " to: " << canonicalUri);
- currentNeighbor->setFaceUri(canonicalUri);
- then(std::next(currentNeighbor));
- },
- [then, currentNeighbor] (const std::string& reason) {
- NLSR_LOG_ERROR("Could not canonize URI: " << currentNeighbor->getFaceUri()
- << " because: " << reason);
- then(std::next(currentNeighbor));
- },
- m_nlsrFace.getIoService(),
- TIME_ALLOWED_FOR_CANONIZATION);
- }
- // We have finished canonizing all neighbors, so call finally()
- else {
- finally();
- }
-}
-
-void
Nlsr::loadCertToPublish(const ndn::security::v2::Certificate& certificate)
{
NLSR_LOG_TRACE("Loading cert to publish.");
diff --git a/src/nlsr.hpp b/src/nlsr.hpp
index 476650f..4614ccb 100644
--- a/src/nlsr.hpp
+++ b/src/nlsr.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2018, The University of Memphis,
+ * Copyright (c) 2014-2019, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -391,26 +391,6 @@
return m_firstHelloInterval;
}
- /*! \brief Canonize the URI for this and all proceeding neighbors in a list.
- *
- * This function canonizes the URI of the Adjacent object pointed to
- * by currentNeighbor. It then executes the then callback, providing
- * the next iterator in the list to the callback. A standard
- * invocation would be to pass the begin() iterator of NLSR's
- * adjacency list, and to provide Nlsr::canonizeContinuation as the
- * callback. Because every URI must be canonical before we begin
- * operations, the canonize function provides a finally() function
- * to resume whatever needs to occur.
- *
- * \sa Nlsr::canonizeContinuation
- * \sa Nlsr::initialize
- * \sa NlsrRunner::run
- */
- void
- canonizeNeighborUris(std::list<Adjacent>::iterator currentNeighbor,
- std::function<void(std::list<Adjacent>::iterator)> then,
- std::function<void(void)> finally);
-
StatsCollector&
getStatsCollector()
{
@@ -462,17 +442,6 @@
m_firstHelloInterval = interval;
}
- /*! \brief Continues canonizing neighbor URIs.
- *
- * For testability reasons, we want what each instance of
- * canonization does after completion to be controllable. The best
- * way to do this is to control that by simply passing a
- * continuation function.
- */
- void
- canonizeContinuation(std::list<Adjacent>::iterator iterator,
- std::function<void(void)> finally);
-
void
scheduleDatasetFetch();