diff options
author | Christian Grothoff <grothoff@gnunet.org> | 2021-09-19 23:35:17 +0200 |
---|---|---|
committer | Christian Grothoff <grothoff@gnunet.org> | 2021-09-19 23:35:17 +0200 |
commit | 48896731e966376ec6f256e175e0d12cd17afa42 (patch) | |
tree | 91d6e73d6861956831f22a644bef1026eecd8ec5 /src/dhtu | |
parent | 10eac9bb7230973e2c37be9181c36bd086ca38de (diff) | |
download | gnunet-48896731e966376ec6f256e175e0d12cd17afa42.tar.gz gnunet-48896731e966376ec6f256e175e0d12cd17afa42.zip |
more dhtu-gnunet basics
Diffstat (limited to 'src/dhtu')
-rw-r--r-- | src/dhtu/Makefile.am | 1 | ||||
-rw-r--r-- | src/dhtu/plugin_dhtu_gnunet.c | 71 |
2 files changed, 72 insertions, 0 deletions
diff --git a/src/dhtu/Makefile.am b/src/dhtu/Makefile.am index 4bc96f236..f4b968526 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/core/libgnunetcore.la \ | ||
31 | $(top_builddir)/src/util/libgnunetutil.la \ | 32 | $(top_builddir)/src/util/libgnunetutil.la \ |
32 | $(XLIBS) \ | 33 | $(XLIBS) \ |
33 | $(LTLIBINTL) | 34 | $(LTLIBINTL) |
diff --git a/src/dhtu/plugin_dhtu_gnunet.c b/src/dhtu/plugin_dhtu_gnunet.c index 9597ebdc0..ccd329e8e 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_core_service.h" | ||
29 | 30 | ||
30 | /** | 31 | /** |
31 | * Handle for a private key used by this underlay. | 32 | * Handle for a private key used by this underlay. |
@@ -134,6 +135,12 @@ struct Plugin | |||
134 | * Callbacks into the DHT. | 135 | * Callbacks into the DHT. |
135 | */ | 136 | */ |
136 | struct GNUNET_DHTU_PluginEnvironment *env; | 137 | struct GNUNET_DHTU_PluginEnvironment *env; |
138 | |||
139 | /** | ||
140 | * Handle to the CORE service. | ||
141 | */ | ||
142 | struct GNUNET_CORE_Handle *core; | ||
143 | |||
137 | }; | 144 | }; |
138 | 145 | ||
139 | 146 | ||
@@ -290,6 +297,60 @@ ip_send (void *cls, | |||
290 | } | 297 | } |
291 | 298 | ||
292 | 299 | ||
300 | |||
301 | /** | ||
302 | * Method called whenever a given peer connects. | ||
303 | * | ||
304 | * @param cls closure | ||
305 | * @param peer peer identity this notification is about | ||
306 | * @return closure associated with @a peer. given to mq callbacks and | ||
307 | * #GNUNET_CORE_DisconnectEventHandler | ||
308 | */ | ||
309 | static void * | ||
310 | core_connect_cb (void *cls, | ||
311 | const struct GNUNET_PeerIdentity *peer, | ||
312 | struct GNUNET_MQ_Handle *mq) | ||
313 | { | ||
314 | return NULL; | ||
315 | } | ||
316 | |||
317 | |||
318 | /** | ||
319 | * Method called whenever a peer disconnects. | ||
320 | * | ||
321 | * @param cls closure | ||
322 | * @param peer peer identity this notification is about | ||
323 | * @param peer_cls closure associated with peer. given in | ||
324 | * #GNUNET_CORE_ConnectEventHandler | ||
325 | */ | ||
326 | static void | ||
327 | core_disconnect_cb (void *cls, | ||
328 | const struct GNUNET_PeerIdentity *peer, | ||
329 | void *peer_cls) | ||
330 | { | ||
331 | } | ||
332 | |||
333 | |||
334 | /** | ||
335 | * Function called after #GNUNET_CORE_connect has succeeded (or failed | ||
336 | * for good). Note that the private key of the peer is intentionally | ||
337 | * not exposed here; if you need it, your process should try to read | ||
338 | * the private key file directly (which should work if you are | ||
339 | * authorized...). Implementations of this function must not call | ||
340 | * #GNUNET_CORE_disconnect (other than by scheduling a new task to | ||
341 | * do this later). | ||
342 | * | ||
343 | * @param cls closure | ||
344 | * @param my_identity ID of this peer, NULL if we failed | ||
345 | */ | ||
346 | static void | ||
347 | core_init_cb (void *cls, | ||
348 | const struct GNUNET_PeerIdentity *my_identity) | ||
349 | { | ||
350 | struct Plugin *plugin = cls; | ||
351 | } | ||
352 | |||
353 | |||
293 | /** | 354 | /** |
294 | * Entry point for the plugin. | 355 | * Entry point for the plugin. |
295 | * | 356 | * |
@@ -302,6 +363,9 @@ libgnunet_plugin_dhtu_ip_init (void *cls) | |||
302 | struct GNUNET_DHTU_PluginEnvironment *env = cls; | 363 | struct GNUNET_DHTU_PluginEnvironment *env = cls; |
303 | struct GNUNET_DHTU_PluginFunctions *api; | 364 | struct GNUNET_DHTU_PluginFunctions *api; |
304 | struct Plugin *plugin; | 365 | struct Plugin *plugin; |
366 | struct GNUNET_MQ_MessageHandler handlers[] = { | ||
367 | GNUNET_MQ_handler_end () | ||
368 | }; | ||
305 | 369 | ||
306 | plugin = GNUNET_new (struct Plugin); | 370 | plugin = GNUNET_new (struct Plugin); |
307 | plugin->env = env; | 371 | plugin->env = env; |
@@ -313,6 +377,12 @@ libgnunet_plugin_dhtu_ip_init (void *cls) | |||
313 | api->hold = &ip_hold; | 377 | api->hold = &ip_hold; |
314 | api->drop = &ip_drop; | 378 | api->drop = &ip_drop; |
315 | api->send = &ip_send; | 379 | api->send = &ip_send; |
380 | plugin->core = GNUNET_CORE_connect (env->cfg, | ||
381 | plugin, | ||
382 | &core_init_cb, | ||
383 | &core_connect_cb, | ||
384 | &core_disconnect_cb, | ||
385 | handlers); | ||
316 | return api; | 386 | return api; |
317 | } | 387 | } |
318 | 388 | ||
@@ -329,6 +399,7 @@ libgnunet_plugin_dhtu_gnunet_done (void *cls) | |||
329 | struct GNUNET_DHTU_PluginFunctions *api = cls; | 399 | struct GNUNET_DHTU_PluginFunctions *api = cls; |
330 | struct Plugin *plugin = api->cls; | 400 | struct Plugin *plugin = api->cls; |
331 | 401 | ||
402 | GNUNET_CORE_disconnect (plugin->core); | ||
332 | GNUNET_free (plugin); | 403 | GNUNET_free (plugin); |
333 | GNUNET_free (api); | 404 | GNUNET_free (api); |
334 | return NULL; | 405 | return NULL; |