diff options
author | Supriti Singh <supritisingh08@gmail.com> | 2014-06-23 10:20:23 +0000 |
---|---|---|
committer | Supriti Singh <supritisingh08@gmail.com> | 2014-06-23 10:20:23 +0000 |
commit | e605b0a9eb0e5229d2c936df4cdf8b2f513abb72 (patch) | |
tree | 65c8f799e1627e576dd4ee283184eed19224a4ae /src | |
parent | 0fd91c35a329c624bc8ee03c6fd738ef5c467dfc (diff) | |
download | gnunet-e605b0a9eb0e5229d2c936df4cdf8b2f513abb72.tar.gz gnunet-e605b0a9eb0e5229d2c936df4cdf8b2f513abb72.zip |
xvine:bug fix
Diffstat (limited to 'src')
-rw-r--r-- | src/dht/gnunet-service-xdht_datacache.c | 5 | ||||
-rw-r--r-- | src/dht/gnunet-service-xdht_neighbours.c | 78 |
2 files changed, 57 insertions, 26 deletions
diff --git a/src/dht/gnunet-service-xdht_datacache.c b/src/dht/gnunet-service-xdht_datacache.c index da8377500..fe27eec5e 100644 --- a/src/dht/gnunet-service-xdht_datacache.c +++ b/src/dht/gnunet-service-xdht_datacache.c | |||
@@ -228,6 +228,7 @@ datacache_get_iterator (void *cls, | |||
228 | GDS_NEIGHBOURS_send_get_result (key,type, &(ctx->next_hop),&(ctx->source_peer), | 228 | GDS_NEIGHBOURS_send_get_result (key,type, &(ctx->next_hop),&(ctx->source_peer), |
229 | put_path_length, put_path, ctx->get_path_length, | 229 | put_path_length, put_path, ctx->get_path_length, |
230 | get_path, exp, data, size ); | 230 | get_path, exp, data, size ); |
231 | GNUNET_free_non_null (get_path); | ||
231 | 232 | ||
232 | break; | 233 | break; |
233 | case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: | 234 | case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: |
@@ -308,8 +309,10 @@ GDS_DATACACHE_handle_get (const struct GNUNET_HashCode * key, | |||
308 | ctx.get_path_length = get_path_length; | 309 | ctx.get_path_length = get_path_length; |
309 | 310 | ||
310 | if (next_hop != NULL) | 311 | if (next_hop != NULL) |
312 | { | ||
311 | memcpy (&(ctx.next_hop), next_hop, sizeof (struct GNUNET_PeerIdentity)); | 313 | memcpy (&(ctx.next_hop), next_hop, sizeof (struct GNUNET_PeerIdentity)); |
312 | 314 | GNUNET_free (next_hop); | |
315 | } | ||
313 | unsigned int i = 0; | 316 | unsigned int i = 0; |
314 | ctx.head = NULL; | 317 | ctx.head = NULL; |
315 | ctx.tail = NULL; | 318 | ctx.tail = NULL; |
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c index d0a6d0955..f4ecbab38 100644 --- a/src/dht/gnunet-service-xdht_neighbours.c +++ b/src/dht/gnunet-service-xdht_neighbours.c | |||
@@ -55,6 +55,25 @@ | |||
55 | * Trail id we can keep but actually there is no trail. | 55 | * Trail id we can keep but actually there is no trail. |
56 | */ | 56 | */ |
57 | 57 | ||
58 | |||
59 | /** | ||
60 | * FIXME: | ||
61 | * 1. check for memory leaks in all the functions, in all the functions | ||
62 | * you should check that if you malloc a variable you should free it also. | ||
63 | * 2. make sure you have gnunet_assert for all target friends | ||
64 | * 3. pay attention to GNUNET_ntohll and endianess | ||
65 | * 4. In trail setup, check that you are adding entry even if its a friend. | ||
66 | * same for trail setup and add_trail. | ||
67 | * 5. go through whole code | ||
68 | * 6. make sure make check passes for minimal things i.e. without congestion, | ||
69 | * trail threshold, without multiple trails. | ||
70 | * 7. write test cases for checking trail congestion, trail threshold, multiple | ||
71 | * trails. | ||
72 | * | ||
73 | * 8. while going through the code write the comments for malicious peer. | ||
74 | * basic - drop packet, ignore message. Not going to check for behaviour | ||
75 | * where a peer changes the value as we handle that case everywhere. s | ||
76 | */ | ||
58 | /** | 77 | /** |
59 | * Maximum possible fingers (including predecessor) of a peer | 78 | * Maximum possible fingers (including predecessor) of a peer |
60 | */ | 79 | */ |
@@ -1650,7 +1669,7 @@ select_finger_trail (struct FingerInfo *finger) | |||
1650 | 1669 | ||
1651 | /* No trail found. */ | 1670 | /* No trail found. */ |
1652 | if (i == finger->trails_count) | 1671 | if (i == finger->trails_count) |
1653 | finger_trail = NULL; | 1672 | return NULL; |
1654 | 1673 | ||
1655 | return finger_trail; | 1674 | return finger_trail; |
1656 | } | 1675 | } |
@@ -1847,6 +1866,7 @@ compare_finger_and_current_successor (struct Closest_Peer *current_closest_peer) | |||
1847 | for (i = 0; i < MAX_FINGERS; i++) | 1866 | for (i = 0; i < MAX_FINGERS; i++) |
1848 | { | 1867 | { |
1849 | struct Selected_Finger_Trail *finger_trail; | 1868 | struct Selected_Finger_Trail *finger_trail; |
1869 | |||
1850 | finger = &finger_table[i]; | 1870 | finger = &finger_table[i]; |
1851 | 1871 | ||
1852 | if (GNUNET_NO == finger->is_present) | 1872 | if (GNUNET_NO == finger->is_present) |
@@ -1896,8 +1916,8 @@ compare_finger_and_current_successor (struct Closest_Peer *current_closest_peer) | |||
1896 | 1916 | ||
1897 | closest_peer = select_closest_peer (&finger->finger_identity, | 1917 | closest_peer = select_closest_peer (&finger->finger_identity, |
1898 | ¤t_closest_peer->best_known_destination, | 1918 | ¤t_closest_peer->best_known_destination, |
1899 | current_closest_peer->destination_finger_value, | 1919 | current_closest_peer->destination_finger_value, |
1900 | current_closest_peer->is_predecessor); | 1920 | current_closest_peer->is_predecessor); |
1901 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity, | 1921 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity, |
1902 | closest_peer)) | 1922 | closest_peer)) |
1903 | { | 1923 | { |
@@ -1905,7 +1925,8 @@ compare_finger_and_current_successor (struct Closest_Peer *current_closest_peer) | |||
1905 | current_closest_peer->next_hop = finger_trail->friend.id; | 1925 | current_closest_peer->next_hop = finger_trail->friend.id; |
1906 | current_closest_peer->trail_id = finger_trail->trail_id; | 1926 | current_closest_peer->trail_id = finger_trail->trail_id; |
1907 | } | 1927 | } |
1908 | continue; | 1928 | GNUNET_free (finger_trail); |
1929 | continue; | ||
1909 | } | 1930 | } |
1910 | return current_closest_peer; | 1931 | return current_closest_peer; |
1911 | } | 1932 | } |
@@ -2101,7 +2122,8 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key, | |||
2101 | return; | 2122 | return; |
2102 | } | 2123 | } |
2103 | else | 2124 | else |
2104 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | 2125 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); |
2126 | GNUNET_free (next_hop); | ||
2105 | } | 2127 | } |
2106 | else | 2128 | else |
2107 | { | 2129 | { |
@@ -2210,12 +2232,14 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key, | |||
2210 | { | 2232 | { |
2211 | GDS_DATACACHE_handle_get (key,block_type, NULL, 0, | 2233 | GDS_DATACACHE_handle_get (key,block_type, NULL, 0, |
2212 | NULL, 0, 1, &my_identity, NULL,&my_identity); | 2234 | NULL, 0, 1, &my_identity, NULL,&my_identity); |
2235 | |||
2213 | return; | 2236 | return; |
2214 | } | 2237 | } |
2215 | else | 2238 | else |
2216 | { | 2239 | { |
2217 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | 2240 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); |
2218 | } | 2241 | } |
2242 | GNUNET_free (next_hop); | ||
2219 | } | 2243 | } |
2220 | else | 2244 | else |
2221 | { | 2245 | { |
@@ -2292,10 +2316,11 @@ GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *key, | |||
2292 | return; | 2316 | return; |
2293 | } | 2317 | } |
2294 | 2318 | ||
2319 | current_path_index = -1; | ||
2295 | if(get_path_length > 0) | 2320 | if(get_path_length > 0) |
2296 | { | 2321 | { |
2297 | current_path_index = search_my_index(get_path, get_path_length); | 2322 | current_path_index = search_my_index(get_path, get_path_length); |
2298 | if (GNUNET_SYSERR == current_path_index) | 2323 | if (-1 == current_path_index) |
2299 | { | 2324 | { |
2300 | GNUNET_break (0); | 2325 | GNUNET_break (0); |
2301 | return; | 2326 | return; |
@@ -2823,6 +2848,7 @@ add_new_finger (struct GNUNET_PeerIdentity finger_identity, | |||
2823 | new_entry->trail_list[0].is_present = GNUNET_YES; | 2848 | new_entry->trail_list[0].is_present = GNUNET_YES; |
2824 | finger_table[finger_table_index] = *new_entry; | 2849 | finger_table[finger_table_index] = *new_entry; |
2825 | GNUNET_free (new_entry); | 2850 | GNUNET_free (new_entry); |
2851 | GNUNET_free (trail); | ||
2826 | return; | 2852 | return; |
2827 | } | 2853 | } |
2828 | 2854 | ||
@@ -3248,11 +3274,6 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity, | |||
3248 | return; | 3274 | return; |
3249 | } | 3275 | } |
3250 | 3276 | ||
3251 | updated_finger_trail_length = finger_trail_length; | ||
3252 | updated_trail = | ||
3253 | scan_and_compress_trail (finger_identity, finger_trail, | ||
3254 | finger_trail_length, finger_trail_id, | ||
3255 | &updated_finger_trail_length); | ||
3256 | 3277 | ||
3257 | /* If the new entry is same as successor then don't add it in finger table, | 3278 | /* If the new entry is same as successor then don't add it in finger table, |
3258 | reset the current search finger index and exit. */ | 3279 | reset the current search finger index and exit. */ |
@@ -3272,12 +3293,18 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity, | |||
3272 | 3293 | ||
3273 | existing_finger = &finger_table[finger_table_index]; | 3294 | existing_finger = &finger_table[finger_table_index]; |
3274 | 3295 | ||
3296 | updated_finger_trail_length = finger_trail_length; | ||
3297 | updated_trail = | ||
3298 | scan_and_compress_trail (finger_identity, finger_trail, | ||
3299 | finger_trail_length, finger_trail_id, | ||
3300 | &updated_finger_trail_length); | ||
3275 | /* No entry present in finger_table for given finger map index. */ | 3301 | /* No entry present in finger_table for given finger map index. */ |
3276 | if (GNUNET_NO == existing_finger->is_present) | 3302 | if (GNUNET_NO == existing_finger->is_present) |
3277 | { | 3303 | { |
3278 | add_new_finger (finger_identity, updated_trail, updated_finger_trail_length, | 3304 | add_new_finger (finger_identity, updated_trail, updated_finger_trail_length, |
3279 | finger_trail_id, finger_table_index); | 3305 | finger_trail_id, finger_table_index); |
3280 | update_current_search_finger_index (finger_identity, finger_table_index); | 3306 | update_current_search_finger_index (finger_identity, finger_table_index); |
3307 | GNUNET_free (updated_trail); | ||
3281 | return; | 3308 | return; |
3282 | } | 3309 | } |
3283 | 3310 | ||
@@ -3302,8 +3329,10 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity, | |||
3302 | /* If both new and existing entry are same as my_identity, then do nothing. */ | 3329 | /* If both new and existing entry are same as my_identity, then do nothing. */ |
3303 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&(existing_finger->finger_identity), | 3330 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&(existing_finger->finger_identity), |
3304 | &my_identity)) | 3331 | &my_identity)) |
3332 | { | ||
3333 | GNUNET_free (updated_trail); | ||
3305 | return; | 3334 | return; |
3306 | 3335 | } | |
3307 | /* If the existing finger is not a friend. */ | 3336 | /* If the existing finger is not a friend. */ |
3308 | if (NULL == | 3337 | if (NULL == |
3309 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 3338 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
@@ -3319,6 +3348,7 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity, | |||
3319 | } | 3348 | } |
3320 | } | 3349 | } |
3321 | update_current_search_finger_index (finger_identity, finger_table_index); | 3350 | update_current_search_finger_index (finger_identity, finger_table_index); |
3351 | GNUNET_free (updated_trail); | ||
3322 | return; | 3352 | return; |
3323 | } | 3353 | } |
3324 | 3354 | ||
@@ -3579,8 +3609,7 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3579 | /* Get the next hop to pass the get result message. */ | 3609 | /* Get the next hop to pass the get result message. */ |
3580 | memcpy (&next_hop, &final_get_path[get_length-2], sizeof (struct GNUNET_PeerIdentity)); | 3610 | memcpy (&next_hop, &final_get_path[get_length-2], sizeof (struct GNUNET_PeerIdentity)); |
3581 | GDS_DATACACHE_handle_get (&(get->key),(get->block_type), NULL, 0, NULL, 0, | 3611 | GDS_DATACACHE_handle_get (&(get->key),(get->block_type), NULL, 0, NULL, 0, |
3582 | get_length, final_get_path,&next_hop, &my_identity); | 3612 | get_length, final_get_path, &next_hop, &my_identity); |
3583 | |||
3584 | return GNUNET_YES; | 3613 | return GNUNET_YES; |
3585 | } | 3614 | } |
3586 | else | 3615 | else |
@@ -3590,6 +3619,7 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3590 | &intermediate_trail_id, next_hop, 0, | 3619 | &intermediate_trail_id, next_hop, 0, |
3591 | get_length, gp); | 3620 | get_length, gp); |
3592 | } | 3621 | } |
3622 | GNUNET_free_non_null (next_hop); | ||
3593 | return GNUNET_SYSERR; | 3623 | return GNUNET_SYSERR; |
3594 | } | 3624 | } |
3595 | 3625 | ||
@@ -3640,17 +3670,14 @@ handle_dht_p2p_get_result (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3640 | return GNUNET_YES; | 3670 | return GNUNET_YES; |
3641 | } | 3671 | } |
3642 | 3672 | ||
3643 | if (getlen > 0) | 3673 | get_path = (struct GNUNET_PeerIdentity *) &get_result[1]; |
3644 | get_path = (struct GNUNET_PeerIdentity *) &get_result[1]; | ||
3645 | payload = &get_path[getlen]; | 3674 | payload = &get_path[getlen]; |
3646 | payload_size = msize - (sizeof (struct PeerGetResultMessage) + | 3675 | payload_size = msize - (sizeof (struct PeerGetResultMessage) + |
3647 | getlen * sizeof (struct GNUNET_PeerIdentity)); | 3676 | getlen * sizeof (struct GNUNET_PeerIdentity)); |
3648 | 3677 | ||
3649 | if (putlen > 0) | ||
3650 | put_path = &get_path[1]; | ||
3651 | else | ||
3652 | put_path = NULL; | ||
3653 | 3678 | ||
3679 | put_path = &get_path[1]; | ||
3680 | |||
3654 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &(get_path[0])))) | 3681 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &(get_path[0])))) |
3655 | { | 3682 | { |
3656 | GDS_CLIENTS_handle_reply (get_result->expiration_time, &(get_result->key), | 3683 | GDS_CLIENTS_handle_reply (get_result->expiration_time, &(get_result->key), |
@@ -3726,18 +3753,18 @@ get_local_best_known_next_hop (uint64_t final_dest_finger_value, | |||
3726 | /* Is current dest (end point of the trail of which I am a part) closest_peer? */ | 3753 | /* Is current dest (end point of the trail of which I am a part) closest_peer? */ |
3727 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (current_dest, closest_peer)) | 3754 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (current_dest, closest_peer)) |
3728 | { | 3755 | { |
3729 | next_hop_to_local_best_known_dest = | 3756 | struct GNUNET_PeerIdentity *next_hop; |
3730 | GDS_ROUTING_get_next_hop (intermediate_trail_id, | 3757 | next_hop = GDS_ROUTING_get_next_hop (intermediate_trail_id, |
3731 | GDS_ROUTING_SRC_TO_DEST); | 3758 | GDS_ROUTING_SRC_TO_DEST); |
3732 | /* FIXME: Here we found next_hop NULL from routing table, but we still | 3759 | /* FIXME: Here we found next_hop NULL from routing table, but we still |
3733 | * have a next_hop from find_successor should we not break and choose that | 3760 | * have a next_hop from find_successor should we not break and choose that |
3734 | * next_hop. */ | 3761 | * next_hop. */ |
3735 | if (NULL == next_hop_to_local_best_known_dest) | 3762 | if (NULL == next_hop) |
3736 | { | 3763 | { |
3737 | GNUNET_break_op (0); | 3764 | GNUNET_break_op (0); |
3738 | return NULL; | 3765 | return NULL; |
3739 | } | 3766 | } |
3740 | 3767 | next_hop_to_local_best_known_dest = next_hop; | |
3741 | local_best_known_dest = current_dest; | 3768 | local_best_known_dest = current_dest; |
3742 | *new_intermediate_trail_id = intermediate_trail_id; | 3769 | *new_intermediate_trail_id = intermediate_trail_id; |
3743 | } | 3770 | } |
@@ -4195,6 +4222,7 @@ update_predecessor (struct GNUNET_PeerIdentity finger, | |||
4195 | 4222 | ||
4196 | add_new_finger (finger, trail_to_new_predecessor, trail_length, | 4223 | add_new_finger (finger, trail_to_new_predecessor, trail_length, |
4197 | trail_to_new_predecessor_id, PREDECESSOR_FINGER_ID); | 4224 | trail_to_new_predecessor_id, PREDECESSOR_FINGER_ID); |
4225 | GNUNET_free_non_null (trail_to_new_predecessor); | ||
4198 | } | 4226 | } |
4199 | 4227 | ||
4200 | 4228 | ||