Weiqi Shi | 90d1e88 | 2014-08-01 21:26:21 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Alexander Afanasyev | c0e2658 | 2017-08-13 21:16:49 -0400 | [diff] [blame] | 2 | /* |
Alexander Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, Regents of the University of California. |
Weiqi Shi | 90d1e88 | 2014-08-01 21:26:21 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of NDN repo-ng (Next generation of NDN repository). |
| 6 | * See AUTHORS.md for complete list of repo-ng authors and contributors. |
| 7 | * |
| 8 | * repo-ng 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 | * repo-ng 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 |
Alexander Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 17 | * repo-ng, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Weiqi Shi | 90d1e88 | 2014-08-01 21:26:21 -0700 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include "../src/repo-command-parameter.hpp" |
| 21 | #include "../src/repo-command-response.hpp" |
| 22 | |
| 23 | #include <ndn-cxx/face.hpp> |
Alexander Afanasyev | 2e8147c | 2017-11-09 14:17:02 -0500 | [diff] [blame] | 24 | #include <ndn-cxx/security/command-interest-signer.hpp> |
Weiqi Shi | 90d1e88 | 2014-08-01 21:26:21 -0700 | [diff] [blame] | 25 | #include <ndn-cxx/security/key-chain.hpp> |
Junxiao Shi | 047a6fb | 2017-06-08 16:16:05 +0000 | [diff] [blame] | 26 | #include <ndn-cxx/security/signing-helpers.hpp> |
Weiqi Shi | 90d1e88 | 2014-08-01 21:26:21 -0700 | [diff] [blame] | 27 | #include <ndn-cxx/util/scheduler.hpp> |
Alexander Afanasyev | c0e2658 | 2017-08-13 21:16:49 -0400 | [diff] [blame] | 28 | |
Weiqi Shi | 90d1e88 | 2014-08-01 21:26:21 -0700 | [diff] [blame] | 29 | #include <stdint.h> |
Alexander Afanasyev | c0e2658 | 2017-08-13 21:16:49 -0400 | [diff] [blame] | 30 | #include <stdlib.h> |
| 31 | |
| 32 | #include <fstream> |
| 33 | #include <iostream> |
| 34 | #include <string> |
Weiqi Shi | 90d1e88 | 2014-08-01 21:26:21 -0700 | [diff] [blame] | 35 | |
Eric Newberry | b16edda | 2017-12-23 17:54:47 -0700 | [diff] [blame] | 36 | #include <boost/asio/io_service.hpp> |
Weiqi Shi | 90d1e88 | 2014-08-01 21:26:21 -0700 | [diff] [blame] | 37 | #include <boost/lexical_cast.hpp> |
| 38 | |
| 39 | namespace repo { |
| 40 | |
| 41 | using namespace ndn::time; |
| 42 | |
Wentao Shang | a8f3c40 | 2014-10-30 14:03:27 -0700 | [diff] [blame] | 43 | using std::shared_ptr; |
| 44 | using std::bind; |
| 45 | using std::placeholders::_1; |
| 46 | using std::placeholders::_2; |
| 47 | |
Weiqi Shi | 90d1e88 | 2014-08-01 21:26:21 -0700 | [diff] [blame] | 48 | static const uint64_t DEFAULT_INTEREST_LIFETIME = 4000; |
| 49 | static const uint64_t DEFAULT_FRESHNESS_PERIOD = 10000; |
| 50 | static const uint64_t DEFAULT_CHECK_PERIOD = 1000; |
| 51 | |
| 52 | enum CommandType |
| 53 | { |
| 54 | START, |
| 55 | CHECK, |
| 56 | STOP |
| 57 | }; |
| 58 | |
Alexander Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 59 | class NdnRepoWatch : boost::noncopyable |
Weiqi Shi | 90d1e88 | 2014-08-01 21:26:21 -0700 | [diff] [blame] | 60 | { |
| 61 | public: |
| 62 | class Error : public std::runtime_error |
| 63 | { |
| 64 | public: |
| 65 | explicit |
| 66 | Error(const std::string& what) |
| 67 | : std::runtime_error(what) |
| 68 | { |
| 69 | } |
| 70 | }; |
| 71 | |
| 72 | NdnRepoWatch() |
| 73 | : freshnessPeriod(DEFAULT_FRESHNESS_PERIOD) |
| 74 | , interestLifetime(DEFAULT_INTEREST_LIFETIME) |
| 75 | , hasTimeout(false) |
| 76 | , watchTimeout(0) |
| 77 | , hasMaxInterestNum(false) |
| 78 | , maxInterestNum(0) |
| 79 | , status(START) |
| 80 | , isVerbose(false) |
Weiqi Shi | 90d1e88 | 2014-08-01 21:26:21 -0700 | [diff] [blame] | 81 | , m_scheduler(m_face.getIoService()) |
| 82 | , m_checkPeriod(DEFAULT_CHECK_PERIOD) |
Alexander Afanasyev | 2e8147c | 2017-11-09 14:17:02 -0500 | [diff] [blame] | 83 | , m_cmdSigner(m_keyChain) |
Weiqi Shi | 90d1e88 | 2014-08-01 21:26:21 -0700 | [diff] [blame] | 84 | { |
| 85 | } |
| 86 | |
| 87 | void |
| 88 | run(); |
| 89 | |
| 90 | private: |
| 91 | |
| 92 | void |
| 93 | startWatchCommand(); |
| 94 | |
| 95 | void |
Alexander Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 96 | onWatchCommandResponse(const ndn::Interest& interest, const ndn::Data& data); |
Weiqi Shi | 90d1e88 | 2014-08-01 21:26:21 -0700 | [diff] [blame] | 97 | |
| 98 | void |
| 99 | onWatchCommandTimeout(const ndn::Interest& interest); |
| 100 | |
| 101 | void |
| 102 | stopProcess(); |
| 103 | |
| 104 | void |
| 105 | signData(ndn::Data& data); |
| 106 | |
| 107 | void |
| 108 | startCheckCommand(); |
| 109 | |
| 110 | void |
| 111 | onCheckCommandTimeout(const ndn::Interest& interest); |
| 112 | |
| 113 | void |
| 114 | onStopCommandResponse(const ndn::Interest& interest, ndn::Data& data); |
| 115 | |
| 116 | void |
| 117 | onStopCommandTimeout(const ndn::Interest& interest); |
| 118 | |
| 119 | ndn::Interest |
| 120 | generateCommandInterest(const ndn::Name& commandPrefix, const std::string& command, |
| 121 | const RepoCommandParameter& commandParameter); |
| 122 | |
| 123 | public: |
| 124 | std::string identityForCommand; |
| 125 | milliseconds freshnessPeriod; |
| 126 | milliseconds interestLifetime; |
| 127 | bool hasTimeout; |
| 128 | milliseconds watchTimeout; |
| 129 | bool hasMaxInterestNum; |
| 130 | int64_t maxInterestNum; |
| 131 | CommandType status; |
| 132 | ndn::Name repoPrefix; |
| 133 | ndn::Name ndnName; |
| 134 | bool isVerbose; |
| 135 | |
| 136 | |
| 137 | private: |
| 138 | ndn::Face m_face; |
| 139 | ndn::Scheduler m_scheduler; |
| 140 | milliseconds m_checkPeriod; |
| 141 | |
| 142 | ndn::Name m_dataPrefix; |
| 143 | ndn::KeyChain m_keyChain; |
Wentao Shang | a8f3c40 | 2014-10-30 14:03:27 -0700 | [diff] [blame] | 144 | typedef std::map<uint64_t, shared_ptr<ndn::Data> > DataContainer; |
Alexander Afanasyev | 2e8147c | 2017-11-09 14:17:02 -0500 | [diff] [blame] | 145 | ndn::security::CommandInterestSigner m_cmdSigner; |
Weiqi Shi | 90d1e88 | 2014-08-01 21:26:21 -0700 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | void |
| 149 | NdnRepoWatch::run() |
| 150 | { |
| 151 | m_dataPrefix = ndnName; |
| 152 | startWatchCommand(); |
| 153 | |
| 154 | if (hasTimeout) |
Wentao Shang | a8f3c40 | 2014-10-30 14:03:27 -0700 | [diff] [blame] | 155 | m_scheduler.scheduleEvent(watchTimeout, bind(&NdnRepoWatch::stopProcess, this)); |
Weiqi Shi | 90d1e88 | 2014-08-01 21:26:21 -0700 | [diff] [blame] | 156 | |
| 157 | m_face.processEvents(); |
| 158 | } |
| 159 | |
| 160 | void |
| 161 | NdnRepoWatch::startWatchCommand() |
| 162 | { |
| 163 | RepoCommandParameter parameters; |
| 164 | parameters.setName(m_dataPrefix); |
| 165 | |
| 166 | repoPrefix.append("watch"); |
| 167 | if (status == START) { |
| 168 | if (hasMaxInterestNum) { |
| 169 | parameters.setMaxInterestNum(maxInterestNum); |
| 170 | } |
| 171 | if (hasTimeout) { |
| 172 | parameters.setWatchTimeout(watchTimeout); |
| 173 | } |
| 174 | ndn::Interest commandInterest = generateCommandInterest(repoPrefix, "start", parameters); |
| 175 | m_face.expressInterest(commandInterest, |
Wentao Shang | a8f3c40 | 2014-10-30 14:03:27 -0700 | [diff] [blame] | 176 | bind(&NdnRepoWatch::onWatchCommandResponse, this, |
| 177 | _1, _2), |
Alexander Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 178 | bind(&NdnRepoWatch::onWatchCommandTimeout, this, _1), // Nack |
Wentao Shang | a8f3c40 | 2014-10-30 14:03:27 -0700 | [diff] [blame] | 179 | bind(&NdnRepoWatch::onWatchCommandTimeout, this, _1)); |
Weiqi Shi | 90d1e88 | 2014-08-01 21:26:21 -0700 | [diff] [blame] | 180 | } |
| 181 | else if (status == STOP){ |
| 182 | ndn::Interest commandInterest = generateCommandInterest(repoPrefix, "stop", parameters); |
| 183 | m_face.expressInterest(commandInterest, |
Wentao Shang | a8f3c40 | 2014-10-30 14:03:27 -0700 | [diff] [blame] | 184 | bind(&NdnRepoWatch::onWatchCommandResponse, this, |
| 185 | _1, _2), |
Alexander Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 186 | bind(&NdnRepoWatch::onWatchCommandTimeout, this, _1), // Nack |
Wentao Shang | a8f3c40 | 2014-10-30 14:03:27 -0700 | [diff] [blame] | 187 | bind(&NdnRepoWatch::onWatchCommandTimeout, this, _1)); |
Weiqi Shi | 90d1e88 | 2014-08-01 21:26:21 -0700 | [diff] [blame] | 188 | } |
| 189 | else if (status == CHECK){ |
| 190 | ndn::Interest commandInterest = generateCommandInterest(repoPrefix, "check", parameters); |
| 191 | m_face.expressInterest(commandInterest, |
Wentao Shang | a8f3c40 | 2014-10-30 14:03:27 -0700 | [diff] [blame] | 192 | bind(&NdnRepoWatch::onWatchCommandResponse, this, |
| 193 | _1, _2), |
Alexander Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 194 | bind(&NdnRepoWatch::onWatchCommandTimeout, this, _1), // Nack |
Wentao Shang | a8f3c40 | 2014-10-30 14:03:27 -0700 | [diff] [blame] | 195 | bind(&NdnRepoWatch::onWatchCommandTimeout, this, _1)); |
Weiqi Shi | 90d1e88 | 2014-08-01 21:26:21 -0700 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | } |
| 199 | |
| 200 | void |
Alexander Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 201 | NdnRepoWatch::onWatchCommandResponse(const ndn::Interest& interest, const ndn::Data& data) |
Weiqi Shi | 90d1e88 | 2014-08-01 21:26:21 -0700 | [diff] [blame] | 202 | { |
| 203 | RepoCommandResponse response(data.getContent().blockFromValue()); |
| 204 | int statusCode = response.getStatusCode(); |
| 205 | if (statusCode >= 400) { |
Alexander Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 206 | BOOST_THROW_EXCEPTION(Error("Watch command failed with code " + |
| 207 | boost::lexical_cast<std::string>(statusCode))); |
Weiqi Shi | 90d1e88 | 2014-08-01 21:26:21 -0700 | [diff] [blame] | 208 | } |
| 209 | else if (statusCode == 101) { |
| 210 | std::cerr << "Watching prefix is stopped!" <<std::endl; |
| 211 | m_face.getIoService().stop(); |
| 212 | return; |
| 213 | } |
| 214 | else if (statusCode == 300) { |
| 215 | std::cerr << "Watching prefix is running!" <<std::endl; |
| 216 | m_scheduler.scheduleEvent(m_checkPeriod, |
Wentao Shang | a8f3c40 | 2014-10-30 14:03:27 -0700 | [diff] [blame] | 217 | bind(&NdnRepoWatch::startCheckCommand, this)); |
Weiqi Shi | 90d1e88 | 2014-08-01 21:26:21 -0700 | [diff] [blame] | 218 | return; |
| 219 | } |
| 220 | else if (statusCode == 100) { |
| 221 | std::cerr << "Watching prefix starts!" <<std::endl; |
| 222 | m_scheduler.scheduleEvent(m_checkPeriod, |
Wentao Shang | a8f3c40 | 2014-10-30 14:03:27 -0700 | [diff] [blame] | 223 | bind(&NdnRepoWatch::startCheckCommand, this)); |
Weiqi Shi | 90d1e88 | 2014-08-01 21:26:21 -0700 | [diff] [blame] | 224 | return; |
| 225 | } |
| 226 | else { |
Alexander Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 227 | BOOST_THROW_EXCEPTION(Error("Unrecognized Status Code " + |
| 228 | boost::lexical_cast<std::string>(statusCode))); |
Weiqi Shi | 90d1e88 | 2014-08-01 21:26:21 -0700 | [diff] [blame] | 229 | } |
| 230 | } |
| 231 | |
| 232 | void |
| 233 | NdnRepoWatch::onWatchCommandTimeout(const ndn::Interest& interest) |
| 234 | { |
Alexander Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 235 | BOOST_THROW_EXCEPTION(Error("command response timeout")); |
Weiqi Shi | 90d1e88 | 2014-08-01 21:26:21 -0700 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | void |
| 239 | NdnRepoWatch::stopProcess() |
| 240 | { |
| 241 | m_face.getIoService().stop(); |
| 242 | } |
| 243 | |
| 244 | void |
| 245 | NdnRepoWatch::startCheckCommand() |
| 246 | { |
| 247 | repoPrefix.append("watch"); |
| 248 | ndn::Interest checkInterest = generateCommandInterest(repoPrefix, "check", |
| 249 | RepoCommandParameter() |
| 250 | .setName(m_dataPrefix)); |
| 251 | m_face.expressInterest(checkInterest, |
Wentao Shang | a8f3c40 | 2014-10-30 14:03:27 -0700 | [diff] [blame] | 252 | bind(&NdnRepoWatch::onWatchCommandResponse, this, _1, _2), |
Alexander Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 253 | bind(&NdnRepoWatch::onCheckCommandTimeout, this, _1), // Nack |
Wentao Shang | a8f3c40 | 2014-10-30 14:03:27 -0700 | [diff] [blame] | 254 | bind(&NdnRepoWatch::onCheckCommandTimeout, this, _1)); |
Weiqi Shi | 90d1e88 | 2014-08-01 21:26:21 -0700 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | void |
| 258 | NdnRepoWatch::onCheckCommandTimeout(const ndn::Interest& interest) |
| 259 | { |
Alexander Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 260 | BOOST_THROW_EXCEPTION(Error("check response timeout")); |
Weiqi Shi | 90d1e88 | 2014-08-01 21:26:21 -0700 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | void |
| 264 | NdnRepoWatch::onStopCommandResponse(const ndn::Interest& interest, ndn::Data& data) |
| 265 | { |
| 266 | RepoCommandResponse response(data.getContent().blockFromValue()); |
| 267 | int statusCode = response.getStatusCode(); |
| 268 | if (statusCode != 101) { |
Alexander Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 269 | BOOST_THROW_EXCEPTION(Error("Watch stop command failed with code: " + |
| 270 | boost::lexical_cast<std::string>(statusCode))); |
Weiqi Shi | 90d1e88 | 2014-08-01 21:26:21 -0700 | [diff] [blame] | 271 | } |
| 272 | else { |
| 273 | std::cerr << "Status code is 101. Watching prefix is stopped successfully!" << std::endl; |
| 274 | m_face.getIoService().stop(); |
| 275 | return; |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | void |
| 280 | NdnRepoWatch::onStopCommandTimeout(const ndn::Interest& interest) |
| 281 | { |
Alexander Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 282 | BOOST_THROW_EXCEPTION(Error("stop response timeout")); |
Weiqi Shi | 90d1e88 | 2014-08-01 21:26:21 -0700 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | ndn::Interest |
| 286 | NdnRepoWatch::generateCommandInterest(const ndn::Name& commandPrefix, const std::string& command, |
| 287 | const RepoCommandParameter& commandParameter) |
| 288 | { |
Alexander Afanasyev | 2e8147c | 2017-11-09 14:17:02 -0500 | [diff] [blame] | 289 | Name cmd = commandPrefix; |
| 290 | cmd |
| 291 | .append(command) |
| 292 | .append(commandParameter.wireEncode()); |
| 293 | ndn::Interest interest; |
Weiqi Shi | 90d1e88 | 2014-08-01 21:26:21 -0700 | [diff] [blame] | 294 | |
| 295 | if (identityForCommand.empty()) |
Alexander Afanasyev | 2e8147c | 2017-11-09 14:17:02 -0500 | [diff] [blame] | 296 | interest = m_cmdSigner.makeCommandInterest(cmd); |
Weiqi Shi | 90d1e88 | 2014-08-01 21:26:21 -0700 | [diff] [blame] | 297 | else { |
Alexander Afanasyev | 2e8147c | 2017-11-09 14:17:02 -0500 | [diff] [blame] | 298 | interest = m_cmdSigner.makeCommandInterest(cmd, ndn::signingByIdentity(identityForCommand)); |
Weiqi Shi | 90d1e88 | 2014-08-01 21:26:21 -0700 | [diff] [blame] | 299 | } |
| 300 | |
Alexander Afanasyev | 2e8147c | 2017-11-09 14:17:02 -0500 | [diff] [blame] | 301 | interest.setInterestLifetime(interestLifetime); |
Weiqi Shi | 90d1e88 | 2014-08-01 21:26:21 -0700 | [diff] [blame] | 302 | return interest; |
| 303 | } |
| 304 | |
| 305 | static void |
| 306 | usage() |
| 307 | { |
| 308 | fprintf(stderr, |
| 309 | "NdnRepoWatch [-I identity]" |
| 310 | " [-x freshness] [-l lifetime] [-w watchtimeout]" |
| 311 | " [-n maxinterestnum][-s stop] [-c check]repo-prefix ndn-name\n" |
| 312 | "\n" |
| 313 | " Write a file into a repo.\n" |
| 314 | " -I: specify identity used for signing commands\n" |
| 315 | " -x: FreshnessPeriod in milliseconds\n" |
| 316 | " -l: InterestLifetime in milliseconds for each command\n" |
| 317 | " -w: timeout in milliseconds for whole process (default unlimited)\n" |
| 318 | " -n: total number of interests to be sent for whole process (default unlimited)\n" |
| 319 | " -s: stop the whole process\n" |
| 320 | " -c: check the process\n" |
| 321 | " repo-prefix: repo command prefix\n" |
| 322 | " ndn-name: NDN Name prefix for written Data\n" |
| 323 | ); |
| 324 | exit(1); |
| 325 | } |
| 326 | |
| 327 | int |
| 328 | main(int argc, char** argv) |
| 329 | { |
| 330 | NdnRepoWatch app; |
| 331 | int opt; |
| 332 | while ((opt = getopt(argc, argv, "x:l:w:n:scI:")) != -1) { |
| 333 | switch (opt) { |
| 334 | case 'x': |
| 335 | try { |
| 336 | app.freshnessPeriod = milliseconds(boost::lexical_cast<uint64_t>(optarg)); |
| 337 | } |
Alexander Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 338 | catch (const boost::bad_lexical_cast&) { |
Weiqi Shi | 90d1e88 | 2014-08-01 21:26:21 -0700 | [diff] [blame] | 339 | std::cerr << "-x option should be an integer."; |
| 340 | return 1; |
| 341 | } |
| 342 | break; |
| 343 | case 'l': |
| 344 | try { |
| 345 | app.interestLifetime = milliseconds(boost::lexical_cast<uint64_t>(optarg)); |
| 346 | } |
Alexander Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 347 | catch (const boost::bad_lexical_cast&) { |
Weiqi Shi | 90d1e88 | 2014-08-01 21:26:21 -0700 | [diff] [blame] | 348 | std::cerr << "-l option should be an integer."; |
| 349 | return 1; |
| 350 | } |
| 351 | break; |
| 352 | case 'w': |
| 353 | app.hasTimeout = true; |
| 354 | try { |
| 355 | app.watchTimeout = milliseconds(boost::lexical_cast<int64_t>(optarg)); |
| 356 | } |
Alexander Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 357 | catch (const boost::bad_lexical_cast&) { |
Weiqi Shi | 90d1e88 | 2014-08-01 21:26:21 -0700 | [diff] [blame] | 358 | std::cerr << "-w option should be an integer."; |
| 359 | return 1; |
| 360 | } |
| 361 | break; |
| 362 | case 'n': |
| 363 | app.hasMaxInterestNum = true; |
| 364 | try { |
| 365 | app.maxInterestNum = boost::lexical_cast<int64_t>(optarg); |
| 366 | } |
Alexander Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 367 | catch (const boost::bad_lexical_cast&) { |
Weiqi Shi | 90d1e88 | 2014-08-01 21:26:21 -0700 | [diff] [blame] | 368 | std::cerr << "-n option should be an integer."; |
| 369 | return 1; |
| 370 | } |
| 371 | break; |
| 372 | case 's': |
| 373 | app.status = STOP; |
| 374 | break; |
| 375 | case 'c': |
| 376 | app.status = CHECK; |
| 377 | break; |
| 378 | case 'I': |
| 379 | app.identityForCommand = std::string(optarg); |
| 380 | break; |
| 381 | case 'v': |
| 382 | app.isVerbose = true; |
| 383 | break; |
| 384 | case 'h': |
| 385 | usage(); |
| 386 | break; |
| 387 | default: |
| 388 | break; |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | argc -= optind; |
| 393 | argv += optind; |
| 394 | |
| 395 | if (argc != 2) |
| 396 | usage(); |
| 397 | |
| 398 | app.repoPrefix = Name(argv[0]); |
| 399 | app.ndnName = Name(argv[1]); |
| 400 | |
| 401 | app.run(); |
| 402 | |
| 403 | return 0; |
| 404 | } |
| 405 | |
| 406 | } // namespace repo |
| 407 | |
| 408 | int |
| 409 | main(int argc, char** argv) |
| 410 | { |
| 411 | try { |
| 412 | return repo::main(argc, argv); |
| 413 | } |
Alexander Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 414 | catch (const std::exception& e) { |
Weiqi Shi | 90d1e88 | 2014-08-01 21:26:21 -0700 | [diff] [blame] | 415 | std::cerr << "ERROR: " << e.what() << std::endl; |
| 416 | return 2; |
| 417 | } |
| 418 | } |