diff options
-rw-r--r-- | src/dht/gnunet-service-dht_clients.c | 4 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_neighbours.c | 6 | ||||
-rw-r--r-- | src/dht/plugin_block_dht.c | 57 | ||||
-rw-r--r-- | src/fs/plugin_block_fs.c | 3 |
4 files changed, 62 insertions, 8 deletions
diff --git a/src/dht/gnunet-service-dht_clients.c b/src/dht/gnunet-service-dht_clients.c index a42356e5f..c304f2e54 100644 --- a/src/dht/gnunet-service-dht_clients.c +++ b/src/dht/gnunet-service-dht_clients.c | |||
@@ -374,7 +374,9 @@ transmit_request (struct ClientQueryRecord *cqr) | |||
374 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 374 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
375 | UINT32_MAX), | 375 | UINT32_MAX), |
376 | NULL, | 376 | NULL, |
377 | 0); | 377 | 0, |
378 | "seen-set-size", | ||
379 | cqr->seen_replies_count); | ||
378 | GNUNET_BLOCK_group_set_seen (bg, | 380 | GNUNET_BLOCK_group_set_seen (bg, |
379 | cqr->seen_replies, | 381 | cqr->seen_replies, |
380 | cqr->seen_replies_count); | 382 | cqr->seen_replies_count); |
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c index 975872f1b..6eef05c20 100644 --- a/src/dht/gnunet-service-dht_neighbours.c +++ b/src/dht/gnunet-service-dht_neighbours.c | |||
@@ -661,7 +661,9 @@ send_find_peer_message (void *cls) | |||
661 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 661 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
662 | UINT32_MAX), | 662 | UINT32_MAX), |
663 | NULL, | 663 | NULL, |
664 | 0); | 664 | 0, |
665 | "filter-size", | ||
666 | DHT_BLOOM_SIZE); | ||
665 | GNUNET_CONTAINER_multipeermap_iterate (all_connected_peers, | 667 | GNUNET_CONTAINER_multipeermap_iterate (all_connected_peers, |
666 | &add_known_to_bloom, | 668 | &add_known_to_bloom, |
667 | bg); | 669 | bg); |
@@ -2087,6 +2089,8 @@ handle_dht_p2p_get (void *cls, | |||
2087 | type, | 2089 | type, |
2088 | get->bf_mutator, | 2090 | get->bf_mutator, |
2089 | &xquery[xquery_size], | 2091 | &xquery[xquery_size], |
2092 | reply_bf_size, | ||
2093 | "filter-size", | ||
2090 | reply_bf_size); | 2094 | reply_bf_size); |
2091 | /* remember request for routing replies */ | 2095 | /* remember request for routing replies */ |
2092 | GDS_ROUTING_add (peer->id, | 2096 | GDS_ROUTING_add (peer->id, |
diff --git a/src/dht/plugin_block_dht.c b/src/dht/plugin_block_dht.c index 168497440..869ec1554 100644 --- a/src/dht/plugin_block_dht.c +++ b/src/dht/plugin_block_dht.c | |||
@@ -34,9 +34,41 @@ | |||
34 | #define DEBUG_DHT GNUNET_EXTRA_LOGGING | 34 | #define DEBUG_DHT GNUNET_EXTRA_LOGGING |
35 | 35 | ||
36 | /** | 36 | /** |
37 | * How big is the BF we use for DHT blocks? | 37 | * Number of bits we set per entry in the bloomfilter. |
38 | * Do not change! | ||
38 | */ | 39 | */ |
39 | #define DHT_BF_SIZE 8 | 40 | #define BLOOMFILTER_K 16 |
41 | |||
42 | |||
43 | /** | ||
44 | * How many bytes should a bloomfilter be if we have already seen | ||
45 | * entry_count responses? Note that #GNUNET_CONSTANTS_BLOOMFILTER_K | ||
46 | * gives us the number of bits set per entry. Furthermore, we should | ||
47 | * not re-size the filter too often (to keep it cheap). | ||
48 | * | ||
49 | * Since other peers will also add entries but not resize the filter, | ||
50 | * we should generally pick a slightly larger size than what the | ||
51 | * strict math would suggest. | ||
52 | * | ||
53 | * @param entry_count expected number of entries in the Bloom filter | ||
54 | * @return must be a power of two and smaller or equal to 2^15. | ||
55 | */ | ||
56 | static size_t | ||
57 | compute_bloomfilter_size (unsigned int entry_count) | ||
58 | { | ||
59 | size_t size; | ||
60 | unsigned int ideal = (entry_count * BLOOMFILTER_K) / 4; | ||
61 | uint16_t max = 1 << 15; | ||
62 | |||
63 | if (entry_count > max) | ||
64 | return max; | ||
65 | size = 8; | ||
66 | while ((size < max) && (size < ideal)) | ||
67 | size *= 2; | ||
68 | if (size > max) | ||
69 | return max; | ||
70 | return size; | ||
71 | } | ||
40 | 72 | ||
41 | 73 | ||
42 | /** | 74 | /** |
@@ -59,9 +91,26 @@ block_plugin_dht_create_group (void *cls, | |||
59 | size_t raw_data_size, | 91 | size_t raw_data_size, |
60 | va_list va) | 92 | va_list va) |
61 | { | 93 | { |
94 | unsigned int bf_size; | ||
95 | const char *guard; | ||
96 | |||
97 | guard = va_arg (va, const char *); | ||
98 | if (0 != memcmp (guard, | ||
99 | "seen-set-size", | ||
100 | strlen ("seen-set-size"))) | ||
101 | bf_size = compute_bloomfilter_size (va_arg (va, unsigned int)); | ||
102 | else if (0 == memcmp (va_arg (va, const char *), | ||
103 | "filter-size", | ||
104 | strlen ("filter-size"))) | ||
105 | bf_size = va_arg (va, unsigned int); | ||
106 | else | ||
107 | { | ||
108 | GNUNET_break (0); | ||
109 | bf_size = 8; | ||
110 | } | ||
62 | return GNUNET_BLOCK_GROUP_bf_create (cls, | 111 | return GNUNET_BLOCK_GROUP_bf_create (cls, |
63 | DHT_BF_SIZE, | 112 | bf_size, |
64 | GNUNET_CONSTANTS_BLOOMFILTER_K, | 113 | BLOOMFILTER_K, |
65 | type, | 114 | type, |
66 | nonce, | 115 | nonce, |
67 | raw_data, | 116 | raw_data, |
diff --git a/src/fs/plugin_block_fs.c b/src/fs/plugin_block_fs.c index 6c574fca2..5ccbd237e 100644 --- a/src/fs/plugin_block_fs.c +++ b/src/fs/plugin_block_fs.c | |||
@@ -28,7 +28,6 @@ | |||
28 | #include "gnunet_fs_service.h" | 28 | #include "gnunet_fs_service.h" |
29 | #include "block_fs.h" | 29 | #include "block_fs.h" |
30 | #include "gnunet_signatures.h" | 30 | #include "gnunet_signatures.h" |
31 | #include "gnunet_constants.h" | ||
32 | #include "gnunet_block_group_lib.h" | 31 | #include "gnunet_block_group_lib.h" |
33 | 32 | ||
34 | 33 | ||
@@ -56,7 +55,7 @@ static size_t | |||
56 | compute_bloomfilter_size (unsigned int entry_count) | 55 | compute_bloomfilter_size (unsigned int entry_count) |
57 | { | 56 | { |
58 | size_t size; | 57 | size_t size; |
59 | unsigned int ideal = (entry_count * GNUNET_CONSTANTS_BLOOMFILTER_K) / 4; | 58 | unsigned int ideal = (entry_count * BLOOMFILTER_K) / 4; |
60 | uint16_t max = 1 << 15; | 59 | uint16_t max = 1 << 15; |
61 | 60 | ||
62 | if (entry_count > max) | 61 | if (entry_count > max) |