GNUnet  0.17.6
fs_api.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2001--2012 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
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  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
27 #include "platform.h"
28 #include "gnunet_util_lib.h"
29 #include "gnunet_fs_service.h"
30 #include "fs_api.h"
31 #include "fs_tree.h"
32 
36 #define DEFAULT_MAX_PARALLEL_REQUESTS (1024 * 10)
37 
41 #define DEFAULT_MAX_PARALLEL_DOWNLOADS 16
42 
49 static void
51 {
52  qe->active = GNUNET_YES;
53  qe->start (qe->cls);
54  qe->start_times++;
55  qe->h->active_blocks += qe->blocks;
56  qe->h->active_downloads++;
57  qe->start_time = GNUNET_TIME_absolute_get ();
59  "Starting job %p (%u active)\n",
60  qe,
61  qe->h->active_downloads);
62  GNUNET_CONTAINER_DLL_remove (qe->h->pending_head, qe->h->pending_tail, qe);
63  GNUNET_CONTAINER_DLL_insert_after (qe->h->running_head,
64  qe->h->running_tail,
65  qe->h->running_tail,
66  qe);
67 }
68 
69 
76 static void
78 {
79  qe->active = GNUNET_NO;
80  qe->stop (qe->cls);
81  GNUNET_assert (0 < qe->h->active_downloads);
82  qe->h->active_downloads--;
83  qe->h->active_blocks -= qe->blocks;
84  qe->run_time = GNUNET_TIME_relative_add (qe->run_time,
86  qe->start_time));
88  "Stopping job %p (%u active)\n",
89  qe,
90  qe->h->active_downloads);
91  GNUNET_CONTAINER_DLL_remove (qe->h->running_head, qe->h->running_tail, qe);
92  GNUNET_CONTAINER_DLL_insert_after (qe->h->pending_head,
93  qe->h->pending_tail,
94  qe->h->pending_tail,
95  qe);
96 }
97 
98 
105 static void
106 process_job_queue (void *cls)
107 {
108  struct GNUNET_FS_Handle *h = cls;
109  struct GNUNET_FS_QueueEntry *qe;
110  struct GNUNET_FS_QueueEntry *next;
111  struct GNUNET_TIME_Relative run_time;
112  struct GNUNET_TIME_Relative restart_at;
113  struct GNUNET_TIME_Relative rst;
115  unsigned int num_downloads_waiting;
116  unsigned int num_downloads_active;
117  unsigned int num_downloads_expired;
118  unsigned int num_probes_active;
119  unsigned int num_probes_waiting;
120  unsigned int num_probes_expired;
121  int num_probes_change;
122  int num_downloads_change;
123  int block_limit_hit;
124 
125  h->queue_job = NULL;
126  /* restart_at will be set to the time when it makes sense to
127  re-evaluate the job queue (unless, of course, jobs complete
128  or are added, then we'll be triggered immediately */
129  restart_at = GNUNET_TIME_UNIT_FOREVER_REL;
130  /* first, calculate some basic statistics on pending jobs */
131  num_probes_waiting = 0;
132  num_downloads_waiting = 0;
133  for (qe = h->pending_head; NULL != qe; qe = qe->next)
134  {
135  switch (qe->priority)
136  {
138  num_probes_waiting++;
139  break;
140 
142  num_downloads_waiting++;
143  break;
144 
145  default:
146  GNUNET_break (0);
147  break;
148  }
149  }
150  /* now, calculate some basic statistics on running jobs */
151  num_probes_active = 0;
152  num_probes_expired = 0;
153  num_downloads_active = 0;
154  num_downloads_expired = 0;
155  next = h->running_head;
156  while (NULL != (qe = next))
157  {
158  next = qe->next;
159  switch (qe->priority)
160  {
163  end_time = GNUNET_TIME_absolute_add (qe->start_time, run_time);
165  if (0 == rst.rel_value_us)
166  {
167  num_probes_expired++;
168  stop_job (qe);
169  }
170  else
171  {
172  num_probes_active++;
173  restart_at = GNUNET_TIME_relative_min (rst, restart_at);
174  }
175  break;
176 
178  run_time =
179  GNUNET_TIME_relative_saturating_multiply (h->avg_block_latency,
180  qe->blocks * qe->start_times);
181  end_time = GNUNET_TIME_absolute_add (qe->start_time, run_time);
183  if (0 == rst.rel_value_us)
184  {
185  num_downloads_expired++;
186  stop_job (qe);
187  }
188  else
189  {
190  num_downloads_active++;
191  restart_at = GNUNET_TIME_relative_min (rst, restart_at);
192  }
193  break;
194 
195  default:
196  GNUNET_break (0);
197  break;
198  }
199  }
200  GNUNET_break (h->active_downloads ==
201  num_downloads_active + num_probes_active);
203  "PA: %u, PE: %u, PW: %u; DA: %u, DE: %u, DW: %u\n",
204  num_probes_active,
205  num_probes_expired,
206  num_probes_waiting,
207  num_downloads_active,
208  num_downloads_expired,
209  num_downloads_waiting);
210  GNUNET_break (h->active_downloads + num_probes_active <=
211  h->max_parallel_downloads);
212  /* calculate start/stop decisions */
213  if (h->active_downloads + num_downloads_waiting > h->max_parallel_downloads)
214  {
215  /* stop as many probes as there are downloads and probes */
216  num_probes_change = -GNUNET_MIN (num_probes_active, num_downloads_waiting);
217  /* start as many downloads as there are free slots, including those
218  we just opened up */
219  num_downloads_change =
220  h->max_parallel_downloads - h->active_downloads - num_probes_change;
221  }
222  else
223  {
224  /* start all downloads (we can) */
225  num_downloads_change = num_downloads_waiting;
226  /* also start probes if there is room, but use a lower cap of (mpd/4) + 1 */
227  if (1 + h->max_parallel_downloads / 4 >=
228  (h->active_downloads + num_downloads_change))
229  num_probes_change =
230  GNUNET_MIN (num_probes_waiting,
231  (1 + h->max_parallel_downloads / 4)
232  - (h->active_downloads + num_downloads_change));
233  else
234  num_probes_change = 0;
235  }
236  GNUNET_break (num_downloads_change <= num_downloads_waiting);
238  "Changing %d probes and %d/%u/%u downloads\n",
239  num_probes_change,
240  num_downloads_change,
241  (unsigned int) h->active_downloads,
242  (unsigned int) h->max_parallel_downloads);
243  /* actually stop probes */
244  next = h->running_head;
245  while (NULL != (qe = next))
246  {
247  next = qe->next;
249  continue;
250  if (num_probes_change < 0)
251  {
252  stop_job (qe);
253  num_probes_change++;
254  if (0 == num_probes_change)
255  break;
256  }
257  }
258  GNUNET_break (0 <= num_probes_change);
259 
260  /* start some more tasks if we now have empty slots */
261  block_limit_hit = GNUNET_NO;
262  next = h->pending_head;
263  while ((NULL != (qe = next)) &&
264  ((num_probes_change > 0) || (num_downloads_change > 0)))
265  {
266  next = qe->next;
267  switch (qe->priority)
268  {
270  if (num_probes_change > 0)
271  {
272  start_job (qe);
273  num_probes_change--;
275  restart_at = GNUNET_TIME_relative_min (run_time, restart_at);
276  }
277  break;
278 
280  if ((num_downloads_change > 0) &&
281  ((qe->blocks + h->active_blocks <= h->max_parallel_requests) ||
282  ((qe->blocks > h->max_parallel_requests) &&
283  (0 == h->active_downloads))))
284  {
285  start_job (qe);
286  num_downloads_change--;
287  }
288  else if (num_downloads_change > 0)
289  block_limit_hit = GNUNET_YES;
290  break;
291 
292  default:
293  GNUNET_break (0);
294  break;
295  }
296  }
297  GNUNET_break ((0 == num_downloads_change) || (GNUNET_YES == block_limit_hit));
298  GNUNET_break (0 == num_probes_change);
299 
300  GNUNET_log (
302  "AD: %u, MP: %u; %d probes and %d downloads to start, will run again in %s\n",
303  h->active_downloads,
304  h->max_parallel_requests,
305  num_probes_change,
306  num_downloads_change,
308 
309  /* make sure we run again, callbacks might have
310  already re-scheduled the job, so cancel such
311  an operation (if it exists) */
312  if (NULL != h->queue_job)
313  GNUNET_SCHEDULER_cancel (h->queue_job);
314  h->queue_job =
316 }
317 
318 
319 struct GNUNET_FS_QueueEntry *
323  void *cls,
324  unsigned int blocks,
326 {
327  struct GNUNET_FS_QueueEntry *qe;
328 
330  qe->h = h;
331  qe->start = start;
332  qe->stop = stop;
333  qe->cls = cls;
334  qe->queue_time = GNUNET_TIME_absolute_get ();
335  qe->blocks = blocks;
336  qe->priority = priority;
337  GNUNET_CONTAINER_DLL_insert_after (h->pending_head,
338  h->pending_tail,
339  h->pending_tail,
340  qe);
341  if (NULL != h->queue_job)
342  GNUNET_SCHEDULER_cancel (h->queue_job);
344  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Queueing job %p\n", qe);
345  return qe;
346 }
347 
348 
354 void
356 {
357  struct GNUNET_FS_Handle *h;
358 
359  h = qe->h;
360  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Dequeueing job %p\n", qe);
361  if (GNUNET_YES == qe->active)
362  stop_job (qe);
363  GNUNET_CONTAINER_DLL_remove (h->pending_head, h->pending_tail, qe);
364  GNUNET_free (qe);
365  if (NULL != h->queue_job)
366  GNUNET_SCHEDULER_cancel (h->queue_job);
368 }
369 
370 
379 struct TopLevelActivity *
382  void *ssf_cls)
383 {
384  struct TopLevelActivity *ret;
385 
386  ret = GNUNET_new (struct TopLevelActivity);
387  ret->ssf = ssf;
388  ret->ssf_cls = ssf_cls;
389  GNUNET_CONTAINER_DLL_insert (h->top_head, h->top_tail, ret);
390  return ret;
391 }
392 
393 
400 void
402 {
403  GNUNET_CONTAINER_DLL_remove (h->top_head, h->top_tail, top);
404  GNUNET_free (top);
405 }
406 
407 
411 struct FileInfo
412 {
416  char *filename;
417 
422 };
423 
424 
445 size_t
447  uint64_t offset,
448  size_t max,
449  void *buf,
450  char **emsg)
451 {
452  struct FileInfo *fi = cls;
453  ssize_t ret;
454 
455  if (UINT64_MAX == offset)
456  {
457  if (NULL != fi->fd)
458  {
460  fi->fd = NULL;
461  }
462  return 0;
463  }
464  if (0 == max)
465  {
466  if (NULL != fi->fd)
468  GNUNET_free (fi->filename);
469  GNUNET_free (fi);
470  return 0;
471  }
472  if (NULL == fi->fd)
473  {
474  fi->fd = GNUNET_DISK_file_open (fi->filename,
477  if (NULL == fi->fd)
478  {
479  GNUNET_asprintf (emsg,
480  _ ("Could not open file `%s': %s"),
481  fi->filename,
482  strerror (errno));
483  return 0;
484  }
485  }
486  if ((GNUNET_SYSERR ==
488  (-1 == (ret = GNUNET_DISK_file_read (fi->fd, buf, max))))
489  {
490  GNUNET_asprintf (emsg,
491  _ ("Could not read file `%s': %s"),
492  fi->filename,
493  strerror (errno));
494  return 0;
495  }
496  if (ret != max)
497  {
498  GNUNET_asprintf (emsg,
499  _ ("Short read reading from file `%s'!"),
500  fi->filename);
501  return 0;
502  }
503  return max;
504 }
505 
506 
507 void *
509 {
510  struct FileInfo *fi;
511 
512  fi = GNUNET_new (struct FileInfo);
514  if (NULL == fi->filename)
515  {
516  GNUNET_free (fi);
517  return NULL;
518  }
519  return fi;
520 }
521 
522 
543 size_t
545  uint64_t offset,
546  size_t max,
547  void *buf,
548  char **emsg)
549 {
550  char *data = cls;
551 
552  if (UINT64_MAX == offset)
553  return 0;
554  if (0 == max)
555  {
556  GNUNET_free (data);
557  return 0;
558  }
559  GNUNET_memcpy (buf, &data[offset], max);
560  return max;
561 }
562 
563 
573 static char *
575  const char *ext,
576  const char *ent)
577 {
578  char *basename;
579  char *ret;
580 
581  if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
582  return NULL; /* persistence not requested */
584  "fs",
585  "STATE_DIR",
586  &basename))
587  return NULL;
589  "%s%s%s%s%s%s%s",
590  basename,
592  h->client_name,
594  ext,
596  ent);
597  GNUNET_free (basename);
598  return ret;
599 }
600 
601 
613 static char *
615  const char *ext,
616  const char *uni,
617  const char *ent)
618 {
619  char *basename;
620  char *ret;
621 
622  if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
623  return NULL; /* persistence not requested */
625  "fs",
626  "STATE_DIR",
627  &basename))
628  return NULL;
630  "%s%s%s%s%s%s%s.dir%s%s",
631  basename,
633  h->client_name,
635  ext,
637  uni,
639  ent);
640  GNUNET_free (basename);
641  return ret;
642 }
643 
644 
653 static struct GNUNET_BIO_ReadHandle *
654 get_read_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
655 {
656  char *fn;
657  struct GNUNET_BIO_ReadHandle *ret;
658 
659  fn = get_serialization_file_name (h, ext, ent);
660  if (NULL == fn)
661  return NULL;
663  GNUNET_free (fn);
664  return ret;
665 }
666 
667 
676 static struct GNUNET_BIO_WriteHandle *
677 get_write_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
678 {
679  char *fn;
680  struct GNUNET_BIO_WriteHandle *ret;
681 
682  fn = get_serialization_file_name (h, ext, ent);
683  if (NULL == fn)
684  return NULL;
686  GNUNET_break (NULL != ret);
687  GNUNET_free (fn);
688  return ret;
689 }
690 
691 
701 static struct GNUNET_BIO_WriteHandle *
703  const char *ext,
704  const char *uni,
705  const char *ent)
706 {
707  char *fn;
708  struct GNUNET_BIO_WriteHandle *ret;
709 
710  fn = get_serialization_file_name_in_dir (h, ext, uni, ent);
711  if (NULL == fn)
712  return NULL;
714  GNUNET_free (fn);
715  return ret;
716 }
717 
718 
726 void
728  const char *ext,
729  const char *ent)
730 {
731  char *filename;
732 
733  if ((NULL == ent) || (0 == strlen (ent)))
734  {
735  GNUNET_break (0);
736  return;
737  }
738  filename = get_serialization_file_name (h, ext, ent);
739  if (NULL != filename)
740  {
741  if ((0 != unlink (filename)) && (ENOENT != errno))
744  }
745 }
746 
747 
756 static void
758  const char *ext,
759  const char *uni,
760  const char *ent)
761 {
762  char *filename;
763 
764  if ((NULL == ent) || (0 == strlen (ent)))
765  {
766  GNUNET_break (0);
767  return;
768  }
769  filename = get_serialization_file_name_in_dir (h, ext, uni, ent);
770  if (NULL == filename)
771  return;
772  if (0 != unlink (filename))
775 }
776 
777 
785 void
787  const char *ext,
788  const char *uni)
789 {
790  char *dn;
791 
792  if (NULL == uni)
793  return;
794  dn = get_serialization_file_name_in_dir (h, ext, uni, "");
795  if (NULL == dn)
796  return;
800  GNUNET_free (dn);
801 }
802 
803 
818 static int
820  struct GNUNET_TIME_Absolute timestamp)
821 {
822  struct GNUNET_TIME_Relative dur;
823 
824  dur = GNUNET_TIME_absolute_get_duration (timestamp);
825  return GNUNET_BIO_write_int64 (wh, "start time", dur.rel_value_us);
826 }
827 
828 
843 static int
845  struct GNUNET_TIME_Absolute *timestamp)
846 {
847  struct GNUNET_TIME_Relative dur;
848 
849  if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, "start time",
850  (int64_t *) &dur.rel_value_us))
851  return GNUNET_SYSERR;
853  return GNUNET_OK;
854 }
855 
856 
866 static struct GNUNET_FS_FileInformation *
868 
869 
880 static struct GNUNET_FS_FileInformation *
882  const char *fn,
883  struct GNUNET_BIO_ReadHandle *rh)
884 {
886  struct GNUNET_FS_FileInformation *nxt;
887  char b;
888  char *ksks;
889  char *chks;
890  char *skss;
891  char *filename;
892  uint32_t dsize;
893 
894  if (GNUNET_OK != GNUNET_BIO_read (rh, "status flag", &b, sizeof(b)))
895  {
896  GNUNET_break (0);
897  return NULL;
898  }
900  ret->h = h;
901  ksks = NULL;
902  chks = NULL;
903  skss = NULL;
904  filename = NULL;
905  if ((GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "metadata", &ret->meta)) ||
906  (GNUNET_OK != GNUNET_BIO_read_string (rh, "ksk-uri", &ksks, 32 * 1024)) ||
907  ((NULL != ksks) &&
908  ((NULL == (ret->keywords = GNUNET_FS_uri_parse (ksks, NULL))) ||
909  (GNUNET_YES != GNUNET_FS_uri_test_ksk (ret->keywords)))) ||
910  (GNUNET_OK != GNUNET_BIO_read_string (rh, "chk-uri", &chks, 1024)) ||
911  ((NULL != chks) &&
912  ((NULL == (ret->chk_uri = GNUNET_FS_uri_parse (chks, NULL))) ||
913  (GNUNET_YES != GNUNET_FS_uri_test_chk (ret->chk_uri)))) ||
914  (GNUNET_OK != GNUNET_BIO_read_string (rh, "sks-uri", &skss, 1024)) ||
915  ((NULL != skss) &&
916  ((NULL == (ret->sks_uri = GNUNET_FS_uri_parse (skss, NULL))) ||
917  (GNUNET_YES != GNUNET_FS_uri_test_sks (ret->sks_uri)))) ||
918  (GNUNET_OK != read_start_time (rh, &ret->start_time)) ||
919  (GNUNET_OK !=
920  GNUNET_BIO_read_string (rh, "emsg", &ret->emsg, 16 * 1024)) ||
921  (GNUNET_OK !=
922  GNUNET_BIO_read_string (rh, "fn", &ret->filename, 16 * 1024)) ||
923  (GNUNET_OK !=
925  rh,
926  "expiration time",
927  (int64_t *) &ret->bo.expiration_time.abs_value_us)) ||
929  rh,
930  "anonymity level",
931  (int32_t *) &ret->bo.anonymity_level)) ||
933  rh,
934  "content priority",
935  (int32_t *) &ret->bo.content_priority)) ||
937  rh,
938  "replication level",
939  (int32_t *) &ret->bo.replication_level)))
940  {
941  GNUNET_break (0);
942  goto cleanup;
943  }
944  switch (b)
945  {
946  case 0: /* file-insert */
948  rh,
949  "file size",
950  (int64_t *) &ret->data.file.file_size))
951  {
952  GNUNET_break (0);
953  goto cleanup;
954  }
955  ret->is_directory = GNUNET_NO;
956  ret->data.file.do_index = GNUNET_NO;
957  ret->data.file.have_hash = GNUNET_NO;
958  ret->data.file.index_start_confirmed = GNUNET_NO;
959  if (GNUNET_NO == ret->is_published)
960  {
961  if (NULL == ret->filename)
962  {
963  ret->data.file.reader = &GNUNET_FS_data_reader_copy_;
964  ret->data.file.reader_cls =
965  GNUNET_malloc_large (ret->data.file.file_size);
966  if (ret->data.file.reader_cls == NULL)
967  goto cleanup;
968  if (GNUNET_OK != GNUNET_BIO_read (rh,
969  "file-data",
970  ret->data.file.reader_cls,
971  ret->data.file.file_size))
972  {
973  GNUNET_break (0);
974  goto cleanup;
975  }
976  }
977  else
978  {
979  ret->data.file.reader = &GNUNET_FS_data_reader_file_;
980  ret->data.file.reader_cls =
982  }
983  }
984  break;
985 
986  case 1: /* file-index, no hash */
987  if (NULL == ret->filename)
988  {
989  GNUNET_break (0);
990  goto cleanup;
991  }
993  rh,
994  "file size",
995  (int64_t *) &ret->data.file.file_size))
996  {
997  GNUNET_break (0);
998  goto cleanup;
999  }
1000  ret->is_directory = GNUNET_NO;
1001  ret->data.file.do_index = GNUNET_YES;
1002  ret->data.file.have_hash = GNUNET_NO;
1003  ret->data.file.index_start_confirmed = GNUNET_NO;
1004  ret->data.file.reader = &GNUNET_FS_data_reader_file_;
1005  ret->data.file.reader_cls =
1007  break;
1008 
1009  case 2: /* file-index-with-hash */
1010  if (NULL == ret->filename)
1011  {
1012  GNUNET_break (0);
1013  goto cleanup;
1014  }
1016  rh,
1017  "file size",
1018  (int64_t *) &ret->data.file.file_size)) ||
1019  (GNUNET_OK != GNUNET_BIO_read (rh,
1020  "fileid",
1021  &ret->data.file.file_id,
1022  sizeof(struct GNUNET_HashCode))))
1023  {
1024  GNUNET_break (0);
1025  goto cleanup;
1026  }
1027  ret->is_directory = GNUNET_NO;
1028  ret->data.file.do_index = GNUNET_YES;
1029  ret->data.file.have_hash = GNUNET_YES;
1030  ret->data.file.index_start_confirmed = GNUNET_NO;
1031  ret->data.file.reader = &GNUNET_FS_data_reader_file_;
1032  ret->data.file.reader_cls =
1034  break;
1035 
1036  case 3: /* file-index-with-hash-confirmed */
1037  if (NULL == ret->filename)
1038  {
1039  GNUNET_break (0);
1040  goto cleanup;
1041  }
1043  rh,
1044  "file size",
1045  (int64_t *) &ret->data.file.file_size)) ||
1046  (GNUNET_OK != GNUNET_BIO_read (rh,
1047  "fileid",
1048  &ret->data.file.file_id,
1049  sizeof(struct GNUNET_HashCode))))
1050  {
1051  GNUNET_break (0);
1052  goto cleanup;
1053  }
1054  ret->is_directory = GNUNET_NO;
1055  ret->data.file.do_index = GNUNET_YES;
1056  ret->data.file.have_hash = GNUNET_YES;
1057  ret->data.file.index_start_confirmed = GNUNET_YES;
1058  ret->data.file.reader = &GNUNET_FS_data_reader_file_;
1059  ret->data.file.reader_cls =
1061  break;
1062 
1063  case 4: /* directory */
1064  ret->is_directory = GNUNET_YES;
1065  if ((GNUNET_OK != GNUNET_BIO_read_int32 (rh, "dsize",
1066  (int32_t *) &dsize)) ||
1067  (GNUNET_OK !=
1069  rh,
1070  "contents completed",
1071  (int64_t *) &ret->data.dir.contents_completed)) ||
1072  (GNUNET_OK !=
1074  rh,
1075  "contents size",
1076  (int64_t *) &ret->data.dir.contents_size)) ||
1077  (NULL == (ret->data.dir.dir_data = GNUNET_malloc_large (dsize))) ||
1078  (GNUNET_OK !=
1079  GNUNET_BIO_read (rh, "dir-data", ret->data.dir.dir_data, dsize)) ||
1080  (GNUNET_OK !=
1081  GNUNET_BIO_read_string (rh, "ent-filename", &filename, 16 * 1024)))
1082  {
1083  GNUNET_break (0);
1084  goto cleanup;
1085  }
1086  ret->data.dir.dir_size = (uint32_t) dsize;
1087  if (NULL != filename)
1088  {
1089  ret->data.dir.entries = deserialize_file_information (h, filename);
1091  filename = NULL;
1092  nxt = ret->data.dir.entries;
1093  while (NULL != nxt)
1094  {
1095  nxt->dir = ret;
1096  nxt = nxt->next;
1097  }
1098  }
1099  break;
1100 
1101  default:
1102  GNUNET_break (0);
1103  goto cleanup;
1104  }
1105  ret->serialization = GNUNET_strdup (fn);
1106  if (GNUNET_OK !=
1107  GNUNET_BIO_read_string (rh, "nxt-filename", &filename, 16 * 1024))
1108  {
1109  GNUNET_break (0);
1110  goto cleanup;
1111  }
1112  if (NULL != filename)
1113  {
1116  filename = NULL;
1117  }
1118  GNUNET_free (ksks);
1119  GNUNET_free (skss);
1120  GNUNET_free (chks);
1121  return ret;
1122 cleanup:
1123  GNUNET_free (ksks);
1124  GNUNET_free (chks);
1125  GNUNET_free (skss);
1128  return NULL;
1129 }
1130 
1131 
1141 static struct GNUNET_FS_FileInformation *
1143 {
1145  struct GNUNET_BIO_ReadHandle *rh;
1146  char *emsg;
1147  char *fn;
1148 
1150  if (NULL == rh)
1151  return NULL;
1152  ret = deserialize_fi_node (h, filename, rh);
1153  if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
1154  {
1156  _ ("Failed to resume publishing information `%s': %s\n"),
1157  filename,
1158  emsg);
1159  GNUNET_free (emsg);
1160  }
1161  if (NULL == ret)
1162  {
1163  fn =
1165  if (NULL != fn)
1166  {
1167  if (0 != unlink (fn))
1169  GNUNET_free (fn);
1170  }
1171  }
1172  return ret;
1173 }
1174 
1175 
1184 static char *
1185 get_serialization_short_name (const char *fullname)
1186 {
1187  const char *end;
1188  const char *nxt;
1189 
1190  end = NULL;
1191  nxt = fullname;
1192  /* FIXME: we could do this faster since we know
1193  * the length of 'end'... */
1194  while ('\0' != *nxt)
1195  {
1196  if (DIR_SEPARATOR == *nxt)
1197  end = nxt + 1;
1198  nxt++;
1199  }
1200  if ((NULL == end) || (0 == strlen (end)))
1201  {
1202  GNUNET_break (0);
1203  return NULL;
1204  }
1205  GNUNET_break (6 == strlen (end));
1206  return GNUNET_strdup (end);
1207 }
1208 
1209 
1218 static char *
1220 {
1221  char *fn;
1222  char *dn;
1223  char *ret;
1224 
1225  if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
1226  return NULL; /* persistence not requested */
1227  dn = get_serialization_file_name (h, ext, "");
1228  if (NULL == dn)
1229  return NULL;
1231  {
1232  GNUNET_free (dn);
1233  return NULL;
1234  }
1235  fn = GNUNET_DISK_mktemp (dn);
1236  GNUNET_free (dn);
1237  if (NULL == fn)
1238  return NULL; /* epic fail */
1240  GNUNET_free (fn);
1241  return ret;
1242 }
1243 
1244 
1254 static char *
1256  const char *ext,
1257  const char *uni)
1258 {
1259  char *fn;
1260  char *dn;
1261  char *ret;
1262 
1263  if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
1264  return NULL; /* persistence not requested */
1265  dn = get_serialization_file_name_in_dir (h, ext, uni, "");
1266  if (NULL == dn)
1267  return NULL;
1269  {
1270  GNUNET_free (dn);
1271  return NULL;
1272  }
1273  fn = GNUNET_DISK_mktemp (dn);
1274  GNUNET_free (dn);
1275  if (NULL == fn)
1276  return NULL; /* epic fail */
1278  GNUNET_free (fn);
1279  return ret;
1280 }
1281 
1282 
1290 static int
1292  struct GNUNET_FS_FileInformation *fi)
1293 {
1294  char buf[32 * 1024];
1295  uint64_t off;
1296  size_t ret;
1297  size_t left;
1298  char *emsg;
1299 
1300  emsg = NULL;
1301  off = 0;
1302  while (off < fi->data.file.file_size)
1303  {
1304  left = GNUNET_MIN (sizeof(buf), fi->data.file.file_size - off);
1305  ret =
1306  fi->data.file.reader (fi->data.file.reader_cls, off, left, buf, &emsg);
1307  if (0 == ret)
1308  {
1309  GNUNET_free (emsg);
1310  return GNUNET_SYSERR;
1311  }
1312  if (GNUNET_OK != GNUNET_BIO_write (wh, "copied from reader", buf, ret))
1313  return GNUNET_SYSERR;
1314  off += ret;
1315  }
1316  return GNUNET_OK;
1317 }
1318 
1319 
1326 void
1328 {
1329  char *fn;
1330  struct GNUNET_BIO_WriteHandle *wh;
1331  char b;
1332  char *ksks;
1333  char *chks;
1334  char *skss;
1335 
1336  if (NULL == fi->serialization)
1337  fi->serialization =
1339  if (NULL == fi->serialization)
1340  return;
1341  wh =
1343  if (NULL == wh)
1344  {
1345  GNUNET_free (fi->serialization);
1346  fi->serialization = NULL;
1347  return;
1348  }
1349  if (GNUNET_YES == fi->is_directory)
1350  b = 4;
1351  else if (GNUNET_YES == fi->data.file.index_start_confirmed)
1352  b = 3;
1353  else if (GNUNET_YES == fi->data.file.have_hash)
1354  b = 2;
1355  else if (GNUNET_YES == fi->data.file.do_index)
1356  b = 1;
1357  else
1358  b = 0;
1359  if (NULL != fi->keywords)
1360  ksks = GNUNET_FS_uri_to_string (fi->keywords);
1361  else
1362  ksks = NULL;
1363  if (NULL != fi->chk_uri)
1364  chks = GNUNET_FS_uri_to_string (fi->chk_uri);
1365  else
1366  chks = NULL;
1367  if (NULL != fi->sks_uri)
1368  skss = GNUNET_FS_uri_to_string (fi->sks_uri);
1369  else
1370  skss = NULL;
1371  struct GNUNET_BIO_WriteSpec ws1[] = {
1372  GNUNET_BIO_write_spec_object ("b", &b, sizeof (b)),
1373  GNUNET_BIO_write_spec_meta_data ("meta", fi->meta),
1374  GNUNET_BIO_write_spec_string ("ksks", ksks),
1375  GNUNET_BIO_write_spec_string ("chks", chks),
1376  GNUNET_BIO_write_spec_string ("skss", skss),
1378  };
1379  struct GNUNET_BIO_WriteSpec ws2[] = {
1380  GNUNET_BIO_write_spec_string ("emsg", fi->emsg),
1381  GNUNET_BIO_write_spec_string ("filename", fi->filename),
1383  "expiration time",
1384  (int64_t *) &fi->bo.expiration_time.abs_value_us),
1386  "anonymity level",
1387  (int32_t *) &fi->bo.anonymity_level),
1389  "content priority",
1390  (int32_t *) &fi->bo.content_priority),
1392  "replication level",
1393  (int32_t *) &fi->bo.replication_level),
1395  };
1396  if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws1)) ||
1397  (GNUNET_OK != write_start_time (wh, fi->start_time)) ||
1399  {
1400  GNUNET_break (0);
1401  goto cleanup;
1402  }
1403  GNUNET_free (chks);
1404  chks = NULL;
1405  GNUNET_free (ksks);
1406  ksks = NULL;
1407  GNUNET_free (skss);
1408  skss = NULL;
1409 
1410  switch (b)
1411  {
1412  case 0: /* file-insert */
1413  if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, "file size",
1414  fi->data.file.file_size))
1415  {
1416  GNUNET_break (0);
1417  goto cleanup;
1418  }
1419  if ((GNUNET_NO == fi->is_published) && (NULL == fi->filename))
1420  if (GNUNET_OK != copy_from_reader (wh, fi))
1421  {
1422  GNUNET_break (0);
1423  goto cleanup;
1424  }
1425  break;
1426 
1427  case 1: /* file-index, no hash */
1428  if (NULL == fi->filename)
1429  {
1430  GNUNET_break (0);
1431  goto cleanup;
1432  }
1433  if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, "file size",
1434  fi->data.file.file_size))
1435  {
1436  GNUNET_break (0);
1437  goto cleanup;
1438  }
1439  break;
1440 
1441  case 2: /* file-index-with-hash */
1442  case 3: /* file-index-with-hash-confirmed */
1443  if (NULL == fi->filename)
1444  {
1445  GNUNET_break (0);
1446  goto cleanup;
1447  }
1448  if ((GNUNET_OK != GNUNET_BIO_write_int64 (wh, "file size",
1449  fi->data.file.file_size)) ||
1451  "file id",
1452  &fi->data.file.file_id,
1453  sizeof(struct GNUNET_HashCode))))
1454  {
1455  GNUNET_break (0);
1456  goto cleanup;
1457  }
1458  break;
1459 
1460  case 4: /* directory */
1461  if ((NULL != fi->data.dir.entries) &&
1462  (NULL == fi->data.dir.entries->serialization))
1464  struct GNUNET_BIO_WriteSpec ws[] = {
1465  GNUNET_BIO_write_spec_int32 ("dir size",
1466  (int32_t *) &fi->data.dir.dir_size),
1468  "contents completed",
1469  (int64_t *) &fi->data.dir.contents_completed),
1470  GNUNET_BIO_write_spec_int64 ("contents size",
1471  (int64_t *) &fi->data.dir.contents_size),
1472  GNUNET_BIO_write_spec_object ("dir data",
1473  fi->data.dir.dir_data,
1474  (uint32_t) fi->data.dir.dir_size),
1475  GNUNET_BIO_write_spec_string ("dir entries",
1476  (fi->data.dir.entries == NULL)
1477  ? NULL
1478  : fi->data.dir.entries->serialization),
1480  };
1481  if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws)))
1482  {
1483  GNUNET_break (0);
1484  goto cleanup;
1485  }
1486  break;
1487 
1488  default:
1489  GNUNET_assert (0);
1490  goto cleanup;
1491  }
1492  if ((NULL != fi->next) && (NULL == fi->next->serialization))
1495  "serialization",
1496  (fi->next != NULL)
1497  ? fi->next->serialization
1498  : NULL))
1499  {
1500  GNUNET_break (0);
1501  goto cleanup;
1502  }
1503  if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
1504  {
1505  wh = NULL;
1506  GNUNET_break (0);
1507  goto cleanup;
1508  }
1509  return; /* done! */
1510 cleanup:
1511  if (NULL != wh)
1512  (void) GNUNET_BIO_write_close (wh, NULL);
1513  GNUNET_free (chks);
1514  GNUNET_free (ksks);
1515  GNUNET_free (skss);
1516  fn = get_serialization_file_name (fi->h,
1518  fi->serialization);
1519  if (NULL != fn)
1520  {
1521  if (0 != unlink (fn))
1523  GNUNET_free (fn);
1524  }
1525  GNUNET_free (fi->serialization);
1526  fi->serialization = NULL;
1527 }
1528 
1529 
1538 static struct GNUNET_FS_FileInformation *
1539 find_file_position (struct GNUNET_FS_FileInformation *pos, const char *srch)
1540 {
1541  struct GNUNET_FS_FileInformation *r;
1542 
1543  while (NULL != pos)
1544  {
1545  if (0 == strcmp (srch, pos->serialization))
1546  return pos;
1547  if ((GNUNET_YES == pos->is_directory) &&
1548  (NULL != (r = find_file_position (pos->data.dir.entries, srch))))
1549  return r;
1550  pos = pos->next;
1551  }
1552  return NULL;
1553 }
1554 
1555 
1570 static int
1572  struct GNUNET_FS_FileInformation *fi,
1573  uint64_t length,
1575  struct GNUNET_FS_Uri **uri,
1576  struct GNUNET_FS_BlockOptions *bo,
1577  int *do_index,
1578  void **client_info)
1579 {
1580  struct GNUNET_FS_PublishContext *pc = cls;
1581  struct GNUNET_FS_ProgressInfo pi;
1582 
1584  {
1586  return GNUNET_OK;
1587  }
1589  pi.value.publish.specifics.resume.message = fi->emsg;
1590  pi.value.publish.specifics.resume.chk_uri = fi->chk_uri;
1591  *client_info = GNUNET_FS_publish_make_status_ (&pi, pc, fi, 0);
1593  {
1594  /* process entries in directory */
1597  }
1598  return GNUNET_OK;
1599 }
1600 
1601 
1610 static int
1611 deserialize_publish_file (void *cls, const char *filename)
1612 {
1613  struct GNUNET_FS_Handle *h = cls;
1614  struct GNUNET_BIO_ReadHandle *rh;
1615  struct GNUNET_FS_PublishContext *pc;
1616  int32_t options;
1617  int32_t all_done;
1618  int32_t have_ns;
1619  char *fi_root;
1621  char *fi_pos;
1622  char *emsg;
1623 
1625  pc->h = h;
1627  fi_root = NULL;
1628  fi_pos = NULL;
1630  if (NULL == rh)
1631  {
1632  GNUNET_break (0);
1633  goto cleanup;
1634  }
1635  struct GNUNET_BIO_ReadSpec rs[] = {
1636  GNUNET_BIO_read_spec_string ("publish-nid", &pc->nid, 1024),
1637  GNUNET_BIO_read_spec_string ("publish-nuid", &pc->nuid, 1024),
1638  GNUNET_BIO_read_spec_int32 ("options", &options),
1639  GNUNET_BIO_read_spec_int32 ("all done", &all_done),
1640  GNUNET_BIO_read_spec_int32 ("have ns", &have_ns),
1641  GNUNET_BIO_read_spec_string ("publish-firoot", &fi_root, 128),
1642  GNUNET_BIO_read_spec_string ("publish-fipos", &fi_pos, 128),
1644  };
1645  if ((GNUNET_OK != GNUNET_BIO_read_spec_commit (rh, rs)) ||
1646  ((GNUNET_YES == have_ns) &&
1647  (GNUNET_OK != GNUNET_BIO_read (rh, "publish-ns", &ns, sizeof(ns)))))
1648  {
1649  GNUNET_break (0);
1650  goto cleanup;
1651  }
1652  pc->options = options;
1653  pc->all_done = all_done;
1654  if (NULL == fi_root)
1655  {
1656  GNUNET_break (0);
1657  goto cleanup;
1658  }
1659  pc->fi = deserialize_file_information (h, fi_root);
1660  if (NULL == pc->fi)
1661  {
1662  GNUNET_break (0);
1663  goto cleanup;
1664  }
1665  if (GNUNET_YES == have_ns)
1666  {
1668  *pc->ns = ns;
1669  }
1671  (GNUNET_YES != pc->all_done))
1672  {
1674  if (NULL == pc->dsh)
1675  goto cleanup;
1676  }
1677  if (NULL != fi_pos)
1678  {
1679  pc->fi_pos = find_file_position (pc->fi, fi_pos);
1680  GNUNET_free (fi_pos);
1681  fi_pos = NULL;
1682  if (NULL == pc->fi_pos)
1683  {
1684  /* failed to find position for resuming, outch! Will start from root! */
1685  GNUNET_break (0);
1686  if (GNUNET_YES != pc->all_done)
1687  pc->fi_pos = pc->fi;
1688  }
1689  }
1690  GNUNET_free (fi_root);
1691  fi_root = NULL;
1692  /* generate RESUME event(s) */
1694 
1695  /* re-start publishing (if needed)... */
1696  if (GNUNET_YES != pc->all_done)
1697  {
1698  GNUNET_assert (NULL == pc->upload_task);
1699  pc->upload_task =
1702  pc);
1703  }
1704  if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
1705  {
1707  _ ("Failure while resuming publishing operation `%s': %s\n"),
1708  filename,
1709  emsg);
1710  GNUNET_free (emsg);
1711  }
1713  return GNUNET_OK;
1714 cleanup:
1715  GNUNET_free (pc->nid);
1716  GNUNET_free (pc->nuid);
1717  GNUNET_free (fi_root);
1718  GNUNET_free (fi_pos);
1719  if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)))
1720  {
1722  _ ("Failed to resume publishing operation `%s': %s\n"),
1723  filename,
1724  emsg);
1725  GNUNET_free (emsg);
1726  }
1727  if (NULL != pc->fi)
1728  GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL);
1729  if (0 != unlink (filename))
1732  GNUNET_free (pc);
1733  return GNUNET_OK;
1734 }
1735 
1736 
1745 void
1747 {
1748  struct GNUNET_BIO_WriteHandle *wh;
1749  int32_t have_ns;
1750 
1751  if (NULL == pc->serialization)
1752  pc->serialization =
1754  if (NULL == pc->serialization)
1755  return;
1756  if (NULL == pc->fi)
1757  return;
1758  if (NULL == pc->fi->serialization)
1759  {
1760  GNUNET_break (0);
1761  return;
1762  }
1763  wh = get_write_handle (pc->h,
1765  pc->serialization);
1766  if (NULL == wh)
1767  {
1768  GNUNET_break (0);
1769  goto cleanup;
1770  }
1771  have_ns = (NULL != pc->ns) ? GNUNET_YES : GNUNET_NO;
1772  struct GNUNET_BIO_WriteSpec ws[] = {
1775  GNUNET_BIO_write_spec_int32 ("options", (int32_t *) &pc->options),
1776  GNUNET_BIO_write_spec_int32 ("all done", &pc->all_done),
1777  GNUNET_BIO_write_spec_int32 ("have ns", &have_ns),
1778  GNUNET_BIO_write_spec_string ("serialization", pc->fi->serialization),
1779  GNUNET_BIO_write_spec_string ("pos serialization", (NULL == pc->fi_pos)
1780  ? NULL
1781  : pc->fi_pos->serialization),
1783  };
1784  if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws)) ||
1785  ((NULL != pc->ns) &&
1786  (GNUNET_OK !=
1788  "ns",
1789  pc->ns,
1790  sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey)))))
1791  {
1792  GNUNET_break (0);
1793  goto cleanup;
1794  }
1795  if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
1796  {
1797  wh = NULL;
1798  GNUNET_break (0);
1799  goto cleanup;
1800  }
1801  return;
1802 cleanup:
1803  if (NULL != wh)
1804  (void) GNUNET_BIO_write_close (wh, NULL);
1807  pc->serialization);
1809  pc->serialization = NULL;
1810 }
1811 
1812 
1821 void
1823 {
1824  struct GNUNET_BIO_WriteHandle *wh;
1825  char *uris;
1826 
1827  if (NULL == uc->serialization)
1828  uc->serialization =
1830  if (NULL == uc->serialization)
1831  return;
1832  wh = get_write_handle (uc->h,
1834  uc->serialization);
1835  if (NULL == wh)
1836  {
1837  GNUNET_break (0);
1838  goto cleanup;
1839  }
1840  if (NULL != uc->ksk_uri)
1842  else
1843  uris = NULL;
1844  struct GNUNET_BIO_WriteSpec ws1[] = {
1845  GNUNET_BIO_write_spec_string ("filename", uc->filename),
1846  GNUNET_BIO_write_spec_int64 ("file size", (int64_t *) &uc->file_size),
1848  };
1849  struct GNUNET_BIO_WriteSpec ws2[] = {
1850  GNUNET_BIO_write_spec_int32 ("state", (int32_t *) &uc->state),
1851  GNUNET_BIO_write_spec_object ("hashkey", &uc->chk,
1852  sizeof (struct ContentHashKey)),
1853  GNUNET_BIO_write_spec_string ("uris", uris),
1854  GNUNET_BIO_write_spec_int32 ("ksk offset", (int32_t *) &uc->ksk_offset),
1856  };
1857  if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws1)) ||
1860  ((uc->state == UNINDEX_STATE_FS_NOTIFY) &&
1862  "file id",
1863  &uc->file_id,
1864  sizeof(struct GNUNET_HashCode)))) ||
1865  ((uc->state == UNINDEX_STATE_ERROR) &&
1866  (GNUNET_OK != GNUNET_BIO_write_string (wh, "emsg", uc->emsg))))
1867  {
1868  GNUNET_break (0);
1869  goto cleanup;
1870  }
1871  if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
1872  {
1873  wh = NULL;
1874  GNUNET_break (0);
1875  goto cleanup;
1876  }
1877  return;
1878 cleanup:
1879  if (NULL != wh)
1880  (void) GNUNET_BIO_write_close (wh, NULL);
1883  uc->serialization);
1885  uc->serialization = NULL;
1886 }
1887 
1888 
1896 static int
1898  struct DownloadRequest *dr)
1899 {
1900  unsigned int i;
1901  struct GNUNET_BIO_WriteSpec ws[] = {
1902  GNUNET_BIO_write_spec_int32 ("state", (int32_t *) &dr->state),
1903  GNUNET_BIO_write_spec_int64 ("offset", (int64_t *) &dr->offset),
1904  GNUNET_BIO_write_spec_int32 ("num children", (int32_t *) &dr->num_children),
1905  GNUNET_BIO_write_spec_int32 ("depth", (int32_t *) &dr->depth),
1907  };
1908 
1909  if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws)))
1910  return GNUNET_NO;
1911  if ((BRS_CHK_SET == dr->state) &&
1912  (GNUNET_OK !=
1913  GNUNET_BIO_write (wh, "hashkey",
1914  &dr->chk, sizeof(struct ContentHashKey))))
1915  return GNUNET_NO;
1916  for (i = 0; i < dr->num_children; i++)
1917  if (GNUNET_NO == write_download_request (wh, dr->children[i]))
1918  return GNUNET_NO;
1919  return GNUNET_YES;
1920 }
1921 
1922 
1929 static struct DownloadRequest *
1931 {
1932  struct DownloadRequest *dr;
1933  unsigned int i;
1934 
1935  dr = GNUNET_new (struct DownloadRequest);
1936  struct GNUNET_BIO_ReadSpec rs[] = {
1937  GNUNET_BIO_read_spec_int32 ("state", (int32_t *) &dr->state),
1938  GNUNET_BIO_read_spec_int64 ("offset", (int64_t *) &dr->offset),
1939  GNUNET_BIO_read_spec_int32 ("num children", (int32_t *) &dr->num_children),
1941  };
1942  if ((GNUNET_OK != GNUNET_BIO_read_spec_commit (rh, rs)) ||
1943  (dr->num_children > CHK_PER_INODE) ||
1944  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "depth",
1945  (int32_t *) &dr->depth)) ||
1946  ((0 == dr->depth) && (dr->num_children > 0)) ||
1947  ((dr->depth > 0) && (0 == dr->num_children)))
1948  {
1949  GNUNET_break (0);
1950  dr->num_children = 0;
1951  goto cleanup;
1952  }
1953  if (dr->num_children > 0)
1954  dr->children =
1955  GNUNET_malloc (dr->num_children * sizeof(struct DownloadRequest *));
1956  switch (dr->state)
1957  {
1958  case BRS_INIT:
1959  case BRS_RECONSTRUCT_DOWN:
1961  case BRS_RECONSTRUCT_UP:
1962  break;
1963 
1964  case BRS_CHK_SET:
1965  if (GNUNET_OK !=
1966  GNUNET_BIO_read (rh, "chk", &dr->chk, sizeof(struct ContentHashKey)))
1967  goto cleanup;
1968  break;
1969 
1970  case BRS_DOWNLOAD_DOWN:
1971  case BRS_DOWNLOAD_UP:
1972  case BRS_ERROR:
1973  break;
1974 
1975  default:
1976  GNUNET_break (0);
1977  goto cleanup;
1978  }
1979  for (i = 0; i < dr->num_children; i++)
1980  {
1981  if (NULL == (dr->children[i] = read_download_request (rh)))
1982  goto cleanup;
1983  dr->children[i]->parent = dr;
1984  }
1985  return dr;
1986 cleanup:
1988  return NULL;
1989 }
1990 
1991 
2001 static char *
2003  const char *uni,
2004  const char *ext)
2005 {
2006  char *par;
2007  char *epar;
2008 
2009  if (dc->parent == NULL)
2010  return get_serialization_file_name (dc->h,
2011  (dc->search != NULL)
2014  uni);
2015  if (NULL == dc->parent->serialization)
2016  return NULL;
2018  if (NULL == par)
2019  return NULL;
2020  GNUNET_asprintf (&epar, "%s.dir%s%s%s", par, DIR_SEPARATOR_STR, uni, ext);
2021  GNUNET_free (par);
2022  return epar;
2023 }
2024 
2025 
2034 void
2036 {
2037  struct GNUNET_BIO_WriteHandle *wh;
2038  char *uris;
2039  char *fn;
2040  char *dir;
2041 
2042  if (0 != (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE))
2043  return; /* we don't sync probes */
2044  if (NULL == dc->serialization)
2045  {
2046  dir = get_download_sync_filename (dc, "", "");
2047  if (NULL == dir)
2048  return;
2050  {
2051  GNUNET_free (dir);
2052  return;
2053  }
2054  fn = GNUNET_DISK_mktemp (dir);
2055  GNUNET_free (dir);
2056  if (NULL == fn)
2057  return;
2059  }
2060  else
2061  {
2063  if (NULL == fn)
2064  {
2066  dc->serialization = NULL;
2067  GNUNET_free (fn);
2068  return;
2069  }
2070  }
2072  if (NULL == wh)
2073  {
2075  dc->serialization = NULL;
2076  GNUNET_free (fn);
2077  return;
2078  }
2081  uris = GNUNET_FS_uri_to_string (dc->uri);
2082  struct GNUNET_BIO_WriteSpec ws1[] = {
2083  GNUNET_BIO_write_spec_string ("uris", uris),
2084  GNUNET_BIO_write_spec_meta_data ("metadata", dc->meta),
2086  GNUNET_BIO_write_spec_string ("filename", dc->filename),
2087  GNUNET_BIO_write_spec_string ("temp filename", dc->temp_filename),
2088  GNUNET_BIO_write_spec_int64 ("old file size",
2089  (int64_t *) &dc->old_file_size),
2090  GNUNET_BIO_write_spec_int64 ("offset", (int64_t *) &dc->offset),
2091  GNUNET_BIO_write_spec_int64 ("length", (int64_t *) &dc->length),
2092  GNUNET_BIO_write_spec_int64 ("completed", (int64_t *) &dc->completed),
2094  };
2095  struct GNUNET_BIO_WriteSpec ws2[] = {
2096  GNUNET_BIO_write_spec_int32 ("anonymity", (int32_t *) &dc->anonymity),
2097  GNUNET_BIO_write_spec_int32 ("options", (int32_t *) &dc->options),
2098  GNUNET_BIO_write_spec_int32 ("has finished", (int32_t *) &dc->has_finished),
2100  };
2101  if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws1)) ||
2104  {
2105  GNUNET_break (0);
2106  goto cleanup;
2107  }
2108  if (NULL == dc->emsg)
2109  {
2110  GNUNET_assert (dc->top_request != NULL);
2112  {
2113  GNUNET_break (0);
2114  goto cleanup;
2115  }
2116  }
2117  GNUNET_free (uris);
2118  uris = NULL;
2119  if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
2120  {
2121  wh = NULL;
2122  GNUNET_break (0);
2123  goto cleanup;
2124  }
2125  GNUNET_free (fn);
2126  return;
2127 cleanup:
2128  if (NULL != wh)
2129  (void) GNUNET_BIO_write_close (wh, NULL);
2130  GNUNET_free (uris);
2131  if (0 != unlink (fn))
2133  GNUNET_free (fn);
2135  dc->serialization = NULL;
2136 }
2137 
2138 
2147 void
2149 {
2150  struct GNUNET_BIO_WriteHandle *wh;
2151  char *uris;
2152 
2153  if (NULL == sr->sc)
2154  return;
2155  uris = NULL;
2156  if (NULL == sr->serialization)
2157  sr->serialization =
2159  (sr->sc->psearch_result == NULL)
2162  sr->sc->serialization);
2163  if (NULL == sr->serialization)
2164  return;
2165  wh = get_write_handle_in_dir (sr->h,
2166  (sr->sc->psearch_result == NULL)
2169  sr->sc->serialization,
2170  sr->serialization);
2171  if (NULL == wh)
2172  {
2173  GNUNET_break (0);
2174  goto cleanup;
2175  }
2176  uris = GNUNET_FS_uri_to_string (sr->uri);
2177  struct GNUNET_BIO_WriteSpec ws[] = {
2178  GNUNET_BIO_write_spec_string ("uris", uris),
2179  GNUNET_BIO_write_spec_string ("download serialization",
2180  (sr->download != NULL)
2181  ? sr->download->serialization
2182  : NULL),
2183  GNUNET_BIO_write_spec_string ("update search serialization",
2184  (sr->update_search != NULL)
2186  : NULL),
2187  GNUNET_BIO_write_spec_meta_data ("metadata", sr->meta),
2188  GNUNET_BIO_write_spec_object ("key", &sr->key,
2189  sizeof(struct GNUNET_HashCode)),
2190  GNUNET_BIO_write_spec_int32 ("mandatory missing",
2191  (int32_t *) &sr->mandatory_missing),
2192  GNUNET_BIO_write_spec_int32 ("optional support",
2193  (int32_t *) &sr->optional_support),
2194  GNUNET_BIO_write_spec_int32 ("availability success",
2195  (int32_t *) &sr->availability_success),
2196  GNUNET_BIO_write_spec_int32 ("availability trials",
2197  (int32_t *) &sr->availability_trials),
2199  };
2200  if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws)))
2201  {
2202  GNUNET_break (0);
2203  goto cleanup;
2204  }
2205  if ((NULL != sr->uri) && (GNUNET_FS_URI_KSK == sr->sc->uri->type) &&
2206  (GNUNET_OK !=
2208  "keyword bitmap",
2209  sr->keyword_bitmap,
2210  (sr->sc->uri->data.ksk.keywordCount + 7) / 8)))
2211  {
2212  GNUNET_break (0);
2213  goto cleanup;
2214  }
2215  if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
2216  {
2217  wh = NULL;
2218  GNUNET_break (0);
2219  goto cleanup;
2220  }
2221  GNUNET_free (uris);
2222  return;
2223 cleanup:
2224  GNUNET_free (uris);
2225  if (NULL != wh)
2226  (void) GNUNET_BIO_write_close (wh, NULL);
2228  (NULL == sr->sc->psearch_result)
2231  sr->sc->serialization,
2232  sr->serialization);
2233  GNUNET_free (sr->serialization);
2234  sr->serialization = NULL;
2235 }
2236 
2237 
2246 void
2248 {
2249  struct GNUNET_BIO_WriteHandle *wh;
2250  char *uris;
2251  char in_pause;
2252  const char *category;
2253 
2254  category = (NULL == sc->psearch_result) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
2256  if (NULL == sc->serialization)
2258  if (NULL == sc->serialization)
2259  return;
2260  uris = NULL;
2261  wh = get_write_handle (sc->h, category, sc->serialization);
2262  if (NULL == wh)
2263  {
2264  GNUNET_break (0);
2265  goto cleanup;
2266  }
2269  uris = GNUNET_FS_uri_to_string (sc->uri);
2270  in_pause = (sc->task != NULL) ? 'r' : '\0';
2271  if ((GNUNET_OK != GNUNET_BIO_write_string (wh, "uris", uris)) ||
2273  (GNUNET_OK != GNUNET_BIO_write_string (wh, "emsg", sc->emsg)) ||
2274  (GNUNET_OK != GNUNET_BIO_write_int32 (wh, "options",
2275  (uint32_t) sc->options)) ||
2276  (GNUNET_OK != GNUNET_BIO_write (wh, "in pause",
2277  &in_pause, sizeof(in_pause))) ||
2278  (GNUNET_OK != GNUNET_BIO_write_int32 (wh, "anonymity", sc->anonymity)))
2279  {
2280  GNUNET_break (0);
2281  goto cleanup;
2282  }
2283  GNUNET_free (uris);
2284  uris = NULL;
2285  if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
2286  {
2287  wh = NULL;
2288  GNUNET_break (0);
2289  goto cleanup;
2290  }
2291  return;
2292 cleanup:
2293  if (NULL != wh)
2294  (void) GNUNET_BIO_write_close (wh, NULL);
2295  GNUNET_free (uris);
2298  sc->serialization = NULL;
2299 }
2300 
2301 
2310 static int
2311 deserialize_unindex_file (void *cls, const char *filename)
2312 {
2313  struct GNUNET_FS_Handle *h = cls;
2314  struct GNUNET_BIO_ReadHandle *rh;
2315  struct GNUNET_FS_UnindexContext *uc;
2316  struct GNUNET_FS_ProgressInfo pi;
2317  char *emsg;
2318  char *uris;
2319  uint32_t state;
2320 
2322  uc->h = h;
2325  if (NULL == rh)
2326  {
2327  GNUNET_break (0);
2328  goto cleanup;
2329  }
2330  uris = NULL;
2331  if ((GNUNET_OK !=
2332  GNUNET_BIO_read_string (rh, "unindex-fn", &uc->filename, 10 * 1024)) ||
2333  (GNUNET_OK != GNUNET_BIO_read_int64 (rh, "file size",
2334  (int64_t *) &uc->file_size)) ||
2335  (GNUNET_OK != read_start_time (rh, &uc->start_time)) ||
2336  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "state",
2337  (int32_t *) &state)) ||
2338  (GNUNET_OK !=
2339  GNUNET_BIO_read (rh, "uri", &uc->chk, sizeof(struct ContentHashKey))) ||
2340  (GNUNET_OK !=
2341  GNUNET_BIO_read_string (rh, "unindex-kskuri", &uris, 10 * 1024)) ||
2342  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "ksk offset",
2343  (int32_t *) &uc->ksk_offset)))
2344  {
2345  GNUNET_free (uris);
2346  GNUNET_break (0);
2347  goto cleanup;
2348  }
2349  if (NULL != uris)
2350  {
2351  uc->ksk_uri = GNUNET_FS_uri_parse (uris, &emsg);
2352  GNUNET_free (uris);
2353  if (NULL == uc->ksk_uri)
2354  {
2355  GNUNET_break (0);
2356  GNUNET_free (emsg);
2357  goto cleanup;
2358  }
2359  }
2360  if ((uc->ksk_offset > 0) &&
2361  ((NULL == uc->ksk_uri) ||
2362  (uc->ksk_offset > uc->ksk_uri->data.ksk.keywordCount)))
2363  {
2364  GNUNET_break (0);
2365  goto cleanup;
2366  }
2367  uc->state = (enum UnindexState) state;
2368  switch (state)
2369  {
2370  case UNINDEX_STATE_HASHING:
2371  break;
2372 
2374  if (GNUNET_OK != GNUNET_BIO_read (rh,
2375  "unindex-hash",
2376  &uc->file_id,
2377  sizeof(struct GNUNET_HashCode)))
2378  {
2379  GNUNET_break (0);
2380  goto cleanup;
2381  }
2382  break;
2383 
2387  break;
2388 
2390  break;
2391 
2392  case UNINDEX_STATE_ERROR:
2393  if (GNUNET_OK !=
2394  GNUNET_BIO_read_string (rh, "unindex-emsg", &uc->emsg, 10 * 1024))
2395  {
2396  GNUNET_break (0);
2397  goto cleanup;
2398  }
2399  break;
2400 
2401  default:
2402  GNUNET_break (0);
2403  goto cleanup;
2404  }
2407  pi.value.unindex.specifics.resume.message = uc->emsg;
2409  uc,
2411  ? uc->file_size
2412  : 0);
2413  switch (uc->state)
2414  {
2415  case UNINDEX_STATE_HASHING:
2417  uc->filename,
2420  uc);
2421  break;
2422 
2426  break;
2427 
2430  break;
2431 
2434  break;
2435 
2438  break;
2439 
2441  case UNINDEX_STATE_ERROR:
2442  /* no need to resume any operation, we were done */
2443  break;
2444 
2445  default:
2446  break;
2447  }
2448  if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
2449  {
2451  _ ("Failure while resuming unindexing operation `%s': %s\n"),
2452  filename,
2453  emsg);
2454  GNUNET_free (emsg);
2455  }
2456  return GNUNET_OK;
2457 cleanup:
2458  GNUNET_free (uc->filename);
2459  if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)))
2460  {
2462  _ ("Failed to resume unindexing operation `%s': %s\n"),
2463  filename,
2464  emsg);
2465  GNUNET_free (emsg);
2466  }
2467  if (NULL != uc->serialization)
2470  uc->serialization);
2472  GNUNET_free (uc);
2473  return GNUNET_OK;
2474 }
2475 
2476 
2486 static void
2488  struct GNUNET_BIO_ReadHandle *rh,
2489  struct GNUNET_FS_DownloadContext *parent,
2491  const char *serialization);
2492 
2493 
2502 static struct GNUNET_FS_SearchContext *
2504  struct GNUNET_BIO_ReadHandle *rh,
2506  const char *serialization);
2507 
2508 
2517 static int
2518 deserialize_search_result (void *cls, const char *filename)
2519 {
2520  struct GNUNET_FS_SearchContext *sc = cls;
2521  char *serialized;
2522  char *uris;
2523  char *emsg;
2524  char *download;
2525  char *update_srch;
2526  struct GNUNET_BIO_ReadHandle *rh;
2527  struct GNUNET_BIO_ReadHandle *drh;
2528  struct GNUNET_FS_SearchResult *sr;
2529 
2530  serialized = get_serialization_short_name (filename);
2532  if (NULL == rh)
2533  {
2534  if (NULL != serialized)
2535  {
2537  (NULL == sc->psearch_result)
2540  sc->serialization,
2541  serialized);
2542  GNUNET_free (serialized);
2543  }
2544  return GNUNET_OK;
2545  }
2546  emsg = NULL;
2547  uris = NULL;
2548  download = NULL;
2549  update_srch = NULL;
2550  sr = GNUNET_new (struct GNUNET_FS_SearchResult);
2551  sr->h = sc->h;
2552  sr->sc = sc;
2553  sr->serialization = serialized;
2554  if ((GNUNET_OK !=
2555  GNUNET_BIO_read_string (rh, "result-uri", &uris, 10 * 1024)) ||
2556  (NULL == (sr->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
2557  (GNUNET_OK !=
2558  GNUNET_BIO_read_string (rh, "download-lnk", &download, 16)) ||
2559  (GNUNET_OK !=
2560  GNUNET_BIO_read_string (rh, "search-lnk", &update_srch, 16)) ||
2561  (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "result-meta", &sr->meta)) ||
2562  (GNUNET_OK != GNUNET_BIO_read (rh,
2563  "result-key",
2564  &sr->key,
2565  sizeof(struct GNUNET_HashCode))) ||
2567  rh,
2568  "mandatory missing",
2569  (int32_t *) &sr->mandatory_missing)) ||
2571  rh,
2572  "optional support",
2573  (int32_t *) &sr->optional_support)) ||
2575  rh,
2576  "availability success",
2577  (int32_t *) &sr->availability_success)) ||
2579  rh,
2580  "availability trials",
2581  (int32_t *) &sr->availability_trials)))
2582  {
2583  GNUNET_break (0);
2584  goto cleanup;
2585  }
2586  if (GNUNET_FS_URI_KSK == sr->sc->uri->type)
2587  {
2589  (sr->sc->uri->data.ksk.keywordCount + 7) / 8); /* round up, count bits */
2590  if (GNUNET_OK !=
2591  GNUNET_BIO_read (rh,
2592  "keyword-bitmap",
2593  sr->keyword_bitmap,
2594  (sr->sc->uri->data.ksk.keywordCount + 7) / 8))
2595  {
2596  GNUNET_break (0);
2597  goto cleanup;
2598  }
2599  }
2600  GNUNET_free (uris);
2601  if (NULL != download)
2602  {
2604  if (NULL != drh)
2605  {
2606  deserialize_download (sc->h, drh, NULL, sr, download);
2607  if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg))
2608  {
2610  _ ("Failed to resume sub-download `%s': %s\n"),
2611  download,
2612  emsg);
2613  GNUNET_free (emsg);
2614  }
2615  }
2617  }
2618  if (NULL != update_srch)
2619  {
2620  drh =
2622  if (NULL != drh)
2623  {
2624  deserialize_search (sc->h, drh, sr, update_srch);
2625  if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg))
2626  {
2628  _ ("Failed to resume sub-search `%s': %s\n"),
2629  update_srch,
2630  emsg);
2631  GNUNET_free (emsg);
2632  }
2633  }
2634  GNUNET_free (update_srch);
2635  }
2638  &sr->key,
2639  sr,
2641  if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
2642  {
2644  _ ("Failure while resuming search operation `%s': %s\n"),
2645  filename,
2646  emsg);
2647  GNUNET_free (emsg);
2648  }
2649  return GNUNET_OK;
2650 cleanup:
2652  GNUNET_free (emsg);
2653  GNUNET_free (uris);
2654  GNUNET_free (update_srch);
2655  if (NULL != sr->uri)
2656  GNUNET_FS_uri_destroy (sr->uri);
2657  if (NULL != sr->meta)
2659  GNUNET_free (sr->serialization);
2660  GNUNET_free (sr);
2661  if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
2662  {
2664  _ ("Failure while resuming search operation `%s': %s\n"),
2665  filename,
2666  emsg);
2667  GNUNET_free (emsg);
2668  }
2669  return GNUNET_OK;
2670 }
2671 
2672 
2681 static void
2683 {
2684  struct GNUNET_FS_DownloadContext *dcc;
2685  struct GNUNET_FS_ProgressInfo pi;
2686 
2688  pi.value.download.specifics.resume.meta = dc->meta;
2689  pi.value.download.specifics.resume.message = dc->emsg;
2691  dcc = dc->child_head;
2692  while (NULL != dcc)
2693  {
2694  signal_download_resume (dcc);
2695  dcc = dcc->next;
2696  }
2697 }
2698 
2699 
2706 static void
2708 
2709 
2719 static int
2720 signal_result_resume (void *cls, const struct GNUNET_HashCode *key, void *value)
2721 {
2722  struct GNUNET_FS_SearchContext *sc = cls;
2723  struct GNUNET_FS_ProgressInfo pi;
2724  struct GNUNET_FS_SearchResult *sr = value;
2725 
2726  if (0 == sr->mandatory_missing)
2727  {
2729  pi.value.search.specifics.resume_result.meta = sr->meta;
2730  pi.value.search.specifics.resume_result.uri = sr->uri;
2731  pi.value.search.specifics.resume_result.result = sr;
2732  pi.value.search.specifics.resume_result.availability_rank =
2734  pi.value.search.specifics.resume_result.availability_certainty =
2735  sr->availability_trials;
2736  pi.value.search.specifics.resume_result.applicability_rank =
2737  sr->optional_support;
2739  }
2740  if (NULL != sr->download)
2741  {
2743  }
2744  else
2745  {
2747  }
2748  if (NULL != sr->update_search)
2750  return GNUNET_YES;
2751 }
2752 
2753 
2759 static void
2761 
2762 
2771 static int
2772 free_result (void *cls, const struct GNUNET_HashCode *key, void *value)
2773 {
2774  struct GNUNET_FS_SearchResult *sr = value;
2775 
2776  if (NULL != sr->update_search)
2777  {
2779  GNUNET_assert (NULL == sr->update_search);
2780  }
2782  GNUNET_FS_uri_destroy (sr->uri);
2783  GNUNET_free (sr);
2784  return GNUNET_YES;
2785 }
2786 
2787 
2793 static void
2795 {
2796  if (NULL != sc->serialization)
2797  {
2799  (sc->psearch_result == NULL)
2802  sc->serialization);
2804  (sc->psearch_result == NULL)
2807  sc->serialization);
2808  }
2810  GNUNET_free (sc->emsg);
2811  if (NULL != sc->uri)
2813  if (NULL != sc->master_result_map)
2814  {
2816  &free_result,
2817  sc);
2819  }
2820  GNUNET_free (sc);
2821 }
2822 
2823 
2832 static int
2833 deserialize_subdownload (void *cls, const char *filename)
2834 {
2835  struct GNUNET_FS_DownloadContext *parent = cls;
2836  char *serialized;
2837  char *emsg;
2838  struct GNUNET_BIO_ReadHandle *rh;
2839 
2840  serialized = get_serialization_short_name (filename);
2842  if (NULL == rh)
2843  {
2845  _ (
2846  "Failed to resume sub-download `%s': could not open file `%s'\n"),
2847  serialized,
2848  filename);
2849  GNUNET_free (serialized);
2850  return GNUNET_OK;
2851  }
2852  deserialize_download (parent->h, rh, parent, NULL, serialized);
2853  if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
2854  {
2856  _ ("Failed to resume sub-download `%s': %s\n"),
2857  serialized,
2858  emsg);
2859  GNUNET_free (emsg);
2860  }
2861  GNUNET_free (serialized);
2862  return GNUNET_OK;
2863 }
2864 
2865 
2873 static void
2875 {
2876  struct GNUNET_FS_DownloadContext *dcc;
2877 
2878  if (NULL != dc->meta)
2880  if (NULL != dc->uri)
2883  GNUNET_free (dc->emsg);
2884  GNUNET_free (dc->filename);
2886  while (NULL != (dcc = dc->child_head))
2887  {
2889  free_download_context (dcc);
2890  }
2892  if (NULL != dc->active)
2894  GNUNET_free (dc);
2895 }
2896 
2897 
2907 static void
2909  struct GNUNET_BIO_ReadHandle *rh,
2912  const char *serialization)
2913 {
2914  struct GNUNET_FS_DownloadContext *dc;
2915  char *emsg;
2916  char *uris;
2917  char *dn;
2918  uint32_t options;
2919  uint32_t status;
2920 
2921  uris = NULL;
2922  emsg = NULL;
2924  dc->parent = parent;
2925  dc->h = h;
2927  struct GNUNET_BIO_ReadSpec rs[] = {
2928  GNUNET_BIO_read_spec_meta_data ("download-meta", &dc->meta),
2929  GNUNET_BIO_read_spec_string ("download-emsg", &dc->emsg, 10 * 1024),
2930  GNUNET_BIO_read_spec_string ("download-fn", &dc->filename, 10 * 1024),
2931  GNUNET_BIO_read_spec_string ("download-tfn",
2932  &dc->temp_filename, 10 * 1024),
2933  GNUNET_BIO_read_spec_int64 ("old file size",
2934  (int64_t *) &dc->old_file_size),
2935  GNUNET_BIO_read_spec_int64 ("offset",
2936  (int64_t *) &dc->offset),
2937  GNUNET_BIO_read_spec_int64 ("length",
2938  (int64_t *) &dc->length),
2939  GNUNET_BIO_read_spec_int64 ("completed",
2940  (int64_t *) &dc->completed),
2942  };
2943  if ((GNUNET_OK !=
2944  GNUNET_BIO_read_string (rh, "download-uri", &uris, 10 * 1024)) ||
2945  (NULL == (dc->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
2950  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "anonymity",
2951  (int32_t *) &dc->anonymity)) ||
2952  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "options",
2953  (int32_t *) &options)) ||
2954  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "status",
2955  (int32_t *) &status)))
2956  {
2957  GNUNET_break (0);
2958  goto cleanup;
2959  }
2961  dc->active =
2963  GNUNET_NO);
2964  dc->has_finished = (int) status;
2965  dc->treedepth =
2967  if (GNUNET_FS_uri_test_loc (dc->uri))
2970  if (NULL == dc->emsg)
2971  {
2973  if (NULL == dc->top_request)
2974  {
2975  GNUNET_break (0);
2976  goto cleanup;
2977  }
2978  }
2979  dn = get_download_sync_filename (dc, dc->serialization, ".dir");
2980  if (NULL != dn)
2981  {
2984  GNUNET_free (dn);
2985  }
2986  if (NULL != parent)
2987  {
2989  }
2990  if (NULL != search)
2991  {
2992  dc->search = search;
2993  search->download = dc;
2994  }
2995  if ((NULL == parent) && (NULL == search))
2996  {
2997  dc->top =
3000  }
3001  GNUNET_free (uris);
3002  GNUNET_assert (NULL == dc->job_queue);
3004  return;
3005 cleanup:
3006  GNUNET_free (uris);
3007  GNUNET_free (emsg);
3009 }
3010 
3011 
3018 static void
3020 {
3021  struct GNUNET_FS_ProgressInfo pi;
3022 
3024  pi.value.search.specifics.resume.message = sc->emsg;
3025  pi.value.search.specifics.resume.is_paused =
3026  (NULL == sc->mq) ? GNUNET_YES : GNUNET_NO;
3030  sc);
3031 }
3032 
3033 
3042 static struct GNUNET_FS_SearchContext *
3044  struct GNUNET_BIO_ReadHandle *rh,
3046  const char *serialization)
3047 {
3048  struct GNUNET_FS_SearchContext *sc;
3049  char *emsg;
3050  char *uris;
3051  char *dn;
3052  uint32_t options;
3053  char in_pause;
3054 
3055  if ((NULL != psearch_result) && (NULL != psearch_result->update_search))
3056  {
3057  GNUNET_break (0);
3058  return NULL;
3059  }
3060  uris = NULL;
3061  emsg = NULL;
3063  if (NULL != psearch_result)
3064  {
3067  }
3068  sc->h = h;
3070  if ((GNUNET_OK !=
3071  GNUNET_BIO_read_string (rh, "search-uri", &uris, 10 * 1024)) ||
3072  (NULL == (sc->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
3075  (GNUNET_OK != read_start_time (rh, &sc->start_time)) ||
3076  (GNUNET_OK !=
3077  GNUNET_BIO_read_string (rh, "search-emsg", &sc->emsg, 10 * 1024)) ||
3078  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "options",
3079  (int32_t *) &options)) ||
3080  (GNUNET_OK !=
3081  GNUNET_BIO_read (rh, "search-pause", &in_pause, sizeof(in_pause))) ||
3082  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "anonymity",
3083  (int32_t *) &sc->anonymity)))
3084  {
3085  GNUNET_break (0);
3086  goto cleanup;
3087  }
3091  (NULL == sc->psearch_result)
3094  sc->serialization,
3095  "");
3096  if (NULL != dn)
3097  {
3100  GNUNET_free (dn);
3101  }
3102  if (('\0' == in_pause) &&
3104  {
3105  GNUNET_log (
3107  _ ("Could not resume running search, will resume as paused search\n"));
3108  }
3110  GNUNET_free (uris);
3111  return sc;
3112 cleanup:
3113  GNUNET_free (emsg);
3115  GNUNET_free (uris);
3116  return NULL;
3117 }
3118 
3119 
3128 static int
3129 deserialize_search_file (void *cls, const char *filename)
3130 {
3131  struct GNUNET_FS_Handle *h = cls;
3132  char *set;
3133  char *emsg;
3134  struct GNUNET_BIO_ReadHandle *rh;
3135  struct GNUNET_FS_SearchContext *sc;
3136  struct stat buf;
3137 
3138  if (0 != stat (filename, &buf))
3139  {
3141  return GNUNET_OK;
3142  }
3143  if (S_ISDIR (buf.st_mode))
3144  return GNUNET_OK; /* skip directories */
3147  if (NULL == rh)
3148  {
3149  if (NULL != set)
3150  {
3152  GNUNET_free (set);
3153  }
3154  return GNUNET_OK;
3155  }
3156  sc = deserialize_search (h, rh, NULL, set);
3157  if (NULL != sc)
3159  GNUNET_free (set);
3160  if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
3161  {
3163  _ ("Failure while resuming search operation `%s': %s\n"),
3164  filename,
3165  emsg);
3166  GNUNET_free (emsg);
3167  }
3168  return GNUNET_OK;
3169 }
3170 
3171 
3180 static int
3181 deserialize_download_file (void *cls, const char *filename)
3182 {
3183  struct GNUNET_FS_Handle *h = cls;
3184  char *set;
3185  char *emsg;
3186  struct GNUNET_BIO_ReadHandle *rh;
3187 
3190  if (NULL == rh)
3191  {
3192  if (0 != unlink (filename))
3194  GNUNET_free (set);
3195  return GNUNET_OK;
3196  }
3197  deserialize_download (h, rh, NULL, NULL, set);
3198  GNUNET_free (set);
3199  if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
3200  {
3202  _ ("Failure while resuming download operation `%s': %s\n"),
3203  filename,
3204  emsg);
3205  GNUNET_free (emsg);
3206  }
3207  return GNUNET_OK;
3208 }
3209 
3210 
3218 static void
3219 deserialization_master (const char *master_path,
3221  struct GNUNET_FS_Handle *h)
3222 {
3223  char *dn;
3224 
3225  dn = get_serialization_file_name (h, master_path, "");
3226  if (NULL == dn)
3227  return;
3229  GNUNET_DISK_directory_scan (dn, proc, h);
3230  GNUNET_free (dn);
3231 }
3232 
3233 
3245 struct GNUNET_FS_Handle *
3247  const char *client_name,
3249  void *upcb_cls,
3250  enum GNUNET_FS_Flags flags,
3251  ...)
3252 {
3253  struct GNUNET_FS_Handle *ret;
3254  enum GNUNET_FS_OPTIONS opt;
3255  va_list ap;
3256 
3257  ret = GNUNET_new (struct GNUNET_FS_Handle);
3258  ret->cfg = cfg;
3259  ret->client_name = GNUNET_strdup (client_name);
3260  ret->upcb = upcb;
3261  ret->upcb_cls = upcb_cls;
3262  ret->flags = flags;
3263  ret->max_parallel_downloads = DEFAULT_MAX_PARALLEL_DOWNLOADS;
3264  ret->max_parallel_requests = DEFAULT_MAX_PARALLEL_REQUESTS;
3265  ret->avg_block_latency =
3266  GNUNET_TIME_UNIT_MINUTES; /* conservative starting point */
3267  va_start (ap, flags);
3268  while (GNUNET_FS_OPTIONS_END !=
3269  (opt = GNUNET_VA_ARG_ENUM (ap, GNUNET_FS_OPTIONS)))
3270  {
3271  switch (opt)
3272  {
3274  ret->max_parallel_downloads = va_arg (ap, unsigned int);
3275 
3276  break;
3277 
3279  ret->max_parallel_requests = va_arg (ap, unsigned int);
3280 
3281  break;
3282 
3283  default:
3284  GNUNET_break (0);
3285  GNUNET_free (ret->client_name);
3286  GNUNET_free (ret);
3287  va_end (ap);
3288  return NULL;
3289  }
3290  }
3291  va_end (ap);
3292  if (0 != (GNUNET_FS_FLAGS_PERSISTENCE & flags))
3293  {
3296  ret);
3299  ret);
3302  ret);
3305  ret);
3306  }
3307  return ret;
3308 }
3309 
3310 
3320 void
3322 {
3323  while (NULL != h->top_head)
3324  h->top_head->ssf (h->top_head->ssf_cls);
3325  if (NULL != h->queue_job)
3326  GNUNET_SCHEDULER_cancel (h->queue_job);
3327  GNUNET_free (h->client_name);
3328  GNUNET_free (h);
3329 }
3330 
3331 
3332 /* end of fs_api.c */
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define HASHING_BLOCKSIZE
Blocksize to use when hashing files for indexing (blocksize for IO, not for the DBlocks).
Definition: fs.h:47
#define DBLOCK_SIZE
Size of the individual blocks used for file-sharing.
Definition: fs.h:40
static int deserialize_download_file(void *cls, const char *filename)
Function called with a filename of serialized download operation to deserialize.
Definition: fs_api.c:3181
static void remove_sync_file_in_dir(struct GNUNET_FS_Handle *h, const char *ext, const char *uni, const char *ent)
Remove serialization/deserialization file from disk.
Definition: fs_api.c:757
void GNUNET_FS_search_result_sync_(struct GNUNET_FS_SearchResult *sr)
Synchronize this search result with its mirror on disk.
Definition: fs_api.c:2148
#define DEFAULT_MAX_PARALLEL_REQUESTS
How many block requests can we have outstanding in parallel at a time by default?
Definition: fs_api.c:36
static int deserialize_unindex_file(void *cls, const char *filename)
Function called with a filename of serialized unindexing operation to deserialize.
Definition: fs_api.c:2311
static char * make_serialization_file_name_in_dir(struct GNUNET_FS_Handle *h, const char *ext, const char *uni)
Create a new random name for serialization.
Definition: fs_api.c:1255
static struct GNUNET_FS_FileInformation * deserialize_fi_node(struct GNUNET_FS_Handle *h, const char *fn, struct GNUNET_BIO_ReadHandle *rh)
Using the given serialization filename, try to deserialize the file-information tree associated with ...
Definition: fs_api.c:881
static int copy_from_reader(struct GNUNET_BIO_WriteHandle *wh, struct GNUNET_FS_FileInformation *fi)
Copy all of the data from the reader to the write handle.
Definition: fs_api.c:1291
static struct GNUNET_FS_FileInformation * deserialize_file_information(struct GNUNET_FS_Handle *h, const char *filename)
Using the given serialization filename, try to deserialize the file-information tree associated with ...
Definition: fs_api.c:1142
void GNUNET_FS_unindex_sync_(struct GNUNET_FS_UnindexContext *uc)
Synchronize this unindex struct with its mirror on disk.
Definition: fs_api.c:1822
static int deserialize_search_file(void *cls, const char *filename)
Function called with a filename of serialized search operation to deserialize.
Definition: fs_api.c:3129
void * GNUNET_FS_make_file_reader_context_(const char *filename)
Create the closure for the GNUNET_FS_data_reader_file_() callback.
Definition: fs_api.c:508
struct TopLevelActivity * GNUNET_FS_make_top(struct GNUNET_FS_Handle *h, SuspendSignalFunction ssf, void *ssf_cls)
Create a top-level activity entry.
Definition: fs_api.c:380
static void start_job(struct GNUNET_FS_QueueEntry *qe)
Start the given job (send signal, remove from pending queue, update counters and state).
Definition: fs_api.c:50
void GNUNET_FS_search_sync_(struct GNUNET_FS_SearchContext *sc)
Synchronize this search struct with its mirror on disk.
Definition: fs_api.c:2247
static struct GNUNET_BIO_WriteHandle * get_write_handle_in_dir(struct GNUNET_FS_Handle *h, const char *ext, const char *uni, const char *ent)
Return a write handle for serialization.
Definition: fs_api.c:702
static char * make_serialization_file_name(struct GNUNET_FS_Handle *h, const char *ext)
Create a new random name for serialization.
Definition: fs_api.c:1219
static void deserialize_download(struct GNUNET_FS_Handle *h, struct GNUNET_BIO_ReadHandle *rh, struct GNUNET_FS_DownloadContext *parent, struct GNUNET_FS_SearchResult *search, const char *serialization)
Deserialize a download.
Definition: fs_api.c:2908
static struct GNUNET_BIO_ReadHandle * get_read_handle(struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
Return a read handle for deserialization.
Definition: fs_api.c:654
static void stop_job(struct GNUNET_FS_QueueEntry *qe)
Stop the given job (send signal, remove from active queue, update counters and state).
Definition: fs_api.c:77
static void signal_download_resume(struct GNUNET_FS_DownloadContext *dc)
Send the 'resume' signal to the callback; also actually resume the download (put it in the queue).
Definition: fs_api.c:2682
static void deserialization_master(const char *master_path, GNUNET_FileNameCallback proc, struct GNUNET_FS_Handle *h)
Deserialize information about pending operations.
Definition: fs_api.c:3219
static struct GNUNET_FS_FileInformation * find_file_position(struct GNUNET_FS_FileInformation *pos, const char *srch)
Find the entry in the file information struct where the serialization filename matches the given name...
Definition: fs_api.c:1539
size_t GNUNET_FS_data_reader_copy_(void *cls, uint64_t offset, size_t max, void *buf, char **emsg)
Function that provides data by copying from a buffer.
Definition: fs_api.c:544
static int read_start_time(struct GNUNET_BIO_ReadHandle *rh, struct GNUNET_TIME_Absolute *timestamp)
Deserialize a start-time.
Definition: fs_api.c:844
static int write_download_request(struct GNUNET_BIO_WriteHandle *wh, struct DownloadRequest *dr)
Serialize a download request.
Definition: fs_api.c:1897
static int free_result(void *cls, const struct GNUNET_HashCode *key, void *value)
Iterator over search results freeing each.
Definition: fs_api.c:2772
void GNUNET_FS_download_sync_(struct GNUNET_FS_DownloadContext *dc)
Synchronize this download struct with its mirror on disk.
Definition: fs_api.c:2035
static struct GNUNET_FS_SearchContext * deserialize_search(struct GNUNET_FS_Handle *h, struct GNUNET_BIO_ReadHandle *rh, struct GNUNET_FS_SearchResult *psearch_result, const char *serialization)
Deserialize a search.
Definition: fs_api.c:3043
static void process_job_queue(void *cls)
Process the jobs in the job queue, possibly starting some and stopping others.
Definition: fs_api.c:106
static void signal_search_resume(struct GNUNET_FS_SearchContext *sc)
Signal resuming of a search to our clients (for the top level search and all sub-searches).
Definition: fs_api.c:3019
void GNUNET_FS_remove_sync_file_(struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
Remove serialization/deserialization file from disk.
Definition: fs_api.c:727
static void free_search_context(struct GNUNET_FS_SearchContext *sc)
Free memory allocated by the search context and its children.
Definition: fs_api.c:2794
#define DEFAULT_MAX_PARALLEL_DOWNLOADS
How many downloads can we have outstanding in parallel at a time by default?
Definition: fs_api.c:41
static char * get_serialization_file_name_in_dir(struct GNUNET_FS_Handle *h, const char *ext, const char *uni, const char *ent)
Return the full filename where we would store state information (for serialization/deserialization) t...
Definition: fs_api.c:614
static struct DownloadRequest * read_download_request(struct GNUNET_BIO_ReadHandle *rh)
Read a download request tree.
Definition: fs_api.c:1930
static int write_start_time(struct GNUNET_BIO_WriteHandle *wh, struct GNUNET_TIME_Absolute timestamp)
Serialize a start-time.
Definition: fs_api.c:819
static char * get_serialization_file_name(struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
Return the full filename where we would store state information (for serialization/deserialization).
Definition: fs_api.c:574
static int deserialize_subdownload(void *cls, const char *filename)
Function called with a filename of serialized sub-download to deserialize.
Definition: fs_api.c:2833
static struct GNUNET_BIO_WriteHandle * get_write_handle(struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
Return a write handle for serialization.
Definition: fs_api.c:677
void GNUNET_FS_remove_sync_dir_(struct GNUNET_FS_Handle *h, const char *ext, const char *uni)
Remove serialization/deserialization directory from disk.
Definition: fs_api.c:786
void GNUNET_FS_file_information_sync_(struct GNUNET_FS_FileInformation *fi)
Create a temporary file on disk to store the current state of fi in.
Definition: fs_api.c:1327
void GNUNET_FS_dequeue_(struct GNUNET_FS_QueueEntry *qe)
Dequeue a job from the queue.
Definition: fs_api.c:355
struct GNUNET_FS_QueueEntry * GNUNET_FS_queue_(struct GNUNET_FS_Handle *h, GNUNET_SCHEDULER_TaskCallback start, GNUNET_SCHEDULER_TaskCallback stop, void *cls, unsigned int blocks, enum GNUNET_FS_QueuePriority priority)
Add a job to the queue.
Definition: fs_api.c:320
static int deserialize_search_result(void *cls, const char *filename)
Function called with a filename of serialized search result to deserialize.
Definition: fs_api.c:2518
static int signal_result_resume(void *cls, const struct GNUNET_HashCode *key, void *value)
Iterator over search results signaling resume to the client for each result.
Definition: fs_api.c:2720
static void free_download_context(struct GNUNET_FS_DownloadContext *dc)
Free this download context and all of its descendants.
Definition: fs_api.c:2874
size_t GNUNET_FS_data_reader_file_(void *cls, uint64_t offset, size_t max, void *buf, char **emsg)
Function that provides data by reading from a file.
Definition: fs_api.c:446
static char * get_download_sync_filename(struct GNUNET_FS_DownloadContext *dc, const char *uni, const char *ext)
Compute the name of the sync file (or directory) for the given download context.
Definition: fs_api.c:2002
static char * get_serialization_short_name(const char *fullname)
Given a serialization name (full absolute path), return the basename of the file (without the path),...
Definition: fs_api.c:1185
void GNUNET_FS_end_top(struct GNUNET_FS_Handle *h, struct TopLevelActivity *top)
Destroy a top-level activity entry.
Definition: fs_api.c:401
void GNUNET_FS_publish_sync_(struct GNUNET_FS_PublishContext *pc)
Synchronize this publishing struct with its mirror on disk.
Definition: fs_api.c:1746
static int deserialize_publish_file(void *cls, const char *filename)
Function called with a filename of serialized publishing operation to deserialize.
Definition: fs_api.c:1611
static int fip_signal_resume(void *cls, struct GNUNET_FS_FileInformation *fi, uint64_t length, struct GNUNET_CONTAINER_MetaData *meta, struct GNUNET_FS_Uri **uri, struct GNUNET_FS_BlockOptions *bo, int *do_index, void **client_info)
Signal the FS's progress function that we are resuming an upload.
Definition: fs_api.c:1571
shared definitions for the FS library
@ BRS_DOWNLOAD_UP
This block and all of its children have been downloaded successfully (full completion propagates up).
Definition: fs_api.h:1660
@ BRS_RECONSTRUCT_META_UP
We've calculated the CHK bottom-up based on the meta data.
Definition: fs_api.h:1628
@ BRS_CHK_SET
We've determined the real, desired CHK for this block (full tree reconstruction failed),...
Definition: fs_api.h:1645
@ BRS_ERROR
We got a block back that matched the query but did not hash to the key (malicious publisher or hash c...
Definition: fs_api.h:1667
@ BRS_RECONSTRUCT_DOWN
We've checked the block on the path down the tree, and the content on disk did match the desired CHK,...
Definition: fs_api.h:1620
@ BRS_INIT
Initial state, block has only been allocated (since it is relevant to the overall download request).
Definition: fs_api.h:1612
@ BRS_DOWNLOAD_DOWN
We've successfully downloaded this block, but the children still need to be either downloaded or veri...
Definition: fs_api.h:1654
@ BRS_RECONSTRUCT_UP
We've calculated the CHK bottom-up based on what we have on disk, which may not be what the desired C...
Definition: fs_api.h:1636
void GNUNET_FS_download_signal_suspend_(void *cls)
Create SUSPEND event for the given download operation and then clean up our state (without stop signa...
Definition: fs_download.c:1953
UnindexState
Phases of unindex processing (state machine).
Definition: fs_api.h:1306
@ UNINDEX_STATE_EXTRACT_KEYWORDS
Find out which keywords apply.
Definition: fs_api.h:1321
@ UNINDEX_STATE_COMPLETE
We're done.
Definition: fs_api.h:1337
@ UNINDEX_STATE_DS_REMOVE
We're telling the datastore to delete the respective DBlocks and IBlocks.
Definition: fs_api.h:1316
@ UNINDEX_STATE_HASHING
We're currently hashing the file.
Definition: fs_api.h:1310
@ UNINDEX_STATE_ERROR
We've encountered a fatal error.
Definition: fs_api.h:1342
@ UNINDEX_STATE_FS_NOTIFY
We're notifying the FS service about the unindexing.
Definition: fs_api.h:1332
@ UNINDEX_STATE_DS_REMOVE_KBLOCKS
We're telling the datastore to remove KBlocks.
Definition: fs_api.h:1326
@ GNUNET_FS_URI_KSK
Keyword search key (query with keywords).
Definition: fs_api.h:153
#define GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD
Name of the directory with master downloads (not associated with search or part of another download).
Definition: fs_api.h:65
void GNUNET_FS_unindex_do_remove_kblocks_(struct GNUNET_FS_UnindexContext *uc)
If necessary, connect to the datastore and remove the KBlocks.
Definition: fs_unindex.c:580
void * GNUNET_FS_search_make_status_(struct GNUNET_FS_ProgressInfo *pi, struct GNUNET_FS_Handle *h, struct GNUNET_FS_SearchContext *sc)
Fill in all of the generic fields for a search event and call the callback.
Definition: fs_search.c:48
void GNUNET_FS_free_download_request_(struct DownloadRequest *dr)
(recursively) free download request structure
Definition: fs_download.c:996
#define GNUNET_FS_SYNC_PATH_MASTER_SEARCH
Name of the directory with top-level searches.
Definition: fs_api.h:54
void GNUNET_FS_publish_signal_suspend_(void *cls)
Create SUSPEND event for the given publish operation and then clean up our state (without stop signal...
Definition: fs_publish.c:1354
#define GNUNET_FS_SYNC_PATH_MASTER_UNINDEX
Name of the directory with unindex operations.
Definition: fs_api.h:86
#define GNUNET_FS_SYNC_PATH_MASTER_PUBLISH
Name of the directory with publishing operations.
Definition: fs_api.h:76
#define CHK_PER_INODE
Pick a multiple of 2 here to achieve 8-byte alignment! We also probably want DBlocks to have (roughly...
Definition: fs_api.h:43
void GNUNET_FS_unindex_make_status_(struct GNUNET_FS_ProgressInfo *pi, struct GNUNET_FS_UnindexContext *uc, uint64_t offset)
Fill in all of the generic fields for an unindex event and call the callback.
Definition: fs_unindex.c:84
void GNUNET_FS_download_make_status_(struct GNUNET_FS_ProgressInfo *pi, struct GNUNET_FS_DownloadContext *dc)
Fill in all of the generic fields for a download event and call the callback.
Definition: fs_download.c:103
void GNUNET_FS_download_start_task_(void *cls)
Task that creates the initial (top-level) download request for the file.
Definition: fs_download.c:1800
#define GNUNET_FS_SYNC_PATH_CHILD_SEARCH
Name of the directory with sub-searches (namespace-updates).
Definition: fs_api.h:59
void GNUNET_FS_unindex_do_extract_keywords_(struct GNUNET_FS_UnindexContext *uc)
Extract the keywords for KBlock removal.
Definition: fs_unindex.c:406
void GNUNET_FS_unindex_do_remove_(struct GNUNET_FS_UnindexContext *uc)
Connect to the datastore and remove the blocks.
Definition: fs_unindex.c:649
void GNUNET_FS_search_start_probe_(struct GNUNET_FS_SearchResult *sr)
Start download probes for the given search result.
Definition: fs_search.c:430
GNUNET_FS_QueuePriority
Priorities for the queue.
Definition: fs_api.h:403
@ GNUNET_FS_QUEUE_PRIORITY_NORMAL
Default priority.
Definition: fs_api.h:412
@ GNUNET_FS_QUEUE_PRIORITY_PROBE
This is a probe (low priority).
Definition: fs_api.h:407
void(* SuspendSignalFunction)(void *cls)
Function signature of the functions that can be called to trigger suspend signals and clean-up for to...
Definition: fs_api.h:1010
void GNUNET_FS_unindex_signal_suspend_(void *cls)
Create SUSPEND event for the given unindex operation and then clean up our state (without stop signal...
Definition: fs_unindex.c:727
int GNUNET_FS_search_start_searching_(struct GNUNET_FS_SearchContext *sc)
Build the request and actually initiate the search using the GNUnet FS service.
Definition: fs_search.c:1401
void * GNUNET_FS_publish_make_status_(struct GNUNET_FS_ProgressInfo *pi, struct GNUNET_FS_PublishContext *pc, const struct GNUNET_FS_FileInformation *p, uint64_t offset)
Fill in all of the generic fields for a publish event and call the callback.
Definition: fs_publish.c:47
void GNUNET_FS_unindex_process_hash_(void *cls, const struct GNUNET_HashCode *file_id)
Function called once the hash of the file that is being unindexed has been computed.
Definition: fs_unindex.c:694
#define GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD
Name of the directory with downloads that are part of another download or a search.
Definition: fs_api.h:71
void GNUNET_FS_publish_main_(void *cls)
Main function that performs the upload.
Definition: fs_publish.c:1062
#define GNUNET_FS_SYNC_PATH_FILE_INFO
Name of the directory with files that are being published.
Definition: fs_api.h:81
void GNUNET_FS_search_signal_suspend_(void *cls)
Create SUSPEND event for the given search operation and then clean up our state (without stop signal)...
Definition: fs_search.c:1554
unsigned int GNUNET_FS_compute_depth(uint64_t flen)
Compute the depth of the CHK tree.
Definition: fs_tree.c:125
Merkle-tree-ish-CHK file encoding for GNUnet.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static struct GNUNET_NAMESTORE_Handle * ns
Handle to the namestore.
Definition: gnunet-abd.c:41
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
static char * dir
Set to the directory where runtime files are stored.
Definition: gnunet-arm.c:89
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
static void cleanup(void *cls)
Function scheduled as very last function, cleans up after us.
static struct GNUNET_TIME_Absolute end_time
At what time MUST the current hostlist request be done?
static struct GNUNET_PEERINFO_Handle * pi
Handle to peerinfo service.
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_FS_DownloadContext * dc
static char * filename
uint32_t data
The data value.
uint16_t status
See PRISM_STATUS_*-constants.
static char * value
Value of the record to add/remove.
static struct GNUNET_FS_Uri * uri
Value of URI provided on command-line (when not publishing a file but just creating UBlocks to refer ...
static struct GNUNET_FS_BlockOptions bo
Options we set for published blocks.
static struct GNUNET_CONTAINER_MetaData * meta
Meta-data provided via command-line option.
static struct GNUNET_FS_PublishContext * pc
Handle to FS-publishing operation.
enum State state
current state of profiling
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:84
static struct GNUNET_TESTBED_BarrierWaitHandle * wh
Our barrier wait handle.
static char buf[2048]
static struct GNUNET_FS_UnindexContext * uc
API for file sharing via GNUnet.
struct GNUNET_BIO_ReadSpec GNUNET_BIO_read_spec_string(const char *what, char **result, size_t max_length)
Create the specification to read a 0-terminated string.
Definition: bio.c:1046
int GNUNET_BIO_read_string(struct GNUNET_BIO_ReadHandle *h, const char *what, char **result, size_t max_length)
Read 0-terminated string.
Definition: bio.c:327
int GNUNET_BIO_read_meta_data(struct GNUNET_BIO_ReadHandle *h, const char *what, struct GNUNET_CONTAINER_MetaData **result)
Read a metadata container.
Definition: bio.c:390
int GNUNET_BIO_write_spec_commit(struct GNUNET_BIO_WriteHandle *h, struct GNUNET_BIO_WriteSpec *ws)
Execute the write specifications in order.
Definition: bio.c:1540
int GNUNET_BIO_read_int32(struct GNUNET_BIO_ReadHandle *h, const char *what, int32_t *i)
Read an (u)int32_t.
Definition: bio.c:479
struct GNUNET_BIO_ReadHandle * GNUNET_BIO_read_open_file(const char *fn)
Open a file for reading.
Definition: bio.c:119
int GNUNET_BIO_write(struct GNUNET_BIO_WriteHandle *h, const char *what, const void *buffer, size_t n)
Write a buffer to a handle.
Definition: bio.c:796
int GNUNET_BIO_read_int64(struct GNUNET_BIO_ReadHandle *h, const char *what, int64_t *i)
Read an (u)int64_t.
Definition: bio.c:501
int GNUNET_BIO_write_string(struct GNUNET_BIO_WriteHandle *h, const char *what, const char *s)
Write a 0-terminated string.
Definition: bio.c:833
int GNUNET_BIO_write_close(struct GNUNET_BIO_WriteHandle *h, char **emsg)
Close an IO handle.
Definition: bio.c:609
int GNUNET_BIO_write_int32(struct GNUNET_BIO_WriteHandle *h, const char *what, int32_t i)
Write an (u)int32_t.
Definition: bio.c:937
struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_string(const char *what, const char *s)
Create the specification to write a 0-terminated string.
Definition: bio.c:1336
#define GNUNET_BIO_read_spec_end()
End of specifications marker.
int GNUNET_BIO_read_spec_commit(struct GNUNET_BIO_ReadHandle *h, struct GNUNET_BIO_ReadSpec *rs)
Execute the read specifications in order.
Definition: bio.c:1243
struct GNUNET_BIO_ReadSpec GNUNET_BIO_read_spec_int32(const char *what, int32_t *i)
Create the specification to read an (u)int32_t.
Definition: bio.c:1136
#define GNUNET_BIO_write_spec_end()
End of specifications marker.
int GNUNET_BIO_read_close(struct GNUNET_BIO_ReadHandle *h, char **emsg)
Close an open handle.
Definition: bio.c:167
int GNUNET_BIO_write_int64(struct GNUNET_BIO_WriteHandle *h, const char *what, int64_t i)
Write an (u)int64_t.
Definition: bio.c:957
int GNUNET_BIO_read(struct GNUNET_BIO_ReadHandle *h, const char *what, void *result, size_t len)
Read some contents into a buffer.
Definition: bio.c:288
struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_object(const char *what, void *source, size_t size)
Create the specification to read some bytes.
Definition: bio.c:1289
struct GNUNET_BIO_WriteHandle * GNUNET_BIO_write_open_file(const char *fn)
Open a file for writing.
Definition: bio.c:560
struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_meta_data(const char *what, const struct GNUNET_CONTAINER_MetaData *m)
Create the specification to write a metadata container.
Definition: bio.c:1382
struct GNUNET_BIO_ReadSpec GNUNET_BIO_read_spec_meta_data(const char *what, struct GNUNET_CONTAINER_MetaData **result)
Create the specification to read a metadata container.
Definition: bio.c:1092
struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_int32(const char *what, int32_t *i)
Create the specification to write an (u)int32_t.
Definition: bio.c:1427
struct GNUNET_BIO_ReadSpec GNUNET_BIO_read_spec_int64(const char *what, int64_t *i)
Create the specification to read an (u)int64_t.
Definition: bio.c:1180
struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_int64(const char *what, int64_t *i)
Create the specification to write an (u)int64_t.
Definition: bio.c:1472
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
struct GNUNET_DATASTORE_Handle * GNUNET_DATASTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the datastore service.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1235
char * GNUNET_DISK_mktemp(const char *t)
Create an (empty) temporary file on disk.
Definition: disk.c:381
off_t GNUNET_DISK_file_seek(const struct GNUNET_DISK_FileHandle *h, off_t offset, enum GNUNET_DISK_Seek whence)
Move the read/write pointer in a file.
Definition: disk.c:206
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
Definition: disk.c:1085
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition: disk.c:404
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1306
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:582
ssize_t GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: disk.c:622
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition: disk.c:814
@ GNUNET_DISK_OPEN_READ
Open the file for reading.
@ GNUNET_DISK_PERM_NONE
Nobody is allowed to do anything to the file.
@ GNUNET_DISK_SEEK_SET
Seek an absolute position (from the start of the file).
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert_after(head, tail, other, element)
Insert an element into a DLL after the given other element.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
GNUNET_FS_Flags
General (global) option flags for file-sharing.
GNUNET_FS_SearchOptions
Options for searching.
struct GNUNET_FS_Uri * GNUNET_FS_uri_parse(const char *uri, char **emsg)
Convert a UTF-8 String to a URI.
Definition: fs_uri.c:644
GNUNET_FS_DownloadOptions
Options for downloading.
void *(* GNUNET_FS_ProgressCallback)(void *cls, const struct GNUNET_FS_ProgressInfo *info)
Notification of FS to a client about the progress of an operation.
int GNUNET_FS_meta_data_test_for_directory(const struct GNUNET_CONTAINER_MetaData *md)
Does the meta-data claim that this is a directory? Checks if the mime-type is that of a GNUnet direct...
Definition: fs_directory.c:54
uint64_t GNUNET_FS_uri_chk_get_file_size(const struct GNUNET_FS_Uri *uri)
What is the size of the file that this URI refers to?
Definition: fs_uri.c:1376
int GNUNET_FS_uri_test_ksk(const struct GNUNET_FS_Uri *uri)
Is this a keyword URI?
Definition: fs_uri.c:1340
GNUNET_FS_OPTIONS
Options specified in the VARARGs portion of GNUNET_FS_start.
void GNUNET_FS_file_information_inspect(struct GNUNET_FS_FileInformation *dir, GNUNET_FS_FileInformationProcessor proc, void *proc_cls)
Inspect a file or directory in a publish-structure.
int GNUNET_FS_uri_test_loc(const struct GNUNET_FS_Uri *uri)
Is this a location URI?
Definition: fs_uri.c:1400
char * GNUNET_FS_uri_to_string(const struct GNUNET_FS_Uri *uri)
Convert a URI to a UTF-8 String.
Definition: fs_uri.c:2033
void GNUNET_FS_uri_destroy(struct GNUNET_FS_Uri *uri)
Free URI.
Definition: fs_uri.c:684
int GNUNET_FS_uri_test_sks(const struct GNUNET_FS_Uri *uri)
Is this a namespace URI?
Definition: fs_uri.c:1287
struct GNUNET_FS_Handle * GNUNET_FS_start(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *client_name, GNUNET_FS_ProgressCallback upcb, void *upcb_cls, enum GNUNET_FS_Flags flags,...)
Setup a connection to the file-sharing service.
Definition: fs_api.c:3246
int GNUNET_FS_uri_test_chk(const struct GNUNET_FS_Uri *uri)
Is this a file (or directory) URI?
Definition: fs_uri.c:1362
void GNUNET_FS_stop(struct GNUNET_FS_Handle *h)
Close our connection with the file-sharing service.
Definition: fs_api.c:3321
void GNUNET_FS_file_information_destroy(struct GNUNET_FS_FileInformation *fi, GNUNET_FS_FileInformationProcessor cleaner, void *cleaner_cls)
Destroy publish-structure.
int GNUNET_FS_uri_loc_get_peer_identity(const struct GNUNET_FS_Uri *uri, struct GNUNET_PeerIdentity *peer)
Obtain the identity of the peer offering the data.
Definition: fs_uri.c:828
@ GNUNET_FS_FLAGS_PERSISTENCE
Is persistence of operations desired? (will create SUSPEND/RESUME events).
@ GNUNET_FS_DOWNLOAD_IS_PROBE
Internal option used to flag this download as a 'probe' for a search result.
@ GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM
Select the desired amount of parallelism (this option should be followed by an "unsigned int" giving ...
@ GNUNET_FS_OPTIONS_END
Last option in the VARARG list.
@ GNUNET_FS_OPTIONS_REQUEST_PARALLELISM
Maximum number of requests that should be pending at a given point in time (invidivual downloads may ...
@ GNUNET_FS_STATUS_UNINDEX_RESUME
Notification that we resumed unindexing of a file.
@ GNUNET_FS_STATUS_DOWNLOAD_RESUME
Notification that this download is being resumed.
@ GNUNET_FS_STATUS_SEARCH_RESUME
Last event when a search is being resumed; note that "GNUNET_FS_SEARCH_START" will not be generated i...
@ GNUNET_FS_STATUS_SEARCH_RESUME_RESULT
Event generated for each search result when the respective search is resumed.
@ GNUNET_FS_STATUS_PUBLISH_RESUME
Notification that we have resumed sharing a file structure.
@ GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY
Simulate publishing.
struct GNUNET_CRYPTO_FileHashContext * GNUNET_CRYPTO_hash_file(enum GNUNET_SCHEDULER_Priority priority, const char *filename, size_t blocksize, GNUNET_CRYPTO_HashCompletedCallback callback, void *callback_cls)
Compute the hash of an entire file.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
enum GNUNET_GenericReturnValue(* GNUNET_FileNameCallback)(void *cls, const char *filename)
Function called with a filename.
#define GNUNET_log(kind,...)
#define GNUNET_VA_ARG_ENUM(va, X)
wrap va_arg for enums
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_MIN(a, b)
@ GNUNET_SCHEDULER_PRIORITY_IDLE
Run when otherwise idle.
@ GNUNET_SCHEDULER_PRIORITY_BACKGROUND
Run as background job (higher than idle, lower than default).
@ GNUNET_OK
Definition: gnunet_common.h:99
@ GNUNET_YES
@ GNUNET_NO
Definition: gnunet_common.h:98
@ GNUNET_SYSERR
Definition: gnunet_common.h:97
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_malloc_large(size)
Wrapper around malloc.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_CONTAINER_meta_data_destroy(struct GNUNET_CONTAINER_MetaData *md)
Free meta data.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1281
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_with_priority(enum GNUNET_SCHEDULER_Priority prio, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified priority.
Definition: scheduler.c:1208
void(* GNUNET_SCHEDULER_TaskCallback)(void *cls)
Signature of the main function of a task.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:957
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1254
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
Definition: strings.c:495
struct GNUNET_TIME_Relative GNUNET_TIME_relative_min(struct GNUNET_TIME_Relative t1, struct GNUNET_TIME_Relative t2)
Return the minimum of two relative time values.
Definition: time.c:342
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
Definition: time.c:435
struct GNUNET_TIME_Relative GNUNET_TIME_relative_saturating_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Saturating multiply relative time by a given factor.
Definition: time.c:530
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:404
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:110
#define GNUNET_TIME_UNIT_MINUTES
One minute.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_add(struct GNUNET_TIME_Relative a1, struct GNUNET_TIME_Relative a2)
Add relative times together.
Definition: time.c:584
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_subtract(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
Subtract a given relative duration from the given start time.
Definition: time.c:468
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:483
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_add(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
Add a given relative duration to the given start time.
Definition: time.c:449
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:570
#define max(x, y)
#define DIR_SEPARATOR
Definition: platform.h:164
#define DIR_SEPARATOR_STR
Definition: platform.h:165
#define _(String)
GNU gettext support macro.
Definition: platform.h:177
content hash key
Definition: fs.h:54
Information about an active download request.
Definition: fs_api.h:1675
struct DownloadRequest ** children
Array (!) of child-requests, or NULL for the bottom of the tree.
Definition: fs_api.h:1684
unsigned int num_children
Number of entries in children array.
Definition: fs_api.h:1702
uint64_t offset
Offset of the corresponding block.
Definition: fs_api.h:1697
enum BlockRequestState state
State in the FSM.
Definition: fs_api.h:1717
unsigned int depth
Depth of the corresponding block in the tree.
Definition: fs_api.h:1707
struct DownloadRequest * parent
Parent in the CHK-tree.
Definition: fs_api.h:1679
struct ContentHashKey chk
CHK for the request for this block (set during reconstruction to what we have on disk,...
Definition: fs_api.h:1690
Closure for GNUNET_FS_data_reader_file_().
Definition: fs_api.c:412
struct GNUNET_DISK_FileHandle * fd
File descriptor, NULL if it has not yet been opened.
Definition: fs_api.c:421
char * filename
Name of the file to read.
Definition: fs_api.c:416
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration that we are using.
Definition: arm_api.c:112
Handle for buffered reading.
Definition: bio.c:74
char * emsg
Error message, NULL if there were no errors.
Definition: bio.c:88
Structure specifying a reading operation on an IO handle.
GNUNET_BIO_ReadHandler rh
Function performing data deserialization.
Handle for buffered writing.
Definition: bio.c:518
Structure specifying a writing operation on an IO handle.
Meta data to associate with a file, directory or namespace.
Private ECC key encoded for transmission.
unsigned int priority
Priority in the queue.
struct GNUNET_DATASTORE_Handle * h
Handle to the master context.
struct GNUNET_DATASTORE_QueueEntry * next
This is a linked list.
Handle used to access files (and pipes).
Settings for publishing a block (which may of course also apply to an entire directory or file).
uint32_t anonymity_level
At which anonymity level should the block be shared? (0: no anonymity, 1: normal GAP,...
uint32_t content_priority
How important is it for us to store the block? If we run out of space, the highest-priority,...
uint32_t replication_level
How often should we try to migrate the block to other peers? Only used if "CONTENT_PUSHING" is set to...
struct GNUNET_TIME_Absolute expiration_time
At what time should the block expire? Data blocks (DBLOCKS and IBLOCKS) may still be used even if the...
Context for controlling a download.
Definition: fs_api.h:1743
int has_finished
Flag set upon transitive completion (includes child downloads).
Definition: fs_api.h:1929
unsigned int treedepth
The depth of the file-tree.
Definition: fs_api.h:1917
char * filename
Where are we writing the data (name of the file, can be NULL!).
Definition: fs_api.h:1821
struct GNUNET_FS_Uri * uri
URI that identifies the file that we are downloading.
Definition: fs_api.h:1799
uint64_t old_file_size
What was the size of the file on disk that we're downloading before we started? Used to detect if the...
Definition: fs_api.h:1897
uint64_t completed
How many bytes have we already received within the specified range (DBlocks only).
Definition: fs_api.h:1889
uint64_t offset
What is the first offset that we're interested in?
Definition: fs_api.h:1877
struct GNUNET_FS_QueueEntry * job_queue
Our entry in the job queue.
Definition: fs_api.h:1833
char * emsg
Error message, NULL if we're doing OK.
Definition: fs_api.h:1809
struct GNUNET_SCHEDULER_Task * task
ID of a task that is using this struct and that must be cancelled when the download is being stopped ...
Definition: fs_api.h:1871
struct GNUNET_FS_SearchResult * search
Associated search (used when downloading files based on search results), or NULL for none.
Definition: fs_api.h:1769
struct GNUNET_FS_DownloadContext * child_tail
Tail of list of child downloads.
Definition: fs_api.h:1779
struct GNUNET_CONTAINER_MultiHashMap * active
Map of active requests (those waiting for a response).
Definition: fs_api.h:1850
struct GNUNET_FS_DownloadContext * child_head
Head of list of child downloads.
Definition: fs_api.h:1774
uint64_t length
How many bytes starting from offset are desired? This is NOT the overall length of the file!
Definition: fs_api.h:1883
char * serialization
Random portion of filename we use for syncing state of this download.
Definition: fs_api.h:1815
uint32_t anonymity
Desired level of anonymity.
Definition: fs_api.h:1912
char * temp_filename
Where are we writing the data temporarily (name of the file, can be NULL!); used if we do not have a ...
Definition: fs_api.h:1828
struct GNUNET_FS_DownloadContext * next
Next download belonging to the same parent.
Definition: fs_api.h:1789
struct GNUNET_FS_DownloadContext * parent
Parent download (used when downloading files in directories).
Definition: fs_api.h:1763
struct DownloadRequest * top_request
Top-level download request.
Definition: fs_api.h:1855
struct GNUNET_PeerIdentity target
Identity of the peer having the content, or all-zeros if we don't know of such a peer.
Definition: fs_api.h:1861
struct GNUNET_CONTAINER_MetaData * meta
Known meta-data for the file (can be NULL).
Definition: fs_api.h:1804
enum GNUNET_FS_DownloadOptions options
Options for the download.
Definition: fs_api.h:1922
struct GNUNET_FS_Handle * h
Global FS context.
Definition: fs_api.h:1747
struct GNUNET_TIME_Absolute start_time
Time download was started.
Definition: fs_api.h:1902
struct TopLevelActivity * top
Our top-level activity entry (if we are top-level, otherwise NULL).
Definition: fs_api.h:1752
Information for a file or directory that is about to be published.
Definition: fs_api.h:227
char * serialization
Under what filename is this struct serialized (for operational persistence).
Definition: fs_api.h:286
struct GNUNET_FS_Uri * keywords
Keywords to use for KBlocks.
Definition: fs_api.h:257
char * filename
Name of the file or directory (must be an absolute path).
Definition: fs_api.h:301
size_t dir_size
Size of the directory itself (in bytes); 0 if the size has not yet been calculated.
Definition: fs_api.h:367
uint64_t contents_completed
How much of the directory have we published (relative to contents_size).
Definition: fs_api.h:378
struct GNUNET_FS_FileInformation::@16::@17 file
Data for a file.
char * emsg
Error message (non-NULL if this operation failed).
Definition: fs_api.h:296
void * client_info
Pointer kept for the client.
Definition: fs_api.h:247
struct GNUNET_FS_FileInformation * next
Files in a directory are kept as a linked list.
Definition: fs_api.h:231
struct GNUNET_FS_BlockOptions bo
Block options for the file.
Definition: fs_api.h:274
struct GNUNET_CONTAINER_MetaData * meta
Metadata to use for the file.
Definition: fs_api.h:252
int is_published
Are we done publishing this file?
Definition: fs_api.h:395
struct GNUNET_FS_Uri * sks_uri
SKS URI for this file or directory.
Definition: fs_api.h:269
void * dir_data
Pointer to the data for the directory (or NULL if not available).
Definition: fs_api.h:373
uint64_t contents_size
Sum of all of the sizes of all of the files in the directory.
Definition: fs_api.h:383
int do_index
Should the file be indexed or inserted?
Definition: fs_api.h:338
union GNUNET_FS_FileInformation::@16 data
Data describing either the file or the directory.
struct GNUNET_FS_Handle * h
Handle to the master context.
Definition: fs_api.h:242
struct GNUNET_TIME_Absolute start_time
At what time did we start this upload?
Definition: fs_api.h:279
struct GNUNET_FS_FileInformation * entries
Linked list of entries in the directory.
Definition: fs_api.h:361
struct GNUNET_FS_FileInformation * dir
If this is a file in a directory, "dir" refers to the directory; otherwise NULL.
Definition: fs_api.h:237
struct GNUNET_FS_Uri * chk_uri
CHK for this file or directory.
Definition: fs_api.h:263
int is_directory
Is this struct for a file or directory?
Definition: fs_api.h:390
Master context for most FS operations.
Definition: fs_api.h:1069
enum GNUNET_FS_Flags flags
General flags.
Definition: fs_api.h:1161
char * client_name
Name of our client.
Definition: fs_api.h:1078
void * upcb_cls
Closure for upcb.
Definition: fs_api.h:1088
GNUNET_FS_ProgressCallback upcb
Function to call with updates on our progress.
Definition: fs_api.h:1083
Argument given to the progress callback with information about what is going on.
struct GNUNET_FS_ProgressInfo::@25::GNUNET_FS_SearchStatusEvent search
const struct GNUNET_FS_FileInformation * fi
Information about the file that is being published.
Handle for controlling a publication process.
Definition: fs_api.h:1179
int skip_next_fi_callback
Flag set to GNUNET_YES if the next callback from GNUNET_FS_file_information_inspect should be skipped...
Definition: fs_api.h:1298
enum GNUNET_FS_PublishOptions options
Options for publishing.
Definition: fs_api.h:1274
struct GNUNET_DATASTORE_Handle * dsh
Connection to the datastore service.
Definition: fs_api.h:1235
struct TopLevelActivity * top
Our top-level activity entry (if we are top-level, otherwise NULL).
Definition: fs_api.h:1188
struct GNUNET_FS_FileInformation * fi_pos
Current position in the file-tree for the upload.
Definition: fs_api.h:1225
char * nuid
ID for future updates, NULL if we have no namespace or no updates.
Definition: fs_api.h:1208
int all_done
Set to GNUNET_YES if all processing has completed.
Definition: fs_api.h:1291
struct GNUNET_FS_FileInformation * fi
File-structure that is being shared.
Definition: fs_api.h:1193
char * nid
ID of the content in the namespace, NULL if we have no namespace.
Definition: fs_api.h:1203
struct GNUNET_FS_Handle * h
Handle to the global fs context.
Definition: fs_api.h:1183
struct GNUNET_CRYPTO_EcdsaPrivateKey * ns
Namespace that we are publishing in, NULL if we have no namespace.
Definition: fs_api.h:1198
struct GNUNET_SCHEDULER_Task * upload_task
ID of the task performing the upload.
Definition: fs_api.h:1258
char * serialization
Filename used for serializing information about this operation (should be determined using 'mktemp').
Definition: fs_api.h:1214
Entry in the job queue.
Definition: fs_api.h:420
GNUNET_SCHEDULER_TaskCallback stop
Function to call when the job needs to stop (or is done / dequeued).
Definition: fs_api.h:439
void * cls
Closure for start and stop.
Definition: fs_api.h:444
enum GNUNET_FS_QueuePriority priority
How important is this download?
Definition: fs_api.h:480
unsigned int blocks
How many blocks do the active downloads have?
Definition: fs_api.h:475
struct GNUNET_FS_QueueEntry * next
This is a linked list.
Definition: fs_api.h:424
Handle for controlling a search.
Definition: fs_api.h:1510
struct GNUNET_CONTAINER_MultiHashMap * master_result_map
Map that contains a struct GNUNET_FS_SearchResult for each result that was found in the search.
Definition: fs_api.h:1558
char * emsg
Error message (non-NULL if this operation failed).
Definition: fs_api.h:1550
char * serialization
Name of the file on disk we use for persistence.
Definition: fs_api.h:1545
void * client_info
Pointer we keep for the client.
Definition: fs_api.h:1540
struct GNUNET_FS_SearchResult * psearch_result
For update-searches, link to the search result that triggered the update search; otherwise NULL.
Definition: fs_api.h:1530
struct GNUNET_SCHEDULER_Task * task
ID of a task that is using this struct and that must be cancelled when the search is being stopped (i...
Definition: fs_api.h:1582
enum GNUNET_FS_SearchOptions options
Options for the search.
Definition: fs_api.h:1597
uint32_t anonymity
Anonymity level for the search.
Definition: fs_api.h:1587
struct TopLevelActivity * top
Our top-level activity entry (if we are top-level, otherwise NULL).
Definition: fs_api.h:1519
struct GNUNET_FS_Uri * uri
List of keywords that we're looking for.
Definition: fs_api.h:1524
struct GNUNET_FS_Handle * h
Handle to the global FS context.
Definition: fs_api.h:1514
struct GNUNET_MQ_Handle * mq
Connection to the FS service.
Definition: fs_api.h:1535
struct GNUNET_TIME_Absolute start_time
When did we start?
Definition: fs_api.h:1569
Information we store for each search result.
Definition: fs_api.h:498
uint32_t optional_support
Number of optional keywords under which this result was also found.
Definition: fs_api.h:601
struct GNUNET_FS_DownloadContext * download
ID of an associated download based on this search result (or NULL for none).
Definition: fs_api.h:545
struct GNUNET_FS_SearchContext * update_search
If this search result triggered an update search, this field links to the update search.
Definition: fs_api.h:551
void * client_info
Client info for this search result.
Definition: fs_api.h:533
uint32_t availability_trials
Number of availability trials that we have performed for this search result.
Definition: fs_api.h:612
struct GNUNET_FS_Uri * uri
URI to which this search result refers to.
Definition: fs_api.h:523
uint8_t * keyword_bitmap
Bitmap that specifies precisely which keywords have been matched already.
Definition: fs_api.h:561
struct GNUNET_FS_Handle * h
File-sharing context this result belongs to.
Definition: fs_api.h:502
struct GNUNET_HashCode key
Key for the search result based on the URI.
Definition: fs_api.h:566
char * serialization
Name under which this search result is stored on disk.
Definition: fs_api.h:556
struct GNUNET_CONTAINER_MetaData * meta
Metadata for the search result.
Definition: fs_api.h:528
uint32_t availability_success
Number of availability tests that have succeeded for this result.
Definition: fs_api.h:606
struct GNUNET_FS_SearchContext * sc
Search context this result belongs to; can be NULL for probes that come from a directory result.
Definition: fs_api.h:518
uint32_t mandatory_missing
Number of mandatory keywords for which we have NOT yet found the search result; when this value hits ...
Definition: fs_api.h:595
Handle for controlling an unindexing operation.
Definition: fs_api.h:1350
enum UnindexState state
Current operatinonal phase.
Definition: fs_api.h:1463
char * emsg
Error message, NULL on success.
Definition: fs_api.h:1438
struct GNUNET_TIME_Absolute start_time
When did we start?
Definition: fs_api.h:1453
struct ContentHashKey chk
The content hash key of the last block we processed, will in the end be set to the CHK from the URI.
Definition: fs_api.h:1355
struct GNUNET_CRYPTO_FileHashContext * fhc
Context for hashing of the file.
Definition: fs_api.h:1443
struct TopLevelActivity * top
Our top-level activity entry.
Definition: fs_api.h:1365
char * filename
Name of the file that we are unindexing.
Definition: fs_api.h:1385
struct GNUNET_FS_Handle * h
Global FS context.
Definition: fs_api.h:1360
uint32_t ksk_offset
Current offset in KSK removal.
Definition: fs_api.h:1380
char * serialization
Short name under which we are serializing the state of this operation.
Definition: fs_api.h:1390
struct GNUNET_FS_Uri * ksk_uri
Keywords found (telling us which KBlocks to remove).
Definition: fs_api.h:1375
struct GNUNET_HashCode file_id
Hash of the file's contents (once computed).
Definition: fs_api.h:1458
uint64_t file_size
Overall size of the file.
Definition: fs_api.h:1448
A Universal Resource Identifier (URI), opaque.
Definition: fs_api.h:166
struct GNUNET_FS_Uri::@13::@14 ksk
union GNUNET_FS_Uri::@13 data
enum GNUNET_FS_UriType type
Type of the URI.
Definition: fs_api.h:170
A 512-bit hashcode.
Time for absolute times used by GNUnet, in microseconds.
uint64_t abs_value_us
The actual value.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.
We track all of the top-level activities of FS so that we can signal 'suspend' on shutdown.
Definition: fs_api.h:1017
void * ssf_cls
Closure for 'ssf' (some struct GNUNET_FS_XXXHandle*)
Definition: fs_api.h:1036
SuspendSignalFunction ssf
Function to call for suspend-signalling and clean up.
Definition: fs_api.h:1031