aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/fs/fs.c106
-rw-r--r--src/fs/fs.h50
-rw-r--r--src/fs/fs_tree.c2
-rw-r--r--src/fs/fs_unindex.c70
4 files changed, 163 insertions, 65 deletions
diff --git a/src/fs/fs.c b/src/fs/fs.c
index df0bf881a..417461404 100644
--- a/src/fs/fs.c
+++ b/src/fs/fs.c
@@ -1191,6 +1191,21 @@ GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc)
1191 1191
1192 1192
1193/** 1193/**
1194 * Synchronize this unindex struct with its mirror
1195 * on disk. Note that all internal FS-operations that change
1196 * publishing structs should already call "sync" internally,
1197 * so this function is likely not useful for clients.
1198 *
1199 * @param uc the struct to sync
1200 */
1201void
1202GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc)
1203{
1204 /* FIXME */
1205}
1206
1207
1208/**
1194 * Deserialize information about pending publish operations. 1209 * Deserialize information about pending publish operations.
1195 * 1210 *
1196 * @param h master context 1211 * @param h master context
@@ -1225,7 +1240,9 @@ deserialize_unindex_file (void *cls,
1225 struct GNUNET_FS_Handle *h = cls; 1240 struct GNUNET_FS_Handle *h = cls;
1226 struct GNUNET_BIO_ReadHandle *rh; 1241 struct GNUNET_BIO_ReadHandle *rh;
1227 struct GNUNET_FS_UnindexContext *uc; 1242 struct GNUNET_FS_UnindexContext *uc;
1243 struct GNUNET_FS_ProgressInfo pi;
1228 char *emsg; 1244 char *emsg;
1245 uint32_t state;
1229 1246
1230 uc = GNUNET_malloc (sizeof (struct GNUNET_FS_UnindexContext)); 1247 uc = GNUNET_malloc (sizeof (struct GNUNET_FS_UnindexContext));
1231 uc->h = h; 1248 uc->h = h;
@@ -1233,33 +1250,70 @@ deserialize_unindex_file (void *cls,
1233 rh = GNUNET_BIO_read_open (filename); 1250 rh = GNUNET_BIO_read_open (filename);
1234 if (rh == NULL) 1251 if (rh == NULL)
1235 goto cleanup; 1252 goto cleanup;
1236 /* FIXME: do unindex state here! */
1237#if 0
1238 if ( (GNUNET_OK != 1253 if ( (GNUNET_OK !=
1239 GNUNET_BIO_read_string (rh, "publish-nid", &pc->nid, 1024)) || 1254 GNUNET_BIO_read_string (rh, "unindex-fn", &uc->filename, 10*1024)) ||
1240 (GNUNET_OK != 1255 (GNUNET_OK !=
1241 GNUNET_BIO_read_string (rh, "publish-nuid", &pc->nuid, 1024)) || 1256 GNUNET_BIO_read_int64 (rh, &uc->file_size)) ||
1242 (GNUNET_OK != 1257 (GNUNET_OK !=
1243 GNUNET_BIO_read_int32 (rh, &options)) || 1258 GNUNET_BIO_read_int64 (rh, &uc->start_time.value)) ||
1244 (GNUNET_OK !=
1245 GNUNET_BIO_read_int32 (rh, &all_done)) ||
1246 (GNUNET_OK !=
1247 GNUNET_BIO_read_string (rh, "publish-firoot", &fi_root, 128)) ||
1248 (GNUNET_OK !=
1249 GNUNET_BIO_read_string (rh, "publish-fipos", &fi_pos, 128)) ||
1250 (GNUNET_OK != 1259 (GNUNET_OK !=
1251 GNUNET_BIO_read_string (rh, "publish-ns", &ns, 1024)) ) 1260 GNUNET_BIO_read_int32 (rh, &state)) )
1252 goto cleanup; 1261 goto cleanup;
1253 pc->options = options; 1262 uc->state = (enum UnindexState) state;
1254 pc->all_done = all_done; 1263 switch (state)
1255 pc->fi = deserialize_file_information (h, fi_root); 1264 {
1256 if (pc->fi == NULL) 1265 case UNINDEX_STATE_HASHING:
1257 goto cleanup; 1266 break;
1258#endif 1267 case UNINDEX_STATE_FS_NOTIFY:
1259 /* FIXME: generate RESUME event */ 1268 if (GNUNET_OK !=
1260 /* FIXME: re-start unindexing (if needed)... */ 1269 GNUNET_BIO_read (rh, "unindex-hash", &uc->file_id, sizeof (GNUNET_HashCode)))
1270 goto cleanup;
1271 break;
1272 case UNINDEX_STATE_DS_REMOVE:
1273 break;
1274 case UNINDEX_STATE_COMPLETE:
1275 break;
1276 case UNINDEX_STATE_ERROR:
1277 if (GNUNET_OK !=
1278 GNUNET_BIO_read_string (rh, "unindex-emsg", &uc->emsg, 10*1024))
1279 goto cleanup;
1280 break;
1281 case UNINDEX_STATE_ABORTED:
1282 GNUNET_break (0);
1283 goto cleanup;
1284 default:
1285 GNUNET_break (0);
1286 goto cleanup;
1287 }
1288 pi.status = GNUNET_FS_STATUS_UNINDEX_RESUME;
1289 pi.value.unindex.specifics.resume.message = uc->emsg;
1290 GNUNET_FS_unindex_make_status_ (&pi,
1291 uc,
1292 (uc->state == UNINDEX_STATE_COMPLETE)
1293 ? uc->file_size
1294 : 0);
1261 switch (uc->state) 1295 switch (uc->state)
1262 { 1296 {
1297 case UNINDEX_STATE_HASHING:
1298 GNUNET_CRYPTO_hash_file (uc->h->sched,
1299 GNUNET_SCHEDULER_PRIORITY_IDLE,
1300 uc->filename,
1301 HASHING_BLOCKSIZE,
1302 &GNUNET_FS_unindex_process_hash_,
1303 uc);
1304 break;
1305 case UNINDEX_STATE_FS_NOTIFY:
1306 uc->state = UNINDEX_STATE_HASHING;
1307 GNUNET_FS_unindex_process_hash_ (uc,
1308 &uc->file_id);
1309 break;
1310 case UNINDEX_STATE_DS_REMOVE:
1311 GNUNET_FS_unindex_do_remove_ (uc);
1312 break;
1313 case UNINDEX_STATE_COMPLETE:
1314 case UNINDEX_STATE_ERROR:
1315 /* no need to resume any operation, we were done */
1316 break;
1263 default: 1317 default:
1264 break; 1318 break;
1265 } 1319 }
@@ -1271,18 +1325,10 @@ deserialize_unindex_file (void *cls,
1271 filename, 1325 filename,
1272 emsg); 1326 emsg);
1273 GNUNET_free (emsg); 1327 GNUNET_free (emsg);
1274 rh = NULL;
1275 goto cleanup;
1276 } 1328 }
1277 return GNUNET_OK; 1329 return GNUNET_OK;
1278 cleanup: 1330 cleanup:
1279 /* FIXME: clean unindex state here! */ 1331 GNUNET_free_non_null (uc->filename);
1280#if 0
1281 GNUNET_free_non_null (pc->nid);
1282 GNUNET_free_non_null (pc->nuid);
1283 GNUNET_free_non_null (fi_root);
1284 GNUNET_free_non_null (ns);
1285#endif
1286 if ( (rh != NULL) && 1332 if ( (rh != NULL) &&
1287 (GNUNET_OK != 1333 (GNUNET_OK !=
1288 GNUNET_BIO_read_close (rh, &emsg)) ) 1334 GNUNET_BIO_read_close (rh, &emsg)) )
@@ -1301,8 +1347,6 @@ deserialize_unindex_file (void *cls,
1301} 1347}
1302 1348
1303 1349
1304
1305
1306/** 1350/**
1307 * Deserialize information about pending publish operations. 1351 * Deserialize information about pending publish operations.
1308 * 1352 *
diff --git a/src/fs/fs.h b/src/fs/fs.h
index 7100b1657..9441b76e0 100644
--- a/src/fs/fs.h
+++ b/src/fs/fs.h
@@ -658,6 +658,18 @@ GNUNET_FS_publish_main_ (void *cls,
658 658
659 659
660/** 660/**
661 * Function called once the hash of the file
662 * that is being unindexed has been computed.
663 *
664 * @param cls closure, unindex context
665 * @param file_id computed hash, NULL on error
666 */
667void
668GNUNET_FS_unindex_process_hash_ (void *cls,
669 const GNUNET_HashCode *file_id);
670
671
672/**
661 * Fill in all of the generic fields for a publish event and call the 673 * Fill in all of the generic fields for a publish event and call the
662 * callback. 674 * callback.
663 * 675 *
@@ -673,6 +685,27 @@ GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
673 const struct GNUNET_FS_FileInformation *p, 685 const struct GNUNET_FS_FileInformation *p,
674 uint64_t offset); 686 uint64_t offset);
675 687
688/**
689 * Fill in all of the generic fields for
690 * an unindex event and call the callback.
691 *
692 * @param pi structure to fill in
693 * @param uc overall unindex context
694 * @param offset where we are in the file (for progress)
695 */
696void
697GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
698 struct GNUNET_FS_UnindexContext *uc,
699 uint64_t offset);
700
701/**
702 * Connect to the datastore and remove the blocks.
703 *
704 * @param uc context for the unindex operation.
705 */
706void
707GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc);
708
676 709
677/** 710/**
678 * Remove serialization/deserialization file from disk. 711 * Remove serialization/deserialization file from disk.
@@ -711,6 +744,18 @@ void
711GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc); 744GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc);
712 745
713 746
747/**
748 * Synchronize this unindex struct with its mirror
749 * on disk. Note that all internal FS-operations that change
750 * publishing structs should already call "sync" internally,
751 * so this function is likely not useful for clients.
752 *
753 * @param uc the struct to sync
754 */
755void
756GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc);
757
758
714 759
715/** 760/**
716 * Master context for most FS operations. 761 * Master context for most FS operations.
@@ -983,6 +1028,11 @@ struct GNUNET_FS_UnindexContext
983 struct GNUNET_DISK_FileHandle *fh; 1028 struct GNUNET_DISK_FileHandle *fh;
984 1029
985 /** 1030 /**
1031 * Error message, NULL on success.
1032 */
1033 char *emsg;
1034
1035 /**
986 * Overall size of the file. 1036 * Overall size of the file.
987 */ 1037 */
988 uint64_t file_size; 1038 uint64_t file_size;
diff --git a/src/fs/fs_tree.c b/src/fs/fs_tree.c
index 15e13be21..c8cb8bab0 100644
--- a/src/fs/fs_tree.c
+++ b/src/fs/fs_tree.c
@@ -173,7 +173,7 @@ GNUNET_FS_tree_encoder_create (struct GNUNET_FS_Handle *h,
173 struct GNUNET_FS_TreeEncoder *te; 173 struct GNUNET_FS_TreeEncoder *te;
174 174
175 GNUNET_assert (size > 0); 175 GNUNET_assert (size > 0);
176 te = GNUNET_malloc (sizeof (struct GNUNET_FS_TreeEncoder)); 176 te = GNUNET_malloc (sizeof (struct GNUNET_FS_TreeEncoder));
177 te->h = h; 177 te->h = h;
178 te->size = size; 178 te->size = size;
179 te->cls = cls; 179 te->cls = cls;
diff --git a/src/fs/fs_unindex.c b/src/fs/fs_unindex.c
index acb3a2068..4b4e526dd 100644
--- a/src/fs/fs_unindex.c
+++ b/src/fs/fs_unindex.c
@@ -77,16 +77,16 @@ unindex_reader (void *cls,
77 77
78/** 78/**
79 * Fill in all of the generic fields for 79 * Fill in all of the generic fields for
80 * an unindex event. 80 * an unindex event and call the callback.
81 * 81 *
82 * @param pi structure to fill in 82 * @param pi structure to fill in
83 * @param uc overall unindex context 83 * @param uc overall unindex context
84 * @param offset where we are in the file (for progress) 84 * @param offset where we are in the file (for progress)
85 */ 85 */
86static void 86void
87make_unindex_status (struct GNUNET_FS_ProgressInfo *pi, 87GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
88 struct GNUNET_FS_UnindexContext *uc, 88 struct GNUNET_FS_UnindexContext *uc,
89 uint64_t offset) 89 uint64_t offset)
90{ 90{
91 pi->value.unindex.uc = uc; 91 pi->value.unindex.uc = uc;
92 pi->value.unindex.cctx = uc->client_info; 92 pi->value.unindex.cctx = uc->client_info;
@@ -98,6 +98,10 @@ make_unindex_status (struct GNUNET_FS_ProgressInfo *pi,
98 uc->file_size); 98 uc->file_size);
99 pi->value.unindex.duration = GNUNET_TIME_absolute_get_duration (uc->start_time); 99 pi->value.unindex.duration = GNUNET_TIME_absolute_get_duration (uc->start_time);
100 pi->value.unindex.completed = offset; 100 pi->value.unindex.completed = offset;
101 uc->client_info
102 = uc->h->upcb (uc->h->upcb_cls,
103 pi);
104
101} 105}
102 106
103 107
@@ -122,14 +126,11 @@ unindex_progress (void *cls,
122 struct GNUNET_FS_ProgressInfo pi; 126 struct GNUNET_FS_ProgressInfo pi;
123 127
124 pi.status = GNUNET_FS_STATUS_UNINDEX_PROGRESS; 128 pi.status = GNUNET_FS_STATUS_UNINDEX_PROGRESS;
125 make_unindex_status (&pi, uc, offset);
126 pi.value.unindex.specifics.progress.data = pt_block; 129 pi.value.unindex.specifics.progress.data = pt_block;
127 pi.value.unindex.specifics.progress.offset = offset; 130 pi.value.unindex.specifics.progress.offset = offset;
128 pi.value.unindex.specifics.progress.data_len = pt_size; 131 pi.value.unindex.specifics.progress.data_len = pt_size;
129 pi.value.unindex.specifics.progress.depth = depth; 132 pi.value.unindex.specifics.progress.depth = depth;
130 uc->client_info 133 GNUNET_FS_unindex_make_status_ (&pi, uc, offset);
131 = uc->h->upcb (uc->h->upcb_cls,
132 &pi);
133} 134}
134 135
135 136
@@ -147,12 +148,9 @@ signal_unindex_error (struct GNUNET_FS_UnindexContext *uc,
147 struct GNUNET_FS_ProgressInfo pi; 148 struct GNUNET_FS_ProgressInfo pi;
148 149
149 pi.status = GNUNET_FS_STATUS_UNINDEX_ERROR; 150 pi.status = GNUNET_FS_STATUS_UNINDEX_ERROR;
150 make_unindex_status (&pi, uc, 0);
151 pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL; 151 pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL;
152 pi.value.unindex.specifics.error.message = emsg; 152 pi.value.unindex.specifics.error.message = emsg;
153 uc->client_info 153 GNUNET_FS_unindex_make_status_ (&pi, uc, 0);
154 = uc->h->upcb (uc->h->upcb_cls,
155 &pi);
156} 154}
157 155
158 156
@@ -262,11 +260,8 @@ unindex_finish (void *cls,
262 else 260 else
263 { 261 {
264 pi.status = GNUNET_FS_STATUS_UNINDEX_COMPLETED; 262 pi.status = GNUNET_FS_STATUS_UNINDEX_COMPLETED;
265 make_unindex_status (&pi, uc, uc->file_size);
266 pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO; 263 pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO;
267 uc->client_info 264 GNUNET_FS_unindex_make_status_ (&pi, uc, uc->file_size);
268 = uc->h->upcb (uc->h->upcb_cls,
269 &pi);
270 } 265 }
271} 266}
272 267
@@ -284,8 +279,11 @@ process_fs_response (void *cls,
284{ 279{
285 struct GNUNET_FS_UnindexContext *uc = cls; 280 struct GNUNET_FS_UnindexContext *uc = cls;
286 281
287 GNUNET_CLIENT_disconnect (uc->client, GNUNET_NO); 282 if (uc->client != NULL)
288 uc->client = NULL; 283 {
284 GNUNET_CLIENT_disconnect (uc->client, GNUNET_NO);
285 uc->client = NULL;
286 }
289 if (uc->state != UNINDEX_STATE_FS_NOTIFY) 287 if (uc->state != UNINDEX_STATE_FS_NOTIFY)
290 { 288 {
291 GNUNET_FS_unindex_stop (uc); 289 GNUNET_FS_unindex_stop (uc);
@@ -306,6 +304,18 @@ process_fs_response (void *cls,
306 return; 304 return;
307 } 305 }
308 uc->state = UNINDEX_STATE_DS_REMOVE; 306 uc->state = UNINDEX_STATE_DS_REMOVE;
307 GNUNET_FS_unindex_do_remove_ (uc);
308}
309
310
311/**
312 * Connect to the datastore and remove the blocks.
313 *
314 * @param uc context for the unindex operation.
315 */
316void
317GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc)
318{
309 uc->dsh = GNUNET_DATASTORE_connect (uc->h->cfg, 319 uc->dsh = GNUNET_DATASTORE_connect (uc->h->cfg,
310 uc->h->sched); 320 uc->h->sched);
311 if (NULL == uc->dsh) 321 if (NULL == uc->dsh)
@@ -345,9 +355,9 @@ process_fs_response (void *cls,
345 * @param cls closure, unindex context 355 * @param cls closure, unindex context
346 * @param file_id computed hash, NULL on error 356 * @param file_id computed hash, NULL on error
347 */ 357 */
348static void 358void
349process_hash (void *cls, 359GNUNET_FS_unindex_process_hash_ (void *cls,
350 const GNUNET_HashCode *file_id) 360 const GNUNET_HashCode *file_id)
351{ 361{
352 struct GNUNET_FS_UnindexContext *uc = cls; 362 struct GNUNET_FS_UnindexContext *uc = cls;
353 struct UnindexMessage req; 363 struct UnindexMessage req;
@@ -414,16 +424,13 @@ GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h,
414 424
415 // FIXME: make persistent! 425 // FIXME: make persistent!
416 pi.status = GNUNET_FS_STATUS_UNINDEX_START; 426 pi.status = GNUNET_FS_STATUS_UNINDEX_START;
417 make_unindex_status (&pi, ret, 0);
418 pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL; 427 pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL;
419 ret->client_info 428 GNUNET_FS_unindex_make_status_ (&pi, ret, 0);
420 = h->upcb (h->upcb_cls,
421 &pi);
422 GNUNET_CRYPTO_hash_file (h->sched, 429 GNUNET_CRYPTO_hash_file (h->sched,
423 GNUNET_SCHEDULER_PRIORITY_IDLE, 430 GNUNET_SCHEDULER_PRIORITY_IDLE,
424 filename, 431 filename,
425 HASHING_BLOCKSIZE, 432 HASHING_BLOCKSIZE,
426 &process_hash, 433 &GNUNET_FS_unindex_process_hash_,
427 ret); 434 ret);
428 return ret; 435 return ret;
429} 436}
@@ -450,14 +457,11 @@ GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc)
450 GNUNET_FS_remove_sync_file_ (uc->h, "unindex", uc->serialization); 457 GNUNET_FS_remove_sync_file_ (uc->h, "unindex", uc->serialization);
451 uc->serialization = NULL; 458 uc->serialization = NULL;
452 } 459 }
453 make_unindex_status (&pi, uc,
454 (uc->state == UNINDEX_STATE_COMPLETE)
455 ? uc->file_size : 0);
456 pi.status = GNUNET_FS_STATUS_UNINDEX_STOPPED; 460 pi.status = GNUNET_FS_STATUS_UNINDEX_STOPPED;
457 pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO; 461 pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO;
458 uc->client_info 462 GNUNET_FS_unindex_make_status_ (&pi, uc,
459 = uc->h->upcb (uc->h->upcb_cls, 463 (uc->state == UNINDEX_STATE_COMPLETE)
460 &pi); 464 ? uc->file_size : 0);
461 GNUNET_break (NULL == uc->client_info); 465 GNUNET_break (NULL == uc->client_info);
462 GNUNET_free (uc->filename); 466 GNUNET_free (uc->filename);
463 GNUNET_free_non_null (uc->serialization); 467 GNUNET_free_non_null (uc->serialization);