aboutsummaryrefslogtreecommitdiff
path: root/src/transport/transport-testing-communicator.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/transport-testing-communicator.h')
-rw-r--r--src/transport/transport-testing-communicator.h355
1 files changed, 355 insertions, 0 deletions
diff --git a/src/transport/transport-testing-communicator.h b/src/transport/transport-testing-communicator.h
new file mode 100644
index 000000000..693e61515
--- /dev/null
+++ b/src/transport/transport-testing-communicator.h
@@ -0,0 +1,355 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2019 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file transport/transport-testing-communicator.h
23 * @brief functions and structures related to testing-tng
24 * @author Christian Grothoff
25 * @author Julius Bünger
26 */
27#include "platform.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_ats_transport_service.h"
30#include "transport.h"
31
32/**
33 * @brief Queue of a communicator and some context
34 */
35struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue;
36
37
38/**
39 * @brief Handle/Context to a single transmission
40 */
41struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission;
42
43/**
44 * @brief Function signature for callbacks that are called when new
45 * backchannel message arrived
46 *
47 * @param cls Closure
48 * @param msg Backchannel message
49 * @param pid Target peer
50 */
51typedef struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *
52(*GNUNET_TRANSPORT_TESTING_BackchannelCallback)(void *cls,
53 struct GNUNET_MessageHeader *msg,
54 struct GNUNET_PeerIdentity *pid);
55
56
57/**
58 * @brief Function signature for callbacks that are called when new
59 * communicators become available
60 *
61 * @param cls Closure
62 * @param tc_h Communicator handle
63 * @param cc Characteristics of communicator
64 * @param address_prefix Prefix of the address
65 */
66typedef void
67(*GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback)(void *cls,
68 struct
69 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
70 *tc_h,
71 enum
72 GNUNET_TRANSPORT_CommunicatorCharacteristics
73 cc,
74 char *address_prefix);
75
76
77/**
78 * @brief Receive information about the address of a communicator.
79 *
80 * @param cls Closure
81 * @param tc_h Communicator handle
82 * @param address Address represented as string
83 * @param expiration Expiration
84 * @param aid Aid
85 * @param nt Network Type
86 */
87typedef void
88(*GNUNET_TRANSPORT_TESTING_AddAddressCallback)(void *cls,
89 struct
90 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
91 *tc_h,
92 const char *address,
93 struct GNUNET_TIME_Relative
94 expiration,
95 uint32_t aid,
96 enum GNUNET_NetworkType nt);
97
98
99/**
100 * @brief Get informed about the success of a queue request.
101 *
102 * @param cls Closure
103 * @param tc_h Communicator handle
104 * @param will_try #GNUNET_YES if communicator will try to create queue
105 */
106typedef void
107(*GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback)(void *cls,
108 struct
109 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
110 *tc_h,
111 int will_try);
112
113
114/**
115 * @brief Handle opening of queue
116 *
117 * @param cls Closure
118 * @param tc_h Communicator handle
119 * @param tc_queue Handle to newly opened queue
120 */
121typedef void
122(*GNUNET_TRANSPORT_TESTING_AddQueueCallback)(void *cls,
123 struct
124 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
125 *tc_h,
126 struct
127 GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue
128 *tc_queue,
129 size_t mtu);
130
131
132/**
133 * @brief Handle an incoming message
134 *
135 * @param cls Closure
136 * @param tc_h Handle to the receiving communicator
137 * @param msg Received message
138 */
139typedef void
140(*GNUNET_TRANSPORT_TESTING_IncomingMessageCallback)(void *cls,
141 struct
142 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
143 *tc_h,
144 const char*payload,
145 size_t payload_len);
146
147/**
148 * @brief Handle to a transport communicator
149 */
150struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
151{
152 /**
153 * Clients
154 */
155 struct MyClient *client_head;
156 struct MyClient *client_tail;
157
158 /**
159 * @brief Handle to the client
160 */
161 struct GNUNET_MQ_Handle *c_mq;
162
163 /**
164 * @brief Handle to the configuration
165 */
166 struct GNUNET_CONFIGURATION_Handle *cfg;
167
168 /**
169 * @brief File name of configuration file
170 */
171 char *cfg_filename;
172
173 struct GNUNET_PeerIdentity peer_id;
174
175 /**
176 * @brief Handle to the transport service
177 */
178 struct GNUNET_SERVICE_Handle *tsh;
179
180 /**
181 * @brief Task that will be run on shutdown to stop and clean transport
182 * service
183 */
184 struct GNUNET_SCHEDULER_Task *ts_shutdown_task;
185
186
187 /**
188 * @brief Process of the communicator
189 */
190 struct GNUNET_OS_Process *c_proc;
191
192 /**
193 * NAT process
194 */
195 struct GNUNET_OS_Process *nat_proc;
196
197 /**
198 * resolver service process
199 */
200 struct GNUNET_OS_Process *resolver_proc;
201
202 /**
203 * peerstore service process
204 */
205 struct GNUNET_OS_Process *ps_proc;
206
207 /**
208 * @brief Task that will be run on shutdown to stop and clean communicator
209 */
210 struct GNUNET_SCHEDULER_Task *c_shutdown_task;
211
212 /**
213 * @brief Characteristics of the communicator
214 */
215 enum GNUNET_TRANSPORT_CommunicatorCharacteristics c_characteristics;
216
217 /**
218 * @brief Specifies supported addresses
219 */
220 char *c_addr_prefix;
221
222 /**
223 * @brief Specifies supported addresses
224 */
225 char *c_address;
226
227 /**
228 * @brief Head of the DLL of queues associated with this communicator
229 */
230 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *queue_head;
231
232 /**
233 * @brief Tail of the DLL of queues associated with this communicator
234 */
235 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *queue_tail;
236
237 /* Callbacks + Closures */
238 /**
239 * @brief Callback called when a new communicator connects
240 */
241 GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback
242 communicator_available_cb;
243
244 /**
245 * @brief Callback called when a new communicator connects
246 */
247 GNUNET_TRANSPORT_TESTING_AddAddressCallback add_address_cb;
248
249 /**
250 * @brief Callback called when a new communicator connects
251 */
252 GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback queue_create_reply_cb;
253
254 /**
255 * @brief Callback called when a new communicator connects
256 */
257 GNUNET_TRANSPORT_TESTING_AddQueueCallback add_queue_cb;
258
259 /**
260 * @brief Callback called when a new communicator connects
261 */
262 GNUNET_TRANSPORT_TESTING_IncomingMessageCallback incoming_msg_cb;
263
264 /**
265 * @brief Backchannel callback
266 */
267 GNUNET_TRANSPORT_TESTING_BackchannelCallback bc_cb;
268
269 /**
270 * Our service handle
271 */
272 struct GNUNET_SERVICE_Handle *sh;
273
274 /**
275 * @brief Closure to the callback
276 */
277 void *cb_cls;
278
279 /**
280 * Backchannel supported
281 */
282 int bc_enabled;
283};
284
285/**
286 * @brief Start communicator part of transport service and communicator
287 *
288 * @param service_name Name of the service
289 * @param cfg Configuration handle
290 * @param communicator_available Callback that is called when a new
291 * communicator becomes available
292 * @param add_address_cb Callback handling new addresses
293 * @param queue_create_reply_cb Callback handling success of queue requests
294 * @param add_queue_cb Callback handling freshly created queues
295 * @param incoming_message_cb Callback handling incoming messages
296 * @param cb_cls Closure to @p communicator_available
297 *
298 * @return Handle to the communicator duo
299 */
300struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *
301GNUNET_TRANSPORT_TESTING_transport_communicator_service_start (
302 const char *service_name,
303 const char *binary_name,
304 const char *cfg_filename,
305 const struct GNUNET_PeerIdentity *peer_id,
306 GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback
307 communicator_available_cb,
308 GNUNET_TRANSPORT_TESTING_AddAddressCallback add_address_cb,
309 GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback queue_create_reply_cb,
310 GNUNET_TRANSPORT_TESTING_AddQueueCallback add_queue_cb,
311 GNUNET_TRANSPORT_TESTING_IncomingMessageCallback incoming_message_cb,
312 GNUNET_TRANSPORT_TESTING_BackchannelCallback bc_cb,
313 void *cb_cls);
314
315
316void
317GNUNET_TRANSPORT_TESTING_transport_communicator_service_stop (
318 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h);
319
320
321/**
322 * @brief Instruct communicator to open a queue
323 *
324 * @param tc_h Handle to communicator which shall open queue
325 * @param peer_id Towards which peer
326 * @param address For which address
327 */
328void
329GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue (struct
330 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
331 *tc_h,
332 const struct
333 GNUNET_PeerIdentity
334 *peer_id,
335 const char *address);
336
337
338/**
339 * @brief Instruct communicator to send data
340 *
341 * @param tc_queue The queue to use for sending
342 * @param cont function to call when done sending
343 * @param cont_cls closure for @a cont
344 * @param payload Data to send
345 * @param payload_size Size of the @a payload
346 */
347void
348GNUNET_TRANSPORT_TESTING_transport_communicator_send (struct
349 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
350 *tc_h,
351 GNUNET_SCHEDULER_TaskCallback
352 cont,
353 void *cont_cls,
354 const void *payload,
355 size_t payload_size);