diff options
Diffstat (limited to 'src/pt/test_gns_vpn.c')
-rw-r--r-- | src/pt/test_gns_vpn.c | 294 |
1 files changed, 222 insertions, 72 deletions
diff --git a/src/pt/test_gns_vpn.c b/src/pt/test_gns_vpn.c index 3661b2ed6..c426aa43c 100644 --- a/src/pt/test_gns_vpn.c +++ b/src/pt/test_gns_vpn.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include <curl/curl.h> | 27 | #include <curl/curl.h> |
28 | #include <microhttpd.h> | 28 | #include <microhttpd.h> |
29 | #include "gnunet_identity_service.h" | ||
29 | #include "gnunet_namestore_service.h" | 30 | #include "gnunet_namestore_service.h" |
30 | #include "gnunet_gnsrecord_lib.h" | 31 | #include "gnunet_gnsrecord_lib.h" |
31 | #include "gnunet_gns_service.h" | 32 | #include "gnunet_gns_service.h" |
@@ -45,9 +46,13 @@ static struct GNUNET_NAMESTORE_Handle *namestore; | |||
45 | 46 | ||
46 | static struct MHD_Daemon *mhd; | 47 | static struct MHD_Daemon *mhd; |
47 | 48 | ||
48 | static struct GNUNET_SCHEDULER_Task * mhd_task_id; | 49 | static struct GNUNET_SCHEDULER_Task *mhd_task_id; |
49 | 50 | ||
50 | static struct GNUNET_SCHEDULER_Task * curl_task_id; | 51 | static struct GNUNET_SCHEDULER_Task *curl_task_id; |
52 | |||
53 | static struct GNUNET_IDENTITY_Handle *identity; | ||
54 | |||
55 | static struct GNUNET_NAMESTORE_QueueEntry *qe; | ||
51 | 56 | ||
52 | static CURL *curl; | 57 | static CURL *curl; |
53 | 58 | ||
@@ -55,6 +60,8 @@ static CURLM *multi; | |||
55 | 60 | ||
56 | static char *url; | 61 | static char *url; |
57 | 62 | ||
63 | static struct GNUNET_PeerIdentity id; | ||
64 | |||
58 | /** | 65 | /** |
59 | * IP address of the ultimate destination. | 66 | * IP address of the ultimate destination. |
60 | */ | 67 | */ |
@@ -129,7 +136,8 @@ mhd_ahc (void *cls, | |||
129 | 136 | ||
130 | 137 | ||
131 | static void | 138 | static void |
132 | do_shutdown () | 139 | do_shutdown (void *cls, |
140 | const struct GNUNET_SCHEDULER_TaskContext *c) | ||
133 | { | 141 | { |
134 | if (mhd_task_id != NULL) | 142 | if (mhd_task_id != NULL) |
135 | { | 143 | { |
@@ -146,6 +154,16 @@ do_shutdown () | |||
146 | MHD_stop_daemon (mhd); | 154 | MHD_stop_daemon (mhd); |
147 | mhd = NULL; | 155 | mhd = NULL; |
148 | } | 156 | } |
157 | if (NULL != identity) | ||
158 | { | ||
159 | GNUNET_IDENTITY_disconnect (identity); | ||
160 | identity = NULL; | ||
161 | } | ||
162 | if (NULL != qe) | ||
163 | { | ||
164 | GNUNET_NAMESTORE_cancel (qe); | ||
165 | qe = NULL; | ||
166 | } | ||
149 | GNUNET_free_non_null (url); | 167 | GNUNET_free_non_null (url); |
150 | url = NULL; | 168 | url = NULL; |
151 | } | 169 | } |
@@ -217,7 +235,7 @@ curl_main () | |||
217 | global_ret = 3; | 235 | global_ret = 3; |
218 | } | 236 | } |
219 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download complete, shutting down!\n"); | 237 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download complete, shutting down!\n"); |
220 | do_shutdown (); | 238 | GNUNET_SCHEDULER_shutdown (); |
221 | return; | 239 | return; |
222 | } | 240 | } |
223 | GNUNET_assert (CURLM_OK == curl_multi_fdset (multi, &rs, &ws, &es, &max)); | 241 | GNUNET_assert (CURLM_OK == curl_multi_fdset (multi, &rs, &ws, &es, &max)); |
@@ -253,13 +271,15 @@ start_curl (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
253 | curl_easy_setopt (curl, CURLOPT_WRITEDATA, &cbc); | 271 | curl_easy_setopt (curl, CURLOPT_WRITEDATA, &cbc); |
254 | curl_easy_setopt (curl, CURLOPT_FAILONERROR, 1); | 272 | curl_easy_setopt (curl, CURLOPT_FAILONERROR, 1); |
255 | curl_easy_setopt (curl, CURLOPT_TIMEOUT, 150L); | 273 | curl_easy_setopt (curl, CURLOPT_TIMEOUT, 150L); |
256 | curl_easy_setopt (curl, CURLOPT_CONNECTTIMEOUT, 15L); | 274 | curl_easy_setopt (curl, CURLOPT_CONNECTTIMEOUT, 150L); |
257 | curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1); | 275 | curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1); |
258 | 276 | ||
259 | multi = curl_multi_init (); | 277 | multi = curl_multi_init (); |
260 | GNUNET_assert (multi != NULL); | 278 | GNUNET_assert (multi != NULL); |
261 | GNUNET_assert (CURLM_OK == curl_multi_add_handle (multi, curl)); | 279 | GNUNET_assert (CURLM_OK == curl_multi_add_handle (multi, curl)); |
262 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Beginning HTTP download from `%s'\n", url); | 280 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
281 | "Beginning HTTP download from `%s'\n", | ||
282 | url); | ||
263 | curl_main (); | 283 | curl_main (); |
264 | } | 284 | } |
265 | 285 | ||
@@ -292,11 +312,15 @@ commence_testing (void *cls, int32_t success, const char *emsg) | |||
292 | if ((emsg != NULL) && (GNUNET_YES != success)) | 312 | if ((emsg != NULL) && (GNUNET_YES != success)) |
293 | { | 313 | { |
294 | fprintf (stderr, | 314 | fprintf (stderr, |
295 | "NS failed to create record %s\n", emsg); | 315 | "NS failed to create record %s\n", |
316 | emsg); | ||
296 | GNUNET_SCHEDULER_shutdown (); | 317 | GNUNET_SCHEDULER_shutdown (); |
297 | return; | 318 | return; |
298 | } | 319 | } |
299 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), &start_curl, NULL); | 320 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
321 | (GNUNET_TIME_UNIT_SECONDS, 10), | ||
322 | &start_curl, | ||
323 | NULL); | ||
300 | } | 324 | } |
301 | 325 | ||
302 | 326 | ||
@@ -356,70 +380,6 @@ mhd_main () | |||
356 | } | 380 | } |
357 | 381 | ||
358 | 382 | ||
359 | static void | ||
360 | run (void *cls, | ||
361 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
362 | struct GNUNET_TESTING_Peer *peer) | ||
363 | { | ||
364 | enum MHD_FLAG flags; | ||
365 | struct GNUNET_PeerIdentity id; | ||
366 | char *peername; | ||
367 | struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key; | ||
368 | struct GNUNET_GNSRECORD_Data rd; | ||
369 | char *rd_string; | ||
370 | char *zone_keyfile; | ||
371 | |||
372 | GNUNET_TESTING_peer_get_identity (peer, &id); | ||
373 | peername = GNUNET_strdup (GNUNET_i2s_full (&id)); | ||
374 | |||
375 | namestore = GNUNET_NAMESTORE_connect (cfg); | ||
376 | GNUNET_assert (NULL != namestore); | ||
377 | flags = MHD_USE_DEBUG; | ||
378 | if (GNUNET_YES == use_v6) | ||
379 | flags |= MHD_USE_IPv6; | ||
380 | mhd = MHD_start_daemon (flags, | ||
381 | PORT, | ||
382 | NULL, NULL, | ||
383 | &mhd_ahc, NULL, | ||
384 | MHD_OPTION_END); | ||
385 | GNUNET_assert (NULL != mhd); | ||
386 | mhd_main (); | ||
387 | |||
388 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns", | ||
389 | "ZONEKEY", | ||
390 | &zone_keyfile)) | ||
391 | { | ||
392 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
393 | "Failed to get key from cfg\n"); | ||
394 | GNUNET_free (peername); | ||
395 | return; | ||
396 | } | ||
397 | |||
398 | zone_key = GNUNET_CRYPTO_ecdsa_key_create_from_file (zone_keyfile); | ||
399 | rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; | ||
400 | GNUNET_asprintf (&rd_string, | ||
401 | "6 %s %s", | ||
402 | peername, | ||
403 | "www.gnu."); | ||
404 | GNUNET_free (peername); | ||
405 | GNUNET_assert (GNUNET_OK == | ||
406 | GNUNET_GNSRECORD_string_to_value (GNUNET_GNSRECORD_TYPE_VPN, | ||
407 | rd_string, | ||
408 | (void**) &rd.data, | ||
409 | &rd.data_size)); | ||
410 | rd.record_type = GNUNET_GNSRECORD_TYPE_VPN; | ||
411 | |||
412 | GNUNET_NAMESTORE_records_store (namestore, | ||
413 | zone_key, | ||
414 | "www", | ||
415 | 1, &rd, | ||
416 | &commence_testing, | ||
417 | NULL); | ||
418 | GNUNET_free ((void**)rd.data); | ||
419 | GNUNET_free (rd_string); | ||
420 | GNUNET_free (zone_keyfile); | ||
421 | GNUNET_free (zone_key); | ||
422 | } | ||
423 | 383 | ||
424 | 384 | ||
425 | /** | 385 | /** |
@@ -505,6 +465,194 @@ fork_and_exec (const char *file, | |||
505 | return 0; | 465 | return 0; |
506 | } | 466 | } |
507 | 467 | ||
468 | |||
469 | |||
470 | /** | ||
471 | * Method called to inform about the egos of this peer. | ||
472 | * | ||
473 | * When used with #GNUNET_IDENTITY_connect, this function is | ||
474 | * initially called for all egos and then again whenever a | ||
475 | * ego's name changes or if it is deleted. At the end of | ||
476 | * the initial pass over all egos, the function is once called | ||
477 | * with 'NULL' for @a ego. That does NOT mean that the callback won't | ||
478 | * be invoked in the future or that there was an error. | ||
479 | * | ||
480 | * When used with #GNUNET_IDENTITY_create or #GNUNET_IDENTITY_get, | ||
481 | * this function is only called ONCE, and 'NULL' being passed in | ||
482 | * @a ego does indicate an error (i.e. name is taken or no default | ||
483 | * value is known). If @a ego is non-NULL and if '*ctx' | ||
484 | * is set in those callbacks, the value WILL be passed to a subsequent | ||
485 | * call to the identity callback of #GNUNET_IDENTITY_connect (if | ||
486 | * that one was not NULL). | ||
487 | * | ||
488 | * When an identity is renamed, this function is called with the | ||
489 | * (known) @a ego but the NEW @a name. | ||
490 | * | ||
491 | * When an identity is deleted, this function is called with the | ||
492 | * (known) ego and "NULL" for the @a name. In this case, | ||
493 | * the @a ego is henceforth invalid (and the @a ctx should also be | ||
494 | * cleaned up). | ||
495 | * | ||
496 | * @param cls closure | ||
497 | * @param ego ego handle | ||
498 | * @param ctx context for application to store data for this ego | ||
499 | * (during the lifetime of this process, initially NULL) | ||
500 | * @param name name assigned by the user for this ego, | ||
501 | * NULL if the user just deleted the ego and it | ||
502 | * must thus no longer be used | ||
503 | */ | ||
504 | static void | ||
505 | identity_cb (void *cls, | ||
506 | struct GNUNET_IDENTITY_Ego *ego, | ||
507 | void **ctx, | ||
508 | const char *name) | ||
509 | { | ||
510 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key; | ||
511 | struct GNUNET_GNSRECORD_Data rd; | ||
512 | char *rd_string; | ||
513 | char *peername; | ||
514 | |||
515 | if (NULL == name) | ||
516 | return; | ||
517 | if (NULL == ego) | ||
518 | { | ||
519 | if (NULL == qe) | ||
520 | { | ||
521 | fprintf (stderr, | ||
522 | "Failed to find master-zone ego\n"); | ||
523 | GNUNET_SCHEDULER_shutdown (); | ||
524 | return; | ||
525 | } | ||
526 | GNUNET_IDENTITY_disconnect (identity); | ||
527 | identity = NULL; | ||
528 | return; | ||
529 | } | ||
530 | GNUNET_assert (NULL != name); | ||
531 | if (0 != strcmp (name, | ||
532 | "master-zone")) | ||
533 | { | ||
534 | fprintf (stderr, | ||
535 | "Unexpected name %s\n", | ||
536 | name); | ||
537 | return; | ||
538 | } | ||
539 | /* FIXME: we somehow need to get this zone-key into | ||
540 | the 'DNS_ROOT' option of the 'gns' service. This | ||
541 | is currently why the test fails... */ | ||
542 | zone_key = GNUNET_IDENTITY_ego_get_private_key (ego); | ||
543 | rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; | ||
544 | peername = GNUNET_strdup (GNUNET_i2s_full (&id)); | ||
545 | GNUNET_asprintf (&rd_string, | ||
546 | "6 %s %s", | ||
547 | peername, | ||
548 | "www.gnu."); | ||
549 | GNUNET_free (peername); | ||
550 | GNUNET_assert (GNUNET_OK == | ||
551 | GNUNET_GNSRECORD_string_to_value (GNUNET_GNSRECORD_TYPE_VPN, | ||
552 | rd_string, | ||
553 | (void**) &rd.data, | ||
554 | &rd.data_size)); | ||
555 | rd.record_type = GNUNET_GNSRECORD_TYPE_VPN; | ||
556 | |||
557 | qe = GNUNET_NAMESTORE_records_store (namestore, | ||
558 | zone_key, | ||
559 | "www", | ||
560 | 1, &rd, | ||
561 | &commence_testing, | ||
562 | NULL); | ||
563 | GNUNET_free ((void**)rd.data); | ||
564 | GNUNET_free (rd_string); | ||
565 | } | ||
566 | |||
567 | |||
568 | static void | ||
569 | run (void *cls, | ||
570 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
571 | struct GNUNET_TESTING_Peer *peer) | ||
572 | { | ||
573 | enum MHD_FLAG flags; | ||
574 | |||
575 | char *bin; | ||
576 | char *bin_identity; | ||
577 | char *config; | ||
578 | |||
579 | if (GNUNET_OK != | ||
580 | GNUNET_CONFIGURATION_get_value_string (cfg, | ||
581 | "arm", | ||
582 | "CONFIG", | ||
583 | &config)) | ||
584 | { | ||
585 | fprintf (stderr, | ||
586 | "Failed to locate configuration file. Skipping test.\n"); | ||
587 | GNUNET_SCHEDULER_shutdown (); | ||
588 | return; | ||
589 | } | ||
590 | |||
591 | char *const identity_args[] = | ||
592 | { | ||
593 | "gnunet-identity", | ||
594 | "-C", "master-zone", | ||
595 | "-c", config, | ||
596 | NULL | ||
597 | }; | ||
598 | char *const identity2_args[] = | ||
599 | { | ||
600 | "gnunet-identity", | ||
601 | "-e", "master-zone", | ||
602 | "-s", "gns-master", | ||
603 | "-c", config, | ||
604 | NULL | ||
605 | }; | ||
606 | GNUNET_TESTING_peer_get_identity (peer, &id); | ||
607 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, | ||
608 | &do_shutdown, | ||
609 | NULL); | ||
610 | bin = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_BINDIR); | ||
611 | GNUNET_asprintf (&bin_identity, | ||
612 | "%s/%s", | ||
613 | bin, | ||
614 | "gnunet-identity"); | ||
615 | GNUNET_free (bin); | ||
616 | if (0 != fork_and_exec (bin_identity, identity_args)) | ||
617 | { | ||
618 | fprintf (stderr, | ||
619 | "Failed to run `gnunet-identity -C. Skipping test.\n"); | ||
620 | GNUNET_SCHEDULER_shutdown (); | ||
621 | GNUNET_free (bin_identity); | ||
622 | GNUNET_free (config); | ||
623 | return; | ||
624 | } | ||
625 | if (0 != fork_and_exec (bin_identity, identity2_args)) | ||
626 | { | ||
627 | fprintf (stderr, | ||
628 | "Failed to run `gnunet-identity -e. Skipping test.\n"); | ||
629 | GNUNET_SCHEDULER_shutdown (); | ||
630 | GNUNET_free (bin_identity); | ||
631 | GNUNET_free (config); | ||
632 | return; | ||
633 | } | ||
634 | GNUNET_free (bin_identity); | ||
635 | GNUNET_free (config); | ||
636 | |||
637 | namestore = GNUNET_NAMESTORE_connect (cfg); | ||
638 | GNUNET_assert (NULL != namestore); | ||
639 | flags = MHD_USE_DEBUG; | ||
640 | if (GNUNET_YES == use_v6) | ||
641 | flags |= MHD_USE_IPv6; | ||
642 | mhd = MHD_start_daemon (flags, | ||
643 | PORT, | ||
644 | NULL, NULL, | ||
645 | &mhd_ahc, NULL, | ||
646 | MHD_OPTION_END); | ||
647 | GNUNET_assert (NULL != mhd); | ||
648 | mhd_main (); | ||
649 | |||
650 | identity = GNUNET_IDENTITY_connect (cfg, | ||
651 | &identity_cb, | ||
652 | NULL); | ||
653 | } | ||
654 | |||
655 | |||
508 | int | 656 | int |
509 | main (int argc, char *const *argv) | 657 | main (int argc, char *const *argv) |
510 | { | 658 | { |
@@ -591,6 +739,8 @@ main (int argc, char *const *argv) | |||
591 | fprintf (stderr, "failed to initialize curl\n"); | 739 | fprintf (stderr, "failed to initialize curl\n"); |
592 | return 2; | 740 | return 2; |
593 | } | 741 | } |
742 | |||
743 | |||
594 | if (0 != GNUNET_TESTING_peer_run ("test-gnunet-vpn", | 744 | if (0 != GNUNET_TESTING_peer_run ("test-gnunet-vpn", |
595 | "test_gns_vpn.conf", | 745 | "test_gns_vpn.conf", |
596 | &run, NULL)) | 746 | &run, NULL)) |