diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/block/plugin_block_template.c | 49 | ||||
-rw-r--r-- | src/block/plugin_block_test.c | 51 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_clients.c | 3 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_neighbours.c | 6 | ||||
-rw-r--r-- | src/dht/plugin_block_dht.c | 1 | ||||
-rw-r--r-- | src/fs/gnunet-service-fs_pr.c | 10 | ||||
-rw-r--r-- | src/fs/plugin_block_fs.c | 8 | ||||
-rw-r--r-- | src/gns/plugin_block_gns.c | 51 | ||||
-rw-r--r-- | src/regex/plugin_block_regex.c | 62 |
9 files changed, 227 insertions, 14 deletions
diff --git a/src/block/plugin_block_template.c b/src/block/plugin_block_template.c index 0e8107af2..f11d5ee76 100644 --- a/src/block/plugin_block_template.c +++ b/src/block/plugin_block_template.c | |||
@@ -44,6 +44,37 @@ | |||
44 | 44 | ||
45 | 45 | ||
46 | /** | 46 | /** |
47 | * How many bytes should a bloomfilter be if we have already seen | ||
48 | * entry_count responses? Note that #GNUNET_CONSTANTS_BLOOMFILTER_K | ||
49 | * gives us the number of bits set per entry. Furthermore, we should | ||
50 | * not re-size the filter too often (to keep it cheap). | ||
51 | * | ||
52 | * Since other peers will also add entries but not resize the filter, | ||
53 | * we should generally pick a slightly larger size than what the | ||
54 | * strict math would suggest. | ||
55 | * | ||
56 | * @param entry_count expected number of entries in the Bloom filter | ||
57 | * @return must be a power of two and smaller or equal to 2^15. | ||
58 | */ | ||
59 | static size_t | ||
60 | compute_bloomfilter_size (unsigned int entry_count) | ||
61 | { | ||
62 | size_t size; | ||
63 | unsigned int ideal = (entry_count * BLOOMFILTER_K) / 4; | ||
64 | uint16_t max = 1 << 15; | ||
65 | |||
66 | if (entry_count > max) | ||
67 | return max; | ||
68 | size = 8; | ||
69 | while ((size < max) && (size < ideal)) | ||
70 | size *= 2; | ||
71 | if (size > max) | ||
72 | return max; | ||
73 | return size; | ||
74 | } | ||
75 | |||
76 | |||
77 | /** | ||
47 | * Create a new block group. | 78 | * Create a new block group. |
48 | * | 79 | * |
49 | * @param ctx block context in which the block group is created | 80 | * @param ctx block context in which the block group is created |
@@ -63,6 +94,24 @@ block_plugin_template_create_group (void *cls, | |||
63 | size_t raw_data_size, | 94 | size_t raw_data_size, |
64 | va_list va) | 95 | va_list va) |
65 | { | 96 | { |
97 | unsigned int bf_size; | ||
98 | const char *guard; | ||
99 | |||
100 | guard = va_arg (va, const char *); | ||
101 | if (0 == memcmp (guard, | ||
102 | "seen-set-size", | ||
103 | strlen ("seen-set-size"))) | ||
104 | bf_size = compute_bloomfilter_size (va_arg (va, unsigned int)); | ||
105 | else if (0 == memcmp (guard, | ||
106 | "filter-size", | ||
107 | strlen ("filter-size"))) | ||
108 | bf_size = va_arg (va, unsigned int); | ||
109 | else | ||
110 | { | ||
111 | GNUNET_break (0); | ||
112 | bf_size = TEMPLATE_BF_SIZE; | ||
113 | } | ||
114 | GNUNET_break (NULL == va_arg (va, const char *)); | ||
66 | return GNUNET_BLOCK_GROUP_bf_create (cls, | 115 | return GNUNET_BLOCK_GROUP_bf_create (cls, |
67 | TEMPLATE_BF_SIZE, | 116 | TEMPLATE_BF_SIZE, |
68 | BLOOMFILTER_K, | 117 | BLOOMFILTER_K, |
diff --git a/src/block/plugin_block_test.c b/src/block/plugin_block_test.c index 615f1571b..c5483f26e 100644 --- a/src/block/plugin_block_test.c +++ b/src/block/plugin_block_test.c | |||
@@ -42,6 +42,37 @@ | |||
42 | 42 | ||
43 | 43 | ||
44 | /** | 44 | /** |
45 | * How many bytes should a bloomfilter be if we have already seen | ||
46 | * entry_count responses? Note that #GNUNET_CONSTANTS_BLOOMFILTER_K | ||
47 | * gives us the number of bits set per entry. Furthermore, we should | ||
48 | * not re-size the filter too often (to keep it cheap). | ||
49 | * | ||
50 | * Since other peers will also add entries but not resize the filter, | ||
51 | * we should generally pick a slightly larger size than what the | ||
52 | * strict math would suggest. | ||
53 | * | ||
54 | * @param entry_count expected number of entries in the Bloom filter | ||
55 | * @return must be a power of two and smaller or equal to 2^15. | ||
56 | */ | ||
57 | static size_t | ||
58 | compute_bloomfilter_size (unsigned int entry_count) | ||
59 | { | ||
60 | size_t size; | ||
61 | unsigned int ideal = (entry_count * BLOOMFILTER_K) / 4; | ||
62 | uint16_t max = 1 << 15; | ||
63 | |||
64 | if (entry_count > max) | ||
65 | return max; | ||
66 | size = 8; | ||
67 | while ((size < max) && (size < ideal)) | ||
68 | size *= 2; | ||
69 | if (size > max) | ||
70 | return max; | ||
71 | return size; | ||
72 | } | ||
73 | |||
74 | |||
75 | /** | ||
45 | * Create a new block group. | 76 | * Create a new block group. |
46 | * | 77 | * |
47 | * @param ctx block context in which the block group is created | 78 | * @param ctx block context in which the block group is created |
@@ -61,8 +92,26 @@ block_plugin_test_create_group (void *cls, | |||
61 | size_t raw_data_size, | 92 | size_t raw_data_size, |
62 | va_list va) | 93 | va_list va) |
63 | { | 94 | { |
95 | unsigned int bf_size; | ||
96 | const char *guard; | ||
97 | |||
98 | guard = va_arg (va, const char *); | ||
99 | if (0 == memcmp (guard, | ||
100 | "seen-set-size", | ||
101 | strlen ("seen-set-size"))) | ||
102 | bf_size = compute_bloomfilter_size (va_arg (va, unsigned int)); | ||
103 | else if (0 == memcmp (guard, | ||
104 | "filter-size", | ||
105 | strlen ("filter-size"))) | ||
106 | bf_size = va_arg (va, unsigned int); | ||
107 | else | ||
108 | { | ||
109 | GNUNET_break (0); | ||
110 | bf_size = TEST_BF_SIZE; | ||
111 | } | ||
112 | GNUNET_break (NULL == va_arg (va, const char *)); | ||
64 | return GNUNET_BLOCK_GROUP_bf_create (cls, | 113 | return GNUNET_BLOCK_GROUP_bf_create (cls, |
65 | TEST_BF_SIZE, | 114 | bf_size, |
66 | BLOOMFILTER_K, | 115 | BLOOMFILTER_K, |
67 | type, | 116 | type, |
68 | nonce, | 117 | nonce, |
diff --git a/src/dht/gnunet-service-dht_clients.c b/src/dht/gnunet-service-dht_clients.c index c304f2e54..0f521a401 100644 --- a/src/dht/gnunet-service-dht_clients.c +++ b/src/dht/gnunet-service-dht_clients.c | |||
@@ -376,7 +376,8 @@ transmit_request (struct ClientQueryRecord *cqr) | |||
376 | NULL, | 376 | NULL, |
377 | 0, | 377 | 0, |
378 | "seen-set-size", | 378 | "seen-set-size", |
379 | cqr->seen_replies_count); | 379 | cqr->seen_replies_count, |
380 | NULL); | ||
380 | GNUNET_BLOCK_group_set_seen (bg, | 381 | GNUNET_BLOCK_group_set_seen (bg, |
381 | cqr->seen_replies, | 382 | cqr->seen_replies, |
382 | cqr->seen_replies_count); | 383 | cqr->seen_replies_count); |
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c index 6eef05c20..9e1cecfcd 100644 --- a/src/dht/gnunet-service-dht_neighbours.c +++ b/src/dht/gnunet-service-dht_neighbours.c | |||
@@ -663,7 +663,8 @@ send_find_peer_message (void *cls) | |||
663 | NULL, | 663 | NULL, |
664 | 0, | 664 | 0, |
665 | "filter-size", | 665 | "filter-size", |
666 | DHT_BLOOM_SIZE); | 666 | DHT_BLOOM_SIZE, |
667 | NULL); | ||
667 | GNUNET_CONTAINER_multipeermap_iterate (all_connected_peers, | 668 | GNUNET_CONTAINER_multipeermap_iterate (all_connected_peers, |
668 | &add_known_to_bloom, | 669 | &add_known_to_bloom, |
669 | bg); | 670 | bg); |
@@ -2091,7 +2092,8 @@ handle_dht_p2p_get (void *cls, | |||
2091 | &xquery[xquery_size], | 2092 | &xquery[xquery_size], |
2092 | reply_bf_size, | 2093 | reply_bf_size, |
2093 | "filter-size", | 2094 | "filter-size", |
2094 | reply_bf_size); | 2095 | reply_bf_size, |
2096 | NULL); | ||
2095 | /* remember request for routing replies */ | 2097 | /* remember request for routing replies */ |
2096 | GDS_ROUTING_add (peer->id, | 2098 | GDS_ROUTING_add (peer->id, |
2097 | type, | 2099 | type, |
diff --git a/src/dht/plugin_block_dht.c b/src/dht/plugin_block_dht.c index 26975e125..72480536c 100644 --- a/src/dht/plugin_block_dht.c +++ b/src/dht/plugin_block_dht.c | |||
@@ -108,6 +108,7 @@ block_plugin_dht_create_group (void *cls, | |||
108 | GNUNET_break (0); | 108 | GNUNET_break (0); |
109 | bf_size = 8; | 109 | bf_size = 8; |
110 | } | 110 | } |
111 | GNUNET_break (NULL == va_arg (va, const char *)); | ||
111 | return GNUNET_BLOCK_GROUP_bf_create (cls, | 112 | return GNUNET_BLOCK_GROUP_bf_create (cls, |
112 | bf_size, | 113 | bf_size, |
113 | BLOOMFILTER_K, | 114 | BLOOMFILTER_K, |
diff --git a/src/fs/gnunet-service-fs_pr.c b/src/fs/gnunet-service-fs_pr.c index 87e2d2ee1..b0fda24b5 100644 --- a/src/fs/gnunet-service-fs_pr.c +++ b/src/fs/gnunet-service-fs_pr.c | |||
@@ -264,8 +264,9 @@ refresh_bloomfilter (enum GNUNET_BLOCK_Type type, | |||
264 | UINT32_MAX), | 264 | UINT32_MAX), |
265 | NULL, | 265 | NULL, |
266 | 0, | 266 | 0, |
267 | "fs-seen-set-size", | 267 | "seen-set-size", |
268 | pr->replies_seen_count); | 268 | pr->replies_seen_count, |
269 | NULL); | ||
269 | if (NULL == pr->bg) | 270 | if (NULL == pr->bg) |
270 | return; | 271 | return; |
271 | GNUNET_break (GNUNET_OK == | 272 | GNUNET_break (GNUNET_OK == |
@@ -383,8 +384,9 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options, | |||
383 | mingle, | 384 | mingle, |
384 | bf_data, | 385 | bf_data, |
385 | bf_size, | 386 | bf_size, |
386 | "fs-seen-set-size", | 387 | "seen-set-size", |
387 | 0); | 388 | 0, |
389 | NULL); | ||
388 | } | 390 | } |
389 | else if ((replies_seen_count > 0) && | 391 | else if ((replies_seen_count > 0) && |
390 | (0 != (options & GSF_PRO_BLOOMFILTER_FULL_REFRESH))) | 392 | (0 != (options & GSF_PRO_BLOOMFILTER_FULL_REFRESH))) |
diff --git a/src/fs/plugin_block_fs.c b/src/fs/plugin_block_fs.c index 5ccbd237e..bea6b148c 100644 --- a/src/fs/plugin_block_fs.c +++ b/src/fs/plugin_block_fs.c | |||
@@ -95,14 +95,16 @@ block_plugin_fs_create_group (void *cls, | |||
95 | switch (type) | 95 | switch (type) |
96 | { | 96 | { |
97 | case GNUNET_BLOCK_TYPE_FS_DBLOCK: | 97 | case GNUNET_BLOCK_TYPE_FS_DBLOCK: |
98 | GNUNET_break (NULL == va_arg (va, const char *)); | ||
98 | return NULL; | 99 | return NULL; |
99 | case GNUNET_BLOCK_TYPE_FS_IBLOCK: | 100 | case GNUNET_BLOCK_TYPE_FS_IBLOCK: |
101 | GNUNET_break (NULL == va_arg (va, const char *)); | ||
100 | return NULL; | 102 | return NULL; |
101 | case GNUNET_BLOCK_TYPE_FS_UBLOCK: | 103 | case GNUNET_BLOCK_TYPE_FS_UBLOCK: |
102 | guard = va_arg (va, const char *); | 104 | guard = va_arg (va, const char *); |
103 | if (0 != memcmp (guard, | 105 | if (0 != memcmp (guard, |
104 | "fs-seen-set-size", | 106 | "seen-set-size", |
105 | strlen ("fs-seen-set-size"))) | 107 | strlen ("seen-set-size"))) |
106 | { | 108 | { |
107 | /* va-args invalid! bad bug, complain! */ | 109 | /* va-args invalid! bad bug, complain! */ |
108 | GNUNET_break (0); | 110 | GNUNET_break (0); |
@@ -114,6 +116,7 @@ block_plugin_fs_create_group (void *cls, | |||
114 | } | 116 | } |
115 | if (0 == size) | 117 | if (0 == size) |
116 | size = raw_data_size; /* not for us to determine, use what we got! */ | 118 | size = raw_data_size; /* not for us to determine, use what we got! */ |
119 | GNUNET_break (NULL == va_arg (va, const char *)); | ||
117 | return GNUNET_BLOCK_GROUP_bf_create (cls, | 120 | return GNUNET_BLOCK_GROUP_bf_create (cls, |
118 | size, | 121 | size, |
119 | BLOOMFILTER_K, | 122 | BLOOMFILTER_K, |
@@ -122,6 +125,7 @@ block_plugin_fs_create_group (void *cls, | |||
122 | raw_data, | 125 | raw_data, |
123 | raw_data_size); | 126 | raw_data_size); |
124 | default: | 127 | default: |
128 | GNUNET_break (NULL == va_arg (va, const char *)); | ||
125 | GNUNET_break (0); | 129 | GNUNET_break (0); |
126 | return NULL; | 130 | return NULL; |
127 | } | 131 | } |
diff --git a/src/gns/plugin_block_gns.c b/src/gns/plugin_block_gns.c index 94222e32b..300dbc020 100644 --- a/src/gns/plugin_block_gns.c +++ b/src/gns/plugin_block_gns.c | |||
@@ -44,6 +44,37 @@ | |||
44 | 44 | ||
45 | 45 | ||
46 | /** | 46 | /** |
47 | * How many bytes should a bloomfilter be if we have already seen | ||
48 | * entry_count responses? Note that #GNUNET_CONSTANTS_BLOOMFILTER_K | ||
49 | * gives us the number of bits set per entry. Furthermore, we should | ||
50 | * not re-size the filter too often (to keep it cheap). | ||
51 | * | ||
52 | * Since other peers will also add entries but not resize the filter, | ||
53 | * we should generally pick a slightly larger size than what the | ||
54 | * strict math would suggest. | ||
55 | * | ||
56 | * @param entry_count expected number of entries in the Bloom filter | ||
57 | * @return must be a power of two and smaller or equal to 2^15. | ||
58 | */ | ||
59 | static size_t | ||
60 | compute_bloomfilter_size (unsigned int entry_count) | ||
61 | { | ||
62 | size_t size; | ||
63 | unsigned int ideal = (entry_count * BLOOMFILTER_K) / 4; | ||
64 | uint16_t max = 1 << 15; | ||
65 | |||
66 | if (entry_count > max) | ||
67 | return max; | ||
68 | size = 8; | ||
69 | while ((size < max) && (size < ideal)) | ||
70 | size *= 2; | ||
71 | if (size > max) | ||
72 | return max; | ||
73 | return size; | ||
74 | } | ||
75 | |||
76 | |||
77 | /** | ||
47 | * Create a new block group. | 78 | * Create a new block group. |
48 | * | 79 | * |
49 | * @param ctx block context in which the block group is created | 80 | * @param ctx block context in which the block group is created |
@@ -63,8 +94,26 @@ block_plugin_gns_create_group (void *cls, | |||
63 | size_t raw_data_size, | 94 | size_t raw_data_size, |
64 | va_list va) | 95 | va_list va) |
65 | { | 96 | { |
97 | unsigned int bf_size; | ||
98 | const char *guard; | ||
99 | |||
100 | guard = va_arg (va, const char *); | ||
101 | if (0 == memcmp (guard, | ||
102 | "seen-set-size", | ||
103 | strlen ("seen-set-size"))) | ||
104 | bf_size = compute_bloomfilter_size (va_arg (va, unsigned int)); | ||
105 | else if (0 == memcmp (guard, | ||
106 | "filter-size", | ||
107 | strlen ("filter-size"))) | ||
108 | bf_size = va_arg (va, unsigned int); | ||
109 | else | ||
110 | { | ||
111 | GNUNET_break (0); | ||
112 | bf_size = GNS_BF_SIZE; | ||
113 | } | ||
114 | GNUNET_break (NULL == va_arg (va, const char *)); | ||
66 | return GNUNET_BLOCK_GROUP_bf_create (cls, | 115 | return GNUNET_BLOCK_GROUP_bf_create (cls, |
67 | GNS_BF_SIZE, | 116 | bf_size, |
68 | BLOOMFILTER_K, | 117 | BLOOMFILTER_K, |
69 | type, | 118 | type, |
70 | nonce, | 119 | nonce, |
diff --git a/src/regex/plugin_block_regex.c b/src/regex/plugin_block_regex.c index 6636f3cdb..b9814c737 100644 --- a/src/regex/plugin_block_regex.c +++ b/src/regex/plugin_block_regex.c | |||
@@ -28,10 +28,17 @@ | |||
28 | #include "gnunet_block_group_lib.h" | 28 | #include "gnunet_block_group_lib.h" |
29 | #include "block_regex.h" | 29 | #include "block_regex.h" |
30 | #include "regex_block_lib.h" | 30 | #include "regex_block_lib.h" |
31 | #include "gnunet_constants.h" | ||
32 | #include "gnunet_signatures.h" | 31 | #include "gnunet_signatures.h" |
33 | 32 | ||
34 | 33 | ||
34 | |||
35 | /** | ||
36 | * Number of bits we set per entry in the bloomfilter. | ||
37 | * Do not change! | ||
38 | */ | ||
39 | #define BLOOMFILTER_K 16 | ||
40 | |||
41 | |||
35 | /** | 42 | /** |
36 | * How big is the BF we use for REGEX blocks? | 43 | * How big is the BF we use for REGEX blocks? |
37 | */ | 44 | */ |
@@ -39,6 +46,37 @@ | |||
39 | 46 | ||
40 | 47 | ||
41 | /** | 48 | /** |
49 | * How many bytes should a bloomfilter be if we have already seen | ||
50 | * entry_count responses? Note that #GNUNET_CONSTANTS_BLOOMFILTER_K | ||
51 | * gives us the number of bits set per entry. Furthermore, we should | ||
52 | * not re-size the filter too often (to keep it cheap). | ||
53 | * | ||
54 | * Since other peers will also add entries but not resize the filter, | ||
55 | * we should generally pick a slightly larger size than what the | ||
56 | * strict math would suggest. | ||
57 | * | ||
58 | * @param entry_count expected number of entries in the Bloom filter | ||
59 | * @return must be a power of two and smaller or equal to 2^15. | ||
60 | */ | ||
61 | static size_t | ||
62 | compute_bloomfilter_size (unsigned int entry_count) | ||
63 | { | ||
64 | size_t size; | ||
65 | unsigned int ideal = (entry_count * BLOOMFILTER_K) / 4; | ||
66 | uint16_t max = 1 << 15; | ||
67 | |||
68 | if (entry_count > max) | ||
69 | return max; | ||
70 | size = 8; | ||
71 | while ((size < max) && (size < ideal)) | ||
72 | size *= 2; | ||
73 | if (size > max) | ||
74 | return max; | ||
75 | return size; | ||
76 | } | ||
77 | |||
78 | |||
79 | /** | ||
42 | * Create a new block group. | 80 | * Create a new block group. |
43 | * | 81 | * |
44 | * @param ctx block context in which the block group is created | 82 | * @param ctx block context in which the block group is created |
@@ -58,9 +96,27 @@ block_plugin_regex_create_group (void *cls, | |||
58 | size_t raw_data_size, | 96 | size_t raw_data_size, |
59 | va_list va) | 97 | va_list va) |
60 | { | 98 | { |
99 | unsigned int bf_size; | ||
100 | const char *guard; | ||
101 | |||
102 | guard = va_arg (va, const char *); | ||
103 | if (0 == memcmp (guard, | ||
104 | "seen-set-size", | ||
105 | strlen ("seen-set-size"))) | ||
106 | bf_size = compute_bloomfilter_size (va_arg (va, unsigned int)); | ||
107 | else if (0 == memcmp (guard, | ||
108 | "filter-size", | ||
109 | strlen ("filter-size"))) | ||
110 | bf_size = va_arg (va, unsigned int); | ||
111 | else | ||
112 | { | ||
113 | GNUNET_break (0); | ||
114 | bf_size = REGEX_BF_SIZE; | ||
115 | } | ||
116 | GNUNET_break (NULL == va_arg (va, const char *)); | ||
61 | return GNUNET_BLOCK_GROUP_bf_create (cls, | 117 | return GNUNET_BLOCK_GROUP_bf_create (cls, |
62 | REGEX_BF_SIZE, | 118 | bf_size, |
63 | GNUNET_CONSTANTS_BLOOMFILTER_K, | 119 | BLOOMFILTER_K, |
64 | type, | 120 | type, |
65 | nonce, | 121 | nonce, |
66 | raw_data, | 122 | raw_data, |