aboutsummaryrefslogtreecommitdiff
path: root/src/dht
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/dht
parentfd620976c140d5df43cf174a54a9f88c4808cad3 (diff)
downloadgnunet-c0b6f577cb6866a8bfce22acbcec6983d5f610f6.tar.gz
gnunet-c0b6f577cb6866a8bfce22acbcec6983d5f610f6.zip
-updating block plugins to new API
Diffstat (limited to 'src/dht')
-rw-r--r--src/dht/plugin_block_dht.c144
1 files changed, 143 insertions, 1 deletions
diff --git a/src/dht/plugin_block_dht.c b/src/dht/plugin_block_dht.c
index a9f336240..7c6fb9ed6 100644
--- a/src/dht/plugin_block_dht.c
+++ b/src/dht/plugin_block_dht.c
@@ -159,6 +159,145 @@ block_plugin_dht_evaluate (void *cls,
159 159
160 160
161/** 161/**
162 * Function called to validate a query.
163 *
164 * @param cls closure
165 * @param ctx block context
166 * @param type block type
167 * @param query original query (hash)
168 * @param xquery extrended query data (can be NULL, depending on type)
169 * @param xquery_size number of bytes in @a xquery
170 * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not
171 */
172static enum GNUNET_GenericReturnValue
173block_plugin_dht_check_query (void *cls,
174 enum GNUNET_BLOCK_Type type,
175 const struct GNUNET_HashCode *query,
176 const void *xquery,
177 size_t xquery_size)
178{
179 if (type != GNUNET_BLOCK_TYPE_DHT_HELLO)
180 return GNUNET_SYSERR;
181 if (0 != xquery_size)
182 {
183 GNUNET_break_op (0);
184 return GNUNET_NO;
185 }
186 return GNUNET_OK;
187}
188
189
190/**
191 * Function called to validate a block for storage.
192 *
193 * @param cls closure
194 * @param type block type
195 * @param query key for the block (hash), must match exactly
196 * @param block block data to validate
197 * @param block_size number of bytes in @a block
198 * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not
199 */
200static enum GNUNET_GenericReturnValue
201block_plugin_dht_check_block (void *cls,
202 enum GNUNET_BLOCK_Type type,
203 const struct GNUNET_HashCode *query,
204 const void *block,
205 size_t block_size)
206{
207 const struct GNUNET_HELLO_Message *hello;
208 struct GNUNET_PeerIdentity pid;
209 const struct GNUNET_MessageHeader *msg;
210
211 if (type != GNUNET_BLOCK_TYPE_DHT_HELLO)
212 return GNUNET_SYSERR;
213 if (block_size < sizeof(struct GNUNET_MessageHeader))
214 {
215 GNUNET_break_op (0);
216 return GNUNET_NO;
217 }
218 msg = block;
219 if (block_size != ntohs (msg->size))
220 {
221 GNUNET_break_op (0);
222 return GNUNET_NO;
223 }
224 hello = block;
225 if (GNUNET_OK !=
226 GNUNET_HELLO_get_id (hello,
227 &pid))
228 {
229 GNUNET_break_op (0);
230 return GNUNET_NO;
231 }
232 return GNUNET_OK;
233}
234
235
236/**
237 * Function called to validate a reply to a request. Note that it is assumed
238 * that the reply has already been matched to the key (and signatures checked)
239 * as it would be done with the GetKeyFunction and the
240 * BlockEvaluationFunction.
241 *
242 * @param cls closure
243 * @param type block type
244 * @param group which block group to use for evaluation
245 * @param query original query (hash)
246 * @param xquery extrended query data (can be NULL, depending on type)
247 * @param xquery_size number of bytes in @a xquery
248 * @param reply_block response to validate
249 * @param reply_block_size number of bytes in @a reply_block
250 * @return characterization of result
251 */
252static enum GNUNET_BLOCK_ReplyEvaluationResult
253block_plugin_dht_check_reply (
254 void *cls,
255 enum GNUNET_BLOCK_Type type,
256 struct GNUNET_BLOCK_Group *group,
257 const struct GNUNET_HashCode *query,
258 const void *xquery,
259 size_t xquery_size,
260 const void *reply_block,
261 size_t reply_block_size)
262{
263 const struct GNUNET_HELLO_Message *hello;
264 struct GNUNET_PeerIdentity pid;
265 const struct GNUNET_MessageHeader *msg;
266 struct GNUNET_HashCode phash;
267
268 if (type != GNUNET_BLOCK_TYPE_DHT_HELLO)
269 return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED;
270 if (reply_block_size < sizeof(struct GNUNET_MessageHeader))
271 {
272 GNUNET_break_op (0);
273 return GNUNET_BLOCK_REPLY_INVALID;
274 }
275 msg = reply_block;
276 if (reply_block_size != ntohs (msg->size))
277 {
278 GNUNET_break_op (0);
279 return GNUNET_BLOCK_REPLY_INVALID;
280 }
281 hello = reply_block;
282 if (GNUNET_OK !=
283 GNUNET_HELLO_get_id (hello,
284 &pid))
285 {
286 GNUNET_break_op (0);
287 return GNUNET_BLOCK_REPLY_INVALID;
288 }
289 GNUNET_CRYPTO_hash (&pid,
290 sizeof(pid),
291 &phash);
292 if (GNUNET_YES ==
293 GNUNET_BLOCK_GROUP_bf_test_and_set (group,
294 &phash))
295 return GNUNET_BLOCK_REPLY_OK_DUPLICATE;
296 return GNUNET_BLOCK_REPLY_OK_MORE;
297}
298
299
300/**
162 * Function called to obtain the key for a block. 301 * Function called to obtain the key for a block.
163 * 302 *
164 * @param cls closure 303 * @param cls closure
@@ -169,7 +308,7 @@ block_plugin_dht_evaluate (void *cls,
169 * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported 308 * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported
170 * (or if extracting a key from a block of this type does not work) 309 * (or if extracting a key from a block of this type does not work)
171 */ 310 */
172static int 311static enum GNUNET_GenericReturnValue
173block_plugin_dht_get_key (void *cls, 312block_plugin_dht_get_key (void *cls,
174 enum GNUNET_BLOCK_Type type, 313 enum GNUNET_BLOCK_Type type,
175 const void *block, 314 const void *block,
@@ -229,6 +368,9 @@ libgnunet_plugin_block_dht_init (void *cls)
229 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); 368 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
230 api->evaluate = &block_plugin_dht_evaluate; 369 api->evaluate = &block_plugin_dht_evaluate;
231 api->get_key = &block_plugin_dht_get_key; 370 api->get_key = &block_plugin_dht_get_key;
371 api->check_query = &block_plugin_dht_check_query;
372 api->check_block = &block_plugin_dht_check_block;
373 api->check_reply = &block_plugin_dht_check_reply;
232 api->create_group = &block_plugin_dht_create_group; 374 api->create_group = &block_plugin_dht_create_group;
233 api->types = types; 375 api->types = types;
234 return api; 376 return api;