diff options
author | Supriti Singh <supritisingh08@gmail.com> | 2014-03-05 14:25:16 +0000 |
---|---|---|
committer | Supriti Singh <supritisingh08@gmail.com> | 2014-03-05 14:25:16 +0000 |
commit | 457009981f77605da6812ac8bd6f67fe455f550f (patch) | |
tree | 0f2b33c3a41c9f160000f4c377f9e1149c0aa21d /src/dht | |
parent | bfa9a1100ed42addaf6c56a818c226a5fd9c6342 (diff) | |
download | gnunet-457009981f77605da6812ac8bd6f67fe455f550f.tar.gz gnunet-457009981f77605da6812ac8bd6f67fe455f550f.zip |
- Adding self to trail_peer_list
- Adding functions to handle concurrent node joins.
- Modified but incomplete find_successor logic.
- Added new message types for concurrent node joins.
Diffstat (limited to 'src/dht')
-rw-r--r-- | src/dht/gnunet-service-xdht.c | 8 | ||||
-rw-r--r-- | src/dht/gnunet-service-xdht_neighbours.c | 632 | ||||
-rw-r--r-- | src/dht/gnunet-service-xdht_neighbours.h | 29 |
3 files changed, 398 insertions, 271 deletions
diff --git a/src/dht/gnunet-service-xdht.c b/src/dht/gnunet-service-xdht.c index 432fea354..f76d62078 100644 --- a/src/dht/gnunet-service-xdht.c +++ b/src/dht/gnunet-service-xdht.c | |||
@@ -192,6 +192,14 @@ main (int argc, char *const *argv) | |||
192 | { | 192 | { |
193 | int ret; | 193 | int ret; |
194 | 194 | ||
195 | /* FIXME: | ||
196 | Here add a new field threshold to set user defined threshold | ||
197 | on routing table size and trail length. Pass the thr1 and thr2 | ||
198 | to neighbours_init and in neighbours file, in function where we | ||
199 | are adding a new entry into our routing table and trail length, | ||
200 | check the threshold values. After conducting experiments, try to | ||
201 | find the correct threshold to have a balance between attack tolerance | ||
202 | and performance.*/ | ||
195 | ret = | 203 | ret = |
196 | (GNUNET_OK == | 204 | (GNUNET_OK == |
197 | GNUNET_SERVICE_run (argc, argv, "dht", GNUNET_SERVICE_OPTION_NONE, &run, | 205 | GNUNET_SERVICE_run (argc, argv, "dht", GNUNET_SERVICE_OPTION_NONE, &run, |
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c index 18b3a88b7..e0f9ff665 100644 --- a/src/dht/gnunet-service-xdht_neighbours.c +++ b/src/dht/gnunet-service-xdht_neighbours.c | |||
@@ -50,6 +50,8 @@ | |||
50 | 50 | ||
51 | 51 | ||
52 | /* FIXME: | 52 | /* FIXME: |
53 | *SUPU: Lets assume that while adding entries in the multipeermap | ||
54 | we are adding it in sorted way. | ||
53 | 1. Add content and route replication later. | 55 | 1. Add content and route replication later. |
54 | *2. Algorithm to shorten the trail length - one possible solution could be | 56 | *2. Algorithm to shorten the trail length - one possible solution could be |
55 | * when we are in trail seutp result part. each peer in the trail check if any of | 57 | * when we are in trail seutp result part. each peer in the trail check if any of |
@@ -62,13 +64,19 @@ | |||
62 | * generate random value does not look smart in send_find_finger_trail_message. | 64 | * generate random value does not look smart in send_find_finger_trail_message. |
63 | * 5. Need to store the interval in finger and friend table which will be used | 65 | * 5. Need to store the interval in finger and friend table which will be used |
64 | * to find the correct successor. | 66 | * to find the correct successor. |
67 | * 6. Need to add a new task, fix fingers. For node join/leave, we need to | ||
68 | * upgrade our finger table periodically. So, we should call fix_fingers | ||
69 | * and change our finger table. | ||
70 | * 7. Should we look for fingers one by one in send_find_finger_trail_setup | ||
71 | * 8. Change the message is gnunet_protocols.h | ||
65 | */ | 72 | */ |
66 | 73 | ||
67 | 74 | ||
68 | /** | 75 | /** |
69 | * Maximum possible fingers of a peer. | 76 | * Maximum possible fingers of a peer. |
77 | * FIXME: Should it be 64 as we are doing all the operation on 64 bit numbers now? | ||
70 | */ | 78 | */ |
71 | #define MAX_FINGERS 256 | 79 | #define MAX_FINGERS 64 |
72 | 80 | ||
73 | /** | 81 | /** |
74 | * Maximum allowed number of pending messages per friend peer. | 82 | * Maximum allowed number of pending messages per friend peer. |
@@ -263,8 +271,10 @@ enum current_destination_type | |||
263 | FRIEND , | 271 | FRIEND , |
264 | 272 | ||
265 | /* Finger */ | 273 | /* Finger */ |
266 | FINGER | 274 | FINGER , |
267 | 275 | ||
276 | /* My own identity */ | ||
277 | MY_ID | ||
268 | }; | 278 | }; |
269 | 279 | ||
270 | /** | 280 | /** |
@@ -284,15 +294,20 @@ struct PeerTrailSetupMessage | |||
284 | struct GNUNET_PeerIdentity source_peer; | 294 | struct GNUNET_PeerIdentity source_peer; |
285 | 295 | ||
286 | /** | 296 | /** |
297 | * As we are not sending any hello messages to this destination | ||
298 | * finger, we are only searching for it, we can just send 64 bit. | ||
287 | * Finger id to which we want to set up the trail to. | 299 | * Finger id to which we want to set up the trail to. |
288 | */ | 300 | * |
289 | struct GNUNET_PeerIdentity destination_finger; | 301 | struct GNUNET_PeerIdentity destination_finger; */ |
290 | 302 | ||
291 | /* FIXME: Temporary field to handle current_destination properly. | 303 | /** |
292 | If flag = 0, then this message's current_destination is a friend. | 304 | * Finger id to which we want to set up the trail to. |
293 | If flag = 1, then the message's current destination is a finger. */ | 305 | */ |
294 | //int flag; | 306 | uint64_t destination_finger; |
295 | 307 | ||
308 | /** | ||
309 | * If the message is forwarded to finger or friend. | ||
310 | */ | ||
296 | enum current_destination_type current_destination_type; | 311 | enum current_destination_type current_destination_type; |
297 | 312 | ||
298 | /** | 313 | /** |
@@ -431,16 +446,25 @@ struct FriendInfo | |||
431 | unsigned int pending_count; | 446 | unsigned int pending_count; |
432 | 447 | ||
433 | /** | 448 | /** |
434 | * FIXME: | 449 | * Start of interval friend[i].start |
435 | * 1. We need some mechanism to check the interval of values for which | 450 | */ |
436 | * a peer is responsible. If we can somehow maintain the peer id of | 451 | uint64_t interval_start; |
437 | * next peer in the friend map, then we will be able to check. Or else | 452 | |
438 | * we iterate over friend map twice will results in O(n^2) complexity. | 453 | /** |
439 | * So, the tradeoff is between space and run time complexity. | 454 | * Start of interval friend[i+1].start |
440 | * Peer id of next friend in friend peermap in 64 bit format. | ||
441 | */ | 455 | */ |
442 | uint64_t interval_end; | 456 | uint64_t interval_end; |
443 | 457 | ||
458 | /** | ||
459 | * Successor of this finger. | ||
460 | */ | ||
461 | struct GNUNET_PeerIdentity successor_identity; | ||
462 | |||
463 | /** | ||
464 | * Predecessor of this finger. | ||
465 | */ | ||
466 | struct GNUNET_PeerIdentity predecessor_identity; | ||
467 | |||
444 | /** | 468 | /** |
445 | * Head of pending messages to be sent to this peer. | 469 | * Head of pending messages to be sent to this peer. |
446 | */ | 470 | */ |
@@ -461,43 +485,73 @@ struct FriendInfo | |||
461 | 485 | ||
462 | 486 | ||
463 | /** | 487 | /** |
488 | * FIXME: Should we use another PeerIdentity which is smaller | ||
489 | * than 256 bits while storing. | ||
490 | * SUPU | ||
491 | * finger_identity is the actual finger that we were looking for. | ||
492 | * successor is the peer id which is our finger in place of finger_identity | ||
493 | * that we were actually looking for. It may happen that finger_identity | ||
494 | * was not in the network and we found the successor closest to that | ||
495 | * finger_identity. | ||
496 | * Predcessor is needed in case of node join/fail. | ||
464 | * Entry in finger_peermap. | 497 | * Entry in finger_peermap. |
465 | */ | 498 | */ |
466 | struct FingerInfo | 499 | struct FingerInfo |
467 | { | 500 | { |
468 | /** | 501 | /** |
469 | * What is the identity of the finger peer? | 502 | * Index in finger_peermap. |
470 | */ | 503 | */ |
471 | struct GNUNET_PeerIdentity id; | 504 | unsigned int index; |
472 | 505 | ||
473 | /** | 506 | /** |
474 | * Start of the interval of keys for which this finger is responsible. | 507 | * Finger identity. |
475 | */ | 508 | */ |
476 | unsigned int interval_start; | 509 | struct GNUNET_PeerIdentity finger_identity; |
477 | 510 | ||
478 | /** | 511 | /** |
479 | * End of the interval of keys for which this finger is responsible. | 512 | * Start of interval finger[i].start |
480 | */ | 513 | */ |
481 | unsigned int interval_end; | 514 | uint64_t interval_start; |
482 | 515 | ||
483 | /** | 516 | /** |
484 | * List of peers in the trail. | 517 | * Start of interval finger[i+1].start |
485 | */ | 518 | */ |
486 | const struct GNUNET_PeerIdentity *trail_peer_list; | 519 | uint64_t interval_end; |
487 | 520 | ||
488 | /** | 521 | /** |
489 | * Finger index. | 522 | * Successor of this finger. |
490 | */ | 523 | */ |
491 | unsigned int finger_index; | 524 | struct GNUNET_PeerIdentity successor_identity; |
525 | |||
526 | /** | ||
527 | * Predecessor of this finger. | ||
528 | */ | ||
529 | struct GNUNET_PeerIdentity predecessor_identity; | ||
530 | |||
531 | /** | ||
532 | * List of peers in the trail. | ||
533 | */ | ||
534 | const struct GNUNET_PeerIdentity *trail_peer_list; | ||
492 | }; | 535 | }; |
493 | 536 | ||
494 | |||
495 | /** | 537 | /** |
496 | * Task that sends FIND FINGER TRAIL requests. | 538 | * Task that sends FIND FINGER TRAIL requests. |
497 | */ | 539 | */ |
498 | static GNUNET_SCHEDULER_TaskIdentifier find_finger_trail_task; | 540 | static GNUNET_SCHEDULER_TaskIdentifier find_finger_trail_task; |
499 | 541 | ||
500 | /** | 542 | /** |
543 | * FIXME: As we should check for our immediate successor | ||
544 | * in case of node join/fail, the immediate successor will change. | ||
545 | * Hence we define a process which will be scheduled in regular interval. | ||
546 | * But you should schedule this process once you have found your successor. | ||
547 | * so, in finger_table_add_entry, when finger_peermap is size 1 then start | ||
548 | * this task, and periodically call it within it self like find_finger_trail_setup | ||
549 | * | ||
550 | * Task that periodically checks for the immediate successor. | ||
551 | */ | ||
552 | static GNUNET_SCHEDULER_TaskIdentifier verify_immediate_successor; | ||
553 | |||
554 | /** | ||
501 | * Identity of this peer. | 555 | * Identity of this peer. |
502 | */ | 556 | */ |
503 | static struct GNUNET_PeerIdentity my_identity; | 557 | static struct GNUNET_PeerIdentity my_identity; |
@@ -640,12 +694,10 @@ process_friend_queue (struct FriendInfo *peer) | |||
640 | 694 | ||
641 | /** | 695 | /** |
642 | * SUPU: | 696 | * SUPU: |
643 | * 1. trail_length is already incremented in the calling function | 697 | * We add the next destination i.e. friend to which we are sending the packet |
644 | * i.e. in send_find_finger_trail, we send trail_length = 1, and then we | 698 | * to our peer list in the calling function and we also increment trail_length |
645 | * add the peer. | 699 | * in calling function i.e. send_find_finger_trail and handle_dht_p2p_trail_setup. |
646 | * 2. in handle_dht_p2p_trail_setup, we send trail_length = trail_length+1; | 700 | * Here we only copy the whole trail into our peer_list. |
647 | * and we already have added the id of current_destination in our peer_list so | ||
648 | * we need not to do anything else. | ||
649 | * Setup the trail message and forward it to a friend. | 701 | * Setup the trail message and forward it to a friend. |
650 | * @param source_peer Peer which wants to set up the trail to one of its finger. | 702 | * @param source_peer Peer which wants to set up the trail to one of its finger. |
651 | * @param destination_finger Peer to which we want to set up the trail to. | 703 | * @param destination_finger Peer to which we want to set up the trail to. |
@@ -655,7 +707,7 @@ process_friend_queue (struct FriendInfo *peer) | |||
655 | */ | 707 | */ |
656 | void | 708 | void |
657 | GDS_NEIGHBOURS_handle_trail_setup(struct GNUNET_PeerIdentity *source_peer, | 709 | GDS_NEIGHBOURS_handle_trail_setup(struct GNUNET_PeerIdentity *source_peer, |
658 | struct GNUNET_PeerIdentity *destination_finger, | 710 | uint64_t *destination_finger, |
659 | struct FriendInfo *current_destination, | 711 | struct FriendInfo *current_destination, |
660 | unsigned int trail_length, | 712 | unsigned int trail_length, |
661 | struct GNUNET_PeerIdentity *trail_peer_list) | 713 | struct GNUNET_PeerIdentity *trail_peer_list) |
@@ -687,23 +739,14 @@ GDS_NEIGHBOURS_handle_trail_setup(struct GNUNET_PeerIdentity *source_peer, | |||
687 | pending->msg = &tsm->header; | 739 | pending->msg = &tsm->header; |
688 | tsm->header.size = htons (msize); | 740 | tsm->header.size = htons (msize); |
689 | tsm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP); | 741 | tsm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP); |
690 | memcpy(&(tsm->destination_finger), destination_finger, sizeof (struct GNUNET_PeerIdentity)); | 742 | memcpy(&(tsm->destination_finger), destination_finger, sizeof (uint64_t)); //FIXME: Is this copy correct? |
691 | memcpy(&(tsm->source_peer), source_peer, sizeof (struct GNUNET_PeerIdentity)); | 743 | memcpy(&(tsm->source_peer), source_peer, sizeof (struct GNUNET_PeerIdentity)); |
692 | memcpy(&(tsm->current_destination),&(current_destination->id), sizeof (struct GNUNET_PeerIdentity)); | 744 | memcpy(&(tsm->current_destination),&(current_destination->id), sizeof (struct GNUNET_PeerIdentity)); |
693 | tsm->current_destination_type = htonl(FRIEND); | 745 | tsm->current_destination_type = htonl(FRIEND); |
694 | tsm->trail_length = htonl(trail_length); | 746 | tsm->trail_length = htonl(trail_length); |
695 | peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * trail_length); | 747 | peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * trail_length); |
696 | peer_list = (struct GNUNET_PeerIdentity *) &tsm[1]; | 748 | peer_list = (struct GNUNET_PeerIdentity *) &tsm[1]; |
697 | 749 | memcpy(peer_list, trail_peer_list, trail_length * sizeof(struct GNUNET_PeerIdentity)); | |
698 | if(NULL == trail_peer_list) | ||
699 | { | ||
700 | /* FIXME: Shift this logic to send_find_finger_trail_message. */ | ||
701 | memcpy(peer_list, &(current_destination->id), sizeof(struct GNUNET_PeerIdentity)); | ||
702 | } | ||
703 | else | ||
704 | { | ||
705 | memcpy(peer_list, trail_peer_list, trail_length * sizeof(struct GNUNET_PeerIdentity)); | ||
706 | } | ||
707 | 750 | ||
708 | GNUNET_CONTAINER_DLL_insert_tail (current_destination->head, current_destination->tail, pending); | 751 | GNUNET_CONTAINER_DLL_insert_tail (current_destination->head, current_destination->tail, pending); |
709 | current_destination->pending_count++; | 752 | current_destination->pending_count++; |
@@ -799,6 +842,13 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, | |||
799 | struct GNUNET_CONTAINER_BloomFilter *peer_bf) | 842 | struct GNUNET_CONTAINER_BloomFilter *peer_bf) |
800 | { | 843 | { |
801 | 844 | ||
845 | /* | ||
846 | 1. take the key, get the 64 bit value of the key. | ||
847 | 2. call find_successor to get the successor of the key. | ||
848 | 3. successor can be either a friend or finger. | ||
849 | 4. update the field in get message to reflect if its a friend or finger table | ||
850 | 5. add the put message to pending message and send it. | ||
851 | */ | ||
802 | } | 852 | } |
803 | 853 | ||
804 | /**FIXME: Old implementation just to remove error. | 854 | /**FIXME: Old implementation just to remove error. |
@@ -834,37 +884,13 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, | |||
834 | const void *data, size_t data_size) | 884 | const void *data, size_t data_size) |
835 | { | 885 | { |
836 | 886 | ||
837 | } | 887 | /* |
838 | 888 | 1. take the key, get the 64 bit value of the key. | |
839 | 889 | 2. call find_successor to get the successor of the key. | |
840 | /**FIXME: Old implementation just to remove error. | 890 | 3. successor can be either a friend or finger. |
841 | * Handle a reply (route to origin). Only forwards the reply back to | 891 | 4. update the field in put message to reflect if its a friend or finger table |
842 | * other peers waiting for it. Does not do local caching or | 892 | 5. add the put message to pending message and send it. |
843 | * forwarding to local clients. | 893 | */ |
844 | * | ||
845 | * @param target neighbour that should receive the block (if still connected) | ||
846 | * @param type type of the block | ||
847 | * @param expiration_time when does the content expire | ||
848 | * @param key key for the content | ||
849 | * @param put_path_length number of entries in put_path | ||
850 | * @param put_path peers the original PUT traversed (if tracked) | ||
851 | * @param get_path_length number of entries in put_path | ||
852 | * @param get_path peers this reply has traversed so far (if tracked) | ||
853 | * @param data payload of the reply | ||
854 | * @param data_size number of bytes in data | ||
855 | */ | ||
856 | void | ||
857 | GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target, | ||
858 | enum GNUNET_BLOCK_Type type, | ||
859 | struct GNUNET_TIME_Absolute expiration_time, | ||
860 | const struct GNUNET_HashCode * key, | ||
861 | unsigned int put_path_length, | ||
862 | const struct GNUNET_PeerIdentity *put_path, | ||
863 | unsigned int get_path_length, | ||
864 | const struct GNUNET_PeerIdentity *get_path, | ||
865 | const void *data, size_t data_size) | ||
866 | { | ||
867 | |||
868 | } | 894 | } |
869 | 895 | ||
870 | 896 | ||
@@ -916,26 +942,20 @@ select_random_friend() | |||
916 | * search for trail to that finger. | 942 | * search for trail to that finger. |
917 | * @return finger_identity | 943 | * @return finger_identity |
918 | */ | 944 | */ |
919 | static | 945 | static uint64_t * |
920 | struct GNUNET_PeerIdentity * | ||
921 | compute_finger_identity() | 946 | compute_finger_identity() |
922 | { | 947 | { |
923 | struct GNUNET_PeerIdentity *finger_identity; | 948 | uint64_t *my_id64 ; |
949 | uint64_t *finger_identity64; | ||
924 | 950 | ||
925 | finger_identity = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity)); | 951 | my_id64 = GNUNET_malloc (sizeof (uint64_t)); |
926 | finger_identity = GNUNET_CRYPTO_compute_finger_identity(&my_identity,current_finger_index ); | 952 | finger_identity64 = GNUNET_malloc (sizeof (uint64_t)); |
927 | 953 | ||
928 | current_finger_index = (current_finger_index+1) % MAX_FINGERS; | 954 | memcpy(my_id64, &(my_identity.public_key.q_y), sizeof (uint64_t)); |
929 | 955 | *finger_identity64 = fmod ((*my_id64 + pow (2,current_finger_index)),( (pow (2,MAX_FINGERS)))); | |
930 | /* Check if you already have an entry in finger_peermap for this finger_id. | 956 | current_finger_index = current_finger_index + 1; |
931 | If yes then again look for a new finger_id. | ||
932 | FIXME: Should we return NULL here? | ||
933 | if(NULL != GNUNET_CONTAINER_multipeermap_get(finger_peermap,finger_peer_id)) | ||
934 | { | ||
935 | finger_peer_id = compute_finger_identity(); | ||
936 | }*/ | ||
937 | 957 | ||
938 | return finger_identity; | 958 | return finger_identity64; |
939 | } | 959 | } |
940 | 960 | ||
941 | 961 | ||
@@ -949,8 +969,7 @@ compute_finger_identity() | |||
949 | * @param me my own identity | 969 | * @param me my own identity |
950 | * @return peer identity of immediate predecessor. | 970 | * @return peer identity of immediate predecessor. |
951 | */ | 971 | */ |
952 | static | 972 | static uint64_t * |
953 | struct GNUNET_PeerIdentity * | ||
954 | find_immediate_predecessor() | 973 | find_immediate_predecessor() |
955 | { | 974 | { |
956 | /* Using your own peer identity, calculate your predecessor | 975 | /* Using your own peer identity, calculate your predecessor |
@@ -959,13 +978,51 @@ find_immediate_predecessor() | |||
959 | * If we already have a trail to our predecessor then send NULL and | 978 | * If we already have a trail to our predecessor then send NULL and |
960 | * calling function should be able to handle that case. | 979 | * calling function should be able to handle that case. |
961 | */ | 980 | */ |
962 | return NULL; | 981 | /* FIXME: O could be a valid peer id, return something else. */ |
982 | return 0; | ||
983 | } | ||
984 | |||
985 | |||
986 | /** | ||
987 | * Periodically verify your own immediate successor and | ||
988 | * tell your successor about yourself. | ||
989 | * | ||
990 | * @param cls closure for this task | ||
991 | * @param tc the context under which the task is running | ||
992 | */ | ||
993 | static void | ||
994 | stabilize(void *cls, | ||
995 | const struct GNUNET_SCHEDULER_TaskContext *tc ) | ||
996 | { | ||
997 | /* | ||
998 | * FIXME: | ||
999 | * Should we have a new message type | ||
1000 | * 1. like who is your predecessor. | ||
1001 | * 2. notify | ||
1002 | In this function | ||
1003 | 1. ask your immediate successor ( its stored in your finger table with | ||
1004 | field that notes that its immediate successor) who is its predecessor. | ||
1005 | 2. Then after getting the reply, check if its you. | ||
1006 | 3. If not then update the new successor and your successor | ||
1007 | and notify the new successor that you are its new predecessor. | ||
1008 | */ | ||
1009 | struct GNUNET_TIME_Relative next_send_time; | ||
1010 | |||
1011 | next_send_time.rel_value_us = | ||
1012 | DHT_MINIMUM_FIND_FINGER_TRAIL_INTERVAL.rel_value_us + | ||
1013 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
1014 | DHT_MAXIMUM_FIND_FINGER_TRAIL_INTERVAL.rel_value_us / | ||
1015 | (current_finger_index + 1)); | ||
1016 | |||
1017 | verify_immediate_successor = | ||
1018 | GNUNET_SCHEDULER_add_delayed (next_send_time, &stabilize, | ||
1019 | NULL); | ||
963 | } | 1020 | } |
964 | 1021 | ||
965 | 1022 | ||
966 | /** | 1023 | /** |
967 | * Task to send a find finger trail message. We attempt to find trail | 1024 | * Task to send a find finger trail message. We attempt to find trail |
968 | * to our finger in the network. | 1025 | * to our finger and successor in the network. |
969 | * | 1026 | * |
970 | * @param cls closure for this task | 1027 | * @param cls closure for this task |
971 | * @param tc the context under which the task is running | 1028 | * @param tc the context under which the task is running |
@@ -974,10 +1031,11 @@ static void | |||
974 | send_find_finger_trail_message (void *cls, | 1031 | send_find_finger_trail_message (void *cls, |
975 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 1032 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
976 | { | 1033 | { |
977 | struct GNUNET_PeerIdentity *finger_identity; | ||
978 | struct FriendInfo *friend; | 1034 | struct FriendInfo *friend; |
979 | struct GNUNET_TIME_Relative next_send_time; | 1035 | struct GNUNET_TIME_Relative next_send_time; |
980 | 1036 | uint64_t *finger_identity; /* FIXME: Better variable name */ | |
1037 | struct GNUNET_PeerIdentity *peer_list; | ||
1038 | |||
981 | /* We already have found trail to each of our possible fingers in the network. */ | 1039 | /* We already have found trail to each of our possible fingers in the network. */ |
982 | if (GNUNET_CONTAINER_multipeermap_size (finger_peermap) == MAX_FINGERS) | 1040 | if (GNUNET_CONTAINER_multipeermap_size (finger_peermap) == MAX_FINGERS) |
983 | { | 1041 | { |
@@ -986,6 +1044,7 @@ send_find_finger_trail_message (void *cls, | |||
986 | * predecessor when there is a node failure/join. It may happen before. | 1044 | * predecessor when there is a node failure/join. It may happen before. |
987 | * Think of a better strategy to decide when to call this function. | 1045 | * Think of a better strategy to decide when to call this function. |
988 | * We can find trail to our immediate predecessor in the network. | 1046 | * We can find trail to our immediate predecessor in the network. |
1047 | * I think its better to call this after we have trail to our successor set up. | ||
989 | */ | 1048 | */ |
990 | finger_identity = find_immediate_predecessor(); | 1049 | finger_identity = find_immediate_predecessor(); |
991 | 1050 | ||
@@ -997,8 +1056,6 @@ send_find_finger_trail_message (void *cls, | |||
997 | } | 1056 | } |
998 | else | 1057 | else |
999 | { | 1058 | { |
1000 | /* Find the finger_peer_id for which we want to setup the trail */ | ||
1001 | finger_identity = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | ||
1002 | finger_identity = compute_finger_identity(); | 1059 | finger_identity = compute_finger_identity(); |
1003 | 1060 | ||
1004 | if(finger_identity == NULL) | 1061 | if(finger_identity == NULL) |
@@ -1012,8 +1069,14 @@ send_find_finger_trail_message (void *cls, | |||
1012 | 1069 | ||
1013 | /* We found a friend.*/ | 1070 | /* We found a friend.*/ |
1014 | if(NULL != friend) | 1071 | if(NULL != friend) |
1015 | { | 1072 | { |
1016 | GDS_NEIGHBOURS_handle_trail_setup(&my_identity,finger_identity,friend,1,NULL); | 1073 | /* SUPU: Verify if its correct or not. */ |
1074 | unsigned int trail_length = 2; | ||
1075 | peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * trail_length); | ||
1076 | memcpy(&peer_list[0], &(my_identity), sizeof (struct GNUNET_PeerIdentity)); | ||
1077 | memcpy(&peer_list[1], &(friend->id), sizeof (struct GNUNET_PeerIdentity)); | ||
1078 | GDS_NEIGHBOURS_handle_trail_setup(&my_identity, finger_identity, | ||
1079 | friend, trail_length, peer_list); | ||
1017 | } | 1080 | } |
1018 | 1081 | ||
1019 | /* FIXME: Should we be using current_finger_index to generate random interval.*/ | 1082 | /* FIXME: Should we be using current_finger_index to generate random interval.*/ |
@@ -1061,14 +1124,19 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
1061 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# peers connected"), 1, | 1124 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# peers connected"), 1, |
1062 | GNUNET_NO); | 1125 | GNUNET_NO); |
1063 | 1126 | ||
1127 | /* FIXME: Whenever you add an entry into your finger peermap, | ||
1128 | first add everything in sorted way and interval field should also | ||
1129 | be updated. */ | ||
1064 | ret = GNUNET_new (struct FriendInfo); | 1130 | ret = GNUNET_new (struct FriendInfo); |
1065 | ret->id = *peer; | 1131 | ret->id = *peer; |
1066 | 1132 | ||
1133 | |||
1067 | GNUNET_assert (GNUNET_OK == | 1134 | GNUNET_assert (GNUNET_OK == |
1068 | GNUNET_CONTAINER_multipeermap_put (friend_peermap, | 1135 | GNUNET_CONTAINER_multipeermap_put (friend_peermap, |
1069 | peer, ret, | 1136 | peer, ret, |
1070 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 1137 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
1071 | 1138 | ||
1139 | |||
1072 | /* got a first connection, good time to start with FIND FINGER TRAIL requests... */ | 1140 | /* got a first connection, good time to start with FIND FINGER TRAIL requests... */ |
1073 | if (1 == GNUNET_CONTAINER_multipeermap_size (friend_peermap)) | 1141 | if (1 == GNUNET_CONTAINER_multipeermap_size (friend_peermap)) |
1074 | find_finger_trail_task = GNUNET_SCHEDULER_add_now (&send_find_finger_trail_message, NULL); | 1142 | find_finger_trail_task = GNUNET_SCHEDULER_add_now (&send_find_finger_trail_message, NULL); |
@@ -1133,15 +1201,12 @@ handle_dht_p2p_put (void *cls, | |||
1133 | const struct GNUNET_MessageHeader *message) | 1201 | const struct GNUNET_MessageHeader *message) |
1134 | { | 1202 | { |
1135 | /** | 1203 | /** |
1136 | 1. Search the friend,finger and check your own id to find the closest | 1204 | 1. Check if destination is friend or finger. |
1137 | * predecessor the given key. --> find_predecessor() | 1205 | 2. If finger then get the next hop from routing table and |
1138 | 2. If self then datache_store | 1206 | * call GDS_NEGIHBOURS_handle_get. |
1139 | 3. If friend, then add to peer queue | 1207 | 3. If friend then call find_successor to get the next hop and again |
1140 | 4. If finger, then add to the peer queue of the first hop. | 1208 | * call GDS_NEIGHBOURS_handle_get to send to chosen hop. |
1141 | * in put message also maintain a field current_destination and use | 1209 | 4. If you are the destination then do datacache_store. |
1142 | * same logic as trail setup to understand if you are just part of trail | ||
1143 | * to reach to a particular peer or you are endpoint of trail or just a friend. | ||
1144 | * | ||
1145 | */ | 1210 | */ |
1146 | return 0; | 1211 | return 0; |
1147 | } | 1212 | } |
@@ -1160,138 +1225,134 @@ static int | |||
1160 | handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | 1225 | handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, |
1161 | const struct GNUNET_MessageHeader *message) | 1226 | const struct GNUNET_MessageHeader *message) |
1162 | { | 1227 | { |
1228 | /** | ||
1229 | 1. Check if destination is friend or finger. | ||
1230 | 2. If finger then get the next hop from routing table and | ||
1231 | * call GDS_NEGIHBOURS_handle_get. | ||
1232 | 3. If friend then call find_successor to get the next hop and again | ||
1233 | * call GDS_NEIGHBOURS_handle_get to send to chosen hop. | ||
1234 | 4. If you are the destination then send the data back to source peer | ||
1235 | * Assuming we have trail setup we can | ||
1236 | * either store the whole trail or again do the search process.. | ||
1237 | */ | ||
1163 | return 0; | 1238 | return 0; |
1164 | } | 1239 | } |
1165 | 1240 | ||
1166 | 1241 | ||
1167 | /** | 1242 | /** |
1168 | * Core handler for p2p result messages. | 1243 | * FIXME: Use some optimal way to do the operations. |
1169 | * | 1244 | * FIXME: Check if this function can be used as such for put/get |
1170 | * @param cls closure | 1245 | * 1.assumption that when ever we insert a value into friend or |
1171 | * @param message message | 1246 | * finger map, we sort it and also update the interval correctly, |
1172 | * @param peer peer identity this notification is about | 1247 | * 2. all the comparison are done on 64 bit values. so in last part when |
1173 | * @return #GNUNET_YES (do not cut p2p connection) | 1248 | * you compare finger , friend and your own identity then also you need to |
1174 | */ | 1249 | * have the values in 64 bit format and get the correct successor. |
1175 | static int | 1250 | * At this point the algorithm does not look very smart. |
1176 | handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer, | 1251 | * Finds successor of the identifier |
1177 | const struct GNUNET_MessageHeader *message) | 1252 | * @param id Identifier for which we are trying to find the successor |
1178 | { | ||
1179 | return 0; | ||
1180 | } | ||
1181 | |||
1182 | |||
1183 | /** | ||
1184 | * FIXME: | ||
1185 | * 1. Where do we use mod MAX_FINGERS? | ||
1186 | * 2. You are not using mod when searching for the closest successor of a finger. | ||
1187 | * 3. * 6. When I change the logic for find_successor, then I need to compare the interval | ||
1188 | * of two fingers. for that do I need to maintain a finger index and calculate | ||
1189 | * the interval? | ||
1190 | * @param destination | ||
1191 | * @param flag Set the value of flag to 0, if next_hop = friend/1 if next_hop = finger. | ||
1192 | * @param current_destination We should set this field to finger id/friend id chosen to be next_hop. | ||
1193 | * @return | 1253 | * @return |
1194 | */ | 1254 | */ |
1195 | static struct GNUNET_PeerIdentity * | 1255 | static struct GNUNET_PeerIdentity * |
1196 | find_successor(struct GNUNET_PeerIdentity *destination, | 1256 | find_successor(uint64_t id, |
1197 | struct GNUNET_PeerIdentity *current_destination, | 1257 | struct GNUNET_PeerIdentity *current_destination, |
1198 | enum current_destination_type *type) | 1258 | enum current_destination_type *type) |
1199 | { | 1259 | { |
1200 | /* | 1260 | /* 1. Iterate over friend map and find the closest peer. |
1201 | * 1. Compare your identity with destination identity. | 1261 | 2. Iterate over finger map and find the closest peer. |
1202 | * 2. Iterate over friend_map to find the peer identity with identity >= destination | 1262 | 3. Sort my_identity, friend successor and finger successor. |
1203 | * 3. Iterate over finger_map to find the peer identity with identity >= destination | 1263 | 4. Choose the closest peer among the three. |
1204 | * 4. Compare id,friend and finger to select one which is the least and still >= destination. | 1264 | */ |
1205 | * 5. If friend/my_identity then flag = 0 | ||
1206 | * 6. If finger, then flag = 1. | ||
1207 | * 7. Set the current_destination value with chosen friend/finger/my_identity | ||
1208 | * 8. If finger, then search in your own finger table send the next hop to reach that finger. | ||
1209 | */ | ||
1210 | unsigned int friend_index; | ||
1211 | unsigned int finger_index; | ||
1212 | struct GNUNET_CONTAINER_MultiPeerMapIterator *friend_iter; | 1265 | struct GNUNET_CONTAINER_MultiPeerMapIterator *friend_iter; |
1213 | struct GNUNET_CONTAINER_MultiPeerMapIterator *finger_iter; | 1266 | struct GNUNET_CONTAINER_MultiPeerMapIterator *finger_iter; |
1214 | struct GNUNET_PeerIdentity key_ret; | ||
1215 | struct FriendInfo *friend; | 1267 | struct FriendInfo *friend; |
1216 | struct FingerInfo *finger; | 1268 | struct FingerInfo *finger; |
1217 | struct GNUNET_PeerIdentity *current_successor; | 1269 | struct GNUNET_PeerIdentity key_ret; |
1218 | 1270 | unsigned int finger_index; | |
1219 | /* FIXME: Temporary field used to understand if we got a friend or finger | 1271 | unsigned int friend_index; |
1220 | as next successor. find something better. */ | 1272 | struct FriendInfo *successor_friend; |
1221 | int successor; | 1273 | struct FingerInfo *successor_finger; |
1222 | int finger_peer = 0; | 1274 | uint64_t friend_id; |
1223 | int friend_peer = 1; | 1275 | uint64_t finger_id; |
1224 | int me = 2; | 1276 | uint64_t my_id; |
1225 | |||
1226 | current_successor = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | ||
1227 | 1277 | ||
1228 | /* initialize current_successor with your own identity. */ | 1278 | successor_friend = GNUNET_malloc (sizeof (struct FriendInfo )); |
1229 | memcpy(current_successor,&my_identity,sizeof(struct GNUNET_PeerIdentity)); | 1279 | successor_finger = GNUNET_malloc (sizeof (struct FingerInfo )); |
1230 | successor = me; | ||
1231 | 1280 | ||
1281 | /* Iterate over friend map. */ | ||
1232 | friend_iter = GNUNET_CONTAINER_multipeermap_iterator_create (friend_peermap); | 1282 | friend_iter = GNUNET_CONTAINER_multipeermap_iterator_create (friend_peermap); |
1233 | |||
1234 | /*iterate over friend map till you reach a peer id such that destination <= peer id */ | ||
1235 | for (friend_index = 0; friend_index < GNUNET_CONTAINER_multipeermap_size (friend_peermap); friend_index++) | 1283 | for (friend_index = 0; friend_index < GNUNET_CONTAINER_multipeermap_size (friend_peermap); friend_index++) |
1236 | { | 1284 | { |
1285 | /* SUPU: check if you are using iterator_next correctly */ | ||
1237 | if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next(friend_iter,&key_ret,(const void **)&friend)) | 1286 | if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next(friend_iter,&key_ret,(const void **)&friend)) |
1238 | { | 1287 | { |
1239 | if(0 > GNUNET_CRYPTO_cmp_peer_identity(&friend->id,destination) || | 1288 | if(((friend->interval_start <= id) && (id < friend->interval_end)) |
1240 | (0 == GNUNET_CRYPTO_cmp_peer_identity(&friend->id,destination))) | 1289 | || (((friend->interval_start) > (friend->interval_end)) |
1290 | && ((friend->interval_start <= id) && (id < friend->interval_end)))) | ||
1241 | { | 1291 | { |
1242 | /* If yes then check if finger <= current_successor */ | 1292 | /* SUPU: Here I am copying friend into successor_friend as when among |
1243 | if(0 < GNUNET_CRYPTO_cmp_peer_identity(&friend->id,current_successor) || | 1293 | three ids i.e. friend, finger and my_id, one is chosen then I should |
1244 | (0 == GNUNET_CRYPTO_cmp_peer_identity(&friend->id,current_successor))) | 1294 | be able to identify which one was chosen. */ |
1245 | { | 1295 | memcpy(successor_friend, friend, sizeof (struct FriendInfo)); |
1246 | memcpy(current_successor,friend,sizeof(struct GNUNET_PeerIdentity)); | 1296 | break; /*FIXME: Will it come out of outer for loop */ |
1247 | successor = friend_peer; | 1297 | } |
1248 | } | ||
1249 | } | ||
1250 | } | 1298 | } |
1251 | } | 1299 | } |
1252 | 1300 | ||
1253 | |||
1254 | finger_iter = GNUNET_CONTAINER_multipeermap_iterator_create (finger_peermap); | 1301 | finger_iter = GNUNET_CONTAINER_multipeermap_iterator_create (finger_peermap); |
1255 | /* iterate over finger map till you reach a peer id such that destination <= peer id */ | 1302 | /* iterate over finger map till you reach a peer id such that destination <= peer id */ |
1256 | for (finger_index = 0; finger_index < GNUNET_CONTAINER_multipeermap_size (finger_peermap); finger_index++) | 1303 | for (finger_index = 0; finger_index < GNUNET_CONTAINER_multipeermap_size (finger_peermap); finger_index++) |
1257 | { | 1304 | { |
1258 | if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next(finger_iter,&key_ret,(const void **)&finger)) | 1305 | if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next(finger_iter,&key_ret,(const void **)&finger)) |
1259 | { | 1306 | { |
1260 | if(0 > GNUNET_CRYPTO_cmp_peer_identity(&finger->id,destination) || | 1307 | if(((finger->interval_start <= id) && (id < finger->interval_end)) |
1261 | (0 == GNUNET_CRYPTO_cmp_peer_identity(&finger->id,destination))) | 1308 | || (((finger->interval_start) > (finger->interval_end)) |
1309 | && ((finger->interval_start <= id) && (id < finger->interval_end)))) | ||
1262 | { | 1310 | { |
1263 | /* If yes then check if finger <= current_friend_successor */ | 1311 | memcpy(successor_finger, finger, sizeof (struct FingerInfo)); |
1264 | if(0 < GNUNET_CRYPTO_cmp_peer_identity(&finger->id,current_successor) | 1312 | break; /*FIXME: Will it come out of outer for loop */ |
1265 | || (0 == GNUNET_CRYPTO_cmp_peer_identity(&finger->id,current_successor))) | 1313 | } |
1266 | { | ||
1267 | memcpy(current_successor,finger,sizeof(struct GNUNET_PeerIdentity)); | ||
1268 | successor = finger_peer; | ||
1269 | } | ||
1270 | } | ||
1271 | } | 1314 | } |
1272 | } | ||
1273 | |||
1274 | memcpy(current_destination,current_successor,sizeof(struct GNUNET_PeerIdentity)); | ||
1275 | |||
1276 | if(successor == finger_peer) | ||
1277 | { | ||
1278 | *type = FINGER; | ||
1279 | } | ||
1280 | else | ||
1281 | { | ||
1282 | /* The successor is either my_identity or friend. */ | ||
1283 | *type = FRIEND; | ||
1284 | } | 1315 | } |
1285 | 1316 | ||
1286 | return current_successor; | 1317 | /* Here you have two values from friend and finger map. |
1318 | Now sort the my_identity, friend and finger and | ||
1319 | choose the closest peer. Also update the closest successor type | ||
1320 | correctly to finger/friend/me. and update the current_destination value. */ | ||
1321 | memcpy (&my_id, &(my_identity.public_key.q_y), sizeof (uint64_t)); | ||
1322 | memcpy (&friend_id, (successor_friend->id.public_key.q_y), sizeof (uint64_t)); | ||
1323 | memcpy (&finger_id, (successor_finger->finger_identity.public_key.q_y), sizeof (uint64_t)); | ||
1324 | |||
1325 | /* if finger_id is selected, then set type = FINGER, current_destination = finger | ||
1326 | and next_hop = first peer in trail list. | ||
1327 | if friend id is selected, then set type = FRIEND, current_destination = friend | ||
1328 | and return friend. */ | ||
1329 | /* You need some function to compare which three of them is successor to | ||
1330 | id that we are looking for. | ||
1331 | 1. Sort three of them. | ||
1332 | 2. Set up the new interval. | ||
1333 | 3. Check in which interval id lies. | ||
1334 | * You should set the type proprly. Need to add a new type to handle | ||
1335 | * my_idenity. | ||
1336 | This is very suboptimal. | ||
1337 | Once you found the correct successor you should just return the | ||
1338 | correct PeerIdentity. | ||
1339 | so basic logic is: | ||
1340 | lets say that | ||
1341 | my_id = 3 [3,5) | ||
1342 | friend_id = 5 [5,7) | ||
1343 | finger_id = 7 [7,3) | ||
1344 | and we are looking for 1. */ | ||
1345 | return &(successor_friend->id); /* FIXME: remove this, added just to remove | ||
1346 | * warning */ | ||
1287 | } | 1347 | } |
1288 | 1348 | ||
1289 | 1349 | ||
1290 | /** | 1350 | /** |
1351 | * Handle a P2PTrailSetupMessage. | ||
1291 | * @param cls closure | 1352 | * @param cls closure |
1292 | * @param message message | 1353 | * @param message message |
1293 | * @param peer peer identity this notification is about | 1354 | * @param peer peer identity this notification is about |
1294 | * @return #GNUNET_YES | 1355 | * @return GNUNET_OK on success, GNUNET_SYSERR on error |
1295 | */ | 1356 | */ |
1296 | static int | 1357 | static int |
1297 | handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer, | 1358 | handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer, |
@@ -1300,13 +1361,13 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1300 | struct PeerTrailSetupMessage *trail_setup; | 1361 | struct PeerTrailSetupMessage *trail_setup; |
1301 | struct GNUNET_PeerIdentity *next_hop; | 1362 | struct GNUNET_PeerIdentity *next_hop; |
1302 | struct FriendInfo *target_friend; | 1363 | struct FriendInfo *target_friend; |
1303 | struct FriendInfo *new_target_friend; | ||
1304 | size_t msize; | 1364 | size_t msize; |
1305 | uint32_t trail_length; | 1365 | uint32_t trail_length; |
1306 | enum current_destination_type peer_type; | 1366 | enum current_destination_type peer_type; |
1307 | struct GNUNET_PeerIdentity *trail_peer_list; | 1367 | struct GNUNET_PeerIdentity *trail_peer_list; |
1308 | uint32_t current_trail_index; | 1368 | uint32_t current_trail_index; |
1309 | struct GNUNET_PeerIdentity *next_peer; | 1369 | struct GNUNET_PeerIdentity *next_peer; |
1370 | |||
1310 | 1371 | ||
1311 | /* parse and validate message. */ | 1372 | /* parse and validate message. */ |
1312 | msize = ntohs (message->size); | 1373 | msize = ntohs (message->size); |
@@ -1328,7 +1389,7 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1328 | GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity))) | 1389 | GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity))) |
1329 | { | 1390 | { |
1330 | GNUNET_break_op (0); | 1391 | GNUNET_break_op (0); |
1331 | return GNUNET_YES; | 1392 | return GNUNET_YES; /*TODO: Why do we send GNUNET_YES here? */ |
1332 | } | 1393 | } |
1333 | 1394 | ||
1334 | 1395 | ||
@@ -1343,17 +1404,19 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1343 | { | 1404 | { |
1344 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity(&(trail_setup->current_destination),&my_identity))) | 1405 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity(&(trail_setup->current_destination),&my_identity))) |
1345 | { | 1406 | { |
1346 | next_hop = find_successor(&(trail_setup->destination_finger),&(trail_setup->current_destination),&(peer_type)); | 1407 | next_hop = find_successor((trail_setup->destination_finger),&(trail_setup->current_destination),&(peer_type)); |
1347 | } | 1408 | } |
1348 | else | 1409 | else |
1349 | return GNUNET_SYSERR; | 1410 | return GNUNET_SYSERR; /*TODO: Should we handle this case differently? */ |
1350 | } | 1411 | } |
1351 | else | 1412 | else if(peer_type == FINGER) |
1352 | { | 1413 | { |
1353 | if(0 != (GNUNET_CRYPTO_cmp_peer_identity(&(trail_setup->current_destination),&my_identity))) | 1414 | if(0 != (GNUNET_CRYPTO_cmp_peer_identity(&(trail_setup->current_destination),&my_identity))) |
1354 | { | 1415 | { |
1355 | /* I am part of trail. */ | 1416 | /* I am part of trail. |
1356 | next_hop = GDS_ROUTING_search(&(trail_setup->source_peer),&(trail_setup->destination_finger)); | 1417 | SUPU: So, I should ask for next hop to reach the current_destination which is the finger |
1418 | for which this packet has been sent. */ | ||
1419 | next_hop = GDS_ROUTING_search(&(trail_setup->source_peer),&(trail_setup->current_destination)); | ||
1357 | 1420 | ||
1358 | /*TODO: | 1421 | /*TODO: |
1359 | call find_successor and compare the two peer ids | 1422 | call find_successor and compare the two peer ids |
@@ -1361,49 +1424,54 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1361 | } | 1424 | } |
1362 | else | 1425 | else |
1363 | { | 1426 | { |
1364 | /* I am the current_destination finger */ | 1427 | /* I am the current_destination finger |
1365 | next_hop = find_successor(&(trail_setup->destination_finger),&(trail_setup->current_destination),&(peer_type)); | 1428 | FIXME: Why are we sending current_destination to find_successor. |
1429 | In this case, is it safe to assume current_Destination = my_identity. | ||
1430 | I guess we are sending current_destination so that we update it with new | ||
1431 | current_destination, if could either me, friend or finger.*/ | ||
1432 | next_hop = find_successor((trail_setup->destination_finger),&(trail_setup->current_destination),&(peer_type)); | ||
1366 | } | 1433 | } |
1367 | } | 1434 | } |
1368 | 1435 | ||
1369 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | 1436 | /* If you are the next hop */ |
1370 | 1437 | if(peer_type == MY_ID) | |
1371 | /* Add yourself to list of peers that trail setup message have traversed so far | ||
1372 | and increment trail length. */ | ||
1373 | struct GNUNET_PeerIdentity *peer_list; | ||
1374 | peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * (trail_length + 1)); | ||
1375 | memcpy(peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); | ||
1376 | memcpy(&peer_list[trail_length], next_hop, sizeof (struct GNUNET_PeerIdentity)); | ||
1377 | trail_length++; | ||
1378 | |||
1379 | /* Check if you are next hop, if yes then you have reached the final destination. */ | ||
1380 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity(next_hop,&my_identity))) | ||
1381 | { | 1438 | { |
1382 | /* FIXME: Trail length should be const. */ | 1439 | /* FIXME: Verify if its allowed here to definer peer_list and define it |
1383 | if(trail_length >= 1) | 1440 | again in the next block below? */ |
1384 | { | 1441 | struct GNUNET_PeerIdentity *peer_list; |
1442 | peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * (trail_length)); | ||
1443 | memcpy(peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); | ||
1385 | current_trail_index = trail_length - 2; | 1444 | current_trail_index = trail_length - 2; |
1386 | next_peer = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); //FIXME: Do we need to allocate the memory? | 1445 | next_peer = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); //FIXME: Do we need to allocate the memory? |
1387 | memcpy(next_peer, &peer_list[current_trail_index], sizeof (struct GNUNET_PeerIdentity)); | 1446 | memcpy(next_peer, &peer_list[current_trail_index], sizeof (struct GNUNET_PeerIdentity)); |
1388 | 1447 | ||
1389 | new_target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_peer); | 1448 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_peer); |
1390 | 1449 | ||
1391 | /* FIXME: It does not find a friend. Could be possible error in find_successor | 1450 | /* FIXME: It does not find a friend. Could be possible error in find_successor |
1392 | function. Change the logic in find_successor and change it again. */ | 1451 | function. Change the logic in find_successor and change it again. */ |
1393 | /*if(GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(friend_peermap,new_target_friend)) | 1452 | |
1394 | { | 1453 | /* FIXME: Here as destination_finger is 64 bit instead of struct |
1395 | 1454 | GNUNET_PeerIdentity, but you need destination_peer id. If you calling the | |
1396 | return GNUNET_SYSERR; | 1455 | function handle_Trail_setup_result from here, it means you are the |
1397 | } | 1456 | destination. So, you can send your own identity. */ |
1398 | */ | ||
1399 | GDS_NEIGHBOURS_handle_trail_setup_result(&(trail_setup->source_peer), | 1457 | GDS_NEIGHBOURS_handle_trail_setup_result(&(trail_setup->source_peer), |
1400 | &(trail_setup->destination_finger), | 1458 | &(my_identity), |
1401 | new_target_friend, trail_length, | 1459 | target_friend, trail_length, |
1402 | peer_list,current_trail_index); | 1460 | peer_list,current_trail_index); |
1403 | } | 1461 | |
1404 | return GNUNET_YES; | 1462 | return GNUNET_YES; |
1405 | } | 1463 | } |
1406 | 1464 | ||
1465 | /* Add next_hop to list of peers that trail setup message have traversed so far | ||
1466 | and increment trail length. */ | ||
1467 | struct GNUNET_PeerIdentity *peer_list; | ||
1468 | peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * (trail_length + 1)); | ||
1469 | memcpy(peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); | ||
1470 | memcpy(&peer_list[trail_length], next_hop, sizeof (struct GNUNET_PeerIdentity)); | ||
1471 | trail_length++; | ||
1472 | |||
1473 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | ||
1474 | |||
1407 | if(peer_type == FINGER) | 1475 | if(peer_type == FINGER) |
1408 | { | 1476 | { |
1409 | GDS_ROUTING_add(&(trail_setup->source_peer),&(trail_setup->current_destination),next_hop); | 1477 | GDS_ROUTING_add(&(trail_setup->source_peer),&(trail_setup->current_destination),next_hop); |
@@ -1420,6 +1488,9 @@ return GNUNET_YES; | |||
1420 | 1488 | ||
1421 | /** | 1489 | /** |
1422 | * FIXME : Add interval field. | 1490 | * FIXME : Add interval field. |
1491 | * When adding successor or predeccsor, update a field to | ||
1492 | * specify that this entry is not a finger but immediate | ||
1493 | * successor or predeccesor. | ||
1423 | * Add an entry in finger table. | 1494 | * Add an entry in finger table. |
1424 | * @param finger Finger to be added to finger table | 1495 | * @param finger Finger to be added to finger table |
1425 | * @param peer_list peers this request has traversed so far | 1496 | * @param peer_list peers this request has traversed so far |
@@ -1432,9 +1503,20 @@ void finger_table_add(struct GNUNET_PeerIdentity *finger, | |||
1432 | { | 1503 | { |
1433 | struct FingerInfo *finger_entry; | 1504 | struct FingerInfo *finger_entry; |
1434 | finger_entry = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity)); | 1505 | finger_entry = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity)); |
1435 | memcpy(&(finger_entry->id), finger, sizeof(struct GNUNET_PeerIdentity)); | 1506 | memcpy(&(finger_entry->finger_identity), finger, sizeof(struct GNUNET_PeerIdentity)); |
1436 | memcpy(&(finger_entry->trail_peer_list), peer_list, sizeof(struct GNUNET_PeerIdentity) | 1507 | memcpy(&(finger_entry->trail_peer_list), peer_list, sizeof(struct GNUNET_PeerIdentity) |
1437 | * trail_length); | 1508 | * trail_length); |
1509 | /*FIXME: When you add an entry into your finger table, then | ||
1510 | you should add it in sorted way. Also, once sorted update the finger table | ||
1511 | entry. As we will be using sorting and updating the interval in finger and friend | ||
1512 | table and also in find_successor, we need this functionality see if you can | ||
1513 | define a common function which can be used in all the three functions. | ||
1514 | Also, you should then insert that entry into your finger_peermap. | ||
1515 | It seems to be too much of complexity but I need a working copy but i will | ||
1516 | ask bart first. */ | ||
1517 | |||
1518 | if (1 == GNUNET_CONTAINER_multipeermap_size (finger_peermap)) | ||
1519 | verify_immediate_successor = GNUNET_SCHEDULER_add_now (&stabilize, NULL); | ||
1438 | } | 1520 | } |
1439 | 1521 | ||
1440 | 1522 | ||
@@ -1443,7 +1525,7 @@ void finger_table_add(struct GNUNET_PeerIdentity *finger, | |||
1443 | * @param cls closure | 1525 | * @param cls closure |
1444 | * @param message message | 1526 | * @param message message |
1445 | * @param peer peer identity this notification is about | 1527 | * @param peer peer identity this notification is about |
1446 | * @return #GNUNET_YES | 1528 | * @return GNUNET_OK on success, GNUNET_SYSERR on error |
1447 | */ | 1529 | */ |
1448 | static int | 1530 | static int |
1449 | handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *peer, | 1531 | handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *peer, |
@@ -1507,6 +1589,61 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p | |||
1507 | 1589 | ||
1508 | 1590 | ||
1509 | /** | 1591 | /** |
1592 | * Core handle for p2p verify successor messages. | ||
1593 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | ||
1594 | */ | ||
1595 | static int | ||
1596 | handle_dht_p2p_verify_successor() | ||
1597 | { | ||
1598 | /* | ||
1599 | * In this function you have received the message verify successor, | ||
1600 | * Now, either you are the destination or just part of the trail. | ||
1601 | * As we already know the whole path find out the next destination | ||
1602 | * and pass the packet forward. | ||
1603 | * If you are the final destination, check who is your predecessor. | ||
1604 | * and send your predecessor back to calling function. | ||
1605 | * FIXME: Should we have a different handler function for it. | ||
1606 | */ | ||
1607 | return GNUNET_YES; | ||
1608 | } | ||
1609 | |||
1610 | /** | ||
1611 | * Core handle for p2p notify successor messages. | ||
1612 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | ||
1613 | */ | ||
1614 | static int | ||
1615 | handle_dht_p2p_notify_successor() | ||
1616 | { | ||
1617 | /* | ||
1618 | * So, if you are the destination you should update your | ||
1619 | * predecessor field with peer id of source peer of this message. | ||
1620 | * If you are not the destination peer, then just check your routing | ||
1621 | * table and pass on the message. | ||
1622 | */ | ||
1623 | return GNUNET_YES; | ||
1624 | } | ||
1625 | |||
1626 | /** | ||
1627 | * Core handle for p2p verify successor result messages. | ||
1628 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | ||
1629 | */ | ||
1630 | static int | ||
1631 | handle_dht_p2p_verify_successor_result() | ||
1632 | { | ||
1633 | /* | ||
1634 | * In this function you have received the message verify successor result, | ||
1635 | If you are not the destination, just pass this message forward | ||
1636 | * if you are destination, | ||
1637 | * then check if immediate predecessor of this peer is you or someone else. | ||
1638 | * If its you, then don't do anything. | ||
1639 | * If its some one else, then call notify method to let your new successor | ||
1640 | * know that you are its predecessor. | ||
1641 | */ | ||
1642 | return GNUNET_YES; | ||
1643 | } | ||
1644 | |||
1645 | |||
1646 | /** | ||
1510 | * Initialize neighbours subsystem. | 1647 | * Initialize neighbours subsystem. |
1511 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 1648 | * @return GNUNET_OK on success, GNUNET_SYSERR on error |
1512 | */ | 1649 | */ |
@@ -1516,13 +1653,15 @@ GDS_NEIGHBOURS_init() | |||
1516 | static struct GNUNET_CORE_MessageHandler core_handlers[] = { | 1653 | static struct GNUNET_CORE_MessageHandler core_handlers[] = { |
1517 | {&handle_dht_p2p_get, GNUNET_MESSAGE_TYPE_DHT_P2P_GET, 0}, | 1654 | {&handle_dht_p2p_get, GNUNET_MESSAGE_TYPE_DHT_P2P_GET, 0}, |
1518 | {&handle_dht_p2p_put, GNUNET_MESSAGE_TYPE_DHT_P2P_PUT, 0}, | 1655 | {&handle_dht_p2p_put, GNUNET_MESSAGE_TYPE_DHT_P2P_PUT, 0}, |
1519 | {&handle_dht_p2p_result, GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT, 0}, | ||
1520 | {&handle_dht_p2p_trail_setup, GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP, 0}, | 1656 | {&handle_dht_p2p_trail_setup, GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP, 0}, |
1521 | {&handle_dht_p2p_trail_setup_result, GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP_RESULT, 0}, | 1657 | {&handle_dht_p2p_trail_setup_result, GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP_RESULT, 0}, |
1658 | {&handle_dht_p2p_verify_successor, GNUNET_MESSAGE_TYPE_DHT_P2P_VERIFY_SUCCESSOR, 0}, | ||
1659 | {&handle_dht_p2p_notify_successor, GNUNET_MESSAGE_TYPE_DHT_P2P_NOTIFY_SUCCESSOR, 0}, | ||
1660 | {&handle_dht_p2p_verify_successor_result, GNUNET_MESSAGE_TYPE_DHT_P2P_VERIFY_SUCCESSOR_RESULT, 0}, | ||
1522 | {NULL, 0, 0} | 1661 | {NULL, 0, 0} |
1523 | }; | 1662 | }; |
1524 | 1663 | ||
1525 | /*ASK: What is ATS? Why do we need it? */ | 1664 | /*TODO: What is ATS? Why do we need it? */ |
1526 | atsAPI = GNUNET_ATS_performance_init (GDS_cfg, NULL, NULL); | 1665 | atsAPI = GNUNET_ATS_performance_init (GDS_cfg, NULL, NULL); |
1527 | core_api = | 1666 | core_api = |
1528 | GNUNET_CORE_connect (GDS_cfg, NULL, &core_init, &handle_core_connect, | 1667 | GNUNET_CORE_connect (GDS_cfg, NULL, &core_init, &handle_core_connect, |
@@ -1532,7 +1671,7 @@ GDS_NEIGHBOURS_init() | |||
1532 | return GNUNET_SYSERR; | 1671 | return GNUNET_SYSERR; |
1533 | 1672 | ||
1534 | friend_peermap = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_NO); | 1673 | friend_peermap = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_NO); |
1535 | finger_peermap = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_NO); | 1674 | finger_peermap = GNUNET_CONTAINER_multipeermap_create (MAX_FINGERS, GNUNET_NO); |
1536 | 1675 | ||
1537 | return GNUNET_OK; | 1676 | return GNUNET_OK; |
1538 | } | 1677 | } |
@@ -1567,6 +1706,15 @@ GDS_NEIGHBOURS_done () | |||
1567 | GNUNET_SCHEDULER_cancel (find_finger_trail_task); | 1706 | GNUNET_SCHEDULER_cancel (find_finger_trail_task); |
1568 | find_finger_trail_task = GNUNET_SCHEDULER_NO_TASK; | 1707 | find_finger_trail_task = GNUNET_SCHEDULER_NO_TASK; |
1569 | } | 1708 | } |
1709 | |||
1710 | /* FIXME: fix_fingers will also be a task like this. | ||
1711 | Add it later. */ | ||
1712 | if (GNUNET_SCHEDULER_NO_TASK != verify_immediate_successor) | ||
1713 | { | ||
1714 | GNUNET_SCHEDULER_cancel (verify_immediate_successor); | ||
1715 | verify_immediate_successor = GNUNET_SCHEDULER_NO_TASK; | ||
1716 | } | ||
1717 | |||
1570 | } | 1718 | } |
1571 | 1719 | ||
1572 | 1720 | ||
diff --git a/src/dht/gnunet-service-xdht_neighbours.h b/src/dht/gnunet-service-xdht_neighbours.h index 4ee1f4f37..0b6eaa6af 100644 --- a/src/dht/gnunet-service-xdht_neighbours.h +++ b/src/dht/gnunet-service-xdht_neighbours.h | |||
@@ -92,35 +92,6 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, | |||
92 | 92 | ||
93 | 93 | ||
94 | /** | 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 | */ | ||
110 | void | ||
111 | GDS_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 | |||
123 | /** | ||
124 | * Initialize neighbours subsystem. | 95 | * Initialize neighbours subsystem. |
125 | * | 96 | * |
126 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 97 | * @return GNUNET_OK on success, GNUNET_SYSERR on error |