aboutsummaryrefslogtreecommitdiff
path: root/src/transport/transport-testing2.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/transport-testing2.h')
-rw-r--r--src/transport/transport-testing2.h971
1 files changed, 770 insertions, 201 deletions
diff --git a/src/transport/transport-testing2.h b/src/transport/transport-testing2.h
index 04f75fc88..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,337 +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;
45
46/**
47 * Definition for a transport testing handle
48 */
49struct GNUNET_TRANSPORT_TESTING_Handle;
50
51
52/**
53 * Context for a single peer
54 */
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
168
169/**
170 * Handle for a request to connect two peers.
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
279 *
280 * @param tth transport testing handle
281 */
282void
283GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_Handle *tth);
284
285
286/**
287 * Start a peer with the given configuration
288 *
289 * @param tth the testing handle
290 * @param cfgname configuration file
291 * @param peer_id the peer_id
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
299 */
300struct GNUNET_TRANSPORT_TESTING_PeerContext *
301GNUNET_TRANSPORT_TESTING_start_peer (
302 struct GNUNET_TRANSPORT_TESTING_Handle *tth,
303 const char *cfgname,
304 int peer_id,
305 const struct GNUNET_MQ_MessageHandler *handlers,
306 GNUNET_TRANSPORT_NotifyConnect nc,
307 GNUNET_TRANSPORT_NotifyDisconnect nd,
308 void *cb_cls,
309 GNUNET_SCHEDULER_TaskCallback start_cb,
310 void *start_cb_cls);
311
312
313/**
314 * Shutdown the given peer
315 *
316 * @param p the peer
317 */
318void
319GNUNET_TRANSPORT_TESTING_stop_peer (
320 struct GNUNET_TRANSPORT_TESTING_PeerContext *pc);
321
322
323/**
324 * Stops and restarts the given peer, sleeping (!) for 5s in between.
325 *
326 * @param p the peer
327 * @param restart_cb restart callback
328 * @param restart_cb_cls callback closure
329 * @return #GNUNET_OK in success otherwise #GNUNET_SYSERR
330 */
331int
332GNUNET_TRANSPORT_TESTING_restart_peer (
333 struct GNUNET_TRANSPORT_TESTING_PeerContext *p,
334 GNUNET_SCHEDULER_TaskCallback restart_cb,
335 void *restart_cb_cls);
336
31 337
32/** 338/**
33 * @brief Queue of a communicator and some context 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.
342 *
343 * @param p1 peer 1
344 * @param p2 peer 2
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
34 */ 349 */
35struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue; 350struct GNUNET_TRANSPORT_TESTING_ConnectRequest *
351GNUNET_TRANSPORT_TESTING_connect_peers (
352 struct GNUNET_TRANSPORT_TESTING_PeerContext *p1,
353 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2,
354 GNUNET_SCHEDULER_TaskCallback cb,
355 void *cls);
36 356
37 357
38/** 358/**
39 * @brief Handle/Context to a single transmission 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.
362 *
363 * @param cc a connect request handle
40 */ 364 */
41struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission; 365void
366GNUNET_TRANSPORT_TESTING_connect_peers_cancel (
367 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc);
368
42 369
43/** 370/**
44 * @brief Function signature for callbacks that are called when new 371 * Function called on matching connect requests.
45 * backchannel message arrived
46 * 372 *
47 * @param cls Closure 373 * @param cls closure
48 * @param msg Backchannel message 374 * @param cc request matching the query
49 * @param pid Target peer
50 */ 375 */
51typedef struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle * 376typedef void (*GNUNET_TRANSPORT_TESTING_ConnectContextCallback) (
52(*GNUNET_TRANSPORT_TESTING_BackchannelCallback)(void *cls, 377 void *cls,
53 struct GNUNET_MessageHeader *msg, 378 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc);
54 struct GNUNET_PeerIdentity *pid);
55 379
56 380
57/** 381/**
58 * @brief Function signature for callbacks that are called when new 382 * Find any connecting context matching the given pair of peers.
59 * communicators become available
60 * 383 *
61 * @param cls Closure 384 * @param p1 first peer
62 * @param tc_h Communicator handle 385 * @param p2 second peer
63 * @param cc Characteristics of communicator 386 * @param cb function to call
64 * @param address_prefix Prefix of the address 387 * @param cb_cls closure for @a cb
65 */ 388 */
66typedef void 389void
67(*GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback)(void *cls, 390GNUNET_TRANSPORT_TESTING_find_connecting_context (
68 struct 391 struct GNUNET_TRANSPORT_TESTING_PeerContext *p1,
69 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle 392 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2,
70 *tc_h, 393 GNUNET_TRANSPORT_TESTING_ConnectContextCallback cb,
71 enum 394 void *cb_cls);
72 GNUNET_TRANSPORT_CommunicatorCharacteristics 395
73 cc, 396
74 char *address_prefix); 397/* ********************** high-level process functions *************** */
75 398
76 399
77/** 400/**
78 * @brief Receive information about the address of a communicator. 401 * Function called once the peers have been launched and
402 * connected by #GNUNET_TRANSPORT_TESTING_connect_check().
79 * 403 *
80 * @param cls Closure 404 * @param cls closure
81 * @param tc_h Communicator handle 405 * @param num_peers size of the @a p array
82 * @param address Address represented as string 406 * @param p the peers that were launched
83 * @param expiration Expiration 407 */
84 * @param aid Aid 408typedef void (*GNUNET_TRANSPORT_TESTING_ConnectContinuation) (
85 * @param nt Network Type 409 void *cls,
86 */ 410 unsigned int num_peers,
87typedef void 411 struct GNUNET_TRANSPORT_TESTING_PeerContext *p[]);
88(*GNUNET_TRANSPORT_TESTING_AddAddressCallback)(void *cls, 412
89 struct 413
90 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle 414/**
91 *tc_h, 415 * Internal data structure.
92 const char *address, 416 */
93 struct GNUNET_TIME_Relative 417struct GNUNET_TRANSPORT_TESTING_ConnectRequestList;
94 expiration, 418
95 uint32_t aid, 419/**
96 enum GNUNET_NetworkType nt); 420 * Internal data structure.
97 421 */
98 422struct GNUNET_TRANSPORT_TESTING_InternalPeerContext;
99/** 423
100 * @brief Get informed about the success of a queue request. 424
425GNUNET_NETWORK_STRUCT_BEGIN
426struct GNUNET_TRANSPORT_TESTING_TestMessage
427{
428 /**
429 * Type is (usually) #GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE.
430 */
431 struct GNUNET_MessageHeader header;
432
433 /**
434 * Monotonically increasing counter throughout the test.
435 */
436 uint32_t num GNUNET_PACKED;
437};
438GNUNET_NETWORK_STRUCT_END
439
440
441/**
442 * Function called by the transport for each received message.
101 * 443 *
102 * @param cls Closure 444 * @param cls closure
103 * @param tc_h Communicator handle 445 * @param receiver receiver of the message
104 * @param will_try #GNUNET_YES if communicator will try to create queue 446 * @param sender sender of the message
447 * @param message the message
105 */ 448 */
106typedef void 449typedef void (*GNUNET_TRANSPORT_TESTING_ReceiveCallback) (
107(*GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback)(void *cls, 450 void *cls,
108 struct 451 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
109 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle 452 const struct GNUNET_PeerIdentity *sender,
110 *tc_h, 453 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message);
111 int will_try);
112 454
113 455
114/** 456/**
115 * @brief Handle opening of queue 457 * Function called to notify transport users that another
458 * peer connected to us.
116 * 459 *
117 * @param cls Closure 460 * @param cls closure
118 * @param tc_h Communicator handle 461 * @param me peer experiencing the event
119 * @param tc_queue Handle to newly opened queue 462 * @param other peer that connected to @a me
120 */ 463 */
121typedef void 464typedef void (*GNUNET_TRANSPORT_TESTING_NotifyConnect) (
122(*GNUNET_TRANSPORT_TESTING_AddQueueCallback)(void *cls, 465 void *cls,
123 struct 466 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
124 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle 467 const struct GNUNET_PeerIdentity *other);
125 *tc_h,
126 struct
127 GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue
128 *tc_queue,
129 size_t mtu);
130 468
131 469
132/** 470/**
133 * @brief Handle an incoming message 471 * Function called to notify transport users that another
472 * peer disconnected from us.
134 * 473 *
135 * @param cls Closure 474 * @param cls closure
136 * @param tc_h Handle to the receiving communicator 475 * @param me peer experiencing the event
137 * @param msg Received message 476 * @param other peer that disconnected from @a me
138 */ 477 */
139typedef void 478typedef void (*GNUNET_TRANSPORT_TESTING_NotifyDisconnect) (
140(*GNUNET_TRANSPORT_TESTING_IncomingMessageCallback)(void *cls, 479 void *cls,
141 struct 480 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
142 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle 481 const struct GNUNET_PeerIdentity *other);
143 *tc_h, 482
144 const char*payload,
145 size_t payload_len);
146 483
147/** 484/**
148 * @brief Handle to a transport communicator 485 * Closure that must be passed to
486 * #GNUNET_TRANSPORT_TESTING_connect_check.
149 */ 487 */
150struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle 488struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext
151{ 489{
152 /** 490 /**
153 * Clients 491 * How should we continue after the connect?
154 */ 492 */
155 struct MyClient *client_head; 493 GNUNET_SCHEDULER_TaskCallback connect_continuation;
156 struct MyClient *client_tail;
157 494
158 /** 495 /**
159 * @brief Handle to the client 496 * Closure for @e connect_continuation.
160 */ 497 */
161 struct GNUNET_MQ_Handle *c_mq; 498 void *connect_continuation_cls;
162 499
163 /** 500 /**
164 * @brief Handle to the configuration 501 * Which configuration file should we pass to the
165 */ 502 * #GNUNET_PROGRAM_run() of the testcase?
166 struct GNUNET_CONFIGURATION_Handle *cfg; 503 */
504 const char *config_file;
167 505
168 /** 506 /**
169 * @brief File name of configuration file 507 * Receiver argument to give for peers we start.
170 */ 508 */
171 char *cfg_filename; 509 GNUNET_TRANSPORT_TESTING_ReceiveCallback rec;
172 510
173 struct GNUNET_PeerIdentity peer_id; 511 /**
512 * Notify connect argument to give for peers we start.
513 */
514 GNUNET_TRANSPORT_TESTING_NotifyConnect nc;
174 515
175 /** 516 /**
176 * @brief Handle to the transport service 517 * Notify disconnect argument to give for peers we start.
177 */ 518 */
178 struct GNUNET_SERVICE_Handle *tsh; 519 GNUNET_TRANSPORT_TESTING_NotifyDisconnect nd;
179 520
180 /** 521 /**
181 * @brief Task that will be run on shutdown to stop and clean transport 522 * Closure for @e rec, @e nc and @e nd.
182 * service
183 */ 523 */
184 struct GNUNET_SCHEDULER_Task *ts_shutdown_task; 524 void *cls;
185 525
526 /**
527 * Custom task to run on shutdown.
528 */
529 GNUNET_SCHEDULER_TaskCallback shutdown_task;
530
531 /**
532 * Closure for @e shutdown_task.
533 */
534 void *shutdown_task_cls;
186 535
187 /** 536 /**
188 * @brief Process of the communicator 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.
189 */ 541 */
190 struct GNUNET_OS_Process *c_proc; 542 GNUNET_SCHEDULER_TaskCallback pre_connect_task;
191 543
192 /** 544 /**
193 * NAT process 545 * Closure for @e shutdown_task.
194 */ 546 */
195 struct GNUNET_OS_Process *nat_proc; 547 void *pre_connect_task_cls;
196 548
197 /** 549 /**
198 * resolver service process 550 * When should the testcase time out?
199 */ 551 */
200 struct GNUNET_OS_Process *resolver_proc; 552 struct GNUNET_TIME_Relative timeout;
201 553
202 /** 554 /**
203 * peerstore service process 555 * Should we try to create connections in both directions?
204 */ 556 */
205 struct GNUNET_OS_Process *ps_proc; 557 int bi_directional;
558
559 /* ******* fields set by #GNUNET_TRANSPORT_TESTING_connect_check **** */
206 560
207 /** 561 /**
208 * @brief Task that will be run on shutdown to stop and clean communicator 562 * Number of peers involved in the test.
209 */ 563 */
210 struct GNUNET_SCHEDULER_Task *c_shutdown_task; 564 unsigned int num_peers;
211 565
212 /** 566 /**
213 * @brief Characteristics of the communicator 567 * Configuration files we have, array with @e num_peers entries.
214 */ 568 */
215 enum GNUNET_TRANSPORT_CommunicatorCharacteristics c_characteristics; 569 char **cfg_files;
216 570
217 /** 571 /**
218 * @brief Specifies supported addresses 572 * Array with @e num_peers entries.
219 */ 573 */
220 char *c_addr_prefix; 574 struct GNUNET_TRANSPORT_TESTING_PeerContext **p;
221 575
222 /** 576 /**
223 * @brief Specifies supported addresses 577 * Name of the plugin.
224 */ 578 */
225 char *c_address; 579 const char *test_plugin;
226 580
227 /** 581 /**
228 * @brief Head of the DLL of queues associated with this communicator 582 * Name of the testcase.
229 */ 583 */
230 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *queue_head; 584 const char *test_name;
231 585
232 /** 586 /**
233 * @brief Tail of the DLL of queues associated with this communicator 587 * Configuration object for the testcase.
234 */ 588 */
235 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *queue_tail; 589 const struct GNUNET_CONFIGURATION_Handle *cfg;
236 590
237 /* Callbacks + Closures */
238 /** 591 /**
239 * @brief Callback called when a new communicator connects 592 * Main testing handle.
240 */ 593 */
241 GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback 594 struct GNUNET_TRANSPORT_TESTING_Handle *tth;
242 communicator_available_cb;
243 595
244 /** 596 /**
245 * @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.
246 */ 599 */
247 GNUNET_TRANSPORT_TESTING_AddAddressCallback add_address_cb; 600 int global_ret;
248 601
249 /** 602 /**
250 * @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.
251 */ 607 */
252 GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback queue_create_reply_cb; 608 uint32_t send_num_gen;
609
610 /* ******* internal state, clients should not mess with this **** */
253 611
254 /** 612 /**
255 * @brief Callback called when a new communicator connects 613 * Task run on timeout.
256 */ 614 */
257 GNUNET_TRANSPORT_TESTING_AddQueueCallback add_queue_cb; 615 struct GNUNET_SCHEDULER_Task *timeout_task;
258 616
259 /** 617 /**
260 * @brief Callback called when a new communicator connects 618 * Task run to connect peers.
261 */ 619 */
262 GNUNET_TRANSPORT_TESTING_IncomingMessageCallback incoming_msg_cb; 620 struct GNUNET_SCHEDULER_Task *connect_task;
263 621
264 /** 622 /**
265 * @brief Backchannel callback 623 * Number of peers that have been started.
266 */ 624 */
267 GNUNET_TRANSPORT_TESTING_BackchannelCallback bc_cb; 625 unsigned int started;
268 626
269 /** 627 /**
270 * Our service handle 628 * DLL of active connect requests.
271 */ 629 */
272 struct GNUNET_SERVICE_Handle *sh; 630 struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl_head;
273 631
274 /** 632 /**
275 * @brief Closure to the callback 633 * DLL of active connect requests.
276 */ 634 */
277 void *cb_cls; 635 struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl_tail;
278 636
279 /** 637 /**
280 * Backchannel supported 638 * Array with @e num_peers entries.
281 */ 639 */
282 int bc_enabled; 640 struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ip;
283}; 641};
284 642
643
285/** 644/**
286 * @brief Start communicator part of transport service and communicator 645 * Find peer by peer ID.
287 * 646 *
288 * @param service_name Name of the service 647 * @param ccc context to search
289 * @param cfg Configuration handle 648 * @param peer peer to look for
290 * @param communicator_available Callback that is called when a new 649 * @return NULL if @a peer was not found
291 * communicator becomes available 650 */
292 * @param add_address_cb Callback handling new addresses 651struct GNUNET_TRANSPORT_TESTING_PeerContext *
293 * @param queue_create_reply_cb Callback handling success of queue requests 652GNUNET_TRANSPORT_TESTING_find_peer (
294 * @param add_queue_cb Callback handling freshly created queues 653 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc,
295 * @param incoming_message_cb Callback handling incoming messages 654 const struct GNUNET_PeerIdentity *peer);
296 * @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.
297 * 663 *
298 * @return Handle to the communicator duo 664 * @param cls closure of type `struct
299 */ 665 * GNUNET_TRANSPORT_TESTING_ConnectCheckContext`
300struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle * 666 * @param tth_ initialized testing handle
301GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( 667 * @param test_plugin_ name of the plugin
302 const char *service_name, 668 * @param test_name_ name of the test
303 const char *binary_name, 669 * @param num_peers number of entries in the @a cfg_file array
304 const char *cfg_filename, 670 * @param cfg_files array of names of configuration files for the peers
305 const struct GNUNET_PeerIdentity *peer_id, 671 * @return #GNUNET_SYSERR on error
306 GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback 672 */
307 communicator_available_cb, 673int
308 GNUNET_TRANSPORT_TESTING_AddAddressCallback add_address_cb, 674GNUNET_TRANSPORT_TESTING_connect_check (
309 GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback queue_create_reply_cb, 675 void *cls,
310 GNUNET_TRANSPORT_TESTING_AddQueueCallback add_queue_cb, 676 struct GNUNET_TRANSPORT_TESTING_Handle *tth_,
311 GNUNET_TRANSPORT_TESTING_IncomingMessageCallback incoming_message_cb, 677 const char *test_plugin_,
312 GNUNET_TRANSPORT_TESTING_BackchannelCallback bc_cb, 678 const char *test_name_,
313 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
776
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};
314 813
315 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 */
316void 823void
317GNUNET_TRANSPORT_TESTING_transport_communicator_service_stop ( 824GNUNET_TRANSPORT_TESTING_simple_send (void *cls);
318 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h);
319 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
320 832
321/** 833/**
322 * @brief Instruct communicator to open a queue 834 * Task that sends a large test message from the
835 * first peer to the second peer.
323 * 836 *
324 * @param tc_h Handle to communicator which shall open queue 837 * @param cls the `struct GNUNET_TRANSPORT_TESTING_SendClosure`
325 * @param peer_id Towards which peer 838 * which should contain at least two peers, the first two
326 * @param address For which address 839 * of which should be currently connected
327 */ 840 */
328void 841void
329GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue (struct 842GNUNET_TRANSPORT_TESTING_large_send (void *cls);
330 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle 843
331 *tc_h, 844
332 const struct 845/* ********************** log-only convenience functions ************* */
333 GNUNET_PeerIdentity
334 *peer_id,
335 const char *address);
336 846
337 847
338/** 848/**
339 * @brief Instruct communicator to send data 849 * Log a connect event.
340 * 850 *
341 * @param tc_queue The queue to use for sending 851 * @param cls NULL
342 * @param cont function to call when done sending 852 * @param me peer that had the event
343 * @param cont_cls closure for @a cont 853 * @param other peer that connected.
344 * @param payload Data to send
345 * @param payload_size Size of the @a payload
346 */ 854 */
347void 855void
348GNUNET_TRANSPORT_TESTING_transport_communicator_send (struct 856GNUNET_TRANSPORT_TESTING_log_connect (
349 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle 857 void *cls,
350 *tc_h, 858 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
351 GNUNET_SCHEDULER_TaskCallback 859 const struct GNUNET_PeerIdentity *other);
352 cont, 860
353 void *cont_cls, 861
354 const void *payload, 862/**
355 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 */