summaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_hello.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/gnunet-service-transport_hello.c')
-rw-r--r--src/transport/gnunet-service-transport_hello.c205
1 files changed, 104 insertions, 101 deletions
diff --git a/src/transport/gnunet-service-transport_hello.c b/src/transport/gnunet-service-transport_hello.c
index 24a8321a2..ed6565d23 100644
--- a/src/transport/gnunet-service-transport_hello.c
+++ b/src/transport/gnunet-service-transport_hello.c
@@ -36,7 +36,8 @@
36/** 36/**
37 * How often do we refresh our HELLO (due to expiration concerns)? 37 * How often do we refresh our HELLO (due to expiration concerns)?
38 */ 38 */
39#define HELLO_REFRESH_PERIOD GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 6) 39#define HELLO_REFRESH_PERIOD GNUNET_TIME_relative_multiply ( \
40 GNUNET_TIME_UNIT_HOURS, 6)
40 41
41/** 42/**
42 * Hello address expiration 43 * Hello address expiration
@@ -48,7 +49,8 @@ extern struct GNUNET_TIME_Relative hello_expiration;
48 * Entry in linked list of network addresses for ourselves. Also 49 * Entry in linked list of network addresses for ourselves. Also
49 * includes a cached signature for 'struct TransportPongMessage's. 50 * includes a cached signature for 'struct TransportPongMessage's.
50 */ 51 */
51struct OwnAddressList { 52struct OwnAddressList
53{
52 /** 54 /**
53 * This is a doubly-linked list. 55 * This is a doubly-linked list.
54 */ 56 */
@@ -123,7 +125,8 @@ static struct GNUNET_SCHEDULER_Task *hello_task;
123/** 125/**
124 * Closure for #address_generator(). 126 * Closure for #address_generator().
125 */ 127 */
126struct GeneratorContext { 128struct GeneratorContext
129{
127 /** 130 /**
128 * Where are we in the DLL? 131 * Where are we in the DLL?
129 */ 132 */
@@ -146,19 +149,19 @@ struct GeneratorContext {
146 * end of the iteration. 149 * end of the iteration.
147 */ 150 */
148static ssize_t 151static ssize_t
149address_generator(void *cls, 152address_generator (void *cls,
150 size_t max, 153 size_t max,
151 void *buf) 154 void *buf)
152{ 155{
153 struct GeneratorContext *gc = cls; 156 struct GeneratorContext *gc = cls;
154 ssize_t ret; 157 ssize_t ret;
155 158
156 if (NULL == gc->addr_pos) 159 if (NULL == gc->addr_pos)
157 return GNUNET_SYSERR; /* Done */ 160 return GNUNET_SYSERR; /* Done */
158 ret = GNUNET_HELLO_add_address(gc->addr_pos->address, 161 ret = GNUNET_HELLO_add_address (gc->addr_pos->address,
159 gc->expiration, 162 gc->expiration,
160 buf, 163 buf,
161 max); 164 max);
162 gc->addr_pos = gc->addr_pos->next; 165 gc->addr_pos = gc->addr_pos->next;
163 return ret; 166 return ret;
164} 167}
@@ -171,38 +174,38 @@ address_generator(void *cls,
171 * @param cls unused 174 * @param cls unused
172 */ 175 */
173static void 176static void
174refresh_hello_task(void *cls) 177refresh_hello_task (void *cls)
175{ 178{
176 struct GeneratorContext gc; 179 struct GeneratorContext gc;
177 180
178 hello_task = NULL; 181 hello_task = NULL;
179 gc.addr_pos = oal_head; 182 gc.addr_pos = oal_head;
180 gc.expiration = GNUNET_TIME_relative_to_absolute(hello_expiration); 183 gc.expiration = GNUNET_TIME_relative_to_absolute (hello_expiration);
181 184
182 GNUNET_free_non_null(our_hello); 185 GNUNET_free_non_null (our_hello);
183 our_hello = GNUNET_HELLO_create(&GST_my_identity.public_key, 186 our_hello = GNUNET_HELLO_create (&GST_my_identity.public_key,
184 &address_generator, 187 &address_generator,
185 &gc, 188 &gc,
186 friend_option); 189 friend_option);
187 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 190 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
188 "Refreshed my %s HELLO, new size is %d\n", 191 "Refreshed my %s HELLO, new size is %d\n",
189 (GNUNET_YES == friend_option) ? "friend-only" : "public", 192 (GNUNET_YES == friend_option) ? "friend-only" : "public",
190 GNUNET_HELLO_size(our_hello)); 193 GNUNET_HELLO_size (our_hello));
191 GNUNET_STATISTICS_update(GST_stats, 194 GNUNET_STATISTICS_update (GST_stats,
192 gettext_noop("# refreshed my HELLO"), 195 gettext_noop ("# refreshed my HELLO"),
193 1, 196 1,
194 GNUNET_NO); 197 GNUNET_NO);
195 if (NULL != hello_cb) 198 if (NULL != hello_cb)
196 hello_cb(hello_cb_cls, 199 hello_cb (hello_cb_cls,
197 GST_hello_get()); 200 GST_hello_get ());
198 GNUNET_PEERINFO_add_peer(GST_peerinfo, 201 GNUNET_PEERINFO_add_peer (GST_peerinfo,
199 our_hello, 202 our_hello,
200 NULL, 203 NULL,
201 NULL); 204 NULL);
202 hello_task = 205 hello_task =
203 GNUNET_SCHEDULER_add_delayed(HELLO_REFRESH_PERIOD, 206 GNUNET_SCHEDULER_add_delayed (HELLO_REFRESH_PERIOD,
204 &refresh_hello_task, 207 &refresh_hello_task,
205 NULL); 208 NULL);
206} 209}
207 210
208 211
@@ -212,14 +215,14 @@ refresh_hello_task(void *cls)
212 * have been shutdown). 215 * have been shutdown).
213 */ 216 */
214static void 217static void
215refresh_hello() 218refresh_hello ()
216{ 219{
217 if (NULL != hello_task) 220 if (NULL != hello_task)
218 { 221 {
219 GNUNET_SCHEDULER_cancel(hello_task); 222 GNUNET_SCHEDULER_cancel (hello_task);
220 hello_task = GNUNET_SCHEDULER_add_now(&refresh_hello_task, 223 hello_task = GNUNET_SCHEDULER_add_now (&refresh_hello_task,
221 NULL); 224 NULL);
222 } 225 }
223} 226}
224 227
225 228
@@ -231,14 +234,14 @@ refresh_hello()
231 * @param cb_cls closure for @a cb 234 * @param cb_cls closure for @a cb
232 */ 235 */
233void 236void
234GST_hello_start(int friend_only, 237GST_hello_start (int friend_only,
235 GST_HelloCallback cb, 238 GST_HelloCallback cb,
236 void *cb_cls) 239 void *cb_cls)
237{ 240{
238 hello_cb = cb; 241 hello_cb = cb;
239 hello_cb_cls = cb_cls; 242 hello_cb_cls = cb_cls;
240 friend_option = friend_only; 243 friend_option = friend_only;
241 refresh_hello_task(NULL); 244 refresh_hello_task (NULL);
242} 245}
243 246
244 247
@@ -246,20 +249,20 @@ GST_hello_start(int friend_only,
246 * Shutdown the HELLO module. 249 * Shutdown the HELLO module.
247 */ 250 */
248void 251void
249GST_hello_stop() 252GST_hello_stop ()
250{ 253{
251 hello_cb = NULL; 254 hello_cb = NULL;
252 hello_cb_cls = NULL; 255 hello_cb_cls = NULL;
253 if (NULL != hello_task) 256 if (NULL != hello_task)
254 { 257 {
255 GNUNET_SCHEDULER_cancel(hello_task); 258 GNUNET_SCHEDULER_cancel (hello_task);
256 hello_task = NULL; 259 hello_task = NULL;
257 } 260 }
258 if (NULL != our_hello) 261 if (NULL != our_hello)
259 { 262 {
260 GNUNET_free(our_hello); 263 GNUNET_free (our_hello);
261 our_hello = NULL; 264 our_hello = NULL;
262 } 265 }
263} 266}
264 267
265 268
@@ -269,9 +272,9 @@ GST_hello_stop()
269 * @return our HELLO message 272 * @return our HELLO message
270 */ 273 */
271const struct GNUNET_MessageHeader * 274const struct GNUNET_MessageHeader *
272GST_hello_get() 275GST_hello_get ()
273{ 276{
274 return (const struct GNUNET_MessageHeader *)our_hello; 277 return (const struct GNUNET_MessageHeader *) our_hello;
275} 278}
276 279
277 280
@@ -282,52 +285,52 @@ GST_hello_get()
282 * @param address address to add or remove 285 * @param address address to add or remove
283 */ 286 */
284void 287void
285GST_hello_modify_addresses(int addremove, 288GST_hello_modify_addresses (int addremove,
286 const struct GNUNET_HELLO_Address *address) 289 const struct GNUNET_HELLO_Address *address)
287{ 290{
288 struct OwnAddressList *al; 291 struct OwnAddressList *al;
289 292
290 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 293 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
291 (GNUNET_YES == addremove) 294 (GNUNET_YES == addremove)
292 ? "Adding `%s' to the set of our addresses\n" 295 ? "Adding `%s' to the set of our addresses\n"
293 : "Removing `%s' from the set of our addresses\n", 296 : "Removing `%s' from the set of our addresses\n",
294 GST_plugins_a2s(address)); 297 GST_plugins_a2s (address));
295 GNUNET_assert(NULL != address); 298 GNUNET_assert (NULL != address);
296 for (al = oal_head; al != NULL; al = al->next) 299 for (al = oal_head; al != NULL; al = al->next)
297 if (0 == GNUNET_HELLO_address_cmp(address, al->address)) 300 if (0 == GNUNET_HELLO_address_cmp (address, al->address))
298 break; 301 break;
299 if (GNUNET_NO == addremove) 302 if (GNUNET_NO == addremove)
303 {
304 if (NULL == al)
300 { 305 {
301 if (NULL == al) 306 /* address to be removed not found!? */
302 { 307 GNUNET_break (0);
303 /* address to be removed not found!? */
304 GNUNET_break(0);
305 return;
306 }
307 al->rc--;
308 if (0 != al->rc)
309 return; /* RC not yet zero */
310 GNUNET_CONTAINER_DLL_remove(oal_head,
311 oal_tail,
312 al);
313 GNUNET_HELLO_address_free(al->address);
314 GNUNET_free(al);
315 refresh_hello();
316 return; 308 return;
317 } 309 }
310 al->rc--;
311 if (0 != al->rc)
312 return; /* RC not yet zero */
313 GNUNET_CONTAINER_DLL_remove (oal_head,
314 oal_tail,
315 al);
316 GNUNET_HELLO_address_free (al->address);
317 GNUNET_free (al);
318 refresh_hello ();
319 return;
320 }
318 if (NULL != al) 321 if (NULL != al)
319 { 322 {
320 /* address added twice or more */ 323 /* address added twice or more */
321 al->rc++; 324 al->rc++;
322 return; 325 return;
323 } 326 }
324 al = GNUNET_new(struct OwnAddressList); 327 al = GNUNET_new (struct OwnAddressList);
325 al->rc = 1; 328 al->rc = 1;
326 GNUNET_CONTAINER_DLL_insert(oal_head, 329 GNUNET_CONTAINER_DLL_insert (oal_head,
327 oal_tail, 330 oal_tail,
328 al); 331 al);
329 al->address = GNUNET_HELLO_address_copy(address); 332 al->address = GNUNET_HELLO_address_copy (address);
330 refresh_hello(); 333 refresh_hello ();
331} 334}
332 335
333 336
@@ -342,20 +345,20 @@ GST_hello_modify_addresses(int addremove,
342 * #GNUNET_NO if not 345 * #GNUNET_NO if not
343 */ 346 */
344int 347int
345GST_hello_test_address(const struct GNUNET_HELLO_Address *address, 348GST_hello_test_address (const struct GNUNET_HELLO_Address *address,
346 struct GNUNET_CRYPTO_EddsaSignature **sig, 349 struct GNUNET_CRYPTO_EddsaSignature **sig,
347 struct GNUNET_TIME_Absolute **sig_expiration) 350 struct GNUNET_TIME_Absolute **sig_expiration)
348{ 351{
349 struct OwnAddressList *al; 352 struct OwnAddressList *al;
350 353
351 for (al = oal_head; al != NULL; al = al->next) 354 for (al = oal_head; al != NULL; al = al->next)
352 if (0 == GNUNET_HELLO_address_cmp(address, 355 if (0 == GNUNET_HELLO_address_cmp (address,
353 al->address)) 356 al->address))
354 { 357 {
355 *sig = &al->pong_signature; 358 *sig = &al->pong_signature;
356 *sig_expiration = &al->pong_sig_expires; 359 *sig_expiration = &al->pong_sig_expires;
357 return GNUNET_YES; 360 return GNUNET_YES;
358 } 361 }
359 *sig = NULL; 362 *sig = NULL;
360 *sig_expiration = NULL; 363 *sig_expiration = NULL;
361 return GNUNET_NO; 364 return GNUNET_NO;