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> 53 #ifdef NFD_HAVE_LIBPCAP 54 #include <pcap/pcap.h> 56 #ifdef NFD_HAVE_SYSTEMD 57 #include <systemd/sd-daemon.h> 59 #ifdef NFD_HAVE_WEBSOCKET 63 namespace po = boost::program_options;
83 : m_nfd(configFile, m_nfdKeyChain)
84 , m_configFile(configFile)
88 m_terminateSignals.async_wait([
this] (
auto&&... args) {
89 terminate(std::forward<decltype(args)>(args)...);
91 m_reloadSignals.async_wait([
this] (
auto&&... args) {
92 reload(std::forward<decltype(args)>(args)...);
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) {
183 #ifdef NFD_HAVE_SYSTEMD 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_reloadSignals.async_wait([
this] (
auto&&... args) {
214 reload(std::forward<decltype(args)>(args)...);
221 std::string m_configFile;
223 boost::asio::signal_set m_terminateSignals;
224 boost::asio::signal_set m_reloadSignals;
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 = NFD_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: " NFD_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 =
297 #ifdef NFD_HAVE_LIBPCAP 298 "with " + std::string(pcap_lib_version());
302 const std::string wsBuildInfo =
303 #ifdef NFD_HAVE_WEBSOCKET 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) {
325 return e.code() == boost::system::errc::permission_denied ? 4 : 1;
327 catch (
const std::exception& e) {
static void printLogModules(std::ostream &os)
#define NFD_LOG_INIT(name)
std::string to_string(const T &val)
initializes and executes NFD-RIB service thread
represents a serious seteuid/gid failure
int main(int argc, char **argv)
static int const patch_version
Library patch version number.
detail::SimulatorIo & getGlobalIoService()
Returns the global io_service instance for the calling thread.
NfdRunner(const std::string &configFile)
static void systemdNotify(const char *state)
static int const major_version
Library major version number.
void reloadConfigFile()
Reload configuration file and apply updates (if any).
Class representing the NFD instance.
Copyright (c) 2011-2015 Regents of the University of California.
Backport of ostream_joiner from the Library Fundamentals v2 TS.
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.
static int const minor_version
Library minor version number.
Executes NFD with RIB manager.
static void printUsage(std::ostream &os, const char *programName, const po::options_description &opts)
const char * what() const