diff options
Diffstat (limited to 'src/dht/gnunet-service-dht_neighbours.c')
-rw-r--r-- | src/dht/gnunet-service-dht_neighbours.c | 108 |
1 files changed, 69 insertions, 39 deletions
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c index 0309bea88..56639448f 100644 --- a/src/dht/gnunet-service-dht_neighbours.c +++ b/src/dht/gnunet-service-dht_neighbours.c | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009-2017 GNUnet e.V. | 3 | Copyright (C) 2009-2017 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | 18 | ||
21 | /** | 19 | /** |
@@ -404,7 +402,7 @@ static struct GNUNET_PeerIdentity my_identity; | |||
404 | /** | 402 | /** |
405 | * Hash of the identity of this peer. | 403 | * Hash of the identity of this peer. |
406 | */ | 404 | */ |
407 | static struct GNUNET_HashCode my_identity_hash; | 405 | struct GNUNET_HashCode my_identity_hash; |
408 | 406 | ||
409 | /** | 407 | /** |
410 | * Handle to CORE. | 408 | * Handle to CORE. |
@@ -421,7 +419,7 @@ static struct GNUNET_ATS_ConnectivityHandle *ats_ch; | |||
421 | * Find the optimal bucket for this key. | 419 | * Find the optimal bucket for this key. |
422 | * | 420 | * |
423 | * @param hc the hashcode to compare our identity to | 421 | * @param hc the hashcode to compare our identity to |
424 | * @return the proper bucket index, or GNUNET_SYSERR | 422 | * @return the proper bucket index, or #GNUNET_SYSERR |
425 | * on error (same hashcode) | 423 | * on error (same hashcode) |
426 | */ | 424 | */ |
427 | static int | 425 | static int |
@@ -470,6 +468,7 @@ free_connect_info (void *cls, | |||
470 | { | 468 | { |
471 | struct ConnectInfo *ci = value; | 469 | struct ConnectInfo *ci = value; |
472 | 470 | ||
471 | (void) cls; | ||
473 | GNUNET_assert (GNUNET_YES == | 472 | GNUNET_assert (GNUNET_YES == |
474 | GNUNET_CONTAINER_multipeermap_remove (all_desired_peers, | 473 | GNUNET_CONTAINER_multipeermap_remove (all_desired_peers, |
475 | peer, | 474 | peer, |
@@ -581,7 +580,10 @@ update_desire_strength (void *cls, | |||
581 | const struct GNUNET_PeerIdentity *pid, | 580 | const struct GNUNET_PeerIdentity *pid, |
582 | void *value) | 581 | void *value) |
583 | { | 582 | { |
584 | try_connect (pid, NULL); | 583 | (void) cls; |
584 | (void) value; | ||
585 | try_connect (pid, | ||
586 | NULL); | ||
585 | return GNUNET_YES; | 587 | return GNUNET_YES; |
586 | } | 588 | } |
587 | 589 | ||
@@ -618,6 +620,8 @@ add_known_to_bloom (void *cls, | |||
618 | struct GNUNET_BLOCK_Group *bg = cls; | 620 | struct GNUNET_BLOCK_Group *bg = cls; |
619 | struct GNUNET_HashCode key_hash; | 621 | struct GNUNET_HashCode key_hash; |
620 | 622 | ||
623 | (void) cls; | ||
624 | (void) value; | ||
621 | GNUNET_CRYPTO_hash (key, | 625 | GNUNET_CRYPTO_hash (key, |
622 | sizeof (struct GNUNET_PeerIdentity), | 626 | sizeof (struct GNUNET_PeerIdentity), |
623 | &key_hash); | 627 | &key_hash); |
@@ -645,7 +649,8 @@ send_find_peer_message (void *cls) | |||
645 | struct GNUNET_BLOCK_Group *bg; | 649 | struct GNUNET_BLOCK_Group *bg; |
646 | struct GNUNET_CONTAINER_BloomFilter *peer_bf; | 650 | struct GNUNET_CONTAINER_BloomFilter *peer_bf; |
647 | 651 | ||
648 | find_peer_task = NULL; | 652 | (void) cls; |
653 | find_peer_task = NULL; | ||
649 | if (newly_found_peers > bucket_size) | 654 | if (newly_found_peers > bucket_size) |
650 | { | 655 | { |
651 | /* If we are finding many peers already, no need to send out our request right now! */ | 656 | /* If we are finding many peers already, no need to send out our request right now! */ |
@@ -718,7 +723,8 @@ handle_core_connect (void *cls, | |||
718 | { | 723 | { |
719 | struct PeerInfo *pi; | 724 | struct PeerInfo *pi; |
720 | 725 | ||
721 | /* Check for connect to self message */ | 726 | (void) cls; |
727 | /* Check for connect to self message */ | ||
722 | if (0 == memcmp (&my_identity, | 728 | if (0 == memcmp (&my_identity, |
723 | peer, | 729 | peer, |
724 | sizeof (struct GNUNET_PeerIdentity))) | 730 | sizeof (struct GNUNET_PeerIdentity))) |
@@ -741,13 +747,13 @@ handle_core_connect (void *cls, | |||
741 | &pi->phash); | 747 | &pi->phash); |
742 | pi->peer_bucket = find_bucket (&pi->phash); | 748 | pi->peer_bucket = find_bucket (&pi->phash); |
743 | GNUNET_assert ( (pi->peer_bucket >= 0) && | 749 | GNUNET_assert ( (pi->peer_bucket >= 0) && |
744 | (pi->peer_bucket < MAX_BUCKETS) ); | 750 | ((unsigned int) pi->peer_bucket < MAX_BUCKETS) ); |
745 | GNUNET_CONTAINER_DLL_insert_tail (k_buckets[pi->peer_bucket].head, | 751 | GNUNET_CONTAINER_DLL_insert_tail (k_buckets[pi->peer_bucket].head, |
746 | k_buckets[pi->peer_bucket].tail, | 752 | k_buckets[pi->peer_bucket].tail, |
747 | pi); | 753 | pi); |
748 | k_buckets[pi->peer_bucket].peers_size++; | 754 | k_buckets[pi->peer_bucket].peers_size++; |
749 | closest_bucket = GNUNET_MAX (closest_bucket, | 755 | closest_bucket = GNUNET_MAX (closest_bucket, |
750 | pi->peer_bucket); | 756 | (unsigned int) pi->peer_bucket); |
751 | GNUNET_assert (GNUNET_OK == | 757 | GNUNET_assert (GNUNET_OK == |
752 | GNUNET_CONTAINER_multipeermap_put (all_connected_peers, | 758 | GNUNET_CONTAINER_multipeermap_put (all_connected_peers, |
753 | pi->id, | 759 | pi->id, |
@@ -785,6 +791,7 @@ handle_core_disconnect (void *cls, | |||
785 | { | 791 | { |
786 | struct PeerInfo *to_remove = internal_cls; | 792 | struct PeerInfo *to_remove = internal_cls; |
787 | 793 | ||
794 | (void) cls; | ||
788 | /* Check for disconnect from self message */ | 795 | /* Check for disconnect from self message */ |
789 | if (NULL == to_remove) | 796 | if (NULL == to_remove) |
790 | return; | 797 | return; |
@@ -941,30 +948,30 @@ get_distance (const struct GNUNET_HashCode *target, | |||
941 | * @return #GNUNET_YES if node location is closest, | 948 | * @return #GNUNET_YES if node location is closest, |
942 | * #GNUNET_NO otherwise. | 949 | * #GNUNET_NO otherwise. |
943 | */ | 950 | */ |
944 | static int | 951 | int |
945 | am_closest_peer (const struct GNUNET_HashCode *key, | 952 | GDS_am_closest_peer (const struct GNUNET_HashCode *key, |
946 | const struct GNUNET_CONTAINER_BloomFilter *bloom) | 953 | const struct GNUNET_CONTAINER_BloomFilter *bloom) |
947 | { | 954 | { |
948 | int bits; | 955 | int bits; |
949 | int other_bits; | 956 | int other_bits; |
950 | int bucket_num; | 957 | int bucket_num; |
951 | int count; | ||
952 | struct PeerInfo *pos; | 958 | struct PeerInfo *pos; |
953 | 959 | ||
954 | if (0 == memcmp (&my_identity_hash, key, sizeof (struct GNUNET_HashCode))) | 960 | if (0 == memcmp (&my_identity_hash, |
961 | key, | ||
962 | sizeof (struct GNUNET_HashCode))) | ||
955 | return GNUNET_YES; | 963 | return GNUNET_YES; |
956 | bucket_num = find_bucket (key); | 964 | bucket_num = find_bucket (key); |
957 | GNUNET_assert (bucket_num >= 0); | 965 | GNUNET_assert (bucket_num >= 0); |
958 | bits = GNUNET_CRYPTO_hash_matching_bits (&my_identity_hash, | 966 | bits = GNUNET_CRYPTO_hash_matching_bits (&my_identity_hash, |
959 | key); | 967 | key); |
960 | pos = k_buckets[bucket_num].head; | 968 | pos = k_buckets[bucket_num].head; |
961 | count = 0; | 969 | while (NULL != pos) |
962 | while ((NULL != pos) && (count < bucket_size)) | ||
963 | { | 970 | { |
964 | if ((NULL != bloom) && | 971 | if ( (NULL != bloom) && |
965 | (GNUNET_YES == | 972 | (GNUNET_YES == |
966 | GNUNET_CONTAINER_bloomfilter_test (bloom, | 973 | GNUNET_CONTAINER_bloomfilter_test (bloom, |
967 | &pos->phash))) | 974 | &pos->phash)) ) |
968 | { | 975 | { |
969 | pos = pos->next; | 976 | pos = pos->next; |
970 | continue; /* Skip already checked entries */ | 977 | continue; /* Skip already checked entries */ |
@@ -1596,6 +1603,7 @@ static void | |||
1596 | core_init (void *cls, | 1603 | core_init (void *cls, |
1597 | const struct GNUNET_PeerIdentity *identity) | 1604 | const struct GNUNET_PeerIdentity *identity) |
1598 | { | 1605 | { |
1606 | (void) cls; | ||
1599 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1607 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1600 | "CORE called, I am %s\n", | 1608 | "CORE called, I am %s\n", |
1601 | GNUNET_i2s (identity)); | 1609 | GNUNET_i2s (identity)); |
@@ -1621,6 +1629,7 @@ check_dht_p2p_put (void *cls, | |||
1621 | uint32_t putlen; | 1629 | uint32_t putlen; |
1622 | uint16_t msize; | 1630 | uint16_t msize; |
1623 | 1631 | ||
1632 | (void) cls; | ||
1624 | msize = ntohs (put->header.size); | 1633 | msize = ntohs (put->header.size); |
1625 | putlen = ntohl (put->put_path_length); | 1634 | putlen = ntohl (put->put_path_length); |
1626 | if ((msize < | 1635 | if ((msize < |
@@ -1656,7 +1665,17 @@ handle_dht_p2p_put (void *cls, | |||
1656 | struct GNUNET_CONTAINER_BloomFilter *bf; | 1665 | struct GNUNET_CONTAINER_BloomFilter *bf; |
1657 | struct GNUNET_HashCode test_key; | 1666 | struct GNUNET_HashCode test_key; |
1658 | int forwarded; | 1667 | int forwarded; |
1668 | struct GNUNET_TIME_Absolute exp_time; | ||
1659 | 1669 | ||
1670 | exp_time = GNUNET_TIME_absolute_ntoh (put->expiration_time); | ||
1671 | if (0 == GNUNET_TIME_absolute_get_remaining (exp_time).rel_value_us) | ||
1672 | { | ||
1673 | GNUNET_STATISTICS_update (GDS_stats, | ||
1674 | gettext_noop ("# Expired PUTs discarded"), | ||
1675 | 1, | ||
1676 | GNUNET_NO); | ||
1677 | return; | ||
1678 | } | ||
1660 | msize = ntohs (put->header.size); | 1679 | msize = ntohs (put->header.size); |
1661 | putlen = ntohl (put->put_path_length); | 1680 | putlen = ntohl (put->put_path_length); |
1662 | GNUNET_STATISTICS_update (GDS_stats, | 1681 | GNUNET_STATISTICS_update (GDS_stats, |
@@ -1792,7 +1811,7 @@ handle_dht_p2p_put (void *cls, | |||
1792 | putlen = 0; | 1811 | putlen = 0; |
1793 | 1812 | ||
1794 | /* give to local clients */ | 1813 | /* give to local clients */ |
1795 | GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (put->expiration_time), | 1814 | GDS_CLIENTS_handle_reply (exp_time, |
1796 | &put->key, | 1815 | &put->key, |
1797 | 0, | 1816 | 0, |
1798 | NULL, | 1817 | NULL, |
@@ -1803,8 +1822,8 @@ handle_dht_p2p_put (void *cls, | |||
1803 | payload); | 1822 | payload); |
1804 | /* store locally */ | 1823 | /* store locally */ |
1805 | if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || | 1824 | if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || |
1806 | (am_closest_peer (&put->key, bf))) | 1825 | (GDS_am_closest_peer (&put->key, bf))) |
1807 | GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (put->expiration_time), | 1826 | GDS_DATACACHE_handle_put (exp_time, |
1808 | &put->key, | 1827 | &put->key, |
1809 | putlen, | 1828 | putlen, |
1810 | pp, | 1829 | pp, |
@@ -1815,7 +1834,7 @@ handle_dht_p2p_put (void *cls, | |||
1815 | forwarded = GDS_NEIGHBOURS_handle_put (ntohl (put->type), | 1834 | forwarded = GDS_NEIGHBOURS_handle_put (ntohl (put->type), |
1816 | options, | 1835 | options, |
1817 | ntohl (put->desired_replication_level), | 1836 | ntohl (put->desired_replication_level), |
1818 | GNUNET_TIME_absolute_ntoh (put->expiration_time), | 1837 | exp_time, |
1819 | ntohl (put->hop_count), | 1838 | ntohl (put->hop_count), |
1820 | bf, | 1839 | bf, |
1821 | &put->key, | 1840 | &put->key, |
@@ -1832,7 +1851,7 @@ handle_dht_p2p_put (void *cls, | |||
1832 | ntohl (put->hop_count), | 1851 | ntohl (put->hop_count), |
1833 | ntohl (put->desired_replication_level), | 1852 | ntohl (put->desired_replication_level), |
1834 | putlen, pp, | 1853 | putlen, pp, |
1835 | GNUNET_TIME_absolute_ntoh (put->expiration_time), | 1854 | exp_time, |
1836 | &put->key, | 1855 | &put->key, |
1837 | payload, | 1856 | payload, |
1838 | payload_size); | 1857 | payload_size); |
@@ -1909,9 +1928,9 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender, | |||
1909 | sizeof (struct GNUNET_HashCode))) | 1928 | sizeof (struct GNUNET_HashCode))) |
1910 | bucket_idx = closest_bucket; | 1929 | bucket_idx = closest_bucket; |
1911 | else | 1930 | else |
1912 | bucket_idx = GNUNET_MIN (closest_bucket, | 1931 | bucket_idx = GNUNET_MIN ((int) closest_bucket, |
1913 | find_bucket (key)); | 1932 | find_bucket (key)); |
1914 | if (bucket_idx == GNUNET_SYSERR) | 1933 | if (bucket_idx < 0) |
1915 | return; | 1934 | return; |
1916 | bucket = &k_buckets[bucket_idx]; | 1935 | bucket = &k_buckets[bucket_idx]; |
1917 | if (bucket->peers_size == 0) | 1936 | if (bucket->peers_size == 0) |
@@ -2018,6 +2037,7 @@ check_dht_p2p_get (void *cls, | |||
2018 | uint32_t xquery_size; | 2037 | uint32_t xquery_size; |
2019 | uint16_t msize; | 2038 | uint16_t msize; |
2020 | 2039 | ||
2040 | (void) cls; | ||
2021 | msize = ntohs (get->header.size); | 2041 | msize = ntohs (get->header.size); |
2022 | xquery_size = ntohl (get->xquery_size); | 2042 | xquery_size = ntohl (get->xquery_size); |
2023 | if (msize < sizeof (struct PeerGetMessage) + xquery_size) | 2043 | if (msize < sizeof (struct PeerGetMessage) + xquery_size) |
@@ -2122,7 +2142,7 @@ handle_dht_p2p_get (void *cls, | |||
2122 | (unsigned int) ntohl (get->hop_count)); | 2142 | (unsigned int) ntohl (get->hop_count)); |
2123 | /* local lookup (this may update the reply_bf) */ | 2143 | /* local lookup (this may update the reply_bf) */ |
2124 | if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || | 2144 | if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || |
2125 | (am_closest_peer (&get->key, | 2145 | (GDS_am_closest_peer (&get->key, |
2126 | peer_bf))) | 2146 | peer_bf))) |
2127 | { | 2147 | { |
2128 | if ((0 != (options & GNUNET_DHT_RO_FIND_PEER))) | 2148 | if ((0 != (options & GNUNET_DHT_RO_FIND_PEER))) |
@@ -2205,6 +2225,7 @@ check_dht_p2p_result (void *cls, | |||
2205 | uint32_t put_path_length; | 2225 | uint32_t put_path_length; |
2206 | uint16_t msize; | 2226 | uint16_t msize; |
2207 | 2227 | ||
2228 | (void) cls; | ||
2208 | msize = ntohs (prm->header.size); | 2229 | msize = ntohs (prm->header.size); |
2209 | put_path_length = ntohl (prm->put_path_length); | 2230 | put_path_length = ntohl (prm->put_path_length); |
2210 | get_path_length = ntohl (prm->get_path_length); | 2231 | get_path_length = ntohl (prm->get_path_length); |
@@ -2318,8 +2339,18 @@ handle_dht_p2p_result (void *cls, | |||
2318 | uint16_t msize; | 2339 | uint16_t msize; |
2319 | size_t data_size; | 2340 | size_t data_size; |
2320 | enum GNUNET_BLOCK_Type type; | 2341 | enum GNUNET_BLOCK_Type type; |
2342 | struct GNUNET_TIME_Absolute exp_time; | ||
2321 | 2343 | ||
2322 | /* parse and validate message */ | 2344 | /* parse and validate message */ |
2345 | exp_time = GNUNET_TIME_absolute_ntoh (prm->expiration_time); | ||
2346 | if (0 == GNUNET_TIME_absolute_get_remaining (exp_time).rel_value_us) | ||
2347 | { | ||
2348 | GNUNET_STATISTICS_update (GDS_stats, | ||
2349 | gettext_noop ("# Expired results discarded"), | ||
2350 | 1, | ||
2351 | GNUNET_NO); | ||
2352 | return; | ||
2353 | } | ||
2323 | msize = ntohs (prm->header.size); | 2354 | msize = ntohs (prm->header.size); |
2324 | put_path_length = ntohl (prm->put_path_length); | 2355 | put_path_length = ntohl (prm->put_path_length); |
2325 | get_path_length = ntohl (prm->get_path_length); | 2356 | get_path_length = ntohl (prm->get_path_length); |
@@ -2393,7 +2424,6 @@ handle_dht_p2p_result (void *cls, | |||
2393 | h); | 2424 | h); |
2394 | } | 2425 | } |
2395 | 2426 | ||
2396 | |||
2397 | /* First, check if 'peer' is already on the path, and if | 2427 | /* First, check if 'peer' is already on the path, and if |
2398 | so, truncate it instead of expanding. */ | 2428 | so, truncate it instead of expanding. */ |
2399 | for (unsigned int i=0;i<=get_path_length;i++) | 2429 | for (unsigned int i=0;i<=get_path_length;i++) |
@@ -2401,7 +2431,7 @@ handle_dht_p2p_result (void *cls, | |||
2401 | peer->id, | 2431 | peer->id, |
2402 | sizeof (struct GNUNET_PeerIdentity))) | 2432 | sizeof (struct GNUNET_PeerIdentity))) |
2403 | { | 2433 | { |
2404 | process_reply_with_path (GNUNET_TIME_absolute_ntoh (prm->expiration_time), | 2434 | process_reply_with_path (exp_time, |
2405 | &prm->key, | 2435 | &prm->key, |
2406 | i, | 2436 | i, |
2407 | get_path, | 2437 | get_path, |
@@ -2422,7 +2452,7 @@ handle_dht_p2p_result (void *cls, | |||
2422 | get_path_length * sizeof (struct GNUNET_PeerIdentity)); | 2452 | get_path_length * sizeof (struct GNUNET_PeerIdentity)); |
2423 | xget_path[get_path_length] = *peer->id; | 2453 | xget_path[get_path_length] = *peer->id; |
2424 | 2454 | ||
2425 | process_reply_with_path (GNUNET_TIME_absolute_ntoh (prm->expiration_time), | 2455 | process_reply_with_path (exp_time, |
2426 | &prm->key, | 2456 | &prm->key, |
2427 | get_path_length + 1, | 2457 | get_path_length + 1, |
2428 | xget_path, | 2458 | xget_path, |