From 48896731e966376ec6f256e175e0d12cd17afa42 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 19 Sep 2021 23:35:17 +0200 Subject: more dhtu-gnunet basics --- src/dhtu/Makefile.am | 1 + src/dhtu/plugin_dhtu_gnunet.c | 71 ++++++++++++++++++++++++++++++++++ src/include/gnunet_hello_lib.h | 7 ++-- src/include/gnunet_mq_lib.h | 21 ++++++---- src/include/gnunet_transport_service.h | 21 ++++++---- 5 files changed, 103 insertions(+), 18 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 = \ libgnunet_plugin_dhtu_gnunet_la_SOURCES = \ plugin_dhtu_gnunet.c libgnunet_plugin_dhtu_gnunet_la_LIBADD = \ + $(top_builddir)/src/core/libgnunetcore.la \ $(top_builddir)/src/util/libgnunetutil.la \ $(XLIBS) \ $(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 @@ */ #include "platform.h" #include "gnunet_dhtu_plugin.h" +#include "gnunet_core_service.h" /** * Handle for a private key used by this underlay. @@ -134,6 +135,12 @@ struct Plugin * Callbacks into the DHT. */ struct GNUNET_DHTU_PluginEnvironment *env; + + /** + * Handle to the CORE service. + */ + struct GNUNET_CORE_Handle *core; + }; @@ -290,6 +297,60 @@ ip_send (void *cls, } + +/** + * Method called whenever a given peer connects. + * + * @param cls closure + * @param peer peer identity this notification is about + * @return closure associated with @a peer. given to mq callbacks and + * #GNUNET_CORE_DisconnectEventHandler + */ +static void * +core_connect_cb (void *cls, + const struct GNUNET_PeerIdentity *peer, + struct GNUNET_MQ_Handle *mq) +{ + return NULL; +} + + +/** + * Method called whenever a peer disconnects. + * + * @param cls closure + * @param peer peer identity this notification is about + * @param peer_cls closure associated with peer. given in + * #GNUNET_CORE_ConnectEventHandler + */ +static void +core_disconnect_cb (void *cls, + const struct GNUNET_PeerIdentity *peer, + void *peer_cls) +{ +} + + +/** + * Function called after #GNUNET_CORE_connect has succeeded (or failed + * for good). Note that the private key of the peer is intentionally + * not exposed here; if you need it, your process should try to read + * the private key file directly (which should work if you are + * authorized...). Implementations of this function must not call + * #GNUNET_CORE_disconnect (other than by scheduling a new task to + * do this later). + * + * @param cls closure + * @param my_identity ID of this peer, NULL if we failed + */ +static void +core_init_cb (void *cls, + const struct GNUNET_PeerIdentity *my_identity) +{ + struct Plugin *plugin = cls; +} + + /** * Entry point for the plugin. * @@ -302,6 +363,9 @@ libgnunet_plugin_dhtu_ip_init (void *cls) struct GNUNET_DHTU_PluginEnvironment *env = cls; struct GNUNET_DHTU_PluginFunctions *api; struct Plugin *plugin; + struct GNUNET_MQ_MessageHandler handlers[] = { + GNUNET_MQ_handler_end () + }; plugin = GNUNET_new (struct Plugin); plugin->env = env; @@ -313,6 +377,12 @@ libgnunet_plugin_dhtu_ip_init (void *cls) api->hold = &ip_hold; api->drop = &ip_drop; api->send = &ip_send; + plugin->core = GNUNET_CORE_connect (env->cfg, + plugin, + &core_init_cb, + &core_connect_cb, + &core_disconnect_cb, + handlers); return api; } @@ -329,6 +399,7 @@ libgnunet_plugin_dhtu_gnunet_done (void *cls) struct GNUNET_DHTU_PluginFunctions *api = cls; struct Plugin *plugin = api->cls; + GNUNET_CORE_disconnect (plugin->core); GNUNET_free (plugin); GNUNET_free (api); return NULL; diff --git a/src/include/gnunet_hello_lib.h b/src/include/gnunet_hello_lib.h index fff0045aa..74eca999d 100644 --- a/src/include/gnunet_hello_lib.h +++ b/src/include/gnunet_hello_lib.h @@ -268,9 +268,10 @@ GNUNET_HELLO_add_address (const struct GNUNET_HELLO_Address *address, * @return number of bytes written or 0, #GNUNET_SYSERR to signal the * end of the iteration. */ -typedef ssize_t (*GNUNET_HELLO_GenerateAddressListCallback) (void *cls, - size_t max, - void *buf); +typedef ssize_t +(*GNUNET_HELLO_GenerateAddressListCallback) (void *cls, + size_t max, + void *buf); /** diff --git a/src/include/gnunet_mq_lib.h b/src/include/gnunet_mq_lib.h index 37bba8c1b..765647a98 100644 --- a/src/include/gnunet_mq_lib.h +++ b/src/include/gnunet_mq_lib.h @@ -331,9 +331,10 @@ typedef int (*GNUNET_MQ_MessageValidationCallback) ( * @param msg the message to send * @param impl_state state of the implementation */ -typedef void (*GNUNET_MQ_SendImpl) (struct GNUNET_MQ_Handle *mq, - const struct GNUNET_MessageHeader *msg, - void *impl_state); +typedef void +(*GNUNET_MQ_SendImpl) (struct GNUNET_MQ_Handle *mq, + const struct GNUNET_MessageHeader *msg, + void *impl_state); /** @@ -345,8 +346,9 @@ typedef void (*GNUNET_MQ_SendImpl) (struct GNUNET_MQ_Handle *mq, * @param mq the message queue to destroy * @param impl_state state of the implementation */ -typedef void (*GNUNET_MQ_DestroyImpl) (struct GNUNET_MQ_Handle *mq, - void *impl_state); +typedef void +(*GNUNET_MQ_DestroyImpl) (struct GNUNET_MQ_Handle *mq, + void *impl_state); /** @@ -355,8 +357,9 @@ typedef void (*GNUNET_MQ_DestroyImpl) (struct GNUNET_MQ_Handle *mq, * @param mq message queue * @param impl_state state specific to the implementation */ -typedef void (*GNUNET_MQ_CancelImpl) (struct GNUNET_MQ_Handle *mq, - void *impl_state); +typedef void +(*GNUNET_MQ_CancelImpl) (struct GNUNET_MQ_Handle *mq, + void *impl_state); /** @@ -368,7 +371,9 @@ typedef void (*GNUNET_MQ_CancelImpl) (struct GNUNET_MQ_Handle *mq, * @param cls closure * @param error error code */ -typedef void (*GNUNET_MQ_ErrorHandler) (void *cls, enum GNUNET_MQ_Error error); +typedef void +(*GNUNET_MQ_ErrorHandler) (void *cls, + enum GNUNET_MQ_Error error); /** diff --git a/src/include/gnunet_transport_service.h b/src/include/gnunet_transport_service.h index d190eff92..545bb28d2 100644 --- a/src/include/gnunet_transport_service.h +++ b/src/include/gnunet_transport_service.h @@ -115,7 +115,8 @@ struct GNUNET_TRANSPORT_AddressToStringContext; * if #GNUNET_NO: address was invalid (or not supported) * if #GNUNET_SYSERR: communication error (IPC error) */ -typedef void (*GNUNET_TRANSPORT_AddressToStringCallback) (void *cls, +typedef void +(*GNUNET_TRANSPORT_AddressToStringCallback) (void *cls, const char *address, int res); @@ -326,7 +327,8 @@ struct GNUNET_TRANSPORT_PeerMonitoringContext; * @param state current state this peer is in * @param state_timeout timeout for the current state of the peer */ -typedef void (*GNUNET_TRANSPORT_PeerIterateCallback) ( +typedef void +(*GNUNET_TRANSPORT_PeerIterateCallback) ( void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Address *address, @@ -394,7 +396,8 @@ struct GNUNET_TRANSPORT_Blacklist; * @param pid peer to approve or disapproave * @return #GNUNET_OK if the connection is allowed, #GNUNET_SYSERR if not */ -typedef int (*GNUNET_TRANSPORT_BlacklistCallback) ( +typedef int +(*GNUNET_TRANSPORT_BlacklistCallback) ( void *cls, const struct GNUNET_PeerIdentity *pid); @@ -541,7 +544,8 @@ struct GNUNET_TRANSPORT_SessionInfo * NULL with @a session being non-NULL if the monitor * was being cancelled while sessions were active */ -typedef void (*GNUNET_TRANSPORT_SessionMonitorCallback) ( +typedef void +(*GNUNET_TRANSPORT_SessionMonitorCallback) ( void *cls, struct GNUNET_TRANSPORT_PluginSession *session, void **session_ctx, @@ -593,7 +597,8 @@ struct GNUNET_TRANSPORT_CoreHandle; * @param mq message queue to use to transmit to @a peer * @return closure to use in MQ handlers */ -typedef void *(*GNUNET_TRANSPORT_NotifyConnect) ( +typedef void * +(*GNUNET_TRANSPORT_NotifyConnect) ( void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq); @@ -610,7 +615,8 @@ typedef void *(*GNUNET_TRANSPORT_NotifyConnect) ( * @param handlers_cls closure of the handlers, was returned from the * connect notification callback */ -typedef void (*GNUNET_TRANSPORT_NotifyDisconnect) ( +typedef void +(*GNUNET_TRANSPORT_NotifyDisconnect) ( void *cls, const struct GNUNET_PeerIdentity *peer, void *handler_cls); @@ -632,7 +638,8 @@ typedef void (*GNUNET_TRANSPORT_NotifyDisconnect) ( * @param handlers_cls closure of the handlers, was returned from the * connect notification callback */ -typedef void (*GNUNET_TRANSPORT_NotifyExcessBandwidth) ( +typedef void +(*GNUNET_TRANSPORT_NotifyExcessBandwidth) ( void *cls, const struct GNUNET_PeerIdentity *neighbour, void *handlers_cls); -- cgit v1.2.3