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
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.
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.
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.
22 * @author Christian Grothoff
25 * API for block plugins.
27 * @defgroup block-plugin Block plugin API
28 * To be implemented by applications storing data in the DHT.
30 * Each block plugin must conform to the API specified by this header.
35 #ifndef PLUGIN_BLOCK_H
36 #define PLUGIN_BLOCK_H
38 #include "gnunet_util_lib.h"
39 #include "gnunet_block_lib.h"
43 * Mark elements as "seen" using a hash of the element. Not supported
44 * by all block plugins.
46 * @param bg group to update
47 * @param seen_results results already seen
48 * @param seen_results_count number of entries in @a seen_results
51 (*GNUNET_BLOCK_GroupMarkSeenFunction)(struct GNUNET_BLOCK_Group *bg,
52 const struct GNUNET_HashCode *seen_results,
53 unsigned int seen_results_count);
57 * Merge two groups, if possible. Not supported by all block plugins,
58 * can also fail if the nonces were different.
60 * @param bg1 group to update
61 * @param bg2 group to merge into @a bg1
62 * @return #GNUNET_OK on success, #GNUNET_NO if the nonces were different and thus
66 (*GNUNET_BLOCK_GroupMergeFunction)(struct GNUNET_BLOCK_Group *bg1,
67 const struct GNUNET_BLOCK_Group *bg2);
71 * Serialize state of a block group.
73 * @param bg group to serialize
74 * @param[out] nonce set to the nonce of the @a bg
75 * @param[out] raw_data set to the serialized state
76 * @param[out] raw_data_size set to the number of bytes in @a raw_data
77 * @return #GNUNET_OK on success, #GNUNET_NO if serialization is not
78 * supported, #GNUNET_SYSERR on error
81 (*GNUNET_BLOCK_GroupSerializeFunction)(struct GNUNET_BLOCK_Group *bg,
84 size_t *raw_data_size);
88 * Destroy resources used by a block group.
90 * @param bg group to destroy, NULL is allowed
93 (*GNUNET_BLOCK_GroupDestroyFunction)(struct GNUNET_BLOCK_Group *bg);
97 * Block group data. The plugin must initialize the callbacks
98 * and can use the @e internal_cls as it likes.
100 struct GNUNET_BLOCK_Group
104 * Context owning the block group. Set by the main block library.
106 struct GNUENT_BLOCK_Context *ctx;
109 * Type for the block group. Set by the main block library.
111 enum GNUNET_BLOCK_Type type;
114 * Serialize the block group data, can be NULL if
117 GNUNET_BLOCK_GroupSerializeFunction serialize_cb;
120 * Function to call to mark elements as seen in the group.
121 * Can be NULL if not supported.
123 GNUNET_BLOCK_GroupMarkSeenFunction mark_seen_cb;
126 * Function to call to merge two groups.
127 * Can be NULL if not supported.
129 GNUNET_BLOCK_GroupMergeFunction merge_cb;
132 * Function to call to destroy the block group.
135 GNUNET_BLOCK_GroupDestroyFunction destroy_cb;
138 * Internal data structure of the plugin.
146 * Create a new block group.
148 * @param ctx block context in which the block group is created
149 * @param type type of the block for which we are creating the group
150 * @param nonce random value used to seed the group creation
151 * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh
152 * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh
153 * @param va variable arguments specific to @a type
154 * @return block group handle, NULL if block groups are not supported
155 * by this @a type of block (this is not an error)
157 typedef struct GNUNET_BLOCK_Group *
158 (*GNUNET_BLOCK_GroupCreateFunction)(void *cls,
159 enum GNUNET_BLOCK_Type type,
161 const void *raw_data,
162 size_t raw_data_size,
167 * Function called to validate a reply or a request. For
168 * request evaluation, simply pass "NULL" for the @a reply_block.
169 * Note that it is assumed that the reply has already been
170 * matched to the key (and signatures checked) as it would
171 * be done with the "get_key" function.
174 * @param ctx block context
175 * @param type block type
176 * @param group which block group to use for evaluation
177 * @param eo evaluation options to control evaluation
178 * @param query original query (hash)
179 * @param xquery extrended query data (can be NULL, depending on type)
180 * @param xquery_size number of bytes in @a xquery
181 * @param reply_block response to validate
182 * @param reply_block_size number of bytes in @a reply_block
183 * @return characterization of result
185 typedef enum GNUNET_BLOCK_EvaluationResult
186 (*GNUNET_BLOCK_EvaluationFunction) (void *cls,
187 struct GNUNET_BLOCK_Context *ctx,
188 enum GNUNET_BLOCK_Type type,
189 struct GNUNET_BLOCK_Group *group,
190 enum GNUNET_BLOCK_EvaluationOptions eo,
191 const struct GNUNET_HashCode *query,
194 const void *reply_block,
195 size_t reply_block_size);
199 * Function called to obtain the key for a block.
202 * @param type block type
203 * @param block block to get the key for
204 * @param block_size number of bytes in @a block
205 * @param key set to the key (query) for the given block
206 * @return #GNUNET_YES on success,
207 * #GNUNET_NO if the block is malformed
208 * #GNUNET_SYSERR if type not supported
209 * (or if extracting a key from a block of this type does not work)
212 (*GNUNET_BLOCK_GetKeyFunction) (void *cls,
213 enum GNUNET_BLOCK_Type type,
216 struct GNUNET_HashCode *key);
221 * Each plugin is required to return a pointer to a struct of this
222 * type as the return value from its entry point.
224 struct GNUNET_BLOCK_PluginFunctions
228 * Closure for all of the callbacks.
233 * 0-terminated array of block types supported by this plugin.
235 const enum GNUNET_BLOCK_Type *types;
238 * Main function of a block plugin. Allows us to check if a
239 * block matches a query.
241 GNUNET_BLOCK_EvaluationFunction evaluate;
244 * Obtain the key for a given block (if possible).
246 GNUNET_BLOCK_GetKeyFunction get_key;
249 * Create a block group to process a bunch of blocks in a shared
250 * context (i.e. to detect duplicates).
252 GNUNET_BLOCK_GroupCreateFunction create_group;
257 /** @} */ /* end of group */