diff options
author | Supriti Singh <supritisingh08@gmail.com> | 2014-02-07 00:14:43 +0000 |
---|---|---|
committer | Supriti Singh <supritisingh08@gmail.com> | 2014-02-07 00:14:43 +0000 |
commit | ba430ff1fbce68a8940e448f0e0fe7266fa638b5 (patch) | |
tree | 88b3f2a2ded45cb4e0a06bbff8c90582a30f53e6 /src/dht | |
parent | d76a8b89e6ff8ab39f65e75ab4ff0c6f21a63a5f (diff) | |
download | gnunet-ba430ff1fbce68a8940e448f0e0fe7266fa638b5.tar.gz gnunet-ba430ff1fbce68a8940e448f0e0fe7266fa638b5.zip |
Computing finger identity using libgcrypt functions.
Diffstat (limited to 'src/dht')
-rw-r--r-- | src/dht/gnunet-service-xdht_neighbours.c | 66 |
1 files changed, 22 insertions, 44 deletions
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c index fa7aeb981..020676a9b 100644 --- a/src/dht/gnunet-service-xdht_neighbours.c +++ b/src/dht/gnunet-service-xdht_neighbours.c | |||
@@ -485,7 +485,7 @@ static struct GNUNET_CORE_Handle *core_api; | |||
485 | /** | 485 | /** |
486 | * The current finger index that we have found trail to. | 486 | * The current finger index that we have found trail to. |
487 | */ | 487 | */ |
488 | static unsigned int current_finger_id; | 488 | static unsigned int current_finger_index; |
489 | 489 | ||
490 | 490 | ||
491 | /** | 491 | /** |
@@ -777,56 +777,29 @@ get_random_friend() | |||
777 | 777 | ||
778 | 778 | ||
779 | /** | 779 | /** |
780 | * TODO: Check the logic of using current_finger_id again. | 780 | * Find finger id to which we want to setup the trail |
781 | * This code is not correct. I need to check the pointers and | 781 | * @return finger id |
782 | * correct use of memcpy and all the data type. | ||
783 | * Use Chord formula finger[i]=(n+2^(i-1))mod m, | ||
784 | * where i = current finger map index - max. 256 bits | ||
785 | * n = own peer identity - 256 bits | ||
786 | * m = number of bits in peer id - 256 bits | ||
787 | * @return finger_peer_id for which we have to find the trail through network. | ||
788 | */ | 782 | */ |
789 | static | 783 | static |
790 | struct GNUNET_PeerIdentity * | 784 | struct GNUNET_PeerIdentity * |
791 | finger_id_to_search() | 785 | compute_finger_identity() |
792 | { | 786 | { |
793 | struct GNUNET_PeerIdentity *finger_peer_id; | 787 | struct GNUNET_PeerIdentity *finger_identity; |
794 | uint32_t peer_id; | ||
795 | uint32_t finger_id; | ||
796 | 788 | ||
797 | finger_peer_id = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 789 | finger_identity = GNUNET_CRYPTO_compute_finger(&my_identity,current_finger_index); |
798 | |||
799 | /* Copy unsigned char array into peer_id. */ | ||
800 | if (0 == memcpy(&peer_id,&my_identity.public_key.q_y,sizeof(uint32_t))) | ||
801 | return NULL; | ||
802 | |||
803 | /* We do all the arithmetic operation on peer_id to get finger_id*/ | ||
804 | finger_id = (uint32_t)(peer_id + pow(2,current_finger_id)) % MAX_FINGERS; | ||
805 | |||
806 | /* Copy the finger_id to finger_peer_id. */ | ||
807 | if (0 == memcpy(&finger_peer_id->public_key.q_y,&finger_id,sizeof(uint32_t))) | ||
808 | return NULL; | ||
809 | 790 | ||
810 | 791 | current_finger_index = (current_finger_index+1) % MAX_FINGERS; | |
811 | /* FIXME: Here I increment the index so that next time when we enter this | ||
812 | function, then we begin the search from current index. Is it possible | ||
813 | to set this value when we add the finger id to our finger table. No, because | ||
814 | even there is a call going on to find the finger, we can start another call | ||
815 | to search another peer. */ | ||
816 | current_finger_id = (current_finger_id+1) % MAX_FINGERS; | ||
817 | 792 | ||
818 | /* Check if you already have an entry in finger_peers for this finger_id. | 793 | /* Check if you already have an entry in finger_peers for this finger_id. |
819 | If yes then again look for a new finger_id. */ | 794 | If yes then again look for a new finger_id. |
820 | /*if(NULL != GNUNET_CONTAINER_multipeermap_get(finger_peers,finger_peer_id)) | 795 | FIXME: Should we return NULL here? |
796 | if(NULL != GNUNET_CONTAINER_multipeermap_get(finger_peers,finger_peer_id)) | ||
821 | { | 797 | { |
822 | 798 | finger_peer_id = compute_finger_identity(); | |
823 | finger_peer_id = finger_id_to_search(); | 799 | }*/ |
824 | } | 800 | return finger_identity; |
825 | */ | ||
826 | return finger_peer_id; | ||
827 | } | 801 | } |
828 | 802 | ||
829 | |||
830 | /** | 803 | /** |
831 | * TODO: Implement after testing friend/finger map. | 804 | * TODO: Implement after testing friend/finger map. |
832 | * TODO: Handle the case when we already have a trail to our predecessor in | 805 | * TODO: Handle the case when we already have a trail to our predecessor in |
@@ -838,7 +811,7 @@ finger_id_to_search() | |||
838 | * @return peer identity of immediate predecessor. | 811 | * @return peer identity of immediate predecessor. |
839 | */ | 812 | */ |
840 | static | 813 | static |
841 | struct GNUNET_PeerIdentity* | 814 | struct GNUNET_PeerIdentity * |
842 | find_immediate_predecessor() | 815 | find_immediate_predecessor() |
843 | { | 816 | { |
844 | /* Using your own peer identity, calculate your predecessor | 817 | /* Using your own peer identity, calculate your predecessor |
@@ -880,7 +853,7 @@ send_find_finger_trail_message (void *cls, | |||
880 | else | 853 | else |
881 | { | 854 | { |
882 | /* Find the finger_peer_id for which we want to setup the trail */ | 855 | /* Find the finger_peer_id for which we want to setup the trail */ |
883 | finger_peer_id = finger_id_to_search(); | 856 | finger_peer_id = compute_finger_identity(); |
884 | } | 857 | } |
885 | 858 | ||
886 | /* Choose a friend randomly from your friend_peers map. */ | 859 | /* Choose a friend randomly from your friend_peers map. */ |
@@ -897,7 +870,7 @@ send_find_finger_trail_message (void *cls, | |||
897 | DHT_MINIMUM_FIND_FINGER_TRAIL_INTERVAL.rel_value_us + | 870 | DHT_MINIMUM_FIND_FINGER_TRAIL_INTERVAL.rel_value_us + |
898 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 871 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
899 | DHT_MAXIMUM_FIND_FINGER_TRAIL_INTERVAL.rel_value_us / | 872 | DHT_MAXIMUM_FIND_FINGER_TRAIL_INTERVAL.rel_value_us / |
900 | (current_finger_id + 1)); | 873 | (current_finger_index + 1)); |
901 | 874 | ||
902 | find_finger_trail_task = | 875 | find_finger_trail_task = |
903 | GNUNET_SCHEDULER_add_delayed (next_send_time, &send_find_finger_trail_message, | 876 | GNUNET_SCHEDULER_add_delayed (next_send_time, &send_find_finger_trail_message, |
@@ -1059,6 +1032,11 @@ handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1059 | * FIXME:1. Check if current_destination field is set correctly. | 1032 | * FIXME:1. Check if current_destination field is set correctly. |
1060 | * 2. Is it correct to use GNUNET_CMP_PEER_IDENTITY to find out the successor | 1033 | * 2. Is it correct to use GNUNET_CMP_PEER_IDENTITY to find out the successor |
1061 | * of a finger. | 1034 | * of a finger. |
1035 | * 3. We should check the interval of the keys for which a peer is responsible | ||
1036 | * when we are looking to find the correct peer to store a key. But | ||
1037 | * --> How do we maintain this interval? | ||
1038 | * --> Should we check this interval when we are looking for trail to a finger | ||
1039 | * as in this function? | ||
1062 | * The code flow seems to be very large. Could do better. | 1040 | * The code flow seems to be very large. Could do better. |
1063 | * @param destination peer id's predecessor we are looking for. | 1041 | * @param destination peer id's predecessor we are looking for. |
1064 | * @return | 1042 | * @return |