diff options
author | Supriti Singh <supritisingh08@gmail.com> | 2014-08-19 11:28:11 +0000 |
---|---|---|
committer | Supriti Singh <supritisingh08@gmail.com> | 2014-08-19 11:28:11 +0000 |
commit | 482d0a0e2045302b4ffacebfa1e48178f6bded55 (patch) | |
tree | e9bea7676ce4731b5fcb65873fcdf5be2e687828 /src | |
parent | af67e292e90dabbe354fdfff3bd4ba994273ce91 (diff) | |
download | gnunet-482d0a0e2045302b4ffacebfa1e48178f6bded55.tar.gz gnunet-482d0a0e2045302b4ffacebfa1e48178f6bded55.zip |
Check for loop in put and get path
Diffstat (limited to 'src')
-rw-r--r-- | src/dht/gnunet-service-xdht_neighbours.c | 253 | ||||
-rw-r--r-- | src/dht/gnunet_dht_profiler.c | 2 |
2 files changed, 146 insertions, 109 deletions
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c index c30855665..663f13692 100644 --- a/src/dht/gnunet-service-xdht_neighbours.c +++ b/src/dht/gnunet-service-xdht_neighbours.c | |||
@@ -1048,7 +1048,6 @@ GDS_NEIGHBOURS_send_trail_setup (struct GNUNET_PeerIdentity source_peer, | |||
1048 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), | 1048 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), |
1049 | 1, GNUNET_NO); | 1049 | 1, GNUNET_NO); |
1050 | } | 1050 | } |
1051 | |||
1052 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | 1051 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); |
1053 | pending->timeout = GNUNET_TIME_relative_to_absolute (PENDING_MESSAGE_TIMEOUT); | 1052 | pending->timeout = GNUNET_TIME_relative_to_absolute (PENDING_MESSAGE_TIMEOUT); |
1054 | tsm = (struct PeerTrailSetupMessage *) &pending[1]; | 1053 | tsm = (struct PeerTrailSetupMessage *) &pending[1]; |
@@ -2101,18 +2100,6 @@ find_successor (uint64_t destination_finger_value, | |||
2101 | /* Compare each finger entry with current_successor and update current_successor | 2100 | /* Compare each finger entry with current_successor and update current_successor |
2102 | * with finger if its closest. */ | 2101 | * with finger if its closest. */ |
2103 | compare_finger_and_current_closest_peer (¤t_closest_peer); | 2102 | compare_finger_and_current_closest_peer (¤t_closest_peer); |
2104 | |||
2105 | if(0 == GNUNET_CRYPTO_cmp_peer_identity (¤t_closest_peer.next_hop, | ||
2106 | ¤t_closest_peer.best_known_destination)) | ||
2107 | { | ||
2108 | FPRINTF (stderr,_("\nSUPU MUST BE 0 trailid = %s,%s, %s, %d,"), | ||
2109 | GNUNET_h2s(¤t_closest_peer.trail_id),__FILE__, __func__,__LINE__); | ||
2110 | } | ||
2111 | else | ||
2112 | { | ||
2113 | FPRINTF (stderr,_("\nSUPU MUST NOT BE 0 trailid = %s,%s, %s, %d,"), | ||
2114 | GNUNET_h2s(¤t_closest_peer.trail_id),__FILE__, __func__,__LINE__); | ||
2115 | } | ||
2116 | return current_closest_peer; | 2103 | return current_closest_peer; |
2117 | } | 2104 | } |
2118 | 2105 | ||
@@ -2154,6 +2141,8 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key, | |||
2154 | struct P2PPendingMessage *pending; | 2141 | struct P2PPendingMessage *pending; |
2155 | struct FriendInfo *target_friend; | 2142 | struct FriendInfo *target_friend; |
2156 | struct GNUNET_PeerIdentity *pp; | 2143 | struct GNUNET_PeerIdentity *pp; |
2144 | struct GNUNET_PeerIdentity new_put_path[1]; | ||
2145 | unsigned int new_put_path_length = 0; | ||
2157 | struct GNUNET_PeerIdentity next_hop; | 2146 | struct GNUNET_PeerIdentity next_hop; |
2158 | 2147 | ||
2159 | size_t msize; | 2148 | size_t msize; |
@@ -2186,7 +2175,6 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key, | |||
2186 | GNUNET_break (0); | 2175 | GNUNET_break (0); |
2187 | return; | 2176 | return; |
2188 | } | 2177 | } |
2189 | |||
2190 | /* This is the first call made from clients file. So, we should search for the | 2178 | /* This is the first call made from clients file. So, we should search for the |
2191 | target_friend. */ | 2179 | target_friend. */ |
2192 | if (NULL == target_peer) | 2180 | if (NULL == target_peer) |
@@ -2211,17 +2199,27 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key, | |||
2211 | return; | 2199 | return; |
2212 | } | 2200 | } |
2213 | else | 2201 | else |
2202 | { | ||
2203 | /* Add yourself to the put path. */ | ||
2204 | new_put_path_length = 1; | ||
2205 | new_put_path[0] = my_identity; | ||
2214 | GNUNET_assert (NULL != | 2206 | GNUNET_assert (NULL != |
2215 | (target_friend = | 2207 | (target_friend = |
2216 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop))); | 2208 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop))); |
2209 | } | ||
2217 | } | 2210 | } |
2218 | else | 2211 | else |
2219 | { | 2212 | { |
2220 | GNUNET_assert (NULL != | 2213 | GNUNET_assert (NULL != |
2221 | (target_friend = | 2214 | (target_friend = |
2222 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer))); | 2215 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer))); |
2223 | } | 2216 | } |
2217 | if (1 == new_put_path_length) | ||
2218 | { | ||
2219 | msize = new_put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size + | ||
2220 | sizeof (struct PeerPutMessage); | ||
2224 | 2221 | ||
2222 | } | ||
2225 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | 2223 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); |
2226 | pending->timeout = expiration_time; | 2224 | pending->timeout = expiration_time; |
2227 | ppm = (struct PeerPutMessage *) &pending[1]; | 2225 | ppm = (struct PeerPutMessage *) &pending[1]; |
@@ -2232,18 +2230,29 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key, | |||
2232 | ppm->block_type = htonl (block_type); | 2230 | ppm->block_type = htonl (block_type); |
2233 | ppm->hop_count = htonl (hop_count + 1); | 2231 | ppm->hop_count = htonl (hop_count + 1); |
2234 | ppm->desired_replication_level = htonl (desired_replication_level); | 2232 | ppm->desired_replication_level = htonl (desired_replication_level); |
2235 | ppm->put_path_length = htonl (put_path_length); | ||
2236 | ppm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time); | 2233 | ppm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time); |
2237 | ppm->best_known_destination = best_known_dest; | 2234 | ppm->best_known_destination = best_known_dest; |
2238 | ppm->key = *key; | 2235 | ppm->key = *key; |
2239 | 2236 | ||
2240 | pp = (struct GNUNET_PeerIdentity *) &ppm[1]; | 2237 | pp = (struct GNUNET_PeerIdentity *) &ppm[1]; |
2241 | if (put_path_length != 0) | 2238 | if (0 == new_put_path_length) |
2239 | { | ||
2240 | ppm->put_path_length = htonl (put_path_length); | ||
2241 | if(put_path_length > 0) | ||
2242 | { | ||
2243 | memcpy (pp, put_path, | ||
2244 | sizeof (struct GNUNET_PeerIdentity) * put_path_length); | ||
2245 | } | ||
2246 | memcpy (&pp[put_path_length], data, data_size); | ||
2247 | } | ||
2248 | else if (1 == new_put_path_length) | ||
2242 | { | 2249 | { |
2243 | memcpy (pp, put_path, | 2250 | ppm->put_path_length = htonl (new_put_path_length); |
2244 | sizeof (struct GNUNET_PeerIdentity) * put_path_length); | 2251 | memcpy (pp, new_put_path, |
2252 | sizeof (struct GNUNET_PeerIdentity) * new_put_path_length); | ||
2253 | memcpy (&pp[new_put_path_length], data, data_size); | ||
2245 | } | 2254 | } |
2246 | memcpy (&pp[put_path_length], data, data_size); | 2255 | GNUNET_assert (NULL != target_friend); |
2247 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); | 2256 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); |
2248 | target_friend->pending_count++; | 2257 | target_friend->pending_count++; |
2249 | process_friend_queue (target_friend); | 2258 | process_friend_queue (target_friend); |
@@ -2285,6 +2294,8 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key, | |||
2285 | struct P2PPendingMessage *pending; | 2294 | struct P2PPendingMessage *pending; |
2286 | struct FriendInfo *target_friend; | 2295 | struct FriendInfo *target_friend; |
2287 | struct GNUNET_PeerIdentity *gp; | 2296 | struct GNUNET_PeerIdentity *gp; |
2297 | struct GNUNET_PeerIdentity new_get_path[1]; | ||
2298 | unsigned int new_get_path_length = 0; | ||
2288 | size_t msize; | 2299 | size_t msize; |
2289 | 2300 | ||
2290 | msize = sizeof (struct PeerGetMessage) + | 2301 | msize = sizeof (struct PeerGetMessage) + |
@@ -2296,9 +2307,6 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key, | |||
2296 | return; | 2307 | return; |
2297 | } | 2308 | } |
2298 | #endif | 2309 | #endif |
2299 | //GNUNET_SERVER_MAX_MESSAGE_SIZE | ||
2300 | /* FIXME:TODO:URGENTHere you can try to optimize it a bit. In case the get path contains you | ||
2301 | or your friend then shorten the path. */ | ||
2302 | /* In this case we don't make get_path_length = 0, as we need get path to | 2310 | /* In this case we don't make get_path_length = 0, as we need get path to |
2303 | * return the message back to querying client. */ | 2311 | * return the message back to querying client. */ |
2304 | if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) | 2312 | if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) |
@@ -2334,6 +2342,9 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key, | |||
2334 | } | 2342 | } |
2335 | else | 2343 | else |
2336 | { | 2344 | { |
2345 | /* Add yourself to the put path. */ | ||
2346 | new_get_path_length = 1; | ||
2347 | new_get_path[0] = my_identity; | ||
2337 | GNUNET_assert (NULL != | 2348 | GNUNET_assert (NULL != |
2338 | (target_friend = | 2349 | (target_friend = |
2339 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 2350 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
@@ -2348,6 +2359,12 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key, | |||
2348 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer))); | 2359 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer))); |
2349 | } | 2360 | } |
2350 | 2361 | ||
2362 | if(1 == new_get_path_length) | ||
2363 | { | ||
2364 | msize = sizeof (struct PeerGetMessage) + | ||
2365 | (new_get_path_length * sizeof (struct GNUNET_PeerIdentity)); | ||
2366 | |||
2367 | } | ||
2351 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | 2368 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); |
2352 | pending->timeout = GNUNET_TIME_relative_to_absolute (PENDING_MESSAGE_TIMEOUT); | 2369 | pending->timeout = GNUNET_TIME_relative_to_absolute (PENDING_MESSAGE_TIMEOUT); |
2353 | pending->importance = 0; /* FIXME */ | 2370 | pending->importance = 0; /* FIXME */ |
@@ -2361,12 +2378,18 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key, | |||
2361 | pgm->intermediate_trail_id = intermediate_trail_id; | 2378 | pgm->intermediate_trail_id = intermediate_trail_id; |
2362 | pgm->hop_count = htonl (hop_count + 1); | 2379 | pgm->hop_count = htonl (hop_count + 1); |
2363 | gp = (struct GNUNET_PeerIdentity *) &pgm[1]; | 2380 | gp = (struct GNUNET_PeerIdentity *) &pgm[1]; |
2364 | 2381 | if (1 == new_get_path_length) | |
2365 | if (get_path_length != 0) | ||
2366 | { | 2382 | { |
2367 | memcpy (gp, get_path, get_path_length * sizeof (struct GNUNET_PeerIdentity)); | 2383 | pgm->get_path_length = htonl (new_get_path_length); |
2384 | memcpy (gp, new_get_path, | ||
2385 | sizeof (struct GNUNET_PeerIdentity) * new_get_path_length); | ||
2386 | } | ||
2387 | else if(0 == new_get_path_length) | ||
2388 | { | ||
2389 | pgm->get_path_length = htonl (get_path_length); | ||
2390 | memcpy (gp, get_path, | ||
2391 | sizeof (struct GNUNET_PeerIdentity) * get_path_length); | ||
2368 | } | 2392 | } |
2369 | |||
2370 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); | 2393 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); |
2371 | target_friend->pending_count++; | 2394 | target_friend->pending_count++; |
2372 | process_friend_queue (target_friend); | 2395 | process_friend_queue (target_friend); |
@@ -2620,7 +2643,6 @@ send_find_finger_trail_message (void *cls, | |||
2620 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG, | 2643 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG, |
2621 | &trail_id, sizeof (trail_id)); | 2644 | &trail_id, sizeof (trail_id)); |
2622 | memset(&intermediate_trail_id, 0, sizeof (struct GNUNET_HashCode)); | 2645 | memset(&intermediate_trail_id, 0, sizeof (struct GNUNET_HashCode)); |
2623 | |||
2624 | GDS_NEIGHBOURS_send_trail_setup (my_identity, finger_id_value, | 2646 | GDS_NEIGHBOURS_send_trail_setup (my_identity, finger_id_value, |
2625 | target_friend->id, target_friend, 0, NULL, | 2647 | target_friend->id, target_friend, 0, NULL, |
2626 | is_predecessor, trail_id, | 2648 | is_predecessor, trail_id, |
@@ -2876,18 +2898,28 @@ send_trail_teardown (struct FingerInfo *finger, | |||
2876 | /* Finger is not a friend. */ | 2898 | /* Finger is not a friend. */ |
2877 | if (trail->trail_length > 0) | 2899 | if (trail->trail_length > 0) |
2878 | { | 2900 | { |
2879 | GNUNET_assert (NULL != (friend = | 2901 | friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
2880 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 2902 | &trail->trail_head->peer); |
2881 | &trail->trail_head->peer))); | ||
2882 | } | 2903 | } |
2883 | else | 2904 | else |
2884 | { | 2905 | { |
2885 | GNUNET_assert (NULL != (friend = | 2906 | friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
2886 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 2907 | &finger->finger_identity); |
2887 | &finger->finger_identity))); | ||
2888 | } | 2908 | } |
2889 | 2909 | ||
2890 | GNUNET_assert (0 == GNUNET_CRYPTO_cmp_peer_identity (next_hop, &friend->id)); | 2910 | if(NULL == friend) |
2911 | { | ||
2912 | DEBUG ("\n LINE NO: = %d, Friend not found for trail id %s of peer %s trail length = %d", | ||
2913 | __LINE__,GNUNET_h2s(&trail->trail_id), GNUNET_i2s(&my_identity),trail->trail_length); | ||
2914 | return; | ||
2915 | } | ||
2916 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (next_hop, &friend->id) | ||
2917 | && (0 == trail->trail_length)) | ||
2918 | { | ||
2919 | DEBUG ("\n LINE NO: = %d, Friend not found for trail id %s of peer %s trail length = %d", | ||
2920 | __LINE__,GNUNET_h2s(&trail->trail_id), GNUNET_i2s(&my_identity),trail->trail_length); | ||
2921 | return; | ||
2922 | } | ||
2891 | GNUNET_assert (GNUNET_YES == GDS_ROUTING_remove_trail (trail->trail_id)); | 2923 | GNUNET_assert (GNUNET_YES == GDS_ROUTING_remove_trail (trail->trail_id)); |
2892 | friend->trails_count--; | 2924 | friend->trails_count--; |
2893 | GDS_NEIGHBOURS_send_trail_teardown (trail->trail_id, | 2925 | GDS_NEIGHBOURS_send_trail_teardown (trail->trail_id, |
@@ -2985,7 +3017,7 @@ add_new_finger (struct GNUNET_PeerIdentity finger_identity, | |||
2985 | struct FriendInfo *first_trail_hop; | 3017 | struct FriendInfo *first_trail_hop; |
2986 | struct Trail *trail; | 3018 | struct Trail *trail; |
2987 | int i; | 3019 | int i; |
2988 | 3020 | ||
2989 | new_entry = GNUNET_new (struct FingerInfo); | 3021 | new_entry = GNUNET_new (struct FingerInfo); |
2990 | new_entry->finger_identity = finger_identity; | 3022 | new_entry->finger_identity = finger_identity; |
2991 | new_entry->finger_table_index = finger_table_index; | 3023 | new_entry->finger_table_index = finger_table_index; |
@@ -3006,6 +3038,7 @@ add_new_finger (struct GNUNET_PeerIdentity finger_identity, | |||
3006 | if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 3038 | if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
3007 | &finger_identity)) | 3039 | &finger_identity)) |
3008 | { | 3040 | { |
3041 | GNUNET_assert (finger_trail_length == 0); | ||
3009 | new_entry->trail_list[0].trail_id = trail_id; | 3042 | new_entry->trail_list[0].trail_id = trail_id; |
3010 | new_entry->trails_count = 1; | 3043 | new_entry->trails_count = 1; |
3011 | new_entry->trail_list[0].is_present = GNUNET_YES; | 3044 | new_entry->trail_list[0].is_present = GNUNET_YES; |
@@ -3029,7 +3062,7 @@ add_new_finger (struct GNUNET_PeerIdentity finger_identity, | |||
3029 | &finger_trail[0]))); | 3062 | &finger_trail[0]))); |
3030 | new_entry->trails_count = 1; | 3063 | new_entry->trails_count = 1; |
3031 | first_trail_hop->trails_count++; | 3064 | first_trail_hop->trails_count++; |
3032 | 3065 | GNUNET_assert (finger_trail_length != 0); | |
3033 | /* Copy the finger trail into trail. */ | 3066 | /* Copy the finger trail into trail. */ |
3034 | trail = GNUNET_new (struct Trail); | 3067 | trail = GNUNET_new (struct Trail); |
3035 | for(i = 0; i < finger_trail_length; i++) | 3068 | for(i = 0; i < finger_trail_length; i++) |
@@ -3487,8 +3520,6 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3487 | 3520 | ||
3488 | put = (struct PeerPutMessage *) message; | 3521 | put = (struct PeerPutMessage *) message; |
3489 | putlen = ntohl (put->put_path_length); | 3522 | putlen = ntohl (put->put_path_length); |
3490 | |||
3491 | |||
3492 | if ((msize < | 3523 | if ((msize < |
3493 | sizeof (struct PeerPutMessage) + | 3524 | sizeof (struct PeerPutMessage) + |
3494 | putlen * sizeof (struct GNUNET_PeerIdentity)) || | 3525 | putlen * sizeof (struct GNUNET_PeerIdentity)) || |
@@ -3509,7 +3540,6 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3509 | payload = &put_path[putlen]; | 3540 | payload = &put_path[putlen]; |
3510 | options = ntohl (put->options); | 3541 | options = ntohl (put->options); |
3511 | intermediate_trail_id = put->intermediate_trail_id; | 3542 | intermediate_trail_id = put->intermediate_trail_id; |
3512 | |||
3513 | payload_size = msize - (sizeof (struct PeerPutMessage) + | 3543 | payload_size = msize - (sizeof (struct PeerPutMessage) + |
3514 | putlen * sizeof (struct GNUNET_PeerIdentity)); | 3544 | putlen * sizeof (struct GNUNET_PeerIdentity)); |
3515 | 3545 | ||
@@ -3561,30 +3591,6 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3561 | } | 3591 | } |
3562 | } | 3592 | } |
3563 | 3593 | ||
3564 | #if 0 | ||
3565 | /* Check if you are present in the trail already. */ | ||
3566 | unsigned int i; | ||
3567 | for (i = 0; i < putlen; i++) | ||
3568 | { | ||
3569 | if(0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &put_path[i])) | ||
3570 | { | ||
3571 | putlen = i; | ||
3572 | break; | ||
3573 | } | ||
3574 | } | ||
3575 | #endif | ||
3576 | //FIXME: always add yourself to the peer list not the sender. | ||
3577 | /* extend 'put path' by sender */ | ||
3578 | struct GNUNET_PeerIdentity pp[putlen + 1]; | ||
3579 | if (0 != (options & GNUNET_DHT_RO_RECORD_ROUTE)) | ||
3580 | { | ||
3581 | memcpy (pp, put_path, putlen * sizeof (struct GNUNET_PeerIdentity)); | ||
3582 | pp[putlen] = *peer; | ||
3583 | putlen++; | ||
3584 | } | ||
3585 | else | ||
3586 | putlen = 0; | ||
3587 | |||
3588 | memcpy (&key_value, &(put->key), sizeof (uint64_t)); | 3594 | memcpy (&key_value, &(put->key), sizeof (uint64_t)); |
3589 | if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&best_known_dest, &my_identity))) | 3595 | if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&best_known_dest, &my_identity))) |
3590 | { | 3596 | { |
@@ -3612,6 +3618,28 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3612 | intermediate_trail_id = successor.trail_id; | 3618 | intermediate_trail_id = successor.trail_id; |
3613 | best_known_dest = successor.best_known_destination; | 3619 | best_known_dest = successor.best_known_destination; |
3614 | } | 3620 | } |
3621 | |||
3622 | /* Check if you are already a part of put path. */ | ||
3623 | unsigned int i; | ||
3624 | for (i = 0; i < putlen; i++) | ||
3625 | { | ||
3626 | if(0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &put_path[i])) | ||
3627 | { | ||
3628 | putlen = i; | ||
3629 | break; | ||
3630 | } | ||
3631 | } | ||
3632 | |||
3633 | /* Add yourself to the list. */ | ||
3634 | struct GNUNET_PeerIdentity pp[putlen + 1]; | ||
3635 | if (0 != (options & GNUNET_DHT_RO_RECORD_ROUTE)) | ||
3636 | { | ||
3637 | memcpy (pp, put_path, putlen * sizeof (struct GNUNET_PeerIdentity)); | ||
3638 | pp[putlen] = my_identity; | ||
3639 | putlen++; | ||
3640 | } | ||
3641 | else | ||
3642 | putlen = 0; | ||
3615 | 3643 | ||
3616 | GDS_CLIENTS_process_put (options, | 3644 | GDS_CLIENTS_process_put (options, |
3617 | ntohl (put->block_type), | 3645 | ntohl (put->block_type), |
@@ -3640,7 +3668,7 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3640 | ntohl (put->hop_count), putlen, pp, | 3668 | ntohl (put->hop_count), putlen, pp, |
3641 | GNUNET_TIME_absolute_ntoh (put->expiration_time), | 3669 | GNUNET_TIME_absolute_ntoh (put->expiration_time), |
3642 | payload, payload_size); | 3670 | payload, payload_size); |
3643 | } | 3671 | } |
3644 | return GNUNET_OK; | 3672 | return GNUNET_OK; |
3645 | } | 3673 | } |
3646 | 3674 | ||
@@ -3705,13 +3733,6 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3705 | ("# Bytes received from other peers"), msize, | 3733 | ("# Bytes received from other peers"), msize, |
3706 | GNUNET_NO); | 3734 | GNUNET_NO); |
3707 | 3735 | ||
3708 | /* Add sender to get path */ | ||
3709 | struct GNUNET_PeerIdentity gp[get_length + 1]; | ||
3710 | if (get_length > 0) | ||
3711 | memcpy (gp, get_path, get_length * sizeof (struct GNUNET_PeerIdentity)); | ||
3712 | gp[get_length] = *peer; | ||
3713 | get_length = get_length + 1; | ||
3714 | |||
3715 | memcpy (&key_value, &(get->key), sizeof (uint64_t)); | 3736 | memcpy (&key_value, &(get->key), sizeof (uint64_t)); |
3716 | key_value = GNUNET_ntohll (key_value); | 3737 | key_value = GNUNET_ntohll (key_value); |
3717 | 3738 | ||
@@ -3742,23 +3763,43 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3742 | best_known_dest = successor.best_known_destination; | 3763 | best_known_dest = successor.best_known_destination; |
3743 | intermediate_trail_id = successor.trail_id; | 3764 | intermediate_trail_id = successor.trail_id; |
3744 | } | 3765 | } |
3745 | 3766 | ||
3767 | /* Check if you are already a part of get path. */ | ||
3768 | unsigned int i; | ||
3769 | for (i = 0; i < get_length; i++) | ||
3770 | { | ||
3771 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &get_path[i])) | ||
3772 | { | ||
3773 | get_length = i; | ||
3774 | break; | ||
3775 | } | ||
3776 | } | ||
3777 | |||
3778 | /* Add yourself in the get path. */ | ||
3779 | struct GNUNET_PeerIdentity gp[get_length + 1]; | ||
3780 | memcpy (gp, get_path, get_length * sizeof (struct GNUNET_PeerIdentity)); | ||
3781 | gp[get_length] = my_identity; | ||
3782 | get_length = get_length + 1; | ||
3746 | GDS_CLIENTS_process_get (get->options, get->block_type,get->hop_count, | 3783 | GDS_CLIENTS_process_get (get->options, get->block_type,get->hop_count, |
3747 | get->desired_replication_level, get->get_path_length, | 3784 | get->desired_replication_level, get->get_path_length, |
3748 | gp, &get->key); | 3785 | gp, &get->key); |
3786 | |||
3749 | /* I am the final destination. */ | 3787 | /* I am the final destination. */ |
3750 | if (0 == GNUNET_CRYPTO_cmp_peer_identity(&my_identity, &best_known_dest)) | 3788 | if (0 == GNUNET_CRYPTO_cmp_peer_identity(&my_identity, &best_known_dest)) |
3751 | { | 3789 | { |
3752 | DEBUG("GET destination is me = %s,KEY = %s\n",GNUNET_i2s(&my_identity),GNUNET_h2s(&(get->key))); | 3790 | DEBUG("GET destination is me = %s,KEY = %s,get_length = %d\n", |
3753 | struct GNUNET_PeerIdentity final_get_path[get_length+1]; | 3791 | GNUNET_i2s(&my_identity),GNUNET_h2s(&(get->key)),get_length); |
3754 | 3792 | if (1 == get_length) | |
3755 | memcpy (final_get_path, gp, get_length * sizeof (struct GNUNET_PeerIdentity)); | 3793 | { |
3756 | memcpy (&final_get_path[get_length], &my_identity, sizeof (struct GNUNET_PeerIdentity)); | 3794 | GDS_DATACACHE_handle_get (&(get->key),(get->block_type), NULL, 0, |
3757 | get_length = get_length + 1; | 3795 | NULL, 0, 1, &my_identity, NULL,&my_identity); |
3758 | 3796 | } | |
3759 | GDS_DATACACHE_handle_get (&(get->key),(get->block_type), NULL, 0, NULL, 0, | 3797 | else |
3760 | get_length, final_get_path, | 3798 | { |
3761 | &final_get_path[get_length-2], &my_identity); | 3799 | GDS_DATACACHE_handle_get (&(get->key),(get->block_type), NULL, 0, NULL, 0, |
3800 | get_length, gp, &gp[get_length - 2], | ||
3801 | &my_identity); | ||
3802 | } | ||
3762 | } | 3803 | } |
3763 | else | 3804 | else |
3764 | { | 3805 | { |
@@ -3945,7 +3986,7 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3945 | struct GNUNET_HashCode trail_id; | 3986 | struct GNUNET_HashCode trail_id; |
3946 | unsigned int is_predecessor; | 3987 | unsigned int is_predecessor; |
3947 | uint32_t trail_length; | 3988 | uint32_t trail_length; |
3948 | unsigned int i; | 3989 | int i; |
3949 | size_t msize; | 3990 | size_t msize; |
3950 | 3991 | ||
3951 | msize = ntohs (message->size); | 3992 | msize = ntohs (message->size); |
@@ -4003,18 +4044,17 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
4003 | trail_length = 0; | 4044 | trail_length = 0; |
4004 | } | 4045 | } |
4005 | } | 4046 | } |
4006 | else | 4047 | |
4048 | /* Check if you are present in the trail seen so far? */ | ||
4049 | for (i = 0; i < trail_length ; i++) | ||
4007 | { | 4050 | { |
4008 | /* Check if you are present in the trail seen so far? */ | 4051 | if(0 == GNUNET_CRYPTO_cmp_peer_identity(&trail_peer_list[i],&my_identity)) |
4009 | for (i = 0; i < trail_length ; i++) | ||
4010 | { | 4052 | { |
4011 | if(0 == GNUNET_CRYPTO_cmp_peer_identity(&trail_peer_list[i],&my_identity)) | 4053 | trail_length = i; /* Check that you add yourself again */ |
4012 | { | 4054 | break; |
4013 | trail_length = i; /* Check that you add yourself again */ | ||
4014 | break; | ||
4015 | } | ||
4016 | } | 4055 | } |
4017 | } | 4056 | } |
4057 | |||
4018 | 4058 | ||
4019 | /* Is my routing table full? */ | 4059 | /* Is my routing table full? */ |
4020 | if (GNUNET_YES == GDS_ROUTING_threshold_reached()) | 4060 | if (GNUNET_YES == GDS_ROUTING_threshold_reached()) |
@@ -4050,6 +4090,12 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
4050 | return GNUNET_OK; | 4090 | return GNUNET_OK; |
4051 | } | 4091 | } |
4052 | 4092 | ||
4093 | if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, | ||
4094 | &source)) | ||
4095 | { | ||
4096 | trail_length = 0; | ||
4097 | } | ||
4098 | |||
4053 | if (trail_length > 0) | 4099 | if (trail_length > 0) |
4054 | target_friend = | 4100 | target_friend = |
4055 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 4101 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
@@ -4063,7 +4109,6 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
4063 | GNUNET_break_op (0); | 4109 | GNUNET_break_op (0); |
4064 | return GNUNET_SYSERR; | 4110 | return GNUNET_SYSERR; |
4065 | } | 4111 | } |
4066 | |||
4067 | GDS_ROUTING_add (trail_id, target_friend->id, my_identity); | 4112 | GDS_ROUTING_add (trail_id, target_friend->id, my_identity); |
4068 | GDS_NEIGHBOURS_send_trail_setup_result (source, | 4113 | GDS_NEIGHBOURS_send_trail_setup_result (source, |
4069 | my_identity, | 4114 | my_identity, |
@@ -4087,7 +4132,6 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
4087 | memcpy (peer_list, trail_peer_list, | 4132 | memcpy (peer_list, trail_peer_list, |
4088 | trail_length * sizeof (struct GNUNET_PeerIdentity)); | 4133 | trail_length * sizeof (struct GNUNET_PeerIdentity)); |
4089 | peer_list[trail_length] = my_identity; | 4134 | peer_list[trail_length] = my_identity; |
4090 | |||
4091 | GDS_NEIGHBOURS_send_trail_setup (source, | 4135 | GDS_NEIGHBOURS_send_trail_setup (source, |
4092 | final_dest_finger_val, | 4136 | final_dest_finger_val, |
4093 | next_peer.best_known_destination, | 4137 | next_peer.best_known_destination, |
@@ -4175,7 +4219,6 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p | |||
4175 | GNUNET_assert(0 == GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, | 4219 | GNUNET_assert(0 == GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, |
4176 | peer)); | 4220 | peer)); |
4177 | } | 4221 | } |
4178 | |||
4179 | GDS_ROUTING_add (trail_id, my_identity, *peer); | 4222 | GDS_ROUTING_add (trail_id, my_identity, *peer); |
4180 | finger_table_add (finger_identity, trail_peer_list, trail_length, | 4223 | finger_table_add (finger_identity, trail_peer_list, trail_length, |
4181 | is_predecessor, ulitmate_destination_finger_value, trail_id); | 4224 | is_predecessor, ulitmate_destination_finger_value, trail_id); |
@@ -4230,7 +4273,6 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p | |||
4230 | GNUNET_break_op (0); | 4273 | GNUNET_break_op (0); |
4231 | return GNUNET_SYSERR; | 4274 | return GNUNET_SYSERR; |
4232 | } | 4275 | } |
4233 | |||
4234 | GDS_ROUTING_add (trail_id, next_hop, *peer); | 4276 | GDS_ROUTING_add (trail_id, next_hop, *peer); |
4235 | GDS_NEIGHBOURS_send_trail_setup_result (querying_peer, finger_identity, | 4277 | GDS_NEIGHBOURS_send_trail_setup_result (querying_peer, finger_identity, |
4236 | target_friend, trail_length, trail_peer_list, | 4278 | target_friend, trail_length, trail_peer_list, |
@@ -5097,8 +5139,6 @@ handle_dht_p2p_notify_new_successor(void *cls, | |||
5097 | next_hop = new_successor; | 5139 | next_hop = new_successor; |
5098 | else | 5140 | else |
5099 | next_hop = trail[my_index + 1]; | 5141 | next_hop = trail[my_index + 1]; |
5100 | |||
5101 | |||
5102 | /* Add an entry in routing table for trail from source to its new successor. */ | 5142 | /* Add an entry in routing table for trail from source to its new successor. */ |
5103 | GNUNET_assert (GNUNET_OK == GDS_ROUTING_add (trail_id, *peer, next_hop)); | 5143 | GNUNET_assert (GNUNET_OK == GDS_ROUTING_add (trail_id, *peer, next_hop)); |
5104 | GNUNET_assert (NULL != | 5144 | GNUNET_assert (NULL != |
@@ -5251,7 +5291,6 @@ handle_dht_p2p_trail_setup_rejection (void *cls, | |||
5251 | GNUNET_assert (NULL != | 5291 | GNUNET_assert (NULL != |
5252 | (target_friend = | 5292 | (target_friend = |
5253 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop))); | 5293 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop))); |
5254 | |||
5255 | GDS_NEIGHBOURS_send_trail_setup (source, | 5294 | GDS_NEIGHBOURS_send_trail_setup (source, |
5256 | ultimate_destination_finger_value, | 5295 | ultimate_destination_finger_value, |
5257 | successor.best_known_destination, | 5296 | successor.best_known_destination, |
@@ -5418,7 +5457,6 @@ handle_dht_p2p_add_trail (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
5418 | { | 5457 | { |
5419 | next_hop = trail[my_index + 1]; | 5458 | next_hop = trail[my_index + 1]; |
5420 | } | 5459 | } |
5421 | |||
5422 | /* Add in your routing table. */ | 5460 | /* Add in your routing table. */ |
5423 | GNUNET_assert (GNUNET_OK == GDS_ROUTING_add (trail_id, next_hop, *peer)); | 5461 | GNUNET_assert (GNUNET_OK == GDS_ROUTING_add (trail_id, next_hop, *peer)); |
5424 | GNUNET_assert (NULL != | 5462 | GNUNET_assert (NULL != |
@@ -5517,14 +5555,11 @@ remove_matching_fingers (const struct GNUNET_PeerIdentity *disconnected_peer) | |||
5517 | current_finger = &finger_table[i]; | 5555 | current_finger = &finger_table[i]; |
5518 | 5556 | ||
5519 | /* No finger stored at this trail index. */ | 5557 | /* No finger stored at this trail index. */ |
5520 | if (GNUNET_NO == current_finger->is_present) | 5558 | if ((GNUNET_NO == current_finger->is_present) || |
5521 | continue; | 5559 | (0 == GNUNET_CRYPTO_cmp_peer_identity (¤t_finger->finger_identity, |
5522 | 5560 | &my_identity))) | |
5523 | /* I am my own finger, then ignore this finger. */ | ||
5524 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (¤t_finger->finger_identity, | ||
5525 | &my_identity)) | ||
5526 | continue; | 5561 | continue; |
5527 | 5562 | ||
5528 | /* Is disconnected_peer a finger? */ | 5563 | /* Is disconnected_peer a finger? */ |
5529 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (disconnected_peer, | 5564 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (disconnected_peer, |
5530 | ¤t_finger->finger_identity)) | 5565 | ¤t_finger->finger_identity)) |
@@ -5597,7 +5632,9 @@ handle_core_disconnect (void *cls, | |||
5597 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer))) | 5632 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer))) |
5598 | { | 5633 | { |
5599 | DEBUG("\n friend already disconnected."); | 5634 | DEBUG("\n friend already disconnected."); |
5635 | return; | ||
5600 | } | 5636 | } |
5637 | |||
5601 | remove_matching_fingers (peer); | 5638 | remove_matching_fingers (peer); |
5602 | GNUNET_assert (GNUNET_SYSERR != GDS_ROUTING_remove_trail_by_peer (peer)); | 5639 | GNUNET_assert (GNUNET_SYSERR != GDS_ROUTING_remove_trail_by_peer (peer)); |
5603 | GNUNET_assert (GNUNET_YES == | 5640 | GNUNET_assert (GNUNET_YES == |
@@ -5624,7 +5661,7 @@ handle_core_disconnect (void *cls, | |||
5624 | gettext_noop | 5661 | gettext_noop |
5625 | ("# Queued messages discarded (peer disconnected)"), | 5662 | ("# Queued messages discarded (peer disconnected)"), |
5626 | discarded, GNUNET_NO); | 5663 | discarded, GNUNET_NO); |
5627 | GNUNET_free (remove_friend); | 5664 | //GNUNET_free (remove_friend); |
5628 | 5665 | ||
5629 | if (0 != GNUNET_CONTAINER_multipeermap_size (friend_peermap)) | 5666 | if (0 != GNUNET_CONTAINER_multipeermap_size (friend_peermap)) |
5630 | return; | 5667 | return; |
diff --git a/src/dht/gnunet_dht_profiler.c b/src/dht/gnunet_dht_profiler.c index acc0453ac..12c273492 100644 --- a/src/dht/gnunet_dht_profiler.c +++ b/src/dht/gnunet_dht_profiler.c | |||
@@ -1105,7 +1105,7 @@ main (int argc, char *const *argv) | |||
1105 | GNUNET_GETOPT_OPTION_END | 1105 | GNUNET_GETOPT_OPTION_END |
1106 | }; | 1106 | }; |
1107 | 1107 | ||
1108 | max_searches = 10; | 1108 | max_searches = 5; |
1109 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 1109 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
1110 | return 2; | 1110 | return 2; |
1111 | delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20); /* default delay */ | 1111 | delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20); /* default delay */ |