diff options
Diffstat (limited to 'src/dht/gnunet-service-xdht_neighbours.c')
-rw-r--r-- | src/dht/gnunet-service-xdht_neighbours.c | 313 |
1 files changed, 186 insertions, 127 deletions
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c index 7ab462a58..e3462f618 100644 --- a/src/dht/gnunet-service-xdht_neighbours.c +++ b/src/dht/gnunet-service-xdht_neighbours.c | |||
@@ -37,10 +37,9 @@ | |||
37 | #include "gnunet_transport_service.h" | 37 | #include "gnunet_transport_service.h" |
38 | #include "gnunet_dht_service.h" | 38 | #include "gnunet_dht_service.h" |
39 | #include "gnunet_statistics_service.h" | 39 | #include "gnunet_statistics_service.h" |
40 | #include "gnunet-service-xdht.h" | 40 | #include "gnunet-service-dht.h" |
41 | #include "gnunet-service-xdht_clients.h" | 41 | #include "gnunet-service-dht_datacache.h" |
42 | #include "gnunet-service-xdht_datacache.h" | 42 | #include "gnunet-service-dht_neighbours.h" |
43 | #include "gnunet-service-xdht_neighbours.h" | ||
44 | #include "gnunet-service-xdht_routing.h" | 43 | #include "gnunet-service-xdht_routing.h" |
45 | #include "dht.h" | 44 | #include "dht.h" |
46 | 45 | ||
@@ -1017,7 +1016,7 @@ GDS_NEIGHBOURS_send_trail_setup_result (const struct GNUNET_PeerIdentity *queryi | |||
1017 | tsrm->finger_identity = *finger; | 1016 | tsrm->finger_identity = *finger; |
1018 | tsrm->is_predecessor = htonl (is_predecessor); | 1017 | tsrm->is_predecessor = htonl (is_predecessor); |
1019 | tsrm->trail_id = *trail_id; | 1018 | tsrm->trail_id = *trail_id; |
1020 | tsrm->ultimate_destination_finger_value | 1019 | tsrm->ultimate_destination_finger_value |
1021 | = GNUNET_htonll (ultimate_destination_finger_value); | 1020 | = GNUNET_htonll (ultimate_destination_finger_value); |
1022 | GNUNET_memcpy (&tsrm[1], | 1021 | GNUNET_memcpy (&tsrm[1], |
1023 | trail_peer_list, | 1022 | trail_peer_list, |
@@ -1114,7 +1113,7 @@ GDS_NEIGHBOURS_send_trail_rejection (const struct GNUNET_PeerIdentity *source_pe | |||
1114 | trm->congestion_time = congestion_timeout; | 1113 | trm->congestion_time = congestion_timeout; |
1115 | trm->is_predecessor = htonl (is_predecessor); | 1114 | trm->is_predecessor = htonl (is_predecessor); |
1116 | trm->trail_id = *trail_id; | 1115 | trm->trail_id = *trail_id; |
1117 | trm->ultimate_destination_finger_value | 1116 | trm->ultimate_destination_finger_value |
1118 | = GNUNET_htonll (ultimate_destination_finger_value); | 1117 | = GNUNET_htonll (ultimate_destination_finger_value); |
1119 | GNUNET_memcpy (&trm[1], | 1118 | GNUNET_memcpy (&trm[1], |
1120 | trail_peer_list, | 1119 | trail_peer_list, |
@@ -1957,7 +1956,7 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key, | |||
1957 | GNUNET_break (0); | 1956 | GNUNET_break (0); |
1958 | return; | 1957 | return; |
1959 | } | 1958 | } |
1960 | 1959 | ||
1961 | GNUNET_assert (NULL != | 1960 | GNUNET_assert (NULL != |
1962 | (target_friend = | 1961 | (target_friend = |
1963 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 1962 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
@@ -1989,20 +1988,29 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key, | |||
1989 | /** | 1988 | /** |
1990 | * Handle the put request from the client. | 1989 | * Handle the put request from the client. |
1991 | * | 1990 | * |
1992 | * @param key Key for the content | ||
1993 | * @param block_type Type of the block | 1991 | * @param block_type Type of the block |
1994 | * @param options Routing options | 1992 | * @param options Routing options |
1995 | * @param desired_replication_level Desired replication count | 1993 | * @param desired_replication_level Desired replication count |
1996 | * @param expiration_time When does the content expire | 1994 | * @param expiration_time When does the content expire |
1995 | * @param hop_count how many hops has this message traversed so far | ||
1996 | * @param bf Bloom filter of peers this PUT has already traversed | ||
1997 | * @param key Key for the content | ||
1998 | * @param put_path_length number of entries in put_path | ||
1999 | * @param put_path peers this request has traversed so far (if tracked) | ||
1997 | * @param data Content to store | 2000 | * @param data Content to store |
1998 | * @param data_size Size of content @a data in bytes | 2001 | * @param data_size Size of content @a data in bytes |
2002 | * @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not | ||
1999 | */ | 2003 | */ |
2000 | void | 2004 | int |
2001 | GDS_NEIGHBOURS_handle_put (const struct GNUNET_HashCode *key, | 2005 | GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type block_type, |
2002 | enum GNUNET_BLOCK_Type block_type, | ||
2003 | enum GNUNET_DHT_RouteOption options, | 2006 | enum GNUNET_DHT_RouteOption options, |
2004 | uint32_t desired_replication_level, | 2007 | uint32_t desired_replication_level, |
2005 | struct GNUNET_TIME_Absolute expiration_time, | 2008 | struct GNUNET_TIME_Absolute expiration_time, |
2009 | uint32_t hop_count, | ||
2010 | struct GNUNET_CONTAINER_BloomFilter *bf, | ||
2011 | const struct GNUNET_HashCode *key, | ||
2012 | unsigned int put_path_length, | ||
2013 | struct GNUNET_PeerIdentity *put_path, | ||
2006 | const void *data, | 2014 | const void *data, |
2007 | size_t data_size) | 2015 | size_t data_size) |
2008 | { | 2016 | { |
@@ -2045,7 +2053,7 @@ GDS_NEIGHBOURS_handle_put (const struct GNUNET_HashCode *key, | |||
2045 | key, | 2053 | key, |
2046 | data, | 2054 | data, |
2047 | data_size); | 2055 | data_size); |
2048 | return; | 2056 | return GNUNET_NO; |
2049 | } | 2057 | } |
2050 | /* In case we are sending the request to a finger, then send across all of its | 2058 | /* In case we are sending the request to a finger, then send across all of its |
2051 | trail.*/ | 2059 | trail.*/ |
@@ -2062,6 +2070,7 @@ GDS_NEIGHBOURS_handle_put (const struct GNUNET_HashCode *key, | |||
2062 | expiration_time, | 2070 | expiration_time, |
2063 | data, | 2071 | data, |
2064 | data_size); | 2072 | data_size); |
2073 | return GNUNET_OK; | ||
2065 | } | 2074 | } |
2066 | 2075 | ||
2067 | 2076 | ||
@@ -2099,7 +2108,7 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key, | |||
2099 | struct GNUNET_MQ_Envelope *env; | 2108 | struct GNUNET_MQ_Envelope *env; |
2100 | struct FriendInfo *target_friend; | 2109 | struct FriendInfo *target_friend; |
2101 | size_t msize; | 2110 | size_t msize; |
2102 | 2111 | ||
2103 | msize = get_path_length * sizeof (struct GNUNET_PeerIdentity); | 2112 | msize = get_path_length * sizeof (struct GNUNET_PeerIdentity); |
2104 | if (msize + sizeof (struct PeerGetMessage) | 2113 | if (msize + sizeof (struct PeerGetMessage) |
2105 | >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) | 2114 | >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) |
@@ -2129,70 +2138,10 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key, | |||
2129 | 2138 | ||
2130 | 2139 | ||
2131 | /** | 2140 | /** |
2132 | * Handle the get request from the client file. If I am destination do | ||
2133 | * datacache put and return. Else find the target friend and forward message | ||
2134 | * to it. | ||
2135 | * | ||
2136 | * @param key Key for the content | ||
2137 | * @param block_type Type of the block | ||
2138 | * @param options Routing options | ||
2139 | * @param desired_replication_level Desired replication count | ||
2140 | */ | ||
2141 | void | ||
2142 | GDS_NEIGHBOURS_handle_get (const struct GNUNET_HashCode *key, | ||
2143 | enum GNUNET_BLOCK_Type block_type, | ||
2144 | enum GNUNET_DHT_RouteOption options, | ||
2145 | uint32_t desired_replication_level) | ||
2146 | { | ||
2147 | struct Closest_Peer successor; | ||
2148 | struct GNUNET_PeerIdentity best_known_dest; | ||
2149 | struct GNUNET_HashCode intermediate_trail_id; | ||
2150 | uint64_t key_value; | ||
2151 | |||
2152 | GNUNET_memcpy (&key_value, | ||
2153 | key, | ||
2154 | sizeof (uint64_t)); | ||
2155 | key_value = GNUNET_ntohll (key_value); | ||
2156 | successor = find_local_best_known_next_hop (key_value, | ||
2157 | GDS_FINGER_TYPE_NON_PREDECESSOR); | ||
2158 | best_known_dest = successor.best_known_destination; | ||
2159 | intermediate_trail_id = successor.trail_id; | ||
2160 | |||
2161 | /* I am the destination. I have the data. */ | ||
2162 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, | ||
2163 | &best_known_dest)) | ||
2164 | { | ||
2165 | GDS_DATACACHE_handle_get (key, | ||
2166 | block_type, | ||
2167 | NULL, | ||
2168 | 0, | ||
2169 | NULL, | ||
2170 | 0, | ||
2171 | 1, | ||
2172 | &my_identity, | ||
2173 | NULL, | ||
2174 | &my_identity); | ||
2175 | return; | ||
2176 | } | ||
2177 | |||
2178 | GDS_NEIGHBOURS_send_get (key, | ||
2179 | block_type, | ||
2180 | options, | ||
2181 | desired_replication_level, | ||
2182 | &best_known_dest, | ||
2183 | &intermediate_trail_id, | ||
2184 | &successor.next_hop, | ||
2185 | 0, | ||
2186 | 1, | ||
2187 | &my_identity); | ||
2188 | } | ||
2189 | |||
2190 | |||
2191 | /** | ||
2192 | * Send the get result to requesting client. | 2141 | * Send the get result to requesting client. |
2193 | * | 2142 | * |
2194 | * @param key Key of the requested data. | 2143 | * @param key Key of the requested data. |
2195 | * @param type Block type | 2144 | * @param block_type Block type |
2196 | * @param target_peer Next peer to forward the message to. | 2145 | * @param target_peer Next peer to forward the message to. |
2197 | * @param source_peer Peer which has the data for the key. | 2146 | * @param source_peer Peer which has the data for the key. |
2198 | * @param put_path_length Number of peers in @a put_path | 2147 | * @param put_path_length Number of peers in @a put_path |
@@ -2205,7 +2154,7 @@ GDS_NEIGHBOURS_handle_get (const struct GNUNET_HashCode *key, | |||
2205 | */ | 2154 | */ |
2206 | void | 2155 | void |
2207 | GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *key, | 2156 | GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *key, |
2208 | enum GNUNET_BLOCK_Type type, | 2157 | enum GNUNET_BLOCK_Type block_type, |
2209 | const struct GNUNET_PeerIdentity *target_peer, | 2158 | const struct GNUNET_PeerIdentity *target_peer, |
2210 | const struct GNUNET_PeerIdentity *source_peer, | 2159 | const struct GNUNET_PeerIdentity *source_peer, |
2211 | unsigned int put_path_length, | 2160 | unsigned int put_path_length, |
@@ -2256,15 +2205,15 @@ GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *key, | |||
2256 | if (0 == current_path_index) | 2205 | if (0 == current_path_index) |
2257 | { | 2206 | { |
2258 | DEBUG ("GET_RESULT TO CLIENT KEY = %s, Peer = %s", | 2207 | DEBUG ("GET_RESULT TO CLIENT KEY = %s, Peer = %s", |
2259 | GNUNET_h2s(key), | 2208 | GNUNET_h2s (key), |
2260 | GNUNET_i2s(&my_identity)); | 2209 | GNUNET_i2s (&my_identity)); |
2261 | GDS_CLIENTS_handle_reply (expiration, | 2210 | GDS_CLIENTS_handle_reply (expiration, |
2262 | key, | 2211 | key, |
2263 | get_path_length, | 2212 | get_path_length, |
2264 | get_path, | 2213 | get_path, |
2265 | put_path_length, | 2214 | put_path_length, |
2266 | put_path, | 2215 | put_path, |
2267 | type, | 2216 | block_type, |
2268 | data_size, | 2217 | data_size, |
2269 | data); | 2218 | data); |
2270 | return; | 2219 | return; |
@@ -2298,6 +2247,120 @@ GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *key, | |||
2298 | 2247 | ||
2299 | 2248 | ||
2300 | /** | 2249 | /** |
2250 | * Handle a result for a GET operation. | ||
2251 | * | ||
2252 | * @param cls closure | ||
2253 | * @param type type of the block | ||
2254 | * @param expiration_time when does the content expire | ||
2255 | * @param key key for the content | ||
2256 | * @param put_path_length number of entries in @a put_path | ||
2257 | * @param put_path peers the original PUT traversed (if tracked) | ||
2258 | * @param get_path_length number of entries in @a get_path | ||
2259 | * @param get_path peers this reply has traversed so far (if tracked) | ||
2260 | * @param data payload of the reply | ||
2261 | * @param data_size number of bytes in @a data | ||
2262 | */ | ||
2263 | static void | ||
2264 | get_cb (void *cls, | ||
2265 | enum GNUNET_BLOCK_Type type, | ||
2266 | struct GNUNET_TIME_Absolute expiration_time, | ||
2267 | const struct GNUNET_HashCode *key, | ||
2268 | unsigned int put_path_length, | ||
2269 | const struct GNUNET_PeerIdentity *put_path, | ||
2270 | unsigned int get_path_length, | ||
2271 | const struct GNUNET_PeerIdentity *get_path, | ||
2272 | const void *data, | ||
2273 | size_t data_size) | ||
2274 | { | ||
2275 | struct GNUNET_PeerIdentity *target_peer = cls; | ||
2276 | // FIXME: inline? | ||
2277 | GDS_NEIGHBOURS_send_get_result (key, | ||
2278 | type, | ||
2279 | target_peer, | ||
2280 | &my_identity, | ||
2281 | put_path_length, | ||
2282 | put_path, | ||
2283 | 1, | ||
2284 | &my_identity, | ||
2285 | expiration_time, | ||
2286 | data, | ||
2287 | data_size); | ||
2288 | } | ||
2289 | |||
2290 | |||
2291 | /** | ||
2292 | * Perform a GET operation. Forwards the given request to other | ||
2293 | * peers. Does not lookup the key locally. May do nothing if this is | ||
2294 | * the only peer in the network (or if we are the closest peer in the | ||
2295 | * network). | ||
2296 | * | ||
2297 | * @param block_type type of the block | ||
2298 | * @param options routing options | ||
2299 | * @param desired_replication_level desired replication count | ||
2300 | * @param hop_count how many hops did this request traverse so far? | ||
2301 | * @param key key for the content | ||
2302 | * @param xquery extended query | ||
2303 | * @param xquery_size number of bytes in @a xquery | ||
2304 | * @param reply_bf bloomfilter to filter duplicates | ||
2305 | * @param reply_bf_mutator mutator for @a reply_bf | ||
2306 | * @param peer_bf filter for peers not to select (again, updated) | ||
2307 | * @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not | ||
2308 | */ | ||
2309 | int | ||
2310 | GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type block_type, | ||
2311 | enum GNUNET_DHT_RouteOption options, | ||
2312 | uint32_t desired_replication_level, | ||
2313 | uint32_t hop_count, | ||
2314 | const struct GNUNET_HashCode *key, | ||
2315 | const void *xquery, size_t xquery_size, | ||
2316 | const struct GNUNET_CONTAINER_BloomFilter *reply_bf, | ||
2317 | uint32_t reply_bf_mutator, | ||
2318 | struct GNUNET_CONTAINER_BloomFilter *peer_bf) | ||
2319 | { | ||
2320 | struct Closest_Peer successor; | ||
2321 | struct GNUNET_PeerIdentity best_known_dest; | ||
2322 | struct GNUNET_HashCode intermediate_trail_id; | ||
2323 | uint64_t key_value; | ||
2324 | |||
2325 | GNUNET_memcpy (&key_value, | ||
2326 | key, | ||
2327 | sizeof (uint64_t)); | ||
2328 | key_value = GNUNET_ntohll (key_value); | ||
2329 | successor = find_local_best_known_next_hop (key_value, | ||
2330 | GDS_FINGER_TYPE_NON_PREDECESSOR); | ||
2331 | best_known_dest = successor.best_known_destination; | ||
2332 | intermediate_trail_id = successor.trail_id; | ||
2333 | |||
2334 | /* I am the destination. I have the data. */ | ||
2335 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, | ||
2336 | &best_known_dest)) | ||
2337 | { | ||
2338 | GDS_DATACACHE_handle_get (key, | ||
2339 | block_type, | ||
2340 | NULL, | ||
2341 | 0, | ||
2342 | NULL, | ||
2343 | 0, | ||
2344 | &get_cb, | ||
2345 | NULL); | ||
2346 | return GNUNET_NO; | ||
2347 | } | ||
2348 | |||
2349 | GDS_NEIGHBOURS_send_get (key, | ||
2350 | block_type, | ||
2351 | options, | ||
2352 | desired_replication_level, | ||
2353 | &best_known_dest, | ||
2354 | &intermediate_trail_id, | ||
2355 | &successor.next_hop, | ||
2356 | 0, | ||
2357 | 1, | ||
2358 | &my_identity); | ||
2359 | return GNUNET_OK; | ||
2360 | } | ||
2361 | |||
2362 | |||
2363 | /** | ||
2301 | * Randomly choose one of your friends (which is not congested and have not crossed | 2364 | * Randomly choose one of your friends (which is not congested and have not crossed |
2302 | * trail threshold) from the friend_peermap | 2365 | * trail threshold) from the friend_peermap |
2303 | * @return Friend Randomly chosen friend. | 2366 | * @return Friend Randomly chosen friend. |
@@ -3121,7 +3184,7 @@ update_current_search_finger_index (unsigned int finger_table_index) | |||
3121 | { | 3184 | { |
3122 | if (NULL == send_verify_successor_task) | 3185 | if (NULL == send_verify_successor_task) |
3123 | { | 3186 | { |
3124 | send_verify_successor_task | 3187 | send_verify_successor_task |
3125 | = GNUNET_SCHEDULER_add_now (&send_verify_successor_message, | 3188 | = GNUNET_SCHEDULER_add_now (&send_verify_successor_message, |
3126 | NULL); | 3189 | NULL); |
3127 | } | 3190 | } |
@@ -3389,7 +3452,7 @@ finger_table_add (const struct GNUNET_PeerIdentity *finger_identity, | |||
3389 | else | 3452 | else |
3390 | select_and_replace_trail (existing_finger, | 3453 | select_and_replace_trail (existing_finger, |
3391 | finger_trail, | 3454 | finger_trail, |
3392 | finger_trail_length, | 3455 | finger_trail_length, |
3393 | finger_trail_id); | 3456 | finger_trail_id); |
3394 | } | 3457 | } |
3395 | update_current_search_finger_index (finger_table_index); | 3458 | update_current_search_finger_index (finger_table_index); |
@@ -3425,7 +3488,7 @@ check_dht_p2p_put (void *cls, | |||
3425 | return GNUNET_OK; | 3488 | return GNUNET_OK; |
3426 | } | 3489 | } |
3427 | 3490 | ||
3428 | 3491 | ||
3429 | /** | 3492 | /** |
3430 | * Core handler for P2P put messages. | 3493 | * Core handler for P2P put messages. |
3431 | * | 3494 | * |
@@ -3435,7 +3498,7 @@ check_dht_p2p_put (void *cls, | |||
3435 | static void | 3498 | static void |
3436 | handle_dht_p2p_put (void *cls, | 3499 | handle_dht_p2p_put (void *cls, |
3437 | const struct PeerPutMessage *put) | 3500 | const struct PeerPutMessage *put) |
3438 | { | 3501 | { |
3439 | struct GNUNET_PeerIdentity *put_path; | 3502 | struct GNUNET_PeerIdentity *put_path; |
3440 | struct GNUNET_PeerIdentity current_best_known_dest; | 3503 | struct GNUNET_PeerIdentity current_best_known_dest; |
3441 | struct GNUNET_PeerIdentity best_known_dest; | 3504 | struct GNUNET_PeerIdentity best_known_dest; |
@@ -3623,7 +3686,7 @@ handle_dht_p2p_put (void *cls, | |||
3623 | * @return #GNUNET_OK if @a get is well-formed | 3686 | * @return #GNUNET_OK if @a get is well-formed |
3624 | */ | 3687 | */ |
3625 | static int | 3688 | static int |
3626 | check_dht_p2p_get (void *cls, | 3689 | check_dht_p2p_get (void *cls, |
3627 | const struct PeerGetMessage *get) | 3690 | const struct PeerGetMessage *get) |
3628 | { | 3691 | { |
3629 | uint32_t get_length; | 3692 | uint32_t get_length; |
@@ -3653,7 +3716,7 @@ check_dht_p2p_get (void *cls, | |||
3653 | * @param get the message | 3716 | * @param get the message |
3654 | */ | 3717 | */ |
3655 | static void | 3718 | static void |
3656 | handle_dht_p2p_get (void *cls, | 3719 | handle_dht_p2p_get (void *cls, |
3657 | const struct PeerGetMessage *get) | 3720 | const struct PeerGetMessage *get) |
3658 | { | 3721 | { |
3659 | const struct GNUNET_PeerIdentity *get_path; | 3722 | const struct GNUNET_PeerIdentity *get_path; |
@@ -3744,10 +3807,8 @@ handle_dht_p2p_get (void *cls, | |||
3744 | 0, | 3807 | 0, |
3745 | NULL, | 3808 | NULL, |
3746 | 0, | 3809 | 0, |
3747 | 1, | 3810 | &get_cb, |
3748 | &my_identity, | 3811 | NULL); |
3749 | NULL, | ||
3750 | &my_identity); | ||
3751 | } | 3812 | } |
3752 | else | 3813 | else |
3753 | { | 3814 | { |
@@ -3757,10 +3818,8 @@ handle_dht_p2p_get (void *cls, | |||
3757 | 0, | 3818 | 0, |
3758 | NULL, | 3819 | NULL, |
3759 | 0, | 3820 | 0, |
3760 | get_length, | 3821 | &get_cb, |
3761 | gp, | 3822 | &gp[get_length - 2]); |
3762 | &gp[get_length - 2], | ||
3763 | &my_identity); | ||
3764 | } | 3823 | } |
3765 | } | 3824 | } |
3766 | else | 3825 | else |
@@ -3822,7 +3881,7 @@ check_dht_p2p_get_result (void *cls, | |||
3822 | static void | 3881 | static void |
3823 | handle_dht_p2p_get_result (void *cls, | 3882 | handle_dht_p2p_get_result (void *cls, |
3824 | const struct PeerGetResultMessage *get_result) | 3883 | const struct PeerGetResultMessage *get_result) |
3825 | { | 3884 | { |
3826 | const struct GNUNET_PeerIdentity *get_path; | 3885 | const struct GNUNET_PeerIdentity *get_path; |
3827 | const struct GNUNET_PeerIdentity *put_path; | 3886 | const struct GNUNET_PeerIdentity *put_path; |
3828 | const void *payload; | 3887 | const void *payload; |
@@ -3965,7 +4024,7 @@ get_local_best_known_next_hop (uint64_t final_dest_finger_val, | |||
3965 | * @return #GNUNET_OK if @a trail_setup is well-formed | 4024 | * @return #GNUNET_OK if @a trail_setup is well-formed |
3966 | */ | 4025 | */ |
3967 | static int | 4026 | static int |
3968 | check_dht_p2p_trail_setup (void *cls, | 4027 | check_dht_p2p_trail_setup (void *cls, |
3969 | const struct PeerTrailSetupMessage *trail_setup) | 4028 | const struct PeerTrailSetupMessage *trail_setup) |
3970 | { | 4029 | { |
3971 | size_t msize; | 4030 | size_t msize; |
@@ -3988,7 +4047,7 @@ check_dht_p2p_trail_setup (void *cls, | |||
3988 | * @param trail_setup the message | 4047 | * @param trail_setup the message |
3989 | */ | 4048 | */ |
3990 | static void | 4049 | static void |
3991 | handle_dht_p2p_trail_setup (void *cls, | 4050 | handle_dht_p2p_trail_setup (void *cls, |
3992 | const struct PeerTrailSetupMessage *trail_setup) | 4051 | const struct PeerTrailSetupMessage *trail_setup) |
3993 | { | 4052 | { |
3994 | struct FriendInfo *friend = cls; | 4053 | struct FriendInfo *friend = cls; |
@@ -4014,7 +4073,7 @@ handle_dht_p2p_trail_setup (void *cls, | |||
4014 | trail_peer_list = (const struct GNUNET_PeerIdentity *) &trail_setup[1]; | 4073 | trail_peer_list = (const struct GNUNET_PeerIdentity *) &trail_setup[1]; |
4015 | current_dest = trail_setup->best_known_destination; | 4074 | current_dest = trail_setup->best_known_destination; |
4016 | trail_id = trail_setup->trail_id; | 4075 | trail_id = trail_setup->trail_id; |
4017 | final_dest_finger_val | 4076 | final_dest_finger_val |
4018 | = GNUNET_ntohll (trail_setup->final_destination_finger_value); | 4077 | = GNUNET_ntohll (trail_setup->final_destination_finger_value); |
4019 | source = trail_setup->source_peer; | 4078 | source = trail_setup->source_peer; |
4020 | is_predecessor = ntohl (trail_setup->is_predecessor); | 4079 | is_predecessor = ntohl (trail_setup->is_predecessor); |
@@ -4024,7 +4083,7 @@ handle_dht_p2p_trail_setup (void *cls, | |||
4024 | if ( (trail_length > 0) && | 4083 | if ( (trail_length > 0) && |
4025 | (0 != memcmp (&trail_peer_list[trail_length-1], | 4084 | (0 != memcmp (&trail_peer_list[trail_length-1], |
4026 | friend->id, | 4085 | friend->id, |
4027 | sizeof (struct GNUNET_PeerIdentity))) ) | 4086 | sizeof (struct GNUNET_PeerIdentity))) ) |
4028 | { | 4087 | { |
4029 | GNUNET_break_op (0); | 4088 | GNUNET_break_op (0); |
4030 | return; | 4089 | return; |
@@ -4052,7 +4111,7 @@ handle_dht_p2p_trail_setup (void *cls, | |||
4052 | /* Is my routing table full? */ | 4111 | /* Is my routing table full? */ |
4053 | if (GNUNET_YES == GDS_ROUTING_threshold_reached ()) | 4112 | if (GNUNET_YES == GDS_ROUTING_threshold_reached ()) |
4054 | { | 4113 | { |
4055 | target_friend | 4114 | target_friend |
4056 | = (trail_length > 0) | 4115 | = (trail_length > 0) |
4057 | ? GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 4116 | ? GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
4058 | &trail_peer_list[trail_length - 1]) | 4117 | &trail_peer_list[trail_length - 1]) |
@@ -4077,7 +4136,7 @@ handle_dht_p2p_trail_setup (void *cls, | |||
4077 | } | 4136 | } |
4078 | 4137 | ||
4079 | /* Get the next hop to forward the trail setup request. */ | 4138 | /* Get the next hop to forward the trail setup request. */ |
4080 | struct Closest_Peer next_peer | 4139 | struct Closest_Peer next_peer |
4081 | = get_local_best_known_next_hop (final_dest_finger_val, | 4140 | = get_local_best_known_next_hop (final_dest_finger_val, |
4082 | &intermediate_trail_id, | 4141 | &intermediate_trail_id, |
4083 | is_predecessor, | 4142 | is_predecessor, |
@@ -4100,7 +4159,7 @@ handle_dht_p2p_trail_setup (void *cls, | |||
4100 | return; | 4159 | return; |
4101 | } | 4160 | } |
4102 | 4161 | ||
4103 | target_friend | 4162 | target_friend |
4104 | = (trail_length > 0) | 4163 | = (trail_length > 0) |
4105 | ? GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 4164 | ? GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
4106 | &trail_peer_list[trail_length-1]) | 4165 | &trail_peer_list[trail_length-1]) |
@@ -4139,7 +4198,7 @@ handle_dht_p2p_trail_setup (void *cls, | |||
4139 | { | 4198 | { |
4140 | /* Add yourself to list of peers. */ | 4199 | /* Add yourself to list of peers. */ |
4141 | struct GNUNET_PeerIdentity peer_list[trail_length + 1]; | 4200 | struct GNUNET_PeerIdentity peer_list[trail_length + 1]; |
4142 | 4201 | ||
4143 | GNUNET_memcpy (peer_list, | 4202 | GNUNET_memcpy (peer_list, |
4144 | trail_peer_list, | 4203 | trail_peer_list, |
4145 | trail_length * sizeof (struct GNUNET_PeerIdentity)); | 4204 | trail_length * sizeof (struct GNUNET_PeerIdentity)); |
@@ -4175,7 +4234,7 @@ handle_dht_p2p_trail_setup (void *cls, | |||
4175 | * @return #GNUNET_OK if @a trail_result is well-formed | 4234 | * @return #GNUNET_OK if @a trail_result is well-formed |
4176 | */ | 4235 | */ |
4177 | static int | 4236 | static int |
4178 | check_dht_p2p_trail_setup_result (void *cls, | 4237 | check_dht_p2p_trail_setup_result (void *cls, |
4179 | const struct PeerTrailSetupResultMessage *trail_result) | 4238 | const struct PeerTrailSetupResultMessage *trail_result) |
4180 | { | 4239 | { |
4181 | size_t msize; | 4240 | size_t msize; |
@@ -4189,7 +4248,7 @@ check_dht_p2p_trail_setup_result (void *cls, | |||
4189 | } | 4248 | } |
4190 | return GNUNET_OK; | 4249 | return GNUNET_OK; |
4191 | } | 4250 | } |
4192 | 4251 | ||
4193 | 4252 | ||
4194 | /** | 4253 | /** |
4195 | * Core handle for p2p trail setup result messages. | 4254 | * Core handle for p2p trail setup result messages. |
@@ -4198,7 +4257,7 @@ check_dht_p2p_trail_setup_result (void *cls, | |||
4198 | * @param trail_result the message | 4257 | * @param trail_result the message |
4199 | */ | 4258 | */ |
4200 | static void | 4259 | static void |
4201 | handle_dht_p2p_trail_setup_result (void *cls, | 4260 | handle_dht_p2p_trail_setup_result (void *cls, |
4202 | const struct PeerTrailSetupResultMessage *trail_result) | 4261 | const struct PeerTrailSetupResultMessage *trail_result) |
4203 | { | 4262 | { |
4204 | struct FriendInfo *friend = cls; | 4263 | struct FriendInfo *friend = cls; |
@@ -4228,7 +4287,7 @@ handle_dht_p2p_trail_setup_result (void *cls, | |||
4228 | finger_identity = trail_result->finger_identity; | 4287 | finger_identity = trail_result->finger_identity; |
4229 | trail_id = trail_result->trail_id; | 4288 | trail_id = trail_result->trail_id; |
4230 | trail_peer_list = (const struct GNUNET_PeerIdentity *) &trail_result[1]; | 4289 | trail_peer_list = (const struct GNUNET_PeerIdentity *) &trail_result[1]; |
4231 | ultimate_destination_finger_value | 4290 | ultimate_destination_finger_value |
4232 | = GNUNET_ntohll (trail_result->ultimate_destination_finger_value); | 4291 | = GNUNET_ntohll (trail_result->ultimate_destination_finger_value); |
4233 | 4292 | ||
4234 | /* Am I the one who initiated the query? */ | 4293 | /* Am I the one who initiated the query? */ |
@@ -4314,7 +4373,7 @@ handle_dht_p2p_trail_setup_result (void *cls, | |||
4314 | GDS_NEIGHBOURS_send_trail_setup_result (&querying_peer, | 4373 | GDS_NEIGHBOURS_send_trail_setup_result (&querying_peer, |
4315 | &finger_identity, | 4374 | &finger_identity, |
4316 | target_friend, | 4375 | target_friend, |
4317 | trail_length, | 4376 | trail_length, |
4318 | trail_peer_list, | 4377 | trail_peer_list, |
4319 | is_predecessor, | 4378 | is_predecessor, |
4320 | ultimate_destination_finger_value, | 4379 | ultimate_destination_finger_value, |
@@ -4569,7 +4628,7 @@ get_trail_src_to_curr_pred (struct GNUNET_PeerIdentity source_peer, | |||
4569 | *trail_src_to_curr_pred_length = trail_me_to_curr_pred_length - i; | 4628 | *trail_src_to_curr_pred_length = trail_me_to_curr_pred_length - i; |
4570 | trail_src_to_curr_pred = GNUNET_new_array (*trail_src_to_curr_pred_length, | 4629 | trail_src_to_curr_pred = GNUNET_new_array (*trail_src_to_curr_pred_length, |
4571 | struct GNUNET_PeerIdentity); | 4630 | struct GNUNET_PeerIdentity); |
4572 | 4631 | ||
4573 | 4632 | ||
4574 | for (j = 0; j < *trail_src_to_curr_pred_length; i++,j++) | 4633 | for (j = 0; j < *trail_src_to_curr_pred_length; i++,j++) |
4575 | trail_src_to_curr_pred[j] = trail_me_to_curr_pred[i]; | 4634 | trail_src_to_curr_pred[j] = trail_me_to_curr_pred[i]; |
@@ -4821,7 +4880,7 @@ handle_dht_p2p_verify_successor (void *cls, | |||
4821 | if (0 != (GNUNET_CRYPTO_cmp_peer_identity (¤t_predecessor.finger_identity, | 4880 | if (0 != (GNUNET_CRYPTO_cmp_peer_identity (¤t_predecessor.finger_identity, |
4822 | &source_peer))) | 4881 | &source_peer))) |
4823 | { | 4882 | { |
4824 | trail_src_to_curr_pred | 4883 | trail_src_to_curr_pred |
4825 | = get_trail_src_to_curr_pred (source_peer, | 4884 | = get_trail_src_to_curr_pred (source_peer, |
4826 | trail, | 4885 | trail, |
4827 | trail_length, | 4886 | trail_length, |
@@ -4832,7 +4891,7 @@ handle_dht_p2p_verify_successor (void *cls, | |||
4832 | trail_src_to_curr_pred_len = trail_length; | 4891 | trail_src_to_curr_pred_len = trail_length; |
4833 | trail_src_to_curr_pred = GNUNET_new_array (trail_src_to_curr_pred_len, | 4892 | trail_src_to_curr_pred = GNUNET_new_array (trail_src_to_curr_pred_len, |
4834 | struct GNUNET_PeerIdentity); | 4893 | struct GNUNET_PeerIdentity); |
4835 | 4894 | ||
4836 | for (unsigned int i = 0; i < trail_src_to_curr_pred_len; i++) | 4895 | for (unsigned int i = 0; i < trail_src_to_curr_pred_len; i++) |
4837 | { | 4896 | { |
4838 | trail_src_to_curr_pred[i] = trail[i]; | 4897 | trail_src_to_curr_pred[i] = trail[i]; |
@@ -5175,7 +5234,7 @@ check_dht_p2p_verify_successor_result (void *cls, | |||
5175 | static void | 5234 | static void |
5176 | handle_dht_p2p_verify_successor_result (void *cls, | 5235 | handle_dht_p2p_verify_successor_result (void *cls, |
5177 | const struct PeerVerifySuccessorResultMessage *vsrm) | 5236 | const struct PeerVerifySuccessorResultMessage *vsrm) |
5178 | { | 5237 | { |
5179 | enum GDS_ROUTING_trail_direction trail_direction; | 5238 | enum GDS_ROUTING_trail_direction trail_direction; |
5180 | struct GNUNET_PeerIdentity querying_peer; | 5239 | struct GNUNET_PeerIdentity querying_peer; |
5181 | struct GNUNET_HashCode trail_id; | 5240 | struct GNUNET_HashCode trail_id; |
@@ -5211,7 +5270,7 @@ handle_dht_p2p_verify_successor_result (void *cls, | |||
5211 | if (NULL != send_verify_successor_retry_task) | 5270 | if (NULL != send_verify_successor_retry_task) |
5212 | { | 5271 | { |
5213 | struct VerifySuccessorContext *ctx; | 5272 | struct VerifySuccessorContext *ctx; |
5214 | 5273 | ||
5215 | ctx = GNUNET_SCHEDULER_cancel (send_verify_successor_retry_task); | 5274 | ctx = GNUNET_SCHEDULER_cancel (send_verify_successor_retry_task); |
5216 | GNUNET_free (ctx); | 5275 | GNUNET_free (ctx); |
5217 | send_verify_successor_retry_task = NULL; | 5276 | send_verify_successor_retry_task = NULL; |
@@ -5277,7 +5336,7 @@ check_dht_p2p_notify_new_successor (void *cls, | |||
5277 | return GNUNET_OK; | 5336 | return GNUNET_OK; |
5278 | } | 5337 | } |
5279 | 5338 | ||
5280 | 5339 | ||
5281 | /** | 5340 | /** |
5282 | * Core handle for p2p notify new successor messages. | 5341 | * Core handle for p2p notify new successor messages. |
5283 | * | 5342 | * |
@@ -5387,7 +5446,7 @@ handle_dht_p2p_notify_succ_confirmation (void *cls, | |||
5387 | struct GNUNET_HashCode trail_id; | 5446 | struct GNUNET_HashCode trail_id; |
5388 | struct FriendInfo *target_friend; | 5447 | struct FriendInfo *target_friend; |
5389 | const struct GNUNET_PeerIdentity *next_hop; | 5448 | const struct GNUNET_PeerIdentity *next_hop; |
5390 | 5449 | ||
5391 | GNUNET_STATISTICS_update (GDS_stats, | 5450 | GNUNET_STATISTICS_update (GDS_stats, |
5392 | gettext_noop ("# Bytes received from other peers"), | 5451 | gettext_noop ("# Bytes received from other peers"), |
5393 | ntohs (notify_confirmation->header.size), | 5452 | ntohs (notify_confirmation->header.size), |
@@ -5431,7 +5490,7 @@ handle_dht_p2p_notify_succ_confirmation (void *cls, | |||
5431 | DHT_SEND_VERIFY_SUCCESSOR_INTERVAL.rel_value_us + | 5490 | DHT_SEND_VERIFY_SUCCESSOR_INTERVAL.rel_value_us + |
5432 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 5491 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
5433 | DHT_SEND_VERIFY_SUCCESSOR_INTERVAL.rel_value_us); | 5492 | DHT_SEND_VERIFY_SUCCESSOR_INTERVAL.rel_value_us); |
5434 | send_verify_successor_task | 5493 | send_verify_successor_task |
5435 | = GNUNET_SCHEDULER_add_delayed(verify_successor_next_send_time, | 5494 | = GNUNET_SCHEDULER_add_delayed(verify_successor_next_send_time, |
5436 | &send_verify_successor_message, | 5495 | &send_verify_successor_message, |
5437 | NULL); | 5496 | NULL); |
@@ -5476,7 +5535,7 @@ check_dht_p2p_trail_setup_rejection (void *cls, | |||
5476 | } | 5535 | } |
5477 | return GNUNET_OK; | 5536 | return GNUNET_OK; |
5478 | } | 5537 | } |
5479 | 5538 | ||
5480 | 5539 | ||
5481 | /** | 5540 | /** |
5482 | * Core handler for P2P trail rejection message | 5541 | * Core handler for P2P trail rejection message |
@@ -5487,7 +5546,7 @@ check_dht_p2p_trail_setup_rejection (void *cls, | |||
5487 | static void | 5546 | static void |
5488 | handle_dht_p2p_trail_setup_rejection (void *cls, | 5547 | handle_dht_p2p_trail_setup_rejection (void *cls, |
5489 | const struct PeerTrailRejectionMessage *trail_rejection) | 5548 | const struct PeerTrailRejectionMessage *trail_rejection) |
5490 | { | 5549 | { |
5491 | struct FriendInfo *friend = cls; | 5550 | struct FriendInfo *friend = cls; |
5492 | unsigned int trail_length; | 5551 | unsigned int trail_length; |
5493 | const struct GNUNET_PeerIdentity *trail_peer_list; | 5552 | const struct GNUNET_PeerIdentity *trail_peer_list; |
@@ -5514,7 +5573,7 @@ handle_dht_p2p_trail_setup_rejection (void *cls, | |||
5514 | congestion_timeout = trail_rejection->congestion_time; | 5573 | congestion_timeout = trail_rejection->congestion_time; |
5515 | source = trail_rejection->source_peer; | 5574 | source = trail_rejection->source_peer; |
5516 | trail_id = trail_rejection->trail_id; | 5575 | trail_id = trail_rejection->trail_id; |
5517 | ultimate_destination_finger_value | 5576 | ultimate_destination_finger_value |
5518 | = GNUNET_ntohll (trail_rejection->ultimate_destination_finger_value); | 5577 | = GNUNET_ntohll (trail_rejection->ultimate_destination_finger_value); |
5519 | /* First set the congestion time of the friend that sent you this message. */ | 5578 | /* First set the congestion time of the friend that sent you this message. */ |
5520 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 5579 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
@@ -5525,7 +5584,7 @@ handle_dht_p2p_trail_setup_rejection (void *cls, | |||
5525 | GNUNET_break(0); | 5584 | GNUNET_break(0); |
5526 | return; | 5585 | return; |
5527 | } | 5586 | } |
5528 | target_friend->congestion_timestamp | 5587 | target_friend->congestion_timestamp |
5529 | = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(), | 5588 | = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(), |
5530 | congestion_timeout); | 5589 | congestion_timeout); |
5531 | 5590 | ||
@@ -5549,7 +5608,7 @@ handle_dht_p2p_trail_setup_rejection (void *cls, | |||
5549 | else | 5608 | else |
5550 | next_peer = trail[new_trail_length-1]; | 5609 | next_peer = trail[new_trail_length-1]; |
5551 | 5610 | ||
5552 | target_friend | 5611 | target_friend |
5553 | = GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 5612 | = GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
5554 | &next_peer); | 5613 | &next_peer); |
5555 | if (NULL == target_friend) | 5614 | if (NULL == target_friend) |
@@ -5640,7 +5699,7 @@ handle_dht_p2p_trail_setup_rejection (void *cls, | |||
5640 | * @param trail_teardown the message | 5699 | * @param trail_teardown the message |
5641 | */ | 5700 | */ |
5642 | static void | 5701 | static void |
5643 | handle_dht_p2p_trail_teardown (void *cls, | 5702 | handle_dht_p2p_trail_teardown (void *cls, |
5644 | const struct PeerTrailTearDownMessage *trail_teardown) | 5703 | const struct PeerTrailTearDownMessage *trail_teardown) |
5645 | { | 5704 | { |
5646 | enum GDS_ROUTING_trail_direction trail_direction; | 5705 | enum GDS_ROUTING_trail_direction trail_direction; |
@@ -5707,7 +5766,7 @@ handle_dht_p2p_trail_teardown (void *cls, | |||
5707 | * @return #GNUNET_OK if @a add_trail is well-formed | 5766 | * @return #GNUNET_OK if @a add_trail is well-formed |
5708 | */ | 5767 | */ |
5709 | static int | 5768 | static int |
5710 | check_dht_p2p_add_trail (void *cls, | 5769 | check_dht_p2p_add_trail (void *cls, |
5711 | const struct PeerAddTrailMessage *add_trail) | 5770 | const struct PeerAddTrailMessage *add_trail) |
5712 | { | 5771 | { |
5713 | size_t msize; | 5772 | size_t msize; |
@@ -5730,9 +5789,9 @@ check_dht_p2p_add_trail (void *cls, | |||
5730 | * @param add_trail the message | 5789 | * @param add_trail the message |
5731 | */ | 5790 | */ |
5732 | static void | 5791 | static void |
5733 | handle_dht_p2p_add_trail (void *cls, | 5792 | handle_dht_p2p_add_trail (void *cls, |
5734 | const struct PeerAddTrailMessage *add_trail) | 5793 | const struct PeerAddTrailMessage *add_trail) |
5735 | { | 5794 | { |
5736 | struct FriendInfo *friend = cls; | 5795 | struct FriendInfo *friend = cls; |
5737 | const struct GNUNET_PeerIdentity *trail; | 5796 | const struct GNUNET_PeerIdentity *trail; |
5738 | struct GNUNET_HashCode trail_id; | 5797 | struct GNUNET_HashCode trail_id; |
@@ -6183,7 +6242,7 @@ GDS_NEIGHBOURS_done (void) | |||
6183 | if (NULL != send_notify_new_successor_retry_task) | 6242 | if (NULL != send_notify_new_successor_retry_task) |
6184 | { | 6243 | { |
6185 | struct SendNotifyContext *notify_ctx; | 6244 | struct SendNotifyContext *notify_ctx; |
6186 | 6245 | ||
6187 | notify_ctx = GNUNET_SCHEDULER_cancel (send_notify_new_successor_retry_task); | 6246 | notify_ctx = GNUNET_SCHEDULER_cancel (send_notify_new_successor_retry_task); |
6188 | GNUNET_free (notify_ctx->successor_trail); | 6247 | GNUNET_free (notify_ctx->successor_trail); |
6189 | GNUNET_free (notify_ctx); | 6248 | GNUNET_free (notify_ctx); |
@@ -6197,10 +6256,10 @@ GDS_NEIGHBOURS_done (void) | |||
6197 | * | 6256 | * |
6198 | * @return my identity | 6257 | * @return my identity |
6199 | */ | 6258 | */ |
6200 | struct GNUNET_PeerIdentity | 6259 | struct GNUNET_PeerIdentity * |
6201 | GDS_NEIGHBOURS_get_my_id (void) | 6260 | GDS_NEIGHBOURS_get_id (void) |
6202 | { | 6261 | { |
6203 | return my_identity; | 6262 | return &my_identity; |
6204 | } | 6263 | } |
6205 | 6264 | ||
6206 | /* end of gnunet-service-xdht_neighbours.c */ | 6265 | /* end of gnunet-service-xdht_neighbours.c */ |