From b96d1545a8d2a173dc5911ed0bca3e04dbb02176 Mon Sep 17 00:00:00 2001 From: Michele Papalini Date: Wed, 1 Feb 2023 17:25:21 +0100 Subject: fix(apps): fix issues reported by sonarqube Ref: HICN-836 Signed-off-by: Michele Papalini Change-Id: Ie76771ca75bd224084ce3c893aba661b97064419 --- apps/higet/higet.cc | 43 +++++---------- apps/hiperf/src/client.cc | 64 +++++++++++++++------- apps/hiperf/src/client.h | 4 +- apps/hiperf/src/common.h | 55 +++++++++---------- apps/hiperf/src/main.cc | 17 +++--- apps/hiperf/src/server.cc | 46 ++++++++++------ .../includes/hicn/http-proxy/forwarder_interface.h | 23 +++----- .../includes/hicn/http-proxy/http_proxy.h | 13 +++-- .../includes/hicn/http-proxy/http_session.h | 24 ++++---- .../includes/hicn/http-proxy/icn_receiver.h | 10 +--- apps/http-proxy/includes/hicn/http-proxy/utils.h | 4 +- apps/http-proxy/main.cc | 5 +- apps/http-proxy/src/forwarder_interface.cc | 10 ++-- apps/http-proxy/src/http_1x_message_fast_parser.cc | 5 +- apps/http-proxy/src/http_proxy.cc | 45 +++++++-------- apps/http-proxy/src/http_session.cc | 52 +++++++----------- apps/http-proxy/src/icn_receiver.cc | 12 ++-- apps/ping/src/ping_client.cc | 16 +++--- apps/ping/src/ping_server.cc | 12 ++-- 19 files changed, 229 insertions(+), 231 deletions(-) (limited to 'apps') diff --git a/apps/higet/higet.cc b/apps/higet/higet.cc index c86f05f12..dcd55e755 100644 --- a/apps/higet/higet.cc +++ b/apps/higet/higet.cc @@ -27,10 +27,6 @@ #define ASIO_STANDALONE #endif #include -#include - -#define DEFAULT_BETA 0.99 -#define DEFAULT_GAMMA 0.07 namespace http { @@ -46,16 +42,13 @@ class ReadBytesCallbackImplementation static std::string chunk_separator; public: - ReadBytesCallbackImplementation(std::string file_name, long yet_downloaded) + ReadBytesCallbackImplementation(const std::string &file_name, + long yet_downloaded) : file_name_(file_name), temp_file_name_(file_name_ + ".temp"), yet_downloaded_(yet_downloaded), byte_downloaded_(yet_downloaded), - chunked_(false), - chunk_size_(0), - work_(std::make_unique(io_service_)), - thread_( - std::make_unique([this]() { io_service_.run(); })) { + work_(std::make_unique(io_service_)) { std::streambuf *buf; if (file_name_ != "-") { of_.open(temp_file_name_, std::ofstream::binary | std::ofstream::app); @@ -67,12 +60,6 @@ class ReadBytesCallbackImplementation out_ = new std::ostream(buf); } - ~ReadBytesCallbackImplementation() { - if (thread_->joinable()) { - thread_->join(); - } - } - void onBytesReceived(std::unique_ptr &&buffer) { auto buffer_ptr = buffer.release(); io_service_.post([this, buffer_ptr]() { @@ -100,7 +87,7 @@ class ReadBytesCallbackImplementation if (chunked_) { if (chunk_size_ > 0) { - out_->write((char *)payload->data(), chunk_size_); + out_->write((char *)payload->writableData(), chunk_size_); payload->trimStart(chunk_size_); if (payload->length() >= chunk_separator.size()) { @@ -128,7 +115,7 @@ class ReadBytesCallbackImplementation chunk_size_ -= payload->length(); } - out_->write((char *)payload->data(), to_write); + out_->write((char *)payload->writableData(), to_write); byte_downloaded_ += (long)to_write; payload->trimStart(to_write); @@ -138,7 +125,7 @@ class ReadBytesCallbackImplementation } } } else { - out_->write((char *)payload->data(), payload->length()); + out_->write((char *)payload->writableData(), payload->length()); byte_downloaded_ += (long)payload->length(); } @@ -224,7 +211,6 @@ class ReadBytesCallbackImplementation } } - private: std::string file_name_; std::string temp_file_name_; std::ostream *out_; @@ -233,23 +219,22 @@ class ReadBytesCallbackImplementation long content_size_; bool first_chunk_read_ = false; long byte_downloaded_ = 0; - bool chunked_; - std::size_t chunk_size_; + bool chunked_ = false; + std::size_t chunk_size_ = 0; asio::io_service io_service_; std::unique_ptr work_; - std::unique_ptr thread_; }; std::string ReadBytesCallbackImplementation::chunk_separator = "\r\n"; -long checkFileStatus(std::string file_name) { +long checkFileStatus(const std::string &file_name) { struct stat stat_buf; std::string temp_file_name_ = file_name + ".temp"; int rc = stat(temp_file_name_.c_str(), &stat_buf); return rc == 0 ? stat_buf.st_size : -1; } -void usage(char *program_name) { +void usage(const char *program_name) { LoggerInfo() << "usage:"; LoggerInfo() << program_name << " [option]... [url]..."; LoggerInfo() << program_name << " options:"; @@ -261,10 +246,9 @@ void usage(char *program_name) { "the response"; LoggerInfo() << "example:"; LoggerInfo() << "\t" << program_name << " -O - http://origin/index.html"; - exit(EXIT_FAILURE); } -int main(int argc, char **argv) { +int http_main(int argc, char **argv) { #ifdef _WIN32 WSADATA wsaData = {0}; WSAStartup(MAKEWORD(2, 2), &wsaData); @@ -293,15 +277,16 @@ int main(int argc, char **argv) { case 'P': conf.ipv6_first_word = optarg; break; - case 'h': default: usage(argv[0]); + exit(EXIT_FAILURE); break; } } if (!argv[optind]) { usage(argv[0]); + exit(EXIT_FAILURE); } name = argv[optind]; @@ -354,4 +339,4 @@ int main(int argc, char **argv) { } // end namespace http -int main(int argc, char **argv) { return http::main(argc, argv); } +int main(int argc, char **argv) { return http::http_main(argc, argv); } diff --git a/apps/hiperf/src/client.cc b/apps/hiperf/src/client.cc index 0e1f596c5..1ce5b4c55 100644 --- a/apps/hiperf/src/client.cc +++ b/apps/hiperf/src/client.cc @@ -26,6 +26,20 @@ namespace hiperf { class RTCCallback; class Callback; +using transport::auth::CryptoHashType; +using transport::core::Packet; +using transport::core::Prefix; +using transport::interface::ConsumerCallbacksOptions; +using transport::interface::ConsumerSocket; +using transport::interface::GeneralTransportOptions; +using transport::interface::ProducerSocket; +using transport::interface::ProductionProtocolAlgorithms; +using transport::interface::RaaqmTransportOptions; +using transport::interface::RtcTransportOptions; +using transport::interface::RtcTransportRecoveryStrategies; +using transport::interface::StrategyCallback; +using transport::interface::TransportStatistics; + /** * Hiperf client class: configure and setup an hicn consumer following the * ClientConfiguration. @@ -207,12 +221,14 @@ class HIperfClient::Impl { void checkReceivedRtcContent( [[maybe_unused]] const ConsumerSocket &c, - [[maybe_unused]] const ContentObject &content_object) const { + [[maybe_unused]] const transport::core::ContentObject &content_object) + const { // Nothing to do here } - void processLeavingInterest(const ConsumerSocket & /*c*/, - const Interest & /*interest*/) const { + void processLeavingInterest( + const ConsumerSocket & /*c*/, + const transport::core::Interest & /*interest*/) const { // Nothing to do here } @@ -470,7 +486,7 @@ class HIperfClient::Impl { int setupRTCSocket() { int ret = ERROR_SUCCESS; - configuration_.transport_protocol_ = RTC; + configuration_.transport_protocol_ = transport::interface::RTC; if (configuration_.relay_ && configuration_.parallel_flows_ == 1) { int production_protocol = ProductionProtocolAlgorithms::RTC_PROD; @@ -563,7 +579,7 @@ class HIperfClient::Impl { ret = consumer_socket_->setSocketOption( ConsumerCallbacksOptions::CONTENT_OBJECT_INPUT, - (ConsumerContentObjectCallback)std::bind( + (transport::interface::ConsumerContentObjectCallback)std::bind( &Impl::ConsumerContext::checkReceivedRtcContent, this, std::placeholders::_1, std::placeholders::_2)); if (ret == SOCKET_OPTION_NOT_SET) { @@ -572,7 +588,8 @@ class HIperfClient::Impl { std::shared_ptr transport_stats; ret = consumer_socket_->getSocketOption( - OtherOptions::STATISTICS, (TransportStatistics **)&transport_stats); + transport::interface::OtherOptions::STATISTICS, + (TransportStatistics **)&transport_stats); transport_stats->setAlpha(0.0); if (ret == SOCKET_OPTION_NOT_SET) { @@ -585,7 +602,7 @@ class HIperfClient::Impl { int setupRAAQMSocket() { int ret = ERROR_SUCCESS; - configuration_.transport_protocol_ = RAAQM; + configuration_.transport_protocol_ = transport::interface::RAAQM; consumer_socket_ = std::make_unique(configuration_.transport_protocol_); @@ -610,7 +627,7 @@ class HIperfClient::Impl { } int setupCBRSocket() { - configuration_.transport_protocol_ = CBR; + configuration_.transport_protocol_ = transport::interface::CBR; consumer_socket_ = std::make_unique(configuration_.transport_protocol_); @@ -621,7 +638,8 @@ class HIperfClient::Impl { public: int setup() { int ret; - std::shared_ptr verifier = std::make_shared(); + std::shared_ptr verifier = + std::make_shared(); if (configuration_.rtc_) { ret = setupRTCSocket(); @@ -669,7 +687,8 @@ class HIperfClient::Impl { ret = consumer_socket_->setSocketOption( ConsumerCallbacksOptions::FWD_STRATEGY_CHANGE, (StrategyCallback)[]( - [[maybe_unused]] notification::Strategy strategy){ + [[maybe_unused]] transport::interface::notification::Strategy + strategy){ // nothing to do }); if (ret == SOCKET_OPTION_NOT_SET) { @@ -679,15 +698,16 @@ class HIperfClient::Impl { ret = consumer_socket_->setSocketOption( ConsumerCallbacksOptions::REC_STRATEGY_CHANGE, (StrategyCallback)[]( - [[maybe_unused]] notification::Strategy strategy){ + [[maybe_unused]] transport::interface::notification::Strategy + strategy){ // nothing to do }); if (ret == SOCKET_OPTION_NOT_SET) { return ERROR_SETUP; } - ret = consumer_socket_->setSocketOption(CURRENT_WINDOW_SIZE, - configuration_.window_); + ret = consumer_socket_->setSocketOption( + transport::interface::CURRENT_WINDOW_SIZE, configuration_.window_); if (ret == SOCKET_OPTION_NOT_SET) { getOutputStream() << "ERROR -- Impossible to set the size of the window." @@ -696,13 +716,13 @@ class HIperfClient::Impl { } if (!configuration_.producer_certificate_.empty()) { - verifier = std::make_shared( + verifier = std::make_shared( configuration_.producer_certificate_); } if (!configuration_.passphrase_.empty()) { - verifier = - std::make_shared(configuration_.passphrase_); + verifier = std::make_shared( + configuration_.passphrase_); } verifier->setVerificationFailedCallback( @@ -716,10 +736,12 @@ class HIperfClient::Impl { } // Signer for aggregatd interests - std::shared_ptr signer = std::make_shared(); + std::shared_ptr signer = + std::make_shared(); if (!configuration_.aggr_interest_passphrase_.empty()) { - signer = std::make_shared( - CryptoSuite::HMAC_SHA256, configuration_.aggr_interest_passphrase_); + signer = std::make_shared( + transport::auth::CryptoSuite::HMAC_SHA256, + configuration_.aggr_interest_passphrase_); } ret = consumer_socket_->setSocketOption(GeneralTransportOptions::SIGNER, signer); @@ -734,7 +756,7 @@ class HIperfClient::Impl { ret = consumer_socket_->setSocketOption( ConsumerCallbacksOptions::INTEREST_OUTPUT, - (ConsumerInterestCallback)std::bind( + (transport::interface::ConsumerInterestCallback)std::bind( &ConsumerContext::processLeavingInterest, this, std::placeholders::_1, std::placeholders::_2)); @@ -751,7 +773,7 @@ class HIperfClient::Impl { ret = consumer_socket_->setSocketOption( ConsumerCallbacksOptions::STATS_SUMMARY, - (ConsumerTimerCallback)std::bind( + (transport::interface::ConsumerTimerCallback)std::bind( &Impl::ConsumerContext::handleTimerExpiration, this, std::placeholders::_1, std::placeholders::_2)); diff --git a/apps/hiperf/src/client.h b/apps/hiperf/src/client.h index c4c6bc2ae..beecbd473 100644 --- a/apps/hiperf/src/client.h +++ b/apps/hiperf/src/client.h @@ -20,7 +20,7 @@ namespace hiperf { -class HIperfClient : private ::utils::NonCopyable { +class HIperfClient : public ::utils::NonCopyable { public: explicit HIperfClient(const ClientConfiguration &conf); @@ -33,4 +33,4 @@ class HIperfClient : private ::utils::NonCopyable { std::unique_ptr impl_; }; -} // namespace hiperf \ No newline at end of file +} // namespace hiperf diff --git a/apps/hiperf/src/common.h b/apps/hiperf/src/common.h index 1565e63f7..0f96bef1f 100644 --- a/apps/hiperf/src/common.h +++ b/apps/hiperf/src/common.h @@ -44,23 +44,22 @@ #ifndef ERROR_SUCCESS #define ERROR_SUCCESS 0 #endif -#define ERROR_SETUP -5 -#define MIN_PROBE_SEQ 0xefffffff -#define RTC_HEADER_SIZE 12 -#define FEC_HEADER_MAX_SIZE 36 -#define HIPERF_MTU 1500 - -using namespace transport::interface; -using namespace transport::auth; -using namespace transport::core; +static constexpr int ERROR_SETUP = -5; +static constexpr uint32_t MIN_PROBE_SEQ = 0xefffffff; +static constexpr uint32_t RTC_HEADER_SIZE = 12; +static constexpr uint32_t FEC_HEADER_MAX_SIZE = 36; +static constexpr uint32_t HIPERF_MTU = 1500; namespace hiperf { +using transport::core::Packet; +using transport::core::Prefix; + /** * Logger */ template -class Base : protected std::stringbuf, protected std::ostream { +class Base : public std::stringbuf, public std::ostream { protected: static inline const char separator[] = "| "; @@ -88,7 +87,7 @@ class Base : protected std::stringbuf, protected std::ostream { end_ = end.str(); } - Base(Base &&other) + Base(Base &&other) noexcept : parent_(other.parent_), configuration_(other.configuration_), io_service_(other.io_service_), @@ -96,6 +95,8 @@ class Base : protected std::stringbuf, protected std::ostream { name_id_(std::move(other.name_id_)), flow_name_(other.flow_name_) {} + ~Base() {} + /*************************************************************** * std::stringbuf sync override ***************************************************************/ @@ -142,7 +143,7 @@ static inline int ensureFlows(const Prefix &prefix, std::size_t flows) { } else { LoggerErr() << "Error: unknown address family."; ret = ERROR_SETUP; - goto end; + goto END; } log2_n_flow = max_ip_addr_len_bits - prefix.getPrefixLength(); @@ -155,7 +156,7 @@ static inline int ensureFlows(const Prefix &prefix, std::size_t flows) { ret = ERROR_SETUP; } -end: +END: return ret; } @@ -184,18 +185,10 @@ class PayloadSize { */ class Rate { public: - Rate() : rate_kbps_(0) {} + Rate() {} ~Rate() {} - Rate &operator=(const Rate &other) { - if (this != &other) { - rate_kbps_ = other.rate_kbps_; - } - - return *this; - } - - Rate(const std::string &rate) { + explicit Rate(const std::string &rate) { std::size_t found = rate.find("kbps"); if (found != std::string::npos) { rate_kbps_ = std::stof(rate.substr(0, found)); @@ -223,7 +216,7 @@ class Rate { } private: - float rate_kbps_; + float rate_kbps_ = 0.0; }; struct packet_t { @@ -238,7 +231,8 @@ struct Configuration { bool rtc_{false}; uint16_t port_{0}; bool aggregated_data_{false}; - Packet::Format packet_format_{default_values::packet_format}; + Packet::Format packet_format_{ + transport::interface::default_values::packet_format}; uint32_t parallel_flows_{1}; bool colored_{true}; }; @@ -246,15 +240,15 @@ struct Configuration { /** * Container for command line configuration for hiperf client. */ -struct ClientConfiguration : public Configuration { +struct ClientConfiguration : Configuration { double beta_{-1.f}; double drop_factor_{-1.f}; double window_{-1.f}; std::string producer_certificate_; - std::string passphrase_; std::size_t receive_buffer_size_{128 * 1024}; std::uint32_t report_interval_milliseconds_{1000}; - TransportProtocolAlgorithms transport_protocol_{CBR}; + transport::interface::TransportProtocolAlgorithms transport_protocol_{ + transport::interface::CBR}; bool test_mode_{false}; bool relay_{false}; Prefix producer_prefix_; @@ -274,14 +268,15 @@ struct ClientConfiguration : public Configuration { /** * Container for command line configuration for hiperf server. */ -struct ServerConfiguration : public Configuration { +struct ServerConfiguration : Configuration { bool virtual_producer_{true}; std::uint32_t manifest_max_capacity_{0}; bool live_production_{false}; std::uint32_t content_lifetime_{ transport::interface::default_values::content_object_expiry_time}; std::uint32_t download_size_{20 * 1024 * 1024}; - CryptoHashType hash_algorithm_{CryptoHashType::SHA256}; + transport::auth::CryptoHashType hash_algorithm_{ + transport::auth::CryptoHashType::SHA256}; std::string keystore_name_; std::string keystore_password_{"cisco"}; bool multiphase_produce_{false}; diff --git a/apps/hiperf/src/main.cc b/apps/hiperf/src/main.cc index d655b1fe3..25c1a288c 100644 --- a/apps/hiperf/src/main.cc +++ b/apps/hiperf/src/main.cc @@ -19,14 +19,18 @@ namespace hiperf { +using transport::auth::CryptoHashType; + static std::unordered_map const packet_format_map = {{"ipv4_tcp", HICN_PACKET_FORMAT_IPV4_TCP}, {"ipv6_tcp", HICN_PACKET_FORMAT_IPV6_TCP}, {"new", HICN_PACKET_FORMAT_NEW}}; -#define TO_LOWER(s) \ - std::transform(s.begin(), s.end(), s.begin(), \ +std::string str_tolower(std::string s) { + std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return std::tolower(c); }); + return s; +} void usage() { LoggerInfo() << "HIPERF - Instrumentation tool for performing active network" @@ -187,7 +191,7 @@ void usage() { "defaults to IPV6_TCP)"; } -int main(int argc, char *argv[]) { +int hiperf_main(int argc, char *argv[]) { #ifndef _WIN32 // Common bool daemon = false; @@ -202,7 +206,7 @@ int main(int argc, char *argv[]) { int role = 0; int options = 0; - char *log_file = nullptr; + const char *log_file = nullptr; transport::interface::global_config::IoModuleConfiguration config; std::string conf_file; config.name = "hicnlight_module"; @@ -282,7 +286,7 @@ int main(int argc, char *argv[]) { } case 'w': { std::string packet_format_s = std::string(optarg); - TO_LOWER(packet_format_s); + packet_format_s = str_tolower(packet_format_s); auto it = packet_format_map.find(std::string(optarg)); if (it == packet_format_map.end()) throw std::runtime_error("Bad packet format"); @@ -476,7 +480,6 @@ int main(int argc, char *argv[]) { options = -1; break; } - case 'h': default: usage(); return EXIT_FAILURE; @@ -565,4 +568,4 @@ int main(int argc, char *argv[]) { } // namespace hiperf -int main(int argc, char *argv[]) { return hiperf::main(argc, argv); } +int main(int argc, char *argv[]) { return hiperf::hiperf_main(argc, argv); } diff --git a/apps/hiperf/src/server.cc b/apps/hiperf/src/server.cc index b338c69df..3f6c335f9 100644 --- a/apps/hiperf/src/server.cc +++ b/apps/hiperf/src/server.cc @@ -17,18 +17,25 @@ namespace hiperf { +using transport::core::ContentObject; +using transport::core::Interest; +using transport::core::Name; +using transport::interface::GeneralTransportOptions; +using transport::interface::ProducerCallbacksOptions; +using transport::interface::ProducerInterestCallback; +using transport::interface::ProducerSocket; +using transport::interface::ProductionProtocolAlgorithms; + /** * Hiperf server class: configure and setup an hicn producer following the * ServerConfiguration. */ class HIperfServer::Impl { - static inline constexpr std::size_t klog2_content_object_buffer_size() { - return 8; - } - static inline constexpr std::size_t kcontent_object_buffer_size() { + static constexpr std::size_t klog2_content_object_buffer_size() { return 8; } + static constexpr std::size_t kcontent_object_buffer_size() { return (1 << klog2_content_object_buffer_size()); } - static inline constexpr std::size_t kmask() { + static constexpr std::size_t kmask() { return (kcontent_object_buffer_size() - 1); } @@ -58,7 +65,8 @@ class HIperfServer::Impl { content_objects_.emplace_back(std::make_shared( configuration_.name_.makeName(), configuration_.packet_format_, 0, (const uint8_t *)buffer.data(), buffer.size())); - element->setLifetime(default_values::content_object_expiry_time); + element->setLifetime( + transport::interface::default_values::content_object_expiry_time); } } @@ -92,7 +100,8 @@ class HIperfServer::Impl { int setup() { int ret; int production_protocol; - std::shared_ptr signer = std::make_shared(); + std::shared_ptr signer = + std::make_shared(); if (!configuration_.rtc_) { production_protocol = ProductionProtocolAlgorithms::BYTE_STREAM; @@ -121,7 +130,7 @@ class HIperfServer::Impl { return ERROR_SETUP; } - if (producer_socket_->setSocketOption(PACKET_FORMAT, + if (producer_socket_->setSocketOption(transport::interface::PACKET_FORMAT, configuration_.packet_format_) == SOCKET_OPTION_NOT_SET) { getOutputStream() << "ERROR -- Impossible to set the packet format." @@ -130,12 +139,13 @@ class HIperfServer::Impl { } if (!configuration_.passphrase_.empty()) { - signer = std::make_shared(CryptoSuite::HMAC_SHA256, - configuration_.passphrase_); + signer = std::make_shared( + transport::auth::CryptoSuite::HMAC_SHA256, + configuration_.passphrase_); } if (!configuration_.keystore_name_.empty()) { - signer = std::make_shared( + signer = std::make_shared( configuration_.keystore_name_, configuration_.keystore_password_); } @@ -161,9 +171,10 @@ class HIperfServer::Impl { } // Verifier for aggregated interests - std::shared_ptr verifier = std::make_shared(); + std::shared_ptr verifier = + std::make_shared(); if (!configuration_.aggr_interest_passphrase_.empty()) { - verifier = std::make_unique( + verifier = std::make_unique( configuration_.aggr_interest_passphrase_); } ret = producer_socket_->setSocketOption(GeneralTransportOptions::VERIFIER, @@ -172,7 +183,7 @@ class HIperfServer::Impl { if (configuration_.rtc_) { ret = producer_socket_->setSocketOption( - RtcTransportOptions::AGGREGATED_DATA, + transport::interface::RtcTransportOptions::AGGREGATED_DATA, configuration_.aggregated_data_); if (ret == SOCKET_OPTION_NOT_SET) { @@ -249,7 +260,7 @@ class HIperfServer::Impl { ret = producer_socket_->setSocketOption( ProducerCallbacksOptions::CONTENT_PRODUCED, - (ProducerContentCallback)bind( + (transport::interface::ProducerContentCallback)bind( &ProducerContext::onContentProduced, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); if (ret == SOCKET_OPTION_NOT_SET) { @@ -308,8 +319,9 @@ class HIperfServer::Impl { * @brief Synchronously produce content upon reception of one interest */ void processInterest(ProducerSocket &p, const Interest &interest) const { - p.setSocketOption(ProducerCallbacksOptions::CACHE_MISS, - (ProducerInterestCallback)VOID_HANDLER); + p.setSocketOption( + ProducerCallbacksOptions::CACHE_MISS, + (ProducerInterestCallback)transport::interface::VOID_HANDLER); p.setSocketOption(GeneralTransportOptions::CONTENT_OBJECT_EXPIRY_TIME, configuration_.content_lifetime_); diff --git a/apps/http-proxy/includes/hicn/http-proxy/forwarder_interface.h b/apps/http-proxy/includes/hicn/http-proxy/forwarder_interface.h index c60e26c63..ae9562a12 100644 --- a/apps/http-proxy/includes/hicn/http-proxy/forwarder_interface.h +++ b/apps/http-proxy/includes/hicn/http-proxy/forwarder_interface.h @@ -52,16 +52,11 @@ using RouteInfoPtr = std::shared_ptr; class ForwarderInterface { public: - ForwarderInterface(asio::io_service &io_service) + explicit ForwarderInterface(asio::io_service &io_service) : external_ioservice_(io_service), work_(std::make_unique(internal_ioservice_)), - sock_(nullptr), thread_(std::make_unique( - [this]() { internal_ioservice_.run(); })), - check_routes_timer_(nullptr), - pending_add_route_counter_(0), - route_id_(0), - closed_(false) {} + [this]() { internal_ioservice_.run(); })) {} ~ForwarderInterface(); @@ -95,20 +90,20 @@ class ForwarderInterface { void internalCreateFaceAndRoute(RouteInfoPtr route_info, uint8_t max_try, asio::steady_timer *timer, - SetRouteCallback callback); + const SetRouteCallback &callback); - int tryToCreateFaceAndRoute(route_info_t *route_info); + int tryToCreateFaceAndRoute(const route_info_t *route_info); asio::io_service &external_ioservice_; asio::io_service internal_ioservice_; std::unique_ptr work_; - hc_sock_t *sock_; + hc_sock_t *sock_ = nullptr; std::unique_ptr thread_; std::unordered_map route_status_; - std::unique_ptr check_routes_timer_; - uint32_t pending_add_route_counter_; - uint32_t route_id_; - bool closed_; + std::unique_ptr check_routes_timer_ = nullptr; + uint32_t pending_add_route_counter_ = 0; + uint32_t route_id_ = 0; + bool closed_ = false; }; } // namespace transport diff --git a/apps/http-proxy/includes/hicn/http-proxy/http_proxy.h b/apps/http-proxy/includes/hicn/http-proxy/http_proxy.h index 1fa96956a..567ab4540 100644 --- a/apps/http-proxy/includes/hicn/http-proxy/http_proxy.h +++ b/apps/http-proxy/includes/hicn/http-proxy/http_proxy.h @@ -34,7 +34,8 @@ class TcpListener { public: using AcceptCallback = std::function; - TcpListener(asio::io_service& io_service, short port, AcceptCallback callback) + TcpListener(asio::io_service& io_service, short port, + const AcceptCallback& callback) : acceptor_(io_service), #if ((ASIO_VERSION / 100 % 1000) < 12) socket_(io_service), @@ -49,7 +50,6 @@ class TcpListener { acceptor_.listen(); } - public: void doAccept() { #if ((ASIO_VERSION / 100 % 1000) >= 12) acceptor_.async_accept( @@ -80,7 +80,7 @@ class HTTPClientConnectionCallback; class Receiver { public: - Receiver() : thread_() {} + Receiver() {} virtual ~Receiver() = default; void stopAndJoinThread() { thread_.stop(); } virtual void stop() = 0; @@ -115,13 +115,13 @@ class TcpReceiver : public Receiver { std::deque http_clients_; std::unordered_set used_http_clients_; ForwarderConfig forwarder_config_; - bool stopped_; + bool stopped_ = false; }; class IcnReceiver : public Receiver { public: template - IcnReceiver(Args&&... args) + explicit IcnReceiver(Args&&... args) : Receiver(), icn_consum_producer_(thread_.getIoService(), std::forward(args)...) { @@ -148,6 +148,7 @@ class HTTPProxy { std::string prefix; std::string first_ipv6_word; + virtual ~CommonParams() {} virtual void printParams() { LoggerInfo() << "Parameters: "; }; }; @@ -206,4 +207,4 @@ class HTTPProxy { asio::signal_set signals_; }; -} // namespace transport \ No newline at end of file +} // namespace transport diff --git a/apps/http-proxy/includes/hicn/http-proxy/http_session.h b/apps/http-proxy/includes/hicn/http-proxy/http_session.h index 1563431dc..1b7df96a6 100644 --- a/apps/http-proxy/includes/hicn/http-proxy/http_session.h +++ b/apps/http-proxy/includes/hicn/http-proxy/http_session.h @@ -73,13 +73,16 @@ class HTTPSession { }; public: - HTTPSession(asio::io_service &io_service, std::string &ip_address, - std::string &port, ContentReceivedCallback receive_callback, - OnConnectionClosed on_reconnect_callback, bool client = false); + HTTPSession(asio::io_service &io_service, const std::string &ip_address, + const std::string &port, + const ContentReceivedCallback &receive_callback, + const OnConnectionClosed &on_reconnect_callback, + bool client = false); HTTPSession(asio::ip::tcp::socket socket, - ContentReceivedCallback receive_callback, - OnConnectionClosed on_reconnect_callback, bool client = true); + const ContentReceivedCallback &receive_callback, + const OnConnectionClosed &on_reconnect_callback, + bool client = true); ~HTTPSession(); @@ -103,7 +106,6 @@ class HTTPSession { bool checkConnected(); - private: void handleRead(const std::error_code &ec, std::size_t length); void tryReconnection(); void startConnectionTimer(); @@ -120,14 +122,14 @@ class HTTPSession { asio::streambuf input_buffer_; bool reverse_; - bool is_reconnection_; - bool data_available_; + bool is_reconnection_ = false; + bool data_available_ = false; - std::size_t content_length_; + std::size_t content_length_ = 0; // Chunked encoding - bool is_last_chunk_; - bool chunked_; + bool is_last_chunk_ = false; + bool chunked_ = false; ContentReceivedCallback receive_callback_; OnConnectionClosed on_connection_closed_callback_; diff --git a/apps/http-proxy/includes/hicn/http-proxy/icn_receiver.h b/apps/http-proxy/includes/hicn/http-proxy/icn_receiver.h index a402d44cf..e3ab97fdd 100644 --- a/apps/http-proxy/includes/hicn/http-proxy/icn_receiver.h +++ b/apps/http-proxy/includes/hicn/http-proxy/icn_receiver.h @@ -24,7 +24,6 @@ #include #include #include -//#include "http_session.h" namespace transport { @@ -48,9 +47,7 @@ class AsyncConsumerProducer { const std::string& content_lifetime, bool manifest) : AsyncConsumerProducer(internal_io_service_, prefix, first_ipv6_word, origin_address, origin_port, cache_size, mtu, - content_lifetime, manifest) { - external_io_service_ = false; - } + content_lifetime, manifest) {} void run(); @@ -72,7 +69,7 @@ class AsyncConsumerProducer { core::Prefix prefix_; asio::io_service& io_service_; asio::io_service internal_io_service_; - bool external_io_service_; + bool external_io_service_ = false; interface::ProducerSocket producer_socket_; std::string ip_address_; @@ -80,9 +77,8 @@ class AsyncConsumerProducer { uint32_t cache_size_; uint32_t mtu_; - uint64_t request_counter_; + uint64_t request_counter_ = 0; - // std::unordered_map> // connection_map_; HTTPSession connector_; diff --git a/apps/http-proxy/includes/hicn/http-proxy/utils.h b/apps/http-proxy/includes/hicn/http-proxy/utils.h index 0df24dfd9..9865d8e4c 100644 --- a/apps/http-proxy/includes/hicn/http-proxy/utils.h +++ b/apps/http-proxy/includes/hicn/http-proxy/utils.h @@ -35,7 +35,7 @@ TRANSPORT_ALWAYS_INLINE std::string generatePrefix( str += pos; uint32_t locator_hash = utils::hash::fnv32_buf(str, strlen(str)); - uint16_t* word = (uint16_t*)&locator_hash; + const uint16_t* word = (const uint16_t*)&locator_hash; std::stringstream stream; stream << first_ipv6_word << ":0"; @@ -47,4 +47,4 @@ TRANSPORT_ALWAYS_INLINE std::string generatePrefix( stream << "::"; return stream.str(); -} \ No newline at end of file +} diff --git a/apps/http-proxy/main.cc b/apps/http-proxy/main.cc index 32be35bdb..832ec23e6 100644 --- a/apps/http-proxy/main.cc +++ b/apps/http-proxy/main.cc @@ -18,7 +18,7 @@ using namespace transport; -int usage(char* program) { +int usage(const char* program) { LoggerInfo() << "USAGE: " << program << "[-C|-S] [options] \n" << "Server or Client: \n" << " -P [FIRST_IPv6_WORD_HEX]\n" @@ -132,7 +132,6 @@ int main(int argc, char** argv) { case 't': params.n_thread = std::stoul(optarg); break; - case 'h': default: return usage(argv[0]); } @@ -150,4 +149,4 @@ int main(int argc, char** argv) { delete proxy; return 0; -} \ No newline at end of file +} diff --git a/apps/http-proxy/src/forwarder_interface.cc b/apps/http-proxy/src/forwarder_interface.cc index 205b290d8..717679e09 100644 --- a/apps/http-proxy/src/forwarder_interface.cc +++ b/apps/http-proxy/src/forwarder_interface.cc @@ -154,10 +154,9 @@ void ForwarderInterface::internalRemoveConnectedUser(uint32_t route_id) { hc_data_free(data); } -void ForwarderInterface::internalCreateFaceAndRoute(RouteInfoPtr route_info, - uint8_t max_try, - asio::steady_timer *timer, - SetRouteCallback callback) { +void ForwarderInterface::internalCreateFaceAndRoute( + RouteInfoPtr route_info, uint8_t max_try, asio::steady_timer *timer, + const SetRouteCallback &callback) { int ret = tryToCreateFaceAndRoute(route_info.get()); if (ret < 0 && max_try > 0) { @@ -186,7 +185,8 @@ void ForwarderInterface::internalCreateFaceAndRoute(RouteInfoPtr route_info, delete timer; } -int ForwarderInterface::tryToCreateFaceAndRoute(route_info_t *route_info) { +int ForwarderInterface::tryToCreateFaceAndRoute( + const route_info_t *route_info) { if (!sock_) return -1; hc_data_t *data; diff --git a/apps/http-proxy/src/http_1x_message_fast_parser.cc b/apps/http-proxy/src/http_1x_message_fast_parser.cc index e97c33161..ffae2368b 100644 --- a/apps/http-proxy/src/http_1x_message_fast_parser.cc +++ b/apps/http-proxy/src/http_1x_message_fast_parser.cc @@ -99,7 +99,8 @@ bool HTTPMessageFastParser::isMpdRequest(const uint8_t *headers, return false; } -uint32_t HTTPMessageFastParser::parseCacheControl(const uint8_t *headers, - std::size_t length) { +uint32_t HTTPMessageFastParser::parseCacheControl( + [[maybe_unused]] const uint8_t *headers, + [[maybe_unused]] std::size_t length) { return 0; } diff --git a/apps/http-proxy/src/http_proxy.cc b/apps/http-proxy/src/http_proxy.cc index b517ae30f..7419c7f7f 100644 --- a/apps/http-proxy/src/http_proxy.cc +++ b/apps/http-proxy/src/http_proxy.cc @@ -29,16 +29,15 @@ using interface::ConsumerInterestCallback; using interface::ConsumerSocket; using interface::TransportProtocolAlgorithms; -class HTTPClientConnectionCallback : interface::ConsumerSocket::ReadCallback { +class HTTPClientConnectionCallback + : public interface::ConsumerSocket::ReadCallback { public: HTTPClientConnectionCallback(TcpReceiver& tcp_receiver, utils::EventThread& thread) : tcp_receiver_(tcp_receiver), thread_(thread), prefix_hash_(tcp_receiver_.prefix_hash_), - consumer_(TransportProtocolAlgorithms::RAAQM, thread_), - session_(nullptr), - current_size_(0) { + consumer_(TransportProtocolAlgorithms::RAAQM, thread_) { consumer_.setSocketOption(ConsumerCallbacksOptions::READ_CALLBACK, this); consumer_.setSocketOption( ConsumerCallbacksOptions::INTEREST_OUTPUT, @@ -62,7 +61,7 @@ class HTTPClientConnectionCallback : interface::ConsumerSocket::ReadCallback { std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5), - [this](asio::ip::tcp::socket& socket) -> bool { + [this](const asio::ip::tcp::socket& socket) { try { std::string remote_address = socket.remote_endpoint().address().to_string(); @@ -136,10 +135,6 @@ class HTTPClientConnectionCallback : interface::ConsumerSocket::ReadCallback { current_size_ += size; if (is_last) { - // TRANSPORT_LOGD("Request received: %s", - // std::string((const char*)tmp_buffer_.first->data(), - // tmp_buffer_.first->length()) - // .c_str()); if (current_size_ < 1400) { request_buffer_queue_.emplace_back(std::move(tmp_buffer_)); } else { @@ -162,15 +157,16 @@ class HTTPClientConnectionCallback : interface::ConsumerSocket::ReadCallback { // hicn callbacks - void processLeavingInterest(interface::ConsumerSocket& c, - const core::Interest& interest) { + void processLeavingInterest( + [[maybe_unused]] const interface::ConsumerSocket& c, + const core::Interest& interest) { if (interest.getName().getSuffix() == 0 && interest.payloadSize() == 0) { Interest& int2 = const_cast(interest); int2.appendPayload(request_buffer_queue_.front().first->clone()); } } - void processInterestRetx(interface::ConsumerSocket& c, + void processInterestRetx([[maybe_unused]] const interface::ConsumerSocket& c, const core::Interest& interest) { if (interest.payloadSize() == 0) { Interest& int2 = const_cast(interest); @@ -179,15 +175,18 @@ class HTTPClientConnectionCallback : interface::ConsumerSocket::ReadCallback { } bool isBufferMovable() noexcept { return true; } - void getReadBuffer(uint8_t** application_buffer, size_t* max_length) {} - void readDataAvailable(size_t length) noexcept {} + void getReadBuffer(uint8_t** application_buffer, + size_t* max_length) { /*nothing to do*/ + } + void readDataAvailable(size_t length) noexcept { /*nothing to do*/ + } size_t maxBufferSize() const { return 64 * 1024; } void readBufferAvailable(std::unique_ptr&& buffer) noexcept { // Response received. Send it back to client auto _buffer = buffer.release(); // TRANSPORT_LOGD("From hicn: %zu bytes.", _buffer->length()); - session_->send(_buffer, []() {}); + session_->send(_buffer, []() { /*nothing to do*/ }); } void readError(const std::error_code& ec) noexcept { @@ -218,7 +217,9 @@ class HTTPClientConnectionCallback : interface::ConsumerSocket::ReadCallback { } } else { tcp_receiver_.parseHicnHeader( - it->second, [this](bool result, std::string configured_prefix) { + it->second, + [this](bool result, + [[maybe_unused]] const std::string& configured_prefix) { const char* reply = nullptr; if (result) { reply = HTTPMessageFastParser::http_ok; @@ -238,16 +239,15 @@ class HTTPClientConnectionCallback : interface::ConsumerSocket::ReadCallback { } } - private: TcpReceiver& tcp_receiver_; utils::EventThread& thread_; std::string& prefix_hash_; ConsumerSocket consumer_; - std::unique_ptr session_; + std::unique_ptr session_ = nullptr; std::deque, std::string>> request_buffer_queue_; std::pair, std::string> tmp_buffer_; - std::size_t current_size_; + std::size_t current_size_ = 0; }; TcpReceiver::TcpReceiver(std::uint16_t port, const std::string& prefix, @@ -260,8 +260,7 @@ TcpReceiver::TcpReceiver(std::uint16_t port, const std::string& prefix, ipv6_first_word_(ipv6_first_word), prefix_hash_(generatePrefix(prefix_, ipv6_first_word_)), forwarder_config_( - thread_.getIoService(), - [this](const std::error_code& ec) { + thread_.getIoService(), [this](const std::error_code& ec) { if (!ec) { listener_.doAccept(); for (int i = 0; i < 10; i++) { @@ -269,8 +268,7 @@ TcpReceiver::TcpReceiver(std::uint16_t port, const std::string& prefix, new HTTPClientConnectionCallback(*this, thread_)); } } - }), - stopped_(false) { + }) { forwarder_config_.tryToConnectToForwarder(); } @@ -349,7 +347,6 @@ void HTTPProxy::stop() { HTTPProxy::HTTPProxy(ClientParams& params, std::size_t n_thread) : signals_(main_io_context_, SIGINT, SIGQUIT) { for (uint16_t i = 0; i < n_thread; i++) { - // icn_receivers_.emplace_back(std::make_unique(icn_params)); receivers_.emplace_back(std::make_unique( params.tcp_listen_port, params.prefix, params.first_ipv6_word)); } diff --git a/apps/http-proxy/src/http_session.cc b/apps/http-proxy/src/http_session.cc index def4c61cf..06a81dc27 100644 --- a/apps/http-proxy/src/http_session.cc +++ b/apps/http-proxy/src/http_session.cc @@ -21,22 +21,16 @@ namespace transport { -HTTPSession::HTTPSession(asio::io_service &io_service, std::string &ip_address, - std::string &port, - ContentReceivedCallback receive_callback, - OnConnectionClosed on_connection_closed_callback, - bool client) +HTTPSession::HTTPSession( + asio::io_service &io_service, const std::string &ip_address, + const std::string &port, const ContentReceivedCallback &receive_callback, + const OnConnectionClosed &on_connection_closed_callback, bool client) : io_service_(io_service), socket_(io_service_), resolver_(io_service_), endpoint_iterator_(resolver_.resolve({ip_address, port})), timer_(io_service), reverse_(client), - is_reconnection_(false), - data_available_(false), - content_length_(0), - is_last_chunk_(false), - chunked_(false), receive_callback_(receive_callback), on_connection_closed_callback_(on_connection_closed_callback) { input_buffer_.prepare(buffer_size + 2048); @@ -51,10 +45,10 @@ HTTPSession::HTTPSession(asio::io_service &io_service, std::string &ip_address, doConnect(); } -HTTPSession::HTTPSession(asio::ip::tcp::socket socket, - ContentReceivedCallback receive_callback, - OnConnectionClosed on_connection_closed_callback, - bool client) +HTTPSession::HTTPSession( + asio::ip::tcp::socket socket, + const ContentReceivedCallback &receive_callback, + const OnConnectionClosed &on_connection_closed_callback, bool client) : #if ((ASIO_VERSION / 100 % 1000) < 12) io_service_(socket.get_io_service()), @@ -120,9 +114,7 @@ void HTTPSession::close() { if (state_ != ConnectorState::CLOSED) { state_ = ConnectorState::CLOSED; if (socket_.is_open()) { - // socket_.shutdown(asio::ip::tcp::socket::shutdown_type::shutdown_both); socket_.close(); - // on_disconnect_callback_(); } } } @@ -130,16 +122,17 @@ void HTTPSession::close() { void HTTPSession::doWrite() { auto &buffer = write_msgs_.front().first; - asio::async_write(socket_, asio::buffer(buffer->data(), buffer->length()), - [this](const std::error_code &ec, std::size_t length) { - if (TRANSPORT_EXPECT_FALSE(!ec)) { - write_msgs_.front().second(); - write_msgs_.pop_front(); - if (!write_msgs_.empty()) { - doWrite(); - } - } - }); + asio::async_write( + socket_, asio::buffer(buffer->data(), buffer->length()), + [this](const std::error_code &ec, [[maybe_unused]] std::size_t length) { + if (TRANSPORT_EXPECT_FALSE(!ec)) { + write_msgs_.front().second(); + write_msgs_.pop_front(); + if (!write_msgs_.empty()) { + doWrite(); + } + } + }); } // namespace transport void HTTPSession::handleRead(const std::error_code &ec, std::size_t length) { @@ -147,8 +140,8 @@ void HTTPSession::handleRead(const std::error_code &ec, std::size_t length) { content_length_ -= length; const uint8_t *buffer = asio::buffer_cast(input_buffer_.data()); - bool is_last = chunked_ ? (is_last_chunk_ ? !content_length_ : false) - : !content_length_; + bool check = is_last_chunk_ ? !content_length_ : false; + bool is_last = chunked_ ? check : !content_length_; receive_callback_(buffer, input_buffer_.size(), is_last, false, nullptr); input_buffer_.consume(input_buffer_.size()); @@ -274,7 +267,6 @@ void HTTPSession::tryReconnection() { is_reconnection_ = true; io_service_.post([this]() { if (socket_.is_open()) { - // socket_.shutdown(asio::ip::tcp::socket::shutdown_type::shutdown_both); socket_.close(); } startConnectionTimer(); @@ -295,8 +287,6 @@ void HTTPSession::doConnect() { asio::ip::tcp::no_delay noDelayOption(true); socket_.set_option(noDelayOption); - // on_reconnect_callback_(); - doReadHeader(); if (data_available_ && !write_msgs_.empty()) { diff --git a/apps/http-proxy/src/icn_receiver.cc b/apps/http-proxy/src/icn_receiver.cc index c97524906..c8904aa95 100644 --- a/apps/http-proxy/src/icn_receiver.cc +++ b/apps/http-proxy/src/icn_receiver.cc @@ -33,18 +33,15 @@ AsyncConsumerProducer::AsyncConsumerProducer( const std::string& mtu, const std::string& content_lifetime, bool manifest) : prefix_(core::Prefix(generatePrefix(prefix, first_ipv6_word), 64)), io_service_(io_service), - external_io_service_(true), - producer_socket_(), ip_address_(origin_address), port_(origin_port), cache_size_((uint32_t)std::stoul(cache_size)), mtu_((uint32_t)std::stoul(mtu)), - request_counter_(0), connector_(io_service_, ip_address_, port_, std::bind(&AsyncConsumerProducer::publishContent, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4), - [this](asio::ip::tcp::socket& socket) -> bool { + [this]([[maybe_unused]] const asio::ip::tcp::socket& socket) { std::queue empty; std::swap(response_name_queue_, empty); @@ -100,7 +97,7 @@ void AsyncConsumerProducer::stop() { void AsyncConsumerProducer::doReceive() { producer_socket_.setSocketOption( interface::ProducerCallbacksOptions::CACHE_MISS, - [this](interface::ProducerSocket& producer, + [this]([[maybe_unused]] const interface::ProducerSocket& producer, interface::Interest& interest) { if (interest.payloadSize() > 0) { // Interest may contain http request @@ -149,7 +146,8 @@ void AsyncConsumerProducer::manageIncomingInterest( response_name_queue_.emplace(std::move(name), is_mpd ? 1000 : default_content_lifetime_); - connector_.send(payload, [packet = std::move(packet)]() {}); + connector_.send(payload, + [packet = std::move(packet)]() { /*nothing to do*/ }); } void AsyncConsumerProducer::publishContent(const uint8_t* data, @@ -162,7 +160,7 @@ void AsyncConsumerProducer::publishContent(const uint8_t* data, abort(); } - interface::PublicationOptions& options = response_name_queue_.front(); + const interface::PublicationOptions& options = response_name_queue_.front(); int ret = producer_socket_.setSocketOption( interface::GeneralTransportOptions::CONTENT_OBJECT_EXPIRY_TIME, diff --git a/apps/ping/src/ping_client.cc b/apps/ping/src/ping_client.cc index b3495ed20..08938734b 100644 --- a/apps/ping/src/ping_client.cc +++ b/apps/ping/src/ping_client.cc @@ -28,8 +28,7 @@ #include #include -#define SYN_STATE 1 -#define ACK_STATE 2 +static constexpr uint32_t SYN_STATE = 1; namespace transport { @@ -63,7 +62,7 @@ class Configuration { Configuration() = default; }; -class Client : private interface::Portal::TransportCallback { +class Client : public interface::Portal::TransportCallback { public: explicit Client(Configuration *c) : signals_(io_service_, SIGINT), @@ -222,6 +221,8 @@ class Client : private interface::Portal::TransportCallback { case HICN_PACKET_FORMAT_IPV6_TCP: checkFamily(format, interest_name.getAddressFamily()); break; + default: + throw std::runtime_error("Bad packet format"); } /* @@ -319,9 +320,11 @@ static std::unordered_map const {"ipv6_tcp", HICN_PACKET_FORMAT_IPV6_TCP}, {"new", HICN_PACKET_FORMAT_NEW}}; -#define TO_LOWER(s) \ - std::transform(s.begin(), s.end(), s.begin(), \ +std::string str_tolower(std::string s) { + std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return std::tolower(c); }); + return s; +} void help() { LoggerInfo() << "usage: hicn-consumer-ping [options]"; @@ -409,14 +412,13 @@ int start(int argc, char *argv[]) { break; case 'w': { std::string packet_format_s = std::string(optarg); - TO_LOWER(packet_format_s); + packet_format_s = str_tolower(packet_format_s); auto it = packet_format_map.find(std::string(optarg)); if (it == packet_format_map.end()) throw std::runtime_error("Bad packet format"); c->packet_format_ = it->second; break; } - case 'H':; default: help(); exit(EXIT_FAILURE); diff --git a/apps/ping/src/ping_server.cc b/apps/ping/src/ping_server.cc index 8156866dd..900da18ca 100644 --- a/apps/ping/src/ping_server.cc +++ b/apps/ping/src/ping_server.cc @@ -70,9 +70,9 @@ class CallbackContainer { } public: - CallbackContainer(const Name &prefix, uint32_t object_size, + CallbackContainer([[maybe_unused]] const Name &prefix, uint32_t object_size, auth::Signer *signer, bool sign, std::string passphrase, - uint32_t lifetime) + [[maybe_unused]] uint32_t lifetime) : buffer_(object_size, 'X'), signer_(signer), sign_(sign) { // Verifier for interest manifests if (!passphrase.empty()) @@ -113,7 +113,8 @@ class CallbackContainer { auto content_object = createContentObject(name, lifetime, interest); p.produce(*content_object); } else { // Interest manifest - uint32_t _, *suffix = NULL; + uint32_t _; + const uint32_t *suffix = NULL; UNUSED(_); interest_manifest_foreach_suffix(interest.getIntManifestHeader(), suffix, @@ -158,7 +159,7 @@ void help() { LoggerInfo() << "-H prints this message"; } -int main(int argc, char **argv) { +int ping_main(int argc, char **argv) { transport::interface::global_config::GlobalConfigInterface global_conf; #ifdef _WIN32 WSADATA wsaData = {0}; @@ -216,7 +217,6 @@ int main(int argc, char **argv) { case 'F': conf_file = optarg; break; - case 'H': default: help(); exit(EXIT_FAILURE); @@ -297,5 +297,5 @@ int main(int argc, char **argv) { } // end namespace transport int main(int argc, char **argv) { - return transport::interface::main(argc, argv); + return transport::interface::ping_main(argc, argv); } -- cgit 1.2.3-korg