summaryrefslogtreecommitdiff
path: root/src/topology/gnunet-daemon-topology.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/topology/gnunet-daemon-topology.c')
-rw-r--r--src/topology/gnunet-daemon-topology.c844
1 files changed, 423 insertions, 421 deletions
diff --git a/src/topology/gnunet-daemon-topology.c b/src/topology/gnunet-daemon-topology.c
index a550286e7..9e662ca0b 100644
--- a/src/topology/gnunet-daemon-topology.c
+++ b/src/topology/gnunet-daemon-topology.c
@@ -52,19 +52,20 @@
52 * At what frequency do we sent HELLOs to a peer? 52 * At what frequency do we sent HELLOs to a peer?
53 */ 53 */
54#define HELLO_ADVERTISEMENT_MIN_FREQUENCY \ 54#define HELLO_ADVERTISEMENT_MIN_FREQUENCY \
55 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5) 55 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
56 56
57/** 57/**
58 * After what time period do we expire the HELLO Bloom filter? 58 * After what time period do we expire the HELLO Bloom filter?
59 */ 59 */
60#define HELLO_ADVERTISEMENT_MIN_REPEAT_FREQUENCY \ 60#define HELLO_ADVERTISEMENT_MIN_REPEAT_FREQUENCY \
61 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 4) 61 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
62 62
63 63
64/** 64/**
65 * Record for neighbours, friends and blacklisted peers. 65 * Record for neighbours, friends and blacklisted peers.
66 */ 66 */
67struct Peer { 67struct Peer
68{
68 /** 69 /**
69 * Which peer is this entry about? 70 * Which peer is this entry about?
70 */ 71 */
@@ -216,17 +217,17 @@ static unsigned int friend_count;
216 * @return #GNUNET_OK if the connection is allowed 217 * @return #GNUNET_OK if the connection is allowed
217 */ 218 */
218static int 219static int
219blacklist_check(void *cls, const struct GNUNET_PeerIdentity *pid) 220blacklist_check (void *cls, const struct GNUNET_PeerIdentity *pid)
220{ 221{
221 struct Peer *pos; 222 struct Peer *pos;
222 223
223 pos = GNUNET_CONTAINER_multipeermap_get(peers, pid); 224 pos = GNUNET_CONTAINER_multipeermap_get (peers, pid);
224 if ((NULL != pos) && (GNUNET_YES == pos->is_friend)) 225 if ((NULL != pos) && (GNUNET_YES == pos->is_friend))
225 return GNUNET_OK; 226 return GNUNET_OK;
226 GNUNET_STATISTICS_update(stats, 227 GNUNET_STATISTICS_update (stats,
227 gettext_noop("# peers blacklisted"), 228 gettext_noop ("# peers blacklisted"),
228 1, 229 1,
229 GNUNET_NO); 230 GNUNET_NO);
230 return GNUNET_SYSERR; 231 return GNUNET_SYSERR;
231} 232}
232 233
@@ -236,13 +237,13 @@ blacklist_check(void *cls, const struct GNUNET_PeerIdentity *pid)
236 * the minimum number of friends. 237 * the minimum number of friends.
237 */ 238 */
238static void 239static void
239whitelist_peers() 240whitelist_peers ()
240{ 241{
241 if (NULL != blacklist) 242 if (NULL != blacklist)
242 { 243 {
243 GNUNET_TRANSPORT_blacklist_cancel(blacklist); 244 GNUNET_TRANSPORT_blacklist_cancel (blacklist);
244 blacklist = NULL; 245 blacklist = NULL;
245 } 246 }
246} 247}
247 248
248 249
@@ -255,34 +256,34 @@ whitelist_peers()
255 * @return #GNUNET_YES (always: continue to iterate) 256 * @return #GNUNET_YES (always: continue to iterate)
256 */ 257 */
257static int 258static int
258free_peer(void *cls, const struct GNUNET_PeerIdentity *pid, void *value) 259free_peer (void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
259{ 260{
260 struct Peer *pos = value; 261 struct Peer *pos = value;
261 262
262 GNUNET_break(NULL == pos->mq); 263 GNUNET_break (NULL == pos->mq);
263 GNUNET_break(GNUNET_OK == 264 GNUNET_break (GNUNET_OK ==
264 GNUNET_CONTAINER_multipeermap_remove(peers, pid, pos)); 265 GNUNET_CONTAINER_multipeermap_remove (peers, pid, pos));
265 if (NULL != pos->hello_delay_task) 266 if (NULL != pos->hello_delay_task)
266 { 267 {
267 GNUNET_SCHEDULER_cancel(pos->hello_delay_task); 268 GNUNET_SCHEDULER_cancel (pos->hello_delay_task);
268 pos->hello_delay_task = NULL; 269 pos->hello_delay_task = NULL;
269 } 270 }
270 if (NULL != pos->sh) 271 if (NULL != pos->sh)
271 { 272 {
272 GNUNET_ATS_connectivity_suggest_cancel(pos->sh); 273 GNUNET_ATS_connectivity_suggest_cancel (pos->sh);
273 pos->sh = NULL; 274 pos->sh = NULL;
274 } 275 }
275 if (NULL != pos->hello) 276 if (NULL != pos->hello)
276 { 277 {
277 GNUNET_free_non_null(pos->hello); 278 GNUNET_free_non_null (pos->hello);
278 pos->hello = NULL; 279 pos->hello = NULL;
279 } 280 }
280 if (NULL != pos->filter) 281 if (NULL != pos->filter)
281 { 282 {
282 GNUNET_CONTAINER_bloomfilter_free(pos->filter); 283 GNUNET_CONTAINER_bloomfilter_free (pos->filter);
283 pos->filter = NULL; 284 pos->filter = NULL;
284 } 285 }
285 GNUNET_free(pos); 286 GNUNET_free (pos);
286 return GNUNET_YES; 287 return GNUNET_YES;
287} 288}
288 289
@@ -294,23 +295,23 @@ free_peer(void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
294 * @param pos peer to consider connecting to 295 * @param pos peer to consider connecting to
295 */ 296 */
296static void 297static void
297attempt_connect(struct Peer *pos) 298attempt_connect (struct Peer *pos)
298{ 299{
299 uint32_t strength; 300 uint32_t strength;
300 301
301 if (0 == GNUNET_memcmp(&my_identity, &pos->pid)) 302 if (0 == GNUNET_memcmp (&my_identity, &pos->pid))
302 return; /* This is myself, nothing to do. */ 303 return; /* This is myself, nothing to do. */
303 if (connection_count < target_connection_count) 304 if (connection_count < target_connection_count)
304 strength = 1; 305 strength = 1;
305 else 306 else
306 strength = 0; 307 strength = 0;
307 if ((friend_count < minimum_friend_count) || (GNUNET_YES == friends_only)) 308 if ((friend_count < minimum_friend_count) || (GNUNET_YES == friends_only))
308 { 309 {
309 if (pos->is_friend) 310 if (pos->is_friend)
310 strength += 10; /* urgently needed */ 311 strength += 10; /* urgently needed */
311 else 312 else
312 strength = 0; /* disallowed */ 313 strength = 0; /* disallowed */
313 } 314 }
314 if (pos->is_friend) 315 if (pos->is_friend)
315 strength *= 2; /* friends always count more */ 316 strength *= 2; /* friends always count more */
316 if (NULL != pos->mq) 317 if (NULL != pos->mq)
@@ -318,23 +319,23 @@ attempt_connect(struct Peer *pos)
318 if (strength == pos->strength) 319 if (strength == pos->strength)
319 return; /* nothing to do */ 320 return; /* nothing to do */
320 if (NULL != pos->sh) 321 if (NULL != pos->sh)
321 { 322 {
322 GNUNET_ATS_connectivity_suggest_cancel(pos->sh); 323 GNUNET_ATS_connectivity_suggest_cancel (pos->sh);
323 pos->sh = NULL; 324 pos->sh = NULL;
324 } 325 }
325 pos->strength = strength; 326 pos->strength = strength;
326 if (0 != strength) 327 if (0 != strength)
327 { 328 {
328 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 329 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
329 "Asking to connect to `%s' with strength %u\n", 330 "Asking to connect to `%s' with strength %u\n",
330 GNUNET_i2s(&pos->pid), 331 GNUNET_i2s (&pos->pid),
331 (unsigned int)strength); 332 (unsigned int) strength);
332 GNUNET_STATISTICS_update(stats, 333 GNUNET_STATISTICS_update (stats,
333 gettext_noop("# connect requests issued to ATS"), 334 gettext_noop ("# connect requests issued to ATS"),
334 1, 335 1,
335 GNUNET_NO); 336 GNUNET_NO);
336 pos->sh = GNUNET_ATS_connectivity_suggest(ats, &pos->pid, strength); 337 pos->sh = GNUNET_ATS_connectivity_suggest (ats, &pos->pid, strength);
337 } 338 }
338} 339}
339 340
340 341
@@ -347,26 +348,26 @@ attempt_connect(struct Peer *pos)
347 * @return the new entry 348 * @return the new entry
348 */ 349 */
349static struct Peer * 350static struct Peer *
350make_peer(const struct GNUNET_PeerIdentity *peer, 351make_peer (const struct GNUNET_PeerIdentity *peer,
351 const struct GNUNET_HELLO_Message *hello, 352 const struct GNUNET_HELLO_Message *hello,
352 int is_friend) 353 int is_friend)
353{ 354{
354 struct Peer *ret; 355 struct Peer *ret;
355 356
356 ret = GNUNET_new(struct Peer); 357 ret = GNUNET_new (struct Peer);
357 ret->pid = *peer; 358 ret->pid = *peer;
358 ret->is_friend = is_friend; 359 ret->is_friend = is_friend;
359 if (NULL != hello) 360 if (NULL != hello)
360 { 361 {
361 ret->hello = GNUNET_malloc(GNUNET_HELLO_size(hello)); 362 ret->hello = GNUNET_malloc (GNUNET_HELLO_size (hello));
362 GNUNET_memcpy(ret->hello, hello, GNUNET_HELLO_size(hello)); 363 GNUNET_memcpy (ret->hello, hello, GNUNET_HELLO_size (hello));
363 } 364 }
364 GNUNET_break(GNUNET_OK == 365 GNUNET_break (GNUNET_OK ==
365 GNUNET_CONTAINER_multipeermap_put( 366 GNUNET_CONTAINER_multipeermap_put (
366 peers, 367 peers,
367 peer, 368 peer,
368 ret, 369 ret,
369 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 370 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
370 return ret; 371 return ret;
371} 372}
372 373
@@ -377,7 +378,7 @@ make_peer(const struct GNUNET_PeerIdentity *peer,
377 * @param peer entry to initialize 378 * @param peer entry to initialize
378 */ 379 */
379static void 380static void
380setup_filter(struct Peer *peer) 381setup_filter (struct Peer *peer)
381{ 382{
382 struct GNUNET_HashCode hc; 383 struct GNUNET_HashCode hc;
383 384
@@ -388,19 +389,20 @@ setup_filter(struct Peer *peer)
388 * "useless" once a HELLO has been passed on to ~100 389 * "useless" once a HELLO has been passed on to ~100
389 * other peers, which is likely more than enough in 390 * other peers, which is likely more than enough in
390 * any case; hence 64, 5 as bloomfilter parameters. */ 391 * any case; hence 64, 5 as bloomfilter parameters. */
391 peer->filter = GNUNET_CONTAINER_bloomfilter_init(NULL, 64, 5); 392 peer->filter = GNUNET_CONTAINER_bloomfilter_init (NULL, 64, 5);
392 peer->filter_expiration = 393 peer->filter_expiration =
393 GNUNET_TIME_relative_to_absolute(HELLO_ADVERTISEMENT_MIN_REPEAT_FREQUENCY); 394 GNUNET_TIME_relative_to_absolute (HELLO_ADVERTISEMENT_MIN_REPEAT_FREQUENCY);
394 /* never send a peer its own HELLO */ 395 /* never send a peer its own HELLO */
395 GNUNET_CRYPTO_hash(&peer->pid, sizeof(struct GNUNET_PeerIdentity), &hc); 396 GNUNET_CRYPTO_hash (&peer->pid, sizeof(struct GNUNET_PeerIdentity), &hc);
396 GNUNET_CONTAINER_bloomfilter_add(peer->filter, &hc); 397 GNUNET_CONTAINER_bloomfilter_add (peer->filter, &hc);
397} 398}
398 399
399 400
400/** 401/**
401 * Closure for #find_advertisable_hello(). 402 * Closure for #find_advertisable_hello().
402 */ 403 */
403struct FindAdvHelloContext { 404struct FindAdvHelloContext
405{
404 /** 406 /**
405 * Peer we want to advertise to. 407 * Peer we want to advertise to.
406 */ 408 */
@@ -429,9 +431,9 @@ struct FindAdvHelloContext {
429 * @return #GNUNET_YES (continue iteration) 431 * @return #GNUNET_YES (continue iteration)
430 */ 432 */
431static int 433static int
432find_advertisable_hello(void *cls, 434find_advertisable_hello (void *cls,
433 const struct GNUNET_PeerIdentity *pid, 435 const struct GNUNET_PeerIdentity *pid,
434 void *value) 436 void *value)
435{ 437{
436 struct FindAdvHelloContext *fah = cls; 438 struct FindAdvHelloContext *fah = cls;
437 struct Peer *pos = value; 439 struct Peer *pos = value;
@@ -443,21 +445,21 @@ find_advertisable_hello(void *cls,
443 return GNUNET_YES; 445 return GNUNET_YES;
444 if (pos->hello == NULL) 446 if (pos->hello == NULL)
445 return GNUNET_YES; 447 return GNUNET_YES;
446 rst_time = GNUNET_TIME_absolute_get_remaining(pos->filter_expiration); 448 rst_time = GNUNET_TIME_absolute_get_remaining (pos->filter_expiration);
447 if (0 == rst_time.rel_value_us) 449 if (0 == rst_time.rel_value_us)
448 { 450 {
449 /* time to discard... */ 451 /* time to discard... */
450 GNUNET_CONTAINER_bloomfilter_free(pos->filter); 452 GNUNET_CONTAINER_bloomfilter_free (pos->filter);
451 setup_filter(pos); 453 setup_filter (pos);
452 } 454 }
453 fah->next_adv = GNUNET_TIME_relative_min(rst_time, fah->next_adv); 455 fah->next_adv = GNUNET_TIME_relative_min (rst_time, fah->next_adv);
454 hs = GNUNET_HELLO_size(pos->hello); 456 hs = GNUNET_HELLO_size (pos->hello);
455 if (hs > fah->max_size) 457 if (hs > fah->max_size)
456 return GNUNET_YES; 458 return GNUNET_YES;
457 GNUNET_CRYPTO_hash(&fah->peer->pid, 459 GNUNET_CRYPTO_hash (&fah->peer->pid,
458 sizeof(struct GNUNET_PeerIdentity), 460 sizeof(struct GNUNET_PeerIdentity),
459 &hc); 461 &hc);
460 if (GNUNET_NO == GNUNET_CONTAINER_bloomfilter_test(pos->filter, &hc)) 462 if (GNUNET_NO == GNUNET_CONTAINER_bloomfilter_test (pos->filter, &hc))
461 fah->result = pos; 463 fah->result = pos;
462 return GNUNET_YES; 464 return GNUNET_YES;
463} 465}
@@ -470,7 +472,7 @@ find_advertisable_hello(void *cls,
470 * @param cls for which peer to schedule the HELLO 472 * @param cls for which peer to schedule the HELLO
471 */ 473 */
472static void 474static void
473schedule_next_hello(void *cls) 475schedule_next_hello (void *cls)
474{ 476{
475 struct Peer *pl = cls; 477 struct Peer *pl = cls;
476 struct FindAdvHelloContext fah; 478 struct FindAdvHelloContext fah;
@@ -480,42 +482,42 @@ schedule_next_hello(void *cls)
480 struct GNUNET_HashCode hc; 482 struct GNUNET_HashCode hc;
481 483
482 pl->hello_delay_task = NULL; 484 pl->hello_delay_task = NULL;
483 GNUNET_assert(NULL != pl->mq); 485 GNUNET_assert (NULL != pl->mq);
484 /* find applicable HELLOs */ 486 /* find applicable HELLOs */
485 fah.peer = pl; 487 fah.peer = pl;
486 fah.result = NULL; 488 fah.result = NULL;
487 fah.max_size = GNUNET_MAX_MESSAGE_SIZE - 1; 489 fah.max_size = GNUNET_MAX_MESSAGE_SIZE - 1;
488 fah.next_adv = GNUNET_TIME_UNIT_FOREVER_REL; 490 fah.next_adv = GNUNET_TIME_UNIT_FOREVER_REL;
489 GNUNET_CONTAINER_multipeermap_iterate(peers, &find_advertisable_hello, &fah); 491 GNUNET_CONTAINER_multipeermap_iterate (peers, &find_advertisable_hello, &fah);
490 pl->hello_delay_task = 492 pl->hello_delay_task =
491 GNUNET_SCHEDULER_add_delayed(fah.next_adv, &schedule_next_hello, pl); 493 GNUNET_SCHEDULER_add_delayed (fah.next_adv, &schedule_next_hello, pl);
492 if (NULL == fah.result) 494 if (NULL == fah.result)
493 return; 495 return;
494 delay = GNUNET_TIME_absolute_get_remaining(pl->next_hello_allowed); 496 delay = GNUNET_TIME_absolute_get_remaining (pl->next_hello_allowed);
495 if (0 != delay.rel_value_us) 497 if (0 != delay.rel_value_us)
496 return; 498 return;
497 499
498 want = GNUNET_HELLO_size(fah.result->hello); 500 want = GNUNET_HELLO_size (fah.result->hello);
499 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 501 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
500 "Sending HELLO with %u bytes", 502 "Sending HELLO with %u bytes",
501 (unsigned int)want); 503 (unsigned int) want);
502 env = GNUNET_MQ_msg_copy(&fah.result->hello->header); 504 env = GNUNET_MQ_msg_copy (&fah.result->hello->header);
503 GNUNET_MQ_send(pl->mq, env); 505 GNUNET_MQ_send (pl->mq, env);
504 506
505 /* avoid sending this one again soon */ 507 /* avoid sending this one again soon */
506 GNUNET_CRYPTO_hash(&pl->pid, sizeof(struct GNUNET_PeerIdentity), &hc); 508 GNUNET_CRYPTO_hash (&pl->pid, sizeof(struct GNUNET_PeerIdentity), &hc);
507 GNUNET_CONTAINER_bloomfilter_add(fah.result->filter, &hc); 509 GNUNET_CONTAINER_bloomfilter_add (fah.result->filter, &hc);
508 510
509 GNUNET_STATISTICS_update(stats, 511 GNUNET_STATISTICS_update (stats,
510 gettext_noop("# HELLO messages gossipped"), 512 gettext_noop ("# HELLO messages gossipped"),
511 1, 513 1,
512 GNUNET_NO); 514 GNUNET_NO);
513 /* prepare to send the next one */ 515 /* prepare to send the next one */
514 pl->next_hello_allowed = 516 pl->next_hello_allowed =
515 GNUNET_TIME_relative_to_absolute(HELLO_ADVERTISEMENT_MIN_FREQUENCY); 517 GNUNET_TIME_relative_to_absolute (HELLO_ADVERTISEMENT_MIN_FREQUENCY);
516 if (NULL != pl->hello_delay_task) 518 if (NULL != pl->hello_delay_task)
517 GNUNET_SCHEDULER_cancel(pl->hello_delay_task); 519 GNUNET_SCHEDULER_cancel (pl->hello_delay_task);
518 pl->hello_delay_task = GNUNET_SCHEDULER_add_now(&schedule_next_hello, pl); 520 pl->hello_delay_task = GNUNET_SCHEDULER_add_now (&schedule_next_hello, pl);
519} 521}
520 522
521 523
@@ -530,9 +532,9 @@ schedule_next_hello(void *cls)
530 * @return #GNUNET_YES (always) 532 * @return #GNUNET_YES (always)
531 */ 533 */
532static int 534static int
533reschedule_hellos(void *cls, 535reschedule_hellos (void *cls,
534 const struct GNUNET_PeerIdentity *pid, 536 const struct GNUNET_PeerIdentity *pid,
535 void *value) 537 void *value)
536{ 538{
537 struct Peer *peer = value; 539 struct Peer *peer = value;
538 struct Peer *skip = cls; 540 struct Peer *skip = cls;
@@ -542,12 +544,12 @@ reschedule_hellos(void *cls,
542 if (NULL == peer->mq) 544 if (NULL == peer->mq)
543 return GNUNET_YES; 545 return GNUNET_YES;
544 if (NULL != peer->hello_delay_task) 546 if (NULL != peer->hello_delay_task)
545 { 547 {
546 GNUNET_SCHEDULER_cancel(peer->hello_delay_task); 548 GNUNET_SCHEDULER_cancel (peer->hello_delay_task);
547 peer->hello_delay_task = NULL; 549 peer->hello_delay_task = NULL;
548 } 550 }
549 peer->hello_delay_task = 551 peer->hello_delay_task =
550 GNUNET_SCHEDULER_add_now(&schedule_next_hello, peer); 552 GNUNET_SCHEDULER_add_now (&schedule_next_hello, peer);
551 return GNUNET_YES; 553 return GNUNET_YES;
552} 554}
553 555
@@ -561,44 +563,44 @@ reschedule_hellos(void *cls,
561 * @return our `struct Peer` for @a peer 563 * @return our `struct Peer` for @a peer
562 */ 564 */
563static void * 565static void *
564connect_notify(void *cls, 566connect_notify (void *cls,
565 const struct GNUNET_PeerIdentity *peer, 567 const struct GNUNET_PeerIdentity *peer,
566 struct GNUNET_MQ_Handle *mq) 568 struct GNUNET_MQ_Handle *mq)
567{ 569{
568 struct Peer *pos; 570 struct Peer *pos;
569 571
570 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 572 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
571 "Core told us that we are connecting to `%s'\n", 573 "Core told us that we are connecting to `%s'\n",
572 GNUNET_i2s(peer)); 574 GNUNET_i2s (peer));
573 if (0 == GNUNET_memcmp(&my_identity, peer)) 575 if (0 == GNUNET_memcmp (&my_identity, peer))
574 return NULL; 576 return NULL;
575 GNUNET_MQ_set_options(mq, GNUNET_MQ_PRIO_BEST_EFFORT); 577 GNUNET_MQ_set_options (mq, GNUNET_MQ_PRIO_BEST_EFFORT);
576 connection_count++; 578 connection_count++;
577 GNUNET_STATISTICS_set(stats, 579 GNUNET_STATISTICS_set (stats,
578 gettext_noop("# peers connected"), 580 gettext_noop ("# peers connected"),
579 connection_count, 581 connection_count,
580 GNUNET_NO); 582 GNUNET_NO);
581 pos = GNUNET_CONTAINER_multipeermap_get(peers, peer); 583 pos = GNUNET_CONTAINER_multipeermap_get (peers, peer);
582 if (NULL == pos) 584 if (NULL == pos)
583 { 585 {
584 pos = make_peer(peer, NULL, GNUNET_NO); 586 pos = make_peer (peer, NULL, GNUNET_NO);
585 } 587 }
586 else 588 else
587 { 589 {
588 GNUNET_assert(NULL == pos->mq); 590 GNUNET_assert (NULL == pos->mq);
589 } 591 }
590 pos->mq = mq; 592 pos->mq = mq;
591 if (pos->is_friend) 593 if (pos->is_friend)
592 { 594 {
593 friend_count++; 595 friend_count++;
594 if ((friend_count == minimum_friend_count) && (GNUNET_YES != friends_only)) 596 if ((friend_count == minimum_friend_count) && (GNUNET_YES != friends_only))
595 whitelist_peers(); 597 whitelist_peers ();
596 GNUNET_STATISTICS_set(stats, 598 GNUNET_STATISTICS_set (stats,
597 gettext_noop("# friends connected"), 599 gettext_noop ("# friends connected"),
598 friend_count, 600 friend_count,
599 GNUNET_NO); 601 GNUNET_NO);
600 } 602 }
601 reschedule_hellos(NULL, peer, pos); 603 reschedule_hellos (NULL, peer, pos);
602 return pos; 604 return pos;
603} 605}
604 606
@@ -612,11 +614,11 @@ connect_notify(void *cls,
612 * @return #GNUNET_YES (continue to iterate) 614 * @return #GNUNET_YES (continue to iterate)
613 */ 615 */
614static int 616static int
615try_add_peers(void *cls, const struct GNUNET_PeerIdentity *pid, void *value) 617try_add_peers (void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
616{ 618{
617 struct Peer *pos = value; 619 struct Peer *pos = value;
618 620
619 attempt_connect(pos); 621 attempt_connect (pos);
620 return GNUNET_YES; 622 return GNUNET_YES;
621} 623}
622 624
@@ -627,11 +629,11 @@ try_add_peers(void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
627 * @param cls unused, NULL 629 * @param cls unused, NULL
628 */ 630 */
629static void 631static void
630add_peer_task(void *cls) 632add_peer_task (void *cls)
631{ 633{
632 add_task = NULL; 634 add_task = NULL;
633 635
634 GNUNET_CONTAINER_multipeermap_iterate(peers, &try_add_peers, NULL); 636 GNUNET_CONTAINER_multipeermap_iterate (peers, &try_add_peers, NULL);
635} 637}
636 638
637 639
@@ -643,47 +645,47 @@ add_peer_task(void *cls)
643 * @param internal_cls the `struct Peer` for this peer 645 * @param internal_cls the `struct Peer` for this peer
644 */ 646 */
645static void 647static void
646disconnect_notify(void *cls, 648disconnect_notify (void *cls,
647 const struct GNUNET_PeerIdentity *peer, 649 const struct GNUNET_PeerIdentity *peer,
648 void *internal_cls) 650 void *internal_cls)
649{ 651{
650 struct Peer *pos = internal_cls; 652 struct Peer *pos = internal_cls;
651 653
652 if (NULL == pos) 654 if (NULL == pos)
653 return; /* myself, we're shutting down */ 655 return; /* myself, we're shutting down */
654 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 656 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
655 "Core told us that we disconnected from `%s'\n", 657 "Core told us that we disconnected from `%s'\n",
656 GNUNET_i2s(peer)); 658 GNUNET_i2s (peer));
657 if (NULL == pos->mq) 659 if (NULL == pos->mq)
658 { 660 {
659 GNUNET_break(0); 661 GNUNET_break (0);
660 return; 662 return;
661 } 663 }
662 pos->mq = NULL; 664 pos->mq = NULL;
663 connection_count--; 665 connection_count--;
664 if (NULL != pos->hello_delay_task) 666 if (NULL != pos->hello_delay_task)
665 { 667 {
666 GNUNET_SCHEDULER_cancel(pos->hello_delay_task); 668 GNUNET_SCHEDULER_cancel (pos->hello_delay_task);
667 pos->hello_delay_task = NULL; 669 pos->hello_delay_task = NULL;
668 } 670 }
669 GNUNET_STATISTICS_set(stats, 671 GNUNET_STATISTICS_set (stats,
670 gettext_noop("# peers connected"), 672 gettext_noop ("# peers connected"),
671 connection_count, 673 connection_count,
672 GNUNET_NO); 674 GNUNET_NO);
673 if (pos->is_friend) 675 if (pos->is_friend)
674 { 676 {
675 friend_count--; 677 friend_count--;
676 GNUNET_STATISTICS_set(stats, 678 GNUNET_STATISTICS_set (stats,
677 gettext_noop("# friends connected"), 679 gettext_noop ("# friends connected"),
678 friend_count, 680 friend_count,
679 GNUNET_NO); 681 GNUNET_NO);
680 } 682 }
681 if (((connection_count < target_connection_count) || 683 if (((connection_count < target_connection_count) ||
682 (friend_count < minimum_friend_count)) && 684 (friend_count < minimum_friend_count)) &&
683 (NULL == add_task)) 685 (NULL == add_task))
684 add_task = GNUNET_SCHEDULER_add_now(&add_peer_task, NULL); 686 add_task = GNUNET_SCHEDULER_add_now (&add_peer_task, NULL);
685 if ((friend_count < minimum_friend_count) && (NULL == blacklist)) 687 if ((friend_count < minimum_friend_count) && (NULL == blacklist))
686 blacklist = GNUNET_TRANSPORT_blacklist(cfg, &blacklist_check, NULL); 688 blacklist = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_check, NULL);
687} 689}
688 690
689 691
@@ -696,9 +698,9 @@ disconnect_notify(void *cls,
696 * @return #GNUNET_SYSERR always, to terminate iteration 698 * @return #GNUNET_SYSERR always, to terminate iteration
697 */ 699 */
698static int 700static int
699address_iterator(void *cls, 701address_iterator (void *cls,
700 const struct GNUNET_HELLO_Address *address, 702 const struct GNUNET_HELLO_Address *address,
701 struct GNUNET_TIME_Absolute expiration) 703 struct GNUNET_TIME_Absolute expiration)
702{ 704{
703 int *flag = cls; 705 int *flag = cls;
704 706
@@ -714,7 +716,7 @@ address_iterator(void *cls,
714 * @param hello the HELLO we got 716 * @param hello the HELLO we got
715 */ 717 */
716static void 718static void
717consider_for_advertising(const struct GNUNET_HELLO_Message *hello) 719consider_for_advertising (const struct GNUNET_HELLO_Message *hello)
718{ 720{
719 int have_address; 721 int have_address;
720 struct GNUNET_PeerIdentity pid; 722 struct GNUNET_PeerIdentity pid;
@@ -723,55 +725,55 @@ consider_for_advertising(const struct GNUNET_HELLO_Message *hello)
723 struct Peer *peer; 725 struct Peer *peer;
724 uint16_t size; 726 uint16_t size;
725 727
726 if (GNUNET_OK != GNUNET_HELLO_get_id(hello, &pid)) 728 if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid))
727 { 729 {
728 GNUNET_break(0); 730 GNUNET_break (0);
729 return; 731 return;
730 } 732 }
731 if (0 == GNUNET_memcmp(&pid, &my_identity)) 733 if (0 == GNUNET_memcmp (&pid, &my_identity))
732 return; /* that's me! */ 734 return; /* that's me! */
733 have_address = GNUNET_NO; 735 have_address = GNUNET_NO;
734 GNUNET_HELLO_iterate_addresses(hello, 736 GNUNET_HELLO_iterate_addresses (hello,
735 GNUNET_NO, 737 GNUNET_NO,
736 &address_iterator, 738 &address_iterator,
737 &have_address); 739 &have_address);
738 if (GNUNET_NO == have_address) 740 if (GNUNET_NO == have_address)
739 return; /* no point in advertising this one... */ 741 return; /* no point in advertising this one... */
740 peer = GNUNET_CONTAINER_multipeermap_get(peers, &pid); 742 peer = GNUNET_CONTAINER_multipeermap_get (peers, &pid);
741 if (NULL == peer) 743 if (NULL == peer)
742 { 744 {
743 peer = make_peer(&pid, hello, GNUNET_NO); 745 peer = make_peer (&pid, hello, GNUNET_NO);
744 } 746 }
745 else if (NULL != peer->hello) 747 else if (NULL != peer->hello)
746 { 748 {
747 dt = GNUNET_HELLO_equals(peer->hello, hello, GNUNET_TIME_absolute_get()); 749 dt = GNUNET_HELLO_equals (peer->hello, hello, GNUNET_TIME_absolute_get ());
748 if (dt.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) 750 if (dt.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us)
749 return; /* nothing new here */ 751 return; /* nothing new here */
750 } 752 }
751 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 753 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
752 "Found HELLO from peer `%s' for advertising\n", 754 "Found HELLO from peer `%s' for advertising\n",
753 GNUNET_i2s(&pid)); 755 GNUNET_i2s (&pid));
754 if (NULL != peer->hello) 756 if (NULL != peer->hello)
755 { 757 {
756 nh = GNUNET_HELLO_merge(peer->hello, hello); 758 nh = GNUNET_HELLO_merge (peer->hello, hello);
757 GNUNET_free(peer->hello); 759 GNUNET_free (peer->hello);
758 peer->hello = nh; 760 peer->hello = nh;
759 } 761 }
760 else 762 else
761 { 763 {
762 size = GNUNET_HELLO_size(hello); 764 size = GNUNET_HELLO_size (hello);
763 peer->hello = GNUNET_malloc(size); 765 peer->hello = GNUNET_malloc (size);
764 GNUNET_memcpy(peer->hello, hello, size); 766 GNUNET_memcpy (peer->hello, hello, size);
765 } 767 }
766 if (NULL != peer->filter) 768 if (NULL != peer->filter)
767 { 769 {
768 GNUNET_CONTAINER_bloomfilter_free(peer->filter); 770 GNUNET_CONTAINER_bloomfilter_free (peer->filter);
769 peer->filter = NULL; 771 peer->filter = NULL;
770 } 772 }
771 setup_filter(peer); 773 setup_filter (peer);
772 /* since we have a new HELLO to pick from, re-schedule all 774 /* since we have a new HELLO to pick from, re-schedule all
773 * HELLO requests that are not bound by the HELLO send rate! */ 775 * HELLO requests that are not bound by the HELLO send rate! */
774 GNUNET_CONTAINER_multipeermap_iterate(peers, &reschedule_hellos, peer); 776 GNUNET_CONTAINER_multipeermap_iterate (peers, &reschedule_hellos, peer);
775} 777}
776 778
777 779
@@ -785,49 +787,49 @@ consider_for_advertising(const struct GNUNET_HELLO_Message *hello)
785 * @param err_msg NULL if successful, otherwise contains error message 787 * @param err_msg NULL if successful, otherwise contains error message
786 */ 788 */
787static void 789static void
788process_peer(void *cls, 790process_peer (void *cls,
789 const struct GNUNET_PeerIdentity *peer, 791 const struct GNUNET_PeerIdentity *peer,
790 const struct GNUNET_HELLO_Message *hello, 792 const struct GNUNET_HELLO_Message *hello,
791 const char *err_msg) 793 const char *err_msg)
792{ 794{
793 struct Peer *pos; 795 struct Peer *pos;
794 796
795 if (NULL != err_msg) 797 if (NULL != err_msg)
796 { 798 {
797 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 799 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
798 _("Error in communication with PEERINFO service: %s\n"), 800 _ ("Error in communication with PEERINFO service: %s\n"),
799 err_msg); 801 err_msg);
800 GNUNET_PEERINFO_notify_cancel(peerinfo_notify); 802 GNUNET_PEERINFO_notify_cancel (peerinfo_notify);
801 peerinfo_notify = 803 peerinfo_notify =
802 GNUNET_PEERINFO_notify(cfg, GNUNET_NO, &process_peer, NULL); 804 GNUNET_PEERINFO_notify (cfg, GNUNET_NO, &process_peer, NULL);
803 return; 805 return;
804 } 806 }
805 GNUNET_assert(NULL != peer); 807 GNUNET_assert (NULL != peer);
806 if (0 == GNUNET_memcmp(&my_identity, peer)) 808 if (0 == GNUNET_memcmp (&my_identity, peer))
807 return; /* that's me! */ 809 return; /* that's me! */
808 if (NULL == hello) 810 if (NULL == hello)
811 {
812 /* free existing HELLO, if any */
813 pos = GNUNET_CONTAINER_multipeermap_get (peers, peer);
814 if (NULL != pos)
809 { 815 {
810 /* free existing HELLO, if any */ 816 GNUNET_free_non_null (pos->hello);
811 pos = GNUNET_CONTAINER_multipeermap_get(peers, peer); 817 pos->hello = NULL;
812 if (NULL != pos) 818 if (NULL != pos->filter)
813 { 819 {
814 GNUNET_free_non_null(pos->hello); 820 GNUNET_CONTAINER_bloomfilter_free (pos->filter);
815 pos->hello = NULL; 821 pos->filter = NULL;
816 if (NULL != pos->filter) 822 }
817 { 823 if ((NULL == pos->mq) && (GNUNET_NO == pos->is_friend))
818 GNUNET_CONTAINER_bloomfilter_free(pos->filter); 824 free_peer (NULL, &pos->pid, pos);
819 pos->filter = NULL;
820 }
821 if ((NULL == pos->mq) && (GNUNET_NO == pos->is_friend))
822 free_peer(NULL, &pos->pid, pos);
823 }
824 return;
825 } 825 }
826 consider_for_advertising(hello); 826 return;
827 pos = GNUNET_CONTAINER_multipeermap_get(peers, peer); 827 }
828 consider_for_advertising (hello);
829 pos = GNUNET_CONTAINER_multipeermap_get (peers, peer);
828 if (NULL == pos) 830 if (NULL == pos)
829 pos = make_peer(peer, hello, GNUNET_NO); 831 pos = make_peer (peer, hello, GNUNET_NO);
830 attempt_connect(pos); 832 attempt_connect (pos);
831} 833}
832 834
833 835
@@ -839,20 +841,20 @@ process_peer(void *cls,
839 * @param my_id ID of this peer, NULL if we failed 841 * @param my_id ID of this peer, NULL if we failed
840 */ 842 */
841static void 843static void
842core_init(void *cls, const struct GNUNET_PeerIdentity *my_id) 844core_init (void *cls, const struct GNUNET_PeerIdentity *my_id)
843{ 845{
844 if (NULL == my_id) 846 if (NULL == my_id)
845 { 847 {
846 GNUNET_log( 848 GNUNET_log (
847 GNUNET_ERROR_TYPE_ERROR, 849 GNUNET_ERROR_TYPE_ERROR,
848 _("Failed to connect to core service, can not manage topology!\n")); 850 _ ("Failed to connect to core service, can not manage topology!\n"));
849 GNUNET_SCHEDULER_shutdown(); 851 GNUNET_SCHEDULER_shutdown ();
850 return; 852 return;
851 } 853 }
852 my_identity = *my_id; 854 my_identity = *my_id;
853 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "I am peer `%s'\n", GNUNET_i2s(my_id)); 855 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "I am peer `%s'\n", GNUNET_i2s (my_id));
854 peerinfo_notify = 856 peerinfo_notify =
855 GNUNET_PEERINFO_notify(cfg, GNUNET_NO, &process_peer, NULL); 857 GNUNET_PEERINFO_notify (cfg, GNUNET_NO, &process_peer, NULL);
856} 858}
857 859
858 860
@@ -863,23 +865,23 @@ core_init(void *cls, const struct GNUNET_PeerIdentity *my_id)
863 * @param pid identity of the friend 865 * @param pid identity of the friend
864 */ 866 */
865static void 867static void
866handle_friend(void *cls, const struct GNUNET_PeerIdentity *pid) 868handle_friend (void *cls, const struct GNUNET_PeerIdentity *pid)
867{ 869{
868 unsigned int *entries_found = cls; 870 unsigned int *entries_found = cls;
869 struct Peer *fl; 871 struct Peer *fl;
870 872
871 if (0 == GNUNET_memcmp(pid, &my_identity)) 873 if (0 == GNUNET_memcmp (pid, &my_identity))
872 { 874 {
873 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 875 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
874 _("Found myself `%s' in friend list (useless, ignored)\n"), 876 _ ("Found myself `%s' in friend list (useless, ignored)\n"),
875 GNUNET_i2s(pid)); 877 GNUNET_i2s (pid));
876 return; 878 return;
877 } 879 }
878 (*entries_found)++; 880 (*entries_found)++;
879 fl = make_peer(pid, NULL, GNUNET_YES); 881 fl = make_peer (pid, NULL, GNUNET_YES);
880 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 882 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
881 _("Found friend `%s' in configuration\n"), 883 _ ("Found friend `%s' in configuration\n"),
882 GNUNET_i2s(&fl->pid)); 884 GNUNET_i2s (&fl->pid));
883} 885}
884 886
885 887
@@ -887,36 +889,36 @@ handle_friend(void *cls, const struct GNUNET_PeerIdentity *pid)
887 * Read the friends file. 889 * Read the friends file.
888 */ 890 */
889static void 891static void
890read_friends_file(const struct GNUNET_CONFIGURATION_Handle *cfg) 892read_friends_file (const struct GNUNET_CONFIGURATION_Handle *cfg)
891{ 893{
892 unsigned int entries_found; 894 unsigned int entries_found;
893 895
894 entries_found = 0; 896 entries_found = 0;
895 if (GNUNET_OK != GNUNET_FRIENDS_parse(cfg, &handle_friend, &entries_found)) 897 if (GNUNET_OK != GNUNET_FRIENDS_parse (cfg, &handle_friend, &entries_found))
896 { 898 {
897 if ((GNUNET_YES == friends_only) || (minimum_friend_count > 0)) 899 if ((GNUNET_YES == friends_only) || (minimum_friend_count > 0))
898 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 900 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
899 _("Encountered errors parsing friends list!\n")); 901 _ ("Encountered errors parsing friends list!\n"));
900 } 902 }
901 GNUNET_STATISTICS_update(stats, 903 GNUNET_STATISTICS_update (stats,
902 gettext_noop("# friends in configuration"), 904 gettext_noop ("# friends in configuration"),
903 entries_found, 905 entries_found,
904 GNUNET_NO); 906 GNUNET_NO);
905 if ((minimum_friend_count > entries_found) && (GNUNET_NO == friends_only)) 907 if ((minimum_friend_count > entries_found) && (GNUNET_NO == friends_only))
906 { 908 {
907 GNUNET_log( 909 GNUNET_log (
908 GNUNET_ERROR_TYPE_WARNING, 910 GNUNET_ERROR_TYPE_WARNING,
909 _( 911 _ (
910 "Fewer friends specified than required by minimum friend count. Will only connect to friends.\n")); 912 "Fewer friends specified than required by minimum friend count. Will only connect to friends.\n"));
911 } 913 }
912 if ((minimum_friend_count > target_connection_count) && 914 if ((minimum_friend_count > target_connection_count) &&
913 (GNUNET_NO == friends_only)) 915 (GNUNET_NO == friends_only))
914 { 916 {
915 GNUNET_log( 917 GNUNET_log (
916 GNUNET_ERROR_TYPE_WARNING, 918 GNUNET_ERROR_TYPE_WARNING,
917 _( 919 _ (
918 "More friendly connections required than target total number of connections.\n")); 920 "More friendly connections required than target total number of connections.\n"));
919 } 921 }
920} 922}
921 923
922 924
@@ -930,15 +932,15 @@ read_friends_file(const struct GNUNET_CONFIGURATION_Handle *cfg)
930 * #GNUNET_SYSERR if @a message is invalid 932 * #GNUNET_SYSERR if @a message is invalid
931 */ 933 */
932static int 934static int
933check_hello(void *cls, const struct GNUNET_HELLO_Message *message) 935check_hello (void *cls, const struct GNUNET_HELLO_Message *message)
934{ 936{
935 struct GNUNET_PeerIdentity pid; 937 struct GNUNET_PeerIdentity pid;
936 938
937 if (GNUNET_OK != GNUNET_HELLO_get_id(message, &pid)) 939 if (GNUNET_OK != GNUNET_HELLO_get_id (message, &pid))
938 { 940 {
939 GNUNET_break_op(0); 941 GNUNET_break_op (0);
940 return GNUNET_SYSERR; 942 return GNUNET_SYSERR;
941 } 943 }
942 return GNUNET_OK; 944 return GNUNET_OK;
943} 945}
944 946
@@ -951,35 +953,35 @@ check_hello(void *cls, const struct GNUNET_HELLO_Message *message)
951 * @param message the actual HELLO message 953 * @param message the actual HELLO message
952 */ 954 */
953static void 955static void
954handle_hello(void *cls, const struct GNUNET_HELLO_Message *message) 956handle_hello (void *cls, const struct GNUNET_HELLO_Message *message)
955{ 957{
956 const struct GNUNET_PeerIdentity *other = cls; 958 const struct GNUNET_PeerIdentity *other = cls;
957 struct Peer *peer; 959 struct Peer *peer;
958 struct GNUNET_PeerIdentity pid; 960 struct GNUNET_PeerIdentity pid;
959 961
960 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 962 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
961 "Received encrypted HELLO from peer `%s'", 963 "Received encrypted HELLO from peer `%s'",
962 GNUNET_i2s(other)); 964 GNUNET_i2s (other));
963 GNUNET_assert(GNUNET_OK == GNUNET_HELLO_get_id(message, &pid)); 965 GNUNET_assert (GNUNET_OK == GNUNET_HELLO_get_id (message, &pid));
964 GNUNET_STATISTICS_update(stats, 966 GNUNET_STATISTICS_update (stats,
965 gettext_noop("# HELLO messages received"), 967 gettext_noop ("# HELLO messages received"),
966 1, 968 1,
967 GNUNET_NO); 969 GNUNET_NO);
968 peer = GNUNET_CONTAINER_multipeermap_get(peers, &pid); 970 peer = GNUNET_CONTAINER_multipeermap_get (peers, &pid);
969 if (NULL == peer) 971 if (NULL == peer)
970 { 972 {
971 if ((GNUNET_YES == friends_only) || (friend_count < minimum_friend_count)) 973 if ((GNUNET_YES == friends_only) || (friend_count < minimum_friend_count))
972 return; 974 return;
973 } 975 }
974 else 976 else
975 { 977 {
976 if ((GNUNET_YES != peer->is_friend) && (GNUNET_YES == friends_only)) 978 if ((GNUNET_YES != peer->is_friend) && (GNUNET_YES == friends_only))
977 return; 979 return;
978 if ((GNUNET_YES != peer->is_friend) && 980 if ((GNUNET_YES != peer->is_friend) &&
979 (friend_count < minimum_friend_count)) 981 (friend_count < minimum_friend_count))
980 return; 982 return;
981 } 983 }
982 (void)GNUNET_PEERINFO_add_peer(pi, message, NULL, NULL); 984 (void) GNUNET_PEERINFO_add_peer (pi, message, NULL, NULL);
983} 985}
984 986
985 987
@@ -990,47 +992,47 @@ handle_hello(void *cls, const struct GNUNET_HELLO_Message *message)
990 * @param cls unused, NULL 992 * @param cls unused, NULL
991 */ 993 */
992static void 994static void
993cleaning_task(void *cls) 995cleaning_task (void *cls)
994{ 996{
995 if (NULL != peerinfo_notify) 997 if (NULL != peerinfo_notify)
996 { 998 {
997 GNUNET_PEERINFO_notify_cancel(peerinfo_notify); 999 GNUNET_PEERINFO_notify_cancel (peerinfo_notify);
998 peerinfo_notify = NULL; 1000 peerinfo_notify = NULL;
999 } 1001 }
1000 if (NULL != handle) 1002 if (NULL != handle)
1001 { 1003 {
1002 GNUNET_CORE_disconnect(handle); 1004 GNUNET_CORE_disconnect (handle);
1003 handle = NULL; 1005 handle = NULL;
1004 } 1006 }
1005 whitelist_peers(); 1007 whitelist_peers ();
1006 if (NULL != add_task) 1008 if (NULL != add_task)
1007 { 1009 {
1008 GNUNET_SCHEDULER_cancel(add_task); 1010 GNUNET_SCHEDULER_cancel (add_task);
1009 add_task = NULL; 1011 add_task = NULL;
1010 } 1012 }
1011 if (NULL != oh) 1013 if (NULL != oh)
1012 { 1014 {
1013 GNUNET_TRANSPORT_offer_hello_cancel(oh); 1015 GNUNET_TRANSPORT_offer_hello_cancel (oh);
1014 oh = NULL; 1016 oh = NULL;
1015 } 1017 }
1016 GNUNET_CONTAINER_multipeermap_iterate(peers, &free_peer, NULL); 1018 GNUNET_CONTAINER_multipeermap_iterate (peers, &free_peer, NULL);
1017 GNUNET_CONTAINER_multipeermap_destroy(peers); 1019 GNUNET_CONTAINER_multipeermap_destroy (peers);
1018 peers = NULL; 1020 peers = NULL;
1019 if (NULL != ats) 1021 if (NULL != ats)
1020 { 1022 {
1021 GNUNET_ATS_connectivity_done(ats); 1023 GNUNET_ATS_connectivity_done (ats);
1022 ats = NULL; 1024 ats = NULL;
1023 } 1025 }
1024 if (NULL != pi) 1026 if (NULL != pi)
1025 { 1027 {
1026 GNUNET_PEERINFO_disconnect(pi); 1028 GNUNET_PEERINFO_disconnect (pi);
1027 pi = NULL; 1029 pi = NULL;
1028 } 1030 }
1029 if (NULL != stats) 1031 if (NULL != stats)
1030 { 1032 {
1031 GNUNET_STATISTICS_destroy(stats, GNUNET_NO); 1033 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
1032 stats = NULL; 1034 stats = NULL;
1033 } 1035 }
1034} 1036}
1035 1037
1036 1038
@@ -1043,62 +1045,62 @@ cleaning_task(void *cls)
1043 * @param c configuration 1045 * @param c configuration
1044 */ 1046 */
1045static void 1047static void
1046run(void *cls, 1048run (void *cls,
1047 char *const *args, 1049 char *const *args,
1048 const char *cfgfile, 1050 const char *cfgfile,
1049 const struct GNUNET_CONFIGURATION_Handle *c) 1051 const struct GNUNET_CONFIGURATION_Handle *c)
1050{ 1052{
1051 struct GNUNET_MQ_MessageHandler handlers[] = 1053 struct GNUNET_MQ_MessageHandler handlers[] =
1052 { GNUNET_MQ_hd_var_size(hello, 1054 { GNUNET_MQ_hd_var_size (hello,
1053 GNUNET_MESSAGE_TYPE_HELLO, 1055 GNUNET_MESSAGE_TYPE_HELLO,
1054 struct GNUNET_HELLO_Message, 1056 struct GNUNET_HELLO_Message,
1055 NULL), 1057 NULL),
1056 GNUNET_MQ_handler_end() }; 1058 GNUNET_MQ_handler_end () };
1057 unsigned long long opt; 1059 unsigned long long opt;
1058 1060
1059 cfg = c; 1061 cfg = c;
1060 stats = GNUNET_STATISTICS_create("topology", cfg); 1062 stats = GNUNET_STATISTICS_create ("topology", cfg);
1061 friends_only = 1063 friends_only =
1062 GNUNET_CONFIGURATION_get_value_yesno(cfg, "TOPOLOGY", "FRIENDS-ONLY"); 1064 GNUNET_CONFIGURATION_get_value_yesno (cfg, "TOPOLOGY", "FRIENDS-ONLY");
1063 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(cfg, 1065 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
1064 "TOPOLOGY", 1066 "TOPOLOGY",
1065 "MINIMUM-FRIENDS", 1067 "MINIMUM-FRIENDS",
1066 &opt)) 1068 &opt))
1067 opt = 0; 1069 opt = 0;
1068 minimum_friend_count = (unsigned int)opt; 1070 minimum_friend_count = (unsigned int) opt;
1069 if (GNUNET_OK != 1071 if (GNUNET_OK !=
1070 GNUNET_CONFIGURATION_get_value_number(cfg, 1072 GNUNET_CONFIGURATION_get_value_number (cfg,
1071 "TOPOLOGY", 1073 "TOPOLOGY",
1072 "TARGET-CONNECTION-COUNT", 1074 "TARGET-CONNECTION-COUNT",
1073 &opt)) 1075 &opt))
1074 opt = 16; 1076 opt = 16;
1075 target_connection_count = (unsigned int)opt; 1077 target_connection_count = (unsigned int) opt;
1076 peers = GNUNET_CONTAINER_multipeermap_create(target_connection_count * 2, 1078 peers = GNUNET_CONTAINER_multipeermap_create (target_connection_count * 2,
1077 GNUNET_NO); 1079 GNUNET_NO);
1078 read_friends_file(cfg); 1080 read_friends_file (cfg);
1079 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1081 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1080 "Topology would like %u connections with at least %u friends\n", 1082 "Topology would like %u connections with at least %u friends\n",
1081 target_connection_count, 1083 target_connection_count,
1082 minimum_friend_count); 1084 minimum_friend_count);
1083 if ((GNUNET_YES == friends_only) || (minimum_friend_count > 0)) 1085 if ((GNUNET_YES == friends_only) || (minimum_friend_count > 0))
1084 blacklist = GNUNET_TRANSPORT_blacklist(cfg, &blacklist_check, NULL); 1086 blacklist = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_check, NULL);
1085 ats = GNUNET_ATS_connectivity_init(cfg); 1087 ats = GNUNET_ATS_connectivity_init (cfg);
1086 pi = GNUNET_PEERINFO_connect(cfg); 1088 pi = GNUNET_PEERINFO_connect (cfg);
1087 handle = GNUNET_CORE_connect(cfg, 1089 handle = GNUNET_CORE_connect (cfg,
1088 NULL, 1090 NULL,
1089 &core_init, 1091 &core_init,
1090 &connect_notify, 1092 &connect_notify,
1091 &disconnect_notify, 1093 &disconnect_notify,
1092 handlers); 1094 handlers);
1093 GNUNET_SCHEDULER_add_shutdown(&cleaning_task, NULL); 1095 GNUNET_SCHEDULER_add_shutdown (&cleaning_task, NULL);
1094 if (NULL == handle) 1096 if (NULL == handle)
1095 { 1097 {
1096 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1098 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1097 _("Failed to connect to `%s' service.\n"), 1099 _ ("Failed to connect to `%s' service.\n"),
1098 "core"); 1100 "core");
1099 GNUNET_SCHEDULER_shutdown(); 1101 GNUNET_SCHEDULER_shutdown ();
1100 return; 1102 return;
1101 } 1103 }
1102} 1104}
1103 1105
1104 1106
@@ -1110,26 +1112,26 @@ run(void *cls,
1110 * @return 0 ok, 1 on error 1112 * @return 0 ok, 1 on error
1111 */ 1113 */
1112int 1114int
1113main(int argc, char *const *argv) 1115main (int argc, char *const *argv)
1114{ 1116{
1115 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 1117 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
1116 GNUNET_GETOPT_OPTION_END 1118 GNUNET_GETOPT_OPTION_END
1117 }; 1119 };
1118 int ret; 1120 int ret;
1119 1121
1120 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) 1122 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1121 return 2; 1123 return 2;
1122 1124
1123 ret = (GNUNET_OK == GNUNET_PROGRAM_run(argc, 1125 ret = (GNUNET_OK == GNUNET_PROGRAM_run (argc,
1124 argv, 1126 argv,
1125 "gnunet-daemon-topology", 1127 "gnunet-daemon-topology",
1126 _("GNUnet topology control"), 1128 _ ("GNUnet topology control"),
1127 options, 1129 options,
1128 &run, 1130 &run,
1129 NULL)) 1131 NULL))
1130 ? 0 1132 ? 0
1131 : 1; 1133 : 1;
1132 GNUNET_free((void *)argv); 1134 GNUNET_free ((void *) argv);
1133 return ret; 1135 return ret;
1134} 1136}
1135 1137
@@ -1140,11 +1142,11 @@ main(int argc, char *const *argv)
1140/** 1142/**
1141 * MINIMIZE heap size (way below 128k) since this process doesn't need much. 1143 * MINIMIZE heap size (way below 128k) since this process doesn't need much.
1142 */ 1144 */
1143void __attribute__ ((constructor)) GNUNET_ARM_memory_init() 1145void __attribute__ ((constructor)) GNUNET_ARM_memory_init ()
1144{ 1146{
1145 mallopt(M_TRIM_THRESHOLD, 4 * 1024); 1147 mallopt (M_TRIM_THRESHOLD, 4 * 1024);
1146 mallopt(M_TOP_PAD, 1 * 1024); 1148 mallopt (M_TOP_PAD, 1 * 1024);
1147 malloc_trim(0); 1149 malloc_trim (0);
1148} 1150}
1149#endif 1151#endif
1150 1152