diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-05-21 13:31:02 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-05-21 13:31:02 +0000 |
commit | bcba42d4b8e2295a8083bdd41cf332919a194cd6 (patch) | |
tree | e89ad934e0ecff9085266ef08b7a8dda2de000ff /src/peerinfo | |
parent | c192aad3e7b492a2042164d8300f060476805afa (diff) | |
download | gnunet-bcba42d4b8e2295a8083bdd41cf332919a194cd6.tar.gz gnunet-bcba42d4b8e2295a8083bdd41cf332919a194cd6.zip |
-fixing indentation, logging
Diffstat (limited to 'src/peerinfo')
-rw-r--r-- | src/peerinfo/gnunet-service-peerinfo.c | 532 |
1 files changed, 268 insertions, 264 deletions
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c index 73be06809..90f0b75dc 100644 --- a/src/peerinfo/gnunet-service-peerinfo.c +++ b/src/peerinfo/gnunet-service-peerinfo.c | |||
@@ -354,7 +354,9 @@ read_host_file (const char *fn, int unlink_garbage, struct ReadHostFileContext * | |||
354 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 354 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
355 | _("Failed to parse HELLO in file `%s': %s\n"), | 355 | _("Failed to parse HELLO in file `%s': %s\n"), |
356 | fn, "Fail has invalid size"); | 356 | fn, "Fail has invalid size"); |
357 | if ( (GNUNET_YES == unlink_garbage) && (0 != UNLINK (fn)) ) | 357 | if ( (GNUNET_YES == unlink_garbage) && |
358 | (0 != UNLINK (fn)) && | ||
359 | (ENOENT != errno) ) | ||
358 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | 360 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); |
359 | return; | 361 | return; |
360 | } | 362 | } |
@@ -362,54 +364,56 @@ read_host_file (const char *fn, int unlink_garbage, struct ReadHostFileContext * | |||
362 | read_pos = 0; | 364 | read_pos = 0; |
363 | while (read_pos < size_total) | 365 | while (read_pos < size_total) |
364 | { | 366 | { |
365 | hello = (const struct GNUNET_HELLO_Message *) &buffer[read_pos]; | 367 | hello = (const struct GNUNET_HELLO_Message *) &buffer[read_pos]; |
366 | size_hello = GNUNET_HELLO_size (hello); | 368 | size_hello = GNUNET_HELLO_size (hello); |
367 | if (0 == size_hello) | 369 | if (0 == size_hello) |
368 | { | 370 | { |
369 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 371 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
370 | _("Failed to parse HELLO in file `%s': %s %u \n"), | 372 | _("Failed to parse HELLO in file `%s': %s %u \n"), |
371 | fn, "HELLO is invalid and has size of ", size_hello); | 373 | fn, "HELLO is invalid and has size of ", size_hello); |
372 | if ((GNUNET_YES == unlink_garbage) && (0 != UNLINK (fn))) | 374 | if ((GNUNET_YES == unlink_garbage) && |
373 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | 375 | (0 != UNLINK (fn)) && |
374 | return; | 376 | (ENOENT != errno) ) |
375 | } | 377 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); |
376 | 378 | return; | |
377 | now = GNUNET_TIME_absolute_get (); | 379 | } |
378 | hello_clean = GNUNET_HELLO_iterate_addresses (hello, GNUNET_YES, | 380 | |
379 | &discard_expired, &now); | 381 | now = GNUNET_TIME_absolute_get (); |
380 | left = 0; | 382 | hello_clean = GNUNET_HELLO_iterate_addresses (hello, GNUNET_YES, |
381 | (void) GNUNET_HELLO_iterate_addresses (hello_clean, GNUNET_NO, | 383 | &discard_expired, &now); |
382 | &count_addresses, &left); | 384 | left = 0; |
383 | 385 | (void) GNUNET_HELLO_iterate_addresses (hello_clean, GNUNET_NO, | |
384 | if (0 == left) | 386 | &count_addresses, &left); |
385 | { | 387 | |
386 | GNUNET_free (hello_clean); | 388 | if (0 == left) |
387 | break; | 389 | { |
388 | } | 390 | GNUNET_free (hello_clean); |
389 | 391 | break; | |
390 | if (GNUNET_NO == GNUNET_HELLO_is_friend_only (hello_clean)) | 392 | } |
391 | { | 393 | |
392 | if (NULL == r->hello) | 394 | if (GNUNET_NO == GNUNET_HELLO_is_friend_only (hello_clean)) |
393 | r->hello = hello_clean; | 395 | { |
394 | else | 396 | if (NULL == r->hello) |
395 | { | 397 | r->hello = hello_clean; |
396 | GNUNET_break (0); | 398 | else |
397 | GNUNET_free (r->hello); | 399 | { |
398 | r->hello = hello_clean; | 400 | GNUNET_break (0); |
399 | } | 401 | GNUNET_free (r->hello); |
400 | } | 402 | r->hello = hello_clean; |
401 | else | 403 | } |
402 | { | 404 | } |
403 | if (NULL == r->friend_only_hello) | 405 | else |
404 | r->friend_only_hello = hello_clean; | 406 | { |
405 | else | 407 | if (NULL == r->friend_only_hello) |
406 | { | 408 | r->friend_only_hello = hello_clean; |
407 | GNUNET_break (0); | 409 | else |
408 | GNUNET_free (r->friend_only_hello); | 410 | { |
409 | r->friend_only_hello = hello_clean; | 411 | GNUNET_break (0); |
410 | } | 412 | GNUNET_free (r->friend_only_hello); |
411 | } | 413 | r->friend_only_hello = hello_clean; |
412 | read_pos += size_hello; | 414 | } |
415 | } | ||
416 | read_pos += size_hello; | ||
413 | } | 417 | } |
414 | 418 | ||
415 | if (0 == left) | 419 | if (0 == left) |
@@ -419,9 +423,10 @@ read_host_file (const char *fn, int unlink_garbage, struct ReadHostFileContext * | |||
419 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | 423 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); |
420 | } | 424 | } |
421 | 425 | ||
422 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found `%s' and `%s' HELLO message in file\n", | 426 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
423 | (NULL != r->hello) ? "public" : "NO public", | 427 | "Found `%s' and `%s' HELLO message in file\n", |
424 | (NULL != r->friend_only_hello) ? "friend only" : "NO friend only"); | 428 | (NULL != r->hello) ? "public" : "NO public", |
429 | (NULL != r->friend_only_hello) ? "friend only" : "NO friend only"); | ||
425 | } | 430 | } |
426 | 431 | ||
427 | 432 | ||
@@ -441,13 +446,13 @@ add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity) | |||
441 | entry = GNUNET_CONTAINER_multihashmap_get (hostmap, &identity->hashPubKey); | 446 | entry = GNUNET_CONTAINER_multihashmap_get (hostmap, &identity->hashPubKey); |
442 | if (NULL == entry) | 447 | if (NULL == entry) |
443 | { | 448 | { |
444 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding new peer `%s'\n", GNUNET_i2s (identity)); | 449 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding new peer `%s'\n", GNUNET_i2s (identity)); |
445 | GNUNET_STATISTICS_update (stats, gettext_noop ("# peers known"), 1, | 450 | GNUNET_STATISTICS_update (stats, gettext_noop ("# peers known"), 1, |
446 | GNUNET_NO); | 451 | GNUNET_NO); |
447 | entry = GNUNET_malloc (sizeof (struct HostEntry)); | 452 | entry = GNUNET_malloc (sizeof (struct HostEntry)); |
448 | entry->identity = *identity; | 453 | entry->identity = *identity; |
449 | GNUNET_CONTAINER_multihashmap_put (hostmap, &entry->identity.hashPubKey, entry, | 454 | GNUNET_CONTAINER_multihashmap_put (hostmap, &entry->identity.hashPubKey, entry, |
450 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 455 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
451 | notify_all (entry); | 456 | notify_all (entry); |
452 | fn = get_host_filename (identity); | 457 | fn = get_host_filename (identity); |
453 | if (NULL != fn) | 458 | if (NULL != fn) |
@@ -536,72 +541,73 @@ hosts_directory_scan_callback (void *cls, const char *fullname) | |||
536 | filename ++; | 541 | filename ++; |
537 | 542 | ||
538 | read_host_file (fullname, dsc->remove_files, &r); | 543 | read_host_file (fullname, dsc->remove_files, &r); |
539 | if ( (NULL == r.hello) && (NULL == r.friend_only_hello)) | 544 | if ( (NULL == r.hello) && (NULL == r.friend_only_hello)) |
540 | { | 545 | { |
541 | if (GNUNET_YES == dsc->remove_files) | 546 | if (GNUNET_YES == dsc->remove_files) |
542 | remove_garbage (fullname); | 547 | remove_garbage (fullname); |
543 | return GNUNET_OK; | 548 | return GNUNET_OK; |
544 | } | 549 | } |
545 | |||
546 | if (NULL != r.friend_only_hello) | ||
547 | { | ||
548 | if (GNUNET_OK != GNUNET_HELLO_get_id (r.friend_only_hello, &id_friend)) | ||
549 | if (GNUNET_YES == dsc->remove_files) | ||
550 | { | ||
551 | remove_garbage (fullname); | ||
552 | return GNUNET_OK; | ||
553 | } | ||
554 | id = id_friend; | ||
555 | } | ||
556 | if (NULL != r.hello) | ||
557 | { | ||
558 | if (GNUNET_OK != GNUNET_HELLO_get_id (r.hello, &id_public)) | ||
559 | if (GNUNET_YES == dsc->remove_files) | ||
560 | { | ||
561 | remove_garbage (fullname); | ||
562 | return GNUNET_OK; | ||
563 | } | ||
564 | id = id_public; | ||
565 | } | ||
566 | 550 | ||
567 | if ( (NULL != r.hello) && (NULL != r.friend_only_hello) && | 551 | if (NULL != r.friend_only_hello) |
568 | (0 != memcmp (&id_friend, &id_public, sizeof (id_friend))) ) | 552 | { |
569 | { | 553 | if (GNUNET_OK != GNUNET_HELLO_get_id (r.friend_only_hello, &id_friend)) |
570 | /* HELLOs are not for the same peer */ | 554 | if (GNUNET_YES == dsc->remove_files) |
571 | GNUNET_break (0); | 555 | { |
572 | if (GNUNET_YES == dsc->remove_files) | 556 | remove_garbage (fullname); |
573 | remove_garbage (fullname); | 557 | return GNUNET_OK; |
574 | return GNUNET_OK; | 558 | } |
575 | } | 559 | id = id_friend; |
560 | } | ||
561 | if (NULL != r.hello) | ||
562 | { | ||
563 | if (GNUNET_OK != GNUNET_HELLO_get_id (r.hello, &id_public)) | ||
564 | if (GNUNET_YES == dsc->remove_files) | ||
565 | { | ||
566 | remove_garbage (fullname); | ||
567 | return GNUNET_OK; | ||
568 | } | ||
569 | id = id_public; | ||
570 | } | ||
571 | |||
572 | if ( (NULL != r.hello) && (NULL != r.friend_only_hello) && | ||
573 | (0 != memcmp (&id_friend, &id_public, sizeof (id_friend))) ) | ||
574 | { | ||
575 | /* HELLOs are not for the same peer */ | ||
576 | GNUNET_break (0); | ||
577 | if (GNUNET_YES == dsc->remove_files) | ||
578 | remove_garbage (fullname); | ||
579 | return GNUNET_OK; | ||
580 | } | ||
576 | if (GNUNET_OK == GNUNET_CRYPTO_hash_from_string (filename, &identity.hashPubKey)) | 581 | if (GNUNET_OK == GNUNET_CRYPTO_hash_from_string (filename, &identity.hashPubKey)) |
577 | { | 582 | { |
578 | if (0 != memcmp (&id, &identity, sizeof (id_friend))) | 583 | if (0 != memcmp (&id, &identity, sizeof (id_friend))) |
579 | { | 584 | { |
580 | /* HELLOs are not for the same peer */ | 585 | /* HELLOs are not for the same peer */ |
581 | GNUNET_break (0); | 586 | GNUNET_break (0); |
582 | if (GNUNET_YES == dsc->remove_files) | 587 | if (GNUNET_YES == dsc->remove_files) |
583 | remove_garbage (fullname); | 588 | remove_garbage (fullname); |
584 | return GNUNET_OK; | 589 | return GNUNET_OK; |
585 | } | 590 | } |
586 | } | 591 | } |
587 | /* ok, found something valid, remember HELLO */ | 592 | |
593 | /* ok, found something valid, remember HELLO */ | ||
588 | add_host_to_known_hosts (&id); | 594 | add_host_to_known_hosts (&id); |
589 | if (NULL != r.hello) | 595 | if (NULL != r.hello) |
590 | { | 596 | { |
591 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating peer `%s' public HELLO \n", | 597 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating peer `%s' public HELLO \n", |
592 | GNUNET_i2s (&id)); | 598 | GNUNET_i2s (&id)); |
593 | update_hello (&id, r.hello); | 599 | update_hello (&id, r.hello); |
594 | GNUNET_free (r.hello); | 600 | GNUNET_free (r.hello); |
595 | } | 601 | } |
596 | if (NULL != r.friend_only_hello) | 602 | if (NULL != r.friend_only_hello) |
597 | { | 603 | { |
598 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating peer `%s' friend only HELLO \n", | 604 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating peer `%s' friend only HELLO \n", |
599 | GNUNET_i2s (&id)); | 605 | GNUNET_i2s (&id)); |
600 | update_hello (&id, r.friend_only_hello); | 606 | update_hello (&id, r.friend_only_hello); |
601 | GNUNET_free (r.friend_only_hello); | 607 | GNUNET_free (r.friend_only_hello); |
602 | } | 608 | } |
603 | dsc->matched++; | 609 | dsc->matched++; |
604 | return GNUNET_OK; | 610 | return GNUNET_OK; |
605 | } | 611 | } |
606 | 612 | ||
607 | 613 | ||
@@ -647,27 +653,26 @@ static struct GNUNET_HELLO_Message * | |||
647 | update_friend_hello (const struct GNUNET_HELLO_Message *hello, | 653 | update_friend_hello (const struct GNUNET_HELLO_Message *hello, |
648 | const struct GNUNET_HELLO_Message *friend_hello) | 654 | const struct GNUNET_HELLO_Message *friend_hello) |
649 | { | 655 | { |
650 | struct GNUNET_HELLO_Message * res; | 656 | struct GNUNET_HELLO_Message * res; |
651 | struct GNUNET_HELLO_Message * tmp; | 657 | struct GNUNET_HELLO_Message * tmp; |
652 | struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pk; | 658 | struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pk; |
653 | 659 | ||
654 | if (NULL != friend_hello) | 660 | if (NULL != friend_hello) |
655 | { | 661 | { |
656 | res = GNUNET_HELLO_merge (hello, friend_hello); | 662 | res = GNUNET_HELLO_merge (hello, friend_hello); |
657 | GNUNET_assert (GNUNET_YES == GNUNET_HELLO_is_friend_only (res)); | 663 | GNUNET_assert (GNUNET_YES == GNUNET_HELLO_is_friend_only (res)); |
658 | return res; | 664 | return res; |
659 | } | 665 | } |
660 | 666 | ||
661 | GNUNET_HELLO_get_key (hello, &pk); | 667 | GNUNET_HELLO_get_key (hello, &pk); |
662 | tmp = GNUNET_HELLO_create (&pk, NULL, NULL, GNUNET_YES); | 668 | tmp = GNUNET_HELLO_create (&pk, NULL, NULL, GNUNET_YES); |
663 | res = GNUNET_HELLO_merge (hello, tmp); | 669 | res = GNUNET_HELLO_merge (hello, tmp); |
664 | GNUNET_free (tmp); | 670 | GNUNET_free (tmp); |
665 | GNUNET_assert (GNUNET_YES == GNUNET_HELLO_is_friend_only (res)); | 671 | GNUNET_assert (GNUNET_YES == GNUNET_HELLO_is_friend_only (res)); |
666 | return res; | 672 | return res; |
667 | } | 673 | } |
668 | 674 | ||
669 | 675 | ||
670 | |||
671 | /** | 676 | /** |
672 | * Bind a host address (hello) to a hostId. | 677 | * Bind a host address (hello) to a hostId. |
673 | * | 678 | * |
@@ -702,16 +707,16 @@ update_hello (const struct GNUNET_PeerIdentity *peer, | |||
702 | dest = NULL; | 707 | dest = NULL; |
703 | if (GNUNET_YES == friend_hello_type) | 708 | if (GNUNET_YES == friend_hello_type) |
704 | { | 709 | { |
705 | dest = &host->friend_only_hello; | 710 | dest = &host->friend_only_hello; |
706 | } | 711 | } |
707 | else | 712 | else |
708 | { | 713 | { |
709 | dest = &host->hello; | 714 | dest = &host->hello; |
710 | } | 715 | } |
711 | 716 | ||
712 | if (NULL == (*dest)) | 717 | if (NULL == (*dest)) |
713 | { | 718 | { |
714 | (*dest) = GNUNET_malloc (GNUNET_HELLO_size (hello)); | 719 | (*dest) = GNUNET_malloc (GNUNET_HELLO_size (hello)); |
715 | memcpy ((*dest), hello, GNUNET_HELLO_size (hello)); | 720 | memcpy ((*dest), hello, GNUNET_HELLO_size (hello)); |
716 | } | 721 | } |
717 | else | 722 | else |
@@ -733,84 +738,83 @@ update_hello (const struct GNUNET_PeerIdentity *peer, | |||
733 | 738 | ||
734 | if ((NULL != (host->hello)) && (GNUNET_NO == friend_hello_type)) | 739 | if ((NULL != (host->hello)) && (GNUNET_NO == friend_hello_type)) |
735 | { | 740 | { |
736 | /* Update friend only hello */ | 741 | /* Update friend only hello */ |
737 | mrg = update_friend_hello (host->hello, host->friend_only_hello); | 742 | mrg = update_friend_hello (host->hello, host->friend_only_hello); |
738 | if (NULL != host->friend_only_hello) | 743 | if (NULL != host->friend_only_hello) |
739 | GNUNET_free (host->friend_only_hello); | 744 | GNUNET_free (host->friend_only_hello); |
740 | host->friend_only_hello = mrg; | 745 | host->friend_only_hello = mrg; |
741 | } | 746 | } |
742 | 747 | ||
743 | if (NULL != host->hello) | 748 | if (NULL != host->hello) |
744 | GNUNET_assert ((GNUNET_NO == GNUNET_HELLO_is_friend_only (host->hello))); | 749 | GNUNET_assert ((GNUNET_NO == GNUNET_HELLO_is_friend_only (host->hello))); |
745 | if (NULL != host->friend_only_hello) | 750 | if (NULL != host->friend_only_hello) |
746 | GNUNET_assert ((GNUNET_YES == GNUNET_HELLO_is_friend_only(host->friend_only_hello))); | 751 | GNUNET_assert ((GNUNET_YES == GNUNET_HELLO_is_friend_only(host->friend_only_hello))); |
747 | 752 | ||
748 | store_hello = GNUNET_NO; | 753 | store_hello = GNUNET_NO; |
749 | store_friend_hello = GNUNET_NO; | 754 | store_friend_hello = GNUNET_NO; |
750 | fn = get_host_filename (peer); | 755 | fn = get_host_filename (peer); |
751 | if ( (NULL != fn) && | 756 | if ( (NULL != fn) && |
752 | (GNUNET_OK == GNUNET_DISK_directory_create_for_file (fn)) ) | 757 | (GNUNET_OK == GNUNET_DISK_directory_create_for_file (fn)) ) |
753 | { | 758 | { |
754 | 759 | store_hello = GNUNET_NO; | |
755 | store_hello = GNUNET_NO; | 760 | size = 0; |
756 | size = 0; | 761 | cnt = 0; |
757 | cnt = 0; | 762 | if (NULL != host->hello) |
758 | if (NULL != host->hello) | 763 | (void) GNUNET_HELLO_iterate_addresses (host->hello, |
759 | (void) GNUNET_HELLO_iterate_addresses (host->hello, | 764 | GNUNET_NO, &count_addresses, &cnt); |
760 | GNUNET_NO, &count_addresses, &cnt); | 765 | if (cnt > 0) |
761 | if (cnt > 0) | 766 | { |
762 | { | 767 | store_hello = GNUNET_YES; |
763 | store_hello = GNUNET_YES; | 768 | size += GNUNET_HELLO_size (host->hello); |
764 | size += GNUNET_HELLO_size (host->hello); | 769 | } |
765 | } | 770 | cnt = 0; |
766 | cnt = 0; | 771 | if (NULL != host->friend_only_hello) |
767 | if (NULL != host->friend_only_hello) | 772 | (void) GNUNET_HELLO_iterate_addresses (host->friend_only_hello, GNUNET_NO, |
768 | (void) GNUNET_HELLO_iterate_addresses (host->friend_only_hello, GNUNET_NO, | 773 | &count_addresses, &cnt); |
769 | &count_addresses, &cnt); | 774 | if (0 < cnt) |
770 | if (0 < cnt) | 775 | { |
771 | { | 776 | store_friend_hello = GNUNET_YES; |
772 | store_friend_hello = GNUNET_YES; | 777 | size += GNUNET_HELLO_size (host->friend_only_hello); |
773 | size += GNUNET_HELLO_size (host->friend_only_hello); | 778 | } |
774 | } | 779 | |
775 | 780 | if ((GNUNET_NO == store_hello) && (GNUNET_NO == store_friend_hello)) | |
776 | if ((GNUNET_NO == store_hello) && (GNUNET_NO == store_friend_hello)) | 781 | { |
777 | { | 782 | /* no valid addresses, don't put HELLO on disk; in fact, |
778 | /* no valid addresses, don't put HELLO on disk; in fact, | 783 | if one exists on disk, remove it */ |
779 | if one exists on disk, remove it */ | 784 | (void) UNLINK (fn); |
780 | (void) UNLINK (fn); | 785 | } |
781 | } | 786 | else |
782 | else | 787 | { |
783 | { | 788 | buffer = GNUNET_malloc (size); |
784 | buffer = GNUNET_malloc (size); | 789 | pos = 0; |
785 | pos = 0; | 790 | |
786 | 791 | if (GNUNET_YES == store_hello) | |
787 | if (GNUNET_YES == store_hello) | 792 | { |
788 | { | 793 | memcpy (buffer, host->hello, GNUNET_HELLO_size (host->hello)); |
789 | memcpy (buffer, host->hello, GNUNET_HELLO_size (host->hello)); | 794 | pos += GNUNET_HELLO_size (host->hello); |
790 | pos += GNUNET_HELLO_size (host->hello); | 795 | } |
791 | } | 796 | if (GNUNET_YES == store_friend_hello) |
792 | if (GNUNET_YES == store_friend_hello) | 797 | { |
793 | { | 798 | memcpy (&buffer[pos], host->friend_only_hello, GNUNET_HELLO_size (host->friend_only_hello)); |
794 | memcpy (&buffer[pos], host->friend_only_hello, GNUNET_HELLO_size (host->friend_only_hello)); | 799 | pos += GNUNET_HELLO_size (host->friend_only_hello); |
795 | pos += GNUNET_HELLO_size (host->friend_only_hello); | 800 | } |
796 | } | 801 | GNUNET_assert (pos == size); |
797 | GNUNET_assert (pos == size); | 802 | |
798 | 803 | if (GNUNET_SYSERR == GNUNET_DISK_fn_write (fn, buffer, size, | |
799 | if (GNUNET_SYSERR == GNUNET_DISK_fn_write (fn, buffer, size, | 804 | GNUNET_DISK_PERM_USER_READ | |
800 | GNUNET_DISK_PERM_USER_READ | | 805 | GNUNET_DISK_PERM_USER_WRITE | |
801 | GNUNET_DISK_PERM_USER_WRITE | | 806 | GNUNET_DISK_PERM_GROUP_READ | |
802 | GNUNET_DISK_PERM_GROUP_READ | | 807 | GNUNET_DISK_PERM_OTHER_READ)) |
803 | GNUNET_DISK_PERM_OTHER_READ)) | 808 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn); |
804 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn); | 809 | else |
805 | else | 810 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stored %s %s HELLO in %s with total size %u\n", |
806 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stored %s %s HELLO in %s with total size %u\n", | 811 | (GNUNET_YES == store_friend_hello) ? "friend-only": "", |
807 | (GNUNET_YES == store_friend_hello) ? "friend-only": "", | 812 | (GNUNET_YES == store_hello) ? "public": "", |
808 | (GNUNET_YES == store_hello) ? "public": "", | 813 | fn, size); |
809 | fn, size); | 814 | GNUNET_free (buffer); |
810 | GNUNET_free (buffer); | 815 | } |
811 | } | ||
812 | } | 816 | } |
813 | GNUNET_free_non_null (fn); | 817 | GNUNET_free_non_null (fn); |
814 | notify_all (host); | 818 | notify_all (host); |
815 | } | 819 | } |
816 | 820 | ||
@@ -907,31 +911,31 @@ discard_hosts_helper (void *cls, const char *fn) | |||
907 | write_pos = 0; | 911 | write_pos = 0; |
908 | while (read_pos < read_size) | 912 | while (read_pos < read_size) |
909 | { | 913 | { |
910 | /* Check each HELLO */ | 914 | /* Check each HELLO */ |
911 | hello = (const struct GNUNET_HELLO_Message *) &buffer[read_pos]; | 915 | hello = (const struct GNUNET_HELLO_Message *) &buffer[read_pos]; |
912 | cur_hello_size = GNUNET_HELLO_size (hello); | 916 | cur_hello_size = GNUNET_HELLO_size (hello); |
913 | new_hello_size = 0; | 917 | new_hello_size = 0; |
914 | if (0 == cur_hello_size) | 918 | if (0 == cur_hello_size) |
915 | { | 919 | { |
916 | /* Invalid data, discard */ | 920 | /* Invalid data, discard */ |
917 | if (0 != UNLINK (fn)) | 921 | if (0 != UNLINK (fn)) |
918 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | | 922 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | |
919 | GNUNET_ERROR_TYPE_BULK, "unlink", fn); | 923 | GNUNET_ERROR_TYPE_BULK, "unlink", fn); |
920 | return GNUNET_OK; | 924 | return GNUNET_OK; |
921 | } | 925 | } |
922 | new_hello = GNUNET_HELLO_iterate_addresses (hello, GNUNET_YES, &discard_expired, now); | 926 | new_hello = GNUNET_HELLO_iterate_addresses (hello, GNUNET_YES, &discard_expired, now); |
923 | cnt = 0; | 927 | cnt = 0; |
924 | if (NULL != new_hello) | 928 | if (NULL != new_hello) |
925 | (void) GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &count_addresses, &cnt); | 929 | (void) GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &count_addresses, &cnt); |
926 | if ( (NULL != new_hello) && (0 < cnt) ) | 930 | if ( (NULL != new_hello) && (0 < cnt) ) |
927 | { | 931 | { |
928 | /* Store new HELLO to write it when done */ | 932 | /* Store new HELLO to write it when done */ |
929 | new_hello_size = GNUNET_HELLO_size(new_hello); | 933 | new_hello_size = GNUNET_HELLO_size(new_hello); |
930 | memcpy (&writebuffer[write_pos], new_hello, new_hello_size); | 934 | memcpy (&writebuffer[write_pos], new_hello, new_hello_size); |
931 | write_pos += new_hello_size; | 935 | write_pos += new_hello_size; |
932 | } | 936 | } |
933 | read_pos += cur_hello_size; | 937 | read_pos += cur_hello_size; |
934 | GNUNET_free_non_null (new_hello); | 938 | GNUNET_free_non_null (new_hello); |
935 | } | 939 | } |
936 | 940 | ||
937 | if (0 < write_pos) | 941 | if (0 < write_pos) |
@@ -1068,28 +1072,28 @@ handle_get_all (void *cls, struct GNUNET_SERVER_Client *client, | |||
1068 | static int | 1072 | static int |
1069 | do_notify_entry (void *cls, const struct GNUNET_HashCode * key, void *value) | 1073 | do_notify_entry (void *cls, const struct GNUNET_HashCode * key, void *value) |
1070 | { | 1074 | { |
1071 | struct NotificationContext *nc = cls; | 1075 | struct NotificationContext *nc = cls; |
1072 | struct HostEntry *he = value; | 1076 | struct HostEntry *he = value; |
1073 | struct InfoMessage *msg; | 1077 | struct InfoMessage *msg; |
1074 | 1078 | ||
1075 | if ((NULL == he->hello) && (GNUNET_NO == nc->include_friend_only)) | 1079 | if ((NULL == he->hello) && (GNUNET_NO == nc->include_friend_only)) |
1076 | { | 1080 | { |
1077 | /* We have no public hello */ | 1081 | /* We have no public hello */ |
1078 | return GNUNET_YES; | 1082 | return GNUNET_YES; |
1079 | } | 1083 | } |
1080 | 1084 | ||
1081 | 1085 | if ( (NULL == he->friend_only_hello) && | |
1082 | if ((NULL == he->friend_only_hello) && GNUNET_YES == nc->include_friend_only) | 1086 | (GNUNET_YES == nc->include_friend_only) ) |
1083 | { | 1087 | { |
1084 | /* We have no friend hello */ | 1088 | /* We have no friend hello */ |
1085 | return GNUNET_YES; | 1089 | return GNUNET_YES; |
1086 | } | 1090 | } |
1087 | 1091 | ||
1088 | msg = make_info_message (he, nc->include_friend_only); | 1092 | msg = make_info_message (he, nc->include_friend_only); |
1089 | GNUNET_SERVER_notification_context_unicast (notify_list, | 1093 | GNUNET_SERVER_notification_context_unicast (notify_list, |
1090 | nc->client, | 1094 | nc->client, |
1091 | &msg->header, | 1095 | &msg->header, |
1092 | GNUNET_NO); | 1096 | GNUNET_NO); |
1093 | GNUNET_free (msg); | 1097 | GNUNET_free (msg); |
1094 | return GNUNET_YES; | 1098 | return GNUNET_YES; |
1095 | } | 1099 | } |
@@ -1109,13 +1113,14 @@ handle_notify (void *cls, struct GNUNET_SERVER_Client *client, | |||
1109 | struct NotifyMessage *nm = (struct NotifyMessage *) message; | 1113 | struct NotifyMessage *nm = (struct NotifyMessage *) message; |
1110 | struct NotificationContext *nc; | 1114 | struct NotificationContext *nc; |
1111 | 1115 | ||
1112 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received\n", "NOTIFY"); | 1116 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1113 | 1117 | "`%s' message received\n", | |
1114 | nc = GNUNET_malloc (sizeof (struct NotificationContext)); | 1118 | "NOTIFY"); |
1115 | nc->client = client; | 1119 | nc = GNUNET_malloc (sizeof (struct NotificationContext)); |
1116 | nc->include_friend_only = ntohl (nm->include_friend_only); | 1120 | nc->client = client; |
1117 | 1121 | nc->include_friend_only = ntohl (nm->include_friend_only); | |
1118 | GNUNET_CONTAINER_DLL_insert (nc_head, nc_tail, nc); | 1122 | |
1123 | GNUNET_CONTAINER_DLL_insert (nc_head, nc_tail, nc); | ||
1119 | GNUNET_SERVER_client_mark_monitor (client); | 1124 | GNUNET_SERVER_client_mark_monitor (client); |
1120 | GNUNET_SERVER_notification_context_add (notify_list, client); | 1125 | GNUNET_SERVER_notification_context_add (notify_list, client); |
1121 | GNUNET_CONTAINER_multihashmap_iterate (hostmap, &do_notify_entry, nc); | 1126 | GNUNET_CONTAINER_multihashmap_iterate (hostmap, &do_notify_entry, nc); |
@@ -1129,19 +1134,18 @@ handle_notify (void *cls, struct GNUNET_SERVER_Client *client, | |||
1129 | * @param cls unused | 1134 | * @param cls unused |
1130 | * @param client server client | 1135 | * @param client server client |
1131 | */ | 1136 | */ |
1132 | static void disconnect_cb (void *cls,struct GNUNET_SERVER_Client *client) | 1137 | static void |
1138 | disconnect_cb (void *cls,struct GNUNET_SERVER_Client *client) | ||
1133 | { | 1139 | { |
1134 | struct NotificationContext *cur; | 1140 | struct NotificationContext *cur; |
1135 | |||
1136 | for (cur = nc_head; NULL != cur; cur = cur->next) | ||
1137 | if (cur->client == client) | ||
1138 | break; | ||
1139 | |||
1140 | if (NULL == cur) | ||
1141 | return; | ||
1142 | 1141 | ||
1143 | GNUNET_CONTAINER_DLL_remove (nc_head, nc_tail, cur); | 1142 | for (cur = nc_head; NULL != cur; cur = cur->next) |
1144 | GNUNET_free (cur); | 1143 | if (cur->client == client) |
1144 | break; | ||
1145 | if (NULL == cur) | ||
1146 | return; | ||
1147 | GNUNET_CONTAINER_DLL_remove (nc_head, nc_tail, cur); | ||
1148 | GNUNET_free (cur); | ||
1145 | } | 1149 | } |
1146 | 1150 | ||
1147 | 1151 | ||