aboutsummaryrefslogtreecommitdiffstats
path: root/icnet
diff options
context:
space:
mode:
authorMauro Sardara <msardara+fdio@cisco.com>2017-06-05 16:48:29 +0200
committerMauro Sardara <msardara+fdio@cisco.com>2017-06-05 17:45:15 +0200
commitd22d2b4785e2f4eafc8dda2ae032931f89c7e45f (patch)
tree47fa6879217c4b08e8a78efc33b8cd007a110866 /icnet
parent52ab9bf241528b0cb1d24384d22b017391be2899 (diff)
- Added new interface between applications and library:
- Application retrieve resources using the common HTTP url format. - Translation between network names and application names performed by the library - Added basic error handling - Added utils for http connections - Added support for differetn build types (DEBUG, RELEASE, RELEASE with debug symbols, RELEASE with min size executable) - Added support for iOS Change-Id: I8ba2a5d8bd70a4f7721e1bbc2efe3fb81ed2c98c Signed-off-by: Mauro Sardara <msardara+fdio@cisco.com>
Diffstat (limited to 'icnet')
-rw-r--r--icnet/CMakeLists.txt156
-rw-r--r--icnet/ccnx/icnet_ccnx_content_object.cc4
-rw-r--r--icnet/ccnx/icnet_ccnx_content_object.h4
-rw-r--r--icnet/ccnx/icnet_ccnx_interest.cc12
-rw-r--r--icnet/ccnx/icnet_ccnx_interest.h9
-rw-r--r--icnet/ccnx/icnet_ccnx_local_connector.cc2
-rw-r--r--icnet/errors/icnet_errors.h21
-rw-r--r--icnet/errors/icnet_errors_malformed_name_exception.cc32
-rw-r--r--icnet/errors/icnet_errors_malformed_name_exception.h32
-rw-r--r--icnet/errors/icnet_errors_malformed_packet_exception.cc32
-rw-r--r--icnet/errors/icnet_errors_malformed_packet_exception.h32
-rw-r--r--icnet/errors/icnet_errors_not_implemented_exception.cc33
-rw-r--r--icnet/errors/icnet_errors_not_implemented_exception.h32
-rw-r--r--icnet/errors/icnet_errors_runtime_exception.cc32
-rw-r--r--icnet/errors/icnet_errors_runtime_exception.h34
-rw-r--r--icnet/errors/icnet_errors_tokenizer_exception.cc33
-rw-r--r--icnet/errors/icnet_errors_tokenizer_exception.h32
-rw-r--r--icnet/http/icnet_http_client_connection.cc119
-rw-r--r--icnet/http/icnet_http_client_connection.h56
-rw-r--r--icnet/http/icnet_http_default_values.h30
-rw-r--r--icnet/http/icnet_http_facade.h22
-rw-r--r--icnet/http/icnet_http_request.cc101
-rw-r--r--icnet/http/icnet_http_request.h71
-rw-r--r--icnet/http/icnet_http_server_acceptor.cc171
-rw-r--r--icnet/http/icnet_http_server_acceptor.h62
-rw-r--r--icnet/http/icnet_http_server_publisher.cc79
-rw-r--r--icnet/http/icnet_http_server_publisher.h72
-rw-r--r--icnet/transport/icnet_transport_common.h (renamed from icnet/transport/icnet_common.h)0
-rw-r--r--icnet/transport/icnet_transport_content_store.cc (renamed from icnet/transport/icnet_content_store.cc)6
-rw-r--r--icnet/transport/icnet_transport_content_store.h (renamed from icnet/transport/icnet_content_store.h)6
-rw-r--r--icnet/transport/icnet_transport_download_observer.h (renamed from icnet/transport/icnet_download_observer.h)4
-rw-r--r--icnet/transport/icnet_transport_protocol.cc (renamed from icnet/transport/icnet_transport.cc)6
-rw-r--r--icnet/transport/icnet_transport_protocol.h (renamed from icnet/transport/icnet_transport.h)8
-rw-r--r--icnet/transport/icnet_transport_raaqm.cc4
-rw-r--r--icnet/transport/icnet_transport_raaqm.h6
-rw-r--r--icnet/transport/icnet_transport_raaqm_data_path.cc4
-rw-r--r--icnet/transport/icnet_transport_raaqm_data_path.h4
-rw-r--r--icnet/transport/icnet_transport_rate_estimation.cc (renamed from icnet/transport/icnet_rate_estimation.cc)8
-rw-r--r--icnet/transport/icnet_transport_rate_estimation.h (renamed from icnet/transport/icnet_rate_estimation.h)8
-rw-r--r--icnet/transport/icnet_transport_socket.h (renamed from icnet/transport/icnet_socket.h)14
-rw-r--r--icnet/transport/icnet_transport_socket_consumer.cc (renamed from icnet/transport/icnet_socket_consumer.cc)6
-rw-r--r--icnet/transport/icnet_transport_socket_consumer.h (renamed from icnet/transport/icnet_socket_consumer.h)10
-rw-r--r--icnet/transport/icnet_transport_socket_options_default_values.h (renamed from icnet/transport/icnet_socket_options_default_values.h)4
-rw-r--r--icnet/transport/icnet_transport_socket_options_keys.h (renamed from icnet/transport/icnet_socket_options_keys.h)4
-rw-r--r--icnet/transport/icnet_transport_socket_producer.cc (renamed from icnet/transport/icnet_socket_producer.cc)28
-rw-r--r--icnet/transport/icnet_transport_socket_producer.h (renamed from icnet/transport/icnet_socket_producer.h)14
-rw-r--r--icnet/transport/icnet_transport_vegas.cc17
-rw-r--r--icnet/transport/icnet_transport_vegas.h6
-rw-r--r--icnet/transport/icnet_transport_vegas_rto_estimator.cc6
-rw-r--r--icnet/transport/icnet_transport_vegas_rto_estimator.h6
-rw-r--r--icnet/utils/icnet_utils_array.cc52
-rw-r--r--icnet/utils/icnet_utils_array.h45
-rw-r--r--icnet/utils/icnet_utils_daemonizator.cc74
-rw-r--r--icnet/utils/icnet_utils_daemonizator.h29
-rw-r--r--icnet/utils/icnet_utils_hash.cc64
-rw-r--r--icnet/utils/icnet_utils_hash.h42
-rw-r--r--icnet/utils/icnet_utils_string_tokenizer.cc52
-rw-r--r--icnet/utils/icnet_utils_string_tokenizer.h38
-rw-r--r--icnet/utils/icnet_utils_uri.cc137
-rw-r--r--icnet/utils/icnet_utils_uri.h51
60 files changed, 1988 insertions, 90 deletions
diff --git a/icnet/CMakeLists.txt b/icnet/CMakeLists.txt
index fae22d61..427a3d9f 100644
--- a/icnet/CMakeLists.txt
+++ b/icnet/CMakeLists.txt
@@ -13,65 +13,149 @@
cmake_minimum_required(VERSION 3.2)
-file(GLOB HEADER_FILES "ccnx/*.h")
-file(GLOB SOURCE_FILES "ccnx/*.cc")
+set(CCNX_HEADER_FILES
+ ccnx/icnet_ccnx_common.h
+ ccnx/icnet_ccnx_content_object.h
+ ccnx/icnet_ccnx_facade.h
+ ccnx/icnet_ccnx_interest.h
+ ccnx/icnet_ccnx_key_locator.h
+ ccnx/icnet_ccnx_key_locator_type.h
+ ccnx/icnet_ccnx_local_connector.h
+ ccnx/icnet_ccnx_manifest.h
+ ccnx/icnet_ccnx_name.h
+ ccnx/icnet_ccnx_network_message.h
+ ccnx/icnet_ccnx_payload_type.h
+ ccnx/icnet_ccnx_pending_interest.h
+ ccnx/icnet_ccnx_portal.h
+ ccnx/icnet_ccnx_segment.h)
-set(ICNET_HEADER_FILES
+set(CCNX_SOURCE_FILES
+ ccnx/icnet_ccnx_segment.cc
+ ccnx/icnet_ccnx_portal.cc
+ ccnx/icnet_ccnx_pending_interest.cc
+ ccnx/icnet_ccnx_network_message.cc
+ ccnx/icnet_ccnx_name.cc
+ ccnx/icnet_ccnx_manifest.cc
+ ccnx/icnet_ccnx_local_connector.cc
+ ccnx/icnet_ccnx_key_locator.cc
+ ccnx/icnet_ccnx_interest.cc
+ ccnx/icnet_ccnx_content_object.cc)
+
+set(TRANSPORT_HEADER_FILES
${CMAKE_BINARY_DIR}/config.hpp
- transport/icnet_rate_estimation.h
- transport/icnet_download_observer.h
- transport/icnet_socket_consumer.h
- transport/icnet_socket.h
- transport/icnet_socket_options_default_values.h
- transport/icnet_socket_options_keys.h
- transport/icnet_common.h
- transport/icnet_socket_producer.h
- transport/icnet_content_store.h
+ transport/icnet_transport_rate_estimation.h
+ transport/icnet_transport_download_observer.h
+ transport/icnet_transport_socket_consumer.h
+ transport/icnet_transport_socket.h
+ transport/icnet_transport_socket_options_default_values.h
+ transport/icnet_transport_socket_options_keys.h
+ transport/icnet_transport_common.h
+ transport/icnet_transport_socket_producer.h
+ transport/icnet_transport_content_store.h
transport/icnet_transport_vegas.h
- transport/icnet_transport.h
+ transport/icnet_transport_protocol.h
transport/icnet_transport_raaqm.h
transport/icnet_transport_vegas_rto_estimator.h
transport/icnet_transport_raaqm_data_path.h)
-set(ICNET_SOURCE_FILES
- transport/icnet_socket_producer.cc
- transport/icnet_socket_consumer.cc
+set(TRANSPORT_SOURCE_FILES
+ transport/icnet_transport_socket_producer.cc
+ transport/icnet_transport_socket_consumer.cc
transport/icnet_transport_vegas.cc
- transport/icnet_transport.cc
- transport/icnet_content_store.cc
+ transport/icnet_transport_protocol.cc
+ transport/icnet_transport_content_store.cc
transport/icnet_transport_raaqm.cc
transport/icnet_transport_vegas_rto_estimator.cc
- transport/icnet_rate_estimation.cc
+ transport/icnet_transport_rate_estimation.cc
transport/icnet_transport_raaqm_data_path.cc)
+set(ERRORS_HEADER_FILES
+ errors/icnet_errors_tokenizer_exception.h
+ errors/icnet_errors.h
+ errors/icnet_errors_malformed_name_exception.h
+ errors/icnet_errors_not_implemented_exception.h
+ errors/icnet_errors_runtime_exception.h
+ errors/icnet_errors_malformed_packet_exception.h)
+
+set(ERRORS_SOURCE_FILES
+ errors/icnet_errors_tokenizer_exception.cc
+ errors/icnet_errors_malformed_name_exception.cc
+ errors/icnet_errors_not_implemented_exception.cc
+ errors/icnet_errors_runtime_exception.cc
+ errors/icnet_errors_malformed_packet_exception.cc)
+
+set(HTTP_HEADER_FILES
+ http/icnet_http_default_values.h
+ http/icnet_http_client_connection.h
+ http/icnet_http_server_acceptor.h
+ http/icnet_http_server_publisher.h
+ http/icnet_http_request.h
+ http/icnet_http_facade.h)
+
+set(HTTP_SOURCE_FILES
+ http/icnet_http_client_connection.cc
+ http/icnet_http_server_acceptor.cc
+ http/icnet_http_server_publisher.cc
+ http/icnet_http_request.cc)
+
+set(UTILS_HEADER_FILES
+ utils/icnet_utils_array.h
+ utils/icnet_utils_uri.h
+ utils/icnet_utils_daemonizator.h
+ utils/icnet_utils_hash.h
+ utils/icnet_utils_string_tokenizer.h)
+
+set(UTILS_SOURCE_FILES
+ utils/icnet_utils_array.cc
+ utils/icnet_utils_uri.cc
+ utils/icnet_utils_daemonizator.cc
+ utils/icnet_utils_hash.cc
+ utils/icnet_utils_string_tokenizer.cc)
+
set(ICNET_CONFIG
transport/consumer.conf)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
-add_library(icnet STATIC ${SOURCE_FILES} ${ICNET_SOURCE_FILES} ${HEADER_FILES} ${ICNET_HEADER_FILES})
-add_library(icnet.shared SHARED ${SOURCE_FILES} ${ICNET_SOURCE_FILES})
-if(ANDROID_API)
- target_link_libraries(icnet.shared ${LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} ${CCNX_COMMON_LIBRARIES} ${CCNX_TRANSPORT_RTA_LIBRARIES} ${CCNX_PORTAL_LIBRARIES} ${LIBPARC_LIBRARIES} ${LONGBOW_LIBRARIES})
- target_link_libraries(icnet ${LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} ${CCNX_COMMON_LIBRARIES} ${CCNX_TRANSPORT_RTA_LIBRARIES} ${CCNX_PORTAL_LIBRARIES} ${LIBPARC_LIBRARIES} ${LONGBOW_LIBRARIES})
-else ()
- target_link_libraries(icnet.shared ${LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
+add_library(icnet STATIC
+ ${CCNX_SOURCE_FILES}
+ ${TRANSPORT_SOURCE_FILES}
+ ${ERRORS_SOURCE_FILES}
+ ${HTTP_SOURCE_FILES}
+ ${UTILS_SOURCE_FILES})
+
+if (COMPILE_FOR_IOS OR ANDROID_API)
target_link_libraries(icnet ${LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
-endif (ANDROID_API)
+ set(libicnet_libraries
+ icnet)
+else()
-set_target_properties(icnet.shared PROPERTIES
- SOVERSION 1
- VERSION 1.0
- OUTPUT_NAME icnet)
+ add_library(icnet.shared SHARED
+ ${CCNX_SOURCE_FILES}
+ ${TRANSPORT_SOURCE_FILES}
+ ${ERRORS_SOURCE_FILES}
+ ${HTTP_SOURCE_FILES}
+ ${UTILS_SOURCE_FILES})
+
+ target_link_libraries(icnet.shared ${LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
+ target_link_libraries(icnet ${LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
+ set_target_properties(icnet.shared PROPERTIES
+ SOVERSION 1
+ VERSION 1.0
+ OUTPUT_NAME icnet)
-set(libicnet_libraries
- icnet
- icnet.shared)
+ set(libicnet_libraries
+ icnet
+ icnet.shared)
+endif()
foreach(lib ${libicnet_libraries})
install(TARGETS ${lib} COMPONENT library LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
endforeach()
-install(FILES ${HEADER_FILES} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/icnet COMPONENT headers)
-install(FILES ${ICNET_HEADER_FILES} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/icnet COMPONENT headers)
+install(FILES ${CCNX_HEADER_FILES} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/icnet COMPONENT headers)
+install(FILES ${TRANSPORT_HEADER_FILES} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/icnet COMPONENT headers)
+install(FILES ${HTTP_HEADER_FILES} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/icnet COMPONENT headers)
+install(FILES ${ERRORS_HEADER_FILES} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/icnet COMPONENT headers)
+install(FILES ${UTILS_HEADER_FILES} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/icnet COMPONENT headers)
install(FILES ${ICNET_CONFIG} DESTINATION ${CMAKE_INSTALL_PREFIX}/etc/ COMPONENT library)
diff --git a/icnet/ccnx/icnet_ccnx_content_object.cc b/icnet/ccnx/icnet_ccnx_content_object.cc
index 03875724..e4070194 100644
--- a/icnet/ccnx/icnet_ccnx_content_object.cc
+++ b/icnet/ccnx/icnet_ccnx_content_object.cc
@@ -63,11 +63,11 @@ bool ContentObject::operator==(const ContentObject &content_object) {
return ccnxContentObject_Equals(ccnx_content_object_, content_object.ccnx_content_object_);
}
-PayloadType ContentObject::getContentType() const {
+PayloadType ContentObject::getPayloadType() const {
return (PayloadType) ccnxContentObject_GetPayloadType(ccnx_content_object_);
}
-void ContentObject::setContentType(PayloadType payload_type) {
+void ContentObject::setPayloadType(PayloadType payload_type) {
content_type_ = payload_type;
}
diff --git a/icnet/ccnx/icnet_ccnx_content_object.h b/icnet/ccnx/icnet_ccnx_content_object.h
index 148587bb..e7e641e6 100644
--- a/icnet/ccnx/icnet_ccnx_content_object.h
+++ b/icnet/ccnx/icnet_ccnx_content_object.h
@@ -71,13 +71,13 @@ class ContentObject : public std::enable_shared_from_this<ContentObject> {
bool operator==(const ContentObject &content_object);
- PayloadType getContentType() const;
+ PayloadType getPayloadType() const;
bool setContent(PayloadType content_type, const uint8_t *buffer, size_t buffer_size);
bool setContent(const uint8_t *buffer, size_t buffer_size);
- void setContentType(PayloadType payload_type);
+ void setPayloadType(PayloadType payload_type);
Array getContent() const;
diff --git a/icnet/ccnx/icnet_ccnx_interest.cc b/icnet/ccnx/icnet_ccnx_interest.cc
index 6b0f92cb..d578d550 100644
--- a/icnet/ccnx/icnet_ccnx_interest.cc
+++ b/icnet/ccnx/icnet_ccnx_interest.cc
@@ -117,6 +117,13 @@ bool Interest::setPayload(const PARCBuffer *payload) {
return ccnxInterest_SetPayload(interest_, payload);
}
+bool Interest::setPayload(const uint8_t *buffer, std::size_t size) {
+ PARCBuffer *pbuffer = parcBuffer_CreateFromArray(buffer, size);
+ bool ret = setPayload(pbuffer);
+ parcBuffer_Release(&pbuffer);
+ return ret;
+}
+
bool Interest::setPayloadAndId(const PARCBuffer *payload) {
return ccnxInterest_SetPayloadAndId(interest_, payload);
}
@@ -125,8 +132,9 @@ bool Interest::setPayloadWithId(const PARCBuffer *payload, const CCNxInterestPay
return ccnxInterest_SetPayloadWithId(interest_, payload, payload_id);
}
-PARCBuffer *Interest::getPayload() {
- return ccnxInterest_GetPayload(interest_);
+utils::Array Interest::getPayload() const {
+ PARCBuffer *buffer = ccnxInterest_GetPayload(interest_);
+ return utils::Array(parcBuffer_Overlay(buffer, 0), parcBuffer_Remaining(buffer));
}
void Interest::setHopLimit(uint32_t hop_limit) {
diff --git a/icnet/ccnx/icnet_ccnx_interest.h b/icnet/ccnx/icnet_ccnx_interest.h
index 2156b56f..47af3f68 100644
--- a/icnet/ccnx/icnet_ccnx_interest.h
+++ b/icnet/ccnx/icnet_ccnx_interest.h
@@ -17,14 +17,13 @@
#define ICNET_CCNX_INTEREST_H_
#include "icnet_ccnx_common.h"
+#include "icnet_utils_array.h"
+#include "icnet_ccnx_name.h"
extern "C" {
#include <ccnx/common/ccnx_Interest.h>
};
-//#include "interest.hpp"
-#include "icnet_ccnx_name.h"
-
namespace icnet {
namespace ccnx {
@@ -67,11 +66,13 @@ class Interest : public std::enable_shared_from_this<Interest> {
bool setPayload(const PARCBuffer *payload);
+ bool setPayload(const uint8_t *buffer, std::size_t size);
+
bool setPayloadAndId(const PARCBuffer *payload);
bool setPayloadWithId(const PARCBuffer *payload, const CCNxInterestPayloadId *payload_id);
- PARCBuffer *getPayload();
+ utils::Array getPayload() const;
void setHopLimit(uint32_t hop_limit);
diff --git a/icnet/ccnx/icnet_ccnx_local_connector.cc b/icnet/ccnx/icnet_ccnx_local_connector.cc
index cd828b08..75691979 100644
--- a/icnet/ccnx/icnet_ccnx_local_connector.cc
+++ b/icnet/ccnx/icnet_ccnx_local_connector.cc
@@ -136,7 +136,7 @@ void LocalConnector::doReadHeader() {
void LocalConnector::tryReconnect() {
if (!is_connecting_) {
#ifdef __ANDROID__
- __android_log_print(ANDROID_LOG_DEBUG, "libICNet", "Connection lost. Trying to reconnect...\n");
+ __android_log_print(ANDROID_LOG_DEBUG, "libICNet", "Connection lost. Trying to reconnect...\n");
#else
std::cerr << "Connection lost. Trying to reconnect..." << std::endl;
#endif
diff --git a/icnet/errors/icnet_errors.h b/icnet/errors/icnet_errors.h
new file mode 100644
index 00000000..34ba11af
--- /dev/null
+++ b/icnet/errors/icnet_errors.h
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2017 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 "icnet_errors_malformed_name_exception.h"
+#include "icnet_errors_not_implemented_exception.h"
+#include "icnet_errors_malformed_packet_exception.h"
+#include "icnet_errors_runtime_exception.h"
diff --git a/icnet/errors/icnet_errors_malformed_name_exception.cc b/icnet/errors/icnet_errors_malformed_name_exception.cc
new file mode 100644
index 00000000..361c211a
--- /dev/null
+++ b/icnet/errors/icnet_errors_malformed_name_exception.cc
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2017 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 "icnet_errors.h"
+
+namespace icnet {
+
+namespace errors {
+
+MalformedNameException::MalformedNameException()
+ : std::runtime_error("") {
+}
+
+char const *MalformedNameException::what() const noexcept {
+ return "Malformed IP address.";
+}
+
+} // end namespace errors
+
+} // end namespace icnet \ No newline at end of file
diff --git a/icnet/errors/icnet_errors_malformed_name_exception.h b/icnet/errors/icnet_errors_malformed_name_exception.h
new file mode 100644
index 00000000..f714d2b0
--- /dev/null
+++ b/icnet/errors/icnet_errors_malformed_name_exception.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2017 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 <stdexcept>
+
+namespace icnet {
+
+namespace errors {
+
+class MalformedNameException : public std::runtime_error {
+ public:
+ MalformedNameException();
+ virtual char const *what() const noexcept override;
+};
+
+} // end namespace errors
+
+} // end namespace icnet \ No newline at end of file
diff --git a/icnet/errors/icnet_errors_malformed_packet_exception.cc b/icnet/errors/icnet_errors_malformed_packet_exception.cc
new file mode 100644
index 00000000..962a6582
--- /dev/null
+++ b/icnet/errors/icnet_errors_malformed_packet_exception.cc
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2017 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 "icnet_errors_malformed_packet_exception.h"
+
+namespace icnet {
+
+namespace errors {
+
+MalformedPacketException::MalformedPacketException()
+ : std::runtime_error("") {
+}
+
+char const *MalformedPacketException::what() const noexcept {
+ return "Malformed IP packet.";
+}
+
+} // end namespace errors
+
+} // end namespace icnet \ No newline at end of file
diff --git a/icnet/errors/icnet_errors_malformed_packet_exception.h b/icnet/errors/icnet_errors_malformed_packet_exception.h
new file mode 100644
index 00000000..0420d5c1
--- /dev/null
+++ b/icnet/errors/icnet_errors_malformed_packet_exception.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2017 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 <stdexcept>
+
+namespace icnet {
+
+namespace errors {
+
+class MalformedPacketException : public std::runtime_error {
+ public:
+ MalformedPacketException();
+ virtual char const *what() const noexcept override;
+};
+
+} // end namespace errors
+
+} // end namespace icnet \ No newline at end of file
diff --git a/icnet/errors/icnet_errors_not_implemented_exception.cc b/icnet/errors/icnet_errors_not_implemented_exception.cc
new file mode 100644
index 00000000..c58039c9
--- /dev/null
+++ b/icnet/errors/icnet_errors_not_implemented_exception.cc
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2017 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 "icnet_errors_not_implemented_exception.h"
+
+namespace icnet {
+
+namespace errors {
+
+NotImplementedException::NotImplementedException()
+ : std::logic_error("") {
+
+}
+
+char const *NotImplementedException::what() const noexcept {
+ return "Function not yet implemented.";
+}
+
+} // end namespace errors
+
+} // end namespace icnet \ No newline at end of file
diff --git a/icnet/errors/icnet_errors_not_implemented_exception.h b/icnet/errors/icnet_errors_not_implemented_exception.h
new file mode 100644
index 00000000..980ae99f
--- /dev/null
+++ b/icnet/errors/icnet_errors_not_implemented_exception.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2017 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 <stdexcept>
+
+namespace icnet {
+
+namespace errors {
+
+class NotImplementedException : public std::logic_error {
+ public:
+ NotImplementedException();
+ virtual char const *what() const noexcept override;
+};
+
+} // end namespace errors
+
+} // end namespace icnet \ No newline at end of file
diff --git a/icnet/errors/icnet_errors_runtime_exception.cc b/icnet/errors/icnet_errors_runtime_exception.cc
new file mode 100644
index 00000000..4853f25c
--- /dev/null
+++ b/icnet/errors/icnet_errors_runtime_exception.cc
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2017 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 "icnet_errors_runtime_exception.h"
+
+namespace icnet {
+
+namespace errors {
+
+RuntimeException::RuntimeException()
+ : std::runtime_error("") {
+}
+
+//char const *Runtime::what() const {
+// return "Function not yet implemented.";
+//}
+
+} // end namespace errors
+
+} // end namespace icnet \ No newline at end of file
diff --git a/icnet/errors/icnet_errors_runtime_exception.h b/icnet/errors/icnet_errors_runtime_exception.h
new file mode 100644
index 00000000..37c6bcb6
--- /dev/null
+++ b/icnet/errors/icnet_errors_runtime_exception.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2017 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 <stdexcept>
+#include <string>
+
+namespace icnet {
+
+namespace errors {
+
+class RuntimeException : public std::runtime_error {
+ public:
+ RuntimeException();
+ RuntimeException(std::string what)
+ : runtime_error(what) {};
+};
+
+} // end namespace errors
+
+} // end namespace icnet \ No newline at end of file
diff --git a/icnet/errors/icnet_errors_tokenizer_exception.cc b/icnet/errors/icnet_errors_tokenizer_exception.cc
new file mode 100644
index 00000000..1b5e8438
--- /dev/null
+++ b/icnet/errors/icnet_errors_tokenizer_exception.cc
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2017 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 "icnet_errors_tokenizer_exception.h"
+
+namespace icnet {
+
+namespace errors {
+
+TokenizerException::TokenizerException()
+ : std::logic_error("") {
+
+}
+
+char const *TokenizerException::what() const noexcept {
+ return "No more tokens available.";
+}
+
+} // end namespace errors
+
+} // end namespace icnet \ No newline at end of file
diff --git a/icnet/errors/icnet_errors_tokenizer_exception.h b/icnet/errors/icnet_errors_tokenizer_exception.h
new file mode 100644
index 00000000..bae9d82a
--- /dev/null
+++ b/icnet/errors/icnet_errors_tokenizer_exception.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2017 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 <stdexcept>
+
+namespace icnet {
+
+namespace errors {
+
+class TokenizerException : public std::logic_error {
+ public:
+ TokenizerException();
+ virtual char const *what() const noexcept override;
+};
+
+} // end namespace errors
+
+} // end namespace icnet \ No newline at end of file
diff --git a/icnet/http/icnet_http_client_connection.cc b/icnet/http/icnet_http_client_connection.cc
new file mode 100644
index 00000000..1f0d8fd8
--- /dev/null
+++ b/icnet/http/icnet_http_client_connection.cc
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2017 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 "icnet_http_client_connection.h"
+
+#define DEFAULT_BETA 0.99
+#define DEFAULT_GAMMA 0.07
+
+namespace icnet {
+
+namespace http {
+
+using namespace transport;
+
+HTTPClientConnection::HTTPClientConnection()
+ : consumer_(Name("ccnx:"), transport::TransportProtocolAlgorithms::RAAQM) {
+
+ consumer_.setSocketOption(GeneralTransportOptions::INTEREST_LIFETIME, 1001);
+ consumer_.setSocketOption(RaaqmTransportOptions::BETA_VALUE, DEFAULT_BETA);
+ consumer_.setSocketOption(RaaqmTransportOptions::DROP_FACTOR, DEFAULT_GAMMA);
+ consumer_.setSocketOption(GeneralTransportOptions::MAX_INTEREST_RETX, 200);
+
+ consumer_.setSocketOption(ConsumerCallbacksOptions::CONTENT_OBJECT_TO_VERIFY,
+ (ConsumerContentObjectVerificationCallback) std::bind(&HTTPClientConnection::verifyData,
+ this,
+ std::placeholders::_1,
+ std::placeholders::_2));
+
+ consumer_.setSocketOption(ConsumerCallbacksOptions::CONTENT_RETRIEVED,
+ (ConsumerContentCallback) std::bind(&HTTPClientConnection::processPayload,
+ this,
+ std::placeholders::_1,
+ std::placeholders::_2));
+}
+
+HTTPClientConnection &HTTPClientConnection::get(std::string &url, HTTPHeaders headers, HTTPPayload payload) {
+
+ HTTPRequest request(GET, url, headers, payload);
+
+ std::string &request_string = request.getRequestString();
+ std::string &locator = request.getLocator();
+ std::string &path = request.getPath();
+
+ consumer_.setSocketOption(ConsumerCallbacksOptions::INTEREST_OUTPUT,
+ (ConsumerInterestCallback) std::bind(&HTTPClientConnection::processLeavingInterest,
+ this,
+ std::placeholders::_1,
+ std::placeholders::_2,
+ request_string));
+
+ // Send content to producer piggybacking it through first interest (to fix)
+
+ response_.clear();
+
+ // Factor icn name
+
+ std::stringstream stream;
+
+ stream << "ccnx:/";
+ stream << locator << "/get";
+ stream << path;
+
+ consumer_.consume(Name(stream.str()));
+
+ consumer_.stop();
+
+ return *this;
+}
+
+HTTPResponse &&HTTPClientConnection::response() {
+ return std::move(response_);
+}
+
+void HTTPClientConnection::processPayload(transport::ConsumerSocket &c,
+ std::vector<uint8_t> &&payload) {
+ response_ = std::move(payload);
+}
+
+bool HTTPClientConnection::verifyData(transport::ConsumerSocket &c, const ContentObject &contentObject) {
+ if (contentObject.getPayloadType() == PayloadType::DATA) {
+ std::cout << "VERIFY CONTENT" << std::endl;
+ } else if (contentObject.getPayloadType() == PayloadType::MANIFEST) {
+ std::cout << "VERIFY MANIFEST" << std::endl;
+ }
+
+ return true;
+}
+
+void HTTPClientConnection::processLeavingInterest(transport::ConsumerSocket &c,
+ const Interest &interest,
+ std::string &payload) {
+ if (interest.getName().get(-1).toSegment() == 0) {
+ Interest &int2 = const_cast<Interest &>(interest);
+ int2.setPayload((const uint8_t *) payload.data(), payload.size());
+ }
+}
+
+HTTPClientConnection& HTTPClientConnection::stop() {
+ // This is thread safe and can be called from another thread
+ consumer_.stop();
+
+ return *this;
+}
+
+}
+
+} \ No newline at end of file
diff --git a/icnet/http/icnet_http_client_connection.h b/icnet/http/icnet_http_client_connection.h
new file mode 100644
index 00000000..5a009d88
--- /dev/null
+++ b/icnet/http/icnet_http_client_connection.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2017 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 "icnet_transport_socket_consumer.h"
+#include "icnet_transport_socket_producer.h"
+#include "icnet_utils_uri.h"
+#include "icnet_http_request.h"
+#include "icnet_http_default_values.h"
+
+#include <vector>
+
+#define HTTP_VERSION "1.0"
+
+namespace icnet {
+
+namespace http {
+
+class HTTPClientConnection {
+ public:
+ HTTPClientConnection();
+
+ HTTPClientConnection &get(std::string &url, HTTPHeaders headers = {}, HTTPPayload payload = {});
+
+ HTTPResponse &&response();
+
+ HTTPClientConnection &stop();
+
+ private:
+
+ void processPayload(transport::ConsumerSocket &c, std::vector<uint8_t> &&payload);
+
+ bool verifyData(transport::ConsumerSocket &c, const transport::ContentObject &contentObject);
+
+ void processLeavingInterest(transport::ConsumerSocket &c, const transport::Interest &interest, std::string &payload);
+
+ HTTPResponse response_;
+ transport::ConsumerSocket consumer_;
+};
+
+} // end namespace http
+
+} // end namespace icnet \ No newline at end of file
diff --git a/icnet/http/icnet_http_default_values.h b/icnet/http/icnet_http_default_values.h
new file mode 100644
index 00000000..5aaf60d8
--- /dev/null
+++ b/icnet/http/icnet_http_default_values.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2017 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
+
+namespace hicnet {
+
+namespace http {
+
+namespace default_values {
+
+const uint16_t ipv6_first_word = 0xb001; // Network byte order
+
+} // end namespace transport
+
+} // end namespace default_values
+
+} // end namespace hicnet
diff --git a/icnet/http/icnet_http_facade.h b/icnet/http/icnet_http_facade.h
new file mode 100644
index 00000000..f32eff73
--- /dev/null
+++ b/icnet/http/icnet_http_facade.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2017 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 "icnet_http_server_acceptor.h"
+#include "icnet_http_server_publisher.h"
+#include "icnet_http_client_connection.h"
+
+namespace libl4 = icnet; \ No newline at end of file
diff --git a/icnet/http/icnet_http_request.cc b/icnet/http/icnet_http_request.cc
new file mode 100644
index 00000000..cd0c512f
--- /dev/null
+++ b/icnet/http/icnet_http_request.cc
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2017 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 "icnet_http_request.h"
+#include "icnet_utils_uri.h"
+
+namespace icnet {
+
+namespace http {
+
+static std::map<HTTPMethod, std::string> method_map = {
+ {GET, "GET"},
+ {POST, "POST"},
+ {PUT, "PUT"},
+ {PATCH, "PATCH"},
+ {DELETE, "DELETE"},
+};
+
+//std::map<HTTPMethod, std::string> method_map
+
+HTTPRequest::HTTPRequest(HTTPMethod method, std::string &url, HTTPHeaders &headers, HTTPPayload &payload) {
+ utils::Uri uri;
+ uri.parse(url);
+
+ path_ = uri.getPath();
+ query_string_ = uri.getQueryString();
+ protocol_ = uri.getProtocol();
+ locator_ = uri.getLocator();
+ port_ = uri.getPort();
+
+ headers_ = headers;
+ payload_ = payload;
+
+ std::transform(locator_.begin(),
+ locator_.end(),
+ locator_.begin(),
+ ::tolower);
+
+ std::transform(protocol_.begin(),
+ protocol_.end(),
+ protocol_.begin(),
+ ::tolower);
+
+ std::stringstream stream;
+ stream << method_map[method] << " " << uri.getPath() << " HTTP/" << HTTP_VERSION << "\r\n";
+ for (auto &item : headers) {
+ stream << item.first << ": " << item.second << "\r\n";
+ }
+ stream << "\r\n";
+ stream << payload.data();
+
+ request_string_ = stream.str();
+}
+
+std::string &HTTPRequest::getPort() {
+ return port_;
+}
+
+std::string &HTTPRequest::getLocator() {
+ return locator_;
+}
+
+std::string &HTTPRequest::getProtocol() {
+ return protocol_;
+}
+
+std::string &HTTPRequest::getPath() {
+ return path_;
+}
+
+std::string &HTTPRequest::getQueryString() {
+ return query_string_;
+}
+
+HTTPHeaders &HTTPRequest::getHeaders() {
+ return headers_;
+}
+
+HTTPPayload &HTTPRequest::getPayload() {
+ return payload_;
+}
+
+std::string &HTTPRequest::getRequestString() {
+ return request_string_;
+}
+
+}
+
+} \ No newline at end of file
diff --git a/icnet/http/icnet_http_request.h b/icnet/http/icnet_http_request.h
new file mode 100644
index 00000000..985d7628
--- /dev/null
+++ b/icnet/http/icnet_http_request.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2017 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 <sstream>
+#include <vector>
+#include <map>
+
+#define HTTP_VERSION "1.0"
+
+namespace icnet {
+
+namespace http {
+
+typedef enum {
+ GET,
+ POST,
+ PUT,
+ PATCH,
+ DELETE
+} HTTPMethod;
+
+typedef std::map<std::string, std::string> HTTPHeaders;
+typedef std::vector<uint8_t> HTTPPayload;
+typedef std::vector<uint8_t> HTTPResponse;
+
+class HTTPRequest {
+ public:
+
+ HTTPRequest(HTTPMethod method,
+ std::string &url, HTTPHeaders &headers, HTTPPayload &payload);
+
+ std::string &getQueryString();
+
+ std::string &getPath();
+
+ std::string &getProtocol();
+
+ std::string &getLocator();
+
+ std::string &getPort();
+
+ std::string &getRequestString();
+
+ HTTPHeaders &getHeaders();
+
+ HTTPPayload &getPayload();
+
+ private:
+ std::string query_string_, path_, protocol_, locator_, port_;
+ std::string request_string_;
+ HTTPHeaders headers_;
+ HTTPPayload payload_;
+};
+
+} // end namespace http
+
+} // end namespace icnet \ No newline at end of file
diff --git a/icnet/http/icnet_http_server_acceptor.cc b/icnet/http/icnet_http_server_acceptor.cc
new file mode 100644
index 00000000..9406955d
--- /dev/null
+++ b/icnet/http/icnet_http_server_acceptor.cc
@@ -0,0 +1,171 @@
+/*
+ * Copyright (c) 2017 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 "icnet_http_server_acceptor.h"
+#include "icnet_http_request.h"
+#include "icnet_errors.h"
+#include "icnet_utils_uri.h"
+#include "icnet_utils_hash.h"
+
+namespace icnet {
+
+namespace http {
+
+HTTPServerAcceptor::HTTPServerAcceptor(std::string &&server_locator, OnHttpRequest callback)
+ : HTTPServerAcceptor(server_locator, callback) {
+}
+
+HTTPServerAcceptor::HTTPServerAcceptor(std::string &server_locator, OnHttpRequest callback)
+ : callback_(callback) {
+ utils::Uri uri;
+
+ uri.parseProtocolAndLocator(server_locator);
+ std::string protocol = uri.getProtocol();
+ std::string locator = uri.getLocator();
+
+ std::transform(locator.begin(),
+ locator.end(),
+ locator.begin(),
+ ::tolower);
+
+ std::transform(protocol.begin(),
+ protocol.end(),
+ protocol.begin(),
+ ::tolower);
+
+ if (protocol != "http") {
+ throw errors::RuntimeException("Malformed server_locator. The locator format should be in the form http://locator");
+ }
+
+ std::stringstream ss;
+
+ ss << "ccnx:/";
+ ss << locator;
+
+ acceptor_producer_ = std::make_shared<transport::ProducerSocket>(ss.str());
+}
+
+void HTTPServerAcceptor::listen(bool async) {
+ acceptor_producer_->setSocketOption(icnet::transport::ProducerCallbacksOptions::INTEREST_INPUT,
+ (icnet::transport::ProducerInterestCallback) bind(&HTTPServerAcceptor::processIncomingInterest,
+ this,
+ std::placeholders::_1,
+ std::placeholders::_2));
+ acceptor_producer_->dispatch();
+
+ if (!async) {
+ acceptor_producer_->serveForever();
+ }
+}
+
+HttpRequest &&HTTPServerAcceptor::request() {
+ return std::move(request_);
+}
+
+void HTTPServerAcceptor::processIncomingInterest(transport::ProducerSocket &p, const transport::Interest &interest) {
+ // Temporary solution
+
+ transport::Name complete_name = interest.getName();
+
+ transport::Name request_name = complete_name.get(-1).isSegment() ? complete_name.getPrefix(-1) : complete_name;
+ transport::Name prefix;
+ acceptor_producer_->getSocketOption(transport::GeneralTransportOptions::NAME_PREFIX, prefix);
+
+ // Get the name of the HTTP method to compute
+ std::string method = request_name.get(prefix.getSegmentCount()).toString();
+ std::transform(method.begin(), method.end(), method.begin(), ::toupper);
+ std::string path;
+ std::string url_begin;
+
+ // This is done for getting rid of useless name components such as ccnx: or ndn:
+ if (request_name.getSegmentCount() > 2) {
+ std::string raw_path = request_name.getSubName(prefix.getSegmentCount() + 1).toString();
+ std::size_t pos = raw_path.find("/");
+ path = raw_path.substr(pos);
+ url_begin = prefix.getSubName(0).toString().substr(pos);
+ }
+
+ std::stringstream ss;
+ ss << "http:/" << url_begin << path;
+
+ std::string url = ss.str();
+ HTTPHeaders headers = {};
+ HTTPPayload payload = {};
+
+ if (method == "GET") {
+ HTTPRequest request(GET, url, headers, payload);
+ auto publisher = std::make_shared<HTTPServerPublisher>(request_name);
+ callback_(publisher, (uint8_t *) request.getRequestString().data(), request.getRequestString().size());
+ }
+}
+
+//void HTTPServerConnection::sendResponse() {
+//
+// std::thread t([]() {
+//
+// // Get the name of the HTTP method to compute
+// std::string method = request_name.get(1).toString();
+// std::transform(method.begin(), method.end(), method.begin(), ::toupper);
+// std::string path;
+//
+// // This is done for getting rid of useless name components such as ccnx: or ndn:
+// if (request_name.getSegmentCount() > 2) {
+// std::string rawPath = request_name.getSubName(2).toString();
+// std::size_t pos = rawPath.find("/");
+// path = rawPath.substr(pos);
+// }
+//
+// // Create new producer
+//
+// // Create timer for response availability
+// std::shared_ptr<core::Portal> portal;
+// po->getSocketOption(icnet::GeneralTransportOptions::PORTAL, portal);
+// boost::asio::io_service &ioService = portal->getIoService();
+//
+// boost::asio::deadline_timer t(ioService, boost::posix_time::seconds(5));
+//
+// std::function<void(const boost::system::error_code e)>
+// wait_callback = [&ioService](const boost::system::error_code e) {
+// if (!e) {
+// // Be sure to delete the timer before the io_service, otherwise we'll get some strange behavior!
+// ioService.stop();
+// }
+// };
+//
+// std::function<void(transport::ProducerSocket, const core::Interest &interest)>
+// interest_enter_callback = [this, &wait_callback, &t]
+// (transport::ProducerSocket &p, const core::Interest &interest) {
+// t.cancel();
+// t.expires_from_now(boost::posix_time::seconds(5));
+// t.async_wait(wait_callback);
+// };
+//
+// p->setSocketOption(transport::ProducerCallbacksOptions::INTEREST_INPUT,
+// (transport::ProducerInterestCallback) interest_enter_callback);
+//
+// t.async_wait(wait_callback);
+//
+// p->serveForever();
+//
+// std::unique_lock<std::mutex> lock(thread_list_mtx_);
+// icn_producers_.erase(request_name);
+// });
+//
+// t.detach();
+//}
+
+}
+
+} \ No newline at end of file
diff --git a/icnet/http/icnet_http_server_acceptor.h b/icnet/http/icnet_http_server_acceptor.h
new file mode 100644
index 00000000..2d0b7f25
--- /dev/null
+++ b/icnet/http/icnet_http_server_acceptor.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2017 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 "icnet_transport_socket_consumer.h"
+#include "icnet_transport_socket_producer.h"
+#include "icnet_http_default_values.h"
+#include "icnet_http_server_publisher.h"
+
+#include <vector>
+#include <functional>
+
+#define HTTP_VERSION "1.0"
+
+namespace icnet {
+
+namespace http {
+
+//typedef std::vector<uint8_t> HTTPResponse;
+typedef std::vector<uint8_t> HttpRequest;
+typedef std::function<void(std::shared_ptr<HTTPServerPublisher> &, const uint8_t *, std::size_t)> OnHttpRequest;
+
+class HTTPServerAcceptor {
+ public:
+ HTTPServerAcceptor(std::string &&server_locator, OnHttpRequest callback);
+ HTTPServerAcceptor(std::string &server_locator, OnHttpRequest callback);
+
+ void listen(bool async);
+
+ HttpRequest &&request();
+
+// void asyncSendResponse();
+
+// HTTPClientConnection& get(std::string &url, HTTPHeaders headers = {}, HTTPPayload payload = {});
+//
+// HTTPResponse&& response();
+
+ private:
+
+ void processIncomingInterest(transport::ProducerSocket &p, const transport::Interest &interest);
+
+ OnHttpRequest callback_;
+ HttpRequest request_;
+ std::shared_ptr<transport::ProducerSocket> acceptor_producer_;
+};
+
+} // end namespace http
+
+} // end namespace icnet \ No newline at end of file
diff --git a/icnet/http/icnet_http_server_publisher.cc b/icnet/http/icnet_http_server_publisher.cc
new file mode 100644
index 00000000..8ff86459
--- /dev/null
+++ b/icnet/http/icnet_http_server_publisher.cc
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2017 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 "icnet_http_server_publisher.h"
+
+namespace icnet {
+
+namespace http {
+
+HTTPServerPublisher::HTTPServerPublisher(const transport::Name &content_name)
+ : content_name_(content_name) {
+ // Create a new publisher
+ producer_ = std::unique_ptr<transport::ProducerSocket>(new transport::ProducerSocket(content_name));
+ producer_->attach();
+}
+
+HTTPServerPublisher::~HTTPServerPublisher() {
+ this->timer_->cancel();
+}
+
+HTTPServerPublisher &HTTPServerPublisher::setTimeout(uint32_t timeout) {
+ std::shared_ptr<transport::Portal> portal;
+ producer_->getSocketOption(transport::GeneralTransportOptions::PORTAL, portal);
+ timer_ = std::unique_ptr<boost::asio::deadline_timer>(new boost::asio::deadline_timer(portal->getIoService(),
+ boost::posix_time::seconds(
+ timeout)));
+
+ wait_callback_ = [this](const boost::system::error_code e) {
+ if (!e) {
+ producer_->stop();
+ }
+ };
+
+ interest_enter_callback_ = [this, timeout](transport::ProducerSocket &p, const transport::Interest &interest) {
+ this->timer_->cancel();
+ this->timer_->expires_from_now(boost::posix_time::seconds(timeout));
+ this->timer_->async_wait(wait_callback_);
+ };
+
+ producer_->setSocketOption(transport::ProducerCallbacksOptions::INTEREST_INPUT,
+ (transport::ProducerInterestCallback) interest_enter_callback_);
+
+ timer_->async_wait(wait_callback_);
+
+ return *this;
+}
+
+void HTTPServerPublisher::publishContent(const uint8_t *buf, size_t buffer_size, const int response_id, bool is_last) {
+ if (producer_) {
+ std::cout << "Replying to " << content_name_ << std::endl;
+ producer_->produce(content_name_, buf, buffer_size, response_id, is_last);
+ }
+}
+
+void HTTPServerPublisher::serveClients() {
+ producer_->serveForever();
+}
+
+void HTTPServerPublisher::stop() {
+ std::shared_ptr<transport::Portal> portal_ptr;
+ producer_->getSocketOption(transport::GeneralTransportOptions::PORTAL, portal_ptr);
+ portal_ptr->getIoService().stop();
+}
+
+}
+
+} \ No newline at end of file
diff --git a/icnet/http/icnet_http_server_publisher.h b/icnet/http/icnet_http_server_publisher.h
new file mode 100644
index 00000000..933d20c8
--- /dev/null
+++ b/icnet/http/icnet_http_server_publisher.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2017 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 "icnet_transport_socket_consumer.h"
+#include "icnet_transport_socket_producer.h"
+#include "icnet_http_default_values.h"
+
+#include <vector>
+#include <functional>
+
+#define HTTP_VERSION "1.0"
+
+namespace icnet {
+
+namespace http {
+
+typedef std::vector<uint8_t> HttpRequest;
+typedef std::function<void(const boost::system::error_code e)> DeadlineTimerCallback;
+
+class HTTPServerPublisher {
+ public:
+ HTTPServerPublisher(const transport::Name &content_name);
+
+ ~HTTPServerPublisher();
+
+ void publishContent(const uint8_t *buf,
+ size_t buffer_size,
+ const int response_id,
+ bool is_last);
+
+ void serveClients();
+
+ void stop();
+
+ HTTPServerPublisher &setTimeout(uint32_t timeout);
+
+// HttpRequest&& request();
+
+// void sendResponse();
+
+// HTTPClientConnection& get(std::string &url, HTTPHeaders headers = {}, HTTPPayload payload = {});
+//
+// HTTPResponse&& response();
+
+ private:
+
+ void processIncomingInterest(transport::ProducerSocket &p, const transport::Interest &interest);
+
+ transport::Name content_name_;
+ std::unique_ptr<boost::asio::deadline_timer> timer_;
+ std::unique_ptr<transport::ProducerSocket> producer_;
+ transport::ProducerInterestCallback interest_enter_callback_;
+ DeadlineTimerCallback wait_callback_;
+};
+
+} // end namespace http
+
+} // end namespace icnet \ No newline at end of file
diff --git a/icnet/transport/icnet_common.h b/icnet/transport/icnet_transport_common.h
index d507b324..d507b324 100644
--- a/icnet/transport/icnet_common.h
+++ b/icnet/transport/icnet_transport_common.h
diff --git a/icnet/transport/icnet_content_store.cc b/icnet/transport/icnet_transport_content_store.cc
index 64694b20..a9f05658 100644
--- a/icnet/transport/icnet_content_store.cc
+++ b/icnet/transport/icnet_transport_content_store.cc
@@ -13,10 +13,12 @@
* limitations under the License.
*/
-#include "icnet_content_store.h"
+#include "icnet_transport_content_store.h"
namespace icnet {
+namespace transport {
+
ContentStore::ContentStore(std::size_t max_packets)
: max_content_store_size_(max_packets) {
}
@@ -73,4 +75,6 @@ std::size_t ContentStore::size() const {
return content_store_hash_table_.size();
}
+}
+
} // end namespace icnet \ No newline at end of file
diff --git a/icnet/transport/icnet_content_store.h b/icnet/transport/icnet_transport_content_store.h
index a626055d..8a2ed4c6 100644
--- a/icnet/transport/icnet_content_store.h
+++ b/icnet/transport/icnet_transport_content_store.h
@@ -16,12 +16,14 @@
#ifndef ICNET_CONTENT_STORE_H_
#define ICNET_CONTENT_STORE_H_
-#include "icnet_socket.h"
+#include "icnet_transport_socket.h"
#include <mutex>
namespace icnet {
+namespace transport {
+
typedef std::pair<std::shared_ptr<ContentObject>, std::list<std::reference_wrapper<const Name>>::iterator>
CcnxContentStoreEntry;
typedef std::list<std::reference_wrapper<const Name>> LRUList;
@@ -54,6 +56,8 @@ class ContentStore {
std::mutex cs_mutex_;
};
+} // end namespace transport
+
} // end namespace icnet
diff --git a/icnet/transport/icnet_download_observer.h b/icnet/transport/icnet_transport_download_observer.h
index 7b640a1c..15ed5436 100644
--- a/icnet/transport/icnet_download_observer.h
+++ b/icnet/transport/icnet_transport_download_observer.h
@@ -18,6 +18,8 @@
namespace icnet {
+namespace transport {
+
class IcnObserver {
public:
virtual ~IcnObserver() {
@@ -26,6 +28,8 @@ class IcnObserver {
virtual void notifyStats(double throughput) = 0;
};
+} // end namespace transport
+
} // end namespace icnet
#endif // ICNET_DOWNLOAD_OBSERVER_H_
diff --git a/icnet/transport/icnet_transport.cc b/icnet/transport/icnet_transport_protocol.cc
index 632d03c4..71b855eb 100644
--- a/icnet/transport/icnet_transport.cc
+++ b/icnet/transport/icnet_transport_protocol.cc
@@ -13,10 +13,12 @@
* limitations under the License.
*/
-#include "icnet_transport.h"
+#include "icnet_transport_protocol.h"
namespace icnet {
+namespace transport {
+
TransportProtocol::TransportProtocol(Socket *icn_socket)
: socket_(icn_socket), is_running_(false) {
}
@@ -29,4 +31,6 @@ bool TransportProtocol::isRunning() {
return is_running_;
}
+} // end namespace transport
+
} // end namespace icnet
diff --git a/icnet/transport/icnet_transport.h b/icnet/transport/icnet_transport_protocol.h
index 738634fb..5ad43fb5 100644
--- a/icnet/transport/icnet_transport.h
+++ b/icnet/transport/icnet_transport_protocol.h
@@ -16,10 +16,12 @@
#ifndef ICNET_TRANSPORT_PROTOCOL_H_
#define ICNET_TRANSPORT_PROTOCOL_H_
-#include "icnet_socket.h"
+#include "icnet_transport_socket.h"
namespace icnet {
+namespace transport {
+
class TransportProtocol {
public:
TransportProtocol(Socket *icn_socket);
@@ -38,6 +40,8 @@ class TransportProtocol {
bool is_running_;
};
-}
+} // end namespace transport
+
+} // end namespace icnet
#endif // ICNET_TRANSPORT_PROTOCOL_H_
diff --git a/icnet/transport/icnet_transport_raaqm.cc b/icnet/transport/icnet_transport_raaqm.cc
index 7216d29e..787631f4 100644
--- a/icnet/transport/icnet_transport_raaqm.cc
+++ b/icnet/transport/icnet_transport_raaqm.cc
@@ -21,6 +21,8 @@
namespace icnet {
+namespace transport {
+
RaaqmTransportProtocol::RaaqmTransportProtocol(Socket *icnet_socket)
: VegasTransportProtocol(icnet_socket), rate_estimator_(NULL) {
init();
@@ -560,4 +562,6 @@ RaaqmTransportProtocol::onInterest(const Interest &interest)
}
#endif
+} // end namespace transport
+
} // end namespace icnet
diff --git a/icnet/transport/icnet_transport_raaqm.h b/icnet/transport/icnet_transport_raaqm.h
index dc5e72bd..adf3d439 100644
--- a/icnet/transport/icnet_transport_raaqm.h
+++ b/icnet/transport/icnet_transport_raaqm.h
@@ -19,10 +19,12 @@
#include "icnet_transport_vegas.h"
#include "icnet_transport_vegas_rto_estimator.h"
#include "icnet_transport_raaqm_data_path.h"
-#include "icnet_rate_estimation.h"
+#include "icnet_transport_rate_estimation.h"
namespace icnet {
+namespace transport {
+
class RaaqmTransportProtocol : public VegasTransportProtocol {
public:
RaaqmTransportProtocol(Socket *icnet_socket);
@@ -95,6 +97,8 @@ class RaaqmTransportProtocol : public VegasTransportProtocol {
double avg_rtt_;
};
+} // end namespace transport
+
} // end namespace icnet
#endif // ICNET_RAAQM_TRANSPORT_PROTOCOL_H_
diff --git a/icnet/transport/icnet_transport_raaqm_data_path.cc b/icnet/transport/icnet_transport_raaqm_data_path.cc
index 1ff3f667..abe8db6c 100644
--- a/icnet/transport/icnet_transport_raaqm_data_path.cc
+++ b/icnet/transport/icnet_transport_raaqm_data_path.cc
@@ -20,6 +20,8 @@
namespace icnet {
+namespace transport {
+
RaaqmDataPath::RaaqmDataPath(double drop_factor,
double minimum_drop_probability,
unsigned new_timer,
@@ -209,4 +211,6 @@ bool RaaqmDataPath::isStale() {
return false;
}
+} // end namespace transport
+
} // end namespace icnet
diff --git a/icnet/transport/icnet_transport_raaqm_data_path.h b/icnet/transport/icnet_transport_raaqm_data_path.h
index 0093f84b..526c0231 100644
--- a/icnet/transport/icnet_transport_raaqm_data_path.h
+++ b/icnet/transport/icnet_transport_raaqm_data_path.h
@@ -31,6 +31,8 @@
namespace icnet {
+namespace transport {
+
class RaaqmDataPath {
public:
@@ -237,6 +239,8 @@ class RaaqmDataPath {
double alpha_;
};
+} // end namespace transport
+
} // end namespace icnet
#endif // ICNET_RAAQM_DATA_PATH_H_
diff --git a/icnet/transport/icnet_rate_estimation.cc b/icnet/transport/icnet_transport_rate_estimation.cc
index b378da06..79b5b3e2 100644
--- a/icnet/transport/icnet_rate_estimation.cc
+++ b/icnet/transport/icnet_transport_rate_estimation.cc
@@ -14,10 +14,12 @@
*/
-#include "icnet_rate_estimation.h"
+#include "icnet_transport_rate_estimation.h"
namespace icnet {
+namespace transport {
+
void *Timer(void *data) {
InterRttEstimator *estimator = (InterRttEstimator *) data;
@@ -108,7 +110,7 @@ void InterRttEstimator::onRttUpdate(double rtt) {
std::cerr << "Error allocating thread." << std::endl;
my_th_ = NULL;
}
- if (/*int err = */pthread_create(my_th_, NULL, icnet::Timer, (void *) this)) {
+ if (/*int err = */pthread_create(my_th_, NULL, Timer, (void *) this)) {
std::cerr << "Error creating the thread" << std::endl;
my_th_ = NULL;
}
@@ -320,5 +322,7 @@ void BatchingPacketsEstimator::onWindowDecrease(double win_current) {
gettimeofday(&(this->begin_), 0);
}
+} // end namespace transport
+
} // end namespace icnet
diff --git a/icnet/transport/icnet_rate_estimation.h b/icnet/transport/icnet_transport_rate_estimation.h
index 86b879c2..7916ccfa 100644
--- a/icnet/transport/icnet_rate_estimation.h
+++ b/icnet/transport/icnet_transport_rate_estimation.h
@@ -19,7 +19,7 @@
#include <unistd.h>
#include "icnet_transport_raaqm_data_path.h"
-#include "icnet_download_observer.h"
+#include "icnet_transport_download_observer.h"
#define BATCH 50
#define KV 20
@@ -28,6 +28,8 @@
namespace icnet {
+namespace transport {
+
class IcnRateEstimator {
public:
IcnRateEstimator() {
@@ -181,7 +183,9 @@ class SimpleEstimator : public IcnRateEstimator {
void *Timer(void *data);
-}// end namespace icnet
+} // end namespace transport
+
+} // end namespace icnet
#endif // ICNET_RATE_ESTIMATION_H_
diff --git a/icnet/transport/icnet_socket.h b/icnet/transport/icnet_transport_socket.h
index f1ce8da0..edfdf1e8 100644
--- a/icnet/transport/icnet_socket.h
+++ b/icnet/transport/icnet_transport_socket.h
@@ -16,10 +16,10 @@
#ifndef ICNET_SOCKET_H_
#define ICNET_SOCKET_H_
-#include "icnet_common.h"
-#include "icnet_socket_options_keys.h"
-#include "icnet_socket_options_default_values.h"
-#include "icnet_download_observer.h"
+#include "icnet_transport_common.h"
+#include "icnet_transport_socket_options_keys.h"
+#include "icnet_transport_socket_options_default_values.h"
+#include "icnet_transport_download_observer.h"
#define SOCKET_OPTION_GET 0
#define SOCKET_OPTION_NOT_GET 1
@@ -31,6 +31,8 @@
namespace icnet {
+namespace transport {
+
class ConsumerSocket;
class ProducerSocket;
@@ -45,7 +47,7 @@ typedef ccnx::PayloadType PayloadType;
typedef ccnx::Array Array;
typedef std::function<void(ConsumerSocket &, const Interest &)> ConsumerInterestCallback;
-typedef std::function<void(ConsumerSocket &, const uint8_t *, size_t)> ConsumerContentCallback;
+typedef std::function<void(ConsumerSocket &, std::vector<uint8_t> &&)> ConsumerContentCallback;
typedef std::function<void(ConsumerSocket &, const ContentObject &)> ConsumerContentObjectCallback;
typedef std::function<bool(ConsumerSocket &, const ContentObject &)> ConsumerContentObjectVerificationCallback;
typedef std::function<void(ConsumerSocket &, const Manifest &)> ConsumerManifestCallback;
@@ -119,6 +121,8 @@ class Socket {
};
};
+} // end namespace transport
+
} // namespace icnet
#endif // ICNET_SOCKET_H_
diff --git a/icnet/transport/icnet_socket_consumer.cc b/icnet/transport/icnet_transport_socket_consumer.cc
index 2aec571b..21fa7327 100644
--- a/icnet/transport/icnet_socket_consumer.cc
+++ b/icnet/transport/icnet_transport_socket_consumer.cc
@@ -13,10 +13,12 @@
* limitations under the License.
*/
-#include "icnet_socket_consumer.h"
+#include "icnet_transport_socket_consumer.h"
namespace icnet {
+namespace transport {
+
ConsumerSocket::ConsumerSocket(Name prefix, int protocol)
: is_running_(false),
name_prefix_(prefix),
@@ -611,4 +613,6 @@ int ConsumerSocket::getSocketOption(int socket_option_key, IcnObserver **socket_
}
}
+} // end namespace transport
+
} // end namespace icnet
diff --git a/icnet/transport/icnet_socket_consumer.h b/icnet/transport/icnet_transport_socket_consumer.h
index 6b9ec811..59a3a8cb 100644
--- a/icnet/transport/icnet_socket_consumer.h
+++ b/icnet/transport/icnet_transport_socket_consumer.h
@@ -16,9 +16,9 @@
#ifndef ICNET_CONSUMER_SOCKET_H_
#define ICNET_CONSUMER_SOCKET_H_
-#include "icnet_common.h"
-#include "icnet_socket.h"
-#include "icnet_transport.h"
+#include "icnet_transport_common.h"
+#include "icnet_transport_socket.h"
+#include "icnet_transport_protocol.h"
#include "icnet_transport_raaqm.h"
#include "icnet_transport_vegas.h"
@@ -27,6 +27,8 @@
namespace icnet {
+namespace transport {
+
class ConsumerSocket : public Socket {
public:
explicit ConsumerSocket(const Name prefix, int protocol);
@@ -156,6 +158,8 @@ class ConsumerSocket : public Socket {
bool rtt_stats_;
};
+} // end namespace transport
+
} // end namespace icnet
#endif // ICNET_CONSUMER_SOCKET_H_
diff --git a/icnet/transport/icnet_socket_options_default_values.h b/icnet/transport/icnet_transport_socket_options_default_values.h
index 4f6d68e9..6214fc96 100644
--- a/icnet/transport/icnet_socket_options_default_values.h
+++ b/icnet/transport/icnet_transport_socket_options_default_values.h
@@ -18,6 +18,8 @@
namespace icnet {
+namespace transport {
+
namespace default_values {
const int interest_lifetime = 1000; // milliseconds
@@ -56,6 +58,8 @@ const int max_content_object_size = 8096;
} // end namespace default_values
+} // end namespace transport
+
} // end namespace icnet
#endif // ICNET_SOCKET_OPTIONS_DEFAULT_VALUES_H_
diff --git a/icnet/transport/icnet_socket_options_keys.h b/icnet/transport/icnet_transport_socket_options_keys.h
index 4b82f67a..460e8383 100644
--- a/icnet/transport/icnet_socket_options_keys.h
+++ b/icnet/transport/icnet_transport_socket_options_keys.h
@@ -18,6 +18,8 @@
namespace icnet {
+namespace transport {
+
typedef enum {
RAAQM = 0, VEGAS = 1
} TransportProtocolAlgorithms;
@@ -90,6 +92,8 @@ typedef enum {
SHA_256 = 701, RSA_256 = 702,
} SignatureType;
+} // end namespace transport
+
} // end namespace icnet
#endif // ICNET_TRANSPORT_OPTIONS_KEYS_H_
diff --git a/icnet/transport/icnet_socket_producer.cc b/icnet/transport/icnet_transport_socket_producer.cc
index 994488a0..190580f8 100644
--- a/icnet/transport/icnet_socket_producer.cc
+++ b/icnet/transport/icnet_transport_socket_producer.cc
@@ -13,10 +13,12 @@
* limitations under the License.
*/
-#include "icnet_socket_producer.h"
+#include "icnet_transport_socket_producer.h"
namespace icnet {
+namespace transport {
+
ProducerSocket::ProducerSocket(Name prefix)
: portal_(new Portal()),
name_prefix_(prefix),
@@ -69,6 +71,10 @@ void ProducerSocket::serveForever() {
}
}
+void ProducerSocket::stop() {
+ portal_->stopEventsLoop();
+}
+
void ProducerSocket::dispatch() {
// Check that the INTEREST_INPUT callback is set.
if (on_interest_input_ == VOID_HANDLER) {
@@ -98,7 +104,7 @@ void ProducerSocket::passContentObjectToCallbacks(const std::shared_ptr<ContentO
if (!making_manifest_) {
on_content_object_to_sign_(*this, *content_object);
} else {
- if (content_object->getContentType() == PayloadType::MANIFEST) {
+ if (content_object->getPayloadType() == PayloadType::MANIFEST) {
on_content_object_to_sign_(*this, *content_object);
} else {
content_object->signWithSha256(key_locator_);
@@ -140,19 +146,19 @@ void ProducerSocket::produce(ContentObject &content_object) {
portal_->sendContentObject(content_object);
}
-void ProducerSocket::produce(Name suffix, const uint8_t *buf, size_t buffer_size, const int response_id, bool is_last) {
+void ProducerSocket::produce(Name name, const uint8_t *buf, size_t buffer_size, const int response_id, bool is_last) {
if (buffer_size == 0) {
return;
}
- int bytes_segmented = 0;
+ if (name.empty() || !name_prefix_.isPrefixOf(name)) {
+ return;
+ }
- Name name(name_prefix_);
+ int bytes_segmented = 0;
- if (!suffix.empty()) {
- name.append(suffix);
- }
+ std::cout << name.toString() << std::endl;
size_t bytes_occupied_by_name = name.size();
@@ -192,8 +198,8 @@ void ProducerSocket::produce(Name suffix, const uint8_t *buf, size_t buffer_size
Name manifest_name(name_prefix_);
- if (!suffix.empty()) {
- manifest_name.append(suffix);
+ if (!name.empty()) {
+ manifest_name.append(name);
}
manifest_name.appendSegment(current_segment);
@@ -717,4 +723,6 @@ int ProducerSocket::setSocketOption(int socket_option_key, IcnObserver *socket_o
return SOCKET_OPTION_NOT_SET;
}
+} // end namespace transport
+
} // end namespace icnet
diff --git a/icnet/transport/icnet_socket_producer.h b/icnet/transport/icnet_transport_socket_producer.h
index d709e305..4f98f9e2 100644
--- a/icnet/transport/icnet_socket_producer.h
+++ b/icnet/transport/icnet_transport_socket_producer.h
@@ -16,8 +16,8 @@
#ifndef ICNET_PRODUCER_SOCKET_H_
#define ICNET_PRODUCER_SOCKET_H_
-#include "icnet_socket.h"
-#include "icnet_content_store.h"
+#include "icnet_transport_socket.h"
+#include "icnet_transport_content_store.h"
#include <queue>
#include <mutex>
@@ -31,6 +31,8 @@
namespace icnet {
+namespace transport {
+
class ProducerSocket : public Socket {
public:
@@ -42,7 +44,7 @@ class ProducerSocket : public Socket {
void dispatch();
- void produce(Name suffix, const uint8_t *buffer, size_t buffer_size, const int request_id = 0, bool is_last = false);
+ void produce(Name name, const uint8_t *buffer, size_t buffer_size, const int request_id = 0, bool is_last = false);
void produce(ContentObject &content_object);
@@ -52,6 +54,8 @@ class ProducerSocket : public Socket {
void serveForever();
+ void stop();
+
void onInterest(const Name &name, const Interest &interest);
int setSocketOption(int socket_option_key, int socket_option_value);
@@ -167,6 +171,8 @@ class ProducerSocket : public Socket {
};
-}
+} // end namespace transport
+
+} // end namespace icnet
#endif // ICNET_PRODUCER_SOCKET_H_
diff --git a/icnet/transport/icnet_transport_vegas.cc b/icnet/transport/icnet_transport_vegas.cc
index d5a3c500..dd5c7c90 100644
--- a/icnet/transport/icnet_transport_vegas.cc
+++ b/icnet/transport/icnet_transport_vegas.cc
@@ -14,10 +14,12 @@
*/
#include "icnet_transport_vegas.h"
-#include "icnet_socket_consumer.h"
+#include "icnet_transport_socket_consumer.h"
namespace icnet {
+namespace transport {
+
VegasTransportProtocol::VegasTransportProtocol(Socket *icnet_socket)
: TransportProtocol(icnet_socket),
is_final_block_number_discovered_(false),
@@ -139,9 +141,9 @@ void VegasTransportProtocol::onContentSegment(const Interest &interest, ContentO
on_interest_satisfied(*dynamic_cast<ConsumerSocket *>(socket_), const_cast<Interest &>(interest));
}
- if (content_object.getContentType() == PayloadType::MANIFEST) {
+ if (content_object.getPayloadType() == PayloadType::MANIFEST) {
onManifest(interest, content_object);
- } else if (content_object.getContentType() == PayloadType::DATA) {
+ } else if (content_object.getPayloadType() == PayloadType::DATA) {
onContentObject(interest, content_object);
} // TODO InterestReturn
@@ -381,8 +383,7 @@ void VegasTransportProtocol::copyContent(ContentObject &content_object) {
socket_->getSocketOption(CONTENT_RETRIEVED, on_payload);
if (on_payload != VOID_HANDLER) {
on_payload(*dynamic_cast<ConsumerSocket *>(socket_),
- (uint8_t *) (content_buffer_.data()),
- content_buffer_.size());
+ std::move(content_buffer_));
}
//reduce window size to prevent its speculative growth in case when consume() is called in loop
@@ -401,7 +402,7 @@ void VegasTransportProtocol::reassemble() {
uint64_t index = last_reassembled_segment_ % default_values::default_buffer_size;
while (receive_buffer_[index % default_values::default_buffer_size]) {
- if (receive_buffer_[index % default_values::default_buffer_size]->getContentType() == PayloadType::DATA) {
+ if (receive_buffer_[index % default_values::default_buffer_size]->getPayloadType() == PayloadType::DATA) {
copyContent(*receive_buffer_[index % default_values::default_buffer_size]);
}
@@ -484,4 +485,6 @@ void VegasTransportProtocol::removeAllPendingInterests() {
portal_->clear();
}
-} // namespace icn-interface
+} // end namespace transport
+
+} // end namespace icnet
diff --git a/icnet/transport/icnet_transport_vegas.h b/icnet/transport/icnet_transport_vegas.h
index a47050d8..cec2aa5a 100644
--- a/icnet/transport/icnet_transport_vegas.h
+++ b/icnet/transport/icnet_transport_vegas.h
@@ -16,11 +16,13 @@
#ifndef ICNET_VEGAS_TRANSPORT_PROTOCOL_H_
#define ICNET_VEGAS_TRANSPORT_PROTOCOL_H_
-#include "icnet_transport.h"
+#include "icnet_transport_protocol.h"
#include "icnet_transport_vegas_rto_estimator.h"
namespace icnet {
+namespace transport {
+
class VegasTransportProtocol : public TransportProtocol {
public:
@@ -103,6 +105,8 @@ class VegasTransportProtocol : public TransportProtocol {
std::unordered_map<uint64_t, bool> fast_retransmitted_segments;
};
+} // end namespace transport
+
} // end namespace icnet
diff --git a/icnet/transport/icnet_transport_vegas_rto_estimator.cc b/icnet/transport/icnet_transport_vegas_rto_estimator.cc
index 6653518e..f1c10637 100644
--- a/icnet/transport/icnet_transport_vegas_rto_estimator.cc
+++ b/icnet/transport/icnet_transport_vegas_rto_estimator.cc
@@ -14,10 +14,12 @@
*/
#include "icnet_transport_vegas_rto_estimator.h"
-#include "icnet_socket_options_default_values.h"
+#include "icnet_transport_socket_options_default_values.h"
namespace icnet {
+namespace transport {
+
RtoEstimator::RtoEstimator(Duration min_rto)
: smoothed_rtt_(RtoEstimator::getInitialRtt().count()),
rtt_variation_(0),
@@ -44,4 +46,6 @@ RtoEstimator::Duration RtoEstimator::computeRto() const {
return Duration(static_cast<Duration::rep>(rto));
}
+} // end namespace transport
+
} // end namespace icnet \ No newline at end of file
diff --git a/icnet/transport/icnet_transport_vegas_rto_estimator.h b/icnet/transport/icnet_transport_vegas_rto_estimator.h
index 7b18533c..799d6fbc 100644
--- a/icnet/transport/icnet_transport_vegas_rto_estimator.h
+++ b/icnet/transport/icnet_transport_vegas_rto_estimator.h
@@ -16,12 +16,14 @@
#ifndef ICNET_VEGAS_TRANSPORT_PROTOCOL_RTT_ESTIMATOR_H_
#define ICNET_VEGAS_TRANSPORT_PROTOCOL_RTT_ESTIMATOR_H_
-#include "icnet_common.h"
+#include "icnet_transport_common.h"
// Implementation inspired from RFC6298 (https://tools.ietf.org/search/rfc6298#ref-JK88)
namespace icnet {
+namespace transport {
+
class RtoEstimator {
public:
typedef std::chrono::microseconds Duration;
@@ -43,6 +45,8 @@ class RtoEstimator {
double last_rto_;
};
+} // end namespace transport
+
} // end namespace icnet
diff --git a/icnet/utils/icnet_utils_array.cc b/icnet/utils/icnet_utils_array.cc
new file mode 100644
index 00000000..413119cb
--- /dev/null
+++ b/icnet/utils/icnet_utils_array.cc
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2017 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 "icnet_utils_array.h"
+
+namespace icnet {
+
+namespace utils {
+
+Array::Array(const void *array, size_t size) {
+ this->array_ = array;
+ this->size_ = size;
+}
+
+Array::Array() {
+ this->array_ = nullptr;
+ this->size_ = 0;
+}
+
+const void *Array::data() const {
+ return array_;
+}
+
+std::size_t Array::size() const {
+ return size_;
+}
+
+Array &Array::setData(const void *data) {
+ array_ = data;
+ return *this;
+}
+
+Array &Array::setSize(std::size_t size) {
+ size_ = size;
+ return *this;
+}
+
+}
+
+} \ No newline at end of file
diff --git a/icnet/utils/icnet_utils_array.h b/icnet/utils/icnet_utils_array.h
new file mode 100644
index 00000000..f13c0b47
--- /dev/null
+++ b/icnet/utils/icnet_utils_array.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2017 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 <cstddef>
+
+namespace icnet {
+
+namespace utils {
+
+class Array {
+ public:
+ explicit Array(const void *array, size_t size);
+
+ Array();
+
+ const void *data() const;
+
+ std::size_t size() const;
+
+ Array &setData(const void *data);
+
+ Array &setSize(std::size_t size);
+
+ private:
+ std::size_t size_;
+ const void *array_;
+};
+
+}
+
+}
diff --git a/icnet/utils/icnet_utils_daemonizator.cc b/icnet/utils/icnet_utils_daemonizator.cc
new file mode 100644
index 00000000..2bb6dd05
--- /dev/null
+++ b/icnet/utils/icnet_utils_daemonizator.cc
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2017 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 "icnet_utils_daemonizator.h"
+#include "icnet_errors_runtime_exception.h"
+#include <cstdlib>
+#include <unistd.h>
+#include <iostream>
+#include <sys/stat.h>
+
+namespace icnet {
+
+namespace utils {
+
+void Daemonizator::daemonize() {
+ pid_t process_id = 0;
+ pid_t sid = 0;
+
+ // Create child process
+ process_id = fork();
+
+ // Indication of fork() failure
+ if (process_id < 0) {
+ throw errors::RuntimeException("Fork failed.");
+ }
+
+ // PARENT PROCESS. Need to kill it.
+ if (process_id > 0) {
+ std::cout << "Process id of child process " << process_id << std::endl;
+ // return success in exit status
+ exit(EXIT_SUCCESS);
+ }
+
+ // unmask the file mode
+ umask(0);
+
+ // set new session
+ sid = setsid();
+ if (sid < 0) {
+ // Return failure
+ exit(EXIT_FAILURE);
+ }
+
+ // Change the current working directory to root.
+ int ret = chdir("/");
+
+ if (ret < 0) {
+ throw errors::RuntimeException("Error changing working directory to root");
+ }
+
+ // Close stdin. stdout and stderr
+
+ close(STDIN_FILENO);
+ close(STDOUT_FILENO);
+ close(STDERR_FILENO);
+
+ // Really start application
+}
+
+}
+
+}
diff --git a/icnet/utils/icnet_utils_daemonizator.h b/icnet/utils/icnet_utils_daemonizator.h
new file mode 100644
index 00000000..20cd80bb
--- /dev/null
+++ b/icnet/utils/icnet_utils_daemonizator.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2017 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
+
+namespace icnet {
+
+namespace utils {
+
+class Daemonizator {
+ public:
+ static void daemonize();
+};
+
+}
+
+} \ No newline at end of file
diff --git a/icnet/utils/icnet_utils_hash.cc b/icnet/utils/icnet_utils_hash.cc
new file mode 100644
index 00000000..39dd0229
--- /dev/null
+++ b/icnet/utils/icnet_utils_hash.cc
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2017 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 "icnet_utils_hash.h"
+
+namespace icnet {
+
+namespace utils {
+
+uint32_t Hash::hash32(const void *data, std::size_t len) {
+ const uint32_t fnv1a_offset = 0x811C9DC5;
+ return Hash::cumulativeHash32(data, len, fnv1a_offset);
+}
+
+uint32_t Hash::cumulativeHash32(const void *data, std::size_t len, uint32_t lastValue) {
+ // Standard FNV 32-bit prime: see http://www.isthe.com/chongo/tech/comp/fnv/#FNV-param
+ const uint32_t fnv1a_prime = 0x01000193;
+ uint32_t hash = lastValue;
+
+ const char *chardata = (char *) data;
+
+ for (std::size_t i = 0; i < len; i++) {
+ hash = hash ^ chardata[i];
+ hash = hash * fnv1a_prime;
+ }
+
+ return hash;
+}
+
+uint64_t Hash::hash64(const void *data, std::size_t len) {
+ // Standard FNV 64-bit offset: see http://www.isthe.com/chongo/tech/comp/fnv/#FNV-param
+ const uint64_t fnv1a_offset = 0xCBF29CE484222325ULL;
+ return cumulativeHash64(data, len, fnv1a_offset);
+}
+
+uint64_t Hash::cumulativeHash64(const void *data, std::size_t len, uint64_t lastValue) {
+ // Standard FNV 64-bit prime: see http://www.isthe.com/chongo/tech/comp/fnv/#FNV-param
+ const uint64_t fnv1a_prime = 0x00000100000001B3ULL;
+ uint64_t hash = lastValue;
+ const char *chardata = (char *) data;
+
+ for (std::size_t i = 0; i < len; i++) {
+ hash = hash ^ chardata[i];
+ hash = hash * fnv1a_prime;
+ }
+
+ return hash;
+}
+
+}
+
+} \ No newline at end of file
diff --git a/icnet/utils/icnet_utils_hash.h b/icnet/utils/icnet_utils_hash.h
new file mode 100644
index 00000000..9ae01f39
--- /dev/null
+++ b/icnet/utils/icnet_utils_hash.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2017 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 <cstdint>
+#include <cstddef>
+
+namespace icnet {
+
+namespace utils {
+
+//const uint32_t FNV1A_PRIME_32 = 0x01000193;
+//const uint32_t FNV1A_OFFSET_32 = 0x811C9DC5;
+//const uint64_t FNV1A_PRIME_64 = 0x00000100000001B3ULL;
+//const uint64_t FNV1A_OFFSET_64 = 0xCBF29CE484222325ULL;
+
+class Hash {
+ public:
+ static uint32_t cumulativeHash32(const void *data, std::size_t len, uint32_t lastValue);
+ static uint64_t cumulativeHash64(const void *data, std::size_t len, uint64_t lastValue);
+ static uint32_t hash32(const void *data, std::size_t len);
+ static uint64_t hash64(const void *data, std::size_t len);
+ private:
+
+};
+
+}
+
+} \ No newline at end of file
diff --git a/icnet/utils/icnet_utils_string_tokenizer.cc b/icnet/utils/icnet_utils_string_tokenizer.cc
new file mode 100644
index 00000000..ead1052a
--- /dev/null
+++ b/icnet/utils/icnet_utils_string_tokenizer.cc
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2017 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 <icnet_errors_tokenizer_exception.h>
+#include "icnet_utils_string_tokenizer.h"
+#include "icnet_errors.h"
+
+namespace icnet {
+
+namespace utils {
+
+StringTokenizer::StringTokenizer(const std::string &str)
+ : str_(str), delimiter_(" ") {
+}
+
+StringTokenizer::StringTokenizer(const std::string &str, const std::string &delim)
+ : str_(str), delimiter_(delim) {
+}
+
+bool StringTokenizer::hasMoreTokens() {
+ return str_.find(delimiter_) != std::string::npos && !str_.empty();
+}
+
+std::string StringTokenizer::nextToken() {
+ unsigned long pos = str_.find(delimiter_);
+
+ bool token_found = std::string::npos != pos;
+
+ if (!token_found && str_.empty()) {
+ throw errors::TokenizerException();
+ }
+
+ std::string token = str_.substr(0, pos);
+ str_.erase(0, token_found ? pos + delimiter_.length() : pos);
+
+ return token;
+}
+
+}
+} \ No newline at end of file
diff --git a/icnet/utils/icnet_utils_string_tokenizer.h b/icnet/utils/icnet_utils_string_tokenizer.h
new file mode 100644
index 00000000..7dc6b458
--- /dev/null
+++ b/icnet/utils/icnet_utils_string_tokenizer.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2017 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 <string>
+
+namespace icnet {
+
+namespace utils {
+
+class StringTokenizer {
+ public:
+ StringTokenizer(const std::string &str);
+ StringTokenizer(const std::string &str, const std::string &delim);
+
+ bool hasMoreTokens();
+ std::string nextToken();
+ private:
+ std::string str_;
+ std::string delimiter_;
+};
+
+}
+
+}
diff --git a/icnet/utils/icnet_utils_uri.cc b/icnet/utils/icnet_utils_uri.cc
new file mode 100644
index 00000000..8268bdf9
--- /dev/null
+++ b/icnet/utils/icnet_utils_uri.cc
@@ -0,0 +1,137 @@
+/*
+ * Copyright (c) 2017 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 "icnet_utils_uri.h"
+#include "icnet_errors_runtime_exception.h"
+
+namespace icnet {
+
+namespace utils {
+
+Uri::Uri() {
+
+}
+
+Uri &Uri::parse(const std::string &uri) {
+ if (uri.length() == 0) {
+ throw errors::RuntimeException("Malformed URI.");
+ }
+
+ iterator_t uriEnd = uri.end();
+
+ // get query start
+ iterator_t queryStart = std::find(uri.begin(), uriEnd, '?');
+
+ // protocol
+ iterator_t protocolStart = uri.begin();
+ iterator_t protocolEnd = std::find(protocolStart, uriEnd, ':'); //"://");
+
+ if (protocolEnd != uriEnd) {
+ std::string prot = &*(protocolEnd);
+ if ((prot.length() > 3) && (prot.substr(0, 3) == "://")) {
+ protocol_ = std::string(protocolStart, protocolEnd);
+ protocolEnd += 3; // ://
+ } else {
+ protocolEnd = uri.begin(); // no protocol
+ }
+ } else {
+ protocolEnd = uri.begin(); // no protocol
+ }
+ // host
+ iterator_t hostStart = protocolEnd;
+ iterator_t pathStart = std::find(hostStart, uriEnd, '/'); // get pathStart
+
+ iterator_t hostEnd = std::find(protocolEnd,
+ (pathStart != uriEnd) ? pathStart : queryStart,
+ ':'); // check for port
+
+ locator_ = std::string(hostStart, hostEnd);
+
+ // port
+ if ((hostEnd != uriEnd) && ((&*(hostEnd))[0] == ':')) {
+ hostEnd++;
+ iterator_t portEnd = (pathStart != uriEnd) ? pathStart : queryStart;
+ port_ = std::string(hostEnd, portEnd);
+ }
+
+ // path
+ if (pathStart != uriEnd) {
+ path_ = std::string(pathStart, queryStart);
+ }
+ // query
+ if (queryStart != uriEnd) {
+ query_string_ = std::string(queryStart, uri.end());
+ }
+
+ return *this;
+
+}
+
+Uri &Uri::parseProtocolAndLocator(const std::string &locator) {
+
+ iterator_t total_end = locator.end();
+
+ // protocol
+ iterator_t protocol_start = locator.begin();
+ iterator_t protocol_end = std::find(protocol_start, total_end, ':'); //"://");
+
+ if (protocol_end != total_end) {
+ std::string prot = &*(protocol_end);
+ if ((prot.length() > 3) && (prot.substr(0, 3) == "://")) {
+ protocol_ = std::string(protocol_start, protocol_end);
+ protocol_end += 3; // ://
+ } else {
+ throw errors::RuntimeException("Malformed locator. (Missing \"://\")");
+ }
+ } else {
+ throw errors::RuntimeException("Malformed locator. No protocol specified.");
+ }
+
+ // locator
+ iterator_t host_start = protocol_end;
+ iterator_t host_end = std::find(protocol_end, total_end, '/');
+
+ if (host_start == host_end) {
+ throw errors::RuntimeException("Malformed locator. Locator name is missing");
+ }
+
+ locator_ = std::string(host_start, host_end);
+
+ return *this;
+}
+
+std::string Uri::getLocator() {
+ return locator_;
+}
+
+std::string Uri::getPath() {
+ return path_;
+}
+
+std::string Uri::getPort() {
+ return port_;
+}
+
+std::string Uri::getProtocol() {
+ return protocol_;
+}
+
+std::string Uri::getQueryString() {
+ return query_string_;
+}
+
+} // end namespace utils
+
+} // end namespace icnet \ No newline at end of file
diff --git a/icnet/utils/icnet_utils_uri.h b/icnet/utils/icnet_utils_uri.h
new file mode 100644
index 00000000..38172282
--- /dev/null
+++ b/icnet/utils/icnet_utils_uri.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2017 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 <string>
+#include <algorithm> // find
+
+namespace icnet {
+
+namespace utils {
+
+class Uri {
+
+ typedef std::string::const_iterator iterator_t;
+
+ public:
+ Uri();
+
+ Uri &parse(const std::string &uri);
+
+ Uri &parseProtocolAndLocator(const std::string &locator);
+
+ std::string getQueryString();
+
+ std::string getPath();
+
+ std::string getProtocol();
+
+ std::string getLocator();
+
+ std::string getPort();
+ private:
+ std::string query_string_, path_, protocol_, locator_, port_;
+}; // uri
+
+}
+
+} \ No newline at end of file