Hybrid ICN (hICN) plugin  v21.06-rc0-4-g18fa668
manifest_incremental_indexer_bytestream.h
1 /*
2  * Copyright (c) 2017-2019 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #pragma once
17 
18 #include <hicn/transport/auth/common.h>
19 #include <implementation/socket.h>
20 #include <protocols/incremental_indexer_bytestream.h>
21 #include <utils/suffix_strategy.h>
22 
23 #include <list>
24 
25 namespace transport {
26 namespace protocol {
27 
29  static constexpr double alpha = 0.3;
30 
31  public:
32  using SuffixQueue = std::queue<uint32_t>;
33  using InterestContentPair =
34  std::tuple<core::Interest::Ptr, core::ContentObject::Ptr, bool>;
35 
38 
40  : IncrementalIndexer(std::move(indexer)),
41  suffix_strategy_(utils::SuffixStrategyFactory::getSuffixStrategy(
42  core::NextSegmentCalculationStrategy::INCREMENTAL,
43  next_download_suffix_, 0)) {
44  for (uint32_t i = first_suffix_; i < next_download_suffix_; i++) {
45  suffix_queue_.push(i);
46  }
47  }
48 
49  virtual ~ManifestIncrementalIndexer() = default;
50 
51  void reset() override;
52 
53  void onContentObject(core::Interest &interest,
54  core::ContentObject &content_object,
55  bool reassembly) override;
56 
57  uint32_t checkNextSuffix() override;
58 
59  uint32_t getNextSuffix() override;
60 
61  uint32_t getNextReassemblySegment() override;
62 
63  bool isFinalSuffixDiscovered() override;
64 
65  uint32_t getFinalSuffix() override;
66 
67  protected:
68  std::unique_ptr<utils::SuffixStrategy> suffix_strategy_;
69  SuffixQueue suffix_queue_;
70 
71  // Hash verification
72  auth::Verifier::SuffixMap suffix_map_;
73  std::unordered_map<auth::Suffix, InterestContentPair> unverified_segments_;
74 
75  private:
76  void onUntrustedManifest(core::Interest &interest,
77  core::ContentObject &content_object,
78  bool reassembly);
79  void processTrustedManifest(core::Interest &interest,
80  std::unique_ptr<ContentObjectManifest> manifest,
81  bool reassembly);
82  void onUntrustedContentObject(core::Interest &interest,
83  core::ContentObject &content_object,
84  bool reassembly);
85  void applyPolicy(core::Interest &interest,
86  core::ContentObject &content_object, bool reassembly,
87  auth::VerificationPolicy policy);
88 };
89 
90 } // end namespace protocol
91 
92 } // end namespace transport
transport::protocol::ManifestIncrementalIndexer::isFinalSuffixDiscovered
bool isFinalSuffixDiscovered() override
transport::interface::ConsumerSocket
Main interface for consumer applications.
Definition: socket_consumer.h:48
transport::protocol::ManifestIncrementalIndexer::onContentObject
void onContentObject(core::Interest &interest, core::ContentObject &content_object, bool reassembly) override
transport::protocol::ManifestIncrementalIndexer::reset
void reset() override
transport::protocol::IncrementalIndexer
Definition: incremental_indexer_bytestream.h:38
transport::protocol::ManifestIncrementalIndexer::getNextReassemblySegment
uint32_t getNextReassemblySegment() override
transport::core::ContentObject
Definition: content_object.h:29
transport::protocol::ManifestIncrementalIndexer::checkNextSuffix
uint32_t checkNextSuffix() override
transport::core::Interest
Definition: interest.h:30
transport
Definition: forwarder_config.h:32
transport::protocol::TransportProtocol
Definition: transport_protocol.h:41
transport::protocol::ManifestIncrementalIndexer
Definition: manifest_incremental_indexer_bytestream.h:28