aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-05-09 15:51:00 +0000
committerNathan S. Evans <evans@in.tum.de>2010-05-09 15:51:00 +0000
commitca3d4f99562556e22eeac7f7f198ff12941a9e1e (patch)
tree9793f550abc079e11dff93889ae23d75cb7ae4a3
parent973122ac7d885ba4e9d9397682ff2eabeef0adc3 (diff)
downloadgnunet-ca3d4f99562556e22eeac7f7f198ff12941a9e1e.tar.gz
gnunet-ca3d4f99562556e22eeac7f7f198ff12941a9e1e.zip
library changes for testing
-rw-r--r--src/include/gnunet_server_lib.h2
-rw-r--r--src/include/gnunet_testing_lib.h215
2 files changed, 196 insertions, 21 deletions
diff --git a/src/include/gnunet_server_lib.h b/src/include/gnunet_server_lib.h
index a24e709dc..6d495c1c0 100644
--- a/src/include/gnunet_server_lib.h
+++ b/src/include/gnunet_server_lib.h
@@ -326,7 +326,7 @@ typedef int (*GNUNET_SERVER_CheckCallback) (void *cls);
326 * Destroy this connection (free resources). 326 * Destroy this connection (free resources).
327 * 327 *
328 * @param cls closure 328 * @param cls closure
329 * @param persist when connection is closed, "leak" socket 329 * @pararm persist when connection is closed, "leak" socket
330 */ 330 */
331typedef void (*GNUNET_SERVER_DestroyCallback) (void *cls, int persist); 331typedef void (*GNUNET_SERVER_DestroyCallback) (void *cls, int persist);
332 332
diff --git a/src/include/gnunet_testing_lib.h b/src/include/gnunet_testing_lib.h
index 4a4eb4331..5343e7c5c 100644
--- a/src/include/gnunet_testing_lib.h
+++ b/src/include/gnunet_testing_lib.h
@@ -49,6 +49,19 @@ extern "C"
49 */ 49 */
50struct GNUNET_TESTING_Daemon; 50struct GNUNET_TESTING_Daemon;
51 51
52/**
53 * Prototype of a function that will be called whenever
54 * a daemon was started by the testing library.
55 *
56 * @param cls closure
57 * @param id identifier for the daemon, NULL on error
58 * @param d handle for the daemon
59 * @param emsg error message (NULL on success)
60 */
61typedef void (*GNUNET_TESTING_NotifyHostkeyCreated)(void *cls,
62 const struct GNUNET_PeerIdentity *id,
63 struct GNUNET_TESTING_Daemon *d,
64 const char *emsg);
52 65
53/** 66/**
54 * Prototype of a function that will be called whenever 67 * Prototype of a function that will be called whenever
@@ -83,11 +96,26 @@ enum GNUNET_TESTING_StartPhase
83 SP_COPYING, 96 SP_COPYING,
84 97
85 /** 98 /**
86 * Configuration file has been copied, start ARM on target system. 99 * Configuration file has been copied, generate hostkey.
87 */ 100 */
88 SP_COPIED, 101 SP_COPIED,
89 102
90 /** 103 /**
104 * Create the hostkey for the peer.
105 */
106 SP_HOSTKEY_CREATE,
107
108 /**
109 * Hostkey generated, wait for topology to be finished.
110 */
111 SP_HOSTKEY_CREATED,
112
113 /**
114 * Topology has been created, now start ARM.
115 */
116 SP_TOPOLOGY_SETUP,
117
118 /**
91 * ARM has been started, check that it has properly daemonized and 119 * ARM has been started, check that it has properly daemonized and
92 * then try to connect to the CORE service (which should be 120 * then try to connect to the CORE service (which should be
93 * auto-started by ARM). 121 * auto-started by ARM).
@@ -132,6 +160,16 @@ typedef void (*GNUNET_TESTING_NotifyCompletion)(void *cls,
132 const char *emsg); 160 const char *emsg);
133 161
134/** 162/**
163 * Prototype of a function that will be called with the
164 * number of connections created for a particular topology.
165 *
166 * @param cls closure
167 * @param num_connections the number of connections created
168 */
169typedef void (*GNUNET_TESTING_NotifyConnections)(void *cls,
170 unsigned int num_connections);
171
172/**
135 * Handle for a GNUnet daemon (technically a set of 173 * Handle for a GNUnet daemon (technically a set of
136 * daemons; the handle is really for the master ARM 174 * daemons; the handle is really for the master ARM
137 * daemon) started by the testing library. 175 * daemon) started by the testing library.
@@ -170,6 +208,17 @@ struct GNUNET_TESTING_Daemon
170 char *cfgfile; 208 char *cfgfile;
171 209
172 /** 210 /**
211 * Callback to inform initiator that the peer's
212 * hostkey has been created.
213 */
214 GNUNET_TESTING_NotifyHostkeyCreated hostkey_callback;
215
216 /**
217 * Closure for hostkey creation callback.
218 */
219 void *hostkey_cls;
220
221 /**
173 * Function to call when the peer is running. 222 * Function to call when the peer is running.
174 */ 223 */
175 GNUNET_TESTING_NotifyDaemonRunning cb; 224 GNUNET_TESTING_NotifyDaemonRunning cb;
@@ -249,6 +298,11 @@ struct GNUNET_TESTING_Daemon
249 struct GNUNET_HELLO_Message *hello; 298 struct GNUNET_HELLO_Message *hello;
250 299
251 /** 300 /**
301 * Handle to a pipe for reading the hostkey.
302 */
303 struct GNUNET_DISK_PipeHandle *pipe_stdout;
304
305 /**
252 * Set to GNUNET_YES once the peer is up. 306 * Set to GNUNET_YES once the peer is up.
253 */ 307 */
254 int running; 308 int running;
@@ -293,17 +347,50 @@ typedef void (*GNUNET_TESTING_NotifyConnection)(void *cls,
293 * @param cfg configuration to use 347 * @param cfg configuration to use
294 * @param hostname name of the machine where to run GNUnet 348 * @param hostname name of the machine where to run GNUnet
295 * (use NULL for localhost). 349 * (use NULL for localhost).
350 * @param hostkey_callback function to call once the hostkey has been
351 * generated for this peer, but it hasn't yet been started
352 * (NULL to start immediately, otherwise waits on GNUNET_TESTING_daemon_continue_start)
353 * @param hostkey_cls closure for hostkey callback
296 * @param cb function to call with the result 354 * @param cb function to call with the result
297 * @param cb_cls closure for cb 355 * @param cb_cls closure for cb
298 * @return handle to the daemon (actual start will be completed asynchronously) 356 * @return handle to the daemon (actual start will be completed asynchronously)
299 */ 357 */
300struct GNUNET_TESTING_Daemon * 358struct GNUNET_TESTING_Daemon *
301GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched, 359GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched,
302 const struct GNUNET_CONFIGURATION_Handle *cfg, 360 const struct GNUNET_CONFIGURATION_Handle *cfg,
303 const char *hostname, 361 const char *hostname,
304 GNUNET_TESTING_NotifyDaemonRunning cb, 362 GNUNET_TESTING_NotifyHostkeyCreated hostkey_callback,
305 void *cb_cls); 363 void *hostkey_cls,
364 GNUNET_TESTING_NotifyDaemonRunning cb,
365 void *cb_cls);
366
367/**
368 * Continues GNUnet daemon startup when user wanted to be notified
369 * once a hostkey was generated (for creating friends files, blacklists,
370 * etc.).
371 *
372 * @param daemon the daemon to finish starting
373 */
374void
375GNUNET_TESTING_daemon_continue_startup(struct GNUNET_TESTING_Daemon *daemon);
376
377/**
378 * Restart (stop and start) a GNUnet daemon.
379 *
380 * @param d the daemon that should be restarted
381 * @param cb function called once the daemon is (re)started
382 * @param cb_cls closure for cb
383 */
384void
385GNUNET_TESTING_daemon_restart (struct GNUNET_TESTING_Daemon *d,
386 GNUNET_TESTING_NotifyDaemonRunning cb, void *cb_cls);
306 387
388/**
389 * Get a certain testing daemon handle.
390 *
391 * @param pg handle to the set of running peers
392 * @param position the number of the peer to return
393 */
307struct GNUNET_TESTING_Daemon * 394struct GNUNET_TESTING_Daemon *
308GNUNET_TESTING_daemon_get (struct GNUNET_TESTING_PeerGroup *pg, unsigned int position); 395GNUNET_TESTING_daemon_get (struct GNUNET_TESTING_PeerGroup *pg, unsigned int position);
309 396
@@ -314,10 +401,12 @@ GNUNET_TESTING_daemon_get (struct GNUNET_TESTING_PeerGroup *pg, unsigned int pos
314 * @param d the daemon that should be stopped 401 * @param d the daemon that should be stopped
315 * @param cb function called once the daemon was stopped 402 * @param cb function called once the daemon was stopped
316 * @param cb_cls closure for cb 403 * @param cb_cls closure for cb
404 * @param delete_files GNUNET_YES to remove files, GNUNET_NO
405 * to leave them (i.e., for a restart)
317 */ 406 */
318void GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, 407void GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
319 GNUNET_TESTING_NotifyCompletion cb, 408 GNUNET_TESTING_NotifyCompletion cb,
320 void * cb_cls); 409 void * cb_cls, int delete_files);
321 410
322 411
323/** 412/**
@@ -365,23 +454,53 @@ void GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
365 * @param sched scheduler to use 454 * @param sched scheduler to use
366 * @param cfg configuration template to use 455 * @param cfg configuration template to use
367 * @param total number of daemons to start 456 * @param total number of daemons to start
457 * @param hostkey_callback function to call on each peers hostkey generation
458 * if NULL, peers will be started by this call, if non-null,
459 * GNUNET_TESTING_daemons_continue_startup must be called after
460 * successful hostkey generation
461 * @param hostkey_cls closure for hostkey callback
368 * @param cb function to call on each daemon that was started 462 * @param cb function to call on each daemon that was started
369 * @param cb_cls closure for cb 463 * @param cb_cls closure for cb
370 * @param connect_callback function to call each time two hosts are connected 464 * @param connect_callback function to call each time two hosts are connected
371 * @param connect_callback_cls closure for connect_callback 465 * @param connect_callback_cls closure for connect_callback
372 * @param hostnames space-separated list of hostnames to use, 466 * @param hostnames space-separated list of hostnames to use; can be NULL (to run
373 * NULL to use localhost only 467 * everything on localhost).
374 * @return NULL on error, otherwise handle to control peer group 468 * @return NULL on error, otherwise handle to control peer group
375 */ 469 */
376struct GNUNET_TESTING_PeerGroup * 470struct GNUNET_TESTING_PeerGroup *
377GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched, 471GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
378 const struct GNUNET_CONFIGURATION_Handle *cfg, 472 const struct GNUNET_CONFIGURATION_Handle *cfg,
379 unsigned int total, 473 unsigned int total,
380 GNUNET_TESTING_NotifyDaemonRunning cb, 474 GNUNET_TESTING_NotifyHostkeyCreated hostkey_callback,
381 void *cb_cls, 475 void *hostkey_cls,
382 GNUNET_TESTING_NotifyConnection connect_callback, 476 GNUNET_TESTING_NotifyDaemonRunning cb,
383 void *connect_callback_cls, 477 void *cb_cls,
384 const char *hostnames); 478 GNUNET_TESTING_NotifyConnection
479 connect_callback, void *connect_callback_cls,
480 const char *hostnames);
481
482/**
483 * Function which continues a peer group starting up
484 * after successfully generating hostkeys for each peer.
485 *
486 * @param pg the peer group to continue starting
487 *
488 */
489void
490GNUNET_TESTING_daemons_continue_startup(struct GNUNET_TESTING_PeerGroup *pg);
491
492/**
493 * Restart all peers in the given group.
494 *
495 * @param pg the handle to the peer group
496 * @param timeout how long to wait on failure
497 * @param callback function to call on completion (or failure)
498 * @param callback_cls closure for the callback function
499 */
500void
501GNUNET_TESTING_daemons_restart (struct GNUNET_TESTING_PeerGroup *pg,
502 GNUNET_TESTING_NotifyCompletion callback,
503 void *callback_cls);
385 504
386 505
387/** 506/**
@@ -445,17 +564,73 @@ enum GNUNET_TESTING_Topology
445 GNUNET_TESTING_TOPOLOGY_NONE 564 GNUNET_TESTING_TOPOLOGY_NONE
446}; 565};
447 566
448
449/** 567/**
450 * Create a topology out for a group of started peers. 568 * Options for connecting a topology.
569 */
570enum GNUNET_TESTING_TopologyOption
571{
572 /**
573 * Try to connect all peers specified in the topology.
574 */
575 GNUNET_TESTING_TOPOLOGY_OPTION_ALL,
576
577 /**
578 * Choose a random subset of connections to create.
579 */
580 GNUNET_TESTING_TOPOLOGY_OPTION_RANDOM,
581
582 /**
583 * Create at least X connections for each peer.
584 */
585 GNUNET_TESTING_TOPOLOGY_OPTION_MINIMUM,
586
587 /**
588 * Using a depth first search, create one connection
589 * per peer. If any are missed (graph disconnected)
590 * start over at those peers until all have at least one
591 * connection.
592 */
593 GNUNET_TESTING_TOPOLOGY_OPTION_DFS,
594
595 /**
596 * No options specified.
597 */
598 GNUNET_TESTING_TOPOLOGY_OPTION_NONE
599};
600
601/*
602 * Takes a peer group and creates a topology based on the
603 * one specified. Creates a topology means generates friend
604 * files for the peers so they can only connect to those allowed
605 * by the topology. This will only have an effect once peers
606 * are started if the FRIENDS_ONLY option is set in the base
607 * config. Also takes an optional restrict topology which
608 * disallows direct TCP connections UNLESS they are specified in
609 * the restricted topology.
610 *
611 * @param pg the peer group struct representing the running peers
612 * @param topology which topology to connect the peers in
613 * @param restrict_topology allow only direct TCP connections in this topology
451 * 614 *
452 * @param pg the peergroup that has already been started 615 * @return the maximum number of connections were all allowed peers
453 * @param topology the topology to connect the peers into 616 * connected to each other
454 */ 617 */
455int 618int
456GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, 619GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg,
457 enum GNUNET_TESTING_Topology topology); 620 enum GNUNET_TESTING_Topology topology,
621 enum GNUNET_TESTING_Topology restrict_topology);
458 622
623/*
624 * @param pg the peer group struct representing the running peers
625 * @param topology which topology to connect the peers in
626 * @param options options for connecting the topology
627 * @param option_modifier modifier for options that take a parameter
628 */
629int
630GNUNET_TESTING_connect_topology (struct GNUNET_TESTING_PeerGroup *pg,
631 enum GNUNET_TESTING_Topology topology,
632 enum GNUNET_TESTING_TopologyOption options,
633 double option_modifier);
459 634
460/** 635/**
461 * Start "count" GNUnet daemons with a particular topology. 636 * Start "count" GNUnet daemons with a particular topology.