From 229385955109b866a23c4ac2aa03d4d11044c39d Mon Sep 17 00:00:00 2001 From: "Enrico Loparco (eloparco)" Date: Thu, 24 Jun 2021 09:15:41 +0200 Subject: [HICN-708] Rebase with master Signed-off-by: Enrico Loparco (eloparco) Change-Id: I2122e1d61dd3b2e039972624ffbdbcb3c5610159 --- libtransport/src/core/manifest_inline.h | 41 +++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 7 deletions(-) (limited to 'libtransport/src/core/manifest_inline.h') diff --git a/libtransport/src/core/manifest_inline.h b/libtransport/src/core/manifest_inline.h index 0227fa93a..fcb1d214f 100644 --- a/libtransport/src/core/manifest_inline.h +++ b/libtransport/src/core/manifest_inline.h @@ -15,10 +15,10 @@ #pragma once -#include - #include #include +#include + #include namespace transport { @@ -30,8 +30,12 @@ class ManifestInline : public Manifest> { using ManifestBase = Manifest>; + + using Hash = typename FormatTraits::Hash; using HashType = typename FormatTraits::HashType; + using Suffix = typename FormatTraits::Suffix; using SuffixList = typename FormatTraits::SuffixList; + using HashEntry = std::pair>; public: ManifestInline() : ManifestBase() {} @@ -44,7 +48,7 @@ class ManifestInline static TRANSPORT_ALWAYS_INLINE ManifestInline *createManifest( const core::Name &manifest_name, ManifestVersion version, - ManifestType type, utils::CryptoHashType algorithm, bool is_last, + ManifestType type, auth::CryptoHashType algorithm, bool is_last, const Name &base_name, NextSegmentCalculationStrategy strategy, std::size_t signature_size) { auto manifest = new ManifestInline(manifest_name, signature_size); @@ -84,7 +88,7 @@ class ManifestInline const Name &getBaseName() { return base_name_; } - ManifestInline &addSuffixHash(uint32_t suffix, const HashType &hash) { + ManifestInline &addSuffixHash(Suffix suffix, const Hash &hash) { ManifestBase::encoder_.addSuffixAndHash(suffix, hash); return *this; } @@ -104,12 +108,35 @@ class ManifestInline return next_segment_strategy_; } + // Convert several manifests into a single map from suffixes to packet hashes. + // All manifests must have been decoded beforehand. + static std::unordered_map getSuffixMap( + const std::vector &manifests) { + std::unordered_map suffix_map; + + for (auto manifest_ptr : manifests) { + HashType hash_algorithm = manifest_ptr->getHashAlgorithm(); + SuffixList suffix_list = manifest_ptr->getSuffixList(); + + for (auto it = suffix_list.begin(); it != suffix_list.end(); ++it) { + std::vector hash( + it->second, it->second + auth::hash_size_map[hash_algorithm]); + suffix_map[it->first] = {hash_algorithm, hash}; + } + } + + return suffix_map; + } + static std::unordered_map getSuffixMap( + ManifestInline *manifest) { + return getSuffixMap(std::vector{manifest}); + } + private: core::Name base_name_; NextSegmentCalculationStrategy next_segment_strategy_; SuffixList suffix_hash_map_; }; -} // end namespace core - -} // end namespace transport \ No newline at end of file +} // namespace core +} // namespace transport -- cgit 1.2.3-korg