aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-05-11 16:11:56 +0000
committerNathan S. Evans <evans@in.tum.de>2010-05-11 16:11:56 +0000
commitf670d73ee633b91ff44c44ee53ab03f450dca7d9 (patch)
tree27850d3e19f982c4be4e692b5b7b4d91a1184a69 /src
parentef75805f2324b4ffba9fea5ce606aa6440ee5c11 (diff)
downloadgnunet-f670d73ee633b91ff44c44ee53ab03f450dca7d9.tar.gz
gnunet-f670d73ee633b91ff44c44ee53ab03f450dca7d9.zip
blacklist testcase, testing_group support for blacklisting
Diffstat (limited to 'src')
-rw-r--r--src/testing/test_testing_topology_blacklist.c505
-rw-r--r--src/testing/testing_group.c186
2 files changed, 669 insertions, 22 deletions
diff --git a/src/testing/test_testing_topology_blacklist.c b/src/testing/test_testing_topology_blacklist.c
new file mode 100644
index 000000000..08a30a347
--- /dev/null
+++ b/src/testing/test_testing_topology_blacklist.c
@@ -0,0 +1,505 @@
1/*
2 This file is part of GNUnet.
3 (C) 2009 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 2, 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 * @file testing/test_testing_topology_blacklist.c
22 * @brief base testcase for testing transport level blacklisting
23 */
24#include "platform.h"
25#include "gnunet_testing_lib.h"
26#include "gnunet_core_service.h"
27
28#define VERBOSE GNUNET_YES
29
30/**
31 * How long until we fail the whole testcase?
32 */
33#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 600)
34
35/**
36 * How long until we give up on starting the peers? (Must be longer than the connect timeout!)
37 */
38#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
39
40#define DEFAULT_NUM_PEERS 4
41
42#define MAX_OUTSTANDING_CONNECTIONS 300
43
44static int ok;
45
46static unsigned long long num_peers;
47
48static unsigned int total_connections;
49
50static unsigned int failed_connections;
51
52static unsigned int expected_connections;
53
54static unsigned int expected_failed_connections;
55
56static unsigned long long peers_left;
57
58static struct GNUNET_TESTING_PeerGroup *pg;
59
60static struct GNUNET_SCHEDULER_Handle *sched;
61
62const struct GNUNET_CONFIGURATION_Handle *main_cfg;
63
64GNUNET_SCHEDULER_TaskIdentifier die_task;
65
66static char *dotOutFileName;
67
68static FILE *dotOutFile;
69
70static char *blacklist_transports;
71
72static enum GNUNET_TESTING_Topology topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Overlay should allow all connections */
73
74static enum GNUNET_TESTING_Topology blacklist_topology = GNUNET_TESTING_TOPOLOGY_RING; /* Blacklist underlay into a ring */
75
76static enum GNUNET_TESTING_Topology connection_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers */
77
78static enum GNUNET_TESTING_TopologyOption connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Try to connect all possible OVERLAY connections */
79
80static double connect_topology_option_modifier = 0.0;
81
82static char *test_directory;
83
84#define MTYPE 12345
85
86struct GNUNET_TestMessage
87{
88 /**
89 * Header of the message
90 */
91 struct GNUNET_MessageHeader header;
92
93 /**
94 * Unique identifier for this message.
95 */
96 uint32_t uid;
97};
98
99static void
100finish_testing ()
101{
102 GNUNET_assert (pg != NULL);
103
104#if VERBOSE
105 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
106 "Called finish testing, stopping daemons.\n");
107#endif
108 sleep(1);
109#if VERBOSE
110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
111 "Calling daemons_stop\n");
112#endif
113 GNUNET_TESTING_daemons_stop (pg, TIMEOUT);
114#if VERBOSE
115 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
116 "daemons_stop finished\n");
117#endif
118 if (dotOutFile != NULL)
119 {
120 fprintf(dotOutFile, "}");
121 fclose(dotOutFile);
122 }
123
124 ok = 0;
125}
126
127static void
128end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
129{
130 char *msg = cls;
131 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
132 "End badly was called (%s)... stopping daemons.\n", msg);
133
134 if (pg != NULL)
135 {
136 GNUNET_TESTING_daemons_stop (pg, TIMEOUT);
137 ok = 7331; /* Opposite of leet */
138 }
139 else
140 ok = 401; /* Never got peers started */
141
142 if (dotOutFile != NULL)
143 {
144 fprintf(dotOutFile, "}");
145 fclose(dotOutFile);
146 }
147}
148
149
150
151void
152topology_callback (void *cls,
153 const struct GNUNET_PeerIdentity *first,
154 const struct GNUNET_PeerIdentity *second,
155 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
156 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
157 struct GNUNET_TESTING_Daemon *first_daemon,
158 struct GNUNET_TESTING_Daemon *second_daemon,
159 const char *emsg)
160{
161 if (emsg == NULL)
162 {
163 total_connections++;
164#if VERBOSE
165 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s\n",
166 first_daemon->shortname,
167 second_daemon->shortname);
168#endif
169 if (dotOutFile != NULL)
170 fprintf(dotOutFile, "\tn%s -- n%s;\n", first_daemon->shortname, second_daemon->shortname);
171 }
172#if VERBOSE
173 else
174 {
175 failed_connections++;
176 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer %s with error :\n%s\n",
177 first_daemon->shortname,
178 second_daemon->shortname, emsg);
179 }
180#endif
181
182 if (total_connections == expected_connections)
183 {
184#if VERBOSE
185 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
186 "Created %d total connections, which is our target number (that's bad)!\n",
187 total_connections);
188#endif
189
190 GNUNET_SCHEDULER_cancel (sched, die_task);
191 die_task = GNUNET_SCHEDULER_NO_TASK;
192 die_task = GNUNET_SCHEDULER_add_now (sched,
193 &end_badly, "from topology_callback (too many successful connections)");
194 }
195 else if (total_connections + failed_connections == expected_connections)
196 {
197 if ((failed_connections == expected_failed_connections) && (total_connections == expected_connections - expected_failed_connections))
198 {
199 GNUNET_SCHEDULER_cancel (sched, die_task);
200 die_task = GNUNET_SCHEDULER_NO_TASK;
201 die_task = GNUNET_SCHEDULER_add_now (sched,
202 &finish_testing, NULL);
203 }
204 else
205 {
206 GNUNET_SCHEDULER_cancel (sched, die_task);
207 die_task = GNUNET_SCHEDULER_add_now (sched,
208 &end_badly, "from topology_callback (wrong number of failed connections)");
209 }
210 }
211 else
212 {
213#if VERBOSE
214 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
215 "Have %d total connections, %d failed connections, Want %d (failed) and %d (successful)\n",
216 total_connections, failed_connections, expected_failed_connections, expected_connections - expected_failed_connections);
217#endif
218 }
219}
220
221static void
222connect_topology ()
223{
224 expected_connections = -1;
225 if ((pg != NULL) && (peers_left == 0))
226 {
227 expected_connections = GNUNET_TESTING_connect_topology (pg, connection_topology, connect_topology_option, connect_topology_option_modifier);
228#if VERBOSE
229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
230 "Have %d expected connections\n", expected_connections);
231#endif
232 }
233
234 GNUNET_SCHEDULER_cancel (sched, die_task);
235 if (expected_connections == GNUNET_SYSERR)
236 {
237 die_task = GNUNET_SCHEDULER_add_now (sched,
238 &end_badly, "from connect topology (bad return)");
239 }
240
241 die_task = GNUNET_SCHEDULER_add_delayed (sched,
242 TEST_TIMEOUT,
243 &end_badly, "from connect topology (timeout)");
244}
245
246static void
247create_topology ()
248{
249 peers_left = num_peers; /* Reset counter */
250 if (GNUNET_TESTING_create_topology (pg, topology, blacklist_topology, blacklist_transports) != GNUNET_SYSERR)
251 {
252#if VERBOSE
253 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
254 "Topology set up, now starting peers!\n");
255#endif
256 GNUNET_TESTING_daemons_continue_startup(pg);
257 }
258 else
259 {
260 GNUNET_SCHEDULER_cancel (sched, die_task);
261 die_task = GNUNET_SCHEDULER_add_now (sched,
262 &end_badly, "from create topology (bad return)");
263 }
264 GNUNET_SCHEDULER_cancel (sched, die_task);
265 die_task = GNUNET_SCHEDULER_add_delayed (sched,
266 TEST_TIMEOUT,
267 &end_badly, "from continue startup (timeout)");
268}
269
270
271static void
272peers_started_callback (void *cls,
273 const struct GNUNET_PeerIdentity *id,
274 const struct GNUNET_CONFIGURATION_Handle *cfg,
275 struct GNUNET_TESTING_Daemon *d, const char *emsg)
276{
277 if (emsg != NULL)
278 {
279 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start daemon with error: `%s'\n",
280 emsg);
281 return;
282 }
283 GNUNET_assert (id != NULL);
284#if VERBOSE
285 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
286 (num_peers - peers_left) + 1, num_peers);
287#endif
288 peers_left--;
289 if (peers_left == 0)
290 {
291#if VERBOSE
292 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
293 "All %d daemons started, now creating topology!\n",
294 num_peers);
295#endif
296 GNUNET_SCHEDULER_cancel (sched, die_task);
297 /* Set up task in case topology creation doesn't finish
298 * within a reasonable amount of time */
299 die_task = GNUNET_SCHEDULER_add_delayed (sched,
300 GNUNET_TIME_relative_multiply
301 (GNUNET_TIME_UNIT_MINUTES, 5),
302 &end_badly, "from peers_started_callback");
303 connect_topology ();
304 ok = 0;
305 }
306}
307
308/**
309 * Callback indicating that the hostkey was created for a peer.
310 *
311 * @param cls NULL
312 * @param id the peer identity
313 * @param d the daemon handle (pretty useless at this point, remove?)
314 * @param emsg non-null on failure
315 */
316void hostkey_callback (void *cls,
317 const struct GNUNET_PeerIdentity *id,
318 struct GNUNET_TESTING_Daemon *d,
319 const char *emsg)
320{
321 if (emsg != NULL)
322 {
323 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Hostkey callback received error: %s\n", emsg);
324 }
325
326#if VERBOSE
327 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
328 "Hostkey created for peer `%s'\n",
329 GNUNET_i2s(id));
330#endif
331 peers_left--;
332 if (peers_left == 0)
333 {
334#if VERBOSE
335 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
336 "All %d hostkeys created, now creating topology!\n",
337 num_peers);
338#endif
339 GNUNET_SCHEDULER_cancel (sched, die_task);
340 /* Set up task in case topology creation doesn't finish
341 * within a reasonable amount of time */
342 die_task = GNUNET_SCHEDULER_add_delayed (sched,
343 GNUNET_TIME_relative_multiply
344 (GNUNET_TIME_UNIT_MINUTES, 5),
345 &end_badly, "from hostkey_callback");
346 GNUNET_SCHEDULER_add_now(sched, &create_topology, NULL);
347 ok = 0;
348 }
349}
350
351static void
352run (void *cls,
353 struct GNUNET_SCHEDULER_Handle *s,
354 char *const *args,
355 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
356{
357 unsigned long long topology_num;
358 unsigned long long connect_topology_num;
359 unsigned long long blacklist_topology_num;
360 unsigned long long connect_topology_option_num;
361 char *connect_topology_option_modifier_string;
362 sched = s;
363 ok = 1;
364
365 dotOutFile = fopen (dotOutFileName, "w");
366 if (dotOutFile != NULL)
367 {
368 fprintf (dotOutFile, "strict graph G {\n");
369 }
370
371#if VERBOSE
372 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
373 "Starting daemons based on config file %s\n", cfgfile);
374#endif
375
376 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory))
377 {
378 ok = 404;
379 return;
380 }
381
382 if (GNUNET_YES ==
383 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "topology",
384 &topology_num))
385 topology = topology_num;
386
387 if (GNUNET_YES ==
388 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_topology",
389 &connect_topology_num))
390 connection_topology = connect_topology_num;
391
392 if (GNUNET_YES ==
393 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_topology_option",
394 &connect_topology_option_num))
395 connect_topology_option = connect_topology_option_num;
396
397 if (GNUNET_YES ==
398 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "connect_topology_option_modifier",
399 &connect_topology_option_modifier_string))
400 {
401 if (sscanf(connect_topology_option_modifier_string, "%lf", &connect_topology_option_modifier) != 1)
402 {
403 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
404 _("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
405 connect_topology_option_modifier_string,
406 "connect_topology_option_modifier",
407 "TESTING");
408 GNUNET_free (connect_topology_option_modifier_string);
409 }
410 }
411
412 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "blacklist_transports",
413 &blacklist_transports);
414
415 if (GNUNET_YES ==
416 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "blacklist_topology",
417 &blacklist_topology_num))
418 blacklist_topology = blacklist_topology_num;
419
420 if (GNUNET_SYSERR ==
421 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
422 &num_peers))
423 num_peers = DEFAULT_NUM_PEERS;
424
425 main_cfg = cfg;
426
427 peers_left = num_peers;
428
429 /* For this specific test we only really want a CLIQUE topology as the
430 * overlay allowed topology, and a RING topology as the underlying connection
431 * allowed topology. So we will expect only num_peers * 2 connections to
432 * work, and (num_peers * (num_peers - 1)) - (num_peers * 2) to fail.
433 */
434 expected_connections = num_peers * (num_peers - 1);
435 expected_failed_connections = expected_connections - (num_peers * 2);
436
437
438 /* Set up a task to end testing if peer start fails */
439 die_task = GNUNET_SCHEDULER_add_delayed (sched,
440 GNUNET_TIME_relative_multiply
441 (GNUNET_TIME_UNIT_MINUTES, 5),
442 &end_badly, "didn't start all daemons in reasonable amount of time!!!");
443
444 pg = GNUNET_TESTING_daemons_start (sched, cfg,
445 peers_left, TIMEOUT, &hostkey_callback, NULL, &peers_started_callback, NULL,
446 &topology_callback, NULL, NULL);
447
448}
449
450static int
451check ()
452{
453 int ret;
454 char *const argv[] = {"test-testing-topology-blacklist",
455 "-c",
456 "test_testing_data_topology_blacklist.conf",
457#if VERBOSE
458 "-L", "DEBUG",
459#endif
460 NULL
461 };
462 struct GNUNET_GETOPT_CommandLineOption options[] = {
463 GNUNET_GETOPT_OPTION_END
464 };
465 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
466 argv, "test-testing-topology-blacklist", "nohelp",
467 options, &run, &ok);
468 if (ret != GNUNET_OK)
469 {
470 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`test-testing-topology-blacklist': Failed with error code %d\n", ret);
471 }
472
473 return ok;
474}
475
476int
477main (int argc, char *argv[])
478{
479 int ret;
480
481 GNUNET_log_setup ("test_testing_topology_blacklist",
482#if VERBOSE
483 "DEBUG",
484#else
485 "WARNING",
486#endif
487 NULL);
488 ret = check ();
489
490 /**
491 * Need to remove base directory, subdirectories taken care
492 * of by the testing framework.
493 */
494 if (test_directory != NULL)
495 {
496 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
497 {
498 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to remove testing directory %s\n", test_directory);
499 }
500 }
501
502 return ret;
503}
504
505/* end of test_testing_topology_blacklist.c */
diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c
index 835b1d979..4b1e771e9 100644
--- a/src/testing/testing_group.c
+++ b/src/testing/testing_group.c
@@ -57,6 +57,42 @@
57typedef int (*GNUNET_TESTING_ConnectionProcessor) 57typedef int (*GNUNET_TESTING_ConnectionProcessor)
58(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, unsigned int second); 58(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, unsigned int second);
59 59
60/**
61 * Context for handling churning a peer group
62 */
63struct ChurnContext
64{
65 /**
66 * Callback used to notify of churning finished
67 */
68 GNUNET_TESTING_NotifyCompletion cb;
69
70 /**
71 * Closure for callback
72 */
73 void *cb_cls;
74
75 /**
76 * Number of peers that still need to be started
77 */
78 unsigned int num_to_start;
79
80 /**
81 * Number of peers that still need to be stopped
82 */
83 unsigned int num_to_stop;
84
85 /**
86 * Number of peers that failed to start
87 */
88 unsigned int num_failed_start;
89
90 /**
91 * Number of peers that failed to stop
92 */
93 unsigned int num_failed_stop;
94};
95
60struct RestartContext 96struct RestartContext
61{ 97{
62 /** 98 /**
@@ -1208,6 +1244,18 @@ friend_file_iterator (void *cls,
1208 return GNUNET_YES; 1244 return GNUNET_YES;
1209} 1245}
1210 1246
1247struct BlacklistContext
1248{
1249 /*
1250 * The (open) file handle to write to
1251 */
1252 FILE *temp_file_handle;
1253
1254 /*
1255 * The transport that this peer will be blacklisted on.
1256 */
1257 char *transport;
1258};
1211 1259
1212/** 1260/**
1213 * Iterator for writing blacklist data to appropriate files. 1261 * Iterator for writing blacklist data to appropriate files.
@@ -1223,14 +1271,15 @@ blacklist_file_iterator (void *cls,
1223 const GNUNET_HashCode * key, 1271 const GNUNET_HashCode * key,
1224 void *value) 1272 void *value)
1225{ 1273{
1226 FILE *temp_blacklist_handle = cls; 1274 struct BlacklistContext *blacklist_ctx = cls;
1275 //FILE *temp_blacklist_handle = cls;
1227 struct GNUNET_TESTING_Daemon *peer = value; 1276 struct GNUNET_TESTING_Daemon *peer = value;
1228 struct GNUNET_PeerIdentity *temppeer; 1277 struct GNUNET_PeerIdentity *temppeer;
1229 struct GNUNET_CRYPTO_HashAsciiEncoded peer_enc; 1278 struct GNUNET_CRYPTO_HashAsciiEncoded peer_enc;
1230 1279
1231 temppeer = &peer->id; 1280 temppeer = &peer->id;
1232 GNUNET_CRYPTO_hash_to_enc(&temppeer->hashPubKey, &peer_enc); 1281 GNUNET_CRYPTO_hash_to_enc(&temppeer->hashPubKey, &peer_enc);
1233 fprintf(temp_blacklist_handle, "tcp:%s\n", (char *)&peer_enc); 1282 fprintf(blacklist_ctx->temp_file_handle, "%s:%s\n", blacklist_ctx->transport, (char *)&peer_enc);
1234 1283
1235 return GNUNET_YES; 1284 return GNUNET_YES;
1236} 1285}
@@ -1364,11 +1413,13 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg)
1364 * to the appropriate place. 1413 * to the appropriate place.
1365 * 1414 *
1366 * @param pg the peer group we are dealing with 1415 * @param pg the peer group we are dealing with
1416 * @param transports space delimited list of transports to blacklist
1367 */ 1417 */
1368static int 1418static int
1369create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg) 1419create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg, char *transports)
1370{ 1420{
1371 FILE *temp_friend_handle; 1421 FILE *temp_file_handle;
1422 static struct BlacklistContext blacklist_ctx;
1372 unsigned int pg_iter; 1423 unsigned int pg_iter;
1373 char *temp_service_path; 1424 char *temp_service_path;
1374 pid_t *pidarr; 1425 pid_t *pidarr;
@@ -1379,16 +1430,42 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg)
1379 int count; 1430 int count;
1380 int ret; 1431 int ret;
1381 int max_wait = 10; 1432 int max_wait = 10;
1433 int transport_len;
1434 unsigned int i;
1435 char *pos;
1436 char *temp_transports;
1382 1437
1383 pidarr = GNUNET_malloc(sizeof(pid_t) * pg->total); 1438 pidarr = GNUNET_malloc(sizeof(pid_t) * pg->total);
1384 for (pg_iter = 0; pg_iter < pg->total; pg_iter++) 1439 for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
1385 { 1440 {
1386 mytemp = GNUNET_DISK_mktemp("blacklist"); 1441 mytemp = GNUNET_DISK_mktemp("blacklist");
1387 GNUNET_assert(mytemp != NULL); 1442 GNUNET_assert(mytemp != NULL);
1388 temp_friend_handle = fopen (mytemp, "wt"); 1443 temp_file_handle = fopen (mytemp, "wt");
1389 GNUNET_assert(temp_friend_handle != NULL); 1444 GNUNET_assert(temp_file_handle != NULL);
1390 GNUNET_CONTAINER_multihashmap_iterate(pg->peers[pg_iter].blacklisted_peers, &blacklist_file_iterator, temp_friend_handle); 1445 temp_transports = GNUNET_strdup(transports);
1391 fclose(temp_friend_handle); 1446 blacklist_ctx.temp_file_handle = temp_file_handle;
1447 transport_len = strlen(temp_transports) + 1;
1448 pos = NULL;
1449
1450 for (i = 0; i < transport_len; i++)
1451 {
1452 if ((temp_transports[i] == ' ') && (pos == NULL))
1453 continue; /* At start of string (whitespace) */
1454 else if ((temp_transports[i] == ' ') || (temp_transports[i] == '\0')) /* At end of string */
1455 {
1456 temp_transports[i] = '\0';
1457 blacklist_ctx.transport = pos;
1458 GNUNET_CONTAINER_multihashmap_iterate(pg->peers[pg_iter].blacklisted_peers, &blacklist_file_iterator, &blacklist_ctx);
1459 pos = NULL;
1460 } /* At beginning of actual string */
1461 else if (pos == NULL)
1462 {
1463 pos = &temp_transports[i];
1464 }
1465 }
1466
1467 GNUNET_free_non_null(temp_transports);
1468 fclose(temp_file_handle);
1392 1469
1393 if (GNUNET_OK != 1470 if (GNUNET_OK !=
1394 GNUNET_CONFIGURATION_get_value_string(pg->peers[pg_iter].daemon->cfg, "PATHS", "SERVICEHOME", &temp_service_path)) 1471 GNUNET_CONFIGURATION_get_value_string(pg->peers[pg_iter].daemon->cfg, "PATHS", "SERVICEHOME", &temp_service_path))
@@ -1669,6 +1746,8 @@ connect_topology (struct GNUNET_TESTING_PeerGroup *pg)
1669 * @param topology which topology to connect the peers in 1746 * @param topology which topology to connect the peers in
1670 * @param restrict_topology allow only direct TCP connections in this topology 1747 * @param restrict_topology allow only direct TCP connections in this topology
1671 * use GNUNET_TESTING_TOPOLOGY_NONE for no restrictions 1748 * use GNUNET_TESTING_TOPOLOGY_NONE for no restrictions
1749 * @param restrict_transports space delimited list of transports to blacklist
1750 * to create restricted topology
1672 * 1751 *
1673 * @return the maximum number of connections were all allowed peers 1752 * @return the maximum number of connections were all allowed peers
1674 * connected to each other 1753 * connected to each other
@@ -1676,7 +1755,8 @@ connect_topology (struct GNUNET_TESTING_PeerGroup *pg)
1676int 1755int
1677GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, 1756GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg,
1678 enum GNUNET_TESTING_Topology topology, 1757 enum GNUNET_TESTING_Topology topology,
1679 enum GNUNET_TESTING_Topology restrict_topology) 1758 enum GNUNET_TESTING_Topology restrict_topology,
1759 char *restrict_transports)
1680{ 1760{
1681 int ret; 1761 int ret;
1682 int num_connections; 1762 int num_connections;
@@ -1847,9 +1927,9 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg,
1847 break; 1927 break;
1848 } 1928 }
1849 1929
1850 if (unblacklisted_connections > 0) 1930 if ((unblacklisted_connections > 0) && (restrict_transports != NULL))
1851 { 1931 {
1852 ret = create_and_copy_blacklist_files(pg); 1932 ret = create_and_copy_blacklist_files(pg, restrict_transports);
1853 if (ret != GNUNET_OK) 1933 if (ret != GNUNET_OK)
1854 { 1934 {
1855#if VERBOSE_TESTING 1935#if VERBOSE_TESTING
@@ -2606,12 +2686,55 @@ void restart_callback (void *cls,
2606 2686
2607} 2687}
2608 2688
2689/**
2690 * Callback for informing us about a successful
2691 * or unsuccessful churn stop call.
2692 *
2693 * @param cls a ChurnContext
2694 * @param emsg NULL on success, non-NULL on failure
2695 *
2696 */
2609void 2697void
2610churn_stop_callback (void *cls, const char *emsg) 2698churn_stop_callback (void *cls, const char *emsg)
2611{ 2699{
2700 struct ChurnContext *churn_ctx = cls;
2701 unsigned int total_left;
2702 char *error_message;
2703
2704 error_message = NULL;
2705 if (emsg != NULL)
2706 {
2707 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Churn stop callback failed with error `%s'\n", emsg);
2708 churn_ctx->num_failed_stop++;
2709 }
2710 else
2711 {
2712 churn_ctx->num_to_stop--;
2713 }
2714
2715 total_left = (churn_ctx->num_to_stop - churn_ctx->num_failed_stop) + (churn_ctx->num_to_start - churn_ctx->num_failed_start);
2612 2716
2717 if (total_left == 0)
2718 {
2719 if ((churn_ctx->num_failed_stop > 0) || (churn_ctx->num_failed_start > 0))
2720 GNUNET_asprintf(&error_message, "Churn didn't complete successfully, %u peers failed to start %u peers failed to be stopped!", churn_ctx->num_failed_start, churn_ctx->num_failed_stop);
2721 churn_ctx->cb(churn_ctx->cb_cls, error_message);
2722 GNUNET_free_non_null(error_message);
2723 GNUNET_free(churn_ctx);
2724 }
2613} 2725}
2614 2726
2727/**
2728 * Callback for informing us about a successful
2729 * or unsuccessful churn start call.
2730 *
2731 * @param cls a ChurnContext
2732 * @param id the peer identity of the started peer
2733 * @param cfg the handle to the configuration of the peer
2734 * @param d handle to the daemon for the peer
2735 * @param emsg NULL on success, non-NULL on failure
2736 *
2737 */
2615void 2738void
2616churn_start_callback (void *cls, 2739churn_start_callback (void *cls,
2617 const struct GNUNET_PeerIdentity *id, 2740 const struct GNUNET_PeerIdentity *id,
@@ -2619,16 +2742,33 @@ churn_start_callback (void *cls,
2619 struct GNUNET_TESTING_Daemon *d, 2742 struct GNUNET_TESTING_Daemon *d,
2620 const char *emsg) 2743 const char *emsg)
2621{ 2744{
2745 struct ChurnContext *churn_ctx = cls;
2746 unsigned int total_left;
2747 char *error_message;
2622 2748
2623} 2749 error_message = NULL;
2750 if (emsg != NULL)
2751 {
2752 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Churn stop callback failed with error `%s'\n", emsg);
2753 churn_ctx->num_failed_start++;
2754 }
2755 else
2756 {
2757 churn_ctx->num_to_start--;
2758 }
2624 2759
2625/** 2760 total_left = (churn_ctx->num_to_stop - churn_ctx->num_failed_stop) + (churn_ctx->num_to_start - churn_ctx->num_failed_start);
2626 * Context for handling churning a peer group
2627 */
2628struct ChurnContext
2629{
2630 2761
2631}; 2762 if (total_left == 0)
2763 {
2764 if ((churn_ctx->num_failed_stop > 0) || (churn_ctx->num_failed_start > 0))
2765 GNUNET_asprintf(&error_message, "Churn didn't complete successfully, %u peers failed to start %u peers failed to be stopped!", churn_ctx->num_failed_start, churn_ctx->num_failed_stop);
2766 churn_ctx->cb(churn_ctx->cb_cls, error_message);
2767 GNUNET_free_non_null(error_message);
2768 GNUNET_free(churn_ctx);
2769 }
2770
2771}
2632 2772
2633/** 2773/**
2634 * Simulate churn by stopping some peers (and possibly 2774 * Simulate churn by stopping some peers (and possibly
@@ -2638,9 +2778,7 @@ struct ChurnContext
2638 * online will be taken offline; then "von" random peers that are then 2778 * online will be taken offline; then "von" random peers that are then
2639 * offline will be put back online. No notifications will be 2779 * offline will be put back online. No notifications will be
2640 * generated for any of these operations except for the callback upon 2780 * generated for any of these operations except for the callback upon
2641 * completion. Note that the implementation is at liberty to keep 2781 * completion.
2642 * the ARM service itself (but none of the other services or daemons)
2643 * running even though the "peer" is being varied offline.
2644 * 2782 *
2645 * @param pg handle for the peer group 2783 * @param pg handle for the peer group
2646 * @param voff number of peers that should go offline 2784 * @param voff number of peers that should go offline
@@ -2707,6 +2845,11 @@ GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg,
2707 running = 0; 2845 running = 0;
2708 stopped = 0; 2846 stopped = 0;
2709 2847
2848 churn_ctx->num_to_start = von;
2849 churn_ctx->num_to_stop = voff;
2850 churn_ctx->cb = cb;
2851 churn_ctx->cb_cls = cb_cls;
2852
2710 for (i = 0; i < pg->total; i++) 2853 for (i = 0; i < pg->total; i++)
2711 { 2854 {
2712 if (pg->peers[i].daemon->running == GNUNET_YES) 2855 if (pg->peers[i].daemon->running == GNUNET_YES)
@@ -2730,7 +2873,6 @@ GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg,
2730 { 2873 {
2731 GNUNET_TESTING_daemon_start_stopped(pg->peers[stopped_arr[stopped_permute[i]]].daemon, timeout, &churn_start_callback, churn_ctx); 2874 GNUNET_TESTING_daemon_start_stopped(pg->peers[stopped_arr[stopped_permute[i]]].daemon, timeout, &churn_start_callback, churn_ctx);
2732 } 2875 }
2733
2734} 2876}
2735 2877
2736 2878