diff options
author | Supriti Singh <supritisingh08@gmail.com> | 2014-03-17 16:19:11 +0000 |
---|---|---|
committer | Supriti Singh <supritisingh08@gmail.com> | 2014-03-17 16:19:11 +0000 |
commit | 9587f52d6d72e7107464fa4cdc863bc64321eb8a (patch) | |
tree | e51f8c21900e732fc11a4d59dc4e2fef419ac3e0 /src/dht | |
parent | f142a06df7bd3223136774dc47fdd1ccd91fb624 (diff) | |
download | gnunet-9587f52d6d72e7107464fa4cdc863bc64321eb8a.tar.gz gnunet-9587f52d6d72e7107464fa4cdc863bc64321eb8a.zip |
Added a dll to store finger trail in struct FingerInfo
Diffstat (limited to 'src/dht')
-rw-r--r-- | src/dht/gnunet-service-xdht_neighbours.c | 463 |
1 files changed, 244 insertions, 219 deletions
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c index d9f073cd6..ccc71d4a7 100644 --- a/src/dht/gnunet-service-xdht_neighbours.c +++ b/src/dht/gnunet-service-xdht_neighbours.c | |||
@@ -584,9 +584,14 @@ struct FingerInfo | |||
584 | unsigned int trail_length; | 584 | unsigned int trail_length; |
585 | 585 | ||
586 | /** | 586 | /** |
587 | * List of peers in the trail to reach this finger. | 587 | * Head of trail to reach this finger. |
588 | */ | 588 | */ |
589 | struct GNUNET_PeerIdentity *trail_peer_list; | 589 | struct TrailPeerList *head; |
590 | |||
591 | /** | ||
592 | * Tail of trail to reach this finger. | ||
593 | */ | ||
594 | struct TrailPeerList *tail; | ||
590 | 595 | ||
591 | }; | 596 | }; |
592 | 597 | ||
@@ -777,7 +782,7 @@ GDS_NEIGHBOURS_handle_trail_setup (struct GNUNET_PeerIdentity *source_peer, | |||
777 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), | 782 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), |
778 | 1, GNUNET_NO); | 783 | 1, GNUNET_NO); |
779 | } | 784 | } |
780 | 785 | ||
781 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | 786 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); |
782 | pending->importance = 0; /* FIXME */ | 787 | pending->importance = 0; /* FIXME */ |
783 | pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); | 788 | pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); |
@@ -785,7 +790,8 @@ GDS_NEIGHBOURS_handle_trail_setup (struct GNUNET_PeerIdentity *source_peer, | |||
785 | pending->msg = &tsm->header; | 790 | pending->msg = &tsm->header; |
786 | tsm->header.size = htons (msize); | 791 | tsm->header.size = htons (msize); |
787 | tsm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP); | 792 | tsm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP); |
788 | memcpy (&(tsm->destination_finger), destination_finger, sizeof (uint64_t)); | 793 | memcpy (&(tsm->destination_finger), destination_finger, sizeof (uint64_t)); /* FIXME: Wrong value of finger identity goes to the target peer in |
794 | * handle_dht_p2p_trail_setup */ | ||
789 | memcpy (&(tsm->source_peer), source_peer, sizeof (struct GNUNET_PeerIdentity)); | 795 | memcpy (&(tsm->source_peer), source_peer, sizeof (struct GNUNET_PeerIdentity)); |
790 | memcpy (&(tsm->current_destination), &(target_friend->id), | 796 | memcpy (&(tsm->current_destination), &(target_friend->id), |
791 | sizeof (struct GNUNET_PeerIdentity)); | 797 | sizeof (struct GNUNET_PeerIdentity)); |
@@ -794,24 +800,21 @@ GDS_NEIGHBOURS_handle_trail_setup (struct GNUNET_PeerIdentity *source_peer, | |||
794 | tsm->finger_map_index = htonl (current_finger_index); | 800 | tsm->finger_map_index = htonl (current_finger_index); |
795 | if(1 == successor_flag) | 801 | if(1 == successor_flag) |
796 | { | 802 | { |
797 | tsm->successor_flag = 1; | 803 | tsm->successor_flag = htonl(1); |
798 | tsm->predecessor_flag = 0; | 804 | tsm->predecessor_flag = htonl (0); |
799 | } | 805 | } |
800 | else if (1 == predecessor_flag) | 806 | else if (1 == predecessor_flag) |
801 | { | 807 | { |
802 | tsm->predecessor_flag = 1; | 808 | tsm->predecessor_flag = htonl(1); |
803 | tsm->successor_flag = 0; | 809 | tsm->successor_flag = htonl(0); |
804 | } | 810 | } |
805 | else | 811 | else |
806 | { | 812 | { |
807 | tsm->successor_flag = 0; | 813 | tsm->successor_flag = htonl(0); |
808 | tsm->predecessor_flag = 0; | 814 | tsm->predecessor_flag = htonl(0); |
809 | } | 815 | } |
810 | |||
811 | peer_list = (struct GNUNET_PeerIdentity *) &tsm[1]; | 816 | peer_list = (struct GNUNET_PeerIdentity *) &tsm[1]; |
812 | peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * trail_length); | ||
813 | memcpy (peer_list, trail_peer_list, trail_length * sizeof(struct GNUNET_PeerIdentity)); | 817 | memcpy (peer_list, trail_peer_list, trail_length * sizeof(struct GNUNET_PeerIdentity)); |
814 | |||
815 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); | 818 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); |
816 | target_friend->pending_count++; | 819 | target_friend->pending_count++; |
817 | process_friend_queue (target_friend); | 820 | process_friend_queue (target_friend); |
@@ -897,7 +900,7 @@ GDS_NEIGHBOURS_handle_trail_setup_result (struct GNUNET_PeerIdentity *destinatio | |||
897 | * @param current_trail_index Index in the trial list at which receiving peer should | 900 | * @param current_trail_index Index in the trial list at which receiving peer should |
898 | * get the next element. | 901 | * get the next element. |
899 | */ | 902 | */ |
900 | void GDS_NEIGUBOURS_handle_verify_successor(struct GNUNET_PeerIdentity *source_peer, | 903 | void GDS_NEIGHBOURS_handle_verify_successor(struct GNUNET_PeerIdentity *source_peer, |
901 | struct GNUNET_PeerIdentity *successor, | 904 | struct GNUNET_PeerIdentity *successor, |
902 | struct FriendInfo *target_friend, | 905 | struct FriendInfo *target_friend, |
903 | struct GNUNET_PeerIdentity *trail_peer_list, | 906 | struct GNUNET_PeerIdentity *trail_peer_list, |
@@ -917,7 +920,7 @@ void GDS_NEIGUBOURS_handle_verify_successor(struct GNUNET_PeerIdentity *source_p | |||
917 | GNUNET_break (0); | 920 | GNUNET_break (0); |
918 | return; | 921 | return; |
919 | } | 922 | } |
920 | 923 | ||
921 | if (target_friend->pending_count >= MAXIMUM_PENDING_PER_FRIEND) | 924 | if (target_friend->pending_count >= MAXIMUM_PENDING_PER_FRIEND) |
922 | { | 925 | { |
923 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), | 926 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), |
@@ -935,7 +938,6 @@ void GDS_NEIGUBOURS_handle_verify_successor(struct GNUNET_PeerIdentity *source_p | |||
935 | memcpy (&(vsm->source_peer), source_peer, sizeof (struct GNUNET_PeerIdentity)); | 938 | memcpy (&(vsm->source_peer), source_peer, sizeof (struct GNUNET_PeerIdentity)); |
936 | vsm->trail_length = htonl (trail_length); | 939 | vsm->trail_length = htonl (trail_length); |
937 | vsm->current_trail_index = htonl (current_trail_index); | 940 | vsm->current_trail_index = htonl (current_trail_index); |
938 | |||
939 | peer_list = (struct GNUNET_PeerIdentity *) &vsm[1]; | 941 | peer_list = (struct GNUNET_PeerIdentity *) &vsm[1]; |
940 | memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); | 942 | memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); |
941 | 943 | ||
@@ -1045,7 +1047,7 @@ GDS_NEIGHBOURS_notify_new_successor (struct GNUNET_PeerIdentity *source_peer, | |||
1045 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), | 1047 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), |
1046 | 1, GNUNET_NO); | 1048 | 1, GNUNET_NO); |
1047 | } | 1049 | } |
1048 | 1050 | ||
1049 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | 1051 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); |
1050 | pending->importance = 0; /* FIXME */ | 1052 | pending->importance = 0; /* FIXME */ |
1051 | pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); | 1053 | pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); |
@@ -1104,6 +1106,7 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, | |||
1104 | 4. update the field in get message to reflect if its a friend or finger table | 1106 | 4. update the field in get message to reflect if its a friend or finger table |
1105 | 5. add the put message to pending message and send it. | 1107 | 5. add the put message to pending message and send it. |
1106 | */ | 1108 | */ |
1109 | |||
1107 | } | 1110 | } |
1108 | 1111 | ||
1109 | /**FIXME: Old implementation just to remove error. | 1112 | /**FIXME: Old implementation just to remove error. |
@@ -1146,11 +1149,15 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, | |||
1146 | 4. update the field in put message to reflect if its a friend or finger table | 1149 | 4. update the field in put message to reflect if its a friend or finger table |
1147 | 5. add the put message to pending message and send it. | 1150 | 5. add the put message to pending message and send it. |
1148 | */ | 1151 | */ |
1152 | /* SUPU: Call is made to this function from client. It does not seem to be | ||
1153 | waiting for a confirmation So, once we got the request, we use the key and | ||
1154 | try to find the closest successor, but in this case when we reach to the | ||
1155 | closest successor in handle_dht_p2p_put, then just do datacache_put. As the calling | ||
1156 | function does not need any confirmation, we don't need the result back. */ | ||
1149 | } | 1157 | } |
1150 | 1158 | ||
1151 | 1159 | ||
1152 | /** | 1160 | /** |
1153 | * FIXME: Check if this function actually iterates or not. | ||
1154 | * Randomly choose one of your friends from the friends_peer map | 1161 | * Randomly choose one of your friends from the friends_peer map |
1155 | * @return Friend | 1162 | * @return Friend |
1156 | */ | 1163 | */ |
@@ -1177,8 +1184,6 @@ select_random_friend() | |||
1177 | { | 1184 | { |
1178 | if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next (iter,NULL,NULL)) | 1185 | if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next (iter,NULL,NULL)) |
1179 | { | 1186 | { |
1180 | /* FIXME: I don't think we are actually incrementing iter. iter is always | ||
1181 | pointing to the same element. */ | ||
1182 | j++; | 1187 | j++; |
1183 | } | 1188 | } |
1184 | else | 1189 | else |
@@ -1196,10 +1201,6 @@ select_random_friend() | |||
1196 | 1201 | ||
1197 | /** | 1202 | /** |
1198 | * Compute finger_identity to which we want to setup the trail | 1203 | * Compute finger_identity to which we want to setup the trail |
1199 | * FIXME: If we maintain a index that is value of current_finger_index | ||
1200 | * to which a particular entry in finger map corresponds then should we first | ||
1201 | * check if there is already an entry for that index. If yes then don't | ||
1202 | * search for trail to that finger. | ||
1203 | * @return finger_identity | 1204 | * @return finger_identity |
1204 | */ | 1205 | */ |
1205 | static uint64_t * | 1206 | static uint64_t * |
@@ -1210,17 +1211,7 @@ compute_finger_identity() | |||
1210 | 1211 | ||
1211 | my_id64 = GNUNET_malloc (sizeof (uint64_t)); | 1212 | my_id64 = GNUNET_malloc (sizeof (uint64_t)); |
1212 | finger_identity64 = GNUNET_malloc (sizeof (uint64_t)); | 1213 | finger_identity64 = GNUNET_malloc (sizeof (uint64_t)); |
1213 | 1214 | ||
1214 | /* Check if for current_finger_index you already have an entry in finger table. | ||
1215 | If yes it means you should try to find the trail for finger identifier | ||
1216 | corresponding to next current_finger_index. */ | ||
1217 | /*FIXME: Create an iterator, read all the elements of finger_peermap one by one | ||
1218 | and if finger_index == current_finger_index, then ( | ||
1219 | current_finger_index = current_finger_index + 1) % MAX_FINGERS. We can either | ||
1220 | return NULL or just restart the process to find finger. When we remove the | ||
1221 | friend in handle_core_disconnect, then we also remove the entry from finger | ||
1222 | * peermap. Thats why there can be gap in our logic. ;*/ | ||
1223 | |||
1224 | memcpy (my_id64, &(my_identity.public_key.q_y), sizeof (uint64_t)); | 1215 | memcpy (my_id64, &(my_identity.public_key.q_y), sizeof (uint64_t)); |
1225 | *finger_identity64 = fmod ((*my_id64 + pow (2,current_finger_index)),( (pow (2,MAX_FINGERS)))); | 1216 | *finger_identity64 = fmod ((*my_id64 + pow (2,current_finger_index)),( (pow (2,MAX_FINGERS)))); |
1226 | 1217 | ||
@@ -1229,12 +1220,11 @@ compute_finger_identity() | |||
1229 | 1220 | ||
1230 | 1221 | ||
1231 | /** | 1222 | /** |
1232 | * Find immediate predecessor in the network. | 1223 | * Compute immediate predecessor identity in the network. |
1233 | * @param me my own identity | ||
1234 | * @return peer identity of immediate predecessor. | 1224 | * @return peer identity of immediate predecessor. |
1235 | */ | 1225 | */ |
1236 | static uint64_t * | 1226 | static uint64_t * |
1237 | find_predecessor() | 1227 | compute_predecessor_identity() |
1238 | { | 1228 | { |
1239 | uint64_t *my_id ; | 1229 | uint64_t *my_id ; |
1240 | uint64_t *predecessor; | 1230 | uint64_t *predecessor; |
@@ -1250,26 +1240,6 @@ find_predecessor() | |||
1250 | 1240 | ||
1251 | 1241 | ||
1252 | /** | 1242 | /** |
1253 | * FIXME: At the moment no one is calling this function. | ||
1254 | * Need to find the correct place to call this function. | ||
1255 | * | ||
1256 | */ | ||
1257 | #if 0 | ||
1258 | static void | ||
1259 | fix_fingers() | ||
1260 | { | ||
1261 | /* | ||
1262 | * 1. Choose a random finger index using GNUNET_CRYPTO_random. | ||
1263 | * 2. call find_successor for that finger. now here you have to send | ||
1264 | * what value how do you remember which index you used. so its important | ||
1265 | * to have finger index in finger table. | ||
1266 | * | ||
1267 | */ | ||
1268 | } | ||
1269 | #endif | ||
1270 | |||
1271 | |||
1272 | /** | ||
1273 | * SUPU: You should pass the trail index from where next peer should read. read | 1243 | * SUPU: You should pass the trail index from where next peer should read. read |
1274 | * position should be set and after you read you should update the read position | 1244 | * position should be set and after you read you should update the read position |
1275 | * for next peer in the trail list. | 1245 | * for next peer in the trail list. |
@@ -1287,11 +1257,11 @@ send_verify_successor_message (void *cls, | |||
1287 | struct GNUNET_PeerIdentity key_ret; | 1257 | struct GNUNET_PeerIdentity key_ret; |
1288 | struct FriendInfo *target_friend; | 1258 | struct FriendInfo *target_friend; |
1289 | struct GNUNET_PeerIdentity *next_hop; | 1259 | struct GNUNET_PeerIdentity *next_hop; |
1290 | struct GNUNET_PeerIdentity *finger_trail; | 1260 | struct GNUNET_PeerIdentity *peer_list; |
1291 | unsigned int finger_trail_length; | ||
1292 | unsigned int finger_trail_current_index; | 1261 | unsigned int finger_trail_current_index; |
1293 | struct FingerInfo *finger; | 1262 | struct FingerInfo *finger; |
1294 | unsigned int finger_index; | 1263 | unsigned int finger_index; |
1264 | unsigned int i; | ||
1295 | 1265 | ||
1296 | finger_iter = GNUNET_CONTAINER_multipeermap_iterator_create (finger_peermap); | 1266 | finger_iter = GNUNET_CONTAINER_multipeermap_iterator_create (finger_peermap); |
1297 | for (finger_index = 0; finger_index < GNUNET_CONTAINER_multipeermap_size (finger_peermap); finger_index++) | 1267 | for (finger_index = 0; finger_index < GNUNET_CONTAINER_multipeermap_size (finger_peermap); finger_index++) |
@@ -1303,32 +1273,35 @@ send_verify_successor_message (void *cls, | |||
1303 | break; | 1273 | break; |
1304 | } | 1274 | } |
1305 | } | 1275 | } |
1306 | |||
1307 | GNUNET_CONTAINER_multipeermap_iterator_destroy (finger_iter); | 1276 | GNUNET_CONTAINER_multipeermap_iterator_destroy (finger_iter); |
1277 | |||
1278 | peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * finger->trail_length); | ||
1308 | 1279 | ||
1309 | finger_trail = GNUNET_malloc ((finger->trail_length * | 1280 | /* Iterate over your linked list of trail and copy it into peer_list. */ |
1310 | sizeof (struct GNUNET_PeerIdentity))); | 1281 | struct TrailPeerList *iterate; |
1311 | target_friend = GNUNET_malloc (sizeof (struct FriendInfo)); | 1282 | iterate = finger->head; |
1312 | memcpy (finger_trail, finger->trail_peer_list, | 1283 | i = 0; |
1313 | (finger->trail_length * sizeof (struct GNUNET_PeerIdentity))); | 1284 | while ( i < (finger->trail_length)) |
1314 | finger_trail_length = finger->trail_length; | 1285 | { |
1315 | /* FIXME: Here I am the first element in the trail to reach to any finger. | 1286 | memcpy (&peer_list[i], &(iterate->peer), sizeof (struct GNUNET_PeerIdentity)); |
1316 | So, our first target friend is situated at trail index = 1 and target friend | 1287 | iterate = iterate->next; |
1317 | should read from finger_Trial_current_index. Check in the function that | 1288 | i++; |
1318 | finger_trail_current_index < trail_length.*/ | 1289 | } |
1319 | finger_trail_current_index = 2; | 1290 | |
1320 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 1291 | /* element stored at location 0 is my own identity. element stored at location 1 |
1321 | memcpy (next_hop, &finger_trail[1], | 1292 | is the next hop. */ |
1322 | sizeof (struct GNUNET_PeerIdentity)); | 1293 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
1294 | memcpy (next_hop, &peer_list[1], sizeof (struct GNUNET_PeerIdentity)); | ||
1295 | |||
1323 | 1296 | ||
1297 | /* Find the friend corresponding to this next hop. */ | ||
1324 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | 1298 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); |
1325 | GNUNET_free (next_hop); | 1299 | finger_trail_current_index = 2; |
1326 | 1300 | GDS_NEIGHBOURS_handle_verify_successor (&my_identity, | |
1327 | GDS_NEIGUBOURS_handle_verify_successor (&my_identity, | ||
1328 | &(finger->finger_identity), | 1301 | &(finger->finger_identity), |
1329 | target_friend, | 1302 | target_friend, |
1330 | finger_trail, | 1303 | peer_list, |
1331 | finger_trail_length, | 1304 | finger->trail_length, |
1332 | finger_trail_current_index); | 1305 | finger_trail_current_index); |
1333 | 1306 | ||
1334 | 1307 | ||
@@ -1365,6 +1338,7 @@ send_find_finger_trail_message (void *cls, | |||
1365 | uint64_t *finger_identity; | 1338 | uint64_t *finger_identity; |
1366 | unsigned int finger_index; | 1339 | unsigned int finger_index; |
1367 | 1340 | ||
1341 | /* Initialize flag values */ | ||
1368 | predecessor_flag = 0; | 1342 | predecessor_flag = 0; |
1369 | successor_flag = 0; | 1343 | successor_flag = 0; |
1370 | 1344 | ||
@@ -1372,33 +1346,13 @@ send_find_finger_trail_message (void *cls, | |||
1372 | { | 1346 | { |
1373 | /* We have started the process to find the successor. We should search | 1347 | /* We have started the process to find the successor. We should search |
1374 | for our predecessor. */ | 1348 | for our predecessor. */ |
1375 | finger_identity = find_predecessor(); | 1349 | finger_identity = compute_predecessor_identity(); |
1376 | |||
1377 | /* FIXME: There is no case in find_predecessor which returns NULL. It can | ||
1378 | return NULL, only if we already have found a trail to predecessor. is it | ||
1379 | required or not need to check.*/ | ||
1380 | if(NULL == finger_identity) | ||
1381 | { | ||
1382 | /* We already have a trail to reach to immediate predecessor. */ | ||
1383 | goto new_find_finger_trail_request; | ||
1384 | } | ||
1385 | predecessor_flag = 1; | 1350 | predecessor_flag = 1; |
1386 | goto select_friend; | 1351 | goto select_friend; |
1387 | } | 1352 | } |
1388 | else | 1353 | else |
1389 | { | 1354 | { |
1390 | finger_identity = compute_finger_identity(); | 1355 | finger_identity = compute_finger_identity(); |
1391 | |||
1392 | /* Here again we can get NULL, only if we already have an entry for that | ||
1393 | index value in our finger peer map. That will be checked in compute_finger_identity | ||
1394 | Also, it may be beneficial to keep checking for the new trail and only when | ||
1395 | adding the entry into finger table, we check if the new route is shorter | ||
1396 | or else we may want to keep more than one route (redundant routing). There can be | ||
1397 | no case when it return NULL. */ | ||
1398 | if(finger_identity == NULL) | ||
1399 | { | ||
1400 | goto new_find_finger_trail_request; | ||
1401 | } | ||
1402 | } | 1356 | } |
1403 | 1357 | ||
1404 | if(0 == current_finger_index) | 1358 | if(0 == current_finger_index) |
@@ -1416,14 +1370,12 @@ send_find_finger_trail_message (void *cls, | |||
1416 | /* We found a friend.*/ | 1370 | /* We found a friend.*/ |
1417 | if(NULL != target_friend) | 1371 | if(NULL != target_friend) |
1418 | { | 1372 | { |
1419 | /*SUPU: Here you are adding yourself to peer list so that trail result | 1373 | /* Add yourself and selected friend in the trail list. */ |
1420 | reaches back to you. Highest trail index = trail_length - 1; */ | ||
1421 | unsigned int trail_length = 2; | 1374 | unsigned int trail_length = 2; |
1422 | peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * trail_length); | 1375 | peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * trail_length); |
1423 | memcpy (&peer_list[0], &(my_identity), sizeof (struct GNUNET_PeerIdentity)); | 1376 | memcpy (&peer_list[0], &(my_identity), sizeof (struct GNUNET_PeerIdentity)); |
1424 | memcpy (&peer_list[1], &(target_friend->id), sizeof (struct GNUNET_PeerIdentity)); | 1377 | memcpy (&peer_list[1], &(target_friend->id), sizeof (struct GNUNET_PeerIdentity)); |
1425 | 1378 | ||
1426 | /* FIXME: Here why are you sending the current_finger_index ? */ | ||
1427 | GDS_NEIGHBOURS_handle_trail_setup (&my_identity, finger_identity, | 1379 | GDS_NEIGHBOURS_handle_trail_setup (&my_identity, finger_identity, |
1428 | target_friend, trail_length, peer_list, | 1380 | target_friend, trail_length, peer_list, |
1429 | successor_flag, predecessor_flag, | 1381 | successor_flag, predecessor_flag, |
@@ -1431,7 +1383,6 @@ send_find_finger_trail_message (void *cls, | |||
1431 | } | 1383 | } |
1432 | 1384 | ||
1433 | /* FIXME: Should we be using current_finger_index to generate random interval.*/ | 1385 | /* FIXME: Should we be using current_finger_index to generate random interval.*/ |
1434 | new_find_finger_trail_request: | ||
1435 | next_send_time.rel_value_us = | 1386 | next_send_time.rel_value_us = |
1436 | DHT_MINIMUM_FIND_FINGER_TRAIL_INTERVAL.rel_value_us + | 1387 | DHT_MINIMUM_FIND_FINGER_TRAIL_INTERVAL.rel_value_us + |
1437 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 1388 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
@@ -1448,25 +1399,21 @@ send_find_finger_trail_message (void *cls, | |||
1448 | * Method called whenever a peer connects. | 1399 | * Method called whenever a peer connects. |
1449 | * | 1400 | * |
1450 | * @param cls closure | 1401 | * @param cls closure |
1451 | * @param peer peer identity this notification is about | 1402 | * @param peer_identity peer identity this notification is about |
1452 | */ | 1403 | */ |
1453 | static void | 1404 | static void |
1454 | handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer) | 1405 | handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer_identity) |
1455 | { | 1406 | { |
1456 | struct FriendInfo *ret; | 1407 | struct FriendInfo *friend; |
1457 | 1408 | ||
1458 | /* Check for connect to self message */ | 1409 | /* Check for connect to self message */ |
1459 | if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) | 1410 | if (0 == memcmp (&my_identity, peer_identity, sizeof (struct GNUNET_PeerIdentity))) |
1460 | return; | 1411 | return; |
1461 | 1412 | ||
1462 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1413 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected to %s\n", GNUNET_i2s (peer_identity)); |
1463 | "Connected to %s\n", | ||
1464 | GNUNET_i2s (peer)); | ||
1465 | 1414 | ||
1466 | /* If peer already exists in our friend_peermap, then exit. */ | 1415 | /* If peer already exists in our friend_peermap, then exit. */ |
1467 | if (GNUNET_YES == | 1416 | if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (friend_peermap, peer_identity)) |
1468 | GNUNET_CONTAINER_multipeermap_contains (friend_peermap, | ||
1469 | peer)) | ||
1470 | { | 1417 | { |
1471 | GNUNET_break (0); | 1418 | GNUNET_break (0); |
1472 | return; | 1419 | return; |
@@ -1476,12 +1423,12 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
1476 | GNUNET_NO); | 1423 | GNUNET_NO); |
1477 | 1424 | ||
1478 | 1425 | ||
1479 | ret = GNUNET_new (struct FriendInfo); | 1426 | friend = GNUNET_new (struct FriendInfo); |
1480 | ret->id = *peer; | 1427 | friend->id = *peer_identity; |
1481 | 1428 | ||
1482 | GNUNET_assert (GNUNET_OK == | 1429 | GNUNET_assert (GNUNET_OK == |
1483 | GNUNET_CONTAINER_multipeermap_put (friend_peermap, | 1430 | GNUNET_CONTAINER_multipeermap_put (friend_peermap, |
1484 | peer, ret, | 1431 | peer_identity, friend, |
1485 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 1432 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
1486 | 1433 | ||
1487 | 1434 | ||
@@ -1609,12 +1556,13 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1609 | * @param p2 Peer identity | 1556 | * @param p2 Peer identity |
1610 | * @return 1 if p1 > p2, -1 if p1 < p2 and 0 if p1 == p2. | 1557 | * @return 1 if p1 > p2, -1 if p1 < p2 and 0 if p1 == p2. |
1611 | */ | 1558 | */ |
1559 | #if 0 | ||
1612 | static int | 1560 | static int |
1613 | compare_peer_id (const void *p1, const void *p2) | 1561 | compare_peer_id (const void *p1, const void *p2) |
1614 | { | 1562 | { |
1615 | return memcmp (p1, p2, sizeof (uint64_t)); | 1563 | return memcmp (p1, p2, sizeof (uint64_t));; |
1616 | } | 1564 | } |
1617 | 1565 | #endif | |
1618 | 1566 | ||
1619 | /** | 1567 | /** |
1620 | * Returns the previous element of value in all_known_peers. | 1568 | * Returns the previous element of value in all_known_peers. |
@@ -1622,13 +1570,14 @@ compare_peer_id (const void *p1, const void *p2) | |||
1622 | * @param value value we have to search in the all_known_peers. | 1570 | * @param value value we have to search in the all_known_peers. |
1623 | * @return | 1571 | * @return |
1624 | */ | 1572 | */ |
1573 | #if 0 | ||
1625 | static struct GNUNET_PeerIdentity * | 1574 | static struct GNUNET_PeerIdentity * |
1626 | binary_search(struct GNUNET_PeerIdentity *all_known_peers, uint64_t *value, | 1575 | binary_search(struct GNUNET_PeerIdentity *all_known_peers, uint64_t *value, |
1627 | unsigned int size) | 1576 | unsigned int size) |
1628 | { | 1577 | { |
1629 | unsigned int first; | 1578 | int first; |
1630 | unsigned int last; | 1579 | int last; |
1631 | unsigned int middle; | 1580 | int middle; |
1632 | struct GNUNET_PeerIdentity *successor; | 1581 | struct GNUNET_PeerIdentity *successor; |
1633 | successor = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 1582 | successor = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
1634 | 1583 | ||
@@ -1638,19 +1587,20 @@ binary_search(struct GNUNET_PeerIdentity *all_known_peers, uint64_t *value, | |||
1638 | 1587 | ||
1639 | while(first <= last) | 1588 | while(first <= last) |
1640 | { | 1589 | { |
1641 | /* all_known_peers[middle] > value*/ | 1590 | if(compare_peer_id(&all_known_peers[middle], &value) > 0) |
1642 | if(0 > compare_peer_id(&all_known_peers[middle], &value)) | ||
1643 | { | 1591 | { |
1644 | first = middle + 1; | 1592 | first = middle + 1; |
1645 | } | 1593 | } |
1646 | else if(0 == compare_peer_id(&all_known_peers[middle], &value)) | 1594 | else if(0 == compare_peer_id(&all_known_peers[middle], &value)) |
1647 | { | 1595 | { |
1648 | if(middle == 0) | 1596 | if(middle == 0) |
1649 | { | 1597 | { |
1650 | successor = &(all_known_peers[size - 1]); | 1598 | memcpy (successor, &(all_known_peers[size - 1]), sizeof (struct GNUNET_PeerIdentity)); |
1651 | } | 1599 | } |
1652 | else | 1600 | else |
1653 | successor = &(all_known_peers[middle-1]); | 1601 | { |
1602 | memcpy (successor, &(all_known_peers[middle-1]), sizeof (struct GNUNET_PeerIdentity)); | ||
1603 | } | ||
1654 | } | 1604 | } |
1655 | else | 1605 | else |
1656 | { | 1606 | { |
@@ -1659,9 +1609,10 @@ binary_search(struct GNUNET_PeerIdentity *all_known_peers, uint64_t *value, | |||
1659 | 1609 | ||
1660 | middle = (first + last)/2; | 1610 | middle = (first + last)/2; |
1661 | } | 1611 | } |
1612 | |||
1662 | return successor; | 1613 | return successor; |
1663 | } | 1614 | } |
1664 | 1615 | #endif | |
1665 | 1616 | ||
1666 | /** | 1617 | /** |
1667 | * Find closest successor for the value. | 1618 | * Find closest successor for the value. |
@@ -1675,6 +1626,7 @@ static struct GNUNET_PeerIdentity * | |||
1675 | find_successor(uint64_t *value, struct GNUNET_PeerIdentity *current_destination, | 1626 | find_successor(uint64_t *value, struct GNUNET_PeerIdentity *current_destination, |
1676 | enum current_destination_type *type) | 1627 | enum current_destination_type *type) |
1677 | { | 1628 | { |
1629 | #if 0 | ||
1678 | struct GNUNET_CONTAINER_MultiPeerMapIterator *friend_iter; | 1630 | struct GNUNET_CONTAINER_MultiPeerMapIterator *friend_iter; |
1679 | struct GNUNET_CONTAINER_MultiPeerMapIterator *finger_iter; | 1631 | struct GNUNET_CONTAINER_MultiPeerMapIterator *finger_iter; |
1680 | struct GNUNET_PeerIdentity key_ret; | 1632 | struct GNUNET_PeerIdentity key_ret; |
@@ -1686,24 +1638,26 @@ find_successor(uint64_t *value, struct GNUNET_PeerIdentity *current_destination, | |||
1686 | struct GNUNET_PeerIdentity *successor; | 1638 | struct GNUNET_PeerIdentity *successor; |
1687 | unsigned int size; | 1639 | unsigned int size; |
1688 | unsigned int j; | 1640 | unsigned int j; |
1689 | /* SUPU: 2 is added for my_identity and value. */ | 1641 | |
1642 | /* 2 is added in size for my_identity and value which will part of all_known_peers. */ | ||
1690 | size = GNUNET_CONTAINER_multipeermap_size (friend_peermap)+ | 1643 | size = GNUNET_CONTAINER_multipeermap_size (friend_peermap)+ |
1691 | GNUNET_CONTAINER_multipeermap_size (finger_peermap)+ | 1644 | GNUNET_CONTAINER_multipeermap_size (finger_peermap)+ |
1692 | 2; | 1645 | 2; |
1693 | 1646 | ||
1694 | all_known_peers = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * size); | 1647 | all_known_peers = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * size); |
1695 | 1648 | ||
1649 | /* Copy your identity at 0th index in all_known_peers. */ | ||
1696 | j = 0; | 1650 | j = 0; |
1697 | memcpy (&all_known_peers[j], &(my_identity), sizeof (struct GNUNET_PeerIdentity)); | 1651 | memcpy (&all_known_peers[j], &(my_identity), sizeof (struct GNUNET_PeerIdentity)); |
1652 | |||
1653 | /* Copy the value that you are searching at index 1 in all_known_peers. */ | ||
1698 | j++; | 1654 | j++; |
1699 | memcpy (&all_known_peers[j], value, sizeof(struct GNUNET_PeerIdentity)); | 1655 | memcpy (&all_known_peers[j], value, sizeof(uint64_t)); |
1700 | 1656 | ||
1701 | /* Iterate over friend peermap and copy all the elements into array. */ | 1657 | /* Iterate over friend peer map and copy all the elements into array. */ |
1702 | friend_iter = GNUNET_CONTAINER_multipeermap_iterator_create (friend_peermap); | 1658 | friend_iter = GNUNET_CONTAINER_multipeermap_iterator_create (friend_peermap); |
1703 | for (friend_index = 0; friend_index < GNUNET_CONTAINER_multipeermap_size (friend_peermap); friend_index++) | 1659 | for (friend_index = 0; friend_index < GNUNET_CONTAINER_multipeermap_size (friend_peermap); friend_index++) |
1704 | { | 1660 | { |
1705 | /* FIXME: I don't think we are actually iterating. | ||
1706 | Read about how to iterate over the multipeermap. */ | ||
1707 | if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next(friend_iter,&key_ret,(const void **)&friend)) | 1661 | if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next(friend_iter,&key_ret,(const void **)&friend)) |
1708 | { | 1662 | { |
1709 | memcpy (&all_known_peers[j], &(friend->id), sizeof (struct GNUNET_PeerIdentity)); | 1663 | memcpy (&all_known_peers[j], &(friend->id), sizeof (struct GNUNET_PeerIdentity)); |
@@ -1724,24 +1678,26 @@ find_successor(uint64_t *value, struct GNUNET_PeerIdentity *current_destination, | |||
1724 | } | 1678 | } |
1725 | } | 1679 | } |
1726 | 1680 | ||
1727 | /* FIXME: If this is correct. */ | ||
1728 | GNUNET_CONTAINER_multipeermap_iterator_destroy (finger_iter); | 1681 | GNUNET_CONTAINER_multipeermap_iterator_destroy (finger_iter); |
1729 | GNUNET_CONTAINER_multipeermap_iterator_destroy (friend_iter); | 1682 | GNUNET_CONTAINER_multipeermap_iterator_destroy (friend_iter); |
1730 | 1683 | ||
1731 | qsort (all_known_peers, size, sizeof (struct GNUNET_PeerIdentity), &compare_peer_id); | 1684 | /* FIMXE : Should we not sort it for 64 bits. */ |
1685 | qsort (all_known_peers, size, sizeof (uint64_t), &compare_peer_id); | ||
1732 | 1686 | ||
1733 | /* search value in all_known_peers array. */ | 1687 | /* search value in all_known_peers array. */ |
1734 | successor = binary_search (all_known_peers, value, size); | 1688 | successor = binary_search (all_known_peers, value, size); |
1735 | 1689 | ||
1736 | /* compare successor with my_identity, finger and friend */ | 1690 | /* compare successor with my_identity, finger and friend */ |
1737 | if(0 == GNUNET_CRYPTO_cmp_peer_identity(&(my_identity), successor)) | 1691 | if(0 == GNUNET_CRYPTO_cmp_peer_identity(&(my_identity), successor)) |
1738 | { | 1692 | { |
1693 | FPRINTF (stderr,_("\nSUPU %s, %s, %d"), __FILE__, __func__,__LINE__); | ||
1739 | *type = MY_ID; | 1694 | *type = MY_ID; |
1740 | return NULL; | 1695 | return NULL; |
1741 | } | 1696 | } |
1742 | else if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (friend_peermap, | 1697 | else if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (friend_peermap, |
1743 | successor)) | 1698 | successor)) |
1744 | { | 1699 | { |
1700 | FPRINTF (stderr,_("\nSUPU %s, %s, %d"), __FILE__, __func__,__LINE__); | ||
1745 | *type = FRIEND; | 1701 | *type = FRIEND; |
1746 | memcpy (current_destination, successor, sizeof (struct GNUNET_PeerIdentity)); | 1702 | memcpy (current_destination, successor, sizeof (struct GNUNET_PeerIdentity)); |
1747 | return successor; | 1703 | return successor; |
@@ -1749,6 +1705,7 @@ find_successor(uint64_t *value, struct GNUNET_PeerIdentity *current_destination, | |||
1749 | else if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (finger_peermap, | 1705 | else if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (finger_peermap, |
1750 | successor)) | 1706 | successor)) |
1751 | { | 1707 | { |
1708 | FPRINTF (stderr,_("\nSUPU %s, %s, %d"), __FILE__, __func__,__LINE__); | ||
1752 | *type = FINGER; | 1709 | *type = FINGER; |
1753 | memcpy (current_destination, successor, sizeof (struct GNUNET_PeerIdentity)); | 1710 | memcpy (current_destination, successor, sizeof (struct GNUNET_PeerIdentity)); |
1754 | /* get the corresponding finger for succcesor and read the first element from | 1711 | /* get the corresponding finger for succcesor and read the first element from |
@@ -1757,32 +1714,17 @@ find_successor(uint64_t *value, struct GNUNET_PeerIdentity *current_destination, | |||
1757 | struct GNUNET_PeerIdentity *next_hop; | 1714 | struct GNUNET_PeerIdentity *next_hop; |
1758 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 1715 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
1759 | successor_finger = GNUNET_CONTAINER_multipeermap_get (finger_peermap, successor); | 1716 | successor_finger = GNUNET_CONTAINER_multipeermap_get (finger_peermap, successor); |
1760 | memcpy (next_hop, &(successor_finger->trail_peer_list[0]), sizeof (struct GNUNET_PeerIdentity)); | 1717 | //memcpy (next_hop, &(successor_finger->trail_peer_list[0]), sizeof (struct GNUNET_PeerIdentity)); |
1761 | GNUNET_free (next_hop); | ||
1762 | return next_hop; | 1718 | return next_hop; |
1763 | } | 1719 | } |
1720 | FPRINTF (stderr,_("\nSUPU %s, %s, %d"), __FILE__, __func__,__LINE__); | ||
1764 | return NULL; | 1721 | return NULL; |
1722 | #endif | ||
1723 | *type = MY_ID; | ||
1724 | return &my_identity; | ||
1765 | } | 1725 | } |
1766 | 1726 | ||
1767 | 1727 | ||
1768 | #if 0 | ||
1769 | /** | ||
1770 | * Compare two peer id's and find the closest peer id for value. | ||
1771 | * @param peer1 some peer id | ||
1772 | * @param peer2 some peer id | ||
1773 | * @param value value to which one of the peer id should be closest. | ||
1774 | * @return | ||
1775 | */ | ||
1776 | static struct GNUNET_PeerIdentity * | ||
1777 | find_closest_destination (struct GNUNET_PeerIdentity *peer1, | ||
1778 | struct GNUNET_PeerIdentity *peer2, | ||
1779 | uint64_t *value) | ||
1780 | { | ||
1781 | /* Compare value with peer1 and peer2 and find the closest peer to this value.*/ | ||
1782 | return NULL; | ||
1783 | } | ||
1784 | #endif | ||
1785 | |||
1786 | /** | 1728 | /** |
1787 | * SUPU: The first element in the trail setup message is your identity. | 1729 | * SUPU: The first element in the trail setup message is your identity. |
1788 | * in this function you should increment the trail length. | 1730 | * in this function you should increment the trail length. |
@@ -1806,7 +1748,9 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1806 | uint32_t current_trail_index; | 1748 | uint32_t current_trail_index; |
1807 | unsigned int finger_map_index; | 1749 | unsigned int finger_map_index; |
1808 | struct GNUNET_PeerIdentity *next_peer; | 1750 | struct GNUNET_PeerIdentity *next_peer; |
1809 | 1751 | unsigned int successor_flag; | |
1752 | unsigned int predecessor_flag; | ||
1753 | |||
1810 | /* parse and validate message. */ | 1754 | /* parse and validate message. */ |
1811 | msize = ntohs (message->size); | 1755 | msize = ntohs (message->size); |
1812 | if (msize < sizeof (struct PeerTrailSetupMessage)) | 1756 | if (msize < sizeof (struct PeerTrailSetupMessage)) |
@@ -1815,11 +1759,15 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1815 | return GNUNET_YES; | 1759 | return GNUNET_YES; |
1816 | } | 1760 | } |
1817 | 1761 | ||
1762 | |||
1818 | trail_setup = (struct PeerTrailSetupMessage *) message; | 1763 | trail_setup = (struct PeerTrailSetupMessage *) message; |
1819 | trail_length = ntohl (trail_setup->trail_length); | 1764 | trail_length = ntohl (trail_setup->trail_length); |
1820 | peer_type = ntohl (trail_setup->current_destination_type); | 1765 | peer_type = ntohl (trail_setup->current_destination_type); |
1821 | trail_peer_list = (struct GNUNET_PeerIdentity *) &trail_setup[1]; | ||
1822 | finger_map_index = ntohl (trail_setup->finger_map_index); | 1766 | finger_map_index = ntohl (trail_setup->finger_map_index); |
1767 | successor_flag = ntohl (trail_setup->successor_flag); | ||
1768 | predecessor_flag = ntohl (trail_setup->predecessor_flag); | ||
1769 | |||
1770 | trail_peer_list = (struct GNUNET_PeerIdentity *) &trail_setup[1]; | ||
1823 | 1771 | ||
1824 | if ((msize < | 1772 | if ((msize < |
1825 | sizeof (struct PeerTrailSetupMessage) + | 1773 | sizeof (struct PeerTrailSetupMessage) + |
@@ -1830,7 +1778,7 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1830 | GNUNET_break_op (0); | 1778 | GNUNET_break_op (0); |
1831 | return GNUNET_YES; | 1779 | return GNUNET_YES; |
1832 | } | 1780 | } |
1833 | 1781 | ||
1834 | GNUNET_STATISTICS_update (GDS_stats, | 1782 | GNUNET_STATISTICS_update (GDS_stats, |
1835 | gettext_noop ("# TRAIL SETUP requests received"), 1, | 1783 | gettext_noop ("# TRAIL SETUP requests received"), 1, |
1836 | GNUNET_NO); | 1784 | GNUNET_NO); |
@@ -1895,21 +1843,20 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1895 | which receives this message should look for the next peer to forward the packet | 1843 | which receives this message should look for the next peer to forward the packet |
1896 | to. */ | 1844 | to. */ |
1897 | current_trail_index = trail_length - 2; | 1845 | current_trail_index = trail_length - 2; |
1898 | |||
1899 | next_peer = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 1846 | next_peer = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
1900 | memcpy (next_peer, &trail_peer_list[current_trail_index], sizeof (struct GNUNET_PeerIdentity)); | 1847 | memcpy (next_peer, &trail_peer_list[current_trail_index], sizeof (struct GNUNET_PeerIdentity)); |
1901 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_peer); | 1848 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_peer); |
1902 | GNUNET_free (next_peer); | 1849 | GNUNET_free (next_peer); |
1903 | 1850 | ||
1904 | if(current_trail_index != 0) | 1851 | if(current_trail_index != 0) |
1905 | current_trail_index = current_trail_index - 1; | 1852 | current_trail_index = current_trail_index - 1; |
1906 | 1853 | ||
1907 | GDS_NEIGHBOURS_handle_trail_setup_result (&(trail_setup->source_peer), | 1854 | GDS_NEIGHBOURS_handle_trail_setup_result (&(trail_setup->source_peer), |
1908 | &(my_identity), | 1855 | &(my_identity), |
1909 | target_friend, trail_length, | 1856 | target_friend, trail_length, |
1910 | trail_peer_list, current_trail_index, | 1857 | trail_peer_list, current_trail_index, |
1911 | trail_setup->successor_flag, | 1858 | successor_flag, |
1912 | trail_setup->predecessor_flag, | 1859 | predecessor_flag, |
1913 | finger_map_index); | 1860 | finger_map_index); |
1914 | 1861 | ||
1915 | return GNUNET_YES; | 1862 | return GNUNET_YES; |
@@ -1938,6 +1885,7 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1938 | peer_list,trail_setup->successor_flag, | 1885 | peer_list,trail_setup->successor_flag, |
1939 | trail_setup->predecessor_flag, | 1886 | trail_setup->predecessor_flag, |
1940 | finger_map_index); | 1887 | finger_map_index); |
1888 | |||
1941 | return GNUNET_YES; | 1889 | return GNUNET_YES; |
1942 | } | 1890 | } |
1943 | 1891 | ||
@@ -1966,18 +1914,49 @@ void finger_table_add (struct GNUNET_PeerIdentity *finger, | |||
1966 | unsigned int finger_map_index) | 1914 | unsigned int finger_map_index) |
1967 | { | 1915 | { |
1968 | struct FingerInfo *new_finger_entry; | 1916 | struct FingerInfo *new_finger_entry; |
1969 | 1917 | unsigned int i = 0; | |
1918 | /** SUPU: when we add an entry then we should look if | ||
1919 | * we already have an entry for that index. If yes, then | ||
1920 | * 1) if both the finger identity are same, and same first friend, then choose | ||
1921 | * the one with shorter trail length. | ||
1922 | * 2) if the finger identity is different, then keep the one which is closest.*/ | ||
1923 | |||
1970 | new_finger_entry = GNUNET_malloc (sizeof (struct FingerInfo)); | 1924 | new_finger_entry = GNUNET_malloc (sizeof (struct FingerInfo)); |
1971 | memcpy (&(new_finger_entry->finger_identity), finger, sizeof (struct GNUNET_PeerIdentity)); | 1925 | memcpy (&(new_finger_entry->finger_identity), finger, sizeof (struct GNUNET_PeerIdentity)); |
1972 | memcpy (&(new_finger_entry->trail_peer_list), peer_list, | 1926 | |
1973 | sizeof (struct GNUNET_PeerIdentity)* trail_length); | 1927 | |
1928 | /* Insert elements of peer_list into TrailPeerList. */ | ||
1929 | i = 0; | ||
1930 | while (i < trail_length) | ||
1931 | { | ||
1932 | struct TrailPeerList *element; | ||
1933 | element = GNUNET_malloc (sizeof (struct TrailPeerList)); | ||
1934 | element->next = NULL; | ||
1935 | element->prev = NULL; | ||
1936 | |||
1937 | memcpy (&(element->peer), &peer_list[i], sizeof(struct GNUNET_PeerIdentity)); | ||
1938 | GNUNET_CONTAINER_DLL_insert_tail(new_finger_entry->head, new_finger_entry->tail, element); | ||
1939 | i++; | ||
1940 | } | ||
1941 | |||
1942 | |||
1974 | new_finger_entry->successor = successor_flag; | 1943 | new_finger_entry->successor = successor_flag; |
1975 | new_finger_entry->predecessor = predecessor_flag; | 1944 | new_finger_entry->predecessor = predecessor_flag; |
1976 | new_finger_entry->finger_map_index = finger_map_index; | 1945 | new_finger_entry->finger_map_index = finger_map_index; |
1946 | new_finger_entry->trail_length = trail_length; | ||
1947 | |||
1948 | |||
1949 | GNUNET_assert (GNUNET_OK == | ||
1950 | GNUNET_CONTAINER_multipeermap_put (finger_peermap, | ||
1951 | &(new_finger_entry->finger_identity), | ||
1952 | new_finger_entry, | ||
1953 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
1977 | 1954 | ||
1978 | /*FIXME: Is it really a good time to call verify successor message. */ | 1955 | /*FIXME: Is it really a good time to call verify successor message. */ |
1979 | if (1 == GNUNET_CONTAINER_multipeermap_size (finger_peermap)) | 1956 | if (1 == GNUNET_CONTAINER_multipeermap_size (finger_peermap)) |
1957 | { | ||
1980 | verify_successor = GNUNET_SCHEDULER_add_now (&send_verify_successor_message, NULL); | 1958 | verify_successor = GNUNET_SCHEDULER_add_now (&send_verify_successor_message, NULL); |
1959 | } | ||
1981 | } | 1960 | } |
1982 | 1961 | ||
1983 | 1962 | ||
@@ -2000,6 +1979,8 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p | |||
2000 | struct GNUNET_PeerIdentity *next_peer; | 1979 | struct GNUNET_PeerIdentity *next_peer; |
2001 | struct FriendInfo *target_friend; | 1980 | struct FriendInfo *target_friend; |
2002 | unsigned int finger_map_index; | 1981 | unsigned int finger_map_index; |
1982 | unsigned int successor_flag; | ||
1983 | unsigned int predecessor_flag; | ||
2003 | 1984 | ||
2004 | msize = ntohs (message->size); | 1985 | msize = ntohs (message->size); |
2005 | if (msize < sizeof (struct PeerTrailSetupMessage)) | 1986 | if (msize < sizeof (struct PeerTrailSetupMessage)) |
@@ -2010,9 +1991,6 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p | |||
2010 | 1991 | ||
2011 | trail_result = (struct PeerTrailSetupResultMessage *) message; | 1992 | trail_result = (struct PeerTrailSetupResultMessage *) message; |
2012 | trail_length = ntohl (trail_result->trail_length); | 1993 | trail_length = ntohl (trail_result->trail_length); |
2013 | current_trail_index = ntohl (trail_result->current_index); | ||
2014 | trail_peer_list = (struct GNUNET_PeerIdentity *) &trail_result[1]; | ||
2015 | finger_map_index = ntohl (trail_result->finger_map_index); | ||
2016 | 1994 | ||
2017 | if ((msize < | 1995 | if ((msize < |
2018 | sizeof (struct PeerTrailSetupResultMessage) + | 1996 | sizeof (struct PeerTrailSetupResultMessage) + |
@@ -2023,7 +2001,14 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p | |||
2023 | GNUNET_break_op (0); | 2001 | GNUNET_break_op (0); |
2024 | return GNUNET_YES; | 2002 | return GNUNET_YES; |
2025 | } | 2003 | } |
2026 | 2004 | ||
2005 | current_trail_index = ntohl (trail_result->current_index); | ||
2006 | successor_flag = ntohl (trail_result->successor_flag); | ||
2007 | predecessor_flag = ntohl (trail_result->predecessor_flag); | ||
2008 | finger_map_index = ntohl (trail_result->finger_map_index); | ||
2009 | |||
2010 | trail_peer_list = (struct GNUNET_PeerIdentity *) &trail_result[1]; | ||
2011 | |||
2027 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&(trail_result->current_destination), | 2012 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&(trail_result->current_destination), |
2028 | &my_identity))) | 2013 | &my_identity))) |
2029 | { | 2014 | { |
@@ -2046,12 +2031,12 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p | |||
2046 | memcpy (&finger_trail[i], &trail_peer_list[i], sizeof (struct GNUNET_PeerIdentity)); | 2031 | memcpy (&finger_trail[i], &trail_peer_list[i], sizeof (struct GNUNET_PeerIdentity)); |
2047 | i--; | 2032 | i--; |
2048 | } | 2033 | } |
2049 | trail_length = trail_length -1 ; /* SUPU: As you removed yourself from the trail.*/ | 2034 | trail_length = trail_length -1 ; SUPU: As you removed yourself from the trail.*/ |
2050 | #endif | 2035 | #endif |
2051 | 2036 | ||
2052 | finger_table_add (&(trail_result->finger), trail_peer_list, trail_length, | 2037 | finger_table_add (&(trail_result->finger), trail_peer_list, trail_length, |
2053 | trail_result->successor_flag, trail_result->predecessor_flag, | 2038 | successor_flag, predecessor_flag, |
2054 | trail_result->finger_map_index); | 2039 | finger_map_index); |
2055 | 2040 | ||
2056 | return GNUNET_YES; | 2041 | return GNUNET_YES; |
2057 | } | 2042 | } |
@@ -2115,9 +2100,6 @@ handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *pee | |||
2115 | 2100 | ||
2116 | vsm = (struct PeerVerifySuccessorMessage *) message; | 2101 | vsm = (struct PeerVerifySuccessorMessage *) message; |
2117 | trail_length = ntohl (vsm->trail_length); | 2102 | trail_length = ntohl (vsm->trail_length); |
2118 | current_trail_index = ntohl (vsm->current_trail_index); | ||
2119 | |||
2120 | trail_peer_list = (struct GNUNET_PeerIdentity *) &vsm[1]; | ||
2121 | 2103 | ||
2122 | if ((msize < | 2104 | if ((msize < |
2123 | sizeof (struct PeerVerifySuccessorMessage) + | 2105 | sizeof (struct PeerVerifySuccessorMessage) + |
@@ -2129,6 +2111,10 @@ handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *pee | |||
2129 | return GNUNET_YES; | 2111 | return GNUNET_YES; |
2130 | } | 2112 | } |
2131 | 2113 | ||
2114 | current_trail_index = ntohl (vsm->current_trail_index); | ||
2115 | |||
2116 | trail_peer_list = (struct GNUNET_PeerIdentity *) &vsm[1]; | ||
2117 | |||
2132 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 2118 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
2133 | 2119 | ||
2134 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(vsm->successor), | 2120 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(vsm->successor), |
@@ -2142,7 +2128,7 @@ handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *pee | |||
2142 | unsigned int finger_index; | 2128 | unsigned int finger_index; |
2143 | struct FingerInfo *my_predecessor; | 2129 | struct FingerInfo *my_predecessor; |
2144 | struct GNUNET_PeerIdentity *destination_peer; | 2130 | struct GNUNET_PeerIdentity *destination_peer; |
2145 | 2131 | ||
2146 | /* Iterate over finger peer map and extract your predecessor. */ | 2132 | /* Iterate over finger peer map and extract your predecessor. */ |
2147 | finger_iter = GNUNET_CONTAINER_multipeermap_iterator_create (finger_peermap); | 2133 | finger_iter = GNUNET_CONTAINER_multipeermap_iterator_create (finger_peermap); |
2148 | for (finger_index = 0; finger_index < GNUNET_CONTAINER_multipeermap_size (finger_peermap); finger_index++) | 2134 | for (finger_index = 0; finger_index < GNUNET_CONTAINER_multipeermap_size (finger_peermap); finger_index++) |
@@ -2154,9 +2140,8 @@ handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *pee | |||
2154 | break; | 2140 | break; |
2155 | } | 2141 | } |
2156 | } | 2142 | } |
2157 | 2143 | ||
2158 | GNUNET_CONTAINER_multipeermap_iterator_destroy (finger_iter); | 2144 | GNUNET_CONTAINER_multipeermap_iterator_destroy (finger_iter); |
2159 | |||
2160 | destination_peer = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 2145 | destination_peer = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
2161 | memcpy (destination_peer, &(vsm->source_peer), sizeof (struct GNUNET_PeerIdentity)); | 2146 | memcpy (destination_peer, &(vsm->source_peer), sizeof (struct GNUNET_PeerIdentity)); |
2162 | current_trail_index = trail_length - 2; /*SUPU: I am the last element in the trail.*/ | 2147 | current_trail_index = trail_length - 2; /*SUPU: I am the last element in the trail.*/ |
@@ -2164,6 +2149,7 @@ handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *pee | |||
2164 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | 2149 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); |
2165 | GNUNET_free (next_hop); | 2150 | GNUNET_free (next_hop); |
2166 | 2151 | ||
2152 | if (current_trail_index != 0) | ||
2167 | current_trail_index = current_trail_index - 1; | 2153 | current_trail_index = current_trail_index - 1; |
2168 | 2154 | ||
2169 | /* FIXME: Here we should check if our predecessor is source peer or not. | 2155 | /* FIXME: Here we should check if our predecessor is source peer or not. |
@@ -2179,10 +2165,11 @@ handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *pee | |||
2179 | unsigned int my_predecessor_trail_length; | 2165 | unsigned int my_predecessor_trail_length; |
2180 | unsigned int new_trail_length; | 2166 | unsigned int new_trail_length; |
2181 | unsigned int i; | 2167 | unsigned int i; |
2182 | 2168 | ||
2183 | /* SUPU:my_predecessor_trail will not contain my identity. But the trail | 2169 | /* SUPU: The trail that we store corresponding to each finger contains |
2184 | that I got from the requesting peer will contain my identity. */ | 2170 | * me as the first element. So, we are included twice when we join the |
2185 | my_predecessor_trail_length = my_predecessor->trail_length; | 2171 | * two trails. */ |
2172 | my_predecessor_trail_length = (my_predecessor->trail_length) - 1; /*SUPU: Removing myself from the trail */ | ||
2186 | new_trail_length = trail_length + my_predecessor_trail_length; | 2173 | new_trail_length = trail_length + my_predecessor_trail_length; |
2187 | 2174 | ||
2188 | new_successor_trail = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) | 2175 | new_successor_trail = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) |
@@ -2190,11 +2177,13 @@ handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *pee | |||
2190 | memcpy (new_successor_trail, trail_peer_list, | 2177 | memcpy (new_successor_trail, trail_peer_list, |
2191 | trail_length * sizeof (struct GNUNET_PeerIdentity)); | 2178 | trail_length * sizeof (struct GNUNET_PeerIdentity)); |
2192 | 2179 | ||
2180 | struct TrailPeerList *iterator; | ||
2181 | iterator = my_predecessor->head->next; /* FIXME: Check if you are removing yourself */ | ||
2193 | i = trail_length; | 2182 | i = trail_length; |
2194 | while (i < new_trail_length) | 2183 | while (i < new_trail_length) |
2195 | { | 2184 | { |
2196 | memcpy (&new_successor_trail[i],&(my_predecessor->trail_peer_list[i]), | 2185 | memcpy (&new_successor_trail[i], &(iterator->peer), sizeof (struct GNUNET_PeerIdentity)); |
2197 | sizeof (struct GNUNET_PeerIdentity)); | 2186 | iterator = iterator->next; |
2198 | i++; | 2187 | i++; |
2199 | } | 2188 | } |
2200 | 2189 | ||
@@ -2225,7 +2214,7 @@ handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *pee | |||
2225 | 2214 | ||
2226 | current_trail_index = current_trail_index + 1; | 2215 | current_trail_index = current_trail_index + 1; |
2227 | 2216 | ||
2228 | GDS_NEIGUBOURS_handle_verify_successor(&(vsm->source_peer), | 2217 | GDS_NEIGHBOURS_handle_verify_successor(&(vsm->source_peer), |
2229 | &(vsm->successor), | 2218 | &(vsm->successor), |
2230 | target_friend, | 2219 | target_friend, |
2231 | trail_peer_list, | 2220 | trail_peer_list, |
@@ -2244,12 +2233,32 @@ handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *pee | |||
2244 | * @param trail_length Number of peers to reach to the new successor. | 2233 | * @param trail_length Number of peers to reach to the new successor. |
2245 | */ | 2234 | */ |
2246 | static void | 2235 | static void |
2247 | update_successor (struct GNUNET_PeerIdentity *successor, | 2236 | update_successor (struct GNUNET_PeerIdentity *successor_identity, |
2248 | struct GNUNET_PeerIdentity *peer_list, | 2237 | struct GNUNET_PeerIdentity *peer_list, |
2249 | unsigned int trail_length) | 2238 | unsigned int trail_length) |
2250 | { | 2239 | { |
2251 | /* FIXME: Here you can call fix_fingers. */ | 2240 | struct FingerInfo *new_finger_entry; |
2241 | unsigned int i; | ||
2252 | 2242 | ||
2243 | new_finger_entry = GNUNET_malloc (sizeof (struct FingerInfo)); | ||
2244 | new_finger_entry->predecessor = 0; | ||
2245 | new_finger_entry->successor = 1; | ||
2246 | new_finger_entry->trail_length = trail_length; | ||
2247 | new_finger_entry->finger_map_index = 0; | ||
2248 | memcpy (&(new_finger_entry->finger_identity), successor_identity, sizeof (struct GNUNET_PeerIdentity)); | ||
2249 | |||
2250 | i = 0; | ||
2251 | while (i < trail_length) | ||
2252 | { | ||
2253 | struct TrailPeerList *element; | ||
2254 | element = GNUNET_malloc (sizeof (struct TrailPeerList)); | ||
2255 | element->next = NULL; | ||
2256 | element->prev = NULL; | ||
2257 | |||
2258 | memcpy (&(element->peer), &peer_list[i], sizeof(struct GNUNET_PeerIdentity)); | ||
2259 | GNUNET_CONTAINER_DLL_insert_tail(new_finger_entry->head, new_finger_entry->tail, element); | ||
2260 | i++; | ||
2261 | } | ||
2253 | } | 2262 | } |
2254 | 2263 | ||
2255 | 2264 | ||
@@ -2266,23 +2275,41 @@ update_predecessor (struct GNUNET_PeerIdentity *predecessor, | |||
2266 | struct GNUNET_PeerIdentity *peer_list, | 2275 | struct GNUNET_PeerIdentity *peer_list, |
2267 | unsigned int trail_length) | 2276 | unsigned int trail_length) |
2268 | { | 2277 | { |
2269 | /* In this function, you should first read the whole peer_list in | 2278 | struct GNUNET_PeerIdentity *trail_peer_list; |
2270 | * opposite direction and copy in into trail_peer field of finger entry. | 2279 | struct FingerInfo *new_finger_entry; |
2271 | * also search for pervious predecessor and change the predecessor flag to 0. | 2280 | unsigned int i; |
2272 | * add the entry into finger table with predecessor flag = 1. | 2281 | unsigned int j; |
2273 | */ | ||
2274 | unsigned int successor_flag; | ||
2275 | unsigned int predecessor_flag; | ||
2276 | unsigned int finger_index; | ||
2277 | 2282 | ||
2278 | successor_flag = 0; | 2283 | i = trail_length - 1; |
2279 | predecessor_flag = 1; | 2284 | j = 0; |
2280 | finger_index = 1; | 2285 | trail_peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * |
2281 | /* FIXME: Assumption that predecessor is always stored at current_finger_index = 1.*/ | 2286 | trail_length); |
2282 | finger_table_add (predecessor, peer_list, trail_length, successor_flag, | 2287 | while (i > 0) |
2283 | predecessor_flag, finger_index); | 2288 | { |
2289 | memcpy( &trail_peer_list[j], &peer_list[i], sizeof (struct GNUNET_PeerIdentity)); | ||
2290 | i--; | ||
2291 | j++; | ||
2292 | } | ||
2293 | memcpy (&trail_peer_list[j], &peer_list[i], sizeof(struct GNUNET_PeerIdentity)); | ||
2294 | |||
2295 | new_finger_entry = GNUNET_malloc (sizeof (struct FingerInfo)); | ||
2296 | memcpy (&(new_finger_entry->finger_identity), predecessor, sizeof (struct GNUNET_PeerIdentity)); | ||
2297 | new_finger_entry->finger_map_index = 1; | ||
2298 | new_finger_entry->predecessor = 1; | ||
2299 | new_finger_entry->successor = 0; | ||
2284 | 2300 | ||
2285 | /* FIXME: Here you should call fix_Fingers. */ | 2301 | i = 0; |
2302 | while (i < trail_length) | ||
2303 | { | ||
2304 | struct TrailPeerList *element; | ||
2305 | element = GNUNET_malloc (sizeof (struct TrailPeerList)); | ||
2306 | element->next = NULL; | ||
2307 | element->prev = NULL; | ||
2308 | |||
2309 | memcpy (&(element->peer), &trail_peer_list[i], sizeof(struct GNUNET_PeerIdentity)); | ||
2310 | GNUNET_CONTAINER_DLL_insert_tail(new_finger_entry->head, new_finger_entry->tail, element); | ||
2311 | i++; | ||
2312 | } | ||
2286 | } | 2313 | } |
2287 | 2314 | ||
2288 | 2315 | ||
@@ -2312,11 +2339,8 @@ handle_dht_p2p_notify_new_successor(void *cls, const struct GNUNET_PeerIdentity | |||
2312 | 2339 | ||
2313 | /* Again in the function you have the whole trail to reach to the destination. */ | 2340 | /* Again in the function you have the whole trail to reach to the destination. */ |
2314 | nsm = (struct PeerNotifyNewSuccessorMessage *) message; | 2341 | nsm = (struct PeerNotifyNewSuccessorMessage *) message; |
2315 | current_trail_index = ntohl (nsm->current_index); | ||
2316 | trail_length = ntohl (nsm->trail_length); | 2342 | trail_length = ntohl (nsm->trail_length); |
2317 | 2343 | ||
2318 | trail_peer_list = (struct GNUNET_PeerIdentity *) &nsm[1]; | ||
2319 | |||
2320 | if ((msize < | 2344 | if ((msize < |
2321 | sizeof (struct PeerNotifyNewSuccessorMessage) + | 2345 | sizeof (struct PeerNotifyNewSuccessorMessage) + |
2322 | trail_length * sizeof (struct GNUNET_PeerIdentity)) || | 2346 | trail_length * sizeof (struct GNUNET_PeerIdentity)) || |
@@ -2327,6 +2351,9 @@ handle_dht_p2p_notify_new_successor(void *cls, const struct GNUNET_PeerIdentity | |||
2327 | return GNUNET_YES; | 2351 | return GNUNET_YES; |
2328 | } | 2352 | } |
2329 | 2353 | ||
2354 | current_trail_index = ntohl (nsm->current_index); | ||
2355 | trail_peer_list = (struct GNUNET_PeerIdentity *) &nsm[1]; | ||
2356 | |||
2330 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(nsm->destination_peer), | 2357 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(nsm->destination_peer), |
2331 | &my_identity))) | 2358 | &my_identity))) |
2332 | { | 2359 | { |
@@ -2380,7 +2407,7 @@ handle_dht_p2p_verify_successor_result(void *cls, const struct GNUNET_PeerIdenti | |||
2380 | GNUNET_break_op (0); | 2407 | GNUNET_break_op (0); |
2381 | return GNUNET_YES; | 2408 | return GNUNET_YES; |
2382 | } | 2409 | } |
2383 | 2410 | ||
2384 | /* Again in the function you have the whole trail to reach to the destination. */ | 2411 | /* Again in the function you have the whole trail to reach to the destination. */ |
2385 | vsrm = (struct PeerVerifySuccessorResultMessage *) message; | 2412 | vsrm = (struct PeerVerifySuccessorResultMessage *) message; |
2386 | current_trail_index = ntohl (vsrm->current_index); | 2413 | current_trail_index = ntohl (vsrm->current_index); |
@@ -2401,7 +2428,6 @@ handle_dht_p2p_verify_successor_result(void *cls, const struct GNUNET_PeerIdenti | |||
2401 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(vsrm->destination_peer), | 2428 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(vsrm->destination_peer), |
2402 | &(my_identity)))) | 2429 | &(my_identity)))) |
2403 | { | 2430 | { |
2404 | |||
2405 | if(0 != (GNUNET_CRYPTO_cmp_peer_identity (&(vsrm->my_predecessor), | 2431 | if(0 != (GNUNET_CRYPTO_cmp_peer_identity (&(vsrm->my_predecessor), |
2406 | &(my_identity)))) | 2432 | &(my_identity)))) |
2407 | { | 2433 | { |
@@ -2455,18 +2481,19 @@ GDS_NEIGHBOURS_init() | |||
2455 | {&handle_dht_p2p_trail_setup, GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP, 0}, | 2481 | {&handle_dht_p2p_trail_setup, GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP, 0}, |
2456 | {&handle_dht_p2p_trail_setup_result, GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP_RESULT, 0}, | 2482 | {&handle_dht_p2p_trail_setup_result, GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP_RESULT, 0}, |
2457 | {&handle_dht_p2p_verify_successor, GNUNET_MESSAGE_TYPE_DHT_P2P_VERIFY_SUCCESSOR, 0}, | 2483 | {&handle_dht_p2p_verify_successor, GNUNET_MESSAGE_TYPE_DHT_P2P_VERIFY_SUCCESSOR, 0}, |
2458 | {&handle_dht_p2p_notify_new_successor, GNUNET_MESSAGE_TYPE_DHT_P2P_NOTIFY_NEW_SUCCESSOR, 0}, | ||
2459 | {&handle_dht_p2p_verify_successor_result, GNUNET_MESSAGE_TYPE_DHT_P2P_VERIFY_SUCCESSOR_RESULT, 0}, | 2484 | {&handle_dht_p2p_verify_successor_result, GNUNET_MESSAGE_TYPE_DHT_P2P_VERIFY_SUCCESSOR_RESULT, 0}, |
2485 | {&handle_dht_p2p_notify_new_successor, GNUNET_MESSAGE_TYPE_DHT_P2P_NOTIFY_NEW_SUCCESSOR, 0}, | ||
2460 | {NULL, 0, 0} | 2486 | {NULL, 0, 0} |
2461 | }; | 2487 | }; |
2462 | 2488 | ||
2489 | |||
2463 | /*TODO: What is ATS? Why do we need it? */ | 2490 | /*TODO: What is ATS? Why do we need it? */ |
2464 | atsAPI = GNUNET_ATS_performance_init (GDS_cfg, NULL, NULL); | 2491 | atsAPI = GNUNET_ATS_performance_init (GDS_cfg, NULL, NULL); |
2465 | core_api = | 2492 | core_api = |
2466 | GNUNET_CORE_connect (GDS_cfg, NULL, &core_init, &handle_core_connect, | 2493 | GNUNET_CORE_connect (GDS_cfg, NULL, &core_init, &handle_core_connect, |
2467 | &handle_core_disconnect, NULL, GNUNET_NO, NULL, | 2494 | &handle_core_disconnect, NULL, GNUNET_NO, NULL, |
2468 | GNUNET_NO, core_handlers); | 2495 | GNUNET_NO, core_handlers); |
2469 | if (core_api == NULL) | 2496 | if (NULL == core_api) |
2470 | return GNUNET_SYSERR; | 2497 | return GNUNET_SYSERR; |
2471 | 2498 | ||
2472 | friend_peermap = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_NO); | 2499 | friend_peermap = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_NO); |
@@ -2512,9 +2539,7 @@ GDS_NEIGHBOURS_done () | |||
2512 | GNUNET_SCHEDULER_cancel (find_finger_trail_task); | 2539 | GNUNET_SCHEDULER_cancel (find_finger_trail_task); |
2513 | find_finger_trail_task = GNUNET_SCHEDULER_NO_TASK; | 2540 | find_finger_trail_task = GNUNET_SCHEDULER_NO_TASK; |
2514 | } | 2541 | } |
2515 | 2542 | ||
2516 | /* FIXME: fix_fingers will also be a task like this. | ||
2517 | Add it later. */ | ||
2518 | if (GNUNET_SCHEDULER_NO_TASK != verify_successor) | 2543 | if (GNUNET_SCHEDULER_NO_TASK != verify_successor) |
2519 | { | 2544 | { |
2520 | GNUNET_SCHEDULER_cancel (verify_successor); | 2545 | GNUNET_SCHEDULER_cancel (verify_successor); |