cmake_parse_arguments(ARG
"NO_INSTALL"
"COMPONENT"
- "SOURCES;LINK_LIBRARIES;DEPENDS;DEFINITIONS"
+ "SOURCES;LINK_LIBRARIES;DEPENDS;INCLUDE_DIRS;DEFINITIONS"
${ARGN}
)
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()
#define IP_MAX_ADDR_LEN IPV6_ADDR_LEN
#define TCP_SEQNO_LEN 4 /* bytes */
-typedef struct
+struct ip_address
{
union
{
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);
${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
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
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;
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);
}
#ifdef __vpp__
-#include <hicn/transport/core/hicn_binary_api.h>
-#include <hicn/transport/core/vpp_binary_api_internal.h>
-
#include <hicn/transport/core/hicn_binary_api.h>
#include <hicn/transport/core/vpp_binary_api_internal.h>
#include <hicn/transport/utils/log.h>
+#define HICN_VPP_PLUGIN
+#include <hicn/name.h>
+#undef HICN_VPP_PLUGIN
+
#include <fcntl.h>
#include <inttypes.h>
#include <semaphore.h>
};
/////////////////////////////////////////////////////
-#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
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);
}
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);
}
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");
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);
/* 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;
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);
}
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;
}
#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;
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;
#include <hicn/transport/core/hicn_forwarder_interface.h>
+
#define ADDR_INET 1
#define ADDR_INET6 2
#define ADD_ROUTE 3
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; });
+++ /dev/null
-/*
- * 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 <hicn/transport/core/key_locator.h>
-
-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
+++ /dev/null
-/*
- * 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 <hicn/transport/core/key_locator_type.h>
-#include <hicn/transport/core/name.h>
-
-namespace transport {
-
-namespace core {
-
-class KeyLocator : public std::enable_shared_from_this<KeyLocator> {
- 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
+++ /dev/null
-/*
- * 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
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 <typename T>
- Manifest(T&& base)
- : packet_(new Base(std::move<T&&>(base)), nullptr),
+ Manifest(T &&base)
+ : packet_(new Base(std::move<T &&>(base)), nullptr),
encoder_(*packet_),
decoder_(*packet_) {
Base::setPayloadType(PayloadType::MANIFEST);
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<ManifestImpl&>(*this).estimateManifestSizeImpl(
+ return static_cast<ManifestImpl &>(*this).estimateManifestSizeImpl(
additional_entries);
}
* After the call to encode, users MUST call clear before adding data
* to the manifest.
*/
- Manifest& encode() { return static_cast<ManifestImpl&>(*this).encodeImpl(); }
+ Manifest &encode() { return static_cast<ManifestImpl &>(*this).encodeImpl(); }
- Manifest& decode() {
+ Manifest &decode() {
Manifest::decoder_.decode();
manifest_type_ = decoder_.getManifestType();
hash_algorithm_ = decoder_.getHashAlgorithm();
is_last_ = decoder_.getIsFinalManifest();
- return static_cast<ManifestImpl&>(*this).decodeImpl();
+ return static_cast<ManifestImpl &>(*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;
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;
}
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;
encoder_.update();
}
- typename Base::Ptr&& getPacket() { return std::move(packet_); }
+ typename Base::Ptr &&getPacket() { return std::move(packet_); }
protected:
typename Base::Ptr packet_;
virtual ~ManifestEncoder() = default;
ManifestEncoder encode() {
- return static_cast<Implementation&>(*this).encodeImpl();
+ return static_cast<Implementation &>(*this).encodeImpl();
}
- ManifestEncoder& clear() {
- return static_cast<Implementation&>(*this).clearImpl();
+ ManifestEncoder &clear() {
+ return static_cast<Implementation &>(*this).clearImpl();
}
- ManifestEncoder& setManifestType(ManifestType type) {
- return static_cast<Implementation&>(*this).setManifestTypeImpl(type);
+ ManifestEncoder &setManifestType(ManifestType type) {
+ return static_cast<Implementation &>(*this).setManifestTypeImpl(type);
}
- ManifestEncoder& setHashAlgorithm(HashAlgorithm hash) {
- return static_cast<Implementation&>(*this).setHashAlgorithmImpl(hash);
+ ManifestEncoder &setHashAlgorithm(HashAlgorithm hash) {
+ return static_cast<Implementation &>(*this).setHashAlgorithmImpl(hash);
}
- ManifestEncoder& setFinalChunkNumber(uint32_t final_chunk) {
- return static_cast<Implementation&>(*this).setFinalChunkImpl(final_chunk);
+ ManifestEncoder &setFinalChunkNumber(uint32_t final_chunk) {
+ return static_cast<Implementation &>(*this).setFinalChunkImpl(final_chunk);
}
- ManifestEncoder& setNextSegmentCalculationStrategy(
+ ManifestEncoder &setNextSegmentCalculationStrategy(
NextSegmentCalculationStrategy strategy) {
- return static_cast<Implementation&>(*this)
+ return static_cast<Implementation &>(*this)
.setNextSegmentCalculationStrategyImpl(strategy);
}
typename T,
typename = std::enable_if_t<std::is_same<
std::remove_const_t<std::remove_reference_t<T>>, core::Name>::value>>
- ManifestEncoder& setBaseName(T&& name) {
- return static_cast<Implementation&>(*this).setBaseNameImpl(name);
+ ManifestEncoder &setBaseName(T &&name) {
+ return static_cast<Implementation &>(*this).setBaseNameImpl(name);
}
template <typename Hash>
- ManifestEncoder& addSuffixAndHash(uint32_t suffix, Hash&& hash) {
- return static_cast<Implementation&>(*this).addSuffixAndHashImpl(
- suffix, std::forward<Hash&&>(hash));
+ ManifestEncoder &addSuffixAndHash(uint32_t suffix, Hash &&hash) {
+ return static_cast<Implementation &>(*this).addSuffixAndHashImpl(
+ suffix, std::forward<Hash &&>(hash));
}
- ManifestEncoder& setIsFinalManifest(bool is_last) {
- return static_cast<Implementation&>(*this).setIsFinalManifestImpl(is_last);
+ ManifestEncoder &setIsFinalManifest(bool is_last) {
+ return static_cast<Implementation &>(*this).setIsFinalManifestImpl(is_last);
}
- ManifestEncoder& setVersion(ManifestVersion version) {
- return static_cast<Implementation&>(*this).setVersionImpl(version);
+ ManifestEncoder &setVersion(ManifestVersion version) {
+ return static_cast<Implementation &>(*this).setVersionImpl(version);
}
std::size_t estimateSerializedLength(std::size_t number_of_entries) {
- return static_cast<Implementation&>(*this).estimateSerializedLengthImpl(
+ return static_cast<Implementation &>(*this).estimateSerializedLengthImpl(
number_of_entries);
}
- ManifestEncoder& update() {
- return static_cast<Implementation&>(*this).updateImpl();
+ ManifestEncoder &update() {
+ return static_cast<Implementation &>(*this).updateImpl();
}
- ManifestEncoder& setFinalBlockNumber(std::uint32_t final_block_number) {
- return static_cast<Implementation&>(*this).setFinalBlockNumberImpl(
+ ManifestEncoder &setFinalBlockNumber(std::uint32_t final_block_number) {
+ return static_cast<Implementation &>(*this).setFinalBlockNumberImpl(
final_block_number);
}
public:
virtual ~ManifestDecoder() = default;
- ManifestDecoder& clear() {
- return static_cast<Implementation&>(*this).clearImpl();
+ ManifestDecoder &clear() {
+ return static_cast<Implementation &>(*this).clearImpl();
}
- void decode() { static_cast<Implementation&>(*this).decodeImpl(); }
+ void decode() { static_cast<Implementation &>(*this).decodeImpl(); }
ManifestType getManifestType() const {
- return static_cast<const Implementation&>(*this).getManifestTypeImpl();
+ return static_cast<const Implementation &>(*this).getManifestTypeImpl();
}
HashAlgorithm getHashAlgorithm() const {
- return static_cast<const Implementation&>(*this).getHashAlgorithmImpl();
+ return static_cast<const Implementation &>(*this).getHashAlgorithmImpl();
}
uint32_t getFinalChunkNumber() const {
- return static_cast<const Implementation&>(*this).getFinalChunkImpl();
+ return static_cast<const Implementation &>(*this).getFinalChunkImpl();
}
NextSegmentCalculationStrategy getNextSegmentCalculationStrategy() const {
- return static_cast<const Implementation&>(*this)
+ return static_cast<const Implementation &>(*this)
.getNextSegmentCalculationStrategyImpl();
}
core::Name getBaseName() const {
- return static_cast<const Implementation&>(*this).getBaseNameImpl();
+ return static_cast<const Implementation &>(*this).getBaseNameImpl();
}
auto getSuffixHashList() {
- return static_cast<Implementation&>(*this).getSuffixHashListImpl();
+ return static_cast<Implementation &>(*this).getSuffixHashListImpl();
}
bool getIsFinalManifest() const {
- return static_cast<const Implementation&>(*this).getIsFinalManifestImpl();
+ return static_cast<const Implementation &>(*this).getIsFinalManifestImpl();
}
ManifestVersion getVersion() const {
- return static_cast<const Implementation&>(*this).getVersionImpl();
+ return static_cast<const Implementation &>(*this).getVersionImpl();
}
std::size_t estimateSerializedLength(std::size_t number_of_entries) const {
- return static_cast<const Implementation&>(*this)
+ return static_cast<const Implementation &>(*this)
.estimateSerializedLengthImpl(number_of_entries);
}
uint32_t getFinalBlockNumber() const {
- return static_cast<const Implementation&>(*this).getFinalBlockNumberImpl();
+ return static_cast<const Implementation &>(*this).getFinalBlockNumberImpl();
}
};
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<ManifestHeader*>(manifest_->writableData())),
- manifest_entries_(reinterpret_cast<ManifestEntry*>(
+ reinterpret_cast<ManifestHeader *>(manifest_->writableData())),
+ manifest_entries_(reinterpret_cast<ManifestEntry *>(
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<uint8_t>(algorithm);
return *this;
}
-FixedManifestEncoder& FixedManifestEncoder::setManifestTypeImpl(
+FixedManifestEncoder &FixedManifestEncoder::setManifestTypeImpl(
ManifestType manifest_type) {
manifest_header_->manifest_type = static_cast<uint8_t>(manifest_type);
return *this;
}
-FixedManifestEncoder&
+FixedManifestEncoder &
FixedManifestEncoder::setNextSegmentCalculationStrategyImpl(
NextSegmentCalculationStrategy strategy) {
manifest_header_->next_segment_strategy = static_cast<uint8_t>(strategy);
return *this;
}
-FixedManifestEncoder& FixedManifestEncoder::setBaseNameImpl(
- const core::Name& base_name) {
+FixedManifestEncoder &FixedManifestEncoder::setBaseNameImpl(
+ const core::Name &base_name) {
base_name.copyToDestination(
- reinterpret_cast<uint8_t*>(&manifest_header_->prefix[0]), false);
+ reinterpret_cast<uint8_t *>(&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<std::uint8_t>();
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<uint8_t*>(manifest_entries_[current_entry_].hash), hash,
+ reinterpret_cast<uint8_t *>(manifest_entries_[current_entry_].hash), hash,
length);
manifest_header_->number_of_entries++;
}
}
-FixedManifestEncoder& FixedManifestEncoder::setIsFinalManifestImpl(
+FixedManifestEncoder &FixedManifestEncoder::setIsFinalManifestImpl(
bool is_last) {
manifest_header_->flags.is_last = static_cast<uint8_t>(is_last);
return *this;
}
-FixedManifestEncoder& FixedManifestEncoder::setVersionImpl(
+FixedManifestEncoder &FixedManifestEncoder::setVersionImpl(
ManifestVersion version) {
manifest_header_->version = static_cast<uint8_t>(version);
return *this;
sizeof(ManifestEntry);
}
-FixedManifestEncoder& FixedManifestEncoder::updateImpl() {
+FixedManifestEncoder &FixedManifestEncoder::updateImpl() {
max_size_ = Packet::default_mtu - packet_.headerSize();
- manifest_header_ = reinterpret_cast<ManifestHeader*>(
- const_cast<uint8_t*>(packet_.getPayload().data()));
- manifest_entries_ = reinterpret_cast<ManifestEntry*>(
- const_cast<uint8_t*>(packet_.getPayload().data()) +
+ manifest_header_ = reinterpret_cast<ManifestHeader *>(
+ const_cast<uint8_t *>(packet_.getPayload().data()));
+ manifest_entries_ = reinterpret_cast<ManifestEntry *>(
+ const_cast<uint8_t *>(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;
return sizeof(ManifestHeader);
}
-FixedManifestDecoder::FixedManifestDecoder(Packet& packet)
+FixedManifestDecoder::FixedManifestDecoder(Packet &packet)
: packet_(packet),
- manifest_header_(reinterpret_cast<ManifestHeader*>(
- const_cast<uint8_t*>(packet_.getPayload().data()))),
- manifest_entries_(reinterpret_cast<ManifestEntry*>(
- const_cast<uint8_t*>(packet_.getPayload().data()) +
+ manifest_header_(reinterpret_cast<ManifestHeader *>(
+ const_cast<uint8_t *>(packet_.getPayload().data()))),
+ manifest_entries_(reinterpret_cast<ManifestEntry *>(
+ const_cast<uint8_t *>(packet_.getPayload().data()) +
sizeof(ManifestHeader))) {}
FixedManifestDecoder::~FixedManifestDecoder() {}
}
}
-FixedManifestDecoder& FixedManifestDecoder::clearImpl() { return *this; }
+FixedManifestDecoder &FixedManifestDecoder::clearImpl() { return *this; }
ManifestType FixedManifestDecoder::getManifestTypeImpl() const {
return static_cast<ManifestType>(manifest_header_->manifest_type);
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<uint8_t*>(
+ reinterpret_cast<uint8_t *>(
&manifest_entries_[i].hash[0])));
}
core::Name FixedManifestDecoder::getBaseNameImpl() const {
if (static_cast<bool>(manifest_header_->flags.ipv6)) {
return core::Name(AF_INET6,
- reinterpret_cast<uint8_t*>(&manifest_header_->prefix));
+ reinterpret_cast<uint8_t *>(&manifest_header_->prefix));
} else {
return core::Name(AF_INET,
- reinterpret_cast<uint8_t*>(&manifest_header_->prefix));
+ reinterpret_cast<uint8_t *>(&manifest_header_->prefix));
}
}
using Encoder = FixedManifestEncoder;
using Decoder = FixedManifestDecoder;
using HashType = utils::CryptoHash;
- using SuffixList = std::list<std::pair<std::uint32_t, std::uint8_t*>>;
+ using SuffixList = std::list<std::pair<std::uint32_t, std::uint8_t *>>;
};
struct Flags {
class FixedManifestEncoder : public ManifestEncoder<FixedManifestEncoder> {
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<utils::MemBuf> manifest_;
- ManifestHeader* manifest_header_;
- ManifestEntry* manifest_entries_;
+ ManifestHeader *manifest_header_;
+ ManifestEntry *manifest_entries_;
std::size_t current_entry_;
};
class FixedManifestDecoder : public ManifestDecoder<FixedManifestDecoder> {
public:
- FixedManifestDecoder(Packet& packet);
+ FixedManifestDecoder(Packet &packet);
~FixedManifestDecoder();
void decodeImpl();
- FixedManifestDecoder& clearImpl();
+ FixedManifestDecoder &clearImpl();
ManifestType getManifestTypeImpl() const;
uint32_t getFinalBlockNumberImpl() const;
private:
- Packet& packet_;
- ManifestHeader* manifest_header_;
- ManifestEntry* manifest_entries_;
+ Packet &packet_;
+ ManifestHeader *manifest_header_;
+ ManifestEntry *manifest_entries_;
};
} // namespace core
namespace {
template <typename T>
-TRANSPORT_ALWAYS_INLINE void checkPointer(T* pointer) {
+TRANSPORT_ALWAYS_INLINE void checkPointer(T *pointer) {
if (pointer == nullptr) {
throw errors::NullPointerException();
}
}
template <typename EnumType>
-TRANSPORT_ALWAYS_INLINE void setValueToJson(Json::Value& root, EnumType value) {
+TRANSPORT_ALWAYS_INLINE void setValueToJson(Json::Value &root, EnumType value) {
root[JSONKey<EnumType>::key] = static_cast<uint8_t>(value);
}
template <typename EnumType>
-TRANSPORT_ALWAYS_INLINE EnumType getValueFromJson(const Json::Value& root) {
+TRANSPORT_ALWAYS_INLINE EnumType getValueFromJson(const Json::Value &root) {
return static_cast<EnumType>(root[JSONKey<EnumType>::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<const uint8_t*>(strbuf.data());
+ const uint8_t *buffer = asio::buffer_cast<const uint8_t *>(strbuf.data());
packet_.setPayload(buffer, strbuf.size());
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<core::Name>::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));
return *this;
}
-TRANSPORT_ALWAYS_INLINE JSONManifestEncoder&
+TRANSPORT_ALWAYS_INLINE JSONManifestEncoder &
JSONManifestEncoder::setIsFinalManifestImpl(bool is_last) {
root_[JSONKey<bool>::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);
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);
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();
}
return 0;
}
-JSONManifestDecoder::JSONManifestDecoder(Packet& packet) : packet_(packet) {}
+JSONManifestDecoder::JSONManifestDecoder(Packet &packet) : packet_(packet) {}
JSONManifestDecoder::~JSONManifestDecoder() {}
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());
delete reader;
}
-TRANSPORT_ALWAYS_INLINE JSONManifestDecoder& JSONManifestDecoder::clearImpl() {
+TRANSPORT_ALWAYS_INLINE JSONManifestDecoder &JSONManifestDecoder::clearImpl() {
root_.clear();
return *this;
}
using Encoder = JSONManifestEncoder;
using Decoder = JSONManifestDecoder;
using HashType = utils::CryptoHash;
- using SuffixList = std::unordered_map<std::uint32_t, std::uint8_t*>;
+ using SuffixList = std::unordered_map<std::uint32_t, std::uint8_t *>;
};
template <typename T>
template <>
struct JSONKey<ManifestVersion> {
- static const constexpr char* key = "manifest_version";
+ static const constexpr char *key = "manifest_version";
};
template <>
struct JSONKey<HashAlgorithm> {
- static const constexpr char* key = "hash_algorithm";
+ static const constexpr char *key = "hash_algorithm";
};
template <>
struct JSONKey<ManifestType> {
- static const constexpr char* key = "manifest_type";
+ static const constexpr char *key = "manifest_type";
};
template <>
struct JSONKey<NextSegmentCalculationStrategy> {
- static const constexpr char* key = "next_segment_strategy";
+ static const constexpr char *key = "next_segment_strategy";
};
template <>
struct JSONKey<typename JSON::SuffixList> {
- static const constexpr char* key = "suffix_hash_list";
+ static const constexpr char *key = "suffix_hash_list";
};
template <>
struct JSONKey<core::Name> {
- static const constexpr char* key = "base_name";
+ static const constexpr char *key = "base_name";
};
template <>
struct JSONKey<bool> {
- static const constexpr char* final_manifest = "final_manifest";
+ static const constexpr char *final_manifest = "final_manifest";
};
class JSONManifestEncoder : public ManifestEncoder<JSONManifestEncoder> {
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<JSONManifestDecoder> {
public:
- JSONManifestDecoder(Packet& packet);
+ JSONManifestDecoder(Packet &packet);
~JSONManifestDecoder() override;
void decodeImpl();
- JSONManifestDecoder& clearImpl();
+ JSONManifestDecoder &clearImpl();
ManifestType getManifestTypeImpl() const;
uint32_t getFinalBlockNumberImpl() const;
private:
- Packet& packet_;
+ Packet &packet_;
Json::Value root_;
};
namespace {
template <typename T>
-TRANSPORT_ALWAYS_INLINE void checkPointer(T* pointer) {
+TRANSPORT_ALWAYS_INLINE void checkPointer(T *pointer) {
if (pointer == nullptr) {
throw errors::NullPointerException();
}
}
template <typename EnumType>
-TRANSPORT_ALWAYS_INLINE void setValueToJson(PARCJSON* root, EnumType value) {
+TRANSPORT_ALWAYS_INLINE void setValueToJson(PARCJSON *root, EnumType value) {
parcJSON_AddInteger(root, JSONKey<EnumType>::key,
static_cast<int64_t>(value));
}
template <typename EnumType>
-TRANSPORT_ALWAYS_INLINE EnumType getValueFromJson(PARCJSON* root) {
+TRANSPORT_ALWAYS_INLINE EnumType getValueFromJson(PARCJSON *root) {
checkPointer(root);
- PARCJSONValue* value = parcJSON_GetValueByName(root, JSONKey<EnumType>::key);
+ PARCJSONValue *value = parcJSON_GetValueByName(root, JSONKey<EnumType>::key);
EnumType ret = static_cast<EnumType>(parcJSONValue_GetInteger(value));
// parcJSONValue_Release(&value);
}
}
-TRANSPORT_ALWAYS_INLINE SONManifestEncoder& JSONManifestEncoder::encodeImpl(
- Packet& packet) {
- char* json_string = parcJSON_ToString(root_);
- packet.setPayload(reinterpret_cast<uint8_t*>(json_string),
+TRANSPORT_ALWAYS_INLINE SONManifestEncoder &JSONManifestEncoder::encodeImpl(
+ Packet &packet) {
+ char *json_string = parcJSON_ToString(root_);
+ packet.setPayload(reinterpret_cast<uint8_t *>(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_);
}
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<core::Name>::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<SuffixHashList>::key);
return *this;
}
-TRANSPORT_ALWAYS_INLINE JSONManifestEncoder&
+TRANSPORT_ALWAYS_INLINE JSONManifestEncoder &
JSONManifestEncoder::setIsFinalManifestImpl(bool is_last) {
parcJSON_AddBoolean(root_, JSONKey<bool>::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);
}
}
TRANSPORT_ALWAYS_INLINE void JSONManifestDecoder::decodeImpl(
- const uint8_t* payload, std::size_t payload_size) {
- PARCBuffer* b = parcBuffer_Wrap(const_cast<uint8_t*>(payload), payload_size,
+ const uint8_t *payload, std::size_t payload_size) {
+ PARCBuffer *b = parcBuffer_Wrap(const_cast<uint8_t *>(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_);
}
TRANSPORT_ALWAYS_INLINE core::Name JSONManifestDecoder::getBaseNameImpl()
const {
checkPointer(root_);
- PARCJSONValue* value =
+ PARCJSONValue *value =
parcJSON_GetValueByName(root_, JSONKey<core::Name>::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);
TRANSPORT_ALWAYS_INLINE bool JSONManifestDecoder::getIsFinalManifestImpl() {
checkPointer(root_);
- PARCJSONValue* value =
+ PARCJSONValue *value =
parcJSON_GetValueByName(root_, JSONKey<bool>::final_manifest);
bool ret = parcJSONValue_GetBoolean(value);
template <>
struct JSONKey<HashAlgorithm> {
- static const constexpr char* key = "hash_algorithm";
+ static const constexpr char *key = "hash_algorithm";
};
template <>
struct JSONKey<ManifestType> {
- static const constexpr char* key = "manifest_type";
+ static const constexpr char *key = "manifest_type";
};
template <>
struct JSONKey<NextSegmentCalculationStrategy> {
- static const constexpr char* key = "next_segment_strategy";
+ static const constexpr char *key = "next_segment_strategy";
};
template <>
struct JSONKey<NameHashList> {
- static const constexpr char* key = "name_hash_list";
+ static const constexpr char *key = "name_hash_list";
};
template <>
struct JSONKey<SuffixHashList> {
- static const constexpr char* key = "suffix_hash_list";
+ static const constexpr char *key = "suffix_hash_list";
};
template <>
struct JSONKey<core::Name> {
- static const constexpr char* key = "base_name";
+ static const constexpr char *key = "base_name";
};
template <>
struct JSONKey<bool> {
- static const constexpr char* final_manifest = "final_manifest";
+ static const constexpr char *final_manifest = "final_manifest";
};
// template <>
~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<JSONManifestDecoder> {
~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;
bool getIsFinalManifestImpl();
private:
- PARCJSON* root_;
+ PARCJSON *root_;
};
} // namespace core
public:
ManifestInline() : ManifestBase() {}
- ManifestInline(const core::Name& name) : ManifestBase(name) {}
+ ManifestInline(const core::Name &name) : ManifestBase(name) {}
template <typename T>
- ManifestInline(T&& base) : ManifestBase(std::forward<T&&>(base)) {}
+ ManifestInline(T &&base) : ManifestBase(std::forward<T &&>(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);
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();
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(
#include <vpp/api/vpe_all_api_h.h>
#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
_(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;
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;
/* 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);
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);
}
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;
}
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
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),
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<const uint8_t *>((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.");
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");
+ }
}
}
volatile bool is_reconnection_;
bool data_available_;
bool enable_burst_;
+ bool closed_;
uint32_t memif_id_;
uint8_t memif_mode_;
std::string app_name_;
header_head_(packet_.get()),
payload_head_(nullptr),
format_(getFormatFromBuffer(packet_start_)) {
-
auto header_size = getHeaderSizeFromFormat(format_);
int signature_size = 0;
packet_->prependChain(std::move(payload));
packet_->append(header_size);
}
-
-
}
Packet::Packet(const uint8_t *buffer, std::size_t size)
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) {
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.");
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.");
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.");
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.");
}
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.");
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.");
#include <hicn/transport/portability/portability.h>
#include <hicn/transport/utils/branch_prediction.h>
#include <hicn/transport/utils/crypto_hasher.h>
-#include <hicn/transport/utils/membuf.h>
-#include <hicn/transport/utils/object_pool.h>
#include <hicn/transport/utils/crypto_suite.h>
#include <hicn/transport/utils/key_id.h>
+#include <hicn/transport/utils/membuf.h>
+#include <hicn/transport/utils/object_pool.h>
namespace utils {
class Signer;
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_;
#include <vpp/api/vpe_all_api_h.h>
#undef vl_msg_name_crc_list
-// #define vl_api_version(n,v) static u32 vpe_api_version = (v);
-// #include <vpp/api/vpe.api.h>
-// #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 <semaphore.h>
+
+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
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);
}
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);
}
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);
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);
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);
* @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
}
#include <vlibapi/api.h>
#include <vlibmemory/api.h>
-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 <stdint.h>
+
+typedef struct vpp_binary_api vpp_binary_api_t;
struct vpp_plugin_binary_api {
vpp_binary_api_t *vpp_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)); \
#include <hicn/transport/core/hicn_binary_api.h>
#include <hicn/transport/core/memif_binary_api.h>
+#include <hicn/transport/core/prefix.h>
#include <hicn/transport/core/vpp_forwarder_interface.h>
typedef enum { MASTER = 0, SLAVE = 1 } memif_role_t;
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.
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;
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.");
}
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() {
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));
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));
}
}
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});
* limitations under the License.
*/
+#include <hicn/transport/interfaces/rtc_socket_producer.h>
#include <stdlib.h>
#include <time.h>
-#include <hicn/transport/interfaces/rtc_socket_producer.h>
#define NACK_HEADER_SIZE 8 // bytes
#define TIMESTAMP_LEN 8 // bytes
transport_protocol_->stop();
}
- //is_running_ = false;
+ // is_running_ = false;
}
void ConsumerSocket::resume() {
- if(!transport_protocol_->isRunning()){
+ if (!transport_protocol_->isRunning()) {
transport_protocol_->resume();
}
}
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_;
void RTCTransportProtocol::start(
utils::SharableVector<uint8_t> &content_buffer) {
-
- if(is_running_)
- return;
+ if (is_running_) return;
is_running_ = true;
content_buffer_ = content_buffer.shared_from_this();
}
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) {
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
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;
//}
#pragma once
-#include <stdint.h>
#include <hicn/transport/utils/min_filter.h>
+#include <stdint.h>
#include <climits>
#define ALPHA_RTC 0.125
void VegasTransportProtocol::start(
utils::SharableVector<uint8_t> &content_buffer) {
-
- if(is_running_)
- return;
+ if (is_running_) return;
socket_->t0_ = std::chrono::steady_clock::now();
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;
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);
index = ++last_reassembled_segment_;
it = receive_buffer_.find(index);
- } while (it != receive_buffer_.end());
+ }
}
void VegasTransportProtocol::partialDownload() {
parcCryptoSuite_GetSigningAlgorithm(static_cast<PARCCryptoSuite>(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<int>(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<int>(key_length), validity_days);
PARCIdentityFile *identity_file =
parcIdentityFile_Create(keystore_name.c_str(), keystore_password.c_str());
* 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,
#include <assert.h>
#include <ctype.h>
+#include <hicn/transport/utils/log.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
-#include <hicn/transport/utils/log.h>
#if defined(_WIN32) || defined(_WIN64)
#include <windows.h>
#else
-#include <unistd.h>
#include <sys/time.h>
+#include <unistd.h>
#if defined(__linux__)
#include <linux/limits.h>
#else
* 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,
public:
using Ptr = std::unique_ptr<T, ObjectDeleter>;
- ObjectPool() {}
+ ObjectPool() : destructor_(false) {}
+
+ ~ObjectPool() {
+ destructor_ = true;
+ }
std::pair<bool, Ptr> get() {
if (object_pool_.empty()) {
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)); }
utils::SpinLock object_pool_lock_;
std::deque<Ptr> object_pool_;
+ bool destructor_;
};
} // namespace utils
\ No newline at end of file
#include <hicn/transport/errors/malformed_ahpacket_exception.h>
#include <hicn/transport/utils/endianess.h>
+#include <hicn/transport/utils/key_id.h>
#include <hicn/transport/utils/membuf.h>
#include <hicn/transport/utils/signer.h>
-#include <hicn/transport/utils/key_id.h>
-
extern "C" {
TRANSPORT_CLANG_DISABLE_WARNING("-Wextern-c-compat")
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_);
/* Fill the hicn_ah header */
using namespace std::chrono;
- auto now = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
+ auto now = duration_cast<milliseconds>(system_clock::now().time_since_epoch())
+ .count();
packet.setSignatureTimestamp(now);
// *reinterpret_cast<uint64_t*>(ah->signTime) = utils::hton<uint64_t>(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) {
std::unique_ptr<utils::MemBuf> signature_buffer;
std::unique_ptr<utils::MemBuf> 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);
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)) {
}
if (consumer_socket_->setSocketOption(OtherOptions::VIRTUAL_DOWNLOAD,
- false) == SOCKET_OPTION_NOT_SET) {
+ configuration_.virtual_download) == SOCKET_OPTION_NOT_SET) {
return ERROR_SETUP;
}
total = producer_socket_->produce(
name, reinterpret_cast<const uint8_t *>(content.data()), content.size(),
- !configuration_.multiphase_produce_);
+ !configuration_.multiphase_produce_, suffix);
std::cout << "Written " << total << "pieces of data in output buffer"
<< std::endl;
}
}
- Client *ping = new Client(c);
+ auto ping = std::make_unique<Client>(c);
auto t0 = std::chrono::steady_clock::now();
ping->ping();