diff options
author | Supriti Singh <supritisingh08@gmail.com> | 2014-08-05 13:24:53 +0000 |
---|---|---|
committer | Supriti Singh <supritisingh08@gmail.com> | 2014-08-05 13:24:53 +0000 |
commit | b046370d179073ed9a3a5ee2eb61269a5178767a (patch) | |
tree | 01c2358eaffdc10abcd15b9ad723b2196c2ce304 /src | |
parent | 81e6e3f1dab7bfd3981b3cb72d18f3cc98a87906 (diff) | |
download | gnunet-b046370d179073ed9a3a5ee2eb61269a5178767a.tar.gz gnunet-b046370d179073ed9a3a5ee2eb61269a5178767a.zip |
Exponential backoff for find_finger_trail_task
Diffstat (limited to 'src')
-rw-r--r-- | src/dht/gnunet-service-xdht_neighbours.c | 117 | ||||
-rw-r--r-- | src/dht/gnunet-service-xdht_routing.c | 4 |
2 files changed, 90 insertions, 31 deletions
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c index 90e89af08..d5139ca73 100644 --- a/src/dht/gnunet-service-xdht_neighbours.c +++ b/src/dht/gnunet-service-xdht_neighbours.c | |||
@@ -1514,12 +1514,9 @@ GDS_NEIGHBOURS_send_add_trail (struct GNUNET_PeerIdentity source_peer, | |||
1514 | adm->source_peer = source_peer; | 1514 | adm->source_peer = source_peer; |
1515 | adm->destination_peer = destination_peer; | 1515 | adm->destination_peer = destination_peer; |
1516 | adm->trail_id = trail_id; | 1516 | adm->trail_id = trail_id; |
1517 | 1517 | peer_list = (struct GNUNET_PeerIdentity *)&adm[1]; | |
1518 | if (trail_length > 0) | 1518 | memcpy (peer_list, trail, sizeof (struct GNUNET_PeerIdentity) * trail_length); |
1519 | { | 1519 | |
1520 | peer_list = (struct GNUNET_PeerIdentity *)&adm[1]; | ||
1521 | memcpy (peer_list, trail, sizeof (struct GNUNET_PeerIdentity) * trail_length); | ||
1522 | } | ||
1523 | /* Send the message to chosen friend. */ | 1520 | /* Send the message to chosen friend. */ |
1524 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); | 1521 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); |
1525 | target_friend->pending_count++; | 1522 | target_friend->pending_count++; |
@@ -1590,16 +1587,14 @@ search_my_index (const struct GNUNET_PeerIdentity *trail, | |||
1590 | int trail_length) | 1587 | int trail_length) |
1591 | { | 1588 | { |
1592 | int i; | 1589 | int i; |
1593 | int lowest_index = -1; | ||
1594 | 1590 | ||
1595 | for (i = 0; i < trail_length; i++) | 1591 | for (i = 0; i < trail_length; i++) |
1596 | { | 1592 | { |
1597 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &trail[i])) | 1593 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &trail[i])) |
1598 | //lowest_index = i; | ||
1599 | return i; | 1594 | return i; |
1600 | } | 1595 | } |
1601 | 1596 | ||
1602 | return lowest_index; | 1597 | return -1; |
1603 | } | 1598 | } |
1604 | 1599 | ||
1605 | 1600 | ||
@@ -2491,6 +2486,7 @@ compute_finger_identity_value (unsigned int finger_index) | |||
2491 | } | 2486 | } |
2492 | } | 2487 | } |
2493 | 2488 | ||
2489 | static struct GNUNET_TIME_Relative next_send_time; | ||
2494 | 2490 | ||
2495 | /* | 2491 | /* |
2496 | * Choose a random friend. Calculate the next finger identity to search,from | 2492 | * Choose a random friend. Calculate the next finger identity to search,from |
@@ -2505,19 +2501,16 @@ send_find_finger_trail_message (void *cls, | |||
2505 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 2501 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
2506 | { | 2502 | { |
2507 | struct FriendInfo *target_friend; | 2503 | struct FriendInfo *target_friend; |
2508 | struct GNUNET_TIME_Relative next_send_time; | 2504 | //struct GNUNET_TIME_Relative next_send_time; |
2509 | struct GNUNET_HashCode trail_id; | 2505 | struct GNUNET_HashCode trail_id; |
2510 | struct GNUNET_HashCode intermediate_trail_id; | 2506 | struct GNUNET_HashCode intermediate_trail_id; |
2511 | unsigned int is_predecessor; | 2507 | unsigned int is_predecessor; |
2512 | uint64_t finger_id_value; | 2508 | uint64_t finger_id_value; |
2513 | 2509 | ||
2514 | /* Schedule another send_find_finger_trail_message task. */ | 2510 | /* Schedule another send_find_finger_trail_message task. */ |
2515 | next_send_time.rel_value_us = | ||
2516 | DHT_FIND_FINGER_TRAIL_INTERVAL.rel_value_us + | ||
2517 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
2518 | DHT_FIND_FINGER_TRAIL_INTERVAL.rel_value_us); | ||
2519 | find_finger_trail_task = | 2511 | find_finger_trail_task = |
2520 | GNUNET_SCHEDULER_add_delayed (next_send_time, &send_find_finger_trail_message, | 2512 | GNUNET_SCHEDULER_add_delayed (next_send_time, |
2513 | &send_find_finger_trail_message, | ||
2521 | NULL); | 2514 | NULL); |
2522 | 2515 | ||
2523 | /* No space in my routing table. (Source and destination peers also store entries | 2516 | /* No space in my routing table. (Source and destination peers also store entries |
@@ -3066,7 +3059,6 @@ scan_and_compress_trail (struct GNUNET_PeerIdentity finger_identity, | |||
3066 | i++; | 3059 | i++; |
3067 | } | 3060 | } |
3068 | *new_trail_length = j+1; | 3061 | *new_trail_length = j+1; |
3069 | GNUNET_assert((j+1) == (trail_length - 1)); //FIXME: remove it afterwards. | ||
3070 | return new_trail; | 3062 | return new_trail; |
3071 | } | 3063 | } |
3072 | } | 3064 | } |
@@ -3375,12 +3367,16 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity, | |||
3375 | &successor->finger_identity)) | 3367 | &successor->finger_identity)) |
3376 | { | 3368 | { |
3377 | current_search_finger_index = 0; | 3369 | current_search_finger_index = 0; |
3370 | /* We slow down the find_finger_trail_task as we have completed the circle. */ | ||
3371 | next_send_time = GNUNET_TIME_STD_BACKOFF(next_send_time); | ||
3372 | |||
3378 | return; | 3373 | return; |
3379 | } | 3374 | } |
3380 | struct FingerInfo *prev_finger; | 3375 | |
3381 | prev_finger = &finger_table[finger_table_index - 1]; | 3376 | struct FingerInfo prev_finger; |
3377 | prev_finger = finger_table[finger_table_index - 1]; | ||
3382 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, | 3378 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, |
3383 | &prev_finger->finger_identity)) | 3379 | &prev_finger.finger_identity)) |
3384 | { | 3380 | { |
3385 | current_search_finger_index--; | 3381 | current_search_finger_index--; |
3386 | return; | 3382 | return; |
@@ -3904,6 +3900,41 @@ get_local_best_known_next_hop (uint64_t final_dest_finger_val, | |||
3904 | return peer; | 3900 | return peer; |
3905 | } | 3901 | } |
3906 | 3902 | ||
3903 | #if 0 | ||
3904 | /** | ||
3905 | * Check if peer is already present in the trail. | ||
3906 | * @param peer | ||
3907 | * @param trail | ||
3908 | * @param trail_length | ||
3909 | * @return | ||
3910 | */ | ||
3911 | static struct GNUNET_PeerIdentity * | ||
3912 | check_for_duplicate_entries (const struct GNUNET_PeerIdentity *trail, | ||
3913 | unsigned int trail_length, | ||
3914 | unsigned int *updated_trail_length) | ||
3915 | { | ||
3916 | struct GNUNET_PeerIdentity *updated_trail; | ||
3917 | unsigned int i; | ||
3918 | unsigned int j; | ||
3919 | |||
3920 | /* It may happen that there are more than one peer present twice. | ||
3921 | but we don't want to*/ | ||
3922 | for(i = 0;i < trail_length; i++) | ||
3923 | { | ||
3924 | for(j = i+1; j < trail_length; j++) | ||
3925 | { | ||
3926 | if(0 != GNUNET_CRYPTO_cmp_peer_identity (&trail[i],&trail[j])) | ||
3927 | continue; | ||
3928 | |||
3929 | /* If you found a duplicate entry in the trail, then you should | ||
3930 | * have the entry at i should point to next of entry stored at j*/ | ||
3931 | |||
3932 | /* In case j = (trail_length - 1), then it should NULL. */ | ||
3933 | |||
3934 | } | ||
3935 | } | ||
3936 | } | ||
3937 | #endif | ||
3907 | 3938 | ||
3908 | /* | 3939 | /* |
3909 | * Core handle for PeerTrailSetupMessage. | 3940 | * Core handle for PeerTrailSetupMessage. |
@@ -3926,6 +3957,7 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3926 | struct GNUNET_HashCode trail_id; | 3957 | struct GNUNET_HashCode trail_id; |
3927 | unsigned int is_predecessor; | 3958 | unsigned int is_predecessor; |
3928 | uint32_t trail_length; | 3959 | uint32_t trail_length; |
3960 | unsigned int i; | ||
3929 | size_t msize; | 3961 | size_t msize; |
3930 | 3962 | ||
3931 | msize = ntohs (message->size); | 3963 | msize = ntohs (message->size); |
@@ -3954,6 +3986,14 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3954 | is_predecessor = ntohl (trail_setup->is_predecessor); | 3986 | is_predecessor = ntohl (trail_setup->is_predecessor); |
3955 | intermediate_trail_id = trail_setup->intermediate_trail_id; | 3987 | intermediate_trail_id = trail_setup->intermediate_trail_id; |
3956 | 3988 | ||
3989 | /* Did the friend insert its ID in the trail list? */ | ||
3990 | if (trail_length > 0 && | ||
3991 | 0 != memcmp (&trail_peer_list[trail_length-1], peer, sizeof (*peer))) | ||
3992 | { | ||
3993 | GNUNET_break_op (0); | ||
3994 | return GNUNET_SYSERR; | ||
3995 | } | ||
3996 | |||
3957 | /* If I was the source and got the message back, then set trail length to 0.*/ | 3997 | /* If I was the source and got the message back, then set trail length to 0.*/ |
3958 | if (0 == GNUNET_CRYPTO_cmp_peer_identity(&my_identity, &source)) | 3998 | if (0 == GNUNET_CRYPTO_cmp_peer_identity(&my_identity, &source)) |
3959 | { | 3999 | { |
@@ -3971,14 +4011,21 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3971 | trail_length = 0; | 4011 | trail_length = 0; |
3972 | } | 4012 | } |
3973 | 4013 | ||
3974 | /* Did the friend insert its ID in the trail list? */ | 4014 | /* Check if you are present in the trail seen so far? */ |
3975 | if (trail_length > 0 && | 4015 | if(trail_length > 0) |
3976 | 0 != memcmp (&trail_peer_list[trail_length-1], peer, sizeof (*peer))) | ||
3977 | { | 4016 | { |
3978 | GNUNET_break_op (0); | 4017 | for (i = 0; i < trail_length ; i++) |
3979 | return GNUNET_SYSERR; | 4018 | { |
4019 | if(0 == GNUNET_CRYPTO_cmp_peer_identity(&trail_peer_list[i],&my_identity)) | ||
4020 | { | ||
4021 | //Here if you already were present in the trail. then you | ||
4022 | // shoudl trail length to i + 1 | ||
4023 | trail_length = i+1; | ||
4024 | break; | ||
4025 | } | ||
4026 | } | ||
3980 | } | 4027 | } |
3981 | 4028 | ||
3982 | /* Is my routing table full? */ | 4029 | /* Is my routing table full? */ |
3983 | if (GNUNET_YES == GDS_ROUTING_threshold_reached()) | 4030 | if (GNUNET_YES == GDS_ROUTING_threshold_reached()) |
3984 | { | 4031 | { |
@@ -4208,6 +4255,9 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p | |||
4208 | } | 4255 | } |
4209 | #endif | 4256 | #endif |
4210 | 4257 | ||
4258 | /*TODO:URGENT Check if I am already present in the trail. If yes then its an error, | ||
4259 | as in trail setup we ensure that it should never happen. */ | ||
4260 | |||
4211 | /* Am I the one who initiated the query? */ | 4261 | /* Am I the one who initiated the query? */ |
4212 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&querying_peer, &my_identity))) | 4262 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&querying_peer, &my_identity))) |
4213 | { | 4263 | { |
@@ -4646,9 +4696,9 @@ handle_dht_p2p_verify_successor(void *cls, | |||
4646 | &source_peer))) | 4696 | &source_peer))) |
4647 | { | 4697 | { |
4648 | trail_src_to_curr_pred = get_trail_src_to_curr_pred (source_peer, | 4698 | trail_src_to_curr_pred = get_trail_src_to_curr_pred (source_peer, |
4649 | trail, | 4699 | trail, |
4650 | trail_length, | 4700 | trail_length, |
4651 | &trail_src_to_curr_pred_len); | 4701 | &trail_src_to_curr_pred_len); |
4652 | } | 4702 | } |
4653 | else | 4703 | else |
4654 | { | 4704 | { |
@@ -4819,6 +4869,8 @@ compare_and_update_successor (struct GNUNET_PeerIdentity curr_succ, | |||
4819 | /* Remove the existing successor. */ | 4869 | /* Remove the existing successor. */ |
4820 | remove_existing_finger (current_successor, 0); | 4870 | remove_existing_finger (current_successor, 0); |
4821 | 4871 | ||
4872 | /* TODO URGENT: Check if any peer is present more than once, if yes then shorten | ||
4873 | the trail. before sending it across the network. */ | ||
4822 | /* Generate a new trail id to reach to your new successor. */ | 4874 | /* Generate a new trail id to reach to your new successor. */ |
4823 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG, | 4875 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG, |
4824 | &trail_id, sizeof (trail_id)); | 4876 | &trail_id, sizeof (trail_id)); |
@@ -5319,6 +5371,7 @@ handle_dht_p2p_add_trail (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
5319 | msize = ntohs (message->size); | 5371 | msize = ntohs (message->size); |
5320 | /* In this message we pass the whole trail from source to destination as we | 5372 | /* In this message we pass the whole trail from source to destination as we |
5321 | * are adding that trail.*/ | 5373 | * are adding that trail.*/ |
5374 | //FIXME: failed when run with 1000 pears. check why. | ||
5322 | if (msize < sizeof (struct PeerAddTrailMessage)) | 5375 | if (msize < sizeof (struct PeerAddTrailMessage)) |
5323 | { | 5376 | { |
5324 | GNUNET_break_op (0); | 5377 | GNUNET_break_op (0); |
@@ -5627,7 +5680,13 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer_identity) | |||
5627 | 5680 | ||
5628 | /* got a first connection, good time to start with FIND FINGER TRAIL requests...*/ | 5681 | /* got a first connection, good time to start with FIND FINGER TRAIL requests...*/ |
5629 | if (GNUNET_SCHEDULER_NO_TASK == find_finger_trail_task) | 5682 | if (GNUNET_SCHEDULER_NO_TASK == find_finger_trail_task) |
5683 | { | ||
5684 | next_send_time.rel_value_us = | ||
5685 | DHT_FIND_FINGER_TRAIL_INTERVAL.rel_value_us + | ||
5686 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
5687 | DHT_FIND_FINGER_TRAIL_INTERVAL.rel_value_us); | ||
5630 | find_finger_trail_task = GNUNET_SCHEDULER_add_now (&send_find_finger_trail_message, NULL); | 5688 | find_finger_trail_task = GNUNET_SCHEDULER_add_now (&send_find_finger_trail_message, NULL); |
5689 | } | ||
5631 | } | 5690 | } |
5632 | 5691 | ||
5633 | 5692 | ||
diff --git a/src/dht/gnunet-service-xdht_routing.c b/src/dht/gnunet-service-xdht_routing.c index de5255cb7..087d4dcff 100644 --- a/src/dht/gnunet-service-xdht_routing.c +++ b/src/dht/gnunet-service-xdht_routing.c | |||
@@ -320,8 +320,8 @@ GDS_ROUTING_add (struct GNUNET_HashCode new_trail_id, | |||
320 | 320 | ||
321 | 321 | ||
322 | ret = GNUNET_CONTAINER_multihashmap_put (routing_table, | 322 | ret = GNUNET_CONTAINER_multihashmap_put (routing_table, |
323 | &new_trail_id, new_entry, | 323 | &new_trail_id, new_entry, |
324 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 324 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
325 | //GNUNET_assert(ret == GNUNET_OK); | 325 | //GNUNET_assert(ret == GNUNET_OK); |
326 | return ret; | 326 | return ret; |
327 | } | 327 | } |