diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/block/Makefile.am | 15 | ||||
-rw-r--r-- | src/block/bg_bf.c | 173 | ||||
-rw-r--r-- | src/block/block.c | 72 | ||||
-rw-r--r-- | src/dht/Makefile.am | 1 | ||||
-rw-r--r-- | src/dht/plugin_block_dht.c | 36 | ||||
-rw-r--r-- | src/dns/plugin_block_dns.c | 6 | ||||
-rw-r--r-- | src/fs/Makefile.am | 1 | ||||
-rw-r--r-- | src/fs/plugin_block_fs.c | 48 | ||||
-rw-r--r-- | src/gns/Makefile.am | 1 | ||||
-rw-r--r-- | src/gns/plugin_block_gns.c | 45 | ||||
-rw-r--r-- | src/include/gnunet_block_group_lib.h | 82 | ||||
-rw-r--r-- | src/include/gnunet_block_lib.h | 51 | ||||
-rw-r--r-- | src/include/gnunet_block_plugin.h | 87 | ||||
-rw-r--r-- | src/regex/Makefile.am | 1 | ||||
-rw-r--r-- | src/regex/plugin_block_regex.c | 37 |
15 files changed, 645 insertions, 11 deletions
diff --git a/src/block/Makefile.am b/src/block/Makefile.am index c54a4c246..4a6d8e71e 100644 --- a/src/block/Makefile.am +++ b/src/block/Makefile.am | |||
@@ -11,7 +11,9 @@ if USE_COVERAGE | |||
11 | AM_CFLAGS = --coverage | 11 | AM_CFLAGS = --coverage |
12 | endif | 12 | endif |
13 | 13 | ||
14 | lib_LTLIBRARIES = libgnunetblock.la | 14 | lib_LTLIBRARIES = \ |
15 | libgnunetblock.la \ | ||
16 | libgnunetblockgroup.la | ||
15 | 17 | ||
16 | plugin_LTLIBRARIES = \ | 18 | plugin_LTLIBRARIES = \ |
17 | libgnunet_plugin_block_test.la | 19 | libgnunet_plugin_block_test.la |
@@ -49,3 +51,14 @@ libgnunetblock_la_DEPENDENCIES = \ | |||
49 | libgnunetblock_la_LDFLAGS = \ | 51 | libgnunetblock_la_LDFLAGS = \ |
50 | $(GN_LIB_LDFLAGS) \ | 52 | $(GN_LIB_LDFLAGS) \ |
51 | -version-info 0:0:0 | 53 | -version-info 0:0:0 |
54 | |||
55 | |||
56 | libgnunetblockgroup_la_SOURCES = \ | ||
57 | bg_bf.c | ||
58 | libgnunetblockgroup_la_LIBADD = \ | ||
59 | $(top_builddir)/src/util/libgnunetutil.la | ||
60 | libgnunetblockgroup_la_DEPENDENCIES = \ | ||
61 | $(top_builddir)/src/util/libgnunetutil.la | ||
62 | libgnunetblockgroup_la_LDFLAGS = \ | ||
63 | $(GN_LIB_LDFLAGS) \ | ||
64 | -version-info 0:0:0 | ||
diff --git a/src/block/bg_bf.c b/src/block/bg_bf.c new file mode 100644 index 000000000..f03ae5247 --- /dev/null +++ b/src/block/bg_bf.c | |||
@@ -0,0 +1,173 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2017 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file block/bg_bf.c | ||
22 | * @brief implementation of a block group using a Bloom filter | ||
23 | * to drop duplicate blocks | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_util_lib.h" | ||
28 | #include "gnunet_block_group_lib.h" | ||
29 | #include "gnunet_block_plugin.h" | ||
30 | |||
31 | |||
32 | /** | ||
33 | * Internal data structure for a block group. | ||
34 | */ | ||
35 | struct BfGroupInternals | ||
36 | { | ||
37 | /** | ||
38 | * A Bloom filter to weed out duplicate replies probabilistically. | ||
39 | */ | ||
40 | struct GNUNET_CONTAINER_BloomFilter *bf; | ||
41 | |||
42 | /** | ||
43 | * Set from the nonce to mingle the hashes before going into the @e bf. | ||
44 | */ | ||
45 | uint32_t bf_mutator; | ||
46 | |||
47 | /** | ||
48 | * Size of @a bf. | ||
49 | */ | ||
50 | uint32_t bf_size; | ||
51 | |||
52 | }; | ||
53 | |||
54 | |||
55 | /** | ||
56 | * Serialize state of a block group. | ||
57 | * | ||
58 | * @param bg group to serialize | ||
59 | * @param[out] raw_data set to the serialized state | ||
60 | * @param[out] raw_data_size set to the number of bytes in @a raw_data | ||
61 | * @return #GNUNET_OK on success, #GNUNET_NO if serialization is not | ||
62 | * supported, #GNUNET_SYSERR on error | ||
63 | */ | ||
64 | static int | ||
65 | bf_group_serialize_cb (struct GNUNET_BLOCK_Group *bg, | ||
66 | void **raw_data, | ||
67 | size_t *raw_data_size) | ||
68 | { | ||
69 | struct BfGroupInternals *gi = bg->internal_cls; | ||
70 | char *raw; | ||
71 | |||
72 | raw = GNUNET_malloc (gi->bf_size); | ||
73 | if (GNUNET_OK != | ||
74 | GNUNET_CONTAINER_bloomfilter_get_raw_data (gi->bf, | ||
75 | raw, | ||
76 | gi->bf_size)) | ||
77 | { | ||
78 | GNUNET_break (0); | ||
79 | return GNUNET_SYSERR; | ||
80 | } | ||
81 | *raw_data = raw; | ||
82 | *raw_data_size = gi->bf_size; | ||
83 | return GNUNET_OK; | ||
84 | } | ||
85 | |||
86 | |||
87 | /** | ||
88 | * Destroy resources used by a block group. | ||
89 | * | ||
90 | * @param bg group to destroy, NULL is allowed | ||
91 | */ | ||
92 | static void | ||
93 | bf_group_destroy_cb (struct GNUNET_BLOCK_Group *bg) | ||
94 | { | ||
95 | struct BfGroupInternals *gi = bg->internal_cls; | ||
96 | |||
97 | GNUNET_CONTAINER_bloomfilter_free (gi->bf); | ||
98 | GNUNET_free (gi); | ||
99 | GNUNET_free (bg); | ||
100 | } | ||
101 | |||
102 | |||
103 | /** | ||
104 | * Create a new block group that filters duplicates using a Bloom filter. | ||
105 | * | ||
106 | * @param ctx block context in which the block group is created | ||
107 | * @param bf_size size of the Bloom filter | ||
108 | * @param bf_k K-value for the Bloom filter | ||
109 | * @param type block type | ||
110 | * @param nonce random value used to seed the group creation | ||
111 | * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh | ||
112 | * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh | ||
113 | * @return block group handle, NULL if block groups are not supported | ||
114 | * by this @a type of block (this is not an error) | ||
115 | */ | ||
116 | struct GNUNET_BLOCK_Group * | ||
117 | GNUNET_BLOCK_GROUP_bf_create (void *cls, | ||
118 | size_t bf_size, | ||
119 | unsigned int bf_k, | ||
120 | enum GNUNET_BLOCK_Type type, | ||
121 | uint32_t nonce, | ||
122 | const void *raw_data, | ||
123 | size_t raw_data_size) | ||
124 | { | ||
125 | struct BfGroupInternals *gi; | ||
126 | struct GNUNET_BLOCK_Group *bg; | ||
127 | |||
128 | gi = GNUNET_new (struct BfGroupInternals); | ||
129 | gi->bf = GNUNET_CONTAINER_bloomfilter_init ((bf_size != raw_data_size) ? NULL : raw_data, | ||
130 | bf_size, | ||
131 | bf_k); | ||
132 | gi->bf_mutator = nonce; | ||
133 | gi->bf_size = bf_size; | ||
134 | bg = GNUNET_new (struct GNUNET_BLOCK_Group); | ||
135 | bg->type = type; | ||
136 | bg->serialize_cb = &bf_group_serialize_cb; | ||
137 | bg->destroy_cb = &bf_group_destroy_cb; | ||
138 | bg->internal_cls = gi; | ||
139 | return bg; | ||
140 | } | ||
141 | |||
142 | |||
143 | /** | ||
144 | * Test if @a hc is contained in the Bloom filter of @a bg. If so, | ||
145 | * return #GNUNET_YES. If not, add @a hc to the Bloom filter and | ||
146 | * return #GNUNET_NO. | ||
147 | * | ||
148 | * @param bg block group to use for testing | ||
149 | * @param hc hash of element to evaluate | ||
150 | * @return #GNUNET_YES if @a hc is (likely) a duplicate | ||
151 | * #GNUNET_NO if @a hc was definitively not in @bg (but now is) | ||
152 | */ | ||
153 | int | ||
154 | GNUNET_BLOCK_GROUP_bf_test_and_set (struct GNUNET_BLOCK_Group *bg, | ||
155 | const struct GNUNET_HashCode *hc) | ||
156 | { | ||
157 | struct BfGroupInternals *gi = bg->internal_cls; | ||
158 | struct GNUNET_HashCode mhash; | ||
159 | |||
160 | GNUNET_BLOCK_mingle_hash (hc, | ||
161 | gi->bf_mutator, | ||
162 | &mhash); | ||
163 | if (GNUNET_YES == | ||
164 | GNUNET_CONTAINER_bloomfilter_test (gi->bf, | ||
165 | &mhash)) | ||
166 | return GNUNET_YES; | ||
167 | GNUNET_CONTAINER_bloomfilter_add (gi->bf, | ||
168 | &mhash); | ||
169 | return GNUNET_NO; | ||
170 | } | ||
171 | |||
172 | |||
173 | /* end of bg_bf.c */ | ||
diff --git a/src/block/block.c b/src/block/block.c index c104f4bd1..d4f5462dd 100644 --- a/src/block/block.c +++ b/src/block/block.c | |||
@@ -159,6 +159,46 @@ GNUNET_BLOCK_context_destroy (struct GNUNET_BLOCK_Context *ctx) | |||
159 | 159 | ||
160 | 160 | ||
161 | /** | 161 | /** |
162 | * Serialize state of a block group. | ||
163 | * | ||
164 | * @param bg group to serialize | ||
165 | * @param[out] raw_data set to the serialized state | ||
166 | * @param[out] raw_data_size set to the number of bytes in @a raw_data | ||
167 | * @return #GNUNET_OK on success, #GNUNET_NO if serialization is not | ||
168 | * supported, #GNUNET_SYSERR on error | ||
169 | */ | ||
170 | int | ||
171 | GNUNET_BLOCK_group_serialize (struct GNUNET_BLOCK_Group *bg, | ||
172 | void **raw_data, | ||
173 | size_t *raw_data_size) | ||
174 | { | ||
175 | *raw_data = NULL; | ||
176 | *raw_data_size = 0; | ||
177 | if (NULL == bg) | ||
178 | return GNUNET_NO; | ||
179 | if (NULL == bg->serialize_cb) | ||
180 | return GNUNET_NO; | ||
181 | return bg->serialize_cb (bg, | ||
182 | raw_data, | ||
183 | raw_data_size); | ||
184 | } | ||
185 | |||
186 | |||
187 | /** | ||
188 | * Destroy resources used by a block group. | ||
189 | * | ||
190 | * @param bg group to destroy, NULL is allowed | ||
191 | */ | ||
192 | void | ||
193 | GNUNET_BLOCK_group_destroy (struct GNUNET_BLOCK_Group *bg) | ||
194 | { | ||
195 | if (NULL == bg) | ||
196 | return; | ||
197 | bg->destroy_cb (bg); | ||
198 | } | ||
199 | |||
200 | |||
201 | /** | ||
162 | * Find a plugin for the given type. | 202 | * Find a plugin for the given type. |
163 | * | 203 | * |
164 | * @param ctx context to search | 204 | * @param ctx context to search |
@@ -189,6 +229,38 @@ find_plugin (struct GNUNET_BLOCK_Context *ctx, | |||
189 | 229 | ||
190 | 230 | ||
191 | /** | 231 | /** |
232 | * Create a new block group. | ||
233 | * | ||
234 | * @param ctx block context in which the block group is created | ||
235 | * @param type type of the block for which we are creating the group | ||
236 | * @param nonce random value used to seed the group creation | ||
237 | * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh | ||
238 | * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh | ||
239 | * @return block group handle, NULL if block groups are not supported | ||
240 | * by this @a type of block (this is not an error) | ||
241 | */ | ||
242 | struct GNUNET_BLOCK_Group * | ||
243 | GNUNET_BLOCK_group_create (struct GNUNET_BLOCK_Context *ctx, | ||
244 | enum GNUNET_BLOCK_Type type, | ||
245 | uint32_t nonce, | ||
246 | const void *raw_data, | ||
247 | size_t raw_data_size) | ||
248 | { | ||
249 | struct GNUNET_BLOCK_PluginFunctions *plugin; | ||
250 | |||
251 | plugin = find_plugin (ctx, | ||
252 | type); | ||
253 | if (NULL == plugin->create_group) | ||
254 | return NULL; | ||
255 | return plugin->create_group (plugin->cls, | ||
256 | type, | ||
257 | nonce, | ||
258 | raw_data, | ||
259 | raw_data_size); | ||
260 | } | ||
261 | |||
262 | |||
263 | /** | ||
192 | * Function called to validate a reply or a request. For | 264 | * Function called to validate a reply or a request. For |
193 | * request evaluation, simply pass "NULL" for the reply_block. | 265 | * request evaluation, simply pass "NULL" for the reply_block. |
194 | * Note that it is assumed that the reply has already been | 266 | * Note that it is assumed that the reply has already been |
diff --git a/src/dht/Makefile.am b/src/dht/Makefile.am index 26beb300b..93dae9f6e 100644 --- a/src/dht/Makefile.am +++ b/src/dht/Makefile.am | |||
@@ -40,6 +40,7 @@ libgnunet_plugin_block_dht_la_SOURCES = \ | |||
40 | libgnunet_plugin_block_dht_la_LIBADD = \ | 40 | libgnunet_plugin_block_dht_la_LIBADD = \ |
41 | $(top_builddir)/src/hello/libgnunethello.la \ | 41 | $(top_builddir)/src/hello/libgnunethello.la \ |
42 | $(top_builddir)/src/block/libgnunetblock.la \ | 42 | $(top_builddir)/src/block/libgnunetblock.la \ |
43 | $(top_builddir)/src/block/libgnunetblockgroup.la \ | ||
43 | $(top_builddir)/src/util/libgnunetutil.la \ | 44 | $(top_builddir)/src/util/libgnunetutil.la \ |
44 | $(LTLIBINTL) | 45 | $(LTLIBINTL) |
45 | libgnunet_plugin_block_dht_la_LDFLAGS = \ | 46 | libgnunet_plugin_block_dht_la_LDFLAGS = \ |
diff --git a/src/dht/plugin_block_dht.c b/src/dht/plugin_block_dht.c index 4256a0fe6..4c5f122a4 100644 --- a/src/dht/plugin_block_dht.c +++ b/src/dht/plugin_block_dht.c | |||
@@ -25,14 +25,47 @@ | |||
25 | * DHT (see fs block plugin) | 25 | * DHT (see fs block plugin) |
26 | * @author Christian Grothoff | 26 | * @author Christian Grothoff |
27 | */ | 27 | */ |
28 | |||
29 | #include "platform.h" | 28 | #include "platform.h" |
30 | #include "gnunet_constants.h" | 29 | #include "gnunet_constants.h" |
31 | #include "gnunet_hello_lib.h" | 30 | #include "gnunet_hello_lib.h" |
32 | #include "gnunet_block_plugin.h" | 31 | #include "gnunet_block_plugin.h" |
32 | #include "gnunet_block_group_lib.h" | ||
33 | 33 | ||
34 | #define DEBUG_DHT GNUNET_EXTRA_LOGGING | 34 | #define DEBUG_DHT GNUNET_EXTRA_LOGGING |
35 | 35 | ||
36 | /** | ||
37 | * How big is the BF we use for DHT blocks? | ||
38 | */ | ||
39 | #define DHT_BF_SIZE 8 | ||
40 | |||
41 | |||
42 | /** | ||
43 | * Create a new block group. | ||
44 | * | ||
45 | * @param ctx block context in which the block group is created | ||
46 | * @param type type of the block for which we are creating the group | ||
47 | * @param nonce random value used to seed the group creation | ||
48 | * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh | ||
49 | * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh | ||
50 | * @return block group handle, NULL if block groups are not supported | ||
51 | * by this @a type of block (this is not an error) | ||
52 | */ | ||
53 | static struct GNUNET_BLOCK_Group * | ||
54 | block_plugin_dht_create_group (void *cls, | ||
55 | enum GNUNET_BLOCK_Type type, | ||
56 | uint32_t nonce, | ||
57 | const void *raw_data, | ||
58 | size_t raw_data_size) | ||
59 | { | ||
60 | return GNUNET_BLOCK_GROUP_bf_create (cls, | ||
61 | DHT_BF_SIZE, | ||
62 | GNUNET_CONSTANTS_BLOOMFILTER_K, | ||
63 | type, | ||
64 | nonce, | ||
65 | raw_data, | ||
66 | raw_data_size); | ||
67 | } | ||
68 | |||
36 | 69 | ||
37 | /** | 70 | /** |
38 | * Function called to validate a reply or a request. For | 71 | * Function called to validate a reply or a request. For |
@@ -182,6 +215,7 @@ libgnunet_plugin_block_dht_init (void *cls) | |||
182 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | 215 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
183 | api->evaluate = &block_plugin_dht_evaluate; | 216 | api->evaluate = &block_plugin_dht_evaluate; |
184 | api->get_key = &block_plugin_dht_get_key; | 217 | api->get_key = &block_plugin_dht_get_key; |
218 | api->create_group = &block_plugin_dht_create_group; | ||
185 | api->types = types; | 219 | api->types = types; |
186 | return api; | 220 | return api; |
187 | } | 221 | } |
diff --git a/src/dns/plugin_block_dns.c b/src/dns/plugin_block_dns.c index 8c6ec93ee..e4bc9209c 100644 --- a/src/dns/plugin_block_dns.c +++ b/src/dns/plugin_block_dns.c | |||
@@ -96,9 +96,9 @@ block_plugin_dns_evaluate (void *cls, | |||
96 | } | 96 | } |
97 | if (GNUNET_OK != | 97 | if (GNUNET_OK != |
98 | GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_DNS_RECORD, | 98 | GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_DNS_RECORD, |
99 | &ad->purpose, | 99 | &ad->purpose, |
100 | &ad->signature, | 100 | &ad->signature, |
101 | &ad->peer.public_key)) | 101 | &ad->peer.public_key)) |
102 | { | 102 | { |
103 | GNUNET_break_op (0); | 103 | GNUNET_break_op (0); |
104 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 104 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am index 75451c7f6..4374d45ea 100644 --- a/src/fs/Makefile.am +++ b/src/fs/Makefile.am | |||
@@ -219,6 +219,7 @@ gnunet_unindex_LDADD = \ | |||
219 | libgnunet_plugin_block_fs_la_SOURCES = \ | 219 | libgnunet_plugin_block_fs_la_SOURCES = \ |
220 | plugin_block_fs.c | 220 | plugin_block_fs.c |
221 | libgnunet_plugin_block_fs_la_LIBADD = \ | 221 | libgnunet_plugin_block_fs_la_LIBADD = \ |
222 | $(top_builddir)/src/block/libgnunetblockgroup.la \ | ||
222 | $(top_builddir)/src/block/libgnunetblock.la \ | 223 | $(top_builddir)/src/block/libgnunetblock.la \ |
223 | libgnunetfs.la \ | 224 | libgnunetfs.la \ |
224 | $(top_builddir)/src/util/libgnunetutil.la \ | 225 | $(top_builddir)/src/util/libgnunetutil.la \ |
diff --git a/src/fs/plugin_block_fs.c b/src/fs/plugin_block_fs.c index 415a2e3ed..038734082 100644 --- a/src/fs/plugin_block_fs.c +++ b/src/fs/plugin_block_fs.c | |||
@@ -23,12 +23,12 @@ | |||
23 | * @brief blocks used for file-sharing | 23 | * @brief blocks used for file-sharing |
24 | * @author Christian Grothoff | 24 | * @author Christian Grothoff |
25 | */ | 25 | */ |
26 | |||
27 | #include "platform.h" | 26 | #include "platform.h" |
28 | #include "gnunet_block_plugin.h" | 27 | #include "gnunet_block_plugin.h" |
29 | #include "gnunet_fs_service.h" | 28 | #include "gnunet_fs_service.h" |
30 | #include "block_fs.h" | 29 | #include "block_fs.h" |
31 | #include "gnunet_signatures.h" | 30 | #include "gnunet_signatures.h" |
31 | #include "gnunet_block_group_lib.h" | ||
32 | 32 | ||
33 | 33 | ||
34 | /** | 34 | /** |
@@ -38,6 +38,51 @@ | |||
38 | #define BLOOMFILTER_K 16 | 38 | #define BLOOMFILTER_K 16 |
39 | 39 | ||
40 | /** | 40 | /** |
41 | * How big is the BF we use for FS blocks? | ||
42 | */ | ||
43 | #define FS_BF_SIZE 8 | ||
44 | |||
45 | |||
46 | /** | ||
47 | * Create a new block group. | ||
48 | * | ||
49 | * @param ctx block context in which the block group is created | ||
50 | * @param type type of the block for which we are creating the group | ||
51 | * @param nonce random value used to seed the group creation | ||
52 | * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh | ||
53 | * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh | ||
54 | * @return block group handle, NULL if block groups are not supported | ||
55 | * by this @a type of block (this is not an error) | ||
56 | */ | ||
57 | static struct GNUNET_BLOCK_Group * | ||
58 | block_plugin_fs_create_group (void *cls, | ||
59 | enum GNUNET_BLOCK_Type type, | ||
60 | uint32_t nonce, | ||
61 | const void *raw_data, | ||
62 | size_t raw_data_size) | ||
63 | { | ||
64 | switch (type) | ||
65 | { | ||
66 | case GNUNET_BLOCK_TYPE_FS_DBLOCK: | ||
67 | return NULL; | ||
68 | case GNUNET_BLOCK_TYPE_FS_IBLOCK: | ||
69 | return NULL; | ||
70 | case GNUNET_BLOCK_TYPE_FS_UBLOCK: | ||
71 | return GNUNET_BLOCK_GROUP_bf_create (cls, | ||
72 | FS_BF_SIZE, | ||
73 | BLOOMFILTER_K, | ||
74 | type, | ||
75 | nonce, | ||
76 | raw_data, | ||
77 | raw_data_size); | ||
78 | default: | ||
79 | GNUNET_break (0); | ||
80 | return NULL; | ||
81 | } | ||
82 | } | ||
83 | |||
84 | |||
85 | /** | ||
41 | * Function called to validate a reply or a request. For | 86 | * Function called to validate a reply or a request. For |
42 | * request evaluation, simply pass "NULL" for the reply_block. | 87 | * request evaluation, simply pass "NULL" for the reply_block. |
43 | * Note that it is assumed that the reply has already been | 88 | * Note that it is assumed that the reply has already been |
@@ -214,6 +259,7 @@ libgnunet_plugin_block_fs_init (void *cls) | |||
214 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | 259 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
215 | api->evaluate = &block_plugin_fs_evaluate; | 260 | api->evaluate = &block_plugin_fs_evaluate; |
216 | api->get_key = &block_plugin_fs_get_key; | 261 | api->get_key = &block_plugin_fs_get_key; |
262 | api->create_group = &block_plugin_fs_create_group; | ||
217 | api->types = types; | 263 | api->types = types; |
218 | return api; | 264 | return api; |
219 | } | 265 | } |
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am index 8f27890d7..d59908c0a 100644 --- a/src/gns/Makefile.am +++ b/src/gns/Makefile.am | |||
@@ -227,6 +227,7 @@ libgnunet_plugin_block_gns_la_SOURCES = \ | |||
227 | libgnunet_plugin_block_gns_la_LIBADD = \ | 227 | libgnunet_plugin_block_gns_la_LIBADD = \ |
228 | $(top_builddir)/src/util/libgnunetutil.la \ | 228 | $(top_builddir)/src/util/libgnunetutil.la \ |
229 | $(top_builddir)/src/block/libgnunetblock.la \ | 229 | $(top_builddir)/src/block/libgnunetblock.la \ |
230 | $(top_builddir)/src/block/libgnunetblockgroup.la \ | ||
230 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la | 231 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la |
231 | libgnunet_plugin_block_gns_la_LDFLAGS = \ | 232 | libgnunet_plugin_block_gns_la_LDFLAGS = \ |
232 | $(GN_PLUGIN_LDFLAGS) | 233 | $(GN_PLUGIN_LDFLAGS) |
diff --git a/src/gns/plugin_block_gns.c b/src/gns/plugin_block_gns.c index f0e34a04b..8d3e84042 100644 --- a/src/gns/plugin_block_gns.c +++ b/src/gns/plugin_block_gns.c | |||
@@ -22,9 +22,11 @@ | |||
22 | * @file gns/plugin_block_gns.c | 22 | * @file gns/plugin_block_gns.c |
23 | * @brief blocks used for GNS records | 23 | * @brief blocks used for GNS records |
24 | * @author Martin Schanzenbach | 24 | * @author Martin Schanzenbach |
25 | * @author Christian Grothoff | ||
25 | */ | 26 | */ |
26 | 27 | ||
27 | #include "platform.h" | 28 | #include "platform.h" |
29 | #include "gnunet_block_group_lib.h" | ||
28 | #include "gnunet_block_plugin.h" | 30 | #include "gnunet_block_plugin.h" |
29 | #include "gnunet_namestore_service.h" | 31 | #include "gnunet_namestore_service.h" |
30 | #include "gnunet_signatures.h" | 32 | #include "gnunet_signatures.h" |
@@ -36,6 +38,40 @@ | |||
36 | #define BLOOMFILTER_K 16 | 38 | #define BLOOMFILTER_K 16 |
37 | 39 | ||
38 | /** | 40 | /** |
41 | * How big is the BF we use for GNS blocks? | ||
42 | */ | ||
43 | #define GNS_BF_SIZE 8 | ||
44 | |||
45 | |||
46 | /** | ||
47 | * Create a new block group. | ||
48 | * | ||
49 | * @param ctx block context in which the block group is created | ||
50 | * @param type type of the block for which we are creating the group | ||
51 | * @param nonce random value used to seed the group creation | ||
52 | * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh | ||
53 | * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh | ||
54 | * @return block group handle, NULL if block groups are not supported | ||
55 | * by this @a type of block (this is not an error) | ||
56 | */ | ||
57 | static struct GNUNET_BLOCK_Group * | ||
58 | block_plugin_gns_create_group (void *cls, | ||
59 | enum GNUNET_BLOCK_Type type, | ||
60 | uint32_t nonce, | ||
61 | const void *raw_data, | ||
62 | size_t raw_data_size) | ||
63 | { | ||
64 | return GNUNET_BLOCK_GROUP_bf_create (cls, | ||
65 | GNS_BF_SIZE, | ||
66 | BLOOMFILTER_K, | ||
67 | type, | ||
68 | nonce, | ||
69 | raw_data, | ||
70 | raw_data_size); | ||
71 | } | ||
72 | |||
73 | |||
74 | /** | ||
39 | * Function called to validate a reply or a request. For | 75 | * Function called to validate a reply or a request. For |
40 | * request evaluation, simply pass "NULL" for the reply_block. | 76 | * request evaluation, simply pass "NULL" for the reply_block. |
41 | * Note that it is assumed that the reply has already been | 77 | * Note that it is assumed that the reply has already been |
@@ -141,9 +177,11 @@ block_plugin_gns_evaluate (void *cls, | |||
141 | * (or if extracting a key from a block of this type does not work) | 177 | * (or if extracting a key from a block of this type does not work) |
142 | */ | 178 | */ |
143 | static int | 179 | static int |
144 | block_plugin_gns_get_key (void *cls, enum GNUNET_BLOCK_Type type, | 180 | block_plugin_gns_get_key (void *cls, |
145 | const void *reply_block, size_t reply_block_size, | 181 | enum GNUNET_BLOCK_Type type, |
146 | struct GNUNET_HashCode *key) | 182 | const void *reply_block, |
183 | size_t reply_block_size, | ||
184 | struct GNUNET_HashCode *key) | ||
147 | { | 185 | { |
148 | const struct GNUNET_GNSRECORD_Block *block; | 186 | const struct GNUNET_GNSRECORD_Block *block; |
149 | 187 | ||
@@ -178,6 +216,7 @@ libgnunet_plugin_block_gns_init (void *cls) | |||
178 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | 216 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
179 | api->evaluate = &block_plugin_gns_evaluate; | 217 | api->evaluate = &block_plugin_gns_evaluate; |
180 | api->get_key = &block_plugin_gns_get_key; | 218 | api->get_key = &block_plugin_gns_get_key; |
219 | api->create_group = &block_plugin_gns_create_group; | ||
181 | api->types = types; | 220 | api->types = types; |
182 | return api; | 221 | return api; |
183 | } | 222 | } |
diff --git a/src/include/gnunet_block_group_lib.h b/src/include/gnunet_block_group_lib.h new file mode 100644 index 000000000..5fa14ce00 --- /dev/null +++ b/src/include/gnunet_block_group_lib.h | |||
@@ -0,0 +1,82 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2010 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @author Christian Grothoff | ||
23 | * | ||
24 | * @file | ||
25 | * Library for creating block groups (to be used by block plugins) | ||
26 | * | ||
27 | * @defgroup block Block group library | ||
28 | * Library for data group management | ||
29 | * @{ | ||
30 | */ | ||
31 | #ifndef GNUNET_BLOCK_GROUP_LIB_H | ||
32 | #define GNUNET_BLOCK_GROUP_LIB_H | ||
33 | |||
34 | #include "gnunet_util_lib.h" | ||
35 | #include "gnunet_block_lib.h" | ||
36 | |||
37 | #ifdef __cplusplus | ||
38 | extern "C" | ||
39 | { | ||
40 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
41 | } | ||
42 | #endif | ||
43 | #endif | ||
44 | |||
45 | |||
46 | /** | ||
47 | * Create a new block group that filters duplicates using a Bloom filter. | ||
48 | * | ||
49 | * @param ctx block context in which the block group is created | ||
50 | * @param bf_size size of the Bloom filter | ||
51 | * @param bf_k K-value for the Bloom filter | ||
52 | * @param type block type | ||
53 | * @param nonce random value used to seed the group creation | ||
54 | * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh | ||
55 | * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh | ||
56 | * @return block group handle, NULL if block groups are not supported | ||
57 | * by this @a type of block (this is not an error) | ||
58 | */ | ||
59 | struct GNUNET_BLOCK_Group * | ||
60 | GNUNET_BLOCK_GROUP_bf_create (void *cls, | ||
61 | size_t bf_size, | ||
62 | unsigned int bf_k, | ||
63 | enum GNUNET_BLOCK_Type type, | ||
64 | uint32_t nonce, | ||
65 | const void *raw_data, | ||
66 | size_t raw_data_size); | ||
67 | |||
68 | |||
69 | |||
70 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
71 | { | ||
72 | #endif | ||
73 | #ifdef __cplusplus | ||
74 | } | ||
75 | #endif | ||
76 | |||
77 | /* ifndef GNUNET_BLOCK_GROUP_LIB_H */ | ||
78 | #endif | ||
79 | |||
80 | /** @} */ /* end of group */ | ||
81 | |||
82 | /* end of gnunet_block_group_lib.h */ | ||
diff --git a/src/include/gnunet_block_lib.h b/src/include/gnunet_block_lib.h index b21b3496b..0f0fee499 100644 --- a/src/include/gnunet_block_lib.h +++ b/src/include/gnunet_block_lib.h | |||
@@ -230,6 +230,57 @@ GNUNET_BLOCK_context_destroy (struct GNUNET_BLOCK_Context *ctx); | |||
230 | 230 | ||
231 | 231 | ||
232 | /** | 232 | /** |
233 | * Handle for a group of elements that will be evaluated together. | ||
234 | * They must all be of the same type. A block group allows the | ||
235 | * plugin to keep some state across individual evaluations. | ||
236 | */ | ||
237 | struct GNUNET_BLOCK_Group; | ||
238 | |||
239 | |||
240 | /** | ||
241 | * Create a new block group. | ||
242 | * | ||
243 | * @param ctx block context in which the block group is created | ||
244 | * @param type type of the block for which we are creating the group | ||
245 | * @param nonce random value used to seed the group creation | ||
246 | * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh | ||
247 | * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh | ||
248 | * @return block group handle, NULL if block groups are not supported | ||
249 | * by this @a type of block (this is not an error) | ||
250 | */ | ||
251 | struct GNUNET_BLOCK_Group * | ||
252 | GNUNET_BLOCK_group_create (struct GNUNET_BLOCK_Context *ctx, | ||
253 | enum GNUNET_BLOCK_Type type, | ||
254 | uint32_t nonce, | ||
255 | const void *raw_data, | ||
256 | size_t raw_data_size); | ||
257 | |||
258 | |||
259 | /** | ||
260 | * Serialize state of a block group. | ||
261 | * | ||
262 | * @param bg group to serialize | ||
263 | * @param[out] raw_data set to the serialized state | ||
264 | * @param[out] raw_data_size set to the number of bytes in @a raw_data | ||
265 | * @return #GNUNET_OK on success, #GNUNET_NO if serialization is not | ||
266 | * supported, #GNUNET_SYSERR on error | ||
267 | */ | ||
268 | int | ||
269 | GNUNET_BLOCK_group_serialize (struct GNUNET_BLOCK_Group *bg, | ||
270 | void **raw_data, | ||
271 | size_t *raw_data_size); | ||
272 | |||
273 | |||
274 | /** | ||
275 | * Destroy resources used by a block group. | ||
276 | * | ||
277 | * @param bg group to destroy, NULL is allowed | ||
278 | */ | ||
279 | void | ||
280 | GNUNET_BLOCK_group_destroy (struct GNUNET_BLOCK_Group *bg); | ||
281 | |||
282 | |||
283 | /** | ||
233 | * Function called to validate a reply or a request. For | 284 | * Function called to validate a reply or a request. For |
234 | * request evaluation, simply pass "NULL" for the @a reply_block. | 285 | * request evaluation, simply pass "NULL" for the @a reply_block. |
235 | * Note that it is assumed that the reply has already been | 286 | * Note that it is assumed that the reply has already been |
diff --git a/src/include/gnunet_block_plugin.h b/src/include/gnunet_block_plugin.h index 5c320457e..d7454b5d5 100644 --- a/src/include/gnunet_block_plugin.h +++ b/src/include/gnunet_block_plugin.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2010,2013 GNUnet e.V. | 3 | Copyright (C) 2010,2013,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 |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -40,6 +40,86 @@ | |||
40 | 40 | ||
41 | 41 | ||
42 | /** | 42 | /** |
43 | * Serialize state of a block group. | ||
44 | * | ||
45 | * @param bg group to serialize | ||
46 | * @param[out] raw_data set to the serialized state | ||
47 | * @param[out] raw_data_size set to the number of bytes in @a raw_data | ||
48 | * @return #GNUNET_OK on success, #GNUNET_NO if serialization is not | ||
49 | * supported, #GNUNET_SYSERR on error | ||
50 | */ | ||
51 | typedef int | ||
52 | (*GNUNET_BLOCK_GroupSerializeFunction)(struct GNUNET_BLOCK_Group *bg, | ||
53 | void **raw_data, | ||
54 | size_t *raw_data_size); | ||
55 | |||
56 | |||
57 | /** | ||
58 | * Destroy resources used by a block group. | ||
59 | * | ||
60 | * @param bg group to destroy, NULL is allowed | ||
61 | */ | ||
62 | typedef void | ||
63 | (*GNUNET_BLOCK_GroupDestroyFunction)(struct GNUNET_BLOCK_Group *bg); | ||
64 | |||
65 | |||
66 | /** | ||
67 | * Block group data. The plugin must initialize the callbacks | ||
68 | * and can use the @e internal_cls as it likes. | ||
69 | */ | ||
70 | struct GNUNET_BLOCK_Group | ||
71 | { | ||
72 | |||
73 | /** | ||
74 | * Context owning the block group. Set by the main block library. | ||
75 | */ | ||
76 | struct GNUENT_BLOCK_Context *ctx; | ||
77 | |||
78 | /** | ||
79 | * Type for the block group. Set by the main block library. | ||
80 | */ | ||
81 | enum GNUNET_BLOCK_Type type; | ||
82 | |||
83 | /** | ||
84 | * Serialize the block group data, can be NULL if | ||
85 | * not supported. | ||
86 | */ | ||
87 | GNUNET_BLOCK_GroupSerializeFunction serialize_cb; | ||
88 | |||
89 | /** | ||
90 | * Function to call to destroy the block group. | ||
91 | * Must not be NULL. | ||
92 | */ | ||
93 | GNUNET_BLOCK_GroupDestroyFunction destroy_cb; | ||
94 | |||
95 | /** | ||
96 | * Internal data structure of the plugin. | ||
97 | */ | ||
98 | void *internal_cls; | ||
99 | |||
100 | }; | ||
101 | |||
102 | |||
103 | /** | ||
104 | * Create a new block group. | ||
105 | * | ||
106 | * @param ctx block context in which the block group is created | ||
107 | * @param type type of the block for which we are creating the group | ||
108 | * @param nonce random value used to seed the group creation | ||
109 | * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh | ||
110 | * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh | ||
111 | * @return block group handle, NULL if block groups are not supported | ||
112 | * by this @a type of block (this is not an error) | ||
113 | */ | ||
114 | typedef struct GNUNET_BLOCK_Group * | ||
115 | (*GNUNET_BLOCK_GroupCreateFunction)(void *cls, | ||
116 | enum GNUNET_BLOCK_Type type, | ||
117 | uint32_t nonce, | ||
118 | const void *raw_data, | ||
119 | size_t raw_data_size); | ||
120 | |||
121 | |||
122 | /** | ||
43 | * Function called to validate a reply or a request. For | 123 | * Function called to validate a reply or a request. For |
44 | * request evaluation, simply pass "NULL" for the @a reply_block. | 124 | * request evaluation, simply pass "NULL" for the @a reply_block. |
45 | * Note that it is assumed that the reply has already been | 125 | * Note that it is assumed that the reply has already been |
@@ -121,6 +201,11 @@ struct GNUNET_BLOCK_PluginFunctions | |||
121 | */ | 201 | */ |
122 | GNUNET_BLOCK_GetKeyFunction get_key; | 202 | GNUNET_BLOCK_GetKeyFunction get_key; |
123 | 203 | ||
204 | /** | ||
205 | * Create a block group to process a bunch of blocks in a shared | ||
206 | * context (i.e. to detect duplicates). | ||
207 | */ | ||
208 | GNUNET_BLOCK_GroupCreateFunction create_group; | ||
124 | }; | 209 | }; |
125 | 210 | ||
126 | #endif | 211 | #endif |
diff --git a/src/regex/Makefile.am b/src/regex/Makefile.am index 70f612485..80997db40 100644 --- a/src/regex/Makefile.am +++ b/src/regex/Makefile.am | |||
@@ -80,6 +80,7 @@ libgnunet_plugin_block_regex_la_SOURCES = \ | |||
80 | libgnunet_plugin_block_regex_la_LIBADD = \ | 80 | libgnunet_plugin_block_regex_la_LIBADD = \ |
81 | libgnunetregexblock.la \ | 81 | libgnunetregexblock.la \ |
82 | $(top_builddir)/src/block/libgnunetblock.la \ | 82 | $(top_builddir)/src/block/libgnunetblock.la \ |
83 | $(top_builddir)/src/block/libgnunetblockgroup.la \ | ||
83 | $(top_builddir)/src/util/libgnunetutil.la | 84 | $(top_builddir)/src/util/libgnunetutil.la |
84 | libgnunet_plugin_block_regex_la_LDFLAGS = \ | 85 | libgnunet_plugin_block_regex_la_LDFLAGS = \ |
85 | $(GN_PLUGIN_LDFLAGS) | 86 | $(GN_PLUGIN_LDFLAGS) |
diff --git a/src/regex/plugin_block_regex.c b/src/regex/plugin_block_regex.c index 36926c25d..11511a71b 100644 --- a/src/regex/plugin_block_regex.c +++ b/src/regex/plugin_block_regex.c | |||
@@ -23,9 +23,9 @@ | |||
23 | * @brief blocks used for regex storage and search | 23 | * @brief blocks used for regex storage and search |
24 | * @author Bartlomiej Polot | 24 | * @author Bartlomiej Polot |
25 | */ | 25 | */ |
26 | |||
27 | #include "platform.h" | 26 | #include "platform.h" |
28 | #include "gnunet_block_plugin.h" | 27 | #include "gnunet_block_plugin.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" | 31 | #include "gnunet_constants.h" |
@@ -33,6 +33,40 @@ | |||
33 | 33 | ||
34 | 34 | ||
35 | /** | 35 | /** |
36 | * How big is the BF we use for REGEX blocks? | ||
37 | */ | ||
38 | #define REGEX_BF_SIZE 8 | ||
39 | |||
40 | |||
41 | /** | ||
42 | * Create a new block group. | ||
43 | * | ||
44 | * @param ctx block context in which the block group is created | ||
45 | * @param type type of the block for which we are creating the group | ||
46 | * @param nonce random value used to seed the group creation | ||
47 | * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh | ||
48 | * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh | ||
49 | * @return block group handle, NULL if block groups are not supported | ||
50 | * by this @a type of block (this is not an error) | ||
51 | */ | ||
52 | static struct GNUNET_BLOCK_Group * | ||
53 | block_plugin_regex_create_group (void *cls, | ||
54 | enum GNUNET_BLOCK_Type type, | ||
55 | uint32_t nonce, | ||
56 | const void *raw_data, | ||
57 | size_t raw_data_size) | ||
58 | { | ||
59 | return GNUNET_BLOCK_GROUP_bf_create (cls, | ||
60 | REGEX_BF_SIZE, | ||
61 | GNUNET_CONSTANTS_BLOOMFILTER_K, | ||
62 | type, | ||
63 | nonce, | ||
64 | raw_data, | ||
65 | raw_data_size); | ||
66 | } | ||
67 | |||
68 | |||
69 | /** | ||
36 | * Function called to validate a reply or a request of type | 70 | * Function called to validate a reply or a request of type |
37 | * #GNUNET_BLOCK_TYPE_REGEX. | 71 | * #GNUNET_BLOCK_TYPE_REGEX. |
38 | * For request evaluation, pass "NULL" for the reply_block. | 72 | * For request evaluation, pass "NULL" for the reply_block. |
@@ -346,6 +380,7 @@ libgnunet_plugin_block_regex_init (void *cls) | |||
346 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | 380 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
347 | api->evaluate = &block_plugin_regex_evaluate; | 381 | api->evaluate = &block_plugin_regex_evaluate; |
348 | api->get_key = &block_plugin_regex_get_key; | 382 | api->get_key = &block_plugin_regex_get_key; |
383 | api->create_group = &block_plugin_regex_create_group; | ||
349 | api->types = types; | 384 | api->types = types; |
350 | return api; | 385 | return api; |
351 | } | 386 | } |