diff options
Diffstat (limited to 'src/topology/gnunet-daemon-topology.c')
-rw-r--r-- | src/topology/gnunet-daemon-topology.c | 109 |
1 files changed, 74 insertions, 35 deletions
diff --git a/src/topology/gnunet-daemon-topology.c b/src/topology/gnunet-daemon-topology.c index b28269a77..efe014776 100644 --- a/src/topology/gnunet-daemon-topology.c +++ b/src/topology/gnunet-daemon-topology.c | |||
@@ -126,6 +126,13 @@ struct Peer | |||
126 | 126 | ||
127 | 127 | ||
128 | /** | 128 | /** |
129 | * The task to delayed start the notification process intially. | ||
130 | * We like to give transport some time to give us our hello to distribute it. | ||
131 | */ | ||
132 | struct GNUNET_SCHEDULER_Task *peerstore_notify_task; | ||
133 | |||
134 | |||
135 | /** | ||
129 | * Our peerstore notification context. We use notification | 136 | * Our peerstore notification context. We use notification |
130 | * to instantly learn about new peers as they are discovered. | 137 | * to instantly learn about new peers as they are discovered. |
131 | */ | 138 | */ |
@@ -353,8 +360,8 @@ make_peer (const struct GNUNET_PeerIdentity *peer, | |||
353 | ret->is_friend = is_friend; | 360 | ret->is_friend = is_friend; |
354 | if (NULL != hello) | 361 | if (NULL != hello) |
355 | { | 362 | { |
356 | ret->hello = GNUNET_malloc (sizeof (hello)); | 363 | ret->hello = GNUNET_malloc (ntohs (hello->size)); |
357 | GNUNET_memcpy (ret->hello, hello, sizeof (hello)); | 364 | GNUNET_memcpy (ret->hello, hello, ntohs (hello->size)); |
358 | } | 365 | } |
359 | GNUNET_break (GNUNET_OK == | 366 | GNUNET_break (GNUNET_OK == |
360 | GNUNET_CONTAINER_multipeermap_put ( | 367 | GNUNET_CONTAINER_multipeermap_put ( |
@@ -504,10 +511,11 @@ schedule_next_hello (void *cls) | |||
504 | 511 | ||
505 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 512 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
506 | "schedule_next_hello 3\n"); | 513 | "schedule_next_hello 3\n"); |
507 | want = fah.result->hello->size; | 514 | want = ntohs (fah.result->hello->size); |
508 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 515 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
509 | "Sending HELLO with %u bytes", | 516 | "Sending HELLO with %u bytes for peer %s\n", |
510 | (unsigned int) want); | 517 | (unsigned int) want, |
518 | GNUNET_i2s (&pl->pid)); | ||
511 | env = GNUNET_MQ_msg_copy (fah.result->hello); | 519 | env = GNUNET_MQ_msg_copy (fah.result->hello); |
512 | GNUNET_MQ_send (pl->mq, env); | 520 | GNUNET_MQ_send (pl->mq, env); |
513 | 521 | ||
@@ -543,14 +551,12 @@ reschedule_hellos (void *cls, | |||
543 | const struct GNUNET_PeerIdentity *pid, | 551 | const struct GNUNET_PeerIdentity *pid, |
544 | void *value) | 552 | void *value) |
545 | { | 553 | { |
554 | (void *) cls; | ||
546 | struct Peer *peer = value; | 555 | struct Peer *peer = value; |
547 | struct Peer *skip = cls; | ||
548 | 556 | ||
549 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 557 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
550 | "Reschedule for `%s'\n", | 558 | "Reschedule for `%s'\n", |
551 | GNUNET_i2s (&peer->pid)); | 559 | GNUNET_i2s (&peer->pid)); |
552 | if (skip == peer) | ||
553 | return GNUNET_YES; | ||
554 | if (NULL == peer->mq) | 560 | if (NULL == peer->mq) |
555 | return GNUNET_YES; | 561 | return GNUNET_YES; |
556 | if (NULL != peer->hello_delay_task) | 562 | if (NULL != peer->hello_delay_task) |
@@ -712,7 +718,8 @@ address_iterator (void *cls, | |||
712 | { | 718 | { |
713 | int *flag = cls; | 719 | int *flag = cls; |
714 | 720 | ||
715 | *flag = GNUNET_YES; | 721 | *flag = *flag + 1; |
722 | //*flag = GNUNET_YES; | ||
716 | } | 723 | } |
717 | 724 | ||
718 | 725 | ||
@@ -725,57 +732,76 @@ address_iterator (void *cls, | |||
725 | static void | 732 | static void |
726 | consider_for_advertising (const struct GNUNET_MessageHeader *hello) | 733 | consider_for_advertising (const struct GNUNET_MessageHeader *hello) |
727 | { | 734 | { |
728 | int have_address; | 735 | int num_addresses_old; |
736 | int num_addresses_new; | ||
729 | struct GNUNET_HELLO_Builder *builder = GNUNET_HELLO_builder_from_msg (hello); | 737 | struct GNUNET_HELLO_Builder *builder = GNUNET_HELLO_builder_from_msg (hello); |
730 | struct GNUNET_PeerIdentity *pid; | 738 | struct GNUNET_PeerIdentity *pid = GNUNET_HELLO_builder_get_id (builder); |
731 | struct GNUNET_TIME_Absolute dt; | 739 | struct GNUNET_TIME_Absolute dt; |
732 | struct GNUNET_MQ_Envelope *env; | 740 | struct GNUNET_MQ_Envelope *env; |
733 | const struct GNUNET_MessageHeader *nh; | 741 | const struct GNUNET_MessageHeader *nh; |
734 | struct Peer *peer; | 742 | struct Peer *peer; |
735 | uint16_t size; | 743 | uint16_t size; |
736 | 744 | ||
737 | have_address = GNUNET_NO; | ||
738 | GNUNET_HELLO_builder_iterate (builder, | 745 | GNUNET_HELLO_builder_iterate (builder, |
739 | pid, | 746 | pid, |
740 | &address_iterator, | 747 | &address_iterator, |
741 | &have_address); | 748 | &num_addresses_new); |
742 | if (GNUNET_NO == have_address) | 749 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
750 | "consider 0 for %s\n", | ||
751 | GNUNET_i2s (pid)); | ||
752 | if (0 == num_addresses_new) | ||
753 | { | ||
754 | GNUNET_HELLO_builder_free (builder); | ||
743 | return; /* no point in advertising this one... */ | 755 | return; /* no point in advertising this one... */ |
744 | if (NULL == pid || 0 == GNUNET_memcmp (pid, &my_identity)) | 756 | } |
745 | return; /* that's me! */ | 757 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
746 | 758 | "consider 1\n"); | |
759 | if (NULL == pid) | ||
760 | { | ||
761 | GNUNET_HELLO_builder_free (builder); | ||
762 | return; | ||
763 | } | ||
764 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
765 | "consider 2\n"); | ||
747 | peer = GNUNET_CONTAINER_multipeermap_get (peers, pid); | 766 | peer = GNUNET_CONTAINER_multipeermap_get (peers, pid); |
748 | if (NULL == peer) | 767 | if (NULL == peer) |
749 | { | 768 | { |
750 | peer = make_peer (pid, hello, GNUNET_NO); | 769 | peer = make_peer (pid, hello, GNUNET_NO); |
751 | } | 770 | } |
752 | 771 | else if (NULL != peer->hello) | |
753 | if (NULL != peer->hello) | ||
754 | { | 772 | { |
755 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); | 773 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); |
756 | struct GNUNET_TIME_Absolute new_hello_exp = GNUNET_HELLO_builder_get_expiration_time (builder, | 774 | struct GNUNET_TIME_Absolute new_hello_exp = |
757 | hello); | 775 | GNUNET_HELLO_builder_get_expiration_time (hello); |
758 | struct GNUNET_HELLO_Builder *peer_builder = GNUNET_HELLO_builder_from_msg (peer->hello); | 776 | struct GNUNET_TIME_Absolute old_hello_exp = |
759 | struct GNUNET_TIME_Absolute old_hello_exp = GNUNET_HELLO_builder_get_expiration_time (peer_builder, | 777 | GNUNET_HELLO_builder_get_expiration_time (peer->hello); |
760 | peer->hello); | 778 | struct GNUNET_HELLO_Builder *builder_old = GNUNET_HELLO_builder_from_msg (peer->hello); |
761 | 779 | struct GNUNET_PeerIdentity *pid_old = GNUNET_HELLO_builder_get_id (builder_old); | |
762 | if (GNUNET_TIME_absolute_cmp (new_hello_exp, > , now) && GNUNET_TIME_absolute_cmp (new_hello_exp, > , old_hello_exp)) | 780 | |
781 | GNUNET_HELLO_builder_iterate (builder_old, | ||
782 | pid_old, | ||
783 | &address_iterator, | ||
784 | &num_addresses_old); | ||
785 | if (GNUNET_TIME_absolute_cmp (new_hello_exp, >, now) && | ||
786 | (GNUNET_TIME_absolute_cmp (new_hello_exp, >, old_hello_exp) || | ||
787 | num_addresses_old < num_addresses_new)) | ||
763 | { | 788 | { |
764 | GNUNET_free (peer->hello); | 789 | GNUNET_free (peer->hello); |
765 | size = sizeof (hello); | 790 | size = ntohs (hello->size); |
766 | peer->hello = GNUNET_malloc (size); | 791 | peer->hello = GNUNET_malloc (size); |
767 | GNUNET_memcpy (peer->hello, hello, size); | 792 | GNUNET_memcpy (peer->hello, hello, size); |
768 | } | 793 | } |
769 | else | 794 | else |
770 | { | 795 | { |
796 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
797 | "consider 3\n"); | ||
798 | GNUNET_HELLO_builder_free (builder); | ||
771 | return; | 799 | return; |
772 | } | 800 | } |
773 | GNUNET_HELLO_builder_free (builder); | ||
774 | GNUNET_HELLO_builder_free (peer_builder); | ||
775 | } | 801 | } |
776 | else | 802 | else |
777 | { | 803 | { |
778 | size = sizeof (hello); | 804 | size = ntohs (hello->size); |
779 | peer->hello = GNUNET_malloc (size); | 805 | peer->hello = GNUNET_malloc (size); |
780 | GNUNET_memcpy (peer->hello, hello, size); | 806 | GNUNET_memcpy (peer->hello, hello, size); |
781 | } | 807 | } |
@@ -790,7 +816,8 @@ consider_for_advertising (const struct GNUNET_MessageHeader *hello) | |||
790 | setup_filter (peer); | 816 | setup_filter (peer); |
791 | /* since we have a new HELLO to pick from, re-schedule all | 817 | /* since we have a new HELLO to pick from, re-schedule all |
792 | * HELLO requests that are not bound by the HELLO send rate! */ | 818 | * HELLO requests that are not bound by the HELLO send rate! */ |
793 | GNUNET_CONTAINER_multipeermap_iterate (peers, &reschedule_hellos, peer); | 819 | GNUNET_CONTAINER_multipeermap_iterate (peers, &reschedule_hellos, NULL); |
820 | GNUNET_HELLO_builder_free (builder); | ||
794 | } | 821 | } |
795 | 822 | ||
796 | 823 | ||
@@ -823,8 +850,6 @@ process_peer (void *cls, | |||
823 | return; | 850 | return; |
824 | } | 851 | } |
825 | GNUNET_assert (NULL != peer); | 852 | GNUNET_assert (NULL != peer); |
826 | if (0 == GNUNET_memcmp (&my_identity, peer)) | ||
827 | return; /* that's me! */ | ||
828 | if (NULL == hello) | 853 | if (NULL == hello) |
829 | { | 854 | { |
830 | /* free existing HELLO, if any */ | 855 | /* free existing HELLO, if any */ |
@@ -850,6 +875,15 @@ process_peer (void *cls, | |||
850 | attempt_connect (pos); | 875 | attempt_connect (pos); |
851 | } | 876 | } |
852 | 877 | ||
878 | static void | ||
879 | start_notify (void *cls) | ||
880 | { | ||
881 | (void *) cls; | ||
882 | |||
883 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting to process new hellos for gossiping.\n"); | ||
884 | peerstore_notify = | ||
885 | GNUNET_PEERSTORE_hello_changed_notify (ps, GNUNET_NO, &process_peer, NULL); | ||
886 | } | ||
853 | 887 | ||
854 | /** | 888 | /** |
855 | * Function called after #GNUNET_CORE_connect has succeeded | 889 | * Function called after #GNUNET_CORE_connect has succeeded |
@@ -871,8 +905,9 @@ core_init (void *cls, const struct GNUNET_PeerIdentity *my_id) | |||
871 | } | 905 | } |
872 | my_identity = *my_id; | 906 | my_identity = *my_id; |
873 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "I am peer `%s'\n", GNUNET_i2s (my_id)); | 907 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "I am peer `%s'\n", GNUNET_i2s (my_id)); |
874 | peerstore_notify = | 908 | peerstore_notify_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, |
875 | GNUNET_PEERSTORE_hello_changed_notify (ps, GNUNET_NO, &process_peer, NULL); | 909 | start_notify, |
910 | NULL); | ||
876 | } | 911 | } |
877 | 912 | ||
878 | 913 | ||
@@ -1030,6 +1065,10 @@ cleaning_task (void *cls) | |||
1030 | GNUNET_PEERSTORE_hello_changed_notify_cancel (peerstore_notify); | 1065 | GNUNET_PEERSTORE_hello_changed_notify_cancel (peerstore_notify); |
1031 | peerstore_notify = NULL; | 1066 | peerstore_notify = NULL; |
1032 | } | 1067 | } |
1068 | else if (NULL != peerstore_notify_task) | ||
1069 | { | ||
1070 | GNUNET_SCHEDULER_cancel (peerstore_notify_task); | ||
1071 | } | ||
1033 | if (NULL != handle) | 1072 | if (NULL != handle) |
1034 | { | 1073 | { |
1035 | GNUNET_CORE_disconnect (handle); | 1074 | GNUNET_CORE_disconnect (handle); |