aboutsummaryrefslogtreecommitdiff
path: root/src/dht/gnunet-service-dht.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-01-15 19:24:33 +0100
committerChristian Grothoff <christian@grothoff.org>2022-02-19 12:39:55 +0100
commitb0abdf7127f2403ff583d224e0d9d4e68c1c5bfc (patch)
tree47df762cdbcce501ec5536c8963b5c9ee55da31d /src/dht/gnunet-service-dht.c
parent3a71153405e8fc26712807b4bdb5987fb3bf2b9e (diff)
downloadgnunet-b0abdf7127f2403ff583d224e0d9d4e68c1c5bfc.tar.gz
gnunet-b0abdf7127f2403ff583d224e0d9d4e68c1c5bfc.zip
-more work on DHTU integration
Diffstat (limited to 'src/dht/gnunet-service-dht.c')
-rw-r--r--src/dht/gnunet-service-dht.c149
1 files changed, 128 insertions, 21 deletions
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c
index 6f2573d26..35e219926 100644
--- a/src/dht/gnunet-service-dht.c
+++ b/src/dht/gnunet-service-dht.c
@@ -28,14 +28,20 @@
28#include "gnunet_block_lib.h" 28#include "gnunet_block_lib.h"
29#include "gnunet_util_lib.h" 29#include "gnunet_util_lib.h"
30#include "gnunet_hello_lib.h" 30#include "gnunet_hello_lib.h"
31#include "gnunet_hello_uri_lib.h"
31#include "gnunet_dht_service.h" 32#include "gnunet_dht_service.h"
32#include "gnunet_statistics_service.h" 33#include "gnunet_statistics_service.h"
33#include "gnunet-service-dht.h" 34#include "gnunet-service-dht.h"
34#include "gnunet-service-dht_datacache.h" 35#include "gnunet-service-dht_datacache.h"
35#include "gnunet-service-dht_hello.h"
36#include "gnunet-service-dht_neighbours.h" 36#include "gnunet-service-dht_neighbours.h"
37#include "gnunet-service-dht_routing.h" 37#include "gnunet-service-dht_routing.h"
38 38
39/**
40 * How often do we broadcast our HELLO to neighbours if
41 * nothing special happens?
42 */
43#define HELLO_FREQUENCY GNUNET_TIME_UNIT_HOURS
44
39 45
40/** 46/**
41 * Information we keep per underlay. 47 * Information we keep per underlay.
@@ -110,7 +116,27 @@ struct MyAddress
110/** 116/**
111 * Our HELLO 117 * Our HELLO
112 */ 118 */
113struct GNUNET_MessageHeader *GDS_my_hello; 119struct GNUNET_HELLO_Builder *GDS_my_hello;
120
121/**
122 * Identity of this peer.
123 */
124struct GNUNET_PeerIdentity GDS_my_identity;
125
126/**
127 * Hash of the identity of this peer.
128 */
129struct GNUNET_HashCode GDS_my_identity_hash;
130
131/**
132 * Our private key.
133 */
134struct GNUNET_CRYPTO_EddsaPrivateKey GDS_my_private_key;
135
136/**
137 * Task broadcasting our HELLO.
138 */
139static struct GNUNET_SCHEDULER_Task *hello_task;
114 140
115/** 141/**
116 * Handles for the DHT underlays. 142 * Handles for the DHT underlays.
@@ -133,11 +159,6 @@ static struct MyAddress *a_head;
133static struct MyAddress *a_tail; 159static struct MyAddress *a_tail;
134 160
135/** 161/**
136 * Hello address expiration
137 */
138struct GNUNET_TIME_Relative hello_expiration;
139
140/**
141 * log of the current network size estimate, used as the point where 162 * log of the current network size estimate, used as the point where
142 * we switch between random and deterministic routing. 163 * we switch between random and deterministic routing.
143 */ 164 */
@@ -195,13 +216,29 @@ GDS_NSE_get (void)
195 216
196 217
197/** 218/**
198 * Update our HELLO with all of our our addresses. 219 * Task run periodically to broadcast our HELLO.
220 *
221 * @param cls NULL
199 */ 222 */
200static void 223static void
201update_hello (void) 224broadcast_hello (void *cls)
202{ 225{
203 GNUNET_free (GDS_my_hello); 226 struct GNUNET_MessageHeader *hello;
204 // FIXME: build new HELLO properly! 227
228 (void) cls;
229 /* TODO: randomize! */
230 hello_task = GNUNET_SCHEDULER_add_delayed (HELLO_FREQUENCY,
231 &broadcast_hello,
232 NULL);
233 hello = GNUNET_HELLO_builder_to_dht_hello_msg (GDS_my_hello,
234 &GDS_my_private_key);
235 if (NULL == hello)
236 {
237 GNUNET_break (0);
238 return;
239 }
240 GDS_NEIGHBOURS_broadcast (hello);
241 GNUNET_free (hello);
205} 242}
206 243
207 244
@@ -231,7 +268,12 @@ u_address_add (void *cls,
231 a_tail, 268 a_tail,
232 a); 269 a);
233 *ctx = a; 270 *ctx = a;
234 update_hello (); 271 GNUNET_HELLO_builder_add_address (GDS_my_hello,
272 address);
273 if (NULL != hello_task)
274 GNUNET_SCHEDULER_cancel (hello_task);
275 hello_task = GNUNET_SCHEDULER_add_now (&broadcast_hello,
276 NULL);
235} 277}
236 278
237 279
@@ -245,12 +287,47 @@ u_address_del (void *ctx)
245{ 287{
246 struct MyAddress *a = ctx; 288 struct MyAddress *a = ctx;
247 289
290 GNUNET_HELLO_builder_del_address (GDS_my_hello,
291 a->url);
248 GNUNET_CONTAINER_DLL_remove (a_head, 292 GNUNET_CONTAINER_DLL_remove (a_head,
249 a_tail, 293 a_tail,
250 a); 294 a);
251 GNUNET_free (a->url); 295 GNUNET_free (a->url);
252 GNUNET_free (a); 296 GNUNET_free (a);
253 update_hello (); 297 if (NULL != hello_task)
298 GNUNET_SCHEDULER_cancel (hello_task);
299 hello_task = GNUNET_SCHEDULER_add_now (&broadcast_hello,
300 NULL);
301}
302
303
304void
305GDS_u_try_connect (const struct GNUNET_PeerIdentity *pid,
306 const char *address)
307{
308 for (struct Underlay *u = u_head;
309 NULL != u;
310 u = u->next)
311 u->dhtu->try_connect (u->dhtu->cls,
312 pid,
313 address);
314}
315
316
317void
318GDS_u_send (struct Underlay *u,
319 struct GNUNET_DHTU_Target *target,
320 const void *msg,
321 size_t msg_size,
322 GNUNET_SCHEDULER_TaskCallback finished_cb,
323 void *finished_cb_cls)
324{
325 u->dhtu->send (u->dhtu->cls,
326 target,
327 msg,
328 msg_size,
329 finished_cb,
330 finished_cb_cls);
254} 331}
255 332
256 333
@@ -265,7 +342,6 @@ shutdown_task (void *cls)
265 GDS_NEIGHBOURS_done (); 342 GDS_NEIGHBOURS_done ();
266 GDS_DATACACHE_done (); 343 GDS_DATACACHE_done ();
267 GDS_ROUTING_done (); 344 GDS_ROUTING_done ();
268 GDS_HELLO_done ();
269 if (NULL != GDS_block_context) 345 if (NULL != GDS_block_context)
270 { 346 {
271 GNUNET_BLOCK_context_destroy (GDS_block_context); 347 GNUNET_BLOCK_context_destroy (GDS_block_context);
@@ -277,7 +353,7 @@ shutdown_task (void *cls)
277 GNUNET_YES); 353 GNUNET_YES);
278 GDS_stats = NULL; 354 GDS_stats = NULL;
279 } 355 }
280 GNUNET_free (GDS_my_hello); 356 GNUNET_HELLO_builder_free (GDS_my_hello);
281 GDS_my_hello = NULL; 357 GDS_my_hello = NULL;
282 GDS_CLIENTS_stop (); 358 GDS_CLIENTS_stop ();
283} 359}
@@ -348,14 +424,39 @@ run (void *cls,
348{ 424{
349 GDS_cfg = c; 425 GDS_cfg = c;
350 GDS_service = service; 426 GDS_service = service;
351 if (GNUNET_OK !=
352 GNUNET_CONFIGURATION_get_value_time (c,
353 "transport",
354 "HELLO_EXPIRATION",
355 &hello_expiration))
356 { 427 {
357 hello_expiration = GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION; 428 char *keyfile;
429
430 if (GNUNET_OK !=
431 GNUNET_CONFIGURATION_get_value_filename (GDS_cfg,
432 "PEER",
433 "PRIVATE_KEY",
434 &keyfile))
435 {
436 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
437 "PEER",
438 "PRIVATE_KEY");
439 GNUNET_SCHEDULER_shutdown ();
440 return;
441 }
442 if (GNUNET_SYSERR ==
443 GNUNET_CRYPTO_eddsa_key_from_file (keyfile,
444 GNUNET_YES,
445 &GDS_my_private_key))
446 {
447 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
448 "Failed to setup peer's private key\n");
449 GNUNET_free (keyfile);
450 GNUNET_SCHEDULER_shutdown ();
451 return;
452 }
453 GNUNET_free (keyfile);
358 } 454 }
455 GNUNET_CRYPTO_eddsa_key_get_public (&GDS_my_private_key,
456 &GDS_my_identity.public_key);
457 GNUNET_CRYPTO_hash (&GDS_my_identity,
458 sizeof(struct GNUNET_PeerIdentity),
459 &GDS_my_identity_hash);
359 GDS_block_context = GNUNET_BLOCK_context_create (GDS_cfg); 460 GDS_block_context = GNUNET_BLOCK_context_create (GDS_cfg);
360 GDS_stats = GNUNET_STATISTICS_create ("dht", 461 GDS_stats = GNUNET_STATISTICS_create ("dht",
361 GDS_cfg); 462 GDS_cfg);
@@ -364,6 +465,12 @@ run (void *cls,
364 GDS_DATACACHE_init (); 465 GDS_DATACACHE_init ();
365 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 466 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
366 NULL); 467 NULL);
468 if (GNUNET_OK !=
469 GDS_NEIGHBOURS_init ())
470 {
471 GNUNET_SCHEDULER_shutdown ();
472 return;
473 }
367 GNUNET_CONFIGURATION_iterate_sections (GDS_cfg, 474 GNUNET_CONFIGURATION_iterate_sections (GDS_cfg,
368 &load_underlay, 475 &load_underlay,
369 NULL); 476 NULL);