chunks: add --naming-convention option
Refs: #5109 Change-Id: I98170dd362663900900e9f792ffb5340ad96fe3a
This commit is contained in:
1 parent
a420e97fed
commit
f8a14d88cb
5 files changed
+167
-111
No files matched your search
+30
-17
@@ -4,16 +4,18 @@ ndnputchunks
|
||||
Synopsis
|
||||
--------
|
||||
|
||||
**ndnputchunks** [options] *name*
|
||||
**ndnputchunks** [*option*]... *name*
|
||||
|
||||
Description
|
||||
-----------
|
||||
|
||||
:program:`ndnputchunks` is a producer program that reads a file from the standard input, and makes it available as NDN Data segments.
|
||||
:program:`ndnputchunks` is a producer program that reads a file from the standard input
|
||||
and makes it available as NDN Data segments.
|
||||
|
||||
It appends version and segment number components to the specified name, according to the `NDN naming conventions`_.
|
||||
Version and segment number components are appended to the specified *name* as needed,
|
||||
according to the `NDN naming conventions`_.
|
||||
|
||||
.. _NDN naming conventions: http://named-data.net/publications/techreports/ndn-tr-22-ndn-memo-naming-conventions/
|
||||
.. _NDN naming conventions: https://named-data.net/publications/techreports/ndn-tr-22-2-ndn-memo-naming-conventions/
|
||||
|
||||
Options
|
||||
-------
|
||||
@@ -26,19 +28,24 @@ Options
|
||||
|
||||
FreshnessPeriod of the published Data packets, in milliseconds. Default = 10000 [ms].
|
||||
|
||||
.. option:: -p, --print-data-version
|
||||
|
||||
Print version of the published Data to the standard output.
|
||||
|
||||
.. option:: -s, --size BYTES
|
||||
|
||||
Maximum chunk size, in bytes. Default = 4400 [bytes].
|
||||
|
||||
.. option:: -N, --naming-convention CONVENTION
|
||||
|
||||
Select the convention used to encode NDN name components. The available choices are:
|
||||
|
||||
* ``marker`` (shorthand: ``m`` or ``1``) for the old marker-based encoding;
|
||||
* ``typed`` (shorthand: ``t`` or ``2``) for the new encoding based on typed name components.
|
||||
|
||||
If this option is not specified, the ndn-cxx library's default is used.
|
||||
|
||||
.. option:: -S, --signing-info STRING
|
||||
|
||||
Specify the parameters used to sign the Data packet. If omitted, the default key of
|
||||
the default identity is used. The general syntax is ``<scheme>:<name>``. The most
|
||||
common supported combinations are as follows:
|
||||
Specify the parameters used to sign the Data packets. If omitted, the default key
|
||||
of the default identity is used. The general syntax is ``<scheme>:<name>``. The
|
||||
most common supported combinations are as follows:
|
||||
|
||||
* Sign with the default certificate of the default key of an identity: ``id:/<my-identity>``.
|
||||
* Sign with the default certificate of a specific key: ``key:/<my-identity>/ksk-1``.
|
||||
@@ -47,6 +54,10 @@ Options
|
||||
is only a hash function, not a real signature, but it can significantly speed up
|
||||
packet signing operations.
|
||||
|
||||
.. option:: -p, --print-data-version
|
||||
|
||||
Print version of the published Data to the standard output.
|
||||
|
||||
.. option:: -q, --quiet
|
||||
|
||||
Turn off all non-error output.
|
||||
@@ -62,7 +73,7 @@ Options
|
||||
Examples
|
||||
--------
|
||||
|
||||
The following command will publish the text of the GPL-3 license under the `/localhost/demo/gpl3`
|
||||
The following command will publish the text of the GPL-3 license under the ``/localhost/demo/gpl3``
|
||||
prefix::
|
||||
|
||||
ndnputchunks /localhost/demo/gpl3 < /usr/share/common-licenses/GPL-3
|
||||
@@ -75,10 +86,12 @@ This command will print the published version to the standard output.
|
||||
|
||||
To publish Data with a specific version, you must append a version component to the end of the
|
||||
prefix. The version component must follow the aforementioned NDN naming conventions.
|
||||
For example, the following command will publish the version `%FD%00%00%01Qc%CF%17v` of the
|
||||
`/localhost/demo/gpl3` prefix::
|
||||
For example, the following command will publish version 1615519151142 of ``/localhost/demo/gpl3``
|
||||
using the "typed" naming convention::
|
||||
|
||||
ndnputchunks /localhost/demo/gpl3/%FD%00%00%01Qc%CF%17v < /usr/share/common-licenses/GPL-3
|
||||
ndnputchunks -Nt /localhost/demo/gpl3/v=1615519151142 < /usr/share/common-licenses/GPL-3
|
||||
|
||||
If the version component is not valid, a new well-formed version will be generated and appended
|
||||
to the supplied NDN name.
|
||||
See Also
|
||||
--------
|
||||
|
||||
.. target-notes::
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2016-2020, Regents of the University of California,
|
||||
* Copyright (c) 2016-2021, Regents of the University of California,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University.
|
||||
*
|
||||
@@ -33,7 +33,6 @@ namespace chunks {
|
||||
Consumer::Consumer(security::Validator& validator, std::ostream& os)
|
||||
: m_validator(validator)
|
||||
, m_outputStream(os)
|
||||
, m_nextToPrint(0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -47,8 +46,8 @@ Consumer::run(unique_ptr<DiscoverVersion> discover, unique_ptr<PipelineInterests
|
||||
|
||||
m_discover->onDiscoverySuccess.connect([this] (const Name& versionedName) {
|
||||
m_pipeline->run(versionedName,
|
||||
[this] (const Data& data) { handleData(data); },
|
||||
[] (const std::string& msg) { NDN_THROW(std::runtime_error(msg)); });
|
||||
[this] (const Data& data) { handleData(data); },
|
||||
[] (const std::string& msg) { NDN_THROW(std::runtime_error(msg)); });
|
||||
});
|
||||
m_discover->onDiscoveryFailure.connect([] (const std::string& msg) {
|
||||
NDN_THROW(std::runtime_error(msg));
|
||||
|
||||
@@ -94,7 +94,7 @@ private:
|
||||
std::ostream& m_outputStream;
|
||||
unique_ptr<DiscoverVersion> m_discover;
|
||||
unique_ptr<PipelineInterests> m_pipeline;
|
||||
uint64_t m_nextToPrint;
|
||||
uint64_t m_nextToPrint = 0;
|
||||
|
||||
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
|
||||
std::map<uint64_t, shared_ptr<const Data>> m_bufferedData;
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
|
||||
#include <fstream>
|
||||
#include <ndn-cxx/security/validator-null.hpp>
|
||||
#include <ndn-cxx/util/rtt-estimator.hpp>
|
||||
|
||||
#include <boost/program_options/options_description.hpp>
|
||||
#include <boost/program_options/parsers.hpp>
|
||||
@@ -47,31 +48,34 @@
|
||||
namespace ndn {
|
||||
namespace chunks {
|
||||
|
||||
namespace po = boost::program_options;
|
||||
|
||||
static int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
std::string programName(argv[0]);
|
||||
const std::string programName(argv[0]);
|
||||
|
||||
Options options;
|
||||
std::string uri, pipelineType("cubic"), cwndPath, rttPath;
|
||||
time::milliseconds::rep minRto(200), maxRto(60000);
|
||||
double rtoAlpha(0.125), rtoBeta(0.25);
|
||||
int rtoK(8);
|
||||
std::string prefix, nameConv, pipelineType("cubic");
|
||||
std::string cwndPath, rttPath;
|
||||
auto rttEstOptions = make_shared<util::RttEstimator::Options>();
|
||||
rttEstOptions->k = 8; // increased from the ndn-cxx default of 4
|
||||
|
||||
namespace po = boost::program_options;
|
||||
po::options_description basicDesc("Basic Options");
|
||||
basicDesc.add_options()
|
||||
("help,h", "print this help message and exit")
|
||||
("pipeline-type,p", po::value<std::string>(&pipelineType)->default_value(pipelineType),
|
||||
"type of Interest pipeline to use; valid values are: 'fixed', 'aimd', 'cubic'")
|
||||
("fresh,f", po::bool_switch(&options.mustBeFresh),
|
||||
"only return fresh content (set MustBeFresh on all outgoing Interests)")
|
||||
("lifetime,l", po::value<time::milliseconds::rep>()->default_value(options.interestLifetime.count()),
|
||||
"lifetime of expressed Interests, in milliseconds")
|
||||
("retries,r", po::value<int>(&options.maxRetriesOnTimeoutOrNack)->default_value(options.maxRetriesOnTimeoutOrNack),
|
||||
"maximum number of retries in case of Nack or timeout (-1 = no limit)")
|
||||
("pipeline-type,p", po::value<std::string>(&pipelineType)->default_value(pipelineType),
|
||||
"type of Interest pipeline to use; valid values are: 'fixed', 'aimd', 'cubic'")
|
||||
("no-version-discovery,D", po::bool_switch(&options.disableVersionDiscovery),
|
||||
"skip version discovery, even if the supplied name does not end with a version component")
|
||||
"skip version discovery even if the name does not end with a version component")
|
||||
("naming-convention,N", po::value<std::string>(&nameConv),
|
||||
"encoding convention to use for name components, either 'marker' or 'typed'")
|
||||
("quiet,q", po::bool_switch(&options.isQuiet), "suppress all diagnostic output, except fatal errors")
|
||||
("verbose,v", po::bool_switch(&options.isVerbose), "turn on verbose output (per segment information")
|
||||
("version,V", "print program version and exit")
|
||||
@@ -85,36 +89,42 @@ main(int argc, char* argv[])
|
||||
|
||||
po::options_description adaptivePipeDesc("Adaptive pipeline options (AIMD & CUBIC)");
|
||||
adaptivePipeDesc.add_options()
|
||||
("ignore-marks", po::bool_switch(&options.ignoreCongMarks),
|
||||
"do not reduce the window after receiving a congestion mark")
|
||||
("disable-cwa", po::bool_switch(&options.disableCwa),
|
||||
"disable Conservative Window Adaptation, i.e., reduce the window on "
|
||||
"each timeout or congestion mark instead of at most once per RTT")
|
||||
("reset-cwnd-to-init", po::bool_switch(&options.resetCwndToInit),
|
||||
"after a timeout or congestion mark, reset the window "
|
||||
"to the initial value instead of resetting to ssthresh")
|
||||
("ignore-marks", po::bool_switch(&options.ignoreCongMarks),
|
||||
"do not reduce the window after receiving a congestion mark")
|
||||
("disable-cwa", po::bool_switch(&options.disableCwa),
|
||||
"disable Conservative Window Adaptation (reduce the window "
|
||||
"on each congestion event instead of at most once per RTT)")
|
||||
("init-cwnd", po::value<double>(&options.initCwnd)->default_value(options.initCwnd),
|
||||
"initial congestion window in segments")
|
||||
("init-ssthresh", po::value<double>(&options.initSsthresh),
|
||||
"initial slow start threshold in segments (defaults to infinity)")
|
||||
("aimd-step", po::value<double>(&options.aiStep)->default_value(options.aiStep),
|
||||
"additive-increase step")
|
||||
("aimd-beta", po::value<double>(&options.mdCoef)->default_value(options.mdCoef),
|
||||
"multiplicative decrease factor (AIMD)")
|
||||
("rto-alpha", po::value<double>(&rtoAlpha)->default_value(rtoAlpha),
|
||||
("rto-alpha", po::value<double>(&rttEstOptions->alpha)->default_value(rttEstOptions->alpha),
|
||||
"alpha value for RTO calculation")
|
||||
("rto-beta", po::value<double>(&rtoBeta)->default_value(rtoBeta),
|
||||
("rto-beta", po::value<double>(&rttEstOptions->beta)->default_value(rttEstOptions->beta),
|
||||
"beta value for RTO calculation")
|
||||
("rto-k", po::value<int>(&rtoK)->default_value(rtoK),
|
||||
("rto-k", po::value<int>(&rttEstOptions->k)->default_value(rttEstOptions->k),
|
||||
"k value for RTO calculation")
|
||||
("min-rto", po::value<time::milliseconds::rep>(&minRto)->default_value(minRto),
|
||||
("min-rto", po::value<time::milliseconds::rep>()->default_value(
|
||||
time::duration_cast<time::milliseconds>(rttEstOptions->minRto).count()),
|
||||
"minimum RTO value, in milliseconds")
|
||||
("max-rto", po::value<time::milliseconds::rep>(&maxRto)->default_value(maxRto),
|
||||
("max-rto", po::value<time::milliseconds::rep>()->default_value(
|
||||
time::duration_cast<time::milliseconds>(rttEstOptions->maxRto).count()),
|
||||
"maximum RTO value, in milliseconds")
|
||||
("log-cwnd", po::value<std::string>(&cwndPath), "log file for congestion window stats")
|
||||
("log-rtt", po::value<std::string>(&rttPath), "log file for round-trip time stats")
|
||||
;
|
||||
|
||||
po::options_description aimdPipeDesc("AIMD pipeline options");
|
||||
aimdPipeDesc.add_options()
|
||||
("aimd-step", po::value<double>(&options.aiStep)->default_value(options.aiStep),
|
||||
"additive increase step")
|
||||
("aimd-beta", po::value<double>(&options.mdCoef)->default_value(options.mdCoef),
|
||||
"multiplicative decrease factor")
|
||||
("reset-cwnd-to-init", po::bool_switch(&options.resetCwndToInit),
|
||||
"after a congestion event, reset the window to the "
|
||||
"initial value instead of resetting to ssthresh")
|
||||
;
|
||||
|
||||
po::options_description cubicPipeDesc("CUBIC pipeline options");
|
||||
cubicPipeDesc.add_options()
|
||||
("cubic-beta", po::value<double>(&options.cubicBeta), "window decrease factor (defaults to 0.7)")
|
||||
@@ -125,17 +135,18 @@ main(int argc, char* argv[])
|
||||
visibleDesc.add(basicDesc)
|
||||
.add(fixedPipeDesc)
|
||||
.add(adaptivePipeDesc)
|
||||
.add(aimdPipeDesc)
|
||||
.add(cubicPipeDesc);
|
||||
|
||||
po::options_description hiddenDesc;
|
||||
hiddenDesc.add_options()
|
||||
("ndn-name,n", po::value<std::string>(&uri), "NDN name of the requested content");
|
||||
("name", po::value<std::string>(&prefix), "NDN name of the requested content");
|
||||
|
||||
po::options_description optDesc;
|
||||
optDesc.add(visibleDesc).add(hiddenDesc);
|
||||
|
||||
po::positional_options_description p;
|
||||
p.add("ndn-name", -1);
|
||||
p.add("name", -1);
|
||||
|
||||
po::variables_map vm;
|
||||
try {
|
||||
@@ -143,55 +154,83 @@ main(int argc, char* argv[])
|
||||
po::notify(vm);
|
||||
}
|
||||
catch (const po::error& e) {
|
||||
std::cerr << "ERROR: " << e.what() << std::endl;
|
||||
std::cerr << "ERROR: " << e.what() << "\n";
|
||||
return 2;
|
||||
}
|
||||
catch (const boost::bad_any_cast& e) {
|
||||
std::cerr << "ERROR: " << e.what() << std::endl;
|
||||
std::cerr << "ERROR: " << e.what() << "\n";
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (vm.count("help") > 0) {
|
||||
std::cout << "Usage: " << programName << " [options] ndn:/name" << std::endl;
|
||||
std::cout << "Usage: " << programName << " [options] ndn:/name\n";
|
||||
std::cout << visibleDesc;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (vm.count("version") > 0) {
|
||||
std::cout << "ndncatchunks " << tools::VERSION << std::endl;
|
||||
std::cout << "ndncatchunks " << tools::VERSION << "\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (vm.count("ndn-name") == 0) {
|
||||
std::cerr << "Usage: " << programName << " [options] ndn:/name" << std::endl;
|
||||
if (prefix.empty()) {
|
||||
std::cerr << "Usage: " << programName << " [options] ndn:/name\n";
|
||||
std::cerr << visibleDesc;
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (options.maxPipelineSize < 1 || options.maxPipelineSize > 1024) {
|
||||
std::cerr << "ERROR: pipeline size must be between 1 and 1024" << std::endl;
|
||||
return 2;
|
||||
if (nameConv == "marker" || nameConv == "m" || nameConv == "1") {
|
||||
name::setConventionEncoding(name::Convention::MARKER);
|
||||
}
|
||||
|
||||
if (options.maxRetriesOnTimeoutOrNack < -1 || options.maxRetriesOnTimeoutOrNack > 1024) {
|
||||
std::cerr << "ERROR: retries value must be between -1 and 1024" << std::endl;
|
||||
else if (nameConv == "typed" || nameConv == "t" || nameConv == "2") {
|
||||
name::setConventionEncoding(name::Convention::TYPED);
|
||||
}
|
||||
else if (!nameConv.empty()) {
|
||||
std::cerr << "ERROR: '" << nameConv << "' is not a valid naming convention\n";
|
||||
return 2;
|
||||
}
|
||||
|
||||
options.interestLifetime = time::milliseconds(vm["lifetime"].as<time::milliseconds::rep>());
|
||||
if (options.interestLifetime < 0_ms) {
|
||||
std::cerr << "ERROR: lifetime cannot be negative" << std::endl;
|
||||
std::cerr << "ERROR: --lifetime cannot be negative\n";
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (options.maxRetriesOnTimeoutOrNack < -1 || options.maxRetriesOnTimeoutOrNack > 1024) {
|
||||
std::cerr << "ERROR: --retries must be between -1 and 1024\n";
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (options.isQuiet && options.isVerbose) {
|
||||
std::cerr << "ERROR: cannot be quiet and verbose at the same time" << std::endl;
|
||||
std::cerr << "ERROR: cannot be quiet and verbose at the same time\n";
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (options.maxPipelineSize < 1 || options.maxPipelineSize > 1024) {
|
||||
std::cerr << "ERROR: --pipeline-size must be between 1 and 1024\n";
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (rttEstOptions->k < 0) {
|
||||
std::cerr << "ERROR: --rto-k cannot be negative\n";
|
||||
return 2;
|
||||
}
|
||||
|
||||
rttEstOptions->minRto = time::milliseconds(vm["min-rto"].as<time::milliseconds::rep>());
|
||||
if (rttEstOptions->minRto < 0_ms) {
|
||||
std::cerr << "ERROR: --min-rto cannot be negative\n";
|
||||
return 2;
|
||||
}
|
||||
|
||||
rttEstOptions->maxRto = time::milliseconds(vm["max-rto"].as<time::milliseconds::rep>());
|
||||
if (rttEstOptions->maxRto < rttEstOptions->minRto) {
|
||||
std::cerr << "ERROR: --max-rto cannot be smaller than --min-rto\n";
|
||||
return 2;
|
||||
}
|
||||
|
||||
try {
|
||||
Face face;
|
||||
auto discover = make_unique<DiscoverVersion>(face, Name(uri), options);
|
||||
auto discover = make_unique<DiscoverVersion>(face, Name(prefix), options);
|
||||
unique_ptr<PipelineInterests> pipeline;
|
||||
unique_ptr<StatisticsCollector> statsCollector;
|
||||
unique_ptr<RttEstimatorWithStats> rttEstimator;
|
||||
@@ -202,26 +241,18 @@ main(int argc, char* argv[])
|
||||
pipeline = make_unique<PipelineInterestsFixed>(face, options);
|
||||
}
|
||||
else if (pipelineType == "aimd" || pipelineType == "cubic") {
|
||||
auto optionsRttEst = make_shared<RttEstimatorWithStats::Options>();
|
||||
optionsRttEst->alpha = rtoAlpha;
|
||||
optionsRttEst->beta = rtoBeta;
|
||||
optionsRttEst->k = rtoK;
|
||||
optionsRttEst->initialRto = 1_s;
|
||||
optionsRttEst->minRto = time::milliseconds(minRto);
|
||||
optionsRttEst->maxRto = time::milliseconds(maxRto);
|
||||
optionsRttEst->rtoBackoffMultiplier = 2;
|
||||
if (options.isVerbose) {
|
||||
using namespace ndn::time;
|
||||
std::cerr << "RTT estimator parameters:\n"
|
||||
<< "\tAlpha = " << optionsRttEst->alpha << "\n"
|
||||
<< "\tBeta = " << optionsRttEst->beta << "\n"
|
||||
<< "\tK = " << optionsRttEst->k << "\n"
|
||||
<< "\tInitial RTO = " << duration_cast<milliseconds>(optionsRttEst->initialRto) << "\n"
|
||||
<< "\tMin RTO = " << duration_cast<milliseconds>(optionsRttEst->minRto) << "\n"
|
||||
<< "\tMax RTO = " << duration_cast<milliseconds>(optionsRttEst->maxRto) << "\n"
|
||||
<< "\tBackoff multiplier = " << optionsRttEst->rtoBackoffMultiplier << "\n";
|
||||
<< "\tAlpha = " << rttEstOptions->alpha << "\n"
|
||||
<< "\tBeta = " << rttEstOptions->beta << "\n"
|
||||
<< "\tK = " << rttEstOptions->k << "\n"
|
||||
<< "\tInitial RTO = " << duration_cast<milliseconds>(rttEstOptions->initialRto) << "\n"
|
||||
<< "\tMin RTO = " << duration_cast<milliseconds>(rttEstOptions->minRto) << "\n"
|
||||
<< "\tMax RTO = " << duration_cast<milliseconds>(rttEstOptions->maxRto) << "\n"
|
||||
<< "\tBackoff multiplier = " << rttEstOptions->rtoBackoffMultiplier << "\n";
|
||||
}
|
||||
rttEstimator = make_unique<RttEstimatorWithStats>(std::move(optionsRttEst));
|
||||
rttEstimator = make_unique<RttEstimatorWithStats>(std::move(rttEstOptions));
|
||||
|
||||
unique_ptr<PipelineInterestsAdaptive> adaptivePipeline;
|
||||
if (pipelineType == "aimd") {
|
||||
@@ -235,14 +266,14 @@ main(int argc, char* argv[])
|
||||
if (!cwndPath.empty()) {
|
||||
statsFileCwnd.open(cwndPath);
|
||||
if (statsFileCwnd.fail()) {
|
||||
std::cerr << "ERROR: failed to open " << cwndPath << std::endl;
|
||||
std::cerr << "ERROR: failed to open '" << cwndPath << "'\n";
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
if (!rttPath.empty()) {
|
||||
statsFileRtt.open(rttPath);
|
||||
if (statsFileRtt.fail()) {
|
||||
std::cerr << "ERROR: failed to open " << rttPath << std::endl;
|
||||
std::cerr << "ERROR: failed to open '" << rttPath << "'\n";
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
@@ -252,7 +283,7 @@ main(int argc, char* argv[])
|
||||
pipeline = std::move(adaptivePipeline);
|
||||
}
|
||||
else {
|
||||
std::cerr << "ERROR: Interest pipeline type not valid" << std::endl;
|
||||
std::cerr << "ERROR: '" << pipelineType << "' is not a valid pipeline type\n";
|
||||
return 2;
|
||||
}
|
||||
|
||||
@@ -263,15 +294,15 @@ main(int argc, char* argv[])
|
||||
face.processEvents();
|
||||
}
|
||||
catch (const Consumer::ApplicationNackError& e) {
|
||||
std::cerr << "ERROR: " << e.what() << std::endl;
|
||||
std::cerr << "ERROR: " << e.what() << "\n";
|
||||
return 3;
|
||||
}
|
||||
catch (const Consumer::DataValidationError& e) {
|
||||
std::cerr << "ERROR: " << e.what() << std::endl;
|
||||
std::cerr << "ERROR: " << e.what() << "\n";
|
||||
return 5;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "ERROR: " << e.what() << std::endl;
|
||||
std::cerr << "ERROR: " << e.what() << "\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,47 +53,49 @@ usage(std::ostream& os, const std::string& programName, const po::options_descri
|
||||
static int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
std::string programName = argv[0];
|
||||
std::string prefix;
|
||||
std::string signingStr;
|
||||
const std::string programName(argv[0]);
|
||||
|
||||
Producer::Options opts;
|
||||
std::string prefix, nameConv, signingStr;
|
||||
|
||||
po::options_description visibleDesc("Options");
|
||||
visibleDesc.add_options()
|
||||
("help,h", "print this help message and exit")
|
||||
("freshness,f", po::value<time::milliseconds::rep>()->default_value(opts.freshnessPeriod.count()),
|
||||
"FreshnessPeriod of the published Data packets, in milliseconds")
|
||||
("help,h", "print this help message and exit")
|
||||
("freshness,f", po::value<time::milliseconds::rep>()->default_value(opts.freshnessPeriod.count()),
|
||||
"FreshnessPeriod of the published Data packets, in milliseconds")
|
||||
("size,s", po::value<size_t>(&opts.maxSegmentSize)->default_value(opts.maxSegmentSize),
|
||||
"maximum chunk size, in bytes")
|
||||
("naming-convention,N", po::value<std::string>(&nameConv),
|
||||
"encoding convention to use for name components, either 'marker' or 'typed'")
|
||||
("signing-info,S", po::value<std::string>(&signingStr), "see 'man ndnputchunks' for usage")
|
||||
("print-data-version,p", po::bool_switch(&opts.wantShowVersion),
|
||||
"print Data version to the standard output")
|
||||
("size,s", po::value<size_t>(&opts.maxSegmentSize)->default_value(opts.maxSegmentSize),
|
||||
"maximum chunk size, in bytes")
|
||||
("signing-info,S", po::value<std::string>(&signingStr), "see 'man ndnputchunks' for usage")
|
||||
("quiet,q", po::bool_switch(&opts.isQuiet), "turn off all non-error output")
|
||||
("verbose,v", po::bool_switch(&opts.isVerbose), "turn on verbose output (per Interest information)")
|
||||
("version,V", "print program version and exit")
|
||||
("quiet,q", po::bool_switch(&opts.isQuiet), "turn off all non-error output")
|
||||
("verbose,v", po::bool_switch(&opts.isVerbose), "turn on verbose output (per Interest information)")
|
||||
("version,V", "print program version and exit")
|
||||
;
|
||||
|
||||
po::options_description hiddenDesc;
|
||||
hiddenDesc.add_options()
|
||||
("ndn-name,n", po::value<std::string>(&prefix), "NDN name for the served content");
|
||||
|
||||
po::positional_options_description p;
|
||||
p.add("ndn-name", -1);
|
||||
("name", po::value<std::string>(&prefix), "NDN name for the served content");
|
||||
|
||||
po::options_description optDesc;
|
||||
optDesc.add(visibleDesc).add(hiddenDesc);
|
||||
|
||||
po::positional_options_description p;
|
||||
p.add("name", -1);
|
||||
|
||||
po::variables_map vm;
|
||||
try {
|
||||
po::store(po::command_line_parser(argc, argv).options(optDesc).positional(p).run(), vm);
|
||||
po::notify(vm);
|
||||
}
|
||||
catch (const po::error& e) {
|
||||
std::cerr << "ERROR: " << e.what() << std::endl;
|
||||
std::cerr << "ERROR: " << e.what() << "\n";
|
||||
return 2;
|
||||
}
|
||||
catch (const boost::bad_any_cast& e) {
|
||||
std::cerr << "ERROR: " << e.what() << std::endl;
|
||||
std::cerr << "ERROR: " << e.what() << "\n";
|
||||
return 2;
|
||||
}
|
||||
|
||||
@@ -103,7 +105,7 @@ main(int argc, char* argv[])
|
||||
}
|
||||
|
||||
if (vm.count("version") > 0) {
|
||||
std::cout << "ndnputchunks " << tools::VERSION << std::endl;
|
||||
std::cout << "ndnputchunks " << tools::VERSION << "\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -112,14 +114,25 @@ main(int argc, char* argv[])
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (nameConv == "marker" || nameConv == "m" || nameConv == "1") {
|
||||
name::setConventionEncoding(name::Convention::MARKER);
|
||||
}
|
||||
else if (nameConv == "typed" || nameConv == "t" || nameConv == "2") {
|
||||
name::setConventionEncoding(name::Convention::TYPED);
|
||||
}
|
||||
else if (!nameConv.empty()) {
|
||||
std::cerr << "ERROR: '" << nameConv << "' is not a valid naming convention\n";
|
||||
return 2;
|
||||
}
|
||||
|
||||
opts.freshnessPeriod = time::milliseconds(vm["freshness"].as<time::milliseconds::rep>());
|
||||
if (opts.freshnessPeriod < 0_ms) {
|
||||
std::cerr << "ERROR: FreshnessPeriod cannot be negative" << std::endl;
|
||||
std::cerr << "ERROR: --freshness cannot be negative\n";
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (opts.maxSegmentSize < 1 || opts.maxSegmentSize > MAX_NDN_PACKET_SIZE) {
|
||||
std::cerr << "ERROR: Maximum chunk size must be between 1 and " << MAX_NDN_PACKET_SIZE << std::endl;
|
||||
std::cerr << "ERROR: --size must be between 1 and " << MAX_NDN_PACKET_SIZE << "\n";
|
||||
return 2;
|
||||
}
|
||||
|
||||
@@ -127,12 +140,12 @@ main(int argc, char* argv[])
|
||||
opts.signingInfo = security::SigningInfo(signingStr);
|
||||
}
|
||||
catch (const std::invalid_argument& e) {
|
||||
std::cerr << "ERROR: " << e.what() << std::endl;
|
||||
std::cerr << "ERROR: " << e.what() << "\n";
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (opts.isQuiet && opts.isVerbose) {
|
||||
std::cerr << "ERROR: Cannot be quiet and verbose at the same time" << std::endl;
|
||||
std::cerr << "ERROR: cannot be quiet and verbose at the same time\n";
|
||||
return 2;
|
||||
}
|
||||
|
||||
@@ -143,7 +156,7 @@ main(int argc, char* argv[])
|
||||
producer.run();
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "ERROR: " << e.what() << std::endl;
|
||||
std::cerr << "ERROR: " << e.what() << "\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user