aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dhtu/Makefile.am3
-rw-r--r--src/dhtu/plugin_dhtu_gnunet.c215
2 files changed, 178 insertions, 40 deletions
diff --git a/src/dhtu/Makefile.am b/src/dhtu/Makefile.am
index 67810e8cc..33c31dd6c 100644
--- a/src/dhtu/Makefile.am
+++ b/src/dhtu/Makefile.am
@@ -30,6 +30,9 @@ libgnunet_plugin_dhtu_gnunet_la_SOURCES = \
30libgnunet_plugin_dhtu_gnunet_la_LIBADD = \ 30libgnunet_plugin_dhtu_gnunet_la_LIBADD = \
31 $(top_builddir)/src/ats/libgnunetats.la \ 31 $(top_builddir)/src/ats/libgnunetats.la \
32 $(top_builddir)/src/core/libgnunetcore.la \ 32 $(top_builddir)/src/core/libgnunetcore.la \
33 $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \
34 $(top_builddir)/src/transport/libgnunettransport.la \
35 $(top_builddir)/src/hello/libgnunethello.la \
33 $(top_builddir)/src/nse/libgnunetnse.la \ 36 $(top_builddir)/src/nse/libgnunetnse.la \
34 $(top_builddir)/src/util/libgnunetutil.la \ 37 $(top_builddir)/src/util/libgnunetutil.la \
35 $(XLIBS) \ 38 $(XLIBS) \
diff --git a/src/dhtu/plugin_dhtu_gnunet.c b/src/dhtu/plugin_dhtu_gnunet.c
index 9cc14361d..ee78858c8 100644
--- a/src/dhtu/plugin_dhtu_gnunet.c
+++ b/src/dhtu/plugin_dhtu_gnunet.c
@@ -28,6 +28,9 @@
28#include "gnunet_dhtu_plugin.h" 28#include "gnunet_dhtu_plugin.h"
29#include "gnunet_ats_service.h" 29#include "gnunet_ats_service.h"
30#include "gnunet_core_service.h" 30#include "gnunet_core_service.h"
31#include "gnunet_transport_service.h"
32#include "gnunet_hello_lib.h"
33#include "gnunet_peerinfo_service.h"
31#include "gnunet_nse_service.h" 34#include "gnunet_nse_service.h"
32 35
33 36
@@ -66,6 +69,35 @@ struct PublicKey
66 69
67GNUNET_NETWORK_STRUCT_END 70GNUNET_NETWORK_STRUCT_END
68 71
72
73/**
74 * Handle for a HELLO we're offering the transport.
75 */
76struct HelloHandle
77{
78 /**
79 * Kept in a DLL.
80 */
81 struct HelloHandle *next;
82
83 /**
84 * Kept in a DLL.
85 */
86 struct HelloHandle *prev;
87
88 /**
89 * Our plugin.
90 */
91 struct Plugin *plugin;
92
93 /**
94 * Offer handle.
95 */
96 struct GNUNET_TRANSPORT_OfferHelloHandle *ohh;
97
98};
99
100
69/** 101/**
70 * Opaque handle that the underlay offers for our address to be used when 102 * Opaque handle that the underlay offers for our address to be used when
71 * sending messages to another peer. 103 * sending messages to another peer.
@@ -77,7 +109,7 @@ struct GNUNET_DHTU_Source
77 * Application context for this source. 109 * Application context for this source.
78 */ 110 */
79 void *app_ctx; 111 void *app_ctx;
80 112
81 /** 113 /**
82 * Hash position of this peer in the DHT. 114 * Hash position of this peer in the DHT.
83 */ 115 */
@@ -107,7 +139,7 @@ struct GNUNET_DHTU_Target
107 * Our plugin with its environment. 139 * Our plugin with its environment.
108 */ 140 */
109 struct Plugin *plugin; 141 struct Plugin *plugin;
110 142
111 /** 143 /**
112 * CORE MQ to send messages to this peer. 144 * CORE MQ to send messages to this peer.
113 */ 145 */
@@ -117,7 +149,7 @@ struct GNUNET_DHTU_Target
117 * Public key of the peer. 149 * Public key of the peer.
118 */ 150 */
119 struct PublicKey pk; 151 struct PublicKey pk;
120 152
121 /** 153 /**
122 * Hash of the @a pk to identify position of the peer 154 * Hash of the @a pk to identify position of the peer
123 * in the DHT. 155 * in the DHT.
@@ -146,6 +178,7 @@ struct GNUNET_DHTU_Target
146 178
147}; 179};
148 180
181
149/** 182/**
150 * Opaque handle expressing a preference of the DHT to 183 * Opaque handle expressing a preference of the DHT to
151 * keep a particular target connected. 184 * keep a particular target connected.
@@ -174,6 +207,18 @@ struct GNUNET_DHTU_PreferenceHandle
174 */ 207 */
175struct Plugin 208struct Plugin
176{ 209{
210
211 /**
212 * Our "source" address. Traditional CORE API does not tell us which source
213 * it is, so they are all identical.
214 */
215 struct GNUNET_DHTU_Source src;
216
217 /**
218 * My identity.
219 */
220 struct GNUNET_PeerIdentity my_identity;
221
177 /** 222 /**
178 * Callbacks into the DHT. 223 * Callbacks into the DHT.
179 */ 224 */
@@ -188,18 +233,26 @@ struct Plugin
188 * Handle to ATS service. 233 * Handle to ATS service.
189 */ 234 */
190 struct GNUNET_ATS_ConnectivityHandle *ats; 235 struct GNUNET_ATS_ConnectivityHandle *ats;
191 236
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 /** 237 /**
199 * Handle to the NSE service. 238 * Handle to the NSE service.
200 */ 239 */
201 struct GNUNET_NSE_Handle *nse; 240 struct GNUNET_NSE_Handle *nse;
202 241
242 /**
243 * Watching for our address to change.
244 */
245 struct GNUNET_PEERINFO_NotifyContext *nc;
246
247 /**
248 * Hellos we are offering to transport.
249 */
250 struct HelloHandle *hh_head;
251
252 /**
253 * Hellos we are offering to transport.
254 */
255 struct HelloHandle *hh_tail;
203}; 256};
204 257
205 258
@@ -273,6 +326,27 @@ ip_verify (void *cls,
273 326
274 327
275/** 328/**
329 * Function called once a hello offer is completed.
330 *
331 * @param cls a `struct HelloHandle`
332 */
333static void
334hello_offered_cb (void *cls)
335{
336 struct HelloHandle *hh = cls;
337 struct Plugin *plugin = hh->plugin;
338
339 GNUNET_CONTAINER_DLL_remove (plugin->hh_head,
340 plugin->hh_tail,
341 hh);
342 GNUNET_free (hh);
343}
344
345
346#include "../peerinfo-tool/gnunet-peerinfo_plugins.c"
347
348
349/**
276 * Request creation of a session with a peer at the given @a address. 350 * Request creation of a session with a peer at the given @a address.
277 * 351 *
278 * @param cls closure (internal context for the plugin) 352 * @param cls closure (internal context for the plugin)
@@ -283,10 +357,30 @@ ip_try_connect (void *cls,
283 const char *address) 357 const char *address)
284{ 358{
285 struct Plugin *plugin = cls; 359 struct Plugin *plugin = cls;
360 struct GNUNET_HELLO_Message *hello = NULL;
361 struct HelloHandle *hh;
362 struct GNUNET_CRYPTO_EddsaPublicKey pubkey;
363
364 if (GNUNET_OK !=
365 GNUNET_HELLO_parse_uri (address,
366 &pubkey,
367 &hello,
368 &GPI_plugins_find))
369 {
370 GNUNET_break (0);
371 return;
372 }
286 373
287 // FIXME: ask ATS/TRANSPORT to 'connect' 374 hh = GNUNET_new (struct HelloHandle);
288 // => needs HELLO! 375 hh->plugin = plugin;
289 GNUNET_break (0); 376 GNUNET_CONTAINER_DLL_insert (plugin->hh_head,
377 plugin->hh_tail,
378 hh);
379 hh->ohh = GNUNET_TRANSPORT_offer_hello (plugin->env->cfg,
380 &hello->header,
381 &hello_offered_cb,
382 hh);
383 GNUNET_free (hello);
290} 384}
291 385
292 386
@@ -332,7 +426,7 @@ ip_drop (struct GNUNET_DHTU_PreferenceHandle *ph)
332{ 426{
333 struct GNUNET_DHTU_Target *target = ph->target; 427 struct GNUNET_DHTU_Target *target = ph->target;
334 struct Plugin *plugin = target->plugin; 428 struct Plugin *plugin = target->plugin;
335 429
336 GNUNET_CONTAINER_DLL_remove (target->ph_head, 430 GNUNET_CONTAINER_DLL_remove (target->ph_head,
337 target->ph_tail, 431 target->ph_tail,
338 ph); 432 ph);
@@ -390,7 +484,6 @@ ip_send (void *cls,
390} 484}
391 485
392 486
393
394/** 487/**
395 * Method called whenever a given peer connects. 488 * Method called whenever a given peer connects.
396 * 489 *
@@ -448,6 +541,52 @@ core_disconnect_cb (void *cls,
448 541
449 542
450/** 543/**
544 * Find the @a hello for our identity and then pass
545 * it to the DHT as a URL. Note that we only
546 * add addresses, never remove them, due to limitations
547 * of the current peerinfo/core/transport APIs.
548 * This will change with TNG.
549 *
550 * @param cls a `struct Plugin`
551 * @param peer id of the peer, NULL for last call
552 * @param hello hello message for the peer (can be NULL)
553 * @param error message
554 */
555static void
556peerinfo_cb (void *cls,
557 const struct GNUNET_PeerIdentity *peer,
558 const struct GNUNET_HELLO_Message *hello,
559 const char *err_msg)
560{
561 struct Plugin *plugin = cls;
562 char *addr;
563
564 if (NULL == hello)
565 return;
566 if (NULL == peer)
567 return;
568 if (0 !=
569 GNUNET_memcmp (peer,
570 &plugin->my_identity))
571 return;
572 addr = GNUNET_HELLO_compose_uri (hello,
573 &GPI_plugins_find);
574 if (NULL == addr)
575 return;
576 GNUNET_CRYPTO_hash (&plugin->my_identity,
577 sizeof (struct GNUNET_PeerIdentity),
578 &plugin->src.my_id.hc);
579 plugin->env->address_add_cb (plugin->env->cls,
580 &plugin->src.my_id,
581 &plugin->src.pk,
582 addr,
583 &plugin->src,
584 &plugin->src.app_ctx);
585 GNUNET_free (addr);
586}
587
588
589/**
451 * Function called after #GNUNET_CORE_connect has succeeded (or failed 590 * Function called after #GNUNET_CORE_connect has succeeded (or failed
452 * for good). Note that the private key of the peer is intentionally 591 * for good). Note that the private key of the peer is intentionally
453 * not exposed here; if you need it, your process should try to read 592 * not exposed here; if you need it, your process should try to read
@@ -464,27 +603,12 @@ core_init_cb (void *cls,
464 const struct GNUNET_PeerIdentity *my_identity) 603 const struct GNUNET_PeerIdentity *my_identity)
465{ 604{
466 struct Plugin *plugin = cls; 605 struct Plugin *plugin = cls;
467 char *addr; 606
468 char *pid; 607 plugin->my_identity = *my_identity;
469 608 plugin->nc = GNUNET_PEERINFO_notify (plugin->env->cfg,
470 // FIXME: to later ask ATS/TRANSPORT to 'connect' we need a HELLO, 609 GNUNET_NO,
471 // not merely a vanilla PID... 610 &peerinfo_cb,
472 pid = GNUNET_STRINGS_data_to_string_alloc (my_identity, 611 plugin);
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} 612}
489 613
490 614
@@ -561,13 +685,25 @@ libgnunet_plugin_dhtu_gnunet_done (void *cls)
561{ 685{
562 struct GNUNET_DHTU_PluginFunctions *api = cls; 686 struct GNUNET_DHTU_PluginFunctions *api = cls;
563 struct Plugin *plugin = api->cls; 687 struct Plugin *plugin = api->cls;
688 struct HelloHandle *hh;
564 689
690 while (NULL != (hh = plugin->hh_head))
691 {
692 GNUNET_CONTAINER_DLL_remove (plugin->hh_head,
693 plugin->hh_tail,
694 hh);
695 GNUNET_TRANSPORT_offer_hello_cancel (hh->ohh);
696 GNUNET_free (hh);
697 }
565 if (NULL != plugin->nse) 698 if (NULL != plugin->nse)
566 GNUNET_NSE_disconnect (plugin->nse); 699 GNUNET_NSE_disconnect (plugin->nse);
567 if (NULL != plugin->core) 700 if (NULL != plugin->core)
568 GNUNET_CORE_disconnect (plugin->core); 701 GNUNET_CORE_disconnect (plugin->core);
569 if (NULL != plugin->ats) 702 if (NULL != plugin->ats)
570 GNUNET_ATS_connectivity_done (plugin->ats); 703 GNUNET_ATS_connectivity_done (plugin->ats);
704 if (NULL != plugin->nc)
705 GNUNET_PEERINFO_notify_cancel (plugin->nc);
706 GPI_plugins_unload ();
571 GNUNET_free (plugin); 707 GNUNET_free (plugin);
572 GNUNET_free (api); 708 GNUNET_free (api);
573 return NULL; 709 return NULL;
@@ -594,7 +730,7 @@ libgnunet_plugin_dhtu_ip_init (void *cls)
594 GNUNET_MQ_handler_end () 730 GNUNET_MQ_handler_end ()
595 }; 731 };
596 struct GNUNET_CRYPTO_EddsaPrivateKey *pk; 732 struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
597 733
598 pk = GNUNET_CRYPTO_eddsa_key_create_from_configuration (env->cfg); 734 pk = GNUNET_CRYPTO_eddsa_key_create_from_configuration (env->cfg);
599 if (NULL == pk) 735 if (NULL == pk)
600 { 736 {
@@ -631,7 +767,6 @@ libgnunet_plugin_dhtu_ip_init (void *cls)
631 libgnunet_plugin_dhtu_gnunet_done (plugin); 767 libgnunet_plugin_dhtu_gnunet_done (plugin);
632 return NULL; 768 return NULL;
633 } 769 }
770 GPI_plugins_load (env->cfg);
634 return api; 771 return api;
635} 772}
636
637