32 #include "core/logger-factory.hpp" 34 #include "core/version.hpp" 38 #include <boost/config.hpp> 39 #include <boost/filesystem.hpp> 40 #include <boost/program_options/options_description.hpp> 41 #include <boost/program_options/parsers.hpp> 42 #include <boost/program_options/variables_map.hpp> 45 #include <boost/thread.hpp> 46 #include <boost/version.hpp> 49 #include <condition_variable> 52 #include <ndn-cxx/version.hpp> 54 #include <pcap/pcap.h> 57 #include <websocketpp/version.hpp> 60 namespace po = boost::program_options;
80 : m_nfd(configFile, m_nfdKeyChain)
81 , m_configFile(configFile)
85 m_terminationSignalSet.add(SIGINT);
86 m_terminationSignalSet.add(SIGTERM);
89 m_reloadSignalSet.add(SIGHUP);
104 std::atomic_int retval(0);
107 boost::asio::io_service* ribIo =
nullptr;
114 std::condition_variable cv;
116 std::string configFile = this->m_configFile;
117 boost::thread ribThread([configFile, &retval, &ribIo, mainIo, &cv, &m] {
119 std::lock_guard<std::mutex> lock(m);
121 BOOST_ASSERT(ribIo != mainIo);
132 catch (
const std::exception& e) {
139 std::lock_guard<std::mutex> lock(m);
147 std::unique_lock<std::mutex> lock(m);
148 cv.wait(lock, [&ribIo] {
return ribIo !=
nullptr; });
154 catch (
const std::exception& e) {
165 std::lock_guard<std::mutex> lock(m);
166 if (ribIo !=
nullptr) {
177 terminate(
const boost::system::error_code& error,
int signalNo)
182 NFD_LOG_INFO(
"Caught signal '" << ::strsignal(signalNo) <<
"', exiting...");
187 reload(
const boost::system::error_code& error,
int signalNo)
192 NFD_LOG_INFO(
"Caught signal '" << ::strsignal(signalNo) <<
"', reloading...");
201 std::string m_configFile;
203 boost::asio::signal_set m_terminationSignalSet;
204 boost::asio::signal_set m_reloadSignalSet;
209 const po::options_description& opts)
211 os <<
"Usage: " << programName <<
" [options]\n" 212 <<
"Run the NDN Forwarding Daemon (NFD)\n" 220 const auto& factory = LoggerFactory::getInstance();
221 for (
const auto& module : factory.getModules()) {
222 os << module <<
"\n";
233 std::string configFile = DEFAULT_CONFIG_FILE;
235 po::options_description description(
"Options");
236 description.add_options()
237 (
"help,h",
"print this message and exit")
238 (
"version,V",
"show version information and exit")
239 (
"config,c", po::value<std::string>(&configFile),
240 "path to configuration file (default: " DEFAULT_CONFIG_FILE
")")
241 (
"modules,m",
"list available logging modules")
244 po::variables_map vm;
246 po::store(po::parse_command_line(argc, argv, description), vm);
249 catch (
const std::exception& e) {
252 std::cerr <<
"ERROR: " << e.what() <<
"\n\n";
257 if (vm.count(
"help") > 0) {
262 if (vm.count(
"version") > 0) {
263 std::cout << NFD_VERSION_BUILD_STRING << std::endl;
267 if (vm.count(
"modules") > 0) {
272 const std::string boostBuildInfo =
273 "with Boost version " +
to_string(BOOST_VERSION / 100000) +
274 "." +
to_string(BOOST_VERSION / 100 % 1000) +
276 const std::string pcapBuildInfo =
278 "with " + std::string(pcap_lib_version());
282 const std::string wsBuildInfo =
283 #ifdef HAVE_WEBSOCKET 284 "with WebSocket++ version " +
to_string(websocketpp::major_version) +
285 "." +
to_string(websocketpp::minor_version) +
286 "." +
to_string(websocketpp::patch_version);
288 "without WebSocket++";
291 NFD_LOG_INFO(
"NFD version " NFD_VERSION_BUILD_STRING
" starting");
293 ", with " BOOST_STDLIB
294 ", " << boostBuildInfo <<
295 ", " << pcapBuildInfo <<
296 ", " << wsBuildInfo <<
297 ", with ndn-cxx version " NDN_CXX_VERSION_BUILD_STRING);
303 catch (
const boost::filesystem::filesystem_error& e) {
304 if (e.code() == boost::system::errc::permission_denied) {
306 ". This program should be run as superuser");
314 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()
void initialize()
Perform initialization of NFD-RIB instance.
NfdRunner(const std::string &configFile)
#define NFD_LOG_INFO(expression)
void reload(const boost::system::error_code &error, int signalNo)
#define NFD_LOG_FATAL(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 ...
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)
void terminate(const boost::system::error_code &error, int signalNo)