aboutsummaryrefslogtreecommitdiff
path: root/src/dht
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-06-12 15:10:52 +0200
committerChristian Grothoff <christian@grothoff.org>2018-06-12 15:10:52 +0200
commitc4ea87522edf51a18538715bec7f4baa87c13cd4 (patch)
treee4728e62b8b6bd8f3ab06d98ee6446f0b11861d6 /src/dht
parent3e5842e44aac604c505edd60a4f3dd8a360ff45b (diff)
downloadgnunet-c4ea87522edf51a18538715bec7f4baa87c13cd4.tar.gz
gnunet-c4ea87522edf51a18538715bec7f4baa87c13cd4.zip
ensure DHT never accepts or passes along expired blocks
Diffstat (limited to 'src/dht')
-rw-r--r--src/dht/gnunet-service-dht_neighbours.c76
1 files changed, 54 insertions, 22 deletions
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c
index 9c1395782..56639448f 100644
--- a/src/dht/gnunet-service-dht_neighbours.c
+++ b/src/dht/gnunet-service-dht_neighbours.c
@@ -468,6 +468,7 @@ free_connect_info (void *cls,
468{ 468{
469 struct ConnectInfo *ci = value; 469 struct ConnectInfo *ci = value;
470 470
471 (void) cls;
471 GNUNET_assert (GNUNET_YES == 472 GNUNET_assert (GNUNET_YES ==
472 GNUNET_CONTAINER_multipeermap_remove (all_desired_peers, 473 GNUNET_CONTAINER_multipeermap_remove (all_desired_peers,
473 peer, 474 peer,
@@ -579,7 +580,10 @@ update_desire_strength (void *cls,
579 const struct GNUNET_PeerIdentity *pid, 580 const struct GNUNET_PeerIdentity *pid,
580 void *value) 581 void *value)
581{ 582{
582 try_connect (pid, NULL); 583 (void) cls;
584 (void) value;
585 try_connect (pid,
586 NULL);
583 return GNUNET_YES; 587 return GNUNET_YES;
584} 588}
585 589
@@ -616,6 +620,8 @@ add_known_to_bloom (void *cls,
616 struct GNUNET_BLOCK_Group *bg = cls; 620 struct GNUNET_BLOCK_Group *bg = cls;
617 struct GNUNET_HashCode key_hash; 621 struct GNUNET_HashCode key_hash;
618 622
623 (void) cls;
624 (void) value;
619 GNUNET_CRYPTO_hash (key, 625 GNUNET_CRYPTO_hash (key,
620 sizeof (struct GNUNET_PeerIdentity), 626 sizeof (struct GNUNET_PeerIdentity),
621 &key_hash); 627 &key_hash);
@@ -643,7 +649,8 @@ send_find_peer_message (void *cls)
643 struct GNUNET_BLOCK_Group *bg; 649 struct GNUNET_BLOCK_Group *bg;
644 struct GNUNET_CONTAINER_BloomFilter *peer_bf; 650 struct GNUNET_CONTAINER_BloomFilter *peer_bf;
645 651
646 find_peer_task = NULL; 652 (void) cls;
653 find_peer_task = NULL;
647 if (newly_found_peers > bucket_size) 654 if (newly_found_peers > bucket_size)
648 { 655 {
649 /* 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! */
@@ -716,7 +723,8 @@ handle_core_connect (void *cls,
716{ 723{
717 struct PeerInfo *pi; 724 struct PeerInfo *pi;
718 725
719 /* Check for connect to self message */ 726 (void) cls;
727 /* Check for connect to self message */
720 if (0 == memcmp (&my_identity, 728 if (0 == memcmp (&my_identity,
721 peer, 729 peer,
722 sizeof (struct GNUNET_PeerIdentity))) 730 sizeof (struct GNUNET_PeerIdentity)))
@@ -739,13 +747,13 @@ handle_core_connect (void *cls,
739 &pi->phash); 747 &pi->phash);
740 pi->peer_bucket = find_bucket (&pi->phash); 748 pi->peer_bucket = find_bucket (&pi->phash);
741 GNUNET_assert ( (pi->peer_bucket >= 0) && 749 GNUNET_assert ( (pi->peer_bucket >= 0) &&
742 (pi->peer_bucket < MAX_BUCKETS) ); 750 ((unsigned int) pi->peer_bucket < MAX_BUCKETS) );
743 GNUNET_CONTAINER_DLL_insert_tail (k_buckets[pi->peer_bucket].head, 751 GNUNET_CONTAINER_DLL_insert_tail (k_buckets[pi->peer_bucket].head,
744 k_buckets[pi->peer_bucket].tail, 752 k_buckets[pi->peer_bucket].tail,
745 pi); 753 pi);
746 k_buckets[pi->peer_bucket].peers_size++; 754 k_buckets[pi->peer_bucket].peers_size++;
747 closest_bucket = GNUNET_MAX (closest_bucket, 755 closest_bucket = GNUNET_MAX (closest_bucket,
748 pi->peer_bucket); 756 (unsigned int) pi->peer_bucket);
749 GNUNET_assert (GNUNET_OK == 757 GNUNET_assert (GNUNET_OK ==
750 GNUNET_CONTAINER_multipeermap_put (all_connected_peers, 758 GNUNET_CONTAINER_multipeermap_put (all_connected_peers,
751 pi->id, 759 pi->id,
@@ -783,6 +791,7 @@ handle_core_disconnect (void *cls,
783{ 791{
784 struct PeerInfo *to_remove = internal_cls; 792 struct PeerInfo *to_remove = internal_cls;
785 793
794 (void) cls;
786 /* Check for disconnect from self message */ 795 /* Check for disconnect from self message */
787 if (NULL == to_remove) 796 if (NULL == to_remove)
788 return; 797 return;
@@ -946,23 +955,23 @@ GDS_am_closest_peer (const struct GNUNET_HashCode *key,
946 int bits; 955 int bits;
947 int other_bits; 956 int other_bits;
948 int bucket_num; 957 int bucket_num;
949 int count;
950 struct PeerInfo *pos; 958 struct PeerInfo *pos;
951 959
952 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)))
953 return GNUNET_YES; 963 return GNUNET_YES;
954 bucket_num = find_bucket (key); 964 bucket_num = find_bucket (key);
955 GNUNET_assert (bucket_num >= 0); 965 GNUNET_assert (bucket_num >= 0);
956 bits = GNUNET_CRYPTO_hash_matching_bits (&my_identity_hash, 966 bits = GNUNET_CRYPTO_hash_matching_bits (&my_identity_hash,
957 key); 967 key);
958 pos = k_buckets[bucket_num].head; 968 pos = k_buckets[bucket_num].head;
959 count = 0; 969 while (NULL != pos)
960 while ((NULL != pos) && (count < bucket_size))
961 { 970 {
962 if ((NULL != bloom) && 971 if ( (NULL != bloom) &&
963 (GNUNET_YES == 972 (GNUNET_YES ==
964 GNUNET_CONTAINER_bloomfilter_test (bloom, 973 GNUNET_CONTAINER_bloomfilter_test (bloom,
965 &pos->phash))) 974 &pos->phash)) )
966 { 975 {
967 pos = pos->next; 976 pos = pos->next;
968 continue; /* Skip already checked entries */ 977 continue; /* Skip already checked entries */
@@ -1594,6 +1603,7 @@ static void
1594core_init (void *cls, 1603core_init (void *cls,
1595 const struct GNUNET_PeerIdentity *identity) 1604 const struct GNUNET_PeerIdentity *identity)
1596{ 1605{
1606 (void) cls;
1597 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1607 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1598 "CORE called, I am %s\n", 1608 "CORE called, I am %s\n",
1599 GNUNET_i2s (identity)); 1609 GNUNET_i2s (identity));
@@ -1619,6 +1629,7 @@ check_dht_p2p_put (void *cls,
1619 uint32_t putlen; 1629 uint32_t putlen;
1620 uint16_t msize; 1630 uint16_t msize;
1621 1631
1632 (void) cls;
1622 msize = ntohs (put->header.size); 1633 msize = ntohs (put->header.size);
1623 putlen = ntohl (put->put_path_length); 1634 putlen = ntohl (put->put_path_length);
1624 if ((msize < 1635 if ((msize <
@@ -1654,7 +1665,17 @@ handle_dht_p2p_put (void *cls,
1654 struct GNUNET_CONTAINER_BloomFilter *bf; 1665 struct GNUNET_CONTAINER_BloomFilter *bf;
1655 struct GNUNET_HashCode test_key; 1666 struct GNUNET_HashCode test_key;
1656 int forwarded; 1667 int forwarded;
1668 struct GNUNET_TIME_Absolute exp_time;
1657 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 }
1658 msize = ntohs (put->header.size); 1679 msize = ntohs (put->header.size);
1659 putlen = ntohl (put->put_path_length); 1680 putlen = ntohl (put->put_path_length);
1660 GNUNET_STATISTICS_update (GDS_stats, 1681 GNUNET_STATISTICS_update (GDS_stats,
@@ -1790,7 +1811,7 @@ handle_dht_p2p_put (void *cls,
1790 putlen = 0; 1811 putlen = 0;
1791 1812
1792 /* give to local clients */ 1813 /* give to local clients */
1793 GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (put->expiration_time), 1814 GDS_CLIENTS_handle_reply (exp_time,
1794 &put->key, 1815 &put->key,
1795 0, 1816 0,
1796 NULL, 1817 NULL,
@@ -1802,7 +1823,7 @@ handle_dht_p2p_put (void *cls,
1802 /* store locally */ 1823 /* store locally */
1803 if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || 1824 if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) ||
1804 (GDS_am_closest_peer (&put->key, bf))) 1825 (GDS_am_closest_peer (&put->key, bf)))
1805 GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (put->expiration_time), 1826 GDS_DATACACHE_handle_put (exp_time,
1806 &put->key, 1827 &put->key,
1807 putlen, 1828 putlen,
1808 pp, 1829 pp,
@@ -1813,7 +1834,7 @@ handle_dht_p2p_put (void *cls,
1813 forwarded = GDS_NEIGHBOURS_handle_put (ntohl (put->type), 1834 forwarded = GDS_NEIGHBOURS_handle_put (ntohl (put->type),
1814 options, 1835 options,
1815 ntohl (put->desired_replication_level), 1836 ntohl (put->desired_replication_level),
1816 GNUNET_TIME_absolute_ntoh (put->expiration_time), 1837 exp_time,
1817 ntohl (put->hop_count), 1838 ntohl (put->hop_count),
1818 bf, 1839 bf,
1819 &put->key, 1840 &put->key,
@@ -1830,7 +1851,7 @@ handle_dht_p2p_put (void *cls,
1830 ntohl (put->hop_count), 1851 ntohl (put->hop_count),
1831 ntohl (put->desired_replication_level), 1852 ntohl (put->desired_replication_level),
1832 putlen, pp, 1853 putlen, pp,
1833 GNUNET_TIME_absolute_ntoh (put->expiration_time), 1854 exp_time,
1834 &put->key, 1855 &put->key,
1835 payload, 1856 payload,
1836 payload_size); 1857 payload_size);
@@ -1907,9 +1928,9 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender,
1907 sizeof (struct GNUNET_HashCode))) 1928 sizeof (struct GNUNET_HashCode)))
1908 bucket_idx = closest_bucket; 1929 bucket_idx = closest_bucket;
1909 else 1930 else
1910 bucket_idx = GNUNET_MIN (closest_bucket, 1931 bucket_idx = GNUNET_MIN ((int) closest_bucket,
1911 find_bucket (key)); 1932 find_bucket (key));
1912 if (bucket_idx == GNUNET_SYSERR) 1933 if (bucket_idx < 0)
1913 return; 1934 return;
1914 bucket = &k_buckets[bucket_idx]; 1935 bucket = &k_buckets[bucket_idx];
1915 if (bucket->peers_size == 0) 1936 if (bucket->peers_size == 0)
@@ -2016,6 +2037,7 @@ check_dht_p2p_get (void *cls,
2016 uint32_t xquery_size; 2037 uint32_t xquery_size;
2017 uint16_t msize; 2038 uint16_t msize;
2018 2039
2040 (void) cls;
2019 msize = ntohs (get->header.size); 2041 msize = ntohs (get->header.size);
2020 xquery_size = ntohl (get->xquery_size); 2042 xquery_size = ntohl (get->xquery_size);
2021 if (msize < sizeof (struct PeerGetMessage) + xquery_size) 2043 if (msize < sizeof (struct PeerGetMessage) + xquery_size)
@@ -2203,6 +2225,7 @@ check_dht_p2p_result (void *cls,
2203 uint32_t put_path_length; 2225 uint32_t put_path_length;
2204 uint16_t msize; 2226 uint16_t msize;
2205 2227
2228 (void) cls;
2206 msize = ntohs (prm->header.size); 2229 msize = ntohs (prm->header.size);
2207 put_path_length = ntohl (prm->put_path_length); 2230 put_path_length = ntohl (prm->put_path_length);
2208 get_path_length = ntohl (prm->get_path_length); 2231 get_path_length = ntohl (prm->get_path_length);
@@ -2316,8 +2339,18 @@ handle_dht_p2p_result (void *cls,
2316 uint16_t msize; 2339 uint16_t msize;
2317 size_t data_size; 2340 size_t data_size;
2318 enum GNUNET_BLOCK_Type type; 2341 enum GNUNET_BLOCK_Type type;
2342 struct GNUNET_TIME_Absolute exp_time;
2319 2343
2320 /* 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 }
2321 msize = ntohs (prm->header.size); 2354 msize = ntohs (prm->header.size);
2322 put_path_length = ntohl (prm->put_path_length); 2355 put_path_length = ntohl (prm->put_path_length);
2323 get_path_length = ntohl (prm->get_path_length); 2356 get_path_length = ntohl (prm->get_path_length);
@@ -2391,7 +2424,6 @@ handle_dht_p2p_result (void *cls,
2391 h); 2424 h);
2392 } 2425 }
2393 2426
2394
2395 /* First, check if 'peer' is already on the path, and if 2427 /* First, check if 'peer' is already on the path, and if
2396 so, truncate it instead of expanding. */ 2428 so, truncate it instead of expanding. */
2397 for (unsigned int i=0;i<=get_path_length;i++) 2429 for (unsigned int i=0;i<=get_path_length;i++)
@@ -2399,7 +2431,7 @@ handle_dht_p2p_result (void *cls,
2399 peer->id, 2431 peer->id,
2400 sizeof (struct GNUNET_PeerIdentity))) 2432 sizeof (struct GNUNET_PeerIdentity)))
2401 { 2433 {
2402 process_reply_with_path (GNUNET_TIME_absolute_ntoh (prm->expiration_time), 2434 process_reply_with_path (exp_time,
2403 &prm->key, 2435 &prm->key,
2404 i, 2436 i,
2405 get_path, 2437 get_path,
@@ -2420,7 +2452,7 @@ handle_dht_p2p_result (void *cls,
2420 get_path_length * sizeof (struct GNUNET_PeerIdentity)); 2452 get_path_length * sizeof (struct GNUNET_PeerIdentity));
2421 xget_path[get_path_length] = *peer->id; 2453 xget_path[get_path_length] = *peer->id;
2422 2454
2423 process_reply_with_path (GNUNET_TIME_absolute_ntoh (prm->expiration_time), 2455 process_reply_with_path (exp_time,
2424 &prm->key, 2456 &prm->key,
2425 get_path_length + 1, 2457 get_path_length + 1,
2426 xget_path, 2458 xget_path,