30 #include "core/logger-factory.hpp" 33 #include <boost/property_tree/info_parser.hpp> 35 #include <ndn-cxx/transport/unix-transport.hpp> 36 #include <ndn-cxx/transport/tcp-transport.hpp> 43 Nrd::Nrd(
const std::string& configFile, ndn::KeyChain& keyChain)
44 : m_configFile(configFile)
45 , m_keyChain(keyChain)
50 : m_configSection(config)
51 , m_keyChain(keyChain)
69 m_ribManager.reset(
new RibManager(*m_face, m_keyChain));
71 ConfigFile config([] (
const std::string& filename,
const std::string& sectionName,
75 if (sectionName !=
"rib" || sectionName ==
"log") {
83 m_ribManager->setConfigFile(config);
86 if (!m_configFile.empty()) {
87 config.parse(m_configFile,
true);
88 config.parse(m_configFile,
false);
91 config.parse(m_configSection,
true, INTERNAL_CONFIG);
92 config.parse(m_configSection,
false, INTERNAL_CONFIG);
95 m_ribManager->registerWithNfd();
96 m_ribManager->enableLocalControlHeader();
100 Nrd::initializeLogging()
103 LoggerFactory::getInstance().setConfigFile(config);
105 if (!m_configFile.empty()) {
106 config.
parse(m_configFile,
true);
107 config.
parse(m_configFile,
false);
110 config.
parse(m_configSection,
true, INTERNAL_CONFIG);
111 config.
parse(m_configSection,
false, INTERNAL_CONFIG);
115 shared_ptr<ndn::Transport>
116 Nrd::getLocalNfdTransport()
120 if (!m_configFile.empty()) {
123 boost::property_tree::read_info(m_configFile, config);
126 config = m_configSection;
128 if (config.get_child_optional(
"face_system.unix")) {
131 auto&& socketPath = config.get<std::string>(
"face_system.unix.path",
"/var/run/nfd.sock");
134 return make_shared<ndn::UnixTransport>(socketPath);
136 else if (config.get_child_optional(
"face_system.tcp") &&
137 config.get<std::string>(
"face_system.tcp.listen",
"yes") ==
"yes") {
140 auto&& port = config.get<std::string>(
"face_system.tcp.port",
"6363");
143 return make_shared<ndn::TcpTransport>(
"localhost", port);
146 BOOST_THROW_EXCEPTION(
Error(
"No transport is available to communicate with NFD"));
static const std::string INTERNAL_CONFIG
Nrd(const std::string &configFile, ndn::KeyChain &keyChain)
Create NRD instance using absolute or relative path to configFile.
static void throwErrorOnUnknownSection(const std::string &filename, const std::string §ionName, const ConfigSection §ion, bool isDryRun)
Copyright (c) 2011-2015 Regents of the University of California.
Abstraction to communicate with local or remote NDN forwarder.
boost::property_tree::ptree ConfigSection
static void ignoreUnknownSection(const std::string &filename, const std::string §ionName, const ConfigSection §ion, bool isDryRun)
void initialize()
Perform initialization of NFD instance After initialization, NFD instance can be started by invoking ...
boost::asio::io_service & getGlobalIoService()
void parse(const std::string &filename, bool isDryRun)