32 #include "core/version.hpp"
36 #include <boost/config.hpp>
37 #include <boost/exception/diagnostic_information.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>
42 #include <boost/version.hpp>
45 #include <condition_variable>
49 #include <ndn-cxx/util/logging.hpp>
51 #include <ndn-cxx/version.hpp>
54 #include <pcap/pcap.h>
57 #include <systemd/sd-daemon.h>
60 #include <websocketpp/version.hpp>
63 namespace po = boost::program_options;
83 : m_nfd(configFile, m_nfdKeyChain)
84 , m_configFile(configFile)
88 m_terminationSignalSet.add(SIGINT);
89 m_terminationSignalSet.add(SIGTERM);
90 m_terminationSignalSet.async_wait(bind(&NfdRunner::terminate,
this, _1, _2));
92 m_reloadSignalSet.add(SIGHUP);
93 m_reloadSignalSet.async_wait(bind(&NfdRunner::reload,
this, _1, _2));
107 std::atomic_int retval(0);
110 setMainIoService(mainIo);
111 boost::asio::io_service* ribIo =
nullptr;
118 std::condition_variable cv;
120 std::thread ribThread([configFile = m_configFile, &retval, &ribIo, mainIo, &cv, &m] {
122 std::lock_guard<std::mutex> lock(m);
124 BOOST_ASSERT(ribIo != mainIo);
125 setRibIoService(ribIo);
135 catch (
const std::exception& e) {
142 std::lock_guard<std::mutex> lock(m);
150 std::unique_lock<std::mutex> lock(m);
151 cv.wait(lock, [&ribIo] {
return ribIo !=
nullptr; });
158 catch (
const std::exception& e) {
169 std::lock_guard<std::mutex> lock(m);
170 if (ribIo !=
nullptr) {
190 terminate(
const boost::system::error_code& error,
int signalNo)
195 NFD_LOG_INFO(
"Caught signal " << signalNo <<
" (" << ::strsignal(signalNo) <<
"), exiting...");
202 reload(
const boost::system::error_code& error,
int signalNo)
207 NFD_LOG_INFO(
"Caught signal " << signalNo <<
" (" << ::strsignal(signalNo) <<
"), reloading...");
213 m_reloadSignalSet.async_wait(bind(&NfdRunner::reload,
this, _1, _2));
219 std::string m_configFile;
221 boost::asio::signal_set m_terminationSignalSet;
222 boost::asio::signal_set m_reloadSignalSet;
226 printUsage(std::ostream& os,
const char* programName,
const po::options_description& opts)
228 os <<
"Usage: " << programName <<
" [options]\n"
230 <<
"Run the NDN Forwarding Daemon (NFD)\n"
238 const auto& modules = ndn::util::Logging::getLoggerNames();
250 std::string configFile = DEFAULT_CONFIG_FILE;
252 po::options_description description(
"Options");
253 description.add_options()
254 (
"help,h",
"print this message and exit")
255 (
"version,V",
"show version information and exit")
256 (
"config,c", po::value<std::string>(&configFile),
257 "path to configuration file (default: " DEFAULT_CONFIG_FILE
")")
258 (
"modules,m",
"list available logging modules")
261 po::variables_map vm;
263 po::store(po::parse_command_line(argc, argv, description), vm);
266 catch (
const std::exception& e) {
270 std::cerr <<
"ERROR: " << e.what() <<
"\n\n";
275 if (vm.count(
"help") > 0) {
280 if (vm.count(
"version") > 0) {
281 std::cout << NFD_VERSION_BUILD_STRING << std::endl;
285 if (vm.count(
"modules") > 0) {
290 const std::string boostBuildInfo =
291 "with Boost version " +
to_string(BOOST_VERSION / 100000) +
292 "." +
to_string(BOOST_VERSION / 100 % 1000) +
294 const std::string pcapBuildInfo =
296 "with " + std::string(pcap_lib_version());
300 const std::string wsBuildInfo =
301 #ifdef HAVE_WEBSOCKET
302 "with WebSocket++ version " +
to_string(websocketpp::major_version) +
303 "." +
to_string(websocketpp::minor_version) +
304 "." +
to_string(websocketpp::patch_version);
306 "without WebSocket++";
309 std::clog <<
"NFD version " << NFD_VERSION_BUILD_STRING <<
" starting\n"
310 <<
"Built with " BOOST_COMPILER
", with " BOOST_STDLIB
311 ", " << boostBuildInfo <<
312 ", " << pcapBuildInfo <<
313 ", " << wsBuildInfo <<
314 ", with ndn-cxx version " NDN_CXX_VERSION_BUILD_STRING
321 catch (
const boost::filesystem::filesystem_error& e) {
323 return e.code() == boost::system::errc::permission_denied ? 4 : 1;
325 catch (
const std::exception& e) {