Hybrid ICN (hICN) plugin  v21.06-rc0-4-g18fa668
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/errors/errors.h>
19 #include <hicn/transport/interfaces/callbacks.h>
20 #include <hicn/transport/utils/literals.h>
21 #include <implementation/socket_consumer.h>
22 #include <protocols/indexer.h>
23 #include <protocols/reassembly.h>
24 
25 #include <deque>
26 
27 namespace transport {
28 
29 namespace interface {
30 class ConsumerSocket;
31 }
32 
33 namespace protocol {
34 
35 class Reassembly;
36 class TransportProtocol;
37 
38 class IncrementalIndexer : public Indexer {
39  public:
42  : Indexer(icn_socket, transport),
43  final_suffix_(Indexer::invalid_index),
44  first_suffix_(0),
45  next_download_suffix_(0),
46  next_reassembly_suffix_(0) {}
47 
48  IncrementalIndexer(const IncrementalIndexer &other) = delete;
49 
51  : Indexer(std::forward<Indexer>(other)),
52  final_suffix_(other.final_suffix_),
53  first_suffix_(other.first_suffix_),
54  next_download_suffix_(other.next_download_suffix_),
55  next_reassembly_suffix_(other.next_reassembly_suffix_) {}
56 
57  virtual ~IncrementalIndexer() {}
58 
59  virtual void reset() override {
60  final_suffix_ = Indexer::invalid_index;
61  next_download_suffix_ = first_suffix_;
62  next_reassembly_suffix_ = first_suffix_;
63  }
64 
65  virtual uint32_t checkNextSuffix() override {
66  return next_download_suffix_ <= final_suffix_ ? next_download_suffix_
67  : Indexer::invalid_index;
68  }
69 
70  virtual uint32_t getNextSuffix() override {
71  return next_download_suffix_ <= final_suffix_ ? next_download_suffix_++
72  : Indexer::invalid_index;
73  }
74 
75  virtual void setFirstSuffix(uint32_t suffix) override {
76  first_suffix_ = suffix;
77  }
78 
79  uint32_t getFirstSuffix() override { return first_suffix_; }
80 
81  virtual uint32_t jumpToIndex(uint32_t index) override {
82  next_download_suffix_ = index;
83  return next_download_suffix_;
84  }
85 
89  virtual uint32_t getNextReassemblySegment() override {
90  return next_reassembly_suffix_ <= final_suffix_ ? next_reassembly_suffix_++
91  : Indexer::invalid_index;
92  }
93 
94  virtual bool isFinalSuffixDiscovered() override {
95  return final_suffix_ != Indexer::invalid_index;
96  }
97 
98  virtual uint32_t getFinalSuffix() override { return final_suffix_; }
99 
100  void enableFec(fec::FECType fec_type) override {}
101 
102  void disableFec() override {}
103 
104  void setNFec(uint32_t n_fec) override {}
105  virtual uint32_t getNFec() override { return 0; }
106 
107  virtual void onContentObject(core::Interest &interest,
108  core::ContentObject &content_object,
109  bool reassembly) override;
110 
111  protected:
112  uint32_t final_suffix_;
113  uint32_t first_suffix_;
114  uint32_t next_download_suffix_;
115  uint32_t next_reassembly_suffix_;
116 };
117 
118 } // namespace protocol
119 } // namespace transport
transport::interface::ConsumerSocket
Main interface for consumer applications.
Definition: socket_consumer.h:48
transport::protocol::IncrementalIndexer::setNFec
void setNFec(uint32_t n_fec) override
Definition: incremental_indexer_bytestream.h:104
transport::protocol::IncrementalIndexer::jumpToIndex
virtual uint32_t jumpToIndex(uint32_t index) override
Definition: incremental_indexer_bytestream.h:81
transport::protocol::IncrementalIndexer::setFirstSuffix
virtual void setFirstSuffix(uint32_t suffix) override
Definition: incremental_indexer_bytestream.h:75
transport::protocol::IncrementalIndexer
Definition: incremental_indexer_bytestream.h:38
transport::core::ContentObject
Definition: content_object.h:29
transport::protocol::IncrementalIndexer::checkNextSuffix
virtual uint32_t checkNextSuffix() override
Definition: incremental_indexer_bytestream.h:65
transport::core::Interest
Definition: interest.h:30
transport
Definition: forwarder_config.h:32
transport::protocol::IncrementalIndexer::isFinalSuffixDiscovered
virtual bool isFinalSuffixDiscovered() override
Definition: incremental_indexer_bytestream.h:94
transport::protocol::IncrementalIndexer::reset
virtual void reset() override
Definition: incremental_indexer_bytestream.h:59
transport::protocol::Indexer
Definition: indexer.h:35
transport::protocol::TransportProtocol
Definition: transport_protocol.h:41
transport::protocol::IncrementalIndexer::onContentObject
virtual void onContentObject(core::Interest &interest, core::ContentObject &content_object, bool reassembly) override
transport::protocol::IncrementalIndexer::getNextReassemblySegment
virtual uint32_t getNextReassemblySegment() override
Definition: incremental_indexer_bytestream.h:89