diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_testbed_service.h | 3 | ||||
-rw-r--r-- | src/testbed/sample_hosts.txt | 10 | ||||
-rw-r--r-- | src/testbed/test_testbed_api_hosts.c | 3 | ||||
-rw-r--r-- | src/testbed/testbed_api_hosts.c | 23 |
4 files changed, 28 insertions, 11 deletions
diff --git a/src/include/gnunet_testbed_service.h b/src/include/gnunet_testbed_service.h index 065cd0c0f..ba3b8961f 100644 --- a/src/include/gnunet_testbed_service.h +++ b/src/include/gnunet_testbed_service.h | |||
@@ -113,7 +113,8 @@ GNUNET_TESTBED_host_create_with_id (uint32_t id, | |||
113 | * Load a set of hosts from a configuration file. | 113 | * Load a set of hosts from a configuration file. |
114 | * | 114 | * |
115 | * @param filename file with the host specification | 115 | * @param filename file with the host specification |
116 | * @param hosts set to the hosts found in the file | 116 | * @param hosts set to the hosts found in the file; caller must free this if |
117 | * number of hosts returned is greater than 0 | ||
117 | * @return number of hosts returned in 'hosts', 0 on error | 118 | * @return number of hosts returned in 'hosts', 0 on error |
118 | */ | 119 | */ |
119 | unsigned int | 120 | unsigned int |
diff --git a/src/testbed/sample_hosts.txt b/src/testbed/sample_hosts.txt index 61b07f3c2..5b661696b 100644 --- a/src/testbed/sample_hosts.txt +++ b/src/testbed/sample_hosts.txt | |||
@@ -3,3 +3,13 @@ totakura@192.168.0.2:22 | |||
3 | totakura@192.168.0.3:22 | 3 | totakura@192.168.0.3:22 |
4 | totakura@192.168.0.4:22 | 4 | totakura@192.168.0.4:22 |
5 | totakura@192.168.0.5:22 | 5 | totakura@192.168.0.5:22 |
6 | totakura@192.168.0.6:22 | ||
7 | totakura@192.168.0.7:22 | ||
8 | totakura@192.168.0.8:22 | ||
9 | totakura@192.168.0.9:22 | ||
10 | totakura@192.168.0.10:22 | ||
11 | totakura@192.168.0.11:22 | ||
12 | totakura@192.168.0.12:22 | ||
13 | totakura@192.168.0.13:22 | ||
14 | totakura@192.168.0.14:22 | ||
15 | totakura@192.168.0.15:22 | ||
diff --git a/src/testbed/test_testbed_api_hosts.c b/src/testbed/test_testbed_api_hosts.c index e98bc8e21..0102b9e26 100644 --- a/src/testbed/test_testbed_api_hosts.c +++ b/src/testbed/test_testbed_api_hosts.c | |||
@@ -73,6 +73,7 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
73 | GNUNET_TESTBED_host_destroy (hosts[num_hosts - 1]); | 73 | GNUNET_TESTBED_host_destroy (hosts[num_hosts - 1]); |
74 | num_hosts--; | 74 | num_hosts--; |
75 | } | 75 | } |
76 | GNUNET_free (hosts); | ||
76 | } | 77 | } |
77 | 78 | ||
78 | 79 | ||
@@ -99,7 +100,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
99 | hosts = NULL; | 100 | hosts = NULL; |
100 | num_hosts = GNUNET_TESTBED_hosts_load_from_file ("sample_hosts.txt", | 101 | num_hosts = GNUNET_TESTBED_hosts_load_from_file ("sample_hosts.txt", |
101 | &hosts); | 102 | &hosts); |
102 | GNUNET_assert (5 == num_hosts); | 103 | GNUNET_assert (15 == num_hosts); |
103 | GNUNET_assert (NULL != hosts); | 104 | GNUNET_assert (NULL != hosts); |
104 | shutdown_id = | 105 | shutdown_id = |
105 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (2), &do_shutdown, NULL); | 106 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (2), &do_shutdown, NULL); |
diff --git a/src/testbed/testbed_api_hosts.c b/src/testbed/testbed_api_hosts.c index 91fffc92d..4a69a17dd 100644 --- a/src/testbed/testbed_api_hosts.c +++ b/src/testbed/testbed_api_hosts.c | |||
@@ -288,7 +288,8 @@ GNUNET_TESTBED_host_create (const char *hostname, const char *username, | |||
288 | * Load a set of hosts from a configuration file. | 288 | * Load a set of hosts from a configuration file. |
289 | * | 289 | * |
290 | * @param filename file with the host specification | 290 | * @param filename file with the host specification |
291 | * @param hosts set to the hosts found in the file | 291 | * @param hosts set to the hosts found in the file; caller must free this if |
292 | * number of hosts returned is greater than 0 | ||
292 | * @return number of hosts returned in 'hosts', 0 on error | 293 | * @return number of hosts returned in 'hosts', 0 on error |
293 | */ | 294 | */ |
294 | unsigned int | 295 | unsigned int |
@@ -339,6 +340,8 @@ GNUNET_TESTBED_hosts_load_from_file (const char *filename, | |||
339 | if (((data[offset] == '\n')) && (buf != &data[offset])) | 340 | if (((data[offset] == '\n')) && (buf != &data[offset])) |
340 | { | 341 | { |
341 | data[offset] = '\0'; | 342 | data[offset] = '\0'; |
343 | username = NULL; | ||
344 | hostname = NULL; | ||
342 | ret = SSCANF (buf, "%a[a-zA-Z0-9_]@%a[a-zA-Z0-9.]:%hd", | 345 | ret = SSCANF (buf, "%a[a-zA-Z0-9_]@%a[a-zA-Z0-9.]:%hd", |
343 | &username, &hostname, &port); | 346 | &username, &hostname, &port); |
344 | if (3 == ret) | 347 | if (3 == ret) |
@@ -347,19 +350,19 @@ GNUNET_TESTBED_hosts_load_from_file (const char *filename, | |||
347 | "Successfully read host %s, port %d and user %s from file\n", | 350 | "Successfully read host %s, port %d and user %s from file\n", |
348 | hostname, port, username); | 351 | hostname, port, username); |
349 | /* We store hosts in a static list; hence we only require the starting | 352 | /* We store hosts in a static list; hence we only require the starting |
350 | host pointer in that list to get the newly created list of hosts */ | 353 | host pointer in that list to access the newly created list of hosts */ |
351 | if (NULL == starting_host) | 354 | if (NULL == starting_host) |
352 | starting_host = GNUNET_TESTBED_host_create (hostname, username, | 355 | starting_host = GNUNET_TESTBED_host_create (hostname, username, |
353 | port); | 356 | port); |
354 | else | 357 | else |
355 | (void) GNUNET_TESTBED_host_create (hostname, username, port); | 358 | (void) GNUNET_TESTBED_host_create (hostname, username, port); |
356 | count++; | 359 | count++; |
357 | GNUNET_free (hostname); | ||
358 | GNUNET_free (username); | ||
359 | } | 360 | } |
360 | else | 361 | else |
361 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 362 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
362 | "Error reading line `%s' in hostfile\n", buf); | 363 | "Error reading line `%s' in hostfile\n", buf); |
364 | GNUNET_free_non_null (hostname); | ||
365 | GNUNET_free_non_null (username); | ||
363 | buf = &data[offset + 1]; | 366 | buf = &data[offset + 1]; |
364 | } | 367 | } |
365 | else if ((data[offset] == '\n') || (data[offset] == '\0')) | 368 | else if ((data[offset] == '\n') || (data[offset] == '\0')) |
@@ -368,7 +371,10 @@ GNUNET_TESTBED_hosts_load_from_file (const char *filename, | |||
368 | GNUNET_free (data); | 371 | GNUNET_free (data); |
369 | if (NULL == starting_host) | 372 | if (NULL == starting_host) |
370 | return 0; | 373 | return 0; |
371 | *hosts = &host_list[GNUNET_TESTBED_host_get_id_ (starting_host)]; | 374 | *hosts = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Host *) * count); |
375 | memcpy (*hosts, | ||
376 | &host_list[GNUNET_TESTBED_host_get_id_ (starting_host)], | ||
377 | sizeof (struct GNUNET_TESTBED_Host *) * count); | ||
372 | return count; | 378 | return count; |
373 | } | 379 | } |
374 | 380 | ||
@@ -411,10 +417,9 @@ GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host) | |||
411 | break; | 417 | break; |
412 | host_list_size -= HOST_LIST_GROW_STEP; | 418 | host_list_size -= HOST_LIST_GROW_STEP; |
413 | } | 419 | } |
414 | if (orig_size != host_list_size) | 420 | host_list = |
415 | host_list = | 421 | GNUNET_realloc (host_list, |
416 | GNUNET_realloc (host_list, | 422 | sizeof (struct GNUNET_TESTBED_Host *) * host_list_size); |
417 | sizeof (struct GNUNET_TESTBED_Host *) * host_list_size); | ||
418 | } | 423 | } |
419 | 424 | ||
420 | 425 | ||