29 #include "version.hpp" 36 #include <boost/filesystem.hpp> 37 #include <boost/program_options/options_description.hpp> 38 #include <boost/program_options/variables_map.hpp> 39 #include <boost/program_options/parsers.hpp> 43 #include <boost/thread.hpp> 46 #include <condition_variable> 66 : m_nfd(configFile, m_nfdKeyChain)
67 , m_configFile(configFile)
71 m_terminationSignalSet.add(SIGINT);
72 m_terminationSignalSet.add(SIGTERM);
75 m_reloadSignalSet.add(SIGHUP);
80 printUsage(std::ostream& os,
const std::string& programName)
83 <<
" " << programName <<
" [options]\n" 85 <<
"Run NFD forwarding daemon\n" 88 <<
" [--help] - print this help message\n" 89 <<
" [--version] - print version and exit\n" 90 <<
" [--modules] - list available logging modules\n" 91 <<
" [--config /path/to/nfd.conf] - path to configuration file " 99 os <<
"Available logging modules: \n";
101 for (
const auto& module : LoggerFactory::getInstance().getModules()) {
102 os << module <<
"\n";
119 std::atomic_int retval(0);
122 boost::asio::io_service* nrdIo =
nullptr;
129 std::condition_variable cv;
131 std::string configFile = this->m_configFile;
132 boost::thread nrdThread([configFile, &retval, &nrdIo, mainIo, &cv, &m] {
134 std::lock_guard<std::mutex> lock(m);
136 BOOST_ASSERT(nrdIo != mainIo);
141 ndn::KeyChain nrdKeyChain;
143 rib::Nrd nrd(configFile, nrdKeyChain);
147 catch (
const std::exception& e) {
154 std::lock_guard<std::mutex> lock(m);
162 std::unique_lock<std::mutex> lock(m);
163 cv.wait(lock, [&nrdIo] {
return nrdIo !=
nullptr; });
169 catch (
const std::exception& e) {
180 std::lock_guard<std::mutex> lock(m);
181 if (nrdIo !=
nullptr) {
192 terminate(
const boost::system::error_code& error,
int signalNo)
197 NFD_LOG_INFO(
"Caught signal '" << ::strsignal(signalNo) <<
"', exiting...");
202 reload(
const boost::system::error_code& error,
int signalNo)
207 NFD_LOG_INFO(
"Caught signal '" << ::strsignal(signalNo) <<
"', reloading...");
214 ndn::KeyChain m_nfdKeyChain;
216 std::string m_configFile;
218 boost::asio::signal_set m_terminationSignalSet;
219 boost::asio::signal_set m_reloadSignalSet;
229 namespace po = boost::program_options;
231 po::options_description description;
234 description.add_options()
235 (
"help,h",
"print this help message")
236 (
"version,V",
"print version and exit")
237 (
"modules,m",
"list available logging modules")
238 (
"config,c", po::value<std::string>(&configFile),
"path to configuration file")
241 po::variables_map vm;
243 po::store(po::command_line_parser(argc, argv).options(description).
run(), vm);
246 catch (
const std::exception& e) {
249 std::cerr <<
"ERROR: " << e.what() << std::endl;
254 if (vm.count(
"help") > 0) {
259 if (vm.count(
"version") > 0) {
260 std::cout << NFD_VERSION_BUILD_STRING << std::endl;
264 if (vm.count(
"modules") > 0) {
274 catch (
const boost::filesystem::filesystem_error& e) {
275 if (e.code() == boost::system::errc::permission_denied) {
276 NFD_LOG_FATAL(
"Permissions denied for " << e.path1() <<
". " <<
277 argv[0] <<
" should be run as superuser");
285 catch (
const std::exception& e) {
static void printUsage(std::ostream &os, const std::string &programName)
represents a serious seteuid/gid failure
int main(int argc, char **argv)
static void printModules(std::ostream &os)
NfdRunner(const std::string &configFile)
Class representing NRD (NFD RIB Manager) instance This class can be used to initialize all components...
void reload(const boost::system::error_code &error, int signalNo)
#define NFD_LOG_INFO(expression)
void reloadConfigFile()
Reload configuration file and apply update (if any)
Class representing NFD instance This class can be used to initialize all components of NFD...
Copyright (c) 2011-2015 Regents of the University of California.
void initialize()
Perform initialization of NFD instance After initialization, NFD instance can be started by invoking ...
#define NFD_LOG_INIT(name)
Executes NFD with RIB manager.
void initialize()
Perform initialization of NFD instance After initialization, NFD instance can be started by invoking ...
boost::asio::io_service & getGlobalIoService()
#define NFD_LOG_FATAL(expression)
#define DEFAULT_CONFIG_FILE
const char * what() const
void terminate(const boost::system::error_code &error, int signalNo)