aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSupriti Singh <supritisingh08@gmail.com>2014-08-19 18:33:27 +0000
committerSupriti Singh <supritisingh08@gmail.com>2014-08-19 18:33:27 +0000
commit1b505820b41ebaa051a257c7191ac47adbb745fd (patch)
tree9a44b0368d8e2d5f8deddf8bdeed3af8e097087c
parentd276b7a5610430cc1e5fe24c21a9957a892b6eaa (diff)
downloadgnunet-1b505820b41ebaa051a257c7191ac47adbb745fd.tar.gz
gnunet-1b505820b41ebaa051a257c7191ac47adbb745fd.zip
- PUT/GET Code refactor
-rw-r--r--src/dht/gnunet-service-xdht_clients.c64
-rw-r--r--src/dht/gnunet-service-xdht_neighbours.c397
-rw-r--r--src/dht/gnunet-service-xdht_neighbours.h81
-rw-r--r--src/dht/gnunet_dht_profiler.c12
4 files changed, 184 insertions, 370 deletions
diff --git a/src/dht/gnunet-service-xdht_clients.c b/src/dht/gnunet-service-xdht_clients.c
index c5f6c0d83..e5513f6a9 100644
--- a/src/dht/gnunet-service-xdht_clients.c
+++ b/src/dht/gnunet-service-xdht_clients.c
@@ -856,21 +856,10 @@ transmit_request (struct ClientQueryRecord *cqr)
856 GNUNET_h2s (&cqr->key), 856 GNUNET_h2s (&cqr->key),
857 cqr->replication, 857 cqr->replication,
858 cqr->seen_replies_count); 858 cqr->seen_replies_count);
859 struct GNUNET_PeerIdentity best_known_dest;
860 struct GNUNET_HashCode intermediate_trail_id;
861 859
862 memset (&best_known_dest, 0, sizeof (struct GNUNET_PeerIdentity)); 860 GDS_NEIGHBOURS_handle_get (&cqr->key, cqr->type, cqr->msg_options,
863 memset (&intermediate_trail_id, 0, sizeof (struct GNUNET_HashCode)); 861 cqr->replication);
864 862
865 GDS_NEIGHBOURS_send_get (&cqr->key, cqr->type, cqr->msg_options,
866 cqr->replication, best_known_dest,
867 intermediate_trail_id , NULL,
868 0, 0, NULL);
869#if 0
870 GDS_NEIGHBOURS_send_get (&cqr->key, cqr->type, cqr->msg_options,
871 cqr->replication, NULL, NULL , NULL,
872 0, 0, NULL);
873#endif
874 /* exponential back-off for retries. 863 /* exponential back-off for retries.
875 * max GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD (15 min) */ 864 * max GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD (15 min) */
876 cqr->retry_frequency = GNUNET_TIME_STD_BACKOFF (cqr->retry_frequency); 865 cqr->retry_frequency = GNUNET_TIME_STD_BACKOFF (cqr->retry_frequency);
@@ -959,48 +948,13 @@ handle_dht_local_put (void *cls, struct GNUNET_SERVER_Client *client,
959 ntohl (put_msg->type), 948 ntohl (put_msg->type),
960 size - sizeof (struct GNUNET_DHT_ClientPutMessage), 949 size - sizeof (struct GNUNET_DHT_ClientPutMessage),
961 &put_msg[1]); 950 &put_msg[1]);
962 /* FIXME: Should we store locally? */
963/* GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (put_msg->expiration),
964 &put_msg->key, 0, NULL, ntohl (put_msg->type),
965 size - sizeof (struct GNUNET_DHT_ClientPutMessage),
966 &put_msg[1]);*/
967 951
968 struct GNUNET_PeerIdentity my_identity = GDS_NEIGHBOURS_get_my_id(); 952 GDS_NEIGHBOURS_handle_put (&put_msg->key,
969 struct GNUNET_PeerIdentity best_known_destination; 953 ntohl (put_msg->type), ntohl (put_msg->options),
970 struct GNUNET_HashCode intermediate_trail_id; 954 ntohl (put_msg->desired_replication_level),
971 955 GNUNET_TIME_absolute_ntoh (put_msg->expiration),
972 memset(&best_known_destination, 0 , sizeof (struct GNUNET_PeerIdentity)); 956 &put_msg[1],
973 memset(&intermediate_trail_id, 0, sizeof (struct GNUNET_HashCode)); 957 size - sizeof (struct GNUNET_DHT_ClientPutMessage));
974
975 GDS_NEIGHBOURS_send_put (&put_msg->key,
976 ntohl (put_msg->type), ntohl (put_msg->options),
977 ntohl (put_msg->desired_replication_level),
978 best_known_destination,
979 intermediate_trail_id, NULL, 0, 0, NULL,
980 GNUNET_TIME_absolute_ntoh (put_msg->expiration),
981 &put_msg[1],
982 size - sizeof (struct GNUNET_DHT_ClientPutMessage));
983#if 0
984 GDS_NEIGHBOURS_send_put (&put_msg->key,
985 ntohl (put_msg->type), ntohl (put_msg->options),
986 ntohl (put_msg->desired_replication_level), NULL,
987 NULL, NULL, 0, 0, NULL,
988 GNUNET_TIME_absolute_ntoh (put_msg->expiration),
989 &put_msg[1],
990 size - sizeof (struct GNUNET_DHT_ClientPutMessage));
991
992#endif
993 GDS_CLIENTS_process_put (ntohl (put_msg->options),
994 ntohl (put_msg->type),
995 0,
996 ntohl (put_msg->desired_replication_level),
997 1,
998 &my_identity,
999 GNUNET_TIME_absolute_ntoh (put_msg->expiration),
1000 &put_msg->key,
1001 &put_msg[1],
1002 size - sizeof (struct GNUNET_DHT_ClientPutMessage));
1003
1004 pm = GNUNET_malloc (sizeof (struct PendingMessage) + 958 pm = GNUNET_malloc (sizeof (struct PendingMessage) +
1005 sizeof (struct GNUNET_DHT_ClientPutConfirmationMessage)); 959 sizeof (struct GNUNET_DHT_ClientPutConfirmationMessage));
1006 conf = (struct GNUNET_DHT_ClientPutConfirmationMessage *) &pm[1]; 960 conf = (struct GNUNET_DHT_ClientPutConfirmationMessage *) &pm[1];
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c
index 663f13692..924328a6f 100644
--- a/src/dht/gnunet-service-xdht_neighbours.c
+++ b/src/dht/gnunet-service-xdht_neighbours.c
@@ -798,30 +798,16 @@ struct Closest_Peer
798 * to reach to it. In other case, same as best_known_destination. 798 * to reach to it. In other case, same as best_known_destination.
799 */ 799 */
800 struct GNUNET_PeerIdentity next_hop; 800 struct GNUNET_PeerIdentity next_hop;
801}; 801
802
803
804/**
805 * Data structure to store the trail chosen to reach to finger.
806 */
807struct Selected_Finger_Trail
808{
809 /**
810 * First friend in the trail to reach finger.
811 */
812 struct FriendInfo friend;
813
814 /**
815 * Identifier of this trail.
816 */
817 struct GNUNET_HashCode trail_id;
818
819 /** 802 /**
820 * Total number of peers in this trail. 803 * In case finger is the next hop, it contains a valid finger table index
804 * at which the finger is stored. Else, It contains 65, which is out of range
805 * of finger table index.
821 */ 806 */
822 unsigned int trail_length; 807 unsigned int finger_table_index;
823}; 808};
824 809
810
825/** 811/**
826 * Task that sends FIND FINGER TRAIL requests. This task is started when we have 812 * Task that sends FIND FINGER TRAIL requests. This task is started when we have
827 * get our first friend. 813 * get our first friend.
@@ -1740,9 +1726,9 @@ test_friend_peermap_print ()
1740 } 1726 }
1741 } 1727 }
1742} 1728}
1729#endif
1743 1730
1744 1731#if 0
1745
1746/** 1732/**
1747 * This is a test function, to print all the entries of finger table. 1733 * This is a test function, to print all the entries of finger table.
1748 */ 1734 */
@@ -1822,8 +1808,7 @@ select_closest_peer (const struct GNUNET_PeerIdentity *peer1,
1822 * Note: We use length as parameter. But we can use any other suitable parameter 1808 * Note: We use length as parameter. But we can use any other suitable parameter
1823 * also. 1809 * also.
1824 * @param finger Finger 1810 * @param finger Finger
1825 * @return struct Selected_Finger_Trail which contains the first friend , trail id 1811 * @return Trail
1826 * and trail length. NULL in case none of the trails are free.
1827 */ 1812 */
1828static struct Trail * 1813static struct Trail *
1829select_finger_trail (struct FingerInfo *finger) 1814select_finger_trail (struct FingerInfo *finger)
@@ -1862,64 +1847,6 @@ select_finger_trail (struct FingerInfo *finger)
1862 return best_trail; 1847 return best_trail;
1863} 1848}
1864 1849
1865#if 0
1866static struct Selected_Finger_Trail *
1867select_finger_trail (struct FingerInfo *finger)
1868{
1869 struct FriendInfo *friend;
1870 struct Trail *current_finger_trail;
1871 struct Selected_Finger_Trail *finger_trail;
1872 unsigned int i;
1873 unsigned int flag = 0;
1874 unsigned int j = 0;
1875
1876 finger_trail = GNUNET_new (struct Selected_Finger_Trail);
1877 GNUNET_assert (finger->trails_count > 0);
1878
1879 for (i = 0; i < finger->trails_count; i++)
1880 {
1881 current_finger_trail = &finger->trail_list[i];
1882
1883 /* No trail stored at this index. */
1884 if (GNUNET_NO == current_finger_trail->is_present)
1885 continue;
1886
1887 GNUNET_assert (NULL !=
1888 (friend =
1889 GNUNET_CONTAINER_multipeermap_get (friend_peermap,
1890 &current_finger_trail->trail_head->peer)));
1891
1892 /* First friend to reach trail is not free. */
1893 if (GNUNET_YES == is_friend_congested (friend))
1894 {
1895 j++;
1896 continue;
1897 }
1898
1899 if (!flag)
1900 {
1901 flag = 1;
1902 finger_trail->trail_length = current_finger_trail->trail_length;
1903 finger_trail->friend = *friend;
1904 finger_trail->trail_id = current_finger_trail->trail_id;
1905 }
1906 else if (finger_trail->trail_length > current_finger_trail->trail_length)
1907 {
1908 finger_trail->friend = *friend;
1909 finger_trail->trail_id = current_finger_trail->trail_id;
1910 finger_trail->trail_length = current_finger_trail->trail_length;
1911 }
1912 }
1913
1914 /* All the first friend in all the trails to reach to finger are either
1915 congested or have crossed trail threshold. */
1916 if (j == finger->trails_count)
1917 return NULL;
1918
1919 return finger_trail;
1920}
1921#endif
1922
1923 1850
1924/** 1851/**
1925 * Compare FINGER entry with current successor. If finger's first friend of all 1852 * Compare FINGER entry with current successor. If finger's first friend of all
@@ -1986,6 +1913,7 @@ compare_finger_and_current_closest_peer (struct Closest_Peer *current_closest_pe
1986 current_closest_peer->best_known_destination = closest_peer; 1913 current_closest_peer->best_known_destination = closest_peer;
1987 current_closest_peer->next_hop = finger_trail->trail_head->peer; 1914 current_closest_peer->next_hop = finger_trail->trail_head->peer;
1988 current_closest_peer->trail_id = finger_trail->trail_id; 1915 current_closest_peer->trail_id = finger_trail->trail_id;
1916 current_closest_peer->finger_table_index = i;
1989 } 1917 }
1990 continue; 1918 continue;
1991 } 1919 }
@@ -2058,7 +1986,7 @@ init_current_successor (struct GNUNET_PeerIdentity my_identity,
2058 current_closest_peer.is_predecessor = is_predecessor; 1986 current_closest_peer.is_predecessor = is_predecessor;
2059 current_closest_peer.next_hop = my_identity; 1987 current_closest_peer.next_hop = my_identity;
2060 current_closest_peer.best_known_destination = my_identity; 1988 current_closest_peer.best_known_destination = my_identity;
2061 1989 current_closest_peer.finger_table_index = 65; //65 is a for non valid finger table index.
2062 return current_closest_peer; 1990 return current_closest_peer;
2063} 1991}
2064 1992
@@ -2103,7 +2031,6 @@ find_successor (uint64_t destination_finger_value,
2103 return current_closest_peer; 2031 return current_closest_peer;
2104} 2032}
2105 2033
2106
2107/** 2034/**
2108 * FIXME; Send put message across all the trail to reach to next hop to handle 2035 * FIXME; Send put message across all the trail to reach to next hop to handle
2109 * malicious peers. 2036 * malicious peers.
@@ -2141,27 +2068,10 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key,
2141 struct P2PPendingMessage *pending; 2068 struct P2PPendingMessage *pending;
2142 struct FriendInfo *target_friend; 2069 struct FriendInfo *target_friend;
2143 struct GNUNET_PeerIdentity *pp; 2070 struct GNUNET_PeerIdentity *pp;
2144 struct GNUNET_PeerIdentity new_put_path[1];
2145 unsigned int new_put_path_length = 0;
2146 struct GNUNET_PeerIdentity next_hop;
2147
2148 size_t msize; 2071 size_t msize;
2149 2072
2150 msize = put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size + 2073 msize = put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size +
2151 sizeof (struct PeerPutMessage); 2074 sizeof (struct PeerPutMessage);
2152
2153#if ENABLE_MALICIOUS
2154 /*Call is made to this function from
2155 1. First peer.
2156 2. Every peer to construct a pending message and send it to next peer.
2157 In case of 2nd, this case should have been handled in handle_dht_p2p_put/get
2158 No need to check here. First peer can never be malicious. IDEALLY we DONOT
2159 need the condition here. REMOVE IT AFTERWARDS once verified.*/
2160 if(1 == act_malicious)
2161 {
2162 return;
2163 }
2164#endif
2165 if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) 2075 if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE)
2166 { 2076 {
2167 put_path_length = 0; 2077 put_path_length = 0;
@@ -2175,51 +2085,10 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key,
2175 GNUNET_break (0); 2085 GNUNET_break (0);
2176 return; 2086 return;
2177 } 2087 }
2178 /* This is the first call made from clients file. So, we should search for the 2088
2179 target_friend. */ 2089 GNUNET_assert (NULL !=
2180 if (NULL == target_peer) 2090 (target_friend =
2181 { 2091 GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer)));
2182 uint64_t key_value;
2183 struct Closest_Peer successor;
2184
2185 memcpy (&key_value, key, sizeof (uint64_t));
2186 key_value = GNUNET_ntohll (key_value);
2187
2188 successor = find_successor (key_value, GDS_FINGER_TYPE_NON_PREDECESSOR);
2189 best_known_dest = successor.best_known_destination;
2190 next_hop = successor.next_hop;
2191 intermediate_trail_id = successor.trail_id;
2192
2193 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&best_known_dest, &my_identity))
2194 {
2195 /* I am the destination. */
2196 DEBUG("PUT destination is me = %s,key =%s\n",GNUNET_i2s(&my_identity),GNUNET_h2s(key));
2197 GDS_DATACACHE_handle_put (expiration_time, key, 0, NULL,
2198 block_type,data_size,data);
2199 return;
2200 }
2201 else
2202 {
2203 /* Add yourself to the put path. */
2204 new_put_path_length = 1;
2205 new_put_path[0] = my_identity;
2206 GNUNET_assert (NULL !=
2207 (target_friend =
2208 GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop)));
2209 }
2210 }
2211 else
2212 {
2213 GNUNET_assert (NULL !=
2214 (target_friend =
2215 GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer)));
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);
2221
2222 }
2223 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); 2092 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
2224 pending->timeout = expiration_time; 2093 pending->timeout = expiration_time;
2225 ppm = (struct PeerPutMessage *) &pending[1]; 2094 ppm = (struct PeerPutMessage *) &pending[1];
@@ -2232,26 +2101,16 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key,
2232 ppm->desired_replication_level = htonl (desired_replication_level); 2101 ppm->desired_replication_level = htonl (desired_replication_level);
2233 ppm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time); 2102 ppm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time);
2234 ppm->best_known_destination = best_known_dest; 2103 ppm->best_known_destination = best_known_dest;
2104 ppm->intermediate_trail_id = intermediate_trail_id;
2235 ppm->key = *key; 2105 ppm->key = *key;
2236
2237 pp = (struct GNUNET_PeerIdentity *) &ppm[1]; 2106 pp = (struct GNUNET_PeerIdentity *) &ppm[1];
2238 if (0 == new_put_path_length) 2107 ppm->put_path_length = htonl (put_path_length);
2239 { 2108 if(put_path_length > 0)
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)
2249 { 2109 {
2250 ppm->put_path_length = htonl (new_put_path_length); 2110 memcpy (pp, put_path,
2251 memcpy (pp, new_put_path, 2111 sizeof (struct GNUNET_PeerIdentity) * put_path_length);
2252 sizeof (struct GNUNET_PeerIdentity) * new_put_path_length);
2253 memcpy (&pp[new_put_path_length], data, data_size);
2254 } 2112 }
2113 memcpy (&pp[put_path_length], data, data_size);
2255 GNUNET_assert (NULL != target_friend); 2114 GNUNET_assert (NULL != target_friend);
2256 GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); 2115 GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending);
2257 target_friend->pending_count++; 2116 target_friend->pending_count++;
@@ -2260,6 +2119,81 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key,
2260 2119
2261 2120
2262/** 2121/**
2122 * Handle the put request from the client.
2123 * @param key Key for the content
2124 * @param block_type Type of the block
2125 * @param options Routing options
2126 * @param desired_replication_level Desired replication count
2127 * @param expiration_time When does the content expire
2128 * @param data Content to store
2129 * @param data_size Size of content @a data in bytes
2130 */
2131void
2132GDS_NEIGHBOURS_handle_put (const struct GNUNET_HashCode *key,
2133 enum GNUNET_BLOCK_Type block_type,
2134 enum GNUNET_DHT_RouteOption options,
2135 uint32_t desired_replication_level,
2136 struct GNUNET_TIME_Absolute expiration_time,
2137 const void *data, size_t data_size)
2138{
2139 struct GNUNET_PeerIdentity best_known_dest;
2140 struct GNUNET_HashCode intermediate_trail_id;
2141 struct GNUNET_PeerIdentity next_hop;
2142 uint64_t key_value;
2143 struct Closest_Peer successor;
2144
2145 memcpy (&key_value, key, sizeof (uint64_t));
2146 key_value = GNUNET_ntohll (key_value);
2147 successor = find_successor (key_value, GDS_FINGER_TYPE_NON_PREDECESSOR);
2148 best_known_dest = successor.best_known_destination;
2149 next_hop = successor.next_hop;
2150 intermediate_trail_id = successor.trail_id;
2151
2152 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&best_known_dest, &my_identity))
2153 {
2154 /* I am the destination. */
2155 DEBUG("PUT destination is me = %s,key =%s\n",GNUNET_i2s(&my_identity),GNUNET_h2s(key));
2156 GDS_DATACACHE_handle_put (expiration_time, key, 0, NULL,
2157 block_type,data_size,data);
2158 GDS_CLIENTS_process_put (options, block_type, 0,
2159 ntohl (desired_replication_level),
2160 1, &my_identity, expiration_time, //FIXME: GNUNETnthoh something on expiration time.
2161 key, data, data_size);
2162 return;
2163 }
2164
2165 /* In case we are sending the request to a finger, then send across all of its
2166 trail.*/
2167#if 0
2168 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&successor.best_known_destination,
2169 &successor.next_hop))
2170 {
2171 struct FingerInfo *next_hop_finger;
2172 unsigned int i;
2173
2174 next_hop_finger = &finger_table[successor.finger_table_index];
2175 for (i = 0; i < next_hop_finger->trails_count; i++)
2176 {
2177 if (GNUNET_YES == next_hop_finger->trail_list[i].is_present)
2178 {
2179 GDS_NEIGHBOURS_send_put (key, block_type, options, desired_replication_level,
2180 best_known_dest,
2181 next_hop_finger->trail_list[i].trail_id,
2182 &next_hop, hop_count, put_path_length, put_path,
2183 expiration_time,
2184 data, data_size);
2185 }
2186 }
2187 }
2188 else
2189#endif
2190 GDS_NEIGHBOURS_send_put (key, block_type, options, desired_replication_level,
2191 best_known_dest, intermediate_trail_id, &next_hop,
2192 0, 1, &my_identity, expiration_time,
2193 data, data_size);
2194}
2195
2196/**
2263 * FIXME; Send get message across all the trail to reach to next hop to handle 2197 * FIXME; Send get message across all the trail to reach to next hop to handle
2264 * malicious peers. 2198 * malicious peers.
2265 * Construct a Get message and send it to target_peer. 2199 * Construct a Get message and send it to target_peer.
@@ -2294,77 +2228,20 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key,
2294 struct P2PPendingMessage *pending; 2228 struct P2PPendingMessage *pending;
2295 struct FriendInfo *target_friend; 2229 struct FriendInfo *target_friend;
2296 struct GNUNET_PeerIdentity *gp; 2230 struct GNUNET_PeerIdentity *gp;
2297 struct GNUNET_PeerIdentity new_get_path[1];
2298 unsigned int new_get_path_length = 0;
2299 size_t msize; 2231 size_t msize;
2300 2232
2301 msize = sizeof (struct PeerGetMessage) + 2233 msize = sizeof (struct PeerGetMessage) +
2302 (get_path_length * sizeof (struct GNUNET_PeerIdentity)); 2234 (get_path_length * sizeof (struct GNUNET_PeerIdentity));
2303 2235
2304#if ENABLE_MALICIOUS
2305 if(1 == act_malicious)
2306 {
2307 return;
2308 }
2309#endif
2310 /* In this case we don't make get_path_length = 0, as we need get path to
2311 * return the message back to querying client. */
2312 if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) 2236 if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE)
2313 { 2237 {
2314 GNUNET_break (0); 2238 GNUNET_break (0);
2315 return; 2239 return;
2316 } 2240 }
2317 2241 GNUNET_assert (NULL !=
2318 DEBUG("GET FOR DATA_SIZE = %lu\n",msize); 2242 (target_friend =
2319 2243 GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer)));
2320 /* This is the first time we got request from our own client file. */
2321 if (NULL == target_peer)
2322 {
2323 uint64_t key_value;
2324 struct Closest_Peer successor;
2325
2326 memcpy (&key_value, key, sizeof (uint64_t));
2327 key_value = GNUNET_ntohll (key_value);
2328 successor = find_successor (key_value, GDS_FINGER_TYPE_NON_PREDECESSOR);
2329
2330 best_known_dest = successor.best_known_destination;
2331 intermediate_trail_id = successor.trail_id;
2332
2333 /* I am the destination. I have the data. */
2334 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity,
2335 &best_known_dest))
2336 {
2337 DEBUG("GET destination is me = %s,KEY = %s\n",GNUNET_i2s(&my_identity),GNUNET_h2s(key));
2338 GDS_DATACACHE_handle_get (key,block_type, NULL, 0,
2339 NULL, 0, 1, &my_identity, NULL,&my_identity);
2340
2341 return;
2342 }
2343 else
2344 {
2345 /* Add yourself to the put path. */
2346 new_get_path_length = 1;
2347 new_get_path[0] = my_identity;
2348 GNUNET_assert (NULL !=
2349 (target_friend =
2350 GNUNET_CONTAINER_multipeermap_get (friend_peermap,
2351 &successor.next_hop)));
2352 }
2353
2354 }
2355 else
2356 {
2357 GNUNET_assert (NULL !=
2358 (target_friend =
2359 GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer)));
2360 }
2361 2244
2362 if(1 == new_get_path_length)
2363 {
2364 msize = sizeof (struct PeerGetMessage) +
2365 (new_get_path_length * sizeof (struct GNUNET_PeerIdentity));
2366
2367 }
2368 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); 2245 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
2369 pending->timeout = GNUNET_TIME_relative_to_absolute (PENDING_MESSAGE_TIMEOUT); 2246 pending->timeout = GNUNET_TIME_relative_to_absolute (PENDING_MESSAGE_TIMEOUT);
2370 pending->importance = 0; /* FIXME */ 2247 pending->importance = 0; /* FIXME */
@@ -2377,19 +2254,10 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key,
2377 pgm->key = *key; 2254 pgm->key = *key;
2378 pgm->intermediate_trail_id = intermediate_trail_id; 2255 pgm->intermediate_trail_id = intermediate_trail_id;
2379 pgm->hop_count = htonl (hop_count + 1); 2256 pgm->hop_count = htonl (hop_count + 1);
2257 pgm->get_path_length = htonl (get_path_length);
2380 gp = (struct GNUNET_PeerIdentity *) &pgm[1]; 2258 gp = (struct GNUNET_PeerIdentity *) &pgm[1];
2381 if (1 == new_get_path_length) 2259 memcpy (gp, get_path,
2382 { 2260 sizeof (struct GNUNET_PeerIdentity) * get_path_length);
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);
2392 }
2393 GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); 2261 GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending);
2394 target_friend->pending_count++; 2262 target_friend->pending_count++;
2395 process_friend_queue (target_friend); 2263 process_friend_queue (target_friend);
@@ -2397,6 +2265,53 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key,
2397 2265
2398 2266
2399/** 2267/**
2268 * Handle the get request from the client file. If I am destination do
2269 * datacache put and return. Else find the target friend and forward message
2270 * to it.
2271 * @param key Key for the content
2272 * @param block_type Type of the block
2273 * @param options Routing options
2274 * @param desired_replication_level Desired replication count
2275 */
2276void
2277GDS_NEIGHBOURS_handle_get(const struct GNUNET_HashCode *key,
2278 enum GNUNET_BLOCK_Type block_type,
2279 enum GNUNET_DHT_RouteOption options,
2280 uint32_t desired_replication_level)
2281{
2282 struct Closest_Peer successor;
2283 struct GNUNET_PeerIdentity best_known_dest;
2284 struct GNUNET_HashCode intermediate_trail_id;
2285 uint64_t key_value;
2286
2287 memcpy (&key_value, key, sizeof (uint64_t));
2288 key_value = GNUNET_ntohll (key_value);
2289
2290 successor = find_successor (key_value, GDS_FINGER_TYPE_NON_PREDECESSOR);
2291
2292 best_known_dest = successor.best_known_destination;
2293 intermediate_trail_id = successor.trail_id;
2294
2295 /* I am the destination. I have the data. */
2296 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity,
2297 &best_known_dest))
2298 {
2299 DEBUG("GET destination is me = %s,KEY = %s\n",GNUNET_i2s(&my_identity),GNUNET_h2s(key));
2300 GDS_DATACACHE_handle_get (key,block_type, NULL, 0,
2301 NULL, 0, 1, &my_identity, NULL,&my_identity);
2302 return;
2303 }
2304
2305 /* fixme; for multiple trails, we need to send back finger index and send trail
2306 across all the fingers. but in current implementation we don't have this case.
2307 compare finger and current_successor returns, */
2308 GDS_NEIGHBOURS_send_get (key, block_type, options, desired_replication_level,
2309 best_known_dest,intermediate_trail_id, &successor.next_hop,
2310 0, 1, &my_identity);
2311}
2312
2313
2314/**
2400 * Send the get result to requesting client. 2315 * Send the get result to requesting client.
2401 * @param key Key of the requested data. 2316 * @param key Key of the requested data.
2402 * @param type Block type 2317 * @param type Block type
@@ -3032,7 +2947,7 @@ add_new_finger (struct GNUNET_PeerIdentity finger_identity,
3032 GNUNET_free (new_entry); 2947 GNUNET_free (new_entry);
3033 return; 2948 return;
3034 } 2949 }
3035 2950
3036 /* If finger is a friend, then we don't actually have a trail. 2951 /* If finger is a friend, then we don't actually have a trail.
3037 * Just a trail id */ 2952 * Just a trail id */
3038 if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, 2953 if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap,
@@ -3215,7 +3130,6 @@ update_current_search_finger_index (struct GNUNET_PeerIdentity finger_identity,
3215 { 3130 {
3216 if (GNUNET_SCHEDULER_NO_TASK == send_verify_successor_task) 3131 if (GNUNET_SCHEDULER_NO_TASK == send_verify_successor_task)
3217 { 3132 {
3218 DEBUG (" schedule");
3219 send_verify_successor_task = 3133 send_verify_successor_task =
3220 GNUNET_SCHEDULER_add_now (&send_verify_successor_message, NULL); 3134 GNUNET_SCHEDULER_add_now (&send_verify_successor_message, NULL);
3221 } 3135 }
@@ -4035,7 +3949,7 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer,
4035 } 3949 }
4036 3950
4037 /* Check if you are friend of source. */ 3951 /* Check if you are friend of source. */
4038 if (trail_length > 1) 3952 if (trail_length >= 1)
4039 { 3953 {
4040 if(NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, &source)) 3954 if(NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, &source))
4041 { 3955 {
@@ -4055,7 +3969,6 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer,
4055 } 3969 }
4056 } 3970 }
4057 3971
4058
4059 /* Is my routing table full? */ 3972 /* Is my routing table full? */
4060 if (GNUNET_YES == GDS_ROUTING_threshold_reached()) 3973 if (GNUNET_YES == GDS_ROUTING_threshold_reached())
4061 { 3974 {
@@ -5529,6 +5442,7 @@ remove_matching_trails (const struct GNUNET_PeerIdentity *disconnected_friend,
5529} 5442}
5530 5443
5531 5444
5445
5532/** 5446/**
5533 * Iterate over finger_table entries. 5447 * Iterate over finger_table entries.
5534 * 0. Ignore finger which is my_identity or if no valid entry present at 5448 * 0. Ignore finger which is my_identity or if no valid entry present at
@@ -5703,7 +5617,7 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer_identity)
5703 5617
5704 friend = GNUNET_new (struct FriendInfo); 5618 friend = GNUNET_new (struct FriendInfo);
5705 friend->id = *peer_identity; 5619 friend->id = *peer_identity;
5706 5620 friend->congestion_timestamp = GNUNET_TIME_relative_to_absolute(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1));
5707 GNUNET_assert (GNUNET_OK == 5621 GNUNET_assert (GNUNET_OK ==
5708 GNUNET_CONTAINER_multipeermap_put (friend_peermap, 5622 GNUNET_CONTAINER_multipeermap_put (friend_peermap,
5709 peer_identity, friend, 5623 peer_identity, friend,
@@ -5712,7 +5626,6 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer_identity)
5712 /* got a first connection, good time to start with FIND FINGER TRAIL requests...*/ 5626 /* got a first connection, good time to start with FIND FINGER TRAIL requests...*/
5713 if (GNUNET_SCHEDULER_NO_TASK == find_finger_trail_task) 5627 if (GNUNET_SCHEDULER_NO_TASK == find_finger_trail_task)
5714 { 5628 {
5715 DEBUG ("sCHEDULING FINGER TASK");
5716 find_finger_trail_task = GNUNET_SCHEDULER_add_now (&send_find_finger_trail_message, NULL); 5629 find_finger_trail_task = GNUNET_SCHEDULER_add_now (&send_find_finger_trail_message, NULL);
5717 } 5630 }
5718} 5631}
diff --git a/src/dht/gnunet-service-xdht_neighbours.h b/src/dht/gnunet-service-xdht_neighbours.h
index 6d5c881ec..e1fae570d 100644
--- a/src/dht/gnunet-service-xdht_neighbours.h
+++ b/src/dht/gnunet-service-xdht_neighbours.h
@@ -42,90 +42,37 @@ GDS_NEIGHBOURS_act_malicious (unsigned int malicious);
42#endif 42#endif
43 43
44/** 44/**
45 * Construct a Put message and send it to target_peer. 45 * Handle the put request from the client.
46 * @param key Key for the content 46 * @param key Key for the content
47 * @param block_type Type of the block 47 * @param block_type Type of the block
48 * @param options Routing options 48 * @param options Routing options
49 * @param desired_replication_level Desired replication count 49 * @param desired_replication_level Desired replication count
50 * @param best_known_dest Peer to which this message should reach eventually,
51 * as it is best known destination to me.
52 * @param intermediate_trail_id Trail id in case
53 * @param target_peer Peer to which this message will be forwarded.
54 * @param hop_count Number of hops traversed so far.
55 * @param put_path_length Total number of peers in @a put_path
56 * @param put_path Number of peers traversed so far
57 * @param expiration_time When does the content expire 50 * @param expiration_time When does the content expire
58 * @param data Content to store 51 * @param data Content to store
59 * @param data_size Size of content @a data in bytes 52 * @param data_size Size of content @a data in bytes
60 */ 53 */
61void 54void
62GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key, 55GDS_NEIGHBOURS_handle_put (const struct GNUNET_HashCode *key,
63 enum GNUNET_BLOCK_Type block_type, 56 enum GNUNET_BLOCK_Type block_type,
64 enum GNUNET_DHT_RouteOption options, 57 enum GNUNET_DHT_RouteOption options,
65 uint32_t desired_replication_level, 58 uint32_t desired_replication_level,
66 struct GNUNET_PeerIdentity best_known_dest, 59 struct GNUNET_TIME_Absolute expiration_time,
67 struct GNUNET_HashCode intermediate_trail_id, 60 const void *data, size_t data_size);
68 struct GNUNET_PeerIdentity *target_peer,
69 uint32_t hop_count,
70 uint32_t put_path_length,
71 struct GNUNET_PeerIdentity *put_path,
72 struct GNUNET_TIME_Absolute expiration_time,
73 const void *data, size_t data_size);
74
75 61
76/** 62/**
77 * Construct a Get message and send it to target_peer. 63 * Handle the get request from the client file. If I am destination do
64 * datacache put and return. Else find the target friend and forward message
65 * to it.
78 * @param key Key for the content 66 * @param key Key for the content
79 * @param block_type Type of the block 67 * @param block_type Type of the block
80 * @param options Routing options 68 * @param options Routing options
81 * @param desired_replication_level Desired replication count 69 * @param desired_replication_level Desired replication count
82 * @param best_known_dest
83 * @param intermediate_trail_id
84 * @param target_peer Peer to which this message will be forwarded.
85 * @param hop_count Number of hops traversed so far.
86 * @param data Content to store
87 * @param data_size Size of content @a data in bytes
88 * @param get_path_length Total number of peers in @a get_path
89 * @param get_path Number of peers traversed so far
90 */
91void
92GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key,
93 enum GNUNET_BLOCK_Type block_type,
94 enum GNUNET_DHT_RouteOption options,
95 uint32_t desired_replication_level,
96 struct GNUNET_PeerIdentity best_known_dest,
97 struct GNUNET_HashCode intermediate_trail_id,
98 struct GNUNET_PeerIdentity *target_peer,
99 uint32_t hop_count,
100 uint32_t get_path_length,
101 struct GNUNET_PeerIdentity *get_path);
102
103
104/**
105 * Send the get result to requesting client.
106 * @param key Key of the requested data.
107 * @param type Block type
108 * @param target_peer Next peer to forward the message to.
109 * @param source_peer Peer which has the data for the key.
110 * @param put_path_length Number of peers in @a put_path
111 * @param put_path Path taken to put the data at its stored location.
112 * @param get_path_length Number of peers in @a get_path
113 * @param get_path Path taken to reach to the location of the key.
114 * @param expiration When will this result expire?
115 * @param data Payload to store
116 * @param data_size Size of the @a data
117 */ 70 */
118void 71void
119GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *key, 72GDS_NEIGHBOURS_handle_get(const struct GNUNET_HashCode *key,
120 enum GNUNET_BLOCK_Type type, 73 enum GNUNET_BLOCK_Type block_type,
121 const struct GNUNET_PeerIdentity *target_peer, 74 enum GNUNET_DHT_RouteOption options,
122 const struct GNUNET_PeerIdentity *source_peer, 75 uint32_t desired_replication_level);
123 unsigned int put_path_length,
124 const struct GNUNET_PeerIdentity *put_path,
125 unsigned int get_path_length,
126 const struct GNUNET_PeerIdentity *get_path,
127 struct GNUNET_TIME_Absolute expiration,
128 const void *data, size_t data_size);
129 76
130/** 77/**
131 * Construct a trail teardown message and forward it to target friend. 78 * Construct a trail teardown message and forward it to target friend.
diff --git a/src/dht/gnunet_dht_profiler.c b/src/dht/gnunet_dht_profiler.c
index 12c273492..31671545d 100644
--- a/src/dht/gnunet_dht_profiler.c
+++ b/src/dht/gnunet_dht_profiler.c
@@ -276,12 +276,12 @@ static uint64_t incoming_bandwidth;
276/** 276/**
277 * Average number of hops taken to do put. 277 * Average number of hops taken to do put.
278 */ 278 */
279static unsigned int average_put_path_length; 279static double average_put_path_length;
280 280
281/** 281/**
282 * Average number of hops taken to do get. 282 * Average number of hops taken to do get.
283 */ 283 */
284static unsigned int average_get_path_length; 284static double average_get_path_length;
285 285
286/** 286/**
287 * Total put path length across all peers. 287 * Total put path length across all peers.
@@ -454,8 +454,8 @@ summarize ()
454 INFO ("# GETS made: %u\n", n_gets); 454 INFO ("# GETS made: %u\n", n_gets);
455 INFO ("# GETS succeeded: %u\n", n_gets_ok); 455 INFO ("# GETS succeeded: %u\n", n_gets_ok);
456 INFO ("# GETS failed: %u\n", n_gets_fail); 456 INFO ("# GETS failed: %u\n", n_gets_fail);
457 INFO ("# average_put_path_length: %u\n", average_put_path_length); 457 INFO ("# average_put_path_length: %f\n", average_put_path_length);
458 INFO ("# average_get_path_length: %u\n", average_get_path_length); 458 INFO ("# average_get_path_length: %f\n", average_get_path_length);
459 459
460 if (NULL == testbed_handles) 460 if (NULL == testbed_handles)
461 { 461 {
@@ -542,8 +542,8 @@ get_iter (void *cls,
542 /* Summarize if profiling is complete */ 542 /* Summarize if profiling is complete */
543 if (n_active == n_gets_fail + n_gets_ok) 543 if (n_active == n_gets_fail + n_gets_ok)
544 { 544 {
545 average_put_path_length = total_put_path_length/n_active; 545 average_put_path_length = (double)total_put_path_length/(double)n_active;
546 average_get_path_length = total_get_path_length/n_active; 546 average_get_path_length = (double)total_get_path_length/(double)n_active;
547 summarize (); 547 summarize ();
548 } 548 }
549} 549}