diff options
author | Supriti Singh <supritisingh08@gmail.com> | 2014-06-24 08:32:56 +0000 |
---|---|---|
committer | Supriti Singh <supritisingh08@gmail.com> | 2014-06-24 08:32:56 +0000 |
commit | 76c3b55cd2589f3376635c9a8f3b0a6f2421ca7a (patch) | |
tree | 716aa94f8c060c31e2ab835c9992021e9c1383e0 /src | |
parent | 0791a56f8b70876cf6e1513731a08e0610590c02 (diff) | |
download | gnunet-76c3b55cd2589f3376635c9a8f3b0a6f2421ca7a.tar.gz gnunet-76c3b55cd2589f3376635c9a8f3b0a6f2421ca7a.zip |
don't send trail teardown in remove_matching_fingers()
Diffstat (limited to 'src')
-rw-r--r-- | src/dht/gnunet-service-xdht_neighbours.c | 130 |
1 files changed, 95 insertions, 35 deletions
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c index b62e622cb..d00644a88 100644 --- a/src/dht/gnunet-service-xdht_neighbours.c +++ b/src/dht/gnunet-service-xdht_neighbours.c | |||
@@ -1321,9 +1321,11 @@ GDS_NEIGHBOURS_send_trail_teardown (struct GNUNET_HashCode trail_id, | |||
1321 | GNUNET_break (0); | 1321 | GNUNET_break (0); |
1322 | return; | 1322 | return; |
1323 | } | 1323 | } |
1324 | 1324 | FPRINTF (stderr,_("\nSUPU %s, %s, %d, peer = %s"), | |
1325 | __FILE__, __func__,__LINE__, GNUNET_i2s(peer)); | ||
1326 | |||
1325 | GNUNET_assert (NULL != (target_friend = | 1327 | GNUNET_assert (NULL != (target_friend = |
1326 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer))); | 1328 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer))); |
1327 | 1329 | ||
1328 | if (target_friend->pending_count >= MAXIMUM_PENDING_PER_FRIEND) | 1330 | if (target_friend->pending_count >= MAXIMUM_PENDING_PER_FRIEND) |
1329 | { | 1331 | { |
@@ -2670,6 +2672,8 @@ add_new_trail (struct FingerInfo *existing_finger, | |||
2670 | 2672 | ||
2671 | 2673 | ||
2672 | /** | 2674 | /** |
2675 | * FIXME Check if this function is called for opposite direction if yes then | ||
2676 | * take it as parameter. | ||
2673 | * Send trail teardown message for a specific trail of a finger. | 2677 | * Send trail teardown message for a specific trail of a finger. |
2674 | * @param finger Finger whose trail is to be removed. | 2678 | * @param finger Finger whose trail is to be removed. |
2675 | * @param trail List of peers in trail from me to a finger, NOT including | 2679 | * @param trail List of peers in trail from me to a finger, NOT including |
@@ -2686,12 +2690,17 @@ send_trail_teardown (struct FingerInfo *finger, | |||
2686 | then remove finger. */ | 2690 | then remove finger. */ |
2687 | /* We should decerement the friend trail count here. */ | 2691 | /* We should decerement the friend trail count here. */ |
2688 | struct FriendInfo *friend; | 2692 | struct FriendInfo *friend; |
2689 | 2693 | struct GNUNET_PeerIdentity *next_hop; | |
2694 | |||
2695 | GNUNET_assert (NULL != | ||
2696 | (next_hop = GDS_ROUTING_get_next_hop (trail->trail_id, | ||
2697 | GDS_ROUTING_SRC_TO_DEST))); | ||
2698 | |||
2690 | GNUNET_assert (NULL != (friend = | 2699 | GNUNET_assert (NULL != (friend = |
2691 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 2700 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
2692 | &trail->trail_head->peer))); | 2701 | &trail->trail_head->peer))); |
2693 | 2702 | GNUNET_assert (0 == GNUNET_CRYPTO_cmp_peer_identity (next_hop, &friend->id)); | |
2694 | //friend->trails_count--; | 2703 | friend->trails_count--; |
2695 | GDS_NEIGHBOURS_send_trail_teardown (trail->trail_id, | 2704 | GDS_NEIGHBOURS_send_trail_teardown (trail->trail_id, |
2696 | GDS_ROUTING_SRC_TO_DEST, | 2705 | GDS_ROUTING_SRC_TO_DEST, |
2697 | &trail->trail_head->peer); | 2706 | &trail->trail_head->peer); |
@@ -2706,17 +2715,15 @@ static void | |||
2706 | send_all_finger_trails_teardown (struct FingerInfo *finger) | 2715 | send_all_finger_trails_teardown (struct FingerInfo *finger) |
2707 | { | 2716 | { |
2708 | struct Trail *trail; | 2717 | struct Trail *trail; |
2709 | int i; | 2718 | unsigned int i; |
2710 | 2719 | ||
2711 | for (i = 0; i < finger->trails_count; i++) | 2720 | for (i = 0; i < finger->trails_count; i++) |
2712 | { | 2721 | { |
2713 | trail = &finger->trail_list[i]; | 2722 | trail = &finger->trail_list[i]; |
2714 | if (trail->trail_length > 0) | 2723 | GNUNET_assert (trail->trail_length > 0); |
2715 | { | 2724 | GNUNET_assert (trail->is_present == GNUNET_YES); |
2716 | /* decerement the friend trails count. */ | 2725 | send_trail_teardown (finger, trail); |
2717 | send_trail_teardown (finger, trail); | 2726 | } |
2718 | } | ||
2719 | } | ||
2720 | } | 2727 | } |
2721 | 2728 | ||
2722 | 2729 | ||
@@ -2758,7 +2765,10 @@ free_finger (struct FingerInfo *finger, unsigned int finger_table_index) | |||
2758 | continue; | 2765 | continue; |
2759 | 2766 | ||
2760 | if (trail->trail_length > 0) | 2767 | if (trail->trail_length > 0) |
2768 | { | ||
2769 | trail->is_present = GNUNET_NO; | ||
2761 | free_trail (trail); | 2770 | free_trail (trail); |
2771 | } | ||
2762 | } | 2772 | } |
2763 | 2773 | ||
2764 | finger->is_present = GNUNET_NO; | 2774 | finger->is_present = GNUNET_NO; |
@@ -2798,15 +2808,29 @@ add_new_finger (struct GNUNET_PeerIdentity finger_identity, | |||
2798 | new_entry->finger_table_index = finger_table_index; | 2808 | new_entry->finger_table_index = finger_table_index; |
2799 | new_entry->is_present = GNUNET_YES; | 2809 | new_entry->is_present = GNUNET_YES; |
2800 | 2810 | ||
2801 | /* If the new entry is my own identity or a friend. */ | 2811 | /* If the new entry is my own identity. */ |
2802 | if ((0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &finger_identity)) || | 2812 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &finger_identity)) |
2803 | (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, &finger_identity))) | ||
2804 | { | 2813 | { |
2805 | new_entry->trails_count = 0; | 2814 | new_entry->trails_count = 0; |
2806 | finger_table[finger_table_index] = *new_entry; | 2815 | finger_table[finger_table_index] = *new_entry; |
2807 | return; | 2816 | return; |
2808 | } | 2817 | } |
2809 | 2818 | ||
2819 | /* If finger is a friend, then we don't actually have a trail. | ||
2820 | * Just a trail id */ | ||
2821 | if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, | ||
2822 | &finger_identity)) | ||
2823 | { | ||
2824 | new_entry->trail_list[0].trail_id = trail_id; | ||
2825 | new_entry->trails_count = 1; | ||
2826 | new_entry->trail_list[0].is_present = GNUNET_YES; | ||
2827 | new_entry->trail_list[0].trail_length = 0; | ||
2828 | new_entry->trail_list[0].trail_head = NULL; | ||
2829 | new_entry->trail_list[0].trail_tail = NULL; | ||
2830 | finger_table[finger_table_index] = *new_entry; | ||
2831 | return; | ||
2832 | } | ||
2833 | |||
2810 | /* finger trail length can be 0 only in case if finger is my identity or | 2834 | /* finger trail length can be 0 only in case if finger is my identity or |
2811 | finger is friend. We should never reach here. */ | 2835 | finger is friend. We should never reach here. */ |
2812 | GNUNET_assert (finger_trail_length > 0); | 2836 | GNUNET_assert (finger_trail_length > 0); |
@@ -2867,7 +2891,7 @@ scan_and_compress_trail (struct GNUNET_PeerIdentity finger_identity, | |||
2867 | { | 2891 | { |
2868 | struct FriendInfo *target_friend; | 2892 | struct FriendInfo *target_friend; |
2869 | struct GNUNET_PeerIdentity *new_trail; | 2893 | struct GNUNET_PeerIdentity *new_trail; |
2870 | int i; | 2894 | unsigned int i; |
2871 | 2895 | ||
2872 | /* If I am my own finger identity, then we set trail_length = 0. | 2896 | /* If I am my own finger identity, then we set trail_length = 0. |
2873 | Note: Here we don't send trail compression message, as no peer in its | 2897 | Note: Here we don't send trail compression message, as no peer in its |
@@ -2907,8 +2931,10 @@ scan_and_compress_trail (struct GNUNET_PeerIdentity finger_identity, | |||
2907 | struct FriendInfo *target_friend; | 2931 | struct FriendInfo *target_friend; |
2908 | int j = 0; | 2932 | int j = 0; |
2909 | 2933 | ||
2910 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 2934 | GNUNET_assert (NULL != |
2911 | &trail[0]); | 2935 | (target_friend = |
2936 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | ||
2937 | &trail[0]))); | ||
2912 | GDS_NEIGHBOURS_send_trail_compression (my_identity, | 2938 | GDS_NEIGHBOURS_send_trail_compression (my_identity, |
2913 | trail_id, trail[i], | 2939 | trail_id, trail[i], |
2914 | target_friend); | 2940 | target_friend); |
@@ -2928,8 +2954,7 @@ scan_and_compress_trail (struct GNUNET_PeerIdentity finger_identity, | |||
2928 | } | 2954 | } |
2929 | } | 2955 | } |
2930 | 2956 | ||
2931 | /* If we found no other friend except the first hop, return the original | 2957 | /* If we did not compress the trail, return the original trail back.*/ |
2932 | trail back.*/ | ||
2933 | new_trail = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * trail_length); | 2958 | new_trail = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * trail_length); |
2934 | *new_trail_length = trail_length; | 2959 | *new_trail_length = trail_length; |
2935 | memcpy (new_trail, trail, trail_length * sizeof (struct GNUNET_PeerIdentity)); | 2960 | memcpy (new_trail, trail, trail_length * sizeof (struct GNUNET_PeerIdentity)); |
@@ -3028,8 +3053,6 @@ send_verify_successor_message (struct FingerInfo *successor) | |||
3028 | 3053 | ||
3029 | 3054 | ||
3030 | /** | 3055 | /** |
3031 | * FIXME" clear abstraction of current search finger index and finger map index. | ||
3032 | * it never goes to 63. I don't know why | ||
3033 | * Update the current search finger index. | 3056 | * Update the current search finger index. |
3034 | */ | 3057 | */ |
3035 | static void | 3058 | static void |
@@ -3071,7 +3094,8 @@ update_current_search_finger_index (struct GNUNET_PeerIdentity finger_identity, | |||
3071 | * identity and finger_table_index. | 3094 | * identity and finger_table_index. |
3072 | * @param is_predecessor Is the entry for predecessor or not? | 3095 | * @param is_predecessor Is the entry for predecessor or not? |
3073 | * @return finger_table_index Value between 0 <= finger_table_index <= 64 | 3096 | * @return finger_table_index Value between 0 <= finger_table_index <= 64 |
3074 | * -1, if no valid finger_table_index is found. | 3097 | * finger_table_index > PREDECESSOR_FINGER_ID , |
3098 | * if no valid finger_table_index is found. | ||
3075 | */ | 3099 | */ |
3076 | static unsigned int | 3100 | static unsigned int |
3077 | get_finger_table_index (uint64_t ultimate_destination_finger_value, | 3101 | get_finger_table_index (uint64_t ultimate_destination_finger_value, |
@@ -3131,9 +3155,20 @@ remove_existing_finger (struct FingerInfo *existing_finger, unsigned int finger_ | |||
3131 | &finger->finger_identity); | 3155 | &finger->finger_identity); |
3132 | if (NULL != friend) | 3156 | if (NULL != friend) |
3133 | { | 3157 | { |
3134 | friend->trails_count--; | 3158 | struct GNUNET_HashCode trail_id; |
3135 | finger->is_present = GNUNET_NO; | 3159 | struct GNUNET_PeerIdentity *next_hop; |
3136 | memset ((void *)&finger_table[finger_table_index], 0, sizeof (finger_table[finger_table_index])); | 3160 | |
3161 | trail_id = finger->trail_list[0].trail_id; | ||
3162 | GNUNET_assert (0 == finger->trail_list[0].trail_length); | ||
3163 | GNUNET_assert (NULL != | ||
3164 | (next_hop = | ||
3165 | GDS_ROUTING_get_next_hop (trail_id, GDS_ROUTING_SRC_TO_DEST))); | ||
3166 | GNUNET_assert (0 == GNUNET_CRYPTO_cmp_peer_identity (next_hop, | ||
3167 | &finger->finger_identity)); | ||
3168 | GDS_ROUTING_remove_trail (trail_id); | ||
3169 | GDS_NEIGHBOURS_send_trail_teardown (trail_id, | ||
3170 | GDS_ROUTING_SRC_TO_DEST, | ||
3171 | &finger->finger_identity); | ||
3137 | return; | 3172 | return; |
3138 | } | 3173 | } |
3139 | 3174 | ||
@@ -3251,7 +3286,6 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity, | |||
3251 | struct FingerInfo *successor; | 3286 | struct FingerInfo *successor; |
3252 | int updated_finger_trail_length; | 3287 | int updated_finger_trail_length; |
3253 | unsigned int finger_table_index; | 3288 | unsigned int finger_table_index; |
3254 | |||
3255 | 3289 | ||
3256 | #if 0 | 3290 | #if 0 |
3257 | test_friend_peermap_print(); | 3291 | test_friend_peermap_print(); |
@@ -5015,6 +5049,7 @@ handle_dht_p2p_trail_teardown (void *cls, const struct GNUNET_PeerIdentity *peer | |||
5015 | /* Check if peer is the real peer from which we should get this message.*/ | 5049 | /* Check if peer is the real peer from which we should get this message.*/ |
5016 | /* Get the prev_hop for this trail by getting the next hop in opposite direction. */ | 5050 | /* Get the prev_hop for this trail by getting the next hop in opposite direction. */ |
5017 | /* FIXME: is using negation of trail direction correct. */ | 5051 | /* FIXME: is using negation of trail direction correct. */ |
5052 | #if 0 | ||
5018 | GNUNET_assert (NULL != (prev_hop = | 5053 | GNUNET_assert (NULL != (prev_hop = |
5019 | GDS_ROUTING_get_next_hop (trail_id, !trail_direction))); | 5054 | GDS_ROUTING_get_next_hop (trail_id, !trail_direction))); |
5020 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (prev_hop, peer)) | 5055 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (prev_hop, peer)) |
@@ -5022,6 +5057,7 @@ handle_dht_p2p_trail_teardown (void *cls, const struct GNUNET_PeerIdentity *peer | |||
5022 | GNUNET_break (0); | 5057 | GNUNET_break (0); |
5023 | return GNUNET_SYSERR; | 5058 | return GNUNET_SYSERR; |
5024 | } | 5059 | } |
5060 | #endif | ||
5025 | 5061 | ||
5026 | next_hop = GDS_ROUTING_get_next_hop (trail_id, trail_direction); | 5062 | next_hop = GDS_ROUTING_get_next_hop (trail_id, trail_direction); |
5027 | if (NULL == next_hop) | 5063 | if (NULL == next_hop) |
@@ -5160,10 +5196,12 @@ remove_matching_trails (const struct GNUNET_PeerIdentity *disconnected_friend, | |||
5160 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&trail->trail_head->peer, | 5196 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&trail->trail_head->peer, |
5161 | disconnected_friend)) | 5197 | disconnected_friend)) |
5162 | { | 5198 | { |
5199 | FPRINTF (stderr,_("\nSUPU %s, %s, %d"),__FILE__, __func__,__LINE__); | ||
5163 | matching_trails_count++; | 5200 | matching_trails_count++; |
5164 | send_trail_teardown (remove_finger, trail); | 5201 | GDS_ROUTING_remove_trail (trail->trail_id); |
5165 | if (trail->trail_length > 0) | 5202 | GNUNET_assert (trail->trail_length > 0); |
5166 | free_trail (trail); | 5203 | free_trail (trail); |
5204 | trail->is_present = GNUNET_NO; | ||
5167 | } | 5205 | } |
5168 | } | 5206 | } |
5169 | return matching_trails_count; | 5207 | return matching_trails_count; |
@@ -5171,6 +5209,8 @@ remove_matching_trails (const struct GNUNET_PeerIdentity *disconnected_friend, | |||
5171 | 5209 | ||
5172 | 5210 | ||
5173 | /** | 5211 | /** |
5212 | * FIXME; make sure you handle friend correctle. remove entry from you | ||
5213 | * routing table if you are the source. | ||
5174 | * Iterate over finger_table entries. | 5214 | * Iterate over finger_table entries. |
5175 | * 0. Ignore finger which is my_identity or if no valid entry present at | 5215 | * 0. Ignore finger which is my_identity or if no valid entry present at |
5176 | * that finger index. | 5216 | * that finger index. |
@@ -5188,10 +5228,10 @@ remove_matching_fingers (const struct GNUNET_PeerIdentity *disconnected_friend) | |||
5188 | struct FingerInfo *remove_finger; | 5228 | struct FingerInfo *remove_finger; |
5189 | int removed_trails_count; | 5229 | int removed_trails_count; |
5190 | int i; | 5230 | int i; |
5191 | 5231 | ||
5192 | /* Iterate over finger table entries. */ | 5232 | /* Iterate over finger table entries. */ |
5193 | for (i = 0; i < MAX_FINGERS; i++) | 5233 | for (i = 0; i < MAX_FINGERS; i++) |
5194 | { | 5234 | { |
5195 | remove_finger = &finger_table[i]; | 5235 | remove_finger = &finger_table[i]; |
5196 | 5236 | ||
5197 | /* No finger stored at this trail index. */ | 5237 | /* No finger stored at this trail index. */ |
@@ -5203,17 +5243,37 @@ remove_matching_fingers (const struct GNUNET_PeerIdentity *disconnected_friend) | |||
5203 | &my_identity)) | 5243 | &my_identity)) |
5204 | continue; | 5244 | continue; |
5205 | 5245 | ||
5206 | /* Is disconnected friend a finger? */ | 5246 | /* Is disconnected_friend a finger? */ |
5207 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (disconnected_friend, | 5247 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (disconnected_friend, |
5208 | &remove_finger->finger_identity)) | 5248 | &remove_finger->finger_identity)) |
5209 | { | 5249 | { |
5210 | /* No trail to reach this finger as it is a friend, don't send | 5250 | struct GNUNET_PeerIdentity *next_hop; |
5211 | * trail_teardown message. */ | 5251 | struct GNUNET_HashCode trail_id; |
5252 | |||
5253 | GNUNET_assert (GNUNET_YES == (remove_finger->trail_list[0].is_present)); | ||
5254 | trail_id = remove_finger->trail_list[0].trail_id; | ||
5255 | |||
5212 | remove_finger->is_present = GNUNET_NO; | 5256 | remove_finger->is_present = GNUNET_NO; |
5257 | |||
5258 | GNUNET_assert (NULL != | ||
5259 | (next_hop = | ||
5260 | GDS_ROUTING_get_next_hop (trail_id, GDS_ROUTING_SRC_TO_DEST))); | ||
5261 | GNUNET_assert (0 == | ||
5262 | (GNUNET_CRYPTO_cmp_peer_identity (next_hop, | ||
5263 | &remove_finger->finger_identity))); | ||
5264 | /* Here we can not send a trail teardown as the friend is already | ||
5265 | * disconnected, So in all cases where next_hop friend from routing table | ||
5266 | * is NULL, we need to remove the trail if it is present. */ | ||
5267 | GDS_ROUTING_remove_trail (trail_id); | ||
5213 | memset ((void *)&finger_table[i], 0, sizeof (finger_table[i])); | 5268 | memset ((void *)&finger_table[i], 0, sizeof (finger_table[i])); |
5214 | continue; | 5269 | continue; |
5215 | } | 5270 | } |
5216 | 5271 | ||
5272 | /* If finger is a friend but not disconnected_friend, then continue */ | ||
5273 | if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, | ||
5274 | &remove_finger->finger_identity)) | ||
5275 | continue; | ||
5276 | |||
5217 | /* Iterate over the list of trails to reach remove_finger. Check if | 5277 | /* Iterate over the list of trails to reach remove_finger. Check if |
5218 | * disconnected_friend is the first friend in any of the trail. */ | 5278 | * disconnected_friend is the first friend in any of the trail. */ |
5219 | removed_trails_count = remove_matching_trails (disconnected_friend, | 5279 | removed_trails_count = remove_matching_trails (disconnected_friend, |
@@ -5257,6 +5317,7 @@ handle_core_disconnect (void *cls, | |||
5257 | * disconnected peer is not part of. */ | 5317 | * disconnected peer is not part of. */ |
5258 | GDS_ROUTING_remove_trail_by_peer (peer); | 5318 | GDS_ROUTING_remove_trail_by_peer (peer); |
5259 | 5319 | ||
5320 | GNUNET_assert (0 == remove_friend->trails_count); | ||
5260 | /* Remove peer from friend_peermap. */ | 5321 | /* Remove peer from friend_peermap. */ |
5261 | GNUNET_assert (GNUNET_YES == | 5322 | GNUNET_assert (GNUNET_YES == |
5262 | GNUNET_CONTAINER_multipeermap_remove (friend_peermap, | 5323 | GNUNET_CONTAINER_multipeermap_remove (friend_peermap, |
@@ -5339,7 +5400,6 @@ core_init (void *cls, | |||
5339 | FPRINTF (stderr,_("\nSUPU %s, %s, %d, my_identity = %s"), | 5400 | FPRINTF (stderr,_("\nSUPU %s, %s, %d, my_identity = %s"), |
5340 | __FILE__, __func__,__LINE__, GNUNET_i2s (&my_identity)); | 5401 | __FILE__, __func__,__LINE__, GNUNET_i2s (&my_identity)); |
5341 | #endif | 5402 | #endif |
5342 | |||
5343 | } | 5403 | } |
5344 | 5404 | ||
5345 | 5405 | ||