diff options
Diffstat (limited to 'src/transport/transport-testing.c')
-rw-r--r-- | src/transport/transport-testing.c | 105 |
1 files changed, 103 insertions, 2 deletions
diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c index fb7535750..6892b2556 100644 --- a/src/transport/transport-testing.c +++ b/src/transport/transport-testing.c | |||
@@ -28,7 +28,30 @@ | |||
28 | #include "transport-testing.h" | 28 | #include "transport-testing.h" |
29 | 29 | ||
30 | #define VERBOSE GNUNET_EXTRA_LOGGING | 30 | #define VERBOSE GNUNET_EXTRA_LOGGING |
31 | #define HOSTKEYFILESIZE 914 | ||
31 | 32 | ||
33 | static const char * | ||
34 | get_host_key (struct GNUNET_TRANSPORT_TESTING_handle *tth) | ||
35 | { | ||
36 | if (tth->hostkey_data == NULL) | ||
37 | { | ||
38 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", | ||
39 | "No precomputed hostkeys available\n"); | ||
40 | return NULL; | ||
41 | } | ||
42 | if (tth->hostkeys_total > tth->hostkeys_last) | ||
43 | { | ||
44 | tth->hostkeys_last++; | ||
45 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", | ||
46 | "Used hostkey %u of %u available hostkeys\n", | ||
47 | tth->hostkeys_last, tth->hostkeys_total); | ||
48 | return &tth->hostkey_data[(tth->hostkeys_last - 1) * HOSTKEYFILESIZE]; | ||
49 | } | ||
50 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", | ||
51 | "No hostkey available (%u of %u already used)\n", | ||
52 | tth->hostkeys_last, tth->hostkeys_total); | ||
53 | return NULL; | ||
54 | } | ||
32 | 55 | ||
33 | static struct PeerContext * | 56 | static struct PeerContext * |
34 | find_peer_context (struct GNUNET_TRANSPORT_TESTING_handle *tth, | 57 | find_peer_context (struct GNUNET_TRANSPORT_TESTING_handle *tth, |
@@ -246,6 +269,9 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle | |||
246 | GNUNET_TRANSPORT_TESTING_start_cb start_cb, | 269 | GNUNET_TRANSPORT_TESTING_start_cb start_cb, |
247 | void *cb_cls) | 270 | void *cb_cls) |
248 | { | 271 | { |
272 | const char *hostkey = NULL; | ||
273 | struct GNUNET_DISK_FileHandle *fn; | ||
274 | |||
249 | GNUNET_assert (tth != NULL); | 275 | GNUNET_assert (tth != NULL); |
250 | if (GNUNET_DISK_file_test (cfgname) == GNUNET_NO) | 276 | if (GNUNET_DISK_file_test (cfgname) == GNUNET_NO) |
251 | { | 277 | { |
@@ -259,13 +285,36 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle | |||
259 | p->cfg = GNUNET_CONFIGURATION_create (); | 285 | p->cfg = GNUNET_CONFIGURATION_create (); |
260 | 286 | ||
261 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 287 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
288 | |||
289 | |||
262 | if (GNUNET_CONFIGURATION_have_value (p->cfg, "PATHS", "SERVICEHOME")) | 290 | if (GNUNET_CONFIGURATION_have_value (p->cfg, "PATHS", "SERVICEHOME")) |
263 | GNUNET_assert (GNUNET_OK == | 291 | GNUNET_assert (GNUNET_OK == |
264 | GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", | 292 | GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", |
265 | "SERVICEHOME", | 293 | "SERVICEHOME", |
266 | &p->servicehome)); | 294 | &p->servicehome)); |
267 | if (NULL != p->servicehome) | 295 | |
268 | GNUNET_DISK_directory_remove (p->servicehome); | 296 | if (NULL != p->servicehome) |
297 | GNUNET_DISK_directory_remove (p->servicehome); | ||
298 | |||
299 | hostkey = get_host_key(tth); | ||
300 | if (hostkey != NULL) | ||
301 | { | ||
302 | |||
303 | GNUNET_asprintf (&p->hostkeyfile, "%s/.hostkey", p->servicehome); | ||
304 | GNUNET_assert(GNUNET_OK == GNUNET_DISK_directory_create_for_file (p->hostkeyfile)); | ||
305 | fn = GNUNET_DISK_file_open (p->hostkeyfile, | ||
306 | GNUNET_DISK_OPEN_READWRITE | | ||
307 | GNUNET_DISK_OPEN_CREATE, | ||
308 | GNUNET_DISK_PERM_USER_READ | | ||
309 | GNUNET_DISK_PERM_USER_WRITE); | ||
310 | GNUNET_assert (fn != NULL); | ||
311 | GNUNET_assert (HOSTKEYFILESIZE == | ||
312 | GNUNET_DISK_file_write (fn, hostkey, HOSTKEYFILESIZE)); | ||
313 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fn)); | ||
314 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", | ||
315 | "Wrote hostkey to file: `%s' \n", p->hostkeyfile); | ||
316 | } | ||
317 | |||
269 | p->arm_proc = | 318 | p->arm_proc = |
270 | GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", | 319 | GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", |
271 | "gnunet-service-arm", "-c", cfgname, | 320 | "gnunet-service-arm", "-c", cfgname, |
@@ -326,6 +375,12 @@ GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth, | |||
326 | p->arm_proc = NULL; | 375 | p->arm_proc = NULL; |
327 | } | 376 | } |
328 | 377 | ||
378 | if (p->hostkeyfile != NULL) | ||
379 | { | ||
380 | GNUNET_DISK_directory_remove (p->hostkeyfile); | ||
381 | GNUNET_free (p->hostkeyfile); | ||
382 | } | ||
383 | |||
329 | if (p->servicehome != NULL) | 384 | if (p->servicehome != NULL) |
330 | { | 385 | { |
331 | GNUNET_DISK_directory_remove (p->servicehome); | 386 | GNUNET_DISK_directory_remove (p->servicehome); |
@@ -454,6 +509,8 @@ GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_handle *tth) | |||
454 | p = t; | 509 | p = t; |
455 | } | 510 | } |
456 | 511 | ||
512 | GNUNET_free_non_null (tth->hostkey_data); | ||
513 | |||
457 | GNUNET_free (tth); | 514 | GNUNET_free (tth); |
458 | tth = NULL; | 515 | tth = NULL; |
459 | } | 516 | } |
@@ -467,6 +524,50 @@ GNUNET_TRANSPORT_TESTING_init () | |||
467 | { | 524 | { |
468 | struct GNUNET_TRANSPORT_TESTING_handle *tth = | 525 | struct GNUNET_TRANSPORT_TESTING_handle *tth = |
469 | GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_TESTING_handle)); | 526 | GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_TESTING_handle)); |
527 | struct GNUNET_DISK_FileHandle *fd; | ||
528 | uint64_t fs; | ||
529 | uint64_t total_hostkeys; | ||
530 | |||
531 | |||
532 | /* prepare hostkeys */ | ||
533 | tth->hostkey_data = NULL; | ||
534 | char * hostkeys_file = "../../contrib/testing_hostkeys.dat"; | ||
535 | if (GNUNET_YES != GNUNET_DISK_file_test (hostkeys_file)) | ||
536 | { | ||
537 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
538 | _("Could not read hostkeys file!\n")); | ||
539 | } | ||
540 | else | ||
541 | { | ||
542 | /* Check hostkey file size, read entire thing into memory */ | ||
543 | fd = GNUNET_DISK_file_open (hostkeys_file, GNUNET_DISK_OPEN_READ, | ||
544 | GNUNET_DISK_PERM_NONE); | ||
545 | if (NULL == fd) | ||
546 | { | ||
547 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", | ||
548 | hostkeys_file); | ||
549 | return NULL; | ||
550 | } | ||
551 | |||
552 | if (GNUNET_YES != GNUNET_DISK_file_size (hostkeys_file, &fs, GNUNET_YES)) | ||
553 | fs = 0; | ||
554 | |||
555 | if (0 != (fs % HOSTKEYFILESIZE)) | ||
556 | { | ||
557 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing", | ||
558 | "File size %llu seems incorrect for hostkeys...\n", fs); | ||
559 | } | ||
560 | else | ||
561 | { | ||
562 | total_hostkeys = fs / HOSTKEYFILESIZE; | ||
563 | tth->hostkey_data = GNUNET_malloc_large (fs); | ||
564 | GNUNET_assert (fs == GNUNET_DISK_file_read (fd, tth->hostkey_data, fs)); | ||
565 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", | ||
566 | "Read %llu hostkeys from file\n", total_hostkeys); | ||
567 | tth->hostkeys_total = total_hostkeys; | ||
568 | } | ||
569 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd)); | ||
570 | } | ||
470 | 571 | ||
471 | return tth; | 572 | return tth; |
472 | } | 573 | } |