aboutsummaryrefslogtreecommitdiff
path: root/src/dht
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-10-05 11:26:25 +0000
committerChristian Grothoff <christian@grothoff.org>2014-10-05 11:26:25 +0000
commit632a39e7a6ce4f4f71901ae50c4dd010066c20f3 (patch)
tree23c3505d3f6a2f2dc6dca130a7f86e509f431851 /src/dht
parente5e86a7cc508949a50461d9c38bb2f7a77f38093 (diff)
downloadgnunet-632a39e7a6ce4f4f71901ae50c4dd010066c20f3.tar.gz
gnunet-632a39e7a6ce4f4f71901ae50c4dd010066c20f3.zip
-fix i/j indexing confusion, resulting in array index out of bounds
Diffstat (limited to 'src/dht')
-rw-r--r--src/dht/gnunet-service-xdht_neighbours.c576
1 files changed, 288 insertions, 288 deletions
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c
index 83d76b073..e8e9e8df9 100644
--- a/src/dht/gnunet-service-xdht_neighbours.c
+++ b/src/dht/gnunet-service-xdht_neighbours.c
@@ -99,7 +99,7 @@
99 99
100/** 100/**
101 * In case we don't hear back from the current successor, then we can start 101 * In case we don't hear back from the current successor, then we can start
102 * verify successor. 102 * verify successor.
103 */ 103 */
104#define WAIT_NOTIFY_CONFIRMATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 200) 104#define WAIT_NOTIFY_CONFIRMATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 200)
105 105
@@ -686,7 +686,7 @@ struct FriendInfo
686 */ 686 */
687 struct GNUNET_TIME_Absolute congestion_timestamp; 687 struct GNUNET_TIME_Absolute congestion_timestamp;
688 688
689 689
690 // TODO : Change name of head and tail to pending_messages_list_head and so. 690 // TODO : Change name of head and tail to pending_messages_list_head and so.
691 /** 691 /**
692 * Head of pending messages to be sent to this friend. 692 * Head of pending messages to be sent to this friend.
@@ -772,7 +772,7 @@ struct FingerInfo
772 * Used ONLY for successor. NOT for any other finger. 772 * Used ONLY for successor. NOT for any other finger.
773 */ 773 */
774 struct GNUNET_TIME_Absolute wait_notify_confirmation; 774 struct GNUNET_TIME_Absolute wait_notify_confirmation;
775 775
776 /** 776 /**
777 * Is any finger stored at this finger index. 777 * Is any finger stored at this finger index.
778 */ 778 */
@@ -830,11 +830,11 @@ struct Closest_Peer
830 * to reach to it. In other case, same as best_known_destination. 830 * to reach to it. In other case, same as best_known_destination.
831 */ 831 */
832 struct GNUNET_PeerIdentity next_hop; 832 struct GNUNET_PeerIdentity next_hop;
833 833
834 /** 834 /**
835 * In case finger is the next hop, it contains a valid finger table index 835 * In case finger is the next hop, it contains a valid finger table index
836 * at which the finger is stored. Else, It contains 65, which is out of range 836 * at which the finger is stored. Else, It contains 65, which is out of range
837 * of finger table index. 837 * of finger table index.
838 */ 838 */
839 unsigned int finger_table_index; 839 unsigned int finger_table_index;
840}; 840};
@@ -908,12 +908,12 @@ static struct GNUNET_CORE_Handle *core_api;
908static unsigned int current_search_finger_index; 908static unsigned int current_search_finger_index;
909 909
910/** 910/**
911 * Time duration to schedule find finger trail task. 911 * Time duration to schedule find finger trail task.
912 */ 912 */
913static struct GNUNET_TIME_Relative find_finger_trail_task_next_send_time; 913static struct GNUNET_TIME_Relative find_finger_trail_task_next_send_time;
914 914
915/** 915/**
916 * Time duration to schedule verify successor task. 916 * Time duration to schedule verify successor task.
917 */ 917 */
918static struct GNUNET_TIME_Relative verify_successor_next_send_time; 918static struct GNUNET_TIME_Relative verify_successor_next_send_time;
919 919
@@ -940,19 +940,19 @@ static struct GNUNET_TIME_Relative notify_successor_retry_time;
940unsigned int track_topology; 940unsigned int track_topology;
941 941
942/** 942/**
943 * Should I be a malicious peer and drop the PUT/GET packets? 943 * Should I be a malicious peer and drop the PUT/GET packets?
944 * if 0 then NOT malicious. 944 * if 0 then NOT malicious.
945 */ 945 */
946unsigned int act_malicious; 946unsigned int act_malicious;
947 947
948/** 948/**
949 * Count of fingers found. Ideally we should have O(logn) fingers for a 949 * Count of fingers found. Ideally we should have O(logn) fingers for a
950 * stable network. 950 * stable network.
951 */ 951 */
952static unsigned int total_fingers_found; 952static unsigned int total_fingers_found;
953 953
954/** 954/**
955 * Number of times we found the same successor. 955 * Number of times we found the same successor.
956 */ 956 */
957static unsigned int successor_times; 957static unsigned int successor_times;
958 958
@@ -1049,7 +1049,7 @@ process_friend_queue (struct FriendInfo *peer)
1049 { 1049 {
1050 return; 1050 return;
1051 } 1051 }
1052 1052
1053 peer->th = 1053 peer->th =
1054 GNUNET_CORE_notify_transmit_ready (core_api, GNUNET_NO, 1054 GNUNET_CORE_notify_transmit_ready (core_api, GNUNET_NO,
1055 pending->importance, 1055 pending->importance,
@@ -1133,7 +1133,7 @@ GDS_NEIGHBOURS_send_trail_setup (struct GNUNET_PeerIdentity source_peer,
1133 tsm->is_predecessor = htonl (is_predecessor); 1133 tsm->is_predecessor = htonl (is_predecessor);
1134 tsm->trail_id = trail_id; 1134 tsm->trail_id = trail_id;
1135 tsm->intermediate_trail_id = intermediate_trail_id; 1135 tsm->intermediate_trail_id = intermediate_trail_id;
1136 1136
1137 if (trail_length > 0) 1137 if (trail_length > 0)
1138 { 1138 {
1139 peer_list = (struct GNUNET_PeerIdentity *) &tsm[1]; 1139 peer_list = (struct GNUNET_PeerIdentity *) &tsm[1];
@@ -1193,7 +1193,7 @@ GDS_NEIGHBOURS_send_trail_setup_result (struct GNUNET_PeerIdentity querying_peer
1193 1193
1194 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); 1194 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
1195 pending->importance = 0; 1195 pending->importance = 0;
1196 pending->timeout = GNUNET_TIME_relative_to_absolute (PENDING_MESSAGE_TIMEOUT); 1196 pending->timeout = GNUNET_TIME_relative_to_absolute (PENDING_MESSAGE_TIMEOUT);
1197 tsrm = (struct PeerTrailSetupResultMessage *) &pending[1]; 1197 tsrm = (struct PeerTrailSetupResultMessage *) &pending[1];
1198 pending->msg = &tsrm->header; 1198 pending->msg = &tsrm->header;
1199 tsrm->header.size = htons (msize); 1199 tsrm->header.size = htons (msize);
@@ -1206,7 +1206,7 @@ GDS_NEIGHBOURS_send_trail_setup_result (struct GNUNET_PeerIdentity querying_peer
1206 GNUNET_htonll (ultimate_destination_finger_value); 1206 GNUNET_htonll (ultimate_destination_finger_value);
1207 peer_list = (struct GNUNET_PeerIdentity *) &tsrm[1]; 1207 peer_list = (struct GNUNET_PeerIdentity *) &tsrm[1];
1208 memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); 1208 memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity));
1209 1209
1210 /* Send the message to chosen friend. */ 1210 /* Send the message to chosen friend. */
1211 GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); 1211 GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending);
1212 target_friend->pending_count++; 1212 target_friend->pending_count++;
@@ -1215,7 +1215,7 @@ GDS_NEIGHBOURS_send_trail_setup_result (struct GNUNET_PeerIdentity querying_peer
1215 1215
1216/** 1216/**
1217 * Send notify successor confirmation message. 1217 * Send notify successor confirmation message.
1218 * @param trail_id Unique Identifier of the trail. 1218 * @param trail_id Unique Identifier of the trail.
1219 * @param trail_direction Destination to Source. 1219 * @param trail_direction Destination to Source.
1220 * @param target_friend Friend to get this message next. 1220 * @param target_friend Friend to get this message next.
1221 */ 1221 */
@@ -1227,7 +1227,7 @@ GDS_NEIGHBOURS_send_notify_succcessor_confirmation (struct GNUNET_HashCode trail
1227 struct PeerNotifyConfirmationMessage *ncm; 1227 struct PeerNotifyConfirmationMessage *ncm;
1228 struct P2PPendingMessage *pending; 1228 struct P2PPendingMessage *pending;
1229 size_t msize; 1229 size_t msize;
1230 1230
1231 msize = sizeof (struct PeerNotifyConfirmationMessage); 1231 msize = sizeof (struct PeerNotifyConfirmationMessage);
1232 if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) 1232 if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE)
1233 { 1233 {
@@ -1359,7 +1359,7 @@ GDS_NEIGHBOURS_send_verify_successor_message (struct GNUNET_PeerIdentity source_
1359 1359
1360 msize = sizeof (struct PeerVerifySuccessorMessage) + 1360 msize = sizeof (struct PeerVerifySuccessorMessage) +
1361 (trail_length * sizeof (struct GNUNET_PeerIdentity)); 1361 (trail_length * sizeof (struct GNUNET_PeerIdentity));
1362 1362
1363 if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) 1363 if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE)
1364 { 1364 {
1365 GNUNET_break (0); 1365 GNUNET_break (0);
@@ -1504,10 +1504,10 @@ GDS_NEIGHBOURS_send_verify_successor_result (struct GNUNET_PeerIdentity querying
1504 vsmr->current_successor = current_successor; 1504 vsmr->current_successor = current_successor;
1505 vsmr->probable_successor = probable_successor; 1505 vsmr->probable_successor = probable_successor;
1506 vsmr->trail_direction = htonl (trail_direction); 1506 vsmr->trail_direction = htonl (trail_direction);
1507 vsmr->trail_id = trail_id; 1507 vsmr->trail_id = trail_id;
1508 peer_list = (struct GNUNET_PeerIdentity *) &vsmr[1]; 1508 peer_list = (struct GNUNET_PeerIdentity *) &vsmr[1];
1509 memcpy (peer_list, trail, trail_length * sizeof (struct GNUNET_PeerIdentity)); 1509 memcpy (peer_list, trail, trail_length * sizeof (struct GNUNET_PeerIdentity));
1510 1510
1511 /* Send the message to chosen friend. */ 1511 /* Send the message to chosen friend. */
1512 GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); 1512 GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending);
1513 target_friend->pending_count++; 1513 target_friend->pending_count++;
@@ -1554,7 +1554,7 @@ GDS_NEIGHBOURS_send_notify_new_successor (struct GNUNET_PeerIdentity source_peer
1554 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), 1554 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"),
1555 1, GNUNET_NO); 1555 1, GNUNET_NO);
1556 } 1556 }
1557 1557
1558 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); 1558 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
1559 pending->importance = 0; /* FIXME */ 1559 pending->importance = 0; /* FIXME */
1560 pending->timeout = GNUNET_TIME_relative_to_absolute (PENDING_MESSAGE_TIMEOUT); 1560 pending->timeout = GNUNET_TIME_relative_to_absolute (PENDING_MESSAGE_TIMEOUT);
@@ -1568,7 +1568,7 @@ GDS_NEIGHBOURS_send_notify_new_successor (struct GNUNET_PeerIdentity source_peer
1568 peer_list = (struct GNUNET_PeerIdentity *) &nsm[1]; 1568 peer_list = (struct GNUNET_PeerIdentity *) &nsm[1];
1569 memcpy (peer_list, successor_trail, 1569 memcpy (peer_list, successor_trail,
1570 successor_trail_length * sizeof (struct GNUNET_PeerIdentity)); 1570 successor_trail_length * sizeof (struct GNUNET_PeerIdentity));
1571 1571
1572 /* Send the message to chosen friend. */ 1572 /* Send the message to chosen friend. */
1573 GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); 1573 GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending);
1574 target_friend->pending_count++; 1574 target_friend->pending_count++;
@@ -1627,7 +1627,7 @@ GDS_NEIGHBOURS_send_add_trail (struct GNUNET_PeerIdentity source_peer,
1627 adm->trail_id = trail_id; 1627 adm->trail_id = trail_id;
1628 peer_list = (struct GNUNET_PeerIdentity *)&adm[1]; 1628 peer_list = (struct GNUNET_PeerIdentity *)&adm[1];
1629 memcpy (peer_list, trail, sizeof (struct GNUNET_PeerIdentity) * trail_length); 1629 memcpy (peer_list, trail, sizeof (struct GNUNET_PeerIdentity) * trail_length);
1630 1630
1631 /* Send the message to chosen friend. */ 1631 /* Send the message to chosen friend. */
1632 GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); 1632 GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending);
1633 target_friend->pending_count++; 1633 target_friend->pending_count++;
@@ -1651,7 +1651,7 @@ search_my_index (const struct GNUNET_PeerIdentity *trail,
1651 int i; 1651 int i;
1652 int index_seen = trail_length + 1; 1652 int index_seen = trail_length + 1;
1653 int flag = 0; 1653 int flag = 0;
1654 1654
1655 for (i = 0; i < trail_length; i++) 1655 for (i = 0; i < trail_length; i++)
1656 { 1656 {
1657 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &trail[i])) 1657 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &trail[i]))
@@ -1700,7 +1700,7 @@ is_friend_congested (struct FriendInfo *friend)
1700 * @param value Value to be compare 1700 * @param value Value to be compare
1701 * @return Closest peer 1701 * @return Closest peer
1702 */ 1702 */
1703static struct GNUNET_PeerIdentity 1703static struct GNUNET_PeerIdentity
1704select_closest_finger (const struct GNUNET_PeerIdentity *peer1, 1704select_closest_finger (const struct GNUNET_PeerIdentity *peer1,
1705 const struct GNUNET_PeerIdentity *peer2, 1705 const struct GNUNET_PeerIdentity *peer2,
1706 uint64_t value) 1706 uint64_t value)
@@ -1722,11 +1722,11 @@ select_closest_finger (const struct GNUNET_PeerIdentity *peer1,
1722 { 1722 {
1723 return *peer2; 1723 return *peer2;
1724 } 1724 }
1725 1725
1726 if (value < peer1_value && peer1_value < peer2_value) 1726 if (value < peer1_value && peer1_value < peer2_value)
1727 { 1727 {
1728 return *peer1; 1728 return *peer1;
1729 } 1729 }
1730 else if (value < peer2_value && peer2_value < peer1_value) 1730 else if (value < peer2_value && peer2_value < peer1_value)
1731 { 1731 {
1732 return *peer2; 1732 return *peer2;
@@ -1757,7 +1757,7 @@ select_closest_finger (const struct GNUNET_PeerIdentity *peer1,
1757 * @param value Value to be compare 1757 * @param value Value to be compare
1758 * @return Peer which precedes value in the network. 1758 * @return Peer which precedes value in the network.
1759 */ 1759 */
1760static struct GNUNET_PeerIdentity 1760static struct GNUNET_PeerIdentity
1761select_closest_predecessor (const struct GNUNET_PeerIdentity *peer1, 1761select_closest_predecessor (const struct GNUNET_PeerIdentity *peer1,
1762 const struct GNUNET_PeerIdentity *peer2, 1762 const struct GNUNET_PeerIdentity *peer2,
1763 uint64_t value) 1763 uint64_t value)
@@ -1779,11 +1779,11 @@ select_closest_predecessor (const struct GNUNET_PeerIdentity *peer1,
1779 { 1779 {
1780 return *peer2; 1780 return *peer2;
1781 } 1781 }
1782 1782
1783 if (value < peer1_value && peer1_value < peer2_value) 1783 if (value < peer1_value && peer1_value < peer2_value)
1784 { 1784 {
1785 return *peer2; 1785 return *peer2;
1786 } 1786 }
1787 else if (value < peer2_value && peer2_value < peer1_value) 1787 else if (value < peer2_value && peer2_value < peer1_value)
1788 { 1788 {
1789 return *peer1; 1789 return *peer1;
@@ -1808,7 +1808,7 @@ select_closest_predecessor (const struct GNUNET_PeerIdentity *peer1,
1808 1808
1809#if 0 1809#if 0
1810/** 1810/**
1811 * 1811 *
1812 * 1812 *
1813 */ 1813 */
1814void 1814void
@@ -1817,7 +1817,7 @@ test_print_trail (struct GNUNET_PeerIdentity *trail,
1817{ 1817{
1818 struct GNUNET_PeerIdentity print_peer; 1818 struct GNUNET_PeerIdentity print_peer;
1819 int i; 1819 int i;
1820 1820
1821 FPRINTF (stderr,_("\nSUPU %s, %s, %d,trail_length = %d"), 1821 FPRINTF (stderr,_("\nSUPU %s, %s, %d,trail_length = %d"),
1822 __FILE__, __func__,__LINE__,trail_length); 1822 __FILE__, __func__,__LINE__,trail_length);
1823 for (i =0 ; i< trail_length; i++) 1823 for (i =0 ; i< trail_length; i++)
@@ -1915,7 +1915,7 @@ test_finger_table_print()
1915 * @param is_predecessor Is value a predecessor or any other finger. 1915 * @param is_predecessor Is value a predecessor or any other finger.
1916 * @return Closest peer among two peers. 1916 * @return Closest peer among two peers.
1917 */ 1917 */
1918static struct GNUNET_PeerIdentity 1918static struct GNUNET_PeerIdentity
1919select_closest_peer (const struct GNUNET_PeerIdentity *peer1, 1919select_closest_peer (const struct GNUNET_PeerIdentity *peer1,
1920 const struct GNUNET_PeerIdentity *peer2, 1920 const struct GNUNET_PeerIdentity *peer2,
1921 uint64_t value, 1921 uint64_t value,
@@ -1940,7 +1940,7 @@ select_closest_peer (const struct GNUNET_PeerIdentity *peer1,
1940 * Note: We use length as parameter. But we can use any other suitable parameter 1940 * Note: We use length as parameter. But we can use any other suitable parameter
1941 * also. 1941 * also.
1942 * @param finger Finger Finger whose trail we have to select. 1942 * @param finger Finger Finger whose trail we have to select.
1943 * @return Trail Selected Trail. 1943 * @return Trail Selected Trail.
1944 */ 1944 */
1945static struct Trail * 1945static struct Trail *
1946select_finger_trail (struct FingerInfo *finger) 1946select_finger_trail (struct FingerInfo *finger)
@@ -1968,7 +1968,7 @@ select_finger_trail (struct FingerInfo *finger)
1968 if (GNUNET_YES == is_friend_congested (friend)) 1968 if (GNUNET_YES == is_friend_congested (friend))
1969 continue; 1969 continue;
1970 1970
1971 if (NULL == best_trail || 1971 if (NULL == best_trail ||
1972 best_trail->trail_length > current_finger_trail->trail_length) 1972 best_trail->trail_length > current_finger_trail->trail_length)
1973 { 1973 {
1974 best_trail = current_finger_trail; 1974 best_trail = current_finger_trail;
@@ -2011,7 +2011,7 @@ compare_finger_and_current_closest_peer (struct Closest_Peer *current_closest_pe
2011 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity, 2011 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity,
2012 &my_identity)) 2012 &my_identity))
2013 continue; 2013 continue;
2014 2014
2015 /* If finger is a friend, we have already checked it in previous function. */ 2015 /* If finger is a friend, we have already checked it in previous function. */
2016 if (NULL != (GNUNET_CONTAINER_multipeermap_get (friend_peermap, 2016 if (NULL != (GNUNET_CONTAINER_multipeermap_get (friend_peermap,
2017 &finger->finger_identity))) 2017 &finger->finger_identity)))
@@ -2109,7 +2109,7 @@ init_closest_peer (struct GNUNET_PeerIdentity my_identity,
2109 current_closest_peer.is_predecessor = is_predecessor; 2109 current_closest_peer.is_predecessor = is_predecessor;
2110 current_closest_peer.next_hop = my_identity; 2110 current_closest_peer.next_hop = my_identity;
2111 current_closest_peer.best_known_destination = my_identity; 2111 current_closest_peer.best_known_destination = my_identity;
2112 current_closest_peer.finger_table_index = 65; //65 is a for non valid finger table index. 2112 current_closest_peer.finger_table_index = 65; //65 is a for non valid finger table index.
2113 return current_closest_peer; 2113 return current_closest_peer;
2114} 2114}
2115 2115
@@ -2117,12 +2117,12 @@ init_closest_peer (struct GNUNET_PeerIdentity my_identity,
2117/** 2117/**
2118 * Find locally best known peer, among your own identity, friend and finger list, 2118 * Find locally best known peer, among your own identity, friend and finger list,
2119 * which is closest to given destination_finger_value. 2119 * which is closest to given destination_finger_value.
2120 * 2120 *
2121 * NOTE: In case a friend is also a finger, then it is always chosen as friend 2121 * NOTE: In case a friend is also a finger, then it is always chosen as friend
2122 * not a finger. 2122 * not a finger.
2123 * @param destination_finger_value Peer closest to this value will be the next destination. 2123 * @param destination_finger_value Peer closest to this value will be the next destination.
2124 * @param is_predecessor Are we looking for predecessor or finger? 2124 * @param is_predecessor Are we looking for predecessor or finger?
2125 * @return Closest_Peer that contains all the relevant field to reach to 2125 * @return Closest_Peer that contains all the relevant field to reach to
2126 * @a destination_finger_value 2126 * @a destination_finger_value
2127 */ 2127 */
2128static struct Closest_Peer 2128static struct Closest_Peer
@@ -2187,7 +2187,7 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key,
2187 struct FriendInfo *target_friend; 2187 struct FriendInfo *target_friend;
2188 struct GNUNET_PeerIdentity *pp; 2188 struct GNUNET_PeerIdentity *pp;
2189 size_t msize; 2189 size_t msize;
2190 2190
2191 msize = put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size + 2191 msize = put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size +
2192 sizeof (struct PeerPutMessage); 2192 sizeof (struct PeerPutMessage);
2193 if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) 2193 if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE)
@@ -2202,7 +2202,7 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key,
2202 GNUNET_break (0); 2202 GNUNET_break (0);
2203 return; 2203 return;
2204 } 2204 }
2205 2205
2206 GNUNET_assert (NULL != 2206 GNUNET_assert (NULL !=
2207 (target_friend = 2207 (target_friend =
2208 GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer))); 2208 GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer)));
@@ -2236,7 +2236,7 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key,
2236 2236
2237 2237
2238/** 2238/**
2239 * Handle the put request from the client. 2239 * Handle the put request from the client.
2240 * @param key Key for the content 2240 * @param key Key for the content
2241 * @param block_type Type of the block 2241 * @param block_type Type of the block
2242 * @param options Routing options 2242 * @param options Routing options
@@ -2258,10 +2258,10 @@ GDS_NEIGHBOURS_handle_put (const struct GNUNET_HashCode *key,
2258 struct GNUNET_PeerIdentity next_hop; 2258 struct GNUNET_PeerIdentity next_hop;
2259 uint64_t key_value; 2259 uint64_t key_value;
2260 struct Closest_Peer successor; 2260 struct Closest_Peer successor;
2261 2261
2262 memcpy (&key_value, key, sizeof (uint64_t)); 2262 memcpy (&key_value, key, sizeof (uint64_t));
2263 key_value = GNUNET_ntohll (key_value); 2263 key_value = GNUNET_ntohll (key_value);
2264 successor = find_local_best_known_next_hop (key_value, 2264 successor = find_local_best_known_next_hop (key_value,
2265 GDS_FINGER_TYPE_NON_PREDECESSOR); 2265 GDS_FINGER_TYPE_NON_PREDECESSOR);
2266 best_known_dest = successor.best_known_destination; 2266 best_known_dest = successor.best_known_destination;
2267 next_hop = successor.next_hop; 2267 next_hop = successor.next_hop;
@@ -2275,7 +2275,7 @@ GDS_NEIGHBOURS_handle_put (const struct GNUNET_HashCode *key,
2275 block_type,data_size,data); 2275 block_type,data_size,data);
2276 GDS_CLIENTS_process_put (options, block_type, 0, 2276 GDS_CLIENTS_process_put (options, block_type, 0,
2277 ntohl (desired_replication_level), 2277 ntohl (desired_replication_level),
2278 1, &my_identity, expiration_time, //FIXME: GNUNETnthoh something on expiration time. 2278 1, &my_identity, expiration_time, //FIXME: GNUNETnthoh something on expiration time.
2279 key, data, data_size); 2279 key, data, data_size);
2280 return; 2280 return;
2281 } 2281 }
@@ -2287,7 +2287,7 @@ GDS_NEIGHBOURS_handle_put (const struct GNUNET_HashCode *key,
2287 { 2287 {
2288 struct FingerInfo *next_hop_finger; 2288 struct FingerInfo *next_hop_finger;
2289 unsigned int i; 2289 unsigned int i;
2290 2290
2291 next_hop_finger = &finger_table[successor.finger_table_index]; 2291 next_hop_finger = &finger_table[successor.finger_table_index];
2292 for (i = 0; i < next_hop_finger->trails_count; i++) 2292 for (i = 0; i < next_hop_finger->trails_count; i++)
2293 { 2293 {
@@ -2300,11 +2300,11 @@ GDS_NEIGHBOURS_handle_put (const struct GNUNET_HashCode *key,
2300 0, 1, &my_identity, expiration_time, 2300 0, 1, &my_identity, expiration_time,
2301 data, data_size); 2301 data, data_size);
2302 return; 2302 return;
2303 } 2303 }
2304 next_hop = next_hop_finger->trail_list[i].trail_head->peer; 2304 next_hop = next_hop_finger->trail_list[i].trail_head->peer;
2305 GDS_NEIGHBOURS_send_put (key, block_type, options, desired_replication_level, 2305 GDS_NEIGHBOURS_send_put (key, block_type, options, desired_replication_level,
2306 best_known_dest, 2306 best_known_dest,
2307 next_hop_finger->trail_list[i].trail_id, 2307 next_hop_finger->trail_list[i].trail_id,
2308 &next_hop, 0, 1, &my_identity, 2308 &next_hop, 0, 1, &my_identity,
2309 expiration_time, 2309 expiration_time,
2310 data, data_size); 2310 data, data_size);
@@ -2364,7 +2364,7 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key,
2364 } 2364 }
2365 GNUNET_assert (NULL != 2365 GNUNET_assert (NULL !=
2366 (target_friend = 2366 (target_friend =
2367 GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer))); 2367 GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer)));
2368 2368
2369 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); 2369 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
2370 pending->timeout = GNUNET_TIME_relative_to_absolute (PENDING_MESSAGE_TIMEOUT); 2370 pending->timeout = GNUNET_TIME_relative_to_absolute (PENDING_MESSAGE_TIMEOUT);
@@ -2389,15 +2389,15 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key,
2389 2389
2390 2390
2391/** 2391/**
2392 * Handle the get request from the client file. If I am destination do 2392 * Handle the get request from the client file. If I am destination do
2393 * datacache put and return. Else find the target friend and forward message 2393 * datacache put and return. Else find the target friend and forward message
2394 * to it. 2394 * to it.
2395 * @param key Key for the content 2395 * @param key Key for the content
2396 * @param block_type Type of the block 2396 * @param block_type Type of the block
2397 * @param options Routing options 2397 * @param options Routing options
2398 * @param desired_replication_level Desired replication count 2398 * @param desired_replication_level Desired replication count
2399 */ 2399 */
2400void 2400void
2401GDS_NEIGHBOURS_handle_get(const struct GNUNET_HashCode *key, 2401GDS_NEIGHBOURS_handle_get(const struct GNUNET_HashCode *key,
2402 enum GNUNET_BLOCK_Type block_type, 2402 enum GNUNET_BLOCK_Type block_type,
2403 enum GNUNET_DHT_RouteOption options, 2403 enum GNUNET_DHT_RouteOption options,
@@ -2407,13 +2407,13 @@ GDS_NEIGHBOURS_handle_get(const struct GNUNET_HashCode *key,
2407 struct GNUNET_PeerIdentity best_known_dest; 2407 struct GNUNET_PeerIdentity best_known_dest;
2408 struct GNUNET_HashCode intermediate_trail_id; 2408 struct GNUNET_HashCode intermediate_trail_id;
2409 uint64_t key_value; 2409 uint64_t key_value;
2410 2410
2411 memcpy (&key_value, key, sizeof (uint64_t)); 2411 memcpy (&key_value, key, sizeof (uint64_t));
2412 key_value = GNUNET_ntohll (key_value); 2412 key_value = GNUNET_ntohll (key_value);
2413 2413
2414 successor = find_local_best_known_next_hop (key_value, 2414 successor = find_local_best_known_next_hop (key_value,
2415 GDS_FINGER_TYPE_NON_PREDECESSOR); 2415 GDS_FINGER_TYPE_NON_PREDECESSOR);
2416 2416
2417 best_known_dest = successor.best_known_destination; 2417 best_known_dest = successor.best_known_destination;
2418 intermediate_trail_id = successor.trail_id; 2418 intermediate_trail_id = successor.trail_id;
2419 2419
@@ -2425,7 +2425,7 @@ GDS_NEIGHBOURS_handle_get(const struct GNUNET_HashCode *key,
2425 NULL, 0, 1, &my_identity, NULL,&my_identity); 2425 NULL, 0, 1, &my_identity, NULL,&my_identity);
2426 return; 2426 return;
2427 } 2427 }
2428 2428
2429#if ENABLE_MALICIOUS 2429#if ENABLE_MALICIOUS
2430 struct GNUNET_PeerIdentity next_hop; 2430 struct GNUNET_PeerIdentity next_hop;
2431 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&successor.best_known_destination, 2431 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&successor.best_known_destination,
@@ -2433,7 +2433,7 @@ GDS_NEIGHBOURS_handle_get(const struct GNUNET_HashCode *key,
2433 { 2433 {
2434 struct FingerInfo *next_hop_finger; 2434 struct FingerInfo *next_hop_finger;
2435 unsigned int i; 2435 unsigned int i;
2436 2436
2437 next_hop_finger = &finger_table[successor.finger_table_index]; 2437 next_hop_finger = &finger_table[successor.finger_table_index];
2438 for (i = 0; i < next_hop_finger->trails_count; i++) 2438 for (i = 0; i < next_hop_finger->trails_count; i++)
2439 { 2439 {
@@ -2441,9 +2441,9 @@ GDS_NEIGHBOURS_handle_get(const struct GNUNET_HashCode *key,
2441 { 2441 {
2442 if(0 == next_hop_finger->trail_list[i].trail_length) 2442 if(0 == next_hop_finger->trail_list[i].trail_length)
2443 { 2443 {
2444 GDS_NEIGHBOURS_send_get (key, block_type, options, 2444 GDS_NEIGHBOURS_send_get (key, block_type, options,
2445 desired_replication_level, 2445 desired_replication_level,
2446 best_known_dest,intermediate_trail_id, 2446 best_known_dest,intermediate_trail_id,
2447 &successor.next_hop, 2447 &successor.next_hop,
2448 0, 1, &my_identity); 2448 0, 1, &my_identity);
2449 return; 2449 return;
@@ -2451,7 +2451,7 @@ GDS_NEIGHBOURS_handle_get(const struct GNUNET_HashCode *key,
2451 next_hop = next_hop_finger->trail_list[i].trail_head->peer; 2451 next_hop = next_hop_finger->trail_list[i].trail_head->peer;
2452 GDS_NEIGHBOURS_send_get (key, block_type, options, desired_replication_level, 2452 GDS_NEIGHBOURS_send_get (key, block_type, options, desired_replication_level,
2453 best_known_dest, 2453 best_known_dest,
2454 next_hop_finger->trail_list[i].trail_id, 2454 next_hop_finger->trail_list[i].trail_id,
2455 &next_hop, 0, 1, &my_identity); 2455 &next_hop, 0, 1, &my_identity);
2456 } 2456 }
2457 } 2457 }
@@ -2597,7 +2597,7 @@ select_random_friend ()
2597 for (j = 0; j < index ; j++) 2597 for (j = 0; j < index ; j++)
2598 GNUNET_assert (GNUNET_YES == 2598 GNUNET_assert (GNUNET_YES ==
2599 GNUNET_CONTAINER_multipeermap_iterator_next (iter, NULL, NULL)); 2599 GNUNET_CONTAINER_multipeermap_iterator_next (iter, NULL, NULL));
2600 2600
2601 do 2601 do
2602 { 2602 {
2603 /* Reset the index in friend peermap to 0 as we reached to the end. */ 2603 /* Reset the index in friend peermap to 0 as we reached to the end. */
@@ -2675,8 +2675,8 @@ send_find_finger_trail_message (void *cls,
2675 struct GNUNET_HashCode intermediate_trail_id; 2675 struct GNUNET_HashCode intermediate_trail_id;
2676 unsigned int is_predecessor = 0; 2676 unsigned int is_predecessor = 0;
2677 uint64_t finger_id_value; 2677 uint64_t finger_id_value;
2678 2678
2679 /* Schedule another send_find_finger_trail_message task. After one round of 2679 /* Schedule another send_find_finger_trail_message task. After one round of
2680 * finger search, this time is exponentially backoff. */ 2680 * finger search, this time is exponentially backoff. */
2681 find_finger_trail_task_next_send_time.rel_value_us = 2681 find_finger_trail_task_next_send_time.rel_value_us =
2682 find_finger_trail_task_next_send_time.rel_value_us + 2682 find_finger_trail_task_next_send_time.rel_value_us +
@@ -2701,7 +2701,7 @@ send_find_finger_trail_message (void *cls,
2701 finger_id_value = compute_finger_identity_value (current_search_finger_index); 2701 finger_id_value = compute_finger_identity_value (current_search_finger_index);
2702 if (PREDECESSOR_FINGER_ID == current_search_finger_index) 2702 if (PREDECESSOR_FINGER_ID == current_search_finger_index)
2703 is_predecessor = 1; 2703 is_predecessor = 1;
2704 2704
2705 /* Generate a unique trail id for trail we are trying to setup. */ 2705 /* Generate a unique trail id for trail we are trying to setup. */
2706 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG, 2706 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG,
2707 &trail_id, sizeof (trail_id)); 2707 &trail_id, sizeof (trail_id));
@@ -2725,9 +2725,9 @@ send_find_finger_trail_message (void *cls,
2725 * 2. if the new trail is completely disjoint than the 2725 * 2. if the new trail is completely disjoint than the
2726 * other trails, then may be choosing it is better. 2726 * other trails, then may be choosing it is better.
2727 * 2727 *
2728 * @param finger Finger 2728 * @param finger Finger
2729 * @param new_finger_trail List of peers to reach from me to @a finger, NOT 2729 * @param new_finger_trail List of peers to reach from me to @a finger, NOT
2730 * including the endpoints. 2730 * including the endpoints.
2731 * @param new_finger_trail_length Total number of peers in @a new_finger_trail 2731 * @param new_finger_trail_length Total number of peers in @a new_finger_trail
2732 * @param new_finger_trail_id Unique identifier of @a new_finger_trail. 2732 * @param new_finger_trail_id Unique identifier of @a new_finger_trail.
2733 */ 2733 */
@@ -2778,7 +2778,7 @@ select_and_replace_trail (struct FingerInfo *finger,
2778 GDS_NEIGHBOURS_send_trail_teardown (replace_trail->trail_id, 2778 GDS_NEIGHBOURS_send_trail_teardown (replace_trail->trail_id,
2779 GDS_ROUTING_SRC_TO_DEST, 2779 GDS_ROUTING_SRC_TO_DEST,
2780 *next_hop); 2780 *next_hop);
2781 2781
2782 /* Free the trail. */ 2782 /* Free the trail. */
2783 while (NULL != (trail_element = replace_trail->trail_head)) 2783 while (NULL != (trail_element = replace_trail->trail_head))
2784 { 2784 {
@@ -2791,7 +2791,7 @@ select_and_replace_trail (struct FingerInfo *finger,
2791 replace_trail->is_present = GNUNET_YES; 2791 replace_trail->is_present = GNUNET_YES;
2792 replace_trail->trail_length = new_trail_length; 2792 replace_trail->trail_length = new_trail_length;
2793 replace_trail->trail_id = new_trail_id; 2793 replace_trail->trail_id = new_trail_id;
2794 2794
2795 for (i = 0; i < new_trail_length; i++) 2795 for (i = 0; i < new_trail_length; i++)
2796 { 2796 {
2797 struct Trail_Element *element = GNUNET_new (struct Trail_Element); 2797 struct Trail_Element *element = GNUNET_new (struct Trail_Element);
@@ -2823,7 +2823,7 @@ is_new_trail_unique (struct FingerInfo *existing_finger,
2823 struct Trail_Element *trail_element; 2823 struct Trail_Element *trail_element;
2824 int i; 2824 int i;
2825 int j; 2825 int j;
2826 2826
2827 GNUNET_assert (existing_finger->trails_count > 0); 2827 GNUNET_assert (existing_finger->trails_count > 0);
2828 2828
2829 /* Iterate over list of trails. */ 2829 /* Iterate over list of trails. */
@@ -2853,11 +2853,11 @@ is_new_trail_unique (struct FingerInfo *existing_finger,
2853 return GNUNET_NO; 2853 return GNUNET_NO;
2854} 2854}
2855 2855
2856/** 2856/**
2857 * FIXME; In case of multiple trails, we may have a case where a trail from in 2857 * FIXME; In case of multiple trails, we may have a case where a trail from in
2858 * between has been removed, then we should try to find a free slot , not simply 2858 * between has been removed, then we should try to find a free slot , not simply
2859 * add a trail at then end of the list. 2859 * add a trail at then end of the list.
2860 * Add a new trail at a free slot in trail array of existing finger. 2860 * Add a new trail at a free slot in trail array of existing finger.
2861 * @param existing_finger Finger 2861 * @param existing_finger Finger
2862 * @param new_finger_trail New trail from me to finger, NOT including endpoints 2862 * @param new_finger_trail New trail from me to finger, NOT including endpoints
2863 * @param new_finger_trail_length Total number of peers in @a new_finger_trail 2863 * @param new_finger_trail_length Total number of peers in @a new_finger_trail
@@ -2873,11 +2873,11 @@ add_new_trail (struct FingerInfo *existing_finger,
2873 struct Trail *trail; 2873 struct Trail *trail;
2874 unsigned int i; 2874 unsigned int i;
2875 int free_slot = -1; 2875 int free_slot = -1;
2876 2876
2877 if (GNUNET_NO == is_new_trail_unique (existing_finger, new_trail, 2877 if (GNUNET_NO == is_new_trail_unique (existing_finger, new_trail,
2878 new_trail_length)) 2878 new_trail_length))
2879 return; 2879 return;
2880 2880
2881 for (i = 0; i < existing_finger->trails_count; i++) 2881 for (i = 0; i < existing_finger->trails_count; i++)
2882 { 2882 {
2883 if (GNUNET_NO == existing_finger->trail_list[i].is_present) 2883 if (GNUNET_NO == existing_finger->trail_list[i].is_present)
@@ -2886,10 +2886,10 @@ add_new_trail (struct FingerInfo *existing_finger,
2886 break; 2886 break;
2887 } 2887 }
2888 } 2888 }
2889 2889
2890 if (-1 == free_slot) 2890 if (-1 == free_slot)
2891 free_slot = i; 2891 free_slot = i;
2892 2892
2893 trail = &existing_finger->trail_list[free_slot]; 2893 trail = &existing_finger->trail_list[free_slot];
2894 GNUNET_assert (GNUNET_NO == trail->is_present); 2894 GNUNET_assert (GNUNET_NO == trail->is_present);
2895 trail->trail_id = new_trail_id; 2895 trail->trail_id = new_trail_id;
@@ -2906,7 +2906,7 @@ add_new_trail (struct FingerInfo *existing_finger,
2906 friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, 2906 friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap,
2907 &new_trail[0]); 2907 &new_trail[0]);
2908 } 2908 }
2909 2909
2910 friend->trails_count++; 2910 friend->trails_count++;
2911 for (i = 0; i < new_trail_length; i++) 2911 for (i = 0; i < new_trail_length; i++)
2912 { 2912 {
@@ -2918,7 +2918,7 @@ add_new_trail (struct FingerInfo *existing_finger,
2918 trail->trail_tail, 2918 trail->trail_tail,
2919 element); 2919 element);
2920 } 2920 }
2921 2921
2922 existing_finger->trail_list[free_slot].trail_head = trail->trail_head; 2922 existing_finger->trail_list[free_slot].trail_head = trail->trail_head;
2923 existing_finger->trail_list[free_slot].trail_tail = trail->trail_tail; 2923 existing_finger->trail_list[free_slot].trail_tail = trail->trail_tail;
2924 existing_finger->trail_list[free_slot].trail_length = new_trail_length; 2924 existing_finger->trail_list[free_slot].trail_length = new_trail_length;
@@ -2928,11 +2928,11 @@ add_new_trail (struct FingerInfo *existing_finger,
2928 2928
2929 2929
2930#if 0 2930#if 0
2931/** 2931/**
2932 * FIXME; In case of multiple trails, we may have a case where a trail from in 2932 * FIXME; In case of multiple trails, we may have a case where a trail from in
2933 * between has been removed, then we should try to find a free slot , not simply 2933 * between has been removed, then we should try to find a free slot , not simply
2934 * add a trail at then end of the list. 2934 * add a trail at then end of the list.
2935 * Add a new trail at a free slot in trail array of existing finger. 2935 * Add a new trail at a free slot in trail array of existing finger.
2936 * @param existing_finger Finger 2936 * @param existing_finger Finger
2937 * @param new_finger_trail New trail from me to finger, NOT including endpoints 2937 * @param new_finger_trail New trail from me to finger, NOT including endpoints
2938 * @param new_finger_trail_length Total number of peers in @a new_finger_trail 2938 * @param new_finger_trail_length Total number of peers in @a new_finger_trail
@@ -2948,11 +2948,11 @@ add_new_trail (struct FingerInfo *existing_finger,
2948 struct FriendInfo *first_friend; 2948 struct FriendInfo *first_friend;
2949 int i; 2949 int i;
2950 int index; 2950 int index;
2951 2951
2952 if (GNUNET_NO == is_new_trail_unique (existing_finger, new_trail, 2952 if (GNUNET_NO == is_new_trail_unique (existing_finger, new_trail,
2953 new_trail_length)) 2953 new_trail_length))
2954 return; 2954 return;
2955 2955
2956 index = existing_finger->trails_count; 2956 index = existing_finger->trails_count;
2957 trail = &existing_finger->trail_list[index]; 2957 trail = &existing_finger->trail_list[index];
2958 GNUNET_assert (GNUNET_NO == trail->is_present); 2958 GNUNET_assert (GNUNET_NO == trail->is_present);
@@ -3138,12 +3138,12 @@ add_new_finger (struct GNUNET_PeerIdentity finger_identity,
3138 struct FriendInfo *first_trail_hop; 3138 struct FriendInfo *first_trail_hop;
3139 struct Trail *trail; 3139 struct Trail *trail;
3140 int i; 3140 int i;
3141 3141
3142 new_entry = GNUNET_new (struct FingerInfo); 3142 new_entry = GNUNET_new (struct FingerInfo);
3143 new_entry->finger_identity = finger_identity; 3143 new_entry->finger_identity = finger_identity;
3144 new_entry->finger_table_index = finger_table_index; 3144 new_entry->finger_table_index = finger_table_index;
3145 new_entry->is_present = GNUNET_YES; 3145 new_entry->is_present = GNUNET_YES;
3146 3146
3147 /* If the new entry is my own identity. */ 3147 /* If the new entry is my own identity. */
3148 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, 3148 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity,
3149 &finger_identity)) 3149 &finger_identity))
@@ -3153,7 +3153,7 @@ add_new_finger (struct GNUNET_PeerIdentity finger_identity,
3153 GNUNET_free (new_entry); 3153 GNUNET_free (new_entry);
3154 return; 3154 return;
3155 } 3155 }
3156 3156
3157 /* Finger is a friend. */ 3157 /* Finger is a friend. */
3158 if (0 == finger_trail_length) 3158 if (0 == finger_trail_length)
3159 { 3159 {
@@ -3179,7 +3179,7 @@ add_new_finger (struct GNUNET_PeerIdentity finger_identity,
3179 GNUNET_CONTAINER_multipeermap_get (friend_peermap, 3179 GNUNET_CONTAINER_multipeermap_get (friend_peermap,
3180 &finger_trail[0]))); 3180 &finger_trail[0])));
3181 new_entry->trails_count = 1; 3181 new_entry->trails_count = 1;
3182 first_trail_hop->trails_count++; 3182 first_trail_hop->trails_count++;
3183 /* Copy the finger trail into trail. */ 3183 /* Copy the finger trail into trail. */
3184 trail = GNUNET_new (struct Trail); 3184 trail = GNUNET_new (struct Trail);
3185 for(i = 0; i < finger_trail_length; i++) 3185 for(i = 0; i < finger_trail_length; i++)
@@ -3193,7 +3193,7 @@ add_new_finger (struct GNUNET_PeerIdentity finger_identity,
3193 trail->trail_tail, 3193 trail->trail_tail,
3194 element); 3194 element);
3195 } 3195 }
3196 3196
3197 /* Add trail to trail list. */ 3197 /* Add trail to trail list. */
3198 new_entry->trail_list[0].trail_head = trail->trail_head; 3198 new_entry->trail_list[0].trail_head = trail->trail_head;
3199 new_entry->trail_list[0].trail_tail = trail->trail_tail; 3199 new_entry->trail_list[0].trail_tail = trail->trail_tail;
@@ -3226,10 +3226,10 @@ send_verify_successor_message (void *cls,
3226 struct FingerInfo *successor; 3226 struct FingerInfo *successor;
3227 3227
3228 successor = &finger_table[0]; 3228 successor = &finger_table[0];
3229 3229
3230 /* This task will be scheduled when the result for Verify Successor is received. */ 3230 /* This task will be scheduled when the result for Verify Successor is received. */
3231 send_verify_successor_task = GNUNET_SCHEDULER_NO_TASK; 3231 send_verify_successor_task = GNUNET_SCHEDULER_NO_TASK;
3232 3232
3233 /* When verify successor is being called for first time *for current context* 3233 /* When verify successor is being called for first time *for current context*
3234 * cls will be NULL. If send_verify_successor_retry_task is not NO_TASK, we 3234 * cls will be NULL. If send_verify_successor_retry_task is not NO_TASK, we
3235 * must cancel the retry task scheduled for verify_successor of previous 3235 * must cancel the retry task scheduled for verify_successor of previous
@@ -3240,42 +3240,42 @@ send_verify_successor_message (void *cls,
3240 /* FIXME: Here we are scheduling a new verify successor task, as we 3240 /* FIXME: Here we are scheduling a new verify successor task, as we
3241 got a new successor. But a send verify successor task may be in progress. 3241 got a new successor. But a send verify successor task may be in progress.
3242 1. We need to be sure that this is indeed a new successor. As this function 3242 1. We need to be sure that this is indeed a new successor. As this function
3243 is called even if we add a new trail to reach t old successor. 3243 is called even if we add a new trail to reach t old successor.
3244 2. Assuming the new successor is different, then verify successor message 3244 2. Assuming the new successor is different, then verify successor message
3245 * to old successor may be following stages. 3245 * to old successor may be following stages.
3246 * --> Waiting for verify successor result. Don't wait anymore. there is 3246 * --> Waiting for verify successor result. Don't wait anymore. there is
3247 * no trail to reach from old successor to me, hence, routing 3247 * no trail to reach from old successor to me, hence, routing
3248 * lookup will fail. 3248 * lookup will fail.
3249 * --> Waiting for notify confirmation. again don't wait for it. notify 3249 * --> Waiting for notify confirmation. again don't wait for it. notify
3250 * confirmation will not succeded. 3250 * confirmation will not succeded.
3251 */ 3251 */
3252 if (send_verify_successor_retry_task != GNUNET_SCHEDULER_NO_TASK) 3252 if (send_verify_successor_retry_task != GNUNET_SCHEDULER_NO_TASK)
3253 { 3253 {
3254 /* FIXME: Are we scheduling retry task as soon as we send verify message. 3254 /* FIXME: Are we scheduling retry task as soon as we send verify message.
3255 If yes then here before making this task, first check if the message 3255 If yes then here before making this task, first check if the message
3256 is for the same peer again. */ 3256 is for the same peer again. */
3257 struct VerifySuccessorContext *old_ctx = 3257 struct VerifySuccessorContext *old_ctx =
3258 GNUNET_SCHEDULER_cancel(send_verify_successor_retry_task); 3258 GNUNET_SCHEDULER_cancel(send_verify_successor_retry_task);
3259 /* old_ctx must not be NULL, as the retry task had been scheduled */ 3259 /* old_ctx must not be NULL, as the retry task had been scheduled */
3260 GNUNET_assert(NULL != old_ctx); 3260 GNUNET_assert(NULL != old_ctx);
3261 GNUNET_free(old_ctx); 3261 GNUNET_free(old_ctx);
3262 /* FIXME: Why don't we reset the task to NO_TASK here? */ 3262 /* FIXME: Why don't we reset the task to NO_TASK here? */
3263 } 3263 }
3264 3264
3265 struct VerifySuccessorContext *ctx; 3265 struct VerifySuccessorContext *ctx;
3266 ctx = GNUNET_new(struct VerifySuccessorContext); 3266 ctx = GNUNET_new(struct VerifySuccessorContext);
3267 3267
3268 ctx->num_retries_scheduled++; 3268 ctx->num_retries_scheduled++;
3269 send_verify_successor_retry_task = 3269 send_verify_successor_retry_task =
3270 GNUNET_SCHEDULER_add_delayed (verify_successor_retry_time, 3270 GNUNET_SCHEDULER_add_delayed (verify_successor_retry_time,
3271 &send_verify_successor_message, 3271 &send_verify_successor_message,
3272 ctx); 3272 ctx);
3273 } 3273 }
3274 else 3274 else
3275 { 3275 {
3276 /* This is a retry attempt for verify_successor for a previous context */ 3276 /* This is a retry attempt for verify_successor for a previous context */
3277 struct VerifySuccessorContext *ctx; 3277 struct VerifySuccessorContext *ctx;
3278 3278
3279 ctx = cls; 3279 ctx = cls;
3280 ctx->num_retries_scheduled++; 3280 ctx->num_retries_scheduled++;
3281 send_verify_successor_retry_task = 3281 send_verify_successor_retry_task =
@@ -3283,7 +3283,7 @@ send_verify_successor_message (void *cls,
3283 &send_verify_successor_message, 3283 &send_verify_successor_message,
3284 ctx); 3284 ctx);
3285 } 3285 }
3286 3286
3287 /* Among all the trails to reach to successor, select first one which is present.*/ 3287 /* Among all the trails to reach to successor, select first one which is present.*/
3288 for (i = 0; i < successor->trails_count; i++) 3288 for (i = 0; i < successor->trails_count; i++)
3289 { 3289 {
@@ -3291,11 +3291,11 @@ send_verify_successor_message (void *cls,
3291 if(GNUNET_YES == trail->is_present) 3291 if(GNUNET_YES == trail->is_present)
3292 break; 3292 break;
3293 } 3293 }
3294 3294
3295 /* No valid trail found to reach to successor. */ 3295 /* No valid trail found to reach to successor. */
3296 if (i == successor->trails_count) 3296 if (i == successor->trails_count)
3297 return; 3297 return;
3298 3298
3299 GNUNET_assert(0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, 3299 GNUNET_assert(0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity,
3300 &successor->finger_identity)); 3300 &successor->finger_identity));
3301 /* Trail stored at this index. */ 3301 /* Trail stored at this index. */
@@ -3343,7 +3343,7 @@ send_verify_successor_message (void *cls,
3343/** 3343/**
3344 * FIXME: should this be a periodic task, incrementing the search finger index? 3344 * FIXME: should this be a periodic task, incrementing the search finger index?
3345 * Update the current search finger index. 3345 * Update the current search finger index.
3346 * @a finger_identity 3346 * @a finger_identity
3347 * @a finger_table_index 3347 * @a finger_table_index
3348 */ 3348 */
3349static void 3349static void
@@ -3366,7 +3366,7 @@ update_current_search_finger_index (unsigned int finger_table_index)
3366 { 3366 {
3367 if (GNUNET_SCHEDULER_NO_TASK == send_verify_successor_task) 3367 if (GNUNET_SCHEDULER_NO_TASK == send_verify_successor_task)
3368 { 3368 {
3369 send_verify_successor_task = 3369 send_verify_successor_task =
3370 GNUNET_SCHEDULER_add_now (&send_verify_successor_message, NULL); 3370 GNUNET_SCHEDULER_add_now (&send_verify_successor_message, NULL);
3371 } 3371 }
3372 } 3372 }
@@ -3452,7 +3452,7 @@ get_finger_table_index (uint64_t ultimate_destination_finger_value,
3452 3452
3453/** 3453/**
3454 * Remove finger and its associated data structures from finger table. 3454 * Remove finger and its associated data structures from finger table.
3455 * @param existing_finger Finger to be removed which is in finger table. 3455 * @param existing_finger Finger to be removed which is in finger table.
3456 * @param finger_table_index Index in finger table where @a existing_finger 3456 * @param finger_table_index Index in finger table where @a existing_finger
3457 * is stored. 3457 * is stored.
3458 */ 3458 */
@@ -3513,7 +3513,7 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity,
3513 struct GNUNET_PeerIdentity closest_peer; 3513 struct GNUNET_PeerIdentity closest_peer;
3514 struct FingerInfo *successor; 3514 struct FingerInfo *successor;
3515 unsigned int finger_table_index; 3515 unsigned int finger_table_index;
3516 3516
3517 /* Get the finger_table_index corresponding to finger_value we got from network.*/ 3517 /* Get the finger_table_index corresponding to finger_value we got from network.*/
3518 finger_table_index = get_finger_table_index (finger_value, is_predecessor); 3518 finger_table_index = get_finger_table_index (finger_value, is_predecessor);
3519 3519
@@ -3539,7 +3539,7 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity,
3539 { 3539 {
3540 if (0 == fingers_round_count) 3540 if (0 == fingers_round_count)
3541 { 3541 {
3542 find_finger_trail_task_next_send_time = 3542 find_finger_trail_task_next_send_time =
3543 GNUNET_TIME_STD_BACKOFF(find_finger_trail_task_next_send_time); 3543 GNUNET_TIME_STD_BACKOFF(find_finger_trail_task_next_send_time);
3544 } 3544 }
3545 else 3545 else
@@ -3552,7 +3552,7 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity,
3552 total_fingers_found = 0; 3552 total_fingers_found = 0;
3553 return; 3553 return;
3554 } 3554 }
3555 3555
3556 struct FingerInfo prev_finger; 3556 struct FingerInfo prev_finger;
3557 prev_finger = finger_table[finger_table_index - 1]; 3557 prev_finger = finger_table[finger_table_index - 1];
3558 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, 3558 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger_identity,
@@ -3562,10 +3562,10 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity,
3562 return; 3562 return;
3563 } 3563 }
3564 } 3564 }
3565 3565
3566 total_fingers_found++; 3566 total_fingers_found++;
3567 existing_finger = &finger_table[finger_table_index]; 3567 existing_finger = &finger_table[finger_table_index];
3568 3568
3569 /* No entry present in finger_table for given finger map index. */ 3569 /* No entry present in finger_table for given finger map index. */
3570 if (GNUNET_NO == existing_finger->is_present) 3570 if (GNUNET_NO == existing_finger->is_present)
3571 { 3571 {
@@ -3585,7 +3585,7 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity,
3585 &finger_identity, 3585 &finger_identity,
3586 finger_value, 3586 finger_value,
3587 is_predecessor); 3587 is_predecessor);
3588 3588
3589 /* If the new finger is the closest peer. */ 3589 /* If the new finger is the closest peer. */
3590 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, &closest_peer)) 3590 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, &closest_peer))
3591 { 3591 {
@@ -3618,7 +3618,7 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity,
3618 { 3618 {
3619 return; 3619 return;
3620 } 3620 }
3621 3621
3622 /* If there is space to store more trails. */ 3622 /* If there is space to store more trails. */
3623 if (existing_finger->trails_count < MAXIMUM_TRAILS_PER_FINGER) 3623 if (existing_finger->trails_count < MAXIMUM_TRAILS_PER_FINGER)
3624 add_new_trail (existing_finger, finger_trail, 3624 add_new_trail (existing_finger, finger_trail,
@@ -3690,7 +3690,7 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer,
3690 gettext_noop 3690 gettext_noop
3691 ("# Bytes received from other peers"), (int64_t) msize, 3691 ("# Bytes received from other peers"), (int64_t) msize,
3692 GNUNET_NO); 3692 GNUNET_NO);
3693 3693
3694 current_best_known_dest = put->best_known_destination; 3694 current_best_known_dest = put->best_known_destination;
3695 put_path = (struct GNUNET_PeerIdentity *) &put[1]; 3695 put_path = (struct GNUNET_PeerIdentity *) &put[1];
3696 payload = &put_path[putlen]; 3696 payload = &put_path[putlen];
@@ -3747,7 +3747,7 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer,
3747 return GNUNET_OK; 3747 return GNUNET_OK;
3748 } 3748 }
3749 } 3749 }
3750 3750
3751 /* Check if you are already a part of put path. */ 3751 /* Check if you are already a part of put path. */
3752 unsigned int i; 3752 unsigned int i;
3753 for (i = 0; i < putlen; i++) 3753 for (i = 0; i < putlen; i++)
@@ -3758,7 +3758,7 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer,
3758 break; 3758 break;
3759 } 3759 }
3760 } 3760 }
3761 3761
3762 /* Add yourself to the list. */ 3762 /* Add yourself to the list. */
3763 struct GNUNET_PeerIdentity pp[putlen + 1]; 3763 struct GNUNET_PeerIdentity pp[putlen + 1];
3764 //if (0 != (options & GNUNET_DHT_RO_RECORD_ROUTE)) 3764 //if (0 != (options & GNUNET_DHT_RO_RECORD_ROUTE))
@@ -3770,17 +3770,17 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer,
3770 } 3770 }
3771 else 3771 else
3772 putlen = 0; 3772 putlen = 0;
3773 3773
3774 memcpy (&key_value, &(put->key), sizeof (uint64_t)); 3774 memcpy (&key_value, &(put->key), sizeof (uint64_t));
3775 struct Closest_Peer successor; 3775 struct Closest_Peer successor;
3776 key_value = GNUNET_ntohll (key_value); 3776 key_value = GNUNET_ntohll (key_value);
3777 successor = find_local_best_known_next_hop (key_value, 3777 successor = find_local_best_known_next_hop (key_value,
3778 GDS_FINGER_TYPE_NON_PREDECESSOR); 3778 GDS_FINGER_TYPE_NON_PREDECESSOR);
3779 next_hop = GNUNET_new (struct GNUNET_PeerIdentity); 3779 next_hop = GNUNET_new (struct GNUNET_PeerIdentity);
3780 *next_hop = successor.next_hop; 3780 *next_hop = successor.next_hop;
3781 intermediate_trail_id = successor.trail_id; 3781 intermediate_trail_id = successor.trail_id;
3782 best_known_dest = successor.best_known_destination; 3782 best_known_dest = successor.best_known_destination;
3783 3783
3784 if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&current_best_known_dest, &my_identity))) 3784 if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&current_best_known_dest, &my_identity)))
3785 { 3785 {
3786 next_routing_hop = GDS_ROUTING_get_next_hop (received_intermediate_trail_id, 3786 next_routing_hop = GDS_ROUTING_get_next_hop (received_intermediate_trail_id,
@@ -3789,10 +3789,10 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer,
3789 { 3789 {
3790 next_hop = next_routing_hop; 3790 next_hop = next_routing_hop;
3791 intermediate_trail_id = received_intermediate_trail_id; 3791 intermediate_trail_id = received_intermediate_trail_id;
3792 best_known_dest = current_best_known_dest; 3792 best_known_dest = current_best_known_dest;
3793 } 3793 }
3794 } 3794 }
3795 3795
3796 GDS_CLIENTS_process_put (options, 3796 GDS_CLIENTS_process_put (options,
3797 ntohl (put->block_type), 3797 ntohl (put->block_type),
3798 hop_count, 3798 hop_count,
@@ -3819,7 +3819,7 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer,
3819 { 3819 {
3820 struct FingerInfo *next_hop_finger; 3820 struct FingerInfo *next_hop_finger;
3821 unsigned int i; 3821 unsigned int i;
3822 3822
3823 next_hop_finger = &finger_table[successor.finger_table_index]; 3823 next_hop_finger = &finger_table[successor.finger_table_index];
3824 for (i = 0; i < next_hop_finger->trails_count; i++) 3824 for (i = 0; i < next_hop_finger->trails_count; i++)
3825 { 3825 {
@@ -3841,7 +3841,7 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer,
3841 ntohl (put->block_type),ntohl (put->options), 3841 ntohl (put->block_type),ntohl (put->options),
3842 ntohl (put->desired_replication_level), 3842 ntohl (put->desired_replication_level),
3843 best_known_dest, 3843 best_known_dest,
3844 next_hop_finger->trail_list[i].trail_id, 3844 next_hop_finger->trail_list[i].trail_id,
3845 next_hop, hop_count, putlen, pp, 3845 next_hop, hop_count, putlen, pp,
3846 GNUNET_TIME_absolute_ntoh (put->expiration_time), 3846 GNUNET_TIME_absolute_ntoh (put->expiration_time),
3847 payload, payload_size); 3847 payload, payload_size);
@@ -3890,7 +3890,7 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
3890 uint64_t key_value; 3890 uint64_t key_value;
3891 uint32_t hop_count; 3891 uint32_t hop_count;
3892 size_t msize; 3892 size_t msize;
3893 3893
3894 msize = ntohs (message->size); 3894 msize = ntohs (message->size);
3895 if (msize < sizeof (struct PeerGetMessage)) 3895 if (msize < sizeof (struct PeerGetMessage))
3896 { 3896 {
@@ -3909,7 +3909,7 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
3909 GNUNET_break_op (0); 3909 GNUNET_break_op (0);
3910 return GNUNET_YES; 3910 return GNUNET_YES;
3911 } 3911 }
3912 3912
3913#if ENABLE_MALICIOUS 3913#if ENABLE_MALICIOUS
3914 if(1 == act_malicious) 3914 if(1 == act_malicious)
3915 { 3915 {
@@ -3922,16 +3922,16 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
3922 get_path = (const struct GNUNET_PeerIdentity *)&get[1]; 3922 get_path = (const struct GNUNET_PeerIdentity *)&get[1];
3923 hop_count = get->hop_count; 3923 hop_count = get->hop_count;
3924 hop_count++; 3924 hop_count++;
3925 3925
3926 3926
3927 GNUNET_STATISTICS_update (GDS_stats, 3927 GNUNET_STATISTICS_update (GDS_stats,
3928 gettext_noop 3928 gettext_noop
3929 ("# Bytes received from other peers"), msize, 3929 ("# Bytes received from other peers"), msize,
3930 GNUNET_NO); 3930 GNUNET_NO);
3931 3931
3932 memcpy (&key_value, &(get->key), sizeof (uint64_t)); 3932 memcpy (&key_value, &(get->key), sizeof (uint64_t));
3933 key_value = GNUNET_ntohll (key_value); 3933 key_value = GNUNET_ntohll (key_value);
3934 3934
3935 /* Check if you are already a part of get path. */ 3935 /* Check if you are already a part of get path. */
3936 unsigned int i; 3936 unsigned int i;
3937 for (i = 0; i < get_length; i++) 3937 for (i = 0; i < get_length; i++)
@@ -3942,7 +3942,7 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
3942 break; 3942 break;
3943 } 3943 }
3944 } 3944 }
3945 3945
3946 /* Add yourself in the get path. */ 3946 /* Add yourself in the get path. */
3947 struct GNUNET_PeerIdentity gp[get_length + 1]; 3947 struct GNUNET_PeerIdentity gp[get_length + 1];
3948 memcpy (gp, get_path, get_length * sizeof (struct GNUNET_PeerIdentity)); 3948 memcpy (gp, get_path, get_length * sizeof (struct GNUNET_PeerIdentity));
@@ -3951,9 +3951,9 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
3951 GDS_CLIENTS_process_get (get->options, get->block_type, hop_count, 3951 GDS_CLIENTS_process_get (get->options, get->block_type, hop_count,
3952 get->desired_replication_level, get->get_path_length, 3952 get->desired_replication_level, get->get_path_length,
3953 gp, &get->key); 3953 gp, &get->key);
3954
3955 3954
3956 successor = find_local_best_known_next_hop (key_value, 3955
3956 successor = find_local_best_known_next_hop (key_value,
3957 GDS_FINGER_TYPE_NON_PREDECESSOR); 3957 GDS_FINGER_TYPE_NON_PREDECESSOR);
3958 next_hop = GNUNET_new (struct GNUNET_PeerIdentity); 3958 next_hop = GNUNET_new (struct GNUNET_PeerIdentity);
3959 *next_hop = successor.next_hop; 3959 *next_hop = successor.next_hop;
@@ -3971,7 +3971,7 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
3971 intermediate_trail_id = received_intermediate_trail_id; 3971 intermediate_trail_id = received_intermediate_trail_id;
3972 } 3972 }
3973 } 3973 }
3974 3974
3975 /* I am the final destination. */ 3975 /* I am the final destination. */
3976 if (0 == GNUNET_CRYPTO_cmp_peer_identity(&my_identity, &best_known_dest)) 3976 if (0 == GNUNET_CRYPTO_cmp_peer_identity(&my_identity, &best_known_dest))
3977 { 3977 {
@@ -3984,20 +3984,20 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
3984 else 3984 else
3985 { 3985 {
3986 GDS_DATACACHE_handle_get (&(get->key),(get->block_type), NULL, 0, NULL, 0, 3986 GDS_DATACACHE_handle_get (&(get->key),(get->block_type), NULL, 0, NULL, 0,
3987 get_length, gp, &gp[get_length - 2], 3987 get_length, gp, &gp[get_length - 2],
3988 &my_identity); 3988 &my_identity);
3989 } 3989 }
3990 } 3990 }
3991 else 3991 else
3992 { 3992 {
3993 3993
3994#if ENABLE_MALICIOUS 3994#if ENABLE_MALICIOUS
3995 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&successor.best_known_destination, 3995 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&successor.best_known_destination,
3996 &successor.next_hop)) 3996 &successor.next_hop))
3997 { 3997 {
3998 struct FingerInfo *next_hop_finger; 3998 struct FingerInfo *next_hop_finger;
3999 unsigned int i; 3999 unsigned int i;
4000 4000
4001 next_hop_finger = &finger_table[successor.finger_table_index]; 4001 next_hop_finger = &finger_table[successor.finger_table_index];
4002 for (i = 0; i < next_hop_finger->trails_count; i++) 4002 for (i = 0; i < next_hop_finger->trails_count; i++)
4003 { 4003 {
@@ -4014,7 +4014,7 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
4014 next_hop = &next_hop_finger->trail_list[i].trail_head->peer; 4014 next_hop = &next_hop_finger->trail_list[i].trail_head->peer;
4015 GDS_NEIGHBOURS_send_get (&(get->key), get->block_type, get->options, 4015 GDS_NEIGHBOURS_send_get (&(get->key), get->block_type, get->options,
4016 get->desired_replication_level, best_known_dest, 4016 get->desired_replication_level, best_known_dest,
4017 next_hop_finger->trail_list[i].trail_id, 4017 next_hop_finger->trail_list[i].trail_id,
4018 next_hop, hop_count, 4018 next_hop, hop_count,
4019 get_length, gp); 4019 get_length, gp);
4020 } 4020 }
@@ -4081,7 +4081,7 @@ handle_dht_p2p_get_result (void *cls, const struct GNUNET_PeerIdentity *peer,
4081 gettext_noop 4081 gettext_noop
4082 ("# Bytes received from other peers"), msize, 4082 ("# Bytes received from other peers"), msize,
4083 GNUNET_NO); 4083 GNUNET_NO);
4084 4084
4085 put_path = (const struct GNUNET_PeerIdentity *) &get_result[1]; 4085 put_path = (const struct GNUNET_PeerIdentity *) &get_result[1];
4086 get_path = &put_path[putlen]; 4086 get_path = &put_path[putlen];
4087 payload = (const void *) &get_path[getlen]; 4087 payload = (const void *) &get_path[getlen];
@@ -4153,7 +4153,7 @@ get_local_best_known_next_hop (uint64_t final_dest_finger_val,
4153 current_dest)) 4153 current_dest))
4154 { 4154 {
4155 struct GNUNET_PeerIdentity closest_peer; 4155 struct GNUNET_PeerIdentity closest_peer;
4156 4156
4157 /* Select best successor among one found locally and current_destination 4157 /* Select best successor among one found locally and current_destination
4158 * that we got from network.*/ 4158 * that we got from network.*/
4159 closest_peer = select_closest_peer (&peer.best_known_destination, 4159 closest_peer = select_closest_peer (&peer.best_known_destination,
@@ -4165,7 +4165,7 @@ get_local_best_known_next_hop (uint64_t final_dest_finger_val,
4165 if (0 == GNUNET_CRYPTO_cmp_peer_identity (current_dest, &closest_peer)) 4165 if (0 == GNUNET_CRYPTO_cmp_peer_identity (current_dest, &closest_peer))
4166 { 4166 {
4167 struct GNUNET_PeerIdentity *next_hop; 4167 struct GNUNET_PeerIdentity *next_hop;
4168 4168
4169 next_hop = GDS_ROUTING_get_next_hop (intermediate_trail_id, 4169 next_hop = GDS_ROUTING_get_next_hop (intermediate_trail_id,
4170 GDS_ROUTING_SRC_TO_DEST); 4170 GDS_ROUTING_SRC_TO_DEST);
4171 /* next_hop NULL is a valid case. This intermediate trail id is set by 4171 /* next_hop NULL is a valid case. This intermediate trail id is set by
@@ -4226,12 +4226,12 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer,
4226 } 4226 }
4227 trail_length = (msize - sizeof (struct PeerTrailSetupMessage))/ 4227 trail_length = (msize - sizeof (struct PeerTrailSetupMessage))/
4228 sizeof (struct GNUNET_PeerIdentity); 4228 sizeof (struct GNUNET_PeerIdentity);
4229 4229
4230 GNUNET_STATISTICS_update (GDS_stats, 4230 GNUNET_STATISTICS_update (GDS_stats,
4231 gettext_noop 4231 gettext_noop
4232 ("# Bytes received from other peers"), msize, 4232 ("# Bytes received from other peers"), msize,
4233 GNUNET_NO); 4233 GNUNET_NO);
4234 4234
4235 trail_peer_list = (const struct GNUNET_PeerIdentity *)&trail_setup[1]; 4235 trail_peer_list = (const struct GNUNET_PeerIdentity *)&trail_setup[1];
4236 current_dest = trail_setup->best_known_destination; 4236 current_dest = trail_setup->best_known_destination;
4237 trail_id = trail_setup->trail_id; 4237 trail_id = trail_setup->trail_id;
@@ -4240,7 +4240,7 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer,
4240 source = trail_setup->source_peer; 4240 source = trail_setup->source_peer;
4241 is_predecessor = ntohl (trail_setup->is_predecessor); 4241 is_predecessor = ntohl (trail_setup->is_predecessor);
4242 intermediate_trail_id = trail_setup->intermediate_trail_id; 4242 intermediate_trail_id = trail_setup->intermediate_trail_id;
4243 4243
4244 /* Did the friend insert its ID in the trail list? */ 4244 /* Did the friend insert its ID in the trail list? */
4245 if (trail_length > 0 && 4245 if (trail_length > 0 &&
4246 0 != memcmp (&trail_peer_list[trail_length-1], peer, sizeof (struct GNUNET_PeerIdentity))) 4246 0 != memcmp (&trail_peer_list[trail_length-1], peer, sizeof (struct GNUNET_PeerIdentity)))
@@ -4248,20 +4248,20 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer,
4248 GNUNET_break_op (0); 4248 GNUNET_break_op (0);
4249 return GNUNET_SYSERR; 4249 return GNUNET_SYSERR;
4250 } 4250 }
4251 4251
4252 /* If I was the source and got the message back, then set trail length to 0.*/ 4252 /* If I was the source and got the message back, then set trail length to 0.*/
4253 if (0 == GNUNET_CRYPTO_cmp_peer_identity(&my_identity, &source)) 4253 if (0 == GNUNET_CRYPTO_cmp_peer_identity(&my_identity, &source))
4254 { 4254 {
4255 trail_length = 0; 4255 trail_length = 0;
4256 } 4256 }
4257 4257
4258 /* Check if you are present in the trail seen so far? */ 4258 /* Check if you are present in the trail seen so far? */
4259 for (i = 0; i < trail_length ; i++) 4259 for (i = 0; i < trail_length ; i++)
4260 { 4260 {
4261 if(0 == GNUNET_CRYPTO_cmp_peer_identity(&trail_peer_list[i],&my_identity)) 4261 if(0 == GNUNET_CRYPTO_cmp_peer_identity(&trail_peer_list[i],&my_identity))
4262 { 4262 {
4263 /* We will add ourself later in code, if NOT destination. */ 4263 /* We will add ourself later in code, if NOT destination. */
4264 trail_length = i; 4264 trail_length = i;
4265 break; 4265 break;
4266 } 4266 }
4267 } 4267 }
@@ -4271,11 +4271,11 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer,
4271 { 4271 {
4272 if (trail_length > 0) 4272 if (trail_length > 0)
4273 target_friend = 4273 target_friend =
4274 GNUNET_CONTAINER_multipeermap_get (friend_peermap, 4274 GNUNET_CONTAINER_multipeermap_get (friend_peermap,
4275 &trail_peer_list[trail_length - 1]); 4275 &trail_peer_list[trail_length - 1]);
4276 else 4276 else
4277 target_friend = 4277 target_friend =
4278 GNUNET_CONTAINER_multipeermap_get (friend_peermap, 4278 GNUNET_CONTAINER_multipeermap_get (friend_peermap,
4279 &source); 4279 &source);
4280 if(NULL == target_friend) 4280 if(NULL == target_friend)
4281 { 4281 {
@@ -4309,13 +4309,13 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer,
4309 final_dest_finger_val, trail_id); 4309 final_dest_finger_val, trail_id);
4310 return GNUNET_OK; 4310 return GNUNET_OK;
4311 } 4311 }
4312 4312
4313 if (trail_length > 0) 4313 if (trail_length > 0)
4314 target_friend = 4314 target_friend =
4315 GNUNET_CONTAINER_multipeermap_get (friend_peermap, 4315 GNUNET_CONTAINER_multipeermap_get (friend_peermap,
4316 &trail_peer_list[trail_length-1]); 4316 &trail_peer_list[trail_length-1]);
4317 else 4317 else
4318 target_friend = 4318 target_friend =
4319 GNUNET_CONTAINER_multipeermap_get (friend_peermap, &source); 4319 GNUNET_CONTAINER_multipeermap_get (friend_peermap, &source);
4320 if (NULL == target_friend) 4320 if (NULL == target_friend)
4321 { 4321 {
@@ -4407,12 +4407,12 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p
4407 } 4407 }
4408 trail_length = (msize - sizeof (struct PeerTrailSetupResultMessage))/ 4408 trail_length = (msize - sizeof (struct PeerTrailSetupResultMessage))/
4409 sizeof (struct GNUNET_PeerIdentity); 4409 sizeof (struct GNUNET_PeerIdentity);
4410 4410
4411 GNUNET_STATISTICS_update (GDS_stats, 4411 GNUNET_STATISTICS_update (GDS_stats,
4412 gettext_noop 4412 gettext_noop
4413 ("# Bytes received from other peers"), msize, 4413 ("# Bytes received from other peers"), msize,
4414 GNUNET_NO); 4414 GNUNET_NO);
4415 4415
4416 is_predecessor = ntohl (trail_result->is_predecessor); 4416 is_predecessor = ntohl (trail_result->is_predecessor);
4417 querying_peer = trail_result->querying_peer; 4417 querying_peer = trail_result->querying_peer;
4418 finger_identity = trail_result->finger_identity; 4418 finger_identity = trail_result->finger_identity;
@@ -4456,7 +4456,7 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p
4456 GNUNET_break_op(0); 4456 GNUNET_break_op(0);
4457 return GNUNET_SYSERR; 4457 return GNUNET_SYSERR;
4458 } 4458 }
4459 4459
4460 //TODO; Refactor code here and above to check if sender peer is correct 4460 //TODO; Refactor code here and above to check if sender peer is correct
4461 if (my_index == 0) 4461 if (my_index == 0)
4462 { 4462 {
@@ -4472,17 +4472,17 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p
4472 { 4472 {
4473 if(my_index == trail_length - 1) 4473 if(my_index == trail_length - 1)
4474 { 4474 {
4475 GNUNET_assert(0 == 4475 GNUNET_assert(0 ==
4476 GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, 4476 GNUNET_CRYPTO_cmp_peer_identity (&finger_identity,
4477 peer)); 4477 peer));
4478 } 4478 }
4479 else 4479 else
4480 GNUNET_assert(0 == 4480 GNUNET_assert(0 ==
4481 GNUNET_CRYPTO_cmp_peer_identity (&trail_peer_list[my_index + 1], 4481 GNUNET_CRYPTO_cmp_peer_identity (&trail_peer_list[my_index + 1],
4482 peer)); 4482 peer));
4483 next_hop = trail_peer_list[my_index - 1]; 4483 next_hop = trail_peer_list[my_index - 1];
4484 } 4484 }
4485 4485
4486 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop); 4486 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop);
4487 if (NULL == target_friend) 4487 if (NULL == target_friend)
4488 { 4488 {
@@ -4592,8 +4592,8 @@ get_shortest_trail (struct FingerInfo *finger,
4592 4592
4593 4593
4594/** 4594/**
4595 * Check if trail_1 and trail_2 have any common element. If yes then join 4595 * Check if trail_1 and trail_2 have any common element. If yes then join
4596 * them at common element. trail_1 always preceeds trail_2 in joined trail. 4596 * them at common element. trail_1 always preceeds trail_2 in joined trail.
4597 * @param trail_1 Trail from source to me, NOT including endpoints. 4597 * @param trail_1 Trail from source to me, NOT including endpoints.
4598 * @param trail_1_len Total number of peers @a trail_1 4598 * @param trail_1_len Total number of peers @a trail_1
4599 * @param trail_2 Trail from me to current predecessor, NOT including endpoints. 4599 * @param trail_2 Trail from me to current predecessor, NOT including endpoints.
@@ -4613,28 +4613,28 @@ check_for_duplicate_entries (const struct GNUNET_PeerIdentity *trail_1,
4613 unsigned int i; 4613 unsigned int i;
4614 unsigned int j; 4614 unsigned int j;
4615 unsigned int k; 4615 unsigned int k;
4616 4616
4617 for (i = 0; i < trail_1_len; i++) 4617 for (i = 0; i < trail_1_len; i++)
4618 { 4618 {
4619 for (j = 0; j < trail_2_len; j++) 4619 for (j = 0; j < trail_2_len; j++)
4620 { 4620 {
4621 if(0 != GNUNET_CRYPTO_cmp_peer_identity (&trail_1[i],&trail_2[j])) 4621 if(0 != GNUNET_CRYPTO_cmp_peer_identity (&trail_1[i],&trail_2[j]))
4622 continue; 4622 continue;
4623 4623
4624 *joined_trail_len = i + (trail_2_len - j); 4624 *joined_trail_len = i + (trail_2_len - j);
4625 joined_trail = GNUNET_malloc (*joined_trail_len * 4625 joined_trail = GNUNET_malloc (*joined_trail_len *
4626 sizeof(struct GNUNET_PeerIdentity)); 4626 sizeof(struct GNUNET_PeerIdentity));
4627 4627
4628 4628
4629 /* Copy all the elements from 0 to i into joined_trail. */ 4629 /* Copy all the elements from 0 to i into joined_trail. */
4630 for(k = 0; k < ( i+1); k++) 4630 for(k = 0; k < ( i+1); k++)
4631 { 4631 {
4632 joined_trail[k] = trail_1[k]; 4632 joined_trail[k] = trail_1[k];
4633 } 4633 }
4634 4634
4635 /* Increment j as entry stored is same as entry stored at i*/ 4635 /* Increment j as entry stored is same as entry stored at i*/
4636 j = j+1; 4636 j = j+1;
4637 4637
4638 /* Copy all the elements from j to trail_2_len-1 to joined trail.*/ 4638 /* Copy all the elements from j to trail_2_len-1 to joined trail.*/
4639 while(k <= (*joined_trail_len - 1)) 4639 while(k <= (*joined_trail_len - 1))
4640 { 4640 {
@@ -4642,30 +4642,30 @@ check_for_duplicate_entries (const struct GNUNET_PeerIdentity *trail_1,
4642 j++; 4642 j++;
4643 k++; 4643 k++;
4644 } 4644 }
4645 4645
4646 return joined_trail; 4646 return joined_trail;
4647 } 4647 }
4648 } 4648 }
4649 4649
4650 /* Here you should join the trails. */ 4650 /* Here you should join the trails. */
4651 *joined_trail_len = trail_1_len + trail_2_len + 1; 4651 *joined_trail_len = trail_1_len + trail_2_len + 1;
4652 joined_trail = GNUNET_malloc (*joined_trail_len * 4652 joined_trail = GNUNET_malloc (*joined_trail_len *
4653 sizeof(struct GNUNET_PeerIdentity)); 4653 sizeof(struct GNUNET_PeerIdentity));
4654 4654
4655 4655
4656 for(i = 0; i < trail_1_len;i++) 4656 for(i = 0; i < trail_1_len;i++)
4657 { 4657 {
4658 joined_trail[i] = trail_1[i]; 4658 joined_trail[i] = trail_1[i];
4659 } 4659 }
4660 4660
4661 joined_trail[i] = my_identity; 4661 joined_trail[i] = my_identity;
4662 i++; 4662 i++;
4663 4663
4664 for (j = 0; i < *joined_trail_len; i++,j++) 4664 for (j = 0; i < *joined_trail_len; i++,j++)
4665 { 4665 {
4666 joined_trail[i] = trail_2[j]; 4666 joined_trail[i] = trail_2[j];
4667 } 4667 }
4668 4668
4669 return joined_trail; 4669 return joined_trail;
4670} 4670}
4671 4671
@@ -4694,20 +4694,20 @@ get_trail_src_to_curr_pred (struct GNUNET_PeerIdentity source_peer,
4694 unsigned int j; 4694 unsigned int j;
4695 4695
4696 current_predecessor = &finger_table[PREDECESSOR_FINGER_ID]; 4696 current_predecessor = &finger_table[PREDECESSOR_FINGER_ID];
4697 4697
4698 /* Check if trail_src_to_me contains current_predecessor. */ 4698 /* Check if trail_src_to_me contains current_predecessor. */
4699 for (i = 0; i < trail_src_to_me_len; i++) 4699 for (i = 0; i < trail_src_to_me_len; i++)
4700 { 4700 {
4701 if(0 != GNUNET_CRYPTO_cmp_peer_identity(&trail_src_to_me[i], 4701 if(0 != GNUNET_CRYPTO_cmp_peer_identity(&trail_src_to_me[i],
4702 &current_predecessor->finger_identity)) 4702 &current_predecessor->finger_identity))
4703 continue; 4703 continue;
4704 4704
4705 4705
4706 *trail_src_to_curr_pred_length = i; 4706 *trail_src_to_curr_pred_length = i;
4707 4707
4708 if(0 == i) 4708 if(0 == i)
4709 return NULL; 4709 return NULL;
4710 4710
4711 trail_src_to_curr_pred = GNUNET_malloc (*trail_src_to_curr_pred_length * 4711 trail_src_to_curr_pred = GNUNET_malloc (*trail_src_to_curr_pred_length *
4712 sizeof(struct GNUNET_PeerIdentity)); 4712 sizeof(struct GNUNET_PeerIdentity));
4713 for(j = 0; j < i;j++) 4713 for(j = 0; j < i;j++)
@@ -4715,17 +4715,17 @@ get_trail_src_to_curr_pred (struct GNUNET_PeerIdentity source_peer,
4715 return trail_src_to_curr_pred; 4715 return trail_src_to_curr_pred;
4716 } 4716 }
4717 4717
4718 4718
4719 trail_me_to_curr_pred = get_shortest_trail (current_predecessor, 4719 trail_me_to_curr_pred = get_shortest_trail (current_predecessor,
4720 &trail_me_to_curr_pred_length); 4720 &trail_me_to_curr_pred_length);
4721 4721
4722 /* Check if trail contains the source_peer. */ 4722 /* Check if trail contains the source_peer. */
4723 for(i = trail_me_to_curr_pred_length - 1; i >= 0; i--) 4723 for(i = trail_me_to_curr_pred_length - 1; i >= 0; i--)
4724 { 4724 {
4725 if(0 != GNUNET_CRYPTO_cmp_peer_identity (&source_peer, 4725 if(0 != GNUNET_CRYPTO_cmp_peer_identity (&source_peer,
4726 &trail_me_to_curr_pred[i])) 4726 &trail_me_to_curr_pred[i]))
4727 continue; 4727 continue;
4728 4728
4729 /* Source is NOT part of trail. */ 4729 /* Source is NOT part of trail. */
4730 i = i+1; 4730 i = i+1;
4731 4731
@@ -4736,11 +4736,11 @@ get_trail_src_to_curr_pred (struct GNUNET_PeerIdentity source_peer,
4736 *trail_src_to_curr_pred_length = 0; 4736 *trail_src_to_curr_pred_length = 0;
4737 return NULL; 4737 return NULL;
4738 } 4738 }
4739 4739
4740 *trail_src_to_curr_pred_length = trail_me_to_curr_pred_length - i; 4740 *trail_src_to_curr_pred_length = trail_me_to_curr_pred_length - i;
4741 trail_src_to_curr_pred = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)* 4741 trail_src_to_curr_pred = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)*
4742 *trail_src_to_curr_pred_length); 4742 *trail_src_to_curr_pred_length);
4743 4743
4744 for(j = 0; j < *trail_src_to_curr_pred_length; i++,j++) 4744 for(j = 0; j < *trail_src_to_curr_pred_length; i++,j++)
4745 { 4745 {
4746 trail_src_to_curr_pred[j] = trail_me_to_curr_pred[i]; 4746 trail_src_to_curr_pred[j] = trail_me_to_curr_pred[i];
@@ -4748,13 +4748,13 @@ get_trail_src_to_curr_pred (struct GNUNET_PeerIdentity source_peer,
4748 GNUNET_free_non_null(trail_me_to_curr_pred); 4748 GNUNET_free_non_null(trail_me_to_curr_pred);
4749 return trail_src_to_curr_pred; 4749 return trail_src_to_curr_pred;
4750 } 4750 }
4751 4751
4752 unsigned int len; 4752 unsigned int len;
4753 trail_src_to_curr_pred = check_for_duplicate_entries (trail_src_to_me, 4753 trail_src_to_curr_pred = check_for_duplicate_entries (trail_src_to_me,
4754 trail_src_to_me_len, 4754 trail_src_to_me_len,
4755 trail_me_to_curr_pred, 4755 trail_me_to_curr_pred,
4756 trail_me_to_curr_pred_length, 4756 trail_me_to_curr_pred_length,
4757 &len); 4757 &len);
4758 *trail_src_to_curr_pred_length = len; 4758 *trail_src_to_curr_pred_length = len;
4759 GNUNET_free_non_null(trail_me_to_curr_pred); 4759 GNUNET_free_non_null(trail_me_to_curr_pred);
4760 return trail_src_to_curr_pred; 4760 return trail_src_to_curr_pred;
@@ -4802,7 +4802,7 @@ update_predecessor (struct GNUNET_PeerIdentity finger,
4802 GNUNET_assert(NULL != GNUNET_CONTAINER_multipeermap_get(friend_peermap, 4802 GNUNET_assert(NULL != GNUNET_CONTAINER_multipeermap_get(friend_peermap,
4803 &trail[trail_length-1])); 4803 &trail[trail_length-1]));
4804 trail_to_new_predecessor = invert_trail (trail, trail_length); 4804 trail_to_new_predecessor = invert_trail (trail, trail_length);
4805 4805
4806 /* Add an entry in your routing table. */ 4806 /* Add an entry in your routing table. */
4807 GDS_ROUTING_add (trail_to_new_predecessor_id, 4807 GDS_ROUTING_add (trail_to_new_predecessor_id,
4808 my_identity, 4808 my_identity,
@@ -4857,7 +4857,7 @@ compare_and_update_predecessor (struct GNUNET_PeerIdentity finger,
4857 update_predecessor (finger, trail, trail_length); 4857 update_predecessor (finger, trail, trail_length);
4858 return; 4858 return;
4859 } 4859 }
4860 4860
4861 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&current_predecessor->finger_identity, 4861 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&current_predecessor->finger_identity,
4862 &finger)) 4862 &finger))
4863 { 4863 {
@@ -4905,7 +4905,7 @@ handle_dht_p2p_verify_successor(void *cls,
4905 struct GNUNET_PeerIdentity *trail_src_to_curr_pred; 4905 struct GNUNET_PeerIdentity *trail_src_to_curr_pred;
4906 unsigned int trail_length; 4906 unsigned int trail_length;
4907 size_t msize; 4907 size_t msize;
4908 4908
4909 msize = ntohs (message->size); 4909 msize = ntohs (message->size);
4910 4910
4911 if (msize < sizeof (struct PeerVerifySuccessorMessage)) 4911 if (msize < sizeof (struct PeerVerifySuccessorMessage))
@@ -4923,29 +4923,29 @@ handle_dht_p2p_verify_successor(void *cls,
4923 GNUNET_break_op (0); 4923 GNUNET_break_op (0);
4924 return GNUNET_OK; 4924 return GNUNET_OK;
4925 } 4925 }
4926 4926
4927 GNUNET_STATISTICS_update (GDS_stats, 4927 GNUNET_STATISTICS_update (GDS_stats,
4928 gettext_noop 4928 gettext_noop
4929 ("# Bytes received from other peers"), msize, 4929 ("# Bytes received from other peers"), msize,
4930 GNUNET_NO); 4930 GNUNET_NO);
4931 4931
4932 trail_id = vsm->trail_id; 4932 trail_id = vsm->trail_id;
4933 source_peer = vsm->source_peer; 4933 source_peer = vsm->source_peer;
4934 successor = vsm->successor; 4934 successor = vsm->successor;
4935 trail = (struct GNUNET_PeerIdentity *)&vsm[1]; 4935 trail = (struct GNUNET_PeerIdentity *)&vsm[1];
4936 4936
4937 /* I am NOT the successor of source_peer. Pass the message to next_hop on 4937 /* I am NOT the successor of source_peer. Pass the message to next_hop on
4938 * the trail. */ 4938 * the trail. */
4939 if(0 != (GNUNET_CRYPTO_cmp_peer_identity (&successor, &my_identity))) 4939 if(0 != (GNUNET_CRYPTO_cmp_peer_identity (&successor, &my_identity)))
4940 { 4940 {
4941 next_hop = GDS_ROUTING_get_next_hop (trail_id, GDS_ROUTING_SRC_TO_DEST); 4941 next_hop = GDS_ROUTING_get_next_hop (trail_id, GDS_ROUTING_SRC_TO_DEST);
4942 if (NULL == next_hop) 4942 if (NULL == next_hop)
4943 { 4943 {
4944 return GNUNET_OK; 4944 return GNUNET_OK;
4945 } 4945 }
4946 4946
4947 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); 4947 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop);
4948 4948
4949 if(NULL == target_friend) 4949 if(NULL == target_friend)
4950 { 4950 {
4951 GNUNET_break_op(0); 4951 GNUNET_break_op(0);
@@ -4963,12 +4963,12 @@ handle_dht_p2p_verify_successor(void *cls,
4963 * it. */ 4963 * it. */
4964 compare_and_update_predecessor (source_peer, trail, trail_length); 4964 compare_and_update_predecessor (source_peer, trail, trail_length);
4965 current_predecessor = finger_table[PREDECESSOR_FINGER_ID]; 4965 current_predecessor = finger_table[PREDECESSOR_FINGER_ID];
4966 4966
4967 /* Is source of this message NOT my predecessor. */ 4967 /* Is source of this message NOT my predecessor. */
4968 if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&current_predecessor.finger_identity, 4968 if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&current_predecessor.finger_identity,
4969 &source_peer))) 4969 &source_peer)))
4970 { 4970 {
4971 trail_src_to_curr_pred = 4971 trail_src_to_curr_pred =
4972 get_trail_src_to_curr_pred (source_peer, 4972 get_trail_src_to_curr_pred (source_peer,
4973 trail, 4973 trail,
4974 trail_length, 4974 trail_length,
@@ -4979,7 +4979,7 @@ handle_dht_p2p_verify_successor(void *cls,
4979 trail_src_to_curr_pred_len = trail_length; 4979 trail_src_to_curr_pred_len = trail_length;
4980 unsigned int i; 4980 unsigned int i;
4981 4981
4982 trail_src_to_curr_pred = 4982 trail_src_to_curr_pred =
4983 GNUNET_malloc (sizeof(struct GNUNET_PeerIdentity) 4983 GNUNET_malloc (sizeof(struct GNUNET_PeerIdentity)
4984 *trail_src_to_curr_pred_len); 4984 *trail_src_to_curr_pred_len);
4985 for(i = 0; i < trail_src_to_curr_pred_len; i++) 4985 for(i = 0; i < trail_src_to_curr_pred_len; i++)
@@ -4987,7 +4987,7 @@ handle_dht_p2p_verify_successor(void *cls,
4987 trail_src_to_curr_pred[i] = trail[i]; 4987 trail_src_to_curr_pred[i] = trail[i];
4988 } 4988 }
4989 } 4989 }
4990 4990
4991 GNUNET_assert (NULL != 4991 GNUNET_assert (NULL !=
4992 (target_friend = 4992 (target_friend =
4993 GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer))); 4993 GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer)));
@@ -5031,7 +5031,7 @@ check_trail_me_to_probable_succ (struct GNUNET_PeerIdentity probable_successor,
5031 *trail_to_new_successor_length = 0; 5031 *trail_to_new_successor_length = 0;
5032 return trail_to_new_successor; 5032 return trail_to_new_successor;
5033 } 5033 }
5034 5034
5035 /* Is there any friend of yours in this trail. */ 5035 /* Is there any friend of yours in this trail. */
5036 if(trail_me_to_probable_successor_len > 1) 5036 if(trail_me_to_probable_successor_len > 1)
5037 { 5037 {
@@ -5045,12 +5045,12 @@ check_trail_me_to_probable_succ (struct GNUNET_PeerIdentity probable_successor,
5045 trail_to_new_successor = GNUNET_malloc (sizeof(struct GNUNET_PeerIdentity)* 5045 trail_to_new_successor = GNUNET_malloc (sizeof(struct GNUNET_PeerIdentity)*
5046 *trail_to_new_successor_length); 5046 *trail_to_new_successor_length);
5047 5047
5048 5048
5049 for(j = 0; j < *trail_to_new_successor_length; i++,j++) 5049 for(j = 0; j < *trail_to_new_successor_length; i++,j++)
5050 { 5050 {
5051 trail_to_new_successor[j] = trail_me_to_probable_successor[i]; 5051 trail_to_new_successor[j] = trail_me_to_probable_successor[i];
5052 } 5052 }
5053 5053
5054 return trail_to_new_successor; 5054 return trail_to_new_successor;
5055 } 5055 }
5056 } 5056 }
@@ -5060,7 +5060,7 @@ check_trail_me_to_probable_succ (struct GNUNET_PeerIdentity probable_successor,
5060} 5060}
5061 5061
5062// TODO: Move up 5062// TODO: Move up
5063struct SendNotifyContext 5063struct SendNotifyContext
5064{ 5064{
5065 struct GNUNET_PeerIdentity source_peer; 5065 struct GNUNET_PeerIdentity source_peer;
5066 struct GNUNET_PeerIdentity successor; 5066 struct GNUNET_PeerIdentity successor;
@@ -5085,7 +5085,7 @@ send_notify_new_successor (void *cls,
5085 * @param curr_succ Peer to which we sent the verify successor message. It may 5085 * @param curr_succ Peer to which we sent the verify successor message. It may
5086 * or may not be our real current successor, as we may have few iterations of 5086 * or may not be our real current successor, as we may have few iterations of
5087 * find finger trail task. 5087 * find finger trail task.
5088 * @param probable_successor Peer which should be our successor accroding to @a 5088 * @param probable_successor Peer which should be our successor accroding to @a
5089 * curr_succ 5089 * curr_succ
5090 * @param trail List of peers to reach from me to @a probable successor, NOT including 5090 * @param trail List of peers to reach from me to @a probable successor, NOT including
5091 * endpoints. 5091 * endpoints.
@@ -5125,12 +5125,12 @@ compare_and_update_successor (struct GNUNET_PeerIdentity curr_succ,
5125 succ = GNUNET_ntohll(succ); 5125 succ = GNUNET_ntohll(succ);
5126 GNUNET_asprintf (&key, "XDHT:%s:", my_id_str); 5126 GNUNET_asprintf (&key, "XDHT:%s:", my_id_str);
5127 GNUNET_free (my_id_str); 5127 GNUNET_free (my_id_str);
5128 5128
5129 GNUNET_STATISTICS_set (GDS_stats, key, succ, 0); 5129 GNUNET_STATISTICS_set (GDS_stats, key, succ, 0);
5130 GNUNET_free (key); 5130 GNUNET_free (key);
5131 } 5131 }
5132 if (send_verify_successor_task == GNUNET_SCHEDULER_NO_TASK) 5132 if (send_verify_successor_task == GNUNET_SCHEDULER_NO_TASK)
5133 send_verify_successor_task = 5133 send_verify_successor_task =
5134 GNUNET_SCHEDULER_add_delayed(verify_successor_next_send_time, 5134 GNUNET_SCHEDULER_add_delayed(verify_successor_next_send_time,
5135 &send_verify_successor_message, 5135 &send_verify_successor_message,
5136 NULL); 5136 NULL);
@@ -5144,13 +5144,13 @@ compare_and_update_successor (struct GNUNET_PeerIdentity curr_succ,
5144 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&closest_peer , 5144 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&closest_peer ,
5145 &current_successor->finger_identity)) 5145 &current_successor->finger_identity))
5146 { 5146 {
5147 //FIXME: Is this a good place to return the stats. 5147 //FIXME: Is this a good place to return the stats.
5148 if ((NULL != GDS_stats)) 5148 if ((NULL != GDS_stats))
5149 { 5149 {
5150 char *my_id_str; 5150 char *my_id_str;
5151 uint64_t succ; 5151 uint64_t succ;
5152 char *key; 5152 char *key;
5153 5153
5154 my_id_str = GNUNET_strdup (GNUNET_i2s_full (&my_identity)); 5154 my_id_str = GNUNET_strdup (GNUNET_i2s_full (&my_identity));
5155 memcpy(&succ, &current_successor->finger_identity, sizeof(uint64_t)); 5155 memcpy(&succ, &current_successor->finger_identity, sizeof(uint64_t));
5156 GNUNET_asprintf (&key, "XDHT:%s:", my_id_str); 5156 GNUNET_asprintf (&key, "XDHT:%s:", my_id_str);
@@ -5158,25 +5158,25 @@ compare_and_update_successor (struct GNUNET_PeerIdentity curr_succ,
5158 GNUNET_STATISTICS_set (GDS_stats, key, succ, 0); 5158 GNUNET_STATISTICS_set (GDS_stats, key, succ, 0);
5159 GNUNET_free (key); 5159 GNUNET_free (key);
5160 } 5160 }
5161 5161
5162 if(0 == successor_times) 5162 if(0 == successor_times)
5163 { 5163 {
5164// successor_times = 3; 5164// successor_times = 3;
5165 verify_successor_next_send_time = 5165 verify_successor_next_send_time =
5166 GNUNET_TIME_STD_BACKOFF (verify_successor_next_send_time); 5166 GNUNET_TIME_STD_BACKOFF (verify_successor_next_send_time);
5167 } 5167 }
5168 else 5168 else
5169 successor_times--; 5169 successor_times--;
5170 5170
5171 5171
5172 if (send_verify_successor_task == GNUNET_SCHEDULER_NO_TASK) 5172 if (send_verify_successor_task == GNUNET_SCHEDULER_NO_TASK)
5173 send_verify_successor_task = 5173 send_verify_successor_task =
5174 GNUNET_SCHEDULER_add_delayed(verify_successor_next_send_time, 5174 GNUNET_SCHEDULER_add_delayed(verify_successor_next_send_time,
5175 &send_verify_successor_message, 5175 &send_verify_successor_message,
5176 NULL); 5176 NULL);
5177 return; 5177 return;
5178 } 5178 }
5179 5179
5180 /* Probable successor is the closest peer.*/ 5180 /* Probable successor is the closest peer.*/
5181 if(trail_length > 0) 5181 if(trail_length > 0)
5182 { 5182 {
@@ -5188,7 +5188,7 @@ compare_and_update_successor (struct GNUNET_PeerIdentity curr_succ,
5188 GNUNET_assert(NULL != GNUNET_CONTAINER_multipeermap_get(friend_peermap, 5188 GNUNET_assert(NULL != GNUNET_CONTAINER_multipeermap_get(friend_peermap,
5189 &probable_successor)); 5189 &probable_successor));
5190 } 5190 }
5191 5191
5192 trail_me_to_probable_succ_len = 0; 5192 trail_me_to_probable_succ_len = 0;
5193 trail_me_to_probable_succ = 5193 trail_me_to_probable_succ =
5194 check_trail_me_to_probable_succ (probable_successor, 5194 check_trail_me_to_probable_succ (probable_successor,
@@ -5220,25 +5220,25 @@ compare_and_update_successor (struct GNUNET_PeerIdentity curr_succ,
5220 5220
5221 add_new_finger (probable_successor, trail_me_to_probable_succ, 5221 add_new_finger (probable_successor, trail_me_to_probable_succ,
5222 trail_me_to_probable_succ_len, trail_id, 0); 5222 trail_me_to_probable_succ_len, trail_id, 0);
5223 5223
5224 struct SendNotifyContext *notify_ctx; 5224 struct SendNotifyContext *notify_ctx;
5225 5225
5226 notify_ctx = GNUNET_new(struct SendNotifyContext); 5226 notify_ctx = GNUNET_new(struct SendNotifyContext);
5227 5227
5228 notify_ctx->source_peer = my_identity; 5228 notify_ctx->source_peer = my_identity;
5229 notify_ctx->successor = probable_successor; 5229 notify_ctx->successor = probable_successor;
5230 notify_ctx->successor_trail = 5230 notify_ctx->successor_trail =
5231 GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity) * trail_me_to_probable_succ_len); 5231 GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity) * trail_me_to_probable_succ_len);
5232 memcpy(notify_ctx->successor_trail, trail_me_to_probable_succ, 5232 memcpy(notify_ctx->successor_trail, trail_me_to_probable_succ,
5233 sizeof(struct GNUNET_PeerIdentity) * trail_me_to_probable_succ_len); 5233 sizeof(struct GNUNET_PeerIdentity) * trail_me_to_probable_succ_len);
5234 notify_ctx->successor_trail_length = trail_me_to_probable_succ_len; 5234 notify_ctx->successor_trail_length = trail_me_to_probable_succ_len;
5235 notify_ctx->succesor_trail_id = trail_id; 5235 notify_ctx->succesor_trail_id = trail_id;
5236 notify_ctx->target_friend = target_friend; 5236 notify_ctx->target_friend = target_friend;
5237 notify_ctx->num_retries_scheduled = 0; 5237 notify_ctx->num_retries_scheduled = 0;
5238 5238
5239 // TODO: Check if we should verify before schedule if already scheduled. 5239 // TODO: Check if we should verify before schedule if already scheduled.
5240 GNUNET_SCHEDULER_add_now(&send_notify_new_successor, (void*)notify_ctx); 5240 GNUNET_SCHEDULER_add_now(&send_notify_new_successor, (void*)notify_ctx);
5241 5241
5242 return; 5242 return;
5243} 5243}
5244 5244
@@ -5250,7 +5250,7 @@ send_notify_new_successor (void *cls,
5250 * tc) 5250 * tc)
5251{ 5251{
5252 struct SendNotifyContext *ctx = (struct SendNotifyContext *) cls; 5252 struct SendNotifyContext *ctx = (struct SendNotifyContext *) cls;
5253 5253
5254 GDS_NEIGHBOURS_send_notify_new_successor (ctx->source_peer, 5254 GDS_NEIGHBOURS_send_notify_new_successor (ctx->source_peer,
5255 ctx->successor, 5255 ctx->successor,
5256 ctx->successor_trail, 5256 ctx->successor_trail,
@@ -5258,7 +5258,7 @@ send_notify_new_successor (void *cls,
5258 ctx->succesor_trail_id, 5258 ctx->succesor_trail_id,
5259 ctx->target_friend); 5259 ctx->target_friend);
5260 5260
5261 if (0 == ctx->num_retries_scheduled && 5261 if (0 == ctx->num_retries_scheduled &&
5262 send_notify_new_successor_retry_task != GNUNET_SCHEDULER_NO_TASK) 5262 send_notify_new_successor_retry_task != GNUNET_SCHEDULER_NO_TASK)
5263 { 5263 {
5264 // Result from previous notify successos hasn't arrived, so the retry task 5264 // Result from previous notify successos hasn't arrived, so the retry task
@@ -5270,7 +5270,7 @@ send_notify_new_successor (void *cls,
5270 GNUNET_free (old_notify_ctx); 5270 GNUNET_free (old_notify_ctx);
5271 send_notify_new_successor_retry_task = GNUNET_SCHEDULER_NO_TASK; 5271 send_notify_new_successor_retry_task = GNUNET_SCHEDULER_NO_TASK;
5272 } 5272 }
5273 5273
5274 ctx->num_retries_scheduled++; 5274 ctx->num_retries_scheduled++;
5275 send_notify_new_successor_retry_task = GNUNET_SCHEDULER_add_delayed(notify_successor_retry_time, 5275 send_notify_new_successor_retry_task = GNUNET_SCHEDULER_add_delayed(notify_successor_retry_time,
5276 &send_notify_new_successor, 5276 &send_notify_new_successor,
@@ -5300,7 +5300,7 @@ handle_dht_p2p_verify_successor_result(void *cls,
5300 const struct GNUNET_PeerIdentity *trail; 5300 const struct GNUNET_PeerIdentity *trail;
5301 unsigned int trail_length; 5301 unsigned int trail_length;
5302 size_t msize; 5302 size_t msize;
5303 5303
5304 msize = ntohs (message->size); 5304 msize = ntohs (message->size);
5305 if (msize < sizeof (struct PeerVerifySuccessorResultMessage)) 5305 if (msize < sizeof (struct PeerVerifySuccessorResultMessage))
5306 { 5306 {
@@ -5317,19 +5317,19 @@ handle_dht_p2p_verify_successor_result(void *cls,
5317 } 5317 }
5318 trail_length = (msize - sizeof (struct PeerVerifySuccessorResultMessage))/ 5318 trail_length = (msize - sizeof (struct PeerVerifySuccessorResultMessage))/
5319 sizeof (struct GNUNET_PeerIdentity); 5319 sizeof (struct GNUNET_PeerIdentity);
5320 5320
5321 GNUNET_STATISTICS_update (GDS_stats, 5321 GNUNET_STATISTICS_update (GDS_stats,
5322 gettext_noop 5322 gettext_noop
5323 ("# Bytes received from other peers"), msize, 5323 ("# Bytes received from other peers"), msize,
5324 GNUNET_NO); 5324 GNUNET_NO);
5325 5325
5326 trail = (const struct GNUNET_PeerIdentity *) &vsrm[1]; 5326 trail = (const struct GNUNET_PeerIdentity *) &vsrm[1];
5327 querying_peer = vsrm->querying_peer; 5327 querying_peer = vsrm->querying_peer;
5328 trail_direction = ntohl (vsrm->trail_direction); 5328 trail_direction = ntohl (vsrm->trail_direction);
5329 trail_id = vsrm->trail_id; 5329 trail_id = vsrm->trail_id;
5330 probable_successor = vsrm->probable_successor; 5330 probable_successor = vsrm->probable_successor;
5331 current_successor = vsrm->current_successor; 5331 current_successor = vsrm->current_successor;
5332 5332
5333 /* I am the querying_peer. */ 5333 /* I am the querying_peer. */
5334 if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&querying_peer, &my_identity))) 5334 if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&querying_peer, &my_identity)))
5335 { 5335 {
@@ -5345,7 +5345,7 @@ handle_dht_p2p_verify_successor_result(void *cls,
5345 probable_successor, trail, trail_length); 5345 probable_successor, trail, trail_length);
5346 return GNUNET_OK; 5346 return GNUNET_OK;
5347 } 5347 }
5348 5348
5349 /*If you are not the querying peer then pass on the message */ 5349 /*If you are not the querying peer then pass on the message */
5350 if(NULL == (next_hop = 5350 if(NULL == (next_hop =
5351 GDS_ROUTING_get_next_hop (trail_id, trail_direction))) 5351 GDS_ROUTING_get_next_hop (trail_id, trail_direction)))
@@ -5415,21 +5415,21 @@ handle_dht_p2p_notify_new_successor(void *cls,
5415 gettext_noop 5415 gettext_noop
5416 ("# Bytes received from other peers"), msize, 5416 ("# Bytes received from other peers"), msize,
5417 GNUNET_NO); 5417 GNUNET_NO);
5418 5418
5419 trail = (struct GNUNET_PeerIdentity *) &nsm[1]; 5419 trail = (struct GNUNET_PeerIdentity *) &nsm[1];
5420 source = nsm->source_peer; 5420 source = nsm->source_peer;
5421 new_successor = nsm->new_successor; 5421 new_successor = nsm->new_successor;
5422 trail_id = nsm->trail_id; 5422 trail_id = nsm->trail_id;
5423 5423
5424 /* I am the new_successor to source_peer. */ 5424 /* I am the new_successor to source_peer. */
5425 if ( 0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &new_successor)) 5425 if ( 0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &new_successor))
5426 { 5426 {
5427 if(trail_length > 0) 5427 if(trail_length > 0)
5428 GNUNET_assert(0 == GNUNET_CRYPTO_cmp_peer_identity(&trail[trail_length - 1], 5428 GNUNET_assert(0 == GNUNET_CRYPTO_cmp_peer_identity(&trail[trail_length - 1],
5429 peer)); 5429 peer));
5430 else 5430 else
5431 GNUNET_assert(0 == GNUNET_CRYPTO_cmp_peer_identity(&source, peer)); 5431 GNUNET_assert(0 == GNUNET_CRYPTO_cmp_peer_identity(&source, peer));
5432 5432
5433 compare_and_update_predecessor (source, trail, trail_length); 5433 compare_and_update_predecessor (source, trail, trail_length);
5434 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer); 5434 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer);
5435 GDS_NEIGHBOURS_send_notify_succcessor_confirmation (trail_id, 5435 GDS_NEIGHBOURS_send_notify_succcessor_confirmation (trail_id,
@@ -5457,7 +5457,7 @@ handle_dht_p2p_notify_new_successor(void *cls,
5457 next_hop = new_successor; 5457 next_hop = new_successor;
5458 else 5458 else
5459 next_hop = trail[my_index + 1]; 5459 next_hop = trail[my_index + 1];
5460 5460
5461 GDS_ROUTING_add(trail_id, *peer, next_hop); 5461 GDS_ROUTING_add(trail_id, *peer, next_hop);
5462 target_friend = 5462 target_friend =
5463 GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop); 5463 GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop);
@@ -5484,7 +5484,7 @@ handle_dht_p2p_notify_new_successor(void *cls,
5484static int 5484static int
5485handle_dht_p2p_notify_succ_confirmation (void *cls, 5485handle_dht_p2p_notify_succ_confirmation (void *cls,
5486 const struct GNUNET_PeerIdentity *peer, 5486 const struct GNUNET_PeerIdentity *peer,
5487 const struct GNUNET_MessageHeader *message) 5487 const struct GNUNET_MessageHeader *message)
5488{ 5488{
5489 const struct PeerNotifyConfirmationMessage *notify_confirmation; 5489 const struct PeerNotifyConfirmationMessage *notify_confirmation;
5490 enum GDS_ROUTING_trail_direction trail_direction; 5490 enum GDS_ROUTING_trail_direction trail_direction;
@@ -5492,7 +5492,7 @@ handle_dht_p2p_notify_succ_confirmation (void *cls,
5492 struct FriendInfo *target_friend; 5492 struct FriendInfo *target_friend;
5493 struct GNUNET_PeerIdentity *next_hop; 5493 struct GNUNET_PeerIdentity *next_hop;
5494 size_t msize; 5494 size_t msize;
5495 5495
5496 msize = ntohs (message->size); 5496 msize = ntohs (message->size);
5497 5497
5498 if (msize != sizeof (struct PeerNotifyConfirmationMessage)) 5498 if (msize != sizeof (struct PeerNotifyConfirmationMessage))
@@ -5504,21 +5504,21 @@ handle_dht_p2p_notify_succ_confirmation (void *cls,
5504 gettext_noop 5504 gettext_noop
5505 ("# Bytes received from other peers"), msize, 5505 ("# Bytes received from other peers"), msize,
5506 GNUNET_NO); 5506 GNUNET_NO);
5507 5507
5508 notify_confirmation = (const struct PeerNotifyConfirmationMessage *) message; 5508 notify_confirmation = (const struct PeerNotifyConfirmationMessage *) message;
5509 trail_direction = ntohl (notify_confirmation->trail_direction); 5509 trail_direction = ntohl (notify_confirmation->trail_direction);
5510 trail_id = notify_confirmation->trail_id; 5510 trail_id = notify_confirmation->trail_id;
5511 5511
5512 next_hop = GDS_ROUTING_get_next_hop (trail_id, trail_direction); 5512 next_hop = GDS_ROUTING_get_next_hop (trail_id, trail_direction);
5513 if (NULL == next_hop) 5513 if (NULL == next_hop)
5514 { 5514 {
5515 /* The source of notify new successor, might have found even a better 5515 /* The source of notify new successor, might have found even a better
5516 successor. In that case it send a trail teardown message, and hence, 5516 successor. In that case it send a trail teardown message, and hence,
5517 the next hop is NULL. */ 5517 the next hop is NULL. */
5518 //Fixme: Add some print to confirm the above theory. 5518 //Fixme: Add some print to confirm the above theory.
5519 return GNUNET_OK; 5519 return GNUNET_OK;
5520 } 5520 }
5521 5521
5522 /* I peer which sent the notify successor message to the successor. */ 5522 /* I peer which sent the notify successor message to the successor. */
5523 if (0 == GNUNET_CRYPTO_cmp_peer_identity (next_hop, &my_identity)) 5523 if (0 == GNUNET_CRYPTO_cmp_peer_identity (next_hop, &my_identity))
5524 { 5524 {
@@ -5527,7 +5527,7 @@ handle_dht_p2p_notify_succ_confirmation (void *cls,
5527 * which may or may not be source of this message. This message is used 5527 * which may or may not be source of this message. This message is used
5528 * only to ensure that we have a path setup to reach to our successor. 5528 * only to ensure that we have a path setup to reach to our successor.
5529 */ 5529 */
5530 5530
5531 // TODO: cancel schedule of notify_successor_retry_task 5531 // TODO: cancel schedule of notify_successor_retry_task
5532 if (send_notify_new_successor_retry_task != GNUNET_SCHEDULER_NO_TASK) 5532 if (send_notify_new_successor_retry_task != GNUNET_SCHEDULER_NO_TASK)
5533 { 5533 {
@@ -5539,11 +5539,11 @@ handle_dht_p2p_notify_succ_confirmation (void *cls,
5539 } 5539 }
5540 if (send_verify_successor_task == GNUNET_SCHEDULER_NO_TASK) 5540 if (send_verify_successor_task == GNUNET_SCHEDULER_NO_TASK)
5541 { 5541 {
5542 verify_successor_next_send_time.rel_value_us = 5542 verify_successor_next_send_time.rel_value_us =
5543 DHT_SEND_VERIFY_SUCCESSOR_INTERVAL.rel_value_us + 5543 DHT_SEND_VERIFY_SUCCESSOR_INTERVAL.rel_value_us +
5544 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 5544 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
5545 DHT_SEND_VERIFY_SUCCESSOR_INTERVAL.rel_value_us); 5545 DHT_SEND_VERIFY_SUCCESSOR_INTERVAL.rel_value_us);
5546 send_verify_successor_task = 5546 send_verify_successor_task =
5547 GNUNET_SCHEDULER_add_delayed(verify_successor_next_send_time, 5547 GNUNET_SCHEDULER_add_delayed(verify_successor_next_send_time,
5548 &send_verify_successor_message, 5548 &send_verify_successor_message,
5549 NULL); 5549 NULL);
@@ -5608,7 +5608,7 @@ handle_dht_p2p_trail_setup_rejection (void *cls,
5608 gettext_noop 5608 gettext_noop
5609 ("# Bytes received from other peers"), msize, 5609 ("# Bytes received from other peers"), msize,
5610 GNUNET_NO); 5610 GNUNET_NO);
5611 5611
5612 trail_peer_list = (const struct GNUNET_PeerIdentity *)&trail_rejection[1]; 5612 trail_peer_list = (const struct GNUNET_PeerIdentity *)&trail_rejection[1];
5613 is_predecessor = ntohl (trail_rejection->is_predecessor); 5613 is_predecessor = ntohl (trail_rejection->is_predecessor);
5614 congestion_timeout = trail_rejection->congestion_time; 5614 congestion_timeout = trail_rejection->congestion_time;
@@ -5639,7 +5639,7 @@ handle_dht_p2p_trail_setup_rejection (void *cls,
5639 /* First remove yourself from the trail. */ 5639 /* First remove yourself from the trail. */
5640 unsigned int new_trail_length = trail_length - 1; 5640 unsigned int new_trail_length = trail_length - 1;
5641 struct GNUNET_PeerIdentity trail[new_trail_length]; 5641 struct GNUNET_PeerIdentity trail[new_trail_length];
5642 5642
5643 memcpy (trail, trail_peer_list, new_trail_length * sizeof(struct GNUNET_PeerIdentity)); 5643 memcpy (trail, trail_peer_list, new_trail_length * sizeof(struct GNUNET_PeerIdentity));
5644 if (0 == trail_length) 5644 if (0 == trail_length)
5645 next_peer = source; 5645 next_peer = source;
@@ -5672,9 +5672,9 @@ handle_dht_p2p_trail_setup_rejection (void *cls,
5672 /*Here you are already part of trail. Copy the trail removing yourself. */ 5672 /*Here you are already part of trail. Copy the trail removing yourself. */
5673 unsigned int new_trail_length = trail_length - 1; 5673 unsigned int new_trail_length = trail_length - 1;
5674 struct GNUNET_PeerIdentity trail[new_trail_length]; 5674 struct GNUNET_PeerIdentity trail[new_trail_length];
5675 5675
5676 memcpy (trail, trail_peer_list, new_trail_length * sizeof(struct GNUNET_PeerIdentity)); 5676 memcpy (trail, trail_peer_list, new_trail_length * sizeof(struct GNUNET_PeerIdentity));
5677 5677
5678 if (0 == new_trail_length) 5678 if (0 == new_trail_length)
5679 next_peer = source; 5679 next_peer = source;
5680 else 5680 else
@@ -5683,7 +5683,7 @@ handle_dht_p2p_trail_setup_rejection (void *cls,
5683 } 5683 }
5684 target_friend = 5684 target_friend =
5685 GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_peer); 5685 GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_peer);
5686 5686
5687 if (NULL == target_friend) 5687 if (NULL == target_friend)
5688 { 5688 {
5689 DEBUG ("\nLINE = %d ,No friend found.",__LINE__); 5689 DEBUG ("\nLINE = %d ,No friend found.",__LINE__);
@@ -5702,7 +5702,7 @@ handle_dht_p2p_trail_setup_rejection (void *cls,
5702 { 5702 {
5703 /* Here I was already part of trail. So no need to add. */ 5703 /* Here I was already part of trail. So no need to add. */
5704 target_friend = 5704 target_friend =
5705 GNUNET_CONTAINER_multipeermap_get (friend_peermap, 5705 GNUNET_CONTAINER_multipeermap_get (friend_peermap,
5706 &successor.next_hop); 5706 &successor.next_hop);
5707 if (NULL == target_friend) 5707 if (NULL == target_friend)
5708 { 5708 {
@@ -5710,7 +5710,7 @@ handle_dht_p2p_trail_setup_rejection (void *cls,
5710 GNUNET_break(0); 5710 GNUNET_break(0);
5711 return GNUNET_OK; 5711 return GNUNET_OK;
5712 } 5712 }
5713 5713
5714 GDS_NEIGHBOURS_send_trail_setup (source, 5714 GDS_NEIGHBOURS_send_trail_setup (source,
5715 ultimate_destination_finger_value, 5715 ultimate_destination_finger_value,
5716 successor.best_known_destination, 5716 successor.best_known_destination,
@@ -5752,7 +5752,7 @@ handle_dht_p2p_trail_teardown (void *cls, const struct GNUNET_PeerIdentity *peer
5752 gettext_noop 5752 gettext_noop
5753 ("# Bytes received from other peers"), msize, 5753 ("# Bytes received from other peers"), msize,
5754 GNUNET_NO); 5754 GNUNET_NO);
5755 5755
5756 trail_teardown = (const struct PeerTrailTearDownMessage *) message; 5756 trail_teardown = (const struct PeerTrailTearDownMessage *) message;
5757 trail_direction = ntohl (trail_teardown->trail_direction); 5757 trail_direction = ntohl (trail_teardown->trail_direction);
5758 trail_id = trail_teardown->trail_id; 5758 trail_id = trail_teardown->trail_id;
@@ -5841,7 +5841,7 @@ handle_dht_p2p_add_trail (void *cls, const struct GNUNET_PeerIdentity *peer,
5841 gettext_noop 5841 gettext_noop
5842 ("# Bytes received from other peers"), msize, 5842 ("# Bytes received from other peers"), msize,
5843 GNUNET_NO); 5843 GNUNET_NO);
5844 5844
5845 trail = (const struct GNUNET_PeerIdentity *)&add_trail[1]; 5845 trail = (const struct GNUNET_PeerIdentity *)&add_trail[1];
5846 destination_peer = add_trail->destination_peer; 5846 destination_peer = add_trail->destination_peer;
5847 source_peer = add_trail->source_peer; 5847 source_peer = add_trail->source_peer;
@@ -5915,7 +5915,7 @@ remove_matching_trails (const struct GNUNET_PeerIdentity *disconnected_friend,
5915 current_trail = &finger->trail_list[i]; 5915 current_trail = &finger->trail_list[i];
5916 if (GNUNET_NO == current_trail->is_present) 5916 if (GNUNET_NO == current_trail->is_present)
5917 continue; 5917 continue;
5918 5918
5919 /* First friend to reach to finger is disconnected_peer. */ 5919 /* First friend to reach to finger is disconnected_peer. */
5920 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&current_trail->trail_head->peer, 5920 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&current_trail->trail_head->peer,
5921 disconnected_friend)) 5921 disconnected_friend))
@@ -5969,20 +5969,20 @@ remove_matching_fingers (const struct GNUNET_PeerIdentity *disconnected_peer)
5969 for (i = 0; i < MAX_FINGERS; i++) 5969 for (i = 0; i < MAX_FINGERS; i++)
5970 { 5970 {
5971 current_finger = &finger_table[i]; 5971 current_finger = &finger_table[i];
5972 5972
5973 /* No finger stored at this trail index or I am the finger. */ 5973 /* No finger stored at this trail index or I am the finger. */
5974 if ((GNUNET_NO == current_finger->is_present) || 5974 if ((GNUNET_NO == current_finger->is_present) ||
5975 (0 == GNUNET_CRYPTO_cmp_peer_identity (&current_finger->finger_identity, 5975 (0 == GNUNET_CRYPTO_cmp_peer_identity (&current_finger->finger_identity,
5976 &my_identity))) 5976 &my_identity)))
5977 continue; 5977 continue;
5978 5978
5979 /* Is disconnected_peer a finger? */ 5979 /* Is disconnected_peer a finger? */
5980 if (0 == GNUNET_CRYPTO_cmp_peer_identity (disconnected_peer, 5980 if (0 == GNUNET_CRYPTO_cmp_peer_identity (disconnected_peer,
5981 &current_finger->finger_identity)) 5981 &current_finger->finger_identity))
5982 { 5982 {
5983 remove_existing_finger (current_finger, i); 5983 remove_existing_finger (current_finger, i);
5984 } 5984 }
5985 5985
5986 /* If finger is a friend but not disconnected_friend, then continue. */ 5986 /* If finger is a friend but not disconnected_friend, then continue. */
5987 if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, 5987 if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap,
5988 &current_finger->finger_identity)) 5988 &current_finger->finger_identity))
@@ -6016,7 +6016,7 @@ handle_core_disconnect (void *cls,
6016 struct FriendInfo *remove_friend; 6016 struct FriendInfo *remove_friend;
6017 struct P2PPendingMessage *pos; 6017 struct P2PPendingMessage *pos;
6018 unsigned int discarded; 6018 unsigned int discarded;
6019 6019
6020 /* If disconnected to own identity, then return. */ 6020 /* If disconnected to own identity, then return. */
6021 if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) 6021 if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity)))
6022 return; 6022 return;
@@ -6027,21 +6027,21 @@ handle_core_disconnect (void *cls,
6027 DEBUG("\n friend already disconnected."); 6027 DEBUG("\n friend already disconnected.");
6028 return; 6028 return;
6029 } 6029 }
6030 6030
6031 remove_matching_fingers (peer); 6031 remove_matching_fingers (peer);
6032 GNUNET_assert (GNUNET_SYSERR != GDS_ROUTING_remove_trail_by_peer (peer)); 6032 GNUNET_assert (GNUNET_SYSERR != GDS_ROUTING_remove_trail_by_peer (peer));
6033 GNUNET_assert (GNUNET_YES == 6033 GNUNET_assert (GNUNET_YES ==
6034 GNUNET_CONTAINER_multipeermap_remove (friend_peermap, 6034 GNUNET_CONTAINER_multipeermap_remove (friend_peermap,
6035 peer, 6035 peer,
6036 remove_friend)); 6036 remove_friend));
6037 6037
6038 /* Remove all the messages queued in pending list of this peer is discarded.*/ 6038 /* Remove all the messages queued in pending list of this peer is discarded.*/
6039 if (remove_friend->th != NULL) 6039 if (remove_friend->th != NULL)
6040 { 6040 {
6041 GNUNET_CORE_notify_transmit_ready_cancel(remove_friend->th); 6041 GNUNET_CORE_notify_transmit_ready_cancel(remove_friend->th);
6042 remove_friend->th = NULL; 6042 remove_friend->th = NULL;
6043 } 6043 }
6044 6044
6045 discarded = 0; 6045 discarded = 0;
6046 while (NULL != (pos = remove_friend->head)) 6046 while (NULL != (pos = remove_friend->head))
6047 { 6047 {
@@ -6049,13 +6049,13 @@ handle_core_disconnect (void *cls,
6049 discarded++; 6049 discarded++;
6050 GNUNET_free (pos); 6050 GNUNET_free (pos);
6051 } 6051 }
6052 6052
6053 GNUNET_STATISTICS_update (GDS_stats, 6053 GNUNET_STATISTICS_update (GDS_stats,
6054 gettext_noop 6054 gettext_noop
6055 ("# Queued messages discarded (peer disconnected)"), 6055 ("# Queued messages discarded (peer disconnected)"),
6056 discarded, GNUNET_NO); 6056 discarded, GNUNET_NO);
6057 //GNUNET_free (remove_friend); 6057 //GNUNET_free (remove_friend);
6058 6058
6059 if (0 != GNUNET_CONTAINER_multipeermap_size (friend_peermap)) 6059 if (0 != GNUNET_CONTAINER_multipeermap_size (friend_peermap))
6060 return; 6060 return;
6061 6061
@@ -6094,7 +6094,7 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer_identity)
6094 6094
6095 friend = GNUNET_new (struct FriendInfo); 6095 friend = GNUNET_new (struct FriendInfo);
6096 friend->id = *peer_identity; 6096 friend->id = *peer_identity;
6097 6097
6098 GNUNET_assert (GNUNET_OK == 6098 GNUNET_assert (GNUNET_OK ==
6099 GNUNET_CONTAINER_multipeermap_put (friend_peermap, 6099 GNUNET_CONTAINER_multipeermap_put (friend_peermap,
6100 peer_identity, friend, 6100 peer_identity, friend,
@@ -6102,7 +6102,7 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer_identity)
6102 6102
6103 /* FIXME: now we are not making a distinction between fingers which are friends 6103 /* FIXME: now we are not making a distinction between fingers which are friends
6104 * also.But later, we should add a congestion timestamp on the friend, so that it is 6104 * also.But later, we should add a congestion timestamp on the friend, so that it is
6105 * selected after some time out. This is to ensure that both peers have added 6105 * selected after some time out. This is to ensure that both peers have added
6106 * each other as their friend. */ 6106 * each other as their friend. */
6107 /* Got a first connection, good time to start with FIND FINGER TRAIL requests...*/ 6107 /* Got a first connection, good time to start with FIND FINGER TRAIL requests...*/
6108 if (GNUNET_SCHEDULER_NO_TASK == find_finger_trail_task) 6108 if (GNUNET_SCHEDULER_NO_TASK == find_finger_trail_task)
@@ -6156,24 +6156,24 @@ GDS_NEIGHBOURS_init (void)
6156 {&handle_dht_p2p_trail_teardown, GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_TEARDOWN, 6156 {&handle_dht_p2p_trail_teardown, GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_TEARDOWN,
6157 sizeof (struct PeerTrailTearDownMessage)}, 6157 sizeof (struct PeerTrailTearDownMessage)},
6158 {&handle_dht_p2p_add_trail, GNUNET_MESSAGE_TYPE_XDHT_P2P_ADD_TRAIL, 0}, 6158 {&handle_dht_p2p_add_trail, GNUNET_MESSAGE_TYPE_XDHT_P2P_ADD_TRAIL, 0},
6159 {&handle_dht_p2p_notify_succ_confirmation, GNUNET_MESSAGE_TYPE_XDHT_P2P_NOTIFY_SUCCESSOR_CONFIRMATION, 6159 {&handle_dht_p2p_notify_succ_confirmation, GNUNET_MESSAGE_TYPE_XDHT_P2P_NOTIFY_SUCCESSOR_CONFIRMATION,
6160 sizeof (struct PeerNotifyConfirmationMessage)}, 6160 sizeof (struct PeerNotifyConfirmationMessage)},
6161 {NULL, 0, 0} 6161 {NULL, 0, 0}
6162 }; 6162 };
6163 6163
6164#if ENABLE_MALICIOUS 6164#if ENABLE_MALICIOUS
6165 act_malicious = 0; 6165 act_malicious = 0;
6166#endif 6166#endif
6167 6167
6168 core_api = 6168 core_api =
6169 GNUNET_CORE_connect (GDS_cfg, NULL, &core_init, &handle_core_connect, 6169 GNUNET_CORE_connect (GDS_cfg, NULL, &core_init, &handle_core_connect,
6170 &handle_core_disconnect, NULL, GNUNET_NO, NULL, 6170 &handle_core_disconnect, NULL, GNUNET_NO, NULL,
6171 GNUNET_NO, core_handlers); 6171 GNUNET_NO, core_handlers);
6172 6172
6173 if (NULL == core_api) 6173 if (NULL == core_api)
6174 return GNUNET_SYSERR; 6174 return GNUNET_SYSERR;
6175 6175
6176 //TODO: check size of this peer map? 6176 //TODO: check size of this peer map?
6177 friend_peermap = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_NO); 6177 friend_peermap = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_NO);
6178 finger_table_init (); 6178 finger_table_init ();
6179 successor_times = 10; 6179 successor_times = 10;
@@ -6182,42 +6182,42 @@ GDS_NEIGHBOURS_init (void)
6182 DHT_FIND_FINGER_TRAIL_INTERVAL.rel_value_us + 6182 DHT_FIND_FINGER_TRAIL_INTERVAL.rel_value_us +
6183 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 6183 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
6184 DHT_FIND_FINGER_TRAIL_INTERVAL.rel_value_us); 6184 DHT_FIND_FINGER_TRAIL_INTERVAL.rel_value_us);
6185 6185
6186 verify_successor_next_send_time.rel_value_us = 6186 verify_successor_next_send_time.rel_value_us =
6187 DHT_SEND_VERIFY_SUCCESSOR_INTERVAL.rel_value_us + 6187 DHT_SEND_VERIFY_SUCCESSOR_INTERVAL.rel_value_us +
6188 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 6188 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
6189 DHT_SEND_VERIFY_SUCCESSOR_INTERVAL.rel_value_us); 6189 DHT_SEND_VERIFY_SUCCESSOR_INTERVAL.rel_value_us);
6190 6190
6191 verify_successor_retry_time.rel_value_us = 6191 verify_successor_retry_time.rel_value_us =
6192 DHT_SEND_VERIFY_SUCCESSOR_RETRY_INTERVAL.rel_value_us + 6192 DHT_SEND_VERIFY_SUCCESSOR_RETRY_INTERVAL.rel_value_us +
6193 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 6193 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
6194 DHT_SEND_VERIFY_SUCCESSOR_RETRY_INTERVAL.rel_value_us); 6194 DHT_SEND_VERIFY_SUCCESSOR_RETRY_INTERVAL.rel_value_us);
6195 6195
6196 notify_successor_retry_time.rel_value_us = 6196 notify_successor_retry_time.rel_value_us =
6197 DHT_SEND_NOTIFY_SUCCESSOR_RETRY_INTERVAL.rel_value_us + 6197 DHT_SEND_NOTIFY_SUCCESSOR_RETRY_INTERVAL.rel_value_us +
6198 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 6198 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
6199 DHT_SEND_NOTIFY_SUCCESSOR_RETRY_INTERVAL.rel_value_us); 6199 DHT_SEND_NOTIFY_SUCCESSOR_RETRY_INTERVAL.rel_value_us);
6200 6200
6201 6201
6202 return GNUNET_OK; 6202 return GNUNET_OK;
6203} 6203}
6204 6204
6205 6205
6206/** 6206/**
6207 * Free the memory held up by trails of a finger. 6207 * Free the memory held up by trails of a finger.
6208 */ 6208 */
6209static void 6209static void
6210delete_finger_table_entries() 6210delete_finger_table_entries()
6211{ 6211{
6212 unsigned int i; 6212 unsigned int i;
6213 unsigned int j; 6213 unsigned int j;
6214 6214
6215 for(i = 0; i < MAX_FINGERS; i++) 6215 for(i = 0; i < MAX_FINGERS; i++)
6216 { 6216 {
6217 if(GNUNET_YES == finger_table[i].is_present) 6217 if(GNUNET_YES == finger_table[i].is_present)
6218 { 6218 {
6219 for(j = 0; j < finger_table[i].trails_count; j++) 6219 for(j = 0; j < finger_table[i].trails_count; j++)
6220 free_trail(&finger_table[i].trail_list[i]); 6220 free_trail(&finger_table[i].trail_list[j]);
6221 } 6221 }
6222 } 6222 }
6223} 6223}
@@ -6259,7 +6259,7 @@ GDS_NEIGHBOURS_done (void)
6259 GNUNET_free(ctx); 6259 GNUNET_free(ctx);
6260 send_verify_successor_retry_task = GNUNET_SCHEDULER_NO_TASK; 6260 send_verify_successor_retry_task = GNUNET_SCHEDULER_NO_TASK;
6261 } 6261 }
6262 6262
6263 if (send_notify_new_successor_retry_task != GNUNET_SCHEDULER_NO_TASK) 6263 if (send_notify_new_successor_retry_task != GNUNET_SCHEDULER_NO_TASK)
6264 { 6264 {
6265 struct SendNotifyContext *notify_ctx; 6265 struct SendNotifyContext *notify_ctx;