aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSupriti Singh <supritisingh08@gmail.com>2014-08-17 12:07:41 +0000
committerSupriti Singh <supritisingh08@gmail.com>2014-08-17 12:07:41 +0000
commit9f2753334e665b88b33e91ae32a1ecee2175dd85 (patch)
tree10787ed18c9b21aacc5343b172ea04453056a112 /src
parent0f74ff197e6d5108c19545a1b407ab965d582137 (diff)
downloadgnunet-9f2753334e665b88b33e91ae32a1ecee2175dd85.tar.gz
gnunet-9f2753334e665b88b33e91ae32a1ecee2175dd85.zip
Removed trail compression message. Checking for friend to source in trail setup.
Diffstat (limited to 'src')
-rw-r--r--src/dht/gnunet-service-xdht_neighbours.c329
-rw-r--r--src/include/gnunet_protocols.h5
2 files changed, 39 insertions, 295 deletions
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c
index a780bb8be..9434bb3bd 100644
--- a/src/dht/gnunet-service-xdht_neighbours.c
+++ b/src/dht/gnunet-service-xdht_neighbours.c
@@ -491,34 +491,6 @@ struct PeerNotifyNewSuccessorMessage
491 */ 491 */
492}; 492};
493 493
494/**
495 * P2P Trail Compression Message.
496 */
497struct PeerTrailCompressionMessage
498{
499 /**
500 * Type: #GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_COMPRESSION
501 */
502 struct GNUNET_MessageHeader header;
503
504 /**
505 * Source peer of this trail.
506 */
507 struct GNUNET_PeerIdentity source_peer;
508
509 /**
510 * Trail from source_peer to destination_peer compressed such that
511 * new_first_friend is the first hop in the trail from source to
512 * destination.
513 */
514 struct GNUNET_PeerIdentity new_first_friend;
515
516 /**
517 * Unique identifier of trail.
518 */
519 struct GNUNET_HashCode trail_id;
520};
521
522 494
523/** 495/**
524 * P2P Trail Tear Down message. 496 * P2P Trail Tear Down message.
@@ -1533,56 +1505,6 @@ GDS_NEIGHBOURS_send_add_trail (struct GNUNET_PeerIdentity source_peer,
1533 1505
1534 1506
1535/** 1507/**
1536 * Construct a trail compression message and send it to target_friend.
1537 * @param source_peer Source of the trail.
1538 * @param trail_id Unique identifier of trail.
1539 * @param first_friend First hop in compressed trail to reach from source to finger
1540 * @param target_friend Next friend to get this message.
1541 */
1542void
1543GDS_NEIGHBOURS_send_trail_compression (struct GNUNET_PeerIdentity source_peer,
1544 struct GNUNET_HashCode trail_id,
1545 struct GNUNET_PeerIdentity first_friend,
1546 struct FriendInfo *target_friend)
1547{
1548 struct P2PPendingMessage *pending;
1549 struct PeerTrailCompressionMessage *tcm;
1550 size_t msize;
1551
1552 msize = sizeof (struct PeerTrailCompressionMessage);
1553
1554 if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE)
1555 {
1556 GNUNET_break (0);
1557 return;
1558 }
1559
1560 if (target_friend->pending_count >= MAXIMUM_PENDING_PER_FRIEND)
1561 {
1562 GNUNET_STATISTICS_update (GDS_stats,
1563 gettext_noop ("# P2P messages dropped due to full queue"),
1564 1, GNUNET_NO);
1565 }
1566
1567 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
1568 pending->importance = 0; /* FIXME */
1569 pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT);
1570 tcm = (struct PeerTrailCompressionMessage *) &pending[1];
1571 pending->msg = &tcm->header;
1572 tcm->header.size = htons (msize);
1573 tcm->header.type = htons (GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_COMPRESSION);
1574 tcm->source_peer = source_peer;
1575 tcm->new_first_friend = first_friend;
1576 tcm->trail_id = trail_id;
1577
1578 GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending);
1579 target_friend->pending_count++;
1580 process_friend_queue (target_friend);
1581
1582}
1583
1584
1585/**
1586 * Search my location in trail. In case I am present more than once in the 1508 * Search my location in trail. In case I am present more than once in the
1587 * trail (can happen during trail setup), then return my lowest index. 1509 * trail (can happen during trail setup), then return my lowest index.
1588 * @param trail List of peers 1510 * @param trail List of peers
@@ -3107,106 +3029,6 @@ add_new_finger (struct GNUNET_PeerIdentity finger_identity,
3107 3029
3108 3030
3109/** 3031/**
3110 * Scan the trail to check if there is any other friend in the trail other than
3111 * first hop. If yes then shortcut the trail, send trail compression message to
3112 * peers which are no longer part of trail and send back the updated trail
3113 * and trail_length to calling function.
3114 * @param finger_identity Finger whose trail we will scan.
3115 * @param finger_trail [in, out] Trail to reach from source to finger,
3116 * @param finger_trail_length Total number of peers in original finger_trail.
3117 * @param finger_trail_id Unique identifier of the finger trail.
3118 * @return updated trail length in case we shortcut the trail, else original
3119 * trail length.
3120 */
3121static struct GNUNET_PeerIdentity *
3122scan_and_compress_trail (struct GNUNET_PeerIdentity finger_identity,
3123 const struct GNUNET_PeerIdentity *trail,
3124 unsigned int trail_length,
3125 struct GNUNET_HashCode trail_id,
3126 int *new_trail_length)
3127{
3128 struct FriendInfo *target_friend;
3129 struct GNUNET_PeerIdentity *new_trail;
3130 unsigned int i;
3131
3132 /* I am my own finger. */
3133 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &finger_identity))
3134 {
3135 *new_trail_length = 0;
3136 return NULL;
3137 }
3138
3139 if (0 == trail_length)
3140 {
3141 *new_trail_length = 0;
3142 return NULL;
3143 }
3144
3145 /* If finger identity is a friend. */
3146 if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, &finger_identity))
3147 {
3148 *new_trail_length = 0;
3149
3150 /* If there is trail to reach this finger/friend */
3151 if (trail_length > 0)
3152 {
3153 /* Finger is your first friend. */
3154 GDS_ROUTING_update_trail_next_hop (trail_id, finger_identity);
3155 GNUNET_assert (NULL !=
3156 (target_friend =
3157 GNUNET_CONTAINER_multipeermap_get (friend_peermap,
3158 &trail[0])));
3159
3160
3161 GDS_NEIGHBOURS_send_trail_compression (my_identity,
3162 trail_id, finger_identity,
3163 target_friend);
3164 }
3165 return NULL;
3166 }
3167
3168 /* For other cases, when its neither a friend nor my own identity.*/
3169 for (i = trail_length - 1; i > 0; i--)
3170 {
3171 /* If the element at this index in trail is a friend. */
3172 if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, &trail[i]))
3173 {
3174 struct FriendInfo *target_friend;
3175 int j = 0;
3176
3177 GNUNET_assert (NULL !=
3178 (target_friend =
3179 GNUNET_CONTAINER_multipeermap_get (friend_peermap,
3180 &trail[0])));
3181 GDS_ROUTING_update_trail_next_hop (trail_id, trail[i]);
3182 GDS_NEIGHBOURS_send_trail_compression (my_identity,
3183 trail_id, trail[i],
3184 target_friend);
3185
3186
3187 /* Copy the trail from index i to index (trail_length -1) into a new trail
3188 * and update new trail length */
3189 *new_trail_length = trail_length - i;
3190 new_trail = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * (*new_trail_length));
3191 while (i < trail_length)
3192 {
3193 memcpy (&new_trail[j], &trail[i], sizeof(struct GNUNET_PeerIdentity));
3194 j++;
3195 i++;
3196 }
3197 return new_trail;
3198 }
3199 }
3200
3201 /* If we did not compress the trail, return the original trail back.*/
3202 *new_trail_length = trail_length;
3203 new_trail = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * trail_length);
3204 memcpy (new_trail, trail, trail_length * sizeof (struct GNUNET_PeerIdentity));
3205 return new_trail;
3206}
3207
3208
3209/**
3210 * Periodic task to verify current successor. There can be multiple trails to reach 3032 * Periodic task to verify current successor. There can be multiple trails to reach
3211 * to successor, choose the shortest one and send verify successor message 3033 * to successor, choose the shortest one and send verify successor message
3212 * across that trail. 3034 * across that trail.
@@ -3473,7 +3295,7 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity,
3473 struct FingerInfo *existing_finger; 3295 struct FingerInfo *existing_finger;
3474 const struct GNUNET_PeerIdentity *closest_peer; 3296 const struct GNUNET_PeerIdentity *closest_peer;
3475 struct FingerInfo *successor; 3297 struct FingerInfo *successor;
3476 int updated_finger_trail_length; 3298 //int updated_finger_trail_length;
3477 unsigned int finger_table_index; 3299 unsigned int finger_table_index;
3478 3300
3479 /* Get the finger_table_index corresponding to finger_value we got from network.*/ 3301 /* Get the finger_table_index corresponding to finger_value we got from network.*/
@@ -3521,18 +3343,18 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity,
3521 /* No entry present in finger_table for given finger map index. */ 3343 /* No entry present in finger_table for given finger map index. */
3522 if (GNUNET_NO == existing_finger->is_present) 3344 if (GNUNET_NO == existing_finger->is_present)
3523 { 3345 {
3524 struct GNUNET_PeerIdentity *updated_trail; 3346 //struct GNUNET_PeerIdentity *updated_trail;
3525 3347
3526 /* Shorten the trail if possible. */ 3348 /* Shorten the trail if possible.
3527 updated_finger_trail_length = finger_trail_length; 3349 updated_finger_trail_length = finger_trail_length;
3528 updated_trail = scan_and_compress_trail (finger_identity, finger_trail, 3350 updated_trail = scan_and_compress_trail (finger_identity, finger_trail,
3529 finger_trail_length, 3351 finger_trail_length,
3530 finger_trail_id, 3352 finger_trail_id,
3531 &updated_finger_trail_length); 3353 &updated_finger_trail_length);*/
3532 add_new_finger (finger_identity, updated_trail, 3354 add_new_finger (finger_identity, finger_trail,
3533 updated_finger_trail_length, 3355 finger_trail_length,
3534 finger_trail_id, finger_table_index); 3356 finger_trail_id, finger_table_index);
3535 GNUNET_free_non_null(updated_trail); 3357 //GNUNET_free_non_null(updated_trail);
3536 update_current_search_finger_index (finger_identity, 3358 update_current_search_finger_index (finger_identity,
3537 finger_table_index); 3359 finger_table_index);
3538 return; 3360 return;
@@ -3551,17 +3373,17 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity,
3551 /* If the new finger is the closest peer. */ 3373 /* If the new finger is the closest peer. */
3552 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, closest_peer)) 3374 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, closest_peer))
3553 { 3375 {
3554 struct GNUNET_PeerIdentity *updated_trail; 3376 //struct GNUNET_PeerIdentity *updated_trail;
3555 /* Shorten the trail if possible. */ 3377 /* Shorten the trail if possible.
3556 updated_finger_trail_length = finger_trail_length; 3378 updated_finger_trail_length = finger_trail_length;
3557 updated_trail = 3379 updated_trail =
3558 scan_and_compress_trail (finger_identity, finger_trail, 3380 scan_and_compress_trail (finger_identity, finger_trail,
3559 finger_trail_length, finger_trail_id, 3381 finger_trail_length, finger_trail_id,
3560 &updated_finger_trail_length); 3382 &updated_finger_trail_length);*/
3561 remove_existing_finger (existing_finger, finger_table_index); 3383 remove_existing_finger (existing_finger, finger_table_index);
3562 add_new_finger (finger_identity, updated_trail, updated_finger_trail_length, 3384 add_new_finger (finger_identity, finger_trail, finger_trail_length,
3563 finger_trail_id, finger_table_index); 3385 finger_trail_id, finger_table_index);
3564 GNUNET_free_non_null((struct GNUNET_PeerIdentity *)updated_trail); 3386 //GNUNET_free_non_null((struct GNUNET_PeerIdentity *)updated_trail);
3565 } 3387 }
3566 else 3388 else
3567 { 3389 {
@@ -3593,21 +3415,21 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity,
3593 GNUNET_CONTAINER_multipeermap_get (friend_peermap, 3415 GNUNET_CONTAINER_multipeermap_get (friend_peermap,
3594 &existing_finger->finger_identity)) 3416 &existing_finger->finger_identity))
3595 { 3417 {
3596 struct GNUNET_PeerIdentity *updated_trail; 3418 //struct GNUNET_PeerIdentity *updated_trail;
3597 3419
3598 /* Shorten the trail if possible. */ 3420 /* Shorten the trail if possible.
3599 updated_finger_trail_length = finger_trail_length; 3421 updated_finger_trail_length = finger_trail_length;
3600 updated_trail = 3422 updated_trail =
3601 scan_and_compress_trail (finger_identity, finger_trail, 3423 scan_and_compress_trail (finger_identity, finger_trail,
3602 finger_trail_length, finger_trail_id, 3424 finger_trail_length, finger_trail_id,
3603 &updated_finger_trail_length); 3425 &updated_finger_trail_length);*/
3604 /* If there is space to store more trails. */ 3426 /* If there is space to store more trails. */
3605 if (existing_finger->trails_count < MAXIMUM_TRAILS_PER_FINGER) 3427 if (existing_finger->trails_count < MAXIMUM_TRAILS_PER_FINGER)
3606 add_new_trail (existing_finger, updated_trail, 3428 add_new_trail (existing_finger, finger_trail,
3607 updated_finger_trail_length, finger_trail_id); 3429 finger_trail_length, finger_trail_id);
3608 else 3430 else
3609 select_and_replace_trail (existing_finger, updated_trail, 3431 select_and_replace_trail (existing_finger, finger_trail,
3610 updated_finger_trail_length, finger_trail_id); 3432 finger_trail_length, finger_trail_id);
3611 3433
3612 } 3434 }
3613 } 3435 }
@@ -4159,17 +3981,30 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer,
4159 { 3981 {
4160 trail_length = 0; 3982 trail_length = 0;
4161 } 3983 }
4162 3984
4163 /* Check if you are present in the trail seen so far? */ 3985 /* Check if you are friend of source. */
4164 for (i = 0; i < trail_length ; i++) 3986 if (trail_length > 1)
4165 { 3987 {
4166 if(0 == GNUNET_CRYPTO_cmp_peer_identity(&trail_peer_list[i],&my_identity)) 3988 if(NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, &source))
4167 { 3989 {
4168 trail_length = i; /* Check that you add yourself again */ 3990 /* If I am a friend, then I can be the first contact, so make
4169 break; 3991 trail length 0. We are going to add ourself later in the code.*/
3992 trail_length = 0;
4170 } 3993 }
4171 } 3994 }
4172 3995 else
3996 {
3997 /* Check if you are present in the trail seen so far? */
3998 for (i = 0; i < trail_length ; i++)
3999 {
4000 if(0 == GNUNET_CRYPTO_cmp_peer_identity(&trail_peer_list[i],&my_identity))
4001 {
4002 trail_length = i; /* Check that you add yourself again */
4003 break;
4004 }
4005 }
4006 }
4007
4173 /* Is my routing table full? */ 4008 /* Is my routing table full? */
4174 if (GNUNET_YES == GDS_ROUTING_threshold_reached()) 4009 if (GNUNET_YES == GDS_ROUTING_threshold_reached())
4175 { 4010 {
@@ -4225,7 +4060,6 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer,
4225 trail_peer_list, 4060 trail_peer_list,
4226 is_predecessor, 4061 is_predecessor,
4227 final_dest_finger_val,trail_id); 4062 final_dest_finger_val,trail_id);
4228
4229 } 4063 }
4230 else /* I'm not the final destination. */ 4064 else /* I'm not the final destination. */
4231 { 4065 {
@@ -4249,7 +4083,6 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer,
4249 target_friend, trail_length + 1, peer_list, 4083 target_friend, trail_length + 1, peer_list,
4250 is_predecessor, trail_id, 4084 is_predecessor, trail_id,
4251 next_peer.trail_id); 4085 next_peer.trail_id);
4252 GNUNET_free_non_null (peer_list);
4253 } 4086 }
4254 else 4087 else
4255 GDS_NEIGHBOURS_send_trail_setup (source, 4088 GDS_NEIGHBOURS_send_trail_setup (source,
@@ -5428,88 +5261,6 @@ handle_dht_p2p_trail_setup_rejection (void *cls,
5428} 5261}
5429 5262
5430 5263
5431/*
5432 * Core handle for p2p trail tear compression messages.
5433 * @param cls closure
5434 * @param message message
5435 * @param peer peer identity this notification is about
5436 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
5437 */
5438static int
5439handle_dht_p2p_trail_compression (void *cls, const struct GNUNET_PeerIdentity *peer,
5440 const struct GNUNET_MessageHeader *message)
5441{
5442 const struct PeerTrailCompressionMessage *trail_compression;
5443 struct GNUNET_PeerIdentity *next_hop;
5444 struct FriendInfo *target_friend;
5445 struct GNUNET_HashCode trail_id;
5446 size_t msize;
5447
5448 msize = ntohs (message->size);
5449
5450 if (msize != sizeof (struct PeerTrailCompressionMessage))
5451 {
5452 GNUNET_break_op (0);
5453 return GNUNET_OK;
5454 }
5455
5456 GNUNET_STATISTICS_update (GDS_stats,
5457 gettext_noop
5458 ("# Bytes received from other peers"), msize,
5459 GNUNET_NO);
5460
5461 trail_compression = (const struct PeerTrailCompressionMessage *) message;
5462 trail_id = trail_compression->trail_id;
5463
5464 /* Am I the new first friend to reach to finger of this trail. */
5465 if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&trail_compression->new_first_friend,
5466 &my_identity)))
5467 {
5468 if (NULL ==
5469 (GNUNET_CONTAINER_multipeermap_get (friend_peermap,
5470 &trail_compression->source_peer)))
5471 {
5472 GNUNET_break_op(0);
5473 return GNUNET_OK;
5474 }
5475
5476 /* Update your prev hop to source of this message. */
5477 if(GNUNET_SYSERR ==
5478 (GDS_ROUTING_update_trail_prev_hop (trail_id,
5479 trail_compression->source_peer)))
5480 {
5481 GNUNET_break(0);
5482 return GNUNET_OK;
5483 }
5484 return GNUNET_OK;
5485 }
5486
5487 /* Pass the message to next hop to finally reach to new_first_friend. */
5488 next_hop = GDS_ROUTING_get_next_hop (trail_id, GDS_ROUTING_SRC_TO_DEST);
5489
5490 if (NULL == next_hop)
5491 {
5492 GNUNET_break (0);
5493 return GNUNET_OK;
5494 }
5495
5496 if( NULL == (target_friend =
5497 GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop)))
5498 {
5499 GNUNET_break_op(0);
5500 return GNUNET_OK;
5501 }
5502
5503 GDS_ROUTING_remove_trail (trail_id);
5504
5505 GDS_NEIGHBOURS_send_trail_compression (trail_compression->source_peer,
5506 trail_id,
5507 trail_compression->new_first_friend,
5508 target_friend);
5509 return GNUNET_OK;
5510}
5511
5512
5513/** 5264/**
5514 * Core handler for trail teardown message. 5265 * Core handler for trail teardown message.
5515 * @param cls closure 5266 * @param cls closure
@@ -6002,8 +5753,6 @@ GDS_NEIGHBOURS_init (void)
6002 {&handle_dht_p2p_verify_successor_result, GNUNET_MESSAGE_TYPE_XDHT_P2P_VERIFY_SUCCESSOR_RESULT, 0}, 5753 {&handle_dht_p2p_verify_successor_result, GNUNET_MESSAGE_TYPE_XDHT_P2P_VERIFY_SUCCESSOR_RESULT, 0},
6003 {&handle_dht_p2p_notify_new_successor, GNUNET_MESSAGE_TYPE_XDHT_P2P_NOTIFY_NEW_SUCCESSOR, 0}, 5754 {&handle_dht_p2p_notify_new_successor, GNUNET_MESSAGE_TYPE_XDHT_P2P_NOTIFY_NEW_SUCCESSOR, 0},
6004 {&handle_dht_p2p_trail_setup_rejection, GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_SETUP_REJECTION, 0}, 5755 {&handle_dht_p2p_trail_setup_rejection, GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_SETUP_REJECTION, 0},
6005 {&handle_dht_p2p_trail_compression, GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_COMPRESSION,
6006 sizeof (struct PeerTrailCompressionMessage)},
6007 {&handle_dht_p2p_trail_teardown, GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_TEARDOWN, 5756 {&handle_dht_p2p_trail_teardown, GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_TEARDOWN,
6008 sizeof (struct PeerTrailTearDownMessage)}, 5757 sizeof (struct PeerTrailTearDownMessage)},
6009 {&handle_dht_p2p_add_trail, GNUNET_MESSAGE_TYPE_XDHT_P2P_ADD_TRAIL, 0}, 5758 {&handle_dht_p2p_add_trail, GNUNET_MESSAGE_TYPE_XDHT_P2P_ADD_TRAIL, 0},
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h
index 68472a3f9..e03b7072a 100644
--- a/src/include/gnunet_protocols.h
+++ b/src/include/gnunet_protocols.h
@@ -2584,11 +2584,6 @@ extern "C"
2584#define GNUNET_MESSAGE_TYPE_XDHT_P2P_ADD_TRAIL 888 2584#define GNUNET_MESSAGE_TYPE_XDHT_P2P_ADD_TRAIL 888
2585 2585
2586/** 2586/**
2587 * Trail compression message.
2588 */
2589#define GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_COMPRESSION 889
2590
2591/**
2592 * Peer is storing the data in DHT. 2587 * Peer is storing the data in DHT.
2593 */ 2588 */
2594#define GNUNET_MESSAGE_TYPE_XDHT_P2P_PUT 890 2589#define GNUNET_MESSAGE_TYPE_XDHT_P2P_PUT 890