aboutsummaryrefslogtreecommitdiffstats
path: root/libtransport/src/hicn/transport/core
diff options
context:
space:
mode:
authorMauro Sardara <msardara@cisco.com>2019-02-04 11:06:18 +0100
committerAlberto Compagno <acompagn+fdio@cisco.com>2019-03-05 09:56:19 +0000
commit6d7704c1b497341fd6dd3c27e3f64d0db062ccc2 (patch)
tree668c6820653cd84da8474d330d2807a8765f96b5 /libtransport/src/hicn/transport/core
parentca66305af16e2f8d8f271218ea71f132e6c21916 (diff)
[HICN-11] Rework on transport protocols improving components modularity
Change-Id: I6683ec5b494238dc93591c103d25275e89b9f267 Signed-off-by: Mauro Sardara <msardara@cisco.com>
Diffstat (limited to 'libtransport/src/hicn/transport/core')
-rw-r--r--libtransport/src/hicn/transport/core/content_object.cc2
-rw-r--r--libtransport/src/hicn/transport/core/content_object.h4
-rw-r--r--libtransport/src/hicn/transport/core/forwarder_interface.h5
-rw-r--r--libtransport/src/hicn/transport/core/interest.cc13
-rw-r--r--libtransport/src/hicn/transport/core/interest.h4
-rw-r--r--libtransport/src/hicn/transport/core/manifest.h37
-rw-r--r--libtransport/src/hicn/transport/core/manifest_format_fixed.cc32
-rw-r--r--libtransport/src/hicn/transport/core/manifest_format_fixed.h3
-rw-r--r--libtransport/src/hicn/transport/core/manifest_format_json_jsoncpp.cc244
-rw-r--r--libtransport/src/hicn/transport/core/manifest_format_json_jsoncpp.h162
-rw-r--r--libtransport/src/hicn/transport/core/manifest_format_json_libparc_deprecated.cc298
-rw-r--r--libtransport/src/hicn/transport/core/manifest_format_json_libparc_deprecated.h152
-rw-r--r--libtransport/src/hicn/transport/core/manifest_inline.h6
-rw-r--r--libtransport/src/hicn/transport/core/packet.cc26
-rw-r--r--libtransport/src/hicn/transport/core/packet.h15
-rw-r--r--libtransport/src/hicn/transport/core/raw_socket_connector.cc2
-rw-r--r--libtransport/src/hicn/transport/core/raw_socket_connector.h2
-rw-r--r--libtransport/src/hicn/transport/core/tcp_socket_connector.cc26
-rw-r--r--libtransport/src/hicn/transport/core/tcp_socket_connector.h2
19 files changed, 85 insertions, 950 deletions
diff --git a/libtransport/src/hicn/transport/core/content_object.cc b/libtransport/src/hicn/transport/core/content_object.cc
index 4cd5623c4..c00535512 100644
--- a/libtransport/src/hicn/transport/core/content_object.cc
+++ b/libtransport/src/hicn/transport/core/content_object.cc
@@ -92,6 +92,8 @@ const Name &ContentObject::getName() const {
return name_;
}
+Name &ContentObject::getWritableName() { return const_cast<Name &>(getName()); }
+
ContentObject &ContentObject::setName(const Name &name) {
if (hicn_data_set_name(format_, (hicn_header_t *)packet_start_,
name.getStructReference()) < 0) {
diff --git a/libtransport/src/hicn/transport/core/content_object.h b/libtransport/src/hicn/transport/core/content_object.h
index c85259f20..8770e8cb4 100644
--- a/libtransport/src/hicn/transport/core/content_object.h
+++ b/libtransport/src/hicn/transport/core/content_object.h
@@ -46,7 +46,9 @@ class ContentObject : public Packet {
~ContentObject() override;
- const Name &getName() const;
+ const Name &getName() const override;
+
+ Name &getWritableName() override;
ContentObject &setName(const Name &name);
diff --git a/libtransport/src/hicn/transport/core/forwarder_interface.h b/libtransport/src/hicn/transport/core/forwarder_interface.h
index de9f3b568..b3403cf5a 100644
--- a/libtransport/src/hicn/transport/core/forwarder_interface.h
+++ b/libtransport/src/hicn/transport/core/forwarder_interface.h
@@ -18,6 +18,8 @@
#include <hicn/transport/core/prefix.h>
#include <hicn/transport/core/udp_socket_connector.h>
#include <hicn/transport/portability/portability.h>
+#include <hicn/transport/utils/chrono_typedefs.h>
+#include <hicn/transport/utils/log.h>
#include <deque>
@@ -97,6 +99,9 @@ class ForwarderInterface {
packet.setLocator(inet6_address_);
}
+ // TRANSPORT_LOGI("Sending packet %s at %lu",
+ // packet.getName().toString().c_str(),
+ // utils::SteadyClock::now().time_since_epoch().count());
packet.setChecksum();
connector_.send(packet.data());
}
diff --git a/libtransport/src/hicn/transport/core/interest.cc b/libtransport/src/hicn/transport/core/interest.cc
index 4ea0c4419..49d452d19 100644
--- a/libtransport/src/hicn/transport/core/interest.cc
+++ b/libtransport/src/hicn/transport/core/interest.cc
@@ -79,16 +79,7 @@ const Name &Interest::getName() const {
return name_;
}
-Name &Interest::getWritableName() {
- if (!name_) {
- if (hicn_interest_get_name(format_, (hicn_header_t *)packet_start_,
- (hicn_name_t *)name_.getStructReference()) < 0) {
- throw errors::MalformedPacketException();
- }
- }
-
- return name_;
-}
+Name &Interest::getWritableName() { return const_cast<Name &>(getName()); }
Interest &Interest::setName(const Name &name) {
if (hicn_interest_set_name(format_, (hicn_header_t *)packet_start_,
@@ -148,4 +139,4 @@ void Interest::resetForHash() {
} // end namespace core
-} // end namespace transport
+} // end namespace transport \ No newline at end of file
diff --git a/libtransport/src/hicn/transport/core/interest.h b/libtransport/src/hicn/transport/core/interest.h
index 75fcba8eb..95b45ac9a 100644
--- a/libtransport/src/hicn/transport/core/interest.h
+++ b/libtransport/src/hicn/transport/core/interest.h
@@ -45,9 +45,9 @@ class Interest
~Interest() override;
- const Name &getName() const;
+ const Name &getName() const override;
- Name &getWritableName();
+ Name &getWritableName() override;
Interest &setName(const Name &name);
diff --git a/libtransport/src/hicn/transport/core/manifest.h b/libtransport/src/hicn/transport/core/manifest.h
index 558a96804..9f7dc5984 100644
--- a/libtransport/src/hicn/transport/core/manifest.h
+++ b/libtransport/src/hicn/transport/core/manifest.h
@@ -38,39 +38,28 @@ class Manifest : public Base {
using Encoder = typename FormatTraits::Encoder;
using Decoder = typename FormatTraits::Decoder;
- Manifest()
- : packet_(new Base(HF_INET6_TCP_AH), nullptr),
- encoder_(*packet_),
- decoder_(*packet_) {
+ Manifest(std::size_t signature_size = 0)
+ : Base(HF_INET6_TCP_AH),
+ encoder_(*this, signature_size),
+ decoder_(*this) {
Base::setPayloadType(PayloadType::MANIFEST);
}
- 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)
- : packet_(std::move(base)), encoder_(*packet_), decoder_(*packet_) {
+ Manifest(const core::Name &name, std::size_t signature_size = 0)
+ : Base(name, HF_INET6_TCP_AH),
+ encoder_(*this, signature_size),
+ decoder_(*this) {
Base::setPayloadType(PayloadType::MANIFEST);
}
template <typename T>
Manifest(T &&base)
- : packet_(new Base(std::move<T &&>(base)), nullptr),
- encoder_(*packet_),
- decoder_(*packet_) {
+ : Base(std::forward<T &&>(base)), encoder_(*this), decoder_(*this) {
Base::setPayloadType(PayloadType::MANIFEST);
}
virtual ~Manifest() = default;
- 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(
additional_entries);
@@ -142,15 +131,7 @@ class Manifest : public Base {
return *this;
}
- void setSignatureSize(std::size_t size_bits) {
- Packet::setSignatureSize(size_bits);
- encoder_.update();
- }
-
- typename Base::Ptr &&getPacket() { return std::move(packet_); }
-
protected:
- typename Base::Ptr packet_;
ManifestType manifest_type_;
HashAlgorithm hash_algorithm_;
bool is_last_;
diff --git a/libtransport/src/hicn/transport/core/manifest_format_fixed.cc b/libtransport/src/hicn/transport/core/manifest_format_fixed.cc
index 6141ae311..73b33268c 100644
--- a/libtransport/src/hicn/transport/core/manifest_format_fixed.cc
+++ b/libtransport/src/hicn/transport/core/manifest_format_fixed.cc
@@ -15,7 +15,6 @@
#include <hicn/transport/core/manifest_format_fixed.h>
#include <hicn/transport/core/packet.h>
-#include <hicn/transport/utils/endianess.h>
#include <hicn/transport/utils/literals.h>
namespace transport {
@@ -23,26 +22,34 @@ namespace transport {
namespace core {
// TODO use preallocated pool of membufs
-FixedManifestEncoder::FixedManifestEncoder(Packet &packet)
+FixedManifestEncoder::FixedManifestEncoder(Packet &packet,
+ std::size_t signature_size)
: packet_(packet),
- max_size_(Packet::default_mtu - packet_.headerSize()),
+ max_size_(Packet::default_mtu - packet_.headerSize() - signature_size),
manifest_(
utils::MemBuf::create(Packet::default_mtu - packet_.headerSize())),
manifest_header_(
reinterpret_cast<ManifestHeader *>(manifest_->writableData())),
manifest_entries_(reinterpret_cast<ManifestEntry *>(
manifest_->writableData() + sizeof(ManifestHeader))),
- current_entry_(0) {}
+ current_entry_(0),
+ signature_size_(signature_size) {
+ *manifest_header_ = {0};
+}
FixedManifestEncoder::~FixedManifestEncoder() {}
FixedManifestEncoder &FixedManifestEncoder::encodeImpl() {
+ manifest_->append(sizeof(ManifestHeader) +
+ manifest_header_->number_of_entries *
+ sizeof(ManifestEntry));
packet_.appendPayload(std::move(manifest_));
return *this;
}
FixedManifestEncoder &FixedManifestEncoder::clearImpl() {
- manifest_ = utils::MemBuf::create(Packet::default_mtu - packet_.headerSize());
+ manifest_ = utils::MemBuf::create(Packet::default_mtu - packet_.headerSize() -
+ signature_size_);
return *this;
}
@@ -84,7 +91,7 @@ FixedManifestEncoder &FixedManifestEncoder::addSuffixAndHashImpl(
void FixedManifestEncoder::addSuffixHashBytes(uint32_t suffix,
const uint8_t *hash,
std::size_t length) {
- manifest_entries_[current_entry_].suffix = utils::hton(suffix);
+ manifest_entries_[current_entry_].suffix = htonl(suffix);
// std::copy(hash, hash + length,
// manifest_entries_[current_entry_].hash);
std::memcpy(
@@ -119,18 +126,13 @@ std::size_t FixedManifestEncoder::estimateSerializedLengthImpl(
}
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()) +
- sizeof(ManifestHeader));
+ max_size_ = Packet::default_mtu - packet_.headerSize() - signature_size_;
return *this;
}
FixedManifestEncoder &FixedManifestEncoder::setFinalBlockNumberImpl(
std::uint32_t final_block_number) {
- manifest_header_->final_block_number = utils::hton(final_block_number);
+ manifest_header_->final_block_number = htonl(final_block_number);
return *this;
}
@@ -179,7 +181,7 @@ typename Fixed::SuffixList FixedManifestDecoder::getSuffixHashListImpl() {
for (int i = 0; i < manifest_header_->number_of_entries; i++) {
hash_list.insert(hash_list.end(),
- std::make_pair(utils::ntoh(manifest_entries_[i].suffix),
+ std::make_pair(ntohl(manifest_entries_[i].suffix),
reinterpret_cast<uint8_t *>(
&manifest_entries_[i].hash[0])));
}
@@ -213,7 +215,7 @@ std::size_t FixedManifestDecoder::estimateSerializedLengthImpl(
}
uint32_t FixedManifestDecoder::getFinalBlockNumberImpl() const {
- return utils::ntoh(manifest_header_->final_block_number);
+ return ntohl(manifest_header_->final_block_number);
}
} // end namespace core
diff --git a/libtransport/src/hicn/transport/core/manifest_format_fixed.h b/libtransport/src/hicn/transport/core/manifest_format_fixed.h
index 82817ddfb..c9bc3f8e5 100644
--- a/libtransport/src/hicn/transport/core/manifest_format_fixed.h
+++ b/libtransport/src/hicn/transport/core/manifest_format_fixed.h
@@ -83,7 +83,7 @@ static const constexpr std::uint8_t manifest_version = 1;
class FixedManifestEncoder : public ManifestEncoder<FixedManifestEncoder> {
public:
- FixedManifestEncoder(Packet &packet);
+ FixedManifestEncoder(Packet &packet, std::size_t signature_size = 0);
~FixedManifestEncoder();
@@ -126,6 +126,7 @@ class FixedManifestEncoder : public ManifestEncoder<FixedManifestEncoder> {
ManifestHeader *manifest_header_;
ManifestEntry *manifest_entries_;
std::size_t current_entry_;
+ std::size_t signature_size_;
};
class FixedManifestDecoder : public ManifestDecoder<FixedManifestDecoder> {
diff --git a/libtransport/src/hicn/transport/core/manifest_format_json_jsoncpp.cc b/libtransport/src/hicn/transport/core/manifest_format_json_jsoncpp.cc
deleted file mode 100644
index 0ffca39f6..000000000
--- a/libtransport/src/hicn/transport/core/manifest_format_json_jsoncpp.cc
+++ /dev/null
@@ -1,244 +0,0 @@
-/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <hicn/transport/core/packet.h>
-#include <hicn/transport/portability/transport_portability.h>
-
-#include <array>
-
-namespace transport {
-
-namespace core {
-
-namespace {
-
-template <typename T>
-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) {
- root[JSONKey<EnumType>::key] = static_cast<uint8_t>(value);
-}
-
-template <typename EnumType>
-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() {}
-
-TRANSPORT_ALWAYS_INLINE JSONManifestEncoder &JSONManifestEncoder::encodeImpl() {
- Json::StreamWriterBuilder writer_builder;
- 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());
-
- packet_.setPayload(buffer, strbuf.size());
-
- delete fast_writer;
-
- return *this;
-}
-
-TRANSPORT_ALWAYS_INLINE JSONManifestEncoder &JSONManifestEncoder::clearImpl() {
- root_.clear();
- return *this;
-}
-
-TRANSPORT_ALWAYS_INLINE JSONManifestEncoder &
-JSONManifestEncoder::setHashAlgorithmImpl(HashAlgorithm algorithm) {
- setValueToJson(root_, algorithm);
- return *this;
-}
-
-JSONManifestEncoder &JSONManifestEncoder::setManifestTypeImpl(
- ManifestType manifest_type) {
- setValueToJson(root_, manifest_type);
- return *this;
-}
-
-JSONManifestEncoder &JSONManifestEncoder::setNextSegmentCalculationStrategyImpl(
- NextSegmentCalculationStrategy strategy) {
- setValueToJson(root_, strategy);
- return *this;
-}
-
-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 &
-JSONManifestEncoder::addSuffixAndHashImpl(uint32_t suffix,
- const utils::CryptoHash &hash) {
- throw errors::NotImplementedException();
- // Json::Value value(Json::arrayValue);
- // value.append(Json::Value(suffix));
- // value.append(Json::Value(Json::Value::UInt64 (hash)));
- // root_[JSONKey<SuffixHashList>::key].append(value);
-
- return *this;
-}
-
-TRANSPORT_ALWAYS_INLINE JSONManifestEncoder &
-JSONManifestEncoder::setIsFinalManifestImpl(bool is_last) {
- root_[JSONKey<bool>::final_manifest] = is_last;
- return *this;
-}
-
-TRANSPORT_ALWAYS_INLINE JSONManifestEncoder &
-JSONManifestEncoder::setVersionImpl(ManifestVersion version) {
- setValueToJson(root_, version);
- return *this;
-}
-
-TRANSPORT_ALWAYS_INLINE JSONManifestEncoder &
-JSONManifestEncoder::setSuffixHashListImpl(
- const typename JSON::SuffixList &name_hash_list) {
- throw errors::NotImplementedException();
- // for (auto &suffix : name_hash_list) {
- // addSuffixAndHashImpl(suffix.first, suffix.second);
- // }
- //
- // return *this;
-}
-
-TRANSPORT_ALWAYS_INLINE std::size_t
-JSONManifestEncoder::estimateSerializedLengthImpl(
- std::size_t number_of_entries) {
- Json::StreamWriterBuilder writer_builder;
- Json::StreamWriter *fast_writer = writer_builder.newStreamWriter();
-
- asio::streambuf strbuf;
- strbuf.prepare(1500);
- std::ostream stream(&strbuf);
- fast_writer->write(root_, &stream);
-
- return strbuf.size();
-}
-
-TRANSPORT_ALWAYS_INLINE JSONManifestEncoder &JSONManifestEncoder::updateImpl() {
- throw errors::NotImplementedException();
-}
-
-TRANSPORT_ALWAYS_INLINE JSONManifestEncoder &
-JSONManifestEncoder::setFinalBlockNumberImpl(std::uint32_t final_block_number) {
- throw errors::NotImplementedException();
-}
-
-TRANSPORT_ALWAYS_INLINE std::size_t
-JSONManifestEncoder::getManifestHeaderSizeImpl() {
- return 0;
-}
-
-JSONManifestDecoder::JSONManifestDecoder(Packet &packet) : packet_(packet) {}
-
-JSONManifestDecoder::~JSONManifestDecoder() {}
-
-TRANSPORT_ALWAYS_INLINE void JSONManifestDecoder::decodeImpl() {
- auto array = packet_.getPayload();
- auto payload = array.data();
- auto payload_size = array.length();
-
- Json::CharReaderBuilder reader_builder;
- Json::CharReader *reader = reader_builder.newCharReader();
- std::string errors;
-
- if (!reader->parse((char *)payload, (char *)payload + payload_size, &root_,
- &errors)) {
- TRANSPORT_LOGE("Error parsing manifest!");
- TRANSPORT_LOGE("%s", errors.c_str());
-
- delete reader;
-
- throw errors::MalformedPacketException();
- }
-
- delete reader;
-}
-
-TRANSPORT_ALWAYS_INLINE JSONManifestDecoder &JSONManifestDecoder::clearImpl() {
- root_.clear();
- return *this;
-}
-
-TRANSPORT_ALWAYS_INLINE ManifestType
-JSONManifestDecoder::getManifestTypeImpl() const {
- return getValueFromJson<ManifestType>(root_);
-}
-
-TRANSPORT_ALWAYS_INLINE HashAlgorithm
-JSONManifestDecoder::getHashAlgorithmImpl() const {
- return getValueFromJson<HashAlgorithm>(root_);
-}
-
-TRANSPORT_ALWAYS_INLINE NextSegmentCalculationStrategy
-JSONManifestDecoder::getNextSegmentCalculationStrategyImpl() const {
- return getValueFromJson<NextSegmentCalculationStrategy>(root_);
-}
-
-TRANSPORT_ALWAYS_INLINE typename JSON::SuffixList
-JSONManifestDecoder::getSuffixHashListImpl() {
- throw errors::NotImplementedException();
- // SuffixHashList hash_list;
- //
- // Json::Value &array = root_[JSONKey<SuffixHashList>::key];
- //
- // for (Json::Value::ArrayIndex i = 0;
- // i != array.size();
- // i++) {
- // hash_list[array[i][0].asUInt()] = array[i][1].asUInt64();
- // }
- //
- // return hash_list;
-}
-
-TRANSPORT_ALWAYS_INLINE core::Name JSONManifestDecoder::getBaseNameImpl()
- const {
- return core::Name(root_[JSONKey<core::Name>::key].asCString());
-}
-
-TRANSPORT_ALWAYS_INLINE bool JSONManifestDecoder::getIsFinalManifestImpl()
- const {
- return root_[JSONKey<bool>::final_manifest].asBool();
-}
-
-TRANSPORT_ALWAYS_INLINE ManifestVersion
-JSONManifestDecoder::getVersionImpl() const {
- return getValueFromJson<ManifestVersion>(root_);
-}
-
-TRANSPORT_ALWAYS_INLINE uint32_t
-JSONManifestDecoder::getFinalBlockNumberImpl() const {
- return 0;
-}
-
-} // end namespace core
-
-} // end namespace transport
diff --git a/libtransport/src/hicn/transport/core/manifest_format_json_jsoncpp.h b/libtransport/src/hicn/transport/core/manifest_format_json_jsoncpp.h
deleted file mode 100644
index 84d2ba29a..000000000
--- a/libtransport/src/hicn/transport/core/manifest_format_json_jsoncpp.h
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <hicn/transport/core/manifest_format.h>
-#include <hicn/transport/core/name.h>
-
-#if defined(__APPLE__) || defined(__ANDROID__)
-#include <json/json.h>
-#else
-#include <jsoncpp/json/json.h>
-#endif /* __APPLE__ || __ANDROID__*/
-
-#include <string>
-
-namespace transport {
-
-namespace core {
-
-class JSONManifestEncoder;
-class JSONManifestDecoder;
-class Packet;
-
-struct JSON {
- using Encoder = JSONManifestEncoder;
- using Decoder = JSONManifestDecoder;
- using HashType = utils::CryptoHash;
- using SuffixList = std::unordered_map<std::uint32_t, std::uint8_t *>;
-};
-
-template <typename T>
-struct JSONKey;
-
-template <>
-struct JSONKey<ManifestVersion> {
- static const constexpr char *key = "manifest_version";
-};
-
-template <>
-struct JSONKey<HashAlgorithm> {
- static const constexpr char *key = "hash_algorithm";
-};
-
-template <>
-struct JSONKey<ManifestType> {
- static const constexpr char *key = "manifest_type";
-};
-
-template <>
-struct JSONKey<NextSegmentCalculationStrategy> {
- static const constexpr char *key = "next_segment_strategy";
-};
-
-template <>
-struct JSONKey<typename JSON::SuffixList> {
- static const constexpr char *key = "suffix_hash_list";
-};
-
-template <>
-struct JSONKey<core::Name> {
- static const constexpr char *key = "base_name";
-};
-
-template <>
-struct JSONKey<bool> {
- static const constexpr char *final_manifest = "final_manifest";
-};
-
-class JSONManifestEncoder : public ManifestEncoder<JSONManifestEncoder> {
- public:
- JSONManifestEncoder(Packet &packet);
-
- ~JSONManifestEncoder() override;
-
- JSONManifestEncoder &encodeImpl();
-
- JSONManifestEncoder &clearImpl();
-
- JSONManifestEncoder &setManifestTypeImpl(ManifestType manifest_type);
-
- JSONManifestEncoder &setHashAlgorithmImpl(HashAlgorithm algorithm);
-
- JSONManifestEncoder &setNextSegmentCalculationStrategyImpl(
- NextSegmentCalculationStrategy strategy);
-
- JSONManifestEncoder &setSuffixHashListImpl(
- const typename JSON::SuffixList &name_hash_list);
-
- JSONManifestEncoder &setBaseNameImpl(const core::Name &base_name);
-
- JSONManifestEncoder &addSuffixAndHashImpl(uint32_t suffix,
- const utils::CryptoHash &hash);
-
- JSONManifestEncoder &setIsFinalManifestImpl(bool is_last);
-
- JSONManifestEncoder &setVersionImpl(ManifestVersion version);
-
- std::size_t estimateSerializedLengthImpl(std::size_t number_of_entries);
-
- JSONManifestEncoder &updateImpl();
-
- JSONManifestEncoder &setFinalBlockNumberImpl(
- std::uint32_t final_block_number);
-
- static std::size_t getManifestHeaderSizeImpl();
-
- private:
- Packet &packet_;
- Json::Value root_;
-};
-
-class JSONManifestDecoder : public ManifestDecoder<JSONManifestDecoder> {
- public:
- JSONManifestDecoder(Packet &packet);
-
- ~JSONManifestDecoder() override;
-
- void decodeImpl();
-
- JSONManifestDecoder &clearImpl();
-
- ManifestType getManifestTypeImpl() const;
-
- HashAlgorithm getHashAlgorithmImpl() const;
-
- uint32_t getFinalChunkImpl() const;
-
- NextSegmentCalculationStrategy getNextSegmentCalculationStrategyImpl() const;
-
- typename JSON::SuffixList getSuffixHashListImpl();
-
- core::Name getBaseNameImpl() const;
-
- bool getIsFinalManifestImpl() const;
-
- std::size_t estimateSerializedLengthImpl(std::size_t number_of_entries) const;
-
- ManifestVersion getVersionImpl() const;
-
- uint32_t getFinalBlockNumberImpl() const;
-
- private:
- Packet &packet_;
- Json::Value root_;
-};
-
-} // namespace core
-
-} // namespace transport \ No newline at end of file
diff --git a/libtransport/src/hicn/transport/core/manifest_format_json_libparc_deprecated.cc b/libtransport/src/hicn/transport/core/manifest_format_json_libparc_deprecated.cc
deleted file mode 100644
index a3a47e62b..000000000
--- a/libtransport/src/hicn/transport/core/manifest_format_json_libparc_deprecated.cc
+++ /dev/null
@@ -1,298 +0,0 @@
-/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <hicn/transport/core/manifest_format_json_libparc_deprecated.h>
-#include <hicn/transport/core/packet.h>
-#include <hicn/transport/errors/errors.h>
-#include <hicn/transport/portability/transport_portability.h>
-
-extern "C" {
-#include <parc/algol/parc_Memory.h>
-}
-
-namespace transport {
-
-namespace core {
-
-namespace {
-
-template <typename T>
-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) {
- parcJSON_AddInteger(root, JSONKey<EnumType>::key,
- static_cast<int64_t>(value));
-}
-
-template <typename EnumType>
-TRANSPORT_ALWAYS_INLINE EnumType getValueFromJson(PARCJSON *root) {
- checkPointer(root);
-
- PARCJSONValue *value = parcJSON_GetValueByName(root, JSONKey<EnumType>::key);
-
- EnumType ret = static_cast<EnumType>(parcJSONValue_GetInteger(value));
- // parcJSONValue_Release(&value);
-
- return ret;
-};
-
-} // namespace
-
-JSONManifestEncoder::JSONManifestEncoder() : root_(parcJSON_Create()) {
- parcJSON_Acquire(root_);
-}
-
-JSONManifestEncoder::~JSONManifestEncoder() {
- if (root_) {
- parcJSON_Release(&root_);
- }
-}
-
-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() {
- if (root_) {
- parcJSON_Release(&root_);
- }
-
- root_ = parcJSON_Create();
-
- return *this;
-}
-
-TRANSPORT_ALWAYS_INLINE JSONManifestEncoder &
-JSONManifestEncoder::setHashAlgorithmImpl(HashAlgorithm algorithm) {
- setValueToJson(root_, algorithm);
- return *this;
-}
-
-TRANSPORT_ALWAYS_INLINE JSONManifestEncoder &
-JSONManifestEncoder::setManifestTypeImpl(ManifestType manifest_type) {
- setValueToJson(root_, manifest_type);
- return *this;
-}
-
-TRANSPORT_ALWAYS_INLINE JSONManifestEncoder &
-JSONManifestEncoder::setNextSegmentCalculationStrategyImpl(
- NextSegmentCalculationStrategy strategy) {
- setValueToJson(root_, strategy);
- return *this;
-}
-
-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 &
-JSONManifestEncoder::addSuffixAndHashImpl(uint32_t suffix,
- utils::CryptoHash &hash) {
- throw errors::NotImplementedException();
- // PARCJSONValue *value = parcJSON_GetValueByName(root_,
- // JSONKey<SuffixHashList>::key);
- //
- // // Create the pair to store in the array.
- // // It will be segment number + Hash of the segment
- // PARCJSONArray * pair = parcJSONArray_Create();
- //
- // PARCJSONValue *v = parcJSONValue_CreateFromInteger(suffix);
- // parcJSONArray_AddValue(pair, v);
- // parcJSONValue_Release(&v);
- //
- // v = parcJSONValue_CreateFromInteger(hash);
- // parcJSONArray_AddValue(pair, v);
- // parcJSONValue_Release(&v);
- //
- // if (value == nullptr /* || !parcJSONValue_IsArray(value) */) {
- // // Create the array
- // PARCJSONArray *array = parcJSONArray_Create();
- // parcJSON_AddArray(root_,
- // JSONKey<SuffixHashList>::key,
- // array);
- // parcJSONArray_Release(&array);
- //
- // value = parcJSON_GetValueByName(root_, JSONKey<SuffixHashList>::key);
- // }
- //
- // v = parcJSONValue_CreateFromJSONArray(pair);
- // parcJSONArray_AddValue(parcJSONValue_GetArray(value), v);
- // parcJSONValue_Release(&v);
- //
- // parcJSONArray_Release(&pair);
- // // parcJSONValue_Release(&value);
-
- return *this;
-}
-
-TRANSPORT_ALWAYS_INLINE JSONManifestEncoder &
-JSONManifestEncoder::setIsFinalManifestImpl(bool is_last) {
- parcJSON_AddBoolean(root_, JSONKey<bool>::final_manifest, is_last);
-
- return *this;
-}
-
-TRANSPORT_ALWAYS_INLINE JSONManifestEncoder &
-JSONManifestEncoder::setSuffixHashListImpl(
- const SuffixHashList &name_hash_list) {
- for (auto &suffix : name_hash_list) {
- addSuffixAndHashImpl(suffix.first, suffix.second);
- }
-
- return *this;
-}
-
-TRANSPORT_ALWAYS_INLINE JSONManifestDecoder::JSONManifestDecoder()
- : root_(nullptr) {}
-
-TRANSPORT_ALWAYS_INLINE JSONManifestDecoder::~JSONManifestDecoder() {
- if (root_) {
- parcJSON_Release(&root_);
- }
-}
-
-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,
- 0, payload_size);
- clearImpl();
-
- root_ = parcJSON_ParseBuffer(b);
- parcBuffer_Release(&b);
-
- char *str = parcJSON_ToString(root_);
-}
-
-TRANSPORT_ALWAYS_INLINE JSONManifestDecoder &JSONManifestDecoder::clearImpl() {
- if (root_) {
- parcJSON_Release(&root_);
- }
-
- return *this;
-}
-
-TRANSPORT_ALWAYS_INLINE ManifestType
-JSONManifestDecoder::getManifestTypeImpl() const {
- return getValueFromJson<ManifestType>(root_);
-}
-
-TRANSPORT_ALWAYS_INLINE HashAlgorithm
-JSONManifestDecoder::getHashAlgorithmImpl() const {
- return getValueFromJson<HashAlgorithm>(root_);
-}
-
-TRANSPORT_ALWAYS_INLINE NextSegmentCalculationStrategy
-JSONManifestDecoder::getNextSegmentCalculationStrategyImpl() const {
- return getValueFromJson<NextSegmentCalculationStrategy>(root_);
-}
-
-TRANSPORT_ALWAYS_INLINE SuffixHashList
-JSONManifestDecoder::getSuffixHashListImpl() {
- throw errors::NotImplementedException();
- // SuffixHashList hash_list;
- //
- // char * str = parcJSON_ToString(root_);
- //
- // PARCJSONValue *value = parcJSON_GetValueByName(root_,
- // JSONKey<SuffixHashList>::key);
- //
- // if (value == nullptr || !parcJSONValue_IsArray(value)) {
- // throw errors::RuntimeException("Manifest does not contain suffix-hash
- // list");
- // }
- //
- // PARCJSONArray *array = parcJSONValue_GetArray(value);
- // std::size_t array_size = parcJSONArray_GetLength(array);
- //
- // for (std::size_t i = 0; i < array_size; i++) {
- // PARCJSONValue *v = parcJSONArray_GetValue(array, i);
- // checkPointer(v);
- // PARCJSONArray *a = parcJSONValue_GetArray(v);
- // PARCJSONValue *_suffix = parcJSONArray_GetValue(a, 0);
- // PARCJSONValue *_hash = parcJSONArray_GetValue(a, 1);
- //
- // uint32_t value1 =
- // static_cast<uint32_t>(parcJSONValue_GetInteger(_suffix)); uint64_t
- // value2 = static_cast<uint64_t>(parcJSONValue_GetInteger(_hash));
- //
- // hash_list[static_cast<uint32_t>(parcJSONValue_GetInteger(_suffix))] =
- // static_cast<uint64_t>(parcJSONValue_GetInteger(_hash));
- //
- //// parcJSONValue_Release(&_hash);
- //// parcJSONValue_Release(&_suffix);
- //// parcJSONArray_Release(&a);
- //// parcJSONValue_Release(&v);
- // }
- //
- //// parcJSONArray_Release(&array);
- //// parcJSONValue_Release(&value);
- //
- // char * str2 = parcJSON_ToString(root_);
- //
- // return hash_list;
-}
-
-TRANSPORT_ALWAYS_INLINE core::Name JSONManifestDecoder::getBaseNameImpl()
- const {
- checkPointer(root_);
- PARCJSONValue *value =
- parcJSON_GetValueByName(root_, JSONKey<core::Name>::key);
-
- PARCBuffer *b = parcJSONValue_GetString(value);
- char *string = parcBuffer_ToString(b);
-
- core::Name ret(string);
-
- // parcJSONValue_Release(&value);
- parcMemory_Deallocate(&string);
-
- return ret;
-}
-
-TRANSPORT_ALWAYS_INLINE bool JSONManifestDecoder::getIsFinalManifestImpl() {
- checkPointer(root_);
- PARCJSONValue *value =
- parcJSON_GetValueByName(root_, JSONKey<bool>::final_manifest);
-
- bool ret = parcJSONValue_GetBoolean(value);
-
- // parcJSONValue_Release(&value);
-
- return ret;
-}
-
-TRANSPORT_ALWAYS_INLINE std::size_t
-JSONManifestDecoder::estimateSerializedLengthImpl(
- std::size_t number_of_entries) {
- return 0;
-}
-
-} // end namespace core
-
-} // end namespace transport \ No newline at end of file
diff --git a/libtransport/src/hicn/transport/core/manifest_format_json_libparc_deprecated.h b/libtransport/src/hicn/transport/core/manifest_format_json_libparc_deprecated.h
deleted file mode 100644
index c89f4af7b..000000000
--- a/libtransport/src/hicn/transport/core/manifest_format_json_libparc_deprecated.h
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <hicn/transport/core/manifest_format.h>
-#include <hicn/transport/core/name.h>
-
-extern "C" {
-#include <parc/algol/parc_JSON.h>
-}
-
-#include <string>
-
-namespace transport {
-
-namespace core {
-
-class JSONManifestEncoder;
-class JSONManifestDecoder;
-class Packet;
-
-struct JSON {
- using Encoder = JSONManifestEncoder;
- using Decoder = JSONManifestDecoder;
-};
-
-template <typename T>
-struct JSONKey;
-
-template <>
-struct JSONKey<HashAlgorithm> {
- static const constexpr char *key = "hash_algorithm";
-};
-
-template <>
-struct JSONKey<ManifestType> {
- static const constexpr char *key = "manifest_type";
-};
-
-template <>
-struct JSONKey<NextSegmentCalculationStrategy> {
- static const constexpr char *key = "next_segment_strategy";
-};
-
-template <>
-struct JSONKey<NameHashList> {
- static const constexpr char *key = "name_hash_list";
-};
-
-template <>
-struct JSONKey<SuffixHashList> {
- static const constexpr char *key = "suffix_hash_list";
-};
-
-template <>
-struct JSONKey<core::Name> {
- static const constexpr char *key = "base_name";
-};
-
-template <>
-struct JSONKey<bool> {
- static const constexpr char *final_manifest = "final_manifest";
-};
-
-// template <>
-// struct JSONKey<base_name> {
-// static const std::string key = "name_hash_list";
-//};
-
-// namespace JSONManifestEncoding {
-// static const std::string base_name = "base_name";
-// static const std::string final_chunk_number = "final_chunk_number";
-// static const std::string hash_algorithm = "hash_algorithm";
-// static const std::string manifest_type = "manifest_type";
-// static const std::string name_hash_list = "name_hash_list";
-// static const std::string next_segment_strategy = "next_segment_strategy";
-//}
-
-class JSONManifestEncoder : public ManifestEncoder<JSONManifestEncoder> {
- public:
- JSONManifestEncoder();
-
- ~JSONManifestEncoder();
-
- JSONManifestEncoder &encodeImpl(Packet &packet);
-
- JSONManifestEncoder &clearImpl();
-
- JSONManifestEncoder &setManifestTypeImpl(ManifestType manifest_type);
-
- JSONManifestEncoder &setHashAlgorithmImpl(HashAlgorithm algorithm);
-
- JSONManifestEncoder &setNextSegmentCalculationStrategyImpl(
- NextSegmentCalculationStrategy strategy);
-
- JSONManifestEncoder &setSuffixHashListImpl(
- const SuffixHashList &name_hash_list);
-
- JSONManifestEncoder &setBaseNameImpl(const core::Name &base_name);
-
- JSONManifestEncoder &addSuffixAndHashImpl(uint32_t suffix, uint64_t hash);
-
- JSONManifestEncoder &setIsFinalManifestImpl(bool is_last);
-
- private:
- PARCJSON *root_;
-};
-
-class JSONManifestDecoder : public ManifestDecoder<JSONManifestDecoder> {
- public:
- JSONManifestDecoder();
-
- ~JSONManifestDecoder();
-
- void decodeImpl(const uint8_t *payload, std::size_t payload_size);
-
- JSONManifestDecoder &clearImpl();
-
- ManifestType getManifestTypeImpl() const;
-
- HashAlgorithm getHashAlgorithmImpl() const;
-
- uint32_t getFinalChunkImpl() const;
-
- NextSegmentCalculationStrategy getNextSegmentCalculationStrategyImpl() const;
-
- SuffixHashList getSuffixHashListImpl();
-
- core::Name getBaseNameImpl() const;
-
- bool getIsFinalManifestImpl();
-
- private:
- PARCJSON *root_;
-};
-
-} // namespace core
-
-} // namespace transport \ No newline at end of file
diff --git a/libtransport/src/hicn/transport/core/manifest_inline.h b/libtransport/src/hicn/transport/core/manifest_inline.h
index 1f2c4edb4..60eb08433 100644
--- a/libtransport/src/hicn/transport/core/manifest_inline.h
+++ b/libtransport/src/hicn/transport/core/manifest_inline.h
@@ -37,7 +37,8 @@ class ManifestInline
public:
ManifestInline() : ManifestBase() {}
- ManifestInline(const core::Name &name) : ManifestBase(name) {}
+ ManifestInline(const core::Name &name, std::size_t signature_size = 0)
+ : ManifestBase(name, signature_size) {}
template <typename T>
ManifestInline(T &&base) : ManifestBase(std::forward<T &&>(base)) {}
@@ -47,8 +48,7 @@ class ManifestInline
ManifestType type, HashAlgorithm algorithm, bool is_last,
const Name &base_name, NextSegmentCalculationStrategy strategy,
std::size_t signature_size) {
- auto manifest = new ManifestInline(manifest_name);
- manifest->setSignatureSize(signature_size);
+ auto manifest = new ManifestInline(manifest_name, signature_size);
manifest->setVersion(version);
manifest->setManifestType(type);
manifest->setHashAlgorithm(algorithm);
diff --git a/libtransport/src/hicn/transport/core/packet.cc b/libtransport/src/hicn/transport/core/packet.cc
index b3e5526ab..ec99bb3f7 100644
--- a/libtransport/src/hicn/transport/core/packet.cc
+++ b/libtransport/src/hicn/transport/core/packet.cc
@@ -80,7 +80,7 @@ Packet::Packet(const uint8_t *buffer, std::size_t size)
Packet::Packet(Packet &&other)
: packet_(std::move(other.packet_)),
- packet_start_(packet_->writableData()),
+ packet_start_(other.packet_start_),
header_head_(other.header_head_),
payload_head_(other.payload_head_),
format_(other.format_) {
@@ -269,7 +269,7 @@ void Packet::dump() const {
std::cout << std::endl << "PAYLOAD -- Length: " << payloadSize() << std::endl;
for (utils::MemBuf *current = payload_head_;
current && current != header_head_; current = current->next()) {
- std::cout << "First MemBuf Length: " << current->length() << std::endl;
+ std::cout << "MemBuf Length: " << current->length() << std::endl;
hicn_packet_dump((uint8_t *)current->data(), current->length());
}
}
@@ -310,17 +310,6 @@ std::size_t Packet::getSignatureSize() const {
return size_bytes;
}
-void Packet::setSignature(std::unique_ptr<utils::MemBuf> &&signature) {
- // Check if packet already contains a signature
- auto header = header_head_->next();
- while (header != payload_head_) {
- header->unlink();
- header = header->next();
- }
-
- appendHeader(std::move(signature));
-}
-
void Packet::setSignatureTimestamp(const uint64_t &timestamp) {
int ret = hicn_packet_set_signature_timestamp(
format_, (hicn_header_t *)packet_start_, timestamp);
@@ -397,12 +386,11 @@ utils::CryptoHash Packet::computeDigest(HashAlgorithm algorithm) const {
const_cast<Packet *>(this)->resetForHash();
- std::size_t payload_len = getPayloadSizeFromBuffer(format_, packet_start_);
- std::size_t header_length = getHeaderSizeFromFormat(format_);
- std::size_t signature_size = _is_ah(format_) ? getSignatureSize() : 0;
-
- hasher.updateBytes(packet_start_,
- payload_len + header_length + signature_size);
+ auto current = header_head_;
+ do {
+ hasher.updateBytes(current->data(), current->length());
+ current = current->next();
+ } while (current != header_head_);
hicn_packet_copy_header(format_, &header_copy, (hicn_header_t *)packet_start_,
false);
diff --git a/libtransport/src/hicn/transport/core/packet.h b/libtransport/src/hicn/transport/core/packet.h
index 49a558333..add830c1e 100644
--- a/libtransport/src/hicn/transport/core/packet.h
+++ b/libtransport/src/hicn/transport/core/packet.h
@@ -103,6 +103,10 @@ class Packet : public std::enable_shared_from_this<Packet> {
virtual void setLifetime(uint32_t lifetime);
+ virtual const Name &getName() const = 0;
+
+ virtual Name &getWritableName() = 0;
+
virtual uint32_t getLifetime() const;
Packet &appendPayload(const uint8_t *buffer, std::size_t length);
@@ -129,12 +133,6 @@ class Packet : public std::enable_shared_from_this<Packet> {
virtual ip_address_t getLocator() const = 0;
- void setSignatureSize(std::size_t size_bytes);
-
- std::size_t getSignatureSize() const;
-
- uint8_t *getSignature() const;
-
void setSignatureTimestamp(const uint64_t &timestamp);
uint64_t getSignatureTimestamp() const;
@@ -147,8 +145,6 @@ class Packet : public std::enable_shared_from_this<Packet> {
utils::KeyId getKeyId() const;
- void setSignature(std::unique_ptr<utils::MemBuf> &&signature);
-
virtual utils::CryptoHash computeDigest(HashAlgorithm algorithm) const;
void setChecksum();
@@ -180,6 +176,9 @@ class Packet : public std::enable_shared_from_this<Packet> {
private:
virtual void resetForHash() = 0;
+ void setSignatureSize(std::size_t size_bytes);
+ std::size_t getSignatureSize() const;
+ uint8_t *getSignature() const;
protected:
Name name_;
diff --git a/libtransport/src/hicn/transport/core/raw_socket_connector.cc b/libtransport/src/hicn/transport/core/raw_socket_connector.cc
index fe16d2132..78241b2ea 100644
--- a/libtransport/src/hicn/transport/core/raw_socket_connector.cc
+++ b/libtransport/src/hicn/transport/core/raw_socket_connector.cc
@@ -181,7 +181,7 @@ void RawSocketConnector::doSendPacket() {
}
void RawSocketConnector::doRecvPacket() {
- read_msg_ = std::move(getPacket());
+ read_msg_ = getPacket();
socket_.async_receive(
asio::buffer(read_msg_->writableData(), packet_size),
[this](std::error_code ec, std::size_t bytes_transferred) mutable {
diff --git a/libtransport/src/hicn/transport/core/raw_socket_connector.h b/libtransport/src/hicn/transport/core/raw_socket_connector.h
index a54b55e7e..57a2bc067 100644
--- a/libtransport/src/hicn/transport/core/raw_socket_connector.h
+++ b/libtransport/src/hicn/transport/core/raw_socket_connector.h
@@ -19,11 +19,11 @@
#include <hicn/transport/core/connector.h>
#include <hicn/transport/core/name.h>
-#include <asio/steady_timer.hpp>
#include <linux/if_packet.h>
#include <net/ethernet.h>
#include <sys/socket.h>
#include <asio.hpp>
+#include <asio/steady_timer.hpp>
#include <deque>
namespace transport {
diff --git a/libtransport/src/hicn/transport/core/tcp_socket_connector.cc b/libtransport/src/hicn/transport/core/tcp_socket_connector.cc
index ade0f2611..4c5f90db3 100644
--- a/libtransport/src/hicn/transport/core/tcp_socket_connector.cc
+++ b/libtransport/src/hicn/transport/core/tcp_socket_connector.cc
@@ -111,8 +111,25 @@ void TcpSocketConnector::close() {
}
void TcpSocketConnector::doWrite() {
- // TODO improve this piece of code for sending many buffers togethers
- // if list contains more than one packet
+#if 1
+ auto array = std::vector<asio::const_buffer>();
+ std::vector<Packet::MemBufPtr> packet_store(packet_store_size);
+ uint8_t i = 0;
+
+ utils::MemBuf *packet = nullptr;
+ const utils::MemBuf *current = nullptr;
+ // Send vectors of 32 packets
+ while (!output_buffer_.empty() && i++ < packet_store_size) {
+ packet_store[i] = output_buffer_.front();
+ output_buffer_.pop_front();
+ packet = packet_store[i].get();
+ current = packet;
+ do {
+ array.push_back(asio::const_buffer(current->data(), current->length()));
+ current = current->next();
+ } while (current != packet);
+ }
+#else
auto packet = output_buffer_.front().get();
auto array = std::vector<asio::const_buffer>();
@@ -121,12 +138,13 @@ void TcpSocketConnector::doWrite() {
array.push_back(asio::const_buffer(current->data(), current->length()));
current = current->next();
} while (current != packet);
+#endif
asio::async_write(
socket_, std::move(array),
- [this /*, packet*/](std::error_code ec, std::size_t length) {
+ [this, packet_store = std::move(packet_store)](std::error_code ec,
+ std::size_t length) {
if (TRANSPORT_EXPECT_TRUE(!ec)) {
- output_buffer_.pop_front();
if (!output_buffer_.empty()) {
doWrite();
}
diff --git a/libtransport/src/hicn/transport/core/tcp_socket_connector.h b/libtransport/src/hicn/transport/core/tcp_socket_connector.h
index ca9d2b663..465eeb912 100644
--- a/libtransport/src/hicn/transport/core/tcp_socket_connector.h
+++ b/libtransport/src/hicn/transport/core/tcp_socket_connector.h
@@ -30,6 +30,8 @@ namespace core {
using asio::ip::tcp;
class TcpSocketConnector : public Connector {
+ static constexpr uint16_t packet_store_size = 32;
+
public:
TcpSocketConnector(PacketReceivedCallback &&receive_callback,
OnReconnect &&reconnect_callback,