2 This file is part of GNUnet.
3 (C) 2001, 2002, 2003, 2004, 2005, 2006, 2008, 2009, 2010 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
23 * @brief main FS functions (master initialization, serialization, deserialization, shared code)
24 * @author Christian Grothoff
28 #include "gnunet_util_lib.h"
29 #include "gnunet_fs_service.h"
35 * Start the given job (send signal, remove from pending queue, update
36 * counters and state).
38 * @param qe job to start
41 start_job (struct GNUNET_FS_QueueEntry *qe)
43 qe->client = GNUNET_CLIENT_connect (qe->h->sched, "fs", qe->h->cfg);
44 if (qe->client == NULL)
49 qe->start (qe->cls, qe->client);
51 qe->h->active_blocks += qe->blocks;
52 qe->start_time = GNUNET_TIME_absolute_get ();
53 GNUNET_CONTAINER_DLL_remove (qe->h->pending_head,
56 GNUNET_CONTAINER_DLL_insert_after (qe->h->running_head,
64 * Stop the given job (send signal, remove from active queue, update
65 * counters and state).
67 * @param qe job to stop
70 stop_job (struct GNUNET_FS_QueueEntry *qe)
74 qe->h->active_downloads--;
75 qe->h->active_blocks -= qe->blocks;
76 qe->run_time = GNUNET_TIME_relative_add (qe->run_time,
77 GNUNET_TIME_absolute_get_duration (qe->start_time));
78 GNUNET_CONTAINER_DLL_remove (qe->h->running_head,
81 GNUNET_CONTAINER_DLL_insert_after (qe->h->pending_head,
89 * Process the jobs in the job queue, possibly starting some
90 * and stopping others.
92 * @param cls the 'struct GNUNET_FS_Handle'
93 * @param tc scheduler context
96 process_job_queue (void *cls,
97 const struct GNUNET_SCHEDULER_TaskContext *tc)
99 struct GNUNET_FS_Handle *h = cls;
100 struct GNUNET_FS_QueueEntry *qe;
101 struct GNUNET_FS_QueueEntry *next;
102 struct GNUNET_TIME_Relative run_time;
103 struct GNUNET_TIME_Relative restart_at;
104 struct GNUNET_TIME_Relative rst;
105 struct GNUNET_TIME_Absolute end_time;
107 h->queue_job = GNUNET_SCHEDULER_NO_TASK;
108 next = h->pending_head;
109 while (NULL != (qe = next))
112 if (h->running_head == NULL)
117 if ( (qe->blocks + h->active_blocks <= h->max_parallel_requests) &&
118 (h->active_downloads + 1 <= h->max_parallel_downloads) )
124 if (h->pending_head == NULL)
125 return; /* no need to stop anything */
126 restart_at = GNUNET_TIME_UNIT_FOREVER_REL;
127 next = h->running_head;
128 while (NULL != (qe = next))
131 run_time = GNUNET_TIME_relative_multiply (h->avg_block_latency,
132 qe->blocks * qe->start_times);
133 end_time = GNUNET_TIME_absolute_add (qe->start_time,
135 rst = GNUNET_TIME_absolute_get_remaining (end_time);
136 restart_at = GNUNET_TIME_relative_min (rst, restart_at);
141 h->queue_job = GNUNET_SCHEDULER_add_delayed (h->sched,
149 * Add a job to the queue.
151 * @param h handle to the overall FS state
152 * @param start function to call to begin the job
153 * @param stop function to call to pause the job, or on dequeue (if the job was running)
154 * @param cls closure for start and stop
155 * @param blocks number of blocks this jobs uses
156 * @return queue handle
158 struct GNUNET_FS_QueueEntry *
159 GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h,
160 GNUNET_FS_QueueStart start,
161 GNUNET_FS_QueueStop stop,
165 struct GNUNET_FS_QueueEntry *qe;
167 qe = GNUNET_malloc (sizeof (struct GNUNET_FS_QueueEntry));
172 qe->queue_time = GNUNET_TIME_absolute_get ();
174 GNUNET_CONTAINER_DLL_insert_after (h->pending_head,
178 if (h->queue_job != GNUNET_SCHEDULER_NO_TASK)
179 GNUNET_SCHEDULER_cancel (h->sched,
182 = GNUNET_SCHEDULER_add_now (h->sched,
190 * Dequeue a job from the queue.
191 * @param qh handle for the job
194 GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qh)
196 struct GNUNET_FS_Handle *h;
199 if (qh->client != NULL)
201 GNUNET_CONTAINER_DLL_remove (h->pending_head,
205 if (h->queue_job != GNUNET_SCHEDULER_NO_TASK)
206 GNUNET_SCHEDULER_cancel (h->sched,
209 = GNUNET_SCHEDULER_add_now (h->sched,
216 * Create a top-level activity entry.
218 * @param h global fs handle
219 * @param ssf suspend signal function to use
220 * @param ssf_cls closure for ssf
221 * @return fresh top-level activity handle
223 struct TopLevelActivity *
224 GNUNET_FS_make_top (struct GNUNET_FS_Handle *h,
225 SuspendSignalFunction ssf,
228 struct TopLevelActivity *ret;
230 ret = GNUNET_malloc (sizeof (struct TopLevelActivity));
232 ret->ssf_cls = ssf_cls;
233 GNUNET_CONTAINER_DLL_insert (h->top_head,
241 * Destroy a top-level activity entry.
243 * @param h global fs handle
244 * @param top top level activity entry
247 GNUNET_FS_end_top (struct GNUNET_FS_Handle *h,
248 struct TopLevelActivity *top)
250 GNUNET_CONTAINER_DLL_remove (h->top_head,
259 * Closure for "data_reader_file".
264 * Name of the file to read.
269 * File descriptor, NULL if it has not yet been opened.
271 struct GNUNET_DISK_FileHandle *fd;
276 * Function that provides data by reading from a file.
278 * @param cls closure (points to the file information)
279 * @param offset offset to read from; it is possible
280 * that the caller might need to go backwards
282 * @param max maximum number of bytes that should be
283 * copied to buf; readers are not allowed
284 * to provide less data unless there is an error;
285 * a value of "0" will be used at the end to allow
286 * the reader to clean up its internal state
287 * @param buf where the reader should write the data
288 * @param emsg location for the reader to store an error message
289 * @return number of bytes written, usually "max", 0 on error
292 GNUNET_FS_data_reader_file_(void *cls,
298 struct FileInfo *fi = cls;
304 GNUNET_DISK_file_close (fi->fd);
305 GNUNET_free (fi->filename);
311 fi->fd = GNUNET_DISK_file_open (fi->filename,
312 GNUNET_DISK_OPEN_READ,
313 GNUNET_DISK_PERM_NONE);
316 GNUNET_asprintf (emsg,
317 _("Could not open file `%s': %s"),
323 GNUNET_DISK_file_seek (fi->fd, offset, GNUNET_DISK_SEEK_SET);
324 ret = GNUNET_DISK_file_read (fi->fd, buf, max);
327 GNUNET_asprintf (emsg,
328 _("Could not read file `%s': %s"),
335 GNUNET_asprintf (emsg,
336 _("Short read reading from file `%s'!"),
345 * Create the closure for the 'GNUNET_FS_data_reader_file_' callback.
347 * @param filename file to read
348 * @return closure to use, NULL on error
351 GNUNET_FS_make_file_reader_context_ (const char *filename)
355 fi = GNUNET_malloc (sizeof(struct FileInfo));
356 fi->filename = GNUNET_STRINGS_filename_expand (filename);
357 if (fi->filename == NULL)
367 * Function that provides data by copying from a buffer.
369 * @param cls closure (points to the buffer)
370 * @param offset offset to read from; it is possible
371 * that the caller might need to go backwards
373 * @param max maximum number of bytes that should be
374 * copied to buf; readers are not allowed
375 * to provide less data unless there is an error;
376 * a value of "0" will be used at the end to allow
377 * the reader to clean up its internal state
378 * @param buf where the reader should write the data
379 * @param emsg location for the reader to store an error message
380 * @return number of bytes written, usually "max", 0 on error
383 GNUNET_FS_data_reader_copy_ (void *cls,
393 GNUNET_free_non_null (data);
396 memcpy (buf, &data[offset], max);
402 * Return the full filename where we would store state information
403 * (for serialization/deserialization).
405 * @param h master context
406 * @param ext component of the path
407 * @param ent entity identifier (or emtpy string for the directory)
408 * @return NULL on error
411 get_serialization_file_name (struct GNUNET_FS_Handle *h,
418 if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
419 return NULL; /* persistence not requested */
421 GNUNET_CONFIGURATION_get_value_filename (h->cfg,
426 GNUNET_asprintf (&ret,
435 GNUNET_free (basename);
441 * Return the full filename where we would store state information
442 * (for serialization/deserialization) that is associated with a
445 * @param h master context
446 * @param ext component of the path
447 * @param uni name of the parent operation
448 * @param ent entity identifier (or emtpy string for the directory)
449 * @return NULL on error
452 get_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h,
460 if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
461 return NULL; /* persistence not requested */
463 GNUNET_CONFIGURATION_get_value_filename (h->cfg,
468 GNUNET_asprintf (&ret,
469 "%s%s%s%s%s%s%s%s%s",
479 GNUNET_free (basename);
485 * Return a read handle for deserialization.
487 * @param h master context
488 * @param ext component of the path
489 * @param ent entity identifier (or emtpy string for the directory)
490 * @return NULL on error
492 static struct GNUNET_BIO_ReadHandle *
493 get_read_handle (struct GNUNET_FS_Handle *h,
498 struct GNUNET_BIO_ReadHandle *ret;
500 fn = get_serialization_file_name (h, ext, ent);
503 ret = GNUNET_BIO_read_open (fn);
510 * Return a write handle for serialization.
512 * @param h master context
513 * @param ext component of the path
514 * @param ent entity identifier (or emtpy string for the directory)
515 * @return NULL on error
517 static struct GNUNET_BIO_WriteHandle *
518 get_write_handle (struct GNUNET_FS_Handle *h,
523 struct GNUNET_BIO_WriteHandle *ret;
525 fn = get_serialization_file_name (h, ext, ent);
530 ret = GNUNET_BIO_write_open (fn);
533 "Failed to create write handle for `%s' from `%s/%s'\n",
541 * Return a write handle for serialization.
543 * @param h master context
544 * @param ext component of the path
545 * @param uni name of parent
546 * @param ent entity identifier (or emtpy string for the directory)
547 * @return NULL on error
549 static struct GNUNET_BIO_WriteHandle *
550 get_write_handle_in_dir (struct GNUNET_FS_Handle *h,
556 struct GNUNET_BIO_WriteHandle *ret;
558 fn = get_serialization_file_name_in_dir (h, ext, uni, ent);
561 ret = GNUNET_BIO_write_open (fn);
568 * Remove serialization/deserialization file from disk.
570 * @param h master context
571 * @param ext component of the path
572 * @param ent entity identifier
575 GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h,
581 if ( (NULL == ent) ||
582 (0 == strlen (ent)) )
587 filename = get_serialization_file_name (h, ext, ent);
588 if (0 != UNLINK (filename))
589 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
592 GNUNET_free (filename);
597 * Remove serialization/deserialization file from disk.
599 * @param h master context
600 * @param ext component of the path
601 * @param uni parent name
602 * @param ent entity identifier
605 remove_sync_file_in_dir (struct GNUNET_FS_Handle *h,
612 if ( (NULL == ent) ||
613 (0 == strlen (ent)) )
618 filename = get_serialization_file_name_in_dir (h, ext, uni, ent);
619 if (0 != UNLINK (filename))
620 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
623 GNUNET_free (filename);
628 * Remove serialization/deserialization directory from disk.
630 * @param h master context
631 * @param ext component of the path
632 * @param uni unique name of parent
635 GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h,
643 dn = get_serialization_file_name_in_dir (h, ext, uni, "");
646 if ( (GNUNET_OK == GNUNET_DISK_directory_test (dn)) &&
647 (GNUNET_OK != GNUNET_DISK_directory_remove (dn)) )
648 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
656 * Serialize a 'start_time'. Since we use start-times to
657 * calculate the duration of some operation, we actually
658 * do not serialize the absolute time but the (relative)
659 * duration since the start time. When we then
660 * deserialize the start time, we take the current time and
661 * subtract that duration so that we get again an absolute
662 * time stamp that will result in correct performance
665 * @param wh handle for writing
666 * @param timestamp time to serialize
667 * @return GNUNET_OK on success
670 write_start_time (struct GNUNET_BIO_WriteHandle *wh,
671 struct GNUNET_TIME_Absolute timestamp)
673 struct GNUNET_TIME_Relative dur;
675 dur = GNUNET_TIME_absolute_get_duration (timestamp);
676 return GNUNET_BIO_write_int64 (wh, dur.value);
681 * Serialize a 'start_time'. Since we use start-times to
682 * calculate the duration of some operation, we actually
683 * do not serialize the absolute time but the (relative)
684 * duration since the start time. When we then
685 * deserialize the start time, we take the current time and
686 * subtract that duration so that we get again an absolute
687 * time stamp that will result in correct performance
690 * @param rh handle for reading
691 * @param timestamp where to write the deserialized timestamp
692 * @return GNUNET_OK on success
695 read_start_time (struct GNUNET_BIO_ReadHandle *rh,
696 struct GNUNET_TIME_Absolute *timestamp)
698 struct GNUNET_TIME_Relative dur;
700 GNUNET_BIO_read_int64 (rh, &dur.value))
701 return GNUNET_SYSERR;
702 *timestamp = GNUNET_TIME_absolute_subtract (GNUNET_TIME_absolute_get (),
709 * Using the given serialization filename, try to deserialize
710 * the file-information tree associated with it.
712 * @param h master context
713 * @param filename name of the file (without directory) with
715 * @return NULL on error
717 static struct GNUNET_FS_FileInformation *
718 deserialize_file_information (struct GNUNET_FS_Handle *h,
719 const char *filename);
723 * Using the given serialization filename, try to deserialize
724 * the file-information tree associated with it.
726 * @param h master context
727 * @param fn name of the file (without directory) with
729 * @param rh handle for reading
730 * @return NULL on error
732 static struct GNUNET_FS_FileInformation *
733 deserialize_fi_node (struct GNUNET_FS_Handle *h,
735 struct GNUNET_BIO_ReadHandle *rh)
737 struct GNUNET_FS_FileInformation *ret;
738 struct GNUNET_FS_FileInformation *nxt;
746 GNUNET_BIO_read (rh, "status flag", &b, sizeof(b)))
751 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_FileInformation));
757 GNUNET_BIO_read_meta_data (rh, "metadata", &ret->meta)) ||
759 GNUNET_BIO_read_string (rh, "ksk-uri", &ksks, 32*1024)) ||
762 (ret->keywords = GNUNET_FS_uri_parse (ksks, NULL))) ) ||
764 GNUNET_FS_uri_test_ksk (ret->keywords)) ||
766 GNUNET_BIO_read_string (rh, "chk-uri", &chks, 1024)) ||
769 (ret->chk_uri = GNUNET_FS_uri_parse (chks, NULL))) ||
771 GNUNET_FS_uri_test_chk (ret->chk_uri)) ) ) ||
773 GNUNET_BIO_read_int64 (rh, &ret->expirationTime.value)) ||
775 read_start_time (rh, &ret->start_time)) ||
777 GNUNET_BIO_read_string (rh, "emsg", &ret->emsg, 16*1024)) ||
779 GNUNET_BIO_read_string (rh, "fn", &ret->filename, 16*1024)) ||
781 GNUNET_BIO_read_int32 (rh, &ret->anonymity)) ||
783 GNUNET_BIO_read_int32 (rh, &ret->priority)) )
790 case 0: /* file-insert */
792 GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size))
797 ret->is_directory = GNUNET_NO;
798 ret->data.file.do_index = GNUNET_NO;
799 ret->data.file.have_hash = GNUNET_NO;
800 ret->data.file.index_start_confirmed = GNUNET_NO;
801 if (GNUNET_NO == ret->is_published)
803 if (NULL == ret->filename)
805 ret->data.file.reader = &GNUNET_FS_data_reader_copy_;
806 ret->data.file.reader_cls = GNUNET_malloc_large (ret->data.file.file_size);
807 if (ret->data.file.reader_cls == NULL)
810 GNUNET_BIO_read (rh, "file-data", ret->data.file.reader_cls, ret->data.file.file_size))
818 ret->data.file.reader = &GNUNET_FS_data_reader_file_;
819 ret->data.file.reader_cls = GNUNET_FS_make_file_reader_context_ (ret->filename);
823 case 1: /* file-index, no hash */
824 if (NULL == ret->filename)
830 GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size))
835 ret->is_directory = GNUNET_NO;
836 ret->data.file.do_index = GNUNET_YES;
837 ret->data.file.have_hash = GNUNET_NO;
838 ret->data.file.index_start_confirmed = GNUNET_NO;
839 ret->data.file.reader = &GNUNET_FS_data_reader_file_;
840 ret->data.file.reader_cls = GNUNET_FS_make_file_reader_context_ (ret->filename);
842 case 2: /* file-index-with-hash */
843 if (NULL == ret->filename)
849 GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) ||
851 GNUNET_BIO_read (rh, "fileid", &ret->data.file.file_id, sizeof (GNUNET_HashCode))) )
856 ret->is_directory = GNUNET_NO;
857 ret->data.file.do_index = GNUNET_YES;
858 ret->data.file.have_hash = GNUNET_YES;
859 ret->data.file.index_start_confirmed = GNUNET_NO;
860 ret->data.file.reader = &GNUNET_FS_data_reader_file_;
861 ret->data.file.reader_cls = GNUNET_FS_make_file_reader_context_ (ret->filename);
863 case 3: /* file-index-with-hash-confirmed */
864 if (NULL == ret->filename)
870 GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) ||
872 GNUNET_BIO_read (rh, "fileid", &ret->data.file.file_id, sizeof (GNUNET_HashCode))) )
877 ret->is_directory = GNUNET_NO;
878 ret->data.file.do_index = GNUNET_YES;
879 ret->data.file.have_hash = GNUNET_YES;
880 ret->data.file.index_start_confirmed = GNUNET_YES;
881 ret->data.file.reader = &GNUNET_FS_data_reader_file_;
882 ret->data.file.reader_cls = GNUNET_FS_make_file_reader_context_ (ret->filename);
884 case 4: /* directory */
886 GNUNET_BIO_read_int32 (rh, &dsize)) ||
887 (NULL == (ret->data.dir.dir_data = GNUNET_malloc_large (dsize))) ||
889 GNUNET_BIO_read (rh, "dir-data", ret->data.dir.dir_data, dsize)) ||
891 GNUNET_BIO_read_string (rh, "ent-filename", &filename, 16*1024)) )
896 ret->data.dir.dir_size = (uint32_t) dsize;
897 ret->is_directory = GNUNET_YES;
898 if (filename != NULL)
900 ret->data.dir.entries = deserialize_file_information (h, filename);
901 GNUNET_free (filename);
903 nxt = ret->data.dir.entries;
915 ret->serialization = GNUNET_strdup (fn);
917 GNUNET_BIO_read_string (rh, "nxt-filename", &filename, 16*1024))
922 if (filename != NULL)
924 ret->next = deserialize_file_information (h, filename);
925 GNUNET_free (filename);
928 GNUNET_free_non_null (ksks);
929 GNUNET_free_non_null (chks);
932 GNUNET_free_non_null (ksks);
933 GNUNET_free_non_null (chks);
934 GNUNET_free_non_null (filename);
935 GNUNET_FS_file_information_destroy (ret, NULL, NULL);
941 * Using the given serialization filename, try to deserialize
942 * the file-information tree associated with it.
944 * @param h master context
945 * @param filename name of the file (without directory) with
947 * @return NULL on error
949 static struct GNUNET_FS_FileInformation *
950 deserialize_file_information (struct GNUNET_FS_Handle *h,
951 const char *filename)
953 struct GNUNET_FS_FileInformation *ret;
954 struct GNUNET_BIO_ReadHandle *rh;
957 rh = get_read_handle (h, GNUNET_FS_SYNC_PATH_FILE_INFO, filename);
960 ret = deserialize_fi_node (h, filename, rh);
962 GNUNET_BIO_read_close (rh, &emsg))
964 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
965 _("Failed to resume publishing information `%s': %s\n"),
975 * Given a serialization name (full absolute path), return the
976 * basename of the file (without the path), which must only
977 * consist of the 6 random characters.
979 * @param fullname name to extract the basename from
980 * @return copy of the basename, NULL on error
983 get_serialization_short_name (const char *fullname)
990 /* FIXME: we could do this faster since we know
991 the length of 'end'... */
994 if (DIR_SEPARATOR == *nxt)
998 if ( (end == NULL) ||
999 (strlen (end) == 0) )
1004 GNUNET_break (6 == strlen (end));
1005 return GNUNET_strdup (end);
1010 * Create a new random name for serialization. Also checks if persistence
1011 * is enabled and returns NULL if not.
1013 * @param h master context
1014 * @param ext component of the path
1015 * @return NULL on errror
1018 make_serialization_file_name (struct GNUNET_FS_Handle *h,
1025 if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
1026 return NULL; /* persistence not requested */
1027 dn = get_serialization_file_name (h, ext, "");
1029 GNUNET_DISK_directory_create_for_file (dn))
1034 fn = GNUNET_DISK_mktemp (dn);
1037 return NULL; /* epic fail */
1038 ret = get_serialization_short_name (fn);
1045 * Create a new random name for serialization. Also checks if persistence
1046 * is enabled and returns NULL if not.
1048 * @param h master context
1049 * @param ext component of the path
1050 * @param uni name of parent
1051 * @return NULL on errror
1054 make_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h,
1062 if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
1063 return NULL; /* persistence not requested */
1064 dn = get_serialization_file_name_in_dir (h, ext, uni, "");
1066 GNUNET_DISK_directory_create_for_file (dn))
1071 fn = GNUNET_DISK_mktemp (dn);
1074 return NULL; /* epic fail */
1075 ret = get_serialization_short_name (fn);
1082 * Copy all of the data from the reader to the write handle.
1084 * @param wh write handle
1085 * @param fi file with reader
1086 * @return GNUNET_OK on success
1089 copy_from_reader (struct GNUNET_BIO_WriteHandle *wh,
1090 struct GNUNET_FS_FileInformation * fi)
1092 char buf[32 * 1024];
1099 while (off < fi->data.file.file_size)
1101 ret = fi->data.file.reader (fi->data.file.reader_cls,
1108 return GNUNET_SYSERR;
1111 GNUNET_BIO_write (wh, buf, ret))
1112 return GNUNET_SYSERR;
1120 * Create a temporary file on disk to store the current
1123 * @param fi file information to sync with disk
1126 GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation * fi)
1129 struct GNUNET_BIO_WriteHandle *wh;
1134 if (NULL == fi->serialization)
1135 fi->serialization = make_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO);
1136 if (NULL == fi->serialization)
1138 wh = get_write_handle (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO, fi->serialization);
1141 GNUNET_free (fi->serialization);
1142 fi->serialization = NULL;
1145 if (GNUNET_YES == fi->is_directory)
1147 else if (GNUNET_YES == fi->data.file.index_start_confirmed)
1149 else if (GNUNET_YES == fi->data.file.have_hash)
1151 else if (GNUNET_YES == fi->data.file.do_index)
1155 if (fi->keywords != NULL)
1156 ksks = GNUNET_FS_uri_to_string (fi->keywords);
1159 if (fi->chk_uri != NULL)
1160 chks = GNUNET_FS_uri_to_string (fi->chk_uri);
1164 GNUNET_BIO_write (wh, &b, sizeof (b))) ||
1166 GNUNET_BIO_write_meta_data (wh, fi->meta)) ||
1168 GNUNET_BIO_write_string (wh, ksks)) ||
1170 GNUNET_BIO_write_string (wh, chks)) ||
1172 GNUNET_BIO_write_int64 (wh, fi->expirationTime.value)) ||
1174 write_start_time (wh, fi->start_time)) ||
1176 GNUNET_BIO_write_string (wh, fi->emsg)) ||
1178 GNUNET_BIO_write_string (wh, fi->filename)) ||
1180 GNUNET_BIO_write_int32 (wh, fi->anonymity)) ||
1182 GNUNET_BIO_write_int32 (wh, fi->priority)) )
1187 GNUNET_free_non_null (chks);
1189 GNUNET_free_non_null (ksks);
1194 case 0: /* file-insert */
1196 GNUNET_BIO_write_int64 (wh, fi->data.file.file_size))
1201 if ( (GNUNET_NO == fi->is_published) &&
1202 (NULL == fi->filename) )
1204 copy_from_reader (wh, fi))
1210 case 1: /* file-index, no hash */
1211 if (NULL == fi->filename)
1217 GNUNET_BIO_write_int64 (wh, fi->data.file.file_size))
1223 case 2: /* file-index-with-hash */
1224 case 3: /* file-index-with-hash-confirmed */
1225 if (NULL == fi->filename)
1231 GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) ||
1233 GNUNET_BIO_write (wh, &fi->data.file.file_id, sizeof (GNUNET_HashCode))) )
1239 case 4: /* directory */
1241 GNUNET_BIO_write_int32 (wh, fi->data.dir.dir_size)) ||
1243 GNUNET_BIO_write (wh, fi->data.dir.dir_data, (uint32_t) fi->data.dir.dir_size)) ||
1245 GNUNET_BIO_write_string (wh, fi->data.dir.entries->serialization)) )
1256 GNUNET_BIO_write_string (wh, (fi->next != NULL) ? fi->next->serialization : NULL))
1262 GNUNET_BIO_write_close (wh))
1269 (void) GNUNET_BIO_write_close (wh);
1270 GNUNET_free_non_null (chks);
1271 GNUNET_free_non_null (ksks);
1272 fn = get_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO, fi->serialization);
1273 if (0 != UNLINK (fn))
1274 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
1276 GNUNET_free (fi->serialization);
1277 fi->serialization = NULL;
1283 * Find the entry in the file information struct where the
1284 * serialization filename matches the given name.
1286 * @param pos file information to search
1287 * @param srch filename to search for
1288 * @return NULL if srch was not found in this subtree
1290 static struct GNUNET_FS_FileInformation *
1291 find_file_position (struct GNUNET_FS_FileInformation *pos,
1294 struct GNUNET_FS_FileInformation *r;
1298 if (0 == strcmp (srch,
1299 pos->serialization))
1301 if (pos->is_directory)
1303 r = find_file_position (pos->data.dir.entries,
1315 * Signal the FS's progress function that we are resuming
1318 * @param cls closure (of type "struct GNUNET_FS_PublishContext*")
1319 * @param fi the entry in the publish-structure
1320 * @param length length of the file or directory
1321 * @param meta metadata for the file or directory (can be modified)
1322 * @param uri pointer to the keywords that will be used for this entry (can be modified)
1323 * @param anonymity pointer to selected anonymity level (can be modified)
1324 * @param priority pointer to selected priority (can be modified)
1325 * @param expirationTime pointer to selected expiration time (can be modified)
1326 * @param client_info pointer to client context set upon creation (can be modified)
1327 * @return GNUNET_OK to continue (always)
1330 fip_signal_resume(void *cls,
1331 struct GNUNET_FS_FileInformation *fi,
1333 struct GNUNET_CONTAINER_MetaData *meta,
1334 struct GNUNET_FS_Uri **uri,
1335 uint32_t *anonymity,
1337 struct GNUNET_TIME_Absolute *expirationTime,
1340 struct GNUNET_FS_PublishContext *sc = cls;
1341 struct GNUNET_FS_ProgressInfo pi;
1343 pi.status = GNUNET_FS_STATUS_PUBLISH_RESUME;
1344 pi.value.publish.specifics.resume.message = sc->fi->emsg;
1345 pi.value.publish.specifics.resume.chk_uri = sc->fi->chk_uri;
1346 *client_info = GNUNET_FS_publish_make_status_ (&pi, sc, fi, 0);
1352 * Function called with a filename of serialized publishing operation
1355 * @param cls the 'struct GNUNET_FS_Handle*'
1356 * @param filename complete filename (absolute path)
1357 * @return GNUNET_OK (continue to iterate)
1360 deserialize_publish_file (void *cls,
1361 const char *filename)
1363 struct GNUNET_FS_Handle *h = cls;
1364 struct GNUNET_BIO_ReadHandle *rh;
1365 struct GNUNET_FS_PublishContext *pc;
1373 pc = GNUNET_malloc (sizeof (struct GNUNET_FS_PublishContext));
1375 pc->serialization = get_serialization_short_name (filename);
1379 rh = GNUNET_BIO_read_open (filename);
1386 GNUNET_BIO_read_string (rh, "publish-nid", &pc->nid, 1024)) ||
1388 GNUNET_BIO_read_string (rh, "publish-nuid", &pc->nuid, 1024)) ||
1390 GNUNET_BIO_read_int32 (rh, &options)) ||
1392 GNUNET_BIO_read_int32 (rh, &all_done)) ||
1394 GNUNET_BIO_read_string (rh, "publish-firoot", &fi_root, 128)) ||
1396 GNUNET_BIO_read_string (rh, "publish-fipos", &fi_pos, 128)) ||
1398 GNUNET_BIO_read_string (rh, "publish-ns", &ns, 1024)) )
1403 pc->options = options;
1404 pc->all_done = all_done;
1405 pc->fi = deserialize_file_information (h, fi_root);
1413 pc->namespace = GNUNET_FS_namespace_create (h, ns);
1414 if (pc->namespace == NULL)
1416 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1417 _("Failed to recover namespace `%s', cannot resume publishing operation.\n"),
1424 pc->fi_pos = find_file_position (pc->fi,
1426 GNUNET_free (fi_pos);
1428 if (pc->fi_pos == NULL)
1430 /* failed to find position for resuming, outch! Will start from root! */
1432 if (pc->all_done != GNUNET_YES)
1433 pc->fi_pos = pc->fi;
1436 /* generate RESUME event(s) */
1437 GNUNET_FS_file_information_inspect (pc->fi,
1441 /* re-start publishing (if needed)... */
1442 if (pc->all_done != GNUNET_YES)
1444 = GNUNET_SCHEDULER_add_with_priority (h->sched,
1445 GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
1446 &GNUNET_FS_publish_main_,
1449 GNUNET_BIO_read_close (rh, &emsg))
1451 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1452 _("Failure while resuming publishing operation `%s': %s\n"),
1457 GNUNET_free_non_null (ns);
1458 pc->top = GNUNET_FS_make_top (h, &GNUNET_FS_publish_signal_suspend_, pc);
1461 GNUNET_free_non_null (pc->nid);
1462 GNUNET_free_non_null (pc->nuid);
1463 GNUNET_free_non_null (fi_root);
1464 GNUNET_free_non_null (fi_pos);
1465 GNUNET_free_non_null (ns);
1466 if ( (rh != NULL) &&
1468 GNUNET_BIO_read_close (rh, &emsg)) )
1470 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1471 _("Failed to resume publishing operation `%s': %s\n"),
1477 GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL);
1478 if (0 != UNLINK (filename))
1479 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
1480 GNUNET_free_non_null (pc->serialization);
1487 * Synchronize this publishing struct with its mirror
1488 * on disk. Note that all internal FS-operations that change
1489 * publishing structs should already call "sync" internally,
1490 * so this function is likely not useful for clients.
1492 * @param pc the struct to sync
1495 GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc)
1497 struct GNUNET_BIO_WriteHandle *wh;
1499 if (NULL == pc->serialization)
1500 pc->serialization = make_serialization_file_name (pc->h,
1501 GNUNET_FS_SYNC_PATH_MASTER_PUBLISH);
1502 if (NULL == pc->serialization)
1506 if (NULL == pc->fi->serialization)
1511 wh = get_write_handle (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, pc->serialization);
1518 GNUNET_BIO_write_string (wh, pc->nid)) ||
1520 GNUNET_BIO_write_string (wh, pc->nuid)) ||
1522 GNUNET_BIO_write_int32 (wh, pc->options)) ||
1524 GNUNET_BIO_write_int32 (wh, pc->all_done)) ||
1526 GNUNET_BIO_write_string (wh, pc->fi->serialization)) ||
1528 GNUNET_BIO_write_string (wh, (pc->fi_pos == NULL) ? NULL : pc->fi_pos->serialization)) ||
1530 GNUNET_BIO_write_string (wh, (pc->namespace == NULL) ? NULL : pc->namespace->name)) )
1536 GNUNET_BIO_write_close (wh))
1545 (void) GNUNET_BIO_write_close (wh);
1546 GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, pc->serialization);
1547 GNUNET_free (pc->serialization);
1548 pc->serialization = NULL;
1553 * Synchronize this unindex struct with its mirror
1554 * on disk. Note that all internal FS-operations that change
1555 * publishing structs should already call "sync" internally,
1556 * so this function is likely not useful for clients.
1558 * @param uc the struct to sync
1561 GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc)
1563 struct GNUNET_BIO_WriteHandle *wh;
1565 if (UNINDEX_STATE_ABORTED == uc->state)
1567 if (NULL == uc->serialization)
1568 uc->serialization = make_serialization_file_name (uc->h,
1569 GNUNET_FS_SYNC_PATH_MASTER_UNINDEX);
1570 if (NULL == uc->serialization)
1572 wh = get_write_handle (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, uc->serialization);
1579 GNUNET_BIO_write_string (wh, uc->filename)) ||
1581 GNUNET_BIO_write_int64 (wh, uc->file_size)) ||
1583 write_start_time (wh, uc->start_time)) ||
1585 GNUNET_BIO_write_int32 (wh, (uint32_t) uc->state)) ||
1586 ( (uc->state == UNINDEX_STATE_FS_NOTIFY) &&
1588 GNUNET_BIO_write (wh, &uc->file_id, sizeof (GNUNET_HashCode))) ) ||
1589 ( (uc->state == UNINDEX_STATE_ERROR) &&
1591 GNUNET_BIO_write_string (wh, uc->emsg)) ) )
1597 GNUNET_BIO_write_close (wh))
1606 (void) GNUNET_BIO_write_close (wh);
1607 GNUNET_FS_remove_sync_file_ (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, uc->serialization);
1608 GNUNET_free (uc->serialization);
1609 uc->serialization = NULL;
1614 * Serialize an active or pending download request.
1616 * @param cls the 'struct GNUNET_BIO_WriteHandle*'
1617 * @param key unused, can be NULL
1618 * @param value the 'struct DownloadRequest'
1619 * @return GNUNET_YES on success, GNUNET_NO on error
1622 write_download_request (void *cls,
1623 const GNUNET_HashCode *key,
1626 struct GNUNET_BIO_WriteHandle *wh = cls;
1627 struct DownloadRequest *dr = value;
1630 GNUNET_BIO_write (wh, &dr->chk, sizeof (struct ContentHashKey))) ||
1632 GNUNET_BIO_write_int64 (wh, dr->offset)) ||
1634 GNUNET_BIO_write_int32 (wh, dr->depth)) )
1641 * Count active download requests.
1643 * @param cls the 'uint32_t*' counter
1644 * @param key unused, can be NULL
1645 * @param value the 'struct DownloadRequest'
1646 * @return GNUNET_YES (continue iteration)
1649 count_download_requests (void *cls,
1650 const GNUNET_HashCode *key,
1653 uint32_t *counter = cls;
1661 * Compute the name of the sync file (or directory) for the given download
1664 * @param dc download context to compute for
1665 * @param uni unique filename to use, use "" for the directory name
1666 * @return the expanded file name, NULL for none
1669 get_download_sync_filename (struct GNUNET_FS_DownloadContext *dc,
1675 if (dc->parent == NULL)
1676 return get_serialization_file_name (dc->h,
1677 (dc->search != NULL) ?
1678 GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD :
1679 GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD,
1681 if (dc->parent->serialization == NULL)
1683 par = get_download_sync_filename (dc->parent, dc->parent->serialization);
1686 GNUNET_asprintf (&epar,
1697 * Synchronize this download struct with its mirror
1698 * on disk. Note that all internal FS-operations that change
1699 * publishing structs should already call "sync" internally,
1700 * so this function is likely not useful for clients.
1702 * @param dc the struct to sync
1705 GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc)
1707 struct GNUNET_BIO_WriteHandle *wh;
1711 uint32_t num_pending;
1713 if (NULL == dc->serialization)
1715 dir = get_download_sync_filename (dc, "");
1719 GNUNET_DISK_directory_create_for_file (dir))
1724 fn = GNUNET_DISK_mktemp (dir);
1726 dc->serialization = get_serialization_short_name (fn);
1730 fn = get_download_sync_filename (dc, dc->serialization);
1732 wh = GNUNET_BIO_write_open (fn);
1735 GNUNET_free (dc->serialization);
1736 dc->serialization = NULL;
1740 GNUNET_assert ( (GNUNET_YES == GNUNET_FS_uri_test_chk (dc->uri)) ||
1741 (GNUNET_YES == GNUNET_FS_uri_test_loc (dc->uri)) );
1742 uris = GNUNET_FS_uri_to_string (dc->uri);
1744 if (dc->emsg == NULL)
1745 (void) GNUNET_CONTAINER_multihashmap_iterate (dc->active,
1746 &count_download_requests,
1748 GNUNET_assert ( (dc->length == dc->completed) ||
1749 (dc->emsg != NULL) ||
1750 (num_pending > 0) );
1752 GNUNET_BIO_write_string (wh, uris)) ||
1754 GNUNET_BIO_write_meta_data (wh, dc->meta)) ||
1756 GNUNET_BIO_write_string (wh, dc->emsg)) ||
1758 GNUNET_BIO_write_string (wh, dc->filename)) ||
1760 GNUNET_BIO_write_string (wh, dc->temp_filename)) ||
1762 GNUNET_BIO_write_int64 (wh, dc->old_file_size)) ||
1764 GNUNET_BIO_write_int64 (wh, dc->offset)) ||
1766 GNUNET_BIO_write_int64 (wh, dc->length)) ||
1768 GNUNET_BIO_write_int64 (wh, dc->completed)) ||
1770 write_start_time (wh, dc->start_time)) ||
1772 GNUNET_BIO_write_int32 (wh, dc->anonymity)) ||
1774 GNUNET_BIO_write_int32 (wh, (uint32_t) dc->options)) ||
1776 GNUNET_BIO_write_int32 (wh, (uint32_t) dc->has_finished)) ||
1778 GNUNET_BIO_write_int32 (wh, num_pending)) )
1783 if (GNUNET_SYSERR ==
1784 GNUNET_CONTAINER_multihashmap_iterate (dc->active,
1785 &write_download_request,
1791 GNUNET_free_non_null (uris);
1793 GNUNET_BIO_write_close (wh))
1803 (void) GNUNET_BIO_write_close (wh);
1804 GNUNET_free_non_null (uris);
1805 if (0 != UNLINK (fn))
1806 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
1808 GNUNET_free (dc->serialization);
1809 dc->serialization = NULL;
1814 * Synchronize this search result with its mirror
1815 * on disk. Note that all internal FS-operations that change
1816 * publishing structs should already call "sync" internally,
1817 * so this function is likely not useful for clients.
1819 * @param sr the struct to sync
1822 GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr)
1824 struct GNUNET_BIO_WriteHandle *wh;
1828 if (NULL == sr->serialization)
1829 sr->serialization = make_serialization_file_name_in_dir (sr->sc->h,
1830 (sr->sc->psearch_result == NULL)
1831 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
1832 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
1833 sr->sc->serialization);
1834 if (NULL == sr->serialization)
1836 wh = get_write_handle_in_dir (sr->sc->h,
1837 (sr->sc->psearch_result == NULL)
1838 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
1839 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
1840 sr->sc->serialization,
1847 uris = GNUNET_FS_uri_to_string (sr->uri);
1849 GNUNET_BIO_write_string (wh, uris)) ||
1851 GNUNET_BIO_write_string (wh, sr->download != NULL ? sr->download->serialization : NULL)) ||
1853 GNUNET_BIO_write_string (wh, sr->update_search != NULL ? sr->update_search->serialization : NULL)) ||
1855 GNUNET_BIO_write_meta_data (wh, sr->meta)) ||
1857 GNUNET_BIO_write (wh, &sr->key, sizeof (GNUNET_HashCode))) ||
1859 GNUNET_BIO_write_int32 (wh, sr->mandatory_missing)) ||
1861 GNUNET_BIO_write_int32 (wh, sr->optional_support)) ||
1863 GNUNET_BIO_write_int32 (wh, sr->availability_success)) ||
1865 GNUNET_BIO_write_int32 (wh, sr->availability_trials)) )
1871 GNUNET_BIO_write_close (wh))
1877 GNUNET_free_non_null (uris);
1880 GNUNET_free_non_null (uris);
1882 (void) GNUNET_BIO_write_close (wh);
1883 remove_sync_file_in_dir (sr->sc->h,
1884 (sr->sc->psearch_result == NULL)
1885 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
1886 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
1887 sr->sc->serialization,
1889 GNUNET_free (sr->serialization);
1890 sr->serialization = NULL;
1895 * Synchronize this search struct with its mirror
1896 * on disk. Note that all internal FS-operations that change
1897 * publishing structs should already call "sync" internally,
1898 * so this function is likely not useful for clients.
1900 * @param sc the struct to sync
1903 GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc)
1905 struct GNUNET_BIO_WriteHandle *wh;
1908 const char *category;
1910 category = (sc->psearch_result == NULL)
1911 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
1912 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH;
1913 if (NULL == sc->serialization)
1914 sc->serialization = make_serialization_file_name (sc->h,
1916 if (NULL == sc->serialization)
1918 wh = get_write_handle (sc->h, category, sc->serialization);
1924 GNUNET_assert ( (GNUNET_YES == GNUNET_FS_uri_test_ksk (sc->uri)) ||
1925 (GNUNET_YES == GNUNET_FS_uri_test_sks (sc->uri)) );
1926 uris = GNUNET_FS_uri_to_string (sc->uri);
1927 in_pause = (sc->task != GNUNET_SCHEDULER_NO_TASK) ? 'r' : '\0';
1929 GNUNET_BIO_write_string (wh, uris)) ||
1931 write_start_time (wh, sc->start_time)) ||
1933 GNUNET_BIO_write_string (wh, sc->emsg)) ||
1935 GNUNET_BIO_write_int32 (wh, (uint32_t) sc->options)) ||
1937 GNUNET_BIO_write (wh, &in_pause, sizeof (in_pause))) ||
1939 GNUNET_BIO_write_int32 (wh, sc->anonymity)) )
1947 GNUNET_BIO_write_close (wh))
1956 (void) GNUNET_BIO_write_close (wh);
1957 GNUNET_free_non_null (uris);
1958 GNUNET_FS_remove_sync_file_ (sc->h, category, sc->serialization);
1959 GNUNET_free (sc->serialization);
1960 sc->serialization = NULL;
1965 * Function called with a filename of serialized unindexing operation
1968 * @param cls the 'struct GNUNET_FS_Handle*'
1969 * @param filename complete filename (absolute path)
1970 * @return GNUNET_OK (continue to iterate)
1973 deserialize_unindex_file (void *cls,
1974 const char *filename)
1976 struct GNUNET_FS_Handle *h = cls;
1977 struct GNUNET_BIO_ReadHandle *rh;
1978 struct GNUNET_FS_UnindexContext *uc;
1979 struct GNUNET_FS_ProgressInfo pi;
1983 uc = GNUNET_malloc (sizeof (struct GNUNET_FS_UnindexContext));
1985 uc->serialization = get_serialization_short_name (filename);
1986 rh = GNUNET_BIO_read_open (filename);
1993 GNUNET_BIO_read_string (rh, "unindex-fn", &uc->filename, 10*1024)) ||
1995 GNUNET_BIO_read_int64 (rh, &uc->file_size)) ||
1997 read_start_time (rh, &uc->start_time)) ||
1999 GNUNET_BIO_read_int32 (rh, &state)) )
2004 uc->state = (enum UnindexState) state;
2007 case UNINDEX_STATE_HASHING:
2009 case UNINDEX_STATE_FS_NOTIFY:
2011 GNUNET_BIO_read (rh, "unindex-hash", &uc->file_id, sizeof (GNUNET_HashCode)))
2017 case UNINDEX_STATE_DS_REMOVE:
2019 case UNINDEX_STATE_COMPLETE:
2021 case UNINDEX_STATE_ERROR:
2023 GNUNET_BIO_read_string (rh, "unindex-emsg", &uc->emsg, 10*1024))
2029 case UNINDEX_STATE_ABORTED:
2036 uc->top = GNUNET_FS_make_top (h,
2037 &GNUNET_FS_unindex_signal_suspend_,
2039 pi.status = GNUNET_FS_STATUS_UNINDEX_RESUME;
2040 pi.value.unindex.specifics.resume.message = uc->emsg;
2041 GNUNET_FS_unindex_make_status_ (&pi,
2043 (uc->state == UNINDEX_STATE_COMPLETE)
2048 case UNINDEX_STATE_HASHING:
2049 GNUNET_CRYPTO_hash_file (uc->h->sched,
2050 GNUNET_SCHEDULER_PRIORITY_IDLE,
2053 &GNUNET_FS_unindex_process_hash_,
2056 case UNINDEX_STATE_FS_NOTIFY:
2057 uc->state = UNINDEX_STATE_HASHING;
2058 GNUNET_FS_unindex_process_hash_ (uc,
2061 case UNINDEX_STATE_DS_REMOVE:
2062 GNUNET_FS_unindex_do_remove_ (uc);
2064 case UNINDEX_STATE_COMPLETE:
2065 case UNINDEX_STATE_ERROR:
2066 /* no need to resume any operation, we were done */
2072 GNUNET_BIO_read_close (rh, &emsg))
2074 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2075 _("Failure while resuming unindexing operation `%s': %s\n"),
2082 GNUNET_free_non_null (uc->filename);
2083 if ( (rh != NULL) &&
2085 GNUNET_BIO_read_close (rh, &emsg)) )
2087 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2088 _("Failed to resume unindexing operation `%s': %s\n"),
2093 if (uc->serialization != NULL)
2094 GNUNET_FS_remove_sync_file_ (h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, uc->serialization);
2095 GNUNET_free_non_null (uc->serialization);
2102 * Deserialize a download.
2104 * @param h overall context
2105 * @param rh file to deserialize from
2106 * @param parent parent download
2107 * @param search associated search
2108 * @param serialization name under which the search was serialized
2111 deserialize_download (struct GNUNET_FS_Handle *h,
2112 struct GNUNET_BIO_ReadHandle *rh,
2113 struct GNUNET_FS_DownloadContext *parent,
2114 struct GNUNET_FS_SearchResult *search,
2115 const char *serialization);
2119 * Deserialize a search.
2121 * @param h overall context
2122 * @param rh file to deserialize from
2123 * @param psearch_result parent search result
2124 * @param serialization name under which the search was serialized
2126 static struct GNUNET_FS_SearchContext *
2127 deserialize_search (struct GNUNET_FS_Handle *h,
2128 struct GNUNET_BIO_ReadHandle *rh,
2129 struct GNUNET_FS_SearchResult *psearch_result,
2130 const char *serialization);
2134 * Function called with a filename of serialized search result
2137 * @param cls the 'struct GNUNET_FS_SearchContext*'
2138 * @param filename complete filename (absolute path)
2139 * @return GNUNET_OK (continue to iterate)
2142 deserialize_search_result (void *cls,
2143 const char *filename)
2145 struct GNUNET_FS_SearchContext *sc = cls;
2151 struct GNUNET_BIO_ReadHandle *rh;
2152 struct GNUNET_BIO_ReadHandle *drh;
2153 struct GNUNET_FS_SearchResult *sr;
2155 ser = get_serialization_short_name (filename);
2156 rh = GNUNET_BIO_read_open (filename);
2161 remove_sync_file_in_dir (sc->h,
2162 (sc->psearch_result == NULL)
2163 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
2164 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2174 sr = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchResult));
2175 sr->serialization = ser;
2177 GNUNET_BIO_read_string (rh, "result-uri", &uris, 10*1024)) ||
2178 (NULL == (sr->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
2180 GNUNET_BIO_read_string (rh, "download-lnk", &download, 16)) ||
2182 GNUNET_BIO_read_string (rh, "search-lnk", &update_srch, 16)) ||
2184 GNUNET_BIO_read_meta_data (rh, "result-meta", &sr->meta)) ||
2186 GNUNET_BIO_read (rh, "result-key", &sr->key, sizeof (GNUNET_HashCode))) ||
2188 GNUNET_BIO_read_int32 (rh, &sr->mandatory_missing)) ||
2190 GNUNET_BIO_read_int32 (rh, &sr->optional_support)) ||
2192 GNUNET_BIO_read_int32 (rh, &sr->availability_success)) ||
2194 GNUNET_BIO_read_int32 (rh, &sr->availability_trials)) )
2200 if (download != NULL)
2202 drh = get_read_handle (sc->h,
2203 GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD,
2205 deserialize_download (sc->h,
2211 GNUNET_BIO_read_close (drh, &emsg))
2213 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2214 _("Failed to resume sub-download `%s': %s\n"),
2219 GNUNET_free (download);
2221 if (update_srch != NULL)
2223 drh = get_read_handle (sc->h,
2224 GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2226 deserialize_search (sc->h,
2231 GNUNET_BIO_read_close (drh, &emsg))
2233 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2234 _("Failed to resume sub-search `%s': %s\n"),
2239 GNUNET_free (update_srch);
2241 GNUNET_CONTAINER_multihashmap_put (sc->master_result_map,
2244 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2247 GNUNET_free_non_null (download);
2248 GNUNET_free_non_null (emsg);
2249 GNUNET_free_non_null (uris);
2250 if (sr->uri != NULL)
2251 GNUNET_FS_uri_destroy (sr->uri);
2252 if (sr->meta != NULL)
2253 GNUNET_CONTAINER_meta_data_destroy (sr->meta);
2254 GNUNET_free (sr->serialization);
2261 * Send the 'resume' signal to the callback; also actually
2262 * resume the download (put it in the queue). Does this
2263 * recursively for the top-level download and all child
2266 * @param dc download to resume
2269 signal_download_resume (struct GNUNET_FS_DownloadContext *dc)
2271 struct GNUNET_FS_DownloadContext *dcc;
2272 struct GNUNET_FS_ProgressInfo pi;
2274 pi.status = GNUNET_FS_STATUS_DOWNLOAD_RESUME;
2275 pi.value.download.specifics.resume.meta = dc->meta;
2276 pi.value.download.specifics.resume.message = dc->emsg;
2277 GNUNET_FS_download_make_status_ (&pi,
2279 dcc = dc->child_head;
2282 signal_download_resume (dcc);
2285 if (dc->pending != NULL)
2286 GNUNET_FS_download_start_downloading_ (dc);
2291 * Signal resuming of a search to our clients (for the
2292 * top level search and all sub-searches).
2294 * @param sc search being resumed
2297 signal_search_resume (struct GNUNET_FS_SearchContext *sc);
2301 * Iterator over search results signaling resume to the client for
2304 * @param cls closure, the 'struct GNUNET_FS_SearchContext'
2305 * @param key current key code
2306 * @param value value in the hash map, the 'struct GNUNET_FS_SearchResult'
2307 * @return GNUNET_YES (we should continue to iterate)
2310 signal_result_resume (void *cls,
2311 const GNUNET_HashCode * key,
2314 struct GNUNET_FS_SearchContext *sc = cls;
2315 struct GNUNET_FS_ProgressInfo pi;
2316 struct GNUNET_FS_SearchResult *sr = value;
2318 if (0 == sr->mandatory_missing)
2320 pi.status = GNUNET_FS_STATUS_SEARCH_RESUME_RESULT;
2321 pi.value.search.specifics.resume_result.meta = sr->meta;
2322 pi.value.search.specifics.resume_result.uri = sr->uri;
2323 pi.value.search.specifics.resume_result.result = sr;
2324 pi.value.search.specifics.resume_result.availability_rank = 2*sr->availability_success - sr->availability_trials;
2325 pi.value.search.specifics.resume_result.availability_certainty = sr->availability_trials;
2326 pi.value.search.specifics.resume_result.applicability_rank = sr->optional_support;
2327 sr->client_info = GNUNET_FS_search_make_status_ (&pi,
2330 if (sr->download != NULL)
2332 signal_download_resume (sr->download);
2336 GNUNET_FS_search_start_probe_ (sr);
2338 if (sr->update_search != NULL)
2339 signal_search_resume (sr->update_search);
2345 * Free memory allocated by the search context and its children
2347 * @param sc search context to free
2350 free_search_context (struct GNUNET_FS_SearchContext *sc);
2354 * Iterator over search results freeing each.
2356 * @param cls closure, the 'struct GNUNET_FS_SearchContext'
2357 * @param key current key code
2358 * @param value value in the hash map, the 'struct GNUNET_FS_SearchResult'
2359 * @return GNUNET_YES (we should continue to iterate)
2362 free_result (void *cls,
2363 const GNUNET_HashCode * key,
2366 struct GNUNET_FS_SearchResult *sr = value;
2368 if (sr->update_search != NULL)
2370 free_search_context (sr->update_search);
2371 GNUNET_assert (NULL == sr->update_search);
2373 GNUNET_CONTAINER_meta_data_destroy (sr->meta);
2374 GNUNET_FS_uri_destroy (sr->uri);
2381 * Free memory allocated by the search context and its children
2383 * @param sc search context to free
2386 free_search_context (struct GNUNET_FS_SearchContext *sc)
2388 if (sc->serialization != NULL)
2390 GNUNET_FS_remove_sync_file_ (sc->h,
2391 (sc->psearch_result == NULL)
2392 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
2393 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2395 GNUNET_FS_remove_sync_dir_ (sc->h,
2396 (sc->psearch_result == NULL)
2397 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
2398 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2401 GNUNET_free_non_null (sc->serialization);
2402 GNUNET_free_non_null (sc->emsg);
2403 if (sc->uri != NULL)
2404 GNUNET_FS_uri_destroy (sc->uri);
2405 if (sc->master_result_map != NULL)
2407 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
2410 GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map);
2417 * Function called with a filename of serialized sub-download
2420 * @param cls the 'struct GNUNET_FS_DownloadContext*' (parent)
2421 * @param filename complete filename (absolute path)
2422 * @return GNUNET_OK (continue to iterate)
2425 deserialize_subdownload (void *cls,
2426 const char *filename)
2428 struct GNUNET_FS_DownloadContext *parent = cls;
2431 struct GNUNET_BIO_ReadHandle *rh;
2433 ser = get_serialization_short_name (filename);
2434 rh = GNUNET_BIO_read_open (filename);
2435 deserialize_download (parent->h,
2441 GNUNET_BIO_read_close (rh, &emsg))
2443 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2444 _("Failed to resume sub-download `%s': %s\n"),
2455 * Free this download context and all of its descendants.
2456 * (only works during deserialization since not all possible
2457 * state it taken care of).
2459 * @param dc context to free
2462 free_download_context (struct GNUNET_FS_DownloadContext *dc)
2464 struct GNUNET_FS_DownloadContext *dcc;
2465 struct DownloadRequest *dr;
2466 if (dc->meta != NULL)
2467 GNUNET_CONTAINER_meta_data_destroy (dc->meta);
2468 if (dc->uri != NULL)
2469 GNUNET_FS_uri_destroy (dc->uri);
2470 GNUNET_free_non_null (dc->temp_filename);
2471 GNUNET_free_non_null (dc->emsg);
2472 GNUNET_free_non_null (dc->filename);
2473 while (NULL != (dcc = dc->child_head))
2475 GNUNET_CONTAINER_DLL_remove (dc->child_head,
2478 free_download_context (dcc);
2480 while (NULL != (dr = dc->pending))
2482 dc->pending = dr->next;
2490 * Deserialize a download.
2492 * @param h overall context
2493 * @param rh file to deserialize from
2494 * @param parent parent download
2495 * @param search associated search
2496 * @param serialization name under which the search was serialized
2499 deserialize_download (struct GNUNET_FS_Handle *h,
2500 struct GNUNET_BIO_ReadHandle *rh,
2501 struct GNUNET_FS_DownloadContext *parent,
2502 struct GNUNET_FS_SearchResult *search,
2503 const char *serialization)
2505 struct GNUNET_FS_DownloadContext *dc;
2506 struct DownloadRequest *dr;
2512 uint32_t num_pending;
2517 dc = GNUNET_malloc (sizeof (struct GNUNET_FS_DownloadContext));
2518 dc->parent = parent;
2520 dc->serialization = GNUNET_strdup (serialization);
2522 GNUNET_BIO_read_string (rh, "download-uri", &uris, 10*1024)) ||
2523 (NULL == (dc->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
2524 ( (GNUNET_YES != GNUNET_FS_uri_test_chk (dc->uri)) &&
2525 (GNUNET_YES != GNUNET_FS_uri_test_loc (dc->uri)) ) ||
2527 GNUNET_BIO_read_meta_data (rh, "download-meta", &dc->meta)) ||
2529 GNUNET_BIO_read_string (rh, "download-emsg", &dc->emsg, 10*1024)) ||
2531 GNUNET_BIO_read_string (rh, "download-fn", &dc->filename, 10*1024)) ||
2533 GNUNET_BIO_read_string (rh, "download-tfn", &dc->temp_filename, 10*1024)) ||
2535 GNUNET_BIO_read_int64 (rh, &dc->old_file_size)) ||
2537 GNUNET_BIO_read_int64 (rh, &dc->offset)) ||
2539 GNUNET_BIO_read_int64 (rh, &dc->length)) ||
2541 GNUNET_BIO_read_int64 (rh, &dc->completed)) ||
2543 read_start_time (rh, &dc->start_time)) ||
2545 GNUNET_BIO_read_int32 (rh, &dc->anonymity)) ||
2547 GNUNET_BIO_read_int32 (rh, &options)) ||
2549 GNUNET_BIO_read_int32 (rh, &status)) ||
2551 GNUNET_BIO_read_int32 (rh, &num_pending)) )
2556 dc->options = (enum GNUNET_FS_DownloadOptions) options;
2557 dc->active = GNUNET_CONTAINER_multihashmap_create (16);
2558 dc->has_finished = (int) status;
2559 dc->treedepth = GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size (dc->uri));
2560 if (GNUNET_FS_uri_test_loc (dc->uri))
2561 GNUNET_assert (GNUNET_OK ==
2562 GNUNET_FS_uri_loc_get_peer_identity (dc->uri,
2564 if ( (dc->length > dc->completed) &&
2565 (num_pending == 0) )
2570 while (0 < num_pending--)
2572 dr = GNUNET_malloc (sizeof (struct DownloadRequest));
2574 GNUNET_BIO_read (rh, "chk", &dr->chk, sizeof (struct ContentHashKey))) ||
2576 GNUNET_BIO_read_int64 (rh, &dr->offset)) ||
2578 GNUNET_BIO_read_int32 (rh, &dr->depth)) )
2583 dr->is_pending = GNUNET_YES;
2584 dr->next = dc->pending;
2588 dn = get_download_sync_filename (dc, "");
2592 GNUNET_DISK_directory_test (dn))
2593 GNUNET_DISK_directory_scan (dn, &deserialize_subdownload, dc);
2597 GNUNET_CONTAINER_DLL_insert (parent->child_head,
2602 dc->search = search;
2603 search->download = dc;
2605 if ( (parent == NULL) ||
2607 dc->top = GNUNET_FS_make_top (dc->h,
2608 &GNUNET_FS_download_signal_suspend_,
2610 signal_download_resume (dc);
2614 GNUNET_free_non_null (uris);
2615 GNUNET_free_non_null (dr);
2616 GNUNET_free_non_null (emsg);
2617 free_download_context (dc);
2622 * Signal resuming of a search to our clients (for the
2623 * top level search and all sub-searches).
2625 * @param sc search being resumed
2628 signal_search_resume (struct GNUNET_FS_SearchContext *sc)
2630 struct GNUNET_FS_ProgressInfo pi;
2632 pi.status = GNUNET_FS_STATUS_SEARCH_RESUME;
2633 pi.value.search.specifics.resume.message = sc->emsg;
2634 pi.value.search.specifics.resume.is_paused = (sc->client == NULL) ? GNUNET_YES : GNUNET_NO;
2635 sc->client_info = GNUNET_FS_search_make_status_ (&pi,
2637 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
2638 &signal_result_resume,
2645 * Deserialize a search.
2647 * @param h overall context
2648 * @param rh file to deserialize from
2649 * @param psearch_result parent search result
2650 * @param serialization name under which the search was serialized
2652 static struct GNUNET_FS_SearchContext *
2653 deserialize_search (struct GNUNET_FS_Handle *h,
2654 struct GNUNET_BIO_ReadHandle *rh,
2655 struct GNUNET_FS_SearchResult *psearch_result,
2656 const char *serialization)
2658 struct GNUNET_FS_SearchContext *sc;
2665 if ( (psearch_result != NULL) &&
2666 (psearch_result->update_search != NULL) )
2673 sc = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchContext));
2674 if (psearch_result != NULL)
2676 sc->psearch_result = psearch_result;
2677 psearch_result->update_search = sc;
2680 sc->serialization = GNUNET_strdup (serialization);
2682 GNUNET_BIO_read_string (rh, "search-uri", &uris, 10*1024)) ||
2683 (NULL == (sc->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
2684 ( (GNUNET_YES != GNUNET_FS_uri_test_ksk (sc->uri)) &&
2685 (GNUNET_YES != GNUNET_FS_uri_test_sks (sc->uri)) ) ||
2687 read_start_time (rh, &sc->start_time)) ||
2689 GNUNET_BIO_read_string (rh, "search-emsg", &sc->emsg, 10*1024)) ||
2691 GNUNET_BIO_read_int32 (rh, &options)) ||
2693 GNUNET_BIO_read (rh, "search-pause", &in_pause, sizeof (in_pause))) ||
2695 GNUNET_BIO_read_int32 (rh, &sc->anonymity)) )
2700 sc->options = (enum GNUNET_FS_SearchOptions) options;
2701 sc->master_result_map = GNUNET_CONTAINER_multihashmap_create (16);
2702 dn = get_serialization_file_name_in_dir (h,
2703 (sc->psearch_result == NULL)
2704 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
2705 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2711 GNUNET_DISK_directory_test (dn))
2712 GNUNET_DISK_directory_scan (dn, &deserialize_search_result, sc);
2715 if ( ('\0' == in_pause) &&
2717 GNUNET_FS_search_start_searching_ (sc)) )
2719 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2720 _("Could not resume running search, will resume as paused search\n"));
2722 signal_search_resume (sc);
2726 GNUNET_free_non_null (emsg);
2727 free_search_context (sc);
2728 GNUNET_free_non_null (uris);
2734 * Function called with a filename of serialized search operation
2737 * @param cls the 'struct GNUNET_FS_Handle*'
2738 * @param filename complete filename (absolute path)
2739 * @return GNUNET_OK (continue to iterate)
2742 deserialize_search_file (void *cls,
2743 const char *filename)
2745 struct GNUNET_FS_Handle *h = cls;
2748 struct GNUNET_BIO_ReadHandle *rh;
2749 struct GNUNET_FS_SearchContext *sc;
2751 ser = get_serialization_short_name (filename);
2752 rh = GNUNET_BIO_read_open (filename);
2757 GNUNET_FS_remove_sync_file_ (h, GNUNET_FS_SYNC_PATH_MASTER_SEARCH, ser);
2762 sc = deserialize_search (h, rh, NULL, ser);
2763 sc->top = GNUNET_FS_make_top (h, &GNUNET_FS_search_signal_suspend_, sc);
2766 GNUNET_BIO_read_close (rh, &emsg))
2768 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2769 _("Failure while resuming search operation `%s': %s\n"),
2779 * Function called with a filename of serialized download operation
2782 * @param cls the 'struct GNUNET_FS_Handle*'
2783 * @param filename complete filename (absolute path)
2784 * @return GNUNET_OK (continue to iterate)
2787 deserialize_download_file (void *cls,
2788 const char *filename)
2790 struct GNUNET_FS_Handle *h = cls;
2793 struct GNUNET_BIO_ReadHandle *rh;
2795 ser = get_serialization_short_name (filename);
2796 rh = GNUNET_BIO_read_open (filename);
2799 if (filename != NULL)
2801 if (0 != UNLINK (filename))
2802 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
2809 deserialize_download (h, rh, NULL, NULL, ser);
2812 GNUNET_BIO_read_close (rh, &emsg))
2814 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2815 _("Failure while resuming download operation `%s': %s\n"),
2825 * Deserialize informatin about pending operations.
2827 * @param master_path which master directory should be scanned
2828 * @param proc function to call for each entry (will get 'h' for 'cls')
2829 * @param h the 'struct GNUNET_FS_Handle*'
2832 deserialization_master (const char *master_path,
2833 GNUNET_FileNameCallback proc,
2834 struct GNUNET_FS_Handle *h)
2838 dn = get_serialization_file_name (h, master_path, "");
2842 GNUNET_DISK_directory_test (dn))
2843 GNUNET_DISK_directory_scan (dn, proc, h);
2849 * Setup a connection to the file-sharing service.
2851 * @param sched scheduler to use
2852 * @param cfg configuration to use
2853 * @param client_name unique identifier for this client
2854 * @param upcb function to call to notify about FS actions
2855 * @param upcb_cls closure for upcb
2856 * @param flags specific attributes for fs-operations
2857 * @param ... list of optional options, terminated with GNUNET_FS_OPTIONS_END
2858 * @return NULL on error
2860 struct GNUNET_FS_Handle *
2861 GNUNET_FS_start (struct GNUNET_SCHEDULER_Handle *sched,
2862 const struct GNUNET_CONFIGURATION_Handle *cfg,
2863 const char *client_name,
2864 GNUNET_FS_ProgressCallback upcb,
2866 enum GNUNET_FS_Flags flags,
2869 struct GNUNET_FS_Handle *ret;
2870 enum GNUNET_FS_OPTIONS opt;
2873 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Handle));
2876 ret->client_name = GNUNET_strdup (client_name);
2878 ret->upcb_cls = upcb_cls;
2880 ret->max_parallel_downloads = 1;
2881 ret->max_parallel_requests = 1;
2882 ret->avg_block_latency = GNUNET_TIME_UNIT_MINUTES; /* conservative starting point */
2883 va_start (ap, flags);
2884 while (GNUNET_FS_OPTIONS_END != (opt = va_arg (ap, enum GNUNET_FS_OPTIONS)))
2888 case GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM:
2889 ret->max_parallel_downloads = va_arg (ap, unsigned int);
2891 case GNUNET_FS_OPTIONS_REQUEST_PARALLELISM:
2892 ret->max_parallel_requests = va_arg (ap, unsigned int);
2896 GNUNET_free (ret->client_name);
2903 if (0 != (GNUNET_FS_FLAGS_PERSISTENCE & flags))
2905 deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_PUBLISH,
2906 &deserialize_publish_file,
2908 deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_SEARCH,
2909 &deserialize_search_file,
2911 deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD,
2912 &deserialize_download_file,
2914 deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
2915 &deserialize_unindex_file,
2923 * Close our connection with the file-sharing service.
2924 * The callback given to GNUNET_FS_start will no longer be
2925 * called after this function returns.
2927 * @param h handle that was returned from GNUNET_FS_start
2930 GNUNET_FS_stop (struct GNUNET_FS_Handle *h)
2932 while (h->top_head != NULL)
2933 h->top_head->ssf (h->top_head->ssf_cls);
2934 if (h->queue_job != GNUNET_SCHEDULER_NO_TASK)
2935 GNUNET_SCHEDULER_cancel (h->sched,
2937 GNUNET_free (h->client_name);