diff options
Diffstat (limited to 'src/dhtu/plugin_dhtu_gnunet.c')
-rw-r--r-- | src/dhtu/plugin_dhtu_gnunet.c | 137 |
1 files changed, 136 insertions, 1 deletions
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); |