shockjiang | 99ad389 | 2014-08-03 14:56:13 -0700 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014, Regents of the University of California. |
shockjiang | 8531202 | 2014-07-27 23:22:16 -0700 | [diff] [blame] | 4 | * |
shockjiang | 99ad389 | 2014-08-03 14:56:13 -0700 | [diff] [blame^] | 5 | * This file is part of NDNS (Named Data Networking Domain Name Service). |
| 6 | * See AUTHORS.md for complete list of NDNS authors and contributors. |
shockjiang | 8531202 | 2014-07-27 23:22:16 -0700 | [diff] [blame] | 7 | * |
shockjiang | 99ad389 | 2014-08-03 14:56:13 -0700 | [diff] [blame^] | 8 | * NDNS is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
shockjiang | 8531202 | 2014-07-27 23:22:16 -0700 | [diff] [blame] | 18 | */ |
| 19 | |
shockjiang | 8531202 | 2014-07-27 23:22:16 -0700 | [diff] [blame] | 20 | #include "app/name-caching-resolver.hpp" |
shockjiang | 99ad389 | 2014-08-03 14:56:13 -0700 | [diff] [blame^] | 21 | #include <ndn-cxx/face.hpp> |
| 22 | #include <ndn-cxx/name.hpp> |
| 23 | #include <ndn-cxx/security/key-chain.hpp> |
| 24 | #include "boost/program_options.hpp" |
| 25 | #include "boost/filesystem.hpp" |
| 26 | |
| 27 | using namespace ndn; |
| 28 | using namespace ndn::ndns; |
| 29 | using namespace std; |
| 30 | |
shockjiang | 8531202 | 2014-07-27 23:22:16 -0700 | [diff] [blame] | 31 | |
| 32 | |
| 33 | int main(int argc, char * argv[]) |
| 34 | { |
shockjiang | 99ad389 | 2014-08-03 14:56:13 -0700 | [diff] [blame^] | 35 | string route="/"; |
| 36 | int lifetime=2; |
| 37 | string hint = ""; |
| 38 | try{ |
shockjiang | 8531202 | 2014-07-27 23:22:16 -0700 | [diff] [blame] | 39 | |
shockjiang | 99ad389 | 2014-08-03 14:56:13 -0700 | [diff] [blame^] | 40 | namespace po = boost::program_options; |
| 41 | po::variables_map vm; |
| 42 | |
| 43 | |
| 44 | po::options_description generic("Generic Options"); |
| 45 | generic.add_options() |
| 46 | ("help,h", "print help message") |
| 47 | ; |
| 48 | |
| 49 | |
| 50 | po::options_description config("Configuration"); |
| 51 | config.add_options() |
| 52 | ("lifetime,t", po::value<std::string>(), "set the lifetime of Interest. default: 2") |
| 53 | ("hint,H", po::value<std::string>(&hint), "enable the forwarding Hint of Root Zone, which is disable by default") |
| 54 | ; |
| 55 | |
| 56 | |
| 57 | po::options_description hidden("Hidden Options"); |
| 58 | hidden.add_options() |
| 59 | ("prefix,p", po::value<string>(&route), "routable prefix of the server. default: /") |
| 60 | ; |
| 61 | |
| 62 | po::positional_options_description postion; |
| 63 | postion.add("prefix", 1); |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | po::options_description cmdline_options; |
| 69 | cmdline_options.add(generic).add(config).add(hidden); |
| 70 | |
| 71 | po::options_description config_file_options; |
| 72 | config_file_options.add(config).add(hidden); |
| 73 | |
| 74 | po::options_description visible("Allowed options"); |
| 75 | visible.add(generic).add(config); |
| 76 | |
| 77 | |
| 78 | po::parsed_options parsed = po::command_line_parser(argc, argv).options(cmdline_options).positional(postion).run(); |
| 79 | |
| 80 | |
| 81 | po::store(parsed, vm); |
| 82 | po::notify(vm); |
| 83 | |
| 84 | if (vm.count("help")) |
| 85 | { |
| 86 | cout<<"E.g: caching-resolver-daemon /routable/prefix/announced"<<endl; |
| 87 | cout<<visible<<endl; |
| 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | cout<<"routablePrefix="<<route<<" lifetime="<<lifetime<<endl; |
| 92 | } |
| 93 | catch(const std::exception& ex) |
shockjiang | 8531202 | 2014-07-27 23:22:16 -0700 | [diff] [blame] | 94 | { |
shockjiang | 99ad389 | 2014-08-03 14:56:13 -0700 | [diff] [blame^] | 95 | cout << "Parameter Error: " << ex.what() << endl; |
| 96 | return 0; |
| 97 | } |
| 98 | catch(...) |
| 99 | { |
| 100 | cout << "Parameter Unknown error" << endl; |
| 101 | return 0; |
shockjiang | 8531202 | 2014-07-27 23:22:16 -0700 | [diff] [blame] | 102 | } |
| 103 | |
shockjiang | 8531202 | 2014-07-27 23:22:16 -0700 | [diff] [blame] | 104 | |
shockjiang | 8531202 | 2014-07-27 23:22:16 -0700 | [diff] [blame] | 105 | |
shockjiang | 99ad389 | 2014-08-03 14:56:13 -0700 | [diff] [blame^] | 106 | |
| 107 | if (hint != "") |
| 108 | { |
| 109 | ndn::ndns::NameCachingResolver<IterativeQueryWithFowardingHint> server(argv[0], route.c_str()); |
| 110 | server.setEnableForwardingHint(1); |
| 111 | server.setRootZoneFowardingHint(Name(hint)); |
| 112 | |
| 113 | time::milliseconds t(1000*lifetime); |
| 114 | server.setInterestLifetime(t); |
| 115 | |
| 116 | server.run(); |
| 117 | |
| 118 | cout<<"the server ends with hasError="<<server.hasError()<<endl; |
| 119 | |
| 120 | if (server.hasError()){ |
| 121 | return 0; |
| 122 | } else { |
| 123 | return 1; |
| 124 | } |
| 125 | |
shockjiang | 8531202 | 2014-07-27 23:22:16 -0700 | [diff] [blame] | 126 | } else { |
shockjiang | 99ad389 | 2014-08-03 14:56:13 -0700 | [diff] [blame^] | 127 | ndn::ndns::NameCachingResolver<IterativeQuery> server(argv[0], route.c_str()); |
| 128 | |
| 129 | time::milliseconds t(1000*lifetime); |
| 130 | server.setInterestLifetime(t); |
| 131 | |
| 132 | server.run(); |
| 133 | |
| 134 | cout<<"the server ends with hasError="<<server.hasError()<<endl; |
| 135 | |
| 136 | if (server.hasError()){ |
| 137 | return 0; |
| 138 | } else { |
| 139 | return 1; |
| 140 | } |
| 141 | |
shockjiang | 8531202 | 2014-07-27 23:22:16 -0700 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | } |
| 145 | |