aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_hello.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-02-09 14:28:45 +0000
committerChristian Grothoff <christian@grothoff.org>2015-02-09 14:28:45 +0000
commit72a2c1b9542d68eab32f483a1c53eeec19bc12b3 (patch)
tree36fe4082af27fba371e51bb838d8a0435e032432 /src/transport/gnunet-service-transport_hello.c
parent6806f421c1164921cfa265ddc7009c08986bc915 (diff)
downloadgnunet-72a2c1b9542d68eab32f483a1c53eeec19bc12b3.tar.gz
gnunet-72a2c1b9542d68eab32f483a1c53eeec19bc12b3.zip
-do only send HELLO to clients once on startup, do only send fully initialized HELLO to clients if we can help it, even the first one; do not perform blacklist check twice for try_connect
Diffstat (limited to 'src/transport/gnunet-service-transport_hello.c')
-rw-r--r--src/transport/gnunet-service-transport_hello.c80
1 files changed, 47 insertions, 33 deletions
diff --git a/src/transport/gnunet-service-transport_hello.c b/src/transport/gnunet-service-transport_hello.c
index d59b0f1b4..7b5f79a4a 100644
--- a/src/transport/gnunet-service-transport_hello.c
+++ b/src/transport/gnunet-service-transport_hello.c
@@ -90,28 +90,33 @@ static struct GNUNET_HELLO_Message *our_hello;
90static GST_HelloCallback hello_cb; 90static GST_HelloCallback hello_cb;
91 91
92/** 92/**
93 * Closure for 'hello_cb'. 93 * Closure for #hello_cb.
94 */ 94 */
95static void *hello_cb_cls; 95static void *hello_cb_cls;
96 96
97/** 97/**
98 * Head of my addresses. 98 * Head of my addresses.
99 */ 99 */
100struct OwnAddressList *oal_head; 100static struct OwnAddressList *oal_head;
101 101
102/** 102/**
103 * Tail of my addresses. 103 * Tail of my addresses.
104 */ 104 */
105struct OwnAddressList *oal_tail; 105static struct OwnAddressList *oal_tail;
106 106
107/** 107/**
108 * Identifier of 'refresh_hello' task. 108 * Should we use a friend-only HELLO?
109 */
110static int friend_option;
111
112/**
113 * Identifier of #refresh_hello_task().
109 */ 114 */
110static struct GNUNET_SCHEDULER_Task * hello_task; 115static struct GNUNET_SCHEDULER_Task * hello_task;
111 116
112 117
113/** 118/**
114 * Closure for 'address_generator'. 119 * Closure for #address_generator().
115 */ 120 */
116struct GeneratorContext 121struct GeneratorContext
117{ 122{
@@ -130,14 +135,16 @@ struct GeneratorContext
130/** 135/**
131 * Add an address from the 'OwnAddressList' to the buffer. 136 * Add an address from the 'OwnAddressList' to the buffer.
132 * 137 *
133 * @param cls the 'struct GeneratorContext' 138 * @param cls the `struct GeneratorContext`
134 * @param max maximum number of bytes left 139 * @param max maximum number of bytes left
135 * @param buf where to write the address 140 * @param buf where to write the address
136 * @return bytes written or GNUNET_SYSERR to signal the 141 * @return bytes written or #GNUNET_SYSERR to signal the
137 * end of the iteration. 142 * end of the iteration.
138 */ 143 */
139static ssize_t 144static ssize_t
140address_generator (void *cls, size_t max, void *buf) 145address_generator (void *cls,
146 size_t max,
147 void *buf)
141{ 148{
142 struct GeneratorContext *gc = cls; 149 struct GeneratorContext *gc = cls;
143 ssize_t ret; 150 ssize_t ret;
@@ -159,35 +166,40 @@ address_generator (void *cls, size_t max, void *buf)
159 * @param tc scheduler context 166 * @param tc scheduler context
160 */ 167 */
161static void 168static void
162refresh_hello_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 169refresh_hello_task (void *cls,
170 const struct GNUNET_SCHEDULER_TaskContext *tc)
163{ 171{
164 struct GeneratorContext gc; 172 struct GeneratorContext gc;
165 int friend_only;
166 173
167 hello_task = NULL; 174 hello_task = NULL;
168 gc.addr_pos = oal_head; 175 gc.addr_pos = oal_head;
169 gc.expiration = GNUNET_TIME_relative_to_absolute (hello_expiration); 176 gc.expiration = GNUNET_TIME_relative_to_absolute (hello_expiration);
170 177
171 178 GNUNET_free_non_null (our_hello);
172 friend_only = GNUNET_HELLO_is_friend_only (our_hello);
173 GNUNET_free (our_hello);
174 our_hello = GNUNET_HELLO_create (&GST_my_identity.public_key, 179 our_hello = GNUNET_HELLO_create (&GST_my_identity.public_key,
175 &address_generator, 180 &address_generator,
176 &gc, friend_only); 181 &gc,
182 friend_option);
177 GNUNET_assert (NULL != our_hello); 183 GNUNET_assert (NULL != our_hello);
178 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 184 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
179 "Refreshed my %s `%s', new size is %d\n", 185 "Refreshed my %s HELLO, new size is %d\n",
180 (GNUNET_YES == GNUNET_HELLO_is_friend_only (our_hello)) ? "friend-only" : "public", 186 (GNUNET_YES == friend_option) ? "friend-only" : "public",
181 "HELLO", GNUNET_HELLO_size (our_hello)); 187 GNUNET_HELLO_size (our_hello));
182 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# refreshed my HELLO"), 1, 188 GNUNET_STATISTICS_update (GST_stats,
189 gettext_noop ("# refreshed my HELLO"),
190 1,
183 GNUNET_NO); 191 GNUNET_NO);
184 if (NULL != hello_cb) 192 if (NULL != hello_cb)
185 hello_cb (hello_cb_cls, GST_hello_get ()); 193 hello_cb (hello_cb_cls,
186 GNUNET_PEERINFO_add_peer (GST_peerinfo, our_hello, NULL, NULL); 194 GST_hello_get ());
195 GNUNET_PEERINFO_add_peer (GST_peerinfo,
196 our_hello,
197 NULL,
198 NULL);
187 hello_task = 199 hello_task =
188 GNUNET_SCHEDULER_add_delayed (HELLO_REFRESH_PERIOD, &refresh_hello_task, 200 GNUNET_SCHEDULER_add_delayed (HELLO_REFRESH_PERIOD,
201 &refresh_hello_task,
189 NULL); 202 NULL);
190
191} 203}
192 204
193 205
@@ -198,9 +210,10 @@ refresh_hello_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
198static void 210static void
199refresh_hello () 211refresh_hello ()
200{ 212{
201 if (hello_task != NULL) 213 if (NULL != hello_task)
202 GNUNET_SCHEDULER_cancel (hello_task); 214 GNUNET_SCHEDULER_cancel (hello_task);
203 hello_task = GNUNET_SCHEDULER_add_now (&refresh_hello_task, NULL); 215 hello_task = GNUNET_SCHEDULER_add_now (&refresh_hello_task,
216 NULL);
204} 217}
205 218
206 219
@@ -209,16 +222,16 @@ refresh_hello ()
209 * 222 *
210 * @param friend_only use a friend only hello 223 * @param friend_only use a friend only hello
211 * @param cb function to call whenever our HELLO changes 224 * @param cb function to call whenever our HELLO changes
212 * @param cb_cls closure for cb 225 * @param cb_cls closure for @a cb
213 */ 226 */
214void 227void
215GST_hello_start (int friend_only, GST_HelloCallback cb, void *cb_cls) 228GST_hello_start (int friend_only,
229 GST_HelloCallback cb,
230 void *cb_cls)
216{ 231{
217 hello_cb = cb; 232 hello_cb = cb;
218 hello_cb_cls = cb_cls; 233 hello_cb_cls = cb_cls;
219 our_hello = GNUNET_HELLO_create (&GST_my_identity.public_key, 234 friend_option = friend_only;
220 NULL, NULL, friend_only);
221 GNUNET_assert (NULL != our_hello);
222 refresh_hello (); 235 refresh_hello ();
223} 236}
224 237
@@ -259,7 +272,7 @@ GST_hello_get ()
259/** 272/**
260 * Add or remove an address from this peer's HELLO message. 273 * Add or remove an address from this peer's HELLO message.
261 * 274 *
262 * @param addremove GNUNET_YES to add, GNUNET_NO to remove 275 * @param addremove #GNUNET_YES to add, #GNUNET_NO to remove
263 * @param address address to add or remove 276 * @param address address to add or remove
264 */ 277 */
265void 278void
@@ -303,8 +316,8 @@ GST_hello_modify_addresses (int addremove,
303 * @param sig location where to cache PONG signatures for this address [set] 316 * @param sig location where to cache PONG signatures for this address [set]
304 * @param sig_expiration how long until the current 'sig' expires? 317 * @param sig_expiration how long until the current 'sig' expires?
305 * (ZERO if sig was never created) [set] 318 * (ZERO if sig was never created) [set]
306 * @return GNUNET_YES if this is one of our addresses, 319 * @return #GNUNET_YES if this is one of our addresses,
307 * GNUNET_NO if not 320 * #GNUNET_NO if not
308 */ 321 */
309int 322int
310GST_hello_test_address (const struct GNUNET_HELLO_Address *address, 323GST_hello_test_address (const struct GNUNET_HELLO_Address *address,
@@ -314,7 +327,8 @@ GST_hello_test_address (const struct GNUNET_HELLO_Address *address,
314 struct OwnAddressList *al; 327 struct OwnAddressList *al;
315 328
316 for (al = oal_head; al != NULL; al = al->next) 329 for (al = oal_head; al != NULL; al = al->next)
317 if (0 == GNUNET_HELLO_address_cmp (address, al->address)) 330 if (0 == GNUNET_HELLO_address_cmp (address,
331 al->address))
318 { 332 {
319 *sig = &al->pong_signature; 333 *sig = &al->pong_signature;
320 *sig_expiration = &al->pong_sig_expires; 334 *sig_expiration = &al->pong_sig_expires;