diff options
Diffstat (limited to 'src/rps/gnunet-service-rps.c')
-rw-r--r-- | src/rps/gnunet-service-rps.c | 164 |
1 files changed, 158 insertions, 6 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index 193e44411..20b314db3 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include "gnunet_applications.h" | 25 | #include "gnunet_applications.h" |
26 | #include "gnunet_util_lib.h" | 26 | #include "gnunet_util_lib.h" |
27 | #include "gnunet_cadet_service.h" | 27 | #include "gnunet_cadet_service.h" |
28 | #include "gnunet_core_service.h" | ||
28 | #include "gnunet_peerinfo_service.h" | 29 | #include "gnunet_peerinfo_service.h" |
29 | #include "gnunet_nse_service.h" | 30 | #include "gnunet_nse_service.h" |
30 | #include "gnunet_statistics_service.h" | 31 | #include "gnunet_statistics_service.h" |
@@ -447,6 +448,16 @@ struct GNUNET_STATISTICS_Handle *stats; | |||
447 | struct GNUNET_CADET_Handle *cadet_handle; | 448 | struct GNUNET_CADET_Handle *cadet_handle; |
448 | 449 | ||
449 | /** | 450 | /** |
451 | * Handle to CORE | ||
452 | */ | ||
453 | struct GNUNET_CORE_Handle *core_handle; | ||
454 | |||
455 | /** | ||
456 | * @brief PeerMap to keep track of connected peers. | ||
457 | */ | ||
458 | struct GNUNET_CONTAINER_MultiPeerMap *map_single_hop; | ||
459 | |||
460 | /** | ||
450 | * Our own identity. | 461 | * Our own identity. |
451 | */ | 462 | */ |
452 | static struct GNUNET_PeerIdentity own_identity; | 463 | static struct GNUNET_PeerIdentity own_identity; |
@@ -768,8 +779,7 @@ get_rand_peer_iterator (void *cls, | |||
768 | * @return a random peer | 779 | * @return a random peer |
769 | */ | 780 | */ |
770 | static const struct GNUNET_PeerIdentity * | 781 | static const struct GNUNET_PeerIdentity * |
771 | get_random_peer_from_peermap (const struct | 782 | get_random_peer_from_peermap (struct GNUNET_CONTAINER_MultiPeerMap *valid_peers) |
772 | GNUNET_CONTAINER_MultiPeerMap *valid_peers) | ||
773 | { | 783 | { |
774 | struct GetRandPeerIteratorCls *iterator_cls; | 784 | struct GetRandPeerIteratorCls *iterator_cls; |
775 | const struct GNUNET_PeerIdentity *ret; | 785 | const struct GNUNET_PeerIdentity *ret; |
@@ -1366,6 +1376,13 @@ mq_notify_sent_cb (void *cls) | |||
1366 | GNUNET_STATISTICS_update(stats, "# pull requests sent", 1, GNUNET_NO); | 1376 | GNUNET_STATISTICS_update(stats, "# pull requests sent", 1, GNUNET_NO); |
1367 | if (0 == strncmp ("PUSH", pending_msg->type, 4)) | 1377 | if (0 == strncmp ("PUSH", pending_msg->type, 4)) |
1368 | GNUNET_STATISTICS_update(stats, "# pushes sent", 1, GNUNET_NO); | 1378 | GNUNET_STATISTICS_update(stats, "# pushes sent", 1, GNUNET_NO); |
1379 | if (0 == strncmp ("PULL REQUEST", pending_msg->type, 12) && | ||
1380 | GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (map_single_hop, | ||
1381 | &pending_msg->peer_ctx->peer_id)) | ||
1382 | GNUNET_STATISTICS_update(stats, | ||
1383 | "# pull requests sent (multi-hop peer)", | ||
1384 | 1, | ||
1385 | GNUNET_NO); | ||
1369 | } | 1386 | } |
1370 | /* Do not cancle message */ | 1387 | /* Do not cancle message */ |
1371 | remove_pending_message (pending_msg, GNUNET_NO); | 1388 | remove_pending_message (pending_msg, GNUNET_NO); |
@@ -1642,7 +1659,7 @@ valid_peer_iterator (void *cls, | |||
1642 | * #GNUNET_SYSERR if it aborted iteration | 1659 | * #GNUNET_SYSERR if it aborted iteration |
1643 | */ | 1660 | */ |
1644 | static int | 1661 | static int |
1645 | get_valid_peers (const struct GNUNET_CONTAINER_MultiPeerMap *valid_peers, | 1662 | get_valid_peers (struct GNUNET_CONTAINER_MultiPeerMap *valid_peers, |
1646 | PeersIterator iterator, | 1663 | PeersIterator iterator, |
1647 | void *it_cls) | 1664 | void *it_cls) |
1648 | { | 1665 | { |
@@ -2150,7 +2167,7 @@ rem_from_list (struct GNUNET_PeerIdentity **peer_list, | |||
2150 | */ | 2167 | */ |
2151 | static void | 2168 | static void |
2152 | insert_in_view_op (void *cls, | 2169 | insert_in_view_op (void *cls, |
2153 | const struct GNUNET_PeerIdentity *peer); | 2170 | const struct GNUNET_PeerIdentity *peer); |
2154 | 2171 | ||
2155 | /** | 2172 | /** |
2156 | * Insert PeerID in #view | 2173 | * Insert PeerID in #view |
@@ -2177,7 +2194,7 @@ insert_in_view (struct Sub *sub, | |||
2177 | (GNUNET_SYSERR == online) ) /* peer is not even known */ | 2194 | (GNUNET_SYSERR == online) ) /* peer is not even known */ |
2178 | { | 2195 | { |
2179 | (void) issue_peer_online_check (sub, peer); | 2196 | (void) issue_peer_online_check (sub, peer); |
2180 | (void) schedule_operation (peer_ctx, insert_in_view_op, NULL); | 2197 | (void) schedule_operation (peer_ctx, insert_in_view_op, sub); |
2181 | return GNUNET_NO; | 2198 | return GNUNET_NO; |
2182 | } | 2199 | } |
2183 | /* Open channel towards peer to keep connection open */ | 2200 | /* Open channel towards peer to keep connection open */ |
@@ -2690,6 +2707,14 @@ clean_peer (struct Sub *sub, | |||
2690 | #endif /* ENABLE_MALICIOUS */ | 2707 | #endif /* ENABLE_MALICIOUS */ |
2691 | } | 2708 | } |
2692 | 2709 | ||
2710 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (sub->peer_map, peer)) | ||
2711 | { | ||
2712 | /* Peer was already removed by callback on destroyed channel */ | ||
2713 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
2714 | "Peer was removed from our knowledge during cleanup\n"); | ||
2715 | return; | ||
2716 | } | ||
2717 | |||
2693 | if ( (GNUNET_NO == check_peer_send_intention (get_peer_ctx (sub->peer_map, | 2718 | if ( (GNUNET_NO == check_peer_send_intention (get_peer_ctx (sub->peer_map, |
2694 | peer))) && | 2719 | peer))) && |
2695 | (GNUNET_NO == View_contains_peer (sub->view, peer)) && | 2720 | (GNUNET_NO == View_contains_peer (sub->view, peer)) && |
@@ -2729,7 +2754,8 @@ cleanup_destroyed_channel (void *cls, | |||
2729 | channel_ctx->channel = NULL; | 2754 | channel_ctx->channel = NULL; |
2730 | remove_channel_ctx (channel_ctx); | 2755 | remove_channel_ctx (channel_ctx); |
2731 | if (NULL != peer_ctx && | 2756 | if (NULL != peer_ctx && |
2732 | peer_ctx->send_channel_ctx == channel_ctx) | 2757 | peer_ctx->send_channel_ctx == channel_ctx && |
2758 | GNUNET_YES == check_sending_channel_needed (channel_ctx->peer_ctx)) | ||
2733 | { | 2759 | { |
2734 | remove_peer (peer_ctx->sub, &peer_ctx->peer_id); | 2760 | remove_peer (peer_ctx->sub, &peer_ctx->peer_id); |
2735 | } | 2761 | } |
@@ -2814,6 +2840,25 @@ new_sub (const struct GNUNET_HashCode *hash, | |||
2814 | "rps", | 2840 | "rps", |
2815 | "FILENAME_VALID_PEERS"); | 2841 | "FILENAME_VALID_PEERS"); |
2816 | } | 2842 | } |
2843 | if (0 != strncmp ("DISABLE", sub->filename_valid_peers, 7)) | ||
2844 | { | ||
2845 | char *tmp_filename_valid_peers; | ||
2846 | char str_hash[105]; | ||
2847 | uint32_t len_filename_valid_peers; | ||
2848 | |||
2849 | (void) GNUNET_snprintf (str_hash, 105, GNUNET_h2s_full (hash)); | ||
2850 | tmp_filename_valid_peers = GNUNET_strdup (sub->filename_valid_peers); | ||
2851 | GNUNET_free (sub->filename_valid_peers); | ||
2852 | len_filename_valid_peers = strlen (tmp_filename_valid_peers) + 105; /* Len of full hash + 1 */ | ||
2853 | sub->filename_valid_peers = GNUNET_malloc (len_filename_valid_peers); | ||
2854 | strncat (sub->filename_valid_peers, | ||
2855 | tmp_filename_valid_peers, | ||
2856 | len_filename_valid_peers); | ||
2857 | strncat (sub->filename_valid_peers, | ||
2858 | str_hash, | ||
2859 | len_filename_valid_peers); | ||
2860 | GNUNET_free (tmp_filename_valid_peers); | ||
2861 | } | ||
2817 | sub->peer_map = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO); | 2862 | sub->peer_map = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO); |
2818 | 2863 | ||
2819 | /* Set up the sampler */ | 2864 | /* Set up the sampler */ |
@@ -2952,6 +2997,73 @@ destroy_sub (struct Sub *sub) | |||
2952 | ***********************************************************************/ | 2997 | ***********************************************************************/ |
2953 | 2998 | ||
2954 | 2999 | ||
3000 | /*********************************************************************** | ||
3001 | * Core handlers | ||
3002 | ***********************************************************************/ | ||
3003 | |||
3004 | /** | ||
3005 | * @brief Callback on initialisation of Core. | ||
3006 | * | ||
3007 | * @param cls - unused | ||
3008 | * @param my_identity - unused | ||
3009 | */ | ||
3010 | void | ||
3011 | core_init (void *cls, | ||
3012 | const struct GNUNET_PeerIdentity *my_identity) | ||
3013 | { | ||
3014 | (void) cls; | ||
3015 | (void) my_identity; | ||
3016 | |||
3017 | map_single_hop = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO); | ||
3018 | } | ||
3019 | |||
3020 | |||
3021 | /** | ||
3022 | * @brief Callback for core. | ||
3023 | * Method called whenever a given peer connects. | ||
3024 | * | ||
3025 | * @param cls closure - unused | ||
3026 | * @param peer peer identity this notification is about | ||
3027 | * @return closure given to #core_disconnects as peer_cls | ||
3028 | */ | ||
3029 | void * | ||
3030 | core_connects (void *cls, | ||
3031 | const struct GNUNET_PeerIdentity *peer, | ||
3032 | struct GNUNET_MQ_Handle *mq) | ||
3033 | { | ||
3034 | (void) cls; | ||
3035 | (void) mq; | ||
3036 | |||
3037 | GNUNET_CONTAINER_multipeermap_put (map_single_hop, peer, NULL, | ||
3038 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | ||
3039 | return NULL; | ||
3040 | } | ||
3041 | |||
3042 | |||
3043 | /** | ||
3044 | * @brief Callback for core. | ||
3045 | * Method called whenever a peer disconnects. | ||
3046 | * | ||
3047 | * @param cls closure - unused | ||
3048 | * @param peer peer identity this notification is about | ||
3049 | * @param peer_cls closure given in #core_connects - unused | ||
3050 | */ | ||
3051 | void | ||
3052 | core_disconnects (void *cls, | ||
3053 | const struct GNUNET_PeerIdentity *peer, | ||
3054 | void *peer_cls) | ||
3055 | { | ||
3056 | (void) cls; | ||
3057 | (void) peer_cls; | ||
3058 | |||
3059 | GNUNET_CONTAINER_multipeermap_remove_all (map_single_hop, peer); | ||
3060 | } | ||
3061 | |||
3062 | /*********************************************************************** | ||
3063 | * /Core handlers | ||
3064 | ***********************************************************************/ | ||
3065 | |||
3066 | |||
2955 | /** | 3067 | /** |
2956 | * @brief Destroy the context for a (connected) client | 3068 | * @brief Destroy the context for a (connected) client |
2957 | * | 3069 | * |
@@ -3395,6 +3507,14 @@ handle_peer_pull_request (void *cls, | |||
3395 | "# pull request message received", | 3507 | "# pull request message received", |
3396 | 1, | 3508 | 1, |
3397 | GNUNET_NO); | 3509 | GNUNET_NO); |
3510 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (map_single_hop, | ||
3511 | &peer_ctx->peer_id)) | ||
3512 | { | ||
3513 | GNUNET_STATISTICS_update (stats, | ||
3514 | "# pull request message received (multi-hop peer)", | ||
3515 | 1, | ||
3516 | GNUNET_NO); | ||
3517 | } | ||
3398 | } | 3518 | } |
3399 | 3519 | ||
3400 | #ifdef ENABLE_MALICIOUS | 3520 | #ifdef ENABLE_MALICIOUS |
@@ -3503,6 +3623,14 @@ handle_peer_pull_reply (void *cls, | |||
3503 | "# pull reply messages received", | 3623 | "# pull reply messages received", |
3504 | 1, | 3624 | 1, |
3505 | GNUNET_NO); | 3625 | GNUNET_NO); |
3626 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (map_single_hop, | ||
3627 | &channel_ctx->peer_ctx->peer_id)) | ||
3628 | { | ||
3629 | GNUNET_STATISTICS_update (stats, | ||
3630 | "# pull reply messages received (multi-hop peer)", | ||
3631 | 1, | ||
3632 | GNUNET_NO); | ||
3633 | } | ||
3506 | } | 3634 | } |
3507 | 3635 | ||
3508 | #ifdef ENABLE_MALICIOUS | 3636 | #ifdef ENABLE_MALICIOUS |
@@ -3650,6 +3778,14 @@ send_pull_request (struct PeerContext *peer_ctx) | |||
3650 | "# pull request send issued", | 3778 | "# pull request send issued", |
3651 | 1, | 3779 | 1, |
3652 | GNUNET_NO); | 3780 | GNUNET_NO); |
3781 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (map_single_hop, | ||
3782 | &peer_ctx->peer_id)) | ||
3783 | { | ||
3784 | GNUNET_STATISTICS_update (stats, | ||
3785 | "# pull request send issued (multi-hop peer)", | ||
3786 | 1, | ||
3787 | GNUNET_NO); | ||
3788 | } | ||
3653 | } | 3789 | } |
3654 | } | 3790 | } |
3655 | 3791 | ||
@@ -4384,6 +4520,15 @@ shutdown_task (void *cls) | |||
4384 | GNUNET_PEERINFO_disconnect (peerinfo_handle); | 4520 | GNUNET_PEERINFO_disconnect (peerinfo_handle); |
4385 | peerinfo_handle = NULL; | 4521 | peerinfo_handle = NULL; |
4386 | GNUNET_NSE_disconnect (nse); | 4522 | GNUNET_NSE_disconnect (nse); |
4523 | if (NULL != map_single_hop) | ||
4524 | { | ||
4525 | /* core_init was called - core was initialised */ | ||
4526 | /* disconnect first, so no callback tries to access missing peermap */ | ||
4527 | GNUNET_CORE_disconnect (core_handle); | ||
4528 | core_handle = NULL; | ||
4529 | GNUNET_CONTAINER_multipeermap_destroy (map_single_hop); | ||
4530 | map_single_hop = NULL; | ||
4531 | } | ||
4387 | 4532 | ||
4388 | if (NULL != stats) | 4533 | if (NULL != stats) |
4389 | { | 4534 | { |
@@ -4538,6 +4683,13 @@ run (void *cls, | |||
4538 | 4683 | ||
4539 | cadet_handle = GNUNET_CADET_connect (cfg); | 4684 | cadet_handle = GNUNET_CADET_connect (cfg); |
4540 | GNUNET_assert (NULL != cadet_handle); | 4685 | GNUNET_assert (NULL != cadet_handle); |
4686 | core_handle = GNUNET_CORE_connect (cfg, | ||
4687 | NULL, /* cls */ | ||
4688 | core_init, /* init */ | ||
4689 | core_connects, /* connects */ | ||
4690 | core_disconnects, /* disconnects */ | ||
4691 | NULL); /* handlers */ | ||
4692 | GNUNET_assert (NULL != core_handle); | ||
4541 | 4693 | ||
4542 | 4694 | ||
4543 | alpha = 0.45; | 4695 | alpha = 0.45; |