aboutsummaryrefslogtreecommitdiff
path: root/src/fs
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2009-10-25 20:12:05 +0000
committerChristian Grothoff <christian@grothoff.org>2009-10-25 20:12:05 +0000
commitc22ef5d895b1dba3555f5e012770265a9372dc8e (patch)
treed4928532a5861cffad12f6eaf9bbbe6f00aa6d15 /src/fs
parenta97a35e05bb843e261e004b58fec87ea18e59347 (diff)
downloadgnunet-c22ef5d895b1dba3555f5e012770265a9372dc8e.tar.gz
gnunet-c22ef5d895b1dba3555f5e012770265a9372dc8e.zip
fixing indexing and unindexing issues
Diffstat (limited to 'src/fs')
-rw-r--r--src/fs/Makefile.am1
-rw-r--r--src/fs/fs.h12
-rw-r--r--src/fs/fs_file_information.c23
-rw-r--r--src/fs/fs_publish.c63
-rw-r--r--src/fs/fs_unindex.c5
-rw-r--r--src/fs/gnunet-service-fs.c26
-rw-r--r--src/fs/test_fs_download.c2
-rw-r--r--src/fs/test_fs_unindex.c4
8 files changed, 100 insertions, 36 deletions
diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am
index 38db1bc58..59361b03e 100644
--- a/src/fs/Makefile.am
+++ b/src/fs/Makefile.am
@@ -118,6 +118,7 @@ TESTS = \
118 test_fs_download \ 118 test_fs_download \
119 test_fs_search \ 119 test_fs_search \
120 test_fs_start_stop \ 120 test_fs_start_stop \
121 test_fs_unindex \
121 test_fs_uri 122 test_fs_uri
122# $(check_PROGRAMS) 123# $(check_PROGRAMS)
123 124
diff --git a/src/fs/fs.h b/src/fs/fs.h
index 2cac304a3..acfc8b1c6 100644
--- a/src/fs/fs.h
+++ b/src/fs/fs.h
@@ -367,6 +367,18 @@ struct GNUNET_FS_FileInformation
367 */ 367 */
368 int do_index; 368 int do_index;
369 369
370 /**
371 * Is "file_id" already valid? Set to GNUNET_YES
372 * once the hash has been calculated.
373 */
374 int have_hash;
375
376 /**
377 * Has the service confirmed our INDEX_START request?
378 * GNUNET_YES if this step has been completed.
379 */
380 int index_start_confirmed;
381
370 } file; 382 } file;
371 383
372 /** 384 /**
diff --git a/src/fs/fs_file_information.c b/src/fs/fs_file_information.c
index f4f4fb567..330ddc2fc 100644
--- a/src/fs/fs_file_information.c
+++ b/src/fs/fs_file_information.c
@@ -202,6 +202,7 @@ GNUNET_FS_file_information_create_from_file (void *client_info,
202{ 202{
203 struct FileInfo *fi; 203 struct FileInfo *fi;
204 struct stat sbuf; 204 struct stat sbuf;
205 struct GNUNET_FS_FileInformation *ret;
205 206
206 if (0 != STAT (filename, &sbuf)) 207 if (0 != STAT (filename, &sbuf))
207 { 208 {
@@ -212,16 +213,18 @@ GNUNET_FS_file_information_create_from_file (void *client_info,
212 } 213 }
213 fi = GNUNET_malloc (sizeof(struct FileInfo)); 214 fi = GNUNET_malloc (sizeof(struct FileInfo));
214 fi->filename = GNUNET_strdup (filename); 215 fi->filename = GNUNET_strdup (filename);
215 return GNUNET_FS_file_information_create_from_reader (client_info, 216 ret = GNUNET_FS_file_information_create_from_reader (client_info,
216 sbuf.st_size, 217 sbuf.st_size,
217 &data_reader_file, 218 &data_reader_file,
218 fi, 219 fi,
219 keywords, 220 keywords,
220 meta, 221 meta,
221 do_index, 222 do_index,
222 anonymity, 223 anonymity,
223 priority, 224 priority,
224 expirationTime); 225 expirationTime);
226 ret->data.file.filename = GNUNET_strdup (filename);
227 return ret;
225} 228}
226 229
227 230
diff --git a/src/fs/fs_publish.c b/src/fs/fs_publish.c
index 34a13f55c..a64f0d15e 100644
--- a/src/fs/fs_publish.c
+++ b/src/fs/fs_publish.c
@@ -482,13 +482,6 @@ block_proc (void *cls,
482 struct PutContCtx * dpc_cls; 482 struct PutContCtx * dpc_cls;
483 struct OnDemandBlock odb; 483 struct OnDemandBlock odb;
484 484
485#if DEBUG_PUBLISH
486 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
487 "Publishing block `%s' for offset %llu with size %u\n",
488 GNUNET_h2s (query),
489 (unsigned long long) offset,
490 (unsigned int) block_size);
491#endif
492 p = sc->fi_pos; 485 p = sc->fi_pos;
493 if (NULL == sc->dsh) 486 if (NULL == sc->dsh)
494 { 487 {
@@ -510,10 +503,17 @@ block_proc (void *cls,
510 dpc_cls->cont_cls = sc; 503 dpc_cls->cont_cls = sc;
511 dpc_cls->sc = sc; 504 dpc_cls->sc = sc;
512 dpc_cls->p = p; 505 dpc_cls->p = p;
513 if ( (p->is_directory) && 506 if ( (! p->is_directory) &&
514 (p->data.file.do_index) && 507 (GNUNET_YES == p->data.file.do_index) &&
515 (type == GNUNET_DATASTORE_BLOCKTYPE_DBLOCK) ) 508 (type == GNUNET_DATASTORE_BLOCKTYPE_DBLOCK) )
516 { 509 {
510#if DEBUG_PUBLISH
511 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
512 "Indexing block `%s' for offset %llu with index size %u\n",
513 GNUNET_h2s (query),
514 (unsigned long long) offset,
515 sizeof (struct OnDemandBlock));
516#endif
517 odb.offset = offset; 517 odb.offset = offset;
518 odb.file_id = p->data.file.file_id; 518 odb.file_id = p->data.file.file_id;
519 GNUNET_DATASTORE_put (sc->dsh, 519 GNUNET_DATASTORE_put (sc->dsh,
@@ -530,6 +530,13 @@ block_proc (void *cls,
530 dpc_cls); 530 dpc_cls);
531 return; 531 return;
532 } 532 }
533#if DEBUG_PUBLISH
534 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
535 "Publishing block `%s' for offset %llu with size %u\n",
536 GNUNET_h2s (query),
537 (unsigned long long) offset,
538 (unsigned int) block_size);
539#endif
533 GNUNET_DATASTORE_put (sc->dsh, 540 GNUNET_DATASTORE_put (sc->dsh,
534 sc->rid, 541 sc->rid,
535 query, 542 query,
@@ -702,6 +709,7 @@ process_index_start_response (void *cls,
702 publish_content (sc); 709 publish_content (sc);
703 return; 710 return;
704 } 711 }
712 p->data.file.index_start_confirmed = GNUNET_YES;
705 /* success! continue with indexing */ 713 /* success! continue with indexing */
706 publish_content (sc); 714 publish_content (sc);
707} 715}
@@ -738,6 +746,11 @@ hash_for_index_cb (void *cls,
738 publish_content (sc); 746 publish_content (sc);
739 return; 747 return;
740 } 748 }
749 if (GNUNET_YES == p->data.file.index_start_confirmed)
750 {
751 publish_content (sc);
752 return;
753 }
741 slen = strlen (p->data.file.filename) + 1; 754 slen = strlen (p->data.file.filename) + 1;
742 if (slen > GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof(struct IndexStartMessage)) 755 if (slen > GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof(struct IndexStartMessage))
743 { 756 {
@@ -749,6 +762,12 @@ hash_for_index_cb (void *cls,
749 publish_content (sc); 762 publish_content (sc);
750 return; 763 return;
751 } 764 }
765#if DEBUG_PUBLISH
766 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
767 "Hash of indexed file `%s' is `%s'\n",
768 p->data.file.filename,
769 GNUNET_h2s (res));
770#endif
752 client = GNUNET_CLIENT_connect (sc->h->sched, 771 client = GNUNET_CLIENT_connect (sc->h->sched,
753 "fs", 772 "fs",
754 sc->h->cfg); 773 sc->h->cfg);
@@ -763,6 +782,7 @@ hash_for_index_cb (void *cls,
763 return; 782 return;
764 } 783 }
765 p->data.file.file_id = *res; 784 p->data.file.file_id = *res;
785 p->data.file.have_hash = GNUNET_YES;
766 ism = GNUNET_malloc (sizeof(struct IndexStartMessage) + 786 ism = GNUNET_malloc (sizeof(struct IndexStartMessage) +
767 slen); 787 slen);
768 ism->header.size = htons(sizeof(struct IndexStartMessage) + 788 ism->header.size = htons(sizeof(struct IndexStartMessage) +
@@ -776,6 +796,13 @@ hash_for_index_cb (void *cls,
776 ism->device = htonl (dev); 796 ism->device = htonl (dev);
777 ism->inode = GNUNET_htonll(ino); 797 ism->inode = GNUNET_htonll(ino);
778 } 798 }
799 else
800 {
801 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
802 _("Failed to get file identifiers for `%s'\n"),
803 p->data.file.filename);
804 }
805 ism->file_id = *res;
779 memcpy (&ism[1], 806 memcpy (&ism[1],
780 p->data.file.filename, 807 p->data.file.filename,
781 slen); 808 slen);
@@ -877,13 +904,17 @@ do_upload (void *cls,
877 publish_content (sc); 904 publish_content (sc);
878 return; 905 return;
879 } 906 }
880 GNUNET_CRYPTO_hash_file (sc->h->sched, 907 if (p->data.file.have_hash)
881 GNUNET_SCHEDULER_PRIORITY_IDLE, 908 hash_for_index_cb (sc,
882 GNUNET_NO, 909 &p->data.file.file_id);
883 p->data.file.filename, 910 else
884 HASHING_BLOCKSIZE, 911 GNUNET_CRYPTO_hash_file (sc->h->sched,
885 &hash_for_index_cb, 912 GNUNET_SCHEDULER_PRIORITY_IDLE,
886 sc); 913 GNUNET_NO,
914 p->data.file.filename,
915 HASHING_BLOCKSIZE,
916 &hash_for_index_cb,
917 sc);
887 return; 918 return;
888 } 919 }
889 publish_content (sc); 920 publish_content (sc);
diff --git a/src/fs/fs_unindex.c b/src/fs/fs_unindex.c
index 10faf4cf9..3d39cb932 100644
--- a/src/fs/fs_unindex.c
+++ b/src/fs/fs_unindex.c
@@ -20,12 +20,9 @@
20 20
21/** 21/**
22 * @file fs/fs_unindex.c 22 * @file fs/fs_unindex.c
23 * @author Krista Bennett 23 * @author Krista Grothoff
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 * @brief Unindex file. 25 * @brief Unindex file.
26 *
27 * TODO:
28 * - code cleanup (share more with upload.c)
29 */ 26 */
30#include "platform.h" 27#include "platform.h"
31#include "gnunet_constants.h" 28#include "gnunet_constants.h"
diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c
index dc97b2cb8..5148c4675 100644
--- a/src/fs/gnunet-service-fs.c
+++ b/src/fs/gnunet-service-fs.c
@@ -990,8 +990,14 @@ hash_for_index_val (void *cls,
990 sizeof(GNUNET_HashCode))) ) 990 sizeof(GNUNET_HashCode))) )
991 { 991 {
992 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 992 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
993 _("Hash mismatch trying to index file `%s'\n"), 993 _("Hash mismatch trying to index file `%s' which has hash `%s'\n"),
994 ii->filename); 994 ii->filename,
995 GNUNET_h2s (res));
996#if DEBUG_FS
997 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
998 "Wanted `%s'\n",
999 GNUNET_h2s (&ii->file_id));
1000#endif
995 GNUNET_SERVER_transmit_context_append (ii->tc, 1001 GNUNET_SERVER_transmit_context_append (ii->tc,
996 NULL, 0, 1002 NULL, 0,
997 GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED); 1003 GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED);
@@ -1058,6 +1064,14 @@ handle_index_start (void *cls,
1058 signal_index_ok (ii); 1064 signal_index_ok (ii);
1059 return; 1065 return;
1060 } 1066 }
1067#if DEBUG_FS
1068 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1069 "Mismatch in file identifiers (%llu != %llu or %u != %u), need to hash.\n",
1070 (unsigned long long) ino,
1071 (unsigned long long) myino,
1072 (unsigned int) dev,
1073 (unsigned int) mydev);
1074#endif
1061 /* slow validation, need to hash full file (again) */ 1075 /* slow validation, need to hash full file (again) */
1062 GNUNET_CRYPTO_hash_file (sched, 1076 GNUNET_CRYPTO_hash_file (sched,
1063 GNUNET_SCHEDULER_PRIORITY_IDLE, 1077 GNUNET_SCHEDULER_PRIORITY_IDLE,
@@ -1165,7 +1179,13 @@ handle_unindex (void *cls,
1165 } 1179 }
1166 pos = next; 1180 pos = next;
1167 } 1181 }
1168 if (GNUNET_YES == found) 1182#if DEBUG_FS
1183 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1184 "Client requested unindexing of file `%s': %s\n",
1185 GNUNET_h2s (&um->file_id),
1186 found ? "found" : "not found");
1187#endif
1188 if (GNUNET_YES == found)
1169 write_index_list (); 1189 write_index_list ();
1170 tc = GNUNET_SERVER_transmit_context_create (client); 1190 tc = GNUNET_SERVER_transmit_context_create (client);
1171 GNUNET_SERVER_transmit_context_append (tc, 1191 GNUNET_SERVER_transmit_context_append (tc,
diff --git a/src/fs/test_fs_download.c b/src/fs/test_fs_download.c
index 1d1813c56..9b85e1ca1 100644
--- a/src/fs/test_fs_download.c
+++ b/src/fs/test_fs_download.c
@@ -116,7 +116,7 @@ progress_cb (void *cls,
116 case GNUNET_FS_STATUS_PUBLISH_COMPLETED: 116 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
117 printf ("Publishing complete, %llu kbps.\n", 117 printf ("Publishing complete, %llu kbps.\n",
118 (unsigned long long) (FILESIZE * 1000 / (1+GNUNET_TIME_absolute_get_duration (start).value) / 1024)); 118 (unsigned long long) (FILESIZE * 1000 / (1+GNUNET_TIME_absolute_get_duration (start).value) / 1024));
119 fn = GNUNET_DISK_mktemp ("gnunet-download-test-dstXXXXXX"); 119 fn = GNUNET_DISK_mktemp ("gnunet-download-test-dst");
120 start = GNUNET_TIME_absolute_get (); 120 start = GNUNET_TIME_absolute_get ();
121 download = GNUNET_FS_download_start (fs, 121 download = GNUNET_FS_download_start (fs,
122 event->value.publish.specifics.completed.chk_uri, 122 event->value.publish.specifics.completed.chk_uri,
diff --git a/src/fs/test_fs_unindex.c b/src/fs/test_fs_unindex.c
index 0b7173115..3dcf7b7f8 100644
--- a/src/fs/test_fs_unindex.c
+++ b/src/fs/test_fs_unindex.c
@@ -29,7 +29,7 @@
29#include "gnunet_arm_service.h" 29#include "gnunet_arm_service.h"
30#include "gnunet_fs_service.h" 30#include "gnunet_fs_service.h"
31 31
32#define VERBOSE GNUNET_NO 32#define VERBOSE GNUNET_YES
33 33
34#define START_ARM GNUNET_YES 34#define START_ARM GNUNET_YES
35 35
@@ -248,7 +248,7 @@ run (void *cls,
248 248
249 sched = s; 249 sched = s;
250 setup_peer (&p1, "test_fs_unindex_data.conf"); 250 setup_peer (&p1, "test_fs_unindex_data.conf");
251 fn = GNUNET_DISK_mktemp ("gnunet-unindex-test-dstXXXXXX"); 251 fn = GNUNET_DISK_mktemp ("gnunet-unindex-test-dst");
252 fs = GNUNET_FS_start (sched, 252 fs = GNUNET_FS_start (sched,
253 cfg, 253 cfg,
254 "test-fs-unindex", 254 "test-fs-unindex",