blob: 453099e5f35a5506466b2e9696758fa392a512c0 [file] [log] [blame]
shockjiang99ad3892014-08-03 14:56:13 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014, Regents of the University of California.
shockjiang85312022014-07-27 23:22:16 -07004 *
shockjiang99ad3892014-08-03 14:56:13 -07005 * This file is part of NDNS (Named Data Networking Domain Name Service).
6 * See AUTHORS.md for complete list of NDNS authors and contributors.
shockjiang85312022014-07-27 23:22:16 -07007 *
shockjiang99ad3892014-08-03 14:56:13 -07008 * 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/>.
shockjiang85312022014-07-27 23:22:16 -070018 */
19
shockjiang85312022014-07-27 23:22:16 -070020#include "app/name-caching-resolver.hpp"
shockjiang99ad3892014-08-03 14:56:13 -070021#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
27using namespace ndn;
28using namespace ndn::ndns;
29using namespace std;
30
shockjiang85312022014-07-27 23:22:16 -070031
32
33int main(int argc, char * argv[])
34{
shockjiang99ad3892014-08-03 14:56:13 -070035 string route="/";
36 int lifetime=2;
37 string hint = "";
38 try{
shockjiang85312022014-07-27 23:22:16 -070039
shockjiang99ad3892014-08-03 14:56:13 -070040 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)
shockjiang85312022014-07-27 23:22:16 -070094 {
shockjiang99ad3892014-08-03 14:56:13 -070095 cout << "Parameter Error: " << ex.what() << endl;
96 return 0;
97 }
98 catch(...)
99 {
100 cout << "Parameter Unknown error" << endl;
101 return 0;
shockjiang85312022014-07-27 23:22:16 -0700102 }
103
shockjiang85312022014-07-27 23:22:16 -0700104
shockjiang85312022014-07-27 23:22:16 -0700105
shockjiang99ad3892014-08-03 14:56:13 -0700106
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
shockjiang85312022014-07-27 23:22:16 -0700126 } else {
shockjiang99ad3892014-08-03 14:56:13 -0700127 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
shockjiang85312022014-07-27 23:22:16 -0700142 }
143
144}
145