diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:46:35 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:46:35 +0000 |
commit | 502af2167f7c218366666ca4944bd7cc54b5b19a (patch) | |
tree | a91fec5cc9769d260640bd91c6633cb9cf395524 /src/topology/gnunet-daemon-topology.c | |
parent | 03af5a603b7cc53432249d5854cd412aa90dde0d (diff) | |
download | gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.tar.gz gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.zip |
indentation
Diffstat (limited to 'src/topology/gnunet-daemon-topology.c')
-rw-r--r-- | src/topology/gnunet-daemon-topology.c | 1080 |
1 files changed, 485 insertions, 595 deletions
diff --git a/src/topology/gnunet-daemon-topology.c b/src/topology/gnunet-daemon-topology.c index 5b6829375..91d0ed12d 100644 --- a/src/topology/gnunet-daemon-topology.c +++ b/src/topology/gnunet-daemon-topology.c | |||
@@ -86,13 +86,13 @@ struct Peer | |||
86 | * Our handle for the request to transmit HELLOs to this peer; NULL | 86 | * Our handle for the request to transmit HELLOs to this peer; NULL |
87 | * if no such request is pending. | 87 | * if no such request is pending. |
88 | */ | 88 | */ |
89 | struct GNUNET_CORE_TransmitHandle *hello_req; | 89 | struct GNUNET_CORE_TransmitHandle *hello_req; |
90 | 90 | ||
91 | /** | 91 | /** |
92 | * Our handle for the request to connect to this peer; NULL if no | 92 | * Our handle for the request to connect to this peer; NULL if no |
93 | * such request is pending. | 93 | * such request is pending. |
94 | */ | 94 | */ |
95 | struct GNUNET_CORE_PeerRequestHandle *connect_req; | 95 | struct GNUNET_CORE_PeerRequestHandle *connect_req; |
96 | 96 | ||
97 | /** | 97 | /** |
98 | * Pointer to the HELLO message of this peer; can be NULL. | 98 | * Pointer to the HELLO message of this peer; can be NULL. |
@@ -240,19 +240,15 @@ static int autoconnect; | |||
240 | * @return GNUNET_OK if the connection is allowed | 240 | * @return GNUNET_OK if the connection is allowed |
241 | */ | 241 | */ |
242 | static int | 242 | static int |
243 | blacklist_check (void *cls, | 243 | blacklist_check (void *cls, const struct GNUNET_PeerIdentity *pid) |
244 | const struct GNUNET_PeerIdentity *pid) | ||
245 | { | 244 | { |
246 | struct Peer *pos; | 245 | struct Peer *pos; |
247 | 246 | ||
248 | pos = GNUNET_CONTAINER_multihashmap_get (peers, &pid->hashPubKey); | 247 | pos = GNUNET_CONTAINER_multihashmap_get (peers, &pid->hashPubKey); |
249 | if ( (pos != NULL) && | 248 | if ((pos != NULL) && (pos->is_friend == GNUNET_YES)) |
250 | (pos->is_friend == GNUNET_YES) ) | ||
251 | return GNUNET_OK; | 249 | return GNUNET_OK; |
252 | GNUNET_STATISTICS_update (stats, | 250 | GNUNET_STATISTICS_update (stats, |
253 | gettext_noop ("# peers blacklisted"), | 251 | gettext_noop ("# peers blacklisted"), 1, GNUNET_NO); |
254 | 1, | ||
255 | GNUNET_NO); | ||
256 | return GNUNET_SYSERR; | 252 | return GNUNET_SYSERR; |
257 | } | 253 | } |
258 | 254 | ||
@@ -265,10 +261,10 @@ static void | |||
265 | whitelist_peers () | 261 | whitelist_peers () |
266 | { | 262 | { |
267 | if (blacklist != NULL) | 263 | if (blacklist != NULL) |
268 | { | 264 | { |
269 | GNUNET_TRANSPORT_blacklist_cancel (blacklist); | 265 | GNUNET_TRANSPORT_blacklist_cancel (blacklist); |
270 | blacklist = NULL; | 266 | blacklist = NULL; |
271 | } | 267 | } |
272 | } | 268 | } |
273 | 269 | ||
274 | 270 | ||
@@ -279,8 +275,7 @@ whitelist_peers () | |||
279 | * @param success was the request transmitted | 275 | * @param success was the request transmitted |
280 | */ | 276 | */ |
281 | static void | 277 | static void |
282 | connect_completed_callback (void *cls, | 278 | connect_completed_callback (void *cls, int success) |
283 | int success) | ||
284 | { | 279 | { |
285 | struct Peer *pos = cls; | 280 | struct Peer *pos = cls; |
286 | 281 | ||
@@ -297,28 +292,27 @@ connect_completed_callback (void *cls, | |||
297 | static int | 292 | static int |
298 | is_connection_allowed (struct Peer *peer) | 293 | is_connection_allowed (struct Peer *peer) |
299 | { | 294 | { |
300 | if (0 == memcmp (&my_identity, | 295 | if (0 == memcmp (&my_identity, |
301 | &peer->pid, | 296 | &peer->pid, sizeof (struct GNUNET_PeerIdentity))) |
302 | sizeof (struct GNUNET_PeerIdentity))) | ||
303 | return GNUNET_SYSERR; /* disallow connections to self */ | 297 | return GNUNET_SYSERR; /* disallow connections to self */ |
304 | if (peer->is_friend) | 298 | if (peer->is_friend) |
305 | return GNUNET_OK; | 299 | return GNUNET_OK; |
306 | if (GNUNET_YES == friends_only) | 300 | if (GNUNET_YES == friends_only) |
307 | { | 301 | { |
308 | #if DEBUG_TOPOLOGY | 302 | #if DEBUG_TOPOLOGY |
309 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 303 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
310 | "Determined that `%s' is not allowed to connect (not a friend)\n", | 304 | "Determined that `%s' is not allowed to connect (not a friend)\n", |
311 | GNUNET_i2s (&peer->pid)); | 305 | GNUNET_i2s (&peer->pid)); |
312 | #endif | 306 | #endif |
313 | return GNUNET_SYSERR; | 307 | return GNUNET_SYSERR; |
314 | } | 308 | } |
315 | if (friend_count >= minimum_friend_count) | 309 | if (friend_count >= minimum_friend_count) |
316 | return GNUNET_OK; | 310 | return GNUNET_OK; |
317 | #if DEBUG_TOPOLOGY | 311 | #if DEBUG_TOPOLOGY |
318 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 312 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
319 | "Determined that `%s' is not allowed to connect (not enough connected friends)\n", | 313 | "Determined that `%s' is not allowed to connect (not enough connected friends)\n", |
320 | GNUNET_i2s (&peer->pid)); | 314 | GNUNET_i2s (&peer->pid)); |
321 | #endif | 315 | #endif |
322 | return GNUNET_SYSERR; | 316 | return GNUNET_SYSERR; |
323 | } | 317 | } |
324 | 318 | ||
@@ -332,25 +326,21 @@ is_connection_allowed (struct Peer *peer) | |||
332 | * @return GNUNET_YES (always: continue to iterate) | 326 | * @return GNUNET_YES (always: continue to iterate) |
333 | */ | 327 | */ |
334 | static int | 328 | static int |
335 | free_peer (void *cls, | 329 | free_peer (void *cls, const GNUNET_HashCode * pid, void *value) |
336 | const GNUNET_HashCode *pid, | ||
337 | void *value) | ||
338 | { | 330 | { |
339 | struct Peer *pos = value; | 331 | struct Peer *pos = value; |
340 | 332 | ||
341 | GNUNET_break (GNUNET_OK == | 333 | GNUNET_break (GNUNET_OK == |
342 | GNUNET_CONTAINER_multihashmap_remove (peers, | 334 | GNUNET_CONTAINER_multihashmap_remove (peers, pid, pos)); |
343 | pid, | ||
344 | pos)); | ||
345 | if (pos->hello_req != NULL) | 335 | if (pos->hello_req != NULL) |
346 | GNUNET_CORE_notify_transmit_ready_cancel (pos->hello_req); | 336 | GNUNET_CORE_notify_transmit_ready_cancel (pos->hello_req); |
347 | if (pos->connect_req != NULL) | 337 | if (pos->connect_req != NULL) |
348 | GNUNET_CORE_peer_request_connect_cancel (pos->connect_req); | 338 | GNUNET_CORE_peer_request_connect_cancel (pos->connect_req); |
349 | if (pos->hello_delay_task != GNUNET_SCHEDULER_NO_TASK) | 339 | if (pos->hello_delay_task != GNUNET_SCHEDULER_NO_TASK) |
350 | GNUNET_SCHEDULER_cancel (pos->hello_delay_task); | 340 | GNUNET_SCHEDULER_cancel (pos->hello_delay_task); |
351 | if (pos->greylist_clean_task != GNUNET_SCHEDULER_NO_TASK) | 341 | if (pos->greylist_clean_task != GNUNET_SCHEDULER_NO_TASK) |
352 | GNUNET_SCHEDULER_cancel (pos->greylist_clean_task); | 342 | GNUNET_SCHEDULER_cancel (pos->greylist_clean_task); |
353 | GNUNET_free_non_null (pos->hello); | 343 | GNUNET_free_non_null (pos->hello); |
354 | if (pos->filter != NULL) | 344 | if (pos->filter != NULL) |
355 | GNUNET_CONTAINER_bloomfilter_free (pos->filter); | 345 | GNUNET_CONTAINER_bloomfilter_free (pos->filter); |
356 | GNUNET_free (pos); | 346 | GNUNET_free (pos); |
@@ -366,8 +356,7 @@ free_peer (void *cls, | |||
366 | * @param tc scheduler context | 356 | * @param tc scheduler context |
367 | */ | 357 | */ |
368 | static void | 358 | static void |
369 | remove_from_greylist (void *cls, | 359 | remove_from_greylist (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
370 | const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
371 | 360 | ||
372 | 361 | ||
373 | /** | 362 | /** |
@@ -379,9 +368,9 @@ static void | |||
379 | attempt_connect (struct Peer *pos) | 368 | attempt_connect (struct Peer *pos) |
380 | { | 369 | { |
381 | struct GNUNET_TIME_Relative rem; | 370 | struct GNUNET_TIME_Relative rem; |
382 | 371 | ||
383 | if ( (connection_count >= target_connection_count) && | 372 | if ((connection_count >= target_connection_count) && |
384 | (friend_count >= minimum_friend_count) ) | 373 | (friend_count >= minimum_friend_count)) |
385 | return; | 374 | return; |
386 | if (GNUNET_YES == pos->is_connected) | 375 | if (GNUNET_YES == pos->is_connected) |
387 | return; | 376 | return; |
@@ -398,30 +387,24 @@ attempt_connect (struct Peer *pos) | |||
398 | if (pos->connect_attempts > 30) | 387 | if (pos->connect_attempts > 30) |
399 | pos->connect_attempts = 30; | 388 | pos->connect_attempts = 30; |
400 | rem = GNUNET_TIME_relative_multiply (rem, 1 << (++pos->connect_attempts)); | 389 | rem = GNUNET_TIME_relative_multiply (rem, 1 << (++pos->connect_attempts)); |
401 | rem = GNUNET_TIME_relative_max (rem, | 390 | rem = GNUNET_TIME_relative_max (rem, GREYLIST_AFTER_ATTEMPT_MIN); |
402 | GREYLIST_AFTER_ATTEMPT_MIN); | 391 | rem = GNUNET_TIME_relative_min (rem, GREYLIST_AFTER_ATTEMPT_MAX); |
403 | rem = GNUNET_TIME_relative_min (rem, | ||
404 | GREYLIST_AFTER_ATTEMPT_MAX); | ||
405 | pos->greylisted_until = GNUNET_TIME_relative_to_absolute (rem); | 392 | pos->greylisted_until = GNUNET_TIME_relative_to_absolute (rem); |
406 | if (pos->greylist_clean_task != GNUNET_SCHEDULER_NO_TASK) | 393 | if (pos->greylist_clean_task != GNUNET_SCHEDULER_NO_TASK) |
407 | GNUNET_SCHEDULER_cancel (pos->greylist_clean_task); | 394 | GNUNET_SCHEDULER_cancel (pos->greylist_clean_task); |
408 | pos->greylist_clean_task | 395 | pos->greylist_clean_task |
409 | = GNUNET_SCHEDULER_add_delayed (rem, | 396 | = GNUNET_SCHEDULER_add_delayed (rem, &remove_from_greylist, pos); |
410 | &remove_from_greylist, | ||
411 | pos); | ||
412 | #if DEBUG_TOPOLOGY | 397 | #if DEBUG_TOPOLOGY |
413 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 398 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
414 | "Asking to connect to `%s'\n", | 399 | "Asking to connect to `%s'\n", GNUNET_i2s (&pos->pid)); |
415 | GNUNET_i2s (&pos->pid)); | ||
416 | #endif | 400 | #endif |
417 | GNUNET_STATISTICS_update (stats, | 401 | GNUNET_STATISTICS_update (stats, |
418 | gettext_noop ("# connect requests issued to core"), | 402 | gettext_noop ("# connect requests issued to core"), |
419 | 1, | 403 | 1, GNUNET_NO); |
420 | GNUNET_NO); | ||
421 | pos->connect_req = GNUNET_CORE_peer_request_connect (handle, | 404 | pos->connect_req = GNUNET_CORE_peer_request_connect (handle, |
422 | &pos->pid, | 405 | &pos->pid, |
423 | &connect_completed_callback, | 406 | &connect_completed_callback, |
424 | pos); | 407 | pos); |
425 | } | 408 | } |
426 | 409 | ||
427 | 410 | ||
@@ -433,8 +416,7 @@ attempt_connect (struct Peer *pos) | |||
433 | * @param tc scheduler context | 416 | * @param tc scheduler context |
434 | */ | 417 | */ |
435 | static void | 418 | static void |
436 | remove_from_greylist (void *cls, | 419 | remove_from_greylist (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
437 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
438 | { | 420 | { |
439 | struct Peer *pos = cls; | 421 | struct Peer *pos = cls; |
440 | struct GNUNET_TIME_Relative rem; | 422 | struct GNUNET_TIME_Relative rem; |
@@ -442,23 +424,20 @@ remove_from_greylist (void *cls, | |||
442 | pos->greylist_clean_task = GNUNET_SCHEDULER_NO_TASK; | 424 | pos->greylist_clean_task = GNUNET_SCHEDULER_NO_TASK; |
443 | rem = GNUNET_TIME_absolute_get_remaining (pos->greylisted_until); | 425 | rem = GNUNET_TIME_absolute_get_remaining (pos->greylisted_until); |
444 | if (rem.rel_value == 0) | 426 | if (rem.rel_value == 0) |
445 | { | 427 | { |
446 | attempt_connect (pos); | 428 | attempt_connect (pos); |
447 | } | 429 | } |
448 | else | 430 | else |
449 | { | 431 | { |
450 | pos->greylist_clean_task | 432 | pos->greylist_clean_task |
451 | = GNUNET_SCHEDULER_add_delayed (rem, | 433 | = GNUNET_SCHEDULER_add_delayed (rem, &remove_from_greylist, pos); |
452 | &remove_from_greylist, | 434 | } |
453 | pos); | 435 | if ((GNUNET_NO == pos->is_friend) && |
454 | } | 436 | (GNUNET_NO == pos->is_connected) && (NULL == pos->hello)) |
455 | if ( (GNUNET_NO == pos->is_friend) && | 437 | { |
456 | (GNUNET_NO == pos->is_connected) && | 438 | free_peer (NULL, &pos->pid.hashPubKey, pos); |
457 | (NULL == pos->hello) ) | 439 | return; |
458 | { | 440 | } |
459 | free_peer (NULL, &pos->pid.hashPubKey, pos); | ||
460 | return; | ||
461 | } | ||
462 | } | 441 | } |
463 | 442 | ||
464 | 443 | ||
@@ -472,26 +451,24 @@ remove_from_greylist (void *cls, | |||
472 | */ | 451 | */ |
473 | static struct Peer * | 452 | static struct Peer * |
474 | make_peer (const struct | 453 | make_peer (const struct |
475 | GNUNET_PeerIdentity * peer, | 454 | GNUNET_PeerIdentity *peer, |
476 | const struct GNUNET_HELLO_Message *hello, | 455 | const struct GNUNET_HELLO_Message *hello, int is_friend) |
477 | int is_friend) | ||
478 | { | 456 | { |
479 | struct Peer *ret; | 457 | struct Peer *ret; |
480 | 458 | ||
481 | ret = GNUNET_malloc (sizeof (struct Peer)); | 459 | ret = GNUNET_malloc (sizeof (struct Peer)); |
482 | ret->pid = *peer; | 460 | ret->pid = *peer; |
483 | ret->is_friend = is_friend; | 461 | ret->is_friend = is_friend; |
484 | if (hello != NULL) | 462 | if (hello != NULL) |
485 | { | 463 | { |
486 | ret->hello = GNUNET_malloc (GNUNET_HELLO_size (hello)); | 464 | ret->hello = GNUNET_malloc (GNUNET_HELLO_size (hello)); |
487 | memcpy (ret->hello, hello, | 465 | memcpy (ret->hello, hello, GNUNET_HELLO_size (hello)); |
488 | GNUNET_HELLO_size (hello)); | 466 | } |
489 | } | ||
490 | GNUNET_break (GNUNET_OK == | 467 | GNUNET_break (GNUNET_OK == |
491 | GNUNET_CONTAINER_multihashmap_put (peers, | 468 | GNUNET_CONTAINER_multihashmap_put (peers, |
492 | &peer->hashPubKey, | 469 | &peer->hashPubKey, |
493 | ret, | 470 | ret, |
494 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 471 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
495 | return ret; | 472 | return ret; |
496 | } | 473 | } |
497 | 474 | ||
@@ -505,14 +482,16 @@ static void | |||
505 | setup_filter (struct Peer *peer) | 482 | setup_filter (struct Peer *peer) |
506 | { | 483 | { |
507 | /* 2^{-5} chance of not sending a HELLO to a peer is | 484 | /* 2^{-5} chance of not sending a HELLO to a peer is |
508 | acceptably small (if the filter is 50% full); | 485 | * acceptably small (if the filter is 50% full); |
509 | 64 bytes of memory are small compared to the rest | 486 | * 64 bytes of memory are small compared to the rest |
510 | of the data structure and would only really become | 487 | * of the data structure and would only really become |
511 | "useless" once a HELLO has been passed on to ~100 | 488 | * "useless" once a HELLO has been passed on to ~100 |
512 | other peers, which is likely more than enough in | 489 | * other peers, which is likely more than enough in |
513 | any case; hence 64, 5 as bloomfilter parameters. */ | 490 | * any case; hence 64, 5 as bloomfilter parameters. */ |
514 | peer->filter = GNUNET_CONTAINER_bloomfilter_init (NULL, 64, 5); | 491 | peer->filter = GNUNET_CONTAINER_bloomfilter_init (NULL, 64, 5); |
515 | peer->filter_expiration = GNUNET_TIME_relative_to_absolute (HELLO_ADVERTISEMENT_MIN_REPEAT_FREQUENCY); | 492 | peer->filter_expiration = |
493 | GNUNET_TIME_relative_to_absolute | ||
494 | (HELLO_ADVERTISEMENT_MIN_REPEAT_FREQUENCY); | ||
516 | /* never send a peer its own HELLO */ | 495 | /* never send a peer its own HELLO */ |
517 | GNUNET_CONTAINER_bloomfilter_add (peer->filter, &peer->pid.hashPubKey); | 496 | GNUNET_CONTAINER_bloomfilter_add (peer->filter, &peer->pid.hashPubKey); |
518 | } | 497 | } |
@@ -526,16 +505,14 @@ setup_filter (struct Peer *peer) | |||
526 | * @param buf where the callee should write the message | 505 | * @param buf where the callee should write the message |
527 | * @return number of bytes written to buf | 506 | * @return number of bytes written to buf |
528 | */ | 507 | */ |
529 | static size_t | 508 | static size_t hello_advertising_ready (void *cls, size_t size, void *buf); |
530 | hello_advertising_ready (void *cls, | ||
531 | size_t size, | ||
532 | void *buf); | ||
533 | 509 | ||
534 | 510 | ||
535 | /** | 511 | /** |
536 | * Closure for 'find_advertisable_hello'. | 512 | * Closure for 'find_advertisable_hello'. |
537 | */ | 513 | */ |
538 | struct FindAdvHelloContext { | 514 | struct FindAdvHelloContext |
515 | { | ||
539 | 516 | ||
540 | /** | 517 | /** |
541 | * Peer we want to advertise to. | 518 | * Peer we want to advertise to. |
@@ -565,9 +542,7 @@ struct FindAdvHelloContext { | |||
565 | * @return GNUNET_YES (continue iteration) | 542 | * @return GNUNET_YES (continue iteration) |
566 | */ | 543 | */ |
567 | static int | 544 | static int |
568 | find_advertisable_hello (void *cls, | 545 | find_advertisable_hello (void *cls, const GNUNET_HashCode * pid, void *value) |
569 | const GNUNET_HashCode *pid, | ||
570 | void *value) | ||
571 | { | 546 | { |
572 | struct FindAdvHelloContext *fah = cls; | 547 | struct FindAdvHelloContext *fah = cls; |
573 | struct Peer *pos = value; | 548 | struct Peer *pos = value; |
@@ -580,20 +555,19 @@ find_advertisable_hello (void *cls, | |||
580 | return GNUNET_YES; | 555 | return GNUNET_YES; |
581 | rst_time = GNUNET_TIME_absolute_get_remaining (pos->filter_expiration); | 556 | rst_time = GNUNET_TIME_absolute_get_remaining (pos->filter_expiration); |
582 | if (0 == rst_time.rel_value) | 557 | if (0 == rst_time.rel_value) |
583 | { | 558 | { |
584 | /* time to discard... */ | 559 | /* time to discard... */ |
585 | GNUNET_CONTAINER_bloomfilter_free (pos->filter); | 560 | GNUNET_CONTAINER_bloomfilter_free (pos->filter); |
586 | setup_filter (pos); | 561 | setup_filter (pos); |
587 | } | 562 | } |
588 | fah->next_adv = GNUNET_TIME_relative_min (rst_time, | 563 | fah->next_adv = GNUNET_TIME_relative_min (rst_time, fah->next_adv); |
589 | fah->next_adv); | ||
590 | hs = GNUNET_HELLO_size (pos->hello); | 564 | hs = GNUNET_HELLO_size (pos->hello); |
591 | if (hs > fah->max_size) | 565 | if (hs > fah->max_size) |
592 | return GNUNET_YES; | 566 | return GNUNET_YES; |
593 | if (GNUNET_NO == | 567 | if (GNUNET_NO == |
594 | GNUNET_CONTAINER_bloomfilter_test (pos->filter, | 568 | GNUNET_CONTAINER_bloomfilter_test (pos->filter, |
595 | &fah->peer->pid.hashPubKey)) | 569 | &fah->peer->pid.hashPubKey)) |
596 | fah->result = pos; | 570 | fah->result = pos; |
597 | return GNUNET_YES; | 571 | return GNUNET_YES; |
598 | } | 572 | } |
599 | 573 | ||
@@ -606,48 +580,43 @@ find_advertisable_hello (void *cls, | |||
606 | * @param tc task context | 580 | * @param tc task context |
607 | */ | 581 | */ |
608 | static void | 582 | static void |
609 | schedule_next_hello (void *cls, | 583 | schedule_next_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
610 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
611 | { | 584 | { |
612 | struct Peer *pl = cls; | 585 | struct Peer *pl = cls; |
613 | struct FindAdvHelloContext fah; | 586 | struct FindAdvHelloContext fah; |
614 | size_t next_want; | 587 | size_t next_want; |
615 | struct GNUNET_TIME_Relative delay; | 588 | struct GNUNET_TIME_Relative delay; |
616 | 589 | ||
617 | pl->hello_delay_task = GNUNET_SCHEDULER_NO_TASK; | 590 | pl->hello_delay_task = GNUNET_SCHEDULER_NO_TASK; |
618 | GNUNET_assert (GNUNET_YES == pl->is_connected); | 591 | GNUNET_assert (GNUNET_YES == pl->is_connected); |
619 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 592 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
620 | return; /* we're out of here */ | 593 | return; /* we're out of here */ |
621 | if (pl->hello_req != NULL) | 594 | if (pl->hello_req != NULL) |
622 | return; /* did not finish sending the previous one */ | 595 | return; /* did not finish sending the previous one */ |
623 | /* find applicable HELLOs */ | 596 | /* find applicable HELLOs */ |
624 | fah.peer = pl; | 597 | fah.peer = pl; |
625 | fah.result = NULL; | 598 | fah.result = NULL; |
626 | fah.max_size = GNUNET_SERVER_MAX_MESSAGE_SIZE - 1; | 599 | fah.max_size = GNUNET_SERVER_MAX_MESSAGE_SIZE - 1; |
627 | fah.next_adv = GNUNET_TIME_UNIT_FOREVER_REL; | 600 | fah.next_adv = GNUNET_TIME_UNIT_FOREVER_REL; |
628 | GNUNET_CONTAINER_multihashmap_iterate (peers, | 601 | GNUNET_CONTAINER_multihashmap_iterate (peers, &find_advertisable_hello, &fah); |
629 | &find_advertisable_hello, | 602 | pl->hello_delay_task |
630 | &fah); | 603 | = GNUNET_SCHEDULER_add_delayed (fah.next_adv, &schedule_next_hello, pl); |
631 | pl->hello_delay_task | ||
632 | = GNUNET_SCHEDULER_add_delayed (fah.next_adv, | ||
633 | &schedule_next_hello, | ||
634 | pl); | ||
635 | if (fah.result == NULL) | 604 | if (fah.result == NULL) |
636 | return; | 605 | return; |
637 | next_want = GNUNET_HELLO_size (fah.result->hello); | 606 | next_want = GNUNET_HELLO_size (fah.result->hello); |
638 | delay = GNUNET_TIME_absolute_get_remaining (pl->next_hello_allowed); | 607 | delay = GNUNET_TIME_absolute_get_remaining (pl->next_hello_allowed); |
639 | if (delay.rel_value == 0) | 608 | if (delay.rel_value == 0) |
640 | { | 609 | { |
641 | /* now! */ | 610 | /* now! */ |
642 | pl->hello_req = GNUNET_CORE_notify_transmit_ready (handle, | 611 | pl->hello_req = GNUNET_CORE_notify_transmit_ready (handle, |
643 | GNUNET_YES, | 612 | GNUNET_YES, |
644 | 0, | 613 | 0, |
645 | GNUNET_CONSTANTS_SERVICE_TIMEOUT, | 614 | GNUNET_CONSTANTS_SERVICE_TIMEOUT, |
646 | &pl->pid, | 615 | &pl->pid, |
647 | next_want, | 616 | next_want, |
648 | &hello_advertising_ready, | 617 | &hello_advertising_ready, |
649 | pl); | 618 | pl); |
650 | } | 619 | } |
651 | } | 620 | } |
652 | 621 | ||
653 | 622 | ||
@@ -662,30 +631,27 @@ schedule_next_hello (void *cls, | |||
662 | * @return GNUNET_YES (always) | 631 | * @return GNUNET_YES (always) |
663 | */ | 632 | */ |
664 | static int | 633 | static int |
665 | reschedule_hellos (void *cls, | 634 | reschedule_hellos (void *cls, const GNUNET_HashCode * pid, void *value) |
666 | const GNUNET_HashCode *pid, | ||
667 | void *value) | ||
668 | { | 635 | { |
669 | struct Peer *peer = value; | 636 | struct Peer *peer = value; |
670 | struct Peer *skip = cls; | 637 | struct Peer *skip = cls; |
671 | 638 | ||
672 | if (skip == peer) | 639 | if (skip == peer) |
673 | return GNUNET_YES; | 640 | return GNUNET_YES; |
674 | if (! peer->is_connected) | 641 | if (!peer->is_connected) |
675 | return GNUNET_YES; | 642 | return GNUNET_YES; |
676 | if (peer->hello_req != NULL) | 643 | if (peer->hello_req != NULL) |
677 | { | 644 | { |
678 | GNUNET_CORE_notify_transmit_ready_cancel (peer->hello_req); | 645 | GNUNET_CORE_notify_transmit_ready_cancel (peer->hello_req); |
679 | peer->hello_req = NULL; | 646 | peer->hello_req = NULL; |
680 | } | 647 | } |
681 | if (peer->hello_delay_task != GNUNET_SCHEDULER_NO_TASK) | 648 | if (peer->hello_delay_task != GNUNET_SCHEDULER_NO_TASK) |
682 | { | 649 | { |
683 | GNUNET_SCHEDULER_cancel (peer->hello_delay_task); | 650 | GNUNET_SCHEDULER_cancel (peer->hello_delay_task); |
684 | peer->hello_delay_task = GNUNET_SCHEDULER_NO_TASK; | 651 | peer->hello_delay_task = GNUNET_SCHEDULER_NO_TASK; |
685 | } | 652 | } |
686 | peer->hello_delay_task | 653 | peer->hello_delay_task |
687 | = GNUNET_SCHEDULER_add_now (&schedule_next_hello, | 654 | = GNUNET_SCHEDULER_add_now (&schedule_next_hello, peer); |
688 | peer); | ||
689 | return GNUNET_YES; | 655 | return GNUNET_YES; |
690 | } | 656 | } |
691 | 657 | ||
@@ -697,51 +663,49 @@ reschedule_hellos (void *cls, | |||
697 | * @param peer peer identity this notification is about | 663 | * @param peer peer identity this notification is about |
698 | * @param atsi performance data | 664 | * @param atsi performance data |
699 | */ | 665 | */ |
700 | static void | 666 | static void |
701 | connect_notify (void *cls, | 667 | connect_notify (void *cls, |
702 | const struct | 668 | const struct |
703 | GNUNET_PeerIdentity * peer, | 669 | GNUNET_PeerIdentity *peer, |
704 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 670 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
705 | { | 671 | { |
706 | struct Peer *pos; | 672 | struct Peer *pos; |
707 | 673 | ||
708 | #if DEBUG_TOPOLOGY | 674 | #if DEBUG_TOPOLOGY |
709 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 675 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
710 | "Core told us that we are connecting to `%s'\n", | 676 | "Core told us that we are connecting to `%s'\n", |
711 | GNUNET_i2s (peer)); | 677 | GNUNET_i2s (peer)); |
712 | #endif | 678 | #endif |
713 | if (0 == memcmp(&my_identity, peer, sizeof(struct GNUNET_PeerIdentity))) | 679 | if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) |
714 | return; | 680 | return; |
715 | 681 | ||
716 | connection_count++; | 682 | connection_count++; |
717 | GNUNET_STATISTICS_set (stats, | 683 | GNUNET_STATISTICS_set (stats, |
718 | gettext_noop ("# peers connected"), | 684 | gettext_noop ("# peers connected"), |
719 | connection_count, | 685 | connection_count, GNUNET_NO); |
720 | GNUNET_NO); | ||
721 | pos = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey); | 686 | pos = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey); |
722 | if (pos == NULL) | 687 | if (pos == NULL) |
723 | { | 688 | { |
724 | pos = make_peer (peer, NULL, GNUNET_NO); | 689 | pos = make_peer (peer, NULL, GNUNET_NO); |
725 | GNUNET_break (GNUNET_OK == is_connection_allowed (pos)); | 690 | GNUNET_break (GNUNET_OK == is_connection_allowed (pos)); |
726 | } | 691 | } |
727 | else | 692 | else |
728 | { | 693 | { |
729 | GNUNET_assert (GNUNET_NO == pos->is_connected); | 694 | GNUNET_assert (GNUNET_NO == pos->is_connected); |
730 | pos->greylisted_until.abs_value = 0; /* remove greylisting */ | 695 | pos->greylisted_until.abs_value = 0; /* remove greylisting */ |
731 | } | 696 | } |
732 | pos->is_connected = GNUNET_YES; | 697 | pos->is_connected = GNUNET_YES; |
733 | pos->connect_attempts = 0; /* re-set back-off factor */ | 698 | pos->connect_attempts = 0; /* re-set back-off factor */ |
734 | if (pos->is_friend) | 699 | if (pos->is_friend) |
735 | { | 700 | { |
736 | if ( (friend_count == minimum_friend_count - 1) && | 701 | if ((friend_count == minimum_friend_count - 1) && |
737 | (GNUNET_YES != friends_only) ) | 702 | (GNUNET_YES != friends_only)) |
738 | whitelist_peers (); | 703 | whitelist_peers (); |
739 | friend_count++; | 704 | friend_count++; |
740 | GNUNET_STATISTICS_set (stats, | 705 | GNUNET_STATISTICS_set (stats, |
741 | gettext_noop ("# friends connected"), | 706 | gettext_noop ("# friends connected"), |
742 | friend_count, | 707 | friend_count, GNUNET_NO); |
743 | GNUNET_NO); | 708 | } |
744 | } | ||
745 | reschedule_hellos (NULL, &peer->hashPubKey, pos); | 709 | reschedule_hellos (NULL, &peer->hashPubKey, pos); |
746 | } | 710 | } |
747 | 711 | ||
@@ -755,9 +719,7 @@ connect_notify (void *cls, | |||
755 | * @return GNUNET_YES (continue to iterate) | 719 | * @return GNUNET_YES (continue to iterate) |
756 | */ | 720 | */ |
757 | static int | 721 | static int |
758 | try_add_peers (void *cls, | 722 | try_add_peers (void *cls, const GNUNET_HashCode * pid, void *value) |
759 | const GNUNET_HashCode *pid, | ||
760 | void *value) | ||
761 | { | 723 | { |
762 | struct Peer *pos = value; | 724 | struct Peer *pos = value; |
763 | 725 | ||
@@ -774,14 +736,11 @@ try_add_peers (void *cls, | |||
774 | * @param tc scheduler context | 736 | * @param tc scheduler context |
775 | */ | 737 | */ |
776 | static void | 738 | static void |
777 | add_peer_task (void *cls, | 739 | add_peer_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
778 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
779 | { | 740 | { |
780 | add_task = GNUNET_SCHEDULER_NO_TASK; | 741 | add_task = GNUNET_SCHEDULER_NO_TASK; |
781 | 742 | ||
782 | GNUNET_CONTAINER_multihashmap_iterate (peers, | 743 | GNUNET_CONTAINER_multihashmap_iterate (peers, &try_add_peers, NULL); |
783 | &try_add_peers, | ||
784 | NULL); | ||
785 | } | 744 | } |
786 | 745 | ||
787 | /** | 746 | /** |
@@ -790,64 +749,57 @@ add_peer_task (void *cls, | |||
790 | * @param cls closure | 749 | * @param cls closure |
791 | * @param peer peer identity this notification is about | 750 | * @param peer peer identity this notification is about |
792 | */ | 751 | */ |
793 | static void | 752 | static void |
794 | disconnect_notify (void *cls, | 753 | disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer) |
795 | const struct | ||
796 | GNUNET_PeerIdentity * peer) | ||
797 | { | 754 | { |
798 | struct Peer *pos; | 755 | struct Peer *pos; |
799 | 756 | ||
800 | if (0 == memcmp(&my_identity, peer, sizeof(struct GNUNET_PeerIdentity))) | 757 | if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) |
801 | return; | 758 | return; |
802 | #if DEBUG_TOPOLOGY | 759 | #if DEBUG_TOPOLOGY |
803 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 760 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
804 | "Core told us that we disconnected from `%s'\n", | 761 | "Core told us that we disconnected from `%s'\n", |
805 | GNUNET_i2s (peer)); | 762 | GNUNET_i2s (peer)); |
806 | #endif | 763 | #endif |
807 | pos = GNUNET_CONTAINER_multihashmap_get (peers, | 764 | pos = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey); |
808 | &peer->hashPubKey); | ||
809 | if (pos == NULL) | 765 | if (pos == NULL) |
810 | { | 766 | { |
811 | GNUNET_break (0); | 767 | GNUNET_break (0); |
812 | return; | 768 | return; |
813 | } | 769 | } |
814 | if (pos->is_connected != GNUNET_YES) | 770 | if (pos->is_connected != GNUNET_YES) |
815 | { | 771 | { |
816 | GNUNET_break (0); | 772 | GNUNET_break (0); |
817 | return; | 773 | return; |
818 | } | 774 | } |
819 | pos->is_connected = GNUNET_NO; | 775 | pos->is_connected = GNUNET_NO; |
820 | connection_count--; | 776 | connection_count--; |
821 | if (NULL != pos->hello_req) | 777 | if (NULL != pos->hello_req) |
822 | { | 778 | { |
823 | GNUNET_CORE_notify_transmit_ready_cancel (pos->hello_req); | 779 | GNUNET_CORE_notify_transmit_ready_cancel (pos->hello_req); |
824 | pos->hello_req = NULL; | 780 | pos->hello_req = NULL; |
825 | } | 781 | } |
826 | if (GNUNET_SCHEDULER_NO_TASK != pos->hello_delay_task) | 782 | if (GNUNET_SCHEDULER_NO_TASK != pos->hello_delay_task) |
827 | { | 783 | { |
828 | GNUNET_SCHEDULER_cancel (pos->hello_delay_task); | 784 | GNUNET_SCHEDULER_cancel (pos->hello_delay_task); |
829 | pos->hello_delay_task = GNUNET_SCHEDULER_NO_TASK; | 785 | pos->hello_delay_task = GNUNET_SCHEDULER_NO_TASK; |
830 | } | 786 | } |
831 | GNUNET_STATISTICS_set (stats, | 787 | GNUNET_STATISTICS_set (stats, |
832 | gettext_noop ("# peers connected"), | 788 | gettext_noop ("# peers connected"), |
833 | connection_count, | 789 | connection_count, GNUNET_NO); |
834 | GNUNET_NO); | ||
835 | if (pos->is_friend) | 790 | if (pos->is_friend) |
836 | { | 791 | { |
837 | friend_count--; | 792 | friend_count--; |
838 | GNUNET_STATISTICS_set (stats, | 793 | GNUNET_STATISTICS_set (stats, |
839 | gettext_noop ("# friends connected"), | 794 | gettext_noop ("# friends connected"), |
840 | friend_count, | 795 | friend_count, GNUNET_NO); |
841 | GNUNET_NO); | 796 | } |
842 | } | 797 | if (((connection_count < target_connection_count) || |
843 | if ( ( (connection_count < target_connection_count) || | 798 | (friend_count < minimum_friend_count)) && |
844 | (friend_count < minimum_friend_count) ) && | 799 | (GNUNET_SCHEDULER_NO_TASK == add_task)) |
845 | (GNUNET_SCHEDULER_NO_TASK == add_task) ) | ||
846 | add_task = GNUNET_SCHEDULER_add_now (&add_peer_task, NULL); | 800 | add_task = GNUNET_SCHEDULER_add_now (&add_peer_task, NULL); |
847 | if ( (friend_count < minimum_friend_count) && | 801 | if ((friend_count < minimum_friend_count) && (blacklist == NULL)) |
848 | (blacklist == NULL) ) | 802 | blacklist = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_check, NULL); |
849 | blacklist = GNUNET_TRANSPORT_blacklist (cfg, | ||
850 | &blacklist_check, NULL); | ||
851 | } | 803 | } |
852 | 804 | ||
853 | 805 | ||
@@ -863,12 +815,12 @@ disconnect_notify (void *cls, | |||
863 | */ | 815 | */ |
864 | static int | 816 | static int |
865 | address_iterator (void *cls, | 817 | address_iterator (void *cls, |
866 | const char *tname, | 818 | const char *tname, |
867 | struct GNUNET_TIME_Absolute expiration, | 819 | struct GNUNET_TIME_Absolute expiration, |
868 | const void *addr, | 820 | const void *addr, uint16_t addrlen) |
869 | uint16_t addrlen) | ||
870 | { | 821 | { |
871 | int *flag = cls; | 822 | int *flag = cls; |
823 | |||
872 | *flag = GNUNET_YES; | 824 | *flag = GNUNET_YES; |
873 | return GNUNET_SYSERR; | 825 | return GNUNET_SYSERR; |
874 | } | 826 | } |
@@ -891,62 +843,51 @@ consider_for_advertising (const struct GNUNET_HELLO_Message *hello) | |||
891 | uint16_t size; | 843 | uint16_t size; |
892 | 844 | ||
893 | if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid)) | 845 | if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid)) |
894 | { | 846 | { |
895 | GNUNET_break (0); | 847 | GNUNET_break (0); |
896 | return; | 848 | return; |
897 | } | 849 | } |
898 | if (0 == memcmp (&pid, | 850 | if (0 == memcmp (&pid, &my_identity, sizeof (struct GNUNET_PeerIdentity))) |
899 | &my_identity, | 851 | return; /* that's me! */ |
900 | sizeof (struct GNUNET_PeerIdentity))) | ||
901 | return; /* that's me! */ | ||
902 | have_address = GNUNET_NO; | 852 | have_address = GNUNET_NO; |
903 | GNUNET_HELLO_iterate_addresses (hello, | 853 | GNUNET_HELLO_iterate_addresses (hello, |
904 | GNUNET_NO, | 854 | GNUNET_NO, &address_iterator, &have_address); |
905 | &address_iterator, | ||
906 | &have_address); | ||
907 | if (GNUNET_NO == have_address) | 855 | if (GNUNET_NO == have_address) |
908 | return; /* no point in advertising this one... */ | 856 | return; /* no point in advertising this one... */ |
909 | peer = GNUNET_CONTAINER_multihashmap_get (peers, | 857 | peer = GNUNET_CONTAINER_multihashmap_get (peers, &pid.hashPubKey); |
910 | &pid.hashPubKey); | ||
911 | if (peer == NULL) | 858 | if (peer == NULL) |
912 | { | 859 | { |
913 | peer = make_peer (&pid, hello, GNUNET_NO); | 860 | peer = make_peer (&pid, hello, GNUNET_NO); |
914 | } | 861 | } |
915 | else if (peer->hello != NULL) | 862 | else if (peer->hello != NULL) |
916 | { | 863 | { |
917 | dt = GNUNET_HELLO_equals (peer->hello, | 864 | dt = GNUNET_HELLO_equals (peer->hello, hello, GNUNET_TIME_absolute_get ()); |
918 | hello, | 865 | if (dt.abs_value == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value) |
919 | GNUNET_TIME_absolute_get()); | 866 | return; /* nothing new here */ |
920 | if (dt.abs_value == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value) | 867 | } |
921 | return; /* nothing new here */ | ||
922 | } | ||
923 | #if DEBUG_TOPOLOGY | 868 | #if DEBUG_TOPOLOGY |
924 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 869 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
925 | "Found `%s' from peer `%s' for advertising\n", | 870 | "Found `%s' from peer `%s' for advertising\n", |
926 | "HELLO", | 871 | "HELLO", GNUNET_i2s (&pid)); |
927 | GNUNET_i2s (&pid)); | 872 | #endif |
928 | #endif | ||
929 | if (peer->hello != NULL) | 873 | if (peer->hello != NULL) |
930 | { | 874 | { |
931 | nh = GNUNET_HELLO_merge (peer->hello, | 875 | nh = GNUNET_HELLO_merge (peer->hello, hello); |
932 | hello); | 876 | GNUNET_free (peer->hello); |
933 | GNUNET_free (peer->hello); | 877 | peer->hello = nh; |
934 | peer->hello = nh; | 878 | } |
935 | } | ||
936 | else | 879 | else |
937 | { | 880 | { |
938 | size = GNUNET_HELLO_size (hello); | 881 | size = GNUNET_HELLO_size (hello); |
939 | peer->hello = GNUNET_malloc (size); | 882 | peer->hello = GNUNET_malloc (size); |
940 | memcpy (peer->hello, hello, size); | 883 | memcpy (peer->hello, hello, size); |
941 | } | 884 | } |
942 | if (peer->filter != NULL) | 885 | if (peer->filter != NULL) |
943 | GNUNET_CONTAINER_bloomfilter_free (peer->filter); | 886 | GNUNET_CONTAINER_bloomfilter_free (peer->filter); |
944 | setup_filter (peer); | 887 | setup_filter (peer); |
945 | /* since we have a new HELLO to pick from, re-schedule all | 888 | /* since we have a new HELLO to pick from, re-schedule all |
946 | HELLO requests that are not bound by the HELLO send rate! */ | 889 | * HELLO requests that are not bound by the HELLO send rate! */ |
947 | GNUNET_CONTAINER_multihashmap_iterate (peers, | 890 | GNUNET_CONTAINER_multihashmap_iterate (peers, &reschedule_hellos, peer); |
948 | &reschedule_hellos, | ||
949 | peer); | ||
950 | } | 891 | } |
951 | 892 | ||
952 | 893 | ||
@@ -961,76 +902,70 @@ consider_for_advertising (const struct GNUNET_HELLO_Message *hello) | |||
961 | */ | 902 | */ |
962 | static void | 903 | static void |
963 | process_peer (void *cls, | 904 | process_peer (void *cls, |
964 | const struct GNUNET_PeerIdentity *peer, | 905 | const struct GNUNET_PeerIdentity *peer, |
965 | const struct GNUNET_HELLO_Message *hello, | 906 | const struct GNUNET_HELLO_Message *hello, const char *err_msg) |
966 | const char *err_msg) | ||
967 | { | 907 | { |
968 | struct Peer *pos; | 908 | struct Peer *pos; |
969 | 909 | ||
970 | if (err_msg != NULL) | 910 | if (err_msg != NULL) |
971 | { | 911 | { |
972 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 912 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
973 | _("Error in communication with PEERINFO service: %s\n"), | 913 | _("Error in communication with PEERINFO service: %s\n"), |
974 | err_msg); | 914 | err_msg); |
975 | GNUNET_PEERINFO_notify_cancel (peerinfo_notify); | 915 | GNUNET_PEERINFO_notify_cancel (peerinfo_notify); |
976 | peerinfo_notify = GNUNET_PEERINFO_notify (cfg, &process_peer, | 916 | peerinfo_notify = GNUNET_PEERINFO_notify (cfg, &process_peer, NULL); |
977 | NULL); | 917 | return; |
978 | return; | 918 | } |
979 | } | ||
980 | GNUNET_assert (peer != NULL); | 919 | GNUNET_assert (peer != NULL); |
981 | if (0 == memcmp (&my_identity, | 920 | if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) |
982 | peer, sizeof (struct GNUNET_PeerIdentity))) | 921 | return; /* that's me! */ |
983 | return; /* that's me! */ | ||
984 | if (hello == NULL) | 922 | if (hello == NULL) |
923 | { | ||
924 | /* free existing HELLO, if any */ | ||
925 | pos = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey); | ||
926 | if (NULL != pos) | ||
985 | { | 927 | { |
986 | /* free existing HELLO, if any */ | 928 | GNUNET_free_non_null (pos->hello); |
987 | pos = GNUNET_CONTAINER_multihashmap_get (peers, | 929 | pos->hello = NULL; |
988 | &peer->hashPubKey); | 930 | if (pos->filter != NULL) |
989 | if (NULL != pos) | 931 | { |
990 | { | 932 | GNUNET_CONTAINER_bloomfilter_free (pos->filter); |
991 | GNUNET_free_non_null (pos->hello); | 933 | pos->filter = NULL; |
992 | pos->hello = NULL; | 934 | } |
993 | if (pos->filter != NULL) | 935 | if ((!pos->is_connected) && |
994 | { | 936 | (!pos->is_friend) && |
995 | GNUNET_CONTAINER_bloomfilter_free (pos->filter); | 937 | (0 == |
996 | pos->filter = NULL; | 938 | GNUNET_TIME_absolute_get_remaining (pos-> |
997 | } | 939 | greylisted_until).rel_value)) |
998 | if ( (! pos->is_connected) && | 940 | free_peer (NULL, &pos->pid.hashPubKey, pos); |
999 | (! pos->is_friend) && | ||
1000 | (0 == GNUNET_TIME_absolute_get_remaining (pos->greylisted_until).rel_value) ) | ||
1001 | free_peer (NULL, &pos->pid.hashPubKey, pos); | ||
1002 | } | ||
1003 | return; | ||
1004 | } | 941 | } |
942 | return; | ||
943 | } | ||
1005 | consider_for_advertising (hello); | 944 | consider_for_advertising (hello); |
1006 | pos = GNUNET_CONTAINER_multihashmap_get (peers, | 945 | pos = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey); |
1007 | &peer->hashPubKey); | ||
1008 | if (pos == NULL) | 946 | if (pos == NULL) |
1009 | pos = make_peer (peer, hello, GNUNET_NO); | 947 | pos = make_peer (peer, hello, GNUNET_NO); |
1010 | GNUNET_assert (NULL != pos); | 948 | GNUNET_assert (NULL != pos); |
1011 | if (GNUNET_YES == pos->is_connected) | 949 | if (GNUNET_YES == pos->is_connected) |
1012 | { | 950 | { |
1013 | #if DEBUG_TOPOLOGY | 951 | #if DEBUG_TOPOLOGY |
1014 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 952 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1015 | "Already connected to peer `%s'\n", | 953 | "Already connected to peer `%s'\n", GNUNET_i2s (peer)); |
1016 | GNUNET_i2s (peer)); | 954 | #endif |
1017 | #endif | 955 | return; |
1018 | return; | 956 | } |
1019 | } | ||
1020 | if (GNUNET_TIME_absolute_get_remaining (pos->greylisted_until).rel_value > 0) | 957 | if (GNUNET_TIME_absolute_get_remaining (pos->greylisted_until).rel_value > 0) |
1021 | { | 958 | { |
1022 | #if DEBUG_TOPOLOGY | 959 | #if DEBUG_TOPOLOGY |
1023 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 960 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1024 | "Already tried peer `%s' recently\n", | 961 | "Already tried peer `%s' recently\n", GNUNET_i2s (peer)); |
1025 | GNUNET_i2s (peer)); | 962 | #endif |
1026 | #endif | 963 | return; /* peer still greylisted */ |
1027 | return; /* peer still greylisted */ | 964 | } |
1028 | } | ||
1029 | #if DEBUG_TOPOLOGY | 965 | #if DEBUG_TOPOLOGY |
1030 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 966 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1031 | "Considering connecting to peer `%s'\n", | 967 | "Considering connecting to peer `%s'\n", GNUNET_i2s (peer)); |
1032 | GNUNET_i2s (peer)); | 968 | #endif |
1033 | #endif | ||
1034 | attempt_connect (pos); | 969 | attempt_connect (pos); |
1035 | } | 970 | } |
1036 | 971 | ||
@@ -1046,29 +981,24 @@ process_peer (void *cls, | |||
1046 | */ | 981 | */ |
1047 | static void | 982 | static void |
1048 | core_init (void *cls, | 983 | core_init (void *cls, |
1049 | struct GNUNET_CORE_Handle * server, | 984 | struct GNUNET_CORE_Handle *server, |
1050 | const struct GNUNET_PeerIdentity * | 985 | const struct GNUNET_PeerIdentity *my_id, |
1051 | my_id, | 986 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) |
1052 | const struct | ||
1053 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded * | ||
1054 | publicKey) | ||
1055 | { | 987 | { |
1056 | if (server == NULL) | 988 | if (server == NULL) |
1057 | { | 989 | { |
1058 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 990 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1059 | _("Failed to connect to core service, can not manage topology!\n")); | 991 | _ |
1060 | GNUNET_SCHEDULER_shutdown (); | 992 | ("Failed to connect to core service, can not manage topology!\n")); |
1061 | return; | 993 | GNUNET_SCHEDULER_shutdown (); |
1062 | } | 994 | return; |
995 | } | ||
1063 | handle = server; | 996 | handle = server; |
1064 | my_identity = *my_id; | 997 | my_identity = *my_id; |
1065 | #if DEBUG_TOPOLOGY | 998 | #if DEBUG_TOPOLOGY |
1066 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 999 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "I am peer `%s'\n", GNUNET_i2s (my_id)); |
1067 | "I am peer `%s'\n", | 1000 | #endif |
1068 | GNUNET_i2s (my_id)); | 1001 | peerinfo_notify = GNUNET_PEERINFO_notify (cfg, &process_peer, NULL); |
1069 | #endif | ||
1070 | peerinfo_notify = GNUNET_PEERINFO_notify (cfg, &process_peer, | ||
1071 | NULL); | ||
1072 | } | 1002 | } |
1073 | 1003 | ||
1074 | 1004 | ||
@@ -1088,123 +1018,119 @@ read_friends_file (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
1088 | struct Peer *fl; | 1018 | struct Peer *fl; |
1089 | 1019 | ||
1090 | if (GNUNET_OK != | 1020 | if (GNUNET_OK != |
1091 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 1021 | GNUNET_CONFIGURATION_get_value_filename (cfg, "TOPOLOGY", "FRIENDS", &fn)) |
1092 | "TOPOLOGY", | 1022 | { |
1093 | "FRIENDS", | 1023 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1094 | &fn)) | 1024 | _("Option `%s' in section `%s' not specified!\n"), |
1095 | { | 1025 | "FRIENDS", "TOPOLOGY"); |
1096 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1026 | return; |
1097 | _("Option `%s' in section `%s' not specified!\n"), | 1027 | } |
1098 | "FRIENDS", | ||
1099 | "TOPOLOGY"); | ||
1100 | return; | ||
1101 | } | ||
1102 | if (GNUNET_OK != GNUNET_DISK_file_test (fn)) | 1028 | if (GNUNET_OK != GNUNET_DISK_file_test (fn)) |
1103 | GNUNET_DISK_fn_write (fn, NULL, 0, | 1029 | GNUNET_DISK_fn_write (fn, NULL, 0, |
1104 | GNUNET_DISK_PERM_USER_READ | 1030 | GNUNET_DISK_PERM_USER_READ |
1105 | | GNUNET_DISK_PERM_USER_WRITE); | 1031 | | GNUNET_DISK_PERM_USER_WRITE); |
1106 | if (0 != STAT (fn, &frstat)) | 1032 | if (0 != STAT (fn, &frstat)) |
1107 | { | 1033 | { |
1108 | if ((friends_only) || (minimum_friend_count > 0)) | 1034 | if ((friends_only) || (minimum_friend_count > 0)) |
1109 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1035 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1110 | _("Could not read friends list `%s'\n"), fn); | 1036 | _("Could not read friends list `%s'\n"), fn); |
1111 | GNUNET_free (fn); | 1037 | GNUNET_free (fn); |
1112 | return; | 1038 | return; |
1113 | } | 1039 | } |
1114 | if (frstat.st_size == 0) | 1040 | if (frstat.st_size == 0) |
1115 | { | 1041 | { |
1116 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1042 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1117 | _("Friends file `%s' is empty.\n"), | 1043 | _("Friends file `%s' is empty.\n"), fn); |
1118 | fn); | 1044 | GNUNET_free (fn); |
1119 | GNUNET_free (fn); | 1045 | return; |
1120 | return; | 1046 | } |
1121 | } | ||
1122 | data = GNUNET_malloc_large (frstat.st_size); | 1047 | data = GNUNET_malloc_large (frstat.st_size); |
1123 | if (data == NULL) | 1048 | if (data == NULL) |
1124 | { | 1049 | { |
1125 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1050 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1126 | _("Failed to read friends list from `%s': out of memory\n"), fn); | 1051 | _("Failed to read friends list from `%s': out of memory\n"), |
1127 | GNUNET_free (fn); | 1052 | fn); |
1128 | return; | 1053 | GNUNET_free (fn); |
1129 | } | 1054 | return; |
1130 | if (frstat.st_size != | 1055 | } |
1131 | GNUNET_DISK_fn_read (fn, data, frstat.st_size)) | 1056 | if (frstat.st_size != GNUNET_DISK_fn_read (fn, data, frstat.st_size)) |
1132 | { | 1057 | { |
1133 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1058 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1134 | _("Failed to read friends list from `%s'\n"), fn); | 1059 | _("Failed to read friends list from `%s'\n"), fn); |
1135 | GNUNET_free (fn); | 1060 | GNUNET_free (fn); |
1136 | GNUNET_free (data); | 1061 | GNUNET_free (data); |
1137 | return; | 1062 | return; |
1138 | } | 1063 | } |
1139 | entries_found = 0; | 1064 | entries_found = 0; |
1140 | pos = 0; | 1065 | pos = 0; |
1141 | while ((pos < frstat.st_size) && isspace ( (unsigned char) data[pos])) | 1066 | while ((pos < frstat.st_size) && isspace ((unsigned char) data[pos])) |
1142 | pos++; | 1067 | pos++; |
1143 | while ((frstat.st_size >= sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) && | 1068 | while ((frstat.st_size >= sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) && |
1144 | (pos <= frstat.st_size - sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded))) | 1069 | (pos <= |
1070 | frstat.st_size - sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded))) | ||
1071 | { | ||
1072 | memcpy (&enc, &data[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); | ||
1073 | if (!isspace | ||
1074 | ((unsigned char) | ||
1075 | enc.encoding[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1])) | ||
1145 | { | 1076 | { |
1146 | memcpy (&enc, &data[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); | 1077 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1147 | if (!isspace ( (unsigned char) enc.encoding[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1])) | 1078 | _ |
1148 | { | 1079 | ("Syntax error in topology specification at offset %llu, skipping bytes.\n"), |
1149 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1080 | (unsigned long long) pos); |
1150 | _("Syntax error in topology specification at offset %llu, skipping bytes.\n"), | 1081 | pos++; |
1151 | (unsigned long long) pos); | 1082 | while ((pos < frstat.st_size) && (!isspace ((unsigned char) data[pos]))) |
1152 | pos++; | 1083 | pos++; |
1153 | while ((pos < frstat.st_size) && (!isspace ( (unsigned char) data[pos]))) | 1084 | continue; |
1154 | pos++; | ||
1155 | continue; | ||
1156 | } | ||
1157 | enc.encoding[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; | ||
1158 | if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char *) &enc, &pid.hashPubKey)) | ||
1159 | { | ||
1160 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1161 | _("Syntax error in topology specification at offset %llu, skipping bytes `%s'.\n"), | ||
1162 | (unsigned long long) pos, | ||
1163 | &enc); | ||
1164 | } | ||
1165 | else | ||
1166 | { | ||
1167 | if (0 != memcmp (&pid, | ||
1168 | &my_identity, | ||
1169 | sizeof (struct GNUNET_PeerIdentity))) | ||
1170 | { | ||
1171 | entries_found++; | ||
1172 | fl = make_peer (&pid, | ||
1173 | NULL, | ||
1174 | GNUNET_YES); | ||
1175 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1176 | _("Found friend `%s' in configuration\n"), | ||
1177 | GNUNET_i2s (&fl->pid)); | ||
1178 | } | ||
1179 | else | ||
1180 | { | ||
1181 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1182 | _("Found myself `%s' in friend list (useless, ignored)\n"), | ||
1183 | GNUNET_i2s (&pid)); | ||
1184 | } | ||
1185 | } | ||
1186 | pos = pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded); | ||
1187 | while ((pos < frstat.st_size) && isspace ( (unsigned char) data[pos])) | ||
1188 | pos++; | ||
1189 | } | 1085 | } |
1190 | GNUNET_free (data); | 1086 | enc.encoding[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; |
1191 | GNUNET_free (fn); | 1087 | if (GNUNET_OK != |
1192 | GNUNET_STATISTICS_update (stats, | 1088 | GNUNET_CRYPTO_hash_from_string ((char *) &enc, &pid.hashPubKey)) |
1193 | gettext_noop ("# friends in configuration"), | ||
1194 | entries_found, | ||
1195 | GNUNET_NO); | ||
1196 | if ( (minimum_friend_count > entries_found) && | ||
1197 | (friends_only == GNUNET_NO) ) | ||
1198 | { | 1089 | { |
1199 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1090 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1200 | _("Fewer friends specified than required by minimum friend count. Will only connect to friends.\n")); | 1091 | _ |
1092 | ("Syntax error in topology specification at offset %llu, skipping bytes `%s'.\n"), | ||
1093 | (unsigned long long) pos, &enc); | ||
1201 | } | 1094 | } |
1202 | if ( (minimum_friend_count > target_connection_count) && | 1095 | else |
1203 | (friends_only == GNUNET_NO) ) | ||
1204 | { | 1096 | { |
1205 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1097 | if (0 != memcmp (&pid, &my_identity, sizeof (struct GNUNET_PeerIdentity))) |
1206 | _("More friendly connections required than target total number of connections.\n")); | 1098 | { |
1099 | entries_found++; | ||
1100 | fl = make_peer (&pid, NULL, GNUNET_YES); | ||
1101 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1102 | _("Found friend `%s' in configuration\n"), | ||
1103 | GNUNET_i2s (&fl->pid)); | ||
1104 | } | ||
1105 | else | ||
1106 | { | ||
1107 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1108 | _("Found myself `%s' in friend list (useless, ignored)\n"), | ||
1109 | GNUNET_i2s (&pid)); | ||
1110 | } | ||
1207 | } | 1111 | } |
1112 | pos = pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded); | ||
1113 | while ((pos < frstat.st_size) && isspace ((unsigned char) data[pos])) | ||
1114 | pos++; | ||
1115 | } | ||
1116 | GNUNET_free (data); | ||
1117 | GNUNET_free (fn); | ||
1118 | GNUNET_STATISTICS_update (stats, | ||
1119 | gettext_noop ("# friends in configuration"), | ||
1120 | entries_found, GNUNET_NO); | ||
1121 | if ((minimum_friend_count > entries_found) && (friends_only == GNUNET_NO)) | ||
1122 | { | ||
1123 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1124 | _ | ||
1125 | ("Fewer friends specified than required by minimum friend count. Will only connect to friends.\n")); | ||
1126 | } | ||
1127 | if ((minimum_friend_count > target_connection_count) && | ||
1128 | (friends_only == GNUNET_NO)) | ||
1129 | { | ||
1130 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1131 | _ | ||
1132 | ("More friendly connections required than target total number of connections.\n")); | ||
1133 | } | ||
1208 | } | 1134 | } |
1209 | 1135 | ||
1210 | 1136 | ||
@@ -1222,51 +1148,43 @@ read_friends_file (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
1222 | */ | 1148 | */ |
1223 | static int | 1149 | static int |
1224 | handle_encrypted_hello (void *cls, | 1150 | handle_encrypted_hello (void *cls, |
1225 | const struct GNUNET_PeerIdentity * other, | 1151 | const struct GNUNET_PeerIdentity *other, |
1226 | const struct GNUNET_MessageHeader * | 1152 | const struct GNUNET_MessageHeader *message, |
1227 | message, | 1153 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
1228 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | ||
1229 | { | 1154 | { |
1230 | struct Peer *peer; | 1155 | struct Peer *peer; |
1231 | struct GNUNET_PeerIdentity pid; | 1156 | struct GNUNET_PeerIdentity pid; |
1232 | 1157 | ||
1233 | #if DEBUG_TOPOLOGY | 1158 | #if DEBUG_TOPOLOGY |
1234 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1159 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1235 | "Received encrypted `%s' from peer `%s'", | 1160 | "Received encrypted `%s' from peer `%s'", |
1236 | "HELLO", | 1161 | "HELLO", GNUNET_i2s (other)); |
1237 | GNUNET_i2s (other)); | 1162 | #endif |
1238 | #endif | ||
1239 | if (GNUNET_OK != | 1163 | if (GNUNET_OK != |
1240 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message*) message, | 1164 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) message, &pid)) |
1241 | &pid)) | 1165 | { |
1242 | { | 1166 | GNUNET_break_op (0); |
1243 | GNUNET_break_op (0); | 1167 | return GNUNET_SYSERR; |
1244 | return GNUNET_SYSERR; | 1168 | } |
1245 | } | ||
1246 | GNUNET_STATISTICS_update (stats, | 1169 | GNUNET_STATISTICS_update (stats, |
1247 | gettext_noop ("# HELLO messages received"), | 1170 | gettext_noop ("# HELLO messages received"), |
1248 | 1, | 1171 | 1, GNUNET_NO); |
1249 | GNUNET_NO); | 1172 | peer = GNUNET_CONTAINER_multihashmap_get (peers, &pid.hashPubKey); |
1250 | peer = GNUNET_CONTAINER_multihashmap_get (peers, | ||
1251 | &pid.hashPubKey); | ||
1252 | if (peer == NULL) | 1173 | if (peer == NULL) |
1253 | { | 1174 | { |
1254 | if ( (GNUNET_YES == friends_only) || | 1175 | if ((GNUNET_YES == friends_only) || (friend_count < minimum_friend_count)) |
1255 | (friend_count < minimum_friend_count) ) | 1176 | return GNUNET_OK; |
1256 | return GNUNET_OK; | 1177 | } |
1257 | } | ||
1258 | else | 1178 | else |
1259 | { | 1179 | { |
1260 | if ( (GNUNET_YES != peer->is_friend) && | 1180 | if ((GNUNET_YES != peer->is_friend) && (GNUNET_YES == friends_only)) |
1261 | (GNUNET_YES == friends_only) ) | 1181 | return GNUNET_OK; |
1262 | return GNUNET_OK; | 1182 | if ((GNUNET_YES != peer->is_friend) && |
1263 | if ( (GNUNET_YES != peer->is_friend) && | 1183 | (friend_count < minimum_friend_count)) |
1264 | (friend_count < minimum_friend_count) ) | 1184 | return GNUNET_OK; |
1265 | return GNUNET_OK; | 1185 | } |
1266 | } | ||
1267 | if (transport != NULL) | 1186 | if (transport != NULL) |
1268 | GNUNET_TRANSPORT_offer_hello (transport, | 1187 | GNUNET_TRANSPORT_offer_hello (transport, message, NULL, NULL); |
1269 | message, NULL, NULL); | ||
1270 | return GNUNET_OK; | 1188 | return GNUNET_OK; |
1271 | } | 1189 | } |
1272 | 1190 | ||
@@ -1280,50 +1198,41 @@ handle_encrypted_hello (void *cls, | |||
1280 | * @return number of bytes written to buf | 1198 | * @return number of bytes written to buf |
1281 | */ | 1199 | */ |
1282 | static size_t | 1200 | static size_t |
1283 | hello_advertising_ready (void *cls, | 1201 | hello_advertising_ready (void *cls, size_t size, void *buf) |
1284 | size_t size, | ||
1285 | void *buf) | ||
1286 | { | 1202 | { |
1287 | struct Peer *pl = cls; | 1203 | struct Peer *pl = cls; |
1288 | struct FindAdvHelloContext fah; | 1204 | struct FindAdvHelloContext fah; |
1289 | size_t want; | 1205 | size_t want; |
1290 | 1206 | ||
1291 | pl->hello_req = NULL; | 1207 | pl->hello_req = NULL; |
1292 | GNUNET_assert (GNUNET_YES == pl->is_connected); | 1208 | GNUNET_assert (GNUNET_YES == pl->is_connected); |
1293 | /* find applicable HELLOs */ | 1209 | /* find applicable HELLOs */ |
1294 | fah.peer = pl; | 1210 | fah.peer = pl; |
1295 | fah.result = NULL; | 1211 | fah.result = NULL; |
1296 | fah.max_size = size; | 1212 | fah.max_size = size; |
1297 | fah.next_adv = GNUNET_TIME_UNIT_FOREVER_REL; | 1213 | fah.next_adv = GNUNET_TIME_UNIT_FOREVER_REL; |
1298 | GNUNET_CONTAINER_multihashmap_iterate (peers, | 1214 | GNUNET_CONTAINER_multihashmap_iterate (peers, &find_advertisable_hello, &fah); |
1299 | &find_advertisable_hello, | ||
1300 | &fah); | ||
1301 | want = 0; | 1215 | want = 0; |
1302 | if (fah.result != NULL) | 1216 | if (fah.result != NULL) |
1303 | { | 1217 | { |
1304 | want = GNUNET_HELLO_size (fah.result->hello); | 1218 | want = GNUNET_HELLO_size (fah.result->hello); |
1305 | GNUNET_assert (want <= size); | 1219 | GNUNET_assert (want <= size); |
1306 | memcpy (buf, fah.result->hello, want); | 1220 | memcpy (buf, fah.result->hello, want); |
1307 | GNUNET_CONTAINER_bloomfilter_add (fah.result->filter, | 1221 | GNUNET_CONTAINER_bloomfilter_add (fah.result->filter, &pl->pid.hashPubKey); |
1308 | &pl->pid.hashPubKey); | ||
1309 | #if DEBUG_TOPOLOGY | 1222 | #if DEBUG_TOPOLOGY |
1310 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1223 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1311 | "Sending `%s' with %u bytes", | 1224 | "Sending `%s' with %u bytes", "HELLO", (unsigned int) want); |
1312 | "HELLO", | 1225 | #endif |
1313 | (unsigned int) want); | 1226 | GNUNET_STATISTICS_update (stats, |
1314 | #endif | 1227 | gettext_noop ("# HELLO messages gossipped"), |
1315 | GNUNET_STATISTICS_update (stats, | 1228 | 1, GNUNET_NO); |
1316 | gettext_noop ("# HELLO messages gossipped"), | 1229 | } |
1317 | 1, | ||
1318 | GNUNET_NO); | ||
1319 | } | ||
1320 | 1230 | ||
1321 | if (pl->hello_delay_task != GNUNET_SCHEDULER_NO_TASK) | 1231 | if (pl->hello_delay_task != GNUNET_SCHEDULER_NO_TASK) |
1322 | GNUNET_SCHEDULER_cancel(pl->hello_delay_task); | 1232 | GNUNET_SCHEDULER_cancel (pl->hello_delay_task); |
1323 | pl->next_hello_allowed = GNUNET_TIME_relative_to_absolute (HELLO_ADVERTISEMENT_MIN_FREQUENCY); | 1233 | pl->next_hello_allowed = |
1324 | pl->hello_delay_task | 1234 | GNUNET_TIME_relative_to_absolute (HELLO_ADVERTISEMENT_MIN_FREQUENCY); |
1325 | = GNUNET_SCHEDULER_add_now (&schedule_next_hello, | 1235 | pl->hello_delay_task = GNUNET_SCHEDULER_add_now (&schedule_next_hello, pl); |
1326 | pl); | ||
1327 | return want; | 1236 | return want; |
1328 | } | 1237 | } |
1329 | 1238 | ||
@@ -1336,36 +1245,33 @@ hello_advertising_ready (void *cls, | |||
1336 | * @param tc scheduler context | 1245 | * @param tc scheduler context |
1337 | */ | 1246 | */ |
1338 | static void | 1247 | static void |
1339 | cleaning_task (void *cls, | 1248 | cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
1340 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1341 | { | 1249 | { |
1342 | if (NULL != peerinfo_notify) | 1250 | if (NULL != peerinfo_notify) |
1343 | { | 1251 | { |
1344 | GNUNET_PEERINFO_notify_cancel (peerinfo_notify); | 1252 | GNUNET_PEERINFO_notify_cancel (peerinfo_notify); |
1345 | peerinfo_notify = NULL; | 1253 | peerinfo_notify = NULL; |
1346 | } | 1254 | } |
1347 | if (GNUNET_SCHEDULER_NO_TASK != add_task) | 1255 | if (GNUNET_SCHEDULER_NO_TASK != add_task) |
1348 | { | 1256 | { |
1349 | GNUNET_SCHEDULER_cancel (add_task); | 1257 | GNUNET_SCHEDULER_cancel (add_task); |
1350 | add_task = GNUNET_SCHEDULER_NO_TASK; | 1258 | add_task = GNUNET_SCHEDULER_NO_TASK; |
1351 | } | 1259 | } |
1352 | GNUNET_TRANSPORT_disconnect (transport); | 1260 | GNUNET_TRANSPORT_disconnect (transport); |
1353 | transport = NULL; | 1261 | transport = NULL; |
1354 | GNUNET_CONTAINER_multihashmap_iterate (peers, | 1262 | GNUNET_CONTAINER_multihashmap_iterate (peers, &free_peer, NULL); |
1355 | &free_peer, | ||
1356 | NULL); | ||
1357 | GNUNET_CONTAINER_multihashmap_destroy (peers); | 1263 | GNUNET_CONTAINER_multihashmap_destroy (peers); |
1358 | if (handle != NULL) | 1264 | if (handle != NULL) |
1359 | { | 1265 | { |
1360 | GNUNET_CORE_disconnect (handle); | 1266 | GNUNET_CORE_disconnect (handle); |
1361 | handle = NULL; | 1267 | handle = NULL; |
1362 | } | 1268 | } |
1363 | whitelist_peers (); | 1269 | whitelist_peers (); |
1364 | if (stats != NULL) | 1270 | if (stats != NULL) |
1365 | { | 1271 | { |
1366 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | 1272 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); |
1367 | stats = NULL; | 1273 | stats = NULL; |
1368 | } | 1274 | } |
1369 | } | 1275 | } |
1370 | 1276 | ||
1371 | 1277 | ||
@@ -1380,88 +1286,72 @@ cleaning_task (void *cls, | |||
1380 | static void | 1286 | static void |
1381 | run (void *cls, | 1287 | run (void *cls, |
1382 | char *const *args, | 1288 | char *const *args, |
1383 | const char *cfgfile, | 1289 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) |
1384 | const struct GNUNET_CONFIGURATION_Handle * c) | ||
1385 | { | 1290 | { |
1386 | static struct GNUNET_CORE_MessageHandler handlers[] = | 1291 | static struct GNUNET_CORE_MessageHandler handlers[] = { |
1387 | { | 1292 | {&handle_encrypted_hello, GNUNET_MESSAGE_TYPE_HELLO, 0}, |
1388 | { &handle_encrypted_hello, GNUNET_MESSAGE_TYPE_HELLO, 0}, | 1293 | {NULL, 0, 0} |
1389 | { NULL, 0, 0 } | 1294 | }; |
1390 | }; | ||
1391 | unsigned long long opt; | 1295 | unsigned long long opt; |
1392 | 1296 | ||
1393 | cfg = c; | 1297 | cfg = c; |
1394 | stats = GNUNET_STATISTICS_create ("topology", cfg); | 1298 | stats = GNUNET_STATISTICS_create ("topology", cfg); |
1395 | autoconnect = GNUNET_CONFIGURATION_get_value_yesno (cfg, | 1299 | autoconnect = GNUNET_CONFIGURATION_get_value_yesno (cfg, |
1396 | "TOPOLOGY", | 1300 | "TOPOLOGY", |
1397 | "AUTOCONNECT"); | 1301 | "AUTOCONNECT"); |
1398 | friends_only = GNUNET_CONFIGURATION_get_value_yesno (cfg, | 1302 | friends_only = GNUNET_CONFIGURATION_get_value_yesno (cfg, |
1399 | "TOPOLOGY", | 1303 | "TOPOLOGY", |
1400 | "FRIENDS-ONLY"); | 1304 | "FRIENDS-ONLY"); |
1401 | if (GNUNET_OK != | 1305 | if (GNUNET_OK != |
1402 | GNUNET_CONFIGURATION_get_value_number (cfg, | 1306 | GNUNET_CONFIGURATION_get_value_number (cfg, |
1403 | "TOPOLOGY", | 1307 | "TOPOLOGY", |
1404 | "MINIMUM-FRIENDS", | 1308 | "MINIMUM-FRIENDS", &opt)) |
1405 | &opt)) | ||
1406 | opt = 0; | 1309 | opt = 0; |
1407 | minimum_friend_count = (unsigned int) opt; | 1310 | minimum_friend_count = (unsigned int) opt; |
1408 | if (GNUNET_OK != | 1311 | if (GNUNET_OK != |
1409 | GNUNET_CONFIGURATION_get_value_number (cfg, | 1312 | GNUNET_CONFIGURATION_get_value_number (cfg, |
1410 | "TOPOLOGY", | 1313 | "TOPOLOGY", |
1411 | "TARGET-CONNECTION-COUNT", | 1314 | "TARGET-CONNECTION-COUNT", &opt)) |
1412 | &opt)) | ||
1413 | opt = 16; | 1315 | opt = 16; |
1414 | target_connection_count = (unsigned int) opt; | 1316 | target_connection_count = (unsigned int) opt; |
1415 | peers = GNUNET_CONTAINER_multihashmap_create (target_connection_count * 2); | 1317 | peers = GNUNET_CONTAINER_multihashmap_create (target_connection_count * 2); |
1416 | 1318 | ||
1417 | if ( (friends_only == GNUNET_YES) || | 1319 | if ((friends_only == GNUNET_YES) || (minimum_friend_count > 0)) |
1418 | (minimum_friend_count > 0) ) | ||
1419 | read_friends_file (cfg); | 1320 | read_friends_file (cfg); |
1420 | #if DEBUG_TOPOLOGY | 1321 | #if DEBUG_TOPOLOGY |
1421 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1322 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1422 | "Topology would like %u connections with at least %u friends (%s)\n", | 1323 | "Topology would like %u connections with at least %u friends (%s)\n", |
1423 | target_connection_count, | 1324 | target_connection_count, |
1424 | minimum_friend_count, | 1325 | minimum_friend_count, |
1425 | autoconnect ? "autoconnect enabled" : "autoconnect disabled"); | 1326 | autoconnect ? "autoconnect enabled" : "autoconnect disabled"); |
1426 | #endif | 1327 | #endif |
1427 | if ( (friend_count < minimum_friend_count) && | 1328 | if ((friend_count < minimum_friend_count) && (blacklist == NULL)) |
1428 | (blacklist == NULL) ) | 1329 | blacklist = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_check, NULL); |
1429 | blacklist = GNUNET_TRANSPORT_blacklist (cfg, | 1330 | transport = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, NULL, NULL, NULL); |
1430 | &blacklist_check, NULL); | ||
1431 | transport = GNUNET_TRANSPORT_connect (cfg, | ||
1432 | NULL, | ||
1433 | NULL, | ||
1434 | NULL, | ||
1435 | NULL, | ||
1436 | NULL); | ||
1437 | handle = GNUNET_CORE_connect (cfg, | 1331 | handle = GNUNET_CORE_connect (cfg, |
1438 | 1, | 1332 | 1, |
1439 | NULL, | 1333 | NULL, |
1440 | &core_init, | 1334 | &core_init, |
1441 | &connect_notify, | 1335 | &connect_notify, |
1442 | &disconnect_notify, | 1336 | &disconnect_notify, |
1443 | NULL, | 1337 | NULL, |
1444 | NULL, GNUNET_NO, | 1338 | NULL, GNUNET_NO, NULL, GNUNET_NO, handlers); |
1445 | NULL, GNUNET_NO, | ||
1446 | handlers); | ||
1447 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 1339 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
1448 | &cleaning_task, NULL); | 1340 | &cleaning_task, NULL); |
1449 | if (NULL == transport) | 1341 | if (NULL == transport) |
1450 | { | 1342 | { |
1451 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1343 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1452 | _("Failed to connect to `%s' service.\n"), | 1344 | _("Failed to connect to `%s' service.\n"), "transport"); |
1453 | "transport"); | 1345 | GNUNET_SCHEDULER_shutdown (); |
1454 | GNUNET_SCHEDULER_shutdown (); | 1346 | return; |
1455 | return; | 1347 | } |
1456 | } | ||
1457 | if (NULL == handle) | 1348 | if (NULL == handle) |
1458 | { | 1349 | { |
1459 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1350 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1460 | _("Failed to connect to `%s' service.\n"), | 1351 | _("Failed to connect to `%s' service.\n"), "core"); |
1461 | "core"); | 1352 | GNUNET_SCHEDULER_shutdown (); |
1462 | GNUNET_SCHEDULER_shutdown (); | 1353 | return; |
1463 | return; | 1354 | } |
1464 | } | ||
1465 | } | 1355 | } |
1466 | 1356 | ||
1467 | 1357 | ||
@@ -1484,9 +1374,9 @@ main (int argc, char *const *argv) | |||
1484 | GNUNET_PROGRAM_run (argc, | 1374 | GNUNET_PROGRAM_run (argc, |
1485 | argv, | 1375 | argv, |
1486 | "gnunet-daemon-topology", | 1376 | "gnunet-daemon-topology", |
1487 | _("GNUnet topology control (maintaining P2P mesh and F2F constraints)"), | 1377 | _ |
1488 | options, | 1378 | ("GNUnet topology control (maintaining P2P mesh and F2F constraints)"), |
1489 | &run, NULL)) ? 0 : 1; | 1379 | options, &run, NULL)) ? 0 : 1; |
1490 | return ret; | 1380 | return ret; |
1491 | } | 1381 | } |
1492 | 1382 | ||