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 3, 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);
137 if (rst.rel_value > 0)
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 (filename != NULL)
588 if (0 != UNLINK (filename))
589 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
592 GNUNET_free (filename);
598 * Remove serialization/deserialization file from disk.
600 * @param h master context
601 * @param ext component of the path
602 * @param uni parent name
603 * @param ent entity identifier
606 remove_sync_file_in_dir (struct GNUNET_FS_Handle *h,
613 if ( (NULL == ent) ||
614 (0 == strlen (ent)) )
619 filename = get_serialization_file_name_in_dir (h, ext, uni, ent);
620 if (filename != NULL)
622 if (0 != UNLINK (filename))
623 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
626 GNUNET_free (filename);
632 * Remove serialization/deserialization directory from disk.
634 * @param h master context
635 * @param ext component of the path
636 * @param uni unique name of parent
639 GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h,
647 dn = get_serialization_file_name_in_dir (h, ext, uni, "");
650 if ( (GNUNET_OK == GNUNET_DISK_directory_test (dn)) &&
651 (GNUNET_OK != GNUNET_DISK_directory_remove (dn)) )
652 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
660 * Serialize a 'start_time'. Since we use start-times to
661 * calculate the duration of some operation, we actually
662 * do not serialize the absolute time but the (relative)
663 * duration since the start time. When we then
664 * deserialize the start time, we take the current time and
665 * subtract that duration so that we get again an absolute
666 * time stamp that will result in correct performance
669 * @param wh handle for writing
670 * @param timestamp time to serialize
671 * @return GNUNET_OK on success
674 write_start_time (struct GNUNET_BIO_WriteHandle *wh,
675 struct GNUNET_TIME_Absolute timestamp)
677 struct GNUNET_TIME_Relative dur;
679 dur = GNUNET_TIME_absolute_get_duration (timestamp);
680 return GNUNET_BIO_write_int64 (wh, dur.rel_value);
685 * Serialize a 'start_time'. Since we use start-times to
686 * calculate the duration of some operation, we actually
687 * do not serialize the absolute time but the (relative)
688 * duration since the start time. When we then
689 * deserialize the start time, we take the current time and
690 * subtract that duration so that we get again an absolute
691 * time stamp that will result in correct performance
694 * @param rh handle for reading
695 * @param timestamp where to write the deserialized timestamp
696 * @return GNUNET_OK on success
699 read_start_time (struct GNUNET_BIO_ReadHandle *rh,
700 struct GNUNET_TIME_Absolute *timestamp)
702 struct GNUNET_TIME_Relative dur;
704 GNUNET_BIO_read_int64 (rh, &dur.rel_value))
705 return GNUNET_SYSERR;
706 *timestamp = GNUNET_TIME_absolute_subtract (GNUNET_TIME_absolute_get (),
713 * Using the given serialization filename, try to deserialize
714 * the file-information tree associated with it.
716 * @param h master context
717 * @param filename name of the file (without directory) with
719 * @return NULL on error
721 static struct GNUNET_FS_FileInformation *
722 deserialize_file_information (struct GNUNET_FS_Handle *h,
723 const char *filename);
727 * Using the given serialization filename, try to deserialize
728 * the file-information tree associated with it.
730 * @param h master context
731 * @param fn name of the file (without directory) with
733 * @param rh handle for reading
734 * @return NULL on error
736 static struct GNUNET_FS_FileInformation *
737 deserialize_fi_node (struct GNUNET_FS_Handle *h,
739 struct GNUNET_BIO_ReadHandle *rh)
741 struct GNUNET_FS_FileInformation *ret;
742 struct GNUNET_FS_FileInformation *nxt;
750 GNUNET_BIO_read (rh, "status flag", &b, sizeof(b)))
755 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_FileInformation));
761 GNUNET_BIO_read_meta_data (rh, "metadata", &ret->meta)) ||
763 GNUNET_BIO_read_string (rh, "ksk-uri", &ksks, 32*1024)) ||
766 (ret->keywords = GNUNET_FS_uri_parse (ksks, NULL))) ) ||
768 GNUNET_FS_uri_test_ksk (ret->keywords)) ||
770 GNUNET_BIO_read_string (rh, "chk-uri", &chks, 1024)) ||
773 (ret->chk_uri = GNUNET_FS_uri_parse (chks, NULL))) ||
775 GNUNET_FS_uri_test_chk (ret->chk_uri)) ) ) ||
777 GNUNET_BIO_read_int64 (rh, &ret->expirationTime.abs_value)) ||
779 read_start_time (rh, &ret->start_time)) ||
781 GNUNET_BIO_read_string (rh, "emsg", &ret->emsg, 16*1024)) ||
783 GNUNET_BIO_read_string (rh, "fn", &ret->filename, 16*1024)) ||
785 GNUNET_BIO_read_int32 (rh, &ret->anonymity)) ||
787 GNUNET_BIO_read_int32 (rh, &ret->priority)) )
794 case 0: /* file-insert */
796 GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size))
801 ret->is_directory = GNUNET_NO;
802 ret->data.file.do_index = GNUNET_NO;
803 ret->data.file.have_hash = GNUNET_NO;
804 ret->data.file.index_start_confirmed = GNUNET_NO;
805 if (GNUNET_NO == ret->is_published)
807 if (NULL == ret->filename)
809 ret->data.file.reader = &GNUNET_FS_data_reader_copy_;
810 ret->data.file.reader_cls = GNUNET_malloc_large (ret->data.file.file_size);
811 if (ret->data.file.reader_cls == NULL)
814 GNUNET_BIO_read (rh, "file-data", ret->data.file.reader_cls, ret->data.file.file_size))
822 ret->data.file.reader = &GNUNET_FS_data_reader_file_;
823 ret->data.file.reader_cls = GNUNET_FS_make_file_reader_context_ (ret->filename);
827 case 1: /* file-index, no hash */
828 if (NULL == ret->filename)
834 GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size))
839 ret->is_directory = GNUNET_NO;
840 ret->data.file.do_index = GNUNET_YES;
841 ret->data.file.have_hash = GNUNET_NO;
842 ret->data.file.index_start_confirmed = GNUNET_NO;
843 ret->data.file.reader = &GNUNET_FS_data_reader_file_;
844 ret->data.file.reader_cls = GNUNET_FS_make_file_reader_context_ (ret->filename);
846 case 2: /* file-index-with-hash */
847 if (NULL == ret->filename)
853 GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) ||
855 GNUNET_BIO_read (rh, "fileid", &ret->data.file.file_id, sizeof (GNUNET_HashCode))) )
860 ret->is_directory = GNUNET_NO;
861 ret->data.file.do_index = GNUNET_YES;
862 ret->data.file.have_hash = GNUNET_YES;
863 ret->data.file.index_start_confirmed = GNUNET_NO;
864 ret->data.file.reader = &GNUNET_FS_data_reader_file_;
865 ret->data.file.reader_cls = GNUNET_FS_make_file_reader_context_ (ret->filename);
867 case 3: /* file-index-with-hash-confirmed */
868 if (NULL == ret->filename)
874 GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) ||
876 GNUNET_BIO_read (rh, "fileid", &ret->data.file.file_id, sizeof (GNUNET_HashCode))) )
881 ret->is_directory = GNUNET_NO;
882 ret->data.file.do_index = GNUNET_YES;
883 ret->data.file.have_hash = GNUNET_YES;
884 ret->data.file.index_start_confirmed = GNUNET_YES;
885 ret->data.file.reader = &GNUNET_FS_data_reader_file_;
886 ret->data.file.reader_cls = GNUNET_FS_make_file_reader_context_ (ret->filename);
888 case 4: /* directory */
889 ret->is_directory = GNUNET_YES;
891 GNUNET_BIO_read_int32 (rh, &dsize)) ||
892 (NULL == (ret->data.dir.dir_data = GNUNET_malloc_large (dsize))) ||
894 GNUNET_BIO_read (rh, "dir-data", ret->data.dir.dir_data, dsize)) ||
896 GNUNET_BIO_read_string (rh, "ent-filename", &filename, 16*1024)) )
901 ret->data.dir.dir_size = (uint32_t) dsize;
902 if (filename != NULL)
904 ret->data.dir.entries = deserialize_file_information (h, filename);
905 GNUNET_free (filename);
907 nxt = ret->data.dir.entries;
919 ret->serialization = GNUNET_strdup (fn);
921 GNUNET_BIO_read_string (rh, "nxt-filename", &filename, 16*1024))
926 if (filename != NULL)
928 ret->next = deserialize_file_information (h, filename);
929 GNUNET_free (filename);
932 GNUNET_free_non_null (ksks);
933 GNUNET_free_non_null (chks);
936 GNUNET_free_non_null (ksks);
937 GNUNET_free_non_null (chks);
938 GNUNET_free_non_null (filename);
939 GNUNET_FS_file_information_destroy (ret, NULL, NULL);
945 * Using the given serialization filename, try to deserialize
946 * the file-information tree associated with it.
948 * @param h master context
949 * @param filename name of the file (without directory) with
951 * @return NULL on error
953 static struct GNUNET_FS_FileInformation *
954 deserialize_file_information (struct GNUNET_FS_Handle *h,
955 const char *filename)
957 struct GNUNET_FS_FileInformation *ret;
958 struct GNUNET_BIO_ReadHandle *rh;
961 rh = get_read_handle (h, GNUNET_FS_SYNC_PATH_FILE_INFO, filename);
964 ret = deserialize_fi_node (h, filename, rh);
966 GNUNET_BIO_read_close (rh, &emsg))
968 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
969 _("Failed to resume publishing information `%s': %s\n"),
976 if (0 != UNLINK (filename))
977 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
986 * Given a serialization name (full absolute path), return the
987 * basename of the file (without the path), which must only
988 * consist of the 6 random characters.
990 * @param fullname name to extract the basename from
991 * @return copy of the basename, NULL on error
994 get_serialization_short_name (const char *fullname)
1001 /* FIXME: we could do this faster since we know
1002 the length of 'end'... */
1003 while ('\0' != *nxt)
1005 if (DIR_SEPARATOR == *nxt)
1009 if ( (end == NULL) ||
1010 (strlen (end) == 0) )
1015 GNUNET_break (6 == strlen (end));
1016 return GNUNET_strdup (end);
1021 * Create a new random name for serialization. Also checks if persistence
1022 * is enabled and returns NULL if not.
1024 * @param h master context
1025 * @param ext component of the path
1026 * @return NULL on errror
1029 make_serialization_file_name (struct GNUNET_FS_Handle *h,
1036 if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
1037 return NULL; /* persistence not requested */
1038 dn = get_serialization_file_name (h, ext, "");
1042 GNUNET_DISK_directory_create_for_file (dn))
1047 fn = GNUNET_DISK_mktemp (dn);
1050 return NULL; /* epic fail */
1051 ret = get_serialization_short_name (fn);
1058 * Create a new random name for serialization. Also checks if persistence
1059 * is enabled and returns NULL if not.
1061 * @param h master context
1062 * @param ext component of the path
1063 * @param uni name of parent
1064 * @return NULL on errror
1067 make_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h,
1075 if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
1076 return NULL; /* persistence not requested */
1077 dn = get_serialization_file_name_in_dir (h, ext, uni, "");
1081 GNUNET_DISK_directory_create_for_file (dn))
1086 fn = GNUNET_DISK_mktemp (dn);
1089 return NULL; /* epic fail */
1090 ret = get_serialization_short_name (fn);
1097 * Copy all of the data from the reader to the write handle.
1099 * @param wh write handle
1100 * @param fi file with reader
1101 * @return GNUNET_OK on success
1104 copy_from_reader (struct GNUNET_BIO_WriteHandle *wh,
1105 struct GNUNET_FS_FileInformation * fi)
1107 char buf[32 * 1024];
1115 while (off < fi->data.file.file_size)
1117 left = GNUNET_MIN (sizeof(buf), fi->data.file.file_size - off);
1118 ret = fi->data.file.reader (fi->data.file.reader_cls,
1125 return GNUNET_SYSERR;
1128 GNUNET_BIO_write (wh, buf, ret))
1129 return GNUNET_SYSERR;
1137 * Create a temporary file on disk to store the current
1140 * @param fi file information to sync with disk
1143 GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation * fi)
1146 struct GNUNET_BIO_WriteHandle *wh;
1151 if (NULL == fi->serialization)
1152 fi->serialization = make_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO);
1153 if (NULL == fi->serialization)
1155 wh = get_write_handle (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO, fi->serialization);
1158 GNUNET_free (fi->serialization);
1159 fi->serialization = NULL;
1162 if (GNUNET_YES == fi->is_directory)
1164 else if (GNUNET_YES == fi->data.file.index_start_confirmed)
1166 else if (GNUNET_YES == fi->data.file.have_hash)
1168 else if (GNUNET_YES == fi->data.file.do_index)
1172 if (fi->keywords != NULL)
1173 ksks = GNUNET_FS_uri_to_string (fi->keywords);
1176 if (fi->chk_uri != NULL)
1177 chks = GNUNET_FS_uri_to_string (fi->chk_uri);
1181 GNUNET_BIO_write (wh, &b, sizeof (b))) ||
1183 GNUNET_BIO_write_meta_data (wh, fi->meta)) ||
1185 GNUNET_BIO_write_string (wh, ksks)) ||
1187 GNUNET_BIO_write_string (wh, chks)) ||
1189 GNUNET_BIO_write_int64 (wh, fi->expirationTime.abs_value)) ||
1191 write_start_time (wh, fi->start_time)) ||
1193 GNUNET_BIO_write_string (wh, fi->emsg)) ||
1195 GNUNET_BIO_write_string (wh, fi->filename)) ||
1197 GNUNET_BIO_write_int32 (wh, fi->anonymity)) ||
1199 GNUNET_BIO_write_int32 (wh, fi->priority)) )
1204 GNUNET_free_non_null (chks);
1206 GNUNET_free_non_null (ksks);
1211 case 0: /* file-insert */
1213 GNUNET_BIO_write_int64 (wh, fi->data.file.file_size))
1218 if ( (GNUNET_NO == fi->is_published) &&
1219 (NULL == fi->filename) )
1221 copy_from_reader (wh, fi))
1227 case 1: /* file-index, no hash */
1228 if (NULL == fi->filename)
1234 GNUNET_BIO_write_int64 (wh, fi->data.file.file_size))
1240 case 2: /* file-index-with-hash */
1241 case 3: /* file-index-with-hash-confirmed */
1242 if (NULL == fi->filename)
1248 GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) ||
1250 GNUNET_BIO_write (wh, &fi->data.file.file_id, sizeof (GNUNET_HashCode))) )
1256 case 4: /* directory */
1258 GNUNET_BIO_write_int32 (wh, fi->data.dir.dir_size)) ||
1260 GNUNET_BIO_write (wh, fi->data.dir.dir_data, (uint32_t) fi->data.dir.dir_size)) ||
1262 GNUNET_BIO_write_string (wh,
1263 (fi->data.dir.entries == NULL)
1265 : fi->data.dir.entries->serialization)) )
1276 GNUNET_BIO_write_string (wh, (fi->next != NULL) ? fi->next->serialization : NULL))
1282 GNUNET_BIO_write_close (wh))
1291 (void) GNUNET_BIO_write_close (wh);
1292 GNUNET_free_non_null (chks);
1293 GNUNET_free_non_null (ksks);
1294 fn = get_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO, fi->serialization);
1297 if (0 != UNLINK (fn))
1298 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
1301 GNUNET_free (fi->serialization);
1302 fi->serialization = NULL;
1308 * Find the entry in the file information struct where the
1309 * serialization filename matches the given name.
1311 * @param pos file information to search
1312 * @param srch filename to search for
1313 * @return NULL if srch was not found in this subtree
1315 static struct GNUNET_FS_FileInformation *
1316 find_file_position (struct GNUNET_FS_FileInformation *pos,
1319 struct GNUNET_FS_FileInformation *r;
1323 if (0 == strcmp (srch,
1324 pos->serialization))
1326 if (pos->is_directory)
1328 r = find_file_position (pos->data.dir.entries,
1340 * Signal the FS's progress function that we are resuming
1343 * @param cls closure (of type "struct GNUNET_FS_PublishContext*")
1344 * @param fi the entry in the publish-structure
1345 * @param length length of the file or directory
1346 * @param meta metadata for the file or directory (can be modified)
1347 * @param uri pointer to the keywords that will be used for this entry (can be modified)
1348 * @param anonymity pointer to selected anonymity level (can be modified)
1349 * @param priority pointer to selected priority (can be modified)
1350 * @param do_index should we index?
1351 * @param expirationTime pointer to selected expiration time (can be modified)
1352 * @param client_info pointer to client context set upon creation (can be modified)
1353 * @return GNUNET_OK to continue (always)
1356 fip_signal_resume(void *cls,
1357 struct GNUNET_FS_FileInformation *fi,
1359 struct GNUNET_CONTAINER_MetaData *meta,
1360 struct GNUNET_FS_Uri **uri,
1361 uint32_t *anonymity,
1364 struct GNUNET_TIME_Absolute *expirationTime,
1367 struct GNUNET_FS_PublishContext *sc = cls;
1368 struct GNUNET_FS_ProgressInfo pi;
1370 pi.status = GNUNET_FS_STATUS_PUBLISH_RESUME;
1371 pi.value.publish.specifics.resume.message = sc->fi->emsg;
1372 pi.value.publish.specifics.resume.chk_uri = sc->fi->chk_uri;
1373 *client_info = GNUNET_FS_publish_make_status_ (&pi, sc, fi, 0);
1379 * Function called with a filename of serialized publishing operation
1382 * @param cls the 'struct GNUNET_FS_Handle*'
1383 * @param filename complete filename (absolute path)
1384 * @return GNUNET_OK (continue to iterate)
1387 deserialize_publish_file (void *cls,
1388 const char *filename)
1390 struct GNUNET_FS_Handle *h = cls;
1391 struct GNUNET_BIO_ReadHandle *rh;
1392 struct GNUNET_FS_PublishContext *pc;
1400 pc = GNUNET_malloc (sizeof (struct GNUNET_FS_PublishContext));
1402 pc->serialization = get_serialization_short_name (filename);
1406 rh = GNUNET_BIO_read_open (filename);
1413 GNUNET_BIO_read_string (rh, "publish-nid", &pc->nid, 1024)) ||
1415 GNUNET_BIO_read_string (rh, "publish-nuid", &pc->nuid, 1024)) ||
1417 GNUNET_BIO_read_int32 (rh, &options)) ||
1419 GNUNET_BIO_read_int32 (rh, &all_done)) ||
1421 GNUNET_BIO_read_string (rh, "publish-firoot", &fi_root, 128)) ||
1423 GNUNET_BIO_read_string (rh, "publish-fipos", &fi_pos, 128)) ||
1425 GNUNET_BIO_read_string (rh, "publish-ns", &ns, 1024)) )
1430 pc->options = options;
1431 pc->all_done = all_done;
1432 pc->fi = deserialize_file_information (h, fi_root);
1440 pc->namespace = GNUNET_FS_namespace_create (h, ns);
1441 if (pc->namespace == NULL)
1443 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1444 _("Failed to recover namespace `%s', cannot resume publishing operation.\n"),
1449 if ( (0 == (pc->options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) &&
1450 (GNUNET_YES != pc->all_done) )
1452 pc->dsh = GNUNET_DATASTORE_connect (h->cfg,
1454 if (NULL == pc->dsh)
1459 pc->fi_pos = find_file_position (pc->fi,
1461 GNUNET_free (fi_pos);
1463 if (pc->fi_pos == NULL)
1465 /* failed to find position for resuming, outch! Will start from root! */
1467 if (pc->all_done != GNUNET_YES)
1468 pc->fi_pos = pc->fi;
1471 GNUNET_free (fi_root);
1473 /* generate RESUME event(s) */
1474 GNUNET_FS_file_information_inspect (pc->fi,
1478 /* re-start publishing (if needed)... */
1479 if (pc->all_done != GNUNET_YES)
1481 = GNUNET_SCHEDULER_add_with_priority (h->sched,
1482 GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
1483 &GNUNET_FS_publish_main_,
1486 GNUNET_BIO_read_close (rh, &emsg))
1488 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1489 _("Failure while resuming publishing operation `%s': %s\n"),
1494 GNUNET_free_non_null (ns);
1495 pc->top = GNUNET_FS_make_top (h, &GNUNET_FS_publish_signal_suspend_, pc);
1498 GNUNET_free_non_null (pc->nid);
1499 GNUNET_free_non_null (pc->nuid);
1500 GNUNET_free_non_null (fi_root);
1501 GNUNET_free_non_null (fi_pos);
1502 GNUNET_free_non_null (ns);
1503 if ( (rh != NULL) &&
1505 GNUNET_BIO_read_close (rh, &emsg)) )
1507 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1508 _("Failed to resume publishing operation `%s': %s\n"),
1514 GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL);
1515 if (0 != UNLINK (filename))
1516 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
1517 GNUNET_free (pc->serialization);
1524 * Synchronize this publishing struct with its mirror
1525 * on disk. Note that all internal FS-operations that change
1526 * publishing structs should already call "sync" internally,
1527 * so this function is likely not useful for clients.
1529 * @param pc the struct to sync
1532 GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc)
1534 struct GNUNET_BIO_WriteHandle *wh;
1536 if (NULL == pc->serialization)
1537 pc->serialization = make_serialization_file_name (pc->h,
1538 GNUNET_FS_SYNC_PATH_MASTER_PUBLISH);
1539 if (NULL == pc->serialization)
1543 if (NULL == pc->fi->serialization)
1548 wh = get_write_handle (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, pc->serialization);
1555 GNUNET_BIO_write_string (wh, pc->nid)) ||
1557 GNUNET_BIO_write_string (wh, pc->nuid)) ||
1559 GNUNET_BIO_write_int32 (wh, pc->options)) ||
1561 GNUNET_BIO_write_int32 (wh, pc->all_done)) ||
1563 GNUNET_BIO_write_string (wh, pc->fi->serialization)) ||
1565 GNUNET_BIO_write_string (wh, (pc->fi_pos == NULL) ? NULL : pc->fi_pos->serialization)) ||
1567 GNUNET_BIO_write_string (wh, (pc->namespace == NULL) ? NULL : pc->namespace->name)) )
1573 GNUNET_BIO_write_close (wh))
1582 (void) GNUNET_BIO_write_close (wh);
1583 GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, pc->serialization);
1584 GNUNET_free (pc->serialization);
1585 pc->serialization = NULL;
1590 * Synchronize this unindex struct with its mirror
1591 * on disk. Note that all internal FS-operations that change
1592 * publishing structs should already call "sync" internally,
1593 * so this function is likely not useful for clients.
1595 * @param uc the struct to sync
1598 GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc)
1600 struct GNUNET_BIO_WriteHandle *wh;
1602 if (NULL == uc->serialization)
1603 uc->serialization = make_serialization_file_name (uc->h,
1604 GNUNET_FS_SYNC_PATH_MASTER_UNINDEX);
1605 if (NULL == uc->serialization)
1607 wh = get_write_handle (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, uc->serialization);
1614 GNUNET_BIO_write_string (wh, uc->filename)) ||
1616 GNUNET_BIO_write_int64 (wh, uc->file_size)) ||
1618 write_start_time (wh, uc->start_time)) ||
1620 GNUNET_BIO_write_int32 (wh, (uint32_t) uc->state)) ||
1621 ( (uc->state == UNINDEX_STATE_FS_NOTIFY) &&
1623 GNUNET_BIO_write (wh, &uc->file_id, sizeof (GNUNET_HashCode))) ) ||
1624 ( (uc->state == UNINDEX_STATE_ERROR) &&
1626 GNUNET_BIO_write_string (wh, uc->emsg)) ) )
1632 GNUNET_BIO_write_close (wh))
1641 (void) GNUNET_BIO_write_close (wh);
1642 GNUNET_FS_remove_sync_file_ (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, uc->serialization);
1643 GNUNET_free (uc->serialization);
1644 uc->serialization = NULL;
1649 * Serialize an active or pending download request.
1651 * @param cls the 'struct GNUNET_BIO_WriteHandle*'
1652 * @param key unused, can be NULL
1653 * @param value the 'struct DownloadRequest'
1654 * @return GNUNET_YES on success, GNUNET_NO on error
1657 write_download_request (void *cls,
1658 const GNUNET_HashCode *key,
1661 struct GNUNET_BIO_WriteHandle *wh = cls;
1662 struct DownloadRequest *dr = value;
1665 GNUNET_BIO_write (wh, &dr->chk, sizeof (struct ContentHashKey))) ||
1667 GNUNET_BIO_write_int64 (wh, dr->offset)) ||
1669 GNUNET_BIO_write_int32 (wh, dr->depth)) )
1676 * Count active download requests.
1678 * @param cls the 'uint32_t*' counter
1679 * @param key unused, can be NULL
1680 * @param value the 'struct DownloadRequest'
1681 * @return GNUNET_YES (continue iteration)
1684 count_download_requests (void *cls,
1685 const GNUNET_HashCode *key,
1688 uint32_t *counter = cls;
1696 * Compute the name of the sync file (or directory) for the given download
1699 * @param dc download context to compute for
1700 * @param uni unique filename to use, use "" for the directory name
1701 * @param ext extension to use, use ".dir" for our own subdirectory
1702 * @return the expanded file name, NULL for none
1705 get_download_sync_filename (struct GNUNET_FS_DownloadContext *dc,
1712 if (dc->parent == NULL)
1713 return get_serialization_file_name (dc->h,
1714 (dc->search != NULL) ?
1715 GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD :
1716 GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD,
1718 if (dc->parent->serialization == NULL)
1720 par = get_download_sync_filename (dc->parent, dc->parent->serialization, "");
1723 GNUNET_asprintf (&epar,
1735 * Synchronize this download struct with its mirror
1736 * on disk. Note that all internal FS-operations that change
1737 * publishing structs should already call "sync" internally,
1738 * so this function is likely not useful for clients.
1740 * @param dc the struct to sync
1743 GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc)
1745 struct GNUNET_BIO_WriteHandle *wh;
1749 uint32_t num_pending;
1751 if (NULL == dc->serialization)
1753 dir = get_download_sync_filename (dc, "", "");
1757 GNUNET_DISK_directory_create_for_file (dir))
1762 fn = GNUNET_DISK_mktemp (dir);
1766 dc->serialization = get_serialization_short_name (fn);
1770 fn = get_download_sync_filename (dc, dc->serialization, "");
1773 GNUNET_free (dc->serialization);
1774 dc->serialization = NULL;
1779 wh = GNUNET_BIO_write_open (fn);
1782 GNUNET_free (dc->serialization);
1783 dc->serialization = NULL;
1787 GNUNET_assert ( (GNUNET_YES == GNUNET_FS_uri_test_chk (dc->uri)) ||
1788 (GNUNET_YES == GNUNET_FS_uri_test_loc (dc->uri)) );
1789 uris = GNUNET_FS_uri_to_string (dc->uri);
1791 if (dc->emsg == NULL)
1792 (void) GNUNET_CONTAINER_multihashmap_iterate (dc->active,
1793 &count_download_requests,
1795 GNUNET_assert ( (dc->length == dc->completed) ||
1796 (dc->emsg != NULL) ||
1797 (num_pending > 0) );
1799 GNUNET_BIO_write_string (wh, uris)) ||
1801 GNUNET_BIO_write_meta_data (wh, dc->meta)) ||
1803 GNUNET_BIO_write_string (wh, dc->emsg)) ||
1805 GNUNET_BIO_write_string (wh, dc->filename)) ||
1807 GNUNET_BIO_write_string (wh, dc->temp_filename)) ||
1809 GNUNET_BIO_write_int64 (wh, dc->old_file_size)) ||
1811 GNUNET_BIO_write_int64 (wh, dc->offset)) ||
1813 GNUNET_BIO_write_int64 (wh, dc->length)) ||
1815 GNUNET_BIO_write_int64 (wh, dc->completed)) ||
1817 write_start_time (wh, dc->start_time)) ||
1819 GNUNET_BIO_write_int32 (wh, dc->anonymity)) ||
1821 GNUNET_BIO_write_int32 (wh, (uint32_t) dc->options)) ||
1823 GNUNET_BIO_write_int32 (wh, (uint32_t) dc->has_finished)) ||
1825 GNUNET_BIO_write_int32 (wh, num_pending)) )
1830 if (GNUNET_SYSERR ==
1831 GNUNET_CONTAINER_multihashmap_iterate (dc->active,
1832 &write_download_request,
1838 GNUNET_free_non_null (uris);
1841 GNUNET_BIO_write_close (wh))
1851 (void) GNUNET_BIO_write_close (wh);
1852 GNUNET_free_non_null (uris);
1853 if (0 != UNLINK (fn))
1854 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
1856 GNUNET_free (dc->serialization);
1857 dc->serialization = NULL;
1862 * Synchronize this search result with its mirror
1863 * on disk. Note that all internal FS-operations that change
1864 * publishing structs should already call "sync" internally,
1865 * so this function is likely not useful for clients.
1867 * @param sr the struct to sync
1870 GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr)
1872 struct GNUNET_BIO_WriteHandle *wh;
1876 if (NULL == sr->serialization)
1877 sr->serialization = make_serialization_file_name_in_dir (sr->sc->h,
1878 (sr->sc->psearch_result == NULL)
1879 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
1880 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
1881 sr->sc->serialization);
1882 if (NULL == sr->serialization)
1884 wh = get_write_handle_in_dir (sr->sc->h,
1885 (sr->sc->psearch_result == NULL)
1886 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
1887 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
1888 sr->sc->serialization,
1895 uris = GNUNET_FS_uri_to_string (sr->uri);
1897 GNUNET_BIO_write_string (wh, uris)) ||
1899 GNUNET_BIO_write_string (wh, sr->download != NULL ? sr->download->serialization : NULL)) ||
1901 GNUNET_BIO_write_string (wh, sr->update_search != NULL ? sr->update_search->serialization : NULL)) ||
1903 GNUNET_BIO_write_meta_data (wh, sr->meta)) ||
1905 GNUNET_BIO_write (wh, &sr->key, sizeof (GNUNET_HashCode))) ||
1907 GNUNET_BIO_write_int32 (wh, sr->mandatory_missing)) ||
1909 GNUNET_BIO_write_int32 (wh, sr->optional_support)) ||
1911 GNUNET_BIO_write_int32 (wh, sr->availability_success)) ||
1913 GNUNET_BIO_write_int32 (wh, sr->availability_trials)) )
1919 GNUNET_BIO_write_close (wh))
1925 GNUNET_free_non_null (uris);
1928 GNUNET_free_non_null (uris);
1930 (void) GNUNET_BIO_write_close (wh);
1931 remove_sync_file_in_dir (sr->sc->h,
1932 (sr->sc->psearch_result == NULL)
1933 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
1934 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
1935 sr->sc->serialization,
1937 GNUNET_free (sr->serialization);
1938 sr->serialization = NULL;
1943 * Synchronize this search struct with its mirror
1944 * on disk. Note that all internal FS-operations that change
1945 * publishing structs should already call "sync" internally,
1946 * so this function is likely not useful for clients.
1948 * @param sc the struct to sync
1951 GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc)
1953 struct GNUNET_BIO_WriteHandle *wh;
1956 const char *category;
1958 category = (sc->psearch_result == NULL)
1959 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
1960 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH;
1961 if (NULL == sc->serialization)
1962 sc->serialization = make_serialization_file_name (sc->h,
1964 if (NULL == sc->serialization)
1967 wh = get_write_handle (sc->h, category, sc->serialization);
1973 GNUNET_assert ( (GNUNET_YES == GNUNET_FS_uri_test_ksk (sc->uri)) ||
1974 (GNUNET_YES == GNUNET_FS_uri_test_sks (sc->uri)) );
1975 uris = GNUNET_FS_uri_to_string (sc->uri);
1976 in_pause = (sc->task != GNUNET_SCHEDULER_NO_TASK) ? 'r' : '\0';
1978 GNUNET_BIO_write_string (wh, uris)) ||
1980 write_start_time (wh, sc->start_time)) ||
1982 GNUNET_BIO_write_string (wh, sc->emsg)) ||
1984 GNUNET_BIO_write_int32 (wh, (uint32_t) sc->options)) ||
1986 GNUNET_BIO_write (wh, &in_pause, sizeof (in_pause))) ||
1988 GNUNET_BIO_write_int32 (wh, sc->anonymity)) )
1996 GNUNET_BIO_write_close (wh))
2005 (void) GNUNET_BIO_write_close (wh);
2006 GNUNET_free_non_null (uris);
2007 GNUNET_FS_remove_sync_file_ (sc->h, category, sc->serialization);
2008 GNUNET_free (sc->serialization);
2009 sc->serialization = NULL;
2014 * Function called with a filename of serialized unindexing operation
2017 * @param cls the 'struct GNUNET_FS_Handle*'
2018 * @param filename complete filename (absolute path)
2019 * @return GNUNET_OK (continue to iterate)
2022 deserialize_unindex_file (void *cls,
2023 const char *filename)
2025 struct GNUNET_FS_Handle *h = cls;
2026 struct GNUNET_BIO_ReadHandle *rh;
2027 struct GNUNET_FS_UnindexContext *uc;
2028 struct GNUNET_FS_ProgressInfo pi;
2032 uc = GNUNET_malloc (sizeof (struct GNUNET_FS_UnindexContext));
2034 uc->serialization = get_serialization_short_name (filename);
2035 rh = GNUNET_BIO_read_open (filename);
2042 GNUNET_BIO_read_string (rh, "unindex-fn", &uc->filename, 10*1024)) ||
2044 GNUNET_BIO_read_int64 (rh, &uc->file_size)) ||
2046 read_start_time (rh, &uc->start_time)) ||
2048 GNUNET_BIO_read_int32 (rh, &state)) )
2053 uc->state = (enum UnindexState) state;
2056 case UNINDEX_STATE_HASHING:
2058 case UNINDEX_STATE_FS_NOTIFY:
2060 GNUNET_BIO_read (rh, "unindex-hash", &uc->file_id, sizeof (GNUNET_HashCode)))
2066 case UNINDEX_STATE_DS_REMOVE:
2068 case UNINDEX_STATE_COMPLETE:
2070 case UNINDEX_STATE_ERROR:
2072 GNUNET_BIO_read_string (rh, "unindex-emsg", &uc->emsg, 10*1024))
2082 uc->top = GNUNET_FS_make_top (h,
2083 &GNUNET_FS_unindex_signal_suspend_,
2085 pi.status = GNUNET_FS_STATUS_UNINDEX_RESUME;
2086 pi.value.unindex.specifics.resume.message = uc->emsg;
2087 GNUNET_FS_unindex_make_status_ (&pi,
2089 (uc->state == UNINDEX_STATE_COMPLETE)
2094 case UNINDEX_STATE_HASHING:
2095 uc->fhc = GNUNET_CRYPTO_hash_file (uc->h->sched,
2096 GNUNET_SCHEDULER_PRIORITY_IDLE,
2099 &GNUNET_FS_unindex_process_hash_,
2102 case UNINDEX_STATE_FS_NOTIFY:
2103 uc->state = UNINDEX_STATE_HASHING;
2104 GNUNET_FS_unindex_process_hash_ (uc,
2107 case UNINDEX_STATE_DS_REMOVE:
2108 GNUNET_FS_unindex_do_remove_ (uc);
2110 case UNINDEX_STATE_COMPLETE:
2111 case UNINDEX_STATE_ERROR:
2112 /* no need to resume any operation, we were done */
2118 GNUNET_BIO_read_close (rh, &emsg))
2120 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2121 _("Failure while resuming unindexing operation `%s': %s\n"),
2128 GNUNET_free_non_null (uc->filename);
2129 if ( (rh != NULL) &&
2131 GNUNET_BIO_read_close (rh, &emsg)) )
2133 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2134 _("Failed to resume unindexing operation `%s': %s\n"),
2139 if (uc->serialization != NULL)
2140 GNUNET_FS_remove_sync_file_ (h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, uc->serialization);
2141 GNUNET_free_non_null (uc->serialization);
2148 * Deserialize a download.
2150 * @param h overall context
2151 * @param rh file to deserialize from
2152 * @param parent parent download
2153 * @param search associated search
2154 * @param serialization name under which the search was serialized
2157 deserialize_download (struct GNUNET_FS_Handle *h,
2158 struct GNUNET_BIO_ReadHandle *rh,
2159 struct GNUNET_FS_DownloadContext *parent,
2160 struct GNUNET_FS_SearchResult *search,
2161 const char *serialization);
2165 * Deserialize a search.
2167 * @param h overall context
2168 * @param rh file to deserialize from
2169 * @param psearch_result parent search result
2170 * @param serialization name under which the search was serialized
2172 static struct GNUNET_FS_SearchContext *
2173 deserialize_search (struct GNUNET_FS_Handle *h,
2174 struct GNUNET_BIO_ReadHandle *rh,
2175 struct GNUNET_FS_SearchResult *psearch_result,
2176 const char *serialization);
2180 * Function called with a filename of serialized search result
2183 * @param cls the 'struct GNUNET_FS_SearchContext*'
2184 * @param filename complete filename (absolute path)
2185 * @return GNUNET_OK (continue to iterate)
2188 deserialize_search_result (void *cls,
2189 const char *filename)
2191 struct GNUNET_FS_SearchContext *sc = cls;
2197 struct GNUNET_BIO_ReadHandle *rh;
2198 struct GNUNET_BIO_ReadHandle *drh;
2199 struct GNUNET_FS_SearchResult *sr;
2201 ser = get_serialization_short_name (filename);
2202 rh = GNUNET_BIO_read_open (filename);
2207 remove_sync_file_in_dir (sc->h,
2208 (sc->psearch_result == NULL)
2209 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
2210 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2221 sr = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchResult));
2222 sr->serialization = ser;
2224 GNUNET_BIO_read_string (rh, "result-uri", &uris, 10*1024)) ||
2225 (NULL == (sr->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
2227 GNUNET_BIO_read_string (rh, "download-lnk", &download, 16)) ||
2229 GNUNET_BIO_read_string (rh, "search-lnk", &update_srch, 16)) ||
2231 GNUNET_BIO_read_meta_data (rh, "result-meta", &sr->meta)) ||
2233 GNUNET_BIO_read (rh, "result-key", &sr->key, sizeof (GNUNET_HashCode))) ||
2235 GNUNET_BIO_read_int32 (rh, &sr->mandatory_missing)) ||
2237 GNUNET_BIO_read_int32 (rh, &sr->optional_support)) ||
2239 GNUNET_BIO_read_int32 (rh, &sr->availability_success)) ||
2241 GNUNET_BIO_read_int32 (rh, &sr->availability_trials)) )
2247 if (download != NULL)
2249 drh = get_read_handle (sc->h,
2250 GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD,
2254 deserialize_download (sc->h,
2260 GNUNET_BIO_read_close (drh, &emsg))
2262 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2263 _("Failed to resume sub-download `%s': %s\n"),
2269 GNUNET_free (download);
2271 if (update_srch != NULL)
2273 drh = get_read_handle (sc->h,
2274 GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2278 deserialize_search (sc->h,
2283 GNUNET_BIO_read_close (drh, &emsg))
2285 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2286 _("Failed to resume sub-search `%s': %s\n"),
2292 GNUNET_free (update_srch);
2294 GNUNET_CONTAINER_multihashmap_put (sc->master_result_map,
2297 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2299 GNUNET_BIO_read_close (rh, &emsg))
2301 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2302 _("Failure while resuming search operation `%s': %s\n"),
2309 GNUNET_free_non_null (download);
2310 GNUNET_free_non_null (emsg);
2311 GNUNET_free_non_null (uris);
2312 GNUNET_free_non_null (update_srch);
2313 if (sr->uri != NULL)
2314 GNUNET_FS_uri_destroy (sr->uri);
2315 if (sr->meta != NULL)
2316 GNUNET_CONTAINER_meta_data_destroy (sr->meta);
2317 GNUNET_free (sr->serialization);
2320 GNUNET_BIO_read_close (rh, &emsg))
2322 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2323 _("Failure while resuming search operation `%s': %s\n"),
2333 * Send the 'resume' signal to the callback; also actually
2334 * resume the download (put it in the queue). Does this
2335 * recursively for the top-level download and all child
2338 * @param dc download to resume
2341 signal_download_resume (struct GNUNET_FS_DownloadContext *dc)
2343 struct GNUNET_FS_DownloadContext *dcc;
2344 struct GNUNET_FS_ProgressInfo pi;
2346 pi.status = GNUNET_FS_STATUS_DOWNLOAD_RESUME;
2347 pi.value.download.specifics.resume.meta = dc->meta;
2348 pi.value.download.specifics.resume.message = dc->emsg;
2349 GNUNET_FS_download_make_status_ (&pi,
2351 dcc = dc->child_head;
2354 signal_download_resume (dcc);
2357 if (dc->pending != NULL)
2358 GNUNET_FS_download_start_downloading_ (dc);
2363 * Signal resuming of a search to our clients (for the
2364 * top level search and all sub-searches).
2366 * @param sc search being resumed
2369 signal_search_resume (struct GNUNET_FS_SearchContext *sc);
2373 * Iterator over search results signaling resume to the client for
2376 * @param cls closure, the 'struct GNUNET_FS_SearchContext'
2377 * @param key current key code
2378 * @param value value in the hash map, the 'struct GNUNET_FS_SearchResult'
2379 * @return GNUNET_YES (we should continue to iterate)
2382 signal_result_resume (void *cls,
2383 const GNUNET_HashCode * key,
2386 struct GNUNET_FS_SearchContext *sc = cls;
2387 struct GNUNET_FS_ProgressInfo pi;
2388 struct GNUNET_FS_SearchResult *sr = value;
2390 if (0 == sr->mandatory_missing)
2392 pi.status = GNUNET_FS_STATUS_SEARCH_RESUME_RESULT;
2393 pi.value.search.specifics.resume_result.meta = sr->meta;
2394 pi.value.search.specifics.resume_result.uri = sr->uri;
2395 pi.value.search.specifics.resume_result.result = sr;
2396 pi.value.search.specifics.resume_result.availability_rank = 2*sr->availability_success - sr->availability_trials;
2397 pi.value.search.specifics.resume_result.availability_certainty = sr->availability_trials;
2398 pi.value.search.specifics.resume_result.applicability_rank = sr->optional_support;
2399 sr->client_info = GNUNET_FS_search_make_status_ (&pi,
2402 if (sr->download != NULL)
2404 signal_download_resume (sr->download);
2408 GNUNET_FS_search_start_probe_ (sr);
2410 if (sr->update_search != NULL)
2411 signal_search_resume (sr->update_search);
2417 * Free memory allocated by the search context and its children
2419 * @param sc search context to free
2422 free_search_context (struct GNUNET_FS_SearchContext *sc);
2426 * Iterator over search results freeing each.
2428 * @param cls closure, the 'struct GNUNET_FS_SearchContext'
2429 * @param key current key code
2430 * @param value value in the hash map, the 'struct GNUNET_FS_SearchResult'
2431 * @return GNUNET_YES (we should continue to iterate)
2434 free_result (void *cls,
2435 const GNUNET_HashCode * key,
2438 struct GNUNET_FS_SearchResult *sr = value;
2440 if (sr->update_search != NULL)
2442 free_search_context (sr->update_search);
2443 GNUNET_assert (NULL == sr->update_search);
2445 GNUNET_CONTAINER_meta_data_destroy (sr->meta);
2446 GNUNET_FS_uri_destroy (sr->uri);
2453 * Free memory allocated by the search context and its children
2455 * @param sc search context to free
2458 free_search_context (struct GNUNET_FS_SearchContext *sc)
2460 if (sc->serialization != NULL)
2462 GNUNET_FS_remove_sync_file_ (sc->h,
2463 (sc->psearch_result == NULL)
2464 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
2465 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2467 GNUNET_FS_remove_sync_dir_ (sc->h,
2468 (sc->psearch_result == NULL)
2469 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
2470 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2473 GNUNET_free_non_null (sc->serialization);
2474 GNUNET_free_non_null (sc->emsg);
2475 if (sc->uri != NULL)
2476 GNUNET_FS_uri_destroy (sc->uri);
2477 if (sc->master_result_map != NULL)
2479 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
2482 GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map);
2489 * Function called with a filename of serialized sub-download
2492 * @param cls the 'struct GNUNET_FS_DownloadContext*' (parent)
2493 * @param filename complete filename (absolute path)
2494 * @return GNUNET_OK (continue to iterate)
2497 deserialize_subdownload (void *cls,
2498 const char *filename)
2500 struct GNUNET_FS_DownloadContext *parent = cls;
2503 struct GNUNET_BIO_ReadHandle *rh;
2505 ser = get_serialization_short_name (filename);
2506 rh = GNUNET_BIO_read_open (filename);
2509 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2510 _("Failed to resume sub-download `%s': could not open file `%s'\n"),
2516 deserialize_download (parent->h,
2522 GNUNET_BIO_read_close (rh, &emsg))
2524 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2525 _("Failed to resume sub-download `%s': %s\n"),
2536 * Free this download context and all of its descendants.
2537 * (only works during deserialization since not all possible
2538 * state it taken care of).
2540 * @param dc context to free
2543 free_download_context (struct GNUNET_FS_DownloadContext *dc)
2545 struct GNUNET_FS_DownloadContext *dcc;
2546 struct DownloadRequest *dr;
2547 if (dc->meta != NULL)
2548 GNUNET_CONTAINER_meta_data_destroy (dc->meta);
2549 if (dc->uri != NULL)
2550 GNUNET_FS_uri_destroy (dc->uri);
2551 GNUNET_free_non_null (dc->temp_filename);
2552 GNUNET_free_non_null (dc->emsg);
2553 GNUNET_free_non_null (dc->filename);
2554 while (NULL != (dcc = dc->child_head))
2556 GNUNET_CONTAINER_DLL_remove (dc->child_head,
2559 free_download_context (dcc);
2561 while (NULL != (dr = dc->pending))
2563 dc->pending = dr->next;
2571 * Deserialize a download.
2573 * @param h overall context
2574 * @param rh file to deserialize from
2575 * @param parent parent download
2576 * @param search associated search
2577 * @param serialization name under which the search was serialized
2580 deserialize_download (struct GNUNET_FS_Handle *h,
2581 struct GNUNET_BIO_ReadHandle *rh,
2582 struct GNUNET_FS_DownloadContext *parent,
2583 struct GNUNET_FS_SearchResult *search,
2584 const char *serialization)
2586 struct GNUNET_FS_DownloadContext *dc;
2587 struct DownloadRequest *dr;
2593 uint32_t num_pending;
2598 dc = GNUNET_malloc (sizeof (struct GNUNET_FS_DownloadContext));
2599 dc->parent = parent;
2601 dc->serialization = GNUNET_strdup (serialization);
2603 GNUNET_BIO_read_string (rh, "download-uri", &uris, 10*1024)) ||
2604 (NULL == (dc->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
2605 ( (GNUNET_YES != GNUNET_FS_uri_test_chk (dc->uri)) &&
2606 (GNUNET_YES != GNUNET_FS_uri_test_loc (dc->uri)) ) ||
2608 GNUNET_BIO_read_meta_data (rh, "download-meta", &dc->meta)) ||
2610 GNUNET_BIO_read_string (rh, "download-emsg", &dc->emsg, 10*1024)) ||
2612 GNUNET_BIO_read_string (rh, "download-fn", &dc->filename, 10*1024)) ||
2614 GNUNET_BIO_read_string (rh, "download-tfn", &dc->temp_filename, 10*1024)) ||
2616 GNUNET_BIO_read_int64 (rh, &dc->old_file_size)) ||
2618 GNUNET_BIO_read_int64 (rh, &dc->offset)) ||
2620 GNUNET_BIO_read_int64 (rh, &dc->length)) ||
2622 GNUNET_BIO_read_int64 (rh, &dc->completed)) ||
2624 read_start_time (rh, &dc->start_time)) ||
2626 GNUNET_BIO_read_int32 (rh, &dc->anonymity)) ||
2628 GNUNET_BIO_read_int32 (rh, &options)) ||
2630 GNUNET_BIO_read_int32 (rh, &status)) ||
2632 GNUNET_BIO_read_int32 (rh, &num_pending)) )
2637 dc->options = (enum GNUNET_FS_DownloadOptions) options;
2638 dc->active = GNUNET_CONTAINER_multihashmap_create (16);
2639 dc->has_finished = (int) status;
2640 dc->treedepth = GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size (dc->uri));
2641 if (GNUNET_FS_uri_test_loc (dc->uri))
2642 GNUNET_assert (GNUNET_OK ==
2643 GNUNET_FS_uri_loc_get_peer_identity (dc->uri,
2645 if ( (dc->length > dc->completed) &&
2646 (num_pending == 0) )
2651 while (0 < num_pending--)
2653 dr = GNUNET_malloc (sizeof (struct DownloadRequest));
2655 GNUNET_BIO_read (rh, "chk", &dr->chk, sizeof (struct ContentHashKey))) ||
2657 GNUNET_BIO_read_int64 (rh, &dr->offset)) ||
2659 GNUNET_BIO_read_int32 (rh, &dr->depth)) )
2664 dr->is_pending = GNUNET_YES;
2665 dr->next = dc->pending;
2667 GNUNET_CONTAINER_multihashmap_put (dc->active,
2670 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2674 dn = get_download_sync_filename (dc, dc->serialization, ".dir");
2678 GNUNET_DISK_directory_test (dn))
2679 GNUNET_DISK_directory_scan (dn, &deserialize_subdownload, dc);
2684 abort (); // for debugging for now
2685 GNUNET_CONTAINER_DLL_insert (parent->child_head,
2691 dc->search = search;
2692 search->download = dc;
2694 if ( (parent == NULL) &&
2697 dc->top = GNUNET_FS_make_top (dc->h,
2698 &GNUNET_FS_download_signal_suspend_,
2700 signal_download_resume (dc);
2705 GNUNET_free_non_null (uris);
2706 GNUNET_free_non_null (dr);
2707 GNUNET_free_non_null (emsg);
2708 free_download_context (dc);
2713 * Signal resuming of a search to our clients (for the
2714 * top level search and all sub-searches).
2716 * @param sc search being resumed
2719 signal_search_resume (struct GNUNET_FS_SearchContext *sc)
2721 struct GNUNET_FS_ProgressInfo pi;
2723 pi.status = GNUNET_FS_STATUS_SEARCH_RESUME;
2724 pi.value.search.specifics.resume.message = sc->emsg;
2725 pi.value.search.specifics.resume.is_paused = (sc->client == NULL) ? GNUNET_YES : GNUNET_NO;
2726 sc->client_info = GNUNET_FS_search_make_status_ (&pi,
2728 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
2729 &signal_result_resume,
2736 * Deserialize a search.
2738 * @param h overall context
2739 * @param rh file to deserialize from
2740 * @param psearch_result parent search result
2741 * @param serialization name under which the search was serialized
2743 static struct GNUNET_FS_SearchContext *
2744 deserialize_search (struct GNUNET_FS_Handle *h,
2745 struct GNUNET_BIO_ReadHandle *rh,
2746 struct GNUNET_FS_SearchResult *psearch_result,
2747 const char *serialization)
2749 struct GNUNET_FS_SearchContext *sc;
2756 if ( (psearch_result != NULL) &&
2757 (psearch_result->update_search != NULL) )
2764 sc = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchContext));
2765 if (psearch_result != NULL)
2767 sc->psearch_result = psearch_result;
2768 psearch_result->update_search = sc;
2771 sc->serialization = GNUNET_strdup (serialization);
2773 GNUNET_BIO_read_string (rh, "search-uri", &uris, 10*1024)) ||
2774 (NULL == (sc->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
2775 ( (GNUNET_YES != GNUNET_FS_uri_test_ksk (sc->uri)) &&
2776 (GNUNET_YES != GNUNET_FS_uri_test_sks (sc->uri)) ) ||
2778 read_start_time (rh, &sc->start_time)) ||
2780 GNUNET_BIO_read_string (rh, "search-emsg", &sc->emsg, 10*1024)) ||
2782 GNUNET_BIO_read_int32 (rh, &options)) ||
2784 GNUNET_BIO_read (rh, "search-pause", &in_pause, sizeof (in_pause))) ||
2786 GNUNET_BIO_read_int32 (rh, &sc->anonymity)) )
2791 sc->options = (enum GNUNET_FS_SearchOptions) options;
2792 sc->master_result_map = GNUNET_CONTAINER_multihashmap_create (16);
2793 dn = get_serialization_file_name_in_dir (h,
2794 (sc->psearch_result == NULL)
2795 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
2796 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2802 GNUNET_DISK_directory_test (dn))
2803 GNUNET_DISK_directory_scan (dn, &deserialize_search_result, sc);
2806 if ( ('\0' == in_pause) &&
2808 GNUNET_FS_search_start_searching_ (sc)) )
2810 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2811 _("Could not resume running search, will resume as paused search\n"));
2813 signal_search_resume (sc);
2817 GNUNET_free_non_null (emsg);
2818 free_search_context (sc);
2819 GNUNET_free_non_null (uris);
2825 * Function called with a filename of serialized search operation
2828 * @param cls the 'struct GNUNET_FS_Handle*'
2829 * @param filename complete filename (absolute path)
2830 * @return GNUNET_OK (continue to iterate)
2833 deserialize_search_file (void *cls,
2834 const char *filename)
2836 struct GNUNET_FS_Handle *h = cls;
2839 struct GNUNET_BIO_ReadHandle *rh;
2840 struct GNUNET_FS_SearchContext *sc;
2842 ser = get_serialization_short_name (filename);
2843 rh = GNUNET_BIO_read_open (filename);
2848 GNUNET_FS_remove_sync_file_ (h, GNUNET_FS_SYNC_PATH_MASTER_SEARCH, ser);
2853 sc = deserialize_search (h, rh, NULL, ser);
2855 sc->top = GNUNET_FS_make_top (h, &GNUNET_FS_search_signal_suspend_, sc);
2858 GNUNET_BIO_read_close (rh, &emsg))
2860 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2861 _("Failure while resuming search operation `%s': %s\n"),
2871 * Function called with a filename of serialized download operation
2874 * @param cls the 'struct GNUNET_FS_Handle*'
2875 * @param filename complete filename (absolute path)
2876 * @return GNUNET_OK (continue to iterate)
2879 deserialize_download_file (void *cls,
2880 const char *filename)
2882 struct GNUNET_FS_Handle *h = cls;
2885 struct GNUNET_BIO_ReadHandle *rh;
2887 ser = get_serialization_short_name (filename);
2888 rh = GNUNET_BIO_read_open (filename);
2891 if (0 != UNLINK (filename))
2892 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
2898 deserialize_download (h, rh, NULL, NULL, ser);
2901 GNUNET_BIO_read_close (rh, &emsg))
2903 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2904 _("Failure while resuming download operation `%s': %s\n"),
2914 * Deserialize informatin about pending operations.
2916 * @param master_path which master directory should be scanned
2917 * @param proc function to call for each entry (will get 'h' for 'cls')
2918 * @param h the 'struct GNUNET_FS_Handle*'
2921 deserialization_master (const char *master_path,
2922 GNUNET_FileNameCallback proc,
2923 struct GNUNET_FS_Handle *h)
2927 dn = get_serialization_file_name (h, master_path, "");
2931 GNUNET_DISK_directory_test (dn))
2932 GNUNET_DISK_directory_scan (dn, proc, h);
2938 * Setup a connection to the file-sharing service.
2940 * @param sched scheduler to use
2941 * @param cfg configuration to use
2942 * @param client_name unique identifier for this client
2943 * @param upcb function to call to notify about FS actions
2944 * @param upcb_cls closure for upcb
2945 * @param flags specific attributes for fs-operations
2946 * @param ... list of optional options, terminated with GNUNET_FS_OPTIONS_END
2947 * @return NULL on error
2949 struct GNUNET_FS_Handle *
2950 GNUNET_FS_start (struct GNUNET_SCHEDULER_Handle *sched,
2951 const struct GNUNET_CONFIGURATION_Handle *cfg,
2952 const char *client_name,
2953 GNUNET_FS_ProgressCallback upcb,
2955 enum GNUNET_FS_Flags flags,
2958 struct GNUNET_FS_Handle *ret;
2959 enum GNUNET_FS_OPTIONS opt;
2962 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Handle));
2965 ret->client_name = GNUNET_strdup (client_name);
2967 ret->upcb_cls = upcb_cls;
2969 ret->max_parallel_downloads = 1;
2970 ret->max_parallel_requests = 1;
2971 ret->avg_block_latency = GNUNET_TIME_UNIT_MINUTES; /* conservative starting point */
2972 va_start (ap, flags);
2973 while (GNUNET_FS_OPTIONS_END != (opt = va_arg (ap, enum GNUNET_FS_OPTIONS)))
2977 case GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM:
2978 ret->max_parallel_downloads = va_arg (ap, unsigned int);
2980 case GNUNET_FS_OPTIONS_REQUEST_PARALLELISM:
2981 ret->max_parallel_requests = va_arg (ap, unsigned int);
2985 GNUNET_free (ret->client_name);
2992 if (0 != (GNUNET_FS_FLAGS_PERSISTENCE & flags))
2994 deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_PUBLISH,
2995 &deserialize_publish_file,
2997 deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_SEARCH,
2998 &deserialize_search_file,
3000 deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD,
3001 &deserialize_download_file,
3003 deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
3004 &deserialize_unindex_file,
3012 * Close our connection with the file-sharing service.
3013 * The callback given to GNUNET_FS_start will no longer be
3014 * called after this function returns.
3016 * @param h handle that was returned from GNUNET_FS_start
3019 GNUNET_FS_stop (struct GNUNET_FS_Handle *h)
3021 while (h->top_head != NULL)
3022 h->top_head->ssf (h->top_head->ssf_cls);
3023 if (h->queue_job != GNUNET_SCHEDULER_NO_TASK)
3024 GNUNET_SCHEDULER_cancel (h->sched,
3026 GNUNET_free (h->client_name);