From: Christian Grothoff Date: Tue, 17 Jan 2017 13:44:50 +0000 (+0100) Subject: starting with CORE subsystem for CADET X-Git-Tag: taler-0.2.1~425 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=164d087730902feaef22c420fa4e00b12a66cd57;p=oweals%2Fgnunet.git starting with CORE subsystem for CADET --- diff --git a/src/cadet/Makefile.am b/src/cadet/Makefile.am index ba93bee18..53d17dd9c 100644 --- a/src/cadet/Makefile.am +++ b/src/cadet/Makefile.am @@ -52,6 +52,7 @@ gnunet_service_cadet_new_SOURCES = \ gnunet-service-cadet-new.c gnunet-service-cadet-new.h \ gnunet-service-cadet-new_channel.c gnunet-service-cadet-new_channel.h \ gnunet-service-cadet-new_connection.c gnunet-service-cadet-new_connection.h \ + gnunet-service-cadet-new_core.c gnunet-service-cadet-new_core.h \ gnunet-service-cadet-new_dht.c gnunet-service-cadet-new_dht.h \ gnunet-service-cadet-new_hello.c gnunet-service-cadet-new_hello.h \ gnunet-service-cadet-new_tunnels.c gnunet-service-cadet-new_tunnels.h \ diff --git a/src/cadet/gnunet-service-cadet-new.c b/src/cadet/gnunet-service-cadet-new.c index 3bb7d9cdf..ad68f09b1 100644 --- a/src/cadet/gnunet-service-cadet-new.c +++ b/src/cadet/gnunet-service-cadet-new.c @@ -40,6 +40,7 @@ #include "gnunet-service-cadet-new.h" #include "gnunet-service-cadet-new_channel.h" #include "gnunet-service-cadet-new_connection.h" +#include "gnunet-service-cadet-new_core.h" #include "gnunet-service-cadet-new_dht.h" #include "gnunet-service-cadet-new_hello.h" #include "gnunet-service-cadet-new_tunnels.h" @@ -308,7 +309,7 @@ shutdown_task (void *cls) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shutting down\n"); shutting_down = GNUNET_YES; - + GCO_shutdown (); if (NULL != stats) { GNUNET_STATISTICS_destroy (stats, @@ -1281,6 +1282,7 @@ run (void *cls, GNUNET_YES); GCH_init (c); GCD_init (c); + GCO_init (c); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "CADET starting at peer %s\n", GNUNET_i2s (&my_full_id)); diff --git a/src/cadet/gnunet-service-cadet-new_core.c b/src/cadet/gnunet-service-cadet-new_core.c new file mode 100644 index 000000000..a24f7a3ce --- /dev/null +++ b/src/cadet/gnunet-service-cadet-new_core.c @@ -0,0 +1,141 @@ +/* + This file is part of GNUnet. + Copyright (C) 2017 GNUnet e.V. + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +/** + * @file cadet/gnunet-service-cadet_core.c + * @brief cadet service; interaction with CORE service + * @author Bartlomiej Polot + * @author Christian Grothoff + * + * All functions in this file should use the prefix GCO (Gnunet Cadet cOre (bottom)) + */ +#include "platform.h" +#include "gnunet-service-cadet-new_core.h" +#include "gnunet-service-cadet-new_peer.h" +#include "gnunet-service-cadet-new_connection.h" +#include "gnunet_core_service.h" + +/** + * Handle to the CORE service. + */ +static struct GNUNET_CORE_Handle *core; + + +/** + * 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) +{ + if (NULL == my_identity) + { + GNUNET_break (0); + return; + } + GNUNET_break (0 == + memcmp (my_identity, + &my_full_id, + sizeof (struct GNUNET_PeerIdentity))); +} + + +/** + * Method called whenever a given peer connects. + * + * @param cls closure + * @param peer peer identity this notification is about + */ +static void * +core_connect_cb (void *cls, + const struct GNUNET_PeerIdentity *peer, + struct GNUNET_MQ_Handle *mq) +{ + struct CadetPeer *cp; + + cp = GCP_get (peer, + GNUNET_YES); + GCP_set_mq (cp, + mq); + return cp; +} + + +/** + * Method called whenever a peer disconnects. + * + * @param cls closure + * @param peer peer identity this notification is about + */ +static void +core_disconnect_cb (void *cls, + const struct GNUNET_PeerIdentity *peer, + void *peer_cls) +{ + struct CadetPeer *cp = peer_cls; + + GCP_set_mq (cp, + NULL); +} + + +/** + * Initialize the CORE subsystem. + * + * @param c Configuration. + */ +void +GCO_init (const struct GNUNET_CONFIGURATION_Handle *c) +{ + struct GNUNET_MQ_MessageHandler handlers[] = { + GNUNET_MQ_handler_end () + }; + core = GNUNET_CORE_connect (c, + NULL, + &core_init_cb, + &core_connect_cb, + &core_disconnect_cb, + handlers); +} + + +/** + * Shut down the CORE subsystem. + */ +void +GCO_shutdown () +{ + if (NULL != core) + { + GNUNET_CORE_disconnect (core); + core = NULL; + } +} + +/* end of gnunet-cadet-service_core.c */ diff --git a/src/cadet/gnunet-service-cadet-new_core.h b/src/cadet/gnunet-service-cadet-new_core.h new file mode 100644 index 000000000..261007a6c --- /dev/null +++ b/src/cadet/gnunet-service-cadet-new_core.h @@ -0,0 +1,70 @@ +/* + This file is part of GNUnet. + Copyright (C) 2017 GNUnet e.V. + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +/** + * @file cadet/gnunet-service-cadet_core.h + * @brief cadet service; interaction with CORE service + * @author Bartlomiej Polot + * @author Christian Grothoff + * + * All functions in this file should use the prefix GCO (Gnunet Cadet cOre (bottom)) + */ + +#ifndef GNUNET_SERVICE_CADET_CORE_H +#define GNUNET_SERVICE_CADET_CORE_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +#include "gnunet_util_lib.h" +#include "gnunet_core_service.h" + + +/** + * Initialize the CORE subsystem. + * + * @param c Configuration. + */ +void +GCO_init (const struct GNUNET_CONFIGURATION_Handle *c); + + +/** + * Shut down the CORE subsystem. + */ +void +GCO_shutdown (void); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +/* ifndef GNUNET_CADET_SERVICE_CORE_H */ +#endif +/* end of gnunet-cadet-service_core.h */