aboutsummaryrefslogtreecommitdiff
path: root/src/cadet/gnunet-service-cadet_hello.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cadet/gnunet-service-cadet_hello.c')
-rw-r--r--src/cadet/gnunet-service-cadet_hello.c140
1 files changed, 46 insertions, 94 deletions
diff --git a/src/cadet/gnunet-service-cadet_hello.c b/src/cadet/gnunet-service-cadet_hello.c
index 3c63f3551..6d85de39f 100644
--- a/src/cadet/gnunet-service-cadet_hello.c
+++ b/src/cadet/gnunet-service-cadet_hello.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2014 GNUnet e.V. 3 Copyright (C) 2014, 2017 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published
@@ -17,58 +17,33 @@
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA. 18 Boston, MA 02110-1301, USA.
19*/ 19*/
20 20/**
21 * @file cadet/gnunet-service-cadet_hello.c
22 * @brief spread knowledge about how to contact other peers from PEERINFO
23 * @author Bartlomiej Polot
24 * @author Christian Grothoff
25 *
26 * TODO:
27 * - is most of this necessary/helpful?
28 * - should we not simply restrict this to OUR hello?
29 */
21#include "platform.h" 30#include "platform.h"
22#include "gnunet_util_lib.h" 31#include "gnunet_util_lib.h"
23 32
24#include "gnunet_statistics_service.h" 33#include "gnunet_statistics_service.h"
25#include "gnunet_peerinfo_service.h" 34#include "gnunet_peerinfo_service.h"
26
27#include "cadet_protocol.h" 35#include "cadet_protocol.h"
28#include "cadet_path.h" 36#include "gnunet-service-cadet.h"
29 37#include "gnunet-service-cadet_dht.h"
30#include "gnunet-service-cadet_hello.h" 38#include "gnunet-service-cadet_hello.h"
31#include "gnunet-service-cadet_peer.h" 39#include "gnunet-service-cadet_peer.h"
32 40
33#define LOG(level, ...) GNUNET_log_from(level,"cadet-hll",__VA_ARGS__) 41#define LOG(level, ...) GNUNET_log_from(level,"cadet-hll",__VA_ARGS__)
34 42
35
36/******************************************************************************/
37/******************************** STRUCTS **********************************/
38/******************************************************************************/
39
40
41
42/******************************************************************************/
43/******************************* GLOBALS ***********************************/
44/******************************************************************************/
45
46/**
47 * Global handle to the statistics service.
48 */
49extern struct GNUNET_STATISTICS_Handle *stats;
50
51/**
52 * Local peer own ID (memory efficient handle).
53 */
54extern GNUNET_PEER_Id myid;
55
56/**
57 * Local peer own ID (full value).
58 */
59extern struct GNUNET_PeerIdentity my_full_id;
60
61
62/**
63 * Don't try to recover tunnels if shutting down.
64 */
65extern int shutting_down;
66
67
68/** 43/**
69 * Hello message of local peer. 44 * Hello message of local peer.
70 */ 45 */
71const struct GNUNET_HELLO_Message *mine; 46static struct GNUNET_HELLO_Message *mine;
72 47
73/** 48/**
74 * Handle to peerinfo service. 49 * Handle to peerinfo service.
@@ -78,13 +53,9 @@ static struct GNUNET_PEERINFO_Handle *peerinfo;
78/** 53/**
79 * Iterator context. 54 * Iterator context.
80 */ 55 */
81struct GNUNET_PEERINFO_NotifyContext* nc; 56static struct GNUNET_PEERINFO_NotifyContext *nc;
82 57
83 58
84/******************************************************************************/
85/******************************** STATIC ***********************************/
86/******************************************************************************/
87
88/** 59/**
89 * Process each hello message received from peerinfo. 60 * Process each hello message received from peerinfo.
90 * 61 *
@@ -94,31 +65,37 @@ struct GNUNET_PEERINFO_NotifyContext* nc;
94 * @param err_msg Error message. 65 * @param err_msg Error message.
95 */ 66 */
96static void 67static void
97got_hello (void *cls, const struct GNUNET_PeerIdentity *id, 68got_hello (void *cls,
69 const struct GNUNET_PeerIdentity *id,
98 const struct GNUNET_HELLO_Message *hello, 70 const struct GNUNET_HELLO_Message *hello,
99 const char *err_msg) 71 const char *err_msg)
100{ 72{
101 struct CadetPeer *peer; 73 struct CadetPeer *peer;
102 74
103 if (NULL == id || NULL == hello) 75 if ( (NULL == id) ||
76 (NULL == hello) )
77 return;
78 if (0 == memcmp (id,
79 &my_full_id,
80 sizeof (struct GNUNET_PeerIdentity)))
104 { 81 {
105 LOG (GNUNET_ERROR_TYPE_DEBUG, " hello with id %p and msg %p\n", id, hello); 82 GNUNET_free_non_null (mine);
83 mine = (struct GNUNET_HELLO_Message *) GNUNET_copy_message (&hello->header);
84 GCD_hello_update ();
106 return; 85 return;
107 } 86 }
108 LOG (GNUNET_ERROR_TYPE_DEBUG, " hello for %s (%d bytes), expires on %s\n",
109 GNUNET_i2s (id), GNUNET_HELLO_size (hello),
110 GNUNET_STRINGS_absolute_time_to_string (GNUNET_HELLO_get_last_expiration(hello)));
111 peer = GCP_get (id, GNUNET_YES);
112 GCP_set_hello (peer, hello);
113
114 if (GCP_get_short_id (peer) == myid)
115 mine = GCP_get_hello (peer);
116}
117 87
88 LOG (GNUNET_ERROR_TYPE_DEBUG,
89 "Hello for %s (%d bytes), expires on %s\n",
90 GNUNET_i2s (id),
91 GNUNET_HELLO_size (hello),
92 GNUNET_STRINGS_absolute_time_to_string (GNUNET_HELLO_get_last_expiration (hello)));
93 peer = GCP_get (id,
94 GNUNET_YES);
95 GCP_set_hello (peer,
96 hello);
97}
118 98
119/******************************************************************************/
120/******************************** API ***********************************/
121/******************************************************************************/
122 99
123/** 100/**
124 * Initialize the hello subsystem. 101 * Initialize the hello subsystem.
@@ -128,10 +105,12 @@ got_hello (void *cls, const struct GNUNET_PeerIdentity *id,
128void 105void
129GCH_init (const struct GNUNET_CONFIGURATION_Handle *c) 106GCH_init (const struct GNUNET_CONFIGURATION_Handle *c)
130{ 107{
131 LOG (GNUNET_ERROR_TYPE_DEBUG, "init\n");
132 GNUNET_assert (NULL == nc); 108 GNUNET_assert (NULL == nc);
133 peerinfo = GNUNET_PEERINFO_connect (c); 109 peerinfo = GNUNET_PEERINFO_connect (c);
134 nc = GNUNET_PEERINFO_notify (c, GNUNET_NO, &got_hello, NULL); 110 nc = GNUNET_PEERINFO_notify (c,
111 GNUNET_NO,
112 &got_hello,
113 NULL);
135} 114}
136 115
137 116
@@ -141,7 +120,6 @@ GCH_init (const struct GNUNET_CONFIGURATION_Handle *c)
141void 120void
142GCH_shutdown () 121GCH_shutdown ()
143{ 122{
144 LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down channels\n");
145 if (NULL != nc) 123 if (NULL != nc)
146 { 124 {
147 GNUNET_PEERINFO_notify_cancel (nc); 125 GNUNET_PEERINFO_notify_cancel (nc);
@@ -152,6 +130,11 @@ GCH_shutdown ()
152 GNUNET_PEERINFO_disconnect (peerinfo); 130 GNUNET_PEERINFO_disconnect (peerinfo);
153 peerinfo = NULL; 131 peerinfo = NULL;
154 } 132 }
133 if (NULL != mine)
134 {
135 GNUNET_free (mine);
136 mine = NULL;
137 }
155} 138}
156 139
157 140
@@ -166,35 +149,4 @@ GCH_get_mine (void)
166 return mine; 149 return mine;
167} 150}
168 151
169 152/* end of gnunet-service-cadet-new_hello.c */
170/**
171 * Get another peer's hello message.
172 *
173 * @param id ID of the peer whose hello message is requested.
174 *
175 * @return Hello message, if any (NULL possible).
176 */
177const struct GNUNET_HELLO_Message *
178GCH_get (const struct GNUNET_PeerIdentity *id)
179{
180 struct CadetPeer *p;
181
182 p = GCP_get (id, GNUNET_NO);
183 if (NULL == p)
184 return NULL;
185 return GCP_get_hello (p);
186}
187
188
189/**
190 * Convert a hello message to a string.
191 *
192 * @param h Hello message.
193 */
194char *
195GCH_2s (const struct GNUNET_HELLO_Message *h)
196{
197 return "hello (TODO)";
198}
199
200