poke: add --verbose option

Change-Id: I435f01cf6625bebbea40a0f808d8456fafb01fe1
This commit is contained in:
Davide Pesavento committed 2019-07-25 21:07:16 -04:00
1 parent de01c81a92
commit b3ae634086
4 files changed
+71 -22

No files matched your search

+4 -1
View File
@@ -4,7 +4,7 @@ ndnpoke
Synopsis
--------
**ndnpoke** [-h] [-f] [-F] [-x *freshness*] [-i *identity*\|\ -D] [-w *timeout*] [-V] *name*
**ndnpoke** [-h] [-f] [-F] [-x *freshness*] [-i *identity*\|\ -D] [-w *timeout*] [-v] [-V] *name*
Description
-----------
@@ -38,6 +38,9 @@ Options
``-w, --timeout <timeout>``
Quit the program after ``timeout`` milliseconds, even if no Interest has been received.
``-v, --verbose``
Turn on verbose output.
``-V, --version``
Print version and exit.
+1
View File
@@ -61,6 +61,7 @@ main(int argc, char* argv[])
("digest,D", po::bool_switch(&wantDigestSha256),
"use DigestSha256 signing method instead of SignatureSha256WithRsa")
("timeout,w", po::value<int>(), "set timeout (in milliseconds)")
("verbose,v", po::bool_switch(&options.isVerbose), "turn on verbose output")
("version,V", "print version and exit")
;
+53 -21
View File
@@ -47,30 +47,13 @@ NdnPoke::start()
auto data = createData();
if (m_options.wantForceData) {
m_face.put(*data);
m_result = Result::DATA_SENT;
return;
return sendData(*data);
}
m_registeredPrefix = m_face.setInterestFilter(m_options.name,
[this, data] (auto&&...) {
m_timeoutEvent.cancel();
m_face.put(*data);
m_result = Result::DATA_SENT;
m_registeredPrefix.cancel();
},
[this] (auto&&) {
if (m_options.timeout) {
m_timeoutEvent = m_scheduler.schedule(*m_options.timeout, [this] {
m_result = Result::TIMEOUT;
m_registeredPrefix.cancel();
});
}
},
[this] (auto&&, const auto& reason) {
m_result = Result::PREFIX_REG_FAIL;
std::cerr << "Prefix registration failure (" << reason << ")\n";
});
[this, data] (auto&&, const auto& interest) { this->onInterest(interest, *data); },
[this] (auto&&) { this->onRegSuccess(); },
[this] (auto&&, const auto& reason) { this->onRegFailure(reason); });
}
shared_ptr<Data>
@@ -93,5 +76,54 @@ NdnPoke::createData() const
return data;
}
void
NdnPoke::sendData(const Data& data)
{
m_face.put(data);
m_result = Result::DATA_SENT;
if (m_options.isVerbose) {
std::cerr << "DATA: " << data;
}
}
void
NdnPoke::onInterest(const Interest& interest, const Data& data)
{
if (m_options.isVerbose) {
std::cerr << "INTEREST: " << interest << std::endl;
}
m_timeoutEvent.cancel();
m_registeredPrefix.cancel();
sendData(data);
}
void
NdnPoke::onRegSuccess()
{
if (m_options.isVerbose) {
std::cerr << "Prefix registration successful" << std::endl;
}
if (m_options.timeout) {
m_timeoutEvent = m_scheduler.schedule(*m_options.timeout, [this] {
m_result = Result::TIMEOUT;
m_registeredPrefix.cancel();
if (m_options.isVerbose) {
std::cerr << "TIMEOUT" << std::endl;
}
});
}
}
void
NdnPoke::onRegFailure(const std::string& reason)
{
m_result = Result::PREFIX_REG_FAIL;
std::cerr << "Prefix registration failure (" << reason << ")" << std::endl;
}
} // namespace peek
} // namespace ndn
+13
View File
@@ -47,6 +47,7 @@ struct PokeOptions
security::SigningInfo signingInfo;
// program behavior options
bool isVerbose = false;
bool wantForceData = false;
optional<time::milliseconds> timeout;
};
@@ -81,6 +82,18 @@ private:
shared_ptr<Data>
createData() const;
void
sendData(const Data& data);
void
onInterest(const Interest& interest, const Data& data);
void
onRegSuccess();
void
onRegFailure(const std::string& reason);
private:
const PokeOptions m_options;
Face& m_face;