diff options
Diffstat (limited to 'apps/http-proxy')
-rw-r--r-- | apps/http-proxy/CMakeLists.txt | 6 | ||||
-rw-r--r-- | apps/http-proxy/includes/hicn/http-proxy/forwarder_config.h | 15 | ||||
-rw-r--r-- | apps/http-proxy/includes/hicn/http-proxy/http_proxy.h | 51 | ||||
-rw-r--r-- | apps/http-proxy/main.cc | 58 | ||||
-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 |
8 files changed, 105 insertions, 117 deletions
diff --git a/apps/http-proxy/CMakeLists.txt b/apps/http-proxy/CMakeLists.txt index 5acf09c19..80f671567 100644 --- a/apps/http-proxy/CMakeLists.txt +++ b/apps/http-proxy/CMakeLists.txt @@ -72,6 +72,8 @@ build_library(${LIBHTTP_PROXY} STATIC SOURCES ${LIB_SOURCE_FILES} LINK_LIBRARIES ${HTTP_PROXY_LIBRARIES} + INCLUDE_DIRS + PRIVATE ${THIRD_PARTY_INCLUDE_DIRS} ${COMMON_INCLUDE_DIRS} DEPENDS ${DEPENDENCIES} INSTALL_HEADERS ${LIBPROXY_TO_INSTALL_HEADER_FILES} INCLUDE_DIRS @@ -91,7 +93,9 @@ if (NOT DISABLE_EXECUTABLES) build_executable(${HTTP_PROXY} SOURCES ${APP_SOURCE_FILES} LINK_LIBRARIES ${LIBHTTP_PROXY_STATIC} - DEPENDS ${LIBHTTP_PROXY_STATIC} + INCLUDE_DIRS + PRIVATE ${THIRD_PARTY_INCLUDE_DIRS} ${COMMON_INCLUDE_DIRS} + DEPENDS ${LIBHTTP_PROXY_STATIC} ${THIRD_PARTY_DEPENDENCIES} COMPONENT ${HICN_APPS} LINK_FLAGS ${LINK_FLAGS} COMPILE_OPTIONS ${COMPILER_OPTIONS} diff --git a/apps/http-proxy/includes/hicn/http-proxy/forwarder_config.h b/apps/http-proxy/includes/hicn/http-proxy/forwarder_config.h index 935b85e78..14e0068ed 100644 --- a/apps/http-proxy/includes/hicn/http-proxy/forwarder_config.h +++ b/apps/http-proxy/includes/hicn/http-proxy/forwarder_config.h @@ -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: @@ -15,9 +15,9 @@ #pragma once +#include <hicn/apps/utils/logger.h> #include <hicn/transport/portability/c_portability.h> #include <hicn/transport/utils/branch_prediction.h> -#include <hicn/transport/utils/log.h> #include <hicn/transport/utils/string_utils.h> #include <asio.hpp> @@ -67,8 +67,7 @@ class ForwarderConfig { if (ret < 0) { // We were not able to connect to the local forwarder. Do not give up // and retry. - TRANSPORT_LOG_ERROR - << "Could not connect to local forwarder. Retrying."; + LoggerErr() << "Could not connect to local forwarder. Retrying."; timer_.expires_from_now(std::chrono::milliseconds(RETRY_INTERVAL)); timer_.async_wait(std::bind(&ForwarderConfig::doTryToConnectToForwarder, @@ -79,8 +78,7 @@ class ForwarderConfig { doGetMainListener(std::make_error_code(std::errc(0))); } } else { - TRANSPORT_LOG_ERROR - << "Timer for re-trying forwarder connection canceled."; + LoggerErr() << "Timer for re-trying forwarder connection canceled."; } } @@ -91,7 +89,7 @@ class ForwarderConfig { if (ret <= 0) { // Since without the main listener of the forwarder the proxy cannot // work, we can stop the program here until we get the listener port. - TRANSPORT_LOG_ERROR + LoggerErr() << "Could not retrieve main listener port from the forwarder. " "Retrying."; @@ -105,8 +103,7 @@ class ForwarderConfig { listener_retrieved_callback_(std::make_error_code(std::errc(0))); } } else { - TRANSPORT_LOG_ERROR - << "Timer for retrieving main hicn listener canceled."; + LoggerErr() << "Timer for retrieving main hicn listener canceled."; } } 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 efb9f850e..1fa96956a 100644 --- a/apps/http-proxy/includes/hicn/http-proxy/http_proxy.h +++ b/apps/http-proxy/includes/hicn/http-proxy/http_proxy.h @@ -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: @@ -15,6 +15,7 @@ #pragma once +#include <hicn/apps/utils/logger.h> #include <hicn/transport/interfaces/socket_consumer.h> #include <hicn/transport/utils/event_thread.h> @@ -147,20 +148,17 @@ class HTTPProxy { std::string prefix; std::string first_ipv6_word; - virtual void printParams() { std::cout << "Parameters: " << std::endl; }; + virtual void printParams() { LoggerInfo() << "Parameters: "; }; }; struct ClientParams : virtual CommonParams { short tcp_listen_port; void printParams() override { - std::cout << "Running HTTP/TCP -> HTTP/hICN proxy." << std::endl; + LoggerInfo() << "Running HTTP/TCP -> HTTP/hICN proxy."; CommonParams::printParams(); - std::cout << "\t" - << "HTTP listen port: " << tcp_listen_port << std::endl; - std::cout << "\t" - << "Consumer Prefix: " << prefix << std::endl; - std::cout << "\t" - << "Prefix first word: " << first_ipv6_word << std::endl; + LoggerInfo() << "\tHTTP listen port: " << tcp_listen_port; + LoggerInfo() << "\tConsumer Prefix: " << prefix; + LoggerInfo() << "\tPrefix first word: " << first_ipv6_word; } }; @@ -173,25 +171,24 @@ class HTTPProxy { bool manifest; void printParams() override { - std::cout << "Running HTTP/hICN -> HTTP/TCP proxy." << std::endl; + LoggerInfo() << "Running HTTP/hICN -> HTTP/TCP proxy."; CommonParams::printParams(); - std::cout << "\t" - << "Origin address: " << origin_address << std::endl; - std::cout << "\t" - << "Origin port: " << origin_port << std::endl; - std::cout << "\t" - << "Producer cache size: " << cache_size << std::endl; - std::cout << "\t" - << "hICN MTU: " << mtu << std::endl; - std::cout << "\t" - << "Default content lifetime: " << content_lifetime - << std::endl; - std::cout << "\t" - << "Producer Prefix: " << prefix << std::endl; - std::cout << "\t" - << "Prefix first word: " << first_ipv6_word << std::endl; - std::cout << "\t" - << "Use manifest: " << manifest << std::endl; + LoggerInfo() << "\t" + << "Origin address: " << origin_address; + LoggerInfo() << "\t" + << "Origin port: " << origin_port; + LoggerInfo() << "\t" + << "Producer cache size: " << cache_size; + LoggerInfo() << "\t" + << "hICN MTU: " << mtu; + LoggerInfo() << "\t" + << "Default content lifetime: " << content_lifetime; + LoggerInfo() << "\t" + << "Producer Prefix: " << prefix; + LoggerInfo() << "\t" + << "Prefix first word: " << first_ipv6_word; + LoggerInfo() << "\t" + << "Use manifest: " << manifest; } }; diff --git a/apps/http-proxy/main.cc b/apps/http-proxy/main.cc index 9bd97e02e..32be35bdb 100644 --- a/apps/http-proxy/main.cc +++ b/apps/http-proxy/main.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,32 +13,31 @@ * limitations under the License. */ +#include <hicn/apps/utils/logger.h> #include <hicn/http-proxy/http_proxy.h> using namespace transport; int usage(char* program) { - std::cerr << "USAGE: " << program << "[-C|-S] [options] <http_prefix>\n" - << "Server or Client: \n" - << " -P [FIRST_IPv6_WORD_HEX]\n" - << " -t [number of threads]\n" - << "Client Options: \n" - << " -L [PROXY_LISTEN_PORT]\n" - << "Server Options: \n" - << " -a [ORIGIN_IP_ADDRESS]\n" - << " -p [ORIGIN_PORT]\n" - << " -c [CACHE_SIZE]\n" - << " -m [MTU]" - << " -l [DEFAULT_CONTENT_LIFETIME] (seconds)\n" - << " -M (enable manifest)\n" - << std::endl - << "Example Server:\n" - << " " << program - << " -S -a example.com -p 80 -c 10000 -m 1300 -l 7200 -M -t 1 " - "http://httpserver\n" - << "Example Client:\n" - << " " << program << " -C -L 9091 http://httpserver\n" - << std::endl; + LoggerInfo() << "USAGE: " << program << "[-C|-S] [options] <http_prefix>\n" + << "Server or Client: \n" + << " -P [FIRST_IPv6_WORD_HEX]\n" + << " -t [number of threads]\n" + << "Client Options: \n" + << " -L [PROXY_LISTEN_PORT]\n" + << "Server Options: \n" + << " -a [ORIGIN_IP_ADDRESS]\n" + << " -p [ORIGIN_PORT]\n" + << " -c [CACHE_SIZE]\n" + << " -m [MTU]" + << " -l [DEFAULT_CONTENT_LIFETIME] (seconds)\n" + << " -M (enable manifest)\n"; + LoggerInfo() << "Example Server:\n" + << " " << program + << " -S -a example.com -p 80 -c 10000 -m 1300 -l 7200 -M -t 1 " + "http://httpserver\n" + << "Example Client:\n" + << " " << program << " -C -L 9091 http://httpserver\n"; return -1; } @@ -53,8 +52,7 @@ struct Params : HTTPProxy::ClientParams, HTTPProxy::ServerParams { "Proxy configured as client and server at the same time."); } - std::cout << "\t" - << "N Threads: " << n_thread << std::endl; + LoggerInfo() << "\tN Threads: " << n_thread; } HTTPProxy* instantiateProxyAsValue() { @@ -93,18 +91,16 @@ int main(int argc, char** argv) { switch (opt) { case 'C': if (params.server) { - std::cerr << "Cannot be both client and server (both -C anc -S " - "options specified.)." - << std::endl; + LoggerErr() << "Cannot be both client and server (both -C anc -S " + "options specified.)."; return usage(argv[0]); } params.client = true; break; case 'S': if (params.client) { - std::cerr << "Cannot be both client and server (both -C anc -S " - "options specified.)." - << std::endl; + LoggerErr() << "Cannot be both client and server (both -C anc -S " + "options specified.)."; return usage(argv[0]); } params.server = true; @@ -143,7 +139,7 @@ int main(int argc, char** argv) { } if (argv[optind] == 0) { - std::cerr << "Using default prefix " << params.prefix << std::endl; + LoggerInfo() << "Using default prefix " << params.prefix; } else { params.prefix = argv[optind]; } 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(); } |