diff options
author | Christian Grothoff <grothoff@gnunet.org> | 2021-09-22 09:29:56 +0200 |
---|---|---|
committer | Christian Grothoff <grothoff@gnunet.org> | 2021-09-22 09:29:56 +0200 |
commit | 5da4ba31a2fb0e12ff0daf2fc6e1c7d8c2749655 (patch) | |
tree | 7d01ead986116d54c5962d128fd0ccd1adcc56e4 /src/dhtu | |
parent | c221e30ea67751237058b6a5aa7b46e12fca5395 (diff) | |
download | gnunet-5da4ba31a2fb0e12ff0daf2fc6e1c7d8c2749655.tar.gz gnunet-5da4ba31a2fb0e12ff0daf2fc6e1c7d8c2749655.zip |
-do ATS integration in DHTU
Diffstat (limited to 'src/dhtu')
-rw-r--r-- | src/dhtu/Makefile.am | 1 | ||||
-rw-r--r-- | src/dhtu/plugin_dhtu_gnunet.c | 114 |
2 files changed, 89 insertions, 26 deletions
diff --git a/src/dhtu/Makefile.am b/src/dhtu/Makefile.am index 601f31bf5..67810e8cc 100644 --- a/src/dhtu/Makefile.am +++ b/src/dhtu/Makefile.am | |||
@@ -28,6 +28,7 @@ libgnunet_plugin_dhtu_ip_la_LDFLAGS = \ | |||
28 | libgnunet_plugin_dhtu_gnunet_la_SOURCES = \ | 28 | 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/ats/libgnunetats.la \ | ||
31 | $(top_builddir)/src/core/libgnunetcore.la \ | 32 | $(top_builddir)/src/core/libgnunetcore.la \ |
32 | $(top_builddir)/src/nse/libgnunetnse.la \ | 33 | $(top_builddir)/src/nse/libgnunetnse.la \ |
33 | $(top_builddir)/src/util/libgnunetutil.la \ | 34 | $(top_builddir)/src/util/libgnunetutil.la \ |
diff --git a/src/dhtu/plugin_dhtu_gnunet.c b/src/dhtu/plugin_dhtu_gnunet.c index b57c65e44..9cc14361d 100644 --- a/src/dhtu/plugin_dhtu_gnunet.c +++ b/src/dhtu/plugin_dhtu_gnunet.c | |||
@@ -26,6 +26,7 @@ | |||
26 | */ | 26 | */ |
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_dhtu_plugin.h" | 28 | #include "gnunet_dhtu_plugin.h" |
29 | #include "gnunet_ats_service.h" | ||
29 | #include "gnunet_core_service.h" | 30 | #include "gnunet_core_service.h" |
30 | #include "gnunet_nse_service.h" | 31 | #include "gnunet_nse_service.h" |
31 | 32 | ||
@@ -134,6 +135,11 @@ struct GNUNET_DHTU_Target | |||
134 | struct GNUNET_DHTU_PreferenceHandle *ph_tail; | 135 | struct GNUNET_DHTU_PreferenceHandle *ph_tail; |
135 | 136 | ||
136 | /** | 137 | /** |
138 | * ATS preference handle for this peer, or NULL. | ||
139 | */ | ||
140 | struct GNUNET_ATS_ConnectivitySuggestHandle *csh; | ||
141 | |||
142 | /** | ||
137 | * Preference counter, length of the @a ph_head DLL. | 143 | * Preference counter, length of the @a ph_head DLL. |
138 | */ | 144 | */ |
139 | unsigned int ph_count; | 145 | unsigned int ph_count; |
@@ -179,6 +185,11 @@ struct Plugin | |||
179 | struct GNUNET_CORE_Handle *core; | 185 | struct GNUNET_CORE_Handle *core; |
180 | 186 | ||
181 | /** | 187 | /** |
188 | * Handle to ATS service. | ||
189 | */ | ||
190 | struct GNUNET_ATS_ConnectivityHandle *ats; | ||
191 | |||
192 | /** | ||
182 | * Our "source" address. Traditional CORE API does not tell us which source | 193 | * Our "source" address. Traditional CORE API does not tell us which source |
183 | * it is, so they are all identical. | 194 | * it is, so they are all identical. |
184 | */ | 195 | */ |
@@ -274,6 +285,7 @@ ip_try_connect (void *cls, | |||
274 | struct Plugin *plugin = cls; | 285 | struct Plugin *plugin = cls; |
275 | 286 | ||
276 | // FIXME: ask ATS/TRANSPORT to 'connect' | 287 | // FIXME: ask ATS/TRANSPORT to 'connect' |
288 | // => needs HELLO! | ||
277 | GNUNET_break (0); | 289 | GNUNET_break (0); |
278 | } | 290 | } |
279 | 291 | ||
@@ -299,7 +311,12 @@ ip_hold (void *cls, | |||
299 | target->ph_tail, | 311 | target->ph_tail, |
300 | ph); | 312 | ph); |
301 | target->ph_count++; | 313 | target->ph_count++; |
302 | // FIXME: update ATS about 'hold' | 314 | if (NULL != target->csh) |
315 | GNUNET_ATS_connectivity_suggest_cancel (target->csh); | ||
316 | target->csh | ||
317 | = GNUNET_ATS_connectivity_suggest (plugin->ats, | ||
318 | &target->pk.peer_pub, | ||
319 | target->ph_count); | ||
303 | return ph; | 320 | return ph; |
304 | } | 321 | } |
305 | 322 | ||
@@ -314,13 +331,22 @@ static void | |||
314 | ip_drop (struct GNUNET_DHTU_PreferenceHandle *ph) | 331 | ip_drop (struct GNUNET_DHTU_PreferenceHandle *ph) |
315 | { | 332 | { |
316 | struct GNUNET_DHTU_Target *target = ph->target; | 333 | struct GNUNET_DHTU_Target *target = ph->target; |
317 | 334 | struct Plugin *plugin = target->plugin; | |
335 | |||
318 | GNUNET_CONTAINER_DLL_remove (target->ph_head, | 336 | GNUNET_CONTAINER_DLL_remove (target->ph_head, |
319 | target->ph_tail, | 337 | target->ph_tail, |
320 | ph); | 338 | ph); |
321 | target->ph_count--; | 339 | target->ph_count--; |
322 | GNUNET_free (ph); | 340 | GNUNET_free (ph); |
323 | // FIXME: update ATS about 'drop' | 341 | if (NULL != target->csh) |
342 | GNUNET_ATS_connectivity_suggest_cancel (target->csh); | ||
343 | if (0 == target->ph_count) | ||
344 | target->csh = NULL; | ||
345 | else | ||
346 | target->csh | ||
347 | = GNUNET_ATS_connectivity_suggest (plugin->ats, | ||
348 | &target->pk.peer_pub, | ||
349 | target->ph_count); | ||
324 | } | 350 | } |
325 | 351 | ||
326 | 352 | ||
@@ -415,6 +441,8 @@ core_disconnect_cb (void *cls, | |||
415 | struct GNUNET_DHTU_Target *target = peer_cls; | 441 | struct GNUNET_DHTU_Target *target = peer_cls; |
416 | 442 | ||
417 | plugin->env->disconnect_cb (target->app_ctx); | 443 | plugin->env->disconnect_cb (target->app_ctx); |
444 | if (NULL != target->csh) | ||
445 | GNUNET_ATS_connectivity_suggest_cancel (target->csh); | ||
418 | GNUNET_free (target); | 446 | GNUNET_free (target); |
419 | } | 447 | } |
420 | 448 | ||
@@ -436,10 +464,20 @@ core_init_cb (void *cls, | |||
436 | const struct GNUNET_PeerIdentity *my_identity) | 464 | const struct GNUNET_PeerIdentity *my_identity) |
437 | { | 465 | { |
438 | struct Plugin *plugin = cls; | 466 | struct Plugin *plugin = cls; |
439 | char *addr = NULL; | 467 | char *addr; |
440 | 468 | char *pid; | |
441 | // FIXME: initialize src.my_id and src.pk and addr! | 469 | |
442 | // (note: with legacy CORE, we only have one addr) | 470 | // FIXME: to later ask ATS/TRANSPORT to 'connect' we need a HELLO, |
471 | // not merely a vanilla PID... | ||
472 | pid = GNUNET_STRINGS_data_to_string_alloc (my_identity, | ||
473 | sizeof (struct GNUNET_PeerIdentity)); | ||
474 | GNUNET_asprintf (&addr, | ||
475 | "gnunet-core-v15://%s/", | ||
476 | pid); | ||
477 | GNUNET_free (pid); | ||
478 | GNUNET_CRYPTO_hash (my_identity, | ||
479 | sizeof (struct GNUNET_PeerIdentity), | ||
480 | &plugin->src.my_id.hc); | ||
443 | plugin->env->address_add_cb (plugin->env->cls, | 481 | plugin->env->address_add_cb (plugin->env->cls, |
444 | &plugin->src.my_id, | 482 | &plugin->src.my_id, |
445 | &plugin->src.pk, | 483 | &plugin->src.pk, |
@@ -513,6 +551,30 @@ nse_cb (void *cls, | |||
513 | 551 | ||
514 | 552 | ||
515 | /** | 553 | /** |
554 | * Exit point from the plugin. | ||
555 | * | ||
556 | * @param cls closure (our `struct Plugin`) | ||
557 | * @return NULL | ||
558 | */ | ||
559 | void * | ||
560 | libgnunet_plugin_dhtu_gnunet_done (void *cls) | ||
561 | { | ||
562 | struct GNUNET_DHTU_PluginFunctions *api = cls; | ||
563 | struct Plugin *plugin = api->cls; | ||
564 | |||
565 | if (NULL != plugin->nse) | ||
566 | GNUNET_NSE_disconnect (plugin->nse); | ||
567 | if (NULL != plugin->core) | ||
568 | GNUNET_CORE_disconnect (plugin->core); | ||
569 | if (NULL != plugin->ats) | ||
570 | GNUNET_ATS_connectivity_done (plugin->ats); | ||
571 | GNUNET_free (plugin); | ||
572 | GNUNET_free (api); | ||
573 | return NULL; | ||
574 | } | ||
575 | |||
576 | |||
577 | /** | ||
516 | * Entry point for the plugin. | 578 | * Entry point for the plugin. |
517 | * | 579 | * |
518 | * @param cls closure (the `struct GNUNET_DHTU_PluginEnvironment`) | 580 | * @param cls closure (the `struct GNUNET_DHTU_PluginEnvironment`) |
@@ -531,9 +593,18 @@ libgnunet_plugin_dhtu_ip_init (void *cls) | |||
531 | NULL), | 593 | NULL), |
532 | GNUNET_MQ_handler_end () | 594 | GNUNET_MQ_handler_end () |
533 | }; | 595 | }; |
534 | 596 | struct GNUNET_CRYPTO_EddsaPrivateKey *pk; | |
597 | |||
598 | pk = GNUNET_CRYPTO_eddsa_key_create_from_configuration (env->cfg); | ||
599 | if (NULL == pk) | ||
600 | { | ||
601 | GNUNET_break (0); | ||
602 | return NULL; | ||
603 | } | ||
535 | plugin = GNUNET_new (struct Plugin); | 604 | plugin = GNUNET_new (struct Plugin); |
536 | plugin->env = env; | 605 | plugin->env = env; |
606 | plugin->src.pk.eddsa_priv = *pk; | ||
607 | GNUNET_free (pk); | ||
537 | api = GNUNET_new (struct GNUNET_DHTU_PluginFunctions); | 608 | api = GNUNET_new (struct GNUNET_DHTU_PluginFunctions); |
538 | api->cls = plugin; | 609 | api->cls = plugin; |
539 | api->sign = &ip_sign; | 610 | api->sign = &ip_sign; |
@@ -542,6 +613,7 @@ libgnunet_plugin_dhtu_ip_init (void *cls) | |||
542 | api->hold = &ip_hold; | 613 | api->hold = &ip_hold; |
543 | api->drop = &ip_drop; | 614 | api->drop = &ip_drop; |
544 | api->send = &ip_send; | 615 | api->send = &ip_send; |
616 | plugin->ats = GNUNET_ATS_connectivity_init (env->cfg); | ||
545 | plugin->core = GNUNET_CORE_connect (env->cfg, | 617 | plugin->core = GNUNET_CORE_connect (env->cfg, |
546 | plugin, | 618 | plugin, |
547 | &core_init_cb, | 619 | &core_init_cb, |
@@ -551,25 +623,15 @@ libgnunet_plugin_dhtu_ip_init (void *cls) | |||
551 | plugin->nse = GNUNET_NSE_connect (env->cfg, | 623 | plugin->nse = GNUNET_NSE_connect (env->cfg, |
552 | &nse_cb, | 624 | &nse_cb, |
553 | plugin); | 625 | plugin); |
626 | if ( (NULL == plugin->ats) || | ||
627 | (NULL == plugin->core) || | ||
628 | (NULL == plugin->nse) ) | ||
629 | { | ||
630 | GNUNET_break (0); | ||
631 | libgnunet_plugin_dhtu_gnunet_done (plugin); | ||
632 | return NULL; | ||
633 | } | ||
554 | return api; | 634 | return api; |
555 | } | 635 | } |
556 | 636 | ||
557 | 637 | ||
558 | /** | ||
559 | * Exit point from the plugin. | ||
560 | * | ||
561 | * @param cls closure (our `struct Plugin`) | ||
562 | * @return NULL | ||
563 | */ | ||
564 | void * | ||
565 | libgnunet_plugin_dhtu_gnunet_done (void *cls) | ||
566 | { | ||
567 | struct GNUNET_DHTU_PluginFunctions *api = cls; | ||
568 | struct Plugin *plugin = api->cls; | ||
569 | |||
570 | GNUNET_NSE_disconnect (plugin->nse); | ||
571 | GNUNET_CORE_disconnect (plugin->core); | ||
572 | GNUNET_free (plugin); | ||
573 | GNUNET_free (api); | ||
574 | return NULL; | ||
575 | } | ||