aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-09-17 10:45:23 +0000
committerChristian Grothoff <christian@grothoff.org>2012-09-17 10:45:23 +0000
commit7e065c18499688141eb68513058131a49344cac1 (patch)
treee441b44c8f0db8a4f214775e4945039cc820cf2f /src/transport
parentb3ad920b6e0107c3da946fe1f2f720955dbac151 (diff)
downloadgnunet-7e065c18499688141eb68513058131a49344cac1.tar.gz
gnunet-7e065c18499688141eb68513058131a49344cac1.zip
fixing #1551/#2503
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/gnunet-service-transport.c109
-rw-r--r--src/transport/test_plugin_transport.c68
2 files changed, 114 insertions, 63 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c
index 677d0033c..f9a4c7b9e 100644
--- a/src/transport/gnunet-service-transport.c
+++ b/src/transport/gnunet-service-transport.c
@@ -62,6 +62,16 @@ struct GNUNET_PeerIdentity GST_my_identity;
62struct GNUNET_PEERINFO_Handle *GST_peerinfo; 62struct GNUNET_PEERINFO_Handle *GST_peerinfo;
63 63
64/** 64/**
65 * Hostkey generation context
66 */
67struct GNUNET_CRYPTO_RsaKeyGenerationContext *GST_keygen;
68
69/**
70 * Handle to our service's server.
71 */
72static struct GNUNET_SERVER_Handle *GST_server;
73
74/**
65 * Our public key. 75 * Our public key.
66 */ 76 */
67struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded GST_my_public_key; 77struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded GST_my_public_key;
@@ -271,7 +281,7 @@ plugin_env_receive_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
271 break; 281 break;
272 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK: 282 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK:
273 GST_neighbours_handle_session_ack (message, peer, &address, session, ats, 283 GST_neighbours_handle_session_ack (message, peer, &address, session, ats,
274 ats_count); 284 ats_count);
275 break; 285 break;
276 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT: 286 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT:
277 GST_neighbours_handle_disconnect_message (peer, message); 287 GST_neighbours_handle_disconnect_message (peer, message);
@@ -539,6 +549,11 @@ neighbours_address_notification (void *cls,
539static void 549static void
540shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 550shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
541{ 551{
552 if (NULL != GST_keygen)
553 {
554 GNUNET_CRYPTO_rsa_key_create_stop (GST_keygen);
555 GST_keygen = NULL;
556 }
542 GST_neighbours_stop (); 557 GST_neighbours_stop ();
543 GST_validation_stop (); 558 GST_validation_stop ();
544 GST_plugins_unload (); 559 GST_plugins_unload ();
@@ -549,17 +564,17 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
549 GST_blacklist_stop (); 564 GST_blacklist_stop ();
550 GST_hello_stop (); 565 GST_hello_stop ();
551 566
552 if (GST_peerinfo != NULL) 567 if (NULL != GST_peerinfo)
553 { 568 {
554 GNUNET_PEERINFO_disconnect (GST_peerinfo); 569 GNUNET_PEERINFO_disconnect (GST_peerinfo);
555 GST_peerinfo = NULL; 570 GST_peerinfo = NULL;
556 } 571 }
557 if (GST_stats != NULL) 572 if (NULL != GST_stats)
558 { 573 {
559 GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO); 574 GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO);
560 GST_stats = NULL; 575 GST_stats = NULL;
561 } 576 }
562 if (GST_my_private_key != NULL) 577 if (NULL != GST_my_private_key)
563 { 578 {
564 GNUNET_CRYPTO_rsa_key_free (GST_my_private_key); 579 GNUNET_CRYPTO_rsa_key_free (GST_my_private_key);
565 GST_my_private_key = NULL; 580 GST_my_private_key = NULL;
@@ -568,41 +583,32 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
568 583
569 584
570/** 585/**
571 * Initiate transport service. 586 * Callback for hostkey read/generation
572 * 587 *
573 * @param cls closure 588 * @param cls NULL
574 * @param server the initialized server 589 * @param pk the private key
575 * @param c configuration to use 590 * @param emsg error message
576 */ 591 */
577static void 592static void
578run (void *cls, struct GNUNET_SERVER_Handle *server, 593key_generation_cb (void *cls,
579 const struct GNUNET_CONFIGURATION_Handle *c) 594 struct GNUNET_CRYPTO_RsaPrivateKey *pk,
595 const char *emsg)
580{ 596{
581 char *keyfile;
582 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded tmp; 597 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded tmp;
583 /* setup globals */ 598
584 GST_cfg = c; 599 GST_keygen = NULL;
585 if (GNUNET_OK != 600 if (NULL == pk)
586 GNUNET_CONFIGURATION_get_value_filename (c, "GNUNETD", "HOSTKEY",
587 &keyfile))
588 {
589 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
590 _
591 ("Transport service is lacking key configuration settings. Exiting.\n"));
592 GNUNET_SCHEDULER_shutdown ();
593 return;
594 }
595 GST_my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
596 GNUNET_free (keyfile);
597 if (GST_my_private_key == NULL)
598 { 601 {
599 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 602 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
600 _("Transport service could not access hostkey. Exiting.\n")); 603 _("Transport service could not access hostkey: %s. Exiting.\n"),
604 emsg);
601 GNUNET_SCHEDULER_shutdown (); 605 GNUNET_SCHEDULER_shutdown ();
602 return; 606 return;
603 } 607 }
604 GST_stats = GNUNET_STATISTICS_create ("transport", c); 608 GST_my_private_key = pk;
605 GST_peerinfo = GNUNET_PEERINFO_connect (c); 609
610 GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg);
611 GST_peerinfo = GNUNET_PEERINFO_connect (GST_cfg);
606 memset (&GST_my_public_key, '\0', sizeof (GST_my_public_key)); 612 memset (&GST_my_public_key, '\0', sizeof (GST_my_public_key));
607 memset (&tmp, '\0', sizeof (tmp)); 613 memset (&tmp, '\0', sizeof (tmp));
608 GNUNET_CRYPTO_rsa_key_get_public (GST_my_private_key, &GST_my_public_key); 614 GNUNET_CRYPTO_rsa_key_get_public (GST_my_private_key, &GST_my_public_key);
@@ -614,7 +620,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
614 620
615 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, 621 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
616 NULL); 622 NULL);
617 if (GST_peerinfo == NULL) 623 if (NULL == GST_peerinfo)
618 { 624 {
619 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 625 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
620 _("Could not access PEERINFO service. Exiting.\n")); 626 _("Could not access PEERINFO service. Exiting.\n"));
@@ -625,7 +631,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
625 /* start subsystems */ 631 /* start subsystems */
626 GST_hello_start (&process_hello_update, NULL); 632 GST_hello_start (&process_hello_update, NULL);
627 GNUNET_assert (NULL != GST_hello_get()); 633 GNUNET_assert (NULL != GST_hello_get());
628 GST_blacklist_start (server); 634 GST_blacklist_start (GST_server);
629 GST_ats = 635 GST_ats =
630 GNUNET_ATS_scheduling_init (GST_cfg, &ats_request_address_change, NULL); 636 GNUNET_ATS_scheduling_init (GST_cfg, &ats_request_address_change, NULL);
631 GST_plugins_load (&plugin_env_receive_callback, 637 GST_plugins_load (&plugin_env_receive_callback,
@@ -636,8 +642,47 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
636 &neighbours_connect_notification, 642 &neighbours_connect_notification,
637 &neighbours_disconnect_notification, 643 &neighbours_disconnect_notification,
638 &neighbours_address_notification); 644 &neighbours_address_notification);
639 GST_clients_start (server); 645 GST_clients_start (GST_server);
640 GST_validation_start (); 646 GST_validation_start ();
647 GNUNET_SERVER_resume (GST_server);
648}
649
650
651/**
652 * Initiate transport service.
653 *
654 * @param cls closure
655 * @param server the initialized server
656 * @param c configuration to use
657 */
658static void
659run (void *cls, struct GNUNET_SERVER_Handle *server,
660 const struct GNUNET_CONFIGURATION_Handle *c)
661{
662 char *keyfile;
663
664 /* setup globals */
665 GST_cfg = c;
666 if (GNUNET_OK !=
667 GNUNET_CONFIGURATION_get_value_filename (c, "GNUNETD", "HOSTKEY",
668 &keyfile))
669 {
670 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
671 _
672 ("Transport service is lacking key configuration settings. Exiting.\n"));
673 GNUNET_SCHEDULER_shutdown ();
674 return;
675 }
676 GST_server = server;
677 GNUNET_SERVER_suspend (server);
678 GST_keygen = GNUNET_CRYPTO_rsa_key_create_start (keyfile, &key_generation_cb, NULL);
679 GNUNET_free (keyfile);
680 if (NULL == GST_keygen)
681 {
682 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
683 _("Transport service is unable to access hostkey. Exiting.\n"));
684 GNUNET_SCHEDULER_shutdown ();
685 }
641} 686}
642 687
643 688
diff --git a/src/transport/test_plugin_transport.c b/src/transport/test_plugin_transport.c
index e6a016c51..6882f919c 100644
--- a/src/transport/test_plugin_transport.c
+++ b/src/transport/test_plugin_transport.c
@@ -139,6 +139,7 @@ struct AddressWrapper
139 char *addrstring; 139 char *addrstring;
140}; 140};
141 141
142
142static void 143static void
143end () 144end ()
144{ 145{
@@ -186,6 +187,7 @@ end ()
186 } 187 }
187} 188}
188 189
190
189static void 191static void
190end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 192end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
191{ 193{
@@ -245,6 +247,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
245 ok = 1; 247 ok = 1;
246} 248}
247 249
250
248static void 251static void
249wait_end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 252wait_end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
250{ 253{
@@ -290,6 +293,7 @@ env_receive (void *cls,
290 293
291static int got_reply; 294static int got_reply;
292 295
296
293/** 297/**
294 * Take the given address and append it to the set of results sent back to 298 * Take the given address and append it to the set of results sent back to
295 * the client. 299 * the client.
@@ -435,7 +439,8 @@ env_notify_address (void *cls,
435 } 439 }
436} 440}
437 441
438struct GNUNET_ATS_Information 442
443static struct GNUNET_ATS_Information
439env_get_address_type (void *cls, 444env_get_address_type (void *cls,
440 const struct sockaddr *addr, 445 const struct sockaddr *addr,
441 size_t addrlen) 446 size_t addrlen)
@@ -446,19 +451,22 @@ env_get_address_type (void *cls,
446 return ats; 451 return ats;
447} 452}
448 453
449const struct GNUNET_MessageHeader * 454
450env_get_our_hello (void) 455static const struct GNUNET_MessageHeader *
456env_get_our_hello ()
451{ 457{
452 return (const struct GNUNET_MessageHeader *) hello; 458 return (const struct GNUNET_MessageHeader *) hello;
453} 459}
454 460
455void env_session_end (void *cls,
456 const struct GNUNET_PeerIdentity *peer,
457 struct Session * session)
458{
459 461
462static void
463env_session_end (void *cls,
464 const struct GNUNET_PeerIdentity *peer,
465 struct Session * session)
466{
460} 467}
461 468
469
462static void 470static void
463setup_plugin_environment () 471setup_plugin_environment ()
464{ 472{
@@ -482,6 +490,7 @@ handle_helper_message (void *cls, void *client,
482 return GNUNET_OK; 490 return GNUNET_OK;
483} 491}
484 492
493
485/** 494/**
486 * Runs the test. 495 * Runs the test.
487 * 496 *
@@ -502,33 +511,31 @@ run (void *cls, char *const *args, const char *cfgfile,
502 511
503 cfg = c; 512 cfg = c;
504 /* parse configuration */ 513 /* parse configuration */
505 if ((GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (c, 514 if ( (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (c,
506 "TRANSPORT", 515 "TRANSPORT",
507 "NEIGHBOUR_LIMIT", 516 "NEIGHBOUR_LIMIT",
508 &tneigh)) || 517 &tneigh)) ||
509 (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c, 518 (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c,
510 "GNUNETD", "HOSTKEY", 519 "GNUNETD", "HOSTKEY",
511 &keyfile))) 520 &keyfile)))
512 { 521 {
513 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 522 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
514 _("Transport service is lacking key configuration settings. Exiting.\n")); 523 _("Transport service is lacking key configuration settings. Exiting.\n"));
515
516 return; 524 return;
517 } 525 }
518 526
519 stats = GNUNET_STATISTICS_create ("transport", cfg); 527 if (NULL == (stats = GNUNET_STATISTICS_create ("transport", cfg)))
520 if (NULL == stats)
521 { 528 {
522 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 529 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
523 _("Could not create statistics. Exiting.\n")); 530 _("Could not create statistics. Exiting.\n"));
524 end_badly_now (); 531 end_badly_now ();
525 return; 532 return;
526 } 533 }
527 534
528 max_connect_per_transport = (uint32_t) tneigh; 535 max_connect_per_transport = (uint32_t) tneigh;
529 my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); 536 my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
530 GNUNET_free (keyfile); 537 GNUNET_free (keyfile);
531 if (my_private_key == NULL) 538 if (NULL == my_private_key)
532 { 539 {
533 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 540 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
534 _("Transport service could not access hostkey. Exiting.\n")); 541 _("Transport service could not access hostkey. Exiting.\n"));
@@ -638,7 +645,7 @@ run (void *cls, char *const *args, const char *cfgfile,
638 645
639 646
640/** 647/**
641 * The main function for the transport service. 648 * The main function for the test
642 * 649 *
643 * @param argc number of arguments from the command line 650 * @param argc number of arguments from the command line
644 * @param argv command line arguments 651 * @param argv command line arguments
@@ -656,20 +663,19 @@ main (int argc, char *const *argv)
656 "test_plugin_transport", 663 "test_plugin_transport",
657 "-c", 664 "-c",
658 "test_plugin_transport_data.conf", 665 "test_plugin_transport_data.conf",
659 "-L", "WARNING",
660 NULL 666 NULL
661 }; 667 };
662 GNUNET_log_setup ("test-plugin-transport", 668 GNUNET_log_setup ("test-plugin-transport",
663 "WARNING", 669 "WARNING",
664 NULL); 670 NULL);
665 ok = 1; /* set to fail */ 671 ok = 1; /* set to fail */
666 ret = (GNUNET_OK == GNUNET_PROGRAM_run (5, 672 ret = (GNUNET_OK == GNUNET_PROGRAM_run (3,
667 argv_prog, 673 argv_prog,
668 "test-plugin-transport", 674 "test-plugin-transport",
669 "testcase", 675 "testcase",
670 options, 676 options,
671 &run, 677 &run,
672 (void *) argv)) ? ok : 1; 678 (void *) argv)) ? ok : 1;
673 GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-plugin-transport"); 679 GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-plugin-transport");
674 return ret; 680 return ret;
675} 681}