blob: 5f3c14721b3f4ab27abdb09f7197a772d0ec3ddb [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014 University of Memphis,
4 * Regents of the University of California
5 *
6 * This file is part of NLSR (Named-data Link State Routing).
7 * See AUTHORS.md for complete list of NLSR authors and contributors.
8 *
9 * NLSR is free software: you can redistribute it and/or modify it under the terms
10 * of the GNU General Public License as published by the Free Software Foundation,
11 * either version 3 of the License, or (at your option) any later version.
12 *
13 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * \author A K M Mahmudul Hoque <ahoque1@memphis.edu>
21 * \author Minsheng Zhang <mzhang4@memphis.edu>
22 *
23 **/
akmhoque53353462014-04-22 08:43:45 -050024#include <iostream>
25#include <fstream>
akmhoque157b0a42014-05-13 00:26:37 -050026#include <boost/algorithm/string.hpp>
27#include <boost/property_tree/info_parser.hpp>
28#include <boost/property_tree/ptree.hpp>
akmhoque674b0b12014-05-20 14:33:28 -050029#include <boost/filesystem.hpp>
akmhoque53353462014-04-22 08:43:45 -050030
akmhoque157b0a42014-05-13 00:26:37 -050031#include <ndn-cxx/name.hpp>
32
akmhoque53353462014-04-22 08:43:45 -050033#include "conf-parameter.hpp"
akmhoque157b0a42014-05-13 00:26:37 -050034#include "conf-file-processor.hpp"
akmhoque53353462014-04-22 08:43:45 -050035#include "adjacent.hpp"
akmhoque157b0a42014-05-13 00:26:37 -050036#include "utility/name-helper.hpp"
akmhoque53353462014-04-22 08:43:45 -050037
akmhoque53353462014-04-22 08:43:45 -050038namespace nlsr {
39
40using namespace std;
41
akmhoque157b0a42014-05-13 00:26:37 -050042bool
akmhoqueb6450b12014-04-24 00:01:03 -050043ConfFileProcessor::processConfFile()
akmhoque53353462014-04-22 08:43:45 -050044{
akmhoque157b0a42014-05-13 00:26:37 -050045 bool ret = true;
46 ifstream inputFile;
47 inputFile.open(m_confFileName.c_str());
48 if (!inputFile.is_open()) {
49 string msg = "Failed to read configuration file: ";
50 msg += m_confFileName;
51 cerr << msg << endl;
akmhoquead5fe952014-06-26 13:34:12 -050052 return false;
akmhoque157b0a42014-05-13 00:26:37 -050053 }
54 ret = load(inputFile);
55 inputFile.close();
56 return ret;
57}
58
59bool
60ConfFileProcessor::load(istream& input)
61{
Alexander Afanasyev8388ec62014-08-16 18:38:57 -070062 ConfigSection pt;
akmhoque157b0a42014-05-13 00:26:37 -050063 bool ret = true;
64 try {
65 boost::property_tree::read_info(input, pt);
66 }
67 catch (const boost::property_tree::info_parser_error& error) {
68 stringstream msg;
69 std::cerr << "Failed to parse configuration file " << std::endl;
70 std::cerr << m_confFileName << std::endl;
71 return false;
72 }
Alexander Afanasyev8388ec62014-08-16 18:38:57 -070073
74 for (ConfigSection::const_iterator tn = pt.begin();
akmhoque157b0a42014-05-13 00:26:37 -050075 tn != pt.end(); ++tn) {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -070076 ret = processSection(tn->first, tn->second);
akmhoque157b0a42014-05-13 00:26:37 -050077 if (ret == false) {
78 break;
79 }
80 }
81 return ret;
82}
83
84bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -070085ConfFileProcessor::processSection(const std::string& sectionName, const ConfigSection& section)
akmhoque157b0a42014-05-13 00:26:37 -050086{
87 bool ret = true;
Alexander Afanasyev8388ec62014-08-16 18:38:57 -070088 if (sectionName == "general")
akmhoque53353462014-04-22 08:43:45 -050089 {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -070090 ret = processConfSectionGeneral(section);
akmhoque157b0a42014-05-13 00:26:37 -050091 }
Alexander Afanasyev8388ec62014-08-16 18:38:57 -070092 else if (sectionName == "neighbors")
akmhoque157b0a42014-05-13 00:26:37 -050093 {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -070094 ret = processConfSectionNeighbors(section);
akmhoque157b0a42014-05-13 00:26:37 -050095 }
Alexander Afanasyev8388ec62014-08-16 18:38:57 -070096 else if (sectionName == "hyperbolic")
akmhoque157b0a42014-05-13 00:26:37 -050097 {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -070098 ret = processConfSectionHyperbolic(section);
akmhoque157b0a42014-05-13 00:26:37 -050099 }
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700100 else if (sectionName == "fib")
akmhoque157b0a42014-05-13 00:26:37 -0500101 {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700102 ret = processConfSectionFib(section);
akmhoque157b0a42014-05-13 00:26:37 -0500103 }
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700104 else if (sectionName == "advertising")
akmhoque157b0a42014-05-13 00:26:37 -0500105 {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700106 ret = processConfSectionAdvertising(section);
akmhoque157b0a42014-05-13 00:26:37 -0500107 }
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700108 else if (sectionName == "security")
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700109 {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700110 ret = processConfSectionSecurity(section);
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700111 }
akmhoque157b0a42014-05-13 00:26:37 -0500112 else
113 {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700114 std::cerr << "Wrong configuration section: " << sectionName << std::endl;
akmhoque157b0a42014-05-13 00:26:37 -0500115 }
116 return ret;
117}
118
119bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700120ConfFileProcessor::processConfSectionGeneral(const ConfigSection& section)
akmhoque157b0a42014-05-13 00:26:37 -0500121{
122 try {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700123 std::string network = section.get<string>("network");
124 std::string site = section.get<string>("site");
125 std::string router = section.get<string>("router");
akmhoque157b0a42014-05-13 00:26:37 -0500126 ndn::Name networkName(network);
127 if (!networkName.empty()) {
128 m_nlsr.getConfParameter().setNetwork(networkName);
129 }
130 else {
131 cerr << " Network can not be null or empty or in bad URI format :(!" << endl;
132 return false;
133 }
134 ndn::Name siteName(site);
135 if (!siteName.empty()) {
136 m_nlsr.getConfParameter().setSiteName(siteName);
137 }
138 else {
139 cerr << "Site can not be null or empty or in bad URI format:( !" << endl;
140 return false;
141 }
142 ndn::Name routerName(router);
143 if (!routerName.empty()) {
144 m_nlsr.getConfParameter().setRouterName(routerName);
145 }
146 else {
147 cerr << " Router name can not be null or empty or in bad URI format:( !" << endl;
148 return false;
149 }
150 }
151 catch (const std::exception& ex) {
152 cerr << ex.what() << endl;
153 return false;
154 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700155
akmhoque157b0a42014-05-13 00:26:37 -0500156 try {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700157 int32_t lsaRefreshTime = section.get<int32_t>("lsa-refresh-time");
akmhoque157b0a42014-05-13 00:26:37 -0500158 if (lsaRefreshTime >= LSA_REFRESH_TIME_MIN &&
159 lsaRefreshTime <= LSA_REFRESH_TIME_MAX) {
160 m_nlsr.getConfParameter().setLsaRefreshTime(lsaRefreshTime);
161 }
162 else {
163 std::cerr << "Wrong value for lsa-refresh-time ";
164 std::cerr << "Allowed value: " << LSA_REFRESH_TIME_MIN << "-";;
165 std::cerr << LSA_REFRESH_TIME_MAX << std::endl;
166 return false;
167 }
168 }
169 catch (const std::exception& ex) {
170 std::cerr << ex.what() << std::endl;
171 return false;
172 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700173
akmhoque157b0a42014-05-13 00:26:37 -0500174 try {
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700175 int lifetime = section.get<int>("lsa-interest-lifetime");
176 if (lifetime >= LSA_INTEREST_LIFETIME_MIN && lifetime <= LSA_INTEREST_LIFETIME_MAX) {
177 m_nlsr.getConfParameter().setLsaInterestLifetime(ndn::time::seconds(lifetime));
178 }
179 else {
180 std::cerr << "Wrong value for lsa-interest-timeout. "
181 << "Allowed value:" << LSA_INTEREST_LIFETIME_MIN << "-"
182 << LSA_INTEREST_LIFETIME_MAX << std::endl;
183 return false;
184 }
185 }
186 catch (const std::exception& ex) {
187 std::cerr << ex.what() << std::endl;
188 // return false;
189 }
190
191 try {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700192 std::string logLevel = section.get<string>("log-level");
akmhoque157b0a42014-05-13 00:26:37 -0500193 if ( boost::iequals(logLevel, "info") || boost::iequals(logLevel, "debug")) {
194 m_nlsr.getConfParameter().setLogLevel(logLevel);
195 }
196 else {
197 std::cerr << "Wrong value for log-level ";
198 std::cerr << "Allowed value: INFO, DEBUG" << std::endl;
199 return false;
200 }
201 }
202 catch (const std::exception& ex) {
203 std::cerr << ex.what() << std::endl;
204 return false;
205 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700206
akmhoque674b0b12014-05-20 14:33:28 -0500207 try {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700208 std::string logDir = section.get<string>("log-dir");
akmhoque674b0b12014-05-20 14:33:28 -0500209 if (boost::filesystem::exists(logDir)) {
210 if (boost::filesystem::is_directory(logDir)) {
211 std::string testFileName=logDir+"/test.log";
212 ofstream testOutFile;
213 testOutFile.open(testFileName.c_str());
214 if (testOutFile.is_open() && testOutFile.good()) {
215 m_nlsr.getConfParameter().setLogDir(logDir);
216 }
217 else {
218 std::cerr << "User does not have read and write permission on the directory";
219 std::cerr << std::endl;
220 return false;
221 }
222 testOutFile.close();
223 remove(testFileName.c_str());
224 }
225 else {
226 std::cerr << "Provided path is not a directory" << std::endl;
227 return false;
228 }
229 }
230 else {
231 std::cerr << "Log directory provided does not exists" << std::endl;
232 return false;
233 }
234 }
235 catch (const std::exception& ex) {
236 std::cerr << "You must configure log directory" << std::endl;
237 std::cerr << ex.what() << std::endl;
238 return false;
239 }
240 try {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700241 std::string seqDir = section.get<string>("seq-dir");
akmhoque674b0b12014-05-20 14:33:28 -0500242 if (boost::filesystem::exists(seqDir)) {
243 if (boost::filesystem::is_directory(seqDir)) {
244 std::string testFileName=seqDir+"/test.seq";
245 ofstream testOutFile;
246 testOutFile.open(testFileName.c_str());
247 if (testOutFile.is_open() && testOutFile.good()) {
248 m_nlsr.getConfParameter().setSeqFileDir(seqDir);
249 }
250 else {
251 std::cerr << "User does not have read and write permission on the directory";
252 std::cerr << std::endl;
253 return false;
254 }
255 testOutFile.close();
256 remove(testFileName.c_str());
257 }
258 else {
259 std::cerr << "Provided path is not a directory" << std::endl;
260 return false;
261 }
262 }
263 else {
264 std::cerr << "Seq directory provided does not exists" << std::endl;
265 return false;
266 }
267 }
268 catch (const std::exception& ex) {
269 std::cerr << "You must configure sequence directory" << std::endl;
270 std::cerr << ex.what() << std::endl;
271 return false;
272 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700273
akmhoque157b0a42014-05-13 00:26:37 -0500274 return true;
275}
276
277bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700278ConfFileProcessor::processConfSectionNeighbors(const ConfigSection& section)
akmhoque157b0a42014-05-13 00:26:37 -0500279{
280 try {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700281 int retrials = section.get<int>("hello-retries");
akmhoque157b0a42014-05-13 00:26:37 -0500282 if (retrials >= HELLO_RETRIES_MIN && retrials <= HELLO_RETRIES_MAX) {
283 m_nlsr.getConfParameter().setInterestRetryNumber(retrials);
284 }
285 else {
286 std::cerr << "Wrong value for hello-retries. ";
287 std::cerr << "Allowed value:" << HELLO_RETRIES_MIN << "-";
288 std::cerr << HELLO_RETRIES_MAX << std::endl;
289 return false;
290 }
291 }
292 catch (const std::exception& ex) {
293 std::cerr << ex.what() << std::endl;
294 return false;
295 }
296 try {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700297 int timeOut = section.get<int>("hello-timeout");
akmhoque157b0a42014-05-13 00:26:37 -0500298 if (timeOut >= HELLO_TIMEOUT_MIN && timeOut <= HELLO_TIMEOUT_MAX) {
299 m_nlsr.getConfParameter().setInterestResendTime(timeOut);
300 }
301 else {
302 std::cerr << "Wrong value for hello-timeout. ";
303 std::cerr << "Allowed value:" << HELLO_TIMEOUT_MIN << "-";
304 std::cerr << HELLO_TIMEOUT_MAX << std::endl;
305 return false;
306 }
307 }
308 catch (const std::exception& ex) {
309 std::cerr << ex.what() << std::endl;
310 }
311 try {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700312 int interval = section.get<int>("hello-interval");
akmhoque157b0a42014-05-13 00:26:37 -0500313 if (interval >= HELLO_INTERVAL_MIN && interval <= HELLO_INTERVAL_MAX) {
314 m_nlsr.getConfParameter().setInfoInterestInterval(interval);
315 }
316 else {
317 std::cerr << "Wrong value for hello-interval. ";
318 std::cerr << "Allowed value:" << HELLO_INTERVAL_MIN << "-";
319 std::cerr << HELLO_INTERVAL_MAX << std::endl;
320 return false;
321 }
322 }
323 catch (const std::exception& ex) {
324 std::cerr << ex.what() << std::endl;
325 }
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700326 for (ConfigSection::const_iterator tn =
327 section.begin(); tn != section.end(); ++tn) {
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700328
akmhoque157b0a42014-05-13 00:26:37 -0500329 if (tn->first == "neighbor")
akmhoque53353462014-04-22 08:43:45 -0500330 {
akmhoque157b0a42014-05-13 00:26:37 -0500331 try {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700332 ConfigSection CommandAttriTree = tn->second;
akmhoque157b0a42014-05-13 00:26:37 -0500333 std::string name = CommandAttriTree.get<std::string>("name");
334 std::string faceUri = CommandAttriTree.get<std::string>("face-uri");
335 double linkCost = CommandAttriTree.get<double>("link-cost",
336 Adjacent::DEFAULT_LINK_COST);
337 ndn::Name neighborName(name);
338 if (!neighborName.empty()) {
akmhoquec04e7272014-07-02 11:00:14 -0500339 Adjacent adj(name, faceUri, linkCost, ADJACENT_STATUS_INACTIVE, 0, 0);
akmhoque157b0a42014-05-13 00:26:37 -0500340 m_nlsr.getAdjacencyList().insert(adj);
341 }
342 else {
akmhoque674b0b12014-05-20 14:33:28 -0500343 std::cerr << " Wrong command format ! [name /nbr/name/ \n face-uri /uri\n]";
akmhoque157b0a42014-05-13 00:26:37 -0500344 std::cerr << " or bad URI format" << std::endl;
akmhoque53353462014-04-22 08:43:45 -0500345 }
346 }
akmhoque157b0a42014-05-13 00:26:37 -0500347 catch (const std::exception& ex) {
348 std::cerr << ex.what() << std::endl;
349 return false;
350 }
akmhoque53353462014-04-22 08:43:45 -0500351 }
352 }
akmhoque157b0a42014-05-13 00:26:37 -0500353 return true;
akmhoque53353462014-04-22 08:43:45 -0500354}
355
akmhoque157b0a42014-05-13 00:26:37 -0500356bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700357ConfFileProcessor::processConfSectionHyperbolic(const ConfigSection& section)
akmhoque53353462014-04-22 08:43:45 -0500358{
akmhoque157b0a42014-05-13 00:26:37 -0500359 std::string state;
360 try {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700361 state= section.get<string>("state","off");
akmhoque157b0a42014-05-13 00:26:37 -0500362 if (boost::iequals(state, "off")) {
363 m_nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_OFF);
364 }
365 else if (boost::iequals(state, "on")) {
366 m_nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_ON);
367 }
368 else if (state == "dry-run") {
369 m_nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_DRY_RUN);
370 }
371 else {
372 std::cerr << "Wrong format for hyperbolic state." << std::endl;
373 std::cerr << "Allowed value: off, on, dry-run" << std::endl;
374 return false;
375 }
akmhoque53353462014-04-22 08:43:45 -0500376 }
akmhoque157b0a42014-05-13 00:26:37 -0500377 catch (const std::exception& ex) {
378 std::cerr << ex.what() << std::endl;
379 return false;
akmhoque53353462014-04-22 08:43:45 -0500380 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700381
akmhoque157b0a42014-05-13 00:26:37 -0500382 try {
383 /* Radius and angle is mandatory configuration parameter in hyperbolic section.
384 * Even if router can have hyperbolic routing calculation off but other router
385 * in the network may use hyperbolic routing calculation for FIB generation.
386 * So each router need to advertise its hyperbolic coordinates in the network
387 */
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700388 double radius = section.get<double>("radius");
389 double angle = section.get<double>("angle");
akmhoque157b0a42014-05-13 00:26:37 -0500390 if (!m_nlsr.getConfParameter().setCorR(radius)) {
391 return false;
392 }
393 m_nlsr.getConfParameter().setCorTheta(angle);
akmhoque53353462014-04-22 08:43:45 -0500394 }
akmhoque157b0a42014-05-13 00:26:37 -0500395 catch (const std::exception& ex) {
396 std::cerr << ex.what() << std::endl;
397 if (state == "on" || state == "dry-run") {
398 return false;
399 }
akmhoque53353462014-04-22 08:43:45 -0500400 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700401
akmhoque157b0a42014-05-13 00:26:37 -0500402 return true;
akmhoque53353462014-04-22 08:43:45 -0500403}
404
akmhoque157b0a42014-05-13 00:26:37 -0500405bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700406ConfFileProcessor::processConfSectionFib(const ConfigSection& section)
akmhoque53353462014-04-22 08:43:45 -0500407{
akmhoque157b0a42014-05-13 00:26:37 -0500408 try {
409 int maxFacesPerPrefixNumber =
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700410 section.get<int>("max-faces-per-prefix");
akmhoque157b0a42014-05-13 00:26:37 -0500411 if (maxFacesPerPrefixNumber >= MAX_FACES_PER_PREFIX_MIN &&
412 maxFacesPerPrefixNumber <= MAX_FACES_PER_PREFIX_MAX)
akmhoque53353462014-04-22 08:43:45 -0500413 {
akmhoque157b0a42014-05-13 00:26:37 -0500414 m_nlsr.getConfParameter().setMaxFacesPerPrefix(maxFacesPerPrefixNumber);
akmhoque53353462014-04-22 08:43:45 -0500415 }
akmhoque157b0a42014-05-13 00:26:37 -0500416 else {
417 std::cerr << "Wrong value for max-faces-per-prefix. ";
akmhoque157b0a42014-05-13 00:26:37 -0500418 std::cerr << MAX_FACES_PER_PREFIX_MIN << std::endl;
419 return false;
akmhoque53353462014-04-22 08:43:45 -0500420 }
akmhoque53353462014-04-22 08:43:45 -0500421 }
akmhoque157b0a42014-05-13 00:26:37 -0500422 catch (const std::exception& ex) {
423 cerr << ex.what() << endl;
424 return false;
425 }
426 return true;
akmhoque53353462014-04-22 08:43:45 -0500427}
428
akmhoque157b0a42014-05-13 00:26:37 -0500429bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700430ConfFileProcessor::processConfSectionAdvertising(const ConfigSection& section)
akmhoque53353462014-04-22 08:43:45 -0500431{
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700432 for (ConfigSection::const_iterator tn =
433 section.begin(); tn != section.end(); ++tn) {
akmhoque157b0a42014-05-13 00:26:37 -0500434 if (tn->first == "prefix") {
435 try {
436 std::string prefix = tn->second.data();
437 ndn::Name namePrefix(prefix);
438 if (!namePrefix.empty()) {
439 m_nlsr.getNamePrefixList().insert(namePrefix);
440 }
441 else {
akmhoque674b0b12014-05-20 14:33:28 -0500442 std::cerr << " Wrong command format ! [prefix /name/prefix] or bad URI" << std::endl;
akmhoque157b0a42014-05-13 00:26:37 -0500443 return false;
444 }
445 }
446 catch (const std::exception& ex) {
447 std::cerr << ex.what() << std::endl;
448 return false;
449 }
akmhoque53353462014-04-22 08:43:45 -0500450 }
akmhoque53353462014-04-22 08:43:45 -0500451 }
akmhoque157b0a42014-05-13 00:26:37 -0500452 return true;
akmhoque53353462014-04-22 08:43:45 -0500453}
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700454
455bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700456ConfFileProcessor::processConfSectionSecurity(const ConfigSection& section)
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700457{
458 ConfigSection::const_iterator it = section.begin();
459
460 if (it == section.end() || it->first != "validator")
461 {
462 std::cerr << "Error: Expect validator section!" << std::endl;
463 return false;
464 }
465
466 m_nlsr.loadValidator(it->second, m_confFileName);
akmhoqued57f3672014-06-10 10:41:32 -0500467 it++;
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700468
469 for (; it != section.end(); it++)
470 {
471 using namespace boost::filesystem;
472 if (it->first != "cert-to-publish")
473 {
474 std::cerr << "Error: Expect cert-to-publish!" << std::endl;
475 return false;
476 }
477
478 std::string file = it->second.data();
479 path certfilePath = absolute(file, path(m_confFileName).parent_path());
480 ndn::shared_ptr<ndn::IdentityCertificate> idCert =
481 ndn::io::load<ndn::IdentityCertificate>(certfilePath.string());
482
483 if (!static_cast<bool>(idCert))
484 {
485 std::cerr << "Error: Cannot load cert-to-publish: " << file << "!" << std::endl;
486 return false;
487 }
488
489 m_nlsr.loadCertToPublish(idCert);
490 }
491
492 return true;
493}
494
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700495} // namespace nlsr