tools: ndn-autoconfig code style corrections
refs #2426
Change-Id: Ied8de3b3f839e07090fc71f41cd01f4e5b4987f3
diff --git a/tools/ndn-autoconfig/base.cpp b/tools/ndn-autoconfig/base.cpp
index a796f4c..c95eb21 100644
--- a/tools/ndn-autoconfig/base.cpp
+++ b/tools/ndn-autoconfig/base.cpp
@@ -40,7 +40,7 @@
void
Base::connectToHub(const std::string& uri)
{
- util::FaceUri faceUri(uri);
+ FaceUri faceUri(uri);
faceUri.canonize(bind(&Base::onCanonizeSuccess, this, _1),
bind(&Base::onCanonizeFailure, this, _1),
@@ -50,26 +50,24 @@
void
-Base::onCanonizeSuccess(const util::FaceUri& canonicalUri)
+Base::onCanonizeSuccess(const FaceUri& canonicalUri)
{
std::cerr << "About to connect to: " << canonicalUri.toString() << std::endl;
- m_controller.start<nfd::FaceCreateCommand>(nfd::ControlParameters()
- .setUri(canonicalUri.toString()),
- bind(&Base::onHubConnectSuccess, this, _1),
- bind(&Base::onHubConnectError, this, _1));
+ m_controller.start<ndn::nfd::FaceCreateCommand>(
+ ControlParameters().setUri(canonicalUri.toString()),
+ bind(&Base::onHubConnectSuccess, this, _1),
+ bind(&Base::onHubConnectError, this, _1));
}
void
Base::onCanonizeFailure(const std::string& reason)
{
- std::ostringstream os;
- os << "FaceUri canonization failed: " << reason;
- BOOST_THROW_EXCEPTION(Error(os.str()));
+ BOOST_THROW_EXCEPTION(Error("FaceUri canonization failed: " + reason));
}
void
-Base::onHubConnectSuccess(const nfd::ControlParameters& resp)
+Base::onHubConnectSuccess(const ControlParameters& resp)
{
std::cerr << "Successfully created face: " << resp << std::endl;
@@ -81,7 +79,7 @@
}
void
-Base::onHubConnectError(const nfd::ControlResponse& response)
+Base::onHubConnectError(const ControlResponse& response)
{
std::ostringstream os;
os << "Failed to create face: " << response.getText() << " (code: " << response.getCode() << ")";
@@ -92,28 +90,28 @@
Base::registerPrefix(const Name& prefix, uint64_t faceId)
{
// Register a prefix in RIB
- m_controller.start<nfd::RibRegisterCommand>(nfd::ControlParameters()
- .setName(prefix)
- .setFaceId(faceId)
- .setOrigin(nfd::ROUTE_ORIGIN_AUTOCONF)
- .setCost(100)
- .setExpirationPeriod(time::milliseconds::max()),
- bind(&Base::onPrefixRegistrationSuccess, this, _1),
- bind(&Base::onPrefixRegistrationError, this, _1));
+ m_controller.start<ndn::nfd::RibRegisterCommand>(
+ ControlParameters()
+ .setName(prefix)
+ .setFaceId(faceId)
+ .setOrigin(ndn::nfd::ROUTE_ORIGIN_AUTOCONF)
+ .setCost(100)
+ .setExpirationPeriod(time::milliseconds::max()),
+ bind(&Base::onPrefixRegistrationSuccess, this, _1),
+ bind(&Base::onPrefixRegistrationError, this, _1));
}
void
-Base::onPrefixRegistrationSuccess(const nfd::ControlParameters& commandSuccessResult)
+Base::onPrefixRegistrationSuccess(const ControlParameters& commandSuccessResult)
{
std::cerr << "Successful in name registration: " << commandSuccessResult << std::endl;
}
void
-Base::onPrefixRegistrationError(const nfd::ControlResponse& response)
+Base::onPrefixRegistrationError(const ControlResponse& response)
{
- std::ostringstream os;
- os << "Failed in name registration, " << response.getText() << " (code: " << response.getCode() << ")";
- BOOST_THROW_EXCEPTION(Error(os.str()));
+ BOOST_THROW_EXCEPTION(Error("Failed in name registration, " + response.getText() +
+ " (code: " + to_string(response.getCode()) + ")"));
}
diff --git a/tools/ndn-autoconfig/base.hpp b/tools/ndn-autoconfig/base.hpp
index e66020c..7cdfcca 100644
--- a/tools/ndn-autoconfig/base.hpp
+++ b/tools/ndn-autoconfig/base.hpp
@@ -29,16 +29,20 @@
#include "core/common.hpp"
#include <ndn-cxx/face.hpp>
-#include <ndn-cxx/security/key-chain.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/encoding/buffer-stream.hpp>
+#include <ndn-cxx/security/key-chain.hpp>
#include <ndn-cxx/util/face-uri.hpp>
namespace ndn {
namespace tools {
namespace autoconfig {
+using ndn::nfd::ControlParameters;
+using ndn::nfd::ControlResponse;
+using ndn::util::FaceUri;
+
/**
* @brief Base class for discovery stages
*/
@@ -68,7 +72,7 @@
protected:
/**
- * @brief Initialize variables and create nfd::Controller instance
+ * @brief Initialize variables and create Controller instance
* @param face Face to be used for all operations (e.g., will send registration commands)
* @param keyChain KeyChain object
* @param nextStageOnFailure Callback to be called after the stage failed
@@ -84,30 +88,30 @@
private:
void
- onCanonizeSuccess(const util::FaceUri& canonicalUri);
+ onCanonizeSuccess(const FaceUri& canonicalUri);
void
onCanonizeFailure(const std::string& reason);
void
- onHubConnectSuccess(const nfd::ControlParameters& resp);
+ onHubConnectSuccess(const ControlParameters& resp);
void
- onHubConnectError(const nfd::ControlResponse& response);
+ onHubConnectError(const ControlResponse& response);
void
registerPrefix(const Name& prefix, uint64_t faceId);
void
- onPrefixRegistrationSuccess(const nfd::ControlParameters& commandSuccessResult);
+ onPrefixRegistrationSuccess(const ControlParameters& commandSuccessResult);
void
- onPrefixRegistrationError(const nfd::ControlResponse& response);
+ onPrefixRegistrationError(const ControlResponse& response);
protected:
Face& m_face;
KeyChain& m_keyChain;
- nfd::Controller m_controller;
+ ndn::nfd::Controller m_controller;
NextStageCallback m_nextStageOnFailure;
};
diff --git a/tools/ndn-autoconfig/main.cpp b/tools/ndn-autoconfig/main.cpp
index 666cca1..61ae22a 100644
--- a/tools/ndn-autoconfig/main.cpp
+++ b/tools/ndn-autoconfig/main.cpp
@@ -35,13 +35,16 @@
#include <boost/noncopyable.hpp>
#include <boost/program_options/options_description.hpp>
-#include <boost/program_options/variables_map.hpp>
#include <boost/program_options/parsers.hpp>
+#include <boost/program_options/variables_map.hpp>
namespace po = boost::program_options;
namespace ndn {
namespace tools {
+namespace autoconfig {
+// ndn-autoconfig is an NDN tool not an NFD tool, so it uses ndn::tools::autoconfig namespace.
+// It lives in NFD repository because nfd-start can automatically start ndn-autoconfig in daemon mode.
class NdnAutoconfig : boost::noncopyable
{
@@ -83,7 +86,7 @@
})
{
if (m_isDaemonMode) {
- m_networkMonitor.reset(new util::NetworkMonitor(m_io));
+ m_networkMonitor.reset(new ndn::util::NetworkMonitor(m_io));
m_networkMonitor->onNetworkStateChanged.connect([this] {
// delay stages, so if multiple events are triggered in short sequence,
// only one auto-detection procedure is triggered
@@ -118,7 +121,6 @@
m_io.stop();
}
-
static void
usage(std::ostream& os,
const po::options_description& optionDescription,
@@ -151,15 +153,12 @@
bool m_isDaemonMode;
boost::asio::signal_set m_terminationSignalSet;
- autoconfig::MulticastDiscovery m_stage1;
- autoconfig::GuessFromSearchDomains m_stage2;
- autoconfig::GuessFromIdentityName m_stage3;
+ MulticastDiscovery m_stage1;
+ GuessFromSearchDomains m_stage2;
+ GuessFromIdentityName m_stage3;
};
-} // namespace tools
-} // namespace ndn
-
-int
+static int
main(int argc, char** argv)
{
bool isDaemonMode = false;
@@ -185,12 +184,12 @@
}
catch (const std::exception& e) {
std::cerr << "ERROR: " << e.what() << "\n" << std::endl;
- ndn::tools::NdnAutoconfig::usage(std::cerr, optionDescription, argv[0]);
+ NdnAutoconfig::usage(std::cerr, optionDescription, argv[0]);
return 1;
}
if (options.count("help")) {
- ndn::tools::NdnAutoconfig::usage(std::cout, optionDescription, argv[0]);
+ NdnAutoconfig::usage(std::cout, optionDescription, argv[0]);
return 0;
}
@@ -224,7 +223,7 @@
}
try {
- ndn::tools::NdnAutoconfig autoConfigInstance(isDaemonMode);
+ NdnAutoconfig autoConfigInstance(isDaemonMode);
autoConfigInstance.run();
}
catch (const std::exception& error) {
@@ -233,3 +232,13 @@
}
return 0;
}
+
+} // namespace autoconfig
+} // namespace tools
+} // namespace ndn
+
+int
+main(int argc, char** argv)
+{
+ return ndn::tools::autoconfig::main(argc, argv);
+}
diff --git a/tools/ndn-autoconfig/multicast-discovery.cpp b/tools/ndn-autoconfig/multicast-discovery.cpp
index a474899..4efcec6 100644
--- a/tools/ndn-autoconfig/multicast-discovery.cpp
+++ b/tools/ndn-autoconfig/multicast-discovery.cpp
@@ -36,8 +36,8 @@
MulticastDiscovery::MulticastDiscovery(Face& face, KeyChain& keyChain,
const NextStageCallback& nextStageOnFailure)
: Base(face, keyChain, nextStageOnFailure)
- , nRequestedRegs(0)
- , nFinishedRegs(0)
+ , m_nRequestedRegs(0)
+ , m_nFinishedRegs(0)
{
}
@@ -46,14 +46,11 @@
{
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);
- });
+ 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); });
}
void
@@ -73,9 +70,9 @@
offset += block.size();
- nfd::FaceStatus faceStatus(block);
+ ndn::nfd::FaceStatus faceStatus(block);
- ndn::util::FaceUri uri(faceStatus.getRemoteUri());
+ FaceUri uri(faceStatus.getRemoteUri());
if (uri.getScheme() == "udp4") {
namespace ip = boost::asio::ip;
boost::system::error_code ec;
@@ -93,22 +90,21 @@
m_nextStageOnFailure("No multicast faces available, skipping multicast discovery stage");
}
else {
- nfd::ControlParameters parameters;
+ ControlParameters parameters;
parameters
.setName(LOCALHOP_HUB_DISCOVERY_PREFIX)
.setCost(1)
.setExpirationPeriod(time::seconds(30));
- nRequestedRegs = multicastFaces.size();
- nFinishedRegs = 0;
+ m_nRequestedRegs = multicastFaces.size();
+ m_nFinishedRegs = 0;
for (const auto& face : multicastFaces) {
parameters.setFaceId(face);
- m_controller.start<nfd::RibRegisterCommand>(parameters,
- bind(&MulticastDiscovery::onRegisterSuccess,
- this),
- bind(&MulticastDiscovery::onRegisterFailure,
- this, _1));
+ m_controller.start<ndn::nfd::RibRegisterCommand>(
+ parameters,
+ bind(&MulticastDiscovery::onRegisterSuccess, this),
+ bind(&MulticastDiscovery::onRegisterFailure, this, _1));
}
}
}
@@ -116,23 +112,24 @@
void
MulticastDiscovery::onRegisterSuccess()
{
- ++nFinishedRegs;
+ ++m_nFinishedRegs;
- if (nRequestedRegs == nFinishedRegs) {
+ if (m_nRequestedRegs == m_nFinishedRegs) {
MulticastDiscovery::setStrategy();
}
}
void
-MulticastDiscovery::onRegisterFailure(const nfd::ControlResponse& response)
+MulticastDiscovery::onRegisterFailure(const ControlResponse& response)
{
std::cerr << "ERROR: " << response.getText() << " (code: " << response.getCode() << ")" << std::endl;
- --nRequestedRegs;
+ --m_nRequestedRegs;
- if (nRequestedRegs == nFinishedRegs) {
- if (nRequestedRegs > 0) {
+ if (m_nRequestedRegs == m_nFinishedRegs) {
+ if (m_nRequestedRegs > 0) {
MulticastDiscovery::setStrategy();
- } else {
+ }
+ else {
m_nextStageOnFailure("Failed to register " + LOCALHOP_HUB_DISCOVERY_PREFIX.toUri() +
" for all multicast faces, skipping multicast discovery stage");
}
@@ -142,19 +139,19 @@
void
MulticastDiscovery::setStrategy()
{
- nfd::ControlParameters parameters;
+ ControlParameters parameters;
parameters
.setName(LOCALHOP_HUB_DISCOVERY_PREFIX)
.setStrategy("/localhost/nfd/strategy/multicast");
- m_controller.start<nfd::StrategyChoiceSetCommand>(parameters,
- bind(&MulticastDiscovery::requestHubData, this),
- bind(&MulticastDiscovery::onSetStrategyFailure,
- this, _1));
+ m_controller.start<ndn::nfd::StrategyChoiceSetCommand>(
+ parameters,
+ bind(&MulticastDiscovery::requestHubData, this),
+ bind(&MulticastDiscovery::onSetStrategyFailure, this, _1));
}
void
-MulticastDiscovery::onSetStrategyFailure(const nfd::ControlResponse& response)
+MulticastDiscovery::onSetStrategyFailure(const ControlResponse& response)
{
m_nextStageOnFailure("Failed to set multicast strategy for " +
LOCALHOP_HUB_DISCOVERY_PREFIX.toUri() + " namespace (" + response.getText() + "). "
diff --git a/tools/ndn-autoconfig/multicast-discovery.hpp b/tools/ndn-autoconfig/multicast-discovery.hpp
index 32f7133..b437aee 100644
--- a/tools/ndn-autoconfig/multicast-discovery.hpp
+++ b/tools/ndn-autoconfig/multicast-discovery.hpp
@@ -69,13 +69,13 @@
onRegisterSuccess();
void
- onRegisterFailure(const nfd::ControlResponse& response);
+ onRegisterFailure(const ControlResponse& response);
void
setStrategy();
void
- onSetStrategyFailure(const nfd::ControlResponse& response);
+ onSetStrategyFailure(const ControlResponse& response);
// Start to look for a hub (NDN hub discovery first stage)
void
@@ -85,8 +85,8 @@
onSuccess(Data& data);
private:
- size_t nRequestedRegs;
- size_t nFinishedRegs;
+ size_t m_nRequestedRegs;
+ size_t m_nFinishedRegs;
ndn::ValidatorNull m_validator;
};