diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/peerinfo/gnunet-service-peerinfo.c | 69 |
1 files changed, 56 insertions, 13 deletions
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c index ce7a38a6d..0b2a360c3 100644 --- a/src/peerinfo/gnunet-service-peerinfo.c +++ b/src/peerinfo/gnunet-service-peerinfo.c | |||
@@ -422,16 +422,34 @@ read_host_file (const char *fn, int unlink_garbage, struct ReadHostFileContext * | |||
422 | } | 422 | } |
423 | 423 | ||
424 | if (GNUNET_NO == GNUNET_HELLO_is_friend_only(hello_clean_1st)) | 424 | if (GNUNET_NO == GNUNET_HELLO_is_friend_only(hello_clean_1st)) |
425 | r->hello = hello_clean_1st; | 425 | { |
426 | if (NULL == r->hello) | ||
427 | r->hello = hello_clean_1st; | ||
428 | else | ||
429 | { | ||
430 | GNUNET_break (0); | ||
431 | GNUNET_free (r->hello); | ||
432 | r->hello = hello_clean_1st; | ||
433 | } | ||
434 | } | ||
426 | else | 435 | else |
427 | r->friend_only_hello = hello_clean_1st; | 436 | { |
437 | if (NULL == r->friend_only_hello) | ||
438 | r->friend_only_hello = hello_clean_1st; | ||
439 | else | ||
440 | { | ||
441 | GNUNET_break (0); | ||
442 | GNUNET_free (r->friend_only_hello); | ||
443 | r->friend_only_hello = hello_clean_1st; | ||
444 | } | ||
445 | } | ||
428 | 446 | ||
429 | if (NULL != hello_2nd) | 447 | if (NULL != hello_2nd) |
430 | { | 448 | { |
431 | hello_clean_2nd = GNUNET_HELLO_iterate_addresses (hello_2nd, GNUNET_YES, | 449 | hello_clean_2nd = GNUNET_HELLO_iterate_addresses (hello_2nd, GNUNET_YES, |
432 | &discard_expired, &now); | 450 | &discard_expired, &now); |
433 | left = 0; | 451 | left = 0; |
434 | (void) GNUNET_HELLO_iterate_addresses (hello_2nd, GNUNET_NO, | 452 | (void) GNUNET_HELLO_iterate_addresses (hello_clean_2nd, GNUNET_NO, |
435 | &count_addresses, &left); | 453 | &count_addresses, &left); |
436 | if (0 == left) | 454 | if (0 == left) |
437 | { | 455 | { |
@@ -440,10 +458,28 @@ read_host_file (const char *fn, int unlink_garbage, struct ReadHostFileContext * | |||
440 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | 458 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); |
441 | } | 459 | } |
442 | 460 | ||
443 | if (GNUNET_NO == GNUNET_HELLO_is_friend_only (hello_clean_2nd)) | 461 | if (GNUNET_NO == GNUNET_HELLO_is_friend_only(hello_clean_2nd)) |
444 | r->hello = hello_clean_2nd; | 462 | { |
463 | if (NULL == r->hello) | ||
464 | r->hello = hello_clean_2nd; | ||
465 | else | ||
466 | { | ||
467 | GNUNET_break (0); | ||
468 | GNUNET_free (r->hello); | ||
469 | r->hello = hello_clean_2nd; | ||
470 | } | ||
471 | } | ||
445 | else | 472 | else |
446 | r->friend_only_hello = hello_clean_2nd; | 473 | { |
474 | if (NULL == r->friend_only_hello) | ||
475 | r->friend_only_hello = hello_clean_2nd; | ||
476 | else | ||
477 | { | ||
478 | GNUNET_break (0); | ||
479 | GNUNET_free (r->friend_only_hello); | ||
480 | r->friend_only_hello = hello_clean_2nd; | ||
481 | } | ||
482 | } | ||
447 | } | 483 | } |
448 | 484 | ||
449 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found `%s' and `%s' HELLO message in file\n", | 485 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found `%s' and `%s' HELLO message in file\n", |
@@ -482,8 +518,12 @@ add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity) | |||
482 | if (NULL != fn) | 518 | if (NULL != fn) |
483 | { | 519 | { |
484 | read_host_file (fn, GNUNET_YES, &r); | 520 | read_host_file (fn, GNUNET_YES, &r); |
485 | entry->hello = r.hello; | 521 | if (NULL != r.hello) |
486 | entry->friend_only_hello = r.friend_only_hello; | 522 | update_hello (identity, r.hello); |
523 | if (NULL != r.friend_only_hello) | ||
524 | update_hello (identity, r.friend_only_hello); | ||
525 | GNUNET_free_non_null (r.hello); | ||
526 | GNUNET_free_non_null (r.friend_only_hello); | ||
487 | GNUNET_free (fn); | 527 | GNUNET_free (fn); |
488 | } | 528 | } |
489 | notify_all (entry); | 529 | notify_all (entry); |
@@ -548,7 +588,6 @@ hosts_directory_scan_callback (void *cls, const char *fullname) | |||
548 | struct GNUNET_PeerIdentity identity; | 588 | struct GNUNET_PeerIdentity identity; |
549 | struct ReadHostFileContext r; | 589 | struct ReadHostFileContext r; |
550 | const char *filename; | 590 | const char *filename; |
551 | struct HostEntry *entry; | ||
552 | struct GNUNET_PeerIdentity id_public; | 591 | struct GNUNET_PeerIdentity id_public; |
553 | struct GNUNET_PeerIdentity id_friend; | 592 | struct GNUNET_PeerIdentity id_friend; |
554 | struct GNUNET_PeerIdentity id; | 593 | struct GNUNET_PeerIdentity id; |
@@ -614,18 +653,20 @@ hosts_directory_scan_callback (void *cls, const char *fullname) | |||
614 | } | 653 | } |
615 | } | 654 | } |
616 | /* ok, found something valid, remember HELLO */ | 655 | /* ok, found something valid, remember HELLO */ |
617 | entry = add_host_to_known_hosts (&id); | 656 | add_host_to_known_hosts (&id); |
618 | if (NULL != r.hello) | 657 | if (NULL != r.hello) |
619 | { | 658 | { |
620 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating peer `%s' public HELLO \n", | 659 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating peer `%s' public HELLO \n", |
621 | GNUNET_i2s (&id)); | 660 | GNUNET_i2s (&id)); |
622 | update_hello (&id, r.hello); | 661 | update_hello (&id, r.hello); |
662 | GNUNET_free (r.hello); | ||
623 | } | 663 | } |
624 | if (NULL != r.friend_only_hello) | 664 | if (NULL != r.friend_only_hello) |
625 | { | 665 | { |
626 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating peer `%s' friend only HELLO \n", | 666 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating peer `%s' friend only HELLO \n", |
627 | GNUNET_i2s (&id)); | 667 | GNUNET_i2s (&id)); |
628 | update_hello (&id, r.friend_only_hello); | 668 | update_hello (&id, r.friend_only_hello); |
669 | GNUNET_free (r.friend_only_hello); | ||
629 | } | 670 | } |
630 | dsc->matched++; | 671 | dsc->matched++; |
631 | return GNUNET_OK; | 672 | return GNUNET_OK; |
@@ -673,6 +714,7 @@ update_friend_hello (const struct GNUNET_HELLO_Message *hello, | |||
673 | const struct GNUNET_HELLO_Message *friend_hello) | 714 | const struct GNUNET_HELLO_Message *friend_hello) |
674 | { | 715 | { |
675 | struct GNUNET_HELLO_Message * res; | 716 | struct GNUNET_HELLO_Message * res; |
717 | struct GNUNET_HELLO_Message * tmp; | ||
676 | struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pk; | 718 | struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pk; |
677 | 719 | ||
678 | if (NULL != friend_hello) | 720 | if (NULL != friend_hello) |
@@ -683,8 +725,9 @@ update_friend_hello (const struct GNUNET_HELLO_Message *hello, | |||
683 | } | 725 | } |
684 | 726 | ||
685 | GNUNET_HELLO_get_key (hello, &pk); | 727 | GNUNET_HELLO_get_key (hello, &pk); |
686 | res = GNUNET_HELLO_create (&pk, NULL, NULL, GNUNET_YES); | 728 | tmp = GNUNET_HELLO_create (&pk, NULL, NULL, GNUNET_YES); |
687 | res = GNUNET_HELLO_merge (hello, res); | 729 | res = GNUNET_HELLO_merge (hello, tmp); |
730 | GNUNET_free (tmp); | ||
688 | GNUNET_assert (GNUNET_YES == GNUNET_HELLO_is_friend_only (res)); | 731 | GNUNET_assert (GNUNET_YES == GNUNET_HELLO_is_friend_only (res)); |
689 | return res; | 732 | return res; |
690 | } | 733 | } |
@@ -718,7 +761,7 @@ update_hello (const struct GNUNET_PeerIdentity *peer, | |||
718 | GNUNET_assert (NULL != host); | 761 | GNUNET_assert (NULL != host); |
719 | 762 | ||
720 | friend_hello_type = GNUNET_HELLO_is_friend_only (hello); | 763 | friend_hello_type = GNUNET_HELLO_is_friend_only (hello); |
721 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %s HELLO for `%s'\n", | 764 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating %s HELLO for `%s'\n", |
722 | (GNUNET_YES == friend_hello_type) ? "friend-only" : "public", | 765 | (GNUNET_YES == friend_hello_type) ? "friend-only" : "public", |
723 | GNUNET_i2s (peer)); | 766 | GNUNET_i2s (peer)); |
724 | 767 | ||