aboutsummaryrefslogtreecommitdiff
path: root/src/block
diff options
context:
space:
mode:
authorChristian Grothoff <grothoff@gnunet.org>2021-12-29 18:22:37 +0100
committerChristian Grothoff <grothoff@gnunet.org>2021-12-29 18:22:37 +0100
commitc0b6f577cb6866a8bfce22acbcec6983d5f610f6 (patch)
treea7cb3c59313b8cc44b3ec51baa9bdd97e25efd09 /src/block
parentfd620976c140d5df43cf174a54a9f88c4808cad3 (diff)
downloadgnunet-c0b6f577cb6866a8bfce22acbcec6983d5f610f6.tar.gz
gnunet-c0b6f577cb6866a8bfce22acbcec6983d5f610f6.zip
-updating block plugins to new API
Diffstat (limited to 'src/block')
-rw-r--r--src/block/plugin_block_template.c83
-rw-r--r--src/block/plugin_block_test.c109
2 files changed, 187 insertions, 5 deletions
diff --git a/src/block/plugin_block_template.c b/src/block/plugin_block_template.c
index ecd46e364..13d9adfda 100644
--- a/src/block/plugin_block_template.c
+++ b/src/block/plugin_block_template.c
@@ -135,6 +135,80 @@ block_plugin_template_evaluate (void *cls,
135 135
136 136
137/** 137/**
138 * Function called to validate a query.
139 *
140 * @param cls closure
141 * @param ctx block context
142 * @param type block type
143 * @param query original query (hash)
144 * @param xquery extrended query data (can be NULL, depending on type)
145 * @param xquery_size number of bytes in @a xquery
146 * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not
147 */
148static enum GNUNET_GenericReturnValue
149block_plugin_template_check_query (void *cls,
150 enum GNUNET_BLOCK_Type type,
151 const struct GNUNET_HashCode *query,
152 const void *xquery,
153 size_t xquery_size)
154{
155 return GNUNET_OK;
156}
157
158
159/**
160 * Function called to validate a block for storage.
161 *
162 * @param cls closure
163 * @param type block type
164 * @param query key for the block (hash), must match exactly
165 * @param block block data to validate
166 * @param block_size number of bytes in @a block
167 * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not
168 */
169static enum GNUNET_GenericReturnValue
170block_plugin_template_check_block (void *cls,
171 enum GNUNET_BLOCK_Type type,
172 const struct GNUNET_HashCode *query,
173 const void *block,
174 size_t block_size)
175{
176 return GNUNET_OK;
177}
178
179
180/**
181 * Function called to validate a reply to a request. Note that it is assumed
182 * that the reply has already been matched to the key (and signatures checked)
183 * as it would be done with the GetKeyFunction and the
184 * BlockEvaluationFunction.
185 *
186 * @param cls closure
187 * @param type block type
188 * @param group which block group to use for evaluation
189 * @param query original query (hash)
190 * @param xquery extrended query data (can be NULL, depending on type)
191 * @param xquery_size number of bytes in @a xquery
192 * @param reply_block response to validate
193 * @param reply_block_size number of bytes in @a reply_block
194 * @return characterization of result
195 */
196static enum GNUNET_BLOCK_ReplyEvaluationResult
197block_plugin_template_check_reply (
198 void *cls,
199 enum GNUNET_BLOCK_Type type,
200 struct GNUNET_BLOCK_Group *group,
201 const struct GNUNET_HashCode *query,
202 const void *xquery,
203 size_t xquery_size,
204 const void *reply_block,
205 size_t reply_block_size)
206{
207 return GNUNET_BLOCK_REPLY_OK_MORE;
208}
209
210
211/**
138 * Function called to obtain the key for a block. 212 * Function called to obtain the key for a block.
139 * 213 *
140 * @param cls closure 214 * @param cls closure
@@ -145,7 +219,7 @@ block_plugin_template_evaluate (void *cls,
145 * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported 219 * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported
146 * (or if extracting a key from a block of this type does not work) 220 * (or if extracting a key from a block of this type does not work)
147 */ 221 */
148static int 222static enum GNUNET_GenericReturnValue
149block_plugin_template_get_key (void *cls, 223block_plugin_template_get_key (void *cls,
150 enum GNUNET_BLOCK_Type type, 224 enum GNUNET_BLOCK_Type type,
151 const void *block, 225 const void *block,
@@ -164,8 +238,8 @@ block_plugin_template_get_key (void *cls,
164void * 238void *
165libgnunet_plugin_block_template_init (void *cls) 239libgnunet_plugin_block_template_init (void *cls)
166{ 240{
167 static enum GNUNET_BLOCK_Type types[] = { 241 static const enum GNUNET_BLOCK_Type types[] = {
168 /* FIXME: insert supported block types here */ 242 /* NOTE: insert supported block types here */
169 GNUNET_BLOCK_TYPE_ANY /* end of list */ 243 GNUNET_BLOCK_TYPE_ANY /* end of list */
170 }; 244 };
171 struct GNUNET_BLOCK_PluginFunctions *api; 245 struct GNUNET_BLOCK_PluginFunctions *api;
@@ -173,6 +247,9 @@ libgnunet_plugin_block_template_init (void *cls)
173 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); 247 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
174 api->evaluate = &block_plugin_template_evaluate; 248 api->evaluate = &block_plugin_template_evaluate;
175 api->get_key = &block_plugin_template_get_key; 249 api->get_key = &block_plugin_template_get_key;
250 api->check_query = &block_plugin_template_check_query;
251 api->check_block = &block_plugin_template_check_block;
252 api->check_reply = &block_plugin_template_check_reply;
176 api->create_group = &block_plugin_template_create_group; 253 api->create_group = &block_plugin_template_create_group;
177 api->types = types; 254 api->types = types;
178 return api; 255 return api;
diff --git a/src/block/plugin_block_test.c b/src/block/plugin_block_test.c
index 45d54d339..fd643c4dc 100644
--- a/src/block/plugin_block_test.c
+++ b/src/block/plugin_block_test.c
@@ -143,6 +143,108 @@ block_plugin_test_evaluate (void *cls,
143 143
144 144
145/** 145/**
146 * Function called to validate a query.
147 *
148 * @param cls closure
149 * @param ctx block context
150 * @param type block type
151 * @param query original query (hash)
152 * @param xquery extrended query data (can be NULL, depending on type)
153 * @param xquery_size number of bytes in @a xquery
154 * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not
155 */
156static enum GNUNET_GenericReturnValue
157block_plugin_test_check_query (void *cls,
158 enum GNUNET_BLOCK_Type type,
159 const struct GNUNET_HashCode *query,
160 const void *xquery,
161 size_t xquery_size)
162{
163 if (GNUNET_BLOCK_TYPE_TEST != type)
164 {
165 GNUNET_break (0);
166 return GNUNET_SYSERR;
167 }
168 if (0 != xquery_size)
169 {
170 GNUNET_break_op (0);
171 return GNUNET_SYSERR;
172 }
173 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
174}
175
176
177/**
178 * Function called to validate a block for storage.
179 *
180 * @param cls closure
181 * @param type block type
182 * @param query key for the block (hash), must match exactly
183 * @param block block data to validate
184 * @param block_size number of bytes in @a block
185 * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not
186 */
187static enum GNUNET_GenericReturnValue
188block_plugin_test_check_block (void *cls,
189 enum GNUNET_BLOCK_Type type,
190 const struct GNUNET_HashCode *query,
191 const void *block,
192 size_t block_size)
193{
194 if (GNUNET_BLOCK_TYPE_TEST != type)
195 {
196 GNUNET_break (0);
197 return GNUNET_SYSERR;
198 }
199 return GNUNET_OK;
200}
201
202
203/**
204 * Function called to validate a reply to a request. Note that it is assumed
205 * that the reply has already been matched to the key (and signatures checked)
206 * as it would be done with the GetKeyFunction and the
207 * BlockEvaluationFunction.
208 *
209 * @param cls closure
210 * @param type block type
211 * @param group which block group to use for evaluation
212 * @param query original query (hash)
213 * @param xquery extrended query data (can be NULL, depending on type)
214 * @param xquery_size number of bytes in @a xquery
215 * @param reply_block response to validate
216 * @param reply_block_size number of bytes in @a reply_block
217 * @return characterization of result
218 */
219static enum GNUNET_BLOCK_ReplyEvaluationResult
220block_plugin_test_check_reply (void *cls,
221 enum GNUNET_BLOCK_Type type,
222 struct GNUNET_BLOCK_Group *group,
223 const struct GNUNET_HashCode *query,
224 const void *xquery,
225 size_t xquery_size,
226 const void *reply_block,
227 size_t reply_block_size)
228{
229 struct GNUNET_HashCode chash;
230
231 if (GNUNET_BLOCK_TYPE_TEST != type)
232 {
233 GNUNET_break (0);
234 return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED;
235 }
236 GNUNET_CRYPTO_hash (reply_block,
237 reply_block_size,
238 &chash);
239 if (GNUNET_YES ==
240 GNUNET_BLOCK_GROUP_bf_test_and_set (group,
241 &chash))
242 return GNUNET_BLOCK_REPLY_OK_DUPLICATE;
243 return GNUNET_BLOCK_REPLY_OK_MORE;
244}
245
246
247/**
146 * Function called to obtain the key for a block. 248 * Function called to obtain the key for a block.
147 * 249 *
148 * @param cls closure 250 * @param cls closure
@@ -153,7 +255,7 @@ block_plugin_test_evaluate (void *cls,
153 * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported 255 * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported
154 * (or if extracting a key from a block of this type does not work) 256 * (or if extracting a key from a block of this type does not work)
155 */ 257 */
156static int 258static enum GNUNET_GenericReturnValue
157block_plugin_test_get_key (void *cls, 259block_plugin_test_get_key (void *cls,
158 enum GNUNET_BLOCK_Type type, 260 enum GNUNET_BLOCK_Type type,
159 const void *block, 261 const void *block,
@@ -175,7 +277,7 @@ block_plugin_test_get_key (void *cls,
175void * 277void *
176libgnunet_plugin_block_test_init (void *cls) 278libgnunet_plugin_block_test_init (void *cls)
177{ 279{
178 static enum GNUNET_BLOCK_Type types[] = { 280 static const enum GNUNET_BLOCK_Type types[] = {
179 GNUNET_BLOCK_TYPE_TEST, 281 GNUNET_BLOCK_TYPE_TEST,
180 GNUNET_BLOCK_TYPE_ANY /* end of list */ 282 GNUNET_BLOCK_TYPE_ANY /* end of list */
181 }; 283 };
@@ -184,6 +286,9 @@ libgnunet_plugin_block_test_init (void *cls)
184 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); 286 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
185 api->evaluate = &block_plugin_test_evaluate; 287 api->evaluate = &block_plugin_test_evaluate;
186 api->get_key = &block_plugin_test_get_key; 288 api->get_key = &block_plugin_test_get_key;
289 api->check_query = &block_plugin_test_check_query;
290 api->check_block = &block_plugin_test_check_block;
291 api->check_reply = &block_plugin_test_check_reply;
187 api->create_group = &block_plugin_test_create_group; 292 api->create_group = &block_plugin_test_create_group;
188 api->types = types; 293 api->types = types;
189 return api; 294 return api;