aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2021-09-22 09:34:37 +0200
committert3sserakt <t3ss@posteo.de>2021-09-22 09:35:15 +0200
commit658bceab7ba3aab5121e8874d8508264d3f63ce3 (patch)
tree1c69216934c3313417bd2031f679fb189399120d
parentc58507bbcbb3d3c87f02f7cc10fb087870c1d509 (diff)
parent5da4ba31a2fb0e12ff0daf2fc6e1c7d8c2749655 (diff)
downloadgnunet-658bceab7ba3aab5121e8874d8508264d3f63ce3.tar.gz
gnunet-658bceab7ba3aab5121e8874d8508264d3f63ce3.zip
Merge branch 'master' of ssh://git.gnunet.org/gnunet
-rw-r--r--src/dhtu/Makefile.am2
-rw-r--r--src/dhtu/plugin_dhtu_gnunet.c277
-rw-r--r--src/include/gnunet_mq_lib.h18
-rw-r--r--src/include/gnunet_protocols.h5
-rw-r--r--src/include/gnunet_transport_service.h4
5 files changed, 275 insertions, 31 deletions
diff --git a/src/dhtu/Makefile.am b/src/dhtu/Makefile.am
index f4b968526..67810e8cc 100644
--- a/src/dhtu/Makefile.am
+++ b/src/dhtu/Makefile.am
@@ -28,7 +28,9 @@ libgnunet_plugin_dhtu_ip_la_LDFLAGS = \
28libgnunet_plugin_dhtu_gnunet_la_SOURCES = \ 28libgnunet_plugin_dhtu_gnunet_la_SOURCES = \
29 plugin_dhtu_gnunet.c 29 plugin_dhtu_gnunet.c
30libgnunet_plugin_dhtu_gnunet_la_LIBADD = \ 30libgnunet_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 \
33 $(top_builddir)/src/nse/libgnunetnse.la \
32 $(top_builddir)/src/util/libgnunetutil.la \ 34 $(top_builddir)/src/util/libgnunetutil.la \
33 $(XLIBS) \ 35 $(XLIBS) \
34 $(LTLIBINTL) 36 $(LTLIBINTL)
diff --git a/src/dhtu/plugin_dhtu_gnunet.c b/src/dhtu/plugin_dhtu_gnunet.c
index ccd329e8e..9cc14361d 100644
--- a/src/dhtu/plugin_dhtu_gnunet.c
+++ b/src/dhtu/plugin_dhtu_gnunet.c
@@ -26,7 +26,10 @@
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"
31#include "gnunet_nse_service.h"
32
30 33
31/** 34/**
32 * Handle for a private key used by this underlay. 35 * Handle for a private key used by this underlay.
@@ -40,6 +43,7 @@ struct GNUNET_DHTU_PrivateKey
40 43
41}; 44};
42 45
46GNUNET_NETWORK_STRUCT_BEGIN
43 47
44/** 48/**
45 * Handle for a public key used by this underlay. 49 * Handle for a public key used by this underlay.
@@ -55,11 +59,13 @@ struct PublicKey
55 /** 59 /**
56 * GNUnet uses eddsa for peers. 60 * GNUnet uses eddsa for peers.
57 */ 61 */
58 struct GNUNET_CRYPTO_EddsaPublicKey eddsa_pub; 62 struct GNUNET_PeerIdentity peer_pub;
59 63
60}; 64};
61 65
62 66
67GNUNET_NETWORK_STRUCT_END
68
63/** 69/**
64 * Opaque handle that the underlay offers for our address to be used when 70 * Opaque handle that the underlay offers for our address to be used when
65 * sending messages to another peer. 71 * sending messages to another peer.
@@ -71,6 +77,17 @@ struct GNUNET_DHTU_Source
71 * Application context for this source. 77 * Application context for this source.
72 */ 78 */
73 void *app_ctx; 79 void *app_ctx;
80
81 /**
82 * Hash position of this peer in the DHT.
83 */
84 struct GNUNET_DHTU_Hash my_id;
85
86 /**
87 * Private key of this peer.
88 */
89 struct GNUNET_DHTU_PrivateKey pk;
90
74}; 91};
75 92
76 93
@@ -87,6 +104,27 @@ struct GNUNET_DHTU_Target
87 void *app_ctx; 104 void *app_ctx;
88 105
89 /** 106 /**
107 * Our plugin with its environment.
108 */
109 struct Plugin *plugin;
110
111 /**
112 * CORE MQ to send messages to this peer.
113 */
114 struct GNUNET_MQ_Handle *mq;
115
116 /**
117 * Public key of the peer.
118 */
119 struct PublicKey pk;
120
121 /**
122 * Hash of the @a pk to identify position of the peer
123 * in the DHT.
124 */
125 struct GNUNET_DHTU_Hash peer_id;
126
127 /**
90 * Head of preferences expressed for this target. 128 * Head of preferences expressed for this target.
91 */ 129 */
92 struct GNUNET_DHTU_PreferenceHandle *ph_head; 130 struct GNUNET_DHTU_PreferenceHandle *ph_head;
@@ -97,6 +135,11 @@ struct GNUNET_DHTU_Target
97 struct GNUNET_DHTU_PreferenceHandle *ph_tail; 135 struct GNUNET_DHTU_PreferenceHandle *ph_tail;
98 136
99 /** 137 /**
138 * ATS preference handle for this peer, or NULL.
139 */
140 struct GNUNET_ATS_ConnectivitySuggestHandle *csh;
141
142 /**
100 * Preference counter, length of the @a ph_head DLL. 143 * Preference counter, length of the @a ph_head DLL.
101 */ 144 */
102 unsigned int ph_count; 145 unsigned int ph_count;
@@ -140,6 +183,22 @@ struct Plugin
140 * Handle to the CORE service. 183 * Handle to the CORE service.
141 */ 184 */
142 struct GNUNET_CORE_Handle *core; 185 struct GNUNET_CORE_Handle *core;
186
187 /**
188 * Handle to ATS service.
189 */
190 struct GNUNET_ATS_ConnectivityHandle *ats;
191
192 /**
193 * Our "source" address. Traditional CORE API does not tell us which source
194 * it is, so they are all identical.
195 */
196 struct GNUNET_DHTU_Source src;
197
198 /**
199 * Handle to the NSE service.
200 */
201 struct GNUNET_NSE_Handle *nse;
143 202
144}; 203};
145 204
@@ -204,7 +263,7 @@ ip_verify (void *cls,
204 GNUNET_CRYPTO_eddsa_verify_ (ntohl (purpose->purpose), 263 GNUNET_CRYPTO_eddsa_verify_ (ntohl (purpose->purpose),
205 purpose, 264 purpose,
206 es, 265 es,
207 &pub->eddsa_pub)) 266 &pub->peer_pub.public_key))
208 { 267 {
209 GNUNET_break_op (0); 268 GNUNET_break_op (0);
210 return GNUNET_SYSERR; 269 return GNUNET_SYSERR;
@@ -223,6 +282,10 @@ static void
223ip_try_connect (void *cls, 282ip_try_connect (void *cls,
224 const char *address) 283 const char *address)
225{ 284{
285 struct Plugin *plugin = cls;
286
287 // FIXME: ask ATS/TRANSPORT to 'connect'
288 // => needs HELLO!
226 GNUNET_break (0); 289 GNUNET_break (0);
227} 290}
228 291
@@ -239,6 +302,7 @@ static struct GNUNET_DHTU_PreferenceHandle *
239ip_hold (void *cls, 302ip_hold (void *cls,
240 struct GNUNET_DHTU_Target *target) 303 struct GNUNET_DHTU_Target *target)
241{ 304{
305 struct Plugin *plugin = cls;
242 struct GNUNET_DHTU_PreferenceHandle *ph; 306 struct GNUNET_DHTU_PreferenceHandle *ph;
243 307
244 ph = GNUNET_new (struct GNUNET_DHTU_PreferenceHandle); 308 ph = GNUNET_new (struct GNUNET_DHTU_PreferenceHandle);
@@ -247,6 +311,12 @@ ip_hold (void *cls,
247 target->ph_tail, 311 target->ph_tail,
248 ph); 312 ph);
249 target->ph_count++; 313 target->ph_count++;
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);
250 return ph; 320 return ph;
251} 321}
252 322
@@ -261,12 +331,22 @@ static void
261ip_drop (struct GNUNET_DHTU_PreferenceHandle *ph) 331ip_drop (struct GNUNET_DHTU_PreferenceHandle *ph)
262{ 332{
263 struct GNUNET_DHTU_Target *target = ph->target; 333 struct GNUNET_DHTU_Target *target = ph->target;
264 334 struct Plugin *plugin = target->plugin;
335
265 GNUNET_CONTAINER_DLL_remove (target->ph_head, 336 GNUNET_CONTAINER_DLL_remove (target->ph_head,
266 target->ph_tail, 337 target->ph_tail,
267 ph); 338 ph);
268 target->ph_count--; 339 target->ph_count--;
269 GNUNET_free (ph); 340 GNUNET_free (ph);
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);
270} 350}
271 351
272 352
@@ -293,7 +373,20 @@ ip_send (void *cls,
293 GNUNET_SCHEDULER_TaskCallback finished_cb, 373 GNUNET_SCHEDULER_TaskCallback finished_cb,
294 void *finished_cb_cls) 374 void *finished_cb_cls)
295{ 375{
296 GNUNET_break (0); 376 struct GNUNET_MQ_Envelope *env;
377 struct GNUNET_MessageHeader *cmsg;
378
379 env = GNUNET_MQ_msg_extra (cmsg,
380 msg_size,
381 GNUNET_MESSAGE_TYPE_DHT_CORE);
382 GNUNET_MQ_notify_sent (env,
383 finished_cb,
384 finished_cb_cls);
385 memcpy (&cmsg[1],
386 msg,
387 msg_size);
388 GNUNET_MQ_send (target->mq,
389 env);
297} 390}
298 391
299 392
@@ -311,7 +404,23 @@ core_connect_cb (void *cls,
311 const struct GNUNET_PeerIdentity *peer, 404 const struct GNUNET_PeerIdentity *peer,
312 struct GNUNET_MQ_Handle *mq) 405 struct GNUNET_MQ_Handle *mq)
313{ 406{
314 return NULL; 407 struct Plugin *plugin = cls;
408 struct GNUNET_DHTU_Target *target;
409
410 target = GNUNET_new (struct GNUNET_DHTU_Target);
411 target->plugin = plugin;
412 target->mq = mq;
413 target->pk.header.size = htons (sizeof (struct PublicKey));
414 target->pk.peer_pub = *peer;
415 GNUNET_CRYPTO_hash (peer,
416 sizeof (struct GNUNET_PeerIdentity),
417 &target->peer_id.hc);
418 plugin->env->connect_cb (plugin->env->cls,
419 &target->pk.header,
420 &target->peer_id,
421 target,
422 &target->app_ctx);
423 return target;
315} 424}
316 425
317 426
@@ -328,6 +437,13 @@ core_disconnect_cb (void *cls,
328 const struct GNUNET_PeerIdentity *peer, 437 const struct GNUNET_PeerIdentity *peer,
329 void *peer_cls) 438 void *peer_cls)
330{ 439{
440 struct Plugin *plugin = cls;
441 struct GNUNET_DHTU_Target *target = peer_cls;
442
443 plugin->env->disconnect_cb (target->app_ctx);
444 if (NULL != target->csh)
445 GNUNET_ATS_connectivity_suggest_cancel (target->csh);
446 GNUNET_free (target);
331} 447}
332 448
333 449
@@ -348,6 +464,113 @@ core_init_cb (void *cls,
348 const struct GNUNET_PeerIdentity *my_identity) 464 const struct GNUNET_PeerIdentity *my_identity)
349{ 465{
350 struct Plugin *plugin = cls; 466 struct Plugin *plugin = cls;
467 char *addr;
468 char *pid;
469
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);
481 plugin->env->address_add_cb (plugin->env->cls,
482 &plugin->src.my_id,
483 &plugin->src.pk,
484 addr,
485 &plugin->src,
486 &plugin->src.app_ctx);
487 GNUNET_free (addr);
488}
489
490
491/**
492 * Anything goes, always return #GNUNET_OK.
493 *
494 * @param cls unused
495 * @param msg message to check
496 * @return #GNUNET_OK if all is fine
497 */
498static int
499check_core_message (void *cls,
500 const struct GNUNET_MessageHeader *msg)
501{
502 (void) cls;
503 (void) msg;
504 return GNUNET_OK;
505}
506
507
508/**
509 * Handle message from CORE for the DHT. Passes it to the
510 * DHT logic.
511 *
512 * @param cls a `struct GNUNET_DHTU_Target` of the sender
513 * @param msg the message we received
514 */
515static void
516handle_core_message (void *cls,
517 const struct GNUNET_MessageHeader *msg)
518{
519 struct GNUNET_DHTU_Target *origin = cls;
520 struct Plugin *plugin = origin->plugin;
521
522 plugin->env->receive_cb (plugin->env->cls,
523 &origin->app_ctx,
524 &plugin->src.app_ctx,
525 &msg[1],
526 ntohs (msg->size) - sizeof (*msg));
527}
528
529
530/**
531 * Callback to call when network size estimate is updated.
532 *
533 * @param cls closure
534 * @param timestamp time when the estimate was received from the server (or created by the server)
535 * @param logestimate the log(Base 2) value of the current network size estimate
536 * @param std_dev standard deviation for the estimate
537 */
538static void
539nse_cb (void *cls,
540 struct GNUNET_TIME_Absolute timestamp,
541 double logestimate,
542 double std_dev)
543{
544 struct Plugin *plugin = cls;
545
546 plugin->env->network_size_cb (plugin->env->cls,
547 timestamp,
548 logestimate,
549 std_dev);
550}
551
552
553/**
554 * Exit point from the plugin.
555 *
556 * @param cls closure (our `struct Plugin`)
557 * @return NULL
558 */
559void *
560libgnunet_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;
351} 574}
352 575
353 576
@@ -364,11 +587,24 @@ libgnunet_plugin_dhtu_ip_init (void *cls)
364 struct GNUNET_DHTU_PluginFunctions *api; 587 struct GNUNET_DHTU_PluginFunctions *api;
365 struct Plugin *plugin; 588 struct Plugin *plugin;
366 struct GNUNET_MQ_MessageHandler handlers[] = { 589 struct GNUNET_MQ_MessageHandler handlers[] = {
590 GNUNET_MQ_hd_var_size (core_message,
591 GNUNET_MESSAGE_TYPE_DHT_CORE,
592 struct GNUNET_MessageHeader,
593 NULL),
367 GNUNET_MQ_handler_end () 594 GNUNET_MQ_handler_end ()
368 }; 595 };
369 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 }
370 plugin = GNUNET_new (struct Plugin); 604 plugin = GNUNET_new (struct Plugin);
371 plugin->env = env; 605 plugin->env = env;
606 plugin->src.pk.eddsa_priv = *pk;
607 GNUNET_free (pk);
372 api = GNUNET_new (struct GNUNET_DHTU_PluginFunctions); 608 api = GNUNET_new (struct GNUNET_DHTU_PluginFunctions);
373 api->cls = plugin; 609 api->cls = plugin;
374 api->sign = &ip_sign; 610 api->sign = &ip_sign;
@@ -377,30 +613,25 @@ libgnunet_plugin_dhtu_ip_init (void *cls)
377 api->hold = &ip_hold; 613 api->hold = &ip_hold;
378 api->drop = &ip_drop; 614 api->drop = &ip_drop;
379 api->send = &ip_send; 615 api->send = &ip_send;
616 plugin->ats = GNUNET_ATS_connectivity_init (env->cfg);
380 plugin->core = GNUNET_CORE_connect (env->cfg, 617 plugin->core = GNUNET_CORE_connect (env->cfg,
381 plugin, 618 plugin,
382 &core_init_cb, 619 &core_init_cb,
383 &core_connect_cb, 620 &core_connect_cb,
384 &core_disconnect_cb, 621 &core_disconnect_cb,
385 handlers); 622 handlers);
623 plugin->nse = GNUNET_NSE_connect (env->cfg,
624 &nse_cb,
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 }
386 return api; 634 return api;
387} 635}
388 636
389 637
390/**
391 * Exit point from the plugin.
392 *
393 * @param cls closure (our `struct Plugin`)
394 * @return NULL
395 */
396void *
397libgnunet_plugin_dhtu_gnunet_done (void *cls)
398{
399 struct GNUNET_DHTU_PluginFunctions *api = cls;
400 struct Plugin *plugin = api->cls;
401
402 GNUNET_CORE_disconnect (plugin->core);
403 GNUNET_free (plugin);
404 GNUNET_free (api);
405 return NULL;
406}
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 */
308typedef void (*GNUNET_MQ_MessageCallback) ( 308typedef 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 */
321typedef int (*GNUNET_MQ_MessageValidationCallback) ( 322typedef 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 */
828void 830void
829GNUNET_MQ_send (struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev); 831GNUNET_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 */
861uint32_t 864uint32_t
862GNUNET_MQ_assoc_add (struct GNUNET_MQ_Handle *mq, void *assoc_data); 865GNUNET_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 */
872void * 876void *
873GNUNET_MQ_assoc_get (struct GNUNET_MQ_Handle *mq, uint32_t request_id); 877GNUNET_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 */
883void * 888void *
884GNUNET_MQ_assoc_remove (struct GNUNET_MQ_Handle *mq, uint32_t request_id); 889GNUNET_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
diff --git a/src/include/gnunet_transport_service.h b/src/include/gnunet_transport_service.h
index 545bb28d2..459efc506 100644
--- a/src/include/gnunet_transport_service.h
+++ b/src/include/gnunet_transport_service.h
@@ -117,8 +117,8 @@ struct GNUNET_TRANSPORT_AddressToStringContext;
117 */ 117 */
118typedef void 118typedef void
119(*GNUNET_TRANSPORT_AddressToStringCallback) (void *cls, 119(*GNUNET_TRANSPORT_AddressToStringCallback) (void *cls,
120 const char *address, 120 const char *address,
121 int res); 121 int res);
122 122
123 123
124/** 124/**