aboutsummaryrefslogtreecommitdiff
path: root/src/block
diff options
context:
space:
mode:
authorChristian Grothoff <grothoff@gnunet.org>2022-03-12 04:01:02 +0100
committerChristian Grothoff <grothoff@gnunet.org>2022-03-12 04:01:02 +0100
commitff992f47e6528b00937c3951b812f6938e1ee21a (patch)
tree96917d63e24d2cc02b0e09a4e1dc29987541ffe8 /src/block
parent06f6791f2d55ab3a1b4ca4c3ba9ed5c315f8d79b (diff)
downloadgnunet-ff992f47e6528b00937c3951b812f6938e1ee21a.tar.gz
gnunet-ff992f47e6528b00937c3951b812f6938e1ee21a.zip
revise block API to match latest DHT specs
Diffstat (limited to 'src/block')
-rw-r--r--src/block/block.c33
-rw-r--r--src/block/plugin_block_template.c82
-rw-r--r--src/block/plugin_block_test.c120
3 files changed, 59 insertions, 176 deletions
diff --git a/src/block/block.c b/src/block/block.c
index 5824946f7..2e3c1dc70 100644
--- a/src/block/block.c
+++ b/src/block/block.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2010, 2017, 2021 GNUnet e.V. 3 Copyright (C) 2010, 2017, 2021, 2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 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 6 under the terms of the GNU Affero General Public License as published
@@ -255,35 +255,6 @@ GNUNET_BLOCK_group_create (struct GNUNET_BLOCK_Context *ctx,
255} 255}
256 256
257 257
258enum GNUNET_BLOCK_EvaluationResult
259GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx,
260 enum GNUNET_BLOCK_Type type,
261 struct GNUNET_BLOCK_Group *group,
262 enum GNUNET_BLOCK_EvaluationOptions eo,
263 const struct GNUNET_HashCode *query,
264 const void *xquery,
265 size_t xquery_size,
266 const void *reply_block,
267 size_t reply_block_size)
268{
269 struct GNUNET_BLOCK_PluginFunctions *plugin = find_plugin (ctx,
270 type);
271
272 if (NULL == plugin)
273 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
274 return plugin->evaluate (plugin->cls,
275 ctx,
276 type,
277 group,
278 eo,
279 query,
280 xquery,
281 xquery_size,
282 reply_block,
283 reply_block_size);
284}
285
286
287enum GNUNET_GenericReturnValue 258enum GNUNET_GenericReturnValue
288GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx, 259GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx,
289 enum GNUNET_BLOCK_Type type, 260 enum GNUNET_BLOCK_Type type,
@@ -327,7 +298,6 @@ GNUNET_BLOCK_check_query (struct GNUNET_BLOCK_Context *ctx,
327enum GNUNET_GenericReturnValue 298enum GNUNET_GenericReturnValue
328GNUNET_BLOCK_check_block (struct GNUNET_BLOCK_Context *ctx, 299GNUNET_BLOCK_check_block (struct GNUNET_BLOCK_Context *ctx,
329 enum GNUNET_BLOCK_Type type, 300 enum GNUNET_BLOCK_Type type,
330 const struct GNUNET_HashCode *query,
331 const void *block, 301 const void *block,
332 size_t block_size) 302 size_t block_size)
333{ 303{
@@ -338,7 +308,6 @@ GNUNET_BLOCK_check_block (struct GNUNET_BLOCK_Context *ctx,
338 return GNUNET_SYSERR; 308 return GNUNET_SYSERR;
339 return plugin->check_block (plugin->cls, 309 return plugin->check_block (plugin->cls,
340 type, 310 type,
341 query,
342 block, 311 block,
343 block_size); 312 block_size);
344} 313}
diff --git a/src/block/plugin_block_template.c b/src/block/plugin_block_template.c
index 13d9adfda..dcaf1afaa 100644
--- a/src/block/plugin_block_template.c
+++ b/src/block/plugin_block_template.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2010 GNUnet e.V. 3 Copyright (C) 2010, 2021, 2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 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 6 under the terms of the GNU Affero General Public License as published
@@ -92,49 +92,6 @@ block_plugin_template_create_group (void *cls,
92 92
93 93
94/** 94/**
95 * Function called to validate a reply or a request. For
96 * request evaluation, simply pass "NULL" for the reply_block.
97 *
98 * @param cls closure
99 * @param ctx context
100 * @param type block type
101 * @param group block group to use
102 * @param eo control flags
103 * @param query original query (hash)
104 * @param xquery extrended query data (can be NULL, depending on type)
105 * @param xquery_size number of bytes in xquery
106 * @param reply_block response to validate
107 * @param reply_block_size number of bytes in reply block
108 * @return characterization of result
109 */
110static enum GNUNET_BLOCK_EvaluationResult
111block_plugin_template_evaluate (void *cls,
112 struct GNUNET_BLOCK_Context *ctx,
113 enum GNUNET_BLOCK_Type type,
114 struct GNUNET_BLOCK_Group *group,
115 enum GNUNET_BLOCK_EvaluationOptions eo,
116 const struct GNUNET_HashCode *query,
117 const void *xquery,
118 size_t xquery_size,
119 const void *reply_block,
120 size_t reply_block_size)
121{
122 struct GNUNET_HashCode chash;
123
124 if (NULL == reply_block)
125 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
126 GNUNET_CRYPTO_hash (reply_block,
127 reply_block_size,
128 &chash);
129 if (GNUNET_YES ==
130 GNUNET_BLOCK_GROUP_bf_test_and_set (group,
131 &chash))
132 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
133 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
134}
135
136
137/**
138 * Function called to validate a query. 95 * Function called to validate a query.
139 * 96 *
140 * @param cls closure 97 * @param cls closure
@@ -143,16 +100,16 @@ block_plugin_template_evaluate (void *cls,
143 * @param query original query (hash) 100 * @param query original query (hash)
144 * @param xquery extrended query data (can be NULL, depending on type) 101 * @param xquery extrended query data (can be NULL, depending on type)
145 * @param xquery_size number of bytes in @a xquery 102 * @param xquery_size number of bytes in @a xquery
146 * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not 103 * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not, #GNUNET_SYSERR if not supported
147 */ 104 */
148static enum GNUNET_GenericReturnValue 105static enum GNUNET_GenericReturnValue
149block_plugin_template_check_query (void *cls, 106block_plugin_template_check_query (void *cls,
150 enum GNUNET_BLOCK_Type type, 107 enum GNUNET_BLOCK_Type type,
151 const struct GNUNET_HashCode *query, 108 const struct GNUNET_HashCode *query,
152 const void *xquery, 109 const void *xquery,
153 size_t xquery_size) 110 size_t xquery_size)
154{ 111{
155 return GNUNET_OK; 112 return GNUNET_SYSERR;
156} 113}
157 114
158 115
@@ -161,19 +118,17 @@ block_plugin_template_check_query (void *cls,
161 * 118 *
162 * @param cls closure 119 * @param cls closure
163 * @param type block type 120 * @param type block type
164 * @param query key for the block (hash), must match exactly
165 * @param block block data to validate 121 * @param block block data to validate
166 * @param block_size number of bytes in @a block 122 * @param block_size number of bytes in @a block
167 * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not 123 * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not, #GNUNET_SYSERR if not supported
168 */ 124 */
169static enum GNUNET_GenericReturnValue 125static enum GNUNET_GenericReturnValue
170block_plugin_template_check_block (void *cls, 126block_plugin_template_check_block (void *cls,
171 enum GNUNET_BLOCK_Type type, 127 enum GNUNET_BLOCK_Type type,
172 const struct GNUNET_HashCode *query,
173 const void *block, 128 const void *block,
174 size_t block_size) 129 size_t block_size)
175{ 130{
176 return GNUNET_OK; 131 return GNUNET_SYSERR;
177} 132}
178 133
179 134
@@ -195,16 +150,16 @@ block_plugin_template_check_block (void *cls,
195 */ 150 */
196static enum GNUNET_BLOCK_ReplyEvaluationResult 151static enum GNUNET_BLOCK_ReplyEvaluationResult
197block_plugin_template_check_reply ( 152block_plugin_template_check_reply (
198 void *cls, 153 void *cls,
199 enum GNUNET_BLOCK_Type type, 154 enum GNUNET_BLOCK_Type type,
200 struct GNUNET_BLOCK_Group *group, 155 struct GNUNET_BLOCK_Group *group,
201 const struct GNUNET_HashCode *query, 156 const struct GNUNET_HashCode *query,
202 const void *xquery, 157 const void *xquery,
203 size_t xquery_size, 158 size_t xquery_size,
204 const void *reply_block, 159 const void *reply_block,
205 size_t reply_block_size) 160 size_t reply_block_size)
206{ 161{
207 return GNUNET_BLOCK_REPLY_OK_MORE; 162 return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED;
208} 163}
209 164
210 165
@@ -245,7 +200,6 @@ libgnunet_plugin_block_template_init (void *cls)
245 struct GNUNET_BLOCK_PluginFunctions *api; 200 struct GNUNET_BLOCK_PluginFunctions *api;
246 201
247 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); 202 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
248 api->evaluate = &block_plugin_template_evaluate;
249 api->get_key = &block_plugin_template_get_key; 203 api->get_key = &block_plugin_template_get_key;
250 api->check_query = &block_plugin_template_check_query; 204 api->check_query = &block_plugin_template_check_query;
251 api->check_block = &block_plugin_template_check_block; 205 api->check_block = &block_plugin_template_check_block;
diff --git a/src/block/plugin_block_test.c b/src/block/plugin_block_test.c
index fd643c4dc..05d379387 100644
--- a/src/block/plugin_block_test.c
+++ b/src/block/plugin_block_test.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2010 GNUnet e.V. 3 Copyright (C) 2010, 2021, 2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 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 6 under the terms of the GNU Affero General Public License as published
@@ -90,59 +90,6 @@ block_plugin_test_create_group (void *cls,
90 90
91 91
92/** 92/**
93 * Function called to validate a reply or a request. For
94 * request evaluation, simply pass "NULL" for the reply_block.
95 *
96 * @param cls closure
97 * @param ctx block context
98 * @param type block type
99 * @param group group to check against
100 * @param eo control flags
101 * @param query original query (hash)
102 * @param xquery extrended query data (can be NULL, depending on type)
103 * @param xquery_size number of bytes in @a xquery
104 * @param reply_block response to validate
105 * @param reply_block_size number of bytes in @a reply_block
106 * @return characterization of result
107 */
108static enum GNUNET_BLOCK_EvaluationResult
109block_plugin_test_evaluate (void *cls,
110 struct GNUNET_BLOCK_Context *ctx,
111 enum GNUNET_BLOCK_Type type,
112 struct GNUNET_BLOCK_Group *group,
113 enum GNUNET_BLOCK_EvaluationOptions eo,
114 const struct GNUNET_HashCode *query,
115 const void *xquery,
116 size_t xquery_size,
117 const void *reply_block,
118 size_t reply_block_size)
119{
120 struct GNUNET_HashCode chash;
121
122 if (GNUNET_BLOCK_TYPE_TEST != type)
123 {
124 GNUNET_break (0);
125 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
126 }
127 if (0 != xquery_size)
128 {
129 GNUNET_break_op (0);
130 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
131 }
132 if (NULL == reply_block)
133 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
134 GNUNET_CRYPTO_hash (reply_block,
135 reply_block_size,
136 &chash);
137 if (GNUNET_YES ==
138 GNUNET_BLOCK_GROUP_bf_test_and_set (group,
139 &chash))
140 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
141 return GNUNET_BLOCK_EVALUATION_OK_MORE;
142}
143
144
145/**
146 * Function called to validate a query. 93 * Function called to validate a query.
147 * 94 *
148 * @param cls closure 95 * @param cls closure
@@ -151,15 +98,18 @@ block_plugin_test_evaluate (void *cls,
151 * @param query original query (hash) 98 * @param query original query (hash)
152 * @param xquery extrended query data (can be NULL, depending on type) 99 * @param xquery extrended query data (can be NULL, depending on type)
153 * @param xquery_size number of bytes in @a xquery 100 * @param xquery_size number of bytes in @a xquery
154 * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not 101 * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not, #GNUNET_SYSERR if @a type is not supported
155 */ 102 */
156static enum GNUNET_GenericReturnValue 103static enum GNUNET_GenericReturnValue
157block_plugin_test_check_query (void *cls, 104block_plugin_test_check_query (void *cls,
158 enum GNUNET_BLOCK_Type type, 105 enum GNUNET_BLOCK_Type type,
159 const struct GNUNET_HashCode *query, 106 const struct GNUNET_HashCode *query,
160 const void *xquery, 107 const void *xquery,
161 size_t xquery_size) 108 size_t xquery_size)
162{ 109{
110 (void) cls;
111 (void) query;
112 (void) xquery;
163 if (GNUNET_BLOCK_TYPE_TEST != type) 113 if (GNUNET_BLOCK_TYPE_TEST != type)
164 { 114 {
165 GNUNET_break (0); 115 GNUNET_break (0);
@@ -168,9 +118,9 @@ block_plugin_test_check_query (void *cls,
168 if (0 != xquery_size) 118 if (0 != xquery_size)
169 { 119 {
170 GNUNET_break_op (0); 120 GNUNET_break_op (0);
171 return GNUNET_SYSERR; 121 return GNUNET_NO;
172 } 122 }
173 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; 123 return GNUNET_OK;
174} 124}
175 125
176 126
@@ -179,18 +129,19 @@ block_plugin_test_check_query (void *cls,
179 * 129 *
180 * @param cls closure 130 * @param cls closure
181 * @param type block type 131 * @param type block type
182 * @param query key for the block (hash), must match exactly
183 * @param block block data to validate 132 * @param block block data to validate
184 * @param block_size number of bytes in @a block 133 * @param block_size number of bytes in @a block
185 * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not 134 * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not, #GNUNET_SYSERR if @a type is not supported
186 */ 135 */
187static enum GNUNET_GenericReturnValue 136static enum GNUNET_GenericReturnValue
188block_plugin_test_check_block (void *cls, 137block_plugin_test_check_block (void *cls,
189 enum GNUNET_BLOCK_Type type, 138 enum GNUNET_BLOCK_Type type,
190 const struct GNUNET_HashCode *query, 139 const void *block,
191 const void *block, 140 size_t block_size)
192 size_t block_size)
193{ 141{
142 (void) cls;
143 (void) block;
144 (void) block_size;
194 if (GNUNET_BLOCK_TYPE_TEST != type) 145 if (GNUNET_BLOCK_TYPE_TEST != type)
195 { 146 {
196 GNUNET_break (0); 147 GNUNET_break (0);
@@ -218,16 +169,20 @@ block_plugin_test_check_block (void *cls,
218 */ 169 */
219static enum GNUNET_BLOCK_ReplyEvaluationResult 170static enum GNUNET_BLOCK_ReplyEvaluationResult
220block_plugin_test_check_reply (void *cls, 171block_plugin_test_check_reply (void *cls,
221 enum GNUNET_BLOCK_Type type, 172 enum GNUNET_BLOCK_Type type,
222 struct GNUNET_BLOCK_Group *group, 173 struct GNUNET_BLOCK_Group *group,
223 const struct GNUNET_HashCode *query, 174 const struct GNUNET_HashCode *query,
224 const void *xquery, 175 const void *xquery,
225 size_t xquery_size, 176 size_t xquery_size,
226 const void *reply_block, 177 const void *reply_block,
227 size_t reply_block_size) 178 size_t reply_block_size)
228{ 179{
229 struct GNUNET_HashCode chash; 180 struct GNUNET_HashCode chash;
230 181
182 (void) cls;
183 (void) query;
184 (void) xquery;
185 (void) xquery_size;
231 if (GNUNET_BLOCK_TYPE_TEST != type) 186 if (GNUNET_BLOCK_TYPE_TEST != type)
232 { 187 {
233 GNUNET_break (0); 188 GNUNET_break (0);
@@ -252,8 +207,7 @@ block_plugin_test_check_reply (void *cls,
252 * @param block block to get the key for 207 * @param block block to get the key for
253 * @param block_size number of bytes in @a block 208 * @param block_size number of bytes in @a block
254 * @param key set to the key (query) for the given block 209 * @param key set to the key (query) for the given block
255 * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported 210 * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported, #GNUNET_NO 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)
257 */ 211 */
258static enum GNUNET_GenericReturnValue 212static enum GNUNET_GenericReturnValue
259block_plugin_test_get_key (void *cls, 213block_plugin_test_get_key (void *cls,
@@ -262,9 +216,16 @@ block_plugin_test_get_key (void *cls,
262 size_t block_size, 216 size_t block_size,
263 struct GNUNET_HashCode *key) 217 struct GNUNET_HashCode *key)
264{ 218{
265 /* always fails since there is no fixed relationship between 219 (void) cls;
266 * keys and values for test values */ 220 (void) block;
267 return GNUNET_SYSERR; 221 (void) block_size;
222 (void) key;
223 if (GNUNET_BLOCK_TYPE_TEST != type)
224 {
225 GNUNET_break (0);
226 return GNUNET_SYSERR;
227 }
228 return GNUNET_NO;
268} 229}
269 230
270 231
@@ -284,7 +245,6 @@ libgnunet_plugin_block_test_init (void *cls)
284 struct GNUNET_BLOCK_PluginFunctions *api; 245 struct GNUNET_BLOCK_PluginFunctions *api;
285 246
286 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); 247 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
287 api->evaluate = &block_plugin_test_evaluate;
288 api->get_key = &block_plugin_test_get_key; 248 api->get_key = &block_plugin_test_get_key;
289 api->check_query = &block_plugin_test_check_query; 249 api->check_query = &block_plugin_test_check_query;
290 api->check_block = &block_plugin_test_check_block; 250 api->check_block = &block_plugin_test_check_block;