aboutsummaryrefslogtreecommitdiff
path: root/src/fs/fs.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/fs.c')
-rw-r--r--src/fs/fs.c2804
1 files changed, 1318 insertions, 1486 deletions
diff --git a/src/fs/fs.c b/src/fs/fs.c
index 046c4dbb0..318b7088e 100644
--- a/src/fs/fs.c
+++ b/src/fs/fs.c
@@ -43,21 +43,18 @@ start_job (struct GNUNET_FS_QueueEntry *qe)
43 GNUNET_assert (NULL == qe->client); 43 GNUNET_assert (NULL == qe->client);
44 qe->client = GNUNET_CLIENT_connect ("fs", qe->h->cfg); 44 qe->client = GNUNET_CLIENT_connect ("fs", qe->h->cfg);
45 if (qe->client == NULL) 45 if (qe->client == NULL)
46 { 46 {
47 GNUNET_break (0); 47 GNUNET_break (0);
48 return; 48 return;
49 } 49 }
50 qe->start (qe->cls, qe->client); 50 qe->start (qe->cls, qe->client);
51 qe->start_times++; 51 qe->start_times++;
52 qe->h->active_blocks += qe->blocks; 52 qe->h->active_blocks += qe->blocks;
53 qe->start_time = GNUNET_TIME_absolute_get (); 53 qe->start_time = GNUNET_TIME_absolute_get ();
54 GNUNET_CONTAINER_DLL_remove (qe->h->pending_head, 54 GNUNET_CONTAINER_DLL_remove (qe->h->pending_head, qe->h->pending_tail, qe);
55 qe->h->pending_tail,
56 qe);
57 GNUNET_CONTAINER_DLL_insert_after (qe->h->running_head, 55 GNUNET_CONTAINER_DLL_insert_after (qe->h->running_head,
58 qe->h->running_tail, 56 qe->h->running_tail,
59 qe->h->running_tail, 57 qe->h->running_tail, qe);
60 qe);
61} 58}
62 59
63 60
@@ -75,14 +72,12 @@ stop_job (struct GNUNET_FS_QueueEntry *qe)
75 qe->h->active_downloads--; 72 qe->h->active_downloads--;
76 qe->h->active_blocks -= qe->blocks; 73 qe->h->active_blocks -= qe->blocks;
77 qe->run_time = GNUNET_TIME_relative_add (qe->run_time, 74 qe->run_time = GNUNET_TIME_relative_add (qe->run_time,
78 GNUNET_TIME_absolute_get_duration (qe->start_time)); 75 GNUNET_TIME_absolute_get_duration
79 GNUNET_CONTAINER_DLL_remove (qe->h->running_head, 76 (qe->start_time));
80 qe->h->running_tail, 77 GNUNET_CONTAINER_DLL_remove (qe->h->running_head, qe->h->running_tail, qe);
81 qe);
82 GNUNET_CONTAINER_DLL_insert_after (qe->h->pending_head, 78 GNUNET_CONTAINER_DLL_insert_after (qe->h->pending_head,
83 qe->h->pending_tail, 79 qe->h->pending_tail,
84 qe->h->pending_tail, 80 qe->h->pending_tail, qe);
85 qe);
86} 81}
87 82
88 83
@@ -94,8 +89,7 @@ stop_job (struct GNUNET_FS_QueueEntry *qe)
94 * @param tc scheduler context 89 * @param tc scheduler context
95 */ 90 */
96static void 91static void
97process_job_queue (void *cls, 92process_job_queue (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
98 const struct GNUNET_SCHEDULER_TaskContext *tc)
99{ 93{
100 struct GNUNET_FS_Handle *h = cls; 94 struct GNUNET_FS_Handle *h = cls;
101 struct GNUNET_FS_QueueEntry *qe; 95 struct GNUNET_FS_QueueEntry *qe;
@@ -108,40 +102,38 @@ process_job_queue (void *cls,
108 h->queue_job = GNUNET_SCHEDULER_NO_TASK; 102 h->queue_job = GNUNET_SCHEDULER_NO_TASK;
109 next = h->pending_head; 103 next = h->pending_head;
110 while (NULL != (qe = next)) 104 while (NULL != (qe = next))
105 {
106 next = qe->next;
107 if (h->running_head == NULL)
108 {
109 start_job (qe);
110 continue;
111 }
112 if ((qe->blocks + h->active_blocks <= h->max_parallel_requests) &&
113 (h->active_downloads + 1 <= h->max_parallel_downloads))
111 { 114 {
112 next = qe->next; 115 start_job (qe);
113 if (h->running_head == NULL) 116 continue;
114 {
115 start_job (qe);
116 continue;
117 }
118 if ( (qe->blocks + h->active_blocks <= h->max_parallel_requests) &&
119 (h->active_downloads + 1 <= h->max_parallel_downloads) )
120 {
121 start_job (qe);
122 continue;
123 }
124 } 117 }
118 }
125 if (h->pending_head == NULL) 119 if (h->pending_head == NULL)
126 return; /* no need to stop anything */ 120 return; /* no need to stop anything */
127 restart_at = GNUNET_TIME_UNIT_FOREVER_REL; 121 restart_at = GNUNET_TIME_UNIT_FOREVER_REL;
128 next = h->running_head; 122 next = h->running_head;
129 while (NULL != (qe = next)) 123 while (NULL != (qe = next))
130 { 124 {
131 next = qe->next; 125 next = qe->next;
132 run_time = GNUNET_TIME_relative_multiply (h->avg_block_latency, 126 run_time = GNUNET_TIME_relative_multiply (h->avg_block_latency,
133 qe->blocks * qe->start_times); 127 qe->blocks * qe->start_times);
134 end_time = GNUNET_TIME_absolute_add (qe->start_time, 128 end_time = GNUNET_TIME_absolute_add (qe->start_time, run_time);
135 run_time); 129 rst = GNUNET_TIME_absolute_get_remaining (end_time);
136 rst = GNUNET_TIME_absolute_get_remaining (end_time); 130 restart_at = GNUNET_TIME_relative_min (rst, restart_at);
137 restart_at = GNUNET_TIME_relative_min (rst, restart_at); 131 if (rst.rel_value > 0)
138 if (rst.rel_value > 0) 132 continue;
139 continue; 133 stop_job (qe);
140 stop_job (qe); 134 }
141 }
142 h->queue_job = GNUNET_SCHEDULER_add_delayed (restart_at, 135 h->queue_job = GNUNET_SCHEDULER_add_delayed (restart_at,
143 &process_job_queue, 136 &process_job_queue, h);
144 h);
145} 137}
146 138
147 139
@@ -157,10 +149,8 @@ process_job_queue (void *cls,
157 */ 149 */
158struct GNUNET_FS_QueueEntry * 150struct GNUNET_FS_QueueEntry *
159GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h, 151GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h,
160 GNUNET_FS_QueueStart start, 152 GNUNET_FS_QueueStart start,
161 GNUNET_FS_QueueStop stop, 153 GNUNET_FS_QueueStop stop, void *cls, unsigned int blocks)
162 void *cls,
163 unsigned int blocks)
164{ 154{
165 struct GNUNET_FS_QueueEntry *qe; 155 struct GNUNET_FS_QueueEntry *qe;
166 156
@@ -172,14 +162,10 @@ GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h,
172 qe->queue_time = GNUNET_TIME_absolute_get (); 162 qe->queue_time = GNUNET_TIME_absolute_get ();
173 qe->blocks = blocks; 163 qe->blocks = blocks;
174 GNUNET_CONTAINER_DLL_insert_after (h->pending_head, 164 GNUNET_CONTAINER_DLL_insert_after (h->pending_head,
175 h->pending_tail, 165 h->pending_tail, h->pending_tail, qe);
176 h->pending_tail,
177 qe);
178 if (h->queue_job != GNUNET_SCHEDULER_NO_TASK) 166 if (h->queue_job != GNUNET_SCHEDULER_NO_TASK)
179 GNUNET_SCHEDULER_cancel (h->queue_job); 167 GNUNET_SCHEDULER_cancel (h->queue_job);
180 h->queue_job 168 h->queue_job = GNUNET_SCHEDULER_add_now (&process_job_queue, h);
181 = GNUNET_SCHEDULER_add_now (&process_job_queue,
182 h);
183 return qe; 169 return qe;
184} 170}
185 171
@@ -194,17 +180,13 @@ GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qh)
194 struct GNUNET_FS_Handle *h; 180 struct GNUNET_FS_Handle *h;
195 181
196 h = qh->h; 182 h = qh->h;
197 if (qh->client != NULL) 183 if (qh->client != NULL)
198 stop_job (qh); 184 stop_job (qh);
199 GNUNET_CONTAINER_DLL_remove (h->pending_head, 185 GNUNET_CONTAINER_DLL_remove (h->pending_head, h->pending_tail, qh);
200 h->pending_tail,
201 qh);
202 GNUNET_free (qh); 186 GNUNET_free (qh);
203 if (h->queue_job != GNUNET_SCHEDULER_NO_TASK) 187 if (h->queue_job != GNUNET_SCHEDULER_NO_TASK)
204 GNUNET_SCHEDULER_cancel (h->queue_job); 188 GNUNET_SCHEDULER_cancel (h->queue_job);
205 h->queue_job 189 h->queue_job = GNUNET_SCHEDULER_add_now (&process_job_queue, h);
206 = GNUNET_SCHEDULER_add_now (&process_job_queue,
207 h);
208} 190}
209 191
210 192
@@ -218,17 +200,14 @@ GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qh)
218 */ 200 */
219struct TopLevelActivity * 201struct TopLevelActivity *
220GNUNET_FS_make_top (struct GNUNET_FS_Handle *h, 202GNUNET_FS_make_top (struct GNUNET_FS_Handle *h,
221 SuspendSignalFunction ssf, 203 SuspendSignalFunction ssf, void *ssf_cls)
222 void *ssf_cls)
223{ 204{
224 struct TopLevelActivity *ret; 205 struct TopLevelActivity *ret;
225 206
226 ret = GNUNET_malloc (sizeof (struct TopLevelActivity)); 207 ret = GNUNET_malloc (sizeof (struct TopLevelActivity));
227 ret->ssf = ssf; 208 ret->ssf = ssf;
228 ret->ssf_cls = ssf_cls; 209 ret->ssf_cls = ssf_cls;
229 GNUNET_CONTAINER_DLL_insert (h->top_head, 210 GNUNET_CONTAINER_DLL_insert (h->top_head, h->top_tail, ret);
230 h->top_tail,
231 ret);
232 return ret; 211 return ret;
233} 212}
234 213
@@ -240,12 +219,9 @@ GNUNET_FS_make_top (struct GNUNET_FS_Handle *h,
240 * @param top top level activity entry 219 * @param top top level activity entry
241 */ 220 */
242void 221void
243GNUNET_FS_end_top (struct GNUNET_FS_Handle *h, 222GNUNET_FS_end_top (struct GNUNET_FS_Handle *h, struct TopLevelActivity *top)
244 struct TopLevelActivity *top)
245{ 223{
246 GNUNET_CONTAINER_DLL_remove (h->top_head, 224 GNUNET_CONTAINER_DLL_remove (h->top_head, h->top_tail, top);
247 h->top_tail,
248 top);
249 GNUNET_free (top); 225 GNUNET_free (top);
250} 226}
251 227
@@ -285,54 +261,49 @@ struct FileInfo
285 * @return number of bytes written, usually "max", 0 on error 261 * @return number of bytes written, usually "max", 0 on error
286 */ 262 */
287size_t 263size_t
288GNUNET_FS_data_reader_file_(void *cls, 264GNUNET_FS_data_reader_file_ (void *cls,
289 uint64_t offset, 265 uint64_t offset,
290 size_t max, 266 size_t max, void *buf, char **emsg)
291 void *buf,
292 char **emsg)
293{ 267{
294 struct FileInfo *fi = cls; 268 struct FileInfo *fi = cls;
295 ssize_t ret; 269 ssize_t ret;
296 270
297 if (max == 0) 271 if (max == 0)
298 { 272 {
299 if (fi->fd != NULL) 273 if (fi->fd != NULL)
300 GNUNET_DISK_file_close (fi->fd); 274 GNUNET_DISK_file_close (fi->fd);
301 GNUNET_free (fi->filename); 275 GNUNET_free (fi->filename);
302 GNUNET_free (fi); 276 GNUNET_free (fi);
303 return 0; 277 return 0;
304 } 278 }
305 if (fi->fd == NULL) 279 if (fi->fd == NULL)
306 { 280 {
307 fi->fd = GNUNET_DISK_file_open (fi->filename, 281 fi->fd = GNUNET_DISK_file_open (fi->filename,
308 GNUNET_DISK_OPEN_READ, 282 GNUNET_DISK_OPEN_READ,
309 GNUNET_DISK_PERM_NONE); 283 GNUNET_DISK_PERM_NONE);
310 if (fi->fd == NULL) 284 if (fi->fd == NULL)
311 { 285 {
312 GNUNET_asprintf (emsg, 286 GNUNET_asprintf (emsg,
313 _("Could not open file `%s': %s"), 287 _("Could not open file `%s': %s"),
314 fi->filename, 288 fi->filename, STRERROR (errno));
315 STRERROR (errno)); 289 return 0;
316 return 0;
317 }
318 } 290 }
291 }
319 GNUNET_DISK_file_seek (fi->fd, offset, GNUNET_DISK_SEEK_SET); 292 GNUNET_DISK_file_seek (fi->fd, offset, GNUNET_DISK_SEEK_SET);
320 ret = GNUNET_DISK_file_read (fi->fd, buf, max); 293 ret = GNUNET_DISK_file_read (fi->fd, buf, max);
321 if (ret == -1) 294 if (ret == -1)
322 { 295 {
323 GNUNET_asprintf (emsg, 296 GNUNET_asprintf (emsg,
324 _("Could not read file `%s': %s"), 297 _("Could not read file `%s': %s"),
325 fi->filename, 298 fi->filename, STRERROR (errno));
326 STRERROR (errno)); 299 return 0;
327 return 0; 300 }
328 }
329 if (ret != max) 301 if (ret != max)
330 { 302 {
331 GNUNET_asprintf (emsg, 303 GNUNET_asprintf (emsg,
332 _("Short read reading from file `%s'!"), 304 _("Short read reading from file `%s'!"), fi->filename);
333 fi->filename); 305 return 0;
334 return 0; 306 }
335 }
336 return max; 307 return max;
337} 308}
338 309
@@ -348,13 +319,13 @@ GNUNET_FS_make_file_reader_context_ (const char *filename)
348{ 319{
349 struct FileInfo *fi; 320 struct FileInfo *fi;
350 321
351 fi = GNUNET_malloc (sizeof(struct FileInfo)); 322 fi = GNUNET_malloc (sizeof (struct FileInfo));
352 fi->filename = GNUNET_STRINGS_filename_expand (filename); 323 fi->filename = GNUNET_STRINGS_filename_expand (filename);
353 if (fi->filename == NULL) 324 if (fi->filename == NULL)
354 { 325 {
355 GNUNET_free (fi); 326 GNUNET_free (fi);
356 return NULL; 327 return NULL;
357 } 328 }
358 return fi; 329 return fi;
359} 330}
360 331
@@ -376,19 +347,17 @@ GNUNET_FS_make_file_reader_context_ (const char *filename)
376 * @return number of bytes written, usually "max", 0 on error 347 * @return number of bytes written, usually "max", 0 on error
377 */ 348 */
378size_t 349size_t
379GNUNET_FS_data_reader_copy_ (void *cls, 350GNUNET_FS_data_reader_copy_ (void *cls,
380 uint64_t offset, 351 uint64_t offset,
381 size_t max, 352 size_t max, void *buf, char **emsg)
382 void *buf,
383 char **emsg)
384{ 353{
385 char *data = cls; 354 char *data = cls;
386 355
387 if (max == 0) 356 if (max == 0)
388 { 357 {
389 GNUNET_free_non_null (data); 358 GNUNET_free_non_null (data);
390 return 0; 359 return 0;
391 } 360 }
392 memcpy (buf, &data[offset], max); 361 memcpy (buf, &data[offset], max);
393 return max; 362 return max;
394} 363}
@@ -405,29 +374,23 @@ GNUNET_FS_data_reader_copy_ (void *cls,
405 */ 374 */
406static char * 375static char *
407get_serialization_file_name (struct GNUNET_FS_Handle *h, 376get_serialization_file_name (struct GNUNET_FS_Handle *h,
408 const char *ext, 377 const char *ext, const char *ent)
409 const char *ent)
410{ 378{
411 char *basename; 379 char *basename;
412 char *ret; 380 char *ret;
413 381
414 if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) 382 if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
415 return NULL; /* persistence not requested */ 383 return NULL; /* persistence not requested */
416 if (GNUNET_OK != 384 if (GNUNET_OK !=
417 GNUNET_CONFIGURATION_get_value_filename (h->cfg, 385 GNUNET_CONFIGURATION_get_value_filename (h->cfg,
418 "fs", 386 "fs", "STATE_DIR", &basename))
419 "STATE_DIR",
420 &basename))
421 return NULL; 387 return NULL;
422 GNUNET_asprintf (&ret, 388 GNUNET_asprintf (&ret,
423 "%s%s%s%s%s%s%s", 389 "%s%s%s%s%s%s%s",
424 basename, 390 basename,
425 DIR_SEPARATOR_STR, 391 DIR_SEPARATOR_STR,
426 h->client_name, 392 h->client_name,
427 DIR_SEPARATOR_STR, 393 DIR_SEPARATOR_STR, ext, DIR_SEPARATOR_STR, ent);
428 ext,
429 DIR_SEPARATOR_STR,
430 ent);
431 GNUNET_free (basename); 394 GNUNET_free (basename);
432 return ret; 395 return ret;
433} 396}
@@ -446,32 +409,25 @@ get_serialization_file_name (struct GNUNET_FS_Handle *h,
446 */ 409 */
447static char * 410static char *
448get_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h, 411get_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h,
449 const char *ext, 412 const char *ext,
450 const char *uni, 413 const char *uni, const char *ent)
451 const char *ent)
452{ 414{
453 char *basename; 415 char *basename;
454 char *ret; 416 char *ret;
455 417
456 if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) 418 if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
457 return NULL; /* persistence not requested */ 419 return NULL; /* persistence not requested */
458 if (GNUNET_OK != 420 if (GNUNET_OK !=
459 GNUNET_CONFIGURATION_get_value_filename (h->cfg, 421 GNUNET_CONFIGURATION_get_value_filename (h->cfg,
460 "fs", 422 "fs", "STATE_DIR", &basename))
461 "STATE_DIR",
462 &basename))
463 return NULL; 423 return NULL;
464 GNUNET_asprintf (&ret, 424 GNUNET_asprintf (&ret,
465 "%s%s%s%s%s%s%s.dir%s%s", 425 "%s%s%s%s%s%s%s.dir%s%s",
466 basename, 426 basename,
467 DIR_SEPARATOR_STR, 427 DIR_SEPARATOR_STR,
468 h->client_name, 428 h->client_name,
469 DIR_SEPARATOR_STR, 429 DIR_SEPARATOR_STR,
470 ext, 430 ext, DIR_SEPARATOR_STR, uni, DIR_SEPARATOR_STR, ent);
471 DIR_SEPARATOR_STR,
472 uni,
473 DIR_SEPARATOR_STR,
474 ent);
475 GNUNET_free (basename); 431 GNUNET_free (basename);
476 return ret; 432 return ret;
477} 433}
@@ -486,9 +442,7 @@ get_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h,
486 * @return NULL on error 442 * @return NULL on error
487 */ 443 */
488static struct GNUNET_BIO_ReadHandle * 444static struct GNUNET_BIO_ReadHandle *
489get_read_handle (struct GNUNET_FS_Handle *h, 445get_read_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
490 const char *ext,
491 const char *ent)
492{ 446{
493 char *fn; 447 char *fn;
494 struct GNUNET_BIO_ReadHandle *ret; 448 struct GNUNET_BIO_ReadHandle *ret;
@@ -511,18 +465,16 @@ get_read_handle (struct GNUNET_FS_Handle *h,
511 * @return NULL on error 465 * @return NULL on error
512 */ 466 */
513static struct GNUNET_BIO_WriteHandle * 467static struct GNUNET_BIO_WriteHandle *
514get_write_handle (struct GNUNET_FS_Handle *h, 468get_write_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
515 const char *ext,
516 const char *ent)
517{ 469{
518 char *fn; 470 char *fn;
519 struct GNUNET_BIO_WriteHandle *ret; 471 struct GNUNET_BIO_WriteHandle *ret;
520 472
521 fn = get_serialization_file_name (h, ext, ent); 473 fn = get_serialization_file_name (h, ext, ent);
522 if (fn == NULL) 474 if (fn == NULL)
523 { 475 {
524 return NULL; 476 return NULL;
525 } 477 }
526 ret = GNUNET_BIO_write_open (fn); 478 ret = GNUNET_BIO_write_open (fn);
527 if (ret == NULL) 479 if (ret == NULL)
528 GNUNET_break (0); 480 GNUNET_break (0);
@@ -542,9 +494,7 @@ get_write_handle (struct GNUNET_FS_Handle *h,
542 */ 494 */
543static struct GNUNET_BIO_WriteHandle * 495static struct GNUNET_BIO_WriteHandle *
544get_write_handle_in_dir (struct GNUNET_FS_Handle *h, 496get_write_handle_in_dir (struct GNUNET_FS_Handle *h,
545 const char *ext, 497 const char *ext, const char *uni, const char *ent)
546 const char *uni,
547 const char *ent)
548{ 498{
549 char *fn; 499 char *fn;
550 struct GNUNET_BIO_WriteHandle *ret; 500 struct GNUNET_BIO_WriteHandle *ret;
@@ -567,26 +517,22 @@ get_write_handle_in_dir (struct GNUNET_FS_Handle *h,
567 */ 517 */
568void 518void
569GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h, 519GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h,
570 const char *ext, 520 const char *ext, const char *ent)
571 const char *ent)
572{ 521{
573 char *filename; 522 char *filename;
574 523
575 if ( (NULL == ent) || 524 if ((NULL == ent) || (0 == strlen (ent)))
576 (0 == strlen (ent)) ) 525 {
577 { 526 GNUNET_break (0);
578 GNUNET_break (0); 527 return;
579 return; 528 }
580 }
581 filename = get_serialization_file_name (h, ext, ent); 529 filename = get_serialization_file_name (h, ext, ent);
582 if (filename != NULL) 530 if (filename != NULL)
583 { 531 {
584 if (0 != UNLINK (filename)) 532 if (0 != UNLINK (filename))
585 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 533 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
586 "unlink", 534 GNUNET_free (filename);
587 filename); 535 }
588 GNUNET_free (filename);
589 }
590} 536}
591 537
592 538
@@ -600,27 +546,22 @@ GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h,
600 */ 546 */
601static void 547static void
602remove_sync_file_in_dir (struct GNUNET_FS_Handle *h, 548remove_sync_file_in_dir (struct GNUNET_FS_Handle *h,
603 const char *ext, 549 const char *ext, const char *uni, const char *ent)
604 const char *uni,
605 const char *ent)
606{ 550{
607 char *filename; 551 char *filename;
608 552
609 if ( (NULL == ent) || 553 if ((NULL == ent) || (0 == strlen (ent)))
610 (0 == strlen (ent)) ) 554 {
611 { 555 GNUNET_break (0);
612 GNUNET_break (0); 556 return;
613 return; 557 }
614 }
615 filename = get_serialization_file_name_in_dir (h, ext, uni, ent); 558 filename = get_serialization_file_name_in_dir (h, ext, uni, ent);
616 if (filename != NULL) 559 if (filename != NULL)
617 { 560 {
618 if (0 != UNLINK (filename)) 561 if (0 != UNLINK (filename))
619 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 562 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
620 "unlink", 563 GNUNET_free (filename);
621 filename); 564 }
622 GNUNET_free (filename);
623 }
624} 565}
625 566
626 567
@@ -633,8 +574,7 @@ remove_sync_file_in_dir (struct GNUNET_FS_Handle *h,
633 */ 574 */
634void 575void
635GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h, 576GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h,
636 const char *ext, 577 const char *ext, const char *uni)
637 const char *uni)
638{ 578{
639 char *dn; 579 char *dn;
640 580
@@ -643,11 +583,9 @@ GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h,
643 dn = get_serialization_file_name_in_dir (h, ext, uni, ""); 583 dn = get_serialization_file_name_in_dir (h, ext, uni, "");
644 if (dn == NULL) 584 if (dn == NULL)
645 return; 585 return;
646 if ( (GNUNET_OK == GNUNET_DISK_directory_test (dn)) && 586 if ((GNUNET_OK == GNUNET_DISK_directory_test (dn)) &&
647 (GNUNET_OK != GNUNET_DISK_directory_remove (dn)) ) 587 (GNUNET_OK != GNUNET_DISK_directory_remove (dn)))
648 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 588 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rmdir", dn);
649 "rmdir",
650 dn);
651 GNUNET_free (dn); 589 GNUNET_free (dn);
652} 590}
653 591
@@ -668,7 +606,7 @@ GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h,
668 */ 606 */
669static int 607static int
670write_start_time (struct GNUNET_BIO_WriteHandle *wh, 608write_start_time (struct GNUNET_BIO_WriteHandle *wh,
671 struct GNUNET_TIME_Absolute timestamp) 609 struct GNUNET_TIME_Absolute timestamp)
672{ 610{
673 struct GNUNET_TIME_Relative dur; 611 struct GNUNET_TIME_Relative dur;
674 612
@@ -693,14 +631,13 @@ write_start_time (struct GNUNET_BIO_WriteHandle *wh,
693 */ 631 */
694static int 632static int
695read_start_time (struct GNUNET_BIO_ReadHandle *rh, 633read_start_time (struct GNUNET_BIO_ReadHandle *rh,
696 struct GNUNET_TIME_Absolute *timestamp) 634 struct GNUNET_TIME_Absolute *timestamp)
697{ 635{
698 struct GNUNET_TIME_Relative dur; 636 struct GNUNET_TIME_Relative dur;
699 if (GNUNET_OK != 637
700 GNUNET_BIO_read_int64 (rh, &dur.rel_value)) 638 if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dur.rel_value))
701 return GNUNET_SYSERR; 639 return GNUNET_SYSERR;
702 *timestamp = GNUNET_TIME_absolute_subtract (GNUNET_TIME_absolute_get (), 640 *timestamp = GNUNET_TIME_absolute_subtract (GNUNET_TIME_absolute_get (), dur);
703 dur);
704 return GNUNET_OK; 641 return GNUNET_OK;
705} 642}
706 643
@@ -714,9 +651,12 @@ read_start_time (struct GNUNET_BIO_ReadHandle *rh,
714 * the infromation 651 * the infromation
715 * @return NULL on error 652 * @return NULL on error
716 */ 653 */
717static struct GNUNET_FS_FileInformation * 654static struct GNUNET_FS_FileInformation *deserialize_file_information (struct
718deserialize_file_information (struct GNUNET_FS_Handle *h, 655 GNUNET_FS_Handle
719 const char *filename); 656 *h,
657 const
658 char
659 *filename);
720 660
721 661
722/** 662/**
@@ -731,8 +671,7 @@ deserialize_file_information (struct GNUNET_FS_Handle *h,
731 */ 671 */
732static struct GNUNET_FS_FileInformation * 672static struct GNUNET_FS_FileInformation *
733deserialize_fi_node (struct GNUNET_FS_Handle *h, 673deserialize_fi_node (struct GNUNET_FS_Handle *h,
734 const char *fn, 674 const char *fn, struct GNUNET_BIO_ReadHandle *rh)
735 struct GNUNET_BIO_ReadHandle *rh)
736{ 675{
737 struct GNUNET_FS_FileInformation *ret; 676 struct GNUNET_FS_FileInformation *ret;
738 struct GNUNET_FS_FileInformation *nxt; 677 struct GNUNET_FS_FileInformation *nxt;
@@ -742,195 +681,199 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h,
742 char *filename; 681 char *filename;
743 uint32_t dsize; 682 uint32_t dsize;
744 683
745 if (GNUNET_OK != 684 if (GNUNET_OK != GNUNET_BIO_read (rh, "status flag", &b, sizeof (b)))
746 GNUNET_BIO_read (rh, "status flag", &b, sizeof(b))) 685 {
747 { 686 GNUNET_break (0);
748 GNUNET_break (0); 687 return NULL;
749 return NULL; 688 }
750 }
751 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_FileInformation)); 689 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_FileInformation));
752 ret->h = h; 690 ret->h = h;
753 ksks = NULL; 691 ksks = NULL;
754 chks = NULL; 692 chks = NULL;
755 filename = NULL; 693 filename = NULL;
756 if ( (GNUNET_OK != 694 if ((GNUNET_OK !=
757 GNUNET_BIO_read_meta_data (rh, "metadata", &ret->meta)) || 695 GNUNET_BIO_read_meta_data (rh, "metadata", &ret->meta)) ||
758 (GNUNET_OK != 696 (GNUNET_OK !=
759 GNUNET_BIO_read_string (rh, "ksk-uri", &ksks, 32*1024)) || 697 GNUNET_BIO_read_string (rh, "ksk-uri", &ksks, 32 * 1024)) ||
760 ( (ksks != NULL) && 698 ((ksks != NULL) &&
761 (NULL == 699 (NULL ==
762 (ret->keywords = GNUNET_FS_uri_parse (ksks, NULL))) ) || 700 (ret->keywords = GNUNET_FS_uri_parse (ksks, NULL)))) ||
763 (GNUNET_YES != 701 (GNUNET_YES !=
764 GNUNET_FS_uri_test_ksk (ret->keywords)) || 702 GNUNET_FS_uri_test_ksk (ret->keywords)) ||
765 (GNUNET_OK != 703 (GNUNET_OK !=
766 GNUNET_BIO_read_string (rh, "chk-uri", &chks, 1024)) || 704 GNUNET_BIO_read_string (rh, "chk-uri", &chks, 1024)) ||
767 ( (chks != NULL) && 705 ((chks != NULL) &&
768 ( (NULL == 706 ((NULL ==
769 (ret->chk_uri = GNUNET_FS_uri_parse (chks, NULL))) || 707 (ret->chk_uri = GNUNET_FS_uri_parse (chks, NULL))) ||
770 (GNUNET_YES != 708 (GNUNET_YES !=
771 GNUNET_FS_uri_test_chk (ret->chk_uri)) ) ) || 709 GNUNET_FS_uri_test_chk (ret->chk_uri)))) ||
772 (GNUNET_OK != 710 (GNUNET_OK !=
773 read_start_time (rh, &ret->start_time)) || 711 read_start_time (rh, &ret->start_time)) ||
774 (GNUNET_OK != 712 (GNUNET_OK !=
775 GNUNET_BIO_read_string (rh, "emsg", &ret->emsg, 16*1024)) || 713 GNUNET_BIO_read_string (rh, "emsg", &ret->emsg, 16 * 1024)) ||
776 (GNUNET_OK != 714 (GNUNET_OK !=
777 GNUNET_BIO_read_string (rh, "fn", &ret->filename, 16*1024)) || 715 GNUNET_BIO_read_string (rh, "fn", &ret->filename, 16 * 1024)) ||
778 (GNUNET_OK != 716 (GNUNET_OK !=
779 GNUNET_BIO_read_int64 (rh, &ret->bo.expiration_time.abs_value)) || 717 GNUNET_BIO_read_int64 (rh, &ret->bo.expiration_time.abs_value)) ||
780 (GNUNET_OK != 718 (GNUNET_OK !=
781 GNUNET_BIO_read_int32 (rh, &ret->bo.anonymity_level)) || 719 GNUNET_BIO_read_int32 (rh, &ret->bo.anonymity_level)) ||
782 (GNUNET_OK != 720 (GNUNET_OK !=
783 GNUNET_BIO_read_int32 (rh, &ret->bo.content_priority)) || 721 GNUNET_BIO_read_int32 (rh, &ret->bo.content_priority)) ||
784 (GNUNET_OK != 722 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &ret->bo.replication_level)))
785 GNUNET_BIO_read_int32 (rh, &ret->bo.replication_level)) ) 723 {
724 GNUNET_break (0);
725 goto cleanup;
726 }
727 switch (b)
728 {
729 case 0: /* file-insert */
730 if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size))
786 { 731 {
787 GNUNET_break (0); 732 GNUNET_break (0);
788 goto cleanup; 733 goto cleanup;
789 } 734 }
790 switch (b) 735 ret->is_directory = GNUNET_NO;
736 ret->data.file.do_index = GNUNET_NO;
737 ret->data.file.have_hash = GNUNET_NO;
738 ret->data.file.index_start_confirmed = GNUNET_NO;
739 if (GNUNET_NO == ret->is_published)
791 { 740 {
792 case 0: /* file-insert */
793 if (GNUNET_OK !=
794 GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size))
795 {
796 GNUNET_break (0);
797 goto cleanup;
798 }
799 ret->is_directory = GNUNET_NO;
800 ret->data.file.do_index = GNUNET_NO;
801 ret->data.file.have_hash = GNUNET_NO;
802 ret->data.file.index_start_confirmed = GNUNET_NO;
803 if (GNUNET_NO == ret->is_published)
804 {
805 if (NULL == ret->filename)
806 {
807 ret->data.file.reader = &GNUNET_FS_data_reader_copy_;
808 ret->data.file.reader_cls = GNUNET_malloc_large (ret->data.file.file_size);
809 if (ret->data.file.reader_cls == NULL)
810 goto cleanup;
811 if (GNUNET_OK !=
812 GNUNET_BIO_read (rh, "file-data", ret->data.file.reader_cls, ret->data.file.file_size))
813 {
814 GNUNET_break (0);
815 goto cleanup;
816 }
817 }
818 else
819 {
820 ret->data.file.reader = &GNUNET_FS_data_reader_file_;
821 ret->data.file.reader_cls = GNUNET_FS_make_file_reader_context_ (ret->filename);
822 }
823 }
824 break;
825 case 1: /* file-index, no hash */
826 if (NULL == ret->filename)
827 {
828 GNUNET_break (0);
829 goto cleanup;
830 }
831 if (GNUNET_OK !=
832 GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size))
833 {
834 GNUNET_break (0);
835 goto cleanup;
836 }
837 ret->is_directory = GNUNET_NO;
838 ret->data.file.do_index = GNUNET_YES;
839 ret->data.file.have_hash = GNUNET_NO;
840 ret->data.file.index_start_confirmed = GNUNET_NO;
841 ret->data.file.reader = &GNUNET_FS_data_reader_file_;
842 ret->data.file.reader_cls = GNUNET_FS_make_file_reader_context_ (ret->filename);
843 break;
844 case 2: /* file-index-with-hash */
845 if (NULL == ret->filename)
846 {
847 GNUNET_break (0);
848 goto cleanup;
849 }
850 if ( (GNUNET_OK !=
851 GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) ||
852 (GNUNET_OK !=
853 GNUNET_BIO_read (rh, "fileid", &ret->data.file.file_id, sizeof (GNUNET_HashCode))) )
854 {
855 GNUNET_break (0);
856 goto cleanup;
857 }
858 ret->is_directory = GNUNET_NO;
859 ret->data.file.do_index = GNUNET_YES;
860 ret->data.file.have_hash = GNUNET_YES;
861 ret->data.file.index_start_confirmed = GNUNET_NO;
862 ret->data.file.reader = &GNUNET_FS_data_reader_file_;
863 ret->data.file.reader_cls = GNUNET_FS_make_file_reader_context_ (ret->filename);
864 break;
865 case 3: /* file-index-with-hash-confirmed */
866 if (NULL == ret->filename) 741 if (NULL == ret->filename)
867 { 742 {
868 GNUNET_break (0); 743 ret->data.file.reader = &GNUNET_FS_data_reader_copy_;
869 goto cleanup; 744 ret->data.file.reader_cls =
870 } 745 GNUNET_malloc_large (ret->data.file.file_size);
871 if ( (GNUNET_OK != 746 if (ret->data.file.reader_cls == NULL)
872 GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) || 747 goto cleanup;
873 (GNUNET_OK != 748 if (GNUNET_OK !=
874 GNUNET_BIO_read (rh, "fileid", &ret->data.file.file_id, sizeof (GNUNET_HashCode))) ) 749 GNUNET_BIO_read (rh, "file-data", ret->data.file.reader_cls,
875 { 750 ret->data.file.file_size))
876 GNUNET_break (0); 751 {
877 goto cleanup; 752 GNUNET_break (0);
878 } 753 goto cleanup;
879 ret->is_directory = GNUNET_NO; 754 }
880 ret->data.file.do_index = GNUNET_YES; 755 }
881 ret->data.file.have_hash = GNUNET_YES; 756 else
882 ret->data.file.index_start_confirmed = GNUNET_YES; 757 {
883 ret->data.file.reader = &GNUNET_FS_data_reader_file_; 758 ret->data.file.reader = &GNUNET_FS_data_reader_file_;
884 ret->data.file.reader_cls = GNUNET_FS_make_file_reader_context_ (ret->filename); 759 ret->data.file.reader_cls =
885 break; 760 GNUNET_FS_make_file_reader_context_ (ret->filename);
886 case 4: /* directory */ 761 }
887 ret->is_directory = GNUNET_YES; 762 }
888 if ( (GNUNET_OK != 763 break;
889 GNUNET_BIO_read_int32 (rh, &dsize)) || 764 case 1: /* file-index, no hash */
890 (NULL == (ret->data.dir.dir_data = GNUNET_malloc_large (dsize))) || 765 if (NULL == ret->filename)
891 (GNUNET_OK != 766 {
892 GNUNET_BIO_read (rh, "dir-data", ret->data.dir.dir_data, dsize)) ||
893 (GNUNET_OK !=
894 GNUNET_BIO_read_string (rh, "ent-filename", &filename, 16*1024)) )
895 {
896 GNUNET_break (0);
897 goto cleanup;
898 }
899 ret->data.dir.dir_size = (uint32_t) dsize;
900 if (filename != NULL)
901 {
902 ret->data.dir.entries = deserialize_file_information (h, filename);
903 GNUNET_free (filename);
904 filename = NULL;
905 nxt = ret->data.dir.entries;
906 while (nxt != NULL)
907 {
908 nxt->dir = ret;
909 nxt = nxt->next;
910 }
911 }
912 break;
913 default:
914 GNUNET_break (0); 767 GNUNET_break (0);
915 goto cleanup; 768 goto cleanup;
916 } 769 }
917 ret->serialization = GNUNET_strdup (fn); 770 if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size))
918 if (GNUNET_OK !=
919 GNUNET_BIO_read_string (rh, "nxt-filename", &filename, 16*1024))
920 { 771 {
921 GNUNET_break (0); 772 GNUNET_break (0);
922 goto cleanup; 773 goto cleanup;
923 } 774 }
924 if (filename != NULL) 775 ret->is_directory = GNUNET_NO;
776 ret->data.file.do_index = GNUNET_YES;
777 ret->data.file.have_hash = GNUNET_NO;
778 ret->data.file.index_start_confirmed = GNUNET_NO;
779 ret->data.file.reader = &GNUNET_FS_data_reader_file_;
780 ret->data.file.reader_cls =
781 GNUNET_FS_make_file_reader_context_ (ret->filename);
782 break;
783 case 2: /* file-index-with-hash */
784 if (NULL == ret->filename)
925 { 785 {
926 ret->next = deserialize_file_information (h, filename); 786 GNUNET_break (0);
787 goto cleanup;
788 }
789 if ((GNUNET_OK !=
790 GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) ||
791 (GNUNET_OK !=
792 GNUNET_BIO_read (rh, "fileid", &ret->data.file.file_id,
793 sizeof (GNUNET_HashCode))))
794 {
795 GNUNET_break (0);
796 goto cleanup;
797 }
798 ret->is_directory = GNUNET_NO;
799 ret->data.file.do_index = GNUNET_YES;
800 ret->data.file.have_hash = GNUNET_YES;
801 ret->data.file.index_start_confirmed = GNUNET_NO;
802 ret->data.file.reader = &GNUNET_FS_data_reader_file_;
803 ret->data.file.reader_cls =
804 GNUNET_FS_make_file_reader_context_ (ret->filename);
805 break;
806 case 3: /* file-index-with-hash-confirmed */
807 if (NULL == ret->filename)
808 {
809 GNUNET_break (0);
810 goto cleanup;
811 }
812 if ((GNUNET_OK !=
813 GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) ||
814 (GNUNET_OK !=
815 GNUNET_BIO_read (rh, "fileid", &ret->data.file.file_id,
816 sizeof (GNUNET_HashCode))))
817 {
818 GNUNET_break (0);
819 goto cleanup;
820 }
821 ret->is_directory = GNUNET_NO;
822 ret->data.file.do_index = GNUNET_YES;
823 ret->data.file.have_hash = GNUNET_YES;
824 ret->data.file.index_start_confirmed = GNUNET_YES;
825 ret->data.file.reader = &GNUNET_FS_data_reader_file_;
826 ret->data.file.reader_cls =
827 GNUNET_FS_make_file_reader_context_ (ret->filename);
828 break;
829 case 4: /* directory */
830 ret->is_directory = GNUNET_YES;
831 if ((GNUNET_OK !=
832 GNUNET_BIO_read_int32 (rh, &dsize)) ||
833 (NULL == (ret->data.dir.dir_data = GNUNET_malloc_large (dsize))) ||
834 (GNUNET_OK !=
835 GNUNET_BIO_read (rh, "dir-data", ret->data.dir.dir_data, dsize)) ||
836 (GNUNET_OK !=
837 GNUNET_BIO_read_string (rh, "ent-filename", &filename, 16 * 1024)))
838 {
839 GNUNET_break (0);
840 goto cleanup;
841 }
842 ret->data.dir.dir_size = (uint32_t) dsize;
843 if (filename != NULL)
844 {
845 ret->data.dir.entries = deserialize_file_information (h, filename);
927 GNUNET_free (filename); 846 GNUNET_free (filename);
928 filename = NULL; 847 filename = NULL;
929 } 848 nxt = ret->data.dir.entries;
849 while (nxt != NULL)
850 {
851 nxt->dir = ret;
852 nxt = nxt->next;
853 }
854 }
855 break;
856 default:
857 GNUNET_break (0);
858 goto cleanup;
859 }
860 ret->serialization = GNUNET_strdup (fn);
861 if (GNUNET_OK !=
862 GNUNET_BIO_read_string (rh, "nxt-filename", &filename, 16 * 1024))
863 {
864 GNUNET_break (0);
865 goto cleanup;
866 }
867 if (filename != NULL)
868 {
869 ret->next = deserialize_file_information (h, filename);
870 GNUNET_free (filename);
871 filename = NULL;
872 }
930 GNUNET_free_non_null (ksks); 873 GNUNET_free_non_null (ksks);
931 GNUNET_free_non_null (chks); 874 GNUNET_free_non_null (chks);
932 return ret; 875 return ret;
933 cleanup: 876cleanup:
934 GNUNET_free_non_null (ksks); 877 GNUNET_free_non_null (ksks);
935 GNUNET_free_non_null (chks); 878 GNUNET_free_non_null (chks);
936 GNUNET_free_non_null (filename); 879 GNUNET_free_non_null (filename);
@@ -949,8 +892,7 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h,
949 * @return NULL on error 892 * @return NULL on error
950 */ 893 */
951static struct GNUNET_FS_FileInformation * 894static struct GNUNET_FS_FileInformation *
952deserialize_file_information (struct GNUNET_FS_Handle *h, 895deserialize_file_information (struct GNUNET_FS_Handle *h, const char *filename)
953 const char *filename)
954{ 896{
955 struct GNUNET_FS_FileInformation *ret; 897 struct GNUNET_FS_FileInformation *ret;
956 struct GNUNET_BIO_ReadHandle *rh; 898 struct GNUNET_BIO_ReadHandle *rh;
@@ -960,22 +902,18 @@ deserialize_file_information (struct GNUNET_FS_Handle *h,
960 if (rh == NULL) 902 if (rh == NULL)
961 return NULL; 903 return NULL;
962 ret = deserialize_fi_node (h, filename, rh); 904 ret = deserialize_fi_node (h, filename, rh);
963 if (GNUNET_OK != 905 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
964 GNUNET_BIO_read_close (rh, &emsg)) 906 {
965 { 907 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
966 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 908 _("Failed to resume publishing information `%s': %s\n"),
967 _("Failed to resume publishing information `%s': %s\n"), 909 filename, emsg);
968 filename, 910 GNUNET_free (emsg);
969 emsg); 911 }
970 GNUNET_free (emsg);
971 }
972 if (ret == NULL) 912 if (ret == NULL)
973 { 913 {
974 if (0 != UNLINK (filename)) 914 if (0 != UNLINK (filename))
975 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 915 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
976 "unlink", 916 }
977 filename);
978 }
979 return ret; 917 return ret;
980} 918}
981 919
@@ -997,21 +935,20 @@ get_serialization_short_name (const char *fullname)
997 end = NULL; 935 end = NULL;
998 nxt = fullname; 936 nxt = fullname;
999 /* FIXME: we could do this faster since we know 937 /* FIXME: we could do this faster since we know
1000 the length of 'end'... */ 938 * the length of 'end'... */
1001 while ('\0' != *nxt) 939 while ('\0' != *nxt)
1002 { 940 {
1003 if (DIR_SEPARATOR == *nxt) 941 if (DIR_SEPARATOR == *nxt)
1004 end = nxt + 1; 942 end = nxt + 1;
1005 nxt++; 943 nxt++;
1006 } 944 }
1007 if ( (end == NULL) || 945 if ((end == NULL) || (strlen (end) == 0))
1008 (strlen (end) == 0) ) 946 {
1009 { 947 GNUNET_break (0);
1010 GNUNET_break (0); 948 return NULL;
1011 return NULL; 949 }
1012 }
1013 GNUNET_break (6 == strlen (end)); 950 GNUNET_break (6 == strlen (end));
1014 return GNUNET_strdup (end); 951 return GNUNET_strdup (end);
1015} 952}
1016 953
1017 954
@@ -1024,28 +961,26 @@ get_serialization_short_name (const char *fullname)
1024 * @return NULL on errror 961 * @return NULL on errror
1025 */ 962 */
1026static char * 963static char *
1027make_serialization_file_name (struct GNUNET_FS_Handle *h, 964make_serialization_file_name (struct GNUNET_FS_Handle *h, const char *ext)
1028 const char *ext)
1029{ 965{
1030 char *fn; 966 char *fn;
1031 char *dn; 967 char *dn;
1032 char *ret; 968 char *ret;
1033 969
1034 if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) 970 if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
1035 return NULL; /* persistence not requested */ 971 return NULL; /* persistence not requested */
1036 dn = get_serialization_file_name (h, ext, ""); 972 dn = get_serialization_file_name (h, ext, "");
1037 if (dn == NULL) 973 if (dn == NULL)
1038 return NULL; 974 return NULL;
1039 if (GNUNET_OK != 975 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (dn))
1040 GNUNET_DISK_directory_create_for_file (dn)) 976 {
1041 { 977 GNUNET_free (dn);
1042 GNUNET_free (dn); 978 return NULL;
1043 return NULL; 979 }
1044 }
1045 fn = GNUNET_DISK_mktemp (dn); 980 fn = GNUNET_DISK_mktemp (dn);
1046 GNUNET_free (dn); 981 GNUNET_free (dn);
1047 if (fn == NULL) 982 if (fn == NULL)
1048 return NULL; /* epic fail */ 983 return NULL; /* epic fail */
1049 ret = get_serialization_short_name (fn); 984 ret = get_serialization_short_name (fn);
1050 GNUNET_free (fn); 985 GNUNET_free (fn);
1051 return ret; 986 return ret;
@@ -1063,28 +998,26 @@ make_serialization_file_name (struct GNUNET_FS_Handle *h,
1063 */ 998 */
1064static char * 999static char *
1065make_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h, 1000make_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h,
1066 const char *ext, 1001 const char *ext, const char *uni)
1067 const char *uni)
1068{ 1002{
1069 char *fn; 1003 char *fn;
1070 char *dn; 1004 char *dn;
1071 char *ret; 1005 char *ret;
1072 1006
1073 if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) 1007 if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
1074 return NULL; /* persistence not requested */ 1008 return NULL; /* persistence not requested */
1075 dn = get_serialization_file_name_in_dir (h, ext, uni, ""); 1009 dn = get_serialization_file_name_in_dir (h, ext, uni, "");
1076 if (dn == NULL) 1010 if (dn == NULL)
1077 return NULL; 1011 return NULL;
1078 if (GNUNET_OK != 1012 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (dn))
1079 GNUNET_DISK_directory_create_for_file (dn)) 1013 {
1080 { 1014 GNUNET_free (dn);
1081 GNUNET_free (dn); 1015 return NULL;
1082 return NULL; 1016 }
1083 }
1084 fn = GNUNET_DISK_mktemp (dn); 1017 fn = GNUNET_DISK_mktemp (dn);
1085 GNUNET_free (dn); 1018 GNUNET_free (dn);
1086 if (fn == NULL) 1019 if (fn == NULL)
1087 return NULL; /* epic fail */ 1020 return NULL; /* epic fail */
1088 ret = get_serialization_short_name (fn); 1021 ret = get_serialization_short_name (fn);
1089 GNUNET_free (fn); 1022 GNUNET_free (fn);
1090 return ret; 1023 return ret;
@@ -1100,7 +1033,7 @@ make_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h,
1100 */ 1033 */
1101static int 1034static int
1102copy_from_reader (struct GNUNET_BIO_WriteHandle *wh, 1035copy_from_reader (struct GNUNET_BIO_WriteHandle *wh,
1103 struct GNUNET_FS_FileInformation * fi) 1036 struct GNUNET_FS_FileInformation *fi)
1104{ 1037{
1105 char buf[32 * 1024]; 1038 char buf[32 * 1024];
1106 uint64_t off; 1039 uint64_t off;
@@ -1111,22 +1044,19 @@ copy_from_reader (struct GNUNET_BIO_WriteHandle *wh,
1111 emsg = NULL; 1044 emsg = NULL;
1112 off = 0; 1045 off = 0;
1113 while (off < fi->data.file.file_size) 1046 while (off < fi->data.file.file_size)
1047 {
1048 left = GNUNET_MIN (sizeof (buf), fi->data.file.file_size - off);
1049 ret = fi->data.file.reader (fi->data.file.reader_cls,
1050 off, left, buf, &emsg);
1051 if (ret == 0)
1114 { 1052 {
1115 left = GNUNET_MIN (sizeof(buf), fi->data.file.file_size - off); 1053 GNUNET_free (emsg);
1116 ret = fi->data.file.reader (fi->data.file.reader_cls, 1054 return GNUNET_SYSERR;
1117 off, left,
1118 buf,
1119 &emsg);
1120 if (ret == 0)
1121 {
1122 GNUNET_free (emsg);
1123 return GNUNET_SYSERR;
1124 }
1125 if (GNUNET_OK !=
1126 GNUNET_BIO_write (wh, buf, ret))
1127 return GNUNET_SYSERR;
1128 off += ret;
1129 } 1055 }
1056 if (GNUNET_OK != GNUNET_BIO_write (wh, buf, ret))
1057 return GNUNET_SYSERR;
1058 off += ret;
1059 }
1130 return GNUNET_OK; 1060 return GNUNET_OK;
1131} 1061}
1132 1062
@@ -1138,7 +1068,7 @@ copy_from_reader (struct GNUNET_BIO_WriteHandle *wh,
1138 * @param fi file information to sync with disk 1068 * @param fi file information to sync with disk
1139 */ 1069 */
1140void 1070void
1141GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation * fi) 1071GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi)
1142{ 1072{
1143 char *fn; 1073 char *fn;
1144 struct GNUNET_BIO_WriteHandle *wh; 1074 struct GNUNET_BIO_WriteHandle *wh;
@@ -1146,17 +1076,19 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation * fi)
1146 char *ksks; 1076 char *ksks;
1147 char *chks; 1077 char *chks;
1148 1078
1149 if (NULL == fi->serialization) 1079 if (NULL == fi->serialization)
1150 fi->serialization = make_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO); 1080 fi->serialization =
1081 make_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO);
1151 if (NULL == fi->serialization) 1082 if (NULL == fi->serialization)
1152 return; 1083 return;
1153 wh = get_write_handle (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO, fi->serialization); 1084 wh = get_write_handle (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO,
1085 fi->serialization);
1154 if (wh == NULL) 1086 if (wh == NULL)
1155 { 1087 {
1156 GNUNET_free (fi->serialization); 1088 GNUNET_free (fi->serialization);
1157 fi->serialization = NULL; 1089 fi->serialization = NULL;
1158 return; 1090 return;
1159 } 1091 }
1160 if (GNUNET_YES == fi->is_directory) 1092 if (GNUNET_YES == fi->is_directory)
1161 b = 4; 1093 b = 4;
1162 else if (GNUNET_YES == fi->data.file.index_start_confirmed) 1094 else if (GNUNET_YES == fi->data.file.index_start_confirmed)
@@ -1175,131 +1107,130 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation * fi)
1175 chks = GNUNET_FS_uri_to_string (fi->chk_uri); 1107 chks = GNUNET_FS_uri_to_string (fi->chk_uri);
1176 else 1108 else
1177 chks = NULL; 1109 chks = NULL;
1178 if ( (GNUNET_OK != 1110 if ((GNUNET_OK !=
1179 GNUNET_BIO_write (wh, &b, sizeof (b))) || 1111 GNUNET_BIO_write (wh, &b, sizeof (b))) ||
1180 (GNUNET_OK != 1112 (GNUNET_OK !=
1181 GNUNET_BIO_write_meta_data (wh, fi->meta)) || 1113 GNUNET_BIO_write_meta_data (wh, fi->meta)) ||
1182 (GNUNET_OK != 1114 (GNUNET_OK !=
1183 GNUNET_BIO_write_string (wh, ksks)) || 1115 GNUNET_BIO_write_string (wh, ksks)) ||
1184 (GNUNET_OK != 1116 (GNUNET_OK !=
1185 GNUNET_BIO_write_string (wh, chks)) || 1117 GNUNET_BIO_write_string (wh, chks)) ||
1186 (GNUNET_OK != 1118 (GNUNET_OK !=
1187 write_start_time (wh, fi->start_time)) || 1119 write_start_time (wh, fi->start_time)) ||
1188 (GNUNET_OK != 1120 (GNUNET_OK !=
1189 GNUNET_BIO_write_string (wh, fi->emsg)) || 1121 GNUNET_BIO_write_string (wh, fi->emsg)) ||
1190 (GNUNET_OK != 1122 (GNUNET_OK !=
1191 GNUNET_BIO_write_string (wh, fi->filename)) || 1123 GNUNET_BIO_write_string (wh, fi->filename)) ||
1192 (GNUNET_OK != 1124 (GNUNET_OK !=
1193 GNUNET_BIO_write_int64 (wh, fi->bo.expiration_time.abs_value)) || 1125 GNUNET_BIO_write_int64 (wh, fi->bo.expiration_time.abs_value)) ||
1194 (GNUNET_OK != 1126 (GNUNET_OK !=
1195 GNUNET_BIO_write_int32 (wh, fi->bo.anonymity_level)) || 1127 GNUNET_BIO_write_int32 (wh, fi->bo.anonymity_level)) ||
1196 (GNUNET_OK != 1128 (GNUNET_OK !=
1197 GNUNET_BIO_write_int32 (wh, fi->bo.content_priority)) || 1129 GNUNET_BIO_write_int32 (wh, fi->bo.content_priority)) ||
1198 (GNUNET_OK != 1130 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->bo.replication_level)))
1199 GNUNET_BIO_write_int32 (wh, fi->bo.replication_level)) ) 1131 {
1200 { 1132 GNUNET_break (0);
1201 GNUNET_break (0); 1133 goto cleanup;
1202 goto cleanup; 1134 }
1203 }
1204 GNUNET_free_non_null (chks); 1135 GNUNET_free_non_null (chks);
1205 chks = NULL; 1136 chks = NULL;
1206 GNUNET_free_non_null (ksks); 1137 GNUNET_free_non_null (ksks);
1207 ksks = NULL; 1138 ksks = NULL;
1208 1139
1209 switch (b) 1140 switch (b)
1141 {
1142 case 0: /* file-insert */
1143 if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size))
1210 { 1144 {
1211 case 0: /* file-insert */ 1145 GNUNET_break (0);
1212 if (GNUNET_OK !=
1213 GNUNET_BIO_write_int64 (wh, fi->data.file.file_size))
1214 {
1215 GNUNET_break (0);
1216 goto cleanup;
1217 }
1218 if ( (GNUNET_NO == fi->is_published) &&
1219 (NULL == fi->filename) )
1220 if (GNUNET_OK !=
1221 copy_from_reader (wh, fi))
1222 {
1223 GNUNET_break (0);
1224 goto cleanup;
1225 }
1226 break;
1227 case 1: /* file-index, no hash */
1228 if (NULL == fi->filename)
1229 {
1230 GNUNET_break (0);
1231 goto cleanup;
1232 }
1233 if (GNUNET_OK !=
1234 GNUNET_BIO_write_int64 (wh, fi->data.file.file_size))
1235 {
1236 GNUNET_break (0);
1237 goto cleanup;
1238 }
1239 break;
1240 case 2: /* file-index-with-hash */
1241 case 3: /* file-index-with-hash-confirmed */
1242 if (NULL == fi->filename)
1243 {
1244 GNUNET_break (0);
1245 goto cleanup;
1246 }
1247 if ( (GNUNET_OK !=
1248 GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) ||
1249 (GNUNET_OK !=
1250 GNUNET_BIO_write (wh, &fi->data.file.file_id, sizeof (GNUNET_HashCode))) )
1251 {
1252 GNUNET_break (0);
1253 goto cleanup;
1254 }
1255 break;
1256 case 4: /* directory */
1257 if ( (GNUNET_OK !=
1258 GNUNET_BIO_write_int32 (wh, fi->data.dir.dir_size)) ||
1259 (GNUNET_OK !=
1260 GNUNET_BIO_write (wh, fi->data.dir.dir_data, (uint32_t) fi->data.dir.dir_size)) ||
1261 (GNUNET_OK !=
1262 GNUNET_BIO_write_string (wh,
1263 (fi->data.dir.entries == NULL)
1264 ? NULL
1265 : fi->data.dir.entries->serialization)) )
1266 {
1267 GNUNET_break (0);
1268 goto cleanup;
1269 }
1270 break;
1271 default:
1272 GNUNET_assert (0);
1273 goto cleanup; 1146 goto cleanup;
1274 } 1147 }
1275 if (GNUNET_OK != 1148 if ((GNUNET_NO == fi->is_published) && (NULL == fi->filename))
1276 GNUNET_BIO_write_string (wh, (fi->next != NULL) ? fi->next->serialization : NULL)) 1149 if (GNUNET_OK != copy_from_reader (wh, fi))
1150 {
1151 GNUNET_break (0);
1152 goto cleanup;
1153 }
1154 break;
1155 case 1: /* file-index, no hash */
1156 if (NULL == fi->filename)
1277 { 1157 {
1278 GNUNET_break (0); 1158 GNUNET_break (0);
1279 goto cleanup; 1159 goto cleanup;
1280 } 1160 }
1281 if (GNUNET_OK != 1161 if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size))
1282 GNUNET_BIO_write_close (wh)) 1162 {
1163 GNUNET_break (0);
1164 goto cleanup;
1165 }
1166 break;
1167 case 2: /* file-index-with-hash */
1168 case 3: /* file-index-with-hash-confirmed */
1169 if (NULL == fi->filename)
1283 { 1170 {
1284 wh = NULL;
1285 GNUNET_break (0); 1171 GNUNET_break (0);
1286 goto cleanup; 1172 goto cleanup;
1287 } 1173 }
1288 return; /* done! */ 1174 if ((GNUNET_OK !=
1289 cleanup: 1175 GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) ||
1176 (GNUNET_OK !=
1177 GNUNET_BIO_write (wh, &fi->data.file.file_id,
1178 sizeof (GNUNET_HashCode))))
1179 {
1180 GNUNET_break (0);
1181 goto cleanup;
1182 }
1183 break;
1184 case 4: /* directory */
1185 if ((GNUNET_OK !=
1186 GNUNET_BIO_write_int32 (wh, fi->data.dir.dir_size)) ||
1187 (GNUNET_OK !=
1188 GNUNET_BIO_write (wh, fi->data.dir.dir_data,
1189 (uint32_t) fi->data.dir.dir_size)) ||
1190 (GNUNET_OK !=
1191 GNUNET_BIO_write_string (wh,
1192 (fi->data.dir.entries ==
1193 NULL) ? NULL : fi->data.dir.
1194 entries->serialization)))
1195 {
1196 GNUNET_break (0);
1197 goto cleanup;
1198 }
1199 break;
1200 default:
1201 GNUNET_assert (0);
1202 goto cleanup;
1203 }
1204 if (GNUNET_OK !=
1205 GNUNET_BIO_write_string (wh,
1206 (fi->next !=
1207 NULL) ? fi->next->serialization : NULL))
1208 {
1209 GNUNET_break (0);
1210 goto cleanup;
1211 }
1212 if (GNUNET_OK != GNUNET_BIO_write_close (wh))
1213 {
1214 wh = NULL;
1215 GNUNET_break (0);
1216 goto cleanup;
1217 }
1218 return; /* done! */
1219cleanup:
1290 if (wh != NULL) 1220 if (wh != NULL)
1291 (void) GNUNET_BIO_write_close (wh); 1221 (void) GNUNET_BIO_write_close (wh);
1292 GNUNET_free_non_null (chks); 1222 GNUNET_free_non_null (chks);
1293 GNUNET_free_non_null (ksks); 1223 GNUNET_free_non_null (ksks);
1294 fn = get_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO, fi->serialization); 1224 fn = get_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO,
1225 fi->serialization);
1295 if (NULL != fn) 1226 if (NULL != fn)
1296 { 1227 {
1297 if (0 != UNLINK (fn)) 1228 if (0 != UNLINK (fn))
1298 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); 1229 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
1299 GNUNET_free (fn); 1230 GNUNET_free (fn);
1300 } 1231 }
1301 GNUNET_free (fi->serialization); 1232 GNUNET_free (fi->serialization);
1302 fi->serialization = NULL; 1233 fi->serialization = NULL;
1303} 1234}
1304 1235
1305 1236
@@ -1313,25 +1244,22 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation * fi)
1313 * @return NULL if srch was not found in this subtree 1244 * @return NULL if srch was not found in this subtree
1314 */ 1245 */
1315static struct GNUNET_FS_FileInformation * 1246static struct GNUNET_FS_FileInformation *
1316find_file_position (struct GNUNET_FS_FileInformation *pos, 1247find_file_position (struct GNUNET_FS_FileInformation *pos, const char *srch)
1317 const char *srch)
1318{ 1248{
1319 struct GNUNET_FS_FileInformation *r; 1249 struct GNUNET_FS_FileInformation *r;
1320 1250
1321 while (pos != NULL) 1251 while (pos != NULL)
1252 {
1253 if (0 == strcmp (srch, pos->serialization))
1254 return pos;
1255 if (pos->is_directory)
1322 { 1256 {
1323 if (0 == strcmp (srch, 1257 r = find_file_position (pos->data.dir.entries, srch);
1324 pos->serialization)) 1258 if (r != NULL)
1325 return pos; 1259 return r;
1326 if (pos->is_directory)
1327 {
1328 r = find_file_position (pos->data.dir.entries,
1329 srch);
1330 if (r != NULL)
1331 return r;
1332 }
1333 pos = pos->next;
1334 } 1260 }
1261 pos = pos->next;
1262 }
1335 return NULL; 1263 return NULL;
1336} 1264}
1337 1265
@@ -1351,14 +1279,13 @@ find_file_position (struct GNUNET_FS_FileInformation *pos,
1351 * @return GNUNET_OK to continue (always) 1279 * @return GNUNET_OK to continue (always)
1352 */ 1280 */
1353static int 1281static int
1354fip_signal_resume(void *cls, 1282fip_signal_resume (void *cls,
1355 struct GNUNET_FS_FileInformation *fi, 1283 struct GNUNET_FS_FileInformation *fi,
1356 uint64_t length, 1284 uint64_t length,
1357 struct GNUNET_CONTAINER_MetaData *meta, 1285 struct GNUNET_CONTAINER_MetaData *meta,
1358 struct GNUNET_FS_Uri **uri, 1286 struct GNUNET_FS_Uri **uri,
1359 struct GNUNET_FS_BlockOptions *bo, 1287 struct GNUNET_FS_BlockOptions *bo,
1360 int *do_index, 1288 int *do_index, void **client_info)
1361 void **client_info)
1362{ 1289{
1363 struct GNUNET_FS_PublishContext *sc = cls; 1290 struct GNUNET_FS_PublishContext *sc = cls;
1364 struct GNUNET_FS_ProgressInfo pi; 1291 struct GNUNET_FS_ProgressInfo pi;
@@ -1380,8 +1307,7 @@ fip_signal_resume(void *cls,
1380 * @return GNUNET_OK (continue to iterate) 1307 * @return GNUNET_OK (continue to iterate)
1381 */ 1308 */
1382static int 1309static int
1383deserialize_publish_file (void *cls, 1310deserialize_publish_file (void *cls, const char *filename)
1384 const char *filename)
1385{ 1311{
1386 struct GNUNET_FS_Handle *h = cls; 1312 struct GNUNET_FS_Handle *h = cls;
1387 struct GNUNET_BIO_ReadHandle *rh; 1313 struct GNUNET_BIO_ReadHandle *rh;
@@ -1401,117 +1327,109 @@ deserialize_publish_file (void *cls,
1401 ns = NULL; 1327 ns = NULL;
1402 rh = GNUNET_BIO_read_open (filename); 1328 rh = GNUNET_BIO_read_open (filename);
1403 if (rh == NULL) 1329 if (rh == NULL)
1404 { 1330 {
1405 GNUNET_break (0); 1331 GNUNET_break (0);
1406 goto cleanup; 1332 goto cleanup;
1407 } 1333 }
1408 if ( (GNUNET_OK != 1334 if ((GNUNET_OK !=
1409 GNUNET_BIO_read_string (rh, "publish-nid", &pc->nid, 1024)) || 1335 GNUNET_BIO_read_string (rh, "publish-nid", &pc->nid, 1024)) ||
1410 (GNUNET_OK != 1336 (GNUNET_OK !=
1411 GNUNET_BIO_read_string (rh, "publish-nuid", &pc->nuid, 1024)) || 1337 GNUNET_BIO_read_string (rh, "publish-nuid", &pc->nuid, 1024)) ||
1412 (GNUNET_OK != 1338 (GNUNET_OK !=
1413 GNUNET_BIO_read_int32 (rh, &options)) || 1339 GNUNET_BIO_read_int32 (rh, &options)) ||
1414 (GNUNET_OK != 1340 (GNUNET_OK !=
1415 GNUNET_BIO_read_int32 (rh, &all_done)) || 1341 GNUNET_BIO_read_int32 (rh, &all_done)) ||
1416 (GNUNET_OK != 1342 (GNUNET_OK !=
1417 GNUNET_BIO_read_string (rh, "publish-firoot", &fi_root, 128)) || 1343 GNUNET_BIO_read_string (rh, "publish-firoot", &fi_root, 128)) ||
1418 (GNUNET_OK != 1344 (GNUNET_OK !=
1419 GNUNET_BIO_read_string (rh, "publish-fipos", &fi_pos, 128)) || 1345 GNUNET_BIO_read_string (rh, "publish-fipos", &fi_pos, 128)) ||
1420 (GNUNET_OK != 1346 (GNUNET_OK != GNUNET_BIO_read_string (rh, "publish-ns", &ns, 1024)))
1421 GNUNET_BIO_read_string (rh, "publish-ns", &ns, 1024)) ) 1347 {
1422 { 1348 GNUNET_break (0);
1423 GNUNET_break (0); 1349 goto cleanup;
1424 goto cleanup; 1350 }
1425 }
1426 pc->options = options; 1351 pc->options = options;
1427 pc->all_done = all_done; 1352 pc->all_done = all_done;
1428 if (NULL == fi_root) 1353 if (NULL == fi_root)
1429 { 1354 {
1430 GNUNET_break (0); 1355 GNUNET_break (0);
1431 goto cleanup; 1356 goto cleanup;
1432 } 1357 }
1433 pc->fi = deserialize_file_information (h, fi_root); 1358 pc->fi = deserialize_file_information (h, fi_root);
1434 if (pc->fi == NULL) 1359 if (pc->fi == NULL)
1435 { 1360 {
1436 GNUNET_break (0); 1361 GNUNET_break (0);
1437 goto cleanup; 1362 goto cleanup;
1438 } 1363 }
1439 if (ns != NULL) 1364 if (ns != NULL)
1365 {
1366 pc->namespace = GNUNET_FS_namespace_create (h, ns);
1367 if (pc->namespace == NULL)
1440 { 1368 {
1441 pc->namespace = GNUNET_FS_namespace_create (h, ns); 1369 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1442 if (pc->namespace == NULL) 1370 _
1443 { 1371 ("Failed to recover namespace `%s', cannot resume publishing operation.\n"),
1444 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1372 ns);
1445 _("Failed to recover namespace `%s', cannot resume publishing operation.\n"), 1373 goto cleanup;
1446 ns);
1447 goto cleanup;
1448 }
1449 } 1374 }
1450 if ( (0 == (pc->options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) && 1375 }
1451 (GNUNET_YES != pc->all_done) ) 1376 if ((0 == (pc->options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) &&
1452 { 1377 (GNUNET_YES != pc->all_done))
1453 pc->dsh = GNUNET_DATASTORE_connect (h->cfg); 1378 {
1454 if (NULL == pc->dsh) 1379 pc->dsh = GNUNET_DATASTORE_connect (h->cfg);
1455 goto cleanup; 1380 if (NULL == pc->dsh)
1456 } 1381 goto cleanup;
1382 }
1457 if (fi_pos != NULL) 1383 if (fi_pos != NULL)
1384 {
1385 pc->fi_pos = find_file_position (pc->fi, fi_pos);
1386 GNUNET_free (fi_pos);
1387 fi_pos = NULL;
1388 if (pc->fi_pos == NULL)
1458 { 1389 {
1459 pc->fi_pos = find_file_position (pc->fi, 1390 /* failed to find position for resuming, outch! Will start from root! */
1460 fi_pos); 1391 GNUNET_break (0);
1461 GNUNET_free (fi_pos); 1392 if (pc->all_done != GNUNET_YES)
1462 fi_pos = NULL; 1393 pc->fi_pos = pc->fi;
1463 if (pc->fi_pos == NULL)
1464 {
1465 /* failed to find position for resuming, outch! Will start from root! */
1466 GNUNET_break (0);
1467 if (pc->all_done != GNUNET_YES)
1468 pc->fi_pos = pc->fi;
1469 }
1470 } 1394 }
1395 }
1471 GNUNET_free (fi_root); 1396 GNUNET_free (fi_root);
1472 fi_root = NULL; 1397 fi_root = NULL;
1473 /* generate RESUME event(s) */ 1398 /* generate RESUME event(s) */
1474 GNUNET_FS_file_information_inspect (pc->fi, 1399 GNUNET_FS_file_information_inspect (pc->fi, &fip_signal_resume, pc);
1475 &fip_signal_resume, 1400
1476 pc);
1477
1478 /* re-start publishing (if needed)... */ 1401 /* re-start publishing (if needed)... */
1479 if (pc->all_done != GNUNET_YES) 1402 if (pc->all_done != GNUNET_YES)
1480 { 1403 {
1481 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task); 1404 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
1482 pc->upload_task 1405 pc->upload_task
1483 = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, 1406 =
1484 &GNUNET_FS_publish_main_, 1407 GNUNET_SCHEDULER_add_with_priority
1485 pc); 1408 (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, pc);
1486 } 1409 }
1487 if (GNUNET_OK != 1410 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
1488 GNUNET_BIO_read_close (rh, &emsg)) 1411 {
1489 { 1412 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1490 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1413 _("Failure while resuming publishing operation `%s': %s\n"),
1491 _("Failure while resuming publishing operation `%s': %s\n"), 1414 filename, emsg);
1492 filename, 1415 GNUNET_free (emsg);
1493 emsg); 1416 }
1494 GNUNET_free (emsg);
1495 }
1496 GNUNET_free_non_null (ns); 1417 GNUNET_free_non_null (ns);
1497 pc->top = GNUNET_FS_make_top (h, &GNUNET_FS_publish_signal_suspend_, pc); 1418 pc->top = GNUNET_FS_make_top (h, &GNUNET_FS_publish_signal_suspend_, pc);
1498 return GNUNET_OK; 1419 return GNUNET_OK;
1499 cleanup: 1420cleanup:
1500 GNUNET_free_non_null (pc->nid); 1421 GNUNET_free_non_null (pc->nid);
1501 GNUNET_free_non_null (pc->nuid); 1422 GNUNET_free_non_null (pc->nuid);
1502 GNUNET_free_non_null (fi_root); 1423 GNUNET_free_non_null (fi_root);
1503 GNUNET_free_non_null (fi_pos); 1424 GNUNET_free_non_null (fi_pos);
1504 GNUNET_free_non_null (ns); 1425 GNUNET_free_non_null (ns);
1505 if ( (rh != NULL) && 1426 if ((rh != NULL) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)))
1506 (GNUNET_OK != 1427 {
1507 GNUNET_BIO_read_close (rh, &emsg)) ) 1428 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1508 { 1429 _("Failed to resume publishing operation `%s': %s\n"),
1509 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1430 filename, emsg);
1510 _("Failed to resume publishing operation `%s': %s\n"), 1431 GNUNET_free (emsg);
1511 filename, 1432 }
1512 emsg);
1513 GNUNET_free (emsg);
1514 }
1515 if (pc->fi != NULL) 1433 if (pc->fi != NULL)
1516 GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL); 1434 GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL);
1517 if (0 != UNLINK (filename)) 1435 if (0 != UNLINK (filename))
@@ -1532,59 +1450,64 @@ deserialize_publish_file (void *cls,
1532 */ 1450 */
1533void 1451void
1534GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc) 1452GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc)
1535{ 1453{
1536 struct GNUNET_BIO_WriteHandle *wh; 1454 struct GNUNET_BIO_WriteHandle *wh;
1537 1455
1538 if (NULL == pc->serialization) 1456 if (NULL == pc->serialization)
1539 pc->serialization = make_serialization_file_name (pc->h, 1457 pc->serialization = make_serialization_file_name (pc->h,
1540 GNUNET_FS_SYNC_PATH_MASTER_PUBLISH); 1458 GNUNET_FS_SYNC_PATH_MASTER_PUBLISH);
1541 if (NULL == pc->serialization) 1459 if (NULL == pc->serialization)
1542 return; 1460 return;
1543 if (NULL == pc->fi) 1461 if (NULL == pc->fi)
1544 return; 1462 return;
1545 if (NULL == pc->fi->serialization) 1463 if (NULL == pc->fi->serialization)
1546 { 1464 {
1547 GNUNET_break (0); 1465 GNUNET_break (0);
1548 return; 1466 return;
1549 } 1467 }
1550 wh = get_write_handle (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, pc->serialization); 1468 wh = get_write_handle (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH,
1469 pc->serialization);
1551 if (wh == NULL) 1470 if (wh == NULL)
1552 { 1471 {
1553 GNUNET_break (0); 1472 GNUNET_break (0);
1554 goto cleanup; 1473 goto cleanup;
1555 } 1474 }
1556 if ( (GNUNET_OK != 1475 if ((GNUNET_OK !=
1557 GNUNET_BIO_write_string (wh, pc->nid)) || 1476 GNUNET_BIO_write_string (wh, pc->nid)) ||
1558 (GNUNET_OK != 1477 (GNUNET_OK !=
1559 GNUNET_BIO_write_string (wh, pc->nuid)) || 1478 GNUNET_BIO_write_string (wh, pc->nuid)) ||
1560 (GNUNET_OK != 1479 (GNUNET_OK !=
1561 GNUNET_BIO_write_int32 (wh, pc->options)) || 1480 GNUNET_BIO_write_int32 (wh, pc->options)) ||
1562 (GNUNET_OK != 1481 (GNUNET_OK !=
1563 GNUNET_BIO_write_int32 (wh, pc->all_done)) || 1482 GNUNET_BIO_write_int32 (wh, pc->all_done)) ||
1564 (GNUNET_OK != 1483 (GNUNET_OK !=
1565 GNUNET_BIO_write_string (wh, pc->fi->serialization)) || 1484 GNUNET_BIO_write_string (wh, pc->fi->serialization)) ||
1566 (GNUNET_OK != 1485 (GNUNET_OK !=
1567 GNUNET_BIO_write_string (wh, (pc->fi_pos == NULL) ? NULL : pc->fi_pos->serialization)) || 1486 GNUNET_BIO_write_string (wh,
1568 (GNUNET_OK != 1487 (pc->fi_pos ==
1569 GNUNET_BIO_write_string (wh, (pc->namespace == NULL) ? NULL : pc->namespace->name)) ) 1488 NULL) ? NULL : pc->fi_pos->serialization)) ||
1570 { 1489 (GNUNET_OK !=
1571 GNUNET_break (0); 1490 GNUNET_BIO_write_string (wh,
1572 goto cleanup; 1491 (pc->namespace ==
1573 } 1492 NULL) ? NULL : pc->namespace->name)))
1574 if (GNUNET_OK != 1493 {
1575 GNUNET_BIO_write_close (wh)) 1494 GNUNET_break (0);
1576 { 1495 goto cleanup;
1577 wh = NULL; 1496 }
1578 GNUNET_break (0); 1497 if (GNUNET_OK != GNUNET_BIO_write_close (wh))
1579 goto cleanup; 1498 {
1580 } 1499 wh = NULL;
1581 return; 1500 GNUNET_break (0);
1582 cleanup: 1501 goto cleanup;
1583 if (wh != NULL) 1502 }
1584 (void) GNUNET_BIO_write_close (wh); 1503 return;
1585 GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, pc->serialization); 1504cleanup:
1586 GNUNET_free (pc->serialization); 1505 if (wh != NULL)
1587 pc->serialization = NULL; 1506 (void) GNUNET_BIO_write_close (wh);
1507 GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH,
1508 pc->serialization);
1509 GNUNET_free (pc->serialization);
1510 pc->serialization = NULL;
1588} 1511}
1589 1512
1590 1513
@@ -1603,45 +1526,45 @@ GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc)
1603 1526
1604 if (NULL == uc->serialization) 1527 if (NULL == uc->serialization)
1605 uc->serialization = make_serialization_file_name (uc->h, 1528 uc->serialization = make_serialization_file_name (uc->h,
1606 GNUNET_FS_SYNC_PATH_MASTER_UNINDEX); 1529 GNUNET_FS_SYNC_PATH_MASTER_UNINDEX);
1607 if (NULL == uc->serialization) 1530 if (NULL == uc->serialization)
1608 return; 1531 return;
1609 wh = get_write_handle (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, uc->serialization); 1532 wh = get_write_handle (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
1533 uc->serialization);
1610 if (wh == NULL) 1534 if (wh == NULL)
1611 { 1535 {
1612 GNUNET_break (0); 1536 GNUNET_break (0);
1613 goto cleanup; 1537 goto cleanup;
1614 } 1538 }
1615 if ( (GNUNET_OK != 1539 if ((GNUNET_OK !=
1616 GNUNET_BIO_write_string (wh, uc->filename)) || 1540 GNUNET_BIO_write_string (wh, uc->filename)) ||
1617 (GNUNET_OK != 1541 (GNUNET_OK !=
1618 GNUNET_BIO_write_int64 (wh, uc->file_size)) || 1542 GNUNET_BIO_write_int64 (wh, uc->file_size)) ||
1619 (GNUNET_OK != 1543 (GNUNET_OK !=
1620 write_start_time (wh, uc->start_time)) || 1544 write_start_time (wh, uc->start_time)) ||
1621 (GNUNET_OK != 1545 (GNUNET_OK !=
1622 GNUNET_BIO_write_int32 (wh, (uint32_t) uc->state)) || 1546 GNUNET_BIO_write_int32 (wh, (uint32_t) uc->state)) ||
1623 ( (uc->state == UNINDEX_STATE_FS_NOTIFY) && 1547 ((uc->state == UNINDEX_STATE_FS_NOTIFY) &&
1624 (GNUNET_OK != 1548 (GNUNET_OK !=
1625 GNUNET_BIO_write (wh, &uc->file_id, sizeof (GNUNET_HashCode))) ) || 1549 GNUNET_BIO_write (wh, &uc->file_id, sizeof (GNUNET_HashCode)))) ||
1626 ( (uc->state == UNINDEX_STATE_ERROR) && 1550 ((uc->state == UNINDEX_STATE_ERROR) &&
1627 (GNUNET_OK != 1551 (GNUNET_OK != GNUNET_BIO_write_string (wh, uc->emsg))))
1628 GNUNET_BIO_write_string (wh, uc->emsg)) ) ) 1552 {
1629 { 1553 GNUNET_break (0);
1630 GNUNET_break (0); 1554 goto cleanup;
1631 goto cleanup; 1555 }
1632 } 1556 if (GNUNET_OK != GNUNET_BIO_write_close (wh))
1633 if (GNUNET_OK != 1557 {
1634 GNUNET_BIO_write_close (wh)) 1558 wh = NULL;
1635 { 1559 GNUNET_break (0);
1636 wh = NULL; 1560 goto cleanup;
1637 GNUNET_break (0); 1561 }
1638 goto cleanup;
1639 }
1640 return; 1562 return;
1641 cleanup: 1563cleanup:
1642 if (wh != NULL) 1564 if (wh != NULL)
1643 (void) GNUNET_BIO_write_close (wh); 1565 (void) GNUNET_BIO_write_close (wh);
1644 GNUNET_FS_remove_sync_file_ (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, uc->serialization); 1566 GNUNET_FS_remove_sync_file_ (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
1567 uc->serialization);
1645 GNUNET_free (uc->serialization); 1568 GNUNET_free (uc->serialization);
1646 uc->serialization = NULL; 1569 uc->serialization = NULL;
1647} 1570}
@@ -1656,26 +1579,24 @@ GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc)
1656 */ 1579 */
1657static int 1580static int
1658write_download_request (struct GNUNET_BIO_WriteHandle *wh, 1581write_download_request (struct GNUNET_BIO_WriteHandle *wh,
1659 struct DownloadRequest *dr) 1582 struct DownloadRequest *dr)
1660{ 1583{
1661 unsigned int i; 1584 unsigned int i;
1662 1585
1663 if ( (GNUNET_OK != 1586 if ((GNUNET_OK !=
1664 GNUNET_BIO_write_int32 (wh, dr->state)) || 1587 GNUNET_BIO_write_int32 (wh, dr->state)) ||
1665 (GNUNET_OK != 1588 (GNUNET_OK !=
1666 GNUNET_BIO_write_int64 (wh, dr->offset)) || 1589 GNUNET_BIO_write_int64 (wh, dr->offset)) ||
1667 (GNUNET_OK != 1590 (GNUNET_OK !=
1668 GNUNET_BIO_write_int32 (wh, dr->num_children)) || 1591 GNUNET_BIO_write_int32 (wh, dr->num_children)) ||
1669 (GNUNET_OK != 1592 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, dr->depth)))
1670 GNUNET_BIO_write_int32 (wh, dr->depth)) )
1671 return GNUNET_NO;
1672 if ( (dr->state == BRS_CHK_SET) &&
1673 (GNUNET_OK !=
1674 GNUNET_BIO_write (wh, &dr->chk, sizeof (struct ContentHashKey))) )
1675 return GNUNET_NO; 1593 return GNUNET_NO;
1676 for (i=0;i<dr->num_children;i++) 1594 if ((dr->state == BRS_CHK_SET) &&
1677 if (GNUNET_NO == 1595 (GNUNET_OK !=
1678 write_download_request (wh, dr->children[i])) 1596 GNUNET_BIO_write (wh, &dr->chk, sizeof (struct ContentHashKey))))
1597 return GNUNET_NO;
1598 for (i = 0; i < dr->num_children; i++)
1599 if (GNUNET_NO == write_download_request (wh, dr->children[i]))
1679 return GNUNET_NO; 1600 return GNUNET_NO;
1680 return GNUNET_YES; 1601 return GNUNET_YES;
1681} 1602}
@@ -1689,59 +1610,59 @@ write_download_request (struct GNUNET_BIO_WriteHandle *wh,
1689 */ 1610 */
1690static struct DownloadRequest * 1611static struct DownloadRequest *
1691read_download_request (struct GNUNET_BIO_ReadHandle *rh) 1612read_download_request (struct GNUNET_BIO_ReadHandle *rh)
1692{ 1613{
1693 struct DownloadRequest *dr; 1614 struct DownloadRequest *dr;
1694 unsigned int i; 1615 unsigned int i;
1695 1616
1696 dr = GNUNET_malloc (sizeof (struct DownloadRequest)); 1617 dr = GNUNET_malloc (sizeof (struct DownloadRequest));
1697 1618
1698 if ( (GNUNET_OK != 1619 if ((GNUNET_OK !=
1699 GNUNET_BIO_read_int32 (rh, &dr->state)) || 1620 GNUNET_BIO_read_int32 (rh, &dr->state)) ||
1700 (GNUNET_OK != 1621 (GNUNET_OK !=
1701 GNUNET_BIO_read_int64 (rh, &dr->offset)) || 1622 GNUNET_BIO_read_int64 (rh, &dr->offset)) ||
1702 (GNUNET_OK != 1623 (GNUNET_OK !=
1703 GNUNET_BIO_read_int32 (rh, &dr->num_children)) || 1624 GNUNET_BIO_read_int32 (rh, &dr->num_children)) ||
1704 (dr->num_children > CHK_PER_INODE) || 1625 (dr->num_children > CHK_PER_INODE) ||
1705 (GNUNET_OK != 1626 (GNUNET_OK !=
1706 GNUNET_BIO_read_int32 (rh, &dr->depth)) || 1627 GNUNET_BIO_read_int32 (rh, &dr->depth)) ||
1707 ( (dr->depth == 0) && (dr->num_children > 0) ) || 1628 ((dr->depth == 0) && (dr->num_children > 0)) ||
1708 ( (dr->depth > 0) && (dr->num_children == 0) ) ) 1629 ((dr->depth > 0) && (dr->num_children == 0)))
1709 { 1630 {
1710 GNUNET_break (0); 1631 GNUNET_break (0);
1711 dr->num_children = 0; 1632 dr->num_children = 0;
1712 goto cleanup; 1633 goto cleanup;
1713 } 1634 }
1714 if (dr->num_children > 0) 1635 if (dr->num_children > 0)
1715 dr->children = GNUNET_malloc (dr->num_children * 1636 dr->children = GNUNET_malloc (dr->num_children *
1716 sizeof (struct ContentHashKey)); 1637 sizeof (struct ContentHashKey));
1717 switch (dr->state) 1638 switch (dr->state)
1718 { 1639 {
1719 case BRS_INIT: 1640 case BRS_INIT:
1720 case BRS_RECONSTRUCT_DOWN: 1641 case BRS_RECONSTRUCT_DOWN:
1721 case BRS_RECONSTRUCT_META_UP: 1642 case BRS_RECONSTRUCT_META_UP:
1722 case BRS_RECONSTRUCT_UP: 1643 case BRS_RECONSTRUCT_UP:
1723 break; 1644 break;
1724 case BRS_CHK_SET: 1645 case BRS_CHK_SET:
1725 if (GNUNET_OK != 1646 if (GNUNET_OK !=
1726 GNUNET_BIO_read (rh, "chk", &dr->chk, sizeof (struct ContentHashKey))) 1647 GNUNET_BIO_read (rh, "chk", &dr->chk, sizeof (struct ContentHashKey)))
1727 goto cleanup;
1728 break;
1729 case BRS_DOWNLOAD_DOWN:
1730 case BRS_DOWNLOAD_UP:
1731 case BRS_ERROR:
1732 break;
1733 default:
1734 GNUNET_break (0);
1735 goto cleanup; 1648 goto cleanup;
1736 } 1649 break;
1737 for (i=0;i<dr->num_children;i++) 1650 case BRS_DOWNLOAD_DOWN:
1738 { 1651 case BRS_DOWNLOAD_UP:
1739 if (NULL == (dr->children[i] = read_download_request (rh))) 1652 case BRS_ERROR:
1740 goto cleanup; 1653 break;
1741 dr->children[i]->parent = dr; 1654 default:
1742 } 1655 GNUNET_break (0);
1656 goto cleanup;
1657 }
1658 for (i = 0; i < dr->num_children; i++)
1659 {
1660 if (NULL == (dr->children[i] = read_download_request (rh)))
1661 goto cleanup;
1662 dr->children[i]->parent = dr;
1663 }
1743 return dr; 1664 return dr;
1744 cleanup: 1665cleanup:
1745 GNUNET_FS_free_download_request_ (dr); 1666 GNUNET_FS_free_download_request_ (dr);
1746 return NULL; 1667 return NULL;
1747} 1668}
@@ -1758,29 +1679,23 @@ read_download_request (struct GNUNET_BIO_ReadHandle *rh)
1758 */ 1679 */
1759static char * 1680static char *
1760get_download_sync_filename (struct GNUNET_FS_DownloadContext *dc, 1681get_download_sync_filename (struct GNUNET_FS_DownloadContext *dc,
1761 const char *uni, 1682 const char *uni, const char *ext)
1762 const char *ext)
1763{ 1683{
1764 char *par; 1684 char *par;
1765 char *epar; 1685 char *epar;
1766 1686
1767 if (dc->parent == NULL) 1687 if (dc->parent == NULL)
1768 return get_serialization_file_name (dc->h, 1688 return get_serialization_file_name (dc->h,
1769 (dc->search != NULL) ? 1689 (dc->search != NULL) ?
1770 GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD : 1690 GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD :
1771 GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, 1691 GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD,
1772 uni); 1692 uni);
1773 if (dc->parent->serialization == NULL) 1693 if (dc->parent->serialization == NULL)
1774 return NULL; 1694 return NULL;
1775 par = get_download_sync_filename (dc->parent, dc->parent->serialization, ""); 1695 par = get_download_sync_filename (dc->parent, dc->parent->serialization, "");
1776 if (par == NULL) 1696 if (par == NULL)
1777 return NULL; 1697 return NULL;
1778 GNUNET_asprintf (&epar, 1698 GNUNET_asprintf (&epar, "%s.dir%s%s%s", par, DIR_SEPARATOR_STR, uni, ext);
1779 "%s.dir%s%s%s",
1780 par,
1781 DIR_SEPARATOR_STR,
1782 uni,
1783 ext);
1784 GNUNET_free (par); 1699 GNUNET_free (par);
1785 return epar; 1700 return epar;
1786} 1701}
@@ -1802,97 +1717,93 @@ GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc)
1802 char *fn; 1717 char *fn;
1803 char *dir; 1718 char *dir;
1804 1719
1805 if (NULL == dc->serialization) 1720 if (NULL == dc->serialization)
1721 {
1722 dir = get_download_sync_filename (dc, "", "");
1723 if (dir == NULL)
1724 return;
1725 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (dir))
1806 { 1726 {
1807 dir = get_download_sync_filename (dc, "", "");
1808 if (dir == NULL)
1809 return;
1810 if (GNUNET_OK !=
1811 GNUNET_DISK_directory_create_for_file (dir))
1812 {
1813 GNUNET_free (dir);
1814 return;
1815 }
1816 fn = GNUNET_DISK_mktemp (dir);
1817 GNUNET_free (dir); 1727 GNUNET_free (dir);
1818 if (fn == NULL) 1728 return;
1819 return;
1820 dc->serialization = get_serialization_short_name (fn);
1821 } 1729 }
1730 fn = GNUNET_DISK_mktemp (dir);
1731 GNUNET_free (dir);
1732 if (fn == NULL)
1733 return;
1734 dc->serialization = get_serialization_short_name (fn);
1735 }
1822 else 1736 else
1823 { 1737 {
1824 fn = get_download_sync_filename (dc, dc->serialization, ""); 1738 fn = get_download_sync_filename (dc, dc->serialization, "");
1825 if (fn == NULL) 1739 if (fn == NULL)
1826 {
1827 GNUNET_free (dc->serialization);
1828 dc->serialization = NULL;
1829 GNUNET_free (fn);
1830 return;
1831 }
1832 }
1833 wh = GNUNET_BIO_write_open (fn);
1834 if (wh == NULL)
1835 { 1740 {
1836 GNUNET_free (dc->serialization); 1741 GNUNET_free (dc->serialization);
1837 dc->serialization = NULL; 1742 dc->serialization = NULL;
1838 GNUNET_free (fn); 1743 GNUNET_free (fn);
1839 return; 1744 return;
1840 } 1745 }
1841 GNUNET_assert ( (GNUNET_YES == GNUNET_FS_uri_test_chk (dc->uri)) || 1746 }
1842 (GNUNET_YES == GNUNET_FS_uri_test_loc (dc->uri)) ); 1747 wh = GNUNET_BIO_write_open (fn);
1748 if (wh == NULL)
1749 {
1750 GNUNET_free (dc->serialization);
1751 dc->serialization = NULL;
1752 GNUNET_free (fn);
1753 return;
1754 }
1755 GNUNET_assert ((GNUNET_YES == GNUNET_FS_uri_test_chk (dc->uri)) ||
1756 (GNUNET_YES == GNUNET_FS_uri_test_loc (dc->uri)));
1843 uris = GNUNET_FS_uri_to_string (dc->uri); 1757 uris = GNUNET_FS_uri_to_string (dc->uri);
1844 if ( (GNUNET_OK != 1758 if ((GNUNET_OK !=
1845 GNUNET_BIO_write_string (wh, uris)) || 1759 GNUNET_BIO_write_string (wh, uris)) ||
1846 (GNUNET_OK != 1760 (GNUNET_OK !=
1847 GNUNET_BIO_write_meta_data (wh, dc->meta)) || 1761 GNUNET_BIO_write_meta_data (wh, dc->meta)) ||
1848 (GNUNET_OK != 1762 (GNUNET_OK !=
1849 GNUNET_BIO_write_string (wh, dc->emsg)) || 1763 GNUNET_BIO_write_string (wh, dc->emsg)) ||
1850 (GNUNET_OK != 1764 (GNUNET_OK !=
1851 GNUNET_BIO_write_string (wh, dc->filename)) || 1765 GNUNET_BIO_write_string (wh, dc->filename)) ||
1852 (GNUNET_OK != 1766 (GNUNET_OK !=
1853 GNUNET_BIO_write_string (wh, dc->temp_filename)) || 1767 GNUNET_BIO_write_string (wh, dc->temp_filename)) ||
1854 (GNUNET_OK != 1768 (GNUNET_OK !=
1855 GNUNET_BIO_write_int64 (wh, dc->old_file_size)) || 1769 GNUNET_BIO_write_int64 (wh, dc->old_file_size)) ||
1856 (GNUNET_OK != 1770 (GNUNET_OK !=
1857 GNUNET_BIO_write_int64 (wh, dc->offset)) || 1771 GNUNET_BIO_write_int64 (wh, dc->offset)) ||
1858 (GNUNET_OK != 1772 (GNUNET_OK !=
1859 GNUNET_BIO_write_int64 (wh, dc->length)) || 1773 GNUNET_BIO_write_int64 (wh, dc->length)) ||
1860 (GNUNET_OK != 1774 (GNUNET_OK !=
1861 GNUNET_BIO_write_int64 (wh, dc->completed)) || 1775 GNUNET_BIO_write_int64 (wh, dc->completed)) ||
1862 (GNUNET_OK != 1776 (GNUNET_OK !=
1863 write_start_time (wh, dc->start_time)) || 1777 write_start_time (wh, dc->start_time)) ||
1864 (GNUNET_OK != 1778 (GNUNET_OK !=
1865 GNUNET_BIO_write_int32 (wh, dc->anonymity)) || 1779 GNUNET_BIO_write_int32 (wh, dc->anonymity)) ||
1866 (GNUNET_OK != 1780 (GNUNET_OK !=
1867 GNUNET_BIO_write_int32 (wh, (uint32_t) dc->options)) || 1781 GNUNET_BIO_write_int32 (wh, (uint32_t) dc->options)) ||
1868 (GNUNET_OK != 1782 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) dc->has_finished)))
1869 GNUNET_BIO_write_int32 (wh, (uint32_t) dc->has_finished)) ) 1783 {
1870 { 1784 GNUNET_break (0);
1871 GNUNET_break (0); 1785 goto cleanup;
1872 goto cleanup; 1786 }
1873 }
1874 if (NULL == dc->emsg) 1787 if (NULL == dc->emsg)
1788 {
1789 GNUNET_assert (dc->top_request != NULL);
1790 if (GNUNET_YES != write_download_request (wh, dc->top_request))
1875 { 1791 {
1876 GNUNET_assert (dc->top_request != NULL);
1877 if (GNUNET_YES !=
1878 write_download_request (wh, dc->top_request))
1879 {
1880 GNUNET_break (0);
1881 goto cleanup;
1882 }
1883 }
1884 GNUNET_free_non_null (uris);
1885 uris = NULL;
1886 if (GNUNET_OK !=
1887 GNUNET_BIO_write_close (wh))
1888 {
1889 wh = NULL;
1890 GNUNET_break (0); 1792 GNUNET_break (0);
1891 goto cleanup; 1793 goto cleanup;
1892 } 1794 }
1795 }
1796 GNUNET_free_non_null (uris);
1797 uris = NULL;
1798 if (GNUNET_OK != GNUNET_BIO_write_close (wh))
1799 {
1800 wh = NULL;
1801 GNUNET_break (0);
1802 goto cleanup;
1803 }
1893 GNUNET_free (fn); 1804 GNUNET_free (fn);
1894 return; 1805 return;
1895 cleanup: 1806cleanup:
1896 if (NULL != wh) 1807 if (NULL != wh)
1897 (void) GNUNET_BIO_write_close (wh); 1808 (void) GNUNET_BIO_write_close (wh);
1898 GNUNET_free_non_null (uris); 1809 GNUNET_free_non_null (uris);
@@ -1921,65 +1832,65 @@ GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr)
1921 uris = NULL; 1832 uris = NULL;
1922 if (NULL == sr->serialization) 1833 if (NULL == sr->serialization)
1923 sr->serialization = make_serialization_file_name_in_dir (sr->sc->h, 1834 sr->serialization = make_serialization_file_name_in_dir (sr->sc->h,
1924 (sr->sc->psearch_result == NULL) 1835 (sr->
1925 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH 1836 sc->psearch_result
1926 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, 1837 ==
1927 sr->sc->serialization); 1838 NULL) ?
1839 GNUNET_FS_SYNC_PATH_MASTER_SEARCH
1840 :
1841 GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
1842 sr->
1843 sc->serialization);
1928 if (NULL == sr->serialization) 1844 if (NULL == sr->serialization)
1929 return; 1845 return;
1930 wh = get_write_handle_in_dir (sr->sc->h, 1846 wh = get_write_handle_in_dir (sr->sc->h,
1931 (sr->sc->psearch_result == NULL) 1847 (sr->sc->psearch_result == NULL)
1932 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH 1848 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
1933 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, 1849 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
1934 sr->sc->serialization, 1850 sr->sc->serialization, sr->serialization);
1935 sr->serialization);
1936 if (wh == NULL) 1851 if (wh == NULL)
1937 { 1852 {
1938 GNUNET_break (0); 1853 GNUNET_break (0);
1939 goto cleanup; 1854 goto cleanup;
1940 } 1855 }
1941 uris = GNUNET_FS_uri_to_string (sr->uri); 1856 uris = GNUNET_FS_uri_to_string (sr->uri);
1942 if ( (GNUNET_OK != 1857 if ((GNUNET_OK !=
1943 GNUNET_BIO_write_string (wh, uris)) || 1858 GNUNET_BIO_write_string (wh, uris)) ||
1944 (GNUNET_OK != 1859 (GNUNET_OK !=
1945 GNUNET_BIO_write_string (wh, sr->download != NULL ? sr->download->serialization : NULL)) || 1860 GNUNET_BIO_write_string (wh,
1946 (GNUNET_OK != 1861 sr->download !=
1947 GNUNET_BIO_write_string (wh, sr->update_search != NULL ? sr->update_search->serialization : NULL)) || 1862 NULL ? sr->download->serialization : NULL)) ||
1948 (GNUNET_OK != 1863 (GNUNET_OK !=
1949 GNUNET_BIO_write_meta_data (wh, sr->meta)) || 1864 GNUNET_BIO_write_string (wh,
1950 (GNUNET_OK != 1865 sr->update_search !=
1951 GNUNET_BIO_write (wh, &sr->key, sizeof (GNUNET_HashCode))) || 1866 NULL ? sr->update_search->serialization : NULL))
1952 (GNUNET_OK != 1867 || (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, sr->meta)) ||
1953 GNUNET_BIO_write_int32 (wh, sr->mandatory_missing)) || 1868 (GNUNET_OK != GNUNET_BIO_write (wh, &sr->key, sizeof (GNUNET_HashCode)))
1954 (GNUNET_OK != 1869 || (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->mandatory_missing)) ||
1955 GNUNET_BIO_write_int32 (wh, sr->optional_support)) || 1870 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->optional_support)) ||
1956 (GNUNET_OK != 1871 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->availability_success)) ||
1957 GNUNET_BIO_write_int32 (wh, sr->availability_success)) || 1872 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->availability_trials)))
1958 (GNUNET_OK != 1873 {
1959 GNUNET_BIO_write_int32 (wh, sr->availability_trials)) ) 1874 GNUNET_break (0);
1960 { 1875 goto cleanup;
1961 GNUNET_break (0); 1876 }
1962 goto cleanup; 1877 if (GNUNET_OK != GNUNET_BIO_write_close (wh))
1963 } 1878 {
1964 if (GNUNET_OK != 1879 wh = NULL;
1965 GNUNET_BIO_write_close (wh)) 1880 GNUNET_break (0);
1966 { 1881 goto cleanup;
1967 wh = NULL; 1882 }
1968 GNUNET_break (0);
1969 goto cleanup;
1970 }
1971 GNUNET_free_non_null (uris); 1883 GNUNET_free_non_null (uris);
1972 return; 1884 return;
1973 cleanup: 1885cleanup:
1974 GNUNET_free_non_null (uris); 1886 GNUNET_free_non_null (uris);
1975 if (wh != NULL) 1887 if (wh != NULL)
1976 (void) GNUNET_BIO_write_close (wh); 1888 (void) GNUNET_BIO_write_close (wh);
1977 remove_sync_file_in_dir (sr->sc->h, 1889 remove_sync_file_in_dir (sr->sc->h,
1978 (sr->sc->psearch_result == NULL) 1890 (sr->sc->psearch_result == NULL)
1979 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH 1891 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
1980 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, 1892 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
1981 sr->sc->serialization, 1893 sr->sc->serialization, sr->serialization);
1982 sr->serialization);
1983 GNUNET_free (sr->serialization); 1894 GNUNET_free (sr->serialization);
1984 sr->serialization = NULL; 1895 sr->serialization = NULL;
1985} 1896}
@@ -1995,58 +1906,54 @@ GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr)
1995 */ 1906 */
1996void 1907void
1997GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc) 1908GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc)
1998{ 1909{
1999 struct GNUNET_BIO_WriteHandle *wh; 1910 struct GNUNET_BIO_WriteHandle *wh;
2000 char *uris; 1911 char *uris;
2001 char in_pause; 1912 char in_pause;
2002 const char *category; 1913 const char *category;
2003 1914
2004 category = (sc->psearch_result == NULL) 1915 category = (sc->psearch_result == NULL)
2005 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH 1916 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH : GNUNET_FS_SYNC_PATH_CHILD_SEARCH;
2006 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH;
2007 if (NULL == sc->serialization) 1917 if (NULL == sc->serialization)
2008 sc->serialization = make_serialization_file_name (sc->h, 1918 sc->serialization = make_serialization_file_name (sc->h, category);
2009 category);
2010 if (NULL == sc->serialization) 1919 if (NULL == sc->serialization)
2011 return; 1920 return;
2012 uris = NULL; 1921 uris = NULL;
2013 wh = get_write_handle (sc->h, category, sc->serialization); 1922 wh = get_write_handle (sc->h, category, sc->serialization);
2014 if (wh == NULL) 1923 if (wh == NULL)
2015 { 1924 {
2016 GNUNET_break (0); 1925 GNUNET_break (0);
2017 goto cleanup; 1926 goto cleanup;
2018 } 1927 }
2019 GNUNET_assert ( (GNUNET_YES == GNUNET_FS_uri_test_ksk (sc->uri)) || 1928 GNUNET_assert ((GNUNET_YES == GNUNET_FS_uri_test_ksk (sc->uri)) ||
2020 (GNUNET_YES == GNUNET_FS_uri_test_sks (sc->uri)) ); 1929 (GNUNET_YES == GNUNET_FS_uri_test_sks (sc->uri)));
2021 uris = GNUNET_FS_uri_to_string (sc->uri); 1930 uris = GNUNET_FS_uri_to_string (sc->uri);
2022 in_pause = (sc->task != GNUNET_SCHEDULER_NO_TASK) ? 'r' : '\0'; 1931 in_pause = (sc->task != GNUNET_SCHEDULER_NO_TASK) ? 'r' : '\0';
2023 if ( (GNUNET_OK != 1932 if ((GNUNET_OK !=
2024 GNUNET_BIO_write_string (wh, uris)) || 1933 GNUNET_BIO_write_string (wh, uris)) ||
2025 (GNUNET_OK != 1934 (GNUNET_OK !=
2026 write_start_time (wh, sc->start_time)) || 1935 write_start_time (wh, sc->start_time)) ||
2027 (GNUNET_OK != 1936 (GNUNET_OK !=
2028 GNUNET_BIO_write_string (wh, sc->emsg)) || 1937 GNUNET_BIO_write_string (wh, sc->emsg)) ||
2029 (GNUNET_OK != 1938 (GNUNET_OK !=
2030 GNUNET_BIO_write_int32 (wh, (uint32_t) sc->options)) || 1939 GNUNET_BIO_write_int32 (wh, (uint32_t) sc->options)) ||
2031 (GNUNET_OK != 1940 (GNUNET_OK !=
2032 GNUNET_BIO_write (wh, &in_pause, sizeof (in_pause))) || 1941 GNUNET_BIO_write (wh, &in_pause, sizeof (in_pause))) ||
2033 (GNUNET_OK != 1942 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sc->anonymity)))
2034 GNUNET_BIO_write_int32 (wh, sc->anonymity)) ) 1943 {
2035 { 1944 GNUNET_break (0);
2036 GNUNET_break (0); 1945 goto cleanup;
2037 goto cleanup; 1946 }
2038 }
2039 GNUNET_free (uris); 1947 GNUNET_free (uris);
2040 uris = NULL; 1948 uris = NULL;
2041 if (GNUNET_OK != 1949 if (GNUNET_OK != GNUNET_BIO_write_close (wh))
2042 GNUNET_BIO_write_close (wh)) 1950 {
2043 { 1951 wh = NULL;
2044 wh = NULL; 1952 GNUNET_break (0);
2045 GNUNET_break (0); 1953 goto cleanup;
2046 goto cleanup; 1954 }
2047 }
2048 return; 1955 return;
2049 cleanup: 1956cleanup:
2050 if (wh != NULL) 1957 if (wh != NULL)
2051 (void) GNUNET_BIO_write_close (wh); 1958 (void) GNUNET_BIO_write_close (wh);
2052 GNUNET_free_non_null (uris); 1959 GNUNET_free_non_null (uris);
@@ -2065,8 +1972,7 @@ GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc)
2065 * @return GNUNET_OK (continue to iterate) 1972 * @return GNUNET_OK (continue to iterate)
2066 */ 1973 */
2067static int 1974static int
2068deserialize_unindex_file (void *cls, 1975deserialize_unindex_file (void *cls, const char *filename)
2069 const char *filename)
2070{ 1976{
2071 struct GNUNET_FS_Handle *h = cls; 1977 struct GNUNET_FS_Handle *h = cls;
2072 struct GNUNET_BIO_ReadHandle *rh; 1978 struct GNUNET_BIO_ReadHandle *rh;
@@ -2080,109 +1986,100 @@ deserialize_unindex_file (void *cls,
2080 uc->serialization = get_serialization_short_name (filename); 1986 uc->serialization = get_serialization_short_name (filename);
2081 rh = GNUNET_BIO_read_open (filename); 1987 rh = GNUNET_BIO_read_open (filename);
2082 if (rh == NULL) 1988 if (rh == NULL)
1989 {
1990 GNUNET_break (0);
1991 goto cleanup;
1992 }
1993 if ((GNUNET_OK !=
1994 GNUNET_BIO_read_string (rh, "unindex-fn", &uc->filename, 10 * 1024)) ||
1995 (GNUNET_OK !=
1996 GNUNET_BIO_read_int64 (rh, &uc->file_size)) ||
1997 (GNUNET_OK !=
1998 read_start_time (rh, &uc->start_time)) ||
1999 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &state)))
2000 {
2001 GNUNET_break (0);
2002 goto cleanup;
2003 }
2004 uc->state = (enum UnindexState) state;
2005 switch (state)
2006 {
2007 case UNINDEX_STATE_HASHING:
2008 break;
2009 case UNINDEX_STATE_FS_NOTIFY:
2010 if (GNUNET_OK !=
2011 GNUNET_BIO_read (rh, "unindex-hash", &uc->file_id,
2012 sizeof (GNUNET_HashCode)))
2083 { 2013 {
2084 GNUNET_break (0); 2014 GNUNET_break (0);
2085 goto cleanup; 2015 goto cleanup;
2086 } 2016 }
2087 if ( (GNUNET_OK != 2017 break;
2088 GNUNET_BIO_read_string (rh, "unindex-fn", &uc->filename, 10*1024)) || 2018 case UNINDEX_STATE_DS_REMOVE:
2089 (GNUNET_OK != 2019 break;
2090 GNUNET_BIO_read_int64 (rh, &uc->file_size)) || 2020 case UNINDEX_STATE_COMPLETE:
2091 (GNUNET_OK != 2021 break;
2092 read_start_time (rh, &uc->start_time)) || 2022 case UNINDEX_STATE_ERROR:
2093 (GNUNET_OK != 2023 if (GNUNET_OK !=
2094 GNUNET_BIO_read_int32 (rh, &state)) ) 2024 GNUNET_BIO_read_string (rh, "unindex-emsg", &uc->emsg, 10 * 1024))
2095 { 2025 {
2096 GNUNET_break (0);
2097 goto cleanup;
2098 }
2099 uc->state = (enum UnindexState) state;
2100 switch (state)
2101 {
2102 case UNINDEX_STATE_HASHING:
2103 break;
2104 case UNINDEX_STATE_FS_NOTIFY:
2105 if (GNUNET_OK !=
2106 GNUNET_BIO_read (rh, "unindex-hash", &uc->file_id, sizeof (GNUNET_HashCode)))
2107 {
2108 GNUNET_break (0);
2109 goto cleanup;
2110 }
2111 break;
2112 case UNINDEX_STATE_DS_REMOVE:
2113 break;
2114 case UNINDEX_STATE_COMPLETE:
2115 break;
2116 case UNINDEX_STATE_ERROR:
2117 if (GNUNET_OK !=
2118 GNUNET_BIO_read_string (rh, "unindex-emsg", &uc->emsg, 10*1024))
2119 {
2120 GNUNET_break (0);
2121 goto cleanup;
2122 }
2123 break;
2124 default:
2125 GNUNET_break (0); 2026 GNUNET_break (0);
2126 goto cleanup; 2027 goto cleanup;
2127 } 2028 }
2128 uc->top = GNUNET_FS_make_top (h, 2029 break;
2129 &GNUNET_FS_unindex_signal_suspend_, 2030 default:
2130 uc); 2031 GNUNET_break (0);
2032 goto cleanup;
2033 }
2034 uc->top = GNUNET_FS_make_top (h, &GNUNET_FS_unindex_signal_suspend_, uc);
2131 pi.status = GNUNET_FS_STATUS_UNINDEX_RESUME; 2035 pi.status = GNUNET_FS_STATUS_UNINDEX_RESUME;
2132 pi.value.unindex.specifics.resume.message = uc->emsg; 2036 pi.value.unindex.specifics.resume.message = uc->emsg;
2133 GNUNET_FS_unindex_make_status_ (&pi, 2037 GNUNET_FS_unindex_make_status_ (&pi,
2134 uc, 2038 uc,
2135 (uc->state == UNINDEX_STATE_COMPLETE) 2039 (uc->state == UNINDEX_STATE_COMPLETE)
2136 ? uc->file_size 2040 ? uc->file_size : 0);
2137 : 0);
2138 switch (uc->state) 2041 switch (uc->state)
2139 { 2042 {
2140 case UNINDEX_STATE_HASHING: 2043 case UNINDEX_STATE_HASHING:
2141 uc->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, 2044 uc->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE,
2142 uc->filename, 2045 uc->filename,
2143 HASHING_BLOCKSIZE, 2046 HASHING_BLOCKSIZE,
2144 &GNUNET_FS_unindex_process_hash_, 2047 &GNUNET_FS_unindex_process_hash_, uc);
2145 uc); 2048 break;
2146 break; 2049 case UNINDEX_STATE_FS_NOTIFY:
2147 case UNINDEX_STATE_FS_NOTIFY: 2050 uc->state = UNINDEX_STATE_HASHING;
2148 uc->state = UNINDEX_STATE_HASHING; 2051 GNUNET_FS_unindex_process_hash_ (uc, &uc->file_id);
2149 GNUNET_FS_unindex_process_hash_ (uc, 2052 break;
2150 &uc->file_id); 2053 case UNINDEX_STATE_DS_REMOVE:
2151 break; 2054 GNUNET_FS_unindex_do_remove_ (uc);
2152 case UNINDEX_STATE_DS_REMOVE: 2055 break;
2153 GNUNET_FS_unindex_do_remove_ (uc); 2056 case UNINDEX_STATE_COMPLETE:
2154 break; 2057 case UNINDEX_STATE_ERROR:
2155 case UNINDEX_STATE_COMPLETE: 2058 /* no need to resume any operation, we were done */
2156 case UNINDEX_STATE_ERROR: 2059 break;
2157 /* no need to resume any operation, we were done */ 2060 default:
2158 break; 2061 break;
2159 default: 2062 }
2160 break; 2063 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
2161 } 2064 {
2162 if (GNUNET_OK != 2065 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2163 GNUNET_BIO_read_close (rh, &emsg)) 2066 _("Failure while resuming unindexing operation `%s': %s\n"),
2164 { 2067 filename, emsg);
2165 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2068 GNUNET_free (emsg);
2166 _("Failure while resuming unindexing operation `%s': %s\n"), 2069 }
2167 filename,
2168 emsg);
2169 GNUNET_free (emsg);
2170 }
2171 return GNUNET_OK; 2070 return GNUNET_OK;
2172 cleanup: 2071cleanup:
2173 GNUNET_free_non_null (uc->filename); 2072 GNUNET_free_non_null (uc->filename);
2174 if ( (rh != NULL) && 2073 if ((rh != NULL) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)))
2175 (GNUNET_OK != 2074 {
2176 GNUNET_BIO_read_close (rh, &emsg)) ) 2075 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2177 { 2076 _("Failed to resume unindexing operation `%s': %s\n"),
2178 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2077 filename, emsg);
2179 _("Failed to resume unindexing operation `%s': %s\n"), 2078 GNUNET_free (emsg);
2180 filename, 2079 }
2181 emsg);
2182 GNUNET_free (emsg);
2183 }
2184 if (uc->serialization != NULL) 2080 if (uc->serialization != NULL)
2185 GNUNET_FS_remove_sync_file_ (h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, uc->serialization); 2081 GNUNET_FS_remove_sync_file_ (h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
2082 uc->serialization);
2186 GNUNET_free_non_null (uc->serialization); 2083 GNUNET_free_non_null (uc->serialization);
2187 GNUNET_free (uc); 2084 GNUNET_free (uc);
2188 return GNUNET_OK; 2085 return GNUNET_OK;
@@ -2200,10 +2097,10 @@ deserialize_unindex_file (void *cls,
2200 */ 2097 */
2201static void 2098static void
2202deserialize_download (struct GNUNET_FS_Handle *h, 2099deserialize_download (struct GNUNET_FS_Handle *h,
2203 struct GNUNET_BIO_ReadHandle *rh, 2100 struct GNUNET_BIO_ReadHandle *rh,
2204 struct GNUNET_FS_DownloadContext *parent, 2101 struct GNUNET_FS_DownloadContext *parent,
2205 struct GNUNET_FS_SearchResult *search, 2102 struct GNUNET_FS_SearchResult *search,
2206 const char *serialization); 2103 const char *serialization);
2207 2104
2208 2105
2209/** 2106/**
@@ -2214,11 +2111,16 @@ deserialize_download (struct GNUNET_FS_Handle *h,
2214 * @param psearch_result parent search result 2111 * @param psearch_result parent search result
2215 * @param serialization name under which the search was serialized 2112 * @param serialization name under which the search was serialized
2216 */ 2113 */
2217static struct GNUNET_FS_SearchContext * 2114static struct GNUNET_FS_SearchContext *deserialize_search (struct
2218deserialize_search (struct GNUNET_FS_Handle *h, 2115 GNUNET_FS_Handle *h,
2219 struct GNUNET_BIO_ReadHandle *rh, 2116 struct
2220 struct GNUNET_FS_SearchResult *psearch_result, 2117 GNUNET_BIO_ReadHandle
2221 const char *serialization); 2118 *rh,
2119 struct
2120 GNUNET_FS_SearchResult
2121 *psearch_result,
2122 const char
2123 *serialization);
2222 2124
2223 2125
2224/** 2126/**
@@ -2230,8 +2132,7 @@ deserialize_search (struct GNUNET_FS_Handle *h,
2230 * @return GNUNET_OK (continue to iterate) 2132 * @return GNUNET_OK (continue to iterate)
2231 */ 2133 */
2232static int 2134static int
2233deserialize_search_result (void *cls, 2135deserialize_search_result (void *cls, const char *filename)
2234 const char *filename)
2235{ 2136{
2236 struct GNUNET_FS_SearchContext *sc = cls; 2137 struct GNUNET_FS_SearchContext *sc = cls;
2237 char *ser; 2138 char *ser;
@@ -2246,130 +2147,107 @@ deserialize_search_result (void *cls,
2246 ser = get_serialization_short_name (filename); 2147 ser = get_serialization_short_name (filename);
2247 rh = GNUNET_BIO_read_open (filename); 2148 rh = GNUNET_BIO_read_open (filename);
2248 if (rh == NULL) 2149 if (rh == NULL)
2249 { 2150 {
2250 if (ser != NULL) 2151 if (ser != NULL)
2251 { 2152 {
2252 remove_sync_file_in_dir (sc->h, 2153 remove_sync_file_in_dir (sc->h,
2253 (sc->psearch_result == NULL) 2154 (sc->psearch_result == NULL)
2254 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH 2155 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
2255 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, 2156 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2256 sc->serialization, 2157 sc->serialization, ser);
2257 ser); 2158 GNUNET_free (ser);
2258 GNUNET_free (ser);
2259 }
2260 return GNUNET_OK;
2261 } 2159 }
2160 return GNUNET_OK;
2161 }
2262 emsg = NULL; 2162 emsg = NULL;
2263 uris = NULL; 2163 uris = NULL;
2264 download = NULL; 2164 download = NULL;
2265 update_srch = NULL; 2165 update_srch = NULL;
2266 sr = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchResult)); 2166 sr = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchResult));
2267 sr->serialization = ser; 2167 sr->serialization = ser;
2268 if ( (GNUNET_OK != 2168 if ((GNUNET_OK !=
2269 GNUNET_BIO_read_string (rh, "result-uri", &uris, 10*1024)) || 2169 GNUNET_BIO_read_string (rh, "result-uri", &uris, 10 * 1024)) ||
2270 (NULL == (sr->uri = GNUNET_FS_uri_parse (uris, &emsg))) || 2170 (NULL == (sr->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
2271 (GNUNET_OK != 2171 (GNUNET_OK !=
2272 GNUNET_BIO_read_string (rh, "download-lnk", &download, 16)) || 2172 GNUNET_BIO_read_string (rh, "download-lnk", &download, 16)) ||
2273 (GNUNET_OK != 2173 (GNUNET_OK !=
2274 GNUNET_BIO_read_string (rh, "search-lnk", &update_srch, 16)) || 2174 GNUNET_BIO_read_string (rh, "search-lnk", &update_srch, 16)) ||
2275 (GNUNET_OK != 2175 (GNUNET_OK !=
2276 GNUNET_BIO_read_meta_data (rh, "result-meta", &sr->meta)) || 2176 GNUNET_BIO_read_meta_data (rh, "result-meta", &sr->meta)) ||
2277 (GNUNET_OK != 2177 (GNUNET_OK !=
2278 GNUNET_BIO_read (rh, "result-key", &sr->key, sizeof (GNUNET_HashCode))) || 2178 GNUNET_BIO_read (rh, "result-key", &sr->key, sizeof (GNUNET_HashCode)))
2279 (GNUNET_OK != 2179 || (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->mandatory_missing)) ||
2280 GNUNET_BIO_read_int32 (rh, &sr->mandatory_missing)) || 2180 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->optional_support)) ||
2281 (GNUNET_OK != 2181 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->availability_success)) ||
2282 GNUNET_BIO_read_int32 (rh, &sr->optional_support)) || 2182 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->availability_trials)))
2283 (GNUNET_OK != 2183 {
2284 GNUNET_BIO_read_int32 (rh, &sr->availability_success)) || 2184 GNUNET_break (0);
2285 (GNUNET_OK != 2185 goto cleanup;
2286 GNUNET_BIO_read_int32 (rh, &sr->availability_trials)) ) 2186 }
2287 {
2288 GNUNET_break (0);
2289 goto cleanup;
2290 }
2291 GNUNET_free (uris); 2187 GNUNET_free (uris);
2292 if (download != NULL) 2188 if (download != NULL)
2293 { 2189 {
2294 drh = get_read_handle (sc->h, 2190 drh = get_read_handle (sc->h, GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD, download);
2295 GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD, 2191 if (drh != NULL)
2296 download); 2192 {
2297 if (drh != NULL) 2193 deserialize_download (sc->h, drh, NULL, sr, download);
2298 { 2194 if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg))
2299 deserialize_download (sc->h, 2195 {
2300 drh, 2196 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2301 NULL, 2197 _("Failed to resume sub-download `%s': %s\n"),
2302 sr, 2198 download, emsg);
2303 download); 2199 GNUNET_free (emsg);
2304 if (GNUNET_OK != 2200 }
2305 GNUNET_BIO_read_close (drh, &emsg)) 2201 }
2306 { 2202 GNUNET_free (download);
2307 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2203 }
2308 _("Failed to resume sub-download `%s': %s\n"),
2309 download,
2310 emsg);
2311 GNUNET_free (emsg);
2312 }
2313 }
2314 GNUNET_free (download);
2315 }
2316 if (update_srch != NULL) 2204 if (update_srch != NULL)
2317 { 2205 {
2318 drh = get_read_handle (sc->h, 2206 drh = get_read_handle (sc->h,
2319 GNUNET_FS_SYNC_PATH_CHILD_SEARCH, 2207 GNUNET_FS_SYNC_PATH_CHILD_SEARCH, update_srch);
2320 update_srch); 2208 if (drh != NULL)
2321 if (drh != NULL) 2209 {
2322 { 2210 deserialize_search (sc->h, drh, sr, update_srch);
2323 deserialize_search (sc->h, 2211 if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg))
2324 drh, 2212 {
2325 sr, 2213 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2326 update_srch); 2214 _("Failed to resume sub-search `%s': %s\n"),
2327 if (GNUNET_OK != 2215 update_srch, emsg);
2328 GNUNET_BIO_read_close (drh, &emsg)) 2216 GNUNET_free (emsg);
2329 { 2217 }
2330 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2218 }
2331 _("Failed to resume sub-search `%s': %s\n"), 2219 GNUNET_free (update_srch);
2332 update_srch, 2220 }
2333 emsg);
2334 GNUNET_free (emsg);
2335 }
2336 }
2337 GNUNET_free (update_srch);
2338 }
2339 GNUNET_CONTAINER_multihashmap_put (sc->master_result_map, 2221 GNUNET_CONTAINER_multihashmap_put (sc->master_result_map,
2340 &sr->key, 2222 &sr->key,
2341 sr, 2223 sr,
2342 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 2224 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2343 if (GNUNET_OK != 2225 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
2344 GNUNET_BIO_read_close (rh, &emsg)) 2226 {
2345 { 2227 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2346 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2228 _("Failure while resuming search operation `%s': %s\n"),
2347 _("Failure while resuming search operation `%s': %s\n"), 2229 filename, emsg);
2348 filename, 2230 GNUNET_free (emsg);
2349 emsg); 2231 }
2350 GNUNET_free (emsg);
2351 }
2352 return GNUNET_OK; 2232 return GNUNET_OK;
2353 cleanup: 2233cleanup:
2354 GNUNET_free_non_null (download); 2234 GNUNET_free_non_null (download);
2355 GNUNET_free_non_null (emsg); 2235 GNUNET_free_non_null (emsg);
2356 GNUNET_free_non_null (uris); 2236 GNUNET_free_non_null (uris);
2357 GNUNET_free_non_null (update_srch); 2237 GNUNET_free_non_null (update_srch);
2358 if (sr->uri != NULL) 2238 if (sr->uri != NULL)
2359 GNUNET_FS_uri_destroy (sr->uri); 2239 GNUNET_FS_uri_destroy (sr->uri);
2360 if (sr->meta != NULL) 2240 if (sr->meta != NULL)
2361 GNUNET_CONTAINER_meta_data_destroy (sr->meta); 2241 GNUNET_CONTAINER_meta_data_destroy (sr->meta);
2362 GNUNET_free (sr->serialization); 2242 GNUNET_free (sr->serialization);
2363 GNUNET_free (sr); 2243 GNUNET_free (sr);
2364 if (GNUNET_OK != 2244 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
2365 GNUNET_BIO_read_close (rh, &emsg)) 2245 {
2366 { 2246 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2367 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2247 _("Failure while resuming search operation `%s': %s\n"),
2368 _("Failure while resuming search operation `%s': %s\n"), 2248 filename, emsg);
2369 filename, 2249 GNUNET_free (emsg);
2370 emsg); 2250 }
2371 GNUNET_free (emsg);
2372 }
2373 return GNUNET_OK; 2251 return GNUNET_OK;
2374} 2252}
2375 2253
@@ -2387,18 +2265,17 @@ signal_download_resume (struct GNUNET_FS_DownloadContext *dc)
2387{ 2265{
2388 struct GNUNET_FS_DownloadContext *dcc; 2266 struct GNUNET_FS_DownloadContext *dcc;
2389 struct GNUNET_FS_ProgressInfo pi; 2267 struct GNUNET_FS_ProgressInfo pi;
2390 2268
2391 pi.status = GNUNET_FS_STATUS_DOWNLOAD_RESUME; 2269 pi.status = GNUNET_FS_STATUS_DOWNLOAD_RESUME;
2392 pi.value.download.specifics.resume.meta = dc->meta; 2270 pi.value.download.specifics.resume.meta = dc->meta;
2393 pi.value.download.specifics.resume.message = dc->emsg; 2271 pi.value.download.specifics.resume.message = dc->emsg;
2394 GNUNET_FS_download_make_status_ (&pi, 2272 GNUNET_FS_download_make_status_ (&pi, dc);
2395 dc);
2396 dcc = dc->child_head; 2273 dcc = dc->child_head;
2397 while (NULL != dcc) 2274 while (NULL != dcc)
2398 { 2275 {
2399 signal_download_resume (dcc); 2276 signal_download_resume (dcc);
2400 dcc = dcc->next; 2277 dcc = dcc->next;
2401 } 2278 }
2402 if (dc->pending_head != NULL) 2279 if (dc->pending_head != NULL)
2403 GNUNET_FS_download_start_downloading_ (dc); 2280 GNUNET_FS_download_start_downloading_ (dc);
2404} 2281}
@@ -2410,8 +2287,7 @@ signal_download_resume (struct GNUNET_FS_DownloadContext *dc)
2410 * 2287 *
2411 * @param sc search being resumed 2288 * @param sc search being resumed
2412 */ 2289 */
2413static void 2290static void signal_search_resume (struct GNUNET_FS_SearchContext *sc);
2414signal_search_resume (struct GNUNET_FS_SearchContext *sc);
2415 2291
2416 2292
2417/** 2293/**
@@ -2424,34 +2300,34 @@ signal_search_resume (struct GNUNET_FS_SearchContext *sc);
2424 * @return GNUNET_YES (we should continue to iterate) 2300 * @return GNUNET_YES (we should continue to iterate)
2425 */ 2301 */
2426static int 2302static int
2427signal_result_resume (void *cls, 2303signal_result_resume (void *cls, const GNUNET_HashCode * key, void *value)
2428 const GNUNET_HashCode * key,
2429 void *value)
2430{ 2304{
2431 struct GNUNET_FS_SearchContext *sc = cls; 2305 struct GNUNET_FS_SearchContext *sc = cls;
2432 struct GNUNET_FS_ProgressInfo pi; 2306 struct GNUNET_FS_ProgressInfo pi;
2433 struct GNUNET_FS_SearchResult *sr = value; 2307 struct GNUNET_FS_SearchResult *sr = value;
2434 2308
2435 if (0 == sr->mandatory_missing) 2309 if (0 == sr->mandatory_missing)
2436 { 2310 {
2437 pi.status = GNUNET_FS_STATUS_SEARCH_RESUME_RESULT; 2311 pi.status = GNUNET_FS_STATUS_SEARCH_RESUME_RESULT;
2438 pi.value.search.specifics.resume_result.meta = sr->meta; 2312 pi.value.search.specifics.resume_result.meta = sr->meta;
2439 pi.value.search.specifics.resume_result.uri = sr->uri; 2313 pi.value.search.specifics.resume_result.uri = sr->uri;
2440 pi.value.search.specifics.resume_result.result = sr; 2314 pi.value.search.specifics.resume_result.result = sr;
2441 pi.value.search.specifics.resume_result.availability_rank = 2*sr->availability_success - sr->availability_trials; 2315 pi.value.search.specifics.resume_result.availability_rank =
2442 pi.value.search.specifics.resume_result.availability_certainty = sr->availability_trials; 2316 2 * sr->availability_success - sr->availability_trials;
2443 pi.value.search.specifics.resume_result.applicability_rank = sr->optional_support; 2317 pi.value.search.specifics.resume_result.availability_certainty =
2444 sr->client_info = GNUNET_FS_search_make_status_ (&pi, 2318 sr->availability_trials;
2445 sc); 2319 pi.value.search.specifics.resume_result.applicability_rank =
2446 } 2320 sr->optional_support;
2321 sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
2322 }
2447 if (sr->download != NULL) 2323 if (sr->download != NULL)
2448 { 2324 {
2449 signal_download_resume (sr->download); 2325 signal_download_resume (sr->download);
2450 } 2326 }
2451 else 2327 else
2452 { 2328 {
2453 GNUNET_FS_search_start_probe_ (sr); 2329 GNUNET_FS_search_start_probe_ (sr);
2454 } 2330 }
2455 if (sr->update_search != NULL) 2331 if (sr->update_search != NULL)
2456 signal_search_resume (sr->update_search); 2332 signal_search_resume (sr->update_search);
2457 return GNUNET_YES; 2333 return GNUNET_YES;
@@ -2463,8 +2339,7 @@ signal_result_resume (void *cls,
2463 * 2339 *
2464 * @param sc search context to free 2340 * @param sc search context to free
2465 */ 2341 */
2466static void 2342static void free_search_context (struct GNUNET_FS_SearchContext *sc);
2467free_search_context (struct GNUNET_FS_SearchContext *sc);
2468 2343
2469 2344
2470/** 2345/**
@@ -2476,17 +2351,15 @@ free_search_context (struct GNUNET_FS_SearchContext *sc);
2476 * @return GNUNET_YES (we should continue to iterate) 2351 * @return GNUNET_YES (we should continue to iterate)
2477 */ 2352 */
2478static int 2353static int
2479free_result (void *cls, 2354free_result (void *cls, const GNUNET_HashCode * key, void *value)
2480 const GNUNET_HashCode * key,
2481 void *value)
2482{ 2355{
2483 struct GNUNET_FS_SearchResult *sr = value; 2356 struct GNUNET_FS_SearchResult *sr = value;
2484 2357
2485 if (sr->update_search != NULL) 2358 if (sr->update_search != NULL)
2486 { 2359 {
2487 free_search_context (sr->update_search); 2360 free_search_context (sr->update_search);
2488 GNUNET_assert (NULL == sr->update_search); 2361 GNUNET_assert (NULL == sr->update_search);
2489 } 2362 }
2490 GNUNET_CONTAINER_meta_data_destroy (sr->meta); 2363 GNUNET_CONTAINER_meta_data_destroy (sr->meta);
2491 GNUNET_FS_uri_destroy (sr->uri); 2364 GNUNET_FS_uri_destroy (sr->uri);
2492 GNUNET_free (sr); 2365 GNUNET_free (sr);
@@ -2503,29 +2376,28 @@ static void
2503free_search_context (struct GNUNET_FS_SearchContext *sc) 2376free_search_context (struct GNUNET_FS_SearchContext *sc)
2504{ 2377{
2505 if (sc->serialization != NULL) 2378 if (sc->serialization != NULL)
2506 { 2379 {
2507 GNUNET_FS_remove_sync_file_ (sc->h, 2380 GNUNET_FS_remove_sync_file_ (sc->h,
2508 (sc->psearch_result == NULL) 2381 (sc->psearch_result == NULL)
2509 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH 2382 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
2510 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, 2383 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2511 sc->serialization); 2384 sc->serialization);
2512 GNUNET_FS_remove_sync_dir_ (sc->h, 2385 GNUNET_FS_remove_sync_dir_ (sc->h,
2513 (sc->psearch_result == NULL) 2386 (sc->psearch_result == NULL)
2514 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH 2387 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
2515 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, 2388 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2516 sc->serialization); 2389 sc->serialization);
2517 } 2390 }
2518 GNUNET_free_non_null (sc->serialization); 2391 GNUNET_free_non_null (sc->serialization);
2519 GNUNET_free_non_null (sc->emsg); 2392 GNUNET_free_non_null (sc->emsg);
2520 if (sc->uri != NULL) 2393 if (sc->uri != NULL)
2521 GNUNET_FS_uri_destroy (sc->uri); 2394 GNUNET_FS_uri_destroy (sc->uri);
2522 if (sc->master_result_map != NULL) 2395 if (sc->master_result_map != NULL)
2523 { 2396 {
2524 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, 2397 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
2525 &free_result, 2398 &free_result, sc);
2526 sc); 2399 GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map);
2527 GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map); 2400 }
2528 }
2529 GNUNET_free (sc); 2401 GNUNET_free (sc);
2530} 2402}
2531 2403
@@ -2539,8 +2411,7 @@ free_search_context (struct GNUNET_FS_SearchContext *sc)
2539 * @return GNUNET_OK (continue to iterate) 2411 * @return GNUNET_OK (continue to iterate)
2540 */ 2412 */
2541static int 2413static int
2542deserialize_subdownload (void *cls, 2414deserialize_subdownload (void *cls, const char *filename)
2543 const char *filename)
2544{ 2415{
2545 struct GNUNET_FS_DownloadContext *parent = cls; 2416 struct GNUNET_FS_DownloadContext *parent = cls;
2546 char *ser; 2417 char *ser;
@@ -2550,28 +2421,21 @@ deserialize_subdownload (void *cls,
2550 ser = get_serialization_short_name (filename); 2421 ser = get_serialization_short_name (filename);
2551 rh = GNUNET_BIO_read_open (filename); 2422 rh = GNUNET_BIO_read_open (filename);
2552 if (rh == NULL) 2423 if (rh == NULL)
2553 { 2424 {
2554 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2425 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2555 _("Failed to resume sub-download `%s': could not open file `%s'\n"), 2426 _
2556 ser, 2427 ("Failed to resume sub-download `%s': could not open file `%s'\n"),
2557 filename); 2428 ser, filename);
2558 GNUNET_free (ser); 2429 GNUNET_free (ser);
2559 return GNUNET_OK; 2430 return GNUNET_OK;
2560 } 2431 }
2561 deserialize_download (parent->h, 2432 deserialize_download (parent->h, rh, parent, NULL, ser);
2562 rh, 2433 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
2563 parent, 2434 {
2564 NULL, 2435 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2565 ser); 2436 _("Failed to resume sub-download `%s': %s\n"), ser, emsg);
2566 if (GNUNET_OK != 2437 GNUNET_free (emsg);
2567 GNUNET_BIO_read_close (rh, &emsg)) 2438 }
2568 {
2569 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2570 _("Failed to resume sub-download `%s': %s\n"),
2571 ser,
2572 emsg);
2573 GNUNET_free (emsg);
2574 }
2575 GNUNET_free (ser); 2439 GNUNET_free (ser);
2576 return GNUNET_OK; 2440 return GNUNET_OK;
2577} 2441}
@@ -2598,15 +2462,13 @@ free_download_context (struct GNUNET_FS_DownloadContext *dc)
2598 GNUNET_free_non_null (dc->filename); 2462 GNUNET_free_non_null (dc->filename);
2599 GNUNET_free_non_null (dc->serialization); 2463 GNUNET_free_non_null (dc->serialization);
2600 while (NULL != (dcc = dc->child_head)) 2464 while (NULL != (dcc = dc->child_head))
2601 { 2465 {
2602 GNUNET_CONTAINER_DLL_remove (dc->child_head, 2466 GNUNET_CONTAINER_DLL_remove (dc->child_head, dc->child_tail, dcc);
2603 dc->child_tail, 2467 free_download_context (dcc);
2604 dcc); 2468 }
2605 free_download_context (dcc);
2606 }
2607 GNUNET_FS_free_download_request_ (dc->top_request); 2469 GNUNET_FS_free_download_request_ (dc->top_request);
2608 if (NULL != dc->active) 2470 if (NULL != dc->active)
2609 GNUNET_CONTAINER_multihashmap_destroy (dc->active); 2471 GNUNET_CONTAINER_multihashmap_destroy (dc->active);
2610 GNUNET_free (dc); 2472 GNUNET_free (dc);
2611} 2473}
2612 2474
@@ -2622,10 +2484,10 @@ free_download_context (struct GNUNET_FS_DownloadContext *dc)
2622 */ 2484 */
2623static void 2485static void
2624deserialize_download (struct GNUNET_FS_Handle *h, 2486deserialize_download (struct GNUNET_FS_Handle *h,
2625 struct GNUNET_BIO_ReadHandle *rh, 2487 struct GNUNET_BIO_ReadHandle *rh,
2626 struct GNUNET_FS_DownloadContext *parent, 2488 struct GNUNET_FS_DownloadContext *parent,
2627 struct GNUNET_FS_SearchResult *search, 2489 struct GNUNET_FS_SearchResult *search,
2628 const char *serialization) 2490 const char *serialization)
2629{ 2491{
2630 struct GNUNET_FS_DownloadContext *dc; 2492 struct GNUNET_FS_DownloadContext *dc;
2631 char *emsg; 2493 char *emsg;
@@ -2640,89 +2502,77 @@ deserialize_download (struct GNUNET_FS_Handle *h,
2640 dc->parent = parent; 2502 dc->parent = parent;
2641 dc->h = h; 2503 dc->h = h;
2642 dc->serialization = GNUNET_strdup (serialization); 2504 dc->serialization = GNUNET_strdup (serialization);
2643 if ( (GNUNET_OK != 2505 if ((GNUNET_OK !=
2644 GNUNET_BIO_read_string (rh, "download-uri", &uris, 10*1024)) || 2506 GNUNET_BIO_read_string (rh, "download-uri", &uris, 10 * 1024)) ||
2645 (NULL == (dc->uri = GNUNET_FS_uri_parse (uris, &emsg))) || 2507 (NULL == (dc->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
2646 ( (GNUNET_YES != GNUNET_FS_uri_test_chk (dc->uri)) && 2508 ((GNUNET_YES != GNUNET_FS_uri_test_chk (dc->uri)) &&
2647 (GNUNET_YES != GNUNET_FS_uri_test_loc (dc->uri)) ) || 2509 (GNUNET_YES != GNUNET_FS_uri_test_loc (dc->uri))) ||
2648 (GNUNET_OK != 2510 (GNUNET_OK !=
2649 GNUNET_BIO_read_meta_data (rh, "download-meta", &dc->meta)) || 2511 GNUNET_BIO_read_meta_data (rh, "download-meta", &dc->meta)) ||
2650 (GNUNET_OK != 2512 (GNUNET_OK !=
2651 GNUNET_BIO_read_string (rh, "download-emsg", &dc->emsg, 10*1024)) || 2513 GNUNET_BIO_read_string (rh, "download-emsg", &dc->emsg, 10 * 1024)) ||
2652 (GNUNET_OK != 2514 (GNUNET_OK !=
2653 GNUNET_BIO_read_string (rh, "download-fn", &dc->filename, 10*1024)) || 2515 GNUNET_BIO_read_string (rh, "download-fn", &dc->filename, 10 * 1024)) ||
2654 (GNUNET_OK != 2516 (GNUNET_OK !=
2655 GNUNET_BIO_read_string (rh, "download-tfn", &dc->temp_filename, 10*1024)) || 2517 GNUNET_BIO_read_string (rh, "download-tfn", &dc->temp_filename,
2656 (GNUNET_OK != 2518 10 * 1024)) ||
2657 GNUNET_BIO_read_int64 (rh, &dc->old_file_size)) || 2519 (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->old_file_size)) ||
2658 (GNUNET_OK != 2520 (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->offset)) ||
2659 GNUNET_BIO_read_int64 (rh, &dc->offset)) || 2521 (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->length)) ||
2660 (GNUNET_OK != 2522 (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->completed)) ||
2661 GNUNET_BIO_read_int64 (rh, &dc->length)) || 2523 (GNUNET_OK != read_start_time (rh, &dc->start_time)) ||
2662 (GNUNET_OK != 2524 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dc->anonymity)) ||
2663 GNUNET_BIO_read_int64 (rh, &dc->completed)) || 2525 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &options)) ||
2664 (GNUNET_OK != 2526 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &status)))
2665 read_start_time (rh, &dc->start_time)) || 2527 {
2666 (GNUNET_OK != 2528 GNUNET_break (0);
2667 GNUNET_BIO_read_int32 (rh, &dc->anonymity)) || 2529 goto cleanup;
2668 (GNUNET_OK != 2530 }
2669 GNUNET_BIO_read_int32 (rh, &options)) ||
2670 (GNUNET_OK !=
2671 GNUNET_BIO_read_int32 (rh, &status)) )
2672 {
2673 GNUNET_break (0);
2674 goto cleanup;
2675 }
2676 dc->options = (enum GNUNET_FS_DownloadOptions) options; 2531 dc->options = (enum GNUNET_FS_DownloadOptions) options;
2677 dc->active = GNUNET_CONTAINER_multihashmap_create (1 + 2 * (dc->length / DBLOCK_SIZE)); 2532 dc->active =
2533 GNUNET_CONTAINER_multihashmap_create (1 + 2 * (dc->length / DBLOCK_SIZE));
2678 dc->has_finished = (int) status; 2534 dc->has_finished = (int) status;
2679 dc->treedepth = GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size (dc->uri)); 2535 dc->treedepth =
2536 GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size (dc->uri));
2680 if (GNUNET_FS_uri_test_loc (dc->uri)) 2537 if (GNUNET_FS_uri_test_loc (dc->uri))
2681 GNUNET_assert (GNUNET_OK == 2538 GNUNET_assert (GNUNET_OK ==
2682 GNUNET_FS_uri_loc_get_peer_identity (dc->uri, 2539 GNUNET_FS_uri_loc_get_peer_identity (dc->uri, &dc->target));
2683 &dc->target));
2684 if (dc->emsg == NULL) 2540 if (dc->emsg == NULL)
2541 {
2542 dc->top_request = read_download_request (rh);
2543 if (dc->top_request == NULL)
2685 { 2544 {
2686 dc->top_request = read_download_request (rh); 2545 GNUNET_break (0);
2687 if (dc->top_request == NULL) 2546 goto cleanup;
2688 {
2689 GNUNET_break (0);
2690 goto cleanup;
2691 }
2692 } 2547 }
2548 }
2693 dn = get_download_sync_filename (dc, dc->serialization, ".dir"); 2549 dn = get_download_sync_filename (dc, dc->serialization, ".dir");
2694 if (dn != NULL) 2550 if (dn != NULL)
2695 { 2551 {
2696 if (GNUNET_YES == 2552 if (GNUNET_YES == GNUNET_DISK_directory_test (dn))
2697 GNUNET_DISK_directory_test (dn)) 2553 GNUNET_DISK_directory_scan (dn, &deserialize_subdownload, dc);
2698 GNUNET_DISK_directory_scan (dn, &deserialize_subdownload, dc); 2554 GNUNET_free (dn);
2699 GNUNET_free (dn); 2555 }
2700 }
2701 if (parent != NULL) 2556 if (parent != NULL)
2702 { 2557 {
2703 abort (); // for debugging for now 2558 abort (); // for debugging for now
2704 GNUNET_CONTAINER_DLL_insert (parent->child_head, 2559 GNUNET_CONTAINER_DLL_insert (parent->child_head, parent->child_tail, dc);
2705 parent->child_tail, 2560 }
2706 dc);
2707 }
2708 if (search != NULL) 2561 if (search != NULL)
2709 { 2562 {
2710 dc->search = search; 2563 dc->search = search;
2711 search->download = dc; 2564 search->download = dc;
2712 } 2565 }
2713 if ( (parent == NULL) && 2566 if ((parent == NULL) && (search == NULL))
2714 (search == NULL) ) 2567 {
2715 { 2568 dc->top = GNUNET_FS_make_top (dc->h,
2716 dc->top = GNUNET_FS_make_top (dc->h, 2569 &GNUNET_FS_download_signal_suspend_, dc);
2717 &GNUNET_FS_download_signal_suspend_, 2570 signal_download_resume (dc);
2718 dc); 2571 }
2719 signal_download_resume (dc);
2720 }
2721 GNUNET_free (uris); 2572 GNUNET_free (uris);
2722 dc->task 2573 dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, dc);
2723 = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, dc);
2724 return; 2574 return;
2725 cleanup: 2575cleanup:
2726 GNUNET_free_non_null (uris); 2576 GNUNET_free_non_null (uris);
2727 GNUNET_free_non_null (emsg); 2577 GNUNET_free_non_null (emsg);
2728 free_download_context (dc); 2578 free_download_context (dc);
@@ -2742,12 +2592,11 @@ signal_search_resume (struct GNUNET_FS_SearchContext *sc)
2742 2592
2743 pi.status = GNUNET_FS_STATUS_SEARCH_RESUME; 2593 pi.status = GNUNET_FS_STATUS_SEARCH_RESUME;
2744 pi.value.search.specifics.resume.message = sc->emsg; 2594 pi.value.search.specifics.resume.message = sc->emsg;
2745 pi.value.search.specifics.resume.is_paused = (sc->client == NULL) ? GNUNET_YES : GNUNET_NO; 2595 pi.value.search.specifics.resume.is_paused =
2746 sc->client_info = GNUNET_FS_search_make_status_ (&pi, 2596 (sc->client == NULL) ? GNUNET_YES : GNUNET_NO;
2747 sc); 2597 sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
2748 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, 2598 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
2749 &signal_result_resume, 2599 &signal_result_resume, sc);
2750 sc);
2751 2600
2752} 2601}
2753 2602
@@ -2762,9 +2611,9 @@ signal_search_resume (struct GNUNET_FS_SearchContext *sc)
2762 */ 2611 */
2763static struct GNUNET_FS_SearchContext * 2612static struct GNUNET_FS_SearchContext *
2764deserialize_search (struct GNUNET_FS_Handle *h, 2613deserialize_search (struct GNUNET_FS_Handle *h,
2765 struct GNUNET_BIO_ReadHandle *rh, 2614 struct GNUNET_BIO_ReadHandle *rh,
2766 struct GNUNET_FS_SearchResult *psearch_result, 2615 struct GNUNET_FS_SearchResult *psearch_result,
2767 const char *serialization) 2616 const char *serialization)
2768{ 2617{
2769 struct GNUNET_FS_SearchContext *sc; 2618 struct GNUNET_FS_SearchContext *sc;
2770 char *emsg; 2619 char *emsg;
@@ -2773,67 +2622,63 @@ deserialize_search (struct GNUNET_FS_Handle *h,
2773 uint32_t options; 2622 uint32_t options;
2774 char in_pause; 2623 char in_pause;
2775 2624
2776 if ( (psearch_result != NULL) && 2625 if ((psearch_result != NULL) && (psearch_result->update_search != NULL))
2777 (psearch_result->update_search != NULL) ) 2626 {
2778 { 2627 GNUNET_break (0);
2779 GNUNET_break (0); 2628 return NULL;
2780 return NULL; 2629 }
2781 }
2782 uris = NULL; 2630 uris = NULL;
2783 emsg = NULL; 2631 emsg = NULL;
2784 sc = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchContext)); 2632 sc = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchContext));
2785 if (psearch_result != NULL) 2633 if (psearch_result != NULL)
2786 { 2634 {
2787 sc->psearch_result = psearch_result; 2635 sc->psearch_result = psearch_result;
2788 psearch_result->update_search = sc; 2636 psearch_result->update_search = sc;
2789 } 2637 }
2790 sc->h = h; 2638 sc->h = h;
2791 sc->serialization = GNUNET_strdup (serialization); 2639 sc->serialization = GNUNET_strdup (serialization);
2792 if ( (GNUNET_OK != 2640 if ((GNUNET_OK !=
2793 GNUNET_BIO_read_string (rh, "search-uri", &uris, 10*1024)) || 2641 GNUNET_BIO_read_string (rh, "search-uri", &uris, 10 * 1024)) ||
2794 (NULL == (sc->uri = GNUNET_FS_uri_parse (uris, &emsg))) || 2642 (NULL == (sc->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
2795 ( (GNUNET_YES != GNUNET_FS_uri_test_ksk (sc->uri)) && 2643 ((GNUNET_YES != GNUNET_FS_uri_test_ksk (sc->uri)) &&
2796 (GNUNET_YES != GNUNET_FS_uri_test_sks (sc->uri)) ) || 2644 (GNUNET_YES != GNUNET_FS_uri_test_sks (sc->uri))) ||
2797 (GNUNET_OK != 2645 (GNUNET_OK !=
2798 read_start_time (rh, &sc->start_time)) || 2646 read_start_time (rh, &sc->start_time)) ||
2799 (GNUNET_OK != 2647 (GNUNET_OK !=
2800 GNUNET_BIO_read_string (rh, "search-emsg", &sc->emsg, 10*1024)) || 2648 GNUNET_BIO_read_string (rh, "search-emsg", &sc->emsg, 10 * 1024)) ||
2801 (GNUNET_OK != 2649 (GNUNET_OK !=
2802 GNUNET_BIO_read_int32 (rh, &options)) || 2650 GNUNET_BIO_read_int32 (rh, &options)) ||
2803 (GNUNET_OK != 2651 (GNUNET_OK !=
2804 GNUNET_BIO_read (rh, "search-pause", &in_pause, sizeof (in_pause))) || 2652 GNUNET_BIO_read (rh, "search-pause", &in_pause, sizeof (in_pause))) ||
2805 (GNUNET_OK != 2653 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sc->anonymity)))
2806 GNUNET_BIO_read_int32 (rh, &sc->anonymity)) ) 2654 {
2807 { 2655 GNUNET_break (0);
2808 GNUNET_break (0); 2656 goto cleanup;
2809 goto cleanup; 2657 }
2810 }
2811 sc->options = (enum GNUNET_FS_SearchOptions) options; 2658 sc->options = (enum GNUNET_FS_SearchOptions) options;
2812 sc->master_result_map = GNUNET_CONTAINER_multihashmap_create (16); 2659 sc->master_result_map = GNUNET_CONTAINER_multihashmap_create (16);
2813 dn = get_serialization_file_name_in_dir (h, 2660 dn = get_serialization_file_name_in_dir (h,
2814 (sc->psearch_result == NULL) 2661 (sc->psearch_result == NULL)
2815 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH 2662 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
2816 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, 2663 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2817 sc->serialization, 2664 sc->serialization, "");
2818 "");
2819 if (dn != NULL) 2665 if (dn != NULL)
2820 { 2666 {
2821 if (GNUNET_YES == 2667 if (GNUNET_YES == GNUNET_DISK_directory_test (dn))
2822 GNUNET_DISK_directory_test (dn)) 2668 GNUNET_DISK_directory_scan (dn, &deserialize_search_result, sc);
2823 GNUNET_DISK_directory_scan (dn, &deserialize_search_result, sc); 2669 GNUNET_free (dn);
2824 GNUNET_free (dn); 2670 }
2825 } 2671 if (('\0' == in_pause) &&
2826 if ( ('\0' == in_pause) && 2672 (GNUNET_OK != GNUNET_FS_search_start_searching_ (sc)))
2827 (GNUNET_OK != 2673 {
2828 GNUNET_FS_search_start_searching_ (sc)) ) 2674 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2829 { 2675 _
2830 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2676 ("Could not resume running search, will resume as paused search\n"));
2831 _("Could not resume running search, will resume as paused search\n")); 2677 }
2832 }
2833 signal_search_resume (sc); 2678 signal_search_resume (sc);
2834 GNUNET_free (uris); 2679 GNUNET_free (uris);
2835 return sc; 2680 return sc;
2836 cleanup: 2681cleanup:
2837 GNUNET_free_non_null (emsg); 2682 GNUNET_free_non_null (emsg);
2838 free_search_context (sc); 2683 free_search_context (sc);
2839 GNUNET_free_non_null (uris); 2684 GNUNET_free_non_null (uris);
@@ -2850,8 +2695,7 @@ deserialize_search (struct GNUNET_FS_Handle *h,
2850 * @return GNUNET_OK (continue to iterate) 2695 * @return GNUNET_OK (continue to iterate)
2851 */ 2696 */
2852static int 2697static int
2853deserialize_search_file (void *cls, 2698deserialize_search_file (void *cls, const char *filename)
2854 const char *filename)
2855{ 2699{
2856 struct GNUNET_FS_Handle *h = cls; 2700 struct GNUNET_FS_Handle *h = cls;
2857 char *ser; 2701 char *ser;
@@ -2862,27 +2706,25 @@ deserialize_search_file (void *cls,
2862 ser = get_serialization_short_name (filename); 2706 ser = get_serialization_short_name (filename);
2863 rh = GNUNET_BIO_read_open (filename); 2707 rh = GNUNET_BIO_read_open (filename);
2864 if (rh == NULL) 2708 if (rh == NULL)
2709 {
2710 if (ser != NULL)
2865 { 2711 {
2866 if (ser != NULL) 2712 GNUNET_FS_remove_sync_file_ (h, GNUNET_FS_SYNC_PATH_MASTER_SEARCH, ser);
2867 { 2713 GNUNET_free (ser);
2868 GNUNET_FS_remove_sync_file_ (h, GNUNET_FS_SYNC_PATH_MASTER_SEARCH, ser);
2869 GNUNET_free (ser);
2870 }
2871 return GNUNET_OK;
2872 } 2714 }
2715 return GNUNET_OK;
2716 }
2873 sc = deserialize_search (h, rh, NULL, ser); 2717 sc = deserialize_search (h, rh, NULL, ser);
2874 if (sc != NULL) 2718 if (sc != NULL)
2875 sc->top = GNUNET_FS_make_top (h, &GNUNET_FS_search_signal_suspend_, sc); 2719 sc->top = GNUNET_FS_make_top (h, &GNUNET_FS_search_signal_suspend_, sc);
2876 GNUNET_free (ser); 2720 GNUNET_free (ser);
2877 if (GNUNET_OK != 2721 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
2878 GNUNET_BIO_read_close (rh, &emsg)) 2722 {
2879 { 2723 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2880 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2724 _("Failure while resuming search operation `%s': %s\n"),
2881 _("Failure while resuming search operation `%s': %s\n"), 2725 filename, emsg);
2882 filename, 2726 GNUNET_free (emsg);
2883 emsg); 2727 }
2884 GNUNET_free (emsg);
2885 }
2886 return GNUNET_OK; 2728 return GNUNET_OK;
2887} 2729}
2888 2730
@@ -2896,8 +2738,7 @@ deserialize_search_file (void *cls,
2896 * @return GNUNET_OK (continue to iterate) 2738 * @return GNUNET_OK (continue to iterate)
2897 */ 2739 */
2898static int 2740static int
2899deserialize_download_file (void *cls, 2741deserialize_download_file (void *cls, const char *filename)
2900 const char *filename)
2901{ 2742{
2902 struct GNUNET_FS_Handle *h = cls; 2743 struct GNUNET_FS_Handle *h = cls;
2903 char *ser; 2744 char *ser;
@@ -2907,25 +2748,21 @@ deserialize_download_file (void *cls,
2907 ser = get_serialization_short_name (filename); 2748 ser = get_serialization_short_name (filename);
2908 rh = GNUNET_BIO_read_open (filename); 2749 rh = GNUNET_BIO_read_open (filename);
2909 if (rh == NULL) 2750 if (rh == NULL)
2910 { 2751 {
2911 if (0 != UNLINK (filename)) 2752 if (0 != UNLINK (filename))
2912 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 2753 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
2913 "unlink", 2754 GNUNET_free (ser);
2914 filename); 2755 return GNUNET_OK;
2915 GNUNET_free (ser); 2756 }
2916 return GNUNET_OK;
2917 }
2918 deserialize_download (h, rh, NULL, NULL, ser); 2757 deserialize_download (h, rh, NULL, NULL, ser);
2919 GNUNET_free (ser); 2758 GNUNET_free (ser);
2920 if (GNUNET_OK != 2759 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
2921 GNUNET_BIO_read_close (rh, &emsg)) 2760 {
2922 { 2761 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2923 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2762 _("Failure while resuming download operation `%s': %s\n"),
2924 _("Failure while resuming download operation `%s': %s\n"), 2763 filename, emsg);
2925 filename, 2764 GNUNET_free (emsg);
2926 emsg); 2765 }
2927 GNUNET_free (emsg);
2928 }
2929 return GNUNET_OK; 2766 return GNUNET_OK;
2930} 2767}
2931 2768
@@ -2939,18 +2776,17 @@ deserialize_download_file (void *cls,
2939 */ 2776 */
2940static void 2777static void
2941deserialization_master (const char *master_path, 2778deserialization_master (const char *master_path,
2942 GNUNET_FileNameCallback proc, 2779 GNUNET_FileNameCallback proc,
2943 struct GNUNET_FS_Handle *h) 2780 struct GNUNET_FS_Handle *h)
2944{ 2781{
2945 char *dn; 2782 char *dn;
2946 2783
2947 dn = get_serialization_file_name (h, master_path, ""); 2784 dn = get_serialization_file_name (h, master_path, "");
2948 if (dn == NULL) 2785 if (dn == NULL)
2949 return; 2786 return;
2950 if (GNUNET_YES == 2787 if (GNUNET_YES == GNUNET_DISK_directory_test (dn))
2951 GNUNET_DISK_directory_test (dn))
2952 GNUNET_DISK_directory_scan (dn, proc, h); 2788 GNUNET_DISK_directory_scan (dn, proc, h);
2953 GNUNET_free (dn); 2789 GNUNET_free (dn);
2954} 2790}
2955 2791
2956 2792
@@ -2967,11 +2803,9 @@ deserialization_master (const char *master_path,
2967 */ 2803 */
2968struct GNUNET_FS_Handle * 2804struct GNUNET_FS_Handle *
2969GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg, 2805GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
2970 const char *client_name, 2806 const char *client_name,
2971 GNUNET_FS_ProgressCallback upcb, 2807 GNUNET_FS_ProgressCallback upcb,
2972 void *upcb_cls, 2808 void *upcb_cls, enum GNUNET_FS_Flags flags, ...)
2973 enum GNUNET_FS_Flags flags,
2974 ...)
2975{ 2809{
2976 struct GNUNET_FS_Handle *ret; 2810 struct GNUNET_FS_Handle *ret;
2977 enum GNUNET_FS_OPTIONS opt; 2811 enum GNUNET_FS_OPTIONS opt;
@@ -2985,42 +2819,40 @@ GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
2985 ret->flags = flags; 2819 ret->flags = flags;
2986 ret->max_parallel_downloads = 1; 2820 ret->max_parallel_downloads = 1;
2987 ret->max_parallel_requests = 1; 2821 ret->max_parallel_requests = 1;
2988 ret->avg_block_latency = GNUNET_TIME_UNIT_MINUTES; /* conservative starting point */ 2822 ret->avg_block_latency = GNUNET_TIME_UNIT_MINUTES; /* conservative starting point */
2989 va_start (ap, flags); 2823 va_start (ap, flags);
2990 while (GNUNET_FS_OPTIONS_END != (opt = va_arg (ap, enum GNUNET_FS_OPTIONS))) 2824 while (GNUNET_FS_OPTIONS_END != (opt = va_arg (ap, enum GNUNET_FS_OPTIONS)))
2825 {
2826 switch (opt)
2991 { 2827 {
2992 switch (opt) 2828 case GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM:
2993 { 2829 ret->max_parallel_downloads = va_arg (ap, unsigned int);
2994 case GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM: 2830
2995 ret->max_parallel_downloads = va_arg (ap, unsigned int); 2831 break;
2996 break; 2832 case GNUNET_FS_OPTIONS_REQUEST_PARALLELISM:
2997 case GNUNET_FS_OPTIONS_REQUEST_PARALLELISM: 2833 ret->max_parallel_requests = va_arg (ap, unsigned int);
2998 ret->max_parallel_requests = va_arg (ap, unsigned int); 2834
2999 break; 2835 break;
3000 default: 2836 default:
3001 GNUNET_break (0); 2837 GNUNET_break (0);
3002 GNUNET_free (ret->client_name); 2838 GNUNET_free (ret->client_name);
3003 GNUNET_free (ret); 2839 GNUNET_free (ret);
3004 va_end (ap); 2840 va_end (ap);
3005 return NULL; 2841 return NULL;
3006 }
3007 } 2842 }
2843 }
3008 va_end (ap); 2844 va_end (ap);
3009 if (0 != (GNUNET_FS_FLAGS_PERSISTENCE & flags)) 2845 if (0 != (GNUNET_FS_FLAGS_PERSISTENCE & flags))
3010 { 2846 {
3011 deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, 2847 deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_PUBLISH,
3012 &deserialize_publish_file, 2848 &deserialize_publish_file, ret);
3013 ret); 2849 deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_SEARCH,
3014 deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_SEARCH, 2850 &deserialize_search_file, ret);
3015 &deserialize_search_file, 2851 deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD,
3016 ret); 2852 &deserialize_download_file, ret);
3017 deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, 2853 deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
3018 &deserialize_download_file, 2854 &deserialize_unindex_file, ret);
3019 ret); 2855 }
3020 deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
3021 &deserialize_unindex_file,
3022 ret);
3023 }
3024 return ret; 2856 return ret;
3025} 2857}
3026 2858
@@ -3031,8 +2863,8 @@ GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
3031 * called after this function returns. 2863 * called after this function returns.
3032 * 2864 *
3033 * @param h handle that was returned from GNUNET_FS_start 2865 * @param h handle that was returned from GNUNET_FS_start
3034 */ 2866 */
3035void 2867void
3036GNUNET_FS_stop (struct GNUNET_FS_Handle *h) 2868GNUNET_FS_stop (struct GNUNET_FS_Handle *h)
3037{ 2869{
3038 while (h->top_head != NULL) 2870 while (h->top_head != NULL)