Hybrid ICN (hICN) plugin  v21.06-rc0-4-g18fa668
icn_receiver.h
1 /*
2  * Copyright (c) 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 #include <hicn/transport/core/prefix.h>
17 #include <hicn/transport/interfaces/publication_options.h>
18 #include <hicn/transport/interfaces/socket_producer.h>
19 #include <hicn/transport/utils/spinlock.h>
20 
21 #include <asio.hpp>
22 #include <cassert>
23 #include <cstring>
24 #include <queue>
25 #include <utility>
26 
27 #include <hicn/http-proxy/http_session.h>
28 //#include "http_session.h"
29 
30 namespace transport {
31 
33  using SegmentProductionPair = std::pair<uint32_t, bool>;
34  using ResponseInfoMap = std::unordered_map<core::Name, SegmentProductionPair>;
35  using RequestQueue = std::queue<interface::PublicationOptions>;
36 
37  public:
38  explicit AsyncConsumerProducer(
39  asio::io_service& io_service, const std::string& prefix,
40  const std::string& first_ipv6_word, const std::string& origin_address,
41  const std::string& origin_port, const std::string& cache_size,
42  const std::string& mtu, const std::string& content_lifetime,
43  bool manifest);
44 
45  explicit AsyncConsumerProducer(
46  const std::string& prefix, const std::string& first_ipv6_word,
47  const std::string& origin_address, const std::string& origin_port,
48  const std::string& cache_size, const std::string& mtu,
49  const std::string& content_lifetime, bool manifest)
50  : AsyncConsumerProducer(internal_io_service_, prefix, first_ipv6_word,
51  origin_address, origin_port, cache_size, mtu,
52  content_lifetime, manifest) {
53  external_io_service_ = false;
54  }
55 
56  void run();
57 
58  void stop();
59 
60  private:
61  void start();
62 
63  void doSend();
64 
65  void doReceive();
66 
67  void publishContent(const uint8_t* data, std::size_t size,
68  bool is_last = true, bool headers = false);
69 
70  void manageIncomingInterest(core::Name& name, core::Packet::MemBufPtr& packet,
71  utils::MemBuf* payload);
72 
73  core::Prefix prefix_;
74  asio::io_service& io_service_;
75  asio::io_service internal_io_service_;
76  bool external_io_service_;
77  interface::ProducerSocket producer_socket_;
78 
79  std::string ip_address_;
80  std::string port_;
81  uint32_t cache_size_;
82  uint32_t mtu_;
83 
84  uint64_t request_counter_;
85 
86  // std::unordered_map<core::Name, std::shared_ptr<ATSConnector>>
87  // connection_map_;
88  HTTPSession connector_;
89 
90  unsigned long default_content_lifetime_;
91 
92  // ResponseInfoMap --> max_seq_number + bool indicating whether request is in
93  // production
94  ResponseInfoMap chunk_number_map_;
95  RequestQueue response_name_queue_;
96 };
97 
98 } // namespace transport
transport::core::Name
Definition: name.h:45
transport::AsyncConsumerProducer
Definition: icn_receiver.h:32
transport::interface::ProducerSocket
Definition: socket_producer.h:37
transport
Definition: forwarder_config.h:32
transport::HTTPSession
Definition: http_session.h:59
transport::core::Prefix
Definition: prefix.h:24
utils::MemBuf
Definition: membuf.h:45