aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorAlberto Compagno <acompagn+fdio@cisco.com>2019-03-23 15:14:39 +0000
committerGerrit Code Review <gerrit@fd.io>2019-03-23 15:14:39 +0000
commitdfc988a222a38da36999395e393e3b1ed1ccdfde (patch)
tree73a34d2f778f8cae62d3a72d38aa63f8c2a28d80 /apps
parenta2bdc00ea25f89185c1095a48a8f51cb2c1a20e6 (diff)
parent1ad06afe9f952642a26f4d28239cf05eb3283eb7 (diff)
Merge "[HICN-6] ATS Working, little refactoring of apps"
Diffstat (limited to 'apps')
-rw-r--r--apps/CMakeLists.txt11
-rw-r--r--apps/README.md30
-rw-r--r--apps/higet/CMakeLists.txt (renamed from apps/src/higet/CMakeLists.txt)20
-rw-r--r--apps/higet/higet.cc (renamed from apps/src/higet/higet.cc)48
-rw-r--r--apps/http-proxy/CMakeLists.txt66
-rw-r--r--apps/http-proxy/main.cc65
-rw-r--r--apps/http-proxy/src/ATSConnector.cc224
-rw-r--r--apps/http-proxy/src/ATSConnector.h99
-rw-r--r--apps/http-proxy/src/HTTP1.xMessageFastParser.cc71
-rw-r--r--apps/http-proxy/src/HTTP1.xMessageFastParser.h34
-rw-r--r--apps/http-proxy/src/IcnReceiver.cc174
-rw-r--r--apps/http-proxy/src/IcnReceiver.h69
-rw-r--r--apps/http-server/CMakeLists.txt (renamed from apps/src/http-server/CMakeLists.txt)74
-rw-r--r--apps/http-server/http-client/http_client.h (renamed from apps/src/http-server/http-client/http_client.h)6
-rw-r--r--apps/http-server/http-client/http_client_icn.cc (renamed from apps/src/http-server/http-client/http_client_icn.cc)2
-rw-r--r--apps/http-server/http-client/http_client_icn.h (renamed from apps/src/http-server/http-client/http_client_icn.h)2
-rw-r--r--apps/http-server/http-client/http_client_tcp.cc (renamed from apps/src/http-server/http-client/http_client_tcp.cc)2
-rw-r--r--apps/http-server/http-client/http_client_tcp.h (renamed from apps/src/http-server/http-client/http_client_tcp.h)2
-rw-r--r--apps/http-server/http-server.cc (renamed from apps/src/http-server/http-server.cc)113
-rw-r--r--apps/http-server/http-server/common.h (renamed from apps/src/http-server/http-server/common.h)11
-rw-r--r--apps/http-server/http-server/configuration.cc (renamed from apps/src/http-server/http-server/configuration.cc)2
-rw-r--r--apps/http-server/http-server/configuration.h (renamed from apps/src/http-server/http-server/configuration.h)2
-rw-r--r--apps/http-server/http-server/content.cc (renamed from apps/src/http-server/http-server/content.cc)2
-rw-r--r--apps/http-server/http-server/content.h (renamed from apps/src/http-server/http-server/content.h)2
-rw-r--r--apps/http-server/http-server/http_server.cc (renamed from apps/src/http-server/http-server/http_server.cc)49
-rw-r--r--apps/http-server/http-server/http_server.h (renamed from apps/src/http-server/http-server/http_server.h)45
-rw-r--r--apps/http-server/http-server/icn_request.cc (renamed from apps/src/http-server/http-server/icn_request.cc)2
-rw-r--r--apps/http-server/http-server/icn_request.h (renamed from apps/src/http-server/http-server/icn_request.h)2
-rw-r--r--apps/http-server/http-server/icn_response.cc (renamed from apps/src/http-server/http-server/icn_response.cc)2
-rw-r--r--apps/http-server/http-server/icn_response.h (renamed from apps/src/http-server/http-server/icn_response.h)2
-rw-r--r--apps/http-server/http-server/request.cc (renamed from apps/src/http-server/http-server/request.cc)2
-rw-r--r--apps/http-server/http-server/request.h (renamed from apps/src/http-server/http-server/request.h)2
-rw-r--r--apps/http-server/http-server/response.cc (renamed from apps/src/http-server/http-server/response.cc)2
-rw-r--r--apps/http-server/http-server/response.h (renamed from apps/src/http-server/http-server/response.h)2
-rw-r--r--apps/http-server/http-server/socket_request.cc29
-rw-r--r--apps/http-server/http-server/socket_request.h (renamed from apps/src/http-server/config.h.in)18
-rw-r--r--apps/http-server/http-server/socket_response.cc43
-rw-r--r--apps/http-server/http-server/socket_response.h38
-rw-r--r--apps/src/http-server/http-server/socket_request.cc38
-rw-r--r--apps/src/http-server/http-server/socket_request.h40
-rw-r--r--apps/src/http-server/http-server/socket_response.cc52
-rw-r--r--apps/src/http-server/http-server/socket_response.h47
42 files changed, 1138 insertions, 408 deletions
diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt
index 8907dfe5b..766c9c7e5 100644
--- a/apps/CMakeLists.txt
+++ b/apps/CMakeLists.txt
@@ -26,7 +26,6 @@ include(BuildMacros)
include(WindowsMacros)
find_package(Asio REQUIRED)
-find_package(CURL REQUIRED)
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
find_package(Libtransport REQUIRED)
@@ -35,26 +34,24 @@ if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
else()
set(LIBTRANSPORT_LIBRARIES ${LIBTRANSPORT_SHARED})
list(APPEND DEPENDENCIES
- ${LIBHICN}
- ${LIBHICN_SHARED}
${LIBTRANSPORT_LIBRARIES}
)
endif()
list(APPEND LIBRARIES
${LIBTRANSPORT_LIBRARIES}
- ${CURL_LIBRARY}
${CMAKE_THREAD_LIBS_INIT}
)
include(Packaging)
-set (COMPILER_DEFINITIONS "")
+set(COMPILER_DEFINITIONS "")
if (WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4200 /wd4996")
endif ()
-add_subdirectory(src/http-server)
-add_subdirectory(src/higet) \ No newline at end of file
+add_subdirectory(http-server)
+add_subdirectory(http-proxy)
+add_subdirectory(higet) \ No newline at end of file
diff --git a/apps/README.md b/apps/README.md
index 1311006f6..937d02248 100644
--- a/apps/README.md
+++ b/apps/README.md
@@ -65,6 +65,36 @@ Options:
-z <hicn_proxy_prefix> = hicn proxy prefix
```
+### hicn-http-proxy ###
+
+`hicn-http-proxy` is a reverse proxy which can be used for augmenting the performance of a legacy HTTP/TCP server
+by making use of hICN. It performs the following operations:
+
+- Receives a HTTP request over hICN
+- Forwards it to a HTTP server over TCP
+- Receives the response from the server and publishes it
+
+Subsequently, other hICN client asking for the same HTTP message can retrieve it directly
+through hICN, by retrieving it either from the forwarder caches or directly from the `hicn-http-proxy`.
+
+The proxy uses hICN names for performing the multiplexing of http requests, allowing a single
+hICN proxy with a single producer socket to serve multiple consumers asking for the same content. Conversely, a normal
+TCP proxy still needs to open one TCP connection per client.
+
+```
+hicn-http-proxy [HTTP_PREFIX] [OPTIONS]
+
+HTTP_PREFIX: The prefix used for building the hicn names.
+
+Options:
+-a <server_address> = origin server address
+-p <server_port> = origin server port
+-c <cache_size> = cache size of the proxy, in number of hicn data packets
+
+Example:
+./hicn-http-proxy http://webserver -a 127.0.0.1 -p 8080 -c 10000
+```
+
## License ##
This software is distributed under the following license:
diff --git a/apps/src/higet/CMakeLists.txt b/apps/higet/CMakeLists.txt
index a144d4c08..5dcae66b2 100644
--- a/apps/src/higet/CMakeLists.txt
+++ b/apps/higet/CMakeLists.txt
@@ -26,16 +26,10 @@ list(APPEND APPS_SRC
higet.cc
)
-
-foreach(app ${APPS_SRC})
- get_filename_component(_app_name ${app} NAME)
- string(REGEX REPLACE ".cc" "" app_name ${_app_name})
-
- build_executable(${app_name}
- SOURCES ${app}
- LINK_LIBRARIES ${LIBTRANSPORT_LIBRARIES} ${WSOCK32_LIBRARY} ${WS2_32_LIBRARY}
- DEPENDS ${LIBTRANSPORT}
- COMPONENT ${HICN_APPS}
- DEFINITIONS ${COMPILER_DEFINITIONS}
- )
-endforeach()
+build_executable(higet
+ SOURCES ${APPS_SRC}
+ LINK_LIBRARIES ${LIBTRANSPORT_LIBRARIES} ${WSOCK32_LIBRARY} ${WS2_32_LIBRARY}
+ DEPENDS ${LIBTRANSPORT}
+ COMPONENT higet
+ DEFINITIONS ${COMPILER_DEFINITIONS}
+)
diff --git a/apps/src/higet/higet.cc b/apps/higet/higet.cc
index 1d1379887..7662c1a2b 100644
--- a/apps/src/higet/higet.cc
+++ b/apps/higet/higet.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Copyright (c) 2019 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:
@@ -25,8 +25,6 @@ Time t1;
#define DEFAULT_BETA 0.99
#define DEFAULT_GAMMA 0.07
-namespace hicnet {
-
namespace http {
typedef struct {
@@ -37,7 +35,6 @@ typedef struct {
void processResponse(Configuration &conf,
transport::http::HTTPResponse &&response) {
-
auto &payload = response.getPayload();
if (conf.file_name != "-") {
@@ -74,7 +71,6 @@ void processResponse(Configuration &conf,
of.close();
Time t2 = std::chrono::system_clock::now();
- ;
TimeDuration dt =
std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1);
TimeDuration dt3 =
@@ -90,8 +86,10 @@ void usage(char *program_name) {
std::cerr << "usage:" << std::endl;
std::cerr << program_name << " [option]... [url]..." << std::endl;
std::cerr << program_name << "options:" << std::endl;
- std::cerr << "-O <output_path> = write documents to <output_file>" << std::endl;
- std::cerr << "-S = print server response" << std::endl;
+ std::cerr << "-O <output_path> = write documents to <output_file>"
+ << std::endl;
+ std::cerr << "-S = print server response"
+ << std::endl;
std::cerr << "example:" << std::endl;
std::cerr << "\t" << program_name << " -O - http://origin/index.html"
<< std::endl;
@@ -99,7 +97,6 @@ void usage(char *program_name) {
}
int main(int argc, char **argv) {
-
#ifdef _WIN32
WSADATA wsaData = {0};
WSAStartup(MAKEWORD(2, 2), &wsaData);
@@ -115,19 +112,19 @@ int main(int argc, char **argv) {
int opt;
while ((opt = getopt(argc, argv, "O:Sc:")) != -1) {
switch (opt) {
- case 'O':
- conf.file_name = optarg;
- break;
- case 'S':
- conf.print_headers = true;
- break;
- case 'c':
- conf.producer_certificate = optarg;
- break;
- case 'h':
- default:
- usage(argv[0]);
- break;
+ case 'O':
+ conf.file_name = optarg;
+ break;
+ case 'S':
+ conf.print_headers = true;
+ break;
+ case 'c':
+ conf.producer_certificate = optarg;
+ break;
+ case 'h':
+ default:
+ usage(argv[0]);
+ break;
}
}
@@ -142,7 +139,8 @@ int main(int argc, char **argv) {
}
std::map<std::string, std::string> headers = {{"Host", "localhost"},
- {"User-Agent", "higet/1.0"}};
+ {"User-Agent", "higet/1.0"},
+ {"Connection", "Keep-Alive"}};
transport::http::HTTPClientConnection connection;
if (!conf.producer_certificate.empty()) {
@@ -161,8 +159,6 @@ int main(int argc, char **argv) {
return EXIT_SUCCESS;
}
-} // end namespace http
-
-} // end namespace hicnet
+} // end namespace http
-int main(int argc, char **argv) { return hicnet::http::main(argc, argv); }
+int main(int argc, char **argv) { return http::main(argc, argv); }
diff --git a/apps/http-proxy/CMakeLists.txt b/apps/http-proxy/CMakeLists.txt
new file mode 100644
index 000000000..3d6b9c672
--- /dev/null
+++ b/apps/http-proxy/CMakeLists.txt
@@ -0,0 +1,66 @@
+# Copyright (c) 2019 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:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
+set(CMAKE_CXX_STANDARD 14)
+
+if (NOT CMAKE_BUILD_TYPE)
+ message(STATUS "No build type selected, default to Release")
+ set(CMAKE_BUILD_TYPE "Release")
+endif()
+
+set(CMAKE_MODULE_PATH
+ ${CMAKE_MODULE_PATH}
+ "${CMAKE_SOURCE_DIR}/cmake/Modules/"
+)
+
+find_package(Threads REQUIRED)
+include_directories(
+ SYSTEM
+ ${CMAKE_BINARY_DIR}
+ ${LIB${TRANSPORT_LIBRARY}_INCLUDE_DIR}
+ http-server
+ http-client
+)
+
+set(LIB_SOURCE_FILES
+ src/ATSConnector.cc
+ src/HTTP1.xMessageFastParser.cc
+ src/IcnReceiver.cc
+)
+
+set(LIB_SERVER_HEADER_FILES
+ src/IcnReceiver.h
+ src/ATSConnector.h
+ src/HTTP1.xMessageFastParser.h
+)
+
+set(APP_SOURCE_FILES
+ main.cc
+)
+
+build_library(httpproxylib
+ STATIC
+ SOURCES ${LIB_SOURCE_FILES}
+ LINK_LIBRARIES ${LIBRARIES}
+ DEPENDS ${DEPENDENCIES}
+ INCLUDE_DIRS ${LIBTRANSPORT_INCLUDE_DIRS}
+)
+
+build_executable(hicn-http-proxy
+ SOURCES ${APP_SOURCE_FILES}
+ LINK_LIBRARIES httpproxylib
+ DEPENDS httpproxylib
+ COMPONENT hicn-http-proxy
+ DEFINITIONS ${COMPILER_DEFINITIONS}
+) \ No newline at end of file
diff --git a/apps/http-proxy/main.cc b/apps/http-proxy/main.cc
new file mode 100644
index 000000000..179da452b
--- /dev/null
+++ b/apps/http-proxy/main.cc
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2019 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:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "src/IcnReceiver.h"
+
+using namespace transport;
+
+int usage(char* program) {
+ std::cerr << "ICN Plugin not loaded!" << std::endl;
+ std::cerr << "USAGE: " << program
+ << "[HTTP_PREFIX] -a [SERVER_IP_ADDRESS] "
+ "-p [SERVER_PORT] -c [CACHE_SIZE]"
+ << std::endl;
+ return -1;
+}
+
+int main(int argc, char** argv) {
+ std::string prefix("http://hicn-http-proxy");
+ std::string ip_address("127.0.0.1");
+ std::string port("80");
+ std::string cache_size("50000");
+
+ int opt;
+ while ((opt = getopt(argc, argv, "a:p:c:")) != -1) {
+ switch (opt) {
+ case 'a':
+ prefix = optarg;
+ break;
+ case 'p':
+ port = optarg;
+ break;
+ case 'c':
+ cache_size = optarg;
+ break;
+ case 'h':
+ default:
+ usage(argv[0]);
+ break;
+ }
+ }
+
+ if (argv[optind] == 0) {
+ std::cerr << "Using default prefix " << prefix << std::endl;
+ } else {
+ prefix = argv[optind];
+ }
+
+ transport::AsyncConsumerProducer proxy(prefix, ip_address, port, cache_size);
+
+ proxy.run();
+
+ return 0;
+} \ No newline at end of file
diff --git a/apps/http-proxy/src/ATSConnector.cc b/apps/http-proxy/src/ATSConnector.cc
new file mode 100644
index 000000000..81f7a776a
--- /dev/null
+++ b/apps/http-proxy/src/ATSConnector.cc
@@ -0,0 +1,224 @@
+/*
+ * Copyright (c) 2019 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:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "ATSConnector.h"
+#include "HTTP1.xMessageFastParser.h"
+
+#include <hicn/transport/utils/branch_prediction.h>
+#include <hicn/transport/utils/log.h>
+#include <iostream>
+
+namespace transport {
+
+ATSConnector::ATSConnector(asio::io_service &io_service,
+ std::string &ip_address, std::string &port,
+ ContentReceivedCallback receive_callback,
+ OnReconnect on_reconnect_callback)
+ : io_service_(io_service),
+ socket_(io_service_),
+ resolver_(io_service_),
+ endpoint_iterator_(resolver_.resolve({ip_address, port})),
+ timer_(io_service),
+ is_reconnection_(false),
+ data_available_(false),
+ receive_callback_(receive_callback),
+ on_reconnect_callback_(on_reconnect_callback) {
+ header_input_buffer_.prepare(2048);
+ state_ = ConnectorState::CONNECTING;
+ doConnect();
+}
+
+ATSConnector::~ATSConnector() {}
+
+void ATSConnector::send(const uint8_t *packet, std::size_t len,
+ ContentSentCallback &&content_sent) {
+ asio::async_write(
+ socket_, asio::buffer(packet, len),
+ [content_sent = std::move(content_sent)](
+ std::error_code ec, std::size_t /*length*/) { content_sent(); });
+}
+
+void ATSConnector::send(utils::MemBuf *buffer,
+ ContentSentCallback &&content_sent) {
+ io_service_.dispatch([this, buffer, callback = std::move(content_sent)]() {
+ bool write_in_progress = !write_msgs_.empty();
+ write_msgs_.emplace_back(std::unique_ptr<utils::MemBuf>(buffer),
+ std::move(callback));
+ if (TRANSPORT_EXPECT_TRUE(state_ == ConnectorState::CONNECTED)) {
+ if (!write_in_progress) {
+ doWrite();
+ }
+ } else {
+ TRANSPORT_LOGD(" Tell the handle connect it has data to write");
+ data_available_ = true;
+ }
+ });
+}
+
+void ATSConnector::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_();
+ }
+ }
+}
+
+void ATSConnector::doWrite() {
+ auto &buffer = write_msgs_.front().first;
+
+ asio::async_write(socket_, asio::buffer(buffer->data(), buffer->length()),
+ [this](std::error_code ec, std::size_t length) {
+ if (TRANSPORT_EXPECT_FALSE(!ec)) {
+ TRANSPORT_LOGD("Content successfully sent!");
+ write_msgs_.front().second();
+ write_msgs_.pop_front();
+ if (!write_msgs_.empty()) {
+ doWrite();
+ }
+ } else {
+ TRANSPORT_LOGD("Content NOT sent!");
+ }
+ });
+} // namespace transport
+
+void ATSConnector::handleRead(std::error_code ec, std::size_t length,
+ std::size_t size) {
+ if (TRANSPORT_EXPECT_TRUE(!ec)) {
+ std::size_t bytes_in_buffer = length;
+ size -= bytes_in_buffer;
+ receive_callback_(input_buffer_, bytes_in_buffer, !size, false);
+
+ if (!size) {
+ doReadHeader();
+ } else {
+ auto to_read = size >= buffer_size ? buffer_size : size;
+ asio::async_read(
+ socket_, asio::buffer(input_buffer_, to_read),
+ std::bind(&ATSConnector::handleRead, this, std::placeholders::_1,
+ std::placeholders::_2, size));
+ }
+ } else if (ec == asio::error::eof) {
+ tryReconnection();
+ }
+}
+
+void ATSConnector::doReadBody(std::size_t size) {
+ auto to_read = size >= buffer_size ? buffer_size : size;
+ asio::async_read(
+ socket_, asio::buffer(input_buffer_, to_read),
+ std::bind(&ATSConnector::handleRead, this, std::placeholders::_1,
+ std::placeholders::_2, size));
+}
+
+void ATSConnector::doReadHeader() {
+ asio::async_read_until(
+ socket_, header_input_buffer_, "\r\n\r\n",
+ [this](std::error_code ec, std::size_t length) {
+ if (TRANSPORT_EXPECT_TRUE(!ec)) {
+ // TRANSPORT_LOGD("Headers received");
+
+ const uint8_t *buffer =
+ asio::buffer_cast<const uint8_t *>(header_input_buffer_.data());
+ std::size_t size = HTTPMessageFastParser::hasBody(buffer, length);
+
+ auto additional_bytes = header_input_buffer_.size() - length;
+ auto bytes_to_read = size - additional_bytes;
+ receive_callback_(buffer, header_input_buffer_.size(), !bytes_to_read,
+ true);
+ header_input_buffer_.consume(header_input_buffer_.size());
+
+ if (bytes_to_read) {
+ doReadBody(bytes_to_read);
+ } else {
+ doReadHeader();
+ }
+ } else {
+ header_input_buffer_.consume(header_input_buffer_.size());
+ tryReconnection();
+ }
+ });
+}
+
+void ATSConnector::tryReconnection() {
+ TRANSPORT_LOGD("Connection lost. Trying to reconnect...\n");
+ if (state_ == ConnectorState::CONNECTED) {
+ state_ = ConnectorState::CONNECTING;
+ is_reconnection_ = true;
+ io_service_.post([this]() {
+ if (socket_.is_open()) {
+ socket_.shutdown(asio::ip::tcp::socket::shutdown_type::shutdown_both);
+ socket_.close();
+ }
+ startConnectionTimer();
+ doConnect();
+ });
+ }
+}
+
+void ATSConnector::doConnect() {
+ asio::async_connect(socket_, endpoint_iterator_,
+ [this](std::error_code ec, tcp::resolver::iterator) {
+ if (!ec) {
+ timer_.cancel();
+ state_ = ConnectorState::CONNECTED;
+
+ asio::ip::tcp::no_delay noDelayOption(true);
+ socket_.set_option(noDelayOption);
+
+ // on_reconnect_callback_();
+
+ doReadHeader();
+
+ if (data_available_ && !write_msgs_.empty()) {
+ data_available_ = false;
+ doWrite();
+ }
+
+ if (is_reconnection_) {
+ is_reconnection_ = false;
+ TRANSPORT_LOGD("Connection recovered!");
+ }
+
+ } else {
+ TRANSPORT_LOGE("Impossible to reconnect.");
+ close();
+ }
+ });
+}
+
+bool ATSConnector::checkConnected() {
+ return state_ == ConnectorState::CONNECTED;
+}
+
+void ATSConnector::startConnectionTimer() {
+ timer_.expires_from_now(std::chrono::seconds(10));
+ timer_.async_wait(
+ std::bind(&ATSConnector::handleDeadline, this, std::placeholders::_1));
+}
+
+void ATSConnector::handleDeadline(const std::error_code &ec) {
+ if (!ec) {
+ io_service_.post([this]() {
+ socket_.close();
+ TRANSPORT_LOGE("Error connecting. Is the server running?\n");
+ io_service_.stop();
+ });
+ }
+}
+
+} // namespace transport
diff --git a/apps/http-proxy/src/ATSConnector.h b/apps/http-proxy/src/ATSConnector.h
new file mode 100644
index 000000000..be5c2c8d5
--- /dev/null
+++ b/apps/http-proxy/src/ATSConnector.h
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2019 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:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <hicn/transport/core/packet.h>
+
+#define ASIO_STANDALONE
+#include <asio.hpp>
+#include <deque>
+#include <functional>
+
+namespace transport {
+
+using asio::ip::tcp;
+
+typedef std::function<void(const uint8_t *data, std::size_t size, bool is_last,
+ bool headers)>
+ ContentReceivedCallback;
+typedef std::function<void()> OnReconnect;
+typedef std::function<void()> ContentSentCallback;
+typedef std::deque<
+ std::pair<std::unique_ptr<utils::MemBuf>, ContentSentCallback>>
+ BufferQueue;
+
+class ATSConnector {
+ static constexpr uint32_t buffer_size = 1024 * 64;
+
+ enum class ConnectorState {
+ CLOSED,
+ CONNECTING,
+ CONNECTED,
+ };
+
+ public:
+ ATSConnector(asio::io_service &io_service, std::string &ip_address,
+ std::string &port, ContentReceivedCallback receive_callback,
+ OnReconnect on_reconnect_callback);
+
+ ~ATSConnector();
+
+ void send(const uint8_t *buffer, std::size_t len,
+ ContentSentCallback &&content_sent = 0);
+
+ void send(utils::MemBuf *buffer, ContentSentCallback &&content_sent);
+
+ void close();
+
+ private:
+ void doConnect();
+
+ void doReadHeader();
+
+ void doReadBody(std::size_t size);
+
+ void doWrite();
+
+ bool checkConnected();
+
+ private:
+ void handleRead(std::error_code ec, std::size_t length, std::size_t bytes);
+ void tryReconnection();
+ void startConnectionTimer();
+ void handleDeadline(const std::error_code &ec);
+
+ asio::io_service &io_service_;
+ asio::ip::tcp::socket socket_;
+ asio::ip::tcp::resolver resolver_;
+ asio::ip::tcp::resolver::iterator endpoint_iterator_;
+ asio::steady_timer timer_;
+
+ BufferQueue write_msgs_;
+
+ asio::streambuf header_input_buffer_;
+ uint8_t input_buffer_[buffer_size];
+
+ bool is_reconnection_;
+ bool data_available_;
+
+ ContentReceivedCallback receive_callback_;
+ OnReconnect on_reconnect_callback_;
+
+ // Connector state
+ ConnectorState state_;
+};
+
+} // namespace transport
diff --git a/apps/http-proxy/src/HTTP1.xMessageFastParser.cc b/apps/http-proxy/src/HTTP1.xMessageFastParser.cc
new file mode 100644
index 000000000..a03871649
--- /dev/null
+++ b/apps/http-proxy/src/HTTP1.xMessageFastParser.cc
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2019 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:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "HTTP1.xMessageFastParser.h"
+
+#include <experimental/algorithm>
+#include <experimental/functional>
+#include <iostream>
+
+std::string HTTPMessageFastParser::numbers = "0123456789";
+std::string HTTPMessageFastParser::content_length = "Content-Length";
+std::string HTTPMessageFastParser::cache_control = "Cache-Control";
+std::string HTTPMessageFastParser::mpd = "mpd";
+std::string HTTPMessageFastParser::connection = "Connection";
+std::string HTTPMessageFastParser::separator = "\r\n\r\n";
+
+std::size_t HTTPMessageFastParser::hasBody(const uint8_t *headers,
+ std::size_t length) {
+ const char *buffer = reinterpret_cast<const char *>(headers);
+ const char *begin = buffer;
+ const char *end = buffer + length;
+
+ using std::experimental::make_boyer_moore_searcher;
+ auto it = std::experimental::search(
+ begin, end,
+ make_boyer_moore_searcher(content_length.begin(), content_length.end()));
+
+ if (it != end) {
+ // Read header line
+ auto it2 = std::find_first_of(it, end, numbers.begin(), numbers.end());
+ auto it3 = std::find(it2, end, '\n');
+
+ return std::stoul(std::string(it2, it3));
+ }
+
+ return 0;
+}
+
+bool HTTPMessageFastParser::isMpdRequest(const uint8_t *headers,
+ std::size_t length) {
+ const char *buffer = reinterpret_cast<const char *>(headers);
+ const char *begin = buffer;
+ const char *end = buffer + length;
+
+ using std::experimental::make_boyer_moore_searcher;
+ auto it = std::experimental::search(
+ begin, end, make_boyer_moore_searcher(mpd.begin(), mpd.end()));
+
+ if (it != end) {
+ return true;
+ }
+
+ return false;
+}
+
+uint32_t HTTPMessageFastParser::parseCacheControl(const uint8_t *headers,
+ std::size_t length) {
+ return 0;
+}
diff --git a/apps/http-proxy/src/HTTP1.xMessageFastParser.h b/apps/http-proxy/src/HTTP1.xMessageFastParser.h
new file mode 100644
index 000000000..10a70c3e9
--- /dev/null
+++ b/apps/http-proxy/src/HTTP1.xMessageFastParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2019 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:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <algorithm>
+#include <string>
+
+class HTTPMessageFastParser {
+ public:
+ static std::size_t hasBody(const uint8_t* headers, std::size_t length);
+ static bool isMpdRequest(const uint8_t* headers, std::size_t length);
+ static uint32_t parseCacheControl(const uint8_t* headers, std::size_t length);
+
+ private:
+ static std::string numbers;
+ static std::string content_length;
+ static std::string cache_control;
+ static std::string connection;
+ static std::string mpd;
+ static std::string separator;
+};
diff --git a/apps/http-proxy/src/IcnReceiver.cc b/apps/http-proxy/src/IcnReceiver.cc
new file mode 100644
index 000000000..ee8ef0823
--- /dev/null
+++ b/apps/http-proxy/src/IcnReceiver.cc
@@ -0,0 +1,174 @@
+/*
+ * Copyright (c) 2019 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:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "IcnReceiver.h"
+#include "HTTP1.xMessageFastParser.h"
+
+#include <hicn/transport/http/default_values.h>
+#include <hicn/transport/utils/hash.h>
+
+#include <functional>
+#include <memory>
+
+namespace transport {
+
+core::Prefix generatePrefix(const std::string& prefix_url) {
+ const char* str = prefix_url.c_str();
+ uint16_t pos = 0;
+
+ if (strncmp("http://", str, 7) == 0) {
+ pos = 7;
+ } else if (strncmp("https://", str, 8) == 0) {
+ pos = 8;
+ }
+
+ str += pos;
+
+ uint32_t locator_hash = utils::hash::fnv32_buf(str, strlen(str));
+
+ std::stringstream stream;
+ stream << std::hex << http::default_values::ipv6_first_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;
+ }
+
+ stream << "::0";
+
+ return core::Prefix(stream.str(), 64);
+}
+
+AsyncConsumerProducer::AsyncConsumerProducer(const std::string& prefix,
+ std::string& ip_address,
+ std::string& port,
+ std::string& cache_size)
+ : prefix_(generatePrefix(prefix)),
+ producer_socket_(),
+ ip_address_(ip_address),
+ port_(port),
+ cache_size_(std::stoul(cache_size)),
+ request_counter_(0),
+ signals_(io_service_, SIGINT, SIGQUIT),
+ connector_(io_service_, ip_address_, port_,
+ std::bind(&AsyncConsumerProducer::publishContent, this,
+ std::placeholders::_1, std::placeholders::_2,
+ std::placeholders::_3, std::placeholders::_4),
+ [this]() {
+ std::queue<interface::PublicationOptions> empty;
+ std::swap(response_name_queue_, empty);
+ }) {
+ int ret = producer_socket_.setSocketOption(
+ interface::GeneralTransportOptions::OUTPUT_BUFFER_SIZE, cache_size_);
+
+ if (ret != SOCKET_OPTION_SET) {
+ TRANSPORT_LOGD("Warning: output buffer size has not been set.");
+ }
+
+ producer_socket_.registerPrefix(prefix_);
+
+ // Let the main thread to catch SIGINT and SIGQUIT
+ signals_.async_wait(
+ [this](const std::error_code& errorCode, int signal_number) {
+ TRANSPORT_LOGI("Number of requests processed by plugin: %lu",
+ (unsigned long)request_counter_);
+ producer_socket_.stop();
+ connector_.close();
+ });
+}
+
+void AsyncConsumerProducer::start() {
+ TRANSPORT_LOGD("Starting listening");
+ doReceive();
+}
+
+void AsyncConsumerProducer::run() {
+ start();
+ io_service_.run();
+}
+
+void AsyncConsumerProducer::doReceive() {
+ producer_socket_.setSocketOption(
+ interface::ProducerCallbacksOptions::CACHE_MISS,
+ [this](interface::ProducerSocket& producer,
+ interface::Interest& interest) {
+ // core::Name n(interest.getWritableName(), true);
+ io_service_.post(std::bind(
+ &AsyncConsumerProducer::manageIncomingInterest, this,
+ interest.getWritableName(), interest.acquireMemBufReference(),
+ interest.getPayload().release()));
+ });
+
+ producer_socket_.connect();
+}
+
+void AsyncConsumerProducer::manageIncomingInterest(
+ core::Name& name, core::Packet::MemBufPtr& packet, utils::MemBuf* payload) {
+ // auto seg = name.getSuffix();
+ name.setSuffix(0);
+ auto _it = chunk_number_map_.find(name);
+ auto _end = chunk_number_map_.end();
+
+ if (_it != _end) {
+ return;
+ }
+
+ bool is_mpd =
+ HTTPMessageFastParser::isMpdRequest(payload->data(), payload->length());
+
+ chunk_number_map_.emplace(name, 0);
+ response_name_queue_.emplace(std::move(name), is_mpd ? 500 : 10000);
+
+ connector_.send(payload, [packet = std::move(packet)]() {});
+}
+
+void AsyncConsumerProducer::publishContent(const uint8_t* data,
+ std::size_t size, bool is_last,
+ bool headers) {
+ uint32_t start_suffix = 0;
+
+ if (response_name_queue_.empty()) {
+ abort();
+ }
+
+ interface::PublicationOptions& options = response_name_queue_.front();
+
+ int ret = producer_socket_.setSocketOption(
+ interface::GeneralTransportOptions::CONTENT_OBJECT_EXPIRY_TIME,
+ options.getLifetime());
+
+ if (TRANSPORT_EXPECT_FALSE(ret != SOCKET_OPTION_SET)) {
+ TRANSPORT_LOGD("Warning: content object lifetime has not been set.");
+ }
+
+ const interface::Name& name = options.getName();
+
+ start_suffix = chunk_number_map_[name];
+
+ if (headers) {
+ request_counter_++;
+ }
+
+ chunk_number_map_[name] +=
+ producer_socket_.produce(name, data, size, is_last, start_suffix);
+
+ if (is_last) {
+ chunk_number_map_.erase(name);
+ response_name_queue_.pop();
+ }
+}
+
+} // namespace transport
diff --git a/apps/http-proxy/src/IcnReceiver.h b/apps/http-proxy/src/IcnReceiver.h
new file mode 100644
index 000000000..7d5c5e4c8
--- /dev/null
+++ b/apps/http-proxy/src/IcnReceiver.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2019 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:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "ATSConnector.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 <cassert>
+#include <cstring>
+#include <queue>
+#include <utility>
+
+namespace transport {
+
+class AsyncConsumerProducer {
+ public:
+ explicit AsyncConsumerProducer(const std::string& prefix,
+ std::string& ip_address, std::string& port,
+ std::string& cache_size);
+
+ void start();
+
+ void run();
+
+ private:
+ void doSend();
+
+ void doReceive();
+
+ void publishContent(const uint8_t* data, std::size_t size,
+ bool is_last = true, bool headers = false);
+
+ void manageIncomingInterest(core::Name& name, core::Packet::MemBufPtr& packet,
+ utils::MemBuf* payload);
+
+ core::Prefix prefix_;
+ asio::io_service io_service_;
+ interface::ProducerSocket producer_socket_;
+
+ std::string ip_address_;
+ std::string port_;
+ uint32_t cache_size_;
+
+ uint64_t request_counter_;
+ asio::signal_set signals_;
+
+ // std::unordered_map<core::Name, std::shared_ptr<ATSConnector>>
+ // connection_map_;
+ ATSConnector connector_;
+ std::unordered_map<core::Name, uint32_t> chunk_number_map_;
+ std::queue<interface::PublicationOptions> response_name_queue_;
+};
+
+} // namespace transport
diff --git a/apps/src/http-server/CMakeLists.txt b/apps/http-server/CMakeLists.txt
index a005f1a8f..94aa9d43a 100644
--- a/apps/src/http-server/CMakeLists.txt
+++ b/apps/http-server/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2017 Cisco and/or its affiliates.
+# Copyright (c) 2019 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:
@@ -11,50 +11,57 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-cmake_minimum_required(VERSION 3.2)
+cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
set(CMAKE_CXX_STANDARD 14)
-option(HICNET "Link against Libhicnet." ON)
-
-configure_file("${PROJECT_SOURCE_DIR}/src/http-server/config.h.in"
- "${CMAKE_BINARY_DIR}/apps/http-server/config.h")
+find_package(CURL REQUIRED)
+list(APPEND LIBRARIES
+ ${CURL_LIBRARY}
+)
set(LIB_SOURCE_FILES
- http-server/http_server.cc
- http-server/response.cc
- http-server/socket_response.cc
- http-server/icn_response.cc
- http-server/content.cc
- http-server/request.cc
- http-server/icn_request.cc
- http-server/socket_request.cc
- http-server/configuration.cc
- http-client/http_client_tcp.cc
- http-client/http_client_icn.cc)
+ http-server/http_server.cc
+ http-server/response.cc
+ http-server/socket_response.cc
+ http-server/icn_response.cc
+ http-server/content.cc
+ http-server/request.cc
+ http-server/icn_request.cc
+ http-server/socket_request.cc
+ http-server/configuration.cc
+ http-client/http_client_tcp.cc
+ http-client/http_client_icn.cc
+)
set(LIB_SERVER_HEADER_FILES
- http-server/http_server.h
- http-server/response.h
- http-server/common.h
- http-server/socket_response.h
- http-server/content.h
- http-server/request.h
- http-server/icn_request.h
- http-server/socket_request.h
- http-server/configuration.h
- ${CMAKE_BINARY_DIR}/apps/http-server/config.h
- http-server/icn_response.h)
+ http-server/http_server.h
+ http-server/response.h
+ http-server/common.h
+ http-server/socket_response.h
+ http-server/content.h
+ http-server/request.h
+ http-server/icn_request.h
+ http-server/socket_request.h
+ http-server/configuration.h
+ http-server/icn_response.h
+)
set(LIB_CLIENT_HEADER_FILES
- http-client/http_client_tcp.h
- http-client/http_client_icn.h
- http-client/http_client.h)
+ http-client/http_client_tcp.h
+ http-client/http_client_icn.h
+ http-client/http_client.h
+)
set(APP_SOURCE_FILES
- http-server.cc)
+ http-server.cc
+)
-include_directories(${CMAKE_BINARY_DIR}/apps/http-server http-server http-client)
+include_directories(
+ ${CMAKE_BINARY_DIR}/apps/http-server
+ http-server
+ http-client
+)
build_library(hicn-httpserver
STATIC
@@ -68,7 +75,6 @@ build_library(hicn-httpserver
DEFINITIONS ${COMPILER_DEFINITIONS}
)
-
build_executable(hicn-http-server
SOURCES ${APP_SOURCE_FILES}
LINK_LIBRARIES hicn-httpserver ${WSOCK32_LIBRARY} ${WS2_32_LIBRARY}
diff --git a/apps/src/http-server/http-client/http_client.h b/apps/http-server/http-client/http_client.h
index b2dbd1ffd..087a061ab 100644
--- a/apps/src/http-server/http-client/http_client.h
+++ b/apps/http-server/http-client/http_client.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Copyright (c) 2019 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,8 +15,6 @@
#pragma once
-#include "config.h"
-
#include <string>
#if defined(HICNET)
@@ -28,7 +26,7 @@
#endif
class HTTPClient {
-public:
+ public:
virtual ~HTTPClient() = default;
virtual void setTcp() = 0;
diff --git a/apps/src/http-server/http-client/http_client_icn.cc b/apps/http-server/http-client/http_client_icn.cc
index 862741bd9..327d2eed1 100644
--- a/apps/src/http-server/http-client/http_client_icn.cc
+++ b/apps/http-server/http-client/http_client_icn.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Copyright (c) 2019 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/src/http-server/http-client/http_client_icn.h b/apps/http-server/http-client/http_client_icn.h
index 8f5e9ae44..5586f6d62 100644
--- a/apps/src/http-server/http-client/http_client_icn.h
+++ b/apps/http-server/http-client/http_client_icn.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Copyright (c) 2019 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/src/http-server/http-client/http_client_tcp.cc b/apps/http-server/http-client/http_client_tcp.cc
index 08474d71c..530f8ef95 100644
--- a/apps/src/http-server/http-client/http_client_tcp.cc
+++ b/apps/http-server/http-client/http_client_tcp.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Copyright (c) 2019 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/src/http-server/http-client/http_client_tcp.h b/apps/http-server/http-client/http_client_tcp.h
index e1d81ada0..9433e8a36 100644
--- a/apps/src/http-server/http-client/http_client_tcp.h
+++ b/apps/http-server/http-client/http_client_tcp.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Copyright (c) 2019 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/src/http-server/http-server.cc b/apps/http-server/http-server.cc
index ec6aa19a1..9d3eac5b8 100644
--- a/apps/src/http-server/http-server.cc
+++ b/apps/http-server/http-server.cc
@@ -1,32 +1,23 @@
/*
- * The MIT License (MIT)
+ * Copyright (c) 2019 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:
*
- * Copyright (c) 2014-2016 Ole Christian Eidheim
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
-#include <fstream>
-#include <iostream>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <fstream>
+#include <iostream>
#ifndef _WIN32
#include <unistd.h>
@@ -48,32 +39,30 @@ namespace std {
int _isDirectory(const char *path) {
struct stat statbuf;
- if (stat(path, &statbuf) != 0)
- return -1;
+ if (stat(path, &statbuf) != 0) return -1;
return S_ISDIR(statbuf.st_mode);
}
int _isRegularFile(const char *path) {
struct stat statbuf;
- if (stat(path, &statbuf) != 0)
- return 0;
+ if (stat(path, &statbuf) != 0) return 0;
return S_ISREG(statbuf.st_mode);
}
string _getFileName(const string &strPath) {
size_t iLastSeparator = 0;
#ifdef _WIN32
- return strPath.substr((iLastSeparator = strPath.find_last_of("\\")) !=
- std::string::npos
- ? iLastSeparator + 1
- : 0,
- strPath.size() - strPath.find_last_of("."));
+ return strPath.substr(
+ (iLastSeparator = strPath.find_last_of("\\")) != std::string::npos
+ ? iLastSeparator + 1
+ : 0,
+ strPath.size() - strPath.find_last_of("."));
#else
- return strPath.substr((iLastSeparator = strPath.find_last_of("/")) !=
- std::string::npos
- ? iLastSeparator + 1
- : 0,
- strPath.size() - strPath.find_last_of("."));
+ return strPath.substr(
+ (iLastSeparator = strPath.find_last_of("/")) != std::string::npos
+ ? iLastSeparator + 1
+ : 0,
+ strPath.size() - strPath.find_last_of("."));
#endif
}
@@ -92,8 +81,7 @@ int _mkdir(const char *dir) {
snprintf(tmp, sizeof(tmp), "%s", dir);
len = strlen(tmp);
- if (tmp[len - 1] == sepChar)
- tmp[len - 1] = 0;
+ if (tmp[len - 1] == sepChar) tmp[len - 1] = 0;
for (p = tmp + 1; *p; p++) {
if (*p == sepChar) {
*p = 0;
@@ -125,11 +113,11 @@ int _mkdir(const char *dir) {
string _getExtension(const string &strPath) {
size_t iLastSeparator = 0;
- return strPath.substr((iLastSeparator = strPath.find_last_of(".")) !=
- std::string::npos
- ? iLastSeparator + 1
- : 0,
- strPath.size());
+ return strPath.substr(
+ (iLastSeparator = strPath.find_last_of(".")) != std::string::npos
+ ? iLastSeparator + 1
+ : 0,
+ strPath.size());
}
void default_resource_send(const HttpServer &server,
@@ -202,25 +190,25 @@ int main(int argc, char **argv) {
while ((opt = getopt(argc, argv, "p:l:o:hx:z:")) != -1) {
switch (opt) {
- case 'p':
- root_folder = optarg;
- break;
- case 'l':
- webserver_prefix = optarg;
- break;
- case 'x':
- tcp_proxy_address = optarg;
- break;
- case 'o':
- port = atoi(optarg);
- break;
- case 'z':
- icn_proxy_prefix = optarg;
- break;
- case 'h':
- default:
- usage(argv[0]);
- break;
+ case 'p':
+ root_folder = optarg;
+ break;
+ case 'l':
+ webserver_prefix = optarg;
+ break;
+ case 'x':
+ tcp_proxy_address = optarg;
+ break;
+ case 'o':
+ port = atoi(optarg);
+ break;
+ case 'z':
+ icn_proxy_prefix = optarg;
+ break;
+ case 'h':
+ default:
+ usage(argv[0]);
+ break;
}
}
@@ -306,7 +294,6 @@ int main(int argc, char **argv) {
equal(web_root_path.begin(), web_root_path.end(), path.begin())) {
path += "index.html";
if (_isRegularFile(path.c_str())) {
-
auto ifs = make_shared<ifstream>();
ifs->open(path, ifstream::in | ios::binary);
@@ -401,6 +388,6 @@ int main(int argc, char **argv) {
return 0;
}
-} // end namespace std
+} // end namespace std
int main(int argc, char **argv) { return std::main(argc, argv); }
diff --git a/apps/src/http-server/http-server/common.h b/apps/http-server/http-server/common.h
index 81f6757c7..d61ddefe5 100644
--- a/apps/src/http-server/http-server/common.h
+++ b/apps/http-server/http-server/common.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Copyright (c) 2019 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,17 +15,8 @@
#pragma once
-#include "config.h"
-
-#if defined(HICNET)
#include <hicn/transport/http/facade.h>
#include <hicn/transport/utils/hash.h>
-#elif defined(ICNET)
-#include <icnet/icnet_http_facade.h>
-#include <icnet/icnet_utils_hash.h>
-#else
-#error "No ICN tranport library to which link against."
-#endif
#include <algorithm>
#include <asio.hpp>
diff --git a/apps/src/http-server/http-server/configuration.cc b/apps/http-server/http-server/configuration.cc
index 603396b44..8aa371432 100644
--- a/apps/src/http-server/http-server/configuration.cc
+++ b/apps/http-server/http-server/configuration.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Copyright (c) 2019 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/src/http-server/http-server/configuration.h b/apps/http-server/http-server/configuration.h
index b87558f91..8404025a6 100644
--- a/apps/src/http-server/http-server/configuration.h
+++ b/apps/http-server/http-server/configuration.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Copyright (c) 2019 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/src/http-server/http-server/content.cc b/apps/http-server/http-server/content.cc
index 8ad16f904..86b7afc47 100644
--- a/apps/src/http-server/http-server/content.cc
+++ b/apps/http-server/http-server/content.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Copyright (c) 2019 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/src/http-server/http-server/content.h b/apps/http-server/http-server/content.h
index ebf2f7f32..d1e6fecd2 100644
--- a/apps/src/http-server/http-server/content.h
+++ b/apps/http-server/http-server/content.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Copyright (c) 2019 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/src/http-server/http-server/http_server.cc b/apps/http-server/http-server/http_server.cc
index 8c8bea60a..a2e911e10 100644
--- a/apps/src/http-server/http-server/http_server.cc
+++ b/apps/http-server/http-server/http_server.cc
@@ -1,25 +1,16 @@
/*
- * The MIT License (MIT)
+ * Copyright (c) 2019 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:
*
- * Copyright (c) 2014-2016 Ole Christian Eidheim
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
#include "http_server.h"
@@ -35,16 +26,20 @@ HttpServer::HttpServer(unsigned short port, std::string icn_name,
long timeout_send_or_receive)
: config_(port, num_threads),
internal_io_service_(std::make_shared<asio::io_service>()),
- io_service_(*internal_io_service_), acceptor_(io_service_),
- icn_name_(icn_name), timeout_request_(timeout_request),
+ io_service_(*internal_io_service_),
+ acceptor_(io_service_),
+ icn_name_(icn_name),
+ timeout_request_(timeout_request),
timeout_content_(timeout_send_or_receive) {}
HttpServer::HttpServer(unsigned short port, std::string icn_name,
size_t num_threads, long timeout_request,
long timeout_send_or_receive,
asio::io_service &ioService)
- : config_(port, num_threads), io_service_(ioService),
- acceptor_(io_service_), icn_name_(icn_name),
+ : config_(port, num_threads),
+ io_service_(ioService),
+ acceptor_(io_service_),
+ icn_name_(icn_name),
timeout_request_(timeout_request),
timeout_content_(timeout_send_or_receive) {}
@@ -188,9 +183,8 @@ void HttpServer::send(std::shared_ptr<Response> response,
response->send(callback);
}
-std::shared_ptr<asio::steady_timer>
-HttpServer::set_timeout_on_socket(std::shared_ptr<socket_type> socket,
- long seconds) {
+std::shared_ptr<asio::steady_timer> HttpServer::set_timeout_on_socket(
+ std::shared_ptr<socket_type> socket, long seconds) {
std::shared_ptr<asio::steady_timer> timer =
std::make_shared<asio::steady_timer>(io_service_);
timer->expires_from_now(std::chrono::seconds(seconds));
@@ -266,7 +260,6 @@ void HttpServer::read_request_and_content(std::shared_ptr<socket_type> socket) {
}
});
} else {
-
if (timeout_content_ > 0) {
timer->cancel();
}
@@ -413,4 +406,4 @@ void HttpServer::write_response(std::shared_ptr<socket_type> socket,
}
}
-} // end namespace icn_httpserver
+} // end namespace icn_httpserver
diff --git a/apps/src/http-server/http-server/http_server.h b/apps/http-server/http-server/http_server.h
index 3468b438a..cb963a900 100644
--- a/apps/src/http-server/http-server/http_server.h
+++ b/apps/http-server/http-server/http_server.h
@@ -1,25 +1,16 @@
/*
- * The MIT License (MIT)
+ * Copyright (c) 2019 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:
*
- * Copyright (c) 2014-2016 Ole Christian Eidheim
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
#pragma once
@@ -48,7 +39,7 @@ typedef std::function<void(std::shared_ptr<icn_httpserver::Response>,
namespace icn_httpserver {
class HttpServer {
-public:
+ public:
explicit HttpServer(unsigned short port, std::string icn_name,
size_t num_threads, long timeout_request,
long timeout_send_or_receive);
@@ -73,17 +64,17 @@ public:
std::unordered_map<std::string, ResourceCallback> default_resource;
- void
- onIcnRequest(std::shared_ptr<libl4::http::HTTPServerPublisher> &publisher,
- const uint8_t *buffer, std::size_t size, int request_id);
+ void onIcnRequest(
+ std::shared_ptr<libl4::http::HTTPServerPublisher> &publisher,
+ const uint8_t *buffer, std::size_t size, int request_id);
-private:
+ private:
void spawnThreads();
void setIcnAcceptor();
- std::shared_ptr<asio::steady_timer>
- set_timeout_on_socket(std::shared_ptr<socket_type> socket, long seconds);
+ std::shared_ptr<asio::steady_timer> set_timeout_on_socket(
+ std::shared_ptr<socket_type> socket, long seconds);
void read_request_and_content(std::shared_ptr<socket_type> socket);
@@ -115,4 +106,4 @@ private:
long timeout_content_;
};
-} // end namespace icn_httpserver
+} // end namespace icn_httpserver
diff --git a/apps/src/http-server/http-server/icn_request.cc b/apps/http-server/http-server/icn_request.cc
index 7871d908d..3f85a927b 100644
--- a/apps/src/http-server/http-server/icn_request.cc
+++ b/apps/http-server/http-server/icn_request.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Copyright (c) 2019 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/src/http-server/http-server/icn_request.h b/apps/http-server/http-server/icn_request.h
index adf36d129..230197d3f 100644
--- a/apps/src/http-server/http-server/icn_request.h
+++ b/apps/http-server/http-server/icn_request.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Copyright (c) 2019 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/src/http-server/http-server/icn_response.cc b/apps/http-server/http-server/icn_response.cc
index 11d0faf6b..0fcfa9493 100644
--- a/apps/src/http-server/http-server/icn_response.cc
+++ b/apps/http-server/http-server/icn_response.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Copyright (c) 2019 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/src/http-server/http-server/icn_response.h b/apps/http-server/http-server/icn_response.h
index 2194a5a7f..90cd33313 100644
--- a/apps/src/http-server/http-server/icn_response.h
+++ b/apps/http-server/http-server/icn_response.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Copyright (c) 2019 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/src/http-server/http-server/request.cc b/apps/http-server/http-server/request.cc
index e754d645b..1e3d5b81d 100644
--- a/apps/src/http-server/http-server/request.cc
+++ b/apps/http-server/http-server/request.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Copyright (c) 2019 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/src/http-server/http-server/request.h b/apps/http-server/http-server/request.h
index f9b2a73df..393556edb 100644
--- a/apps/src/http-server/http-server/request.h
+++ b/apps/http-server/http-server/request.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Copyright (c) 2019 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/src/http-server/http-server/response.cc b/apps/http-server/http-server/response.cc
index ccb249e4a..ce5919934 100644
--- a/apps/src/http-server/http-server/response.cc
+++ b/apps/http-server/http-server/response.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Copyright (c) 2019 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/src/http-server/http-server/response.h b/apps/http-server/http-server/response.h
index 9cc2e61ab..27be566bf 100644
--- a/apps/src/http-server/http-server/response.h
+++ b/apps/http-server/http-server/response.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Copyright (c) 2019 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-server/http-server/socket_request.cc b/apps/http-server/http-server/socket_request.cc
new file mode 100644
index 000000000..7affe08f3
--- /dev/null
+++ b/apps/http-server/http-server/socket_request.cc
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2019 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:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "socket_request.h"
+
+namespace icn_httpserver {
+
+void SocketRequest::read_remote_endpoint_data(socket_type &socket) {
+ try {
+ remote_endpoint_address_ =
+ socket.lowest_layer().remote_endpoint().address().to_string();
+ remote_endpoint_port_ = socket.lowest_layer().remote_endpoint().port();
+ } catch (const std::exception &) {
+ }
+}
+
+} // end namespace icn_httpserver
diff --git a/apps/src/http-server/config.h.in b/apps/http-server/http-server/socket_request.h
index d10e62ee2..020b7f5b4 100644
--- a/apps/src/http-server/config.h.in
+++ b/apps/http-server/http-server/socket_request.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Copyright (c) 2019 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,5 +15,17 @@
#pragma once
-#cmakedefine ICNET
-#cmakedefine HICNET
+#include "request.h"
+
+namespace icn_httpserver {
+
+class SocketRequest : public Request {
+ public:
+ void read_remote_endpoint_data(socket_type &socket);
+
+ private:
+ std::string remote_endpoint_address_;
+ unsigned short remote_endpoint_port_;
+};
+
+} // end namespace icn_httpserver
diff --git a/apps/http-server/http-server/socket_response.cc b/apps/http-server/http-server/socket_response.cc
new file mode 100644
index 000000000..07ef96045
--- /dev/null
+++ b/apps/http-server/http-server/socket_response.cc
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2019 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:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "socket_response.h"
+
+namespace icn_httpserver {
+
+SocketResponse::SocketResponse(std::shared_ptr<asio::ip::tcp::socket> socket)
+ : socket_(socket) {}
+
+SocketResponse::~SocketResponse(){};
+
+void SocketResponse::send(const SendCallback &callback) {
+ asio::async_write(
+ *this->socket_, this->streambuf_,
+ [callback](const std::error_code &ec, size_t /*bytes_transferred*/) {
+ if (callback) {
+ callback(ec);
+ }
+ });
+}
+
+const std::shared_ptr<socket_type> &SocketResponse::getSocket() const {
+ return socket_;
+}
+
+void SocketResponse::setSocket(const std::shared_ptr<socket_type> &socket) {
+ SocketResponse::socket_ = socket;
+}
+
+} // end namespace icn_httpserver
diff --git a/apps/http-server/http-server/socket_response.h b/apps/http-server/http-server/socket_response.h
new file mode 100644
index 000000000..477fb30cb
--- /dev/null
+++ b/apps/http-server/http-server/socket_response.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2019 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:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include "response.h"
+
+namespace icn_httpserver {
+
+class SocketResponse : public Response {
+ public:
+ SocketResponse(std::shared_ptr<socket_type> socket);
+
+ ~SocketResponse();
+
+ void send(const SendCallback &callback = nullptr);
+
+ const std::shared_ptr<socket_type> &getSocket() const;
+
+ void setSocket(const std::shared_ptr<socket_type> &socket);
+
+ private:
+ std::shared_ptr<socket_type> socket_;
+};
+
+} // end namespace icn_httpserver
diff --git a/apps/src/http-server/http-server/socket_request.cc b/apps/src/http-server/http-server/socket_request.cc
deleted file mode 100644
index 321d9c61a..000000000
--- a/apps/src/http-server/http-server/socket_request.cc
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2014-2016 Ole Christian Eidheim
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#include "socket_request.h"
-
-namespace icn_httpserver {
-
-void SocketRequest::read_remote_endpoint_data(socket_type &socket) {
- try {
- remote_endpoint_address_ =
- socket.lowest_layer().remote_endpoint().address().to_string();
- remote_endpoint_port_ = socket.lowest_layer().remote_endpoint().port();
- } catch (const std::exception &) {
- }
-}
-
-} // end namespace icn_httpserver
diff --git a/apps/src/http-server/http-server/socket_request.h b/apps/src/http-server/http-server/socket_request.h
deleted file mode 100644
index c6566a207..000000000
--- a/apps/src/http-server/http-server/socket_request.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2014-2016 Ole Christian Eidheim
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#pragma once
-
-#include "request.h"
-
-namespace icn_httpserver {
-
-class SocketRequest : public Request {
-public:
- void read_remote_endpoint_data(socket_type &socket);
-
-private:
- std::string remote_endpoint_address_;
- unsigned short remote_endpoint_port_;
-};
-
-} // end namespace icn_httpserver
diff --git a/apps/src/http-server/http-server/socket_response.cc b/apps/src/http-server/http-server/socket_response.cc
deleted file mode 100644
index 5095c614f..000000000
--- a/apps/src/http-server/http-server/socket_response.cc
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2014-2016 Ole Christian Eidheim
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#include "socket_response.h"
-
-namespace icn_httpserver {
-
-SocketResponse::SocketResponse(std::shared_ptr<asio::ip::tcp::socket> socket)
- : socket_(socket) {}
-
-SocketResponse::~SocketResponse(){};
-
-void SocketResponse::send(const SendCallback &callback) {
- asio::async_write(
- *this->socket_, this->streambuf_,
- [callback](const std::error_code &ec, size_t /*bytes_transferred*/) {
- if (callback) {
- callback(ec);
- }
- });
-}
-
-const std::shared_ptr<socket_type> &SocketResponse::getSocket() const {
- return socket_;
-}
-
-void SocketResponse::setSocket(const std::shared_ptr<socket_type> &socket) {
- SocketResponse::socket_ = socket;
-}
-
-} // end namespace icn_httpserver
diff --git a/apps/src/http-server/http-server/socket_response.h b/apps/src/http-server/http-server/socket_response.h
deleted file mode 100644
index b582809dc..000000000
--- a/apps/src/http-server/http-server/socket_response.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2014-2016 Ole Christian Eidheim
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#pragma once
-
-#include "response.h"
-
-namespace icn_httpserver {
-
-class SocketResponse : public Response {
-public:
- SocketResponse(std::shared_ptr<socket_type> socket);
-
- ~SocketResponse();
-
- void send(const SendCallback &callback = nullptr);
-
- const std::shared_ptr<socket_type> &getSocket() const;
-
- void setSocket(const std::shared_ptr<socket_type> &socket);
-
-private:
- std::shared_ptr<socket_type> socket_;
-};
-
-} // end namespace icn_httpserver