diff options
author | Supriti Singh <supritisingh08@gmail.com> | 2014-03-20 14:00:52 +0000 |
---|---|---|
committer | Supriti Singh <supritisingh08@gmail.com> | 2014-03-20 14:00:52 +0000 |
commit | 5cd93ed2b702e40972269970ad298a86c83469db (patch) | |
tree | a6ede4ff51708865bffbacf949e530ae93f2f78c /src/dht | |
parent | 5ef3be020477b2e154b54a03f164002f5ff640dc (diff) | |
download | gnunet-5cd93ed2b702e40972269970ad298a86c83469db.tar.gz gnunet-5cd93ed2b702e40972269970ad298a86c83469db.zip |
Updated find successor
Diffstat (limited to 'src/dht')
-rw-r--r-- | src/dht/gnunet-service-xdht_neighbours.c | 639 |
1 files changed, 388 insertions, 251 deletions
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c index ccc71d4a7..fb6e71f2e 100644 --- a/src/dht/gnunet-service-xdht_neighbours.c +++ b/src/dht/gnunet-service-xdht_neighbours.c | |||
@@ -238,7 +238,8 @@ enum current_destination_type | |||
238 | { | 238 | { |
239 | FRIEND , | 239 | FRIEND , |
240 | FINGER , | 240 | FINGER , |
241 | MY_ID | 241 | MY_ID , |
242 | VALUE | ||
242 | }; | 243 | }; |
243 | 244 | ||
244 | 245 | ||
@@ -595,6 +596,21 @@ struct FingerInfo | |||
595 | 596 | ||
596 | }; | 597 | }; |
597 | 598 | ||
599 | /** | ||
600 | * Data structure passed to sorting algorithm in find_successor. | ||
601 | */ | ||
602 | struct Sorting_List | ||
603 | { | ||
604 | /* 64 bit value of peer identity */ | ||
605 | uint64_t peer_id; | ||
606 | |||
607 | /* Type : MY_ID, FINGER, FINGER */ | ||
608 | enum current_destination_type type; | ||
609 | |||
610 | /* Pointer to original data structure linked to peer id. */ | ||
611 | void *data; | ||
612 | }; | ||
613 | |||
598 | 614 | ||
599 | /** | 615 | /** |
600 | * Task that sends FIND FINGER TRAIL requests. | 616 | * Task that sends FIND FINGER TRAIL requests. |
@@ -754,8 +770,8 @@ process_friend_queue (struct FriendInfo *peer) | |||
754 | * @param current_finger_index Finger index in finger peer map | 770 | * @param current_finger_index Finger index in finger peer map |
755 | */ | 771 | */ |
756 | void | 772 | void |
757 | GDS_NEIGHBOURS_handle_trail_setup (struct GNUNET_PeerIdentity *source_peer, | 773 | GDS_NEIGHBOURS_send_trail_setup (struct GNUNET_PeerIdentity *source_peer, |
758 | uint64_t *destination_finger, | 774 | uint64_t destination_finger, |
759 | struct FriendInfo *target_friend, | 775 | struct FriendInfo *target_friend, |
760 | unsigned int trail_length, | 776 | unsigned int trail_length, |
761 | struct GNUNET_PeerIdentity *trail_peer_list, | 777 | struct GNUNET_PeerIdentity *trail_peer_list, |
@@ -790,8 +806,7 @@ GDS_NEIGHBOURS_handle_trail_setup (struct GNUNET_PeerIdentity *source_peer, | |||
790 | pending->msg = &tsm->header; | 806 | pending->msg = &tsm->header; |
791 | tsm->header.size = htons (msize); | 807 | tsm->header.size = htons (msize); |
792 | tsm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP); | 808 | tsm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP); |
793 | memcpy (&(tsm->destination_finger), destination_finger, sizeof (uint64_t)); /* FIXME: Wrong value of finger identity goes to the target peer in | 809 | memcpy (&(tsm->destination_finger), &destination_finger, sizeof (uint64_t)); |
794 | * handle_dht_p2p_trail_setup */ | ||
795 | memcpy (&(tsm->source_peer), source_peer, sizeof (struct GNUNET_PeerIdentity)); | 810 | memcpy (&(tsm->source_peer), source_peer, sizeof (struct GNUNET_PeerIdentity)); |
796 | memcpy (&(tsm->current_destination), &(target_friend->id), | 811 | memcpy (&(tsm->current_destination), &(target_friend->id), |
797 | sizeof (struct GNUNET_PeerIdentity)); | 812 | sizeof (struct GNUNET_PeerIdentity)); |
@@ -813,6 +828,7 @@ GDS_NEIGHBOURS_handle_trail_setup (struct GNUNET_PeerIdentity *source_peer, | |||
813 | tsm->successor_flag = htonl(0); | 828 | tsm->successor_flag = htonl(0); |
814 | tsm->predecessor_flag = htonl(0); | 829 | tsm->predecessor_flag = htonl(0); |
815 | } | 830 | } |
831 | |||
816 | peer_list = (struct GNUNET_PeerIdentity *) &tsm[1]; | 832 | peer_list = (struct GNUNET_PeerIdentity *) &tsm[1]; |
817 | memcpy (peer_list, trail_peer_list, trail_length * sizeof(struct GNUNET_PeerIdentity)); | 833 | memcpy (peer_list, trail_peer_list, trail_length * sizeof(struct GNUNET_PeerIdentity)); |
818 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); | 834 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); |
@@ -835,7 +851,7 @@ GDS_NEIGHBOURS_handle_trail_setup (struct GNUNET_PeerIdentity *source_peer, | |||
835 | * @param finger_map_index Finger index in finger peer map | 851 | * @param finger_map_index Finger index in finger peer map |
836 | */ | 852 | */ |
837 | void | 853 | void |
838 | GDS_NEIGHBOURS_handle_trail_setup_result (struct GNUNET_PeerIdentity *destination_peer, | 854 | GDS_NEIGHBOURS_send_trail_setup_result (struct GNUNET_PeerIdentity *destination_peer, |
839 | struct GNUNET_PeerIdentity *source_finger, | 855 | struct GNUNET_PeerIdentity *source_finger, |
840 | struct FriendInfo *target_friend, | 856 | struct FriendInfo *target_friend, |
841 | unsigned int trail_length, | 857 | unsigned int trail_length, |
@@ -900,7 +916,7 @@ GDS_NEIGHBOURS_handle_trail_setup_result (struct GNUNET_PeerIdentity *destinatio | |||
900 | * @param current_trail_index Index in the trial list at which receiving peer should | 916 | * @param current_trail_index Index in the trial list at which receiving peer should |
901 | * get the next element. | 917 | * get the next element. |
902 | */ | 918 | */ |
903 | void GDS_NEIGHBOURS_handle_verify_successor(struct GNUNET_PeerIdentity *source_peer, | 919 | void GDS_NEIGHBOURS_send_verify_successor(struct GNUNET_PeerIdentity *source_peer, |
904 | struct GNUNET_PeerIdentity *successor, | 920 | struct GNUNET_PeerIdentity *successor, |
905 | struct FriendInfo *target_friend, | 921 | struct FriendInfo *target_friend, |
906 | struct GNUNET_PeerIdentity *trail_peer_list, | 922 | struct GNUNET_PeerIdentity *trail_peer_list, |
@@ -960,7 +976,7 @@ void GDS_NEIGHBOURS_handle_verify_successor(struct GNUNET_PeerIdentity *source_p | |||
960 | * @param current_trail_index Index in the trial list at which receiving peer should | 976 | * @param current_trail_index Index in the trial list at which receiving peer should |
961 | * get the next element. | 977 | * get the next element. |
962 | */ | 978 | */ |
963 | void GDS_NEIGHBOURS_handle_verify_successor_result (struct GNUNET_PeerIdentity *destination_peer, | 979 | void GDS_NEIGHBOURS_send_verify_successor_result (struct GNUNET_PeerIdentity *destination_peer, |
964 | struct GNUNET_PeerIdentity *source_successor, | 980 | struct GNUNET_PeerIdentity *source_successor, |
965 | struct GNUNET_PeerIdentity *my_predecessor, | 981 | struct GNUNET_PeerIdentity *my_predecessor, |
966 | struct FriendInfo *target_friend, | 982 | struct FriendInfo *target_friend, |
@@ -982,6 +998,7 @@ void GDS_NEIGHBOURS_handle_verify_successor_result (struct GNUNET_PeerIdentity * | |||
982 | return; | 998 | return; |
983 | } | 999 | } |
984 | 1000 | ||
1001 | |||
985 | if (target_friend->pending_count >= MAXIMUM_PENDING_PER_FRIEND) | 1002 | if (target_friend->pending_count >= MAXIMUM_PENDING_PER_FRIEND) |
986 | { | 1003 | { |
987 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), | 1004 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), |
@@ -1021,7 +1038,7 @@ void GDS_NEIGHBOURS_handle_verify_successor_result (struct GNUNET_PeerIdentity * | |||
1021 | * @param trail_length Total number of peers in peer list | 1038 | * @param trail_length Total number of peers in peer list |
1022 | */ | 1039 | */ |
1023 | void | 1040 | void |
1024 | GDS_NEIGHBOURS_notify_new_successor (struct GNUNET_PeerIdentity *source_peer, | 1041 | GDS_NEIGHBOURS_send_notify_new_successor (struct GNUNET_PeerIdentity *source_peer, |
1025 | struct GNUNET_PeerIdentity *destination_peer, | 1042 | struct GNUNET_PeerIdentity *destination_peer, |
1026 | struct FriendInfo *target_friend, | 1043 | struct FriendInfo *target_friend, |
1027 | struct GNUNET_PeerIdentity *trail_peer_list, | 1044 | struct GNUNET_PeerIdentity *trail_peer_list, |
@@ -1047,7 +1064,7 @@ GDS_NEIGHBOURS_notify_new_successor (struct GNUNET_PeerIdentity *source_peer, | |||
1047 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), | 1064 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), |
1048 | 1, GNUNET_NO); | 1065 | 1, GNUNET_NO); |
1049 | } | 1066 | } |
1050 | 1067 | ||
1051 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | 1068 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); |
1052 | pending->importance = 0; /* FIXME */ | 1069 | pending->importance = 0; /* FIXME */ |
1053 | pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); | 1070 | pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); |
@@ -1292,12 +1309,11 @@ send_verify_successor_message (void *cls, | |||
1292 | is the next hop. */ | 1309 | is the next hop. */ |
1293 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 1310 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
1294 | memcpy (next_hop, &peer_list[1], sizeof (struct GNUNET_PeerIdentity)); | 1311 | memcpy (next_hop, &peer_list[1], sizeof (struct GNUNET_PeerIdentity)); |
1295 | |||
1296 | |||
1297 | /* Find the friend corresponding to this next hop. */ | 1312 | /* Find the friend corresponding to this next hop. */ |
1298 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | 1313 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); |
1299 | finger_trail_current_index = 2; | 1314 | finger_trail_current_index = 2; |
1300 | GDS_NEIGHBOURS_handle_verify_successor (&my_identity, | 1315 | |
1316 | GDS_NEIGHBOURS_send_verify_successor (&my_identity, | ||
1301 | &(finger->finger_identity), | 1317 | &(finger->finger_identity), |
1302 | target_friend, | 1318 | target_friend, |
1303 | peer_list, | 1319 | peer_list, |
@@ -1311,7 +1327,7 @@ send_verify_successor_message (void *cls, | |||
1311 | DHT_MINIMUM_FIND_FINGER_TRAIL_INTERVAL.rel_value_us + | 1327 | DHT_MINIMUM_FIND_FINGER_TRAIL_INTERVAL.rel_value_us + |
1312 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 1328 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
1313 | DHT_MAXIMUM_FIND_FINGER_TRAIL_INTERVAL.rel_value_us / | 1329 | DHT_MAXIMUM_FIND_FINGER_TRAIL_INTERVAL.rel_value_us / |
1314 | (current_finger_index + 1)); | 1330 | (current_finger_index + 50)); |
1315 | 1331 | ||
1316 | verify_successor = | 1332 | verify_successor = |
1317 | GNUNET_SCHEDULER_add_delayed (next_send_time, &send_verify_successor_message, | 1333 | GNUNET_SCHEDULER_add_delayed (next_send_time, &send_verify_successor_message, |
@@ -1366,7 +1382,7 @@ send_find_finger_trail_message (void *cls, | |||
1366 | current_finger_index = ( current_finger_index + 1) % MAX_FINGERS; | 1382 | current_finger_index = ( current_finger_index + 1) % MAX_FINGERS; |
1367 | 1383 | ||
1368 | target_friend = select_random_friend(); | 1384 | target_friend = select_random_friend(); |
1369 | 1385 | ||
1370 | /* We found a friend.*/ | 1386 | /* We found a friend.*/ |
1371 | if(NULL != target_friend) | 1387 | if(NULL != target_friend) |
1372 | { | 1388 | { |
@@ -1376,10 +1392,11 @@ send_find_finger_trail_message (void *cls, | |||
1376 | memcpy (&peer_list[0], &(my_identity), sizeof (struct GNUNET_PeerIdentity)); | 1392 | memcpy (&peer_list[0], &(my_identity), sizeof (struct GNUNET_PeerIdentity)); |
1377 | memcpy (&peer_list[1], &(target_friend->id), sizeof (struct GNUNET_PeerIdentity)); | 1393 | memcpy (&peer_list[1], &(target_friend->id), sizeof (struct GNUNET_PeerIdentity)); |
1378 | 1394 | ||
1379 | GDS_NEIGHBOURS_handle_trail_setup (&my_identity, finger_identity, | 1395 | /* TODO send trail setup */ |
1380 | target_friend, trail_length, peer_list, | 1396 | GDS_NEIGHBOURS_send_trail_setup (&my_identity, *finger_identity, |
1381 | successor_flag, predecessor_flag, | 1397 | target_friend, trail_length, peer_list, |
1382 | finger_index); | 1398 | successor_flag, predecessor_flag, |
1399 | finger_index); | ||
1383 | } | 1400 | } |
1384 | 1401 | ||
1385 | /* FIXME: Should we be using current_finger_index to generate random interval.*/ | 1402 | /* FIXME: Should we be using current_finger_index to generate random interval.*/ |
@@ -1387,7 +1404,7 @@ send_find_finger_trail_message (void *cls, | |||
1387 | DHT_MINIMUM_FIND_FINGER_TRAIL_INTERVAL.rel_value_us + | 1404 | DHT_MINIMUM_FIND_FINGER_TRAIL_INTERVAL.rel_value_us + |
1388 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 1405 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
1389 | DHT_MAXIMUM_FIND_FINGER_TRAIL_INTERVAL.rel_value_us / | 1406 | DHT_MAXIMUM_FIND_FINGER_TRAIL_INTERVAL.rel_value_us / |
1390 | (current_finger_index + 1)); | 1407 | (current_finger_index + 10)); |
1391 | 1408 | ||
1392 | find_finger_trail_task = | 1409 | find_finger_trail_task = |
1393 | GNUNET_SCHEDULER_add_delayed (next_send_time, &send_find_finger_trail_message, | 1410 | GNUNET_SCHEDULER_add_delayed (next_send_time, &send_find_finger_trail_message, |
@@ -1431,7 +1448,6 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer_identity) | |||
1431 | peer_identity, friend, | 1448 | peer_identity, friend, |
1432 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 1449 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
1433 | 1450 | ||
1434 | |||
1435 | /* got a first connection, good time to start with FIND FINGER TRAIL requests... */ | 1451 | /* got a first connection, good time to start with FIND FINGER TRAIL requests... */ |
1436 | if (1 == GNUNET_CONTAINER_multipeermap_size (friend_peermap)) | 1452 | if (1 == GNUNET_CONTAINER_multipeermap_size (friend_peermap)) |
1437 | find_finger_trail_task = GNUNET_SCHEDULER_add_now (&send_find_finger_trail_message, NULL); | 1453 | find_finger_trail_task = GNUNET_SCHEDULER_add_now (&send_find_finger_trail_message, NULL); |
@@ -1549,6 +1565,200 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1549 | return 0; | 1565 | return 0; |
1550 | } | 1566 | } |
1551 | 1567 | ||
1568 | /** | ||
1569 | * FIXME: For redundant routing, we may start looking for different | ||
1570 | * paths to reach to same finger. So, in send_find_finger, we are starting | ||
1571 | * the search for trail to a finger, even if we already have found trail to | ||
1572 | * reach to it. There are several reasons for doing so | ||
1573 | * 1. We may reach to a closer successor than we have at the moment. So, we | ||
1574 | * should keep looking for the successor. | ||
1575 | * 2. We may reach to the same successor but through a shorter path. | ||
1576 | * 3. As I don't know how keys are distributed and how put/get will react | ||
1577 | * because of this, I have to think further before implementing it. | ||
1578 | * Add an entry in finger table. | ||
1579 | * @param finger Finger to be added to finger table | ||
1580 | * @param peer_list peers this request has traversed so far | ||
1581 | * @param trail_length Numbers of peers in the trail. | ||
1582 | */ | ||
1583 | static | ||
1584 | void finger_table_add (struct GNUNET_PeerIdentity *finger, | ||
1585 | struct GNUNET_PeerIdentity *peer_list, | ||
1586 | unsigned int trail_length, | ||
1587 | unsigned int successor_flag, | ||
1588 | unsigned int predecessor_flag, | ||
1589 | unsigned int finger_map_index) | ||
1590 | { | ||
1591 | struct FingerInfo *new_finger_entry; | ||
1592 | unsigned int i = 0; | ||
1593 | /** SUPU: when we add an entry then we should look if | ||
1594 | * we already have an entry for that index. If yes, then | ||
1595 | * 1) if both the finger identity are same, and same first friend, then choose | ||
1596 | * the one with shorter trail length. | ||
1597 | * 2) if the finger identity is different, then keep the one which is closest.*/ | ||
1598 | |||
1599 | if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (finger_peermap, finger)) | ||
1600 | { | ||
1601 | exit(0); | ||
1602 | #if 0 | ||
1603 | /* Optimization. For the moment we just ignore and do nothing.*/ | ||
1604 | /* We already have an entry for this finger. */ | ||
1605 | struct GNUNET_PeerIdentity *first_friend; | ||
1606 | struct FingerInfo *exisiting_finger_entry; | ||
1607 | |||
1608 | struct TrailPeerList *iterator; | ||
1609 | iterator = GNUNET_malloc (sizeof (struct TrailPeerList)); | ||
1610 | exisiting_finger_entry = GNUNET_CONTAINER_multipeermap_get(finger_peermap, finger); | ||
1611 | iterator = exisiting_finger_entry->head; | ||
1612 | memcpy (first_friend, &(iterator->peer), sizeof(struct GNUNET_PeerIdentity)); | ||
1613 | |||
1614 | if(0 == GNUNET_CRYPTO_cmp_peer_identity(first_friend, finger)) | ||
1615 | { | ||
1616 | |||
1617 | } | ||
1618 | #endif | ||
1619 | } | ||
1620 | |||
1621 | new_finger_entry = GNUNET_malloc (sizeof (struct FingerInfo)); | ||
1622 | memcpy (&(new_finger_entry->finger_identity), finger, sizeof (struct GNUNET_PeerIdentity)); | ||
1623 | |||
1624 | |||
1625 | /* Insert elements of peer_list into TrailPeerList. */ | ||
1626 | i = 0; | ||
1627 | while (i < trail_length) | ||
1628 | { | ||
1629 | struct TrailPeerList *element; | ||
1630 | element = GNUNET_malloc (sizeof (struct TrailPeerList)); | ||
1631 | element->next = NULL; | ||
1632 | element->prev = NULL; | ||
1633 | |||
1634 | memcpy (&(element->peer), &peer_list[i], sizeof(struct GNUNET_PeerIdentity)); | ||
1635 | GNUNET_CONTAINER_DLL_insert_tail(new_finger_entry->head, new_finger_entry->tail, element); | ||
1636 | i++; | ||
1637 | } | ||
1638 | |||
1639 | |||
1640 | new_finger_entry->successor = successor_flag; | ||
1641 | new_finger_entry->predecessor = predecessor_flag; | ||
1642 | new_finger_entry->finger_map_index = finger_map_index; | ||
1643 | new_finger_entry->trail_length = trail_length; | ||
1644 | |||
1645 | |||
1646 | GNUNET_assert (GNUNET_OK == | ||
1647 | GNUNET_CONTAINER_multipeermap_put (finger_peermap, | ||
1648 | &(new_finger_entry->finger_identity), | ||
1649 | new_finger_entry, | ||
1650 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
1651 | |||
1652 | /*FIXME: Is it really a good time to call verify successor message. */ | ||
1653 | if (1 == GNUNET_CONTAINER_multipeermap_size (finger_peermap)) | ||
1654 | { | ||
1655 | verify_successor = GNUNET_SCHEDULER_add_now (&send_verify_successor_message, NULL); | ||
1656 | } | ||
1657 | } | ||
1658 | |||
1659 | |||
1660 | /** | ||
1661 | * FIXME: Also copy the trail list in reverse direction that is the path to | ||
1662 | * reach to your predecessor. | ||
1663 | * Replace your predecessor with new predecessor. | ||
1664 | * @param predecessor My new predecessor | ||
1665 | * @param peer_list Trail list to reach to my new predecessor | ||
1666 | * @param trail_length Number of peers in the trail. | ||
1667 | */ | ||
1668 | static void | ||
1669 | update_predecessor (struct GNUNET_PeerIdentity *predecessor, | ||
1670 | struct GNUNET_PeerIdentity *peer_list, | ||
1671 | unsigned int trail_length) | ||
1672 | { | ||
1673 | struct GNUNET_PeerIdentity *trail_peer_list; | ||
1674 | struct FingerInfo *new_finger_entry; | ||
1675 | struct FingerInfo *finger; | ||
1676 | struct GNUNET_CONTAINER_MultiPeerMapIterator *finger_iter; | ||
1677 | struct GNUNET_PeerIdentity key_ret; | ||
1678 | int finger_index; | ||
1679 | int i; | ||
1680 | int j; | ||
1681 | int flag = 0; | ||
1682 | |||
1683 | /* Check if you already have a predecessor. Then remove it and add the new | ||
1684 | entry. */ | ||
1685 | finger_iter = GNUNET_CONTAINER_multipeermap_iterator_create (finger_peermap); | ||
1686 | for (finger_index = 0; finger_index < GNUNET_CONTAINER_multipeermap_size (finger_peermap); finger_index++) | ||
1687 | { | ||
1688 | if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next (finger_iter, &key_ret, | ||
1689 | (const void **)&finger)) | ||
1690 | { | ||
1691 | if (1 == finger->predecessor) | ||
1692 | { | ||
1693 | flag = 1; | ||
1694 | break; | ||
1695 | } | ||
1696 | } | ||
1697 | } | ||
1698 | GNUNET_CONTAINER_multipeermap_iterator_destroy (finger_iter); | ||
1699 | /* check if you come out of the loop or because of the conditoin*/ | ||
1700 | if (flag == 0) | ||
1701 | { | ||
1702 | goto add_new_predecessor; | ||
1703 | } | ||
1704 | else | ||
1705 | { | ||
1706 | if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains(finger_peermap, &(finger->finger_identity))) | ||
1707 | { | ||
1708 | /* compare peer ids of new finger and old finger if they are same don't remove and exit | ||
1709 | if different then remove and exit. */ | ||
1710 | if ( 0 == GNUNET_CRYPTO_cmp_peer_identity (&(finger->finger_identity), predecessor)) | ||
1711 | { | ||
1712 | //goto do_nothing; | ||
1713 | exit(0); | ||
1714 | } | ||
1715 | else | ||
1716 | { | ||
1717 | if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove(finger_peermap, &(finger->finger_identity), finger)) | ||
1718 | { | ||
1719 | goto add_new_predecessor; | ||
1720 | } | ||
1721 | else | ||
1722 | //goto do_nothing; | ||
1723 | exit(0); | ||
1724 | } | ||
1725 | } | ||
1726 | } | ||
1727 | |||
1728 | add_new_predecessor: | ||
1729 | i = trail_length - 1; | ||
1730 | j = 0; | ||
1731 | trail_peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * | ||
1732 | trail_length); | ||
1733 | while (i > 0) | ||
1734 | { | ||
1735 | memcpy( &trail_peer_list[j], &peer_list[i], sizeof (struct GNUNET_PeerIdentity)); | ||
1736 | i--; | ||
1737 | j++; | ||
1738 | } | ||
1739 | memcpy (&trail_peer_list[j], &peer_list[i], sizeof(struct GNUNET_PeerIdentity)); | ||
1740 | |||
1741 | new_finger_entry = GNUNET_malloc (sizeof (struct FingerInfo)); | ||
1742 | memcpy (&(new_finger_entry->finger_identity), predecessor, sizeof (struct GNUNET_PeerIdentity)); | ||
1743 | new_finger_entry->finger_map_index = 1; | ||
1744 | new_finger_entry->predecessor = 1; | ||
1745 | new_finger_entry->successor = 0; | ||
1746 | new_finger_entry->trail_length = trail_length; | ||
1747 | |||
1748 | i = 0; | ||
1749 | while (i < trail_length) | ||
1750 | { | ||
1751 | struct TrailPeerList *element; | ||
1752 | element = GNUNET_malloc (sizeof (struct TrailPeerList)); | ||
1753 | element->next = NULL; | ||
1754 | element->prev = NULL; | ||
1755 | |||
1756 | memcpy (&(element->peer), &trail_peer_list[i], sizeof(struct GNUNET_PeerIdentity)); | ||
1757 | GNUNET_CONTAINER_DLL_insert_tail(new_finger_entry->head, new_finger_entry->tail, element); | ||
1758 | i++; | ||
1759 | } | ||
1760 | } | ||
1761 | |||
1552 | 1762 | ||
1553 | /** | 1763 | /** |
1554 | * Compare two peer identities. | 1764 | * Compare two peer identities. |
@@ -1556,30 +1766,35 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1556 | * @param p2 Peer identity | 1766 | * @param p2 Peer identity |
1557 | * @return 1 if p1 > p2, -1 if p1 < p2 and 0 if p1 == p2. | 1767 | * @return 1 if p1 > p2, -1 if p1 < p2 and 0 if p1 == p2. |
1558 | */ | 1768 | */ |
1559 | #if 0 | 1769 | static int |
1560 | static int | ||
1561 | compare_peer_id (const void *p1, const void *p2) | 1770 | compare_peer_id (const void *p1, const void *p2) |
1562 | { | 1771 | { |
1563 | return memcmp (p1, p2, sizeof (uint64_t));; | 1772 | struct Sorting_List *p11; |
1773 | struct Sorting_List *p22; | ||
1774 | int ret; | ||
1775 | p11 = GNUNET_malloc (sizeof (struct Sorting_List)); | ||
1776 | p22 = GNUNET_malloc (sizeof (struct Sorting_List)); | ||
1777 | p11 = (struct Sorting_List *)p1; | ||
1778 | p22 = (struct Sorting_List *)p2; | ||
1779 | ret = ( (p11->peer_id) > (p22->peer_id) ) ? 1 : | ||
1780 | ( (p11->peer_id) == (p22->peer_id) ) ? 0 : -1; | ||
1781 | return ret; | ||
1564 | } | 1782 | } |
1565 | #endif | ||
1566 | 1783 | ||
1784 | |||
1567 | /** | 1785 | /** |
1568 | * Returns the previous element of value in all_known_peers. | 1786 | * Returns the previous element of value in all_known_peers. |
1569 | * @param all_known_peers list of all the peers | 1787 | * @param all_known_peers list of all the peers |
1570 | * @param value value we have to search in the all_known_peers. | 1788 | * @param value value we have to search in the all_known_peers. |
1571 | * @return | 1789 | * @return |
1572 | */ | 1790 | */ |
1573 | #if 0 | 1791 | static struct Sorting_List * |
1574 | static struct GNUNET_PeerIdentity * | 1792 | find_closest_successor(struct Sorting_List *all_known_peers, uint64_t value, |
1575 | binary_search(struct GNUNET_PeerIdentity *all_known_peers, uint64_t *value, | ||
1576 | unsigned int size) | 1793 | unsigned int size) |
1577 | { | 1794 | { |
1578 | int first; | 1795 | int first; |
1579 | int last; | 1796 | int last; |
1580 | int middle; | 1797 | int middle; |
1581 | struct GNUNET_PeerIdentity *successor; | ||
1582 | successor = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | ||
1583 | 1798 | ||
1584 | first = 0; | 1799 | first = 0; |
1585 | last = size - 1; | 1800 | last = size - 1; |
@@ -1587,19 +1802,19 @@ binary_search(struct GNUNET_PeerIdentity *all_known_peers, uint64_t *value, | |||
1587 | 1802 | ||
1588 | while(first <= last) | 1803 | while(first <= last) |
1589 | { | 1804 | { |
1590 | if(compare_peer_id(&all_known_peers[middle], &value) > 0) | 1805 | if(all_known_peers[middle].peer_id < value) |
1591 | { | 1806 | { |
1592 | first = middle + 1; | 1807 | first = middle + 1; |
1593 | } | 1808 | } |
1594 | else if(0 == compare_peer_id(&all_known_peers[middle], &value)) | 1809 | else if(all_known_peers[middle].peer_id == value) |
1595 | { | 1810 | { |
1596 | if(middle == 0) | 1811 | if(middle == (size -1)) |
1597 | { | 1812 | { |
1598 | memcpy (successor, &(all_known_peers[size - 1]), sizeof (struct GNUNET_PeerIdentity)); | 1813 | return &all_known_peers[0]; |
1599 | } | 1814 | } |
1600 | else | 1815 | else |
1601 | { | 1816 | { |
1602 | memcpy (successor, &(all_known_peers[middle-1]), sizeof (struct GNUNET_PeerIdentity)); | 1817 | return &all_known_peers[middle+1]; |
1603 | } | 1818 | } |
1604 | } | 1819 | } |
1605 | else | 1820 | else |
@@ -1609,10 +1824,9 @@ binary_search(struct GNUNET_PeerIdentity *all_known_peers, uint64_t *value, | |||
1609 | 1824 | ||
1610 | middle = (first + last)/2; | 1825 | middle = (first + last)/2; |
1611 | } | 1826 | } |
1612 | 1827 | return NULL; | |
1613 | return successor; | ||
1614 | } | 1828 | } |
1615 | #endif | 1829 | |
1616 | 1830 | ||
1617 | /** | 1831 | /** |
1618 | * Find closest successor for the value. | 1832 | * Find closest successor for the value. |
@@ -1623,10 +1837,9 @@ binary_search(struct GNUNET_PeerIdentity *all_known_peers, uint64_t *value, | |||
1623 | * @return Peer identity of next destination i.e. successor of value. | 1837 | * @return Peer identity of next destination i.e. successor of value. |
1624 | */ | 1838 | */ |
1625 | static struct GNUNET_PeerIdentity * | 1839 | static struct GNUNET_PeerIdentity * |
1626 | find_successor(uint64_t *value, struct GNUNET_PeerIdentity *current_destination, | 1840 | find_successor(uint64_t value, struct GNUNET_PeerIdentity *current_destination, |
1627 | enum current_destination_type *type) | 1841 | enum current_destination_type *type) |
1628 | { | 1842 | { |
1629 | #if 0 | ||
1630 | struct GNUNET_CONTAINER_MultiPeerMapIterator *friend_iter; | 1843 | struct GNUNET_CONTAINER_MultiPeerMapIterator *friend_iter; |
1631 | struct GNUNET_CONTAINER_MultiPeerMapIterator *finger_iter; | 1844 | struct GNUNET_CONTAINER_MultiPeerMapIterator *finger_iter; |
1632 | struct GNUNET_PeerIdentity key_ret; | 1845 | struct GNUNET_PeerIdentity key_ret; |
@@ -1634,25 +1847,33 @@ find_successor(uint64_t *value, struct GNUNET_PeerIdentity *current_destination, | |||
1634 | struct FingerInfo *finger; | 1847 | struct FingerInfo *finger; |
1635 | unsigned int finger_index; | 1848 | unsigned int finger_index; |
1636 | unsigned int friend_index; | 1849 | unsigned int friend_index; |
1637 | struct GNUNET_PeerIdentity *all_known_peers; | 1850 | struct Sorting_List *successor; |
1638 | struct GNUNET_PeerIdentity *successor; | ||
1639 | unsigned int size; | 1851 | unsigned int size; |
1640 | unsigned int j; | 1852 | int j; |
1641 | 1853 | ||
1642 | /* 2 is added in size for my_identity and value which will part of all_known_peers. */ | 1854 | /* 2 is added in size for my_identity and value which will part of all_known_peers. */ |
1643 | size = GNUNET_CONTAINER_multipeermap_size (friend_peermap)+ | 1855 | size = GNUNET_CONTAINER_multipeermap_size (friend_peermap)+ |
1644 | GNUNET_CONTAINER_multipeermap_size (finger_peermap)+ | 1856 | GNUNET_CONTAINER_multipeermap_size (finger_peermap)+ |
1645 | 2; | 1857 | 2; |
1646 | 1858 | ||
1647 | all_known_peers = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * size); | 1859 | struct Sorting_List all_known_peers[size]; |
1860 | |||
1861 | int k; | ||
1862 | for (k = 0; k < size; k++) | ||
1863 | all_known_peers[k].peer_id = 0; | ||
1648 | 1864 | ||
1649 | /* Copy your identity at 0th index in all_known_peers. */ | 1865 | /* Copy your identity at 0th index in all_known_peers. */ |
1650 | j = 0; | 1866 | j = 0; |
1651 | memcpy (&all_known_peers[j], &(my_identity), sizeof (struct GNUNET_PeerIdentity)); | 1867 | memcpy (&(all_known_peers[j].peer_id), &my_identity, sizeof (uint64_t)); |
1868 | all_known_peers[j].type = MY_ID; | ||
1869 | all_known_peers[j].data = 0; | ||
1870 | j++; | ||
1652 | 1871 | ||
1653 | /* Copy the value that you are searching at index 1 in all_known_peers. */ | 1872 | /* Copy value */ |
1873 | all_known_peers[j].peer_id = value; | ||
1874 | all_known_peers[j].type = VALUE; | ||
1875 | all_known_peers[j].data = 0; | ||
1654 | j++; | 1876 | j++; |
1655 | memcpy (&all_known_peers[j], value, sizeof(uint64_t)); | ||
1656 | 1877 | ||
1657 | /* Iterate over friend peer map and copy all the elements into array. */ | 1878 | /* Iterate over friend peer map and copy all the elements into array. */ |
1658 | friend_iter = GNUNET_CONTAINER_multipeermap_iterator_create (friend_peermap); | 1879 | friend_iter = GNUNET_CONTAINER_multipeermap_iterator_create (friend_peermap); |
@@ -1660,7 +1881,9 @@ find_successor(uint64_t *value, struct GNUNET_PeerIdentity *current_destination, | |||
1660 | { | 1881 | { |
1661 | if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next(friend_iter,&key_ret,(const void **)&friend)) | 1882 | if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next(friend_iter,&key_ret,(const void **)&friend)) |
1662 | { | 1883 | { |
1663 | memcpy (&all_known_peers[j], &(friend->id), sizeof (struct GNUNET_PeerIdentity)); | 1884 | memcpy (&(all_known_peers[j].peer_id), &(friend->id), sizeof (uint64_t)); |
1885 | all_known_peers[j].type = FRIEND; | ||
1886 | all_known_peers[j].data = friend; | ||
1664 | j++; | 1887 | j++; |
1665 | } | 1888 | } |
1666 | } | 1889 | } |
@@ -1669,59 +1892,55 @@ find_successor(uint64_t *value, struct GNUNET_PeerIdentity *current_destination, | |||
1669 | finger_iter = GNUNET_CONTAINER_multipeermap_iterator_create (finger_peermap); | 1892 | finger_iter = GNUNET_CONTAINER_multipeermap_iterator_create (finger_peermap); |
1670 | for (finger_index = 0; finger_index < GNUNET_CONTAINER_multipeermap_size (finger_peermap); finger_index++) | 1893 | for (finger_index = 0; finger_index < GNUNET_CONTAINER_multipeermap_size (finger_peermap); finger_index++) |
1671 | { | 1894 | { |
1672 | /* FIXME: I don't think we are actually iterating. | ||
1673 | Read about how to iterate over the multi peer map. */ | ||
1674 | if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next(finger_iter,&key_ret,(const void **)&finger)) | 1895 | if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next(finger_iter,&key_ret,(const void **)&finger)) |
1675 | { | 1896 | { |
1676 | memcpy (&all_known_peers[j], &(finger->finger_identity), sizeof (struct GNUNET_PeerIdentity)); | 1897 | memcpy (&(all_known_peers[j].peer_id), &(finger->finger_identity), sizeof (uint64_t)); |
1898 | all_known_peers[j].type = FINGER; | ||
1899 | all_known_peers[j].data = finger; | ||
1677 | j++; | 1900 | j++; |
1678 | } | 1901 | } |
1679 | } | 1902 | } |
1680 | 1903 | ||
1681 | GNUNET_CONTAINER_multipeermap_iterator_destroy (finger_iter); | 1904 | GNUNET_CONTAINER_multipeermap_iterator_destroy (finger_iter); |
1682 | GNUNET_CONTAINER_multipeermap_iterator_destroy (friend_iter); | 1905 | GNUNET_CONTAINER_multipeermap_iterator_destroy (friend_iter); |
1683 | 1906 | ||
1684 | /* FIMXE : Should we not sort it for 64 bits. */ | 1907 | qsort (&all_known_peers, size, sizeof (struct Sorting_List), &compare_peer_id); |
1685 | qsort (all_known_peers, size, sizeof (uint64_t), &compare_peer_id); | ||
1686 | 1908 | ||
1687 | /* search value in all_known_peers array. */ | 1909 | /* search value in all_known_peers array. */ |
1688 | successor = binary_search (all_known_peers, value, size); | 1910 | successor = find_closest_successor (all_known_peers, value, size); |
1689 | 1911 | ||
1690 | /* compare successor with my_identity, finger and friend */ | 1912 | if (successor->type == MY_ID) |
1691 | if(0 == GNUNET_CRYPTO_cmp_peer_identity(&(my_identity), successor)) | ||
1692 | { | 1913 | { |
1693 | FPRINTF (stderr,_("\nSUPU %s, %s, %d"), __FILE__, __func__,__LINE__); | ||
1694 | *type = MY_ID; | 1914 | *type = MY_ID; |
1695 | return NULL; | 1915 | return NULL; |
1696 | } | 1916 | } |
1697 | else if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (friend_peermap, | 1917 | else if (successor->type == FRIEND) |
1698 | successor)) | ||
1699 | { | 1918 | { |
1700 | FPRINTF (stderr,_("\nSUPU %s, %s, %d"), __FILE__, __func__,__LINE__); | ||
1701 | *type = FRIEND; | 1919 | *type = FRIEND; |
1702 | memcpy (current_destination, successor, sizeof (struct GNUNET_PeerIdentity)); | 1920 | struct FriendInfo *target_friend; |
1703 | return successor; | 1921 | target_friend = (struct FriendInfo *)successor->data; |
1922 | memcpy (current_destination, &(target_friend->id), sizeof (struct GNUNET_PeerIdentity)); | ||
1923 | return current_destination; | ||
1704 | } | 1924 | } |
1705 | else if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (finger_peermap, | 1925 | else if (successor->type == FINGER) |
1706 | successor)) | ||
1707 | { | 1926 | { |
1708 | FPRINTF (stderr,_("\nSUPU %s, %s, %d"), __FILE__, __func__,__LINE__); | ||
1709 | *type = FINGER; | 1927 | *type = FINGER; |
1710 | memcpy (current_destination, successor, sizeof (struct GNUNET_PeerIdentity)); | ||
1711 | /* get the corresponding finger for succcesor and read the first element from | ||
1712 | the trail list and return that element. */ | ||
1713 | struct FingerInfo *successor_finger; | ||
1714 | struct GNUNET_PeerIdentity *next_hop; | 1928 | struct GNUNET_PeerIdentity *next_hop; |
1929 | struct FingerInfo *finger; | ||
1930 | struct TrailPeerList *iterator; | ||
1931 | iterator = GNUNET_malloc (sizeof (struct TrailPeerList)); | ||
1932 | finger = successor->data; | ||
1933 | iterator = finger->head->next; | ||
1715 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 1934 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
1716 | successor_finger = GNUNET_CONTAINER_multipeermap_get (finger_peermap, successor); | 1935 | memcpy (next_hop, &(iterator->peer), sizeof (struct GNUNET_PeerIdentity)); |
1717 | //memcpy (next_hop, &(successor_finger->trail_peer_list[0]), sizeof (struct GNUNET_PeerIdentity)); | 1936 | memcpy (current_destination, &(finger->finger_identity), sizeof (struct GNUNET_PeerIdentity)); |
1718 | return next_hop; | 1937 | return next_hop; |
1719 | } | 1938 | } |
1720 | FPRINTF (stderr,_("\nSUPU %s, %s, %d"), __FILE__, __func__,__LINE__); | 1939 | else |
1721 | return NULL; | 1940 | { |
1722 | #endif | 1941 | type = NULL; |
1723 | *type = MY_ID; | 1942 | return NULL; |
1724 | return &my_identity; | 1943 | } |
1725 | } | 1944 | } |
1726 | 1945 | ||
1727 | 1946 | ||
@@ -1750,7 +1969,10 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1750 | struct GNUNET_PeerIdentity *next_peer; | 1969 | struct GNUNET_PeerIdentity *next_peer; |
1751 | unsigned int successor_flag; | 1970 | unsigned int successor_flag; |
1752 | unsigned int predecessor_flag; | 1971 | unsigned int predecessor_flag; |
1753 | 1972 | uint64_t value; | |
1973 | struct GNUNET_PeerIdentity *current_destination; | ||
1974 | current_destination = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | ||
1975 | |||
1754 | /* parse and validate message. */ | 1976 | /* parse and validate message. */ |
1755 | msize = ntohs (message->size); | 1977 | msize = ntohs (message->size); |
1756 | if (msize < sizeof (struct PeerTrailSetupMessage)) | 1978 | if (msize < sizeof (struct PeerTrailSetupMessage)) |
@@ -1766,8 +1988,8 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1766 | finger_map_index = ntohl (trail_setup->finger_map_index); | 1988 | finger_map_index = ntohl (trail_setup->finger_map_index); |
1767 | successor_flag = ntohl (trail_setup->successor_flag); | 1989 | successor_flag = ntohl (trail_setup->successor_flag); |
1768 | predecessor_flag = ntohl (trail_setup->predecessor_flag); | 1990 | predecessor_flag = ntohl (trail_setup->predecessor_flag); |
1769 | |||
1770 | trail_peer_list = (struct GNUNET_PeerIdentity *) &trail_setup[1]; | 1991 | trail_peer_list = (struct GNUNET_PeerIdentity *) &trail_setup[1]; |
1992 | value = trail_setup->destination_finger; | ||
1771 | 1993 | ||
1772 | if ((msize < | 1994 | if ((msize < |
1773 | sizeof (struct PeerTrailSetupMessage) + | 1995 | sizeof (struct PeerTrailSetupMessage) + |
@@ -1778,7 +2000,7 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1778 | GNUNET_break_op (0); | 2000 | GNUNET_break_op (0); |
1779 | return GNUNET_YES; | 2001 | return GNUNET_YES; |
1780 | } | 2002 | } |
1781 | 2003 | ||
1782 | GNUNET_STATISTICS_update (GDS_stats, | 2004 | GNUNET_STATISTICS_update (GDS_stats, |
1783 | gettext_noop ("# TRAIL SETUP requests received"), 1, | 2005 | gettext_noop ("# TRAIL SETUP requests received"), 1, |
1784 | GNUNET_NO); | 2006 | GNUNET_NO); |
@@ -1791,8 +2013,8 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1791 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&(trail_setup->current_destination), | 2013 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&(trail_setup->current_destination), |
1792 | &my_identity))) | 2014 | &my_identity))) |
1793 | { | 2015 | { |
1794 | next_hop = find_successor (&(trail_setup->destination_finger), | 2016 | next_hop = find_successor (value, |
1795 | &(trail_setup->current_destination), | 2017 | current_destination, |
1796 | &(peer_type)); | 2018 | &(peer_type)); |
1797 | } | 2019 | } |
1798 | else | 2020 | else |
@@ -1828,8 +2050,8 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1828 | else | 2050 | else |
1829 | { | 2051 | { |
1830 | /* I am the current_destination finger */ | 2052 | /* I am the current_destination finger */ |
1831 | next_hop = find_successor (&(trail_setup->destination_finger), | 2053 | next_hop = find_successor (value, |
1832 | &(trail_setup->current_destination), &(peer_type)); | 2054 | current_destination, &(peer_type)); |
1833 | } | 2055 | } |
1834 | } | 2056 | } |
1835 | 2057 | ||
@@ -1851,7 +2073,8 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1851 | if(current_trail_index != 0) | 2073 | if(current_trail_index != 0) |
1852 | current_trail_index = current_trail_index - 1; | 2074 | current_trail_index = current_trail_index - 1; |
1853 | 2075 | ||
1854 | GDS_NEIGHBOURS_handle_trail_setup_result (&(trail_setup->source_peer), | 2076 | update_predecessor (&(trail_setup->source_peer), trail_peer_list, trail_length ); |
2077 | GDS_NEIGHBOURS_send_trail_setup_result (&(trail_setup->source_peer), | ||
1855 | &(my_identity), | 2078 | &(my_identity), |
1856 | target_friend, trail_length, | 2079 | target_friend, trail_length, |
1857 | trail_peer_list, current_trail_index, | 2080 | trail_peer_list, current_trail_index, |
@@ -1874,12 +2097,12 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1874 | if(peer_type == FINGER) | 2097 | if(peer_type == FINGER) |
1875 | { | 2098 | { |
1876 | GDS_ROUTING_add (&(trail_setup->source_peer), | 2099 | GDS_ROUTING_add (&(trail_setup->source_peer), |
1877 | &(trail_setup->current_destination), | 2100 | &(trail_setup->current_destination), |
1878 | next_hop); | 2101 | next_hop); |
1879 | } | 2102 | } |
1880 | 2103 | ||
1881 | GDS_NEIGHBOURS_handle_trail_setup (&(trail_setup->source_peer), | 2104 | GDS_NEIGHBOURS_send_trail_setup (&(trail_setup->source_peer), |
1882 | &(trail_setup->destination_finger), | 2105 | trail_setup->destination_finger, |
1883 | target_friend, | 2106 | target_friend, |
1884 | trail_setup->trail_length, | 2107 | trail_setup->trail_length, |
1885 | peer_list,trail_setup->successor_flag, | 2108 | peer_list,trail_setup->successor_flag, |
@@ -1891,76 +2114,6 @@ return GNUNET_YES; | |||
1891 | 2114 | ||
1892 | 2115 | ||
1893 | /** | 2116 | /** |
1894 | * FIXME: For redundant routing, we may start looking for different | ||
1895 | * paths to reach to same finger. So, in send_find_finger, we are starting | ||
1896 | * the search for trail to a finger, even if we already have found trail to | ||
1897 | * reach to it. There are several reasons for doing so | ||
1898 | * 1. We may reach to a closer successor than we have at the moment. So, we | ||
1899 | * should keep looking for the successor. | ||
1900 | * 2. We may reach to the same successor but through a shorter path. | ||
1901 | * 3. As I don't know how keys are distributed and how put/get will react | ||
1902 | * because of this, I have to think further before implementing it. | ||
1903 | * Add an entry in finger table. | ||
1904 | * @param finger Finger to be added to finger table | ||
1905 | * @param peer_list peers this request has traversed so far | ||
1906 | * @param trail_length Numbers of peers in the trail. | ||
1907 | */ | ||
1908 | static | ||
1909 | void finger_table_add (struct GNUNET_PeerIdentity *finger, | ||
1910 | struct GNUNET_PeerIdentity *peer_list, | ||
1911 | unsigned int trail_length, | ||
1912 | unsigned int successor_flag, | ||
1913 | unsigned int predecessor_flag, | ||
1914 | unsigned int finger_map_index) | ||
1915 | { | ||
1916 | struct FingerInfo *new_finger_entry; | ||
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 | |||
1924 | new_finger_entry = GNUNET_malloc (sizeof (struct FingerInfo)); | ||
1925 | memcpy (&(new_finger_entry->finger_identity), finger, sizeof (struct GNUNET_PeerIdentity)); | ||
1926 | |||
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 | |||
1943 | new_finger_entry->successor = successor_flag; | ||
1944 | new_finger_entry->predecessor = predecessor_flag; | ||
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)); | ||
1954 | |||
1955 | /*FIXME: Is it really a good time to call verify successor message. */ | ||
1956 | if (1 == GNUNET_CONTAINER_multipeermap_size (finger_peermap)) | ||
1957 | { | ||
1958 | verify_successor = GNUNET_SCHEDULER_add_now (&send_verify_successor_message, NULL); | ||
1959 | } | ||
1960 | } | ||
1961 | |||
1962 | |||
1963 | /** | ||
1964 | * Core handle for p2p trail construction result messages. | 2117 | * Core handle for p2p trail construction result messages. |
1965 | * @param cls closure | 2118 | * @param cls closure |
1966 | * @param message message | 2119 | * @param message message |
@@ -2054,7 +2207,7 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p | |||
2054 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_peer); | 2207 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_peer); |
2055 | GNUNET_free (next_peer); | 2208 | GNUNET_free (next_peer); |
2056 | 2209 | ||
2057 | GDS_NEIGHBOURS_handle_trail_setup_result (&(trail_result->destination_peer), | 2210 | GDS_NEIGHBOURS_send_trail_setup_result (&(trail_result->destination_peer), |
2058 | &(trail_result->finger), | 2211 | &(trail_result->finger), |
2059 | target_friend, trail_length, | 2212 | target_friend, trail_length, |
2060 | trail_peer_list,current_trail_index, | 2213 | trail_peer_list,current_trail_index, |
@@ -2111,18 +2264,13 @@ handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *pee | |||
2111 | return GNUNET_YES; | 2264 | return GNUNET_YES; |
2112 | } | 2265 | } |
2113 | 2266 | ||
2114 | current_trail_index = ntohl (vsm->current_trail_index); | 2267 | current_trail_index = ntohl (vsm->current_trail_index); |
2115 | |||
2116 | trail_peer_list = (struct GNUNET_PeerIdentity *) &vsm[1]; | 2268 | trail_peer_list = (struct GNUNET_PeerIdentity *) &vsm[1]; |
2117 | 2269 | ||
2118 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 2270 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
2119 | |||
2120 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(vsm->successor), | 2271 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(vsm->successor), |
2121 | &my_identity))) | 2272 | &my_identity))) |
2122 | { | 2273 | { |
2123 | /* I am the successor, check who is my predecessor. If my predecessor is not | ||
2124 | same as source peer then update the trail and send back to calling function. | ||
2125 | */ | ||
2126 | struct GNUNET_CONTAINER_MultiPeerMapIterator *finger_iter; | 2274 | struct GNUNET_CONTAINER_MultiPeerMapIterator *finger_iter; |
2127 | struct GNUNET_PeerIdentity key_ret; | 2275 | struct GNUNET_PeerIdentity key_ret; |
2128 | unsigned int finger_index; | 2276 | unsigned int finger_index; |
@@ -2140,11 +2288,11 @@ handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *pee | |||
2140 | break; | 2288 | break; |
2141 | } | 2289 | } |
2142 | } | 2290 | } |
2143 | |||
2144 | GNUNET_CONTAINER_multipeermap_iterator_destroy (finger_iter); | 2291 | GNUNET_CONTAINER_multipeermap_iterator_destroy (finger_iter); |
2292 | |||
2145 | destination_peer = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 2293 | destination_peer = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
2146 | memcpy (destination_peer, &(vsm->source_peer), sizeof (struct GNUNET_PeerIdentity)); | 2294 | memcpy (destination_peer, &(vsm->source_peer), sizeof (struct GNUNET_PeerIdentity)); |
2147 | current_trail_index = trail_length - 2; /*SUPU: I am the last element in the trail.*/ | 2295 | current_trail_index = trail_length - 2; |
2148 | memcpy (next_hop, &trail_peer_list[current_trail_index], sizeof (struct GNUNET_PeerIdentity)); | 2296 | memcpy (next_hop, &trail_peer_list[current_trail_index], sizeof (struct GNUNET_PeerIdentity)); |
2149 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | 2297 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); |
2150 | GNUNET_free (next_hop); | 2298 | GNUNET_free (next_hop); |
@@ -2152,33 +2300,25 @@ handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *pee | |||
2152 | if (current_trail_index != 0) | 2300 | if (current_trail_index != 0) |
2153 | current_trail_index = current_trail_index - 1; | 2301 | current_trail_index = current_trail_index - 1; |
2154 | 2302 | ||
2155 | /* FIXME: Here we should check if our predecessor is source peer or not. | 2303 | |
2156 | If not then, we can send an updated trail that goes through us. Instead of | ||
2157 | looking for a new trail to reach to the new successor, source peer | ||
2158 | can just use this trail. It may not be an optimal route. */ | ||
2159 | if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&(vsm->source_peer), | 2304 | if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&(vsm->source_peer), |
2160 | &(my_predecessor->finger_identity)))) | 2305 | &(my_predecessor->finger_identity)))) |
2161 | { | 2306 | { |
2162 | /*If we have a new predecessor, then create a new trail to reach from | ||
2163 | vsm source peer to this new successor of source peer. */ | ||
2164 | struct GNUNET_PeerIdentity *new_successor_trail; | 2307 | struct GNUNET_PeerIdentity *new_successor_trail; |
2165 | unsigned int my_predecessor_trail_length; | ||
2166 | unsigned int new_trail_length; | 2308 | unsigned int new_trail_length; |
2167 | unsigned int i; | 2309 | unsigned int i; |
2168 | |||
2169 | /* SUPU: The trail that we store corresponding to each finger contains | ||
2170 | * me as the first element. So, we are included twice when we join the | ||
2171 | * two trails. */ | ||
2172 | my_predecessor_trail_length = (my_predecessor->trail_length) - 1; /*SUPU: Removing myself from the trail */ | ||
2173 | new_trail_length = trail_length + my_predecessor_trail_length; | ||
2174 | 2310 | ||
2311 | new_trail_length = trail_length + my_predecessor->trail_length - 1; | ||
2175 | new_successor_trail = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) | 2312 | new_successor_trail = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) |
2176 | * new_trail_length); | 2313 | * new_trail_length); |
2314 | |||
2315 | /* Copy the trail from source peer to me. */ | ||
2177 | memcpy (new_successor_trail, trail_peer_list, | 2316 | memcpy (new_successor_trail, trail_peer_list, |
2178 | trail_length * sizeof (struct GNUNET_PeerIdentity)); | 2317 | (trail_length) * sizeof (struct GNUNET_PeerIdentity)); |
2179 | 2318 | ||
2319 | /* Copy the trail from me to my predecessor excluding me. */ | ||
2180 | struct TrailPeerList *iterator; | 2320 | struct TrailPeerList *iterator; |
2181 | iterator = my_predecessor->head->next; /* FIXME: Check if you are removing yourself */ | 2321 | iterator = my_predecessor->head->next; |
2182 | i = trail_length; | 2322 | i = trail_length; |
2183 | while (i < new_trail_length) | 2323 | while (i < new_trail_length) |
2184 | { | 2324 | { |
@@ -2186,9 +2326,8 @@ handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *pee | |||
2186 | iterator = iterator->next; | 2326 | iterator = iterator->next; |
2187 | i++; | 2327 | i++; |
2188 | } | 2328 | } |
2189 | 2329 | ||
2190 | 2330 | GDS_NEIGHBOURS_send_verify_successor_result (destination_peer, | |
2191 | GDS_NEIGHBOURS_handle_verify_successor_result (destination_peer, | ||
2192 | &(my_identity), | 2331 | &(my_identity), |
2193 | &(my_predecessor->finger_identity), | 2332 | &(my_predecessor->finger_identity), |
2194 | target_friend, | 2333 | target_friend, |
@@ -2196,8 +2335,8 @@ handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *pee | |||
2196 | new_trail_length, | 2335 | new_trail_length, |
2197 | current_trail_index); | 2336 | current_trail_index); |
2198 | } | 2337 | } |
2199 | 2338 | ||
2200 | GDS_NEIGHBOURS_handle_verify_successor_result (destination_peer, | 2339 | GDS_NEIGHBOURS_send_verify_successor_result (destination_peer, |
2201 | &(my_identity), | 2340 | &(my_identity), |
2202 | &(my_predecessor->finger_identity), | 2341 | &(my_predecessor->finger_identity), |
2203 | target_friend, | 2342 | target_friend, |
@@ -2214,7 +2353,7 @@ handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *pee | |||
2214 | 2353 | ||
2215 | current_trail_index = current_trail_index + 1; | 2354 | current_trail_index = current_trail_index + 1; |
2216 | 2355 | ||
2217 | GDS_NEIGHBOURS_handle_verify_successor(&(vsm->source_peer), | 2356 | GDS_NEIGHBOURS_send_verify_successor(&(vsm->source_peer), |
2218 | &(vsm->successor), | 2357 | &(vsm->successor), |
2219 | target_friend, | 2358 | target_friend, |
2220 | trail_peer_list, | 2359 | trail_peer_list, |
@@ -2239,7 +2378,58 @@ update_successor (struct GNUNET_PeerIdentity *successor_identity, | |||
2239 | { | 2378 | { |
2240 | struct FingerInfo *new_finger_entry; | 2379 | struct FingerInfo *new_finger_entry; |
2241 | unsigned int i; | 2380 | unsigned int i; |
2381 | struct FingerInfo *finger; | ||
2382 | struct GNUNET_CONTAINER_MultiPeerMapIterator *finger_iter; | ||
2383 | struct GNUNET_PeerIdentity key_ret; | ||
2384 | int finger_index; | ||
2385 | int flag = 0; | ||
2386 | |||
2387 | /* Check if you already have a predecessor. Then remove it and add the new | ||
2388 | entry. */ | ||
2389 | finger_iter = GNUNET_CONTAINER_multipeermap_iterator_create (finger_peermap); | ||
2390 | for (finger_index = 0; finger_index < GNUNET_CONTAINER_multipeermap_size (finger_peermap); finger_index++) | ||
2391 | { | ||
2392 | if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next (finger_iter, &key_ret, | ||
2393 | (const void **)&finger)) | ||
2394 | { | ||
2395 | if (1 == finger->successor) | ||
2396 | { | ||
2397 | flag = 1; | ||
2398 | break; | ||
2399 | } | ||
2400 | } | ||
2401 | } | ||
2402 | GNUNET_CONTAINER_multipeermap_iterator_destroy (finger_iter); | ||
2403 | /* check if you come out of the loop or because of the conditoin*/ | ||
2404 | if (flag == 0) | ||
2405 | { | ||
2406 | goto add_new_successor; | ||
2407 | } | ||
2408 | else | ||
2409 | { | ||
2410 | if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains(finger_peermap, &(finger->finger_identity))) | ||
2411 | { | ||
2412 | /* compare peer ids of new finger and old finger if they are same don't remove and exit | ||
2413 | if different then remove and exit. */ | ||
2414 | if ( 0 == GNUNET_CRYPTO_cmp_peer_identity (&(finger->finger_identity), successor_identity)) | ||
2415 | { | ||
2416 | //goto do_nothing; | ||
2417 | exit(0); | ||
2418 | } | ||
2419 | else | ||
2420 | { | ||
2421 | if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove(finger_peermap, &(finger->finger_identity), finger)) | ||
2422 | { | ||
2423 | goto add_new_successor; | ||
2424 | } | ||
2425 | else | ||
2426 | //goto do_nothing; | ||
2427 | exit(0); | ||
2428 | } | ||
2429 | } | ||
2430 | } | ||
2242 | 2431 | ||
2432 | add_new_successor: | ||
2243 | new_finger_entry = GNUNET_malloc (sizeof (struct FingerInfo)); | 2433 | new_finger_entry = GNUNET_malloc (sizeof (struct FingerInfo)); |
2244 | new_finger_entry->predecessor = 0; | 2434 | new_finger_entry->predecessor = 0; |
2245 | new_finger_entry->successor = 1; | 2435 | new_finger_entry->successor = 1; |
@@ -2263,57 +2453,6 @@ update_successor (struct GNUNET_PeerIdentity *successor_identity, | |||
2263 | 2453 | ||
2264 | 2454 | ||
2265 | /** | 2455 | /** |
2266 | * FIXME: Also copy the trail list in reverse direction that is the path to | ||
2267 | * reach to your predecessor. | ||
2268 | * Replace your predecessor with new predecessor. | ||
2269 | * @param predecessor My new predecessor | ||
2270 | * @param peer_list Trail list to reach to my new predecessor | ||
2271 | * @param trail_length Number of peers in the trail. | ||
2272 | */ | ||
2273 | static void | ||
2274 | update_predecessor (struct GNUNET_PeerIdentity *predecessor, | ||
2275 | struct GNUNET_PeerIdentity *peer_list, | ||
2276 | unsigned int trail_length) | ||
2277 | { | ||
2278 | struct GNUNET_PeerIdentity *trail_peer_list; | ||
2279 | struct FingerInfo *new_finger_entry; | ||
2280 | unsigned int i; | ||
2281 | unsigned int j; | ||
2282 | |||
2283 | i = trail_length - 1; | ||
2284 | j = 0; | ||
2285 | trail_peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * | ||
2286 | trail_length); | ||
2287 | while (i > 0) | ||
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; | ||
2300 | |||
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 | } | ||
2313 | } | ||
2314 | |||
2315 | |||
2316 | /** | ||
2317 | * Core handle for p2p notify new successor messages. | 2456 | * Core handle for p2p notify new successor messages. |
2318 | * @param cls closure | 2457 | * @param cls closure |
2319 | * @param message message | 2458 | * @param message message |
@@ -2337,7 +2476,6 @@ handle_dht_p2p_notify_new_successor(void *cls, const struct GNUNET_PeerIdentity | |||
2337 | return GNUNET_YES; | 2476 | return GNUNET_YES; |
2338 | } | 2477 | } |
2339 | 2478 | ||
2340 | /* Again in the function you have the whole trail to reach to the destination. */ | ||
2341 | nsm = (struct PeerNotifyNewSuccessorMessage *) message; | 2479 | nsm = (struct PeerNotifyNewSuccessorMessage *) message; |
2342 | trail_length = ntohl (nsm->trail_length); | 2480 | trail_length = ntohl (nsm->trail_length); |
2343 | 2481 | ||
@@ -2355,7 +2493,7 @@ handle_dht_p2p_notify_new_successor(void *cls, const struct GNUNET_PeerIdentity | |||
2355 | trail_peer_list = (struct GNUNET_PeerIdentity *) &nsm[1]; | 2493 | trail_peer_list = (struct GNUNET_PeerIdentity *) &nsm[1]; |
2356 | 2494 | ||
2357 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(nsm->destination_peer), | 2495 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(nsm->destination_peer), |
2358 | &my_identity))) | 2496 | &my_identity))) |
2359 | { | 2497 | { |
2360 | update_predecessor (&(nsm->source_peer), | 2498 | update_predecessor (&(nsm->source_peer), |
2361 | trail_peer_list, | 2499 | trail_peer_list, |
@@ -2368,12 +2506,14 @@ handle_dht_p2p_notify_new_successor(void *cls, const struct GNUNET_PeerIdentity | |||
2368 | target_friend = GNUNET_malloc (sizeof (struct FriendInfo)); | 2506 | target_friend = GNUNET_malloc (sizeof (struct FriendInfo)); |
2369 | struct GNUNET_PeerIdentity *next_hop; | 2507 | struct GNUNET_PeerIdentity *next_hop; |
2370 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 2508 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
2371 | memcpy (next_hop, &trail_peer_list[current_trail_index], sizeof (struct GNUNET_PeerIdentity)); | 2509 | memcpy (next_hop, &trail_peer_list[current_trail_index], sizeof (struct GNUNET_PeerIdentity)); |
2510 | |||
2511 | |||
2372 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | 2512 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); |
2373 | GNUNET_free (next_hop); | 2513 | GNUNET_free (next_hop); |
2374 | current_trail_index = current_trail_index + 1; | 2514 | current_trail_index = current_trail_index + 1; |
2375 | 2515 | ||
2376 | GDS_NEIGHBOURS_notify_new_successor (&(nsm->source_peer), | 2516 | GDS_NEIGHBOURS_send_notify_new_successor (&(nsm->source_peer), |
2377 | &(nsm->destination_peer), | 2517 | &(nsm->destination_peer), |
2378 | target_friend, trail_peer_list, trail_length, | 2518 | target_friend, trail_peer_list, trail_length, |
2379 | current_trail_index); | 2519 | current_trail_index); |
@@ -2407,7 +2547,7 @@ handle_dht_p2p_verify_successor_result(void *cls, const struct GNUNET_PeerIdenti | |||
2407 | GNUNET_break_op (0); | 2547 | GNUNET_break_op (0); |
2408 | return GNUNET_YES; | 2548 | return GNUNET_YES; |
2409 | } | 2549 | } |
2410 | 2550 | ||
2411 | /* Again in the function you have the whole trail to reach to the destination. */ | 2551 | /* Again in the function you have the whole trail to reach to the destination. */ |
2412 | vsrm = (struct PeerVerifySuccessorResultMessage *) message; | 2552 | vsrm = (struct PeerVerifySuccessorResultMessage *) message; |
2413 | current_trail_index = ntohl (vsrm->current_index); | 2553 | current_trail_index = ntohl (vsrm->current_index); |
@@ -2434,29 +2574,26 @@ handle_dht_p2p_verify_successor_result(void *cls, const struct GNUNET_PeerIdenti | |||
2434 | update_successor (&(vsrm->my_predecessor), trail_peer_list, trail_length); | 2574 | update_successor (&(vsrm->my_predecessor), trail_peer_list, trail_length); |
2435 | 2575 | ||
2436 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 2576 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
2437 | /* FIXME: Assuming that I am also in trail list and I am the first peer. */ | ||
2438 | memcpy (next_hop, &trail_peer_list[1], sizeof (struct GNUNET_PeerIdentity)); | 2577 | memcpy (next_hop, &trail_peer_list[1], sizeof (struct GNUNET_PeerIdentity)); |
2439 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | 2578 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); |
2579 | current_trail_index = 2; | ||
2440 | GNUNET_free (next_hop); | 2580 | GNUNET_free (next_hop); |
2441 | 2581 | ||
2442 | GDS_NEIGHBOURS_notify_new_successor (&my_identity, &(vsrm->my_predecessor), | 2582 | GDS_NEIGHBOURS_send_notify_new_successor (&my_identity, &(vsrm->my_predecessor), |
2443 | target_friend, trail_peer_list, | 2583 | target_friend, trail_peer_list, |
2444 | trail_length, current_trail_index); | 2584 | trail_length, current_trail_index); |
2445 | } | 2585 | } |
2446 | } | 2586 | } |
2447 | else | 2587 | else |
2448 | { | 2588 | { |
2449 | /* Read the peer trail list and find out the next destination to forward this | ||
2450 | packet to. */ | ||
2451 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 2589 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
2452 | 2590 | ||
2453 | /* FIXME: Assuming that I am also in trail list and I am the first peer. */ | ||
2454 | memcpy (next_hop, &trail_peer_list[current_trail_index], sizeof (struct GNUNET_PeerIdentity)); | 2591 | memcpy (next_hop, &trail_peer_list[current_trail_index], sizeof (struct GNUNET_PeerIdentity)); |
2455 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | 2592 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); |
2456 | GNUNET_free (next_hop); | 2593 | GNUNET_free (next_hop); |
2457 | current_trail_index = current_trail_index - 1; | 2594 | current_trail_index = current_trail_index - 1; |
2458 | 2595 | ||
2459 | GDS_NEIGHBOURS_handle_verify_successor_result (&(vsrm->destination_peer), | 2596 | GDS_NEIGHBOURS_send_verify_successor_result (&(vsrm->destination_peer), |
2460 | &(vsrm->source_successor), | 2597 | &(vsrm->source_successor), |
2461 | &(vsrm->my_predecessor), | 2598 | &(vsrm->my_predecessor), |
2462 | target_friend, | 2599 | target_friend, |