diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/peerinfo/gnunet-service-peerinfo.c | 108 |
1 files changed, 71 insertions, 37 deletions
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c index c4131ffc9..06ab9da8e 100644 --- a/src/peerinfo/gnunet-service-peerinfo.c +++ b/src/peerinfo/gnunet-service-peerinfo.c | |||
@@ -144,7 +144,7 @@ static struct GNUNET_CONTAINER_MultiHashMap *hostmap; | |||
144 | static struct GNUNET_SERVER_NotificationContext *notify_list; | 144 | static struct GNUNET_SERVER_NotificationContext *notify_list; |
145 | 145 | ||
146 | /** | 146 | /** |
147 | * Directory where the hellos are stored in (data/hosts) | 147 | * Directory where the hellos are stored in (peerinfo/) |
148 | */ | 148 | */ |
149 | static char *networkIdDirectory; | 149 | static char *networkIdDirectory; |
150 | 150 | ||
@@ -330,6 +330,7 @@ read_host_file (const char *fn, int unlink_garbage, struct ReadHostFileContext * | |||
330 | return; | 330 | return; |
331 | 331 | ||
332 | size_total = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer)); | 332 | size_total = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer)); |
333 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Read %u bytes from `%s'\n", size_total, fn); | ||
333 | if (size_total < sizeof (struct GNUNET_MessageHeader)) | 334 | if (size_total < sizeof (struct GNUNET_MessageHeader)) |
334 | { | 335 | { |
335 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 336 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -341,17 +342,25 @@ read_host_file (const char *fn, int unlink_garbage, struct ReadHostFileContext * | |||
341 | } | 342 | } |
342 | 343 | ||
343 | hello_1st = (const struct GNUNET_HELLO_Message *) buffer; | 344 | hello_1st = (const struct GNUNET_HELLO_Message *) buffer; |
344 | size_1st = ntohs (((const struct GNUNET_MessageHeader *) hello_1st)->size); | 345 | size_1st = ntohs (((struct GNUNET_MessageHeader *) &buffer)->size); |
345 | if ((size_1st < sizeof (struct GNUNET_MessageHeader)) || | 346 | if (size_1st < sizeof (struct GNUNET_MessageHeader)) |
346 | (size_1st != GNUNET_HELLO_size (hello_1st))) | ||
347 | { | 347 | { |
348 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 348 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
349 | _("Failed to parse HELLO in file `%s': %s\n"), | 349 | _("Failed to parse HELLO in file `%s': %s %u \n"), |
350 | fn, "1nd HELLO has wrong size"); | 350 | fn, "1st HELLO has invalid size of ", size_1st); |
351 | if ((GNUNET_YES == unlink_garbage) && (0 != UNLINK (fn))) | 351 | if ((GNUNET_YES == unlink_garbage) && (0 != UNLINK (fn))) |
352 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | 352 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); |
353 | return; | 353 | return; |
354 | } | 354 | } |
355 | if (size_1st != GNUNET_HELLO_size (hello_1st)) | ||
356 | { | ||
357 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
358 | _("Failed to parse HELLO in file `%s': %s \n"), | ||
359 | fn, "1st HELLO is invalid"); | ||
360 | if ((GNUNET_YES == unlink_garbage) && (0 != UNLINK (fn))) | ||
361 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | ||
362 | return; | ||
363 | } | ||
355 | 364 | ||
356 | if (size_total > size_1st) | 365 | if (size_total > size_1st) |
357 | { | 366 | { |
@@ -412,7 +421,7 @@ read_host_file (const char *fn, int unlink_garbage, struct ReadHostFileContext * | |||
412 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | 421 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); |
413 | } | 422 | } |
414 | 423 | ||
415 | if (GNUNET_NO == GNUNET_HELLO_is_friend_only(hello_clean_2nd)) | 424 | if (GNUNET_NO == GNUNET_HELLO_is_friend_only (hello_clean_2nd)) |
416 | r->hello = hello_clean_2nd; | 425 | r->hello = hello_clean_2nd; |
417 | else | 426 | else |
418 | r->friend_only_hello = hello_clean_2nd; | 427 | r->friend_only_hello = hello_clean_2nd; |
@@ -441,12 +450,13 @@ add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity) | |||
441 | entry->identity = *identity; | 450 | entry->identity = *identity; |
442 | GNUNET_CONTAINER_multihashmap_put (hostmap, &entry->identity.hashPubKey, entry, | 451 | GNUNET_CONTAINER_multihashmap_put (hostmap, &entry->identity.hashPubKey, entry, |
443 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 452 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
453 | |||
444 | fn = get_host_filename (identity); | 454 | fn = get_host_filename (identity); |
445 | if (NULL != fn) | 455 | if (NULL != fn) |
446 | { | 456 | { |
447 | read_host_file (fn, GNUNET_YES, &r); | 457 | read_host_file (fn, GNUNET_YES, &r); |
448 | entry->hello = r.hello; | 458 | entry->hello = r.hello; |
449 | entry->hello = r.friend_only_hello; | 459 | entry->friend_only_hello = r.friend_only_hello; |
450 | GNUNET_free (fn); | 460 | GNUNET_free (fn); |
451 | } | 461 | } |
452 | notify_all (entry); | 462 | notify_all (entry); |
@@ -515,31 +525,35 @@ hosts_directory_scan_callback (void *cls, const char *fullname) | |||
515 | 525 | ||
516 | if (GNUNET_YES != GNUNET_DISK_file_test (fullname)) | 526 | if (GNUNET_YES != GNUNET_DISK_file_test (fullname)) |
517 | return GNUNET_OK; /* ignore non-files */ | 527 | return GNUNET_OK; /* ignore non-files */ |
518 | if (strlen (fullname) < sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) | 528 | |
519 | { | 529 | filename = fullname; |
520 | if (GNUNET_YES == dsc->remove_files) | 530 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reading `%s'\n", filename); |
521 | remove_garbage (fullname); | 531 | |
522 | return GNUNET_OK; | 532 | if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (filename, &identity.hashPubKey)) |
523 | } | ||
524 | filename = | ||
525 | &fullname[strlen (fullname) - | ||
526 | sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1]; | ||
527 | if (DIR_SEPARATOR != filename[-1]) | ||
528 | { | ||
529 | if (GNUNET_YES == dsc->remove_files) | ||
530 | remove_garbage (fullname); | ||
531 | return GNUNET_OK; | ||
532 | } | ||
533 | if (GNUNET_OK != | ||
534 | GNUNET_CRYPTO_hash_from_string (filename, &identity.hashPubKey)) | ||
535 | { | 533 | { |
536 | /* odd filename, but might still be valid, try getting identity from HELLO */ | 534 | /* odd filename, but might still be valid, try getting identity from HELLO */ |
537 | read_host_file (filename, dsc->remove_files, &r); | 535 | read_host_file (filename, dsc->remove_files, &r); |
538 | if ( ((NULL != r.hello) && | 536 | if ( (NULL != r.hello)|| (NULL != r.friend_only_hello) ) |
539 | (GNUNET_OK == GNUNET_HELLO_get_id (r.hello, &id_public))) || | ||
540 | ((NULL != r.friend_only_hello) && | ||
541 | (GNUNET_OK == GNUNET_HELLO_get_id (r.friend_only_hello, &id_friend))) ) | ||
542 | { | 537 | { |
538 | if (NULL != r.friend_only_hello) | ||
539 | { | ||
540 | if (GNUNET_OK != GNUNET_HELLO_get_id (r.friend_only_hello, &id_friend)) | ||
541 | if (GNUNET_YES == dsc->remove_files) | ||
542 | { | ||
543 | remove_garbage (fullname); | ||
544 | return GNUNET_OK; | ||
545 | } | ||
546 | } | ||
547 | if (NULL != r.hello) | ||
548 | { | ||
549 | if (GNUNET_OK != GNUNET_HELLO_get_id (r.hello, &id_public)) | ||
550 | if (GNUNET_YES == dsc->remove_files) | ||
551 | { | ||
552 | remove_garbage (fullname); | ||
553 | return GNUNET_OK; | ||
554 | } | ||
555 | } | ||
556 | |||
543 | if ( (NULL != r.hello) && (NULL != r.friend_only_hello) && | 557 | if ( (NULL != r.hello) && (NULL != r.friend_only_hello) && |
544 | (0 != memcmp (&id_friend, &id_public, sizeof (id_friend))) ) | 558 | (0 != memcmp (&id_friend, &id_public, sizeof (id_friend))) ) |
545 | { | 559 | { |
@@ -556,10 +570,13 @@ hosts_directory_scan_callback (void *cls, const char *fullname) | |||
556 | GNUNET_CONTAINER_multihashmap_put (hostmap, &entry->identity.hashPubKey, entry, | 570 | GNUNET_CONTAINER_multihashmap_put (hostmap, &entry->identity.hashPubKey, entry, |
557 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 571 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
558 | entry->hello = r.hello; | 572 | entry->hello = r.hello; |
559 | entry->hello = r.friend_only_hello; | 573 | entry->friend_only_hello = r.friend_only_hello; |
560 | notify_all (entry); | 574 | notify_all (entry); |
561 | dsc->matched++; | 575 | dsc->matched++; |
562 | 576 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found %s %s HELLO for peer `%s'\n", | |
577 | (NULL != r.hello) ? "public" : "", | ||
578 | (NULL != r.friend_only_hello) ? "friend-only" : "", | ||
579 | GNUNET_i2s (&entry->identity)); | ||
563 | return GNUNET_OK; | 580 | return GNUNET_OK; |
564 | } | 581 | } |
565 | if (GNUNET_YES == dsc->remove_files) | 582 | if (GNUNET_YES == dsc->remove_files) |
@@ -657,7 +674,11 @@ bind_address (const struct GNUNET_PeerIdentity *peer, | |||
657 | add_host_to_known_hosts (peer); | 674 | add_host_to_known_hosts (peer); |
658 | host = GNUNET_CONTAINER_multihashmap_get (hostmap, &peer->hashPubKey); | 675 | host = GNUNET_CONTAINER_multihashmap_get (hostmap, &peer->hashPubKey); |
659 | GNUNET_assert (NULL != host); | 676 | GNUNET_assert (NULL != host); |
677 | |||
660 | friend_hello_type = GNUNET_HELLO_is_friend_only (hello); | 678 | friend_hello_type = GNUNET_HELLO_is_friend_only (hello); |
679 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %s HELLO for `%s'\n", | ||
680 | (GNUNET_YES == friend_hello_type) ? "friend-only" : "public", | ||
681 | GNUNET_i2s (peer)); | ||
661 | 682 | ||
662 | dest = NULL; | 683 | dest = NULL; |
663 | if (GNUNET_YES == friend_hello_type) | 684 | if (GNUNET_YES == friend_hello_type) |
@@ -691,6 +712,11 @@ bind_address (const struct GNUNET_PeerIdentity *peer, | |||
691 | if ((NULL != (host->hello)) && (GNUNET_NO == friend_hello_type)) | 712 | if ((NULL != (host->hello)) && (GNUNET_NO == friend_hello_type)) |
692 | host->friend_only_hello = update_friend_hello (host->hello, host->friend_only_hello); | 713 | host->friend_only_hello = update_friend_hello (host->hello, host->friend_only_hello); |
693 | 714 | ||
715 | if (NULL != host->hello) | ||
716 | GNUNET_assert ((GNUNET_NO == GNUNET_HELLO_is_friend_only (host->hello))); | ||
717 | if (NULL != host->friend_only_hello) | ||
718 | GNUNET_assert ((GNUNET_YES == GNUNET_HELLO_is_friend_only(host->friend_only_hello))); | ||
719 | |||
694 | fn = get_host_filename (peer); | 720 | fn = get_host_filename (peer); |
695 | if ( (NULL != fn) && | 721 | if ( (NULL != fn) && |
696 | (GNUNET_OK == GNUNET_DISK_directory_create_for_file (fn)) ) | 722 | (GNUNET_OK == GNUNET_DISK_directory_create_for_file (fn)) ) |
@@ -704,7 +730,6 @@ bind_address (const struct GNUNET_PeerIdentity *peer, | |||
704 | GNUNET_NO, &count_addresses, &cnt); | 730 | GNUNET_NO, &count_addresses, &cnt); |
705 | if (cnt > 0) | 731 | if (cnt > 0) |
706 | { | 732 | { |
707 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Store HELLO in `%s'\n", fn); | ||
708 | store_hello = GNUNET_YES; | 733 | store_hello = GNUNET_YES; |
709 | size += GNUNET_HELLO_size (host->hello); | 734 | size += GNUNET_HELLO_size (host->hello); |
710 | } | 735 | } |
@@ -712,9 +737,8 @@ bind_address (const struct GNUNET_PeerIdentity *peer, | |||
712 | if (NULL != host->friend_only_hello) | 737 | if (NULL != host->friend_only_hello) |
713 | (void) GNUNET_HELLO_iterate_addresses (host->friend_only_hello, GNUNET_NO, | 738 | (void) GNUNET_HELLO_iterate_addresses (host->friend_only_hello, GNUNET_NO, |
714 | &count_addresses, &cnt); | 739 | &count_addresses, &cnt); |
715 | if (0 <= cnt) | 740 | if (0 < cnt) |
716 | { | 741 | { |
717 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Store Friend HELLO in %s\n", fn); | ||
718 | store_friend_hello = GNUNET_YES; | 742 | store_friend_hello = GNUNET_YES; |
719 | size += GNUNET_HELLO_size (host->friend_only_hello); | 743 | size += GNUNET_HELLO_size (host->friend_only_hello); |
720 | } | 744 | } |
@@ -748,7 +772,11 @@ bind_address (const struct GNUNET_PeerIdentity *peer, | |||
748 | GNUNET_DISK_PERM_GROUP_READ | | 772 | GNUNET_DISK_PERM_GROUP_READ | |
749 | GNUNET_DISK_PERM_OTHER_READ)) | 773 | GNUNET_DISK_PERM_OTHER_READ)) |
750 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn); | 774 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn); |
751 | 775 | else | |
776 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stored %s %s HELLO in %s with total size %u\n", | ||
777 | (GNUNET_YES == store_friend_hello) ? "friend-only": "", | ||
778 | (GNUNET_YES == store_hello) ? "public": "", | ||
779 | fn, size); | ||
752 | GNUNET_free (buffer); | 780 | GNUNET_free (buffer); |
753 | } | 781 | } |
754 | } | 782 | } |
@@ -1135,22 +1163,28 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
1135 | "HOSTS", | 1163 | "HOSTS", |
1136 | &networkIdDirectory)); | 1164 | &networkIdDirectory)); |
1137 | GNUNET_DISK_directory_create (networkIdDirectory); | 1165 | GNUNET_DISK_directory_create (networkIdDirectory); |
1166 | |||
1138 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, | 1167 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, |
1139 | &cron_scan_directory_data_hosts, NULL); /* CHECK */ | 1168 | &cron_scan_directory_data_hosts, NULL); /* CHECK */ |
1140 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, | 1169 | |
1141 | &cron_clean_data_hosts, NULL); /* CHECK */ | 1170 | // GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, |
1171 | // &cron_clean_data_hosts, NULL); /* CHECK */ | ||
1172 | |||
1142 | ip = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR); | 1173 | ip = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR); |
1143 | GNUNET_asprintf (&peerdir, | 1174 | GNUNET_asprintf (&peerdir, |
1144 | "%shellos", | 1175 | "%shellos", |
1145 | ip); | 1176 | ip); |
1146 | GNUNET_free (ip); | 1177 | GNUNET_free (ip); |
1178 | |||
1147 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1179 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1148 | _("Importing HELLOs from `%s'\n"), | 1180 | _("Importing HELLOs from `%s'\n"), |
1149 | peerdir); | 1181 | peerdir); |
1150 | dsc.matched = 0; | 1182 | dsc.matched = 0; |
1151 | dsc.remove_files = GNUNET_NO; | 1183 | dsc.remove_files = GNUNET_NO; |
1184 | |||
1152 | GNUNET_DISK_directory_scan (peerdir, | 1185 | GNUNET_DISK_directory_scan (peerdir, |
1153 | &hosts_directory_scan_callback, &dsc); | 1186 | &hosts_directory_scan_callback, &dsc); |
1187 | |||
1154 | GNUNET_free (peerdir); | 1188 | GNUNET_free (peerdir); |
1155 | } | 1189 | } |
1156 | GNUNET_SERVER_add_handlers (server, handlers); | 1190 | GNUNET_SERVER_add_handlers (server, handlers); |