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.dir%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);
539 * Return a write handle for serialization.
541 * @param h master context
542 * @param ext component of the path
543 * @param uni name of parent
544 * @param ent entity identifier (or emtpy string for the directory)
545 * @return NULL on error
547 static struct GNUNET_BIO_WriteHandle *
548 get_write_handle_in_dir (struct GNUNET_FS_Handle *h,
554 struct GNUNET_BIO_WriteHandle *ret;
556 fn = get_serialization_file_name_in_dir (h, ext, uni, ent);
559 ret = GNUNET_BIO_write_open (fn);
566 * Remove serialization/deserialization file from disk.
568 * @param h master context
569 * @param ext component of the path
570 * @param ent entity identifier
573 GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h,
579 if ( (NULL == ent) ||
580 (0 == strlen (ent)) )
585 filename = get_serialization_file_name (h, ext, ent);
586 if (0 != UNLINK (filename))
587 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
590 GNUNET_free (filename);
595 * Remove serialization/deserialization file from disk.
597 * @param h master context
598 * @param ext component of the path
599 * @param uni parent name
600 * @param ent entity identifier
603 remove_sync_file_in_dir (struct GNUNET_FS_Handle *h,
610 if ( (NULL == ent) ||
611 (0 == strlen (ent)) )
616 filename = get_serialization_file_name_in_dir (h, ext, uni, ent);
617 if (0 != UNLINK (filename))
618 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
621 GNUNET_free (filename);
626 * Remove serialization/deserialization directory from disk.
628 * @param h master context
629 * @param ext component of the path
630 * @param uni unique name of parent
633 GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h,
641 dn = get_serialization_file_name_in_dir (h, ext, uni, "");
644 if ( (GNUNET_OK == GNUNET_DISK_directory_test (dn)) &&
645 (GNUNET_OK != GNUNET_DISK_directory_remove (dn)) )
646 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
654 * Serialize a 'start_time'. Since we use start-times to
655 * calculate the duration of some operation, we actually
656 * do not serialize the absolute time but the (relative)
657 * duration since the start time. When we then
658 * deserialize the start time, we take the current time and
659 * subtract that duration so that we get again an absolute
660 * time stamp that will result in correct performance
663 * @param wh handle for writing
664 * @param timestamp time to serialize
665 * @return GNUNET_OK on success
668 write_start_time (struct GNUNET_BIO_WriteHandle *wh,
669 struct GNUNET_TIME_Absolute timestamp)
671 struct GNUNET_TIME_Relative dur;
673 dur = GNUNET_TIME_absolute_get_duration (timestamp);
674 return GNUNET_BIO_write_int64 (wh, dur.value);
679 * Serialize a 'start_time'. Since we use start-times to
680 * calculate the duration of some operation, we actually
681 * do not serialize the absolute time but the (relative)
682 * duration since the start time. When we then
683 * deserialize the start time, we take the current time and
684 * subtract that duration so that we get again an absolute
685 * time stamp that will result in correct performance
688 * @param rh handle for reading
689 * @param timestamp where to write the deserialized timestamp
690 * @return GNUNET_OK on success
693 read_start_time (struct GNUNET_BIO_ReadHandle *rh,
694 struct GNUNET_TIME_Absolute *timestamp)
696 struct GNUNET_TIME_Relative dur;
698 GNUNET_BIO_read_int64 (rh, &dur.value))
699 return GNUNET_SYSERR;
700 *timestamp = GNUNET_TIME_absolute_subtract (GNUNET_TIME_absolute_get (),
707 * Using the given serialization filename, try to deserialize
708 * the file-information tree associated with it.
710 * @param h master context
711 * @param filename name of the file (without directory) with
713 * @return NULL on error
715 static struct GNUNET_FS_FileInformation *
716 deserialize_file_information (struct GNUNET_FS_Handle *h,
717 const char *filename);
721 * Using the given serialization filename, try to deserialize
722 * the file-information tree associated with it.
724 * @param h master context
725 * @param fn name of the file (without directory) with
727 * @param rh handle for reading
728 * @return NULL on error
730 static struct GNUNET_FS_FileInformation *
731 deserialize_fi_node (struct GNUNET_FS_Handle *h,
733 struct GNUNET_BIO_ReadHandle *rh)
735 struct GNUNET_FS_FileInformation *ret;
736 struct GNUNET_FS_FileInformation *nxt;
744 GNUNET_BIO_read (rh, "status flag", &b, sizeof(b)))
749 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_FileInformation));
755 GNUNET_BIO_read_meta_data (rh, "metadata", &ret->meta)) ||
757 GNUNET_BIO_read_string (rh, "ksk-uri", &ksks, 32*1024)) ||
760 (ret->keywords = GNUNET_FS_uri_parse (ksks, NULL))) ) ||
762 GNUNET_FS_uri_test_ksk (ret->keywords)) ||
764 GNUNET_BIO_read_string (rh, "chk-uri", &chks, 1024)) ||
767 (ret->chk_uri = GNUNET_FS_uri_parse (chks, NULL))) ||
769 GNUNET_FS_uri_test_chk (ret->chk_uri)) ) ) ||
771 GNUNET_BIO_read_int64 (rh, &ret->expirationTime.value)) ||
773 read_start_time (rh, &ret->start_time)) ||
775 GNUNET_BIO_read_string (rh, "emsg", &ret->emsg, 16*1024)) ||
777 GNUNET_BIO_read_string (rh, "fn", &ret->filename, 16*1024)) ||
779 GNUNET_BIO_read_int32 (rh, &ret->anonymity)) ||
781 GNUNET_BIO_read_int32 (rh, &ret->priority)) )
788 case 0: /* file-insert */
790 GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size))
795 ret->is_directory = GNUNET_NO;
796 ret->data.file.do_index = GNUNET_NO;
797 ret->data.file.have_hash = GNUNET_NO;
798 ret->data.file.index_start_confirmed = GNUNET_NO;
799 if (GNUNET_NO == ret->is_published)
801 if (NULL == ret->filename)
803 ret->data.file.reader = &GNUNET_FS_data_reader_copy_;
804 ret->data.file.reader_cls = GNUNET_malloc_large (ret->data.file.file_size);
805 if (ret->data.file.reader_cls == NULL)
808 GNUNET_BIO_read (rh, "file-data", ret->data.file.reader_cls, ret->data.file.file_size))
816 ret->data.file.reader = &GNUNET_FS_data_reader_file_;
817 ret->data.file.reader_cls = GNUNET_FS_make_file_reader_context_ (ret->filename);
821 case 1: /* file-index, no hash */
822 if (NULL == ret->filename)
828 GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size))
833 ret->is_directory = GNUNET_NO;
834 ret->data.file.do_index = GNUNET_YES;
835 ret->data.file.have_hash = GNUNET_NO;
836 ret->data.file.index_start_confirmed = GNUNET_NO;
837 ret->data.file.reader = &GNUNET_FS_data_reader_file_;
838 ret->data.file.reader_cls = GNUNET_FS_make_file_reader_context_ (ret->filename);
840 case 2: /* file-index-with-hash */
841 if (NULL == ret->filename)
847 GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) ||
849 GNUNET_BIO_read (rh, "fileid", &ret->data.file.file_id, sizeof (GNUNET_HashCode))) )
854 ret->is_directory = GNUNET_NO;
855 ret->data.file.do_index = GNUNET_YES;
856 ret->data.file.have_hash = GNUNET_YES;
857 ret->data.file.index_start_confirmed = GNUNET_NO;
858 ret->data.file.reader = &GNUNET_FS_data_reader_file_;
859 ret->data.file.reader_cls = GNUNET_FS_make_file_reader_context_ (ret->filename);
861 case 3: /* file-index-with-hash-confirmed */
862 if (NULL == ret->filename)
868 GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) ||
870 GNUNET_BIO_read (rh, "fileid", &ret->data.file.file_id, sizeof (GNUNET_HashCode))) )
875 ret->is_directory = GNUNET_NO;
876 ret->data.file.do_index = GNUNET_YES;
877 ret->data.file.have_hash = GNUNET_YES;
878 ret->data.file.index_start_confirmed = GNUNET_YES;
879 ret->data.file.reader = &GNUNET_FS_data_reader_file_;
880 ret->data.file.reader_cls = GNUNET_FS_make_file_reader_context_ (ret->filename);
882 case 4: /* directory */
883 ret->is_directory = GNUNET_YES;
885 GNUNET_BIO_read_int32 (rh, &dsize)) ||
886 (NULL == (ret->data.dir.dir_data = GNUNET_malloc_large (dsize))) ||
888 GNUNET_BIO_read (rh, "dir-data", ret->data.dir.dir_data, dsize)) ||
890 GNUNET_BIO_read_string (rh, "ent-filename", &filename, 16*1024)) )
895 ret->data.dir.dir_size = (uint32_t) dsize;
896 if (filename != NULL)
898 ret->data.dir.entries = deserialize_file_information (h, filename);
899 GNUNET_free (filename);
901 nxt = ret->data.dir.entries;
913 ret->serialization = GNUNET_strdup (fn);
915 GNUNET_BIO_read_string (rh, "nxt-filename", &filename, 16*1024))
920 if (filename != NULL)
922 ret->next = deserialize_file_information (h, filename);
923 GNUNET_free (filename);
926 GNUNET_free_non_null (ksks);
927 GNUNET_free_non_null (chks);
930 GNUNET_free_non_null (ksks);
931 GNUNET_free_non_null (chks);
932 GNUNET_free_non_null (filename);
933 GNUNET_FS_file_information_destroy (ret, NULL, NULL);
939 * Using the given serialization filename, try to deserialize
940 * the file-information tree associated with it.
942 * @param h master context
943 * @param filename name of the file (without directory) with
945 * @return NULL on error
947 static struct GNUNET_FS_FileInformation *
948 deserialize_file_information (struct GNUNET_FS_Handle *h,
949 const char *filename)
951 struct GNUNET_FS_FileInformation *ret;
952 struct GNUNET_BIO_ReadHandle *rh;
955 rh = get_read_handle (h, GNUNET_FS_SYNC_PATH_FILE_INFO, filename);
958 ret = deserialize_fi_node (h, filename, rh);
960 GNUNET_BIO_read_close (rh, &emsg))
962 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
963 _("Failed to resume publishing information `%s': %s\n"),
970 if (0 != UNLINK (filename))
971 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
980 * Given a serialization name (full absolute path), return the
981 * basename of the file (without the path), which must only
982 * consist of the 6 random characters.
984 * @param fullname name to extract the basename from
985 * @return copy of the basename, NULL on error
988 get_serialization_short_name (const char *fullname)
995 /* FIXME: we could do this faster since we know
996 the length of 'end'... */
999 if (DIR_SEPARATOR == *nxt)
1003 if ( (end == NULL) ||
1004 (strlen (end) == 0) )
1009 GNUNET_break (6 == strlen (end));
1010 return GNUNET_strdup (end);
1015 * Create a new random name for serialization. Also checks if persistence
1016 * is enabled and returns NULL if not.
1018 * @param h master context
1019 * @param ext component of the path
1020 * @return NULL on errror
1023 make_serialization_file_name (struct GNUNET_FS_Handle *h,
1030 if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
1031 return NULL; /* persistence not requested */
1032 dn = get_serialization_file_name (h, ext, "");
1034 GNUNET_DISK_directory_create_for_file (dn))
1039 fn = GNUNET_DISK_mktemp (dn);
1042 return NULL; /* epic fail */
1043 ret = get_serialization_short_name (fn);
1050 * Create a new random name for serialization. Also checks if persistence
1051 * is enabled and returns NULL if not.
1053 * @param h master context
1054 * @param ext component of the path
1055 * @param uni name of parent
1056 * @return NULL on errror
1059 make_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h,
1067 if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
1068 return NULL; /* persistence not requested */
1069 dn = get_serialization_file_name_in_dir (h, ext, uni, "");
1071 GNUNET_DISK_directory_create_for_file (dn))
1076 fn = GNUNET_DISK_mktemp (dn);
1079 return NULL; /* epic fail */
1080 ret = get_serialization_short_name (fn);
1087 * Copy all of the data from the reader to the write handle.
1089 * @param wh write handle
1090 * @param fi file with reader
1091 * @return GNUNET_OK on success
1094 copy_from_reader (struct GNUNET_BIO_WriteHandle *wh,
1095 struct GNUNET_FS_FileInformation * fi)
1097 char buf[32 * 1024];
1105 while (off < fi->data.file.file_size)
1107 left = GNUNET_MIN (sizeof(buf), fi->data.file.file_size - off);
1108 ret = fi->data.file.reader (fi->data.file.reader_cls,
1115 return GNUNET_SYSERR;
1118 GNUNET_BIO_write (wh, buf, ret))
1119 return GNUNET_SYSERR;
1127 * Create a temporary file on disk to store the current
1130 * @param fi file information to sync with disk
1133 GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation * fi)
1136 struct GNUNET_BIO_WriteHandle *wh;
1141 if (NULL == fi->serialization)
1142 fi->serialization = make_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO);
1143 if (NULL == fi->serialization)
1145 wh = get_write_handle (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO, fi->serialization);
1148 GNUNET_free (fi->serialization);
1149 fi->serialization = NULL;
1152 if (GNUNET_YES == fi->is_directory)
1154 else if (GNUNET_YES == fi->data.file.index_start_confirmed)
1156 else if (GNUNET_YES == fi->data.file.have_hash)
1158 else if (GNUNET_YES == fi->data.file.do_index)
1162 if (fi->keywords != NULL)
1163 ksks = GNUNET_FS_uri_to_string (fi->keywords);
1166 if (fi->chk_uri != NULL)
1167 chks = GNUNET_FS_uri_to_string (fi->chk_uri);
1171 GNUNET_BIO_write (wh, &b, sizeof (b))) ||
1173 GNUNET_BIO_write_meta_data (wh, fi->meta)) ||
1175 GNUNET_BIO_write_string (wh, ksks)) ||
1177 GNUNET_BIO_write_string (wh, chks)) ||
1179 GNUNET_BIO_write_int64 (wh, fi->expirationTime.value)) ||
1181 write_start_time (wh, fi->start_time)) ||
1183 GNUNET_BIO_write_string (wh, fi->emsg)) ||
1185 GNUNET_BIO_write_string (wh, fi->filename)) ||
1187 GNUNET_BIO_write_int32 (wh, fi->anonymity)) ||
1189 GNUNET_BIO_write_int32 (wh, fi->priority)) )
1194 GNUNET_free_non_null (chks);
1196 GNUNET_free_non_null (ksks);
1201 case 0: /* file-insert */
1203 GNUNET_BIO_write_int64 (wh, fi->data.file.file_size))
1208 if ( (GNUNET_NO == fi->is_published) &&
1209 (NULL == fi->filename) )
1211 copy_from_reader (wh, fi))
1217 case 1: /* file-index, no hash */
1218 if (NULL == fi->filename)
1224 GNUNET_BIO_write_int64 (wh, fi->data.file.file_size))
1230 case 2: /* file-index-with-hash */
1231 case 3: /* file-index-with-hash-confirmed */
1232 if (NULL == fi->filename)
1238 GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) ||
1240 GNUNET_BIO_write (wh, &fi->data.file.file_id, sizeof (GNUNET_HashCode))) )
1246 case 4: /* directory */
1248 GNUNET_BIO_write_int32 (wh, fi->data.dir.dir_size)) ||
1250 GNUNET_BIO_write (wh, fi->data.dir.dir_data, (uint32_t) fi->data.dir.dir_size)) ||
1252 GNUNET_BIO_write_string (wh,
1253 (fi->data.dir.entries == NULL)
1255 : fi->data.dir.entries->serialization)) )
1266 GNUNET_BIO_write_string (wh, (fi->next != NULL) ? fi->next->serialization : NULL))
1272 GNUNET_BIO_write_close (wh))
1279 (void) GNUNET_BIO_write_close (wh);
1280 GNUNET_free_non_null (chks);
1281 GNUNET_free_non_null (ksks);
1282 fn = get_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO, fi->serialization);
1283 if (0 != UNLINK (fn))
1284 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
1286 GNUNET_free (fi->serialization);
1287 fi->serialization = NULL;
1293 * Find the entry in the file information struct where the
1294 * serialization filename matches the given name.
1296 * @param pos file information to search
1297 * @param srch filename to search for
1298 * @return NULL if srch was not found in this subtree
1300 static struct GNUNET_FS_FileInformation *
1301 find_file_position (struct GNUNET_FS_FileInformation *pos,
1304 struct GNUNET_FS_FileInformation *r;
1308 if (0 == strcmp (srch,
1309 pos->serialization))
1311 if (pos->is_directory)
1313 r = find_file_position (pos->data.dir.entries,
1325 * Signal the FS's progress function that we are resuming
1328 * @param cls closure (of type "struct GNUNET_FS_PublishContext*")
1329 * @param fi the entry in the publish-structure
1330 * @param length length of the file or directory
1331 * @param meta metadata for the file or directory (can be modified)
1332 * @param uri pointer to the keywords that will be used for this entry (can be modified)
1333 * @param anonymity pointer to selected anonymity level (can be modified)
1334 * @param priority pointer to selected priority (can be modified)
1335 * @param expirationTime pointer to selected expiration time (can be modified)
1336 * @param client_info pointer to client context set upon creation (can be modified)
1337 * @return GNUNET_OK to continue (always)
1340 fip_signal_resume(void *cls,
1341 struct GNUNET_FS_FileInformation *fi,
1343 struct GNUNET_CONTAINER_MetaData *meta,
1344 struct GNUNET_FS_Uri **uri,
1345 uint32_t *anonymity,
1347 struct GNUNET_TIME_Absolute *expirationTime,
1350 struct GNUNET_FS_PublishContext *sc = cls;
1351 struct GNUNET_FS_ProgressInfo pi;
1353 pi.status = GNUNET_FS_STATUS_PUBLISH_RESUME;
1354 pi.value.publish.specifics.resume.message = sc->fi->emsg;
1355 pi.value.publish.specifics.resume.chk_uri = sc->fi->chk_uri;
1356 *client_info = GNUNET_FS_publish_make_status_ (&pi, sc, fi, 0);
1362 * Function called with a filename of serialized publishing operation
1365 * @param cls the 'struct GNUNET_FS_Handle*'
1366 * @param filename complete filename (absolute path)
1367 * @return GNUNET_OK (continue to iterate)
1370 deserialize_publish_file (void *cls,
1371 const char *filename)
1373 struct GNUNET_FS_Handle *h = cls;
1374 struct GNUNET_BIO_ReadHandle *rh;
1375 struct GNUNET_FS_PublishContext *pc;
1383 pc = GNUNET_malloc (sizeof (struct GNUNET_FS_PublishContext));
1385 pc->serialization = get_serialization_short_name (filename);
1389 rh = GNUNET_BIO_read_open (filename);
1396 GNUNET_BIO_read_string (rh, "publish-nid", &pc->nid, 1024)) ||
1398 GNUNET_BIO_read_string (rh, "publish-nuid", &pc->nuid, 1024)) ||
1400 GNUNET_BIO_read_int32 (rh, &options)) ||
1402 GNUNET_BIO_read_int32 (rh, &all_done)) ||
1404 GNUNET_BIO_read_string (rh, "publish-firoot", &fi_root, 128)) ||
1406 GNUNET_BIO_read_string (rh, "publish-fipos", &fi_pos, 128)) ||
1408 GNUNET_BIO_read_string (rh, "publish-ns", &ns, 1024)) )
1413 pc->options = options;
1414 pc->all_done = all_done;
1415 pc->fi = deserialize_file_information (h, fi_root);
1423 pc->namespace = GNUNET_FS_namespace_create (h, ns);
1424 if (pc->namespace == NULL)
1426 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1427 _("Failed to recover namespace `%s', cannot resume publishing operation.\n"),
1432 if ( (0 == (pc->options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) &&
1433 (GNUNET_YES != pc->all_done) )
1435 pc->dsh = GNUNET_DATASTORE_connect (h->cfg,
1437 if (NULL == pc->dsh)
1442 pc->fi_pos = find_file_position (pc->fi,
1444 GNUNET_free (fi_pos);
1446 if (pc->fi_pos == NULL)
1448 /* failed to find position for resuming, outch! Will start from root! */
1450 if (pc->all_done != GNUNET_YES)
1451 pc->fi_pos = pc->fi;
1454 GNUNET_free (fi_root);
1456 /* generate RESUME event(s) */
1457 GNUNET_FS_file_information_inspect (pc->fi,
1461 /* re-start publishing (if needed)... */
1462 if (pc->all_done != GNUNET_YES)
1464 = GNUNET_SCHEDULER_add_with_priority (h->sched,
1465 GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
1466 &GNUNET_FS_publish_main_,
1469 GNUNET_BIO_read_close (rh, &emsg))
1471 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1472 _("Failure while resuming publishing operation `%s': %s\n"),
1477 GNUNET_free_non_null (ns);
1478 pc->top = GNUNET_FS_make_top (h, &GNUNET_FS_publish_signal_suspend_, pc);
1481 GNUNET_free_non_null (pc->nid);
1482 GNUNET_free_non_null (pc->nuid);
1483 GNUNET_free_non_null (fi_root);
1484 GNUNET_free_non_null (fi_pos);
1485 GNUNET_free_non_null (ns);
1486 if ( (rh != NULL) &&
1488 GNUNET_BIO_read_close (rh, &emsg)) )
1490 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1491 _("Failed to resume publishing operation `%s': %s\n"),
1497 GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL);
1498 if (0 != UNLINK (filename))
1499 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
1500 GNUNET_free (pc->serialization);
1507 * Synchronize this publishing struct with its mirror
1508 * on disk. Note that all internal FS-operations that change
1509 * publishing structs should already call "sync" internally,
1510 * so this function is likely not useful for clients.
1512 * @param pc the struct to sync
1515 GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc)
1517 struct GNUNET_BIO_WriteHandle *wh;
1519 if (NULL == pc->serialization)
1520 pc->serialization = make_serialization_file_name (pc->h,
1521 GNUNET_FS_SYNC_PATH_MASTER_PUBLISH);
1522 if (NULL == pc->serialization)
1526 if (NULL == pc->fi->serialization)
1531 wh = get_write_handle (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, pc->serialization);
1538 GNUNET_BIO_write_string (wh, pc->nid)) ||
1540 GNUNET_BIO_write_string (wh, pc->nuid)) ||
1542 GNUNET_BIO_write_int32 (wh, pc->options)) ||
1544 GNUNET_BIO_write_int32 (wh, pc->all_done)) ||
1546 GNUNET_BIO_write_string (wh, pc->fi->serialization)) ||
1548 GNUNET_BIO_write_string (wh, (pc->fi_pos == NULL) ? NULL : pc->fi_pos->serialization)) ||
1550 GNUNET_BIO_write_string (wh, (pc->namespace == NULL) ? NULL : pc->namespace->name)) )
1556 GNUNET_BIO_write_close (wh))
1565 (void) GNUNET_BIO_write_close (wh);
1566 GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, pc->serialization);
1567 GNUNET_free (pc->serialization);
1568 pc->serialization = NULL;
1573 * Synchronize this unindex struct with its mirror
1574 * on disk. Note that all internal FS-operations that change
1575 * publishing structs should already call "sync" internally,
1576 * so this function is likely not useful for clients.
1578 * @param uc the struct to sync
1581 GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc)
1583 struct GNUNET_BIO_WriteHandle *wh;
1585 if (NULL == uc->serialization)
1586 uc->serialization = make_serialization_file_name (uc->h,
1587 GNUNET_FS_SYNC_PATH_MASTER_UNINDEX);
1588 if (NULL == uc->serialization)
1590 wh = get_write_handle (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, uc->serialization);
1597 GNUNET_BIO_write_string (wh, uc->filename)) ||
1599 GNUNET_BIO_write_int64 (wh, uc->file_size)) ||
1601 write_start_time (wh, uc->start_time)) ||
1603 GNUNET_BIO_write_int32 (wh, (uint32_t) uc->state)) ||
1604 ( (uc->state == UNINDEX_STATE_FS_NOTIFY) &&
1606 GNUNET_BIO_write (wh, &uc->file_id, sizeof (GNUNET_HashCode))) ) ||
1607 ( (uc->state == UNINDEX_STATE_ERROR) &&
1609 GNUNET_BIO_write_string (wh, uc->emsg)) ) )
1615 GNUNET_BIO_write_close (wh))
1624 (void) GNUNET_BIO_write_close (wh);
1625 GNUNET_FS_remove_sync_file_ (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, uc->serialization);
1626 GNUNET_free (uc->serialization);
1627 uc->serialization = NULL;
1632 * Serialize an active or pending download request.
1634 * @param cls the 'struct GNUNET_BIO_WriteHandle*'
1635 * @param key unused, can be NULL
1636 * @param value the 'struct DownloadRequest'
1637 * @return GNUNET_YES on success, GNUNET_NO on error
1640 write_download_request (void *cls,
1641 const GNUNET_HashCode *key,
1644 struct GNUNET_BIO_WriteHandle *wh = cls;
1645 struct DownloadRequest *dr = value;
1648 GNUNET_BIO_write (wh, &dr->chk, sizeof (struct ContentHashKey))) ||
1650 GNUNET_BIO_write_int64 (wh, dr->offset)) ||
1652 GNUNET_BIO_write_int32 (wh, dr->depth)) )
1659 * Count active download requests.
1661 * @param cls the 'uint32_t*' counter
1662 * @param key unused, can be NULL
1663 * @param value the 'struct DownloadRequest'
1664 * @return GNUNET_YES (continue iteration)
1667 count_download_requests (void *cls,
1668 const GNUNET_HashCode *key,
1671 uint32_t *counter = cls;
1679 * Compute the name of the sync file (or directory) for the given download
1682 * @param dc download context to compute for
1683 * @param uni unique filename to use, use "" for the directory name
1684 * @param ext extension to use, use ".dir" for our own subdirectory
1685 * @return the expanded file name, NULL for none
1688 get_download_sync_filename (struct GNUNET_FS_DownloadContext *dc,
1695 if (dc->parent == NULL)
1696 return get_serialization_file_name (dc->h,
1697 (dc->search != NULL) ?
1698 GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD :
1699 GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD,
1701 if (dc->parent->serialization == NULL)
1703 par = get_download_sync_filename (dc->parent, dc->parent->serialization, "");
1706 GNUNET_asprintf (&epar,
1718 * Synchronize this download struct with its mirror
1719 * on disk. Note that all internal FS-operations that change
1720 * publishing structs should already call "sync" internally,
1721 * so this function is likely not useful for clients.
1723 * @param dc the struct to sync
1726 GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc)
1728 struct GNUNET_BIO_WriteHandle *wh;
1732 uint32_t num_pending;
1734 if (NULL == dc->serialization)
1736 dir = get_download_sync_filename (dc, "", "");
1740 GNUNET_DISK_directory_create_for_file (dir))
1745 fn = GNUNET_DISK_mktemp (dir);
1747 dc->serialization = get_serialization_short_name (fn);
1751 fn = get_download_sync_filename (dc, dc->serialization, "");
1753 wh = GNUNET_BIO_write_open (fn);
1756 GNUNET_free (dc->serialization);
1757 dc->serialization = NULL;
1761 GNUNET_assert ( (GNUNET_YES == GNUNET_FS_uri_test_chk (dc->uri)) ||
1762 (GNUNET_YES == GNUNET_FS_uri_test_loc (dc->uri)) );
1763 uris = GNUNET_FS_uri_to_string (dc->uri);
1765 if (dc->emsg == NULL)
1766 (void) GNUNET_CONTAINER_multihashmap_iterate (dc->active,
1767 &count_download_requests,
1769 GNUNET_assert ( (dc->length == dc->completed) ||
1770 (dc->emsg != NULL) ||
1771 (num_pending > 0) );
1773 GNUNET_BIO_write_string (wh, uris)) ||
1775 GNUNET_BIO_write_meta_data (wh, dc->meta)) ||
1777 GNUNET_BIO_write_string (wh, dc->emsg)) ||
1779 GNUNET_BIO_write_string (wh, dc->filename)) ||
1781 GNUNET_BIO_write_string (wh, dc->temp_filename)) ||
1783 GNUNET_BIO_write_int64 (wh, dc->old_file_size)) ||
1785 GNUNET_BIO_write_int64 (wh, dc->offset)) ||
1787 GNUNET_BIO_write_int64 (wh, dc->length)) ||
1789 GNUNET_BIO_write_int64 (wh, dc->completed)) ||
1791 write_start_time (wh, dc->start_time)) ||
1793 GNUNET_BIO_write_int32 (wh, dc->anonymity)) ||
1795 GNUNET_BIO_write_int32 (wh, (uint32_t) dc->options)) ||
1797 GNUNET_BIO_write_int32 (wh, (uint32_t) dc->has_finished)) ||
1799 GNUNET_BIO_write_int32 (wh, num_pending)) )
1804 if (GNUNET_SYSERR ==
1805 GNUNET_CONTAINER_multihashmap_iterate (dc->active,
1806 &write_download_request,
1812 GNUNET_free_non_null (uris);
1814 GNUNET_BIO_write_close (wh))
1824 (void) GNUNET_BIO_write_close (wh);
1825 GNUNET_free_non_null (uris);
1826 if (0 != UNLINK (fn))
1827 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
1829 GNUNET_free (dc->serialization);
1830 dc->serialization = NULL;
1835 * Synchronize this search result with its mirror
1836 * on disk. Note that all internal FS-operations that change
1837 * publishing structs should already call "sync" internally,
1838 * so this function is likely not useful for clients.
1840 * @param sr the struct to sync
1843 GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr)
1845 struct GNUNET_BIO_WriteHandle *wh;
1849 if (NULL == sr->serialization)
1850 sr->serialization = make_serialization_file_name_in_dir (sr->sc->h,
1851 (sr->sc->psearch_result == NULL)
1852 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
1853 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
1854 sr->sc->serialization);
1855 if (NULL == sr->serialization)
1857 wh = get_write_handle_in_dir (sr->sc->h,
1858 (sr->sc->psearch_result == NULL)
1859 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
1860 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
1861 sr->sc->serialization,
1868 uris = GNUNET_FS_uri_to_string (sr->uri);
1870 GNUNET_BIO_write_string (wh, uris)) ||
1872 GNUNET_BIO_write_string (wh, sr->download != NULL ? sr->download->serialization : NULL)) ||
1874 GNUNET_BIO_write_string (wh, sr->update_search != NULL ? sr->update_search->serialization : NULL)) ||
1876 GNUNET_BIO_write_meta_data (wh, sr->meta)) ||
1878 GNUNET_BIO_write (wh, &sr->key, sizeof (GNUNET_HashCode))) ||
1880 GNUNET_BIO_write_int32 (wh, sr->mandatory_missing)) ||
1882 GNUNET_BIO_write_int32 (wh, sr->optional_support)) ||
1884 GNUNET_BIO_write_int32 (wh, sr->availability_success)) ||
1886 GNUNET_BIO_write_int32 (wh, sr->availability_trials)) )
1892 GNUNET_BIO_write_close (wh))
1898 GNUNET_free_non_null (uris);
1901 GNUNET_free_non_null (uris);
1903 (void) GNUNET_BIO_write_close (wh);
1904 remove_sync_file_in_dir (sr->sc->h,
1905 (sr->sc->psearch_result == NULL)
1906 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
1907 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
1908 sr->sc->serialization,
1910 GNUNET_free (sr->serialization);
1911 sr->serialization = NULL;
1916 * Synchronize this search struct with its mirror
1917 * on disk. Note that all internal FS-operations that change
1918 * publishing structs should already call "sync" internally,
1919 * so this function is likely not useful for clients.
1921 * @param sc the struct to sync
1924 GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc)
1926 struct GNUNET_BIO_WriteHandle *wh;
1929 const char *category;
1931 category = (sc->psearch_result == NULL)
1932 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
1933 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH;
1934 if (NULL == sc->serialization)
1935 sc->serialization = make_serialization_file_name (sc->h,
1937 if (NULL == sc->serialization)
1940 wh = get_write_handle (sc->h, category, sc->serialization);
1946 GNUNET_assert ( (GNUNET_YES == GNUNET_FS_uri_test_ksk (sc->uri)) ||
1947 (GNUNET_YES == GNUNET_FS_uri_test_sks (sc->uri)) );
1948 uris = GNUNET_FS_uri_to_string (sc->uri);
1949 in_pause = (sc->task != GNUNET_SCHEDULER_NO_TASK) ? 'r' : '\0';
1951 GNUNET_BIO_write_string (wh, uris)) ||
1953 write_start_time (wh, sc->start_time)) ||
1955 GNUNET_BIO_write_string (wh, sc->emsg)) ||
1957 GNUNET_BIO_write_int32 (wh, (uint32_t) sc->options)) ||
1959 GNUNET_BIO_write (wh, &in_pause, sizeof (in_pause))) ||
1961 GNUNET_BIO_write_int32 (wh, sc->anonymity)) )
1969 GNUNET_BIO_write_close (wh))
1978 (void) GNUNET_BIO_write_close (wh);
1979 GNUNET_free_non_null (uris);
1980 GNUNET_FS_remove_sync_file_ (sc->h, category, sc->serialization);
1981 GNUNET_free (sc->serialization);
1982 sc->serialization = NULL;
1987 * Function called with a filename of serialized unindexing operation
1990 * @param cls the 'struct GNUNET_FS_Handle*'
1991 * @param filename complete filename (absolute path)
1992 * @return GNUNET_OK (continue to iterate)
1995 deserialize_unindex_file (void *cls,
1996 const char *filename)
1998 struct GNUNET_FS_Handle *h = cls;
1999 struct GNUNET_BIO_ReadHandle *rh;
2000 struct GNUNET_FS_UnindexContext *uc;
2001 struct GNUNET_FS_ProgressInfo pi;
2005 uc = GNUNET_malloc (sizeof (struct GNUNET_FS_UnindexContext));
2007 uc->serialization = get_serialization_short_name (filename);
2008 rh = GNUNET_BIO_read_open (filename);
2015 GNUNET_BIO_read_string (rh, "unindex-fn", &uc->filename, 10*1024)) ||
2017 GNUNET_BIO_read_int64 (rh, &uc->file_size)) ||
2019 read_start_time (rh, &uc->start_time)) ||
2021 GNUNET_BIO_read_int32 (rh, &state)) )
2026 uc->state = (enum UnindexState) state;
2029 case UNINDEX_STATE_HASHING:
2031 case UNINDEX_STATE_FS_NOTIFY:
2033 GNUNET_BIO_read (rh, "unindex-hash", &uc->file_id, sizeof (GNUNET_HashCode)))
2039 case UNINDEX_STATE_DS_REMOVE:
2041 case UNINDEX_STATE_COMPLETE:
2043 case UNINDEX_STATE_ERROR:
2045 GNUNET_BIO_read_string (rh, "unindex-emsg", &uc->emsg, 10*1024))
2055 uc->top = GNUNET_FS_make_top (h,
2056 &GNUNET_FS_unindex_signal_suspend_,
2058 pi.status = GNUNET_FS_STATUS_UNINDEX_RESUME;
2059 pi.value.unindex.specifics.resume.message = uc->emsg;
2060 GNUNET_FS_unindex_make_status_ (&pi,
2062 (uc->state == UNINDEX_STATE_COMPLETE)
2067 case UNINDEX_STATE_HASHING:
2068 uc->fhc = GNUNET_CRYPTO_hash_file (uc->h->sched,
2069 GNUNET_SCHEDULER_PRIORITY_IDLE,
2072 &GNUNET_FS_unindex_process_hash_,
2075 case UNINDEX_STATE_FS_NOTIFY:
2076 uc->state = UNINDEX_STATE_HASHING;
2077 GNUNET_FS_unindex_process_hash_ (uc,
2080 case UNINDEX_STATE_DS_REMOVE:
2081 GNUNET_FS_unindex_do_remove_ (uc);
2083 case UNINDEX_STATE_COMPLETE:
2084 case UNINDEX_STATE_ERROR:
2085 /* no need to resume any operation, we were done */
2091 GNUNET_BIO_read_close (rh, &emsg))
2093 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2094 _("Failure while resuming unindexing operation `%s': %s\n"),
2101 GNUNET_free_non_null (uc->filename);
2102 if ( (rh != NULL) &&
2104 GNUNET_BIO_read_close (rh, &emsg)) )
2106 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2107 _("Failed to resume unindexing operation `%s': %s\n"),
2112 if (uc->serialization != NULL)
2113 GNUNET_FS_remove_sync_file_ (h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, uc->serialization);
2114 GNUNET_free_non_null (uc->serialization);
2121 * Deserialize a download.
2123 * @param h overall context
2124 * @param rh file to deserialize from
2125 * @param parent parent download
2126 * @param search associated search
2127 * @param serialization name under which the search was serialized
2130 deserialize_download (struct GNUNET_FS_Handle *h,
2131 struct GNUNET_BIO_ReadHandle *rh,
2132 struct GNUNET_FS_DownloadContext *parent,
2133 struct GNUNET_FS_SearchResult *search,
2134 const char *serialization);
2138 * Deserialize a search.
2140 * @param h overall context
2141 * @param rh file to deserialize from
2142 * @param psearch_result parent search result
2143 * @param serialization name under which the search was serialized
2145 static struct GNUNET_FS_SearchContext *
2146 deserialize_search (struct GNUNET_FS_Handle *h,
2147 struct GNUNET_BIO_ReadHandle *rh,
2148 struct GNUNET_FS_SearchResult *psearch_result,
2149 const char *serialization);
2153 * Function called with a filename of serialized search result
2156 * @param cls the 'struct GNUNET_FS_SearchContext*'
2157 * @param filename complete filename (absolute path)
2158 * @return GNUNET_OK (continue to iterate)
2161 deserialize_search_result (void *cls,
2162 const char *filename)
2164 struct GNUNET_FS_SearchContext *sc = cls;
2170 struct GNUNET_BIO_ReadHandle *rh;
2171 struct GNUNET_BIO_ReadHandle *drh;
2172 struct GNUNET_FS_SearchResult *sr;
2174 ser = get_serialization_short_name (filename);
2175 rh = GNUNET_BIO_read_open (filename);
2180 remove_sync_file_in_dir (sc->h,
2181 (sc->psearch_result == NULL)
2182 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
2183 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2193 sr = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchResult));
2194 sr->serialization = ser;
2196 GNUNET_BIO_read_string (rh, "result-uri", &uris, 10*1024)) ||
2197 (NULL == (sr->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
2199 GNUNET_BIO_read_string (rh, "download-lnk", &download, 16)) ||
2201 GNUNET_BIO_read_string (rh, "search-lnk", &update_srch, 16)) ||
2203 GNUNET_BIO_read_meta_data (rh, "result-meta", &sr->meta)) ||
2205 GNUNET_BIO_read (rh, "result-key", &sr->key, sizeof (GNUNET_HashCode))) ||
2207 GNUNET_BIO_read_int32 (rh, &sr->mandatory_missing)) ||
2209 GNUNET_BIO_read_int32 (rh, &sr->optional_support)) ||
2211 GNUNET_BIO_read_int32 (rh, &sr->availability_success)) ||
2213 GNUNET_BIO_read_int32 (rh, &sr->availability_trials)) )
2219 if (download != NULL)
2221 drh = get_read_handle (sc->h,
2222 GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD,
2224 deserialize_download (sc->h,
2230 GNUNET_BIO_read_close (drh, &emsg))
2232 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2233 _("Failed to resume sub-download `%s': %s\n"),
2238 GNUNET_free (download);
2240 if (update_srch != NULL)
2242 drh = get_read_handle (sc->h,
2243 GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2245 deserialize_search (sc->h,
2250 GNUNET_BIO_read_close (drh, &emsg))
2252 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2253 _("Failed to resume sub-search `%s': %s\n"),
2258 GNUNET_free (update_srch);
2260 GNUNET_CONTAINER_multihashmap_put (sc->master_result_map,
2263 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2266 GNUNET_free_non_null (download);
2267 GNUNET_free_non_null (emsg);
2268 GNUNET_free_non_null (uris);
2269 if (sr->uri != NULL)
2270 GNUNET_FS_uri_destroy (sr->uri);
2271 if (sr->meta != NULL)
2272 GNUNET_CONTAINER_meta_data_destroy (sr->meta);
2273 GNUNET_free (sr->serialization);
2280 * Send the 'resume' signal to the callback; also actually
2281 * resume the download (put it in the queue). Does this
2282 * recursively for the top-level download and all child
2285 * @param dc download to resume
2288 signal_download_resume (struct GNUNET_FS_DownloadContext *dc)
2290 struct GNUNET_FS_DownloadContext *dcc;
2291 struct GNUNET_FS_ProgressInfo pi;
2293 pi.status = GNUNET_FS_STATUS_DOWNLOAD_RESUME;
2294 pi.value.download.specifics.resume.meta = dc->meta;
2295 pi.value.download.specifics.resume.message = dc->emsg;
2296 GNUNET_FS_download_make_status_ (&pi,
2298 dcc = dc->child_head;
2301 signal_download_resume (dcc);
2304 if (dc->pending != NULL)
2305 GNUNET_FS_download_start_downloading_ (dc);
2310 * Signal resuming of a search to our clients (for the
2311 * top level search and all sub-searches).
2313 * @param sc search being resumed
2316 signal_search_resume (struct GNUNET_FS_SearchContext *sc);
2320 * Iterator over search results signaling resume to the client for
2323 * @param cls closure, the 'struct GNUNET_FS_SearchContext'
2324 * @param key current key code
2325 * @param value value in the hash map, the 'struct GNUNET_FS_SearchResult'
2326 * @return GNUNET_YES (we should continue to iterate)
2329 signal_result_resume (void *cls,
2330 const GNUNET_HashCode * key,
2333 struct GNUNET_FS_SearchContext *sc = cls;
2334 struct GNUNET_FS_ProgressInfo pi;
2335 struct GNUNET_FS_SearchResult *sr = value;
2337 if (0 == sr->mandatory_missing)
2339 pi.status = GNUNET_FS_STATUS_SEARCH_RESUME_RESULT;
2340 pi.value.search.specifics.resume_result.meta = sr->meta;
2341 pi.value.search.specifics.resume_result.uri = sr->uri;
2342 pi.value.search.specifics.resume_result.result = sr;
2343 pi.value.search.specifics.resume_result.availability_rank = 2*sr->availability_success - sr->availability_trials;
2344 pi.value.search.specifics.resume_result.availability_certainty = sr->availability_trials;
2345 pi.value.search.specifics.resume_result.applicability_rank = sr->optional_support;
2346 sr->client_info = GNUNET_FS_search_make_status_ (&pi,
2349 if (sr->download != NULL)
2351 signal_download_resume (sr->download);
2355 GNUNET_FS_search_start_probe_ (sr);
2357 if (sr->update_search != NULL)
2358 signal_search_resume (sr->update_search);
2364 * Free memory allocated by the search context and its children
2366 * @param sc search context to free
2369 free_search_context (struct GNUNET_FS_SearchContext *sc);
2373 * Iterator over search results freeing each.
2375 * @param cls closure, the 'struct GNUNET_FS_SearchContext'
2376 * @param key current key code
2377 * @param value value in the hash map, the 'struct GNUNET_FS_SearchResult'
2378 * @return GNUNET_YES (we should continue to iterate)
2381 free_result (void *cls,
2382 const GNUNET_HashCode * key,
2385 struct GNUNET_FS_SearchResult *sr = value;
2387 if (sr->update_search != NULL)
2389 free_search_context (sr->update_search);
2390 GNUNET_assert (NULL == sr->update_search);
2392 GNUNET_CONTAINER_meta_data_destroy (sr->meta);
2393 GNUNET_FS_uri_destroy (sr->uri);
2400 * Free memory allocated by the search context and its children
2402 * @param sc search context to free
2405 free_search_context (struct GNUNET_FS_SearchContext *sc)
2407 if (sc->serialization != NULL)
2409 GNUNET_FS_remove_sync_file_ (sc->h,
2410 (sc->psearch_result == NULL)
2411 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
2412 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2414 GNUNET_FS_remove_sync_dir_ (sc->h,
2415 (sc->psearch_result == NULL)
2416 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
2417 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2420 GNUNET_free_non_null (sc->serialization);
2421 GNUNET_free_non_null (sc->emsg);
2422 if (sc->uri != NULL)
2423 GNUNET_FS_uri_destroy (sc->uri);
2424 if (sc->master_result_map != NULL)
2426 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
2429 GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map);
2436 * Function called with a filename of serialized sub-download
2439 * @param cls the 'struct GNUNET_FS_DownloadContext*' (parent)
2440 * @param filename complete filename (absolute path)
2441 * @return GNUNET_OK (continue to iterate)
2444 deserialize_subdownload (void *cls,
2445 const char *filename)
2447 struct GNUNET_FS_DownloadContext *parent = cls;
2450 struct GNUNET_BIO_ReadHandle *rh;
2452 ser = get_serialization_short_name (filename);
2453 rh = GNUNET_BIO_read_open (filename);
2456 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2457 _("Failed to resume sub-download `%s': could not open file `%s'\n"),
2463 deserialize_download (parent->h,
2469 GNUNET_BIO_read_close (rh, &emsg))
2471 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2472 _("Failed to resume sub-download `%s': %s\n"),
2483 * Free this download context and all of its descendants.
2484 * (only works during deserialization since not all possible
2485 * state it taken care of).
2487 * @param dc context to free
2490 free_download_context (struct GNUNET_FS_DownloadContext *dc)
2492 struct GNUNET_FS_DownloadContext *dcc;
2493 struct DownloadRequest *dr;
2494 if (dc->meta != NULL)
2495 GNUNET_CONTAINER_meta_data_destroy (dc->meta);
2496 if (dc->uri != NULL)
2497 GNUNET_FS_uri_destroy (dc->uri);
2498 GNUNET_free_non_null (dc->temp_filename);
2499 GNUNET_free_non_null (dc->emsg);
2500 GNUNET_free_non_null (dc->filename);
2501 while (NULL != (dcc = dc->child_head))
2503 GNUNET_CONTAINER_DLL_remove (dc->child_head,
2506 free_download_context (dcc);
2508 while (NULL != (dr = dc->pending))
2510 dc->pending = dr->next;
2518 * Deserialize a download.
2520 * @param h overall context
2521 * @param rh file to deserialize from
2522 * @param parent parent download
2523 * @param search associated search
2524 * @param serialization name under which the search was serialized
2527 deserialize_download (struct GNUNET_FS_Handle *h,
2528 struct GNUNET_BIO_ReadHandle *rh,
2529 struct GNUNET_FS_DownloadContext *parent,
2530 struct GNUNET_FS_SearchResult *search,
2531 const char *serialization)
2533 struct GNUNET_FS_DownloadContext *dc;
2534 struct DownloadRequest *dr;
2540 uint32_t num_pending;
2545 dc = GNUNET_malloc (sizeof (struct GNUNET_FS_DownloadContext));
2546 dc->parent = parent;
2548 dc->serialization = GNUNET_strdup (serialization);
2550 GNUNET_BIO_read_string (rh, "download-uri", &uris, 10*1024)) ||
2551 (NULL == (dc->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
2552 ( (GNUNET_YES != GNUNET_FS_uri_test_chk (dc->uri)) &&
2553 (GNUNET_YES != GNUNET_FS_uri_test_loc (dc->uri)) ) ||
2555 GNUNET_BIO_read_meta_data (rh, "download-meta", &dc->meta)) ||
2557 GNUNET_BIO_read_string (rh, "download-emsg", &dc->emsg, 10*1024)) ||
2559 GNUNET_BIO_read_string (rh, "download-fn", &dc->filename, 10*1024)) ||
2561 GNUNET_BIO_read_string (rh, "download-tfn", &dc->temp_filename, 10*1024)) ||
2563 GNUNET_BIO_read_int64 (rh, &dc->old_file_size)) ||
2565 GNUNET_BIO_read_int64 (rh, &dc->offset)) ||
2567 GNUNET_BIO_read_int64 (rh, &dc->length)) ||
2569 GNUNET_BIO_read_int64 (rh, &dc->completed)) ||
2571 read_start_time (rh, &dc->start_time)) ||
2573 GNUNET_BIO_read_int32 (rh, &dc->anonymity)) ||
2575 GNUNET_BIO_read_int32 (rh, &options)) ||
2577 GNUNET_BIO_read_int32 (rh, &status)) ||
2579 GNUNET_BIO_read_int32 (rh, &num_pending)) )
2584 dc->options = (enum GNUNET_FS_DownloadOptions) options;
2585 dc->active = GNUNET_CONTAINER_multihashmap_create (16);
2586 dc->has_finished = (int) status;
2587 dc->treedepth = GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size (dc->uri));
2588 if (GNUNET_FS_uri_test_loc (dc->uri))
2589 GNUNET_assert (GNUNET_OK ==
2590 GNUNET_FS_uri_loc_get_peer_identity (dc->uri,
2592 if ( (dc->length > dc->completed) &&
2593 (num_pending == 0) )
2598 while (0 < num_pending--)
2600 dr = GNUNET_malloc (sizeof (struct DownloadRequest));
2602 GNUNET_BIO_read (rh, "chk", &dr->chk, sizeof (struct ContentHashKey))) ||
2604 GNUNET_BIO_read_int64 (rh, &dr->offset)) ||
2606 GNUNET_BIO_read_int32 (rh, &dr->depth)) )
2611 dr->is_pending = GNUNET_YES;
2612 dr->next = dc->pending;
2614 GNUNET_CONTAINER_multihashmap_put (dc->active,
2617 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2621 dn = get_download_sync_filename (dc, dc->serialization, ".dir");
2625 GNUNET_DISK_directory_test (dn))
2626 GNUNET_DISK_directory_scan (dn, &deserialize_subdownload, dc);
2631 abort (); // for debugging for now
2632 GNUNET_CONTAINER_DLL_insert (parent->child_head,
2638 dc->search = search;
2639 search->download = dc;
2641 if ( (parent == NULL) &&
2644 dc->top = GNUNET_FS_make_top (dc->h,
2645 &GNUNET_FS_download_signal_suspend_,
2647 signal_download_resume (dc);
2652 GNUNET_free_non_null (uris);
2653 GNUNET_free_non_null (dr);
2654 GNUNET_free_non_null (emsg);
2655 free_download_context (dc);
2660 * Signal resuming of a search to our clients (for the
2661 * top level search and all sub-searches).
2663 * @param sc search being resumed
2666 signal_search_resume (struct GNUNET_FS_SearchContext *sc)
2668 struct GNUNET_FS_ProgressInfo pi;
2670 pi.status = GNUNET_FS_STATUS_SEARCH_RESUME;
2671 pi.value.search.specifics.resume.message = sc->emsg;
2672 pi.value.search.specifics.resume.is_paused = (sc->client == NULL) ? GNUNET_YES : GNUNET_NO;
2673 sc->client_info = GNUNET_FS_search_make_status_ (&pi,
2675 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
2676 &signal_result_resume,
2683 * Deserialize a search.
2685 * @param h overall context
2686 * @param rh file to deserialize from
2687 * @param psearch_result parent search result
2688 * @param serialization name under which the search was serialized
2690 static struct GNUNET_FS_SearchContext *
2691 deserialize_search (struct GNUNET_FS_Handle *h,
2692 struct GNUNET_BIO_ReadHandle *rh,
2693 struct GNUNET_FS_SearchResult *psearch_result,
2694 const char *serialization)
2696 struct GNUNET_FS_SearchContext *sc;
2703 if ( (psearch_result != NULL) &&
2704 (psearch_result->update_search != NULL) )
2711 sc = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchContext));
2712 if (psearch_result != NULL)
2714 sc->psearch_result = psearch_result;
2715 psearch_result->update_search = sc;
2718 sc->serialization = GNUNET_strdup (serialization);
2720 GNUNET_BIO_read_string (rh, "search-uri", &uris, 10*1024)) ||
2721 (NULL == (sc->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
2722 ( (GNUNET_YES != GNUNET_FS_uri_test_ksk (sc->uri)) &&
2723 (GNUNET_YES != GNUNET_FS_uri_test_sks (sc->uri)) ) ||
2725 read_start_time (rh, &sc->start_time)) ||
2727 GNUNET_BIO_read_string (rh, "search-emsg", &sc->emsg, 10*1024)) ||
2729 GNUNET_BIO_read_int32 (rh, &options)) ||
2731 GNUNET_BIO_read (rh, "search-pause", &in_pause, sizeof (in_pause))) ||
2733 GNUNET_BIO_read_int32 (rh, &sc->anonymity)) )
2738 sc->options = (enum GNUNET_FS_SearchOptions) options;
2739 sc->master_result_map = GNUNET_CONTAINER_multihashmap_create (16);
2740 dn = get_serialization_file_name_in_dir (h,
2741 (sc->psearch_result == NULL)
2742 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
2743 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2749 GNUNET_DISK_directory_test (dn))
2750 GNUNET_DISK_directory_scan (dn, &deserialize_search_result, sc);
2753 if ( ('\0' == in_pause) &&
2755 GNUNET_FS_search_start_searching_ (sc)) )
2757 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2758 _("Could not resume running search, will resume as paused search\n"));
2760 signal_search_resume (sc);
2764 GNUNET_free_non_null (emsg);
2765 free_search_context (sc);
2766 GNUNET_free_non_null (uris);
2772 * Function called with a filename of serialized search operation
2775 * @param cls the 'struct GNUNET_FS_Handle*'
2776 * @param filename complete filename (absolute path)
2777 * @return GNUNET_OK (continue to iterate)
2780 deserialize_search_file (void *cls,
2781 const char *filename)
2783 struct GNUNET_FS_Handle *h = cls;
2786 struct GNUNET_BIO_ReadHandle *rh;
2787 struct GNUNET_FS_SearchContext *sc;
2789 ser = get_serialization_short_name (filename);
2790 rh = GNUNET_BIO_read_open (filename);
2795 GNUNET_FS_remove_sync_file_ (h, GNUNET_FS_SYNC_PATH_MASTER_SEARCH, ser);
2800 sc = deserialize_search (h, rh, NULL, ser);
2801 sc->top = GNUNET_FS_make_top (h, &GNUNET_FS_search_signal_suspend_, sc);
2804 GNUNET_BIO_read_close (rh, &emsg))
2806 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2807 _("Failure while resuming search operation `%s': %s\n"),
2817 * Function called with a filename of serialized download operation
2820 * @param cls the 'struct GNUNET_FS_Handle*'
2821 * @param filename complete filename (absolute path)
2822 * @return GNUNET_OK (continue to iterate)
2825 deserialize_download_file (void *cls,
2826 const char *filename)
2828 struct GNUNET_FS_Handle *h = cls;
2831 struct GNUNET_BIO_ReadHandle *rh;
2833 ser = get_serialization_short_name (filename);
2834 rh = GNUNET_BIO_read_open (filename);
2837 if (0 != UNLINK (filename))
2838 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
2844 deserialize_download (h, rh, NULL, NULL, ser);
2847 GNUNET_BIO_read_close (rh, &emsg))
2849 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2850 _("Failure while resuming download operation `%s': %s\n"),
2860 * Deserialize informatin about pending operations.
2862 * @param master_path which master directory should be scanned
2863 * @param proc function to call for each entry (will get 'h' for 'cls')
2864 * @param h the 'struct GNUNET_FS_Handle*'
2867 deserialization_master (const char *master_path,
2868 GNUNET_FileNameCallback proc,
2869 struct GNUNET_FS_Handle *h)
2873 dn = get_serialization_file_name (h, master_path, "");
2877 GNUNET_DISK_directory_test (dn))
2878 GNUNET_DISK_directory_scan (dn, proc, h);
2884 * Setup a connection to the file-sharing service.
2886 * @param sched scheduler to use
2887 * @param cfg configuration to use
2888 * @param client_name unique identifier for this client
2889 * @param upcb function to call to notify about FS actions
2890 * @param upcb_cls closure for upcb
2891 * @param flags specific attributes for fs-operations
2892 * @param ... list of optional options, terminated with GNUNET_FS_OPTIONS_END
2893 * @return NULL on error
2895 struct GNUNET_FS_Handle *
2896 GNUNET_FS_start (struct GNUNET_SCHEDULER_Handle *sched,
2897 const struct GNUNET_CONFIGURATION_Handle *cfg,
2898 const char *client_name,
2899 GNUNET_FS_ProgressCallback upcb,
2901 enum GNUNET_FS_Flags flags,
2904 struct GNUNET_FS_Handle *ret;
2905 enum GNUNET_FS_OPTIONS opt;
2908 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Handle));
2911 ret->client_name = GNUNET_strdup (client_name);
2913 ret->upcb_cls = upcb_cls;
2915 ret->max_parallel_downloads = 1;
2916 ret->max_parallel_requests = 1;
2917 ret->avg_block_latency = GNUNET_TIME_UNIT_MINUTES; /* conservative starting point */
2918 va_start (ap, flags);
2919 while (GNUNET_FS_OPTIONS_END != (opt = va_arg (ap, enum GNUNET_FS_OPTIONS)))
2923 case GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM:
2924 ret->max_parallel_downloads = va_arg (ap, unsigned int);
2926 case GNUNET_FS_OPTIONS_REQUEST_PARALLELISM:
2927 ret->max_parallel_requests = va_arg (ap, unsigned int);
2931 GNUNET_free (ret->client_name);
2938 if (0 != (GNUNET_FS_FLAGS_PERSISTENCE & flags))
2940 deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_PUBLISH,
2941 &deserialize_publish_file,
2943 deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_SEARCH,
2944 &deserialize_search_file,
2946 deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD,
2947 &deserialize_download_file,
2949 deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
2950 &deserialize_unindex_file,
2958 * Close our connection with the file-sharing service.
2959 * The callback given to GNUNET_FS_start will no longer be
2960 * called after this function returns.
2962 * @param h handle that was returned from GNUNET_FS_start
2965 GNUNET_FS_stop (struct GNUNET_FS_Handle *h)
2967 while (h->top_head != NULL)
2968 h->top_head->ssf (h->top_head->ssf_cls);
2969 if (h->queue_job != GNUNET_SCHEDULER_NO_TASK)
2970 GNUNET_SCHEDULER_cancel (h->sched,
2972 GNUNET_free (h->client_name);