diff options
Diffstat (limited to 'apps/ping/src/ping_server.cc')
-rw-r--r-- | apps/ping/src/ping_server.cc | 136 |
1 files changed, 55 insertions, 81 deletions
diff --git a/apps/ping/src/ping_server.cc b/apps/ping/src/ping_server.cc index 325ef675c..b2806ba64 100644 --- a/apps/ping/src/ping_server.cc +++ b/apps/ping/src/ping_server.cc @@ -21,6 +21,7 @@ #include <openssl/applink.c> #endif +#include <hicn/apps/utils/logger.h> #include <hicn/transport/auth/signer.h> #include <hicn/transport/auth/verifier.h> #include <hicn/transport/core/content_object.h> @@ -53,19 +54,19 @@ class CallbackContainer { content_object->setDstPort(interest.getSrcPort()); content_object->setTTL(ttl_); - if (verbose_) { - std::cout << ">>> send object " << content_object->getName() - << " src port: " << content_object->getSrcPort() - << " dst port: " << content_object->getDstPort() - << " TTL: " << (int)content_object->getTTL() << std::endl; - } else if (!quiet_) { - std::cout << ">>> send object " << content_object->getName() << std::endl; + if (LoggerIsOn(2)) { + LoggerInfo() << ">>> send object " << content_object->getName() + << " src port: " << content_object->getSrcPort() + << " dst port: " << content_object->getDstPort() + << " TTL: " << (int)content_object->getTTL(); + } else if (LoggerIsOn(1)) { + LoggerInfo() << ">>> send object " << content_object->getName(); } - if (dump_) { - std::cout << "----- object dump -----" << std::endl; + if (LoggerIsOn(3)) { + LoggerInfo() << "----- object dump -----"; content_object->dump(); - std::cout << "-----------------------" << std::endl; + LoggerInfo() << "-----------------------"; } if (sign_ && signer_) signer_->signPacket(content_object.get()); @@ -73,16 +74,13 @@ class CallbackContainer { } public: - CallbackContainer(const Name &prefix, uint32_t object_size, bool verbose, - bool dump, bool quiet, uint8_t ttl, auth::Signer *signer, - bool sign, std::string passphrase, uint32_t lifetime) + CallbackContainer(const Name &prefix, uint32_t object_size, uint8_t ttl, + auth::Signer *signer, bool sign, std::string passphrase, + uint32_t lifetime) : buffer_(object_size, 'X'), content_objects_((std::uint32_t)(1 << log2_content_object_buffer_size)), mask_((std::uint16_t)(1 << log2_content_object_buffer_size) - 1), content_objects_index_(0), - verbose_(verbose), - dump_(dump), - quiet_(quiet), ttl_(ttl), signer_(signer), sign_(sign) { @@ -117,28 +115,27 @@ class CallbackContainer { if (verifier_->verifyPacket(&interest)) { auto t1 = utils::SteadyTime::now(); auto dt = utils::SteadyTime::getDurationUs(t0, t1); - std::cout << "Verification time: " << dt.count() << std::endl; - std::cout << "<<< Signature Ok." << std::endl; + LoggerInfo() << "Verification time: " << dt.count(); + LoggerInfo() << "<<< Signature Ok."; } else { - std::cout << "<<< Signature verification failed!" << std::endl; + LoggerErr() << "<<< Signature verification failed!"; } } - if (verbose_) { - std::cout << "<<< received interest " << interest.getName() - << " src port: " << interest.getSrcPort() - << " dst port: " << interest.getDstPort() - << "TTL: " << (int)interest.getTTL() - << " suffixes in manifest: " << interest.numberOfSuffixes() - << std::endl; - } else if (!quiet_) { - std::cout << "<<< received interest " << interest.getName() << std::endl; + if (LoggerIsOn(2)) { + LoggerInfo() << "<<< received interest " << interest.getName() + << " src port: " << interest.getSrcPort() + << " dst port: " << interest.getDstPort() + << "TTL: " << (int)interest.getTTL() + << " suffixes in manifest: " << interest.numberOfSuffixes(); + } else if (LoggerIsOn(1)) { + LoggerInfo() << "<<< received interest " << interest.getName(); } - if (dump_) { - std::cout << "----- interest dump -----" << std::endl; + if (LoggerIsOn(3)) { + LoggerInfo() << "----- interest dump -----"; interest.dump(); - std::cout << "-------------------------" << std::endl; + LoggerInfo() << "-------------------------"; } if (!interest.isValid()) throw std::runtime_error("Bad interest format"); @@ -160,7 +157,7 @@ class CallbackContainer { } } - if (!quiet_) std::cout << std::endl; + LoggerVerbose(1) << "\n"; } private: @@ -168,9 +165,6 @@ class CallbackContainer { std::vector<std::shared_ptr<ContentObject>> content_objects_; std::uint16_t mask_; std::uint16_t content_objects_index_; - bool verbose_; - bool dump_; - bool quiet_; uint8_t ttl_; auth::Signer *signer_; bool sign_; @@ -178,32 +172,27 @@ class CallbackContainer { }; void help() { - std::cout << "usage: hicn-preoducer-ping [options]" << std::endl; - std::cout << "PING options" << std::endl; - std::cout << "-s <val> object content size (default 1350B)" - << std::endl; - std::cout << "-n <val> hicn name (default b001::/64)" << std::endl; - std::cout << "-l data lifetime" << std::endl; - std::cout << "-t set ttl (default 64)" << std::endl; - std::cout << "OUTPUT options" << std::endl; - std::cout << "-V verbose, prints statistics about the " - "messagges sent " - " and received (default false)" - << std::endl; - std::cout << "-D dump, dumps sent and received packets " - "(default false)" - << std::endl; - std::cout << "-q quiet, not prints (default false)" - << std::endl; - std::cerr << "-z <io_module> IO module to use. Default: hicnlight_module" - << std::endl; - std::cerr << "-F <conf_file> Path to optional configuration file for " - "libtransport" - << std::endl; + LoggerInfo() << "usage: hicn-preoducer-ping [options]"; + LoggerInfo() << "PING options"; + LoggerInfo() << "-s <val> object content size (default 1350B)"; + LoggerInfo() << "-n <val> hicn name (default b001::/64)"; + LoggerInfo() << "-l data lifetime"; + LoggerInfo() << "-t set ttl (default 64)"; + LoggerInfo() << "OUTPUT options"; + LoggerInfo() << "-V verbose, prints statistics about the " + "messagges sent " + " and received (default false)"; + LoggerInfo() << "-D dump, dumps sent and received packets " + "(default false)"; + LoggerInfo() << "-q quiet, not prints (default false)"; + LoggerInfo() + << "-z <io_module> IO module to use. Default: hicnlight_module"; + LoggerInfo() << "-F <conf_file> Path to optional configuration file for " + "libtransport"; #ifndef _WIN32 - std::cout << "-d daemon mode" << std::endl; + LoggerInfo() << "-d daemon mode"; #endif - std::cout << "-H prints this message" << std::endl; + LoggerInfo() << "-H prints this message"; } int main(int argc, char **argv) { @@ -216,9 +205,6 @@ int main(int argc, char **argv) { #endif std::string name_prefix = "b001::0/64"; std::string delimiter = "/"; - bool verbose = false; - bool dump = false; - bool quiet = false; uint32_t object_size = 1250; uint8_t ttl = 64; std::string keystore_path = "./rsa_crypto_material.p12"; @@ -233,9 +219,9 @@ int main(int argc, char **argv) { int opt; #ifndef _WIN32 - while ((opt = getopt(argc, argv, "a:s:n:t:l:qfrVDdHk:p:z:F:")) != -1) { + while ((opt = getopt(argc, argv, "a:s:n:t:l:frdHk:p:z:F:")) != -1) { #else - while ((opt = getopt(argc, argv, "s:n:t:l:qfrVDHk:p:z:F:")) != -1) { + while ((opt = getopt(argc, argv, "s:n:t:l:frHk:p:z:F:")) != -1) { #endif switch (opt) { case 'a': @@ -253,17 +239,6 @@ int main(int argc, char **argv) { case 'l': data_lifetime = std::stoi(optarg); break; - case 'V': - verbose = true; - break; - case 'D': - dump = true; - break; - case 'q': - verbose = false; - dump = false; - quiet = true; - break; #ifndef _WIN32 case 'd': daemon = true; @@ -319,13 +294,12 @@ int main(int argc, char **argv) { if (sign) { signer = std::make_unique<auth::AsymmetricSigner>(keystore_path, keystore_password); - stubs = - new CallbackContainer(n, object_size, verbose, dump, quiet, ttl, - signer.get(), sign, passphrase, data_lifetime); + stubs = new CallbackContainer(n, object_size, ttl, signer.get(), sign, + passphrase, data_lifetime); } else { auth::Signer *signer = nullptr; - stubs = new CallbackContainer(n, object_size, verbose, dump, quiet, ttl, - signer, sign, passphrase, data_lifetime); + stubs = new CallbackContainer(n, object_size, ttl, signer, sign, passphrase, + data_lifetime); } ProducerSocket p; @@ -346,7 +320,7 @@ int main(int argc, char **argv) { asio::signal_set signal_set(io_service, SIGINT); signal_set.async_wait( [&p, &io_service](const std::error_code &, const int &) { - std::cout << "STOPPING!!" << std::endl; + LoggerInfo() << "STOPPING!!"; p.stop(); io_service.stop(); }); |