2 This file is part of GNUnet.
3 Copyright (C) 2014, 2017 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
21 * @file cadet/gnunet-service-cadet_hello.c
22 * @brief spread knowledge about how to contact us (get HELLO from peerinfo),
23 * and remember HELLOs of other peers we have an interest in
24 * @author Bartlomiej Polot
25 * @author Christian Grothoff
28 #include "gnunet_util_lib.h"
30 #include "gnunet_statistics_service.h"
31 #include "gnunet_peerinfo_service.h"
32 #include "cadet_protocol.h"
33 #include "gnunet-service-cadet.h"
34 #include "gnunet-service-cadet_dht.h"
35 #include "gnunet-service-cadet_hello.h"
36 #include "gnunet-service-cadet_peer.h"
38 #define LOG(level, ...) GNUNET_log_from(level,"cadet-hll",__VA_ARGS__)
41 * Hello message of local peer.
43 static struct GNUNET_HELLO_Message *mine;
46 * Handle to peerinfo service.
48 static struct GNUNET_PEERINFO_Handle *peerinfo;
53 static struct GNUNET_PEERINFO_NotifyContext *nc;
57 * Process each hello message received from peerinfo.
59 * @param cls Closure (unused).
60 * @param peer Identity of the peer.
61 * @param hello Hello of the peer.
62 * @param err_msg Error message.
66 const struct GNUNET_PeerIdentity *id,
67 const struct GNUNET_HELLO_Message *hello,
70 struct CadetPeer *peer;
77 sizeof (struct GNUNET_PeerIdentity)))
79 GNUNET_free_non_null (mine);
80 mine = (struct GNUNET_HELLO_Message *) GNUNET_copy_message (&hello->header);
85 LOG (GNUNET_ERROR_TYPE_DEBUG,
86 "Hello for %s (%d bytes), expires on %s\n",
88 GNUNET_HELLO_size (hello),
89 GNUNET_STRINGS_absolute_time_to_string (GNUNET_HELLO_get_last_expiration (hello)));
98 * Initialize the hello subsystem.
100 * @param c Configuration.
103 GCH_init (const struct GNUNET_CONFIGURATION_Handle *c)
105 GNUNET_assert (NULL == nc);
106 peerinfo = GNUNET_PEERINFO_connect (c);
107 nc = GNUNET_PEERINFO_notify (c,
115 * Shut down the hello subsystem.
122 GNUNET_PEERINFO_notify_cancel (nc);
125 if (NULL != peerinfo)
127 GNUNET_PEERINFO_disconnect (peerinfo);
139 * Get own hello message.
141 * @return Own hello message.
143 const struct GNUNET_HELLO_Message *
149 /* end of gnunet-service-cadet-new_hello.c */