aboutsummaryrefslogtreecommitdiff
path: root/src/dht
diff options
context:
space:
mode:
authorSupriti Singh <supritisingh08@gmail.com>2014-04-16 16:18:34 +0000
committerSupriti Singh <supritisingh08@gmail.com>2014-04-16 16:18:34 +0000
commit4fe8ee2e15a25362dc418b89ae2d06d0b7099827 (patch)
tree5183fd433fae6ff13a6f15156f26f46d4ace6014 /src/dht
parent21d0e9ff2c7538d455ecc300dd306964ea1c9a1a (diff)
downloadgnunet-4fe8ee2e15a25362dc418b89ae2d06d0b7099827.tar.gz
gnunet-4fe8ee2e15a25362dc418b89ae2d06d0b7099827.zip
Removing routing table entries corresponding to disconnected peer
Diffstat (limited to 'src/dht')
-rw-r--r--src/dht/gnunet-service-xdht_clients.c28
-rw-r--r--src/dht/gnunet-service-xdht_datacache.c3
-rw-r--r--src/dht/gnunet-service-xdht_neighbours.c581
-rw-r--r--src/dht/gnunet-service-xdht_neighbours.h2
-rw-r--r--src/dht/gnunet-service-xdht_routing.c159
-rw-r--r--src/dht/gnunet-service-xdht_routing.h47
6 files changed, 489 insertions, 331 deletions
diff --git a/src/dht/gnunet-service-xdht_clients.c b/src/dht/gnunet-service-xdht_clients.c
index 6761dd96b..83c8983bf 100644
--- a/src/dht/gnunet-service-xdht_clients.c
+++ b/src/dht/gnunet-service-xdht_clients.c
@@ -844,13 +844,18 @@ 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: Here I am passing NULL for parameters check if its correct or 847 /* FIXME: Is it correct to pass your identity as default current_destination
848 not. Here I don't want address to be const just the value how do I do it? */ 848 * and current_source. also is it correct to copy your identity into a new
849 FPRINTF (stderr,_("\nSUPU %s, %s, %d"),__FILE__, __func__,__LINE__); 849 * address and then pass this address. address at which your identity is
850 struct GNUNET_PeerIdentity *my_identity; 850 * stored should be const or else you may overwrite it and you lose your
851 * identity value. */
852
853 const struct GNUNET_PeerIdentity *my_identity;
854 struct GNUNET_PeerIdentity copy_my_identity;
851 my_identity = GDS_NEIGHBOURS_get_my_id (); 855 my_identity = GDS_NEIGHBOURS_get_my_id ();
856 memcpy (&copy_my_identity, my_identity, sizeof(struct GNUNET_PeerIdentity));
852 GDS_NEIGHBOURS_send_get (&cqr->key, cqr->type, cqr->msg_options, 857 GDS_NEIGHBOURS_send_get (&cqr->key, cqr->type, cqr->msg_options,
853 cqr->replication, my_identity, my_identity, NULL, 858 cqr->replication, &copy_my_identity, &copy_my_identity, NULL,
854 0, 0, NULL); 859 0, 0, NULL);
855 860
856 /* exponential back-off for retries. 861 /* exponential back-off for retries.
@@ -947,16 +952,21 @@ handle_dht_local_put (void *cls, struct GNUNET_SERVER_Client *client,
947 size - sizeof (struct GNUNET_DHT_ClientPutMessage), 952 size - sizeof (struct GNUNET_DHT_ClientPutMessage),
948 &put_msg[1]); 953 &put_msg[1]);
949 954
950 /* FIXME: Is it correct to pass NULL for current destination and current 955 /* FIXME: Is it correct to pass your identity as default current_destination
951 source. */ 956 * and current_source. also is it correct to copy your identity into a new
952 struct GNUNET_PeerIdentity *my_identity; 957 * address and then pass this address. address at which your identity is
958 * stored should be const or else you may overwrite it and you lose your
959 * identity value. */
960 const struct GNUNET_PeerIdentity *my_identity;
961 struct GNUNET_PeerIdentity copy_my_identity;
953 my_identity = GDS_NEIGHBOURS_get_my_id(); 962 my_identity = GDS_NEIGHBOURS_get_my_id();
963 memcpy (&copy_my_identity, my_identity, sizeof(struct GNUNET_PeerIdentity));
954 GDS_NEIGHBOURS_send_put (&put_msg->key, &put_msg[1], 964 GDS_NEIGHBOURS_send_put (&put_msg->key, &put_msg[1],
955 size - sizeof (struct GNUNET_DHT_ClientPutMessage), 965 size - sizeof (struct GNUNET_DHT_ClientPutMessage),
956 ntohl (put_msg->type), ntohl (put_msg->options), 966 ntohl (put_msg->type), ntohl (put_msg->options),
957 ntohl (put_msg->desired_replication_level), 967 ntohl (put_msg->desired_replication_level),
958 GNUNET_TIME_absolute_ntoh (put_msg->expiration), 968 GNUNET_TIME_absolute_ntoh (put_msg->expiration),
959 my_identity, my_identity, NULL, 0, 0, NULL); 969 &copy_my_identity, &copy_my_identity, NULL, 0, 0, NULL);
960 970
961 971
962 GDS_CLIENTS_process_put (ntohl (put_msg->options), 972 GDS_CLIENTS_process_put (ntohl (put_msg->options),
diff --git a/src/dht/gnunet-service-xdht_datacache.c b/src/dht/gnunet-service-xdht_datacache.c
index dd6810f45..e741b02e7 100644
--- a/src/dht/gnunet-service-xdht_datacache.c
+++ b/src/dht/gnunet-service-xdht_datacache.c
@@ -228,9 +228,6 @@ datacache_get_iterator (void *cls,
228 &(ctx->next_hop), 228 &(ctx->next_hop),
229 &(ctx->source_peer)); 229 &(ctx->source_peer));
230 230
231 /* forward to other peers */
232 GDS_ROUTING_process (type, exp, key, put_path_length, put_path, 0, NULL,
233 data, size);
234 break; 231 break;
235 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: 232 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
236 GNUNET_STATISTICS_update (GDS_stats, 233 GNUNET_STATISTICS_update (GDS_stats,
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c
index 70aa47108..bb2346bad 100644
--- a/src/dht/gnunet-service-xdht_neighbours.c
+++ b/src/dht/gnunet-service-xdht_neighbours.c
@@ -30,49 +30,29 @@
30#include "gnunet_hello_lib.h" 30#include "gnunet_hello_lib.h"
31#include "gnunet_constants.h" 31#include "gnunet_constants.h"
32#include "gnunet_protocols.h" 32#include "gnunet_protocols.h"
33#include "gnunet_nse_service.h"
34#include "gnunet_ats_service.h" 33#include "gnunet_ats_service.h"
35#include "gnunet_core_service.h" 34#include "gnunet_core_service.h"
36#include "gnunet_datacache_lib.h" 35#include "gnunet_datacache_lib.h"
37#include "gnunet_transport_service.h" 36#include "gnunet_transport_service.h"
38#include "gnunet_hello_lib.h"
39#include "gnunet_dht_service.h" 37#include "gnunet_dht_service.h"
40#include "gnunet_statistics_service.h" 38#include "gnunet_statistics_service.h"
41#include "gnunet-service-xdht.h" 39#include "gnunet-service-xdht.h"
42#include "gnunet-service-xdht_clients.h" 40#include "gnunet-service-xdht_clients.h"
43#include "gnunet-service-xdht_datacache.h" 41#include "gnunet-service-xdht_datacache.h"
44#include "gnunet-service-xdht_hello.h"
45#include "gnunet-service-xdht_neighbours.h" 42#include "gnunet-service-xdht_neighbours.h"
46#include "gnunet-service-xdht_nse.h"
47#include "gnunet-service-xdht_routing.h" 43#include "gnunet-service-xdht_routing.h"
48#include <fenv.h> 44#include <fenv.h>
49#include "dht.h" 45#include "dht.h"
50 46
51/* TODO: 47/* TODO:
52 * 1. when should we use const struct and replace wherever needed.
53 * 2. use assert for each function where you need to check the return value.
54 1. Use a global array of all known peers in find_successor, Only when 48 1. Use a global array of all known peers in find_successor, Only when
55 a new peer is added in finger or friend peer map, then re calculate 49 a new peer is added in finger or friend peer map, then re calculate
56 the array. Or else use the old one. 50 the array. Or else use the old one.*/
57 2. Should we be using const in all the handle for the message we received
58 * and then copy the fields and make changes to the fields instead of sending
59 * them as they come.
60 * 3. Everywhere you are storing yourself as the first element in the trail.
61 * It is obviously taking too much space. Try to remove it and think of something
62 * better.
63 4. Choose the correct interval to send finger and verify message.
64 5. Do we need expiration time for trail setup and all other messages? TTL
65 6. In case of trail setup after TTL, we should again send the request but
66 * through a different route. How do we remeber each time which friend we
67 * chose last time for the trail setup. We will need a data structure where we
68 * add entry in finger table add and when setup is done remove it.
69 * 7. I have not added any authentication on messages exachanged between peers.
70 * Only when basic put/get is correct I will add it. */
71 51
72/** 52/**
73 * Maximum possible fingers of a peer. 53 * Maximum possible fingers of a peer.
74 */ 54 */
75#define MAX_FINGERS 64 55#define MAX_FINGERS 63
76 56
77/** 57/**
78 * Maximum allowed number of pending messages per friend peer. 58 * Maximum allowed number of pending messages per friend peer.
@@ -362,24 +342,24 @@ struct PeerTrailRejectionMessage
362 struct GNUNET_PeerIdentity source_peer; 342 struct GNUNET_PeerIdentity source_peer;
363 343
364 /** 344 /**
365 * Finger identity value. 345 * Peer which sent trail rejection message.
366 */ 346 */
367 uint64_t finger_identity; 347 struct GNUNET_PeerIdentity congested_peer;
368 348
369 /** 349 /**
370 * Peer which sent trail rejection message. 350 * Finger identity value.
371 */ 351 */
372 struct GNUNET_PeerIdentity congested_peer; 352 uint64_t finger_identity;
373 353
374 /** 354 /**
375 * Index in finger peer map of source peer. 355 * Index in finger peer map of source peer.
376 */ 356 */
377 unsigned int finger_map_index; 357 uint32_t finger_map_index;
378 358
379 /** 359 /**
380 * Total number of peers in the trail. 360 * Total number of peers in the trail.
381 */ 361 */
382 unsigned int trail_length; 362 uint32_t trail_length;
383 363
384 /* trail_list */ 364 /* trail_list */
385}; 365};
@@ -409,7 +389,7 @@ struct PeerVerifySuccessorMessage
409 /** 389 /**
410 * Total number of peers in trail to current successor. 390 * Total number of peers in trail to current successor.
411 */ 391 */
412 unsigned int trail_length; 392 uint32_t trail_length;
413}; 393};
414 394
415 395
@@ -446,7 +426,7 @@ struct PeerVerifySuccessorResultMessage
446 * If source_successor is destination peer, then trail is from destination_peer 426 * If source_successor is destination peer, then trail is from destination_peer
447 * to source_successor. 427 * to source_successor.
448 */ 428 */
449 unsigned int trail_length; 429 uint32_t trail_length;
450}; 430};
451 431
452/** 432/**
@@ -472,7 +452,7 @@ struct PeerNotifyNewSuccessorMessage
472 /** 452 /**
473 * Number of peers in trail from source_peer to new successor. 453 * Number of peers in trail from source_peer to new successor.
474 */ 454 */
475 unsigned int trail_length; 455 uint32_t trail_length;
476}; 456};
477 457
478 458
@@ -495,15 +475,15 @@ struct P2PPendingMessage
495 struct P2PPendingMessage *prev; 475 struct P2PPendingMessage *prev;
496 476
497 /** 477 /**
498 * When does this message time out?
499 */
500 struct GNUNET_TIME_Absolute timeout;
501
502 /**
503 * Message importance level. FIXME: used? useful? 478 * Message importance level. FIXME: used? useful?
504 */ 479 */
505 unsigned int importance; 480 unsigned int importance;
506 481
482 /**
483 * When does this message time out?
484 */
485 struct GNUNET_TIME_Absolute timeout;
486
507 /** 487 /**
508 * Actual message to be sent, allocated at the end of the struct: 488 * Actual message to be sent, allocated at the end of the struct:
509 * // msg = (cast) &pm[1]; 489 * // msg = (cast) &pm[1];
@@ -714,7 +694,7 @@ static unsigned int current_finger_index;
714 * @return Index in the array. 694 * @return Index in the array.
715 */ 695 */
716static int 696static int
717search_my_location (struct GNUNET_PeerIdentity *trail) 697search_my_index (const struct GNUNET_PeerIdentity *trail)
718{ 698{
719 return 0; 699 return 0;
720} 700}
@@ -914,11 +894,11 @@ GDS_NEIGHBOURS_send_trail_setup (const struct GNUNET_PeerIdentity *source_peer,
914 * @param finger_map_index Index in finger peer map 894 * @param finger_map_index Index in finger peer map
915 */ 895 */
916void 896void
917GDS_NEIGHBOURS_send_trail_setup_result (struct GNUNET_PeerIdentity *destination_peer, 897GDS_NEIGHBOURS_send_trail_setup_result (const struct GNUNET_PeerIdentity *destination_peer,
918 struct GNUNET_PeerIdentity *source_finger, 898 const struct GNUNET_PeerIdentity *source_finger,
919 struct FriendInfo *target_friend, 899 struct FriendInfo *target_friend,
920 unsigned int trail_length, 900 unsigned int trail_length,
921 struct GNUNET_PeerIdentity *trail_peer_list, 901 const struct GNUNET_PeerIdentity *trail_peer_list,
922 unsigned int finger_map_index) 902 unsigned int finger_map_index)
923{ 903{
924 struct P2PPendingMessage *pending; 904 struct P2PPendingMessage *pending;
@@ -970,10 +950,10 @@ GDS_NEIGHBOURS_send_trail_setup_result (struct GNUNET_PeerIdentity *destination_
970 * @param trail_peer_list Peer which are part of trail from source to destination 950 * @param trail_peer_list Peer which are part of trail from source to destination
971 * @param trail_length Number of peers in the trail list. 951 * @param trail_length Number of peers in the trail list.
972 */ 952 */
973void GDS_NEIGHBOURS_send_verify_successor(struct GNUNET_PeerIdentity *source_peer, 953void GDS_NEIGHBOURS_send_verify_successor(const struct GNUNET_PeerIdentity *source_peer,
974 struct GNUNET_PeerIdentity *successor, 954 const struct GNUNET_PeerIdentity *successor,
975 struct FriendInfo *target_friend, 955 struct FriendInfo *target_friend,
976 struct GNUNET_PeerIdentity *trail_peer_list, 956 const struct GNUNET_PeerIdentity *trail_peer_list,
977 unsigned int trail_length) 957 unsigned int trail_length)
978{ 958{
979 struct PeerVerifySuccessorMessage *vsm; 959 struct PeerVerifySuccessorMessage *vsm;
@@ -1026,11 +1006,11 @@ void GDS_NEIGHBOURS_send_verify_successor(struct GNUNET_PeerIdentity *source_pee
1026 * @param trail_peer_list Peers which are part of trail from source to destination 1006 * @param trail_peer_list Peers which are part of trail from source to destination
1027 * @param trail_length Number of peers in the trail list. 1007 * @param trail_length Number of peers in the trail list.
1028 */ 1008 */
1029void GDS_NEIGHBOURS_send_verify_successor_result (struct GNUNET_PeerIdentity *destination_peer, 1009void GDS_NEIGHBOURS_send_verify_successor_result (const struct GNUNET_PeerIdentity *destination_peer,
1030 struct GNUNET_PeerIdentity *source_successor, 1010 const struct GNUNET_PeerIdentity *source_successor,
1031 struct GNUNET_PeerIdentity *my_predecessor, 1011 const struct GNUNET_PeerIdentity *my_predecessor,
1032 struct FriendInfo *target_friend, 1012 struct FriendInfo *target_friend,
1033 struct GNUNET_PeerIdentity *trail_peer_list, 1013 const struct GNUNET_PeerIdentity *trail_peer_list,
1034 unsigned int trail_length) 1014 unsigned int trail_length)
1035{ 1015{
1036 struct PeerVerifySuccessorResultMessage *vsmr; 1016 struct PeerVerifySuccessorResultMessage *vsmr;
@@ -1084,10 +1064,10 @@ void GDS_NEIGHBOURS_send_verify_successor_result (struct GNUNET_PeerIdentity *de
1084 * @param trail_length Total number of peers in peer list 1064 * @param trail_length Total number of peers in peer list
1085 */ 1065 */
1086void 1066void
1087GDS_NEIGHBOURS_send_notify_new_successor (struct GNUNET_PeerIdentity *source_peer, 1067GDS_NEIGHBOURS_send_notify_new_successor (const struct GNUNET_PeerIdentity *source_peer,
1088 struct GNUNET_PeerIdentity *destination_peer, 1068 const struct GNUNET_PeerIdentity *destination_peer,
1089 struct FriendInfo *target_friend, 1069 struct FriendInfo *target_friend,
1090 struct GNUNET_PeerIdentity *trail_peer_list, 1070 const struct GNUNET_PeerIdentity *trail_peer_list,
1091 unsigned int trail_length) 1071 unsigned int trail_length)
1092{ 1072{
1093 struct PeerNotifyNewSuccessorMessage *nsm; 1073 struct PeerNotifyNewSuccessorMessage *nsm;
@@ -1422,13 +1402,16 @@ compare_finger_identity (struct GNUNET_PeerIdentity *existing_finger,
1422} 1402}
1423#endif 1403#endif
1424 1404
1405
1425/** 1406/**
1426 * FIXME: Not sure of the logic to find the correct predecessor 1407 * Check if there is a predecessor in our finger peer map or not.
1427 * I think logic of this code is wrong everything else seems to be correct. 1408 * If no, then return GNUNET_YES
1428 * Given two finger identities, find the closest predecessor. 1409 * else compare existing predecessor and peer, and find the correct
1410 * predecessor.
1429 * @param existing_predecessor 1411 * @param existing_predecessor
1430 * @param new_predecessor 1412 * @param new_predecessor
1431 * @return 1413 * @return #GNUNET_YES if new peer is predecessor
1414 * #GNUNET_NO if new peer is not the predecessor.
1432 */ 1415 */
1433static int 1416static int
1434compare_predecessor(struct GNUNET_PeerIdentity *peer) 1417compare_predecessor(struct GNUNET_PeerIdentity *peer)
@@ -1436,13 +1419,132 @@ compare_predecessor(struct GNUNET_PeerIdentity *peer)
1436 /* FIXME: here you should first check if you already have an entry in the 1419 /* FIXME: here you should first check if you already have an entry in the
1437 finger peer map for finger index = 64, if yes then compare it with peer 1420 finger peer map for finger index = 64, if yes then compare it with peer
1438 if not then just add the peer. */ 1421 if not then just add the peer. */
1439 return 0; 1422 return GNUNET_YES;
1423}
1424
1425/**
1426 *
1427 * @return
1428 */
1429static struct GNUNET_PeerIdentity *
1430check_for_successor ()
1431{
1432 return NULL;
1433}
1434/**
1435 * Scan the trail, check if there is a friend in the trail, then shortcut
1436 * the trail and return the new trail and trail length.
1437 * FIXME: How to send the trail length? Should I create a new array and copy into
1438 * it or modify the existing trail. also, how can it be done optimally?
1439 * @param finger_trail
1440 * @return
1441 */
1442#if 0
1443static struct GNUNET_PeerIdentity *
1444scan_trail (struct GNUNET_PeerIdentity *finger_trail)
1445{
1446 return NULL;
1447}
1448#endif
1449
1450/**
1451 * Add an entry in finger table. Before adding, check if there is already an
1452 * entry in finger peermap for the same index, if yes then choose the closest one.
1453 * In case both the existing identity and new identity are same, keep both the trail
1454 * only if the trails are different (Redundant routing). Also, a peer stored at index,i
1455 * if its same as peer stored index, i+1, and 'i' is the lowest finger map index
1456 * seen so far, then that peer is the successor. In case finger_map_index is PREDECESSOR_INDEX,
1457 * then simply add it as handle rest of the cases for it in a different function.
1458 * Also while adding an entry check the trail, scan the trail and check if there
1459 * is a friend in between, then shortcut the path.
1460 * @param finger_identity
1461 * @param finger_trail
1462 * @param finger_trail_length
1463 * @param finger_map_index
1464 */
1465static
1466void finger_table_add (const struct GNUNET_PeerIdentity *finger_identity,
1467 const struct GNUNET_PeerIdentity *finger_trail,
1468 uint32_t finger_trail_length,
1469 uint32_t finger_map_index)
1470{
1471 struct FingerInfo new_finger_entry;
1472 int i;
1473
1474 /* If I am my own finger, then return. */
1475 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, finger_identity))
1476 {
1477 GNUNET_break (0); /* SUPU: Its here because I need to see when it happens. */
1478 return;
1479 }
1480
1481 if (finger_map_index == PREDECESSOR_FINGER_ID)
1482 goto add_new_entry;
1483
1484 /* For rest of current_finger_index, choose the correct finger and correct trail. */
1485 /* SUPU: Here I want to iterate over all the entries and see if there is already
1486 an entry for the finger map index. if yes then check if finger identity are same
1487 if yes then check the trail. if I use gnuent_container_multipeermap_iterate,
1488 i should stop after I found the finger map index, and just return the
1489 struct finger info. then I should call another function which takes care of
1490 finding the closest peer*/
1491
1492 add_new_entry:
1493 memcpy (&(new_finger_entry.finger_identity), finger_identity, sizeof (struct GNUNET_PeerIdentity));
1494 new_finger_entry.finger_map_index = finger_map_index;
1495 /* FIXME: How do I get the length as well as the trail.
1496 * scan_trail (finger_trail);
1497 */
1498 new_finger_entry.trail_length = finger_trail_length;
1499
1500 i = 0;
1501 while (i < finger_trail_length)
1502 {
1503 struct TrailPeerList *element;
1504 element = GNUNET_malloc (sizeof (struct TrailPeerList));
1505 element->next = NULL;
1506 element->prev = NULL;
1507
1508 memcpy (&(element->peer), &finger_trail[i], sizeof(struct GNUNET_PeerIdentity));
1509 GNUNET_CONTAINER_DLL_insert_tail(new_finger_entry.head, new_finger_entry.tail, element);
1510 i++;
1511 }
1512
1513 GNUNET_assert (GNUNET_OK ==
1514 GNUNET_CONTAINER_multipeermap_put (finger_peermap,
1515 &(new_finger_entry.finger_identity),
1516 &new_finger_entry,
1517 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
1518
1519 /* FIXME: after adding an entry, I want to check if there is a successor, if yes
1520 then this function will return it and then we should schedule a verify successor
1521 task */
1522 if (NULL != check_for_successor())
1523 {
1524 verify_successor = GNUNET_SCHEDULER_add_now (&send_verify_successor_message, NULL);
1525 /* FIXME: Is it safe to set the finger index to predecessor_finger_id here? */
1526 current_finger_index = PREDECESSOR_FINGER_ID;
1527 return;
1528 }
1529
1530 /* FIXME: Not sure if this is the correct place to set the values. Look into
1531 send_find_finger_trail_message and check. */
1532 if(current_finger_index == 0)
1533 current_finger_index = PREDECESSOR_FINGER_ID;
1534 else
1535 current_finger_index = current_finger_index - 1;
1440} 1536}
1441 1537
1442 1538
1539#if 0
1443/*FIXME: Here you need to set the correct value of finger_map_index, 1540/*FIXME: Here you need to set the correct value of finger_map_index,
1444 * in case it is 0, then you set it back to 64, and in case it is x, 1541 * in case it is 0, then you set it back to 64, and in case it is x,
1445 * then you set it back to x-1. current_finger_index = ( current_finger_index - 1) % MAX_FINGERS 1542 * then you set it back to x-1. current_finger_index = ( current_finger_index - 1) % MAX_FINGERS
1543 * we also need to change the logic of starting the process to look for a successor.
1544 * when you add an entry then go through whole trail and check if there is an entry
1545 * which is your friend, if yes then just collapse the trail. if you are not doing it
1546 * here then you need to do it in handle_core_disconnect where you will have to search
1547 * through whole trail find peer and then delete the finger.
1446 * Add an entry in finger table. 1548 * Add an entry in finger table.
1447 * @param finger_identity Peer identity of finger 1549 * @param finger_identity Peer identity of finger
1448 * @param finger_trail Trail to reach the finger 1550 * @param finger_trail Trail to reach the finger
@@ -1450,10 +1552,10 @@ compare_predecessor(struct GNUNET_PeerIdentity *peer)
1450 * @param finger_map_index Index in finger peer map. 1552 * @param finger_map_index Index in finger peer map.
1451 */ 1553 */
1452static 1554static
1453void finger_table_add (struct GNUNET_PeerIdentity *finger_identity, 1555void finger_table_add (const struct GNUNET_PeerIdentity *finger_identity,
1454 struct GNUNET_PeerIdentity *finger_trail, 1556 const struct GNUNET_PeerIdentity *finger_trail,
1455 unsigned int trail_length, 1557 unsigned int trail_length,
1456 unsigned int finger_map_index) 1558 const unsigned int finger_map_index)
1457{ 1559{
1458 struct FingerInfo *new_finger_entry; 1560 struct FingerInfo *new_finger_entry;
1459 //struct GNUNET_PeerIdentity key_ret; 1561 //struct GNUNET_PeerIdentity key_ret;
@@ -1541,6 +1643,9 @@ void finger_table_add (struct GNUNET_PeerIdentity *finger_identity,
1541 { 1643 {
1542 /* I am the finger */ 1644 /* I am the finger */
1543 new_finger_entry->trail_length = 0; 1645 new_finger_entry->trail_length = 0;
1646 /* FIXME: If I am the finger then why do we even do an entry. don't add any
1647 * field because it is of no use. you may just send a message to yourself
1648 * when another peer send you a trail setup or put request. */
1544 } 1649 }
1545 else 1650 else
1546 { 1651 {
@@ -1576,7 +1681,7 @@ void finger_table_add (struct GNUNET_PeerIdentity *finger_identity,
1576 verify_successor = GNUNET_SCHEDULER_add_now (&send_verify_successor_message, NULL); 1681 verify_successor = GNUNET_SCHEDULER_add_now (&send_verify_successor_message, NULL);
1577 } 1682 }
1578} 1683}
1579 1684#endif
1580 1685
1581/** 1686/**
1582 * Compare two peer identities. 1687 * Compare two peer identities.
@@ -1647,7 +1752,11 @@ find_closest_successor(struct Sorting_List *all_known_peers, uint64_t value,
1647 1752
1648 1753
1649/** 1754/**
1650 * here you should set the current source instead of destination type. 1755 * here you should set the current source instead of destination type.
1756 * so current_source is actual source till we don't find another current_source
1757 * but is it good. why are we wasting space in case current_Destination is just us.
1758 * also in many case current_destination is just me. so again it does not seem
1759 * so smart.
1651 * Find closest successor for the value. 1760 * Find closest successor for the value.
1652 * @param value Value for which we are looking for successor 1761 * @param value Value for which we are looking for successor
1653 * FIXME: pass the correct value for current_destination 1762 * FIXME: pass the correct value for current_destination
@@ -1989,7 +2098,7 @@ GDS_NEIGHBOURS_send_get_result (struct GNUNET_TIME_Absolute expiration,
1989 return; 2098 return;
1990 } 2099 }
1991 2100
1992 current_path_index = search_my_location(get_path); 2101 current_path_index = search_my_index(get_path);
1993 if (0 == current_path_index) 2102 if (0 == current_path_index)
1994 { 2103 {
1995 FPRINTF (stderr,_("\nSUPU %s, %s, %d"),__FILE__, __func__,__LINE__); 2104 FPRINTF (stderr,_("\nSUPU %s, %s, %d"),__FILE__, __func__,__LINE__);
@@ -2390,7 +2499,7 @@ handle_dht_p2p_get_result (void *cls, const struct GNUNET_PeerIdentity *peer,
2390 { 2499 {
2391 struct GNUNET_PeerIdentity *next_hop; 2500 struct GNUNET_PeerIdentity *next_hop;
2392 next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); 2501 next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
2393 current_path_index = search_my_location (get_path); 2502 current_path_index = search_my_index (get_path);
2394 /* FIXME: First check if you are adding yourself to the get path or not. 2503 /* FIXME: First check if you are adding yourself to the get path or not.
2395 if yes then don't check if current_path_index == 0, if not then check 2504 if yes then don't check if current_path_index == 0, if not then check
2396 and next_hop == source_peer. */ 2505 and next_hop == source_peer. */
@@ -2447,7 +2556,7 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer,
2447 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity))) 2556 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)))
2448 { 2557 {
2449 GNUNET_break_op (0); 2558 GNUNET_break_op (0);
2450 return GNUNET_YES; 2559 return GNUNET_OK;
2451 } 2560 }
2452 2561
2453 trail_peer_list = (struct GNUNET_PeerIdentity *)&trail_setup[1]; 2562 trail_peer_list = (struct GNUNET_PeerIdentity *)&trail_setup[1];
@@ -2456,7 +2565,7 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer,
2456 source = trail_setup->source_peer; 2565 source = trail_setup->source_peer;
2457 finger_map_index = ntohl (trail_setup->finger_map_index); 2566 finger_map_index = ntohl (trail_setup->finger_map_index);
2458 destination_finger_value = ntohl (trail_setup->destination_finger); 2567 destination_finger_value = ntohl (trail_setup->destination_finger);
2459 2568
2460 /* Check if you are part of the trail or current destination, and accordingly 2569 /* Check if you are part of the trail or current destination, and accordingly
2461 * find the next peer to send the message to. */ 2570 * find the next peer to send the message to. */
2462 if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&current_destination, &my_identity))) 2571 if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&current_destination, &my_identity)))
@@ -2465,8 +2574,7 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer,
2465 /* OPTIMIZATION: do find_successor also and get a better path if possible. */ 2574 /* OPTIMIZATION: do find_successor also and get a better path if possible. */
2466 if (next_hop == NULL) 2575 if (next_hop == NULL)
2467 { 2576 {
2468 /* FIXME next_hop to NULL, 2577 /* FIXME next_hop to NULL, 1. statistics update, drop the message.
2469 * 1. statistics update, drop the message.
2470 2. complain to sender with new message: trail lost */ 2578 2. complain to sender with new message: trail lost */
2471 return GNUNET_OK; 2579 return GNUNET_OK;
2472 } 2580 }
@@ -2493,9 +2601,8 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer,
2493 { 2601 {
2494 memcpy (&next_peer, &trail_peer_list[trail_length-2], sizeof (struct GNUNET_PeerIdentity)); 2602 memcpy (&next_peer, &trail_peer_list[trail_length-2], sizeof (struct GNUNET_PeerIdentity));
2495 } 2603 }
2496 2604
2497 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_peer); 2605 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_peer);
2498
2499 /* FIXME: URGENT change it to handle the change in current_finger_index. 2606 /* FIXME: URGENT change it to handle the change in current_finger_index.
2500 compare to your own predecessor */ 2607 compare to your own predecessor */
2501 if (compare_predecessor (&source) /* ! HAVE A PREDECESSOR || (source_peer closer than existing PREDECESOR) */) 2608 if (compare_predecessor (&source) /* ! HAVE A PREDECESSOR || (source_peer closer than existing PREDECESOR) */)
@@ -2504,14 +2611,12 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer,
2504 new_trail_list = invert_trail_list (&source, peer_list, trail_length); 2611 new_trail_list = invert_trail_list (&source, peer_list, trail_length);
2505 finger_table_add (&source, new_trail_list, trail_length, PREDECESSOR_FINGER_ID); 2612 finger_table_add (&source, new_trail_list, trail_length, PREDECESSOR_FINGER_ID);
2506 } 2613 }
2507
2508 GDS_NEIGHBOURS_send_trail_setup_result (&source, 2614 GDS_NEIGHBOURS_send_trail_setup_result (&source,
2509 &(my_identity), 2615 &(my_identity),
2510 target_friend, trail_length, 2616 target_friend, trail_length,
2511 peer_list, 2617 peer_list,
2512 finger_map_index); 2618 finger_map_index);
2513 2619 return GNUNET_OK;
2514 return GNUNET_YES;
2515 } 2620 }
2516 else 2621 else
2517 { 2622 {
@@ -2521,7 +2626,7 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer,
2521 &current_destination, &current_source, 2626 &current_destination, &current_source,
2522 target_friend, trail_length, peer_list, 2627 target_friend, trail_length, peer_list,
2523 finger_map_index); 2628 finger_map_index);
2524 return GNUNET_YES; 2629 return GNUNET_OK;
2525 } 2630 }
2526 return GNUNET_SYSERR; 2631 return GNUNET_SYSERR;
2527} 2632}
@@ -2529,22 +2634,19 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer,
2529 2634
2530/** 2635/**
2531 * Core handle for p2p trail construction result messages. 2636 * Core handle for p2p trail construction result messages.
2532 * @param cls closure 2637 * @param closure
2533 * @param message message 2638 * @param message message
2534 * @param peer peer identity this notification is about 2639 * @param peer peer identity this notification is about
2535 * @return GNUNET_OK on success, GNUNET_SYSERR on error 2640 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
2536 */ 2641 */
2537static int 2642static int
2538handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *peer, 2643handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *peer,
2539 const struct GNUNET_MessageHeader *message) 2644 const struct GNUNET_MessageHeader *message)
2540{ 2645{
2541 struct PeerTrailSetupResultMessage *trail_result; 2646 const struct PeerTrailSetupResultMessage *trail_result;
2542 struct GNUNET_PeerIdentity *trail_peer_list; 2647 const struct GNUNET_PeerIdentity *trail_peer_list;
2543 struct GNUNET_PeerIdentity *next_hop; 2648 uint32_t trail_length;
2544 struct FriendInfo *target_friend; 2649 uint32_t finger_map_index;
2545 unsigned int current_trail_index;
2546 unsigned int finger_map_index;
2547 unsigned int trail_length;
2548 size_t msize; 2650 size_t msize;
2549 2651
2550 msize = ntohs (message->size); 2652 msize = ntohs (message->size);
@@ -2554,7 +2656,7 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p
2554 return GNUNET_YES; 2656 return GNUNET_YES;
2555 } 2657 }
2556 2658
2557 trail_result = (struct PeerTrailSetupResultMessage *) message; 2659 trail_result = (const struct PeerTrailSetupResultMessage *) message;
2558 trail_length = ntohl (trail_result->trail_length); 2660 trail_length = ntohl (trail_result->trail_length);
2559 2661
2560 if ((msize < 2662 if ((msize <
@@ -2567,53 +2669,51 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p
2567 return GNUNET_YES; 2669 return GNUNET_YES;
2568 } 2670 }
2569 2671
2570 finger_map_index = ntohl (trail_result->finger_map_index); 2672 finger_map_index = htonl (trail_result->finger_map_index);
2571 2673 trail_peer_list = (const struct GNUNET_PeerIdentity *) &trail_result[1];
2572 trail_peer_list = (struct GNUNET_PeerIdentity *) &trail_result[1];
2573 2674
2574 if ( 0 == (GNUNET_CRYPTO_cmp_peer_identity (&(trail_result->destination_peer), 2675 if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&(trail_result->destination_peer),
2575 &my_identity))) 2676 &my_identity)))
2576 { 2677 {
2577 finger_table_add (&(trail_result->finger_identity), trail_peer_list, trail_length, 2678 finger_table_add (&(trail_result->finger_identity), trail_peer_list, trail_length,
2578 finger_map_index); 2679 finger_map_index);
2579
2580 return GNUNET_YES; 2680 return GNUNET_YES;
2581
2582 } 2681 }
2583 else 2682 else
2584 { 2683 {
2585 next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); 2684 struct GNUNET_PeerIdentity next_hop;
2586 current_trail_index = search_my_location (trail_peer_list); 2685 struct FriendInfo *target_friend;
2587 current_trail_index = current_trail_index - 1; 2686 int my_index;
2588 if (current_trail_index == 0) 2687
2688 my_index = search_my_index (trail_peer_list);
2689 if (my_index == 0)
2589 { 2690 {
2590 memcpy (next_hop, &(trail_result->destination_peer),sizeof (struct GNUNET_PeerIdentity)); 2691 next_hop = trail_result->destination_peer;
2591 } 2692 }
2592 else 2693 else
2593 { 2694 next_hop = trail_peer_list[my_index - 1];
2594 memcpy (next_hop, &(trail_peer_list[current_trail_index-1]),sizeof (struct GNUNET_PeerIdentity));
2595 }
2596 2695
2597 /* If trail length = 2, it means that destination and source peer are friends 2696 /* Finger table of destination peer will not contain any trail for the case
2598 Then don't add an entry. */ 2697 * where destination peer is its own finger identity. */
2599 if (trail_length != 2) 2698 if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&(trail_result->destination_peer),
2699 &(trail_result->finger_identity))))
2700 {
2600 GDS_ROUTING_add (&(trail_result->destination_peer), &(trail_result->finger_identity), 2701 GDS_ROUTING_add (&(trail_result->destination_peer), &(trail_result->finger_identity),
2601 peer, next_hop); 2702 peer, &next_hop);
2602 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); 2703 }
2603 GNUNET_free (next_hop); 2704
2604 2705 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop);
2605 GDS_NEIGHBOURS_send_trail_setup_result (&(trail_result->destination_peer), 2706 GDS_NEIGHBOURS_send_trail_setup_result (&(trail_result->destination_peer),
2606 &(trail_result->finger_identity), 2707 &(trail_result->finger_identity),
2607 target_friend, trail_length, 2708 target_friend, trail_length,
2608 trail_peer_list, 2709 trail_peer_list,
2609 finger_map_index); 2710 finger_map_index);
2610 return GNUNET_YES; 2711 return GNUNET_YES;
2611 } 2712 }
2612
2613 return GNUNET_SYSERR; 2713 return GNUNET_SYSERR;
2614} 2714}
2615 2715
2616 2716#if 0
2617/** 2717/**
2618 * FIXME: Use flag in the case finger peer map does not contain predcessor 2718 * FIXME: Use flag in the case finger peer map does not contain predcessor
2619 * then its NULL. Ideally it should never happen. 2719 * then its NULL. Ideally it should never happen.
@@ -2644,8 +2744,67 @@ get_predecessor()
2644 GNUNET_CONTAINER_multipeermap_iterator_destroy (finger_iter); 2744 GNUNET_CONTAINER_multipeermap_iterator_destroy (finger_iter);
2645 return my_predecessor; 2745 return my_predecessor;
2646} 2746}
2747#endif
2647 2748
2749/**
2750 * Core handle for p2p verify successor messages.
2751 * @param cls closure
2752 * @param message message
2753 * @param peer peer identity this notification is about
2754 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
2755 */
2756static int
2757handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *peer,
2758 const struct GNUNET_MessageHeader *message)
2759{
2760 const struct PeerVerifySuccessorMessage *vsm;
2761 const struct GNUNET_PeerIdentity *trail_peer_list;
2762 struct GNUNET_PeerIdentity next_hop;
2763 struct FriendInfo *target_friend;
2764 size_t msize;
2765 uint32_t trail_length;
2766
2767 msize = ntohs (message->size);
2768 if (msize < sizeof (struct PeerVerifySuccessorMessage))
2769 {
2770 GNUNET_break_op (0);
2771 return GNUNET_YES;
2772 }
2773
2774 vsm = (struct PeerVerifySuccessorMessage *) message;
2775 trail_length = ntohl (vsm->trail_length);
2776
2777 if ((msize < sizeof (struct PeerVerifySuccessorMessage) +
2778 trail_length * sizeof (struct GNUNET_PeerIdentity)) ||
2779 (trail_length > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)))
2780 {
2781 GNUNET_break_op (0);
2782 return GNUNET_YES;
2783 }
2784
2785 trail_peer_list = (const struct GNUNET_PeerIdentity *)&vsm[1];
2786 if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(vsm->successor),&my_identity)))
2787 {
2788 /*FIXME:URGENT:IMPLEMENT Here you are the successor, here you should check your predecessor
2789 and if there is no predecessor then just add this peer and send result
2790 if there is some other predecessor, then construct a new trial and then
2791 send back the list to requesting peer. */
2792 }
2793 else
2794 {
2795 int my_index;
2796
2797 my_index = search_my_index (trail_peer_list);
2798 memcpy (&next_hop, &trail_peer_list[my_index], sizeof (struct GNUNET_PeerIdentity));
2799 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop);
2800
2801 GDS_NEIGHBOURS_send_verify_successor (&(vsm->source_peer), &(vsm->successor),target_friend,
2802 trail_peer_list, trail_length);
2803 }
2804 return GNUNET_SYSERR;
2805}
2648 2806
2807#if 0
2649/** 2808/**
2650 * Core handle for p2p verify successor messages. 2809 * Core handle for p2p verify successor messages.
2651 * @param cls closure 2810 * @param cls closure
@@ -2697,7 +2856,7 @@ handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *pee
2697 else 2856 else
2698 { 2857 {
2699 int current_trail_index; 2858 int current_trail_index;
2700 current_trail_index = search_my_location (trail_peer_list); 2859 current_trail_index = search_my_index (trail_peer_list);
2701 memcpy (next_hop, &trail_peer_list[current_trail_index-1], sizeof (struct GNUNET_PeerIdentity)); 2860 memcpy (next_hop, &trail_peer_list[current_trail_index-1], sizeof (struct GNUNET_PeerIdentity));
2702 } 2861 }
2703 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); 2862 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop);
@@ -2746,7 +2905,7 @@ handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *pee
2746 else 2905 else
2747 { 2906 {
2748 unsigned int current_trail_index; 2907 unsigned int current_trail_index;
2749 current_trail_index = search_my_location (trail_peer_list); 2908 current_trail_index = search_my_index (trail_peer_list);
2750 memcpy (next_hop, &trail_peer_list[current_trail_index], sizeof (struct GNUNET_PeerIdentity)); 2909 memcpy (next_hop, &trail_peer_list[current_trail_index], sizeof (struct GNUNET_PeerIdentity));
2751 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); 2910 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop);
2752 GNUNET_free (next_hop); 2911 GNUNET_free (next_hop);
@@ -2756,26 +2915,25 @@ handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *pee
2756 } 2915 }
2757 return GNUNET_YES; 2916 return GNUNET_YES;
2758} 2917}
2759 2918#endif
2760 2919
2761/** 2920/**
2762 * Core handle for p2p verify successor result messages. 2921 * Core handle for p2p verify successor result messages.
2763 * @param cls closure 2922 * @param cls closure
2764 * @param message message 2923 * @param message message
2765 * @param peer peer identity this notification is about 2924 * @param peer peer identity this notification is about
2766 * @return GNUNET_OK on success, GNUNET_SYSERR on error 2925 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
2767 */ 2926 */
2768static int 2927static int
2769handle_dht_p2p_verify_successor_result(void *cls, const struct GNUNET_PeerIdentity *peer, 2928handle_dht_p2p_verify_successor_result(void *cls, const struct GNUNET_PeerIdentity *peer,
2770 const struct GNUNET_MessageHeader *message) 2929 const struct GNUNET_MessageHeader *message)
2771{ 2930{
2772 struct PeerVerifySuccessorResultMessage *vsrm; 2931 const struct PeerVerifySuccessorResultMessage *vsrm;
2932 const struct GNUNET_PeerIdentity *trail_peer_list;
2933 struct GNUNET_PeerIdentity next_hop;
2773 struct FriendInfo *target_friend; 2934 struct FriendInfo *target_friend;
2774 struct GNUNET_PeerIdentity *trail_peer_list;
2775 struct GNUNET_PeerIdentity *next_hop;
2776 unsigned int trail_length;
2777 unsigned int current_trail_index;
2778 size_t msize; 2935 size_t msize;
2936 uint32_t trail_length;
2779 2937
2780 msize = ntohs (message->size); 2938 msize = ntohs (message->size);
2781 if (msize < sizeof (struct PeerVerifySuccessorResultMessage)) 2939 if (msize < sizeof (struct PeerVerifySuccessorResultMessage))
@@ -2784,7 +2942,7 @@ handle_dht_p2p_verify_successor_result(void *cls, const struct GNUNET_PeerIdenti
2784 return GNUNET_YES; 2942 return GNUNET_YES;
2785 } 2943 }
2786 2944
2787 vsrm = (struct PeerVerifySuccessorResultMessage *) message; 2945 vsrm = (const struct PeerVerifySuccessorResultMessage *) message;
2788 trail_length = ntohl (vsrm->trail_length); 2946 trail_length = ntohl (vsrm->trail_length);
2789 2947
2790 if ((msize < 2948 if ((msize <
@@ -2797,42 +2955,62 @@ handle_dht_p2p_verify_successor_result(void *cls, const struct GNUNET_PeerIdenti
2797 return GNUNET_YES; 2955 return GNUNET_YES;
2798 } 2956 }
2799 2957
2800 trail_peer_list = (struct GNUNET_PeerIdentity *) &vsrm[1]; 2958 trail_peer_list = (const struct GNUNET_PeerIdentity *) &vsrm[1];
2801 2959
2802 if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(vsrm->destination_peer), &(my_identity)))) 2960 if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(vsrm->destination_peer), &(my_identity))))
2803 { 2961 {
2804 if(0 != (GNUNET_CRYPTO_cmp_peer_identity (&(vsrm->my_predecessor), &(my_identity)))) 2962 if(0 != (GNUNET_CRYPTO_cmp_peer_identity (&(vsrm->my_predecessor), &(my_identity))))
2805 { 2963 {
2806 finger_table_add (&(vsrm->my_predecessor), trail_peer_list, trail_length, 0); 2964 finger_table_add (&(vsrm->my_predecessor), trail_peer_list, trail_length, 0);
2807 next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); 2965 memcpy (&next_hop, &trail_peer_list[0], sizeof (struct GNUNET_PeerIdentity));
2808 memcpy (next_hop, &trail_peer_list[0], sizeof (struct GNUNET_PeerIdentity)); 2966 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop);
2809 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop);
2810 GNUNET_free (next_hop);
2811
2812 GDS_NEIGHBOURS_send_notify_new_successor (&my_identity, &(vsrm->my_predecessor), 2967 GDS_NEIGHBOURS_send_notify_new_successor (&my_identity, &(vsrm->my_predecessor),
2813 target_friend, trail_peer_list, 2968 target_friend, trail_peer_list,
2814 trail_length); 2969 trail_length);
2970 return GNUNET_OK;
2815 } 2971 }
2816 } 2972 }
2817 else 2973 else
2818 { 2974 {
2819 next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); 2975 int my_index;
2820 current_trail_index = search_my_location (trail_peer_list);
2821 if (current_trail_index == 1)
2822 memcpy (next_hop, &(vsrm->destination_peer), sizeof (struct GNUNET_PeerIdentity));
2823 else
2824 memcpy (next_hop, &trail_peer_list[current_trail_index-1], sizeof (struct GNUNET_PeerIdentity));
2825 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop);
2826 GNUNET_free (next_hop);
2827 2976
2977 my_index = search_my_index (trail_peer_list);
2978 if (my_index == 1)
2979 memcpy (&next_hop, &(vsrm->destination_peer), sizeof (struct GNUNET_PeerIdentity));
2980 else
2981 memcpy (&next_hop, &trail_peer_list[my_index-1], sizeof (struct GNUNET_PeerIdentity));
2982 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop);
2828 GDS_NEIGHBOURS_send_verify_successor_result (&(vsrm->destination_peer), 2983 GDS_NEIGHBOURS_send_verify_successor_result (&(vsrm->destination_peer),
2829 &(vsrm->source_successor), 2984 &(vsrm->source_successor),
2830 &(vsrm->my_predecessor), 2985 &(vsrm->my_predecessor),
2831 target_friend, 2986 target_friend,
2832 trail_peer_list, 2987 trail_peer_list,
2833 trail_length); 2988 trail_length);
2989 return GNUNET_OK;
2834 } 2990 }
2835 return GNUNET_YES; 2991 return GNUNET_SYSERR;
2992}
2993
2994
2995/**
2996 * Check if there is already an entry in finger_peermap for predecessor,
2997 * If not then add peer as your predecessor.
2998 * Else compare existing entry and peer, and choose the closest one as predecessor.
2999 * @param peer Peer identity
3000 * @param trail_peer_list Trail to reach from @a peer to me.
3001 */
3002static void
3003update_predecessor (const struct GNUNET_PeerIdentity *peer,
3004 const struct GNUNET_PeerIdentity *trail_peer_list)
3005{
3006 /*FIXME: URGENT: Here you should first check if there is already an entry for predecessor
3007 field or not. if not then add peer. else compare existing entry and peer,
3008 and choose the closest one as predecessor. I am confused should I call a
3009 function which just checks if this peer can be predecessor or not, and then
3010 call another function to add it. Or call a single function which checks
3011 it all and add the entry. we are never going to communicate with the peer
3012 if it is my predecessor or not. so, we don't care about the result. */
3013
2836} 3014}
2837 3015
2838 3016
@@ -2841,17 +3019,16 @@ handle_dht_p2p_verify_successor_result(void *cls, const struct GNUNET_PeerIdenti
2841 * @param cls closure 3019 * @param cls closure
2842 * @param message message 3020 * @param message message
2843 * @param peer peer identity this notification is about 3021 * @param peer peer identity this notification is about
2844 * @return GNUNET_OK on success, GNUNET_SYSERR on error 3022 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
2845 */ 3023 */
2846static int 3024static int
2847handle_dht_p2p_notify_new_successor(void *cls, const struct GNUNET_PeerIdentity *peer, 3025handle_dht_p2p_notify_new_successor(void *cls, const struct GNUNET_PeerIdentity *peer,
2848 const struct GNUNET_MessageHeader *message) 3026 const struct GNUNET_MessageHeader *message)
2849{ 3027{
2850 struct PeerNotifyNewSuccessorMessage *nsm; 3028 const struct PeerNotifyNewSuccessorMessage *nsm;
2851 struct GNUNET_PeerIdentity *trail_peer_list; 3029 const struct GNUNET_PeerIdentity *trail_peer_list;
2852 unsigned int current_trail_index;
2853 size_t msize; 3030 size_t msize;
2854 unsigned int trail_length; 3031 uint32_t trail_length;
2855 3032
2856 msize = ntohs (message->size); 3033 msize = ntohs (message->size);
2857 if (msize < sizeof (struct PeerNotifyNewSuccessorMessage)) 3034 if (msize < sizeof (struct PeerNotifyNewSuccessorMessage))
@@ -2860,7 +3037,7 @@ handle_dht_p2p_notify_new_successor(void *cls, const struct GNUNET_PeerIdentity
2860 return GNUNET_YES; 3037 return GNUNET_YES;
2861 } 3038 }
2862 3039
2863 nsm = (struct PeerNotifyNewSuccessorMessage *) message; 3040 nsm = (const struct PeerNotifyNewSuccessorMessage *) message;
2864 trail_length = ntohl (nsm->trail_length); 3041 trail_length = ntohl (nsm->trail_length);
2865 3042
2866 if ((msize < sizeof (struct PeerNotifyNewSuccessorMessage) + 3043 if ((msize < sizeof (struct PeerNotifyNewSuccessorMessage) +
@@ -2872,39 +3049,36 @@ handle_dht_p2p_notify_new_successor(void *cls, const struct GNUNET_PeerIdentity
2872 return GNUNET_YES; 3049 return GNUNET_YES;
2873 } 3050 }
2874 3051
2875 trail_peer_list = (struct GNUNET_PeerIdentity *) &nsm[1]; 3052 trail_peer_list = (const struct GNUNET_PeerIdentity *) &nsm[1];
2876 3053
2877 if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(nsm->destination_peer), &my_identity))) 3054 if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(nsm->destination_peer), &my_identity)))
2878 { 3055 {
2879 struct GNUNET_PeerIdentity *new_trail; 3056 update_predecessor (&(nsm->destination_peer), trail_peer_list);
2880 new_trail = invert_trail_list (&(nsm->source_peer), trail_peer_list, trail_length); 3057 return GNUNET_OK;
2881 finger_table_add (&(nsm->source_peer), new_trail, trail_length, 1);
2882 return GNUNET_YES;
2883 } 3058 }
2884 else 3059 else
2885 { 3060 {
2886 struct FriendInfo *target_friend; 3061 struct FriendInfo *target_friend;
2887 struct GNUNET_PeerIdentity *next_hop; 3062 struct GNUNET_PeerIdentity next_hop;
2888 3063 int my_index;
2889 target_friend = GNUNET_malloc (sizeof (struct FriendInfo));
2890 next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
2891
2892 current_trail_index = search_my_location (trail_peer_list);
2893 memcpy (next_hop, &trail_peer_list[current_trail_index+1], sizeof (struct GNUNET_PeerIdentity));
2894 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop);
2895 GNUNET_free (next_hop);
2896 3064
3065 my_index = search_my_index (trail_peer_list);
3066 memcpy (&next_hop, &trail_peer_list[my_index+1], sizeof (struct GNUNET_PeerIdentity));
3067 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop);
2897 GDS_NEIGHBOURS_send_notify_new_successor (&(nsm->source_peer), 3068 GDS_NEIGHBOURS_send_notify_new_successor (&(nsm->source_peer),
2898 &(nsm->destination_peer), 3069 &(nsm->destination_peer),
2899 target_friend, trail_peer_list, 3070 target_friend, trail_peer_list,
2900 trail_length); 3071 trail_length);
3072 return GNUNET_OK;
2901 } 3073 }
2902 return GNUNET_YES; 3074 return GNUNET_SYSERR;
2903} 3075}
2904 3076
2905 3077
2906/** 3078/**
2907 * FIXME: Does it matter if the packet was going to a finger or friend? 3079 * FIXME: I am not sure if this is correct or not. once I am done with
3080 * basic implementation then will handle threshold limits.
3081 * Does it matter if the packet was going to a finger or friend?
2908 * Core handle for p2p trail rejection messages. 3082 * Core handle for p2p trail rejection messages.
2909 * @param cls closure 3083 * @param cls closure
2910 * @param message message 3084 * @param message message
@@ -2957,18 +3131,42 @@ int handle_dht_p2p_trail_rejection(void *cls, const struct GNUNET_PeerIdentity *
2957 return GNUNET_SYSERR; 3131 return GNUNET_SYSERR;
2958} 3132}
2959 3133
2960#if 0 3134
2961/** 3135/**
2962 * 3136 * FIXME: free_finger(remove_finger); Call this function at finger_table_add,
2963 * @param cls 3137 when you replace an existing entry
2964 * @param key 3138 * Free finger and its trail.
2965 * @param value 3139 * @param remove_finger Finger to be freed.
2966 * @return 3140 */
3141static void
3142free_finger (struct FingerInfo *finger)
3143{
3144 struct TrailPeerList *peer;
3145
3146 while (NULL != (peer = finger->head))
3147 {
3148 GNUNET_CONTAINER_DLL_remove (finger->head, finger->tail, peer);
3149 GNUNET_free (peer);
3150 }
3151
3152 GNUNET_free (finger);
3153}
3154
3155
3156/**
3157 * Iterate over finger_peermap, and remove entries with peer as the first element
3158 * of their trail.
3159 * @param cls closure
3160 * @param key current public key
3161 * @param value value in the hash map
3162 * @return #GNUNET_YES if we should continue to
3163 * iterate,
3164 * #GNUNET_NO if not.
2967 */ 3165 */
2968static int 3166static int
2969remove_matching_finger (void *cls, 3167remove_matching_finger (void *cls,
2970 const struct GNUNET_PeerIdentity *key, 3168 const struct GNUNET_PeerIdentity *key,
2971 void *value) 3169 void *value)
2972{ 3170{
2973 struct FingerInfo *remove_finger = value; 3171 struct FingerInfo *remove_finger = value;
2974 const struct GNUNET_PeerIdentity *disconnected_peer = cls; 3172 const struct GNUNET_PeerIdentity *disconnected_peer = cls;
@@ -2979,12 +3177,11 @@ remove_matching_finger (void *cls,
2979 GNUNET_CONTAINER_multipeermap_remove (finger_peermap, 3177 GNUNET_CONTAINER_multipeermap_remove (finger_peermap,
2980 key, 3178 key,
2981 remove_finger)); 3179 remove_finger));
2982 /* FIXME: free_finger(remove_finger); Call this function at finger_table_add, 3180 free_finger (remove_finger);
2983 *when you replace an existing entry */
2984 } 3181 }
2985 return GNUNET_YES; 3182 return GNUNET_YES;
2986} 3183}
2987#endif 3184
2988 3185
2989/** 3186/**
2990 * Method called whenever a peer disconnects. 3187 * Method called whenever a peer disconnects.
@@ -2996,20 +3193,13 @@ static void
2996handle_core_disconnect (void *cls, 3193handle_core_disconnect (void *cls,
2997 const struct GNUNET_PeerIdentity *peer) 3194 const struct GNUNET_PeerIdentity *peer)
2998{ 3195{
2999#if 0
3000 struct FriendInfo *remove_friend; 3196 struct FriendInfo *remove_friend;
3001 //struct FingerInfo *remove_finger;
3002 // struct GNUNET_PeerIdentity key_ret;
3003 //struct GNUNET_CONTAINER_MultiPeerMapIterator *finger_iter;
3004 //struct TrailPeerList *iterator;
3005 //struct GNUNET_PeerIdentity *finger_identity;
3006 //int finger_index;
3007 3197
3008 /* Check for self message. */ 3198 /* Check for self message. */
3009 if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) 3199 if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity)))
3010 return; 3200 return;
3011 3201
3012 /* Search for peer to remove in your friend_peermap. */ 3202 /* Search for peer to remove in your friend_peermap. */
3013 remove_friend = 3203 remove_friend =
3014 GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer); 3204 GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer);
3015 3205
@@ -3018,11 +3208,15 @@ handle_core_disconnect (void *cls,
3018 GNUNET_break (0); 3208 GNUNET_break (0);
3019 return; 3209 return;
3020 } 3210 }
3021 //FPRINTF (stderr,_("\nSUPU %s, %s, %d"),__FILE__, __func__,__LINE__); 3211
3022 3212 /* Remove fingers for which this peer is the first element in the trail. */
3023 GNUNET_CONTAINER_multipeermap_iterate (finger_peermap, 3213 GNUNET_CONTAINER_multipeermap_iterate (finger_peermap,
3024 &remove_matching_finger, peer); 3214 &remove_matching_finger, (void *)peer);
3025 /* Remove the friend from friend_peermap. */ 3215
3216 /* Remove routing trails of which this peer is a part. */
3217 GDS_ROUTING_remove_entry (peer);
3218
3219 /* Remove the peer from friend_peermap. */
3026 GNUNET_assert (GNUNET_YES == 3220 GNUNET_assert (GNUNET_YES ==
3027 GNUNET_CONTAINER_multipeermap_remove (friend_peermap, 3221 GNUNET_CONTAINER_multipeermap_remove (friend_peermap,
3028 peer, 3222 peer,
@@ -3044,10 +3238,6 @@ handle_core_disconnect (void *cls,
3044 GNUNET_SCHEDULER_cancel (verify_successor); 3238 GNUNET_SCHEDULER_cancel (verify_successor);
3045 verify_successor = GNUNET_SCHEDULER_NO_TASK; 3239 verify_successor = GNUNET_SCHEDULER_NO_TASK;
3046 } 3240 }
3047 /* FIXME: garbage collect routing table, and notify the failed trails about
3048 trail lost.
3049 */
3050#endif
3051} 3241}
3052 3242
3053 3243
@@ -3074,9 +3264,7 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer_identity)
3074 GNUNET_break (0); 3264 GNUNET_break (0);
3075 return; 3265 return;
3076 } 3266 }
3077 /* FIXME: Use statistics at places where you think such a conditions are very 3267
3078 rare. Then use statistics to make sure that it is indeed rare but if not
3079 rare then hanlde it differently.*/
3080 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# peers connected"), 1, 3268 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# peers connected"), 1,
3081 GNUNET_NO); 3269 GNUNET_NO);
3082 3270
@@ -3105,13 +3293,6 @@ core_init (void *cls,
3105 const struct GNUNET_PeerIdentity *identity) 3293 const struct GNUNET_PeerIdentity *identity)
3106{ 3294{
3107 my_identity = *identity; 3295 my_identity = *identity;
3108
3109 /* SUPU TEST CODE */
3110 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3111 _("\nSUPU %s, %s, %d,my_identity = %s"),
3112 __FILE__, __func__, __LINE__, GNUNET_i2s (&my_identity));
3113 /* SUPU TEST CODE ENDS */
3114
3115} 3296}
3116 3297
3117 3298
@@ -3120,7 +3301,7 @@ core_init (void *cls,
3120 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 3301 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
3121 */ 3302 */
3122int 3303int
3123GDS_NEIGHBOURS_init() 3304GDS_NEIGHBOURS_init (void)
3124{ 3305{
3125 static struct GNUNET_CORE_MessageHandler core_handlers[] = { 3306 static struct GNUNET_CORE_MessageHandler core_handlers[] = {
3126 {&handle_dht_p2p_put, GNUNET_MESSAGE_TYPE_DHT_P2P_PUT, 0}, 3307 {&handle_dht_p2p_put, GNUNET_MESSAGE_TYPE_DHT_P2P_PUT, 0},
@@ -3159,7 +3340,7 @@ GDS_NEIGHBOURS_init()
3159 * Shutdown neighbours subsystem. 3340 * Shutdown neighbours subsystem.
3160 */ 3341 */
3161void 3342void
3162GDS_NEIGHBOURS_done () 3343GDS_NEIGHBOURS_done (void)
3163{ 3344{
3164 if (NULL == core_api) 3345 if (NULL == core_api)
3165 return; 3346 return;
@@ -3185,10 +3366,6 @@ GDS_NEIGHBOURS_done ()
3185 find_finger_trail_task = GNUNET_SCHEDULER_NO_TASK; 3366 find_finger_trail_task = GNUNET_SCHEDULER_NO_TASK;
3186 } 3367 }
3187 3368
3188 /* FIXME: when do you cancel verify successor irrespective of this part
3189 of code. If no where else, then there should not be GNUNET_break (0) as it
3190 is right to call it here. Also, leave it here for time being and in case
3191 you always encounter this break, it means it is nor required. remove it then. */
3192 if (GNUNET_SCHEDULER_NO_TASK != verify_successor) 3369 if (GNUNET_SCHEDULER_NO_TASK != verify_successor)
3193 { 3370 {
3194 GNUNET_break (0); 3371 GNUNET_break (0);
@@ -3199,13 +3376,11 @@ GDS_NEIGHBOURS_done ()
3199 3376
3200 3377
3201/** 3378/**
3202 * FIXME: I want to remove const but at the moment its giving error
3203 * in client file.
3204 * Get my identity 3379 * Get my identity
3205 * 3380 *
3206 * @return my identity 3381 * @return my identity
3207 */ 3382 */
3208struct GNUNET_PeerIdentity * 3383const struct GNUNET_PeerIdentity *
3209GDS_NEIGHBOURS_get_my_id (void) 3384GDS_NEIGHBOURS_get_my_id (void)
3210{ 3385{
3211 return &my_identity; 3386 return &my_identity;
diff --git a/src/dht/gnunet-service-xdht_neighbours.h b/src/dht/gnunet-service-xdht_neighbours.h
index b0d509b0b..f4cfe4ae8 100644
--- a/src/dht/gnunet-service-xdht_neighbours.h
+++ b/src/dht/gnunet-service-xdht_neighbours.h
@@ -149,7 +149,7 @@ GDS_NEIGHBOURS_done (void);
149 * 149 *
150 * @return my identity 150 * @return my identity
151 */ 151 */
152struct GNUNET_PeerIdentity * 152const struct GNUNET_PeerIdentity *
153GDS_NEIGHBOURS_get_my_id (void); 153GDS_NEIGHBOURS_get_my_id (void);
154 154
155 155
diff --git a/src/dht/gnunet-service-xdht_routing.c b/src/dht/gnunet-service-xdht_routing.c
index f083b6e62..59df8ed40 100644
--- a/src/dht/gnunet-service-xdht_routing.c
+++ b/src/dht/gnunet-service-xdht_routing.c
@@ -72,69 +72,39 @@ struct RoutingTrail
72 */ 72 */
73static struct GNUNET_CONTAINER_MultiPeerMap *routing_table; 73static struct GNUNET_CONTAINER_MultiPeerMap *routing_table;
74 74
75
76/** 75/**
77 * Add a new entry to our routing table. 76 * Iterate over routing table and remove entries for which peer is a part.
78 * @param source peer Source of the trail. 77 * @param cls closure
79 * @param destintation Destination of the trail. 78 * @param key current public key
80 * @param next_hop Next peer to forward the message to reach the destination. 79 * @param value value in the hash map
81 * @return GNUNET_YES 80 * @return #GNUNET_YES if we should continue to
82 * GNUNET_SYSERR If the number of routing entries crossed thershold. 81 * iterate,
82 * #GNUNET_NO if not.
83 */ 83 */
84int 84static int
85GDS_ROUTING_add (struct GNUNET_PeerIdentity *source, 85remove_routing_entry (void *cls,
86 struct GNUNET_PeerIdentity *dest, 86 const struct GNUNET_PeerIdentity *key,
87 const struct GNUNET_PeerIdentity *next_hop, 87 void *value)
88 struct GNUNET_PeerIdentity *prev_hop)
89{ 88{
90 struct RoutingTrail *new_routing_entry; 89 struct RoutingTrail *remove_entry = value;
91 90 const struct GNUNET_PeerIdentity *disconnected_peer = cls;
92 if (GNUNET_CONTAINER_multipeermap_size(routing_table) > ROUTING_TABLE_THRESHOLD)
93 return GNUNET_SYSERR;
94 //FPRINTF (stderr,_("\nSUPU ROUTING ADD %s, %s, %d"),__FILE__, __func__,__LINE__);
95 new_routing_entry = GNUNET_malloc (sizeof (struct RoutingTrail));
96 memcpy (&(new_routing_entry->source) , source, sizeof (struct GNUNET_PeerIdentity));
97 memcpy (&(new_routing_entry->next_hop), next_hop, sizeof (struct GNUNET_PeerIdentity));
98 memcpy (&(new_routing_entry->destination), dest, sizeof (struct GNUNET_PeerIdentity));
99 memcpy (&(new_routing_entry->prev_hop), prev_hop, sizeof (struct GNUNET_PeerIdentity));
100 91
101 GNUNET_assert (GNUNET_OK == 92 if ((0 == GNUNET_CRYPTO_cmp_peer_identity (&(remove_entry->source), disconnected_peer)) ||
102 GNUNET_CONTAINER_multipeermap_put (routing_table, 93 (0 == GNUNET_CRYPTO_cmp_peer_identity (&(remove_entry->destination), disconnected_peer)) ||
103 dest, new_routing_entry, 94 (0 == GNUNET_CRYPTO_cmp_peer_identity (&(remove_entry->next_hop), disconnected_peer)) ||
104 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 95 (0 == GNUNET_CRYPTO_cmp_peer_identity (&(remove_entry->prev_hop), disconnected_peer)))
105
106 /* SUPU TEST CODE */
107 /* Here I want to see if routing table is correct or not. */
108 int test_index;
109 struct GNUNET_CONTAINER_MultiPeerMapIterator *test_iter;
110 struct GNUNET_PeerIdentity *print_peer;
111 print_peer = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
112 struct RoutingTrail *test_trail;
113 test_iter = GNUNET_CONTAINER_multipeermap_iterator_create (routing_table);
114 for (test_index = 0; test_index < GNUNET_CONTAINER_multipeermap_size (routing_table); test_index++)
115 { 96 {
116 FPRINTF (stderr,_("\nSUPU %s, %s, %d, entry[%d]"),__FILE__, __func__,__LINE__,test_index); 97 GNUNET_assert (GNUNET_YES ==
117 if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next (test_iter, NULL, 98 GNUNET_CONTAINER_multipeermap_remove (routing_table,
118 (const void **)&test_trail)) 99 key,
119 { 100 remove_entry));
120 memcpy (print_peer, &(test_trail->source),sizeof (struct GNUNET_PeerIdentity));
121 FPRINTF (stderr,_("\nSUPU %s, %s, %d, test_trail->source =%s"),__FILE__, __func__,__LINE__,GNUNET_i2s (print_peer));
122 memcpy (print_peer, &(test_trail->destination),sizeof (struct GNUNET_PeerIdentity));
123 FPRINTF (stderr,_("\nSUPU %s, %s, %d, test_trail->destination =%s"),__FILE__, __func__,__LINE__,GNUNET_i2s(print_peer));
124 memcpy (print_peer, &(test_trail->prev_hop),sizeof (struct GNUNET_PeerIdentity));
125 FPRINTF (stderr,_("\nSUPU %s, %s, %d, test_trail->prev_hop =%s"),__FILE__, __func__,__LINE__,GNUNET_i2s(print_peer));
126 memcpy (print_peer, &(test_trail->next_hop),sizeof (struct GNUNET_PeerIdentity));
127 FPRINTF (stderr,_("\nSUPU %s, %s, %d, test_trail->next_hop =%s"),__FILE__, __func__,__LINE__,GNUNET_i2s(print_peer));
128
129 }
130 } 101 }
131 /* SUPU TEST CODE ENDS*/
132 return GNUNET_YES; 102 return GNUNET_YES;
133} 103}
134 104
135 105
136/** 106/**
137 * Iterate over multiple entries for same destinational value and get 107 * Iterate over multiple entries for same destination value and get
138 * the correct next hop. 108 * the correct next hop.
139 * @param cls struct RoutingTrail 109 * @param cls struct RoutingTrail
140 * @param key Destination identity 110 * @param key Destination identity
@@ -162,6 +132,53 @@ get_next_hop (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
162 132
163 133
164/** 134/**
135 * Add a new entry to our routing table.
136 * @param source peer Source of the trail.
137 * @param destintation Destination of the trail.
138 * @param next_hop Next peer to forward the message to reach the destination.
139 * @return GNUNET_YES
140 * GNUNET_SYSERR If the number of routing entries crossed thershold.
141 */
142int
143GDS_ROUTING_add (const struct GNUNET_PeerIdentity *source,
144 const struct GNUNET_PeerIdentity *dest,
145 const struct GNUNET_PeerIdentity *next_hop,
146 struct GNUNET_PeerIdentity *prev_hop)
147{
148 struct RoutingTrail *new_routing_entry;
149
150 if (GNUNET_CONTAINER_multipeermap_size(routing_table) > ROUTING_TABLE_THRESHOLD)
151 return GNUNET_SYSERR;
152
153 new_routing_entry = GNUNET_malloc (sizeof (struct RoutingTrail));
154 memcpy (&(new_routing_entry->source) , source, sizeof (struct GNUNET_PeerIdentity));
155 memcpy (&(new_routing_entry->next_hop), next_hop, sizeof (struct GNUNET_PeerIdentity));
156 memcpy (&(new_routing_entry->destination), dest, sizeof (struct GNUNET_PeerIdentity));
157 memcpy (&(new_routing_entry->prev_hop), prev_hop, sizeof (struct GNUNET_PeerIdentity));
158
159 GNUNET_assert (GNUNET_OK ==
160 GNUNET_CONTAINER_multipeermap_put (routing_table,
161 dest, new_routing_entry,
162 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
163
164 return GNUNET_YES;
165}
166
167
168/**
169 * Iterate over routing table and remove entries for which peer is a part.
170 * @param peer
171 * @return
172 */
173void
174GDS_ROUTING_remove_entry (const struct GNUNET_PeerIdentity *peer)
175{
176 GNUNET_CONTAINER_multipeermap_iterate (routing_table, &remove_routing_entry,
177 (void *)peer);
178}
179
180
181/**
165 * Find the next hop to send packet to. 182 * Find the next hop to send packet to.
166 * @param source_peer Source of the trail. 183 * @param source_peer Source of the trail.
167 * @param destination_peer Destination of the trail. 184 * @param destination_peer Destination of the trail.
@@ -178,8 +195,7 @@ GDS_ROUTING_search(struct GNUNET_PeerIdentity *source_peer,
178 memcpy (&(trail->destination), destination_peer, sizeof (struct GNUNET_PeerIdentity)); 195 memcpy (&(trail->destination), destination_peer, sizeof (struct GNUNET_PeerIdentity));
179 memcpy (&(trail->source), source_peer, sizeof (struct GNUNET_PeerIdentity)); 196 memcpy (&(trail->source), source_peer, sizeof (struct GNUNET_PeerIdentity));
180 memcpy (&(trail->prev_hop), prev_hop, sizeof (struct GNUNET_PeerIdentity)); 197 memcpy (&(trail->prev_hop), prev_hop, sizeof (struct GNUNET_PeerIdentity));
181 //trail->next_hop = NULL; 198
182 //FPRINTF (stderr,_("\nSUPU ROUTING SEARCH %s, %s, %d"),__FILE__, __func__,__LINE__);
183 GNUNET_CONTAINER_multipeermap_get_multiple (routing_table, destination_peer, 199 GNUNET_CONTAINER_multipeermap_get_multiple (routing_table, destination_peer,
184 get_next_hop, trail); 200 get_next_hop, trail);
185 if(trail != NULL) 201 if(trail != NULL)
@@ -189,41 +205,12 @@ GDS_ROUTING_search(struct GNUNET_PeerIdentity *source_peer,
189} 205}
190 206
191 207
192/**FIXME: Old implementation just to remove error
193 * Handle a reply (route to origin). Only forwards the reply back to
194 * other peers waiting for it. Does not do local caching or
195 * forwarding to local clients. Essentially calls
196 * GDS_NEIGHBOURS_handle_reply for all peers that sent us a matching
197 * request recently.
198 *
199 * @param type type of the block
200 * @param expiration_time when does the content expire
201 * @param key key for the content
202 * @param put_path_length number of entries in put_path
203 * @param put_path peers the original PUT traversed (if tracked)
204 * @param get_path_length number of entries in get_path
205 * @param get_path peers this reply has traversed so far (if tracked)
206 * @param data payload of the reply
207 * @param data_size number of bytes in data
208 */
209void
210GDS_ROUTING_process (enum GNUNET_BLOCK_Type type,
211 struct GNUNET_TIME_Absolute expiration_time,
212 const struct GNUNET_HashCode * key, unsigned int put_path_length,
213 const struct GNUNET_PeerIdentity *put_path,
214 unsigned int get_path_length,
215 const struct GNUNET_PeerIdentity *get_path,
216 const void *data, size_t data_size)
217{
218 return;
219}
220
221/** 208/**
222 * Check if the size of routing table has crossed threshold. 209 * Check if the size of routing table has crossed threshold.
223 * @return 210 * @return
224 */ 211 */
225int 212int
226GDS_ROUTING_size () 213GDS_ROUTING_check_threshold ()
227{ 214{
228 int ret; 215 int ret;
229 ret = (GNUNET_CONTAINER_multipeermap_size(routing_table) > ROUTING_TABLE_THRESHOLD) ? 0:1; 216 ret = (GNUNET_CONTAINER_multipeermap_size(routing_table) > ROUTING_TABLE_THRESHOLD) ? 0:1;
@@ -235,7 +222,7 @@ GDS_ROUTING_size ()
235 * Initialize routing subsystem. 222 * Initialize routing subsystem.
236 */ 223 */
237void 224void
238GDS_ROUTING_init () 225GDS_ROUTING_init (void)
239{ 226{
240 routing_table = GNUNET_CONTAINER_multipeermap_create (DHT_MAX_RECENT * 4 / 3, GNUNET_NO); 227 routing_table = GNUNET_CONTAINER_multipeermap_create (DHT_MAX_RECENT * 4 / 3, GNUNET_NO);
241} 228}
@@ -245,7 +232,7 @@ GDS_ROUTING_init ()
245 * Shutdown routing subsystem. 232 * Shutdown routing subsystem.
246 */ 233 */
247void 234void
248GDS_ROUTING_done () 235GDS_ROUTING_done (void)
249{ 236{
250 GNUNET_assert (0 == GNUNET_CONTAINER_multipeermap_size (routing_table)); 237 GNUNET_assert (0 == GNUNET_CONTAINER_multipeermap_size (routing_table));
251 GNUNET_CONTAINER_multipeermap_destroy (routing_table); 238 GNUNET_CONTAINER_multipeermap_destroy (routing_table);
diff --git a/src/dht/gnunet-service-xdht_routing.h b/src/dht/gnunet-service-xdht_routing.h
index 147d36480..70bacebf5 100644
--- a/src/dht/gnunet-service-xdht_routing.h
+++ b/src/dht/gnunet-service-xdht_routing.h
@@ -33,15 +33,29 @@
33 33
34/** 34/**
35 * Add a new entry to our routing table. 35 * Add a new entry to our routing table.
36*/ 36 * @param source peer Source of the trail.
37 * @param destintation Destination of the trail.
38 * @param next_hop Next peer to forward the message to reach the destination.
39 * @return GNUNET_YES
40 * GNUNET_SYSERR If the number of routing entries crossed thershold.
41 */
37int 42int
38GDS_ROUTING_add (struct GNUNET_PeerIdentity *source, 43GDS_ROUTING_add (const struct GNUNET_PeerIdentity *source,
39 struct GNUNET_PeerIdentity *destination_peer, 44 const struct GNUNET_PeerIdentity *dest,
40 const struct GNUNET_PeerIdentity *next_hop, 45 const struct GNUNET_PeerIdentity *next_hop,
41 struct GNUNET_PeerIdentity *prev_hop); 46 struct GNUNET_PeerIdentity *prev_hop);
42 47
43 48
44/** 49/**
50 * Iterate over routing table and remove entries for which peer is a part.
51 * @param peer
52 * @return
53 */
54void
55GDS_ROUTING_remove_entry (const struct GNUNET_PeerIdentity *peer);
56
57
58/**
45 * Search the next hop to send the packet to in routing table. 59 * Search the next hop to send the packet to in routing table.
46 * @return next hop peer id 60 * @return next hop peer id
47 */ 61 */
@@ -50,37 +64,12 @@ GDS_ROUTING_search(struct GNUNET_PeerIdentity *source_peer,
50 struct GNUNET_PeerIdentity *destination_peer, 64 struct GNUNET_PeerIdentity *destination_peer,
51 const struct GNUNET_PeerIdentity *prev_hop); 65 const struct GNUNET_PeerIdentity *prev_hop);
52 66
53/**
54 * Handle a reply (route to origin). Only forwards the reply back to
55 * other peers waiting for it. Does not do local caching or
56 * forwarding to local clients. Essentially calls
57 * GDS_NEIGHBOURS_handle_reply for all peers that sent us a matching
58 * request recently.
59 *
60 * @param type type of the block
61 * @param expiration_time when does the content expire
62 * @param key key for the content
63 * @param put_path_length number of entries in @a put_path
64 * @param put_path peers the original PUT traversed (if tracked)
65 * @param get_path_length number of entries in @a get_path
66 * @param get_path peers this reply has traversed so far (if tracked)
67 * @param data payload of the reply
68 * @param data_size number of bytes in @a data
69 */
70void
71GDS_ROUTING_process (enum GNUNET_BLOCK_Type type,
72 struct GNUNET_TIME_Absolute expiration_time,
73 const struct GNUNET_HashCode * key, unsigned int put_path_length,
74 const struct GNUNET_PeerIdentity *put_path,
75 unsigned int get_path_length,
76 const struct GNUNET_PeerIdentity *get_path,
77 const void *data, size_t data_size);
78 67
79/** 68/**
80 * Check if size of routing table is greater than threshold or not. 69 * Check if size of routing table is greater than threshold or not.
81 */ 70 */
82int 71int
83GDS_ROUTING_size (void); 72GDS_ROUTING_check_threshold (void);
84 73
85/** 74/**
86 * Initialize routing subsystem. 75 * Initialize routing subsystem.