33 #include "core/version.hpp" 37 #include <boost/config.hpp> 38 #include <boost/filesystem.hpp> 39 #include <boost/program_options/options_description.hpp> 40 #include <boost/program_options/parsers.hpp> 41 #include <boost/program_options/variables_map.hpp> 44 #include <boost/thread.hpp> 45 #include <boost/version.hpp> 48 #include <condition_variable> 51 #include <ndn-cxx/util/logging.hpp> 52 #include <ndn-cxx/version.hpp> 55 #include <pcap/pcap.h> 58 #include <systemd/sd-daemon.h> 61 #include <websocketpp/version.hpp> 64 namespace po = boost::program_options;
84 : m_nfd(configFile, m_nfdKeyChain)
85 , m_configFile(configFile)
89 m_terminationSignalSet.add(SIGINT);
90 m_terminationSignalSet.add(SIGTERM);
91 m_terminationSignalSet.async_wait(bind(&NfdRunner::terminate,
this, _1, _2));
93 m_reloadSignalSet.add(SIGHUP);
94 m_reloadSignalSet.async_wait(bind(&NfdRunner::reload,
this, _1, _2));
108 std::atomic_int retval(0);
111 setMainIoService(mainIo);
112 boost::asio::io_service* ribIo =
nullptr;
119 std::condition_variable cv;
121 std::string configFile = this->m_configFile;
122 boost::thread ribThread([configFile, &retval, &ribIo, mainIo, &cv, &m] {
124 std::lock_guard<std::mutex> lock(m);
126 BOOST_ASSERT(ribIo != mainIo);
127 setRibIoService(ribIo);
137 catch (
const std::exception& e) {
144 std::lock_guard<std::mutex> lock(m);
152 std::unique_lock<std::mutex> lock(m);
153 cv.wait(lock, [&ribIo] {
return ribIo !=
nullptr; });
160 catch (
const std::exception& e) {
171 std::lock_guard<std::mutex> lock(m);
172 if (ribIo !=
nullptr) {
192 terminate(
const boost::system::error_code& error,
int signalNo)
197 NFD_LOG_INFO(
"Caught signal '" << ::strsignal(signalNo) <<
"', exiting...");
204 reload(
const boost::system::error_code& error,
int signalNo)
209 NFD_LOG_INFO(
"Caught signal '" << ::strsignal(signalNo) <<
"', reloading...");
215 m_reloadSignalSet.async_wait(bind(&NfdRunner::reload,
this, _1, _2));
221 std::string m_configFile;
223 boost::asio::signal_set m_terminationSignalSet;
224 boost::asio::signal_set m_reloadSignalSet;
228 printUsage(std::ostream& os,
const char* programName,
const po::options_description& opts)
230 os <<
"Usage: " << programName <<
" [options]\n" 232 <<
"Run the NDN Forwarding Daemon (NFD)\n" 240 const auto& modules = ndn::util::Logging::getLoggerNames();
252 std::string configFile = DEFAULT_CONFIG_FILE;
254 po::options_description description(
"Options");
255 description.add_options()
256 (
"help,h",
"print this message and exit")
257 (
"version,V",
"show version information and exit")
258 (
"config,c", po::value<std::string>(&configFile),
259 "path to configuration file (default: " DEFAULT_CONFIG_FILE
")")
260 (
"modules,m",
"list available logging modules")
263 po::variables_map vm;
265 po::store(po::parse_command_line(argc, argv, description), vm);
268 catch (
const std::exception& e) {
272 std::cerr <<
"ERROR: " << e.what() <<
"\n\n";
277 if (vm.count(
"help") > 0) {
282 if (vm.count(
"version") > 0) {
283 std::cout << NFD_VERSION_BUILD_STRING << std::endl;
287 if (vm.count(
"modules") > 0) {
292 const std::string boostBuildInfo =
293 "with Boost version " +
to_string(BOOST_VERSION / 100000) +
294 "." +
to_string(BOOST_VERSION / 100 % 1000) +
296 const std::string pcapBuildInfo =
298 "with " + std::string(pcap_lib_version());
302 const std::string wsBuildInfo =
303 #ifdef HAVE_WEBSOCKET 304 "with WebSocket++ version " +
to_string(websocketpp::major_version) +
305 "." +
to_string(websocketpp::minor_version) +
306 "." +
to_string(websocketpp::patch_version);
308 "without WebSocket++";
311 std::clog <<
"NFD version " NFD_VERSION_BUILD_STRING
" starting\n" 312 <<
"Built with " BOOST_COMPILER
", with " BOOST_STDLIB
313 ", " << boostBuildInfo <<
314 ", " << pcapBuildInfo <<
315 ", " << wsBuildInfo <<
316 ", with ndn-cxx version " NDN_CXX_VERSION_BUILD_STRING
323 catch (
const boost::filesystem::filesystem_error& e) {
324 if (e.code() == boost::system::errc::permission_denied) {
326 ". This program should be run as superuser");
334 catch (
const std::exception& e) {
std::string getExtendedErrorMessage(const E &exception)
static void printLogModules(std::ostream &os)
The interface of signing key management.
initializes and executes NFD-RIB service thread
represents a serious seteuid/gid failure
int main(int argc, char **argv)
detail::SimulatorIo & getGlobalIoService()
NfdRunner(const std::string &configFile)
static void systemdNotify(const char *state)
void reloadConfigFile()
Reload configuration file and apply update (if any)
Copyright (c) 2011-2015 Regents of the University of California.
ostream_joiner< std::decay_t< DelimT >, CharT, Traits > make_ostream_joiner(std::basic_ostream< CharT, Traits > &os, DelimT &&delimiter)
void initialize()
Perform initialization of NFD instance After initialization, NFD instance can be started by invoking ...
Executes NFD with RIB manager.
static void printUsage(std::ostream &os, const char *programName, const po::options_description &opts)
std::string to_string(const V &v)
const char * what() const
#define NFD_LOG_INIT(name)