diff options
author | Supriti Singh <supritisingh08@gmail.com> | 2014-01-28 16:49:31 +0000 |
---|---|---|
committer | Supriti Singh <supritisingh08@gmail.com> | 2014-01-28 16:49:31 +0000 |
commit | 6f2f81102aec50dab3b84ee4ef9fdb930e15e08e (patch) | |
tree | 0a6533fb01faae68c57d35d2e31c2b9cd9ce6f29 /src/dht | |
parent | 4eecf60dd155280bc5c3f83dea117b32a87ad34b (diff) | |
download | gnunet-6f2f81102aec50dab3b84ee4ef9fdb930e15e08e.tar.gz gnunet-6f2f81102aec50dab3b84ee4ef9fdb930e15e08e.zip |
Implemented logic to randomly choose a friend.
Modified struct TrailPeerList
Diffstat (limited to 'src/dht')
-rw-r--r-- | src/dht/gnunet-service-xdht_neighbours.c | 432 | ||||
-rw-r--r-- | src/dht/gnunet-service-xdht_routing.c | 72 |
2 files changed, 303 insertions, 201 deletions
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c index 568dbae2f..ac21c67b0 100644 --- a/src/dht/gnunet-service-xdht_neighbours.c +++ b/src/dht/gnunet-service-xdht_neighbours.c | |||
@@ -52,9 +52,10 @@ | |||
52 | /*TODO | 52 | /*TODO |
53 | 1. Add logic to get connected to your predecessor | 53 | 1. Add logic to get connected to your predecessor |
54 | because when nodes join/fail , you need to maintain correct | 54 | because when nodes join/fail , you need to maintain correct |
55 | pointers to predecessor and your successor i.e.your first finger, | 55 | pointers to predecessor and your successor (your first finger), |
56 | to update tables. | 56 | to update tables. |
57 | 2. Remove extra comments. */ | 57 | 2. Remove extra comments - FIXME,TODO,SUPU |
58 | 3. When do we call GDS_Routing_add()? */ | ||
58 | 59 | ||
59 | /** | 60 | /** |
60 | * Maximum possible fingers of a peer. | 61 | * Maximum possible fingers of a peer. |
@@ -62,9 +63,9 @@ | |||
62 | #define MAX_FINGERS 256 | 63 | #define MAX_FINGERS 256 |
63 | 64 | ||
64 | /** | 65 | /** |
65 | * Maximum allowed number of pending messages per peer. | 66 | * Maximum allowed number of pending messages per friend peer. |
66 | */ | 67 | */ |
67 | #define MAXIMUM_PENDING_PER_PEER 64 | 68 | #define MAXIMUM_PENDING_PER_FRIEND 64 |
68 | 69 | ||
69 | /** | 70 | /** |
70 | * How long at least to wait before sending another find finger trail request. | 71 | * How long at least to wait before sending another find finger trail request. |
@@ -240,6 +241,33 @@ struct PeerGetMessage | |||
240 | 241 | ||
241 | 242 | ||
242 | /** | 243 | /** |
244 | * FIXME: I have defined this struct between GNUNET_NETWORK_STRUCT_BEGIN. Is | ||
245 | * it correct? Also, I am using the same struct inside finger info and trailsetup | ||
246 | * trailsetupresult message. Is it correct? */ | ||
247 | /** | ||
248 | * Linked List of peers which are part of trail to reach a particular Finger. | ||
249 | */ | ||
250 | struct TrailPeerList | ||
251 | { | ||
252 | /** | ||
253 | * Pointer to next item in the list | ||
254 | */ | ||
255 | struct TrailPeerList *next; | ||
256 | |||
257 | /** | ||
258 | * Pointer to previous item in the list | ||
259 | */ | ||
260 | struct TrailPeerList *prev; | ||
261 | |||
262 | /** | ||
263 | * An element in this trail list | ||
264 | */ | ||
265 | struct GNUNET_PeerIdentity *peer; | ||
266 | |||
267 | }; | ||
268 | |||
269 | |||
270 | /** | ||
243 | * FIXME : I am using the same structure trail list in both finger info | 271 | * FIXME : I am using the same structure trail list in both finger info |
244 | * and peertrailsetupmessage. Verify if its okay. | 272 | * and peertrailsetupmessage. Verify if its okay. |
245 | * P2P Trail setup message | 273 | * P2P Trail setup message |
@@ -269,12 +297,12 @@ struct PeerTrailSetupMessage | |||
269 | /** | 297 | /** |
270 | * Head of trail list. | 298 | * Head of trail list. |
271 | */ | 299 | */ |
272 | struct TrailList *head; | 300 | struct TrailPeerList *head; |
273 | 301 | ||
274 | /** | 302 | /** |
275 | * Tail of trail list. | 303 | * Tail of trail list. |
276 | */ | 304 | */ |
277 | struct TrailList *tail; | 305 | struct TrailPeerList *tail; |
278 | 306 | ||
279 | }; | 307 | }; |
280 | 308 | ||
@@ -293,7 +321,7 @@ struct PeerTrailSetupResultMessage | |||
293 | */ | 321 | */ |
294 | struct GNUNET_MessageHeader header; | 322 | struct GNUNET_MessageHeader header; |
295 | 323 | ||
296 | /* It should contain the list of peers which form the trail. | 324 | /* SUPU: 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 | 325 | 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 | 326 | 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. */ | 327 | at the end source peer will store this list in its finger table. */ |
@@ -316,12 +344,13 @@ struct PeerTrailSetupResultMessage | |||
316 | /** | 344 | /** |
317 | * Head of trail list. | 345 | * Head of trail list. |
318 | */ | 346 | */ |
319 | struct TrailList *head; | 347 | struct TrailPeerList *head; |
320 | 348 | ||
321 | /** | 349 | /** |
322 | * Tail of trail list. | 350 | * Tail of trail list. |
323 | */ | 351 | */ |
324 | struct TrailList *tail; | 352 | struct TrailPeerList *tail; |
353 | |||
325 | }; | 354 | }; |
326 | 355 | ||
327 | GNUNET_NETWORK_STRUCT_END | 356 | GNUNET_NETWORK_STRUCT_END |
@@ -362,34 +391,12 @@ struct P2PPendingMessage | |||
362 | }; | 391 | }; |
363 | 392 | ||
364 | /** | 393 | /** |
365 | * Linked List of peers which are part of trail to reach a particular Finger. | ||
366 | */ | ||
367 | struct 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 | }; | ||
385 | |||
386 | /** | ||
387 | * Entry in friend_peers map. | 394 | * Entry in friend_peers map. |
388 | */ | 395 | */ |
389 | struct FriendInfo | 396 | struct FriendInfo |
390 | { | 397 | { |
391 | 398 | ||
392 | /** | 399 | /** |
393 | * What is the identity of the peer? | 400 | * What is the identity of the peer? |
394 | */ | 401 | */ |
395 | struct GNUNET_PeerIdentity id; | 402 | struct GNUNET_PeerIdentity id; |
@@ -441,12 +448,12 @@ struct FingerInfo | |||
441 | /** | 448 | /** |
442 | * Head of trail list. | 449 | * Head of trail list. |
443 | */ | 450 | */ |
444 | struct TrailList *head; | 451 | struct TrailPeerList *head; |
445 | 452 | ||
446 | /** | 453 | /** |
447 | * Tail of trail list. | 454 | * Tail of trail list. |
448 | */ | 455 | */ |
449 | struct TrailList *tail; | 456 | struct TrailPeerList *tail; |
450 | 457 | ||
451 | }; | 458 | }; |
452 | 459 | ||
@@ -487,6 +494,7 @@ static struct GNUNET_ATS_PerformanceHandle *atsAPI; | |||
487 | static struct GNUNET_CORE_Handle *core_api; | 494 | static struct GNUNET_CORE_Handle *core_api; |
488 | 495 | ||
489 | /** | 496 | /** |
497 | * FIXME:where are we using this field. | ||
490 | * The highest finger_id that we have found trail to. | 498 | * The highest finger_id that we have found trail to. |
491 | */ | 499 | */ |
492 | static unsigned int finger_id; | 500 | static unsigned int finger_id; |
@@ -565,12 +573,12 @@ core_transmit_notify (void *cls, size_t size, void *buf) | |||
565 | 573 | ||
566 | 574 | ||
567 | /** | 575 | /** |
568 | * Transmit all messages in the peer's message queue. | 576 | * Transmit all messages in the friend's message queue. |
569 | * | 577 | * |
570 | * @param peer message queue to process | 578 | * @param peer message queue to process |
571 | */ | 579 | */ |
572 | static void | 580 | static void |
573 | process_peer_queue (struct FriendInfo *peer) | 581 | process_friend_queue (struct FriendInfo *peer) |
574 | { | 582 | { |
575 | 583 | ||
576 | struct P2PPendingMessage *pending; | 584 | struct P2PPendingMessage *pending; |
@@ -608,29 +616,29 @@ void | |||
608 | GDS_NEIGHBOURS_trail_setup(struct GNUNET_PeerIdentity *finger_id, | 616 | GDS_NEIGHBOURS_trail_setup(struct GNUNET_PeerIdentity *finger_id, |
609 | struct FriendInfo *target_friend) | 617 | struct FriendInfo *target_friend) |
610 | { | 618 | { |
611 | /* | 619 | /* |
612 | * FIXME: check if pending message actually contains the correct data. | 620 | * FIXME: check if pending message actually contains the correct data. |
613 | */ | 621 | */ |
614 | struct P2PPendingMessage *pending; | 622 | struct P2PPendingMessage *pending; |
615 | /* FIXME: why I have defined as **? verify by testing. */ | 623 | /* FIXME: why I have defined as **? verify by testing. */ |
616 | struct PeerTrailSetupMessage *tsm; | 624 | struct PeerTrailSetupMessage *tsm; |
617 | 625 | ||
618 | 626 | ||
619 | if (target_friend->pending_count >= MAXIMUM_PENDING_PER_PEER) | 627 | if (target_friend->pending_count >= MAXIMUM_PENDING_PER_FRIEND) |
620 | { | 628 | { |
621 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), | 629 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), |
622 | 1, GNUNET_NO); | 630 | 1, GNUNET_NO); |
623 | } | 631 | } |
624 | 632 | ||
625 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage)); | 633 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage)); |
626 | tsm = (struct PeerTrailSetupMessage *) &pending[1]; | 634 | tsm = (struct PeerTrailSetupMessage *) &pending[1]; |
627 | pending->msg = &tsm->header; | 635 | pending->msg = &tsm->header; |
628 | tsm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP); | 636 | tsm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP); |
629 | tsm->destination_finger = finger_id; | 637 | tsm->destination_finger = finger_id; |
630 | tsm->source_peer = &my_identity; | 638 | tsm->source_peer = &my_identity; |
631 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); | 639 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); |
632 | target_friend->pending_count++; | 640 | target_friend->pending_count++; |
633 | process_peer_queue(target_friend); | 641 | process_friend_queue(target_friend); |
634 | } | 642 | } |
635 | 643 | ||
636 | 644 | ||
@@ -730,42 +738,65 @@ GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target, | |||
730 | { | 738 | { |
731 | 739 | ||
732 | } | 740 | } |
741 | |||
742 | |||
733 | /** | 743 | /** |
744 | * SUPU: Check again. | ||
745 | * I have written a code where | ||
746 | * 1. I choose a random index from 0 to current size of my map. | ||
747 | * 2. Create an iterator. | ||
748 | * 3. set the iterator value to the current index id. | ||
749 | * 4. get the element stored at that index id. | ||
750 | * 5. return the index to calling function. | ||
751 | * I have not yet tested this function and I am not sure if its correct. | ||
734 | * Randomly choose one of your friends from the friends_peer map | 752 | * Randomly choose one of your friends from the friends_peer map |
735 | * @return Friend | 753 | * @return Friend |
736 | */ | 754 | */ |
737 | static struct FriendInfo * | 755 | static struct FriendInfo * |
738 | get_friend() | 756 | get_random_friend() |
739 | { | 757 | { |
740 | /*1. get the size of your friend map first. | 758 | unsigned int current_size; |
741 | 2. Then, choose a number randomly from 0 to size-1 | 759 | unsigned int *index; |
742 | 3. Then create an iterator to extract the peer id from friend map | 760 | unsigned int j = 0; |
743 | This function should be defined in this file as no other file uses it.*/ | 761 | struct GNUNET_CONTAINER_MultiPeerMapIterator *iter; |
744 | 762 | struct GNUNET_PeerIdentity key_ret; | |
745 | //unsigned int current_size; | 763 | struct FriendInfo *friend; |
746 | //unsigned int *index; | ||
747 | 764 | ||
748 | //current_size = GNUNET_CONTAINER_multipeermap_size(friend_peers); | 765 | current_size = GNUNET_CONTAINER_multipeermap_size(friend_peers); |
749 | 766 | ||
750 | /* Element stored at this index in friend_peers map should be chosen friend. */ | 767 | /* 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); | 768 | index = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, current_size); |
752 | 769 | ||
770 | /* Create an iterator for friend_peers map. */ | ||
771 | iter = GNUNET_CONTAINER_multipeermap_iterator_create(friend_peers); | ||
753 | 772 | ||
754 | /*TODO: Add a function which will get the element stored at that index in | 773 | /* Set the position of iterator to index. */ |
755 | our friend_peers_map.Take care of parameters. */ | 774 | while(j < (*index)) |
756 | 775 | { | |
776 | if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next(iter,NULL,NULL)) | ||
777 | j++; | ||
778 | else | ||
779 | return NULL; | ||
780 | } | ||
781 | |||
782 | if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next(iter,&key_ret,(const void **)&friend)) | ||
783 | { | ||
784 | return friend; | ||
785 | } | ||
786 | |||
757 | return NULL; | 787 | return NULL; |
758 | } | 788 | } |
759 | 789 | ||
760 | 790 | ||
761 | /** | 791 | /** |
792 | * TODO: Complete this function. | ||
762 | * Use Chord formula finger[i]=(n+2^(i-1))mod m, | 793 | * Use Chord formula finger[i]=(n+2^(i-1))mod m, |
763 | * where i = current finger map index. | 794 | * where i = current finger map index. |
764 | * n = own peer identity | 795 | * n = own peer identity |
765 | * m = number of bits in peer id. | 796 | * m = number of bits in peer id. |
766 | * @return finger_peer_id for which we have to find the trail through network. | 797 | * @return finger_peer_id for which we have to find the trail through network. |
767 | */ | 798 | */ |
768 | //static | 799 | static |
769 | struct GNUNET_PeerIdentity * | 800 | struct GNUNET_PeerIdentity * |
770 | finger_id_to_search() | 801 | finger_id_to_search() |
771 | { | 802 | { |
@@ -774,9 +805,29 @@ finger_id_to_search() | |||
774 | 805 | ||
775 | /*TODO: Add a wrapper in crypto_ecc.c to add an integer do mod operation on integer | 806 | /*TODO: Add a wrapper in crypto_ecc.c to add an integer do mod operation on integer |
776 | to find peer id. Take care of parameters. You should work on the value of | 807 | to find peer id. Take care of parameters. You should work on the value of |
777 | finger_id not on its pointer. */ | 808 | finger_id not on its pointer. |
809 | Increment the value of finger_id. */ | ||
778 | 810 | ||
779 | //return finger_peer_id; | 811 | //return finger_peer_id; |
812 | return NULL; | ||
813 | } | ||
814 | |||
815 | |||
816 | /** | ||
817 | * FIXME: Implement after testing friend/finger map. | ||
818 | * This function will be needed when we are handling node joins/fails | ||
819 | * to maintain correct pointer to our predecessor and successor in the network. | ||
820 | * Find immediate predecessor in the network. | ||
821 | * @param me my own identity | ||
822 | * @return peer identity of immediate predecessor. | ||
823 | */ | ||
824 | static | ||
825 | struct GNUNET_PeerIdentity* | ||
826 | find_immediate_predecessor() | ||
827 | { | ||
828 | /* Using your own peer identity, calculate your predecessor | ||
829 | in the network. Try to setup path to this predecessor using | ||
830 | the same logic as used for other fingers. */ | ||
780 | return NULL; | 831 | return NULL; |
781 | } | 832 | } |
782 | 833 | ||
@@ -796,29 +847,26 @@ send_find_finger_trail_message (void *cls, | |||
796 | struct FriendInfo *friend_peer_id; | 847 | struct FriendInfo *friend_peer_id; |
797 | struct GNUNET_TIME_Relative next_send_time; | 848 | struct GNUNET_TIME_Relative next_send_time; |
798 | 849 | ||
799 | /* FIXME: Not sure if this is required. Here I am checking if I have | 850 | /* We already have found trail to each of our possible fingers in the network. */ |
800 | already found trail for each of the possible finger. If yes then don't look | ||
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.*/ | ||
805 | if (GNUNET_CONTAINER_multipeermap_size(finger_peers) == MAX_FINGERS) | 851 | if (GNUNET_CONTAINER_multipeermap_size(finger_peers) == MAX_FINGERS) |
806 | { | 852 | { |
807 | /*FIXME: Should we call find_predecessor_peer here. We need to maintain | 853 | /* We can find trail to our immediate predecessor in the network. */ |
808 | pointer to predecessor in the network to handle node join/failure case. */ | 854 | finger_peer_id = find_immediate_predecessor(); |
809 | return; | ||
810 | } | 855 | } |
811 | 856 | else | |
812 | /* Find the finger_peer_id for which we want to setup the trial */ | 857 | { |
813 | finger_peer_id = finger_id_to_search(); | 858 | /* Find the finger_peer_id for which we want to setup the trial */ |
814 | 859 | finger_peer_id = finger_id_to_search(); | |
860 | } | ||
861 | |||
815 | /* Choose a friend randomly from your friend_peers map. */ | 862 | /* Choose a friend randomly from your friend_peers map. */ |
816 | friend_peer_id = get_friend(); | 863 | friend_peer_id = get_random_friend(); |
817 | 864 | ||
818 | /*FIXME: Check if we are passing parameters correctly. */ | 865 | /* Check if we found a friend or not. */ |
819 | GDS_NEIGHBOURS_trail_setup(finger_peer_id, friend_peer_id); | 866 | if(NULL != friend_peer_id) |
820 | 867 | GDS_NEIGHBOURS_trail_setup(finger_peer_id, friend_peer_id); | |
821 | /* FIXME: Is using finger_id to generate random function ok here. */ | 868 | |
869 | |||
822 | next_send_time.rel_value_us = | 870 | next_send_time.rel_value_us = |
823 | DHT_MINIMUM_FIND_FINGER_TRAIL_INTERVAL.rel_value_us + | 871 | DHT_MINIMUM_FIND_FINGER_TRAIL_INTERVAL.rel_value_us + |
824 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 872 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
@@ -877,6 +925,7 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
877 | 925 | ||
878 | 926 | ||
879 | /** | 927 | /** |
928 | * FIXME: Implement after testing finger/friend table setup. | ||
880 | * Method called whenever a peer disconnects. | 929 | * Method called whenever a peer disconnects. |
881 | * | 930 | * |
882 | * @param cls closure | 931 | * @param cls closure |
@@ -886,13 +935,18 @@ static void | |||
886 | handle_core_disconnect (void *cls, | 935 | handle_core_disconnect (void *cls, |
887 | const struct GNUNET_PeerIdentity *peer) | 936 | const struct GNUNET_PeerIdentity *peer) |
888 | { | 937 | { |
889 | /* Here I guess | 938 | /** |
890 | 1. if a core disconnect, then mark it disconnected or remove the entry from | 939 | * 1. remove the friend from the friend map. |
891 | friend/finger table. | 940 | * 2. remove the trail for the fingers for which this peer was the first hop. |
892 | 2. If entry is removed from finger table then remove trail also. | 941 | * 3. start send_find_finger_trail for these fingers to find a new trail |
893 | Here is case where we started put operation but a peer got disconnected and | 942 | * in the network. |
894 | we removed the entry from the table. | 943 | * 4. Also when a node gets disconnected, how should we update pointers of its |
895 | How to handle such a case. */ | 944 | * immediate successor and predecessor in the network ? |
945 | * 5. Also how do we distribute the keys in the network? | ||
946 | * 6. Here is case where we started put operation but a peer got disconnected and | ||
947 | we removed the entry from the table. How to handle such a case. | ||
948 | */ | ||
949 | |||
896 | } | 950 | } |
897 | 951 | ||
898 | 952 | ||
@@ -990,6 +1044,13 @@ find_next_hop() | |||
990 | 1044 | ||
991 | 1045 | ||
992 | /** | 1046 | /** |
1047 | * FIXME: | ||
1048 | * Are we comparing the predecessor with our own identity also. | ||
1049 | * Its important. | ||
1050 | * Here also we would be comparing the numeric value of | ||
1051 | * peer identity. We read the element from our map. Extract | ||
1052 | * the peer id and compare it with destination id. But again | ||
1053 | * this comparison is on values. Same issue again. | ||
993 | * Find the predecessor for given finger_id from the | 1054 | * Find the predecessor for given finger_id from the |
994 | * friend and finger table. | 1055 | * friend and finger table. |
995 | * if friend, then just return the friend | 1056 | * if friend, then just return the friend |
@@ -999,21 +1060,64 @@ find_next_hop() | |||
999 | * @return | 1060 | * @return |
1000 | */ | 1061 | */ |
1001 | static struct GNUNET_PeerIdentity * | 1062 | static struct GNUNET_PeerIdentity * |
1002 | find_predecessor(struct GNUNET_PeerIdentity *destination) | 1063 | find_successor(struct GNUNET_PeerIdentity *destination) |
1003 | { | 1064 | { |
1004 | /*iterate over friend map till you reach a peer id such that | 1065 | unsigned int friend_index; |
1005 | destination <= peer id */ | 1066 | unsigned int finger_index; |
1067 | struct GNUNET_CONTAINER_MultiPeerMapIterator *friend_iter; | ||
1068 | struct GNUNET_CONTAINER_MultiPeerMapIterator *finger_iter; | ||
1069 | struct GNUNET_PeerIdentity key_ret; | ||
1070 | struct FriendInfo *friend; | ||
1071 | struct FingerInfo *finger; | ||
1072 | |||
1073 | /* Should I keep a variable to remember if GNUNET_PeerIdentity is | ||
1074 | friend or finger. */ | ||
1075 | friend_iter = GNUNET_CONTAINER_multipeermap_iterator_create (friend_peers); | ||
1076 | |||
1077 | /*iterate over friend map till you reach a peer id such that destination <= peer id */ | ||
1078 | for (friend_index = 0; friend_index < GNUNET_CONTAINER_multipeermap_size (friend_peers); friend_index++) | ||
1079 | { | ||
1080 | if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next(friend_iter,&key_ret,(const void **)&friend)) | ||
1081 | { | ||
1082 | /* | ||
1083 | * 1. Check if friend >= destination. | ||
1084 | * 2. If yes then check if friend <= current_predecessor, | ||
1085 | * if yes then curret_predecessor = friend. | ||
1086 | * 3 If not then do nothing. | ||
1087 | */ | ||
1088 | } | ||
1089 | } | ||
1090 | |||
1091 | |||
1092 | finger_iter = GNUNET_CONTAINER_multipeermap_iterator_create (finger_peers); | ||
1093 | /*iterate over finger map till you reach a peer id such that destination <= peer id */ | ||
1094 | for (finger_index = 0; finger_index < GNUNET_CONTAINER_multipeermap_size (friend_peers); finger_index++) | ||
1095 | { | ||
1096 | if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next(finger_iter,&key_ret,(const void **)&finger)) | ||
1097 | { | ||
1098 | /* | ||
1099 | * 1. Check if finger >= destination. | ||
1100 | * 2. If yes then check if finger <= current_predecessor, | ||
1101 | * if yes then curret_predecessor = finger. | ||
1102 | * 3 If not then do nothing. | ||
1103 | */ | ||
1104 | } | ||
1105 | } | ||
1106 | |||
1006 | 1107 | ||
1007 | return NULL; | 1108 | /* Check between friend and finger value to decide which is the predecessor. |
1109 | If friend, then send the friend id. | ||
1110 | If finger, then send the next hop. */ | ||
1111 | return NULL; | ||
1008 | } | 1112 | } |
1009 | 1113 | ||
1010 | 1114 | ||
1011 | /** | 1115 | /** |
1012 | * Core handler for P2P trail setup message. | ||
1013 | * FIXME: | 1116 | * FIXME: |
1014 | * 1. Check if we are maintaining the 64k size of struct PeerTrailSetupMessage. | 1117 | * 1. Check if we are maintaining the 64k size of struct PeerTrailSetupMessage. |
1015 | * when we add ourself to the trail list. | 1118 | * when we add ourself to the trail list. |
1016 | * 2. Ensure that you set the correct value of current_destination. | 1119 | * 2. Ensure every case is handled for current_destination. |
1120 | * Core handler for P2P trail setup message. | ||
1017 | * @param cls closure | 1121 | * @param cls closure |
1018 | * @param message message | 1122 | * @param message message |
1019 | * @param peer peer identity this notification is about | 1123 | * @param peer peer identity this notification is about |
@@ -1023,9 +1127,11 @@ static int | |||
1023 | handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer, | 1127 | handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer, |
1024 | const struct GNUNET_MessageHeader *message) | 1128 | const struct GNUNET_MessageHeader *message) |
1025 | { | 1129 | { |
1026 | /*SUPU: Why am I defining this message as const? */ | ||
1027 | const struct PeerTrailSetupMessage *trail_setup; | 1130 | const struct PeerTrailSetupMessage *trail_setup; |
1028 | struct GNUNET_PeerIdentity *next_hop; | 1131 | struct GNUNET_PeerIdentity *next_hop; |
1132 | struct FriendInfo *friend; | ||
1133 | struct TrailPeerList *peer_entry; | ||
1134 | struct P2PPendingMessage *pending; | ||
1029 | 1135 | ||
1030 | uint16_t msize; | 1136 | uint16_t msize; |
1031 | 1137 | ||
@@ -1036,8 +1142,6 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1036 | return GNUNET_YES; | 1142 | return GNUNET_YES; |
1037 | } | 1143 | } |
1038 | 1144 | ||
1039 | /*SUPU: So here we have the message that we got from one of our peer into | ||
1040 | our own trail_setup message.*/ | ||
1041 | trail_setup = (const struct PeerTrailSetupMessage *) message; | 1145 | trail_setup = (const struct PeerTrailSetupMessage *) message; |
1042 | 1146 | ||
1043 | GNUNET_STATISTICS_update (GDS_stats, | 1147 | GNUNET_STATISTICS_update (GDS_stats, |
@@ -1048,50 +1152,52 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1048 | GNUNET_NO); | 1152 | GNUNET_NO); |
1049 | 1153 | ||
1050 | 1154 | ||
1051 | /*Check the value of current_destination and handle the respective case. */ | 1155 | /* Check the value of current_destination and handle the respective case. */ |
1052 | if(trail_setup->current_destination == NULL) | 1156 | if(trail_setup->current_destination == NULL) |
1053 | { | 1157 | { |
1054 | /*if there is no value set up for current destination then | 1158 | /* Find the next peer to pass the trail setup message. */ |
1055 | just call find_predecessor() */ | 1159 | next_hop = find_successor(trail_setup->destination_finger); |
1056 | next_hop = find_predecessor(trail_setup->destination_finger); | ||
1057 | } | 1160 | } |
1058 | else if( 0 == (GNUNET_CRYPTO_cmp_peer_identity(trail_setup->current_destination,&my_identity))) | 1161 | else if( 0 == (GNUNET_CRYPTO_cmp_peer_identity(trail_setup->current_destination,&my_identity))) |
1059 | { | 1162 | { |
1060 | /* If this packet is send to me. | 1163 | /* I am current destination, find the next peer to pass the trail setup message. */ |
1061 | 1. call find_predecessor() if it returns your own identity, then | 1164 | next_hop = find_successor(trail_setup->destination_finger); |
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 | } | 1165 | } |
1081 | else | 1166 | else |
1082 | { | 1167 | { |
1083 | /* here is trail_setup is not NULL, but it is not equal to my_identity | 1168 | /* I am part of the trail to reach to current_destination. */ |
1084 | so, it means I am part of the trail to reach to current_destination. | 1169 | next_hop = GDS_Routing_search(trail_setup->source_peer, trail_setup->current_destination, trail_setup->tail->peer); |
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 | } | 1170 | } |
1089 | /*If you have reached here, it means that we have still not reached our | 1171 | |
1090 | final destination, so we now | 1172 | |
1091 | 1. add ourself to trail list | 1173 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity(next_hop,&my_identity))) |
1092 | 2. pass the message to next_hop. */ | 1174 | { |
1093 | forward: | 1175 | /* I am the closest successor of the destination finger in the network. */ |
1176 | /*SUPU:: | ||
1177 | 1. Prepare a trail setup result message. | ||
1178 | 2. Add yourself to trail list. | ||
1179 | 3. send packet to last element in the list. | ||
1180 | */ | ||
1181 | return GNUNET_YES; | ||
1182 | } | ||
1183 | |||
1184 | /* Insert next hop into trial list. */ | ||
1185 | peer_entry = GNUNET_malloc (sizeof (struct TrailPeerList)); | ||
1186 | peer_entry->peer = &my_identity; | ||
1187 | peer_entry->next = NULL; | ||
1188 | peer_entry->prev = NULL; | ||
1189 | |||
1190 | /*SUPU what is this stupid code that I have written. */ | ||
1191 | GNUNET_CONTAINER_DLL_insert_tail(trail_setup->head->next,trail_setup->tail->prev,peer_entry); | ||
1094 | 1192 | ||
1193 | /* Find the struct FriendInfo for next_hop peer id. */ | ||
1194 | friend = GNUNET_CONTAINER_multipeermap_get(friend_peers,next_hop); | ||
1195 | |||
1196 | /* Send trail setup message to next hop friend. */ | ||
1197 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage)); | ||
1198 | GNUNET_CONTAINER_DLL_insert_tail (friend->head, friend->tail, pending); | ||
1199 | friend->pending_count++; | ||
1200 | process_friend_queue(friend); | ||
1095 | return GNUNET_YES; | 1201 | return GNUNET_YES; |
1096 | } | 1202 | } |
1097 | 1203 | ||
@@ -1108,32 +1214,32 @@ static int | |||
1108 | handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *peer, | 1214 | handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *peer, |
1109 | const struct GNUNET_MessageHeader *message) | 1215 | const struct GNUNET_MessageHeader *message) |
1110 | { | 1216 | { |
1111 | /** | 1217 | /** |
1112 | * Just read the linked list backwards and send the packet to next hop | 1218 | * Just read the linked list backwards and send the packet to next hop |
1113 | * till you don't reach the source | 1219 | * till you don't reach the source |
1114 | * but if you are source, then add an entry in finger table for given finger id. | 1220 | * but if you are source, then add an entry in finger table for given finger id. |
1115 | * | 1221 | * |
1116 | * | 1222 | * |
1117 | */ | 1223 | */ |
1118 | //const struct PeerTrailSetupResultMessage *trail_result; | 1224 | //const struct PeerTrailSetupResultMessage *trail_result; |
1119 | //trail_result = (const struct PeerTrailSetupResultMessage *) message; | 1225 | //trail_result = (const struct PeerTrailSetupResultMessage *) message; |
1120 | 1226 | ||
1121 | /*FIXME: This code is wrong, I am writing just to understand the flow, | 1227 | /*FIXME: This code is wrong, I am writing just to understand the flow, |
1122 | if(trail_result->destination == message->destination) | 1228 | if(trail_result->destination == message->destination) |
1123 | { | 1229 | { |
1124 | This condition holds true, then we should add an entry in our | 1230 | This condition holds true, then we should add an entry in our |
1125 | routing table and store this finger and its trail. | 1231 | routing table and store this finger and its trail. |
1126 | struct finger_info = with interval . | 1232 | struct finger_info = with interval . |
1127 | GNUNET_multipeer_map_insert(finger_map) | 1233 | GNUNET_multipeer_map_insert(finger_map) |
1128 | * GDS_Routing_add(); | 1234 | * GDS_Routing_add(); |
1129 | } | 1235 | } |
1130 | else | 1236 | else |
1131 | { | 1237 | { |
1132 | Read the trail list, Check the next_hop and pass the packet to it. | 1238 | 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. | 1239 | FIXME: Should we an entry in our own routing table. |
1134 | }*/ | 1240 | }*/ |
1135 | 1241 | ||
1136 | return 0; | 1242 | return 0; |
1137 | } | 1243 | } |
1138 | 1244 | ||
1139 | 1245 | ||
diff --git a/src/dht/gnunet-service-xdht_routing.c b/src/dht/gnunet-service-xdht_routing.c index 469cd004a..0a0b1ac61 100644 --- a/src/dht/gnunet-service-xdht_routing.c +++ b/src/dht/gnunet-service-xdht_routing.c | |||
@@ -31,7 +31,12 @@ | |||
31 | /* FIXME | 31 | /* FIXME |
32 | * 1. We need field to understand which routing table is for which peer. | 32 | * 1. We need field to understand which routing table is for which peer. |
33 | * 2. Better function names and variable names. | 33 | * 2. Better function names and variable names. |
34 | * 3. Use destination peer id as key for routing table. | ||
35 | * 4. What does GDS stands for? | ||
36 | * | ||
34 | */ | 37 | */ |
38 | |||
39 | |||
35 | /** | 40 | /** |
36 | * Number of requests we track at most (for routing replies). | 41 | * Number of requests we track at most (for routing replies). |
37 | */ | 42 | */ |
@@ -43,25 +48,26 @@ | |||
43 | */ | 48 | */ |
44 | struct RoutingTrail | 49 | struct RoutingTrail |
45 | { | 50 | { |
46 | /** | 51 | /** |
47 | * Source peer . | 52 | * Source peer . |
48 | */ | 53 | */ |
49 | struct GNUNET_PeerIdentity endpoint1; | 54 | struct GNUNET_PeerIdentity *source; |
50 | 55 | ||
51 | /** | 56 | /** |
52 | * Destination peer. | 57 | * Destination peer. |
53 | */ | 58 | */ |
54 | struct GNUNET_PeerIdentity endppoint2; | 59 | struct GNUNET_PeerIdentity *destination; |
55 | 60 | ||
56 | /** | 61 | /** |
57 | * The peer this request was received from. | 62 | * The peer this request was received from. |
58 | */ | 63 | */ |
59 | struct GNUNET_PeerIdentity previous_hop; | 64 | struct GNUNET_PeerIdentity *previous_hop; |
60 | 65 | ||
61 | /** | 66 | /** |
62 | * The peer to which this request should be passed to. | 67 | * The peer to which this request should be passed to. |
63 | */ | 68 | */ |
64 | struct GNUNET_PeerIdentity next_hop; | 69 | struct GNUNET_PeerIdentity *next_hop; |
70 | |||
65 | }; | 71 | }; |
66 | 72 | ||
67 | 73 | ||
@@ -71,19 +77,6 @@ struct RoutingTrail | |||
71 | static struct GNUNET_CONTAINER_MultiPeerMap *routing_table; | 77 | static struct GNUNET_CONTAINER_MultiPeerMap *routing_table; |
72 | 78 | ||
73 | 79 | ||
74 | /** | ||
75 | * Find the next hop to pass the message to . | ||
76 | * @return | ||
77 | */ | ||
78 | //static | ||
79 | struct GNUNET_PeerIdentity * | ||
80 | find_next_hop() | ||
81 | { | ||
82 | return NULL; | ||
83 | } | ||
84 | |||
85 | |||
86 | |||
87 | /**FIXME: Old function added just to remove error for time being. | 80 | /**FIXME: Old function added just to remove error for time being. |
88 | * Add a new entry to our routing table. | 81 | * Add a new entry to our routing table. |
89 | * | 82 | * |
@@ -110,7 +103,7 @@ GDS_ROUTING_add (const struct GNUNET_PeerIdentity *sender, | |||
110 | 103 | ||
111 | 104 | ||
112 | /** | 105 | /** |
113 | * Search the next hop to send the packet to in routing table. | 106 | * Find the next hop to send packet to . |
114 | * @return next hop peer id | 107 | * @return next hop peer id |
115 | */ | 108 | */ |
116 | struct GNUNET_PeerIdentity * | 109 | struct GNUNET_PeerIdentity * |
@@ -118,12 +111,13 @@ GDS_Routing_search(struct GNUNET_PeerIdentity *source_peer, | |||
118 | struct GNUNET_PeerIdentity *destination_peer, | 111 | struct GNUNET_PeerIdentity *destination_peer, |
119 | struct GNUNET_PeerIdentity *prev_hop) | 112 | struct GNUNET_PeerIdentity *prev_hop) |
120 | { | 113 | { |
121 | //struct GNUNET_PeerIdentity *next_hop; | 114 | struct RoutingTrail *trail; |
115 | trail = (struct RoutingTrail *)(GNUNET_CONTAINER_multipeermap_get(routing_table,destination_peer)); | ||
122 | 116 | ||
123 | /* We have got all the fields and now we should search the | 117 | if(trail == NULL) |
124 | routing table by destination_peer and we should return the next_hop | 118 | return NULL; |
125 | I don't see any function at the moment in container_multipeer_map. */ | 119 | |
126 | return NULL; | 120 | return trail->next_hop; |
127 | } | 121 | } |
128 | 122 | ||
129 | 123 | ||
@@ -154,6 +148,8 @@ GDS_ROUTING_process (enum GNUNET_BLOCK_Type type, | |||
154 | const void *data, size_t data_size) | 148 | const void *data, size_t data_size) |
155 | { | 149 | { |
156 | } | 150 | } |
151 | |||
152 | |||
157 | /** | 153 | /** |
158 | * Initialize routing subsystem. | 154 | * Initialize routing subsystem. |
159 | */ | 155 | */ |