aboutsummaryrefslogtreecommitdiff
path: root/src/peerinfo
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-06-09 08:54:49 +0000
committerChristian Grothoff <christian@grothoff.org>2014-06-09 08:54:49 +0000
commit995ff4c783691df5462353d0ef4f698942de1010 (patch)
treecb929c9f4e91d09e932c233c73ae9f48808e46a0 /src/peerinfo
parente703948983a444cf4204913602aac2191d72dc8b (diff)
downloadgnunet-995ff4c783691df5462353d0ef4f698942de1010.tar.gz
gnunet-995ff4c783691df5462353d0ef4f698942de1010.zip
-fixing doxygen, indentation
Diffstat (limited to 'src/peerinfo')
-rw-r--r--src/peerinfo/gnunet-service-peerinfo.c226
-rw-r--r--src/peerinfo/peerinfo_api.c139
2 files changed, 244 insertions, 121 deletions
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c
index 486cb24ba..8e58afc58 100644
--- a/src/peerinfo/gnunet-service-peerinfo.c
+++ b/src/peerinfo/gnunet-service-peerinfo.c
@@ -462,13 +462,17 @@ add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity)
462 entry = GNUNET_CONTAINER_multipeermap_get (hostmap, identity); 462 entry = GNUNET_CONTAINER_multipeermap_get (hostmap, identity);
463 if (NULL == entry) 463 if (NULL == entry)
464 { 464 {
465 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding new peer `%s'\n", GNUNET_i2s (identity)); 465 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
466 "Adding new peer `%s'\n",
467 GNUNET_i2s (identity));
466 GNUNET_STATISTICS_update (stats, gettext_noop ("# peers known"), 1, 468 GNUNET_STATISTICS_update (stats, gettext_noop ("# peers known"), 1,
467 GNUNET_NO); 469 GNUNET_NO);
468 entry = GNUNET_new (struct HostEntry); 470 entry = GNUNET_new (struct HostEntry);
469 entry->identity = *identity; 471 entry->identity = *identity;
470 GNUNET_assert (GNUNET_OK == 472 GNUNET_assert (GNUNET_OK ==
471 GNUNET_CONTAINER_multipeermap_put (hostmap, &entry->identity, entry, 473 GNUNET_CONTAINER_multipeermap_put (hostmap,
474 &entry->identity,
475 entry,
472 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 476 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
473 notify_all (entry); 477 notify_all (entry);
474 fn = get_host_filename (identity); 478 fn = get_host_filename (identity);
@@ -499,17 +503,18 @@ remove_garbage (const char *fullname)
499{ 503{
500 if (0 == UNLINK (fullname)) 504 if (0 == UNLINK (fullname))
501 GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, 505 GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
502 _ 506 _("File `%s' in directory `%s' does not match naming convention. Removed.\n"),
503 ("File `%s' in directory `%s' does not match naming convention. " 507 fullname,
504 "Removed.\n"), fullname, networkIdDirectory); 508 networkIdDirectory);
505 else 509 else
506 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 510 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
507 "unlink", fullname); 511 "unlink",
512 fullname);
508} 513}
509 514
510 515
511/** 516/**
512 * Closure for 'hosts_directory_scan_callback'. 517 * Closure for #hosts_directory_scan_callback().
513 */ 518 */
514struct DirScanContext 519struct DirScanContext
515{ 520{
@@ -538,7 +543,8 @@ struct DirScanContext
538 * @return #GNUNET_OK (continue iteration) 543 * @return #GNUNET_OK (continue iteration)
539 */ 544 */
540static int 545static int
541hosts_directory_scan_callback (void *cls, const char *fullname) 546hosts_directory_scan_callback (void *cls,
547 const char *fullname)
542{ 548{
543 struct DirScanContext *dsc = cls; 549 struct DirScanContext *dsc = cls;
544 struct GNUNET_PeerIdentity identity; 550 struct GNUNET_PeerIdentity identity;
@@ -590,9 +596,10 @@ hosts_directory_scan_callback (void *cls, const char *fullname)
590 remove_garbage (fullname); 596 remove_garbage (fullname);
591 return GNUNET_OK; 597 return GNUNET_OK;
592 } 598 }
593 if (GNUNET_OK == GNUNET_CRYPTO_eddsa_public_key_from_string (filename, 599 if (GNUNET_OK ==
594 strlen (filename), 600 GNUNET_CRYPTO_eddsa_public_key_from_string (filename,
595 &identity.public_key)) 601 strlen (filename),
602 &identity.public_key))
596 { 603 {
597 if (0 != memcmp (&id, &identity, sizeof (id_friend))) 604 if (0 != memcmp (&id, &identity, sizeof (id_friend)))
598 { 605 {
@@ -608,14 +615,16 @@ hosts_directory_scan_callback (void *cls, const char *fullname)
608 add_host_to_known_hosts (&id); 615 add_host_to_known_hosts (&id);
609 if (NULL != r.hello) 616 if (NULL != r.hello)
610 { 617 {
611 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating peer `%s' public HELLO \n", 618 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
619 "Updating peer `%s' public HELLO \n",
612 GNUNET_i2s (&id)); 620 GNUNET_i2s (&id));
613 update_hello (&id, r.hello); 621 update_hello (&id, r.hello);
614 GNUNET_free (r.hello); 622 GNUNET_free (r.hello);
615 } 623 }
616 if (NULL != r.friend_only_hello) 624 if (NULL != r.friend_only_hello)
617 { 625 {
618 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating peer `%s' friend only HELLO \n", 626 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
627 "Updating peer `%s' friend only HELLO \n",
619 GNUNET_i2s (&id)); 628 GNUNET_i2s (&id));
620 update_hello (&id, r.friend_only_hello); 629 update_hello (&id, r.friend_only_hello);
621 GNUNET_free (r.friend_only_hello); 630 GNUNET_free (r.friend_only_hello);
@@ -650,12 +659,14 @@ cron_scan_directory_data_hosts (void *cls,
650 dsc.matched = 0; 659 dsc.matched = 0;
651 dsc.remove_files = GNUNET_YES; 660 dsc.remove_files = GNUNET_YES;
652 GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, 661 GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK,
653 _("Scanning directory `%s'\n"), networkIdDirectory); 662 _("Scanning directory `%s'\n"),
663 networkIdDirectory);
654 GNUNET_DISK_directory_scan (networkIdDirectory, 664 GNUNET_DISK_directory_scan (networkIdDirectory,
655 &hosts_directory_scan_callback, &dsc); 665 &hosts_directory_scan_callback, &dsc);
656 if ((0 == dsc.matched) && (0 == (++retries & 31))) 666 if ((0 == dsc.matched) && (0 == (++retries & 31)))
657 GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, 667 GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
658 _("Still no peers found in `%s'!\n"), networkIdDirectory); 668 _("Still no peers found in `%s'!\n"),
669 networkIdDirectory);
659 GNUNET_SCHEDULER_add_delayed_with_priority (DATA_HOST_FREQ, 670 GNUNET_SCHEDULER_add_delayed_with_priority (DATA_HOST_FREQ,
660 GNUNET_SCHEDULER_PRIORITY_IDLE, 671 GNUNET_SCHEDULER_PRIORITY_IDLE,
661 &cron_scan_directory_data_hosts, 672 &cron_scan_directory_data_hosts,
@@ -663,6 +674,13 @@ cron_scan_directory_data_hosts (void *cls,
663} 674}
664 675
665 676
677/**
678 * Update the HELLO of a friend by merging the addresses.
679 *
680 * @param hello original hello
681 * @param friend_hello hello with additional addresses
682 * @return merged HELLO
683 */
666static struct GNUNET_HELLO_Message * 684static struct GNUNET_HELLO_Message *
667update_friend_hello (const struct GNUNET_HELLO_Message *hello, 685update_friend_hello (const struct GNUNET_HELLO_Message *hello,
668 const struct GNUNET_HELLO_Message *friend_hello) 686 const struct GNUNET_HELLO_Message *friend_hello)
@@ -719,9 +737,10 @@ update_hello (const struct GNUNET_PeerIdentity *peer,
719 GNUNET_assert (NULL != host); 737 GNUNET_assert (NULL != host);
720 738
721 friend_hello_type = GNUNET_HELLO_is_friend_only (hello); 739 friend_hello_type = GNUNET_HELLO_is_friend_only (hello);
722 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating %s HELLO for `%s'\n", 740 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
723 (GNUNET_YES == friend_hello_type) ? "friend-only" : "public", 741 "Updating %s HELLO for `%s'\n",
724 GNUNET_i2s (peer)); 742 (GNUNET_YES == friend_hello_type) ? "friend-only" : "public",
743 GNUNET_i2s (peer));
725 744
726 dest = NULL; 745 dest = NULL;
727 if (GNUNET_YES == friend_hello_type) 746 if (GNUNET_YES == friend_hello_type)
@@ -745,9 +764,10 @@ update_hello (const struct GNUNET_PeerIdentity *peer,
745 if (delta.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) 764 if (delta.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us)
746 { 765 {
747 /* no differences, just ignore the update */ 766 /* no differences, just ignore the update */
748 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No change in %s HELLO for `%s'\n", 767 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
749 (GNUNET_YES == friend_hello_type) ? "friend-only" : "public", 768 "No change in %s HELLO for `%s'\n",
750 GNUNET_i2s (peer)); 769 (GNUNET_YES == friend_hello_type) ? "friend-only" : "public",
770 GNUNET_i2s (peer));
751 GNUNET_free (mrg); 771 GNUNET_free (mrg);
752 return; 772 return;
753 } 773 }
@@ -755,7 +775,8 @@ update_hello (const struct GNUNET_PeerIdentity *peer,
755 (*dest) = mrg; 775 (*dest) = mrg;
756 } 776 }
757 777
758 if ((NULL != (host->hello)) && (GNUNET_NO == friend_hello_type)) 778 if ( (NULL != (host->hello)) &&
779 (GNUNET_NO == friend_hello_type) )
759 { 780 {
760 /* Update friend only hello */ 781 /* Update friend only hello */
761 mrg = update_friend_hello (host->hello, host->friend_only_hello); 782 mrg = update_friend_hello (host->hello, host->friend_only_hello);
@@ -765,20 +786,25 @@ update_hello (const struct GNUNET_PeerIdentity *peer,
765 } 786 }
766 787
767 if (NULL != host->hello) 788 if (NULL != host->hello)
768 GNUNET_assert ((GNUNET_NO == GNUNET_HELLO_is_friend_only (host->hello))); 789 GNUNET_assert ((GNUNET_NO ==
790 GNUNET_HELLO_is_friend_only (host->hello)));
769 if (NULL != host->friend_only_hello) 791 if (NULL != host->friend_only_hello)
770 GNUNET_assert ((GNUNET_YES == GNUNET_HELLO_is_friend_only(host->friend_only_hello))); 792 GNUNET_assert ((GNUNET_YES ==
793 GNUNET_HELLO_is_friend_only (host->friend_only_hello)));
771 794
772 fn = get_host_filename (peer); 795 fn = get_host_filename (peer);
773 if ( (NULL != fn) && 796 if ( (NULL != fn) &&
774 (GNUNET_OK == GNUNET_DISK_directory_create_for_file (fn)) ) 797 (GNUNET_OK ==
798 GNUNET_DISK_directory_create_for_file (fn)) )
775 { 799 {
776 store_hello = GNUNET_NO; 800 store_hello = GNUNET_NO;
777 size = 0; 801 size = 0;
778 cnt = 0; 802 cnt = 0;
779 if (NULL != host->hello) 803 if (NULL != host->hello)
780 (void) GNUNET_HELLO_iterate_addresses (host->hello, 804 (void) GNUNET_HELLO_iterate_addresses (host->hello,
781 GNUNET_NO, &count_addresses, &cnt); 805 GNUNET_NO,
806 &count_addresses,
807 &cnt);
782 if (cnt > 0) 808 if (cnt > 0)
783 { 809 {
784 store_hello = GNUNET_YES; 810 store_hello = GNUNET_YES;
@@ -786,8 +812,10 @@ update_hello (const struct GNUNET_PeerIdentity *peer,
786 } 812 }
787 cnt = 0; 813 cnt = 0;
788 if (NULL != host->friend_only_hello) 814 if (NULL != host->friend_only_hello)
789 (void) GNUNET_HELLO_iterate_addresses (host->friend_only_hello, GNUNET_NO, 815 (void) GNUNET_HELLO_iterate_addresses (host->friend_only_hello,
790 &count_addresses, &cnt); 816 GNUNET_NO,
817 &count_addresses,
818 &cnt);
791 store_friend_hello = GNUNET_NO; 819 store_friend_hello = GNUNET_NO;
792 if (0 < cnt) 820 if (0 < cnt)
793 { 821 {
@@ -795,7 +823,8 @@ update_hello (const struct GNUNET_PeerIdentity *peer,
795 size += GNUNET_HELLO_size (host->friend_only_hello); 823 size += GNUNET_HELLO_size (host->friend_only_hello);
796 } 824 }
797 825
798 if ((GNUNET_NO == store_hello) && (GNUNET_NO == store_friend_hello)) 826 if ( (GNUNET_NO == store_hello) &&
827 (GNUNET_NO == store_friend_hello) )
799 { 828 {
800 /* no valid addresses, don't put HELLO on disk; in fact, 829 /* no valid addresses, don't put HELLO on disk; in fact,
801 if one exists on disk, remove it */ 830 if one exists on disk, remove it */
@@ -808,7 +837,8 @@ update_hello (const struct GNUNET_PeerIdentity *peer,
808 837
809 if (GNUNET_YES == store_hello) 838 if (GNUNET_YES == store_hello)
810 { 839 {
811 memcpy (buffer, host->hello, GNUNET_HELLO_size (host->hello)); 840 memcpy (buffer, host->hello,
841 GNUNET_HELLO_size (host->hello));
812 pos += GNUNET_HELLO_size (host->hello); 842 pos += GNUNET_HELLO_size (host->hello);
813 } 843 }
814 if (GNUNET_YES == store_friend_hello) 844 if (GNUNET_YES == store_friend_hello)
@@ -825,7 +855,8 @@ update_hello (const struct GNUNET_PeerIdentity *peer,
825 GNUNET_DISK_PERM_OTHER_READ)) 855 GNUNET_DISK_PERM_OTHER_READ))
826 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn); 856 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn);
827 else 857 else
828 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stored %s %s HELLO in %s with total size %u\n", 858 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
859 "Stored %s %s HELLO in %s with total size %u\n",
829 (GNUNET_YES == store_friend_hello) ? "friend-only": "", 860 (GNUNET_YES == store_friend_hello) ? "friend-only": "",
830 (GNUNET_YES == store_hello) ? "public": "", 861 (GNUNET_YES == store_hello) ? "public": "",
831 fn, size); 862 fn, size);
@@ -846,7 +877,9 @@ update_hello (const struct GNUNET_PeerIdentity *peer,
846 * @return #GNUNET_YES (continue to iterate) 877 * @return #GNUNET_YES (continue to iterate)
847 */ 878 */
848static int 879static int
849add_to_tc (void *cls, const struct GNUNET_PeerIdentity *key, void *value) 880add_to_tc (void *cls,
881 const struct GNUNET_PeerIdentity *key,
882 void *value)
850{ 883{
851 struct TransmitContext *tc = cls; 884 struct TransmitContext *tc = cls;
852 struct HostEntry *pos = value; 885 struct HostEntry *pos = value;
@@ -857,7 +890,8 @@ add_to_tc (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
857 hs = 0; 890 hs = 0;
858 im = (struct InfoMessage *) buf; 891 im = (struct InfoMessage *) buf;
859 892
860 if ((pos->hello != NULL) && (GNUNET_NO == tc->friend_only)) 893 if ( (NULL != pos->hello) &&
894 (GNUNET_NO == tc->friend_only) )
861 { 895 {
862 /* Copy public HELLO */ 896 /* Copy public HELLO */
863 hs = GNUNET_HELLO_size (pos->hello); 897 hs = GNUNET_HELLO_size (pos->hello);
@@ -868,7 +902,8 @@ add_to_tc (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
868 "Sending public HELLO with size %u for peer `%4s'\n", 902 "Sending public HELLO with size %u for peer `%4s'\n",
869 hs, GNUNET_i2s (key)); 903 hs, GNUNET_i2s (key));
870 } 904 }
871 else if ((pos->friend_only_hello != NULL) && (GNUNET_YES == tc->friend_only)) 905 else if ( (NULL != pos->friend_only_hello) &&
906 (GNUNET_YES == tc->friend_only) )
872 { 907 {
873 /* Copy friend only HELLO */ 908 /* Copy friend only HELLO */
874 hs = GNUNET_HELLO_size (pos->friend_only_hello); 909 hs = GNUNET_HELLO_size (pos->friend_only_hello);
@@ -877,13 +912,14 @@ add_to_tc (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
877 memcpy (&im[1], pos->friend_only_hello, hs); 912 memcpy (&im[1], pos->friend_only_hello, hs);
878 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 913 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
879 "Sending friend-only HELLO with size %u for peer `%4s'\n", 914 "Sending friend-only HELLO with size %u for peer `%4s'\n",
880 hs, GNUNET_i2s (key)); 915 hs,
916 GNUNET_i2s (key));
881 } 917 }
882 else 918 else
883 { 919 {
884 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 920 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
885 "Adding no HELLO for peer `%s'\n", 921 "Adding no HELLO for peer `%s'\n",
886 GNUNET_i2s (key)); 922 GNUNET_i2s (key));
887 } 923 }
888 924
889 im->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_INFO); 925 im->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_INFO);
@@ -898,12 +934,13 @@ add_to_tc (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
898/** 934/**
899 * @brief delete expired HELLO entries in directory 935 * @brief delete expired HELLO entries in directory
900 * 936 *
901 * @param cls pointer to current time (struct GNUNET_TIME_Absolute) 937 * @param cls pointer to current time (`struct GNUNET_TIME_Absolute *`)
902 * @param fn filename to test to see if the HELLO expired 938 * @param fn filename to test to see if the HELLO expired
903 * @return #GNUNET_OK (continue iteration) 939 * @return #GNUNET_OK (continue iteration)
904 */ 940 */
905static int 941static int
906discard_hosts_helper (void *cls, const char *fn) 942discard_hosts_helper (void *cls,
943 const char *fn)
907{ 944{
908 struct GNUNET_TIME_Absolute *now = cls; 945 struct GNUNET_TIME_Absolute *now = cls;
909 char buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1] GNUNET_ALIGN; 946 char buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1] GNUNET_ALIGN;
@@ -917,7 +954,6 @@ discard_hosts_helper (void *cls, const char *fn)
917 unsigned int cnt; 954 unsigned int cnt;
918 char *writebuffer; 955 char *writebuffer;
919 956
920
921 read_size = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer)); 957 read_size = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer));
922 if (read_size < sizeof (struct GNUNET_MessageHeader)) 958 if (read_size < sizeof (struct GNUNET_MessageHeader))
923 { 959 {
@@ -940,13 +976,18 @@ discard_hosts_helper (void *cls, const char *fn)
940 /* Invalid data, discard */ 976 /* Invalid data, discard */
941 if (0 != UNLINK (fn)) 977 if (0 != UNLINK (fn))
942 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | 978 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
943 GNUNET_ERROR_TYPE_BULK, "unlink", fn); 979 GNUNET_ERROR_TYPE_BULK,
980 "unlink", fn);
944 return GNUNET_OK; 981 return GNUNET_OK;
945 } 982 }
946 new_hello = GNUNET_HELLO_iterate_addresses (hello, GNUNET_YES, &discard_expired, now); 983 new_hello = GNUNET_HELLO_iterate_addresses (hello,
984 GNUNET_YES,
985 &discard_expired, now);
947 cnt = 0; 986 cnt = 0;
948 if (NULL != new_hello) 987 if (NULL != new_hello)
949 (void) GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &count_addresses, &cnt); 988 (void) GNUNET_HELLO_iterate_addresses (hello,
989 GNUNET_NO,
990 &count_addresses, &cnt);
950 if ( (NULL != new_hello) && (0 < cnt) ) 991 if ( (NULL != new_hello) && (0 < cnt) )
951 { 992 {
952 /* Store new HELLO to write it when done */ 993 /* Store new HELLO to write it when done */
@@ -968,7 +1009,8 @@ discard_hosts_helper (void *cls, const char *fn)
968 } 1009 }
969 else if (0 != UNLINK (fn)) 1010 else if (0 != UNLINK (fn))
970 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | 1011 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
971 GNUNET_ERROR_TYPE_BULK, "unlink", fn); 1012 GNUNET_ERROR_TYPE_BULK,
1013 "unlink", fn);
972 1014
973 GNUNET_free (writebuffer); 1015 GNUNET_free (writebuffer);
974 return GNUNET_OK; 1016 return GNUNET_OK;
@@ -983,7 +1025,8 @@ discard_hosts_helper (void *cls, const char *fn)
983 * @param tc scheduler context, aborted if reason is shutdown 1025 * @param tc scheduler context, aborted if reason is shutdown
984 */ 1026 */
985static void 1027static void
986cron_clean_data_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 1028cron_clean_data_hosts (void *cls,
1029 const struct GNUNET_SCHEDULER_TaskContext *tc)
987{ 1030{
988 struct GNUNET_TIME_Absolute now; 1031 struct GNUNET_TIME_Absolute now;
989 1032
@@ -991,9 +1034,13 @@ cron_clean_data_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
991 return; 1034 return;
992 now = GNUNET_TIME_absolute_get (); 1035 now = GNUNET_TIME_absolute_get ();
993 GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, 1036 GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK,
994 _("Cleaning up directory `%s'\n"), networkIdDirectory); 1037 _("Cleaning up directory `%s'\n"),
995 GNUNET_DISK_directory_scan (networkIdDirectory, &discard_hosts_helper, &now); 1038 networkIdDirectory);
996 GNUNET_SCHEDULER_add_delayed (DATA_HOST_CLEAN_FREQ, &cron_clean_data_hosts, 1039 GNUNET_DISK_directory_scan (networkIdDirectory,
1040 &discard_hosts_helper,
1041 &now);
1042 GNUNET_SCHEDULER_add_delayed (DATA_HOST_CLEAN_FREQ,
1043 &cron_clean_data_hosts,
997 NULL); 1044 NULL);
998} 1045}
999 1046
@@ -1006,7 +1053,8 @@ cron_clean_data_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1006 * @param message the actual message 1053 * @param message the actual message
1007 */ 1054 */
1008static void 1055static void
1009handle_hello (void *cls, struct GNUNET_SERVER_Client *client, 1056handle_hello (void *cls,
1057 struct GNUNET_SERVER_Client *client,
1010 const struct GNUNET_MessageHeader *message) 1058 const struct GNUNET_MessageHeader *message)
1011{ 1059{
1012 const struct GNUNET_HELLO_Message *hello; 1060 const struct GNUNET_HELLO_Message *hello;
@@ -1019,8 +1067,10 @@ handle_hello (void *cls, struct GNUNET_SERVER_Client *client,
1019 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1067 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1020 return; 1068 return;
1021 } 1069 }
1022 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received for peer `%4s'\n", 1070 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1023 "HELLO", GNUNET_i2s (&pid)); 1071 "`%s' message received for peer `%4s'\n",
1072 "HELLO",
1073 GNUNET_i2s (&pid));
1024 add_host_to_known_hosts (&pid); 1074 add_host_to_known_hosts (&pid);
1025 update_hello (&pid, hello); 1075 update_hello (&pid, hello);
1026 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1076 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -1035,15 +1085,18 @@ handle_hello (void *cls, struct GNUNET_SERVER_Client *client,
1035 * @param message the actual message 1085 * @param message the actual message
1036 */ 1086 */
1037static void 1087static void
1038handle_get (void *cls, struct GNUNET_SERVER_Client *client, 1088handle_get (void *cls,
1089 struct GNUNET_SERVER_Client *client,
1039 const struct GNUNET_MessageHeader *message) 1090 const struct GNUNET_MessageHeader *message)
1040{ 1091{
1041 const struct ListPeerMessage *lpm; 1092 const struct ListPeerMessage *lpm;
1042 struct TransmitContext tcx; 1093 struct TransmitContext tcx;
1043 1094
1044 lpm = (const struct ListPeerMessage *) message; 1095 lpm = (const struct ListPeerMessage *) message;
1045 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received for peer `%4s'\n", 1096 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1046 "GET", GNUNET_i2s (&lpm->peer)); 1097 "`%s' message received for peer `%4s'\n",
1098 "GET",
1099 GNUNET_i2s (&lpm->peer));
1047 tcx.friend_only = ntohl (lpm->include_friend_only); 1100 tcx.friend_only = ntohl (lpm->include_friend_only);
1048 tcx.tc = GNUNET_SERVER_transmit_context_create (client); 1101 tcx.tc = GNUNET_SERVER_transmit_context_create (client);
1049 GNUNET_CONTAINER_multipeermap_get_multiple (hostmap, &lpm->peer, 1102 GNUNET_CONTAINER_multipeermap_get_multiple (hostmap, &lpm->peer,
@@ -1070,10 +1123,14 @@ handle_get_all (void *cls, struct GNUNET_SERVER_Client *client,
1070 1123
1071 lapm = (const struct ListAllPeersMessage *) message; 1124 lapm = (const struct ListAllPeersMessage *) message;
1072 tcx.friend_only = ntohl (lapm->include_friend_only); 1125 tcx.friend_only = ntohl (lapm->include_friend_only);
1073 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received\n", "GET_ALL"); 1126 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1127 "`%s' message received\n",
1128 "GET_ALL");
1074 GNUNET_SERVER_disable_receive_done_warning (client); 1129 GNUNET_SERVER_disable_receive_done_warning (client);
1075 tcx.tc = GNUNET_SERVER_transmit_context_create (client); 1130 tcx.tc = GNUNET_SERVER_transmit_context_create (client);
1076 GNUNET_CONTAINER_multipeermap_iterate (hostmap, &add_to_tc, &tcx); 1131 GNUNET_CONTAINER_multipeermap_iterate (hostmap,
1132 &add_to_tc,
1133 &tcx);
1077 GNUNET_SERVER_transmit_context_append_data (tcx.tc, NULL, 0, 1134 GNUNET_SERVER_transmit_context_append_data (tcx.tc, NULL, 0,
1078 GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); 1135 GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END);
1079 GNUNET_SERVER_transmit_context_run (tcx.tc, GNUNET_TIME_UNIT_FOREVER_REL); 1136 GNUNET_SERVER_transmit_context_run (tcx.tc, GNUNET_TIME_UNIT_FOREVER_REL);
@@ -1091,13 +1148,16 @@ handle_get_all (void *cls, struct GNUNET_SERVER_Client *client,
1091 * @return #GNUNET_YES (always, continue to iterate) 1148 * @return #GNUNET_YES (always, continue to iterate)
1092 */ 1149 */
1093static int 1150static int
1094do_notify_entry (void *cls, const struct GNUNET_PeerIdentity *key, void *value) 1151do_notify_entry (void *cls,
1152 const struct GNUNET_PeerIdentity *key,
1153 void *value)
1095{ 1154{
1096 struct NotificationContext *nc = cls; 1155 struct NotificationContext *nc = cls;
1097 struct HostEntry *he = value; 1156 struct HostEntry *he = value;
1098 struct InfoMessage *msg; 1157 struct InfoMessage *msg;
1099 1158
1100 if ((NULL == he->hello) && (GNUNET_NO == nc->include_friend_only)) 1159 if ( (NULL == he->hello) &&
1160 (GNUNET_NO == nc->include_friend_only) )
1101 { 1161 {
1102 /* We have no public hello */ 1162 /* We have no public hello */
1103 return GNUNET_YES; 1163 return GNUNET_YES;
@@ -1128,7 +1188,8 @@ do_notify_entry (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
1128 * @param message the actual message 1188 * @param message the actual message
1129 */ 1189 */
1130static void 1190static void
1131handle_notify (void *cls, struct GNUNET_SERVER_Client *client, 1191handle_notify (void *cls,
1192 struct GNUNET_SERVER_Client *client,
1132 const struct GNUNET_MessageHeader *message) 1193 const struct GNUNET_MessageHeader *message)
1133{ 1194{
1134 struct NotifyMessage *nm = (struct NotifyMessage *) message; 1195 struct NotifyMessage *nm = (struct NotifyMessage *) message;
@@ -1156,7 +1217,8 @@ handle_notify (void *cls, struct GNUNET_SERVER_Client *client,
1156 * @param client server client 1217 * @param client server client
1157 */ 1218 */
1158static void 1219static void
1159disconnect_cb (void *cls,struct GNUNET_SERVER_Client *client) 1220disconnect_cb (void *cls,
1221 struct GNUNET_SERVER_Client *client)
1160{ 1222{
1161 struct NotificationContext *cur; 1223 struct NotificationContext *cur;
1162 1224
@@ -1214,7 +1276,9 @@ shutdown_task (void *cls,
1214 GNUNET_CONTAINER_DLL_remove (nc_head, nc_tail, cur); 1276 GNUNET_CONTAINER_DLL_remove (nc_head, nc_tail, cur);
1215 GNUNET_free (cur); 1277 GNUNET_free (cur);
1216 } 1278 }
1217 GNUNET_CONTAINER_multipeermap_iterate (hostmap, &free_host_entry, NULL); 1279 GNUNET_CONTAINER_multipeermap_iterate (hostmap,
1280 &free_host_entry,
1281 NULL);
1218 GNUNET_CONTAINER_multipeermap_destroy (hostmap); 1282 GNUNET_CONTAINER_multipeermap_destroy (hostmap);
1219 if (NULL != stats) 1283 if (NULL != stats)
1220 { 1284 {
@@ -1232,7 +1296,8 @@ shutdown_task (void *cls,
1232 * @param cfg configuration to use 1296 * @param cfg configuration to use
1233 */ 1297 */
1234static void 1298static void
1235run (void *cls, struct GNUNET_SERVER_Handle *server, 1299run (void *cls,
1300 struct GNUNET_SERVER_Handle *server,
1236 const struct GNUNET_CONFIGURATION_Handle *cfg) 1301 const struct GNUNET_CONFIGURATION_Handle *cfg)
1237{ 1302{
1238 static const struct GNUNET_SERVER_MessageHandler handlers[] = { 1303 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
@@ -1255,10 +1320,13 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1255 stats = GNUNET_STATISTICS_create ("peerinfo", cfg); 1320 stats = GNUNET_STATISTICS_create ("peerinfo", cfg);
1256 notify_list = GNUNET_SERVER_notification_context_create (server, 0); 1321 notify_list = GNUNET_SERVER_notification_context_create (server, 0);
1257 noio = GNUNET_CONFIGURATION_get_value_yesno (cfg, "peerinfo", "NO_IO"); 1322 noio = GNUNET_CONFIGURATION_get_value_yesno (cfg, "peerinfo", "NO_IO");
1258 use_included = GNUNET_CONFIGURATION_get_value_yesno (cfg, "peerinfo", "USE_INCLUDED_HELLOS"); 1323 use_included = GNUNET_CONFIGURATION_get_value_yesno (cfg,
1324 "peerinfo",
1325 "USE_INCLUDED_HELLOS");
1259 if (GNUNET_SYSERR == use_included) 1326 if (GNUNET_SYSERR == use_included)
1260 use_included = GNUNET_NO; 1327 use_included = GNUNET_NO;
1261 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, 1328 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
1329 &shutdown_task,
1262 NULL); 1330 NULL);
1263 if (GNUNET_YES != noio) 1331 if (GNUNET_YES != noio)
1264 { 1332 {
@@ -1281,25 +1349,32 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1281 if (GNUNET_YES == use_included) 1349 if (GNUNET_YES == use_included)
1282 { 1350 {
1283 ip = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR); 1351 ip = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
1284 GNUNET_asprintf (&peerdir, "%shellos", ip); 1352 GNUNET_asprintf (&peerdir,
1353 "%shellos",
1354 ip);
1285 GNUNET_free(ip); 1355 GNUNET_free(ip);
1286 1356
1287 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Importing HELLOs from `%s'\n"), 1357 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1288 peerdir); 1358 _("Importing HELLOs from `%s'\n"),
1359 peerdir);
1289 dsc.matched = 0; 1360 dsc.matched = 0;
1290 dsc.remove_files = GNUNET_NO; 1361 dsc.remove_files = GNUNET_NO;
1291 1362
1292 GNUNET_DISK_directory_scan (peerdir, &hosts_directory_scan_callback, 1363 GNUNET_DISK_directory_scan (peerdir,
1293 &dsc); 1364 &hosts_directory_scan_callback,
1365 &dsc);
1294 GNUNET_free (peerdir); 1366 GNUNET_free (peerdir);
1295 } 1367 }
1296 else 1368 else
1297 { 1369 {
1298 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Skipping import of included HELLOs\n")); 1370 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1371 _("Skipping import of included HELLOs\n"));
1299 } 1372 }
1300 } 1373 }
1301 GNUNET_SERVER_add_handlers (server, handlers); 1374 GNUNET_SERVER_add_handlers (server, handlers);
1302 GNUNET_SERVER_disconnect_notify (server, &disconnect_cb, NULL) ; 1375 GNUNET_SERVER_disconnect_notify (server,
1376 &disconnect_cb,
1377 NULL);
1303} 1378}
1304 1379
1305 1380
@@ -1311,13 +1386,16 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1311 * @return 0 ok, 1 on error 1386 * @return 0 ok, 1 on error
1312 */ 1387 */
1313int 1388int
1314main (int argc, char *const *argv) 1389main (int argc,
1390 char *const *argv)
1315{ 1391{
1316 int ret; 1392 int ret;
1317 1393
1318 ret = 1394 ret =
1319 (GNUNET_OK == 1395 (GNUNET_OK ==
1320 GNUNET_SERVICE_run (argc, argv, "peerinfo", GNUNET_SERVICE_OPTION_NONE, 1396 GNUNET_SERVICE_run (argc, argv,
1397 "peerinfo",
1398 GNUNET_SERVICE_OPTION_NONE,
1321 &run, NULL)) ? 0 : 1; 1399 &run, NULL)) ? 0 : 1;
1322 GNUNET_free_non_null (networkIdDirectory); 1400 GNUNET_free_non_null (networkIdDirectory);
1323 return ret; 1401 return ret;
diff --git a/src/peerinfo/peerinfo_api.c b/src/peerinfo/peerinfo_api.c
index 716802389..20042f8e3 100644
--- a/src/peerinfo/peerinfo_api.c
+++ b/src/peerinfo/peerinfo_api.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2001, 2002, 2004, 2005, 2007, 2009, 2010, 2012 Christian Grothoff (and other contributing authors) 3 (C) 2001-2014 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -98,7 +98,7 @@ struct GNUNET_PEERINFO_IteratorContext
98 GNUNET_PEERINFO_Processor callback; 98 GNUNET_PEERINFO_Processor callback;
99 99
100 /** 100 /**
101 * Closure for 'callback'. 101 * Closure for @e callback.
102 */ 102 */
103 void *callback_cls; 103 void *callback_cls;
104 104
@@ -123,12 +123,12 @@ struct GNUNET_PEERINFO_IteratorContext
123 struct GNUNET_PeerIdentity peer; 123 struct GNUNET_PeerIdentity peer;
124 124
125 /** 125 /**
126 * Is 'peer' set? 126 * Is @e peer set?
127 */ 127 */
128 int have_peer; 128 int have_peer;
129 129
130 /** 130 /**
131 * Set to GNUNET_YES if we are currently receiving replies from the 131 * Set to #GNUNET_YES if we are currently receiving replies from the
132 * service. 132 * service.
133 */ 133 */
134 int request_transmitted; 134 int request_transmitted;
@@ -212,7 +212,7 @@ GNUNET_PEERINFO_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
212 * Disconnect from the peerinfo service. Note that all iterators must 212 * Disconnect from the peerinfo service. Note that all iterators must
213 * have completed or have been cancelled by the time this function is 213 * have completed or have been cancelled by the time this function is
214 * called (otherwise, calling this function is a serious error). 214 * called (otherwise, calling this function is a serious error).
215 * Furthermore, if 'GNUNET_PEERINFO_add_peer' operations are still 215 * Furthermore, if #GNUNET_PEERINFO_add_peer() operations are still
216 * pending, they will be cancelled silently on disconnect. 216 * pending, they will be cancelled silently on disconnect.
217 * 217 *
218 * @param h handle to disconnect 218 * @param h handle to disconnect
@@ -233,7 +233,8 @@ GNUNET_PEERINFO_disconnect (struct GNUNET_PEERINFO_Handle *h)
233 { 233 {
234 GNUNET_CONTAINER_DLL_remove (h->ac_head, h->ac_tail, ac); 234 GNUNET_CONTAINER_DLL_remove (h->ac_head, h->ac_tail, ac);
235 if (NULL != ac->cont) 235 if (NULL != ac->cont)
236 ac->cont (ac->cont_cls, _("aborted due to explicit disconnect request")); 236 ac->cont (ac->cont_cls,
237 _("aborted due to explicit disconnect request"));
237 GNUNET_free (ac); 238 GNUNET_free (ac);
238 } 239 }
239 if (NULL != h->th) 240 if (NULL != h->th)
@@ -277,11 +278,12 @@ reconnect (struct GNUNET_PEERINFO_Handle *h);
277/** 278/**
278 * Task scheduled to re-try connecting to the peerinfo service. 279 * Task scheduled to re-try connecting to the peerinfo service.
279 * 280 *
280 * @param cls the 'struct GNUNET_PEERINFO_Handle' 281 * @param cls the `struct GNUNET_PEERINFO_Handle *`
281 * @param tc scheduler context 282 * @param tc scheduler context
282 */ 283 */
283static void 284static void
284reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 285reconnect_task (void *cls,
286 const struct GNUNET_SCHEDULER_TaskContext *tc)
285{ 287{
286 struct GNUNET_PEERINFO_Handle *h = cls; 288 struct GNUNET_PEERINFO_Handle *h = cls;
287 289
@@ -318,7 +320,8 @@ reconnect (struct GNUNET_PEERINFO_Handle *h)
318 if (NULL == h->client) 320 if (NULL == h->client)
319 { 321 {
320 h->r_task = 322 h->r_task =
321 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &reconnect_task, 323 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
324 &reconnect_task,
322 h); 325 h);
323 return; 326 return;
324 } 327 }
@@ -330,13 +333,15 @@ reconnect (struct GNUNET_PEERINFO_Handle *h)
330 * Transmit the request at the head of the transmission queue 333 * Transmit the request at the head of the transmission queue
331 * and trigger continuation (if any). 334 * and trigger continuation (if any).
332 * 335 *
333 * @param cls the 'struct GNUNET_PEERINFO_Handle' (with the queue) 336 * @param cls the `struct GNUNET_PEERINFO_Handle *` (with the queue)
334 * @param size size of the buffer (0 on error) 337 * @param size size of @a buf (0 on error)
335 * @param buf where to copy the message 338 * @param buf where to copy the message
336 * @return number of bytes copied to buf 339 * @return number of bytes copied to @a buf
337 */ 340 */
338static size_t 341static size_t
339do_transmit (void *cls, size_t size, void *buf) 342do_transmit (void *cls,
343 size_t size,
344 void *buf)
340{ 345{
341 struct GNUNET_PEERINFO_Handle *h = cls; 346 struct GNUNET_PEERINFO_Handle *h = cls;
342 struct GNUNET_PEERINFO_AddContext *ac = h->ac_head; 347 struct GNUNET_PEERINFO_AddContext *ac = h->ac_head;
@@ -349,11 +354,13 @@ do_transmit (void *cls, size_t size, void *buf)
349 { 354 {
350 /* peerinfo service died */ 355 /* peerinfo service died */
351 LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 356 LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
352 "Failed to transmit message to `%s' service.\n", "PEERINFO"); 357 "Failed to transmit message to `%s' service.\n",
358 "PEERINFO");
353 GNUNET_CONTAINER_DLL_remove (h->ac_head, h->ac_tail, ac); 359 GNUNET_CONTAINER_DLL_remove (h->ac_head, h->ac_tail, ac);
354 reconnect (h); 360 reconnect (h);
355 if (NULL != ac->cont) 361 if (NULL != ac->cont)
356 ac->cont (ac->cont_cls, _("failed to transmit request (service down?)")); 362 ac->cont (ac->cont_cls,
363 _("failed to transmit request (service down?)"));
357 GNUNET_free (ac); 364 GNUNET_free (ac);
358 return 0; 365 return 0;
359 } 366 }
@@ -365,7 +372,9 @@ do_transmit (void *cls, size_t size, void *buf)
365 return 0; 372 return 0;
366 } 373 }
367 LOG (GNUNET_ERROR_TYPE_DEBUG, 374 LOG (GNUNET_ERROR_TYPE_DEBUG,
368 "Transmitting request of size %u to `%s' service.\n", ret, "PEERINFO"); 375 "Transmitting request of size %u to `%s' service.\n",
376 ret,
377 "PEERINFO");
369 memcpy (buf, &ac[1], ret); 378 memcpy (buf, &ac[1], ret);
370 GNUNET_CONTAINER_DLL_remove (h->ac_head, h->ac_tail, ac); 379 GNUNET_CONTAINER_DLL_remove (h->ac_head, h->ac_tail, ac);
371 trigger_transmit (h); 380 trigger_transmit (h);
@@ -398,7 +407,8 @@ trigger_transmit (struct GNUNET_PEERINFO_Handle *h)
398 return; 407 return;
399 } 408 }
400 h->th = 409 h->th =
401 GNUNET_CLIENT_notify_transmit_ready (h->client, ac->size, 410 GNUNET_CLIENT_notify_transmit_ready (h->client,
411 ac->size,
402 GNUNET_TIME_UNIT_FOREVER_REL, 412 GNUNET_TIME_UNIT_FOREVER_REL,
403 GNUNET_YES, 413 GNUNET_YES,
404 &do_transmit, h); 414 &do_transmit, h);
@@ -408,7 +418,7 @@ trigger_transmit (struct GNUNET_PEERINFO_Handle *h)
408/** 418/**
409 * Add a host to the persistent list. This method operates in 419 * Add a host to the persistent list. This method operates in
410 * semi-reliable mode: if the transmission is not completed by 420 * semi-reliable mode: if the transmission is not completed by
411 * the time 'GNUNET_PEERINFO_disconnect' is called, it will be 421 * the time #GNUNET_PEERINFO_disconnect() is called, it will be
412 * aborted. Furthermore, if a second HELLO is added for the 422 * aborted. Furthermore, if a second HELLO is added for the
413 * same peer before the first one was transmitted, PEERINFO may 423 * same peer before the first one was transmitted, PEERINFO may
414 * merge the two HELLOs prior to transmission to the service. 424 * merge the two HELLOs prior to transmission to the service.
@@ -416,7 +426,7 @@ trigger_transmit (struct GNUNET_PEERINFO_Handle *h)
416 * @param h handle to the peerinfo service 426 * @param h handle to the peerinfo service
417 * @param hello the verified (!) HELLO message 427 * @param hello the verified (!) HELLO message
418 * @param cont continuation to call when done, NULL is allowed 428 * @param cont continuation to call when done, NULL is allowed
419 * @param cont_cls closure for 'cont' 429 * @param cont_cls closure for @a cont
420 * @return handle to cancel add operation; all pending 430 * @return handle to cancel add operation; all pending
421 * 'add' operations will be cancelled automatically 431 * 'add' operations will be cancelled automatically
422 * on disconnect, so it is not necessary to keep this 432 * on disconnect, so it is not necessary to keep this
@@ -436,7 +446,9 @@ GNUNET_PEERINFO_add_peer (struct GNUNET_PEERINFO_Handle *h,
436 GNUNET_assert (GNUNET_OK == GNUNET_HELLO_get_id (hello, &peer)); 446 GNUNET_assert (GNUNET_OK == GNUNET_HELLO_get_id (hello, &peer));
437 LOG (GNUNET_ERROR_TYPE_DEBUG, 447 LOG (GNUNET_ERROR_TYPE_DEBUG,
438 "Adding peer `%s' to PEERINFO database (%u bytes of `%s')\n", 448 "Adding peer `%s' to PEERINFO database (%u bytes of `%s')\n",
439 GNUNET_i2s (&peer), hs, "HELLO"); 449 GNUNET_i2s (&peer),
450 hs,
451 "HELLO");
440 ac = GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_AddContext) + hs); 452 ac = GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_AddContext) + hs);
441 ac->h = h; 453 ac->h = h;
442 ac->size = hs; 454 ac->size = hs;
@@ -451,7 +463,7 @@ GNUNET_PEERINFO_add_peer (struct GNUNET_PEERINFO_Handle *h,
451 463
452/** 464/**
453 * Cancel pending 'add' operation. Must only be called before 465 * Cancel pending 'add' operation. Must only be called before
454 * either 'cont' or 'GNUNET_PEERINFO_disconnect' are invoked. 466 * either 'cont' or #GNUNET_PEERINFO_disconnect() are invoked.
455 * 467 *
456 * @param ac handle for the add operation to cancel 468 * @param ac handle for the add operation to cancel
457 */ 469 */
@@ -475,7 +487,8 @@ GNUNET_PEERINFO_add_peer_cancel (struct GNUNET_PEERINFO_AddContext *ac)
475 * @param msg message received, NULL on timeout or fatal error 487 * @param msg message received, NULL on timeout or fatal error
476 */ 488 */
477static void 489static void
478peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg) 490peerinfo_handler (void *cls,
491 const struct GNUNET_MessageHeader *msg)
479{ 492{
480 struct GNUNET_PEERINFO_Handle *h = cls; 493 struct GNUNET_PEERINFO_Handle *h = cls;
481 struct GNUNET_PEERINFO_IteratorContext *ic = h->ic_head; 494 struct GNUNET_PEERINFO_IteratorContext *ic = h->ic_head;
@@ -519,14 +532,17 @@ peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg)
519 { 532 {
520 /* normal end of list of peers, signal end, process next pending request */ 533 /* normal end of list of peers, signal end, process next pending request */
521 LOG (GNUNET_ERROR_TYPE_DEBUG, 534 LOG (GNUNET_ERROR_TYPE_DEBUG,
522 "Received end of list of peers from `%s' service\n", "PEERINFO"); 535 "Received end of list of peers from `%s' service\n",
536 "PEERINFO");
523 GNUNET_PEERINFO_iterate_cancel (ic); 537 GNUNET_PEERINFO_iterate_cancel (ic);
524 trigger_transmit (h); 538 trigger_transmit (h);
525 if ( (GNUNET_NO == h->in_receive) && 539 if ( (GNUNET_NO == h->in_receive) &&
526 (NULL != h->ic_head) ) 540 (NULL != h->ic_head) )
527 { 541 {
528 h->in_receive = GNUNET_YES; 542 h->in_receive = GNUNET_YES;
529 GNUNET_CLIENT_receive (h->client, &peerinfo_handler, h, 543 GNUNET_CLIENT_receive (h->client,
544 &peerinfo_handler,
545 h,
530 GNUNET_TIME_absolute_get_remaining (h->ic_head->timeout)); 546 GNUNET_TIME_absolute_get_remaining (h->ic_head->timeout));
531 } 547 }
532 if (NULL != cb) 548 if (NULL != cb)
@@ -550,7 +566,9 @@ peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg)
550 im = (const struct InfoMessage *) msg; 566 im = (const struct InfoMessage *) msg;
551 GNUNET_break (0 == ntohl (im->reserved)); 567 GNUNET_break (0 == ntohl (im->reserved));
552 if ( (GNUNET_YES == ic->have_peer) && 568 if ( (GNUNET_YES == ic->have_peer) &&
553 (0 != memcmp (&ic->peer, &im->peer, sizeof (struct GNUNET_PeerIdentity))) ) 569 (0 != memcmp (&ic->peer,
570 &im->peer,
571 sizeof (struct GNUNET_PeerIdentity))) )
554 { 572 {
555 /* bogus message (from a different iteration call?); out of sequence! */ 573 /* bogus message (from a different iteration call?); out of sequence! */
556 LOG (GNUNET_ERROR_TYPE_ERROR, 574 LOG (GNUNET_ERROR_TYPE_ERROR,
@@ -562,7 +580,9 @@ peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg)
562 GNUNET_PEERINFO_iterate_cancel (ic); 580 GNUNET_PEERINFO_iterate_cancel (ic);
563 reconnect (h); 581 reconnect (h);
564 if (NULL != cb) 582 if (NULL != cb)
565 cb (cb_cls, NULL, NULL, 583 cb (cb_cls,
584 NULL,
585 NULL,
566 _("Received invalid message from `PEERINFO' service.")); 586 _("Received invalid message from `PEERINFO' service."));
567 return; 587 return;
568 } 588 }
@@ -577,7 +597,9 @@ peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg)
577 GNUNET_PEERINFO_iterate_cancel (ic); 597 GNUNET_PEERINFO_iterate_cancel (ic);
578 reconnect (h); 598 reconnect (h);
579 if (NULL != cb) 599 if (NULL != cb)
580 cb (cb_cls, NULL, NULL, 600 cb (cb_cls,
601 NULL,
602 NULL,
581 _("Received invalid message from `PEERINFO' service.")); 603 _("Received invalid message from `PEERINFO' service."));
582 return; 604 return;
583 } 605 }
@@ -588,18 +610,24 @@ peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg)
588 GNUNET_PEERINFO_iterate_cancel (ic); 610 GNUNET_PEERINFO_iterate_cancel (ic);
589 reconnect (h); 611 reconnect (h);
590 if (NULL != cb) 612 if (NULL != cb)
591 cb (cb_cls, NULL, NULL, 613 cb (cb_cls,
614 NULL,
615 NULL,
592 _("Received invalid message from `PEERINFO' service.")); 616 _("Received invalid message from `PEERINFO' service."));
593 return; 617 return;
594 } 618 }
595 if (0 != memcmp (&im->peer, &id, sizeof (struct GNUNET_PeerIdentity))) 619 if (0 != memcmp (&im->peer,
620 &id,
621 sizeof (struct GNUNET_PeerIdentity)))
596 { 622 {
597 /* malformed message */ 623 /* malformed message */
598 GNUNET_break (0); 624 GNUNET_break (0);
599 GNUNET_PEERINFO_iterate_cancel (ic); 625 GNUNET_PEERINFO_iterate_cancel (ic);
600 reconnect (h); 626 reconnect (h);
601 if (NULL != cb) 627 if (NULL != cb)
602 cb (cb_cls, NULL, NULL, 628 cb (cb_cls,
629 NULL,
630 NULL,
603 _("Received invalid message from `PEERINFO' service.")); 631 _("Received invalid message from `PEERINFO' service."));
604 return; 632 return;
605 } 633 }
@@ -608,13 +636,20 @@ peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg)
608 /* normal data message */ 636 /* normal data message */
609 LOG (GNUNET_ERROR_TYPE_DEBUG, 637 LOG (GNUNET_ERROR_TYPE_DEBUG,
610 "Received %u bytes of `%s' information about peer `%s' from `%s' service\n", 638 "Received %u bytes of `%s' information about peer `%s' from `%s' service\n",
611 (hello == NULL) ? 0 : (unsigned int) GNUNET_HELLO_size (hello), "HELLO", 639 (hello == NULL) ? 0 : (unsigned int) GNUNET_HELLO_size (hello),
612 GNUNET_i2s (&im->peer), "PEERINFO"); 640 "HELLO",
641 GNUNET_i2s (&im->peer),
642 "PEERINFO");
613 h->in_receive = GNUNET_YES; 643 h->in_receive = GNUNET_YES;
614 GNUNET_CLIENT_receive (h->client, &peerinfo_handler, h, 644 GNUNET_CLIENT_receive (h->client,
645 &peerinfo_handler,
646 h,
615 GNUNET_TIME_absolute_get_remaining (ic->timeout)); 647 GNUNET_TIME_absolute_get_remaining (ic->timeout));
616 if (NULL != cb) 648 if (NULL != cb)
617 cb (cb_cls, &im->peer, hello, NULL); 649 cb (cb_cls,
650 &im->peer,
651 hello,
652 NULL);
618} 653}
619 654
620 655
@@ -622,11 +657,12 @@ peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg)
622 * We've transmitted the iteration request. Now get ready to process 657 * We've transmitted the iteration request. Now get ready to process
623 * the results (or handle transmission error). 658 * the results (or handle transmission error).
624 * 659 *
625 * @param cls the 'struct GNUNET_PEERINFO_IteratorContext' 660 * @param cls the `struct GNUNET_PEERINFO_IteratorContext *`
626 * @param emsg error message, NULL if transmission worked 661 * @param emsg error message, NULL if transmission worked
627 */ 662 */
628static void 663static void
629iterator_start_receive (void *cls, const char *emsg) 664iterator_start_receive (void *cls,
665 const char *emsg)
630{ 666{
631 struct GNUNET_PEERINFO_IteratorContext *ic = cls; 667 struct GNUNET_PEERINFO_IteratorContext *ic = cls;
632 struct GNUNET_PEERINFO_Handle *h = ic->h; 668 struct GNUNET_PEERINFO_Handle *h = ic->h;
@@ -644,13 +680,16 @@ iterator_start_receive (void *cls, const char *emsg)
644 cb (cb_cls, NULL, NULL, emsg); 680 cb (cb_cls, NULL, NULL, emsg);
645 return; 681 return;
646 } 682 }
647 LOG (GNUNET_ERROR_TYPE_DEBUG, "Waiting for response from `%s' service.\n", 683 LOG (GNUNET_ERROR_TYPE_DEBUG,
684 "Waiting for response from `%s' service.\n",
648 "PEERINFO"); 685 "PEERINFO");
649 ic->request_transmitted = GNUNET_YES; 686 ic->request_transmitted = GNUNET_YES;
650 if (GNUNET_NO == h->in_receive) 687 if (GNUNET_NO == h->in_receive)
651 { 688 {
652 h->in_receive = GNUNET_YES; 689 h->in_receive = GNUNET_YES;
653 GNUNET_CLIENT_receive (h->client, &peerinfo_handler, h, 690 GNUNET_CLIENT_receive (h->client,
691 &peerinfo_handler,
692 h,
654 GNUNET_TIME_absolute_get_remaining (ic->timeout)); 693 GNUNET_TIME_absolute_get_remaining (ic->timeout));
655 } 694 }
656} 695}
@@ -659,11 +698,12 @@ iterator_start_receive (void *cls, const char *emsg)
659/** 698/**
660 * Peerinfo iteration request has timed out. 699 * Peerinfo iteration request has timed out.
661 * 700 *
662 * @param cls the 'struct GNUNET_PEERINFO_IteratorContext*' 701 * @param cls the `struct GNUNET_PEERINFO_IteratorContext *`
663 * @param tc scheduler context 702 * @param tc scheduler context
664 */ 703 */
665static void 704static void
666signal_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 705signal_timeout (void *cls,
706 const struct GNUNET_SCHEDULER_TaskContext *tc)
667{ 707{
668 struct GNUNET_PEERINFO_IteratorContext *ic = cls; 708 struct GNUNET_PEERINFO_IteratorContext *ic = cls;
669 GNUNET_PEERINFO_Processor cb; 709 GNUNET_PEERINFO_Processor cb;
@@ -674,7 +714,9 @@ signal_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
674 cb_cls = ic->callback_cls; 714 cb_cls = ic->callback_cls;
675 GNUNET_PEERINFO_iterate_cancel (ic); 715 GNUNET_PEERINFO_iterate_cancel (ic);
676 if (NULL != cb) 716 if (NULL != cb)
677 cb (cb_cls, NULL, NULL, 717 cb (cb_cls,
718 NULL,
719 NULL,
678 _("Timeout transmitting iteration request to `PEERINFO' service.")); 720 _("Timeout transmitting iteration request to `PEERINFO' service."));
679} 721}
680 722
@@ -685,23 +727,24 @@ signal_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
685 * with a NULL pointer. After that final invocation, the iterator 727 * with a NULL pointer. After that final invocation, the iterator
686 * context must no longer be used. 728 * context must no longer be used.
687 * 729 *
688 * Instead of calling this function with 'peer == NULL' it is often 730 * Instead of calling this function with `peer == NULL` it is often
689 * better to use 'GNUNET_PEERINFO_notify'. 731 * better to use #GNUNET_PEERINFO_notify().
690 * 732 *
691 * @param h handle to the peerinfo service 733 * @param h handle to the peerinfo service
692 * @param include_friend_only include HELLO messages for friends only 734 * @param include_friend_only include HELLO messages for friends only
693 * @param peer restrict iteration to this peer only (can be NULL) 735 * @param peer restrict iteration to this peer only (can be NULL)
694 * @param timeout how long to wait until timing out 736 * @param timeout how long to wait until timing out
695 * @param callback the method to call for each peer 737 * @param callback the method to call for each peer
696 * @param callback_cls closure for callback 738 * @param callback_cls closure for @a callback
697 * @return iterator context 739 * @return iterator context
698 */ 740 */
699struct GNUNET_PEERINFO_IteratorContext * 741struct GNUNET_PEERINFO_IteratorContext *
700GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h, 742GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h,
701 int include_friend_only, 743 int include_friend_only,
702 const struct GNUNET_PeerIdentity *peer, 744 const struct GNUNET_PeerIdentity *peer,
703 struct GNUNET_TIME_Relative timeout, 745 struct GNUNET_TIME_Relative timeout,
704 GNUNET_PEERINFO_Processor callback, void *callback_cls) 746 GNUNET_PEERINFO_Processor callback,
747 void *callback_cls)
705{ 748{
706 struct ListAllPeersMessage *lapm; 749 struct ListAllPeersMessage *lapm;
707 struct ListPeerMessage *lpm; 750 struct ListPeerMessage *lpm;
@@ -781,7 +824,9 @@ GNUNET_PEERINFO_iterate_cancel (struct GNUNET_PEERINFO_IteratorContext *ic)
781 ic); 824 ic);
782 if (NULL != ic->ac) 825 if (NULL != ic->ac)
783 { 826 {
784 GNUNET_CONTAINER_DLL_remove (h->ac_head, h->ac_tail, ic->ac); 827 GNUNET_CONTAINER_DLL_remove (h->ac_head,
828 h->ac_tail,
829 ic->ac);
785 GNUNET_free (ic->ac); 830 GNUNET_free (ic->ac);
786 } 831 }
787 GNUNET_free (ic); 832 GNUNET_free (ic);