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 --- 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 +-- 6 files changed, 47 insertions(+), 36 deletions(-) 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 (limited to 'libtransport/src/hicn/transport/utils') 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)) { -- cgit 1.2.3-korg