diff options
author | Supriti Singh <supritisingh08@gmail.com> | 2014-06-23 09:32:01 +0000 |
---|---|---|
committer | Supriti Singh <supritisingh08@gmail.com> | 2014-06-23 09:32:01 +0000 |
commit | 8db86bd4418dd3f17c635df117153c14941a4366 (patch) | |
tree | e6fbc89af9f4357ab9f7d7c919cba114376b0ebe /src | |
parent | 737db6486404cbb5a9bb0f0918dcfc211a8b6066 (diff) | |
download | gnunet-8db86bd4418dd3f17c635df117153c14941a4366.tar.gz gnunet-8db86bd4418dd3f17c635df117153c14941a4366.zip |
xvine: minor fixes
Diffstat (limited to 'src')
-rw-r--r-- | src/dht/gnunet-service-xdht_datacache.c | 1 | ||||
-rw-r--r-- | src/dht/gnunet-service-xdht_neighbours.c | 137 | ||||
-rw-r--r-- | src/dht/gnunet-service-xdht_neighbours.h | 2 |
3 files changed, 85 insertions, 55 deletions
diff --git a/src/dht/gnunet-service-xdht_datacache.c b/src/dht/gnunet-service-xdht_datacache.c index 5f35f088b..da8377500 100644 --- a/src/dht/gnunet-service-xdht_datacache.c +++ b/src/dht/gnunet-service-xdht_datacache.c | |||
@@ -225,7 +225,6 @@ datacache_get_iterator (void *cls, | |||
225 | i++; | 225 | i++; |
226 | iterator = iterator->next; | 226 | iterator = iterator->next; |
227 | } | 227 | } |
228 | |||
229 | 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), |
230 | put_path_length, put_path, ctx->get_path_length, | 229 | put_path_length, put_path, ctx->get_path_length, |
231 | get_path, exp, data, size ); | 230 | get_path, exp, data, size ); |
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c index a0b1c378f..d0a6d0955 100644 --- a/src/dht/gnunet-service-xdht_neighbours.c +++ b/src/dht/gnunet-service-xdht_neighbours.c | |||
@@ -1674,6 +1674,11 @@ select_closest_finger (struct GNUNET_PeerIdentity *peer1, | |||
1674 | 1674 | ||
1675 | memcpy (&peer1_value, peer1, sizeof (uint64_t)); | 1675 | memcpy (&peer1_value, peer1, sizeof (uint64_t)); |
1676 | memcpy (&peer2_value, peer2, sizeof (uint64_t)); | 1676 | memcpy (&peer2_value, peer2, sizeof (uint64_t)); |
1677 | peer1_value = GNUNET_ntohll (peer1_value); | ||
1678 | peer2_value = GNUNET_ntohll (peer2_value); | ||
1679 | value = GNUNET_ntohll (value); //FIXME: Is it correct to do it here? | ||
1680 | // we do it when we get from the network. | ||
1681 | |||
1677 | if (peer1_value == value) | 1682 | if (peer1_value == value) |
1678 | { | 1683 | { |
1679 | return peer1; | 1684 | return peer1; |
@@ -1739,6 +1744,8 @@ select_closest_predecessor (struct GNUNET_PeerIdentity *peer1, | |||
1739 | 1744 | ||
1740 | memcpy (&peer1_value, peer1, sizeof (uint64_t)); | 1745 | memcpy (&peer1_value, peer1, sizeof (uint64_t)); |
1741 | memcpy (&peer2_value, peer2, sizeof (uint64_t)); | 1746 | memcpy (&peer2_value, peer2, sizeof (uint64_t)); |
1747 | peer1_value = GNUNET_ntohll (peer1_value); | ||
1748 | peer2_value = GNUNET_ntohll (peer2_value); | ||
1742 | 1749 | ||
1743 | if (peer1_value == value) | 1750 | if (peer1_value == value) |
1744 | return peer1; | 1751 | return peer1; |
@@ -1805,6 +1812,7 @@ select_closest_peer (struct GNUNET_PeerIdentity *peer1, | |||
1805 | unsigned int finger_table_index) | 1812 | unsigned int finger_table_index) |
1806 | { | 1813 | { |
1807 | struct GNUNET_PeerIdentity *closest_peer; | 1814 | struct GNUNET_PeerIdentity *closest_peer; |
1815 | |||
1808 | /* FIXME: select closest peer w.r.t. value. [friend_id, current_successor->id) | 1816 | /* FIXME: select closest peer w.r.t. value. [friend_id, current_successor->id) |
1809 | and [current_successor->id, friend_id). Check in which range value lies. | 1817 | and [current_successor->id, friend_id). Check in which range value lies. |
1810 | Also, check for wrap around. Set the value of current_successor accordingly.*/ | 1818 | Also, check for wrap around. Set the value of current_successor accordingly.*/ |
@@ -1818,6 +1826,8 @@ select_closest_peer (struct GNUNET_PeerIdentity *peer1, | |||
1818 | 1826 | ||
1819 | 1827 | ||
1820 | /** | 1828 | /** |
1829 | * FIXME: free every memory allocated using malloc before the function ends | ||
1830 | * i.e. trail. | ||
1821 | * FIXME: better names and more refactoring. | 1831 | * FIXME: better names and more refactoring. |
1822 | * Compare FINGER entry with current successor. If finger's first friend of all | 1832 | * Compare FINGER entry with current successor. If finger's first friend of all |
1823 | * its trail is not congested and has not crossed trail threshold, then check | 1833 | * its trail is not congested and has not crossed trail threshold, then check |
@@ -1841,7 +1851,7 @@ compare_finger_and_current_successor (struct Closest_Peer *current_closest_peer) | |||
1841 | 1851 | ||
1842 | if (GNUNET_NO == finger->is_present) | 1852 | if (GNUNET_NO == finger->is_present) |
1843 | continue; | 1853 | continue; |
1844 | 1854 | ||
1845 | /* If my identity is same as current closest peer then don't consider me*/ | 1855 | /* If my identity is same as current closest peer then don't consider me*/ |
1846 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity, | 1856 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity, |
1847 | ¤t_closest_peer->best_known_destination)) | 1857 | ¤t_closest_peer->best_known_destination)) |
@@ -1923,7 +1933,7 @@ compare_friend_and_current_closest_peer (void *cls, | |||
1923 | 1933 | ||
1924 | if (GNUNET_YES == is_friend_congested (friend)) | 1934 | if (GNUNET_YES == is_friend_congested (friend)) |
1925 | return GNUNET_YES; | 1935 | return GNUNET_YES; |
1926 | 1936 | ||
1927 | if (0 == | 1937 | if (0 == |
1928 | GNUNET_CRYPTO_cmp_peer_identity (&friend->id, | 1938 | GNUNET_CRYPTO_cmp_peer_identity (&friend->id, |
1929 | ¤t_closest_peer->best_known_destination)) | 1939 | ¤t_closest_peer->best_known_destination)) |
@@ -2057,9 +2067,9 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key, | |||
2057 | struct P2PPendingMessage *pending; | 2067 | struct P2PPendingMessage *pending; |
2058 | struct FriendInfo *target_friend; | 2068 | struct FriendInfo *target_friend; |
2059 | struct GNUNET_PeerIdentity *pp; | 2069 | struct GNUNET_PeerIdentity *pp; |
2060 | struct GNUNET_PeerIdentity *local_best_known_dest; | 2070 | struct GNUNET_PeerIdentity local_best_known_dest; |
2061 | size_t msize; | 2071 | size_t msize; |
2062 | 2072 | ||
2063 | msize = put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size + | 2073 | msize = put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size + |
2064 | sizeof (struct PeerPutMessage); | 2074 | sizeof (struct PeerPutMessage); |
2065 | 2075 | ||
@@ -2082,12 +2092,10 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key, | |||
2082 | uint64_t key_value; | 2092 | uint64_t key_value; |
2083 | struct GNUNET_PeerIdentity *next_hop; | 2093 | struct GNUNET_PeerIdentity *next_hop; |
2084 | 2094 | ||
2085 | memcpy (&key_value, key, sizeof (uint64_t)); | 2095 | memcpy (&key_value, key, sizeof (uint64_t)); |
2086 | local_best_known_dest = GNUNET_new (struct GNUNET_PeerIdentity); | 2096 | next_hop = find_successor (key_value, &local_best_known_dest, |
2087 | |||
2088 | next_hop = find_successor (key_value, local_best_known_dest, | ||
2089 | intermediate_trail_id, GDS_FINGER_TYPE_NON_PREDECESSOR); | 2097 | intermediate_trail_id, GDS_FINGER_TYPE_NON_PREDECESSOR); |
2090 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (local_best_known_dest, &my_identity)) | 2098 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&local_best_known_dest, &my_identity)) |
2091 | { | 2099 | { |
2092 | /* I am the destination but we have already done datacache_put in client file. */ | 2100 | /* I am the destination but we have already done datacache_put in client file. */ |
2093 | return; | 2101 | return; |
@@ -2112,7 +2120,7 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key, | |||
2112 | ppm->put_path_length = htonl (put_path_length); | 2120 | ppm->put_path_length = htonl (put_path_length); |
2113 | ppm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time); | 2121 | ppm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time); |
2114 | if (NULL == best_known_dest) | 2122 | if (NULL == best_known_dest) |
2115 | ppm->best_known_destination = *local_best_known_dest; | 2123 | ppm->best_known_destination = local_best_known_dest; |
2116 | else | 2124 | else |
2117 | ppm->best_known_destination = *best_known_dest; | 2125 | ppm->best_known_destination = *best_known_dest; |
2118 | ppm->key = *key; | 2126 | ppm->key = *key; |
@@ -2133,15 +2141,16 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key, | |||
2133 | } | 2141 | } |
2134 | 2142 | ||
2135 | 2143 | ||
2136 | |||
2137 | /** | 2144 | /** |
2138 | * Construct a Get message and send it to target_peer. | 2145 | * Construct a Get message and send it to target_peer. |
2139 | * @param key Key for the content | 2146 | * @param key Key for the content |
2140 | * @param block_type Type of the block | 2147 | * @param block_type Type of the block |
2141 | * @param options Routing options | 2148 | * @param options Routing options |
2142 | * @param desired_replication_level Desired replication count | 2149 | * @param desired_replication_level Desired replication count |
2143 | * @param best_known_dest | 2150 | * @param best_known_dest Peer which should get this message. Same as target peer |
2144 | * @param intermediate_trail_id | 2151 | * if best_known_dest is a friend else its a finger. |
2152 | * @param intermediate_trail_id Trail id to reach to @a best_known_dest | ||
2153 | * in case it is a finger else set to 0. | ||
2145 | * @param target_peer Peer to which this message will be forwarded. | 2154 | * @param target_peer Peer to which this message will be forwarded. |
2146 | * @param hop_count Number of hops traversed so far. | 2155 | * @param hop_count Number of hops traversed so far. |
2147 | * @param data Content to store | 2156 | * @param data Content to store |
@@ -2154,7 +2163,7 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key, | |||
2154 | enum GNUNET_BLOCK_Type block_type, | 2163 | enum GNUNET_BLOCK_Type block_type, |
2155 | enum GNUNET_DHT_RouteOption options, | 2164 | enum GNUNET_DHT_RouteOption options, |
2156 | uint32_t desired_replication_level, | 2165 | uint32_t desired_replication_level, |
2157 | struct GNUNET_PeerIdentity *best_known_dest, | 2166 | const struct GNUNET_PeerIdentity *best_known_dest, |
2158 | struct GNUNET_HashCode *intermediate_trail_id, | 2167 | struct GNUNET_HashCode *intermediate_trail_id, |
2159 | struct GNUNET_PeerIdentity *target_peer, | 2168 | struct GNUNET_PeerIdentity *target_peer, |
2160 | uint32_t hop_count, | 2169 | uint32_t hop_count, |
@@ -2164,31 +2173,40 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key, | |||
2164 | struct PeerGetMessage *pgm; | 2173 | struct PeerGetMessage *pgm; |
2165 | struct P2PPendingMessage *pending; | 2174 | struct P2PPendingMessage *pending; |
2166 | struct FriendInfo *target_friend; | 2175 | struct FriendInfo *target_friend; |
2167 | struct GNUNET_PeerIdentity *local_best_known_dest; | 2176 | struct GNUNET_PeerIdentity local_best_known_dest; |
2168 | struct GNUNET_PeerIdentity *gp; | 2177 | struct GNUNET_PeerIdentity *gp; |
2169 | size_t msize; | 2178 | size_t msize; |
2170 | 2179 | ||
2171 | msize = sizeof (struct PeerGetMessage) + | 2180 | msize = sizeof (struct PeerGetMessage) + |
2172 | (get_path_length * sizeof (struct GNUNET_PeerIdentity)); | 2181 | (get_path_length * sizeof (struct GNUNET_PeerIdentity)); |
2173 | 2182 | ||
2174 | if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 2183 | if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
2175 | { | 2184 | { |
2185 | get_path_length = 0; | ||
2186 | msize = sizeof (struct PeerPutMessage); | ||
2187 | } | ||
2188 | |||
2189 | if (msize > GNUNET_SERVER_MAX_MESSAGE_SIZE) | ||
2190 | { | ||
2176 | GNUNET_break (0); | 2191 | GNUNET_break (0); |
2177 | return; | 2192 | return; |
2178 | } | 2193 | } |
2179 | 2194 | ||
2195 | /* This is the first time we got request from our own client file. */ | ||
2180 | if (NULL == target_peer) | 2196 | if (NULL == target_peer) |
2181 | { | 2197 | { |
2182 | struct GNUNET_PeerIdentity *next_hop; | 2198 | struct GNUNET_PeerIdentity *next_hop; |
2183 | uint64_t key_value; | 2199 | uint64_t key_value; |
2184 | 2200 | ||
2185 | memcpy (&key_value, key, sizeof (uint64_t)); | 2201 | memcpy (&key_value, key, sizeof (uint64_t)); //FIXME: endianess of key? |
2186 | // FIXME: endianess of key_value!? | ||
2187 | local_best_known_dest = GNUNET_new (struct GNUNET_PeerIdentity); | ||
2188 | next_hop = find_successor (key_value, local_best_known_dest, | ||
2189 | intermediate_trail_id, GDS_FINGER_TYPE_NON_PREDECESSOR); | ||
2190 | 2202 | ||
2191 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity,next_hop)) | 2203 | /* Find the next destination to forward the packet. */ |
2204 | next_hop = find_successor (key_value, &local_best_known_dest, | ||
2205 | intermediate_trail_id, GDS_FINGER_TYPE_NON_PREDECESSOR); | ||
2206 | |||
2207 | /* I am the destination. I have the data. */ | ||
2208 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, | ||
2209 | &local_best_known_dest)) | ||
2192 | { | 2210 | { |
2193 | GDS_DATACACHE_handle_get (key,block_type, NULL, 0, | 2211 | GDS_DATACACHE_handle_get (key,block_type, NULL, 0, |
2194 | NULL, 0, 1, &my_identity, NULL,&my_identity); | 2212 | NULL, 0, 1, &my_identity, NULL,&my_identity); |
@@ -2201,6 +2219,7 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key, | |||
2201 | } | 2219 | } |
2202 | else | 2220 | else |
2203 | { | 2221 | { |
2222 | local_best_known_dest = *best_known_dest; | ||
2204 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer); | 2223 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer); |
2205 | } | 2224 | } |
2206 | 2225 | ||
@@ -2211,11 +2230,7 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key, | |||
2211 | pgm->header.size = htons (msize); | 2230 | pgm->header.size = htons (msize); |
2212 | pgm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_GET); | 2231 | pgm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_GET); |
2213 | pgm->get_path_length = htonl (get_path_length); | 2232 | pgm->get_path_length = htonl (get_path_length); |
2214 | pgm->key = *key; | 2233 | pgm->best_known_destination = local_best_known_dest; |
2215 | if (NULL != best_known_dest) | ||
2216 | pgm->best_known_destination = *best_known_dest; | ||
2217 | else | ||
2218 | pgm->best_known_destination = *local_best_known_dest; | ||
2219 | 2234 | ||
2220 | if (NULL == intermediate_trail_id) | 2235 | if (NULL == intermediate_trail_id) |
2221 | memset (&pgm->intermediate_trail_id, 0, sizeof (pgm->intermediate_trail_id)); | 2236 | memset (&pgm->intermediate_trail_id, 0, sizeof (pgm->intermediate_trail_id)); |
@@ -2223,7 +2238,7 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key, | |||
2223 | pgm->intermediate_trail_id = *intermediate_trail_id; | 2238 | pgm->intermediate_trail_id = *intermediate_trail_id; |
2224 | pgm->hop_count = htonl (hop_count + 1); | 2239 | pgm->hop_count = htonl (hop_count + 1); |
2225 | 2240 | ||
2226 | if (get_path != 0) | 2241 | if (get_path_length != 0) |
2227 | { | 2242 | { |
2228 | gp = (struct GNUNET_PeerIdentity *) &pgm[1]; | 2243 | gp = (struct GNUNET_PeerIdentity *) &pgm[1]; |
2229 | memcpy (gp, get_path, get_path_length * sizeof (struct GNUNET_PeerIdentity)); | 2244 | memcpy (gp, get_path, get_path_length * sizeof (struct GNUNET_PeerIdentity)); |
@@ -2305,9 +2320,8 @@ GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *key, | |||
2305 | the get_result documentation. */ | 2320 | the get_result documentation. */ |
2306 | memcpy (&(get_result->querying_peer), source_peer, sizeof (struct GNUNET_PeerIdentity)); | 2321 | memcpy (&(get_result->querying_peer), source_peer, sizeof (struct GNUNET_PeerIdentity)); |
2307 | get_result->expiration_time = expiration; | 2322 | get_result->expiration_time = expiration; |
2308 | |||
2309 | |||
2310 | get_result_path = (struct GNUNET_PeerIdentity *)&get_result[1]; | 2323 | get_result_path = (struct GNUNET_PeerIdentity *)&get_result[1]; |
2324 | if (get_path_length != 0) | ||
2311 | memcpy (get_result_path, get_path, | 2325 | memcpy (get_result_path, get_path, |
2312 | sizeof (struct GNUNET_PeerIdentity) * get_path_length); | 2326 | sizeof (struct GNUNET_PeerIdentity) * get_path_length); |
2313 | memcpy (&get_result_path[get_path_length], data, data_size); | 2327 | memcpy (&get_result_path[get_path_length], data, data_size); |
@@ -2449,7 +2463,7 @@ send_find_finger_trail_message (void *cls, | |||
2449 | { | 2463 | { |
2450 | return; | 2464 | return; |
2451 | } | 2465 | } |
2452 | 2466 | ||
2453 | finger_id_value = compute_finger_identity_value (current_search_finger_index); | 2467 | finger_id_value = compute_finger_identity_value (current_search_finger_index); |
2454 | if (PREDECESSOR_FINGER_ID == current_search_finger_index) | 2468 | if (PREDECESSOR_FINGER_ID == current_search_finger_index) |
2455 | is_predecessor = 1; | 2469 | is_predecessor = 1; |
@@ -2808,6 +2822,7 @@ add_new_finger (struct GNUNET_PeerIdentity finger_identity, | |||
2808 | new_entry->trail_list[0].trail_id = trail_id; | 2822 | new_entry->trail_list[0].trail_id = trail_id; |
2809 | new_entry->trail_list[0].is_present = GNUNET_YES; | 2823 | new_entry->trail_list[0].is_present = GNUNET_YES; |
2810 | finger_table[finger_table_index] = *new_entry; | 2824 | finger_table[finger_table_index] = *new_entry; |
2825 | GNUNET_free (new_entry); | ||
2811 | return; | 2826 | return; |
2812 | } | 2827 | } |
2813 | 2828 | ||
@@ -2957,7 +2972,7 @@ send_verify_successor_message (struct FingerInfo *successor) | |||
2957 | struct Trail *trail; | 2972 | struct Trail *trail; |
2958 | struct Trail_Element *element; | 2973 | struct Trail_Element *element; |
2959 | unsigned int trail_length; | 2974 | unsigned int trail_length; |
2960 | int j; | 2975 | int j = 0; |
2961 | 2976 | ||
2962 | trail = &successor->trail_list[i]; | 2977 | trail = &successor->trail_list[i]; |
2963 | 2978 | ||
@@ -3218,8 +3233,10 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity, | |||
3218 | int updated_finger_trail_length; | 3233 | int updated_finger_trail_length; |
3219 | unsigned int finger_table_index; | 3234 | unsigned int finger_table_index; |
3220 | 3235 | ||
3221 | //test_friend_peermap_print(); | 3236 | #if 0 |
3222 | //test_finger_table_print(); | 3237 | test_friend_peermap_print(); |
3238 | test_finger_table_print(); | ||
3239 | #endif | ||
3223 | 3240 | ||
3224 | /* Get the finger_table_index corresponding to finger_value we got from network.*/ | 3241 | /* Get the finger_table_index corresponding to finger_value we got from network.*/ |
3225 | finger_table_index = get_finger_table_index (finger_value, is_predecessor); | 3242 | finger_table_index = get_finger_table_index (finger_value, is_predecessor); |
@@ -3230,7 +3247,7 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity, | |||
3230 | GNUNET_break_op (0); | 3247 | GNUNET_break_op (0); |
3231 | return; | 3248 | return; |
3232 | } | 3249 | } |
3233 | 3250 | ||
3234 | updated_finger_trail_length = finger_trail_length; | 3251 | updated_finger_trail_length = finger_trail_length; |
3235 | updated_trail = | 3252 | updated_trail = |
3236 | scan_and_compress_trail (finger_identity, finger_trail, | 3253 | scan_and_compress_trail (finger_identity, finger_trail, |
@@ -3318,7 +3335,7 @@ static int | |||
3318 | handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, | 3335 | handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, |
3319 | const struct GNUNET_MessageHeader *message) | 3336 | const struct GNUNET_MessageHeader *message) |
3320 | { | 3337 | { |
3321 | struct PeerPutMessage *put; | 3338 | struct PeerPutMessage *put; |
3322 | struct GNUNET_PeerIdentity *put_path; | 3339 | struct GNUNET_PeerIdentity *put_path; |
3323 | struct GNUNET_HashCode test_key; | 3340 | struct GNUNET_HashCode test_key; |
3324 | enum GNUNET_DHT_RouteOption options; | 3341 | enum GNUNET_DHT_RouteOption options; |
@@ -3450,7 +3467,7 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3450 | payload, | 3467 | payload, |
3451 | payload_size); | 3468 | payload_size); |
3452 | 3469 | ||
3453 | if (0 == GNUNET_CRYPTO_cmp_peer_identity(&my_identity, next_hop)) /* I am the final destination */ | 3470 | if (0 == GNUNET_CRYPTO_cmp_peer_identity(&my_identity, &best_known_dest)) /* I am the final destination */ |
3454 | { | 3471 | { |
3455 | GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (put->expiration_time), | 3472 | GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (put->expiration_time), |
3456 | &(put->key),putlen, pp, ntohl (put->block_type), | 3473 | &(put->key),putlen, pp, ntohl (put->block_type), |
@@ -3486,8 +3503,8 @@ static int | |||
3486 | handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | 3503 | handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, |
3487 | const struct GNUNET_MessageHeader *message) | 3504 | const struct GNUNET_MessageHeader *message) |
3488 | { | 3505 | { |
3489 | struct PeerGetMessage *get; | 3506 | const struct PeerGetMessage *get; |
3490 | struct GNUNET_PeerIdentity *get_path; | 3507 | const struct GNUNET_PeerIdentity *get_path; |
3491 | struct GNUNET_PeerIdentity best_known_dest; | 3508 | struct GNUNET_PeerIdentity best_known_dest; |
3492 | struct GNUNET_HashCode intermediate_trail_id; | 3509 | struct GNUNET_HashCode intermediate_trail_id; |
3493 | struct GNUNET_PeerIdentity *next_hop; | 3510 | struct GNUNET_PeerIdentity *next_hop; |
@@ -3501,13 +3518,13 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3501 | GNUNET_break_op (0); | 3518 | GNUNET_break_op (0); |
3502 | return GNUNET_YES; | 3519 | return GNUNET_YES; |
3503 | } | 3520 | } |
3504 | 3521 | ||
3505 | get = (struct PeerGetMessage *)message; | 3522 | get = (const struct PeerGetMessage *)message; |
3506 | get_length = ntohl (get->get_path_length); | 3523 | get_length = ntohl (get->get_path_length); |
3507 | best_known_dest = get->best_known_destination; | 3524 | best_known_dest = get->best_known_destination; |
3508 | intermediate_trail_id = get->intermediate_trail_id; | 3525 | intermediate_trail_id = get->intermediate_trail_id; |
3509 | get_path = (struct GNUNET_PeerIdentity *)&get[1]; | 3526 | get_path = (const struct GNUNET_PeerIdentity *)&get[1]; |
3510 | 3527 | ||
3511 | if ((msize < | 3528 | if ((msize < |
3512 | sizeof (struct PeerGetMessage) + | 3529 | sizeof (struct PeerGetMessage) + |
3513 | get_length * sizeof (struct GNUNET_PeerIdentity)) || | 3530 | get_length * sizeof (struct GNUNET_PeerIdentity)) || |
@@ -3520,11 +3537,14 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3520 | 3537 | ||
3521 | /* Add sender to get path */ | 3538 | /* Add sender to get path */ |
3522 | struct GNUNET_PeerIdentity gp[get_length + 1]; | 3539 | struct GNUNET_PeerIdentity gp[get_length + 1]; |
3523 | memcpy (gp, get_path, get_length * sizeof (struct GNUNET_PeerIdentity)); | 3540 | if (get_length > 0) |
3541 | memcpy (gp, get_path, get_length * sizeof (struct GNUNET_PeerIdentity)); | ||
3524 | gp[get_length + 1] = *peer; | 3542 | gp[get_length + 1] = *peer; |
3525 | get_length = get_length + 1; | 3543 | get_length = get_length + 1; |
3526 | 3544 | ||
3527 | memcpy (&key_value, &(get->key), sizeof (uint64_t)); | 3545 | memcpy (&key_value, &(get->key), sizeof (uint64_t)); |
3546 | |||
3547 | /* I am not the final destination. I am part of trail to reach final dest. */ | ||
3528 | if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&best_known_dest, &my_identity))) | 3548 | if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&best_known_dest, &my_identity))) |
3529 | { | 3549 | { |
3530 | next_hop = GDS_ROUTING_get_next_hop (intermediate_trail_id, | 3550 | next_hop = GDS_ROUTING_get_next_hop (intermediate_trail_id, |
@@ -3532,6 +3552,7 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3532 | } | 3552 | } |
3533 | else | 3553 | else |
3534 | { | 3554 | { |
3555 | /* Get the next hop to pass the message to. */ | ||
3535 | next_hop = find_successor (key_value, &best_known_dest, | 3556 | next_hop = find_successor (key_value, &best_known_dest, |
3536 | &intermediate_trail_id, GDS_FINGER_TYPE_NON_PREDECESSOR); | 3557 | &intermediate_trail_id, GDS_FINGER_TYPE_NON_PREDECESSOR); |
3537 | } | 3558 | } |
@@ -3544,15 +3565,18 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3544 | 1, GNUNET_NO); | 3565 | 1, GNUNET_NO); |
3545 | return GNUNET_SYSERR; | 3566 | return GNUNET_SYSERR; |
3546 | } | 3567 | } |
3547 | if (0 == GNUNET_CRYPTO_cmp_peer_identity(&my_identity, next_hop)) | 3568 | |
3569 | /* I am the final destination. */ | ||
3570 | if (0 == GNUNET_CRYPTO_cmp_peer_identity(&my_identity, &best_known_dest)) | ||
3548 | { | 3571 | { |
3549 | /* I am the destination.*/ | ||
3550 | struct GNUNET_PeerIdentity final_get_path[get_length+1]; | 3572 | struct GNUNET_PeerIdentity final_get_path[get_length+1]; |
3551 | struct GNUNET_PeerIdentity next_hop; | 3573 | struct GNUNET_PeerIdentity next_hop; |
3552 | 3574 | ||
3553 | memcpy (final_get_path, gp, get_length * sizeof (struct GNUNET_PeerIdentity)); | 3575 | memcpy (final_get_path, gp, get_length * sizeof (struct GNUNET_PeerIdentity)); |
3554 | memcpy (&final_get_path[get_length+1], &my_identity, sizeof (struct GNUNET_PeerIdentity)); | 3576 | memcpy (&final_get_path[get_length+1], &my_identity, sizeof (struct GNUNET_PeerIdentity)); |
3555 | get_length = get_length + 1; | 3577 | get_length = get_length + 1; |
3578 | |||
3579 | /* Get the next hop to pass the get result message. */ | ||
3556 | memcpy (&next_hop, &final_get_path[get_length-2], sizeof (struct GNUNET_PeerIdentity)); | 3580 | memcpy (&next_hop, &final_get_path[get_length-2], sizeof (struct GNUNET_PeerIdentity)); |
3557 | GDS_DATACACHE_handle_get (&(get->key),(get->block_type), NULL, 0, NULL, 0, | 3581 | GDS_DATACACHE_handle_get (&(get->key),(get->block_type), NULL, 0, NULL, 0, |
3558 | get_length, final_get_path,&next_hop, &my_identity); | 3582 | get_length, final_get_path,&next_hop, &my_identity); |
@@ -4221,6 +4245,8 @@ compare_and_update_predecessor (struct GNUNET_PeerIdentity finger, | |||
4221 | 4245 | ||
4222 | current_predecessor = &finger_table[PREDECESSOR_FINGER_ID]; | 4246 | current_predecessor = &finger_table[PREDECESSOR_FINGER_ID]; |
4223 | 4247 | ||
4248 | GNUNET_assert (0 != GNUNET_CRYPTO_cmp_peer_identity (&finger, &my_identity)); | ||
4249 | |||
4224 | /* No predecessor. Add finger as your predecessor. */ | 4250 | /* No predecessor. Add finger as your predecessor. */ |
4225 | if (GNUNET_NO == current_predecessor->is_present) | 4251 | if (GNUNET_NO == current_predecessor->is_present) |
4226 | { | 4252 | { |
@@ -4241,6 +4267,7 @@ compare_and_update_predecessor (struct GNUNET_PeerIdentity finger, | |||
4241 | update_predecessor (finger, trail, trail_length); | 4267 | update_predecessor (finger, trail, trail_length); |
4242 | return; | 4268 | return; |
4243 | } | 4269 | } |
4270 | |||
4244 | return; | 4271 | return; |
4245 | } | 4272 | } |
4246 | 4273 | ||
@@ -4345,10 +4372,12 @@ handle_dht_p2p_verify_successor(void *cls, | |||
4345 | 4372 | ||
4346 | /* I am the destination of this message. */ | 4373 | /* I am the destination of this message. */ |
4347 | 4374 | ||
4348 | /* Check if there is a predecessor or not. */ | 4375 | /* Check if the source_peer could be our predecessor and if yes then update |
4376 | * it. */ | ||
4349 | compare_and_update_predecessor (source_peer, trail, trail_length); | 4377 | compare_and_update_predecessor (source_peer, trail, trail_length); |
4350 | 4378 | ||
4351 | current_predecessor = &finger_table[PREDECESSOR_FINGER_ID]; | 4379 | current_predecessor = &finger_table[PREDECESSOR_FINGER_ID]; |
4380 | |||
4352 | /* Is source of this message my predecessor. */ | 4381 | /* Is source of this message my predecessor. */ |
4353 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (¤t_predecessor->finger_identity, | 4382 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (¤t_predecessor->finger_identity, |
4354 | &source_peer))) | 4383 | &source_peer))) |
@@ -4373,7 +4402,6 @@ handle_dht_p2p_verify_successor(void *cls, | |||
4373 | trail_to_predecessor_length = 0; | 4402 | trail_to_predecessor_length = 0; |
4374 | } | 4403 | } |
4375 | } | 4404 | } |
4376 | |||
4377 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer); | 4405 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer); |
4378 | GDS_NEIGHBOURS_send_verify_successor_result (source_peer, my_identity, | 4406 | GDS_NEIGHBOURS_send_verify_successor_result (source_peer, my_identity, |
4379 | current_predecessor->finger_identity, | 4407 | current_predecessor->finger_identity, |
@@ -4381,6 +4409,7 @@ handle_dht_p2p_verify_successor(void *cls, | |||
4381 | trail_to_predecessor_length, | 4409 | trail_to_predecessor_length, |
4382 | GDS_ROUTING_DEST_TO_SRC, | 4410 | GDS_ROUTING_DEST_TO_SRC, |
4383 | target_friend); | 4411 | target_friend); |
4412 | GNUNET_free_non_null (trail_to_predecessor); | ||
4384 | return GNUNET_OK; | 4413 | return GNUNET_OK; |
4385 | } | 4414 | } |
4386 | 4415 | ||
@@ -4461,13 +4490,13 @@ compare_and_update_successor (struct GNUNET_PeerIdentity probable_successor, | |||
4461 | 4490 | ||
4462 | current_successor = &finger_table[0]; | 4491 | current_successor = &finger_table[0]; |
4463 | GNUNET_assert (GNUNET_YES == current_successor->is_present); | 4492 | GNUNET_assert (GNUNET_YES == current_successor->is_present); |
4464 | 4493 | ||
4465 | /* Compute the 64 bit value of successor identity. We need this as we need to | 4494 | /* Compute the 64 bit value of successor identity. We need this as we need to |
4466 | * find the closest peer w.r.t this value.*/ | 4495 | * find the closest peer w.r.t this value.*/ |
4467 | successor_value = compute_finger_identity_value (0); | 4496 | successor_value = compute_finger_identity_value (0); |
4468 | closest_peer = select_closest_peer (¤t_successor->finger_identity, | 4497 | closest_peer = select_closest_peer (¤t_successor->finger_identity, |
4469 | &probable_successor, | 4498 | &probable_successor, |
4470 | successor_value, GNUNET_NO); | 4499 | successor_value, 0); |
4471 | 4500 | ||
4472 | /* If the current_successor is the closest one, then exit. */ | 4501 | /* If the current_successor is the closest one, then exit. */ |
4473 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (closest_peer, | 4502 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (closest_peer, |
@@ -4571,7 +4600,7 @@ handle_dht_p2p_verify_successor_result(void *cls, | |||
4571 | trail_direction = ntohl (vsrm->trail_direction); | 4600 | trail_direction = ntohl (vsrm->trail_direction); |
4572 | trail_id = vsrm->trail_id; | 4601 | trail_id = vsrm->trail_id; |
4573 | probable_successor = vsrm->probable_successor; | 4602 | probable_successor = vsrm->probable_successor; |
4574 | 4603 | ||
4575 | //FIXME: add a check to ensure that peer from which you got the message is | 4604 | //FIXME: add a check to ensure that peer from which you got the message is |
4576 | //the correct peer. | 4605 | //the correct peer. |
4577 | /* I am the querying_peer. */ | 4606 | /* I am the querying_peer. */ |
@@ -4904,8 +4933,8 @@ handle_dht_p2p_trail_compression (void *cls, const struct GNUNET_PeerIdentity *p | |||
4904 | return GNUNET_OK; | 4933 | return GNUNET_OK; |
4905 | } | 4934 | } |
4906 | 4935 | ||
4907 | GNUNET_assert (GNUNET_YES == GDS_ROUTING_remove_trail (trail_id)); | 4936 | GNUNET_assert (NULL != (target_friend = |
4908 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | 4937 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop))); |
4909 | GDS_NEIGHBOURS_send_trail_compression (trail_compression->source_peer, | 4938 | GDS_NEIGHBOURS_send_trail_compression (trail_compression->source_peer, |
4910 | trail_id, | 4939 | trail_id, |
4911 | trail_compression->new_first_friend, | 4940 | trail_compression->new_first_friend, |
@@ -5268,8 +5297,10 @@ core_init (void *cls, | |||
5268 | my_identity = *identity; | 5297 | my_identity = *identity; |
5269 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 5298 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
5270 | "my_indentity = %s\n",GNUNET_i2s(&my_identity)); | 5299 | "my_indentity = %s\n",GNUNET_i2s(&my_identity)); |
5300 | #if 0 | ||
5271 | FPRINTF (stderr,_("\nSUPU %s, %s, %d, my_identity = %s"), | 5301 | FPRINTF (stderr,_("\nSUPU %s, %s, %d, my_identity = %s"), |
5272 | __FILE__, __func__,__LINE__, GNUNET_i2s (&my_identity)); | 5302 | __FILE__, __func__,__LINE__, GNUNET_i2s (&my_identity)); |
5303 | #endif | ||
5273 | } | 5304 | } |
5274 | 5305 | ||
5275 | 5306 | ||
diff --git a/src/dht/gnunet-service-xdht_neighbours.h b/src/dht/gnunet-service-xdht_neighbours.h index d96afdb47..a72f92984 100644 --- a/src/dht/gnunet-service-xdht_neighbours.h +++ b/src/dht/gnunet-service-xdht_neighbours.h | |||
@@ -84,7 +84,7 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key, | |||
84 | enum GNUNET_BLOCK_Type block_type, | 84 | enum GNUNET_BLOCK_Type block_type, |
85 | enum GNUNET_DHT_RouteOption options, | 85 | enum GNUNET_DHT_RouteOption options, |
86 | uint32_t desired_replication_level, | 86 | uint32_t desired_replication_level, |
87 | struct GNUNET_PeerIdentity *best_known_dest, | 87 | const struct GNUNET_PeerIdentity *best_known_dest, |
88 | struct GNUNET_HashCode *intermediate_trail_id, | 88 | struct GNUNET_HashCode *intermediate_trail_id, |
89 | struct GNUNET_PeerIdentity *target_peer, | 89 | struct GNUNET_PeerIdentity *target_peer, |
90 | uint32_t hop_count, | 90 | uint32_t hop_count, |