diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/rps/gnunet-service-rps.c | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/rps/gnunet-service-rps.c')
-rw-r--r-- | src/rps/gnunet-service-rps.c | 4251 |
1 files changed, 2148 insertions, 2103 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index 32f3103ed..66ffd173a 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c | |||
@@ -41,7 +41,7 @@ | |||
41 | #include <inttypes.h> | 41 | #include <inttypes.h> |
42 | #include <string.h> | 42 | #include <string.h> |
43 | 43 | ||
44 | #define LOG(kind, ...) GNUNET_log(kind, __VA_ARGS__) | 44 | #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) |
45 | 45 | ||
46 | // TODO check for overflows | 46 | // TODO check for overflows |
47 | 47 | ||
@@ -92,7 +92,8 @@ | |||
92 | * When an operation cannot be executed right now this struct is used to store | 92 | * When an operation cannot be executed right now this struct is used to store |
93 | * the callback and closure for later execution. | 93 | * the callback and closure for later execution. |
94 | */ | 94 | */ |
95 | struct PeerPendingOp { | 95 | struct PeerPendingOp |
96 | { | ||
96 | /** | 97 | /** |
97 | * Callback | 98 | * Callback |
98 | */ | 99 | */ |
@@ -110,7 +111,8 @@ struct PeerPendingOp { | |||
110 | * This is used to keep track of all messages that have not been sent yet. When | 111 | * This is used to keep track of all messages that have not been sent yet. When |
111 | * a peer is to be removed the pending messages can be removed properly. | 112 | * a peer is to be removed the pending messages can be removed properly. |
112 | */ | 113 | */ |
113 | struct PendingMessage { | 114 | struct PendingMessage |
115 | { | ||
114 | /** | 116 | /** |
115 | * DLL next, prev | 117 | * DLL next, prev |
116 | */ | 118 | */ |
@@ -146,7 +148,8 @@ struct ChannelCtx; | |||
146 | * status about the channels, the pending operations on this peer and some flags | 148 | * status about the channels, the pending operations on this peer and some flags |
147 | * about the status of the peer itself. (online, valid, ...) | 149 | * about the status of the peer itself. (online, valid, ...) |
148 | */ | 150 | */ |
149 | struct PeerContext { | 151 | struct PeerContext |
152 | { | ||
150 | /** | 153 | /** |
151 | * The Sub this context belongs to. | 154 | * The Sub this context belongs to. |
152 | */ | 155 | */ |
@@ -221,7 +224,8 @@ struct PeerContext { | |||
221 | /** | 224 | /** |
222 | * @brief Closure to #valid_peer_iterator | 225 | * @brief Closure to #valid_peer_iterator |
223 | */ | 226 | */ |
224 | struct PeersIteratorCls { | 227 | struct PeersIteratorCls |
228 | { | ||
225 | /** | 229 | /** |
226 | * Iterator function | 230 | * Iterator function |
227 | */ | 231 | */ |
@@ -236,7 +240,8 @@ struct PeersIteratorCls { | |||
236 | /** | 240 | /** |
237 | * @brief Context for a channel | 241 | * @brief Context for a channel |
238 | */ | 242 | */ |
239 | struct ChannelCtx { | 243 | struct ChannelCtx |
244 | { | ||
240 | /** | 245 | /** |
241 | * @brief The channel itself | 246 | * @brief The channel itself |
242 | */ | 247 | */ |
@@ -261,7 +266,8 @@ struct ChannelCtx { | |||
261 | /** | 266 | /** |
262 | * If type is 2 This struct is used to store the attacked peers in a DLL | 267 | * If type is 2 This struct is used to store the attacked peers in a DLL |
263 | */ | 268 | */ |
264 | struct AttackedPeer { | 269 | struct AttackedPeer |
270 | { | ||
265 | /** | 271 | /** |
266 | * DLL | 272 | * DLL |
267 | */ | 273 | */ |
@@ -296,7 +302,8 @@ struct AttackedPeer { | |||
296 | * Essentially one instance of brahms that only connects to other instances | 302 | * Essentially one instance of brahms that only connects to other instances |
297 | * with the same (secret) value. | 303 | * with the same (secret) value. |
298 | */ | 304 | */ |
299 | struct Sub { | 305 | struct Sub |
306 | { | ||
300 | /** | 307 | /** |
301 | * @brief Hash of the shared value that defines Subs. | 308 | * @brief Hash of the shared value that defines Subs. |
302 | */ | 309 | */ |
@@ -588,10 +595,10 @@ static const uint32_t num_valid_peers_max = UINT32_MAX; | |||
588 | 595 | ||
589 | 596 | ||
590 | static void | 597 | static void |
591 | do_round(void *cls); | 598 | do_round (void *cls); |
592 | 599 | ||
593 | static void | 600 | static void |
594 | do_mal_round(void *cls); | 601 | do_mal_round (void *cls); |
595 | 602 | ||
596 | 603 | ||
597 | /** | 604 | /** |
@@ -603,16 +610,16 @@ do_mal_round(void *cls); | |||
603 | * @return the #PeerContext | 610 | * @return the #PeerContext |
604 | */ | 611 | */ |
605 | static struct PeerContext * | 612 | static struct PeerContext * |
606 | get_peer_ctx(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, | 613 | get_peer_ctx (const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, |
607 | const struct GNUNET_PeerIdentity *peer) | 614 | const struct GNUNET_PeerIdentity *peer) |
608 | { | 615 | { |
609 | struct PeerContext *ctx; | 616 | struct PeerContext *ctx; |
610 | int ret; | 617 | int ret; |
611 | 618 | ||
612 | ret = GNUNET_CONTAINER_multipeermap_contains(peer_map, peer); | 619 | ret = GNUNET_CONTAINER_multipeermap_contains (peer_map, peer); |
613 | GNUNET_assert(GNUNET_YES == ret); | 620 | GNUNET_assert (GNUNET_YES == ret); |
614 | ctx = GNUNET_CONTAINER_multipeermap_get(peer_map, peer); | 621 | ctx = GNUNET_CONTAINER_multipeermap_get (peer_map, peer); |
615 | GNUNET_assert(NULL != ctx); | 622 | GNUNET_assert (NULL != ctx); |
616 | return ctx; | 623 | return ctx; |
617 | } | 624 | } |
618 | 625 | ||
@@ -628,17 +635,17 @@ get_peer_ctx(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, | |||
628 | * #GNUNET_NO if peer is not knwon | 635 | * #GNUNET_NO if peer is not knwon |
629 | */ | 636 | */ |
630 | static int | 637 | static int |
631 | check_peer_known(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, | 638 | check_peer_known (const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, |
632 | const struct GNUNET_PeerIdentity *peer) | 639 | const struct GNUNET_PeerIdentity *peer) |
633 | { | 640 | { |
634 | if (NULL != peer_map) | 641 | if (NULL != peer_map) |
635 | { | 642 | { |
636 | return GNUNET_CONTAINER_multipeermap_contains(peer_map, peer); | 643 | return GNUNET_CONTAINER_multipeermap_contains (peer_map, peer); |
637 | } | 644 | } |
638 | else | 645 | else |
639 | { | 646 | { |
640 | return GNUNET_NO; | 647 | return GNUNET_NO; |
641 | } | 648 | } |
642 | } | 649 | } |
643 | 650 | ||
644 | 651 | ||
@@ -651,27 +658,27 @@ check_peer_known(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, | |||
651 | * @return the #PeerContext | 658 | * @return the #PeerContext |
652 | */ | 659 | */ |
653 | static struct PeerContext * | 660 | static struct PeerContext * |
654 | create_peer_ctx(struct Sub *sub, | 661 | create_peer_ctx (struct Sub *sub, |
655 | const struct GNUNET_PeerIdentity *peer) | 662 | const struct GNUNET_PeerIdentity *peer) |
656 | { | 663 | { |
657 | struct PeerContext *ctx; | 664 | struct PeerContext *ctx; |
658 | int ret; | 665 | int ret; |
659 | 666 | ||
660 | GNUNET_assert(GNUNET_NO == check_peer_known(sub->peer_map, peer)); | 667 | GNUNET_assert (GNUNET_NO == check_peer_known (sub->peer_map, peer)); |
661 | 668 | ||
662 | ctx = GNUNET_new(struct PeerContext); | 669 | ctx = GNUNET_new (struct PeerContext); |
663 | ctx->peer_id = *peer; | 670 | ctx->peer_id = *peer; |
664 | ctx->sub = sub; | 671 | ctx->sub = sub; |
665 | ret = GNUNET_CONTAINER_multipeermap_put(sub->peer_map, peer, ctx, | 672 | ret = GNUNET_CONTAINER_multipeermap_put (sub->peer_map, peer, ctx, |
666 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 673 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
667 | GNUNET_assert(GNUNET_OK == ret); | 674 | GNUNET_assert (GNUNET_OK == ret); |
668 | if (sub == msub) | 675 | if (sub == msub) |
669 | { | 676 | { |
670 | GNUNET_STATISTICS_set(stats, | 677 | GNUNET_STATISTICS_set (stats, |
671 | "# known peers", | 678 | "# known peers", |
672 | GNUNET_CONTAINER_multipeermap_size(sub->peer_map), | 679 | GNUNET_CONTAINER_multipeermap_size (sub->peer_map), |
673 | GNUNET_NO); | 680 | GNUNET_NO); |
674 | } | 681 | } |
675 | return ctx; | 682 | return ctx; |
676 | } | 683 | } |
677 | 684 | ||
@@ -685,14 +692,14 @@ create_peer_ctx(struct Sub *sub, | |||
685 | * @return the context | 692 | * @return the context |
686 | */ | 693 | */ |
687 | static struct PeerContext * | 694 | static struct PeerContext * |
688 | create_or_get_peer_ctx(struct Sub *sub, | 695 | create_or_get_peer_ctx (struct Sub *sub, |
689 | const struct GNUNET_PeerIdentity *peer) | 696 | const struct GNUNET_PeerIdentity *peer) |
690 | { | 697 | { |
691 | if (GNUNET_NO == check_peer_known(sub->peer_map, peer)) | 698 | if (GNUNET_NO == check_peer_known (sub->peer_map, peer)) |
692 | { | 699 | { |
693 | return create_peer_ctx(sub, peer); | 700 | return create_peer_ctx (sub, peer); |
694 | } | 701 | } |
695 | return get_peer_ctx(sub->peer_map, peer); | 702 | return get_peer_ctx (sub->peer_map, peer); |
696 | } | 703 | } |
697 | 704 | ||
698 | 705 | ||
@@ -707,25 +714,25 @@ create_or_get_peer_ctx(struct Sub *sub, | |||
707 | * #GNUNET_NO otherwise | 714 | * #GNUNET_NO otherwise |
708 | */ | 715 | */ |
709 | static int | 716 | static int |
710 | check_connected(struct PeerContext *peer_ctx) | 717 | check_connected (struct PeerContext *peer_ctx) |
711 | { | 718 | { |
712 | /* If we don't know about this peer we don't know whether it's online */ | 719 | /* If we don't know about this peer we don't know whether it's online */ |
713 | if (GNUNET_NO == check_peer_known(peer_ctx->sub->peer_map, | 720 | if (GNUNET_NO == check_peer_known (peer_ctx->sub->peer_map, |
714 | &peer_ctx->peer_id)) | 721 | &peer_ctx->peer_id)) |
715 | { | 722 | { |
716 | return GNUNET_NO; | 723 | return GNUNET_NO; |
717 | } | 724 | } |
718 | /* Get the context */ | 725 | /* Get the context */ |
719 | peer_ctx = get_peer_ctx(peer_ctx->sub->peer_map, &peer_ctx->peer_id); | 726 | peer_ctx = get_peer_ctx (peer_ctx->sub->peer_map, &peer_ctx->peer_id); |
720 | /* If we have no channel to this peer we don't know whether it's online */ | 727 | /* If we have no channel to this peer we don't know whether it's online */ |
721 | if ((NULL == peer_ctx->send_channel_ctx) && | 728 | if ((NULL == peer_ctx->send_channel_ctx) && |
722 | (NULL == peer_ctx->recv_channel_ctx)) | 729 | (NULL == peer_ctx->recv_channel_ctx)) |
723 | { | 730 | { |
724 | UNSET_PEER_FLAG(peer_ctx, Peers_ONLINE); | 731 | UNSET_PEER_FLAG (peer_ctx, Peers_ONLINE); |
725 | return GNUNET_NO; | 732 | return GNUNET_NO; |
726 | } | 733 | } |
727 | /* Otherwise (if we have a channel, we know that it's online */ | 734 | /* Otherwise (if we have a channel, we know that it's online */ |
728 | SET_PEER_FLAG(peer_ctx, Peers_ONLINE); | 735 | SET_PEER_FLAG (peer_ctx, Peers_ONLINE); |
729 | return GNUNET_YES; | 736 | return GNUNET_YES; |
730 | } | 737 | } |
731 | 738 | ||
@@ -733,7 +740,8 @@ check_connected(struct PeerContext *peer_ctx) | |||
733 | /** | 740 | /** |
734 | * @brief The closure to #get_rand_peer_iterator. | 741 | * @brief The closure to #get_rand_peer_iterator. |
735 | */ | 742 | */ |
736 | struct GetRandPeerIteratorCls { | 743 | struct GetRandPeerIteratorCls |
744 | { | ||
737 | /** | 745 | /** |
738 | * @brief The index of the peer to return. | 746 | * @brief The index of the peer to return. |
739 | * Will be decreased until 0. | 747 | * Will be decreased until 0. |
@@ -764,19 +772,19 @@ struct GetRandPeerIteratorCls { | |||
764 | * #GNUNET_NO if not. | 772 | * #GNUNET_NO if not. |
765 | */ | 773 | */ |
766 | static int | 774 | static int |
767 | get_rand_peer_iterator(void *cls, | 775 | get_rand_peer_iterator (void *cls, |
768 | const struct GNUNET_PeerIdentity *peer, | 776 | const struct GNUNET_PeerIdentity *peer, |
769 | void *value) | 777 | void *value) |
770 | { | 778 | { |
771 | struct GetRandPeerIteratorCls *iterator_cls = cls; | 779 | struct GetRandPeerIteratorCls *iterator_cls = cls; |
772 | 780 | ||
773 | (void)value; | 781 | (void) value; |
774 | 782 | ||
775 | if (0 >= iterator_cls->index) | 783 | if (0 >= iterator_cls->index) |
776 | { | 784 | { |
777 | iterator_cls->peer = peer; | 785 | iterator_cls->peer = peer; |
778 | return GNUNET_NO; | 786 | return GNUNET_NO; |
779 | } | 787 | } |
780 | iterator_cls->index--; | 788 | iterator_cls->index--; |
781 | return GNUNET_YES; | 789 | return GNUNET_YES; |
782 | } | 790 | } |
@@ -791,19 +799,20 @@ get_rand_peer_iterator(void *cls, | |||
791 | * @return a random peer | 799 | * @return a random peer |
792 | */ | 800 | */ |
793 | static const struct GNUNET_PeerIdentity * | 801 | static const struct GNUNET_PeerIdentity * |
794 | get_random_peer_from_peermap(struct GNUNET_CONTAINER_MultiPeerMap *valid_peers) | 802 | get_random_peer_from_peermap (struct GNUNET_CONTAINER_MultiPeerMap *valid_peers) |
795 | { | 803 | { |
796 | struct GetRandPeerIteratorCls *iterator_cls; | 804 | struct GetRandPeerIteratorCls *iterator_cls; |
797 | const struct GNUNET_PeerIdentity *ret; | 805 | const struct GNUNET_PeerIdentity *ret; |
798 | 806 | ||
799 | iterator_cls = GNUNET_new(struct GetRandPeerIteratorCls); | 807 | iterator_cls = GNUNET_new (struct GetRandPeerIteratorCls); |
800 | iterator_cls->index = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, | 808 | iterator_cls->index = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
801 | GNUNET_CONTAINER_multipeermap_size(valid_peers)); | 809 | GNUNET_CONTAINER_multipeermap_size ( |
802 | (void)GNUNET_CONTAINER_multipeermap_iterate(valid_peers, | 810 | valid_peers)); |
803 | get_rand_peer_iterator, | 811 | (void) GNUNET_CONTAINER_multipeermap_iterate (valid_peers, |
804 | iterator_cls); | 812 | get_rand_peer_iterator, |
813 | iterator_cls); | ||
805 | ret = iterator_cls->peer; | 814 | ret = iterator_cls->peer; |
806 | GNUNET_free(iterator_cls); | 815 | GNUNET_free (iterator_cls); |
807 | return ret; | 816 | return ret; |
808 | } | 817 | } |
809 | 818 | ||
@@ -820,8 +829,8 @@ get_random_peer_from_peermap(struct GNUNET_CONTAINER_MultiPeerMap *valid_peers) | |||
820 | * #GNUNET_NO otherwise | 829 | * #GNUNET_NO otherwise |
821 | */ | 830 | */ |
822 | static int | 831 | static int |
823 | add_valid_peer(const struct GNUNET_PeerIdentity *peer, | 832 | add_valid_peer (const struct GNUNET_PeerIdentity *peer, |
824 | struct GNUNET_CONTAINER_MultiPeerMap *valid_peers) | 833 | struct GNUNET_CONTAINER_MultiPeerMap *valid_peers) |
825 | { | 834 | { |
826 | const struct GNUNET_PeerIdentity *rand_peer; | 835 | const struct GNUNET_PeerIdentity *rand_peer; |
827 | int ret; | 836 | int ret; |
@@ -829,26 +838,26 @@ add_valid_peer(const struct GNUNET_PeerIdentity *peer, | |||
829 | ret = GNUNET_YES; | 838 | ret = GNUNET_YES; |
830 | /* Remove random peers until there is space for a new one */ | 839 | /* Remove random peers until there is space for a new one */ |
831 | while (num_valid_peers_max <= | 840 | while (num_valid_peers_max <= |
832 | GNUNET_CONTAINER_multipeermap_size(valid_peers)) | 841 | GNUNET_CONTAINER_multipeermap_size (valid_peers)) |
833 | { | 842 | { |
834 | rand_peer = get_random_peer_from_peermap(valid_peers); | 843 | rand_peer = get_random_peer_from_peermap (valid_peers); |
835 | GNUNET_CONTAINER_multipeermap_remove_all(valid_peers, rand_peer); | 844 | GNUNET_CONTAINER_multipeermap_remove_all (valid_peers, rand_peer); |
836 | ret = GNUNET_NO; | 845 | ret = GNUNET_NO; |
837 | } | 846 | } |
838 | (void)GNUNET_CONTAINER_multipeermap_put(valid_peers, peer, NULL, | 847 | (void) GNUNET_CONTAINER_multipeermap_put (valid_peers, peer, NULL, |
839 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 848 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
840 | if (valid_peers == msub->valid_peers) | 849 | if (valid_peers == msub->valid_peers) |
841 | { | 850 | { |
842 | GNUNET_STATISTICS_set(stats, | 851 | GNUNET_STATISTICS_set (stats, |
843 | "# valid peers", | 852 | "# valid peers", |
844 | GNUNET_CONTAINER_multipeermap_size(valid_peers), | 853 | GNUNET_CONTAINER_multipeermap_size (valid_peers), |
845 | GNUNET_NO); | 854 | GNUNET_NO); |
846 | } | 855 | } |
847 | return ret; | 856 | return ret; |
848 | } | 857 | } |
849 | 858 | ||
850 | static void | 859 | static void |
851 | remove_pending_message(struct PendingMessage *pending_msg, int cancel); | 860 | remove_pending_message (struct PendingMessage *pending_msg, int cancel); |
852 | 861 | ||
853 | /** | 862 | /** |
854 | * @brief Set the peer flag to living and | 863 | * @brief Set the peer flag to living and |
@@ -859,62 +868,62 @@ remove_pending_message(struct PendingMessage *pending_msg, int cancel); | |||
859 | * @param peer_ctx the #PeerContext of the peer to set online | 868 | * @param peer_ctx the #PeerContext of the peer to set online |
860 | */ | 869 | */ |
861 | static void | 870 | static void |
862 | set_peer_online(struct PeerContext *peer_ctx) | 871 | set_peer_online (struct PeerContext *peer_ctx) |
863 | { | 872 | { |
864 | struct GNUNET_PeerIdentity *peer; | 873 | struct GNUNET_PeerIdentity *peer; |
865 | unsigned int i; | 874 | unsigned int i; |
866 | 875 | ||
867 | peer = &peer_ctx->peer_id; | 876 | peer = &peer_ctx->peer_id; |
868 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 877 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
869 | "Peer %s is online and valid, calling %i pending operations on it\n", | 878 | "Peer %s is online and valid, calling %i pending operations on it\n", |
870 | GNUNET_i2s(peer), | 879 | GNUNET_i2s (peer), |
871 | peer_ctx->num_pending_ops); | 880 | peer_ctx->num_pending_ops); |
872 | 881 | ||
873 | if (NULL != peer_ctx->online_check_pending) | 882 | if (NULL != peer_ctx->online_check_pending) |
874 | { | 883 | { |
875 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 884 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
876 | "Removing pending online check for peer %s\n", | 885 | "Removing pending online check for peer %s\n", |
877 | GNUNET_i2s(&peer_ctx->peer_id)); | 886 | GNUNET_i2s (&peer_ctx->peer_id)); |
878 | // TODO wait until cadet sets mq->cancel_impl | 887 | // TODO wait until cadet sets mq->cancel_impl |
879 | //GNUNET_MQ_send_cancel (peer_ctx->online_check_pending->ev); | 888 | // GNUNET_MQ_send_cancel (peer_ctx->online_check_pending->ev); |
880 | remove_pending_message(peer_ctx->online_check_pending, GNUNET_YES); | 889 | remove_pending_message (peer_ctx->online_check_pending, GNUNET_YES); |
881 | peer_ctx->online_check_pending = NULL; | 890 | peer_ctx->online_check_pending = NULL; |
882 | } | 891 | } |
883 | 892 | ||
884 | SET_PEER_FLAG(peer_ctx, Peers_ONLINE); | 893 | SET_PEER_FLAG (peer_ctx, Peers_ONLINE); |
885 | 894 | ||
886 | /* Call pending operations */ | 895 | /* Call pending operations */ |
887 | for (i = 0; i < peer_ctx->num_pending_ops; i++) | 896 | for (i = 0; i < peer_ctx->num_pending_ops; i++) |
888 | { | 897 | { |
889 | peer_ctx->pending_ops[i].op(peer_ctx->pending_ops[i].op_cls, peer); | 898 | peer_ctx->pending_ops[i].op (peer_ctx->pending_ops[i].op_cls, peer); |
890 | } | 899 | } |
891 | GNUNET_array_grow(peer_ctx->pending_ops, peer_ctx->num_pending_ops, 0); | 900 | GNUNET_array_grow (peer_ctx->pending_ops, peer_ctx->num_pending_ops, 0); |
892 | } | 901 | } |
893 | 902 | ||
894 | static void | 903 | static void |
895 | cleanup_destroyed_channel(void *cls, | 904 | cleanup_destroyed_channel (void *cls, |
896 | const struct GNUNET_CADET_Channel *channel); | 905 | const struct GNUNET_CADET_Channel *channel); |
897 | 906 | ||
898 | /* Declaration of handlers */ | 907 | /* Declaration of handlers */ |
899 | static void | 908 | static void |
900 | handle_peer_check(void *cls, | 909 | handle_peer_check (void *cls, |
901 | const struct GNUNET_MessageHeader *msg); | 910 | const struct GNUNET_MessageHeader *msg); |
902 | 911 | ||
903 | static void | 912 | static void |
904 | handle_peer_push(void *cls, | 913 | handle_peer_push (void *cls, |
905 | const struct GNUNET_MessageHeader *msg); | 914 | const struct GNUNET_MessageHeader *msg); |
906 | 915 | ||
907 | static void | 916 | static void |
908 | handle_peer_pull_request(void *cls, | 917 | handle_peer_pull_request (void *cls, |
909 | const struct GNUNET_MessageHeader *msg); | 918 | const struct GNUNET_MessageHeader *msg); |
910 | 919 | ||
911 | static int | 920 | static int |
912 | check_peer_pull_reply(void *cls, | 921 | check_peer_pull_reply (void *cls, |
913 | const struct GNUNET_RPS_P2P_PullReplyMessage *msg); | 922 | const struct GNUNET_RPS_P2P_PullReplyMessage *msg); |
914 | 923 | ||
915 | static void | 924 | static void |
916 | handle_peer_pull_reply(void *cls, | 925 | handle_peer_pull_reply (void *cls, |
917 | const struct GNUNET_RPS_P2P_PullReplyMessage *msg); | 926 | const struct GNUNET_RPS_P2P_PullReplyMessage *msg); |
918 | 927 | ||
919 | /* End declaration of handlers */ | 928 | /* End declaration of handlers */ |
920 | 929 | ||
@@ -926,11 +935,11 @@ handle_peer_pull_reply(void *cls, | |||
926 | * @return The channel context | 935 | * @return The channel context |
927 | */ | 936 | */ |
928 | static struct ChannelCtx * | 937 | static struct ChannelCtx * |
929 | add_channel_ctx(struct PeerContext *peer_ctx) | 938 | add_channel_ctx (struct PeerContext *peer_ctx) |
930 | { | 939 | { |
931 | struct ChannelCtx *channel_ctx; | 940 | struct ChannelCtx *channel_ctx; |
932 | 941 | ||
933 | channel_ctx = GNUNET_new(struct ChannelCtx); | 942 | channel_ctx = GNUNET_new (struct ChannelCtx); |
934 | channel_ctx->peer_ctx = peer_ctx; | 943 | channel_ctx->peer_ctx = peer_ctx; |
935 | return channel_ctx; | 944 | return channel_ctx; |
936 | } | 945 | } |
@@ -942,29 +951,29 @@ add_channel_ctx(struct PeerContext *peer_ctx) | |||
942 | * @param channel_ctx The channel context. | 951 | * @param channel_ctx The channel context. |
943 | */ | 952 | */ |
944 | static void | 953 | static void |
945 | remove_channel_ctx(struct ChannelCtx *channel_ctx) | 954 | remove_channel_ctx (struct ChannelCtx *channel_ctx) |
946 | { | 955 | { |
947 | struct PeerContext *peer_ctx = channel_ctx->peer_ctx; | 956 | struct PeerContext *peer_ctx = channel_ctx->peer_ctx; |
948 | 957 | ||
949 | if (NULL != channel_ctx->destruction_task) | 958 | if (NULL != channel_ctx->destruction_task) |
950 | { | 959 | { |
951 | GNUNET_SCHEDULER_cancel(channel_ctx->destruction_task); | 960 | GNUNET_SCHEDULER_cancel (channel_ctx->destruction_task); |
952 | channel_ctx->destruction_task = NULL; | 961 | channel_ctx->destruction_task = NULL; |
953 | } | 962 | } |
954 | 963 | ||
955 | GNUNET_free(channel_ctx); | 964 | GNUNET_free (channel_ctx); |
956 | 965 | ||
957 | if (NULL == peer_ctx) | 966 | if (NULL == peer_ctx) |
958 | return; | 967 | return; |
959 | if (channel_ctx == peer_ctx->send_channel_ctx) | 968 | if (channel_ctx == peer_ctx->send_channel_ctx) |
960 | { | 969 | { |
961 | peer_ctx->send_channel_ctx = NULL; | 970 | peer_ctx->send_channel_ctx = NULL; |
962 | peer_ctx->mq = NULL; | 971 | peer_ctx->mq = NULL; |
963 | } | 972 | } |
964 | else if (channel_ctx == peer_ctx->recv_channel_ctx) | 973 | else if (channel_ctx == peer_ctx->recv_channel_ctx) |
965 | { | 974 | { |
966 | peer_ctx->recv_channel_ctx = NULL; | 975 | peer_ctx->recv_channel_ctx = NULL; |
967 | } | 976 | } |
968 | } | 977 | } |
969 | 978 | ||
970 | 979 | ||
@@ -975,47 +984,47 @@ remove_channel_ctx(struct ChannelCtx *channel_ctx) | |||
975 | * @return the #GNUNET_CADET_Channel used to send data to @a peer_ctx | 984 | * @return the #GNUNET_CADET_Channel used to send data to @a peer_ctx |
976 | */ | 985 | */ |
977 | struct GNUNET_CADET_Channel * | 986 | struct GNUNET_CADET_Channel * |
978 | get_channel(struct PeerContext *peer_ctx) | 987 | get_channel (struct PeerContext *peer_ctx) |
979 | { | 988 | { |
980 | /* There exists a copy-paste-clone in run() */ | 989 | /* There exists a copy-paste-clone in run() */ |
981 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = { | 990 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = { |
982 | GNUNET_MQ_hd_fixed_size(peer_check, | 991 | GNUNET_MQ_hd_fixed_size (peer_check, |
983 | GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE, | 992 | GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE, |
984 | struct GNUNET_MessageHeader, | 993 | struct GNUNET_MessageHeader, |
985 | NULL), | 994 | NULL), |
986 | GNUNET_MQ_hd_fixed_size(peer_push, | 995 | GNUNET_MQ_hd_fixed_size (peer_push, |
987 | GNUNET_MESSAGE_TYPE_RPS_PP_PUSH, | 996 | GNUNET_MESSAGE_TYPE_RPS_PP_PUSH, |
988 | struct GNUNET_MessageHeader, | 997 | struct GNUNET_MessageHeader, |
989 | NULL), | 998 | NULL), |
990 | GNUNET_MQ_hd_fixed_size(peer_pull_request, | 999 | GNUNET_MQ_hd_fixed_size (peer_pull_request, |
991 | GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST, | 1000 | GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST, |
992 | struct GNUNET_MessageHeader, | 1001 | struct GNUNET_MessageHeader, |
993 | NULL), | 1002 | NULL), |
994 | GNUNET_MQ_hd_var_size(peer_pull_reply, | 1003 | GNUNET_MQ_hd_var_size (peer_pull_reply, |
995 | GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY, | 1004 | GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY, |
996 | struct GNUNET_RPS_P2P_PullReplyMessage, | 1005 | struct GNUNET_RPS_P2P_PullReplyMessage, |
997 | NULL), | 1006 | NULL), |
998 | GNUNET_MQ_handler_end() | 1007 | GNUNET_MQ_handler_end () |
999 | }; | 1008 | }; |
1000 | 1009 | ||
1001 | 1010 | ||
1002 | if (NULL == peer_ctx->send_channel_ctx) | 1011 | if (NULL == peer_ctx->send_channel_ctx) |
1003 | { | 1012 | { |
1004 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1013 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1005 | "Trying to establish channel to peer %s\n", | 1014 | "Trying to establish channel to peer %s\n", |
1006 | GNUNET_i2s(&peer_ctx->peer_id)); | 1015 | GNUNET_i2s (&peer_ctx->peer_id)); |
1007 | peer_ctx->send_channel_ctx = add_channel_ctx(peer_ctx); | 1016 | peer_ctx->send_channel_ctx = add_channel_ctx (peer_ctx); |
1008 | peer_ctx->send_channel_ctx->channel = | 1017 | peer_ctx->send_channel_ctx->channel = |
1009 | GNUNET_CADET_channel_create(cadet_handle, | 1018 | GNUNET_CADET_channel_create (cadet_handle, |
1010 | peer_ctx->send_channel_ctx, /* context */ | 1019 | peer_ctx->send_channel_ctx, /* context */ |
1011 | &peer_ctx->peer_id, | 1020 | &peer_ctx->peer_id, |
1012 | &peer_ctx->sub->hash, | 1021 | &peer_ctx->sub->hash, |
1013 | NULL, /* WindowSize handler */ | 1022 | NULL, /* WindowSize handler */ |
1014 | &cleanup_destroyed_channel, /* Disconnect handler */ | 1023 | &cleanup_destroyed_channel, /* Disconnect handler */ |
1015 | cadet_handlers); | 1024 | cadet_handlers); |
1016 | } | 1025 | } |
1017 | GNUNET_assert(NULL != peer_ctx->send_channel_ctx); | 1026 | GNUNET_assert (NULL != peer_ctx->send_channel_ctx); |
1018 | GNUNET_assert(NULL != peer_ctx->send_channel_ctx->channel); | 1027 | GNUNET_assert (NULL != peer_ctx->send_channel_ctx->channel); |
1019 | return peer_ctx->send_channel_ctx->channel; | 1028 | return peer_ctx->send_channel_ctx->channel; |
1020 | } | 1029 | } |
1021 | 1030 | ||
@@ -1030,12 +1039,12 @@ get_channel(struct PeerContext *peer_ctx) | |||
1030 | * @return the #GNUNET_MQ_Handle | 1039 | * @return the #GNUNET_MQ_Handle |
1031 | */ | 1040 | */ |
1032 | static struct GNUNET_MQ_Handle * | 1041 | static struct GNUNET_MQ_Handle * |
1033 | get_mq(struct PeerContext *peer_ctx) | 1042 | get_mq (struct PeerContext *peer_ctx) |
1034 | { | 1043 | { |
1035 | if (NULL == peer_ctx->mq) | 1044 | if (NULL == peer_ctx->mq) |
1036 | { | 1045 | { |
1037 | peer_ctx->mq = GNUNET_CADET_get_mq(get_channel(peer_ctx)); | 1046 | peer_ctx->mq = GNUNET_CADET_get_mq (get_channel (peer_ctx)); |
1038 | } | 1047 | } |
1039 | return peer_ctx->mq; | 1048 | return peer_ctx->mq; |
1040 | } | 1049 | } |
1041 | 1050 | ||
@@ -1048,19 +1057,19 @@ get_mq(struct PeerContext *peer_ctx) | |||
1048 | * @return pointer to pending message | 1057 | * @return pointer to pending message |
1049 | */ | 1058 | */ |
1050 | static struct PendingMessage * | 1059 | static struct PendingMessage * |
1051 | insert_pending_message(struct PeerContext *peer_ctx, | 1060 | insert_pending_message (struct PeerContext *peer_ctx, |
1052 | struct GNUNET_MQ_Envelope *ev, | 1061 | struct GNUNET_MQ_Envelope *ev, |
1053 | const char *type) | 1062 | const char *type) |
1054 | { | 1063 | { |
1055 | struct PendingMessage *pending_msg; | 1064 | struct PendingMessage *pending_msg; |
1056 | 1065 | ||
1057 | pending_msg = GNUNET_new(struct PendingMessage); | 1066 | pending_msg = GNUNET_new (struct PendingMessage); |
1058 | pending_msg->ev = ev; | 1067 | pending_msg->ev = ev; |
1059 | pending_msg->peer_ctx = peer_ctx; | 1068 | pending_msg->peer_ctx = peer_ctx; |
1060 | pending_msg->type = type; | 1069 | pending_msg->type = type; |
1061 | GNUNET_CONTAINER_DLL_insert(peer_ctx->pending_messages_head, | 1070 | GNUNET_CONTAINER_DLL_insert (peer_ctx->pending_messages_head, |
1062 | peer_ctx->pending_messages_tail, | 1071 | peer_ctx->pending_messages_tail, |
1063 | pending_msg); | 1072 | pending_msg); |
1064 | return pending_msg; | 1073 | return pending_msg; |
1065 | } | 1074 | } |
1066 | 1075 | ||
@@ -1072,23 +1081,23 @@ insert_pending_message(struct PeerContext *peer_ctx, | |||
1072 | * @param cancel whether to cancel the pending message, too | 1081 | * @param cancel whether to cancel the pending message, too |
1073 | */ | 1082 | */ |
1074 | static void | 1083 | static void |
1075 | remove_pending_message(struct PendingMessage *pending_msg, int cancel) | 1084 | remove_pending_message (struct PendingMessage *pending_msg, int cancel) |
1076 | { | 1085 | { |
1077 | struct PeerContext *peer_ctx; | 1086 | struct PeerContext *peer_ctx; |
1078 | 1087 | ||
1079 | (void)cancel; | 1088 | (void) cancel; |
1080 | 1089 | ||
1081 | peer_ctx = pending_msg->peer_ctx; | 1090 | peer_ctx = pending_msg->peer_ctx; |
1082 | GNUNET_assert(NULL != peer_ctx); | 1091 | GNUNET_assert (NULL != peer_ctx); |
1083 | GNUNET_CONTAINER_DLL_remove(peer_ctx->pending_messages_head, | 1092 | GNUNET_CONTAINER_DLL_remove (peer_ctx->pending_messages_head, |
1084 | peer_ctx->pending_messages_tail, | 1093 | peer_ctx->pending_messages_tail, |
1085 | pending_msg); | 1094 | pending_msg); |
1086 | // TODO wait for the cadet implementation of message cancellation | 1095 | // TODO wait for the cadet implementation of message cancellation |
1087 | //if (GNUNET_YES == cancel) | 1096 | // if (GNUNET_YES == cancel) |
1088 | //{ | 1097 | // { |
1089 | // GNUNET_MQ_send_cancel (pending_msg->ev); | 1098 | // GNUNET_MQ_send_cancel (pending_msg->ev); |
1090 | //} | 1099 | // } |
1091 | GNUNET_free(pending_msg); | 1100 | GNUNET_free (pending_msg); |
1092 | } | 1101 | } |
1093 | 1102 | ||
1094 | 1103 | ||
@@ -1099,20 +1108,20 @@ remove_pending_message(struct PendingMessage *pending_msg, int cancel) | |||
1099 | * @param cls #PeerContext of peer with pending online check | 1108 | * @param cls #PeerContext of peer with pending online check |
1100 | */ | 1109 | */ |
1101 | static void | 1110 | static void |
1102 | mq_online_check_successful(void *cls) | 1111 | mq_online_check_successful (void *cls) |
1103 | { | 1112 | { |
1104 | struct PeerContext *peer_ctx = cls; | 1113 | struct PeerContext *peer_ctx = cls; |
1105 | 1114 | ||
1106 | if (NULL != peer_ctx->online_check_pending) | 1115 | if (NULL != peer_ctx->online_check_pending) |
1107 | { | 1116 | { |
1108 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1117 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1109 | "Online check for peer %s was successfull\n", | 1118 | "Online check for peer %s was successfull\n", |
1110 | GNUNET_i2s(&peer_ctx->peer_id)); | 1119 | GNUNET_i2s (&peer_ctx->peer_id)); |
1111 | remove_pending_message(peer_ctx->online_check_pending, GNUNET_YES); | 1120 | remove_pending_message (peer_ctx->online_check_pending, GNUNET_YES); |
1112 | peer_ctx->online_check_pending = NULL; | 1121 | peer_ctx->online_check_pending = NULL; |
1113 | set_peer_online(peer_ctx); | 1122 | set_peer_online (peer_ctx); |
1114 | (void)add_valid_peer(&peer_ctx->peer_id, peer_ctx->sub->valid_peers); | 1123 | (void) add_valid_peer (&peer_ctx->peer_id, peer_ctx->sub->valid_peers); |
1115 | } | 1124 | } |
1116 | } | 1125 | } |
1117 | 1126 | ||
1118 | /** | 1127 | /** |
@@ -1121,30 +1130,30 @@ mq_online_check_successful(void *cls) | |||
1121 | * @param peer_ctx the context of the peer | 1130 | * @param peer_ctx the context of the peer |
1122 | */ | 1131 | */ |
1123 | static void | 1132 | static void |
1124 | check_peer_online(struct PeerContext *peer_ctx) | 1133 | check_peer_online (struct PeerContext *peer_ctx) |
1125 | { | 1134 | { |
1126 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1135 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1127 | "Get informed about peer %s getting online\n", | 1136 | "Get informed about peer %s getting online\n", |
1128 | GNUNET_i2s(&peer_ctx->peer_id)); | 1137 | GNUNET_i2s (&peer_ctx->peer_id)); |
1129 | 1138 | ||
1130 | struct GNUNET_MQ_Handle *mq; | 1139 | struct GNUNET_MQ_Handle *mq; |
1131 | struct GNUNET_MQ_Envelope *ev; | 1140 | struct GNUNET_MQ_Envelope *ev; |
1132 | 1141 | ||
1133 | ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE); | 1142 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE); |
1134 | peer_ctx->online_check_pending = | 1143 | peer_ctx->online_check_pending = |
1135 | insert_pending_message(peer_ctx, ev, "Check online"); | 1144 | insert_pending_message (peer_ctx, ev, "Check online"); |
1136 | mq = get_mq(peer_ctx); | 1145 | mq = get_mq (peer_ctx); |
1137 | GNUNET_MQ_notify_sent(ev, | 1146 | GNUNET_MQ_notify_sent (ev, |
1138 | mq_online_check_successful, | 1147 | mq_online_check_successful, |
1139 | peer_ctx); | 1148 | peer_ctx); |
1140 | GNUNET_MQ_send(mq, ev); | 1149 | GNUNET_MQ_send (mq, ev); |
1141 | if (peer_ctx->sub == msub) | 1150 | if (peer_ctx->sub == msub) |
1142 | { | 1151 | { |
1143 | GNUNET_STATISTICS_update(stats, | 1152 | GNUNET_STATISTICS_update (stats, |
1144 | "# pending online checks", | 1153 | "# pending online checks", |
1145 | 1, | 1154 | 1, |
1146 | GNUNET_NO); | 1155 | GNUNET_NO); |
1147 | } | 1156 | } |
1148 | } | 1157 | } |
1149 | 1158 | ||
1150 | 1159 | ||
@@ -1161,8 +1170,8 @@ check_peer_online(struct PeerContext *peer_ctx) | |||
1161 | * #GNUNET_NO otherwise | 1170 | * #GNUNET_NO otherwise |
1162 | */ | 1171 | */ |
1163 | static int | 1172 | static int |
1164 | check_operation_scheduled(const struct PeerContext *peer_ctx, | 1173 | check_operation_scheduled (const struct PeerContext *peer_ctx, |
1165 | const PeerOp peer_op) | 1174 | const PeerOp peer_op) |
1166 | { | 1175 | { |
1167 | unsigned int i; | 1176 | unsigned int i; |
1168 | 1177 | ||
@@ -1179,20 +1188,20 @@ check_operation_scheduled(const struct PeerContext *peer_ctx, | |||
1179 | * @param cls Context of the channel | 1188 | * @param cls Context of the channel |
1180 | */ | 1189 | */ |
1181 | static void | 1190 | static void |
1182 | destroy_channel(struct ChannelCtx *channel_ctx) | 1191 | destroy_channel (struct ChannelCtx *channel_ctx) |
1183 | { | 1192 | { |
1184 | struct GNUNET_CADET_Channel *channel; | 1193 | struct GNUNET_CADET_Channel *channel; |
1185 | 1194 | ||
1186 | if (NULL != channel_ctx->destruction_task) | 1195 | if (NULL != channel_ctx->destruction_task) |
1187 | { | 1196 | { |
1188 | GNUNET_SCHEDULER_cancel(channel_ctx->destruction_task); | 1197 | GNUNET_SCHEDULER_cancel (channel_ctx->destruction_task); |
1189 | channel_ctx->destruction_task = NULL; | 1198 | channel_ctx->destruction_task = NULL; |
1190 | } | 1199 | } |
1191 | GNUNET_assert(channel_ctx->channel != NULL); | 1200 | GNUNET_assert (channel_ctx->channel != NULL); |
1192 | channel = channel_ctx->channel; | 1201 | channel = channel_ctx->channel; |
1193 | channel_ctx->channel = NULL; | 1202 | channel_ctx->channel = NULL; |
1194 | GNUNET_CADET_channel_destroy(channel); | 1203 | GNUNET_CADET_channel_destroy (channel); |
1195 | remove_channel_ctx(channel_ctx); | 1204 | remove_channel_ctx (channel_ctx); |
1196 | } | 1205 | } |
1197 | 1206 | ||
1198 | 1207 | ||
@@ -1204,12 +1213,12 @@ destroy_channel(struct ChannelCtx *channel_ctx) | |||
1204 | * @param cls | 1213 | * @param cls |
1205 | */ | 1214 | */ |
1206 | static void | 1215 | static void |
1207 | destroy_channel_cb(void *cls) | 1216 | destroy_channel_cb (void *cls) |
1208 | { | 1217 | { |
1209 | struct ChannelCtx *channel_ctx = cls; | 1218 | struct ChannelCtx *channel_ctx = cls; |
1210 | 1219 | ||
1211 | channel_ctx->destruction_task = NULL; | 1220 | channel_ctx->destruction_task = NULL; |
1212 | destroy_channel(channel_ctx); | 1221 | destroy_channel (channel_ctx); |
1213 | } | 1222 | } |
1214 | 1223 | ||
1215 | 1224 | ||
@@ -1224,15 +1233,15 @@ destroy_channel_cb(void *cls) | |||
1224 | * @param channel_ctx channel to be destroyed. | 1233 | * @param channel_ctx channel to be destroyed. |
1225 | */ | 1234 | */ |
1226 | static void | 1235 | static void |
1227 | schedule_channel_destruction(struct ChannelCtx *channel_ctx) | 1236 | schedule_channel_destruction (struct ChannelCtx *channel_ctx) |
1228 | { | 1237 | { |
1229 | GNUNET_assert(NULL == | 1238 | GNUNET_assert (NULL == |
1230 | channel_ctx->destruction_task); | 1239 | channel_ctx->destruction_task); |
1231 | GNUNET_assert(NULL != | 1240 | GNUNET_assert (NULL != |
1232 | channel_ctx->channel); | 1241 | channel_ctx->channel); |
1233 | channel_ctx->destruction_task = | 1242 | channel_ctx->destruction_task = |
1234 | GNUNET_SCHEDULER_add_now(&destroy_channel_cb, | 1243 | GNUNET_SCHEDULER_add_now (&destroy_channel_cb, |
1235 | channel_ctx); | 1244 | channel_ctx); |
1236 | } | 1245 | } |
1237 | 1246 | ||
1238 | 1247 | ||
@@ -1250,98 +1259,99 @@ schedule_channel_destruction(struct ChannelCtx *channel_ctx) | |||
1250 | * #GNUNET_NO otherwise | 1259 | * #GNUNET_NO otherwise |
1251 | */ | 1260 | */ |
1252 | static int | 1261 | static int |
1253 | destroy_peer(struct PeerContext *peer_ctx) | 1262 | destroy_peer (struct PeerContext *peer_ctx) |
1254 | { | 1263 | { |
1255 | GNUNET_assert(NULL != peer_ctx); | 1264 | GNUNET_assert (NULL != peer_ctx); |
1256 | GNUNET_assert(NULL != peer_ctx->sub->peer_map); | 1265 | GNUNET_assert (NULL != peer_ctx->sub->peer_map); |
1257 | if (GNUNET_NO == | 1266 | if (GNUNET_NO == |
1258 | GNUNET_CONTAINER_multipeermap_contains(peer_ctx->sub->peer_map, | 1267 | GNUNET_CONTAINER_multipeermap_contains (peer_ctx->sub->peer_map, |
1259 | &peer_ctx->peer_id)) | 1268 | &peer_ctx->peer_id)) |
1260 | { | 1269 | { |
1261 | return GNUNET_NO; | 1270 | return GNUNET_NO; |
1262 | } | 1271 | } |
1263 | SET_PEER_FLAG(peer_ctx, Peers_TO_DESTROY); | 1272 | SET_PEER_FLAG (peer_ctx, Peers_TO_DESTROY); |
1264 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1273 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1265 | "Going to remove peer %s\n", | 1274 | "Going to remove peer %s\n", |
1266 | GNUNET_i2s(&peer_ctx->peer_id)); | 1275 | GNUNET_i2s (&peer_ctx->peer_id)); |
1267 | UNSET_PEER_FLAG(peer_ctx, Peers_ONLINE); | 1276 | UNSET_PEER_FLAG (peer_ctx, Peers_ONLINE); |
1268 | 1277 | ||
1269 | /* Clear list of pending operations */ | 1278 | /* Clear list of pending operations */ |
1270 | // TODO this probably leaks memory | 1279 | // TODO this probably leaks memory |
1271 | // ('only' the cls to the function. Not sure what to do with it) | 1280 | // ('only' the cls to the function. Not sure what to do with it) |
1272 | GNUNET_array_grow(peer_ctx->pending_ops, | 1281 | GNUNET_array_grow (peer_ctx->pending_ops, |
1273 | peer_ctx->num_pending_ops, | 1282 | peer_ctx->num_pending_ops, |
1274 | 0); | 1283 | 0); |
1275 | /* Remove all pending messages */ | 1284 | /* Remove all pending messages */ |
1276 | while (NULL != peer_ctx->pending_messages_head) | 1285 | while (NULL != peer_ctx->pending_messages_head) |
1286 | { | ||
1287 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1288 | "Removing unsent %s\n", | ||
1289 | peer_ctx->pending_messages_head->type); | ||
1290 | /* Cancle pending message, too */ | ||
1291 | if ((NULL != peer_ctx->online_check_pending) && | ||
1292 | (0 == memcmp (peer_ctx->pending_messages_head, | ||
1293 | peer_ctx->online_check_pending, | ||
1294 | sizeof(struct PendingMessage)))) | ||
1277 | { | 1295 | { |
1278 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1296 | peer_ctx->online_check_pending = NULL; |
1279 | "Removing unsent %s\n", | 1297 | if (peer_ctx->sub == msub) |
1280 | peer_ctx->pending_messages_head->type); | 1298 | { |
1281 | /* Cancle pending message, too */ | 1299 | GNUNET_STATISTICS_update (stats, |
1282 | if ((NULL != peer_ctx->online_check_pending) && | 1300 | "# pending online checks", |
1283 | (0 == memcmp(peer_ctx->pending_messages_head, | 1301 | -1, |
1284 | peer_ctx->online_check_pending, | 1302 | GNUNET_NO); |
1285 | sizeof(struct PendingMessage)))) | 1303 | } |
1286 | { | 1304 | } |
1287 | peer_ctx->online_check_pending = NULL; | 1305 | remove_pending_message (peer_ctx->pending_messages_head, |
1288 | if (peer_ctx->sub == msub) | 1306 | GNUNET_YES); |
1289 | { | 1307 | } |
1290 | GNUNET_STATISTICS_update(stats, | ||
1291 | "# pending online checks", | ||
1292 | -1, | ||
1293 | GNUNET_NO); | ||
1294 | } | ||
1295 | } | ||
1296 | remove_pending_message(peer_ctx->pending_messages_head, | ||
1297 | GNUNET_YES); | ||
1298 | } | ||
1299 | 1308 | ||
1300 | /* If we are still waiting for notification whether this peer is online | 1309 | /* If we are still waiting for notification whether this peer is online |
1301 | * cancel the according task */ | 1310 | * cancel the according task */ |
1302 | if (NULL != peer_ctx->online_check_pending) | 1311 | if (NULL != peer_ctx->online_check_pending) |
1303 | { | 1312 | { |
1304 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1313 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1305 | "Removing pending online check for peer %s\n", | 1314 | "Removing pending online check for peer %s\n", |
1306 | GNUNET_i2s(&peer_ctx->peer_id)); | 1315 | GNUNET_i2s (&peer_ctx->peer_id)); |
1307 | // TODO wait until cadet sets mq->cancel_impl | 1316 | // TODO wait until cadet sets mq->cancel_impl |
1308 | //GNUNET_MQ_send_cancel (peer_ctx->online_check_pending->ev); | 1317 | // GNUNET_MQ_send_cancel (peer_ctx->online_check_pending->ev); |
1309 | remove_pending_message(peer_ctx->online_check_pending, | 1318 | remove_pending_message (peer_ctx->online_check_pending, |
1310 | GNUNET_YES); | 1319 | GNUNET_YES); |
1311 | peer_ctx->online_check_pending = NULL; | 1320 | peer_ctx->online_check_pending = NULL; |
1312 | } | 1321 | } |
1313 | 1322 | ||
1314 | if (NULL != peer_ctx->send_channel_ctx) | 1323 | if (NULL != peer_ctx->send_channel_ctx) |
1315 | { | 1324 | { |
1316 | /* This is possibly called from within channel destruction */ | 1325 | /* This is possibly called from within channel destruction */ |
1317 | peer_ctx->send_channel_ctx->peer_ctx = NULL; | 1326 | peer_ctx->send_channel_ctx->peer_ctx = NULL; |
1318 | schedule_channel_destruction(peer_ctx->send_channel_ctx); | 1327 | schedule_channel_destruction (peer_ctx->send_channel_ctx); |
1319 | peer_ctx->send_channel_ctx = NULL; | 1328 | peer_ctx->send_channel_ctx = NULL; |
1320 | peer_ctx->mq = NULL; | 1329 | peer_ctx->mq = NULL; |
1321 | } | 1330 | } |
1322 | if (NULL != peer_ctx->recv_channel_ctx) | 1331 | if (NULL != peer_ctx->recv_channel_ctx) |
1323 | { | 1332 | { |
1324 | /* This is possibly called from within channel destruction */ | 1333 | /* This is possibly called from within channel destruction */ |
1325 | peer_ctx->recv_channel_ctx->peer_ctx = NULL; | 1334 | peer_ctx->recv_channel_ctx->peer_ctx = NULL; |
1326 | schedule_channel_destruction(peer_ctx->recv_channel_ctx); | 1335 | schedule_channel_destruction (peer_ctx->recv_channel_ctx); |
1327 | peer_ctx->recv_channel_ctx = NULL; | 1336 | peer_ctx->recv_channel_ctx = NULL; |
1328 | } | 1337 | } |
1329 | 1338 | ||
1330 | if (GNUNET_YES != | 1339 | if (GNUNET_YES != |
1331 | GNUNET_CONTAINER_multipeermap_remove_all(peer_ctx->sub->peer_map, | 1340 | GNUNET_CONTAINER_multipeermap_remove_all (peer_ctx->sub->peer_map, |
1332 | &peer_ctx->peer_id)) | 1341 | &peer_ctx->peer_id)) |
1333 | { | 1342 | { |
1334 | LOG(GNUNET_ERROR_TYPE_WARNING, | 1343 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1335 | "removing peer from peer_ctx->sub->peer_map failed\n"); | 1344 | "removing peer from peer_ctx->sub->peer_map failed\n"); |
1336 | } | 1345 | } |
1337 | if (peer_ctx->sub == msub) | 1346 | if (peer_ctx->sub == msub) |
1338 | { | 1347 | { |
1339 | GNUNET_STATISTICS_set(stats, | 1348 | GNUNET_STATISTICS_set (stats, |
1340 | "# known peers", | 1349 | "# known peers", |
1341 | GNUNET_CONTAINER_multipeermap_size(peer_ctx->sub->peer_map), | 1350 | GNUNET_CONTAINER_multipeermap_size ( |
1342 | GNUNET_NO); | 1351 | peer_ctx->sub->peer_map), |
1343 | } | 1352 | GNUNET_NO); |
1344 | GNUNET_free(peer_ctx); | 1353 | } |
1354 | GNUNET_free (peer_ctx); | ||
1345 | return GNUNET_YES; | 1355 | return GNUNET_YES; |
1346 | } | 1356 | } |
1347 | 1357 | ||
@@ -1356,15 +1366,15 @@ destroy_peer(struct PeerContext *peer_ctx) | |||
1356 | * #GNUNET_NO if not. | 1366 | * #GNUNET_NO if not. |
1357 | */ | 1367 | */ |
1358 | static int | 1368 | static int |
1359 | peermap_clear_iterator(void *cls, | 1369 | peermap_clear_iterator (void *cls, |
1360 | const struct GNUNET_PeerIdentity *key, | 1370 | const struct GNUNET_PeerIdentity *key, |
1361 | void *value) | 1371 | void *value) |
1362 | { | 1372 | { |
1363 | struct Sub *sub = cls; | 1373 | struct Sub *sub = cls; |
1364 | 1374 | ||
1365 | (void)value; | 1375 | (void) value; |
1366 | 1376 | ||
1367 | destroy_peer(get_peer_ctx(sub->peer_map, key)); | 1377 | destroy_peer (get_peer_ctx (sub->peer_map, key)); |
1368 | return GNUNET_YES; | 1378 | return GNUNET_YES; |
1369 | } | 1379 | } |
1370 | 1380 | ||
@@ -1377,32 +1387,33 @@ peermap_clear_iterator(void *cls, | |||
1377 | * @param cls type of the message that was sent | 1387 | * @param cls type of the message that was sent |
1378 | */ | 1388 | */ |
1379 | static void | 1389 | static void |
1380 | mq_notify_sent_cb(void *cls) | 1390 | mq_notify_sent_cb (void *cls) |
1381 | { | 1391 | { |
1382 | struct PendingMessage *pending_msg = (struct PendingMessage *)cls; | 1392 | struct PendingMessage *pending_msg = (struct PendingMessage *) cls; |
1383 | 1393 | ||
1384 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1394 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1385 | "%s was sent.\n", | 1395 | "%s was sent.\n", |
1386 | pending_msg->type); | 1396 | pending_msg->type); |
1387 | if (pending_msg->peer_ctx->sub == msub) | 1397 | if (pending_msg->peer_ctx->sub == msub) |
1388 | { | 1398 | { |
1389 | if (0 == strncmp("PULL REPLY", pending_msg->type, 10)) | 1399 | if (0 == strncmp ("PULL REPLY", pending_msg->type, 10)) |
1390 | GNUNET_STATISTICS_update(stats, "# pull replys sent", 1, GNUNET_NO); | 1400 | GNUNET_STATISTICS_update (stats, "# pull replys sent", 1, GNUNET_NO); |
1391 | if (0 == strncmp("PULL REQUEST", pending_msg->type, 12)) | 1401 | if (0 == strncmp ("PULL REQUEST", pending_msg->type, 12)) |
1392 | GNUNET_STATISTICS_update(stats, "# pull requests sent", 1, GNUNET_NO); | 1402 | GNUNET_STATISTICS_update (stats, "# pull requests sent", 1, GNUNET_NO); |
1393 | if (0 == strncmp("PUSH", pending_msg->type, 4)) | 1403 | if (0 == strncmp ("PUSH", pending_msg->type, 4)) |
1394 | GNUNET_STATISTICS_update(stats, "# pushes sent", 1, GNUNET_NO); | 1404 | GNUNET_STATISTICS_update (stats, "# pushes sent", 1, GNUNET_NO); |
1395 | if (0 == strncmp("PULL REQUEST", pending_msg->type, 12) && | 1405 | if ((0 == strncmp ("PULL REQUEST", pending_msg->type, 12)) && |
1396 | NULL != map_single_hop && | 1406 | (NULL != map_single_hop) && |
1397 | GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(map_single_hop, | 1407 | (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (map_single_hop, |
1398 | &pending_msg->peer_ctx->peer_id)) | 1408 | &pending_msg-> |
1399 | GNUNET_STATISTICS_update(stats, | 1409 | peer_ctx->peer_id)) ) |
1400 | "# pull requests sent (multi-hop peer)", | 1410 | GNUNET_STATISTICS_update (stats, |
1401 | 1, | 1411 | "# pull requests sent (multi-hop peer)", |
1402 | GNUNET_NO); | 1412 | 1, |
1403 | } | 1413 | GNUNET_NO); |
1414 | } | ||
1404 | /* Do not cancle message */ | 1415 | /* Do not cancle message */ |
1405 | remove_pending_message(pending_msg, GNUNET_NO); | 1416 | remove_pending_message (pending_msg, GNUNET_NO); |
1406 | } | 1417 | } |
1407 | 1418 | ||
1408 | 1419 | ||
@@ -1421,30 +1432,30 @@ mq_notify_sent_cb(void *cls) | |||
1421 | * #GNUNET_NO if not. | 1432 | * #GNUNET_NO if not. |
1422 | */ | 1433 | */ |
1423 | static int | 1434 | static int |
1424 | store_peer_presistently_iterator(void *cls, | 1435 | store_peer_presistently_iterator (void *cls, |
1425 | const struct GNUNET_PeerIdentity *peer, | 1436 | const struct GNUNET_PeerIdentity *peer, |
1426 | void *value) | 1437 | void *value) |
1427 | { | 1438 | { |
1428 | const struct GNUNET_DISK_FileHandle *fh = cls; | 1439 | const struct GNUNET_DISK_FileHandle *fh = cls; |
1429 | char peer_string[128]; | 1440 | char peer_string[128]; |
1430 | int size; | 1441 | int size; |
1431 | ssize_t ret; | 1442 | ssize_t ret; |
1432 | 1443 | ||
1433 | (void)value; | 1444 | (void) value; |
1434 | 1445 | ||
1435 | if (NULL == peer) | 1446 | if (NULL == peer) |
1436 | { | 1447 | { |
1437 | return GNUNET_YES; | 1448 | return GNUNET_YES; |
1438 | } | 1449 | } |
1439 | size = GNUNET_snprintf(peer_string, | 1450 | size = GNUNET_snprintf (peer_string, |
1440 | sizeof(peer_string), | 1451 | sizeof(peer_string), |
1441 | "%s\n", | 1452 | "%s\n", |
1442 | GNUNET_i2s_full(peer)); | 1453 | GNUNET_i2s_full (peer)); |
1443 | GNUNET_assert(53 == size); | 1454 | GNUNET_assert (53 == size); |
1444 | ret = GNUNET_DISK_file_write(fh, | 1455 | ret = GNUNET_DISK_file_write (fh, |
1445 | peer_string, | 1456 | peer_string, |
1446 | size); | 1457 | size); |
1447 | GNUNET_assert(size == ret); | 1458 | GNUNET_assert (size == ret); |
1448 | return GNUNET_YES; | 1459 | return GNUNET_YES; |
1449 | } | 1460 | } |
1450 | 1461 | ||
@@ -1455,54 +1466,54 @@ store_peer_presistently_iterator(void *cls, | |||
1455 | * @param sub Sub for which to store the valid peers | 1466 | * @param sub Sub for which to store the valid peers |
1456 | */ | 1467 | */ |
1457 | static void | 1468 | static void |
1458 | store_valid_peers(const struct Sub *sub) | 1469 | store_valid_peers (const struct Sub *sub) |
1459 | { | 1470 | { |
1460 | struct GNUNET_DISK_FileHandle *fh; | 1471 | struct GNUNET_DISK_FileHandle *fh; |
1461 | uint32_t number_written_peers; | 1472 | uint32_t number_written_peers; |
1462 | int ret; | 1473 | int ret; |
1463 | 1474 | ||
1464 | if (0 == strncmp("DISABLE", sub->filename_valid_peers, 7)) | 1475 | if (0 == strncmp ("DISABLE", sub->filename_valid_peers, 7)) |
1465 | { | 1476 | { |
1466 | return; | 1477 | return; |
1467 | } | 1478 | } |
1468 | 1479 | ||
1469 | ret = GNUNET_DISK_directory_create_for_file(sub->filename_valid_peers); | 1480 | ret = GNUNET_DISK_directory_create_for_file (sub->filename_valid_peers); |
1470 | if (GNUNET_SYSERR == ret) | 1481 | if (GNUNET_SYSERR == ret) |
1471 | { | 1482 | { |
1472 | LOG(GNUNET_ERROR_TYPE_WARNING, | 1483 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1473 | "Not able to create directory for file `%s'\n", | 1484 | "Not able to create directory for file `%s'\n", |
1474 | sub->filename_valid_peers); | 1485 | sub->filename_valid_peers); |
1475 | GNUNET_break(0); | 1486 | GNUNET_break (0); |
1476 | } | 1487 | } |
1477 | else if (GNUNET_NO == ret) | 1488 | else if (GNUNET_NO == ret) |
1478 | { | 1489 | { |
1479 | LOG(GNUNET_ERROR_TYPE_WARNING, | 1490 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1480 | "Directory for file `%s' exists but is not writable for us\n", | 1491 | "Directory for file `%s' exists but is not writable for us\n", |
1481 | sub->filename_valid_peers); | 1492 | sub->filename_valid_peers); |
1482 | GNUNET_break(0); | 1493 | GNUNET_break (0); |
1483 | } | 1494 | } |
1484 | fh = GNUNET_DISK_file_open(sub->filename_valid_peers, | 1495 | fh = GNUNET_DISK_file_open (sub->filename_valid_peers, |
1485 | GNUNET_DISK_OPEN_WRITE | | 1496 | GNUNET_DISK_OPEN_WRITE |
1486 | GNUNET_DISK_OPEN_CREATE, | 1497 | | GNUNET_DISK_OPEN_CREATE, |
1487 | GNUNET_DISK_PERM_USER_READ | | 1498 | GNUNET_DISK_PERM_USER_READ |
1488 | GNUNET_DISK_PERM_USER_WRITE); | 1499 | | GNUNET_DISK_PERM_USER_WRITE); |
1489 | if (NULL == fh) | 1500 | if (NULL == fh) |
1490 | { | 1501 | { |
1491 | LOG(GNUNET_ERROR_TYPE_WARNING, | 1502 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1492 | "Not able to write valid peers to file `%s'\n", | 1503 | "Not able to write valid peers to file `%s'\n", |
1493 | sub->filename_valid_peers); | 1504 | sub->filename_valid_peers); |
1494 | return; | 1505 | return; |
1495 | } | 1506 | } |
1496 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1507 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1497 | "Writing %u valid peers to disk\n", | 1508 | "Writing %u valid peers to disk\n", |
1498 | GNUNET_CONTAINER_multipeermap_size(sub->valid_peers)); | 1509 | GNUNET_CONTAINER_multipeermap_size (sub->valid_peers)); |
1499 | number_written_peers = | 1510 | number_written_peers = |
1500 | GNUNET_CONTAINER_multipeermap_iterate(sub->valid_peers, | 1511 | GNUNET_CONTAINER_multipeermap_iterate (sub->valid_peers, |
1501 | store_peer_presistently_iterator, | 1512 | store_peer_presistently_iterator, |
1502 | fh); | 1513 | fh); |
1503 | GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fh)); | 1514 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); |
1504 | GNUNET_assert(number_written_peers == | 1515 | GNUNET_assert (number_written_peers == |
1505 | GNUNET_CONTAINER_multipeermap_size(sub->valid_peers)); | 1516 | GNUNET_CONTAINER_multipeermap_size (sub->valid_peers)); |
1506 | } | 1517 | } |
1507 | 1518 | ||
1508 | 1519 | ||
@@ -1516,38 +1527,38 @@ store_valid_peers(const struct Sub *sub) | |||
1516 | * @return The peer id | 1527 | * @return The peer id |
1517 | */ | 1528 | */ |
1518 | static const struct GNUNET_PeerIdentity * | 1529 | static const struct GNUNET_PeerIdentity * |
1519 | s2i_full(const char *string_repr) | 1530 | s2i_full (const char *string_repr) |
1520 | { | 1531 | { |
1521 | struct GNUNET_PeerIdentity *peer; | 1532 | struct GNUNET_PeerIdentity *peer; |
1522 | size_t len; | 1533 | size_t len; |
1523 | int ret; | 1534 | int ret; |
1524 | 1535 | ||
1525 | peer = GNUNET_new(struct GNUNET_PeerIdentity); | 1536 | peer = GNUNET_new (struct GNUNET_PeerIdentity); |
1526 | len = strlen(string_repr); | 1537 | len = strlen (string_repr); |
1527 | if (52 > len) | 1538 | if (52 > len) |
1528 | { | 1539 | { |
1529 | LOG(GNUNET_ERROR_TYPE_WARNING, | 1540 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1530 | "Not able to convert string representation of PeerID to PeerID\n" | 1541 | "Not able to convert string representation of PeerID to PeerID\n" |
1531 | "Sting representation: %s (len %lu) - too short\n", | 1542 | "Sting representation: %s (len %lu) - too short\n", |
1532 | string_repr, | 1543 | string_repr, |
1533 | len); | 1544 | len); |
1534 | GNUNET_break(0); | 1545 | GNUNET_break (0); |
1535 | } | 1546 | } |
1536 | else if (52 < len) | 1547 | else if (52 < len) |
1537 | { | 1548 | { |
1538 | len = 52; | 1549 | len = 52; |
1539 | } | 1550 | } |
1540 | ret = GNUNET_CRYPTO_eddsa_public_key_from_string(string_repr, | 1551 | ret = GNUNET_CRYPTO_eddsa_public_key_from_string (string_repr, |
1541 | len, | 1552 | len, |
1542 | &peer->public_key); | 1553 | &peer->public_key); |
1543 | if (GNUNET_OK != ret) | 1554 | if (GNUNET_OK != ret) |
1544 | { | 1555 | { |
1545 | LOG(GNUNET_ERROR_TYPE_WARNING, | 1556 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1546 | "Not able to convert string representation of PeerID to PeerID\n" | 1557 | "Not able to convert string representation of PeerID to PeerID\n" |
1547 | "Sting representation: %s\n", | 1558 | "Sting representation: %s\n", |
1548 | string_repr); | 1559 | string_repr); |
1549 | GNUNET_break(0); | 1560 | GNUNET_break (0); |
1550 | } | 1561 | } |
1551 | return peer; | 1562 | return peer; |
1552 | } | 1563 | } |
1553 | 1564 | ||
@@ -1558,7 +1569,7 @@ s2i_full(const char *string_repr) | |||
1558 | * @param sub Sub for which to restore the valid peers | 1569 | * @param sub Sub for which to restore the valid peers |
1559 | */ | 1570 | */ |
1560 | static void | 1571 | static void |
1561 | restore_valid_peers(const struct Sub *sub) | 1572 | restore_valid_peers (const struct Sub *sub) |
1562 | { | 1573 | { |
1563 | off_t file_size; | 1574 | off_t file_size; |
1564 | uint32_t num_peers; | 1575 | uint32_t num_peers; |
@@ -1569,53 +1580,53 @@ restore_valid_peers(const struct Sub *sub) | |||
1569 | char *str_repr; | 1580 | char *str_repr; |
1570 | const struct GNUNET_PeerIdentity *peer; | 1581 | const struct GNUNET_PeerIdentity *peer; |
1571 | 1582 | ||
1572 | if (0 == strncmp("DISABLE", sub->filename_valid_peers, 7)) | 1583 | if (0 == strncmp ("DISABLE", sub->filename_valid_peers, 7)) |
1573 | { | 1584 | { |
1574 | return; | 1585 | return; |
1575 | } | 1586 | } |
1576 | 1587 | ||
1577 | if (GNUNET_OK != GNUNET_DISK_file_test(sub->filename_valid_peers)) | 1588 | if (GNUNET_OK != GNUNET_DISK_file_test (sub->filename_valid_peers)) |
1578 | { | 1589 | { |
1579 | return; | 1590 | return; |
1580 | } | 1591 | } |
1581 | fh = GNUNET_DISK_file_open(sub->filename_valid_peers, | 1592 | fh = GNUNET_DISK_file_open (sub->filename_valid_peers, |
1582 | GNUNET_DISK_OPEN_READ, | 1593 | GNUNET_DISK_OPEN_READ, |
1583 | GNUNET_DISK_PERM_NONE); | 1594 | GNUNET_DISK_PERM_NONE); |
1584 | GNUNET_assert(NULL != fh); | 1595 | GNUNET_assert (NULL != fh); |
1585 | GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_handle_size(fh, &file_size)); | 1596 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_handle_size (fh, &file_size)); |
1586 | num_peers = file_size / 53; | 1597 | num_peers = file_size / 53; |
1587 | buf = GNUNET_malloc(file_size); | 1598 | buf = GNUNET_malloc (file_size); |
1588 | size_read = GNUNET_DISK_file_read(fh, buf, file_size); | 1599 | size_read = GNUNET_DISK_file_read (fh, buf, file_size); |
1589 | GNUNET_assert(size_read == file_size); | 1600 | GNUNET_assert (size_read == file_size); |
1590 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1601 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1591 | "Restoring %" PRIu32 " peers from file `%s'\n", | 1602 | "Restoring %" PRIu32 " peers from file `%s'\n", |
1592 | num_peers, | 1603 | num_peers, |
1593 | sub->filename_valid_peers); | 1604 | sub->filename_valid_peers); |
1594 | for (iter_buf = buf; iter_buf < buf + file_size - 1; iter_buf += 53) | 1605 | for (iter_buf = buf; iter_buf < buf + file_size - 1; iter_buf += 53) |
1595 | { | 1606 | { |
1596 | str_repr = GNUNET_strndup(iter_buf, 53); | 1607 | str_repr = GNUNET_strndup (iter_buf, 53); |
1597 | peer = s2i_full(str_repr); | 1608 | peer = s2i_full (str_repr); |
1598 | GNUNET_free(str_repr); | 1609 | GNUNET_free (str_repr); |
1599 | add_valid_peer(peer, sub->valid_peers); | 1610 | add_valid_peer (peer, sub->valid_peers); |
1600 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1611 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1601 | "Restored valid peer %s from disk\n", | 1612 | "Restored valid peer %s from disk\n", |
1602 | GNUNET_i2s_full(peer)); | 1613 | GNUNET_i2s_full (peer)); |
1603 | } | 1614 | } |
1604 | iter_buf = NULL; | 1615 | iter_buf = NULL; |
1605 | GNUNET_free(buf); | 1616 | GNUNET_free (buf); |
1606 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1617 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1607 | "num_peers: %" PRIu32 ", _size (sub->valid_peers): %u\n", | 1618 | "num_peers: %" PRIu32 ", _size (sub->valid_peers): %u\n", |
1608 | num_peers, | 1619 | num_peers, |
1609 | GNUNET_CONTAINER_multipeermap_size(sub->valid_peers)); | 1620 | GNUNET_CONTAINER_multipeermap_size (sub->valid_peers)); |
1610 | if (num_peers != GNUNET_CONTAINER_multipeermap_size(sub->valid_peers)) | 1621 | if (num_peers != GNUNET_CONTAINER_multipeermap_size (sub->valid_peers)) |
1611 | { | 1622 | { |
1612 | LOG(GNUNET_ERROR_TYPE_WARNING, | 1623 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1613 | "Number of restored peers does not match file size. Have probably duplicates.\n"); | 1624 | "Number of restored peers does not match file size. Have probably duplicates.\n"); |
1614 | } | 1625 | } |
1615 | GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fh)); | 1626 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); |
1616 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1627 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1617 | "Restored %u valid peers from disk\n", | 1628 | "Restored %u valid peers from disk\n", |
1618 | GNUNET_CONTAINER_multipeermap_size(sub->valid_peers)); | 1629 | GNUNET_CONTAINER_multipeermap_size (sub->valid_peers)); |
1619 | } | 1630 | } |
1620 | 1631 | ||
1621 | 1632 | ||
@@ -1625,22 +1636,22 @@ restore_valid_peers(const struct Sub *sub) | |||
1625 | * @param sub Sub for which the storage is deleted | 1636 | * @param sub Sub for which the storage is deleted |
1626 | */ | 1637 | */ |
1627 | static void | 1638 | static void |
1628 | peers_terminate(struct Sub *sub) | 1639 | peers_terminate (struct Sub *sub) |
1629 | { | 1640 | { |
1630 | if (GNUNET_SYSERR == | 1641 | if (GNUNET_SYSERR == |
1631 | GNUNET_CONTAINER_multipeermap_iterate(sub->peer_map, | 1642 | GNUNET_CONTAINER_multipeermap_iterate (sub->peer_map, |
1632 | &peermap_clear_iterator, | 1643 | &peermap_clear_iterator, |
1633 | sub)) | 1644 | sub)) |
1634 | { | 1645 | { |
1635 | LOG(GNUNET_ERROR_TYPE_WARNING, | 1646 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1636 | "Iteration destroying peers was aborted.\n"); | 1647 | "Iteration destroying peers was aborted.\n"); |
1637 | } | 1648 | } |
1638 | GNUNET_CONTAINER_multipeermap_destroy(sub->peer_map); | 1649 | GNUNET_CONTAINER_multipeermap_destroy (sub->peer_map); |
1639 | sub->peer_map = NULL; | 1650 | sub->peer_map = NULL; |
1640 | store_valid_peers(sub); | 1651 | store_valid_peers (sub); |
1641 | GNUNET_free(sub->filename_valid_peers); | 1652 | GNUNET_free (sub->filename_valid_peers); |
1642 | sub->filename_valid_peers = NULL; | 1653 | sub->filename_valid_peers = NULL; |
1643 | GNUNET_CONTAINER_multipeermap_destroy(sub->valid_peers); | 1654 | GNUNET_CONTAINER_multipeermap_destroy (sub->valid_peers); |
1644 | sub->valid_peers = NULL; | 1655 | sub->valid_peers = NULL; |
1645 | } | 1656 | } |
1646 | 1657 | ||
@@ -1656,15 +1667,15 @@ peers_terminate(struct Sub *sub) | |||
1656 | * #GNUNET_NO if not. | 1667 | * #GNUNET_NO if not. |
1657 | */ | 1668 | */ |
1658 | static int | 1669 | static int |
1659 | valid_peer_iterator(void *cls, | 1670 | valid_peer_iterator (void *cls, |
1660 | const struct GNUNET_PeerIdentity *peer, | 1671 | const struct GNUNET_PeerIdentity *peer, |
1661 | void *value) | 1672 | void *value) |
1662 | { | 1673 | { |
1663 | struct PeersIteratorCls *it_cls = cls; | 1674 | struct PeersIteratorCls *it_cls = cls; |
1664 | 1675 | ||
1665 | (void)value; | 1676 | (void) value; |
1666 | 1677 | ||
1667 | return it_cls->iterator(it_cls->cls, peer); | 1678 | return it_cls->iterator (it_cls->cls, peer); |
1668 | } | 1679 | } |
1669 | 1680 | ||
1670 | 1681 | ||
@@ -1678,20 +1689,20 @@ valid_peer_iterator(void *cls, | |||
1678 | * #GNUNET_SYSERR if it aborted iteration | 1689 | * #GNUNET_SYSERR if it aborted iteration |
1679 | */ | 1690 | */ |
1680 | static int | 1691 | static int |
1681 | get_valid_peers(struct GNUNET_CONTAINER_MultiPeerMap *valid_peers, | 1692 | get_valid_peers (struct GNUNET_CONTAINER_MultiPeerMap *valid_peers, |
1682 | PeersIterator iterator, | 1693 | PeersIterator iterator, |
1683 | void *it_cls) | 1694 | void *it_cls) |
1684 | { | 1695 | { |
1685 | struct PeersIteratorCls *cls; | 1696 | struct PeersIteratorCls *cls; |
1686 | int ret; | 1697 | int ret; |
1687 | 1698 | ||
1688 | cls = GNUNET_new(struct PeersIteratorCls); | 1699 | cls = GNUNET_new (struct PeersIteratorCls); |
1689 | cls->iterator = iterator; | 1700 | cls->iterator = iterator; |
1690 | cls->cls = it_cls; | 1701 | cls->cls = it_cls; |
1691 | ret = GNUNET_CONTAINER_multipeermap_iterate(valid_peers, | 1702 | ret = GNUNET_CONTAINER_multipeermap_iterate (valid_peers, |
1692 | valid_peer_iterator, | 1703 | valid_peer_iterator, |
1693 | cls); | 1704 | cls); |
1694 | GNUNET_free(cls); | 1705 | GNUNET_free (cls); |
1695 | return ret; | 1706 | return ret; |
1696 | } | 1707 | } |
1697 | 1708 | ||
@@ -1709,14 +1720,14 @@ get_valid_peers(struct GNUNET_CONTAINER_MultiPeerMap *valid_peers, | |||
1709 | * #GNUNET_NO otherwise | 1720 | * #GNUNET_NO otherwise |
1710 | */ | 1721 | */ |
1711 | static int | 1722 | static int |
1712 | insert_peer(struct Sub *sub, | 1723 | insert_peer (struct Sub *sub, |
1713 | const struct GNUNET_PeerIdentity *peer) | 1724 | const struct GNUNET_PeerIdentity *peer) |
1714 | { | 1725 | { |
1715 | if (GNUNET_YES == check_peer_known(sub->peer_map, peer)) | 1726 | if (GNUNET_YES == check_peer_known (sub->peer_map, peer)) |
1716 | { | 1727 | { |
1717 | return GNUNET_NO; /* We already know this peer - nothing to do */ | 1728 | return GNUNET_NO; /* We already know this peer - nothing to do */ |
1718 | } | 1729 | } |
1719 | (void)create_peer_ctx(sub, peer); | 1730 | (void) create_peer_ctx (sub, peer); |
1720 | return GNUNET_YES; | 1731 | return GNUNET_YES; |
1721 | } | 1732 | } |
1722 | 1733 | ||
@@ -1733,18 +1744,18 @@ insert_peer(struct Sub *sub, | |||
1733 | * #GNUNET_NO otherwise | 1744 | * #GNUNET_NO otherwise |
1734 | */ | 1745 | */ |
1735 | static int | 1746 | static int |
1736 | check_peer_flag(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, | 1747 | check_peer_flag (const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, |
1737 | const struct GNUNET_PeerIdentity *peer, | 1748 | const struct GNUNET_PeerIdentity *peer, |
1738 | enum Peers_PeerFlags flags) | 1749 | enum Peers_PeerFlags flags) |
1739 | { | 1750 | { |
1740 | struct PeerContext *peer_ctx; | 1751 | struct PeerContext *peer_ctx; |
1741 | 1752 | ||
1742 | if (GNUNET_NO == check_peer_known(peer_map, peer)) | 1753 | if (GNUNET_NO == check_peer_known (peer_map, peer)) |
1743 | { | 1754 | { |
1744 | return GNUNET_SYSERR; | 1755 | return GNUNET_SYSERR; |
1745 | } | 1756 | } |
1746 | peer_ctx = get_peer_ctx(peer_map, peer); | 1757 | peer_ctx = get_peer_ctx (peer_map, peer); |
1747 | return check_peer_flag_set(peer_ctx, flags); | 1758 | return check_peer_flag_set (peer_ctx, flags); |
1748 | } | 1759 | } |
1749 | 1760 | ||
1750 | /** | 1761 | /** |
@@ -1758,19 +1769,19 @@ check_peer_flag(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, | |||
1758 | * #GNUNET_NO otherwise | 1769 | * #GNUNET_NO otherwise |
1759 | */ | 1770 | */ |
1760 | static int | 1771 | static int |
1761 | issue_peer_online_check(struct Sub *sub, | 1772 | issue_peer_online_check (struct Sub *sub, |
1762 | const struct GNUNET_PeerIdentity *peer) | 1773 | const struct GNUNET_PeerIdentity *peer) |
1763 | { | 1774 | { |
1764 | struct PeerContext *peer_ctx; | 1775 | struct PeerContext *peer_ctx; |
1765 | 1776 | ||
1766 | (void)insert_peer(sub, peer); // TODO even needed? | 1777 | (void) insert_peer (sub, peer); // TODO even needed? |
1767 | peer_ctx = get_peer_ctx(sub->peer_map, peer); | 1778 | peer_ctx = get_peer_ctx (sub->peer_map, peer); |
1768 | if ((GNUNET_NO == check_peer_flag(sub->peer_map, peer, Peers_ONLINE)) && | 1779 | if ((GNUNET_NO == check_peer_flag (sub->peer_map, peer, Peers_ONLINE)) && |
1769 | (NULL == peer_ctx->online_check_pending)) | 1780 | (NULL == peer_ctx->online_check_pending)) |
1770 | { | 1781 | { |
1771 | check_peer_online(peer_ctx); | 1782 | check_peer_online (peer_ctx); |
1772 | return GNUNET_YES; | 1783 | return GNUNET_YES; |
1773 | } | 1784 | } |
1774 | return GNUNET_NO; | 1785 | return GNUNET_NO; |
1775 | } | 1786 | } |
1776 | 1787 | ||
@@ -1789,20 +1800,21 @@ issue_peer_online_check(struct Sub *sub, | |||
1789 | * #GNUNET_SYSERR if peer is not known | 1800 | * #GNUNET_SYSERR if peer is not known |
1790 | */ | 1801 | */ |
1791 | static int | 1802 | static int |
1792 | check_removable(const struct PeerContext *peer_ctx) | 1803 | check_removable (const struct PeerContext *peer_ctx) |
1793 | { | 1804 | { |
1794 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(peer_ctx->sub->peer_map, | 1805 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains ( |
1795 | &peer_ctx->peer_id)) | 1806 | peer_ctx->sub->peer_map, |
1796 | { | 1807 | &peer_ctx->peer_id)) |
1797 | return GNUNET_SYSERR; | 1808 | { |
1798 | } | 1809 | return GNUNET_SYSERR; |
1810 | } | ||
1799 | 1811 | ||
1800 | if ((NULL != peer_ctx->recv_channel_ctx) || | 1812 | if ((NULL != peer_ctx->recv_channel_ctx) || |
1801 | (NULL != peer_ctx->pending_messages_head) || | 1813 | (NULL != peer_ctx->pending_messages_head) || |
1802 | (GNUNET_YES == check_peer_flag_set(peer_ctx, Peers_PULL_REPLY_PENDING))) | 1814 | (GNUNET_YES == check_peer_flag_set (peer_ctx, Peers_PULL_REPLY_PENDING))) |
1803 | { | 1815 | { |
1804 | return GNUNET_NO; | 1816 | return GNUNET_NO; |
1805 | } | 1817 | } |
1806 | return GNUNET_YES; | 1818 | return GNUNET_YES; |
1807 | } | 1819 | } |
1808 | 1820 | ||
@@ -1819,10 +1831,10 @@ check_removable(const struct PeerContext *peer_ctx) | |||
1819 | * #GNUNET_NO if peer is not valid | 1831 | * #GNUNET_NO if peer is not valid |
1820 | */ | 1832 | */ |
1821 | static int | 1833 | static int |
1822 | check_peer_valid(const struct GNUNET_CONTAINER_MultiPeerMap *valid_peers, | 1834 | check_peer_valid (const struct GNUNET_CONTAINER_MultiPeerMap *valid_peers, |
1823 | const struct GNUNET_PeerIdentity *peer) | 1835 | const struct GNUNET_PeerIdentity *peer) |
1824 | { | 1836 | { |
1825 | return GNUNET_CONTAINER_multipeermap_contains(valid_peers, peer); | 1837 | return GNUNET_CONTAINER_multipeermap_contains (valid_peers, peer); |
1826 | } | 1838 | } |
1827 | 1839 | ||
1828 | 1840 | ||
@@ -1834,11 +1846,11 @@ check_peer_valid(const struct GNUNET_CONTAINER_MultiPeerMap *valid_peers, | |||
1834 | * @param peer_ctx Context of the target peer | 1846 | * @param peer_ctx Context of the target peer |
1835 | */ | 1847 | */ |
1836 | static void | 1848 | static void |
1837 | indicate_sending_intention(struct PeerContext *peer_ctx) | 1849 | indicate_sending_intention (struct PeerContext *peer_ctx) |
1838 | { | 1850 | { |
1839 | GNUNET_assert(GNUNET_YES == check_peer_known(peer_ctx->sub->peer_map, | 1851 | GNUNET_assert (GNUNET_YES == check_peer_known (peer_ctx->sub->peer_map, |
1840 | &peer_ctx->peer_id)); | 1852 | &peer_ctx->peer_id)); |
1841 | (void)get_channel(peer_ctx); | 1853 | (void) get_channel (peer_ctx); |
1842 | } | 1854 | } |
1843 | 1855 | ||
1844 | 1856 | ||
@@ -1852,12 +1864,12 @@ indicate_sending_intention(struct PeerContext *peer_ctx) | |||
1852 | * #GNUNET_NO otherwise | 1864 | * #GNUNET_NO otherwise |
1853 | */ | 1865 | */ |
1854 | static int | 1866 | static int |
1855 | check_peer_send_intention(const struct PeerContext *peer_ctx) | 1867 | check_peer_send_intention (const struct PeerContext *peer_ctx) |
1856 | { | 1868 | { |
1857 | if (NULL != peer_ctx->recv_channel_ctx) | 1869 | if (NULL != peer_ctx->recv_channel_ctx) |
1858 | { | 1870 | { |
1859 | return GNUNET_YES; | 1871 | return GNUNET_YES; |
1860 | } | 1872 | } |
1861 | return GNUNET_NO; | 1873 | return GNUNET_NO; |
1862 | } | 1874 | } |
1863 | 1875 | ||
@@ -1873,36 +1885,36 @@ check_peer_send_intention(const struct PeerContext *peer_ctx) | |||
1873 | * (can be NULL -- that's not an error) | 1885 | * (can be NULL -- that's not an error) |
1874 | */ | 1886 | */ |
1875 | static void * | 1887 | static void * |
1876 | handle_inbound_channel(void *cls, | 1888 | handle_inbound_channel (void *cls, |
1877 | struct GNUNET_CADET_Channel *channel, | 1889 | struct GNUNET_CADET_Channel *channel, |
1878 | const struct GNUNET_PeerIdentity *initiator) | 1890 | const struct GNUNET_PeerIdentity *initiator) |
1879 | { | 1891 | { |
1880 | struct PeerContext *peer_ctx; | 1892 | struct PeerContext *peer_ctx; |
1881 | struct ChannelCtx *channel_ctx; | 1893 | struct ChannelCtx *channel_ctx; |
1882 | struct Sub *sub = cls; | 1894 | struct Sub *sub = cls; |
1883 | 1895 | ||
1884 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1896 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1885 | "New channel was established to us (Peer %s).\n", | 1897 | "New channel was established to us (Peer %s).\n", |
1886 | GNUNET_i2s(initiator)); | 1898 | GNUNET_i2s (initiator)); |
1887 | GNUNET_assert(NULL != channel); /* according to cadet API */ | 1899 | GNUNET_assert (NULL != channel); /* according to cadet API */ |
1888 | /* Make sure we 'know' about this peer */ | 1900 | /* Make sure we 'know' about this peer */ |
1889 | peer_ctx = create_or_get_peer_ctx(sub, initiator); | 1901 | peer_ctx = create_or_get_peer_ctx (sub, initiator); |
1890 | set_peer_online(peer_ctx); | 1902 | set_peer_online (peer_ctx); |
1891 | (void)add_valid_peer(&peer_ctx->peer_id, peer_ctx->sub->valid_peers); | 1903 | (void) add_valid_peer (&peer_ctx->peer_id, peer_ctx->sub->valid_peers); |
1892 | channel_ctx = add_channel_ctx(peer_ctx); | 1904 | channel_ctx = add_channel_ctx (peer_ctx); |
1893 | channel_ctx->channel = channel; | 1905 | channel_ctx->channel = channel; |
1894 | /* We only accept one incoming channel per peer */ | 1906 | /* We only accept one incoming channel per peer */ |
1895 | if (GNUNET_YES == check_peer_send_intention(get_peer_ctx(sub->peer_map, | 1907 | if (GNUNET_YES == check_peer_send_intention (get_peer_ctx (sub->peer_map, |
1896 | initiator))) | 1908 | initiator))) |
1897 | { | 1909 | { |
1898 | LOG(GNUNET_ERROR_TYPE_WARNING, | 1910 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1899 | "Already got one receive channel. Destroying old one.\n"); | 1911 | "Already got one receive channel. Destroying old one.\n"); |
1900 | GNUNET_break_op(0); | 1912 | GNUNET_break_op (0); |
1901 | destroy_channel(peer_ctx->recv_channel_ctx); | 1913 | destroy_channel (peer_ctx->recv_channel_ctx); |
1902 | peer_ctx->recv_channel_ctx = channel_ctx; | 1914 | peer_ctx->recv_channel_ctx = channel_ctx; |
1903 | /* return the channel context */ | 1915 | /* return the channel context */ |
1904 | return channel_ctx; | 1916 | return channel_ctx; |
1905 | } | 1917 | } |
1906 | peer_ctx->recv_channel_ctx = channel_ctx; | 1918 | peer_ctx->recv_channel_ctx = channel_ctx; |
1907 | return channel_ctx; | 1919 | return channel_ctx; |
1908 | } | 1920 | } |
@@ -1917,17 +1929,17 @@ handle_inbound_channel(void *cls, | |||
1917 | * #GNUNET_NO otherwise | 1929 | * #GNUNET_NO otherwise |
1918 | */ | 1930 | */ |
1919 | static int | 1931 | static int |
1920 | check_sending_channel_exists(const struct PeerContext *peer_ctx) | 1932 | check_sending_channel_exists (const struct PeerContext *peer_ctx) |
1921 | { | 1933 | { |
1922 | if (GNUNET_NO == check_peer_known(peer_ctx->sub->peer_map, | 1934 | if (GNUNET_NO == check_peer_known (peer_ctx->sub->peer_map, |
1923 | &peer_ctx->peer_id)) | 1935 | &peer_ctx->peer_id)) |
1924 | { /* If no such peer exists, there is no channel */ | 1936 | { /* If no such peer exists, there is no channel */ |
1925 | return GNUNET_NO; | 1937 | return GNUNET_NO; |
1926 | } | 1938 | } |
1927 | if (NULL == peer_ctx->send_channel_ctx) | 1939 | if (NULL == peer_ctx->send_channel_ctx) |
1928 | { | 1940 | { |
1929 | return GNUNET_NO; | 1941 | return GNUNET_NO; |
1930 | } | 1942 | } |
1931 | return GNUNET_YES; | 1943 | return GNUNET_YES; |
1932 | } | 1944 | } |
1933 | 1945 | ||
@@ -1941,19 +1953,19 @@ check_sending_channel_exists(const struct PeerContext *peer_ctx) | |||
1941 | * #GNUNET_NO otherwise | 1953 | * #GNUNET_NO otherwise |
1942 | */ | 1954 | */ |
1943 | static int | 1955 | static int |
1944 | destroy_sending_channel(struct PeerContext *peer_ctx) | 1956 | destroy_sending_channel (struct PeerContext *peer_ctx) |
1945 | { | 1957 | { |
1946 | if (GNUNET_NO == check_peer_known(peer_ctx->sub->peer_map, | 1958 | if (GNUNET_NO == check_peer_known (peer_ctx->sub->peer_map, |
1947 | &peer_ctx->peer_id)) | 1959 | &peer_ctx->peer_id)) |
1948 | { | 1960 | { |
1949 | return GNUNET_NO; | 1961 | return GNUNET_NO; |
1950 | } | 1962 | } |
1951 | if (NULL != peer_ctx->send_channel_ctx) | 1963 | if (NULL != peer_ctx->send_channel_ctx) |
1952 | { | 1964 | { |
1953 | destroy_channel(peer_ctx->send_channel_ctx); | 1965 | destroy_channel (peer_ctx->send_channel_ctx); |
1954 | (void)check_connected(peer_ctx); | 1966 | (void) check_connected (peer_ctx); |
1955 | return GNUNET_YES; | 1967 | return GNUNET_YES; |
1956 | } | 1968 | } |
1957 | return GNUNET_NO; | 1969 | return GNUNET_NO; |
1958 | } | 1970 | } |
1959 | 1971 | ||
@@ -1968,23 +1980,23 @@ destroy_sending_channel(struct PeerContext *peer_ctx) | |||
1968 | * @param type type of the message | 1980 | * @param type type of the message |
1969 | */ | 1981 | */ |
1970 | static void | 1982 | static void |
1971 | send_message(struct PeerContext *peer_ctx, | 1983 | send_message (struct PeerContext *peer_ctx, |
1972 | struct GNUNET_MQ_Envelope *ev, | 1984 | struct GNUNET_MQ_Envelope *ev, |
1973 | const char *type) | 1985 | const char *type) |
1974 | { | 1986 | { |
1975 | struct PendingMessage *pending_msg; | 1987 | struct PendingMessage *pending_msg; |
1976 | struct GNUNET_MQ_Handle *mq; | 1988 | struct GNUNET_MQ_Handle *mq; |
1977 | 1989 | ||
1978 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1990 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1979 | "Sending message to %s of type %s\n", | 1991 | "Sending message to %s of type %s\n", |
1980 | GNUNET_i2s(&peer_ctx->peer_id), | 1992 | GNUNET_i2s (&peer_ctx->peer_id), |
1981 | type); | 1993 | type); |
1982 | pending_msg = insert_pending_message(peer_ctx, ev, type); | 1994 | pending_msg = insert_pending_message (peer_ctx, ev, type); |
1983 | mq = get_mq(peer_ctx); | 1995 | mq = get_mq (peer_ctx); |
1984 | GNUNET_MQ_notify_sent(ev, | 1996 | GNUNET_MQ_notify_sent (ev, |
1985 | mq_notify_sent_cb, | 1997 | mq_notify_sent_cb, |
1986 | pending_msg); | 1998 | pending_msg); |
1987 | GNUNET_MQ_send(mq, ev); | 1999 | GNUNET_MQ_send (mq, ev); |
1988 | } | 2000 | } |
1989 | 2001 | ||
1990 | /** | 2002 | /** |
@@ -2000,26 +2012,26 @@ send_message(struct PeerContext *peer_ctx, | |||
2000 | * #GNUNET_NO otherwise | 2012 | * #GNUNET_NO otherwise |
2001 | */ | 2013 | */ |
2002 | static int | 2014 | static int |
2003 | schedule_operation(struct PeerContext *peer_ctx, | 2015 | schedule_operation (struct PeerContext *peer_ctx, |
2004 | const PeerOp peer_op, | 2016 | const PeerOp peer_op, |
2005 | void *cls) | 2017 | void *cls) |
2006 | { | 2018 | { |
2007 | struct PeerPendingOp pending_op; | 2019 | struct PeerPendingOp pending_op; |
2008 | 2020 | ||
2009 | GNUNET_assert(GNUNET_YES == check_peer_known(peer_ctx->sub->peer_map, | 2021 | GNUNET_assert (GNUNET_YES == check_peer_known (peer_ctx->sub->peer_map, |
2010 | &peer_ctx->peer_id)); | 2022 | &peer_ctx->peer_id)); |
2011 | 2023 | ||
2012 | //TODO if ONLINE execute immediately | 2024 | // TODO if ONLINE execute immediately |
2013 | 2025 | ||
2014 | if (GNUNET_NO == check_operation_scheduled(peer_ctx, peer_op)) | 2026 | if (GNUNET_NO == check_operation_scheduled (peer_ctx, peer_op)) |
2015 | { | 2027 | { |
2016 | pending_op.op = peer_op; | 2028 | pending_op.op = peer_op; |
2017 | pending_op.op_cls = cls; | 2029 | pending_op.op_cls = cls; |
2018 | GNUNET_array_append(peer_ctx->pending_ops, | 2030 | GNUNET_array_append (peer_ctx->pending_ops, |
2019 | peer_ctx->num_pending_ops, | 2031 | peer_ctx->num_pending_ops, |
2020 | pending_op); | 2032 | pending_op); |
2021 | return GNUNET_YES; | 2033 | return GNUNET_YES; |
2022 | } | 2034 | } |
2023 | return GNUNET_NO; | 2035 | return GNUNET_NO; |
2024 | } | 2036 | } |
2025 | 2037 | ||
@@ -2036,7 +2048,8 @@ schedule_operation(struct PeerContext *peer_ctx, | |||
2036 | * Closure used to pass the client and the id to the callback | 2048 | * Closure used to pass the client and the id to the callback |
2037 | * that replies to a client's request | 2049 | * that replies to a client's request |
2038 | */ | 2050 | */ |
2039 | struct ReplyCls { | 2051 | struct ReplyCls |
2052 | { | ||
2040 | /** | 2053 | /** |
2041 | * DLL | 2054 | * DLL |
2042 | */ | 2055 | */ |
@@ -2063,7 +2076,8 @@ struct ReplyCls { | |||
2063 | /** | 2076 | /** |
2064 | * Struct used to store the context of a connected client. | 2077 | * Struct used to store the context of a connected client. |
2065 | */ | 2078 | */ |
2066 | struct ClientContext { | 2079 | struct ClientContext |
2080 | { | ||
2067 | /** | 2081 | /** |
2068 | * DLL | 2082 | * DLL |
2069 | */ | 2083 | */ |
@@ -2120,21 +2134,21 @@ struct ClientContext *cli_ctx_tail; | |||
2120 | * Print peerlist to log. | 2134 | * Print peerlist to log. |
2121 | */ | 2135 | */ |
2122 | static void | 2136 | static void |
2123 | print_peer_list(struct GNUNET_PeerIdentity *list, | 2137 | print_peer_list (struct GNUNET_PeerIdentity *list, |
2124 | unsigned int len) | 2138 | unsigned int len) |
2125 | { | 2139 | { |
2126 | unsigned int i; | 2140 | unsigned int i; |
2127 | 2141 | ||
2128 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2142 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2129 | "Printing peer list of length %u at %p:\n", | 2143 | "Printing peer list of length %u at %p:\n", |
2130 | len, | 2144 | len, |
2131 | list); | 2145 | list); |
2132 | for (i = 0; i < len; i++) | 2146 | for (i = 0; i < len; i++) |
2133 | { | 2147 | { |
2134 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2148 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2135 | "%u. peer: %s\n", | 2149 | "%u. peer: %s\n", |
2136 | i, GNUNET_i2s(&list[i])); | 2150 | i, GNUNET_i2s (&list[i])); |
2137 | } | 2151 | } |
2138 | } | 2152 | } |
2139 | 2153 | ||
2140 | 2154 | ||
@@ -2142,33 +2156,33 @@ print_peer_list(struct GNUNET_PeerIdentity *list, | |||
2142 | * Remove peer from list. | 2156 | * Remove peer from list. |
2143 | */ | 2157 | */ |
2144 | static void | 2158 | static void |
2145 | rem_from_list(struct GNUNET_PeerIdentity **peer_list, | 2159 | rem_from_list (struct GNUNET_PeerIdentity **peer_list, |
2146 | unsigned int *list_size, | 2160 | unsigned int *list_size, |
2147 | const struct GNUNET_PeerIdentity *peer) | 2161 | const struct GNUNET_PeerIdentity *peer) |
2148 | { | 2162 | { |
2149 | unsigned int i; | 2163 | unsigned int i; |
2150 | struct GNUNET_PeerIdentity *tmp; | 2164 | struct GNUNET_PeerIdentity *tmp; |
2151 | 2165 | ||
2152 | tmp = *peer_list; | 2166 | tmp = *peer_list; |
2153 | 2167 | ||
2154 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2168 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2155 | "Removing peer %s from list at %p\n", | 2169 | "Removing peer %s from list at %p\n", |
2156 | GNUNET_i2s(peer), | 2170 | GNUNET_i2s (peer), |
2157 | tmp); | 2171 | tmp); |
2158 | 2172 | ||
2159 | for (i = 0; i < *list_size; i++) | 2173 | for (i = 0; i < *list_size; i++) |
2174 | { | ||
2175 | if (0 == GNUNET_memcmp (&tmp[i], peer)) | ||
2160 | { | 2176 | { |
2161 | if (0 == GNUNET_memcmp(&tmp[i], peer)) | 2177 | if (i < *list_size - 1) |
2162 | { | 2178 | { /* Not at the last entry -- shift peers left */ |
2163 | if (i < *list_size - 1) | 2179 | memmove (&tmp[i], &tmp[i + 1], |
2164 | { /* Not at the last entry -- shift peers left */ | 2180 | ((*list_size) - i - 1) * sizeof(struct GNUNET_PeerIdentity)); |
2165 | memmove(&tmp[i], &tmp[i + 1], | 2181 | } |
2166 | ((*list_size) - i - 1) * sizeof(struct GNUNET_PeerIdentity)); | 2182 | /* Remove last entry (should be now useless PeerID) */ |
2167 | } | 2183 | GNUNET_array_grow (tmp, *list_size, (*list_size) - 1); |
2168 | /* Remove last entry (should be now useless PeerID) */ | 2184 | } |
2169 | GNUNET_array_grow(tmp, *list_size, (*list_size) - 1); | 2185 | } |
2170 | } | ||
2171 | } | ||
2172 | *peer_list = tmp; | 2186 | *peer_list = tmp; |
2173 | } | 2187 | } |
2174 | 2188 | ||
@@ -2183,8 +2197,8 @@ rem_from_list(struct GNUNET_PeerIdentity **peer_list, | |||
2183 | * GNUNET_NO if peer was not inserted | 2197 | * GNUNET_NO if peer was not inserted |
2184 | */ | 2198 | */ |
2185 | static void | 2199 | static void |
2186 | insert_in_view_op(void *cls, | 2200 | insert_in_view_op (void *cls, |
2187 | const struct GNUNET_PeerIdentity *peer); | 2201 | const struct GNUNET_PeerIdentity *peer); |
2188 | 2202 | ||
2189 | /** | 2203 | /** |
2190 | * Insert PeerID in #view | 2204 | * Insert PeerID in #view |
@@ -2198,32 +2212,32 @@ insert_in_view_op(void *cls, | |||
2198 | * GNUNET_NO if peer was not inserted | 2212 | * GNUNET_NO if peer was not inserted |
2199 | */ | 2213 | */ |
2200 | static int | 2214 | static int |
2201 | insert_in_view(struct Sub *sub, | 2215 | insert_in_view (struct Sub *sub, |
2202 | const struct GNUNET_PeerIdentity *peer) | 2216 | const struct GNUNET_PeerIdentity *peer) |
2203 | { | 2217 | { |
2204 | struct PeerContext *peer_ctx; | 2218 | struct PeerContext *peer_ctx; |
2205 | int online; | 2219 | int online; |
2206 | int ret; | 2220 | int ret; |
2207 | 2221 | ||
2208 | online = check_peer_flag(sub->peer_map, peer, Peers_ONLINE); | 2222 | online = check_peer_flag (sub->peer_map, peer, Peers_ONLINE); |
2209 | peer_ctx = get_peer_ctx(sub->peer_map, peer); // TODO indirection needed? | 2223 | peer_ctx = get_peer_ctx (sub->peer_map, peer); // TODO indirection needed? |
2210 | if ((GNUNET_NO == online) || | 2224 | if ((GNUNET_NO == online) || |
2211 | (GNUNET_SYSERR == online)) /* peer is not even known */ | 2225 | (GNUNET_SYSERR == online)) /* peer is not even known */ |
2212 | { | 2226 | { |
2213 | (void)issue_peer_online_check(sub, peer); | 2227 | (void) issue_peer_online_check (sub, peer); |
2214 | (void)schedule_operation(peer_ctx, insert_in_view_op, sub); | 2228 | (void) schedule_operation (peer_ctx, insert_in_view_op, sub); |
2215 | return GNUNET_NO; | 2229 | return GNUNET_NO; |
2216 | } | 2230 | } |
2217 | /* Open channel towards peer to keep connection open */ | 2231 | /* Open channel towards peer to keep connection open */ |
2218 | indicate_sending_intention(peer_ctx); | 2232 | indicate_sending_intention (peer_ctx); |
2219 | ret = View_put(sub->view, peer); | 2233 | ret = View_put (sub->view, peer); |
2220 | if (peer_ctx->sub == msub) | 2234 | if (peer_ctx->sub == msub) |
2221 | { | 2235 | { |
2222 | GNUNET_STATISTICS_set(stats, | 2236 | GNUNET_STATISTICS_set (stats, |
2223 | "view size", | 2237 | "view size", |
2224 | View_size(peer_ctx->sub->view), | 2238 | View_size (peer_ctx->sub->view), |
2225 | GNUNET_NO); | 2239 | GNUNET_NO); |
2226 | } | 2240 | } |
2227 | return ret; | 2241 | return ret; |
2228 | } | 2242 | } |
2229 | 2243 | ||
@@ -2236,33 +2250,33 @@ insert_in_view(struct Sub *sub, | |||
2236 | * @param view_size the size of the view array (can be 0) | 2250 | * @param view_size the size of the view array (can be 0) |
2237 | */ | 2251 | */ |
2238 | static void | 2252 | static void |
2239 | send_view(const struct ClientContext *cli_ctx, | 2253 | send_view (const struct ClientContext *cli_ctx, |
2240 | const struct GNUNET_PeerIdentity *view_array, | 2254 | const struct GNUNET_PeerIdentity *view_array, |
2241 | uint64_t view_size) | 2255 | uint64_t view_size) |
2242 | { | 2256 | { |
2243 | struct GNUNET_MQ_Envelope *ev; | 2257 | struct GNUNET_MQ_Envelope *ev; |
2244 | struct GNUNET_RPS_CS_DEBUG_ViewReply *out_msg; | 2258 | struct GNUNET_RPS_CS_DEBUG_ViewReply *out_msg; |
2245 | struct Sub *sub; | 2259 | struct Sub *sub; |
2246 | 2260 | ||
2247 | if (NULL == view_array) | 2261 | if (NULL == view_array) |
2248 | { | 2262 | { |
2249 | if (NULL == cli_ctx->sub) | 2263 | if (NULL == cli_ctx->sub) |
2250 | sub = msub; | 2264 | sub = msub; |
2251 | else | 2265 | else |
2252 | sub = cli_ctx->sub; | 2266 | sub = cli_ctx->sub; |
2253 | view_size = View_size(sub->view); | 2267 | view_size = View_size (sub->view); |
2254 | view_array = View_get_as_array(sub->view); | 2268 | view_array = View_get_as_array (sub->view); |
2255 | } | 2269 | } |
2256 | 2270 | ||
2257 | ev = GNUNET_MQ_msg_extra(out_msg, | 2271 | ev = GNUNET_MQ_msg_extra (out_msg, |
2258 | view_size * sizeof(struct GNUNET_PeerIdentity), | 2272 | view_size * sizeof(struct GNUNET_PeerIdentity), |
2259 | GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REPLY); | 2273 | GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REPLY); |
2260 | out_msg->num_peers = htonl(view_size); | 2274 | out_msg->num_peers = htonl (view_size); |
2261 | 2275 | ||
2262 | GNUNET_memcpy(&out_msg[1], | 2276 | GNUNET_memcpy (&out_msg[1], |
2263 | view_array, | 2277 | view_array, |
2264 | view_size * sizeof(struct GNUNET_PeerIdentity)); | 2278 | view_size * sizeof(struct GNUNET_PeerIdentity)); |
2265 | GNUNET_MQ_send(cli_ctx->mq, ev); | 2279 | GNUNET_MQ_send (cli_ctx->mq, ev); |
2266 | } | 2280 | } |
2267 | 2281 | ||
2268 | 2282 | ||
@@ -2276,24 +2290,24 @@ send_view(const struct ClientContext *cli_ctx, | |||
2276 | * @param view_size the size of the view array (can be 0) | 2290 | * @param view_size the size of the view array (can be 0) |
2277 | */ | 2291 | */ |
2278 | static void | 2292 | static void |
2279 | send_stream_peers(const struct ClientContext *cli_ctx, | 2293 | send_stream_peers (const struct ClientContext *cli_ctx, |
2280 | uint64_t num_peers, | 2294 | uint64_t num_peers, |
2281 | const struct GNUNET_PeerIdentity *peers) | 2295 | const struct GNUNET_PeerIdentity *peers) |
2282 | { | 2296 | { |
2283 | struct GNUNET_MQ_Envelope *ev; | 2297 | struct GNUNET_MQ_Envelope *ev; |
2284 | struct GNUNET_RPS_CS_DEBUG_StreamReply *out_msg; | 2298 | struct GNUNET_RPS_CS_DEBUG_StreamReply *out_msg; |
2285 | 2299 | ||
2286 | GNUNET_assert(NULL != peers); | 2300 | GNUNET_assert (NULL != peers); |
2287 | 2301 | ||
2288 | ev = GNUNET_MQ_msg_extra(out_msg, | 2302 | ev = GNUNET_MQ_msg_extra (out_msg, |
2289 | num_peers * sizeof(struct GNUNET_PeerIdentity), | 2303 | num_peers * sizeof(struct GNUNET_PeerIdentity), |
2290 | GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REPLY); | 2304 | GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REPLY); |
2291 | out_msg->num_peers = htonl(num_peers); | 2305 | out_msg->num_peers = htonl (num_peers); |
2292 | 2306 | ||
2293 | GNUNET_memcpy(&out_msg[1], | 2307 | GNUNET_memcpy (&out_msg[1], |
2294 | peers, | 2308 | peers, |
2295 | num_peers * sizeof(struct GNUNET_PeerIdentity)); | 2309 | num_peers * sizeof(struct GNUNET_PeerIdentity)); |
2296 | GNUNET_MQ_send(cli_ctx->mq, ev); | 2310 | GNUNET_MQ_send (cli_ctx->mq, ev); |
2297 | } | 2311 | } |
2298 | 2312 | ||
2299 | 2313 | ||
@@ -2303,46 +2317,46 @@ send_stream_peers(const struct ClientContext *cli_ctx, | |||
2303 | * @param sub Sub for which to notify clients | 2317 | * @param sub Sub for which to notify clients |
2304 | */ | 2318 | */ |
2305 | static void | 2319 | static void |
2306 | clients_notify_view_update(const struct Sub *sub) | 2320 | clients_notify_view_update (const struct Sub *sub) |
2307 | { | 2321 | { |
2308 | struct ClientContext *cli_ctx_iter; | 2322 | struct ClientContext *cli_ctx_iter; |
2309 | uint64_t num_peers; | 2323 | uint64_t num_peers; |
2310 | const struct GNUNET_PeerIdentity *view_array; | 2324 | const struct GNUNET_PeerIdentity *view_array; |
2311 | 2325 | ||
2312 | num_peers = View_size(sub->view); | 2326 | num_peers = View_size (sub->view); |
2313 | view_array = View_get_as_array(sub->view); | 2327 | view_array = View_get_as_array (sub->view); |
2314 | /* check size of view is small enough */ | 2328 | /* check size of view is small enough */ |
2315 | if (GNUNET_MAX_MESSAGE_SIZE < num_peers) | 2329 | if (GNUNET_MAX_MESSAGE_SIZE < num_peers) |
2316 | { | 2330 | { |
2317 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 2331 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
2318 | "View is too big to send\n"); | 2332 | "View is too big to send\n"); |
2319 | return; | 2333 | return; |
2320 | } | 2334 | } |
2321 | 2335 | ||
2322 | for (cli_ctx_iter = cli_ctx_head; | 2336 | for (cli_ctx_iter = cli_ctx_head; |
2323 | NULL != cli_ctx_iter; | 2337 | NULL != cli_ctx_iter; |
2324 | cli_ctx_iter = cli_ctx_iter->next) | 2338 | cli_ctx_iter = cli_ctx_iter->next) |
2339 | { | ||
2340 | if (1 < cli_ctx_iter->view_updates_left) | ||
2325 | { | 2341 | { |
2326 | if (1 < cli_ctx_iter->view_updates_left) | 2342 | /* Client wants to receive limited amount of updates */ |
2327 | { | 2343 | cli_ctx_iter->view_updates_left -= 1; |
2328 | /* Client wants to receive limited amount of updates */ | ||
2329 | cli_ctx_iter->view_updates_left -= 1; | ||
2330 | } | ||
2331 | else if (1 == cli_ctx_iter->view_updates_left) | ||
2332 | { | ||
2333 | /* Last update of view for client */ | ||
2334 | cli_ctx_iter->view_updates_left = -1; | ||
2335 | } | ||
2336 | else if (0 > cli_ctx_iter->view_updates_left) | ||
2337 | { | ||
2338 | /* Client is not interested in updates */ | ||
2339 | continue; | ||
2340 | } | ||
2341 | /* else _updates_left == 0 - infinite amount of updates */ | ||
2342 | |||
2343 | /* send view */ | ||
2344 | send_view(cli_ctx_iter, view_array, num_peers); | ||
2345 | } | 2344 | } |
2345 | else if (1 == cli_ctx_iter->view_updates_left) | ||
2346 | { | ||
2347 | /* Last update of view for client */ | ||
2348 | cli_ctx_iter->view_updates_left = -1; | ||
2349 | } | ||
2350 | else if (0 > cli_ctx_iter->view_updates_left) | ||
2351 | { | ||
2352 | /* Client is not interested in updates */ | ||
2353 | continue; | ||
2354 | } | ||
2355 | /* else _updates_left == 0 - infinite amount of updates */ | ||
2356 | |||
2357 | /* send view */ | ||
2358 | send_view (cli_ctx_iter, view_array, num_peers); | ||
2359 | } | ||
2346 | } | 2360 | } |
2347 | 2361 | ||
2348 | 2362 | ||
@@ -2353,27 +2367,27 @@ clients_notify_view_update(const struct Sub *sub) | |||
2353 | * @param peers the array of peers to send | 2367 | * @param peers the array of peers to send |
2354 | */ | 2368 | */ |
2355 | static void | 2369 | static void |
2356 | clients_notify_stream_peer(const struct Sub *sub, | 2370 | clients_notify_stream_peer (const struct Sub *sub, |
2357 | uint64_t num_peers, | 2371 | uint64_t num_peers, |
2358 | const struct GNUNET_PeerIdentity *peers) | 2372 | const struct GNUNET_PeerIdentity *peers) |
2359 | // TODO enum StreamPeerSource) | 2373 | // TODO enum StreamPeerSource) |
2360 | { | 2374 | { |
2361 | struct ClientContext *cli_ctx_iter; | 2375 | struct ClientContext *cli_ctx_iter; |
2362 | 2376 | ||
2363 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2377 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2364 | "Got peer (%s) from biased stream - update all clients\n", | 2378 | "Got peer (%s) from biased stream - update all clients\n", |
2365 | GNUNET_i2s(peers)); | 2379 | GNUNET_i2s (peers)); |
2366 | 2380 | ||
2367 | for (cli_ctx_iter = cli_ctx_head; | 2381 | for (cli_ctx_iter = cli_ctx_head; |
2368 | NULL != cli_ctx_iter; | 2382 | NULL != cli_ctx_iter; |
2369 | cli_ctx_iter = cli_ctx_iter->next) | 2383 | cli_ctx_iter = cli_ctx_iter->next) |
2384 | { | ||
2385 | if ((GNUNET_YES == cli_ctx_iter->stream_update) && | ||
2386 | ((sub == cli_ctx_iter->sub) ||(sub == msub) )) | ||
2370 | { | 2387 | { |
2371 | if (GNUNET_YES == cli_ctx_iter->stream_update && | 2388 | send_stream_peers (cli_ctx_iter, num_peers, peers); |
2372 | (sub == cli_ctx_iter->sub || sub == msub)) | ||
2373 | { | ||
2374 | send_stream_peers(cli_ctx_iter, num_peers, peers); | ||
2375 | } | ||
2376 | } | 2389 | } |
2390 | } | ||
2377 | } | 2391 | } |
2378 | 2392 | ||
2379 | 2393 | ||
@@ -2385,34 +2399,34 @@ clients_notify_stream_peer(const struct Sub *sub, | |||
2385 | * @param cls Closure - The Sub for which this is to be done | 2399 | * @param cls Closure - The Sub for which this is to be done |
2386 | */ | 2400 | */ |
2387 | static void | 2401 | static void |
2388 | hist_update(const struct GNUNET_PeerIdentity *ids, | 2402 | hist_update (const struct GNUNET_PeerIdentity *ids, |
2389 | uint32_t num_peers, | 2403 | uint32_t num_peers, |
2390 | void *cls) | 2404 | void *cls) |
2391 | { | 2405 | { |
2392 | unsigned int i; | 2406 | unsigned int i; |
2393 | struct Sub *sub = cls; | 2407 | struct Sub *sub = cls; |
2394 | 2408 | ||
2395 | for (i = 0; i < num_peers; i++) | 2409 | for (i = 0; i < num_peers; i++) |
2410 | { | ||
2411 | int inserted; | ||
2412 | if (GNUNET_YES != check_peer_known (sub->peer_map, &ids[i])) | ||
2396 | { | 2413 | { |
2397 | int inserted; | 2414 | LOG (GNUNET_ERROR_TYPE_WARNING, |
2398 | if (GNUNET_YES != check_peer_known(sub->peer_map, &ids[i])) | 2415 | "Peer in history update not known!\n"); |
2399 | { | 2416 | continue; |
2400 | LOG(GNUNET_ERROR_TYPE_WARNING, | 2417 | } |
2401 | "Peer in history update not known!\n"); | 2418 | inserted = insert_in_view (sub, &ids[i]); |
2402 | continue; | 2419 | if (GNUNET_OK == inserted) |
2403 | } | 2420 | { |
2404 | inserted = insert_in_view(sub, &ids[i]); | 2421 | clients_notify_stream_peer (sub, 1, &ids[i]); |
2405 | if (GNUNET_OK == inserted) | 2422 | } |
2406 | { | ||
2407 | clients_notify_stream_peer(sub, 1, &ids[i]); | ||
2408 | } | ||
2409 | #ifdef TO_FILE_FULL | 2423 | #ifdef TO_FILE_FULL |
2410 | to_file(sub->file_name_view_log, | 2424 | to_file (sub->file_name_view_log, |
2411 | "+%s\t(hist)", | 2425 | "+%s\t(hist)", |
2412 | GNUNET_i2s_full(ids)); | 2426 | GNUNET_i2s_full (ids)); |
2413 | #endif /* TO_FILE_FULL */ | 2427 | #endif /* TO_FILE_FULL */ |
2414 | } | 2428 | } |
2415 | clients_notify_view_update(sub); | 2429 | clients_notify_view_update (sub); |
2416 | } | 2430 | } |
2417 | 2431 | ||
2418 | 2432 | ||
@@ -2426,22 +2440,22 @@ hist_update(const struct GNUNET_PeerIdentity *ids, | |||
2426 | * @param new_size New size to which to resize | 2440 | * @param new_size New size to which to resize |
2427 | */ | 2441 | */ |
2428 | static void | 2442 | static void |
2429 | resize_wrapper(struct RPS_Sampler *sampler, uint32_t new_size) | 2443 | resize_wrapper (struct RPS_Sampler *sampler, uint32_t new_size) |
2430 | { | 2444 | { |
2431 | unsigned int sampler_size; | 2445 | unsigned int sampler_size; |
2432 | 2446 | ||
2433 | // TODO statistics | 2447 | // TODO statistics |
2434 | // TODO respect the min, max | 2448 | // TODO respect the min, max |
2435 | sampler_size = RPS_sampler_get_size(sampler); | 2449 | sampler_size = RPS_sampler_get_size (sampler); |
2436 | if (sampler_size > new_size * 4) | 2450 | if (sampler_size > new_size * 4) |
2437 | { /* Shrinking */ | 2451 | { /* Shrinking */ |
2438 | RPS_sampler_resize(sampler, sampler_size / 2); | 2452 | RPS_sampler_resize (sampler, sampler_size / 2); |
2439 | } | 2453 | } |
2440 | else if (sampler_size < new_size) | 2454 | else if (sampler_size < new_size) |
2441 | { /* Growing */ | 2455 | { /* Growing */ |
2442 | RPS_sampler_resize(sampler, sampler_size * 2); | 2456 | RPS_sampler_resize (sampler, sampler_size * 2); |
2443 | } | 2457 | } |
2444 | LOG(GNUNET_ERROR_TYPE_DEBUG, "sampler_size is now %u\n", sampler_size); | 2458 | LOG (GNUNET_ERROR_TYPE_DEBUG, "sampler_size is now %u\n", sampler_size); |
2445 | } | 2459 | } |
2446 | 2460 | ||
2447 | 2461 | ||
@@ -2453,33 +2467,33 @@ resize_wrapper(struct RPS_Sampler *sampler, uint32_t new_size) | |||
2453 | * @param peer_map the peermap to use as set | 2467 | * @param peer_map the peermap to use as set |
2454 | */ | 2468 | */ |
2455 | static void | 2469 | static void |
2456 | add_peer_array_to_set(const struct GNUNET_PeerIdentity *peer_array, | 2470 | add_peer_array_to_set (const struct GNUNET_PeerIdentity *peer_array, |
2457 | unsigned int num_peers, | 2471 | unsigned int num_peers, |
2458 | struct GNUNET_CONTAINER_MultiPeerMap *peer_map) | 2472 | struct GNUNET_CONTAINER_MultiPeerMap *peer_map) |
2459 | { | 2473 | { |
2460 | unsigned int i; | 2474 | unsigned int i; |
2461 | 2475 | ||
2462 | if (NULL == peer_map) | 2476 | if (NULL == peer_map) |
2463 | { | 2477 | { |
2464 | LOG(GNUNET_ERROR_TYPE_WARNING, | 2478 | LOG (GNUNET_ERROR_TYPE_WARNING, |
2465 | "Trying to add peers to non-existing peermap.\n"); | 2479 | "Trying to add peers to non-existing peermap.\n"); |
2466 | return; | 2480 | return; |
2467 | } | 2481 | } |
2468 | 2482 | ||
2469 | for (i = 0; i < num_peers; i++) | 2483 | for (i = 0; i < num_peers; i++) |
2484 | { | ||
2485 | GNUNET_CONTAINER_multipeermap_put (peer_map, | ||
2486 | &peer_array[i], | ||
2487 | NULL, | ||
2488 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | ||
2489 | if (msub->peer_map == peer_map) | ||
2470 | { | 2490 | { |
2471 | GNUNET_CONTAINER_multipeermap_put(peer_map, | 2491 | GNUNET_STATISTICS_set (stats, |
2472 | &peer_array[i], | 2492 | "# known peers", |
2473 | NULL, | 2493 | GNUNET_CONTAINER_multipeermap_size (peer_map), |
2474 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | 2494 | GNUNET_NO); |
2475 | if (msub->peer_map == peer_map) | ||
2476 | { | ||
2477 | GNUNET_STATISTICS_set(stats, | ||
2478 | "# known peers", | ||
2479 | GNUNET_CONTAINER_multipeermap_size(peer_map), | ||
2480 | GNUNET_NO); | ||
2481 | } | ||
2482 | } | 2495 | } |
2496 | } | ||
2483 | } | 2497 | } |
2484 | 2498 | ||
2485 | 2499 | ||
@@ -2491,17 +2505,17 @@ add_peer_array_to_set(const struct GNUNET_PeerIdentity *peer_array, | |||
2491 | * @param num_peer_ids the number of peers to send to @a peer_id | 2505 | * @param num_peer_ids the number of peers to send to @a peer_id |
2492 | */ | 2506 | */ |
2493 | static void | 2507 | static void |
2494 | send_pull_reply(struct PeerContext *peer_ctx, | 2508 | send_pull_reply (struct PeerContext *peer_ctx, |
2495 | const struct GNUNET_PeerIdentity *peer_ids, | 2509 | const struct GNUNET_PeerIdentity *peer_ids, |
2496 | unsigned int num_peer_ids) | 2510 | unsigned int num_peer_ids) |
2497 | { | 2511 | { |
2498 | uint32_t send_size; | 2512 | uint32_t send_size; |
2499 | struct GNUNET_MQ_Envelope *ev; | 2513 | struct GNUNET_MQ_Envelope *ev; |
2500 | struct GNUNET_RPS_P2P_PullReplyMessage *out_msg; | 2514 | struct GNUNET_RPS_P2P_PullReplyMessage *out_msg; |
2501 | 2515 | ||
2502 | /* Compute actual size */ | 2516 | /* Compute actual size */ |
2503 | send_size = sizeof(struct GNUNET_RPS_P2P_PullReplyMessage) + | 2517 | send_size = sizeof(struct GNUNET_RPS_P2P_PullReplyMessage) |
2504 | num_peer_ids * sizeof(struct GNUNET_PeerIdentity); | 2518 | + num_peer_ids * sizeof(struct GNUNET_PeerIdentity); |
2505 | 2519 | ||
2506 | if (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE < send_size) | 2520 | if (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE < send_size) |
2507 | /* Compute number of peers to send | 2521 | /* Compute number of peers to send |
@@ -2509,28 +2523,28 @@ send_pull_reply(struct PeerContext *peer_ctx, | |||
2509 | // TODO select random ones via permutation | 2523 | // TODO select random ones via permutation |
2510 | // or even better: do good protocol design | 2524 | // or even better: do good protocol design |
2511 | send_size = | 2525 | send_size = |
2512 | (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - | 2526 | (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE |
2513 | sizeof(struct GNUNET_RPS_P2P_PullReplyMessage)) / | 2527 | - sizeof(struct GNUNET_RPS_P2P_PullReplyMessage)) |
2514 | sizeof(struct GNUNET_PeerIdentity); | 2528 | / sizeof(struct GNUNET_PeerIdentity); |
2515 | else | 2529 | else |
2516 | send_size = num_peer_ids; | 2530 | send_size = num_peer_ids; |
2517 | 2531 | ||
2518 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2532 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2519 | "Going to send PULL REPLY with %u peers to %s\n", | 2533 | "Going to send PULL REPLY with %u peers to %s\n", |
2520 | send_size, GNUNET_i2s(&peer_ctx->peer_id)); | 2534 | send_size, GNUNET_i2s (&peer_ctx->peer_id)); |
2521 | 2535 | ||
2522 | ev = GNUNET_MQ_msg_extra(out_msg, | 2536 | ev = GNUNET_MQ_msg_extra (out_msg, |
2523 | send_size * sizeof(struct GNUNET_PeerIdentity), | 2537 | send_size * sizeof(struct GNUNET_PeerIdentity), |
2524 | GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY); | 2538 | GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY); |
2525 | out_msg->num_peers = htonl(send_size); | 2539 | out_msg->num_peers = htonl (send_size); |
2526 | GNUNET_memcpy(&out_msg[1], peer_ids, | 2540 | GNUNET_memcpy (&out_msg[1], peer_ids, |
2527 | send_size * sizeof(struct GNUNET_PeerIdentity)); | 2541 | send_size * sizeof(struct GNUNET_PeerIdentity)); |
2528 | 2542 | ||
2529 | send_message(peer_ctx, ev, "PULL REPLY"); | 2543 | send_message (peer_ctx, ev, "PULL REPLY"); |
2530 | if (peer_ctx->sub == msub) | 2544 | if (peer_ctx->sub == msub) |
2531 | { | 2545 | { |
2532 | GNUNET_STATISTICS_update(stats, "# pull reply send issued", 1, GNUNET_NO); | 2546 | GNUNET_STATISTICS_update (stats, "# pull reply send issued", 1, GNUNET_NO); |
2533 | } | 2547 | } |
2534 | // TODO check with send intention: as send_channel is used/opened we indicate | 2548 | // TODO check with send intention: as send_channel is used/opened we indicate |
2535 | // a sending intention without intending it. | 2549 | // a sending intention without intending it. |
2536 | // -> clean peer afterwards? | 2550 | // -> clean peer afterwards? |
@@ -2547,12 +2561,12 @@ send_pull_reply(struct PeerContext *peer_ctx, | |||
2547 | * @param peer Peer to insert | 2561 | * @param peer Peer to insert |
2548 | */ | 2562 | */ |
2549 | static void | 2563 | static void |
2550 | insert_in_pull_map(void *cls, | 2564 | insert_in_pull_map (void *cls, |
2551 | const struct GNUNET_PeerIdentity *peer) | 2565 | const struct GNUNET_PeerIdentity *peer) |
2552 | { | 2566 | { |
2553 | struct Sub *sub = cls; | 2567 | struct Sub *sub = cls; |
2554 | 2568 | ||
2555 | CustomPeerMap_put(sub->pull_map, peer); | 2569 | CustomPeerMap_put (sub->pull_map, peer); |
2556 | } | 2570 | } |
2557 | 2571 | ||
2558 | 2572 | ||
@@ -2566,17 +2580,17 @@ insert_in_pull_map(void *cls, | |||
2566 | * @param peer the peer to insert | 2580 | * @param peer the peer to insert |
2567 | */ | 2581 | */ |
2568 | static void | 2582 | static void |
2569 | insert_in_view_op(void *cls, | 2583 | insert_in_view_op (void *cls, |
2570 | const struct GNUNET_PeerIdentity *peer) | 2584 | const struct GNUNET_PeerIdentity *peer) |
2571 | { | 2585 | { |
2572 | struct Sub *sub = cls; | 2586 | struct Sub *sub = cls; |
2573 | int inserted; | 2587 | int inserted; |
2574 | 2588 | ||
2575 | inserted = insert_in_view(sub, peer); | 2589 | inserted = insert_in_view (sub, peer); |
2576 | if (GNUNET_OK == inserted) | 2590 | if (GNUNET_OK == inserted) |
2577 | { | 2591 | { |
2578 | clients_notify_stream_peer(sub, 1, peer); | 2592 | clients_notify_stream_peer (sub, 1, peer); |
2579 | } | 2593 | } |
2580 | } | 2594 | } |
2581 | 2595 | ||
2582 | 2596 | ||
@@ -2588,30 +2602,30 @@ insert_in_view_op(void *cls, | |||
2588 | * @param peer Peer to insert | 2602 | * @param peer Peer to insert |
2589 | */ | 2603 | */ |
2590 | static void | 2604 | static void |
2591 | insert_in_sampler(void *cls, | 2605 | insert_in_sampler (void *cls, |
2592 | const struct GNUNET_PeerIdentity *peer) | 2606 | const struct GNUNET_PeerIdentity *peer) |
2593 | { | 2607 | { |
2594 | struct Sub *sub = cls; | 2608 | struct Sub *sub = cls; |
2595 | 2609 | ||
2596 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2610 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2597 | "Updating samplers with peer %s from insert_in_sampler()\n", | 2611 | "Updating samplers with peer %s from insert_in_sampler()\n", |
2598 | GNUNET_i2s(peer)); | 2612 | GNUNET_i2s (peer)); |
2599 | RPS_sampler_update(sub->sampler, peer); | 2613 | RPS_sampler_update (sub->sampler, peer); |
2600 | if (0 < RPS_sampler_count_id(sub->sampler, peer)) | 2614 | if (0 < RPS_sampler_count_id (sub->sampler, peer)) |
2601 | { | 2615 | { |
2602 | /* Make sure we 'know' about this peer */ | 2616 | /* Make sure we 'know' about this peer */ |
2603 | (void)issue_peer_online_check(sub, peer); | 2617 | (void) issue_peer_online_check (sub, peer); |
2604 | /* Establish a channel towards that peer to indicate we are going to send | 2618 | /* Establish a channel towards that peer to indicate we are going to send |
2605 | * messages to it */ | 2619 | * messages to it */ |
2606 | //indicate_sending_intention (peer); | 2620 | // indicate_sending_intention (peer); |
2607 | } | 2621 | } |
2608 | if (sub == msub) | 2622 | if (sub == msub) |
2609 | { | 2623 | { |
2610 | GNUNET_STATISTICS_update(stats, | 2624 | GNUNET_STATISTICS_update (stats, |
2611 | "# observed peers in gossip", | 2625 | "# observed peers in gossip", |
2612 | 1, | 2626 | 1, |
2613 | GNUNET_NO); | 2627 | GNUNET_NO); |
2614 | } | 2628 | } |
2615 | #ifdef TO_FILE | 2629 | #ifdef TO_FILE |
2616 | sub->num_observed_peers++; | 2630 | sub->num_observed_peers++; |
2617 | GNUNET_CONTAINER_multipeermap_put | 2631 | GNUNET_CONTAINER_multipeermap_put |
@@ -2620,17 +2634,17 @@ insert_in_sampler(void *cls, | |||
2620 | NULL, | 2634 | NULL, |
2621 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 2635 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
2622 | uint32_t num_observed_unique_peers = | 2636 | uint32_t num_observed_unique_peers = |
2623 | GNUNET_CONTAINER_multipeermap_size(sub->observed_unique_peers); | 2637 | GNUNET_CONTAINER_multipeermap_size (sub->observed_unique_peers); |
2624 | GNUNET_STATISTICS_set(stats, | 2638 | GNUNET_STATISTICS_set (stats, |
2625 | "# unique peers in gossip", | 2639 | "# unique peers in gossip", |
2626 | num_observed_unique_peers, | 2640 | num_observed_unique_peers, |
2627 | GNUNET_NO); | 2641 | GNUNET_NO); |
2628 | #ifdef TO_FILE_FULL | 2642 | #ifdef TO_FILE_FULL |
2629 | to_file(sub->file_name_observed_log, | 2643 | to_file (sub->file_name_observed_log, |
2630 | "%" PRIu32 " %" PRIu32 " %f\n", | 2644 | "%" PRIu32 " %" PRIu32 " %f\n", |
2631 | sub->num_observed_peers, | 2645 | sub->num_observed_peers, |
2632 | num_observed_unique_peers, | 2646 | num_observed_unique_peers, |
2633 | 1.0 * num_observed_unique_peers / sub->num_observed_peers) | 2647 | 1.0 * num_observed_unique_peers / sub->num_observed_peers) |
2634 | #endif /* TO_FILE_FULL */ | 2648 | #endif /* TO_FILE_FULL */ |
2635 | #endif /* TO_FILE */ | 2649 | #endif /* TO_FILE */ |
2636 | } | 2650 | } |
@@ -2647,24 +2661,24 @@ insert_in_sampler(void *cls, | |||
2647 | * @param peer peer to insert/peer received | 2661 | * @param peer peer to insert/peer received |
2648 | */ | 2662 | */ |
2649 | static void | 2663 | static void |
2650 | got_peer(struct Sub *sub, | 2664 | got_peer (struct Sub *sub, |
2651 | const struct GNUNET_PeerIdentity *peer) | 2665 | const struct GNUNET_PeerIdentity *peer) |
2652 | { | 2666 | { |
2653 | /* If we did not know this peer already, insert it into sampler and view */ | 2667 | /* If we did not know this peer already, insert it into sampler and view */ |
2654 | if (GNUNET_YES == issue_peer_online_check(sub, peer)) | 2668 | if (GNUNET_YES == issue_peer_online_check (sub, peer)) |
2655 | { | 2669 | { |
2656 | schedule_operation(get_peer_ctx(sub->peer_map, peer), | 2670 | schedule_operation (get_peer_ctx (sub->peer_map, peer), |
2657 | &insert_in_sampler, sub); | 2671 | &insert_in_sampler, sub); |
2658 | schedule_operation(get_peer_ctx(sub->peer_map, peer), | 2672 | schedule_operation (get_peer_ctx (sub->peer_map, peer), |
2659 | &insert_in_view_op, sub); | 2673 | &insert_in_view_op, sub); |
2660 | } | 2674 | } |
2661 | if (sub == msub) | 2675 | if (sub == msub) |
2662 | { | 2676 | { |
2663 | GNUNET_STATISTICS_update(stats, | 2677 | GNUNET_STATISTICS_update (stats, |
2664 | "# learnd peers", | 2678 | "# learnd peers", |
2665 | 1, | 2679 | 1, |
2666 | GNUNET_NO); | 2680 | GNUNET_NO); |
2667 | } | 2681 | } |
2668 | } | 2682 | } |
2669 | 2683 | ||
2670 | 2684 | ||
@@ -2676,32 +2690,32 @@ got_peer(struct Sub *sub, | |||
2676 | * GNUNET_NO otherwise | 2690 | * GNUNET_NO otherwise |
2677 | */ | 2691 | */ |
2678 | static int | 2692 | static int |
2679 | check_sending_channel_needed(const struct PeerContext *peer_ctx) | 2693 | check_sending_channel_needed (const struct PeerContext *peer_ctx) |
2680 | { | 2694 | { |
2681 | /* struct GNUNET_CADET_Channel *channel; */ | 2695 | /* struct GNUNET_CADET_Channel *channel; */ |
2682 | if (GNUNET_NO == check_peer_known(peer_ctx->sub->peer_map, | 2696 | if (GNUNET_NO == check_peer_known (peer_ctx->sub->peer_map, |
2683 | &peer_ctx->peer_id)) | 2697 | &peer_ctx->peer_id)) |
2684 | { | 2698 | { |
2685 | return GNUNET_NO; | 2699 | return GNUNET_NO; |
2686 | } | 2700 | } |
2687 | if (GNUNET_YES == check_sending_channel_exists(peer_ctx)) | 2701 | if (GNUNET_YES == check_sending_channel_exists (peer_ctx)) |
2688 | { | 2702 | { |
2689 | if ((0 < RPS_sampler_count_id(peer_ctx->sub->sampler, | 2703 | if ((0 < RPS_sampler_count_id (peer_ctx->sub->sampler, |
2690 | &peer_ctx->peer_id)) || | 2704 | &peer_ctx->peer_id)) || |
2691 | (GNUNET_YES == View_contains_peer(peer_ctx->sub->view, | 2705 | (GNUNET_YES == View_contains_peer (peer_ctx->sub->view, |
2692 | &peer_ctx->peer_id)) || | 2706 | &peer_ctx->peer_id)) || |
2693 | (GNUNET_YES == CustomPeerMap_contains_peer(peer_ctx->sub->push_map, | 2707 | (GNUNET_YES == CustomPeerMap_contains_peer (peer_ctx->sub->push_map, |
2694 | &peer_ctx->peer_id)) || | 2708 | &peer_ctx->peer_id)) || |
2695 | (GNUNET_YES == CustomPeerMap_contains_peer(peer_ctx->sub->pull_map, | 2709 | (GNUNET_YES == CustomPeerMap_contains_peer (peer_ctx->sub->pull_map, |
2696 | &peer_ctx->peer_id)) || | 2710 | &peer_ctx->peer_id)) || |
2697 | (GNUNET_YES == check_peer_flag(peer_ctx->sub->peer_map, | 2711 | (GNUNET_YES == check_peer_flag (peer_ctx->sub->peer_map, |
2698 | &peer_ctx->peer_id, | 2712 | &peer_ctx->peer_id, |
2699 | Peers_PULL_REPLY_PENDING))) | 2713 | Peers_PULL_REPLY_PENDING))) |
2700 | { /* If we want to keep the connection to peer open */ | 2714 | { /* If we want to keep the connection to peer open */ |
2701 | return GNUNET_YES; | 2715 | return GNUNET_YES; |
2702 | } | ||
2703 | return GNUNET_NO; | ||
2704 | } | 2716 | } |
2717 | return GNUNET_NO; | ||
2718 | } | ||
2705 | return GNUNET_NO; | 2719 | return GNUNET_NO; |
2706 | } | 2720 | } |
2707 | 2721 | ||
@@ -2714,26 +2728,26 @@ check_sending_channel_needed(const struct PeerContext *peer_ctx) | |||
2714 | * @param peer the peer to remove | 2728 | * @param peer the peer to remove |
2715 | */ | 2729 | */ |
2716 | static void | 2730 | static void |
2717 | remove_peer(struct Sub *sub, | 2731 | remove_peer (struct Sub *sub, |
2718 | const struct GNUNET_PeerIdentity *peer) | 2732 | const struct GNUNET_PeerIdentity *peer) |
2719 | { | 2733 | { |
2720 | (void)View_remove_peer(sub->view, | 2734 | (void) View_remove_peer (sub->view, |
2721 | peer); | 2735 | peer); |
2722 | CustomPeerMap_remove_peer(sub->pull_map, | 2736 | CustomPeerMap_remove_peer (sub->pull_map, |
2723 | peer); | 2737 | peer); |
2724 | CustomPeerMap_remove_peer(sub->push_map, | 2738 | CustomPeerMap_remove_peer (sub->push_map, |
2725 | peer); | 2739 | peer); |
2726 | RPS_sampler_reinitialise_by_value(sub->sampler, | 2740 | RPS_sampler_reinitialise_by_value (sub->sampler, |
2727 | peer); | 2741 | peer); |
2728 | /* We want to destroy the peer now. | 2742 | /* We want to destroy the peer now. |
2729 | * Sometimes, it just seems that it's already been removed from the peer_map, | 2743 | * Sometimes, it just seems that it's already been removed from the peer_map, |
2730 | * so check the peer_map first. */ | 2744 | * so check the peer_map first. */ |
2731 | if (GNUNET_YES == check_peer_known(sub->peer_map, | 2745 | if (GNUNET_YES == check_peer_known (sub->peer_map, |
2732 | peer)) | 2746 | peer)) |
2733 | { | 2747 | { |
2734 | destroy_peer(get_peer_ctx(sub->peer_map, | 2748 | destroy_peer (get_peer_ctx (sub->peer_map, |
2735 | peer)); | 2749 | peer)); |
2736 | } | 2750 | } |
2737 | } | 2751 | } |
2738 | 2752 | ||
2739 | 2753 | ||
@@ -2746,49 +2760,49 @@ remove_peer(struct Sub *sub, | |||
2746 | * @param peer the peer whose data is about to be cleaned | 2760 | * @param peer the peer whose data is about to be cleaned |
2747 | */ | 2761 | */ |
2748 | static void | 2762 | static void |
2749 | clean_peer(struct Sub *sub, | 2763 | clean_peer (struct Sub *sub, |
2750 | const struct GNUNET_PeerIdentity *peer) | 2764 | const struct GNUNET_PeerIdentity *peer) |
2751 | { | 2765 | { |
2752 | if (GNUNET_NO == check_sending_channel_needed(get_peer_ctx(sub->peer_map, | 2766 | if (GNUNET_NO == check_sending_channel_needed (get_peer_ctx (sub->peer_map, |
2753 | peer))) | 2767 | peer))) |
2754 | { | 2768 | { |
2755 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2769 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2756 | "Going to remove send channel to peer %s\n", | 2770 | "Going to remove send channel to peer %s\n", |
2757 | GNUNET_i2s(peer)); | 2771 | GNUNET_i2s (peer)); |
2758 | #if ENABLE_MALICIOUS | 2772 | #if ENABLE_MALICIOUS |
2759 | if (0 != GNUNET_memcmp(&attacked_peer, | 2773 | if (0 != GNUNET_memcmp (&attacked_peer, |
2760 | peer)) | 2774 | peer)) |
2761 | (void)destroy_sending_channel(get_peer_ctx(sub->peer_map, | 2775 | (void) destroy_sending_channel (get_peer_ctx (sub->peer_map, |
2762 | peer)); | 2776 | peer)); |
2763 | #else /* ENABLE_MALICIOUS */ | 2777 | #else /* ENABLE_MALICIOUS */ |
2764 | (void)destroy_sending_channel(get_peer_ctx(sub->peer_map, | 2778 | (void) destroy_sending_channel (get_peer_ctx (sub->peer_map, |
2765 | peer)); | 2779 | peer)); |
2766 | #endif /* ENABLE_MALICIOUS */ | 2780 | #endif /* ENABLE_MALICIOUS */ |
2767 | } | 2781 | } |
2768 | 2782 | ||
2769 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(sub->peer_map, | 2783 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (sub->peer_map, |
2770 | peer)) | 2784 | peer)) |
2771 | { | 2785 | { |
2772 | /* Peer was already removed by callback on destroyed channel */ | 2786 | /* Peer was already removed by callback on destroyed channel */ |
2773 | LOG(GNUNET_ERROR_TYPE_WARNING, | 2787 | LOG (GNUNET_ERROR_TYPE_WARNING, |
2774 | "Peer was removed from our knowledge during cleanup\n"); | 2788 | "Peer was removed from our knowledge during cleanup\n"); |
2775 | return; | 2789 | return; |
2776 | } | 2790 | } |
2777 | 2791 | ||
2778 | if ((GNUNET_NO == check_peer_send_intention(get_peer_ctx(sub->peer_map, | 2792 | if ((GNUNET_NO == check_peer_send_intention (get_peer_ctx (sub->peer_map, |
2779 | peer))) && | 2793 | peer))) && |
2780 | (GNUNET_NO == View_contains_peer(sub->view, peer)) && | 2794 | (GNUNET_NO == View_contains_peer (sub->view, peer)) && |
2781 | (GNUNET_NO == CustomPeerMap_contains_peer(sub->push_map, peer)) && | 2795 | (GNUNET_NO == CustomPeerMap_contains_peer (sub->push_map, peer)) && |
2782 | (GNUNET_NO == CustomPeerMap_contains_peer(sub->push_map, peer)) && | 2796 | (GNUNET_NO == CustomPeerMap_contains_peer (sub->push_map, peer)) && |
2783 | (0 == RPS_sampler_count_id(sub->sampler, peer)) && | 2797 | (0 == RPS_sampler_count_id (sub->sampler, peer)) && |
2784 | (GNUNET_YES == check_removable(get_peer_ctx(sub->peer_map, peer)))) | 2798 | (GNUNET_YES == check_removable (get_peer_ctx (sub->peer_map, peer)))) |
2785 | { /* We can safely remove this peer */ | 2799 | { /* We can safely remove this peer */ |
2786 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2800 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2787 | "Going to remove peer %s\n", | 2801 | "Going to remove peer %s\n", |
2788 | GNUNET_i2s(peer)); | 2802 | GNUNET_i2s (peer)); |
2789 | remove_peer(sub, peer); | 2803 | remove_peer (sub, peer); |
2790 | return; | 2804 | return; |
2791 | } | 2805 | } |
2792 | } | 2806 | } |
2793 | 2807 | ||
2794 | 2808 | ||
@@ -2804,22 +2818,22 @@ clean_peer(struct Sub *sub, | |||
2804 | * @param channel The channel being closed | 2818 | * @param channel The channel being closed |
2805 | */ | 2819 | */ |
2806 | static void | 2820 | static void |
2807 | cleanup_destroyed_channel(void *cls, | 2821 | cleanup_destroyed_channel (void *cls, |
2808 | const struct GNUNET_CADET_Channel *channel) | 2822 | const struct GNUNET_CADET_Channel *channel) |
2809 | { | 2823 | { |
2810 | struct ChannelCtx *channel_ctx = cls; | 2824 | struct ChannelCtx *channel_ctx = cls; |
2811 | struct PeerContext *peer_ctx = channel_ctx->peer_ctx; | 2825 | struct PeerContext *peer_ctx = channel_ctx->peer_ctx; |
2812 | 2826 | ||
2813 | (void)channel; | 2827 | (void) channel; |
2814 | 2828 | ||
2815 | channel_ctx->channel = NULL; | 2829 | channel_ctx->channel = NULL; |
2816 | remove_channel_ctx(channel_ctx); | 2830 | remove_channel_ctx (channel_ctx); |
2817 | if (NULL != peer_ctx && | 2831 | if ((NULL != peer_ctx)&& |
2818 | peer_ctx->send_channel_ctx == channel_ctx && | 2832 | (peer_ctx->send_channel_ctx == channel_ctx) && |
2819 | GNUNET_YES == check_sending_channel_needed(channel_ctx->peer_ctx)) | 2833 | (GNUNET_YES == check_sending_channel_needed (channel_ctx->peer_ctx)) ) |
2820 | { | 2834 | { |
2821 | remove_peer(peer_ctx->sub, &peer_ctx->peer_id); | 2835 | remove_peer (peer_ctx->sub, &peer_ctx->peer_id); |
2822 | } | 2836 | } |
2823 | } | 2837 | } |
2824 | 2838 | ||
2825 | /*********************************************************************** | 2839 | /*********************************************************************** |
@@ -2843,119 +2857,119 @@ cleanup_destroyed_channel(void *cls, | |||
2843 | * @return Sub | 2857 | * @return Sub |
2844 | */ | 2858 | */ |
2845 | struct Sub * | 2859 | struct Sub * |
2846 | new_sub(const struct GNUNET_HashCode *hash, | 2860 | new_sub (const struct GNUNET_HashCode *hash, |
2847 | uint32_t sampler_size, | 2861 | uint32_t sampler_size, |
2848 | struct GNUNET_TIME_Relative round_interval) | 2862 | struct GNUNET_TIME_Relative round_interval) |
2849 | { | 2863 | { |
2850 | struct Sub *sub; | 2864 | struct Sub *sub; |
2851 | 2865 | ||
2852 | sub = GNUNET_new(struct Sub); | 2866 | sub = GNUNET_new (struct Sub); |
2853 | 2867 | ||
2854 | /* With the hash generated from the secret value this service only connects | 2868 | /* With the hash generated from the secret value this service only connects |
2855 | * to rps instances that share the value */ | 2869 | * to rps instances that share the value */ |
2856 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = { | 2870 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = { |
2857 | GNUNET_MQ_hd_fixed_size(peer_check, | 2871 | GNUNET_MQ_hd_fixed_size (peer_check, |
2858 | GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE, | 2872 | GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE, |
2859 | struct GNUNET_MessageHeader, | 2873 | struct GNUNET_MessageHeader, |
2860 | NULL), | 2874 | NULL), |
2861 | GNUNET_MQ_hd_fixed_size(peer_push, | 2875 | GNUNET_MQ_hd_fixed_size (peer_push, |
2862 | GNUNET_MESSAGE_TYPE_RPS_PP_PUSH, | 2876 | GNUNET_MESSAGE_TYPE_RPS_PP_PUSH, |
2863 | struct GNUNET_MessageHeader, | 2877 | struct GNUNET_MessageHeader, |
2864 | NULL), | 2878 | NULL), |
2865 | GNUNET_MQ_hd_fixed_size(peer_pull_request, | 2879 | GNUNET_MQ_hd_fixed_size (peer_pull_request, |
2866 | GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST, | 2880 | GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST, |
2867 | struct GNUNET_MessageHeader, | 2881 | struct GNUNET_MessageHeader, |
2868 | NULL), | 2882 | NULL), |
2869 | GNUNET_MQ_hd_var_size(peer_pull_reply, | 2883 | GNUNET_MQ_hd_var_size (peer_pull_reply, |
2870 | GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY, | 2884 | GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY, |
2871 | struct GNUNET_RPS_P2P_PullReplyMessage, | 2885 | struct GNUNET_RPS_P2P_PullReplyMessage, |
2872 | NULL), | 2886 | NULL), |
2873 | GNUNET_MQ_handler_end() | 2887 | GNUNET_MQ_handler_end () |
2874 | }; | 2888 | }; |
2875 | sub->hash = *hash; | 2889 | sub->hash = *hash; |
2876 | sub->cadet_port = | 2890 | sub->cadet_port = |
2877 | GNUNET_CADET_open_port(cadet_handle, | 2891 | GNUNET_CADET_open_port (cadet_handle, |
2878 | &sub->hash, | 2892 | &sub->hash, |
2879 | &handle_inbound_channel, /* Connect handler */ | 2893 | &handle_inbound_channel, /* Connect handler */ |
2880 | sub, /* cls */ | 2894 | sub, /* cls */ |
2881 | NULL, /* WindowSize handler */ | 2895 | NULL, /* WindowSize handler */ |
2882 | &cleanup_destroyed_channel, /* Disconnect handler */ | 2896 | &cleanup_destroyed_channel, /* Disconnect handler */ |
2883 | cadet_handlers); | 2897 | cadet_handlers); |
2884 | if (NULL == sub->cadet_port) | 2898 | if (NULL == sub->cadet_port) |
2885 | { | 2899 | { |
2886 | LOG(GNUNET_ERROR_TYPE_ERROR, | 2900 | LOG (GNUNET_ERROR_TYPE_ERROR, |
2887 | "Cadet port `%s' is already in use.\n", | 2901 | "Cadet port `%s' is already in use.\n", |
2888 | GNUNET_APPLICATION_PORT_RPS); | 2902 | GNUNET_APPLICATION_PORT_RPS); |
2889 | GNUNET_assert(0); | 2903 | GNUNET_assert (0); |
2890 | } | 2904 | } |
2891 | 2905 | ||
2892 | /* Set up general data structure to keep track about peers */ | 2906 | /* Set up general data structure to keep track about peers */ |
2893 | sub->valid_peers = GNUNET_CONTAINER_multipeermap_create(4, GNUNET_NO); | 2907 | sub->valid_peers = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO); |
2894 | if (GNUNET_OK != | 2908 | if (GNUNET_OK != |
2895 | GNUNET_CONFIGURATION_get_value_filename(cfg, | 2909 | GNUNET_CONFIGURATION_get_value_filename (cfg, |
2896 | "rps", | 2910 | "rps", |
2897 | "FILENAME_VALID_PEERS", | 2911 | "FILENAME_VALID_PEERS", |
2898 | &sub->filename_valid_peers)) | 2912 | &sub->filename_valid_peers)) |
2899 | { | 2913 | { |
2900 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, | 2914 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
2901 | "rps", | 2915 | "rps", |
2902 | "FILENAME_VALID_PEERS"); | 2916 | "FILENAME_VALID_PEERS"); |
2903 | } | 2917 | } |
2904 | if (0 != strncmp("DISABLE", sub->filename_valid_peers, 7)) | 2918 | if (0 != strncmp ("DISABLE", sub->filename_valid_peers, 7)) |
2905 | { | 2919 | { |
2906 | char *tmp_filename_valid_peers; | 2920 | char *tmp_filename_valid_peers; |
2907 | char str_hash[105]; | 2921 | char str_hash[105]; |
2908 | 2922 | ||
2909 | GNUNET_snprintf(str_hash, | 2923 | GNUNET_snprintf (str_hash, |
2910 | sizeof(str_hash), | 2924 | sizeof(str_hash), |
2911 | GNUNET_h2s_full(hash)); | 2925 | GNUNET_h2s_full (hash)); |
2912 | tmp_filename_valid_peers = sub->filename_valid_peers; | 2926 | tmp_filename_valid_peers = sub->filename_valid_peers; |
2913 | GNUNET_asprintf(&sub->filename_valid_peers, | 2927 | GNUNET_asprintf (&sub->filename_valid_peers, |
2914 | "%s%s", | 2928 | "%s%s", |
2915 | tmp_filename_valid_peers, | 2929 | tmp_filename_valid_peers, |
2916 | str_hash); | 2930 | str_hash); |
2917 | GNUNET_free(tmp_filename_valid_peers); | 2931 | GNUNET_free (tmp_filename_valid_peers); |
2918 | } | 2932 | } |
2919 | sub->peer_map = GNUNET_CONTAINER_multipeermap_create(4, GNUNET_NO); | 2933 | sub->peer_map = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO); |
2920 | 2934 | ||
2921 | /* Set up the sampler */ | 2935 | /* Set up the sampler */ |
2922 | sub->sampler_size_est_min = sampler_size; | 2936 | sub->sampler_size_est_min = sampler_size; |
2923 | sub->sampler_size_est_need = sampler_size;; | 2937 | sub->sampler_size_est_need = sampler_size;; |
2924 | LOG(GNUNET_ERROR_TYPE_DEBUG, "MINSIZE is %u\n", sub->sampler_size_est_min); | 2938 | LOG (GNUNET_ERROR_TYPE_DEBUG, "MINSIZE is %u\n", sub->sampler_size_est_min); |
2925 | GNUNET_assert(0 != round_interval.rel_value_us); | 2939 | GNUNET_assert (0 != round_interval.rel_value_us); |
2926 | sub->round_interval = round_interval; | 2940 | sub->round_interval = round_interval; |
2927 | sub->sampler = RPS_sampler_init(sampler_size, | 2941 | sub->sampler = RPS_sampler_init (sampler_size, |
2928 | round_interval); | 2942 | round_interval); |
2929 | 2943 | ||
2930 | /* Logging of internals */ | 2944 | /* Logging of internals */ |
2931 | #ifdef TO_FILE_FULL | 2945 | #ifdef TO_FILE_FULL |
2932 | sub->file_name_view_log = store_prefix_file_name(&own_identity, "view"); | 2946 | sub->file_name_view_log = store_prefix_file_name (&own_identity, "view"); |
2933 | #endif /* TO_FILE_FULL */ | 2947 | #endif /* TO_FILE_FULL */ |
2934 | #ifdef TO_FILE | 2948 | #ifdef TO_FILE |
2935 | #ifdef TO_FILE_FULL | 2949 | #ifdef TO_FILE_FULL |
2936 | sub->file_name_observed_log = store_prefix_file_name(&own_identity, | 2950 | sub->file_name_observed_log = store_prefix_file_name (&own_identity, |
2937 | "observed"); | 2951 | "observed"); |
2938 | #endif /* TO_FILE_FULL */ | 2952 | #endif /* TO_FILE_FULL */ |
2939 | sub->num_observed_peers = 0; | 2953 | sub->num_observed_peers = 0; |
2940 | sub->observed_unique_peers = GNUNET_CONTAINER_multipeermap_create(1, | 2954 | sub->observed_unique_peers = GNUNET_CONTAINER_multipeermap_create (1, |
2941 | GNUNET_NO); | 2955 | GNUNET_NO); |
2942 | #endif /* TO_FILE */ | 2956 | #endif /* TO_FILE */ |
2943 | 2957 | ||
2944 | /* Set up data structures for gossip */ | 2958 | /* Set up data structures for gossip */ |
2945 | sub->push_map = CustomPeerMap_create(4); | 2959 | sub->push_map = CustomPeerMap_create (4); |
2946 | sub->pull_map = CustomPeerMap_create(4); | 2960 | sub->pull_map = CustomPeerMap_create (4); |
2947 | sub->view_size_est_min = sampler_size;; | 2961 | sub->view_size_est_min = sampler_size;; |
2948 | sub->view = View_create(sub->view_size_est_min); | 2962 | sub->view = View_create (sub->view_size_est_min); |
2949 | if (sub == msub) | 2963 | if (sub == msub) |
2950 | { | 2964 | { |
2951 | GNUNET_STATISTICS_set(stats, | 2965 | GNUNET_STATISTICS_set (stats, |
2952 | "view size aim", | 2966 | "view size aim", |
2953 | sub->view_size_est_min, | 2967 | sub->view_size_est_min, |
2954 | GNUNET_NO); | 2968 | GNUNET_NO); |
2955 | } | 2969 | } |
2956 | 2970 | ||
2957 | /* Start executing rounds */ | 2971 | /* Start executing rounds */ |
2958 | sub->do_round_task = GNUNET_SCHEDULER_add_now(&do_round, sub); | 2972 | sub->do_round_task = GNUNET_SCHEDULER_add_now (&do_round, sub); |
2959 | 2973 | ||
2960 | return sub; | 2974 | return sub; |
2961 | } | 2975 | } |
@@ -2971,36 +2985,36 @@ new_sub(const struct GNUNET_HashCode *hash, | |||
2971 | * @param file_name file to dump into | 2985 | * @param file_name file to dump into |
2972 | */ | 2986 | */ |
2973 | static void | 2987 | static void |
2974 | write_histogram_to_file(const uint32_t hist_array[], | 2988 | write_histogram_to_file (const uint32_t hist_array[], |
2975 | const char *file_name) | 2989 | const char *file_name) |
2976 | { | 2990 | { |
2977 | char collect_str[SIZE_DUMP_FILE + 1] = ""; | 2991 | char collect_str[SIZE_DUMP_FILE + 1] = ""; |
2978 | char *recv_str_iter; | 2992 | char *recv_str_iter; |
2979 | char *file_name_full; | 2993 | char *file_name_full; |
2980 | 2994 | ||
2981 | recv_str_iter = collect_str; | 2995 | recv_str_iter = collect_str; |
2982 | file_name_full = store_prefix_file_name(&own_identity, | 2996 | file_name_full = store_prefix_file_name (&own_identity, |
2983 | file_name); | 2997 | file_name); |
2984 | for (uint32_t i = 0; i < HISTOGRAM_FILE_SLOTS; i++) | 2998 | for (uint32_t i = 0; i < HISTOGRAM_FILE_SLOTS; i++) |
2985 | { | 2999 | { |
2986 | char collect_str_tmp[8]; | 3000 | char collect_str_tmp[8]; |
2987 | 3001 | ||
2988 | GNUNET_snprintf(collect_str_tmp, | 3002 | GNUNET_snprintf (collect_str_tmp, |
2989 | sizeof(collect_str_tmp), | 3003 | sizeof(collect_str_tmp), |
2990 | "%" PRIu32 "\n", | 3004 | "%" PRIu32 "\n", |
2991 | hist_array[i]); | 3005 | hist_array[i]); |
2992 | recv_str_iter = stpncpy(recv_str_iter, | 3006 | recv_str_iter = stpncpy (recv_str_iter, |
2993 | collect_str_tmp, | 3007 | collect_str_tmp, |
2994 | 6); | 3008 | 6); |
2995 | } | 3009 | } |
2996 | (void)stpcpy(recv_str_iter, | 3010 | (void) stpcpy (recv_str_iter, |
2997 | "\n"); | 3011 | "\n"); |
2998 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 3012 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2999 | "Writing push stats to disk\n"); | 3013 | "Writing push stats to disk\n"); |
3000 | to_file_w_len(file_name_full, | 3014 | to_file_w_len (file_name_full, |
3001 | SIZE_DUMP_FILE, | 3015 | SIZE_DUMP_FILE, |
3002 | collect_str); | 3016 | collect_str); |
3003 | GNUNET_free(file_name_full); | 3017 | GNUNET_free (file_name_full); |
3004 | } | 3018 | } |
3005 | #endif /* TO_FILE */ | 3019 | #endif /* TO_FILE */ |
3006 | 3020 | ||
@@ -3011,56 +3025,56 @@ write_histogram_to_file(const uint32_t hist_array[], | |||
3011 | * @param sub Sub to destroy | 3025 | * @param sub Sub to destroy |
3012 | */ | 3026 | */ |
3013 | static void | 3027 | static void |
3014 | destroy_sub(struct Sub *sub) | 3028 | destroy_sub (struct Sub *sub) |
3015 | { | 3029 | { |
3016 | GNUNET_assert(NULL != sub); | 3030 | GNUNET_assert (NULL != sub); |
3017 | GNUNET_assert(NULL != sub->do_round_task); | 3031 | GNUNET_assert (NULL != sub->do_round_task); |
3018 | GNUNET_SCHEDULER_cancel(sub->do_round_task); | 3032 | GNUNET_SCHEDULER_cancel (sub->do_round_task); |
3019 | sub->do_round_task = NULL; | 3033 | sub->do_round_task = NULL; |
3020 | 3034 | ||
3021 | /* Disconnect from cadet */ | 3035 | /* Disconnect from cadet */ |
3022 | GNUNET_CADET_close_port(sub->cadet_port); | 3036 | GNUNET_CADET_close_port (sub->cadet_port); |
3023 | sub->cadet_port = NULL; | 3037 | sub->cadet_port = NULL; |
3024 | 3038 | ||
3025 | /* Clean up data structures for peers */ | 3039 | /* Clean up data structures for peers */ |
3026 | RPS_sampler_destroy(sub->sampler); | 3040 | RPS_sampler_destroy (sub->sampler); |
3027 | sub->sampler = NULL; | 3041 | sub->sampler = NULL; |
3028 | View_destroy(sub->view); | 3042 | View_destroy (sub->view); |
3029 | sub->view = NULL; | 3043 | sub->view = NULL; |
3030 | CustomPeerMap_destroy(sub->push_map); | 3044 | CustomPeerMap_destroy (sub->push_map); |
3031 | sub->push_map = NULL; | 3045 | sub->push_map = NULL; |
3032 | CustomPeerMap_destroy(sub->pull_map); | 3046 | CustomPeerMap_destroy (sub->pull_map); |
3033 | sub->pull_map = NULL; | 3047 | sub->pull_map = NULL; |
3034 | peers_terminate(sub); | 3048 | peers_terminate (sub); |
3035 | 3049 | ||
3036 | /* Free leftover data structures */ | 3050 | /* Free leftover data structures */ |
3037 | #ifdef TO_FILE_FULL | 3051 | #ifdef TO_FILE_FULL |
3038 | GNUNET_free(sub->file_name_view_log); | 3052 | GNUNET_free (sub->file_name_view_log); |
3039 | sub->file_name_view_log = NULL; | 3053 | sub->file_name_view_log = NULL; |
3040 | #endif /* TO_FILE_FULL */ | 3054 | #endif /* TO_FILE_FULL */ |
3041 | #ifdef TO_FILE | 3055 | #ifdef TO_FILE |
3042 | #ifdef TO_FILE_FULL | 3056 | #ifdef TO_FILE_FULL |
3043 | GNUNET_free(sub->file_name_observed_log); | 3057 | GNUNET_free (sub->file_name_observed_log); |
3044 | sub->file_name_observed_log = NULL; | 3058 | sub->file_name_observed_log = NULL; |
3045 | #endif /* TO_FILE_FULL */ | 3059 | #endif /* TO_FILE_FULL */ |
3046 | 3060 | ||
3047 | /* Write push frequencies to disk */ | 3061 | /* Write push frequencies to disk */ |
3048 | write_histogram_to_file(sub->push_recv, | 3062 | write_histogram_to_file (sub->push_recv, |
3049 | "push_recv"); | 3063 | "push_recv"); |
3050 | 3064 | ||
3051 | /* Write push deltas to disk */ | 3065 | /* Write push deltas to disk */ |
3052 | write_histogram_to_file(sub->push_delta, | 3066 | write_histogram_to_file (sub->push_delta, |
3053 | "push_delta"); | 3067 | "push_delta"); |
3054 | 3068 | ||
3055 | /* Write pull delays to disk */ | 3069 | /* Write pull delays to disk */ |
3056 | write_histogram_to_file(sub->pull_delays, | 3070 | write_histogram_to_file (sub->pull_delays, |
3057 | "pull_delays"); | 3071 | "pull_delays"); |
3058 | 3072 | ||
3059 | GNUNET_CONTAINER_multipeermap_destroy(sub->observed_unique_peers); | 3073 | GNUNET_CONTAINER_multipeermap_destroy (sub->observed_unique_peers); |
3060 | sub->observed_unique_peers = NULL; | 3074 | sub->observed_unique_peers = NULL; |
3061 | #endif /* TO_FILE */ | 3075 | #endif /* TO_FILE */ |
3062 | 3076 | ||
3063 | GNUNET_free(sub); | 3077 | GNUNET_free (sub); |
3064 | } | 3078 | } |
3065 | 3079 | ||
3066 | 3080 | ||
@@ -3080,13 +3094,13 @@ destroy_sub(struct Sub *sub) | |||
3080 | * @param my_identity - unused | 3094 | * @param my_identity - unused |
3081 | */ | 3095 | */ |
3082 | void | 3096 | void |
3083 | core_init(void *cls, | 3097 | core_init (void *cls, |
3084 | const struct GNUNET_PeerIdentity *my_identity) | 3098 | const struct GNUNET_PeerIdentity *my_identity) |
3085 | { | 3099 | { |
3086 | (void)cls; | 3100 | (void) cls; |
3087 | (void)my_identity; | 3101 | (void) my_identity; |
3088 | 3102 | ||
3089 | map_single_hop = GNUNET_CONTAINER_multipeermap_create(4, GNUNET_NO); | 3103 | map_single_hop = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO); |
3090 | } | 3104 | } |
3091 | 3105 | ||
3092 | 3106 | ||
@@ -3099,18 +3113,18 @@ core_init(void *cls, | |||
3099 | * @return closure given to #core_disconnects as peer_cls | 3113 | * @return closure given to #core_disconnects as peer_cls |
3100 | */ | 3114 | */ |
3101 | void * | 3115 | void * |
3102 | core_connects(void *cls, | 3116 | core_connects (void *cls, |
3103 | const struct GNUNET_PeerIdentity *peer, | 3117 | const struct GNUNET_PeerIdentity *peer, |
3104 | struct GNUNET_MQ_Handle *mq) | 3118 | struct GNUNET_MQ_Handle *mq) |
3105 | { | 3119 | { |
3106 | (void)cls; | 3120 | (void) cls; |
3107 | (void)mq; | 3121 | (void) mq; |
3108 | 3122 | ||
3109 | GNUNET_assert(GNUNET_YES == | 3123 | GNUNET_assert (GNUNET_YES == |
3110 | GNUNET_CONTAINER_multipeermap_put(map_single_hop, | 3124 | GNUNET_CONTAINER_multipeermap_put (map_single_hop, |
3111 | peer, | 3125 | peer, |
3112 | NULL, | 3126 | NULL, |
3113 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 3127 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
3114 | return NULL; | 3128 | return NULL; |
3115 | } | 3129 | } |
3116 | 3130 | ||
@@ -3124,14 +3138,14 @@ core_connects(void *cls, | |||
3124 | * @param peer_cls closure given in #core_connects - unused | 3138 | * @param peer_cls closure given in #core_connects - unused |
3125 | */ | 3139 | */ |
3126 | void | 3140 | void |
3127 | core_disconnects(void *cls, | 3141 | core_disconnects (void *cls, |
3128 | const struct GNUNET_PeerIdentity *peer, | 3142 | const struct GNUNET_PeerIdentity *peer, |
3129 | void *peer_cls) | 3143 | void *peer_cls) |
3130 | { | 3144 | { |
3131 | (void)cls; | 3145 | (void) cls; |
3132 | (void)peer_cls; | 3146 | (void) peer_cls; |
3133 | 3147 | ||
3134 | GNUNET_CONTAINER_multipeermap_remove_all(map_single_hop, peer); | 3148 | GNUNET_CONTAINER_multipeermap_remove_all (map_single_hop, peer); |
3135 | } | 3149 | } |
3136 | 3150 | ||
3137 | /*********************************************************************** | 3151 | /*********************************************************************** |
@@ -3145,18 +3159,18 @@ core_disconnects(void *cls, | |||
3145 | * @param cli_ctx Context to destroy | 3159 | * @param cli_ctx Context to destroy |
3146 | */ | 3160 | */ |
3147 | static void | 3161 | static void |
3148 | destroy_cli_ctx(struct ClientContext *cli_ctx) | 3162 | destroy_cli_ctx (struct ClientContext *cli_ctx) |
3149 | { | 3163 | { |
3150 | GNUNET_assert(NULL != cli_ctx); | 3164 | GNUNET_assert (NULL != cli_ctx); |
3151 | GNUNET_CONTAINER_DLL_remove(cli_ctx_head, | 3165 | GNUNET_CONTAINER_DLL_remove (cli_ctx_head, |
3152 | cli_ctx_tail, | 3166 | cli_ctx_tail, |
3153 | cli_ctx); | 3167 | cli_ctx); |
3154 | if (NULL != cli_ctx->sub) | 3168 | if (NULL != cli_ctx->sub) |
3155 | { | 3169 | { |
3156 | destroy_sub(cli_ctx->sub); | 3170 | destroy_sub (cli_ctx->sub); |
3157 | cli_ctx->sub = NULL; | 3171 | cli_ctx->sub = NULL; |
3158 | } | 3172 | } |
3159 | GNUNET_free(cli_ctx); | 3173 | GNUNET_free (cli_ctx); |
3160 | } | 3174 | } |
3161 | 3175 | ||
3162 | 3176 | ||
@@ -3168,44 +3182,44 @@ destroy_cli_ctx(struct ClientContext *cli_ctx) | |||
3168 | * @param std_dev standard deviation for the estimate | 3182 | * @param std_dev standard deviation for the estimate |
3169 | */ | 3183 | */ |
3170 | static void | 3184 | static void |
3171 | adapt_sizes(struct Sub *sub, double logestimate, double std_dev) | 3185 | adapt_sizes (struct Sub *sub, double logestimate, double std_dev) |
3172 | { | 3186 | { |
3173 | double estimate; | 3187 | double estimate; |
3174 | 3188 | ||
3175 | //double scale; // TODO this might go gloabal/config | 3189 | // double scale; // TODO this might go gloabal/config |
3176 | 3190 | ||
3177 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 3191 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3178 | "Received a ns estimate - logest: %f, std_dev: %f (old_size: %u)\n", | 3192 | "Received a ns estimate - logest: %f, std_dev: %f (old_size: %u)\n", |
3179 | logestimate, std_dev, RPS_sampler_get_size(sub->sampler)); | 3193 | logestimate, std_dev, RPS_sampler_get_size (sub->sampler)); |
3180 | //scale = .01; | 3194 | // scale = .01; |
3181 | estimate = GNUNET_NSE_log_estimate_to_n(logestimate); | 3195 | estimate = GNUNET_NSE_log_estimate_to_n (logestimate); |
3182 | // GNUNET_NSE_log_estimate_to_n (logestimate); | 3196 | // GNUNET_NSE_log_estimate_to_n (logestimate); |
3183 | estimate = pow(estimate, 1.0 / 3); | 3197 | estimate = pow (estimate, 1.0 / 3); |
3184 | // TODO add if std_dev is a number | 3198 | // TODO add if std_dev is a number |
3185 | // estimate += (std_dev * scale); | 3199 | // estimate += (std_dev * scale); |
3186 | if (sub->view_size_est_min < ceil(estimate)) | 3200 | if (sub->view_size_est_min < ceil (estimate)) |
3187 | { | 3201 | { |
3188 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Changing estimate to %f\n", estimate); | 3202 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Changing estimate to %f\n", estimate); |
3189 | sub->sampler_size_est_need = estimate; | 3203 | sub->sampler_size_est_need = estimate; |
3190 | sub->view_size_est_need = estimate; | 3204 | sub->view_size_est_need = estimate; |
3191 | } | 3205 | } |
3192 | else | 3206 | else |
3193 | { | 3207 | { |
3194 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Not using estimate %f\n", estimate); | 3208 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Not using estimate %f\n", estimate); |
3195 | //sub->sampler_size_est_need = sub->view_size_est_min; | 3209 | // sub->sampler_size_est_need = sub->view_size_est_min; |
3196 | sub->view_size_est_need = sub->view_size_est_min; | 3210 | sub->view_size_est_need = sub->view_size_est_min; |
3197 | } | 3211 | } |
3198 | if (sub == msub) | 3212 | if (sub == msub) |
3199 | { | 3213 | { |
3200 | GNUNET_STATISTICS_set(stats, | 3214 | GNUNET_STATISTICS_set (stats, |
3201 | "view size aim", | 3215 | "view size aim", |
3202 | sub->view_size_est_need, | 3216 | sub->view_size_est_need, |
3203 | GNUNET_NO); | 3217 | GNUNET_NO); |
3204 | } | 3218 | } |
3205 | 3219 | ||
3206 | /* If the NSE has changed adapt the lists accordingly */ | 3220 | /* If the NSE has changed adapt the lists accordingly */ |
3207 | resize_wrapper(sub->sampler, sub->sampler_size_est_need); | 3221 | resize_wrapper (sub->sampler, sub->sampler_size_est_need); |
3208 | View_change_len(sub->view, sub->view_size_est_need); | 3222 | View_change_len (sub->view, sub->view_size_est_need); |
3209 | } | 3223 | } |
3210 | 3224 | ||
3211 | 3225 | ||
@@ -3223,24 +3237,24 @@ adapt_sizes(struct Sub *sub, double logestimate, double std_dev) | |||
3223 | * @param std_dev standard deviation for the estimate | 3237 | * @param std_dev standard deviation for the estimate |
3224 | */ | 3238 | */ |
3225 | static void | 3239 | static void |
3226 | nse_callback(void *cls, | 3240 | nse_callback (void *cls, |
3227 | struct GNUNET_TIME_Absolute timestamp, | 3241 | struct GNUNET_TIME_Absolute timestamp, |
3228 | double logestimate, double std_dev) | 3242 | double logestimate, double std_dev) |
3229 | { | 3243 | { |
3230 | (void)cls; | 3244 | (void) cls; |
3231 | (void)timestamp; | 3245 | (void) timestamp; |
3232 | struct ClientContext *cli_ctx_iter; | 3246 | struct ClientContext *cli_ctx_iter; |
3233 | 3247 | ||
3234 | adapt_sizes(msub, logestimate, std_dev); | 3248 | adapt_sizes (msub, logestimate, std_dev); |
3235 | for (cli_ctx_iter = cli_ctx_head; | 3249 | for (cli_ctx_iter = cli_ctx_head; |
3236 | NULL != cli_ctx_iter; | 3250 | NULL != cli_ctx_iter; |
3237 | cli_ctx_iter = cli_ctx_iter->next) | 3251 | cli_ctx_iter = cli_ctx_iter->next) |
3252 | { | ||
3253 | if (NULL != cli_ctx_iter->sub) | ||
3238 | { | 3254 | { |
3239 | if (NULL != cli_ctx_iter->sub) | 3255 | adapt_sizes (cli_ctx_iter->sub, logestimate, std_dev); |
3240 | { | ||
3241 | adapt_sizes(cli_ctx_iter->sub, logestimate, std_dev); | ||
3242 | } | ||
3243 | } | 3256 | } |
3257 | } | ||
3244 | } | 3258 | } |
3245 | 3259 | ||
3246 | 3260 | ||
@@ -3254,24 +3268,24 @@ nse_callback(void *cls, | |||
3254 | * #GNUNET_SYSERR otherwise | 3268 | * #GNUNET_SYSERR otherwise |
3255 | */ | 3269 | */ |
3256 | static int | 3270 | static int |
3257 | check_client_seed(void *cls, const struct GNUNET_RPS_CS_SeedMessage *msg) | 3271 | check_client_seed (void *cls, const struct GNUNET_RPS_CS_SeedMessage *msg) |
3258 | { | 3272 | { |
3259 | struct ClientContext *cli_ctx = cls; | 3273 | struct ClientContext *cli_ctx = cls; |
3260 | uint16_t msize = ntohs(msg->header.size); | 3274 | uint16_t msize = ntohs (msg->header.size); |
3261 | uint32_t num_peers = ntohl(msg->num_peers); | 3275 | uint32_t num_peers = ntohl (msg->num_peers); |
3262 | 3276 | ||
3263 | msize -= sizeof(struct GNUNET_RPS_CS_SeedMessage); | 3277 | msize -= sizeof(struct GNUNET_RPS_CS_SeedMessage); |
3264 | if ((msize / sizeof(struct GNUNET_PeerIdentity) != num_peers) || | 3278 | if ((msize / sizeof(struct GNUNET_PeerIdentity) != num_peers) || |
3265 | (msize % sizeof(struct GNUNET_PeerIdentity) != 0)) | 3279 | (msize % sizeof(struct GNUNET_PeerIdentity) != 0)) |
3266 | { | 3280 | { |
3267 | LOG(GNUNET_ERROR_TYPE_ERROR, | 3281 | LOG (GNUNET_ERROR_TYPE_ERROR, |
3268 | "message says it sends %" PRIu32 " peers, have space for %lu peers\n", | 3282 | "message says it sends %" PRIu32 " peers, have space for %lu peers\n", |
3269 | ntohl(msg->num_peers), | 3283 | ntohl (msg->num_peers), |
3270 | (msize / sizeof(struct GNUNET_PeerIdentity))); | 3284 | (msize / sizeof(struct GNUNET_PeerIdentity))); |
3271 | GNUNET_break(0); | 3285 | GNUNET_break (0); |
3272 | GNUNET_SERVICE_client_drop(cli_ctx->client); | 3286 | GNUNET_SERVICE_client_drop (cli_ctx->client); |
3273 | return GNUNET_SYSERR; | 3287 | return GNUNET_SYSERR; |
3274 | } | 3288 | } |
3275 | return GNUNET_OK; | 3289 | return GNUNET_OK; |
3276 | } | 3290 | } |
3277 | 3291 | ||
@@ -3283,34 +3297,34 @@ check_client_seed(void *cls, const struct GNUNET_RPS_CS_SeedMessage *msg) | |||
3283 | * @param message the actual message | 3297 | * @param message the actual message |
3284 | */ | 3298 | */ |
3285 | static void | 3299 | static void |
3286 | handle_client_seed(void *cls, | 3300 | handle_client_seed (void *cls, |
3287 | const struct GNUNET_RPS_CS_SeedMessage *msg) | 3301 | const struct GNUNET_RPS_CS_SeedMessage *msg) |
3288 | { | 3302 | { |
3289 | struct ClientContext *cli_ctx = cls; | 3303 | struct ClientContext *cli_ctx = cls; |
3290 | struct GNUNET_PeerIdentity *peers; | 3304 | struct GNUNET_PeerIdentity *peers; |
3291 | uint32_t num_peers; | 3305 | uint32_t num_peers; |
3292 | uint32_t i; | 3306 | uint32_t i; |
3293 | 3307 | ||
3294 | num_peers = ntohl(msg->num_peers); | 3308 | num_peers = ntohl (msg->num_peers); |
3295 | peers = (struct GNUNET_PeerIdentity *)&msg[1]; | 3309 | peers = (struct GNUNET_PeerIdentity *) &msg[1]; |
3296 | 3310 | ||
3297 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 3311 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3298 | "Client seeded peers:\n"); | 3312 | "Client seeded peers:\n"); |
3299 | print_peer_list(peers, num_peers); | 3313 | print_peer_list (peers, num_peers); |
3300 | 3314 | ||
3301 | for (i = 0; i < num_peers; i++) | 3315 | for (i = 0; i < num_peers; i++) |
3302 | { | 3316 | { |
3303 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 3317 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3304 | "Updating samplers with seed %" PRIu32 ": %s\n", | 3318 | "Updating samplers with seed %" PRIu32 ": %s\n", |
3305 | i, | 3319 | i, |
3306 | GNUNET_i2s(&peers[i])); | 3320 | GNUNET_i2s (&peers[i])); |
3307 | 3321 | ||
3308 | if (NULL != msub) | 3322 | if (NULL != msub) |
3309 | got_peer(msub, &peers[i]); /* Condition needed? */ | 3323 | got_peer (msub, &peers[i]); /* Condition needed? */ |
3310 | if (NULL != cli_ctx->sub) | 3324 | if (NULL != cli_ctx->sub) |
3311 | got_peer(cli_ctx->sub, &peers[i]); | 3325 | got_peer (cli_ctx->sub, &peers[i]); |
3312 | } | 3326 | } |
3313 | GNUNET_SERVICE_client_continue(cli_ctx->client); | 3327 | GNUNET_SERVICE_client_continue (cli_ctx->client); |
3314 | } | 3328 | } |
3315 | 3329 | ||
3316 | 3330 | ||
@@ -3322,22 +3336,22 @@ handle_client_seed(void *cls, | |||
3322 | * receive | 3336 | * receive |
3323 | */ | 3337 | */ |
3324 | static void | 3338 | static void |
3325 | handle_client_view_request(void *cls, | 3339 | handle_client_view_request (void *cls, |
3326 | const struct GNUNET_RPS_CS_DEBUG_ViewRequest *msg) | 3340 | const struct GNUNET_RPS_CS_DEBUG_ViewRequest *msg) |
3327 | { | 3341 | { |
3328 | struct ClientContext *cli_ctx = cls; | 3342 | struct ClientContext *cli_ctx = cls; |
3329 | uint64_t num_updates; | 3343 | uint64_t num_updates; |
3330 | 3344 | ||
3331 | num_updates = ntohl(msg->num_updates); | 3345 | num_updates = ntohl (msg->num_updates); |
3332 | 3346 | ||
3333 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 3347 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3334 | "Client requested %" PRIu64 " updates of view.\n", | 3348 | "Client requested %" PRIu64 " updates of view.\n", |
3335 | num_updates); | 3349 | num_updates); |
3336 | 3350 | ||
3337 | GNUNET_assert(NULL != cli_ctx); | 3351 | GNUNET_assert (NULL != cli_ctx); |
3338 | cli_ctx->view_updates_left = num_updates; | 3352 | cli_ctx->view_updates_left = num_updates; |
3339 | send_view(cli_ctx, NULL, 0); | 3353 | send_view (cli_ctx, NULL, 0); |
3340 | GNUNET_SERVICE_client_continue(cli_ctx->client); | 3354 | GNUNET_SERVICE_client_continue (cli_ctx->client); |
3341 | } | 3355 | } |
3342 | 3356 | ||
3343 | 3357 | ||
@@ -3348,23 +3362,23 @@ handle_client_view_request(void *cls, | |||
3348 | * @param msg Unused | 3362 | * @param msg Unused |
3349 | */ | 3363 | */ |
3350 | static void | 3364 | static void |
3351 | handle_client_view_cancel(void *cls, | 3365 | handle_client_view_cancel (void *cls, |
3352 | const struct GNUNET_MessageHeader *msg) | 3366 | const struct GNUNET_MessageHeader *msg) |
3353 | { | 3367 | { |
3354 | struct ClientContext *cli_ctx = cls; | 3368 | struct ClientContext *cli_ctx = cls; |
3355 | 3369 | ||
3356 | (void)msg; | 3370 | (void) msg; |
3357 | 3371 | ||
3358 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 3372 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3359 | "Client does not want to receive updates of view any more.\n"); | 3373 | "Client does not want to receive updates of view any more.\n"); |
3360 | 3374 | ||
3361 | GNUNET_assert(NULL != cli_ctx); | 3375 | GNUNET_assert (NULL != cli_ctx); |
3362 | cli_ctx->view_updates_left = 0; | 3376 | cli_ctx->view_updates_left = 0; |
3363 | GNUNET_SERVICE_client_continue(cli_ctx->client); | 3377 | GNUNET_SERVICE_client_continue (cli_ctx->client); |
3364 | if (GNUNET_YES == cli_ctx->stream_update) | 3378 | if (GNUNET_YES == cli_ctx->stream_update) |
3365 | { | 3379 | { |
3366 | destroy_cli_ctx(cli_ctx); | 3380 | destroy_cli_ctx (cli_ctx); |
3367 | } | 3381 | } |
3368 | } | 3382 | } |
3369 | 3383 | ||
3370 | 3384 | ||
@@ -3375,19 +3389,20 @@ handle_client_view_cancel(void *cls, | |||
3375 | * @param message unused | 3389 | * @param message unused |
3376 | */ | 3390 | */ |
3377 | static void | 3391 | static void |
3378 | handle_client_stream_request(void *cls, | 3392 | handle_client_stream_request (void *cls, |
3379 | const struct GNUNET_RPS_CS_DEBUG_StreamRequest *msg) | 3393 | const struct |
3394 | GNUNET_RPS_CS_DEBUG_StreamRequest *msg) | ||
3380 | { | 3395 | { |
3381 | struct ClientContext *cli_ctx = cls; | 3396 | struct ClientContext *cli_ctx = cls; |
3382 | 3397 | ||
3383 | (void)msg; | 3398 | (void) msg; |
3384 | 3399 | ||
3385 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 3400 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3386 | "Client requested peers from biased stream.\n"); | 3401 | "Client requested peers from biased stream.\n"); |
3387 | cli_ctx->stream_update = GNUNET_YES; | 3402 | cli_ctx->stream_update = GNUNET_YES; |
3388 | 3403 | ||
3389 | GNUNET_assert(NULL != cli_ctx); | 3404 | GNUNET_assert (NULL != cli_ctx); |
3390 | GNUNET_SERVICE_client_continue(cli_ctx->client); | 3405 | GNUNET_SERVICE_client_continue (cli_ctx->client); |
3391 | } | 3406 | } |
3392 | 3407 | ||
3393 | 3408 | ||
@@ -3398,19 +3413,19 @@ handle_client_stream_request(void *cls, | |||
3398 | * @param msg unused | 3413 | * @param msg unused |
3399 | */ | 3414 | */ |
3400 | static void | 3415 | static void |
3401 | handle_client_stream_cancel(void *cls, | 3416 | handle_client_stream_cancel (void *cls, |
3402 | const struct GNUNET_MessageHeader *msg) | 3417 | const struct GNUNET_MessageHeader *msg) |
3403 | { | 3418 | { |
3404 | struct ClientContext *cli_ctx = cls; | 3419 | struct ClientContext *cli_ctx = cls; |
3405 | 3420 | ||
3406 | (void)msg; | 3421 | (void) msg; |
3407 | 3422 | ||
3408 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 3423 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3409 | "Client canceled receiving peers from biased stream.\n"); | 3424 | "Client canceled receiving peers from biased stream.\n"); |
3410 | cli_ctx->stream_update = GNUNET_NO; | 3425 | cli_ctx->stream_update = GNUNET_NO; |
3411 | 3426 | ||
3412 | GNUNET_assert(NULL != cli_ctx); | 3427 | GNUNET_assert (NULL != cli_ctx); |
3413 | GNUNET_SERVICE_client_continue(cli_ctx->client); | 3428 | GNUNET_SERVICE_client_continue (cli_ctx->client); |
3414 | } | 3429 | } |
3415 | 3430 | ||
3416 | 3431 | ||
@@ -3421,25 +3436,26 @@ handle_client_stream_cancel(void *cls, | |||
3421 | * @param msg Message containing the necessary information | 3436 | * @param msg Message containing the necessary information |
3422 | */ | 3437 | */ |
3423 | static void | 3438 | static void |
3424 | handle_client_start_sub(void *cls, | 3439 | handle_client_start_sub (void *cls, |
3425 | const struct GNUNET_RPS_CS_SubStartMessage *msg) | 3440 | const struct GNUNET_RPS_CS_SubStartMessage *msg) |
3426 | { | 3441 | { |
3427 | struct ClientContext *cli_ctx = cls; | 3442 | struct ClientContext *cli_ctx = cls; |
3428 | 3443 | ||
3429 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Client requested start of a new sub.\n"); | 3444 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Client requested start of a new sub.\n"); |
3430 | if (NULL != cli_ctx->sub && | 3445 | if ((NULL != cli_ctx->sub)&& |
3431 | 0 != memcmp(&cli_ctx->sub->hash, | 3446 | (0 != memcmp (&cli_ctx->sub->hash, |
3432 | &msg->hash, | 3447 | &msg->hash, |
3433 | sizeof(struct GNUNET_HashCode))) | 3448 | sizeof(struct GNUNET_HashCode))) ) |
3434 | { | 3449 | { |
3435 | LOG(GNUNET_ERROR_TYPE_WARNING, "Already have a Sub with different share for this client. Remove old one, add new.\n"); | 3450 | LOG (GNUNET_ERROR_TYPE_WARNING, |
3436 | destroy_sub(cli_ctx->sub); | 3451 | "Already have a Sub with different share for this client. Remove old one, add new.\n"); |
3437 | cli_ctx->sub = NULL; | 3452 | destroy_sub (cli_ctx->sub); |
3438 | } | 3453 | cli_ctx->sub = NULL; |
3439 | cli_ctx->sub = new_sub(&msg->hash, | 3454 | } |
3440 | msub->sampler_size_est_min, // TODO make api input? | 3455 | cli_ctx->sub = new_sub (&msg->hash, |
3441 | GNUNET_TIME_relative_ntoh(msg->round_interval)); | 3456 | msub->sampler_size_est_min, // TODO make api input? |
3442 | GNUNET_SERVICE_client_continue(cli_ctx->client); | 3457 | GNUNET_TIME_relative_ntoh (msg->round_interval)); |
3458 | GNUNET_SERVICE_client_continue (cli_ctx->client); | ||
3443 | } | 3459 | } |
3444 | 3460 | ||
3445 | 3461 | ||
@@ -3450,19 +3466,21 @@ handle_client_start_sub(void *cls, | |||
3450 | * @param msg Message containing the hash that identifies the Sub | 3466 | * @param msg Message containing the hash that identifies the Sub |
3451 | */ | 3467 | */ |
3452 | static void | 3468 | static void |
3453 | handle_client_stop_sub(void *cls, | 3469 | handle_client_stop_sub (void *cls, |
3454 | const struct GNUNET_RPS_CS_SubStopMessage *msg) | 3470 | const struct GNUNET_RPS_CS_SubStopMessage *msg) |
3455 | { | 3471 | { |
3456 | struct ClientContext *cli_ctx = cls; | 3472 | struct ClientContext *cli_ctx = cls; |
3457 | 3473 | ||
3458 | GNUNET_assert(NULL != cli_ctx->sub); | 3474 | GNUNET_assert (NULL != cli_ctx->sub); |
3459 | if (0 != memcmp(&cli_ctx->sub->hash, &msg->hash, sizeof(struct GNUNET_HashCode))) | 3475 | if (0 != memcmp (&cli_ctx->sub->hash, &msg->hash, sizeof(struct |
3460 | { | 3476 | GNUNET_HashCode))) |
3461 | LOG(GNUNET_ERROR_TYPE_WARNING, "Share of current sub and request differ!\n"); | 3477 | { |
3462 | } | 3478 | LOG (GNUNET_ERROR_TYPE_WARNING, |
3463 | destroy_sub(cli_ctx->sub); | 3479 | "Share of current sub and request differ!\n"); |
3480 | } | ||
3481 | destroy_sub (cli_ctx->sub); | ||
3464 | cli_ctx->sub = NULL; | 3482 | cli_ctx->sub = NULL; |
3465 | GNUNET_SERVICE_client_continue(cli_ctx->client); | 3483 | GNUNET_SERVICE_client_continue (cli_ctx->client); |
3466 | } | 3484 | } |
3467 | 3485 | ||
3468 | 3486 | ||
@@ -3476,25 +3494,25 @@ handle_client_stop_sub(void *cls, | |||
3476 | * @param msg Message - unused | 3494 | * @param msg Message - unused |
3477 | */ | 3495 | */ |
3478 | static void | 3496 | static void |
3479 | handle_peer_check(void *cls, | 3497 | handle_peer_check (void *cls, |
3480 | const struct GNUNET_MessageHeader *msg) | 3498 | const struct GNUNET_MessageHeader *msg) |
3481 | { | 3499 | { |
3482 | const struct ChannelCtx *channel_ctx = cls; | 3500 | const struct ChannelCtx *channel_ctx = cls; |
3483 | const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id; | 3501 | const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id; |
3484 | 3502 | ||
3485 | (void)msg; | 3503 | (void) msg; |
3486 | 3504 | ||
3487 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 3505 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3488 | "Received CHECK_LIVE (%s)\n", GNUNET_i2s(peer)); | 3506 | "Received CHECK_LIVE (%s)\n", GNUNET_i2s (peer)); |
3489 | if (channel_ctx->peer_ctx->sub == msub) | 3507 | if (channel_ctx->peer_ctx->sub == msub) |
3490 | { | 3508 | { |
3491 | GNUNET_STATISTICS_update(stats, | 3509 | GNUNET_STATISTICS_update (stats, |
3492 | "# pending online checks", | 3510 | "# pending online checks", |
3493 | -1, | 3511 | -1, |
3494 | GNUNET_NO); | 3512 | GNUNET_NO); |
3495 | } | 3513 | } |
3496 | 3514 | ||
3497 | GNUNET_CADET_receive_done(channel_ctx->channel); | 3515 | GNUNET_CADET_receive_done (channel_ctx->channel); |
3498 | } | 3516 | } |
3499 | 3517 | ||
3500 | 3518 | ||
@@ -3508,70 +3526,70 @@ handle_peer_check(void *cls, | |||
3508 | * @param msg Message - unused | 3526 | * @param msg Message - unused |
3509 | */ | 3527 | */ |
3510 | static void | 3528 | static void |
3511 | handle_peer_push(void *cls, | 3529 | handle_peer_push (void *cls, |
3512 | const struct GNUNET_MessageHeader *msg) | 3530 | const struct GNUNET_MessageHeader *msg) |
3513 | { | 3531 | { |
3514 | const struct ChannelCtx *channel_ctx = cls; | 3532 | const struct ChannelCtx *channel_ctx = cls; |
3515 | const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id; | 3533 | const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id; |
3516 | 3534 | ||
3517 | (void)msg; | 3535 | (void) msg; |
3518 | 3536 | ||
3519 | // (check the proof of work (?)) | 3537 | // (check the proof of work (?)) |
3520 | 3538 | ||
3521 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 3539 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3522 | "Received PUSH (%s)\n", | 3540 | "Received PUSH (%s)\n", |
3523 | GNUNET_i2s(peer)); | 3541 | GNUNET_i2s (peer)); |
3524 | if (channel_ctx->peer_ctx->sub == msub) | 3542 | if (channel_ctx->peer_ctx->sub == msub) |
3543 | { | ||
3544 | GNUNET_STATISTICS_update (stats, "# push message received", 1, GNUNET_NO); | ||
3545 | if ((NULL != map_single_hop) && | ||
3546 | (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (map_single_hop, | ||
3547 | peer))) | ||
3525 | { | 3548 | { |
3526 | GNUNET_STATISTICS_update(stats, "# push message received", 1, GNUNET_NO); | 3549 | GNUNET_STATISTICS_update (stats, |
3527 | if (NULL != map_single_hop && | 3550 | "# push message received (multi-hop peer)", |
3528 | GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(map_single_hop, | 3551 | 1, |
3529 | peer)) | 3552 | GNUNET_NO); |
3530 | { | ||
3531 | GNUNET_STATISTICS_update(stats, | ||
3532 | "# push message received (multi-hop peer)", | ||
3533 | 1, | ||
3534 | GNUNET_NO); | ||
3535 | } | ||
3536 | } | 3553 | } |
3554 | } | ||
3537 | 3555 | ||
3538 | #if ENABLE_MALICIOUS | 3556 | #if ENABLE_MALICIOUS |
3539 | struct AttackedPeer *tmp_att_peer; | 3557 | struct AttackedPeer *tmp_att_peer; |
3540 | 3558 | ||
3541 | if ((1 == mal_type) || | 3559 | if ((1 == mal_type) || |
3542 | (3 == mal_type)) | 3560 | (3 == mal_type)) |
3543 | { /* Try to maximise representation */ | 3561 | { /* Try to maximise representation */ |
3544 | tmp_att_peer = GNUNET_new(struct AttackedPeer); | 3562 | tmp_att_peer = GNUNET_new (struct AttackedPeer); |
3545 | tmp_att_peer->peer_id = *peer; | 3563 | tmp_att_peer->peer_id = *peer; |
3546 | if (NULL == att_peer_set) | 3564 | if (NULL == att_peer_set) |
3547 | att_peer_set = GNUNET_CONTAINER_multipeermap_create(1, GNUNET_NO); | 3565 | att_peer_set = GNUNET_CONTAINER_multipeermap_create (1, GNUNET_NO); |
3548 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(att_peer_set, | 3566 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (att_peer_set, |
3549 | peer)) | 3567 | peer)) |
3550 | { | 3568 | { |
3551 | GNUNET_CONTAINER_DLL_insert(att_peers_head, | 3569 | GNUNET_CONTAINER_DLL_insert (att_peers_head, |
3552 | att_peers_tail, | 3570 | att_peers_tail, |
3553 | tmp_att_peer); | 3571 | tmp_att_peer); |
3554 | add_peer_array_to_set(peer, 1, att_peer_set); | 3572 | add_peer_array_to_set (peer, 1, att_peer_set); |
3555 | } | ||
3556 | else | ||
3557 | { | ||
3558 | GNUNET_free(tmp_att_peer); | ||
3559 | } | ||
3560 | } | 3573 | } |
3574 | else | ||
3575 | { | ||
3576 | GNUNET_free (tmp_att_peer); | ||
3577 | } | ||
3578 | } | ||
3561 | 3579 | ||
3562 | 3580 | ||
3563 | else if (2 == mal_type) | 3581 | else if (2 == mal_type) |
3564 | { | 3582 | { |
3565 | /* We attack one single well-known peer - simply ignore */ | 3583 | /* We attack one single well-known peer - simply ignore */ |
3566 | } | 3584 | } |
3567 | #endif /* ENABLE_MALICIOUS */ | 3585 | #endif /* ENABLE_MALICIOUS */ |
3568 | 3586 | ||
3569 | /* Add the sending peer to the push_map */ | 3587 | /* Add the sending peer to the push_map */ |
3570 | CustomPeerMap_put(channel_ctx->peer_ctx->sub->push_map, peer); | 3588 | CustomPeerMap_put (channel_ctx->peer_ctx->sub->push_map, peer); |
3571 | 3589 | ||
3572 | GNUNET_break_op(check_peer_known(channel_ctx->peer_ctx->sub->peer_map, | 3590 | GNUNET_break_op (check_peer_known (channel_ctx->peer_ctx->sub->peer_map, |
3573 | &channel_ctx->peer_ctx->peer_id)); | 3591 | &channel_ctx->peer_ctx->peer_id)); |
3574 | GNUNET_CADET_receive_done(channel_ctx->channel); | 3592 | GNUNET_CADET_receive_done (channel_ctx->channel); |
3575 | } | 3593 | } |
3576 | 3594 | ||
3577 | 3595 | ||
@@ -3584,57 +3602,58 @@ handle_peer_push(void *cls, | |||
3584 | * @param msg Message - unused | 3602 | * @param msg Message - unused |
3585 | */ | 3603 | */ |
3586 | static void | 3604 | static void |
3587 | handle_peer_pull_request(void *cls, | 3605 | handle_peer_pull_request (void *cls, |
3588 | const struct GNUNET_MessageHeader *msg) | 3606 | const struct GNUNET_MessageHeader *msg) |
3589 | { | 3607 | { |
3590 | const struct ChannelCtx *channel_ctx = cls; | 3608 | const struct ChannelCtx *channel_ctx = cls; |
3591 | struct PeerContext *peer_ctx = channel_ctx->peer_ctx; | 3609 | struct PeerContext *peer_ctx = channel_ctx->peer_ctx; |
3592 | const struct GNUNET_PeerIdentity *peer = &peer_ctx->peer_id; | 3610 | const struct GNUNET_PeerIdentity *peer = &peer_ctx->peer_id; |
3593 | const struct GNUNET_PeerIdentity *view_array; | 3611 | const struct GNUNET_PeerIdentity *view_array; |
3594 | 3612 | ||
3595 | (void)msg; | 3613 | (void) msg; |
3596 | 3614 | ||
3597 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Received PULL REQUEST (%s)\n", GNUNET_i2s(peer)); | 3615 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PULL REQUEST (%s)\n", GNUNET_i2s ( |
3616 | peer)); | ||
3598 | if (peer_ctx->sub == msub) | 3617 | if (peer_ctx->sub == msub) |
3618 | { | ||
3619 | GNUNET_STATISTICS_update (stats, | ||
3620 | "# pull request message received", | ||
3621 | 1, | ||
3622 | GNUNET_NO); | ||
3623 | if ((NULL != map_single_hop) && | ||
3624 | (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (map_single_hop, | ||
3625 | &peer_ctx->peer_id))) | ||
3599 | { | 3626 | { |
3600 | GNUNET_STATISTICS_update(stats, | 3627 | GNUNET_STATISTICS_update (stats, |
3601 | "# pull request message received", | 3628 | "# pull request message received (multi-hop peer)", |
3602 | 1, | 3629 | 1, |
3603 | GNUNET_NO); | 3630 | GNUNET_NO); |
3604 | if (NULL != map_single_hop && | ||
3605 | GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(map_single_hop, | ||
3606 | &peer_ctx->peer_id)) | ||
3607 | { | ||
3608 | GNUNET_STATISTICS_update(stats, | ||
3609 | "# pull request message received (multi-hop peer)", | ||
3610 | 1, | ||
3611 | GNUNET_NO); | ||
3612 | } | ||
3613 | } | 3631 | } |
3632 | } | ||
3614 | 3633 | ||
3615 | #if ENABLE_MALICIOUS | 3634 | #if ENABLE_MALICIOUS |
3616 | if (1 == mal_type | 3635 | if ((1 == mal_type) |
3617 | || 3 == mal_type) | 3636 | ||(3 == mal_type)) |
3618 | { /* Try to maximise representation */ | 3637 | { /* Try to maximise representation */ |
3619 | send_pull_reply(peer_ctx, mal_peers, num_mal_peers); | 3638 | send_pull_reply (peer_ctx, mal_peers, num_mal_peers); |
3620 | } | 3639 | } |
3621 | 3640 | ||
3622 | else if (2 == mal_type) | 3641 | else if (2 == mal_type) |
3623 | { /* Try to partition network */ | 3642 | { /* Try to partition network */ |
3624 | if (0 == GNUNET_memcmp(&attacked_peer, peer)) | 3643 | if (0 == GNUNET_memcmp (&attacked_peer, peer)) |
3625 | { | 3644 | { |
3626 | send_pull_reply(peer_ctx, mal_peers, num_mal_peers); | 3645 | send_pull_reply (peer_ctx, mal_peers, num_mal_peers); |
3627 | } | ||
3628 | } | 3646 | } |
3647 | } | ||
3629 | #endif /* ENABLE_MALICIOUS */ | 3648 | #endif /* ENABLE_MALICIOUS */ |
3630 | 3649 | ||
3631 | GNUNET_break_op(check_peer_known(channel_ctx->peer_ctx->sub->peer_map, | 3650 | GNUNET_break_op (check_peer_known (channel_ctx->peer_ctx->sub->peer_map, |
3632 | &channel_ctx->peer_ctx->peer_id)); | 3651 | &channel_ctx->peer_ctx->peer_id)); |
3633 | GNUNET_CADET_receive_done(channel_ctx->channel); | 3652 | GNUNET_CADET_receive_done (channel_ctx->channel); |
3634 | view_array = View_get_as_array(channel_ctx->peer_ctx->sub->view); | 3653 | view_array = View_get_as_array (channel_ctx->peer_ctx->sub->view); |
3635 | send_pull_reply(peer_ctx, | 3654 | send_pull_reply (peer_ctx, |
3636 | view_array, | 3655 | view_array, |
3637 | View_size(channel_ctx->peer_ctx->sub->view)); | 3656 | View_size (channel_ctx->peer_ctx->sub->view)); |
3638 | } | 3657 | } |
3639 | 3658 | ||
3640 | 3659 | ||
@@ -3646,45 +3665,47 @@ handle_peer_pull_request(void *cls, | |||
3646 | * @param msg Message containing the replied peers | 3665 | * @param msg Message containing the replied peers |
3647 | */ | 3666 | */ |
3648 | static int | 3667 | static int |
3649 | check_peer_pull_reply(void *cls, | 3668 | check_peer_pull_reply (void *cls, |
3650 | const struct GNUNET_RPS_P2P_PullReplyMessage *msg) | 3669 | const struct GNUNET_RPS_P2P_PullReplyMessage *msg) |
3651 | { | 3670 | { |
3652 | struct ChannelCtx *channel_ctx = cls; | 3671 | struct ChannelCtx *channel_ctx = cls; |
3653 | struct PeerContext *sender_ctx = channel_ctx->peer_ctx; | 3672 | struct PeerContext *sender_ctx = channel_ctx->peer_ctx; |
3654 | 3673 | ||
3655 | if (sizeof(struct GNUNET_RPS_P2P_PullReplyMessage) > ntohs(msg->header.size)) | 3674 | if (sizeof(struct GNUNET_RPS_P2P_PullReplyMessage) > ntohs (msg->header.size)) |
3656 | { | 3675 | { |
3657 | GNUNET_break_op(0); | 3676 | GNUNET_break_op (0); |
3658 | return GNUNET_SYSERR; | 3677 | return GNUNET_SYSERR; |
3659 | } | 3678 | } |
3660 | 3679 | ||
3661 | if ((ntohs(msg->header.size) - sizeof(struct GNUNET_RPS_P2P_PullReplyMessage)) / | 3680 | if ((ntohs (msg->header.size) - sizeof(struct |
3662 | sizeof(struct GNUNET_PeerIdentity) != ntohl(msg->num_peers)) | 3681 | GNUNET_RPS_P2P_PullReplyMessage)) |
3663 | { | 3682 | / sizeof(struct GNUNET_PeerIdentity) != ntohl (msg->num_peers)) |
3664 | LOG(GNUNET_ERROR_TYPE_ERROR, | 3683 | { |
3665 | "message says it sends %" PRIu32 " peers, have space for %lu peers\n", | 3684 | LOG (GNUNET_ERROR_TYPE_ERROR, |
3666 | ntohl(msg->num_peers), | 3685 | "message says it sends %" PRIu32 " peers, have space for %lu peers\n", |
3667 | (ntohs(msg->header.size) - sizeof(struct GNUNET_RPS_P2P_PullReplyMessage)) / | 3686 | ntohl (msg->num_peers), |
3668 | sizeof(struct GNUNET_PeerIdentity)); | 3687 | (ntohs (msg->header.size) - sizeof(struct |
3669 | GNUNET_break_op(0); | 3688 | GNUNET_RPS_P2P_PullReplyMessage)) |
3670 | return GNUNET_SYSERR; | 3689 | / sizeof(struct GNUNET_PeerIdentity)); |
3671 | } | 3690 | GNUNET_break_op (0); |
3672 | 3691 | return GNUNET_SYSERR; | |
3673 | if (GNUNET_YES != check_peer_flag(sender_ctx->sub->peer_map, | 3692 | } |
3674 | &sender_ctx->peer_id, | 3693 | |
3675 | Peers_PULL_REPLY_PENDING)) | 3694 | if (GNUNET_YES != check_peer_flag (sender_ctx->sub->peer_map, |
3695 | &sender_ctx->peer_id, | ||
3696 | Peers_PULL_REPLY_PENDING)) | ||
3697 | { | ||
3698 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
3699 | "Received a pull reply from a peer (%s) we didn't request one from!\n", | ||
3700 | GNUNET_i2s (&sender_ctx->peer_id)); | ||
3701 | if (sender_ctx->sub == msub) | ||
3676 | { | 3702 | { |
3677 | LOG(GNUNET_ERROR_TYPE_WARNING, | 3703 | GNUNET_STATISTICS_update (stats, |
3678 | "Received a pull reply from a peer (%s) we didn't request one from!\n", | 3704 | "# unrequested pull replies", |
3679 | GNUNET_i2s(&sender_ctx->peer_id)); | 3705 | 1, |
3680 | if (sender_ctx->sub == msub) | 3706 | GNUNET_NO); |
3681 | { | ||
3682 | GNUNET_STATISTICS_update(stats, | ||
3683 | "# unrequested pull replies", | ||
3684 | 1, | ||
3685 | GNUNET_NO); | ||
3686 | } | ||
3687 | } | 3707 | } |
3708 | } | ||
3688 | return GNUNET_OK; | 3709 | return GNUNET_OK; |
3689 | } | 3710 | } |
3690 | 3711 | ||
@@ -3696,8 +3717,8 @@ check_peer_pull_reply(void *cls, | |||
3696 | * @param msg The message header | 3717 | * @param msg The message header |
3697 | */ | 3718 | */ |
3698 | static void | 3719 | static void |
3699 | handle_peer_pull_reply(void *cls, | 3720 | handle_peer_pull_reply (void *cls, |
3700 | const struct GNUNET_RPS_P2P_PullReplyMessage *msg) | 3721 | const struct GNUNET_RPS_P2P_PullReplyMessage *msg) |
3701 | { | 3722 | { |
3702 | const struct ChannelCtx *channel_ctx = cls; | 3723 | const struct ChannelCtx *channel_ctx = cls; |
3703 | const struct GNUNET_PeerIdentity *sender = &channel_ctx->peer_ctx->peer_id; | 3724 | const struct GNUNET_PeerIdentity *sender = &channel_ctx->peer_ctx->peer_id; |
@@ -3710,94 +3731,96 @@ handle_peer_pull_reply(void *cls, | |||
3710 | #endif /* ENABLE_MALICIOUS */ | 3731 | #endif /* ENABLE_MALICIOUS */ |
3711 | 3732 | ||
3712 | sub->pull_delays[sub->num_rounds - channel_ctx->peer_ctx->round_pull_req]++; | 3733 | sub->pull_delays[sub->num_rounds - channel_ctx->peer_ctx->round_pull_req]++; |
3713 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Received PULL REPLY (%s)\n", GNUNET_i2s(sender)); | 3734 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PULL REPLY (%s)\n", GNUNET_i2s ( |
3735 | sender)); | ||
3714 | if (channel_ctx->peer_ctx->sub == msub) | 3736 | if (channel_ctx->peer_ctx->sub == msub) |
3737 | { | ||
3738 | GNUNET_STATISTICS_update (stats, | ||
3739 | "# pull reply messages received", | ||
3740 | 1, | ||
3741 | GNUNET_NO); | ||
3742 | if ((NULL != map_single_hop) && | ||
3743 | (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (map_single_hop, | ||
3744 | &channel_ctx-> | ||
3745 | peer_ctx->peer_id)) ) | ||
3715 | { | 3746 | { |
3716 | GNUNET_STATISTICS_update(stats, | 3747 | GNUNET_STATISTICS_update (stats, |
3717 | "# pull reply messages received", | 3748 | "# pull reply messages received (multi-hop peer)", |
3718 | 1, | 3749 | 1, |
3719 | GNUNET_NO); | 3750 | GNUNET_NO); |
3720 | if (NULL != map_single_hop && | ||
3721 | GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(map_single_hop, | ||
3722 | &channel_ctx->peer_ctx->peer_id)) | ||
3723 | { | ||
3724 | GNUNET_STATISTICS_update(stats, | ||
3725 | "# pull reply messages received (multi-hop peer)", | ||
3726 | 1, | ||
3727 | GNUNET_NO); | ||
3728 | } | ||
3729 | } | 3751 | } |
3752 | } | ||
3730 | 3753 | ||
3731 | #if ENABLE_MALICIOUS | 3754 | #if ENABLE_MALICIOUS |
3732 | // We shouldn't even receive pull replies as we're not sending | 3755 | // We shouldn't even receive pull replies as we're not sending |
3733 | if (2 == mal_type) | 3756 | if (2 == mal_type) |
3734 | { | 3757 | { |
3735 | } | 3758 | } |
3736 | #endif /* ENABLE_MALICIOUS */ | 3759 | #endif /* ENABLE_MALICIOUS */ |
3737 | 3760 | ||
3738 | /* Do actual logic */ | 3761 | /* Do actual logic */ |
3739 | peers = (const struct GNUNET_PeerIdentity *)&msg[1]; | 3762 | peers = (const struct GNUNET_PeerIdentity *) &msg[1]; |
3740 | 3763 | ||
3741 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 3764 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3742 | "PULL REPLY received, got following %u peers:\n", | 3765 | "PULL REPLY received, got following %u peers:\n", |
3743 | ntohl(msg->num_peers)); | 3766 | ntohl (msg->num_peers)); |
3744 | 3767 | ||
3745 | for (i = 0; i < ntohl(msg->num_peers); i++) | 3768 | for (i = 0; i < ntohl (msg->num_peers); i++) |
3746 | { | 3769 | { |
3747 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 3770 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3748 | "%u. %s\n", | 3771 | "%u. %s\n", |
3749 | i, | 3772 | i, |
3750 | GNUNET_i2s(&peers[i])); | 3773 | GNUNET_i2s (&peers[i])); |
3751 | 3774 | ||
3752 | #if ENABLE_MALICIOUS | 3775 | #if ENABLE_MALICIOUS |
3753 | if ((NULL != att_peer_set) && | 3776 | if ((NULL != att_peer_set) && |
3754 | (1 == mal_type || 3 == mal_type)) | 3777 | ((1 == mal_type) ||(3 == mal_type) )) |
3755 | { /* Add attacked peer to local list */ | 3778 | { /* Add attacked peer to local list */ |
3756 | // TODO check if we sent a request and this was the first reply | 3779 | // TODO check if we sent a request and this was the first reply |
3757 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(att_peer_set, | 3780 | if ((GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (att_peer_set, |
3758 | &peers[i]) | 3781 | &peers[i])) |
3759 | && GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(mal_peer_set, | 3782 | &&(GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (mal_peer_set, |
3760 | &peers[i])) | 3783 | &peers[i])) ) |
3761 | { | 3784 | { |
3762 | tmp_att_peer = GNUNET_new(struct AttackedPeer); | 3785 | tmp_att_peer = GNUNET_new (struct AttackedPeer); |
3763 | tmp_att_peer->peer_id = peers[i]; | 3786 | tmp_att_peer->peer_id = peers[i]; |
3764 | GNUNET_CONTAINER_DLL_insert(att_peers_head, | 3787 | GNUNET_CONTAINER_DLL_insert (att_peers_head, |
3765 | att_peers_tail, | 3788 | att_peers_tail, |
3766 | tmp_att_peer); | 3789 | tmp_att_peer); |
3767 | add_peer_array_to_set(&peers[i], 1, att_peer_set); | 3790 | add_peer_array_to_set (&peers[i], 1, att_peer_set); |
3768 | } | 3791 | } |
3769 | continue; | 3792 | continue; |
3770 | } | 3793 | } |
3771 | #endif /* ENABLE_MALICIOUS */ | 3794 | #endif /* ENABLE_MALICIOUS */ |
3772 | /* Make sure we 'know' about this peer */ | 3795 | /* Make sure we 'know' about this peer */ |
3773 | (void)insert_peer(channel_ctx->peer_ctx->sub, | 3796 | (void) insert_peer (channel_ctx->peer_ctx->sub, |
3774 | &peers[i]); | 3797 | &peers[i]); |
3775 | 3798 | ||
3776 | if (GNUNET_YES == check_peer_valid(channel_ctx->peer_ctx->sub->valid_peers, | 3799 | if (GNUNET_YES == check_peer_valid (channel_ctx->peer_ctx->sub->valid_peers, |
3777 | &peers[i])) | 3800 | &peers[i])) |
3778 | { | 3801 | { |
3779 | CustomPeerMap_put(channel_ctx->peer_ctx->sub->pull_map, | 3802 | CustomPeerMap_put (channel_ctx->peer_ctx->sub->pull_map, |
3780 | &peers[i]); | 3803 | &peers[i]); |
3781 | } | ||
3782 | else | ||
3783 | { | ||
3784 | schedule_operation(channel_ctx->peer_ctx, | ||
3785 | insert_in_pull_map, | ||
3786 | channel_ctx->peer_ctx->sub); /* cls */ | ||
3787 | (void)issue_peer_online_check(channel_ctx->peer_ctx->sub, | ||
3788 | &peers[i]); | ||
3789 | } | ||
3790 | } | 3804 | } |
3791 | 3805 | else | |
3792 | UNSET_PEER_FLAG(get_peer_ctx(channel_ctx->peer_ctx->sub->peer_map, | 3806 | { |
3793 | sender), | 3807 | schedule_operation (channel_ctx->peer_ctx, |
3794 | Peers_PULL_REPLY_PENDING); | 3808 | insert_in_pull_map, |
3795 | clean_peer(channel_ctx->peer_ctx->sub, | 3809 | channel_ctx->peer_ctx->sub); /* cls */ |
3796 | sender); | 3810 | (void) issue_peer_online_check (channel_ctx->peer_ctx->sub, |
3797 | 3811 | &peers[i]); | |
3798 | GNUNET_break_op(check_peer_known(channel_ctx->peer_ctx->sub->peer_map, | 3812 | } |
3799 | sender)); | 3813 | } |
3800 | GNUNET_CADET_receive_done(channel_ctx->channel); | 3814 | |
3815 | UNSET_PEER_FLAG (get_peer_ctx (channel_ctx->peer_ctx->sub->peer_map, | ||
3816 | sender), | ||
3817 | Peers_PULL_REPLY_PENDING); | ||
3818 | clean_peer (channel_ctx->peer_ctx->sub, | ||
3819 | sender); | ||
3820 | |||
3821 | GNUNET_break_op (check_peer_known (channel_ctx->peer_ctx->sub->peer_map, | ||
3822 | sender)); | ||
3823 | GNUNET_CADET_receive_done (channel_ctx->channel); | ||
3801 | } | 3824 | } |
3802 | 3825 | ||
3803 | 3826 | ||
@@ -3812,8 +3835,8 @@ handle_peer_pull_reply(void *cls, | |||
3812 | * @param spread the inverse amount of deviation from the mean | 3835 | * @param spread the inverse amount of deviation from the mean |
3813 | */ | 3836 | */ |
3814 | static struct GNUNET_TIME_Relative | 3837 | static struct GNUNET_TIME_Relative |
3815 | compute_rand_delay(struct GNUNET_TIME_Relative mean, | 3838 | compute_rand_delay (struct GNUNET_TIME_Relative mean, |
3816 | unsigned int spread) | 3839 | unsigned int spread) |
3817 | { | 3840 | { |
3818 | struct GNUNET_TIME_Relative half_interval; | 3841 | struct GNUNET_TIME_Relative half_interval; |
3819 | struct GNUNET_TIME_Relative ret; | 3842 | struct GNUNET_TIME_Relative ret; |
@@ -3821,30 +3844,32 @@ compute_rand_delay(struct GNUNET_TIME_Relative mean, | |||
3821 | unsigned int max_rand_delay; | 3844 | unsigned int max_rand_delay; |
3822 | 3845 | ||
3823 | if (0 == spread) | 3846 | if (0 == spread) |
3824 | { | 3847 | { |
3825 | LOG(GNUNET_ERROR_TYPE_WARNING, | 3848 | LOG (GNUNET_ERROR_TYPE_WARNING, |
3826 | "Not accepting spread of 0\n"); | 3849 | "Not accepting spread of 0\n"); |
3827 | GNUNET_break(0); | 3850 | GNUNET_break (0); |
3828 | GNUNET_assert(0); | 3851 | GNUNET_assert (0); |
3829 | } | 3852 | } |
3830 | GNUNET_assert(0 != mean.rel_value_us); | 3853 | GNUNET_assert (0 != mean.rel_value_us); |
3831 | 3854 | ||
3832 | /* Compute random time value between spread * mean and spread * mean */ | 3855 | /* Compute random time value between spread * mean and spread * mean */ |
3833 | half_interval = GNUNET_TIME_relative_divide(mean, spread); | 3856 | half_interval = GNUNET_TIME_relative_divide (mean, spread); |
3834 | 3857 | ||
3835 | max_rand_delay = GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us / mean.rel_value_us * (2 / spread); | 3858 | max_rand_delay = GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us |
3859 | / mean.rel_value_us * (2 / spread); | ||
3836 | /** | 3860 | /** |
3837 | * Compute random value between (0 and 1) * round_interval | 3861 | * Compute random value between (0 and 1) * round_interval |
3838 | * via multiplying round_interval with a 'fraction' (0 to value)/value | 3862 | * via multiplying round_interval with a 'fraction' (0 to value)/value |
3839 | */ | 3863 | */ |
3840 | rand_delay = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, max_rand_delay); | 3864 | rand_delay = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
3841 | ret = GNUNET_TIME_relative_saturating_multiply(mean, rand_delay); | 3865 | max_rand_delay); |
3842 | ret = GNUNET_TIME_relative_divide(ret, max_rand_delay); | 3866 | ret = GNUNET_TIME_relative_saturating_multiply (mean, rand_delay); |
3843 | ret = GNUNET_TIME_relative_add(ret, half_interval); | 3867 | ret = GNUNET_TIME_relative_divide (ret, max_rand_delay); |
3868 | ret = GNUNET_TIME_relative_add (ret, half_interval); | ||
3844 | 3869 | ||
3845 | if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == ret.rel_value_us) | 3870 | if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == ret.rel_value_us) |
3846 | LOG(GNUNET_ERROR_TYPE_WARNING, | 3871 | LOG (GNUNET_ERROR_TYPE_WARNING, |
3847 | "Returning FOREVER_REL\n"); | 3872 | "Returning FOREVER_REL\n"); |
3848 | 3873 | ||
3849 | return ret; | 3874 | return ret; |
3850 | } | 3875 | } |
@@ -3856,41 +3881,41 @@ compute_rand_delay(struct GNUNET_TIME_Relative mean, | |||
3856 | * @param peer_ctx Context to the peer to send request to | 3881 | * @param peer_ctx Context to the peer to send request to |
3857 | */ | 3882 | */ |
3858 | static void | 3883 | static void |
3859 | send_pull_request(struct PeerContext *peer_ctx) | 3884 | send_pull_request (struct PeerContext *peer_ctx) |
3860 | { | 3885 | { |
3861 | struct GNUNET_MQ_Envelope *ev; | 3886 | struct GNUNET_MQ_Envelope *ev; |
3862 | 3887 | ||
3863 | GNUNET_assert(GNUNET_NO == check_peer_flag(peer_ctx->sub->peer_map, | 3888 | GNUNET_assert (GNUNET_NO == check_peer_flag (peer_ctx->sub->peer_map, |
3864 | &peer_ctx->peer_id, | 3889 | &peer_ctx->peer_id, |
3865 | Peers_PULL_REPLY_PENDING)); | 3890 | Peers_PULL_REPLY_PENDING)); |
3866 | SET_PEER_FLAG(peer_ctx, | 3891 | SET_PEER_FLAG (peer_ctx, |
3867 | Peers_PULL_REPLY_PENDING); | 3892 | Peers_PULL_REPLY_PENDING); |
3868 | peer_ctx->round_pull_req = peer_ctx->sub->num_rounds; | 3893 | peer_ctx->round_pull_req = peer_ctx->sub->num_rounds; |
3869 | 3894 | ||
3870 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 3895 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3871 | "Going to send PULL REQUEST to peer %s.\n", | 3896 | "Going to send PULL REQUEST to peer %s.\n", |
3872 | GNUNET_i2s(&peer_ctx->peer_id)); | 3897 | GNUNET_i2s (&peer_ctx->peer_id)); |
3873 | 3898 | ||
3874 | ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST); | 3899 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST); |
3875 | send_message(peer_ctx, | 3900 | send_message (peer_ctx, |
3876 | ev, | 3901 | ev, |
3877 | "PULL REQUEST"); | 3902 | "PULL REQUEST"); |
3878 | if (peer_ctx->sub) | 3903 | if (peer_ctx->sub) |
3904 | { | ||
3905 | GNUNET_STATISTICS_update (stats, | ||
3906 | "# pull request send issued", | ||
3907 | 1, | ||
3908 | GNUNET_NO); | ||
3909 | if ((NULL != map_single_hop) && | ||
3910 | (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (map_single_hop, | ||
3911 | &peer_ctx->peer_id))) | ||
3879 | { | 3912 | { |
3880 | GNUNET_STATISTICS_update(stats, | 3913 | GNUNET_STATISTICS_update (stats, |
3881 | "# pull request send issued", | 3914 | "# pull request send issued (multi-hop peer)", |
3882 | 1, | 3915 | 1, |
3883 | GNUNET_NO); | 3916 | GNUNET_NO); |
3884 | if (NULL != map_single_hop && | ||
3885 | GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(map_single_hop, | ||
3886 | &peer_ctx->peer_id)) | ||
3887 | { | ||
3888 | GNUNET_STATISTICS_update(stats, | ||
3889 | "# pull request send issued (multi-hop peer)", | ||
3890 | 1, | ||
3891 | GNUNET_NO); | ||
3892 | } | ||
3893 | } | 3917 | } |
3918 | } | ||
3894 | } | 3919 | } |
3895 | 3920 | ||
3896 | 3921 | ||
@@ -3900,32 +3925,32 @@ send_pull_request(struct PeerContext *peer_ctx) | |||
3900 | * @param peer_ctx Context of peer to send push to | 3925 | * @param peer_ctx Context of peer to send push to |
3901 | */ | 3926 | */ |
3902 | static void | 3927 | static void |
3903 | send_push(struct PeerContext *peer_ctx) | 3928 | send_push (struct PeerContext *peer_ctx) |
3904 | { | 3929 | { |
3905 | struct GNUNET_MQ_Envelope *ev; | 3930 | struct GNUNET_MQ_Envelope *ev; |
3906 | 3931 | ||
3907 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 3932 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3908 | "Going to send PUSH to peer %s.\n", | 3933 | "Going to send PUSH to peer %s.\n", |
3909 | GNUNET_i2s(&peer_ctx->peer_id)); | 3934 | GNUNET_i2s (&peer_ctx->peer_id)); |
3910 | 3935 | ||
3911 | ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_RPS_PP_PUSH); | 3936 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PUSH); |
3912 | send_message(peer_ctx, ev, "PUSH"); | 3937 | send_message (peer_ctx, ev, "PUSH"); |
3913 | if (peer_ctx->sub) | 3938 | if (peer_ctx->sub) |
3939 | { | ||
3940 | GNUNET_STATISTICS_update (stats, | ||
3941 | "# push send issued", | ||
3942 | 1, | ||
3943 | GNUNET_NO); | ||
3944 | if ((NULL != map_single_hop) && | ||
3945 | (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (map_single_hop, | ||
3946 | &peer_ctx->peer_id))) | ||
3914 | { | 3947 | { |
3915 | GNUNET_STATISTICS_update(stats, | 3948 | GNUNET_STATISTICS_update (stats, |
3916 | "# push send issued", | 3949 | "# push send issued (multi-hop peer)", |
3917 | 1, | 3950 | 1, |
3918 | GNUNET_NO); | 3951 | GNUNET_NO); |
3919 | if (NULL != map_single_hop && | ||
3920 | GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(map_single_hop, | ||
3921 | &peer_ctx->peer_id)) | ||
3922 | { | ||
3923 | GNUNET_STATISTICS_update(stats, | ||
3924 | "# push send issued (multi-hop peer)", | ||
3925 | 1, | ||
3926 | GNUNET_NO); | ||
3927 | } | ||
3928 | } | 3952 | } |
3953 | } | ||
3929 | } | 3954 | } |
3930 | 3955 | ||
3931 | 3956 | ||
@@ -3941,25 +3966,25 @@ send_push(struct PeerContext *peer_ctx) | |||
3941 | * @return #GNUNET_OK if @a msg is well-formed | 3966 | * @return #GNUNET_OK if @a msg is well-formed |
3942 | */ | 3967 | */ |
3943 | static int | 3968 | static int |
3944 | check_client_act_malicious(void *cls, | 3969 | check_client_act_malicious (void *cls, |
3945 | const struct GNUNET_RPS_CS_ActMaliciousMessage *msg) | 3970 | const struct GNUNET_RPS_CS_ActMaliciousMessage *msg) |
3946 | { | 3971 | { |
3947 | struct ClientContext *cli_ctx = cls; | 3972 | struct ClientContext *cli_ctx = cls; |
3948 | uint16_t msize = ntohs(msg->header.size); | 3973 | uint16_t msize = ntohs (msg->header.size); |
3949 | uint32_t num_peers = ntohl(msg->num_peers); | 3974 | uint32_t num_peers = ntohl (msg->num_peers); |
3950 | 3975 | ||
3951 | msize -= sizeof(struct GNUNET_RPS_CS_ActMaliciousMessage); | 3976 | msize -= sizeof(struct GNUNET_RPS_CS_ActMaliciousMessage); |
3952 | if ((msize / sizeof(struct GNUNET_PeerIdentity) != num_peers) || | 3977 | if ((msize / sizeof(struct GNUNET_PeerIdentity) != num_peers) || |
3953 | (msize % sizeof(struct GNUNET_PeerIdentity) != 0)) | 3978 | (msize % sizeof(struct GNUNET_PeerIdentity) != 0)) |
3954 | { | 3979 | { |
3955 | LOG(GNUNET_ERROR_TYPE_ERROR, | 3980 | LOG (GNUNET_ERROR_TYPE_ERROR, |
3956 | "message says it sends %" PRIu32 " peers, have space for %lu peers\n", | 3981 | "message says it sends %" PRIu32 " peers, have space for %lu peers\n", |
3957 | ntohl(msg->num_peers), | 3982 | ntohl (msg->num_peers), |
3958 | (msize / sizeof(struct GNUNET_PeerIdentity))); | 3983 | (msize / sizeof(struct GNUNET_PeerIdentity))); |
3959 | GNUNET_break(0); | 3984 | GNUNET_break (0); |
3960 | GNUNET_SERVICE_client_drop(cli_ctx->client); | 3985 | GNUNET_SERVICE_client_drop (cli_ctx->client); |
3961 | return GNUNET_SYSERR; | 3986 | return GNUNET_SYSERR; |
3962 | } | 3987 | } |
3963 | return GNUNET_OK; | 3988 | return GNUNET_OK; |
3964 | } | 3989 | } |
3965 | 3990 | ||
@@ -3971,8 +3996,9 @@ check_client_act_malicious(void *cls, | |||
3971 | * @param msg The message header | 3996 | * @param msg The message header |
3972 | */ | 3997 | */ |
3973 | static void | 3998 | static void |
3974 | handle_client_act_malicious(void *cls, | 3999 | handle_client_act_malicious (void *cls, |
3975 | const struct GNUNET_RPS_CS_ActMaliciousMessage *msg) | 4000 | const struct |
4001 | GNUNET_RPS_CS_ActMaliciousMessage *msg) | ||
3976 | { | 4002 | { |
3977 | struct ClientContext *cli_ctx = cls; | 4003 | struct ClientContext *cli_ctx = cls; |
3978 | struct GNUNET_PeerIdentity *peers; | 4004 | struct GNUNET_PeerIdentity *peers; |
@@ -3983,100 +4009,100 @@ handle_client_act_malicious(void *cls, | |||
3983 | if (NULL == sub) | 4009 | if (NULL == sub) |
3984 | sub = msub; | 4010 | sub = msub; |
3985 | /* Do actual logic */ | 4011 | /* Do actual logic */ |
3986 | peers = (struct GNUNET_PeerIdentity *)&msg[1]; | 4012 | peers = (struct GNUNET_PeerIdentity *) &msg[1]; |
3987 | mal_type = ntohl(msg->type); | 4013 | mal_type = ntohl (msg->type); |
3988 | if (NULL == mal_peer_set) | 4014 | if (NULL == mal_peer_set) |
3989 | mal_peer_set = GNUNET_CONTAINER_multipeermap_create(1, GNUNET_NO); | 4015 | mal_peer_set = GNUNET_CONTAINER_multipeermap_create (1, GNUNET_NO); |
3990 | 4016 | ||
3991 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 4017 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3992 | "Now acting malicious type %" PRIu32 ", got %" PRIu32 " peers.\n", | 4018 | "Now acting malicious type %" PRIu32 ", got %" PRIu32 " peers.\n", |
3993 | mal_type, | 4019 | mal_type, |
3994 | ntohl(msg->num_peers)); | 4020 | ntohl (msg->num_peers)); |
3995 | 4021 | ||
3996 | if (1 == mal_type) | 4022 | if (1 == mal_type) |
3997 | { /* Try to maximise representation */ | 4023 | { /* Try to maximise representation */ |
3998 | /* Add other malicious peers to those we already know */ | 4024 | /* Add other malicious peers to those we already know */ |
3999 | 4025 | ||
4000 | num_mal_peers_sent = ntohl(msg->num_peers); | 4026 | num_mal_peers_sent = ntohl (msg->num_peers); |
4001 | num_mal_peers_old = num_mal_peers; | 4027 | num_mal_peers_old = num_mal_peers; |
4002 | GNUNET_array_grow(mal_peers, | 4028 | GNUNET_array_grow (mal_peers, |
4003 | num_mal_peers, | 4029 | num_mal_peers, |
4004 | num_mal_peers + num_mal_peers_sent); | 4030 | num_mal_peers + num_mal_peers_sent); |
4005 | GNUNET_memcpy(&mal_peers[num_mal_peers_old], | 4031 | GNUNET_memcpy (&mal_peers[num_mal_peers_old], |
4006 | peers, | 4032 | peers, |
4007 | num_mal_peers_sent * sizeof(struct GNUNET_PeerIdentity)); | 4033 | num_mal_peers_sent * sizeof(struct GNUNET_PeerIdentity)); |
4008 | 4034 | ||
4009 | /* Add all mal peers to mal_peer_set */ | 4035 | /* Add all mal peers to mal_peer_set */ |
4010 | add_peer_array_to_set(&mal_peers[num_mal_peers_old], | 4036 | add_peer_array_to_set (&mal_peers[num_mal_peers_old], |
4011 | num_mal_peers_sent, | 4037 | num_mal_peers_sent, |
4012 | mal_peer_set); | 4038 | mal_peer_set); |
4013 | 4039 | ||
4014 | /* Substitute do_round () with do_mal_round () */ | 4040 | /* Substitute do_round () with do_mal_round () */ |
4015 | GNUNET_assert(NULL != sub->do_round_task); | 4041 | GNUNET_assert (NULL != sub->do_round_task); |
4016 | GNUNET_SCHEDULER_cancel(sub->do_round_task); | 4042 | GNUNET_SCHEDULER_cancel (sub->do_round_task); |
4017 | sub->do_round_task = GNUNET_SCHEDULER_add_now(&do_mal_round, sub); | 4043 | sub->do_round_task = GNUNET_SCHEDULER_add_now (&do_mal_round, sub); |
4018 | } | 4044 | } |
4019 | 4045 | ||
4020 | else if ((2 == mal_type) || | 4046 | else if ((2 == mal_type) || |
4021 | (3 == mal_type)) | 4047 | (3 == mal_type)) |
4022 | { /* Try to partition the network */ | 4048 | { /* Try to partition the network */ |
4023 | /* Add other malicious peers to those we already know */ | 4049 | /* Add other malicious peers to those we already know */ |
4024 | 4050 | ||
4025 | num_mal_peers_sent = ntohl(msg->num_peers) - 1; | 4051 | num_mal_peers_sent = ntohl (msg->num_peers) - 1; |
4026 | num_mal_peers_old = num_mal_peers; | 4052 | num_mal_peers_old = num_mal_peers; |
4027 | GNUNET_assert(GNUNET_MAX_MALLOC_CHECKED > num_mal_peers_sent); | 4053 | GNUNET_assert (GNUNET_MAX_MALLOC_CHECKED > num_mal_peers_sent); |
4028 | GNUNET_array_grow(mal_peers, | 4054 | GNUNET_array_grow (mal_peers, |
4029 | num_mal_peers, | 4055 | num_mal_peers, |
4030 | num_mal_peers + num_mal_peers_sent); | 4056 | num_mal_peers + num_mal_peers_sent); |
4031 | if (NULL != mal_peers && | 4057 | if ((NULL != mal_peers) && |
4032 | 0 != num_mal_peers) | 4058 | (0 != num_mal_peers) ) |
4033 | { | 4059 | { |
4034 | GNUNET_memcpy(&mal_peers[num_mal_peers_old], | 4060 | GNUNET_memcpy (&mal_peers[num_mal_peers_old], |
4035 | peers, | 4061 | peers, |
4036 | num_mal_peers_sent * sizeof(struct GNUNET_PeerIdentity)); | 4062 | num_mal_peers_sent * sizeof(struct GNUNET_PeerIdentity)); |
4037 | 4063 | ||
4038 | /* Add all mal peers to mal_peer_set */ | 4064 | /* Add all mal peers to mal_peer_set */ |
4039 | add_peer_array_to_set(&mal_peers[num_mal_peers_old], | 4065 | add_peer_array_to_set (&mal_peers[num_mal_peers_old], |
4040 | num_mal_peers_sent, | 4066 | num_mal_peers_sent, |
4041 | mal_peer_set); | 4067 | mal_peer_set); |
4042 | } | ||
4043 | |||
4044 | /* Store the one attacked peer */ | ||
4045 | GNUNET_memcpy(&attacked_peer, | ||
4046 | &msg->attacked_peer, | ||
4047 | sizeof(struct GNUNET_PeerIdentity)); | ||
4048 | /* Set the flag of the attacked peer to valid to avoid problems */ | ||
4049 | if (GNUNET_NO == check_peer_known(sub->peer_map, &attacked_peer)) | ||
4050 | { | ||
4051 | (void)issue_peer_online_check(sub, &attacked_peer); | ||
4052 | } | ||
4053 | |||
4054 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
4055 | "Attacked peer is %s\n", | ||
4056 | GNUNET_i2s(&attacked_peer)); | ||
4057 | |||
4058 | /* Substitute do_round () with do_mal_round () */ | ||
4059 | if (NULL != sub->do_round_task) | ||
4060 | { | ||
4061 | /* Probably in shutdown */ | ||
4062 | GNUNET_SCHEDULER_cancel(sub->do_round_task); | ||
4063 | sub->do_round_task = GNUNET_SCHEDULER_add_now(&do_mal_round, sub); | ||
4064 | } | ||
4065 | } | 4068 | } |
4066 | else if (0 == mal_type) | ||
4067 | { /* Stop acting malicious */ | ||
4068 | GNUNET_array_grow(mal_peers, num_mal_peers, 0); | ||
4069 | 4069 | ||
4070 | /* Substitute do_mal_round () with do_round () */ | 4070 | /* Store the one attacked peer */ |
4071 | GNUNET_SCHEDULER_cancel(sub->do_round_task); | 4071 | GNUNET_memcpy (&attacked_peer, |
4072 | sub->do_round_task = GNUNET_SCHEDULER_add_now(&do_round, sub); | 4072 | &msg->attacked_peer, |
4073 | sizeof(struct GNUNET_PeerIdentity)); | ||
4074 | /* Set the flag of the attacked peer to valid to avoid problems */ | ||
4075 | if (GNUNET_NO == check_peer_known (sub->peer_map, &attacked_peer)) | ||
4076 | { | ||
4077 | (void) issue_peer_online_check (sub, &attacked_peer); | ||
4073 | } | 4078 | } |
4074 | else | 4079 | |
4080 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
4081 | "Attacked peer is %s\n", | ||
4082 | GNUNET_i2s (&attacked_peer)); | ||
4083 | |||
4084 | /* Substitute do_round () with do_mal_round () */ | ||
4085 | if (NULL != sub->do_round_task) | ||
4075 | { | 4086 | { |
4076 | GNUNET_break(0); | 4087 | /* Probably in shutdown */ |
4077 | GNUNET_SERVICE_client_continue(cli_ctx->client); | 4088 | GNUNET_SCHEDULER_cancel (sub->do_round_task); |
4089 | sub->do_round_task = GNUNET_SCHEDULER_add_now (&do_mal_round, sub); | ||
4078 | } | 4090 | } |
4079 | GNUNET_SERVICE_client_continue(cli_ctx->client); | 4091 | } |
4092 | else if (0 == mal_type) | ||
4093 | { /* Stop acting malicious */ | ||
4094 | GNUNET_array_grow (mal_peers, num_mal_peers, 0); | ||
4095 | |||
4096 | /* Substitute do_mal_round () with do_round () */ | ||
4097 | GNUNET_SCHEDULER_cancel (sub->do_round_task); | ||
4098 | sub->do_round_task = GNUNET_SCHEDULER_add_now (&do_round, sub); | ||
4099 | } | ||
4100 | else | ||
4101 | { | ||
4102 | GNUNET_break (0); | ||
4103 | GNUNET_SERVICE_client_continue (cli_ctx->client); | ||
4104 | } | ||
4105 | GNUNET_SERVICE_client_continue (cli_ctx->client); | ||
4080 | } | 4106 | } |
4081 | 4107 | ||
4082 | 4108 | ||
@@ -4088,7 +4114,7 @@ handle_client_act_malicious(void *cls, | |||
4088 | * @param cls Closure - Sub | 4114 | * @param cls Closure - Sub |
4089 | */ | 4115 | */ |
4090 | static void | 4116 | static void |
4091 | do_mal_round(void *cls) | 4117 | do_mal_round (void *cls) |
4092 | { | 4118 | { |
4093 | uint32_t num_pushes; | 4119 | uint32_t num_pushes; |
4094 | uint32_t i; | 4120 | uint32_t i; |
@@ -4096,119 +4122,119 @@ do_mal_round(void *cls) | |||
4096 | struct AttackedPeer *tmp_att_peer; | 4122 | struct AttackedPeer *tmp_att_peer; |
4097 | struct Sub *sub = cls; | 4123 | struct Sub *sub = cls; |
4098 | 4124 | ||
4099 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 4125 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
4100 | "Going to execute next round maliciously type %" PRIu32 ".\n", | 4126 | "Going to execute next round maliciously type %" PRIu32 ".\n", |
4101 | mal_type); | 4127 | mal_type); |
4102 | sub->do_round_task = NULL; | 4128 | sub->do_round_task = NULL; |
4103 | GNUNET_assert(mal_type <= 3); | 4129 | GNUNET_assert (mal_type <= 3); |
4104 | /* Do malicious actions */ | 4130 | /* Do malicious actions */ |
4105 | if (1 == mal_type) | 4131 | if (1 == mal_type) |
4106 | { /* Try to maximise representation */ | 4132 | { /* Try to maximise representation */ |
4107 | /* The maximum of pushes we're going to send this round */ | 4133 | /* The maximum of pushes we're going to send this round */ |
4108 | num_pushes = GNUNET_MIN(GNUNET_MIN(push_limit, | 4134 | num_pushes = GNUNET_MIN (GNUNET_MIN (push_limit, |
4109 | num_attacked_peers), | 4135 | num_attacked_peers), |
4110 | GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE); | 4136 | GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE); |
4111 | 4137 | ||
4112 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 4138 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
4113 | "Going to send %" PRIu32 " pushes\n", | 4139 | "Going to send %" PRIu32 " pushes\n", |
4114 | num_pushes); | 4140 | num_pushes); |
4115 | 4141 | ||
4116 | /* Send PUSHes to attacked peers */ | 4142 | /* Send PUSHes to attacked peers */ |
4117 | for (i = 0; i < num_pushes; i++) | 4143 | for (i = 0; i < num_pushes; i++) |
4118 | { | 4144 | { |
4119 | if (att_peers_tail == att_peer_index) | 4145 | if (att_peers_tail == att_peer_index) |
4120 | att_peer_index = att_peers_head; | 4146 | att_peer_index = att_peers_head; |
4121 | else | 4147 | else |
4122 | att_peer_index = att_peer_index->next; | 4148 | att_peer_index = att_peer_index->next; |
4123 | 4149 | ||
4124 | send_push(get_peer_ctx(sub->peer_map, &att_peer_index->peer_id)); | 4150 | send_push (get_peer_ctx (sub->peer_map, &att_peer_index->peer_id)); |
4125 | } | 4151 | } |
4126 | 4152 | ||
4127 | /* Send PULLs to some peers to learn about additional peers to attack */ | 4153 | /* Send PULLs to some peers to learn about additional peers to attack */ |
4128 | tmp_att_peer = att_peer_index; | 4154 | tmp_att_peer = att_peer_index; |
4129 | for (i = 0; i < num_pushes * alpha; i++) | 4155 | for (i = 0; i < num_pushes * alpha; i++) |
4130 | { | 4156 | { |
4131 | if (att_peers_tail == tmp_att_peer) | 4157 | if (att_peers_tail == tmp_att_peer) |
4132 | tmp_att_peer = att_peers_head; | 4158 | tmp_att_peer = att_peers_head; |
4133 | else | 4159 | else |
4134 | att_peer_index = tmp_att_peer->next; | 4160 | att_peer_index = tmp_att_peer->next; |
4135 | 4161 | ||
4136 | send_pull_request(get_peer_ctx(sub->peer_map, &tmp_att_peer->peer_id)); | 4162 | send_pull_request (get_peer_ctx (sub->peer_map, &tmp_att_peer->peer_id)); |
4137 | } | ||
4138 | } | 4163 | } |
4164 | } | ||
4139 | 4165 | ||
4140 | 4166 | ||
4141 | else if (2 == mal_type) | 4167 | else if (2 == mal_type) |
4142 | { /** | 4168 | { /** |
4143 | * Try to partition the network | 4169 | * Try to partition the network |
4144 | * Send as many pushes to the attacked peer as possible | 4170 | * Send as many pushes to the attacked peer as possible |
4145 | * That is one push per round as it will ignore more. | 4171 | * That is one push per round as it will ignore more. |
4146 | */ | 4172 | */ |
4147 | (void)issue_peer_online_check(sub, &attacked_peer); | 4173 | (void) issue_peer_online_check (sub, &attacked_peer); |
4148 | if (GNUNET_YES == check_peer_flag(sub->peer_map, | 4174 | if (GNUNET_YES == check_peer_flag (sub->peer_map, |
4149 | &attacked_peer, | 4175 | &attacked_peer, |
4150 | Peers_ONLINE)) | 4176 | Peers_ONLINE)) |
4151 | send_push(get_peer_ctx(sub->peer_map, &attacked_peer)); | 4177 | send_push (get_peer_ctx (sub->peer_map, &attacked_peer)); |
4152 | } | 4178 | } |
4153 | 4179 | ||
4154 | 4180 | ||
4155 | if (3 == mal_type) | 4181 | if (3 == mal_type) |
4156 | { /* Combined attack */ | 4182 | { /* Combined attack */ |
4157 | /* Send PUSH to attacked peers */ | 4183 | /* Send PUSH to attacked peers */ |
4158 | if (GNUNET_YES == check_peer_known(sub->peer_map, &attacked_peer)) | 4184 | if (GNUNET_YES == check_peer_known (sub->peer_map, &attacked_peer)) |
4159 | { | 4185 | { |
4160 | (void)issue_peer_online_check(sub, &attacked_peer); | 4186 | (void) issue_peer_online_check (sub, &attacked_peer); |
4161 | if (GNUNET_YES == check_peer_flag(sub->peer_map, | 4187 | if (GNUNET_YES == check_peer_flag (sub->peer_map, |
4162 | &attacked_peer, | 4188 | &attacked_peer, |
4163 | Peers_ONLINE)) | 4189 | Peers_ONLINE)) |
4164 | { | 4190 | { |
4165 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 4191 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
4166 | "Goding to send push to attacked peer (%s)\n", | 4192 | "Goding to send push to attacked peer (%s)\n", |
4167 | GNUNET_i2s(&attacked_peer)); | 4193 | GNUNET_i2s (&attacked_peer)); |
4168 | send_push(get_peer_ctx(sub->peer_map, &attacked_peer)); | 4194 | send_push (get_peer_ctx (sub->peer_map, &attacked_peer)); |
4169 | } | 4195 | } |
4170 | } | 4196 | } |
4171 | (void)issue_peer_online_check(sub, &attacked_peer); | 4197 | (void) issue_peer_online_check (sub, &attacked_peer); |
4172 | 4198 | ||
4173 | /* The maximum of pushes we're going to send this round */ | 4199 | /* The maximum of pushes we're going to send this round */ |
4174 | num_pushes = GNUNET_MIN(GNUNET_MIN(push_limit - 1, | 4200 | num_pushes = GNUNET_MIN (GNUNET_MIN (push_limit - 1, |
4175 | num_attacked_peers), | 4201 | num_attacked_peers), |
4176 | GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE); | 4202 | GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE); |
4177 | 4203 | ||
4178 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 4204 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
4179 | "Going to send %" PRIu32 " pushes\n", | 4205 | "Going to send %" PRIu32 " pushes\n", |
4180 | num_pushes); | 4206 | num_pushes); |
4181 | 4207 | ||
4182 | for (i = 0; i < num_pushes; i++) | 4208 | for (i = 0; i < num_pushes; i++) |
4183 | { | 4209 | { |
4184 | if (att_peers_tail == att_peer_index) | 4210 | if (att_peers_tail == att_peer_index) |
4185 | att_peer_index = att_peers_head; | 4211 | att_peer_index = att_peers_head; |
4186 | else | 4212 | else |
4187 | att_peer_index = att_peer_index->next; | 4213 | att_peer_index = att_peer_index->next; |
4188 | 4214 | ||
4189 | send_push(get_peer_ctx(sub->peer_map, &att_peer_index->peer_id)); | 4215 | send_push (get_peer_ctx (sub->peer_map, &att_peer_index->peer_id)); |
4190 | } | ||
4191 | |||
4192 | /* Send PULLs to some peers to learn about additional peers to attack */ | ||
4193 | tmp_att_peer = att_peer_index; | ||
4194 | for (i = 0; i < num_pushes * alpha; i++) | ||
4195 | { | ||
4196 | if (att_peers_tail == tmp_att_peer) | ||
4197 | tmp_att_peer = att_peers_head; | ||
4198 | else | ||
4199 | att_peer_index = tmp_att_peer->next; | ||
4200 | |||
4201 | send_pull_request(get_peer_ctx(sub->peer_map, &tmp_att_peer->peer_id)); | ||
4202 | } | ||
4203 | } | 4216 | } |
4204 | 4217 | ||
4218 | /* Send PULLs to some peers to learn about additional peers to attack */ | ||
4219 | tmp_att_peer = att_peer_index; | ||
4220 | for (i = 0; i < num_pushes * alpha; i++) | ||
4221 | { | ||
4222 | if (att_peers_tail == tmp_att_peer) | ||
4223 | tmp_att_peer = att_peers_head; | ||
4224 | else | ||
4225 | att_peer_index = tmp_att_peer->next; | ||
4226 | |||
4227 | send_pull_request (get_peer_ctx (sub->peer_map, &tmp_att_peer->peer_id)); | ||
4228 | } | ||
4229 | } | ||
4230 | |||
4205 | /* Schedule next round */ | 4231 | /* Schedule next round */ |
4206 | time_next_round = compute_rand_delay(sub->round_interval, 2); | 4232 | time_next_round = compute_rand_delay (sub->round_interval, 2); |
4207 | 4233 | ||
4208 | GNUNET_assert(NULL == sub->do_round_task); | 4234 | GNUNET_assert (NULL == sub->do_round_task); |
4209 | sub->do_round_task = GNUNET_SCHEDULER_add_delayed(time_next_round, | 4235 | sub->do_round_task = GNUNET_SCHEDULER_add_delayed (time_next_round, |
4210 | &do_mal_round, sub); | 4236 | &do_mal_round, sub); |
4211 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Finished round\n"); | 4237 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Finished round\n"); |
4212 | } | 4238 | } |
4213 | #endif /* ENABLE_MALICIOUS */ | 4239 | #endif /* ENABLE_MALICIOUS */ |
4214 | 4240 | ||
@@ -4221,7 +4247,7 @@ do_mal_round(void *cls) | |||
4221 | * @param cls Closure - Sub | 4247 | * @param cls Closure - Sub |
4222 | */ | 4248 | */ |
4223 | static void | 4249 | static void |
4224 | do_round(void *cls) | 4250 | do_round (void *cls) |
4225 | { | 4251 | { |
4226 | unsigned int i; | 4252 | unsigned int i; |
4227 | const struct GNUNET_PeerIdentity *view_array; | 4253 | const struct GNUNET_PeerIdentity *view_array; |
@@ -4235,308 +4261,327 @@ do_round(void *cls) | |||
4235 | struct Sub *sub = cls; | 4261 | struct Sub *sub = cls; |
4236 | 4262 | ||
4237 | sub->num_rounds++; | 4263 | sub->num_rounds++; |
4238 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 4264 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
4239 | "Going to execute next round.\n"); | 4265 | "Going to execute next round.\n"); |
4240 | if (sub == msub) | 4266 | if (sub == msub) |
4241 | { | 4267 | { |
4242 | GNUNET_STATISTICS_update(stats, "# rounds", 1, GNUNET_NO); | 4268 | GNUNET_STATISTICS_update (stats, "# rounds", 1, GNUNET_NO); |
4243 | } | 4269 | } |
4244 | sub->do_round_task = NULL; | 4270 | sub->do_round_task = NULL; |
4245 | #ifdef TO_FILE_FULL | 4271 | #ifdef TO_FILE_FULL |
4246 | to_file(sub->file_name_view_log, | 4272 | to_file (sub->file_name_view_log, |
4247 | "___ new round ___"); | 4273 | "___ new round ___"); |
4248 | #endif /* TO_FILE_FULL */ | 4274 | #endif /* TO_FILE_FULL */ |
4249 | view_array = View_get_as_array(sub->view); | 4275 | view_array = View_get_as_array (sub->view); |
4250 | for (i = 0; i < View_size(sub->view); i++) | 4276 | for (i = 0; i < View_size (sub->view); i++) |
4251 | { | 4277 | { |
4252 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 4278 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
4253 | "\t%s\n", GNUNET_i2s(&view_array[i])); | 4279 | "\t%s\n", GNUNET_i2s (&view_array[i])); |
4254 | #ifdef TO_FILE_FULL | 4280 | #ifdef TO_FILE_FULL |
4255 | to_file(sub->file_name_view_log, | 4281 | to_file (sub->file_name_view_log, |
4256 | "=%s\t(do round)", | 4282 | "=%s\t(do round)", |
4257 | GNUNET_i2s_full(&view_array[i])); | 4283 | GNUNET_i2s_full (&view_array[i])); |
4258 | #endif /* TO_FILE_FULL */ | 4284 | #endif /* TO_FILE_FULL */ |
4259 | } | 4285 | } |
4260 | 4286 | ||
4261 | 4287 | ||
4262 | /* Send pushes and pull requests */ | 4288 | /* Send pushes and pull requests */ |
4263 | if (0 < View_size(sub->view)) | 4289 | if (0 < View_size (sub->view)) |
4290 | { | ||
4291 | permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_STRONG, | ||
4292 | View_size (sub->view)); | ||
4293 | |||
4294 | /* Send PUSHes */ | ||
4295 | a_peers = ceil (alpha * View_size (sub->view)); | ||
4296 | |||
4297 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
4298 | "Going to send pushes to %u (ceil (%f * %u)) peers.\n", | ||
4299 | a_peers, alpha, View_size (sub->view)); | ||
4300 | for (i = 0; i < a_peers; i++) | ||
4264 | { | 4301 | { |
4265 | permut = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_STRONG, | 4302 | peer = view_array[permut[i]]; |
4266 | View_size(sub->view)); | 4303 | // FIXME if this fails schedule/loop this for later |
4267 | 4304 | send_push (get_peer_ctx (sub->peer_map, &peer)); | |
4268 | /* Send PUSHes */ | ||
4269 | a_peers = ceil(alpha * View_size(sub->view)); | ||
4270 | |||
4271 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
4272 | "Going to send pushes to %u (ceil (%f * %u)) peers.\n", | ||
4273 | a_peers, alpha, View_size(sub->view)); | ||
4274 | for (i = 0; i < a_peers; i++) | ||
4275 | { | ||
4276 | peer = view_array[permut[i]]; | ||
4277 | // FIXME if this fails schedule/loop this for later | ||
4278 | send_push(get_peer_ctx(sub->peer_map, &peer)); | ||
4279 | } | ||
4280 | |||
4281 | /* Send PULL requests */ | ||
4282 | b_peers = ceil(beta * View_size(sub->view)); | ||
4283 | first_border = a_peers; | ||
4284 | second_border = a_peers + b_peers; | ||
4285 | if (second_border > View_size(sub->view)) | ||
4286 | { | ||
4287 | first_border = View_size(sub->view) - b_peers; | ||
4288 | second_border = View_size(sub->view); | ||
4289 | } | ||
4290 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
4291 | "Going to send pulls to %u (ceil (%f * %u)) peers.\n", | ||
4292 | b_peers, beta, View_size(sub->view)); | ||
4293 | for (i = first_border; i < second_border; i++) | ||
4294 | { | ||
4295 | peer = view_array[permut[i]]; | ||
4296 | if (GNUNET_NO == check_peer_flag(sub->peer_map, | ||
4297 | &peer, | ||
4298 | Peers_PULL_REPLY_PENDING)) | ||
4299 | { // FIXME if this fails schedule/loop this for later | ||
4300 | send_pull_request(get_peer_ctx(sub->peer_map, &peer)); | ||
4301 | } | ||
4302 | } | ||
4303 | |||
4304 | GNUNET_free(permut); | ||
4305 | permut = NULL; | ||
4306 | } | 4305 | } |
4307 | 4306 | ||
4307 | /* Send PULL requests */ | ||
4308 | b_peers = ceil (beta * View_size (sub->view)); | ||
4309 | first_border = a_peers; | ||
4310 | second_border = a_peers + b_peers; | ||
4311 | if (second_border > View_size (sub->view)) | ||
4312 | { | ||
4313 | first_border = View_size (sub->view) - b_peers; | ||
4314 | second_border = View_size (sub->view); | ||
4315 | } | ||
4316 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
4317 | "Going to send pulls to %u (ceil (%f * %u)) peers.\n", | ||
4318 | b_peers, beta, View_size (sub->view)); | ||
4319 | for (i = first_border; i < second_border; i++) | ||
4320 | { | ||
4321 | peer = view_array[permut[i]]; | ||
4322 | if (GNUNET_NO == check_peer_flag (sub->peer_map, | ||
4323 | &peer, | ||
4324 | Peers_PULL_REPLY_PENDING)) | ||
4325 | { // FIXME if this fails schedule/loop this for later | ||
4326 | send_pull_request (get_peer_ctx (sub->peer_map, &peer)); | ||
4327 | } | ||
4328 | } | ||
4329 | |||
4330 | GNUNET_free (permut); | ||
4331 | permut = NULL; | ||
4332 | } | ||
4333 | |||
4308 | 4334 | ||
4309 | /* Update view */ | 4335 | /* Update view */ |
4310 | /* TODO see how many peers are in push-/pull- list! */ | 4336 | /* TODO see how many peers are in push-/pull- list! */ |
4311 | 4337 | ||
4312 | if ((CustomPeerMap_size(sub->push_map) <= alpha * sub->view_size_est_need) && | 4338 | if ((CustomPeerMap_size (sub->push_map) <= alpha * sub->view_size_est_need) && |
4313 | (0 < CustomPeerMap_size(sub->push_map)) && | 4339 | (0 < CustomPeerMap_size (sub->push_map)) && |
4314 | (0 < CustomPeerMap_size(sub->pull_map))) | 4340 | (0 < CustomPeerMap_size (sub->pull_map))) |
4315 | { /* If conditions for update are fulfilled, update */ | 4341 | { /* If conditions for update are fulfilled, update */ |
4316 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Update of the view.\n"); | 4342 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Update of the view.\n"); |
4317 | 4343 | ||
4318 | uint32_t final_size; | 4344 | uint32_t final_size; |
4319 | uint32_t peers_to_clean_size; | 4345 | uint32_t peers_to_clean_size; |
4320 | struct GNUNET_PeerIdentity *peers_to_clean; | 4346 | struct GNUNET_PeerIdentity *peers_to_clean; |
4321 | 4347 | ||
4322 | peers_to_clean = NULL; | 4348 | peers_to_clean = NULL; |
4323 | peers_to_clean_size = 0; | 4349 | peers_to_clean_size = 0; |
4324 | GNUNET_array_grow(peers_to_clean, | 4350 | GNUNET_array_grow (peers_to_clean, |
4325 | peers_to_clean_size, | 4351 | peers_to_clean_size, |
4326 | View_size(sub->view)); | 4352 | View_size (sub->view)); |
4327 | GNUNET_memcpy(peers_to_clean, | 4353 | GNUNET_memcpy (peers_to_clean, |
4328 | view_array, | 4354 | view_array, |
4329 | View_size(sub->view) * sizeof(struct GNUNET_PeerIdentity)); | 4355 | View_size (sub->view) * sizeof(struct GNUNET_PeerIdentity)); |
4330 | 4356 | ||
4331 | /* Seems like recreating is the easiest way of emptying the peermap */ | 4357 | /* Seems like recreating is the easiest way of emptying the peermap */ |
4332 | View_clear(sub->view); | 4358 | View_clear (sub->view); |
4333 | #ifdef TO_FILE_FULL | 4359 | #ifdef TO_FILE_FULL |
4334 | to_file(sub->file_name_view_log, | 4360 | to_file (sub->file_name_view_log, |
4335 | "--- emptied ---"); | 4361 | "--- emptied ---"); |
4336 | #endif /* TO_FILE_FULL */ | 4362 | #endif /* TO_FILE_FULL */ |
4337 | 4363 | ||
4338 | first_border = GNUNET_MIN(ceil(alpha * sub->view_size_est_need), | 4364 | first_border = GNUNET_MIN (ceil (alpha * sub->view_size_est_need), |
4339 | CustomPeerMap_size(sub->push_map)); | 4365 | CustomPeerMap_size (sub->push_map)); |
4340 | second_border = first_border + | 4366 | second_border = first_border |
4341 | GNUNET_MIN(floor(beta * sub->view_size_est_need), | 4367 | + GNUNET_MIN (floor (beta * sub->view_size_est_need), |
4342 | CustomPeerMap_size(sub->pull_map)); | 4368 | CustomPeerMap_size (sub->pull_map)); |
4343 | final_size = second_border + | 4369 | final_size = second_border |
4344 | ceil((1 - (alpha + beta)) * sub->view_size_est_need); | 4370 | + ceil ((1 - (alpha + beta)) * sub->view_size_est_need); |
4345 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 4371 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
4346 | "first border: %" PRIu32 ", second border: %" PRIu32 ", final size: %" PRIu32 "\n", | 4372 | "first border: %" PRIu32 ", second border: %" PRIu32 ", final size: %" |
4347 | first_border, | 4373 | PRIu32 "\n", |
4348 | second_border, | 4374 | first_border, |
4349 | final_size); | 4375 | second_border, |
4350 | 4376 | final_size); | |
4351 | /* Update view with peers received through PUSHes */ | 4377 | |
4352 | permut = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_STRONG, | 4378 | /* Update view with peers received through PUSHes */ |
4353 | CustomPeerMap_size(sub->push_map)); | 4379 | permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_STRONG, |
4354 | for (i = 0; i < first_border; i++) | 4380 | CustomPeerMap_size (sub->push_map)); |
4355 | { | 4381 | for (i = 0; i < first_border; i++) |
4356 | int inserted; | 4382 | { |
4357 | inserted = insert_in_view(sub, | 4383 | int inserted; |
4358 | CustomPeerMap_get_peer_by_index(sub->push_map, | 4384 | inserted = insert_in_view (sub, |
4359 | permut[i])); | 4385 | CustomPeerMap_get_peer_by_index (sub->push_map, |
4360 | if (GNUNET_OK == inserted) | 4386 | permut[i])); |
4361 | { | 4387 | if (GNUNET_OK == inserted) |
4362 | clients_notify_stream_peer(sub, | 4388 | { |
4363 | 1, | 4389 | clients_notify_stream_peer (sub, |
4364 | CustomPeerMap_get_peer_by_index(sub->push_map, permut[i])); | 4390 | 1, |
4365 | } | 4391 | CustomPeerMap_get_peer_by_index ( |
4392 | sub->push_map, permut[i])); | ||
4393 | } | ||
4366 | #ifdef TO_FILE_FULL | 4394 | #ifdef TO_FILE_FULL |
4367 | to_file(sub->file_name_view_log, | 4395 | to_file (sub->file_name_view_log, |
4368 | "+%s\t(push list)", | 4396 | "+%s\t(push list)", |
4369 | GNUNET_i2s_full(&view_array[i])); | 4397 | GNUNET_i2s_full (&view_array[i])); |
4370 | #endif /* TO_FILE_FULL */ | 4398 | #endif /* TO_FILE_FULL */ |
4371 | // TODO change the peer_flags accordingly | 4399 | // TODO change the peer_flags accordingly |
4372 | } | 4400 | } |
4373 | GNUNET_free(permut); | 4401 | GNUNET_free (permut); |
4374 | permut = NULL; | 4402 | permut = NULL; |
4375 | 4403 | ||
4376 | /* Update view with peers received through PULLs */ | 4404 | /* Update view with peers received through PULLs */ |
4377 | permut = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_STRONG, | 4405 | permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_STRONG, |
4378 | CustomPeerMap_size(sub->pull_map)); | 4406 | CustomPeerMap_size (sub->pull_map)); |
4379 | for (i = first_border; i < second_border; i++) | 4407 | for (i = first_border; i < second_border; i++) |
4380 | { | 4408 | { |
4381 | int inserted; | 4409 | int inserted; |
4382 | inserted = insert_in_view(sub, | 4410 | inserted = insert_in_view (sub, |
4383 | CustomPeerMap_get_peer_by_index(sub->pull_map, | 4411 | CustomPeerMap_get_peer_by_index (sub->pull_map, |
4384 | permut[i - first_border])); | 4412 | permut[i |
4385 | if (GNUNET_OK == inserted) | 4413 | - |
4386 | { | 4414 | first_border |
4387 | clients_notify_stream_peer(sub, | 4415 | ])); |
4388 | 1, | 4416 | if (GNUNET_OK == inserted) |
4389 | CustomPeerMap_get_peer_by_index(sub->pull_map, | 4417 | { |
4390 | permut[i - first_border])); | 4418 | clients_notify_stream_peer (sub, |
4391 | } | 4419 | 1, |
4420 | CustomPeerMap_get_peer_by_index ( | ||
4421 | sub->pull_map, | ||
4422 | permut[i | ||
4423 | - first_border])); | ||
4424 | } | ||
4392 | #ifdef TO_FILE_FULL | 4425 | #ifdef TO_FILE_FULL |
4393 | to_file(sub->file_name_view_log, | 4426 | to_file (sub->file_name_view_log, |
4394 | "+%s\t(pull list)", | 4427 | "+%s\t(pull list)", |
4395 | GNUNET_i2s_full(&view_array[i])); | 4428 | GNUNET_i2s_full (&view_array[i])); |
4396 | #endif /* TO_FILE_FULL */ | 4429 | #endif /* TO_FILE_FULL */ |
4397 | // TODO change the peer_flags accordingly | 4430 | // TODO change the peer_flags accordingly |
4398 | } | 4431 | } |
4399 | GNUNET_free(permut); | 4432 | GNUNET_free (permut); |
4400 | permut = NULL; | 4433 | permut = NULL; |
4401 | 4434 | ||
4402 | /* Update view with peers from history */ | 4435 | /* Update view with peers from history */ |
4403 | RPS_sampler_get_n_rand_peers(sub->sampler, | 4436 | RPS_sampler_get_n_rand_peers (sub->sampler, |
4404 | final_size - second_border, | 4437 | final_size - second_border, |
4405 | hist_update, | 4438 | hist_update, |
4406 | sub); | 4439 | sub); |
4407 | // TODO change the peer_flags accordingly | 4440 | // TODO change the peer_flags accordingly |
4408 | 4441 | ||
4409 | for (i = 0; i < View_size(sub->view); i++) | 4442 | for (i = 0; i < View_size (sub->view); i++) |
4410 | rem_from_list(&peers_to_clean, &peers_to_clean_size, &view_array[i]); | 4443 | rem_from_list (&peers_to_clean, &peers_to_clean_size, &view_array[i]); |
4411 | 4444 | ||
4412 | /* Clean peers that were removed from the view */ | 4445 | /* Clean peers that were removed from the view */ |
4413 | for (i = 0; i < peers_to_clean_size; i++) | 4446 | for (i = 0; i < peers_to_clean_size; i++) |
4414 | { | 4447 | { |
4415 | #ifdef TO_FILE_FULL | 4448 | #ifdef TO_FILE_FULL |
4416 | to_file(sub->file_name_view_log, | 4449 | to_file (sub->file_name_view_log, |
4417 | "-%s", | 4450 | "-%s", |
4418 | GNUNET_i2s_full(&peers_to_clean[i])); | 4451 | GNUNET_i2s_full (&peers_to_clean[i])); |
4419 | #endif /* TO_FILE_FULL */ | 4452 | #endif /* TO_FILE_FULL */ |
4420 | clean_peer(sub, &peers_to_clean[i]); | 4453 | clean_peer (sub, &peers_to_clean[i]); |
4421 | } | ||
4422 | |||
4423 | GNUNET_array_grow(peers_to_clean, peers_to_clean_size, 0); | ||
4424 | clients_notify_view_update(sub); | ||
4425 | } | 4454 | } |
4455 | |||
4456 | GNUNET_array_grow (peers_to_clean, peers_to_clean_size, 0); | ||
4457 | clients_notify_view_update (sub); | ||
4458 | } | ||
4426 | else | 4459 | else |
4460 | { | ||
4461 | LOG (GNUNET_ERROR_TYPE_DEBUG, "No update of the view.\n"); | ||
4462 | if (sub == msub) | ||
4427 | { | 4463 | { |
4428 | LOG(GNUNET_ERROR_TYPE_DEBUG, "No update of the view.\n"); | 4464 | GNUNET_STATISTICS_update (stats, "# rounds blocked", 1, GNUNET_NO); |
4429 | if (sub == msub) | 4465 | if ((CustomPeerMap_size (sub->push_map) > alpha |
4430 | { | 4466 | * sub->view_size_est_need) && |
4431 | GNUNET_STATISTICS_update(stats, "# rounds blocked", 1, GNUNET_NO); | 4467 | ! (0 >= CustomPeerMap_size (sub->pull_map))) |
4432 | if (CustomPeerMap_size(sub->push_map) > alpha * sub->view_size_est_need && | 4468 | GNUNET_STATISTICS_update (stats, "# rounds blocked - too many pushes", |
4433 | !(0 >= CustomPeerMap_size(sub->pull_map))) | 4469 | 1, GNUNET_NO); |
4434 | GNUNET_STATISTICS_update(stats, "# rounds blocked - too many pushes", 1, GNUNET_NO); | 4470 | if ((CustomPeerMap_size (sub->push_map) > alpha |
4435 | if (CustomPeerMap_size(sub->push_map) > alpha * sub->view_size_est_need && | 4471 | * sub->view_size_est_need) && |
4436 | (0 >= CustomPeerMap_size(sub->pull_map))) | 4472 | (0 >= CustomPeerMap_size (sub->pull_map))) |
4437 | GNUNET_STATISTICS_update(stats, "# rounds blocked - too many pushes, no pull replies", 1, GNUNET_NO); | 4473 | GNUNET_STATISTICS_update (stats, |
4438 | if (0 >= CustomPeerMap_size(sub->push_map) && | 4474 | "# rounds blocked - too many pushes, no pull replies", |
4439 | !(0 >= CustomPeerMap_size(sub->pull_map))) | 4475 | 1, GNUNET_NO); |
4440 | GNUNET_STATISTICS_update(stats, "# rounds blocked - no pushes", 1, GNUNET_NO); | 4476 | if ((0 >= CustomPeerMap_size (sub->push_map)) && |
4441 | if (0 >= CustomPeerMap_size(sub->push_map) && | 4477 | ! (0 >= CustomPeerMap_size (sub->pull_map))) |
4442 | (0 >= CustomPeerMap_size(sub->pull_map))) | 4478 | GNUNET_STATISTICS_update (stats, "# rounds blocked - no pushes", 1, |
4443 | GNUNET_STATISTICS_update(stats, "# rounds blocked - no pushes, no pull replies", 1, GNUNET_NO); | 4479 | GNUNET_NO); |
4444 | if (0 >= CustomPeerMap_size(sub->pull_map) && | 4480 | if ((0 >= CustomPeerMap_size (sub->push_map)) && |
4445 | CustomPeerMap_size(sub->push_map) > alpha * sub->view_size_est_need && | 4481 | (0 >= CustomPeerMap_size (sub->pull_map))) |
4446 | 0 >= CustomPeerMap_size(sub->push_map)) | 4482 | GNUNET_STATISTICS_update (stats, |
4447 | GNUNET_STATISTICS_update(stats, "# rounds blocked - no pull replies", 1, GNUNET_NO); | 4483 | "# rounds blocked - no pushes, no pull replies", |
4448 | } | 4484 | 1, GNUNET_NO); |
4449 | } | 4485 | if ((0 >= CustomPeerMap_size (sub->pull_map)) && |
4486 | (CustomPeerMap_size (sub->push_map) > alpha | ||
4487 | * sub->view_size_est_need) && | ||
4488 | (0 >= CustomPeerMap_size (sub->push_map)) ) | ||
4489 | GNUNET_STATISTICS_update (stats, "# rounds blocked - no pull replies", | ||
4490 | 1, GNUNET_NO); | ||
4491 | } | ||
4492 | } | ||
4450 | // TODO independent of that also get some peers from CADET_get_peers()? | 4493 | // TODO independent of that also get some peers from CADET_get_peers()? |
4451 | if (CustomPeerMap_size(sub->push_map) < HISTOGRAM_FILE_SLOTS) | 4494 | if (CustomPeerMap_size (sub->push_map) < HISTOGRAM_FILE_SLOTS) |
4452 | { | 4495 | { |
4453 | sub->push_recv[CustomPeerMap_size(sub->push_map)]++; | 4496 | sub->push_recv[CustomPeerMap_size (sub->push_map)]++; |
4454 | } | 4497 | } |
4455 | else | 4498 | else |
4456 | { | 4499 | { |
4457 | LOG(GNUNET_ERROR_TYPE_WARNING, | 4500 | LOG (GNUNET_ERROR_TYPE_WARNING, |
4458 | "Push map size too big for histogram (%u, %u)\n", | 4501 | "Push map size too big for histogram (%u, %u)\n", |
4459 | CustomPeerMap_size(sub->push_map), | 4502 | CustomPeerMap_size (sub->push_map), |
4460 | HISTOGRAM_FILE_SLOTS); | 4503 | HISTOGRAM_FILE_SLOTS); |
4461 | } | 4504 | } |
4462 | // FIXME check bounds of histogram | 4505 | // FIXME check bounds of histogram |
4463 | sub->push_delta[(int32_t)(CustomPeerMap_size(sub->push_map) - | 4506 | sub->push_delta[(int32_t) (CustomPeerMap_size (sub->push_map) |
4464 | (alpha * sub->view_size_est_need)) + | 4507 | - (alpha * sub->view_size_est_need)) |
4465 | (HISTOGRAM_FILE_SLOTS / 2)]++; | 4508 | + (HISTOGRAM_FILE_SLOTS / 2)]++; |
4466 | if (sub == msub) | 4509 | if (sub == msub) |
4467 | { | 4510 | { |
4468 | GNUNET_STATISTICS_set(stats, | 4511 | GNUNET_STATISTICS_set (stats, |
4469 | "# peers in push map at end of round", | 4512 | "# peers in push map at end of round", |
4470 | CustomPeerMap_size(sub->push_map), | 4513 | CustomPeerMap_size (sub->push_map), |
4471 | GNUNET_NO); | 4514 | GNUNET_NO); |
4472 | GNUNET_STATISTICS_set(stats, | 4515 | GNUNET_STATISTICS_set (stats, |
4473 | "# peers in pull map at end of round", | 4516 | "# peers in pull map at end of round", |
4474 | CustomPeerMap_size(sub->pull_map), | 4517 | CustomPeerMap_size (sub->pull_map), |
4475 | GNUNET_NO); | 4518 | GNUNET_NO); |
4476 | GNUNET_STATISTICS_set(stats, | 4519 | GNUNET_STATISTICS_set (stats, |
4477 | "# peers in view at end of round", | 4520 | "# peers in view at end of round", |
4478 | View_size(sub->view), | 4521 | View_size (sub->view), |
4479 | GNUNET_NO); | 4522 | GNUNET_NO); |
4480 | GNUNET_STATISTICS_set(stats, | 4523 | GNUNET_STATISTICS_set (stats, |
4481 | "# expected pushes", | 4524 | "# expected pushes", |
4482 | alpha * sub->view_size_est_need, | 4525 | alpha * sub->view_size_est_need, |
4483 | GNUNET_NO); | 4526 | GNUNET_NO); |
4484 | GNUNET_STATISTICS_set(stats, | 4527 | GNUNET_STATISTICS_set (stats, |
4485 | "delta expected - received pushes", | 4528 | "delta expected - received pushes", |
4486 | CustomPeerMap_size(sub->push_map) - (alpha * sub->view_size_est_need), | 4529 | CustomPeerMap_size (sub->push_map) - (alpha |
4487 | GNUNET_NO); | 4530 | * sub-> |
4488 | } | 4531 | view_size_est_need), |
4489 | 4532 | GNUNET_NO); | |
4490 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 4533 | } |
4491 | "Received %u pushes and %u pulls last round (alpha (%.2f) * view_size (sub->view%u) = %.2f)\n", | 4534 | |
4492 | CustomPeerMap_size(sub->push_map), | 4535 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
4493 | CustomPeerMap_size(sub->pull_map), | 4536 | "Received %u pushes and %u pulls last round (alpha (%.2f) * view_size (sub->view%u) = %.2f)\n", |
4494 | alpha, | 4537 | CustomPeerMap_size (sub->push_map), |
4495 | View_size(sub->view), | 4538 | CustomPeerMap_size (sub->pull_map), |
4496 | alpha * View_size(sub->view)); | 4539 | alpha, |
4540 | View_size (sub->view), | ||
4541 | alpha * View_size (sub->view)); | ||
4497 | 4542 | ||
4498 | /* Update samplers */ | 4543 | /* Update samplers */ |
4499 | for (i = 0; i < CustomPeerMap_size(sub->push_map); i++) | 4544 | for (i = 0; i < CustomPeerMap_size (sub->push_map); i++) |
4500 | { | 4545 | { |
4501 | update_peer = CustomPeerMap_get_peer_by_index(sub->push_map, i); | 4546 | update_peer = CustomPeerMap_get_peer_by_index (sub->push_map, i); |
4502 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 4547 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
4503 | "Updating with peer %s from push list\n", | 4548 | "Updating with peer %s from push list\n", |
4504 | GNUNET_i2s(update_peer)); | 4549 | GNUNET_i2s (update_peer)); |
4505 | insert_in_sampler(sub, update_peer); | 4550 | insert_in_sampler (sub, update_peer); |
4506 | clean_peer(sub, update_peer); /* This cleans only if it is not in the view */ | 4551 | clean_peer (sub, update_peer); /* This cleans only if it is not in the view */ |
4507 | } | 4552 | } |
4508 | 4553 | ||
4509 | for (i = 0; i < CustomPeerMap_size(sub->pull_map); i++) | 4554 | for (i = 0; i < CustomPeerMap_size (sub->pull_map); i++) |
4510 | { | 4555 | { |
4511 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 4556 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
4512 | "Updating with peer %s from pull list\n", | 4557 | "Updating with peer %s from pull list\n", |
4513 | GNUNET_i2s(CustomPeerMap_get_peer_by_index(sub->pull_map, i))); | 4558 | GNUNET_i2s (CustomPeerMap_get_peer_by_index (sub->pull_map, i))); |
4514 | insert_in_sampler(sub, CustomPeerMap_get_peer_by_index(sub->pull_map, i)); | 4559 | insert_in_sampler (sub, CustomPeerMap_get_peer_by_index (sub->pull_map, i)); |
4515 | /* This cleans only if it is not in the view */ | 4560 | /* This cleans only if it is not in the view */ |
4516 | clean_peer(sub, CustomPeerMap_get_peer_by_index(sub->pull_map, i)); | 4561 | clean_peer (sub, CustomPeerMap_get_peer_by_index (sub->pull_map, i)); |
4517 | } | 4562 | } |
4518 | 4563 | ||
4519 | 4564 | ||
4520 | /* Empty push/pull lists */ | 4565 | /* Empty push/pull lists */ |
4521 | CustomPeerMap_clear(sub->push_map); | 4566 | CustomPeerMap_clear (sub->push_map); |
4522 | CustomPeerMap_clear(sub->pull_map); | 4567 | CustomPeerMap_clear (sub->pull_map); |
4523 | 4568 | ||
4524 | if (sub == msub) | 4569 | if (sub == msub) |
4525 | { | 4570 | { |
4526 | GNUNET_STATISTICS_set(stats, | 4571 | GNUNET_STATISTICS_set (stats, |
4527 | "view size", | 4572 | "view size", |
4528 | View_size(sub->view), | 4573 | View_size (sub->view), |
4529 | GNUNET_NO); | 4574 | GNUNET_NO); |
4530 | } | 4575 | } |
4531 | 4576 | ||
4532 | struct GNUNET_TIME_Relative time_next_round; | 4577 | struct GNUNET_TIME_Relative time_next_round; |
4533 | 4578 | ||
4534 | time_next_round = compute_rand_delay(sub->round_interval, 2); | 4579 | time_next_round = compute_rand_delay (sub->round_interval, 2); |
4535 | 4580 | ||
4536 | /* Schedule next round */ | 4581 | /* Schedule next round */ |
4537 | sub->do_round_task = GNUNET_SCHEDULER_add_delayed(time_next_round, | 4582 | sub->do_round_task = GNUNET_SCHEDULER_add_delayed (time_next_round, |
4538 | &do_round, sub); | 4583 | &do_round, sub); |
4539 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Finished round\n"); | 4584 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Finished round\n"); |
4540 | } | 4585 | } |
4541 | 4586 | ||
4542 | 4587 | ||
@@ -4556,26 +4601,26 @@ do_round(void *cls) | |||
4556 | * (0 = unknown, 1 = ourselves, 2 = neighbor) | 4601 | * (0 = unknown, 1 = ourselves, 2 = neighbor) |
4557 | */ | 4602 | */ |
4558 | void | 4603 | void |
4559 | init_peer_cb(void *cls, | 4604 | init_peer_cb (void *cls, |
4560 | const struct GNUNET_PeerIdentity *peer, | 4605 | const struct GNUNET_PeerIdentity *peer, |
4561 | int tunnel, /* "Do we have a tunnel towards this peer?" */ | 4606 | int tunnel, /* "Do we have a tunnel towards this peer?" */ |
4562 | unsigned int n_paths, /* "Number of known paths towards this peer" */ | 4607 | unsigned int n_paths, /* "Number of known paths towards this peer" */ |
4563 | unsigned int best_path) /* "How long is the best path? | 4608 | unsigned int best_path) /* "How long is the best path? |
4564 | * (0 = unknown, 1 = ourselves, 2 = neighbor)" */ | 4609 | * (0 = unknown, 1 = ourselves, 2 = neighbor)" */ |
4565 | { | 4610 | { |
4566 | struct Sub *sub = cls; | 4611 | struct Sub *sub = cls; |
4567 | 4612 | ||
4568 | (void)tunnel; | 4613 | (void) tunnel; |
4569 | (void)n_paths; | 4614 | (void) n_paths; |
4570 | (void)best_path; | 4615 | (void) best_path; |
4571 | 4616 | ||
4572 | if (NULL != peer) | 4617 | if (NULL != peer) |
4573 | { | 4618 | { |
4574 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 4619 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
4575 | "Got peer_id %s from cadet\n", | 4620 | "Got peer_id %s from cadet\n", |
4576 | GNUNET_i2s(peer)); | 4621 | GNUNET_i2s (peer)); |
4577 | got_peer(sub, peer); | 4622 | got_peer (sub, peer); |
4578 | } | 4623 | } |
4579 | } | 4624 | } |
4580 | 4625 | ||
4581 | 4626 | ||
@@ -4591,18 +4636,18 @@ init_peer_cb(void *cls, | |||
4591 | * #GNUNET_NO if not. | 4636 | * #GNUNET_NO if not. |
4592 | */ | 4637 | */ |
4593 | static int | 4638 | static int |
4594 | valid_peers_iterator(void *cls, | 4639 | valid_peers_iterator (void *cls, |
4595 | const struct GNUNET_PeerIdentity *peer) | 4640 | const struct GNUNET_PeerIdentity *peer) |
4596 | { | 4641 | { |
4597 | struct Sub *sub = cls; | 4642 | struct Sub *sub = cls; |
4598 | 4643 | ||
4599 | if (NULL != peer) | 4644 | if (NULL != peer) |
4600 | { | 4645 | { |
4601 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 4646 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
4602 | "Got stored, valid peer %s\n", | 4647 | "Got stored, valid peer %s\n", |
4603 | GNUNET_i2s(peer)); | 4648 | GNUNET_i2s (peer)); |
4604 | got_peer(sub, peer); | 4649 | got_peer (sub, peer); |
4605 | } | 4650 | } |
4606 | return GNUNET_YES; | 4651 | return GNUNET_YES; |
4607 | } | 4652 | } |
4608 | 4653 | ||
@@ -4616,23 +4661,23 @@ valid_peers_iterator(void *cls, | |||
4616 | * @param error message | 4661 | * @param error message |
4617 | */ | 4662 | */ |
4618 | void | 4663 | void |
4619 | process_peerinfo_peers(void *cls, | 4664 | process_peerinfo_peers (void *cls, |
4620 | const struct GNUNET_PeerIdentity *peer, | 4665 | const struct GNUNET_PeerIdentity *peer, |
4621 | const struct GNUNET_HELLO_Message *hello, | 4666 | const struct GNUNET_HELLO_Message *hello, |
4622 | const char *err_msg) | 4667 | const char *err_msg) |
4623 | { | 4668 | { |
4624 | struct Sub *sub = cls; | 4669 | struct Sub *sub = cls; |
4625 | 4670 | ||
4626 | (void)hello; | 4671 | (void) hello; |
4627 | (void)err_msg; | 4672 | (void) err_msg; |
4628 | 4673 | ||
4629 | if (NULL != peer) | 4674 | if (NULL != peer) |
4630 | { | 4675 | { |
4631 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 4676 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
4632 | "Got peer_id %s from peerinfo\n", | 4677 | "Got peer_id %s from peerinfo\n", |
4633 | GNUNET_i2s(peer)); | 4678 | GNUNET_i2s (peer)); |
4634 | got_peer(sub, peer); | 4679 | got_peer (sub, peer); |
4635 | } | 4680 | } |
4636 | } | 4681 | } |
4637 | 4682 | ||
4638 | 4683 | ||
@@ -4642,69 +4687,69 @@ process_peerinfo_peers(void *cls, | |||
4642 | * @param cls Closure - unused | 4687 | * @param cls Closure - unused |
4643 | */ | 4688 | */ |
4644 | static void | 4689 | static void |
4645 | shutdown_task(void *cls) | 4690 | shutdown_task (void *cls) |
4646 | { | 4691 | { |
4647 | (void)cls; | 4692 | (void) cls; |
4648 | struct ClientContext *client_ctx; | 4693 | struct ClientContext *client_ctx; |
4649 | 4694 | ||
4650 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 4695 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
4651 | "RPS service is going down\n"); | 4696 | "RPS service is going down\n"); |
4652 | 4697 | ||
4653 | /* Clean all clients */ | 4698 | /* Clean all clients */ |
4654 | for (client_ctx = cli_ctx_head; | 4699 | for (client_ctx = cli_ctx_head; |
4655 | NULL != cli_ctx_head; | 4700 | NULL != cli_ctx_head; |
4656 | client_ctx = cli_ctx_head) | 4701 | client_ctx = cli_ctx_head) |
4657 | { | 4702 | { |
4658 | destroy_cli_ctx(client_ctx); | 4703 | destroy_cli_ctx (client_ctx); |
4659 | } | 4704 | } |
4660 | if (NULL != msub) | 4705 | if (NULL != msub) |
4661 | { | 4706 | { |
4662 | destroy_sub(msub); | 4707 | destroy_sub (msub); |
4663 | msub = NULL; | 4708 | msub = NULL; |
4664 | } | 4709 | } |
4665 | 4710 | ||
4666 | /* Disconnect from other services */ | 4711 | /* Disconnect from other services */ |
4667 | GNUNET_PEERINFO_notify_cancel(peerinfo_notify_handle); | 4712 | GNUNET_PEERINFO_notify_cancel (peerinfo_notify_handle); |
4668 | GNUNET_PEERINFO_disconnect(peerinfo_handle); | 4713 | GNUNET_PEERINFO_disconnect (peerinfo_handle); |
4669 | peerinfo_handle = NULL; | 4714 | peerinfo_handle = NULL; |
4670 | GNUNET_NSE_disconnect(nse); | 4715 | GNUNET_NSE_disconnect (nse); |
4671 | if (NULL != map_single_hop) | 4716 | if (NULL != map_single_hop) |
4672 | { | 4717 | { |
4673 | /* core_init was called - core was initialised */ | 4718 | /* core_init was called - core was initialised */ |
4674 | /* disconnect first, so no callback tries to access missing peermap */ | 4719 | /* disconnect first, so no callback tries to access missing peermap */ |
4675 | GNUNET_CORE_disconnect(core_handle); | 4720 | GNUNET_CORE_disconnect (core_handle); |
4676 | core_handle = NULL; | 4721 | core_handle = NULL; |
4677 | GNUNET_CONTAINER_multipeermap_destroy(map_single_hop); | 4722 | GNUNET_CONTAINER_multipeermap_destroy (map_single_hop); |
4678 | map_single_hop = NULL; | 4723 | map_single_hop = NULL; |
4679 | } | 4724 | } |
4680 | 4725 | ||
4681 | if (NULL != stats) | 4726 | if (NULL != stats) |
4682 | { | 4727 | { |
4683 | GNUNET_STATISTICS_destroy(stats, | 4728 | GNUNET_STATISTICS_destroy (stats, |
4684 | GNUNET_NO); | 4729 | GNUNET_NO); |
4685 | stats = NULL; | 4730 | stats = NULL; |
4686 | } | 4731 | } |
4687 | GNUNET_CADET_disconnect(cadet_handle); | 4732 | GNUNET_CADET_disconnect (cadet_handle); |
4688 | cadet_handle = NULL; | 4733 | cadet_handle = NULL; |
4689 | #if ENABLE_MALICIOUS | 4734 | #if ENABLE_MALICIOUS |
4690 | struct AttackedPeer *tmp_att_peer; | 4735 | struct AttackedPeer *tmp_att_peer; |
4691 | GNUNET_array_grow(mal_peers, | 4736 | GNUNET_array_grow (mal_peers, |
4692 | num_mal_peers, | 4737 | num_mal_peers, |
4693 | 0); | 4738 | 0); |
4694 | if (NULL != mal_peer_set) | 4739 | if (NULL != mal_peer_set) |
4695 | GNUNET_CONTAINER_multipeermap_destroy(mal_peer_set); | 4740 | GNUNET_CONTAINER_multipeermap_destroy (mal_peer_set); |
4696 | if (NULL != att_peer_set) | 4741 | if (NULL != att_peer_set) |
4697 | GNUNET_CONTAINER_multipeermap_destroy(att_peer_set); | 4742 | GNUNET_CONTAINER_multipeermap_destroy (att_peer_set); |
4698 | while (NULL != att_peers_head) | 4743 | while (NULL != att_peers_head) |
4699 | { | 4744 | { |
4700 | tmp_att_peer = att_peers_head; | 4745 | tmp_att_peer = att_peers_head; |
4701 | GNUNET_CONTAINER_DLL_remove(att_peers_head, | 4746 | GNUNET_CONTAINER_DLL_remove (att_peers_head, |
4702 | att_peers_tail, | 4747 | att_peers_tail, |
4703 | tmp_att_peer); | 4748 | tmp_att_peer); |
4704 | GNUNET_free(tmp_att_peer); | 4749 | GNUNET_free (tmp_att_peer); |
4705 | } | 4750 | } |
4706 | #endif /* ENABLE_MALICIOUS */ | 4751 | #endif /* ENABLE_MALICIOUS */ |
4707 | close_all_files(); | 4752 | close_all_files (); |
4708 | } | 4753 | } |
4709 | 4754 | ||
4710 | 4755 | ||
@@ -4717,26 +4762,26 @@ shutdown_task(void *cls) | |||
4717 | * @return @a client | 4762 | * @return @a client |
4718 | */ | 4763 | */ |
4719 | static void * | 4764 | static void * |
4720 | client_connect_cb(void *cls, | 4765 | client_connect_cb (void *cls, |
4721 | struct GNUNET_SERVICE_Client *client, | 4766 | struct GNUNET_SERVICE_Client *client, |
4722 | struct GNUNET_MQ_Handle *mq) | 4767 | struct GNUNET_MQ_Handle *mq) |
4723 | { | 4768 | { |
4724 | struct ClientContext *cli_ctx; | 4769 | struct ClientContext *cli_ctx; |
4725 | 4770 | ||
4726 | (void)cls; | 4771 | (void) cls; |
4727 | 4772 | ||
4728 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 4773 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
4729 | "Client connected\n"); | 4774 | "Client connected\n"); |
4730 | if (NULL == client) | 4775 | if (NULL == client) |
4731 | return client; /* Server was destroyed before a client connected. Shutting down */ | 4776 | return client; /* Server was destroyed before a client connected. Shutting down */ |
4732 | cli_ctx = GNUNET_new(struct ClientContext); | 4777 | cli_ctx = GNUNET_new (struct ClientContext); |
4733 | cli_ctx->mq = mq; | 4778 | cli_ctx->mq = mq; |
4734 | cli_ctx->view_updates_left = -1; | 4779 | cli_ctx->view_updates_left = -1; |
4735 | cli_ctx->stream_update = GNUNET_NO; | 4780 | cli_ctx->stream_update = GNUNET_NO; |
4736 | cli_ctx->client = client; | 4781 | cli_ctx->client = client; |
4737 | GNUNET_CONTAINER_DLL_insert(cli_ctx_head, | 4782 | GNUNET_CONTAINER_DLL_insert (cli_ctx_head, |
4738 | cli_ctx_tail, | 4783 | cli_ctx_tail, |
4739 | cli_ctx); | 4784 | cli_ctx); |
4740 | return cli_ctx; | 4785 | return cli_ctx; |
4741 | } | 4786 | } |
4742 | 4787 | ||
@@ -4748,25 +4793,25 @@ client_connect_cb(void *cls, | |||
4748 | * @param internal_cls should be equal to @a c | 4793 | * @param internal_cls should be equal to @a c |
4749 | */ | 4794 | */ |
4750 | static void | 4795 | static void |
4751 | client_disconnect_cb(void *cls, | 4796 | client_disconnect_cb (void *cls, |
4752 | struct GNUNET_SERVICE_Client *client, | 4797 | struct GNUNET_SERVICE_Client *client, |
4753 | void *internal_cls) | 4798 | void *internal_cls) |
4754 | { | 4799 | { |
4755 | struct ClientContext *cli_ctx = internal_cls; | 4800 | struct ClientContext *cli_ctx = internal_cls; |
4756 | 4801 | ||
4757 | (void)cls; | 4802 | (void) cls; |
4758 | GNUNET_assert(client == cli_ctx->client); | 4803 | GNUNET_assert (client == cli_ctx->client); |
4759 | if (NULL == client) | 4804 | if (NULL == client) |
4760 | {/* shutdown task - destroy all clients */ | 4805 | { /* shutdown task - destroy all clients */ |
4761 | while (NULL != cli_ctx_head) | 4806 | while (NULL != cli_ctx_head) |
4762 | destroy_cli_ctx(cli_ctx_head); | 4807 | destroy_cli_ctx (cli_ctx_head); |
4763 | } | 4808 | } |
4764 | else | 4809 | else |
4765 | { /* destroy this client */ | 4810 | { /* destroy this client */ |
4766 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 4811 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
4767 | "Client disconnected. Destroy its context.\n"); | 4812 | "Client disconnected. Destroy its context.\n"); |
4768 | destroy_cli_ctx(cli_ctx); | 4813 | destroy_cli_ctx (cli_ctx); |
4769 | } | 4814 | } |
4770 | } | 4815 | } |
4771 | 4816 | ||
4772 | 4817 | ||
@@ -4778,68 +4823,68 @@ client_disconnect_cb(void *cls, | |||
4778 | * @param service the initialized service | 4823 | * @param service the initialized service |
4779 | */ | 4824 | */ |
4780 | static void | 4825 | static void |
4781 | run(void *cls, | 4826 | run (void *cls, |
4782 | const struct GNUNET_CONFIGURATION_Handle *c, | 4827 | const struct GNUNET_CONFIGURATION_Handle *c, |
4783 | struct GNUNET_SERVICE_Handle *service) | 4828 | struct GNUNET_SERVICE_Handle *service) |
4784 | { | 4829 | { |
4785 | struct GNUNET_TIME_Relative round_interval; | 4830 | struct GNUNET_TIME_Relative round_interval; |
4786 | long long unsigned int sampler_size; | 4831 | long long unsigned int sampler_size; |
4787 | char hash_port_string[] = GNUNET_APPLICATION_PORT_RPS; | 4832 | char hash_port_string[] = GNUNET_APPLICATION_PORT_RPS; |
4788 | struct GNUNET_HashCode hash; | 4833 | struct GNUNET_HashCode hash; |
4789 | 4834 | ||
4790 | (void)cls; | 4835 | (void) cls; |
4791 | (void)service; | 4836 | (void) service; |
4792 | 4837 | ||
4793 | GNUNET_log_setup("rps", | 4838 | GNUNET_log_setup ("rps", |
4794 | GNUNET_error_type_to_string(GNUNET_ERROR_TYPE_DEBUG), | 4839 | GNUNET_error_type_to_string (GNUNET_ERROR_TYPE_DEBUG), |
4795 | NULL); | 4840 | NULL); |
4796 | cfg = c; | 4841 | cfg = c; |
4797 | /* Get own ID */ | 4842 | /* Get own ID */ |
4798 | GNUNET_CRYPTO_get_peer_identity(cfg, | 4843 | GNUNET_CRYPTO_get_peer_identity (cfg, |
4799 | &own_identity); // TODO check return value | 4844 | &own_identity); // TODO check return value |
4800 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 4845 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
4801 | "STARTING SERVICE (rps) for peer [%s]\n", | 4846 | "STARTING SERVICE (rps) for peer [%s]\n", |
4802 | GNUNET_i2s(&own_identity)); | 4847 | GNUNET_i2s (&own_identity)); |
4803 | #if ENABLE_MALICIOUS | 4848 | #if ENABLE_MALICIOUS |
4804 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 4849 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
4805 | "Malicious execution compiled in.\n"); | 4850 | "Malicious execution compiled in.\n"); |
4806 | #endif /* ENABLE_MALICIOUS */ | 4851 | #endif /* ENABLE_MALICIOUS */ |
4807 | 4852 | ||
4808 | /* Get time interval from the configuration */ | 4853 | /* Get time interval from the configuration */ |
4809 | if (GNUNET_OK != | 4854 | if (GNUNET_OK != |
4810 | GNUNET_CONFIGURATION_get_value_time(cfg, | 4855 | GNUNET_CONFIGURATION_get_value_time (cfg, |
4811 | "RPS", | 4856 | "RPS", |
4812 | "ROUNDINTERVAL", | 4857 | "ROUNDINTERVAL", |
4813 | &round_interval)) | 4858 | &round_interval)) |
4814 | { | 4859 | { |
4815 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, | 4860 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
4816 | "RPS", "ROUNDINTERVAL"); | 4861 | "RPS", "ROUNDINTERVAL"); |
4817 | GNUNET_SCHEDULER_shutdown(); | 4862 | GNUNET_SCHEDULER_shutdown (); |
4818 | return; | 4863 | return; |
4819 | } | 4864 | } |
4820 | 4865 | ||
4821 | /* Get initial size of sampler/view from the configuration */ | 4866 | /* Get initial size of sampler/view from the configuration */ |
4822 | if (GNUNET_OK != | 4867 | if (GNUNET_OK != |
4823 | GNUNET_CONFIGURATION_get_value_number(cfg, | 4868 | GNUNET_CONFIGURATION_get_value_number (cfg, |
4824 | "RPS", | 4869 | "RPS", |
4825 | "MINSIZE", | 4870 | "MINSIZE", |
4826 | &sampler_size)) | 4871 | &sampler_size)) |
4827 | { | 4872 | { |
4828 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, | 4873 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
4829 | "RPS", "MINSIZE"); | 4874 | "RPS", "MINSIZE"); |
4830 | GNUNET_SCHEDULER_shutdown(); | 4875 | GNUNET_SCHEDULER_shutdown (); |
4831 | return; | 4876 | return; |
4832 | } | 4877 | } |
4833 | 4878 | ||
4834 | cadet_handle = GNUNET_CADET_connect(cfg); | 4879 | cadet_handle = GNUNET_CADET_connect (cfg); |
4835 | GNUNET_assert(NULL != cadet_handle); | 4880 | GNUNET_assert (NULL != cadet_handle); |
4836 | core_handle = GNUNET_CORE_connect(cfg, | 4881 | core_handle = GNUNET_CORE_connect (cfg, |
4837 | NULL, /* cls */ | 4882 | NULL, /* cls */ |
4838 | core_init, /* init */ | 4883 | core_init, /* init */ |
4839 | core_connects, /* connects */ | 4884 | core_connects, /* connects */ |
4840 | core_disconnects, /* disconnects */ | 4885 | core_disconnects, /* disconnects */ |
4841 | NULL); /* handlers */ | 4886 | NULL); /* handlers */ |
4842 | GNUNET_assert(NULL != core_handle); | 4887 | GNUNET_assert (NULL != core_handle); |
4843 | 4888 | ||
4844 | 4889 | ||
4845 | alpha = 0.45; | 4890 | alpha = 0.45; |
@@ -4847,35 +4892,35 @@ run(void *cls, | |||
4847 | 4892 | ||
4848 | 4893 | ||
4849 | /* Set up main Sub */ | 4894 | /* Set up main Sub */ |
4850 | GNUNET_CRYPTO_hash(hash_port_string, | 4895 | GNUNET_CRYPTO_hash (hash_port_string, |
4851 | strlen(hash_port_string), | 4896 | strlen (hash_port_string), |
4852 | &hash); | 4897 | &hash); |
4853 | msub = new_sub(&hash, | 4898 | msub = new_sub (&hash, |
4854 | sampler_size, /* Will be overwritten by config */ | 4899 | sampler_size, /* Will be overwritten by config */ |
4855 | round_interval); | 4900 | round_interval); |
4856 | 4901 | ||
4857 | 4902 | ||
4858 | peerinfo_handle = GNUNET_PEERINFO_connect(cfg); | 4903 | peerinfo_handle = GNUNET_PEERINFO_connect (cfg); |
4859 | 4904 | ||
4860 | /* connect to NSE */ | 4905 | /* connect to NSE */ |
4861 | nse = GNUNET_NSE_connect(cfg, nse_callback, NULL); | 4906 | nse = GNUNET_NSE_connect (cfg, nse_callback, NULL); |
4862 | 4907 | ||
4863 | //LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting peers from CADET\n"); | 4908 | // LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting peers from CADET\n"); |
4864 | //GNUNET_CADET_get_peers (cadet_handle, &init_peer_cb, msub); | 4909 | // GNUNET_CADET_get_peers (cadet_handle, &init_peer_cb, msub); |
4865 | // TODO send push/pull to each of those peers? | 4910 | // TODO send push/pull to each of those peers? |
4866 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Requesting stored valid peers\n"); | 4911 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting stored valid peers\n"); |
4867 | restore_valid_peers(msub); | 4912 | restore_valid_peers (msub); |
4868 | get_valid_peers(msub->valid_peers, valid_peers_iterator, msub); | 4913 | get_valid_peers (msub->valid_peers, valid_peers_iterator, msub); |
4869 | 4914 | ||
4870 | peerinfo_notify_handle = GNUNET_PEERINFO_notify(cfg, | 4915 | peerinfo_notify_handle = GNUNET_PEERINFO_notify (cfg, |
4871 | GNUNET_NO, | 4916 | GNUNET_NO, |
4872 | process_peerinfo_peers, | 4917 | process_peerinfo_peers, |
4873 | msub); | 4918 | msub); |
4874 | 4919 | ||
4875 | LOG(GNUNET_ERROR_TYPE_INFO, "Ready to receive requests from clients\n"); | 4920 | LOG (GNUNET_ERROR_TYPE_INFO, "Ready to receive requests from clients\n"); |
4876 | 4921 | ||
4877 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); | 4922 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
4878 | stats = GNUNET_STATISTICS_create("rps", cfg); | 4923 | stats = GNUNET_STATISTICS_create ("rps", cfg); |
4879 | } | 4924 | } |
4880 | 4925 | ||
4881 | 4926 | ||
@@ -4889,40 +4934,40 @@ GNUNET_SERVICE_MAIN | |||
4889 | &client_connect_cb, | 4934 | &client_connect_cb, |
4890 | &client_disconnect_cb, | 4935 | &client_disconnect_cb, |
4891 | NULL, | 4936 | NULL, |
4892 | GNUNET_MQ_hd_var_size(client_seed, | 4937 | GNUNET_MQ_hd_var_size (client_seed, |
4893 | GNUNET_MESSAGE_TYPE_RPS_CS_SEED, | 4938 | GNUNET_MESSAGE_TYPE_RPS_CS_SEED, |
4894 | struct GNUNET_RPS_CS_SeedMessage, | 4939 | struct GNUNET_RPS_CS_SeedMessage, |
4895 | NULL), | 4940 | NULL), |
4896 | #if ENABLE_MALICIOUS | 4941 | #if ENABLE_MALICIOUS |
4897 | GNUNET_MQ_hd_var_size(client_act_malicious, | 4942 | GNUNET_MQ_hd_var_size (client_act_malicious, |
4898 | GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS, | 4943 | GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS, |
4899 | struct GNUNET_RPS_CS_ActMaliciousMessage, | 4944 | struct GNUNET_RPS_CS_ActMaliciousMessage, |
4900 | NULL), | 4945 | NULL), |
4901 | #endif /* ENABLE_MALICIOUS */ | 4946 | #endif /* ENABLE_MALICIOUS */ |
4902 | GNUNET_MQ_hd_fixed_size(client_view_request, | 4947 | GNUNET_MQ_hd_fixed_size (client_view_request, |
4903 | GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REQUEST, | 4948 | GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REQUEST, |
4904 | struct GNUNET_RPS_CS_DEBUG_ViewRequest, | 4949 | struct GNUNET_RPS_CS_DEBUG_ViewRequest, |
4905 | NULL), | 4950 | NULL), |
4906 | GNUNET_MQ_hd_fixed_size(client_view_cancel, | 4951 | GNUNET_MQ_hd_fixed_size (client_view_cancel, |
4907 | GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_CANCEL, | 4952 | GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_CANCEL, |
4908 | struct GNUNET_MessageHeader, | 4953 | struct GNUNET_MessageHeader, |
4909 | NULL), | 4954 | NULL), |
4910 | GNUNET_MQ_hd_fixed_size(client_stream_request, | 4955 | GNUNET_MQ_hd_fixed_size (client_stream_request, |
4911 | GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REQUEST, | 4956 | GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REQUEST, |
4912 | struct GNUNET_RPS_CS_DEBUG_StreamRequest, | 4957 | struct GNUNET_RPS_CS_DEBUG_StreamRequest, |
4913 | NULL), | 4958 | NULL), |
4914 | GNUNET_MQ_hd_fixed_size(client_stream_cancel, | 4959 | GNUNET_MQ_hd_fixed_size (client_stream_cancel, |
4915 | GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_CANCEL, | 4960 | GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_CANCEL, |
4916 | struct GNUNET_MessageHeader, | 4961 | struct GNUNET_MessageHeader, |
4917 | NULL), | 4962 | NULL), |
4918 | GNUNET_MQ_hd_fixed_size(client_start_sub, | 4963 | GNUNET_MQ_hd_fixed_size (client_start_sub, |
4919 | GNUNET_MESSAGE_TYPE_RPS_CS_SUB_START, | 4964 | GNUNET_MESSAGE_TYPE_RPS_CS_SUB_START, |
4920 | struct GNUNET_RPS_CS_SubStartMessage, | 4965 | struct GNUNET_RPS_CS_SubStartMessage, |
4921 | NULL), | 4966 | NULL), |
4922 | GNUNET_MQ_hd_fixed_size(client_stop_sub, | 4967 | GNUNET_MQ_hd_fixed_size (client_stop_sub, |
4923 | GNUNET_MESSAGE_TYPE_RPS_CS_SUB_STOP, | 4968 | GNUNET_MESSAGE_TYPE_RPS_CS_SUB_STOP, |
4924 | struct GNUNET_RPS_CS_SubStopMessage, | 4969 | struct GNUNET_RPS_CS_SubStopMessage, |
4925 | NULL), | 4970 | NULL), |
4926 | GNUNET_MQ_handler_end()); | 4971 | GNUNET_MQ_handler_end ()); |
4927 | 4972 | ||
4928 | /* end of gnunet-service-rps.c */ | 4973 | /* end of gnunet-service-rps.c */ |