blob: 202cd83330d11a64b0b52cb33d7c60f0c5eda3a3 [file] [log] [blame]
Andrea Tosatto672b9a72016-01-05 16:18:20 +01001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2016, Regents of the University of California,
4 * Colorado State University,
5 * University Pierre & Marie Curie, Sorbonne University.
6 *
7 * This file is part of ndn-tools (Named Data Networking Essential Tools).
8 * See AUTHORS.md for complete list of ndn-tools authors and contributors.
9 *
10 * ndn-tools is free software: you can redistribute it and/or modify it under the terms
11 * of the GNU General Public License as published by the Free Software Foundation,
12 * either version 3 of the License, or (at your option) any later version.
13 *
14 * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 * PURPOSE. See the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
20 *
21 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
22 *
23 * @author Wentao Shang
24 * @author Steve DiBenedetto
25 * @author Andrea Tosatto
26 */
27
28#include "core/version.hpp"
29#include "producer.hpp"
30
31namespace ndn {
32namespace chunks {
33
34static int
35main(int argc, char** argv)
36{
37 std::string programName = argv[0];
38 uint64_t freshnessPeriod = 10000;
39 bool printVersion = false;
40 size_t maxChunkSize = MAX_NDN_PACKET_SIZE >> 1;
41 std::string signingStr;
42 bool isVerbose = false;
43 std::string prefix;
44
45 namespace po = boost::program_options;
46 po::options_description visibleDesc("Options");
47 visibleDesc.add_options()
48 ("help,h", "print this help message and exit")
49 ("freshness,f", po::value<uint64_t>(&freshnessPeriod)->default_value(freshnessPeriod),
50 "specify FreshnessPeriod, in milliseconds")
51 ("print-data-version,p", po::bool_switch(&printVersion), "print Data version to the standard output")
52 ("size,s", po::value<size_t>(&maxChunkSize)->default_value(maxChunkSize),
53 "maximum chunk size, in bytes")
54 ("signing-info,S", po::value<std::string>(&signingStr)->default_value(signingStr),
55 "set signing information")
56 ("verbose,v", po::bool_switch(&isVerbose), "turn on verbose output")
57 ("version,V", "print program version and exit")
58 ;
59
60 po::options_description hiddenDesc("Hidden options");
61 hiddenDesc.add_options()
62 ("ndn-name,n", po::value<std::string>(&prefix), "NDN name for the served content");
63
64 po::positional_options_description p;
65 p.add("ndn-name", -1);
66
67 po::options_description optDesc("Allowed options");
68 optDesc.add(visibleDesc).add(hiddenDesc);
69
70 po::variables_map vm;
71 try {
72 po::store(po::command_line_parser(argc, argv).options(optDesc).positional(p).run(), vm);
73 po::notify(vm);
74 }
75 catch (const po::error& e) {
76 std::cerr << "ERROR: " << e.what() << std::endl;
77 return 2;
78 }
79 catch (const boost::bad_any_cast& e) {
80 std::cerr << "ERROR: " << e.what() << std::endl;
81 return 2;
82 }
83
84 if (vm.count("help") > 0) {
85 std::cout << "Usage: " << programName << " [options] ndn:/name" << std::endl;
86 std::cout << visibleDesc;
87 return 0;
88 }
89
90 if (vm.count("version") > 0) {
91 std::cout << "ndnputchunks " << tools::VERSION << std::endl;
92 return 0;
93 }
94
95 if (prefix.empty()) {
96 std::cerr << "Usage: " << programName << " [options] ndn:/name" << std::endl;
97 std::cerr << visibleDesc;
98 return 2;
99 }
100
101 if (maxChunkSize < 1 || maxChunkSize > MAX_NDN_PACKET_SIZE) {
102 std::cerr << "ERROR: Maximum chunk size must be between 1 and " << MAX_NDN_PACKET_SIZE << std::endl;
103 return 2;
104 }
105
106 security::SigningInfo signingInfo;
107 try {
108 signingInfo = security::SigningInfo(signingStr);
109 }
110 catch (const std::invalid_argument& e) {
111 std::cerr << "ERROR: " << e.what() << std::endl;
112 return 2;
113 }
114
115 try {
116 Face face;
117 KeyChain keyChain;
118 Producer producer(prefix, face, keyChain, signingInfo, time::milliseconds(freshnessPeriod),
119 maxChunkSize, isVerbose, printVersion, std::cin);
120 producer.run();
121 }
122 catch (const std::exception& e) {
123 std::cerr << "ERROR: " << e.what() << std::endl;
124 return 1;
125 }
126
127 return 0;
128}
129
130} // namespace chunks
131} // namespace ndn
132
133int
134main(int argc, char** argv)
135{
136 return ndn::chunks::main(argc, argv);
137}