diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-02-20 15:09:00 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-02-20 15:09:19 +0100 |
commit | a3882b58f1c5976677aa65b0af8a48e8e946b06e (patch) | |
tree | bd841d8e78052a05821e194d002ca843693fb2c9 /src/include | |
parent | f0149c5430f42a8bad422e9c51754af59c7bfa2f (diff) | |
download | gnunet-a3882b58f1c5976677aa65b0af8a48e8e946b06e.tar.gz gnunet-a3882b58f1c5976677aa65b0af8a48e8e946b06e.zip |
first half of new BLOCK API to generalize duplicate detection beyond BFs
Diffstat (limited to 'src/include')
-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 |
3 files changed, 219 insertions, 1 deletions
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 |