aboutsummaryrefslogtreecommitdiff
path: root/src/dht
diff options
context:
space:
mode:
authorSupriti Singh <supritisingh08@gmail.com>2014-01-27 10:51:33 +0000
committerSupriti Singh <supritisingh08@gmail.com>2014-01-27 10:51:33 +0000
commitb238cc48391682b2fee423f3cb4de1965eef1aaf (patch)
tree793f9372fedf9ba4d1c27e15e1be31e5c55de26e /src/dht
parentdb51f79c2b0933f78b423b5cbe5ddb85562244a2 (diff)
downloadgnunet-b238cc48391682b2fee423f3cb4de1965eef1aaf.tar.gz
gnunet-b238cc48391682b2fee423f3cb4de1965eef1aaf.zip
-Modified struct PeerTrailSetupMessage.
-Modified struct PeerTrailSetupResultMessage. -Added stubs for find_predecessor. -Added comments to understand the flow.
Diffstat (limited to 'src/dht')
-rw-r--r--src/dht/gnunet-service-xdht_neighbours.c548
-rw-r--r--src/dht/gnunet-service-xdht_neighbours.h88
-rw-r--r--src/dht/gnunet-service-xdht_routing.c34
-rw-r--r--src/dht/gnunet-service-xdht_routing.h34
4 files changed, 498 insertions, 206 deletions
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c
index 06891bb21..568dbae2f 100644
--- a/src/dht/gnunet-service-xdht_neighbours.c
+++ b/src/dht/gnunet-service-xdht_neighbours.c
@@ -20,7 +20,7 @@
20 20
21/** 21/**
22 * @file dht/gnunet-service-xdht_neighbours.c 22 * @file dht/gnunet-service-xdht_neighbours.c
23 * @brief GNUnet DHT service's bucket and neighbour management code 23 * @brief GNUnet DHT service's finger and friend table management code
24 * @author Supriti Singh 24 * @author Supriti Singh
25 */ 25 */
26 26
@@ -48,7 +48,17 @@
48#include <fenv.h> 48#include <fenv.h>
49#include "dht.h" 49#include "dht.h"
50 50
51/* The maximum possible fingers of a peer. */ 51
52/*TODO
53 1. Add logic to get connected to your predecessor
54 because when nodes join/fail , you need to maintain correct
55 pointers to predecessor and your successor i.e.your first finger,
56 to update tables.
57 2. Remove extra comments. */
58
59/**
60 * Maximum possible fingers of a peer.
61 */
52#define MAX_FINGERS 256 62#define MAX_FINGERS 256
53 63
54/** 64/**
@@ -59,12 +69,12 @@
59/** 69/**
60 * How long at least to wait before sending another find finger trail request. 70 * How long at least to wait before sending another find finger trail request.
61 */ 71 */
62#define DHT_MINIMUM_FIND_PEER_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) 72#define DHT_MINIMUM_FIND_FINGER_TRAIL_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30)
63 73
64/** 74/**
65 * How long at most to wait before sending another find finger trail request. 75 * How long at most to wait before sending another find finger trail request.
66 */ 76 */
67#define DHT_MAXIMUM_FIND_PEER_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 10) 77#define DHT_MAXIMUM_FIND_FINGER_TRAIL_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 10)
68 78
69 79
70GNUNET_NETWORK_STRUCT_BEGIN 80GNUNET_NETWORK_STRUCT_BEGIN
@@ -230,7 +240,8 @@ struct PeerGetMessage
230 240
231 241
232/** 242/**
233 * FIXME : should change the fields 243 * FIXME : I am using the same structure trail list in both finger info
244 * and peertrailsetupmessage. Verify if its okay.
234 * P2P Trail setup message 245 * P2P Trail setup message
235 */ 246 */
236struct PeerTrailSetupMessage 247struct PeerTrailSetupMessage
@@ -240,37 +251,40 @@ struct PeerTrailSetupMessage
240 */ 251 */
241 struct GNUNET_MessageHeader header; 252 struct GNUNET_MessageHeader header;
242 253
243 /* Source peer which wants to find trail to one of its finger. */ 254 /**
255 * Source peer which wants to find trail to one of its finger.
256 */
244 struct GNUNET_PeerIdentity *source_peer; 257 struct GNUNET_PeerIdentity *source_peer;
245 258
246 /* Finger id to which we want to set up the trail to. */ 259 /**
260 * Finger id to which we want to set up the trail to.
261 */
247 struct GNUNET_PeerIdentity *destination_finger; 262 struct GNUNET_PeerIdentity *destination_finger;
263
264 /**
265 * This field contains the peer to which this packet is forwarded.
266 */
267 struct GNUNET_PeerIdentity *current_destination;
268
269 /**
270 * Head of trail list.
271 */
272 struct TrailList *head;
248 273
249 /* This field contains the peer to which this packet is forwarded. 274 /**
250 If temp_destination = my_identity, then check if destination_finger = temp_destination. 275 * Tail of trail list.
251 If temp_destination != my_identity, then it means you are part of trail that 276 */
252 you take to temp_destination. So, search in routing table. 277 struct TrailList *tail;
253 */
254 struct GNUNET_PeerIdentity *temp_destination;
255
256 /*FIXME: I want to store a list of all the peer_id which are part of trail in
257 this message
258 Also, when sending the reply back we are just going to read this list
259 backwards. Assuming that we add a new peer at the end of our list. */
260
261 278
262
263}; 279};
280
281
264/** 282/**
265 * P2P Trail setup Result message 283 * P2P Trail setup Result message
266 * TODO: Check the fields and if they are really required. 284 * FIXME: There seem to be no difference between trail_setup and trailsetupresult
267 * FIXME: should change the fields 285 * Can we somehow merge these two. As in result we don't have to do any
268 * it can contain the peertrailsetup only 286 * search in our finger or friend table thats why I kept it separate. But is it
269 * and we just read the list backwards and make the 287 * actually required to keep these two things different.
270 * packet reach to destination
271 *There can be lots and lots of cases where the packet are lost but
272 * as we have non blocking function call we are ok
273 * i think i will implement and verify by printing the design.
274 */ 288 */
275struct PeerTrailSetupResultMessage 289struct PeerTrailSetupResultMessage
276{ 290{
@@ -279,42 +293,40 @@ struct PeerTrailSetupResultMessage
279 */ 293 */
280 struct GNUNET_MessageHeader header; 294 struct GNUNET_MessageHeader header;
281 295
296 /* It should contain the list of peers which form the trail.
297 and also maintain a pointer to the current_peer to which we have to forward
298 the packet. We have to maintain the whole list in this message because
299 at the end source peer will store this list in its finger table. */
300
282 /** 301 /**
283 * Content type. 302 * Source peer which wants to find trail to one of its finger.
284 */ 303 */
285 uint32_t type GNUNET_PACKED; 304 struct GNUNET_PeerIdentity *source_peer;
286 305
287 /** 306 /**
288 * Length of the PUT path that follows (if tracked). 307 * Finger id to which we want to set up the trail to.
289 */ 308 */
290 uint32_t put_path_length GNUNET_PACKED; 309 struct GNUNET_PeerIdentity *destination_finger;
291 310
292 /** 311 /**
293 * Length of the GET path that follows (if tracked). 312 * This field contains the peer to which this packet is forwarded.
294 */ 313 */
295 uint32_t get_path_length GNUNET_PACKED; 314 struct GNUNET_PeerIdentity *current_destination;
296 315
297 /** 316 /**
298 * When does the content expire? 317 * Head of trail list.
299 */ 318 */
300 struct GNUNET_TIME_AbsoluteNBO expiration_time; 319 struct TrailList *head;
301 320
302 /** 321 /**
303 * The key of the corresponding GET request. 322 * Tail of trail list.
304 */ 323 */
305 struct GNUNET_HashCode key; 324 struct TrailList *tail;
306
307 /* put path (if tracked) */
308
309 /* get path (if tracked) */
310
311 /* Payload */
312
313}; 325};
314 326
315GNUNET_NETWORK_STRUCT_END 327GNUNET_NETWORK_STRUCT_END
316 328
317 329
318/** 330/**
319 * Linked list of messages to send to a particular other peer. 331 * Linked list of messages to send to a particular other peer.
320 */ 332 */
@@ -334,12 +346,12 @@ struct P2PPendingMessage
334 * When does this message time out? 346 * When does this message time out?
335 */ 347 */
336 struct GNUNET_TIME_Absolute timeout; 348 struct GNUNET_TIME_Absolute timeout;
337 349
338 /** 350 /**
339 * Message importance level. FIXME: used? useful? 351 * Message importance level. FIXME: used? useful?
340 */ 352 */
341 unsigned int importance; 353 unsigned int importance;
342 354
343 /** 355 /**
344 * Actual message to be sent, allocated at the end of the struct: 356 * Actual message to be sent, allocated at the end of the struct:
345 * // msg = (cast) &pm[1]; 357 * // msg = (cast) &pm[1];
@@ -349,13 +361,34 @@ struct P2PPendingMessage
349 361
350}; 362};
351 363
364/**
365 * Linked List of peers which are part of trail to reach a particular Finger.
366 */
367struct TrailList
368{
369 /**
370 * Pointer to next item in the list
371 */
372 struct TrailList *next;
373
374 /**
375 * Pointer to previous item in the list
376 */
377 struct TrailList *prev;
378
379 /**
380 * An element in this trail list
381 */
382 struct GNUNET_PeerIdentity *peer;
383
384};
352 385
353/** 386/**
354 * Entry in friend_peers map. 387 * Entry in friend_peers map.
355 */ 388 */
356struct FriendInfo 389struct FriendInfo
357{ 390{
358 391
359 /** 392 /**
360 * What is the identity of the peer? 393 * What is the identity of the peer?
361 */ 394 */
@@ -375,8 +408,7 @@ struct FriendInfo
375 * Tail of pending messages to be sent to this peer. 408 * Tail of pending messages to be sent to this peer.
376 */ 409 */
377 struct P2PPendingMessage *tail; 410 struct P2PPendingMessage *tail;
378 411
379
380 /** 412 /**
381 * TODO - How and where to use this? 413 * TODO - How and where to use this?
382 * Core handle for sending messages to this peer. 414 * Core handle for sending messages to this peer.
@@ -386,50 +418,36 @@ struct FriendInfo
386}; 418};
387 419
388/** 420/**
389 * Linked List of peers which are part of trail to reach a particular Finger.
390 */
391struct TrailList
392{
393 /**
394 * Pointer to next item in the list
395 */
396 struct TrailList *next;
397
398 /**
399 * Pointer to previous item in the list
400 */
401 struct TrailList *prev;
402};
403
404/**
405 * Entry in finger_peers map. 421 * Entry in finger_peers map.
406 */ 422 */
407struct FingerInfo 423struct FingerInfo
408{ 424{
409 /** 425 /**
410 * What is the identity of the peer? 426 * What is the identity of the peer?
411 */ 427 */
412 struct GNUNET_PeerIdentity id; 428 struct GNUNET_PeerIdentity id;
413 429
414 /* FIXME:: Range of keys for which this finger is responsible */ 430
415 /* Start of the interval of keys for which this finger is responsible. */ 431 /**
432 * Start of the interval of keys for which this finger is responsible.
433 */
416 unsigned int interval_start; 434 unsigned int interval_start;
417 435
418 /* End of the interval of keys for which this finger is responsible. */ 436 /**
437 * End of the interval of keys for which this finger is responsible.
438 */
419 unsigned int interval_end; 439 unsigned int interval_end;
420 440
421
422 /* FIXME:: A double link list which stores the trail to reach it from given peer .*/
423
424 /** 441 /**
425 * Head of trail list. 442 * Head of trail list.
426 */ 443 */
427 struct TrailList *head; 444 struct TrailList *head;
428 445
429 /** 446 /**
430 * Tail of trail list. 447 * Tail of trail list.
431 */ 448 */
432 struct TrailList *tail; 449 struct TrailList *tail;
450
433}; 451};
434 452
435 453
@@ -475,11 +493,11 @@ static unsigned int finger_id;
475 493
476 494
477/** 495/**
496 * TODO: Check this function again.
478 * Called when core is ready to send a message we asked for 497 * Called when core is ready to send a message we asked for
479 * out to the destination. At the moment, I have just copied it from previous 498 * out to the destination.
480 * code. 499 *
481 * 500 * @param cls the 'struct FriendInfo' of the target friend peer
482 * @param cls the 'struct PeerInfo' of the target peer
483 * @param size number of bytes available in buf 501 * @param size number of bytes available in buf
484 * @param buf where the callee should write the message 502 * @param buf where the callee should write the message
485 * @return number of bytes written to buf 503 * @return number of bytes written to buf
@@ -554,7 +572,7 @@ core_transmit_notify (void *cls, size_t size, void *buf)
554static void 572static void
555process_peer_queue (struct FriendInfo *peer) 573process_peer_queue (struct FriendInfo *peer)
556{ 574{
557 575
558 struct P2PPendingMessage *pending; 576 struct P2PPendingMessage *pending;
559 577
560 if (NULL == (pending = peer->head)) 578 if (NULL == (pending = peer->head))
@@ -565,6 +583,7 @@ process_peer_queue (struct FriendInfo *peer)
565 gettext_noop 583 gettext_noop
566 ("# Bytes of bandwidth requested from core"), 584 ("# Bytes of bandwidth requested from core"),
567 ntohs (pending->msg->size), GNUNET_NO); 585 ntohs (pending->msg->size), GNUNET_NO);
586
568 /*FIXME : here I don't know the use of importance, time out 587 /*FIXME : here I don't know the use of importance, time out
569 Will check at run time if its all correct. */ 588 Will check at run time if its all correct. */
570 peer->th = 589 peer->th =
@@ -579,38 +598,30 @@ process_peer_queue (struct FriendInfo *peer)
579 598
580 599
581/** 600/**
582 * This function is similar to get request but used specifically for trail 601 * FIXME: Check the parameters.
583 * construction. I don't know if using GDS_NEIGHBOURS_handle_get is sufficient 602 * Set up the trial message and forwards this message to friend.
584 * or we need this new function. 603 *
585 * @param Finger id to which we want to setup the trail. 604 * @param Finger id to which we want to setup the trail.
586 * @param Friend id through which we will try to setup the trail. 605 * @param Friend id through which we will try to setup the trail.
587 */ 606 */
588void 607void
589GDS_NEIGHBOURS_trail_setup(struct GNUNET_PeerIdentity *finger_id, 608GDS_NEIGHBOURS_trail_setup(struct GNUNET_PeerIdentity *finger_id,
590 struct FriendInfo *target_friend) 609 struct FriendInfo *target_friend)
591{ 610{
592 /* 611 /*
593 1. first construct the trail message which should contain
594 * the source peer id, the finger peer id and randomly chosen one of our
595 * friends peer id. Should there be a new block type?
596 * Construct a message and add it to your peer queue of the friend you have
597 * chosen to send the packet to and then call process_peer_queue.
598 * Just follow GDS_NEIGHBOURS_handle_reply to complete this function.
599 */
600 /*
601 * FIXME: check if pending message actually contains the correct data. 612 * FIXME: check if pending message actually contains the correct data.
602 */ 613 */
603 struct P2PPendingMessage *pending; 614 struct P2PPendingMessage *pending;
604 /* FIXME: why I have defined as **? verify by testing. */ 615 /* FIXME: why I have defined as **? verify by testing. */
605 struct PeerTrailSetupMessage *tsm; 616 struct PeerTrailSetupMessage *tsm;
606 617
607 618
608 if (target_friend->pending_count >= MAXIMUM_PENDING_PER_PEER) 619 if (target_friend->pending_count >= MAXIMUM_PENDING_PER_PEER)
609 { 620 {
610 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), 621 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"),
611 1, GNUNET_NO); 622 1, GNUNET_NO);
612 } 623 }
613 624
614 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage)); 625 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage));
615 tsm = (struct PeerTrailSetupMessage *) &pending[1]; 626 tsm = (struct PeerTrailSetupMessage *) &pending[1];
616 pending->msg = &tsm->header; 627 pending->msg = &tsm->header;
@@ -624,6 +635,7 @@ GDS_NEIGHBOURS_trail_setup(struct GNUNET_PeerIdentity *finger_id,
624 635
625 636
626/**FIXME: Old implementation just to remove error 637/**FIXME: Old implementation just to remove error
638 * TODO: Modify this function to handle our get request.
627 * Perform a GET operation. Forwards the given request to other 639 * Perform a GET operation. Forwards the given request to other
628 * peers. Does not lookup the key locally. May do nothing if this is 640 * peers. Does not lookup the key locally. May do nothing if this is
629 * the only peer in the network (or if we are the closest peer in the 641 * the only peer in the network (or if we are the closest peer in the
@@ -650,10 +662,11 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
650 uint32_t reply_bf_mutator, 662 uint32_t reply_bf_mutator,
651 struct GNUNET_CONTAINER_BloomFilter *peer_bf) 663 struct GNUNET_CONTAINER_BloomFilter *peer_bf)
652{ 664{
653 665
654} 666}
655 667
656/**FIXME: Old implementation just to remove error. 668/**FIXME: Old implementation just to remove error.
669 * TODO: Modify this function to handle our put request.
657 * Perform a PUT operation. Forwards the given request to other 670 * Perform a PUT operation. Forwards the given request to other
658 * peers. Does not store the data locally. Does not give the 671 * peers. Does not store the data locally. Does not give the
659 * data to local clients. May do nothing if this is the only 672 * data to local clients. May do nothing if this is the only
@@ -686,6 +699,37 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
686{ 699{
687 700
688} 701}
702
703
704/**FIXME: Old implementation just to remove error.
705 * Handle a reply (route to origin). Only forwards the reply back to
706 * other peers waiting for it. Does not do local caching or
707 * forwarding to local clients.
708 *
709 * @param target neighbour that should receive the block (if still connected)
710 * @param type type of the block
711 * @param expiration_time when does the content expire
712 * @param key key for the content
713 * @param put_path_length number of entries in put_path
714 * @param put_path peers the original PUT traversed (if tracked)
715 * @param get_path_length number of entries in put_path
716 * @param get_path peers this reply has traversed so far (if tracked)
717 * @param data payload of the reply
718 * @param data_size number of bytes in data
719 */
720void
721GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target,
722 enum GNUNET_BLOCK_Type type,
723 struct GNUNET_TIME_Absolute expiration_time,
724 const struct GNUNET_HashCode * key,
725 unsigned int put_path_length,
726 const struct GNUNET_PeerIdentity *put_path,
727 unsigned int get_path_length,
728 const struct GNUNET_PeerIdentity *get_path,
729 const void *data, size_t data_size)
730{
731
732}
689/** 733/**
690 * Randomly choose one of your friends from the friends_peer map 734 * Randomly choose one of your friends from the friends_peer map
691 * @return Friend 735 * @return Friend
@@ -693,40 +737,53 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
693static struct FriendInfo * 737static struct FriendInfo *
694get_friend() 738get_friend()
695{ 739{
696 740 /*1. get the size of your friend map first.
697 return NULL; 741 2. Then, choose a number randomly from 0 to size-1
742 3. Then create an iterator to extract the peer id from friend map
743 This function should be defined in this file as no other file uses it.*/
744
745 //unsigned int current_size;
746 //unsigned int *index;
747
748 //current_size = GNUNET_CONTAINER_multipeermap_size(friend_peers);
749
750 /* Element stored at this index in friend_peers map should be chosen friend. */
751 //index = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, current_size);
752
753
754 /*TODO: Add a function which will get the element stored at that index in
755 our friend_peers_map.Take care of parameters. */
756
757 return NULL;
698} 758}
699 759
760
700/** 761/**
701 * Use Chord formula finger[i]=(n+2^(i-1))mod m, 762 * Use Chord formula finger[i]=(n+2^(i-1))mod m,
702 * where i = current finger map index. 763 * where i = current finger map index.
703 * n = own peer identity 764 * n = own peer identity
704 * m = number of bits in peer id. 765 * m = number of bits in peer id.
705 * @return finger_peer_id for which we have to find the trail through network. 766 * @return finger_peer_id for which we have to find the trail through network.
706 */ 767 */
707static struct GNUNET_PeerIdentity * 768//static
769struct GNUNET_PeerIdentity *
708finger_id_to_search() 770finger_id_to_search()
709{ 771{
710 /* After finding the finger_id increment the value of 'i' 772
711 so that the next search begins from there. */ 773 //struct GNUNET_PeerIdentity *finger_peer_id;
712 struct GNUNET_PeerIdentity *finger_peer_id; 774
713 775 /*TODO: Add a wrapper in crypto_ecc.c to add an integer do mod operation on integer
714 776 to find peer id. Take care of parameters. You should work on the value of
715 777 finger_id not on its pointer. */
716 /* FIXME: This typecasting is not correct. */ 778
717 //finger_peer_id = ((unsigned int)(my_identity.public_key.q_y)+(2^(finger_id)))%MAX_FINGERS; 779 //return finger_peer_id;
718 780 return NULL;
719 /* Increment the next finger_id we should be searching. */
720 finger_id = (finger_id+1)%MAX_FINGERS;
721
722 return finger_peer_id;
723
724} 781}
725 782
726 783
727/** 784/**
728 * Task to send a find finger trail message. We attempt to find trail 785 * Task to send a find finger trail message. We attempt to find trail
729 * to our fingers in the network. 786 * to our finger in the network.
730 * 787 *
731 * @param cls closure for this task 788 * @param cls closure for this task
732 * @param tc the context under which the task is running 789 * @param tc the context under which the task is running
@@ -735,34 +792,39 @@ static void
735send_find_finger_trail_message (void *cls, 792send_find_finger_trail_message (void *cls,
736 const struct GNUNET_SCHEDULER_TaskContext *tc) 793 const struct GNUNET_SCHEDULER_TaskContext *tc)
737{ 794{
738 /* finger we are searching for */
739 struct GNUNET_PeerIdentity *finger_peer_id; 795 struct GNUNET_PeerIdentity *finger_peer_id;
740 struct FriendInfo *friend_peer_id; 796 struct FriendInfo *friend_peer_id;
741 struct GNUNET_TIME_Relative next_send_time; 797 struct GNUNET_TIME_Relative next_send_time;
742 798
743 /* FIXME: Not sure if this is required. Here I am checking if I have 799 /* FIXME: Not sure if this is required. Here I am checking if I have
744 already found trail for each of the possible finger. If yes then don't look 800 already found trail for each of the possible finger. If yes then don't look
745 anymore in the network. */ 801 anymore in the network. We can at this point may even look for the
802 predecessor in the network. It handles the case where one of the peer
803 gets disconnected -- as we remove the element from finger_peers, and the
804 size will not be MAX_FINGERS.*/
746 if (GNUNET_CONTAINER_multipeermap_size(finger_peers) == MAX_FINGERS) 805 if (GNUNET_CONTAINER_multipeermap_size(finger_peers) == MAX_FINGERS)
747 { 806 {
807 /*FIXME: Should we call find_predecessor_peer here. We need to maintain
808 pointer to predecessor in the network to handle node join/failure case. */
748 return; 809 return;
749 } 810 }
750 811
751 /* Find the finger_peer_id to which we want to setup the trial */ 812 /* Find the finger_peer_id for which we want to setup the trial */
752 finger_peer_id = finger_id_to_search(); 813 finger_peer_id = finger_id_to_search();
753 814
754 /* Choose a friend randomly from your friend_peers map. */ 815 /* Choose a friend randomly from your friend_peers map. */
755 friend_peer_id = get_friend(); 816 friend_peer_id = get_friend();
756 817
818 /*FIXME: Check if we are passing parameters correctly. */
757 GDS_NEIGHBOURS_trail_setup(finger_peer_id, friend_peer_id); 819 GDS_NEIGHBOURS_trail_setup(finger_peer_id, friend_peer_id);
758 820
759 /* FIXME: Is using finger_id to generate random function ok here. */ 821 /* FIXME: Is using finger_id to generate random function ok here. */
760 next_send_time.rel_value_us = 822 next_send_time.rel_value_us =
761 DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value_us + 823 DHT_MINIMUM_FIND_FINGER_TRAIL_INTERVAL.rel_value_us +
762 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 824 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
763 DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value_us / 825 DHT_MAXIMUM_FIND_FINGER_TRAIL_INTERVAL.rel_value_us /
764 (finger_id + 1)); 826 (finger_id + 1));
765 827
766 find_finger_trail_task = 828 find_finger_trail_task =
767 GNUNET_SCHEDULER_add_delayed (next_send_time, &send_find_finger_trail_message, 829 GNUNET_SCHEDULER_add_delayed (next_send_time, &send_find_finger_trail_message,
768 NULL); 830 NULL);
@@ -778,22 +840,17 @@ send_find_finger_trail_message (void *cls,
778static void 840static void
779handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer) 841handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
780{ 842{
781 /*When a peer is connected, then add it to your friend_peers map.
782 Also, start an asynchronous method to look for your fingers that you can
783 reach whenever you get the first connection to the peer. Also try to
784 reach to your predecessor. */
785
786 struct FriendInfo *ret; 843 struct FriendInfo *ret;
787 struct GNUNET_HashCode phash;
788 844
789 /* Check for connect to self message */ 845 /* Check for connect to self message */
790 if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) 846 if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity)))
791 return; 847 return;
792 848
793 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 849 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
794 "Connected to %s\n", 850 "Connected to %s\n",
795 GNUNET_i2s (peer)); 851 GNUNET_i2s (peer));
796 852
853 /* If peer already exists in our friend_peers, then exit. */
797 if (GNUNET_YES == 854 if (GNUNET_YES ==
798 GNUNET_CONTAINER_multipeermap_contains (friend_peers, 855 GNUNET_CONTAINER_multipeermap_contains (friend_peers,
799 peer)) 856 peer))
@@ -801,12 +858,9 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
801 GNUNET_break (0); 858 GNUNET_break (0);
802 return; 859 return;
803 } 860 }
804 861
805 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# peers connected"), 1, 862 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# peers connected"), 1,
806 GNUNET_NO); 863 GNUNET_NO);
807 GNUNET_CRYPTO_hash (peer,
808 sizeof (struct GNUNET_PeerIdentity),
809 &phash);
810 864
811 ret = GNUNET_new (struct FriendInfo); 865 ret = GNUNET_new (struct FriendInfo);
812 ret->id = *peer; 866 ret->id = *peer;
@@ -816,7 +870,7 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
816 peer, ret, 870 peer, ret,
817 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 871 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
818 872
819 /* got a first connection, good time to start with FIND TRAIL TO FINGER requests... */ 873 /* got a first connection, good time to start with FIND FINGER TRAIL requests... */
820 if (1 == GNUNET_CONTAINER_multipeermap_size(friend_peers)) 874 if (1 == GNUNET_CONTAINER_multipeermap_size(friend_peers))
821 find_finger_trail_task = GNUNET_SCHEDULER_add_now (&send_find_finger_trail_message, NULL); 875 find_finger_trail_task = GNUNET_SCHEDULER_add_now (&send_find_finger_trail_message, NULL);
822} 876}
@@ -832,7 +886,13 @@ static void
832handle_core_disconnect (void *cls, 886handle_core_disconnect (void *cls,
833 const struct GNUNET_PeerIdentity *peer) 887 const struct GNUNET_PeerIdentity *peer)
834{ 888{
835 889 /* Here I guess
890 1. if a core disconnect, then mark it disconnected or remove the entry from
891 friend/finger table.
892 2. If entry is removed from finger table then remove trail also.
893 Here is case where we started put operation but a peer got disconnected and
894 we removed the entry from the table.
895 How to handle such a case. */
836} 896}
837 897
838 898
@@ -870,13 +930,14 @@ handle_dht_p2p_put (void *cls,
870{ 930{
871 /** 931 /**
872 1. Search the friend,finger and check your own id to find the closest 932 1. Search the friend,finger and check your own id to find the closest
873 * predecessor the given key. 933 * predecessor the given key. --> find_predecessor()
874 2. If self then datache_store 934 2. If self then datache_store
875 3. If friend, then add to peer queue 935 3. If friend, then add to peer queue
876 4. If finger, then add to the peer queue of the first hop.Again the 936 4. If finger, then add to the peer queue of the first hop.
877 * same doubt,how does a peer when it is in handle_dht_p2p_put makes 937 * in put message also maintain a field current_destination and use
878 * a distinction weather it should do a lookup in routing table or finger or 938 * same logic as trail setup to understand if you are just part of trail
879 * friend table. 939 * to reach to a particular peer or you are endpoint of trail or just a friend.
940 *
880 */ 941 */
881 return 0; 942 return 0;
882} 943}
@@ -917,66 +978,161 @@ handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer,
917 978
918/** 979/**
919 * Read the trail setup message backwards to find which is the next hop to which 980 * Read the trail setup message backwards to find which is the next hop to which
920 * it should be send to. 981 * it should be send to.
921 * @return 982 * @return
922 */ 983
923//static 984static
924struct GNUNET_PeerIdentity * 985struct GNUNET_PeerIdentity *
925find_next_hop() 986find_next_hop()
926{ 987{
927 return NULL; 988 return NULL;
928} 989}*/
929 990
930 991
931/** 992/**
932 * Find the predecessor for given finger_id from the 993 * Find the predecessor for given finger_id from the
933 * friend and finger table. 994 * friend and finger table.
934 * if friend, then just return the friend it 995 * if friend, then just return the friend
935 * if finger, then return the next hop to forward the packet to. 996 * if finger, then return the next hop to forward the packet to and also
936 * @return 997 * set the current_destination field to finger_id.
998 * @param destination peer id's predecessor we are looking for.
999 * @return
937 */ 1000 */
938//static 1001static struct GNUNET_PeerIdentity *
939struct GNUNET_PeerIdentity * 1002find_predecessor(struct GNUNET_PeerIdentity *destination)
940find_predecessor()
941{ 1003{
1004 /*iterate over friend map till you reach a peer id such that
1005 destination <= peer id */
1006
942 return NULL; 1007 return NULL;
943} 1008}
944 1009
945 1010
946/** 1011/**
947 * Core handler for P2P trail setup message. 1012 * Core handler for P2P trail setup message.
1013 * FIXME:
1014 * 1. Check if we are maintaining the 64k size of struct PeerTrailSetupMessage.
1015 * when we add ourself to the trail list.
1016 * 2. Ensure that you set the correct value of current_destination.
1017 * @param cls closure
1018 * @param message message
1019 * @param peer peer identity this notification is about
1020 * @return #GNUNET_YES
948 */ 1021 */
949static int 1022static int
950handle_dht_p2p_trail_setup() 1023handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer,
1024 const struct GNUNET_MessageHeader *message)
951{ 1025{
952 /* 1026 /*SUPU: Why am I defining this message as const? */
953 * When we get this message from our friend then 1027 const struct PeerTrailSetupMessage *trail_setup;
954 * 1. Check the destination finger id that the message is looking for. 1028 struct GNUNET_PeerIdentity *next_hop;
955 * 2. If my_identity = destination, then create a trail_setup_result message 1029
956 * read the path taken to reach to you. read that list backwards to find which 1030 uint16_t msize;
957 * friend to forward this trailsetupresult to. find_next_hop() 1031
958 * call process_peer_queue() to add trailsetupresult message to peer 1032 msize = ntohs (message->size);
959 * 3. If you are not the destination 1033 if (msize < sizeof (struct PeerTrailSetupMessage))
960 * then call find_predecessor() to find closest finger to our given finger_id 1034 {
961 * //GDS_ROUTING_ADD 1035 GNUNET_break_op (0);
962 * //GDS_ROUTING_FIND 1036 return GNUNET_YES;
963 * 1037 }
964 */ 1038
965 return 0; 1039 /*SUPU: So here we have the message that we got from one of our peer into
966 1040 our own trail_setup message.*/
1041 trail_setup = (const struct PeerTrailSetupMessage *) message;
1042
1043 GNUNET_STATISTICS_update (GDS_stats,
1044 gettext_noop ("# TRAIL SETUP requests received"), 1,
1045 GNUNET_NO);
1046 GNUNET_STATISTICS_update (GDS_stats,
1047 gettext_noop ("# TRAIL SETUP bytes received"), msize,
1048 GNUNET_NO);
1049
1050
1051 /*Check the value of current_destination and handle the respective case. */
1052 if(trail_setup->current_destination == NULL)
1053 {
1054 /*if there is no value set up for current destination then
1055 just call find_predecessor() */
1056 next_hop = find_predecessor(trail_setup->destination_finger);
1057 }
1058 else if( 0 == (GNUNET_CRYPTO_cmp_peer_identity(trail_setup->current_destination,&my_identity)))
1059 {
1060 /* If this packet is send to me.
1061 1. call find_predecessor() if it returns your own identity, then
1062 * prepare a trail setup message and send to last element of our trail
1063 * list.
1064 2. if find_predecessor(), returns a friend id then send the packet along
1065 that.
1066 */
1067 next_hop = find_predecessor(trail_setup->destination_finger);
1068 if(0 == (GNUNET_CRYPTO_cmp_peer_identity(next_hop,&my_identity)))
1069 {
1070 /*1. Prepare a trail setup message.
1071 2. Add yourself to trail list.
1072 3. send packet to last element in the list.
1073 */
1074 }
1075 else
1076 {
1077 /* send the message to next_hop.*/
1078 goto forward;
1079 }
1080 }
1081 else
1082 {
1083 /* here is trail_setup is not NULL, but it is not equal to my_identity
1084 so, it means I am part of the trail to reach to current_destination.
1085 so , search in routing table to find which is the next hop to send this
1086 packet to.*/
1087 next_hop = GDS_Routing_search(trail_setup->source_peer, trail_setup->current_destination, trail_setup->tail->peer);
1088 }
1089 /*If you have reached here, it means that we have still not reached our
1090 final destination, so we now
1091 1. add ourself to trail list
1092 2. pass the message to next_hop. */
1093 forward:
1094
1095 return GNUNET_YES;
967} 1096}
968 1097
969 1098
970/** 1099/**
971 * Core handle for p2p trail construction result messages. 1100 * Core handle for p2p trail construction result messages.
972 * 1101 * @param cls closure
973 * @return 1102 * @param message message
1103 * @param peer peer identity this notification is about
1104 * @return #GNUNET_YES (do not cut p2p connection)
1105 * @return
974 */ 1106 */
975static int 1107static int
976handle_dht_p2p_trail_setup_result() 1108handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *peer,
1109 const struct GNUNET_MessageHeader *message)
977{ 1110{
978 /* 1111 /**
979 Here you got a message that trail is set*/ 1112 * Just read the linked list backwards and send the packet to next hop
1113 * till you don't reach the source
1114 * but if you are source, then add an entry in finger table for given finger id.
1115 *
1116 *
1117 */
1118 //const struct PeerTrailSetupResultMessage *trail_result;
1119 //trail_result = (const struct PeerTrailSetupResultMessage *) message;
1120
1121 /*FIXME: This code is wrong, I am writing just to understand the flow,
1122 if(trail_result->destination == message->destination)
1123 {
1124 This condition holds true, then we should add an entry in our
1125 routing table and store this finger and its trail.
1126 struct finger_info = with interval .
1127 GNUNET_multipeer_map_insert(finger_map)
1128 * GDS_Routing_add();
1129 }
1130 else
1131 {
1132 Read the trail list, Check the next_hop and pass the packet to it.
1133 FIXME: Should we an entry in our own routing table.
1134 }*/
1135
980 return 0; 1136 return 0;
981} 1137}
982 1138
@@ -1007,8 +1163,8 @@ GDS_NEIGHBOURS_init()
1007 1163
1008 friend_peers = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_NO); 1164 friend_peers = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_NO);
1009 finger_peers = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_NO); 1165 finger_peers = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_NO);
1010 1166
1011 1167
1012 return GNUNET_OK; 1168 return GNUNET_OK;
1013 1169
1014} 1170}
@@ -1034,7 +1190,7 @@ GDS_NEIGHBOURS_done ()
1034 GNUNET_assert (0 == GNUNET_CONTAINER_multipeermap_size (finger_peers)); 1190 GNUNET_assert (0 == GNUNET_CONTAINER_multipeermap_size (finger_peers));
1035 GNUNET_CONTAINER_multipeermap_destroy (finger_peers); 1191 GNUNET_CONTAINER_multipeermap_destroy (finger_peers);
1036 finger_peers = NULL; 1192 finger_peers = NULL;
1037 1193
1038 if (GNUNET_SCHEDULER_NO_TASK != find_finger_trail_task) 1194 if (GNUNET_SCHEDULER_NO_TASK != find_finger_trail_task)
1039 { 1195 {
1040 GNUNET_SCHEDULER_cancel (find_finger_trail_task); 1196 GNUNET_SCHEDULER_cancel (find_finger_trail_task);
diff --git a/src/dht/gnunet-service-xdht_neighbours.h b/src/dht/gnunet-service-xdht_neighbours.h
index 615db9198..50d39ac99 100644
--- a/src/dht/gnunet-service-xdht_neighbours.h
+++ b/src/dht/gnunet-service-xdht_neighbours.h
@@ -32,6 +32,94 @@
32#include "gnunet_dht_service.h" 32#include "gnunet_dht_service.h"
33 33
34/** 34/**
35 * Perform a PUT operation. Forwards the given request to other
36 * peers. Does not store the data locally. Does not give the
37 * data to local clients. May do nothing if this is the only
38 * peer in the network (or if we are the closest peer in the
39 * network).
40 *
41 * @param type type of the block
42 * @param options routing options
43 * @param desired_replication_level desired replication level
44 * @param expiration_time when does the content expire
45 * @param hop_count how many hops has this message traversed so far
46 * @param bf Bloom filter of peers this PUT has already traversed
47 * @param key key for the content
48 * @param put_path_length number of entries in put_path
49 * @param put_path peers this request has traversed so far (if tracked)
50 * @param data payload to store
51 * @param data_size number of bytes in data
52 */
53void
54GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
55 enum GNUNET_DHT_RouteOption options,
56 uint32_t desired_replication_level,
57 struct GNUNET_TIME_Absolute expiration_time,
58 uint32_t hop_count,
59 struct GNUNET_CONTAINER_BloomFilter *bf,
60 const struct GNUNET_HashCode * key,
61 unsigned int put_path_length,
62 struct GNUNET_PeerIdentity *put_path,
63 const void *data, size_t data_size);
64
65
66/**
67 * Perform a GET operation. Forwards the given request to other
68 * peers. Does not lookup the key locally. May do nothing if this is
69 * the only peer in the network (or if we are the closest peer in the
70 * network).
71 *
72 * @param type type of the block
73 * @param options routing options
74 * @param desired_replication_level desired replication count
75 * @param hop_count how many hops did this request traverse so far?
76 * @param key key for the content
77 * @param xquery extended query
78 * @param xquery_size number of bytes in xquery
79 * @param reply_bf bloomfilter to filter duplicates
80 * @param reply_bf_mutator mutator for reply_bf
81 * @param peer_bf filter for peers not to select (again, updated)
82 */
83void
84GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
85 enum GNUNET_DHT_RouteOption options,
86 uint32_t desired_replication_level,
87 uint32_t hop_count, const struct GNUNET_HashCode * key,
88 const void *xquery, size_t xquery_size,
89 const struct GNUNET_CONTAINER_BloomFilter *reply_bf,
90 uint32_t reply_bf_mutator,
91 struct GNUNET_CONTAINER_BloomFilter *peer_bf);
92
93
94/**
95 * Handle a reply (route to origin). Only forwards the reply back to
96 * other peers waiting for it. Does not do local caching or
97 * forwarding to local clients.
98 *
99 * @param target neighbour that should receive the block (if still connected)
100 * @param type type of the block
101 * @param expiration_time when does the content expire
102 * @param key key for the content
103 * @param put_path_length number of entries in put_path
104 * @param put_path peers the original PUT traversed (if tracked)
105 * @param get_path_length number of entries in put_path
106 * @param get_path peers this reply has traversed so far (if tracked)
107 * @param data payload of the reply
108 * @param data_size number of bytes in data
109 */
110void
111GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target,
112 enum GNUNET_BLOCK_Type type,
113 struct GNUNET_TIME_Absolute expiration_time,
114 const struct GNUNET_HashCode * key,
115 unsigned int put_path_length,
116 const struct GNUNET_PeerIdentity *put_path,
117 unsigned int get_path_length,
118 const struct GNUNET_PeerIdentity *get_path,
119 const void *data, size_t data_size);
120
121
122/**
35 * Initialize neighbours subsystem. 123 * Initialize neighbours subsystem.
36 * 124 *
37 * @return GNUNET_OK on success, GNUNET_SYSERR on error 125 * @return GNUNET_OK on success, GNUNET_SYSERR on error
diff --git a/src/dht/gnunet-service-xdht_routing.c b/src/dht/gnunet-service-xdht_routing.c
index 66ab88eb4..469cd004a 100644
--- a/src/dht/gnunet-service-xdht_routing.c
+++ b/src/dht/gnunet-service-xdht_routing.c
@@ -75,15 +75,16 @@ static struct GNUNET_CONTAINER_MultiPeerMap *routing_table;
75 * Find the next hop to pass the message to . 75 * Find the next hop to pass the message to .
76 * @return 76 * @return
77 */ 77 */
78//static struct GNUNET_PeerIdentity * 78//static
79//find_next_hop() 79struct GNUNET_PeerIdentity *
80//{ 80find_next_hop()
81 81{
82//} 82 return NULL;
83}
83 84
84 85
85 86
86/** 87/**FIXME: Old function added just to remove error for time being.
87 * Add a new entry to our routing table. 88 * Add a new entry to our routing table.
88 * 89 *
89 * @param sender peer that originated the request 90 * @param sender peer that originated the request
@@ -107,11 +108,24 @@ GDS_ROUTING_add (const struct GNUNET_PeerIdentity *sender,
107 108
108} 109}
109 110
110/* search in routing table for next hop to pass the message to . 111
111 * struct GNUNET_PeerIdentity * 112/**
112GDS_Routing_search() 113 * Search the next hop to send the packet to in routing table.
114 * @return next hop peer id
115 */
116struct GNUNET_PeerIdentity *
117GDS_Routing_search(struct GNUNET_PeerIdentity *source_peer,
118 struct GNUNET_PeerIdentity *destination_peer,
119 struct GNUNET_PeerIdentity *prev_hop)
113{ 120{
114}*/ 121 //struct GNUNET_PeerIdentity *next_hop;
122
123 /* We have got all the fields and now we should search the
124 routing table by destination_peer and we should return the next_hop
125 I don't see any function at the moment in container_multipeer_map. */
126 return NULL;
127}
128
115 129
116/**FIXME: Old implementation just to remove error 130/**FIXME: Old implementation just to remove error
117 * Handle a reply (route to origin). Only forwards the reply back to 131 * Handle a reply (route to origin). Only forwards the reply back to
diff --git a/src/dht/gnunet-service-xdht_routing.h b/src/dht/gnunet-service-xdht_routing.h
index a6c3281e9..d1ca53512 100644
--- a/src/dht/gnunet-service-xdht_routing.h
+++ b/src/dht/gnunet-service-xdht_routing.h
@@ -53,6 +53,40 @@ GDS_ROUTING_add (const struct GNUNET_PeerIdentity *sender,
53 uint32_t reply_bf_mutator); 53 uint32_t reply_bf_mutator);
54 54
55 55
56/**
57 * Search the next hop to send the packet to in routing table.
58 * @return next hop peer id
59 */
60struct GNUNET_PeerIdentity *
61GDS_Routing_search(struct GNUNET_PeerIdentity *source_peer,
62 struct GNUNET_PeerIdentity *destination_peer,
63 struct GNUNET_PeerIdentity *prev_hop);
64
65/**
66 * Handle a reply (route to origin). Only forwards the reply back to
67 * other peers waiting for it. Does not do local caching or
68 * forwarding to local clients. Essentially calls
69 * GDS_NEIGHBOURS_handle_reply for all peers that sent us a matching
70 * request recently.
71 *
72 * @param type type of the block
73 * @param expiration_time when does the content expire
74 * @param key key for the content
75 * @param put_path_length number of entries in @a put_path
76 * @param put_path peers the original PUT traversed (if tracked)
77 * @param get_path_length number of entries in @a get_path
78 * @param get_path peers this reply has traversed so far (if tracked)
79 * @param data payload of the reply
80 * @param data_size number of bytes in @a data
81 */
82void
83GDS_ROUTING_process (enum GNUNET_BLOCK_Type type,
84 struct GNUNET_TIME_Absolute expiration_time,
85 const struct GNUNET_HashCode * key, unsigned int put_path_length,
86 const struct GNUNET_PeerIdentity *put_path,
87 unsigned int get_path_length,
88 const struct GNUNET_PeerIdentity *get_path,
89 const void *data, size_t data_size);
56 90
57/** 91/**
58 * Initialize routing subsystem. 92 * Initialize routing subsystem.