diff options
author | Supriti Singh <supritisingh08@gmail.com> | 2014-08-05 15:58:59 +0000 |
---|---|---|
committer | Supriti Singh <supritisingh08@gmail.com> | 2014-08-05 15:58:59 +0000 |
commit | 8a9baa7ae446c2eacb18a5290c98ae59bc2ad857 (patch) | |
tree | 89a786dedf1ddd6c7591567de86abac3c59b2308 /src | |
parent | b046370d179073ed9a3a5ee2eb61269a5178767a (diff) | |
download | gnunet-8a9baa7ae446c2eacb18a5290c98ae59bc2ad857.tar.gz gnunet-8a9baa7ae446c2eacb18a5290c98ae59bc2ad857.zip |
Check for duplicate peers in trail setup and verify successor
Diffstat (limited to 'src')
-rw-r--r-- | src/dht/gnunet-service-xdht_neighbours.c | 147 |
1 files changed, 88 insertions, 59 deletions
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c index d5139ca73..6b7f2d5de 100644 --- a/src/dht/gnunet-service-xdht_neighbours.c +++ b/src/dht/gnunet-service-xdht_neighbours.c | |||
@@ -3900,42 +3900,6 @@ get_local_best_known_next_hop (uint64_t final_dest_finger_val, | |||
3900 | return peer; | 3900 | return peer; |
3901 | } | 3901 | } |
3902 | 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 | ||
3938 | |||
3939 | /* | 3903 | /* |
3940 | * Core handle for PeerTrailSetupMessage. | 3904 | * Core handle for PeerTrailSetupMessage. |
3941 | * @param cls closure | 3905 | * @param cls closure |
@@ -4387,6 +4351,7 @@ get_shortest_trail (struct FingerInfo *finger, | |||
4387 | /* Copy the shortest trail and return. */ | 4351 | /* Copy the shortest trail and return. */ |
4388 | trail = &finger->trail_list[shortest_trail_index]; | 4352 | trail = &finger->trail_list[shortest_trail_index]; |
4389 | trail_element = trail->trail_head; | 4353 | trail_element = trail->trail_head; |
4354 | |||
4390 | trail_list = GNUNET_malloc (sizeof(struct GNUNET_PeerIdentity)* | 4355 | trail_list = GNUNET_malloc (sizeof(struct GNUNET_PeerIdentity)* |
4391 | shortest_trail_length); | 4356 | shortest_trail_length); |
4392 | 4357 | ||
@@ -4401,6 +4366,80 @@ get_shortest_trail (struct FingerInfo *finger, | |||
4401 | return trail_list; | 4366 | return trail_list; |
4402 | } | 4367 | } |
4403 | 4368 | ||
4369 | /** | ||
4370 | * Check if trail_1 and trail_2 have any common element. If yes then join | ||
4371 | * them at common element. trail_1 always preceeds trail_2 in joined trail. | ||
4372 | * @param trail_1 | ||
4373 | * @param trail_1_len | ||
4374 | * @param trail_2 | ||
4375 | * @param trail_2_len | ||
4376 | * @param joined_trail_len | ||
4377 | * @return | ||
4378 | */ | ||
4379 | static struct GNUNET_PeerIdentity * | ||
4380 | check_for_duplicate_entries (const struct GNUNET_PeerIdentity *trail_1, | ||
4381 | unsigned int trail_1_len, | ||
4382 | struct GNUNET_PeerIdentity *trail_2, | ||
4383 | unsigned int trail_2_len, | ||
4384 | unsigned int *joined_trail_len) | ||
4385 | { | ||
4386 | struct GNUNET_PeerIdentity *joined_trail; | ||
4387 | unsigned int i; | ||
4388 | unsigned int j; | ||
4389 | unsigned int k; | ||
4390 | |||
4391 | for (i = 0; i < trail_1_len; i++) | ||
4392 | { | ||
4393 | for (j = 0; j < trail_2_len; j++) | ||
4394 | { | ||
4395 | if(0 != GNUNET_CRYPTO_cmp_peer_identity (&trail_1[i],&trail_2[j])) | ||
4396 | continue; | ||
4397 | |||
4398 | *joined_trail_len = i + (trail_2_len - j); | ||
4399 | joined_trail = GNUNET_malloc (*joined_trail_len * | ||
4400 | sizeof(struct GNUNET_PeerIdentity)); | ||
4401 | |||
4402 | |||
4403 | /* Copy all the elements from 0 to i into joined_trail. */ | ||
4404 | for(k = 0; k < trail_1_len; k++) | ||
4405 | { | ||
4406 | joined_trail[k] = trail_1[k]; | ||
4407 | } | ||
4408 | |||
4409 | /* Increment j as entry stored is same as entry stored at i*/ | ||
4410 | j = j+1; | ||
4411 | |||
4412 | /* Copy all the elements from j+1 to trail_2_len-1 to joined trail.*/ | ||
4413 | while(k < *joined_trail_len) | ||
4414 | { | ||
4415 | joined_trail[k] = trail_2[j]; | ||
4416 | k++; | ||
4417 | } | ||
4418 | |||
4419 | return joined_trail; | ||
4420 | } | ||
4421 | } | ||
4422 | |||
4423 | /* Here you should join the trails. */ | ||
4424 | *joined_trail_len = trail_1_len + trail_2_len + 1; | ||
4425 | joined_trail = GNUNET_malloc (*joined_trail_len * | ||
4426 | sizeof(struct GNUNET_PeerIdentity)); | ||
4427 | i = 0; | ||
4428 | while( i < trail_1_len) | ||
4429 | { | ||
4430 | joined_trail[i] = trail_1[i]; | ||
4431 | i++; | ||
4432 | } | ||
4433 | joined_trail[i] = my_identity; | ||
4434 | i++; | ||
4435 | |||
4436 | for (j = 0; i < *joined_trail_len; i++,j++) | ||
4437 | { | ||
4438 | joined_trail[i] = trail_2[j]; | ||
4439 | } | ||
4440 | return joined_trail; | ||
4441 | } | ||
4442 | |||
4404 | 4443 | ||
4405 | /** | 4444 | /** |
4406 | * Return the trail from source to my current predecessor. Check if source | 4445 | * Return the trail from source to my current predecessor. Check if source |
@@ -4467,23 +4506,14 @@ get_trail_src_to_curr_pred (struct GNUNET_PeerIdentity source_peer, | |||
4467 | return trail_src_to_curr_pred; | 4506 | return trail_src_to_curr_pred; |
4468 | } | 4507 | } |
4469 | } | 4508 | } |
4470 | 4509 | ||
4471 | /* Append trail from source to me to my current_predecessor. */ | 4510 | unsigned int len; |
4472 | *trail_src_to_curr_pred_length = trail_src_to_me_len + | 4511 | trail_src_to_curr_pred = check_for_duplicate_entries (trail_src_to_me, |
4473 | trail_me_to_curr_pred_length + 1; | 4512 | trail_src_to_me_len, |
4474 | 4513 | trail_me_to_curr_pred, | |
4475 | trail_src_to_curr_pred = GNUNET_malloc (sizeof(struct GNUNET_PeerIdentity)* | 4514 | trail_me_to_curr_pred_length, |
4476 | *trail_src_to_curr_pred_length); | 4515 | &len); |
4477 | 4516 | *trail_src_to_curr_pred_length = len; | |
4478 | for (i = 0; i < trail_src_to_me_len; i++) | ||
4479 | trail_src_to_curr_pred[i] = trail_src_to_me[i]; | ||
4480 | |||
4481 | trail_src_to_curr_pred[i] = my_identity; | ||
4482 | i++; | ||
4483 | |||
4484 | for (j = 0; i < *trail_src_to_curr_pred_length; i++,j++) | ||
4485 | trail_src_to_curr_pred[i] = trail_me_to_curr_pred[j]; | ||
4486 | |||
4487 | return trail_src_to_curr_pred; | 4517 | return trail_src_to_curr_pred; |
4488 | } | 4518 | } |
4489 | 4519 | ||
@@ -4525,7 +4555,7 @@ update_predecessor (struct GNUNET_PeerIdentity finger, | |||
4525 | /* Invert the trail to get the trail from me to finger, NOT including the | 4555 | /* Invert the trail to get the trail from me to finger, NOT including the |
4526 | endpoints.*/ | 4556 | endpoints.*/ |
4527 | trail_to_new_predecessor = invert_trail (trail, trail_length); | 4557 | trail_to_new_predecessor = invert_trail (trail, trail_length); |
4528 | 4558 | ||
4529 | /* Add an entry in your routing table. */ | 4559 | /* Add an entry in your routing table. */ |
4530 | GDS_ROUTING_add (trail_to_new_predecessor_id, | 4560 | GDS_ROUTING_add (trail_to_new_predecessor_id, |
4531 | my_identity, | 4561 | my_identity, |
@@ -4696,14 +4726,15 @@ handle_dht_p2p_verify_successor(void *cls, | |||
4696 | &source_peer))) | 4726 | &source_peer))) |
4697 | { | 4727 | { |
4698 | trail_src_to_curr_pred = get_trail_src_to_curr_pred (source_peer, | 4728 | trail_src_to_curr_pred = get_trail_src_to_curr_pred (source_peer, |
4699 | trail, | 4729 | trail, |
4700 | trail_length, | 4730 | trail_length, |
4701 | &trail_src_to_curr_pred_len); | 4731 | &trail_src_to_curr_pred_len); |
4702 | } | 4732 | } |
4703 | else | 4733 | else |
4704 | { | 4734 | { |
4705 | trail_src_to_curr_pred_len = trail_length; | 4735 | trail_src_to_curr_pred_len = trail_length; |
4706 | int i; | 4736 | int i; |
4737 | |||
4707 | trail_src_to_curr_pred = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity)*trail_length); | 4738 | trail_src_to_curr_pred = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity)*trail_length); |
4708 | for(i = 0; i < trail_src_to_curr_pred_len; i++) | 4739 | for(i = 0; i < trail_src_to_curr_pred_len; i++) |
4709 | { | 4740 | { |
@@ -5406,12 +5437,10 @@ handle_dht_p2p_add_trail (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
5406 | my_index = search_my_index (trail, trail_length); | 5437 | my_index = search_my_index (trail, trail_length); |
5407 | if (-1 == my_index) | 5438 | if (-1 == my_index) |
5408 | { | 5439 | { |
5409 | |||
5410 | GNUNET_break_op (0); | 5440 | GNUNET_break_op (0); |
5411 | return GNUNET_SYSERR; | 5441 | return GNUNET_SYSERR; |
5412 | } | 5442 | } |
5413 | 5443 | ||
5414 | |||
5415 | if ((trail_length - 1) == my_index) | 5444 | if ((trail_length - 1) == my_index) |
5416 | { | 5445 | { |
5417 | next_hop = destination_peer; | 5446 | next_hop = destination_peer; |