aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-04-09 15:24:42 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-04-09 15:24:42 +0000
commitae9a6cf3069a7ec482f2bb940595e24bdc092ca1 (patch)
tree53ab8b8c9b9cfd8184eea5a60377c334a3631cc6 /src
parentab9c2c3d09929da991d4bf46aeabcd9c8b671762 (diff)
downloadgnunet-ae9a6cf3069a7ec482f2bb940595e24bdc092ca1.tar.gz
gnunet-ae9a6cf3069a7ec482f2bb940595e24bdc092ca1.zip
fixes
Diffstat (limited to 'src')
-rw-r--r--src/peerinfo/gnunet-service-peerinfo.c156
1 files changed, 103 insertions, 53 deletions
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c
index 06ab9da8e..a66dd02e1 100644
--- a/src/peerinfo/gnunet-service-peerinfo.c
+++ b/src/peerinfo/gnunet-service-peerinfo.c
@@ -294,6 +294,17 @@ notify_all (struct HostEntry *entry)
294 294
295 295
296/** 296/**
297 * Bind a host address (hello) to a hostId.
298 *
299 * @param peer the peer for which this is a hello
300 * @param hello the verified (!) hello message
301 */
302static void
303bind_address (const struct GNUNET_PeerIdentity *peer,
304 const struct GNUNET_HELLO_Message *hello);
305
306
307/**
297 * Try to read the HELLOs in the given filename and discard expired 308 * Try to read the HELLOs in the given filename and discard expired
298 * addresses. Removes the file if one the HELLO is mal-formed. If all 309 * addresses. Removes the file if one the HELLO is mal-formed. If all
299 * addresses are expired, the HELLO is also removed (but the HELLO 310 * addresses are expired, the HELLO is also removed (but the HELLO
@@ -330,7 +341,7 @@ read_host_file (const char *fn, int unlink_garbage, struct ReadHostFileContext *
330 return; 341 return;
331 342
332 size_total = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer)); 343 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); 344 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Read %u bytes from `%s'\n", size_total, fn);
334 if (size_total < sizeof (struct GNUNET_MessageHeader)) 345 if (size_total < sizeof (struct GNUNET_MessageHeader))
335 { 346 {
336 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 347 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -389,7 +400,6 @@ read_host_file (const char *fn, int unlink_garbage, struct ReadHostFileContext *
389 } 400 }
390 401
391 now = GNUNET_TIME_absolute_get (); 402 now = GNUNET_TIME_absolute_get ();
392
393 hello_clean_1st = GNUNET_HELLO_iterate_addresses (hello_1st, GNUNET_YES, 403 hello_clean_1st = GNUNET_HELLO_iterate_addresses (hello_1st, GNUNET_YES,
394 &discard_expired, &now); 404 &discard_expired, &now);
395 left = 0; 405 left = 0;
@@ -522,66 +532,103 @@ hosts_directory_scan_callback (void *cls, const char *fullname)
522 struct HostEntry *entry; 532 struct HostEntry *entry;
523 struct GNUNET_PeerIdentity id_public; 533 struct GNUNET_PeerIdentity id_public;
524 struct GNUNET_PeerIdentity id_friend; 534 struct GNUNET_PeerIdentity id_friend;
535 struct GNUNET_PeerIdentity id;
536
537 if (GNUNET_YES != GNUNET_DISK_file_test (fullname))
538 return GNUNET_OK; /* ignore non-files */
525 539
526 if (GNUNET_YES != GNUNET_DISK_file_test (fullname)) 540 if (GNUNET_YES != GNUNET_DISK_file_test (fullname))
527 return GNUNET_OK; /* ignore non-files */ 541 return GNUNET_OK; /* ignore non-files */
528 542
529 filename = fullname; 543 filename = fullname;
530 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reading `%s'\n", filename); 544 filename = strrchr (fullname, DIR_SEPARATOR);
545 if ((NULL == filename) || (1 > strlen (filename)))
546 filename = fullname;
547 else
548 filename ++;
549 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Reading `%s'\n", filename);
531 550
532 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (filename, &identity.hashPubKey)) 551 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (filename, &identity.hashPubKey))
533 { 552 {
553
534 /* odd filename, but might still be valid, try getting identity from HELLO */ 554 /* odd filename, but might still be valid, try getting identity from HELLO */
535 read_host_file (filename, dsc->remove_files, &r); 555 read_host_file (fullname, dsc->remove_files, &r);
536 if ( (NULL != r.hello)|| (NULL != r.friend_only_hello) ) 556 if ( (NULL == r.hello) && (NULL == r.friend_only_hello) )
537 { 557 {
538 if (NULL != r.friend_only_hello) 558 if (GNUNET_YES == dsc->remove_files)
539 { 559 remove_garbage (fullname);
540 if (GNUNET_OK != GNUNET_HELLO_get_id (r.friend_only_hello, &id_friend)) 560 return GNUNET_OK;
541 if (GNUNET_YES == dsc->remove_files) 561 }
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 562
557 if ( (NULL != r.hello) && (NULL != r.friend_only_hello) && 563 if (NULL != r.friend_only_hello)
558 (0 != memcmp (&id_friend, &id_public, sizeof (id_friend))) ) 564 {
559 { 565 if (GNUNET_OK != GNUNET_HELLO_get_id (r.friend_only_hello, &id_friend))
560 /* HELLOs are not for the same peer */
561 GNUNET_break (0);
562 if (GNUNET_YES == dsc->remove_files) 566 if (GNUNET_YES == dsc->remove_files)
567 {
563 remove_garbage (fullname); 568 remove_garbage (fullname);
564 return GNUNET_OK; 569 return GNUNET_OK;
565 } 570 }
571 id = id_friend;
572 }
573 if (NULL != r.hello)
574 {
575 if (GNUNET_OK != GNUNET_HELLO_get_id (r.hello, &id_public))
576 if (GNUNET_YES == dsc->remove_files)
577 {
578 remove_garbage (fullname);
579 return GNUNET_OK;
580 }
581 id = id_public;
582 }
566 583
567 /* ok, found something valid, remember HELLO */ 584 if ( (NULL != r.hello) && (NULL != r.friend_only_hello) &&
568 entry = GNUNET_malloc (sizeof (struct HostEntry)); 585 (0 != memcmp (&id_friend, &id_public, sizeof (id_friend))) )
569 entry->identity = id_friend; 586 {
570 GNUNET_CONTAINER_multihashmap_put (hostmap, &entry->identity.hashPubKey, entry, 587 /* HELLOs are not for the same peer */
571 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 588 GNUNET_break (0);
572 entry->hello = r.hello; 589 if (GNUNET_YES == dsc->remove_files)
573 entry->friend_only_hello = r.friend_only_hello; 590 remove_garbage (fullname);
574 notify_all (entry); 591 return GNUNET_OK;
575 dsc->matched++; 592 }
576 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found %s %s HELLO for peer `%s'\n", 593
577 (NULL != r.hello) ? "public" : "", 594 /* ok, found something valid, remember HELLO */
578 (NULL != r.friend_only_hello) ? "friend-only" : "", 595 entry = GNUNET_CONTAINER_multihashmap_get (hostmap, &id.hashPubKey);
579 GNUNET_i2s (&entry->identity)); 596 if (NULL == entry)
580 return GNUNET_OK; 597 {
581 } 598 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Adding new peer `%s' with %s %s HELLO \n",
582 if (GNUNET_YES == dsc->remove_files) 599 GNUNET_i2s (&entry->identity),
583 remove_garbage (fullname); 600 (NULL != r.hello) ? "public" : "",
584 return GNUNET_OK; 601 (NULL != r.friend_only_hello) ? "friend-only" : "");
602 /* Add new entry */
603 entry = GNUNET_malloc (sizeof (struct HostEntry));
604 entry->identity = id;
605 entry->hello = r.hello;
606 entry->friend_only_hello = r.friend_only_hello;
607 GNUNET_CONTAINER_multihashmap_put (hostmap, &entry->identity.hashPubKey, entry,
608 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
609 }
610 else
611 {
612 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Updating existing peer `%s' with %s %s HELLO \n",
613 GNUNET_i2s (&entry->identity),
614 (NULL != r.hello) ? "public" : "",
615 (NULL != r.friend_only_hello) ? "friend-only" : "");
616 /* Update entry */
617 if (NULL != r.hello)
618 {
619 bind_address (&id, r.hello);
620 GNUNET_free (r.hello);
621 }
622 if (NULL != r.friend_only_hello)
623 {
624 bind_address (&id, r.friend_only_hello);
625 GNUNET_free (r.friend_only_hello);
626 }
627 }
628
629 notify_all (entry);
630 dsc->matched++;
631 return GNUNET_OK;
585 } 632 }
586 dsc->matched++; 633 dsc->matched++;
587 add_host_to_known_hosts (&identity); 634 add_host_to_known_hosts (&identity);
@@ -710,7 +757,12 @@ bind_address (const struct GNUNET_PeerIdentity *peer,
710 } 757 }
711 758
712 if ((NULL != (host->hello)) && (GNUNET_NO == friend_hello_type)) 759 if ((NULL != (host->hello)) && (GNUNET_NO == friend_hello_type))
713 host->friend_only_hello = update_friend_hello (host->hello, host->friend_only_hello); 760 {
761 mrg = update_friend_hello (host->hello, host->friend_only_hello);
762 if (NULL != host->friend_only_hello)
763 GNUNET_free (host->friend_only_hello);
764 host->friend_only_hello = mrg;
765 }
714 766
715 if (NULL != host->hello) 767 if (NULL != host->hello)
716 GNUNET_assert ((GNUNET_NO == GNUNET_HELLO_is_friend_only (host->hello))); 768 GNUNET_assert ((GNUNET_NO == GNUNET_HELLO_is_friend_only (host->hello)));
@@ -812,7 +864,6 @@ add_to_tc (void *cls, const struct GNUNET_HashCode * key, void *value)
812 GNUNET_assert (hs < GNUNET_SERVER_MAX_MESSAGE_SIZE - 864 GNUNET_assert (hs < GNUNET_SERVER_MAX_MESSAGE_SIZE -
813 sizeof (struct InfoMessage)); 865 sizeof (struct InfoMessage));
814 memcpy (&im[1], pos->hello, hs); 866 memcpy (&im[1], pos->hello, hs);
815
816 } 867 }
817 868
818 if ((pos->friend_only_hello != NULL) && (GNUNET_YES == tc->friend_only)) 869 if ((pos->friend_only_hello != NULL) && (GNUNET_YES == tc->friend_only))
@@ -822,7 +873,6 @@ add_to_tc (void *cls, const struct GNUNET_HashCode * key, void *value)
822 GNUNET_assert (hs < GNUNET_SERVER_MAX_MESSAGE_SIZE - 873 GNUNET_assert (hs < GNUNET_SERVER_MAX_MESSAGE_SIZE -
823 sizeof (struct InfoMessage)); 874 sizeof (struct InfoMessage));
824 memcpy (&im[1], pos->friend_only_hello, hs); 875 memcpy (&im[1], pos->friend_only_hello, hs);
825
826 } 876 }
827 im->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_INFO); 877 im->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_INFO);
828 im->header.size = htons (sizeof (struct InfoMessage) + hs); 878 im->header.size = htons (sizeof (struct InfoMessage) + hs);
@@ -1167,8 +1217,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1167 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, 1217 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
1168 &cron_scan_directory_data_hosts, NULL); /* CHECK */ 1218 &cron_scan_directory_data_hosts, NULL); /* CHECK */
1169 1219
1170// GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, 1220 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
1171// &cron_clean_data_hosts, NULL); /* CHECK */ 1221 &cron_clean_data_hosts, NULL); /* CHECK */
1172 1222
1173 ip = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR); 1223 ip = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
1174 GNUNET_asprintf (&peerdir, 1224 GNUNET_asprintf (&peerdir,