blob: dfe54a7c8470f48ab6cd11a512a94dc6362ffb03 [file] [log] [blame]
Yingdi Yu40cd1c32014-04-17 15:02:17 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventoe3c741d2019-01-29 20:28:15 -05002/*
Davide Pesavento5849ee72023-11-12 20:00:21 -05003 * Copyright (c) 2014-2023, The University of Memphis,
Vince Lehman9dce0c92015-02-09 12:53:41 -06004 * Regents of the University of California,
5 * Arizona Board of Regents.
Yingdi Yu40cd1c32014-04-17 15:02:17 -07006 *
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 **/
Alexander Afanasyevb669f9c2014-11-14 12:41:54 -080021
Ashlesh Gawande85998a12017-12-07 22:22:13 -060022#include "conf-file-processor.hpp"
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050023#include "nlsr.hpp"
Davide Pesaventod90338d2021-01-07 17:50:05 -050024#include "security/certificate-store.hpp"
Vince Lehmanb722b102014-08-24 16:33:49 -050025#include "version.hpp"
Yingdi Yu40cd1c32014-04-17 15:02:17 -070026
Davide Pesaventod90338d2021-01-07 17:50:05 -050027#include <boost/exception/diagnostic_information.hpp>
28#include <iostream>
Alexander Afanasyev7afe22f2018-02-13 16:17:40 -050029
Davide Pesaventoe3c741d2019-01-29 20:28:15 -050030static void
31printUsage(std::ostream& os, const std::string& programName)
Yingdi Yu40cd1c32014-04-17 15:02:17 -070032{
Davide Pesaventoe3c741d2019-01-29 20:28:15 -050033 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}
Vince Lehman7c603292014-09-11 17:48:16 -050041
Davide Pesaventoe3c741d2019-01-29 20:28:15 -050042int
43main(int argc, char** argv)
44{
akmhoquefdbddb12014-05-02 18:35:19 -050045 std::string programName(argv[0]);
Davide Pesaventoe3c741d2019-01-29 20:28:15 -050046 std::string configFileName("nlsr.conf");
Vince Lehmanc57c64b2015-08-10 12:21:31 -050047
Davide Pesaventoe3c741d2019-01-29 20:28:15 -050048 int opt;
49 while ((opt = getopt(argc, argv, "hf:V")) != -1) {
Vince Lehmanc57c64b2015-08-10 12:21:31 -050050 switch (opt) {
Davide Pesaventoe3c741d2019-01-29 20:28:15 -050051 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;
Vince Lehmanc57c64b2015-08-10 12:21:31 -050063 }
Yingdi Yu40cd1c32014-04-17 15:02:17 -070064 }
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -050065
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050066 ndn::KeyChain keyChain;
Davide Pesavento5849ee72023-11-12 20:00:21 -050067 ndn::Face face(nullptr, keyChain);
Ashlesh Gawande85998a12017-12-07 22:22:13 -060068
Saurab Dulal427e0122019-11-28 11:58:02 -060069 nlsr::ConfParameter confParam(face, keyChain, configFileName);
Ashlesh Gawande85998a12017-12-07 22:22:13 -060070 nlsr::ConfFileProcessor configProcessor(confParam);
Ashlesh Gawande85998a12017-12-07 22:22:13 -060071 if (!configProcessor.processConfFile()) {
72 std::cerr << "Error in configuration file processing" << std::endl;
73 return 2;
74 }
Davide Pesaventod90338d2021-01-07 17:50:05 -050075
Saurab Dulal427e0122019-11-28 11:58:02 -060076 // Since confParam is already populated, key is initialized here before
77 // and independent of the NLSR class
78 auto certificate = confParam.initializeKey();
Ashlesh Gawande85998a12017-12-07 22:22:13 -060079
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050080 nlsr::Nlsr nlsr(face, keyChain, confParam);
Vince Lehmanc57c64b2015-08-10 12:21:31 -050081
Saurab Dulal427e0122019-11-28 11:58:02 -060082 nlsr::security::CertificateStore certStore(face, confParam, nlsr.getLsdb());
Saurab Dulal427e0122019-11-28 11:58:02 -060083 if (certificate) {
84 certStore.insert(*certificate);
85 }
86
Vince Lehmanc57c64b2015-08-10 12:21:31 -050087 try {
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050088 face.processEvents();
Vince Lehmanc57c64b2015-08-10 12:21:31 -050089 }
90 catch (const std::exception& e) {
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050091 nlsr.getFib().clean();
Davide Pesaventod90338d2021-01-07 17:50:05 -050092 std::cerr << "FATAL: " << boost::diagnostic_information(e) << std::endl;
Davide Pesaventoe3c741d2019-01-29 20:28:15 -050093 return 1;
Yingdi Yu40cd1c32014-04-17 15:02:17 -070094 }
Vince Lehmanf99b87f2014-08-26 15:54:27 -050095
Davide Pesaventoe3c741d2019-01-29 20:28:15 -050096 return 0;
Yingdi Yu40cd1c32014-04-17 15:02:17 -070097}