From 6d7704c1b497341fd6dd3c27e3f64d0db062ccc2 Mon Sep 17 00:00:00 2001 From: Mauro Sardara Date: Mon, 4 Feb 2019 11:06:18 +0100 Subject: [HICN-11] Rework on transport protocols improving components modularity Change-Id: I6683ec5b494238dc93591c103d25275e89b9f267 Signed-off-by: Mauro Sardara --- .../src/hicn/transport/utils/CMakeLists.txt | 2 - libtransport/src/hicn/transport/utils/array.h | 2 +- .../src/hicn/transport/utils/chrono_typedefs.h | 27 +++ .../src/hicn/transport/utils/content_store.cc | 28 +-- .../src/hicn/transport/utils/content_store.h | 4 +- .../src/hicn/transport/utils/crypto_hash.h | 4 + libtransport/src/hicn/transport/utils/endianess.h | 141 ----------- .../src/hicn/transport/utils/event_thread.h | 2 - libtransport/src/hicn/transport/utils/identity.h | 1 - .../src/hicn/transport/utils/sharable_vector.h | 30 --- libtransport/src/hicn/transport/utils/signer.cc | 22 +- libtransport/src/hicn/transport/utils/socket.h | 267 --------------------- libtransport/src/hicn/transport/utils/verifier.cc | 19 +- 13 files changed, 58 insertions(+), 491 deletions(-) create mode 100644 libtransport/src/hicn/transport/utils/chrono_typedefs.h delete mode 100644 libtransport/src/hicn/transport/utils/endianess.h delete mode 100644 libtransport/src/hicn/transport/utils/sharable_vector.h delete mode 100644 libtransport/src/hicn/transport/utils/socket.h (limited to 'libtransport/src/hicn/transport/utils') diff --git a/libtransport/src/hicn/transport/utils/CMakeLists.txt b/libtransport/src/hicn/transport/utils/CMakeLists.txt index a5daf785e..c6b09fc5f 100644 --- a/libtransport/src/hicn/transport/utils/CMakeLists.txt +++ b/libtransport/src/hicn/transport/utils/CMakeLists.txt @@ -30,7 +30,6 @@ list(APPEND HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/string_tokenizer.h ${CMAKE_CURRENT_SOURCE_DIR}/hash.h ${CMAKE_CURRENT_SOURCE_DIR}/uri.h - ${CMAKE_CURRENT_SOURCE_DIR}/sharable_vector.h ${CMAKE_CURRENT_SOURCE_DIR}/branch_prediction.h ${CMAKE_CURRENT_SOURCE_DIR}/event_reactor.h ${CMAKE_CURRENT_SOURCE_DIR}/deadline_timer.h @@ -38,7 +37,6 @@ list(APPEND HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/event_reactor.h ${CMAKE_CURRENT_SOURCE_DIR}/min_filter.h ${CMAKE_CURRENT_SOURCE_DIR}/stream_buffer.h - ${CMAKE_CURRENT_SOURCE_DIR}/endianess.h ${CMAKE_CURRENT_SOURCE_DIR}/literals.h ${CMAKE_CURRENT_SOURCE_DIR}/signer.h ${CMAKE_CURRENT_SOURCE_DIR}/verifier.h diff --git a/libtransport/src/hicn/transport/utils/array.h b/libtransport/src/hicn/transport/utils/array.h index a3a66e498..7c0ed65d8 100644 --- a/libtransport/src/hicn/transport/utils/array.h +++ b/libtransport/src/hicn/transport/utils/array.h @@ -21,7 +21,7 @@ namespace utils { -template +template class Array { public: explicit Array(const T *array, size_t size) : array_(array), size_(size) { diff --git a/libtransport/src/hicn/transport/utils/chrono_typedefs.h b/libtransport/src/hicn/transport/utils/chrono_typedefs.h new file mode 100644 index 000000000..8f28e763c --- /dev/null +++ b/libtransport/src/hicn/transport/utils/chrono_typedefs.h @@ -0,0 +1,27 @@ +/* + * 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 + +namespace utils { + +using SteadyClock = std::chrono::steady_clock; +using TimePoint = SteadyClock::time_point; +using Milliseconds = std::chrono::milliseconds; +using Microseconds = std::chrono::microseconds; + +} // namespace utils diff --git a/libtransport/src/hicn/transport/utils/content_store.cc b/libtransport/src/hicn/transport/utils/content_store.cc index 4c7637dad..d48e16daf 100644 --- a/libtransport/src/hicn/transport/utils/content_store.cc +++ b/libtransport/src/hicn/transport/utils/content_store.cc @@ -34,29 +34,29 @@ void ContentStore::insert( std::unique_lock lock(cs_mutex_); if (TRANSPORT_EXPECT_FALSE(content_store_hash_table_.size() != - lru_list_.size())) { + fifo_list_.size())) { TRANSPORT_LOGW("Inconsistent size!!!!"); TRANSPORT_LOGW("Hash Table: %zu |||| FIFO List: %zu", - content_store_hash_table_.size(), lru_list_.size()); + content_store_hash_table_.size(), fifo_list_.size()); } // Check if the content can be cached if (content_object->getLifetime() > 0) { if (content_store_hash_table_.size() >= max_content_store_size_) { - content_store_hash_table_.erase(lru_list_.back()); - lru_list_.pop_back(); + content_store_hash_table_.erase(fifo_list_.back()); + fifo_list_.pop_back(); } // Insert new item auto it = content_store_hash_table_.find(content_object->getName()); if (it != content_store_hash_table_.end()) { - lru_list_.erase(it->second.second); + fifo_list_.erase(it->second.second); content_store_hash_table_.erase(content_object->getName()); } - lru_list_.push_front(std::cref(content_object->getName())); - auto pos = lru_list_.begin(); + fifo_list_.push_front(std::cref(content_object->getName())); + auto pos = fifo_list_.begin(); content_store_hash_table_[content_object->getName()] = ContentStoreEntry( ObjectTimeEntry(content_object, std::chrono::steady_clock::now()), pos); } @@ -67,13 +67,11 @@ const std::shared_ptr &ContentStore::find( std::unique_lock lock(cs_mutex_); auto it = content_store_hash_table_.find(interest.getName()); if (it != content_store_hash_table_.end()) { - // if (std::chrono::duration_cast( - // std::chrono::steady_clock::now() - it->second.first.second).count() - // < it->second.first.first->getLifetime() || - // it->second.first.first->getLifetime() == - // default_values::never_expire_time) { - return it->second.first.first; - // } + if (std::chrono::duration_cast( + std::chrono::steady_clock::now() - it->second.first.second) + .count() < it->second.first.first->getLifetime()) { + return it->second.first.first; + } } return empty_reference_; @@ -82,7 +80,7 @@ const std::shared_ptr &ContentStore::find( void ContentStore::erase(const Name &exact_name) { std::unique_lock lock(cs_mutex_); auto it = content_store_hash_table_.find(exact_name); - lru_list_.erase(it->second.second); + fifo_list_.erase(it->second.second); content_store_hash_table_.erase(exact_name); } diff --git a/libtransport/src/hicn/transport/utils/content_store.h b/libtransport/src/hicn/transport/utils/content_store.h index ab4963fff..39e87fb7d 100644 --- a/libtransport/src/hicn/transport/utils/content_store.h +++ b/libtransport/src/hicn/transport/utils/content_store.h @@ -41,7 +41,7 @@ typedef std::pair, typedef std::pair>::iterator> ContentStoreEntry; -typedef std::list> LRUList; +typedef std::list> FIFOList; typedef std::unordered_map ContentStoreHashTable; class ContentStore { @@ -66,7 +66,7 @@ class ContentStore { private: ContentStoreHashTable content_store_hash_table_; - LRUList lru_list_; + FIFOList fifo_list_; std::shared_ptr empty_reference_; std::size_t max_content_store_size_; std::mutex cs_mutex_; diff --git a/libtransport/src/hicn/transport/utils/crypto_hash.h b/libtransport/src/hicn/transport/utils/crypto_hash.h index 0c15c8bda..945909d14 100644 --- a/libtransport/src/hicn/transport/utils/crypto_hash.h +++ b/libtransport/src/hicn/transport/utils/crypto_hash.h @@ -108,6 +108,10 @@ class CryptoHash { std::memcmp(digest1, digest2, hash_size_map[hash_type])); } + TRANSPORT_ALWAYS_INLINE void display() { + parcBuffer_Display(parcCryptoHash_GetDigest(hash_), 2); + } + private: PARCCryptoHash* hash_; }; diff --git a/libtransport/src/hicn/transport/utils/endianess.h b/libtransport/src/hicn/transport/utils/endianess.h deleted file mode 100644 index d86e764ab..000000000 --- a/libtransport/src/hicn/transport/utils/endianess.h +++ /dev/null @@ -1,141 +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 - -#ifndef _WIN32 -#include -#else -#include -#endif - -#include - -namespace utils { - -namespace { - -template -struct uint_types_by_size; - -#define GENERATOR(sz, fn) \ - static TRANSPORT_ALWAYS_INLINE uint##sz##_t byteswap_gen(uint##sz##_t v) { \ - return fn(v); \ - } \ - template <> \ - struct uint_types_by_size { \ - using type = uint##sz##_t; \ - }; - -GENERATOR(8, uint8_t) -#ifdef _MSC_VER -GENERATOR(64, _byteswap_uint64) -GENERATOR(32, _byteswap_ulong) -GENERATOR(16, _byteswap_ushort) -#else -GENERATOR(64, __builtin_bswap64) -GENERATOR(32, __builtin_bswap32) -GENERATOR(16, __builtin_bswap16) -#endif - -template -struct EndianInt { - static_assert( - (std::is_integral::value && !std::is_same::value) || - std::is_floating_point::value, - "template type parameter must be non-bool integral or floating point"); - - static T swap(T x) { - // we implement this with memcpy because that is defined behavior in C++ - // we rely on compilers to optimize away the memcpy calls - constexpr auto s = sizeof(T); - using B = typename uint_types_by_size::type; - B b; - std::memcpy(&b, &x, s); - b = byteswap_gen(b); - std::memcpy(&x, &b, s); - return x; - } - static T big(T x) { - return portability::little_endian_arch ? EndianInt::swap(x) : x; - } - static T little(T x) { - return portability::big_endian_arch ? EndianInt::swap(x) : x; - } -}; - -} // namespace - -// big* convert between native and big-endian representations -// little* convert between native and little-endian representations -// swap* convert between big-endian and little-endian representations -// -// ntohs, htons == big16 -// ntohl, htonl == big32 -#define GENERATOR1(fn, t, sz) \ - static t fn##sz(t x) { return fn(x); } - -#define GENERATOR2(t, sz) \ - GENERATOR1(swap, t, sz) \ - GENERATOR1(big, t, sz) \ - GENERATOR1(little, t, sz) - -#define GENERATOR3(sz) \ - GENERATOR2(uint##sz##_t, sz) \ - GENERATOR2(int##sz##_t, sz) - -class Endian { - public: - enum class Order : uint8_t { LITTLE, BIG }; - - static constexpr Order order = - portability::little_endian_arch ? Order::LITTLE : Order::BIG; - - template - static T swap(T x) { - return EndianInt::swap(x); - } - - template - static T big(T x) { - return EndianInt::big(x); - } - - template - static T little(T x) { - return EndianInt::little(x); - } - -#if !defined(__ANDROID__) - GENERATOR3(64) - GENERATOR3(32) - GENERATOR3(16) - GENERATOR3(8) -#endif -}; - -template -static TRANSPORT_ALWAYS_INLINE T ntoh(T x) { - return Endian::order == Endian::Order::LITTLE ? Endian::little(x) : x; -} - -template -static TRANSPORT_ALWAYS_INLINE T hton(T x) { - return Endian::order == Endian::Order::LITTLE ? Endian::big(x) : x; -} - -} // namespace utils \ No newline at end of file diff --git a/libtransport/src/hicn/transport/utils/event_thread.h b/libtransport/src/hicn/transport/utils/event_thread.h index 3bf08c94b..e50ae9648 100644 --- a/libtransport/src/hicn/transport/utils/event_thread.h +++ b/libtransport/src/hicn/transport/utils/event_thread.h @@ -76,8 +76,6 @@ class EventThread { } void stop() { - TRANSPORT_LOGI("Stopping event thread!"); - io_service_.stop(); if (thread_ && thread_->joinable()) { diff --git a/libtransport/src/hicn/transport/utils/identity.h b/libtransport/src/hicn/transport/utils/identity.h index 018842ee3..349b38914 100644 --- a/libtransport/src/hicn/transport/utils/identity.h +++ b/libtransport/src/hicn/transport/utils/identity.h @@ -36,7 +36,6 @@ class Identity { unsigned int signature_length, unsigned int validity_days, const std::string &subject_name); - // No copies Identity(const Identity &other); Identity(std::string &file_name, std::string &password, diff --git a/libtransport/src/hicn/transport/utils/sharable_vector.h b/libtransport/src/hicn/transport/utils/sharable_vector.h deleted file mode 100644 index 31adff1ad..000000000 --- a/libtransport/src/hicn/transport/utils/sharable_vector.h +++ /dev/null @@ -1,30 +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 utils { - -template -class SharableVector : public std::vector, - public std::enable_shared_from_this> { - public: - virtual ~SharableVector(){}; -}; - -} // namespace utils diff --git a/libtransport/src/hicn/transport/utils/signer.cc b/libtransport/src/hicn/transport/utils/signer.cc index e1262ec94..981e5f02b 100644 --- a/libtransport/src/hicn/transport/utils/signer.cc +++ b/libtransport/src/hicn/transport/utils/signer.cc @@ -16,7 +16,6 @@ */ #include -#include #include #include #include @@ -91,14 +90,8 @@ void Signer::sign(Packet &packet) { // Copy IP+TCP/ICMP header before zeroing them hicn_header_t header_copy; - if (format == HF_INET_TCP_AH) { - memcpy(&header_copy, hicn_packet, HICN_V4_TCP_HDRLEN); - } else if (format == HF_INET6_TCP_AH) { - memcpy(&header_copy, hicn_packet, HICN_V6_TCP_HDRLEN); - } else { - throw errors::RuntimeException( - "Signer::sign -- Packet format not expected."); - } + hicn_packet_copy_header(format, (const hicn_header_t *)packet.packet_start_, + &header_copy, false); std::size_t header_len = Packet::getHeaderSizeFromFormat(format); @@ -130,7 +123,8 @@ void Signer::sign(Packet &packet) { utils::CryptoHash hash = hasher.finalize(); PARCSignature *signature = parcSigner_SignDigestNoAlloc( - this->signer_, hash.hash_, packet.getSignature(), (uint32_t)sign_len_bytes); + this->signer_, hash.hash_, packet.getSignature(), + (uint32_t)sign_len_bytes); PARCBuffer *buffer = parcSignature_GetSignature(signature); size_t bytes_len = parcBuffer_Remaining(buffer); @@ -139,12 +133,8 @@ void Signer::sign(Packet &packet) { throw errors::MalformedAHPacketException(); } - /* Restore the resetted fields */ - if (format & HFO_INET) { - memcpy(hicn_packet, &header_copy, HICN_V4_TCP_HDRLEN); - } else if (format & HFO_INET6) { - memcpy(hicn_packet, &header_copy, HICN_V6_TCP_HDRLEN); - } + hicn_packet_copy_header(format, &header_copy, + (hicn_header_t *)packet.packet_start_, false); } PARCKeyStore *Signer::getKeyStore() { diff --git a/libtransport/src/hicn/transport/utils/socket.h b/libtransport/src/hicn/transport/utils/socket.h deleted file mode 100644 index ab8578f91..000000000 --- a/libtransport/src/hicn/transport/utils/socket.h +++ /dev/null @@ -1,267 +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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define SOCKET_OPTION_GET 0 -#define SOCKET_OPTION_NOT_GET 1 -#define SOCKET_OPTION_SET 2 -#define SOCKET_OPTION_NOT_SET 3 -#define SOCKET_OPTION_DEFAULT 12345 - -#define VOID_HANDLER 0 - -namespace transport { - -namespace transport { - -template -class Socket; -class ConsumerSocket; -class ProducerSocket; - -using Interest = core::Interest; -using ContentObject = core::ContentObject; -using Name = core::Name; -using ContentObjectManifest = core::ManifestInline; -using InterestManifest = core::ManifestInline; -using HashAlgorithm = core::HashAlgorithm; -using CryptoSuite = utils::CryptoSuite; -using Identity = utils::Identity; -using Verifier = utils::Verifier; - -using HicnForwarderPortal = core::HicnForwarderPortal; - -#ifdef __linux__ -#ifndef __ANDROID__ -using RawSocketPortal = core::RawSocketPortal; -#endif -#endif - -#ifdef __vpp__ -using VPPForwarderPortal = core::VPPForwarderPortal; -using BaseSocket = Socket; -using BasePortal = VPPForwarderPortal; -#else -using BaseSocket = Socket; -using BasePortal = HicnForwarderPortal; -#endif - -using PayloadType = core::PayloadType; -using Prefix = core::Prefix; -using Array = utils::Array; - -using ConsumerInterestCallback = - std::function; - -using ConsumerContentCallback = - std::function; - -using ConsumerTimerCallback = - std::function; - -using ProducerContentCallback = std::function; - -using ConsumerContentObjectCallback = - std::function; - -using ConsumerContentObjectVerificationCallback = - std::function; - -using ConsumerManifestCallback = - std::function; - -using ProducerContentObjectCallback = - std::function; - -using ProducerInterestCallback = - std::function; - -using ProducerInterestCallback = - std::function; - -template -class Socket { - static_assert(std::is_same::value -#ifdef __linux__ -#ifndef __ANDROID__ - || std::is_same::value -#ifdef __vpp__ - || std::is_same::value -#endif -#endif - , -#else - , - -#endif - "This class is not allowed as Portal"); - - public: - typedef PortalType Portal; - - virtual asio::io_service &getIoService() = 0; - - virtual void connect() = 0; - - virtual int setSocketOption(int socket_option_key, - uint32_t socket_option_value) = 0; - - virtual int setSocketOption(int socket_option_key, - double socket_option_value) = 0; - - virtual int setSocketOption(int socket_option_key, - bool socket_option_value) = 0; - - virtual int setSocketOption(int socket_option_key, - Name socket_option_value) = 0; - - virtual int setSocketOption(int socket_option_key, - std::list socket_option_value) = 0; - - virtual int setSocketOption( - int socket_option_key, - ProducerContentObjectCallback socket_option_value) = 0; - - virtual int setSocketOption(int socket_option_key, - ProducerInterestCallback socket_option_value) = 0; - - virtual int setSocketOption(int socket_option_key, - ProducerContentCallback socket_option_value) = 0; - - virtual int setSocketOption( - int socket_option_key, - ConsumerContentObjectVerificationCallback socket_option_value) = 0; - - virtual int setSocketOption( - int socket_option_key, - ConsumerContentObjectCallback socket_option_value) = 0; - - virtual int setSocketOption(int socket_option_key, - ConsumerInterestCallback socket_option_value) = 0; - - virtual int setSocketOption(int socket_option_key, - ConsumerContentCallback socket_option_value) = 0; - - virtual int setSocketOption(int socket_option_key, - ConsumerManifestCallback socket_option_value) = 0; - - virtual int setSocketOption(int socket_option_key, - IcnObserver *socket_option_value) = 0; - - virtual int setSocketOption(int socket_option_key, - HashAlgorithm socket_option_value) = 0; - - virtual int setSocketOption(int socket_option_key, - CryptoSuite socket_option_value) = 0; - - virtual int setSocketOption(int socket_option_key, - const Identity &socket_option_value) = 0; - - virtual int setSocketOption(int socket_option_key, - ConsumerTimerCallback socket_option_value) = 0; - - virtual int setSocketOption(int socket_option_key, - const std::string &socket_option_value) = 0; - - virtual int getSocketOption(int socket_option_key, - uint32_t &socket_option_value) = 0; - - virtual int getSocketOption(int socket_option_key, - double &socket_option_value) = 0; - - virtual int getSocketOption(int socket_option_key, - bool &socket_option_value) = 0; - - virtual int getSocketOption(int socket_option_key, - Name &socket_option_value) = 0; - - virtual int getSocketOption(int socket_option_key, - std::list &socket_option_value) = 0; - - virtual int getSocketOption( - int socket_option_key, - ProducerContentObjectCallback &socket_option_value) = 0; - - virtual int getSocketOption( - int socket_option_key, ProducerInterestCallback &socket_option_value) = 0; - - virtual int getSocketOption( - int socket_option_key, - ConsumerContentObjectVerificationCallback &socket_option_value) = 0; - - virtual int getSocketOption( - int socket_option_key, - ConsumerContentObjectCallback &socket_option_value) = 0; - - virtual int getSocketOption( - int socket_option_key, ConsumerInterestCallback &socket_option_value) = 0; - - virtual int getSocketOption(int socket_option_key, - ConsumerContentCallback &socket_option_value) = 0; - - virtual int getSocketOption( - int socket_option_key, ConsumerManifestCallback &socket_option_value) = 0; - - virtual int getSocketOption(int socket_option_key, - ProducerContentCallback &socket_option_value) = 0; - - virtual int getSocketOption(int socket_option_key, - std::shared_ptr &socket_option_value) = 0; - - virtual int getSocketOption(int socket_option_key, - IcnObserver **socket_option_value) = 0; - - virtual int getSocketOption(int socket_option_key, - HashAlgorithm &socket_option_value) = 0; - - virtual int getSocketOption(int socket_option_key, - CryptoSuite &socket_option_value) = 0; - - virtual int getSocketOption(int socket_option_key, - Identity &socket_option_value) = 0; - - virtual int getSocketOption(int socket_option_key, - std::string &socket_option_value) = 0; - - virtual int getSocketOption(int socket_option_key, - ConsumerTimerCallback &socket_option_value) = 0; - - protected: - virtual ~Socket(){}; - - protected: - std::string output_interface_; -}; - -} // namespace transport - -} // namespace transport diff --git a/libtransport/src/hicn/transport/utils/verifier.cc b/libtransport/src/hicn/transport/utils/verifier.cc index 4295aaab7..af19d8b5e 100644 --- a/libtransport/src/hicn/transport/utils/verifier.cc +++ b/libtransport/src/hicn/transport/utils/verifier.cc @@ -109,14 +109,8 @@ int Verifier::verify(const Packet &packet) { // Copy IP+TCP/ICMP header before zeroing them hicn_header_t header_copy; - if (format == HF_INET_TCP_AH) { - memcpy(&header_copy, hicn_packet, HICN_V4_TCP_HDRLEN); - } else if (format == HF_INET6_TCP_AH) { - memcpy(&header_copy, hicn_packet, HICN_V6_TCP_HDRLEN); - } else { - throw errors::RuntimeException( - "Verifier::verify -- Packet format not expected."); - } + hicn_packet_copy_header(format, (const hicn_header_t *)packet.packet_start_, + &header_copy, false); std::size_t header_len = Packet::getHeaderSizeFromFormat(format); @@ -130,7 +124,7 @@ int Verifier::verify(const Packet &packet) { int ah_payload_len = (int)packet.getSignatureSize(); uint8_t *_signature = packet.getSignature(); - uint8_t * signature = new uint8_t[ah_payload_len]; + uint8_t *signature = new uint8_t[ah_payload_len]; // TODO Remove signature copy at this point, by not setting to zero // the validation payload. @@ -185,11 +179,8 @@ int Verifier::verify(const Packet &packet) { verifier_, key_id, hash_computed_locally, suite, signatureToVerify); /* Restore the resetted fields */ - if (format & HFO_INET) { - memcpy(hicn_packet, &header_copy, HICN_V4_TCP_HDRLEN); - } else if (format & HFO_INET6) { - memcpy(hicn_packet, &header_copy, HICN_V6_TCP_HDRLEN); - } + hicn_packet_copy_header(format, &header_copy, + (hicn_header_t *)packet.packet_start_, false); delete[] signature; -- cgit 1.2.3-korg