aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-09-05 10:50:56 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-09-05 10:50:56 +0000
commit270a6392703fe1cb99f69ed8a35c1be0c864b11f (patch)
tree1c65d01fefab939684c58757880987d2a00fd060
parentc09edda8e8071c6e5ca6b76e7c75a7b8402010ed (diff)
downloadgnunet-270a6392703fe1cb99f69ed8a35c1be0c864b11f.tar.gz
gnunet-270a6392703fe1cb99f69ed8a35c1be0c864b11f.zip
changed testbed API to include convenience callbacks
-rw-r--r--src/include/gnunet_testbed_service-new.h1268
-rw-r--r--src/include/gnunet_testbed_service.h120
-rw-r--r--src/testbed/test_testbed_api.c95
-rw-r--r--src/testbed/test_testbed_api_2peers.c37
-rw-r--r--src/testbed/test_testbed_api_controllerlink.c4
-rw-r--r--src/testbed/test_testbed_api_test.c64
-rw-r--r--src/testbed/testbed_api.c63
-rw-r--r--src/testbed/testbed_api_peers.c33
-rw-r--r--src/testbed/testbed_api_peers.h42
-rw-r--r--src/testbed/testbed_api_services.c43
10 files changed, 325 insertions, 1444 deletions
diff --git a/src/include/gnunet_testbed_service-new.h b/src/include/gnunet_testbed_service-new.h
deleted file mode 100644
index 75f7a0ab2..000000000
--- a/src/include/gnunet_testbed_service-new.h
+++ /dev/null
@@ -1,1268 +0,0 @@
1/*
2 This file is part of GNUnet
3 (C) 2008, 2009, 2012 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19 */
20
21/**
22 * @file include/gnunet_testbed_service.h
23 * @brief API for writing tests and creating large-scale
24 * emulation testbeds for GNUnet.
25 * @author Christian Grothoff
26 */
27
28#ifndef GNUNET_TESTBED_SERVICE_H
29#define GNUNET_TESTBED_SERVICE_H
30
31#include "gnunet_util_lib.h"
32#include "gnunet_testing_lib-new.h"
33
34#ifdef __cplusplus
35extern "C"
36{
37#if 0 /* keep Emacsens' auto-indent happy */
38}
39#endif
40#endif
41
42
43/**
44 * Opaque handle to a host running experiments managed by the testbed framework.
45 * The master process must be able to SSH to this host without password (via
46 * ssh-agent).
47 */
48struct GNUNET_TESTBED_Host;
49
50/**
51 * Opaque handle to a peer controlled by the testbed framework. A peer runs
52 * at a particular host.
53 */
54struct GNUNET_TESTBED_Peer;
55
56/**
57 * Opaque handle to an abstract operation to be executed by the testbed framework.
58 */
59struct GNUNET_TESTBED_Operation;
60
61/**
62 * Handle to interact with a GNUnet testbed controller. Each
63 * controller has at least one master handle which is created when the
64 * controller is created; this master handle interacts with the
65 * controller process, destroying it destroys the controller (by
66 * closing stdin of the controller process). Additionally,
67 * controllers can interact with each other (in a P2P fashion); those
68 * links are established via TCP/IP on the controller's service port.
69 */
70struct GNUNET_TESTBED_Controller;
71
72/**
73 * Handle to a large-scale testbed that is managed at a high level.
74 */
75struct GNUNET_TESTBED_Testbed;
76
77
78/**
79 * Create a host to run peers and controllers on.
80 *
81 * @param hostname name of the host, use "NULL" for localhost
82 * @param username username to use for the login; may be NULL
83 * @param port port number to use for ssh; use 0 to let ssh decide
84 * @return handle to the host, NULL on error
85 */
86struct GNUNET_TESTBED_Host *
87GNUNET_TESTBED_host_create (const char *hostname,
88 const char *username,
89 uint16_t port);
90
91
92
93/**
94 * Create a host to run peers and controllers on. This function is used
95 * if a peer learns about a host via IPC between controllers (and thus
96 * some higher-level controller has already determined the unique IDs).
97 *
98 * @param id global host ID assigned to the host; 0 is
99 * reserved to always mean 'localhost'
100 * @param hostname name of the host, use "NULL" for localhost
101 * @param username username to use for the login; may be NULL
102 * @param port port number to use for ssh; use 0 to let ssh decide
103 * @return handle to the host, NULL on error
104 */
105struct GNUNET_TESTBED_Host *
106GNUNET_TESTBED_host_create_with_id (uint32_t id,
107 const char *hostname,
108 const char *username,
109 uint16_t port);
110
111
112/**
113 * Load a set of hosts from a configuration file.
114 *
115 * @param filename file with the host specification
116 * @param hosts set to the hosts found in the file
117 * @return number of hosts returned in 'hosts', 0 on error
118 */
119unsigned int
120GNUNET_TESTBED_hosts_load_from_file (const char *filename,
121 struct GNUNET_TESTBED_Host **hosts);
122
123
124/**
125 * Destroy a host handle. Must only be called once everything
126 * running on that host has been stopped.
127 *
128 * @param host handle to destroy
129 */
130void
131GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host);
132
133
134/**
135 * Enumeration with (at most 64) possible event types that
136 * can be monitored using the testbed framework.
137 */
138enum GNUNET_TESTBED_EventType
139{
140 /**
141 * A peer has been started.
142 */
143 GNUNET_TESTBED_ET_PEER_START = 0,
144
145 /**
146 * A peer has been stopped.
147 */
148 GNUNET_TESTBED_ET_PEER_STOP = 1,
149
150 /**
151 * A connection between two peers was established.
152 */
153 GNUNET_TESTBED_ET_CONNECT = 2,
154
155 /**
156 * A connection between two peers was torn down.
157 */
158 GNUNET_TESTBED_ET_DISCONNECT = 3,
159
160 /**
161 * A requested testbed operation has been completed.
162 */
163 GNUNET_TESTBED_ET_OPERATION_FINISHED = 4,
164
165 /**
166 * The 'GNUNET_TESTBED_run' operation has been completed
167 */
168 GNUNET_TESTBED_ET_TESTBED_ONLINE = 5
169
170};
171
172
173/**
174 * Types of information that can be requested about a peer.
175 */
176enum GNUNET_TESTBED_PeerInformationType
177{
178
179 /**
180 * Special value (not valid for requesting information)
181 * that is used in the event struct if a 'generic' pointer
182 * is returned (for other operations not related to this
183 * enumeration).
184 */
185 GNUNET_TESTBED_PIT_GENERIC = 0,
186
187 /**
188 * What configuration is the peer using? Returns a 'const struct
189 * GNUNET_CONFIGURATION_Handle *'. Valid until
190 * 'GNUNET_TESTNIG_operation_done' is called. However, the
191 * values may be inaccurate if the peer is reconfigured in
192 * the meantime.
193 */
194 GNUNET_TESTBED_PIT_CONFIGURATION,
195
196 /**
197 * What is the identity of the peer? Returns a
198 * 'const struct GNUNET_PeerIdentity *'. Valid until
199 * 'GNUNET_TESTNIG_operation_done' is called.
200 */
201 GNUNET_TESTBED_PIT_IDENTITY
202
203};
204
205
206/**
207 * Argument to GNUNET_TESTBED_ControllerCallback with details about
208 * the event.
209 */
210struct GNUNET_TESTBED_EventInformation
211{
212
213 /**
214 * Type of the event.
215 */
216 enum GNUNET_TESTBED_EventType type;
217
218 /**
219 * Details about the event.
220 */
221 union
222 {
223
224 /**
225 * Details about peer start event.
226 */
227 struct
228 {
229 /**
230 * Handle for the host where the peer
231 * was started.
232 */
233 struct GNUNET_TESTBED_Host *host;
234
235 /**
236 * Handle for the peer that was started.
237 */
238 struct GNUNET_TESTBED_Peer *peer;
239
240 } peer_start;
241
242 /**
243 * Details about peer stop event.
244 */
245 struct
246 {
247
248 /**
249 * Handle for the peer that was started.
250 */
251 struct GNUNET_TESTBED_Peer *peer;
252
253 } peer_stop;
254
255 /**
256 * Details about connect event.
257 */
258 struct
259 {
260 /**
261 * Handle for one of the connected peers.
262 */
263 struct GNUNET_TESTBED_Peer *peer1;
264
265 /**
266 * Handle for one of the connected peers.
267 */
268 struct GNUNET_TESTBED_Peer *peer2;
269
270 } peer_connect;
271
272 /**
273 * Details about disconnect event.
274 */
275 struct
276 {
277 /**
278 * Handle for one of the disconnected peers.
279 */
280 struct GNUNET_TESTBED_Peer *peer1;
281
282 /**
283 * Handle for one of the disconnected peers.
284 */
285 struct GNUNET_TESTBED_Peer *peer2;
286
287 } peer_disconnect;
288
289 /**
290 * Details about an operation finished event.
291 */
292 struct
293 {
294
295 /**
296 * Handle for the operation that was finished.
297 */
298 struct GNUNET_TESTBED_Operation *operation;
299
300 /**
301 * Closure that was passed in when the event was
302 * requested.
303 */
304 void *op_cls;
305
306 /**
307 * Error message for the operation, NULL on success.
308 */
309 const char *emsg;
310
311 /**
312 * No result (NULL pointer) or generic result
313 * (whatever the GNUNET_TESTBED_ConnectAdapter returned).
314 */
315 void *generic;
316
317 } operation_finished;
318
319
320 /**
321 * Details about an testbed run completed event.
322 */
323 struct
324 {
325
326 /**
327 * Error message for the operation, NULL on success.
328 */
329 const char *emsg;
330
331 /**
332 * Array of peers now running (valid until
333 * 'GNUNET_TESTBED_testbed_stop' is called). Note that it is
334 * not allowed to call 'GNUNET_TESTBED_peer_destroy' on peers
335 * from this array.
336 */
337 struct GNUNET_TESTBED_Peer **peers;
338
339 /**
340 * Size of the 'peers' array.
341 */
342 unsigned int num_peers;
343
344 } testbed_run_finished;
345
346 } details;
347
348};
349
350
351/**
352 * Signature of the event handler function called by the
353 * respective event controller.
354 *
355 * @param cls closure
356 * @param event information about the event
357 */
358typedef void (*GNUNET_TESTBED_ControllerCallback)(void *cls,
359 const struct GNUNET_TESTBED_EventInformation *event);
360
361
362/**
363 * Opaque Handle for Controller process
364 */
365struct GNUNET_TESTBED_ControllerProc;
366
367
368/**
369 * Callback to signal successfull startup of the controller process
370 *
371 * @param cls the closure from GNUNET_TESTBED_controller_start()
372 * @param cfg the configuration with which the controller has been started;
373 * NULL if status is not GNUNET_OK
374 * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
375 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
376 */
377typedef void (*GNUNET_TESTBED_ControllerStatusCallback) (void *cls,
378 const struct GNUNET_CONFIGURATION_Handle *cfg,
379 int status);
380
381
382/**
383 * Starts a controller process at the host. FIXME: add controller start callback
384 * with the configuration with which the controller is started
385 *
386 * @param controller_ip the ip address of the controller. Will be set as TRUSTED
387 * host when starting testbed controller at host
388 * @param host the host where the controller has to be started; NULL for
389 * localhost
390 * @param cfg template configuration to use for the remote controller; the
391 * remote controller will be started with a slightly modified
392 * configuration (port numbers, unix domain sockets and service home
393 * values are changed as per TESTING library on the remote host)
394 * @param cb function called when the controller is successfully started or
395 * dies unexpectedly; GNUNET_TESTBED_controller_stop shouldn't be
396 * called if cb is called with GNUNET_SYSERR as status. Will never be
397 * called in the same task as 'GNUNET_TESTBED_controller_start'
398 * (synchronous errors will be signalled by returning NULL). This
399 * parameter cannot be NULL.
400 * @param cls closure for above callbacks
401 * @return the controller process handle, NULL on errors
402 */
403struct GNUNET_TESTBED_ControllerProc *
404GNUNET_TESTBED_controller_start (const char *controller_ip,
405 struct GNUNET_TESTBED_Host *host,
406 const struct GNUNET_CONFIGURATION_Handle *cfg,
407 GNUNET_TESTBED_ControllerStatusCallback cb,
408 void *cls);
409
410
411/**
412 * Stop the controller process (also will terminate all peers and controllers
413 * dependent on this controller). This function blocks until the testbed has
414 * been fully terminated (!).
415 *
416 * @param cproc the controller process handle
417 */
418void
419GNUNET_TESTBED_controller_stop (struct GNUNET_TESTBED_ControllerProc *cproc);
420
421
422/**
423 * Connect to a controller process using the given configuration at the
424 * given host.
425 *
426 * @param cfg configuration to use
427 * @param host host to run the controller on; This should be the same host if
428 * the controller was previously started with
429 * GNUNET_TESTBED_controller_start; NULL for localhost
430 * @param host host where this controller is being run;
431 * @param event_mask bit mask with set of events to call 'cc' for;
432 * or-ed values of "1LL" shifted by the
433 * respective 'enum GNUNET_TESTBED_EventType'
434 * (i.e. "(1LL << GNUNET_TESTBED_ET_CONNECT) | ...")
435 * @param cc controller callback to invoke on events
436 * @param cc_cls closure for cc
437 * @return handle to the controller
438 */
439struct GNUNET_TESTBED_Controller *
440GNUNET_TESTBED_controller_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
441 struct GNUNET_TESTBED_Host *host,
442 uint64_t event_mask,
443 GNUNET_TESTBED_ControllerCallback cc,
444 void *cc_cls);
445
446
447/**
448 * Configure shared services at a controller. Using this function,
449 * you can specify that certain services (such as "resolver")
450 * should not be run for each peer but instead be shared
451 * across N peers on the specified host. This function
452 * must be called before any peers are created at the host.
453 *
454 * @param controller controller to configure
455 * @param service_name name of the service to share
456 * @param num_peers number of peers that should share one instance
457 * of the specified service (1 for no sharing is the default),
458 * use 0 to disable the service
459 */
460void
461GNUNET_TESTBED_controller_configure_sharing (struct GNUNET_TESTBED_Controller *controller,
462 const char *service_name,
463 uint32_t num_peers);
464
465
466/**
467 * Stop the given controller (also will terminate all peers and
468 * controllers dependent on this controller). This function
469 * blocks until the testbed has been fully terminated (!).
470 *
471 * @param controller handle to controller to stop
472 */
473void
474GNUNET_TESTBED_controller_disconnect (struct GNUNET_TESTBED_Controller *controller);
475
476
477/**
478 * Opaque handle for host registration
479 */
480struct GNUNET_TESTBED_HostRegistrationHandle;
481
482
483/**
484 * Callback which will be called to after a host registration succeeded or failed
485 *
486 * @param cls the closure
487 * @param emsg the error message; NULL if host registration is successful
488 */
489typedef void (* GNUNET_TESTBED_HostRegistrationCompletion) (void *cls,
490 const char *emsg);
491
492
493/**
494 * Register a host with the controller
495 *
496 * @param controller the controller handle
497 * @param host the host to register
498 * @param cc the completion callback to call to inform the status of
499 * registration. After calling this callback the registration handle
500 * will be invalid. Cannot be NULL
501 * @param cc_cls the closure for the cc
502 * @return handle to the host registration which can be used to cancel the
503 * registration; NULL if another registration handle is present and
504 * is not cancelled
505 */
506struct GNUNET_TESTBED_HostRegistrationHandle *
507GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller,
508 struct GNUNET_TESTBED_Host *host,
509 GNUNET_TESTBED_HostRegistrationCompletion cc,
510 void *cc_cls);
511
512
513/**
514 * Cancel the pending registration. Note that the registration message will
515 * already be queued to be sent to the service, cancellation has only the
516 * effect that the registration completion callback for the registration is
517 * never called and from our perspective the host is not registered until the
518 * completion callback is called.
519 *
520 * @param handle the registration handle to cancel
521 */
522void
523GNUNET_TESTBED_cancel_registration (struct GNUNET_TESTBED_HostRegistrationHandle
524 *handle);
525
526
527/**
528 * Create a link from slave controller to delegated controller. Whenever the
529 * master controller is asked to start a peer at the delegated controller the
530 * request will be routed towards slave controller (if a route exists). The
531 * slave controller will then route it to the delegated controller. The
532 * configuration of the slave controller is given and to be used to either
533 * create the slave controller or to connect to an existing slave controller
534 * process. 'is_subordinate' specifies if the given slave controller should be
535 * started and managed by the master controller, or if the slave already has a
536 * master and this is just a secondary master that is also allowed to use the
537 * existing slave.
538 *
539 * @param master handle to the master controller who creates the association
540 * @param delegated_host requests to which host should be delegated; cannot be NULL
541 * @param slave_host which host is used to run the slave controller; use NULL to
542 * make the master controller connect to the delegated host
543 * @param slave_cfg configuration to use for the slave controller
544 * @param is_subordinate GNUNET_YES if the controller at delegated_host should
545 * be started by the master controller; GNUNET_NO if we are just
546 * allowed to use the slave via TCP/IP
547 * @return the operation handle
548 */
549struct GNUNET_TESTBED_Operation *
550GNUNET_TESTBED_controller_link (struct GNUNET_TESTBED_Controller *master,
551 struct GNUNET_TESTBED_Host *delegated_host,
552 struct GNUNET_TESTBED_Host *slave_host,
553 const struct GNUNET_CONFIGURATION_Handle *slave_cfg,
554 int is_subordinate);
555
556
557/**
558 * Same as the GNUNET_TESTBED_controller_link, however expects configuration in
559 * serialized and compressed
560 *
561 * @param master handle to the master controller who creates the association
562 * @param delegated_host requests to which host should be delegated; cannot be NULL
563 * @param slave_host which host is used to run the slave controller; use NULL to
564 * make the master controller connect to the delegated host
565 * @param sxcfg serialized and compressed configuration
566 * @param sxcfg_size the size scfg
567 * @param scfg_size the size of uncompressed serialized configuration
568 * @param is_subordinate GNUNET_YES if the controller at delegated_host should
569 * be started by the master controller; GNUNET_NO if we are just
570 * allowed to use the slave via TCP/IP
571 * @return the operation handle
572 */
573struct GNUNET_TESTBED_Operation *
574GNUNET_TESTBED_controller_link_2 (struct GNUNET_TESTBED_Controller *master,
575 struct GNUNET_TESTBED_Host *delegated_host,
576 struct GNUNET_TESTBED_Host *slave_host,
577 const char *sxcfg,
578 size_t sxcfg_size,
579 size_t scfg_size,
580 int is_subordinate);
581
582
583/**
584 * Functions of this signature are called when a peer has been successfully
585 * created
586 *
587 * @param cls the closure from GNUNET_TESTBED_peer_create()
588 * @param peer the handle for the created peer; NULL on any error during
589 * creation
590 * @param emsg NULL if peer is not NULL; else MAY contain the error description
591 */
592typedef void (*GNUNET_TESTBED_PeerCreateCallback) (void *cls,
593 struct GNUNET_TESTBED_Peer *peer,
594 const char *emsg);
595
596
597/**
598 * Create the given peer at the specified host using the given
599 * controller. If the given controller is not running on the target
600 * host, it should find or create a controller at the target host and
601 * delegate creating the peer. Explicit delegation paths can be setup
602 * using 'GNUNET_TESTBED_controller_link'. If no explicit delegation
603 * path exists, a direct link with a subordinate controller is setup
604 * for the first delegated peer to a particular host; the subordinate
605 * controller is then destroyed once the last peer that was delegated
606 * to the remote host is stopped.
607 *
608 * Creating the peer only creates the handle to manipulate and further
609 * configure the peer; use "GNUNET_TESTBED_peer_start" and
610 * "GNUNET_TESTBED_peer_stop" to actually start/stop the peer's
611 * processes.
612 *
613 * Note that the given configuration will be adjusted by the
614 * controller to avoid port/path conflicts with other peers.
615 * The "final" configuration can be obtained using
616 * 'GNUNET_TESTBED_peer_get_information'.
617 *
618 * @param controller controller process to use
619 * @param host host to run the peer on
620 * @param cfg Template configuration to use for the peer. Should exist until
621 * operation is cancelled or GNUNET_TESTBED_operation_done() is called
622 * @param cb the callback to call when the peer has been created
623 * @param cls the closure to the above callback
624 * @return the operation handle
625 */
626struct GNUNET_TESTBED_Operation *
627GNUNET_TESTBED_peer_create (struct GNUNET_TESTBED_Controller *controller,
628 struct GNUNET_TESTBED_Host *host,
629 const struct GNUNET_CONFIGURATION_Handle *cfg,
630 GNUNET_TESTBED_PeerCreateCallback cb,
631 void *cls);
632
633
634/**
635 * Start the given peer.
636 *
637 * @param peer peer to start
638 * @return handle to the operation
639 */
640struct GNUNET_TESTBED_Operation *
641GNUNET_TESTBED_peer_start (struct GNUNET_TESTBED_Peer *peer);
642
643
644/**
645 * Stop the given peer. The handle remains valid (use
646 * "GNUNET_TESTBED_peer_destroy" to fully clean up the
647 * state of the peer).
648 *
649 * @param peer peer to stop
650 * @return handle to the operation
651 */
652struct GNUNET_TESTBED_Operation *
653GNUNET_TESTBED_peer_stop (struct GNUNET_TESTBED_Peer *peer);
654
655
656/**
657 * Data returned from GNUNET_TESTBED_peer_get_information
658 */
659struct GNUNET_TESTBED_PeerInformation
660{
661 /**
662 * Peer information type; captures which of the types
663 * in the 'op_result' is actually in use.
664 */
665 enum GNUNET_TESTBED_PeerInformationType pit;
666
667 /**
668 * The result of the get information operation; Choose according to the pit
669 */
670 union
671 {
672 /**
673 * The configuration of the peer
674 */
675 struct GNUNET_CONFIGURATION_Handle *cfg;
676
677 /**
678 * The identity of the peer
679 */
680 struct GNUNET_PeerIdentity *id;
681
682 /**
683 * The host where the peer is running
684 */
685 struct GNUNET_TESTBED_Host *host;
686 } result;
687};
688
689
690/**
691 * Callback to be called when the requested peer information is available
692 *
693 * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information()
694 * @return
695 */
696typedef void (*GNUNET_TESTBED_PICallback) (void *cb_cls,
697 const struct
698 GNUNET_TESTBED_PeerInformation *pit);
699
700
701
702/**
703 * Request information about a peer. The controller callback will be called with
704 * event type GNUNET_TESTBED_ET_OPERATION_FINISHED when result for this
705 * operation is available
706 *
707 * @param op_cls the closure for the operation
708 * @param peer peer to request information about
709 * @param pit desired information
710 * @param cb the convenience callback to be called when results for this
711 * operation are available
712 * @param cb_cls the closure for the above callback
713 * @return handle to the operation
714 */
715struct GNUNET_TESTBED_Operation *
716GNUNET_TESTBED_peer_get_information (void *op_cls,
717 struct GNUNET_TESTBED_Peer *peer,
718 enum GNUNET_TESTBED_PeerInformationType
719 pit,
720 GNUNET_TESTBED_PICallback cb,
721 void *cb_cls);
722
723
724/**
725 * Change peer configuration. Must only be called while the
726 * peer is stopped. Ports and paths cannot be changed this
727 * way.
728 *
729 * @param peer peer to change configuration for
730 * @param cfg new configuration (differences to existing
731 * configuration only)
732 * @return handle to the operation
733 */
734struct GNUNET_TESTBED_Operation *
735GNUNET_TESTBED_peer_update_configuration (struct GNUNET_TESTBED_Peer *peer,
736 const struct GNUNET_CONFIGURATION_Handle *cfg);
737
738
739/**
740 * Destroy the given peer; the peer should have been
741 * stopped first (if it was started).
742 *
743 * @param peer peer to stop
744 * @return handle to the operation
745 */
746struct GNUNET_TESTBED_Operation *
747GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer);
748
749
750/**
751 * Options for peer connections.
752 */
753enum GNUNET_TESTBED_ConnectOption
754{
755 /**
756 * No option (not valid as an argument).
757 */
758 GNUNET_TESTBED_CO_NONE = 0,
759
760 /**
761 * Allow or disallow a connection between the specified peers.
762 * Followed by GNUNET_NO (int) if a connection is disallowed
763 * or GNUNET_YES if a connection is allowed. Note that the
764 * default (all connections allowed or disallowed) is
765 * specified in the configuration of the controller.
766 */
767 GNUNET_TESTBED_CO_ALLOW = 1,
768
769 /**
770 * FIXME: add (and implement) options to limit connection to
771 * particular transports, force simulation of particular latencies
772 * or message loss rates, or set bandwidth limitations.
773 */
774
775};
776
777
778/**
779 * Manipulate the P2P underlay topology by configuring a link
780 * between two peers.
781 *
782 * @param op_cls closure argument to give with the operation event
783 * @param p1 first peer
784 * @param p2 second peer
785 * @param co option to change
786 * @param ap option-specific values
787 * @return handle to the operation, NULL if configuring the link at this
788 * time is not allowed
789 */
790struct GNUNET_TESTBED_Operation *
791GNUNET_TESTBED_underlay_configure_link_va (void *op_cls,
792 struct GNUNET_TESTBED_Peer *p1,
793 struct GNUNET_TESTBED_Peer *p2,
794 enum GNUNET_TESTBED_ConnectOption co,
795 va_list ap);
796
797
798/**
799 * Manipulate the P2P underlay topology by configuring a link
800 * between two peers.
801 *
802 * @param op_cls closure argument to give with the operation event
803 * @param p1 first peer
804 * @param p2 second peer
805 * @param co option to change
806 * @param ... option-specific values
807 * @return handle to the operation, NULL if configuring the link at this
808 * time is not allowed
809 */
810struct GNUNET_TESTBED_Operation *
811GNUNET_TESTBED_underlay_configure_link (void *op_cls,
812 struct GNUNET_TESTBED_Peer *p1,
813 struct GNUNET_TESTBED_Peer *p2,
814 enum GNUNET_TESTBED_ConnectOption co, ...);
815
816
817
818/**
819 * Topologies supported for testbeds.
820 */
821enum GNUNET_TESTBED_TopologyOption
822{
823 /**
824 * A clique (everyone connected to everyone else). No options.
825 */
826 GNUNET_TESTBED_TOPOLOGY_CLIQUE,
827
828 /**
829 * Small-world network (2d torus plus random links). Followed
830 * by the number of random links to add (unsigned int).
831 */
832 GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD,
833
834 /**
835 * Small-world network (ring plus random links). Followed
836 * by the number of random links to add (unsigned int).
837 */
838 GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING,
839
840 /**
841 * Ring topology. No options.
842 */
843 GNUNET_TESTBED_TOPOLOGY_RING,
844
845 /**
846 * 2-d torus. No options.
847 */
848 GNUNET_TESTBED_TOPOLOGY_2D_TORUS,
849
850 /**
851 * Random graph. Followed by the link density, that is the
852 * percentage of links present in relation to a clique
853 * (float).
854 */
855 GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI,
856
857 /**
858 * Certain percentage of peers are unable to communicate directly
859 * replicating NAT conditions. Followed by the fraction of
860 * NAT'ed peers (float).
861 */
862 GNUNET_TESTBED_TOPOLOGY_INTERNAT,
863
864 /**
865 * Scale free topology. FIXME: options?
866 */
867 GNUNET_TESTBED_TOPOLOGY_SCALE_FREE,
868
869 /**
870 * Straight line topology. No options.
871 */
872 GNUNET_TESTBED_TOPOLOGY_LINE,
873
874 /**
875 * All peers are disconnected. No options.
876 */
877 GNUNET_TESTBED_TOPOLOGY_NONE,
878
879 /**
880 * Read a topology from a given file. Followed by the name of the file (const char *).
881 */
882 GNUNET_TESTBED_TOPOLOGY_FROM_FILE
883};
884
885
886/**
887 * Configure overall network topology to have a particular shape.
888 *
889 * @param op_cls closure argument to give with the operation event
890 * @param num_peers number of peers in 'peers'
891 * @param peers array of 'num_peers' with the peers to configure
892 * @param topo desired underlay topology to use
893 * @param ap topology-specific options
894 * @return handle to the operation, NULL if configuring the topology
895 * is not allowed at this time
896 */
897struct GNUNET_TESTBED_Operation *
898GNUNET_TESTBED_underlay_configure_topology_va (void *op_cls,
899 unsigned int num_peers,
900 struct GNUNET_TESTBED_Peer **peers,
901 enum GNUNET_TESTBED_TopologyOption topo,
902 va_list ap);
903
904
905/**
906 * Configure overall network topology to have a particular shape.
907 *
908 * @param op_cls closure argument to give with the operation event
909 * @param num_peers number of peers in 'peers'
910 * @param peers array of 'num_peers' with the peers to configure
911 * @param topo desired underlay topology to use
912 * @param ... topology-specific options
913 * @return handle to the operation, NULL if configuring the topology
914 * is not allowed at this time
915 */
916struct GNUNET_TESTBED_Operation *
917GNUNET_TESTBED_underlay_configure_topology (void *op_cls,
918 unsigned int num_peers,
919 struct GNUNET_TESTBED_Peer **peers,
920 enum GNUNET_TESTBED_TopologyOption topo,
921 ...);
922
923
924/**
925 * Callback to be called when an operation is completed
926 *
927 * @param cls the callback closure from functions generating an operation
928 * @param op the operation that has been finished
929 * @param emsg error message in case the operation has failed; will be NULL if
930 * operation has executed successfully.
931 */
932typedef void (*GNUNET_TESTBED_OperationCompletionCallback) (void *cls,
933 struct
934 GNUNET_TESTBED_Operation
935 *op,
936 const char *emsg);
937
938
939/**
940 * Both peers must have been started before calling this function.
941 * This function then obtains a HELLO from 'p1', gives it to 'p2'
942 * and asks 'p2' to connect to 'p1'.
943 *
944 * @param op_cls closure argument to give with the operation event
945 * @param cb the callback to call when this operation has finished
946 * @param cb_cls the closure for the above callback
947 * @param p1 first peer
948 * @param p2 second peer
949 * @return handle to the operation, NULL if connecting these two
950 * peers is fundamentally not possible at this time (peers
951 * not running or underlay disallows)
952 */
953struct GNUNET_TESTBED_Operation *
954GNUNET_TESTBED_overlay_connect (void *op_cls,
955 GNUNET_TESTBED_OperationCompletionCallback cb,
956 void *cb_cls,
957 struct GNUNET_TESTBED_Peer *p1,
958 struct GNUNET_TESTBED_Peer *p2);
959
960
961/**
962 * All peers must have been started before calling this function.
963 * This function then connects the given peers in the P2P overlay
964 * using the given topology.
965 *
966 * @param op_cls closure argument to give with the operation event
967 * @param num_peers number of peers in 'peers'
968 * @param peers array of 'num_peers' with the peers to configure
969 * @param topo desired underlay topology to use
970 * @param va topology-specific options
971 * @return handle to the operation, NULL if connecting these
972 * peers is fundamentally not possible at this time (peers
973 * not running or underlay disallows)
974 */
975struct GNUNET_TESTBED_Operation *
976GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
977 unsigned int num_peers,
978 struct GNUNET_TESTBED_Peer *peers,
979 enum GNUNET_TESTBED_TopologyOption topo,
980 va_list va);
981
982
983/**
984 * All peers must have been started before calling this function.
985 * This function then connects the given peers in the P2P overlay
986 * using the given topology.
987 *
988 * @param op_cls closure argument to give with the operation event
989 * @param num_peers number of peers in 'peers'
990 * @param peers array of 'num_peers' with the peers to configure
991 * @param topo desired underlay topology to use
992 * @param ... topology-specific options
993 * @return handle to the operation, NULL if connecting these
994 * peers is fundamentally not possible at this time (peers
995 * not running or underlay disallows)
996 */
997struct GNUNET_TESTBED_Operation *
998GNUNET_TESTBED_overlay_configure_topology (void *op_cls,
999 unsigned int num_peers,
1000 struct GNUNET_TESTBED_Peer *peers,
1001 enum GNUNET_TESTBED_TopologyOption topo,
1002 ...);
1003
1004
1005/**
1006 * Ask the testbed controller to write the current overlay topology to
1007 * a file. Naturally, the file will only contain a snapshot as the
1008 * topology may evolve all the time.
1009 *
1010 * @param controller overlay controller to inspect
1011 * @param filename name of the file the topology should
1012 * be written to.
1013 */
1014void
1015GNUNET_TESTBED_overlay_write_topology_to_file (struct GNUNET_TESTBED_Controller *controller,
1016 const char *filename);
1017
1018
1019/**
1020 * Adapter function called to establish a connection to
1021 * a service.
1022 *
1023 * @param cls closure
1024 * @param cfg configuration of the peer to connect to; will be available until
1025 * GNUNET_TESTBED_operation_done() is called on the operation returned
1026 * from GNUNET_TESTBED_service_connect()
1027 * @return service handle to return in 'op_result', NULL on error
1028 */
1029typedef void * (*GNUNET_TESTBED_ConnectAdapter)(void *cls,
1030 const struct GNUNET_CONFIGURATION_Handle *cfg);
1031
1032
1033/**
1034 * Adapter function called to destroy a connection to
1035 * a service.
1036 *
1037 * @param cls closure
1038 * @param op_result service handle returned from the connect adapter
1039 */
1040typedef void (*GNUNET_TESTBED_DisconnectAdapter)(void *cls,
1041 void *op_result);
1042
1043
1044/**
1045 * Connect to a service offered by the given peer. Will ensure that
1046 * the request is queued to not overwhelm our ability to create and
1047 * maintain connections with other systems. The actual service
1048 * handle is then returned via the 'op_result' member in the event
1049 * callback. The 'ca' callback is used to create the connection
1050 * when the time is right; the 'da' callback will be used to
1051 * destroy the connection (upon 'GNUNET_TESTBED_operation_done').
1052 * 'GNUNET_TESTBED_operation_cancel' can be used to abort this
1053 * operation until the event callback has been called.
1054 *
1055 * @param op_cls closure to pass in operation event
1056 * @param peer peer that runs the service
1057 * @param service_name name of the service to connect to
1058 * @param cb the callback to call when this operation finishes
1059 * @param cb_cls closure for the above callback
1060 * @param ca helper function to establish the connection
1061 * @param da helper function to close the connection
1062 * @param cada_cls closure for ca and da
1063 * @return handle for the operation
1064 */
1065struct GNUNET_TESTBED_Operation *
1066GNUNET_TESTBED_service_connect (void *op_cls,
1067 struct GNUNET_TESTBED_Peer *peer,
1068 const char *service_name,
1069 GNUNET_TESTBED_OperationCompletionCallback cb,
1070 void *cb_cls,
1071 GNUNET_TESTBED_ConnectAdapter ca,
1072 GNUNET_TESTBED_DisconnectAdapter da,
1073 void *cada_cls);
1074
1075
1076/**
1077 * Cancel a pending operation. Releases all resources
1078 * of the operation and will ensure that no event
1079 * is generated for the operation. Does NOT guarantee
1080 * that the operation will be fully undone (or that
1081 * nothing ever happened).
1082 *
1083 * @param operation operation to cancel
1084 */
1085void
1086GNUNET_TESTBED_operation_cancel (struct GNUNET_TESTBED_Operation *operation);
1087
1088
1089/**
1090 * Signal that the information from an operation has been fully
1091 * processed. This function MUST be called for each event
1092 * of type 'operation_finished' to fully remove the operation
1093 * from the operation queue. After calling this function, the
1094 * 'op_result' becomes invalid (!).
1095 *
1096 * @param operation operation to signal completion for
1097 */
1098void
1099GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation);
1100
1101
1102/**
1103 * Configure and run a testbed using the given
1104 * master controller on 'num_hosts' starting
1105 * 'num_peers' using the given peer configuration.
1106 *
1107 * @param controller master controller for the testbed
1108 * (must not be destroyed until after the
1109 * testbed is destroyed).
1110 * @param num_hosts number of hosts in 'hosts', 0 to only
1111 * use 'localhost'
1112 * @param hosts list of hosts to use for the testbed
1113 * @param num_peers number of peers to start
1114 * @param peer_cfg peer configuration template to use
1115 * @param underlay_topology underlay topology to create
1116 * @param va topology-specific options
1117 * @return handle to the testbed
1118 */
1119struct GNUNET_TESTBED_Testbed *
1120GNUNET_TESTBED_create_va (struct GNUNET_TESTBED_Controller *controller,
1121 unsigned int num_hosts,
1122 struct GNUNET_TESTBED_Host **hosts,
1123 unsigned int num_peers,
1124 const struct GNUNET_CONFIGURATION_Handle *peer_cfg,
1125 enum GNUNET_TESTBED_TopologyOption underlay_topology,
1126 va_list va);
1127
1128
1129/**
1130 * Configure and run a testbed using the given
1131 * master controller on 'num_hosts' starting
1132 * 'num_peers' using the given peer configuration.
1133 *
1134 * @param controller master controller for the testbed
1135 * (must not be destroyed until after the
1136 * testbed is destroyed).
1137 * @param num_hosts number of hosts in 'hosts', 0 to only
1138 * use 'localhost'
1139 * @param hosts list of hosts to use for the testbed
1140 * @param num_peers number of peers to start
1141 * @param peer_cfg peer configuration template to use
1142 * @param underlay_topology underlay topology to create
1143 * @param ... topology-specific options
1144 */
1145struct GNUNET_TESTBED_Testbed *
1146GNUNET_TESTBED_create (struct GNUNET_TESTBED_Controller *controller,
1147 unsigned int num_hosts,
1148 struct GNUNET_TESTBED_Host **hosts,
1149 unsigned int num_peers,
1150 const struct GNUNET_CONFIGURATION_Handle *peer_cfg,
1151 enum GNUNET_TESTBED_TopologyOption underlay_topology,
1152 ...);
1153
1154
1155/**
1156 * Destroy a testbed. Stops all running peers and then
1157 * destroys all peers. Does NOT destroy the master controller.
1158 *
1159 * @param testbed testbed to destroy
1160 */
1161void
1162GNUNET_TESTBED_destroy (struct GNUNET_TESTBED_Testbed *testbed);
1163
1164
1165/**
1166 * Convenience method for running a testbed with
1167 * a single call. Underlay and overlay topology
1168 * are configured using the "UNDERLAY" and "OVERLAY"
1169 * options in the "[testbed]" section of the configuration\
1170 * (with possible options given in "UNDERLAY_XXX" and/or
1171 * "OVERLAY_XXX").
1172 *
1173 * The testbed is to be terminated using a call to
1174 * "GNUNET_SCHEDULER_shutdown".
1175 *
1176 * @param host_filename name of the file with the 'hosts', NULL
1177 * to run everything on 'localhost'
1178 * @param cfg configuration to use (for testbed, controller and peers)
1179 * @param num_peers number of peers to start; FIXME: maybe put that ALSO into
1180 * cfg?; should be greater than 0
1181 * @param event_mask bit mask with set of events to call 'cc' for;
1182 * or-ed values of "1LL" shifted by the
1183 * respective 'enum GNUNET_TESTBED_EventType'
1184 * (i.e. "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...")
1185 * @param cc controller callback to invoke on events; This callback is called
1186 * for all peer start events even if GNUNET_TESTBED_ET_PEER_START isn't
1187 * set in the event_mask as this is the only way get access to the
1188 * handle of each peer
1189 * @param cc_cls closure for cc
1190 * @param master task to run once the testbed is ready
1191 * @param master_cls closure for 'task'.
1192 */
1193void
1194GNUNET_TESTBED_run (const char *host_filename,
1195 const struct GNUNET_CONFIGURATION_Handle *cfg,
1196 unsigned int num_peers,
1197 uint64_t event_mask,
1198 GNUNET_TESTBED_ControllerCallback cc,
1199 void *cc_cls,
1200 GNUNET_SCHEDULER_Task master,
1201 void *master_cls);
1202
1203
1204/**
1205 * Signature of a main function for a testcase.
1206 *
1207 * @param cls closure
1208 * @param num_peers number of peers in 'peers'
1209 * @param peers handle to peers run in the testbed
1210 */
1211typedef void (*GNUNET_TESTBED_TestMaster)(void *cls,
1212 unsigned int num_peers,
1213 struct GNUNET_TESTBED_Peer **peers);
1214
1215
1216/**
1217 * Convenience method for running a "simple" test on the local system
1218 * with a single call from 'main'. Underlay and overlay topology are
1219 * configured using the "UNDERLAY" and "OVERLAY" options in the
1220 * "[testbed]" section of the configuration (with possible options
1221 * given in "UNDERLAY_XXX" and/or "OVERLAY_XXX").
1222 *
1223 * The test is to be terminated using a call to
1224 * "GNUNET_SCHEDULER_shutdown". If starting the test fails,
1225 * the program is stopped without 'master' ever being run.
1226 *
1227 * NOTE: this function should be called from 'main', NOT from
1228 * within a GNUNET_SCHEDULER-loop. This function will initialze
1229 * the scheduler loop, the testbed and then pass control to
1230 * 'master'.
1231 *
1232 * @param testname name of the testcase (to configure logging, etc.)
1233 * @param cfg_filename configuration filename to use
1234 * (for testbed, controller and peers)
1235 * @param num_peers number of peers to start; should be greter than 0
1236 * @param event_mask bit mask with set of events to call 'cc' for;
1237 * or-ed values of "1LL" shifted by the
1238 * respective 'enum GNUNET_TESTBED_EventType'
1239 * (i.e. "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...")
1240 * @param cc controller callback to invoke on events; This callback is called
1241 * for all peer start events even if GNUNET_TESTBED_ET_PEER_START isn't
1242 * set in the event_mask as this is the only way get access to the
1243 * handle of each peer
1244 * @param cc_cls closure for cc
1245 * @param test_master task to run once the test is ready
1246 * @param test_master_cls closure for 'task'.
1247 */
1248void
1249GNUNET_TESTBED_test_run (const char *testname,
1250 const char *cfg_filename,
1251 unsigned int num_peers,
1252 uint64_t event_mask,
1253 GNUNET_TESTBED_ControllerCallback cc,
1254 void *cc_cls,
1255 GNUNET_TESTBED_TestMaster test_master,
1256 void *test_master_cls);
1257
1258
1259#if 0 /* keep Emacsens' auto-indent happy */
1260{
1261#endif
1262
1263
1264#ifdef __cplusplus
1265}
1266#endif
1267
1268#endif
diff --git a/src/include/gnunet_testbed_service.h b/src/include/gnunet_testbed_service.h
index 1be35c098..249b40752 100644
--- a/src/include/gnunet_testbed_service.h
+++ b/src/include/gnunet_testbed_service.h
@@ -309,41 +309,11 @@ struct GNUNET_TESTBED_EventInformation
309 const char *emsg; 309 const char *emsg;
310 310
311 /** 311 /**
312 * Peer information type; captures which of the types 312 * No result (NULL pointer) or generic result
313 * in the 'op_result' is actually in use. 313 * (whatever the GNUNET_TESTBED_ConnectAdapter returned).
314 */ 314 */
315 enum GNUNET_TESTBED_PeerInformationType pit; 315 void *generic;
316 316
317 /**
318 * Pointer to an operation-specific return value; NULL on error;
319 * can be NULL for certain operations. Valid until
320 * 'GNUNET_TESTBED_operation_done' is called.
321 */
322 union
323 {
324 /**
325 * No result (NULL pointer) or generic result
326 * (whatever the GNUNET_TESTBED_ConnectAdapter returned).
327 */
328 void *generic;
329
330 /**
331 * Identity of host running the peer.
332 */
333 struct GNUNET_TESTBED_Host *host;
334
335 /**
336 * Identity of the peer.
337 */
338 const struct GNUNET_PeerIdentity *pid;
339
340 /**
341 * Configuration of the peer.
342 */
343 const struct GNUNET_CONFIGURATION_Handle *cfg;
344
345 } op_result;
346
347 } operation_finished; 317 } operation_finished;
348 318
349 319
@@ -555,6 +525,21 @@ GNUNET_TESTBED_cancel_registration (struct GNUNET_TESTBED_HostRegistrationHandle
555 525
556 526
557/** 527/**
528 * Callback to be called when an operation is completed
529 *
530 * @param cls the callback closure from functions generating an operation
531 * @param op the operation that has been finished
532 * @param emsg error message in case the operation has failed; will be NULL if
533 * operation has executed successfully.
534 */
535typedef void (*GNUNET_TESTBED_OperationCompletionCallback) (void *cls,
536 struct
537 GNUNET_TESTBED_Operation
538 *op,
539 const char *emsg);
540
541
542/**
558 * Create a link from slave controller to delegated controller. Whenever the 543 * Create a link from slave controller to delegated controller. Whenever the
559 * master controller is asked to start a peer at the delegated controller the 544 * master controller is asked to start a peer at the delegated controller the
560 * request will be routed towards slave controller (if a route exists). The 545 * request will be routed towards slave controller (if a route exists). The
@@ -684,15 +669,70 @@ GNUNET_TESTBED_peer_stop (struct GNUNET_TESTBED_Peer *peer);
684 669
685 670
686/** 671/**
687 * Request information about a peer. 672 * Data returned from GNUNET_TESTBED_peer_get_information
673 */
674struct GNUNET_TESTBED_PeerInformation
675{
676 /**
677 * Peer information type; captures which of the types
678 * in the 'op_result' is actually in use.
679 */
680 enum GNUNET_TESTBED_PeerInformationType pit;
681
682 /**
683 * The result of the get information operation; Choose according to the pit
684 */
685 union
686 {
687 /**
688 * The configuration of the peer
689 */
690 struct GNUNET_CONFIGURATION_Handle *cfg;
691
692 /**
693 * The identity of the peer
694 */
695 struct GNUNET_PeerIdentity *id;
696 } result;
697};
698
699
700/**
701 * Callback to be called when the requested peer information is available
702 *
703 * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information()
704 * @param op the operation this callback corresponds to
705 * @param pinfo the result; will be NULL if the operation has failed
706 * @param emsg error message if the operation has failed; will be NULL if the
707 * operation is successfull
708 */
709typedef void (*GNUNET_TESTBED_PeerInfoCallback) (void *cb_cls,
710 struct GNUNET_TESTBED_Operation
711 *op,
712 const struct
713 GNUNET_TESTBED_PeerInformation
714 *pinfo,
715 const char *emsg);
716
717
718/**
719 * Request information about a peer. The controller callback will be called with
720 * event type GNUNET_TESTBED_ET_OPERATION_FINISHED when result for this
721 * operation is available
688 * 722 *
689 * @param peer peer to request information about 723 * @param peer peer to request information about
690 * @param pit desired information 724 * @param pit desired information
725 * @param cb the convenience callback to be called when results for this
726 * operation are available
727 * @param cb_cls the closure for the above callback
691 * @return handle to the operation 728 * @return handle to the operation
692 */ 729 */
693struct GNUNET_TESTBED_Operation * 730struct GNUNET_TESTBED_Operation *
694GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer, 731GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer,
695 enum GNUNET_TESTBED_PeerInformationType pit); 732 enum GNUNET_TESTBED_PeerInformationType
733 pit,
734 GNUNET_TESTBED_PeerInfoCallback cb,
735 void *cb_cls);
696 736
697 737
698/** 738/**
@@ -901,6 +941,8 @@ GNUNET_TESTBED_underlay_configure_topology (void *op_cls,
901 * and asks 'p2' to connect to 'p1'. 941 * and asks 'p2' to connect to 'p1'.
902 * 942 *
903 * @param op_cls closure argument to give with the operation event 943 * @param op_cls closure argument to give with the operation event
944 * @param cb the callback to call when this operation has finished
945 * @param cb_cls the closure for the above callback
904 * @param p1 first peer 946 * @param p1 first peer
905 * @param p2 second peer 947 * @param p2 second peer
906 * @return handle to the operation, NULL if connecting these two 948 * @return handle to the operation, NULL if connecting these two
@@ -909,6 +951,8 @@ GNUNET_TESTBED_underlay_configure_topology (void *op_cls,
909 */ 951 */
910struct GNUNET_TESTBED_Operation * 952struct GNUNET_TESTBED_Operation *
911GNUNET_TESTBED_overlay_connect (void *op_cls, 953GNUNET_TESTBED_overlay_connect (void *op_cls,
954 GNUNET_TESTBED_OperationCompletionCallback cb,
955 void *cb_cls,
912 struct GNUNET_TESTBED_Peer *p1, 956 struct GNUNET_TESTBED_Peer *p1,
913 struct GNUNET_TESTBED_Peer *p2); 957 struct GNUNET_TESTBED_Peer *p2);
914 958
@@ -1010,6 +1054,8 @@ typedef void (*GNUNET_TESTBED_DisconnectAdapter)(void *cls,
1010 * @param op_cls closure to pass in operation event 1054 * @param op_cls closure to pass in operation event
1011 * @param peer peer that runs the service 1055 * @param peer peer that runs the service
1012 * @param service_name name of the service to connect to 1056 * @param service_name name of the service to connect to
1057 * @param cb the callback to call when this operation finishes
1058 * @param cb_cls closure for the above callback
1013 * @param ca helper function to establish the connection 1059 * @param ca helper function to establish the connection
1014 * @param da helper function to close the connection 1060 * @param da helper function to close the connection
1015 * @param cada_cls closure for ca and da 1061 * @param cada_cls closure for ca and da
@@ -1019,6 +1065,8 @@ struct GNUNET_TESTBED_Operation *
1019GNUNET_TESTBED_service_connect (void *op_cls, 1065GNUNET_TESTBED_service_connect (void *op_cls,
1020 struct GNUNET_TESTBED_Peer *peer, 1066 struct GNUNET_TESTBED_Peer *peer,
1021 const char *service_name, 1067 const char *service_name,
1068 GNUNET_TESTBED_OperationCompletionCallback cb,
1069 void *cb_cls,
1022 GNUNET_TESTBED_ConnectAdapter ca, 1070 GNUNET_TESTBED_ConnectAdapter ca,
1023 GNUNET_TESTBED_DisconnectAdapter da, 1071 GNUNET_TESTBED_DisconnectAdapter da,
1024 void *cada_cls); 1072 void *cada_cls);
diff --git a/src/testbed/test_testbed_api.c b/src/testbed/test_testbed_api.c
index caa3d09fd..529072cee 100644
--- a/src/testbed/test_testbed_api.c
+++ b/src/testbed/test_testbed_api.c
@@ -207,6 +207,64 @@ dht_disconnect_adapter (void *cls, void *op_result)
207} 207}
208 208
209 209
210/**
211 * Callback to be called when an operation is completed
212 *
213 * @param cls the callback closure from functions generating an operation
214 * @param op the operation that has been finished
215 * @param emsg error message in case the operation has failed; will be NULL if
216 * operation has executed successfully.
217 */
218static void
219op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
220{
221 switch (sub_test)
222 {
223 case PEER_SERVICE_CONNECT:
224 GNUNET_assert (operation == op);
225 GNUNET_assert (NULL == emsg);
226 GNUNET_assert (NULL == cls);
227 GNUNET_TESTBED_operation_done (operation); /* This results in call to
228 * disconnect adapter */
229 break;
230 default:
231 GNUNET_assert (0);
232 }
233}
234
235
236/**
237 * Callback to be called when the requested peer information is available
238 *
239 * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information()
240 * @param op the operation this callback corresponds to
241 * @param pinfo the result; will be NULL if the operation has failed
242 * @param emsg error message if the operation has failed; will be NULL if the
243 * operation is successfull
244 */
245static void
246peerinfo_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op,
247 const struct GNUNET_TESTBED_PeerInformation *pinfo,
248 const char *emsg)
249{
250 switch (sub_test)
251 {
252 case PEER_GETCONFIG:
253 GNUNET_assert (NULL != pinfo);
254 GNUNET_assert (NULL == emsg);
255 GNUNET_assert (NULL == cb_cls);
256 GNUNET_assert (operation == op);
257 GNUNET_assert (GNUNET_TESTBED_PIT_CONFIGURATION == pinfo->pit);
258 GNUNET_assert (NULL != pinfo->result.cfg);
259 sub_test = PEER_DESTROY;
260 GNUNET_TESTBED_operation_done (operation);
261 operation = GNUNET_TESTBED_peer_destroy (peer);
262 break;
263 default:
264 GNUNET_assert (0);
265 }
266}
267
210 268
211/** 269/**
212 * Signature of the event handler function called by the 270 * Signature of the event handler function called by the
@@ -223,25 +281,11 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
223 case GNUNET_TESTBED_ET_OPERATION_FINISHED: 281 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
224 switch (sub_test) 282 switch (sub_test)
225 { 283 {
226 case PEER_GETCONFIG:
227 GNUNET_assert (event->details.operation_finished.operation == operation);
228 GNUNET_assert (NULL == event->details.operation_finished.op_cls);
229 GNUNET_assert (NULL == event->details.operation_finished.emsg);
230 GNUNET_assert (GNUNET_TESTBED_PIT_CONFIGURATION ==
231 event->details.operation_finished.pit);
232 GNUNET_assert (NULL != event->details.operation_finished.op_result.cfg);
233 sub_test = PEER_DESTROY;
234 GNUNET_TESTBED_operation_done (operation);
235 operation = GNUNET_TESTBED_peer_destroy (peer);
236 break;
237 case PEER_DESTROY: 284 case PEER_DESTROY:
238 GNUNET_assert (event->details.operation_finished.operation == operation); 285 GNUNET_assert (event->details.operation_finished.operation == operation);
239 GNUNET_assert (NULL == event->details.operation_finished.op_cls); 286 GNUNET_assert (NULL == event->details.operation_finished.op_cls);
240 GNUNET_assert (NULL == event->details.operation_finished.emsg); 287 GNUNET_assert (NULL == event->details.operation_finished.emsg);
241 GNUNET_assert (GNUNET_TESTBED_PIT_GENERIC == 288 GNUNET_assert (NULL == event->details.operation_finished.generic);
242 event->details.operation_finished.pit);
243 GNUNET_assert (NULL ==
244 event->details.operation_finished.op_result.generic);
245 GNUNET_TESTBED_operation_done (operation); 289 GNUNET_TESTBED_operation_done (operation);
246 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 290 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
247 break; 291 break;
@@ -249,15 +293,10 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
249 GNUNET_assert (event->details.operation_finished.operation == operation); 293 GNUNET_assert (event->details.operation_finished.operation == operation);
250 GNUNET_assert (NULL == event->details.operation_finished.op_cls); 294 GNUNET_assert (NULL == event->details.operation_finished.op_cls);
251 GNUNET_assert (NULL == event->details.operation_finished.emsg); 295 GNUNET_assert (NULL == event->details.operation_finished.emsg);
252 GNUNET_assert (GNUNET_TESTBED_PIT_GENERIC ==
253 event->details.operation_finished.pit);
254 GNUNET_assert (NULL != dht_handle); 296 GNUNET_assert (NULL != dht_handle);
255 GNUNET_assert (event->details.operation_finished.op_result.generic == 297 GNUNET_assert (event->details.operation_finished.generic == dht_handle);
256 dht_handle);
257 GNUNET_TESTBED_operation_done (operation); /* This results in call to
258 * disconnect adapter */
259 break; 298 break;
260 case OTHER: 299 default:
261 GNUNET_assert (0); 300 GNUNET_assert (0);
262 break; 301 break;
263 } 302 }
@@ -268,8 +307,9 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
268 GNUNET_assert (OTHER == sub_test); 307 GNUNET_assert (OTHER == sub_test);
269 GNUNET_TESTBED_operation_done (operation); 308 GNUNET_TESTBED_operation_done (operation);
270 operation = 309 operation =
271 GNUNET_TESTBED_service_connect (NULL, peer, "dht", &dht_connect_adapter, 310 GNUNET_TESTBED_service_connect (NULL, peer, "dht", &op_comp_cb, NULL,
272 &dht_disconnect_adapter, NULL); 311 &dht_connect_adapter,
312 &dht_disconnect_adapter, NULL);
273 GNUNET_assert (NULL != operation); 313 GNUNET_assert (NULL != operation);
274 break; 314 break;
275 case GNUNET_TESTBED_ET_PEER_STOP: 315 case GNUNET_TESTBED_ET_PEER_STOP:
@@ -278,9 +318,10 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
278 result = GNUNET_YES; 318 result = GNUNET_YES;
279 sub_test = PEER_GETCONFIG; 319 sub_test = PEER_GETCONFIG;
280 GNUNET_TESTBED_operation_done (operation); 320 GNUNET_TESTBED_operation_done (operation);
281 operation = 321 operation =
282 GNUNET_TESTBED_peer_get_information (peer, 322 GNUNET_TESTBED_peer_get_information (peer,
283 GNUNET_TESTBED_PIT_CONFIGURATION); 323 GNUNET_TESTBED_PIT_CONFIGURATION,
324 &peerinfo_cb, NULL);
284 break; 325 break;
285 default: 326 default:
286 GNUNET_assert (0); /* We should never reach this state */ 327 GNUNET_assert (0); /* We should never reach this state */
diff --git a/src/testbed/test_testbed_api_2peers.c b/src/testbed/test_testbed_api_2peers.c
index e1445d961..63810187b 100644
--- a/src/testbed/test_testbed_api_2peers.c
+++ b/src/testbed/test_testbed_api_2peers.c
@@ -196,6 +196,30 @@ do_abort (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
196 196
197 197
198/** 198/**
199 * Callback to be called when an operation is completed
200 *
201 * @param cls the callback closure from functions generating an operation
202 * @param op the operation that has been finished
203 * @param emsg error message in case the operation has failed; will be NULL if
204 * operation has executed successfully.
205 */
206static void
207op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
208{
209 GNUNET_assert (PEERS_STARTED == result);
210 GNUNET_assert (NULL == peer1.operation);
211 GNUNET_assert (NULL == peer2.operation);
212 GNUNET_assert (NULL != common_operation);
213 GNUNET_TESTBED_operation_done (common_operation);
214 common_operation = NULL;
215 result = PEERS_CONNECTED;
216 LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected\n");
217 peer1.operation = GNUNET_TESTBED_peer_stop (peer1.peer);
218 peer2.operation = GNUNET_TESTBED_peer_stop (peer2.peer);
219}
220
221
222/**
199 * Signature of the event handler function called by the 223 * Signature of the event handler function called by the
200 * respective event controller. 224 * respective event controller.
201 * 225 *
@@ -211,9 +235,7 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
211 GNUNET_assert (PEERS_STOPPED == result); 235 GNUNET_assert (PEERS_STOPPED == result);
212 GNUNET_assert (NULL == event->details.operation_finished.op_cls); 236 GNUNET_assert (NULL == event->details.operation_finished.op_cls);
213 GNUNET_assert (NULL == event->details.operation_finished.emsg); 237 GNUNET_assert (NULL == event->details.operation_finished.emsg);
214 GNUNET_assert (GNUNET_TESTBED_PIT_GENERIC == 238 GNUNET_assert (NULL == event->details.operation_finished.generic);
215 event->details.operation_finished.pit);
216 GNUNET_assert (NULL == event->details.operation_finished.op_result.generic);
217 if (event->details.operation_finished.operation == peer1.operation) 239 if (event->details.operation_finished.operation == peer1.operation)
218 { 240 {
219 GNUNET_TESTBED_operation_done (peer1.operation); 241 GNUNET_TESTBED_operation_done (peer1.operation);
@@ -255,7 +277,8 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
255 { 277 {
256 result = PEERS_STARTED; 278 result = PEERS_STARTED;
257 common_operation = 279 common_operation =
258 GNUNET_TESTBED_overlay_connect (NULL, peer1.peer, peer2.peer); 280 GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer1.peer,
281 peer2.peer);
259 } 282 }
260 break; 283 break;
261 case GNUNET_TESTBED_ET_PEER_STOP: 284 case GNUNET_TESTBED_ET_PEER_STOP:
@@ -284,12 +307,6 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
284 GNUNET_assert (NULL != common_operation); 307 GNUNET_assert (NULL != common_operation);
285 GNUNET_assert ((event->details.peer_connect.peer1 == peer1.peer) && 308 GNUNET_assert ((event->details.peer_connect.peer1 == peer1.peer) &&
286 (event->details.peer_connect.peer2 == peer2.peer)); 309 (event->details.peer_connect.peer2 == peer2.peer));
287 GNUNET_TESTBED_operation_done (common_operation);
288 common_operation = NULL;
289 result = PEERS_CONNECTED;
290 LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected\n");
291 peer1.operation = GNUNET_TESTBED_peer_stop (peer1.peer);
292 peer2.operation = GNUNET_TESTBED_peer_stop (peer2.peer);
293 break; 310 break;
294 default: 311 default:
295 GNUNET_assert (0); 312 GNUNET_assert (0);
diff --git a/src/testbed/test_testbed_api_controllerlink.c b/src/testbed/test_testbed_api_controllerlink.c
index b10e454de..ee62bf1aa 100644
--- a/src/testbed/test_testbed_api_controllerlink.c
+++ b/src/testbed/test_testbed_api_controllerlink.c
@@ -305,9 +305,7 @@ check_operation_success (const struct GNUNET_TESTBED_EventInformation *event)
305 GNUNET_assert (event->details.operation_finished.operation == op); 305 GNUNET_assert (event->details.operation_finished.operation == op);
306 GNUNET_assert (NULL == event->details.operation_finished.op_cls); 306 GNUNET_assert (NULL == event->details.operation_finished.op_cls);
307 GNUNET_assert (NULL == event->details.operation_finished.emsg); 307 GNUNET_assert (NULL == event->details.operation_finished.emsg);
308 GNUNET_assert (GNUNET_TESTBED_PIT_GENERIC == 308 GNUNET_assert (NULL == event->details.operation_finished.generic);
309 event->details.operation_finished.pit);
310 GNUNET_assert (NULL == event->details.operation_finished.op_result.generic);
311} 309}
312 310
313 311
diff --git a/src/testbed/test_testbed_api_test.c b/src/testbed/test_testbed_api_test.c
index 43a5628ad..f552d1a78 100644
--- a/src/testbed/test_testbed_api_test.c
+++ b/src/testbed/test_testbed_api_test.c
@@ -63,6 +63,52 @@ do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
63 63
64 64
65/** 65/**
66 * Callback to be called when the requested peer information is available
67 *
68 * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information()
69 * @param op the operation this callback corresponds to
70 * @param pinfo the result; will be NULL if the operation has failed
71 * @param emsg error message if the operation has failed; will be NULL if the
72 * operation is successfull
73 */
74static void
75peerinfo_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op_,
76 const struct GNUNET_TESTBED_PeerInformation *pinfo,
77 const char *emsg)
78{
79 GNUNET_assert (op == op_);
80 GNUNET_assert (NULL == cb_cls);
81 GNUNET_assert (NULL == emsg);
82 GNUNET_assert (GNUNET_TESTBED_PIT_IDENTITY == pinfo->pit);
83 GNUNET_assert (NULL != pinfo->result.id);
84 GNUNET_TESTBED_operation_done (op);
85 result = GNUNET_OK;
86 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
87}
88
89
90/**
91 * Callback to be called when an operation is completed
92 *
93 * @param cls the callback closure from functions generating an operation
94 * @param op the operation that has been finished
95 * @param emsg error message in case the operation has failed; will be NULL if
96 * operation has executed successfully.
97 */
98static void
99op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op_, const char *emsg)
100{
101 GNUNET_assert (NULL == cls);
102 GNUNET_assert (op == op_);
103 GNUNET_assert (NULL == emsg);
104 GNUNET_TESTBED_operation_done (op);
105 op = GNUNET_TESTBED_peer_get_information (peers[0],
106 GNUNET_TESTBED_PIT_IDENTITY,
107 &peerinfo_cb, NULL);
108}
109
110
111/**
66 * Controller event callback 112 * Controller event callback
67 * 113 *
68 * @param cls NULL 114 * @param cls NULL
@@ -76,21 +122,7 @@ controller_event_cb (void *cls,
76 { 122 {
77 case GNUNET_TESTBED_ET_CONNECT: 123 case GNUNET_TESTBED_ET_CONNECT:
78 GNUNET_assert (event->details.peer_connect.peer1 == peers[0]); 124 GNUNET_assert (event->details.peer_connect.peer1 == peers[0]);
79 GNUNET_assert (event->details.peer_connect.peer2 == peers[1]); 125 GNUNET_assert (event->details.peer_connect.peer2 == peers[1]);
80 GNUNET_TESTBED_operation_done (op);
81 op = GNUNET_TESTBED_peer_get_information (peers[0],
82 GNUNET_TESTBED_PIT_IDENTITY);
83 break;
84 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
85 GNUNET_assert (event->details.operation_finished.operation == op);
86 GNUNET_assert (NULL == event->details.operation_finished.op_cls);
87 GNUNET_assert (NULL == event->details.operation_finished.emsg);
88 GNUNET_assert (GNUNET_TESTBED_PIT_IDENTITY ==
89 event->details.operation_finished.pit);
90 GNUNET_assert (NULL != event->details.operation_finished.op_result.pid);
91 GNUNET_TESTBED_operation_done (op);
92 result = GNUNET_OK;
93 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
94 break; 126 break;
95 default: 127 default:
96 GNUNET_assert (0); 128 GNUNET_assert (0);
@@ -117,7 +149,7 @@ test_master (void *cls, unsigned int num_peers,
117 for (peer = 0; peer < num_peers; peer++) 149 for (peer = 0; peer < num_peers; peer++)
118 GNUNET_assert (NULL != peers_[peer]); 150 GNUNET_assert (NULL != peers_[peer]);
119 peers = peers_; 151 peers = peers_;
120 op = GNUNET_TESTBED_overlay_connect (NULL, peers[0], peers[1]); 152 op = GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peers[0], peers[1]);
121} 153}
122 154
123 155
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c
index 48c55e470..665c19486 100644
--- a/src/testbed/testbed_api.c
+++ b/src/testbed/testbed_api.c
@@ -322,8 +322,7 @@ handle_opsuccess (struct GNUNET_TESTBED_Controller *c,
322 event->details.operation_finished.operation = opc->op; 322 event->details.operation_finished.operation = opc->op;
323 event->details.operation_finished.op_cls = NULL; 323 event->details.operation_finished.op_cls = NULL;
324 event->details.operation_finished.emsg = NULL; 324 event->details.operation_finished.emsg = NULL;
325 event->details.operation_finished.pit = GNUNET_TESTBED_PIT_GENERIC; 325 event->details.operation_finished.generic = NULL;
326 event->details.operation_finished.op_result.generic = NULL;
327 } 326 }
328 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); 327 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
329 opc->state = OPC_STATE_FINISHED; 328 opc->state = OPC_STATE_FINISHED;
@@ -480,6 +479,8 @@ handle_peer_conevent (struct GNUNET_TESTBED_Controller *c,
480{ 479{
481 struct OperationContext *opc; 480 struct OperationContext *opc;
482 struct OverlayConnectData *data; 481 struct OverlayConnectData *data;
482 GNUNET_TESTBED_OperationCompletionCallback cb;
483 void *cb_cls;
483 struct GNUNET_TESTBED_EventInformation event; 484 struct GNUNET_TESTBED_EventInformation event;
484 uint64_t op_id; 485 uint64_t op_id;
485 486
@@ -507,6 +508,8 @@ handle_peer_conevent (struct GNUNET_TESTBED_Controller *c,
507 GNUNET_assert (0); /* Should never reach here */ 508 GNUNET_assert (0); /* Should never reach here */
508 break; 509 break;
509 } 510 }
511 cb = data->cb;
512 cb_cls = data->cb_cls;
510 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); 513 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
511 opc->state = OPC_STATE_FINISHED; 514 opc->state = OPC_STATE_FINISHED;
512 GNUNET_free (data); 515 GNUNET_free (data);
@@ -517,6 +520,8 @@ handle_peer_conevent (struct GNUNET_TESTBED_Controller *c,
517 if (NULL != c->cc) 520 if (NULL != c->cc)
518 c->cc (c->cc_cls, &event); 521 c->cc (c->cc_cls, &event);
519 } 522 }
523 if (NULL != cb)
524 cb (cb_cls, opc->op, NULL);
520 return GNUNET_YES; 525 return GNUNET_YES;
521} 526}
522 527
@@ -538,8 +543,9 @@ handle_peer_config (struct GNUNET_TESTBED_Controller *c,
538 struct OperationContext *opc; 543 struct OperationContext *opc;
539 struct GNUNET_TESTBED_Peer *peer; 544 struct GNUNET_TESTBED_Peer *peer;
540 struct PeerInfoData *data; 545 struct PeerInfoData *data;
541 struct PeerInfoData2 *response_data; 546 struct GNUNET_TESTBED_PeerInformation *pinfo;
542 struct GNUNET_TESTBED_EventInformation info; 547 GNUNET_TESTBED_PeerInfoCallback cb;
548 void *cb_cls;
543 uint64_t op_id; 549 uint64_t op_id;
544 550
545 op_id = GNUNET_ntohll (msg->operation_id); 551 op_id = GNUNET_ntohll (msg->operation_id);
@@ -565,52 +571,32 @@ handle_peer_config (struct GNUNET_TESTBED_Controller *c,
565 peer = data->peer; 571 peer = data->peer;
566 GNUNET_assert (NULL != peer); 572 GNUNET_assert (NULL != peer);
567 GNUNET_assert (ntohl (msg->peer_id) == peer->unique_id); 573 GNUNET_assert (ntohl (msg->peer_id) == peer->unique_id);
568 if (0 == (c->event_mask & (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED))) 574 pinfo = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerInformation));
569 { 575 pinfo->pit = data->pit;
570 LOG_DEBUG ("Skipping operation callback as flag not set\n"); 576 cb = data->cb;
571 return GNUNET_YES; 577 cb_cls = data->cb_cls;
572 }
573 response_data = GNUNET_malloc (sizeof (struct PeerInfoData2));
574 response_data->pit = data->pit;
575 GNUNET_free (data); 578 GNUNET_free (data);
576 opc->data = NULL; 579 opc->data = NULL;
577 info.type = GNUNET_TESTBED_ET_OPERATION_FINISHED; 580 switch (pinfo->pit)
578 info.details.operation_finished.operation = opc->op;
579 info.details.operation_finished.op_cls = NULL;
580 info.details.operation_finished.emsg = NULL;
581 info.details.operation_finished.pit = response_data->pit;
582 switch (response_data->pit)
583 { 581 {
584 case GNUNET_TESTBED_PIT_IDENTITY: 582 case GNUNET_TESTBED_PIT_IDENTITY:
585 { 583 pinfo->result.id = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
586 struct GNUNET_PeerIdentity *peer_identity; 584 (void) memcpy (pinfo->result.id, &msg->peer_identity,
587 585 sizeof (struct GNUNET_PeerIdentity));
588 peer_identity = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
589 (void) memcpy (peer_identity, &msg->peer_identity,
590 sizeof (struct GNUNET_PeerIdentity));
591 response_data->details.peer_identity = peer_identity;
592 info.details.operation_finished.op_result.pid = peer_identity;
593 }
594 break; 586 break;
595 case GNUNET_TESTBED_PIT_CONFIGURATION: 587 case GNUNET_TESTBED_PIT_CONFIGURATION:
596 response_data->details.cfg = /* Freed in oprelease_peer_getinfo */ 588 pinfo->result.cfg = /* Freed in oprelease_peer_getinfo */
597 GNUNET_TESTBED_get_config_from_peerinfo_msg_ (msg); 589 GNUNET_TESTBED_get_config_from_peerinfo_msg_ (msg);
598 info.details.operation_finished.op_result.cfg = response_data->details.cfg;
599 break; 590 break;
600 case GNUNET_TESTBED_PIT_GENERIC: 591 case GNUNET_TESTBED_PIT_GENERIC:
601 GNUNET_assert (0); /* never reach here */ 592 GNUNET_assert (0); /* never reach here */
602 break; 593 break;
603 } 594 }
604 opc->data = response_data; 595 opc->data = pinfo;
605 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); 596 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
606 opc->state = OPC_STATE_FINISHED; 597 opc->state = OPC_STATE_FINISHED;
607 if (0 != 598 if (NULL != cb)
608 ((GNUNET_TESTBED_ET_CONNECT | GNUNET_TESTBED_ET_DISCONNECT) & 599 cb (cb_cls, opc->op, pinfo, NULL);
609 c->event_mask))
610 {
611 if (NULL != c->cc)
612 c->cc (c->cc_cls, &info);
613 }
614 return GNUNET_YES; 600 return GNUNET_YES;
615} 601}
616 602
@@ -676,8 +662,7 @@ handle_op_fail_event (struct GNUNET_TESTBED_Controller *c,
676 event.details.operation_finished.operation = opc->op; 662 event.details.operation_finished.operation = opc->op;
677 event.details.operation_finished.op_cls = NULL; 663 event.details.operation_finished.op_cls = NULL;
678 event.details.operation_finished.emsg = emsg; 664 event.details.operation_finished.emsg = emsg;
679 event.details.operation_finished.pit = GNUNET_TESTBED_PIT_GENERIC; 665 event.details.operation_finished.generic = NULL;
680 event.details.operation_finished.op_result.generic = NULL;
681 c->cc (c->cc_cls, &event); 666 c->cc (c->cc_cls, &event);
682 } 667 }
683 return GNUNET_YES; 668 return GNUNET_YES;
diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c
index 9ced75973..9465c66bb 100644
--- a/src/testbed/testbed_api_peers.c
+++ b/src/testbed/testbed_api_peers.c
@@ -279,7 +279,7 @@ static void
279oprelease_peer_getinfo (void *cls) 279oprelease_peer_getinfo (void *cls)
280{ 280{
281 struct OperationContext *opc = cls; 281 struct OperationContext *opc = cls;
282 struct PeerInfoData2 *data; 282 struct GNUNET_TESTBED_PeerInformation *data;
283 283
284 if (OPC_STATE_FINISHED != opc->state) 284 if (OPC_STATE_FINISHED != opc->state)
285 { 285 {
@@ -293,10 +293,10 @@ oprelease_peer_getinfo (void *cls)
293 switch (data->pit) 293 switch (data->pit)
294 { 294 {
295 case GNUNET_TESTBED_PIT_CONFIGURATION: 295 case GNUNET_TESTBED_PIT_CONFIGURATION:
296 GNUNET_CONFIGURATION_destroy (data->details.cfg); 296 GNUNET_CONFIGURATION_destroy (data->result.cfg);
297 break; 297 break;
298 case GNUNET_TESTBED_PIT_IDENTITY: 298 case GNUNET_TESTBED_PIT_IDENTITY:
299 GNUNET_free (data->details.peer_identity); 299 GNUNET_free (data->result.id);
300 break; 300 break;
301 default: 301 default:
302 GNUNET_assert (0); /* We should never reach here */ 302 GNUNET_assert (0); /* We should never reach here */
@@ -532,16 +532,23 @@ GNUNET_TESTBED_peer_stop (struct GNUNET_TESTBED_Peer *peer)
532 532
533 533
534/** 534/**
535 * Request information about a peer. 535 * Request information about a peer. The controller callback will be called with
536 * event type GNUNET_TESTBED_ET_OPERATION_FINISHED when result for this
537 * operation is available
536 * 538 *
537 * @param peer peer to request information about 539 * @param peer peer to request information about
538 * @param pit desired information 540 * @param pit desired information
541 * @param cb the convenience callback to be called when results for this
542 * operation are available
543 * @param cb_cls the closure for the above callback
539 * @return handle to the operation 544 * @return handle to the operation
540 */ 545 */
541struct GNUNET_TESTBED_Operation * 546struct GNUNET_TESTBED_Operation *
542GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer, 547GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer,
543 enum GNUNET_TESTBED_PeerInformationType 548 enum GNUNET_TESTBED_PeerInformationType
544 pit) 549 pit,
550 GNUNET_TESTBED_PeerInfoCallback cb,
551 void *cb_cls)
545{ 552{
546 struct OperationContext *opc; 553 struct OperationContext *opc;
547 struct PeerInfoData *data; 554 struct PeerInfoData *data;
@@ -550,6 +557,8 @@ GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer,
550 data = GNUNET_malloc (sizeof (struct PeerInfoData)); 557 data = GNUNET_malloc (sizeof (struct PeerInfoData));
551 data->peer = peer; 558 data->peer = peer;
552 data->pit = pit; 559 data->pit = pit;
560 data->cb = cb;
561 data->cb_cls = cb_cls;
553 opc = GNUNET_malloc (sizeof (struct OperationContext)); 562 opc = GNUNET_malloc (sizeof (struct OperationContext));
554 opc->c = peer->controller; 563 opc->c = peer->controller;
555 opc->data = data; 564 opc->data = data;
@@ -635,13 +644,14 @@ GNUNET_TESTBED_underlay_configure_link (void *op_cls,
635} 644}
636 645
637 646
638
639/** 647/**
640 * Both peers must have been started before calling this function. 648 * Both peers must have been started before calling this function.
641 * This function then obtains a HELLO from 'p1', gives it to 'p2' 649 * This function then obtains a HELLO from 'p1', gives it to 'p2'
642 * and asks 'p2' to connect to 'p1'. 650 * and asks 'p2' to connect to 'p1'.
643 * 651 *
644 * @param op_cls closure argument to give with the operation event 652 * @param op_cls closure argument to give with the operation event
653 * @param cb the callback to call when this operation has finished
654 * @param cb_cls the closure for the above callback
645 * @param p1 first peer 655 * @param p1 first peer
646 * @param p2 second peer 656 * @param p2 second peer
647 * @return handle to the operation, NULL if connecting these two 657 * @return handle to the operation, NULL if connecting these two
@@ -649,8 +659,11 @@ GNUNET_TESTBED_underlay_configure_link (void *op_cls,
649 * not running or underlay disallows) 659 * not running or underlay disallows)
650 */ 660 */
651struct GNUNET_TESTBED_Operation * 661struct GNUNET_TESTBED_Operation *
652GNUNET_TESTBED_overlay_connect (void *op_cls, struct GNUNET_TESTBED_Peer *p1, 662GNUNET_TESTBED_overlay_connect (void *op_cls,
653 struct GNUNET_TESTBED_Peer *p2) 663 GNUNET_TESTBED_OperationCompletionCallback cb,
664 void *cb_cls,
665 struct GNUNET_TESTBED_Peer *p1,
666 struct GNUNET_TESTBED_Peer *p2)
654{ 667{
655 struct OperationContext *opc; 668 struct OperationContext *opc;
656 struct OverlayConnectData *data; 669 struct OverlayConnectData *data;
@@ -660,6 +673,8 @@ GNUNET_TESTBED_overlay_connect (void *op_cls, struct GNUNET_TESTBED_Peer *p1,
660 data = GNUNET_malloc (sizeof (struct OverlayConnectData)); 673 data = GNUNET_malloc (sizeof (struct OverlayConnectData));
661 data->p1 = p1; 674 data->p1 = p1;
662 data->p2 = p2; 675 data->p2 = p2;
676 data->cb = cb;
677 data->cb_cls = cb_cls;
663 opc = GNUNET_malloc (sizeof (struct OperationContext)); 678 opc = GNUNET_malloc (sizeof (struct OperationContext));
664 opc->data = data; 679 opc->data = data;
665 opc->c = p1->controller; 680 opc->c = p1->controller;
diff --git a/src/testbed/testbed_api_peers.h b/src/testbed/testbed_api_peers.h
index 21cae976b..16c4ea42f 100644
--- a/src/testbed/testbed_api_peers.h
+++ b/src/testbed/testbed_api_peers.h
@@ -146,37 +146,19 @@ struct PeerInfoData
146 struct GNUNET_TESTBED_Peer *peer; 146 struct GNUNET_TESTBED_Peer *peer;
147 147
148 /** 148 /**
149 * The type of peer information requested 149 * The Peer info callback to call when this operation has completed
150 */ 150 */
151 enum GNUNET_TESTBED_PeerInformationType pit; 151 GNUNET_TESTBED_PeerInfoCallback cb;
152}; 152
153
154
155/**
156 * Data for the OperationType OP_PEER_INFO
157 */
158struct PeerInfoData2
159{
160 /** 153 /**
161 * The type of peer information requested 154 * The closure for peer info callback
162 */ 155 */
163 enum GNUNET_TESTBED_PeerInformationType pit; 156 void *cb_cls;
164 157
165 /** 158 /**
166 * The data from reply 159 * The type of peer information requested
167 */ 160 */
168 union 161 enum GNUNET_TESTBED_PeerInformationType pit;
169 {
170 /**
171 * Configuration handle
172 */
173 struct GNUNET_CONFIGURATION_Handle *cfg;
174
175 /**
176 * Peer Identity
177 */
178 struct GNUNET_PeerIdentity *peer_identity;
179 } details;
180}; 162};
181 163
182 164
@@ -195,6 +177,16 @@ struct OverlayConnectData
195 */ 177 */
196 struct GNUNET_TESTBED_Peer *p2; 178 struct GNUNET_TESTBED_Peer *p2;
197 179
180 /**
181 * The operation completion callback to call once this operation is done
182 */
183 GNUNET_TESTBED_OperationCompletionCallback cb;
184
185 /**
186 * The closure for the above callback
187 */
188 void *cb_cls;
189
198}; 190};
199 191
200 192
diff --git a/src/testbed/testbed_api_services.c b/src/testbed/testbed_api_services.c
index f37ada310..3e8484022 100644
--- a/src/testbed/testbed_api_services.c
+++ b/src/testbed/testbed_api_services.c
@@ -49,9 +49,6 @@ enum State
49 */ 49 */
50 SERVICE_CONNECTED, 50 SERVICE_CONNECTED,
51 51
52 /**
53 *
54 */
55}; 52};
56 53
57 54
@@ -111,6 +108,16 @@ struct ServiceConnectData
111 void *op_result; 108 void *op_result;
112 109
113 /** 110 /**
111 * The operation completion callback
112 */
113 GNUNET_TESTBED_OperationCompletionCallback cb;
114
115 /**
116 * The closure for operation completion callback
117 */
118 void *cb_cls;
119
120 /**
114 * State information 121 * State information
115 */ 122 */
116 enum State state; 123 enum State state;
@@ -132,7 +139,13 @@ configuration_receiver (void *cls, const struct GNUNET_MessageHeader *msg)
132 const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *imsg; 139 const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *imsg;
133 struct GNUNET_TESTBED_Controller *c; 140 struct GNUNET_TESTBED_Controller *c;
134 struct GNUNET_TESTBED_EventInformation info; 141 struct GNUNET_TESTBED_EventInformation info;
142 uint16_t mtype;
135 143
144 mtype = ntohs (msg->type);
145 if (GNUNET_MESSAGE_TYPE_TESTBED_OPERATIONEVENT == mtype)
146 {
147 GNUNET_assert (0); /* FIXME: Add notification for failure */
148 }
136 imsg = 149 imsg =
137 (const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *) msg; 150 (const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *) msg;
138 data->cfg = GNUNET_TESTBED_get_config_from_peerinfo_msg_ (imsg); 151 data->cfg = GNUNET_TESTBED_get_config_from_peerinfo_msg_ (imsg);
@@ -141,13 +154,14 @@ configuration_receiver (void *cls, const struct GNUNET_MessageHeader *msg)
141 info.details.operation_finished.operation = data->operation; 154 info.details.operation_finished.operation = data->operation;
142 info.details.operation_finished.op_cls = data->op_cls; 155 info.details.operation_finished.op_cls = data->op_cls;
143 info.details.operation_finished.emsg = NULL; 156 info.details.operation_finished.emsg = NULL;
144 info.details.operation_finished.pit = GNUNET_TESTBED_PIT_GENERIC; 157 info.details.operation_finished.generic = data->op_result;
145 info.details.operation_finished.op_result.generic = data->op_result;
146 c = data->peer->controller; 158 c = data->peer->controller;
147 data->state = SERVICE_CONNECTED; 159 data->state = SERVICE_CONNECTED;
148 if ((0 != (GNUNET_TESTBED_ET_OPERATION_FINISHED & c->event_mask)) && 160 if ((0 != (GNUNET_TESTBED_ET_OPERATION_FINISHED & c->event_mask)) &&
149 (NULL != c->cc)) 161 (NULL != c->cc))
150 c->cc (c->cc_cls, &info); 162 c->cc (c->cc_cls, &info);
163 if (NULL != data->cb)
164 data->cb (data->cb_cls, data->operation, NULL);
151} 165}
152 166
153 167
@@ -214,7 +228,7 @@ oprelease_service_connect (void *cls)
214 * maintain connections with other systems. The actual service 228 * maintain connections with other systems. The actual service
215 * handle is then returned via the 'op_result' member in the event 229 * handle is then returned via the 'op_result' member in the event
216 * callback. The 'ca' callback is used to create the connection 230 * callback. The 'ca' callback is used to create the connection
217 * when the time is right; the 'da' callback will be used to 231 * when the time is right; the 'da' callback will be used to
218 * destroy the connection (upon 'GNUNET_TESTBED_operation_done'). 232 * destroy the connection (upon 'GNUNET_TESTBED_operation_done').
219 * 'GNUNET_TESTBED_operation_cancel' can be used to abort this 233 * 'GNUNET_TESTBED_operation_cancel' can be used to abort this
220 * operation until the event callback has been called. 234 * operation until the event callback has been called.
@@ -222,17 +236,22 @@ oprelease_service_connect (void *cls)
222 * @param op_cls closure to pass in operation event 236 * @param op_cls closure to pass in operation event
223 * @param peer peer that runs the service 237 * @param peer peer that runs the service
224 * @param service_name name of the service to connect to 238 * @param service_name name of the service to connect to
239 * @param cb the callback to call when this operation finishes
240 * @param cb_cls closure for the above callback
225 * @param ca helper function to establish the connection 241 * @param ca helper function to establish the connection
226 * @param da helper function to close the connection 242 * @param da helper function to close the connection
227 * @param cada_cls closure for ca and da 243 * @param cada_cls closure for ca and da
228 * @return handle for the operation 244 * @return handle for the operation
229 */ 245 */
230struct GNUNET_TESTBED_Operation * 246struct GNUNET_TESTBED_Operation *
231GNUNET_TESTBED_service_connect (void *op_cls, struct GNUNET_TESTBED_Peer *peer, 247GNUNET_TESTBED_service_connect (void *op_cls,
232 const char *service_name, 248 struct GNUNET_TESTBED_Peer *peer,
233 GNUNET_TESTBED_ConnectAdapter ca, 249 const char *service_name,
234 GNUNET_TESTBED_DisconnectAdapter da, 250 GNUNET_TESTBED_OperationCompletionCallback cb,
235 void *cada_cls) 251 void *cb_cls,
252 GNUNET_TESTBED_ConnectAdapter ca,
253 GNUNET_TESTBED_DisconnectAdapter da,
254 void *cada_cls)
236{ 255{
237 struct ServiceConnectData *data; 256 struct ServiceConnectData *data;
238 257
@@ -243,6 +262,8 @@ GNUNET_TESTBED_service_connect (void *op_cls, struct GNUNET_TESTBED_Peer *peer,
243 data->op_cls = op_cls; 262 data->op_cls = op_cls;
244 data->peer = peer; 263 data->peer = peer;
245 data->state = INIT; 264 data->state = INIT;
265 data->cb = cb;
266 data->cb_cls = cb_cls;
246 data->operation = 267 data->operation =
247 GNUNET_TESTBED_operation_create_ (data, &opstart_service_connect, 268 GNUNET_TESTBED_operation_create_ (data, &opstart_service_connect,
248 &oprelease_service_connect); 269 &oprelease_service_connect);