main.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2023, The University of Memphis,
4  * Regents of the University of California,
5  * Arizona Board of Regents.
6  *
7  * This file is part of NLSR (Named-data Link State Routing).
8  * See AUTHORS.md for complete list of NLSR authors and contributors.
9  *
10  * NLSR is free software: you can redistribute it and/or modify it under the terms
11  * of the GNU General Public License as published by the Free Software Foundation,
12  * either version 3 of the License, or (at your option) any later version.
13  *
14  * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16  * PURPOSE. See the GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along with
19  * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
20  **/
21 
22 #include "conf-file-processor.hpp"
23 #include "nlsr.hpp"
25 #include "version.hpp"
26 
27 #include <boost/exception/diagnostic_information.hpp>
28 #include <iostream>
29 
30 static void
31 printUsage(std::ostream& os, const std::string& programName)
32 {
33  os << "Usage: " << programName << " [OPTIONS...]\n"
34  << "\n"
35  << "Options:\n"
36  << " -f <FILE> Path to configuration file\n"
37  << " -h Display this help message\n"
38  << " -V Display version information\n"
39  << std::endl;
40 }
41 
42 int
43 main(int argc, char** argv)
44 {
45  std::string programName(argv[0]);
46  std::string configFileName("nlsr.conf");
47 
48  int opt;
49  while ((opt = getopt(argc, argv, "hf:V")) != -1) {
50  switch (opt) {
51  case 'h':
52  printUsage(std::cout, programName);
53  return 0;
54  case 'f':
55  configFileName = optarg;
56  break;
57  case 'V':
58  std::cout << NLSR_VERSION_BUILD_STRING << std::endl;
59  return 0;
60  default:
61  printUsage(std::cerr, programName);
62  return 2;
63  }
64  }
65 
66  ndn::KeyChain keyChain;
67  ndn::Face face(nullptr, keyChain);
68 
69  nlsr::ConfParameter confParam(face, keyChain, configFileName);
70  nlsr::ConfFileProcessor configProcessor(confParam);
71  if (!configProcessor.processConfFile()) {
72  std::cerr << "Error in configuration file processing" << std::endl;
73  return 2;
74  }
75 
76  // Since confParam is already populated, key is initialized here before
77  // and independent of the NLSR class
78  auto certificate = confParam.initializeKey();
79 
80  nlsr::Nlsr nlsr(face, keyChain, confParam);
81 
82  nlsr::security::CertificateStore certStore(face, confParam, nlsr.getLsdb());
83  if (certificate) {
84  certStore.insert(*certificate);
85  }
86 
87  try {
88  face.processEvents();
89  }
90  catch (const std::exception& e) {
91  nlsr.getFib().clean();
92  std::cerr << "FATAL: " << boost::diagnostic_information(e) << std::endl;
93  return 1;
94  }
95 
96  return 0;
97 }
A class containing methods to parse an NLSR configuration file.
bool processConfFile()
Load and parse the configuration file, then populate NLSR.
A class to house all the configuration parameters for NLSR.
std::optional< ndn::security::Certificate > initializeKey()
Store certificates for names.
void insert(const ndn::security::Certificate &certificate)
int main(int argc, char **argv)
Definition: main.cpp:43
static void printUsage(std::ostream &os, const std::string &programName)
Definition: main.cpp:31
Copyright (c) 2014-2020, The University of Memphis, Regents of the University of California.