diff options
author | Supriti Singh <supritisingh08@gmail.com> | 2014-02-25 09:42:06 +0000 |
---|---|---|
committer | Supriti Singh <supritisingh08@gmail.com> | 2014-02-25 09:42:06 +0000 |
commit | 3e8fdd425a6186e2ae8b342384ce9addb2b1aaff (patch) | |
tree | 2f6a19b5c2a668fa9019b665838773b9848e6460 /src/dht | |
parent | 7ff606c7821c3beec90d4d5511162f33688138bc (diff) | |
download | gnunet-3e8fdd425a6186e2ae8b342384ce9addb2b1aaff.tar.gz gnunet-3e8fdd425a6186e2ae8b342384ce9addb2b1aaff.zip |
Fixed memory allocation for peer list.
Diffstat (limited to 'src/dht')
-rw-r--r-- | src/dht/gnunet-service-xdht_neighbours.c | 51 |
1 files changed, 35 insertions, 16 deletions
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c index 4d4997d6e..18b3a88b7 100644 --- a/src/dht/gnunet-service-xdht_neighbours.c +++ b/src/dht/gnunet-service-xdht_neighbours.c | |||
@@ -51,11 +51,17 @@ | |||
51 | 51 | ||
52 | /* FIXME: | 52 | /* FIXME: |
53 | 1. Add content and route replication later. | 53 | 1. Add content and route replication later. |
54 | * 3. Algorithm to shorten the trail length - one possible solution could be | 54 | *2. Algorithm to shorten the trail length - one possible solution could be |
55 | * when we are in trail seutp result part. each peer in the trail check if any of | 55 | * when we are in trail seutp result part. each peer in the trail check if any of |
56 | * the corresponding peers is its friend list. Then it can shortcut the path. | 56 | * the corresponding peers is its friend list. Then it can shortcut the path. |
57 | * But this will have O(n) run time at each peer, where n = trail_length.\ | 57 | * But this will have O(n) run time at each peer, where n = trail_length.\ |
58 | * or rather O(n)+O(n-1)+..O(1) =O(n). | 58 | * or rather O(n)+O(n-1)+..O(1) =O(n). |
59 | * 3. Add a new field finger index to keep track of which finger respongs to which | ||
60 | * entry. | ||
61 | * 4. As we start looking for finger from i = 0, using this parameter to | ||
62 | * generate random value does not look smart in send_find_finger_trail_message. | ||
63 | * 5. Need to store the interval in finger and friend table which will be used | ||
64 | * to find the correct successor. | ||
59 | */ | 65 | */ |
60 | 66 | ||
61 | 67 | ||
@@ -673,7 +679,7 @@ GDS_NEIGHBOURS_handle_trail_setup(struct GNUNET_PeerIdentity *source_peer, | |||
673 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), | 679 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), |
674 | 1, GNUNET_NO); | 680 | 1, GNUNET_NO); |
675 | } | 681 | } |
676 | 682 | ||
677 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | 683 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); |
678 | pending->importance = 0; /* FIXME */ | 684 | pending->importance = 0; /* FIXME */ |
679 | pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); | 685 | pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); |
@@ -686,10 +692,12 @@ GDS_NEIGHBOURS_handle_trail_setup(struct GNUNET_PeerIdentity *source_peer, | |||
686 | memcpy(&(tsm->current_destination),&(current_destination->id), sizeof (struct GNUNET_PeerIdentity)); | 692 | memcpy(&(tsm->current_destination),&(current_destination->id), sizeof (struct GNUNET_PeerIdentity)); |
687 | tsm->current_destination_type = htonl(FRIEND); | 693 | tsm->current_destination_type = htonl(FRIEND); |
688 | tsm->trail_length = htonl(trail_length); | 694 | tsm->trail_length = htonl(trail_length); |
695 | peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * trail_length); | ||
689 | peer_list = (struct GNUNET_PeerIdentity *) &tsm[1]; | 696 | peer_list = (struct GNUNET_PeerIdentity *) &tsm[1]; |
690 | 697 | ||
691 | if(NULL == trail_peer_list) | 698 | if(NULL == trail_peer_list) |
692 | { | 699 | { |
700 | /* FIXME: Shift this logic to send_find_finger_trail_message. */ | ||
693 | memcpy(peer_list, &(current_destination->id), sizeof(struct GNUNET_PeerIdentity)); | 701 | memcpy(peer_list, &(current_destination->id), sizeof(struct GNUNET_PeerIdentity)); |
694 | } | 702 | } |
695 | else | 703 | else |
@@ -739,7 +747,7 @@ GDS_NEIGHBOURS_handle_trail_setup_result(struct GNUNET_PeerIdentity *destination | |||
739 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), | 747 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), |
740 | 1, GNUNET_NO); | 748 | 1, GNUNET_NO); |
741 | } | 749 | } |
742 | 750 | ||
743 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | 751 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); |
744 | pending->importance = 0; /* FIXME */ | 752 | pending->importance = 0; /* FIXME */ |
745 | pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); | 753 | pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); |
@@ -757,7 +765,6 @@ GDS_NEIGHBOURS_handle_trail_setup_result(struct GNUNET_PeerIdentity *destination | |||
757 | 765 | ||
758 | /* Send the message to chosen friend. */ | 766 | /* Send the message to chosen friend. */ |
759 | GNUNET_CONTAINER_DLL_insert_tail (current_destination->head, current_destination->tail, pending); | 767 | GNUNET_CONTAINER_DLL_insert_tail (current_destination->head, current_destination->tail, pending); |
760 | |||
761 | current_destination->pending_count++; | 768 | current_destination->pending_count++; |
762 | process_friend_queue (current_destination); | 769 | process_friend_queue (current_destination); |
763 | } | 770 | } |
@@ -1293,6 +1300,7 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1293 | struct PeerTrailSetupMessage *trail_setup; | 1300 | struct PeerTrailSetupMessage *trail_setup; |
1294 | struct GNUNET_PeerIdentity *next_hop; | 1301 | struct GNUNET_PeerIdentity *next_hop; |
1295 | struct FriendInfo *target_friend; | 1302 | struct FriendInfo *target_friend; |
1303 | struct FriendInfo *new_target_friend; | ||
1296 | size_t msize; | 1304 | size_t msize; |
1297 | uint32_t trail_length; | 1305 | uint32_t trail_length; |
1298 | enum current_destination_type peer_type; | 1306 | enum current_destination_type peer_type; |
@@ -1312,7 +1320,7 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1312 | trail_length = ntohl (trail_setup->trail_length); | 1320 | trail_length = ntohl (trail_setup->trail_length); |
1313 | peer_type = ntohl (trail_setup->current_destination_type); | 1321 | peer_type = ntohl (trail_setup->current_destination_type); |
1314 | trail_peer_list = (struct GNUNET_PeerIdentity *) &trail_setup[1]; | 1322 | trail_peer_list = (struct GNUNET_PeerIdentity *) &trail_setup[1]; |
1315 | 1323 | ||
1316 | if ((msize < | 1324 | if ((msize < |
1317 | sizeof (struct PeerTrailSetupMessage) + | 1325 | sizeof (struct PeerTrailSetupMessage) + |
1318 | trail_length * sizeof (struct GNUNET_PeerIdentity)) || | 1326 | trail_length * sizeof (struct GNUNET_PeerIdentity)) || |
@@ -1363,24 +1371,36 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1363 | /* Add yourself to list of peers that trail setup message have traversed so far | 1371 | /* Add yourself to list of peers that trail setup message have traversed so far |
1364 | and increment trail length. */ | 1372 | and increment trail length. */ |
1365 | struct GNUNET_PeerIdentity *peer_list; | 1373 | struct GNUNET_PeerIdentity *peer_list; |
1366 | peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * trail_length); | 1374 | peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * (trail_length + 1)); |
1367 | memcpy(peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); | 1375 | memcpy(peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); |
1368 | peer_list[trail_length] = *next_hop; | 1376 | memcpy(&peer_list[trail_length], next_hop, sizeof (struct GNUNET_PeerIdentity)); |
1369 | trail_length++; | 1377 | trail_length++; |
1370 | 1378 | ||
1371 | /* Check if you are next hop, if yes then you have reached the final destination. */ | 1379 | /* Check if you are next hop, if yes then you have reached the final destination. */ |
1372 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity(next_hop,&my_identity))) | 1380 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity(next_hop,&my_identity))) |
1373 | { | 1381 | { |
1374 | /* FIXME: Trail length should be const. */ | 1382 | /* FIXME: Trail length should be const. */ |
1375 | current_trail_index = trail_length - 1; | 1383 | if(trail_length >= 1) |
1376 | next_peer = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity)); //FIXME: Do we need to allocate the memory? | 1384 | { |
1377 | memcpy(next_peer, &peer_list[trail_length-1], sizeof (struct GNUNET_PeerIdentity)); | 1385 | current_trail_index = trail_length - 2; |
1378 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_peer); | 1386 | next_peer = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); //FIXME: Do we need to allocate the memory? |
1379 | 1387 | memcpy(next_peer, &peer_list[current_trail_index], sizeof (struct GNUNET_PeerIdentity)); | |
1380 | GDS_NEIGHBOURS_handle_trail_setup_result(&(trail_setup->source_peer), | 1388 | |
1389 | new_target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_peer); | ||
1390 | |||
1391 | /* FIXME: It does not find a friend. Could be possible error in find_successor | ||
1392 | function. Change the logic in find_successor and change it again. */ | ||
1393 | /*if(GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(friend_peermap,new_target_friend)) | ||
1394 | { | ||
1395 | |||
1396 | return GNUNET_SYSERR; | ||
1397 | } | ||
1398 | */ | ||
1399 | GDS_NEIGHBOURS_handle_trail_setup_result(&(trail_setup->source_peer), | ||
1381 | &(trail_setup->destination_finger), | 1400 | &(trail_setup->destination_finger), |
1382 | target_friend, trail_length, | 1401 | new_target_friend, trail_length, |
1383 | peer_list,current_trail_index); | 1402 | peer_list,current_trail_index); |
1403 | } | ||
1384 | return GNUNET_YES; | 1404 | return GNUNET_YES; |
1385 | } | 1405 | } |
1386 | 1406 | ||
@@ -1411,7 +1431,6 @@ void finger_table_add(struct GNUNET_PeerIdentity *finger, | |||
1411 | unsigned int trail_length) | 1431 | unsigned int trail_length) |
1412 | { | 1432 | { |
1413 | struct FingerInfo *finger_entry; | 1433 | struct FingerInfo *finger_entry; |
1414 | |||
1415 | finger_entry = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity)); | 1434 | finger_entry = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity)); |
1416 | memcpy(&(finger_entry->id), finger, sizeof(struct GNUNET_PeerIdentity)); | 1435 | memcpy(&(finger_entry->id), finger, sizeof(struct GNUNET_PeerIdentity)); |
1417 | memcpy(&(finger_entry->trail_peer_list), peer_list, sizeof(struct GNUNET_PeerIdentity) | 1436 | memcpy(&(finger_entry->trail_peer_list), peer_list, sizeof(struct GNUNET_PeerIdentity) |