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 * Serialize state of a block group.
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
52 (*GNUNET_BLOCK_GroupSerializeFunction)(struct GNUNET_BLOCK_Group *bg,
54 size_t *raw_data_size);
58 * Destroy resources used by a block group.
60 * @param bg group to destroy, NULL is allowed
63 (*GNUNET_BLOCK_GroupDestroyFunction)(struct GNUNET_BLOCK_Group *bg);
67 * Block group data. The plugin must initialize the callbacks
68 * and can use the @e internal_cls as it likes.
70 struct GNUNET_BLOCK_Group
74 * Context owning the block group. Set by the main block library.
76 struct GNUENT_BLOCK_Context *ctx;
79 * Type for the block group. Set by the main block library.
81 enum GNUNET_BLOCK_Type type;
84 * Serialize the block group data, can be NULL if
87 GNUNET_BLOCK_GroupSerializeFunction serialize_cb;
90 * Function to call to destroy the block group.
93 GNUNET_BLOCK_GroupDestroyFunction destroy_cb;
96 * Internal data structure of the plugin.
104 * Create a new block group.
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)
114 typedef struct GNUNET_BLOCK_Group *
115 (*GNUNET_BLOCK_GroupCreateFunction)(void *cls,
116 enum GNUNET_BLOCK_Type type,
118 const void *raw_data,
119 size_t raw_data_size);
123 * Function called to validate a reply or a request. For
124 * request evaluation, simply pass "NULL" for the @a reply_block.
125 * Note that it is assumed that the reply has already been
126 * matched to the key (and signatures checked) as it would
127 * be done with the "get_key" function.
130 * @param type block type
131 * @param eo evaluation options to control evaluation
132 * @param query original query (hash)
133 * @param bf pointer to bloom filter associated with query; possibly updated (!)
134 * @param bf_mutator mutation value for @a bf
135 * @param xquery extrended query data (can be NULL, depending on type)
136 * @param xquery_size number of bytes in @a xquery
137 * @param reply_block response to validate
138 * @param reply_block_size number of bytes in @a reply_block
139 * @return characterization of result
141 typedef enum GNUNET_BLOCK_EvaluationResult
142 (*GNUNET_BLOCK_EvaluationFunction) (void *cls,
143 enum GNUNET_BLOCK_Type type,
144 enum GNUNET_BLOCK_EvaluationOptions eo,
145 const struct GNUNET_HashCode *query,
146 struct GNUNET_CONTAINER_BloomFilter **bf,
150 const void *reply_block,
151 size_t reply_block_size);
155 * Function called to obtain the key for a block.
158 * @param type block type
159 * @param block block to get the key for
160 * @param block_size number of bytes in @a block
161 * @param key set to the key (query) for the given block
162 * @return #GNUNET_YES on success,
163 * #GNUNET_NO if the block is malformed
164 * #GNUNET_SYSERR if type not supported
165 * (or if extracting a key from a block of this type does not work)
168 (*GNUNET_BLOCK_GetKeyFunction) (void *cls,
169 enum GNUNET_BLOCK_Type type,
172 struct GNUNET_HashCode *key);
177 * Each plugin is required to return a pointer to a struct of this
178 * type as the return value from its entry point.
180 struct GNUNET_BLOCK_PluginFunctions
184 * Closure for all of the callbacks.
189 * 0-terminated array of block types supported by this plugin.
191 const enum GNUNET_BLOCK_Type *types;
194 * Main function of a block plugin. Allows us to check if a
195 * block matches a query.
197 GNUNET_BLOCK_EvaluationFunction evaluate;
200 * Obtain the key for a given block (if possible).
202 GNUNET_BLOCK_GetKeyFunction get_key;
205 * Create a block group to process a bunch of blocks in a shared
206 * context (i.e. to detect duplicates).
208 GNUNET_BLOCK_GroupCreateFunction create_group;
213 /** @} */ /* end of group */