diff options
Diffstat (limited to 'apps/http-proxy/src')
-rw-r--r-- | apps/http-proxy/src/forwarder_interface.cc | 8 | ||||
-rw-r--r-- | apps/http-proxy/src/http_proxy.cc | 48 | ||||
-rw-r--r-- | apps/http-proxy/src/http_session.cc | 12 | ||||
-rw-r--r-- | apps/http-proxy/src/icn_receiver.cc | 24 |
4 files changed, 43 insertions, 49 deletions
diff --git a/apps/http-proxy/src/forwarder_interface.cc b/apps/http-proxy/src/forwarder_interface.cc index 5566eb6ff..205b290d8 100644 --- a/apps/http-proxy/src/forwarder_interface.cc +++ b/apps/http-proxy/src/forwarder_interface.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -14,8 +14,8 @@ */ #include <arpa/inet.h> +#include <hicn/apps/utils/logger.h> #include <hicn/http-proxy/forwarder_interface.h> -#include <hicn/transport/utils/log.h> #include <chrono> #include <iostream> @@ -120,7 +120,7 @@ void ForwarderInterface::internalRemoveConnectedUser(uint32_t route_id) { for (unsigned i = 0; i < routes_to_remove.size(); i++) { connids_to_remove.insert(routes_to_remove[i]->face_id); if (hc_route_delete(sock_, routes_to_remove[i]) < 0) { - TRANSPORT_LOG_ERROR << "Error removing route from forwarder."; + LoggerErr() << "Error removing route from forwarder."; } } @@ -147,7 +147,7 @@ void ForwarderInterface::internalRemoveConnectedUser(uint32_t route_id) { for (unsigned i = 0; i < conns_to_remove.size(); i++) { if (hc_connection_delete(sock_, conns_to_remove[i]) < 0) { - TRANSPORT_LOG_ERROR << "Error removing connection from forwarder."; + LoggerErr() << "Error removing connection from forwarder."; } } diff --git a/apps/http-proxy/src/http_proxy.cc b/apps/http-proxy/src/http_proxy.cc index 5abe8780f..b517ae30f 100644 --- a/apps/http-proxy/src/http_proxy.cc +++ b/apps/http-proxy/src/http_proxy.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -13,11 +13,11 @@ * limitations under the License. */ +#include <hicn/apps/utils/logger.h> #include <hicn/http-proxy/http_proxy.h> #include <hicn/http-proxy/http_session.h> #include <hicn/http-proxy/utils.h> #include <hicn/transport/core/interest.h> -#include <hicn/transport/utils/log.h> #include <hicn/transport/utils/string_utils.h> namespace transport { @@ -67,10 +67,10 @@ class HTTPClientConnectionCallback : interface::ConsumerSocket::ReadCallback { std::string remote_address = socket.remote_endpoint().address().to_string(); std::uint16_t remote_port = socket.remote_endpoint().port(); - TRANSPORT_LOG_INFO << "Client " << remote_address << ":" - << remote_port << "disconnected."; + LoggerInfo() << "Client " << remote_address << ":" << remote_port + << "disconnected."; } catch (asio::system_error& e) { - TRANSPORT_LOG_INFO << "Client disconnected."; + LoggerInfo() << "Client disconnected."; } consumer_.stop(); @@ -143,17 +143,16 @@ class HTTPClientConnectionCallback : interface::ConsumerSocket::ReadCallback { if (current_size_ < 1400) { request_buffer_queue_.emplace_back(std::move(tmp_buffer_)); } else { - TRANSPORT_LOG_ERROR << "Ignoring client request due to size (" - << current_size_ << ") > 1400."; + LoggerErr() << "Ignoring client request due to size (" << current_size_ + << ") > 1400."; session_->close(); current_size_ = 0; return; } if (!consumer_.isRunning()) { - TRANSPORT_LOG_INFO - << "Consumer stopped, triggering consume from TCP session " - "handler.."; + LoggerInfo() << "Consumer stopped, triggering consume from TCP session " + "handler.."; consumeNextRequest(); } @@ -192,8 +191,7 @@ class HTTPClientConnectionCallback : interface::ConsumerSocket::ReadCallback { } void readError(const std::error_code& ec) noexcept { - TRANSPORT_LOG_ERROR - << "Error reading from hicn consumer socket. Closing session."; + LoggerErr() << "Error reading from hicn consumer socket. Closing session."; session_->close(); } @@ -213,10 +211,9 @@ class HTTPClientConnectionCallback : interface::ConsumerSocket::ReadCallback { session_->send((const uint8_t*)HTTPMessageFastParser::http_cors, std::strlen(HTTPMessageFastParser::http_cors), [this]() { auto& socket = session_->socket_; - TRANSPORT_LOG_INFO - << "Sent OPTIONS to client " - << socket.remote_endpoint().address() << ":" - << socket.remote_endpoint().port(); + LoggerInfo() << "Sent OPTIONS to client " + << socket.remote_endpoint().address() + << ":" << socket.remote_endpoint().port(); }); } } else { @@ -230,14 +227,13 @@ class HTTPClientConnectionCallback : interface::ConsumerSocket::ReadCallback { } /* Route created. Send back a 200 OK to client */ - session_->send((const uint8_t*)reply, std::strlen(reply), - [this, result]() { - auto& socket = session_->socket_; - TRANSPORT_LOG_INFO - << "Sent " << result << " response to client " - << socket.remote_endpoint().address() << ":" - << socket.remote_endpoint().port(); - }); + session_->send( + (const uint8_t*)reply, std::strlen(reply), [this, result]() { + auto& socket = session_->socket_; + LoggerInfo() << "Sent " << result << " response to client " + << socket.remote_endpoint().address() << ":" + << socket.remote_endpoint().port(); + }); }); } } @@ -331,8 +327,8 @@ void TcpReceiver::onNewConnection(asio::ip::tcp::socket&& socket) { void HTTPProxy::setupSignalHandler() { signals_.async_wait([this](const std::error_code& ec, int signal_number) { if (!ec) { - TRANSPORT_LOG_INFO << "Received signal " << signal_number - << ". Stopping gracefully."; + LoggerInfo() << "Received signal " << signal_number + << ". Stopping gracefully."; stop(); } }); diff --git a/apps/http-proxy/src/http_session.cc b/apps/http-proxy/src/http_session.cc index 870f188cd..def4c61cf 100644 --- a/apps/http-proxy/src/http_session.cc +++ b/apps/http-proxy/src/http_session.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -13,9 +13,9 @@ * limitations under the License. */ +#include <hicn/apps/utils/logger.h> #include <hicn/http-proxy/http_proxy.h> #include <hicn/transport/utils/branch_prediction.h> -#include <hicn/transport/utils/log.h> #include <iostream> @@ -269,7 +269,7 @@ void HTTPSession::doReadHeader() { void HTTPSession::tryReconnection() { if (on_connection_closed_callback_(socket_)) { if (state_ == ConnectorState::CONNECTED) { - TRANSPORT_LOG_ERROR << "Connection lost. Trying to reconnect..."; + LoggerErr() << "Connection lost. Trying to reconnect..."; state_ = ConnectorState::CONNECTING; is_reconnection_ = true; io_service_.post([this]() { @@ -306,11 +306,11 @@ void HTTPSession::doConnect() { if (is_reconnection_) { is_reconnection_ = false; - TRANSPORT_LOG_INFO << "Connection recovered!"; + LoggerInfo() << "Connection recovered!"; } } else { - TRANSPORT_LOG_ERROR << "Impossible to reconnect: " << ec.message(); + LoggerErr() << "Impossible to reconnect: " << ec.message(); close(); } }); @@ -330,7 +330,7 @@ void HTTPSession::handleDeadline(const std::error_code &ec) { if (!ec) { io_service_.post([this]() { socket_.close(); - TRANSPORT_LOG_ERROR << "Error connecting. Is the server running?"; + LoggerErr() << "Error connecting. Is the server running?"; io_service_.stop(); }); } diff --git a/apps/http-proxy/src/icn_receiver.cc b/apps/http-proxy/src/icn_receiver.cc index f15851915..c97524906 100644 --- a/apps/http-proxy/src/icn_receiver.cc +++ b/apps/http-proxy/src/icn_receiver.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -13,13 +13,13 @@ * limitations under the License. */ +#include <hicn/apps/utils/logger.h> #include <hicn/http-proxy/http_1x_message_fast_parser.h> #include <hicn/http-proxy/icn_receiver.h> #include <hicn/http-proxy/utils.h> #include <hicn/transport/core/interest.h> #include <hicn/transport/http/default_values.h> #include <hicn/transport/utils/hash.h> -#include <hicn/transport/utils/log.h> #include <functional> #include <memory> @@ -55,28 +55,28 @@ AsyncConsumerProducer::AsyncConsumerProducer( interface::GeneralTransportOptions::OUTPUT_BUFFER_SIZE, cache_size_); if (ret != SOCKET_OPTION_SET) { - TRANSPORT_LOG_WARNING << "Warning: output buffer size has not been set."; + LoggerWarn() << "Warning: output buffer size has not been set."; } ret = producer_socket_.setSocketOption( interface::GeneralTransportOptions::MANIFEST_MAX_CAPACITY, manifest); if (ret != SOCKET_OPTION_SET) { - TRANSPORT_LOG_WARNING << "Warning: impossible to enable signatures."; + LoggerWarn() << "Warning: impossible to enable signatures."; } ret = producer_socket_.setSocketOption( interface::GeneralTransportOptions::DATA_PACKET_SIZE, mtu_); if (ret != SOCKET_OPTION_SET) { - TRANSPORT_LOG_WARNING << "Warning: mtu has not been set."; + LoggerWarn() << "Warning: mtu has not been set."; } producer_socket_.registerPrefix(prefix_); } void AsyncConsumerProducer::start() { - TRANSPORT_LOG_INFO << "Starting listening"; + LoggerInfo() << "Starting listening"; doReceive(); } @@ -90,8 +90,8 @@ void AsyncConsumerProducer::run() { void AsyncConsumerProducer::stop() { io_service_.post([this]() { - TRANSPORT_LOG_INFO << "Number of requests processed by plugin: " - << request_counter_; + LoggerInfo() << "Number of requests processed by plugin: " + << request_counter_; producer_socket_.stop(); connector_.close(); }); @@ -158,7 +158,7 @@ void AsyncConsumerProducer::publishContent(const uint8_t* data, uint32_t start_suffix = 0; if (response_name_queue_.empty()) { - std::cerr << "Aborting due tue empty request queue" << std::endl; + LoggerErr() << "Aborting due tue empty request queue"; abort(); } @@ -169,16 +169,14 @@ void AsyncConsumerProducer::publishContent(const uint8_t* data, options.getLifetime()); if (TRANSPORT_EXPECT_FALSE(ret != SOCKET_OPTION_SET)) { - TRANSPORT_LOG_WARNING - << "Warning: content object lifetime has not been set."; + LoggerWarn() << "Warning: content object lifetime has not been set."; } const interface::Name& name = options.getName(); auto it = chunk_number_map_.find(name); if (it == chunk_number_map_.end()) { - std::cerr << "Aborting due to response not found in ResposeInfo map." - << std::endl; + LoggerErr() << "Aborting due to response not found in ResposeInfo map."; abort(); } |