2 This file is part of GNUnet
3 (C) 2008-2011 Christian Grothoff (and other contributing authors)
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.
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.
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.
22 * @file testing/testing_peergroup.c
23 * @brief API implementation for easy peer group creation
24 * @author Nathan Evans
25 * @author Christian Grothoff
29 #include "gnunet_constants.h"
30 #include "gnunet_arm_service.h"
31 #include "gnunet_testing_lib.h"
32 #include "gnunet_core_service.h"
33 #include "gnunet_disk_lib.h"
36 #define DEFAULT_CONNECT_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30)
38 #define DEFAULT_CONNECT_ATTEMPTS 2
40 /** Struct definitions **/
42 struct PeerGroupStartupContext
44 struct GNUNET_TESTING_PeerGroup *pg;
45 const struct GNUNET_CONFIGURATION_Handle *cfg;
47 unsigned int peers_left;
48 unsigned long long max_concurrent_connections;
49 unsigned long long connect_attempts;
50 unsigned long long max_concurrent_ssh;
51 struct GNUNET_TIME_Absolute timeout;
52 GNUNET_TESTING_NotifyConnection connect_cb;
53 GNUNET_TESTING_NotifyCompletion peergroup_cb;
56 * Closure for all peergroup callbacks.
60 const struct GNUNET_TESTING_Host *hostnames;
61 enum GNUNET_TESTING_Topology topology;
63 float topology_percentage;
65 float topology_probability;
67 enum GNUNET_TESTING_Topology restrict_topology;
68 char *restrict_transports;
69 enum GNUNET_TESTING_Topology connect_topology;
70 enum GNUNET_TESTING_TopologyOption connect_topology_option;
71 double connect_topology_option_modifier;
74 struct ProgressMeter *hostkey_meter;
75 struct ProgressMeter *peer_start_meter;
76 struct ProgressMeter *connect_meter;
79 * Task used to kill the peergroup.
81 GNUNET_SCHEDULER_TaskIdentifier die_task;
86 * Variable used to store the number of connections we should wait for.
88 unsigned int expected_connections;
91 * Time when the connecting peers was started.
93 struct GNUNET_TIME_Absolute connect_start_time;
96 * The total number of connections that have been created so far.
98 unsigned int total_connections;
101 * The total number of connections that have failed so far.
103 unsigned int failed_connections;
106 * File handle to write out topology in dot format.
108 struct GNUNET_DISK_FileHandle *topology_output_file;
111 struct TopologyOutputContext
113 struct GNUNET_DISK_FileHandle *file;
114 GNUNET_TESTING_NotifyCompletion notify_cb;
119 * Simple struct to keep track of progress, and print a
120 * percentage meter for long running tasks.
125 * Total number of tasks to complete.
130 * Print percentage done after modnum tasks.
135 * Print a . each dotnum tasks.
140 * Total number completed thus far.
142 unsigned int completed;
145 * Whether or not to print.
150 * Startup string for progress meter.
152 char *startup_string;
156 /** Utility functions **/
159 * Create a meter to keep track of the progress of some task.
161 * @param total the total number of items to complete
162 * @param start_string a string to prefix the meter with (if printing)
163 * @param print GNUNET_YES to print the meter, GNUNET_NO to count
166 * @return the progress meter
168 static struct ProgressMeter *
169 create_meter (unsigned int total, char *start_string, int print)
171 struct ProgressMeter *ret;
173 ret = GNUNET_malloc (sizeof (struct ProgressMeter));
176 ret->modnum = total / 4;
177 ret->dotnum = (total / 50) + 1;
178 if (start_string != NULL)
179 ret->startup_string = GNUNET_strdup (start_string);
181 ret->startup_string = GNUNET_strdup ("");
187 * Update progress meter (increment by one).
189 * @param meter the meter to update and print info for
191 * @return GNUNET_YES if called the total requested,
192 * GNUNET_NO if more items expected
195 update_meter (struct ProgressMeter *meter)
197 if (meter->print == GNUNET_YES)
199 if (meter->completed % meter->modnum == 0)
201 if (meter->completed == 0)
203 fprintf (stdout, "%sProgress: [0%%", meter->startup_string);
206 fprintf (stdout, "%d%%",
207 (int) (((float) meter->completed / meter->total) * 100));
209 else if (meter->completed % meter->dotnum == 0)
210 fprintf (stdout, ".");
212 if (meter->completed + 1 == meter->total)
213 fprintf (stdout, "%d%%]\n", 100);
218 if (meter->completed == meter->total)
224 * Reset progress meter.
226 * @param meter the meter to reset
228 * @return GNUNET_YES if meter reset,
229 * GNUNET_SYSERR on error
232 reset_meter (struct ProgressMeter *meter)
235 return GNUNET_SYSERR;
237 meter->completed = 0;
242 * Release resources for meter
244 * @param meter the meter to free
247 free_meter (struct ProgressMeter *meter)
249 GNUNET_free_non_null (meter->startup_string);
254 /** Functions for creating, starting and connecting the peergroup **/
257 * Check whether peers successfully shut down.
260 internal_shutdown_callback (void *cls, const char *emsg)
262 struct PeerGroupStartupContext *pg_start_ctx = cls;
265 pg_start_ctx->peergroup_cb (pg_start_ctx->cls, emsg);
267 pg_start_ctx->peergroup_cb (pg_start_ctx->cls, pg_start_ctx->fail_reason);
271 * Check if the get_handle is being used, if so stop the request. Either
272 * way, schedule the end_badly_cont function which actually shuts down the
276 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
278 struct PeerGroupStartupContext *pg_start_ctx = cls;
280 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
281 "Failing peer group startup with error: `%s'!\n",
282 pg_start_ctx->fail_reason);
284 GNUNET_TESTING_daemons_stop (pg_start_ctx->pg,
285 GNUNET_TIME_absolute_get_remaining
286 (pg_start_ctx->timeout),
287 &internal_shutdown_callback, pg_start_ctx);
289 if (pg_start_ctx->hostkey_meter != NULL)
290 free_meter (pg_start_ctx->hostkey_meter);
291 if (pg_start_ctx->peer_start_meter != NULL)
292 free_meter (pg_start_ctx->peer_start_meter);
293 if (pg_start_ctx->connect_meter != NULL)
294 free_meter (pg_start_ctx->connect_meter);
298 * This function is called whenever a connection attempt is finished between two of
299 * the started peers (started with GNUNET_TESTING_daemons_start). The total
300 * number of times this function is called should equal the number returned
301 * from the GNUNET_TESTING_connect_topology call.
303 * The emsg variable is NULL on success (peers connected), and non-NULL on
304 * failure (peers failed to connect).
307 internal_topology_callback (void *cls, const struct GNUNET_PeerIdentity *first,
308 const struct GNUNET_PeerIdentity *second,
310 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
311 const struct GNUNET_CONFIGURATION_Handle
313 struct GNUNET_TESTING_Daemon *first_daemon,
314 struct GNUNET_TESTING_Daemon *second_daemon,
317 struct PeerGroupStartupContext *pg_start_ctx = cls;
323 unsigned long long duration;
324 unsigned long long total_duration;
325 unsigned int new_connections;
326 unsigned int new_failed_connections;
327 double conns_per_sec_recent;
328 double conns_per_sec_total;
329 double failed_conns_per_sec_recent;
330 double failed_conns_per_sec_total;
334 if (GNUNET_TIME_absolute_get_difference
336 GNUNET_TIME_absolute_get ()).rel_value >
337 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
338 CONN_UPDATE_DURATION).rel_value)
340 /* Get number of new connections */
341 new_connections = total_connections - previous_connections;
343 /* Get number of new FAILED connections */
344 new_failed_connections = failed_connections - previous_failed_connections;
346 /* Get duration in seconds */
348 GNUNET_TIME_absolute_get_difference (connect_last_time,
349 GNUNET_TIME_absolute_get ()).
352 GNUNET_TIME_absolute_get_difference (connect_start_time,
353 GNUNET_TIME_absolute_get ()).
356 failed_conns_per_sec_recent = (double) new_failed_connections / duration;
357 failed_conns_per_sec_total = (double) failed_connections / total_duration;
358 conns_per_sec_recent = (double) new_connections / duration;
359 conns_per_sec_total = (double) total_connections / total_duration;
360 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
361 "Recent: %.2f/s, Total: %.2f/s, Recent failed: %.2f/s, total failed %.2f/s\n",
362 conns_per_sec_recent, CONN_UPDATE_DURATION, conns_per_sec_total,
363 failed_conns_per_sec_recent, failed_conns_per_sec_total);
364 connect_last_time = GNUNET_TIME_absolute_get ();
365 previous_connections = total_connections;
366 previous_failed_connections = failed_connections;
367 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
368 "have %u total_connections, %u failed\n", total_connections,
376 pg_start_ctx->total_connections++;
378 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
379 "connected peer %s to peer %s, distance %u\n",
380 first_daemon->shortname, second_daemon->shortname, distance);
382 if (pg_start_ctx->topology_output_file != NULL)
384 second_str = GNUNET_strdup (GNUNET_i2s (second));
386 GNUNET_asprintf (&temp_str, "\t\"%s\" -- \"%s\"\n",
387 GNUNET_i2s (first), second_str);
388 GNUNET_free (second_str);
390 GNUNET_DISK_file_write (pg_start_ctx->topology_output_file, temp_str,
392 GNUNET_free (temp_str);
397 pg_start_ctx->failed_connections++;
399 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
400 "Failed to connect peer %s to peer %s with error :\n%s\n",
401 first_daemon->shortname, second_daemon->shortname, emsg);
403 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
404 "Failed to connect peer %s to peer %s with error :\n%s\n",
405 first_daemon->shortname, second_daemon->shortname, emsg);
409 GNUNET_assert (pg_start_ctx->connect_meter != NULL);
410 if (pg_start_ctx->connect_cb != NULL)
411 pg_start_ctx->connect_cb (pg_start_ctx->cls, first, second, distance,
412 first_cfg, second_cfg, first_daemon,
413 second_daemon, emsg);
414 if (GNUNET_YES == update_meter (pg_start_ctx->connect_meter))
417 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
418 "Created %d total connections, which is our target number! Starting next phase of testing.\n",
424 GNUNET_TIME_absolute_get_difference (connect_start_time,
425 GNUNET_TIME_absolute_get ()).
427 failed_conns_per_sec_total = (double) failed_connections / total_duration;
428 conns_per_sec_total = (double) total_connections / total_duration;
429 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
430 "Overall connection info --- Total: %u, Total Failed %u/s\n",
431 total_connections, failed_connections);
432 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
433 "Overall connection info --- Total: %.2f/s, Total Failed %.2f/s\n",
434 conns_per_sec_total, failed_conns_per_sec_total);
437 GNUNET_assert (pg_start_ctx->die_task != GNUNET_SCHEDULER_NO_TASK);
438 GNUNET_SCHEDULER_cancel (pg_start_ctx->die_task);
440 /* Call final callback, signifying that the peer group has been started and connected */
441 if (pg_start_ctx->peergroup_cb != NULL)
442 pg_start_ctx->peergroup_cb (pg_start_ctx->cls, NULL);
444 if (pg_start_ctx->topology_output_file != NULL)
446 temp = GNUNET_asprintf (&temp_str, "}\n");
448 GNUNET_DISK_file_write (pg_start_ctx->topology_output_file, temp_str,
450 GNUNET_free (temp_str);
451 GNUNET_DISK_file_close (pg_start_ctx->topology_output_file);
457 internal_peers_started_callback (void *cls,
458 const struct GNUNET_PeerIdentity *id,
459 const struct GNUNET_CONFIGURATION_Handle *cfg,
460 struct GNUNET_TESTING_Daemon *d,
463 struct PeerGroupStartupContext *pg_start_ctx = cls;
467 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
468 "Failed to start daemon with error: `%s'\n", emsg);
471 GNUNET_assert (id != NULL);
474 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
475 (num_peers - peers_left) + 1, num_peers);
478 pg_start_ctx->peers_left--;
480 if (GNUNET_YES == update_meter (pg_start_ctx->peer_start_meter))
483 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
484 "All %d daemons started, now connecting peers!\n", num_peers);
486 GNUNET_assert (pg_start_ctx->die_task != GNUNET_SCHEDULER_NO_TASK);
487 GNUNET_SCHEDULER_cancel (pg_start_ctx->die_task);
489 pg_start_ctx->expected_connections = UINT_MAX;
490 if ((pg_start_ctx->pg != NULL) && (pg_start_ctx->peers_left == 0))
492 pg_start_ctx->connect_start_time = GNUNET_TIME_absolute_get ();
493 pg_start_ctx->expected_connections =
494 GNUNET_TESTING_connect_topology (pg_start_ctx->pg,
495 pg_start_ctx->connect_topology,
497 connect_topology_option,
499 connect_topology_option_modifier,
500 DEFAULT_CONNECT_TIMEOUT,
501 pg_start_ctx->connect_attempts, NULL,
504 pg_start_ctx->connect_meter =
505 create_meter (pg_start_ctx->expected_connections, "Peer connection ",
506 pg_start_ctx->verbose);
507 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Have %d expected connections\n",
508 pg_start_ctx->expected_connections);
511 if (pg_start_ctx->expected_connections == 0)
513 GNUNET_free_non_null (pg_start_ctx->fail_reason);
514 pg_start_ctx->fail_reason =
515 GNUNET_strdup ("from connect topology (bad return)");
516 pg_start_ctx->die_task =
517 GNUNET_SCHEDULER_add_now (&end_badly, pg_start_ctx);
520 GNUNET_free_non_null (pg_start_ctx->fail_reason);
521 pg_start_ctx->fail_reason =
522 GNUNET_strdup ("from connect topology (timeout)");
523 pg_start_ctx->die_task =
524 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
525 (pg_start_ctx->timeout), &end_badly,
531 * Callback indicating that the hostkey was created for a peer.
534 * @param id the peer identity
535 * @param d the daemon handle (pretty useless at this point, remove?)
536 * @param emsg non-null on failure
539 internal_hostkey_callback (void *cls, const struct GNUNET_PeerIdentity *id,
540 struct GNUNET_TESTING_Daemon *d, const char *emsg)
542 struct PeerGroupStartupContext *pg_start_ctx = cls;
543 unsigned int create_expected_connections;
547 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
548 "Hostkey callback received error: %s\n", emsg);
552 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
553 "Hostkey (%d/%d) created for peer `%s'\n", num_peers - peers_left,
554 num_peers, GNUNET_i2s (id));
557 pg_start_ctx->peers_left--;
558 if (GNUNET_YES == update_meter (pg_start_ctx->hostkey_meter))
560 GNUNET_SCHEDULER_cancel (pg_start_ctx->die_task);
561 /* Set up task in case topology creation doesn't finish
562 * within a reasonable amount of time */
563 pg_start_ctx->die_task =
564 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
565 (pg_start_ctx->timeout), &end_badly,
566 "from create_topology");
567 pg_start_ctx->peers_left = pg_start_ctx->total; /* Reset counter */
568 create_expected_connections =
569 GNUNET_TESTING_create_topology (pg_start_ctx->pg,
570 pg_start_ctx->topology,
571 pg_start_ctx->restrict_topology,
572 pg_start_ctx->restrict_transports);
573 if (create_expected_connections > 0)
575 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
576 "Topology set up, have %u expected connections, now starting peers!\n",
577 create_expected_connections);
578 GNUNET_TESTING_daemons_continue_startup (pg_start_ctx->pg);
582 GNUNET_SCHEDULER_cancel (pg_start_ctx->die_task);
583 pg_start_ctx->die_task =
584 GNUNET_SCHEDULER_add_now (&end_badly,
585 "from create topology (bad return)");
588 GNUNET_SCHEDULER_cancel (pg_start_ctx->die_task);
589 pg_start_ctx->die_task =
590 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
591 (pg_start_ctx->timeout), &end_badly,
592 "from continue startup (timeout)");
598 * Prototype of a callback function indicating that two peers
599 * are currently connected.
602 * @param first peer id for first daemon
603 * @param second peer id for the second daemon
604 * @param distance distance between the connected peers
605 * @param emsg error message (NULL on success)
608 write_topology_cb (void *cls, const struct GNUNET_PeerIdentity *first,
609 const struct GNUNET_PeerIdentity *second, const char *emsg)
611 struct TopologyOutputContext *topo_ctx;
616 topo_ctx = (struct TopologyOutputContext *) cls;
617 GNUNET_assert (topo_ctx->file != NULL);
618 if ((emsg == NULL) && (first != NULL) && (second != NULL))
620 GNUNET_assert (first != NULL);
621 GNUNET_assert (second != NULL);
622 temp_pid2 = GNUNET_strdup (GNUNET_i2s (second));
624 GNUNET_asprintf (&temp_str, "\t\"%s\" -- \"%s\"\n", GNUNET_i2s (first),
626 GNUNET_free (temp_pid2);
627 GNUNET_DISK_file_write (topo_ctx->file, temp_str, temp);
629 else if ((emsg == NULL) && (first == NULL) && (second == NULL))
631 temp = GNUNET_asprintf (&temp_str, "}\n");
632 GNUNET_DISK_file_write (topo_ctx->file, temp_str, temp);
633 GNUNET_DISK_file_close (topo_ctx->file);
634 topo_ctx->notify_cb (topo_ctx->notify_cb_cls, NULL);
635 GNUNET_free (topo_ctx);
639 temp = GNUNET_asprintf (&temp_str, "}\n");
640 GNUNET_DISK_file_write (topo_ctx->file, temp_str, temp);
641 GNUNET_DISK_file_close (topo_ctx->file);
642 topo_ctx->notify_cb (topo_ctx->notify_cb_cls, emsg);
643 GNUNET_free (topo_ctx);
648 * Print current topology to a graphviz readable file.
650 * @param pg a currently running peergroup to print to file
651 * @param output_filename the file to write the topology to
652 * @param notify_cb callback to call upon completion or failure
653 * @param notify_cb_cls closure for notify_cb
657 GNUNET_TESTING_peergroup_topology_to_file (struct GNUNET_TESTING_PeerGroup *pg,
658 const char *output_filename,
659 GNUNET_TESTING_NotifyCompletion
660 notify_cb, void *notify_cb_cls)
662 struct TopologyOutputContext *topo_ctx;
666 topo_ctx = GNUNET_malloc (sizeof (struct TopologyOutputContext));
668 topo_ctx->notify_cb = notify_cb;
669 topo_ctx->notify_cb_cls = notify_cb_cls;
671 GNUNET_DISK_file_open (output_filename,
672 GNUNET_DISK_OPEN_READWRITE |
673 GNUNET_DISK_OPEN_CREATE,
674 GNUNET_DISK_PERM_USER_READ |
675 GNUNET_DISK_PERM_USER_WRITE);
676 if (topo_ctx->file == NULL)
678 notify_cb (notify_cb_cls, "Failed to open output file!");
679 GNUNET_free (topo_ctx);
683 temp = GNUNET_asprintf (&temp_str, "strict graph G {\n");
685 GNUNET_DISK_file_write (topo_ctx->file, temp_str, temp);
686 GNUNET_free_non_null (temp_str);
687 GNUNET_TESTING_get_topology (pg, &write_topology_cb, topo_ctx);
691 * Start a peer group with a given number of peers. Notify
692 * on completion of peer startup and connection based on given
693 * topological constraints. Optionally notify on each
694 * established connection.
696 * @param cfg configuration template to use
697 * @param total number of daemons to start
698 * @param timeout total time allowed for peers to start
699 * @param connect_cb function to call each time two daemons are connected
700 * @param peergroup_cb function to call once all peers are up and connected
701 * @param peergroup_cls closure for peergroup callbacks
702 * @param hostnames linked list of host structs to use to start peers on
703 * (NULL to run on localhost only)
705 * @return NULL on error, otherwise handle to control peer group
707 struct GNUNET_TESTING_PeerGroup *
708 GNUNET_TESTING_peergroup_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
710 struct GNUNET_TIME_Relative timeout,
711 GNUNET_TESTING_NotifyConnection connect_cb,
712 GNUNET_TESTING_NotifyCompletion peergroup_cb,
714 const struct GNUNET_TESTING_Host *hostnames)
716 struct PeerGroupStartupContext *pg_start_ctx;
717 unsigned long long temp_config_number;
721 GNUNET_assert (total > 0);
722 GNUNET_assert (cfg != NULL);
724 pg_start_ctx = GNUNET_malloc (sizeof (struct PeerGroupStartupContext));
727 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_attempts",
728 &pg_start_ctx->connect_attempts))
730 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
731 "testing", "connect_attempts");
732 GNUNET_free (pg_start_ctx);
737 GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
738 "max_outstanding_connections",
740 max_concurrent_connections))
742 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
743 "testing", "max_outstanding_connections");
744 GNUNET_free (pg_start_ctx);
749 GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
750 "max_concurrent_ssh",
751 &pg_start_ctx->max_concurrent_ssh))
753 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
754 "testing", "max_concurrent_ssh");
755 GNUNET_free (pg_start_ctx);
760 (pg_start_ctx->verbose =
761 GNUNET_CONFIGURATION_get_value_yesno (cfg, "testing",
762 "use_progressbars")))
764 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
765 "testing", "use_progressbars");
766 GNUNET_free (pg_start_ctx);
771 GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
773 &temp_config_number))
774 pg_start_ctx->timeout =
775 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply
776 (GNUNET_TIME_UNIT_SECONDS,
777 temp_config_number));
780 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
781 "testing", "peergroup_timeout");
782 GNUNET_free (pg_start_ctx);
787 /* Read topology related options from the configuration file */
790 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "topology",
793 GNUNET_TESTING_topology_get (&pg_start_ctx->topology, temp_str)))
795 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
796 "Invalid topology `%s' given for section %s option %s\n",
797 temp_str, "TESTING", "TOPOLOGY");
798 pg_start_ctx->topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */
800 GNUNET_free_non_null (temp_str);
803 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
804 "topology_output_file", &temp_str))
806 pg_start_ctx->topology_output_file =
807 GNUNET_DISK_file_open (temp_str,
808 GNUNET_DISK_OPEN_READWRITE |
809 GNUNET_DISK_OPEN_CREATE,
810 GNUNET_DISK_PERM_USER_READ |
811 GNUNET_DISK_PERM_USER_WRITE);
812 if (pg_start_ctx->topology_output_file != NULL)
814 GNUNET_free (temp_str);
815 temp = GNUNET_asprintf (&temp_str, "strict graph G {\n");
817 GNUNET_DISK_file_write (pg_start_ctx->topology_output_file, temp_str,
820 GNUNET_free (temp_str);
824 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "percentage",
826 pg_start_ctx->topology_percentage = 0.5;
829 pg_start_ctx->topology_percentage = atof (temp_str);
830 GNUNET_free (temp_str);
834 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "probability",
836 pg_start_ctx->topology_probability = 0.5;
839 pg_start_ctx->topology_probability = atof (temp_str);
840 GNUNET_free (temp_str);
844 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
845 "connect_topology", &temp_str)) &&
847 GNUNET_TESTING_topology_get (&pg_start_ctx->connect_topology, temp_str)))
849 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
850 "Invalid connect topology `%s' given for section %s option %s\n",
851 temp_str, "TESTING", "CONNECT_TOPOLOGY");
853 GNUNET_free_non_null (temp_str);
856 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
857 "connect_topology_option",
860 GNUNET_TESTING_topology_option_get (&pg_start_ctx->
861 connect_topology_option, temp_str)))
863 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
864 "Invalid connect topology option `%s' given for section %s option %s\n",
865 temp_str, "TESTING", "CONNECT_TOPOLOGY_OPTION");
866 pg_start_ctx->connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */
868 GNUNET_free_non_null (temp_str);
871 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
872 "connect_topology_option_modifier",
876 (temp_str, "%lf", &pg_start_ctx->connect_topology_option_modifier) != 1)
878 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
880 ("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
881 temp_str, "connect_topology_option_modifier", "TESTING");
882 GNUNET_free (temp_str);
883 GNUNET_free (pg_start_ctx);
886 GNUNET_free (temp_str);
890 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
891 "blacklist_transports",
893 restrict_transports))
894 pg_start_ctx->restrict_transports = NULL;
896 pg_start_ctx->restrict_topology = GNUNET_TESTING_TOPOLOGY_NONE;
898 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
899 "blacklist_topology", &temp_str))
901 GNUNET_TESTING_topology_get (&pg_start_ctx->restrict_topology,
904 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
905 "Invalid topology `%s' given for section %s option %s\n",
906 temp_str, "TESTING", "BLACKLIST_TOPOLOGY");
909 GNUNET_free_non_null (temp_str);
911 pg_start_ctx->cfg = cfg;
912 pg_start_ctx->total = total;
913 pg_start_ctx->peers_left = total;
914 pg_start_ctx->connect_cb = connect_cb;
915 pg_start_ctx->peergroup_cb = peergroup_cb;
916 pg_start_ctx->cls = peergroup_cls;
917 pg_start_ctx->hostnames = hostnames;
918 pg_start_ctx->hostkey_meter =
919 create_meter (pg_start_ctx->peers_left, "Hostkeys created ",
920 pg_start_ctx->verbose);
921 pg_start_ctx->peer_start_meter =
922 create_meter (pg_start_ctx->peers_left, "Peers started ",
923 pg_start_ctx->verbose);
924 /* Make compilers happy */
925 reset_meter (pg_start_ctx->peer_start_meter);
926 pg_start_ctx->die_task =
927 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
928 (pg_start_ctx->timeout), &end_badly,
929 "didn't generate all hostkeys within allowed startup time!");
932 GNUNET_TESTING_daemons_start (pg_start_ctx->cfg, pg_start_ctx->peers_left,
933 pg_start_ctx->max_concurrent_connections,
934 pg_start_ctx->max_concurrent_ssh,
935 GNUNET_TIME_absolute_get_remaining
936 (pg_start_ctx->timeout),
937 &internal_hostkey_callback, pg_start_ctx,
938 &internal_peers_started_callback,
939 pg_start_ctx, &internal_topology_callback,
940 pg_start_ctx, pg_start_ctx->hostnames);
942 return pg_start_ctx->pg;
945 /* end of testing_peergroup.c */