diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-06-09 08:54:49 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-06-09 08:54:49 +0000 |
commit | 995ff4c783691df5462353d0ef4f698942de1010 (patch) | |
tree | cb929c9f4e91d09e932c233c73ae9f48808e46a0 /src/peerinfo/gnunet-service-peerinfo.c | |
parent | e703948983a444cf4204913602aac2191d72dc8b (diff) | |
download | gnunet-995ff4c783691df5462353d0ef4f698942de1010.tar.gz gnunet-995ff4c783691df5462353d0ef4f698942de1010.zip |
-fixing doxygen, indentation
Diffstat (limited to 'src/peerinfo/gnunet-service-peerinfo.c')
-rw-r--r-- | src/peerinfo/gnunet-service-peerinfo.c | 226 |
1 files changed, 152 insertions, 74 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 | */ |
514 | struct DirScanContext | 519 | struct DirScanContext |
515 | { | 520 | { |
@@ -538,7 +543,8 @@ struct DirScanContext | |||
538 | * @return #GNUNET_OK (continue iteration) | 543 | * @return #GNUNET_OK (continue iteration) |
539 | */ | 544 | */ |
540 | static int | 545 | static int |
541 | hosts_directory_scan_callback (void *cls, const char *fullname) | 546 | hosts_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 | */ | ||
666 | static struct GNUNET_HELLO_Message * | 684 | static struct GNUNET_HELLO_Message * |
667 | update_friend_hello (const struct GNUNET_HELLO_Message *hello, | 685 | update_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 | */ |
848 | static int | 879 | static int |
849 | add_to_tc (void *cls, const struct GNUNET_PeerIdentity *key, void *value) | 880 | add_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 | */ |
905 | static int | 941 | static int |
906 | discard_hosts_helper (void *cls, const char *fn) | 942 | discard_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 | */ |
985 | static void | 1027 | static void |
986 | cron_clean_data_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 1028 | cron_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 | */ |
1008 | static void | 1055 | static void |
1009 | handle_hello (void *cls, struct GNUNET_SERVER_Client *client, | 1056 | handle_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 | */ |
1037 | static void | 1087 | static void |
1038 | handle_get (void *cls, struct GNUNET_SERVER_Client *client, | 1088 | handle_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 | */ |
1093 | static int | 1150 | static int |
1094 | do_notify_entry (void *cls, const struct GNUNET_PeerIdentity *key, void *value) | 1151 | do_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 | */ |
1130 | static void | 1190 | static void |
1131 | handle_notify (void *cls, struct GNUNET_SERVER_Client *client, | 1191 | handle_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 | */ |
1158 | static void | 1219 | static void |
1159 | disconnect_cb (void *cls,struct GNUNET_SERVER_Client *client) | 1220 | disconnect_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 | */ |
1234 | static void | 1298 | static void |
1235 | run (void *cls, struct GNUNET_SERVER_Handle *server, | 1299 | run (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 | */ |
1313 | int | 1388 | int |
1314 | main (int argc, char *const *argv) | 1389 | main (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; |