aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSupriti Singh <supritisingh08@gmail.com>2014-07-31 13:24:22 +0000
committerSupriti Singh <supritisingh08@gmail.com>2014-07-31 13:24:22 +0000
commit976ccd4fc024f26de4b6fc801ba8fea1860430dd (patch)
treee61084dbc4dc1be16c6c201ed5b3ef93dc9116cc /src
parent35d40eca953a9e2e1b5bd021dbabe4d591941afa (diff)
downloadgnunet-976ccd4fc024f26de4b6fc801ba8fea1860430dd.tar.gz
gnunet-976ccd4fc024f26de4b6fc801ba8fea1860430dd.zip
x-vine:fixes
Diffstat (limited to 'src')
-rw-r--r--src/dht/gnunet-service-xdht_neighbours.c162
1 files changed, 68 insertions, 94 deletions
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c
index b38c8332d..646d02bd4 100644
--- a/src/dht/gnunet-service-xdht_neighbours.c
+++ b/src/dht/gnunet-service-xdht_neighbours.c
@@ -3083,7 +3083,7 @@ scan_and_compress_trail (struct GNUNET_PeerIdentity finger_identity,
3083 return new_trail; 3083 return new_trail;
3084} 3084}
3085 3085
3086#if 0 3086
3087/** 3087/**
3088 * Periodic task to verify current successor. There can be multiple trails to reach 3088 * Periodic task to verify current successor. There can be multiple trails to reach
3089 * to successor, choose the shortest one and send verify successor message 3089 * to successor, choose the shortest one and send verify successor message
@@ -3095,45 +3095,6 @@ static void
3095send_verify_successor_message (void *cls, 3095send_verify_successor_message (void *cls,
3096 const struct GNUNET_SCHEDULER_TaskContext *tc) 3096 const struct GNUNET_SCHEDULER_TaskContext *tc)
3097{ 3097{
3098 struct FingerInfo *current_successor;
3099 struct GNUNET_TIME_Relative next_send_time;
3100 struct GNUNET_PeerIdentity *trail;
3101 struct GNUNET_HashCode trail_id;
3102 unsigned int trail_length;
3103
3104 /* Schedule another send_verify_successor_message. */
3105 next_send_time.rel_value_us =
3106 DHT_SEND_VERIFY_SUCCESSOR_INTERVAL.rel_value_us +
3107 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
3108 DHT_SEND_VERIFY_SUCCESSOR_INTERVAL.rel_value_us);
3109 send_verify_successor_task =
3110 GNUNET_SCHEDULER_add_delayed (next_send_time, &send_verify_successor_message,
3111 NULL);
3112
3113 /* We should never be our own successor. */
3114 GNUNET_assert(0 !=
3115 GNUNET_CRYTPO_cmp_peer_identity (&my_identity,
3116 &current_successor->finger_identity));
3117
3118
3119 trail = get_shortest_trail (successor, &trail_length, &trail_id);
3120
3121 if(trail_length > 0)
3122 {
3123
3124 }
3125 else
3126 {
3127
3128 }
3129}
3130#endif
3131
3132
3133static void
3134send_verify_successor_message (void *cls,
3135 const struct GNUNET_SCHEDULER_TaskContext *tc)
3136{
3137 struct FriendInfo *target_friend; 3098 struct FriendInfo *target_friend;
3138 struct GNUNET_HashCode trail_id; 3099 struct GNUNET_HashCode trail_id;
3139 int i; 3100 int i;
@@ -3143,7 +3104,7 @@ send_verify_successor_message (void *cls,
3143 unsigned int trail_length; 3104 unsigned int trail_length;
3144 unsigned int j = 0; 3105 unsigned int j = 0;
3145 struct FingerInfo *successor; 3106 struct FingerInfo *successor;
3146 3107
3147 /* Schedule another send_find_finger_trail_message task. */ 3108 /* Schedule another send_find_finger_trail_message task. */
3148 next_send_time.rel_value_us = 3109 next_send_time.rel_value_us =
3149 DHT_FIND_FINGER_TRAIL_INTERVAL.rel_value_us + 3110 DHT_FIND_FINGER_TRAIL_INTERVAL.rel_value_us +
@@ -3157,9 +3118,25 @@ send_verify_successor_message (void *cls,
3157 i = 0; 3118 i = 0;
3158 trail = &successor->trail_list[i]; 3119 trail = &successor->trail_list[i];
3159 3120
3160 if(0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, 3121 /* Store the successor for path tracking */
3161 &successor->finger_identity)) 3122 if (track_topology && (NULL != GDS_stats))
3162 return; 3123 {
3124 char *my_id_str;
3125 char *succ_id_str;
3126 char *key;
3127
3128 my_id_str = GNUNET_strdup (GNUNET_i2s (&my_identity));
3129 succ_id_str = GNUNET_strdup (GNUNET_i2s
3130 (&successor->finger_identity));
3131 GNUNET_asprintf (&key, "XDHT:0:%.4s:%.4s", my_id_str, succ_id_str);
3132 GNUNET_free (my_id_str);
3133 GNUNET_free (succ_id_str);
3134 GNUNET_STATISTICS_update (GDS_stats, "key", 1, 0);
3135 GNUNET_free (key);
3136 }
3137
3138 GNUNET_assert(0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity,
3139 &successor->finger_identity));
3163 3140
3164 /* Trail stored at this index. */ 3141 /* Trail stored at this index. */
3165 GNUNET_assert (GNUNET_YES == trail->is_present); 3142 GNUNET_assert (GNUNET_YES == trail->is_present);
@@ -3459,23 +3436,6 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity,
3459 GDS_ROUTING_SRC_TO_DEST, 3436 GDS_ROUTING_SRC_TO_DEST,
3460 finger_identity); 3437 finger_identity);
3461 } 3438 }
3462
3463 /* Store the successor for path tracking */
3464 if (track_topology && (NULL != GDS_stats) && (0 == finger_table_index))
3465 {
3466 char *my_id_str;
3467 char *succ_id_str;
3468 char *key;
3469
3470 my_id_str = GNUNET_strdup (GNUNET_i2s (&my_identity));
3471 succ_id_str = GNUNET_strdup (GNUNET_i2s
3472 (&existing_finger->finger_identity));
3473 GNUNET_asprintf (&key, "XDHT:0:%.4s:%.4s", my_id_str, succ_id_str);
3474 GNUNET_free (my_id_str);
3475 GNUNET_free (succ_id_str);
3476 GNUNET_STATISTICS_update (GDS_stats, "key", 1, 0);
3477 GNUNET_free (key);
3478 }
3479 } 3439 }
3480 } 3440 }
3481 else 3441 else
@@ -4384,7 +4344,7 @@ get_trail_src_to_curr_pred (struct GNUNET_PeerIdentity source_peer,
4384 current_predecessor = &finger_table[PREDECESSOR_FINGER_ID]; 4344 current_predecessor = &finger_table[PREDECESSOR_FINGER_ID];
4385 trail_me_to_curr_pred = get_shortest_trail (current_predecessor, 4345 trail_me_to_curr_pred = get_shortest_trail (current_predecessor,
4386 &trail_me_to_curr_pred_length); 4346 &trail_me_to_curr_pred_length);
4387 4347
4388 /* Check if trail_me_to_curr_pred contains source. */ 4348 /* Check if trail_me_to_curr_pred contains source. */
4389 if (trail_me_to_curr_pred_length > 0) 4349 if (trail_me_to_curr_pred_length > 0)
4390 { 4350 {
@@ -4393,8 +4353,8 @@ get_trail_src_to_curr_pred (struct GNUNET_PeerIdentity source_peer,
4393 if(0 != GNUNET_CRYPTO_cmp_peer_identity (&source_peer, 4353 if(0 != GNUNET_CRYPTO_cmp_peer_identity (&source_peer,
4394 &trail_me_to_curr_pred[i])) 4354 &trail_me_to_curr_pred[i]))
4395 continue; 4355 continue;
4396 4356
4397 i = i+1; 4357 i = i+1;
4398 4358
4399 /* Source is the last element in the trail to reach to my pred. 4359 /* Source is the last element in the trail to reach to my pred.
4400 Source is direct friend of the pred. */ 4360 Source is direct friend of the pred. */
@@ -4407,10 +4367,11 @@ get_trail_src_to_curr_pred (struct GNUNET_PeerIdentity source_peer,
4407 *trail_src_to_curr_pred_length = trail_me_to_curr_pred_length - i; 4367 *trail_src_to_curr_pred_length = trail_me_to_curr_pred_length - i;
4408 trail_src_to_curr_pred = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)* 4368 trail_src_to_curr_pred = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)*
4409 *trail_src_to_curr_pred_length); 4369 *trail_src_to_curr_pred_length);
4410 for(j = 0; i < *trail_src_to_curr_pred_length; i++,j++) 4370 for(j = 0; j < *trail_src_to_curr_pred_length; i++,j++)
4411 { 4371 {
4412 trail_src_to_curr_pred[j] = trail_me_to_curr_pred[i]; 4372 trail_src_to_curr_pred[j] = trail_me_to_curr_pred[i];
4413 } 4373 }
4374
4414 return trail_src_to_curr_pred; 4375 return trail_src_to_curr_pred;
4415 } 4376 }
4416 } 4377 }
@@ -4587,7 +4548,7 @@ handle_dht_p2p_verify_successor(void *cls,
4587 GNUNET_break_op (0); 4548 GNUNET_break_op (0);
4588 return GNUNET_YES; 4549 return GNUNET_YES;
4589 } 4550 }
4590 4551
4591 vsm = (const struct PeerVerifySuccessorMessage *) message; 4552 vsm = (const struct PeerVerifySuccessorMessage *) message;
4592 trail_length = (msize - sizeof (struct PeerVerifySuccessorMessage))/ 4553 trail_length = (msize - sizeof (struct PeerVerifySuccessorMessage))/
4593 sizeof (struct GNUNET_PeerIdentity); 4554 sizeof (struct GNUNET_PeerIdentity);
@@ -4638,14 +4599,18 @@ handle_dht_p2p_verify_successor(void *cls,
4638 trail_src_to_curr_pred = get_trail_src_to_curr_pred (source_peer, 4599 trail_src_to_curr_pred = get_trail_src_to_curr_pred (source_peer,
4639 trail, 4600 trail,
4640 trail_length, 4601 trail_length,
4641 &trail_src_to_curr_pred_len); 4602 &trail_src_to_curr_pred_len);
4642
4643 } 4603 }
4644 else 4604 else
4645 { 4605 {
4646 trail_src_to_curr_pred = GNUNET_new(struct GNUNET_PeerIdentity); 4606 trail_src_to_curr_pred_len = trail_length;
4647 trail_src_to_curr_pred = NULL; 4607 int i;
4648 trail_src_to_curr_pred_len = 0; 4608 trail_src_to_curr_pred = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity)*trail_length);
4609 for(i = 0; i < trail_src_to_curr_pred_len; i++)
4610 {
4611 trail_src_to_curr_pred[i] = trail[i];
4612 }
4613
4649 } 4614 }
4650 4615
4651 GNUNET_assert (NULL != 4616 GNUNET_assert (NULL !=
@@ -4682,7 +4647,7 @@ check_trail_me_to_probable_succ (struct GNUNET_PeerIdentity probable_successor,
4682 unsigned int i; 4647 unsigned int i;
4683 unsigned int j; 4648 unsigned int j;
4684 struct GNUNET_PeerIdentity *trail_to_new_successor; 4649 struct GNUNET_PeerIdentity *trail_to_new_successor;
4685 4650
4686 /* Probable successor is a friend */ 4651 /* Probable successor is a friend */
4687 if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, 4652 if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap,
4688 &probable_successor)) 4653 &probable_successor))
@@ -4693,30 +4658,32 @@ check_trail_me_to_probable_succ (struct GNUNET_PeerIdentity probable_successor,
4693 } 4658 }
4694 4659
4695 /* Is there any friend of yours in this trail. */ 4660 /* Is there any friend of yours in this trail. */
4696 for (i = trail_me_to_probable_successor_len - 1; i > 0; i--) 4661 if(trail_me_to_probable_successor_len > 1)
4697 { 4662 {
4698 if (NULL == GNUNET_CONTAINER_multipeermap_get (friend_peermap, 4663 for (i = trail_me_to_probable_successor_len - 1; i > 0; i--)
4699 &trail_me_to_probable_successor[i])) 4664 {
4700 continue; 4665 if (NULL == GNUNET_CONTAINER_multipeermap_get (friend_peermap,
4666 &trail_me_to_probable_successor[i]))
4667 continue;
4701 4668
4702 j = 0; 4669 j = 0;
4703 *trail_to_new_successor_length = (trail_me_to_probable_successor_len - i); 4670 *trail_to_new_successor_length = (trail_me_to_probable_successor_len - i);
4704 trail_to_new_successor = GNUNET_malloc (sizeof(struct GNUNET_PeerIdentity)* 4671 trail_to_new_successor = GNUNET_malloc (sizeof(struct GNUNET_PeerIdentity)*
4705 *trail_to_new_successor_length); 4672 *trail_to_new_successor_length);
4706 4673
4707 for(j = 0;i < trail_me_to_probable_successor_len;i++,j++) 4674 for(j = 0;i < trail_me_to_probable_successor_len;i++,j++)
4708 { 4675 {
4709 trail_to_new_successor[j] = trail_me_to_probable_successor[i]; 4676 trail_to_new_successor[j] = trail_me_to_probable_successor[i];
4677 }
4678 return trail_to_new_successor;
4710 } 4679 }
4711
4712 return trail_to_new_successor;
4713 } 4680 }
4714 4681
4715 4682 *trail_to_new_successor_length = trail_me_to_probable_successor_len;
4716 trail_to_new_successor = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)* 4683 trail_to_new_successor = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)*
4717 trail_me_to_probable_successor_len); 4684 *trail_to_new_successor_length);
4718 4685
4719 for(i = 0; i < trail_me_to_probable_successor_len; i++) 4686 for(i = 0; i < *trail_to_new_successor_length; i++)
4720 trail_to_new_successor[i] = trail_me_to_probable_successor[i]; 4687 trail_to_new_successor[i] = trail_me_to_probable_successor[i];
4721 4688
4722 return trail_to_new_successor; 4689 return trail_to_new_successor;
@@ -4724,7 +4691,11 @@ check_trail_me_to_probable_succ (struct GNUNET_PeerIdentity probable_successor,
4724 4691
4725 4692
4726/** 4693/**
4727 * 4694 * Check if the peer which sent us verify successor result message is still ours
4695 * successor or not. If not, then compare existing successor and probable successor.
4696 * In case probable successor is the correct successor, remove the existing
4697 * successor. Add probable successor as new successor. Send notify new successor
4698 * message to new successor.
4728 * @param curr_succ 4699 * @param curr_succ
4729 * @param probable_successor 4700 * @param probable_successor
4730 * @param trail 4701 * @param trail
@@ -4774,16 +4745,20 @@ compare_and_update_successor (struct GNUNET_PeerIdentity curr_succ,
4774 return; 4745 return;
4775 4746
4776 /* Probable successor is the closest peer.*/ 4747 /* Probable successor is the closest peer.*/
4748 if(trail_length > 0)
4749 GNUNET_assert(NULL != GNUNET_CONTAINER_multipeermap_get(friend_peermap,
4750 &trail[0]));
4751 else
4752 GNUNET_assert(NULL != GNUNET_CONTAINER_multipeermap_get(friend_peermap,
4753 &probable_successor));
4777 4754
4778 GNUNET_assert(NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, 4755 trail_me_to_probable_succ_len = 0;
4779 &trail[0]));
4780
4781 /* TODO: Check if the path to reach to probable successor contains a friend. */ 4756 /* TODO: Check if the path to reach to probable successor contains a friend. */
4782 trail_me_to_probable_succ = 4757 trail_me_to_probable_succ =
4783 check_trail_me_to_probable_succ (probable_successor, 4758 check_trail_me_to_probable_succ (probable_successor,
4784 trail, trail_length, 4759 trail, trail_length,
4785 &trail_me_to_probable_succ_len); 4760 &trail_me_to_probable_succ_len);
4786 4761
4787 /* Remove the existing successor. */ 4762 /* Remove the existing successor. */
4788 remove_existing_finger (current_successor, 0); 4763 remove_existing_finger (current_successor, 0);
4789 4764
@@ -4804,7 +4779,7 @@ compare_and_update_successor (struct GNUNET_PeerIdentity curr_succ,
4804 GDS_ROUTING_add (trail_id, my_identity, probable_successor); 4779 GDS_ROUTING_add (trail_id, my_identity, probable_successor);
4805 GNUNET_assert (NULL != 4780 GNUNET_assert (NULL !=
4806 (target_friend = 4781 (target_friend =
4807 GNUNET_CONTAINER_multipeermap_get (friend_peermap, 4782 GNUNET_CONTAINER_multipeermap_get (friend_peermap,
4808 &probable_successor))); 4783 &probable_successor)));
4809 } 4784 }
4810 4785
@@ -4871,7 +4846,6 @@ handle_dht_p2p_verify_successor_result(void *cls,
4871 probable_successor = vsrm->probable_successor; 4846 probable_successor = vsrm->probable_successor;
4872 current_successor = vsrm->current_successor; 4847 current_successor = vsrm->current_successor;
4873 4848
4874
4875 /* I am the querying_peer. */ 4849 /* I am the querying_peer. */
4876 if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&querying_peer, &my_identity))) 4850 if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&querying_peer, &my_identity)))
4877 { 4851 {