aboutsummaryrefslogtreecommitdiff
path: root/src/fs/fs_unindex.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/fs_unindex.c')
-rw-r--r--src/fs/fs_unindex.c437
1 files changed, 200 insertions, 237 deletions
diff --git a/src/fs/fs_unindex.c b/src/fs/fs_unindex.c
index 83db96932..130b2eae2 100644
--- a/src/fs/fs_unindex.c
+++ b/src/fs/fs_unindex.c
@@ -47,31 +47,22 @@
47 * @return number of bytes copied to buf, 0 on error 47 * @return number of bytes copied to buf, 0 on error
48 */ 48 */
49static size_t 49static size_t
50unindex_reader (void *cls, 50unindex_reader (void *cls, uint64_t offset, size_t max, void *buf, char **emsg)
51 uint64_t offset,
52 size_t max,
53 void *buf,
54 char **emsg)
55{ 51{
56 struct GNUNET_FS_UnindexContext *uc = cls; 52 struct GNUNET_FS_UnindexContext *uc = cls;
57 size_t pt_size; 53 size_t pt_size;
58 54
59 pt_size = GNUNET_MIN(max, 55 pt_size = GNUNET_MIN (max, uc->file_size - offset);
60 uc->file_size - offset); 56 if (offset != GNUNET_DISK_file_seek (uc->fh, offset, GNUNET_DISK_SEEK_SET))
61 if (offset != 57 {
62 GNUNET_DISK_file_seek (uc->fh, offset, GNUNET_DISK_SEEK_SET)) 58 *emsg = GNUNET_strdup (_("Failed to find given position in file"));
63 { 59 return 0;
64 *emsg = GNUNET_strdup (_("Failed to find given position in file")); 60 }
65 return 0; 61 if (pt_size != GNUNET_DISK_file_read (uc->fh, buf, pt_size))
66 } 62 {
67 if (pt_size != 63 *emsg = GNUNET_strdup (_("Failed to read file"));
68 GNUNET_DISK_file_read (uc->fh, 64 return 0;
69 buf, 65 }
70 pt_size))
71 {
72 *emsg = GNUNET_strdup (_("Failed to read file"));
73 return 0;
74 }
75 return pt_size; 66 return pt_size;
76} 67}
77 68
@@ -86,22 +77,19 @@ unindex_reader (void *cls,
86 */ 77 */
87void 78void
88GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi, 79GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
89 struct GNUNET_FS_UnindexContext *uc, 80 struct GNUNET_FS_UnindexContext *uc,
90 uint64_t offset) 81 uint64_t offset)
91{ 82{
92 pi->value.unindex.uc = uc; 83 pi->value.unindex.uc = uc;
93 pi->value.unindex.cctx = uc->client_info; 84 pi->value.unindex.cctx = uc->client_info;
94 pi->value.unindex.filename = uc->filename; 85 pi->value.unindex.filename = uc->filename;
95 pi->value.unindex.size = uc->file_size; 86 pi->value.unindex.size = uc->file_size;
96 pi->value.unindex.eta 87 pi->value.unindex.eta
97 = GNUNET_TIME_calculate_eta (uc->start_time, 88 = GNUNET_TIME_calculate_eta (uc->start_time, offset, uc->file_size);
98 offset, 89 pi->value.unindex.duration =
99 uc->file_size); 90 GNUNET_TIME_absolute_get_duration (uc->start_time);
100 pi->value.unindex.duration = GNUNET_TIME_absolute_get_duration (uc->start_time);
101 pi->value.unindex.completed = offset; 91 pi->value.unindex.completed = offset;
102 uc->client_info 92 uc->client_info = uc->h->upcb (uc->h->upcb_cls, pi);
103 = uc->h->upcb (uc->h->upcb_cls,
104 pi);
105 93
106} 94}
107 95
@@ -118,10 +106,8 @@ GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
118 */ 106 */
119static void 107static void
120unindex_progress (void *cls, 108unindex_progress (void *cls,
121 uint64_t offset, 109 uint64_t offset,
122 const void *pt_block, 110 const void *pt_block, size_t pt_size, unsigned int depth)
123 size_t pt_size,
124 unsigned int depth)
125{ 111{
126 struct GNUNET_FS_UnindexContext *uc = cls; 112 struct GNUNET_FS_UnindexContext *uc = cls;
127 struct GNUNET_FS_ProgressInfo pi; 113 struct GNUNET_FS_ProgressInfo pi;
@@ -133,7 +119,7 @@ unindex_progress (void *cls,
133 pi.value.unindex.specifics.progress.depth = depth; 119 pi.value.unindex.specifics.progress.depth = depth;
134 GNUNET_FS_unindex_make_status_ (&pi, uc, offset); 120 GNUNET_FS_unindex_make_status_ (&pi, uc, offset);
135} 121}
136 122
137 123
138/** 124/**
139 * We've encountered an error during 125 * We've encountered an error during
@@ -145,7 +131,7 @@ static void
145signal_unindex_error (struct GNUNET_FS_UnindexContext *uc) 131signal_unindex_error (struct GNUNET_FS_UnindexContext *uc)
146{ 132{
147 struct GNUNET_FS_ProgressInfo pi; 133 struct GNUNET_FS_ProgressInfo pi;
148 134
149 pi.status = GNUNET_FS_STATUS_UNINDEX_ERROR; 135 pi.status = GNUNET_FS_STATUS_UNINDEX_ERROR;
150 pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL; 136 pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL;
151 pi.value.unindex.specifics.error.message = uc->emsg; 137 pi.value.unindex.specifics.error.message = uc->emsg;
@@ -162,20 +148,19 @@ signal_unindex_error (struct GNUNET_FS_UnindexContext *uc)
162 * @param msg NULL on success, otherwise an error message 148 * @param msg NULL on success, otherwise an error message
163 */ 149 */
164static void 150static void
165process_cont (void *cls, 151process_cont (void *cls, int success, const char *msg)
166 int success,
167 const char *msg)
168{ 152{
169 struct GNUNET_FS_UnindexContext *uc = cls; 153 struct GNUNET_FS_UnindexContext *uc = cls;
154
170 if (success == GNUNET_SYSERR) 155 if (success == GNUNET_SYSERR)
171 { 156 {
172 uc->emsg = GNUNET_strdup (msg); 157 uc->emsg = GNUNET_strdup (msg);
173 signal_unindex_error (uc); 158 signal_unindex_error (uc);
174 return; 159 return;
175 } 160 }
176#if DEBUG_UNINDEX 161#if DEBUG_UNINDEX
177 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 162 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
178 "Datastore REMOVE operation succeeded\n"); 163 "Datastore REMOVE operation succeeded\n");
179#endif 164#endif
180 GNUNET_FS_tree_encoder_next (uc->tc); 165 GNUNET_FS_tree_encoder_next (uc->tc);
181} 166}
@@ -195,14 +180,13 @@ process_cont (void *cls,
195 * @param block the (encrypted) block 180 * @param block the (encrypted) block
196 * @param block_size size of block (in bytes) 181 * @param block_size size of block (in bytes)
197 */ 182 */
198static void 183static void
199unindex_process (void *cls, 184unindex_process (void *cls,
200 const struct ContentHashKey *chk, 185 const struct ContentHashKey *chk,
201 uint64_t offset, 186 uint64_t offset,
202 unsigned int depth, 187 unsigned int depth,
203 enum GNUNET_BLOCK_Type type, 188 enum GNUNET_BLOCK_Type type,
204 const void *block, 189 const void *block, uint16_t block_size)
205 uint16_t block_size)
206{ 190{
207 struct GNUNET_FS_UnindexContext *uc = cls; 191 struct GNUNET_FS_UnindexContext *uc = cls;
208 uint32_t size; 192 uint32_t size;
@@ -210,29 +194,27 @@ unindex_process (void *cls,
210 struct OnDemandBlock odb; 194 struct OnDemandBlock odb;
211 195
212 if (type != GNUNET_BLOCK_TYPE_FS_DBLOCK) 196 if (type != GNUNET_BLOCK_TYPE_FS_DBLOCK)
213 { 197 {
214 size = block_size; 198 size = block_size;
215 data = block; 199 data = block;
216 } 200 }
217 else /* on-demand encoded DBLOCK */ 201 else /* on-demand encoded DBLOCK */
218 { 202 {
219 size = sizeof(struct OnDemandBlock); 203 size = sizeof (struct OnDemandBlock);
220 odb.offset = GNUNET_htonll (offset); 204 odb.offset = GNUNET_htonll (offset);
221 odb.file_id = uc->file_id; 205 odb.file_id = uc->file_id;
222 data = &odb; 206 data = &odb;
223 } 207 }
224#if DEBUG_UNINDEX 208#if DEBUG_UNINDEX
225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 209 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
226 "Sending REMOVE request to DATASTORE service\n"); 210 "Sending REMOVE request to DATASTORE service\n");
227#endif 211#endif
228 GNUNET_DATASTORE_remove (uc->dsh, 212 GNUNET_DATASTORE_remove (uc->dsh,
229 &chk->query, 213 &chk->query,
230 size, 214 size,
231 data, 215 data,
232 -2, 1, 216 -2, 1,
233 GNUNET_CONSTANTS_SERVICE_TIMEOUT, 217 GNUNET_CONSTANTS_SERVICE_TIMEOUT, &process_cont, uc);
234 &process_cont,
235 uc);
236} 218}
237 219
238 220
@@ -244,41 +226,41 @@ unindex_process (void *cls,
244 * @param msg NULL on timeout, otherwise the response 226 * @param msg NULL on timeout, otherwise the response
245 */ 227 */
246static void 228static void
247process_fs_response (void *cls, 229process_fs_response (void *cls, const struct GNUNET_MessageHeader *msg)
248 const struct GNUNET_MessageHeader *msg)
249{ 230{
250 struct GNUNET_FS_UnindexContext *uc = cls; 231 struct GNUNET_FS_UnindexContext *uc = cls;
251 struct GNUNET_FS_ProgressInfo pi; 232 struct GNUNET_FS_ProgressInfo pi;
252 233
253 if (uc->client != NULL) 234 if (uc->client != NULL)
254 { 235 {
255 GNUNET_CLIENT_disconnect (uc->client, GNUNET_NO); 236 GNUNET_CLIENT_disconnect (uc->client, GNUNET_NO);
256 uc->client = NULL; 237 uc->client = NULL;
257 } 238 }
258 if (uc->state != UNINDEX_STATE_FS_NOTIFY) 239 if (uc->state != UNINDEX_STATE_FS_NOTIFY)
259 { 240 {
260 uc->state = UNINDEX_STATE_ERROR; 241 uc->state = UNINDEX_STATE_ERROR;
261 uc->emsg = GNUNET_strdup (_("Unexpected time for a response from `fs' service.")); 242 uc->emsg =
262 GNUNET_FS_unindex_sync_ (uc); 243 GNUNET_strdup (_("Unexpected time for a response from `fs' service."));
263 signal_unindex_error (uc); 244 GNUNET_FS_unindex_sync_ (uc);
264 return; 245 signal_unindex_error (uc);
265 } 246 return;
247 }
266 if (NULL == msg) 248 if (NULL == msg)
267 { 249 {
268 uc->state = UNINDEX_STATE_ERROR; 250 uc->state = UNINDEX_STATE_ERROR;
269 uc->emsg = GNUNET_strdup (_("Timeout waiting for `fs' service.")); 251 uc->emsg = GNUNET_strdup (_("Timeout waiting for `fs' service."));
270 GNUNET_FS_unindex_sync_ (uc); 252 GNUNET_FS_unindex_sync_ (uc);
271 signal_unindex_error (uc); 253 signal_unindex_error (uc);
272 return; 254 return;
273 } 255 }
274 if (ntohs(msg->type) != GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK) 256 if (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK)
275 { 257 {
276 uc->state = UNINDEX_STATE_ERROR; 258 uc->state = UNINDEX_STATE_ERROR;
277 uc->emsg = GNUNET_strdup (_("Invalid response from `fs' service.")); 259 uc->emsg = GNUNET_strdup (_("Invalid response from `fs' service."));
278 GNUNET_FS_unindex_sync_ (uc); 260 GNUNET_FS_unindex_sync_ (uc);
279 signal_unindex_error (uc); 261 signal_unindex_error (uc);
280 return; 262 return;
281 } 263 }
282 uc->state = UNINDEX_STATE_COMPLETE; 264 uc->state = UNINDEX_STATE_COMPLETE;
283 pi.status = GNUNET_FS_STATUS_UNINDEX_COMPLETED; 265 pi.status = GNUNET_FS_STATUS_UNINDEX_COMPLETED;
284 pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO; 266 pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO;
@@ -295,8 +277,7 @@ process_fs_response (void *cls,
295 * @param tc not used 277 * @param tc not used
296 */ 278 */
297static void 279static void
298unindex_finish (void *cls, 280unindex_finish (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
299 const struct GNUNET_SCHEDULER_TaskContext *tc)
300{ 281{
301 struct GNUNET_FS_UnindexContext *uc = cls; 282 struct GNUNET_FS_UnindexContext *uc = cls;
302 char *emsg; 283 char *emsg;
@@ -304,13 +285,8 @@ unindex_finish (void *cls,
304 struct UnindexMessage req; 285 struct UnindexMessage req;
305 286
306 /* generate final progress message */ 287 /* generate final progress message */
307 unindex_progress (uc, 288 unindex_progress (uc, uc->file_size, NULL, 0, 0);
308 uc->file_size, 289 GNUNET_FS_tree_encoder_finish (uc->tc, &uri, &emsg);
309 NULL,
310 0, 0);
311 GNUNET_FS_tree_encoder_finish (uc->tc,
312 &uri,
313 &emsg);
314 uc->tc = NULL; 290 uc->tc = NULL;
315 if (uri != NULL) 291 if (uri != NULL)
316 GNUNET_FS_uri_destroy (uri); 292 GNUNET_FS_uri_destroy (uri);
@@ -320,31 +296,31 @@ unindex_finish (void *cls,
320 uc->dsh = NULL; 296 uc->dsh = NULL;
321 uc->state = UNINDEX_STATE_FS_NOTIFY; 297 uc->state = UNINDEX_STATE_FS_NOTIFY;
322 GNUNET_FS_unindex_sync_ (uc); 298 GNUNET_FS_unindex_sync_ (uc);
323 uc->client = GNUNET_CLIENT_connect ("fs", 299 uc->client = GNUNET_CLIENT_connect ("fs", uc->h->cfg);
324 uc->h->cfg);
325 if (uc->client == NULL) 300 if (uc->client == NULL)
326 { 301 {
327 uc->state = UNINDEX_STATE_ERROR; 302 uc->state = UNINDEX_STATE_ERROR;
328 uc->emsg = GNUNET_strdup (_("Failed to connect to FS service for unindexing.")); 303 uc->emsg =
329 GNUNET_FS_unindex_sync_ (uc); 304 GNUNET_strdup (_("Failed to connect to FS service for unindexing."));
330 signal_unindex_error (uc); 305 GNUNET_FS_unindex_sync_ (uc);
331 return; 306 signal_unindex_error (uc);
332 } 307 return;
308 }
333#if DEBUG_UNINDEX 309#if DEBUG_UNINDEX
334 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 310 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
335 "Sending UNINDEX message to FS service\n"); 311 "Sending UNINDEX message to FS service\n");
336#endif 312#endif
337 req.header.size = htons (sizeof (struct UnindexMessage)); 313 req.header.size = htons (sizeof (struct UnindexMessage));
338 req.header.type = htons (GNUNET_MESSAGE_TYPE_FS_UNINDEX); 314 req.header.type = htons (GNUNET_MESSAGE_TYPE_FS_UNINDEX);
339 req.reserved = 0; 315 req.reserved = 0;
340 req.file_id = uc->file_id; 316 req.file_id = uc->file_id;
341 GNUNET_break (GNUNET_OK == 317 GNUNET_break (GNUNET_OK ==
342 GNUNET_CLIENT_transmit_and_get_response (uc->client, 318 GNUNET_CLIENT_transmit_and_get_response (uc->client,
343 &req.header, 319 &req.header,
344 GNUNET_CONSTANTS_SERVICE_TIMEOUT, 320 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
345 GNUNET_YES, 321 GNUNET_YES,
346 &process_fs_response, 322 &process_fs_response,
347 uc)); 323 uc));
348} 324}
349 325
350 326
@@ -353,38 +329,36 @@ unindex_finish (void *cls,
353 * 329 *
354 * @param uc context for the unindex operation. 330 * @param uc context for the unindex operation.
355 */ 331 */
356void 332void
357GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc) 333GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc)
358{ 334{
359 uc->dsh = GNUNET_DATASTORE_connect (uc->h->cfg); 335 uc->dsh = GNUNET_DATASTORE_connect (uc->h->cfg);
360 if (NULL == uc->dsh) 336 if (NULL == uc->dsh)
361 { 337 {
362 uc->state = UNINDEX_STATE_ERROR; 338 uc->state = UNINDEX_STATE_ERROR;
363 uc->emsg = GNUNET_strdup (_("Failed to connect to `datastore' service.")); 339 uc->emsg = GNUNET_strdup (_("Failed to connect to `datastore' service."));
364 GNUNET_FS_unindex_sync_ (uc); 340 GNUNET_FS_unindex_sync_ (uc);
365 signal_unindex_error (uc); 341 signal_unindex_error (uc);
366 return; 342 return;
367 } 343 }
368 uc->fh = GNUNET_DISK_file_open (uc->filename, 344 uc->fh = GNUNET_DISK_file_open (uc->filename,
369 GNUNET_DISK_OPEN_READ, 345 GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE);
370 GNUNET_DISK_PERM_NONE);
371 if (NULL == uc->fh) 346 if (NULL == uc->fh)
372 { 347 {
373 GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO); 348 GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO);
374 uc->dsh = NULL; 349 uc->dsh = NULL;
375 uc->state = UNINDEX_STATE_ERROR; 350 uc->state = UNINDEX_STATE_ERROR;
376 uc->emsg = GNUNET_strdup (_("Failed to open file for unindexing.")); 351 uc->emsg = GNUNET_strdup (_("Failed to open file for unindexing."));
377 GNUNET_FS_unindex_sync_ (uc); 352 GNUNET_FS_unindex_sync_ (uc);
378 signal_unindex_error (uc); 353 signal_unindex_error (uc);
379 return; 354 return;
380 } 355 }
381 uc->tc = GNUNET_FS_tree_encoder_create (uc->h, 356 uc->tc = GNUNET_FS_tree_encoder_create (uc->h,
382 uc->file_size, 357 uc->file_size,
383 uc, 358 uc,
384 &unindex_reader, 359 &unindex_reader,
385 &unindex_process, 360 &unindex_process,
386 &unindex_progress, 361 &unindex_progress, &unindex_finish);
387 &unindex_finish);
388 GNUNET_FS_tree_encoder_next (uc->tc); 362 GNUNET_FS_tree_encoder_next (uc->tc);
389} 363}
390 364
@@ -396,26 +370,25 @@ GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc)
396 * @param cls closure, unindex context 370 * @param cls closure, unindex context
397 * @param file_id computed hash, NULL on error 371 * @param file_id computed hash, NULL on error
398 */ 372 */
399void 373void
400GNUNET_FS_unindex_process_hash_ (void *cls, 374GNUNET_FS_unindex_process_hash_ (void *cls, const GNUNET_HashCode * file_id)
401 const GNUNET_HashCode *file_id)
402{ 375{
403 struct GNUNET_FS_UnindexContext *uc = cls; 376 struct GNUNET_FS_UnindexContext *uc = cls;
404 377
405 uc->fhc = NULL; 378 uc->fhc = NULL;
406 if (uc->state != UNINDEX_STATE_HASHING) 379 if (uc->state != UNINDEX_STATE_HASHING)
407 { 380 {
408 GNUNET_FS_unindex_stop (uc); 381 GNUNET_FS_unindex_stop (uc);
409 return; 382 return;
410 } 383 }
411 if (file_id == NULL) 384 if (file_id == NULL)
412 { 385 {
413 uc->state = UNINDEX_STATE_ERROR; 386 uc->state = UNINDEX_STATE_ERROR;
414 uc->emsg = GNUNET_strdup (_("Failed to compute hash of file.")); 387 uc->emsg = GNUNET_strdup (_("Failed to compute hash of file."));
415 GNUNET_FS_unindex_sync_ (uc); 388 GNUNET_FS_unindex_sync_ (uc);
416 signal_unindex_error (uc); 389 signal_unindex_error (uc);
417 return; 390 return;
418 } 391 }
419 uc->file_id = *file_id; 392 uc->file_id = *file_id;
420 uc->state = UNINDEX_STATE_DS_REMOVE; 393 uc->state = UNINDEX_STATE_DS_REMOVE;
421 GNUNET_FS_unindex_sync_ (uc); 394 GNUNET_FS_unindex_sync_ (uc);
@@ -436,37 +409,35 @@ GNUNET_FS_unindex_signal_suspend_ (void *cls)
436 struct GNUNET_FS_ProgressInfo pi; 409 struct GNUNET_FS_ProgressInfo pi;
437 410
438 if (uc->fhc != NULL) 411 if (uc->fhc != NULL)
439 { 412 {
440 GNUNET_CRYPTO_hash_file_cancel (uc->fhc); 413 GNUNET_CRYPTO_hash_file_cancel (uc->fhc);
441 uc->fhc = NULL; 414 uc->fhc = NULL;
442 } 415 }
443 if (uc->client != NULL) 416 if (uc->client != NULL)
444 { 417 {
445 GNUNET_CLIENT_disconnect (uc->client, GNUNET_NO); 418 GNUNET_CLIENT_disconnect (uc->client, GNUNET_NO);
446 uc->client = NULL; 419 uc->client = NULL;
447 } 420 }
448 if (NULL != uc->dsh) 421 if (NULL != uc->dsh)
449 { 422 {
450 GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO); 423 GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO);
451 uc->dsh = NULL; 424 uc->dsh = NULL;
452 } 425 }
453 if (NULL != uc->tc) 426 if (NULL != uc->tc)
454 { 427 {
455 GNUNET_FS_tree_encoder_finish (uc->tc, 428 GNUNET_FS_tree_encoder_finish (uc->tc, NULL, NULL);
456 NULL, 429 uc->tc = NULL;
457 NULL); 430 }
458 uc->tc = NULL;
459 }
460 if (uc->fh != NULL) 431 if (uc->fh != NULL)
461 { 432 {
462 GNUNET_DISK_file_close (uc->fh); 433 GNUNET_DISK_file_close (uc->fh);
463 uc->fh = NULL; 434 uc->fh = NULL;
464 } 435 }
465 GNUNET_FS_end_top (uc->h, uc->top); 436 GNUNET_FS_end_top (uc->h, uc->top);
466 pi.status = GNUNET_FS_STATUS_UNINDEX_SUSPEND; 437 pi.status = GNUNET_FS_STATUS_UNINDEX_SUSPEND;
467 GNUNET_FS_unindex_make_status_ (&pi, uc, 438 GNUNET_FS_unindex_make_status_ (&pi, uc,
468 (uc->state == UNINDEX_STATE_COMPLETE) 439 (uc->state == UNINDEX_STATE_COMPLETE)
469 ? uc->file_size : 0); 440 ? uc->file_size : 0);
470 GNUNET_break (NULL == uc->client_info); 441 GNUNET_break (NULL == uc->client_info);
471 GNUNET_free (uc->filename); 442 GNUNET_free (uc->filename);
472 GNUNET_free_non_null (uc->serialization); 443 GNUNET_free_non_null (uc->serialization);
@@ -485,17 +456,13 @@ GNUNET_FS_unindex_signal_suspend_ (void *cls)
485 */ 456 */
486struct GNUNET_FS_UnindexContext * 457struct GNUNET_FS_UnindexContext *
487GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h, 458GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h,
488 const char *filename, 459 const char *filename, void *cctx)
489 void *cctx)
490{ 460{
491 struct GNUNET_FS_UnindexContext *ret; 461 struct GNUNET_FS_UnindexContext *ret;
492 struct GNUNET_FS_ProgressInfo pi; 462 struct GNUNET_FS_ProgressInfo pi;
493 uint64_t size; 463 uint64_t size;
494 464
495 if (GNUNET_OK != 465 if (GNUNET_OK != GNUNET_DISK_file_size (filename, &size, GNUNET_YES))
496 GNUNET_DISK_file_size (filename,
497 &size,
498 GNUNET_YES))
499 return NULL; 466 return NULL;
500 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_UnindexContext)); 467 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_UnindexContext));
501 ret->h = h; 468 ret->h = h;
@@ -508,13 +475,10 @@ GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h,
508 pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL; 475 pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL;
509 GNUNET_FS_unindex_make_status_ (&pi, ret, 0); 476 GNUNET_FS_unindex_make_status_ (&pi, ret, 0);
510 ret->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, 477 ret->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE,
511 filename, 478 filename,
512 HASHING_BLOCKSIZE, 479 HASHING_BLOCKSIZE,
513 &GNUNET_FS_unindex_process_hash_, 480 &GNUNET_FS_unindex_process_hash_, ret);
514 ret); 481 ret->top = GNUNET_FS_make_top (h, &GNUNET_FS_unindex_signal_suspend_, ret);
515 ret->top = GNUNET_FS_make_top (h,
516 &GNUNET_FS_unindex_signal_suspend_,
517 ret);
518 return ret; 482 return ret;
519} 483}
520 484
@@ -526,48 +490,47 @@ GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h,
526 */ 490 */
527void 491void
528GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc) 492GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc)
529{ 493{
530 struct GNUNET_FS_ProgressInfo pi; 494 struct GNUNET_FS_ProgressInfo pi;
531 495
532 if (uc->fhc != NULL) 496 if (uc->fhc != NULL)
533 { 497 {
534 GNUNET_CRYPTO_hash_file_cancel (uc->fhc); 498 GNUNET_CRYPTO_hash_file_cancel (uc->fhc);
535 uc->fhc = NULL; 499 uc->fhc = NULL;
536 } 500 }
537 if (uc->client != NULL) 501 if (uc->client != NULL)
538 { 502 {
539 GNUNET_CLIENT_disconnect (uc->client, GNUNET_NO); 503 GNUNET_CLIENT_disconnect (uc->client, GNUNET_NO);
540 uc->client = NULL; 504 uc->client = NULL;
541 } 505 }
542 if (NULL != uc->dsh) 506 if (NULL != uc->dsh)
543 { 507 {
544 GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO); 508 GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO);
545 uc->dsh = NULL; 509 uc->dsh = NULL;
546 } 510 }
547 if (NULL != uc->tc) 511 if (NULL != uc->tc)
548 { 512 {
549 GNUNET_FS_tree_encoder_finish (uc->tc, 513 GNUNET_FS_tree_encoder_finish (uc->tc, NULL, NULL);
550 NULL, 514 uc->tc = NULL;
551 NULL); 515 }
552 uc->tc = NULL;
553 }
554 if (uc->fh != NULL) 516 if (uc->fh != NULL)
555 { 517 {
556 GNUNET_DISK_file_close (uc->fh); 518 GNUNET_DISK_file_close (uc->fh);
557 uc->fh = NULL; 519 uc->fh = NULL;
558 } 520 }
559 GNUNET_FS_end_top (uc->h, uc->top); 521 GNUNET_FS_end_top (uc->h, uc->top);
560 if (uc->serialization != NULL) 522 if (uc->serialization != NULL)
561 { 523 {
562 GNUNET_FS_remove_sync_file_ (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, uc->serialization); 524 GNUNET_FS_remove_sync_file_ (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
563 GNUNET_free (uc->serialization); 525 uc->serialization);
564 uc->serialization = NULL; 526 GNUNET_free (uc->serialization);
565 } 527 uc->serialization = NULL;
528 }
566 pi.status = GNUNET_FS_STATUS_UNINDEX_STOPPED; 529 pi.status = GNUNET_FS_STATUS_UNINDEX_STOPPED;
567 pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO; 530 pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO;
568 GNUNET_FS_unindex_make_status_ (&pi, uc, 531 GNUNET_FS_unindex_make_status_ (&pi, uc,
569 (uc->state == UNINDEX_STATE_COMPLETE) 532 (uc->state == UNINDEX_STATE_COMPLETE)
570 ? uc->file_size : 0); 533 ? uc->file_size : 0);
571 GNUNET_break (NULL == uc->client_info); 534 GNUNET_break (NULL == uc->client_info);
572 GNUNET_free (uc->filename); 535 GNUNET_free (uc->filename);
573 GNUNET_free (uc); 536 GNUNET_free (uc);