X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fcadet%2Fgnunet-service-cadet_hello.c;h=6d85de39f6af8561366306dbe926a5cdb6185e43;hb=9c13c44768d048339c5b1c48d4b0ef35000c524d;hp=edb1a96a2e412a4d0f73a7e232646efd8d05de97;hpb=9aaa554470dbff968c6cab7a2850a15318c1f15b;p=oweals%2Fgnunet.git diff --git a/src/cadet/gnunet-service-cadet_hello.c b/src/cadet/gnunet-service-cadet_hello.c index edb1a96a2..6d85de39f 100644 --- a/src/cadet/gnunet-service-cadet_hello.c +++ b/src/cadet/gnunet-service-cadet_hello.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - (C) 2014 Christian Grothoff (and other contributing authors) + Copyright (C) 2014, 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 @@ -14,61 +14,36 @@ 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. + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. */ - +/** + * @file cadet/gnunet-service-cadet_hello.c + * @brief spread knowledge about how to contact other peers from PEERINFO + * @author Bartlomiej Polot + * @author Christian Grothoff + * + * TODO: + * - is most of this necessary/helpful? + * - should we not simply restrict this to OUR hello? + */ #include "platform.h" #include "gnunet_util_lib.h" #include "gnunet_statistics_service.h" #include "gnunet_peerinfo_service.h" - #include "cadet_protocol.h" -#include "cadet_path.h" - +#include "gnunet-service-cadet.h" +#include "gnunet-service-cadet_dht.h" #include "gnunet-service-cadet_hello.h" #include "gnunet-service-cadet_peer.h" #define LOG(level, ...) GNUNET_log_from(level,"cadet-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; +static struct GNUNET_HELLO_Message *mine; /** * Handle to peerinfo service. @@ -78,13 +53,9 @@ static struct GNUNET_PEERINFO_Handle *peerinfo; /** * Iterator context. */ -struct GNUNET_PEERINFO_NotifyContext* nc; +static struct GNUNET_PEERINFO_NotifyContext *nc; -/******************************************************************************/ -/******************************** STATIC ***********************************/ -/******************************************************************************/ - /** * Process each hello message received from peerinfo. * @@ -94,35 +65,38 @@ struct GNUNET_PEERINFO_NotifyContext* nc; * @param err_msg Error message. */ static void -got_hello (void *cls, const struct GNUNET_PeerIdentity *id, +got_hello (void *cls, + const struct GNUNET_PeerIdentity *id, const struct GNUNET_HELLO_Message *hello, const char *err_msg) { struct CadetPeer *peer; - if (NULL == id || NULL == hello) + if ( (NULL == id) || + (NULL == hello) ) + return; + if (0 == memcmp (id, + &my_full_id, + sizeof (struct GNUNET_PeerIdentity))) { - LOG (GNUNET_ERROR_TYPE_DEBUG, " hello with id %p and msg %p\n", id, hello); + GNUNET_free_non_null (mine); + mine = (struct GNUNET_HELLO_Message *) GNUNET_copy_message (&hello->header); + GCD_hello_update (); return; } - LOG (GNUNET_ERROR_TYPE_DEBUG, " hello for %s (%d bytes), expires on %s\n", - GNUNET_i2s (id), GNUNET_HELLO_size (hello), - GNUNET_STRINGS_absolute_time_to_string (GNUNET_HELLO_get_last_expiration(hello))); - peer = GCP_get (id); - GCP_set_hello (peer, hello); - if (GCP_get_short_id (peer) == myid) - { - mine = GCP_get_hello (peer); - LOG (GNUNET_ERROR_TYPE_DEBUG, " updated mine to %p\n", mine); - } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Hello for %s (%d bytes), expires on %s\n", + GNUNET_i2s (id), + GNUNET_HELLO_size (hello), + GNUNET_STRINGS_absolute_time_to_string (GNUNET_HELLO_get_last_expiration (hello))); + peer = GCP_get (id, + GNUNET_YES); + GCP_set_hello (peer, + hello); } -/******************************************************************************/ -/******************************** API ***********************************/ -/******************************************************************************/ - /** * Initialize the hello subsystem. * @@ -131,10 +105,12 @@ got_hello (void *cls, const struct GNUNET_PeerIdentity *id, void GCH_init (const struct GNUNET_CONFIGURATION_Handle *c) { - LOG (GNUNET_ERROR_TYPE_DEBUG, "init\n"); GNUNET_assert (NULL == nc); peerinfo = GNUNET_PEERINFO_connect (c); - nc = GNUNET_PEERINFO_notify (c, GNUNET_NO, &got_hello, NULL); + nc = GNUNET_PEERINFO_notify (c, + GNUNET_NO, + &got_hello, + NULL); } @@ -154,6 +130,11 @@ GCH_shutdown () GNUNET_PEERINFO_disconnect (peerinfo); peerinfo = NULL; } + if (NULL != mine) + { + GNUNET_free (mine); + mine = NULL; + } } @@ -165,34 +146,7 @@ GCH_shutdown () const struct GNUNET_HELLO_Message * GCH_get_mine (void) { - LOG (GNUNET_ERROR_TYPE_DEBUG, " mine is %p\n", mine); return mine; } - -/** - * Get another peer's hello message. - * - * @param id ID of the peer whose hello message is requested. - * - * @return Hello message, if any (NULL possible). - */ -const struct GNUNET_HELLO_Message * -GCH_get (const struct GNUNET_PeerIdentity *id) -{ - return GCP_get_hello (GCP_get (id)); -} - - -/** - * Convert a hello message to a string. - * - * @param h Hello message. - */ -char * -GCH_2s (const struct GNUNET_HELLO_Message *h) -{ - return "hello (TODO)"; -} - - +/* end of gnunet-service-cadet-new_hello.c */