diff options
Diffstat (limited to 'src/fs/fs_api.c')
-rw-r--r-- | src/fs/fs_api.c | 842 |
1 files changed, 432 insertions, 410 deletions
diff --git a/src/fs/fs_api.c b/src/fs/fs_api.c index aec5ff340..f7b64a5c9 100644 --- a/src/fs/fs_api.c +++ b/src/fs/fs_api.c | |||
@@ -56,12 +56,10 @@ start_job (struct GNUNET_FS_QueueEntry *qe) | |||
56 | qe->h->active_downloads++; | 56 | qe->h->active_downloads++; |
57 | qe->start_time = GNUNET_TIME_absolute_get (); | 57 | qe->start_time = GNUNET_TIME_absolute_get (); |
58 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 58 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
59 | "Starting job %p (%u active)\n", | 59 | "Starting job %p (%u active)\n", |
60 | qe, | 60 | qe, |
61 | qe->h->active_downloads); | 61 | qe->h->active_downloads); |
62 | GNUNET_CONTAINER_DLL_remove (qe->h->pending_head, | 62 | GNUNET_CONTAINER_DLL_remove (qe->h->pending_head, qe->h->pending_tail, qe); |
63 | qe->h->pending_tail, | ||
64 | qe); | ||
65 | GNUNET_CONTAINER_DLL_insert_after (qe->h->running_head, | 63 | GNUNET_CONTAINER_DLL_insert_after (qe->h->running_head, |
66 | qe->h->running_tail, | 64 | qe->h->running_tail, |
67 | qe->h->running_tail, | 65 | qe->h->running_tail, |
@@ -83,17 +81,14 @@ stop_job (struct GNUNET_FS_QueueEntry *qe) | |||
83 | GNUNET_assert (0 < qe->h->active_downloads); | 81 | GNUNET_assert (0 < qe->h->active_downloads); |
84 | qe->h->active_downloads--; | 82 | qe->h->active_downloads--; |
85 | qe->h->active_blocks -= qe->blocks; | 83 | qe->h->active_blocks -= qe->blocks; |
86 | qe->run_time = | 84 | qe->run_time = GNUNET_TIME_relative_add (qe->run_time, |
87 | GNUNET_TIME_relative_add (qe->run_time, | 85 | GNUNET_TIME_absolute_get_duration ( |
88 | GNUNET_TIME_absolute_get_duration | 86 | qe->start_time)); |
89 | (qe->start_time)); | ||
90 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 87 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
91 | "Stopping job %p (%u active)\n", | 88 | "Stopping job %p (%u active)\n", |
92 | qe, | 89 | qe, |
93 | qe->h->active_downloads); | 90 | qe->h->active_downloads); |
94 | GNUNET_CONTAINER_DLL_remove (qe->h->running_head, | 91 | GNUNET_CONTAINER_DLL_remove (qe->h->running_head, qe->h->running_tail, qe); |
95 | qe->h->running_tail, | ||
96 | qe); | ||
97 | GNUNET_CONTAINER_DLL_insert_after (qe->h->pending_head, | 92 | GNUNET_CONTAINER_DLL_insert_after (qe->h->pending_head, |
98 | qe->h->pending_tail, | 93 | qe->h->pending_tail, |
99 | qe->h->pending_tail, | 94 | qe->h->pending_tail, |
@@ -167,13 +162,13 @@ process_job_queue (void *cls) | |||
167 | rst = GNUNET_TIME_absolute_get_remaining (end_time); | 162 | rst = GNUNET_TIME_absolute_get_remaining (end_time); |
168 | if (0 == rst.rel_value_us) | 163 | if (0 == rst.rel_value_us) |
169 | { | 164 | { |
170 | num_probes_expired++; | 165 | num_probes_expired++; |
171 | stop_job (qe); | 166 | stop_job (qe); |
172 | } | 167 | } |
173 | else | 168 | else |
174 | { | 169 | { |
175 | num_probes_active++; | 170 | num_probes_active++; |
176 | restart_at = GNUNET_TIME_relative_min (rst, restart_at); | 171 | restart_at = GNUNET_TIME_relative_min (rst, restart_at); |
177 | } | 172 | } |
178 | break; | 173 | break; |
179 | case GNUNET_FS_QUEUE_PRIORITY_NORMAL: | 174 | case GNUNET_FS_QUEUE_PRIORITY_NORMAL: |
@@ -184,13 +179,13 @@ process_job_queue (void *cls) | |||
184 | rst = GNUNET_TIME_absolute_get_remaining (end_time); | 179 | rst = GNUNET_TIME_absolute_get_remaining (end_time); |
185 | if (0 == rst.rel_value_us) | 180 | if (0 == rst.rel_value_us) |
186 | { | 181 | { |
187 | num_downloads_expired++; | 182 | num_downloads_expired++; |
188 | stop_job (qe); | 183 | stop_job (qe); |
189 | } | 184 | } |
190 | else | 185 | else |
191 | { | 186 | { |
192 | num_downloads_active++; | 187 | num_downloads_active++; |
193 | restart_at = GNUNET_TIME_relative_min (rst, restart_at); | 188 | restart_at = GNUNET_TIME_relative_min (rst, restart_at); |
194 | } | 189 | } |
195 | break; | 190 | break; |
196 | default: | 191 | default: |
@@ -201,41 +196,44 @@ process_job_queue (void *cls) | |||
201 | GNUNET_break (h->active_downloads == | 196 | GNUNET_break (h->active_downloads == |
202 | num_downloads_active + num_probes_active); | 197 | num_downloads_active + num_probes_active); |
203 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 198 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
204 | "PA: %u, PE: %u, PW: %u; DA: %u, DE: %u, DW: %u\n", | 199 | "PA: %u, PE: %u, PW: %u; DA: %u, DE: %u, DW: %u\n", |
205 | num_probes_active, | 200 | num_probes_active, |
206 | num_probes_expired, | 201 | num_probes_expired, |
207 | num_probes_waiting, | 202 | num_probes_waiting, |
208 | num_downloads_active, | 203 | num_downloads_active, |
209 | num_downloads_expired, | 204 | num_downloads_expired, |
210 | num_downloads_waiting); | 205 | num_downloads_waiting); |
211 | GNUNET_break (h->active_downloads + num_probes_active <= | 206 | GNUNET_break (h->active_downloads + num_probes_active <= |
212 | h->max_parallel_downloads); | 207 | h->max_parallel_downloads); |
213 | /* calculate start/stop decisions */ | 208 | /* calculate start/stop decisions */ |
214 | if (h->active_downloads + num_downloads_waiting > h->max_parallel_downloads) | 209 | if (h->active_downloads + num_downloads_waiting > h->max_parallel_downloads) |
215 | { | 210 | { |
216 | /* stop as many probes as there are downloads and probes */ | 211 | /* stop as many probes as there are downloads and probes */ |
217 | num_probes_change = - GNUNET_MIN (num_probes_active, | 212 | num_probes_change = -GNUNET_MIN (num_probes_active, num_downloads_waiting); |
218 | num_downloads_waiting); | ||
219 | /* start as many downloads as there are free slots, including those | 213 | /* start as many downloads as there are free slots, including those |
220 | we just opened up */ | 214 | we just opened up */ |
221 | num_downloads_change = h->max_parallel_downloads - h->active_downloads - num_probes_change; | 215 | num_downloads_change = |
216 | h->max_parallel_downloads - h->active_downloads - num_probes_change; | ||
222 | } | 217 | } |
223 | else | 218 | else |
224 | { | 219 | { |
225 | /* start all downloads (we can) */ | 220 | /* start all downloads (we can) */ |
226 | num_downloads_change = num_downloads_waiting; | 221 | num_downloads_change = num_downloads_waiting; |
227 | /* also start probes if there is room, but use a lower cap of (mpd/4) + 1 */ | 222 | /* also start probes if there is room, but use a lower cap of (mpd/4) + 1 */ |
228 | if (1 + h->max_parallel_downloads / 4 >= (h->active_downloads + num_downloads_change)) | 223 | if (1 + h->max_parallel_downloads / 4 >= |
229 | num_probes_change = GNUNET_MIN (num_probes_waiting, | 224 | (h->active_downloads + num_downloads_change)) |
230 | (1 + h->max_parallel_downloads / 4) - (h->active_downloads + num_downloads_change)); | 225 | num_probes_change = |
226 | GNUNET_MIN (num_probes_waiting, | ||
227 | (1 + h->max_parallel_downloads / 4) - | ||
228 | (h->active_downloads + num_downloads_change)); | ||
231 | else | 229 | else |
232 | num_probes_change = 0; | 230 | num_probes_change = 0; |
233 | } | 231 | } |
234 | GNUNET_break (num_downloads_change <= num_downloads_waiting); | 232 | GNUNET_break (num_downloads_change <= num_downloads_waiting); |
235 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 233 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
236 | "Changing %d probes and %d/%u/%u downloads\n", | 234 | "Changing %d probes and %d/%u/%u downloads\n", |
237 | num_probes_change, | 235 | num_probes_change, |
238 | num_downloads_change, | 236 | num_downloads_change, |
239 | (unsigned int) h->active_downloads, | 237 | (unsigned int) h->active_downloads, |
240 | (unsigned int) h->max_parallel_downloads); | 238 | (unsigned int) h->max_parallel_downloads); |
241 | /* actually stop probes */ | 239 | /* actually stop probes */ |
@@ -250,7 +248,7 @@ process_job_queue (void *cls) | |||
250 | stop_job (qe); | 248 | stop_job (qe); |
251 | num_probes_change++; | 249 | num_probes_change++; |
252 | if (0 == num_probes_change) | 250 | if (0 == num_probes_change) |
253 | break; | 251 | break; |
254 | } | 252 | } |
255 | } | 253 | } |
256 | GNUNET_break (0 <= num_probes_change); | 254 | GNUNET_break (0 <= num_probes_change); |
@@ -258,9 +256,8 @@ process_job_queue (void *cls) | |||
258 | /* start some more tasks if we now have empty slots */ | 256 | /* start some more tasks if we now have empty slots */ |
259 | block_limit_hit = GNUNET_NO; | 257 | block_limit_hit = GNUNET_NO; |
260 | next = h->pending_head; | 258 | next = h->pending_head; |
261 | while ( (NULL != (qe = next)) && | 259 | while ((NULL != (qe = next)) && |
262 | ( (num_probes_change > 0) || | 260 | ((num_probes_change > 0) || (num_downloads_change > 0))) |
263 | (num_downloads_change > 0) ) ) | ||
264 | { | 261 | { |
265 | next = qe->next; | 262 | next = qe->next; |
266 | switch (qe->priority) | 263 | switch (qe->priority) |
@@ -268,40 +265,40 @@ process_job_queue (void *cls) | |||
268 | case GNUNET_FS_QUEUE_PRIORITY_PROBE: | 265 | case GNUNET_FS_QUEUE_PRIORITY_PROBE: |
269 | if (num_probes_change > 0) | 266 | if (num_probes_change > 0) |
270 | { | 267 | { |
271 | start_job (qe); | 268 | start_job (qe); |
272 | num_probes_change--; | 269 | num_probes_change--; |
273 | run_time = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2); | 270 | run_time = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2); |
274 | restart_at = GNUNET_TIME_relative_min (run_time, restart_at); | 271 | restart_at = GNUNET_TIME_relative_min (run_time, restart_at); |
275 | } | 272 | } |
276 | break; | 273 | break; |
277 | case GNUNET_FS_QUEUE_PRIORITY_NORMAL: | 274 | case GNUNET_FS_QUEUE_PRIORITY_NORMAL: |
278 | if ( (num_downloads_change > 0) && | 275 | if ((num_downloads_change > 0) && |
279 | ( (qe->blocks + h->active_blocks <= h->max_parallel_requests) || | 276 | ((qe->blocks + h->active_blocks <= h->max_parallel_requests) || |
280 | ( (qe->blocks > h->max_parallel_requests) && | 277 | ((qe->blocks > h->max_parallel_requests) && |
281 | (0 == h->active_downloads) ) ) ) | 278 | (0 == h->active_downloads)))) |
282 | { | 279 | { |
283 | start_job (qe); | 280 | start_job (qe); |
284 | num_downloads_change--; | 281 | num_downloads_change--; |
285 | } | 282 | } |
286 | else if (num_downloads_change > 0) | 283 | else if (num_downloads_change > 0) |
287 | block_limit_hit = GNUNET_YES; | 284 | block_limit_hit = GNUNET_YES; |
288 | break; | 285 | break; |
289 | default: | 286 | default: |
290 | GNUNET_break (0); | 287 | GNUNET_break (0); |
291 | break; | 288 | break; |
292 | } | 289 | } |
293 | } | 290 | } |
294 | GNUNET_break ( (0 == num_downloads_change) || | 291 | GNUNET_break ((0 == num_downloads_change) || (GNUNET_YES == block_limit_hit)); |
295 | (GNUNET_YES == block_limit_hit) ); | ||
296 | GNUNET_break (0 == num_probes_change); | 292 | GNUNET_break (0 == num_probes_change); |
297 | 293 | ||
298 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 294 | GNUNET_log ( |
299 | "AD: %u, MP: %u; %d probes and %d downloads to start, will run again in %s\n", | 295 | GNUNET_ERROR_TYPE_DEBUG, |
300 | h->active_downloads, | 296 | "AD: %u, MP: %u; %d probes and %d downloads to start, will run again in %s\n", |
301 | h->max_parallel_requests, | 297 | h->active_downloads, |
302 | num_probes_change, | 298 | h->max_parallel_requests, |
303 | num_downloads_change, | 299 | num_probes_change, |
304 | GNUNET_STRINGS_relative_time_to_string (restart_at, GNUNET_YES)); | 300 | num_downloads_change, |
301 | GNUNET_STRINGS_relative_time_to_string (restart_at, GNUNET_YES)); | ||
305 | 302 | ||
306 | /* make sure we run again, callbacks might have | 303 | /* make sure we run again, callbacks might have |
307 | already re-scheduled the job, so cancel such | 304 | already re-scheduled the job, so cancel such |
@@ -309,7 +306,7 @@ process_job_queue (void *cls) | |||
309 | if (NULL != h->queue_job) | 306 | if (NULL != h->queue_job) |
310 | GNUNET_SCHEDULER_cancel (h->queue_job); | 307 | GNUNET_SCHEDULER_cancel (h->queue_job); |
311 | h->queue_job = | 308 | h->queue_job = |
312 | GNUNET_SCHEDULER_add_delayed (restart_at, &process_job_queue, h); | 309 | GNUNET_SCHEDULER_add_delayed (restart_at, &process_job_queue, h); |
313 | } | 310 | } |
314 | 311 | ||
315 | 312 | ||
@@ -330,7 +327,7 @@ GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h, | |||
330 | GNUNET_SCHEDULER_TaskCallback stop, | 327 | GNUNET_SCHEDULER_TaskCallback stop, |
331 | void *cls, | 328 | void *cls, |
332 | unsigned int blocks, | 329 | unsigned int blocks, |
333 | enum GNUNET_FS_QueuePriority priority) | 330 | enum GNUNET_FS_QueuePriority priority) |
334 | { | 331 | { |
335 | struct GNUNET_FS_QueueEntry *qe; | 332 | struct GNUNET_FS_QueueEntry *qe; |
336 | 333 | ||
@@ -342,14 +339,14 @@ GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h, | |||
342 | qe->queue_time = GNUNET_TIME_absolute_get (); | 339 | qe->queue_time = GNUNET_TIME_absolute_get (); |
343 | qe->blocks = blocks; | 340 | qe->blocks = blocks; |
344 | qe->priority = priority; | 341 | qe->priority = priority; |
345 | GNUNET_CONTAINER_DLL_insert_after (h->pending_head, h->pending_tail, | 342 | GNUNET_CONTAINER_DLL_insert_after (h->pending_head, |
346 | h->pending_tail, qe); | 343 | h->pending_tail, |
344 | h->pending_tail, | ||
345 | qe); | ||
347 | if (NULL != h->queue_job) | 346 | if (NULL != h->queue_job) |
348 | GNUNET_SCHEDULER_cancel (h->queue_job); | 347 | GNUNET_SCHEDULER_cancel (h->queue_job); |
349 | h->queue_job = GNUNET_SCHEDULER_add_now (&process_job_queue, h); | 348 | h->queue_job = GNUNET_SCHEDULER_add_now (&process_job_queue, h); |
350 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 349 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Queueing job %p\n", qe); |
351 | "Queueing job %p\n", | ||
352 | qe); | ||
353 | return qe; | 350 | return qe; |
354 | } | 351 | } |
355 | 352 | ||
@@ -365,19 +362,14 @@ GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qe) | |||
365 | struct GNUNET_FS_Handle *h; | 362 | struct GNUNET_FS_Handle *h; |
366 | 363 | ||
367 | h = qe->h; | 364 | h = qe->h; |
368 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 365 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Dequeueing job %p\n", qe); |
369 | "Dequeueing job %p\n", | ||
370 | qe); | ||
371 | if (GNUNET_YES == qe->active) | 366 | if (GNUNET_YES == qe->active) |
372 | stop_job (qe); | 367 | stop_job (qe); |
373 | GNUNET_CONTAINER_DLL_remove (h->pending_head, | 368 | GNUNET_CONTAINER_DLL_remove (h->pending_head, h->pending_tail, qe); |
374 | h->pending_tail, | ||
375 | qe); | ||
376 | GNUNET_free (qe); | 369 | GNUNET_free (qe); |
377 | if (NULL != h->queue_job) | 370 | if (NULL != h->queue_job) |
378 | GNUNET_SCHEDULER_cancel (h->queue_job); | 371 | GNUNET_SCHEDULER_cancel (h->queue_job); |
379 | h->queue_job = GNUNET_SCHEDULER_add_now (&process_job_queue, | 372 | h->queue_job = GNUNET_SCHEDULER_add_now (&process_job_queue, h); |
380 | h); | ||
381 | } | 373 | } |
382 | 374 | ||
383 | 375 | ||
@@ -399,9 +391,7 @@ GNUNET_FS_make_top (struct GNUNET_FS_Handle *h, | |||
399 | ret = GNUNET_new (struct TopLevelActivity); | 391 | ret = GNUNET_new (struct TopLevelActivity); |
400 | ret->ssf = ssf; | 392 | ret->ssf = ssf; |
401 | ret->ssf_cls = ssf_cls; | 393 | ret->ssf_cls = ssf_cls; |
402 | GNUNET_CONTAINER_DLL_insert (h->top_head, | 394 | GNUNET_CONTAINER_DLL_insert (h->top_head, h->top_tail, ret); |
403 | h->top_tail, | ||
404 | ret); | ||
405 | return ret; | 395 | return ret; |
406 | } | 396 | } |
407 | 397 | ||
@@ -413,12 +403,9 @@ GNUNET_FS_make_top (struct GNUNET_FS_Handle *h, | |||
413 | * @param top top level activity entry | 403 | * @param top top level activity entry |
414 | */ | 404 | */ |
415 | void | 405 | void |
416 | GNUNET_FS_end_top (struct GNUNET_FS_Handle *h, | 406 | GNUNET_FS_end_top (struct GNUNET_FS_Handle *h, struct TopLevelActivity *top) |
417 | struct TopLevelActivity *top) | ||
418 | { | 407 | { |
419 | GNUNET_CONTAINER_DLL_remove (h->top_head, | 408 | GNUNET_CONTAINER_DLL_remove (h->top_head, h->top_tail, top); |
420 | h->top_tail, | ||
421 | top); | ||
422 | GNUNET_free (top); | 409 | GNUNET_free (top); |
423 | } | 410 | } |
424 | 411 | ||
@@ -489,33 +476,32 @@ GNUNET_FS_data_reader_file_ (void *cls, | |||
489 | } | 476 | } |
490 | if (NULL == fi->fd) | 477 | if (NULL == fi->fd) |
491 | { | 478 | { |
492 | fi->fd = | 479 | fi->fd = GNUNET_DISK_file_open (fi->filename, |
493 | GNUNET_DISK_file_open (fi->filename, | 480 | GNUNET_DISK_OPEN_READ, |
494 | GNUNET_DISK_OPEN_READ, | 481 | GNUNET_DISK_PERM_NONE); |
495 | GNUNET_DISK_PERM_NONE); | ||
496 | if (NULL == fi->fd) | 482 | if (NULL == fi->fd) |
497 | { | 483 | { |
498 | GNUNET_asprintf (emsg, | 484 | GNUNET_asprintf (emsg, |
499 | _("Could not open file `%s': %s"), | 485 | _ ("Could not open file `%s': %s"), |
500 | fi->filename, | 486 | fi->filename, |
501 | STRERROR (errno)); | 487 | strerror (errno)); |
502 | return 0; | 488 | return 0; |
503 | } | 489 | } |
504 | } | 490 | } |
505 | if ( (GNUNET_SYSERR == | 491 | if ((GNUNET_SYSERR == |
506 | GNUNET_DISK_file_seek (fi->fd, offset, GNUNET_DISK_SEEK_SET)) || | 492 | GNUNET_DISK_file_seek (fi->fd, offset, GNUNET_DISK_SEEK_SET)) || |
507 | (-1 == (ret = GNUNET_DISK_file_read (fi->fd, buf, max))) ) | 493 | (-1 == (ret = GNUNET_DISK_file_read (fi->fd, buf, max)))) |
508 | { | 494 | { |
509 | GNUNET_asprintf (emsg, | 495 | GNUNET_asprintf (emsg, |
510 | _("Could not read file `%s': %s"), | 496 | _ ("Could not read file `%s': %s"), |
511 | fi->filename, | 497 | fi->filename, |
512 | STRERROR (errno)); | 498 | strerror (errno)); |
513 | return 0; | 499 | return 0; |
514 | } | 500 | } |
515 | if (ret != max) | 501 | if (ret != max) |
516 | { | 502 | { |
517 | GNUNET_asprintf (emsg, | 503 | GNUNET_asprintf (emsg, |
518 | _("Short read reading from file `%s'!"), | 504 | _ ("Short read reading from file `%s'!"), |
519 | fi->filename); | 505 | fi->filename); |
520 | return 0; | 506 | return 0; |
521 | } | 507 | } |
@@ -604,13 +590,20 @@ get_serialization_file_name (struct GNUNET_FS_Handle *h, | |||
604 | char *ret; | 590 | char *ret; |
605 | 591 | ||
606 | if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) | 592 | if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) |
607 | return NULL; /* persistence not requested */ | 593 | return NULL; /* persistence not requested */ |
608 | if (GNUNET_OK != | 594 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (h->cfg, |
609 | GNUNET_CONFIGURATION_get_value_filename (h->cfg, "fs", "STATE_DIR", | 595 | "fs", |
610 | &basename)) | 596 | "STATE_DIR", |
597 | &basename)) | ||
611 | return NULL; | 598 | return NULL; |
612 | GNUNET_asprintf (&ret, "%s%s%s%s%s%s%s", basename, DIR_SEPARATOR_STR, | 599 | GNUNET_asprintf (&ret, |
613 | h->client_name, DIR_SEPARATOR_STR, ext, DIR_SEPARATOR_STR, | 600 | "%s%s%s%s%s%s%s", |
601 | basename, | ||
602 | DIR_SEPARATOR_STR, | ||
603 | h->client_name, | ||
604 | DIR_SEPARATOR_STR, | ||
605 | ext, | ||
606 | DIR_SEPARATOR_STR, | ||
614 | ent); | 607 | ent); |
615 | GNUNET_free (basename); | 608 | GNUNET_free (basename); |
616 | return ret; | 609 | return ret; |
@@ -638,14 +631,23 @@ get_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h, | |||
638 | char *ret; | 631 | char *ret; |
639 | 632 | ||
640 | if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) | 633 | if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) |
641 | return NULL; /* persistence not requested */ | 634 | return NULL; /* persistence not requested */ |
642 | if (GNUNET_OK != | 635 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (h->cfg, |
643 | GNUNET_CONFIGURATION_get_value_filename (h->cfg, "fs", "STATE_DIR", | 636 | "fs", |
644 | &basename)) | 637 | "STATE_DIR", |
638 | &basename)) | ||
645 | return NULL; | 639 | return NULL; |
646 | GNUNET_asprintf (&ret, "%s%s%s%s%s%s%s.dir%s%s", basename, DIR_SEPARATOR_STR, | 640 | GNUNET_asprintf (&ret, |
647 | h->client_name, DIR_SEPARATOR_STR, ext, DIR_SEPARATOR_STR, | 641 | "%s%s%s%s%s%s%s.dir%s%s", |
648 | uni, DIR_SEPARATOR_STR, ent); | 642 | basename, |
643 | DIR_SEPARATOR_STR, | ||
644 | h->client_name, | ||
645 | DIR_SEPARATOR_STR, | ||
646 | ext, | ||
647 | DIR_SEPARATOR_STR, | ||
648 | uni, | ||
649 | DIR_SEPARATOR_STR, | ||
650 | ent); | ||
649 | GNUNET_free (basename); | 651 | GNUNET_free (basename); |
650 | return ret; | 652 | return ret; |
651 | } | 653 | } |
@@ -660,9 +662,7 @@ get_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h, | |||
660 | * @return NULL on error | 662 | * @return NULL on error |
661 | */ | 663 | */ |
662 | static struct GNUNET_BIO_ReadHandle * | 664 | static struct GNUNET_BIO_ReadHandle * |
663 | get_read_handle (struct GNUNET_FS_Handle *h, | 665 | get_read_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent) |
664 | const char *ext, | ||
665 | const char *ent) | ||
666 | { | 666 | { |
667 | char *fn; | 667 | char *fn; |
668 | struct GNUNET_BIO_ReadHandle *ret; | 668 | struct GNUNET_BIO_ReadHandle *ret; |
@@ -685,9 +685,7 @@ get_read_handle (struct GNUNET_FS_Handle *h, | |||
685 | * @return NULL on error | 685 | * @return NULL on error |
686 | */ | 686 | */ |
687 | static struct GNUNET_BIO_WriteHandle * | 687 | static struct GNUNET_BIO_WriteHandle * |
688 | get_write_handle (struct GNUNET_FS_Handle *h, | 688 | get_write_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent) |
689 | const char *ext, | ||
690 | const char *ent) | ||
691 | { | 689 | { |
692 | char *fn; | 690 | char *fn; |
693 | struct GNUNET_BIO_WriteHandle *ret; | 691 | struct GNUNET_BIO_WriteHandle *ret; |
@@ -712,8 +710,10 @@ get_write_handle (struct GNUNET_FS_Handle *h, | |||
712 | * @return NULL on error | 710 | * @return NULL on error |
713 | */ | 711 | */ |
714 | static struct GNUNET_BIO_WriteHandle * | 712 | static struct GNUNET_BIO_WriteHandle * |
715 | get_write_handle_in_dir (struct GNUNET_FS_Handle *h, const char *ext, | 713 | get_write_handle_in_dir (struct GNUNET_FS_Handle *h, |
716 | const char *uni, const char *ent) | 714 | const char *ext, |
715 | const char *uni, | ||
716 | const char *ent) | ||
717 | { | 717 | { |
718 | char *fn; | 718 | char *fn; |
719 | struct GNUNET_BIO_WriteHandle *ret; | 719 | struct GNUNET_BIO_WriteHandle *ret; |
@@ -749,8 +749,7 @@ GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h, | |||
749 | filename = get_serialization_file_name (h, ext, ent); | 749 | filename = get_serialization_file_name (h, ext, ent); |
750 | if (NULL != filename) | 750 | if (NULL != filename) |
751 | { | 751 | { |
752 | if ( (0 != UNLINK (filename)) && | 752 | if ((0 != unlink (filename)) && (ENOENT != errno)) |
753 | (ENOENT != errno) ) | ||
754 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); | 753 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); |
755 | GNUNET_free (filename); | 754 | GNUNET_free (filename); |
756 | } | 755 | } |
@@ -768,7 +767,8 @@ GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h, | |||
768 | static void | 767 | static void |
769 | remove_sync_file_in_dir (struct GNUNET_FS_Handle *h, | 768 | remove_sync_file_in_dir (struct GNUNET_FS_Handle *h, |
770 | const char *ext, | 769 | const char *ext, |
771 | const char *uni, const char *ent) | 770 | const char *uni, |
771 | const char *ent) | ||
772 | { | 772 | { |
773 | char *filename; | 773 | char *filename; |
774 | 774 | ||
@@ -780,7 +780,7 @@ remove_sync_file_in_dir (struct GNUNET_FS_Handle *h, | |||
780 | filename = get_serialization_file_name_in_dir (h, ext, uni, ent); | 780 | filename = get_serialization_file_name_in_dir (h, ext, uni, ent); |
781 | if (NULL == filename) | 781 | if (NULL == filename) |
782 | return; | 782 | return; |
783 | if (0 != UNLINK (filename)) | 783 | if (0 != unlink (filename)) |
784 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); | 784 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); |
785 | GNUNET_free (filename); | 785 | GNUNET_free (filename); |
786 | } | 786 | } |
@@ -874,8 +874,7 @@ read_start_time (struct GNUNET_BIO_ReadHandle *rh, | |||
874 | * @return NULL on error | 874 | * @return NULL on error |
875 | */ | 875 | */ |
876 | static struct GNUNET_FS_FileInformation * | 876 | static struct GNUNET_FS_FileInformation * |
877 | deserialize_file_information (struct GNUNET_FS_Handle *h, | 877 | deserialize_file_information (struct GNUNET_FS_Handle *h, const char *filename); |
878 | const char *filename); | ||
879 | 878 | ||
880 | 879 | ||
881 | /** | 880 | /** |
@@ -915,21 +914,22 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h, | |||
915 | filename = NULL; | 914 | filename = NULL; |
916 | if ((GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "metadata", &ret->meta)) || | 915 | if ((GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "metadata", &ret->meta)) || |
917 | (GNUNET_OK != GNUNET_BIO_read_string (rh, "ksk-uri", &ksks, 32 * 1024)) || | 916 | (GNUNET_OK != GNUNET_BIO_read_string (rh, "ksk-uri", &ksks, 32 * 1024)) || |
918 | ( (NULL != ksks) && | 917 | ((NULL != ksks) && |
919 | ( (NULL == (ret->keywords = GNUNET_FS_uri_parse (ksks, NULL))) || | 918 | ((NULL == (ret->keywords = GNUNET_FS_uri_parse (ksks, NULL))) || |
920 | (GNUNET_YES != GNUNET_FS_uri_test_ksk (ret->keywords)) ) ) || | 919 | (GNUNET_YES != GNUNET_FS_uri_test_ksk (ret->keywords)))) || |
921 | (GNUNET_OK != GNUNET_BIO_read_string (rh, "chk-uri", &chks, 1024)) || | 920 | (GNUNET_OK != GNUNET_BIO_read_string (rh, "chk-uri", &chks, 1024)) || |
922 | ( (NULL != chks) && | 921 | ((NULL != chks) && |
923 | ( (NULL == (ret->chk_uri = GNUNET_FS_uri_parse (chks, NULL))) || | 922 | ((NULL == (ret->chk_uri = GNUNET_FS_uri_parse (chks, NULL))) || |
924 | (GNUNET_YES != GNUNET_FS_uri_test_chk (ret->chk_uri))) ) || | 923 | (GNUNET_YES != GNUNET_FS_uri_test_chk (ret->chk_uri)))) || |
925 | (GNUNET_OK != GNUNET_BIO_read_string (rh, "sks-uri", &skss, 1024)) || | 924 | (GNUNET_OK != GNUNET_BIO_read_string (rh, "sks-uri", &skss, 1024)) || |
926 | ( (NULL != skss) && | 925 | ((NULL != skss) && |
927 | ( (NULL == (ret->sks_uri = GNUNET_FS_uri_parse (skss, NULL))) || | 926 | ((NULL == (ret->sks_uri = GNUNET_FS_uri_parse (skss, NULL))) || |
928 | (GNUNET_YES != GNUNET_FS_uri_test_sks (ret->sks_uri))) ) || | 927 | (GNUNET_YES != GNUNET_FS_uri_test_sks (ret->sks_uri)))) || |
929 | (GNUNET_OK != read_start_time (rh, &ret->start_time)) || | 928 | (GNUNET_OK != read_start_time (rh, &ret->start_time)) || |
930 | (GNUNET_OK != GNUNET_BIO_read_string (rh, "emsg", &ret->emsg, 16 * 1024)) | 929 | (GNUNET_OK != |
931 | || (GNUNET_OK != | 930 | GNUNET_BIO_read_string (rh, "emsg", &ret->emsg, 16 * 1024)) || |
932 | GNUNET_BIO_read_string (rh, "fn", &ret->filename, 16 * 1024)) || | 931 | (GNUNET_OK != |
932 | GNUNET_BIO_read_string (rh, "fn", &ret->filename, 16 * 1024)) || | ||
933 | (GNUNET_OK != | 933 | (GNUNET_OK != |
934 | GNUNET_BIO_read_int64 (rh, &ret->bo.expiration_time.abs_value_us)) || | 934 | GNUNET_BIO_read_int64 (rh, &ret->bo.expiration_time.abs_value_us)) || |
935 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &ret->bo.anonymity_level)) || | 935 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &ret->bo.anonymity_level)) || |
@@ -941,7 +941,7 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h, | |||
941 | } | 941 | } |
942 | switch (b) | 942 | switch (b) |
943 | { | 943 | { |
944 | case 0: /* file-insert */ | 944 | case 0: /* file-insert */ |
945 | if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) | 945 | if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) |
946 | { | 946 | { |
947 | GNUNET_break (0); | 947 | GNUNET_break (0); |
@@ -957,12 +957,13 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h, | |||
957 | { | 957 | { |
958 | ret->data.file.reader = &GNUNET_FS_data_reader_copy_; | 958 | ret->data.file.reader = &GNUNET_FS_data_reader_copy_; |
959 | ret->data.file.reader_cls = | 959 | ret->data.file.reader_cls = |
960 | GNUNET_malloc_large (ret->data.file.file_size); | 960 | GNUNET_malloc_large (ret->data.file.file_size); |
961 | if (ret->data.file.reader_cls == NULL) | 961 | if (ret->data.file.reader_cls == NULL) |
962 | goto cleanup; | 962 | goto cleanup; |
963 | if (GNUNET_OK != | 963 | if (GNUNET_OK != GNUNET_BIO_read (rh, |
964 | GNUNET_BIO_read (rh, "file-data", ret->data.file.reader_cls, | 964 | "file-data", |
965 | ret->data.file.file_size)) | 965 | ret->data.file.reader_cls, |
966 | ret->data.file.file_size)) | ||
966 | { | 967 | { |
967 | GNUNET_break (0); | 968 | GNUNET_break (0); |
968 | goto cleanup; | 969 | goto cleanup; |
@@ -972,11 +973,11 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h, | |||
972 | { | 973 | { |
973 | ret->data.file.reader = &GNUNET_FS_data_reader_file_; | 974 | ret->data.file.reader = &GNUNET_FS_data_reader_file_; |
974 | ret->data.file.reader_cls = | 975 | ret->data.file.reader_cls = |
975 | GNUNET_FS_make_file_reader_context_ (ret->filename); | 976 | GNUNET_FS_make_file_reader_context_ (ret->filename); |
976 | } | 977 | } |
977 | } | 978 | } |
978 | break; | 979 | break; |
979 | case 1: /* file-index, no hash */ | 980 | case 1: /* file-index, no hash */ |
980 | if (NULL == ret->filename) | 981 | if (NULL == ret->filename) |
981 | { | 982 | { |
982 | GNUNET_break (0); | 983 | GNUNET_break (0); |
@@ -993,18 +994,19 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h, | |||
993 | ret->data.file.index_start_confirmed = GNUNET_NO; | 994 | ret->data.file.index_start_confirmed = GNUNET_NO; |
994 | ret->data.file.reader = &GNUNET_FS_data_reader_file_; | 995 | ret->data.file.reader = &GNUNET_FS_data_reader_file_; |
995 | ret->data.file.reader_cls = | 996 | ret->data.file.reader_cls = |
996 | GNUNET_FS_make_file_reader_context_ (ret->filename); | 997 | GNUNET_FS_make_file_reader_context_ (ret->filename); |
997 | break; | 998 | break; |
998 | case 2: /* file-index-with-hash */ | 999 | case 2: /* file-index-with-hash */ |
999 | if (NULL == ret->filename) | 1000 | if (NULL == ret->filename) |
1000 | { | 1001 | { |
1001 | GNUNET_break (0); | 1002 | GNUNET_break (0); |
1002 | goto cleanup; | 1003 | goto cleanup; |
1003 | } | 1004 | } |
1004 | if ((GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) || | 1005 | if ((GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) || |
1005 | (GNUNET_OK != | 1006 | (GNUNET_OK != GNUNET_BIO_read (rh, |
1006 | GNUNET_BIO_read (rh, "fileid", &ret->data.file.file_id, | 1007 | "fileid", |
1007 | sizeof (struct GNUNET_HashCode)))) | 1008 | &ret->data.file.file_id, |
1009 | sizeof (struct GNUNET_HashCode)))) | ||
1008 | { | 1010 | { |
1009 | GNUNET_break (0); | 1011 | GNUNET_break (0); |
1010 | goto cleanup; | 1012 | goto cleanup; |
@@ -1015,18 +1017,19 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h, | |||
1015 | ret->data.file.index_start_confirmed = GNUNET_NO; | 1017 | ret->data.file.index_start_confirmed = GNUNET_NO; |
1016 | ret->data.file.reader = &GNUNET_FS_data_reader_file_; | 1018 | ret->data.file.reader = &GNUNET_FS_data_reader_file_; |
1017 | ret->data.file.reader_cls = | 1019 | ret->data.file.reader_cls = |
1018 | GNUNET_FS_make_file_reader_context_ (ret->filename); | 1020 | GNUNET_FS_make_file_reader_context_ (ret->filename); |
1019 | break; | 1021 | break; |
1020 | case 3: /* file-index-with-hash-confirmed */ | 1022 | case 3: /* file-index-with-hash-confirmed */ |
1021 | if (NULL == ret->filename) | 1023 | if (NULL == ret->filename) |
1022 | { | 1024 | { |
1023 | GNUNET_break (0); | 1025 | GNUNET_break (0); |
1024 | goto cleanup; | 1026 | goto cleanup; |
1025 | } | 1027 | } |
1026 | if ((GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) || | 1028 | if ((GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) || |
1027 | (GNUNET_OK != | 1029 | (GNUNET_OK != GNUNET_BIO_read (rh, |
1028 | GNUNET_BIO_read (rh, "fileid", &ret->data.file.file_id, | 1030 | "fileid", |
1029 | sizeof (struct GNUNET_HashCode)))) | 1031 | &ret->data.file.file_id, |
1032 | sizeof (struct GNUNET_HashCode)))) | ||
1030 | { | 1033 | { |
1031 | GNUNET_break (0); | 1034 | GNUNET_break (0); |
1032 | goto cleanup; | 1035 | goto cleanup; |
@@ -1037,13 +1040,15 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h, | |||
1037 | ret->data.file.index_start_confirmed = GNUNET_YES; | 1040 | ret->data.file.index_start_confirmed = GNUNET_YES; |
1038 | ret->data.file.reader = &GNUNET_FS_data_reader_file_; | 1041 | ret->data.file.reader = &GNUNET_FS_data_reader_file_; |
1039 | ret->data.file.reader_cls = | 1042 | ret->data.file.reader_cls = |
1040 | GNUNET_FS_make_file_reader_context_ (ret->filename); | 1043 | GNUNET_FS_make_file_reader_context_ (ret->filename); |
1041 | break; | 1044 | break; |
1042 | case 4: /* directory */ | 1045 | case 4: /* directory */ |
1043 | ret->is_directory = GNUNET_YES; | 1046 | ret->is_directory = GNUNET_YES; |
1044 | if ((GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dsize)) || | 1047 | if ((GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dsize)) || |
1045 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.dir.contents_completed)) || | 1048 | (GNUNET_OK != |
1046 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.dir.contents_size)) || | 1049 | GNUNET_BIO_read_int64 (rh, &ret->data.dir.contents_completed)) || |
1050 | (GNUNET_OK != | ||
1051 | GNUNET_BIO_read_int64 (rh, &ret->data.dir.contents_size)) || | ||
1047 | (NULL == (ret->data.dir.dir_data = GNUNET_malloc_large (dsize))) || | 1052 | (NULL == (ret->data.dir.dir_data = GNUNET_malloc_large (dsize))) || |
1048 | (GNUNET_OK != | 1053 | (GNUNET_OK != |
1049 | GNUNET_BIO_read (rh, "dir-data", ret->data.dir.dir_data, dsize)) || | 1054 | GNUNET_BIO_read (rh, "dir-data", ret->data.dir.dir_data, dsize)) || |
@@ -1108,8 +1113,7 @@ cleanup: | |||
1108 | * @return NULL on error | 1113 | * @return NULL on error |
1109 | */ | 1114 | */ |
1110 | static struct GNUNET_FS_FileInformation * | 1115 | static struct GNUNET_FS_FileInformation * |
1111 | deserialize_file_information (struct GNUNET_FS_Handle *h, | 1116 | deserialize_file_information (struct GNUNET_FS_Handle *h, const char *filename) |
1112 | const char *filename) | ||
1113 | { | 1117 | { |
1114 | struct GNUNET_FS_FileInformation *ret; | 1118 | struct GNUNET_FS_FileInformation *ret; |
1115 | struct GNUNET_BIO_ReadHandle *rh; | 1119 | struct GNUNET_BIO_ReadHandle *rh; |
@@ -1123,17 +1127,19 @@ deserialize_file_information (struct GNUNET_FS_Handle *h, | |||
1123 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) | 1127 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) |
1124 | { | 1128 | { |
1125 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1129 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1126 | _("Failed to resume publishing information `%s': %s\n"), | 1130 | _ ("Failed to resume publishing information `%s': %s\n"), |
1127 | filename, emsg); | 1131 | filename, |
1132 | emsg); | ||
1128 | GNUNET_free (emsg); | 1133 | GNUNET_free (emsg); |
1129 | } | 1134 | } |
1130 | if (NULL == ret) | 1135 | if (NULL == ret) |
1131 | { | 1136 | { |
1132 | fn = get_serialization_file_name (h, GNUNET_FS_SYNC_PATH_FILE_INFO, filename); | 1137 | fn = |
1138 | get_serialization_file_name (h, GNUNET_FS_SYNC_PATH_FILE_INFO, filename); | ||
1133 | if (NULL != fn) | 1139 | if (NULL != fn) |
1134 | { | 1140 | { |
1135 | if (0 != UNLINK (fn)) | 1141 | if (0 != unlink (fn)) |
1136 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | 1142 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); |
1137 | GNUNET_free (fn); | 1143 | GNUNET_free (fn); |
1138 | } | 1144 | } |
1139 | } | 1145 | } |
@@ -1184,15 +1190,14 @@ get_serialization_short_name (const char *fullname) | |||
1184 | * @return NULL on errror | 1190 | * @return NULL on errror |
1185 | */ | 1191 | */ |
1186 | static char * | 1192 | static char * |
1187 | make_serialization_file_name (struct GNUNET_FS_Handle *h, | 1193 | make_serialization_file_name (struct GNUNET_FS_Handle *h, const char *ext) |
1188 | const char *ext) | ||
1189 | { | 1194 | { |
1190 | char *fn; | 1195 | char *fn; |
1191 | char *dn; | 1196 | char *dn; |
1192 | char *ret; | 1197 | char *ret; |
1193 | 1198 | ||
1194 | if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) | 1199 | if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) |
1195 | return NULL; /* persistence not requested */ | 1200 | return NULL; /* persistence not requested */ |
1196 | dn = get_serialization_file_name (h, ext, ""); | 1201 | dn = get_serialization_file_name (h, ext, ""); |
1197 | if (NULL == dn) | 1202 | if (NULL == dn) |
1198 | return NULL; | 1203 | return NULL; |
@@ -1204,7 +1209,7 @@ make_serialization_file_name (struct GNUNET_FS_Handle *h, | |||
1204 | fn = GNUNET_DISK_mktemp (dn); | 1209 | fn = GNUNET_DISK_mktemp (dn); |
1205 | GNUNET_free (dn); | 1210 | GNUNET_free (dn); |
1206 | if (NULL == fn) | 1211 | if (NULL == fn) |
1207 | return NULL; /* epic fail */ | 1212 | return NULL; /* epic fail */ |
1208 | ret = get_serialization_short_name (fn); | 1213 | ret = get_serialization_short_name (fn); |
1209 | GNUNET_free (fn); | 1214 | GNUNET_free (fn); |
1210 | return ret; | 1215 | return ret; |
@@ -1230,7 +1235,7 @@ make_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h, | |||
1230 | char *ret; | 1235 | char *ret; |
1231 | 1236 | ||
1232 | if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) | 1237 | if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) |
1233 | return NULL; /* persistence not requested */ | 1238 | return NULL; /* persistence not requested */ |
1234 | dn = get_serialization_file_name_in_dir (h, ext, uni, ""); | 1239 | dn = get_serialization_file_name_in_dir (h, ext, uni, ""); |
1235 | if (NULL == dn) | 1240 | if (NULL == dn) |
1236 | return NULL; | 1241 | return NULL; |
@@ -1242,7 +1247,7 @@ make_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h, | |||
1242 | fn = GNUNET_DISK_mktemp (dn); | 1247 | fn = GNUNET_DISK_mktemp (dn); |
1243 | GNUNET_free (dn); | 1248 | GNUNET_free (dn); |
1244 | if (NULL == fn) | 1249 | if (NULL == fn) |
1245 | return NULL; /* epic fail */ | 1250 | return NULL; /* epic fail */ |
1246 | ret = get_serialization_short_name (fn); | 1251 | ret = get_serialization_short_name (fn); |
1247 | GNUNET_free (fn); | 1252 | GNUNET_free (fn); |
1248 | return ret; | 1253 | return ret; |
@@ -1272,7 +1277,7 @@ copy_from_reader (struct GNUNET_BIO_WriteHandle *wh, | |||
1272 | { | 1277 | { |
1273 | left = GNUNET_MIN (sizeof (buf), fi->data.file.file_size - off); | 1278 | left = GNUNET_MIN (sizeof (buf), fi->data.file.file_size - off); |
1274 | ret = | 1279 | ret = |
1275 | fi->data.file.reader (fi->data.file.reader_cls, off, left, buf, &emsg); | 1280 | fi->data.file.reader (fi->data.file.reader_cls, off, left, buf, &emsg); |
1276 | if (0 == ret) | 1281 | if (0 == ret) |
1277 | { | 1282 | { |
1278 | GNUNET_free (emsg); | 1283 | GNUNET_free (emsg); |
@@ -1304,11 +1309,11 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) | |||
1304 | 1309 | ||
1305 | if (NULL == fi->serialization) | 1310 | if (NULL == fi->serialization) |
1306 | fi->serialization = | 1311 | fi->serialization = |
1307 | make_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO); | 1312 | make_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO); |
1308 | if (NULL == fi->serialization) | 1313 | if (NULL == fi->serialization) |
1309 | return; | 1314 | return; |
1310 | wh = get_write_handle (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO, | 1315 | wh = |
1311 | fi->serialization); | 1316 | get_write_handle (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO, fi->serialization); |
1312 | if (NULL == wh) | 1317 | if (NULL == wh) |
1313 | { | 1318 | { |
1314 | GNUNET_free (fi->serialization); | 1319 | GNUNET_free (fi->serialization); |
@@ -1363,7 +1368,7 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) | |||
1363 | 1368 | ||
1364 | switch (b) | 1369 | switch (b) |
1365 | { | 1370 | { |
1366 | case 0: /* file-insert */ | 1371 | case 0: /* file-insert */ |
1367 | if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) | 1372 | if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) |
1368 | { | 1373 | { |
1369 | GNUNET_break (0); | 1374 | GNUNET_break (0); |
@@ -1376,7 +1381,7 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) | |||
1376 | goto cleanup; | 1381 | goto cleanup; |
1377 | } | 1382 | } |
1378 | break; | 1383 | break; |
1379 | case 1: /* file-index, no hash */ | 1384 | case 1: /* file-index, no hash */ |
1380 | if (NULL == fi->filename) | 1385 | if (NULL == fi->filename) |
1381 | { | 1386 | { |
1382 | GNUNET_break (0); | 1387 | GNUNET_break (0); |
@@ -1388,37 +1393,39 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) | |||
1388 | goto cleanup; | 1393 | goto cleanup; |
1389 | } | 1394 | } |
1390 | break; | 1395 | break; |
1391 | case 2: /* file-index-with-hash */ | 1396 | case 2: /* file-index-with-hash */ |
1392 | case 3: /* file-index-with-hash-confirmed */ | 1397 | case 3: /* file-index-with-hash-confirmed */ |
1393 | if (NULL == fi->filename) | 1398 | if (NULL == fi->filename) |
1394 | { | 1399 | { |
1395 | GNUNET_break (0); | 1400 | GNUNET_break (0); |
1396 | goto cleanup; | 1401 | goto cleanup; |
1397 | } | 1402 | } |
1398 | if ((GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) || | 1403 | if ((GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) || |
1399 | (GNUNET_OK != | 1404 | (GNUNET_OK != GNUNET_BIO_write (wh, |
1400 | GNUNET_BIO_write (wh, &fi->data.file.file_id, | 1405 | &fi->data.file.file_id, |
1401 | sizeof (struct GNUNET_HashCode)))) | 1406 | sizeof (struct GNUNET_HashCode)))) |
1402 | { | 1407 | { |
1403 | GNUNET_break (0); | 1408 | GNUNET_break (0); |
1404 | goto cleanup; | 1409 | goto cleanup; |
1405 | } | 1410 | } |
1406 | break; | 1411 | break; |
1407 | case 4: /* directory */ | 1412 | case 4: /* directory */ |
1408 | if ( (NULL != fi->data.dir.entries) && | 1413 | if ((NULL != fi->data.dir.entries) && |
1409 | (NULL == fi->data.dir.entries->serialization) ) | 1414 | (NULL == fi->data.dir.entries->serialization)) |
1410 | GNUNET_FS_file_information_sync_ (fi->data.dir.entries); | 1415 | GNUNET_FS_file_information_sync_ (fi->data.dir.entries); |
1411 | if ((GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->data.dir.dir_size)) || | 1416 | if ((GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->data.dir.dir_size)) || |
1412 | (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.dir.contents_completed)) || | ||
1413 | (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.dir.contents_size)) || | ||
1414 | (GNUNET_OK != | 1417 | (GNUNET_OK != |
1415 | GNUNET_BIO_write (wh, fi->data.dir.dir_data, | 1418 | GNUNET_BIO_write_int64 (wh, fi->data.dir.contents_completed)) || |
1416 | (uint32_t) fi->data.dir.dir_size)) || | 1419 | (GNUNET_OK != |
1420 | GNUNET_BIO_write_int64 (wh, fi->data.dir.contents_size)) || | ||
1421 | (GNUNET_OK != GNUNET_BIO_write (wh, | ||
1422 | fi->data.dir.dir_data, | ||
1423 | (uint32_t) fi->data.dir.dir_size)) || | ||
1417 | (GNUNET_OK != | 1424 | (GNUNET_OK != |
1418 | GNUNET_BIO_write_string (wh, | 1425 | GNUNET_BIO_write_string (wh, |
1419 | (fi->data.dir.entries == | 1426 | (fi->data.dir.entries == NULL) |
1420 | NULL) ? NULL : fi->data.dir. | 1427 | ? NULL |
1421 | entries->serialization))) | 1428 | : fi->data.dir.entries->serialization))) |
1422 | { | 1429 | { |
1423 | GNUNET_break (0); | 1430 | GNUNET_break (0); |
1424 | goto cleanup; | 1431 | goto cleanup; |
@@ -1428,13 +1435,12 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) | |||
1428 | GNUNET_assert (0); | 1435 | GNUNET_assert (0); |
1429 | goto cleanup; | 1436 | goto cleanup; |
1430 | } | 1437 | } |
1431 | if ( (NULL != fi->next) && | 1438 | if ((NULL != fi->next) && (NULL == fi->next->serialization)) |
1432 | (NULL == fi->next->serialization) ) | ||
1433 | GNUNET_FS_file_information_sync_ (fi->next); | 1439 | GNUNET_FS_file_information_sync_ (fi->next); |
1434 | if (GNUNET_OK != | 1440 | if (GNUNET_OK != GNUNET_BIO_write_string (wh, |
1435 | GNUNET_BIO_write_string (wh, | 1441 | (fi->next != NULL) |
1436 | (fi->next != | 1442 | ? fi->next->serialization |
1437 | NULL) ? fi->next->serialization : NULL)) | 1443 | : NULL)) |
1438 | { | 1444 | { |
1439 | GNUNET_break (0); | 1445 | GNUNET_break (0); |
1440 | goto cleanup; | 1446 | goto cleanup; |
@@ -1445,18 +1451,19 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) | |||
1445 | GNUNET_break (0); | 1451 | GNUNET_break (0); |
1446 | goto cleanup; | 1452 | goto cleanup; |
1447 | } | 1453 | } |
1448 | return; /* done! */ | 1454 | return; /* done! */ |
1449 | cleanup: | 1455 | cleanup: |
1450 | if (NULL != wh) | 1456 | if (NULL != wh) |
1451 | (void) GNUNET_BIO_write_close (wh); | 1457 | (void) GNUNET_BIO_write_close (wh); |
1452 | GNUNET_free_non_null (chks); | 1458 | GNUNET_free_non_null (chks); |
1453 | GNUNET_free_non_null (ksks); | 1459 | GNUNET_free_non_null (ksks); |
1454 | GNUNET_free_non_null (skss); | 1460 | GNUNET_free_non_null (skss); |
1455 | fn = get_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO, | 1461 | fn = get_serialization_file_name (fi->h, |
1462 | GNUNET_FS_SYNC_PATH_FILE_INFO, | ||
1456 | fi->serialization); | 1463 | fi->serialization); |
1457 | if (NULL != fn) | 1464 | if (NULL != fn) |
1458 | { | 1465 | { |
1459 | if (0 != UNLINK (fn)) | 1466 | if (0 != unlink (fn)) |
1460 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | 1467 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); |
1461 | GNUNET_free (fn); | 1468 | GNUNET_free (fn); |
1462 | } | 1469 | } |
@@ -1465,7 +1472,6 @@ cleanup: | |||
1465 | } | 1472 | } |
1466 | 1473 | ||
1467 | 1474 | ||
1468 | |||
1469 | /** | 1475 | /** |
1470 | * Find the entry in the file information struct where the | 1476 | * Find the entry in the file information struct where the |
1471 | * serialization filename matches the given name. | 1477 | * serialization filename matches the given name. |
@@ -1475,8 +1481,7 @@ cleanup: | |||
1475 | * @return NULL if srch was not found in this subtree | 1481 | * @return NULL if srch was not found in this subtree |
1476 | */ | 1482 | */ |
1477 | static struct GNUNET_FS_FileInformation * | 1483 | static struct GNUNET_FS_FileInformation * |
1478 | find_file_position (struct GNUNET_FS_FileInformation *pos, | 1484 | find_file_position (struct GNUNET_FS_FileInformation *pos, const char *srch) |
1479 | const char *srch) | ||
1480 | { | 1485 | { |
1481 | struct GNUNET_FS_FileInformation *r; | 1486 | struct GNUNET_FS_FileInformation *r; |
1482 | 1487 | ||
@@ -1484,8 +1489,8 @@ find_file_position (struct GNUNET_FS_FileInformation *pos, | |||
1484 | { | 1489 | { |
1485 | if (0 == strcmp (srch, pos->serialization)) | 1490 | if (0 == strcmp (srch, pos->serialization)) |
1486 | return pos; | 1491 | return pos; |
1487 | if ( (GNUNET_YES == pos->is_directory) && | 1492 | if ((GNUNET_YES == pos->is_directory) && |
1488 | (NULL != (r = find_file_position (pos->data.dir.entries, srch))) ) | 1493 | (NULL != (r = find_file_position (pos->data.dir.entries, srch)))) |
1489 | return r; | 1494 | return r; |
1490 | pos = pos->next; | 1495 | pos = pos->next; |
1491 | } | 1496 | } |
@@ -1548,8 +1553,7 @@ fip_signal_resume (void *cls, | |||
1548 | * @return #GNUNET_OK (continue to iterate) | 1553 | * @return #GNUNET_OK (continue to iterate) |
1549 | */ | 1554 | */ |
1550 | static int | 1555 | static int |
1551 | deserialize_publish_file (void *cls, | 1556 | deserialize_publish_file (void *cls, const char *filename) |
1552 | const char *filename) | ||
1553 | { | 1557 | { |
1554 | struct GNUNET_FS_Handle *h = cls; | 1558 | struct GNUNET_FS_Handle *h = cls; |
1555 | struct GNUNET_BIO_ReadHandle *rh; | 1559 | struct GNUNET_BIO_ReadHandle *rh; |
@@ -1573,17 +1577,19 @@ deserialize_publish_file (void *cls, | |||
1573 | GNUNET_break (0); | 1577 | GNUNET_break (0); |
1574 | goto cleanup; | 1578 | goto cleanup; |
1575 | } | 1579 | } |
1576 | if ((GNUNET_OK != GNUNET_BIO_read_string (rh, "publish-nid", &pc->nid, 1024)) | 1580 | if ((GNUNET_OK != |
1577 | || (GNUNET_OK != | 1581 | GNUNET_BIO_read_string (rh, "publish-nid", &pc->nid, 1024)) || |
1578 | GNUNET_BIO_read_string (rh, "publish-nuid", &pc->nuid, 1024)) || | 1582 | (GNUNET_OK != |
1583 | GNUNET_BIO_read_string (rh, "publish-nuid", &pc->nuid, 1024)) || | ||
1579 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &options)) || | 1584 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &options)) || |
1580 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &all_done)) || | 1585 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &all_done)) || |
1581 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &have_ns)) || | 1586 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &have_ns)) || |
1582 | (GNUNET_OK != | 1587 | (GNUNET_OK != |
1583 | GNUNET_BIO_read_string (rh, "publish-firoot", &fi_root, 128)) || | 1588 | GNUNET_BIO_read_string (rh, "publish-firoot", &fi_root, 128)) || |
1584 | (GNUNET_OK != GNUNET_BIO_read_string (rh, "publish-fipos", &fi_pos, 128)) | 1589 | (GNUNET_OK != |
1585 | || ( (GNUNET_YES == have_ns) && | 1590 | GNUNET_BIO_read_string (rh, "publish-fipos", &fi_pos, 128)) || |
1586 | (GNUNET_OK != GNUNET_BIO_read (rh, "publish-ns", &ns, sizeof (ns)))) ) | 1591 | ((GNUNET_YES == have_ns) && |
1592 | (GNUNET_OK != GNUNET_BIO_read (rh, "publish-ns", &ns, sizeof (ns))))) | ||
1587 | { | 1593 | { |
1588 | GNUNET_break (0); | 1594 | GNUNET_break (0); |
1589 | goto cleanup; | 1595 | goto cleanup; |
@@ -1636,20 +1642,19 @@ deserialize_publish_file (void *cls, | |||
1636 | { | 1642 | { |
1637 | GNUNET_assert (NULL == pc->upload_task); | 1643 | GNUNET_assert (NULL == pc->upload_task); |
1638 | pc->upload_task = | 1644 | pc->upload_task = |
1639 | GNUNET_SCHEDULER_add_with_priority | 1645 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, |
1640 | (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, | 1646 | &GNUNET_FS_publish_main_, |
1641 | &GNUNET_FS_publish_main_, pc); | 1647 | pc); |
1642 | } | 1648 | } |
1643 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) | 1649 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) |
1644 | { | 1650 | { |
1645 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1651 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1646 | _("Failure while resuming publishing operation `%s': %s\n"), | 1652 | _ ("Failure while resuming publishing operation `%s': %s\n"), |
1647 | filename, emsg); | 1653 | filename, |
1654 | emsg); | ||
1648 | GNUNET_free (emsg); | 1655 | GNUNET_free (emsg); |
1649 | } | 1656 | } |
1650 | pc->top = GNUNET_FS_make_top (h, | 1657 | pc->top = GNUNET_FS_make_top (h, &GNUNET_FS_publish_signal_suspend_, pc); |
1651 | &GNUNET_FS_publish_signal_suspend_, | ||
1652 | pc); | ||
1653 | return GNUNET_OK; | 1658 | return GNUNET_OK; |
1654 | cleanup: | 1659 | cleanup: |
1655 | GNUNET_free_non_null (pc->nid); | 1660 | GNUNET_free_non_null (pc->nid); |
@@ -1659,13 +1664,14 @@ cleanup: | |||
1659 | if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))) | 1664 | if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))) |
1660 | { | 1665 | { |
1661 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1666 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1662 | _("Failed to resume publishing operation `%s': %s\n"), filename, | 1667 | _ ("Failed to resume publishing operation `%s': %s\n"), |
1668 | filename, | ||
1663 | emsg); | 1669 | emsg); |
1664 | GNUNET_free (emsg); | 1670 | GNUNET_free (emsg); |
1665 | } | 1671 | } |
1666 | if (NULL != pc->fi) | 1672 | if (NULL != pc->fi) |
1667 | GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL); | 1673 | GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL); |
1668 | if (0 != UNLINK (filename)) | 1674 | if (0 != unlink (filename)) |
1669 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); | 1675 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); |
1670 | GNUNET_free (pc->serialization); | 1676 | GNUNET_free (pc->serialization); |
1671 | GNUNET_free (pc); | 1677 | GNUNET_free (pc); |
@@ -1689,8 +1695,7 @@ GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc) | |||
1689 | 1695 | ||
1690 | if (NULL == pc->serialization) | 1696 | if (NULL == pc->serialization) |
1691 | pc->serialization = | 1697 | pc->serialization = |
1692 | make_serialization_file_name (pc->h, | 1698 | make_serialization_file_name (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH); |
1693 | GNUNET_FS_SYNC_PATH_MASTER_PUBLISH); | ||
1694 | if (NULL == pc->serialization) | 1699 | if (NULL == pc->serialization) |
1695 | return; | 1700 | return; |
1696 | if (NULL == pc->fi) | 1701 | if (NULL == pc->fi) |
@@ -1700,7 +1705,8 @@ GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc) | |||
1700 | GNUNET_break (0); | 1705 | GNUNET_break (0); |
1701 | return; | 1706 | return; |
1702 | } | 1707 | } |
1703 | wh = get_write_handle (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, | 1708 | wh = get_write_handle (pc->h, |
1709 | GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, | ||
1704 | pc->serialization); | 1710 | pc->serialization); |
1705 | if (NULL == wh) | 1711 | if (NULL == wh) |
1706 | { | 1712 | { |
@@ -1714,13 +1720,15 @@ GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc) | |||
1714 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pc->all_done)) || | 1720 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pc->all_done)) || |
1715 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, have_ns)) || | 1721 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, have_ns)) || |
1716 | (GNUNET_OK != GNUNET_BIO_write_string (wh, pc->fi->serialization)) || | 1722 | (GNUNET_OK != GNUNET_BIO_write_string (wh, pc->fi->serialization)) || |
1717 | (GNUNET_OK != | 1723 | (GNUNET_OK != GNUNET_BIO_write_string (wh, |
1718 | GNUNET_BIO_write_string (wh, | 1724 | (NULL == pc->fi_pos) |
1719 | (NULL == pc->fi_pos) ? NULL : pc->fi_pos->serialization)) || | 1725 | ? NULL |
1720 | ( (NULL != pc->ns) && | 1726 | : pc->fi_pos->serialization)) || |
1721 | (GNUNET_OK != GNUNET_BIO_write (wh, | 1727 | ((NULL != pc->ns) && |
1722 | pc->ns, | 1728 | (GNUNET_OK != |
1723 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)) ) )) | 1729 | GNUNET_BIO_write (wh, |
1730 | pc->ns, | ||
1731 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))))) | ||
1724 | { | 1732 | { |
1725 | GNUNET_break (0); | 1733 | GNUNET_break (0); |
1726 | goto cleanup; | 1734 | goto cleanup; |
@@ -1735,7 +1743,8 @@ GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc) | |||
1735 | cleanup: | 1743 | cleanup: |
1736 | if (NULL != wh) | 1744 | if (NULL != wh) |
1737 | (void) GNUNET_BIO_write_close (wh); | 1745 | (void) GNUNET_BIO_write_close (wh); |
1738 | GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, | 1746 | GNUNET_FS_remove_sync_file_ (pc->h, |
1747 | GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, | ||
1739 | pc->serialization); | 1748 | pc->serialization); |
1740 | GNUNET_free (pc->serialization); | 1749 | GNUNET_free (pc->serialization); |
1741 | pc->serialization = NULL; | 1750 | pc->serialization = NULL; |
@@ -1758,11 +1767,11 @@ GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc) | |||
1758 | 1767 | ||
1759 | if (NULL == uc->serialization) | 1768 | if (NULL == uc->serialization) |
1760 | uc->serialization = | 1769 | uc->serialization = |
1761 | make_serialization_file_name (uc->h, | 1770 | make_serialization_file_name (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX); |
1762 | GNUNET_FS_SYNC_PATH_MASTER_UNINDEX); | ||
1763 | if (NULL == uc->serialization) | 1771 | if (NULL == uc->serialization) |
1764 | return; | 1772 | return; |
1765 | wh = get_write_handle (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, | 1773 | wh = get_write_handle (uc->h, |
1774 | GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, | ||
1766 | uc->serialization); | 1775 | uc->serialization); |
1767 | if (NULL == wh) | 1776 | if (NULL == wh) |
1768 | { | 1777 | { |
@@ -1782,8 +1791,9 @@ GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc) | |||
1782 | (GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) || | 1791 | (GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) || |
1783 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) uc->ksk_offset)) || | 1792 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) uc->ksk_offset)) || |
1784 | ((uc->state == UNINDEX_STATE_FS_NOTIFY) && | 1793 | ((uc->state == UNINDEX_STATE_FS_NOTIFY) && |
1785 | (GNUNET_OK != | 1794 | (GNUNET_OK != GNUNET_BIO_write (wh, |
1786 | GNUNET_BIO_write (wh, &uc->file_id, sizeof (struct GNUNET_HashCode)))) || | 1795 | &uc->file_id, |
1796 | sizeof (struct GNUNET_HashCode)))) || | ||
1787 | ((uc->state == UNINDEX_STATE_ERROR) && | 1797 | ((uc->state == UNINDEX_STATE_ERROR) && |
1788 | (GNUNET_OK != GNUNET_BIO_write_string (wh, uc->emsg)))) | 1798 | (GNUNET_OK != GNUNET_BIO_write_string (wh, uc->emsg)))) |
1789 | { | 1799 | { |
@@ -1800,7 +1810,8 @@ GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc) | |||
1800 | cleanup: | 1810 | cleanup: |
1801 | if (NULL != wh) | 1811 | if (NULL != wh) |
1802 | (void) GNUNET_BIO_write_close (wh); | 1812 | (void) GNUNET_BIO_write_close (wh); |
1803 | GNUNET_FS_remove_sync_file_ (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, | 1813 | GNUNET_FS_remove_sync_file_ (uc->h, |
1814 | GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, | ||
1804 | uc->serialization); | 1815 | uc->serialization); |
1805 | GNUNET_free (uc->serialization); | 1816 | GNUNET_free (uc->serialization); |
1806 | uc->serialization = NULL; | 1817 | uc->serialization = NULL; |
@@ -1854,8 +1865,7 @@ read_download_request (struct GNUNET_BIO_ReadHandle *rh) | |||
1854 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->num_children)) || | 1865 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->num_children)) || |
1855 | (dr->num_children > CHK_PER_INODE) || | 1866 | (dr->num_children > CHK_PER_INODE) || |
1856 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->depth)) || | 1867 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->depth)) || |
1857 | ( (0 == dr->depth) && | 1868 | ((0 == dr->depth) && (dr->num_children > 0)) || |
1858 | (dr->num_children > 0) ) || | ||
1859 | ((dr->depth > 0) && (0 == dr->num_children))) | 1869 | ((dr->depth > 0) && (0 == dr->num_children))) |
1860 | { | 1870 | { |
1861 | GNUNET_break (0); | 1871 | GNUNET_break (0); |
@@ -1864,7 +1874,7 @@ read_download_request (struct GNUNET_BIO_ReadHandle *rh) | |||
1864 | } | 1874 | } |
1865 | if (dr->num_children > 0) | 1875 | if (dr->num_children > 0) |
1866 | dr->children = | 1876 | dr->children = |
1867 | GNUNET_malloc (dr->num_children * sizeof (struct DownloadRequest *)); | 1877 | GNUNET_malloc (dr->num_children * sizeof (struct DownloadRequest *)); |
1868 | switch (dr->state) | 1878 | switch (dr->state) |
1869 | { | 1879 | { |
1870 | case BRS_INIT: | 1880 | case BRS_INIT: |
@@ -1917,9 +1927,9 @@ get_download_sync_filename (struct GNUNET_FS_DownloadContext *dc, | |||
1917 | 1927 | ||
1918 | if (dc->parent == NULL) | 1928 | if (dc->parent == NULL) |
1919 | return get_serialization_file_name (dc->h, | 1929 | return get_serialization_file_name (dc->h, |
1920 | (dc->search != NULL) ? | 1930 | (dc->search != NULL) |
1921 | GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD : | 1931 | ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD |
1922 | GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, | 1932 | : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, |
1923 | uni); | 1933 | uni); |
1924 | if (NULL == dc->parent->serialization) | 1934 | if (NULL == dc->parent->serialization) |
1925 | return NULL; | 1935 | return NULL; |
@@ -2028,7 +2038,7 @@ cleanup: | |||
2028 | if (NULL != wh) | 2038 | if (NULL != wh) |
2029 | (void) GNUNET_BIO_write_close (wh); | 2039 | (void) GNUNET_BIO_write_close (wh); |
2030 | GNUNET_free_non_null (uris); | 2040 | GNUNET_free_non_null (uris); |
2031 | if (0 != UNLINK (fn)) | 2041 | if (0 != unlink (fn)) |
2032 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | 2042 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); |
2033 | GNUNET_free (fn); | 2043 | GNUNET_free (fn); |
2034 | GNUNET_free (dc->serialization); | 2044 | GNUNET_free (dc->serialization); |
@@ -2055,19 +2065,19 @@ GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr) | |||
2055 | uris = NULL; | 2065 | uris = NULL; |
2056 | if (NULL == sr->serialization) | 2066 | if (NULL == sr->serialization) |
2057 | sr->serialization = | 2067 | sr->serialization = |
2058 | make_serialization_file_name_in_dir (sr->h, | 2068 | make_serialization_file_name_in_dir (sr->h, |
2059 | (sr->sc->psearch_result == | 2069 | (sr->sc->psearch_result == NULL) |
2060 | NULL) ? | 2070 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH |
2061 | GNUNET_FS_SYNC_PATH_MASTER_SEARCH : | 2071 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, |
2062 | GNUNET_FS_SYNC_PATH_CHILD_SEARCH, | 2072 | sr->sc->serialization); |
2063 | sr->sc->serialization); | ||
2064 | if (NULL == sr->serialization) | 2073 | if (NULL == sr->serialization) |
2065 | return; | 2074 | return; |
2066 | wh = get_write_handle_in_dir (sr->h, | 2075 | wh = get_write_handle_in_dir (sr->h, |
2067 | (sr->sc->psearch_result == | 2076 | (sr->sc->psearch_result == NULL) |
2068 | NULL) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH : | 2077 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH |
2069 | GNUNET_FS_SYNC_PATH_CHILD_SEARCH, | 2078 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, |
2070 | sr->sc->serialization, sr->serialization); | 2079 | sr->sc->serialization, |
2080 | sr->serialization); | ||
2071 | if (NULL == wh) | 2081 | if (NULL == wh) |
2072 | { | 2082 | { |
2073 | GNUNET_break (0); | 2083 | GNUNET_break (0); |
@@ -2075,28 +2085,31 @@ GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr) | |||
2075 | } | 2085 | } |
2076 | uris = GNUNET_FS_uri_to_string (sr->uri); | 2086 | uris = GNUNET_FS_uri_to_string (sr->uri); |
2077 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) || | 2087 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) || |
2088 | (GNUNET_OK != GNUNET_BIO_write_string (wh, | ||
2089 | sr->download != NULL | ||
2090 | ? sr->download->serialization | ||
2091 | : NULL)) || | ||
2078 | (GNUNET_OK != | 2092 | (GNUNET_OK != |
2079 | GNUNET_BIO_write_string (wh, | 2093 | GNUNET_BIO_write_string (wh, |
2080 | sr->download != | 2094 | sr->update_search != NULL |
2081 | NULL ? sr->download->serialization : NULL)) || | 2095 | ? sr->update_search->serialization |
2096 | : NULL)) || | ||
2097 | (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, sr->meta)) || | ||
2082 | (GNUNET_OK != | 2098 | (GNUNET_OK != |
2083 | GNUNET_BIO_write_string (wh, | 2099 | GNUNET_BIO_write (wh, &sr->key, sizeof (struct GNUNET_HashCode))) || |
2084 | sr->update_search != | 2100 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->mandatory_missing)) || |
2085 | NULL ? sr->update_search->serialization : NULL)) | ||
2086 | || (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, sr->meta)) || | ||
2087 | (GNUNET_OK != GNUNET_BIO_write (wh, &sr->key, sizeof (struct GNUNET_HashCode))) | ||
2088 | || (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->mandatory_missing)) || | ||
2089 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->optional_support)) || | 2101 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->optional_support)) || |
2090 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->availability_success)) || | 2102 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->availability_success)) || |
2091 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->availability_trials)) ) | 2103 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->availability_trials))) |
2092 | { | 2104 | { |
2093 | GNUNET_break (0); | 2105 | GNUNET_break (0); |
2094 | goto cleanup; | 2106 | goto cleanup; |
2095 | } | 2107 | } |
2096 | if ( (NULL != sr->uri) && | 2108 | if ((NULL != sr->uri) && (GNUNET_FS_URI_KSK == sr->sc->uri->type) && |
2097 | (GNUNET_FS_URI_KSK == sr->sc->uri->type) && | 2109 | (GNUNET_OK != |
2098 | (GNUNET_OK != GNUNET_BIO_write (wh, sr->keyword_bitmap, | 2110 | GNUNET_BIO_write (wh, |
2099 | (sr->sc->uri->data.ksk.keywordCount + 7) / 8)) ) | 2111 | sr->keyword_bitmap, |
2112 | (sr->sc->uri->data.ksk.keywordCount + 7) / 8))) | ||
2100 | { | 2113 | { |
2101 | GNUNET_break (0); | 2114 | GNUNET_break (0); |
2102 | goto cleanup; | 2115 | goto cleanup; |
@@ -2115,9 +2128,10 @@ cleanup: | |||
2115 | (void) GNUNET_BIO_write_close (wh); | 2128 | (void) GNUNET_BIO_write_close (wh); |
2116 | remove_sync_file_in_dir (sr->h, | 2129 | remove_sync_file_in_dir (sr->h, |
2117 | (NULL == sr->sc->psearch_result) | 2130 | (NULL == sr->sc->psearch_result) |
2118 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH | 2131 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH |
2119 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, | 2132 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, |
2120 | sr->sc->serialization, sr->serialization); | 2133 | sr->sc->serialization, |
2134 | sr->serialization); | ||
2121 | GNUNET_free (sr->serialization); | 2135 | GNUNET_free (sr->serialization); |
2122 | sr->serialization = NULL; | 2136 | sr->serialization = NULL; |
2123 | } | 2137 | } |
@@ -2139,10 +2153,8 @@ GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc) | |||
2139 | char in_pause; | 2153 | char in_pause; |
2140 | const char *category; | 2154 | const char *category; |
2141 | 2155 | ||
2142 | category = | 2156 | category = (NULL == sc->psearch_result) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH |
2143 | (NULL == sc->psearch_result) | 2157 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH; |
2144 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH | ||
2145 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH; | ||
2146 | if (NULL == sc->serialization) | 2158 | if (NULL == sc->serialization) |
2147 | sc->serialization = make_serialization_file_name (sc->h, category); | 2159 | sc->serialization = make_serialization_file_name (sc->h, category); |
2148 | if (NULL == sc->serialization) | 2160 | if (NULL == sc->serialization) |
@@ -2196,8 +2208,7 @@ cleanup: | |||
2196 | * @return #GNUNET_OK (continue to iterate) | 2208 | * @return #GNUNET_OK (continue to iterate) |
2197 | */ | 2209 | */ |
2198 | static int | 2210 | static int |
2199 | deserialize_unindex_file (void *cls, | 2211 | deserialize_unindex_file (void *cls, const char *filename) |
2200 | const char *filename) | ||
2201 | { | 2212 | { |
2202 | struct GNUNET_FS_Handle *h = cls; | 2213 | struct GNUNET_FS_Handle *h = cls; |
2203 | struct GNUNET_BIO_ReadHandle *rh; | 2214 | struct GNUNET_BIO_ReadHandle *rh; |
@@ -2222,9 +2233,11 @@ deserialize_unindex_file (void *cls, | |||
2222 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &uc->file_size)) || | 2233 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &uc->file_size)) || |
2223 | (GNUNET_OK != read_start_time (rh, &uc->start_time)) || | 2234 | (GNUNET_OK != read_start_time (rh, &uc->start_time)) || |
2224 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &state)) || | 2235 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &state)) || |
2225 | (GNUNET_OK != GNUNET_BIO_read (rh, "uri", &uc->chk, sizeof (struct ContentHashKey))) || | 2236 | (GNUNET_OK != |
2226 | (GNUNET_OK != GNUNET_BIO_read_string (rh, "unindex-kskuri", &uris, 10 * 1024)) || | 2237 | GNUNET_BIO_read (rh, "uri", &uc->chk, sizeof (struct ContentHashKey))) || |
2227 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &uc->ksk_offset)) ) | 2238 | (GNUNET_OK != |
2239 | GNUNET_BIO_read_string (rh, "unindex-kskuri", &uris, 10 * 1024)) || | ||
2240 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &uc->ksk_offset))) | ||
2228 | { | 2241 | { |
2229 | GNUNET_free_non_null (uris); | 2242 | GNUNET_free_non_null (uris); |
2230 | GNUNET_break (0); | 2243 | GNUNET_break (0); |
@@ -2241,9 +2254,9 @@ deserialize_unindex_file (void *cls, | |||
2241 | goto cleanup; | 2254 | goto cleanup; |
2242 | } | 2255 | } |
2243 | } | 2256 | } |
2244 | if ( (uc->ksk_offset > 0) && | 2257 | if ((uc->ksk_offset > 0) && |
2245 | ( (NULL == uc->ksk_uri) || | 2258 | ((NULL == uc->ksk_uri) || |
2246 | (uc->ksk_offset > uc->ksk_uri->data.ksk.keywordCount) ) ) | 2259 | (uc->ksk_offset > uc->ksk_uri->data.ksk.keywordCount))) |
2247 | { | 2260 | { |
2248 | GNUNET_break (0); | 2261 | GNUNET_break (0); |
2249 | goto cleanup; | 2262 | goto cleanup; |
@@ -2254,9 +2267,10 @@ deserialize_unindex_file (void *cls, | |||
2254 | case UNINDEX_STATE_HASHING: | 2267 | case UNINDEX_STATE_HASHING: |
2255 | break; | 2268 | break; |
2256 | case UNINDEX_STATE_FS_NOTIFY: | 2269 | case UNINDEX_STATE_FS_NOTIFY: |
2257 | if (GNUNET_OK != | 2270 | if (GNUNET_OK != GNUNET_BIO_read (rh, |
2258 | GNUNET_BIO_read (rh, "unindex-hash", &uc->file_id, | 2271 | "unindex-hash", |
2259 | sizeof (struct GNUNET_HashCode))) | 2272 | &uc->file_id, |
2273 | sizeof (struct GNUNET_HashCode))) | ||
2260 | { | 2274 | { |
2261 | GNUNET_break (0); | 2275 | GNUNET_break (0); |
2262 | goto cleanup; | 2276 | goto cleanup; |
@@ -2280,21 +2294,22 @@ deserialize_unindex_file (void *cls, | |||
2280 | GNUNET_break (0); | 2294 | GNUNET_break (0); |
2281 | goto cleanup; | 2295 | goto cleanup; |
2282 | } | 2296 | } |
2283 | uc->top = GNUNET_FS_make_top (h, | 2297 | uc->top = GNUNET_FS_make_top (h, &GNUNET_FS_unindex_signal_suspend_, uc); |
2284 | &GNUNET_FS_unindex_signal_suspend_, | ||
2285 | uc); | ||
2286 | pi.status = GNUNET_FS_STATUS_UNINDEX_RESUME; | 2298 | pi.status = GNUNET_FS_STATUS_UNINDEX_RESUME; |
2287 | pi.value.unindex.specifics.resume.message = uc->emsg; | 2299 | pi.value.unindex.specifics.resume.message = uc->emsg; |
2288 | GNUNET_FS_unindex_make_status_ (&pi, uc, | 2300 | GNUNET_FS_unindex_make_status_ (&pi, |
2289 | (uc->state == | 2301 | uc, |
2290 | UNINDEX_STATE_COMPLETE) ? uc->file_size : 0); | 2302 | (uc->state == UNINDEX_STATE_COMPLETE) |
2303 | ? uc->file_size | ||
2304 | : 0); | ||
2291 | switch (uc->state) | 2305 | switch (uc->state) |
2292 | { | 2306 | { |
2293 | case UNINDEX_STATE_HASHING: | 2307 | case UNINDEX_STATE_HASHING: |
2294 | uc->fhc = | 2308 | uc->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, |
2295 | GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, uc->filename, | 2309 | uc->filename, |
2296 | HASHING_BLOCKSIZE, | 2310 | HASHING_BLOCKSIZE, |
2297 | &GNUNET_FS_unindex_process_hash_, uc); | 2311 | &GNUNET_FS_unindex_process_hash_, |
2312 | uc); | ||
2298 | break; | 2313 | break; |
2299 | case UNINDEX_STATE_FS_NOTIFY: | 2314 | case UNINDEX_STATE_FS_NOTIFY: |
2300 | uc->state = UNINDEX_STATE_HASHING; | 2315 | uc->state = UNINDEX_STATE_HASHING; |
@@ -2319,8 +2334,9 @@ deserialize_unindex_file (void *cls, | |||
2319 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) | 2334 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) |
2320 | { | 2335 | { |
2321 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2336 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2322 | _("Failure while resuming unindexing operation `%s': %s\n"), | 2337 | _ ("Failure while resuming unindexing operation `%s': %s\n"), |
2323 | filename, emsg); | 2338 | filename, |
2339 | emsg); | ||
2324 | GNUNET_free (emsg); | 2340 | GNUNET_free (emsg); |
2325 | } | 2341 | } |
2326 | return GNUNET_OK; | 2342 | return GNUNET_OK; |
@@ -2329,13 +2345,14 @@ cleanup: | |||
2329 | if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))) | 2345 | if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))) |
2330 | { | 2346 | { |
2331 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2347 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2332 | _("Failed to resume unindexing operation `%s': %s\n"), | 2348 | _ ("Failed to resume unindexing operation `%s': %s\n"), |
2333 | filename, | 2349 | filename, |
2334 | emsg); | 2350 | emsg); |
2335 | GNUNET_free (emsg); | 2351 | GNUNET_free (emsg); |
2336 | } | 2352 | } |
2337 | if (NULL != uc->serialization) | 2353 | if (NULL != uc->serialization) |
2338 | GNUNET_FS_remove_sync_file_ (h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, | 2354 | GNUNET_FS_remove_sync_file_ (h, |
2355 | GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, | ||
2339 | uc->serialization); | 2356 | uc->serialization); |
2340 | GNUNET_free_non_null (uc->serialization); | 2357 | GNUNET_free_non_null (uc->serialization); |
2341 | GNUNET_free (uc); | 2358 | GNUNET_free (uc); |
@@ -2384,8 +2401,7 @@ deserialize_search (struct GNUNET_FS_Handle *h, | |||
2384 | * @return #GNUNET_OK (continue to iterate) | 2401 | * @return #GNUNET_OK (continue to iterate) |
2385 | */ | 2402 | */ |
2386 | static int | 2403 | static int |
2387 | deserialize_search_result (void *cls, | 2404 | deserialize_search_result (void *cls, const char *filename) |
2388 | const char *filename) | ||
2389 | { | 2405 | { |
2390 | struct GNUNET_FS_SearchContext *sc = cls; | 2406 | struct GNUNET_FS_SearchContext *sc = cls; |
2391 | char *ser; | 2407 | char *ser; |
@@ -2405,9 +2421,10 @@ deserialize_search_result (void *cls, | |||
2405 | { | 2421 | { |
2406 | remove_sync_file_in_dir (sc->h, | 2422 | remove_sync_file_in_dir (sc->h, |
2407 | (NULL == sc->psearch_result) | 2423 | (NULL == sc->psearch_result) |
2408 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH | 2424 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH |
2409 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, | 2425 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, |
2410 | sc->serialization, ser); | 2426 | sc->serialization, |
2427 | ser); | ||
2411 | GNUNET_free (ser); | 2428 | GNUNET_free (ser); |
2412 | } | 2429 | } |
2413 | return GNUNET_OK; | 2430 | return GNUNET_OK; |
@@ -2420,15 +2437,19 @@ deserialize_search_result (void *cls, | |||
2420 | sr->h = sc->h; | 2437 | sr->h = sc->h; |
2421 | sr->sc = sc; | 2438 | sr->sc = sc; |
2422 | sr->serialization = ser; | 2439 | sr->serialization = ser; |
2423 | if ((GNUNET_OK != GNUNET_BIO_read_string (rh, "result-uri", &uris, 10 * 1024)) | 2440 | if ((GNUNET_OK != |
2424 | || (NULL == (sr->uri = GNUNET_FS_uri_parse (uris, &emsg))) || | 2441 | GNUNET_BIO_read_string (rh, "result-uri", &uris, 10 * 1024)) || |
2425 | (GNUNET_OK != GNUNET_BIO_read_string (rh, "download-lnk", &download, 16)) | 2442 | (NULL == (sr->uri = GNUNET_FS_uri_parse (uris, &emsg))) || |
2426 | || (GNUNET_OK != | ||
2427 | GNUNET_BIO_read_string (rh, "search-lnk", &update_srch, 16)) || | ||
2428 | (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "result-meta", &sr->meta)) || | ||
2429 | (GNUNET_OK != | 2443 | (GNUNET_OK != |
2430 | GNUNET_BIO_read (rh, "result-key", &sr->key, sizeof (struct GNUNET_HashCode))) | 2444 | GNUNET_BIO_read_string (rh, "download-lnk", &download, 16)) || |
2431 | || (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->mandatory_missing)) || | 2445 | (GNUNET_OK != |
2446 | GNUNET_BIO_read_string (rh, "search-lnk", &update_srch, 16)) || | ||
2447 | (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "result-meta", &sr->meta)) || | ||
2448 | (GNUNET_OK != GNUNET_BIO_read (rh, | ||
2449 | "result-key", | ||
2450 | &sr->key, | ||
2451 | sizeof (struct GNUNET_HashCode))) || | ||
2452 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->mandatory_missing)) || | ||
2432 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->optional_support)) || | 2453 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->optional_support)) || |
2433 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->availability_success)) || | 2454 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->availability_success)) || |
2434 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->availability_trials))) | 2455 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->availability_trials))) |
@@ -2438,10 +2459,13 @@ deserialize_search_result (void *cls, | |||
2438 | } | 2459 | } |
2439 | if (GNUNET_FS_URI_KSK == sr->sc->uri->type) | 2460 | if (GNUNET_FS_URI_KSK == sr->sc->uri->type) |
2440 | { | 2461 | { |
2441 | sr->keyword_bitmap = GNUNET_malloc ((sr->sc->uri->data.ksk.keywordCount + 7) / 8); /* round up, count bits */ | 2462 | sr->keyword_bitmap = GNUNET_malloc ( |
2442 | if (GNUNET_OK != GNUNET_BIO_read (rh, "keyword-bitmap", | 2463 | (sr->sc->uri->data.ksk.keywordCount + 7) / 8); /* round up, count bits */ |
2443 | sr->keyword_bitmap, | 2464 | if (GNUNET_OK != |
2444 | (sr->sc->uri->data.ksk.keywordCount + 7) / 8)) | 2465 | GNUNET_BIO_read (rh, |
2466 | "keyword-bitmap", | ||
2467 | sr->keyword_bitmap, | ||
2468 | (sr->sc->uri->data.ksk.keywordCount + 7) / 8)) | ||
2445 | { | 2469 | { |
2446 | GNUNET_break (0); | 2470 | GNUNET_break (0); |
2447 | goto cleanup; | 2471 | goto cleanup; |
@@ -2457,7 +2481,7 @@ deserialize_search_result (void *cls, | |||
2457 | if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg)) | 2481 | if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg)) |
2458 | { | 2482 | { |
2459 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2483 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2460 | _("Failed to resume sub-download `%s': %s\n"), | 2484 | _ ("Failed to resume sub-download `%s': %s\n"), |
2461 | download, | 2485 | download, |
2462 | emsg); | 2486 | emsg); |
2463 | GNUNET_free (emsg); | 2487 | GNUNET_free (emsg); |
@@ -2468,14 +2492,14 @@ deserialize_search_result (void *cls, | |||
2468 | if (NULL != update_srch) | 2492 | if (NULL != update_srch) |
2469 | { | 2493 | { |
2470 | drh = | 2494 | drh = |
2471 | get_read_handle (sc->h, GNUNET_FS_SYNC_PATH_CHILD_SEARCH, update_srch); | 2495 | get_read_handle (sc->h, GNUNET_FS_SYNC_PATH_CHILD_SEARCH, update_srch); |
2472 | if (NULL != drh) | 2496 | if (NULL != drh) |
2473 | { | 2497 | { |
2474 | deserialize_search (sc->h, drh, sr, update_srch); | 2498 | deserialize_search (sc->h, drh, sr, update_srch); |
2475 | if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg)) | 2499 | if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg)) |
2476 | { | 2500 | { |
2477 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2501 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2478 | _("Failed to resume sub-search `%s': %s\n"), | 2502 | _ ("Failed to resume sub-search `%s': %s\n"), |
2479 | update_srch, | 2503 | update_srch, |
2480 | emsg); | 2504 | emsg); |
2481 | GNUNET_free (emsg); | 2505 | GNUNET_free (emsg); |
@@ -2483,15 +2507,17 @@ deserialize_search_result (void *cls, | |||
2483 | } | 2507 | } |
2484 | GNUNET_free (update_srch); | 2508 | GNUNET_free (update_srch); |
2485 | } | 2509 | } |
2486 | GNUNET_break (GNUNET_YES == | 2510 | GNUNET_break (GNUNET_YES == GNUNET_CONTAINER_multihashmap_put ( |
2487 | GNUNET_CONTAINER_multihashmap_put (sc->master_result_map, | 2511 | sc->master_result_map, |
2488 | &sr->key, sr, | 2512 | &sr->key, |
2489 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | 2513 | sr, |
2514 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | ||
2490 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) | 2515 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) |
2491 | { | 2516 | { |
2492 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2517 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2493 | _("Failure while resuming search operation `%s': %s\n"), | 2518 | _ ("Failure while resuming search operation `%s': %s\n"), |
2494 | filename, emsg); | 2519 | filename, |
2520 | emsg); | ||
2495 | GNUNET_free (emsg); | 2521 | GNUNET_free (emsg); |
2496 | } | 2522 | } |
2497 | return GNUNET_OK; | 2523 | return GNUNET_OK; |
@@ -2509,8 +2535,9 @@ cleanup: | |||
2509 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) | 2535 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) |
2510 | { | 2536 | { |
2511 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2537 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2512 | _("Failure while resuming search operation `%s': %s\n"), | 2538 | _ ("Failure while resuming search operation `%s': %s\n"), |
2513 | filename, emsg); | 2539 | filename, |
2540 | emsg); | ||
2514 | GNUNET_free (emsg); | 2541 | GNUNET_free (emsg); |
2515 | } | 2542 | } |
2516 | return GNUNET_OK; | 2543 | return GNUNET_OK; |
@@ -2564,9 +2591,7 @@ signal_search_resume (struct GNUNET_FS_SearchContext *sc); | |||
2564 | * @return #GNUNET_YES (we should continue to iterate) | 2591 | * @return #GNUNET_YES (we should continue to iterate) |
2565 | */ | 2592 | */ |
2566 | static int | 2593 | static int |
2567 | signal_result_resume (void *cls, | 2594 | signal_result_resume (void *cls, const struct GNUNET_HashCode *key, void *value) |
2568 | const struct GNUNET_HashCode *key, | ||
2569 | void *value) | ||
2570 | { | 2595 | { |
2571 | struct GNUNET_FS_SearchContext *sc = cls; | 2596 | struct GNUNET_FS_SearchContext *sc = cls; |
2572 | struct GNUNET_FS_ProgressInfo pi; | 2597 | struct GNUNET_FS_ProgressInfo pi; |
@@ -2579,11 +2604,11 @@ signal_result_resume (void *cls, | |||
2579 | pi.value.search.specifics.resume_result.uri = sr->uri; | 2604 | pi.value.search.specifics.resume_result.uri = sr->uri; |
2580 | pi.value.search.specifics.resume_result.result = sr; | 2605 | pi.value.search.specifics.resume_result.result = sr; |
2581 | pi.value.search.specifics.resume_result.availability_rank = | 2606 | pi.value.search.specifics.resume_result.availability_rank = |
2582 | 2 * sr->availability_success - sr->availability_trials; | 2607 | 2 * sr->availability_success - sr->availability_trials; |
2583 | pi.value.search.specifics.resume_result.availability_certainty = | 2608 | pi.value.search.specifics.resume_result.availability_certainty = |
2584 | sr->availability_trials; | 2609 | sr->availability_trials; |
2585 | pi.value.search.specifics.resume_result.applicability_rank = | 2610 | pi.value.search.specifics.resume_result.applicability_rank = |
2586 | sr->optional_support; | 2611 | sr->optional_support; |
2587 | sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc); | 2612 | sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc); |
2588 | } | 2613 | } |
2589 | if (NULL != sr->download) | 2614 | if (NULL != sr->download) |
@@ -2618,9 +2643,7 @@ free_search_context (struct GNUNET_FS_SearchContext *sc); | |||
2618 | * @return #GNUNET_YES (we should continue to iterate) | 2643 | * @return #GNUNET_YES (we should continue to iterate) |
2619 | */ | 2644 | */ |
2620 | static int | 2645 | static int |
2621 | free_result (void *cls, | 2646 | free_result (void *cls, const struct GNUNET_HashCode *key, void *value) |
2622 | const struct GNUNET_HashCode *key, | ||
2623 | void *value) | ||
2624 | { | 2647 | { |
2625 | struct GNUNET_FS_SearchResult *sr = value; | 2648 | struct GNUNET_FS_SearchResult *sr = value; |
2626 | 2649 | ||
@@ -2647,14 +2670,14 @@ free_search_context (struct GNUNET_FS_SearchContext *sc) | |||
2647 | if (NULL != sc->serialization) | 2670 | if (NULL != sc->serialization) |
2648 | { | 2671 | { |
2649 | GNUNET_FS_remove_sync_file_ (sc->h, | 2672 | GNUNET_FS_remove_sync_file_ (sc->h, |
2650 | (sc->psearch_result == | 2673 | (sc->psearch_result == NULL) |
2651 | NULL) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH : | 2674 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH |
2652 | GNUNET_FS_SYNC_PATH_CHILD_SEARCH, | 2675 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, |
2653 | sc->serialization); | 2676 | sc->serialization); |
2654 | GNUNET_FS_remove_sync_dir_ (sc->h, | 2677 | GNUNET_FS_remove_sync_dir_ (sc->h, |
2655 | (sc->psearch_result == | 2678 | (sc->psearch_result == NULL) |
2656 | NULL) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH : | 2679 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH |
2657 | GNUNET_FS_SYNC_PATH_CHILD_SEARCH, | 2680 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, |
2658 | sc->serialization); | 2681 | sc->serialization); |
2659 | } | 2682 | } |
2660 | GNUNET_free_non_null (sc->serialization); | 2683 | GNUNET_free_non_null (sc->serialization); |
@@ -2663,7 +2686,8 @@ free_search_context (struct GNUNET_FS_SearchContext *sc) | |||
2663 | GNUNET_FS_uri_destroy (sc->uri); | 2686 | GNUNET_FS_uri_destroy (sc->uri); |
2664 | if (NULL != sc->master_result_map) | 2687 | if (NULL != sc->master_result_map) |
2665 | { | 2688 | { |
2666 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, &free_result, | 2689 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, |
2690 | &free_result, | ||
2667 | sc); | 2691 | sc); |
2668 | GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map); | 2692 | GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map); |
2669 | } | 2693 | } |
@@ -2680,8 +2704,7 @@ free_search_context (struct GNUNET_FS_SearchContext *sc) | |||
2680 | * @return #GNUNET_OK (continue to iterate) | 2704 | * @return #GNUNET_OK (continue to iterate) |
2681 | */ | 2705 | */ |
2682 | static int | 2706 | static int |
2683 | deserialize_subdownload (void *cls, | 2707 | deserialize_subdownload (void *cls, const char *filename) |
2684 | const char *filename) | ||
2685 | { | 2708 | { |
2686 | struct GNUNET_FS_DownloadContext *parent = cls; | 2709 | struct GNUNET_FS_DownloadContext *parent = cls; |
2687 | char *ser; | 2710 | char *ser; |
@@ -2693,7 +2716,8 @@ deserialize_subdownload (void *cls, | |||
2693 | if (NULL == rh) | 2716 | if (NULL == rh) |
2694 | { | 2717 | { |
2695 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2718 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2696 | _("Failed to resume sub-download `%s': could not open file `%s'\n"), | 2719 | _ ( |
2720 | "Failed to resume sub-download `%s': could not open file `%s'\n"), | ||
2697 | ser, | 2721 | ser, |
2698 | filename); | 2722 | filename); |
2699 | GNUNET_free (ser); | 2723 | GNUNET_free (ser); |
@@ -2703,7 +2727,7 @@ deserialize_subdownload (void *cls, | |||
2703 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) | 2727 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) |
2704 | { | 2728 | { |
2705 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2729 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2706 | _("Failed to resume sub-download `%s': %s\n"), | 2730 | _ ("Failed to resume sub-download `%s': %s\n"), |
2707 | ser, | 2731 | ser, |
2708 | emsg); | 2732 | emsg); |
2709 | GNUNET_free (emsg); | 2733 | GNUNET_free (emsg); |
@@ -2735,9 +2759,7 @@ free_download_context (struct GNUNET_FS_DownloadContext *dc) | |||
2735 | GNUNET_free_non_null (dc->serialization); | 2759 | GNUNET_free_non_null (dc->serialization); |
2736 | while (NULL != (dcc = dc->child_head)) | 2760 | while (NULL != (dcc = dc->child_head)) |
2737 | { | 2761 | { |
2738 | GNUNET_CONTAINER_DLL_remove (dc->child_head, | 2762 | GNUNET_CONTAINER_DLL_remove (dc->child_head, dc->child_tail, dcc); |
2739 | dc->child_tail, | ||
2740 | dcc); | ||
2741 | free_download_context (dcc); | 2763 | free_download_context (dcc); |
2742 | } | 2764 | } |
2743 | GNUNET_FS_free_download_request_ (dc->top_request); | 2765 | GNUNET_FS_free_download_request_ (dc->top_request); |
@@ -2781,14 +2803,16 @@ deserialize_download (struct GNUNET_FS_Handle *h, | |||
2781 | (NULL == (dc->uri = GNUNET_FS_uri_parse (uris, &emsg))) || | 2803 | (NULL == (dc->uri = GNUNET_FS_uri_parse (uris, &emsg))) || |
2782 | ((GNUNET_YES != GNUNET_FS_uri_test_chk (dc->uri)) && | 2804 | ((GNUNET_YES != GNUNET_FS_uri_test_chk (dc->uri)) && |
2783 | (GNUNET_YES != GNUNET_FS_uri_test_loc (dc->uri))) || | 2805 | (GNUNET_YES != GNUNET_FS_uri_test_loc (dc->uri))) || |
2784 | (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "download-meta", &dc->meta)) | ||
2785 | || (GNUNET_OK != | ||
2786 | GNUNET_BIO_read_string (rh, "download-emsg", &dc->emsg, 10 * 1024)) || | ||
2787 | (GNUNET_OK != | 2806 | (GNUNET_OK != |
2788 | GNUNET_BIO_read_string (rh, "download-fn", &dc->filename, 10 * 1024)) || | 2807 | GNUNET_BIO_read_meta_data (rh, "download-meta", &dc->meta)) || |
2808 | (GNUNET_OK != | ||
2809 | GNUNET_BIO_read_string (rh, "download-emsg", &dc->emsg, 10 * 1024)) || | ||
2789 | (GNUNET_OK != | 2810 | (GNUNET_OK != |
2790 | GNUNET_BIO_read_string (rh, "download-tfn", &dc->temp_filename, | 2811 | GNUNET_BIO_read_string (rh, "download-fn", &dc->filename, 10 * 1024)) || |
2791 | 10 * 1024)) || | 2812 | (GNUNET_OK != GNUNET_BIO_read_string (rh, |
2813 | "download-tfn", | ||
2814 | &dc->temp_filename, | ||
2815 | 10 * 1024)) || | ||
2792 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->old_file_size)) || | 2816 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->old_file_size)) || |
2793 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->offset)) || | 2817 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->offset)) || |
2794 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->length)) || | 2818 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->length)) || |
@@ -2803,14 +2827,14 @@ deserialize_download (struct GNUNET_FS_Handle *h, | |||
2803 | } | 2827 | } |
2804 | dc->options = (enum GNUNET_FS_DownloadOptions) options; | 2828 | dc->options = (enum GNUNET_FS_DownloadOptions) options; |
2805 | dc->active = | 2829 | dc->active = |
2806 | GNUNET_CONTAINER_multihashmap_create (1 + 2 * (dc->length / DBLOCK_SIZE), GNUNET_NO); | 2830 | GNUNET_CONTAINER_multihashmap_create (1 + 2 * (dc->length / DBLOCK_SIZE), |
2831 | GNUNET_NO); | ||
2807 | dc->has_finished = (int) status; | 2832 | dc->has_finished = (int) status; |
2808 | dc->treedepth = | 2833 | dc->treedepth = |
2809 | GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size (dc->uri)); | 2834 | GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size (dc->uri)); |
2810 | if (GNUNET_FS_uri_test_loc (dc->uri)) | 2835 | if (GNUNET_FS_uri_test_loc (dc->uri)) |
2811 | GNUNET_assert (GNUNET_OK == | 2836 | GNUNET_assert (GNUNET_OK == |
2812 | GNUNET_FS_uri_loc_get_peer_identity (dc->uri, | 2837 | GNUNET_FS_uri_loc_get_peer_identity (dc->uri, &dc->target)); |
2813 | &dc->target)); | ||
2814 | if (NULL == dc->emsg) | 2838 | if (NULL == dc->emsg) |
2815 | { | 2839 | { |
2816 | dc->top_request = read_download_request (rh); | 2840 | dc->top_request = read_download_request (rh); |
@@ -2820,43 +2844,31 @@ deserialize_download (struct GNUNET_FS_Handle *h, | |||
2820 | goto cleanup; | 2844 | goto cleanup; |
2821 | } | 2845 | } |
2822 | } | 2846 | } |
2823 | dn = get_download_sync_filename (dc, | 2847 | dn = get_download_sync_filename (dc, dc->serialization, ".dir"); |
2824 | dc->serialization, | ||
2825 | ".dir"); | ||
2826 | if (NULL != dn) | 2848 | if (NULL != dn) |
2827 | { | 2849 | { |
2828 | if (GNUNET_YES == | 2850 | if (GNUNET_YES == GNUNET_DISK_directory_test (dn, GNUNET_YES)) |
2829 | GNUNET_DISK_directory_test (dn, | 2851 | GNUNET_DISK_directory_scan (dn, &deserialize_subdownload, dc); |
2830 | GNUNET_YES)) | ||
2831 | GNUNET_DISK_directory_scan (dn, | ||
2832 | &deserialize_subdownload, | ||
2833 | dc); | ||
2834 | GNUNET_free (dn); | 2852 | GNUNET_free (dn); |
2835 | } | 2853 | } |
2836 | if (NULL != parent) | 2854 | if (NULL != parent) |
2837 | { | 2855 | { |
2838 | GNUNET_CONTAINER_DLL_insert (parent->child_head, | 2856 | GNUNET_CONTAINER_DLL_insert (parent->child_head, parent->child_tail, dc); |
2839 | parent->child_tail, | ||
2840 | dc); | ||
2841 | } | 2857 | } |
2842 | if (NULL != search) | 2858 | if (NULL != search) |
2843 | { | 2859 | { |
2844 | dc->search = search; | 2860 | dc->search = search; |
2845 | search->download = dc; | 2861 | search->download = dc; |
2846 | } | 2862 | } |
2847 | if ( (NULL == parent) && | 2863 | if ((NULL == parent) && (NULL == search)) |
2848 | (NULL == search) ) | ||
2849 | { | 2864 | { |
2850 | dc->top | 2865 | dc->top = |
2851 | = GNUNET_FS_make_top (dc->h, | 2866 | GNUNET_FS_make_top (dc->h, &GNUNET_FS_download_signal_suspend_, dc); |
2852 | &GNUNET_FS_download_signal_suspend_, | ||
2853 | dc); | ||
2854 | signal_download_resume (dc); | 2867 | signal_download_resume (dc); |
2855 | } | 2868 | } |
2856 | GNUNET_free (uris); | 2869 | GNUNET_free (uris); |
2857 | GNUNET_assert (NULL == dc->job_queue); | 2870 | GNUNET_assert (NULL == dc->job_queue); |
2858 | dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, | 2871 | dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, dc); |
2859 | dc); | ||
2860 | return; | 2872 | return; |
2861 | cleanup: | 2873 | cleanup: |
2862 | GNUNET_free_non_null (uris); | 2874 | GNUNET_free_non_null (uris); |
@@ -2879,11 +2891,11 @@ signal_search_resume (struct GNUNET_FS_SearchContext *sc) | |||
2879 | pi.status = GNUNET_FS_STATUS_SEARCH_RESUME; | 2891 | pi.status = GNUNET_FS_STATUS_SEARCH_RESUME; |
2880 | pi.value.search.specifics.resume.message = sc->emsg; | 2892 | pi.value.search.specifics.resume.message = sc->emsg; |
2881 | pi.value.search.specifics.resume.is_paused = | 2893 | pi.value.search.specifics.resume.is_paused = |
2882 | (NULL == sc->mq) ? GNUNET_YES : GNUNET_NO; | 2894 | (NULL == sc->mq) ? GNUNET_YES : GNUNET_NO; |
2883 | sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc); | 2895 | sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc); |
2884 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, | 2896 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, |
2885 | &signal_result_resume, sc); | 2897 | &signal_result_resume, |
2886 | 2898 | sc); | |
2887 | } | 2899 | } |
2888 | 2900 | ||
2889 | 2901 | ||
@@ -2942,10 +2954,11 @@ deserialize_search (struct GNUNET_FS_Handle *h, | |||
2942 | sc->options = (enum GNUNET_FS_SearchOptions) options; | 2954 | sc->options = (enum GNUNET_FS_SearchOptions) options; |
2943 | sc->master_result_map = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_NO); | 2955 | sc->master_result_map = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_NO); |
2944 | dn = get_serialization_file_name_in_dir (h, | 2956 | dn = get_serialization_file_name_in_dir (h, |
2945 | (NULL == sc->psearch_result) ? | 2957 | (NULL == sc->psearch_result) |
2946 | GNUNET_FS_SYNC_PATH_MASTER_SEARCH : | 2958 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH |
2947 | GNUNET_FS_SYNC_PATH_CHILD_SEARCH, | 2959 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, |
2948 | sc->serialization, ""); | 2960 | sc->serialization, |
2961 | ""); | ||
2949 | if (NULL != dn) | 2962 | if (NULL != dn) |
2950 | { | 2963 | { |
2951 | if (GNUNET_YES == GNUNET_DISK_directory_test (dn, GNUNET_YES)) | 2964 | if (GNUNET_YES == GNUNET_DISK_directory_test (dn, GNUNET_YES)) |
@@ -2955,8 +2968,9 @@ deserialize_search (struct GNUNET_FS_Handle *h, | |||
2955 | if (('\0' == in_pause) && | 2968 | if (('\0' == in_pause) && |
2956 | (GNUNET_OK != GNUNET_FS_search_start_searching_ (sc))) | 2969 | (GNUNET_OK != GNUNET_FS_search_start_searching_ (sc))) |
2957 | { | 2970 | { |
2958 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2971 | GNUNET_log ( |
2959 | _("Could not resume running search, will resume as paused search\n")); | 2972 | GNUNET_ERROR_TYPE_WARNING, |
2973 | _ ("Could not resume running search, will resume as paused search\n")); | ||
2960 | } | 2974 | } |
2961 | signal_search_resume (sc); | 2975 | signal_search_resume (sc); |
2962 | GNUNET_free (uris); | 2976 | GNUNET_free (uris); |
@@ -2978,8 +2992,7 @@ cleanup: | |||
2978 | * @return #GNUNET_OK (continue to iterate) | 2992 | * @return #GNUNET_OK (continue to iterate) |
2979 | */ | 2993 | */ |
2980 | static int | 2994 | static int |
2981 | deserialize_search_file (void *cls, | 2995 | deserialize_search_file (void *cls, const char *filename) |
2982 | const char *filename) | ||
2983 | { | 2996 | { |
2984 | struct GNUNET_FS_Handle *h = cls; | 2997 | struct GNUNET_FS_Handle *h = cls; |
2985 | char *ser; | 2998 | char *ser; |
@@ -2988,7 +3001,7 @@ deserialize_search_file (void *cls, | |||
2988 | struct GNUNET_FS_SearchContext *sc; | 3001 | struct GNUNET_FS_SearchContext *sc; |
2989 | struct stat buf; | 3002 | struct stat buf; |
2990 | 3003 | ||
2991 | if (0 != STAT (filename, &buf)) | 3004 | if (0 != stat (filename, &buf)) |
2992 | { | 3005 | { |
2993 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename); | 3006 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename); |
2994 | return GNUNET_OK; | 3007 | return GNUNET_OK; |
@@ -3013,8 +3026,9 @@ deserialize_search_file (void *cls, | |||
3013 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) | 3026 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) |
3014 | { | 3027 | { |
3015 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3028 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3016 | _("Failure while resuming search operation `%s': %s\n"), | 3029 | _ ("Failure while resuming search operation `%s': %s\n"), |
3017 | filename, emsg); | 3030 | filename, |
3031 | emsg); | ||
3018 | GNUNET_free (emsg); | 3032 | GNUNET_free (emsg); |
3019 | } | 3033 | } |
3020 | return GNUNET_OK; | 3034 | return GNUNET_OK; |
@@ -3041,7 +3055,7 @@ deserialize_download_file (void *cls, const char *filename) | |||
3041 | rh = GNUNET_BIO_read_open (filename); | 3055 | rh = GNUNET_BIO_read_open (filename); |
3042 | if (NULL == rh) | 3056 | if (NULL == rh) |
3043 | { | 3057 | { |
3044 | if (0 != UNLINK (filename)) | 3058 | if (0 != unlink (filename)) |
3045 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); | 3059 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); |
3046 | GNUNET_free (ser); | 3060 | GNUNET_free (ser); |
3047 | return GNUNET_OK; | 3061 | return GNUNET_OK; |
@@ -3051,8 +3065,9 @@ deserialize_download_file (void *cls, const char *filename) | |||
3051 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) | 3065 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) |
3052 | { | 3066 | { |
3053 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3067 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3054 | _("Failure while resuming download operation `%s': %s\n"), | 3068 | _ ("Failure while resuming download operation `%s': %s\n"), |
3055 | filename, emsg); | 3069 | filename, |
3070 | emsg); | ||
3056 | GNUNET_free (emsg); | 3071 | GNUNET_free (emsg); |
3057 | } | 3072 | } |
3058 | return GNUNET_OK; | 3073 | return GNUNET_OK; |
@@ -3068,7 +3083,7 @@ deserialize_download_file (void *cls, const char *filename) | |||
3068 | */ | 3083 | */ |
3069 | static void | 3084 | static void |
3070 | deserialization_master (const char *master_path, | 3085 | deserialization_master (const char *master_path, |
3071 | GNUNET_FileNameCallback proc, | 3086 | GNUNET_FileNameCallback proc, |
3072 | struct GNUNET_FS_Handle *h) | 3087 | struct GNUNET_FS_Handle *h) |
3073 | { | 3088 | { |
3074 | char *dn; | 3089 | char *dn; |
@@ -3098,7 +3113,8 @@ GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
3098 | const char *client_name, | 3113 | const char *client_name, |
3099 | GNUNET_FS_ProgressCallback upcb, | 3114 | GNUNET_FS_ProgressCallback upcb, |
3100 | void *upcb_cls, | 3115 | void *upcb_cls, |
3101 | enum GNUNET_FS_Flags flags, ...) | 3116 | enum GNUNET_FS_Flags flags, |
3117 | ...) | ||
3102 | { | 3118 | { |
3103 | struct GNUNET_FS_Handle *ret; | 3119 | struct GNUNET_FS_Handle *ret; |
3104 | enum GNUNET_FS_OPTIONS opt; | 3120 | enum GNUNET_FS_OPTIONS opt; |
@@ -3112,9 +3128,11 @@ GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
3112 | ret->flags = flags; | 3128 | ret->flags = flags; |
3113 | ret->max_parallel_downloads = DEFAULT_MAX_PARALLEL_DOWNLOADS; | 3129 | ret->max_parallel_downloads = DEFAULT_MAX_PARALLEL_DOWNLOADS; |
3114 | ret->max_parallel_requests = DEFAULT_MAX_PARALLEL_REQUESTS; | 3130 | ret->max_parallel_requests = DEFAULT_MAX_PARALLEL_REQUESTS; |
3115 | ret->avg_block_latency = GNUNET_TIME_UNIT_MINUTES; /* conservative starting point */ | 3131 | ret->avg_block_latency = |
3132 | GNUNET_TIME_UNIT_MINUTES; /* conservative starting point */ | ||
3116 | va_start (ap, flags); | 3133 | va_start (ap, flags); |
3117 | while (GNUNET_FS_OPTIONS_END != (opt = GNUNET_VA_ARG_ENUM (ap,GNUNET_FS_OPTIONS))) | 3134 | while (GNUNET_FS_OPTIONS_END != |
3135 | (opt = GNUNET_VA_ARG_ENUM (ap, GNUNET_FS_OPTIONS))) | ||
3118 | { | 3136 | { |
3119 | switch (opt) | 3137 | switch (opt) |
3120 | { | 3138 | { |
@@ -3138,13 +3156,17 @@ GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
3138 | if (0 != (GNUNET_FS_FLAGS_PERSISTENCE & flags)) | 3156 | if (0 != (GNUNET_FS_FLAGS_PERSISTENCE & flags)) |
3139 | { | 3157 | { |
3140 | deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, | 3158 | deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, |
3141 | &deserialize_publish_file, ret); | 3159 | &deserialize_publish_file, |
3160 | ret); | ||
3142 | deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_SEARCH, | 3161 | deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_SEARCH, |
3143 | &deserialize_search_file, ret); | 3162 | &deserialize_search_file, |
3163 | ret); | ||
3144 | deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, | 3164 | deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, |
3145 | &deserialize_download_file, ret); | 3165 | &deserialize_download_file, |
3166 | ret); | ||
3146 | deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, | 3167 | deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, |
3147 | &deserialize_unindex_file, ret); | 3168 | &deserialize_unindex_file, |
3169 | ret); | ||
3148 | } | 3170 | } |
3149 | return ret; | 3171 | return ret; |
3150 | } | 3172 | } |