Hybrid ICN (hICN) plugin  v21.06-rc0-4-g18fa668
socket_producer.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/signer.h>
19 #include <hicn/transport/config.h>
20 #include <hicn/transport/core/asio_wrapper.h>
21 #include <hicn/transport/core/name.h>
22 #include <hicn/transport/core/prefix.h>
23 #include <hicn/transport/interfaces/callbacks.h>
24 #include <hicn/transport/interfaces/socket_options_default_values.h>
25 #include <hicn/transport/interfaces/socket_options_keys.h>
26 
27 namespace transport {
28 
29 namespace implementation {
30 class ProducerSocket;
31 }
32 
33 namespace interface {
34 
35 using namespace core;
36 
38  public:
39  explicit ProducerSocket(
40  int protocol = ProductionProtocolAlgorithms::BYTE_STREAM);
41 
42  explicit ProducerSocket(int protocol, asio::io_service &io_service);
43 
44  virtual ~ProducerSocket();
45 
46  void connect();
47 
48  bool isRunning();
49 
50  void registerPrefix(const Prefix &producer_namespace);
51 
52  uint32_t produceStream(const Name &content_name, const uint8_t *buffer,
53  size_t buffer_size, bool is_last = true,
54  uint32_t start_offset = 0);
55 
56  uint32_t produceStream(const Name &content_name,
57  std::unique_ptr<utils::MemBuf> &&buffer,
58  bool is_last = true, uint32_t start_offset = 0);
59 
60  uint32_t produceDatagram(const Name &content_name, const uint8_t *buffer,
61  size_t buffer_size);
62 
63  uint32_t produceDatagram(const Name &content_name,
64  std::unique_ptr<utils::MemBuf> &&buffer);
65 
66  void asyncProduce(const Name &suffix, const uint8_t *buf, size_t buffer_size,
67  bool is_last = true, uint32_t *start_offset = nullptr);
68 
69  void asyncProduce(Name content_name, std::unique_ptr<utils::MemBuf> &&buffer,
70  bool is_last, uint32_t offset,
71  uint32_t **last_segment = nullptr);
72 
73  void produce(ContentObject &content_object);
74 
75  void serveForever();
76 
77  void stop();
78 
79  asio::io_service &getIoService();
80 
81  int setSocketOption(int socket_option_key, uint32_t socket_option_value);
82 
83  int setSocketOption(int socket_option_key,
84  std::nullptr_t socket_option_value);
85 
86  int setSocketOption(int socket_option_key, bool socket_option_value);
87 
88  int setSocketOption(int socket_option_key, Name *socket_option_value);
89 
90  int setSocketOption(int socket_option_key,
91  std::list<Prefix> socket_option_value);
92 
93  int setSocketOption(int socket_option_key,
94  ProducerContentObjectCallback socket_option_value);
95 
96  int setSocketOption(int socket_option_key,
97  ProducerInterestCallback socket_option_value);
98 
99  int setSocketOption(int socket_option_key,
100  ProducerContentCallback socket_option_value);
101 
102  int setSocketOption(int socket_option_key,
103  auth::CryptoHashType socket_option_value);
104 
105  int setSocketOption(int socket_option_key,
106  auth::CryptoSuite socket_option_value);
107 
108  int setSocketOption(int socket_option_key,
109  const std::shared_ptr<auth::Signer> &socket_option_value);
110 
111  int setSocketOption(int socket_option_key,
112  const std::string &socket_option_value);
113 
114  int getSocketOption(int socket_option_key, uint32_t &socket_option_value);
115 
116  int getSocketOption(int socket_option_key, bool &socket_option_value);
117 
118  int getSocketOption(int socket_option_key,
119  std::list<Prefix> &socket_option_value);
120 
121  int getSocketOption(int socket_option_key,
122  ProducerContentObjectCallback **socket_option_value);
123 
124  int getSocketOption(int socket_option_key,
125  ProducerContentCallback **socket_option_value);
126 
127  int getSocketOption(int socket_option_key,
128  ProducerInterestCallback **socket_option_value);
129 
130  int getSocketOption(int socket_option_key,
131  auth::CryptoHashType &socket_option_value);
132 
133  int getSocketOption(int socket_option_key,
134  auth::CryptoSuite &socket_option_value);
135 
136  int getSocketOption(int socket_option_key,
137  std::shared_ptr<auth::Signer> &socket_option_value);
138 
139  int getSocketOption(int socket_option_key, std::string &socket_option_value);
140 
141  protected:
142  ProducerSocket(bool);
143  std::unique_ptr<implementation::ProducerSocket> socket_;
144 };
145 
146 } // namespace interface
147 
148 } // namespace transport
transport::core::Name
Definition: name.h:45
transport::interface::ProducerSocket
Definition: socket_producer.h:37
transport::core::ContentObject
Definition: content_object.h:29
transport
Definition: forwarder_config.h:32
transport::core::Prefix
Definition: prefix.h:24