From: Bart Polot Date: Tue, 4 Feb 2014 12:36:31 +0000 (+0000) Subject: - add hello subsystem to get hellos for known peers X-Git-Tag: initial-import-from-subversion-38251~4811 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=0066f847206caa73b90b01a49d88e408934530dd;p=oweals%2Fgnunet.git - add hello subsystem to get hellos for known peers --- diff --git a/src/mesh/Makefile.am b/src/mesh/Makefile.am index 1ca4c5a49..5c2dc84dc 100644 --- a/src/mesh/Makefile.am +++ b/src/mesh/Makefile.am @@ -69,6 +69,7 @@ gnunet_service_mesh_SOURCES = \ gnunet-service-mesh_local.c gnunet-service-mesh_local.h \ gnunet-service-mesh_peer.c gnunet-service-mesh_peer.h \ gnunet-service-mesh_dht.c gnunet-service-mesh_dht.h \ + gnunet-service-mesh_hello.c gnunet-service-mesh_hello.h \ mesh_path.c mesh_path.h \ mesh_common.c \ gnunet-service-mesh.c @@ -78,12 +79,14 @@ gnunet_service_mesh_LDADD = \ $(top_builddir)/src/core/libgnunetcore.la \ $(top_builddir)/src/dht/libgnunetdht.la \ $(top_builddir)/src/statistics/libgnunetstatistics.la \ + $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \ $(top_builddir)/src/block/libgnunetblock.la gnunet_service_mesh_DEPENDENCIES = \ $(top_builddir)/src/util/libgnunetutil.la \ $(top_builddir)/src/core/libgnunetcore.la \ $(top_builddir)/src/dht/libgnunetdht.la \ $(top_builddir)/src/statistics/libgnunetstatistics.la \ + $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \ $(top_builddir)/src/block/libgnunetblock.la if LINUX gnunet_service_mesh_LDFLAGS = -lrt diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index b4df7cb48..ec402f43b 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c @@ -52,6 +52,7 @@ #include "gnunet-service-mesh_tunnel.h" #include "gnunet-service-mesh_dht.h" #include "gnunet-service-mesh_peer.h" +#include "gnunet-service-mesh_hello.h" /******************************************************************************/ @@ -107,6 +108,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) shutting_down = GNUNET_YES; GML_shutdown (); + GMH_shutdown (); GMD_shutdown (); GMC_shutdown (); GMT_shutdown (); @@ -146,6 +148,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, GNUNET_i2s (&my_full_id)); GML_init (server); /* Local clients */ + GMH_shutdown (c); /* Hellos */ GMC_init (c); /* Connections */ GMP_init (c); /* Peers */ GMD_init (c); /* DHT */ diff --git a/src/mesh/gnunet-service-mesh_hello.c b/src/mesh/gnunet-service-mesh_hello.c new file mode 100644 index 000000000..5ebf030f5 --- /dev/null +++ b/src/mesh/gnunet-service-mesh_hello.c @@ -0,0 +1,159 @@ +/* + This file is part of GNUnet. + (C) 2014 Christian Grothoff (and other contributing authors) + + 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., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#include "platform.h" +#include "gnunet_util_lib.h" + +#include "gnunet_statistics_service.h" +#include "gnunet_peerinfo_service.h" + +#include "mesh_protocol.h" +#include "mesh_path.h" + +#include "gnunet-service-mesh_hello.h" +#include "gnunet-service-mesh_peer.h" + +#define LOG(level, ...) GNUNET_log_from(level,"mesh-hll",__VA_ARGS__) + + +/******************************************************************************/ +/******************************** STRUCTS **********************************/ +/******************************************************************************/ + + + +/******************************************************************************/ +/******************************* GLOBALS ***********************************/ +/******************************************************************************/ + +/** + * Global handle to the statistics service. + */ +extern struct GNUNET_STATISTICS_Handle *stats; + +/** + * Local peer own ID (memory efficient handle). + */ +extern GNUNET_PEER_Id myid; + +/** + * Local peer own ID (full value). + */ +extern struct GNUNET_PeerIdentity my_full_id; + + +/** + * Don't try to recover tunnels if shutting down. + */ +extern int shutting_down; + + +/** + * Hello message of local peer. + */ +const struct GNUNET_HELLO_Message *mine; + +/** + * Handle to peerinfo service. + */ +static struct GNUNET_PEERINFO_Handle *peerinfo; + +/** + * Iterator context. + */ +struct GNUNET_PEERINFO_NotifyContext* nc; + + +/******************************************************************************/ +/******************************** STATIC ***********************************/ +/******************************************************************************/ + +/** + * Process each hello message received from peerinfo. + * + * @param cls the 'struct GetUriContext' + * @param peer identity of the peer + * @param hello addresses of the peer + * @param err_msg error message + */ +static void +got_hello (void *cls, const struct GNUNET_PeerIdentity *id, + const struct GNUNET_HELLO_Message *hello, + const char *err_msg) +{ + struct MeshPeer *peer; + + if (NULL == id) + LOG (GNUNET_ERROR_TYPE_ERROR, "not a valid id\n"); + + peer = GMP_get (id); + GMP_set_hello (peer, hello); +} + + +/******************************************************************************/ +/******************************** API ***********************************/ +/******************************************************************************/ + + +void +GMH_init (const struct GNUNET_CONFIGURATION_Handle *c) +{ + GNUNET_assert (NULL != nc); + peerinfo = GNUNET_PEERINFO_connect (c); + nc = GNUNET_PEERINFO_notify (c, GNUNET_NO, &got_hello, NULL); +} + + +void +GMH_shutdown () +{ + if (NULL != nc) + { + GNUNET_PEERINFO_notify_cancel (nc); + nc = NULL; + } + if (NULL != peerinfo) + { + GNUNET_PEERINFO_disconnect (peerinfo); + peerinfo = NULL; + } +} + + +const struct GNUNET_HELLO_Message * +GMH_get_mine (void) +{ + return mine; +} + + +const struct GNUNET_HELLO_Message * +GMH_get (const struct GNUNET_PeerIdentity *id) +{ + return GMP_get_hello (GMP_get (id)); +} + +void +GMH_2s () +{ +} + + diff --git a/src/mesh/gnunet-service-mesh_hello.h b/src/mesh/gnunet-service-mesh_hello.h new file mode 100644 index 000000000..866d7abb6 --- /dev/null +++ b/src/mesh/gnunet-service-mesh_hello.h @@ -0,0 +1,61 @@ +/* + This file is part of GNUnet. + (C) 2014 Christian Grothoff (and other contributing authors) + + 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., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/** + * @file mesh/gnunet-service-mesh_hello.h + * @brief mesh service; dealing with hello messages + * @author Bartlomiej Polot + * + * All functions in this file should use the prefix GMH (Gnunet Mesh Hello) + */ + +#ifndef GNUNET_SERVICE_MESH_HELLO_H +#define GNUNET_SERVICE_MESH_HELLO_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +#include "platform.h" +#include "gnunet_util_lib.h" + + +void +GMH_init (const struct GNUNET_CONFIGURATION_Handle *c); + +void +GMH_shutdown (); + + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +/* ifndef GNUNET_MESH_SERVICE_HELLO_H */ +#endif +/* end of gnunet-mesh-service_hello.h */