diff options
author | Christian Grothoff <grothoff@gnunet.org> | 2021-09-22 08:49:48 +0200 |
---|---|---|
committer | Christian Grothoff <grothoff@gnunet.org> | 2021-09-22 08:49:48 +0200 |
commit | c221e30ea67751237058b6a5aa7b46e12fca5395 (patch) | |
tree | 0bfecab095d69ee4bdd0cac76692e9e72a1640d4 /src | |
parent | 33d31c58c1036acdef9f7d6cb3bb27881e6e26cb (diff) | |
download | gnunet-c221e30ea67751237058b6a5aa7b46e12fca5395.tar.gz gnunet-c221e30ea67751237058b6a5aa7b46e12fca5395.zip |
-work on dhtu
Diffstat (limited to 'src')
-rw-r--r-- | src/dhtu/Makefile.am | 1 | ||||
-rw-r--r-- | src/dhtu/plugin_dhtu_gnunet.c | 137 | ||||
-rw-r--r-- | src/include/gnunet_mq_lib.h | 18 | ||||
-rw-r--r-- | src/include/gnunet_protocols.h | 5 |
4 files changed, 154 insertions, 7 deletions
diff --git a/src/dhtu/Makefile.am b/src/dhtu/Makefile.am index f4b968526..601f31bf5 100644 --- a/src/dhtu/Makefile.am +++ b/src/dhtu/Makefile.am | |||
@@ -29,6 +29,7 @@ libgnunet_plugin_dhtu_gnunet_la_SOURCES = \ | |||
29 | plugin_dhtu_gnunet.c | 29 | plugin_dhtu_gnunet.c |
30 | libgnunet_plugin_dhtu_gnunet_la_LIBADD = \ | 30 | libgnunet_plugin_dhtu_gnunet_la_LIBADD = \ |
31 | $(top_builddir)/src/core/libgnunetcore.la \ | 31 | $(top_builddir)/src/core/libgnunetcore.la \ |
32 | $(top_builddir)/src/nse/libgnunetnse.la \ | ||
32 | $(top_builddir)/src/util/libgnunetutil.la \ | 33 | $(top_builddir)/src/util/libgnunetutil.la \ |
33 | $(XLIBS) \ | 34 | $(XLIBS) \ |
34 | $(LTLIBINTL) | 35 | $(LTLIBINTL) |
diff --git a/src/dhtu/plugin_dhtu_gnunet.c b/src/dhtu/plugin_dhtu_gnunet.c index e01f90bde..b57c65e44 100644 --- a/src/dhtu/plugin_dhtu_gnunet.c +++ b/src/dhtu/plugin_dhtu_gnunet.c | |||
@@ -27,6 +27,8 @@ | |||
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_dhtu_plugin.h" | 28 | #include "gnunet_dhtu_plugin.h" |
29 | #include "gnunet_core_service.h" | 29 | #include "gnunet_core_service.h" |
30 | #include "gnunet_nse_service.h" | ||
31 | |||
30 | 32 | ||
31 | /** | 33 | /** |
32 | * Handle for a private key used by this underlay. | 34 | * Handle for a private key used by this underlay. |
@@ -74,6 +76,17 @@ struct GNUNET_DHTU_Source | |||
74 | * Application context for this source. | 76 | * Application context for this source. |
75 | */ | 77 | */ |
76 | void *app_ctx; | 78 | void *app_ctx; |
79 | |||
80 | /** | ||
81 | * Hash position of this peer in the DHT. | ||
82 | */ | ||
83 | struct GNUNET_DHTU_Hash my_id; | ||
84 | |||
85 | /** | ||
86 | * Private key of this peer. | ||
87 | */ | ||
88 | struct GNUNET_DHTU_PrivateKey pk; | ||
89 | |||
77 | }; | 90 | }; |
78 | 91 | ||
79 | 92 | ||
@@ -90,6 +103,11 @@ struct GNUNET_DHTU_Target | |||
90 | void *app_ctx; | 103 | void *app_ctx; |
91 | 104 | ||
92 | /** | 105 | /** |
106 | * Our plugin with its environment. | ||
107 | */ | ||
108 | struct Plugin *plugin; | ||
109 | |||
110 | /** | ||
93 | * CORE MQ to send messages to this peer. | 111 | * CORE MQ to send messages to this peer. |
94 | */ | 112 | */ |
95 | struct GNUNET_MQ_Handle *mq; | 113 | struct GNUNET_MQ_Handle *mq; |
@@ -159,6 +177,17 @@ struct Plugin | |||
159 | * Handle to the CORE service. | 177 | * Handle to the CORE service. |
160 | */ | 178 | */ |
161 | struct GNUNET_CORE_Handle *core; | 179 | struct GNUNET_CORE_Handle *core; |
180 | |||
181 | /** | ||
182 | * Our "source" address. Traditional CORE API does not tell us which source | ||
183 | * it is, so they are all identical. | ||
184 | */ | ||
185 | struct GNUNET_DHTU_Source src; | ||
186 | |||
187 | /** | ||
188 | * Handle to the NSE service. | ||
189 | */ | ||
190 | struct GNUNET_NSE_Handle *nse; | ||
162 | 191 | ||
163 | }; | 192 | }; |
164 | 193 | ||
@@ -242,6 +271,9 @@ static void | |||
242 | ip_try_connect (void *cls, | 271 | ip_try_connect (void *cls, |
243 | const char *address) | 272 | const char *address) |
244 | { | 273 | { |
274 | struct Plugin *plugin = cls; | ||
275 | |||
276 | // FIXME: ask ATS/TRANSPORT to 'connect' | ||
245 | GNUNET_break (0); | 277 | GNUNET_break (0); |
246 | } | 278 | } |
247 | 279 | ||
@@ -258,6 +290,7 @@ static struct GNUNET_DHTU_PreferenceHandle * | |||
258 | ip_hold (void *cls, | 290 | ip_hold (void *cls, |
259 | struct GNUNET_DHTU_Target *target) | 291 | struct GNUNET_DHTU_Target *target) |
260 | { | 292 | { |
293 | struct Plugin *plugin = cls; | ||
261 | struct GNUNET_DHTU_PreferenceHandle *ph; | 294 | struct GNUNET_DHTU_PreferenceHandle *ph; |
262 | 295 | ||
263 | ph = GNUNET_new (struct GNUNET_DHTU_PreferenceHandle); | 296 | ph = GNUNET_new (struct GNUNET_DHTU_PreferenceHandle); |
@@ -266,6 +299,7 @@ ip_hold (void *cls, | |||
266 | target->ph_tail, | 299 | target->ph_tail, |
267 | ph); | 300 | ph); |
268 | target->ph_count++; | 301 | target->ph_count++; |
302 | // FIXME: update ATS about 'hold' | ||
269 | return ph; | 303 | return ph; |
270 | } | 304 | } |
271 | 305 | ||
@@ -286,6 +320,7 @@ ip_drop (struct GNUNET_DHTU_PreferenceHandle *ph) | |||
286 | ph); | 320 | ph); |
287 | target->ph_count--; | 321 | target->ph_count--; |
288 | GNUNET_free (ph); | 322 | GNUNET_free (ph); |
323 | // FIXME: update ATS about 'drop' | ||
289 | } | 324 | } |
290 | 325 | ||
291 | 326 | ||
@@ -312,7 +347,20 @@ ip_send (void *cls, | |||
312 | GNUNET_SCHEDULER_TaskCallback finished_cb, | 347 | GNUNET_SCHEDULER_TaskCallback finished_cb, |
313 | void *finished_cb_cls) | 348 | void *finished_cb_cls) |
314 | { | 349 | { |
315 | GNUNET_break (0); | 350 | struct GNUNET_MQ_Envelope *env; |
351 | struct GNUNET_MessageHeader *cmsg; | ||
352 | |||
353 | env = GNUNET_MQ_msg_extra (cmsg, | ||
354 | msg_size, | ||
355 | GNUNET_MESSAGE_TYPE_DHT_CORE); | ||
356 | GNUNET_MQ_notify_sent (env, | ||
357 | finished_cb, | ||
358 | finished_cb_cls); | ||
359 | memcpy (&cmsg[1], | ||
360 | msg, | ||
361 | msg_size); | ||
362 | GNUNET_MQ_send (target->mq, | ||
363 | env); | ||
316 | } | 364 | } |
317 | 365 | ||
318 | 366 | ||
@@ -334,6 +382,7 @@ core_connect_cb (void *cls, | |||
334 | struct GNUNET_DHTU_Target *target; | 382 | struct GNUNET_DHTU_Target *target; |
335 | 383 | ||
336 | target = GNUNET_new (struct GNUNET_DHTU_Target); | 384 | target = GNUNET_new (struct GNUNET_DHTU_Target); |
385 | target->plugin = plugin; | ||
337 | target->mq = mq; | 386 | target->mq = mq; |
338 | target->pk.header.size = htons (sizeof (struct PublicKey)); | 387 | target->pk.header.size = htons (sizeof (struct PublicKey)); |
339 | target->pk.peer_pub = *peer; | 388 | target->pk.peer_pub = *peer; |
@@ -362,6 +411,11 @@ core_disconnect_cb (void *cls, | |||
362 | const struct GNUNET_PeerIdentity *peer, | 411 | const struct GNUNET_PeerIdentity *peer, |
363 | void *peer_cls) | 412 | void *peer_cls) |
364 | { | 413 | { |
414 | struct Plugin *plugin = cls; | ||
415 | struct GNUNET_DHTU_Target *target = peer_cls; | ||
416 | |||
417 | plugin->env->disconnect_cb (target->app_ctx); | ||
418 | GNUNET_free (target); | ||
365 | } | 419 | } |
366 | 420 | ||
367 | 421 | ||
@@ -382,6 +436,79 @@ core_init_cb (void *cls, | |||
382 | const struct GNUNET_PeerIdentity *my_identity) | 436 | const struct GNUNET_PeerIdentity *my_identity) |
383 | { | 437 | { |
384 | struct Plugin *plugin = cls; | 438 | struct Plugin *plugin = cls; |
439 | char *addr = NULL; | ||
440 | |||
441 | // FIXME: initialize src.my_id and src.pk and addr! | ||
442 | // (note: with legacy CORE, we only have one addr) | ||
443 | plugin->env->address_add_cb (plugin->env->cls, | ||
444 | &plugin->src.my_id, | ||
445 | &plugin->src.pk, | ||
446 | addr, | ||
447 | &plugin->src, | ||
448 | &plugin->src.app_ctx); | ||
449 | GNUNET_free (addr); | ||
450 | } | ||
451 | |||
452 | |||
453 | /** | ||
454 | * Anything goes, always return #GNUNET_OK. | ||
455 | * | ||
456 | * @param cls unused | ||
457 | * @param msg message to check | ||
458 | * @return #GNUNET_OK if all is fine | ||
459 | */ | ||
460 | static int | ||
461 | check_core_message (void *cls, | ||
462 | const struct GNUNET_MessageHeader *msg) | ||
463 | { | ||
464 | (void) cls; | ||
465 | (void) msg; | ||
466 | return GNUNET_OK; | ||
467 | } | ||
468 | |||
469 | |||
470 | /** | ||
471 | * Handle message from CORE for the DHT. Passes it to the | ||
472 | * DHT logic. | ||
473 | * | ||
474 | * @param cls a `struct GNUNET_DHTU_Target` of the sender | ||
475 | * @param msg the message we received | ||
476 | */ | ||
477 | static void | ||
478 | handle_core_message (void *cls, | ||
479 | const struct GNUNET_MessageHeader *msg) | ||
480 | { | ||
481 | struct GNUNET_DHTU_Target *origin = cls; | ||
482 | struct Plugin *plugin = origin->plugin; | ||
483 | |||
484 | plugin->env->receive_cb (plugin->env->cls, | ||
485 | &origin->app_ctx, | ||
486 | &plugin->src.app_ctx, | ||
487 | &msg[1], | ||
488 | ntohs (msg->size) - sizeof (*msg)); | ||
489 | } | ||
490 | |||
491 | |||
492 | /** | ||
493 | * Callback to call when network size estimate is updated. | ||
494 | * | ||
495 | * @param cls closure | ||
496 | * @param timestamp time when the estimate was received from the server (or created by the server) | ||
497 | * @param logestimate the log(Base 2) value of the current network size estimate | ||
498 | * @param std_dev standard deviation for the estimate | ||
499 | */ | ||
500 | static void | ||
501 | nse_cb (void *cls, | ||
502 | struct GNUNET_TIME_Absolute timestamp, | ||
503 | double logestimate, | ||
504 | double std_dev) | ||
505 | { | ||
506 | struct Plugin *plugin = cls; | ||
507 | |||
508 | plugin->env->network_size_cb (plugin->env->cls, | ||
509 | timestamp, | ||
510 | logestimate, | ||
511 | std_dev); | ||
385 | } | 512 | } |
386 | 513 | ||
387 | 514 | ||
@@ -398,6 +525,10 @@ libgnunet_plugin_dhtu_ip_init (void *cls) | |||
398 | struct GNUNET_DHTU_PluginFunctions *api; | 525 | struct GNUNET_DHTU_PluginFunctions *api; |
399 | struct Plugin *plugin; | 526 | struct Plugin *plugin; |
400 | struct GNUNET_MQ_MessageHandler handlers[] = { | 527 | struct GNUNET_MQ_MessageHandler handlers[] = { |
528 | GNUNET_MQ_hd_var_size (core_message, | ||
529 | GNUNET_MESSAGE_TYPE_DHT_CORE, | ||
530 | struct GNUNET_MessageHeader, | ||
531 | NULL), | ||
401 | GNUNET_MQ_handler_end () | 532 | GNUNET_MQ_handler_end () |
402 | }; | 533 | }; |
403 | 534 | ||
@@ -417,6 +548,9 @@ libgnunet_plugin_dhtu_ip_init (void *cls) | |||
417 | &core_connect_cb, | 548 | &core_connect_cb, |
418 | &core_disconnect_cb, | 549 | &core_disconnect_cb, |
419 | handlers); | 550 | handlers); |
551 | plugin->nse = GNUNET_NSE_connect (env->cfg, | ||
552 | &nse_cb, | ||
553 | plugin); | ||
420 | return api; | 554 | return api; |
421 | } | 555 | } |
422 | 556 | ||
@@ -433,6 +567,7 @@ libgnunet_plugin_dhtu_gnunet_done (void *cls) | |||
433 | struct GNUNET_DHTU_PluginFunctions *api = cls; | 567 | struct GNUNET_DHTU_PluginFunctions *api = cls; |
434 | struct Plugin *plugin = api->cls; | 568 | struct Plugin *plugin = api->cls; |
435 | 569 | ||
570 | GNUNET_NSE_disconnect (plugin->nse); | ||
436 | GNUNET_CORE_disconnect (plugin->core); | 571 | GNUNET_CORE_disconnect (plugin->core); |
437 | GNUNET_free (plugin); | 572 | GNUNET_free (plugin); |
438 | GNUNET_free (api); | 573 | GNUNET_free (api); |
diff --git a/src/include/gnunet_mq_lib.h b/src/include/gnunet_mq_lib.h index 765647a98..a1c5c4957 100644 --- a/src/include/gnunet_mq_lib.h +++ b/src/include/gnunet_mq_lib.h | |||
@@ -305,7 +305,8 @@ enum GNUNET_MQ_PriorityPreferences | |||
305 | * @param cls closure | 305 | * @param cls closure |
306 | * @param msg the received message | 306 | * @param msg the received message |
307 | */ | 307 | */ |
308 | typedef void (*GNUNET_MQ_MessageCallback) ( | 308 | typedef void |
309 | (*GNUNET_MQ_MessageCallback) ( | ||
309 | void *cls, | 310 | void *cls, |
310 | const struct GNUNET_MessageHeader *msg); | 311 | const struct GNUNET_MessageHeader *msg); |
311 | 312 | ||
@@ -318,7 +319,8 @@ typedef void (*GNUNET_MQ_MessageCallback) ( | |||
318 | * @return #GNUNET_OK if the message is well-formed, | 319 | * @return #GNUNET_OK if the message is well-formed, |
319 | * #GNUNET_SYSERR if not | 320 | * #GNUNET_SYSERR if not |
320 | */ | 321 | */ |
321 | typedef int (*GNUNET_MQ_MessageValidationCallback) ( | 322 | typedef int |
323 | (*GNUNET_MQ_MessageValidationCallback) ( | ||
322 | void *cls, | 324 | void *cls, |
323 | const struct GNUNET_MessageHeader *msg); | 325 | const struct GNUNET_MessageHeader *msg); |
324 | 326 | ||
@@ -826,7 +828,8 @@ GNUNET_MQ_get_length (struct GNUNET_MQ_Handle *mq); | |||
826 | * @param ev the envelope with the message to send. | 828 | * @param ev the envelope with the message to send. |
827 | */ | 829 | */ |
828 | void | 830 | void |
829 | GNUNET_MQ_send (struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev); | 831 | GNUNET_MQ_send (struct GNUNET_MQ_Handle *mq, |
832 | struct GNUNET_MQ_Envelope *ev); | ||
830 | 833 | ||
831 | 834 | ||
832 | /** | 835 | /** |
@@ -859,7 +862,8 @@ GNUNET_MQ_send_cancel (struct GNUNET_MQ_Envelope *ev); | |||
859 | * @param assoc_data to associate | 862 | * @param assoc_data to associate |
860 | */ | 863 | */ |
861 | uint32_t | 864 | uint32_t |
862 | GNUNET_MQ_assoc_add (struct GNUNET_MQ_Handle *mq, void *assoc_data); | 865 | GNUNET_MQ_assoc_add (struct GNUNET_MQ_Handle *mq, |
866 | void *assoc_data); | ||
863 | 867 | ||
864 | 868 | ||
865 | /** | 869 | /** |
@@ -870,7 +874,8 @@ GNUNET_MQ_assoc_add (struct GNUNET_MQ_Handle *mq, void *assoc_data); | |||
870 | * @return the associated data | 874 | * @return the associated data |
871 | */ | 875 | */ |
872 | void * | 876 | void * |
873 | GNUNET_MQ_assoc_get (struct GNUNET_MQ_Handle *mq, uint32_t request_id); | 877 | GNUNET_MQ_assoc_get (struct GNUNET_MQ_Handle *mq, |
878 | uint32_t request_id); | ||
874 | 879 | ||
875 | 880 | ||
876 | /** | 881 | /** |
@@ -881,7 +886,8 @@ GNUNET_MQ_assoc_get (struct GNUNET_MQ_Handle *mq, uint32_t request_id); | |||
881 | * @return the associated data | 886 | * @return the associated data |
882 | */ | 887 | */ |
883 | void * | 888 | void * |
884 | GNUNET_MQ_assoc_remove (struct GNUNET_MQ_Handle *mq, uint32_t request_id); | 889 | GNUNET_MQ_assoc_remove (struct GNUNET_MQ_Handle *mq, |
890 | uint32_t request_id); | ||
885 | 891 | ||
886 | 892 | ||
887 | /** | 893 | /** |
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index 6b61dfc72..41f2876e6 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h | |||
@@ -660,6 +660,11 @@ extern "C" { | |||
660 | #define GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN 156 | 660 | #define GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN 156 |
661 | 661 | ||
662 | /** | 662 | /** |
663 | * DHT wants to use CORE to transmit data. | ||
664 | */ | ||
665 | #define GNUNET_MESSAGE_TYPE_DHT_CORE 143 | ||
666 | |||
667 | /** | ||
663 | * Further X-VINE DHT messages continued from 880 | 668 | * Further X-VINE DHT messages continued from 880 |
664 | */ | 669 | */ |
665 | 670 | ||