aboutsummaryrefslogtreecommitdiffstats
path: root/apps/http-proxy/includes/hicn
diff options
context:
space:
mode:
Diffstat (limited to 'apps/http-proxy/includes/hicn')
-rw-r--r--apps/http-proxy/includes/hicn/http-proxy/CMakeLists.txt5
-rw-r--r--apps/http-proxy/includes/hicn/http-proxy/forwarder_config.h27
-rw-r--r--apps/http-proxy/includes/hicn/http-proxy/forwarder_interface.h36
-rw-r--r--apps/http-proxy/includes/hicn/http-proxy/http_1x_message_fast_parser.h2
-rw-r--r--apps/http-proxy/includes/hicn/http-proxy/http_proxy.h70
-rw-r--r--apps/http-proxy/includes/hicn/http-proxy/http_session.h42
-rw-r--r--apps/http-proxy/includes/hicn/http-proxy/icn_receiver.h17
-rw-r--r--apps/http-proxy/includes/hicn/http-proxy/utils.h11
8 files changed, 105 insertions, 105 deletions
diff --git a/apps/http-proxy/includes/hicn/http-proxy/CMakeLists.txt b/apps/http-proxy/includes/hicn/http-proxy/CMakeLists.txt
index 5cc80a168..18f5704d1 100644
--- a/apps/http-proxy/includes/hicn/http-proxy/CMakeLists.txt
+++ b/apps/http-proxy/includes/hicn/http-proxy/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2017-2019 Cisco and/or its affiliates.
+# Copyright (c) 2021 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:
@@ -24,7 +24,7 @@ list(APPEND HEADER_FILES
set(HEADER_FILES ${HEADER_FILES} PARENT_SCOPE)
set(LIBPROXY_INCLUDE_DIRS
- ${CMAKE_CURRENT_SOURCE_DIR}/../.. ""
+ ${CMAKE_CURRENT_SOURCE_DIR}/../..
CACHE INTERNAL
"" FORCE
)
@@ -34,4 +34,3 @@ set(LIBPROXY_TO_INSTALL_HEADER_FILES
CACHE INTERNAL
"" FORCE
)
-
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 e02b9d9a7..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) 2020 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>
@@ -60,15 +60,14 @@ class ForwarderConfig {
doTryToConnectToForwarder(std::make_error_code(std::errc(0)));
}
- void doTryToConnectToForwarder(std::error_code ec) {
+ void doTryToConnectToForwarder(const std::error_code& ec) {
if (!ec) {
// ec == 0 --> timer expired
int ret = forwarder_interface_.connectToForwarder();
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,19 +78,18 @@ 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.";
}
}
- void doGetMainListener(std::error_code ec) {
+ void doGetMainListener(const std::error_code& ec) {
if (!ec) {
// ec == 0 --> timer expired
int ret = forwarder_interface_.getMainListenerPort();
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.";
}
}
@@ -114,7 +111,7 @@ class ForwarderConfig {
TRANSPORT_ALWAYS_INLINE bool parseHicnHeader(std::string& header,
Callback&& callback) {
std::stringstream ss(header);
- route_info_t* ret = new route_info_t();
+ RouteInfoPtr ret = std::make_shared<route_info_t>();
std::string port_string;
while (ss.good()) {
@@ -174,9 +171,9 @@ class ForwarderConfig {
ret->family = AF_INET;
std::string _prefix = ret->route_addr;
forwarder_interface_.createFaceAndRoute(
- RouteInfoPtr(ret), [callback = std::forward<Callback>(callback),
- configured_prefix = std::move(_prefix)](
- uint32_t route_id, bool result) {
+ std::move(ret), [callback = std::forward<Callback>(callback),
+ configured_prefix = std::move(_prefix)](
+ uint32_t route_id, bool result) {
callback(result, configured_prefix);
});
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 54941a4ba..ae9562a12 100644
--- a/apps/http-proxy/includes/hicn/http-proxy/forwarder_interface.h
+++ b/apps/http-proxy/includes/hicn/http-proxy/forwarder_interface.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020 Cisco and/or its affiliates.
+ * Copyright (c) 2021 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:
@@ -23,8 +23,15 @@ extern "C" {
#ifndef ASIO_STANDALONE
#define ASIO_STANDALONE 1
#endif
-#include <asio.hpp>
-#include <asio/steady_timer.hpp>
+
+#ifdef __APPLE__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wshorten-64-to-32"
+#endif
+#include <hicn/transport/core/asio_wrapper.h>
+#ifdef __APPLE__
+#pragma clang diagnostic pop
+#endif
#include <functional>
#include <thread>
#include <unordered_map>
@@ -45,16 +52,11 @@ using RouteInfoPtr = std::shared_ptr<route_info_t>;
class ForwarderInterface {
public:
- ForwarderInterface(asio::io_service &io_service)
+ explicit ForwarderInterface(asio::io_service &io_service)
: external_ioservice_(io_service),
work_(std::make_unique<asio::io_service::work>(internal_ioservice_)),
- sock_(nullptr),
thread_(std::make_unique<std::thread>(
- [this]() { internal_ioservice_.run(); })),
- check_routes_timer_(nullptr),
- pending_add_route_counter_(0),
- route_id_(0),
- closed_(false) {}
+ [this]() { internal_ioservice_.run(); })) {}
~ForwarderInterface();
@@ -88,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<asio::io_service::work> work_;
- hc_sock_t *sock_;
+ hc_sock_t *sock_ = nullptr;
std::unique_ptr<std::thread> thread_;
std::unordered_map<uint32_t, RouteInfoPtr> route_status_;
- std::unique_ptr<asio::steady_timer> check_routes_timer_;
- uint32_t pending_add_route_counter_;
- uint32_t route_id_;
- bool closed_;
+ std::unique_ptr<asio::steady_timer> 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_1x_message_fast_parser.h b/apps/http-proxy/includes/hicn/http-proxy/http_1x_message_fast_parser.h
index 7c035c83b..87a5c7d4e 100644
--- a/apps/http-proxy/includes/hicn/http-proxy/http_1x_message_fast_parser.h
+++ b/apps/http-proxy/includes/hicn/http-proxy/http_1x_message_fast_parser.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021 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:
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 a4139a620..567ab4540 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) 2020 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>
@@ -22,7 +23,9 @@
#include "http_session.h"
#include "icn_receiver.h"
+#ifndef ASIO_STANDALONE
#define ASIO_STANDALONE
+#endif
#include <asio.hpp>
#include <asio/version.hpp>
#include <unordered_set>
@@ -31,7 +34,8 @@ class TcpListener {
public:
using AcceptCallback = std::function<void(asio::ip::tcp::socket&&)>;
- 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),
@@ -46,13 +50,12 @@ class TcpListener {
acceptor_.listen();
}
- public:
void doAccept() {
#if ((ASIO_VERSION / 100 % 1000) >= 12)
acceptor_.async_accept(
- [this](std::error_code ec, asio::ip::tcp::socket socket) {
+ [this](const std::error_code& ec, asio::ip::tcp::socket socket) {
#else
- acceptor_.async_accept(socket_, [this](std::error_code ec) {
+ acceptor_.async_accept(socket_, [this](const std::error_code& ec) {
auto socket = std::move(socket_);
#endif
if (!ec) {
@@ -77,7 +80,7 @@ class HTTPClientConnectionCallback;
class Receiver {
public:
- Receiver() : thread_() {}
+ Receiver() {}
virtual ~Receiver() = default;
void stopAndJoinThread() { thread_.stop(); }
virtual void stop() = 0;
@@ -112,13 +115,13 @@ class TcpReceiver : public Receiver {
std::deque<HTTPClientConnectionCallback*> http_clients_;
std::unordered_set<HTTPClientConnectionCallback*> used_http_clients_;
ForwarderConfig forwarder_config_;
- bool stopped_;
+ bool stopped_ = false;
};
class IcnReceiver : public Receiver {
public:
template <typename... Args>
- IcnReceiver(Args&&... args)
+ explicit IcnReceiver(Args&&... args)
: Receiver(),
icn_consum_producer_(thread_.getIoService(),
std::forward<Args>(args)...) {
@@ -145,20 +148,18 @@ class HTTPProxy {
std::string prefix;
std::string first_ipv6_word;
- virtual void printParams() { std::cout << "Parameters: " << std::endl; };
+ virtual ~CommonParams() {}
+ 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;
}
};
@@ -171,25 +172,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;
}
};
@@ -207,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 f4a3dbdee..1b7df96a6 100644
--- a/apps/http-proxy/includes/hicn/http-proxy/http_session.h
+++ b/apps/http-proxy/includes/hicn/http-proxy/http_session.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021 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:
@@ -17,13 +17,19 @@
#include <hicn/transport/core/packet.h>
-#include "http_1x_message_fast_parser.h"
-
-#define ASIO_STANDALONE
-#include <asio.hpp>
+#ifdef __APPLE__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wshorten-64-to-32"
+#endif
+#include <hicn/transport/core/asio_wrapper.h>
+#ifdef __APPLE__
+#pragma clang diagnostic pop
+#endif
#include <deque>
#include <functional>
+#include "http_1x_message_fast_parser.h"
+
namespace transport {
using asio::ip::tcp;
@@ -67,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();
@@ -97,8 +106,7 @@ class HTTPSession {
bool checkConnected();
- private:
- void handleRead(std::error_code ec, std::size_t length);
+ void handleRead(const std::error_code &ec, std::size_t length);
void tryReconnection();
void startConnectionTimer();
void handleDeadline(const std::error_code &ec);
@@ -114,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 780037665..e3ab97fdd 100644
--- a/apps/http-proxy/includes/hicn/http-proxy/icn_receiver.h
+++ b/apps/http-proxy/includes/hicn/http-proxy/icn_receiver.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021 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,20 +13,18 @@
* limitations under the License.
*/
+#include <hicn/http-proxy/http_session.h>
+#include <hicn/transport/core/asio_wrapper.h>
#include <hicn/transport/core/prefix.h>
#include <hicn/transport/interfaces/publication_options.h>
#include <hicn/transport/interfaces/socket_producer.h>
#include <hicn/transport/utils/spinlock.h>
-#include <asio.hpp>
#include <cassert>
#include <cstring>
#include <queue>
#include <utility>
-#include <hicn/http-proxy/http_session.h>
-//#include "http_session.h"
-
namespace transport {
class AsyncConsumerProducer {
@@ -49,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();
@@ -73,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_;
@@ -81,9 +77,8 @@ class AsyncConsumerProducer {
uint32_t cache_size_;
uint32_t mtu_;
- uint64_t request_counter_;
+ uint64_t request_counter_ = 0;
- // std::unordered_map<core::Name, std::shared_ptr<ATSConnector>>
// 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 d87c796d0..9865d8e4c 100644
--- a/apps/http-proxy/includes/hicn/http-proxy/utils.h
+++ b/apps/http-proxy/includes/hicn/http-proxy/utils.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020 Cisco and/or its affiliates.
+ * Copyright (c) 2021 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:
@@ -35,17 +35,16 @@ TRANSPORT_ALWAYS_INLINE std::string generatePrefix(
str += pos;
uint32_t locator_hash = utils::hash::fnv32_buf(str, strlen(str));
+ const uint16_t* word = (const uint16_t*)&locator_hash;
std::stringstream stream;
stream << first_ipv6_word << ":0";
- for (uint16_t* word = (uint16_t*)&locator_hash;
- std::size_t(word) < (std::size_t(&locator_hash) + sizeof(locator_hash));
- word++) {
- stream << ":" << std::hex << *word;
+ for (std::size_t i = 0; i < sizeof(locator_hash) / 2; i++) {
+ stream << ":" << std::hex << word[i];
}
stream << "::";
return stream.str();
-} \ No newline at end of file
+}