aboutsummaryrefslogtreecommitdiff
path: root/src/dht
diff options
context:
space:
mode:
authorSupriti Singh <supritisingh08@gmail.com>2014-05-21 10:25:40 +0000
committerSupriti Singh <supritisingh08@gmail.com>2014-05-21 10:25:40 +0000
commit7fc4aba249907a094015c520cc68b07547d33747 (patch)
treecd83dfb87943d3d44956e292ff66cae184933de4 /src/dht
parentf18f70cac7c127db77d3eff6b785714cc8498bb3 (diff)
downloadgnunet-7fc4aba249907a094015c520cc68b07547d33747.tar.gz
gnunet-7fc4aba249907a094015c520cc68b07547d33747.zip
Refactoring
Diffstat (limited to 'src/dht')
-rw-r--r--src/dht/gnunet-service-xdht_clients.c21
-rw-r--r--src/dht/gnunet-service-xdht_datacache.c8
-rw-r--r--src/dht/gnunet-service-xdht_neighbours.c641
-rw-r--r--src/dht/gnunet-service-xdht_neighbours.h70
-rw-r--r--src/dht/gnunet-service-xdht_routing.c26
-rw-r--r--src/dht/gnunet-service-xdht_routing.h6
6 files changed, 255 insertions, 517 deletions
diff --git a/src/dht/gnunet-service-xdht_clients.c b/src/dht/gnunet-service-xdht_clients.c
index 566e19ae4..056377e0e 100644
--- a/src/dht/gnunet-service-xdht_clients.c
+++ b/src/dht/gnunet-service-xdht_clients.c
@@ -844,12 +844,6 @@ transmit_request (struct ClientQueryRecord *cqr)
844 cqr->replication, 844 cqr->replication,
845 cqr->seen_replies_count); 845 cqr->seen_replies_count);
846 846
847 /* FIXME: Is it correct to pass your identity as default current_destination
848 * and current_source. also is it correct to copy your identity into a new
849 * address and then pass this address. address at which your identity is
850 * stored should be const or else you may overwrite it and you lose your
851 * identity value. */
852
853 struct GNUNET_PeerIdentity my_identity; 847 struct GNUNET_PeerIdentity my_identity;
854 my_identity = GDS_NEIGHBOURS_get_my_id (); 848 my_identity = GDS_NEIGHBOURS_get_my_id ();
855 GDS_NEIGHBOURS_send_get (&cqr->key, cqr->type, cqr->msg_options, 849 GDS_NEIGHBOURS_send_get (&cqr->key, cqr->type, cqr->msg_options,
@@ -951,12 +945,13 @@ handle_dht_local_put (void *cls, struct GNUNET_SERVER_Client *client,
951 &put_msg[1]); 945 &put_msg[1]);
952 946
953 struct GNUNET_PeerIdentity my_identity = GDS_NEIGHBOURS_get_my_id(); 947 struct GNUNET_PeerIdentity my_identity = GDS_NEIGHBOURS_get_my_id();
954 GDS_NEIGHBOURS_send_put (&put_msg->key, &put_msg[1], 948 GDS_NEIGHBOURS_send_put (&put_msg->key,
955 size - sizeof (struct GNUNET_DHT_ClientPutMessage),
956 ntohl (put_msg->type), ntohl (put_msg->options), 949 ntohl (put_msg->type), ntohl (put_msg->options),
957 ntohl (put_msg->desired_replication_level), 950 ntohl (put_msg->desired_replication_level),
951 my_identity, my_identity, NULL, 0, 0, NULL,
958 GNUNET_TIME_absolute_ntoh (put_msg->expiration), 952 GNUNET_TIME_absolute_ntoh (put_msg->expiration),
959 my_identity, my_identity, NULL, 0, 0, NULL); 953 &put_msg[1],
954 size - sizeof (struct GNUNET_DHT_ClientPutMessage));
960 955
961 956
962 GDS_CLIENTS_process_put (ntohl (put_msg->options), 957 GDS_CLIENTS_process_put (ntohl (put_msg->options),
@@ -1052,12 +1047,6 @@ handle_dht_local_get (void *cls, struct GNUNET_SERVER_Client *client,
1052 if (GNUNET_SCHEDULER_NO_TASK != retry_task) 1047 if (GNUNET_SCHEDULER_NO_TASK != retry_task)
1053 GNUNET_SCHEDULER_cancel (retry_task); 1048 GNUNET_SCHEDULER_cancel (retry_task);
1054 retry_task = GNUNET_SCHEDULER_add_now (&transmit_next_request_task, NULL); 1049 retry_task = GNUNET_SCHEDULER_add_now (&transmit_next_request_task, NULL);
1055 /* perform local lookup
1056 * FIXME: Should we call it here or in neighbours file. And how to handle
1057 * this case where we may get the data locally. You really need to rethink
1058 * this design again.
1059 GDS_DATACACHE_handle_get (&get->key, cqr->type, cqr->xquery, xquery_size,
1060 NULL, 0); */
1061 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1050 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1062} 1051}
1063 1052
diff --git a/src/dht/gnunet-service-xdht_datacache.c b/src/dht/gnunet-service-xdht_datacache.c
index 34b3f2b9c..6d13e344d 100644
--- a/src/dht/gnunet-service-xdht_datacache.c
+++ b/src/dht/gnunet-service-xdht_datacache.c
@@ -223,10 +223,9 @@ datacache_get_iterator (void *cls,
223 i++; 223 i++;
224 iterator = iterator->next; 224 iterator = iterator->next;
225 } 225 }
226 GDS_NEIGHBOURS_send_get_result (exp, key, put_path_length, put_path, 226 GDS_NEIGHBOURS_send_get_result (key,type, &(ctx->next_hop),&(ctx->source_peer),
227 type, size, data, get_path, ctx->get_path_length, 227 put_path_length, put_path, ctx->get_path_length,
228 &(ctx->next_hop), 228 get_path, exp, data, size );
229 &(ctx->source_peer));
230 229
231 break; 230 break;
232 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: 231 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
@@ -308,7 +307,6 @@ GDS_DATACACHE_handle_get (const struct GNUNET_HashCode * key,
308 if (next_hop != NULL) 307 if (next_hop != NULL)
309 memcpy (&(ctx.next_hop), next_hop, sizeof (struct GNUNET_PeerIdentity)); 308 memcpy (&(ctx.next_hop), next_hop, sizeof (struct GNUNET_PeerIdentity));
310 309
311 /* FIXME: add the get path into ctx and then call gds_neighbours_handle_get*/
312 int i = 0; 310 int i = 0;
313 311
314 if(get_path != NULL) 312 if(get_path != NULL)
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c
index 29efc4c57..38309d5d4 100644
--- a/src/dht/gnunet-service-xdht_neighbours.c
+++ b/src/dht/gnunet-service-xdht_neighbours.c
@@ -44,27 +44,11 @@
44#include <fenv.h> 44#include <fenv.h>
45#include "dht.h" 45#include "dht.h"
46 46
47/* TODO:
48 1. to randomly choose one of the routes in case there are multiple
49 routes to reach to the finger.
50 2. Structure alignment.
51 3. In put, we don't have anything like put result. so we are not adding anything
52 in the routing table.
53 4. Maintain a list of trails --> struct Trail *all_trails_head
54 * struct Trail *all_trails_tail. How do I keep it as an array and not as a list??
55 * First will complete the logic everywhere and then make this change.
56 5. At some places you use memcpy and at some places =, use uniformly.
57 6. I have removed compare_and_update_predecessor from handle_dht_p2p_Trail_setup
58 * (refer to google docs for reason).
59 7. when to use GNUNET_ntohll and when to use ntohl.
60 8. everywhere check if you should use GNUNET_htonll for key value which is 64 bit
61 * right now you are doing memcpy which does not seem correct.
62*/
63 47
64/** 48/**
65 * Maximum possible fingers of a peer. 49 * Maximum possible fingers of a peer.
66 */ 50 */
67#define MAX_FINGERS 66 51#define MAX_FINGERS 65
68 52
69/** 53/**
70 * Maximum allowed number of pending messages per friend peer. 54 * Maximum allowed number of pending messages per friend peer.
@@ -84,8 +68,7 @@
84/** 68/**
85 * How long will I remain congested? 69 * How long will I remain congested?
86 */ 70 */
87#define CONGESTION_TIMEOUT GNUNET_TIME_relative_get_minute_() 71#define CONGESTION_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 2)
88
89 72
90/** 73/**
91 * Maximum number of trails stored per finger. 74 * Maximum number of trails stored per finger.
@@ -95,7 +78,8 @@
95/** 78/**
96 * Used to distinguish put/get request use of find_successor() from others 79 * Used to distinguish put/get request use of find_successor() from others
97 */ 80 */
98#define PUT_GET_REQUEST 68 81#define PUT_GET_REQUEST 65
82
99 83
100GNUNET_NETWORK_STRUCT_BEGIN 84GNUNET_NETWORK_STRUCT_BEGIN
101 85
@@ -178,11 +162,6 @@ struct PeerGetResultMessage
178 uint32_t type GNUNET_PACKED; 162 uint32_t type GNUNET_PACKED;
179 163
180 /** 164 /**
181 * Peer which will receive the get result message.
182 */
183 struct GNUNET_PeerIdentity source_peer;
184
185 /**
186 * Number of peers recorded in the outgoing path from source to the 165 * Number of peers recorded in the outgoing path from source to the
187 * stored location of this message. 166 * stored location of this message.
188 */ 167 */
@@ -192,7 +171,12 @@ struct PeerGetResultMessage
192 * Length of the GET path that follows (if tracked). 171 * Length of the GET path that follows (if tracked).
193 */ 172 */
194 uint32_t get_path_length GNUNET_PACKED; 173 uint32_t get_path_length GNUNET_PACKED;
195 174
175 /**
176 * Peer which will receive the get result message.
177 */
178 struct GNUNET_PeerIdentity source_peer;
179
196 /** 180 /**
197 * When does the content expire? 181 * When does the content expire?
198 */ 182 */
@@ -280,7 +264,7 @@ struct PeerTrailSetupMessage
280 struct GNUNET_MessageHeader header; 264 struct GNUNET_MessageHeader header;
281 265
282 /** 266 /**
283 * Successor of this finger value will be our finger peer. 267 * Peer closest to this value will be our finger.
284 */ 268 */
285 uint64_t destination_finger; 269 uint64_t destination_finger;
286 270
@@ -641,7 +625,7 @@ struct FriendInfo
641 unsigned int pending_count; 625 unsigned int pending_count;
642 626
643 /** 627 /**
644 628 * In case not 0, then amount of time for which this friend is congested.
645 */ 629 */
646 struct GNUNET_TIME_Absolute congestion_duration; 630 struct GNUNET_TIME_Absolute congestion_duration;
647 631
@@ -664,8 +648,6 @@ struct FriendInfo
664 648
665 649
666/** 650/**
667 * FIXME: make an array of trails. #define number of entries in the array =
668 * number of trails we want to keep. Remove head, tail of trails.
669 * Entry in finger_peermap. 651 * Entry in finger_peermap.
670 */ 652 */
671struct FingerInfo 653struct FingerInfo
@@ -834,6 +816,7 @@ search_my_index (const struct GNUNET_PeerIdentity *trail,
834 return GNUNET_SYSERR; 816 return GNUNET_SYSERR;
835} 817}
836 818
819
837/** 820/**
838 * Compare two peer identities. 821 * Compare two peer identities.
839 * @param p1 Peer identity 822 * @param p1 Peer identity
@@ -1023,6 +1006,7 @@ core_transmit_notify (void *cls, size_t size, void *buf)
1023 1006
1024 1007
1025/** 1008/**
1009 * FIXME: assertion fails at the end of this function. also in core_api.c at 1299.
1026 * Transmit all messages in the friend's message queue. 1010 * Transmit all messages in the friend's message queue.
1027 * 1011 *
1028 * @param peer message queue to process 1012 * @param peer message queue to process
@@ -1042,7 +1026,6 @@ process_friend_queue (struct FriendInfo *peer)
1042 ("# Bytes of bandwidth requested from core"), 1026 ("# Bytes of bandwidth requested from core"),
1043 ntohs (pending->msg->size), GNUNET_NO); 1027 ntohs (pending->msg->size), GNUNET_NO);
1044 1028
1045 /* FIXME: Are we correctly initializing importance and pending. */
1046 peer->th = 1029 peer->th =
1047 GNUNET_CORE_notify_transmit_ready (core_api, GNUNET_NO, 1030 GNUNET_CORE_notify_transmit_ready (core_api, GNUNET_NO,
1048 pending->importance, 1031 pending->importance,
@@ -1362,6 +1345,7 @@ GDS_NEIGHBOURS_send_notify_new_successor (const struct GNUNET_PeerIdentity *sour
1362 process_friend_queue (target_friend); 1345 process_friend_queue (target_friend);
1363} 1346}
1364 1347
1348
1365/** 1349/**
1366 * Send a trail tear down message 1350 * Send a trail tear down message
1367 * @param source_peer Source of the trail. 1351 * @param source_peer Source of the trail.
@@ -1425,12 +1409,12 @@ GDS_NEIGHBOURS_send_trail_teardown (const struct GNUNET_PeerIdentity *source_pee
1425 1409
1426 1410
1427/** 1411/**
1428 * 1412 * Construct an add_trail_message and send it to target_friend
1429 * @param source_peer 1413 * @param source_peer Source of the trail to be added
1430 * @param destination_peer 1414 * @param destination_peer Destination of the trail to be added
1431 * @param trail 1415 * @param trail Trail from source to destination
1432 * @param trail_length 1416 * @param trail_length Total number of peers in the trail
1433 * @param target_friend 1417 * @param target_friend Friend to forward this message.
1434 */ 1418 */
1435void 1419void
1436GDS_NEIGHBOURS_send_add_trail_message (struct GNUNET_PeerIdentity *source_peer, 1420GDS_NEIGHBOURS_send_add_trail_message (struct GNUNET_PeerIdentity *source_peer,
@@ -1734,6 +1718,7 @@ send_find_finger_trail_message (void *cls,
1734 1718
1735 1719
1736/** 1720/**
1721 * FIXME: TRAIL_LIST URGENT. Send trail teardown message along each of the trail.
1737 * Scan the trail to check if any of my own friend is part of trail. If yes 1722 * Scan the trail to check if any of my own friend is part of trail. If yes
1738 * then shortcut the trail, send a trail teardown for the discarded trail, 1723 * then shortcut the trail, send a trail teardown for the discarded trail,
1739 * update trail list and trail_length. 1724 * update trail list and trail_length.
@@ -1817,7 +1802,7 @@ scan_and_compress_trail (struct GNUNET_PeerIdentity *trail,
1817 1802
1818 1803
1819/** 1804/**
1820 * FIXME: Adapt the code for List of trails. 1805 * FIXME: URGENT:Adapt the code for List of trails.
1821 * Free finger and its trail. 1806 * Free finger and its trail.
1822 * @param finger Finger to be freed. 1807 * @param finger Finger to be freed.
1823 */ 1808 */
@@ -1848,8 +1833,8 @@ free_finger (struct FingerInfo *finger)
1848 1833
1849 1834
1850/** 1835/**
1851 * FIXME: First check if both the trails are present if yes then send it 1836 * FIXME: URGENT: TRAIL_LIST First check if both the trails are present if yes
1852 * for both of them. Currently sending it only for one trail. 1837 * then send it for both of them. Currently sending it only for one trail.
1853 * Send a trail teardown message for the trail of removed finger from the finger 1838 * Send a trail teardown message for the trail of removed finger from the finger
1854 * peermap. 1839 * peermap.
1855 * @param existing_finger Finger to removed from the finger peermap. 1840 * @param existing_finger Finger to removed from the finger peermap.
@@ -1883,7 +1868,7 @@ void send_trail_teardown (struct FingerInfo *removed_finger)
1883 1868
1884 1869
1885/** 1870/**
1886 * FIXME: How do we understand which is the correct trail head? 1871 * FIXME: URGENT Adapt it to trail list.
1887 * Add a new trail to reach an existing finger in finger peermap and increment 1872 * Add a new trail to reach an existing finger in finger peermap and increment
1888 * the count of number of trails to reach to this finger. 1873 * the count of number of trails to reach to this finger.
1889 * @param existing_finger Finger 1874 * @param existing_finger Finger
@@ -1933,6 +1918,7 @@ void add_new_trail (struct FingerInfo *existing_finger,
1933 1918
1934 1919
1935/** 1920/**
1921 * FIXME: URGENT: adapt it to TRAIL LIST.
1936 * In case there are already maximum number of possible trail to reach to a finger, 1922 * In case there are already maximum number of possible trail to reach to a finger,
1937 * then check if the new trail's length is lesser than any of the existing trails. 1923 * then check if the new trail's length is lesser than any of the existing trails.
1938 * If yes then replace that old trail by new trail. 1924 * If yes then replace that old trail by new trail.
@@ -2033,6 +2019,7 @@ void select_and_replace_trail (struct FingerInfo *existing_finger,
2033 2019
2034 2020
2035/** 2021/**
2022 * FIXME: URGENT: Adapat it for trail list.
2036 * FIXME: If we remove a finger which is our friend, then how should we handle it. 2023 * FIXME: If we remove a finger which is our friend, then how should we handle it.
2037 * Ideally only in case if the trail_length > 0,we increment the trail count 2024 * Ideally only in case if the trail_length > 0,we increment the trail count
2038 * of the first friend in the trail to reach to the finger. in case finger is 2025 * of the first friend in the trail to reach to the finger. in case finger is
@@ -2184,6 +2171,7 @@ compare_new_entry_and_successor (const struct GNUNET_PeerIdentity *new_finger,
2184 2171
2185 2172
2186/** 2173/**
2174 * FIXME: URGENT: Adapat it for trail list.
2187 * Add a new entry in finger table. 2175 * Add a new entry in finger table.
2188 * @param finger_identity PeerIdentity of the new finger 2176 * @param finger_identity PeerIdentity of the new finger
2189 * @param finger_trail Trail to reach to the finger, can be NULL in case I am my own 2177 * @param finger_trail Trail to reach to the finger, can be NULL in case I am my own
@@ -2323,6 +2311,7 @@ int select_closest_finger (struct FingerInfo *existing_finger,
2323 2311
2324 2312
2325/** 2313/**
2314 * FIXME: TRAIL LIST urgent.
2326 * Check if there is already an entry for finger map index in finger table. 2315 * Check if there is already an entry for finger map index in finger table.
2327 * If yes then choose the closest finger. 2316 * If yes then choose the closest finger.
2328 * @param finger_identity Peer Identity of finger. 2317 * @param finger_identity Peer Identity of finger.
@@ -2400,6 +2389,7 @@ int finger_table_add (const struct GNUNET_PeerIdentity *finger_identity,
2400 2389
2401 2390
2402/** 2391/**
2392 * FIXME: URGNET: adapt it for trail list.
2403 * Check if the successor chosen is congested or has crossed trail threshold. 2393 * Check if the successor chosen is congested or has crossed trail threshold.
2404 * @param successor Successor to be checked. 2394 * @param successor Successor to be checked.
2405 * @return #GNUNET_YES in case its is either congested or has crossed trail threshold. 2395 * @return #GNUNET_YES in case its is either congested or has crossed trail threshold.
@@ -2424,7 +2414,10 @@ check_friend_threshold_and_congestion (struct Sorting_List *successor)
2424 } 2414 }
2425 else 2415 else
2426 { 2416 {
2427 friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &(finger->finger_identity)); 2417 if (0 != GNUNET_CRYPTO_cmp_peer_identity(&my_identity, &finger->finger_identity))
2418 friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &(finger->finger_identity));
2419 else
2420 return GNUNET_YES;
2428 } 2421 }
2429 } 2422 }
2430 2423
@@ -2439,12 +2432,15 @@ check_friend_threshold_and_congestion (struct Sorting_List *successor)
2439 2432
2440 2433
2441/** 2434/**
2442 * 2435 * Find the next successor for key_value as the earlier selected successor is either
2443 * @param all_known_peers 2436 * congested or have crossed trail threshold.
2444 * @param array_size 2437 * @param all_known_peers Array that contains my_identity, value, friends and fingers.
2445 * @param friend 2438 * @param array_size Total number of entries in @a all_known_peers.
2446 * @param key_value 2439 * @param start_index Index at which original successor is located.
2447 * @return 2440 * @param search_index Index at which our possible current successor is located.
2441 * @param count Number of times this function has been called.
2442 * @return successor, in case found.
2443 * NULL, in case of error.
2448 */ 2444 */
2449static struct Sorting_List * 2445static struct Sorting_List *
2450get_next_successor (struct Sorting_List *all_known_peers, 2446get_next_successor (struct Sorting_List *all_known_peers,
@@ -2458,6 +2454,9 @@ get_next_successor (struct Sorting_List *all_known_peers,
2458 next_peer = GNUNET_malloc (sizeof (struct Sorting_List)); 2454 next_peer = GNUNET_malloc (sizeof (struct Sorting_List));
2459 memcpy (next_peer, &all_known_peers[search_index], sizeof (struct Sorting_List)); 2455 memcpy (next_peer, &all_known_peers[search_index], sizeof (struct Sorting_List));
2460 2456
2457 if (next_peer->type == MY_ID)
2458 return next_peer;
2459
2461 if ((next_peer->type == VALUE) || 2460 if ((next_peer->type == VALUE) ||
2462 (GNUNET_YES == check_friend_threshold_and_congestion (next_peer))) 2461 (GNUNET_YES == check_friend_threshold_and_congestion (next_peer)))
2463 { 2462 {
@@ -2471,19 +2470,20 @@ get_next_successor (struct Sorting_List *all_known_peers,
2471 2470
2472 2471
2473/** 2472/**
2474 * 2473 * Search the current location of successor in all_known_peers array.
2475 * @param all_known_peers 2474 * @param all_known_peers Array which contains my_id, key value, friends and fingers.
2476 * @param array_size 2475 * @param array_size Total number of entries in @a all_known_peers
2477 * @param search_value 2476 * @param search_value 64 bit value of successor.
2478 * @return 2477 * @return Index of array at which value is stored,
2478 * #GNUNET_SYSERR in case of error.
2479 */ 2479 */
2480static int 2480static int
2481get_friend_location (struct Sorting_List *all_known_peers, size_t array_size, 2481get_successor_location (struct Sorting_List *all_known_peers, size_t array_size,
2482 uint64_t search_value) 2482 uint64_t search_value)
2483{ 2483{
2484 int k; 2484 int k;
2485 2485
2486 while (0 != memcmp (&all_known_peers[k], &search_value, sizeof (uint64_t))) 2486 while (0 != memcmp (&all_known_peers[k].data, &search_value, sizeof (uint64_t)))
2487 { 2487 {
2488 k++; 2488 k++;
2489 } 2489 }
@@ -2559,7 +2559,16 @@ init_all_known_peers (struct Sorting_List *all_known_peers, int size, uint64_t v
2559 GNUNET_CONTAINER_multipeermap_iterator_destroy (friend_iter); 2559 GNUNET_CONTAINER_multipeermap_iterator_destroy (friend_iter);
2560} 2560}
2561 2561
2562/** Find closest successor for the value. 2562
2563/**
2564 * FIXME: 1. In case all the peers are congested/threshold then by default my_id is
2565 * chosen. There is no limit on number of peers which can keep me as their finger.
2566 * Should there be limit? If yes then we need to keep a counter of number of peers
2567 * that keep me as fingers. This counter may/may not give the correct value as
2568 * that peer may have found a better finger. So should reset the limit at some
2569 * interval.
2570 * 2. Change the finger code, TRAIL_LIST. URGENT
2571 * Find closest successor for the value.
2563 * @param value Value for which we are looking for successor 2572 * @param value Value for which we are looking for successor
2564 * @param[out] current_destination set to my_identity in case I am the final destination, 2573 * @param[out] current_destination set to my_identity in case I am the final destination,
2565 * set to friend identity in case friend is final destination, 2574 * set to friend identity in case friend is final destination,
@@ -2567,9 +2576,7 @@ init_all_known_peers (struct Sorting_List *all_known_peers, int size, uint64_t v
2567 * is final destination. 2576 * is final destination.
2568 * @param[out] current_source set to my_identity. 2577 * @param[out] current_source set to my_identity.
2569 * @param finger_map_index Index in finger peer map. 2578 * @param finger_map_index Index in finger peer map.
2570 * @return Peer identity of next hop to send trail setup message to, 2579 * @return Peer identity of next hop to send trail setup message to
2571 * NULL in case all the friends are either congested or have crossed
2572 * their trail threshold.
2573 */ 2580 */
2574static struct GNUNET_PeerIdentity * 2581static struct GNUNET_PeerIdentity *
2575find_successor (uint64_t value, struct GNUNET_PeerIdentity *current_destination, 2582find_successor (uint64_t value, struct GNUNET_PeerIdentity *current_destination,
@@ -2595,7 +2602,7 @@ find_successor (uint64_t value, struct GNUNET_PeerIdentity *current_destination,
2595 { 2602 {
2596 if (GNUNET_YES == check_friend_threshold_and_congestion (successor)) 2603 if (GNUNET_YES == check_friend_threshold_and_congestion (successor))
2597 { 2604 {
2598 int search_index = get_friend_location (all_known_peers, size, successor->peer_id); 2605 int search_index = get_successor_location (all_known_peers, size, successor->peer_id);
2599 successor = get_next_successor (all_known_peers, size, search_index, search_index + 1, 0); 2606 successor = get_next_successor (all_known_peers, size, search_index, search_index + 1, 0);
2600 } 2607 }
2601 } 2608 }
@@ -2635,185 +2642,40 @@ find_successor (uint64_t value, struct GNUNET_PeerIdentity *current_destination,
2635 } 2642 }
2636 else 2643 else
2637 { 2644 {
2638 /* It means all the peers known to me are either congested or has crossed
2639 trial threshold. */
2640 return NULL; 2645 return NULL;
2641 } 2646 }
2642} 2647}
2643 2648
2644#if 0
2645/**
2646 * FIXME: Complete the code for checking the threshold and getting the next
2647 * peer, add the case in finger.
2648 * In case a friend is either congested or has crossed its trail threshold,
2649 * then don't consider it as next successor, In case of finger if its first
2650 * friend has crossed the threshold then don't consider it. In case no finger
2651 * or friend is found, then return NULL.
2652 * Find closest successor for the value.
2653 * @param value Value for which we are looking for successor
2654 * @param[out] current_destination set to my_identity in case I am the final destination,
2655 * set to friend identity in case friend is final destination,
2656 * set to first friend to reach to finger, in case finger
2657 * is final destination.
2658 * @param[out] current_source set to my_identity.
2659 * @param finger_map_index Index in finger peer map.
2660 * @return Peer identity of next hop to send trail setup message to,
2661 * NULL in case all the friends are either congested or have crossed
2662 * their trail threshold.
2663 */
2664static struct GNUNET_PeerIdentity *
2665find_successor (uint64_t value, struct GNUNET_PeerIdentity *current_destination,
2666 struct GNUNET_PeerIdentity *current_source, unsigned int finger_map_index)
2667{
2668 struct GNUNET_CONTAINER_MultiPeerMapIterator *friend_iter;
2669 struct GNUNET_CONTAINER_MultiPeerMapIterator *finger_iter;
2670 struct GNUNET_PeerIdentity key_ret;
2671 struct FriendInfo *friend;
2672 struct FingerInfo *finger;
2673 unsigned int finger_index;
2674 unsigned int friend_index;
2675 struct Sorting_List *successor;
2676 unsigned int size;
2677 int j;
2678
2679 /* 2 is added in size for my_identity and value which will part of all_known_peers. */
2680 size = GNUNET_CONTAINER_multipeermap_size (friend_peermap)+
2681 GNUNET_CONTAINER_multipeermap_size (finger_peermap)+
2682 2;
2683
2684 struct Sorting_List all_known_peers[size];
2685
2686 int k;
2687 for (k = 0; k < size; k++)
2688 all_known_peers[k].peer_id = 0;
2689
2690 /* Copy your identity at 0th index in all_known_peers. */
2691 j = 0;
2692 memcpy (&(all_known_peers[j].peer_id), &my_identity, sizeof (uint64_t));
2693 all_known_peers[j].type = MY_ID;
2694 all_known_peers[j].data = 0;
2695 j++;
2696
2697 /* Copy value */
2698 all_known_peers[j].peer_id = value;
2699 all_known_peers[j].type = VALUE;
2700 all_known_peers[j].data = 0;
2701 j++;
2702
2703 /* Iterate over friend peer map and copy all the elements into array. */
2704 friend_iter = GNUNET_CONTAINER_multipeermap_iterator_create (friend_peermap);
2705 for (friend_index = 0; friend_index < GNUNET_CONTAINER_multipeermap_size (friend_peermap); friend_index++)
2706 {
2707 if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next(friend_iter,&key_ret,(const void **)&friend))
2708 {
2709 memcpy (&(all_known_peers[j].peer_id), &(friend->id), sizeof (uint64_t));
2710 all_known_peers[j].type = FRIEND;
2711 all_known_peers[j].data = friend;
2712 j++;
2713 }
2714 }
2715
2716
2717 /* Iterate over finger map and copy all the entries into all_known_peers array. */
2718 finger_iter = GNUNET_CONTAINER_multipeermap_iterator_create (finger_peermap);
2719 for (finger_index = 0; finger_index < GNUNET_CONTAINER_multipeermap_size (finger_peermap); finger_index++)
2720 {
2721 if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next(finger_iter,&key_ret,(const void **)&finger))
2722 {
2723 memcpy (&(all_known_peers[j].peer_id), &(finger->finger_identity), sizeof (uint64_t));
2724 all_known_peers[j].type = FINGER;
2725 all_known_peers[j].data = finger;
2726 j++;
2727 }
2728 }
2729
2730 GNUNET_CONTAINER_multipeermap_iterator_destroy (finger_iter);
2731 GNUNET_CONTAINER_multipeermap_iterator_destroy (friend_iter);
2732
2733 qsort (&all_known_peers, size, sizeof (struct Sorting_List), &compare_peer_id);
2734
2735 /* search value in all_known_peers array. */
2736 if (PREDECESSOR_FINGER_ID == finger_map_index)
2737 successor = find_closest_predecessor (all_known_peers, value, size);
2738 else
2739 successor = find_closest_successor (all_known_peers, value, size);
2740
2741 if (successor->type == MY_ID)
2742 {
2743 memcpy (current_destination, &my_identity, sizeof (struct GNUNET_PeerIdentity));
2744 return &my_identity;
2745 }
2746 else if (successor->type == FRIEND)
2747 {
2748 struct FriendInfo *target_friend;
2749 target_friend = (struct FriendInfo *)successor->data;
2750 if( GNUNET_YES == check_friend_threshold_and_congestion (all_known_peers, size, target_friend, value))
2751 {
2752 int search_index = get_friend_location (all_known_peers);
2753 get_next_successor (all_known_peers, size, search_index, search_index + 1, 0);
2754 }
2755 memcpy (current_destination, &(target_friend->id), sizeof (struct GNUNET_PeerIdentity));
2756 memcpy (current_source, &my_identity, sizeof (struct GNUNET_PeerIdentity));
2757 return current_destination;
2758 }
2759 else if (successor->type == FINGER)
2760 {
2761 struct GNUNET_PeerIdentity *next_hop;
2762 struct FingerInfo *finger;
2763 finger = successor->data;
2764 next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
2765
2766 if (finger->first_trail_length > 0)
2767 {
2768 struct TrailPeerList *iterator;
2769 iterator = GNUNET_malloc (sizeof (struct TrailPeerList));
2770 iterator = finger->first_trail_head;
2771 memcpy (next_hop, &(iterator->peer), sizeof (struct GNUNET_PeerIdentity));
2772 }
2773 else /* This means finger is our friend. */
2774 memcpy (next_hop, &(finger->finger_identity), sizeof(struct GNUNET_PeerIdentity));
2775
2776 memcpy (current_destination, &(finger->finger_identity), sizeof (struct GNUNET_PeerIdentity));
2777 memcpy (current_source, &my_identity, sizeof (struct GNUNET_PeerIdentity));
2778 return next_hop;
2779 }
2780 else
2781 {
2782 GNUNET_assert (0);
2783 return NULL;
2784 }
2785}
2786#endif
2787 2649
2788/** 2650/**
2789 * Construct a Put message and send it to target_peer. 2651 * Construct a Put message and send it to target_peer.
2790 * @param key Key for the content 2652 * @param key Key for the content
2791 * @param data Content to store
2792 * @param data_size Size of content @a data in bytes
2793 * @param block_type Type of the block 2653 * @param block_type Type of the block
2794 * @param options Routing options 2654 * @param options Routing options
2795 * @param desired_replication_level Desired replication count 2655 * @param desired_replication_level Desired replication count
2796 * @param expiration_time When does the content expire 2656 * @param current_destination Next current destination which will get this message.
2797 * @param current_destination 2657 * @param current_source Source for @a current_destination
2798 * @param current_source
2799 * @param target_peer Peer to which this message will be forwarded. 2658 * @param target_peer Peer to which this message will be forwarded.
2800 * @param hop_count Number of hops traversed so far. 2659 * @param hop_count Number of hops traversed so far.
2801 * @param put_path_length Total number of peers in @a put_path 2660 * @param put_path_length Total number of peers in @a put_path
2802 * @param put_path Number of peers traversed so far 2661 * @param put_path Number of peers traversed so far
2662 * @param expiration_time When does the content expire
2663 * @param data Content to store
2664 * @param data_size Size of content @a data in bytes
2803 */ 2665 */
2804void 2666void
2805GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key, 2667GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key,
2806 const void *data, size_t data_size,
2807 enum GNUNET_BLOCK_Type block_type, 2668 enum GNUNET_BLOCK_Type block_type,
2808 enum GNUNET_DHT_RouteOption options, 2669 enum GNUNET_DHT_RouteOption options,
2809 uint32_t desired_replication_level, 2670 uint32_t desired_replication_level,
2810 struct GNUNET_TIME_Absolute expiration_time,
2811 struct GNUNET_PeerIdentity current_destination, 2671 struct GNUNET_PeerIdentity current_destination,
2812 struct GNUNET_PeerIdentity current_source, 2672 struct GNUNET_PeerIdentity current_source,
2813 struct GNUNET_PeerIdentity *target_peer, 2673 struct GNUNET_PeerIdentity *target_peer,
2814 uint32_t hop_count, 2674 uint32_t hop_count,
2815 uint32_t put_path_length, 2675 uint32_t put_path_length,
2816 struct GNUNET_PeerIdentity *put_path) 2676 struct GNUNET_PeerIdentity *put_path,
2677 struct GNUNET_TIME_Absolute expiration_time,
2678 const void *data, size_t data_size)
2817{ 2679{
2818 struct PeerPutMessage *ppm; 2680 struct PeerPutMessage *ppm;
2819 struct P2PPendingMessage *pending; 2681 struct P2PPendingMessage *pending;
@@ -2845,10 +2707,9 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key,
2845 2707
2846 memcpy (&key_value, key, sizeof (uint64_t)); 2708 memcpy (&key_value, key, sizeof (uint64_t));
2847 next_hop = find_successor (key_value, &current_destination, &current_source,PUT_GET_REQUEST); 2709 next_hop = find_successor (key_value, &current_destination, &current_source,PUT_GET_REQUEST);
2848 if (0 == GNUNET_CRYPTO_cmp_peer_identity(next_hop, &my_identity)) /* I am the destination do datacache_put */ 2710 if (0 == GNUNET_CRYPTO_cmp_peer_identity(next_hop, &my_identity))
2849 { 2711 {
2850 GDS_DATACACHE_handle_put (expiration_time, key, put_path_length, put_path, 2712 /* I am the destination but we have already done datacache_put in client file. */
2851 block_type, data_size, data);
2852 return; 2713 return;
2853 } 2714 }
2854 else 2715 else
@@ -2884,20 +2745,20 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key,
2884} 2745}
2885 2746
2886 2747
2887
2888/** 2748/**
2889 * Construct a Get message and send it to target_peer. 2749 * Construct a Get message and send it to target_peer.
2890 * @param key Key for the content 2750 * @param key Key for the content
2891 * @param block_type Type of the block 2751 * @param block_type Type of the block
2892 * @param options Routing options 2752 * @param options Routing options
2893 * @param desired_replication_level Desired replication count 2753 * @param desired_replication_level Desired replication count
2894 * @param expiration_time When does the content expire 2754 * @param current_destination Next current destination which will get this message.
2895 * @param current_destination 2755 * @param current_source Source for @a current_destination
2896 * @param current_source
2897 * @param target_peer Peer to which this message will be forwarded. 2756 * @param target_peer Peer to which this message will be forwarded.
2898 * @param hop_count Number of hops traversed so far. 2757 * @param hop_count Number of hops traversed so far.
2899 * @param put_path_length Total number of peers in @a put_path 2758 * @param data Content to store
2900 * @param put_path Number of peers traversed so far 2759 * @param data_size Size of content @a data in bytes
2760 * @param get_path_length Total number of peers in @a get_path
2761 * @param get_path Number of peers traversed so far
2901 */ 2762 */
2902void 2763void
2903GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key, 2764GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key,
@@ -2928,14 +2789,13 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key,
2928 2789
2929 if (NULL == target_peer) 2790 if (NULL == target_peer)
2930 { 2791 {
2931 /* This is the first call from client file, we need to search for next_hop*/
2932 struct GNUNET_PeerIdentity *next_hop; 2792 struct GNUNET_PeerIdentity *next_hop;
2933 uint64_t key_value; 2793 uint64_t key_value;
2934 2794
2935 memcpy (&key_value, key, sizeof (uint64_t)); 2795 memcpy (&key_value, key, sizeof (uint64_t));
2936 // FIXME: endianess of key_value!? 2796 // FIXME: endianess of key_value!?
2937 next_hop = find_successor (key_value, &current_destination, &current_source,PUT_GET_REQUEST); 2797 next_hop = find_successor (key_value, &current_destination, &current_source, PUT_GET_REQUEST);
2938 if (0 == GNUNET_CRYPTO_cmp_peer_identity(&my_identity,next_hop)) /* I am the destination do datacache_put */ 2798 if (0 == GNUNET_CRYPTO_cmp_peer_identity(&my_identity,next_hop))
2939 { 2799 {
2940 GDS_DATACACHE_handle_get (key,block_type, NULL, 0, 2800 GDS_DATACACHE_handle_get (key,block_type, NULL, 0,
2941 NULL, 0, 1, &my_identity, NULL,&my_identity); 2801 NULL, 0, 1, &my_identity, NULL,&my_identity);
@@ -2972,29 +2832,29 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key,
2972 2832
2973/** 2833/**
2974 * Send the get result to requesting client. 2834 * Send the get result to requesting client.
2975 * @param expiration When will this result expire?
2976 * @param key Key of the requested data. 2835 * @param key Key of the requested data.
2836 * @param type Block type
2837 * @param target_peer Next peer to forward the message to.
2838 * @param source_peer Peer which has the data for the key.
2977 * @param put_path_length Number of peers in @a put_path 2839 * @param put_path_length Number of peers in @a put_path
2978 * @param put_path Path taken to put the data at its stored location. 2840 * @param put_path Path taken to put the data at its stored location.
2979 * @param type Block type
2980 * @param data_size Size of the @a data
2981 * @param data Payload to store
2982 * @param get_path Path taken to reach to the location of the key.
2983 * @param get_path_length Number of peers in @a get_path 2841 * @param get_path_length Number of peers in @a get_path
2984 * @param next_hop Next peer to forward the message to. 2842 * @param get_path Path taken to reach to the location of the key.
2985 * @param source_peer Peer which has the data for the key. 2843 * @param expiration When will this result expire?
2844 * @param data Payload to store
2845 * @param data_size Size of the @a data
2986 */ 2846 */
2987void 2847void
2988GDS_NEIGHBOURS_send_get_result (struct GNUNET_TIME_Absolute expiration, 2848GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *key,
2989 const struct GNUNET_HashCode *key, 2849 enum GNUNET_BLOCK_Type type,
2850 struct GNUNET_PeerIdentity *next_hop,
2851 struct GNUNET_PeerIdentity *source_peer,
2990 unsigned int put_path_length, 2852 unsigned int put_path_length,
2991 const struct GNUNET_PeerIdentity *put_path, 2853 const struct GNUNET_PeerIdentity *put_path,
2992 enum GNUNET_BLOCK_Type type, size_t data_size,
2993 const void *data,
2994 struct GNUNET_PeerIdentity *get_path,
2995 unsigned int get_path_length, 2854 unsigned int get_path_length,
2996 struct GNUNET_PeerIdentity *next_hop, 2855 struct GNUNET_PeerIdentity *get_path,
2997 struct GNUNET_PeerIdentity *source_peer) 2856 struct GNUNET_TIME_Absolute expiration,
2857 const void *data, size_t data_size)
2998{ 2858{
2999 struct PeerGetResultMessage *get_result; 2859 struct PeerGetResultMessage *get_result;
3000 struct GNUNET_PeerIdentity *get_result_path; 2860 struct GNUNET_PeerIdentity *get_result_path;
@@ -3018,7 +2878,6 @@ GDS_NEIGHBOURS_send_get_result (struct GNUNET_TIME_Absolute expiration,
3018 current_path_index = search_my_index(get_path, get_path_length); 2878 current_path_index = search_my_index(get_path, get_path_length);
3019 if (GNUNET_SYSERR == current_path_index) 2879 if (GNUNET_SYSERR == current_path_index)
3020 { 2880 {
3021 /* FIXME: This assertion always fails. FIX IT. */
3022 GNUNET_break (0); 2881 GNUNET_break (0);
3023 return; 2882 return;
3024 } 2883 }
@@ -3072,6 +2931,8 @@ GDS_NEIGHBOURS_send_get_result (struct GNUNET_TIME_Absolute expiration,
3072 * NULL, in case the @a congested_peer was the first peer 2931 * NULL, in case the @a congested_peer was the first peer
3073 * to which trail setup message was forwarded. 2932 * to which trail setup message was forwarded.
3074 * @param trail_length Number of peers in trail_peer_list. 2933 * @param trail_length Number of peers in trail_peer_list.
2934 * @param congestion_timeout Time duration for which @a congested peer will be
2935 * congested.
3075 */ 2936 */
3076void 2937void
3077GDS_NEIGHBOURS_send_trail_rejection (const struct GNUNET_PeerIdentity *source_peer, 2938GDS_NEIGHBOURS_send_trail_rejection (const struct GNUNET_PeerIdentity *source_peer,
@@ -3226,9 +3087,8 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer,
3226 } 3087 }
3227 } 3088 }
3228 3089
3229 struct GNUNET_PeerIdentity pp[putlen + 1];
3230 /* extend 'put path' by sender */ 3090 /* extend 'put path' by sender */
3231 /* FIXME: Check what are we doing here? */ 3091 struct GNUNET_PeerIdentity pp[putlen + 1];
3232 if (0 != (options & GNUNET_DHT_RO_RECORD_ROUTE)) 3092 if (0 != (options & GNUNET_DHT_RO_RECORD_ROUTE))
3233 { 3093 {
3234 memcpy (pp, put_path, putlen * sizeof (struct GNUNET_PeerIdentity)); 3094 memcpy (pp, put_path, putlen * sizeof (struct GNUNET_PeerIdentity));
@@ -3241,42 +3101,48 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer,
3241 memcpy (&key_value, &(put->key), sizeof (uint64_t)); 3101 memcpy (&key_value, &(put->key), sizeof (uint64_t));
3242 if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&current_destination, &my_identity))) 3102 if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&current_destination, &my_identity)))
3243 { 3103 {
3244 GDS_ROUTING_print();
3245 next_hop = GDS_ROUTING_search (&current_source, &current_destination, peer); 3104 next_hop = GDS_ROUTING_search (&current_source, &current_destination, peer);
3246 if (next_hop == NULL)
3247 {
3248 /* refer to handle_dht_p2p_trail_setup. */
3249 }
3250 } 3105 }
3251 else 3106 else
3252 { 3107 {
3253 next_hop = find_successor (key_value, &current_destination, &current_source,PUT_GET_REQUEST); 3108 next_hop = find_successor (key_value, &current_destination, &current_source,PUT_GET_REQUEST);
3254 } 3109 }
3255 3110
3111 if (NULL == next_hop)
3112 {
3113 GNUNET_STATISTICS_update (GDS_stats,
3114 gettext_noop ("# Next hop to forward the packet not found "
3115 "trail setup request, packet dropped."),
3116 1, GNUNET_NO);
3117 return GNUNET_SYSERR;
3118 }
3119
3120 GDS_CLIENTS_process_put (options,
3121 ntohl (put->block_type),
3122 ntohl (put->hop_count),
3123 ntohl (put->desired_replication_level),
3124 putlen, pp,
3125 GNUNET_TIME_absolute_ntoh (put->expiration_time),
3126 &put->key,
3127 payload,
3128 payload_size);
3129
3256 if (0 == GNUNET_CRYPTO_cmp_peer_identity(&my_identity, next_hop)) /* I am the final destination */ 3130 if (0 == GNUNET_CRYPTO_cmp_peer_identity(&my_identity, next_hop)) /* I am the final destination */
3257 { 3131 {
3258 GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (put->expiration_time), 3132 GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (put->expiration_time),
3259 &(put->key),putlen, pp, ntohl (put->block_type), 3133 &(put->key),putlen, pp, ntohl (put->block_type),
3260 payload_size, payload); 3134 payload_size, payload);
3261 return GNUNET_YES; 3135 return GNUNET_YES;
3262 } 3136 }
3263 else 3137 else
3264 { 3138 {
3265 GDS_CLIENTS_process_put (options, 3139 GDS_NEIGHBOURS_send_put (&put->key,
3266 ntohl (put->block_type),
3267 ntohl (put->hop_count),
3268 ntohl (put->desired_replication_level),
3269 putlen, pp,
3270 GNUNET_TIME_absolute_ntoh (put->expiration_time),
3271 &put->key,
3272 payload,
3273 payload_size);
3274 GDS_NEIGHBOURS_send_put (&put->key, payload, payload_size,
3275 ntohl (put->block_type),ntohl (put->options), 3140 ntohl (put->block_type),ntohl (put->options),
3276 ntohl (put->desired_replication_level), 3141 ntohl (put->desired_replication_level),
3277 GNUNET_TIME_absolute_ntoh (put->expiration_time),
3278 current_destination, current_source, next_hop, 3142 current_destination, current_source, next_hop,
3279 ntohl (put->hop_count), putlen, pp); 3143 ntohl (put->hop_count), putlen, pp,
3144 GNUNET_TIME_absolute_ntoh (put->expiration_time),
3145 payload, payload_size);
3280 3146
3281 return GNUNET_YES; 3147 return GNUNET_YES;
3282 } 3148 }
@@ -3315,9 +3181,10 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
3315 3181
3316 get = (struct PeerGetMessage *)message; 3182 get = (struct PeerGetMessage *)message;
3317 get_length = ntohl (get->get_path_length); 3183 get_length = ntohl (get->get_path_length);
3318 get_path = (struct GNUNET_PeerIdentity *)&get[1];
3319 current_destination = get->current_destination; 3184 current_destination = get->current_destination;
3320 current_source = get->current_source; 3185 current_source = get->current_source;
3186 if (get_length > 0)
3187 get_path = (struct GNUNET_PeerIdentity *)&get[1];
3321 3188
3322 if ((msize < 3189 if ((msize <
3323 sizeof (struct PeerGetMessage) + 3190 sizeof (struct PeerGetMessage) +
@@ -3338,18 +3205,21 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
3338 memcpy (&key_value, &(get->key), sizeof (uint64_t)); 3205 memcpy (&key_value, &(get->key), sizeof (uint64_t));
3339 if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&current_destination, &my_identity))) 3206 if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&current_destination, &my_identity)))
3340 { 3207 {
3341 GDS_ROUTING_print();
3342 next_hop = GDS_ROUTING_search (&current_source, &current_destination, peer); 3208 next_hop = GDS_ROUTING_search (&current_source, &current_destination, peer);
3343 if (next_hop == NULL)
3344 {
3345 /* refer to handle_dht_p2p_trail_setup. */
3346 }
3347 } 3209 }
3348 else 3210 else
3349 { 3211 {
3350 next_hop = find_successor (key_value, &current_destination, &current_source,PUT_GET_REQUEST); 3212 next_hop = find_successor (key_value, &current_destination, &current_source,PUT_GET_REQUEST);
3351 } 3213 }
3352 3214
3215 if (NULL == next_hop)
3216 {
3217 GNUNET_STATISTICS_update (GDS_stats,
3218 gettext_noop ("# Next hop to forward the packet not found "
3219 "trail setup request, packet dropped."),
3220 1, GNUNET_NO);
3221 return GNUNET_SYSERR;
3222 }
3353 if (0 == GNUNET_CRYPTO_cmp_peer_identity(&my_identity, next_hop)) 3223 if (0 == GNUNET_CRYPTO_cmp_peer_identity(&my_identity, next_hop))
3354 { 3224 {
3355 /* I am the destination.*/ 3225 /* I am the destination.*/
@@ -3362,7 +3232,7 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
3362 memcpy (&next_hop, &final_get_path[get_length-2], sizeof (struct GNUNET_PeerIdentity)); 3232 memcpy (&next_hop, &final_get_path[get_length-2], sizeof (struct GNUNET_PeerIdentity));
3363 GDS_DATACACHE_handle_get (&(get->key),(get->block_type), NULL, 0, NULL, 0, 3233 GDS_DATACACHE_handle_get (&(get->key),(get->block_type), NULL, 0, NULL, 0,
3364 get_length, final_get_path,&next_hop, &my_identity); 3234 get_length, final_get_path,&next_hop, &my_identity);
3365 3235
3366 return GNUNET_YES; 3236 return GNUNET_YES;
3367 } 3237 }
3368 else 3238 else
@@ -3377,9 +3247,6 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
3377 3247
3378 3248
3379/** 3249/**
3380 * FIXME: In case of trail, we don't have source and destination part of the trail,
3381 * Check if we follow the same in case of get/put/get_result. Also, in case of
3382 * put should we do a routing table add.
3383 * Core handler for get result 3250 * Core handler for get result
3384 * @param cls closure 3251 * @param cls closure
3385 * @param peer sender of the request 3252 * @param peer sender of the request
@@ -3425,12 +3292,12 @@ handle_dht_p2p_get_result (void *cls, const struct GNUNET_PeerIdentity *peer,
3425 return GNUNET_YES; 3292 return GNUNET_YES;
3426 } 3293 }
3427 3294
3428 get_path = (struct GNUNET_PeerIdentity *) &get_result[1]; 3295 if (getlen > 0)
3296 get_path = (struct GNUNET_PeerIdentity *) &get_result[1];
3429 payload = &get_path[getlen]; 3297 payload = &get_path[getlen];
3430 payload_size = msize - (sizeof (struct PeerGetResultMessage) + 3298 payload_size = msize - (sizeof (struct PeerGetResultMessage) +
3431 getlen * sizeof (struct GNUNET_PeerIdentity)); 3299 getlen * sizeof (struct GNUNET_PeerIdentity));
3432 /* FIXME: Check if its correct or not. */ 3300
3433
3434 if (putlen > 0) 3301 if (putlen > 0)
3435 put_path = &get_path[1]; 3302 put_path = &get_path[1];
3436 else 3303 else
@@ -3445,37 +3312,31 @@ handle_dht_p2p_get_result (void *cls, const struct GNUNET_PeerIdentity *peer,
3445 } 3312 }
3446 else 3313 else
3447 { 3314 {
3448 struct GNUNET_PeerIdentity *next_hop;
3449 next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
3450 /* FIXME: handle the case when current_path_index = GNUNET_SYSERR;*/
3451 current_path_index = search_my_index (get_path, getlen); 3315 current_path_index = search_my_index (get_path, getlen);
3452 /* FIXME: First check if you are adding yourself to the get path or not. 3316 if (GNUNET_SYSERR == current_path_index )
3453 if yes then don't check if current_path_index == 0, if not then check 3317 {
3454 and next_hop == source_peer. */ 3318 GNUNET_break (0);
3455 memcpy (next_hop, &get_path[current_path_index - 1], sizeof (struct GNUNET_PeerIdentity)); 3319 return GNUNET_SYSERR;
3456 3320 }
3457 GDS_NEIGHBOURS_send_get_result (get_result->expiration_time, &(get_result->key), 3321 GDS_NEIGHBOURS_send_get_result (&(get_result->key), get_result->type,
3458 putlen, put_path, 3322 &get_path[current_path_index - 1],
3459 get_result->type, payload_size,payload, 3323 &(get_result->source_peer), putlen, put_path,
3460 get_path, getlen, 3324 getlen, get_path, get_result->expiration_time,
3461 next_hop, &(get_result->source_peer)); 3325 payload, payload_size);
3462 return GNUNET_YES; 3326 return GNUNET_YES;
3463 } 3327 }
3464 return GNUNET_SYSERR; 3328 return GNUNET_SYSERR;
3465} 3329}
3466 3330
3467 3331
3468/** 3332/**
3469 * FIXME: URGENT: refactor it. 3333 * Select the closest peer between peer returned from routing table and from
3470 * FIXME; now we can make a new ds to store 2 peers and one value as we are 3334 * find_successor()
3471 * using it at two places. Will complete the logic and then add a new ds. 3335 * @param prev_hop Peer which sent the trail setup message.
3472 * In case finger map index is 64 do we need to call find_closest_predecessor? 3336 * @param current_destination[out] Next peer which will receive this message.
3473 * Select the closest peer. 3337 * @param current_source[out] Source of the @a current_destination.
3474 * @param prev_hop 3338 * @param value Key value to which the peer should be closest.
3475 * @param current_destination 3339 * @para finger_map_index Index in finger map.
3476 * @param current_source
3477 * @param value
3478 * @para finger_map_index
3479 * @return Peer which is closest, in case of error NULL. 3340 * @return Peer which is closest, in case of error NULL.
3480 */ 3341 */
3481struct GNUNET_PeerIdentity * 3342struct GNUNET_PeerIdentity *
@@ -3489,44 +3350,36 @@ select_closest_peer (const struct GNUNET_PeerIdentity *prev_hop,
3489 struct GNUNET_PeerIdentity *peer2; 3350 struct GNUNET_PeerIdentity *peer2;
3490 struct Sorting_List peers[3]; 3351 struct Sorting_List peers[3];
3491 struct Sorting_List *closest_finger; 3352 struct Sorting_List *closest_finger;
3353 struct GNUNET_PeerIdentity current_dest;
3354 struct GNUNET_PeerIdentity current_src;
3492 3355
3493 peer1 = GDS_ROUTING_search (current_source, current_destination, prev_hop); 3356 peer1 = GDS_ROUTING_search (current_source, current_destination, prev_hop);
3494 peer2 = find_successor (value, current_destination, current_source,finger_map_index); 3357 peer2 = find_successor (value, &current_dest, &current_src,finger_map_index);
3495 3358
3496 /* SUPU TEST CODE */
3497 struct GNUNET_PeerIdentity print_peer;
3498 memcpy (&print_peer, &peer1, sizeof (struct GNUNET_PeerIdentity));
3499 FPRINTF (stderr,_("\nSUPU %s, %s, %d,routing_peer = %s"), __FILE__, __func__,__LINE__,GNUNET_i2s(&print_peer));
3500 memcpy (&print_peer, &peer2, sizeof (struct GNUNET_PeerIdentity));
3501 FPRINTF (stderr,_("\nSUPU %s, %s, %d,find_successor_peer = %s"), __FILE__, __func__,__LINE__,GNUNET_i2s(&print_peer));
3502 /* SUPU TEST CODE ENDS*/
3503 if( (peer1 != NULL) && (peer2 != NULL)) 3359 if( (peer1 != NULL) && (peer2 != NULL))
3504 { 3360 {
3505 /* Add peer 1 to the list. */
3506 memcpy (&peers[0], &peer1, sizeof (uint64_t)); 3361 memcpy (&peers[0], &peer1, sizeof (uint64_t));
3507 peers[0].type = FINGER;
3508 peers[0].data = NULL;
3509
3510 /* Add peer 2 to the list. */
3511 memcpy (&peers[1], &peer1, sizeof (uint64_t));
3512 peers[0].type = FRIEND; 3362 peers[0].type = FRIEND;
3513 peers[0].data = NULL; 3363 peers[0].data = NULL;
3514 3364
3515 /* Add value to the list. */ 3365 memcpy (&peers[1], &value, sizeof (uint64_t));
3516 memcpy (&peers[2], &peer1, sizeof (uint64_t)); 3366 peers[1].type = VALUE;
3517 peers[0].type = VALUE; 3367 peers[1].data = NULL;
3518 peers[0].data = NULL; 3368
3369 memcpy (&peers[2], &peer2, sizeof (uint64_t));
3370 peers[2].type = FINGER;
3371 peers[1].data = NULL;
3519 3372
3520 qsort (&peers, 3, sizeof (struct Sorting_List), &compare_peer_id); 3373 qsort (&peers, 3, sizeof (struct Sorting_List), &compare_peer_id);
3521 if (PREDECESSOR_FINGER_ID == finger_map_index) 3374 if (PREDECESSOR_FINGER_ID == finger_map_index)
3522 closest_finger = find_closest_predecessor (peers, value, 3); 3375 closest_finger = find_closest_predecessor (peers, value, 3);
3523 else 3376 else
3524 closest_finger = find_closest_successor (peers, value, 3); 3377 closest_finger = find_closest_successor (peers, value, 3);
3525 3378
3526 /* SUPU TEST CODE*/
3527 if (closest_finger->type == FINGER) 3379 if (closest_finger->type == FINGER)
3528 { 3380 {
3529 FPRINTF (stderr,_("\nSUPU %s, %s, %d"), __FILE__, __func__,__LINE__); 3381 memcpy (current_destination, &current_dest, sizeof (struct GNUNET_PeerIdentity));
3382 memcpy (current_source, &current_src, sizeof (struct GNUNET_PeerIdentity));
3530 return peer2; 3383 return peer2;
3531 } 3384 }
3532 else if (closest_finger->type == VALUE) 3385 else if (closest_finger->type == VALUE)
@@ -3535,8 +3388,6 @@ select_closest_peer (const struct GNUNET_PeerIdentity *prev_hop,
3535 } 3388 }
3536 else if (closest_finger->type == FRIEND); 3389 else if (closest_finger->type == FRIEND);
3537 { 3390 {
3538 /* If we are returning peer2 then find_successor has already taken care
3539 of setting up current_destination and current_source. */
3540 return peer1; 3391 return peer1;
3541 } 3392 }
3542 } 3393 }
@@ -3631,7 +3482,7 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer,
3631 if (NULL == next_hop) 3482 if (NULL == next_hop)
3632 { 3483 {
3633 GNUNET_STATISTICS_update (GDS_stats, 3484 GNUNET_STATISTICS_update (GDS_stats,
3634 gettext_noop ("# Trail not found in routing table during" 3485 gettext_noop ("# Next hop to forward the packet not found "
3635 "trail setup request, packet dropped."), 3486 "trail setup request, packet dropped."),
3636 1, GNUNET_NO); 3487 1, GNUNET_NO);
3637 return GNUNET_SYSERR; 3488 return GNUNET_SYSERR;
@@ -3739,9 +3590,7 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p
3739 return GNUNET_SYSERR; 3590 return GNUNET_SYSERR;
3740 3591
3741 if (my_index == 0) 3592 if (my_index == 0)
3742 {
3743 next_hop = trail_result->destination_peer; 3593 next_hop = trail_result->destination_peer;
3744 }
3745 else 3594 else
3746 next_hop = trail_peer_list[my_index - 1]; 3595 next_hop = trail_peer_list[my_index - 1];
3747 3596
@@ -3749,7 +3598,7 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p
3749 &(trail_result->finger_identity)))) 3598 &(trail_result->finger_identity))))
3750 { 3599 {
3751 struct GNUNET_PeerIdentity *routing_next_hop; 3600 struct GNUNET_PeerIdentity *routing_next_hop;
3752 3601
3753 routing_next_hop = GDS_ROUTING_search (&destination_peer,&finger_identity, 3602 routing_next_hop = GDS_ROUTING_search (&destination_peer,&finger_identity,
3754 peer); 3603 peer);
3755 if ((NULL == routing_next_hop) || 3604 if ((NULL == routing_next_hop) ||
@@ -3758,7 +3607,6 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p
3758 GDS_ROUTING_add (&(trail_result->destination_peer), &(trail_result->finger_identity), 3607 GDS_ROUTING_add (&(trail_result->destination_peer), &(trail_result->finger_identity),
3759 peer, &next_hop); 3608 peer, &next_hop);
3760 } 3609 }
3761 GDS_ROUTING_print();
3762 } 3610 }
3763 3611
3764 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop); 3612 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop);
@@ -3852,6 +3700,14 @@ handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *pee
3852 if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(vsm->successor),&my_identity))) 3700 if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(vsm->successor),&my_identity)))
3853 { 3701 {
3854 struct FingerInfo *my_predecessor; 3702 struct FingerInfo *my_predecessor;
3703
3704 my_predecessor = get_predecessor();
3705 if (NULL == my_predecessor)
3706 {
3707 /* FIXME: should we just return. */
3708 return GNUNET_OK;
3709 }
3710
3855 if (trail_length == 0) 3711 if (trail_length == 0)
3856 { 3712 {
3857 memcpy (&next_hop, &source_peer, sizeof (struct GNUNET_PeerIdentity)); 3713 memcpy (&next_hop, &source_peer, sizeof (struct GNUNET_PeerIdentity));
@@ -3862,17 +3718,11 @@ handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *pee
3862 } 3718 }
3863 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop); 3719 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop);
3864 3720
3865 my_predecessor = get_predecessor();
3866 if (NULL == my_predecessor)
3867 {
3868 /* FIXME: should we just return. */
3869 return GNUNET_OK;
3870 }
3871
3872 if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&source_peer, 3721 if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&source_peer,
3873 &(my_predecessor->finger_identity)))) 3722 &(my_predecessor->finger_identity))))
3874 { 3723 {
3875 /* Source peer and my predecessor, both are same. */ 3724 /* Source peer and my predecessor, both are same. */
3725
3876 GDS_NEIGHBOURS_send_verify_successor_result (&source_peer, 3726 GDS_NEIGHBOURS_send_verify_successor_result (&source_peer,
3877 &(my_identity), 3727 &(my_identity),
3878 &(my_predecessor->finger_identity), 3728 &(my_predecessor->finger_identity),
@@ -3919,12 +3769,6 @@ handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *pee
3919 { 3769 {
3920 int my_index; 3770 int my_index;
3921 3771
3922 if (trail_length == 0)
3923 {
3924 GNUNET_break (0);
3925 return GNUNET_SYSERR;
3926 }
3927
3928 my_index = search_my_index (trail_peer_list, trail_length); 3772 my_index = search_my_index (trail_peer_list, trail_length);
3929 if (my_index == GNUNET_SYSERR) 3773 if (my_index == GNUNET_SYSERR)
3930 { 3774 {
@@ -3996,16 +3840,13 @@ handle_dht_p2p_verify_successor_result(void *cls, const struct GNUNET_PeerIdenti
3996 { 3840 {
3997 memcpy (&next_hop, &trail_peer_list[0], sizeof (struct GNUNET_PeerIdentity)); 3841 memcpy (&next_hop, &trail_peer_list[0], sizeof (struct GNUNET_PeerIdentity));
3998 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop); 3842 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop);
3999 /* FIXME: first call scan_and_compress_trail and then call the notify new 3843 scan_and_compress_trail (trail_peer_list, &trail_length, &(vsrm->my_predecessor));
4000 successor with new trail. */
4001 GDS_NEIGHBOURS_send_notify_new_successor (&my_identity, &(vsrm->my_predecessor), 3844 GDS_NEIGHBOURS_send_notify_new_successor (&my_identity, &(vsrm->my_predecessor),
4002 &(vsrm->source_successor), 3845 &(vsrm->source_successor),
4003 target_friend, trail_peer_list, 3846 target_friend, trail_peer_list,
4004 trail_length); 3847 trail_length);
4005 return GNUNET_OK;
4006 } 3848 }
4007 else 3849 return GNUNET_OK;
4008 return GNUNET_OK;
4009 } 3850 }
4010 } 3851 }
4011 else 3852 else
@@ -4018,7 +3859,6 @@ handle_dht_p2p_verify_successor_result(void *cls, const struct GNUNET_PeerIdenti
4018 GNUNET_break (0); 3859 GNUNET_break (0);
4019 return GNUNET_SYSERR; 3860 return GNUNET_SYSERR;
4020 } 3861 }
4021
4022 if (my_index == 0) 3862 if (my_index == 0)
4023 { 3863 {
4024 memcpy (&next_hop, &(vsrm->destination_peer), sizeof (struct GNUNET_PeerIdentity)); 3864 memcpy (&next_hop, &(vsrm->destination_peer), sizeof (struct GNUNET_PeerIdentity));
@@ -4057,6 +3897,7 @@ handle_dht_p2p_notify_new_successor(void *cls, const struct GNUNET_PeerIdentity
4057 struct GNUNET_PeerIdentity source_peer; 3897 struct GNUNET_PeerIdentity source_peer;
4058 struct GNUNET_PeerIdentity old_successor; 3898 struct GNUNET_PeerIdentity old_successor;
4059 struct GNUNET_PeerIdentity new_successor; 3899 struct GNUNET_PeerIdentity new_successor;
3900 struct FriendInfo *target_friend;
4060 size_t msize; 3901 size_t msize;
4061 uint32_t trail_length; 3902 uint32_t trail_length;
4062 3903
@@ -4088,30 +3929,28 @@ handle_dht_p2p_notify_new_successor(void *cls, const struct GNUNET_PeerIdentity
4088 { 3929 {
4089 /* I am the new successor. */ 3930 /* I am the new successor. */
4090 struct GNUNET_PeerIdentity *new_predecessor; 3931 struct GNUNET_PeerIdentity *new_predecessor;
3932
4091 new_predecessor = GNUNET_new (struct GNUNET_PeerIdentity); 3933 new_predecessor = GNUNET_new (struct GNUNET_PeerIdentity);
4092 memcpy (new_predecessor, &(nsm->source_peer), sizeof (struct GNUNET_PeerIdentity)); 3934 memcpy (new_predecessor, &(nsm->source_peer), sizeof (struct GNUNET_PeerIdentity));
4093 if (GNUNET_YES == finger_table_add (new_predecessor, trail_peer_list, trail_length, PREDECESSOR_FINGER_ID)) 3935 if (GNUNET_YES == finger_table_add (new_predecessor, trail_peer_list, trail_length, PREDECESSOR_FINGER_ID))
4094 { 3936 {
4095 /* You are adding a new predecessor in your finger table. but the intermediate 3937 if (trail_length > 0)
4096 peers don't have an entry in their routing table. So, you need to check the 3938 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &(trail_peer_list[trail_length - 1]));
4097 return value of finger_table_Add and if its successful then you should send 3939 else
4098 routing_add_message. */ 3940 target_friend = NULL;
3941 GDS_NEIGHBOURS_send_add_trail_message (&my_identity, new_predecessor,
3942 trail_peer_list, trail_length, target_friend);
4099 } 3943 }
4100 return GNUNET_OK; 3944 return GNUNET_OK;
4101 } 3945 }
4102 else 3946 else
4103 { 3947 {
4104 struct FriendInfo *target_friend;
4105 struct GNUNET_PeerIdentity next_hop; 3948 struct GNUNET_PeerIdentity next_hop;
4106 int my_index; 3949 int my_index;
4107 3950
4108 if (trail_length == 0)
4109 return GNUNET_SYSERR;
4110
4111 my_index = search_my_index (trail_peer_list, trail_length); 3951 my_index = search_my_index (trail_peer_list, trail_length);
4112 if (GNUNET_SYSERR == my_index) 3952 if (GNUNET_SYSERR == my_index)
4113 { 3953 {
4114 /* FIXME: happend once */
4115 GNUNET_break(0); 3954 GNUNET_break(0);
4116 return GNUNET_SYSERR; 3955 return GNUNET_SYSERR;
4117 } 3956 }
@@ -4125,7 +3964,6 @@ handle_dht_p2p_notify_new_successor(void *cls, const struct GNUNET_PeerIdentity
4125 memcpy (&next_hop, &trail_peer_list[my_index+1], sizeof (struct GNUNET_PeerIdentity)); 3964 memcpy (&next_hop, &trail_peer_list[my_index+1], sizeof (struct GNUNET_PeerIdentity));
4126 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop); 3965 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop);
4127 } 3966 }
4128
4129 GDS_ROUTING_remove_trail (&source_peer, &old_successor, peer); 3967 GDS_ROUTING_remove_trail (&source_peer, &old_successor, peer);
4130 GDS_ROUTING_add (&(nsm->source_peer), &(nsm->destination_peer), &next_hop, peer); 3968 GDS_ROUTING_add (&(nsm->source_peer), &(nsm->destination_peer), &next_hop, peer);
4131 GDS_NEIGHBOURS_send_notify_new_successor (&(nsm->source_peer), 3969 GDS_NEIGHBOURS_send_notify_new_successor (&(nsm->source_peer),
@@ -4138,11 +3976,8 @@ handle_dht_p2p_notify_new_successor(void *cls, const struct GNUNET_PeerIdentity
4138 return GNUNET_SYSERR; 3976 return GNUNET_SYSERR;
4139} 3977}
4140 3978
3979
4141/** 3980/**
4142 * FIXME: pass congestion time in struct PeerTrailRejectionMessage,
4143 * we are calling exact same thing here as in handle_dht_p2p_trail_seutp.set
4144 * that value here.
4145 * if we make it a function then we can it here.
4146 * Core handler for P2P trail rejection message 3981 * Core handler for P2P trail rejection message
4147 * @param cls closure 3982 * @param cls closure
4148 * @param message message 3983 * @param message message
@@ -4237,21 +4072,14 @@ int handle_dht_p2p_trail_rejection(void *cls, const struct GNUNET_PeerIdentity *
4237 if (NULL == next_peer) 4072 if (NULL == next_peer)
4238 { 4073 {
4239 GNUNET_STATISTICS_update (GDS_stats, 4074 GNUNET_STATISTICS_update (GDS_stats,
4240 gettext_noop ("# Trail not found in routing table during" 4075 gettext_noop ("# Next hop not found"
4241 "trail setup request, packet dropped."), 4076 "trail setup request, packet dropped."),
4242 1, GNUNET_NO); 4077 1, GNUNET_NO);
4243 return GNUNET_SYSERR; 4078 return GNUNET_SYSERR;
4244 } 4079 }
4245 else if (0 == (GNUNET_CRYPTO_cmp_peer_identity (next_peer, &my_identity)))/* This means I am the final destination */ 4080 else if (0 == (GNUNET_CRYPTO_cmp_peer_identity (next_peer, &my_identity)))/* This means I am the final destination */
4246 { 4081 {
4247 if (trail_length == 0) 4082 memcpy (&next_hop, &trail_peer_list[trail_length-1], sizeof (struct GNUNET_PeerIdentity));
4248 {
4249 memcpy (&next_hop, &source, sizeof (struct GNUNET_PeerIdentity));
4250 }
4251 else
4252 {
4253 memcpy (&next_hop, &trail_peer_list[trail_length-1], sizeof (struct GNUNET_PeerIdentity));
4254 }
4255 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop); 4083 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop);
4256 GDS_NEIGHBOURS_send_trail_setup_result (&source, 4084 GDS_NEIGHBOURS_send_trail_setup_result (&source,
4257 &(my_identity), 4085 &(my_identity),
@@ -4281,8 +4109,7 @@ int handle_dht_p2p_trail_rejection(void *cls, const struct GNUNET_PeerIdentity *
4281} 4109}
4282 4110
4283 4111
4284/* FIXME: there is a loop between in call from notify new successor to this function 4112/*
4285 * check why and fix it.
4286 * Core handle for p2p trail tear down messages. 4113 * Core handle for p2p trail tear down messages.
4287 * @param cls closure 4114 * @param cls closure
4288 * @param message message 4115 * @param message message
@@ -4321,68 +4148,40 @@ int handle_dht_p2p_trail_teardown (void *cls, const struct GNUNET_PeerIdentity *
4321 } 4148 }
4322 4149
4323 if (discarded_trail_length > 0) 4150 if (discarded_trail_length > 0)
4324 discarded_trail = (struct GNUNET_PeerIdentity *) &trail_teardown[1]; 4151 discarded_trail = (struct GNUNET_PeerIdentity *) &trail_teardown[1];
4325 4152
4326 /* SUPU TEST CODE */
4327 struct GNUNET_PeerIdentity print_peer;
4328 int k = 0;
4329 while ( k < discarded_trail_length)
4330 {
4331 memcpy (&print_peer, &discarded_trail[k], sizeof (struct GNUNET_PeerIdentity));
4332 FPRINTF (stderr,_("\nSUPU %s, %s, %d,discarded_trail[%d]=%s"),
4333 __FILE__, __func__,__LINE__,k,GNUNET_i2s(&print_peer));
4334 k++;
4335 }
4336 /* SUPU TEST CODE ENDS*/
4337 if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&(trail_teardown->new_first_friend), 4153 if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&(trail_teardown->new_first_friend),
4338 &my_identity))) 4154 &my_identity)))
4339 { 4155 {
4340 if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(trail_teardown->destination_peer), 4156 if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(trail_teardown->destination_peer),
4341 &my_identity))) 4157 &my_identity)))
4342 { 4158 {
4343 return GNUNET_OK; 4159 return GNUNET_OK;
4344 } 4160 }
4345 else 4161 else
4346 { 4162 {
4347 /* FIXME:
4348 * I am the new first hop in the trail to reach from source to destination.
4349 Update the trail in routing table with prev_hop == source peer. */
4350 return GDS_ROUTING_trail_update (&(trail_teardown->source_peer), 4163 return GDS_ROUTING_trail_update (&(trail_teardown->source_peer),
4351 &(trail_teardown->destination_peer), peer); 4164 &(trail_teardown->destination_peer), peer);
4352 } 4165 }
4353 } 4166 }
4354 else 4167 else
4355 { 4168 {
4356 /* This should always be the case. */ 4169 my_index = search_my_index (discarded_trail, discarded_trail_length);
4357 if (discarded_trail_length > 0) 4170 if(GNUNET_SYSERR == my_index)
4358 {
4359 my_index = search_my_index (discarded_trail, discarded_trail_length);
4360 if(GNUNET_SYSERR == my_index)
4361 return GNUNET_SYSERR; 4171 return GNUNET_SYSERR;
4362 } 4172
4363 else
4364 {
4365 GNUNET_break (0);
4366 return GNUNET_SYSERR;
4367 }
4368 GDS_ROUTING_print();
4369 if (GNUNET_NO == GDS_ROUTING_remove_trail (&(trail_teardown->source_peer), 4173 if (GNUNET_NO == GDS_ROUTING_remove_trail (&(trail_teardown->source_peer),
4370 &(trail_teardown->destination_peer),peer)) 4174 &(trail_teardown->destination_peer),peer))
4371 { 4175 {
4372 /* Here we get GNUNET_NO, only if there is no matching entry found in routing 4176 GNUNET_break (0); /* no matching entry found. Should not happen */
4373 table. */ 4177 return GNUNET_SYSERR;
4374 GNUNET_break (0);
4375 return GNUNET_YES;
4376 } 4178 }
4377 4179
4378 /* In case we got this message when we removed an entry from finger table, 4180 if (my_index == (discarded_trail_length - 1))
4379 then we need to send the message to destination. */ 4181 return GNUNET_OK;
4380 if (my_index != (discarded_trail_length - 1)) 4182
4381 memcpy (&next_hop, &discarded_trail[my_index + 1], sizeof (struct GNUNET_PeerIdentity)); 4183 memcpy (&next_hop, &discarded_trail[my_index + 1], sizeof (struct GNUNET_PeerIdentity));
4382 else
4383 memcpy (&next_hop, &(trail_teardown->destination_peer), sizeof (struct GNUNET_PeerIdentity));
4384 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop); 4184 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop);
4385
4386 GDS_NEIGHBOURS_send_trail_teardown (&(trail_teardown->source_peer), 4185 GDS_NEIGHBOURS_send_trail_teardown (&(trail_teardown->source_peer),
4387 &(trail_teardown->destination_peer), 4186 &(trail_teardown->destination_peer),
4388 discarded_trail, discarded_trail_length, 4187 discarded_trail, discarded_trail_length,
@@ -4392,8 +4191,9 @@ int handle_dht_p2p_trail_teardown (void *cls, const struct GNUNET_PeerIdentity *
4392 return GNUNET_SYSERR; 4191 return GNUNET_SYSERR;
4393} 4192}
4394 4193
4194
4395/** 4195/**
4396 * Core handle for p2p routing table add messages. 4196 * Core handle for p2p add trail message.
4397 * @param cls closure 4197 * @param cls closure
4398 * @param message message 4198 * @param message message
4399 * @param peer peer identity this notification is about 4199 * @param peer peer identity this notification is about
@@ -4401,13 +4201,8 @@ int handle_dht_p2p_trail_teardown (void *cls, const struct GNUNET_PeerIdentity *
4401 */ 4201 */
4402static int 4202static int
4403handle_dht_p2p_add_trail (void *cls, const struct GNUNET_PeerIdentity *peer, 4203handle_dht_p2p_add_trail (void *cls, const struct GNUNET_PeerIdentity *peer,
4404 const struct GNUNET_MessageHeader *message) 4204 const struct GNUNET_MessageHeader *message)
4405{ 4205{
4406 /* This function is called in case when we update our predecessor as a new peer
4407 claims to be our successor. In that case as we did not do a trail setup,
4408 intermediate nodes don't know about this trail. our predecessor has added
4409 that trail but not we. So, we need to add it. Its only in case of predecessor
4410 and succcessor that we have a symmetric relation. */
4411 struct PeerAddTrailMessage *add_trail; 4206 struct PeerAddTrailMessage *add_trail;
4412 struct GNUNET_PeerIdentity *trail; 4207 struct GNUNET_PeerIdentity *trail;
4413 struct GNUNET_PeerIdentity next_hop; 4208 struct GNUNET_PeerIdentity next_hop;
@@ -4444,16 +4239,13 @@ handle_dht_p2p_add_trail (void *cls, const struct GNUNET_PeerIdentity *peer,
4444 GNUNET_break (0); 4239 GNUNET_break (0);
4445 return GNUNET_SYSERR; 4240 return GNUNET_SYSERR;
4446 } 4241 }
4447 if (my_index == 0)
4448 memcpy(&next_hop, &(add_trail->source_peer), sizeof (struct GNUNET_PeerIdentity));
4449 else
4450 memcpy (&next_hop, &trail[my_index - 1], sizeof (struct GNUNET_PeerIdentity));
4451 4242
4452 if (GNUNET_YES == GDS_ROUTING_add (&(add_trail->source_peer), &(add_trail->destination_peer), 4243 if (GNUNET_YES == GDS_ROUTING_add (&(add_trail->source_peer), &(add_trail->destination_peer),
4453 peer,&next_hop)) 4244 peer,&next_hop))
4454 { 4245 {
4455 if (my_index != 0) 4246 if (my_index != 0)
4456 { 4247 {
4248 memcpy (&next_hop, &trail[my_index - 1], sizeof (struct GNUNET_PeerIdentity));
4457 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop); 4249 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop);
4458 GDS_NEIGHBOURS_send_add_trail_message (&(add_trail->source_peer), 4250 GDS_NEIGHBOURS_send_add_trail_message (&(add_trail->source_peer),
4459 &(add_trail->destination_peer), 4251 &(add_trail->destination_peer),
@@ -4463,8 +4255,7 @@ handle_dht_p2p_add_trail (void *cls, const struct GNUNET_PeerIdentity *peer,
4463 } 4255 }
4464 else 4256 else
4465 { 4257 {
4466 /* FIXME: there is not space in routing table to add the trail. What should 4258 /* No space left in my routing table. How should we handle this case? */
4467 be done. */
4468 return GNUNET_SYSERR; 4259 return GNUNET_SYSERR;
4469 } 4260 }
4470} 4261}
diff --git a/src/dht/gnunet-service-xdht_neighbours.h b/src/dht/gnunet-service-xdht_neighbours.h
index 38f3cfe92..a1a6ea564 100644
--- a/src/dht/gnunet-service-xdht_neighbours.h
+++ b/src/dht/gnunet-service-xdht_neighbours.h
@@ -32,56 +32,51 @@
32#include "gnunet_dht_service.h" 32#include "gnunet_dht_service.h"
33 33
34 34
35/** FIXME: by default I keep current_source, and destination as my own id. 35/**
36 * in case we find a finger then we update current_source in the
37 * find_successor message.
38 * Construct a Put message and send it to target_peer. 36 * Construct a Put message and send it to target_peer.
39 * @param key Key for the content 37 * @param key Key for the content
40 * @param data Content to store
41 * @param data_size Size of content @a data in bytes
42 * @param block_type Type of the block 38 * @param block_type Type of the block
43 * @param options Routing options 39 * @param options Routing options
44 * @param desired_replication_level Desired replication count 40 * @param desired_replication_level Desired replication count
45 * @param expiration_time When does the content expire 41 * @param current_destination Next current destination which will get this message.
46 * @param current_destination 42 * @param current_source Source for @a current_destination
47 * @param current_source
48 * @param target_peer Peer to which this message will be forwarded. 43 * @param target_peer Peer to which this message will be forwarded.
49 * @param hop_count Number of hops traversed so far. 44 * @param hop_count Number of hops traversed so far.
50 * @param put_path_length Total number of peers in @a put_path 45 * @param put_path_length Total number of peers in @a put_path
51 * @param put_path Number of peers traversed so far 46 * @param put_path Number of peers traversed so far
47 * @param expiration_time When does the content expire
48 * @param data Content to store
49 * @param data_size Size of content @a data in bytes
52 */ 50 */
53void 51void
54GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key, 52GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key,
55 const void *data, size_t data_size,
56 enum GNUNET_BLOCK_Type block_type, 53 enum GNUNET_BLOCK_Type block_type,
57 enum GNUNET_DHT_RouteOption options, 54 enum GNUNET_DHT_RouteOption options,
58 uint32_t desired_replication_level, 55 uint32_t desired_replication_level,
59 struct GNUNET_TIME_Absolute expiration_time,
60 struct GNUNET_PeerIdentity current_destination, 56 struct GNUNET_PeerIdentity current_destination,
61 struct GNUNET_PeerIdentity current_source, 57 struct GNUNET_PeerIdentity current_source,
62 struct GNUNET_PeerIdentity *target_peer, 58 struct GNUNET_PeerIdentity *target_peer,
63 uint32_t hop_count, 59 uint32_t hop_count,
64 uint32_t put_path_length, 60 uint32_t put_path_length,
65 struct GNUNET_PeerIdentity *put_path); 61 struct GNUNET_PeerIdentity *put_path,
62 struct GNUNET_TIME_Absolute expiration_time,
63 const void *data, size_t data_size);
66 64
67 65
68/** FIXME: by default I keep current_source, and destination as my own id. 66/**
69 * in case we find a finger then we update current_source in the
70 * find_successor message.
71 * Construct a Get message and send it to target_peer. 67 * Construct a Get message and send it to target_peer.
72 * @param key Key for the content 68 * @param key Key for the content
73 * @param data Content to store
74 * @param data_size Size of content @a data in bytes
75 * @param block_type Type of the block 69 * @param block_type Type of the block
76 * @param options Routing options 70 * @param options Routing options
77 * @param desired_replication_level Desired replication count 71 * @param desired_replication_level Desired replication count
78 * @param expiration_time When does the content expire 72 * @param current_destination Next current destination which will get this message.
79 * @param current_destination 73 * @param current_source Source for @a current_destination
80 * @param current_source
81 * @param target_peer Peer to which this message will be forwarded. 74 * @param target_peer Peer to which this message will be forwarded.
82 * @param hop_count Number of hops traversed so far. 75 * @param hop_count Number of hops traversed so far.
83 * @param put_path_length Total number of peers in @a put_path 76 * @param data Content to store
84 * @param put_path Number of peers traversed so far 77 * @param data_size Size of content @a data in bytes
78 * @param get_path_length Total number of peers in @a get_path
79 * @param get_path Number of peers traversed so far
85 */ 80 */
86void 81void
87GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key, 82GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key,
@@ -98,34 +93,29 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key,
98 93
99/** 94/**
100 * Send the get result to requesting client. 95 * Send the get result to requesting client.
101 * @param expiration When will this result expire?
102 * @param key Key of the requested data. 96 * @param key Key of the requested data.
97 * @param type Block type
98 * @param target_peer Next peer to forward the message to.
99 * @param source_peer Peer which has the data for the key.
103 * @param put_path_length Number of peers in @a put_path 100 * @param put_path_length Number of peers in @a put_path
104 * @param put_path Path taken to put the data at its stored location. 101 * @param put_path Path taken to put the data at its stored location.
105 * @param type Block type
106 * @param data_size Size of the @a data
107 * @param data Payload to store
108 * @param get_path Path taken to reach to the location of the key.
109 * @param get_path_length Number of peers in @a get_path 102 * @param get_path_length Number of peers in @a get_path
110 * @param current_get_path_index Index in get_path 103 * @param get_path Path taken to reach to the location of the key.
111 * @param next_hop Next peer to forward the message to. 104 * @param expiration When will this result expire?
112 * @param source_peer Peer which has the data for the key. 105 * @param data Payload to store
106 * @param data_size Size of the @a data
113 */ 107 */
114/* FIXME: Remove redundant arguments
115 * 1.remove get_path_index from message and just look up into the get path
116 for your location and get the next peer.
117 * 2. Remove next_hop, source_peer */
118void 108void
119GDS_NEIGHBOURS_send_get_result (struct GNUNET_TIME_Absolute expiration, 109GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *key,
120 const struct GNUNET_HashCode *key, 110 enum GNUNET_BLOCK_Type type,
111 struct GNUNET_PeerIdentity *target_peer,
112 struct GNUNET_PeerIdentity *source_peer,
121 unsigned int put_path_length, 113 unsigned int put_path_length,
122 const struct GNUNET_PeerIdentity *put_path, 114 const struct GNUNET_PeerIdentity *put_path,
123 enum GNUNET_BLOCK_Type type, size_t data_size,
124 const void *data,
125 struct GNUNET_PeerIdentity *get_path,
126 unsigned int get_path_length, 115 unsigned int get_path_length,
127 struct GNUNET_PeerIdentity *next_hop, 116 struct GNUNET_PeerIdentity *get_path,
128 struct GNUNET_PeerIdentity *source_peer); 117 struct GNUNET_TIME_Absolute expiration,
118 const void *data, size_t data_size);
129 119
130/** 120/**
131 * Initialize neighbours subsystem. 121 * Initialize neighbours subsystem.
diff --git a/src/dht/gnunet-service-xdht_routing.c b/src/dht/gnunet-service-xdht_routing.c
index 2101a8ada..32faa25fe 100644
--- a/src/dht/gnunet-service-xdht_routing.c
+++ b/src/dht/gnunet-service-xdht_routing.c
@@ -332,32 +332,8 @@ GDS_ROUTING_init (void)
332 routing_table = GNUNET_CONTAINER_multipeermap_create (ROUTING_TABLE_THRESHOLD * 4 / 3, 332 routing_table = GNUNET_CONTAINER_multipeermap_create (ROUTING_TABLE_THRESHOLD * 4 / 3,
333 GNUNET_NO); 333 GNUNET_NO);
334} 334}
335
336/**
337 * ONLY FOR TESTING.
338 */
339void
340GDS_ROUTING_print (void)
341{
342 struct RoutingTrail *trail;
343 struct GNUNET_CONTAINER_MultiPeerMapIterator *iterator;
344 int i;
345
346 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Routing table entries \n");
347 iterator = GNUNET_CONTAINER_multipeermap_iterator_create (routing_table);
348 for (i = 0; i< GNUNET_CONTAINER_multipeermap_size(routing_table); i++)
349 {
350 if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next (iterator, NULL,
351 (const void **)&trail))
352 {
353 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Routing trail source \n", GNUNET_i2s (&(trail->source)));
354 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Routing trail source \n", GNUNET_i2s (&(trail->destination)));
355 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Routing trail source \n", GNUNET_i2s (&(trail->next_hop)));
356 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Routing trail source \n", GNUNET_i2s (&(trail->prev_hop)));
357 }
358 }
359 335
360} 336
361/** 337/**
362 * FIXME: here you can have routing table with size 0, only when you delete 338 * FIXME: here you can have routing table with size 0, only when you delete
363 * the entries correctly. Possible scenarios where we delete the entries are 339 * the entries correctly. Possible scenarios where we delete the entries are
diff --git a/src/dht/gnunet-service-xdht_routing.h b/src/dht/gnunet-service-xdht_routing.h
index a79ba68a3..2475741c4 100644
--- a/src/dht/gnunet-service-xdht_routing.h
+++ b/src/dht/gnunet-service-xdht_routing.h
@@ -101,12 +101,6 @@ GDS_ROUTING_remove_trail (struct GNUNET_PeerIdentity *source_peer,
101 const struct GNUNET_PeerIdentity *prev_hop); 101 const struct GNUNET_PeerIdentity *prev_hop);
102 102
103/** 103/**
104 * FOR TESTING.
105 */
106void
107GDS_ROUTING_print (void);
108
109/**
110 * Check if size of routing table is greater than threshold or not. 104 * Check if size of routing table is greater than threshold or not.
111 */ 105 */
112int 106int