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