aboutsummaryrefslogtreecommitdiff
path: root/src/dht
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-01-12 20:42:34 +0100
committerChristian Grothoff <christian@grothoff.org>2022-02-19 12:39:55 +0100
commitac77d5f4341e25eda4f12ef050a97c7794e034ca (patch)
tree7ede916d0a7fa8c05787a95179456e8958f19c1f /src/dht
parentaf252f5c3d4e62f4db39bbc65f3eea4f853d04bc (diff)
downloadgnunet-ac77d5f4341e25eda4f12ef050a97c7794e034ca.tar.gz
gnunet-ac77d5f4341e25eda4f12ef050a97c7794e034ca.zip
add new HELLO_URI block support to block plugin
Diffstat (limited to 'src/dht')
-rw-r--r--src/dht/plugin_block_dht.c77
1 files changed, 75 insertions, 2 deletions
diff --git a/src/dht/plugin_block_dht.c b/src/dht/plugin_block_dht.c
index a6a2104ce..0dbe21af9 100644
--- a/src/dht/plugin_block_dht.c
+++ b/src/dht/plugin_block_dht.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 GNUnet e.V. 3 Copyright (C) 2010, 2017, 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
@@ -28,6 +28,7 @@
28#include "platform.h" 28#include "platform.h"
29#include "gnunet_constants.h" 29#include "gnunet_constants.h"
30#include "gnunet_hello_lib.h" 30#include "gnunet_hello_lib.h"
31#include "gnunet_hello_uri_lib.h"
31#include "gnunet_block_plugin.h" 32#include "gnunet_block_plugin.h"
32#include "gnunet_block_group_lib.h" 33#include "gnunet_block_group_lib.h"
33 34
@@ -158,6 +159,8 @@ block_plugin_dht_evaluate (void *cls,
158 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; 159 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
159 return GNUNET_BLOCK_EVALUATION_OK_MORE; 160 return GNUNET_BLOCK_EVALUATION_OK_MORE;
160 } 161 }
162 case GNUNET_BLOCK_TYPE_DHT_URL_HELLO:
163 GNUNET_break (0); // legacy API not implemented
161 default: 164 default:
162 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; 165 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
163 } 166 }
@@ -191,6 +194,13 @@ block_plugin_dht_check_query (void *cls,
191 return GNUNET_NO; 194 return GNUNET_NO;
192 } 195 }
193 return GNUNET_OK; 196 return GNUNET_OK;
197 case GNUNET_BLOCK_TYPE_DHT_URL_HELLO:
198 if (0 != xquery_size)
199 {
200 GNUNET_break_op (0);
201 return GNUNET_NO;
202 }
203 return GNUNET_OK;
194 default: 204 default:
195 return GNUNET_SYSERR; 205 return GNUNET_SYSERR;
196 } 206 }
@@ -243,6 +253,35 @@ block_plugin_dht_check_block (void *cls,
243 } 253 }
244 return GNUNET_OK; 254 return GNUNET_OK;
245 } 255 }
256 case GNUNET_BLOCK_TYPE_DHT_URL_HELLO:
257 {
258 struct GNUNET_HELLO_Builder *b;
259 struct GNUNET_PeerIdentity pid;
260 struct GNUNET_HashCode h_pid;
261
262 b = GNUNET_HELLO_builder_from_block (block,
263 block_size);
264 if (NULL == b)
265 {
266 GNUNET_break (0);
267 return GNUNET_NO;
268 }
269 GNUNET_HELLO_builder_iterate (b,
270 &pid,
271 NULL, NULL);
272 GNUNET_CRYPTO_hash (&pid,
273 sizeof (pid),
274 &h_pid);
275 GNUNET_HELLO_builder_free (b);
276 if (0 !=
277 GNUNET_memcmp (&h_pid,
278 query))
279 {
280 GNUNET_break_op (0);
281 return GNUNET_NO;
282 }
283 return GNUNET_OK;
284 }
246 default: 285 default:
247 return GNUNET_SYSERR; 286 return GNUNET_SYSERR;
248 } 287 }
@@ -313,6 +352,19 @@ block_plugin_dht_check_reply (
313 return GNUNET_BLOCK_REPLY_OK_DUPLICATE; 352 return GNUNET_BLOCK_REPLY_OK_DUPLICATE;
314 return GNUNET_BLOCK_REPLY_OK_MORE; 353 return GNUNET_BLOCK_REPLY_OK_MORE;
315 } 354 }
355 case GNUNET_BLOCK_TYPE_DHT_URL_HELLO:
356 {
357 struct GNUNET_HashCode phash;
358
359 GNUNET_CRYPTO_hash (reply_block,
360 reply_block_size,
361 &phash);
362 if (GNUNET_YES ==
363 GNUNET_BLOCK_GROUP_bf_test_and_set (group,
364 &phash))
365 return GNUNET_BLOCK_REPLY_OK_DUPLICATE;
366 return GNUNET_BLOCK_REPLY_OK_MORE;
367 }
316 default: 368 default:
317 return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED; 369 return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED;
318 } 370 }
@@ -375,6 +427,27 @@ block_plugin_dht_get_key (void *cls,
375 } 427 }
376 return GNUNET_OK; 428 return GNUNET_OK;
377 } 429 }
430 case GNUNET_BLOCK_TYPE_DHT_URL_HELLO:
431 {
432 struct GNUNET_HELLO_Builder *b;
433 struct GNUNET_PeerIdentity pid;
434
435 b = GNUNET_HELLO_builder_from_block (block,
436 block_size);
437 if (NULL == b)
438 {
439 GNUNET_break (0);
440 return GNUNET_NO;
441 }
442 GNUNET_HELLO_builder_iterate (b,
443 &pid,
444 NULL, NULL);
445 GNUNET_CRYPTO_hash (&pid,
446 sizeof (pid),
447 key);
448 GNUNET_HELLO_builder_free (b);
449 return GNUNET_OK;
450 }
378 default: 451 default:
379 return GNUNET_SYSERR; 452 return GNUNET_SYSERR;
380 } 453 }
@@ -389,7 +462,7 @@ libgnunet_plugin_block_dht_init (void *cls)
389{ 462{
390 static enum GNUNET_BLOCK_Type types[] = { 463 static enum GNUNET_BLOCK_Type types[] = {
391 GNUNET_BLOCK_TYPE_DHT_HELLO, 464 GNUNET_BLOCK_TYPE_DHT_HELLO,
392 // FIXME: add GNUNET_BLOCK_TYPE_DHT_URL_HELLO, 465 GNUNET_BLOCK_TYPE_DHT_URL_HELLO,
393 GNUNET_BLOCK_TYPE_ANY /* end of list */ 466 GNUNET_BLOCK_TYPE_ANY /* end of list */
394 }; 467 };
395 struct GNUNET_BLOCK_PluginFunctions *api; 468 struct GNUNET_BLOCK_PluginFunctions *api;