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 --- .../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 ++-- 5 files changed, 34 insertions(+), 40 deletions(-) (limited to 'apps/http-proxy/includes/hicn/http-proxy') 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 +} -- cgit 1.2.3-korg