aboutsummaryrefslogtreecommitdiff
path: root/src/transport/transport-testing2.h
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2020-12-08 10:56:46 +0100
committert3sserakt <t3ss@posteo.de>2020-12-08 10:56:46 +0100
commit7a8531c1245983ab09a5bf146c9258321f7fa61a (patch)
treea5ac229e4667866340a685c7eb6fa19b259c363f /src/transport/transport-testing2.h
parent6e3ca264f69ea03520c5855161d1c8487c1e4e01 (diff)
parent7ce054864a112f459a75ab542f844a8be0e6c47c (diff)
downloadgnunet-7a8531c1245983ab09a5bf146c9258321f7fa61a.tar.gz
gnunet-7a8531c1245983ab09a5bf146c9258321f7fa61a.zip
Merge branch 'master' of ssh://gnunet.org/gnunet
Diffstat (limited to 'src/transport/transport-testing2.h')
-rw-r--r--src/transport/transport-testing2.h970
1 files changed, 767 insertions, 203 deletions
diff --git a/src/transport/transport-testing2.h b/src/transport/transport-testing2.h
index a95c0dfa7..3554436d8 100644
--- a/src/transport/transport-testing2.h
+++ b/src/transport/transport-testing2.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2019 GNUnet e.V. 3 Copyright (C) 2006, 2009, 2015, 2016 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 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 6 under the terms of the GNU Affero General Public License as published
@@ -19,342 +19,906 @@
19 */ 19 */
20 20
21/** 21/**
22 * @file transport/transport-testing2.h 22 * @file transport-testing.h
23 * @brief functions and structures related to testing-tng 23 * @brief testing lib for transport service
24 * @author Matthias Wachs
24 * @author Christian Grothoff 25 * @author Christian Grothoff
25 * @author Julius Bünger
26 */ 26 */
27#ifndef TRANSPORT_TESTING_H
28#define TRANSPORT_TESTING_H
27#include "platform.h" 29#include "platform.h"
28#include "gnunet_util_lib.h" 30#include "gnunet_util_lib.h"
29#include "gnunet_ats_transport_service.h" 31#include "gnunet_hello_lib.h"
30#include "transport.h" 32#include "gnunet_peerstore_service.h"
33#include "gnunet_transport_core_service.h"
34#include "gnunet_transport_application_service.h"
35#include "gnunet_transport_manipulation_service.h"
36#include "gnunet_testing_lib.h"
37
38
39/* ************* Basic functions for starting/stopping/connecting *********** */
40
41/**
42 * Context for a single peer
43 */
44struct GNUNET_TRANSPORT_TESTING_PeerContext;
31 45
32/** 46/**
33 * @brief Queue of a communicator and some context 47 * Definition for a transport testing handle
34 */ 48 */
35struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue; 49struct GNUNET_TRANSPORT_TESTING_Handle;
36 50
37 51
38/** 52/**
39 * @brief Handle/Context to a single transmission 53 * Context for a single peer
40 */ 54 */
41struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission; 55struct GNUNET_TRANSPORT_TESTING_PeerContext
56{
57 /**
58 * Next element in the DLL
59 */
60 struct GNUNET_TRANSPORT_TESTING_PeerContext *next;
61
62 /**
63 * Previous element in the DLL
64 */
65 struct GNUNET_TRANSPORT_TESTING_PeerContext *prev;
66
67 /**
68 * Transport testing handle this peer belongs to
69 */
70 struct GNUNET_TRANSPORT_TESTING_Handle *tth;
71
72 /**
73 * Application handle
74 */
75 struct GNUNET_TRANSPORT_ApplicationHandle *ah;
76
77 /**
78 * Peer's configuration
79 */
80 struct GNUNET_CONFIGURATION_Handle *cfg;
81
82 /**
83 * Peer's transport service handle
84 */
85 struct GNUNET_TRANSPORT_CoreHandle *th;
86
87 /**
88 * Peer's transport service manipulation handle
89 */
90 struct GNUNET_TRANSPORT_ManipulationHandle *tmh;
91
92 /**
93 * Peer's ATS handle.
94 */
95 struct GNUNET_ATS_ConnectivityHandle *ats;
96
97 /**
98 * Peer's PEERSTORE Handle
99 */
100 struct GNUNET_PEERSTORE_Handle *ph;
101
102 /**
103 * Peer's transport get hello handle to retrieve peer's HELLO message
104 */
105 struct GNUNET_PEERSTORE_IterateContext *pic;
106
107 /**
108 * Hello
109 */
110 char *hello;
111
112 /**
113 * Hello size
114 */
115 size_t hello_size;
116
117 /**
118 * Peer's testing handle
119 */
120 struct GNUNET_TESTING_Peer *peer;
121
122 /**
123 * Peer identity
124 */
125 struct GNUNET_PeerIdentity id;
126
127 /**
128 * Handle for the peer's ARM process
129 */
130 struct GNUNET_OS_Process *arm_proc;
131
132 /**
133 * Receive callback
134 */
135 struct GNUNET_MQ_MessageHandler *handlers;
136
137 /**
138 * Notify connect callback
139 */
140 GNUNET_TRANSPORT_NotifyConnect nc;
141
142 /**
143 * Notify disconnect callback
144 */
145 GNUNET_TRANSPORT_NotifyDisconnect nd;
146
147 /**
148 * Startup completed callback
149 */
150 GNUNET_SCHEDULER_TaskCallback start_cb;
151
152 /**
153 * Closure for the @a nc and @a nd callbacks
154 */
155 void *cb_cls;
156
157 /**
158 * Closure for @e start_cb.
159 */
160 void *start_cb_cls;
161
162 /**
163 * An unique number to identify the peer
164 */
165 unsigned int no;
166};
167
42 168
43/** 169/**
44 * @brief Function signature for callbacks that are called when new 170 * Handle for a request to connect two peers.
45 * backchannel message arrived 171 */
172struct GNUNET_TRANSPORT_TESTING_ConnectRequest
173{
174 /**
175 * Kept in a DLL.
176 */
177 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *next;
178
179 /**
180 * Kept in a DLL.
181 */
182 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *prev;
183
184 /**
185 * Peer we want to connect.
186 */
187 struct GNUNET_TRANSPORT_TESTING_PeerContext *p1;
188
189 /**
190 * Peer we want to connect.
191 */
192 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2;
193
194 /**
195 * Task by which we accomplish the connection.
196 */
197 struct GNUNET_SCHEDULER_Task *tct;
198
199 /**
200 * Handle by which we ask ATS to faciliate the connection.
201 */
202 struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh;
203
204 /**
205 * Function to call upon completion.
206 */
207 GNUNET_SCHEDULER_TaskCallback cb;
208
209 /**
210 * Closure for @e cb.
211 */
212 void *cb_cls;
213
214 /**
215 * Message queue for sending from @a p1 to @a p2.
216 */
217 struct GNUNET_MQ_Handle *mq;
218
219 /**
220 * Set if peer1 says the connection is up to peer2.
221 */
222 int p1_c;
223
224 /**
225 * Set if peer2 says the connection is up to peer1.
226 */
227 int p2_c;
228
229 /**
230 * #GNUNET_YES if both @e p1_c and @e p2_c are #GNUNET_YES.
231 */
232 int connected;
233};
234
235
236/**
237 * Handle for a test run.
238 */
239struct GNUNET_TRANSPORT_TESTING_Handle
240{
241 /**
242 * Testing library system handle
243 */
244 struct GNUNET_TESTING_System *tl_system;
245
246 /**
247 * head DLL of connect contexts
248 */
249 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc_head;
250
251 /**
252 * head DLL of connect contexts
253 */
254 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc_tail;
255
256 /**
257 * head DLL of peers
258 */
259 struct GNUNET_TRANSPORT_TESTING_PeerContext *p_head;
260
261 /**
262 * tail DLL of peers
263 */
264 struct GNUNET_TRANSPORT_TESTING_PeerContext *p_tail;
265};
266
267
268/**
269 * Initialize the transport testing
270 *
271 * @return transport testing handle
272 */
273struct GNUNET_TRANSPORT_TESTING_Handle *
274GNUNET_TRANSPORT_TESTING_init (void);
275
276
277/**
278 * Clean up the transport testing
46 * 279 *
47 * @param cls Closure 280 * @param tth transport testing handle
48 * @param msg Backchannel message
49 * @param pid Target peer
50 */ 281 */
51typedef struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle * 282void
52(*GNUNET_TRANSPORT_TESTING_BackchannelCallback)(void *cls, 283GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_Handle *tth);
53 struct GNUNET_MessageHeader *msg,
54 struct GNUNET_PeerIdentity *pid);
55 284
56 285
57/** 286/**
58 * @brief Function signature for callbacks that are called when new 287 * Start a peer with the given configuration
59 * communicators become available
60 * 288 *
61 * @param cls Closure 289 * @param tth the testing handle
62 * @param tc_h Communicator handle 290 * @param cfgname configuration file
63 * @param cc Characteristics of communicator 291 * @param peer_id the peer_id
64 * @param address_prefix Prefix of the address 292 * @param handlers functions for receiving messages
293 * @param nc connect callback
294 * @param nd disconnect callback
295 * @param cb_cls closure for @a nc and @a nd callback
296 * @param start_cb start callback
297 * @param start_cb_cls closure for @a start_cb
298 * @return the peer context
65 */ 299 */
66typedef void 300struct GNUNET_TRANSPORT_TESTING_PeerContext *
67(*GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback)(void *cls, 301GNUNET_TRANSPORT_TESTING_start_peer (
68 struct 302 struct GNUNET_TRANSPORT_TESTING_Handle *tth,
69 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle 303 const char *cfgname,
70 *tc_h, 304 int peer_id,
71 enum 305 const struct GNUNET_MQ_MessageHandler *handlers,
72 GNUNET_TRANSPORT_CommunicatorCharacteristics 306 GNUNET_TRANSPORT_NotifyConnect nc,
73 cc, 307 GNUNET_TRANSPORT_NotifyDisconnect nd,
74 char *address_prefix); 308 void *cb_cls,
309 GNUNET_SCHEDULER_TaskCallback start_cb,
310 void *start_cb_cls);
75 311
76 312
77/** 313/**
78 * @brief Receive information about the address of a communicator. 314 * Shutdown the given peer
79 * 315 *
80 * @param cls Closure 316 * @param p the peer
81 * @param tc_h Communicator handle 317 */
82 * @param address Address represented as string 318void
83 * @param expiration Expiration 319GNUNET_TRANSPORT_TESTING_stop_peer (
84 * @param aid Aid 320 struct GNUNET_TRANSPORT_TESTING_PeerContext *pc);
85 * @param nt Network Type 321
86 */ 322
87typedef void 323/**
88(*GNUNET_TRANSPORT_TESTING_AddAddressCallback)(void *cls, 324 * Stops and restarts the given peer, sleeping (!) for 5s in between.
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 * 325 *
102 * @param cls Closure 326 * @param p the peer
103 * @param tc_h Communicator handle 327 * @param restart_cb restart callback
104 * @param will_try #GNUNET_YES if communicator will try to create queue 328 * @param restart_cb_cls callback closure
329 * @return #GNUNET_OK in success otherwise #GNUNET_SYSERR
105 */ 330 */
106typedef void 331int
107(*GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback)(void *cls, 332GNUNET_TRANSPORT_TESTING_restart_peer (
108 struct 333 struct GNUNET_TRANSPORT_TESTING_PeerContext *p,
109 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle 334 GNUNET_SCHEDULER_TaskCallback restart_cb,
110 *tc_h, 335 void *restart_cb_cls);
111 int will_try);
112 336
113 337
114/** 338/**
115 * @brief Handle opening of queue 339 * Connect the given peers and call the callback when both peers
340 * report the inbound connection. Remarks: start_peer's notify_connect
341 * callback can be called before.
116 * 342 *
117 * @param cls Closure 343 * @param p1 peer 1
118 * @param tc_h Communicator handle 344 * @param p2 peer 2
119 * @param tc_queue Handle to newly opened queue 345 * @param cb the callback to call when both peers notified that they are
346 * connected
347 * @param cls callback cls
348 * @return a connect request handle
120 */ 349 */
121typedef void 350struct GNUNET_TRANSPORT_TESTING_ConnectRequest *
122(*GNUNET_TRANSPORT_TESTING_AddQueueCallback)(void *cls, 351GNUNET_TRANSPORT_TESTING_connect_peers (
123 struct 352 struct GNUNET_TRANSPORT_TESTING_PeerContext *p1,
124 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle 353 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2,
125 *tc_h, 354 GNUNET_SCHEDULER_TaskCallback cb,
126 struct 355 void *cls);
127 GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue
128 *tc_queue,
129 size_t mtu);
130 356
131 357
132/** 358/**
133 * @brief Handle an incoming message 359 * Cancel the request to connect two peers. You MUST cancel the
360 * request if you stop the peers before the peers connected
361 * succesfully.
134 * 362 *
135 * @param cls Closure 363 * @param cc a connect request handle
136 * @param tc_h Handle to the receiving communicator
137 * @param msg Received message
138 */ 364 */
139typedef void 365void
140(*GNUNET_TRANSPORT_TESTING_IncomingMessageCallback)(void *cls, 366GNUNET_TRANSPORT_TESTING_connect_peers_cancel (
141 struct 367 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc);
142 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle 368
143 *tc_h,
144 const char*payload,
145 size_t payload_len);
146 369
147/** 370/**
148 * @brief Handle to a transport communicator 371 * Function called on matching connect requests.
372 *
373 * @param cls closure
374 * @param cc request matching the query
149 */ 375 */
150struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle 376typedef void (*GNUNET_TRANSPORT_TESTING_ConnectContextCallback) (
377 void *cls,
378 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc);
379
380
381/**
382 * Find any connecting context matching the given pair of peers.
383 *
384 * @param p1 first peer
385 * @param p2 second peer
386 * @param cb function to call
387 * @param cb_cls closure for @a cb
388 */
389void
390GNUNET_TRANSPORT_TESTING_find_connecting_context (
391 struct GNUNET_TRANSPORT_TESTING_PeerContext *p1,
392 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2,
393 GNUNET_TRANSPORT_TESTING_ConnectContextCallback cb,
394 void *cb_cls);
395
396
397/* ********************** high-level process functions *************** */
398
399
400/**
401 * Function called once the peers have been launched and
402 * connected by #GNUNET_TRANSPORT_TESTING_connect_check().
403 *
404 * @param cls closure
405 * @param num_peers size of the @a p array
406 * @param p the peers that were launched
407 */
408typedef void (*GNUNET_TRANSPORT_TESTING_ConnectContinuation) (
409 void *cls,
410 unsigned int num_peers,
411 struct GNUNET_TRANSPORT_TESTING_PeerContext *p[]);
412
413
414/**
415 * Internal data structure.
416 */
417struct GNUNET_TRANSPORT_TESTING_ConnectRequestList;
418
419/**
420 * Internal data structure.
421 */
422struct GNUNET_TRANSPORT_TESTING_InternalPeerContext;
423
424
425GNUNET_NETWORK_STRUCT_BEGIN
426struct GNUNET_TRANSPORT_TESTING_TestMessage
151{ 427{
152 /** 428 /**
153 * Clients 429 * Type is (usually) #GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE.
154 */ 430 */
155 struct MyClient *client_head; 431 struct GNUNET_MessageHeader header;
156 struct MyClient *client_tail;
157 432
158 /** 433 /**
159 * @brief Handle to the client 434 * Monotonically increasing counter throughout the test.
160 */ 435 */
161 struct GNUNET_MQ_Handle *c_mq; 436 uint32_t num GNUNET_PACKED;
437};
438GNUNET_NETWORK_STRUCT_END
439
162 440
441/**
442 * Function called by the transport for each received message.
443 *
444 * @param cls closure
445 * @param receiver receiver of the message
446 * @param sender sender of the message
447 * @param message the message
448 */
449typedef void (*GNUNET_TRANSPORT_TESTING_ReceiveCallback) (
450 void *cls,
451 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
452 const struct GNUNET_PeerIdentity *sender,
453 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message);
454
455
456/**
457 * Function called to notify transport users that another
458 * peer connected to us.
459 *
460 * @param cls closure
461 * @param me peer experiencing the event
462 * @param other peer that connected to @a me
463 */
464typedef void (*GNUNET_TRANSPORT_TESTING_NotifyConnect) (
465 void *cls,
466 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
467 const struct GNUNET_PeerIdentity *other);
468
469
470/**
471 * Function called to notify transport users that another
472 * peer disconnected from us.
473 *
474 * @param cls closure
475 * @param me peer experiencing the event
476 * @param other peer that disconnected from @a me
477 */
478typedef void (*GNUNET_TRANSPORT_TESTING_NotifyDisconnect) (
479 void *cls,
480 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
481 const struct GNUNET_PeerIdentity *other);
482
483
484/**
485 * Closure that must be passed to
486 * #GNUNET_TRANSPORT_TESTING_connect_check.
487 */
488struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext
489{
163 /** 490 /**
164 * @brief Handle to the configuration 491 * How should we continue after the connect?
165 */ 492 */
166 struct GNUNET_CONFIGURATION_Handle *cfg; 493 GNUNET_SCHEDULER_TaskCallback connect_continuation;
167 494
168 /** 495 /**
169 * @brief File name of configuration file 496 * Closure for @e connect_continuation.
170 */ 497 */
171 char *cfg_filename; 498 void *connect_continuation_cls;
172 499
173 struct GNUNET_PeerIdentity peer_id; 500 /**
501 * Which configuration file should we pass to the
502 * #GNUNET_PROGRAM_run() of the testcase?
503 */
504 const char *config_file;
174 505
175 /** 506 /**
176 * @brief Handle to the transport service 507 * Receiver argument to give for peers we start.
177 */ 508 */
178 struct GNUNET_SERVICE_Handle *tsh; 509 GNUNET_TRANSPORT_TESTING_ReceiveCallback rec;
179 510
180 /** 511 /**
181 * @brief Task that will be run on shutdown to stop and clean transport 512 * Notify connect argument to give for peers we start.
182 * service
183 */ 513 */
184 struct GNUNET_SCHEDULER_Task *ts_shutdown_task; 514 GNUNET_TRANSPORT_TESTING_NotifyConnect nc;
185 515
516 /**
517 * Notify disconnect argument to give for peers we start.
518 */
519 GNUNET_TRANSPORT_TESTING_NotifyDisconnect nd;
186 520
187 /** 521 /**
188 * @brief Process of the communicator 522 * Closure for @e rec, @e nc and @e nd.
189 */ 523 */
190 struct GNUNET_OS_Process *c_proc; 524 void *cls;
191 525
192 /** 526 /**
193 * NAT process 527 * Custom task to run on shutdown.
194 */ 528 */
195 struct GNUNET_OS_Process *nat_proc; 529 GNUNET_SCHEDULER_TaskCallback shutdown_task;
196 530
197 /** 531 /**
198 * statistics service process 532 * Closure for @e shutdown_task.
199 */ 533 */
200 struct GNUNET_OS_Process *statistics_proc; 534 void *shutdown_task_cls;
201 535
202 /** 536 /**
203 * resolver service process 537 * Custom task to run after peers were started but before we try to
538 * connect them. If this function is set, we wait ONE second after
539 * running this function until we continue with connecting the
540 * peers.
204 */ 541 */
205 struct GNUNET_OS_Process *resolver_proc; 542 GNUNET_SCHEDULER_TaskCallback pre_connect_task;
206 543
207 /** 544 /**
208 * peerstore service process 545 * Closure for @e shutdown_task.
209 */ 546 */
210 struct GNUNET_OS_Process *ps_proc; 547 void *pre_connect_task_cls;
211 548
212 /** 549 /**
213 * @brief Task that will be run on shutdown to stop and clean communicator 550 * When should the testcase time out?
214 */ 551 */
215 struct GNUNET_SCHEDULER_Task *c_shutdown_task; 552 struct GNUNET_TIME_Relative timeout;
216 553
217 /** 554 /**
218 * @brief Characteristics of the communicator 555 * Should we try to create connections in both directions?
219 */ 556 */
220 enum GNUNET_TRANSPORT_CommunicatorCharacteristics c_characteristics; 557 int bi_directional;
558
559 /* ******* fields set by #GNUNET_TRANSPORT_TESTING_connect_check **** */
221 560
222 /** 561 /**
223 * @brief Specifies supported addresses 562 * Number of peers involved in the test.
224 */ 563 */
225 char *c_addr_prefix; 564 unsigned int num_peers;
226 565
227 /** 566 /**
228 * @brief Specifies supported addresses 567 * Configuration files we have, array with @e num_peers entries.
229 */ 568 */
230 char *c_address; 569 char **cfg_files;
231 570
232 /** 571 /**
233 * @brief Head of the DLL of queues associated with this communicator 572 * Array with @e num_peers entries.
234 */ 573 */
235 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *queue_head; 574 struct GNUNET_TRANSPORT_TESTING_PeerContext **p;
236 575
237 /** 576 /**
238 * @brief Tail of the DLL of queues associated with this communicator 577 * Name of the plugin.
239 */ 578 */
240 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *queue_tail; 579 const char *test_plugin;
241 580
242 /* Callbacks + Closures */
243 /** 581 /**
244 * @brief Callback called when a new communicator connects 582 * Name of the testcase.
245 */ 583 */
246 GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback 584 const char *test_name;
247 communicator_available_cb;
248 585
249 /** 586 /**
250 * @brief Callback called when a new communicator connects 587 * Configuration object for the testcase.
251 */ 588 */
252 GNUNET_TRANSPORT_TESTING_AddAddressCallback add_address_cb; 589 const struct GNUNET_CONFIGURATION_Handle *cfg;
253 590
254 /** 591 /**
255 * @brief Callback called when a new communicator connects 592 * Main testing handle.
256 */ 593 */
257 GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback queue_create_reply_cb; 594 struct GNUNET_TRANSPORT_TESTING_Handle *tth;
258 595
259 /** 596 /**
260 * @brief Callback called when a new communicator connects 597 * Result from the main function, set to #GNUNET_OK on success.
598 * Clients should set to #GNUNET_SYSERR to indicate test failure.
261 */ 599 */
262 GNUNET_TRANSPORT_TESTING_AddQueueCallback add_queue_cb; 600 int global_ret;
263 601
264 /** 602 /**
265 * @brief Callback called when a new communicator connects 603 * Generator for the `num` field in test messages. Incremented each
604 * time #GNUNET_TRANSPORT_TESTING_simple_send or
605 * #GNUNET_TRANSPORT_TESTING_large_send are used to transmit a
606 * message.
266 */ 607 */
267 GNUNET_TRANSPORT_TESTING_IncomingMessageCallback incoming_msg_cb; 608 uint32_t send_num_gen;
609
610 /* ******* internal state, clients should not mess with this **** */
268 611
269 /** 612 /**
270 * @brief Backchannel callback 613 * Task run on timeout.
271 */ 614 */
272 GNUNET_TRANSPORT_TESTING_BackchannelCallback bc_cb; 615 struct GNUNET_SCHEDULER_Task *timeout_task;
273 616
274 /** 617 /**
275 * Our service handle 618 * Task run to connect peers.
276 */ 619 */
277 struct GNUNET_SERVICE_Handle *sh; 620 struct GNUNET_SCHEDULER_Task *connect_task;
278 621
279 /** 622 /**
280 * @brief Closure to the callback 623 * Number of peers that have been started.
281 */ 624 */
282 void *cb_cls; 625 unsigned int started;
283 626
284 /** 627 /**
285 * Backchannel supported 628 * DLL of active connect requests.
286 */ 629 */
287 int bc_enabled; 630 struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl_head;
631
632 /**
633 * DLL of active connect requests.
634 */
635 struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl_tail;
636
637 /**
638 * Array with @e num_peers entries.
639 */
640 struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ip;
288}; 641};
289 642
643
290/** 644/**
291 * @brief Start communicator part of transport service and communicator 645 * Find peer by peer ID.
292 * 646 *
293 * @param service_name Name of the service 647 * @param ccc context to search
294 * @param cfg Configuration handle 648 * @param peer peer to look for
295 * @param communicator_available Callback that is called when a new 649 * @return NULL if @a peer was not found
296 * communicator becomes available 650 */
297 * @param add_address_cb Callback handling new addresses 651struct GNUNET_TRANSPORT_TESTING_PeerContext *
298 * @param queue_create_reply_cb Callback handling success of queue requests 652GNUNET_TRANSPORT_TESTING_find_peer (
299 * @param add_queue_cb Callback handling freshly created queues 653 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc,
300 * @param incoming_message_cb Callback handling incoming messages 654 const struct GNUNET_PeerIdentity *peer);
301 * @param cb_cls Closure to @p communicator_available 655
656
657/**
658 * Common implementation of the #GNUNET_TRANSPORT_TESTING_CheckCallback.
659 * Starts and connects the two peers, then invokes the
660 * `connect_continuation` from @a cls. Sets up a timeout to
661 * abort the test, and a shutdown handler to clean up properly
662 * on exit.
302 * 663 *
303 * @return Handle to the communicator duo 664 * @param cls closure of type `struct
304 */ 665 * GNUNET_TRANSPORT_TESTING_ConnectCheckContext`
305struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle * 666 * @param tth_ initialized testing handle
306GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( 667 * @param test_plugin_ name of the plugin
307 const char *service_name, 668 * @param test_name_ name of the test
308 const char *binary_name, 669 * @param num_peers number of entries in the @a cfg_file array
309 const char *cfg_filename, 670 * @param cfg_files array of names of configuration files for the peers
310 const struct GNUNET_PeerIdentity *peer_id, 671 * @return #GNUNET_SYSERR on error
311 GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback 672 */
312 communicator_available_cb, 673int
313 GNUNET_TRANSPORT_TESTING_AddAddressCallback add_address_cb, 674GNUNET_TRANSPORT_TESTING_connect_check (
314 GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback queue_create_reply_cb, 675 void *cls,
315 GNUNET_TRANSPORT_TESTING_AddQueueCallback add_queue_cb, 676 struct GNUNET_TRANSPORT_TESTING_Handle *tth_,
316 GNUNET_TRANSPORT_TESTING_IncomingMessageCallback incoming_message_cb, 677 const char *test_plugin_,
317 GNUNET_TRANSPORT_TESTING_BackchannelCallback bc_cb, 678 const char *test_name_,
318 void *cb_cls); 679 unsigned int num_peers,
680 char *cfg_files[]);
681
682
683/**
684 * Main function of a testcase. Called with the initial setup data
685 * for the test as derived from the source name and the binary name.
686 *
687 * @param cls closure
688 * @param tth_ initialized testing handle
689 * @param test_plugin_ name of the plugin
690 * @param test_name_ name of the test
691 * @param num_peers number of entries in the @a cfg_file array
692 * @param cfg_files array of names of configuration files for the peers
693 * @return #GNUNET_SYSERR on error
694 */
695typedef int (*GNUNET_TRANSPORT_TESTING_CheckCallback) (
696 void *cls,
697 struct GNUNET_TRANSPORT_TESTING_Handle *tth_,
698 const char *test_plugin_,
699 const char *test_name_,
700 unsigned int num_peers,
701 char *cfg_files[]);
702
703
704/**
705 * Setup testcase. Calls @a check with the data the test needs.
706 *
707 * @param argv0 binary name (argv[0])
708 * @param filename source file name (__FILE__)
709 * @param num_peers number of peers to start
710 * @param check main function to run
711 * @param check_cls closure for @a check
712 * @return #GNUNET_OK on success
713 */
714int
715GNUNET_TRANSPORT_TESTING_main_ (const char *argv0,
716 const char *filename,
717 unsigned int num_peers,
718 GNUNET_TRANSPORT_TESTING_CheckCallback check,
719 void *check_cls);
720
721
722/**
723 * Setup testcase. Calls @a check with the data the test needs.
724 *
725 * @param num_peers number of peers to start
726 * @param check main function to run
727 * @param check_cls closure for @a check
728 * @return #GNUNET_OK on success
729 */
730#define GNUNET_TRANSPORT_TESTING_main(num_peers, check, check_cls) \
731 GNUNET_TRANSPORT_TESTING_main_ (argv[0], \
732 __FILE__, \
733 num_peers, \
734 check, \
735 check_cls)
736
737/* ***************** Convenience functions for sending ********* */
738
739/**
740 * Send a test message of type @a mtype and size @a msize from
741 * peer @a sender to peer @a receiver. The peers should be
742 * connected when this function is called.
743 *
744 * @param sender the sending peer
745 * @param receiver the receiving peer
746 * @param mtype message type to use
747 * @param msize size of the message, at least `sizeof (struct
748 * GNUNET_TRANSPORT_TESTING_TestMessage)`
749 * @param num unique message number
750 * @param cont continuation to call after transmission
751 * @param cont_cls closure for @a cont
752 * @return #GNUNET_OK if message was queued,
753 * #GNUNET_NO if peers are not connected
754 * #GNUNET_SYSERR if @a msize is illegal
755 */
756int
757GNUNET_TRANSPORT_TESTING_send (
758 struct GNUNET_TRANSPORT_TESTING_PeerContext *sender,
759 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
760 uint16_t mtype,
761 uint16_t msize,
762 uint32_t num,
763 GNUNET_SCHEDULER_TaskCallback cont,
764 void *cont_cls);
765
766
767/**
768 * Message type used by #GNUNET_TRANSPORT_TESTING_simple_send().
769 */
770#define GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE 12345
771
772/**
773 * Alternative message type for tests.
774 */
775#define GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2 12346
319 776
320 777
778/**
779 * Type of the closure argument to pass to
780 * #GNUNET_TRANSPORT_TESTING_simple_send() and
781 * #GNUNET_TRANSPORT_TESTING_large_send().
782 */
783struct GNUNET_TRANSPORT_TESTING_SendClosure
784{
785 /**
786 * Context for the transmission.
787 */
788 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
789
790 /**
791 * Function that returns the desired message size. Overrides
792 * the message size, can be NULL in which case the message
793 * size is the default.
794 */
795 size_t (*get_size_cb) (unsigned int n);
796
797 /**
798 * Number of messages to be transmitted in a loop.
799 * Use zero for "forever" (until external shutdown).
800 */
801 unsigned int num_messages;
802
803 /**
804 * Function to call after all transmissions, can be NULL.
805 */
806 GNUNET_SCHEDULER_TaskCallback cont;
807
808 /**
809 * Closure for @e cont.
810 */
811 void *cont_cls;
812};
813
814
815/**
816 * Task that sends a minimalistic test message from the
817 * first peer to the second peer.
818 *
819 * @param cls the `struct GNUNET_TRANSPORT_TESTING_SendClosure`
820 * which should contain at least two peers, the first two
821 * of which should be currently connected
822 */
321void 823void
322GNUNET_TRANSPORT_TESTING_transport_communicator_service_stop ( 824GNUNET_TRANSPORT_TESTING_simple_send (void *cls);
323 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h);
324 825
826/**
827 * Size of a message sent with
828 * #GNUNET_TRANSPORT_TESTING_large_send(). Big enough
829 * to usually force defragmentation.
830 */
831#define GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE 2600
325 832
326/** 833/**
327 * @brief Instruct communicator to open a queue 834 * Task that sends a large test message from the
835 * first peer to the second peer.
328 * 836 *
329 * @param tc_h Handle to communicator which shall open queue 837 * @param cls the `struct GNUNET_TRANSPORT_TESTING_SendClosure`
330 * @param peer_id Towards which peer 838 * which should contain at least two peers, the first two
331 * @param address For which address 839 * of which should be currently connected
332 */ 840 */
333void 841void
334GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue (struct 842GNUNET_TRANSPORT_TESTING_large_send (void *cls);
335 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle 843
336 *tc_h, 844
337 const struct 845/* ********************** log-only convenience functions ************* */
338 GNUNET_PeerIdentity
339 *peer_id,
340 const char *address);
341 846
342 847
343/** 848/**
344 * @brief Instruct communicator to send data 849 * Log a connect event.
345 * 850 *
346 * @param tc_queue The queue to use for sending 851 * @param cls NULL
347 * @param cont function to call when done sending 852 * @param me peer that had the event
348 * @param cont_cls closure for @a cont 853 * @param other peer that connected.
349 * @param payload Data to send
350 * @param payload_size Size of the @a payload
351 */ 854 */
352void 855void
353GNUNET_TRANSPORT_TESTING_transport_communicator_send (struct 856GNUNET_TRANSPORT_TESTING_log_connect (
354 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle 857 void *cls,
355 *tc_h, 858 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
356 GNUNET_SCHEDULER_TaskCallback 859 const struct GNUNET_PeerIdentity *other);
357 cont, 860
358 void *cont_cls, 861
359 const void *payload, 862/**
360 size_t payload_size); 863 * Log a disconnect event.
864 *
865 * @param cls NULL
866 * @param me peer that had the event
867 * @param other peer that disconnected.
868 */
869void
870GNUNET_TRANSPORT_TESTING_log_disconnect (
871 void *cls,
872 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
873 const struct GNUNET_PeerIdentity *other);
874
875
876/* ********************** low-level filename functions *************** */
877
878
879/**
880 * Extracts the test filename from an absolute file name and removes
881 * the extension.
882 *
883 * @param file absolute file name
884 * @return resulting test name
885 */
886char *
887GNUNET_TRANSPORT_TESTING_get_test_name (const char *file);
888
889
890/**
891 * This function takes the filename (e.g. argv[0), removes a "lt-"-prefix and
892 * if existing ".exe"-prefix and adds the peer-number
893 *
894 * @param file filename of the test, e.g. argv[0]
895 * @param count peer number
896 * @return configuration name to use
897 */
898char *
899GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, int count);
900
901
902/**
903 * Extracts the plugin anme from an absolute file name and the test name
904 * @param file absolute file name
905 * @param test test name
906 * @return the plugin name
907 */
908char *
909GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *executable,
910 const char *testname);
911
912
913/**
914 * Extracts the filename from an absolute file name and removes the
915 * extenstion
916 *
917 * @param file absolute file name
918 * @return the source name
919 */
920char *
921GNUNET_TRANSPORT_TESTING_get_test_source_name (const char *file);
922
923#endif
924/* end of transport_testing.h */