diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-04-09 12:08:58 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-04-09 12:08:58 +0000 |
commit | 02e5060f18eba19252673555b0c0fbb5d996df1a (patch) | |
tree | ed84d24208bd3ed15fce0d5316a25ac9b3c723c3 /src | |
parent | 9745cb16ac9fc3a3e49ffdba3d9ae72797262c63 (diff) | |
download | gnunet-02e5060f18eba19252673555b0c0fbb5d996df1a.tar.gz gnunet-02e5060f18eba19252673555b0c0fbb5d996df1a.zip |
store 2 hellos
Diffstat (limited to 'src')
-rw-r--r-- | src/peerinfo/gnunet-service-peerinfo.c | 66 |
1 files changed, 52 insertions, 14 deletions
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c index 32e50f348..c4131ffc9 100644 --- a/src/peerinfo/gnunet-service-peerinfo.c +++ b/src/peerinfo/gnunet-service-peerinfo.c | |||
@@ -647,7 +647,12 @@ bind_address (const struct GNUNET_PeerIdentity *peer, | |||
647 | struct GNUNET_HELLO_Message **dest; | 647 | struct GNUNET_HELLO_Message **dest; |
648 | struct GNUNET_TIME_Absolute delta; | 648 | struct GNUNET_TIME_Absolute delta; |
649 | unsigned int cnt; | 649 | unsigned int cnt; |
650 | unsigned int size; | ||
650 | int friend_hello_type; | 651 | int friend_hello_type; |
652 | int store_hello; | ||
653 | int store_friend_hello; | ||
654 | int pos; | ||
655 | char *buffer; | ||
651 | 656 | ||
652 | add_host_to_known_hosts (peer); | 657 | add_host_to_known_hosts (peer); |
653 | host = GNUNET_CONTAINER_multihashmap_get (hostmap, &peer->hashPubKey); | 658 | host = GNUNET_CONTAINER_multihashmap_get (hostmap, &peer->hashPubKey); |
@@ -690,31 +695,64 @@ bind_address (const struct GNUNET_PeerIdentity *peer, | |||
690 | if ( (NULL != fn) && | 695 | if ( (NULL != fn) && |
691 | (GNUNET_OK == GNUNET_DISK_directory_create_for_file (fn)) ) | 696 | (GNUNET_OK == GNUNET_DISK_directory_create_for_file (fn)) ) |
692 | { | 697 | { |
693 | #if 0 | 698 | |
699 | store_hello = GNUNET_NO; | ||
700 | size = 0; | ||
694 | cnt = 0; | 701 | cnt = 0; |
695 | (void) GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &count_addresses, | 702 | if (NULL != host->hello) |
696 | &cnt); | 703 | (void) GNUNET_HELLO_iterate_addresses (host->hello, |
697 | if (0 == cnt) | 704 | GNUNET_NO, &count_addresses, &cnt); |
705 | if (cnt > 0) | ||
706 | { | ||
707 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Store HELLO in `%s'\n", fn); | ||
708 | store_hello = GNUNET_YES; | ||
709 | size += GNUNET_HELLO_size (host->hello); | ||
710 | } | ||
711 | cnt = 0; | ||
712 | if (NULL != host->friend_only_hello) | ||
713 | (void) GNUNET_HELLO_iterate_addresses (host->friend_only_hello, GNUNET_NO, | ||
714 | &count_addresses, &cnt); | ||
715 | if (0 <= cnt) | ||
716 | { | ||
717 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Store Friend HELLO in %s\n", fn); | ||
718 | store_friend_hello = GNUNET_YES; | ||
719 | size += GNUNET_HELLO_size (host->friend_only_hello); | ||
720 | } | ||
721 | |||
722 | if ((GNUNET_NO == store_hello) && (GNUNET_NO == store_friend_hello)) | ||
698 | { | 723 | { |
699 | /* no valid addresses, don't put HELLO on disk; in fact, | 724 | /* no valid addresses, don't put HELLO on disk; in fact, |
700 | if one exists on disk, remove it */ | 725 | if one exists on disk, remove it */ |
701 | (void) UNLINK (fn); | 726 | (void) UNLINK (fn); |
702 | } | 727 | } |
703 | else | 728 | else |
704 | { | 729 | { |
705 | if (GNUNET_SYSERR == | 730 | buffer = GNUNET_malloc (size); |
706 | GNUNET_DISK_fn_write (fn, host->hello, GNUNET_HELLO_size (host->hello), | 731 | pos = 0; |
732 | |||
733 | if (GNUNET_YES == store_hello) | ||
734 | { | ||
735 | memcpy (buffer, host->hello, GNUNET_HELLO_size (host->hello)); | ||
736 | pos += GNUNET_HELLO_size (host->hello); | ||
737 | } | ||
738 | if (GNUNET_YES == store_friend_hello) | ||
739 | { | ||
740 | memcpy (&buffer[pos], host->friend_only_hello, GNUNET_HELLO_size (host->friend_only_hello)); | ||
741 | pos += GNUNET_HELLO_size (host->friend_only_hello); | ||
742 | } | ||
743 | GNUNET_assert (pos == size); | ||
744 | |||
745 | if (GNUNET_SYSERR == GNUNET_DISK_fn_write (fn, buffer, size, | ||
707 | GNUNET_DISK_PERM_USER_READ | | 746 | GNUNET_DISK_PERM_USER_READ | |
708 | GNUNET_DISK_PERM_USER_WRITE | | 747 | GNUNET_DISK_PERM_USER_WRITE | |
709 | GNUNET_DISK_PERM_GROUP_READ | | 748 | GNUNET_DISK_PERM_GROUP_READ | |
710 | GNUNET_DISK_PERM_OTHER_READ)) | 749 | GNUNET_DISK_PERM_OTHER_READ)) |
711 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn); | 750 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn); |
751 | |||
752 | GNUNET_free (buffer); | ||
712 | } | 753 | } |
713 | } | ||
714 | #endif | ||
715 | GNUNET_free_non_null (fn); | ||
716 | } | 754 | } |
717 | 755 | GNUNET_free_non_null (fn); | |
718 | notify_all (host); | 756 | notify_all (host); |
719 | } | 757 | } |
720 | 758 | ||
@@ -1098,9 +1136,9 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
1098 | &networkIdDirectory)); | 1136 | &networkIdDirectory)); |
1099 | GNUNET_DISK_directory_create (networkIdDirectory); | 1137 | GNUNET_DISK_directory_create (networkIdDirectory); |
1100 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, | 1138 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, |
1101 | &cron_scan_directory_data_hosts, NULL); | 1139 | &cron_scan_directory_data_hosts, NULL); /* CHECK */ |
1102 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, | 1140 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, |
1103 | &cron_clean_data_hosts, NULL); | 1141 | &cron_clean_data_hosts, NULL); /* CHECK */ |
1104 | ip = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR); | 1142 | ip = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR); |
1105 | GNUNET_asprintf (&peerdir, | 1143 | GNUNET_asprintf (&peerdir, |
1106 | "%shellos", | 1144 | "%shellos", |