From 9e5f41ed6ebe64a789916794626485460078c420 Mon Sep 17 00:00:00 2001 From: Mauro Sardara Date: Sat, 19 Jan 2019 01:29:33 +0100 Subject: - Code style fix - Improved vpp binary api interface - Correction in object pool destructor - Fix error in Memif Connector Change-Id: Id1dd9219fc1ac0b3717ae019ebff17373bebc635 Signed-off-by: Mauro Sardara --- cmake/Modules/BuildMacros.cmake | 9 +- lib/src/name.h | 9 +- .../src/hicn/transport/core/CMakeLists.txt | 3 - libtransport/src/hicn/transport/core/connector.cc | 0 libtransport/src/hicn/transport/core/connector.h | 6 +- .../src/hicn/transport/core/content_object.cc | 0 .../src/hicn/transport/core/content_object.h | 0 libtransport/src/hicn/transport/core/facade.h | 0 .../src/hicn/transport/core/forwarder_interface.h | 0 .../src/hicn/transport/core/hicn_binary_api.c | 85 +++++++++---------- .../src/hicn/transport/core/hicn_binary_api.h | 37 ++------- .../transport/core/hicn_forwarder_interface.cc | 2 +- .../hicn/transport/core/hicn_forwarder_interface.h | 0 .../src/hicn/transport/core/hicn_memif_api.c | 0 libtransport/src/hicn/transport/core/interest.cc | 0 libtransport/src/hicn/transport/core/interest.h | 0 .../src/hicn/transport/core/key_locator.cc | 42 ---------- libtransport/src/hicn/transport/core/key_locator.h | 48 ----------- .../src/hicn/transport/core/key_locator_type.h | 28 ------- libtransport/src/hicn/transport/core/manifest.cc | 0 libtransport/src/hicn/transport/core/manifest.h | 32 ++++---- .../src/hicn/transport/core/manifest_format.h | 76 ++++++++--------- .../hicn/transport/core/manifest_format_fixed.cc | 64 +++++++-------- .../hicn/transport/core/manifest_format_fixed.h | 46 +++++------ .../transport/core/manifest_format_json_jsoncpp.cc | 52 ++++++------ .../transport/core/manifest_format_json_jsoncpp.h | 54 ++++++------ .../manifest_format_json_libparc_deprecated.cc | 56 ++++++------- .../core/manifest_format_json_libparc_deprecated.h | 42 +++++----- .../src/hicn/transport/core/manifest_inline.h | 24 +++--- .../src/hicn/transport/core/memif_binary_api.c | 62 +++++++------- .../src/hicn/transport/core/memif_binary_api.h | 13 +-- .../src/hicn/transport/core/memif_connector.cc | 31 +++---- .../src/hicn/transport/core/memif_connector.h | 1 + libtransport/src/hicn/transport/core/name.cc | 0 libtransport/src/hicn/transport/core/name.h | 0 libtransport/src/hicn/transport/core/packet.cc | 28 +++---- libtransport/src/hicn/transport/core/packet.h | 4 +- .../src/hicn/transport/core/payload_type.h | 0 .../src/hicn/transport/core/pending_interest.cc | 0 .../src/hicn/transport/core/pending_interest.h | 0 libtransport/src/hicn/transport/core/portal.h | 2 +- libtransport/src/hicn/transport/core/prefix.cc | 0 libtransport/src/hicn/transport/core/prefix.h | 0 .../hicn/transport/core/raw_socket_connector.cc | 0 .../src/hicn/transport/core/raw_socket_connector.h | 0 .../hicn/transport/core/raw_socket_interface.cc | 0 .../src/hicn/transport/core/raw_socket_interface.h | 0 .../src/hicn/transport/core/socket_connector.cc | 0 .../src/hicn/transport/core/socket_connector.h | 0 .../hicn/transport/core/test/test_core_manifest.cc | 0 .../src/hicn/transport/core/vpp_binary_api.c | 60 ++++++++++---- .../src/hicn/transport/core/vpp_binary_api.h | 29 +++++-- .../hicn/transport/core/vpp_binary_api_internal.h | 33 +++++--- .../hicn/transport/core/vpp_forwarder_interface.cc | 96 +++++++++++++++------- .../hicn/transport/core/vpp_forwarder_interface.h | 0 .../transport/interfaces/full_duplex_socket.cc | 7 +- .../transport/interfaces/rtc_socket_producer.cc | 2 +- .../hicn/transport/interfaces/socket_consumer.cc | 6 +- libtransport/src/hicn/transport/protocols/rtc.cc | 40 ++++----- .../src/hicn/transport/protocols/rtc_data_path.h | 2 +- libtransport/src/hicn/transport/protocols/vegas.cc | 16 ++-- libtransport/src/hicn/transport/utils/identity.cc | 9 +- libtransport/src/hicn/transport/utils/log.cc | 8 +- libtransport/src/hicn/transport/utils/log.h | 4 +- .../src/hicn/transport/utils/object_pool.h | 11 ++- libtransport/src/hicn/transport/utils/signer.cc | 45 +++++----- libtransport/src/hicn/transport/utils/verifier.cc | 6 +- utils/src/hiperf.cc | 4 +- utils/src/ping_client.cc | 2 +- 69 files changed, 594 insertions(+), 642 deletions(-) mode change 100755 => 100644 libtransport/src/hicn/transport/core/connector.cc mode change 100755 => 100644 libtransport/src/hicn/transport/core/connector.h mode change 100755 => 100644 libtransport/src/hicn/transport/core/content_object.cc mode change 100755 => 100644 libtransport/src/hicn/transport/core/content_object.h mode change 100755 => 100644 libtransport/src/hicn/transport/core/facade.h mode change 100755 => 100644 libtransport/src/hicn/transport/core/forwarder_interface.h mode change 100755 => 100644 libtransport/src/hicn/transport/core/hicn_binary_api.c mode change 100755 => 100644 libtransport/src/hicn/transport/core/hicn_binary_api.h mode change 100755 => 100644 libtransport/src/hicn/transport/core/hicn_forwarder_interface.cc mode change 100755 => 100644 libtransport/src/hicn/transport/core/hicn_forwarder_interface.h delete mode 100755 libtransport/src/hicn/transport/core/hicn_memif_api.c mode change 100755 => 100644 libtransport/src/hicn/transport/core/interest.cc mode change 100755 => 100644 libtransport/src/hicn/transport/core/interest.h delete mode 100755 libtransport/src/hicn/transport/core/key_locator.cc delete mode 100755 libtransport/src/hicn/transport/core/key_locator.h delete mode 100755 libtransport/src/hicn/transport/core/key_locator_type.h mode change 100755 => 100644 libtransport/src/hicn/transport/core/manifest.cc mode change 100755 => 100644 libtransport/src/hicn/transport/core/manifest.h mode change 100755 => 100644 libtransport/src/hicn/transport/core/manifest_format.h mode change 100755 => 100644 libtransport/src/hicn/transport/core/manifest_format_fixed.cc mode change 100755 => 100644 libtransport/src/hicn/transport/core/manifest_format_fixed.h mode change 100755 => 100644 libtransport/src/hicn/transport/core/manifest_format_json_jsoncpp.cc mode change 100755 => 100644 libtransport/src/hicn/transport/core/manifest_format_json_jsoncpp.h mode change 100755 => 100644 libtransport/src/hicn/transport/core/manifest_format_json_libparc_deprecated.cc mode change 100755 => 100644 libtransport/src/hicn/transport/core/manifest_format_json_libparc_deprecated.h mode change 100755 => 100644 libtransport/src/hicn/transport/core/manifest_inline.h mode change 100755 => 100644 libtransport/src/hicn/transport/core/memif_binary_api.c mode change 100755 => 100644 libtransport/src/hicn/transport/core/memif_binary_api.h mode change 100755 => 100644 libtransport/src/hicn/transport/core/memif_connector.cc mode change 100755 => 100644 libtransport/src/hicn/transport/core/memif_connector.h mode change 100755 => 100644 libtransport/src/hicn/transport/core/name.cc mode change 100755 => 100644 libtransport/src/hicn/transport/core/name.h mode change 100755 => 100644 libtransport/src/hicn/transport/core/packet.cc mode change 100755 => 100644 libtransport/src/hicn/transport/core/packet.h mode change 100755 => 100644 libtransport/src/hicn/transport/core/payload_type.h mode change 100755 => 100644 libtransport/src/hicn/transport/core/pending_interest.cc mode change 100755 => 100644 libtransport/src/hicn/transport/core/pending_interest.h mode change 100755 => 100644 libtransport/src/hicn/transport/core/portal.h mode change 100755 => 100644 libtransport/src/hicn/transport/core/prefix.cc mode change 100755 => 100644 libtransport/src/hicn/transport/core/prefix.h mode change 100755 => 100644 libtransport/src/hicn/transport/core/raw_socket_connector.cc mode change 100755 => 100644 libtransport/src/hicn/transport/core/raw_socket_connector.h mode change 100755 => 100644 libtransport/src/hicn/transport/core/raw_socket_interface.cc mode change 100755 => 100644 libtransport/src/hicn/transport/core/raw_socket_interface.h mode change 100755 => 100644 libtransport/src/hicn/transport/core/socket_connector.cc mode change 100755 => 100644 libtransport/src/hicn/transport/core/socket_connector.h mode change 100755 => 100644 libtransport/src/hicn/transport/core/test/test_core_manifest.cc mode change 100755 => 100644 libtransport/src/hicn/transport/core/vpp_binary_api.c mode change 100755 => 100644 libtransport/src/hicn/transport/core/vpp_binary_api.h mode change 100755 => 100644 libtransport/src/hicn/transport/core/vpp_binary_api_internal.h mode change 100755 => 100644 libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc mode change 100755 => 100644 libtransport/src/hicn/transport/core/vpp_forwarder_interface.h mode change 100755 => 100644 libtransport/src/hicn/transport/interfaces/full_duplex_socket.cc mode change 100755 => 100644 libtransport/src/hicn/transport/interfaces/rtc_socket_producer.cc mode change 100755 => 100644 libtransport/src/hicn/transport/interfaces/socket_consumer.cc mode change 100755 => 100644 libtransport/src/hicn/transport/protocols/rtc.cc mode change 100755 => 100644 libtransport/src/hicn/transport/protocols/rtc_data_path.h mode change 100755 => 100644 libtransport/src/hicn/transport/protocols/vegas.cc mode change 100755 => 100644 libtransport/src/hicn/transport/utils/identity.cc mode change 100755 => 100644 libtransport/src/hicn/transport/utils/log.cc mode change 100755 => 100644 libtransport/src/hicn/transport/utils/log.h mode change 100755 => 100644 libtransport/src/hicn/transport/utils/signer.cc mode change 100755 => 100644 libtransport/src/hicn/transport/utils/verifier.cc diff --git a/cmake/Modules/BuildMacros.cmake b/cmake/Modules/BuildMacros.cmake index 14a82fab7..3630d2e26 100755 --- a/cmake/Modules/BuildMacros.cmake +++ b/cmake/Modules/BuildMacros.cmake @@ -19,7 +19,7 @@ macro(build_executable exec) cmake_parse_arguments(ARG "NO_INSTALL" "COMPONENT" - "SOURCES;LINK_LIBRARIES;DEPENDS;DEFINITIONS" + "SOURCES;LINK_LIBRARIES;DEPENDS;INCLUDE_DIRS;DEFINITIONS" ${ARGN} ) @@ -36,6 +36,13 @@ macro(build_executable exec) target_compile_definitions(${exec} PRIVATE ${ARG_DEFINITIONS}) endif() + if(ARG_INCLUDE_DIRS) + target_include_directories(${exec} BEFORE PUBLIC + ${ARG_INCLUDE_DIRS} + ${PROJECT_BINARY_DIR} + ) + endif() + if(NOT ARG_NO_INSTALL) install(TARGETS ${exec} DESTINATION bin COMPONENT ${ARG_COMPONENT}) endif() diff --git a/lib/src/name.h b/lib/src/name.h index 0a55fedc6..ffcb4a451 100755 --- a/lib/src/name.h +++ b/lib/src/name.h @@ -48,7 +48,7 @@ #define IP_MAX_ADDR_LEN IPV6_ADDR_LEN #define TCP_SEQNO_LEN 4 /* bytes */ -typedef struct +struct ip_address { union { @@ -57,12 +57,13 @@ typedef struct u16 as_u16[IP_MAX_ADDR_LEN >> 1]; u32 as_u32[IP_MAX_ADDR_LEN >> 2]; u64 as_u64[IP_MAX_ADDR_LEN >> 3]; - ip4_address_t as_ip4; - ip6_address_t as_ip6; + ip46_address_t as_ip46; }; int family; unsigned short prefix_len; -} ip_address_t; +}; + +typedef struct ip_address ip_address_t; int ip_address_len (const ip_address_t * ip_address); bool ip_address_empty (const ip_address_t * ip_address); diff --git a/libtransport/src/hicn/transport/core/CMakeLists.txt b/libtransport/src/hicn/transport/core/CMakeLists.txt index c8dea8328..a97e74b2a 100755 --- a/libtransport/src/hicn/transport/core/CMakeLists.txt +++ b/libtransport/src/hicn/transport/core/CMakeLists.txt @@ -17,8 +17,6 @@ list(APPEND HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/content_object.h ${CMAKE_CURRENT_SOURCE_DIR}/facade.h ${CMAKE_CURRENT_SOURCE_DIR}/interest.h - ${CMAKE_CURRENT_SOURCE_DIR}/key_locator.h - ${CMAKE_CURRENT_SOURCE_DIR}/key_locator_type.h ${CMAKE_CURRENT_SOURCE_DIR}/socket_connector.h ${CMAKE_CURRENT_SOURCE_DIR}/manifest.h ${CMAKE_CURRENT_SOURCE_DIR}/manifest_inline.h @@ -41,7 +39,6 @@ list(APPEND HEADER_FILES list(APPEND SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/content_object.cc ${CMAKE_CURRENT_SOURCE_DIR}/interest.cc - ${CMAKE_CURRENT_SOURCE_DIR}/key_locator.cc ${CMAKE_CURRENT_SOURCE_DIR}/socket_connector.cc ${CMAKE_CURRENT_SOURCE_DIR}/pending_interest.cc ${CMAKE_CURRENT_SOURCE_DIR}/packet.cc diff --git a/libtransport/src/hicn/transport/core/connector.cc b/libtransport/src/hicn/transport/core/connector.cc old mode 100755 new mode 100644 diff --git a/libtransport/src/hicn/transport/core/connector.h b/libtransport/src/hicn/transport/core/connector.h old mode 100755 new mode 100644 index 14201879c..c5250486c --- a/libtransport/src/hicn/transport/core/connector.h +++ b/libtransport/src/hicn/transport/core/connector.h @@ -33,7 +33,7 @@ enum class ConnectorType : uint8_t { VPP_CONNECTOR, }; -static constexpr std::size_t packet_size = 2000; +static constexpr std::size_t packet_size = 2048; static constexpr std::size_t queue_size = 4096; static constexpr std::size_t packet_pool_size = 4096; @@ -72,6 +72,10 @@ class Connector { result = packet_pool_.get(); } + if (result.second->isChained()) { + result.second->separateChain(result.second->next(), + result.second->prev()); + } result.second->clear(); return std::move(result.second); } diff --git a/libtransport/src/hicn/transport/core/content_object.cc b/libtransport/src/hicn/transport/core/content_object.cc old mode 100755 new mode 100644 diff --git a/libtransport/src/hicn/transport/core/content_object.h b/libtransport/src/hicn/transport/core/content_object.h old mode 100755 new mode 100644 diff --git a/libtransport/src/hicn/transport/core/facade.h b/libtransport/src/hicn/transport/core/facade.h old mode 100755 new mode 100644 diff --git a/libtransport/src/hicn/transport/core/forwarder_interface.h b/libtransport/src/hicn/transport/core/forwarder_interface.h old mode 100755 new mode 100644 diff --git a/libtransport/src/hicn/transport/core/hicn_binary_api.c b/libtransport/src/hicn/transport/core/hicn_binary_api.c old mode 100755 new mode 100644 index c49cb5c88..d909578a2 --- a/libtransport/src/hicn/transport/core/hicn_binary_api.c +++ b/libtransport/src/hicn/transport/core/hicn_binary_api.c @@ -17,13 +17,14 @@ #ifdef __vpp__ -#include -#include - #include #include #include +#define HICN_VPP_PLUGIN +#include +#undef HICN_VPP_PLUGIN + #include #include #include @@ -66,21 +67,9 @@ const char *HICN_ERROR_STRING[] = { }; ///////////////////////////////////////////////////// -#define POINTER_MAP_SIZE 32 -static void *global_pointers_map[POINTER_MAP_SIZE]; -static uint8_t global_pointers_map_index = 0; - -#define CONTEXT_SAVE(pointer, mp) \ - do { \ - global_pointers_map[global_pointers_map_index] = pointer; \ - mp->context = global_pointers_map_index++; \ - global_pointers_map_index %= POINTER_MAP_SIZE; \ - } while (0); - -#define CONTEXT_GET(mp, pointer) \ - do { \ - pointer = global_pointers_map[mp->context]; \ - } while (0); +static context_store_t context_store = { + .global_pointers_map_index = 0, +}; /* * Table of message reply handlers, must include boilerplate handlers @@ -96,22 +85,19 @@ int hicn_binary_api_register_prod_app( hicn_producer_output_params *output_params) { vl_api_hicn_api_register_prod_app_t *mp; vpp_plugin_binary_api_t *hm = api; - api->vpp_api->user_param = output_params; + vpp_binary_api_set_user_param(api->vpp_api, output_params); /* Construct the API message */ M(HICN_API_REGISTER_PROD_APP, mp); - CONTEXT_SAVE(api, mp) + CONTEXT_SAVE(context_store, api, mp) - mp->len = (u8)input_params->prefix.prefix_length; + mp->len = (u8)input_params->prefix->prefix_len; mp->swif = clib_host_to_net_u32(input_params->swif); mp->cs_reserved = clib_host_to_net_u32(input_params->cs_reserved); - mp->prefix[0] = clib_host_to_net_u64(input_params->prefix.ip6.as_u64[0]); - mp->prefix[1] = clib_host_to_net_u64(input_params->prefix.ip6.as_u64[1]); - - TRANSPORT_LOGI("Prefix length: %u", mp->len); - TRANSPORT_LOGI("Memif ID: %u", mp->swif); + mp->prefix[0] = clib_host_to_net_u64(input_params->prefix->as_u64[0]); + mp->prefix[1] = clib_host_to_net_u64(input_params->prefix->as_u64[1]); return vpp_binary_api_send_request_wait_reply(api->vpp_api, mp); } @@ -119,17 +105,17 @@ int hicn_binary_api_register_prod_app( static void vl_api_hicn_api_register_prod_app_reply_t_handler( vl_api_hicn_api_register_prod_app_reply_t *mp) { vpp_plugin_binary_api_t *binary_api; - CONTEXT_GET(mp, binary_api); - hicn_producer_output_params *params = binary_api->vpp_api->user_param; + CONTEXT_GET(context_store, mp, binary_api); + hicn_producer_output_params *params = + vpp_binary_api_get_user_param(binary_api->vpp_api); - binary_api->vpp_api->ret_val = clib_net_to_host_u32(mp->retval); + vpp_binary_api_set_ret_value(binary_api->vpp_api, + clib_net_to_host_u32(mp->retval)); params->cs_reserved = mp->cs_reserved; - params->prod_addr.ip6.as_u64[0] = mp->prod_addr[0]; - params->prod_addr.ip6.as_u64[1] = mp->prod_addr[1]; + params->prod_addr->as_u64[0] = mp->prod_addr[0]; + params->prod_addr->as_u64[1] = mp->prod_addr[1]; params->face_id = clib_net_to_host_u32(mp->faceid); - TRANSPORT_LOGI("ret :%s", get_error_string(binary_api->vpp_api->ret_val)); - vpp_binary_api_unlock_waiting_thread(binary_api->vpp_api); } @@ -139,14 +125,14 @@ int hicn_binary_api_register_cons_app( vl_api_hicn_api_register_cons_app_t *mp; vpp_plugin_binary_api_t *hm = api; - hm->vpp_api->user_param = output_params; + vpp_binary_api_set_user_param(hm->vpp_api, output_params); /* Construct the API message */ M(HICN_API_REGISTER_CONS_APP, mp); mp->swif = clib_host_to_net_u32(input_params->swif); - CONTEXT_SAVE(api, mp) + CONTEXT_SAVE(context_store, api, mp) TRANSPORT_LOGI("Message created"); @@ -156,14 +142,16 @@ int hicn_binary_api_register_cons_app( static void vl_api_hicn_api_register_cons_app_reply_t_handler( vl_api_hicn_api_register_cons_app_reply_t *mp) { vpp_plugin_binary_api_t *binary_api; - CONTEXT_GET(mp, binary_api); - hicn_consumer_output_params *params = binary_api->vpp_api->user_param; + CONTEXT_GET(context_store, mp, binary_api); + hicn_consumer_output_params *params = + vpp_binary_api_get_user_param(binary_api->vpp_api); - binary_api->vpp_api->ret_val = clib_net_to_host_u32(mp->retval); + vpp_binary_api_set_ret_value(binary_api->vpp_api, + clib_net_to_host_u32(mp->retval)); - params->src4.ip4.as_u32 = clib_net_to_host_u32(mp->src_addr4); - params->src6.ip6.as_u64[0] = clib_net_to_host_u64(mp->src_addr6[0]); - params->src6.ip6.as_u64[1] = clib_net_to_host_u64(mp->src_addr6[1]); + params->src4->as_ip46.ip4.as_u32 = clib_net_to_host_u32(mp->src_addr4); + params->src6->as_u64[0] = clib_net_to_host_u64(mp->src_addr6[0]); + params->src6->as_u64[1] = clib_net_to_host_u64(mp->src_addr6[1]); params->face_id = clib_host_to_net_u32(mp->faceid); vpp_binary_api_unlock_waiting_thread(binary_api->vpp_api); @@ -178,11 +166,11 @@ int hicn_binary_api_register_route( /* Construct the API message */ M(HICN_API_ROUTE_NHOPS_ADD, mp); - CONTEXT_SAVE(api, mp) + CONTEXT_SAVE(context_store, api, mp) - mp->prefix[0] = input_params->prefix.ip6.as_u64[0]; - mp->prefix[1] = input_params->prefix.ip6.as_u64[1]; - mp->len = input_params->prefix.prefix_length; + mp->prefix[0] = input_params->prefix->as_u64[0]; + mp->prefix[1] = input_params->prefix->as_u64[1]; + mp->len = input_params->prefix->prefix_len; mp->face_ids[0] = input_params->face_id; mp->n_faces = 1; @@ -192,9 +180,10 @@ int hicn_binary_api_register_route( static void vl_api_hicn_api_route_nhops_add_reply_t_handler( vl_api_hicn_api_route_nhops_add_reply_t *mp) { vpp_plugin_binary_api_t *binary_api; - CONTEXT_GET(mp, binary_api); + CONTEXT_GET(context_store, mp, binary_api); - binary_api->vpp_api->ret_val = clib_net_to_host_u32(mp->retval); + vpp_binary_api_set_ret_value(binary_api->vpp_api, + clib_net_to_host_u32(mp->retval)); vpp_binary_api_unlock_waiting_thread(binary_api->vpp_api); } @@ -220,7 +209,7 @@ vpp_plugin_binary_api_t *hicn_binary_api_init(vpp_binary_api_t *api) { u8 *name = format(0, "hicn_%08x%c", api_version, 0); ret->msg_id_base = vl_client_get_first_plugin_msg_id((char *)name); ret->vpp_api = api; - ret->my_client_index = api->my_client_index; + ret->my_client_index = vpp_binary_api_get_client_index(api); hicn_binary_api_setup_handlers(ret); return ret; } diff --git a/libtransport/src/hicn/transport/core/hicn_binary_api.h b/libtransport/src/hicn/transport/core/hicn_binary_api.h old mode 100755 new mode 100644 index 752844153..410ffb96c --- a/libtransport/src/hicn/transport/core/hicn_binary_api.h +++ b/libtransport/src/hicn/transport/core/hicn_binary_api.h @@ -27,35 +27,10 @@ extern "C" { #include "stdint.h" -typedef union { - uint8_t data[4]; - uint32_t data_u32; - /* Aliases. */ - uint8_t as_u8[4]; - uint16_t as_u16[2]; - uint32_t as_u32; -} ip4_address; - -typedef union { - uint8_t as_u8[16]; - uint16_t as_u16[8]; - uint32_t as_u32[4]; - uint64_t as_u64[2]; -} ip6_address; - -typedef enum { IP_TYPE_ANY, IP_TYPE_IP4, IP_TYPE_IP6 } ip46_type; +typedef struct ip_address ip_address_t; typedef struct { - ip46_type type; - uint8_t prefix_length; - union { - ip4_address ip4; - ip6_address ip6; - }; -} ip46_address; - -typedef struct { - ip46_address prefix; + ip_address_t* prefix; uint32_t swif; uint32_t cs_reserved; } hicn_producer_input_params; @@ -66,18 +41,18 @@ typedef struct { typedef struct { uint32_t cs_reserved; - ip46_address prod_addr; + ip_address_t* prod_addr; uint32_t face_id; } hicn_producer_output_params; typedef struct { - ip46_address src4; - ip46_address src6; + ip_address_t* src4; + ip_address_t* src6; uint32_t face_id; } hicn_consumer_output_params; typedef struct { - ip46_address prefix; + ip_address_t* prefix; uint32_t face_id; } hicn_producer_set_route_params; diff --git a/libtransport/src/hicn/transport/core/hicn_forwarder_interface.cc b/libtransport/src/hicn/transport/core/hicn_forwarder_interface.cc old mode 100755 new mode 100644 index 03a294957..1d82ff0b0 --- a/libtransport/src/hicn/transport/core/hicn_forwarder_interface.cc +++ b/libtransport/src/hicn/transport/core/hicn_forwarder_interface.cc @@ -15,6 +15,7 @@ #include + #define ADDR_INET 1 #define ADDR_INET6 2 #define ADD_ROUTE 3 @@ -73,7 +74,6 @@ void HicnForwarderInterface::registerRoute(Prefix &prefix) { route_to_self->command_id = ADD_ROUTE; route_to_self->message_type = REQUEST_LIGHT; route_to_self->length = 1; - // route_to_self->seq_num not needed for now send((uint8_t *)route_to_self, sizeof(RouteToSelfCommand), [route_to_self]() { delete route_to_self; }); diff --git a/libtransport/src/hicn/transport/core/hicn_forwarder_interface.h b/libtransport/src/hicn/transport/core/hicn_forwarder_interface.h old mode 100755 new mode 100644 diff --git a/libtransport/src/hicn/transport/core/hicn_memif_api.c b/libtransport/src/hicn/transport/core/hicn_memif_api.c deleted file mode 100755 index e69de29bb..000000000 diff --git a/libtransport/src/hicn/transport/core/interest.cc b/libtransport/src/hicn/transport/core/interest.cc old mode 100755 new mode 100644 diff --git a/libtransport/src/hicn/transport/core/interest.h b/libtransport/src/hicn/transport/core/interest.h old mode 100755 new mode 100644 diff --git a/libtransport/src/hicn/transport/core/key_locator.cc b/libtransport/src/hicn/transport/core/key_locator.cc deleted file mode 100755 index 509fc35ff..000000000 --- a/libtransport/src/hicn/transport/core/key_locator.cc +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2017-2019 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -namespace transport { - -namespace core { - -KeyLocator::KeyLocator() : type_(KeyLocatorType::UNKNOWN) {} - -KeyLocator::KeyLocator(KeyLocatorType type, Name &name) - : type_(type), name_(name) {} - -Name &KeyLocator::getName() { return name_; } - -void KeyLocator::setName(Name &name) { name_ = name; } - -void KeyLocator::setType(KeyLocatorType type) { type_ = type; } - -KeyLocatorType KeyLocator::getType() { return type_; } - -void KeyLocator::clear() { - type_ = KeyLocatorType::UNKNOWN; - name_.clear(); -} - -} // end namespace core - -} // end namespace transport \ No newline at end of file diff --git a/libtransport/src/hicn/transport/core/key_locator.h b/libtransport/src/hicn/transport/core/key_locator.h deleted file mode 100755 index ae3a4ab08..000000000 --- a/libtransport/src/hicn/transport/core/key_locator.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2017-2019 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace transport { - -namespace core { - -class KeyLocator : public std::enable_shared_from_this { - public: - KeyLocator(); - - KeyLocator(KeyLocatorType type, Name &name); - - KeyLocatorType getType(); - - void setType(KeyLocatorType type); - - void setName(Name &name); - - Name &getName(); - - void clear(); - - private: - KeyLocatorType type_; - Name name_; -}; - -} // end namespace core - -} // end namespace transport diff --git a/libtransport/src/hicn/transport/core/key_locator_type.h b/libtransport/src/hicn/transport/core/key_locator_type.h deleted file mode 100755 index 0c84a43ca..000000000 --- a/libtransport/src/hicn/transport/core/key_locator_type.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2017-2019 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -namespace transport { - -namespace core { - -enum Type { NAME = 0, KEY_DIGEST = 1, UNKNOWN = 255 }; - -typedef enum Type KeyLocatorType; - -} // end namespace core - -} // end namespace transport diff --git a/libtransport/src/hicn/transport/core/manifest.cc b/libtransport/src/hicn/transport/core/manifest.cc old mode 100755 new mode 100644 diff --git a/libtransport/src/hicn/transport/core/manifest.h b/libtransport/src/hicn/transport/core/manifest.h old mode 100755 new mode 100644 index 767addb2e..558a96804 --- a/libtransport/src/hicn/transport/core/manifest.h +++ b/libtransport/src/hicn/transport/core/manifest.h @@ -45,21 +45,21 @@ class Manifest : public Base { Base::setPayloadType(PayloadType::MANIFEST); } - Manifest(const core::Name& name) + Manifest(const core::Name &name) : packet_(new Base(name, HF_INET6_TCP_AH), nullptr), encoder_(*packet_), decoder_(*packet_) { Base::setPayloadType(PayloadType::MANIFEST); } - Manifest(typename Base::Ptr&& base) + Manifest(typename Base::Ptr &&base) : packet_(std::move(base)), encoder_(*packet_), decoder_(*packet_) { Base::setPayloadType(PayloadType::MANIFEST); } template - Manifest(T&& base) - : packet_(new Base(std::move(base)), nullptr), + Manifest(T &&base) + : packet_(new Base(std::move(base)), nullptr), encoder_(*packet_), decoder_(*packet_) { Base::setPayloadType(PayloadType::MANIFEST); @@ -67,12 +67,12 @@ class Manifest : public Base { virtual ~Manifest() = default; - bool operator==(const Manifest& other) { + bool operator==(const Manifest &other) { return this->packet_ == other.packet_; } std::size_t estimateManifestSize(std::size_t additional_entries = 0) { - return static_cast(*this).estimateManifestSizeImpl( + return static_cast(*this).estimateManifestSizeImpl( additional_entries); } @@ -80,29 +80,29 @@ class Manifest : public Base { * After the call to encode, users MUST call clear before adding data * to the manifest. */ - Manifest& encode() { return static_cast(*this).encodeImpl(); } + Manifest &encode() { return static_cast(*this).encodeImpl(); } - Manifest& decode() { + Manifest &decode() { Manifest::decoder_.decode(); manifest_type_ = decoder_.getManifestType(); hash_algorithm_ = decoder_.getHashAlgorithm(); is_last_ = decoder_.getIsFinalManifest(); - return static_cast(*this).decodeImpl(); + return static_cast(*this).decodeImpl(); } static std::size_t getManifestHeaderSize() { return Encoder::getManifestHeaderSize(); } - Manifest& setManifestType(ManifestType type) { + Manifest &setManifestType(ManifestType type) { manifest_type_ = type; encoder_.setManifestType(manifest_type_); return *this; } - Manifest& setHashAlgorithm(HashAlgorithm hash_algorithm) { + Manifest &setHashAlgorithm(HashAlgorithm hash_algorithm) { hash_algorithm_ = hash_algorithm; encoder_.setHashAlgorithm(hash_algorithm_); return *this; @@ -114,12 +114,12 @@ class Manifest : public Base { bool isFinalManifest() const { return is_last_; } - Manifest& setVersion(ManifestVersion version) { + Manifest &setVersion(ManifestVersion version) { encoder_.setVersion(version); return *this; } - Manifest& setFinalBlockNumber(std::uint32_t final_block_number) { + Manifest &setFinalBlockNumber(std::uint32_t final_block_number) { encoder_.setFinalBlockNumber(final_block_number); return *this; } @@ -130,13 +130,13 @@ class Manifest : public Base { ManifestVersion getVersion() const { return decoder_.getVersion(); } - Manifest& setFinalManifest(bool is_final_manifest) { + Manifest &setFinalManifest(bool is_final_manifest) { encoder_.setIsFinalManifest(is_final_manifest); is_last_ = is_final_manifest; return *this; } - Manifest& clear() { + Manifest &clear() { encoder_.clear(); decoder_.clear(); return *this; @@ -147,7 +147,7 @@ class Manifest : public Base { encoder_.update(); } - typename Base::Ptr&& getPacket() { return std::move(packet_); } + typename Base::Ptr &&getPacket() { return std::move(packet_); } protected: typename Base::Ptr packet_; diff --git a/libtransport/src/hicn/transport/core/manifest_format.h b/libtransport/src/hicn/transport/core/manifest_format.h old mode 100755 new mode 100644 index 1dcf013dc..00782f14d --- a/libtransport/src/hicn/transport/core/manifest_format.h +++ b/libtransport/src/hicn/transport/core/manifest_format.h @@ -71,28 +71,28 @@ class ManifestEncoder { virtual ~ManifestEncoder() = default; ManifestEncoder encode() { - return static_cast(*this).encodeImpl(); + return static_cast(*this).encodeImpl(); } - ManifestEncoder& clear() { - return static_cast(*this).clearImpl(); + ManifestEncoder &clear() { + return static_cast(*this).clearImpl(); } - ManifestEncoder& setManifestType(ManifestType type) { - return static_cast(*this).setManifestTypeImpl(type); + ManifestEncoder &setManifestType(ManifestType type) { + return static_cast(*this).setManifestTypeImpl(type); } - ManifestEncoder& setHashAlgorithm(HashAlgorithm hash) { - return static_cast(*this).setHashAlgorithmImpl(hash); + ManifestEncoder &setHashAlgorithm(HashAlgorithm hash) { + return static_cast(*this).setHashAlgorithmImpl(hash); } - ManifestEncoder& setFinalChunkNumber(uint32_t final_chunk) { - return static_cast(*this).setFinalChunkImpl(final_chunk); + ManifestEncoder &setFinalChunkNumber(uint32_t final_chunk) { + return static_cast(*this).setFinalChunkImpl(final_chunk); } - ManifestEncoder& setNextSegmentCalculationStrategy( + ManifestEncoder &setNextSegmentCalculationStrategy( NextSegmentCalculationStrategy strategy) { - return static_cast(*this) + return static_cast(*this) .setNextSegmentCalculationStrategyImpl(strategy); } @@ -100,35 +100,35 @@ class ManifestEncoder { typename T, typename = std::enable_if_t>, core::Name>::value>> - ManifestEncoder& setBaseName(T&& name) { - return static_cast(*this).setBaseNameImpl(name); + ManifestEncoder &setBaseName(T &&name) { + return static_cast(*this).setBaseNameImpl(name); } template - ManifestEncoder& addSuffixAndHash(uint32_t suffix, Hash&& hash) { - return static_cast(*this).addSuffixAndHashImpl( - suffix, std::forward(hash)); + ManifestEncoder &addSuffixAndHash(uint32_t suffix, Hash &&hash) { + return static_cast(*this).addSuffixAndHashImpl( + suffix, std::forward(hash)); } - ManifestEncoder& setIsFinalManifest(bool is_last) { - return static_cast(*this).setIsFinalManifestImpl(is_last); + ManifestEncoder &setIsFinalManifest(bool is_last) { + return static_cast(*this).setIsFinalManifestImpl(is_last); } - ManifestEncoder& setVersion(ManifestVersion version) { - return static_cast(*this).setVersionImpl(version); + ManifestEncoder &setVersion(ManifestVersion version) { + return static_cast(*this).setVersionImpl(version); } std::size_t estimateSerializedLength(std::size_t number_of_entries) { - return static_cast(*this).estimateSerializedLengthImpl( + return static_cast(*this).estimateSerializedLengthImpl( number_of_entries); } - ManifestEncoder& update() { - return static_cast(*this).updateImpl(); + ManifestEncoder &update() { + return static_cast(*this).updateImpl(); } - ManifestEncoder& setFinalBlockNumber(std::uint32_t final_block_number) { - return static_cast(*this).setFinalBlockNumberImpl( + ManifestEncoder &setFinalBlockNumber(std::uint32_t final_block_number) { + return static_cast(*this).setFinalBlockNumberImpl( final_block_number); } @@ -142,52 +142,52 @@ class ManifestDecoder { public: virtual ~ManifestDecoder() = default; - ManifestDecoder& clear() { - return static_cast(*this).clearImpl(); + ManifestDecoder &clear() { + return static_cast(*this).clearImpl(); } - void decode() { static_cast(*this).decodeImpl(); } + void decode() { static_cast(*this).decodeImpl(); } ManifestType getManifestType() const { - return static_cast(*this).getManifestTypeImpl(); + return static_cast(*this).getManifestTypeImpl(); } HashAlgorithm getHashAlgorithm() const { - return static_cast(*this).getHashAlgorithmImpl(); + return static_cast(*this).getHashAlgorithmImpl(); } uint32_t getFinalChunkNumber() const { - return static_cast(*this).getFinalChunkImpl(); + return static_cast(*this).getFinalChunkImpl(); } NextSegmentCalculationStrategy getNextSegmentCalculationStrategy() const { - return static_cast(*this) + return static_cast(*this) .getNextSegmentCalculationStrategyImpl(); } core::Name getBaseName() const { - return static_cast(*this).getBaseNameImpl(); + return static_cast(*this).getBaseNameImpl(); } auto getSuffixHashList() { - return static_cast(*this).getSuffixHashListImpl(); + return static_cast(*this).getSuffixHashListImpl(); } bool getIsFinalManifest() const { - return static_cast(*this).getIsFinalManifestImpl(); + return static_cast(*this).getIsFinalManifestImpl(); } ManifestVersion getVersion() const { - return static_cast(*this).getVersionImpl(); + return static_cast(*this).getVersionImpl(); } std::size_t estimateSerializedLength(std::size_t number_of_entries) const { - return static_cast(*this) + return static_cast(*this) .estimateSerializedLengthImpl(number_of_entries); } uint32_t getFinalBlockNumber() const { - return static_cast(*this).getFinalBlockNumberImpl(); + return static_cast(*this).getFinalBlockNumberImpl(); } }; diff --git a/libtransport/src/hicn/transport/core/manifest_format_fixed.cc b/libtransport/src/hicn/transport/core/manifest_format_fixed.cc old mode 100755 new mode 100644 index f26f20adb..6141ae311 --- a/libtransport/src/hicn/transport/core/manifest_format_fixed.cc +++ b/libtransport/src/hicn/transport/core/manifest_format_fixed.cc @@ -23,72 +23,72 @@ namespace transport { namespace core { // TODO use preallocated pool of membufs -FixedManifestEncoder::FixedManifestEncoder(Packet& packet) +FixedManifestEncoder::FixedManifestEncoder(Packet &packet) : packet_(packet), max_size_(Packet::default_mtu - packet_.headerSize()), manifest_( utils::MemBuf::create(Packet::default_mtu - packet_.headerSize())), manifest_header_( - reinterpret_cast(manifest_->writableData())), - manifest_entries_(reinterpret_cast( + reinterpret_cast(manifest_->writableData())), + manifest_entries_(reinterpret_cast( manifest_->writableData() + sizeof(ManifestHeader))), current_entry_(0) {} FixedManifestEncoder::~FixedManifestEncoder() {} -FixedManifestEncoder& FixedManifestEncoder::encodeImpl() { +FixedManifestEncoder &FixedManifestEncoder::encodeImpl() { packet_.appendPayload(std::move(manifest_)); return *this; } -FixedManifestEncoder& FixedManifestEncoder::clearImpl() { +FixedManifestEncoder &FixedManifestEncoder::clearImpl() { manifest_ = utils::MemBuf::create(Packet::default_mtu - packet_.headerSize()); return *this; } -FixedManifestEncoder& FixedManifestEncoder::setHashAlgorithmImpl( +FixedManifestEncoder &FixedManifestEncoder::setHashAlgorithmImpl( HashAlgorithm algorithm) { manifest_header_->hash_algorithm = static_cast(algorithm); return *this; } -FixedManifestEncoder& FixedManifestEncoder::setManifestTypeImpl( +FixedManifestEncoder &FixedManifestEncoder::setManifestTypeImpl( ManifestType manifest_type) { manifest_header_->manifest_type = static_cast(manifest_type); return *this; } -FixedManifestEncoder& +FixedManifestEncoder & FixedManifestEncoder::setNextSegmentCalculationStrategyImpl( NextSegmentCalculationStrategy strategy) { manifest_header_->next_segment_strategy = static_cast(strategy); return *this; } -FixedManifestEncoder& FixedManifestEncoder::setBaseNameImpl( - const core::Name& base_name) { +FixedManifestEncoder &FixedManifestEncoder::setBaseNameImpl( + const core::Name &base_name) { base_name.copyToDestination( - reinterpret_cast(&manifest_header_->prefix[0]), false); + reinterpret_cast(&manifest_header_->prefix[0]), false); manifest_header_->flags.ipv6 = base_name.getAddressFamily() == AF_INET6 ? 1_U8 : 0_U8; return *this; } -FixedManifestEncoder& FixedManifestEncoder::addSuffixAndHashImpl( - uint32_t suffix, const utils::CryptoHash& hash) { +FixedManifestEncoder &FixedManifestEncoder::addSuffixAndHashImpl( + uint32_t suffix, const utils::CryptoHash &hash) { auto _hash = hash.getDigest(); addSuffixHashBytes(suffix, _hash.data(), _hash.length()); return *this; } void FixedManifestEncoder::addSuffixHashBytes(uint32_t suffix, - const uint8_t* hash, + const uint8_t *hash, std::size_t length) { manifest_entries_[current_entry_].suffix = utils::hton(suffix); // std::copy(hash, hash + length, // manifest_entries_[current_entry_].hash); std::memcpy( - reinterpret_cast(manifest_entries_[current_entry_].hash), hash, + reinterpret_cast(manifest_entries_[current_entry_].hash), hash, length); manifest_header_->number_of_entries++; @@ -99,13 +99,13 @@ void FixedManifestEncoder::addSuffixHashBytes(uint32_t suffix, } } -FixedManifestEncoder& FixedManifestEncoder::setIsFinalManifestImpl( +FixedManifestEncoder &FixedManifestEncoder::setIsFinalManifestImpl( bool is_last) { manifest_header_->flags.is_last = static_cast(is_last); return *this; } -FixedManifestEncoder& FixedManifestEncoder::setVersionImpl( +FixedManifestEncoder &FixedManifestEncoder::setVersionImpl( ManifestVersion version) { manifest_header_->version = static_cast(version); return *this; @@ -118,17 +118,17 @@ std::size_t FixedManifestEncoder::estimateSerializedLengthImpl( sizeof(ManifestEntry); } -FixedManifestEncoder& FixedManifestEncoder::updateImpl() { +FixedManifestEncoder &FixedManifestEncoder::updateImpl() { max_size_ = Packet::default_mtu - packet_.headerSize(); - manifest_header_ = reinterpret_cast( - const_cast(packet_.getPayload().data())); - manifest_entries_ = reinterpret_cast( - const_cast(packet_.getPayload().data()) + + manifest_header_ = reinterpret_cast( + const_cast(packet_.getPayload().data())); + manifest_entries_ = reinterpret_cast( + const_cast(packet_.getPayload().data()) + sizeof(ManifestHeader)); return *this; } -FixedManifestEncoder& FixedManifestEncoder::setFinalBlockNumberImpl( +FixedManifestEncoder &FixedManifestEncoder::setFinalBlockNumberImpl( std::uint32_t final_block_number) { manifest_header_->final_block_number = utils::hton(final_block_number); return *this; @@ -138,12 +138,12 @@ std::size_t FixedManifestEncoder::getManifestHeaderSizeImpl() { return sizeof(ManifestHeader); } -FixedManifestDecoder::FixedManifestDecoder(Packet& packet) +FixedManifestDecoder::FixedManifestDecoder(Packet &packet) : packet_(packet), - manifest_header_(reinterpret_cast( - const_cast(packet_.getPayload().data()))), - manifest_entries_(reinterpret_cast( - const_cast(packet_.getPayload().data()) + + manifest_header_(reinterpret_cast( + const_cast(packet_.getPayload().data()))), + manifest_entries_(reinterpret_cast( + const_cast(packet_.getPayload().data()) + sizeof(ManifestHeader))) {} FixedManifestDecoder::~FixedManifestDecoder() {} @@ -158,7 +158,7 @@ void FixedManifestDecoder::decodeImpl() { } } -FixedManifestDecoder& FixedManifestDecoder::clearImpl() { return *this; } +FixedManifestDecoder &FixedManifestDecoder::clearImpl() { return *this; } ManifestType FixedManifestDecoder::getManifestTypeImpl() const { return static_cast(manifest_header_->manifest_type); @@ -180,7 +180,7 @@ typename Fixed::SuffixList FixedManifestDecoder::getSuffixHashListImpl() { for (int i = 0; i < manifest_header_->number_of_entries; i++) { hash_list.insert(hash_list.end(), std::make_pair(utils::ntoh(manifest_entries_[i].suffix), - reinterpret_cast( + reinterpret_cast( &manifest_entries_[i].hash[0]))); } @@ -190,10 +190,10 @@ typename Fixed::SuffixList FixedManifestDecoder::getSuffixHashListImpl() { core::Name FixedManifestDecoder::getBaseNameImpl() const { if (static_cast(manifest_header_->flags.ipv6)) { return core::Name(AF_INET6, - reinterpret_cast(&manifest_header_->prefix)); + reinterpret_cast(&manifest_header_->prefix)); } else { return core::Name(AF_INET, - reinterpret_cast(&manifest_header_->prefix)); + reinterpret_cast(&manifest_header_->prefix)); } } diff --git a/libtransport/src/hicn/transport/core/manifest_format_fixed.h b/libtransport/src/hicn/transport/core/manifest_format_fixed.h old mode 100755 new mode 100644 index 66825e2f4..82817ddfb --- a/libtransport/src/hicn/transport/core/manifest_format_fixed.h +++ b/libtransport/src/hicn/transport/core/manifest_format_fixed.h @@ -53,7 +53,7 @@ struct Fixed { using Encoder = FixedManifestEncoder; using Decoder = FixedManifestDecoder; using HashType = utils::CryptoHash; - using SuffixList = std::list>; + using SuffixList = std::list>; }; struct Flags { @@ -83,60 +83,60 @@ static const constexpr std::uint8_t manifest_version = 1; class FixedManifestEncoder : public ManifestEncoder { public: - FixedManifestEncoder(Packet& packet); + FixedManifestEncoder(Packet &packet); ~FixedManifestEncoder(); - FixedManifestEncoder& encodeImpl(); + FixedManifestEncoder &encodeImpl(); - FixedManifestEncoder& clearImpl(); + FixedManifestEncoder &clearImpl(); - FixedManifestEncoder& setManifestTypeImpl(ManifestType manifest_type); + FixedManifestEncoder &setManifestTypeImpl(ManifestType manifest_type); - FixedManifestEncoder& setHashAlgorithmImpl(HashAlgorithm algorithm); + FixedManifestEncoder &setHashAlgorithmImpl(HashAlgorithm algorithm); - FixedManifestEncoder& setNextSegmentCalculationStrategyImpl( + FixedManifestEncoder &setNextSegmentCalculationStrategyImpl( NextSegmentCalculationStrategy strategy); - FixedManifestEncoder& setBaseNameImpl(const core::Name& base_name); + FixedManifestEncoder &setBaseNameImpl(const core::Name &base_name); - FixedManifestEncoder& addSuffixAndHashImpl(uint32_t suffix, - const utils::CryptoHash& hash); + FixedManifestEncoder &addSuffixAndHashImpl(uint32_t suffix, + const utils::CryptoHash &hash); - FixedManifestEncoder& setIsFinalManifestImpl(bool is_last); + FixedManifestEncoder &setIsFinalManifestImpl(bool is_last); - FixedManifestEncoder& setVersionImpl(ManifestVersion version); + FixedManifestEncoder &setVersionImpl(ManifestVersion version); std::size_t estimateSerializedLengthImpl(std::size_t additional_entries = 0); - FixedManifestEncoder& updateImpl(); + FixedManifestEncoder &updateImpl(); - FixedManifestEncoder& setFinalBlockNumberImpl( + FixedManifestEncoder &setFinalBlockNumberImpl( std::uint32_t final_block_number); static std::size_t getManifestHeaderSizeImpl(); private: - void addSuffixHashBytes(uint32_t suffix, const uint8_t* hash, + void addSuffixHashBytes(uint32_t suffix, const uint8_t *hash, std::size_t length); - Packet& packet_; + Packet &packet_; std::size_t max_size_; std::unique_ptr manifest_; - ManifestHeader* manifest_header_; - ManifestEntry* manifest_entries_; + ManifestHeader *manifest_header_; + ManifestEntry *manifest_entries_; std::size_t current_entry_; }; class FixedManifestDecoder : public ManifestDecoder { public: - FixedManifestDecoder(Packet& packet); + FixedManifestDecoder(Packet &packet); ~FixedManifestDecoder(); void decodeImpl(); - FixedManifestDecoder& clearImpl(); + FixedManifestDecoder &clearImpl(); ManifestType getManifestTypeImpl() const; @@ -158,9 +158,9 @@ class FixedManifestDecoder : public ManifestDecoder { uint32_t getFinalBlockNumberImpl() const; private: - Packet& packet_; - ManifestHeader* manifest_header_; - ManifestEntry* manifest_entries_; + Packet &packet_; + ManifestHeader *manifest_header_; + ManifestEntry *manifest_entries_; }; } // namespace core diff --git a/libtransport/src/hicn/transport/core/manifest_format_json_jsoncpp.cc b/libtransport/src/hicn/transport/core/manifest_format_json_jsoncpp.cc old mode 100755 new mode 100644 index 512cdba5b..0ffca39f6 --- a/libtransport/src/hicn/transport/core/manifest_format_json_jsoncpp.cc +++ b/libtransport/src/hicn/transport/core/manifest_format_json_jsoncpp.cc @@ -25,38 +25,38 @@ namespace core { namespace { template -TRANSPORT_ALWAYS_INLINE void checkPointer(T* pointer) { +TRANSPORT_ALWAYS_INLINE void checkPointer(T *pointer) { if (pointer == nullptr) { throw errors::NullPointerException(); } } template -TRANSPORT_ALWAYS_INLINE void setValueToJson(Json::Value& root, EnumType value) { +TRANSPORT_ALWAYS_INLINE void setValueToJson(Json::Value &root, EnumType value) { root[JSONKey::key] = static_cast(value); } template -TRANSPORT_ALWAYS_INLINE EnumType getValueFromJson(const Json::Value& root) { +TRANSPORT_ALWAYS_INLINE EnumType getValueFromJson(const Json::Value &root) { return static_cast(root[JSONKey::key].asUInt()); }; } // namespace -JSONManifestEncoder::JSONManifestEncoder(Packet& packet) : packet_(packet) {} +JSONManifestEncoder::JSONManifestEncoder(Packet &packet) : packet_(packet) {} JSONManifestEncoder::~JSONManifestEncoder() {} -TRANSPORT_ALWAYS_INLINE JSONManifestEncoder& JSONManifestEncoder::encodeImpl() { +TRANSPORT_ALWAYS_INLINE JSONManifestEncoder &JSONManifestEncoder::encodeImpl() { Json::StreamWriterBuilder writer_builder; - Json::StreamWriter* fast_writer = writer_builder.newStreamWriter(); + Json::StreamWriter *fast_writer = writer_builder.newStreamWriter(); asio::streambuf strbuf; strbuf.prepare(1500); std::ostream stream(&strbuf); fast_writer->write(root_, &stream); - const uint8_t* buffer = asio::buffer_cast(strbuf.data()); + const uint8_t *buffer = asio::buffer_cast(strbuf.data()); packet_.setPayload(buffer, strbuf.size()); @@ -65,38 +65,38 @@ TRANSPORT_ALWAYS_INLINE JSONManifestEncoder& JSONManifestEncoder::encodeImpl() { return *this; } -TRANSPORT_ALWAYS_INLINE JSONManifestEncoder& JSONManifestEncoder::clearImpl() { +TRANSPORT_ALWAYS_INLINE JSONManifestEncoder &JSONManifestEncoder::clearImpl() { root_.clear(); return *this; } -TRANSPORT_ALWAYS_INLINE JSONManifestEncoder& +TRANSPORT_ALWAYS_INLINE JSONManifestEncoder & JSONManifestEncoder::setHashAlgorithmImpl(HashAlgorithm algorithm) { setValueToJson(root_, algorithm); return *this; } -JSONManifestEncoder& JSONManifestEncoder::setManifestTypeImpl( +JSONManifestEncoder &JSONManifestEncoder::setManifestTypeImpl( ManifestType manifest_type) { setValueToJson(root_, manifest_type); return *this; } -JSONManifestEncoder& JSONManifestEncoder::setNextSegmentCalculationStrategyImpl( +JSONManifestEncoder &JSONManifestEncoder::setNextSegmentCalculationStrategyImpl( NextSegmentCalculationStrategy strategy) { setValueToJson(root_, strategy); return *this; } -TRANSPORT_ALWAYS_INLINE JSONManifestEncoder& -JSONManifestEncoder::setBaseNameImpl(const core::Name& base_name) { +TRANSPORT_ALWAYS_INLINE JSONManifestEncoder & +JSONManifestEncoder::setBaseNameImpl(const core::Name &base_name) { root_[JSONKey::key] = base_name.toString().c_str(); return *this; } -TRANSPORT_ALWAYS_INLINE JSONManifestEncoder& +TRANSPORT_ALWAYS_INLINE JSONManifestEncoder & JSONManifestEncoder::addSuffixAndHashImpl(uint32_t suffix, - const utils::CryptoHash& hash) { + const utils::CryptoHash &hash) { throw errors::NotImplementedException(); // Json::Value value(Json::arrayValue); // value.append(Json::Value(suffix)); @@ -106,21 +106,21 @@ JSONManifestEncoder::addSuffixAndHashImpl(uint32_t suffix, return *this; } -TRANSPORT_ALWAYS_INLINE JSONManifestEncoder& +TRANSPORT_ALWAYS_INLINE JSONManifestEncoder & JSONManifestEncoder::setIsFinalManifestImpl(bool is_last) { root_[JSONKey::final_manifest] = is_last; return *this; } -TRANSPORT_ALWAYS_INLINE JSONManifestEncoder& +TRANSPORT_ALWAYS_INLINE JSONManifestEncoder & JSONManifestEncoder::setVersionImpl(ManifestVersion version) { setValueToJson(root_, version); return *this; } -TRANSPORT_ALWAYS_INLINE JSONManifestEncoder& +TRANSPORT_ALWAYS_INLINE JSONManifestEncoder & JSONManifestEncoder::setSuffixHashListImpl( - const typename JSON::SuffixList& name_hash_list) { + const typename JSON::SuffixList &name_hash_list) { throw errors::NotImplementedException(); // for (auto &suffix : name_hash_list) { // addSuffixAndHashImpl(suffix.first, suffix.second); @@ -133,7 +133,7 @@ TRANSPORT_ALWAYS_INLINE std::size_t JSONManifestEncoder::estimateSerializedLengthImpl( std::size_t number_of_entries) { Json::StreamWriterBuilder writer_builder; - Json::StreamWriter* fast_writer = writer_builder.newStreamWriter(); + Json::StreamWriter *fast_writer = writer_builder.newStreamWriter(); asio::streambuf strbuf; strbuf.prepare(1500); @@ -143,11 +143,11 @@ JSONManifestEncoder::estimateSerializedLengthImpl( return strbuf.size(); } -TRANSPORT_ALWAYS_INLINE JSONManifestEncoder& JSONManifestEncoder::updateImpl() { +TRANSPORT_ALWAYS_INLINE JSONManifestEncoder &JSONManifestEncoder::updateImpl() { throw errors::NotImplementedException(); } -TRANSPORT_ALWAYS_INLINE JSONManifestEncoder& +TRANSPORT_ALWAYS_INLINE JSONManifestEncoder & JSONManifestEncoder::setFinalBlockNumberImpl(std::uint32_t final_block_number) { throw errors::NotImplementedException(); } @@ -157,7 +157,7 @@ JSONManifestEncoder::getManifestHeaderSizeImpl() { return 0; } -JSONManifestDecoder::JSONManifestDecoder(Packet& packet) : packet_(packet) {} +JSONManifestDecoder::JSONManifestDecoder(Packet &packet) : packet_(packet) {} JSONManifestDecoder::~JSONManifestDecoder() {} @@ -167,10 +167,10 @@ TRANSPORT_ALWAYS_INLINE void JSONManifestDecoder::decodeImpl() { auto payload_size = array.length(); Json::CharReaderBuilder reader_builder; - Json::CharReader* reader = reader_builder.newCharReader(); + Json::CharReader *reader = reader_builder.newCharReader(); std::string errors; - if (!reader->parse((char*)payload, (char*)payload + payload_size, &root_, + if (!reader->parse((char *)payload, (char *)payload + payload_size, &root_, &errors)) { TRANSPORT_LOGE("Error parsing manifest!"); TRANSPORT_LOGE("%s", errors.c_str()); @@ -183,7 +183,7 @@ TRANSPORT_ALWAYS_INLINE void JSONManifestDecoder::decodeImpl() { delete reader; } -TRANSPORT_ALWAYS_INLINE JSONManifestDecoder& JSONManifestDecoder::clearImpl() { +TRANSPORT_ALWAYS_INLINE JSONManifestDecoder &JSONManifestDecoder::clearImpl() { root_.clear(); return *this; } diff --git a/libtransport/src/hicn/transport/core/manifest_format_json_jsoncpp.h b/libtransport/src/hicn/transport/core/manifest_format_json_jsoncpp.h old mode 100755 new mode 100644 index 39f0cf351..84d2ba29a --- a/libtransport/src/hicn/transport/core/manifest_format_json_jsoncpp.h +++ b/libtransport/src/hicn/transport/core/manifest_format_json_jsoncpp.h @@ -38,7 +38,7 @@ struct JSON { using Encoder = JSONManifestEncoder; using Decoder = JSONManifestDecoder; using HashType = utils::CryptoHash; - using SuffixList = std::unordered_map; + using SuffixList = std::unordered_map; }; template @@ -46,91 +46,91 @@ struct JSONKey; template <> struct JSONKey { - static const constexpr char* key = "manifest_version"; + static const constexpr char *key = "manifest_version"; }; template <> struct JSONKey { - static const constexpr char* key = "hash_algorithm"; + static const constexpr char *key = "hash_algorithm"; }; template <> struct JSONKey { - static const constexpr char* key = "manifest_type"; + static const constexpr char *key = "manifest_type"; }; template <> struct JSONKey { - static const constexpr char* key = "next_segment_strategy"; + static const constexpr char *key = "next_segment_strategy"; }; template <> struct JSONKey { - static const constexpr char* key = "suffix_hash_list"; + static const constexpr char *key = "suffix_hash_list"; }; template <> struct JSONKey { - static const constexpr char* key = "base_name"; + static const constexpr char *key = "base_name"; }; template <> struct JSONKey { - static const constexpr char* final_manifest = "final_manifest"; + static const constexpr char *final_manifest = "final_manifest"; }; class JSONManifestEncoder : public ManifestEncoder { public: - JSONManifestEncoder(Packet& packet); + JSONManifestEncoder(Packet &packet); ~JSONManifestEncoder() override; - JSONManifestEncoder& encodeImpl(); + JSONManifestEncoder &encodeImpl(); - JSONManifestEncoder& clearImpl(); + JSONManifestEncoder &clearImpl(); - JSONManifestEncoder& setManifestTypeImpl(ManifestType manifest_type); + JSONManifestEncoder &setManifestTypeImpl(ManifestType manifest_type); - JSONManifestEncoder& setHashAlgorithmImpl(HashAlgorithm algorithm); + JSONManifestEncoder &setHashAlgorithmImpl(HashAlgorithm algorithm); - JSONManifestEncoder& setNextSegmentCalculationStrategyImpl( + JSONManifestEncoder &setNextSegmentCalculationStrategyImpl( NextSegmentCalculationStrategy strategy); - JSONManifestEncoder& setSuffixHashListImpl( - const typename JSON::SuffixList& name_hash_list); + JSONManifestEncoder &setSuffixHashListImpl( + const typename JSON::SuffixList &name_hash_list); - JSONManifestEncoder& setBaseNameImpl(const core::Name& base_name); + JSONManifestEncoder &setBaseNameImpl(const core::Name &base_name); - JSONManifestEncoder& addSuffixAndHashImpl(uint32_t suffix, - const utils::CryptoHash& hash); + JSONManifestEncoder &addSuffixAndHashImpl(uint32_t suffix, + const utils::CryptoHash &hash); - JSONManifestEncoder& setIsFinalManifestImpl(bool is_last); + JSONManifestEncoder &setIsFinalManifestImpl(bool is_last); - JSONManifestEncoder& setVersionImpl(ManifestVersion version); + JSONManifestEncoder &setVersionImpl(ManifestVersion version); std::size_t estimateSerializedLengthImpl(std::size_t number_of_entries); - JSONManifestEncoder& updateImpl(); + JSONManifestEncoder &updateImpl(); - JSONManifestEncoder& setFinalBlockNumberImpl( + JSONManifestEncoder &setFinalBlockNumberImpl( std::uint32_t final_block_number); static std::size_t getManifestHeaderSizeImpl(); private: - Packet& packet_; + Packet &packet_; Json::Value root_; }; class JSONManifestDecoder : public ManifestDecoder { public: - JSONManifestDecoder(Packet& packet); + JSONManifestDecoder(Packet &packet); ~JSONManifestDecoder() override; void decodeImpl(); - JSONManifestDecoder& clearImpl(); + JSONManifestDecoder &clearImpl(); ManifestType getManifestTypeImpl() const; @@ -153,7 +153,7 @@ class JSONManifestDecoder : public ManifestDecoder { uint32_t getFinalBlockNumberImpl() const; private: - Packet& packet_; + Packet &packet_; Json::Value root_; }; diff --git a/libtransport/src/hicn/transport/core/manifest_format_json_libparc_deprecated.cc b/libtransport/src/hicn/transport/core/manifest_format_json_libparc_deprecated.cc old mode 100755 new mode 100644 index d0365d2fe..a3a47e62b --- a/libtransport/src/hicn/transport/core/manifest_format_json_libparc_deprecated.cc +++ b/libtransport/src/hicn/transport/core/manifest_format_json_libparc_deprecated.cc @@ -29,23 +29,23 @@ namespace core { namespace { template -TRANSPORT_ALWAYS_INLINE void checkPointer(T* pointer) { +TRANSPORT_ALWAYS_INLINE void checkPointer(T *pointer) { if (pointer == nullptr) { throw errors::NullPointerException(); } } template -TRANSPORT_ALWAYS_INLINE void setValueToJson(PARCJSON* root, EnumType value) { +TRANSPORT_ALWAYS_INLINE void setValueToJson(PARCJSON *root, EnumType value) { parcJSON_AddInteger(root, JSONKey::key, static_cast(value)); } template -TRANSPORT_ALWAYS_INLINE EnumType getValueFromJson(PARCJSON* root) { +TRANSPORT_ALWAYS_INLINE EnumType getValueFromJson(PARCJSON *root) { checkPointer(root); - PARCJSONValue* value = parcJSON_GetValueByName(root, JSONKey::key); + PARCJSONValue *value = parcJSON_GetValueByName(root, JSONKey::key); EnumType ret = static_cast(parcJSONValue_GetInteger(value)); // parcJSONValue_Release(&value); @@ -65,17 +65,17 @@ JSONManifestEncoder::~JSONManifestEncoder() { } } -TRANSPORT_ALWAYS_INLINE SONManifestEncoder& JSONManifestEncoder::encodeImpl( - Packet& packet) { - char* json_string = parcJSON_ToString(root_); - packet.setPayload(reinterpret_cast(json_string), +TRANSPORT_ALWAYS_INLINE SONManifestEncoder &JSONManifestEncoder::encodeImpl( + Packet &packet) { + char *json_string = parcJSON_ToString(root_); + packet.setPayload(reinterpret_cast(json_string), std::strlen(json_string)); parcMemory_Deallocate(&json_string); return *this; } -TRANSPORT_ALWAYS_INLINE JSONManifestEncoder& JSONManifestEncoder::clearImpl() { +TRANSPORT_ALWAYS_INLINE JSONManifestEncoder &JSONManifestEncoder::clearImpl() { if (root_) { parcJSON_Release(&root_); } @@ -85,35 +85,35 @@ TRANSPORT_ALWAYS_INLINE JSONManifestEncoder& JSONManifestEncoder::clearImpl() { return *this; } -TRANSPORT_ALWAYS_INLINE JSONManifestEncoder& +TRANSPORT_ALWAYS_INLINE JSONManifestEncoder & JSONManifestEncoder::setHashAlgorithmImpl(HashAlgorithm algorithm) { setValueToJson(root_, algorithm); return *this; } -TRANSPORT_ALWAYS_INLINE JSONManifestEncoder& +TRANSPORT_ALWAYS_INLINE JSONManifestEncoder & JSONManifestEncoder::setManifestTypeImpl(ManifestType manifest_type) { setValueToJson(root_, manifest_type); return *this; } -TRANSPORT_ALWAYS_INLINE JSONManifestEncoder& +TRANSPORT_ALWAYS_INLINE JSONManifestEncoder & JSONManifestEncoder::setNextSegmentCalculationStrategyImpl( NextSegmentCalculationStrategy strategy) { setValueToJson(root_, strategy); return *this; } -TRANSPORT_ALWAYS_INLINE JSONManifestEncoder& -JSONManifestEncoder::setBaseNameImpl(const core::Name& base_name) { +TRANSPORT_ALWAYS_INLINE JSONManifestEncoder & +JSONManifestEncoder::setBaseNameImpl(const core::Name &base_name) { parcJSON_AddString(root_, JSONKey::key, base_name.toString().c_str()); return *this; } -TRANSPORT_ALWAYS_INLINE JSONManifestEncoder& +TRANSPORT_ALWAYS_INLINE JSONManifestEncoder & JSONManifestEncoder::addSuffixAndHashImpl(uint32_t suffix, - utils::CryptoHash& hash) { + utils::CryptoHash &hash) { throw errors::NotImplementedException(); // PARCJSONValue *value = parcJSON_GetValueByName(root_, // JSONKey::key); @@ -151,17 +151,17 @@ JSONManifestEncoder::addSuffixAndHashImpl(uint32_t suffix, return *this; } -TRANSPORT_ALWAYS_INLINE JSONManifestEncoder& +TRANSPORT_ALWAYS_INLINE JSONManifestEncoder & JSONManifestEncoder::setIsFinalManifestImpl(bool is_last) { parcJSON_AddBoolean(root_, JSONKey::final_manifest, is_last); return *this; } -TRANSPORT_ALWAYS_INLINE JSONManifestEncoder& +TRANSPORT_ALWAYS_INLINE JSONManifestEncoder & JSONManifestEncoder::setSuffixHashListImpl( - const SuffixHashList& name_hash_list) { - for (auto& suffix : name_hash_list) { + const SuffixHashList &name_hash_list) { + for (auto &suffix : name_hash_list) { addSuffixAndHashImpl(suffix.first, suffix.second); } @@ -178,18 +178,18 @@ TRANSPORT_ALWAYS_INLINE JSONManifestDecoder::~JSONManifestDecoder() { } TRANSPORT_ALWAYS_INLINE void JSONManifestDecoder::decodeImpl( - const uint8_t* payload, std::size_t payload_size) { - PARCBuffer* b = parcBuffer_Wrap(const_cast(payload), payload_size, + const uint8_t *payload, std::size_t payload_size) { + PARCBuffer *b = parcBuffer_Wrap(const_cast(payload), payload_size, 0, payload_size); clearImpl(); root_ = parcJSON_ParseBuffer(b); parcBuffer_Release(&b); - char* str = parcJSON_ToString(root_); + char *str = parcJSON_ToString(root_); } -TRANSPORT_ALWAYS_INLINE JSONManifestDecoder& JSONManifestDecoder::clearImpl() { +TRANSPORT_ALWAYS_INLINE JSONManifestDecoder &JSONManifestDecoder::clearImpl() { if (root_) { parcJSON_Release(&root_); } @@ -261,11 +261,11 @@ JSONManifestDecoder::getSuffixHashListImpl() { TRANSPORT_ALWAYS_INLINE core::Name JSONManifestDecoder::getBaseNameImpl() const { checkPointer(root_); - PARCJSONValue* value = + PARCJSONValue *value = parcJSON_GetValueByName(root_, JSONKey::key); - PARCBuffer* b = parcJSONValue_GetString(value); - char* string = parcBuffer_ToString(b); + PARCBuffer *b = parcJSONValue_GetString(value); + char *string = parcBuffer_ToString(b); core::Name ret(string); @@ -277,7 +277,7 @@ TRANSPORT_ALWAYS_INLINE core::Name JSONManifestDecoder::getBaseNameImpl() TRANSPORT_ALWAYS_INLINE bool JSONManifestDecoder::getIsFinalManifestImpl() { checkPointer(root_); - PARCJSONValue* value = + PARCJSONValue *value = parcJSON_GetValueByName(root_, JSONKey::final_manifest); bool ret = parcJSONValue_GetBoolean(value); diff --git a/libtransport/src/hicn/transport/core/manifest_format_json_libparc_deprecated.h b/libtransport/src/hicn/transport/core/manifest_format_json_libparc_deprecated.h old mode 100755 new mode 100644 index 28c6c1b40..c89f4af7b --- a/libtransport/src/hicn/transport/core/manifest_format_json_libparc_deprecated.h +++ b/libtransport/src/hicn/transport/core/manifest_format_json_libparc_deprecated.h @@ -42,37 +42,37 @@ struct JSONKey; template <> struct JSONKey { - static const constexpr char* key = "hash_algorithm"; + static const constexpr char *key = "hash_algorithm"; }; template <> struct JSONKey { - static const constexpr char* key = "manifest_type"; + static const constexpr char *key = "manifest_type"; }; template <> struct JSONKey { - static const constexpr char* key = "next_segment_strategy"; + static const constexpr char *key = "next_segment_strategy"; }; template <> struct JSONKey { - static const constexpr char* key = "name_hash_list"; + static const constexpr char *key = "name_hash_list"; }; template <> struct JSONKey { - static const constexpr char* key = "suffix_hash_list"; + static const constexpr char *key = "suffix_hash_list"; }; template <> struct JSONKey { - static const constexpr char* key = "base_name"; + static const constexpr char *key = "base_name"; }; template <> struct JSONKey { - static const constexpr char* final_manifest = "final_manifest"; + static const constexpr char *final_manifest = "final_manifest"; }; // template <> @@ -95,28 +95,28 @@ class JSONManifestEncoder : public ManifestEncoder { ~JSONManifestEncoder(); - JSONManifestEncoder& encodeImpl(Packet& packet); + JSONManifestEncoder &encodeImpl(Packet &packet); - JSONManifestEncoder& clearImpl(); + JSONManifestEncoder &clearImpl(); - JSONManifestEncoder& setManifestTypeImpl(ManifestType manifest_type); + JSONManifestEncoder &setManifestTypeImpl(ManifestType manifest_type); - JSONManifestEncoder& setHashAlgorithmImpl(HashAlgorithm algorithm); + JSONManifestEncoder &setHashAlgorithmImpl(HashAlgorithm algorithm); - JSONManifestEncoder& setNextSegmentCalculationStrategyImpl( + JSONManifestEncoder &setNextSegmentCalculationStrategyImpl( NextSegmentCalculationStrategy strategy); - JSONManifestEncoder& setSuffixHashListImpl( - const SuffixHashList& name_hash_list); + JSONManifestEncoder &setSuffixHashListImpl( + const SuffixHashList &name_hash_list); - JSONManifestEncoder& setBaseNameImpl(const core::Name& base_name); + JSONManifestEncoder &setBaseNameImpl(const core::Name &base_name); - JSONManifestEncoder& addSuffixAndHashImpl(uint32_t suffix, uint64_t hash); + JSONManifestEncoder &addSuffixAndHashImpl(uint32_t suffix, uint64_t hash); - JSONManifestEncoder& setIsFinalManifestImpl(bool is_last); + JSONManifestEncoder &setIsFinalManifestImpl(bool is_last); private: - PARCJSON* root_; + PARCJSON *root_; }; class JSONManifestDecoder : public ManifestDecoder { @@ -125,9 +125,9 @@ class JSONManifestDecoder : public ManifestDecoder { ~JSONManifestDecoder(); - void decodeImpl(const uint8_t* payload, std::size_t payload_size); + void decodeImpl(const uint8_t *payload, std::size_t payload_size); - JSONManifestDecoder& clearImpl(); + JSONManifestDecoder &clearImpl(); ManifestType getManifestTypeImpl() const; @@ -144,7 +144,7 @@ class JSONManifestDecoder : public ManifestDecoder { bool getIsFinalManifestImpl(); private: - PARCJSON* root_; + PARCJSON *root_; }; } // namespace core diff --git a/libtransport/src/hicn/transport/core/manifest_inline.h b/libtransport/src/hicn/transport/core/manifest_inline.h old mode 100755 new mode 100644 index fd1a9abd3..1f2c4edb4 --- a/libtransport/src/hicn/transport/core/manifest_inline.h +++ b/libtransport/src/hicn/transport/core/manifest_inline.h @@ -37,15 +37,15 @@ class ManifestInline public: ManifestInline() : ManifestBase() {} - ManifestInline(const core::Name& name) : ManifestBase(name) {} + ManifestInline(const core::Name &name) : ManifestBase(name) {} template - ManifestInline(T&& base) : ManifestBase(std::forward(base)) {} + ManifestInline(T &&base) : ManifestBase(std::forward(base)) {} - static TRANSPORT_ALWAYS_INLINE ManifestInline* createManifest( - const core::Name& manifest_name, ManifestVersion version, + static TRANSPORT_ALWAYS_INLINE ManifestInline *createManifest( + const core::Name &manifest_name, ManifestVersion version, ManifestType type, HashAlgorithm algorithm, bool is_last, - const Name& base_name, NextSegmentCalculationStrategy strategy, + const Name &base_name, NextSegmentCalculationStrategy strategy, std::size_t signature_size) { auto manifest = new ManifestInline(manifest_name); manifest->setSignatureSize(signature_size); @@ -59,12 +59,12 @@ class ManifestInline return manifest; } - ManifestInline& encodeImpl() { + ManifestInline &encodeImpl() { ManifestBase::encoder_.encode(); return *this; } - ManifestInline& decodeImpl() { + ManifestInline &decodeImpl() { base_name_ = ManifestBase::decoder_.getBaseName(); next_segment_strategy_ = ManifestBase::decoder_.getNextSegmentCalculationStrategy(); @@ -77,23 +77,23 @@ class ManifestInline return ManifestBase::encoder_.estimateSerializedLength(additional_entries); } - ManifestInline& setBaseName(const Name& name) { + ManifestInline &setBaseName(const Name &name) { base_name_ = name; ManifestBase::encoder_.setBaseName(base_name_); return *this; } - const Name& getBaseName() { return base_name_; } + const Name &getBaseName() { return base_name_; } - ManifestInline& addSuffixHash(uint32_t suffix, const HashType& hash) { + ManifestInline &addSuffixHash(uint32_t suffix, const HashType &hash) { ManifestBase::encoder_.addSuffixAndHash(suffix, hash); return *this; } // Call this function only after the decode function! - const SuffixList& getSuffixList() { return suffix_hash_map_; } + const SuffixList &getSuffixList() { return suffix_hash_map_; } - ManifestInline& setNextSegmentCalculationStrategy( + ManifestInline &setNextSegmentCalculationStrategy( NextSegmentCalculationStrategy strategy) { next_segment_strategy_ = strategy; ManifestBase::encoder_.setNextSegmentCalculationStrategy( diff --git a/libtransport/src/hicn/transport/core/memif_binary_api.c b/libtransport/src/hicn/transport/core/memif_binary_api.c old mode 100755 new mode 100644 index b443b51ce..834c8db13 --- a/libtransport/src/hicn/transport/core/memif_binary_api.c +++ b/libtransport/src/hicn/transport/core/memif_binary_api.c @@ -57,6 +57,10 @@ #include #undef vl_typedefs +static context_store_t context_store = { + .global_pointers_map_index = 0, +}; + /* * Table of message reply handlers, must include boilerplate handlers * we just generated @@ -66,35 +70,34 @@ _(MEMIF_DELETE_REPLY, memif_delete_reply) \ _(MEMIF_DETAILS, memif_details) -#define POINTER_MAP_SIZE 32 -static void *global_pointers_map[POINTER_MAP_SIZE]; -static uint8_t global_pointers_map_index = 0; - -uint32_t memif_binary_api_get_next_memif_id(vpp_plugin_binary_api_t *api) { +int memif_binary_api_get_next_memif_id(vpp_plugin_binary_api_t *api, + uint32_t *memif_id) { // Dump all the memif interfaces and return the next to the largest memif id vl_api_memif_dump_t *mp; vpp_plugin_binary_api_t *hm = api; M(MEMIF_DUMP, mp); - api->vpp_api->user_param = malloc(sizeof(uint32_t)); - *(uint32_t *)(api->vpp_api->user_param) = 0; - global_pointers_map[global_pointers_map_index] = api; - mp->context = global_pointers_map_index++; - global_pointers_map_index %= POINTER_MAP_SIZE; + uint32_t *user_param = malloc(sizeof(uint32_t)); + *user_param = 0; + vpp_binary_api_set_user_param(api->vpp_api, user_param); + + CONTEXT_SAVE(context_store, api, mp); vpp_binary_api_send_request(api->vpp_api, mp); vpp_binary_api_send_receive_ping(api->vpp_api); - uint32_t ret = *(uint32_t *)(api->vpp_api->user_param); - free(api->vpp_api->user_param); + user_param = vpp_binary_api_get_user_param(api->vpp_api); + *memif_id = *(uint32_t *)(user_param); + free(user_param); - return ret; + return vpp_binary_api_get_ret_value(api->vpp_api); } static void vl_api_memif_details_t_handler(vl_api_memif_details_t *mp) { - vpp_plugin_binary_api_t *binary_api = global_pointers_map[mp->context]; - uint32_t *last_memif_id = binary_api->vpp_api->user_param; + vpp_plugin_binary_api_t *binary_api; + CONTEXT_GET(context_store, mp, binary_api); + uint32_t *last_memif_id = vpp_binary_api_get_user_param(binary_api->vpp_api); uint32_t current_memif_id = clib_net_to_host_u32(mp->id); if (current_memif_id >= *last_memif_id) { *last_memif_id = current_memif_id + 1; @@ -127,14 +130,12 @@ int memif_binary_api_create_memif(vpp_plugin_binary_api_t *api, return -1; } - api->vpp_api->user_param = output_params; + vpp_binary_api_set_user_param(api->vpp_api, output_params); /* Construct the API message */ M(MEMIF_CREATE, mp); - global_pointers_map[global_pointers_map_index] = api; - mp->context = global_pointers_map_index++; - global_pointers_map_index %= POINTER_MAP_SIZE; + CONTEXT_SAVE(context_store, api, mp) mp->role = input_params->role; mp->mode = input_params->mode; @@ -161,9 +162,7 @@ int memif_binary_api_delete_memif(vpp_plugin_binary_api_t *api, /* Construct the API message */ M(MEMIF_DELETE, mp); - global_pointers_map[global_pointers_map_index] = api; - mp->context = global_pointers_map_index++; - global_pointers_map_index %= POINTER_MAP_SIZE; + CONTEXT_SAVE(context_store, api, mp) mp->sw_if_index = htonl(sw_if_index); @@ -172,22 +171,25 @@ int memif_binary_api_delete_memif(vpp_plugin_binary_api_t *api, static void vl_api_memif_create_reply_t_handler( vl_api_memif_create_reply_t *mp) { - vpp_plugin_binary_api_t *binary_api = global_pointers_map[mp->context]; - memif_output_params_t *params = binary_api->vpp_api->user_param; + vpp_plugin_binary_api_t *binary_api; + CONTEXT_GET(context_store, mp, binary_api); + memif_output_params_t *params = + vpp_binary_api_get_user_param(binary_api->vpp_api); - binary_api->vpp_api->ret_val = ntohl(mp->retval); + vpp_binary_api_set_ret_value(binary_api->vpp_api, + clib_net_to_host_u32(mp->retval)); params->sw_if_index = clib_net_to_host_u32(mp->sw_if_index); - TRANSPORT_LOGI("ret :%d", binary_api->vpp_api->ret_val); - vpp_binary_api_unlock_waiting_thread(binary_api->vpp_api); } static void vl_api_memif_delete_reply_t_handler( vl_api_memif_delete_reply_t *mp) { - vpp_plugin_binary_api_t *binary_api = global_pointers_map[mp->context]; + vpp_plugin_binary_api_t *binary_api; + CONTEXT_GET(context_store, mp, binary_api); - binary_api->vpp_api->ret_val = ntohl(mp->retval); + vpp_binary_api_set_ret_value(binary_api->vpp_api, + clib_net_to_host_u32(mp->retval)); vpp_binary_api_unlock_waiting_thread(binary_api->vpp_api); } @@ -210,7 +212,7 @@ vpp_plugin_binary_api_t *memif_binary_api_init(vpp_binary_api_t *api) { u8 *name = format(0, "memif_%08x%c", api_version, 0); ret->msg_id_base = vl_client_get_first_plugin_msg_id((char *)name); ret->vpp_api = api; - ret->my_client_index = api->my_client_index; + ret->my_client_index = vpp_binary_api_get_client_index(api); memif_binary_api_setup_handlers(ret); return ret; } diff --git a/libtransport/src/hicn/transport/core/memif_binary_api.h b/libtransport/src/hicn/transport/core/memif_binary_api.h old mode 100755 new mode 100644 index 582aeb1a0..b950292b9 --- a/libtransport/src/hicn/transport/core/memif_binary_api.h +++ b/libtransport/src/hicn/transport/core/memif_binary_api.h @@ -43,15 +43,16 @@ typedef struct memif_output_params_s { uint32_t sw_if_index; } memif_output_params_t; -vpp_plugin_binary_api_t* memif_binary_api_init(vpp_binary_api_t* api); +vpp_plugin_binary_api_t *memif_binary_api_init(vpp_binary_api_t *api); -uint32_t memif_binary_api_get_next_memif_id(vpp_plugin_binary_api_t* api); +int memif_binary_api_get_next_memif_id(vpp_plugin_binary_api_t *api, + uint32_t *memif_id); -int memif_binary_api_create_memif(vpp_plugin_binary_api_t* api, - memif_create_params_t* input_params, - memif_output_params_t* output_params); +int memif_binary_api_create_memif(vpp_plugin_binary_api_t *api, + memif_create_params_t *input_params, + memif_output_params_t *output_params); -int memif_binary_api_delete_memif(vpp_plugin_binary_api_t* api, +int memif_binary_api_delete_memif(vpp_plugin_binary_api_t *api, uint32_t sw_if_index); #ifdef __cplusplus diff --git a/libtransport/src/hicn/transport/core/memif_connector.cc b/libtransport/src/hicn/transport/core/memif_connector.cc old mode 100755 new mode 100644 index 7a672314e..b3785e5c3 --- a/libtransport/src/hicn/transport/core/memif_connector.cc +++ b/libtransport/src/hicn/transport/core/memif_connector.cc @@ -46,6 +46,7 @@ MemifConnector::MemifConnector(PacketReceivedCallback &&receive_callback, is_reconnection_(false), data_available_(false), enable_burst_(false), + closed_(false), app_name_(app_name), receive_callback_(receive_callback), on_reconnect_callback_(on_reconnect_callback), @@ -342,11 +343,14 @@ int MemifConnector::onInterrupt(memif_conn_handle_t conn, void *private_ctx, goto error; } + std::size_t packet_length; for (int i = 0; i < rx; i++) { auto packet = connector->getPacket(); + packet_length = (c->rx_bufs + i)->len; std::memcpy(packet->writableData(), reinterpret_cast((c->rx_bufs + i)->data), - (c->rx_bufs + i)->len); + packet_length); + packet->append(packet_length); if (!connector->input_buffer_.push(std::move(packet))) { TRANSPORT_LOGI("Error pushing packet. Ring buffer full."); @@ -394,20 +398,19 @@ error: return 0; } -// void MemifConnector::runEventsLoop() { -// io_service_.run(); -//} - void MemifConnector::close() { - event_reactor_.stop(); - io_service_.stop(); - - if (memif_worker_ && memif_worker_->joinable()) { - memif_worker_->join(); - TRANSPORT_LOGD("Memif worker joined"); - deleteMemif(); - } else { - TRANSPORT_LOGD("Memif worker not joined"); + if (!closed_) { + closed_ = true; + event_reactor_.stop(); + io_service_.stop(); + + if (memif_worker_ && memif_worker_->joinable()) { + memif_worker_->join(); + TRANSPORT_LOGD("Memif worker joined"); + deleteMemif(); + } else { + TRANSPORT_LOGD("Memif worker not joined"); + } } } diff --git a/libtransport/src/hicn/transport/core/memif_connector.h b/libtransport/src/hicn/transport/core/memif_connector.h old mode 100755 new mode 100644 index 24c8ac16c..4667ec0b2 --- a/libtransport/src/hicn/transport/core/memif_connector.h +++ b/libtransport/src/hicn/transport/core/memif_connector.h @@ -143,6 +143,7 @@ class MemifConnector : public Connector { volatile bool is_reconnection_; bool data_available_; bool enable_burst_; + bool closed_; uint32_t memif_id_; uint8_t memif_mode_; std::string app_name_; diff --git a/libtransport/src/hicn/transport/core/name.cc b/libtransport/src/hicn/transport/core/name.cc old mode 100755 new mode 100644 diff --git a/libtransport/src/hicn/transport/core/name.h b/libtransport/src/hicn/transport/core/name.h old mode 100755 new mode 100644 diff --git a/libtransport/src/hicn/transport/core/packet.cc b/libtransport/src/hicn/transport/core/packet.cc old mode 100755 new mode 100644 index 74f407ff7..69cbb3cb3 --- a/libtransport/src/hicn/transport/core/packet.cc +++ b/libtransport/src/hicn/transport/core/packet.cc @@ -48,7 +48,6 @@ Packet::Packet(MemBufPtr &&buffer) header_head_(packet_.get()), payload_head_(nullptr), format_(getFormatFromBuffer(packet_start_)) { - auto header_size = getHeaderSizeFromFormat(format_); int signature_size = 0; @@ -79,8 +78,6 @@ Packet::Packet(MemBufPtr &&buffer) packet_->prependChain(std::move(payload)); packet_->append(header_size); } - - } Packet::Packet(const uint8_t *buffer, std::size_t size) @@ -98,11 +95,7 @@ Packet::Packet(Packet &&other) other.format_ = HF_UNSPEC; } -Packet::~Packet() { - if (packet_->isChained()) { - packet_->separateChain(packet_->next(), packet_->prev()); - } -} +Packet::~Packet() {} std::size_t Packet::getHeaderSizeFromFormat(Format format, size_t signature_size) { @@ -317,7 +310,7 @@ void Packet::setSignature(std::unique_ptr &&signature) { void Packet::setSignatureTimestamp(const uint64_t ×tamp) { int ret = hicn_packet_set_signature_timestamp( - format_, (hicn_header_t *)packet_start_, timestamp); + format_, (hicn_header_t *)packet_start_, timestamp); if (ret < 0) { throw errors::RuntimeException("Error setting the signature timestamp."); @@ -327,7 +320,7 @@ void Packet::setSignatureTimestamp(const uint64_t ×tamp) { uint64_t Packet::getSignatureTimestamp() const { uint64_t return_value; int ret = hicn_packet_get_signature_timestamp( - format_, (hicn_header_t *)packet_start_, &return_value); + format_, (hicn_header_t *)packet_start_, &return_value); if (ret < 0) { throw errors::RuntimeException("Error getting the signature timestamp."); @@ -336,9 +329,10 @@ uint64_t Packet::getSignatureTimestamp() const { return return_value; } -void Packet::setValidationAlgorithm(const utils::CryptoSuite &validation_algorithm) { +void Packet::setValidationAlgorithm( + const utils::CryptoSuite &validation_algorithm) { int ret = hicn_packet_set_validation_algorithm( - format_, (hicn_header_t *)packet_start_, uint8_t(validation_algorithm)); + format_, (hicn_header_t *)packet_start_, uint8_t(validation_algorithm)); if (ret < 0) { throw errors::RuntimeException("Error setting the validation algorithm."); @@ -348,7 +342,7 @@ void Packet::setValidationAlgorithm(const utils::CryptoSuite &validation_algorit utils::CryptoSuite Packet::getValidationAlgorithm() const { uint8_t return_value; int ret = hicn_packet_get_validation_algorithm( - format_, (hicn_header_t *)packet_start_, &return_value); + format_, (hicn_header_t *)packet_start_, &return_value); if (ret < 0) { throw errors::RuntimeException("Error getting the validation algorithm."); @@ -358,8 +352,8 @@ utils::CryptoSuite Packet::getValidationAlgorithm() const { } void Packet::setKeyId(const utils::KeyId &key_id) { - int ret = hicn_packet_set_key_id( - format_, (hicn_header_t *)packet_start_, key_id.first); + int ret = hicn_packet_set_key_id(format_, (hicn_header_t *)packet_start_, + key_id.first); if (ret < 0) { throw errors::RuntimeException("Error setting the key id."); @@ -368,8 +362,8 @@ void Packet::setKeyId(const utils::KeyId &key_id) { utils::KeyId Packet::getKeyId() const { utils::KeyId return_value; - int ret = hicn_packet_get_key_id( - format_, (hicn_header_t *)packet_start_, &return_value.first, &return_value.second); + int ret = hicn_packet_get_key_id(format_, (hicn_header_t *)packet_start_, + &return_value.first, &return_value.second); if (ret < 0) { throw errors::RuntimeException("Error getting the validation algorithm."); diff --git a/libtransport/src/hicn/transport/core/packet.h b/libtransport/src/hicn/transport/core/packet.h old mode 100755 new mode 100644 index 0a5673401..bc23588dc --- a/libtransport/src/hicn/transport/core/packet.h +++ b/libtransport/src/hicn/transport/core/packet.h @@ -20,10 +20,10 @@ #include #include #include -#include -#include #include #include +#include +#include namespace utils { class Signer; diff --git a/libtransport/src/hicn/transport/core/payload_type.h b/libtransport/src/hicn/transport/core/payload_type.h old mode 100755 new mode 100644 diff --git a/libtransport/src/hicn/transport/core/pending_interest.cc b/libtransport/src/hicn/transport/core/pending_interest.cc old mode 100755 new mode 100644 diff --git a/libtransport/src/hicn/transport/core/pending_interest.h b/libtransport/src/hicn/transport/core/pending_interest.h old mode 100755 new mode 100644 diff --git a/libtransport/src/hicn/transport/core/portal.h b/libtransport/src/hicn/transport/core/portal.h old mode 100755 new mode 100644 index 88020447f..a79717037 --- a/libtransport/src/hicn/transport/core/portal.h +++ b/libtransport/src/hicn/transport/core/portal.h @@ -224,7 +224,7 @@ class Portal { TRANSPORT_ALWAYS_INLINE void killConnection() { connector_.close(); } - TRANSPORT_ALWAYS_INLINE void clear() { pending_interest_hash_table_.clear();} + TRANSPORT_ALWAYS_INLINE void clear() { pending_interest_hash_table_.clear(); } TRANSPORT_ALWAYS_INLINE asio::io_service &getIoService() { return io_service_; diff --git a/libtransport/src/hicn/transport/core/prefix.cc b/libtransport/src/hicn/transport/core/prefix.cc old mode 100755 new mode 100644 diff --git a/libtransport/src/hicn/transport/core/prefix.h b/libtransport/src/hicn/transport/core/prefix.h old mode 100755 new mode 100644 diff --git a/libtransport/src/hicn/transport/core/raw_socket_connector.cc b/libtransport/src/hicn/transport/core/raw_socket_connector.cc old mode 100755 new mode 100644 diff --git a/libtransport/src/hicn/transport/core/raw_socket_connector.h b/libtransport/src/hicn/transport/core/raw_socket_connector.h old mode 100755 new mode 100644 diff --git a/libtransport/src/hicn/transport/core/raw_socket_interface.cc b/libtransport/src/hicn/transport/core/raw_socket_interface.cc old mode 100755 new mode 100644 diff --git a/libtransport/src/hicn/transport/core/raw_socket_interface.h b/libtransport/src/hicn/transport/core/raw_socket_interface.h old mode 100755 new mode 100644 diff --git a/libtransport/src/hicn/transport/core/socket_connector.cc b/libtransport/src/hicn/transport/core/socket_connector.cc old mode 100755 new mode 100644 diff --git a/libtransport/src/hicn/transport/core/socket_connector.h b/libtransport/src/hicn/transport/core/socket_connector.h old mode 100755 new mode 100644 diff --git a/libtransport/src/hicn/transport/core/test/test_core_manifest.cc b/libtransport/src/hicn/transport/core/test/test_core_manifest.cc old mode 100755 new mode 100644 diff --git a/libtransport/src/hicn/transport/core/vpp_binary_api.c b/libtransport/src/hicn/transport/core/vpp_binary_api.c old mode 100755 new mode 100644 index ab23d3cf5..09ffb2ec6 --- a/libtransport/src/hicn/transport/core/vpp_binary_api.c +++ b/libtransport/src/hicn/transport/core/vpp_binary_api.c @@ -53,13 +53,22 @@ #include #undef vl_msg_name_crc_list -// #define vl_api_version(n,v) static u32 vpe_api_version = (v); -// #include -// #undef vl_api_version - -#define POINTER_MAP_SIZE 32 -static void *global_pointers_map[POINTER_MAP_SIZE]; -static uint8_t global_pointers_map_index = 0; +#include + +struct vpp_binary_api { + api_main_t *api_main; + u32 my_client_index; + unix_shared_memory_queue_t *vl_input_queue; + vlib_main_t *vlib_main; + sem_t *semaphore; + u32 ping_id; + int ret_val; + void *user_param; +}; + +static context_store_t context_store = { + .global_pointers_map_index = 0, +}; /* * Table of message reply handlers, must include boilerplate handlers @@ -91,7 +100,8 @@ typedef struct __attribute__((packed)) vl_generic_reply_s { static void vl_api_control_ping_reply_t_handler( vl_api_control_ping_reply_t *mp) { // Just unblock main thread - vpp_binary_api_t *binary_api = global_pointers_map[mp->context]; + vpp_binary_api_t *binary_api; + CONTEXT_GET(context_store, mp, binary_api); binary_api->ret_val = ntohl(mp->retval); vpp_binary_api_unlock_waiting_thread(binary_api); } @@ -99,7 +109,8 @@ static void vl_api_control_ping_reply_t_handler( static void vl_api_sw_interface_set_flags_reply_t_handler( vl_api_control_ping_reply_t *mp) { // Unblock main thread setting reply message status code - vpp_binary_api_t *binary_api = global_pointers_map[mp->context]; + vpp_binary_api_t *binary_api; + CONTEXT_GET(context_store, mp, binary_api); binary_api->ret_val = ntohl(mp->retval); vpp_binary_api_unlock_waiting_thread(binary_api); } @@ -160,9 +171,7 @@ void vpp_binary_api_send_receive_ping(vpp_binary_api_t *api) { vl_msg_api_get_msg_index((u8 *)(VL_API_CONTROL_PING_CRC))); mp_ping->client_index = api->my_client_index; - global_pointers_map[global_pointers_map_index] = api; - mp_ping->context = global_pointers_map_index++; - global_pointers_map_index %= POINTER_MAP_SIZE; + CONTEXT_SAVE(context_store, api, mp_ping); TRANSPORT_LOGI("Sending ping id %u", mp_ping->_vl_msg_id); @@ -191,9 +200,7 @@ int vpp_binary_api_set_int_state(vpp_binary_api_t *api, uint32_t sw_index, mp->sw_if_index = clib_host_to_net_u32(sw_index); mp->admin_up_down = (u8)state; - global_pointers_map[global_pointers_map_index] = api; - mp->context = global_pointers_map_index++; - global_pointers_map_index %= POINTER_MAP_SIZE; + CONTEXT_SAVE(context_store, api, mp); TRANSPORT_LOGI("Sending set int flags id %u", mp->_vl_msg_id); @@ -209,6 +216,29 @@ void vpp_binary_api_send_request(vpp_binary_api_t *api, void *request) { S(api, req); } +int vpp_binary_api_get_ret_value(vpp_binary_api_t *api) { return api->ret_val; } + +void vpp_binary_api_set_ret_value(vpp_binary_api_t *api, int ret_val) { + api->ret_val = ret_val; +} + +void *vpp_binary_api_get_user_param(vpp_binary_api_t *api) { + return api->user_param; +} + +void vpp_binary_api_set_user_param(vpp_binary_api_t *api, void *user_param) { + api->user_param = user_param; +} + +uint32_t vpp_binary_api_get_client_index(vpp_binary_api_t *api) { + return api->my_client_index; +} + +void vpp_binary_api_set_client_index(vpp_binary_api_t *api, + uint32_t client_index) { + api->my_client_index = client_index; +} + int vpp_binary_api_send_request_wait_reply(vpp_binary_api_t *api, void *request) { vpp_binary_api_send_request(api, request); diff --git a/libtransport/src/hicn/transport/core/vpp_binary_api.h b/libtransport/src/hicn/transport/core/vpp_binary_api.h old mode 100755 new mode 100644 index 1eb10e766..932a59ec2 --- a/libtransport/src/hicn/transport/core/vpp_binary_api.h +++ b/libtransport/src/hicn/transport/core/vpp_binary_api.h @@ -35,27 +35,40 @@ typedef enum link_state_s { UP = 1, DOWN = 0 } link_state_t; * @brief Instantiate a new vpp_binary_api_t data structure and * connect the application to the local VPP forwarder. */ -vpp_binary_api_t* vpp_binary_api_init(const char* app_name); +vpp_binary_api_t *vpp_binary_api_init(const char *app_name); /** * @brief Destroy the vpp_binary_api_t and disconnect from VPP. */ -void vpp_binary_api_destroy(vpp_binary_api_t* api); +void vpp_binary_api_destroy(vpp_binary_api_t *api); -void vpp_binary_api_send_receive_ping(vpp_binary_api_t* api); +void vpp_binary_api_send_receive_ping(vpp_binary_api_t *api); -int vpp_binary_api_set_int_state(vpp_binary_api_t* api, uint32_t sw_index, +int vpp_binary_api_set_int_state(vpp_binary_api_t *api, uint32_t sw_index, link_state_t state); /** * @brief Send request to VPP and wait for reply. */ -int vpp_binary_api_send_request_wait_reply(vpp_binary_api_t* api, - void* request); +int vpp_binary_api_send_request_wait_reply(vpp_binary_api_t *api, + void *request); -void vpp_binary_api_unlock_waiting_thread(vpp_binary_api_t* api); +void vpp_binary_api_unlock_waiting_thread(vpp_binary_api_t *api); -void vpp_binary_api_send_request(vpp_binary_api_t* api, void* request); +void vpp_binary_api_send_request(vpp_binary_api_t *api, void *request); + +int vpp_binary_api_get_ret_value(vpp_binary_api_t *api); + +void vpp_binary_api_set_ret_value(vpp_binary_api_t *api, int ret_val); + +void *vpp_binary_api_get_user_param(vpp_binary_api_t *api); + +void vpp_binary_api_set_user_param(vpp_binary_api_t *api, void *user_param); + +uint32_t vpp_binary_api_get_client_index(vpp_binary_api_t *api); + +void vpp_binary_api_set_client_index(vpp_binary_api_t *api, + uint32_t client_index); #ifdef __cplusplus } diff --git a/libtransport/src/hicn/transport/core/vpp_binary_api_internal.h b/libtransport/src/hicn/transport/core/vpp_binary_api_internal.h old mode 100755 new mode 100644 index 22b665e96..a6e2c01a3 --- a/libtransport/src/hicn/transport/core/vpp_binary_api_internal.h +++ b/libtransport/src/hicn/transport/core/vpp_binary_api_internal.h @@ -27,16 +27,9 @@ extern "C" { #include #include -struct vpp_binary_api { - api_main_t *api_main; - u32 my_client_index; - unix_shared_memory_queue_t *vl_input_queue; - vlib_main_t *vlib_main; - sem_t *semaphore; - u32 ping_id; - int ret_val; - void *user_param; -}; +#include + +typedef struct vpp_binary_api vpp_binary_api_t; struct vpp_plugin_binary_api { vpp_binary_api_t *vpp_api; @@ -44,6 +37,26 @@ struct vpp_plugin_binary_api { u32 my_client_index; }; +#define POINTER_MAP_SIZE 32 +typedef struct { + void *global_pointers_map[POINTER_MAP_SIZE]; + uint8_t global_pointers_map_index; +} context_store_t; + +#define CONTEXT_SAVE(context_store, pointer, mp) \ + do { \ + context_store \ + .global_pointers_map[context_store.global_pointers_map_index] = \ + pointer; \ + mp->context = context_store.global_pointers_map_index++; \ + context_store.global_pointers_map_index %= POINTER_MAP_SIZE; \ + } while (0); + +#define CONTEXT_GET(context_store, mp, pointer) \ + do { \ + pointer = context_store.global_pointers_map[mp->context]; \ + } while (0); + #define M(T, mp) \ do { \ mp = vl_msg_api_alloc_as_if_client(sizeof(*mp)); \ diff --git a/libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc b/libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc old mode 100755 new mode 100644 index 3a748c821..0335c3829 --- a/libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc +++ b/libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc @@ -19,6 +19,7 @@ #include #include +#include #include typedef enum { MASTER = 0, SLAVE = 1 } memif_role_t; @@ -42,7 +43,19 @@ VPPForwarderInterface::VPPForwarderInterface(MemifConnector &connector) sw_if_index_(~0), face_id_(~0) {} -VPPForwarderInterface::~VPPForwarderInterface() {} +VPPForwarderInterface::~VPPForwarderInterface() { + if (sw_if_index_ != uint32_t(~0) && VPPForwarderInterface::memif_api_) { + int ret = memif_binary_api_delete_memif(VPPForwarderInterface::memif_api_, sw_if_index_); + + if (ret < 0) { + TRANSPORT_LOGE("Error deleting memif with sw idx %u.", sw_if_index_); + } + } + + if (VPPForwarderInterface::api_) { + vpp_binary_api_destroy(VPPForwarderInterface::api_); + } +} /** * @brief Create a memif interface in the local VPP forwarder. @@ -50,8 +63,13 @@ VPPForwarderInterface::~VPPForwarderInterface() {} uint32_t VPPForwarderInterface::getMemifConfiguration() { memif_create_params_t input_params = {0}; - memif_id_ = - memif_binary_api_get_next_memif_id(VPPForwarderInterface::memif_api_); + int ret = memif_binary_api_get_next_memif_id( + VPPForwarderInterface::memif_api_, &memif_id_); + + if (ret < 0) { + throw errors::RuntimeException( + "Error getting next memif id. Could not create memif interface."); + } input_params.id = memif_id_; input_params.role = memif_role_t::MASTER; @@ -63,8 +81,10 @@ uint32_t VPPForwarderInterface::getMemifConfiguration() { memif_output_params_t output_params = {0}; - if (memif_binary_api_create_memif(VPPForwarderInterface::memif_api_, - &input_params, &output_params) < 0) { + ret = memif_binary_api_create_memif(VPPForwarderInterface::memif_api_, + &input_params, &output_params); + + if (ret < 0) { throw errors::RuntimeException( "Error creating memif interface in the local VPP forwarder."); } @@ -75,23 +95,30 @@ uint32_t VPPForwarderInterface::getMemifConfiguration() { void VPPForwarderInterface::consumerConnection() { hicn_consumer_input_params input = {0}; hicn_consumer_output_params output; + ip_address_t ip4_address; + ip_address_t ip6_address; std::memset(&output, 0, sizeof(hicn_consumer_output_params)); + output.src4 = &ip4_address; + output.src6 = &ip6_address; + input.swif = sw_if_index_; - if (int ret = hicn_binary_api_register_cons_app( - VPPForwarderInterface::hicn_api_, &input, &output) < 0) { + int ret = hicn_binary_api_register_cons_app( + VPPForwarderInterface::hicn_api_, &input, &output); + + if (ret < 0) { throw errors::RuntimeException(hicn_binary_api_get_error_string(ret)); } inet_address_.family = AF_INET; - inet_address_.prefix_len = output.src4.prefix_length; - std::memcpy(inet_address_.buffer, output.src4.ip4.as_u8, IPV4_ADDR_LEN); + inet_address_.prefix_len = output.src4->prefix_len; + std::memcpy(inet_address_.buffer, output.src4->buffer, IPV6_ADDR_LEN); inet6_address_.family = AF_INET6; - inet6_address_.prefix_len = output.src6.prefix_length; - std::memcpy(inet6_address_.buffer, output.src6.ip6.as_u8, IPV6_ADDR_LEN); + inet6_address_.prefix_len = output.src6->prefix_len; + std::memcpy(inet6_address_.buffer, output.src6->buffer, IPV6_ADDR_LEN); } void VPPForwarderInterface::producerConnection() { @@ -127,6 +154,9 @@ void VPPForwarderInterface::connect(bool is_consumer) { void VPPForwarderInterface::registerRoute(Prefix &prefix) { auto &addr = prefix.toIpAddressStruct(); + // Same ip address for input and outurt params + ip_address_t ip_address; + if (face_id_ == uint32_t(~0)) { hicn_producer_input_params input; std::memset(&input, 0, sizeof(input)); @@ -134,44 +164,52 @@ void VPPForwarderInterface::registerRoute(Prefix &prefix) { hicn_producer_output_params output; std::memset(&output, 0, sizeof(output)); + input.prefix = &ip_address; + output.prod_addr = &ip_address; + // Here we have to ask to the actual connector what is the // memif_id, since this function should be called after the // memif creation. input.swif = sw_if_index_; - input.prefix.ip6.as_u64[0] = addr.as_u64[0]; - input.prefix.ip6.as_u64[1] = addr.as_u64[1]; - input.prefix.type = addr.family == AF_INET6 ? IP_TYPE_IP6 : IP_TYPE_IP4; - input.prefix.prefix_length = addr.prefix_len; + input.prefix->as_u64[0] = addr.as_u64[0]; + input.prefix->as_u64[1] = addr.as_u64[1]; + input.prefix->family = addr.family == AF_INET6 ? AF_INET6 : AF_INET; + input.prefix->prefix_len = addr.prefix_len; input.cs_reserved = content_store_reserved_; - if (int ret = hicn_binary_api_register_prod_app( - VPPForwarderInterface::hicn_api_, &input, &output) < 0) { + int ret = hicn_binary_api_register_prod_app( + VPPForwarderInterface::hicn_api_, &input, &output); + + if (ret < 0) { throw errors::RuntimeException(hicn_binary_api_get_error_string(ret)); } if (addr.family == AF_INET6) { - inet6_address_.prefix_len = output.prod_addr.prefix_length; - std::memcpy(inet6_address_.buffer, output.prod_addr.ip6.as_u8, - IPV6_ADDR_LEN); + inet6_address_.prefix_len = output.prod_addr->prefix_len; + inet6_address_.as_u64[0] = output.prod_addr->as_u64[0]; + inet6_address_.as_u64[1] = output.prod_addr->as_u64[1]; } else { - inet_address_.prefix_len = output.prod_addr.prefix_length; + inet_address_.prefix_len = output.prod_addr->prefix_len; // The ipv4 is written in the last 4 bytes of the ipv6 address, so we need // to copy from the byte 12 - std::memcpy(inet_address_.buffer, output.prod_addr.ip6.as_u8 + 12, - IPV4_ADDR_LEN); + inet_address_.as_u64[0] = output.prod_addr->as_u64[0]; + inet_address_.as_u64[1] = output.prod_addr->as_u64[1]; } face_id_ = output.face_id; } else { hicn_producer_set_route_params params; - params.prefix.ip6.as_u64[0] = addr.as_u64[0]; - params.prefix.ip6.as_u64[1] = addr.as_u64[1]; - params.prefix.type = addr.family == AF_INET6 ? IP_TYPE_IP6 : IP_TYPE_IP4; - params.prefix.prefix_length = addr.prefix_len; + params.prefix = &ip_address; + params.prefix->as_u64[0] = addr.as_u64[0]; + params.prefix->as_u64[1] = addr.as_u64[1]; + params.prefix->family = addr.family == AF_INET6 ? AF_INET6 : AF_INET; + params.prefix->prefix_len = addr.prefix_len; params.face_id = face_id_; - if (int ret = hicn_binary_api_register_route( - VPPForwarderInterface::hicn_api_, ¶ms) < 0) { + int ret = hicn_binary_api_register_route( + VPPForwarderInterface::hicn_api_, ¶ms); + + if (ret < 0) { throw errors::RuntimeException(hicn_binary_api_get_error_string(ret)); } } diff --git a/libtransport/src/hicn/transport/core/vpp_forwarder_interface.h b/libtransport/src/hicn/transport/core/vpp_forwarder_interface.h old mode 100755 new mode 100644 diff --git a/libtransport/src/hicn/transport/interfaces/full_duplex_socket.cc b/libtransport/src/hicn/transport/interfaces/full_duplex_socket.cc old mode 100755 new mode 100644 index 7b6342262..37e1d7b3e --- a/libtransport/src/hicn/transport/interfaces/full_duplex_socket.cc +++ b/libtransport/src/hicn/transport/interfaces/full_duplex_socket.cc @@ -68,9 +68,10 @@ AsyncFullDuplexSocket::AsyncFullDuplexSocket(const Prefix &locator, ConsumerSocket & s, const ContentObject &c) ->bool { return true; }); - consumer_->setSocketOption( - ConsumerCallbacksOptions::CONTENT_RETRIEVED, - std::bind(&AsyncFullDuplexSocket::onContentRetrieved, this, _1, _2, _3)); + ConsumerContentCallback callback = + std::bind(&AsyncFullDuplexSocket::onContentRetrieved, this, _1, _2, _3); + consumer_->setSocketOption(ConsumerCallbacksOptions::CONTENT_RETRIEVED, + callback); consumer_->setSocketOption(GeneralTransportOptions::MAX_INTEREST_RETX, uint32_t{4}); diff --git a/libtransport/src/hicn/transport/interfaces/rtc_socket_producer.cc b/libtransport/src/hicn/transport/interfaces/rtc_socket_producer.cc old mode 100755 new mode 100644 index d8a9d53b9..ec8c4c69e --- a/libtransport/src/hicn/transport/interfaces/rtc_socket_producer.cc +++ b/libtransport/src/hicn/transport/interfaces/rtc_socket_producer.cc @@ -13,9 +13,9 @@ * limitations under the License. */ +#include #include #include -#include #define NACK_HEADER_SIZE 8 // bytes #define TIMESTAMP_LEN 8 // bytes diff --git a/libtransport/src/hicn/transport/interfaces/socket_consumer.cc b/libtransport/src/hicn/transport/interfaces/socket_consumer.cc old mode 100755 new mode 100644 index 8109d0e99..27ed4e65f --- a/libtransport/src/hicn/transport/interfaces/socket_consumer.cc +++ b/libtransport/src/hicn/transport/interfaces/socket_consumer.cc @@ -137,11 +137,11 @@ void ConsumerSocket::stop() { transport_protocol_->stop(); } - //is_running_ = false; + // is_running_ = false; } void ConsumerSocket::resume() { - if(!transport_protocol_->isRunning()){ + if (!transport_protocol_->isRunning()) { transport_protocol_->resume(); } } @@ -548,7 +548,7 @@ int ConsumerSocket::getSocketOption(int socket_option_key, case GeneralTransportOptions::RUNNING: socket_option_value = transport_protocol_->isRunning(); - return SOCKET_OPTION_GET; + return SOCKET_OPTION_GET; case OtherOptions::VIRTUAL_DOWNLOAD: socket_option_value = virtual_download_; diff --git a/libtransport/src/hicn/transport/protocols/rtc.cc b/libtransport/src/hicn/transport/protocols/rtc.cc old mode 100755 new mode 100644 index 1f42cf230..ee90e5d9e --- a/libtransport/src/hicn/transport/protocols/rtc.cc +++ b/libtransport/src/hicn/transport/protocols/rtc.cc @@ -48,9 +48,7 @@ RTCTransportProtocol::~RTCTransportProtocol() { void RTCTransportProtocol::start( utils::SharableVector &content_buffer) { - - if(is_running_) - return; + if (is_running_) return; is_running_ = true; content_buffer_ = content_buffer.shared_from_this(); @@ -63,29 +61,26 @@ void RTCTransportProtocol::start( } void RTCTransportProtocol::stop() { - if(!is_running_) - return; + if (!is_running_) return; is_running_ = false; portal_->stopEventsLoop(); } -void RTCTransportProtocol::resume(){ - if(is_running_) - return; - - is_running_ = true; - - lastRoundBegin_ = std::chrono::steady_clock::now(); - inflightInterestsCount_ = 0; - if(content_buffer_) - content_buffer_->clear(); +void RTCTransportProtocol::resume() { + if (is_running_) return; - scheduleNextInterest(); - - portal_->runEventsLoop(); + is_running_ = true; - is_running_ = false; + lastRoundBegin_ = std::chrono::steady_clock::now(); + inflightInterestsCount_ = 0; + if (content_buffer_) content_buffer_->clear(); + + scheduleNextInterest(); + + portal_->runEventsLoop(); + + is_running_ = false; } void RTCTransportProtocol::onRTCPPacket(uint8_t *packet, size_t len) { @@ -452,8 +447,7 @@ void RTCTransportProtocol::sendInterest() { void RTCTransportProtocol::scheduleNextInterest() { checkRound(); - if(!is_running_) - return; + if (!is_running_) return; uint32_t MAX_RECOVER = 40; // if the packet is more than MAX_RECOVER seq in the past we drop it @@ -573,8 +567,8 @@ void RTCTransportProtocol::onNack(const ContentObject &content_object) { estimatedBw_ = (double)productionRate; // if(inflightInterests_[segmentNumber % - // default_values::default_buffer_size].retransmissions != 0){ ignore nacks for - // retransmissions + // default_values::default_buffer_size].retransmissions != 0){ ignore nacks + // for retransmissions // return; //} diff --git a/libtransport/src/hicn/transport/protocols/rtc_data_path.h b/libtransport/src/hicn/transport/protocols/rtc_data_path.h old mode 100755 new mode 100644 index ace16ff12..b55139d52 --- a/libtransport/src/hicn/transport/protocols/rtc_data_path.h +++ b/libtransport/src/hicn/transport/protocols/rtc_data_path.h @@ -15,8 +15,8 @@ #pragma once -#include #include +#include #include #define ALPHA_RTC 0.125 diff --git a/libtransport/src/hicn/transport/protocols/vegas.cc b/libtransport/src/hicn/transport/protocols/vegas.cc old mode 100755 new mode 100644 index b6d79bfcc..1431020a6 --- a/libtransport/src/hicn/transport/protocols/vegas.cc +++ b/libtransport/src/hicn/transport/protocols/vegas.cc @@ -95,9 +95,7 @@ void VegasTransportProtocol::reset() { void VegasTransportProtocol::start( utils::SharableVector &content_buffer) { - - if(is_running_) - return; + if (is_running_) return; socket_->t0_ = std::chrono::steady_clock::now(); @@ -110,15 +108,13 @@ void VegasTransportProtocol::start( portal_->runEventsLoop(); removeAllPendingInterests(); is_running_ = false; - } -void VegasTransportProtocol::resume(){ - if(is_running_) - return; +void VegasTransportProtocol::resume() { + if (is_running_) return; is_running_ = true; - sendInterest(next_suffix_++); + sendInterest(next_suffix_++); portal_->runEventsLoop(); removeAllPendingInterests(); is_running_ = false; @@ -539,7 +535,7 @@ void VegasTransportProtocol::reassemble() { uint64_t index = last_reassembled_segment_; auto it = receive_buffer_.find(index); - do { + while (it != receive_buffer_.end()) { if (it->second->getPayloadType() == PayloadType::CONTENT_OBJECT) { copyContent(*it->second); receive_buffer_.erase(it); @@ -547,7 +543,7 @@ void VegasTransportProtocol::reassemble() { index = ++last_reassembled_segment_; it = receive_buffer_.find(index); - } while (it != receive_buffer_.end()); + } } void VegasTransportProtocol::partialDownload() { diff --git a/libtransport/src/hicn/transport/utils/identity.cc b/libtransport/src/hicn/transport/utils/identity.cc old mode 100755 new mode 100644 index bdf7f29f9..1b2fd4828 --- a/libtransport/src/hicn/transport/utils/identity.cc +++ b/libtransport/src/hicn/transport/utils/identity.cc @@ -33,10 +33,11 @@ Identity::Identity(const std::string &keystore_name, parcCryptoSuite_GetSigningAlgorithm(static_cast(suite)), key_length, validity_days); - parcAssertTrue(success, - "parcPkcs12KeyStore_CreateFile('%s', '%s', '%s', %d, %d) failed.", - keystore_name.c_str(), keystore_password.c_str(), - subject_name.c_str(), static_cast(key_length), validity_days); + parcAssertTrue( + success, + "parcPkcs12KeyStore_CreateFile('%s', '%s', '%s', %d, %d) failed.", + keystore_name.c_str(), keystore_password.c_str(), subject_name.c_str(), + static_cast(key_length), validity_days); PARCIdentityFile *identity_file = parcIdentityFile_Create(keystore_name.c_str(), keystore_password.c_str()); diff --git a/libtransport/src/hicn/transport/utils/log.cc b/libtransport/src/hicn/transport/utils/log.cc old mode 100755 new mode 100644 index 064625ec0..00bd7d54f --- a/libtransport/src/hicn/transport/utils/log.cc +++ b/libtransport/src/hicn/transport/utils/log.cc @@ -25,8 +25,8 @@ * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, @@ -321,19 +321,19 @@ #include #include +#include #include #include #include #include #include #include -#include #if defined(_WIN32) || defined(_WIN64) #include #else -#include #include +#include #if defined(__linux__) #include #else diff --git a/libtransport/src/hicn/transport/utils/log.h b/libtransport/src/hicn/transport/utils/log.h old mode 100755 new mode 100644 index 17e47e7df..3c4f1277a --- a/libtransport/src/hicn/transport/utils/log.h +++ b/libtransport/src/hicn/transport/utils/log.h @@ -25,8 +25,8 @@ * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, diff --git a/libtransport/src/hicn/transport/utils/object_pool.h b/libtransport/src/hicn/transport/utils/object_pool.h index d4d8e18d6..c369f7e12 100755 --- a/libtransport/src/hicn/transport/utils/object_pool.h +++ b/libtransport/src/hicn/transport/utils/object_pool.h @@ -45,7 +45,11 @@ class ObjectPool { public: using Ptr = std::unique_ptr; - ObjectPool() {} + ObjectPool() : destructor_(false) {} + + ~ObjectPool() { + destructor_ = true; + } std::pair get() { if (object_pool_.empty()) { @@ -60,7 +64,9 @@ class ObjectPool { void add(T *object) { utils::SpinLock::Acquire locked(object_pool_lock_); - object_pool_.emplace_back(makePtr(object)); + if (TRANSPORT_EXPECT_TRUE(!destructor_)) { + object_pool_.emplace_back(makePtr(object)); + } } Ptr makePtr(T *object) { return Ptr(object, ObjectDeleter(this)); } @@ -71,6 +77,7 @@ class ObjectPool { utils::SpinLock object_pool_lock_; std::deque object_pool_; + bool destructor_; }; } // namespace utils \ No newline at end of file diff --git a/libtransport/src/hicn/transport/utils/signer.cc b/libtransport/src/hicn/transport/utils/signer.cc old mode 100755 new mode 100644 index c11d5e183..579b08aff --- a/libtransport/src/hicn/transport/utils/signer.cc +++ b/libtransport/src/hicn/transport/utils/signer.cc @@ -17,10 +17,9 @@ #include #include +#include #include #include -#include - extern "C" { TRANSPORT_CLANG_DISABLE_WARNING("-Wextern-c-compat") @@ -77,7 +76,7 @@ Signer::~Signer() { void Signer::sign(Packet &packet) { // header chain points to the IP + TCP hicn header utils::MemBuf *header_chain = packet.header_head_; - utils::MemBuf * payload_chain = packet.payload_head_; + utils::MemBuf *payload_chain = packet.payload_head_; uint8_t *hicn_packet = header_chain->writableData(); Packet::Format format = packet.getFormat(); std::size_t sign_len_bytes = parcSigner_GetSignatureSize(signer_); @@ -101,46 +100,51 @@ void Signer::sign(Packet &packet) { /* Fill the hicn_ah header */ using namespace std::chrono; - auto now = duration_cast(system_clock::now().time_since_epoch()).count(); + auto now = duration_cast(system_clock::now().time_since_epoch()) + .count(); packet.setSignatureTimestamp(now); // *reinterpret_cast(ah->signTime) = utils::hton(now); - // // std::memcpy(&ah->hicn_ah.signTime, &sign_time, sizeof(ah->hicn_ah.signTime)); + // // std::memcpy(&ah->hicn_ah.signTime, &sign_time, + // sizeof(ah->hicn_ah.signTime)); - packet.setValidationAlgorithm(CryptoSuite(parcSigner_GetCryptoSuite(this->signer_))); + packet.setValidationAlgorithm( + CryptoSuite(parcSigner_GetCryptoSuite(this->signer_))); // ah->validationAlgorithm = parcSigner_GetCryptoSuite(this->signer_); KeyId key_id; - key_id.first = (uint8_t *)parcBuffer_Overlay((PARCBuffer *) parcKeyId_GetKeyId(this->key_id_), 0); + key_id.first = (uint8_t *)parcBuffer_Overlay( + (PARCBuffer *)parcKeyId_GetKeyId(this->key_id_), 0); packet.setKeyId(key_id); // memcpy(ah->keyId, - // parcBuffer_Overlay((PARCBuffer *) parcKeyId_GetKeyId(this->key_id_), 0), - // sizeof(_ah_header_t::keyId)); + // parcBuffer_Overlay((PARCBuffer *) parcKeyId_GetKeyId(this->key_id_), + // 0), sizeof(_ah_header_t::keyId)); // Calculate hash utils::CryptoHasher hasher(parcSigner_GetCryptoHasher(signer_)); hasher.init(); hasher.updateBytes(hicn_packet, header_len); hasher.updateBytes(zeros, sign_len_bytes); - - for (utils::MemBuf *current = payload_chain; current != header_chain; current = current->next()) { + + for (utils::MemBuf *current = payload_chain; current != header_chain; + current = current->next()) { hasher.updateBytes(current->data(), current->length()); } utils::CryptoHash hash = hasher.finalize(); - + PARCSignature *signature = parcSigner_SignDigest(this->signer_, hash.hash_); PARCBuffer *buffer = parcSignature_GetSignature(signature); - PARCByteArray * byte_array = parcBuffer_Array(buffer); - uint8_t * bytes = parcByteArray_Array(byte_array); + PARCByteArray *byte_array = parcBuffer_Array(buffer); + uint8_t *bytes = parcByteArray_Array(byte_array); size_t bytes_len = parcBuffer_Remaining(buffer); if (bytes_len > sign_len_bytes) { throw errors::MalformedAHPacketException(); } - /* Restore the resetted fields */ + /* Restore the resetted fields */ if (format & HFO_INET) { memcpy(hicn_packet, &header_copy, sizeof(hicn_v4_hdr_t)); } else if (format & HFO_INET6) { @@ -151,12 +155,11 @@ void Signer::sign(Packet &packet) { std::unique_ptr signature_buffer; std::unique_ptr tmp_buf = utils::MemBuf::takeOwnership( - bytes, - bytes_len, - bytes_len, - [](void* buf, void* userData){ parcSignature_Release((PARCSignature **)&userData); }, - signature, - true); + bytes, bytes_len, bytes_len, + [](void *buf, void *userData) { + parcSignature_Release((PARCSignature **)&userData); + }, + signature, true); if (offset) { signature_buffer = utils::MemBuf::create(offset); diff --git a/libtransport/src/hicn/transport/utils/verifier.cc b/libtransport/src/hicn/transport/utils/verifier.cc old mode 100755 new mode 100644 index 9a3de43c1..93efe063a --- a/libtransport/src/hicn/transport/utils/verifier.cc +++ b/libtransport/src/hicn/transport/utils/verifier.cc @@ -65,9 +65,9 @@ bool Verifier::addKey(PARCKey *key) { return true; } -PARCKeyId * Verifier::addKeyFromCertificate(const std::string &file_name) { - PARCCertificateFactory *factory = parcCertificateFactory_Create(PARCCertificateType_X509, - PARCContainerEncoding_PEM); +PARCKeyId *Verifier::addKeyFromCertificate(const std::string &file_name) { + PARCCertificateFactory *factory = parcCertificateFactory_Create( + PARCCertificateType_X509, PARCContainerEncoding_PEM); parcAssertNotNull(factory, "Expected non-NULL factory"); if (!file_exists(file_name)) { diff --git a/utils/src/hiperf.cc b/utils/src/hiperf.cc index d8953b36a..221a8746b 100755 --- a/utils/src/hiperf.cc +++ b/utils/src/hiperf.cc @@ -229,7 +229,7 @@ class HIperfClient { } if (consumer_socket_->setSocketOption(OtherOptions::VIRTUAL_DOWNLOAD, - false) == SOCKET_OPTION_NOT_SET) { + configuration_.virtual_download) == SOCKET_OPTION_NOT_SET) { return ERROR_SETUP; } @@ -376,7 +376,7 @@ class HIperfServer { total = producer_socket_->produce( name, reinterpret_cast(content.data()), content.size(), - !configuration_.multiphase_produce_); + !configuration_.multiphase_produce_, suffix); std::cout << "Written " << total << "pieces of data in output buffer" << std::endl; diff --git a/utils/src/ping_client.cc b/utils/src/ping_client.cc index 178bd8bac..c3bfa4086 100755 --- a/utils/src/ping_client.cc +++ b/utils/src/ping_client.cc @@ -403,7 +403,7 @@ int main(int argc, char *argv[]) { } } - Client *ping = new Client(c); + auto ping = std::make_unique(c); auto t0 = std::chrono::steady_clock::now(); ping->ping(); -- cgit 1.2.3-korg