2 This file is part of GNUnet.
3 (C) 2014 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 #include "gnunet_util_lib.h"
24 #include "gnunet_statistics_service.h"
25 #include "gnunet_peerinfo_service.h"
27 #include "mesh_protocol.h"
28 #include "mesh_path.h"
30 #include "gnunet-service-mesh_hello.h"
31 #include "gnunet-service-mesh_peer.h"
33 #define LOG(level, ...) GNUNET_log_from(level,"mesh-hll",__VA_ARGS__)
36 /******************************************************************************/
37 /******************************** STRUCTS **********************************/
38 /******************************************************************************/
42 /******************************************************************************/
43 /******************************* GLOBALS ***********************************/
44 /******************************************************************************/
47 * Global handle to the statistics service.
49 extern struct GNUNET_STATISTICS_Handle *stats;
52 * Local peer own ID (memory efficient handle).
54 extern GNUNET_PEER_Id myid;
57 * Local peer own ID (full value).
59 extern struct GNUNET_PeerIdentity my_full_id;
63 * Don't try to recover tunnels if shutting down.
65 extern int shutting_down;
69 * Hello message of local peer.
71 const struct GNUNET_HELLO_Message *mine;
74 * Handle to peerinfo service.
76 static struct GNUNET_PEERINFO_Handle *peerinfo;
81 struct GNUNET_PEERINFO_NotifyContext* nc;
84 /******************************************************************************/
85 /******************************** STATIC ***********************************/
86 /******************************************************************************/
89 * Process each hello message received from peerinfo.
91 * @param cls Closure (unused).
92 * @param peer Identity of the peer.
93 * @param hello Hello of the peer.
94 * @param err_msg Error message.
97 got_hello (void *cls, const struct GNUNET_PeerIdentity *id,
98 const struct GNUNET_HELLO_Message *hello,
101 struct MeshPeer *peer;
105 LOG (GNUNET_ERROR_TYPE_ERROR, " hello with NULL id\n");
108 LOG (GNUNET_ERROR_TYPE_INFO, " hello for %s (%d bytes), expires on %s\n",
109 GNUNET_i2s (id), NULL != hello ? GNUNET_HELLO_size (hello) : -1,
110 GNUNET_STRINGS_absolute_time_to_string(GNUNET_HELLO_get_last_expiration(hello)));
113 LOG (GNUNET_ERROR_TYPE_DEBUG, " hello is NULL\n");
117 GMP_set_hello (peer, hello);
119 if (GMP_get_short_id (peer) == myid)
121 mine = GMP_get_hello (peer);
122 LOG (GNUNET_ERROR_TYPE_DEBUG, " updated mine to %p\n", mine);
127 /******************************************************************************/
128 /******************************** API ***********************************/
129 /******************************************************************************/
132 * Initialize the hello subsystem.
134 * @param c Configuration.
137 GMH_init (const struct GNUNET_CONFIGURATION_Handle *c)
139 LOG (GNUNET_ERROR_TYPE_DEBUG, "init\n");
140 GNUNET_assert (NULL == nc);
141 peerinfo = GNUNET_PEERINFO_connect (c);
142 nc = GNUNET_PEERINFO_notify (c, GNUNET_NO, &got_hello, NULL);
147 * Shut down the hello subsystem.
154 GNUNET_PEERINFO_notify_cancel (nc);
157 if (NULL != peerinfo)
159 GNUNET_PEERINFO_disconnect (peerinfo);
166 * Get own hello message.
168 * @return Own hello message.
170 const struct GNUNET_HELLO_Message *
173 LOG (GNUNET_ERROR_TYPE_DEBUG, " mine is %p\n", mine);
179 * Get another peer's hello message.
181 * @param id ID of the peer whose hello message is requested.
183 * @return Hello message, if any (NULL possible).
185 const struct GNUNET_HELLO_Message *
186 GMH_get (const struct GNUNET_PeerIdentity *id)
188 return GMP_get_hello (GMP_get (id));
193 * Convert a hello message to a string.
195 * @param h Hello message.
198 GMH_2s (const struct GNUNET_HELLO_Message *h)
200 return "hello (TODO)";