GNUnet  0.10.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);
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
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 {
426  char *filename;
427 
432 };
433 
434 
455 size_t
457  uint64_t offset,
458  size_t max,
459  void *buf,
460  char **emsg)
461 {
462  struct FileInfo *fi = cls;
463  ssize_t ret;
464 
465  if (UINT64_MAX == offset)
466  {
467  if (NULL != fi->fd)
468  {
470  fi->fd = NULL;
471  }
472  return 0;
473  }
474  if (0 == max)
475  {
476  if (NULL != fi->fd)
478  GNUNET_free(fi->filename);
479  GNUNET_free(fi);
480  return 0;
481  }
482  if (NULL == fi->fd)
483  {
487  if (NULL == fi->fd)
488  {
489  GNUNET_asprintf(emsg,
490  _("Could not open file `%s': %s"),
491  fi->filename,
492  strerror(errno));
493  return 0;
494  }
495  }
496  if ((GNUNET_SYSERR ==
498  (-1 == (ret = GNUNET_DISK_file_read(fi->fd, buf, max))))
499  {
500  GNUNET_asprintf(emsg,
501  _("Could not read file `%s': %s"),
502  fi->filename,
503  strerror(errno));
504  return 0;
505  }
506  if (ret != max)
507  {
508  GNUNET_asprintf(emsg,
509  _("Short read reading from file `%s'!"),
510  fi->filename);
511  return 0;
512  }
513  return max;
514 }
515 
516 
523 void *
525 {
526  struct FileInfo *fi;
527 
528  fi = GNUNET_new(struct FileInfo);
530  if (NULL == fi->filename)
531  {
532  GNUNET_free(fi);
533  return NULL;
534  }
535  return fi;
536 }
537 
538 
559 size_t
561  uint64_t offset,
562  size_t max,
563  void *buf,
564  char **emsg)
565 {
566  char *data = cls;
567 
568  if (UINT64_MAX == offset)
569  return 0;
570  if (0 == max)
571  {
572  GNUNET_free_non_null(data);
573  return 0;
574  }
575  GNUNET_memcpy(buf, &data[offset], max);
576  return max;
577 }
578 
579 
589 static char *
591  const char *ext,
592  const char *ent)
593 {
594  char *basename;
595  char *ret;
596 
597  if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
598  return NULL; /* persistence not requested */
600  "fs",
601  "STATE_DIR",
602  &basename))
603  return NULL;
604  GNUNET_asprintf(&ret,
605  "%s%s%s%s%s%s%s",
606  basename,
608  h->client_name,
610  ext,
612  ent);
613  GNUNET_free(basename);
614  return ret;
615 }
616 
617 
629 static char *
631  const char *ext,
632  const char *uni,
633  const char *ent)
634 {
635  char *basename;
636  char *ret;
637 
638  if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
639  return NULL; /* persistence not requested */
641  "fs",
642  "STATE_DIR",
643  &basename))
644  return NULL;
645  GNUNET_asprintf(&ret,
646  "%s%s%s%s%s%s%s.dir%s%s",
647  basename,
649  h->client_name,
651  ext,
653  uni,
655  ent);
656  GNUNET_free(basename);
657  return ret;
658 }
659 
660 
669 static struct GNUNET_BIO_ReadHandle *
670 get_read_handle(struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
671 {
672  char *fn;
673  struct GNUNET_BIO_ReadHandle *ret;
674 
675  fn = get_serialization_file_name(h, ext, ent);
676  if (NULL == fn)
677  return NULL;
678  ret = GNUNET_BIO_read_open(fn);
679  GNUNET_free(fn);
680  return ret;
681 }
682 
683 
692 static struct GNUNET_BIO_WriteHandle *
693 get_write_handle(struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
694 {
695  char *fn;
696  struct GNUNET_BIO_WriteHandle *ret;
697 
698  fn = get_serialization_file_name(h, ext, ent);
699  if (NULL == fn)
700  return NULL;
701  ret = GNUNET_BIO_write_open(fn);
702  GNUNET_break(NULL != ret);
703  GNUNET_free(fn);
704  return ret;
705 }
706 
707 
717 static struct GNUNET_BIO_WriteHandle *
719  const char *ext,
720  const char *uni,
721  const char *ent)
722 {
723  char *fn;
724  struct GNUNET_BIO_WriteHandle *ret;
725 
726  fn = get_serialization_file_name_in_dir(h, ext, uni, ent);
727  if (NULL == fn)
728  return NULL;
729  ret = GNUNET_BIO_write_open(fn);
730  GNUNET_free(fn);
731  return ret;
732 }
733 
734 
742 void
744  const char *ext,
745  const char *ent)
746 {
747  char *filename;
748 
749  if ((NULL == ent) || (0 == strlen(ent)))
750  {
751  GNUNET_break(0);
752  return;
753  }
754  filename = get_serialization_file_name(h, ext, ent);
755  if (NULL != filename)
756  {
757  if ((0 != unlink(filename)) && (ENOENT != errno))
759  GNUNET_free(filename);
760  }
761 }
762 
763 
772 static void
774  const char *ext,
775  const char *uni,
776  const char *ent)
777 {
778  char *filename;
779 
780  if ((NULL == ent) || (0 == strlen(ent)))
781  {
782  GNUNET_break(0);
783  return;
784  }
785  filename = get_serialization_file_name_in_dir(h, ext, uni, ent);
786  if (NULL == filename)
787  return;
788  if (0 != unlink(filename))
790  GNUNET_free(filename);
791 }
792 
793 
801 void
803  const char *ext,
804  const char *uni)
805 {
806  char *dn;
807 
808  if (NULL == uni)
809  return;
810  dn = get_serialization_file_name_in_dir(h, ext, uni, "");
811  if (NULL == dn)
812  return;
816  GNUNET_free(dn);
817 }
818 
819 
834 static int
836  struct GNUNET_TIME_Absolute timestamp)
837 {
838  struct GNUNET_TIME_Relative dur;
839 
840  dur = GNUNET_TIME_absolute_get_duration(timestamp);
841  return GNUNET_BIO_write_int64(wh, dur.rel_value_us);
842 }
843 
844 
859 static int
861  struct GNUNET_TIME_Absolute *timestamp)
862 {
863  struct GNUNET_TIME_Relative dur;
864 
866  return GNUNET_SYSERR;
868  return GNUNET_OK;
869 }
870 
871 
881 static struct GNUNET_FS_FileInformation *
883 
884 
895 static struct GNUNET_FS_FileInformation *
897  const char *fn,
898  struct GNUNET_BIO_ReadHandle *rh)
899 {
901  struct GNUNET_FS_FileInformation *nxt;
902  char b;
903  char *ksks;
904  char *chks;
905  char *skss;
906  char *filename;
907  uint32_t dsize;
908 
909  if (GNUNET_OK != GNUNET_BIO_read(rh, "status flag", &b, sizeof(b)))
910  {
911  GNUNET_break(0);
912  return NULL;
913  }
915  ret->h = h;
916  ksks = NULL;
917  chks = NULL;
918  skss = NULL;
919  filename = NULL;
920  if ((GNUNET_OK != GNUNET_BIO_read_meta_data(rh, "metadata", &ret->meta)) ||
921  (GNUNET_OK != GNUNET_BIO_read_string(rh, "ksk-uri", &ksks, 32 * 1024)) ||
922  ((NULL != ksks) &&
923  ((NULL == (ret->keywords = GNUNET_FS_uri_parse(ksks, NULL))) ||
925  (GNUNET_OK != GNUNET_BIO_read_string(rh, "chk-uri", &chks, 1024)) ||
926  ((NULL != chks) &&
927  ((NULL == (ret->chk_uri = GNUNET_FS_uri_parse(chks, NULL))) ||
929  (GNUNET_OK != GNUNET_BIO_read_string(rh, "sks-uri", &skss, 1024)) ||
930  ((NULL != skss) &&
931  ((NULL == (ret->sks_uri = GNUNET_FS_uri_parse(skss, NULL))) ||
933  (GNUNET_OK != read_start_time(rh, &ret->start_time)) ||
934  (GNUNET_OK !=
935  GNUNET_BIO_read_string(rh, "emsg", &ret->emsg, 16 * 1024)) ||
936  (GNUNET_OK !=
937  GNUNET_BIO_read_string(rh, "fn", &ret->filename, 16 * 1024)) ||
938  (GNUNET_OK !=
943  {
944  GNUNET_break(0);
945  goto cleanup;
946  }
947  switch (b)
948  {
949  case 0: /* file-insert */
950  if (GNUNET_OK != GNUNET_BIO_read_int64(rh, &ret->data.file.file_size))
951  {
952  GNUNET_break(0);
953  goto cleanup;
954  }
955  ret->is_directory = GNUNET_NO;
956  ret->data.file.do_index = GNUNET_NO;
957  ret->data.file.have_hash = GNUNET_NO;
958  ret->data.file.index_start_confirmed = GNUNET_NO;
959  if (GNUNET_NO == ret->is_published)
960  {
961  if (NULL == ret->filename)
962  {
963  ret->data.file.reader = &GNUNET_FS_data_reader_copy_;
964  ret->data.file.reader_cls =
965  GNUNET_malloc_large(ret->data.file.file_size);
966  if (ret->data.file.reader_cls == NULL)
967  goto cleanup;
968  if (GNUNET_OK != GNUNET_BIO_read(rh,
969  "file-data",
970  ret->data.file.reader_cls,
971  ret->data.file.file_size))
972  {
973  GNUNET_break(0);
974  goto cleanup;
975  }
976  }
977  else
978  {
979  ret->data.file.reader = &GNUNET_FS_data_reader_file_;
980  ret->data.file.reader_cls =
982  }
983  }
984  break;
985 
986  case 1: /* file-index, no hash */
987  if (NULL == ret->filename)
988  {
989  GNUNET_break(0);
990  goto cleanup;
991  }
992  if (GNUNET_OK != GNUNET_BIO_read_int64(rh, &ret->data.file.file_size))
993  {
994  GNUNET_break(0);
995  goto cleanup;
996  }
997  ret->is_directory = GNUNET_NO;
998  ret->data.file.do_index = GNUNET_YES;
999  ret->data.file.have_hash = GNUNET_NO;
1000  ret->data.file.index_start_confirmed = GNUNET_NO;
1001  ret->data.file.reader = &GNUNET_FS_data_reader_file_;
1002  ret->data.file.reader_cls =
1004  break;
1005 
1006  case 2: /* file-index-with-hash */
1007  if (NULL == ret->filename)
1008  {
1009  GNUNET_break(0);
1010  goto cleanup;
1011  }
1012  if ((GNUNET_OK != GNUNET_BIO_read_int64(rh, &ret->data.file.file_size)) ||
1013  (GNUNET_OK != GNUNET_BIO_read(rh,
1014  "fileid",
1015  &ret->data.file.file_id,
1016  sizeof(struct GNUNET_HashCode))))
1017  {
1018  GNUNET_break(0);
1019  goto cleanup;
1020  }
1021  ret->is_directory = GNUNET_NO;
1022  ret->data.file.do_index = GNUNET_YES;
1023  ret->data.file.have_hash = GNUNET_YES;
1024  ret->data.file.index_start_confirmed = GNUNET_NO;
1025  ret->data.file.reader = &GNUNET_FS_data_reader_file_;
1026  ret->data.file.reader_cls =
1028  break;
1029 
1030  case 3: /* file-index-with-hash-confirmed */
1031  if (NULL == ret->filename)
1032  {
1033  GNUNET_break(0);
1034  goto cleanup;
1035  }
1036  if ((GNUNET_OK != GNUNET_BIO_read_int64(rh, &ret->data.file.file_size)) ||
1037  (GNUNET_OK != GNUNET_BIO_read(rh,
1038  "fileid",
1039  &ret->data.file.file_id,
1040  sizeof(struct GNUNET_HashCode))))
1041  {
1042  GNUNET_break(0);
1043  goto cleanup;
1044  }
1045  ret->is_directory = GNUNET_NO;
1046  ret->data.file.do_index = GNUNET_YES;
1047  ret->data.file.have_hash = GNUNET_YES;
1048  ret->data.file.index_start_confirmed = GNUNET_YES;
1049  ret->data.file.reader = &GNUNET_FS_data_reader_file_;
1050  ret->data.file.reader_cls =
1052  break;
1053 
1054  case 4: /* directory */
1055  ret->is_directory = GNUNET_YES;
1056  if ((GNUNET_OK != GNUNET_BIO_read_int32(rh, &dsize)) ||
1057  (GNUNET_OK !=
1059  (GNUNET_OK !=
1061  (NULL == (ret->data.dir.dir_data = GNUNET_malloc_large(dsize))) ||
1062  (GNUNET_OK !=
1063  GNUNET_BIO_read(rh, "dir-data", ret->data.dir.dir_data, dsize)) ||
1064  (GNUNET_OK !=
1065  GNUNET_BIO_read_string(rh, "ent-filename", &filename, 16 * 1024)))
1066  {
1067  GNUNET_break(0);
1068  goto cleanup;
1069  }
1070  ret->data.dir.dir_size = (uint32_t)dsize;
1071  if (NULL != filename)
1072  {
1073  ret->data.dir.entries = deserialize_file_information(h, filename);
1074  GNUNET_free(filename);
1075  filename = NULL;
1076  nxt = ret->data.dir.entries;
1077  while (NULL != nxt)
1078  {
1079  nxt->dir = ret;
1080  nxt = nxt->next;
1081  }
1082  }
1083  break;
1084 
1085  default:
1086  GNUNET_break(0);
1087  goto cleanup;
1088  }
1089  ret->serialization = GNUNET_strdup(fn);
1090  if (GNUNET_OK !=
1091  GNUNET_BIO_read_string(rh, "nxt-filename", &filename, 16 * 1024))
1092  {
1093  GNUNET_break(0);
1094  goto cleanup;
1095  }
1096  if (NULL != filename)
1097  {
1098  ret->next = deserialize_file_information(h, filename);
1099  GNUNET_free(filename);
1100  filename = NULL;
1101  }
1102  GNUNET_free_non_null(ksks);
1103  GNUNET_free_non_null(skss);
1104  GNUNET_free_non_null(chks);
1105  return ret;
1106 cleanup:
1107  GNUNET_free_non_null(ksks);
1108  GNUNET_free_non_null(chks);
1109  GNUNET_free_non_null(skss);
1110  GNUNET_free_non_null(filename);
1111  GNUNET_FS_file_information_destroy(ret, NULL, NULL);
1112  return NULL;
1113 }
1114 
1115 
1125 static struct GNUNET_FS_FileInformation *
1127 {
1129  struct GNUNET_BIO_ReadHandle *rh;
1130  char *emsg;
1131  char *fn;
1132 
1134  if (NULL == rh)
1135  return NULL;
1136  ret = deserialize_fi_node(h, filename, rh);
1137  if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg))
1138  {
1140  _("Failed to resume publishing information `%s': %s\n"),
1141  filename,
1142  emsg);
1143  GNUNET_free(emsg);
1144  }
1145  if (NULL == ret)
1146  {
1147  fn =
1149  if (NULL != fn)
1150  {
1151  if (0 != unlink(fn))
1153  GNUNET_free(fn);
1154  }
1155  }
1156  return ret;
1157 }
1158 
1159 
1168 static char *
1169 get_serialization_short_name(const char *fullname)
1170 {
1171  const char *end;
1172  const char *nxt;
1173 
1174  end = NULL;
1175  nxt = fullname;
1176  /* FIXME: we could do this faster since we know
1177  * the length of 'end'... */
1178  while ('\0' != *nxt)
1179  {
1180  if (DIR_SEPARATOR == *nxt)
1181  end = nxt + 1;
1182  nxt++;
1183  }
1184  if ((NULL == end) || (0 == strlen(end)))
1185  {
1186  GNUNET_break(0);
1187  return NULL;
1188  }
1189  GNUNET_break(6 == strlen(end));
1190  return GNUNET_strdup(end);
1191 }
1192 
1193 
1202 static char *
1204 {
1205  char *fn;
1206  char *dn;
1207  char *ret;
1208 
1209  if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
1210  return NULL; /* persistence not requested */
1211  dn = get_serialization_file_name(h, ext, "");
1212  if (NULL == dn)
1213  return NULL;
1215  {
1216  GNUNET_free(dn);
1217  return NULL;
1218  }
1219  fn = GNUNET_DISK_mktemp(dn);
1220  GNUNET_free(dn);
1221  if (NULL == fn)
1222  return NULL; /* epic fail */
1223  ret = get_serialization_short_name(fn);
1224  GNUNET_free(fn);
1225  return ret;
1226 }
1227 
1228 
1238 static char *
1240  const char *ext,
1241  const char *uni)
1242 {
1243  char *fn;
1244  char *dn;
1245  char *ret;
1246 
1247  if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
1248  return NULL; /* persistence not requested */
1249  dn = get_serialization_file_name_in_dir(h, ext, uni, "");
1250  if (NULL == dn)
1251  return NULL;
1253  {
1254  GNUNET_free(dn);
1255  return NULL;
1256  }
1257  fn = GNUNET_DISK_mktemp(dn);
1258  GNUNET_free(dn);
1259  if (NULL == fn)
1260  return NULL; /* epic fail */
1261  ret = get_serialization_short_name(fn);
1262  GNUNET_free(fn);
1263  return ret;
1264 }
1265 
1266 
1274 static int
1276  struct GNUNET_FS_FileInformation *fi)
1277 {
1278  char buf[32 * 1024];
1279  uint64_t off;
1280  size_t ret;
1281  size_t left;
1282  char *emsg;
1283 
1284  emsg = NULL;
1285  off = 0;
1286  while (off < fi->data.file.file_size)
1287  {
1288  left = GNUNET_MIN(sizeof(buf), fi->data.file.file_size - off);
1289  ret =
1290  fi->data.file.reader(fi->data.file.reader_cls, off, left, buf, &emsg);
1291  if (0 == ret)
1292  {
1293  GNUNET_free(emsg);
1294  return GNUNET_SYSERR;
1295  }
1296  if (GNUNET_OK != GNUNET_BIO_write(wh, buf, ret))
1297  return GNUNET_SYSERR;
1298  off += ret;
1299  }
1300  return GNUNET_OK;
1301 }
1302 
1303 
1310 void
1312 {
1313  char *fn;
1314  struct GNUNET_BIO_WriteHandle *wh;
1315  char b;
1316  char *ksks;
1317  char *chks;
1318  char *skss;
1319 
1320  if (NULL == fi->serialization)
1321  fi->serialization =
1323  if (NULL == fi->serialization)
1324  return;
1325  wh =
1327  if (NULL == wh)
1328  {
1330  fi->serialization = NULL;
1331  return;
1332  }
1333  if (GNUNET_YES == fi->is_directory)
1334  b = 4;
1335  else if (GNUNET_YES == fi->data.file.index_start_confirmed)
1336  b = 3;
1337  else if (GNUNET_YES == fi->data.file.have_hash)
1338  b = 2;
1339  else if (GNUNET_YES == fi->data.file.do_index)
1340  b = 1;
1341  else
1342  b = 0;
1343  if (NULL != fi->keywords)
1344  ksks = GNUNET_FS_uri_to_string(fi->keywords);
1345  else
1346  ksks = NULL;
1347  if (NULL != fi->chk_uri)
1348  chks = GNUNET_FS_uri_to_string(fi->chk_uri);
1349  else
1350  chks = NULL;
1351  if (NULL != fi->sks_uri)
1352  skss = GNUNET_FS_uri_to_string(fi->sks_uri);
1353  else
1354  skss = NULL;
1355  if ((GNUNET_OK != GNUNET_BIO_write(wh, &b, sizeof(b))) ||
1356  (GNUNET_OK != GNUNET_BIO_write_meta_data(wh, fi->meta)) ||
1357  (GNUNET_OK != GNUNET_BIO_write_string(wh, ksks)) ||
1358  (GNUNET_OK != GNUNET_BIO_write_string(wh, chks)) ||
1359  (GNUNET_OK != GNUNET_BIO_write_string(wh, skss)) ||
1360  (GNUNET_OK != write_start_time(wh, fi->start_time)) ||
1361  (GNUNET_OK != GNUNET_BIO_write_string(wh, fi->emsg)) ||
1362  (GNUNET_OK != GNUNET_BIO_write_string(wh, fi->filename)) ||
1363  (GNUNET_OK !=
1368  {
1369  GNUNET_break(0);
1370  goto cleanup;
1371  }
1372  GNUNET_free_non_null(chks);
1373  chks = NULL;
1374  GNUNET_free_non_null(ksks);
1375  ksks = NULL;
1376  GNUNET_free_non_null(skss);
1377  skss = NULL;
1378 
1379  switch (b)
1380  {
1381  case 0: /* file-insert */
1382  if (GNUNET_OK != GNUNET_BIO_write_int64(wh, fi->data.file.file_size))
1383  {
1384  GNUNET_break(0);
1385  goto cleanup;
1386  }
1387  if ((GNUNET_NO == fi->is_published) && (NULL == fi->filename))
1388  if (GNUNET_OK != copy_from_reader(wh, fi))
1389  {
1390  GNUNET_break(0);
1391  goto cleanup;
1392  }
1393  break;
1394 
1395  case 1: /* file-index, no hash */
1396  if (NULL == fi->filename)
1397  {
1398  GNUNET_break(0);
1399  goto cleanup;
1400  }
1401  if (GNUNET_OK != GNUNET_BIO_write_int64(wh, fi->data.file.file_size))
1402  {
1403  GNUNET_break(0);
1404  goto cleanup;
1405  }
1406  break;
1407 
1408  case 2: /* file-index-with-hash */
1409  case 3: /* file-index-with-hash-confirmed */
1410  if (NULL == fi->filename)
1411  {
1412  GNUNET_break(0);
1413  goto cleanup;
1414  }
1415  if ((GNUNET_OK != GNUNET_BIO_write_int64(wh, fi->data.file.file_size)) ||
1416  (GNUNET_OK != GNUNET_BIO_write(wh,
1417  &fi->data.file.file_id,
1418  sizeof(struct GNUNET_HashCode))))
1419  {
1420  GNUNET_break(0);
1421  goto cleanup;
1422  }
1423  break;
1424 
1425  case 4: /* directory */
1426  if ((NULL != fi->data.dir.entries) &&
1427  (NULL == fi->data.dir.entries->serialization))
1429  if ((GNUNET_OK != GNUNET_BIO_write_int32(wh, fi->data.dir.dir_size)) ||
1430  (GNUNET_OK !=
1432  (GNUNET_OK !=
1434  (GNUNET_OK != GNUNET_BIO_write(wh,
1435  fi->data.dir.dir_data,
1436  (uint32_t)fi->data.dir.dir_size)) ||
1437  (GNUNET_OK !=
1439  (fi->data.dir.entries == NULL)
1440  ? NULL
1441  : fi->data.dir.entries->serialization)))
1442  {
1443  GNUNET_break(0);
1444  goto cleanup;
1445  }
1446  break;
1447 
1448  default:
1449  GNUNET_assert(0);
1450  goto cleanup;
1451  }
1452  if ((NULL != fi->next) && (NULL == fi->next->serialization))
1455  (fi->next != NULL)
1456  ? fi->next->serialization
1457  : NULL))
1458  {
1459  GNUNET_break(0);
1460  goto cleanup;
1461  }
1462  if (GNUNET_OK != GNUNET_BIO_write_close(wh))
1463  {
1464  wh = NULL;
1465  GNUNET_break(0);
1466  goto cleanup;
1467  }
1468  return; /* done! */
1469 cleanup:
1470  if (NULL != wh)
1471  (void)GNUNET_BIO_write_close(wh);
1472  GNUNET_free_non_null(chks);
1473  GNUNET_free_non_null(ksks);
1474  GNUNET_free_non_null(skss);
1475  fn = get_serialization_file_name(fi->h,
1477  fi->serialization);
1478  if (NULL != fn)
1479  {
1480  if (0 != unlink(fn))
1482  GNUNET_free(fn);
1483  }
1485  fi->serialization = NULL;
1486 }
1487 
1488 
1497 static struct GNUNET_FS_FileInformation *
1498 find_file_position(struct GNUNET_FS_FileInformation *pos, const char *srch)
1499 {
1500  struct GNUNET_FS_FileInformation *r;
1501 
1502  while (NULL != pos)
1503  {
1504  if (0 == strcmp(srch, pos->serialization))
1505  return pos;
1506  if ((GNUNET_YES == pos->is_directory) &&
1507  (NULL != (r = find_file_position(pos->data.dir.entries, srch))))
1508  return r;
1509  pos = pos->next;
1510  }
1511  return NULL;
1512 }
1513 
1514 
1529 static int
1531  struct GNUNET_FS_FileInformation *fi,
1532  uint64_t length,
1534  struct GNUNET_FS_Uri **uri,
1535  struct GNUNET_FS_BlockOptions *bo,
1536  int *do_index,
1537  void **client_info)
1538 {
1539  struct GNUNET_FS_PublishContext *pc = cls;
1540  struct GNUNET_FS_ProgressInfo pi;
1541 
1542  if (GNUNET_YES == pc->skip_next_fi_callback)
1543  {
1545  return GNUNET_OK;
1546  }
1548  pi.value.publish.specifics.resume.message = fi->emsg;
1549  pi.value.publish.specifics.resume.chk_uri = fi->chk_uri;
1550  *client_info = GNUNET_FS_publish_make_status_(&pi, pc, fi, 0);
1552  {
1553  /* process entries in directory */
1556  }
1557  return GNUNET_OK;
1558 }
1559 
1560 
1569 static int
1570 deserialize_publish_file(void *cls, const char *filename)
1571 {
1572  struct GNUNET_FS_Handle *h = cls;
1573  struct GNUNET_BIO_ReadHandle *rh;
1574  struct GNUNET_FS_PublishContext *pc;
1575  int32_t options;
1576  int32_t all_done;
1577  int32_t have_ns;
1578  char *fi_root;
1580  char *fi_pos;
1581  char *emsg;
1582 
1583  pc = GNUNET_new(struct GNUNET_FS_PublishContext);
1584  pc->h = h;
1586  fi_root = NULL;
1587  fi_pos = NULL;
1588  rh = GNUNET_BIO_read_open(filename);
1589  if (NULL == rh)
1590  {
1591  GNUNET_break(0);
1592  goto cleanup;
1593  }
1594  if ((GNUNET_OK !=
1595  GNUNET_BIO_read_string(rh, "publish-nid", &pc->nid, 1024)) ||
1596  (GNUNET_OK !=
1597  GNUNET_BIO_read_string(rh, "publish-nuid", &pc->nuid, 1024)) ||
1598  (GNUNET_OK != GNUNET_BIO_read_int32(rh, &options)) ||
1599  (GNUNET_OK != GNUNET_BIO_read_int32(rh, &all_done)) ||
1600  (GNUNET_OK != GNUNET_BIO_read_int32(rh, &have_ns)) ||
1601  (GNUNET_OK !=
1602  GNUNET_BIO_read_string(rh, "publish-firoot", &fi_root, 128)) ||
1603  (GNUNET_OK !=
1604  GNUNET_BIO_read_string(rh, "publish-fipos", &fi_pos, 128)) ||
1605  ((GNUNET_YES == have_ns) &&
1606  (GNUNET_OK != GNUNET_BIO_read(rh, "publish-ns", &ns, sizeof(ns)))))
1607  {
1608  GNUNET_break(0);
1609  goto cleanup;
1610  }
1611  pc->options = options;
1612  pc->all_done = all_done;
1613  if (NULL == fi_root)
1614  {
1615  GNUNET_break(0);
1616  goto cleanup;
1617  }
1618  pc->fi = deserialize_file_information(h, fi_root);
1619  if (NULL == pc->fi)
1620  {
1621  GNUNET_break(0);
1622  goto cleanup;
1623  }
1624  if (GNUNET_YES == have_ns)
1625  {
1627  *pc->ns = ns;
1628  }
1629  if ((0 == (pc->options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) &&
1630  (GNUNET_YES != pc->all_done))
1631  {
1632  pc->dsh = GNUNET_DATASTORE_connect(h->cfg);
1633  if (NULL == pc->dsh)
1634  goto cleanup;
1635  }
1636  if (NULL != fi_pos)
1637  {
1638  pc->fi_pos = find_file_position(pc->fi, fi_pos);
1639  GNUNET_free(fi_pos);
1640  fi_pos = NULL;
1641  if (NULL == pc->fi_pos)
1642  {
1643  /* failed to find position for resuming, outch! Will start from root! */
1644  GNUNET_break(0);
1645  if (GNUNET_YES != pc->all_done)
1646  pc->fi_pos = pc->fi;
1647  }
1648  }
1649  GNUNET_free(fi_root);
1650  fi_root = NULL;
1651  /* generate RESUME event(s) */
1653 
1654  /* re-start publishing (if needed)... */
1655  if (GNUNET_YES != pc->all_done)
1656  {
1657  GNUNET_assert(NULL == pc->upload_task);
1658  pc->upload_task =
1661  pc);
1662  }
1663  if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg))
1664  {
1666  _("Failure while resuming publishing operation `%s': %s\n"),
1667  filename,
1668  emsg);
1669  GNUNET_free(emsg);
1670  }
1672  return GNUNET_OK;
1673 cleanup:
1676  GNUNET_free_non_null(fi_root);
1677  GNUNET_free_non_null(fi_pos);
1678  if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg)))
1679  {
1681  _("Failed to resume publishing operation `%s': %s\n"),
1682  filename,
1683  emsg);
1684  GNUNET_free(emsg);
1685  }
1686  if (NULL != pc->fi)
1687  GNUNET_FS_file_information_destroy(pc->fi, NULL, NULL);
1688  if (0 != unlink(filename))
1691  GNUNET_free(pc);
1692  return GNUNET_OK;
1693 }
1694 
1695 
1704 void
1706 {
1707  struct GNUNET_BIO_WriteHandle *wh;
1708  int32_t have_ns;
1709 
1710  if (NULL == pc->serialization)
1711  pc->serialization =
1713  if (NULL == pc->serialization)
1714  return;
1715  if (NULL == pc->fi)
1716  return;
1717  if (NULL == pc->fi->serialization)
1718  {
1719  GNUNET_break(0);
1720  return;
1721  }
1722  wh = get_write_handle(pc->h,
1724  pc->serialization);
1725  if (NULL == wh)
1726  {
1727  GNUNET_break(0);
1728  goto cleanup;
1729  }
1730  have_ns = (NULL != pc->ns) ? GNUNET_YES : GNUNET_NO;
1731  if ((GNUNET_OK != GNUNET_BIO_write_string(wh, pc->nid)) ||
1732  (GNUNET_OK != GNUNET_BIO_write_string(wh, pc->nuid)) ||
1733  (GNUNET_OK != GNUNET_BIO_write_int32(wh, pc->options)) ||
1734  (GNUNET_OK != GNUNET_BIO_write_int32(wh, pc->all_done)) ||
1735  (GNUNET_OK != GNUNET_BIO_write_int32(wh, have_ns)) ||
1738  (NULL == pc->fi_pos)
1739  ? NULL
1740  : pc->fi_pos->serialization)) ||
1741  ((NULL != pc->ns) &&
1742  (GNUNET_OK !=
1743  GNUNET_BIO_write(wh,
1744  pc->ns,
1745  sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey)))))
1746  {
1747  GNUNET_break(0);
1748  goto cleanup;
1749  }
1750  if (GNUNET_OK != GNUNET_BIO_write_close(wh))
1751  {
1752  wh = NULL;
1753  GNUNET_break(0);
1754  goto cleanup;
1755  }
1756  return;
1757 cleanup:
1758  if (NULL != wh)
1759  (void)GNUNET_BIO_write_close(wh);
1762  pc->serialization);
1764  pc->serialization = NULL;
1765 }
1766 
1767 
1776 void
1778 {
1779  struct GNUNET_BIO_WriteHandle *wh;
1780  char *uris;
1781 
1782  if (NULL == uc->serialization)
1783  uc->serialization =
1785  if (NULL == uc->serialization)
1786  return;
1787  wh = get_write_handle(uc->h,
1789  uc->serialization);
1790  if (NULL == wh)
1791  {
1792  GNUNET_break(0);
1793  goto cleanup;
1794  }
1795  if (NULL != uc->ksk_uri)
1796  uris = GNUNET_FS_uri_to_string(uc->ksk_uri);
1797  else
1798  uris = NULL;
1799  if ((GNUNET_OK != GNUNET_BIO_write_string(wh, uc->filename)) ||
1800  (GNUNET_OK != GNUNET_BIO_write_int64(wh, uc->file_size)) ||
1801  (GNUNET_OK != write_start_time(wh, uc->start_time)) ||
1802  (GNUNET_OK != GNUNET_BIO_write_int32(wh, (uint32_t)uc->state)) ||
1803  (GNUNET_OK !=
1804  GNUNET_BIO_write(wh, &uc->chk, sizeof(struct ContentHashKey))) ||
1805  (GNUNET_OK != GNUNET_BIO_write_string(wh, uris)) ||
1806  (GNUNET_OK != GNUNET_BIO_write_int32(wh, (uint32_t)uc->ksk_offset)) ||
1807  ((uc->state == UNINDEX_STATE_FS_NOTIFY) &&
1808  (GNUNET_OK != GNUNET_BIO_write(wh,
1809  &uc->file_id,
1810  sizeof(struct GNUNET_HashCode)))) ||
1811  ((uc->state == UNINDEX_STATE_ERROR) &&
1812  (GNUNET_OK != GNUNET_BIO_write_string(wh, uc->emsg))))
1813  {
1814  GNUNET_break(0);
1815  goto cleanup;
1816  }
1817  if (GNUNET_OK != GNUNET_BIO_write_close(wh))
1818  {
1819  wh = NULL;
1820  GNUNET_break(0);
1821  goto cleanup;
1822  }
1823  return;
1824 cleanup:
1825  if (NULL != wh)
1826  (void)GNUNET_BIO_write_close(wh);
1829  uc->serialization);
1831  uc->serialization = NULL;
1832 }
1833 
1834 
1842 static int
1844  struct DownloadRequest *dr)
1845 {
1846  unsigned int i;
1847 
1848  if ((GNUNET_OK != GNUNET_BIO_write_int32(wh, dr->state)) ||
1849  (GNUNET_OK != GNUNET_BIO_write_int64(wh, dr->offset)) ||
1851  (GNUNET_OK != GNUNET_BIO_write_int32(wh, dr->depth)))
1852  return GNUNET_NO;
1853  if ((BRS_CHK_SET == dr->state) &&
1854  (GNUNET_OK !=
1855  GNUNET_BIO_write(wh, &dr->chk, sizeof(struct ContentHashKey))))
1856  return GNUNET_NO;
1857  for (i = 0; i < dr->num_children; i++)
1858  if (GNUNET_NO == write_download_request(wh, dr->children[i]))
1859  return GNUNET_NO;
1860  return GNUNET_YES;
1861 }
1862 
1863 
1870 static struct DownloadRequest *
1872 {
1873  struct DownloadRequest *dr;
1874  unsigned int i;
1875 
1876  dr = GNUNET_new(struct DownloadRequest);
1877  if ((GNUNET_OK != GNUNET_BIO_read_int32(rh, &dr->state)) ||
1878  (GNUNET_OK != GNUNET_BIO_read_int64(rh, &dr->offset)) ||
1879  (GNUNET_OK != GNUNET_BIO_read_int32(rh, &dr->num_children)) ||
1880  (dr->num_children > CHK_PER_INODE) ||
1881  (GNUNET_OK != GNUNET_BIO_read_int32(rh, &dr->depth)) ||
1882  ((0 == dr->depth) && (dr->num_children > 0)) ||
1883  ((dr->depth > 0) && (0 == dr->num_children)))
1884  {
1885  GNUNET_break(0);
1886  dr->num_children = 0;
1887  goto cleanup;
1888  }
1889  if (dr->num_children > 0)
1890  dr->children =
1891  GNUNET_malloc(dr->num_children * sizeof(struct DownloadRequest *));
1892  switch (dr->state)
1893  {
1894  case BRS_INIT:
1895  case BRS_RECONSTRUCT_DOWN:
1897  case BRS_RECONSTRUCT_UP:
1898  break;
1899 
1900  case BRS_CHK_SET:
1901  if (GNUNET_OK !=
1902  GNUNET_BIO_read(rh, "chk", &dr->chk, sizeof(struct ContentHashKey)))
1903  goto cleanup;
1904  break;
1905 
1906  case BRS_DOWNLOAD_DOWN:
1907  case BRS_DOWNLOAD_UP:
1908  case BRS_ERROR:
1909  break;
1910 
1911  default:
1912  GNUNET_break(0);
1913  goto cleanup;
1914  }
1915  for (i = 0; i < dr->num_children; i++)
1916  {
1917  if (NULL == (dr->children[i] = read_download_request(rh)))
1918  goto cleanup;
1919  dr->children[i]->parent = dr;
1920  }
1921  return dr;
1922 cleanup:
1924  return NULL;
1925 }
1926 
1927 
1937 static char *
1939  const char *uni,
1940  const char *ext)
1941 {
1942  char *par;
1943  char *epar;
1944 
1945  if (dc->parent == NULL)
1946  return get_serialization_file_name(dc->h,
1947  (dc->search != NULL)
1950  uni);
1951  if (NULL == dc->parent->serialization)
1952  return NULL;
1954  if (NULL == par)
1955  return NULL;
1956  GNUNET_asprintf(&epar, "%s.dir%s%s%s", par, DIR_SEPARATOR_STR, uni, ext);
1957  GNUNET_free(par);
1958  return epar;
1959 }
1960 
1961 
1970 void
1972 {
1973  struct GNUNET_BIO_WriteHandle *wh;
1974  char *uris;
1975  char *fn;
1976  char *dir;
1977 
1978  if (0 != (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE))
1979  return; /* we don't sync probes */
1980  if (NULL == dc->serialization)
1981  {
1982  dir = get_download_sync_filename(dc, "", "");
1983  if (NULL == dir)
1984  return;
1986  {
1987  GNUNET_free(dir);
1988  return;
1989  }
1990  fn = GNUNET_DISK_mktemp(dir);
1991  GNUNET_free(dir);
1992  if (NULL == fn)
1993  return;
1995  }
1996  else
1997  {
1998  fn = get_download_sync_filename(dc, dc->serialization, "");
1999  if (NULL == fn)
2000  {
2002  dc->serialization = NULL;
2003  GNUNET_free(fn);
2004  return;
2005  }
2006  }
2007  wh = GNUNET_BIO_write_open(fn);
2008  if (NULL == wh)
2009  {
2011  dc->serialization = NULL;
2012  GNUNET_free(fn);
2013  return;
2014  }
2017  uris = GNUNET_FS_uri_to_string(dc->uri);
2018  if ((GNUNET_OK != GNUNET_BIO_write_string(wh, uris)) ||
2019  (GNUNET_OK != GNUNET_BIO_write_meta_data(wh, dc->meta)) ||
2020  (GNUNET_OK != GNUNET_BIO_write_string(wh, dc->emsg)) ||
2021  (GNUNET_OK != GNUNET_BIO_write_string(wh, dc->filename)) ||
2024  (GNUNET_OK != GNUNET_BIO_write_int64(wh, dc->offset)) ||
2025  (GNUNET_OK != GNUNET_BIO_write_int64(wh, dc->length)) ||
2026  (GNUNET_OK != GNUNET_BIO_write_int64(wh, dc->completed)) ||
2027  (GNUNET_OK != write_start_time(wh, dc->start_time)) ||
2028  (GNUNET_OK != GNUNET_BIO_write_int32(wh, dc->anonymity)) ||
2029  (GNUNET_OK != GNUNET_BIO_write_int32(wh, (uint32_t)dc->options)) ||
2030  (GNUNET_OK != GNUNET_BIO_write_int32(wh, (uint32_t)dc->has_finished)))
2031  {
2032  GNUNET_break(0);
2033  goto cleanup;
2034  }
2035  if (NULL == dc->emsg)
2036  {
2037  GNUNET_assert(dc->top_request != NULL);
2039  {
2040  GNUNET_break(0);
2041  goto cleanup;
2042  }
2043  }
2044  GNUNET_free_non_null(uris);
2045  uris = NULL;
2046  if (GNUNET_OK != GNUNET_BIO_write_close(wh))
2047  {
2048  wh = NULL;
2049  GNUNET_break(0);
2050  goto cleanup;
2051  }
2052  GNUNET_free(fn);
2053  return;
2054 cleanup:
2055  if (NULL != wh)
2056  (void)GNUNET_BIO_write_close(wh);
2057  GNUNET_free_non_null(uris);
2058  if (0 != unlink(fn))
2060  GNUNET_free(fn);
2062  dc->serialization = NULL;
2063 }
2064 
2065 
2074 void
2076 {
2077  struct GNUNET_BIO_WriteHandle *wh;
2078  char *uris;
2079 
2080  if (NULL == sr->sc)
2081  return;
2082  uris = NULL;
2083  if (NULL == sr->serialization)
2084  sr->serialization =
2086  (sr->sc->psearch_result == NULL)
2089  sr->sc->serialization);
2090  if (NULL == sr->serialization)
2091  return;
2092  wh = get_write_handle_in_dir(sr->h,
2093  (sr->sc->psearch_result == NULL)
2095  : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2096  sr->sc->serialization,
2097  sr->serialization);
2098  if (NULL == wh)
2099  {
2100  GNUNET_break(0);
2101  goto cleanup;
2102  }
2103  uris = GNUNET_FS_uri_to_string(sr->uri);
2104  if ((GNUNET_OK != GNUNET_BIO_write_string(wh, uris)) ||
2106  sr->download != NULL
2107  ? sr->download->serialization
2108  : NULL)) ||
2109  (GNUNET_OK !=
2111  sr->update_search != NULL
2113  : NULL)) ||
2114  (GNUNET_OK != GNUNET_BIO_write_meta_data(wh, sr->meta)) ||
2115  (GNUNET_OK !=
2116  GNUNET_BIO_write(wh, &sr->key, sizeof(struct GNUNET_HashCode))) ||
2121  {
2122  GNUNET_break(0);
2123  goto cleanup;
2124  }
2125  if ((NULL != sr->uri) && (GNUNET_FS_URI_KSK == sr->sc->uri->type) &&
2126  (GNUNET_OK !=
2127  GNUNET_BIO_write(wh,
2128  sr->keyword_bitmap,
2129  (sr->sc->uri->data.ksk.keywordCount + 7) / 8)))
2130  {
2131  GNUNET_break(0);
2132  goto cleanup;
2133  }
2134  if (GNUNET_OK != GNUNET_BIO_write_close(wh))
2135  {
2136  wh = NULL;
2137  GNUNET_break(0);
2138  goto cleanup;
2139  }
2140  GNUNET_free_non_null(uris);
2141  return;
2142 cleanup:
2143  GNUNET_free_non_null(uris);
2144  if (NULL != wh)
2145  (void)GNUNET_BIO_write_close(wh);
2147  (NULL == sr->sc->psearch_result)
2149  : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2150  sr->sc->serialization,
2151  sr->serialization);
2153  sr->serialization = NULL;
2154 }
2155 
2156 
2165 void
2167 {
2168  struct GNUNET_BIO_WriteHandle *wh;
2169  char *uris;
2170  char in_pause;
2171  const char *category;
2172 
2173  category = (NULL == sc->psearch_result) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
2175  if (NULL == sc->serialization)
2176  sc->serialization = make_serialization_file_name(sc->h, category);
2177  if (NULL == sc->serialization)
2178  return;
2179  uris = NULL;
2180  wh = get_write_handle(sc->h, category, sc->serialization);
2181  if (NULL == wh)
2182  {
2183  GNUNET_break(0);
2184  goto cleanup;
2185  }
2188  uris = GNUNET_FS_uri_to_string(sc->uri);
2189  in_pause = (sc->task != NULL) ? 'r' : '\0';
2190  if ((GNUNET_OK != GNUNET_BIO_write_string(wh, uris)) ||
2191  (GNUNET_OK != write_start_time(wh, sc->start_time)) ||
2192  (GNUNET_OK != GNUNET_BIO_write_string(wh, sc->emsg)) ||
2193  (GNUNET_OK != GNUNET_BIO_write_int32(wh, (uint32_t)sc->options)) ||
2194  (GNUNET_OK != GNUNET_BIO_write(wh, &in_pause, sizeof(in_pause))) ||
2196  {
2197  GNUNET_break(0);
2198  goto cleanup;
2199  }
2200  GNUNET_free(uris);
2201  uris = NULL;
2202  if (GNUNET_OK != GNUNET_BIO_write_close(wh))
2203  {
2204  wh = NULL;
2205  GNUNET_break(0);
2206  goto cleanup;
2207  }
2208  return;
2209 cleanup:
2210  if (NULL != wh)
2211  (void)GNUNET_BIO_write_close(wh);
2212  GNUNET_free_non_null(uris);
2213  GNUNET_FS_remove_sync_file_(sc->h, category, sc->serialization);
2215  sc->serialization = NULL;
2216 }
2217 
2218 
2227 static int
2228 deserialize_unindex_file(void *cls, const char *filename)
2229 {
2230  struct GNUNET_FS_Handle *h = cls;
2231  struct GNUNET_BIO_ReadHandle *rh;
2232  struct GNUNET_FS_UnindexContext *uc;
2233  struct GNUNET_FS_ProgressInfo pi;
2234  char *emsg;
2235  char *uris;
2236  uint32_t state;
2237 
2238  uc = GNUNET_new(struct GNUNET_FS_UnindexContext);
2239  uc->h = h;
2241  rh = GNUNET_BIO_read_open(filename);
2242  if (NULL == rh)
2243  {
2244  GNUNET_break(0);
2245  goto cleanup;
2246  }
2247  uris = NULL;
2248  if ((GNUNET_OK !=
2249  GNUNET_BIO_read_string(rh, "unindex-fn", &uc->filename, 10 * 1024)) ||
2250  (GNUNET_OK != GNUNET_BIO_read_int64(rh, &uc->file_size)) ||
2251  (GNUNET_OK != read_start_time(rh, &uc->start_time)) ||
2252  (GNUNET_OK != GNUNET_BIO_read_int32(rh, &state)) ||
2253  (GNUNET_OK !=
2254  GNUNET_BIO_read(rh, "uri", &uc->chk, sizeof(struct ContentHashKey))) ||
2255  (GNUNET_OK !=
2256  GNUNET_BIO_read_string(rh, "unindex-kskuri", &uris, 10 * 1024)) ||
2258  {
2259  GNUNET_free_non_null(uris);
2260  GNUNET_break(0);
2261  goto cleanup;
2262  }
2263  if (NULL != uris)
2264  {
2265  uc->ksk_uri = GNUNET_FS_uri_parse(uris, &emsg);
2266  GNUNET_free(uris);
2267  if (NULL == uc->ksk_uri)
2268  {
2269  GNUNET_break(0);
2270  GNUNET_free_non_null(emsg);
2271  goto cleanup;
2272  }
2273  }
2274  if ((uc->ksk_offset > 0) &&
2275  ((NULL == uc->ksk_uri) ||
2276  (uc->ksk_offset > uc->ksk_uri->data.ksk.keywordCount)))
2277  {
2278  GNUNET_break(0);
2279  goto cleanup;
2280  }
2281  uc->state = (enum UnindexState)state;
2282  switch (state)
2283  {
2284  case UNINDEX_STATE_HASHING:
2285  break;
2286 
2288  if (GNUNET_OK != GNUNET_BIO_read(rh,
2289  "unindex-hash",
2290  &uc->file_id,
2291  sizeof(struct GNUNET_HashCode)))
2292  {
2293  GNUNET_break(0);
2294  goto cleanup;
2295  }
2296  break;
2297 
2301  break;
2302 
2304  break;
2305 
2306  case UNINDEX_STATE_ERROR:
2307  if (GNUNET_OK !=
2308  GNUNET_BIO_read_string(rh, "unindex-emsg", &uc->emsg, 10 * 1024))
2309  {
2310  GNUNET_break(0);
2311  goto cleanup;
2312  }
2313  break;
2314 
2315  default:
2316  GNUNET_break(0);
2317  goto cleanup;
2318  }
2321  pi.value.unindex.specifics.resume.message = uc->emsg;
2323  uc,
2324  (uc->state == UNINDEX_STATE_COMPLETE)
2325  ? uc->file_size
2326  : 0);
2327  switch (uc->state)
2328  {
2329  case UNINDEX_STATE_HASHING:
2331  uc->filename,
2334  uc);
2335  break;
2336 
2340  break;
2341 
2344  break;
2345 
2348  break;
2349 
2352  break;
2353 
2355  case UNINDEX_STATE_ERROR:
2356  /* no need to resume any operation, we were done */
2357  break;
2358 
2359  default:
2360  break;
2361  }
2362  if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg))
2363  {
2365  _("Failure while resuming unindexing operation `%s': %s\n"),
2366  filename,
2367  emsg);
2368  GNUNET_free(emsg);
2369  }
2370  return GNUNET_OK;
2371 cleanup:
2373  if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg)))
2374  {
2376  _("Failed to resume unindexing operation `%s': %s\n"),
2377  filename,
2378  emsg);
2379  GNUNET_free(emsg);
2380  }
2381  if (NULL != uc->serialization)
2384  uc->serialization);
2386  GNUNET_free(uc);
2387  return GNUNET_OK;
2388 }
2389 
2390 
2400 static void
2402  struct GNUNET_BIO_ReadHandle *rh,
2403  struct GNUNET_FS_DownloadContext *parent,
2405  const char *serialization);
2406 
2407 
2416 static struct GNUNET_FS_SearchContext *
2418  struct GNUNET_BIO_ReadHandle *rh,
2420  const char *serialization);
2421 
2422 
2431 static int
2432 deserialize_search_result(void *cls, const char *filename)
2433 {
2434  struct GNUNET_FS_SearchContext *sc = cls;
2435  char *ser;
2436  char *uris;
2437  char *emsg;
2438  char *download;
2439  char *update_srch;
2440  struct GNUNET_BIO_ReadHandle *rh;
2441  struct GNUNET_BIO_ReadHandle *drh;
2442  struct GNUNET_FS_SearchResult *sr;
2443 
2444  ser = get_serialization_short_name(filename);
2445  rh = GNUNET_BIO_read_open(filename);
2446  if (NULL == rh)
2447  {
2448  if (NULL != ser)
2449  {
2451  (NULL == sc->psearch_result)
2454  sc->serialization,
2455  ser);
2456  GNUNET_free(ser);
2457  }
2458  return GNUNET_OK;
2459  }
2460  emsg = NULL;
2461  uris = NULL;
2462  download = NULL;
2463  update_srch = NULL;
2464  sr = GNUNET_new(struct GNUNET_FS_SearchResult);
2465  sr->h = sc->h;
2466  sr->sc = sc;
2467  sr->serialization = ser;
2468  if ((GNUNET_OK !=
2469  GNUNET_BIO_read_string(rh, "result-uri", &uris, 10 * 1024)) ||
2470  (NULL == (sr->uri = GNUNET_FS_uri_parse(uris, &emsg))) ||
2471  (GNUNET_OK !=
2472  GNUNET_BIO_read_string(rh, "download-lnk", &download, 16)) ||
2473  (GNUNET_OK !=
2474  GNUNET_BIO_read_string(rh, "search-lnk", &update_srch, 16)) ||
2475  (GNUNET_OK != GNUNET_BIO_read_meta_data(rh, "result-meta", &sr->meta)) ||
2476  (GNUNET_OK != GNUNET_BIO_read(rh,
2477  "result-key",
2478  &sr->key,
2479  sizeof(struct GNUNET_HashCode))) ||
2484  {
2485  GNUNET_break(0);
2486  goto cleanup;
2487  }
2488  if (GNUNET_FS_URI_KSK == sr->sc->uri->type)
2489  {
2491  (sr->sc->uri->data.ksk.keywordCount + 7) / 8); /* round up, count bits */
2492  if (GNUNET_OK !=
2493  GNUNET_BIO_read(rh,
2494  "keyword-bitmap",
2495  sr->keyword_bitmap,
2496  (sr->sc->uri->data.ksk.keywordCount + 7) / 8))
2497  {
2498  GNUNET_break(0);
2499  goto cleanup;
2500  }
2501  }
2502  GNUNET_free(uris);
2503  if (NULL != download)
2504  {
2506  if (NULL != drh)
2507  {
2508  deserialize_download(sc->h, drh, NULL, sr, download);
2509  if (GNUNET_OK != GNUNET_BIO_read_close(drh, &emsg))
2510  {
2512  _("Failed to resume sub-download `%s': %s\n"),
2513  download,
2514  emsg);
2515  GNUNET_free(emsg);
2516  }
2517  }
2518  GNUNET_free(download);
2519  }
2520  if (NULL != update_srch)
2521  {
2522  drh =
2524  if (NULL != drh)
2525  {
2526  deserialize_search(sc->h, drh, sr, update_srch);
2527  if (GNUNET_OK != GNUNET_BIO_read_close(drh, &emsg))
2528  {
2530  _("Failed to resume sub-search `%s': %s\n"),
2531  update_srch,
2532  emsg);
2533  GNUNET_free(emsg);
2534  }
2535  }
2536  GNUNET_free(update_srch);
2537  }
2539  sc->master_result_map,
2540  &sr->key,
2541  sr,
2543  if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg))
2544  {
2546  _("Failure while resuming search operation `%s': %s\n"),
2547  filename,
2548  emsg);
2549  GNUNET_free(emsg);
2550  }
2551  return GNUNET_OK;
2552 cleanup:
2553  GNUNET_free_non_null(download);
2554  GNUNET_free_non_null(emsg);
2555  GNUNET_free_non_null(uris);
2556  GNUNET_free_non_null(update_srch);
2557  if (NULL != sr->uri)
2559  if (NULL != sr->meta)
2562  GNUNET_free(sr);
2563  if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg))
2564  {
2566  _("Failure while resuming search operation `%s': %s\n"),
2567  filename,
2568  emsg);
2569  GNUNET_free(emsg);
2570  }
2571  return GNUNET_OK;
2572 }
2573 
2574 
2583 static void
2585 {
2586  struct GNUNET_FS_DownloadContext *dcc;
2587  struct GNUNET_FS_ProgressInfo pi;
2588 
2590  pi.value.download.specifics.resume.meta = dc->meta;
2591  pi.value.download.specifics.resume.message = dc->emsg;
2593  dcc = dc->child_head;
2594  while (NULL != dcc)
2595  {
2597  dcc = dcc->next;
2598  }
2599 }
2600 
2601 
2608 static void
2610 
2611 
2621 static int
2622 signal_result_resume(void *cls, const struct GNUNET_HashCode *key, void *value)
2623 {
2624  struct GNUNET_FS_SearchContext *sc = cls;
2625  struct GNUNET_FS_ProgressInfo pi;
2626  struct GNUNET_FS_SearchResult *sr = value;
2627 
2628  if (0 == sr->mandatory_missing)
2629  {
2631  pi.value.search.specifics.resume_result.meta = sr->meta;
2632  pi.value.search.specifics.resume_result.uri = sr->uri;
2633  pi.value.search.specifics.resume_result.result = sr;
2634  pi.value.search.specifics.resume_result.availability_rank =
2636  pi.value.search.specifics.resume_result.availability_certainty =
2637  sr->availability_trials;
2638  pi.value.search.specifics.resume_result.applicability_rank =
2639  sr->optional_support;
2640  sr->client_info = GNUNET_FS_search_make_status_(&pi, sc->h, sc);
2641  }
2642  if (NULL != sr->download)
2643  {
2645  }
2646  else
2647  {
2649  }
2650  if (NULL != sr->update_search)
2652  return GNUNET_YES;
2653 }
2654 
2655 
2661 static void
2663 
2664 
2673 static int
2674 free_result(void *cls, const struct GNUNET_HashCode *key, void *value)
2675 {
2676  struct GNUNET_FS_SearchResult *sr = value;
2677 
2678  if (NULL != sr->update_search)
2679  {
2681  GNUNET_assert(NULL == sr->update_search);
2682  }
2685  GNUNET_free(sr);
2686  return GNUNET_YES;
2687 }
2688 
2689 
2695 static void
2697 {
2698  if (NULL != sc->serialization)
2699  {
2701  (sc->psearch_result == NULL)
2704  sc->serialization);
2706  (sc->psearch_result == NULL)
2708  : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2709  sc->serialization);
2710  }
2713  if (NULL != sc->uri)
2715  if (NULL != sc->master_result_map)
2716  {
2718  &free_result,
2719  sc);
2721  }
2722  GNUNET_free(sc);
2723 }
2724 
2725 
2734 static int
2735 deserialize_subdownload(void *cls, const char *filename)
2736 {
2737  struct GNUNET_FS_DownloadContext *parent = cls;
2738  char *ser;
2739  char *emsg;
2740  struct GNUNET_BIO_ReadHandle *rh;
2741 
2742  ser = get_serialization_short_name(filename);
2743  rh = GNUNET_BIO_read_open(filename);
2744  if (NULL == rh)
2745  {
2747  _(
2748  "Failed to resume sub-download `%s': could not open file `%s'\n"),
2749  ser,
2750  filename);
2751  GNUNET_free(ser);
2752  return GNUNET_OK;
2753  }
2754  deserialize_download(parent->h, rh, parent, NULL, ser);
2755  if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg))
2756  {
2758  _("Failed to resume sub-download `%s': %s\n"),
2759  ser,
2760  emsg);
2761  GNUNET_free(emsg);
2762  }
2763  GNUNET_free(ser);
2764  return GNUNET_OK;
2765 }
2766 
2767 
2775 static void
2777 {
2778  struct GNUNET_FS_DownloadContext *dcc;
2779 
2780  if (NULL != dc->meta)
2782  if (NULL != dc->uri)
2788  while (NULL != (dcc = dc->child_head))
2789  {
2791  free_download_context(dcc);
2792  }
2794  if (NULL != dc->active)
2796  GNUNET_free(dc);
2797 }
2798 
2799 
2809 static void
2811  struct GNUNET_BIO_ReadHandle *rh,
2812  struct GNUNET_FS_DownloadContext *parent,
2813  struct GNUNET_FS_SearchResult *search,
2814  const char *serialization)
2815 {
2816  struct GNUNET_FS_DownloadContext *dc;
2817  char *emsg;
2818  char *uris;
2819  char *dn;
2820  uint32_t options;
2821  uint32_t status;
2822 
2823  uris = NULL;
2824  emsg = NULL;
2826  dc->parent = parent;
2827  dc->h = h;
2828  dc->serialization = GNUNET_strdup(serialization);
2829  if ((GNUNET_OK !=
2830  GNUNET_BIO_read_string(rh, "download-uri", &uris, 10 * 1024)) ||
2831  (NULL == (dc->uri = GNUNET_FS_uri_parse(uris, &emsg))) ||
2832  ((GNUNET_YES != GNUNET_FS_uri_test_chk(dc->uri)) &&
2833  (GNUNET_YES != GNUNET_FS_uri_test_loc(dc->uri))) ||
2834  (GNUNET_OK !=
2835  GNUNET_BIO_read_meta_data(rh, "download-meta", &dc->meta)) ||
2836  (GNUNET_OK !=
2837  GNUNET_BIO_read_string(rh, "download-emsg", &dc->emsg, 10 * 1024)) ||
2838  (GNUNET_OK !=
2839  GNUNET_BIO_read_string(rh, "download-fn", &dc->filename, 10 * 1024)) ||
2841  "download-tfn",
2842  &dc->temp_filename,
2843  10 * 1024)) ||
2845  (GNUNET_OK != GNUNET_BIO_read_int64(rh, &dc->offset)) ||
2846  (GNUNET_OK != GNUNET_BIO_read_int64(rh, &dc->length)) ||
2847  (GNUNET_OK != GNUNET_BIO_read_int64(rh, &dc->completed)) ||
2848  (GNUNET_OK != read_start_time(rh, &dc->start_time)) ||
2849  (GNUNET_OK != GNUNET_BIO_read_int32(rh, &dc->anonymity)) ||
2850  (GNUNET_OK != GNUNET_BIO_read_int32(rh, &options)) ||
2851  (GNUNET_OK != GNUNET_BIO_read_int32(rh, &status)))
2852  {
2853  GNUNET_break(0);
2854  goto cleanup;
2855  }
2856  dc->options = (enum GNUNET_FS_DownloadOptions)options;
2857  dc->active =
2859  GNUNET_NO);
2860  dc->has_finished = (int)status;
2861  dc->treedepth =
2863  if (GNUNET_FS_uri_test_loc(dc->uri))
2866  if (NULL == dc->emsg)
2867  {
2869  if (NULL == dc->top_request)
2870  {
2871  GNUNET_break(0);
2872  goto cleanup;
2873  }
2874  }
2875  dn = get_download_sync_filename(dc, dc->serialization, ".dir");
2876  if (NULL != dn)
2877  {
2880  GNUNET_free(dn);
2881  }
2882  if (NULL != parent)
2883  {
2884  GNUNET_CONTAINER_DLL_insert(parent->child_head, parent->child_tail, dc);
2885  }
2886  if (NULL != search)
2887  {
2888  dc->search = search;
2889  search->download = dc;
2890  }
2891  if ((NULL == parent) && (NULL == search))
2892  {
2893  dc->top =
2896  }
2897  GNUNET_free(uris);
2898  GNUNET_assert(NULL == dc->job_queue);
2900  return;
2901 cleanup:
2902  GNUNET_free_non_null(uris);
2903  GNUNET_free_non_null(emsg);
2905 }
2906 
2907 
2914 static void
2916 {
2917  struct GNUNET_FS_ProgressInfo pi;
2918 
2920  pi.value.search.specifics.resume.message = sc->emsg;
2921  pi.value.search.specifics.resume.is_paused =
2922  (NULL == sc->mq) ? GNUNET_YES : GNUNET_NO;
2923  sc->client_info = GNUNET_FS_search_make_status_(&pi, sc->h, sc);
2926  sc);
2927 }
2928 
2929 
2938 static struct GNUNET_FS_SearchContext *
2940  struct GNUNET_BIO_ReadHandle *rh,
2941  struct GNUNET_FS_SearchResult *psearch_result,
2942  const char *serialization)
2943 {
2944  struct GNUNET_FS_SearchContext *sc;
2945  char *emsg;
2946  char *uris;
2947  char *dn;
2948  uint32_t options;
2949  char in_pause;
2950 
2951  if ((NULL != psearch_result) && (NULL != psearch_result->update_search))
2952  {
2953  GNUNET_break(0);
2954  return NULL;
2955  }
2956  uris = NULL;
2957  emsg = NULL;
2958  sc = GNUNET_new(struct GNUNET_FS_SearchContext);
2959  if (NULL != psearch_result)
2960  {
2962  psearch_result->update_search = sc;
2963  }
2964  sc->h = h;
2965  sc->serialization = GNUNET_strdup(serialization);
2966  if ((GNUNET_OK !=
2967  GNUNET_BIO_read_string(rh, "search-uri", &uris, 10 * 1024)) ||
2968  (NULL == (sc->uri = GNUNET_FS_uri_parse(uris, &emsg))) ||
2969  ((GNUNET_YES != GNUNET_FS_uri_test_ksk(sc->uri)) &&
2970  (GNUNET_YES != GNUNET_FS_uri_test_sks(sc->uri))) ||
2971  (GNUNET_OK != read_start_time(rh, &sc->start_time)) ||
2972  (GNUNET_OK !=
2973  GNUNET_BIO_read_string(rh, "search-emsg", &sc->emsg, 10 * 1024)) ||
2974  (GNUNET_OK != GNUNET_BIO_read_int32(rh, &options)) ||
2975  (GNUNET_OK !=
2976  GNUNET_BIO_read(rh, "search-pause", &in_pause, sizeof(in_pause))) ||
2977  (GNUNET_OK != GNUNET_BIO_read_int32(rh, &sc->anonymity)))
2978  {
2979  GNUNET_break(0);
2980  goto cleanup;
2981  }
2982  sc->options = (enum GNUNET_FS_SearchOptions)options;
2985  (NULL == sc->psearch_result)
2988  sc->serialization,
2989  "");
2990  if (NULL != dn)
2991  {
2994  GNUNET_free(dn);
2995  }
2996  if (('\0' == in_pause) &&
2998  {
2999  GNUNET_log(
3001  _("Could not resume running search, will resume as paused search\n"));
3002  }
3004  GNUNET_free(uris);
3005  return sc;
3006 cleanup:
3007  GNUNET_free_non_null(emsg);
3008  free_search_context(sc);
3009  GNUNET_free_non_null(uris);
3010  return NULL;
3011 }
3012 
3013 
3022 static int
3023 deserialize_search_file(void *cls, const char *filename)
3024 {
3025  struct GNUNET_FS_Handle *h = cls;
3026  char *ser;
3027  char *emsg;
3028  struct GNUNET_BIO_ReadHandle *rh;
3029  struct GNUNET_FS_SearchContext *sc;
3030  struct stat buf;
3031 
3032  if (0 != stat(filename, &buf))
3033  {
3035  return GNUNET_OK;
3036  }
3037  if (S_ISDIR(buf.st_mode))
3038  return GNUNET_OK; /* skip directories */
3039  ser = get_serialization_short_name(filename);
3040  rh = GNUNET_BIO_read_open(filename);
3041  if (NULL == rh)
3042  {
3043  if (NULL != ser)
3044  {
3046  GNUNET_free(ser);
3047  }
3048  return GNUNET_OK;
3049  }
3050  sc = deserialize_search(h, rh, NULL, ser);
3051  if (NULL != sc)
3053  GNUNET_free(ser);
3054  if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg))
3055  {
3057  _("Failure while resuming search operation `%s': %s\n"),
3058  filename,
3059  emsg);
3060  GNUNET_free(emsg);
3061  }
3062  return GNUNET_OK;
3063 }
3064 
3065 
3074 static int
3075 deserialize_download_file(void *cls, const char *filename)
3076 {
3077  struct GNUNET_FS_Handle *h = cls;
3078  char *ser;
3079  char *emsg;
3080  struct GNUNET_BIO_ReadHandle *rh;
3081 
3082  ser = get_serialization_short_name(filename);
3083  rh = GNUNET_BIO_read_open(filename);
3084  if (NULL == rh)
3085  {
3086  if (0 != unlink(filename))
3088  GNUNET_free(ser);
3089  return GNUNET_OK;
3090  }
3091  deserialize_download(h, rh, NULL, NULL, ser);
3092  GNUNET_free(ser);
3093  if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg))
3094  {
3096  _("Failure while resuming download operation `%s': %s\n"),
3097  filename,
3098  emsg);
3099  GNUNET_free(emsg);
3100  }
3101  return GNUNET_OK;
3102 }
3103 
3104 
3112 static void
3113 deserialization_master(const char *master_path,
3115  struct GNUNET_FS_Handle *h)
3116 {
3117  char *dn;
3118 
3119  dn = get_serialization_file_name(h, master_path, "");
3120  if (NULL == dn)
3121  return;
3123  GNUNET_DISK_directory_scan(dn, proc, h);
3124  GNUNET_free(dn);
3125 }
3126 
3127 
3139 struct GNUNET_FS_Handle *
3141  const char *client_name,
3143  void *upcb_cls,
3144  enum GNUNET_FS_Flags flags,
3145  ...)
3146 {
3147  struct GNUNET_FS_Handle *ret;
3148  enum GNUNET_FS_OPTIONS opt;
3149  va_list ap;
3150 
3151  ret = GNUNET_new(struct GNUNET_FS_Handle);
3152  ret->cfg = cfg;
3153  ret->client_name = GNUNET_strdup(client_name);
3154  ret->upcb = upcb;
3155  ret->upcb_cls = upcb_cls;
3156  ret->flags = flags;
3159  ret->avg_block_latency =
3160  GNUNET_TIME_UNIT_MINUTES; /* conservative starting point */
3161  va_start(ap, flags);
3162  while (GNUNET_FS_OPTIONS_END !=
3164  {
3165  switch (opt)
3166  {
3168  ret->max_parallel_downloads = va_arg(ap, unsigned int);
3169 
3170  break;
3171 
3173  ret->max_parallel_requests = va_arg(ap, unsigned int);
3174 
3175  break;
3176 
3177  default:
3178  GNUNET_break(0);
3179  GNUNET_free(ret->client_name);
3180  GNUNET_free(ret);
3181  va_end(ap);
3182  return NULL;
3183  }
3184  }
3185  va_end(ap);
3186  if (0 != (GNUNET_FS_FLAGS_PERSISTENCE & flags))
3187  {
3190  ret);
3193  ret);
3196  ret);
3199  ret);
3200  }
3201  return ret;
3202 }
3203 
3204 
3214 void
3216 {
3217  while (NULL != h->top_head)
3218  h->top_head->ssf(h->top_head->ssf_cls);
3219  if (NULL != h->queue_job)
3222  GNUNET_free(h);
3223 }
3224 
3225 
3226 /* 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:819
#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:519
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:587
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:3075
struct GNUNET_FS_FileInformation * entries
Linked list of entries in the directory.
Definition: fs_api.h:350
This is a probe (low priority).
Definition: fs_api.h:395
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:542
char * nid
ID of the content in the namespace, NULL if we have no namespace.
Definition: fs_api.h:1189
int GNUNET_FS_uri_test_ksk(const struct GNUNET_FS_Uri *uri)
Is this a keyword URI?
Definition: fs_uri.c:1332
Open the file for reading.
char * serialization
Short name under which we are serializing the state of this operation.
Definition: fs_api.h:1374
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:3113
static char * dir
Set to the directory where runtime files are stored.
Definition: gnunet-arm.c:84
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:1244
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:1564
struct GNUNET_FS_FileInformation * dir
If this is a file in a directory, "dir" refers to the directory; otherwise NULL.
Definition: fs_api.h:229
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:420
struct GNUNET_FS_ProgressInfo::@28::@31 search
Values for all "GNUNET_FS_STATUS_SEARCH_*" events.
Context for controlling a download.
Definition: fs_api.h:1722
struct GNUNET_FS_DownloadContext * download
ID of an associated download based on this search result (or NULL for none).
Definition: fs_api.h:531
int GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1339
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:1311
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:2939
struct GNUNET_TIME_Relative avg_block_latency
Average time we take for a single request to be satisfied.
Definition: fs_api.h:1133
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:244
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:1512
struct GNUNET_FS_FileInformation::@19::@20 file
Data for a file.
enum GNUNET_FS_DownloadOptions options
Options for the download.
Definition: fs_api.h:1901
struct GNUNET_FS_Handle * h
Global FS context.
Definition: fs_api.h:1726
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:239
#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:1530
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:1239
struct DownloadRequest ** children
Array (!) of child-requests, or NULL for the bottom of the tree.
Definition: fs_api.h:1664
uint32_t ksk_offset
Current offset in KSK removal.
Definition: fs_api.h:1364
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:729
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:641
char * emsg
Error message (non-NULL if this operation failed).
Definition: fs_api.h:288
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:1121
char * serialization
Under what filename is this struct serialized (for operational persistence).
Definition: fs_api.h:278
struct GNUNET_FS_DownloadContext * child_head
Head of list of child downloads.
Definition: fs_api.h:1753
#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:1971
Master context for most FS operations.
Definition: fs_api.h:1056
We&#39;re done.
Definition: fs_api.h:1322
enum GNUNET_FS_SearchOptions options
Options for the search.
Definition: fs_api.h:1579
#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:2166
int GNUNET_BIO_write_string(struct GNUNET_BIO_WriteHandle *h, const char *s)
Write a string to a file.
Definition: bio.c:521
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:1501
char * emsg
Error message (non-NULL if this operation failed).
Definition: fs_api.h:1532
struct GNUNET_TIME_Absolute start_time
When did we start?
Definition: fs_api.h:1551
#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:647
int GNUNET_BIO_write_int64(struct GNUNET_BIO_WriteHandle *h, int64_t i)
Write an (u)int64_t.
Definition: bio.c:597
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:504
uint8_t * keyword_bitmap
Bitmap that specifies precisely which keywords have been matched already.
Definition: fs_api.h:547
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:560
struct GNUNET_FS_QueueEntry * pending_head
Head of DLL of pending jobs.
Definition: fs_api.h:1100
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 GNUNET_FS_ProgressInfo::@28::@30 download
Values for all "GNUNET_FS_STATUS_DOWNLOAD_*" events.
struct DownloadRequest * top_request
Top-level download request.
Definition: fs_api.h:1834
struct GNUNET_FS_DownloadContext * parent
Parent download (used when downloading files in directories).
Definition: fs_api.h:1742
GNUNET_FS_SearchOptions
Options for searching.
struct GNUNET_ATS_TEST_Topology * top
Definition: ats-testing.c:52
struct GNUNET_TIME_Absolute start_time
At what time did we start this upload?
Definition: fs_api.h:271
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:773
uint64_t offset
Offset of the corresponding block.
Definition: fs_api.h:1677
Last option in the VARARG list.
Keyword search key (query with keywords).
Definition: fs_api.h:150
char * filename
Name of the file or directory (must be an absolute path).
Definition: fs_api.h:293
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:500
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:2696
struct GNUNET_FS_Uri * uri
URI to which this search result refers to.
Definition: fs_api.h:509
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:693
int GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:681
enum GNUNET_FS_PublishOptions options
Options for publishing.
Definition: fs_api.h:1260
unsigned int active_blocks
How many blocks do the active downloads have?
Definition: fs_api.h:1143
#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:1800
struct GNUNET_DATASTORE_Handle * dsh
Connection to the datastore service.
Definition: fs_api.h:1221
struct GNUNET_FS_Handle * h
Handle to the global fs context.
Definition: fs_api.h:1169
#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:393
#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:1200
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:431
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:456
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition: disk.c:909
Information for a file or directory that is about to be published.
Definition: fs_api.h:219
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:1670
int GNUNET_FS_uri_test_sks(const struct GNUNET_FS_Uri *uri)
Is this a namespace URI?
Definition: fs_uri.c:1279
struct GNUNET_FS_Handle * h
Handle to the master context.
Definition: fs_api.h:234
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:223
struct GNUNET_HashCode file_id
Hash of the file&#39;s contents (once computed).
Definition: fs_api.h:1442
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:1617
Run as background job (higher than idle, lower than default).
enum UnindexState state
Current operatinonal phase.
Definition: fs_api.h:1447
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:1697
static int ret
Final status code.
Definition: gnunet-arm.c:89
unsigned int num_children
Number of entries in children array.
Definition: fs_api.h:1682
struct GNUNET_FS_QueueEntry * running_head
Head of DLL of running jobs.
Definition: fs_api.h:1090
void GNUNET_FS_stop(struct GNUNET_FS_Handle *h)
Close our connection with the file-sharing service.
Definition: fs_api.c:3215
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:1807
#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:1334
void * dir_data
Pointer to the data for the directory (or NULL if not available).
Definition: fs_api.h:362
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:1498
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:718
uint64_t abs_value_us
The actual value.
unsigned int max_parallel_requests
Maximum number of parallel requests.
Definition: fs_api.h:1158
int GNUNET_BIO_read_close(struct GNUNET_BIO_ReadHandle *h, char **emsg)
Close an open file.
Definition: bio.c:118
#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:1427
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
Find out which keywords apply.
Definition: fs_api.h:1306
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:1506
We&#39;re notifying the FS service about the unindexing.
Definition: fs_api.h:1317
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:3140
Initial state, block has only been allocated (since it is relevant to the overall download request)...
Definition: fs_api.h:1593
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:1876
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:537
#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:1085
int GNUNET_FS_uri_test_loc(const struct GNUNET_FS_Uri *uri)
Is this a location URI?
Definition: fs_uri.c:1392
uint32_t anonymity
Anonymity level for the search.
Definition: fs_api.h:1569
char * GNUNET_FS_uri_to_string(const struct GNUNET_FS_Uri *uri)
Convert a URI to a UTF-8 String.
Definition: fs_uri.c:2024
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:896
struct GNUNET_BIO_ReadHandle * GNUNET_BIO_read_open(const char *fn)
Open a file for reading.
Definition: bio.c:93
uint64_t length
How many bytes starting from offset are desired? This is NOT the overall length of the file! ...
Definition: fs_api.h:1862
#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:2622
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:124
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:143
struct GNUNET_TIME_Absolute queue_time
Time the job was originally queued.
Definition: fs_api.h:446
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:1559
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
Meta data to associate with a file, directory or namespace.
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:1237
union GNUNET_FS_ProgressInfo::@28 value
Values that depend on the event type.
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:2915
void GNUNET_FS_search_start_probe_(struct GNUNET_FS_SearchResult *sr)
Start download probes for the given search result.
Definition: fs_search.c:435
struct TopLevelActivity * top
Our top-level activity entry.
Definition: fs_api.h:1349
char * GNUNET_DISK_mktemp(const char *t)
Create an (empty) temporary file on disk.
Definition: disk.c:465
void GNUNET_FS_publish_sync_(struct GNUNET_FS_PublishContext *pc)
Synchronize this publishing struct with its mirror on disk.
Definition: fs_api.c:1705
struct GNUNET_FS_DownloadContext * next
Next download belonging to the same parent.
Definition: fs_api.h:1768
char * serialization
Name of the file on disk we use for persistence.
Definition: fs_api.h:1527
int active
GNUNET_YES if the job is active now.
Definition: fs_api.h:477
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:1191
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:1794
uint32_t availability_trials
Number of availability trials that we have performed for this search result.
Definition: fs_api.h:598
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
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:1400
enum GNUNET_FS_QueuePriority priority
How important is this download?
Definition: fs_api.h:467
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:578
#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:1540
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:2810
static char * fn
Filename of the unique file.
Information we store for each search result.
Definition: fs_api.h:484
struct GNUNET_FS_Handle * h
File-sharing context this result belongs to.
Definition: fs_api.h:488
struct GNUNET_FS_Uri::@16::@17 ksk
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:630
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:670
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:1264
#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:1026
char * nuid
ID for future updates, NULL if we have no namespace or no updates.
Definition: fs_api.h:1194
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:379
uint32_t availability_success
Number of availability tests that have succeeded for this result.
Definition: fs_api.h:592
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:1311
UnindexState
Phases of unindex processing (state machine).
Definition: fs_api.h:1291
union GNUNET_FS_Uri::@16 data
#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:2776
void GNUNET_FS_search_result_sync_(struct GNUNET_FS_SearchResult *sr)
Synchronize this search result with its mirror on disk.
Definition: fs_api.c:2075
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:686
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:1601
struct GNUNET_TIME_Absolute start_time
When did we start?
Definition: fs_api.h:1437
Last event when a search is being resumed; note that "GNUNET_FS_SEARCH_START" will not be generated i...
struct GNUNET_FS_ProgressInfo::@28::@29 publish
Values for all "GNUNET_FS_STATUS_PUBLISH_*" events.
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:1050
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:1065
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:440
struct TopLevelActivity * top_head
Head of DLL of top-level activities.
Definition: fs_api.h:1080
#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:1211
struct GNUNET_CONTAINER_MultiHashMap * active
Map of active requests (those waiting for a response).
Definition: fs_api.h:1829
#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:378
We&#39;ve encountered a fatal error.
Definition: fs_api.h:1327
struct GNUNET_FS_Uri * chk_uri
CHK for this file or directory.
Definition: fs_api.h:255
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:2584
We&#39;ve calculated the CHK bottom-up based on the meta data.
Definition: fs_api.h:1609
uint64_t offset
What is the first offset that we&#39;re interested in?
Definition: fs_api.h:1856
struct TopLevelActivity * top
Our top-level activity entry (if we are top-level, otherwise NULL).
Definition: fs_api.h:1731
void GNUNET_FS_uri_destroy(struct GNUNET_FS_Uri *uri)
Free URI.
Definition: fs_uri.c:675
Handle for controlling a publication process.
Definition: fs_api.h:1165
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:1871
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:1359
A 512-bit hashcode.
char * filename
Name of the file that we are unindexing.
Definition: fs_api.h:1369
We&#39;ve successfully downloaded this block, but the children still need to be either downloaded or veri...
Definition: fs_api.h:1635
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:232
GNUNET_SCHEDULER_TaskCallback start
Function to call when the job is started.
Definition: fs_api.h:421
#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:1850
int GNUNET_FS_uri_test_chk(const struct GNUNET_FS_Uri *uri)
Is this a file (or directory) URI?
Definition: fs_uri.c:1354
Run when otherwise idle.
This block and all of its children have been downloaded successfully (full completion propagates up)...
Definition: fs_api.h:1641
#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:1095
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:104
uint64_t contents_size
Sum of all of the sizes of all of the files in the directory.
Definition: fs_api.h:372
#define DIR_SEPARATOR
Definition: platform.h:167
void * ssf_cls
Closure for &#39;ssf&#39; (some struct GNUNET_FS_XXXHandle*)
Definition: fs_api.h:1023
struct GNUNET_FS_Handle * h
Handle to FS primary context.
Definition: fs_api.h:436
unsigned int active_downloads
How many actual downloads do we have running right now?
Definition: fs_api.h:1138
#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:1748
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:1126
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:1788
#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:590
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:3023
#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:451
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:524
int has_finished
Flag set upon transitive completion (includes child downloads).
Definition: fs_api.h:1908
int all_done
Set to GNUNET_YES if all processing has completed.
Definition: fs_api.h:1277
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:1938
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:602
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:835
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:1169
struct GNUNET_CONTAINER_MetaData * meta
Metadata for the search result.
Definition: fs_api.h:514
Maximum number of requests that should be pending at a given point in time (invidivual downloads may ...
Notification that this download is being resumed.
static struct GNUNET_NAMESTORE_Handle * ns
Handle to the namestore.
enum GNUNET_FS_UriType type
Type of the URI.
Definition: fs_api.h:166
struct GNUNET_FS_FileInformation * next
Files in a directory are kept as a linked list.
Definition: fs_api.h:223
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:436
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:552
void GNUNET_FS_unindex_sync_(struct GNUNET_FS_UnindexContext *uc)
Synchronize this unindex struct with its mirror on disk.
Definition: fs_api.c:1777
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:725
struct GNUNET_FS_BlockOptions bo
Block options for the file.
Definition: fs_api.h:266
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:1648
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:328
struct TopLevelActivity * top
Our top-level activity entry (if we are top-level, otherwise NULL).
Definition: fs_api.h:1174
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:577
struct GNUNET_TIME_Relative run_time
Total amount of time the job has been running (except for the current run).
Definition: fs_api.h:457
#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:1758
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:581
struct GNUNET_FS_FileInformation * fi
File-structure that is being shared.
Definition: fs_api.h:1179
union GNUNET_FS_FileInformation::@19 data
Data describing either the file or the directory.
GNUNET_FS_ProgressCallback upcb
Function to call with updates on our progress.
Definition: fs_api.h:1070
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:1203
unsigned int blocks
How many blocks do the active downloads have?
Definition: fs_api.h:462
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:998
We&#39;re currently hashing the file.
Definition: fs_api.h:1295
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:1340
#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:1368
struct GNUNET_FS_QueueEntry * next
This is a linked list.
Definition: fs_api.h:411
configuration data
Definition: configuration.c:83
shared definitions for the FS library
We&#39;re telling the datastore to delete the respective DBlocks and IBlocks.
Definition: fs_api.h:1301
struct GNUNET_BIO_WriteHandle * GNUNET_BIO_write_open(const char *fn)
Open a file for writing.
Definition: bio.c:408
struct GNUNET_CRYPTO_EcdsaPrivateKey * ns
Namespace that we are publishing in, NULL if we have no namespace.
Definition: fs_api.h:1184
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:1840
A Universal Resource Identifier (URI), opaque.
Definition: fs_api.h:162
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:373
static int free_result(void *cls, const struct GNUNET_HashCode *key, void *value)
Iterator over search results freeing each.
Definition: fs_api.c:2674
static int read_start_time(struct GNUNET_BIO_ReadHandle *rh, struct GNUNET_TIME_Absolute *timestamp)
Deserialize a start-time.
Definition: fs_api.c:860
Handle for controlling a search.
Definition: fs_api.h:1492
#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:1075
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:1339
struct GNUNET_FS_Uri * keywords
Keywords to use for KBlocks.
Definition: fs_api.h:249
char * filename
Name of the file to read.
Definition: fs_api.c:426
#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:1843
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:1517
uint32_t anonymity
Desired level of anonymity.
Definition: fs_api.h:1891
struct GNUNET_FS_Handle * h
Handle to the global FS context.
Definition: fs_api.h:1496
GNUNET_SCHEDULER_TaskCallback stop
Function to call when the job needs to stop (or is done / dequeued).
Definition: fs_api.h:426
unsigned int treedepth
The depth of the file-tree.
Definition: fs_api.h:1896
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:580
struct GNUNET_CONTAINER_MetaData * meta
Known meta-data for the file (can be NULL).
Definition: fs_api.h:1783
static int deserialize_subdownload(void *cls, const char *filename)
Function called with a filename of serialized sub-download to deserialize.
Definition: fs_api.c:2735
struct GNUNET_FS_QueueEntry * pending_tail
Tail of DLL of pending jobs.
Definition: fs_api.h:1105
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:284
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:2432
uint64_t contents_completed
How much of the directory have we published (relative to contents_size).
Definition: fs_api.h:367
char * emsg
Error message, NULL on success.
Definition: fs_api.h:1422
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:431
struct GNUNET_TIME_Absolute start_time
Time download was started.
Definition: fs_api.h:1881
int GNUNET_BIO_write(struct GNUNET_BIO_WriteHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: bio.c:481
char * serialization
Name under which this search result is stored on disk.
Definition: fs_api.h:542
uint64_t completed
How many bytes have we already received within the specified range (DBlocks only).
Definition: fs_api.h:1868
struct GNUNET_FS_Uri * uri
URI that identifies the file that we are downloading.
Definition: fs_api.h:1778
int is_published
Are we done publishing this file?
Definition: fs_api.h:384
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:2228
We track all of the top-level activities of FS so that we can signal &#39;suspend&#39; on shutdown...
Definition: fs_api.h:1004
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:1344
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:1262
struct GNUNET_FS_ProgressInfo::@28::@32 unindex
Values for all "GNUNET_FS_STATUS_UNINDEX_*" events.
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:1153
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:692
struct DownloadRequest * parent
Parent in the CHK-tree.
Definition: fs_api.h:1659
char * emsg
Error message, NULL if there were no errors.
Definition: bio.c:62
Entry in the job queue.
Definition: fs_api.h:407
void * client_info
Pointer we keep for the client.
Definition: fs_api.h:1522
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:1284
Information about an active download request.
Definition: fs_api.h:1655
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:499
size_t dir_size
Size of the directory itself (in bytes); 0 if the size has not yet been calculated.
Definition: fs_api.h:356
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:1275
struct GNUNET_FS_Uri * sks_uri
SKS URI for this file or directory.
Definition: fs_api.h:261
unsigned int depth
Depth of the corresponding block in the tree.
Definition: fs_api.h:1687
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:1626
#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:743
GNUNET_FS_QueuePriority
Priorities for the queue.
Definition: fs_api.h:391
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:1570
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:1018
Default priority.
Definition: fs_api.h:400
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:472
#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:1148
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:802
struct GNUNET_FS_QueueEntry * job_queue
Our entry in the job queue.
Definition: fs_api.h:1812
Merkle-tree-ish-CHK file encoding for GNUnet.
uint64_t file_size
Overall size of the file.
Definition: fs_api.h:1432
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Definition: fs_api.h:1060