aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dht/gnunet-dht-driver.c2
-rw-r--r--src/dht/test_dht_multipeer.c2
-rw-r--r--src/dht/test_dht_twopeer.c2
-rw-r--r--src/dht/test_dht_twopeer_put_get.c2
-rw-r--r--src/dv/test_transport_api_dv.c2
-rw-r--r--src/include/gnunet_testing_lib.h7
-rw-r--r--src/testing/test_testing_topology.c9
-rw-r--r--src/testing/test_testing_topology_blacklist.c2
-rw-r--r--src/testing/testing_group.c140
9 files changed, 125 insertions, 43 deletions
diff --git a/src/dht/gnunet-dht-driver.c b/src/dht/gnunet-dht-driver.c
index e91b1f04e..6ebb4da8a 100644
--- a/src/dht/gnunet-dht-driver.c
+++ b/src/dht/gnunet-dht-driver.c
@@ -2380,7 +2380,7 @@ peers_started_callback (void *cls,
2380 expected_connections = UINT_MAX; 2380 expected_connections = UINT_MAX;
2381 if ((pg != NULL) && (peers_left == 0)) 2381 if ((pg != NULL) && (peers_left == 0))
2382 { 2382 {
2383 expected_connections = GNUNET_TESTING_connect_topology (pg, connect_topology, connect_topology_option, connect_topology_option_modifier); 2383 expected_connections = GNUNET_TESTING_connect_topology (pg, connect_topology, connect_topology_option, connect_topology_option_modifier, NULL, NULL);
2384 2384
2385 peer_connect_meter = create_meter(expected_connections, "Peer connection ", GNUNET_YES); 2385 peer_connect_meter = create_meter(expected_connections, "Peer connection ", GNUNET_YES);
2386 fprintf(stderr, "Have %d expected connections\n", expected_connections); 2386 fprintf(stderr, "Have %d expected connections\n", expected_connections);
diff --git a/src/dht/test_dht_multipeer.c b/src/dht/test_dht_multipeer.c
index 65eb213e2..dc877c28b 100644
--- a/src/dht/test_dht_multipeer.c
+++ b/src/dht/test_dht_multipeer.c
@@ -666,7 +666,7 @@ peers_started_callback (void *cls,
666 expected_connections = -1; 666 expected_connections = -1;
667 if ((pg != NULL) && (peers_left == 0)) 667 if ((pg != NULL) && (peers_left == 0))
668 { 668 {
669 expected_connections = GNUNET_TESTING_connect_topology (pg, connection_topology, connect_topology_option, connect_topology_option_modifier); 669 expected_connections = GNUNET_TESTING_connect_topology (pg, connection_topology, connect_topology_option, connect_topology_option_modifier, NULL, NULL);
670#if VERBOSE 670#if VERBOSE
671 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 671 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
672 "Have %d expected connections\n", expected_connections); 672 "Have %d expected connections\n", expected_connections);
diff --git a/src/dht/test_dht_twopeer.c b/src/dht/test_dht_twopeer.c
index 02e789069..ade8e65bd 100644
--- a/src/dht/test_dht_twopeer.c
+++ b/src/dht/test_dht_twopeer.c
@@ -320,7 +320,7 @@ connect_topology (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
320{ 320{
321 expected_connections = -1; 321 expected_connections = -1;
322 if ((pg != NULL) && (peers_left == 0)) 322 if ((pg != NULL) && (peers_left == 0))
323 expected_connections = GNUNET_TESTING_connect_topology (pg, GNUNET_TESTING_TOPOLOGY_CLIQUE, GNUNET_TESTING_TOPOLOGY_OPTION_ALL, 0.0); 323 expected_connections = GNUNET_TESTING_connect_topology (pg, GNUNET_TESTING_TOPOLOGY_CLIQUE, GNUNET_TESTING_TOPOLOGY_OPTION_ALL, 0.0, NULL, NULL);
324 324
325 GNUNET_SCHEDULER_cancel (sched, die_task); 325 GNUNET_SCHEDULER_cancel (sched, die_task);
326 if (expected_connections == GNUNET_SYSERR) 326 if (expected_connections == GNUNET_SYSERR)
diff --git a/src/dht/test_dht_twopeer_put_get.c b/src/dht/test_dht_twopeer_put_get.c
index 1aa83716b..b57faeb83 100644
--- a/src/dht/test_dht_twopeer_put_get.c
+++ b/src/dht/test_dht_twopeer_put_get.c
@@ -407,7 +407,7 @@ peers_started_callback (void *cls,
407 if ((pg != NULL)) /* Sanity check */ 407 if ((pg != NULL)) /* Sanity check */
408 { 408 {
409 /* Connect peers in a "straight line" topology, return the number of expected connections */ 409 /* Connect peers in a "straight line" topology, return the number of expected connections */
410 expected_connections = GNUNET_TESTING_connect_topology (pg, GNUNET_TESTING_TOPOLOGY_LINE, GNUNET_TESTING_TOPOLOGY_OPTION_ALL, 0.0); 410 expected_connections = GNUNET_TESTING_connect_topology (pg, GNUNET_TESTING_TOPOLOGY_LINE, GNUNET_TESTING_TOPOLOGY_OPTION_ALL, 0.0, NULL, NULL);
411 } 411 }
412 412
413 /* Cancel current timeout fail task */ 413 /* Cancel current timeout fail task */
diff --git a/src/dv/test_transport_api_dv.c b/src/dv/test_transport_api_dv.c
index 244966300..d38f378ba 100644
--- a/src/dv/test_transport_api_dv.c
+++ b/src/dv/test_transport_api_dv.c
@@ -757,7 +757,7 @@ connect_topology ()
757 expected_connections = -1; 757 expected_connections = -1;
758 if ((pg != NULL) && (peers_left == 0)) 758 if ((pg != NULL) && (peers_left == 0))
759 { 759 {
760 expected_connections = GNUNET_TESTING_connect_topology (pg, connection_topology, connect_topology_option, connect_topology_option_modifier); 760 expected_connections = GNUNET_TESTING_connect_topology (pg, connection_topology, connect_topology_option, connect_topology_option_modifier, NULL, NULL);
761#if VERBOSE 761#if VERBOSE
762 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 762 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
763 "Have %d expected connections\n", expected_connections); 763 "Have %d expected connections\n", expected_connections);
diff --git a/src/include/gnunet_testing_lib.h b/src/include/gnunet_testing_lib.h
index e443c2f92..e0ea15fcd 100644
--- a/src/include/gnunet_testing_lib.h
+++ b/src/include/gnunet_testing_lib.h
@@ -879,13 +879,18 @@ GNUNET_TESTING_get_topology (struct GNUNET_TESTING_PeerGroup *pg,
879 * @param topology which topology to connect the peers in 879 * @param topology which topology to connect the peers in
880 * @param options options for connecting the topology 880 * @param options options for connecting the topology
881 * @param option_modifier modifier for options that take a parameter 881 * @param option_modifier modifier for options that take a parameter
882 * @param notify_callback notification to be called once all connections completed
883 * @param notify_cls closure for notification callback
884 *
882 * @return the number of connections that will be attempted, GNUNET_SYSERR on error 885 * @return the number of connections that will be attempted, GNUNET_SYSERR on error
883 */ 886 */
884int 887int
885GNUNET_TESTING_connect_topology (struct GNUNET_TESTING_PeerGroup *pg, 888GNUNET_TESTING_connect_topology (struct GNUNET_TESTING_PeerGroup *pg,
886 enum GNUNET_TESTING_Topology topology, 889 enum GNUNET_TESTING_Topology topology,
887 enum GNUNET_TESTING_TopologyOption options, 890 enum GNUNET_TESTING_TopologyOption options,
888 double option_modifier); 891 double option_modifier,
892 GNUNET_TESTING_NotifyCompletion notify_callback,
893 void *notify_cls);
889 894
890/** 895/**
891 * Start or stop an individual peer from the given group. 896 * Start or stop an individual peer from the given group.
diff --git a/src/testing/test_testing_topology.c b/src/testing/test_testing_topology.c
index 8e28a8372..83c96a451 100644
--- a/src/testing/test_testing_topology.c
+++ b/src/testing/test_testing_topology.c
@@ -706,13 +706,20 @@ topology_callback (void *cls,
706 } 706 }
707} 707}
708 708
709static void topology_creation_finished (void *cls,
710 const char *emsg)
711{
712 if (emsg == NULL)
713 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "All topology connections created successfully!\n");
714}
715
709static void 716static void
710connect_topology () 717connect_topology ()
711{ 718{
712 expected_connections = -1; 719 expected_connections = -1;
713 if ((pg != NULL) && (peers_left == 0)) 720 if ((pg != NULL) && (peers_left == 0))
714 { 721 {
715 expected_connections = GNUNET_TESTING_connect_topology (pg, connection_topology, connect_topology_option, connect_topology_option_modifier); 722 expected_connections = GNUNET_TESTING_connect_topology (pg, connection_topology, connect_topology_option, connect_topology_option_modifier, &topology_creation_finished, NULL);
716#if VERBOSE > 1 723#if VERBOSE > 1
717 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 724 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
718 "Have %d expected connections\n", expected_connections); 725 "Have %d expected connections\n", expected_connections);
diff --git a/src/testing/test_testing_topology_blacklist.c b/src/testing/test_testing_topology_blacklist.c
index 5e3520510..448531921 100644
--- a/src/testing/test_testing_topology_blacklist.c
+++ b/src/testing/test_testing_topology_blacklist.c
@@ -250,7 +250,7 @@ connect_topology ()
250 expected_connections = -1; 250 expected_connections = -1;
251 if ((pg != NULL) && (peers_left == 0)) 251 if ((pg != NULL) && (peers_left == 0))
252 { 252 {
253 expected_connections = GNUNET_TESTING_connect_topology (pg, connection_topology, connect_topology_option, connect_topology_option_modifier); 253 expected_connections = GNUNET_TESTING_connect_topology (pg, connection_topology, connect_topology_option, connect_topology_option_modifier, NULL, NULL);
254#if VERBOSE 254#if VERBOSE
255 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 255 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
256 "Have %d expected connections\n", expected_connections); 256 "Have %d expected connections\n", expected_connections);
diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c
index 72b56ae99..e4aef1b86 100644
--- a/src/testing/testing_group.c
+++ b/src/testing/testing_group.c
@@ -67,7 +67,7 @@
67 * Prototype of a function called whenever two peers would be connected 67 * Prototype of a function called whenever two peers would be connected
68 * in a certain topology. 68 * in a certain topology.
69 */ 69 */
70typedef int (*GNUNET_TESTING_ConnectionProcessor)(struct GNUNET_TESTING_PeerGroup *pg, 70typedef unsigned int (*GNUNET_TESTING_ConnectionProcessor)(struct GNUNET_TESTING_PeerGroup *pg,
71 unsigned int first, 71 unsigned int first,
72 unsigned int second); 72 unsigned int second);
73 73
@@ -556,14 +556,50 @@ struct UpdateContext
556 unsigned int fdnum; 556 unsigned int fdnum;
557}; 557};
558 558
559struct ConnectTopologyContext
560{
561 /**
562 * How many connections are left to create.
563 */
564 unsigned int remaining_connections;
565
566 /**
567 * Handle to group of peers.
568 */
569 struct GNUNET_TESTING_PeerGroup *pg;
570
571 /**
572 * Temp value set for each iteration.
573 */
574 struct PeerData *first;
575
576 /**
577 * Notification that all peers are connected.
578 */
579 GNUNET_TESTING_NotifyCompletion notify_connections_done;
580
581 /**
582 * Closure for notify.
583 */
584 void *notify_cls;
585};
559 586
560struct ConnectContext 587struct ConnectContext
561{ 588{
589 /**
590 * Peer to connect second to.
591 */
562 struct GNUNET_TESTING_Daemon *first; 592 struct GNUNET_TESTING_Daemon *first;
563 593
594 /**
595 * Peer to connect first to.
596 */
564 struct GNUNET_TESTING_Daemon *second; 597 struct GNUNET_TESTING_Daemon *second;
565 598
566 struct GNUNET_TESTING_PeerGroup *pg; 599 /**
600 * Higher level topology connection context.
601 */
602 struct ConnectTopologyContext *ct_ctx;
567}; 603};
568 604
569/** 605/**
@@ -608,7 +644,7 @@ static int outstanding_connects;
608 * known topology, GNUNET_NO if not 644 * known topology, GNUNET_NO if not
609 */ 645 */
610int 646int
611GNUNET_TESTING_topology_get(enum GNUNET_TESTING_Topology *topology, char * topology_string) 647GNUNET_TESTING_topology_get(enum GNUNET_TESTING_Topology *topology, const char * topology_string)
612{ 648{
613 /** 649 /**
614 * Strings representing topologies in enum 650 * Strings representing topologies in enum
@@ -697,7 +733,7 @@ GNUNET_TESTING_topology_get(enum GNUNET_TESTING_Topology *topology, char * topol
697 */ 733 */
698int 734int
699GNUNET_TESTING_topology_option_get (enum GNUNET_TESTING_TopologyOption *topology_option, 735GNUNET_TESTING_topology_option_get (enum GNUNET_TESTING_TopologyOption *topology_option,
700 char * topology_string) 736 const char * topology_string)
701{ 737{
702 /** 738 /**
703 * Options for connecting a topology as strings. 739 * Options for connecting a topology as strings.
@@ -922,7 +958,7 @@ make_config (const struct GNUNET_CONFIGURATION_Handle *cfg,
922 * technically should only be 0 or 2 958 * technically should only be 0 or 2
923 * 959 *
924 */ 960 */
925static int 961static unsigned int
926add_actual_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, unsigned int second) 962add_actual_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, unsigned int second)
927{ 963{
928 int added; 964 int added;
@@ -979,7 +1015,7 @@ add_actual_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first,
979 * for being sure doesn't bother me! 1015 * for being sure doesn't bother me!
980 * 1016 *
981 */ 1017 */
982static int 1018static unsigned int
983add_allowed_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, unsigned int second) 1019add_allowed_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, unsigned int second)
984{ 1020{
985 int added; 1021 int added;
@@ -1069,7 +1105,7 @@ add_allowed_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first,
1069 * @return the number of connections added (can be 0, 1 or 2) 1105 * @return the number of connections added (can be 0, 1 or 2)
1070 * 1106 *
1071 */ 1107 */
1072static int 1108static unsigned int
1073blacklist_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, unsigned int second) 1109blacklist_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, unsigned int second)
1074{ 1110{
1075 int added; 1111 int added;
@@ -1121,7 +1157,7 @@ blacklist_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, u
1121 * @return the number of connections removed (can be 0, 1 or 2) 1157 * @return the number of connections removed (can be 0, 1 or 2)
1122 * 1158 *
1123 */ 1159 */
1124static int 1160static unsigned int
1125unblacklist_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, unsigned int second) 1161unblacklist_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, unsigned int second)
1126{ 1162{
1127 int removed; 1163 int removed;
@@ -1167,7 +1203,7 @@ unblacklist_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first,
1167 * 1203 *
1168 * @return the number of connections created 1204 * @return the number of connections created
1169 */ 1205 */
1170static int 1206static unsigned int
1171create_scale_free (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProcessor proc) 1207create_scale_free (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProcessor proc)
1172{ 1208{
1173 1209
@@ -1222,7 +1258,7 @@ create_scale_free (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Connectio
1222 * @return the number of connections that were set up 1258 * @return the number of connections that were set up
1223 * 1259 *
1224 */ 1260 */
1225int 1261static unsigned int
1226create_small_world_ring(struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProcessor proc) 1262create_small_world_ring(struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProcessor proc)
1227{ 1263{
1228 unsigned int i, j; 1264 unsigned int i, j;
@@ -1344,7 +1380,7 @@ create_small_world_ring(struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Conn
1344 * @return the number of connections that were set up 1380 * @return the number of connections that were set up
1345 * 1381 *
1346 */ 1382 */
1347static int 1383static unsigned int
1348create_nated_internet (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProcessor proc) 1384create_nated_internet (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProcessor proc)
1349{ 1385{
1350 unsigned int outer_count, inner_count; 1386 unsigned int outer_count, inner_count;
@@ -1406,7 +1442,7 @@ create_nated_internet (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Conne
1406 * @return the number of connections that were set up 1442 * @return the number of connections that were set up
1407 * 1443 *
1408 */ 1444 */
1409static int 1445static unsigned int
1410create_small_world (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProcessor proc) 1446create_small_world (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProcessor proc)
1411{ 1447{
1412 unsigned int i, j, k; 1448 unsigned int i, j, k;
@@ -1568,7 +1604,7 @@ create_small_world (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Connecti
1568 * @return the number of connections that were set up 1604 * @return the number of connections that were set up
1569 * 1605 *
1570 */ 1606 */
1571static int 1607static unsigned int
1572create_erdos_renyi (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProcessor proc) 1608create_erdos_renyi (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProcessor proc)
1573{ 1609{
1574 double temp_rand; 1610 double temp_rand;
@@ -1628,7 +1664,7 @@ create_erdos_renyi (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Connecti
1628 * @return the number of connections that were set up 1664 * @return the number of connections that were set up
1629 * 1665 *
1630 */ 1666 */
1631static int 1667static unsigned int
1632create_2d_torus (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProcessor proc) 1668create_2d_torus (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProcessor proc)
1633{ 1669{
1634 unsigned int i; 1670 unsigned int i;
@@ -1716,7 +1752,7 @@ create_2d_torus (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionP
1716 * @return the number of connections that were set up 1752 * @return the number of connections that were set up
1717 * 1753 *
1718 */ 1754 */
1719static int 1755static unsigned int
1720create_clique (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProcessor proc) 1756create_clique (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProcessor proc)
1721{ 1757{
1722 unsigned int outer_count; 1758 unsigned int outer_count;
@@ -1753,7 +1789,7 @@ create_clique (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionPro
1753 * @return the number of connections that were set up 1789 * @return the number of connections that were set up
1754 * 1790 *
1755 */ 1791 */
1756static int 1792static unsigned int
1757create_line (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProcessor proc) 1793create_line (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProcessor proc)
1758{ 1794{
1759 unsigned int count; 1795 unsigned int count;
@@ -1786,7 +1822,7 @@ create_line (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProce
1786 * @return the number of connections that were set up 1822 * @return the number of connections that were set up
1787 * 1823 *
1788 */ 1824 */
1789static int 1825static unsigned int
1790create_ring (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProcessor proc) 1826create_ring (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProcessor proc)
1791{ 1827{
1792 unsigned int count; 1828 unsigned int count;
@@ -2019,7 +2055,7 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg)
2019 * @param transports space delimited list of transports to blacklist 2055 * @param transports space delimited list of transports to blacklist
2020 */ 2056 */
2021static int 2057static int
2022create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg, char *transports) 2058create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg, const char *transports)
2023{ 2059{
2024 FILE *temp_file_handle; 2060 FILE *temp_file_handle;
2025 static struct BlacklistContext blacklist_ctx; 2061 static struct BlacklistContext blacklist_ctx;
@@ -2176,10 +2212,19 @@ static void internal_connect_notify (void *cls,
2176 struct GNUNET_TESTING_Daemon *second_daemon, 2212 struct GNUNET_TESTING_Daemon *second_daemon,
2177 const char *emsg) 2213 const char *emsg)
2178{ 2214{
2179 struct GNUNET_TESTING_PeerGroup *pg = cls; 2215 struct ConnectTopologyContext *ct_ctx = cls;
2216 struct GNUNET_TESTING_PeerGroup *pg = ct_ctx->pg;
2180 outstanding_connects--; 2217 outstanding_connects--;
2218 ct_ctx->remaining_connections--;
2219 if (ct_ctx->remaining_connections == 0)
2220 {
2221 if (ct_ctx->notify_connections_done != NULL)
2222 ct_ctx->notify_connections_done(ct_ctx->notify_cls, NULL);
2223 GNUNET_free(ct_ctx);
2224 }
2181 2225
2182 pg->notify_connection(pg->notify_connection_cls, first, second, distance, first_cfg, second_cfg, first_daemon, second_daemon, emsg); 2226 if (pg->notify_connection != NULL)
2227 pg->notify_connection (pg->notify_connection_cls, first, second, distance, first_cfg, second_cfg, first_daemon, second_daemon, emsg);
2183} 2228}
2184 2229
2185 2230
@@ -2203,7 +2248,7 @@ static void schedule_connect(void *cls, const struct GNUNET_SCHEDULER_TaskContex
2203 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2248 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2204 _("Delaying connect, we have too many outstanding connections!\n")); 2249 _("Delaying connect, we have too many outstanding connections!\n"));
2205#endif 2250#endif
2206 GNUNET_SCHEDULER_add_delayed(connect_context->pg->sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 100), &schedule_connect, connect_context); 2251 GNUNET_SCHEDULER_add_delayed(connect_context->ct_ctx->pg->sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 100), &schedule_connect, connect_context);
2207 } 2252 }
2208 else 2253 else
2209 { 2254 {
@@ -2217,7 +2262,7 @@ static void schedule_connect(void *cls, const struct GNUNET_SCHEDULER_TaskContex
2217 CONNECT_TIMEOUT, 2262 CONNECT_TIMEOUT,
2218 CONNECT_ATTEMPTS, 2263 CONNECT_ATTEMPTS,
2219 &internal_connect_notify, 2264 &internal_connect_notify,
2220 connect_context->pg); 2265 connect_context->ct_ctx);
2221 GNUNET_free(connect_context); 2266 GNUNET_free(connect_context);
2222 } 2267 }
2223} 2268}
@@ -2238,14 +2283,15 @@ connect_iterator (void *cls,
2238 const GNUNET_HashCode * key, 2283 const GNUNET_HashCode * key,
2239 void *value) 2284 void *value)
2240{ 2285{
2241 struct PeerData *first = cls; 2286 struct ConnectTopologyContext *ct_ctx = cls;
2287 struct PeerData *first = ct_ctx->first;
2242 struct GNUNET_TESTING_Daemon *second = value; 2288 struct GNUNET_TESTING_Daemon *second = value;
2243 struct ConnectContext *connect_context; 2289 struct ConnectContext *connect_context;
2244 2290
2245 connect_context = GNUNET_malloc(sizeof(struct ConnectContext)); 2291 connect_context = GNUNET_malloc(sizeof(struct ConnectContext));
2246 connect_context->pg = first->pg;
2247 connect_context->first = first->daemon; 2292 connect_context->first = first->daemon;
2248 connect_context->second = second; 2293 connect_context->second = second;
2294 connect_context->ct_ctx = ct_ctx;
2249 GNUNET_SCHEDULER_add_now(first->pg->sched, &schedule_connect, connect_context); 2295 GNUNET_SCHEDULER_add_now(first->pg->sched, &schedule_connect, connect_context);
2250 2296
2251 return GNUNET_YES; 2297 return GNUNET_YES;
@@ -2309,23 +2355,41 @@ copy_allowed_topology (struct GNUNET_TESTING_PeerGroup *pg)
2309 * @return the number of connections that will be attempted 2355 * @return the number of connections that will be attempted
2310 */ 2356 */
2311static int 2357static int
2312connect_topology (struct GNUNET_TESTING_PeerGroup *pg) 2358connect_topology (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_NotifyCompletion notify_callback, void *notify_cls)
2313{ 2359{
2314 unsigned int pg_iter; 2360 unsigned int pg_iter;
2315 int ret; 2361 int ret;
2316 int total; 2362 unsigned int total;
2363 struct ConnectTopologyContext *ct_ctx;
2317#if OLD 2364#if OLD
2318 struct PeerConnection *connection_iter; 2365 struct PeerConnection *connection_iter;
2319 struct ConnectContext *connect_context; 2366 struct ConnectContext *connect_context;
2320#endif 2367#endif
2321 2368
2322 total = 0; 2369 total = 0;
2370 ct_ctx = GNUNET_malloc(sizeof(struct ConnectTopologyContext));
2371 ct_ctx->notify_connections_done = notify_callback;
2372 ct_ctx->notify_cls = notify_cls;
2373 ct_ctx->pg = pg;
2374
2323 for (pg_iter = 0; pg_iter < pg->total; pg_iter++) 2375 for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
2324 { 2376 {
2325 ret = GNUNET_CONTAINER_multihashmap_iterate(pg->peers[pg_iter].connect_peers, &connect_iterator, &pg->peers[pg_iter]); 2377 total += GNUNET_CONTAINER_multihashmap_size(pg->peers[pg_iter].connect_peers);
2326 if (GNUNET_SYSERR == ret) 2378 }
2327 return GNUNET_SYSERR; 2379
2380 if (total == 0)
2381 {
2382 GNUNET_free(ct_ctx);
2383 return total;
2384 }
2385 ct_ctx->remaining_connections = total;
2386 total = 0;
2328 2387
2388 for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
2389 {
2390 ct_ctx->first = &pg->peers[pg_iter];
2391 ret = GNUNET_CONTAINER_multihashmap_iterate(pg->peers[pg_iter].connect_peers, &connect_iterator, ct_ctx);
2392 GNUNET_assert(GNUNET_SYSERR != ret && ret >= 0);
2329 total = total + ret; 2393 total = total + ret;
2330 2394
2331#if OLD 2395#if OLD
@@ -2365,14 +2429,14 @@ connect_topology (struct GNUNET_TESTING_PeerGroup *pg)
2365 * @return the maximum number of connections were all allowed peers 2429 * @return the maximum number of connections were all allowed peers
2366 * connected to each other 2430 * connected to each other
2367 */ 2431 */
2368int 2432unsigned int
2369GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, 2433GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg,
2370 enum GNUNET_TESTING_Topology topology, 2434 enum GNUNET_TESTING_Topology topology,
2371 enum GNUNET_TESTING_Topology restrict_topology, 2435 enum GNUNET_TESTING_Topology restrict_topology,
2372 char *restrict_transports) 2436 const char *restrict_transports)
2373{ 2437{
2374 int ret; 2438 int ret;
2375 int num_connections; 2439 unsigned int num_connections;
2376 int unblacklisted_connections; 2440 int unblacklisted_connections;
2377 2441
2378 GNUNET_assert (pg->notify_connection != NULL); 2442 GNUNET_assert (pg->notify_connection != NULL);
@@ -2480,6 +2544,7 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg,
2480 /* Use the create clique method to initially set all connections as blacklisted. */ 2544 /* Use the create clique method to initially set all connections as blacklisted. */
2481 if (restrict_topology != GNUNET_TESTING_TOPOLOGY_NONE) 2545 if (restrict_topology != GNUNET_TESTING_TOPOLOGY_NONE)
2482 create_clique (pg, &blacklist_connections); 2546 create_clique (pg, &blacklist_connections);
2547
2483 unblacklisted_connections = 0; 2548 unblacklisted_connections = 0;
2484 /* Un-blacklist connections as per the topology specified */ 2549 /* Un-blacklist connections as per the topology specified */
2485 switch (restrict_topology) 2550 switch (restrict_topology)
@@ -2565,7 +2630,7 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg,
2565 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2630 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2566 _("Failed during blacklist file copying!\n")); 2631 _("Failed during blacklist file copying!\n"));
2567#endif 2632#endif
2568 return GNUNET_SYSERR; 2633 return 0;
2569 } 2634 }
2570 else 2635 else
2571 { 2636 {
@@ -3361,13 +3426,18 @@ GNUNET_TESTING_get_statistics (struct GNUNET_TESTING_PeerGroup *pg,
3361 * @param topology which topology to connect the peers in 3426 * @param topology which topology to connect the peers in
3362 * @param options options for connecting the topology 3427 * @param options options for connecting the topology
3363 * @param option_modifier modifier for options that take a parameter 3428 * @param option_modifier modifier for options that take a parameter
3429 * @param notify_callback notification to be called once all connections completed
3430 * @param notify_cls closure for notification callback
3431 *
3364 * @return the number of connections that will be attempted, GNUNET_SYSERR on error 3432 * @return the number of connections that will be attempted, GNUNET_SYSERR on error
3365 */ 3433 */
3366int 3434int
3367GNUNET_TESTING_connect_topology (struct GNUNET_TESTING_PeerGroup *pg, 3435GNUNET_TESTING_connect_topology (struct GNUNET_TESTING_PeerGroup *pg,
3368 enum GNUNET_TESTING_Topology topology, 3436 enum GNUNET_TESTING_Topology topology,
3369 enum GNUNET_TESTING_TopologyOption options, 3437 enum GNUNET_TESTING_TopologyOption options,
3370 double option_modifier) 3438 double option_modifier,
3439 GNUNET_TESTING_NotifyCompletion notify_callback,
3440 void *notify_cls)
3371{ 3441{
3372 switch (topology) 3442 switch (topology)
3373 { 3443 {
@@ -3485,7 +3555,7 @@ GNUNET_TESTING_connect_topology (struct GNUNET_TESTING_PeerGroup *pg,
3485 break; 3555 break;
3486 } 3556 }
3487 3557
3488 return connect_topology(pg); 3558 return connect_topology(pg, notify_callback, notify_cls);
3489} 3559}
3490 3560
3491/** 3561/**