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 Affero 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.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * @author Christian Grothoff
23 * API for block plugins.
25 * @defgroup block-plugin Block plugin API
26 * To be implemented by applications storing data in the DHT.
28 * Each block plugin must conform to the API specified by this header.
33 #ifndef PLUGIN_BLOCK_H
34 #define PLUGIN_BLOCK_H
36 #include "gnunet_util_lib.h"
37 #include "gnunet_block_lib.h"
41 * Mark elements as "seen" using a hash of the element. Not supported
42 * by all block plugins.
44 * @param bg group to update
45 * @param seen_results results already seen
46 * @param seen_results_count number of entries in @a seen_results
49 (*GNUNET_BLOCK_GroupMarkSeenFunction)(struct GNUNET_BLOCK_Group *bg,
50 const struct GNUNET_HashCode *seen_results,
51 unsigned int seen_results_count);
55 * Merge two groups, if possible. Not supported by all block plugins,
56 * can also fail if the nonces were different.
58 * @param bg1 group to update
59 * @param bg2 group to merge into @a bg1
60 * @return #GNUNET_OK on success, #GNUNET_NO if the nonces were different and thus
64 (*GNUNET_BLOCK_GroupMergeFunction)(struct GNUNET_BLOCK_Group *bg1,
65 const struct GNUNET_BLOCK_Group *bg2);
69 * Serialize state of a block group.
71 * @param bg group to serialize
72 * @param[out] nonce set to the nonce of the @a bg
73 * @param[out] raw_data set to the serialized state
74 * @param[out] raw_data_size set to the number of bytes in @a raw_data
75 * @return #GNUNET_OK on success, #GNUNET_NO if serialization is not
76 * supported, #GNUNET_SYSERR on error
79 (*GNUNET_BLOCK_GroupSerializeFunction)(struct GNUNET_BLOCK_Group *bg,
82 size_t *raw_data_size);
86 * Destroy resources used by a block group.
88 * @param bg group to destroy, NULL is allowed
91 (*GNUNET_BLOCK_GroupDestroyFunction)(struct GNUNET_BLOCK_Group *bg);
95 * Block group data. The plugin must initialize the callbacks
96 * and can use the @e internal_cls as it likes.
98 struct GNUNET_BLOCK_Group
102 * Context owning the block group. Set by the main block library.
104 struct GNUENT_BLOCK_Context *ctx;
107 * Type for the block group. Set by the main block library.
109 enum GNUNET_BLOCK_Type type;
112 * Serialize the block group data, can be NULL if
115 GNUNET_BLOCK_GroupSerializeFunction serialize_cb;
118 * Function to call to mark elements as seen in the group.
119 * Can be NULL if not supported.
121 GNUNET_BLOCK_GroupMarkSeenFunction mark_seen_cb;
124 * Function to call to merge two groups.
125 * Can be NULL if not supported.
127 GNUNET_BLOCK_GroupMergeFunction merge_cb;
130 * Function to call to destroy the block group.
133 GNUNET_BLOCK_GroupDestroyFunction destroy_cb;
136 * Internal data structure of the plugin.
144 * Create a new block group.
146 * @param ctx block context in which the block group is created
147 * @param type type of the block for which we are creating the group
148 * @param nonce random value used to seed the group creation
149 * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh
150 * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh
151 * @param va variable arguments specific to @a type
152 * @return block group handle, NULL if block groups are not supported
153 * by this @a type of block (this is not an error)
155 typedef struct GNUNET_BLOCK_Group *
156 (*GNUNET_BLOCK_GroupCreateFunction)(void *cls,
157 enum GNUNET_BLOCK_Type type,
159 const void *raw_data,
160 size_t raw_data_size,
165 * Function called to validate a reply or a request. For
166 * request evaluation, simply pass "NULL" for the @a reply_block.
167 * Note that it is assumed that the reply has already been
168 * matched to the key (and signatures checked) as it would
169 * be done with the "get_key" function.
172 * @param ctx block context
173 * @param type block type
174 * @param group which block group to use for evaluation
175 * @param eo evaluation options to control evaluation
176 * @param query original query (hash)
177 * @param xquery extrended query data (can be NULL, depending on type)
178 * @param xquery_size number of bytes in @a xquery
179 * @param reply_block response to validate
180 * @param reply_block_size number of bytes in @a reply_block
181 * @return characterization of result
183 typedef enum GNUNET_BLOCK_EvaluationResult
184 (*GNUNET_BLOCK_EvaluationFunction) (void *cls,
185 struct GNUNET_BLOCK_Context *ctx,
186 enum GNUNET_BLOCK_Type type,
187 struct GNUNET_BLOCK_Group *group,
188 enum GNUNET_BLOCK_EvaluationOptions eo,
189 const struct GNUNET_HashCode *query,
192 const void *reply_block,
193 size_t reply_block_size);
197 * Function called to obtain the key for a block.
200 * @param type block type
201 * @param block block to get the key for
202 * @param block_size number of bytes in @a block
203 * @param key set to the key (query) for the given block
204 * @return #GNUNET_YES on success,
205 * #GNUNET_NO if the block is malformed
206 * #GNUNET_SYSERR if type not supported
207 * (or if extracting a key from a block of this type does not work)
210 (*GNUNET_BLOCK_GetKeyFunction) (void *cls,
211 enum GNUNET_BLOCK_Type type,
214 struct GNUNET_HashCode *key);
219 * Each plugin is required to return a pointer to a struct of this
220 * type as the return value from its entry point.
222 struct GNUNET_BLOCK_PluginFunctions
226 * Closure for all of the callbacks.
231 * 0-terminated array of block types supported by this plugin.
233 const enum GNUNET_BLOCK_Type *types;
236 * Main function of a block plugin. Allows us to check if a
237 * block matches a query.
239 GNUNET_BLOCK_EvaluationFunction evaluate;
242 * Obtain the key for a given block (if possible).
244 GNUNET_BLOCK_GetKeyFunction get_key;
247 * Create a block group to process a bunch of blocks in a shared
248 * context (i.e. to detect duplicates).
250 GNUNET_BLOCK_GroupCreateFunction create_group;
255 /** @} */ /* end of group */