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