Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | e3c741d | 2019-01-29 20:28:15 -0500 | [diff] [blame] | 2 | /* |
Davide Pesavento | 5849ee7 | 2023-11-12 20:00:21 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2023, The University of Memphis, |
Vince Lehman | 9dce0c9 | 2015-02-09 12:53:41 -0600 | [diff] [blame] | 4 | * Regents of the University of California, |
| 5 | * Arizona Board of Regents. |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 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 | **/ |
Alexander Afanasyev | b669f9c | 2014-11-14 12:41:54 -0800 | [diff] [blame] | 21 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 22 | #include "conf-file-processor.hpp" |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 23 | #include "nlsr.hpp" |
Davide Pesavento | d90338d | 2021-01-07 17:50:05 -0500 | [diff] [blame] | 24 | #include "security/certificate-store.hpp" |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 25 | #include "version.hpp" |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 26 | |
Davide Pesavento | d90338d | 2021-01-07 17:50:05 -0500 | [diff] [blame] | 27 | #include <boost/exception/diagnostic_information.hpp> |
| 28 | #include <iostream> |
Alexander Afanasyev | 7afe22f | 2018-02-13 16:17:40 -0500 | [diff] [blame] | 29 | |
Davide Pesavento | e3c741d | 2019-01-29 20:28:15 -0500 | [diff] [blame] | 30 | static void |
| 31 | printUsage(std::ostream& os, const std::string& programName) |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 32 | { |
Davide Pesavento | e3c741d | 2019-01-29 20:28:15 -0500 | [diff] [blame] | 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 | } |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 41 | |
Davide Pesavento | e3c741d | 2019-01-29 20:28:15 -0500 | [diff] [blame] | 42 | int |
| 43 | main(int argc, char** argv) |
| 44 | { |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 45 | std::string programName(argv[0]); |
Davide Pesavento | e3c741d | 2019-01-29 20:28:15 -0500 | [diff] [blame] | 46 | std::string configFileName("nlsr.conf"); |
Vince Lehman | c57c64b | 2015-08-10 12:21:31 -0500 | [diff] [blame] | 47 | |
Davide Pesavento | e3c741d | 2019-01-29 20:28:15 -0500 | [diff] [blame] | 48 | int opt; |
| 49 | while ((opt = getopt(argc, argv, "hf:V")) != -1) { |
Vince Lehman | c57c64b | 2015-08-10 12:21:31 -0500 | [diff] [blame] | 50 | switch (opt) { |
Davide Pesavento | e3c741d | 2019-01-29 20:28:15 -0500 | [diff] [blame] | 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; |
Vince Lehman | c57c64b | 2015-08-10 12:21:31 -0500 | [diff] [blame] | 63 | } |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 64 | } |
Muktadir R Chowdhury | bfa2760 | 2014-10-31 10:57:41 -0500 | [diff] [blame] | 65 | |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 66 | ndn::KeyChain keyChain; |
Davide Pesavento | 5849ee7 | 2023-11-12 20:00:21 -0500 | [diff] [blame] | 67 | ndn::Face face(nullptr, keyChain); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 68 | |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 69 | nlsr::ConfParameter confParam(face, keyChain, configFileName); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 70 | nlsr::ConfFileProcessor configProcessor(confParam); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 71 | if (!configProcessor.processConfFile()) { |
| 72 | std::cerr << "Error in configuration file processing" << std::endl; |
| 73 | return 2; |
| 74 | } |
Davide Pesavento | d90338d | 2021-01-07 17:50:05 -0500 | [diff] [blame] | 75 | |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 76 | // Since confParam is already populated, key is initialized here before |
| 77 | // and independent of the NLSR class |
| 78 | auto certificate = confParam.initializeKey(); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 79 | |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 80 | nlsr::Nlsr nlsr(face, keyChain, confParam); |
Vince Lehman | c57c64b | 2015-08-10 12:21:31 -0500 | [diff] [blame] | 81 | |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 82 | nlsr::security::CertificateStore certStore(face, confParam, nlsr.getLsdb()); |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 83 | if (certificate) { |
| 84 | certStore.insert(*certificate); |
| 85 | } |
| 86 | |
Vince Lehman | c57c64b | 2015-08-10 12:21:31 -0500 | [diff] [blame] | 87 | try { |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 88 | face.processEvents(); |
Vince Lehman | c57c64b | 2015-08-10 12:21:31 -0500 | [diff] [blame] | 89 | } |
| 90 | catch (const std::exception& e) { |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 91 | nlsr.getFib().clean(); |
Davide Pesavento | d90338d | 2021-01-07 17:50:05 -0500 | [diff] [blame] | 92 | std::cerr << "FATAL: " << boost::diagnostic_information(e) << std::endl; |
Davide Pesavento | e3c741d | 2019-01-29 20:28:15 -0500 | [diff] [blame] | 93 | return 1; |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 94 | } |
Vince Lehman | f99b87f | 2014-08-26 15:54:27 -0500 | [diff] [blame] | 95 | |
Davide Pesavento | e3c741d | 2019-01-29 20:28:15 -0500 | [diff] [blame] | 96 | return 0; |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 97 | } |