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/block/block.c | |
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/block/block.c')
-rw-r--r-- | src/block/block.c | 72 |
1 files changed, 72 insertions, 0 deletions
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 |