GNUnet  0.11.x
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++;
59  "Starting job %p (%u active)\n",
60  qe,
61  qe->h->active_downloads);
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;
86  qe->start_time));
88  "Stopping job %p (%u active)\n",
89  qe,
90  qe->h->active_downloads);
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;
114  struct GNUNET_TIME_Absolute end_time;
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);
164  rst = GNUNET_TIME_absolute_get_remaining (end_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 =
180  qe->blocks * qe->start_times);
181  end_time = GNUNET_TIME_absolute_add (qe->start_time, run_time);
182  rst = GNUNET_TIME_absolute_get_remaining (end_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  }
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 <=
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,
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)
314  h->queue_job =
316 }
317 
318 
330 struct GNUNET_FS_QueueEntry *
334  void *cls,
335  unsigned int blocks,
337 {
338  struct GNUNET_FS_QueueEntry *qe;
339 
340  qe = GNUNET_new (struct GNUNET_FS_QueueEntry);
341  qe->h = h;
342  qe->start = start;
343  qe->stop = stop;
344  qe->cls = cls;
346  qe->blocks = blocks;
347  qe->priority = priority;
349  h->pending_tail,
350  h->pending_tail,
351  qe);
352  if (NULL != h->queue_job)
355  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Queueing job %p\n", qe);
356  return qe;
357 }
358 
359 
365 void
367 {
368  struct GNUNET_FS_Handle *h;
369 
370  h = qe->h;
371  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Dequeueing job %p\n", qe);
372  if (GNUNET_YES == qe->active)
373  stop_job (qe);
375  GNUNET_free (qe);
376  if (NULL != h->queue_job)
379 }
380 
381 
390 struct TopLevelActivity *
393  void *ssf_cls)
394 {
395  struct TopLevelActivity *ret;
396 
397  ret = GNUNET_new (struct TopLevelActivity);
398  ret->ssf = ssf;
399  ret->ssf_cls = ssf_cls;
401  return ret;
402 }
403 
404 
411 void
413 {
415  GNUNET_free (top);
416 }
417 
418 
422 struct FileInfo
423 {
427  char *filename;
428 
433 };
434 
435 
456 size_t
458  uint64_t offset,
459  size_t max,
460  void *buf,
461  char **emsg)
462 {
463  struct FileInfo *fi = cls;
464  ssize_t ret;
465 
466  if (UINT64_MAX == offset)
467  {
468  if (NULL != fi->fd)
469  {
471  fi->fd = NULL;
472  }
473  return 0;
474  }
475  if (0 == max)
476  {
477  if (NULL != fi->fd)
479  GNUNET_free (fi->filename);
480  GNUNET_free (fi);
481  return 0;
482  }
483  if (NULL == fi->fd)
484  {
485  fi->fd = GNUNET_DISK_file_open (fi->filename,
488  if (NULL == fi->fd)
489  {
490  GNUNET_asprintf (emsg,
491  _ ("Could not open file `%s': %s"),
492  fi->filename,
493  strerror (errno));
494  return 0;
495  }
496  }
497  if ((GNUNET_SYSERR ==
499  (-1 == (ret = GNUNET_DISK_file_read (fi->fd, buf, max))))
500  {
501  GNUNET_asprintf (emsg,
502  _ ("Could not read file `%s': %s"),
503  fi->filename,
504  strerror (errno));
505  return 0;
506  }
507  if (ret != max)
508  {
509  GNUNET_asprintf (emsg,
510  _ ("Short read reading from file `%s'!"),
511  fi->filename);
512  return 0;
513  }
514  return max;
515 }
516 
517 
524 void *
526 {
527  struct FileInfo *fi;
528 
529  fi = GNUNET_new (struct FileInfo);
530  fi->filename = GNUNET_STRINGS_filename_expand (filename);
531  if (NULL == fi->filename)
532  {
533  GNUNET_free (fi);
534  return NULL;
535  }
536  return fi;
537 }
538 
539 
560 size_t
562  uint64_t offset,
563  size_t max,
564  void *buf,
565  char **emsg)
566 {
567  char *data = cls;
568 
569  if (UINT64_MAX == offset)
570  return 0;
571  if (0 == max)
572  {
573  GNUNET_free_non_null (data);
574  return 0;
575  }
576  GNUNET_memcpy (buf, &data[offset], max);
577  return max;
578 }
579 
580 
590 static char *
592  const char *ext,
593  const char *ent)
594 {
595  char *basename;
596  char *ret;
597 
598  if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
599  return NULL; /* persistence not requested */
601  "fs",
602  "STATE_DIR",
603  &basename))
604  return NULL;
605  GNUNET_asprintf (&ret,
606  "%s%s%s%s%s%s%s",
607  basename,
609  h->client_name,
611  ext,
613  ent);
614  GNUNET_free (basename);
615  return ret;
616 }
617 
618 
630 static char *
632  const char *ext,
633  const char *uni,
634  const char *ent)
635 {
636  char *basename;
637  char *ret;
638 
639  if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
640  return NULL; /* persistence not requested */
642  "fs",
643  "STATE_DIR",
644  &basename))
645  return NULL;
646  GNUNET_asprintf (&ret,
647  "%s%s%s%s%s%s%s.dir%s%s",
648  basename,
650  h->client_name,
652  ext,
654  uni,
656  ent);
657  GNUNET_free (basename);
658  return ret;
659 }
660 
661 
670 static struct GNUNET_BIO_ReadHandle *
671 get_read_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
672 {
673  char *fn;
674  struct GNUNET_BIO_ReadHandle *ret;
675 
676  fn = get_serialization_file_name (h, ext, ent);
677  if (NULL == fn)
678  return NULL;
679  ret = GNUNET_BIO_read_open (fn);
680  GNUNET_free (fn);
681  return ret;
682 }
683 
684 
693 static struct GNUNET_BIO_WriteHandle *
694 get_write_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
695 {
696  char *fn;
697  struct GNUNET_BIO_WriteHandle *ret;
698 
699  fn = get_serialization_file_name (h, ext, ent);
700  if (NULL == fn)
701  return NULL;
702  ret = GNUNET_BIO_write_open (fn);
703  GNUNET_break (NULL != ret);
704  GNUNET_free (fn);
705  return ret;
706 }
707 
708 
718 static struct GNUNET_BIO_WriteHandle *
720  const char *ext,
721  const char *uni,
722  const char *ent)
723 {
724  char *fn;
725  struct GNUNET_BIO_WriteHandle *ret;
726 
727  fn = get_serialization_file_name_in_dir (h, ext, uni, ent);
728  if (NULL == fn)
729  return NULL;
730  ret = GNUNET_BIO_write_open (fn);
731  GNUNET_free (fn);
732  return ret;
733 }
734 
735 
743 void
745  const char *ext,
746  const char *ent)
747 {
748  char *filename;
749 
750  if ((NULL == ent) || (0 == strlen (ent)))
751  {
752  GNUNET_break (0);
753  return;
754  }
755  filename = get_serialization_file_name (h, ext, ent);
756  if (NULL != filename)
757  {
758  if ((0 != unlink (filename)) && (ENOENT != errno))
760  GNUNET_free (filename);
761  }
762 }
763 
764 
773 static void
775  const char *ext,
776  const char *uni,
777  const char *ent)
778 {
779  char *filename;
780 
781  if ((NULL == ent) || (0 == strlen (ent)))
782  {
783  GNUNET_break (0);
784  return;
785  }
786  filename = get_serialization_file_name_in_dir (h, ext, uni, ent);
787  if (NULL == filename)
788  return;
789  if (0 != unlink (filename))
791  GNUNET_free (filename);
792 }
793 
794 
802 void
804  const char *ext,
805  const char *uni)
806 {
807  char *dn;
808 
809  if (NULL == uni)
810  return;
811  dn = get_serialization_file_name_in_dir (h, ext, uni, "");
812  if (NULL == dn)
813  return;
817  GNUNET_free (dn);
818 }
819 
820 
835 static int
837  struct GNUNET_TIME_Absolute timestamp)
838 {
839  struct GNUNET_TIME_Relative dur;
840 
841  dur = GNUNET_TIME_absolute_get_duration (timestamp);
842  return GNUNET_BIO_write_int64 (wh, dur.rel_value_us);
843 }
844 
845 
860 static int
862  struct GNUNET_TIME_Absolute *timestamp)
863 {
864  struct GNUNET_TIME_Relative dur;
865 
866  if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dur.rel_value_us))
867  return GNUNET_SYSERR;
869  return GNUNET_OK;
870 }
871 
872 
882 static struct GNUNET_FS_FileInformation *
884 
885 
896 static struct GNUNET_FS_FileInformation *
898  const char *fn,
899  struct GNUNET_BIO_ReadHandle *rh)
900 {
902  struct GNUNET_FS_FileInformation *nxt;
903  char b;
904  char *ksks;
905  char *chks;
906  char *skss;
907  char *filename;
908  uint32_t dsize;
909 
910  if (GNUNET_OK != GNUNET_BIO_read (rh, "status flag", &b, sizeof(b)))
911  {
912  GNUNET_break (0);
913  return NULL;
914  }
915  ret = GNUNET_new (struct GNUNET_FS_FileInformation);
916  ret->h = h;
917  ksks = NULL;
918  chks = NULL;
919  skss = NULL;
920  filename = NULL;
921  if ((GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "metadata", &ret->meta)) ||
922  (GNUNET_OK != GNUNET_BIO_read_string (rh, "ksk-uri", &ksks, 32 * 1024)) ||
923  ((NULL != ksks) &&
924  ((NULL == (ret->keywords = GNUNET_FS_uri_parse (ksks, NULL))) ||
926  (GNUNET_OK != GNUNET_BIO_read_string (rh, "chk-uri", &chks, 1024)) ||
927  ((NULL != chks) &&
928  ((NULL == (ret->chk_uri = GNUNET_FS_uri_parse (chks, NULL))) ||
929  (GNUNET_YES != GNUNET_FS_uri_test_chk (ret->chk_uri)))) ||
930  (GNUNET_OK != GNUNET_BIO_read_string (rh, "sks-uri", &skss, 1024)) ||
931  ((NULL != skss) &&
932  ((NULL == (ret->sks_uri = GNUNET_FS_uri_parse (skss, NULL))) ||
933  (GNUNET_YES != GNUNET_FS_uri_test_sks (ret->sks_uri)))) ||
934  (GNUNET_OK != read_start_time (rh, &ret->start_time)) ||
935  (GNUNET_OK !=
936  GNUNET_BIO_read_string (rh, "emsg", &ret->emsg, 16 * 1024)) ||
937  (GNUNET_OK !=
938  GNUNET_BIO_read_string (rh, "fn", &ret->filename, 16 * 1024)) ||
939  (GNUNET_OK !=
944  {
945  GNUNET_break (0);
946  goto cleanup;
947  }
948  switch (b)
949  {
950  case 0: /* file-insert */
951  if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size))
952  {
953  GNUNET_break (0);
954  goto cleanup;
955  }
956  ret->is_directory = GNUNET_NO;
957  ret->data.file.do_index = GNUNET_NO;
958  ret->data.file.have_hash = GNUNET_NO;
959  ret->data.file.index_start_confirmed = GNUNET_NO;
960  if (GNUNET_NO == ret->is_published)
961  {
962  if (NULL == ret->filename)
963  {
964  ret->data.file.reader = &GNUNET_FS_data_reader_copy_;
965  ret->data.file.reader_cls =
966  GNUNET_malloc_large (ret->data.file.file_size);
967  if (ret->data.file.reader_cls == NULL)
968  goto cleanup;
969  if (GNUNET_OK != GNUNET_BIO_read (rh,
970  "file-data",
971  ret->data.file.reader_cls,
972  ret->data.file.file_size))
973  {
974  GNUNET_break (0);
975  goto cleanup;
976  }
977  }
978  else
979  {
980  ret->data.file.reader = &GNUNET_FS_data_reader_file_;
981  ret->data.file.reader_cls =
983  }
984  }
985  break;
986 
987  case 1: /* file-index, no hash */
988  if (NULL == ret->filename)
989  {
990  GNUNET_break (0);
991  goto cleanup;
992  }
993  if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size))
994  {
995  GNUNET_break (0);
996  goto cleanup;
997  }
998  ret->is_directory = GNUNET_NO;
999  ret->data.file.do_index = GNUNET_YES;
1000  ret->data.file.have_hash = GNUNET_NO;
1001  ret->data.file.index_start_confirmed = GNUNET_NO;
1002  ret->data.file.reader = &GNUNET_FS_data_reader_file_;
1003  ret->data.file.reader_cls =
1005  break;
1006 
1007  case 2: /* file-index-with-hash */
1008  if (NULL == ret->filename)
1009  {
1010  GNUNET_break (0);
1011  goto cleanup;
1012  }
1013  if ((GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) ||
1014  (GNUNET_OK != GNUNET_BIO_read (rh,
1015  "fileid",
1016  &ret->data.file.file_id,
1017  sizeof(struct GNUNET_HashCode))))
1018  {
1019  GNUNET_break (0);
1020  goto cleanup;
1021  }
1022  ret->is_directory = GNUNET_NO;
1023  ret->data.file.do_index = GNUNET_YES;
1024  ret->data.file.have_hash = GNUNET_YES;
1025  ret->data.file.index_start_confirmed = GNUNET_NO;
1026  ret->data.file.reader = &GNUNET_FS_data_reader_file_;
1027  ret->data.file.reader_cls =
1029  break;
1030 
1031  case 3: /* file-index-with-hash-confirmed */
1032  if (NULL == ret->filename)
1033  {
1034  GNUNET_break (0);
1035  goto cleanup;
1036  }
1037  if ((GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) ||
1038  (GNUNET_OK != GNUNET_BIO_read (rh,
1039  "fileid",
1040  &ret->data.file.file_id,
1041  sizeof(struct GNUNET_HashCode))))
1042  {
1043  GNUNET_break (0);
1044  goto cleanup;
1045  }
1046  ret->is_directory = GNUNET_NO;
1047  ret->data.file.do_index = GNUNET_YES;
1048  ret->data.file.have_hash = GNUNET_YES;
1049  ret->data.file.index_start_confirmed = GNUNET_YES;
1050  ret->data.file.reader = &GNUNET_FS_data_reader_file_;
1051  ret->data.file.reader_cls =
1053  break;
1054 
1055  case 4: /* directory */
1056  ret->is_directory = GNUNET_YES;
1057  if ((GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dsize)) ||
1058  (GNUNET_OK !=
1060  (GNUNET_OK !=
1062  (NULL == (ret->data.dir.dir_data = GNUNET_malloc_large (dsize))) ||
1063  (GNUNET_OK !=
1064  GNUNET_BIO_read (rh, "dir-data", ret->data.dir.dir_data, dsize)) ||
1065  (GNUNET_OK !=
1066  GNUNET_BIO_read_string (rh, "ent-filename", &filename, 16 * 1024)))
1067  {
1068  GNUNET_break (0);
1069  goto cleanup;
1070  }
1071  ret->data.dir.dir_size = (uint32_t) dsize;
1072  if (NULL != filename)
1073  {
1074  ret->data.dir.entries = deserialize_file_information (h, filename);
1075  GNUNET_free (filename);
1076  filename = NULL;
1077  nxt = ret->data.dir.entries;
1078  while (NULL != nxt)
1079  {
1080  nxt->dir = ret;
1081  nxt = nxt->next;
1082  }
1083  }
1084  break;
1085 
1086  default:
1087  GNUNET_break (0);
1088  goto cleanup;
1089  }
1090  ret->serialization = GNUNET_strdup (fn);
1091  if (GNUNET_OK !=
1092  GNUNET_BIO_read_string (rh, "nxt-filename", &filename, 16 * 1024))
1093  {
1094  GNUNET_break (0);
1095  goto cleanup;
1096  }
1097  if (NULL != filename)
1098  {
1099  ret->next = deserialize_file_information (h, filename);
1100  GNUNET_free (filename);
1101  filename = NULL;
1102  }
1103  GNUNET_free_non_null (ksks);
1104  GNUNET_free_non_null (skss);
1105  GNUNET_free_non_null (chks);
1106  return ret;
1107 cleanup:
1108  GNUNET_free_non_null (ksks);
1109  GNUNET_free_non_null (chks);
1110  GNUNET_free_non_null (skss);
1111  GNUNET_free_non_null (filename);
1112  GNUNET_FS_file_information_destroy (ret, NULL, NULL);
1113  return NULL;
1114 }
1115 
1116 
1126 static struct GNUNET_FS_FileInformation *
1128 {
1130  struct GNUNET_BIO_ReadHandle *rh;
1131  char *emsg;
1132  char *fn;
1133 
1134  rh = get_read_handle (h, GNUNET_FS_SYNC_PATH_FILE_INFO, filename);
1135  if (NULL == rh)
1136  return NULL;
1137  ret = deserialize_fi_node (h, filename, rh);
1138  if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
1139  {
1141  _ ("Failed to resume publishing information `%s': %s\n"),
1142  filename,
1143  emsg);
1144  GNUNET_free (emsg);
1145  }
1146  if (NULL == ret)
1147  {
1148  fn =
1150  if (NULL != fn)
1151  {
1152  if (0 != unlink (fn))
1154  GNUNET_free (fn);
1155  }
1156  }
1157  return ret;
1158 }
1159 
1160 
1169 static char *
1170 get_serialization_short_name (const char *fullname)
1171 {
1172  const char *end;
1173  const char *nxt;
1174 
1175  end = NULL;
1176  nxt = fullname;
1177  /* FIXME: we could do this faster since we know
1178  * the length of 'end'... */
1179  while ('\0' != *nxt)
1180  {
1181  if (DIR_SEPARATOR == *nxt)
1182  end = nxt + 1;
1183  nxt++;
1184  }
1185  if ((NULL == end) || (0 == strlen (end)))
1186  {
1187  GNUNET_break (0);
1188  return NULL;
1189  }
1190  GNUNET_break (6 == strlen (end));
1191  return GNUNET_strdup (end);
1192 }
1193 
1194 
1203 static char *
1205 {
1206  char *fn;
1207  char *dn;
1208  char *ret;
1209 
1210  if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
1211  return NULL; /* persistence not requested */
1212  dn = get_serialization_file_name (h, ext, "");
1213  if (NULL == dn)
1214  return NULL;
1216  {
1217  GNUNET_free (dn);
1218  return NULL;
1219  }
1220  fn = GNUNET_DISK_mktemp (dn);
1221  GNUNET_free (dn);
1222  if (NULL == fn)
1223  return NULL; /* epic fail */
1224  ret = get_serialization_short_name (fn);
1225  GNUNET_free (fn);
1226  return ret;
1227 }
1228 
1229 
1239 static char *
1241  const char *ext,
1242  const char *uni)
1243 {
1244  char *fn;
1245  char *dn;
1246  char *ret;
1247 
1248  if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
1249  return NULL; /* persistence not requested */
1250  dn = get_serialization_file_name_in_dir (h, ext, uni, "");
1251  if (NULL == dn)
1252  return NULL;
1254  {
1255  GNUNET_free (dn);
1256  return NULL;
1257  }
1258  fn = GNUNET_DISK_mktemp (dn);
1259  GNUNET_free (dn);
1260  if (NULL == fn)
1261  return NULL; /* epic fail */
1262  ret = get_serialization_short_name (fn);
1263  GNUNET_free (fn);
1264  return ret;
1265 }
1266 
1267 
1275 static int
1277  struct GNUNET_FS_FileInformation *fi)
1278 {
1279  char buf[32 * 1024];
1280  uint64_t off;
1281  size_t ret;
1282  size_t left;
1283  char *emsg;
1284 
1285  emsg = NULL;
1286  off = 0;
1287  while (off < fi->data.file.file_size)
1288  {
1289  left = GNUNET_MIN (sizeof(buf), fi->data.file.file_size - off);
1290  ret =
1291  fi->data.file.reader (fi->data.file.reader_cls, off, left, buf, &emsg);
1292  if (0 == ret)
1293  {
1294  GNUNET_free (emsg);
1295  return GNUNET_SYSERR;
1296  }
1297  if (GNUNET_OK != GNUNET_BIO_write (wh, buf, ret))
1298  return GNUNET_SYSERR;
1299  off += ret;
1300  }
1301  return GNUNET_OK;
1302 }
1303 
1304 
1311 void
1313 {
1314  char *fn;
1315  struct GNUNET_BIO_WriteHandle *wh;
1316  char b;
1317  char *ksks;
1318  char *chks;
1319  char *skss;
1320 
1321  if (NULL == fi->serialization)
1322  fi->serialization =
1324  if (NULL == fi->serialization)
1325  return;
1326  wh =
1328  if (NULL == wh)
1329  {
1330  GNUNET_free (fi->serialization);
1331  fi->serialization = NULL;
1332  return;
1333  }
1334  if (GNUNET_YES == fi->is_directory)
1335  b = 4;
1336  else if (GNUNET_YES == fi->data.file.index_start_confirmed)
1337  b = 3;
1338  else if (GNUNET_YES == fi->data.file.have_hash)
1339  b = 2;
1340  else if (GNUNET_YES == fi->data.file.do_index)
1341  b = 1;
1342  else
1343  b = 0;
1344  if (NULL != fi->keywords)
1345  ksks = GNUNET_FS_uri_to_string (fi->keywords);
1346  else
1347  ksks = NULL;
1348  if (NULL != fi->chk_uri)
1349  chks = GNUNET_FS_uri_to_string (fi->chk_uri);
1350  else
1351  chks = NULL;
1352  if (NULL != fi->sks_uri)
1353  skss = GNUNET_FS_uri_to_string (fi->sks_uri);
1354  else
1355  skss = NULL;
1356  if ((GNUNET_OK != GNUNET_BIO_write (wh, &b, sizeof(b))) ||
1357  (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, fi->meta)) ||
1358  (GNUNET_OK != GNUNET_BIO_write_string (wh, ksks)) ||
1359  (GNUNET_OK != GNUNET_BIO_write_string (wh, chks)) ||
1360  (GNUNET_OK != GNUNET_BIO_write_string (wh, skss)) ||
1361  (GNUNET_OK != write_start_time (wh, fi->start_time)) ||
1362  (GNUNET_OK != GNUNET_BIO_write_string (wh, fi->emsg)) ||
1363  (GNUNET_OK != GNUNET_BIO_write_string (wh, fi->filename)) ||
1364  (GNUNET_OK !=
1369  {
1370  GNUNET_break (0);
1371  goto cleanup;
1372  }
1373  GNUNET_free_non_null (chks);
1374  chks = NULL;
1375  GNUNET_free_non_null (ksks);
1376  ksks = NULL;
1377  GNUNET_free_non_null (skss);
1378  skss = NULL;
1379 
1380  switch (b)
1381  {
1382  case 0: /* file-insert */
1383  if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size))
1384  {
1385  GNUNET_break (0);
1386  goto cleanup;
1387  }
1388  if ((GNUNET_NO == fi->is_published) && (NULL == fi->filename))
1389  if (GNUNET_OK != copy_from_reader (wh, fi))
1390  {
1391  GNUNET_break (0);
1392  goto cleanup;
1393  }
1394  break;
1395 
1396  case 1: /* file-index, no hash */
1397  if (NULL == fi->filename)
1398  {
1399  GNUNET_break (0);
1400  goto cleanup;
1401  }
1402  if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size))
1403  {
1404  GNUNET_break (0);
1405  goto cleanup;
1406  }
1407  break;
1408 
1409  case 2: /* file-index-with-hash */
1410  case 3: /* file-index-with-hash-confirmed */
1411  if (NULL == fi->filename)
1412  {
1413  GNUNET_break (0);
1414  goto cleanup;
1415  }
1416  if ((GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) ||
1417  (GNUNET_OK != GNUNET_BIO_write (wh,
1418  &fi->data.file.file_id,
1419  sizeof(struct GNUNET_HashCode))))
1420  {
1421  GNUNET_break (0);
1422  goto cleanup;
1423  }
1424  break;
1425 
1426  case 4: /* directory */
1427  if ((NULL != fi->data.dir.entries) &&
1428  (NULL == fi->data.dir.entries->serialization))
1430  if ((GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->data.dir.dir_size)) ||
1431  (GNUNET_OK !=
1433  (GNUNET_OK !=
1435  (GNUNET_OK != GNUNET_BIO_write (wh,
1436  fi->data.dir.dir_data,
1437  (uint32_t) fi->data.dir.dir_size)) ||
1438  (GNUNET_OK !=
1440  (fi->data.dir.entries == NULL)
1441  ? NULL
1442  : fi->data.dir.entries->serialization)))
1443  {
1444  GNUNET_break (0);
1445  goto cleanup;
1446  }
1447  break;
1448 
1449  default:
1450  GNUNET_assert (0);
1451  goto cleanup;
1452  }
1453  if ((NULL != fi->next) && (NULL == fi->next->serialization))
1456  (fi->next != NULL)
1457  ? fi->next->serialization
1458  : NULL))
1459  {
1460  GNUNET_break (0);
1461  goto cleanup;
1462  }
1463  if (GNUNET_OK != GNUNET_BIO_write_close (wh))
1464  {
1465  wh = NULL;
1466  GNUNET_break (0);
1467  goto cleanup;
1468  }
1469  return; /* done! */
1470 cleanup:
1471  if (NULL != wh)
1472  (void) GNUNET_BIO_write_close (wh);
1473  GNUNET_free_non_null (chks);
1474  GNUNET_free_non_null (ksks);
1475  GNUNET_free_non_null (skss);
1476  fn = get_serialization_file_name (fi->h,
1478  fi->serialization);
1479  if (NULL != fn)
1480  {
1481  if (0 != unlink (fn))
1483  GNUNET_free (fn);
1484  }
1485  GNUNET_free (fi->serialization);
1486  fi->serialization = NULL;
1487 }
1488 
1489 
1498 static struct GNUNET_FS_FileInformation *
1499 find_file_position (struct GNUNET_FS_FileInformation *pos, const char *srch)
1500 {
1501  struct GNUNET_FS_FileInformation *r;
1502 
1503  while (NULL != pos)
1504  {
1505  if (0 == strcmp (srch, pos->serialization))
1506  return pos;
1507  if ((GNUNET_YES == pos->is_directory) &&
1508  (NULL != (r = find_file_position (pos->data.dir.entries, srch))))
1509  return r;
1510  pos = pos->next;
1511  }
1512  return NULL;
1513 }
1514 
1515 
1530 static int
1532  struct GNUNET_FS_FileInformation *fi,
1533  uint64_t length,
1535  struct GNUNET_FS_Uri **uri,
1536  struct GNUNET_FS_BlockOptions *bo,
1537  int *do_index,
1538  void **client_info)
1539 {
1540  struct GNUNET_FS_PublishContext *pc = cls;
1541  struct GNUNET_FS_ProgressInfo pi;
1542 
1543  if (GNUNET_YES == pc->skip_next_fi_callback)
1544  {
1546  return GNUNET_OK;
1547  }
1549  pi.value.publish.specifics.resume.message = fi->emsg;
1550  pi.value.publish.specifics.resume.chk_uri = fi->chk_uri;
1551  *client_info = GNUNET_FS_publish_make_status_ (&pi, pc, fi, 0);
1553  {
1554  /* process entries in directory */
1557  }
1558  return GNUNET_OK;
1559 }
1560 
1561 
1570 static int
1571 deserialize_publish_file (void *cls, const char *filename)
1572 {
1573  struct GNUNET_FS_Handle *h = cls;
1574  struct GNUNET_BIO_ReadHandle *rh;
1575  struct GNUNET_FS_PublishContext *pc;
1576  int32_t options;
1577  int32_t all_done;
1578  int32_t have_ns;
1579  char *fi_root;
1581  char *fi_pos;
1582  char *emsg;
1583 
1584  pc = GNUNET_new (struct GNUNET_FS_PublishContext);
1585  pc->h = h;
1587  fi_root = NULL;
1588  fi_pos = NULL;
1589  rh = GNUNET_BIO_read_open (filename);
1590  if (NULL == rh)
1591  {
1592  GNUNET_break (0);
1593  goto cleanup;
1594  }
1595  if ((GNUNET_OK !=
1596  GNUNET_BIO_read_string (rh, "publish-nid", &pc->nid, 1024)) ||
1597  (GNUNET_OK !=
1598  GNUNET_BIO_read_string (rh, "publish-nuid", &pc->nuid, 1024)) ||
1599  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &options)) ||
1600  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &all_done)) ||
1601  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &have_ns)) ||
1602  (GNUNET_OK !=
1603  GNUNET_BIO_read_string (rh, "publish-firoot", &fi_root, 128)) ||
1604  (GNUNET_OK !=
1605  GNUNET_BIO_read_string (rh, "publish-fipos", &fi_pos, 128)) ||
1606  ((GNUNET_YES == have_ns) &&
1607  (GNUNET_OK != GNUNET_BIO_read (rh, "publish-ns", &ns, sizeof(ns)))))
1608  {
1609  GNUNET_break (0);
1610  goto cleanup;
1611  }
1612  pc->options = options;
1613  pc->all_done = all_done;
1614  if (NULL == fi_root)
1615  {
1616  GNUNET_break (0);
1617  goto cleanup;
1618  }
1619  pc->fi = deserialize_file_information (h, fi_root);
1620  if (NULL == pc->fi)
1621  {
1622  GNUNET_break (0);
1623  goto cleanup;
1624  }
1625  if (GNUNET_YES == have_ns)
1626  {
1628  *pc->ns = ns;
1629  }
1630  if ((0 == (pc->options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) &&
1631  (GNUNET_YES != pc->all_done))
1632  {
1633  pc->dsh = GNUNET_DATASTORE_connect (h->cfg);
1634  if (NULL == pc->dsh)
1635  goto cleanup;
1636  }
1637  if (NULL != fi_pos)
1638  {
1639  pc->fi_pos = find_file_position (pc->fi, fi_pos);
1640  GNUNET_free (fi_pos);
1641  fi_pos = NULL;
1642  if (NULL == pc->fi_pos)
1643  {
1644  /* failed to find position for resuming, outch! Will start from root! */
1645  GNUNET_break (0);
1646  if (GNUNET_YES != pc->all_done)
1647  pc->fi_pos = pc->fi;
1648  }
1649  }
1650  GNUNET_free (fi_root);
1651  fi_root = NULL;
1652  /* generate RESUME event(s) */
1654 
1655  /* re-start publishing (if needed)... */
1656  if (GNUNET_YES != pc->all_done)
1657  {
1658  GNUNET_assert (NULL == pc->upload_task);
1659  pc->upload_task =
1662  pc);
1663  }
1664  if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
1665  {
1667  _ ("Failure while resuming publishing operation `%s': %s\n"),
1668  filename,
1669  emsg);
1670  GNUNET_free (emsg);
1671  }
1673  return GNUNET_OK;
1674 cleanup:
1675  GNUNET_free_non_null (pc->nid);
1676  GNUNET_free_non_null (pc->nuid);
1677  GNUNET_free_non_null (fi_root);
1678  GNUNET_free_non_null (fi_pos);
1679  if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)))
1680  {
1682  _ ("Failed to resume publishing operation `%s': %s\n"),
1683  filename,
1684  emsg);
1685  GNUNET_free (emsg);
1686  }
1687  if (NULL != pc->fi)
1688  GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL);
1689  if (0 != unlink (filename))
1691  GNUNET_free (pc->serialization);
1692  GNUNET_free (pc);
1693  return GNUNET_OK;
1694 }
1695 
1696 
1705 void
1707 {
1708  struct GNUNET_BIO_WriteHandle *wh;
1709  int32_t have_ns;
1710 
1711  if (NULL == pc->serialization)
1712  pc->serialization =
1714  if (NULL == pc->serialization)
1715  return;
1716  if (NULL == pc->fi)
1717  return;
1718  if (NULL == pc->fi->serialization)
1719  {
1720  GNUNET_break (0);
1721  return;
1722  }
1723  wh = get_write_handle (pc->h,
1725  pc->serialization);
1726  if (NULL == wh)
1727  {
1728  GNUNET_break (0);
1729  goto cleanup;
1730  }
1731  have_ns = (NULL != pc->ns) ? GNUNET_YES : GNUNET_NO;
1732  if ((GNUNET_OK != GNUNET_BIO_write_string (wh, pc->nid)) ||
1733  (GNUNET_OK != GNUNET_BIO_write_string (wh, pc->nuid)) ||
1734  (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pc->options)) ||
1735  (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pc->all_done)) ||
1736  (GNUNET_OK != GNUNET_BIO_write_int32 (wh, have_ns)) ||
1739  (NULL == pc->fi_pos)
1740  ? NULL
1741  : pc->fi_pos->serialization)) ||
1742  ((NULL != pc->ns) &&
1743  (GNUNET_OK !=
1744  GNUNET_BIO_write (wh,
1745  pc->ns,
1746  sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey)))))
1747  {
1748  GNUNET_break (0);
1749  goto cleanup;
1750  }
1751  if (GNUNET_OK != GNUNET_BIO_write_close (wh))
1752  {
1753  wh = NULL;
1754  GNUNET_break (0);
1755  goto cleanup;
1756  }
1757  return;
1758 cleanup:
1759  if (NULL != wh)
1760  (void) GNUNET_BIO_write_close (wh);
1763  pc->serialization);
1764  GNUNET_free (pc->serialization);
1765  pc->serialization = NULL;
1766 }
1767 
1768 
1777 void
1779 {
1780  struct GNUNET_BIO_WriteHandle *wh;
1781  char *uris;
1782 
1783  if (NULL == uc->serialization)
1784  uc->serialization =
1786  if (NULL == uc->serialization)
1787  return;
1788  wh = get_write_handle (uc->h,
1790  uc->serialization);
1791  if (NULL == wh)
1792  {
1793  GNUNET_break (0);
1794  goto cleanup;
1795  }
1796  if (NULL != uc->ksk_uri)
1797  uris = GNUNET_FS_uri_to_string (uc->ksk_uri);
1798  else
1799  uris = NULL;
1800  if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uc->filename)) ||
1801  (GNUNET_OK != GNUNET_BIO_write_int64 (wh, uc->file_size)) ||
1802  (GNUNET_OK != write_start_time (wh, uc->start_time)) ||
1803  (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) uc->state)) ||
1804  (GNUNET_OK !=
1805  GNUNET_BIO_write (wh, &uc->chk, sizeof(struct ContentHashKey))) ||
1806  (GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) ||
1807  (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) uc->ksk_offset)) ||
1808  ((uc->state == UNINDEX_STATE_FS_NOTIFY) &&
1809  (GNUNET_OK != GNUNET_BIO_write (wh,
1810  &uc->file_id,
1811  sizeof(struct GNUNET_HashCode)))) ||
1812  ((uc->state == UNINDEX_STATE_ERROR) &&
1813  (GNUNET_OK != GNUNET_BIO_write_string (wh, uc->emsg))))
1814  {
1815  GNUNET_break (0);
1816  goto cleanup;
1817  }
1818  if (GNUNET_OK != GNUNET_BIO_write_close (wh))
1819  {
1820  wh = NULL;
1821  GNUNET_break (0);
1822  goto cleanup;
1823  }
1824  return;
1825 cleanup:
1826  if (NULL != wh)
1827  (void) GNUNET_BIO_write_close (wh);
1830  uc->serialization);
1831  GNUNET_free (uc->serialization);
1832  uc->serialization = NULL;
1833 }
1834 
1835 
1843 static int
1845  struct DownloadRequest *dr)
1846 {
1847  unsigned int i;
1848 
1849  if ((GNUNET_OK != GNUNET_BIO_write_int32 (wh, dr->state)) ||
1850  (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dr->offset)) ||
1852  (GNUNET_OK != GNUNET_BIO_write_int32 (wh, dr->depth)))
1853  return GNUNET_NO;
1854  if ((BRS_CHK_SET == dr->state) &&
1855  (GNUNET_OK !=
1856  GNUNET_BIO_write (wh, &dr->chk, sizeof(struct ContentHashKey))))
1857  return GNUNET_NO;
1858  for (i = 0; i < dr->num_children; i++)
1859  if (GNUNET_NO == write_download_request (wh, dr->children[i]))
1860  return GNUNET_NO;
1861  return GNUNET_YES;
1862 }
1863 
1864 
1871 static struct DownloadRequest *
1873 {
1874  struct DownloadRequest *dr;
1875  unsigned int i;
1876 
1877  dr = GNUNET_new (struct DownloadRequest);
1878  if ((GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->state)) ||
1879  (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dr->offset)) ||
1880  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->num_children)) ||
1881  (dr->num_children > CHK_PER_INODE) ||
1882  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->depth)) ||
1883  ((0 == dr->depth) && (dr->num_children > 0)) ||
1884  ((dr->depth > 0) && (0 == dr->num_children)))
1885  {
1886  GNUNET_break (0);
1887  dr->num_children = 0;
1888  goto cleanup;
1889  }
1890  if (dr->num_children > 0)
1891  dr->children =
1892  GNUNET_malloc (dr->num_children * sizeof(struct DownloadRequest *));
1893  switch (dr->state)
1894  {
1895  case BRS_INIT:
1896  case BRS_RECONSTRUCT_DOWN:
1898  case BRS_RECONSTRUCT_UP:
1899  break;
1900 
1901  case BRS_CHK_SET:
1902  if (GNUNET_OK !=
1903  GNUNET_BIO_read (rh, "chk", &dr->chk, sizeof(struct ContentHashKey)))
1904  goto cleanup;
1905  break;
1906 
1907  case BRS_DOWNLOAD_DOWN:
1908  case BRS_DOWNLOAD_UP:
1909  case BRS_ERROR:
1910  break;
1911 
1912  default:
1913  GNUNET_break (0);
1914  goto cleanup;
1915  }
1916  for (i = 0; i < dr->num_children; i++)
1917  {
1918  if (NULL == (dr->children[i] = read_download_request (rh)))
1919  goto cleanup;
1920  dr->children[i]->parent = dr;
1921  }
1922  return dr;
1923 cleanup:
1925  return NULL;
1926 }
1927 
1928 
1938 static char *
1940  const char *uni,
1941  const char *ext)
1942 {
1943  char *par;
1944  char *epar;
1945 
1946  if (dc->parent == NULL)
1947  return get_serialization_file_name (dc->h,
1948  (dc->search != NULL)
1951  uni);
1952  if (NULL == dc->parent->serialization)
1953  return NULL;
1954  par = get_download_sync_filename (dc->parent, dc->parent->serialization, "");
1955  if (NULL == par)
1956  return NULL;
1957  GNUNET_asprintf (&epar, "%s.dir%s%s%s", par, DIR_SEPARATOR_STR, uni, ext);
1958  GNUNET_free (par);
1959  return epar;
1960 }
1961 
1962 
1971 void
1973 {
1974  struct GNUNET_BIO_WriteHandle *wh;
1975  char *uris;
1976  char *fn;
1977  char *dir;
1978 
1979  if (0 != (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE))
1980  return; /* we don't sync probes */
1981  if (NULL == dc->serialization)
1982  {
1983  dir = get_download_sync_filename (dc, "", "");
1984  if (NULL == dir)
1985  return;
1987  {
1988  GNUNET_free (dir);
1989  return;
1990  }
1991  fn = GNUNET_DISK_mktemp (dir);
1992  GNUNET_free (dir);
1993  if (NULL == fn)
1994  return;
1996  }
1997  else
1998  {
1999  fn = get_download_sync_filename (dc, dc->serialization, "");
2000  if (NULL == fn)
2001  {
2002  GNUNET_free (dc->serialization);
2003  dc->serialization = NULL;
2004  GNUNET_free (fn);
2005  return;
2006  }
2007  }
2008  wh = GNUNET_BIO_write_open (fn);
2009  if (NULL == wh)
2010  {
2011  GNUNET_free (dc->serialization);
2012  dc->serialization = NULL;
2013  GNUNET_free (fn);
2014  return;
2015  }
2018  uris = GNUNET_FS_uri_to_string (dc->uri);
2019  if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) ||
2020  (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, dc->meta)) ||
2021  (GNUNET_OK != GNUNET_BIO_write_string (wh, dc->emsg)) ||
2022  (GNUNET_OK != GNUNET_BIO_write_string (wh, dc->filename)) ||
2025  (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dc->offset)) ||
2026  (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dc->length)) ||
2027  (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dc->completed)) ||
2028  (GNUNET_OK != write_start_time (wh, dc->start_time)) ||
2029  (GNUNET_OK != GNUNET_BIO_write_int32 (wh, dc->anonymity)) ||
2030  (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) dc->options)) ||
2031  (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) dc->has_finished)))
2032  {
2033  GNUNET_break (0);
2034  goto cleanup;
2035  }
2036  if (NULL == dc->emsg)
2037  {
2038  GNUNET_assert (dc->top_request != NULL);
2040  {
2041  GNUNET_break (0);
2042  goto cleanup;
2043  }
2044  }
2045  GNUNET_free_non_null (uris);
2046  uris = NULL;
2047  if (GNUNET_OK != GNUNET_BIO_write_close (wh))
2048  {
2049  wh = NULL;
2050  GNUNET_break (0);
2051  goto cleanup;
2052  }
2053  GNUNET_free (fn);
2054  return;
2055 cleanup:
2056  if (NULL != wh)
2057  (void) GNUNET_BIO_write_close (wh);
2058  GNUNET_free_non_null (uris);
2059  if (0 != unlink (fn))
2061  GNUNET_free (fn);
2062  GNUNET_free (dc->serialization);
2063  dc->serialization = NULL;
2064 }
2065 
2066 
2075 void
2077 {
2078  struct GNUNET_BIO_WriteHandle *wh;
2079  char *uris;
2080 
2081  if (NULL == sr->sc)
2082  return;
2083  uris = NULL;
2084  if (NULL == sr->serialization)
2085  sr->serialization =
2087  (sr->sc->psearch_result == NULL)
2090  sr->sc->serialization);
2091  if (NULL == sr->serialization)
2092  return;
2093  wh = get_write_handle_in_dir (sr->h,
2094  (sr->sc->psearch_result == NULL)
2096  : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2097  sr->sc->serialization,
2098  sr->serialization);
2099  if (NULL == wh)
2100  {
2101  GNUNET_break (0);
2102  goto cleanup;
2103  }
2104  uris = GNUNET_FS_uri_to_string (sr->uri);
2105  if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) ||
2107  (sr->download != NULL)
2108  ? sr->download->serialization
2109  : NULL)) ||
2110  (GNUNET_OK !=
2112  (sr->update_search != NULL)
2114  : NULL)) ||
2115  (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, sr->meta)) ||
2116  (GNUNET_OK !=
2117  GNUNET_BIO_write (wh, &sr->key, sizeof(struct GNUNET_HashCode))) ||
2122  {
2123  GNUNET_break (0);
2124  goto cleanup;
2125  }
2126  if ((NULL != sr->uri) && (GNUNET_FS_URI_KSK == sr->sc->uri->type) &&
2127  (GNUNET_OK !=
2128  GNUNET_BIO_write (wh,
2129  sr->keyword_bitmap,
2130  (sr->sc->uri->data.ksk.keywordCount + 7) / 8)))
2131  {
2132  GNUNET_break (0);
2133  goto cleanup;
2134  }
2135  if (GNUNET_OK != GNUNET_BIO_write_close (wh))
2136  {
2137  wh = NULL;
2138  GNUNET_break (0);
2139  goto cleanup;
2140  }
2141  GNUNET_free_non_null (uris);
2142  return;
2143 cleanup:
2144  GNUNET_free_non_null (uris);
2145  if (NULL != wh)
2146  (void) GNUNET_BIO_write_close (wh);
2148  (NULL == sr->sc->psearch_result)
2150  : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2151  sr->sc->serialization,
2152  sr->serialization);
2153  GNUNET_free (sr->serialization);
2154  sr->serialization = NULL;
2155 }
2156 
2157 
2166 void
2168 {
2169  struct GNUNET_BIO_WriteHandle *wh;
2170  char *uris;
2171  char in_pause;
2172  const char *category;
2173 
2174  category = (NULL == sc->psearch_result) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
2176  if (NULL == sc->serialization)
2177  sc->serialization = make_serialization_file_name (sc->h, category);
2178  if (NULL == sc->serialization)
2179  return;
2180  uris = NULL;
2181  wh = get_write_handle (sc->h, category, sc->serialization);
2182  if (NULL == wh)
2183  {
2184  GNUNET_break (0);
2185  goto cleanup;
2186  }
2189  uris = GNUNET_FS_uri_to_string (sc->uri);
2190  in_pause = (sc->task != NULL) ? 'r' : '\0';
2191  if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) ||
2192  (GNUNET_OK != write_start_time (wh, sc->start_time)) ||
2193  (GNUNET_OK != GNUNET_BIO_write_string (wh, sc->emsg)) ||
2194  (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) sc->options)) ||
2195  (GNUNET_OK != GNUNET_BIO_write (wh, &in_pause, sizeof(in_pause))) ||
2197  {
2198  GNUNET_break (0);
2199  goto cleanup;
2200  }
2201  GNUNET_free (uris);
2202  uris = NULL;
2203  if (GNUNET_OK != GNUNET_BIO_write_close (wh))
2204  {
2205  wh = NULL;
2206  GNUNET_break (0);
2207  goto cleanup;
2208  }
2209  return;
2210 cleanup:
2211  if (NULL != wh)
2212  (void) GNUNET_BIO_write_close (wh);
2213  GNUNET_free_non_null (uris);
2214  GNUNET_FS_remove_sync_file_ (sc->h, category, sc->serialization);
2215  GNUNET_free (sc->serialization);
2216  sc->serialization = NULL;
2217 }
2218 
2219 
2228 static int
2229 deserialize_unindex_file (void *cls, const char *filename)
2230 {
2231  struct GNUNET_FS_Handle *h = cls;
2232  struct GNUNET_BIO_ReadHandle *rh;
2233  struct GNUNET_FS_UnindexContext *uc;
2234  struct GNUNET_FS_ProgressInfo pi;
2235  char *emsg;
2236  char *uris;
2237  uint32_t state;
2238 
2239  uc = GNUNET_new (struct GNUNET_FS_UnindexContext);
2240  uc->h = h;
2242  rh = GNUNET_BIO_read_open (filename);
2243  if (NULL == rh)
2244  {
2245  GNUNET_break (0);
2246  goto cleanup;
2247  }
2248  uris = NULL;
2249  if ((GNUNET_OK !=
2250  GNUNET_BIO_read_string (rh, "unindex-fn", &uc->filename, 10 * 1024)) ||
2251  (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &uc->file_size)) ||
2252  (GNUNET_OK != read_start_time (rh, &uc->start_time)) ||
2253  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &state)) ||
2254  (GNUNET_OK !=
2255  GNUNET_BIO_read (rh, "uri", &uc->chk, sizeof(struct ContentHashKey))) ||
2256  (GNUNET_OK !=
2257  GNUNET_BIO_read_string (rh, "unindex-kskuri", &uris, 10 * 1024)) ||
2258  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &uc->ksk_offset)))
2259  {
2260  GNUNET_free_non_null (uris);
2261  GNUNET_break (0);
2262  goto cleanup;
2263  }
2264  if (NULL != uris)
2265  {
2266  uc->ksk_uri = GNUNET_FS_uri_parse (uris, &emsg);
2267  GNUNET_free (uris);
2268  if (NULL == uc->ksk_uri)
2269  {
2270  GNUNET_break (0);
2271  GNUNET_free_non_null (emsg);
2272  goto cleanup;
2273  }
2274  }
2275  if ((uc->ksk_offset > 0) &&
2276  ((NULL == uc->ksk_uri) ||
2277  (uc->ksk_offset > uc->ksk_uri->data.ksk.keywordCount)))
2278  {
2279  GNUNET_break (0);
2280  goto cleanup;
2281  }
2282  uc->state = (enum UnindexState) state;
2283  switch (state)
2284  {
2285  case UNINDEX_STATE_HASHING:
2286  break;
2287 
2289  if (GNUNET_OK != GNUNET_BIO_read (rh,
2290  "unindex-hash",
2291  &uc->file_id,
2292  sizeof(struct GNUNET_HashCode)))
2293  {
2294  GNUNET_break (0);
2295  goto cleanup;
2296  }
2297  break;
2298 
2302  break;
2303 
2305  break;
2306 
2307  case UNINDEX_STATE_ERROR:
2308  if (GNUNET_OK !=
2309  GNUNET_BIO_read_string (rh, "unindex-emsg", &uc->emsg, 10 * 1024))
2310  {
2311  GNUNET_break (0);
2312  goto cleanup;
2313  }
2314  break;
2315 
2316  default:
2317  GNUNET_break (0);
2318  goto cleanup;
2319  }
2322  pi.value.unindex.specifics.resume.message = uc->emsg;
2324  uc,
2325  (uc->state == UNINDEX_STATE_COMPLETE)
2326  ? uc->file_size
2327  : 0);
2328  switch (uc->state)
2329  {
2330  case UNINDEX_STATE_HASHING:
2332  uc->filename,
2335  uc);
2336  break;
2337 
2341  break;
2342 
2345  break;
2346 
2349  break;
2350 
2353  break;
2354 
2356  case UNINDEX_STATE_ERROR:
2357  /* no need to resume any operation, we were done */
2358  break;
2359 
2360  default:
2361  break;
2362  }
2363  if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
2364  {
2366  _ ("Failure while resuming unindexing operation `%s': %s\n"),
2367  filename,
2368  emsg);
2369  GNUNET_free (emsg);
2370  }
2371  return GNUNET_OK;
2372 cleanup:
2374  if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)))
2375  {
2377  _ ("Failed to resume unindexing operation `%s': %s\n"),
2378  filename,
2379  emsg);
2380  GNUNET_free (emsg);
2381  }
2382  if (NULL != uc->serialization)
2385  uc->serialization);
2387  GNUNET_free (uc);
2388  return GNUNET_OK;
2389 }
2390 
2391 
2401 static void
2403  struct GNUNET_BIO_ReadHandle *rh,
2404  struct GNUNET_FS_DownloadContext *parent,
2406  const char *serialization);
2407 
2408 
2417 static struct GNUNET_FS_SearchContext *
2419  struct GNUNET_BIO_ReadHandle *rh,
2421  const char *serialization);
2422 
2423 
2432 static int
2433 deserialize_search_result (void *cls, const char *filename)
2434 {
2435  struct GNUNET_FS_SearchContext *sc = cls;
2436  char *ser;
2437  char *uris;
2438  char *emsg;
2439  char *download;
2440  char *update_srch;
2441  struct GNUNET_BIO_ReadHandle *rh;
2442  struct GNUNET_BIO_ReadHandle *drh;
2443  struct GNUNET_FS_SearchResult *sr;
2444 
2445  ser = get_serialization_short_name (filename);
2446  rh = GNUNET_BIO_read_open (filename);
2447  if (NULL == rh)
2448  {
2449  if (NULL != ser)
2450  {
2452  (NULL == sc->psearch_result)
2455  sc->serialization,
2456  ser);
2457  GNUNET_free (ser);
2458  }
2459  return GNUNET_OK;
2460  }
2461  emsg = NULL;
2462  uris = NULL;
2463  download = NULL;
2464  update_srch = NULL;
2465  sr = GNUNET_new (struct GNUNET_FS_SearchResult);
2466  sr->h = sc->h;
2467  sr->sc = sc;
2468  sr->serialization = ser;
2469  if ((GNUNET_OK !=
2470  GNUNET_BIO_read_string (rh, "result-uri", &uris, 10 * 1024)) ||
2471  (NULL == (sr->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
2472  (GNUNET_OK !=
2473  GNUNET_BIO_read_string (rh, "download-lnk", &download, 16)) ||
2474  (GNUNET_OK !=
2475  GNUNET_BIO_read_string (rh, "search-lnk", &update_srch, 16)) ||
2476  (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "result-meta", &sr->meta)) ||
2477  (GNUNET_OK != GNUNET_BIO_read (rh,
2478  "result-key",
2479  &sr->key,
2480  sizeof(struct GNUNET_HashCode))) ||
2485  {
2486  GNUNET_break (0);
2487  goto cleanup;
2488  }
2489  if (GNUNET_FS_URI_KSK == sr->sc->uri->type)
2490  {
2492  (sr->sc->uri->data.ksk.keywordCount + 7) / 8); /* round up, count bits */
2493  if (GNUNET_OK !=
2494  GNUNET_BIO_read (rh,
2495  "keyword-bitmap",
2496  sr->keyword_bitmap,
2497  (sr->sc->uri->data.ksk.keywordCount + 7) / 8))
2498  {
2499  GNUNET_break (0);
2500  goto cleanup;
2501  }
2502  }
2503  GNUNET_free (uris);
2504  if (NULL != download)
2505  {
2506  drh = get_read_handle (sc->h, GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD, download);
2507  if (NULL != drh)
2508  {
2509  deserialize_download (sc->h, drh, NULL, sr, download);
2510  if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg))
2511  {
2513  _ ("Failed to resume sub-download `%s': %s\n"),
2514  download,
2515  emsg);
2516  GNUNET_free (emsg);
2517  }
2518  }
2519  GNUNET_free (download);
2520  }
2521  if (NULL != update_srch)
2522  {
2523  drh =
2525  if (NULL != drh)
2526  {
2527  deserialize_search (sc->h, drh, sr, update_srch);
2528  if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg))
2529  {
2531  _ ("Failed to resume sub-search `%s': %s\n"),
2532  update_srch,
2533  emsg);
2534  GNUNET_free (emsg);
2535  }
2536  }
2537  GNUNET_free (update_srch);
2538  }
2540  sc->master_result_map,
2541  &sr->key,
2542  sr,
2544  if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
2545  {
2547  _ ("Failure while resuming search operation `%s': %s\n"),
2548  filename,
2549  emsg);
2550  GNUNET_free (emsg);
2551  }
2552  return GNUNET_OK;
2553 cleanup:
2554  GNUNET_free_non_null (download);
2555  GNUNET_free_non_null (emsg);
2556  GNUNET_free_non_null (uris);
2557  GNUNET_free_non_null (update_srch);
2558  if (NULL != sr->uri)
2559  GNUNET_FS_uri_destroy (sr->uri);
2560  if (NULL != sr->meta)
2562  GNUNET_free (sr->serialization);
2563  GNUNET_free (sr);
2564  if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
2565  {
2567  _ ("Failure while resuming search operation `%s': %s\n"),
2568  filename,
2569  emsg);
2570  GNUNET_free (emsg);
2571  }
2572  return GNUNET_OK;
2573 }
2574 
2575 
2584 static void
2586 {
2587  struct GNUNET_FS_DownloadContext *dcc;
2588  struct GNUNET_FS_ProgressInfo pi;
2589 
2591  pi.value.download.specifics.resume.meta = dc->meta;
2592  pi.value.download.specifics.resume.message = dc->emsg;
2594  dcc = dc->child_head;
2595  while (NULL != dcc)
2596  {
2597  signal_download_resume (dcc);
2598  dcc = dcc->next;
2599  }
2600 }
2601 
2602 
2609 static void
2611 
2612 
2622 static int
2623 signal_result_resume (void *cls, const struct GNUNET_HashCode *key, void *value)
2624 {
2625  struct GNUNET_FS_SearchContext *sc = cls;
2626  struct GNUNET_FS_ProgressInfo pi;
2627  struct GNUNET_FS_SearchResult *sr = value;
2628 
2629  if (0 == sr->mandatory_missing)
2630  {
2632  pi.value.search.specifics.resume_result.meta = sr->meta;
2633  pi.value.search.specifics.resume_result.uri = sr->uri;
2634  pi.value.search.specifics.resume_result.result = sr;
2635  pi.value.search.specifics.resume_result.availability_rank =
2637  pi.value.search.specifics.resume_result.availability_certainty =
2638  sr->availability_trials;
2639  pi.value.search.specifics.resume_result.applicability_rank =
2640  sr->optional_support;
2641  sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc);
2642  }
2643  if (NULL != sr->download)
2644  {
2646  }
2647  else
2648  {
2650  }
2651  if (NULL != sr->update_search)
2653  return GNUNET_YES;
2654 }
2655 
2656 
2662 static void
2664 
2665 
2674 static int
2675 free_result (void *cls, const struct GNUNET_HashCode *key, void *value)
2676 {
2677  struct GNUNET_FS_SearchResult *sr = value;
2678 
2679  if (NULL != sr->update_search)
2680  {
2682  GNUNET_assert (NULL == sr->update_search);
2683  }
2685  GNUNET_FS_uri_destroy (sr->uri);
2686  GNUNET_free (sr);
2687  return GNUNET_YES;
2688 }
2689 
2690 
2696 static void
2698 {
2699  if (NULL != sc->serialization)
2700  {
2702  (sc->psearch_result == NULL)
2705  sc->serialization);
2707  (sc->psearch_result == NULL)
2709  : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2710  sc->serialization);
2711  }
2713  GNUNET_free_non_null (sc->emsg);
2714  if (NULL != sc->uri)
2715  GNUNET_FS_uri_destroy (sc->uri);
2716  if (NULL != sc->master_result_map)
2717  {
2719  &free_result,
2720  sc);
2722  }
2723  GNUNET_free (sc);
2724 }
2725 
2726 
2735 static int
2736 deserialize_subdownload (void *cls, const char *filename)
2737 {
2738  struct GNUNET_FS_DownloadContext *parent = cls;
2739  char *ser;
2740  char *emsg;
2741  struct GNUNET_BIO_ReadHandle *rh;
2742 
2743  ser = get_serialization_short_name (filename);
2744  rh = GNUNET_BIO_read_open (filename);
2745  if (NULL == rh)
2746  {
2748  _ (
2749  "Failed to resume sub-download `%s': could not open file `%s'\n"),
2750  ser,
2751  filename);
2752  GNUNET_free (ser);
2753  return GNUNET_OK;
2754  }
2755  deserialize_download (parent->h, rh, parent, NULL, ser);
2756  if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
2757  {
2759  _ ("Failed to resume sub-download `%s': %s\n"),
2760  ser,
2761  emsg);
2762  GNUNET_free (emsg);
2763  }
2764  GNUNET_free (ser);
2765  return GNUNET_OK;
2766 }
2767 
2768 
2776 static void
2778 {
2779  struct GNUNET_FS_DownloadContext *dcc;
2780 
2781  if (NULL != dc->meta)
2783  if (NULL != dc->uri)
2784  GNUNET_FS_uri_destroy (dc->uri);
2786  GNUNET_free_non_null (dc->emsg);
2789  while (NULL != (dcc = dc->child_head))
2790  {
2792  free_download_context (dcc);
2793  }
2795  if (NULL != dc->active)
2797  GNUNET_free (dc);
2798 }
2799 
2800 
2810 static void
2812  struct GNUNET_BIO_ReadHandle *rh,
2813  struct GNUNET_FS_DownloadContext *parent,
2814  struct GNUNET_FS_SearchResult *search,
2815  const char *serialization)
2816 {
2817  struct GNUNET_FS_DownloadContext *dc;
2818  char *emsg;
2819  char *uris;
2820  char *dn;
2821  uint32_t options;
2822  uint32_t status;
2823 
2824  uris = NULL;
2825  emsg = NULL;
2826  dc = GNUNET_new (struct GNUNET_FS_DownloadContext);
2827  dc->parent = parent;
2828  dc->h = h;
2829  dc->serialization = GNUNET_strdup (serialization);
2830  if ((GNUNET_OK !=
2831  GNUNET_BIO_read_string (rh, "download-uri", &uris, 10 * 1024)) ||
2832  (NULL == (dc->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
2833  ((GNUNET_YES != GNUNET_FS_uri_test_chk (dc->uri)) &&
2834  (GNUNET_YES != GNUNET_FS_uri_test_loc (dc->uri))) ||
2835  (GNUNET_OK !=
2836  GNUNET_BIO_read_meta_data (rh, "download-meta", &dc->meta)) ||
2837  (GNUNET_OK !=
2838  GNUNET_BIO_read_string (rh, "download-emsg", &dc->emsg, 10 * 1024)) ||
2839  (GNUNET_OK !=
2840  GNUNET_BIO_read_string (rh, "download-fn", &dc->filename, 10 * 1024)) ||
2842  "download-tfn",
2843  &dc->temp_filename,
2844  10 * 1024)) ||
2845  (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->old_file_size)) ||
2846  (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->offset)) ||
2847  (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->length)) ||
2848  (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->completed)) ||
2849  (GNUNET_OK != read_start_time (rh, &dc->start_time)) ||
2850  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dc->anonymity)) ||
2851  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &options)) ||
2852  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &status)))
2853  {
2854  GNUNET_break (0);
2855  goto cleanup;
2856  }
2857  dc->options = (enum GNUNET_FS_DownloadOptions) options;
2858  dc->active =
2860  GNUNET_NO);
2861  dc->has_finished = (int) status;
2862  dc->treedepth =
2864  if (GNUNET_FS_uri_test_loc (dc->uri))
2867  if (NULL == dc->emsg)
2868  {
2870  if (NULL == dc->top_request)
2871  {
2872  GNUNET_break (0);
2873  goto cleanup;
2874  }
2875  }
2876  dn = get_download_sync_filename (dc, dc->serialization, ".dir");
2877  if (NULL != dn)
2878  {
2881  GNUNET_free (dn);
2882  }
2883  if (NULL != parent)
2884  {
2885  GNUNET_CONTAINER_DLL_insert (parent->child_head, parent->child_tail, dc);
2886  }
2887  if (NULL != search)
2888  {
2889  dc->search = search;
2890  search->download = dc;
2891  }
2892  if ((NULL == parent) && (NULL == search))
2893  {
2894  dc->top =
2897  }
2898  GNUNET_free (uris);
2899  GNUNET_assert (NULL == dc->job_queue);
2901  return;
2902 cleanup:
2903  GNUNET_free_non_null (uris);
2904  GNUNET_free_non_null (emsg);
2905  free_download_context (dc);
2906 }
2907 
2908 
2915 static void
2917 {
2918  struct GNUNET_FS_ProgressInfo pi;
2919 
2921  pi.value.search.specifics.resume.message = sc->emsg;
2922  pi.value.search.specifics.resume.is_paused =
2923  (NULL == sc->mq) ? GNUNET_YES : GNUNET_NO;
2924  sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc);
2927  sc);
2928 }
2929 
2930 
2939 static struct GNUNET_FS_SearchContext *
2941  struct GNUNET_BIO_ReadHandle *rh,
2942  struct GNUNET_FS_SearchResult *psearch_result,
2943  const char *serialization)
2944 {
2945  struct GNUNET_FS_SearchContext *sc;
2946  char *emsg;
2947  char *uris;
2948  char *dn;
2949  uint32_t options;
2950  char in_pause;
2951 
2952  if ((NULL != psearch_result) && (NULL != psearch_result->update_search))
2953  {
2954  GNUNET_break (0);
2955  return NULL;
2956  }
2957  uris = NULL;
2958  emsg = NULL;
2959  sc = GNUNET_new (struct GNUNET_FS_SearchContext);
2960  if (NULL != psearch_result)
2961  {
2963  psearch_result->update_search = sc;
2964  }
2965  sc->h = h;
2966  sc->serialization = GNUNET_strdup (serialization);
2967  if ((GNUNET_OK !=
2968  GNUNET_BIO_read_string (rh, "search-uri", &uris, 10 * 1024)) ||
2969  (NULL == (sc->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
2970  ((GNUNET_YES != GNUNET_FS_uri_test_ksk (sc->uri)) &&
2971  (GNUNET_YES != GNUNET_FS_uri_test_sks (sc->uri))) ||
2972  (GNUNET_OK != read_start_time (rh, &sc->start_time)) ||
2973  (GNUNET_OK !=
2974  GNUNET_BIO_read_string (rh, "search-emsg", &sc->emsg, 10 * 1024)) ||
2975  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &options)) ||
2976  (GNUNET_OK !=
2977  GNUNET_BIO_read (rh, "search-pause", &in_pause, sizeof(in_pause))) ||
2978  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sc->anonymity)))
2979  {
2980  GNUNET_break (0);
2981  goto cleanup;
2982  }
2983  sc->options = (enum GNUNET_FS_SearchOptions) options;
2986  (NULL == sc->psearch_result)
2989  sc->serialization,
2990  "");
2991  if (NULL != dn)
2992  {
2995  GNUNET_free (dn);
2996  }
2997  if (('\0' == in_pause) &&
2999  {
3000  GNUNET_log (
3002  _ ("Could not resume running search, will resume as paused search\n"));
3003  }
3004  signal_search_resume (sc);
3005  GNUNET_free (uris);
3006  return sc;
3007 cleanup:
3008  GNUNET_free_non_null (emsg);
3009  free_search_context (sc);
3010  GNUNET_free_non_null (uris);
3011  return NULL;
3012 }
3013 
3014 
3023 static int
3024 deserialize_search_file (void *cls, const char *filename)
3025 {
3026  struct GNUNET_FS_Handle *h = cls;
3027  char *ser;
3028  char *emsg;
3029  struct GNUNET_BIO_ReadHandle *rh;
3030  struct GNUNET_FS_SearchContext *sc;
3031  struct stat buf;
3032 
3033  if (0 != stat (filename, &buf))
3034  {
3036  return GNUNET_OK;
3037  }
3038  if (S_ISDIR (buf.st_mode))
3039  return GNUNET_OK; /* skip directories */
3040  ser = get_serialization_short_name (filename);
3041  rh = GNUNET_BIO_read_open (filename);
3042  if (NULL == rh)
3043  {
3044  if (NULL != ser)
3045  {
3047  GNUNET_free (ser);
3048  }
3049  return GNUNET_OK;
3050  }
3051  sc = deserialize_search (h, rh, NULL, ser);
3052  if (NULL != sc)
3054  GNUNET_free (ser);
3055  if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
3056  {
3058  _ ("Failure while resuming search operation `%s': %s\n"),
3059  filename,
3060  emsg);
3061  GNUNET_free (emsg);
3062  }
3063  return GNUNET_OK;
3064 }
3065 
3066 
3075 static int
3076 deserialize_download_file (void *cls, const char *filename)
3077 {
3078  struct GNUNET_FS_Handle *h = cls;
3079  char *ser;
3080  char *emsg;
3081  struct GNUNET_BIO_ReadHandle *rh;
3082 
3083  ser = get_serialization_short_name (filename);
3084  rh = GNUNET_BIO_read_open (filename);
3085  if (NULL == rh)
3086  {
3087  if (0 != unlink (filename))
3089  GNUNET_free (ser);
3090  return GNUNET_OK;
3091  }
3092  deserialize_download (h, rh, NULL, NULL, ser);
3093  GNUNET_free (ser);
3094  if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
3095  {
3097  _ ("Failure while resuming download operation `%s': %s\n"),
3098  filename,
3099  emsg);
3100  GNUNET_free (emsg);
3101  }
3102  return GNUNET_OK;
3103 }
3104 
3105 
3113 static void
3114 deserialization_master (const char *master_path,
3116  struct GNUNET_FS_Handle *h)
3117 {
3118  char *dn;
3119 
3120  dn = get_serialization_file_name (h, master_path, "");
3121  if (NULL == dn)
3122  return;
3124  GNUNET_DISK_directory_scan (dn, proc, h);
3125  GNUNET_free (dn);
3126 }
3127 
3128 
3140 struct GNUNET_FS_Handle *
3142  const char *client_name,
3144  void *upcb_cls,
3145  enum GNUNET_FS_Flags flags,
3146  ...)
3147 {
3148  struct GNUNET_FS_Handle *ret;
3149  enum GNUNET_FS_OPTIONS opt;
3150  va_list ap;
3151 
3152  ret = GNUNET_new (struct GNUNET_FS_Handle);
3153  ret->cfg = cfg;
3154  ret->client_name = GNUNET_strdup (client_name);
3155  ret->upcb = upcb;
3156  ret->upcb_cls = upcb_cls;
3157  ret->flags = flags;
3160  ret->avg_block_latency =
3161  GNUNET_TIME_UNIT_MINUTES; /* conservative starting point */
3162  va_start (ap, flags);
3163  while (GNUNET_FS_OPTIONS_END !=
3164  (opt = GNUNET_VA_ARG_ENUM (ap, GNUNET_FS_OPTIONS)))
3165  {
3166  switch (opt)
3167  {
3169  ret->max_parallel_downloads = va_arg (ap, unsigned int);
3170 
3171  break;
3172 
3174  ret->max_parallel_requests = va_arg (ap, unsigned int);
3175 
3176  break;
3177 
3178  default:
3179  GNUNET_break (0);
3180  GNUNET_free (ret->client_name);
3181  GNUNET_free (ret);
3182  va_end (ap);
3183  return NULL;
3184  }
3185  }
3186  va_end (ap);
3187  if (0 != (GNUNET_FS_FLAGS_PERSISTENCE & flags))
3188  {
3191  ret);
3194  ret);
3197  ret);
3200  ret);
3201  }
3202  return ret;
3203 }
3204 
3205 
3215 void
3217 {
3218  while (NULL != h->top_head)
3219  h->top_head->ssf (h->top_head->ssf_cls);
3220  if (NULL != h->queue_job)
3222  GNUNET_free (h->client_name);
3223  GNUNET_free (h);
3224 }
3225 
3226 
3227 /* end of fs_api.c */
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:822
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
void * client_info
Client info for this search result.
Definition: fs_api.h:533
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...
uint32_t optional_support
Number of optional keywords under which this result was also found.
Definition: fs_api.h:601
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:3076
struct GNUNET_FS_FileInformation * entries
Linked list of entries in the directory.
Definition: fs_api.h:361
This is a probe (low priority).
Definition: fs_api.h:407
int GNUNET_BIO_write_meta_data(struct GNUNET_BIO_WriteHandle *h, const struct GNUNET_CONTAINER_MetaData *m)
Write metadata container to a file.
Definition: bio.c:544
char * nid
ID of the content in the namespace, NULL if we have no namespace.
Definition: fs_api.h:1203
int GNUNET_FS_uri_test_ksk(const struct GNUNET_FS_Uri *uri)
Is this a keyword URI?
Definition: fs_uri.c:1335
Open the file for reading.
char * serialization
Short name under which we are serializing the state of this operation.
Definition: fs_api.h:1390
static void deserialization_master(const char *master_path, GNUNET_FileNameCallback proc, struct GNUNET_FS_Handle *h)
Deserialize informatin about pending operations.
Definition: fs_api.c:3114
static char * dir
Set to the directory where runtime files are stored.
Definition: gnunet-arm.c:89
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
struct GNUNET_SCHEDULER_Task * upload_task
ID of the task performing the upload.
Definition: fs_api.h:1258
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
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_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:422
Context for controlling a download.
Definition: fs_api.h:1742
struct GNUNET_FS_DownloadContext * download
ID of an associated download based on this search result (or NULL for none).
Definition: fs_api.h:545
int GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1345
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:1312
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
uint64_t rel_value_us
The actual value.
GNUNET_FS_Flags
General (global) option flags for file-sharing.
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:2940
struct GNUNET_TIME_Relative avg_block_latency
Average time we take for a single request to be satisfied.
Definition: fs_api.h:1146
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct GNUNET_CONTAINER_MetaData * meta
Metadata to use for the file.
Definition: fs_api.h:252
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_FS_ProgressInfo::@25::@27 download
Values for all "GNUNET_FS_STATUS_DOWNLOAD_*" events.
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_GETOPT_CommandLineOption options[]
Definition: 002.c:5
content hash key
Definition: fs.h:53
void * client_info
Pointer kept for the client.
Definition: fs_api.h:247
#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
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&#39;s progress function that we are resuming an upload.
Definition: fs_api.c:1531
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:1240
struct DownloadRequest ** children
Array (!) of child-requests, or NULL for the bottom of the tree.
Definition: fs_api.h:1684
uint32_t ksk_offset
Current offset in KSK removal.
Definition: fs_api.h:1380
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:732
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
char * emsg
Error message (non-NULL if this operation failed).
Definition: fs_api.h:296
struct GNUNET_SCHEDULER_Task * queue_job
Task that processes the jobs in the running and pending queues (and moves jobs around as needed)...
Definition: fs_api.h:1134
char * serialization
Under what filename is this struct serialized (for operational persistence).
Definition: fs_api.h:286
struct GNUNET_FS_DownloadContext * child_head
Head of list of child downloads.
Definition: fs_api.h:1774
#define DEFAULT_MAX_PARALLEL_DOWNLOADS
How many downloads can we have outstanding in parallel at a time by default?
Definition: fs_api.c:41
void GNUNET_FS_download_sync_(struct GNUNET_FS_DownloadContext *dc)
Synchronize this download struct with its mirror on disk.
Definition: fs_api.c:1972
Master context for most FS operations.
Definition: fs_api.h:1068
We&#39;re done.
Definition: fs_api.h:1337
enum GNUNET_FS_SearchOptions options
Options for the search.
Definition: fs_api.h:1597
#define GNUNET_TIME_UNIT_MINUTES
One minute.
void GNUNET_FS_search_sync_(struct GNUNET_FS_SearchContext *sc)
Synchronize this search struct with its mirror on disk.
Definition: fs_api.c:2167
int GNUNET_BIO_write_string(struct GNUNET_BIO_WriteHandle *h, const char *s)
Write a string to a file.
Definition: bio.c:523
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
struct TopLevelActivity * top
Our top-level activity entry (if we are top-level, otherwise NULL).
Definition: fs_api.h:1519
char * emsg
Error message (non-NULL if this operation failed).
Definition: fs_api.h:1550
struct GNUNET_TIME_Absolute start_time
When did we start?
Definition: fs_api.h:1569
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void GNUNET_FS_unindex_do_remove_(struct GNUNET_FS_UnindexContext *uc)
Connect to the datastore and remove the blocks.
Definition: fs_unindex.c:649
int GNUNET_BIO_write_int64(struct GNUNET_BIO_WriteHandle *h, int64_t i)
Write an (u)int64_t.
Definition: bio.c:599
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
uint8_t * keyword_bitmap
Bitmap that specifies precisely which keywords have been matched already.
Definition: fs_api.h:561
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
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:561
struct GNUNET_FS_QueueEntry * pending_head
Head of DLL of pending jobs.
Definition: fs_api.h:1113
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
struct DownloadRequest * top_request
Top-level download request.
Definition: fs_api.h:1855
struct GNUNET_FS_DownloadContext * parent
Parent download (used when downloading files in directories).
Definition: fs_api.h:1763
GNUNET_FS_SearchOptions
Options for searching.
struct GNUNET_ATS_TEST_Topology * top
Definition: ats-testing.c:53
struct GNUNET_TIME_Absolute start_time
At what time did we start this upload?
Definition: fs_api.h:279
static struct GNUNET_FS_UnindexContext * uc
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:774
uint64_t offset
Offset of the corresponding block.
Definition: fs_api.h:1697
Last option in the VARARG list.
Keyword search key (query with keywords).
Definition: fs_api.h:153
char * filename
Name of the file or directory (must be an absolute path).
Definition: fs_api.h:301
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
int GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition: disk.c:503
Nobody is allowed to do anything to the file.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
static void free_search_context(struct GNUNET_FS_SearchContext *sc)
Free memory allocated by the search context and its children.
Definition: fs_api.c:2697
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
struct GNUNET_FS_Uri * uri
URI to which this search result refers to.
Definition: fs_api.h:523
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:694
int GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:684
enum GNUNET_FS_PublishOptions options
Options for publishing.
Definition: fs_api.h:1274
unsigned int active_blocks
How many blocks do the active downloads have?
Definition: fs_api.h:1156
#define GNUNET_NO
Definition: gnunet_common.h:78
char * filename
Where are we writing the data (name of the file, can be NULL!).
Definition: fs_api.h:1821
struct GNUNET_DATASTORE_Handle * dsh
Connection to the datastore service.
Definition: fs_api.h:1235
struct GNUNET_FS_Handle * h
Handle to the global fs context.
Definition: fs_api.h:1183
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
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:395
#define GNUNET_new(type)
Allocate a struct or union of the given type.
char * serialization
Filename used for serializing information about this operation (should be determined using &#39;mktemp&#39;)...
Definition: fs_api.h:1214
Private ECC key encoded for transmission.
struct GNUNET_DISK_FileHandle * fd
File descriptor, NULL if it has not yet been opened.
Definition: fs_api.c:432
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:457
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition: disk.c:912
Information for a file or directory that is about to be published.
Definition: fs_api.h:226
struct ContentHashKey chk
CHK for the request for this block (set during reconstruction to what we have on disk, later to what we want to have).
Definition: fs_api.h:1690
int GNUNET_FS_uri_test_sks(const struct GNUNET_FS_Uri *uri)
Is this a namespace URI?
Definition: fs_uri.c:1282
struct GNUNET_FS_Handle * h
Handle to the master context.
Definition: fs_api.h:242
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:226
struct GNUNET_HashCode file_id
Hash of the file&#39;s contents (once computed).
Definition: fs_api.h:1458
We&#39;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
Run as background job (higher than idle, lower than default).
enum UnindexState state
Current operatinonal phase.
Definition: fs_api.h:1463
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 BlockRequestState state
State in the FSM.
Definition: fs_api.h:1717
union GNUNET_FS_FileInformation::@16 data
Data describing either the file or the directory.
unsigned int num_children
Number of entries in children array.
Definition: fs_api.h:1702
struct GNUNET_FS_QueueEntry * running_head
Head of DLL of running jobs.
Definition: fs_api.h:1103
void GNUNET_FS_stop(struct GNUNET_FS_Handle *h)
Close our connection with the file-sharing service.
Definition: fs_api.c:3216
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
#define GNUNET_malloc_large(size)
Wrapper around malloc.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
Handle for controlling an unindexing operation.
Definition: fs_api.h:1349
void * dir_data
Pointer to the data for the directory (or NULL if not available).
Definition: fs_api.h:373
struct GNUNET_FS_ProgressInfo::@25::@29 unindex
Values for all "GNUNET_FS_STATUS_UNINDEX_*" events.
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:1499
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:719
uint64_t abs_value_us
The actual value.
unsigned int max_parallel_requests
Maximum number of parallel requests.
Definition: fs_api.h:1171
int GNUNET_BIO_read_close(struct GNUNET_BIO_ReadHandle *h, char **emsg)
Close an open file.
Definition: bio.c:119
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#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
struct GNUNET_CRYPTO_FileHashContext * fhc
Context for hashing of the file.
Definition: fs_api.h:1443
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
Find out which keywords apply.
Definition: fs_api.h:1321
void(* GNUNET_SCHEDULER_TaskCallback)(void *cls)
Signature of the main function of a task.
struct GNUNET_FS_Uri * uri
List of keywords that we&#39;re looking for.
Definition: fs_api.h:1524
We&#39;re notifying the FS service about the unindexing.
Definition: fs_api.h:1332
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
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:3141
Initial state, block has only been allocated (since it is relevant to the overall download request)...
Definition: fs_api.h:1612
void GNUNET_FS_dequeue_(struct GNUNET_FS_QueueEntry *qe)
Dequeue a job from the queue.
Definition: fs_api.c:366
uint64_t old_file_size
What was the size of the file on disk that we&#39;re downloading before we started? Used to detect if the...
Definition: fs_api.h:1897
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
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
struct TopLevelActivity * top_tail
Tail of DLL of top-level activities.
Definition: fs_api.h:1098
int GNUNET_FS_uri_test_loc(const struct GNUNET_FS_Uri *uri)
Is this a location URI?
Definition: fs_uri.c:1395
uint32_t anonymity
Anonymity level for the search.
Definition: fs_api.h:1587
char * GNUNET_FS_uri_to_string(const struct GNUNET_FS_Uri *uri)
Convert a URI to a UTF-8 String.
Definition: fs_uri.c:2028
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:897
struct GNUNET_BIO_ReadHandle * GNUNET_BIO_read_open(const char *fn)
Open a file for reading.
Definition: bio.c:94
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
#define GNUNET_BIO_read_int64(h, i)
Read an (u)int64_t.
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 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:2623
uint32_t anonymity_level
At which anonymity level should the block be shared? (0: no anonymity, 1: normal GAP, >1: with cover traffic).
unsigned int GNUNET_FS_compute_depth(uint64_t flen)
Compute the depth of the CHK tree.
Definition: fs_tree.c:125
int GNUNET_BIO_read(struct GNUNET_BIO_ReadHandle *h, const char *what, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: bio.c:144
struct GNUNET_TIME_Absolute queue_time
Time the job was originally queued.
Definition: fs_api.h:459
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:1567
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
Meta data to associate with a file, directory or namespace.
union GNUNET_FS_ProgressInfo::@25 value
Values that depend on the event type.
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:1253
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:2916
void GNUNET_FS_search_start_probe_(struct GNUNET_FS_SearchResult *sr)
Start download probes for the given search result.
Definition: fs_search.c:430
struct TopLevelActivity * top
Our top-level activity entry.
Definition: fs_api.h:1365
char * GNUNET_DISK_mktemp(const char *t)
Create an (empty) temporary file on disk.
Definition: disk.c:468
void GNUNET_FS_publish_sync_(struct GNUNET_FS_PublishContext *pc)
Synchronize this publishing struct with its mirror on disk.
Definition: fs_api.c:1706
struct GNUNET_FS_DownloadContext * next
Next download belonging to the same parent.
Definition: fs_api.h:1789
char * serialization
Name of the file on disk we use for persistence.
Definition: fs_api.h:1545
int active
GNUNET_YES if the job is active now.
Definition: fs_api.h:490
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:1207
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:1968
enum State state
current state of profiling
char * serialization
Random portion of filename we use for syncing state of this download.
Definition: fs_api.h:1815
uint32_t availability_trials
Number of availability trials that we have performed for this search result.
Definition: fs_api.h:612
static char * value
Value of the record to add/remove.
#define GNUNET_FS_SYNC_PATH_MASTER_UNINDEX
Name of the directory with unindex operations.
Definition: fs_api.h:86
struct GNUNET_FS_FileInformation::@16::@17 file
Data for a file.
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:1408
struct GNUNET_FS_ProgressInfo::@25::@28 search
Values for all "GNUNET_FS_STATUS_SEARCH_*" events.
enum GNUNET_FS_QueuePriority priority
How important is this download?
Definition: fs_api.h:480
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
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
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
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:2811
static char * fn
Filename of the unique file.
Information we store for each search result.
Definition: fs_api.h:497
struct GNUNET_FS_Handle * h
File-sharing context this result belongs to.
Definition: fs_api.h:502
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:631
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:671
void GNUNET_FS_end_top(struct GNUNET_FS_Handle *h, struct TopLevelActivity *top)
Destroy a top-level activity entry.
Definition: fs_api.c:412
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
void *(* GNUNET_FS_ProgressCallback)(void *cls, const struct GNUNET_FS_ProgressInfo *info)
Notification of FS to a client about the progress of an operation.
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:1280
#define DIR_SEPARATOR_STR
Definition: platform.h:168
int GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
Definition: disk.c:1029
char * nuid
ID for future updates, NULL if we have no namespace or no updates.
Definition: fs_api.h:1208
enum GNUNET_FS_Status status
Specific status code (determines the event type).
int is_directory
Is this struct for a file or directory?
Definition: fs_api.h:390
uint32_t availability_success
Number of availability tests that have succeeded for this result.
Definition: fs_api.h:606
Internal option used to flag this download as a &#39;probe&#39; for a search result.
We&#39;re telling the datastore to remove KBlocks.
Definition: fs_api.h:1326
UnindexState
Phases of unindex processing (state machine).
Definition: fs_api.h:1305
#define GNUNET_MIN(a, b)
Definition: gnunet_common.h:80
static void free_download_context(struct GNUNET_FS_DownloadContext *dc)
Free this download context and all of its descendants.
Definition: fs_api.c:2777
void GNUNET_FS_search_result_sync_(struct GNUNET_FS_SearchResult *sr)
Synchronize this search result with its mirror on disk.
Definition: fs_api.c:2076
static struct GNUNET_NAMESTORE_Handle * ns
Handle to the namestore.
Definition: gnunet-abd.c:41
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:687
We&#39;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
struct GNUNET_TIME_Absolute start_time
When did we start?
Definition: fs_api.h:1453
Last event when a search is being resumed; note that "GNUNET_FS_SEARCH_START" will not be generated i...
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:331
uint16_t status
See PRISM_STATUS_*-constants.
static char buf[2048]
#define CHK_PER_INODE
Pick a multiple of 2 here to achive 8-byte alignment! We also probably want DBlocks to have (roughly)...
Definition: fs_api.h:43
void GNUNET_FS_publish_main_(void *cls)
Main function that performs the upload.
Definition: fs_publish.c:1062
static void cleanup(void *cls)
Function scheduled as very last function, cleans up after us.
void GNUNET_CONTAINER_meta_data_destroy(struct GNUNET_CONTAINER_MetaData *md)
Free meta data.
char * client_name
Name of our client.
Definition: fs_api.h:1078
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:442
struct TopLevelActivity * top_head
Head of DLL of top-level activities.
Definition: fs_api.h:1093
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
#define GNUNET_CONTAINER_DLL_insert_after(head, tail, other, element)
Insert an element into a DLL after the given other element.
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
struct GNUNET_FS_FileInformation * fi_pos
Current position in the file-tree for the upload.
Definition: fs_api.h:1225
struct GNUNET_CONTAINER_MultiHashMap * active
Map of active requests (those waiting for a response).
Definition: fs_api.h:1850
#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
GNUNET_FS_OPTIONS
Options specified in the VARARGs portion of GNUNET_FS_start.
int(* GNUNET_FileNameCallback)(void *cls, const char *filename)
Function called with a filename.
Handle for buffered writing.
Definition: bio.c:379
We&#39;ve encountered a fatal error.
Definition: fs_api.h:1342
struct GNUNET_FS_Uri * chk_uri
CHK for this file or directory.
Definition: fs_api.h:263
static void signal_download_resume(struct GNUNET_FS_DownloadContext *dc)
Send the &#39;resume&#39; signal to the callback; also actually resume the download (put it in the queue)...
Definition: fs_api.c:2585
We&#39;ve calculated the CHK bottom-up based on the meta data.
Definition: fs_api.h:1628
uint64_t offset
What is the first offset that we&#39;re interested in?
Definition: fs_api.h:1877
struct TopLevelActivity * top
Our top-level activity entry (if we are top-level, otherwise NULL).
Definition: fs_api.h:1752
void GNUNET_FS_uri_destroy(struct GNUNET_FS_Uri *uri)
Free URI.
Definition: fs_uri.c:678
Handle for controlling a publication process.
Definition: fs_api.h:1178
void GNUNET_FS_download_start_task_(void *cls)
Task that creates the initial (top-level) download request for the file.
Definition: fs_download.c:1809
static struct DownloadRequest * read_download_request(struct GNUNET_BIO_ReadHandle *rh)
Read a download request tree.
Definition: fs_api.c:1872
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
struct GNUNET_FS_Uri * ksk_uri
Keywords found (telling us which KBlocks to remove).
Definition: fs_api.h:1375
A 512-bit hashcode.
char * filename
Name of the file that we are unindexing.
Definition: fs_api.h:1385
We&#39;ve successfully downloaded this block, but the children still need to be either downloaded or veri...
Definition: fs_api.h:1654
int GNUNET_BIO_read_string(struct GNUNET_BIO_ReadHandle *h, const char *what, char **result, size_t max_length)
Read 0-terminated string from a file.
Definition: bio.c:233
GNUNET_SCHEDULER_TaskCallback start
Function to call when the job is started.
Definition: fs_api.h:434
#define GNUNET_FS_SYNC_PATH_CHILD_SEARCH
Name of the directory with sub-searches (namespace-updates).
Definition: fs_api.h:59
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
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
int GNUNET_FS_uri_test_chk(const struct GNUNET_FS_Uri *uri)
Is this a file (or directory) URI?
Definition: fs_uri.c:1357
Run when otherwise idle.
This block and all of its children have been downloaded successfully (full completion propagates up)...
Definition: fs_api.h:1660
#define DBLOCK_SIZE
Size of the individual blocks used for file-sharing.
Definition: fs.h:40
struct GNUNET_FS_QueueEntry * running_tail
Tail of DLL of running jobs.
Definition: fs_api.h:1108
uint64_t contents_size
Sum of all of the sizes of all of the files in the directory.
Definition: fs_api.h:383
#define DIR_SEPARATOR
Definition: platform.h:167
void * ssf_cls
Closure for &#39;ssf&#39; (some struct GNUNET_FS_XXXHandle*)
Definition: fs_api.h:1036
struct GNUNET_FS_Handle * h
Handle to FS primary context.
Definition: fs_api.h:449
unsigned int active_downloads
How many actual downloads do we have running right now?
Definition: fs_api.h:1151
#define GNUNET_FS_SYNC_PATH_FILE_INFO
Name of the directory with files that are being published.
Definition: fs_api.h:81
struct GNUNET_FS_SearchResult * search
Associated search (used when downloading files based on search results), or NULL for none...
Definition: fs_api.h:1769
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:1127
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:272
struct GNUNET_HashCode key
The key used in the DHT.
char * emsg
Error message, NULL if we&#39;re doing OK.
Definition: fs_api.h:1809
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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:591
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:3024
#define GNUNET_BIO_read_int32(h, i)
Read an (u)int32_t.
struct GNUNET_TIME_Absolute start_time
Time the job was started last.
Definition: fs_api.h:464
GNUNET_FS_DownloadOptions
Options for downloading.
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:525
int has_finished
Flag set upon transitive completion (includes child downloads).
Definition: fs_api.h:1929
int all_done
Set to GNUNET_YES if all processing has completed.
Definition: fs_api.h:1291
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:1939
Select the desired amount of parallelism (this option should be followed by an "unsigned int" giving ...
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
Definition: strings.c:603
Settings for publishing a block (which may of course also apply to an entire directory or file)...
static int write_start_time(struct GNUNET_BIO_WriteHandle *wh, struct GNUNET_TIME_Absolute timestamp)
Serialize a start-time.
Definition: fs_api.c:836
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:37
static struct GNUNET_TESTBED_BarrierWaitHandle * wh
Our barrier wait handle.
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:1170
struct GNUNET_CONTAINER_MetaData * meta
Metadata for the search result.
Definition: fs_api.h:528
Maximum number of requests that should be pending at a given point in time (invidivual downloads may ...
Notification that this download is being resumed.
enum GNUNET_FS_UriType type
Type of the URI.
Definition: fs_api.h:170
struct GNUNET_FS_FileInformation * next
Files in a directory are kept as a linked list.
Definition: fs_api.h:231
int 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.
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
int GNUNET_BIO_write_close(struct GNUNET_BIO_WriteHandle *h)
Close an open file for writing.
Definition: bio.c:438
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
struct GNUNET_HashCode key
Key for the search result based on the URI.
Definition: fs_api.h:566
void GNUNET_FS_unindex_sync_(struct GNUNET_FS_UnindexContext *uc)
Synchronize this unindex struct with its mirror on disk.
Definition: fs_api.c:1778
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
union GNUNET_FS_Uri::@13 data
struct GNUNET_FS_BlockOptions bo
Block options for the file.
Definition: fs_api.h:274
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:391
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
Allow multiple values with the same key.
uint32_t replication_level
How often should we try to migrate the block to other peers? Only used if "CONTENT_PUSHING" is set to...
Event generated for each search result when the respective search is resumed.
Notification that we have resumed sharing a file structure.
int do_index
Should the file be indexed or inserted?
Definition: fs_api.h:338
struct TopLevelActivity * top
Our top-level activity entry (if we are top-level, otherwise NULL).
Definition: fs_api.h:1188
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:579
struct GNUNET_TIME_Relative run_time
Total amount of time the job has been running (except for the current run).
Definition: fs_api.h:470
#define GNUNET_FS_SYNC_PATH_MASTER_SEARCH
Name of the directory with top-level searches.
Definition: fs_api.h:54
struct GNUNET_FS_DownloadContext * child_tail
Tail of list of child downloads.
Definition: fs_api.h:1779
static struct GNUNET_FS_PublishContext * pc
Handle to FS-publishing operation.
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
struct GNUNET_FS_FileInformation * fi
File-structure that is being shared.
Definition: fs_api.h:1193
GNUNET_FS_ProgressCallback upcb
Function to call with updates on our progress.
Definition: fs_api.h:1083
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:1204
unsigned int blocks
How many blocks do the active downloads have?
Definition: fs_api.h:475
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
struct GNUNET_FS_ProgressInfo::@25::@26 publish
Values for all "GNUNET_FS_STATUS_PUBLISH_*" events.
We&#39;re currently hashing the file.
Definition: fs_api.h:1310
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 HASHING_BLOCKSIZE
Blocksize to use when hashing files for indexing (blocksize for IO, not for the DBlocks).
Definition: fs.h:47
Seek an absolute position (from the start of the file).
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:1371
struct GNUNET_FS_QueueEntry * next
This is a linked list.
Definition: fs_api.h:424
configuration data
Definition: configuration.c:85
shared definitions for the FS library
We&#39;re telling the datastore to delete the respective DBlocks and IBlocks.
Definition: fs_api.h:1316
struct GNUNET_BIO_WriteHandle * GNUNET_BIO_write_open(const char *fn)
Open a file for writing.
Definition: bio.c:410
struct GNUNET_CRYPTO_EcdsaPrivateKey * ns
Namespace that we are publishing in, NULL if we have no namespace.
Definition: fs_api.h:1198
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.
struct GNUNET_PeerIdentity target
Identity of the peer having the content, or all-zeros if we don&#39;t know of such a peer.
Definition: fs_api.h:1861
A Universal Resource Identifier (URI), opaque.
Definition: fs_api.h:165
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:375
static int free_result(void *cls, const struct GNUNET_HashCode *key, void *value)
Iterator over search results freeing each.
Definition: fs_api.c:2675
static int read_start_time(struct GNUNET_BIO_ReadHandle *rh, struct GNUNET_TIME_Absolute *timestamp)
Deserialize a start-time.
Definition: fs_api.c:861
Handle for controlling a search.
Definition: fs_api.h:1509
#define GNUNET_VA_ARG_ENUM(va, X)
wrap va_arg for enums
static struct GNUNET_CONTAINER_MetaData * meta
Meta-data provided via command-line option.
void GNUNET_FS_unindex_do_extract_keywords_(struct GNUNET_FS_UnindexContext *uc)
Extract the keywords for KBlock removal.
Definition: fs_unindex.c:406
void * upcb_cls
Closure for upcb.
Definition: fs_api.h:1088
struct GNUNET_FS_Uri::@13::@14 ksk
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_FS_Uri * keywords
Keywords to use for KBlocks.
Definition: fs_api.h:257
char * filename
Name of the file to read.
Definition: fs_api.c:427
#define GNUNET_log(kind,...)
static int write_download_request(struct GNUNET_BIO_WriteHandle *wh, struct DownloadRequest *dr)
Serialize a download request.
Definition: fs_api.c:1844
void GNUNET_FS_file_information_destroy(struct GNUNET_FS_FileInformation *fi, GNUNET_FS_FileInformationProcessor cleaner, void *cleaner_cls)
Destroy publish-structure.
struct GNUNET_MQ_Handle * mq
Connection to the FS service.
Definition: fs_api.h:1535
uint32_t anonymity
Desired level of anonymity.
Definition: fs_api.h:1912
struct GNUNET_FS_Handle * h
Handle to the global FS context.
Definition: fs_api.h:1514
GNUNET_SCHEDULER_TaskCallback stop
Function to call when the job needs to stop (or is done / dequeued).
Definition: fs_api.h:439
unsigned int treedepth
The depth of the file-tree.
Definition: fs_api.h:1917
uint32_t content_priority
How important is it for us to store the block? If we run out of space, the highest-priority, non-expired blocks will be kept.
int 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_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
#define GNUNET_FS_SYNC_PATH_MASTER_PUBLISH
Name of the directory with publishing operations.
Definition: fs_api.h:76
int GNUNET_BIO_write_int32(struct GNUNET_BIO_WriteHandle *h, int32_t i)
Write an (u)int32_t.
Definition: bio.c:582
struct GNUNET_CONTAINER_MetaData * meta
Known meta-data for the file (can be NULL).
Definition: fs_api.h:1804
static int deserialize_subdownload(void *cls, const char *filename)
Function called with a filename of serialized sub-download to deserialize.
Definition: fs_api.c:2736
struct GNUNET_FS_QueueEntry * pending_tail
Tail of DLL of pending jobs.
Definition: fs_api.h:1118
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:331
int GNUNET_BIO_read_meta_data(struct GNUNET_BIO_ReadHandle *h, const char *what, struct GNUNET_CONTAINER_MetaData **result)
Read metadata container from a file.
Definition: bio.c:285
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:2433
uint64_t contents_completed
How much of the directory have we published (relative to contents_size).
Definition: fs_api.h:378
char * emsg
Error message, NULL on success.
Definition: fs_api.h:1438
Time for absolute times used by GNUnet, in microseconds.
#define GNUNET_YES
Definition: gnunet_common.h:77
void * cls
Closure for start and stop.
Definition: fs_api.h:444
struct GNUNET_TIME_Absolute start_time
Time download was started.
Definition: fs_api.h:1902
int GNUNET_BIO_write(struct GNUNET_BIO_WriteHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: bio.c:483
char * serialization
Name under which this search result is stored on disk.
Definition: fs_api.h:556
uint64_t completed
How many bytes have we already received within the specified range (DBlocks only).
Definition: fs_api.h:1889
struct GNUNET_FS_Uri * uri
URI that identifies the file that we are downloading.
Definition: fs_api.h:1799
int is_published
Are we done publishing this file?
Definition: fs_api.h:395
Notification that we resumed unindexing of a file.
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:2229
We track all of the top-level activities of FS so that we can signal &#39;suspend&#39; on shutdown...
Definition: fs_api.h:1016
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_FS_free_download_request_(struct DownloadRequest *dr)
(recursively) free download request structure
Definition: fs_download.c:996
struct GNUNET_FS_Handle * h
Global FS context.
Definition: fs_api.h:1360
uint32_t data
The data value.
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:1268
struct GNUNET_DATASTORE_Handle * GNUNET_DATASTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the datastore service.
unsigned int max_parallel_downloads
Maximum number of parallel downloads.
Definition: fs_api.h:1166
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
struct DownloadRequest * parent
Parent in the CHK-tree.
Definition: fs_api.h:1679
char * emsg
Error message, NULL if there were no errors.
Definition: bio.c:63
Entry in the job queue.
Definition: fs_api.h:419
void * client_info
Pointer we keep for the client.
Definition: fs_api.h:1540
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
Information about an active download request.
Definition: fs_api.h:1674
Handle used to access files (and pipes).
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:501
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
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:1276
struct GNUNET_FS_Uri * sks_uri
SKS URI for this file or directory.
Definition: fs_api.h:269
unsigned int depth
Depth of the corresponding block in the tree.
Definition: fs_api.h:1707
Closure for GNUNET_FS_data_reader_file_().
Definition: fs_api.c:422
We&#39;ve determined the real, desired CHK for this block (full tree reconstruction failed), request is now pending.
Definition: fs_api.h:1645
#define GNUNET_malloc(size)
Wrapper around malloc.
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:744
GNUNET_FS_QueuePriority
Priorities for the queue.
Definition: fs_api.h:402
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:1571
Handle for buffered reading.
Definition: bio.c:53
static struct GNUNET_FS_DownloadContext * dc
SuspendSignalFunction ssf
Function to call for suspend-signalling and clean up.
Definition: fs_api.h:1031
Default priority.
Definition: fs_api.h:412
static struct GNUNET_FS_BlockOptions bo
Options we set for published blocks.
unsigned int start_times
How often have we (re)started this download?
Definition: fs_api.h:485
#define GNUNET_free(ptr)
Wrapper around free.
Argument given to the progress callback with information about what is going on.
Time for relative time used by GNUnet, in microseconds.
Is persistence of operations desired? (will create SUSPEND/RESUME events).
enum GNUNET_FS_Flags flags
General flags.
Definition: fs_api.h:1161
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:803
struct GNUNET_FS_QueueEntry * job_queue
Our entry in the job queue.
Definition: fs_api.h:1833
Merkle-tree-ish-CHK file encoding for GNUnet.
uint64_t file_size
Overall size of the file.
Definition: fs_api.h:1448
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Definition: fs_api.h:1073