aboutsummaryrefslogtreecommitdiff
path: root/src/peerinfo-tool/gnunet-peerinfo.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-12-14 20:52:16 +0000
committerChristian Grothoff <christian@grothoff.org>2014-12-14 20:52:16 +0000
commita8e5b09df9ce6f090ab4ecfde02fc7ab3b667c13 (patch)
treedd96afbbe0cfb435c94a377d6762100d4a205d05 /src/peerinfo-tool/gnunet-peerinfo.c
parentea17e83e666b0104b43d04423cef193f92199c26 (diff)
downloadgnunet-a8e5b09df9ce6f090ab4ecfde02fc7ab3b667c13.tar.gz
gnunet-a8e5b09df9ce6f090ab4ecfde02fc7ab3b667c13.zip
-fixing peerinfo part of #3559
Diffstat (limited to 'src/peerinfo-tool/gnunet-peerinfo.c')
-rw-r--r--src/peerinfo-tool/gnunet-peerinfo.c154
1 files changed, 87 insertions, 67 deletions
diff --git a/src/peerinfo-tool/gnunet-peerinfo.c b/src/peerinfo-tool/gnunet-peerinfo.c
index d826a8050..18e1f8da7 100644
--- a/src/peerinfo-tool/gnunet-peerinfo.c
+++ b/src/peerinfo-tool/gnunet-peerinfo.c
@@ -178,6 +178,16 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg;
178static GNUNET_SCHEDULER_TaskIdentifier tt; 178static GNUNET_SCHEDULER_TaskIdentifier tt;
179 179
180/** 180/**
181 * Pending #GNUNET_TRANSPORT_get_hello() operation.
182 */
183static struct GNUNET_TRANSPORT_GetHelloHandle *gh;
184
185/**
186 * Connection to transport service.
187 */
188static struct GNUNET_TRANSPORT_Handle *transport;
189
190/**
181 * Current iterator context (if active, otherwise NULL). 191 * Current iterator context (if active, otherwise NULL).
182 */ 192 */
183static struct GNUNET_PEERINFO_IteratorContext *pic; 193static struct GNUNET_PEERINFO_IteratorContext *pic;
@@ -202,6 +212,11 @@ static struct PrintContext *pc_tail;
202 */ 212 */
203static struct GNUNET_PEERINFO_AddContext *ac; 213static struct GNUNET_PEERINFO_AddContext *ac;
204 214
215/**
216 * Hello of this peer (if initialized).
217 */
218static struct GNUNET_HELLO_Message *my_hello;
219
205 220
206/** 221/**
207 * Main state machine that goes over all options and 222 * Main state machine that goes over all options and
@@ -436,44 +451,23 @@ count_addr (void *cls,
436 * @param err_msg error message 451 * @param err_msg error message
437 */ 452 */
438static void 453static void
439dump_my_hello (void *cls, 454dump_my_hello ()
440 const struct GNUNET_PeerIdentity *peer,
441 const struct GNUNET_HELLO_Message *hello,
442 const char *err_msg)
443{ 455{
444 unsigned int size; 456 unsigned int size;
445 unsigned int c_addr; 457 unsigned int c_addr;
446 458
447 if (NULL == peer) 459 size = GNUNET_HELLO_size (my_hello);
448 {
449 pic = NULL;
450 if (NULL != err_msg)
451 FPRINTF (stderr,
452 _("Error in communication with PEERINFO service: %s\n"),
453 err_msg);
454 tt = GNUNET_SCHEDULER_add_now (&state_machine,
455 NULL);
456 return;
457 }
458
459 if (NULL == hello)
460 {
461 FPRINTF (stderr,
462 _("Failure: Did not receive %s\n"),
463 "HELLO");
464 return;
465 }
466
467 size = GNUNET_HELLO_size (hello);
468 if (0 == size) 460 if (0 == size)
469 { 461 {
470 FPRINTF (stderr, 462 FPRINTF (stderr,
471 _("Failure: Received invalid %s\n"), 463 _("Failure: Received invalid %s\n"),
472 "HELLO"); 464 "HELLO");
473 return; 465 return;
474 } 466 }
475 if (GNUNET_SYSERR == 467 if (GNUNET_SYSERR ==
476 GNUNET_DISK_fn_write (dump_hello, hello, size, 468 GNUNET_DISK_fn_write (dump_hello,
469 my_hello,
470 size,
477 GNUNET_DISK_PERM_USER_READ | 471 GNUNET_DISK_PERM_USER_READ |
478 GNUNET_DISK_PERM_USER_WRITE | 472 GNUNET_DISK_PERM_USER_WRITE |
479 GNUNET_DISK_PERM_GROUP_READ | 473 GNUNET_DISK_PERM_GROUP_READ |
@@ -491,7 +485,7 @@ dump_my_hello (void *cls,
491 485
492 } 486 }
493 c_addr = 0; 487 c_addr = 0;
494 GNUNET_HELLO_iterate_addresses (hello, 488 GNUNET_HELLO_iterate_addresses (my_hello,
495 GNUNET_NO, 489 GNUNET_NO,
496 count_addr, 490 count_addr,
497 &c_addr); 491 &c_addr);
@@ -500,7 +494,7 @@ dump_my_hello (void *cls,
500 { 494 {
501 FPRINTF (stderr, 495 FPRINTF (stderr,
502 _("Wrote %s HELLO containing %u addresses with %u bytes to file `%s'\n"), 496 _("Wrote %s HELLO containing %u addresses with %u bytes to file `%s'\n"),
503 (GNUNET_YES == GNUNET_HELLO_is_friend_only(hello)) ? "friend-only": "public", 497 (GNUNET_YES == GNUNET_HELLO_is_friend_only (my_hello)) ? "friend-only": "public",
504 c_addr, 498 c_addr,
505 size, 499 size,
506 dump_hello); 500 dump_hello);
@@ -527,6 +521,8 @@ print_my_uri (void *cls,
527 const struct GNUNET_HELLO_Message *hello, 521 const struct GNUNET_HELLO_Message *hello,
528 const char *err_msg) 522 const char *err_msg)
529{ 523{
524 char *uri;
525
530 if (NULL == peer) 526 if (NULL == peer)
531 { 527 {
532 pic = NULL; 528 pic = NULL;
@@ -540,8 +536,8 @@ print_my_uri (void *cls,
540 536
541 if (NULL == hello) 537 if (NULL == hello)
542 return; 538 return;
543 char *uri = GNUNET_HELLO_compose_uri (hello, 539 uri = GNUNET_HELLO_compose_uri (hello,
544 &GPI_plugins_find); 540 &GPI_plugins_find);
545 if (NULL != uri) 541 if (NULL != uri)
546 { 542 {
547 printf ("%s\n", 543 printf ("%s\n",
@@ -640,6 +636,16 @@ shutdown_task (void *cls,
640 GNUNET_PEERINFO_iterate_cancel (pic); 636 GNUNET_PEERINFO_iterate_cancel (pic);
641 pic = NULL; 637 pic = NULL;
642 } 638 }
639 if (NULL != gh)
640 {
641 GNUNET_TRANSPORT_get_hello_cancel (gh);
642 gh = NULL;
643 }
644 if (NULL != transport)
645 {
646 GNUNET_TRANSPORT_disconnect (transport);
647 transport = NULL;
648 }
643 while (NULL != (pc = pc_head)) 649 while (NULL != (pc = pc_head))
644 { 650 {
645 GNUNET_CONTAINER_DLL_remove (pc_head, 651 GNUNET_CONTAINER_DLL_remove (pc_head,
@@ -664,6 +670,43 @@ shutdown_task (void *cls,
664 GNUNET_PEERINFO_disconnect (peerinfo); 670 GNUNET_PEERINFO_disconnect (peerinfo);
665 peerinfo = NULL; 671 peerinfo = NULL;
666 } 672 }
673 if (NULL != my_hello)
674 {
675 GNUNET_free (my_hello);
676 my_hello = NULL;
677 }
678}
679
680
681/**
682 * Function called with our peer's HELLO message.
683 * Used to obtain our peer's public key.
684 *
685 * @param cls NULL
686 * @param hello the HELLO message
687 */
688static void
689hello_callback (void *cls,
690 const struct GNUNET_MessageHeader *hello)
691{
692 if (NULL == hello)
693 {
694 fprintf (stderr,
695 _("Failed to get my own HELLO from this peer!\n"));
696 GNUNET_SCHEDULER_shutdown ();
697 return;
698 }
699 my_hello = (struct GNUNET_HELLO_Message *) GNUNET_copy_message (hello);
700 GNUNET_assert (GNUNET_OK ==
701 GNUNET_HELLO_get_id (hello,
702 &my_peer_identity));
703 GNUNET_TRANSPORT_get_hello_cancel (gh);
704 gh = NULL;
705 GNUNET_TRANSPORT_disconnect (transport);
706 transport = NULL;
707 if (NULL != dump_hello)
708 dump_my_hello ();
709 tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
667} 710}
668 711
669 712
@@ -700,33 +743,18 @@ testservice_task (void *cls,
700 (GNUNET_YES == get_uri) || 743 (GNUNET_YES == get_uri) ||
701 (NULL != dump_hello) ) 744 (NULL != dump_hello) )
702 { 745 {
703 /* load private key */ 746 transport = GNUNET_TRANSPORT_connect (cfg,
704 if (GNUNET_OK != 747 NULL,
705 GNUNET_CONFIGURATION_get_value_filename (cfg, 748 NULL,
706 "PEER", 749 NULL, NULL, NULL);
707 "PRIVATE_KEY", 750 gh = GNUNET_TRANSPORT_get_hello (transport,
708 &fn)) 751 &hello_callback,
709 { 752 NULL);
710 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 753 }
711 "PEER", 754 else
712 "PRIVATE_KEY"); 755 {
713 return; 756 tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
714 }
715 if (NULL == (priv = GNUNET_CRYPTO_eddsa_key_create_from_file (fn)))
716 {
717 FPRINTF (stderr,
718 _("Loading hostkey from `%s' failed.\n"),
719 fn);
720 GNUNET_free (fn);
721 return;
722 }
723 GNUNET_free (fn);
724 GNUNET_CRYPTO_eddsa_key_get_public (priv,
725 &my_peer_identity.public_key);
726 GNUNET_free (priv);
727 } 757 }
728
729 tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
730 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 758 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
731 &shutdown_task, 759 &shutdown_task,
732 NULL); 760 NULL);
@@ -827,14 +855,6 @@ state_machine (void *cls,
827 &print_my_uri, NULL); 855 &print_my_uri, NULL);
828 get_uri = GNUNET_NO; 856 get_uri = GNUNET_NO;
829 } 857 }
830 else if (NULL != dump_hello)
831 {
832 pic = GNUNET_PEERINFO_iterate (peerinfo,
833 include_friend_only,
834 &my_peer_identity,
835 TIMEOUT,
836 &dump_my_hello, NULL);
837 }
838 else if (GNUNET_YES == default_operation) 858 else if (GNUNET_YES == default_operation)
839 { 859 {
840 /* default operation list all */ 860 /* default operation list all */
@@ -843,8 +863,8 @@ state_machine (void *cls,
843 tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL); 863 tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
844 } 864 }
845 else 865 else
846 { 866 {
847 GNUNET_SCHEDULER_shutdown (); 867 GNUNET_SCHEDULER_shutdown ();
848 } 868 }
849 default_operation = GNUNET_NO; 869 default_operation = GNUNET_NO;
850} 870}