| /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| /* |
| * Copyright (c) 2014-2023, The University of Memphis, |
| * Regents of the University of California, |
| * Arizona Board of Regents. |
| * |
| * This file is part of NLSR (Named-data Link State Routing). |
| * See AUTHORS.md for complete list of NLSR authors and contributors. |
| * |
| * NLSR is free software: you can redistribute it and/or modify it under the terms |
| * of the GNU General Public License as published by the Free Software Foundation, |
| * either version 3 of the License, or (at your option) any later version. |
| * |
| * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| * PURPOSE. See the GNU General Public License for more details. |
| * |
| * You should have received a copy of the GNU General Public License along with |
| * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| **/ |
| |
| #include "conf-file-processor.hpp" |
| #include "nlsr.hpp" |
| #include "security/certificate-store.hpp" |
| #include "version.hpp" |
| |
| #include <boost/exception/diagnostic_information.hpp> |
| #include <iostream> |
| |
| static void |
| printUsage(std::ostream& os, const std::string& programName) |
| { |
| os << "Usage: " << programName << " [OPTIONS...]\n" |
| << "\n" |
| << "Options:\n" |
| << " -f <FILE> Path to configuration file\n" |
| << " -h Display this help message\n" |
| << " -V Display version information\n" |
| << std::endl; |
| } |
| |
| int |
| main(int argc, char** argv) |
| { |
| std::string programName(argv[0]); |
| std::string configFileName("nlsr.conf"); |
| |
| int opt; |
| while ((opt = getopt(argc, argv, "hf:V")) != -1) { |
| switch (opt) { |
| case 'h': |
| printUsage(std::cout, programName); |
| return 0; |
| case 'f': |
| configFileName = optarg; |
| break; |
| case 'V': |
| std::cout << NLSR_VERSION_BUILD_STRING << std::endl; |
| return 0; |
| default: |
| printUsage(std::cerr, programName); |
| return 2; |
| } |
| } |
| |
| ndn::KeyChain keyChain; |
| ndn::Face face(nullptr, keyChain); |
| |
| nlsr::ConfParameter confParam(face, keyChain, configFileName); |
| nlsr::ConfFileProcessor configProcessor(confParam); |
| if (!configProcessor.processConfFile()) { |
| std::cerr << "Error in configuration file processing" << std::endl; |
| return 2; |
| } |
| |
| // Since confParam is already populated, key is initialized here before |
| // and independent of the NLSR class |
| auto certificate = confParam.initializeKey(); |
| |
| nlsr::Nlsr nlsr(face, keyChain, confParam); |
| |
| nlsr::security::CertificateStore certStore(face, confParam, nlsr.getLsdb()); |
| if (certificate) { |
| certStore.insert(*certificate); |
| } |
| |
| try { |
| face.processEvents(); |
| } |
| catch (const std::exception& e) { |
| nlsr.getFib().clean(); |
| std::cerr << "FATAL: " << boost::diagnostic_information(e) << std::endl; |
| return 1; |
| } |
| |
| return 0; |
| } |