aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-04-10 11:27:32 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-04-10 11:27:32 +0000
commit2e7423ffb297c6956228930e03ebaf58eb13da06 (patch)
tree05e7250eba2112495df2d15104f6bcd74f64596b /src
parent468fea92f64d600ed635c417d91a235535098372 (diff)
downloadgnunet-2e7423ffb297c6956228930e03ebaf58eb13da06.tar.gz
gnunet-2e7423ffb297c6956228930e03ebaf58eb13da06.zip
fixed periodic cleanup
Diffstat (limited to 'src')
-rw-r--r--src/peerinfo/gnunet-service-peerinfo.c81
1 files changed, 56 insertions, 25 deletions
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c
index a2a66bd62..a76ac81d2 100644
--- a/src/peerinfo/gnunet-service-peerinfo.c
+++ b/src/peerinfo/gnunet-service-peerinfo.c
@@ -601,9 +601,7 @@ hosts_directory_scan_callback (void *cls, const char *fullname)
601 else 601 else
602 filename ++; 602 filename ++;
603 603
604 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reading %s `%s'\n", fullname, filename);
605 read_host_file (fullname, dsc->remove_files, &r); 604 read_host_file (fullname, dsc->remove_files, &r);
606
607 if ( (NULL == r.hello) && (NULL == r.friend_only_hello)) 605 if ( (NULL == r.hello) && (NULL == r.friend_only_hello))
608 { 606 {
609 if (GNUNET_YES == dsc->remove_files) 607 if (GNUNET_YES == dsc->remove_files)
@@ -952,44 +950,75 @@ discard_hosts_helper (void *cls, const char *fn)
952 char buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1] GNUNET_ALIGN; 950 char buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1] GNUNET_ALIGN;
953 const struct GNUNET_HELLO_Message *hello; 951 const struct GNUNET_HELLO_Message *hello;
954 struct GNUNET_HELLO_Message *new_hello; 952 struct GNUNET_HELLO_Message *new_hello;
955 int size; 953 int read_size;
954 int cur_hello_size;
955 int new_hello_size;
956 int read_pos;
957 int write_pos;
956 unsigned int cnt; 958 unsigned int cnt;
959 char *writebuffer;
960
957 961
958 size = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer)); 962 read_size = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer));
959 if (size < sizeof (struct GNUNET_MessageHeader)) 963 if (read_size < sizeof (struct GNUNET_MessageHeader))
960 { 964 {
961 if (0 != UNLINK (fn)) 965 if (0 != UNLINK (fn))
962 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | 966 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
963 GNUNET_ERROR_TYPE_BULK, "unlink", fn); 967 GNUNET_ERROR_TYPE_BULK, "unlink", fn);
964 return GNUNET_OK; 968 return GNUNET_OK;
965 } 969 }
966 hello = (const struct GNUNET_HELLO_Message *) buffer; 970
967 new_hello = 971 writebuffer = GNUNET_malloc (read_size);
968 GNUNET_HELLO_iterate_addresses (hello, GNUNET_YES, &discard_expired, now); 972 read_pos = 0;
969 cnt = 0; 973 write_pos = 0;
970 if (NULL != new_hello) 974 while (read_pos < read_size)
971 (void) GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &count_addresses, &cnt);
972 if ( (NULL != new_hello) && (0 < cnt) )
973 { 975 {
974 GNUNET_DISK_fn_write (fn, new_hello, GNUNET_HELLO_size (new_hello), 976 /* Check each HELLO */
975 GNUNET_DISK_PERM_USER_READ | 977 hello = (const struct GNUNET_HELLO_Message *) &buffer[read_pos];
976 GNUNET_DISK_PERM_USER_WRITE | 978 cur_hello_size = GNUNET_HELLO_size (hello);
977 GNUNET_DISK_PERM_GROUP_READ | 979 new_hello_size = 0;
978 GNUNET_DISK_PERM_OTHER_READ); 980 if (0 == cur_hello_size)
981 {
982 /* Invalid data, discard */
983 if (0 != UNLINK (fn))
984 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
985 GNUNET_ERROR_TYPE_BULK, "unlink", fn);
986 return GNUNET_OK;
987 }
988 new_hello = GNUNET_HELLO_iterate_addresses (hello, GNUNET_YES, &discard_expired, now);
989 cnt = 0;
990 if (NULL != new_hello)
991 (void) GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &count_addresses, &cnt);
992 if ( (NULL != new_hello) && (0 < cnt) )
993 {
994 /* Store new HELLO to write it when done */
995 new_hello_size = GNUNET_HELLO_size(new_hello);
996 memcpy (&writebuffer[write_pos], new_hello, new_hello_size);
997 write_pos += new_hello_size;
998 }
999 read_pos += cur_hello_size;
1000 GNUNET_free_non_null (new_hello);
979 } 1001 }
980 else 1002
1003 if (0 < write_pos)
981 { 1004 {
982 if (0 != UNLINK (fn)) 1005 GNUNET_DISK_fn_write (fn, writebuffer,write_pos,
983 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | 1006 GNUNET_DISK_PERM_USER_READ |
984 GNUNET_ERROR_TYPE_BULK, "unlink", fn); 1007 GNUNET_DISK_PERM_USER_WRITE |
1008 GNUNET_DISK_PERM_GROUP_READ |
1009 GNUNET_DISK_PERM_OTHER_READ);
985 } 1010 }
986 GNUNET_free_non_null (new_hello); 1011 else if (0 != UNLINK (fn))
1012 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
1013 GNUNET_ERROR_TYPE_BULK, "unlink", fn);
1014
1015 GNUNET_free (writebuffer);
987 return GNUNET_OK; 1016 return GNUNET_OK;
988} 1017}
989 1018
990 1019
991/** 1020/**
992 * Call this method periodically to scan data/hosts for ancient 1021 * Call this method periodically to scan peerinfo/ for ancient
993 * HELLOs to expire. 1022 * HELLOs to expire.
994 * 1023 *
995 * @param cls unused 1024 * @param cls unused
@@ -1003,6 +1032,8 @@ cron_clean_data_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1003 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 1032 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1004 return; 1033 return;
1005 now = GNUNET_TIME_absolute_get (); 1034 now = GNUNET_TIME_absolute_get ();
1035 GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK,
1036 _("Cleaning up directory `%s'\n"), networkIdDirectory);
1006 GNUNET_DISK_directory_scan (networkIdDirectory, &discard_hosts_helper, &now); 1037 GNUNET_DISK_directory_scan (networkIdDirectory, &discard_hosts_helper, &now);
1007 GNUNET_SCHEDULER_add_delayed (DATA_HOST_CLEAN_FREQ, &cron_clean_data_hosts, 1038 GNUNET_SCHEDULER_add_delayed (DATA_HOST_CLEAN_FREQ, &cron_clean_data_hosts,
1008 NULL); 1039 NULL);
@@ -1270,10 +1301,10 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1270 GNUNET_DISK_directory_create (networkIdDirectory); 1301 GNUNET_DISK_directory_create (networkIdDirectory);
1271 1302
1272 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, 1303 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
1273 &cron_scan_directory_data_hosts, NULL); /* CHECK */ 1304 &cron_scan_directory_data_hosts, NULL);
1274 1305
1275 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, 1306 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
1276 &cron_clean_data_hosts, NULL); /* CHECK */ 1307 &cron_clean_data_hosts, NULL);
1277 1308
1278 ip = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR); 1309 ip = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
1279 GNUNET_asprintf (&peerdir, 1310 GNUNET_asprintf (&peerdir,