2 This file is part of GNUnet
3 Copyright (C) 2010,2013,2017 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
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 Affero General Public License for more details.
17 * @author Christian Grothoff
20 * API for block plugins.
22 * @defgroup block-plugin Block plugin API
23 * To be implemented by applications storing data in the DHT.
25 * Each block plugin must conform to the API specified by this header.
30 #ifndef PLUGIN_BLOCK_H
31 #define PLUGIN_BLOCK_H
33 #include "gnunet_util_lib.h"
34 #include "gnunet_block_lib.h"
38 * Mark elements as "seen" using a hash of the element. Not supported
39 * by all block plugins.
41 * @param bg group to update
42 * @param seen_results results already seen
43 * @param seen_results_count number of entries in @a seen_results
46 (*GNUNET_BLOCK_GroupMarkSeenFunction)(struct GNUNET_BLOCK_Group *bg,
47 const struct GNUNET_HashCode *seen_results,
48 unsigned int seen_results_count);
52 * Merge two groups, if possible. Not supported by all block plugins,
53 * can also fail if the nonces were different.
55 * @param bg1 group to update
56 * @param bg2 group to merge into @a bg1
57 * @return #GNUNET_OK on success, #GNUNET_NO if the nonces were different and thus
61 (*GNUNET_BLOCK_GroupMergeFunction)(struct GNUNET_BLOCK_Group *bg1,
62 const struct GNUNET_BLOCK_Group *bg2);
66 * Serialize state of a block group.
68 * @param bg group to serialize
69 * @param[out] nonce set to the nonce of the @a bg
70 * @param[out] raw_data set to the serialized state
71 * @param[out] raw_data_size set to the number of bytes in @a raw_data
72 * @return #GNUNET_OK on success, #GNUNET_NO if serialization is not
73 * supported, #GNUNET_SYSERR on error
76 (*GNUNET_BLOCK_GroupSerializeFunction)(struct GNUNET_BLOCK_Group *bg,
79 size_t *raw_data_size);
83 * Destroy resources used by a block group.
85 * @param bg group to destroy, NULL is allowed
88 (*GNUNET_BLOCK_GroupDestroyFunction)(struct GNUNET_BLOCK_Group *bg);
92 * Block group data. The plugin must initialize the callbacks
93 * and can use the @e internal_cls as it likes.
95 struct GNUNET_BLOCK_Group
99 * Context owning the block group. Set by the main block library.
101 struct GNUENT_BLOCK_Context *ctx;
104 * Type for the block group. Set by the main block library.
106 enum GNUNET_BLOCK_Type type;
109 * Serialize the block group data, can be NULL if
112 GNUNET_BLOCK_GroupSerializeFunction serialize_cb;
115 * Function to call to mark elements as seen in the group.
116 * Can be NULL if not supported.
118 GNUNET_BLOCK_GroupMarkSeenFunction mark_seen_cb;
121 * Function to call to merge two groups.
122 * Can be NULL if not supported.
124 GNUNET_BLOCK_GroupMergeFunction merge_cb;
127 * Function to call to destroy the block group.
130 GNUNET_BLOCK_GroupDestroyFunction destroy_cb;
133 * Internal data structure of the plugin.
141 * Create a new block group.
143 * @param ctx block context in which the block group is created
144 * @param type type of the block for which we are creating the group
145 * @param nonce random value used to seed the group creation
146 * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh
147 * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh
148 * @param va variable arguments specific to @a type
149 * @return block group handle, NULL if block groups are not supported
150 * by this @a type of block (this is not an error)
152 typedef struct GNUNET_BLOCK_Group *
153 (*GNUNET_BLOCK_GroupCreateFunction)(void *cls,
154 enum GNUNET_BLOCK_Type type,
156 const void *raw_data,
157 size_t raw_data_size,
162 * Function called to validate a reply or a request. For
163 * request evaluation, simply pass "NULL" for the @a reply_block.
164 * Note that it is assumed that the reply has already been
165 * matched to the key (and signatures checked) as it would
166 * be done with the "get_key" function.
169 * @param ctx block context
170 * @param type block type
171 * @param group which block group to use for evaluation
172 * @param eo evaluation options to control evaluation
173 * @param query original query (hash)
174 * @param xquery extrended query data (can be NULL, depending on type)
175 * @param xquery_size number of bytes in @a xquery
176 * @param reply_block response to validate
177 * @param reply_block_size number of bytes in @a reply_block
178 * @return characterization of result
180 typedef enum GNUNET_BLOCK_EvaluationResult
181 (*GNUNET_BLOCK_EvaluationFunction) (void *cls,
182 struct GNUNET_BLOCK_Context *ctx,
183 enum GNUNET_BLOCK_Type type,
184 struct GNUNET_BLOCK_Group *group,
185 enum GNUNET_BLOCK_EvaluationOptions eo,
186 const struct GNUNET_HashCode *query,
189 const void *reply_block,
190 size_t reply_block_size);
194 * Function called to obtain the key for a block.
197 * @param type block type
198 * @param block block to get the key for
199 * @param block_size number of bytes in @a block
200 * @param key set to the key (query) for the given block
201 * @return #GNUNET_YES on success,
202 * #GNUNET_NO if the block is malformed
203 * #GNUNET_SYSERR if type not supported
204 * (or if extracting a key from a block of this type does not work)
207 (*GNUNET_BLOCK_GetKeyFunction) (void *cls,
208 enum GNUNET_BLOCK_Type type,
211 struct GNUNET_HashCode *key);
216 * Each plugin is required to return a pointer to a struct of this
217 * type as the return value from its entry point.
219 struct GNUNET_BLOCK_PluginFunctions
223 * Closure for all of the callbacks.
228 * 0-terminated array of block types supported by this plugin.
230 const enum GNUNET_BLOCK_Type *types;
233 * Main function of a block plugin. Allows us to check if a
234 * block matches a query.
236 GNUNET_BLOCK_EvaluationFunction evaluate;
239 * Obtain the key for a given block (if possible).
241 GNUNET_BLOCK_GetKeyFunction get_key;
244 * Create a block group to process a bunch of blocks in a shared
245 * context (i.e. to detect duplicates).
247 GNUNET_BLOCK_GroupCreateFunction create_group;
252 /** @} */ /* end of group */