diff options
author | Michele Papalini <micpapal@cisco.com> | 2023-02-01 17:25:21 +0100 |
---|---|---|
committer | Michele Papalini <micpapal@cisco.com> | 2023-02-02 14:56:22 +0100 |
commit | b96d1545a8d2a173dc5911ed0bca3e04dbb02176 (patch) | |
tree | a69893191b0f7d52c10135e8b0c7702378ffee69 /apps/http-proxy/src | |
parent | f72846be51c7fd70310ea166cfc2ffbdc930f0e6 (diff) |
fix(apps): fix issues reported by sonarqube
Ref: HICN-836
Signed-off-by: Michele Papalini <micpapal@cisco.com>
Change-Id: Ie76771ca75bd224084ce3c893aba661b97064419
Diffstat (limited to 'apps/http-proxy/src')
-rw-r--r-- | apps/http-proxy/src/forwarder_interface.cc | 10 | ||||
-rw-r--r-- | apps/http-proxy/src/http_1x_message_fast_parser.cc | 5 | ||||
-rw-r--r-- | apps/http-proxy/src/http_proxy.cc | 45 | ||||
-rw-r--r-- | apps/http-proxy/src/http_session.cc | 52 | ||||
-rw-r--r-- | apps/http-proxy/src/icn_receiver.cc | 12 |
5 files changed, 55 insertions, 69 deletions
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&>(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&>(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<utils::MemBuf>&& 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<HTTPSession> session_; + std::unique_ptr<HTTPSession> session_ = nullptr; std::deque<std::pair<std::unique_ptr<utils::MemBuf>, std::string>> request_buffer_queue_; std::pair<std::unique_ptr<utils::MemBuf>, 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<IcnReceiver>(icn_params)); receivers_.emplace_back(std::make_unique<TcpReceiver>( 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<const uint8_t *>(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<interface::PublicationOptions> 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, |