diff options
author | Supriti Singh <supritisingh08@gmail.com> | 2014-04-13 19:45:42 +0000 |
---|---|---|
committer | Supriti Singh <supritisingh08@gmail.com> | 2014-04-13 19:45:42 +0000 |
commit | b69e3d6a0d84b7969a1d32708b7fc1cd088c5da5 (patch) | |
tree | 2a62113119a0937dd084aa6f03902b6bea1273a8 /src/dht | |
parent | c004e39e12ae8064a898bc218246c2eb379b1a9a (diff) | |
download | gnunet-b69e3d6a0d84b7969a1d32708b7fc1cd088c5da5.tar.gz gnunet-b69e3d6a0d84b7969a1d32708b7fc1cd088c5da5.zip |
changes in get and put code.
Diffstat (limited to 'src/dht')
-rw-r--r-- | src/dht/gnunet-service-xdht_clients.c | 10 | ||||
-rw-r--r-- | src/dht/gnunet-service-xdht_datacache.c | 14 | ||||
-rw-r--r-- | src/dht/gnunet-service-xdht_datacache.h | 3 | ||||
-rw-r--r-- | src/dht/gnunet-service-xdht_neighbours.c | 316 | ||||
-rw-r--r-- | src/dht/gnunet-service-xdht_neighbours.h | 5 |
5 files changed, 166 insertions, 182 deletions
diff --git a/src/dht/gnunet-service-xdht_clients.c b/src/dht/gnunet-service-xdht_clients.c index 17c95cc4c..b2803afd9 100644 --- a/src/dht/gnunet-service-xdht_clients.c +++ b/src/dht/gnunet-service-xdht_clients.c | |||
@@ -846,11 +846,11 @@ transmit_request (struct ClientQueryRecord *cqr) | |||
846 | 846 | ||
847 | /* FIXME: Here I am passing NULL for parameters check if its correct or | 847 | /* FIXME: Here I am passing NULL for parameters check if its correct or |
848 | not. */ | 848 | not. */ |
849 | #if 0 | 849 | FPRINTF (stderr,_("\nSUPU %s, %s, %d"),__FILE__, __func__,__LINE__); |
850 | GDS_NEIGHBOURS_handle_get (cqr->type, cqr->msg_options, cqr->replication, | 850 | GDS_NEIGHBOURS_handle_get (cqr->type, cqr->msg_options, cqr->replication, |
851 | 0 /* hop count */ ,NULL, NULL, 0, | 851 | 0 /* hop count */ ,NULL, 0, |
852 | &cqr->key, NULL, NULL, 0); | 852 | &cqr->key, NULL, NULL, NULL, 0); |
853 | #endif | 853 | |
854 | /* exponential back-off for retries. | 854 | /* exponential back-off for retries. |
855 | * max GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD (15 min) */ | 855 | * max GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD (15 min) */ |
856 | cqr->retry_frequency = GNUNET_TIME_STD_BACKOFF (cqr->retry_frequency); | 856 | cqr->retry_frequency = GNUNET_TIME_STD_BACKOFF (cqr->retry_frequency); |
@@ -913,7 +913,7 @@ handle_dht_local_put (void *cls, struct GNUNET_SERVER_Client *client, | |||
913 | struct PendingMessage *pm; | 913 | struct PendingMessage *pm; |
914 | struct GNUNET_DHT_ClientPutConfirmationMessage *conf; | 914 | struct GNUNET_DHT_ClientPutConfirmationMessage *conf; |
915 | uint16_t size; | 915 | uint16_t size; |
916 | 916 | FPRINTF (stderr,_("\nSUPU %s, %s, %d"),__FILE__, __func__,__LINE__); | |
917 | size = ntohs (message->size); | 917 | size = ntohs (message->size); |
918 | if (size < sizeof (struct GNUNET_DHT_ClientPutMessage)) | 918 | if (size < sizeof (struct GNUNET_DHT_ClientPutMessage)) |
919 | { | 919 | { |
diff --git a/src/dht/gnunet-service-xdht_datacache.c b/src/dht/gnunet-service-xdht_datacache.c index df2e17187..3af22e791 100644 --- a/src/dht/gnunet-service-xdht_datacache.c +++ b/src/dht/gnunet-service-xdht_datacache.c | |||
@@ -150,6 +150,11 @@ struct GetRequestContext | |||
150 | /** | 150 | /** |
151 | * | 151 | * |
152 | */ | 152 | */ |
153 | struct GNUNET_PeerIdentity source_peer; | ||
154 | |||
155 | /** | ||
156 | * | ||
157 | */ | ||
153 | unsigned int current_trail_index; | 158 | unsigned int current_trail_index; |
154 | 159 | ||
155 | /** | 160 | /** |
@@ -225,7 +230,8 @@ datacache_get_iterator (void *cls, | |||
225 | } | 230 | } |
226 | GDS_NEIGHBOURS_send_get_result (exp, key, put_path_length, put_path, | 231 | GDS_NEIGHBOURS_send_get_result (exp, key, put_path_length, put_path, |
227 | type, size, data, get_path, ctx->get_path_length, | 232 | type, size, data, get_path, ctx->get_path_length, |
228 | ctx->current_trail_index, &(ctx->next_hop)); | 233 | ctx->current_trail_index, &(ctx->next_hop), |
234 | &(ctx->source_peer)); | ||
229 | 235 | ||
230 | /* forward to other peers */ | 236 | /* forward to other peers */ |
231 | GDS_ROUTING_process (type, exp, key, put_path_length, put_path, 0, NULL, | 237 | GDS_ROUTING_process (type, exp, key, put_path_length, put_path, 0, NULL, |
@@ -290,7 +296,8 @@ GDS_DATACACHE_handle_get (const struct GNUNET_HashCode * key, | |||
290 | uint32_t get_path_length, | 296 | uint32_t get_path_length, |
291 | struct GNUNET_PeerIdentity *get_path, | 297 | struct GNUNET_PeerIdentity *get_path, |
292 | unsigned int current_trail_index, | 298 | unsigned int current_trail_index, |
293 | struct GNUNET_PeerIdentity *next_hop) | 299 | struct GNUNET_PeerIdentity *next_hop, |
300 | struct GNUNET_PeerIdentity *source_peer) | ||
294 | { | 301 | { |
295 | struct GetRequestContext ctx; | 302 | struct GetRequestContext ctx; |
296 | unsigned int r; | 303 | unsigned int r; |
@@ -307,7 +314,8 @@ GDS_DATACACHE_handle_get (const struct GNUNET_HashCode * key, | |||
307 | ctx.reply_bf = reply_bf; | 314 | ctx.reply_bf = reply_bf; |
308 | ctx.reply_bf_mutator = reply_bf_mutator; | 315 | ctx.reply_bf_mutator = reply_bf_mutator; |
309 | ctx.get_path_length = get_path_length; | 316 | ctx.get_path_length = get_path_length; |
310 | memcpy (&(ctx.next_hop), next_hop, sizeof (struct GNUNET_PeerIdentity)); | 317 | if (next_hop != NULL) |
318 | memcpy (&(ctx.next_hop), next_hop, sizeof (struct GNUNET_PeerIdentity)); | ||
311 | ctx.current_trail_index = current_trail_index; | 319 | ctx.current_trail_index = current_trail_index; |
312 | /* FIXME: add the get path into ctx and then call gds_neighbours_handle_get*/ | 320 | /* FIXME: add the get path into ctx and then call gds_neighbours_handle_get*/ |
313 | int i = 0; | 321 | int i = 0; |
diff --git a/src/dht/gnunet-service-xdht_datacache.h b/src/dht/gnunet-service-xdht_datacache.h index 38515d062..9b147612f 100644 --- a/src/dht/gnunet-service-xdht_datacache.h +++ b/src/dht/gnunet-service-xdht_datacache.h | |||
@@ -71,7 +71,8 @@ GDS_DATACACHE_handle_get (const struct GNUNET_HashCode * key, | |||
71 | uint32_t get_path_length, | 71 | uint32_t get_path_length, |
72 | struct GNUNET_PeerIdentity *get_path, | 72 | struct GNUNET_PeerIdentity *get_path, |
73 | unsigned int current_trail_index, | 73 | unsigned int current_trail_index, |
74 | struct GNUNET_PeerIdentity *next_hop); | 74 | struct GNUNET_PeerIdentity *next_hop, |
75 | struct GNUNET_PeerIdentity *source_peer); | ||
75 | 76 | ||
76 | 77 | ||
77 | /** | 78 | /** |
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c index 8d99d5414..7913b619b 100644 --- a/src/dht/gnunet-service-xdht_neighbours.c +++ b/src/dht/gnunet-service-xdht_neighbours.c | |||
@@ -186,31 +186,22 @@ struct PeerGetResultMessage | |||
186 | uint32_t type GNUNET_PACKED; | 186 | uint32_t type GNUNET_PACKED; |
187 | 187 | ||
188 | /** | 188 | /** |
189 | * Peer which is sending get result message. | ||
190 | */ | ||
191 | struct GNUNET_PeerIdentity source_peer; | ||
192 | |||
193 | /** | ||
194 | * Peer which will receive the get result message. | 189 | * Peer which will receive the get result message. |
195 | */ | 190 | */ |
196 | struct GNUNET_PeerIdentity destination_peer; | 191 | struct GNUNET_PeerIdentity source_peer; |
197 | 192 | ||
198 | /** | 193 | /** |
199 | * Current index in get path. | 194 | * Current index in get path. |
200 | */ | 195 | */ |
201 | unsigned int current_path_index; | 196 | unsigned int current_path_index; |
197 | |||
202 | /** | 198 | /** |
203 | * Number of peers recorded in the outgoing path from source to the | 199 | * Number of peers recorded in the outgoing path from source to the |
204 | * storgage location of this message. | 200 | * stored location of this message. |
205 | */ | 201 | */ |
206 | uint32_t put_path_length GNUNET_PACKED; | 202 | uint32_t put_path_length GNUNET_PACKED; |
207 | 203 | ||
208 | /** | 204 | /** |
209 | * When does this entry expire? | ||
210 | */ | ||
211 | struct GNUNET_TIME_AbsoluteNBO expiration; | ||
212 | |||
213 | /** | ||
214 | * Length of the GET path that follows (if tracked). | 205 | * Length of the GET path that follows (if tracked). |
215 | */ | 206 | */ |
216 | uint32_t get_path_length GNUNET_PACKED; | 207 | uint32_t get_path_length GNUNET_PACKED; |
@@ -218,7 +209,7 @@ struct PeerGetResultMessage | |||
218 | /** | 209 | /** |
219 | * When does the content expire? | 210 | * When does the content expire? |
220 | */ | 211 | */ |
221 | struct GNUNET_TIME_AbsoluteNBO expiration_time; | 212 | struct GNUNET_TIME_Absolute expiration_time; |
222 | 213 | ||
223 | /** | 214 | /** |
224 | * The key of the corresponding GET request. | 215 | * The key of the corresponding GET request. |
@@ -1627,7 +1618,6 @@ void finger_table_add (struct GNUNET_PeerIdentity *finger_identity, | |||
1627 | { | 1618 | { |
1628 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&(existing_finger->finger_identity),finger_identity)) | 1619 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&(existing_finger->finger_identity),finger_identity)) |
1629 | { | 1620 | { |
1630 | FPRINTF (stderr,_("\nSUPU Entries are same. %s, %s, %d"), __FILE__, __func__,__LINE__); | ||
1631 | /* FIXME: Here you should check if the trail is same. If yes then don't add the entry. it | 1621 | /* FIXME: Here you should check if the trail is same. If yes then don't add the entry. it |
1632 | seems to be very suboptimal. */ | 1622 | seems to be very suboptimal. */ |
1633 | if ((existing_finger->trail_length) == trail_length) | 1623 | if ((existing_finger->trail_length) == trail_length) |
@@ -1656,20 +1646,17 @@ void finger_table_add (struct GNUNET_PeerIdentity *finger_identity, | |||
1656 | int ret; | 1646 | int ret; |
1657 | if (finger_map_index == 1) | 1647 | if (finger_map_index == 1) |
1658 | { | 1648 | { |
1659 | FPRINTF (stderr,_("\nSUPUP Predecessor are different %s, %s, %d"), __FILE__, __func__,__LINE__); | ||
1660 | ret = compare_predecessor (&(existing_finger->finger_identity), | 1649 | ret = compare_predecessor (&(existing_finger->finger_identity), |
1661 | finger_identity); | 1650 | finger_identity); |
1662 | goto add_new_entry; | 1651 | goto add_new_entry; |
1663 | } | 1652 | } |
1664 | else | 1653 | else |
1665 | { | 1654 | { |
1666 | FPRINTF (stderr,_("\nSUPU %s, %s, %d"), __FILE__, __func__,__LINE__); | ||
1667 | ret = compare_finger_identity (&(existing_finger->finger_identity), | 1655 | ret = compare_finger_identity (&(existing_finger->finger_identity), |
1668 | finger_identity); | 1656 | finger_identity); |
1669 | } | 1657 | } |
1670 | if (ret > 0) | 1658 | if (ret > 0) |
1671 | { | 1659 | { |
1672 | FPRINTF (stderr,_("\nSUPU Adding the new one and removing the old one %s, %s, %d"), __FILE__, __func__,__LINE__); | ||
1673 | GNUNET_assert (GNUNET_YES == | 1660 | GNUNET_assert (GNUNET_YES == |
1674 | GNUNET_CONTAINER_multipeermap_remove (finger_peermap, | 1661 | GNUNET_CONTAINER_multipeermap_remove (finger_peermap, |
1675 | &(existing_finger->finger_identity), | 1662 | &(existing_finger->finger_identity), |
@@ -1678,7 +1665,6 @@ void finger_table_add (struct GNUNET_PeerIdentity *finger_identity, | |||
1678 | } | 1665 | } |
1679 | else | 1666 | else |
1680 | { | 1667 | { |
1681 | FPRINTF (stderr,_("\nSUPU Nothing to do return %s, %s, %d"), __FILE__, __func__,__LINE__); | ||
1682 | return; | 1668 | return; |
1683 | } | 1669 | } |
1684 | } | 1670 | } |
@@ -1722,45 +1708,7 @@ void finger_table_add (struct GNUNET_PeerIdentity *finger_identity, | |||
1722 | GNUNET_CONTAINER_multipeermap_put (finger_peermap, | 1708 | GNUNET_CONTAINER_multipeermap_put (finger_peermap, |
1723 | &(new_finger_entry->finger_identity), | 1709 | &(new_finger_entry->finger_identity), |
1724 | new_finger_entry, | 1710 | new_finger_entry, |
1725 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); /* Fixme: change to multiple */ | 1711 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
1726 | /* SUPU TEST CODE */ | ||
1727 | /* Here I want to iterate over finger peer map, print its id and the trail | ||
1728 | to reach to the finger. */ | ||
1729 | int test_index; | ||
1730 | struct GNUNET_CONTAINER_MultiPeerMapIterator *test_iter; | ||
1731 | struct FingerInfo *test_finger; | ||
1732 | test_iter = GNUNET_CONTAINER_multipeermap_iterator_create (finger_peermap); | ||
1733 | FPRINTF (stderr,_("\nSUPU #### %s, %s, %d, size = %d####"),__FILE__, __func__,__LINE__,GNUNET_CONTAINER_multipeermap_size (finger_peermap)); | ||
1734 | for (test_index = 0; test_index < GNUNET_CONTAINER_multipeermap_size (finger_peermap); test_index++) | ||
1735 | { | ||
1736 | FPRINTF (stderr,_("\nSUPU *********%s, %s, %d, %d entry*********"),__FILE__, __func__,__LINE__,test_index); | ||
1737 | if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next (test_iter, &key_ret, | ||
1738 | (const void **)&test_finger)) | ||
1739 | { | ||
1740 | FPRINTF (stderr,_("\nSUPU %s, %s, %d "),__FILE__, __func__,__LINE__); | ||
1741 | struct GNUNET_PeerIdentity *print_peer; | ||
1742 | struct TrailPeerList *iterator; | ||
1743 | int z; | ||
1744 | iterator = GNUNET_malloc (sizeof (struct TrailPeerList)); | ||
1745 | print_peer = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | ||
1746 | memcpy (print_peer, &(test_finger->finger_identity), sizeof (struct GNUNET_PeerIdentity)); | ||
1747 | FPRINTF (stderr,_("\nSUPU %s, %s, %d, finger_index = %d"), __FILE__, __func__,__LINE__,test_finger->finger_map_index); | ||
1748 | FPRINTF (stderr,_("\nSUPU %s, %s, %d, finger_identity = %s"), | ||
1749 | __FILE__, __func__,__LINE__, GNUNET_i2s (print_peer)); | ||
1750 | iterator = test_finger->head; | ||
1751 | z = 0; | ||
1752 | while (z < test_finger->trail_length) | ||
1753 | { | ||
1754 | memcpy (print_peer, &(iterator->peer), sizeof (struct GNUNET_PeerIdentity)); | ||
1755 | FPRINTF (stderr,_("\nSUPU %s, %s, %d, trail[%d] = %s"),__FILE__, __func__,__LINE__,z,GNUNET_i2s (print_peer)); | ||
1756 | z++; | ||
1757 | iterator = iterator->next; | ||
1758 | } | ||
1759 | } | ||
1760 | } | ||
1761 | FPRINTF (stderr,_("\nSUPU End of loop%s, %s, %d"),__FILE__, __func__,__LINE__); | ||
1762 | /* SUPU TEST CODE ENDS */ | ||
1763 | |||
1764 | 1712 | ||
1765 | if (1 == GNUNET_CONTAINER_multipeermap_size (finger_peermap) | 1713 | if (1 == GNUNET_CONTAINER_multipeermap_size (finger_peermap) |
1766 | && (new_finger_entry->finger_map_index!= 1)) | 1714 | && (new_finger_entry->finger_map_index!= 1)) |
@@ -1962,10 +1910,11 @@ find_successor (uint64_t value, struct GNUNET_PeerIdentity *current_destination, | |||
1962 | * @param desired_replication_level desired replication count | 1910 | * @param desired_replication_level desired replication count |
1963 | * @param hop_count how many hops did this request traverse so far? | 1911 | * @param hop_count how many hops did this request traverse so far? |
1964 | * @param get_peer_path Peer list to reach to final destination which contains the data. | 1912 | * @param get_peer_path Peer list to reach to final destination which contains the data. |
1965 | * @param get_path_length Total numbers of peer in get_path | 1913 | * @param get_path_length Total numbers of peer in @a get_path |
1966 | * @param key Key key for the content | 1914 | * @param key Key key for the content |
1967 | * @param target_peer Next peer to forward the message to. | 1915 | * @param target_peer Next peer to forward the message to. |
1968 | * @param current_destination Peer which will get this message. | 1916 | * @param current_destination Peer which will get this message. |
1917 | * @param current_source Peer for @a current_destination is the finger. | ||
1969 | * @param current_dest_type Type of current destination can be either FRIEND or FINGER | 1918 | * @param current_dest_type Type of current destination can be either FRIEND or FINGER |
1970 | */ | 1919 | */ |
1971 | void | 1920 | void |
@@ -1979,15 +1928,19 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type block_type, | |||
1979 | struct GNUNET_PeerIdentity *target_peer, | 1928 | struct GNUNET_PeerIdentity *target_peer, |
1980 | struct GNUNET_PeerIdentity *current_destination, | 1929 | struct GNUNET_PeerIdentity *current_destination, |
1981 | struct GNUNET_PeerIdentity *current_source, | 1930 | struct GNUNET_PeerIdentity *current_source, |
1982 | enum current_destination_type *current_dest_type) | 1931 | enum current_destination_type current_dest_type) |
1983 | { | 1932 | { |
1984 | struct PeerGetMessage *get_request; | 1933 | struct PeerGetMessage *get_request; |
1985 | struct P2PPendingMessage *pending; | 1934 | struct P2PPendingMessage *pending; |
1986 | struct GNUNET_PeerIdentity *get_path; | 1935 | struct GNUNET_PeerIdentity *get_path; |
1987 | struct FriendInfo *target_friend; | 1936 | struct FriendInfo *target_friend; |
1937 | struct GNUNET_PeerIdentity *next_hop; | ||
1938 | struct GNUNET_PeerIdentity *current_dest; | ||
1939 | enum current_destination_type dest_type; | ||
1988 | uint64_t key_value; | 1940 | uint64_t key_value; |
1989 | size_t msize; | 1941 | size_t msize; |
1990 | 1942 | ||
1943 | FPRINTF (stderr,_("\nSUPU %s, %s, %d"),__FILE__, __func__,__LINE__); | ||
1991 | msize = sizeof (struct PeerGetMessage) + | 1944 | msize = sizeof (struct PeerGetMessage) + |
1992 | (get_path_length * sizeof (struct GNUNET_PeerIdentity)); | 1945 | (get_path_length * sizeof (struct GNUNET_PeerIdentity)); |
1993 | 1946 | ||
@@ -1998,39 +1951,34 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type block_type, | |||
1998 | } | 1951 | } |
1999 | 1952 | ||
2000 | memcpy (&key_value, key, sizeof (uint64_t)); | 1953 | memcpy (&key_value, key, sizeof (uint64_t)); |
2001 | 1954 | ||
2002 | /* FIXME: Is this correct comparison? */ | ||
2003 | if (NULL == target_peer) | 1955 | if (NULL == target_peer) |
2004 | { | 1956 | { |
2005 | /* We have received the request from the client file and we don't know | 1957 | FPRINTF (stderr,_("\nSUPU %s, %s, %d"),__FILE__, __func__,__LINE__); |
2006 | to which peer should we forward the message to. */ | 1958 | current_dest = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
2007 | struct GNUNET_PeerIdentity *next_hop; | 1959 | dest_type = MY_ID; |
2008 | next_hop = find_successor (key_value, current_destination, current_dest_type); | 1960 | next_hop = find_successor (key_value, current_dest, &dest_type); |
2009 | 1961 | ||
2010 | if (*current_dest_type == MY_ID) | 1962 | if (dest_type == MY_ID) |
2011 | { | 1963 | { |
1964 | FPRINTF (stderr,_("\nSUPU %s, %s, %d"),__FILE__, __func__,__LINE__); | ||
2012 | get_path = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 1965 | get_path = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
2013 | memcpy (get_path, &my_identity, sizeof (struct GNUNET_PeerIdentity)); | 1966 | memcpy (get_path, &my_identity, sizeof (struct GNUNET_PeerIdentity)); |
2014 | get_path_length = 1; | 1967 | get_path_length = 1; |
2015 | /* FIXME: At the moment I am just passing null,0 for values which I don't | 1968 | GDS_DATACACHE_handle_get (key,block_type, NULL, 0, |
2016 | have. Also, handle return type. Modify this function and pass get path | 1969 | NULL, 0, get_path_length, get_path, 0, NULL,&my_identity); |
2017 | and get path length and then in datacache_handle. here in this case | ||
2018 | you can diretly call gds_client_handle_reply. */ | ||
2019 | #if 0 | ||
2020 | GDS_DATACACHE_handle_get (&(get_request->key),(get_request->block_type), | ||
2021 | get_path, get_path_length,get_path_length - 1,NULL); | ||
2022 | #endif | ||
2023 | return; | 1970 | return; |
2024 | } | 1971 | } |
2025 | else | 1972 | else |
2026 | { | 1973 | { |
2027 | if (*current_dest_type == FINGER) | 1974 | if (dest_type == FINGER) |
2028 | { | 1975 | { |
2029 | memcpy (current_source, &my_identity, sizeof (struct GNUNET_PeerIdentity)); | 1976 | memcpy (current_source, &my_identity, sizeof (struct GNUNET_PeerIdentity)); |
2030 | } | 1977 | } |
2031 | |||
2032 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | 1978 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); |
2033 | } | 1979 | } |
1980 | current_dest_type = dest_type; | ||
1981 | |||
2034 | } | 1982 | } |
2035 | else | 1983 | else |
2036 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer); | 1984 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer); |
@@ -2043,13 +1991,17 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type block_type, | |||
2043 | get_request->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_GET); | 1991 | get_request->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_GET); |
2044 | get_request->get_path_length = htonl (get_path_length); | 1992 | get_request->get_path_length = htonl (get_path_length); |
2045 | get_request->key = *key; | 1993 | get_request->key = *key; |
2046 | memcpy (&(get_request->current_destination), current_destination, sizeof (struct GNUNET_PeerIdentity)); | 1994 | if (current_destination != NULL) |
1995 | memcpy (&(get_request->current_destination), current_destination, sizeof (struct GNUNET_PeerIdentity)); | ||
1996 | else | ||
1997 | memcpy (&(get_request->current_destination), current_dest, sizeof (struct GNUNET_PeerIdentity)); | ||
2047 | /* FIXME: Is this comparison correct? */ | 1998 | /* FIXME: Is this comparison correct? */ |
2048 | if (current_source != NULL) | 1999 | if (current_source != NULL) |
2049 | memcpy (&(get_request->current_source), current_source, sizeof (struct GNUNET_PeerIdentity)); | 2000 | memcpy (&(get_request->current_source), current_source, sizeof (struct GNUNET_PeerIdentity)); |
2050 | get_request->current_dest_type = htonl (*current_dest_type); | 2001 | get_request->current_dest_type = htonl (current_dest_type); |
2051 | get_path = (struct GNUNET_PeerIdentity *) &get_request[1]; | 2002 | get_path = (struct GNUNET_PeerIdentity *) &get_request[1]; |
2052 | memcpy (get_path, get_peer_path, get_path_length * sizeof (struct GNUNET_PeerIdentity)); | 2003 | if (get_path_length > 0) |
2004 | memcpy (get_path, get_peer_path, get_path_length * sizeof (struct GNUNET_PeerIdentity)); | ||
2053 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); | 2005 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); |
2054 | target_friend->pending_count++; | 2006 | target_friend->pending_count++; |
2055 | process_friend_queue (target_friend); | 2007 | process_friend_queue (target_friend); |
@@ -2128,6 +2080,9 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type block_type, | |||
2128 | struct P2PPendingMessage *pending; | 2080 | struct P2PPendingMessage *pending; |
2129 | struct FriendInfo *target_friend; | 2081 | struct FriendInfo *target_friend; |
2130 | struct GNUNET_PeerIdentity *pp; | 2082 | struct GNUNET_PeerIdentity *pp; |
2083 | struct GNUNET_PeerIdentity *next_hop; | ||
2084 | struct GNUNET_PeerIdentity *current_dest; | ||
2085 | enum current_destination_type curr_dest_type; | ||
2131 | size_t msize; | 2086 | size_t msize; |
2132 | uint64_t key_value; | 2087 | uint64_t key_value; |
2133 | 2088 | ||
@@ -2147,20 +2102,19 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type block_type, | |||
2147 | } | 2102 | } |
2148 | 2103 | ||
2149 | memcpy (&key_value, key, sizeof (uint64_t)); | 2104 | memcpy (&key_value, key, sizeof (uint64_t)); |
2150 | struct GNUNET_PeerIdentity *current_dest; | 2105 | |
2151 | current_dest = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | ||
2152 | if (target_peer == NULL) | 2106 | if (target_peer == NULL) |
2153 | { | 2107 | { |
2154 | /* This is the first time the call has been made from handle_dht_local_put. | 2108 | FPRINTF (stderr,_("\nSUPU %s, %s, %d"),__FILE__, __func__,__LINE__); |
2155 | So, you need to search for the next peer to send this message to. */ | 2109 | curr_dest_type = MY_ID; |
2156 | struct GNUNET_PeerIdentity *next_hop; | 2110 | current_dest = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
2157 | 2111 | next_hop = find_successor (key_value, current_dest, &curr_dest_type); | |
2158 | next_hop = find_successor (key_value, current_dest, &dest_type); | 2112 | if (curr_dest_type == MY_ID) |
2159 | if (dest_type == MY_ID) | ||
2160 | { | 2113 | { |
2161 | /* FIXME: Choose one place to do datacache_put. I am doing put only if its | 2114 | /* FIXME: Choose one place to do datacache_put. I am doing put only if its |
2162 | destination so I will do no put operation | 2115 | destination so I will do no put operation |
2163 | in the client file.*/ | 2116 | in the client file.*/ |
2117 | FPRINTF (stderr,_("\nSUPU %s, %s, %d"),__FILE__, __func__,__LINE__); | ||
2164 | GDS_DATACACHE_handle_put (expiration_time, key, put_path_length, put_path, | 2118 | GDS_DATACACHE_handle_put (expiration_time, key, put_path_length, put_path, |
2165 | block_type, data_size, data); | 2119 | block_type, data_size, data); |
2166 | return; | 2120 | return; |
@@ -2168,12 +2122,14 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type block_type, | |||
2168 | else | 2122 | else |
2169 | { | 2123 | { |
2170 | /* Find the friend corresponding to next_hop */ | 2124 | /* Find the friend corresponding to next_hop */ |
2171 | if (dest_type == FINGER) | 2125 | if (curr_dest_type == FINGER) |
2172 | { | 2126 | { |
2127 | FPRINTF (stderr,_("\nSUPU %s, %s, %d"),__FILE__, __func__,__LINE__); | ||
2173 | memcpy (current_source, &my_identity, sizeof (struct GNUNET_PeerIdentity)); | 2128 | memcpy (current_source, &my_identity, sizeof (struct GNUNET_PeerIdentity)); |
2174 | } | 2129 | } |
2175 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | 2130 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); |
2176 | } | 2131 | } |
2132 | dest_type = curr_dest_type; | ||
2177 | } | 2133 | } |
2178 | else | 2134 | else |
2179 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer); | 2135 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer); |
@@ -2191,14 +2147,16 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type block_type, | |||
2191 | ppm->desired_replication_level = htonl (desired_replication_level); | 2147 | ppm->desired_replication_level = htonl (desired_replication_level); |
2192 | ppm->put_path_length = htonl (put_path_length); | 2148 | ppm->put_path_length = htonl (put_path_length); |
2193 | ppm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time); | 2149 | ppm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time); |
2150 | ppm->current_destination_type = dest_type; | ||
2194 | /* FIXME: Here I am checking if we have a value in current_source then only copy. | 2151 | /* FIXME: Here I am checking if we have a value in current_source then only copy. |
2195 | I am not sure if this checking is correct or not. */ | 2152 | I am not sure if this checking is correct or not. */ |
2196 | if (current_source != NULL) | 2153 | if (current_source != NULL) |
2154 | { | ||
2155 | FPRINTF (stderr,_("\nSUPU %s, %s, %d"),__FILE__, __func__,__LINE__); | ||
2197 | memcpy (&(ppm->current_source), current_source, sizeof (struct GNUNET_PeerIdentity)); | 2156 | memcpy (&(ppm->current_source), current_source, sizeof (struct GNUNET_PeerIdentity)); |
2198 | 2157 | } | |
2199 | /* FIXME: here current_destination is the parameter, current_dest is what you | 2158 | else |
2200 | get when you call find_successor. names don't do justice to the function. | 2159 | FPRINTF (stderr,_("\nSUPU %s, %s, %d"),__FILE__, __func__,__LINE__); |
2201 | Please change it*/ | ||
2202 | if (current_destination != NULL) | 2160 | if (current_destination != NULL) |
2203 | memcpy (&(ppm->current_destination), current_destination, sizeof (struct GNUNET_PeerIdentity)); | 2161 | memcpy (&(ppm->current_destination), current_destination, sizeof (struct GNUNET_PeerIdentity)); |
2204 | else | 2162 | else |
@@ -2223,11 +2181,6 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type block_type, | |||
2223 | 2181 | ||
2224 | 2182 | ||
2225 | /** | 2183 | /** |
2226 | * FIXME: I am removing source peer as the first element in the trail | ||
2227 | * is source identity. | ||
2228 | * If I am adding myself when I am source then I don't need destination | ||
2229 | * peer in get but if I am not adding then I need it. At the moment I am removing | ||
2230 | * it but will check later if its wrong. | ||
2231 | * Send get result back to requesting client. | 2184 | * Send get result back to requesting client. |
2232 | * @param expiration when will the reply expire | 2185 | * @param expiration when will the reply expire |
2233 | * @param key the query this reply is for | 2186 | * @param key the query this reply is for |
@@ -2251,10 +2204,12 @@ GDS_NEIGHBOURS_send_get_result (struct GNUNET_TIME_Absolute expiration, | |||
2251 | struct GNUNET_PeerIdentity *get_path, | 2204 | struct GNUNET_PeerIdentity *get_path, |
2252 | unsigned int get_path_length, | 2205 | unsigned int get_path_length, |
2253 | unsigned int current_path_index, | 2206 | unsigned int current_path_index, |
2254 | struct GNUNET_PeerIdentity *next_hop) | 2207 | struct GNUNET_PeerIdentity *next_hop, |
2208 | struct GNUNET_PeerIdentity *source_peer) | ||
2255 | { | 2209 | { |
2256 | struct PeerGetResultMessage *get_result; | 2210 | struct PeerGetResultMessage *get_result; |
2257 | struct GNUNET_PeerIdentity *get_result_path; | 2211 | struct GNUNET_PeerIdentity *get_result_path; |
2212 | struct GNUNET_PeerIdentity *pp; | ||
2258 | struct P2PPendingMessage *pending; | 2213 | struct P2PPendingMessage *pending; |
2259 | struct FriendInfo *target_friend; | 2214 | struct FriendInfo *target_friend; |
2260 | size_t msize; | 2215 | size_t msize; |
@@ -2267,23 +2222,32 @@ GDS_NEIGHBOURS_send_get_result (struct GNUNET_TIME_Absolute expiration, | |||
2267 | GNUNET_break (0); | 2222 | GNUNET_break (0); |
2268 | return; | 2223 | return; |
2269 | } | 2224 | } |
2270 | /* GET_REULT should have all the things which we want to pass in client_handle_reply | 2225 | |
2271 | put path put path length get path get length data data_size. and rest things | 2226 | if (current_path_index == 0) |
2272 | are required to reach to the correct peer. */ | 2227 | { |
2228 | FPRINTF (stderr,_("\nSUPU %s, %s, %d"),__FILE__, __func__,__LINE__); | ||
2229 | GDS_CLIENTS_handle_reply (expiration, key, get_path_length, get_path, put_path_length, | ||
2230 | put_path, type, data_size, data); | ||
2231 | return; | ||
2232 | } | ||
2273 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | 2233 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); |
2274 | pending->importance = 0; /* FIXME */ | 2234 | pending->importance = 0; |
2275 | /* FIXME: Should we add an expiration time like in put message. */ | ||
2276 | get_result = (struct PeerGetResultMessage *)&pending[1]; | 2235 | get_result = (struct PeerGetResultMessage *)&pending[1]; |
2277 | pending->msg = &get_result->header; | 2236 | pending->msg = &get_result->header; |
2278 | get_result->header.size = htons (msize); | 2237 | get_result->header.size = htons (msize); |
2279 | get_result->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_GET_RESULT); | 2238 | get_result->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_GET_RESULT); |
2280 | get_result->current_path_index = current_path_index; | 2239 | get_result->current_path_index = current_path_index; |
2281 | get_result->key = *key; | 2240 | get_result->key = *key; |
2241 | memcpy (&(get_result->source_peer), source_peer, sizeof (struct GNUNET_PeerIdentity)); | ||
2242 | get_result->expiration_time = expiration; | ||
2282 | 2243 | ||
2283 | get_result_path = (struct GNUNET_PeerIdentity *)&get_result[1]; | 2244 | get_result_path = (struct GNUNET_PeerIdentity *)&get_result[1]; |
2284 | memcpy (get_result_path, get_path, | 2245 | memcpy (get_result_path, get_path, |
2285 | sizeof (struct GNUNET_PeerIdentity) * get_path_length); | 2246 | sizeof (struct GNUNET_PeerIdentity) * get_path_length); |
2286 | memcpy (&get_result_path[get_path_length], data, data_size); | 2247 | memcpy (&get_result_path[get_path_length], data, data_size); |
2248 | /* FIXME: Is this correct? */ | ||
2249 | pp = (struct GNUNET_PeerIdentity *)&get_result_path[1]; | ||
2250 | memcpy (pp, put_path,sizeof (struct GNUNET_PeerIdentity) * put_path_length); | ||
2287 | 2251 | ||
2288 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | 2252 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); |
2289 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); | 2253 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); |
@@ -2307,10 +2271,12 @@ handle_dht_p2p_get_result (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2307 | the requesting client and send back the result. */ | 2271 | the requesting client and send back the result. */ |
2308 | struct PeerGetResultMessage *get_result; | 2272 | struct PeerGetResultMessage *get_result; |
2309 | struct GNUNET_PeerIdentity *get_path; | 2273 | struct GNUNET_PeerIdentity *get_path; |
2310 | //void *payload; | 2274 | struct GNUNET_PeerIdentity *put_path; |
2311 | //size_t payload_size; | 2275 | void *payload; |
2276 | size_t payload_size; | ||
2312 | size_t msize; | 2277 | size_t msize; |
2313 | unsigned int getlen; | 2278 | unsigned int getlen; |
2279 | unsigned int putlen; | ||
2314 | int current_path_index; | 2280 | int current_path_index; |
2315 | 2281 | ||
2316 | msize = ntohs (message->size); | 2282 | msize = ntohs (message->size); |
@@ -2322,53 +2288,51 @@ handle_dht_p2p_get_result (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2322 | 2288 | ||
2323 | get_result = (struct PeerGetResultMessage *)message; | 2289 | get_result = (struct PeerGetResultMessage *)message; |
2324 | getlen = ntohl (get_result->get_path_length); | 2290 | getlen = ntohl (get_result->get_path_length); |
2291 | putlen = ntohl (get_result->put_path_length); | ||
2325 | 2292 | ||
2326 | if ((msize < | 2293 | if ((msize < |
2327 | sizeof (struct PeerGetResultMessage) + | 2294 | sizeof (struct PeerGetResultMessage) + |
2328 | getlen * sizeof (struct GNUNET_PeerIdentity)) || | 2295 | getlen * sizeof (struct GNUNET_PeerIdentity) + |
2296 | putlen * sizeof (struct GNUNET_PeerIdentity)) || | ||
2329 | (getlen > | 2297 | (getlen > |
2330 | GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity))) | 2298 | GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity) || |
2299 | (putlen > | ||
2300 | GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)))) | ||
2331 | { | 2301 | { |
2332 | GNUNET_break_op (0); | 2302 | GNUNET_break_op (0); |
2333 | return GNUNET_YES; | 2303 | return GNUNET_YES; |
2334 | } | 2304 | } |
2335 | 2305 | ||
2336 | /* FIXME: Get the put_path */ | ||
2337 | get_path = (struct GNUNET_PeerIdentity *) &get_result[1]; | 2306 | get_path = (struct GNUNET_PeerIdentity *) &get_result[1]; |
2338 | //payload = &get_path[getlen]; | 2307 | payload = &get_path[getlen]; |
2339 | /* payload_size = msize - (sizeof (struct PeerGetResultMessage) + | 2308 | payload_size = msize - (sizeof (struct PeerGetResultMessage) + |
2340 | getlen * sizeof (struct GNUNET_PeerIdentity));*/ | 2309 | getlen * sizeof (struct GNUNET_PeerIdentity)); |
2341 | current_path_index = ntohl (get_result->current_path_index); | 2310 | /* FIXME: Check if its correct or not. */ |
2311 | if (putlen > 0) | ||
2312 | put_path = &get_path[1]; | ||
2342 | 2313 | ||
2343 | /* Here you just have to check if you are the destination or not if not | 2314 | current_path_index = ntohl (get_result->current_path_index); |
2344 | then read the next peer and send the message. */ | 2315 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &(get_path[0])))) |
2345 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &(get_result->destination_peer)))) | ||
2346 | { | 2316 | { |
2347 | /* I am the destination. Call the function in client file. | ||
2348 | * FIXME: Here I don't know how I communicate the result back to client | ||
2349 | file. */ | ||
2350 | //GDS_CLIENTS_process_get_result(); | 2317 | //GDS_CLIENTS_process_get_result(); |
2318 | GDS_CLIENTS_handle_reply (get_result->expiration_time, &(get_result->key), | ||
2319 | getlen, get_path, putlen, | ||
2320 | put_path, get_result->type, payload_size, payload); | ||
2351 | return GNUNET_YES; | 2321 | return GNUNET_YES; |
2352 | } | 2322 | } |
2353 | else | 2323 | else |
2354 | { | 2324 | { |
2355 | /* Read the element from the get path at trail index. set the trail index | ||
2356 | and call gds_neighbours_send_get_result.*/ | ||
2357 | struct GNUNET_PeerIdentity *next_hop; | 2325 | struct GNUNET_PeerIdentity *next_hop; |
2358 | |||
2359 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 2326 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
2360 | memcpy (next_hop, &get_path[current_path_index], sizeof (struct GNUNET_PeerIdentity)); | ||
2361 | |||
2362 | |||
2363 | if (current_path_index != 0) | 2327 | if (current_path_index != 0) |
2364 | current_path_index--; | 2328 | current_path_index--; |
2365 | #if 0 | 2329 | memcpy (next_hop, &get_path[current_path_index], sizeof (struct GNUNET_PeerIdentity)); |
2366 | GDS_NEIGHBOURS_send_get_result ((get_result->expiration), get_result->key, | 2330 | |
2367 | get_result->put_path_length, put_path, | 2331 | GDS_NEIGHBOURS_send_get_result (get_result->expiration_time, &(get_result->key), |
2368 | get_result->type, payload, payload_size | 2332 | putlen, put_path, |
2333 | get_result->type, payload_size,payload, | ||
2369 | get_path, getlen,current_path_index, | 2334 | get_path, getlen,current_path_index, |
2370 | next_hop); | 2335 | next_hop, &(get_result->source_peer)); |
2371 | #endif | ||
2372 | return GNUNET_YES; | 2336 | return GNUNET_YES; |
2373 | } | 2337 | } |
2374 | return GNUNET_SYSERR; | 2338 | return GNUNET_SYSERR; |
@@ -2376,6 +2340,8 @@ handle_dht_p2p_get_result (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2376 | 2340 | ||
2377 | 2341 | ||
2378 | /** | 2342 | /** |
2343 | * FIXME: Can refactor the code where we are setting the current source and | ||
2344 | * current_dest_type | ||
2379 | * Core handler for p2p put requests. | 2345 | * Core handler for p2p put requests. |
2380 | * | 2346 | * |
2381 | * @param cls closure | 2347 | * @param cls closure |
@@ -2394,6 +2360,7 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2394 | enum GNUNET_DHT_RouteOption options; | 2360 | enum GNUNET_DHT_RouteOption options; |
2395 | enum current_destination_type current_dst_type; | 2361 | enum current_destination_type current_dst_type; |
2396 | struct GNUNET_PeerIdentity *current_destination; | 2362 | struct GNUNET_PeerIdentity *current_destination; |
2363 | struct GNUNET_PeerIdentity *current_source; | ||
2397 | struct GNUNET_PeerIdentity *next_hop; | 2364 | struct GNUNET_PeerIdentity *next_hop; |
2398 | struct GNUNET_HashCode test_key; | 2365 | struct GNUNET_HashCode test_key; |
2399 | uint64_t key_value; | 2366 | uint64_t key_value; |
@@ -2402,9 +2369,15 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2402 | size_t msize; | 2369 | size_t msize; |
2403 | uint32_t putlen; | 2370 | uint32_t putlen; |
2404 | 2371 | ||
2372 | msize = ntohs (message->size); | ||
2373 | if (msize < sizeof (struct PeerPutMessage)) | ||
2374 | { | ||
2375 | GNUNET_break_op (0); | ||
2376 | return GNUNET_YES; | ||
2377 | } | ||
2378 | |||
2405 | put = (struct PeerPutMessage *) message; | 2379 | put = (struct PeerPutMessage *) message; |
2406 | putlen = ntohl (put->put_path_length); | 2380 | putlen = ntohl (put->put_path_length); |
2407 | msize = ntohs (message->size); | ||
2408 | 2381 | ||
2409 | if ((msize < | 2382 | if ((msize < |
2410 | sizeof (struct PeerPutMessage) + | 2383 | sizeof (struct PeerPutMessage) + |
@@ -2473,6 +2446,7 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2473 | struct GNUNET_PeerIdentity pp[putlen + 1]; | 2446 | struct GNUNET_PeerIdentity pp[putlen + 1]; |
2474 | 2447 | ||
2475 | /* extend 'put path' by sender */ | 2448 | /* extend 'put path' by sender */ |
2449 | /* FIXME: Check what are we doing here? */ | ||
2476 | if (0 != (options & GNUNET_DHT_RO_RECORD_ROUTE)) | 2450 | if (0 != (options & GNUNET_DHT_RO_RECORD_ROUTE)) |
2477 | { | 2451 | { |
2478 | memcpy (pp, put_path, putlen * sizeof (struct GNUNET_PeerIdentity)); | 2452 | memcpy (pp, put_path, putlen * sizeof (struct GNUNET_PeerIdentity)); |
@@ -2486,21 +2460,34 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2486 | memcpy (current_destination, &(put->current_destination), sizeof (struct GNUNET_PeerIdentity)); | 2460 | memcpy (current_destination, &(put->current_destination), sizeof (struct GNUNET_PeerIdentity)); |
2487 | current_dst_type = ntohl (put->current_destination_type); | 2461 | current_dst_type = ntohl (put->current_destination_type); |
2488 | memcpy (&key_value, &(put->key), sizeof (uint64_t)); | 2462 | memcpy (&key_value, &(put->key), sizeof (uint64_t)); |
2489 | 2463 | current_source = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | |
2490 | if (current_dst_type == FRIEND) | 2464 | if (current_dst_type == FRIEND) |
2491 | { | 2465 | { |
2492 | next_hop = find_successor (key_value, current_destination, ¤t_dst_type); | 2466 | next_hop = find_successor (key_value, current_destination, ¤t_dst_type); |
2467 | if (current_dst_type == FINGER) | ||
2468 | { | ||
2469 | memcpy (current_source, &my_identity, sizeof (struct GNUNET_PeerIdentity)); | ||
2470 | } | ||
2471 | else | ||
2472 | current_source = NULL; | ||
2493 | } | 2473 | } |
2494 | else if (current_dst_type == FINGER) | 2474 | else if (current_dst_type == FINGER) |
2495 | { | 2475 | { |
2496 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, current_destination)) | 2476 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, current_destination)) |
2497 | { | 2477 | { |
2498 | next_hop = find_successor (key_value, current_destination, ¤t_dst_type); | 2478 | next_hop = find_successor (key_value, current_destination, ¤t_dst_type); |
2479 | if (current_dst_type == FINGER) | ||
2480 | { | ||
2481 | memcpy (current_source, &my_identity, sizeof (struct GNUNET_PeerIdentity)); | ||
2482 | } | ||
2483 | else | ||
2484 | current_source = NULL; | ||
2499 | } | 2485 | } |
2500 | else | 2486 | else |
2501 | { | 2487 | { |
2502 | next_hop = GDS_ROUTING_search (&(put->current_source), current_destination, peer); | 2488 | next_hop = GDS_ROUTING_search (&(put->current_source), current_destination, peer); |
2503 | current_dst_type = FRIEND; | 2489 | memcpy (current_source, &(put->current_source), sizeof (struct GNUNET_PeerIdentity)); |
2490 | current_dst_type = FINGER; | ||
2504 | } | 2491 | } |
2505 | } | 2492 | } |
2506 | 2493 | ||
@@ -2513,15 +2500,6 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2513 | } | 2500 | } |
2514 | else | 2501 | else |
2515 | { | 2502 | { |
2516 | struct GNUNET_PeerIdentity *current_source; | ||
2517 | if (current_dst_type == FINGER) | ||
2518 | { | ||
2519 | current_source = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | ||
2520 | memcpy (current_source, &my_identity, sizeof (struct GNUNET_PeerIdentity)); | ||
2521 | } | ||
2522 | else | ||
2523 | current_source = NULL; | ||
2524 | |||
2525 | GDS_CLIENTS_process_put (options, | 2503 | GDS_CLIENTS_process_put (options, |
2526 | ntohl (put->block_type), | 2504 | ntohl (put->block_type), |
2527 | ntohl (put->hop_count), | 2505 | ntohl (put->hop_count), |
@@ -2545,10 +2523,6 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2545 | 2523 | ||
2546 | 2524 | ||
2547 | /** | 2525 | /** |
2548 | * FIXME | ||
2549 | * 1. I don't do block evalute as it uses xquery and bf for evaluation.Is | ||
2550 | * it okay if I just pass NULL. I am anyways going to pass NULL in case of | ||
2551 | * datacache_get? | ||
2552 | * Core handler for p2p get requests. | 2526 | * Core handler for p2p get requests. |
2553 | * | 2527 | * |
2554 | * @param cls closure | 2528 | * @param cls closure |
@@ -2599,21 +2573,35 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2599 | current_dest_type = ntohl (get->current_dest_type); | 2573 | current_dest_type = ntohl (get->current_dest_type); |
2600 | block_type = ntohl (get->block_type); | 2574 | block_type = ntohl (get->block_type); |
2601 | options = ntohl (get->options); | 2575 | options = ntohl (get->options); |
2602 | 2576 | struct GNUNET_PeerIdentity *current_source; | |
2577 | current_source = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | ||
2578 | |||
2603 | if (current_dest_type == FRIEND) | 2579 | if (current_dest_type == FRIEND) |
2604 | { | 2580 | { |
2605 | next_hop = find_successor (key_value, current_destination, ¤t_dest_type); | 2581 | next_hop = find_successor (key_value, current_destination, ¤t_dest_type); |
2582 | if (current_dest_type == FINGER) | ||
2583 | { | ||
2584 | memcpy (current_source, &my_identity, sizeof (struct GNUNET_PeerIdentity)); | ||
2585 | } | ||
2586 | else | ||
2587 | current_source = NULL; | ||
2606 | } | 2588 | } |
2607 | else if (current_dest_type == FINGER) | 2589 | else if (current_dest_type == FINGER) |
2608 | { | 2590 | { |
2609 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, current_destination)) | 2591 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, current_destination)) |
2610 | { | 2592 | { |
2611 | next_hop = find_successor (key_value, current_destination, ¤t_dest_type); | 2593 | next_hop = find_successor (key_value, current_destination, ¤t_dest_type); |
2594 | if (current_dest_type == FINGER) | ||
2595 | { | ||
2596 | memcpy (current_source, &my_identity, sizeof (struct GNUNET_PeerIdentity)); | ||
2597 | } | ||
2598 | else | ||
2599 | current_source = NULL; | ||
2612 | } | 2600 | } |
2613 | else | 2601 | else |
2614 | { | 2602 | { |
2615 | next_hop = GDS_ROUTING_search (&(get->current_source), current_destination, peer); | 2603 | next_hop = GDS_ROUTING_search (&(get->current_source), current_destination, peer); |
2616 | current_dest_type = FRIEND; | 2604 | current_dest_type = FINGER; |
2617 | } | 2605 | } |
2618 | } | 2606 | } |
2619 | 2607 | ||
@@ -2626,37 +2614,23 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2626 | if (current_dest_type == MY_ID) | 2614 | if (current_dest_type == MY_ID) |
2627 | { | 2615 | { |
2628 | struct GNUNET_PeerIdentity final_get_path[get_length+1]; | 2616 | struct GNUNET_PeerIdentity final_get_path[get_length+1]; |
2629 | memcpy (final_get_path, get_path, get_length * sizeof (struct GNUNET_PeerIdentity)); | 2617 | memcpy (final_get_path, gp, get_length * sizeof (struct GNUNET_PeerIdentity)); |
2630 | memcpy (final_get_path, &my_identity, sizeof (struct GNUNET_PeerIdentity)); | 2618 | memcpy (&final_get_path[get_length+1], &my_identity, sizeof (struct GNUNET_PeerIdentity)); |
2631 | get_length = get_length + 1; | 2619 | get_length = get_length + 1; |
2632 | struct GNUNET_PeerIdentity *next_hop; | 2620 | struct GNUNET_PeerIdentity *next_hop; |
2633 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 2621 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
2634 | /* FIXME: Check if we need to have a check on get length. */ | ||
2635 | memcpy (next_hop, &final_get_path[get_length-2], sizeof (struct GNUNET_PeerIdentity)); | 2622 | memcpy (next_hop, &final_get_path[get_length-2], sizeof (struct GNUNET_PeerIdentity)); |
2636 | #if 0 | 2623 | GDS_DATACACHE_handle_get (&(get->key),(get->block_type), NULL, 0, NULL, 0, |
2637 | GDS_DATACACHE_handle_get (&(get->key),(get->block_type), | 2624 | get_length, final_get_path,get_length - 1,next_hop, &my_identity); |
2638 | final_get_path, get_length,get_length - 1,next_hop); | 2625 | |
2639 | #endif | ||
2640 | return GNUNET_YES; | 2626 | return GNUNET_YES; |
2641 | } | 2627 | } |
2642 | else | 2628 | else |
2643 | { | 2629 | { |
2644 | struct GNUNET_PeerIdentity *current_source; | ||
2645 | current_source = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | ||
2646 | if (current_dest_type == FINGER) | ||
2647 | { | ||
2648 | memcpy (current_source, &my_identity, sizeof (struct GNUNET_PeerIdentity)); | ||
2649 | } | ||
2650 | else | ||
2651 | /* FIXME: Is this correct? */ | ||
2652 | { | ||
2653 | /* how to handle the case when we don't have any value for current source.*/ | ||
2654 | } | ||
2655 | |||
2656 | GDS_NEIGHBOURS_handle_get (block_type, options, get->desired_replication_level, | 2630 | GDS_NEIGHBOURS_handle_get (block_type, options, get->desired_replication_level, |
2657 | get->hop_count, gp, | 2631 | get->hop_count, gp, |
2658 | get_length, &(get->key),next_hop, | 2632 | get_length, &(get->key),next_hop, |
2659 | current_destination, &(get->current_source),¤t_dest_type); | 2633 | current_destination, &(get->current_source),current_dest_type); |
2660 | 2634 | ||
2661 | return GNUNET_YES; | 2635 | return GNUNET_YES; |
2662 | } | 2636 | } |
diff --git a/src/dht/gnunet-service-xdht_neighbours.h b/src/dht/gnunet-service-xdht_neighbours.h index e8809d11a..a1d896bc4 100644 --- a/src/dht/gnunet-service-xdht_neighbours.h +++ b/src/dht/gnunet-service-xdht_neighbours.h | |||
@@ -96,7 +96,7 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type block_type, | |||
96 | struct GNUNET_PeerIdentity *target_peer, | 96 | struct GNUNET_PeerIdentity *target_peer, |
97 | struct GNUNET_PeerIdentity *current_destination, | 97 | struct GNUNET_PeerIdentity *current_destination, |
98 | struct GNUNET_PeerIdentity *current_source, | 98 | struct GNUNET_PeerIdentity *current_source, |
99 | enum current_destination_type *current_dest_type); | 99 | enum current_destination_type current_dest_type); |
100 | 100 | ||
101 | 101 | ||
102 | /** | 102 | /** |
@@ -125,7 +125,8 @@ GDS_NEIGHBOURS_send_get_result (struct GNUNET_TIME_Absolute expiration, | |||
125 | struct GNUNET_PeerIdentity *get_path, | 125 | struct GNUNET_PeerIdentity *get_path, |
126 | unsigned int get_path_length, | 126 | unsigned int get_path_length, |
127 | unsigned int current_trail_index, | 127 | unsigned int current_trail_index, |
128 | struct GNUNET_PeerIdentity *next_hop); | 128 | struct GNUNET_PeerIdentity *next_hop, |
129 | struct GNUNET_PeerIdentity *source_peer); | ||
129 | 130 | ||
130 | /** | 131 | /** |
131 | * FIXME: Here you should update the fields of struct PeerGetResultMessage. | 132 | * FIXME: Here you should update the fields of struct PeerGetResultMessage. |