GNUnet  0.20.0
fs_api.c File Reference

main FS functions (master initialization, serialization, deserialization, shared code) More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_fs_service.h"
#include "fs_api.h"
#include "fs_tree.h"
Include dependency graph for fs_api.c:

Go to the source code of this file.

Data Structures

struct  FileInfo
 Closure for GNUNET_FS_data_reader_file_(). More...
 

Macros

#define DEFAULT_MAX_PARALLEL_REQUESTS   (1024 * 10)
 How many block requests can we have outstanding in parallel at a time by default? More...
 
#define DEFAULT_MAX_PARALLEL_DOWNLOADS   16
 How many downloads can we have outstanding in parallel at a time by default? More...
 

Functions

static void start_job (struct GNUNET_FS_QueueEntry *qe)
 Start the given job (send signal, remove from pending queue, update counters and state). More...
 
static void stop_job (struct GNUNET_FS_QueueEntry *qe)
 Stop the given job (send signal, remove from active queue, update counters and state). More...
 
static void process_job_queue (void *cls)
 Process the jobs in the job queue, possibly starting some and stopping others. More...
 
struct GNUNET_FS_QueueEntryGNUNET_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. More...
 
void GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qe)
 Dequeue a job from the queue. More...
 
struct TopLevelActivityGNUNET_FS_make_top (struct GNUNET_FS_Handle *h, SuspendSignalFunction ssf, void *ssf_cls)
 Create a top-level activity entry. More...
 
void GNUNET_FS_end_top (struct GNUNET_FS_Handle *h, struct TopLevelActivity *top)
 Destroy a top-level activity entry. More...
 
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. More...
 
void * GNUNET_FS_make_file_reader_context_ (const char *filename)
 Create the closure for the GNUNET_FS_data_reader_file_() callback. More...
 
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. More...
 
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). More...
 
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) that is associated with a parent operation. More...
 
static struct GNUNET_BIO_ReadHandleget_read_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
 Return a read handle for deserialization. More...
 
static struct GNUNET_BIO_WriteHandleget_write_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
 Return a write handle for serialization. More...
 
static struct GNUNET_BIO_WriteHandleget_write_handle_in_dir (struct GNUNET_FS_Handle *h, const char *ext, const char *uni, const char *ent)
 Return a write handle for serialization. More...
 
void GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
 Remove serialization/deserialization file from disk. More...
 
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. More...
 
void GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h, const char *ext, const char *uni)
 Remove serialization/deserialization directory from disk. More...
 
static int write_start_time (struct GNUNET_BIO_WriteHandle *wh, struct GNUNET_TIME_Absolute timestamp)
 Serialize a start-time. More...
 
static int read_start_time (struct GNUNET_BIO_ReadHandle *rh, struct GNUNET_TIME_Absolute *timestamp)
 Deserialize a start-time. More...
 
static struct GNUNET_FS_FileInformationdeserialize_file_information (struct GNUNET_FS_Handle *h, const char *filename)
 Using the given serialization filename, try to deserialize the file-information tree associated with it. More...
 
static struct GNUNET_FS_FileInformationdeserialize_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 it. More...
 
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), which must only consist of the 6 random characters. More...
 
static char * make_serialization_file_name (struct GNUNET_FS_Handle *h, const char *ext)
 Create a new random name for serialization. More...
 
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. More...
 
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. More...
 
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. More...
 
static struct GNUNET_FS_FileInformationfind_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. More...
 
static int fip_signal_resume (void *cls, struct GNUNET_FS_FileInformation *fi, uint64_t length, struct GNUNET_FS_MetaData *meta, struct GNUNET_FS_Uri **uri, struct GNUNET_FS_BlockOptions *bo, int *do_index, void **client_info)
 Signal the FS's progress function that we are resuming an upload. More...
 
static int deserialize_publish_file (void *cls, const char *filename)
 Function called with a filename of serialized publishing operation to deserialize. More...
 
void GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc)
 Synchronize this publishing struct with its mirror on disk. More...
 
void GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc)
 Synchronize this unindex struct with its mirror on disk. More...
 
static int write_download_request (struct GNUNET_BIO_WriteHandle *wh, struct DownloadRequest *dr)
 Serialize a download request. More...
 
static struct DownloadRequestread_download_request (struct GNUNET_BIO_ReadHandle *rh)
 Read a download request tree. More...
 
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. More...
 
void GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc)
 Synchronize this download struct with its mirror on disk. More...
 
void GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr)
 Synchronize this search result with its mirror on disk. More...
 
void GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc)
 Synchronize this search struct with its mirror on disk. More...
 
static int deserialize_unindex_file (void *cls, const char *filename)
 Function called with a filename of serialized unindexing operation to deserialize. More...
 
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. More...
 
static struct GNUNET_FS_SearchContextdeserialize_search (struct GNUNET_FS_Handle *h, struct GNUNET_BIO_ReadHandle *rh, struct GNUNET_FS_SearchResult *psearch_result, const char *serialization)
 Deserialize a search. More...
 
static int deserialize_search_result (void *cls, const char *filename)
 Function called with a filename of serialized search result to deserialize. More...
 
static void signal_download_resume (struct GNUNET_FS_DownloadContext *dc)
 Send the 'resume' signal to the callback; also actually resume the download (put it in the queue). More...
 
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). More...
 
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. More...
 
static void free_search_context (struct GNUNET_FS_SearchContext *sc)
 Free memory allocated by the search context and its children. More...
 
static int free_result (void *cls, const struct GNUNET_HashCode *key, void *value)
 Iterator over search results freeing each. More...
 
static int deserialize_subdownload (void *cls, const char *filename)
 Function called with a filename of serialized sub-download to deserialize. More...
 
static void free_download_context (struct GNUNET_FS_DownloadContext *dc)
 Free this download context and all of its descendants. More...
 
static int deserialize_search_file (void *cls, const char *filename)
 Function called with a filename of serialized search operation to deserialize. More...
 
static int deserialize_download_file (void *cls, const char *filename)
 Function called with a filename of serialized download operation to deserialize. More...
 
static void deserialization_master (const char *master_path, GNUNET_FileNameCallback proc, struct GNUNET_FS_Handle *h)
 Deserialize information about pending operations. More...
 
struct GNUNET_FS_HandleGNUNET_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. More...
 
void GNUNET_FS_stop (struct GNUNET_FS_Handle *h)
 Close our connection with the file-sharing service. More...
 

Detailed Description

main FS functions (master initialization, serialization, deserialization, shared code)

Author
Christian Grothoff

Definition in file fs_api.c.

Macro Definition Documentation

◆ DEFAULT_MAX_PARALLEL_REQUESTS

#define DEFAULT_MAX_PARALLEL_REQUESTS   (1024 * 10)

How many block requests can we have outstanding in parallel at a time by default?

Definition at line 37 of file fs_api.c.

◆ DEFAULT_MAX_PARALLEL_DOWNLOADS

#define DEFAULT_MAX_PARALLEL_DOWNLOADS   16

How many downloads can we have outstanding in parallel at a time by default?

Definition at line 42 of file fs_api.c.

Function Documentation

◆ start_job()

static void start_job ( struct GNUNET_FS_QueueEntry qe)
static

Start the given job (send signal, remove from pending queue, update counters and state).

Parameters
qejob to start

Definition at line 51 of file fs_api.c.

52 {
53  qe->active = GNUNET_YES;
54  qe->start (qe->cls);
55  qe->start_times++;
56  qe->h->active_blocks += qe->blocks;
57  qe->h->active_downloads++;
58  qe->start_time = GNUNET_TIME_absolute_get ();
60  "Starting job %p (%u active)\n",
61  qe,
62  qe->h->active_downloads);
63  GNUNET_CONTAINER_DLL_remove (qe->h->pending_head, qe->h->pending_tail, qe);
64  GNUNET_CONTAINER_DLL_insert_after (qe->h->running_head,
65  qe->h->running_tail,
66  qe->h->running_tail,
67  qe);
68 }
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert_after(head, tail, other, element)
Insert an element into a DLL after the given other element.
#define GNUNET_log(kind,...)
@ GNUNET_YES
@ GNUNET_ERROR_TYPE_DEBUG
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:111
struct GNUNET_DATASTORE_Handle * h
Handle to the master context.

References GNUNET_CONTAINER_DLL_insert_after, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_TIME_absolute_get(), GNUNET_YES, GNUNET_DATASTORE_QueueEntry::h, and qe.

Referenced by process_job_queue().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stop_job()

static void stop_job ( struct GNUNET_FS_QueueEntry qe)
static

Stop the given job (send signal, remove from active queue, update counters and state).

Parameters
qejob to stop

Definition at line 78 of file fs_api.c.

79 {
80  qe->active = GNUNET_NO;
81  qe->stop (qe->cls);
82  GNUNET_assert (0 < qe->h->active_downloads);
83  qe->h->active_downloads--;
84  qe->h->active_blocks -= qe->blocks;
85  qe->run_time = GNUNET_TIME_relative_add (qe->run_time,
87  qe->start_time));
89  "Stopping job %p (%u active)\n",
90  qe,
91  qe->h->active_downloads);
92  GNUNET_CONTAINER_DLL_remove (qe->h->running_head, qe->h->running_tail, qe);
93  GNUNET_CONTAINER_DLL_insert_after (qe->h->pending_head,
94  qe->h->pending_tail,
95  qe->h->pending_tail,
96  qe);
97 }
@ GNUNET_NO
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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:436
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:585

References GNUNET_assert, GNUNET_CONTAINER_DLL_insert_after, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_NO, GNUNET_TIME_absolute_get_duration(), GNUNET_TIME_relative_add(), GNUNET_DATASTORE_QueueEntry::h, and qe.

Referenced by GNUNET_FS_dequeue_(), and process_job_queue().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_job_queue()

static void process_job_queue ( void *  cls)
static

Process the jobs in the job queue, possibly starting some and stopping others.

Parameters
clsthe struct GNUNET_FS_Handle *

Definition at line 107 of file fs_api.c.

108 {
109  struct GNUNET_FS_Handle *h = cls;
110  struct GNUNET_FS_QueueEntry *qe;
111  struct GNUNET_FS_QueueEntry *next;
112  struct GNUNET_TIME_Relative run_time;
113  struct GNUNET_TIME_Relative restart_at;
114  struct GNUNET_TIME_Relative rst;
116  unsigned int num_downloads_waiting;
117  unsigned int num_downloads_active;
118  unsigned int num_downloads_expired;
119  unsigned int num_probes_active;
120  unsigned int num_probes_waiting;
121  unsigned int num_probes_expired;
122  int num_probes_change;
123  int num_downloads_change;
124  int block_limit_hit;
125 
126  h->queue_job = NULL;
127  /* restart_at will be set to the time when it makes sense to
128  re-evaluate the job queue (unless, of course, jobs complete
129  or are added, then we'll be triggered immediately */
130  restart_at = GNUNET_TIME_UNIT_FOREVER_REL;
131  /* first, calculate some basic statistics on pending jobs */
132  num_probes_waiting = 0;
133  num_downloads_waiting = 0;
134  for (qe = h->pending_head; NULL != qe; qe = qe->next)
135  {
136  switch (qe->priority)
137  {
139  num_probes_waiting++;
140  break;
141 
143  num_downloads_waiting++;
144  break;
145 
146  default:
147  GNUNET_break (0);
148  break;
149  }
150  }
151  /* now, calculate some basic statistics on running jobs */
152  num_probes_active = 0;
153  num_probes_expired = 0;
154  num_downloads_active = 0;
155  num_downloads_expired = 0;
156  next = h->running_head;
157  while (NULL != (qe = next))
158  {
159  next = qe->next;
160  switch (qe->priority)
161  {
164  end_time = GNUNET_TIME_absolute_add (qe->start_time, run_time);
166  if (0 == rst.rel_value_us)
167  {
168  num_probes_expired++;
169  stop_job (qe);
170  }
171  else
172  {
173  num_probes_active++;
174  restart_at = GNUNET_TIME_relative_min (rst, restart_at);
175  }
176  break;
177 
179  run_time =
180  GNUNET_TIME_relative_saturating_multiply (h->avg_block_latency,
181  qe->blocks * qe->start_times);
182  end_time = GNUNET_TIME_absolute_add (qe->start_time, run_time);
184  if (0 == rst.rel_value_us)
185  {
186  num_downloads_expired++;
187  stop_job (qe);
188  }
189  else
190  {
191  num_downloads_active++;
192  restart_at = GNUNET_TIME_relative_min (rst, restart_at);
193  }
194  break;
195 
196  default:
197  GNUNET_break (0);
198  break;
199  }
200  }
201  GNUNET_break (h->active_downloads ==
202  num_downloads_active + num_probes_active);
204  "PA: %u, PE: %u, PW: %u; DA: %u, DE: %u, DW: %u\n",
205  num_probes_active,
206  num_probes_expired,
207  num_probes_waiting,
208  num_downloads_active,
209  num_downloads_expired,
210  num_downloads_waiting);
211  GNUNET_break (h->active_downloads + num_probes_active <=
212  h->max_parallel_downloads);
213  /* calculate start/stop decisions */
214  if (h->active_downloads + num_downloads_waiting > h->max_parallel_downloads)
215  {
216  /* stop as many probes as there are downloads and probes */
217  num_probes_change = -GNUNET_MIN (num_probes_active, num_downloads_waiting);
218  /* start as many downloads as there are free slots, including those
219  we just opened up */
220  num_downloads_change =
221  h->max_parallel_downloads - h->active_downloads - num_probes_change;
222  }
223  else
224  {
225  /* start all downloads (we can) */
226  num_downloads_change = num_downloads_waiting;
227  /* also start probes if there is room, but use a lower cap of (mpd/4) + 1 */
228  if (1 + h->max_parallel_downloads / 4 >=
229  (h->active_downloads + num_downloads_change))
230  num_probes_change =
231  GNUNET_MIN (num_probes_waiting,
232  (1 + h->max_parallel_downloads / 4)
233  - (h->active_downloads + num_downloads_change));
234  else
235  num_probes_change = 0;
236  }
237  GNUNET_break (num_downloads_change <= num_downloads_waiting);
239  "Changing %d probes and %d/%u/%u downloads\n",
240  num_probes_change,
241  num_downloads_change,
242  (unsigned int) h->active_downloads,
243  (unsigned int) h->max_parallel_downloads);
244  /* actually stop probes */
245  next = h->running_head;
246  while (NULL != (qe = next))
247  {
248  next = qe->next;
250  continue;
251  if (num_probes_change < 0)
252  {
253  stop_job (qe);
254  num_probes_change++;
255  if (0 == num_probes_change)
256  break;
257  }
258  }
259  GNUNET_break (0 <= num_probes_change);
260 
261  /* start some more tasks if we now have empty slots */
262  block_limit_hit = GNUNET_NO;
263  next = h->pending_head;
264  while ((NULL != (qe = next)) &&
265  ((num_probes_change > 0) || (num_downloads_change > 0)))
266  {
267  next = qe->next;
268  switch (qe->priority)
269  {
271  if (num_probes_change > 0)
272  {
273  start_job (qe);
274  num_probes_change--;
276  restart_at = GNUNET_TIME_relative_min (run_time, restart_at);
277  }
278  break;
279 
281  if ((num_downloads_change > 0) &&
282  ((qe->blocks + h->active_blocks <= h->max_parallel_requests) ||
283  ((qe->blocks > h->max_parallel_requests) &&
284  (0 == h->active_downloads))))
285  {
286  start_job (qe);
287  num_downloads_change--;
288  }
289  else if (num_downloads_change > 0)
290  block_limit_hit = GNUNET_YES;
291  break;
292 
293  default:
294  GNUNET_break (0);
295  break;
296  }
297  }
298  GNUNET_break ((0 == num_downloads_change) || (GNUNET_YES == block_limit_hit));
299  GNUNET_break (0 == num_probes_change);
300 
301  GNUNET_log (
303  "AD: %u, MP: %u; %d probes and %d downloads to start, will run again in %s\n",
304  h->active_downloads,
305  h->max_parallel_requests,
306  num_probes_change,
307  num_downloads_change,
309 
310  /* make sure we run again, callbacks might have
311  already re-scheduled the job, so cancel such
312  an operation (if it exists) */
313  if (NULL != h->queue_job)
314  GNUNET_SCHEDULER_cancel (h->queue_job);
315  h->queue_job =
317 }
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:51
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:78
static void process_job_queue(void *cls)
Process the jobs in the job queue, possibly starting some and stopping others.
Definition: fs_api.c:107
@ GNUNET_FS_QUEUE_PRIORITY_NORMAL
Default priority.
Definition: fs_api.h:413
@ GNUNET_FS_QUEUE_PRIORITY_PROBE
This is a probe (low priority).
Definition: fs_api.h:408
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static struct GNUNET_TIME_Absolute end_time
At what time MUST the current hostlist request be done?
#define GNUNET_MIN(a, b)
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:975
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:1272
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:343
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
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:531
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:405
#define GNUNET_TIME_UNIT_MINUTES
One minute.
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:484
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:450
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:569
unsigned int priority
Priority in the queue.
struct GNUNET_DATASTORE_QueueEntry * next
This is a linked list.
Master context for most FS operations.
Definition: fs_api.h:1070
Entry in the job queue.
Definition: fs_api.h:421
struct GNUNET_FS_QueueEntry * next
This is a linked list.
Definition: fs_api.h:425
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.

References end_time, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_FS_QUEUE_PRIORITY_NORMAL, GNUNET_FS_QUEUE_PRIORITY_PROBE, GNUNET_log, GNUNET_MIN, GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_cancel(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_add(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_relative_min(), GNUNET_TIME_relative_multiply(), GNUNET_TIME_relative_saturating_multiply(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TIME_UNIT_MINUTES, GNUNET_YES, h, GNUNET_DATASTORE_QueueEntry::next, GNUNET_FS_QueueEntry::next, GNUNET_DATASTORE_QueueEntry::priority, qe, GNUNET_TIME_Relative::rel_value_us, start_job(), and stop_job().

Referenced by GNUNET_FS_dequeue_(), and GNUNET_FS_queue_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_FS_queue_()

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.

Parameters
hhandle to the overall FS state
startfunction to call to begin the job
stopfunction to call to pause the job, or on dequeue (if the job was running)
clsclosure for start and stop
blocksnumber of blocks this download has
priorityhow important is this download
Returns
queue handle

Definition at line 321 of file fs_api.c.

327 {
328  struct GNUNET_FS_QueueEntry *qe;
329 
331  qe->h = h;
332  qe->start = start;
333  qe->stop = stop;
334  qe->cls = cls;
335  qe->queue_time = GNUNET_TIME_absolute_get ();
336  qe->blocks = blocks;
337  qe->priority = priority;
338  GNUNET_CONTAINER_DLL_insert_after (h->pending_head,
339  h->pending_tail,
340  h->pending_tail,
341  qe);
342  if (NULL != h->queue_job)
343  GNUNET_SCHEDULER_cancel (h->queue_job);
345  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Queueing job %p\n", qe);
346  return qe;
347 }
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
#define GNUNET_new(type)
Allocate a struct or union of the given type.
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:1299
GNUNET_SCHEDULER_TaskCallback stop
Function to call when the job needs to stop (or is done / dequeued).
Definition: fs_api.h:440
void * cls
Closure for start and stop.
Definition: fs_api.h:445
enum GNUNET_FS_QueuePriority priority
How important is this download?
Definition: fs_api.h:481
unsigned int blocks
How many blocks do the active downloads have?
Definition: fs_api.h:476

References GNUNET_FS_QueueEntry::blocks, GNUNET_FS_QueueEntry::cls, GNUNET_CONTAINER_DLL_insert_after, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_new, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), GNUNET_TIME_absolute_get(), h, GNUNET_DATASTORE_QueueEntry::h, GNUNET_DATASTORE_QueueEntry::priority, GNUNET_FS_QueueEntry::priority, process_job_queue(), qe, start, and GNUNET_FS_QueueEntry::stop.

Referenced by GNUNET_FS_download_resume(), and GNUNET_FS_download_start_downloading_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_FS_dequeue_()

void GNUNET_FS_dequeue_ ( struct GNUNET_FS_QueueEntry qe)

Dequeue a job from the queue.

Parameters
qehandle for the job

Definition at line 356 of file fs_api.c.

357 {
358  struct GNUNET_FS_Handle *h;
359 
360  h = qe->h;
361  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Dequeueing job %p\n", qe);
362  if (GNUNET_YES == qe->active)
363  stop_job (qe);
364  GNUNET_CONTAINER_DLL_remove (h->pending_head, h->pending_tail, qe);
365  GNUNET_free (qe);
366  if (NULL != h->queue_job)
367  GNUNET_SCHEDULER_cancel (h->queue_job);
369 }
#define GNUNET_free(ptr)
Wrapper around free.

References GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), GNUNET_YES, h, GNUNET_DATASTORE_QueueEntry::h, process_job_queue(), qe, and stop_job().

Referenced by check_completed(), GNUNET_FS_download_signal_suspend_(), and process_result_with_request().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_FS_make_top()

struct TopLevelActivity* GNUNET_FS_make_top ( struct GNUNET_FS_Handle h,
SuspendSignalFunction  ssf,
void *  ssf_cls 
)

Create a top-level activity entry.

Parameters
hglobal fs handle
ssfsuspend signal function to use
ssf_clsclosure for ssf
Returns
fresh top-level activity handle

Definition at line 381 of file fs_api.c.

384 {
385  struct TopLevelActivity *ret;
386 
387  ret = GNUNET_new (struct TopLevelActivity);
388  ret->ssf = ssf;
389  ret->ssf_cls = ssf_cls;
390  GNUNET_CONTAINER_DLL_insert (h->top_head, h->top_tail, ret);
391  return ret;
392 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
We track all of the top-level activities of FS so that we can signal 'suspend' on shutdown.
Definition: fs_api.h:1018
void * ssf_cls
Closure for 'ssf' (some struct GNUNET_FS_XXXHandle*)
Definition: fs_api.h:1037
SuspendSignalFunction ssf
Function to call for suspend-signalling and clean up.
Definition: fs_api.h:1032

References GNUNET_CONTAINER_DLL_insert, GNUNET_new, h, ret, TopLevelActivity::ssf, and TopLevelActivity::ssf_cls.

Referenced by deserialize_download(), deserialize_publish_file(), deserialize_search_file(), deserialize_unindex_file(), GNUNET_FS_download_start(), GNUNET_FS_publish_start(), GNUNET_FS_search_start(), GNUNET_FS_unindex_start(), and search_result_stop().

Here is the caller graph for this function:

◆ GNUNET_FS_end_top()

void GNUNET_FS_end_top ( struct GNUNET_FS_Handle h,
struct TopLevelActivity top 
)

Destroy a top-level activity entry.

Parameters
hglobal fs handle
toptop level activity entry

Definition at line 402 of file fs_api.c.

403 {
404  GNUNET_CONTAINER_DLL_remove (h->top_head, h->top_tail, top);
405  GNUNET_free (top);
406 }

References GNUNET_CONTAINER_DLL_remove, GNUNET_free, and h.

Referenced by GNUNET_FS_download_signal_suspend_(), GNUNET_FS_publish_signal_suspend_(), GNUNET_FS_publish_stop(), GNUNET_FS_search_signal_suspend_(), GNUNET_FS_search_stop(), GNUNET_FS_unindex_signal_suspend_(), and GNUNET_FS_unindex_stop().

Here is the caller graph for this function:

◆ GNUNET_FS_data_reader_file_()

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.

Parameters
clsclosure with the struct FileInfo *
offsetoffset to read from; it is possible that the caller might need to go backwards a bit at times; set to UINT64_MAX to tell the reader that we won't be reading for a while (used to close the file descriptor but NOT fully clean up the reader's state); in this case, a value of '0' for max should be ignored
maxmaximum number of bytes that should be copied to buf; readers are not allowed to provide less data unless there is an error; a value of "0" will be used at the end to allow the reader to clean up its internal state
bufwhere the reader should write the data
emsglocation for the reader to store an error message
Returns
number of bytes written, usually max, 0 on error

Definition at line 447 of file fs_api.c.

452 {
453  struct FileInfo *fi = cls;
454  ssize_t ret;
455 
456  if (UINT64_MAX == offset)
457  {
458  if (NULL != fi->fd)
459  {
461  fi->fd = NULL;
462  }
463  return 0;
464  }
465  if (0 == max)
466  {
467  if (NULL != fi->fd)
469  GNUNET_free (fi->filename);
470  GNUNET_free (fi);
471  return 0;
472  }
473  if (NULL == fi->fd)
474  {
475  fi->fd = GNUNET_DISK_file_open (fi->filename,
478  if (NULL == fi->fd)
479  {
480  GNUNET_asprintf (emsg,
481  _ ("Could not open file `%s': %s"),
482  fi->filename,
483  strerror (errno));
484  return 0;
485  }
486  }
487  if ((GNUNET_SYSERR ==
489  (-1 == (ret = GNUNET_DISK_file_read (fi->fd, buf, max))))
490  {
491  GNUNET_asprintf (emsg,
492  _ ("Could not read file `%s': %s"),
493  fi->filename,
494  strerror (errno));
495  return 0;
496  }
497  if (ret != max)
498  {
499  GNUNET_asprintf (emsg,
500  _ ("Short read reading from file `%s'!"),
501  fi->filename);
502  return 0;
503  }
504  return max;
505 }
static char buf[2048]
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:1237
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:205
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1308
ssize_t GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: disk.c:622
@ GNUNET_DISK_OPEN_READ
Open the file for reading.
@ GNUNET_DISK_PERM_NONE
Nobody is allowed to do anything to the file.
@ GNUNET_DISK_SEEK_SET
Seek an absolute position (from the start of the file).
@ GNUNET_SYSERR
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define max(x, y)
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
Closure for GNUNET_FS_data_reader_file_().
Definition: fs_api.c:413
struct GNUNET_DISK_FileHandle * fd
File descriptor, NULL if it has not yet been opened.
Definition: fs_api.c:422
char * filename
Name of the file to read.
Definition: fs_api.c:417

References _, buf, FileInfo::fd, FileInfo::filename, GNUNET_asprintf(), GNUNET_DISK_file_close(), GNUNET_DISK_file_open(), GNUNET_DISK_file_read(), GNUNET_DISK_file_seek(), GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE, GNUNET_DISK_SEEK_SET, GNUNET_free, GNUNET_SYSERR, max, and ret.

Referenced by block_reader(), deserialize_fi_node(), GNUNET_FS_file_information_create_from_file(), and GNUNET_FS_file_information_create_from_reader().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_FS_make_file_reader_context_()

void* GNUNET_FS_make_file_reader_context_ ( const char *  filename)

Create the closure for the GNUNET_FS_data_reader_file_() callback.

Parameters
filenamefile to read
Returns
closure to use, NULL on error

Definition at line 509 of file fs_api.c.

510 {
511  struct FileInfo *fi;
512 
513  fi = GNUNET_new (struct FileInfo);
515  if (NULL == fi->filename)
516  {
517  GNUNET_free (fi);
518  return NULL;
519  }
520  return fi;
521 }
static char * filename
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
Definition: strings.c:494

References FileInfo::filename, filename, GNUNET_free, GNUNET_new, and GNUNET_STRINGS_filename_expand().

Referenced by deserialize_fi_node(), and GNUNET_FS_file_information_create_from_file().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_FS_data_reader_copy_()

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.

Parameters
clsclosure (points to the buffer)
offsetoffset to read from; it is possible that the caller might need to go backwards a bit at times; set to UINT64_MAX to tell the reader that we won't be reading for a while (used to close the file descriptor but NOT fully clean up the reader's state); in this case, a value of '0' for max should be ignored
maxmaximum number of bytes that should be copied to buf; readers are not allowed to provide less data unless there is an error; a value of "0" will be used at the end to allow the reader to clean up its internal state
bufwhere the reader should write the data
emsglocation for the reader to store an error message
Returns
number of bytes written, usually max, 0 on error

Definition at line 545 of file fs_api.c.

550 {
551  char *data = cls;
552 
553  if (UINT64_MAX == offset)
554  return 0;
555  if (0 == max)
556  {
557  GNUNET_free (data);
558  return 0;
559  }
560  GNUNET_memcpy (buf, &data[offset], max);
561  return max;
562 }
uint32_t data
The data value.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.

References buf, data, GNUNET_free, GNUNET_memcpy, and max.

Referenced by deserialize_fi_node(), and GNUNET_FS_file_information_create_from_data().

Here is the caller graph for this function:

◆ get_serialization_file_name()

static char* get_serialization_file_name ( struct GNUNET_FS_Handle h,
const char *  ext,
const char *  ent 
)
static

Return the full filename where we would store state information (for serialization/deserialization).

Parameters
hmaster context
extcomponent of the path
ententity identifier (or empty string for the directory)
Returns
NULL on error

Definition at line 575 of file fs_api.c.

578 {
579  char *basename;
580  char *ret;
581 
582  if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
583  return NULL; /* persistence not requested */
585  "fs",
586  "STATE_DIR",
587  &basename))
588  return NULL;
590  "%s%s%s%s%s%s%s",
591  basename,
593  h->client_name,
595  ext,
597  ent);
598  GNUNET_free (basename);
599  return ret;
600 }
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
@ GNUNET_FS_FLAGS_PERSISTENCE
Is persistence of operations desired? (will create SUSPEND/RESUME events).
@ GNUNET_OK
#define DIR_SEPARATOR_STR
Definition: platform.h:166
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration that we are using.
Definition: arm_api.c:112

References GNUNET_ARM_Handle::cfg, DIR_SEPARATOR_STR, GNUNET_asprintf(), GNUNET_CONFIGURATION_get_value_filename(), GNUNET_free, GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_OK, h, and ret.

Referenced by deserialization_master(), deserialize_file_information(), get_download_sync_filename(), get_read_handle(), get_write_handle(), GNUNET_FS_file_information_sync_(), GNUNET_FS_remove_sync_file_(), and make_serialization_file_name().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_serialization_file_name_in_dir()

static char* get_serialization_file_name_in_dir ( struct GNUNET_FS_Handle h,
const char *  ext,
const char *  uni,
const char *  ent 
)
static

Return the full filename where we would store state information (for serialization/deserialization) that is associated with a parent operation.

Parameters
hmaster context
extcomponent of the path
uniname of the parent operation
ententity identifier (or empty string for the directory)
Returns
NULL on error

Definition at line 615 of file fs_api.c.

619 {
620  char *basename;
621  char *ret;
622 
623  if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
624  return NULL; /* persistence not requested */
626  "fs",
627  "STATE_DIR",
628  &basename))
629  return NULL;
631  "%s%s%s%s%s%s%s.dir%s%s",
632  basename,
634  h->client_name,
636  ext,
638  uni,
640  ent);
641  GNUNET_free (basename);
642  return ret;
643 }

References GNUNET_ARM_Handle::cfg, DIR_SEPARATOR_STR, GNUNET_asprintf(), GNUNET_CONFIGURATION_get_value_filename(), GNUNET_free, GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_OK, h, and ret.

Referenced by deserialize_search(), get_write_handle_in_dir(), GNUNET_FS_remove_sync_dir_(), make_serialization_file_name_in_dir(), and remove_sync_file_in_dir().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_read_handle()

static struct GNUNET_BIO_ReadHandle* get_read_handle ( struct GNUNET_FS_Handle h,
const char *  ext,
const char *  ent 
)
static

Return a read handle for deserialization.

Parameters
hmaster context
extcomponent of the path
ententity identifier (or empty string for the directory)
Returns
NULL on error

Definition at line 655 of file fs_api.c.

656 {
657  char *fn;
658  struct GNUNET_BIO_ReadHandle *ret;
659 
660  fn = get_serialization_file_name (h, ext, ent);
661  if (NULL == fn)
662  return NULL;
664  GNUNET_free (fn);
665  return ret;
666 }
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:575
struct GNUNET_BIO_ReadHandle * GNUNET_BIO_read_open_file(const char *fn)
Open a file for reading.
Definition: bio.c:115
Handle for buffered reading.
Definition: bio.c:70

References get_serialization_file_name(), GNUNET_BIO_read_open_file(), GNUNET_free, h, and ret.

Referenced by deserialize_file_information(), and deserialize_search_result().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_write_handle()

static struct GNUNET_BIO_WriteHandle* get_write_handle ( struct GNUNET_FS_Handle h,
const char *  ext,
const char *  ent 
)
static

Return a write handle for serialization.

Parameters
hmaster context
extcomponent of the path
ententity identifier (or empty string for the directory)
Returns
NULL on error

Definition at line 678 of file fs_api.c.

679 {
680  char *fn;
681  struct GNUNET_BIO_WriteHandle *ret;
682 
683  fn = get_serialization_file_name (h, ext, ent);
684  if (NULL == fn)
685  return NULL;
687  GNUNET_break (NULL != ret);
688  GNUNET_free (fn);
689  return ret;
690 }
struct GNUNET_BIO_WriteHandle * GNUNET_BIO_write_open_file(const char *fn)
Open a file for writing.
Definition: bio.c:509
Handle for buffered writing.
Definition: bio.c:467

References get_serialization_file_name(), GNUNET_BIO_write_open_file(), GNUNET_break, GNUNET_free, h, and ret.

Referenced by GNUNET_FS_file_information_sync_(), GNUNET_FS_publish_sync_(), GNUNET_FS_search_sync_(), and GNUNET_FS_unindex_sync_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_write_handle_in_dir()

static struct GNUNET_BIO_WriteHandle* get_write_handle_in_dir ( struct GNUNET_FS_Handle h,
const char *  ext,
const char *  uni,
const char *  ent 
)
static

Return a write handle for serialization.

Parameters
hmaster context
extcomponent of the path
uniname of parent
ententity identifier (or empty string for the directory)
Returns
NULL on error

Definition at line 703 of file fs_api.c.

707 {
708  char *fn;
709  struct GNUNET_BIO_WriteHandle *ret;
710 
711  fn = get_serialization_file_name_in_dir (h, ext, uni, ent);
712  if (NULL == fn)
713  return NULL;
715  GNUNET_free (fn);
716  return ret;
717 }
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:615

References get_serialization_file_name_in_dir(), GNUNET_BIO_write_open_file(), GNUNET_free, h, and ret.

Referenced by GNUNET_FS_search_result_sync_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_FS_remove_sync_file_()

void GNUNET_FS_remove_sync_file_ ( struct GNUNET_FS_Handle h,
const char *  ext,
const char *  ent 
)

Remove serialization/deserialization file from disk.

Parameters
hmaster context
extcomponent of the path
ententity identifier

Definition at line 728 of file fs_api.c.

731 {
732  char *filename;
733 
734  if ((NULL == ent) || (0 == strlen (ent)))
735  {
736  GNUNET_break (0);
737  return;
738  }
739  filename = get_serialization_file_name (h, ext, ent);
740  if (NULL != filename)
741  {
742  if ((0 != unlink (filename)) && (ENOENT != errno))
745  }
746 }
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_WARNING

References filename, get_serialization_file_name(), GNUNET_break, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log_strerror_file, and h.

Referenced by deserialize_search_file(), deserialize_unindex_file(), fip_signal_stop(), free_search_context(), GNUNET_FS_publish_stop(), GNUNET_FS_publish_sync_(), GNUNET_FS_search_stop(), GNUNET_FS_search_sync_(), GNUNET_FS_unindex_stop(), GNUNET_FS_unindex_sync_(), and search_result_stop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ remove_sync_file_in_dir()

static void remove_sync_file_in_dir ( struct GNUNET_FS_Handle h,
const char *  ext,
const char *  uni,
const char *  ent 
)
static

Remove serialization/deserialization file from disk.

Parameters
hmaster context
extcomponent of the path
uniparent name
ententity identifier

Definition at line 758 of file fs_api.c.

762 {
763  char *filename;
764 
765  if ((NULL == ent) || (0 == strlen (ent)))
766  {
767  GNUNET_break (0);
768  return;
769  }
770  filename = get_serialization_file_name_in_dir (h, ext, uni, ent);
771  if (NULL == filename)
772  return;
773  if (0 != unlink (filename))
776 }

References filename, get_serialization_file_name_in_dir(), GNUNET_break, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log_strerror_file, and h.

Referenced by deserialize_search_result(), and GNUNET_FS_search_result_sync_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_FS_remove_sync_dir_()

void GNUNET_FS_remove_sync_dir_ ( struct GNUNET_FS_Handle h,
const char *  ext,
const char *  uni 
)

Remove serialization/deserialization directory from disk.

Parameters
hmaster context
extcomponent of the path
uniunique name of parent

Definition at line 787 of file fs_api.c.

790 {
791  char *dn;
792 
793  if (NULL == uni)
794  return;
795  dn = get_serialization_file_name_in_dir (h, ext, uni, "");
796  if (NULL == dn)
797  return;
801  GNUNET_free (dn);
802 }
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
Definition: disk.c:1087
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition: disk.c:403

References get_serialization_file_name_in_dir(), GNUNET_DISK_directory_remove(), GNUNET_DISK_directory_test(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log_strerror_file, GNUNET_OK, GNUNET_YES, and h.

Referenced by free_search_context(), and GNUNET_FS_search_stop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_start_time()

static int write_start_time ( struct GNUNET_BIO_WriteHandle wh,
struct GNUNET_TIME_Absolute  timestamp 
)
static

Serialize a start-time.

Since we use start-times to calculate the duration of some operation, we actually do not serialize the absolute time but the (relative) duration since the start time. When we then deserialize the start time, we take the current time and subtract that duration so that we get again an absolute time stamp that will result in correct performance calculations.

Parameters
whhandle for writing
timestamptime to serialize
Returns
GNUNET_OK on success

Definition at line 820 of file fs_api.c.

822 {
823  struct GNUNET_TIME_Relative dur;
824 
825  dur = GNUNET_TIME_absolute_get_duration (timestamp);
826  return GNUNET_BIO_write_int64 (wh, "start time", dur.rel_value_us);
827 }
static struct GNUNET_TESTBED_BarrierWaitHandle * wh
Our barrier wait handle.
enum GNUNET_GenericReturnValue GNUNET_BIO_write_int64(struct GNUNET_BIO_WriteHandle *h, const char *what, int64_t i)
Write an (u)int64_t.
Definition: bio.c:868

References GNUNET_BIO_write_int64(), GNUNET_TIME_absolute_get_duration(), GNUNET_TIME_Relative::rel_value_us, and wh.

Referenced by GNUNET_FS_download_sync_(), GNUNET_FS_file_information_sync_(), GNUNET_FS_search_sync_(), and GNUNET_FS_unindex_sync_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_start_time()

static int read_start_time ( struct GNUNET_BIO_ReadHandle rh,
struct GNUNET_TIME_Absolute timestamp 
)
static

Deserialize a start-time.

Since we use start-times to calculate the duration of some operation, we actually do not serialize the absolute time but the (relative) duration since the start time. Thus, when we then deserialize the start time, we take the current time and subtract that duration so that we get again an absolute time stamp that will result in correct performance calculations.

Parameters
rhhandle for reading
timestampwhere to write the deserialized timestamp
Returns
GNUNET_OK on success

Definition at line 845 of file fs_api.c.

847 {
848  struct GNUNET_TIME_Relative dur;
849 
850  if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, "start time",
851  (int64_t *) &dur.rel_value_us))
852  return GNUNET_SYSERR;
854  return GNUNET_OK;
855 }
enum GNUNET_GenericReturnValue GNUNET_BIO_read_int64(struct GNUNET_BIO_ReadHandle *h, const char *what, int64_t *i)
Read an (u)int64_t.
Definition: bio.c:450
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:469

References GNUNET_BIO_read_int64(), GNUNET_OK, GNUNET_SYSERR, GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_subtract(), and GNUNET_TIME_Relative::rel_value_us.

Referenced by deserialize_download(), deserialize_fi_node(), deserialize_search(), and deserialize_unindex_file().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ deserialize_file_information()

static struct GNUNET_FS_FileInformation * deserialize_file_information ( struct GNUNET_FS_Handle h,
const char *  filename 
)
static

Using the given serialization filename, try to deserialize the file-information tree associated with it.

Parameters
hmaster context
filenamename of the file (without directory) with the information
Returns
NULL on error

Definition at line 1143 of file fs_api.c.

1144 {
1146  struct GNUNET_BIO_ReadHandle *rh;
1147  char *emsg;
1148  char *fn;
1149 
1151  if (NULL == rh)
1152  return NULL;
1153  ret = deserialize_fi_node (h, filename, rh);
1154  if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
1155  {
1157  _ ("Failed to resume publishing information `%s': %s\n"),
1158  filename,
1159  emsg);
1160  GNUNET_free (emsg);
1161  }
1162  if (NULL == ret)
1163  {
1164  fn =
1166  if (NULL != fn)
1167  {
1168  if (0 != unlink (fn))
1170  GNUNET_free (fn);
1171  }
1172  }
1173  return ret;
1174 }
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:882
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:655
#define GNUNET_FS_SYNC_PATH_FILE_INFO
Name of the directory with files that are being published.
Definition: fs_api.h:82
enum GNUNET_GenericReturnValue GNUNET_BIO_read_close(struct GNUNET_BIO_ReadHandle *h, char **emsg)
Close an open handle.
Definition: bio.c:163
char * emsg
Error message, NULL if there were no errors.
Definition: bio.c:84
Information for a file or directory that is about to be published.
Definition: fs_api.h:228

References _, deserialize_fi_node(), GNUNET_BIO_ReadHandle::emsg, filename, get_read_handle(), get_serialization_file_name(), GNUNET_BIO_read_close(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_FS_SYNC_PATH_FILE_INFO, GNUNET_log, GNUNET_log_strerror_file, GNUNET_OK, h, and ret.

Referenced by deserialize_fi_node(), and deserialize_publish_file().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ deserialize_fi_node()

static struct GNUNET_FS_FileInformation* deserialize_fi_node ( struct GNUNET_FS_Handle h,
const char *  fn,
struct GNUNET_BIO_ReadHandle rh 
)
static

Using the given serialization filename, try to deserialize the file-information tree associated with it.

Parameters
hmaster context
fnname of the file (without directory) with the information
rhhandle for reading
Returns
NULL on error

Definition at line 882 of file fs_api.c.

885 {
887  struct GNUNET_FS_FileInformation *nxt;
888  char b;
889  char *ksks;
890  char *chks;
891  char *skss;
892  char *filename;
893  uint32_t dsize;
894 
895  if (GNUNET_OK != GNUNET_BIO_read (rh, "status flag", &b, sizeof(b)))
896  {
897  GNUNET_break (0);
898  return NULL;
899  }
901  ret->h = h;
902  ksks = NULL;
903  chks = NULL;
904  skss = NULL;
905  filename = NULL;
906  if ((GNUNET_OK != GNUNET_FS_read_meta_data (rh, "metadata", &ret->meta)) ||
907  (GNUNET_OK != GNUNET_BIO_read_string (rh, "ksk-uri", &ksks, 32 * 1024)) ||
908  ((NULL != ksks) &&
909  ((NULL == (ret->keywords = GNUNET_FS_uri_parse (ksks, NULL))) ||
910  (GNUNET_YES != GNUNET_FS_uri_test_ksk (ret->keywords)))) ||
911  (GNUNET_OK != GNUNET_BIO_read_string (rh, "chk-uri", &chks, 1024)) ||
912  ((NULL != chks) &&
913  ((NULL == (ret->chk_uri = GNUNET_FS_uri_parse (chks, NULL))) ||
914  (GNUNET_YES != GNUNET_FS_uri_test_chk (ret->chk_uri)))) ||
915  (GNUNET_OK != GNUNET_BIO_read_string (rh, "sks-uri", &skss, 1024)) ||
916  ((NULL != skss) &&
917  ((NULL == (ret->sks_uri = GNUNET_FS_uri_parse (skss, NULL))) ||
918  (GNUNET_YES != GNUNET_FS_uri_test_sks (ret->sks_uri)))) ||
919  (GNUNET_OK != read_start_time (rh, &ret->start_time)) ||
920  (GNUNET_OK !=
921  GNUNET_BIO_read_string (rh, "emsg", &ret->emsg, 16 * 1024)) ||
922  (GNUNET_OK !=
923  GNUNET_BIO_read_string (rh, "fn", &ret->filename, 16 * 1024)) ||
924  (GNUNET_OK !=
926  rh,
927  "expiration time",
928  (int64_t *) &ret->bo.expiration_time.abs_value_us)) ||
930  rh,
931  "anonymity level",
932  (int32_t *) &ret->bo.anonymity_level)) ||
934  rh,
935  "content priority",
936  (int32_t *) &ret->bo.content_priority)) ||
938  rh,
939  "replication level",
940  (int32_t *) &ret->bo.replication_level)))
941  {
942  GNUNET_break (0);
943  goto cleanup;
944  }
945  switch (b)
946  {
947  case 0: /* file-insert */
949  rh,
950  "file size",
951  (int64_t *) &ret->data.file.file_size))
952  {
953  GNUNET_break (0);
954  goto cleanup;
955  }
956  ret->is_directory = GNUNET_NO;
957  ret->data.file.do_index = GNUNET_NO;
958  ret->data.file.have_hash = GNUNET_NO;
959  ret->data.file.index_start_confirmed = GNUNET_NO;
960  if (GNUNET_NO == ret->is_published)
961  {
962  if (NULL == ret->filename)
963  {
964  ret->data.file.reader = &GNUNET_FS_data_reader_copy_;
965  ret->data.file.reader_cls =
966  GNUNET_malloc_large (ret->data.file.file_size);
967  if (ret->data.file.reader_cls == NULL)
968  goto cleanup;
969  if (GNUNET_OK != GNUNET_BIO_read (rh,
970  "file-data",
971  ret->data.file.reader_cls,
972  ret->data.file.file_size))
973  {
974  GNUNET_break (0);
975  goto cleanup;
976  }
977  }
978  else
979  {
980  ret->data.file.reader = &GNUNET_FS_data_reader_file_;
981  ret->data.file.reader_cls =
983  }
984  }
985  break;
986 
987  case 1: /* file-index, no hash */
988  if (NULL == ret->filename)
989  {
990  GNUNET_break (0);
991  goto cleanup;
992  }
994  rh,
995  "file size",
996  (int64_t *) &ret->data.file.file_size))
997  {
998  GNUNET_break (0);
999  goto cleanup;
1000  }
1001  ret->is_directory = GNUNET_NO;
1002  ret->data.file.do_index = GNUNET_YES;
1003  ret->data.file.have_hash = GNUNET_NO;
1004  ret->data.file.index_start_confirmed = GNUNET_NO;
1005  ret->data.file.reader = &GNUNET_FS_data_reader_file_;
1006  ret->data.file.reader_cls =
1008  break;
1009 
1010  case 2: /* file-index-with-hash */
1011  if (NULL == ret->filename)
1012  {
1013  GNUNET_break (0);
1014  goto cleanup;
1015  }
1017  rh,
1018  "file size",
1019  (int64_t *) &ret->data.file.file_size)) ||
1020  (GNUNET_OK != GNUNET_BIO_read (rh,
1021  "fileid",
1022  &ret->data.file.file_id,
1023  sizeof(struct GNUNET_HashCode))))
1024  {
1025  GNUNET_break (0);
1026  goto cleanup;
1027  }
1028  ret->is_directory = GNUNET_NO;
1029  ret->data.file.do_index = GNUNET_YES;
1030  ret->data.file.have_hash = GNUNET_YES;
1031  ret->data.file.index_start_confirmed = GNUNET_NO;
1032  ret->data.file.reader = &GNUNET_FS_data_reader_file_;
1033  ret->data.file.reader_cls =
1035  break;
1036 
1037  case 3: /* file-index-with-hash-confirmed */
1038  if (NULL == ret->filename)
1039  {
1040  GNUNET_break (0);
1041  goto cleanup;
1042  }
1044  rh,
1045  "file size",
1046  (int64_t *) &ret->data.file.file_size)) ||
1047  (GNUNET_OK != GNUNET_BIO_read (rh,
1048  "fileid",
1049  &ret->data.file.file_id,
1050  sizeof(struct GNUNET_HashCode))))
1051  {
1052  GNUNET_break (0);
1053  goto cleanup;
1054  }
1055  ret->is_directory = GNUNET_NO;
1056  ret->data.file.do_index = GNUNET_YES;
1057  ret->data.file.have_hash = GNUNET_YES;
1058  ret->data.file.index_start_confirmed = GNUNET_YES;
1059  ret->data.file.reader = &GNUNET_FS_data_reader_file_;
1060  ret->data.file.reader_cls =
1062  break;
1063 
1064  case 4: /* directory */
1065  ret->is_directory = GNUNET_YES;
1066  if ((GNUNET_OK != GNUNET_BIO_read_int32 (rh, "dsize",
1067  (int32_t *) &dsize)) ||
1068  (GNUNET_OK !=
1070  rh,
1071  "contents completed",
1072  (int64_t *) &ret->data.dir.contents_completed)) ||
1073  (GNUNET_OK !=
1075  rh,
1076  "contents size",
1077  (int64_t *) &ret->data.dir.contents_size)) ||
1078  (NULL == (ret->data.dir.dir_data = GNUNET_malloc_large (dsize))) ||
1079  (GNUNET_OK !=
1080  GNUNET_BIO_read (rh, "dir-data", ret->data.dir.dir_data, dsize)) ||
1081  (GNUNET_OK !=
1082  GNUNET_BIO_read_string (rh, "ent-filename", &filename, 16 * 1024)))
1083  {
1084  GNUNET_break (0);
1085  goto cleanup;
1086  }
1087  ret->data.dir.dir_size = (uint32_t) dsize;
1088  if (NULL != filename)
1089  {
1090  ret->data.dir.entries = deserialize_file_information (h, filename);
1092  filename = NULL;
1093  nxt = ret->data.dir.entries;
1094  while (NULL != nxt)
1095  {
1096  nxt->dir = ret;
1097  nxt = nxt->next;
1098  }
1099  }
1100  break;
1101 
1102  default:
1103  GNUNET_break (0);
1104  goto cleanup;
1105  }
1106  ret->serialization = GNUNET_strdup (fn);
1107  if (GNUNET_OK !=
1108  GNUNET_BIO_read_string (rh, "nxt-filename", &filename, 16 * 1024))
1109  {
1110  GNUNET_break (0);
1111  goto cleanup;
1112  }
1113  if (NULL != filename)
1114  {
1117  filename = NULL;
1118  }
1119  GNUNET_free (ksks);
1120  GNUNET_free (skss);
1121  GNUNET_free (chks);
1122  return ret;
1123 cleanup:
1124  GNUNET_free (ksks);
1125  GNUNET_free (chks);
1126  GNUNET_free (skss);
1129  return NULL;
1130 }
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:1143
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:509
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:545
static int read_start_time(struct GNUNET_BIO_ReadHandle *rh, struct GNUNET_TIME_Absolute *timestamp)
Deserialize a start-time.
Definition: fs_api.c:845
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:447
static void cleanup(void *cls)
Function scheduled as very last function, cleans up after us.
enum GNUNET_GenericReturnValue GNUNET_BIO_read(struct GNUNET_BIO_ReadHandle *h, const char *what, void *result, size_t len)
Read some contents into a buffer.
Definition: bio.c:292
enum GNUNET_GenericReturnValue GNUNET_BIO_read_string(struct GNUNET_BIO_ReadHandle *h, const char *what, char **result, size_t max_length)
Read 0-terminated string.
Definition: bio.c:331
enum GNUNET_GenericReturnValue GNUNET_BIO_read_int32(struct GNUNET_BIO_ReadHandle *h, const char *what, int32_t *i)
Read an (u)int32_t.
Definition: bio.c:428
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:637
int GNUNET_FS_uri_test_ksk(const struct GNUNET_FS_Uri *uri)
Is this a keyword URI?
Definition: fs_uri.c:1324
enum GNUNET_GenericReturnValue GNUNET_FS_read_meta_data(struct GNUNET_BIO_ReadHandle *h, const char *what, struct GNUNET_FS_MetaData **result)
Read a metadata container.
Definition: meta_data.c:1055
int GNUNET_FS_uri_test_sks(const struct GNUNET_FS_Uri *uri)
Is this a namespace URI?
Definition: fs_uri.c:1271
int GNUNET_FS_uri_test_chk(const struct GNUNET_FS_Uri *uri)
Is this a file (or directory) URI?
Definition: fs_uri.c:1346
void GNUNET_FS_file_information_destroy(struct GNUNET_FS_FileInformation *fi, GNUNET_FS_FileInformationProcessor cleaner, void *cleaner_cls)
Destroy publish-structure.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_malloc_large(size)
Wrapper around malloc.
struct GNUNET_FS_FileInformation * next
Files in a directory are kept as a linked list.
Definition: fs_api.h:232
struct GNUNET_FS_FileInformation * dir
If this is a file in a directory, "dir" refers to the directory; otherwise NULL.
Definition: fs_api.h:238
A 512-bit hashcode.

References cleanup(), deserialize_file_information(), GNUNET_FS_FileInformation::dir, filename, GNUNET_BIO_read(), GNUNET_BIO_read_int32(), GNUNET_BIO_read_int64(), GNUNET_BIO_read_string(), GNUNET_break, GNUNET_free, GNUNET_FS_data_reader_copy_(), GNUNET_FS_data_reader_file_(), GNUNET_FS_file_information_destroy(), GNUNET_FS_make_file_reader_context_(), GNUNET_FS_read_meta_data(), GNUNET_FS_uri_parse(), GNUNET_FS_uri_test_chk(), GNUNET_FS_uri_test_ksk(), GNUNET_FS_uri_test_sks(), GNUNET_malloc_large, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_strdup, GNUNET_YES, h, GNUNET_FS_FileInformation::next, read_start_time(), and ret.

Referenced by deserialize_file_information().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_serialization_short_name()

static char* get_serialization_short_name ( const char *  fullname)
static

Given a serialization name (full absolute path), return the basename of the file (without the path), which must only consist of the 6 random characters.

Parameters
fullnamename to extract the basename from
Returns
copy of the basename, NULL on error

Definition at line 1186 of file fs_api.c.

1187 {
1188  const char *end;
1189  const char *nxt;
1190 
1191  end = NULL;
1192  nxt = fullname;
1193  /* FIXME: we could do this faster since we know
1194  * the length of 'end'... */
1195  while ('\0' != *nxt)
1196  {
1197  if (DIR_SEPARATOR == *nxt)
1198  end = nxt + 1;
1199  nxt++;
1200  }
1201  if ((NULL == end) || (0 == strlen (end)))
1202  {
1203  GNUNET_break (0);
1204  return NULL;
1205  }
1206  GNUNET_break (6 == strlen (end));
1207  return GNUNET_strdup (end);
1208 }
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
#define DIR_SEPARATOR
Definition: platform.h:165

References DIR_SEPARATOR, end, GNUNET_break, and GNUNET_strdup.

Referenced by deserialize_download_file(), deserialize_publish_file(), deserialize_search_file(), deserialize_search_result(), deserialize_subdownload(), deserialize_unindex_file(), GNUNET_FS_download_sync_(), make_serialization_file_name(), and make_serialization_file_name_in_dir().

Here is the caller graph for this function:

◆ make_serialization_file_name()

static char* make_serialization_file_name ( struct GNUNET_FS_Handle h,
const char *  ext 
)
static

Create a new random name for serialization.

Also checks if persistence is enabled and returns NULL if not.

Parameters
hmaster context
extcomponent of the path
Returns
NULL on error

Definition at line 1220 of file fs_api.c.

1221 {
1222  char *fn;
1223  char *dn;
1224  char *ret;
1225 
1226  if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
1227  return NULL; /* persistence not requested */
1228  dn = get_serialization_file_name (h, ext, "");
1229  if (NULL == dn)
1230  return NULL;
1232  {
1233  GNUNET_free (dn);
1234  return NULL;
1235  }
1236  fn = GNUNET_DISK_mktemp (dn);
1237  GNUNET_free (dn);
1238  if (NULL == fn)
1239  return NULL; /* epic fail */
1241  GNUNET_free (fn);
1242  return ret;
1243 }
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:1186
char * GNUNET_DISK_mktemp(const char *t)
Create an (empty) temporary file on disk.
Definition: disk.c:380
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:582

References get_serialization_file_name(), get_serialization_short_name(), GNUNET_DISK_directory_create_for_file(), GNUNET_DISK_mktemp(), GNUNET_free, GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_OK, h, and ret.

Referenced by GNUNET_FS_file_information_sync_(), GNUNET_FS_publish_sync_(), GNUNET_FS_search_sync_(), and GNUNET_FS_unindex_sync_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_serialization_file_name_in_dir()

static char* make_serialization_file_name_in_dir ( struct GNUNET_FS_Handle h,
const char *  ext,
const char *  uni 
)
static

Create a new random name for serialization.

Also checks if persistence is enabled and returns NULL if not.

Parameters
hmaster context
extcomponent of the path
uniname of parent
Returns
NULL on error

Definition at line 1256 of file fs_api.c.

1259 {
1260  char *fn;
1261  char *dn;
1262  char *ret;
1263 
1264  if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
1265  return NULL; /* persistence not requested */
1266  dn = get_serialization_file_name_in_dir (h, ext, uni, "");
1267  if (NULL == dn)
1268  return NULL;
1270  {
1271  GNUNET_free (dn);
1272  return NULL;
1273  }
1274  fn = GNUNET_DISK_mktemp (dn);
1275  GNUNET_free (dn);
1276  if (NULL == fn)
1277  return NULL; /* epic fail */
1279  GNUNET_free (fn);
1280  return ret;
1281 }

References get_serialization_file_name_in_dir(), get_serialization_short_name(), GNUNET_DISK_directory_create_for_file(), GNUNET_DISK_mktemp(), GNUNET_free, GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_OK, h, and ret.

Referenced by GNUNET_FS_search_result_sync_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ copy_from_reader()

static int copy_from_reader ( struct GNUNET_BIO_WriteHandle wh,
struct GNUNET_FS_FileInformation fi 
)
static

Copy all of the data from the reader to the write handle.

Parameters
whwrite handle
fifile with reader
Returns
GNUNET_OK on success

Definition at line 1292 of file fs_api.c.

1294 {
1295  char buf[32 * 1024];
1296  uint64_t off;
1297  size_t ret;
1298  size_t left;
1299  char *emsg;
1300 
1301  emsg = NULL;
1302  off = 0;
1303  while (off < fi->data.file.file_size)
1304  {
1305  left = GNUNET_MIN (sizeof(buf), fi->data.file.file_size - off);
1306  ret =
1307  fi->data.file.reader (fi->data.file.reader_cls, off, left, buf, &emsg);
1308  if (0 == ret)
1309  {
1310  GNUNET_free (emsg);
1311  return GNUNET_SYSERR;
1312  }
1313  if (GNUNET_OK != GNUNET_BIO_write (wh, "copied from reader", buf, ret))
1314  return GNUNET_SYSERR;
1315  off += ret;
1316  }
1317  return GNUNET_OK;
1318 }
enum GNUNET_GenericReturnValue GNUNET_BIO_write(struct GNUNET_BIO_WriteHandle *h, const char *what, const void *buffer, size_t n)
Write a buffer to a handle.
Definition: bio.c:753
struct GNUNET_FS_FileInformation::@16::@17 file
Data for a file.
union GNUNET_FS_FileInformation::@16 data
Data describing either the file or the directory.

References buf, GNUNET_FS_FileInformation::data, data, GNUNET_BIO_ReadHandle::emsg, GNUNET_FS_FileInformation::file, GNUNET_BIO_write(), GNUNET_free, GNUNET_MIN, GNUNET_OK, GNUNET_SYSERR, ret, and wh.

Referenced by GNUNET_FS_file_information_sync_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_FS_file_information_sync_()

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.

Synchronize this file-information struct with its mirror on disk.

Parameters
fifile information to sync with disk

Definition at line 1328 of file fs_api.c.

1329 {
1330  char *fn;
1331  struct GNUNET_BIO_WriteHandle *wh;
1332  char b;
1333  char *ksks;
1334  char *chks;
1335  char *skss;
1336 
1337  if (NULL == fi->serialization)
1338  fi->serialization =
1340  if (NULL == fi->serialization)
1341  return;
1342  wh =
1344  if (NULL == wh)
1345  {
1346  GNUNET_free (fi->serialization);
1347  fi->serialization = NULL;
1348  return;
1349  }
1350  if (GNUNET_YES == fi->is_directory)
1351  b = 4;
1352  else if (GNUNET_YES == fi->data.file.index_start_confirmed)
1353  b = 3;
1354  else if (GNUNET_YES == fi->data.file.have_hash)
1355  b = 2;
1356  else if (GNUNET_YES == fi->data.file.do_index)
1357  b = 1;
1358  else
1359  b = 0;
1360  if (NULL != fi->keywords)
1361  ksks = GNUNET_FS_uri_to_string (fi->keywords);
1362  else
1363  ksks = NULL;
1364  if (NULL != fi->chk_uri)
1365  chks = GNUNET_FS_uri_to_string (fi->chk_uri);
1366  else
1367  chks = NULL;
1368  if (NULL != fi->sks_uri)
1369  skss = GNUNET_FS_uri_to_string (fi->sks_uri);
1370  else
1371  skss = NULL;
1372  struct GNUNET_BIO_WriteSpec ws1[] = {
1373  GNUNET_BIO_write_spec_object ("b", &b, sizeof (b)),
1374  GNUNET_FS_write_spec_meta_data ("meta", fi->meta),
1375  GNUNET_BIO_write_spec_string ("ksks", ksks),
1376  GNUNET_BIO_write_spec_string ("chks", chks),
1377  GNUNET_BIO_write_spec_string ("skss", skss),
1379  };
1380  struct GNUNET_BIO_WriteSpec ws2[] = {
1381  GNUNET_BIO_write_spec_string ("emsg", fi->emsg),
1382  GNUNET_BIO_write_spec_string ("filename", fi->filename),
1384  "expiration time",
1385  (int64_t *) &fi->bo.expiration_time.abs_value_us),
1387  "anonymity level",
1388  (int32_t *) &fi->bo.anonymity_level),
1390  "content priority",
1391  (int32_t *) &fi->bo.content_priority),
1393  "replication level",
1394  (int32_t *) &fi->bo.replication_level),
1396  };
1397  if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws1)) ||
1398  (GNUNET_OK != write_start_time (wh, fi->start_time)) ||
1400  {
1401  GNUNET_break (0);
1402  goto cleanup;
1403  }
1404  GNUNET_free (chks);
1405  chks = NULL;
1406  GNUNET_free (ksks);
1407  ksks = NULL;
1408  GNUNET_free (skss);
1409  skss = NULL;
1410 
1411  switch (b)
1412  {
1413  case 0: /* file-insert */
1414  if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, "file size",
1415  fi->data.file.file_size))
1416  {
1417  GNUNET_break (0);
1418  goto cleanup;
1419  }
1420  if ((GNUNET_NO == fi->is_published) && (NULL == fi->filename))
1421  if (GNUNET_OK != copy_from_reader (wh, fi))
1422  {
1423  GNUNET_break (0);
1424  goto cleanup;
1425  }
1426  break;
1427 
1428  case 1: /* file-index, no hash */
1429  if (NULL == fi->filename)
1430  {
1431  GNUNET_break (0);
1432  goto cleanup;
1433  }
1434  if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, "file size",
1435  fi->data.file.file_size))
1436  {
1437  GNUNET_break (0);
1438  goto cleanup;
1439  }
1440  break;
1441 
1442  case 2: /* file-index-with-hash */
1443  case 3: /* file-index-with-hash-confirmed */
1444  if (NULL == fi->filename)
1445  {
1446  GNUNET_break (0);
1447  goto cleanup;
1448  }
1449  if ((GNUNET_OK != GNUNET_BIO_write_int64 (wh, "file size",
1450  fi->data.file.file_size)) ||
1452  "file id",
1453  &fi->data.file.file_id,
1454  sizeof(struct GNUNET_HashCode))))
1455  {
1456  GNUNET_break (0);
1457  goto cleanup;
1458  }
1459  break;
1460 
1461  case 4: /* directory */
1462  if ((NULL != fi->data.dir.entries) &&
1463  (NULL == fi->data.dir.entries->serialization))
1465  struct GNUNET_BIO_WriteSpec ws[] = {
1466  GNUNET_BIO_write_spec_int32 ("dir size",
1467  (int32_t *) &fi->data.dir.dir_size),
1469  "contents completed",
1470  (int64_t *) &fi->data.dir.contents_completed),
1471  GNUNET_BIO_write_spec_int64 ("contents size",
1472  (int64_t *) &fi->data.dir.contents_size),
1473  GNUNET_BIO_write_spec_object ("dir data",
1474  fi->data.dir.dir_data,
1475  (uint32_t) fi->data.dir.dir_size),
1476  GNUNET_BIO_write_spec_string ("dir entries",
1477  (fi->data.dir.entries == NULL)
1478  ? NULL
1479  : fi->data.dir.entries->serialization),
1481  };
1482  if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws)))
1483  {
1484  GNUNET_break (0);
1485  goto cleanup;
1486  }
1487  break;
1488 
1489  default:
1490  GNUNET_assert (0);
1491  goto cleanup;
1492  }
1493  if ((NULL != fi->next) && (NULL == fi->next->serialization))
1496  "serialization",
1497  (fi->next != NULL)
1498  ? fi->next->serialization
1499  : NULL))
1500  {
1501  GNUNET_break (0);
1502  goto cleanup;
1503  }
1504  if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
1505  {
1506  wh = NULL;
1507  GNUNET_break (0);
1508  goto cleanup;
1509  }
1510  return; /* done! */
1511 cleanup:
1512  if (NULL != wh)
1513  (void) GNUNET_BIO_write_close (wh, NULL);
1514  GNUNET_free (chks);
1515  GNUNET_free (ksks);
1516  GNUNET_free (skss);
1517  fn = get_serialization_file_name (fi->h,
1519  fi->serialization);
1520  if (NULL != fn)
1521  {
1522  if (0 != unlink (fn))
1524  GNUNET_free (fn);
1525  }
1526  GNUNET_free (fi->serialization);
1527  fi->serialization = NULL;
1528 }
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:1292
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:1220
static int write_start_time(struct GNUNET_BIO_WriteHandle *wh, struct GNUNET_TIME_Absolute timestamp)
Serialize a start-time.
Definition: fs_api.c:820
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:678
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:1328
enum GNUNET_GenericReturnValue GNUNET_BIO_write_close(struct GNUNET_BIO_WriteHandle *h, char **emsg)
Close an IO handle.
Definition: bio.c:557
struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_string(const char *what, const char *s)
Create the specification to write a 0-terminated string.
Definition: bio.c:1202
enum GNUNET_GenericReturnValue GNUNET_BIO_write_string(struct GNUNET_BIO_WriteHandle *h, const char *what, const char *s)
Write a 0-terminated string.
Definition: bio.c:790
#define GNUNET_BIO_write_spec_end()
End of specifications marker.
struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_object(const char *what, void *source, size_t size)
Create the specification to read some bytes.
Definition: bio.c:1155
enum GNUNET_GenericReturnValue GNUNET_BIO_write_spec_commit(struct GNUNET_BIO_WriteHandle *h, struct GNUNET_BIO_WriteSpec *ws)
Execute the write specifications in order.
Definition: bio.c:1360
struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_int32(const char *what, int32_t *i)
Create the specification to write an (u)int32_t.
Definition: bio.c:1247
struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_int64(const char *what, int64_t *i)
Create the specification to write an (u)int64_t.
Definition: bio.c:1292
char * GNUNET_FS_uri_to_string(const struct GNUNET_FS_Uri *uri)
Convert a URI to a UTF-8 String.
Definition: fs_uri.c:2017
struct GNUNET_BIO_WriteSpec GNUNET_FS_write_spec_meta_data(const char *what, const struct GNUNET_FS_MetaData *m)
Create the specification to write a metadata container.
Definition: meta_data.c:1218
Structure specifying a writing operation on an IO handle.
uint32_t anonymity_level
At which anonymity level should the block be shared? (0: no anonymity, 1: normal GAP,...
uint32_t content_priority
How important is it for us to store the block? If we run out of space, the highest-priority,...
uint32_t replication_level
How often should we try to migrate the block to other peers? Only used if "CONTENT_PUSHING" is set to...
struct GNUNET_TIME_Absolute expiration_time
At what time should the block expire? Data blocks (DBLOCKS and IBLOCKS) may still be used even if the...
char * serialization
Under what filename is this struct serialized (for operational persistence).
Definition: fs_api.h:287
struct GNUNET_FS_Uri * keywords
Keywords to use for KBlocks.
Definition: fs_api.h:258
char * filename
Name of the file or directory (must be an absolute path).
Definition: fs_api.h:302
size_t dir_size
Size of the directory itself (in bytes); 0 if the size has not yet been calculated.
Definition: fs_api.h:368
uint64_t contents_completed
How much of the directory have we published (relative to contents_size).
Definition: fs_api.h:379
char * emsg
Error message (non-NULL if this operation failed).
Definition: fs_api.h:297
struct GNUNET_FS_BlockOptions bo
Block options for the file.
Definition: fs_api.h:275
int is_published
Are we done publishing this file?
Definition: fs_api.h:396
struct GNUNET_FS_MetaData * meta
Metadata to use for the file.
Definition: fs_api.h:253
struct GNUNET_FS_Uri * sks_uri
SKS URI for this file or directory.
Definition: fs_api.h:270
void * dir_data
Pointer to the data for the directory (or NULL if not available).
Definition: fs_api.h:374
uint64_t contents_size
Sum of all of the sizes of all of the files in the directory.
Definition: fs_api.h:384
struct GNUNET_FS_Handle * h
Handle to the master context.
Definition: fs_api.h:243
struct GNUNET_TIME_Absolute start_time
At what time did we start this upload?
Definition: fs_api.h:280
struct GNUNET_FS_FileInformation * entries
Linked list of entries in the directory.
Definition: fs_api.h:362
struct GNUNET_FS_Uri * chk_uri
CHK for this file or directory.
Definition: fs_api.h:264
int is_directory
Is this struct for a file or directory?
Definition: fs_api.h:391
uint64_t abs_value_us
The actual value.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_FS_BlockOptions::anonymity_level, GNUNET_FS_FileInformation::bo, GNUNET_FS_FileInformation::chk_uri, cleanup(), GNUNET_FS_BlockOptions::content_priority, GNUNET_FS_FileInformation::contents_completed, GNUNET_FS_FileInformation::contents_size, copy_from_reader(), GNUNET_FS_FileInformation::data, GNUNET_FS_FileInformation::dir, GNUNET_FS_FileInformation::dir_data, GNUNET_FS_FileInformation::dir_size, GNUNET_FS_FileInformation::emsg, GNUNET_FS_FileInformation::entries, GNUNET_FS_BlockOptions::expiration_time, GNUNET_FS_FileInformation::file, GNUNET_FS_FileInformation::filename, get_serialization_file_name(), get_write_handle(), GNUNET_assert, GNUNET_BIO_write(), GNUNET_BIO_write_close(), GNUNET_BIO_write_int64(), GNUNET_BIO_write_spec_commit(), GNUNET_BIO_write_spec_end, GNUNET_BIO_write_spec_int32(), GNUNET_BIO_write_spec_int64(), GNUNET_BIO_write_spec_object(), GNUNET_BIO_write_spec_string(), GNUNET_BIO_write_string(), GNUNET_break, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_FS_SYNC_PATH_FILE_INFO, GNUNET_FS_uri_to_string(), GNUNET_FS_write_spec_meta_data(), GNUNET_log_strerror_file, GNUNET_NO, GNUNET_OK, GNUNET_YES, GNUNET_FS_FileInformation::h, GNUNET_FS_FileInformation::is_directory, GNUNET_FS_FileInformation::is_published, GNUNET_FS_FileInformation::keywords, make_serialization_file_name(), GNUNET_FS_FileInformation::meta, GNUNET_FS_FileInformation::next, GNUNET_FS_BlockOptions::replication_level, GNUNET_FS_FileInformation::serialization, GNUNET_FS_FileInformation::sks_uri, GNUNET_FS_FileInformation::start_time, wh, and write_start_time().

Referenced by encode_cont(), fip_signal_start(), GNUNET_FS_publish_main_(), handle_index_start_failed(), handle_index_start_ok(), handle_signature_response(), hash_for_index_cb(), index_mq_error_handler(), publish_content(), and publish_kblocks_cont().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_file_position()

static struct GNUNET_FS_FileInformation* find_file_position ( struct GNUNET_FS_FileInformation pos,
const char *  srch 
)
static

Find the entry in the file information struct where the serialization filename matches the given name.

Parameters
posfile information to search
srchfilename to search for
Returns
NULL if srch was not found in this subtree

Definition at line 1540 of file fs_api.c.

1541 {
1542  struct GNUNET_FS_FileInformation *r;
1543 
1544  while (NULL != pos)
1545  {
1546  if (0 == strcmp (srch, pos->serialization))
1547  return pos;
1548  if ((GNUNET_YES == pos->is_directory) &&
1549  (NULL != (r = find_file_position (pos->data.dir.entries, srch))))
1550  return r;
1551  pos = pos->next;
1552  }
1553  return NULL;
1554 }
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:1540

References GNUNET_FS_FileInformation::data, GNUNET_FS_FileInformation::dir, GNUNET_FS_FileInformation::entries, GNUNET_YES, GNUNET_FS_FileInformation::is_directory, GNUNET_FS_FileInformation::next, and GNUNET_FS_FileInformation::serialization.

Referenced by deserialize_publish_file().

Here is the caller graph for this function:

◆ fip_signal_resume()

static int fip_signal_resume ( void *  cls,
struct GNUNET_FS_FileInformation fi,
uint64_t  length,
struct GNUNET_FS_MetaData meta,
struct GNUNET_FS_Uri **  uri,
struct GNUNET_FS_BlockOptions bo,
int *  do_index,
void **  client_info 
)
static

Signal the FS's progress function that we are resuming an upload.

Parameters
clsclosure (of type struct GNUNET_FS_PublishContext *, for the parent (!))
fithe entry in the publish-structure
lengthlength of the file or directory
metametadata for the file or directory (can be modified)
uripointer to the keywords that will be used for this entry (can be modified)
boblock options (can be modified)
do_indexshould we index?
client_infopointer to client context set upon creation (can be modified)
Returns
GNUNET_OK to continue (always)

Definition at line 1572 of file fs_api.c.

1580 {
1581  struct GNUNET_FS_PublishContext *pc = cls;
1582  struct GNUNET_FS_ProgressInfo pi;
1583 
1585  {
1587  return GNUNET_OK;
1588  }
1590  pi.value.publish.specifics.resume.message = fi->emsg;
1591  pi.value.publish.specifics.resume.chk_uri = fi->chk_uri;
1592  *client_info = GNUNET_FS_publish_make_status_ (&pi, pc, fi, 0);
1594  {
1595  /* process entries in directory */
1598  }
1599  return GNUNET_OK;
1600 }
static int fip_signal_resume(void *cls, struct GNUNET_FS_FileInformation *fi, uint64_t length, struct GNUNET_FS_MetaData *meta, struct GNUNET_FS_Uri **uri, struct GNUNET_FS_BlockOptions *bo, int *do_index, void **client_info)
Signal the FS's progress function that we are resuming an upload.
Definition: fs_api.c:1572
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:48
static struct GNUNET_PEERINFO_Handle * pi
Handle to peerinfo service.
static struct GNUNET_FS_MetaData * meta
Meta-data provided via command-line option.
static struct GNUNET_FS_PublishContext * pc
Handle to FS-publishing operation.
void GNUNET_FS_file_information_inspect(struct GNUNET_FS_FileInformation *dir, GNUNET_FS_FileInformationProcessor proc, void *proc_cls)
Inspect a file or directory in a publish-structure.
int GNUNET_FS_meta_data_test_for_directory(const struct GNUNET_FS_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:55
@ GNUNET_FS_STATUS_PUBLISH_RESUME
Notification that we have resumed sharing a file structure.
Argument given to the progress callback with information about what is going on.
const struct GNUNET_FS_FileInformation * fi
Information about the file that is being published.
Handle for controlling a publication process.
Definition: fs_api.h:1180
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:1299

References GNUNET_FS_FileInformation::chk_uri, GNUNET_FS_FileInformation::emsg, GNUNET_FS_ProgressInfo::fi, GNUNET_FS_file_information_inspect(), GNUNET_FS_meta_data_test_for_directory(), GNUNET_FS_publish_make_status_(), GNUNET_FS_STATUS_PUBLISH_RESUME, GNUNET_NO, GNUNET_OK, GNUNET_YES, meta, pc, pi, and GNUNET_FS_PublishContext::skip_next_fi_callback.

Referenced by deserialize_publish_file().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ deserialize_publish_file()

static int deserialize_publish_file ( void *  cls,
const char *  filename 
)
static

Function called with a filename of serialized publishing operation to deserialize.

Parameters
clsthe struct GNUNET_FS_Handle *
filenamecomplete filename (absolute path)
Returns
GNUNET_OK (continue to iterate)

Definition at line 1612 of file fs_api.c.

1613 {
1614  struct GNUNET_FS_Handle *h = cls;
1615  struct GNUNET_BIO_ReadHandle *rh;
1616  struct GNUNET_FS_PublishContext *pc;
1617  int32_t options;
1618  int32_t all_done;
1619  int32_t have_ns;
1620  char *fi_root;
1622  char *fi_pos;
1623  char *emsg;
1624 
1626  pc->h = h;
1628  fi_root = NULL;
1629  fi_pos = NULL;
1631  if (NULL == rh)
1632  {
1633  GNUNET_break (0);
1634  goto cleanup;
1635  }
1636  struct GNUNET_BIO_ReadSpec rs[] = {
1637  GNUNET_BIO_read_spec_string ("publish-nid", &pc->nid, 1024),
1638  GNUNET_BIO_read_spec_string ("publish-nuid", &pc->nuid, 1024),
1639  GNUNET_BIO_read_spec_int32 ("options", &options),
1640  GNUNET_BIO_read_spec_int32 ("all done", &all_done),
1641  GNUNET_BIO_read_spec_int32 ("have ns", &have_ns),
1642  GNUNET_BIO_read_spec_string ("publish-firoot", &fi_root, 128),
1643  GNUNET_BIO_read_spec_string ("publish-fipos", &fi_pos, 128),
1645  };
1646  if ((GNUNET_OK != GNUNET_BIO_read_spec_commit (rh, rs)) ||
1647  ((GNUNET_YES == have_ns) &&
1648  (GNUNET_OK != GNUNET_BIO_read (rh, "publish-ns", &ns, sizeof(ns)))))
1649  {
1650  GNUNET_break (0);
1651  goto cleanup;
1652  }
1653  pc->options = options;
1654  pc->all_done = all_done;
1655  if (NULL == fi_root)
1656  {
1657  GNUNET_break (0);
1658  goto cleanup;
1659  }
1660  pc->fi = deserialize_file_information (h, fi_root);
1661  if (NULL == pc->fi)
1662  {
1663  GNUNET_break (0);
1664  goto cleanup;
1665  }
1666  if (GNUNET_YES == have_ns)
1667  {
1669  *pc->ns = ns;
1670  }
1672  (GNUNET_YES != pc->all_done))
1673  {
1675  if (NULL == pc->dsh)
1676  goto cleanup;
1677  }
1678  if (NULL != fi_pos)
1679  {
1680  pc->fi_pos = find_file_position (pc->fi, fi_pos);
1681  GNUNET_free (fi_pos);
1682  fi_pos = NULL;
1683  if (NULL == pc->fi_pos)
1684  {
1685  /* failed to find position for resuming, outch! Will start from root! */
1686  GNUNET_break (0);
1687  if (GNUNET_YES != pc->all_done)
1688  pc->fi_pos = pc->fi;
1689  }
1690  }
1691  GNUNET_free (fi_root);
1692  fi_root = NULL;
1693  /* generate RESUME event(s) */
1695 
1696  /* re-start publishing (if needed)... */
1697  if (GNUNET_YES != pc->all_done)
1698  {
1699  GNUNET_assert (NULL == pc->upload_task);
1700  pc->upload_task =
1703  pc);
1704  }
1705  if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
1706  {
1708  _ ("Failure while resuming publishing operation `%s': %s\n"),
1709  filename,
1710  emsg);
1711  GNUNET_free (emsg);
1712  }
1714  return GNUNET_OK;
1715 cleanup:
1716  GNUNET_free (pc->nid);
1717  GNUNET_free (pc->nuid);
1718  GNUNET_free (fi_root);
1719  GNUNET_free (fi_pos);
1720  if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)))
1721  {
1723  _ ("Failed to resume publishing operation `%s': %s\n"),
1724  filename,
1725  emsg);
1726  GNUNET_free (emsg);
1727  }
1728  if (NULL != pc->fi)
1729  GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL);
1730  if (0 != unlink (filename))
1733  GNUNET_free (pc);
1734  return GNUNET_OK;
1735 }
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
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:381
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:1355
void GNUNET_FS_publish_main_(void *cls)
Main function that performs the upload.
Definition: fs_publish.c:1063
static struct GNUNET_NAMESTORE_Handle * ns
Handle to the namestore.
Definition: gnunet-abd.c:41
struct GNUNET_BIO_ReadSpec GNUNET_BIO_read_spec_string(const char *what, char **result, size_t max_length)
Create the specification to read a 0-terminated string.
Definition: bio.c:957
enum GNUNET_GenericReturnValue GNUNET_BIO_read_spec_commit(struct GNUNET_BIO_ReadHandle *h, struct GNUNET_BIO_ReadSpec *rs)
Execute the read specifications in order.
Definition: bio.c:1109
#define GNUNET_BIO_read_spec_end()
End of specifications marker.
struct GNUNET_BIO_ReadSpec GNUNET_BIO_read_spec_int32(const char *what, int32_t *i)
Create the specification to read an (u)int32_t.
Definition: bio.c:1002
struct GNUNET_DATASTORE_Handle * GNUNET_DATASTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the datastore service.
@ GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY
Simulate publishing.
@ GNUNET_SCHEDULER_PRIORITY_BACKGROUND
Run as background job (higher than idle, lower than default).
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:1226
Structure specifying a reading operation on an IO handle.
GNUNET_BIO_ReadHandler rh
Function performing data deserialization.
Private ECC key encoded for transmission.
enum GNUNET_FS_PublishOptions options
Options for publishing.
Definition: fs_api.h:1275
struct GNUNET_DATASTORE_Handle * dsh
Connection to the datastore service.
Definition: fs_api.h:1236
struct TopLevelActivity * top
Our top-level activity entry (if we are top-level, otherwise NULL).
Definition: fs_api.h:1189
struct GNUNET_FS_FileInformation * fi_pos
Current position in the file-tree for the upload.
Definition: fs_api.h:1226
char * nuid
ID for future updates, NULL if we have no namespace or no updates.
Definition: fs_api.h:1209
int all_done
Set to GNUNET_YES if all processing has completed.
Definition: fs_api.h:1292
struct GNUNET_FS_FileInformation * fi
File-structure that is being shared.
Definition: fs_api.h:1194
char * nid
ID of the content in the namespace, NULL if we have no namespace.
Definition: fs_api.h:1204
struct GNUNET_FS_Handle * h
Handle to the global fs context.
Definition: fs_api.h:1184
struct GNUNET_CRYPTO_EcdsaPrivateKey * ns
Namespace that we are publishing in, NULL if we have no namespace.
Definition: fs_api.h:1199
struct GNUNET_SCHEDULER_Task * upload_task
ID of the task performing the upload.
Definition: fs_api.h:1259
char * serialization
Filename used for serializing information about this operation (should be determined using 'mktemp').
Definition: fs_api.h:1215

References _, GNUNET_FS_PublishContext::all_done, GNUNET_ARM_Handle::cfg, cleanup(), deserialize_file_information(), GNUNET_FS_PublishContext::dsh, GNUNET_FS_PublishContext::fi, GNUNET_FS_PublishContext::fi_pos, filename, find_file_position(), fip_signal_resume(), get_serialization_short_name(), GNUNET_assert, GNUNET_BIO_read(), GNUNET_BIO_read_close(), GNUNET_BIO_read_open_file(), GNUNET_BIO_read_spec_commit(), GNUNET_BIO_read_spec_end, GNUNET_BIO_read_spec_int32(), GNUNET_BIO_read_spec_string(), GNUNET_break, GNUNET_DATASTORE_connect(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_FS_file_information_destroy(), GNUNET_FS_file_information_inspect(), GNUNET_FS_make_top(), GNUNET_FS_publish_main_(), GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY, GNUNET_FS_publish_signal_suspend_(), GNUNET_log, GNUNET_log_strerror_file, GNUNET_new, GNUNET_OK, GNUNET_SCHEDULER_add_with_priority(), GNUNET_SCHEDULER_PRIORITY_BACKGROUND, GNUNET_YES, h, GNUNET_FS_PublishContext::h, GNUNET_FS_PublishContext::nid, ns, GNUNET_FS_PublishContext::ns, GNUNET_FS_PublishContext::nuid, options, GNUNET_FS_PublishContext::options, pc, GNUNET_BIO_ReadSpec::rh, GNUNET_FS_PublishContext::serialization, GNUNET_FS_PublishContext::top, and GNUNET_FS_PublishContext::upload_task.

Referenced by GNUNET_FS_start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_FS_publish_sync_()

void GNUNET_FS_publish_sync_ ( struct GNUNET_FS_PublishContext pc)

Synchronize this publishing struct with its mirror on disk.

Note that all internal FS-operations that change publishing structs should already call "sync" internally, so this function is likely not useful for clients.

Parameters
pcthe struct to sync

Definition at line 1747 of file fs_api.c.

1748 {
1749  struct GNUNET_BIO_WriteHandle *wh;
1750  int32_t have_ns;
1751 
1752  if (NULL == pc->serialization)
1753  pc->serialization =
1755  if (NULL == pc->serialization)
1756  return;
1757  if (NULL == pc->fi)
1758  return;
1759  if (NULL == pc->fi->serialization)
1760  {
1761  GNUNET_break (0);
1762  return;
1763  }
1764  wh = get_write_handle (pc->h,
1766  pc->serialization);
1767  if (NULL == wh)
1768  {
1769  GNUNET_break (0);
1770  goto cleanup;
1771  }
1772  have_ns = (NULL != pc->ns) ? GNUNET_YES : GNUNET_NO;
1773  struct GNUNET_BIO_WriteSpec ws[] = {
1776  GNUNET_BIO_write_spec_int32 ("options", (int32_t *) &pc->options),
1777  GNUNET_BIO_write_spec_int32 ("all done", &pc->all_done),
1778  GNUNET_BIO_write_spec_int32 ("have ns", &have_ns),
1779  GNUNET_BIO_write_spec_string ("serialization", pc->fi->serialization),
1780  GNUNET_BIO_write_spec_string ("pos serialization", (NULL == pc->fi_pos)
1781  ? NULL
1782  : pc->fi_pos->serialization),
1784  };
1785  if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws)) ||
1786  ((NULL != pc->ns) &&
1787  (GNUNET_OK !=
1789  "ns",
1790  pc->ns,
1791  sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey)))))
1792  {
1793  GNUNET_break (0);
1794  goto cleanup;
1795  }
1796  if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
1797  {
1798  wh = NULL;
1799  GNUNET_break (0);
1800  goto cleanup;
1801  }
1802  return;
1803 cleanup:
1804  if (NULL != wh)
1805  (void) GNUNET_BIO_write_close (wh, NULL);
1808  pc->serialization);
1810  pc->serialization = NULL;
1811 }
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:728
#define GNUNET_FS_SYNC_PATH_MASTER_PUBLISH
Name of the directory with publishing operations.
Definition: fs_api.h:77

References GNUNET_FS_PublishContext::all_done, cleanup(), GNUNET_FS_PublishContext::fi, GNUNET_FS_PublishContext::fi_pos, get_write_handle(), GNUNET_BIO_read_spec_end, GNUNET_BIO_write(), GNUNET_BIO_write_close(), GNUNET_BIO_write_spec_commit(), GNUNET_BIO_write_spec_int32(), GNUNET_BIO_write_spec_string(), GNUNET_break, GNUNET_free, GNUNET_FS_remove_sync_file_(), GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, GNUNET_NO, GNUNET_OK, GNUNET_YES, GNUNET_FS_PublishContext::h, make_serialization_file_name(), GNUNET_FS_PublishContext::nid, GNUNET_FS_PublishContext::ns, GNUNET_FS_PublishContext::nuid, GNUNET_FS_PublishContext::options, pc, GNUNET_FS_FileInformation::serialization, GNUNET_FS_PublishContext::serialization, and wh.

Referenced by finish_release_reserve(), GNUNET_FS_publish_main_(), GNUNET_FS_publish_start(), handle_index_start_failed(), handle_signature_response(), publish_kblocks_cont(), and publish_sblocks_cont().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_FS_unindex_sync_()

void GNUNET_FS_unindex_sync_ ( struct GNUNET_FS_UnindexContext uc)

Synchronize this unindex struct with its mirror on disk.

Note that all internal FS-operations that change publishing structs should already call "sync" internally, so this function is likely not useful for clients.

Parameters
ucthe struct to sync

Definition at line 1823 of file fs_api.c.

1824 {
1825  struct GNUNET_BIO_WriteHandle *wh;
1826  char *uris;
1827 
1828  if (NULL == uc->serialization)
1829  uc->serialization =
1831  if (NULL == uc->serialization)
1832  return;
1833  wh = get_write_handle (uc->h,
1835  uc->serialization);
1836  if (NULL == wh)
1837  {
1838  GNUNET_break (0);
1839  goto cleanup;
1840  }
1841  if (NULL != uc->ksk_uri)
1843  else
1844  uris = NULL;
1845  struct GNUNET_BIO_WriteSpec ws1[] = {
1846  GNUNET_BIO_write_spec_string ("filename", uc->filename),
1847  GNUNET_BIO_write_spec_int64 ("file size", (int64_t *) &uc->file_size),
1849  };
1850  struct GNUNET_BIO_WriteSpec ws2[] = {
1851  GNUNET_BIO_write_spec_int32 ("state", (int32_t *) &uc->state),
1852  GNUNET_BIO_write_spec_object ("hashkey", &uc->chk,
1853  sizeof (struct ContentHashKey)),
1854  GNUNET_BIO_write_spec_string ("uris", uris),
1855  GNUNET_BIO_write_spec_int32 ("ksk offset", (int32_t *) &uc->ksk_offset),
1857  };
1858  if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws1)) ||
1861  ((uc->state == UNINDEX_STATE_FS_NOTIFY) &&
1863  "file id",
1864  &uc->file_id,
1865  sizeof(struct GNUNET_HashCode)))) ||
1866  ((uc->state == UNINDEX_STATE_ERROR) &&
1867  (GNUNET_OK != GNUNET_BIO_write_string (wh, "emsg", uc->emsg))))
1868  {
1869  GNUNET_break (0);
1870  goto cleanup;
1871  }
1872  if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
1873  {
1874  wh = NULL;
1875  GNUNET_break (0);
1876  goto cleanup;
1877  }
1878  return;
1879 cleanup:
1880  if (NULL != wh)
1881  (void) GNUNET_BIO_write_close (wh, NULL);
1884  uc->serialization);
1886  uc->serialization = NULL;
1887 }
@ UNINDEX_STATE_ERROR
We've encountered a fatal error.
Definition: fs_api.h:1343
@ UNINDEX_STATE_FS_NOTIFY
We're notifying the FS service about the unindexing.
Definition: fs_api.h:1333
#define GNUNET_FS_SYNC_PATH_MASTER_UNINDEX
Name of the directory with unindex operations.
Definition: fs_api.h:87
static struct GNUNET_FS_UnindexContext * uc
content hash key
Definition: fs.h:55
enum UnindexState state
Current operatinonal phase.
Definition: fs_api.h:1464
char * emsg
Error message, NULL on success.
Definition: fs_api.h:1439
struct GNUNET_TIME_Absolute start_time
When did we start?
Definition: fs_api.h:1454
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:1356
char * filename
Name of the file that we are unindexing.
Definition: fs_api.h:1386
struct GNUNET_FS_Handle * h
Global FS context.
Definition: fs_api.h:1361
uint32_t ksk_offset
Current offset in KSK removal.
Definition: fs_api.h:1381
char * serialization
Short name under which we are serializing the state of this operation.
Definition: fs_api.h:1391
struct GNUNET_FS_Uri * ksk_uri
Keywords found (telling us which KBlocks to remove).
Definition: fs_api.h:1376
struct GNUNET_HashCode file_id
Hash of the file's contents (once computed).
Definition: fs_api.h:1459
uint64_t file_size
Overall size of the file.
Definition: fs_api.h:1449

References GNUNET_FS_UnindexContext::chk, cleanup(), GNUNET_FS_UnindexContext::emsg, GNUNET_FS_UnindexContext::file_id, GNUNET_FS_UnindexContext::file_size, GNUNET_FS_UnindexContext::filename, get_write_handle(), GNUNET_BIO_write(), GNUNET_BIO_write_close(), GNUNET_BIO_write_spec_commit(), GNUNET_BIO_write_spec_end, GNUNET_BIO_write_spec_int32(), GNUNET_BIO_write_spec_int64(), GNUNET_BIO_write_spec_object(), GNUNET_BIO_write_spec_string(), GNUNET_BIO_write_string(), GNUNET_break, GNUNET_free, GNUNET_FS_remove_sync_file_(), GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, GNUNET_FS_uri_to_string(), GNUNET_OK, GNUNET_FS_UnindexContext::h, GNUNET_FS_UnindexContext::ksk_offset, GNUNET_FS_UnindexContext::ksk_uri, make_serialization_file_name(), GNUNET_FS_UnindexContext::serialization, GNUNET_FS_UnindexContext::start_time, GNUNET_FS_UnindexContext::state, uc, UNINDEX_STATE_ERROR, UNINDEX_STATE_FS_NOTIFY, wh, and write_start_time().

Referenced by GNUNET_FS_unindex_do_remove_(), GNUNET_FS_unindex_do_remove_kblocks_(), GNUNET_FS_unindex_process_hash_(), GNUNET_FS_unindex_start(), handle_unindex_response(), unindex_directory_scan_cb(), unindex_extract_keywords(), unindex_finish(), and unindex_mq_error_handler().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_download_request()

static int write_download_request ( struct GNUNET_BIO_WriteHandle wh,
struct DownloadRequest dr 
)
static

Serialize a download request.

Parameters
whhandle for writing the download request to disk
drthe the request to write to disk
Returns
GNUNET_YES on success, GNUNET_NO on error

Definition at line 1898 of file fs_api.c.

1900 {
1901  unsigned int i;
1902  struct GNUNET_BIO_WriteSpec ws[] = {
1903  GNUNET_BIO_write_spec_int32 ("state", (int32_t *) &dr->state),
1904  GNUNET_BIO_write_spec_int64 ("offset", (int64_t *) &dr->offset),
1905  GNUNET_BIO_write_spec_int32 ("num children", (int32_t *) &dr->num_children),
1906  GNUNET_BIO_write_spec_int32 ("depth", (int32_t *) &dr->depth),
1908  };
1909 
1910  if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws)))
1911  return GNUNET_NO;
1912  if ((BRS_CHK_SET == dr->state) &&
1913  (GNUNET_OK !=
1914  GNUNET_BIO_write (wh, "hashkey",
1915  &dr->chk, sizeof(struct ContentHashKey))))
1916  return GNUNET_NO;
1917  for (i = 0; i < dr->num_children; i++)
1918  if (GNUNET_NO == write_download_request (wh, dr->children[i]))
1919  return GNUNET_NO;
1920  return GNUNET_YES;
1921 }
static int write_download_request(struct GNUNET_BIO_WriteHandle *wh, struct DownloadRequest *dr)
Serialize a download request.
Definition: fs_api.c:1898
@ BRS_CHK_SET
We've determined the real, desired CHK for this block (full tree reconstruction failed),...
Definition: fs_api.h:1646
struct DownloadRequest ** children
Array (!) of child-requests, or NULL for the bottom of the tree.
Definition: fs_api.h:1685
unsigned int num_children
Number of entries in children array.
Definition: fs_api.h:1703
uint64_t offset
Offset of the corresponding block.
Definition: fs_api.h:1698
enum BlockRequestState state
State in the FSM.
Definition: fs_api.h:1718
unsigned int depth
Depth of the corresponding block in the tree.
Definition: fs_api.h:1708
struct ContentHashKey chk
CHK for the request for this block (set during reconstruction to what we have on disk,...
Definition: fs_api.h:1691

References BRS_CHK_SET, DownloadRequest::children, DownloadRequest::chk, DownloadRequest::depth, GNUNET_BIO_write(), GNUNET_BIO_write_spec_commit(), GNUNET_BIO_write_spec_end, GNUNET_BIO_write_spec_int32(), GNUNET_BIO_write_spec_int64(), GNUNET_NO, GNUNET_OK, GNUNET_YES, DownloadRequest::num_children, DownloadRequest::offset, DownloadRequest::state, and wh.

Referenced by GNUNET_FS_download_sync_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_download_request()

static struct DownloadRequest* read_download_request ( struct GNUNET_BIO_ReadHandle rh)
static

Read a download request tree.

Parameters
rhcadet to read from
Returns
value the download request read from disk, NULL on error

Definition at line 1931 of file fs_api.c.

1932 {
1933  struct DownloadRequest *dr;
1934  unsigned int i;
1935 
1936  dr = GNUNET_new (struct DownloadRequest);
1937  struct GNUNET_BIO_ReadSpec rs[] = {
1938  GNUNET_BIO_read_spec_int32 ("state", (int32_t *) &dr->state),
1939  GNUNET_BIO_read_spec_int64 ("offset", (int64_t *) &dr->offset),
1940  GNUNET_BIO_read_spec_int32 ("num children", (int32_t *) &dr->num_children),
1942  };
1943  if ((GNUNET_OK != GNUNET_BIO_read_spec_commit (rh, rs)) ||
1944  (dr->num_children > CHK_PER_INODE) ||
1945  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "depth",
1946  (int32_t *) &dr->depth)) ||
1947  ((0 == dr->depth) && (dr->num_children > 0)) ||
1948  ((dr->depth > 0) && (0 == dr->num_children)))
1949  {
1950  GNUNET_break (0);
1951  dr->num_children = 0;
1952  goto cleanup;
1953  }
1954  if (dr->num_children > 0)
1955  dr->children =
1956  GNUNET_malloc (dr->num_children * sizeof(struct DownloadRequest *));
1957  switch (dr->state)
1958  {
1959  case BRS_INIT:
1960  case BRS_RECONSTRUCT_DOWN:
1962  case BRS_RECONSTRUCT_UP:
1963  break;
1964 
1965  case BRS_CHK_SET:
1966  if (GNUNET_OK !=
1967  GNUNET_BIO_read (rh, "chk", &dr->chk, sizeof(struct ContentHashKey)))
1968  goto cleanup;
1969  break;
1970 
1971  case BRS_DOWNLOAD_DOWN:
1972  case BRS_DOWNLOAD_UP:
1973  case BRS_ERROR:
1974  break;
1975 
1976  default:
1977  GNUNET_break (0);
1978  goto cleanup;
1979  }
1980  for (i = 0; i < dr->num_children; i++)
1981  {
1982  if (NULL == (dr->children[i] = read_download_request (rh)))
1983  goto cleanup;
1984  dr->children[i]->parent = dr;
1985  }
1986  return dr;
1987 cleanup:
1989  return NULL;
1990 }
static struct DownloadRequest * read_download_request(struct GNUNET_BIO_ReadHandle *rh)
Read a download request tree.
Definition: fs_api.c:1931
@ BRS_DOWNLOAD_UP
This block and all of its children have been downloaded successfully (full completion propagates up).
Definition: fs_api.h:1661
@ BRS_RECONSTRUCT_META_UP
We've calculated the CHK bottom-up based on the meta data.
Definition: fs_api.h:1629
@ BRS_ERROR
We got a block back that matched the query but did not hash to the key (malicious publisher or hash c...
Definition: fs_api.h:1668
@ BRS_RECONSTRUCT_DOWN
We've checked the block on the path down the tree, and the content on disk did match the desired CHK,...
Definition: fs_api.h:1621
@ BRS_INIT
Initial state, block has only been allocated (since it is relevant to the overall download request).
Definition: fs_api.h:1613
@ BRS_DOWNLOAD_DOWN
We've successfully downloaded this block, but the children still need to be either downloaded or veri...
Definition: fs_api.h:1655
@ BRS_RECONSTRUCT_UP
We've calculated the CHK bottom-up based on what we have on disk, which may not be what the desired C...
Definition: fs_api.h:1637
void GNUNET_FS_free_download_request_(struct DownloadRequest *dr)
(recursively) free download request structure
Definition: fs_download.c:997
#define CHK_PER_INODE
Pick a multiple of 2 here to achieve 8-byte alignment! We also probably want DBlocks to have (roughly...
Definition: fs_api.h:44
struct GNUNET_BIO_ReadSpec GNUNET_BIO_read_spec_int64(const char *what, int64_t *i)
Create the specification to read an (u)int64_t.
Definition: bio.c:1046
#define GNUNET_malloc(size)
Wrapper around malloc.
Information about an active download request.
Definition: fs_api.h:1676
struct DownloadRequest * parent
Parent in the CHK-tree.
Definition: fs_api.h:1680

References BRS_CHK_SET, BRS_DOWNLOAD_DOWN, BRS_DOWNLOAD_UP, BRS_ERROR, BRS_INIT, BRS_RECONSTRUCT_DOWN, BRS_RECONSTRUCT_META_UP, BRS_RECONSTRUCT_UP, DownloadRequest::children, DownloadRequest::chk, CHK_PER_INODE, cleanup(), DownloadRequest::depth, GNUNET_BIO_read(), GNUNET_BIO_read_int32(), GNUNET_BIO_read_spec_commit(), GNUNET_BIO_read_spec_end, GNUNET_BIO_read_spec_int32(), GNUNET_BIO_read_spec_int64(), GNUNET_break, GNUNET_FS_free_download_request_(), GNUNET_malloc, GNUNET_new, GNUNET_OK, DownloadRequest::num_children, DownloadRequest::offset, DownloadRequest::parent, GNUNET_BIO_ReadSpec::rh, and DownloadRequest::state.

Referenced by deserialize_download().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_download_sync_filename()

static char* get_download_sync_filename ( struct GNUNET_FS_DownloadContext dc,
const char *  uni,
const char *  ext 
)
static

Compute the name of the sync file (or directory) for the given download context.

Parameters
dcdownload context to compute for
uniunique filename to use, use "" for the directory name
extextension to use, use ".dir" for our own subdirectory
Returns
the expanded file name, NULL for none

Definition at line 2003 of file fs_api.c.

2006 {
2007  char *par;
2008  char *epar;
2009 
2010  if (dc->parent == NULL)
2011  return get_serialization_file_name (dc->h,
2012  (dc->search != NULL)
2015  uni);
2016  if (NULL == dc->parent->serialization)
2017  return NULL;
2019  if (NULL == par)
2020  return NULL;
2021  GNUNET_asprintf (&epar, "%s.dir%s%s%s", par, DIR_SEPARATOR_STR, uni, ext);
2022  GNUNET_free (par);
2023  return epar;
2024 }
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:2003
#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:66
#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:72
static struct GNUNET_FS_DownloadContext * dc
struct GNUNET_FS_SearchResult * search
Associated search (used when downloading files based on search results), or NULL for none.
Definition: fs_api.h:1770
char * serialization
Random portion of filename we use for syncing state of this download.
Definition: fs_api.h:1816
struct GNUNET_FS_DownloadContext * parent
Parent download (used when downloading files in directories).
Definition: fs_api.h:1764
struct GNUNET_FS_Handle * h
Global FS context.
Definition: fs_api.h:1748

References dc, DIR_SEPARATOR_STR, get_serialization_file_name(), GNUNET_asprintf(), GNUNET_free, GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD, GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, GNUNET_FS_DownloadContext::h, GNUNET_FS_DownloadContext::parent, GNUNET_FS_DownloadContext::search, and GNUNET_FS_DownloadContext::serialization.

Referenced by deserialize_download(), and GNUNET_FS_download_sync_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_FS_download_sync_()

void GNUNET_FS_download_sync_ ( struct GNUNET_FS_DownloadContext dc)

Synchronize this download struct with its mirror on disk.

Note that all internal FS-operations that change publishing structs should already call "sync" internally, so this function is likely not useful for clients.

Parameters
dcthe struct to sync

Definition at line 2036 of file fs_api.c.

2037 {
2038  struct GNUNET_BIO_WriteHandle *wh;
2039  char *uris;
2040  char *fn;
2041  char *dir;
2042 
2043  if (0 != (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE))
2044  return; /* we don't sync probes */
2045  if (NULL == dc->serialization)
2046  {
2047  dir = get_download_sync_filename (dc, "", "");
2048  if (NULL == dir)
2049  return;
2051  {
2052  GNUNET_free (dir);
2053  return;
2054  }
2055  fn = GNUNET_DISK_mktemp (dir);
2056  GNUNET_free (dir);
2057  if (NULL == fn)
2058  return;
2060  }
2061  else
2062  {
2064  if (NULL == fn)
2065  {
2067  dc->serialization = NULL;
2068  GNUNET_free (fn);
2069  return;
2070  }
2071  }
2073  if (NULL == wh)
2074  {
2076  dc->serialization = NULL;
2077  GNUNET_free (fn);
2078  return;
2079  }
2082  uris = GNUNET_FS_uri_to_string (dc->uri);
2083  struct GNUNET_BIO_WriteSpec ws1[] = {
2084  GNUNET_BIO_write_spec_string ("uris", uris),
2085  GNUNET_FS_write_spec_meta_data ("metadata", dc->meta),
2087  GNUNET_BIO_write_spec_string ("filename", dc->filename),
2088  GNUNET_BIO_write_spec_string ("temp filename", dc->temp_filename),
2089  GNUNET_BIO_write_spec_int64 ("old file size",
2090  (int64_t *) &dc->old_file_size),
2091  GNUNET_BIO_write_spec_int64 ("offset", (int64_t *) &dc->offset),
2092  GNUNET_BIO_write_spec_int64 ("length", (int64_t *) &dc->length),
2093  GNUNET_BIO_write_spec_int64 ("completed", (int64_t *) &dc->completed),
2095  };
2096  struct GNUNET_BIO_WriteSpec ws2[] = {
2097  GNUNET_BIO_write_spec_int32 ("anonymity", (int32_t *) &dc->anonymity),
2098  GNUNET_BIO_write_spec_int32 ("options", (int32_t *) &dc->options),
2099  GNUNET_BIO_write_spec_int32 ("has finished", (int32_t *) &dc->has_finished),
2101  };
2102  if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws1)) ||
2105  {
2106  GNUNET_break (0);
2107  goto cleanup;
2108  }
2109  if (NULL == dc->emsg)
2110  {
2111  GNUNET_assert (dc->top_request != NULL);
2113  {
2114  GNUNET_break (0);
2115  goto cleanup;
2116  }
2117  }
2118  GNUNET_free (uris);
2119  uris = NULL;
2120  if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
2121  {
2122  wh = NULL;
2123  GNUNET_break (0);
2124  goto cleanup;
2125  }
2126  GNUNET_free (fn);
2127  return;
2128 cleanup:
2129  if (NULL != wh)
2130  (void) GNUNET_BIO_write_close (wh, NULL);
2131  GNUNET_free (uris);
2132  if (0 != unlink (fn))
2134  GNUNET_free (fn);
2136  dc->serialization = NULL;
2137 }
static char * dir
Set to the directory where runtime files are stored.
Definition: gnunet-arm.c:89
int GNUNET_FS_uri_test_loc(const struct GNUNET_FS_Uri *uri)
Is this a location URI?
Definition: fs_uri.c:1384
@ GNUNET_FS_DOWNLOAD_IS_PROBE
Internal option used to flag this download as a 'probe' for a search result.
int has_finished
Flag set upon transitive completion (includes child downloads).
Definition: fs_api.h:1930
char * filename
Where are we writing the data (name of the file, can be NULL!).
Definition: fs_api.h:1822
struct GNUNET_FS_Uri * uri
URI that identifies the file that we are downloading.
Definition: fs_api.h:1800
struct GNUNET_FS_MetaData * meta
Known meta-data for the file (can be NULL).
Definition: fs_api.h:1805
uint64_t old_file_size
What was the size of the file on disk that we're downloading before we started? Used to detect if the...
Definition: fs_api.h:1898
uint64_t completed
How many bytes have we already received within the specified range (DBlocks only).
Definition: fs_api.h:1890
uint64_t offset
What is the first offset that we're interested in?
Definition: fs_api.h:1878
char * emsg
Error message, NULL if we're doing OK.
Definition: fs_api.h:1810
uint64_t length
How many bytes starting from offset are desired? This is NOT the overall length of the file!
Definition: fs_api.h:1884
uint32_t anonymity
Desired level of anonymity.
Definition: fs_api.h:1913
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:1829
struct DownloadRequest * top_request
Top-level download request.
Definition: fs_api.h:1856
enum GNUNET_FS_DownloadOptions options
Options for the download.
Definition: fs_api.h:1923
struct GNUNET_TIME_Absolute start_time
Time download was started.
Definition: fs_api.h:1903

References GNUNET_FS_DownloadContext::anonymity, cleanup(), GNUNET_FS_DownloadContext::completed, dc, dir, GNUNET_FS_DownloadContext::emsg, GNUNET_FS_DownloadContext::filename, get_download_sync_filename(), get_serialization_short_name(), GNUNET_assert, GNUNET_BIO_write_close(), GNUNET_BIO_write_open_file(), GNUNET_BIO_write_spec_commit(), GNUNET_BIO_write_spec_end, GNUNET_BIO_write_spec_int32(), GNUNET_BIO_write_spec_int64(), GNUNET_BIO_write_spec_string(), GNUNET_break, GNUNET_DISK_directory_create_for_file(), GNUNET_DISK_mktemp(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_FS_DOWNLOAD_IS_PROBE, GNUNET_FS_uri_test_chk(), GNUNET_FS_uri_test_loc(), GNUNET_FS_uri_to_string(), GNUNET_FS_write_spec_meta_data(), GNUNET_log_strerror_file, GNUNET_OK, GNUNET_YES, GNUNET_FS_DownloadContext::has_finished, GNUNET_FS_DownloadContext::length, GNUNET_FS_DownloadContext::meta, GNUNET_FS_DownloadContext::offset, GNUNET_FS_DownloadContext::old_file_size, GNUNET_FS_DownloadContext::options, GNUNET_FS_DownloadContext::serialization, GNUNET_FS_DownloadContext::start_time, GNUNET_FS_DownloadContext::temp_filename, GNUNET_FS_DownloadContext::top_request, GNUNET_FS_DownloadContext::uri, wh, write_download_request(), and write_start_time().

Referenced by check_completed(), GNUNET_FS_download_start_task_(), process_result_with_request(), search_result_stop(), and try_match_block().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_FS_search_result_sync_()

void GNUNET_FS_search_result_sync_ ( struct GNUNET_FS_SearchResult sr)

Synchronize this search result with its mirror on disk.

Note that all internal FS-operations that change publishing structs should already call "sync" internally, so this function is likely not useful for clients.

Parameters
srthe struct to sync

Definition at line 2149 of file fs_api.c.

2150 {
2151  struct GNUNET_BIO_WriteHandle *wh;
2152  char *uris;
2153 
2154  if (NULL == sr->sc)
2155  return;
2156  uris = NULL;
2157  if (NULL == sr->serialization)
2158  sr->serialization =
2160  (sr->sc->psearch_result == NULL)
2163  sr->sc->serialization);
2164  if (NULL == sr->serialization)
2165  return;
2166  wh = get_write_handle_in_dir (sr->h,
2167  (sr->sc->psearch_result == NULL)
2170  sr->sc->serialization,
2171  sr->serialization);
2172  if (NULL == wh)
2173  {
2174  GNUNET_break (0);
2175  goto cleanup;
2176  }
2177  uris = GNUNET_FS_uri_to_string (sr->uri);
2178  struct GNUNET_BIO_WriteSpec ws[] = {
2179  GNUNET_BIO_write_spec_string ("uris", uris),
2180  GNUNET_BIO_write_spec_string ("download serialization",
2181  (sr->download != NULL)
2182  ? sr->download->serialization
2183  : NULL),
2184  GNUNET_BIO_write_spec_string ("update search serialization",
2185  (sr->update_search != NULL)
2187  : NULL),
2188  GNUNET_FS_write_spec_meta_data ("metadata", sr->meta),
2189  GNUNET_BIO_write_spec_object ("key", &sr->key,
2190  sizeof(struct GNUNET_HashCode)),
2191  GNUNET_BIO_write_spec_int32 ("mandatory missing",
2192  (int32_t *) &sr->mandatory_missing),
2193  GNUNET_BIO_write_spec_int32 ("optional support",
2194  (int32_t *) &sr->optional_support),
2195  GNUNET_BIO_write_spec_int32 ("availability success",
2196  (int32_t *) &sr->availability_success),
2197  GNUNET_BIO_write_spec_int32 ("availability trials",
2198  (int32_t *) &sr->availability_trials),
2200  };
2201  if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws)))
2202  {
2203  GNUNET_break (0);
2204  goto cleanup;
2205  }
2206  if ((NULL != sr->uri) && (GNUNET_FS_URI_KSK == sr->sc->uri->type) &&
2207  (GNUNET_OK !=
2209  "keyword bitmap",
2210  sr->keyword_bitmap,
2211  (sr->sc->uri->data.ksk.keywordCount + 7) / 8)))
2212  {
2213  GNUNET_break (0);
2214  goto cleanup;
2215  }
2216  if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
2217  {
2218  wh = NULL;
2219  GNUNET_break (0);
2220  goto cleanup;
2221  }
2222  GNUNET_free (uris);
2223  return;
2224 cleanup:
2225  GNUNET_free (uris);
2226  if (NULL != wh)
2227  (void) GNUNET_BIO_write_close (wh, NULL);
2229  (NULL == sr->sc->psearch_result)
2232  sr->sc->serialization,
2233  sr->serialization);
2234  GNUNET_free (sr->serialization);
2235  sr->serialization = NULL;
2236 }
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:758
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:1256
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:703
@ GNUNET_FS_URI_KSK
Keyword search key (query with keywords).
Definition: fs_api.h:154
#define GNUNET_FS_SYNC_PATH_MASTER_SEARCH
Name of the directory with top-level searches.
Definition: fs_api.h:55
#define GNUNET_FS_SYNC_PATH_CHILD_SEARCH
Name of the directory with sub-searches (namespace-updates).
Definition: fs_api.h:60
char * serialization
Name of the file on disk we use for persistence.
Definition: fs_api.h:1546
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:1531
struct GNUNET_FS_Uri * uri
List of keywords that we're looking for.
Definition: fs_api.h:1525
uint32_t optional_support
Number of optional keywords under which this result was also found.
Definition: fs_api.h:602
struct GNUNET_FS_DownloadContext * download
ID of an associated download based on this search result (or NULL for none).
Definition: fs_api.h:546
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:552
uint32_t availability_trials
Number of availability trials that we have performed for this search result.
Definition: fs_api.h:613
struct GNUNET_FS_Uri * uri
URI to which this search result refers to.
Definition: fs_api.h:524
uint8_t * keyword_bitmap
Bitmap that specifies precisely which keywords have been matched already.
Definition: fs_api.h:562
struct GNUNET_FS_Handle * h
File-sharing context this result belongs to.
Definition: fs_api.h:503
struct GNUNET_HashCode key
Key for the search result based on the URI.
Definition: fs_api.h:567
char * serialization
Name under which this search result is stored on disk.
Definition: fs_api.h:557
uint32_t availability_success
Number of availability tests that have succeeded for this result.
Definition: fs_api.h:607
struct GNUNET_FS_MetaData * meta
Metadata for the search result.
Definition: fs_api.h:529
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:519
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:596
struct GNUNET_FS_Uri::@13::@14 ksk
union GNUNET_FS_Uri::@13 data
enum GNUNET_FS_UriType type
Type of the URI.
Definition: fs_api.h:171

References GNUNET_FS_SearchResult::availability_success, GNUNET_FS_SearchResult::availability_trials, cleanup(), GNUNET_FS_Uri::data, GNUNET_FS_SearchResult::download, get_write_handle_in_dir(), GNUNET_BIO_write(), GNUNET_BIO_write_close(), GNUNET_BIO_write_spec_commit(), GNUNET_BIO_write_spec_end, GNUNET_BIO_write_spec_int32(), GNUNET_BIO_write_spec_object(), GNUNET_BIO_write_spec_string(), GNUNET_break, GNUNET_free, GNUNET_FS_SYNC_PATH_CHILD_SEARCH, GNUNET_FS_SYNC_PATH_MASTER_SEARCH, GNUNET_FS_URI_KSK, GNUNET_FS_uri_to_string(), GNUNET_FS_write_spec_meta_data(), GNUNET_OK, GNUNET_FS_SearchResult::h, GNUNET_FS_SearchResult::key, GNUNET_FS_SearchResult::keyword_bitmap, GNUNET_FS_Uri::ksk, make_serialization_file_name_in_dir(), GNUNET_FS_SearchResult::mandatory_missing, GNUNET_FS_SearchResult::meta, GNUNET_FS_SearchResult::optional_support, GNUNET_FS_SearchContext::psearch_result, remove_sync_file_in_dir(), GNUNET_FS_SearchResult::sc, GNUNET_FS_SearchResult::serialization, GNUNET_FS_SearchContext::serialization, GNUNET_FS_DownloadContext::serialization, GNUNET_FS_Uri::type, GNUNET_FS_SearchResult::update_search, GNUNET_FS_SearchResult::uri, GNUNET_FS_SearchContext::uri, and wh.

Referenced by GNUNET_FS_download_start_task_(), GNUNET_FS_search_probe_progress_(), probe_failure_handler(), probe_success_handler(), process_ksk_result(), and process_sks_result().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_FS_search_sync_()

void GNUNET_FS_search_sync_ ( struct GNUNET_FS_SearchContext sc)

Synchronize this search struct with its mirror on disk.

Note that all internal FS-operations that change publishing structs should already call "sync" internally, so this function is likely not useful for clients.

Parameters
scthe struct to sync

Definition at line 2248 of file fs_api.c.

2249 {
2250  struct GNUNET_BIO_WriteHandle *wh;
2251  char *uris;
2252  char in_pause;
2253  const char *category;
2254 
2255  category = (NULL == sc->psearch_result) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
2257  if (NULL == sc->serialization)
2259  if (NULL == sc->serialization)
2260  return;
2261  uris = NULL;
2262  wh = get_write_handle (sc->h, category, sc->serialization);
2263  if (NULL == wh)
2264  {
2265  GNUNET_break (0);
2266  goto cleanup;
2267  }
2270  uris = GNUNET_FS_uri_to_string (sc->uri);
2271  in_pause = (sc->task != NULL) ? 'r' : '\0';
2272  if ((GNUNET_OK != GNUNET_BIO_write_string (wh, "uris", uris)) ||
2274  (GNUNET_OK != GNUNET_BIO_write_string (wh, "emsg", sc->emsg)) ||
2275  (GNUNET_OK != GNUNET_BIO_write_int32 (wh, "options",
2276  (uint32_t) sc->options)) ||
2277  (GNUNET_OK != GNUNET_BIO_write (wh, "in pause",
2278  &in_pause, sizeof(in_pause))) ||
2279  (GNUNET_OK != GNUNET_BIO_write_int32 (wh, "anonymity", sc->anonymity)))
2280  {
2281  GNUNET_break (0);
2282  goto cleanup;
2283  }
2284  GNUNET_free (uris);
2285  uris = NULL;
2286  if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
2287  {
2288  wh = NULL;
2289  GNUNET_break (0);
2290  goto cleanup;
2291  }
2292  return;
2293 cleanup:
2294  if (NULL != wh)
2295  (void) GNUNET_BIO_write_close (wh, NULL);
2296  GNUNET_free (uris);
2299  sc->serialization = NULL;
2300 }
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:87
enum GNUNET_GenericReturnValue GNUNET_BIO_write_int32(struct GNUNET_BIO_WriteHandle *h, const char *what, int32_t i)
Write an (u)int32_t.
Definition: bio.c:848
char * emsg
Error message (non-NULL if this operation failed).
Definition: fs_api.h:1551
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:1583
enum GNUNET_FS_SearchOptions options
Options for the search.
Definition: fs_api.h:1598
uint32_t anonymity
Anonymity level for the search.
Definition: fs_api.h:1588
struct GNUNET_FS_Handle * h
Handle to the global FS context.
Definition: fs_api.h:1515
struct GNUNET_TIME_Absolute start_time
When did we start?
Definition: fs_api.h:1570

References GNUNET_FS_SearchContext::anonymity, cleanup(), GNUNET_FS_SearchContext::emsg, get_write_handle(), GNUNET_assert, GNUNET_BIO_write(), GNUNET_BIO_write_close(), GNUNET_BIO_write_int32(), GNUNET_BIO_write_string(), GNUNET_break, GNUNET_free, GNUNET_FS_remove_sync_file_(), GNUNET_FS_SYNC_PATH_CHILD_SEARCH, GNUNET_FS_SYNC_PATH_MASTER_SEARCH, GNUNET_FS_uri_test_ksk(), GNUNET_FS_uri_test_sks(), GNUNET_FS_uri_to_string(), GNUNET_OK, GNUNET_YES, GNUNET_FS_SearchContext::h, make_serialization_file_name(), GNUNET_FS_SearchContext::options, GNUNET_FS_SearchContext::psearch_result, sc, GNUNET_FS_SearchContext::serialization, GNUNET_FS_SearchContext::start_time, GNUNET_FS_SearchContext::task, GNUNET_FS_SearchContext::uri, wh, and write_start_time().

Referenced by GNUNET_FS_search_continue(), GNUNET_FS_search_pause(), and search_start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ deserialize_unindex_file()

static int deserialize_unindex_file ( void *  cls,
const char *  filename 
)
static

Function called with a filename of serialized unindexing operation to deserialize.

Parameters
clsthe struct GNUNET_FS_Handle *
filenamecomplete filename (absolute path)
Returns
GNUNET_OK (continue to iterate)

Definition at line 2312 of file fs_api.c.

2313 {
2314  struct GNUNET_FS_Handle *h = cls;
2315  struct GNUNET_BIO_ReadHandle *rh;
2316  struct GNUNET_FS_UnindexContext *uc;
2317  struct GNUNET_FS_ProgressInfo pi;
2318  char *emsg;
2319  char *uris;
2320  uint32_t state;
2321 
2323  uc->h = h;
2326  if (NULL == rh)
2327  {
2328  GNUNET_break (0);
2329  goto cleanup;
2330  }
2331  uris = NULL;
2332  if ((GNUNET_OK !=
2333  GNUNET_BIO_read_string (rh, "unindex-fn", &uc->filename, 10 * 1024)) ||
2334  (GNUNET_OK != GNUNET_BIO_read_int64 (rh, "file size",
2335  (int64_t *) &uc->file_size)) ||
2336  (GNUNET_OK != read_start_time (rh, &uc->start_time)) ||
2337  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "state",
2338  (int32_t *) &state)) ||
2339  (GNUNET_OK !=
2340  GNUNET_BIO_read (rh, "uri", &uc->chk, sizeof(struct ContentHashKey))) ||
2341  (GNUNET_OK !=
2342  GNUNET_BIO_read_string (rh, "unindex-kskuri", &uris, 10 * 1024)) ||
2343  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "ksk offset",
2344  (int32_t *) &uc->ksk_offset)))
2345  {
2346  GNUNET_free (uris);
2347  GNUNET_break (0);
2348  goto cleanup;
2349  }
2350  if (NULL != uris)
2351  {
2352  uc->ksk_uri = GNUNET_FS_uri_parse (uris, &emsg);
2353  GNUNET_free (uris);
2354  if (NULL == uc->ksk_uri)
2355  {
2356  GNUNET_break (0);
2357  GNUNET_free (emsg);
2358  goto cleanup;
2359  }
2360  }
2361  if ((uc->ksk_offset > 0) &&
2362  ((NULL == uc->ksk_uri) ||
2363  (uc->ksk_offset > uc->ksk_uri->data.ksk.keywordCount)))
2364  {
2365  GNUNET_break (0);
2366  goto cleanup;
2367  }
2368  uc->state = (enum UnindexState) state;
2369  switch (state)
2370  {
2371  case UNINDEX_STATE_HASHING:
2372  break;
2373 
2375  if (GNUNET_OK != GNUNET_BIO_read (rh,
2376  "unindex-hash",
2377  &uc->file_id,
2378  sizeof(struct GNUNET_HashCode)))
2379  {
2380  GNUNET_break (0);
2381  goto cleanup;
2382  }
2383  break;
2384 
2388  break;
2389 
2391  break;
2392 
2393  case UNINDEX_STATE_ERROR:
2394  if (GNUNET_OK !=
2395  GNUNET_BIO_read_string (rh, "unindex-emsg", &uc->emsg, 10 * 1024))
2396  {
2397  GNUNET_break (0);
2398  goto cleanup;
2399  }
2400  break;
2401 
2402  default:
2403  GNUNET_break (0);
2404  goto cleanup;
2405  }
2408  pi.value.unindex.specifics.resume.message = uc->emsg;
2410  uc,
2412  ? uc->file_size
2413  : 0);
2414  switch (uc->state)
2415  {
2416  case UNINDEX_STATE_HASHING:
2418  uc->filename,
2421  uc);
2422  break;
2423 
2427  break;
2428 
2431  break;
2432 
2435  break;
2436 
2439  break;
2440 
2442  case UNINDEX_STATE_ERROR:
2443  /* no need to resume any operation, we were done */
2444  break;
2445 
2446  default:
2447  break;
2448  }
2449  if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
2450  {
2452  _ ("Failure while resuming unindexing operation `%s': %s\n"),
2453  filename,
2454  emsg);
2455  GNUNET_free (emsg);
2456  }
2457  return GNUNET_OK;
2458 cleanup:
2459  GNUNET_free (uc->filename);
2460  if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)))
2461  {
2463  _ ("Failed to resume unindexing operation `%s': %s\n"),
2464  filename,
2465  emsg);
2466  GNUNET_free (emsg);
2467  }
2468  if (NULL != uc->serialization)
2471  uc->serialization);
2473  GNUNET_free (uc);
2474  return GNUNET_OK;
2475 }
#define HASHING_BLOCKSIZE
Blocksize to use when hashing files for indexing (blocksize for IO, not for the DBlocks).
Definition: fs.h:48
UnindexState
Phases of unindex processing (state machine).
Definition: fs_api.h:1307
@ UNINDEX_STATE_EXTRACT_KEYWORDS
Find out which keywords apply.
Definition: fs_api.h:1322
@ UNINDEX_STATE_COMPLETE
We're done.
Definition: fs_api.h:1338
@ UNINDEX_STATE_DS_REMOVE
We're telling the datastore to delete the respective DBlocks and IBlocks.
Definition: fs_api.h:1317
@ UNINDEX_STATE_HASHING
We're currently hashing the file.
Definition: fs_api.h:1311
@ UNINDEX_STATE_DS_REMOVE_KBLOCKS
We're telling the datastore to remove KBlocks.
Definition: fs_api.h:1327
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:581
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:85
void GNUNET_FS_unindex_do_extract_keywords_(struct GNUNET_FS_UnindexContext *uc)
Extract the keywords for KBlock removal.
Definition: fs_unindex.c:407
void GNUNET_FS_unindex_do_remove_(struct GNUNET_FS_UnindexContext *uc)
Connect to the datastore and remove the blocks.
Definition: fs_unindex.c:650
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:728
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:695
enum State state
current state of profiling
@ GNUNET_FS_STATUS_UNINDEX_RESUME
Notification that we resumed unindexing of a file.
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.
@ GNUNET_SCHEDULER_PRIORITY_IDLE
Run when otherwise idle.
Handle for controlling an unindexing operation.
Definition: fs_api.h:1351
struct GNUNET_CRYPTO_FileHashContext * fhc
Context for hashing of the file.
Definition: fs_api.h:1444
struct TopLevelActivity * top
Our top-level activity entry.
Definition: fs_api.h:1366

References _, GNUNET_FS_UnindexContext::chk, cleanup(), GNUNET_FS_Uri::data, GNUNET_FS_UnindexContext::emsg, GNUNET_FS_UnindexContext::fhc, GNUNET_FS_UnindexContext::file_id, GNUNET_FS_UnindexContext::file_size, GNUNET_FS_UnindexContext::filename, filename, get_serialization_short_name(), GNUNET_BIO_read(), GNUNET_BIO_read_close(), GNUNET_BIO_read_int32(), GNUNET_BIO_read_int64(), GNUNET_BIO_read_open_file(), GNUNET_BIO_read_string(), GNUNET_break, GNUNET_CRYPTO_hash_file(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_FS_make_top(), GNUNET_FS_remove_sync_file_(), GNUNET_FS_STATUS_UNINDEX_RESUME, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, GNUNET_FS_unindex_do_extract_keywords_(), GNUNET_FS_unindex_do_remove_(), GNUNET_FS_unindex_do_remove_kblocks_(), GNUNET_FS_unindex_make_status_(), GNUNET_FS_unindex_process_hash_(), GNUNET_FS_unindex_signal_suspend_(), GNUNET_FS_uri_parse(), GNUNET_log, GNUNET_new, GNUNET_OK, GNUNET_SCHEDULER_PRIORITY_IDLE, h, GNUNET_FS_UnindexContext::h, HASHING_BLOCKSIZE, GNUNET_FS_Uri::ksk, GNUNET_FS_UnindexContext::ksk_offset, GNUNET_FS_UnindexContext::ksk_uri, pi, read_start_time(), GNUNET_FS_UnindexContext::serialization, GNUNET_FS_UnindexContext::start_time, GNUNET_FS_UnindexContext::state, state, GNUNET_FS_UnindexContext::top, uc, UNINDEX_STATE_COMPLETE, UNINDEX_STATE_DS_REMOVE, UNINDEX_STATE_DS_REMOVE_KBLOCKS, UNINDEX_STATE_ERROR, UNINDEX_STATE_EXTRACT_KEYWORDS, UNINDEX_STATE_FS_NOTIFY, and UNINDEX_STATE_HASHING.

Referenced by GNUNET_FS_start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ deserialize_download()

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 
)
static

Deserialize a download.

Parameters
hoverall context
rhfile to deserialize from
parentparent download
searchassociated search
serializationname under which the search was serialized

Definition at line 2909 of file fs_api.c.

2914 {
2915  struct GNUNET_FS_DownloadContext *dc;
2916  char *emsg;
2917  char *uris;
2918  char *dn;
2919  uint32_t options;
2920  uint32_t status;
2921 
2922  uris = NULL;
2923  emsg = NULL;
2925  dc->parent = parent;
2926  dc->h = h;
2928  struct GNUNET_BIO_ReadSpec rs[] = {
2929  GNUNET_FS_read_spec_meta_data ("download-meta", &dc->meta),
2930  GNUNET_BIO_read_spec_string ("download-emsg", &dc->emsg, 10 * 1024),
2931  GNUNET_BIO_read_spec_string ("download-fn", &dc->filename, 10 * 1024),
2932  GNUNET_BIO_read_spec_string ("download-tfn",
2933  &dc->temp_filename, 10 * 1024),
2934  GNUNET_BIO_read_spec_int64 ("old file size",
2935  (int64_t *) &dc->old_file_size),
2936  GNUNET_BIO_read_spec_int64 ("offset",
2937  (int64_t *) &dc->offset),
2938  GNUNET_BIO_read_spec_int64 ("length",
2939  (int64_t *) &dc->length),
2940  GNUNET_BIO_read_spec_int64 ("completed",
2941  (int64_t *) &dc->completed),
2943  };
2944  if ((GNUNET_OK !=
2945  GNUNET_BIO_read_string (rh, "download-uri", &uris, 10 * 1024)) ||
2946  (NULL == (dc->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
2951  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "anonymity",
2952  (int32_t *) &dc->anonymity)) ||
2953  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "options",
2954  (int32_t *) &options)) ||
2955  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "status",
2956  (int32_t *) &status)))
2957  {
2958  GNUNET_break (0);
2959  goto cleanup;
2960  }
2962  dc->active =
2964  GNUNET_NO);
2965  dc->has_finished = (int) status;
2966  dc->treedepth =
2968  if (GNUNET_FS_uri_test_loc (dc->uri))
2971  if (NULL == dc->emsg)
2972  {
2974  if (NULL == dc->top_request)
2975  {
2976  GNUNET_break (0);
2977  goto cleanup;
2978  }
2979  }
2980  dn = get_download_sync_filename (dc, dc->serialization, ".dir");
2981  if (NULL != dn)
2982  {
2985  GNUNET_free (dn);
2986  }
2987  if (NULL != parent)
2988  {
2990  }
2991  if (NULL != search)
2992  {
2993  dc->search = search;
2994  search->download = dc;
2995  }
2996  if ((NULL == parent) && (NULL == search))
2997  {
2998  dc->top =
3001  }
3002  GNUNET_free (uris);
3003  GNUNET_assert (NULL == dc->job_queue);
3005  return;
3006 cleanup:
3007  GNUNET_free (uris);
3008  GNUNET_free (emsg);
3010 }
#define DBLOCK_SIZE
Size of the individual blocks used for file-sharing.
Definition: fs.h:41
static void signal_download_resume(struct GNUNET_FS_DownloadContext *dc)
Send the 'resume' signal to the callback; also actually resume the download (put it in the queue).
Definition: fs_api.c:2683
static int deserialize_subdownload(void *cls, const char *filename)
Function called with a filename of serialized sub-download to deserialize.
Definition: fs_api.c:2834
static void free_download_context(struct GNUNET_FS_DownloadContext *dc)
Free this download context and all of its descendants.
Definition: fs_api.c:2875
void GNUNET_FS_download_signal_suspend_(void *cls)
Create SUSPEND event for the given download operation and then clean up our state (without stop signa...
Definition: fs_download.c:1953
void GNUNET_FS_download_start_task_(void *cls)
Task that creates the initial (top-level) download request for the file.
Definition: fs_download.c:1800
unsigned int GNUNET_FS_compute_depth(uint64_t flen)
Compute the depth of the CHK tree.
Definition: fs_tree.c:125
uint16_t status
See PRISM_STATUS_*-constants.
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition: disk.c:814
GNUNET_FS_DownloadOptions
Options for downloading.
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:1360
struct GNUNET_BIO_ReadSpec GNUNET_FS_read_spec_meta_data(const char *what, struct GNUNET_FS_MetaData **result)
Create the specification to read a metadata container.
Definition: meta_data.c:1181
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:812
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
Context for controlling a download.
Definition: fs_api.h:1744
unsigned int treedepth
The depth of the file-tree.
Definition: fs_api.h:1918
struct GNUNET_FS_QueueEntry * job_queue
Our entry in the job queue.
Definition: fs_api.h:1834
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:1872
struct GNUNET_FS_DownloadContext * child_tail
Tail of list of child downloads.
Definition: fs_api.h:1780
struct GNUNET_CONTAINER_MultiHashMap * active
Map of active requests (those waiting for a response).
Definition: fs_api.h:1851
struct GNUNET_FS_DownloadContext * child_head
Head of list of child downloads.
Definition: fs_api.h:1775
struct GNUNET_PeerIdentity target
Identity of the peer having the content, or all-zeros if we don't know of such a peer.
Definition: fs_api.h:1862
struct TopLevelActivity * top
Our top-level activity entry (if we are top-level, otherwise NULL).
Definition: fs_api.h:1753

References GNUNET_FS_DownloadContext::active, GNUNET_FS_DownloadContext::anonymity, GNUNET_FS_DownloadContext::child_head, GNUNET_FS_DownloadContext::child_tail, cleanup(), GNUNET_FS_DownloadContext::completed, DBLOCK_SIZE, dc, deserialize_subdownload(), GNUNET_FS_SearchResult::download, GNUNET_FS_DownloadContext::emsg, GNUNET_FS_DownloadContext::filename, free_download_context(), get_download_sync_filename(), GNUNET_assert, GNUNET_BIO_read_int32(), GNUNET_BIO_read_spec_commit(), GNUNET_BIO_read_spec_end, GNUNET_BIO_read_spec_int64(), GNUNET_BIO_read_spec_string(), GNUNET_BIO_read_string(), GNUNET_break, GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_multihashmap_create(), GNUNET_DISK_directory_scan(), GNUNET_DISK_directory_test(), GNUNET_free, GNUNET_FS_compute_depth(), GNUNET_FS_download_signal_suspend_(), GNUNET_FS_download_start_task_(), GNUNET_FS_make_top(), GNUNET_FS_read_spec_meta_data(), GNUNET_FS_uri_chk_get_file_size(), GNUNET_FS_uri_loc_get_peer_identity(), GNUNET_FS_uri_parse(), GNUNET_FS_uri_test_chk(), GNUNET_FS_uri_test_loc(), GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, GNUNET_YES, h, GNUNET_FS_DownloadContext::h, GNUNET_FS_DownloadContext::has_finished, consensus-simulation::int, GNUNET_FS_DownloadContext::job_queue, GNUNET_FS_DownloadContext::length, GNUNET_FS_DownloadContext::meta, GNUNET_FS_DownloadContext::offset, GNUNET_FS_DownloadContext::old_file_size, options, GNUNET_FS_DownloadContext::options, GNUNET_FS_DownloadContext::parent, read_download_request(), read_start_time(), GNUNET_BIO_ReadSpec::rh, GNUNET_FS_DownloadContext::search, GNUNET_FS_DownloadContext::serialization, signal_download_resume(), GNUNET_FS_DownloadContext::start_time, status, GNUNET_FS_DownloadContext::target, GNUNET_FS_DownloadContext::task, GNUNET_FS_DownloadContext::temp_filename, GNUNET_FS_DownloadContext::top, GNUNET_FS_DownloadContext::top_request, GNUNET_FS_DownloadContext::treedepth, and GNUNET_FS_DownloadContext::uri.

Referenced by deserialize_download_file(), deserialize_search_result(), and deserialize_subdownload().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ deserialize_search()

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 
)
static

Deserialize a search.

Parameters
hoverall context
rhfile to deserialize from
psearch_resultparent search result
serializationname under which the search was serialized

Definition at line 3044 of file fs_api.c.

3048 {
3049  struct GNUNET_FS_SearchContext *sc;
3050  char *emsg;
3051  char *uris;
3052  char *dn;
3053  uint32_t options;
3054  char in_pause;
3055 
3056  if ((NULL != psearch_result) && (NULL != psearch_result->update_search))
3057  {
3058  GNUNET_break (0);
3059  return NULL;
3060  }
3061  uris = NULL;
3062  emsg = NULL;
3064  if (NULL != psearch_result)
3065  {
3068  }
3069  sc->h = h;
3071  if ((GNUNET_OK !=
3072  GNUNET_BIO_read_string (rh, "search-uri", &uris, 10 * 1024)) ||
3073  (NULL == (sc->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
3076  (GNUNET_OK != read_start_time (rh, &sc->start_time)) ||
3077  (GNUNET_OK !=
3078  GNUNET_BIO_read_string (rh, "search-emsg", &sc->emsg, 10 * 1024)) ||
3079  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "options",
3080  (int32_t *) &options)) ||
3081  (GNUNET_OK !=
3082  GNUNET_BIO_read (rh, "search-pause", &in_pause, sizeof(in_pause))) ||
3083  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "anonymity",
3084  (int32_t *) &sc->anonymity)))
3085  {
3086  GNUNET_break (0);
3087  goto cleanup;
3088  }
3092  (NULL == sc->psearch_result)
3095  sc->serialization,
3096  "");
3097  if (NULL != dn)
3098  {
3101  GNUNET_free (dn);
3102  }
3103  if (('\0' == in_pause) &&
3105  {
3106  GNUNET_log (
3108  _ ("Could not resume running search, will resume as paused search\n"));
3109  }
3111  GNUNET_free (uris);
3112  return sc;
3113 cleanup:
3114  GNUNET_free (emsg);
3116  GNUNET_free (uris);
3117  return NULL;
3118 }
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:3020
static void free_search_context(struct GNUNET_FS_SearchContext *sc)
Free memory allocated by the search context and its children.
Definition: fs_api.c:2795
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:2519
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:1402
GNUNET_FS_SearchOptions
Options for searching.
Handle for controlling a search.
Definition: fs_api.h:1511
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:1559

References _, GNUNET_FS_SearchContext::anonymity, cleanup(), deserialize_search_result(), GNUNET_FS_SearchContext::emsg, free_search_context(), get_serialization_file_name_in_dir(), GNUNET_BIO_read(), GNUNET_BIO_read_int32(), GNUNET_BIO_read_string(), GNUNET_break, GNUNET_CONTAINER_multihashmap_create(), GNUNET_DISK_directory_scan(), GNUNET_DISK_directory_test(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_FS_search_start_searching_(), GNUNET_FS_SYNC_PATH_CHILD_SEARCH, GNUNET_FS_SYNC_PATH_MASTER_SEARCH, GNUNET_FS_uri_parse(), GNUNET_FS_uri_test_ksk(), GNUNET_FS_uri_test_sks(), GNUNET_log, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_strdup, GNUNET_YES, h, GNUNET_FS_SearchContext::h, GNUNET_FS_SearchContext::master_result_map, options, GNUNET_FS_SearchContext::options, GNUNET_FS_SearchContext::psearch_result, read_start_time(), sc, GNUNET_FS_SearchContext::serialization, signal_search_resume(), GNUNET_FS_SearchContext::start_time, GNUNET_FS_SearchResult::update_search, and GNUNET_FS_SearchContext::uri.

Referenced by deserialize_search_file(), and deserialize_search_result().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ deserialize_search_result()

static int deserialize_search_result ( void *  cls,
const char *  filename 
)
static

Function called with a filename of serialized search result to deserialize.

Parameters
clsthe struct GNUNET_FS_SearchContext *
filenamecomplete filename (absolute path)
Returns
GNUNET_OK (continue to iterate)

Definition at line 2519 of file fs_api.c.

2520 {
2521  struct GNUNET_FS_SearchContext *sc = cls;
2522  char *serialized;
2523  char *uris;
2524  char *emsg;
2525  char *download;
2526  char *update_srch;
2527  struct GNUNET_BIO_ReadHandle *rh;
2528  struct GNUNET_BIO_ReadHandle *drh;
2529  struct GNUNET_FS_SearchResult *sr;
2530 
2531  serialized = get_serialization_short_name (filename);
2533  if (NULL == rh)
2534  {
2535  if (NULL != serialized)
2536  {
2538  (NULL == sc->psearch_result)
2541  sc->serialization,
2542  serialized);
2543  GNUNET_free (serialized);
2544  }
2545  return GNUNET_OK;
2546  }
2547  emsg = NULL;
2548  uris = NULL;
2549  download = NULL;
2550  update_srch = NULL;
2551  sr = GNUNET_new (struct GNUNET_FS_SearchResult);
2552  sr->h = sc->h;
2553  sr->sc = sc;
2554  sr->serialization = serialized;
2555  if ((GNUNET_OK !=
2556  GNUNET_BIO_read_string (rh, "result-uri", &uris, 10 * 1024)) ||
2557  (NULL == (sr->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
2558  (GNUNET_OK !=
2559  GNUNET_BIO_read_string (rh, "download-lnk", &download, 16)) ||
2560  (GNUNET_OK !=
2561  GNUNET_BIO_read_string (rh, "search-lnk", &update_srch, 16)) ||
2562  (GNUNET_OK != GNUNET_FS_read_meta_data (rh, "result-meta", &sr->meta)) ||
2563  (GNUNET_OK != GNUNET_BIO_read (rh,
2564  "result-key",
2565  &sr->key,
2566  sizeof(struct GNUNET_HashCode))) ||
2568  rh,
2569  "mandatory missing",
2570  (int32_t *) &sr->mandatory_missing)) ||
2572  rh,
2573  "optional support",
2574  (int32_t *) &sr->optional_support)) ||
2576  rh,
2577  "availability success",
2578  (int32_t *) &sr->availability_success)) ||
2580  rh,
2581  "availability trials",
2582  (int32_t *) &sr->availability_trials)))
2583  {
2584  GNUNET_break (0);
2585  goto cleanup;
2586  }
2587  if (GNUNET_FS_URI_KSK == sr->sc->uri->type)
2588  {
2590  (sr->sc->uri->data.ksk.keywordCount + 7) / 8); /* round up, count bits */
2591  if (GNUNET_OK !=
2592  GNUNET_BIO_read (rh,
2593  "keyword-bitmap",
2594  sr->keyword_bitmap,
2595  (sr->sc->uri->data.ksk.keywordCount + 7) / 8))
2596  {
2597  GNUNET_break (0);
2598  goto cleanup;
2599  }
2600  }
2601  GNUNET_free (uris);
2602  if (NULL != download)
2603  {
2605  if (NULL != drh)
2606  {
2607  deserialize_download (sc->h, drh, NULL, sr, download);
2608  if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg))
2609  {
2611  _ ("Failed to resume sub-download `%s': %s\n"),
2612  download,
2613  emsg);
2614  GNUNET_free (emsg);
2615  }
2616  }
2618  }
2619  if (NULL != update_srch)
2620  {
2621  drh =
2623  if (NULL != drh)
2624  {
2625  deserialize_search (sc->h, drh, sr, update_srch);
2626  if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg))
2627  {
2629  _ ("Failed to resume sub-search `%s': %s\n"),
2630  update_srch,
2631  emsg);
2632  GNUNET_free (emsg);
2633  }
2634  }
2635  GNUNET_free (update_srch);
2636  }
2639  &sr->key,
2640  sr,
2642  if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
2643  {
2645  _ ("Failure while resuming search operation `%s': %s\n"),
2646  filename,
2647  emsg);
2648  GNUNET_free (emsg);
2649  }
2650  return GNUNET_OK;
2651 cleanup:
2653  GNUNET_free (emsg);
2654  GNUNET_free (uris);
2655  GNUNET_free (update_srch);
2656  if (NULL != sr->uri)
2657  GNUNET_FS_uri_destroy (sr->uri);
2658  if (NULL != sr->meta)
2660  GNUNET_free (sr->serialization);
2661  GNUNET_free (sr);
2662  if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
2663  {
2665  _ ("Failure while resuming search operation `%s': %s\n"),
2666  filename,
2667  emsg);
2668  GNUNET_free (emsg);
2669  }
2670  return GNUNET_OK;
2671 }
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:2909
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:3044
void GNUNET_FS_uri_destroy(struct GNUNET_FS_Uri *uri)
Free URI.
Definition: fs_uri.c:677
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
void GNUNET_FS_meta_data_destroy(struct GNUNET_FS_MetaData *md)
Free meta data.
Definition: meta_data.c:171
Information we store for each search result.
Definition: fs_api.h:499

References _, GNUNET_FS_SearchResult::availability_success, GNUNET_FS_SearchResult::availability_trials, cleanup(), GNUNET_FS_Uri::data, deserialize_download(), deserialize_search(), GNUNET_FS_SearchResult::download, GNUNET_FS_SearchContext::emsg, filename, get_read_handle(), get_serialization_short_name(), GNUNET_BIO_read(), GNUNET_BIO_read_close(), GNUNET_BIO_read_int32(), GNUNET_BIO_read_open_file(), GNUNET_BIO_read_string(), GNUNET_break, GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_FS_meta_data_destroy(), GNUNET_FS_read_meta_data(), GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD, GNUNET_FS_SYNC_PATH_CHILD_SEARCH, GNUNET_FS_SYNC_PATH_MASTER_SEARCH, GNUNET_FS_uri_destroy(), GNUNET_FS_URI_KSK, GNUNET_FS_uri_parse(), GNUNET_log, GNUNET_malloc, GNUNET_new, GNUNET_OK, GNUNET_YES, GNUNET_FS_SearchResult::h, GNUNET_FS_SearchContext::h, GNUNET_FS_SearchResult::key, GNUNET_FS_SearchResult::keyword_bitmap, GNUNET_FS_Uri::ksk, GNUNET_FS_SearchResult::mandatory_missing, GNUNET_FS_SearchContext::master_result_map, GNUNET_FS_SearchResult::meta, GNUNET_FS_SearchResult::optional_support, GNUNET_FS_SearchContext::psearch_result, remove_sync_file_in_dir(), GNUNET_FS_SearchResult::sc, sc, GNUNET_FS_SearchResult::serialization, GNUNET_FS_SearchContext::serialization, GNUNET_FS_Uri::type, GNUNET_FS_SearchResult::uri, and GNUNET_FS_SearchContext::uri.

Referenced by deserialize_search().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ signal_download_resume()

static void signal_download_resume ( struct GNUNET_FS_DownloadContext dc)
static

Send the 'resume' signal to the callback; also actually resume the download (put it in the queue).

Does this recursively for the top-level download and all child downloads.

Parameters
dcdownload to resume

Definition at line 2683 of file fs_api.c.

2684 {
2685  struct GNUNET_FS_DownloadContext *dcc;
2686  struct GNUNET_FS_ProgressInfo pi;
2687 
2689  pi.value.download.specifics.resume.meta = dc->meta;
2690  pi.value.download.specifics.resume.message = dc->emsg;
2692  dcc = dc->child_head;
2693  while (NULL != dcc)
2694  {
2695  signal_download_resume (dcc);
2696  dcc = dcc->next;
2697  }
2698 }
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:104
@ GNUNET_FS_STATUS_DOWNLOAD_RESUME
Notification that this download is being resumed.
struct GNUNET_FS_DownloadContext * next
Next download belonging to the same parent.
Definition: fs_api.h:1790

References GNUNET_FS_DownloadContext::child_head, dc, GNUNET_FS_DownloadContext::emsg, GNUNET_FS_download_make_status_(), GNUNET_FS_STATUS_DOWNLOAD_RESUME, GNUNET_FS_DownloadContext::meta, GNUNET_FS_DownloadContext::next, and pi.

Referenced by deserialize_download(), and signal_result_resume().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ signal_search_resume()

static void signal_search_resume ( struct GNUNET_FS_SearchContext sc)
static

Signal resuming of a search to our clients (for the top level search and all sub-searches).

Parameters
scsearch being resumed

Definition at line 3020 of file fs_api.c.

3021 {
3022  struct GNUNET_FS_ProgressInfo pi;
3023 
3025  pi.value.search.specifics.resume.message = sc->emsg;
3026  pi.value.search.specifics.resume.is_paused =
3027  (NULL == sc->mq) ? GNUNET_YES : GNUNET_NO;
3031  sc);
3032 }
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:2721
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:49
@ GNUNET_FS_STATUS_SEARCH_RESUME
Last event when a search is being resumed; note that "GNUNET_FS_SEARCH_START" will not be generated i...
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
void * client_info
Pointer we keep for the client.
Definition: fs_api.h:1541
struct GNUNET_MQ_Handle * mq
Connection to the FS service.
Definition: fs_api.h:1536

References GNUNET_FS_SearchContext::client_info, GNUNET_FS_SearchContext::emsg, GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_FS_search_make_status_(), GNUNET_FS_STATUS_SEARCH_RESUME, GNUNET_NO, GNUNET_YES, GNUNET_FS_SearchContext::h, GNUNET_FS_SearchContext::master_result_map, GNUNET_FS_SearchContext::mq, pi, sc, and signal_result_resume().

Referenced by deserialize_search(), and signal_result_resume().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ signal_result_resume()

static int signal_result_resume ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Iterator over search results signaling resume to the client for each result.

Parameters
clsclosure, the struct GNUNET_FS_SearchContext *
keycurrent key code
valuevalue in the hash map, the struct GNUNET_FS_SearchResult *
Returns
GNUNET_YES (we should continue to iterate)

Definition at line 2721 of file fs_api.c.

2722 {
2723  struct GNUNET_FS_SearchContext *sc = cls;
2724  struct GNUNET_FS_ProgressInfo pi;
2725  struct GNUNET_FS_SearchResult *sr = value;
2726 
2727  if (0 == sr->mandatory_missing)
2728  {
2730  pi.value.search.specifics.resume_result.meta = sr->meta;
2731  pi.value.search.specifics.resume_result.uri = sr->uri;
2732  pi.value.search.specifics.resume_result.result = sr;
2733  pi.value.search.specifics.resume_result.availability_rank =
2735  pi.value.search.specifics.resume_result.availability_certainty =
2736  sr->availability_trials;
2737  pi.value.search.specifics.resume_result.applicability_rank =
2738  sr->optional_support;
2740  }
2741  if (NULL != sr->download)
2742  {
2744  }
2745  else
2746  {
2748  }
2749  if (NULL != sr->update_search)
2751  return GNUNET_YES;
2752 }
void GNUNET_FS_search_start_probe_(struct GNUNET_FS_SearchResult *sr)
Start download probes for the given search result.
Definition: fs_search.c:431
static char * value
Value of the record to add/remove.
@ GNUNET_FS_STATUS_SEARCH_RESUME_RESULT
Event generated for each search result when the respective search is resumed.
void * client_info
Client info for this search result.
Definition: fs_api.h:534

References GNUNET_FS_SearchResult::availability_success, GNUNET_FS_SearchResult::availability_trials, GNUNET_FS_SearchResult::client_info, GNUNET_FS_SearchResult::download, GNUNET_FS_search_make_status_(), GNUNET_FS_search_start_probe_(), GNUNET_FS_STATUS_SEARCH_RESUME_RESULT, GNUNET_YES, GNUNET_FS_SearchContext::h, GNUNET_FS_SearchResult::mandatory_missing, GNUNET_FS_SearchResult::meta, GNUNET_FS_SearchResult::optional_support, pi, sc, signal_download_resume(), signal_search_resume(), GNUNET_FS_SearchResult::update_search, GNUNET_FS_SearchResult::uri, and value.

Referenced by signal_search_resume().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ free_search_context()

static void free_search_context ( struct GNUNET_FS_SearchContext sc)
static

Free memory allocated by the search context and its children.

Parameters
scsearch context to free

Definition at line 2795 of file fs_api.c.

2796 {
2797  if (NULL != sc->serialization)
2798  {
2800  (sc->psearch_result == NULL)
2803  sc->serialization);
2805  (sc->psearch_result == NULL)
2808  sc->serialization);
2809  }
2811  GNUNET_free (sc->emsg);
2812  if (NULL != sc->uri)
2814  if (NULL != sc->master_result_map)
2815  {
2817  &free_result,
2818  sc);
2820  }
2821  GNUNET_free (sc);
2822 }
static int free_result(void *cls, const struct GNUNET_HashCode *key, void *value)
Iterator over search results freeing each.
Definition: fs_api.c:2773
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:787
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.

References GNUNET_FS_SearchContext::emsg, free_result(), GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_free, GNUNET_FS_remove_sync_dir_(), GNUNET_FS_remove_sync_file_(), GNUNET_FS_SYNC_PATH_CHILD_SEARCH, GNUNET_FS_SYNC_PATH_MASTER_SEARCH, GNUNET_FS_uri_destroy(), GNUNET_FS_SearchContext::h, GNUNET_FS_SearchContext::master_result_map, GNUNET_FS_SearchContext::psearch_result, sc, GNUNET_FS_SearchContext::serialization, and GNUNET_FS_SearchContext::uri.

Referenced by deserialize_search(), and free_result().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ free_result()

static int free_result ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Iterator over search results freeing each.

Parameters
clsclosure, the struct GNUNET_FS_SearchContext *
keycurrent key code
valuevalue in the hash map, the struct GNUNET_FS_SearchResult *
Returns
GNUNET_YES (we should continue to iterate)

Definition at line 2773 of file fs_api.c.

2774 {
2775  struct GNUNET_FS_SearchResult *sr = value;
2776 
2777  if (NULL != sr->update_search)
2778  {
2780  GNUNET_assert (NULL == sr->update_search);
2781  }
2783  GNUNET_FS_uri_destroy (sr->uri);
2784  GNUNET_free (sr);
2785  return GNUNET_YES;
2786 }

References free_search_context(), GNUNET_assert, GNUNET_free, GNUNET_FS_meta_data_destroy(), GNUNET_FS_uri_destroy(), GNUNET_YES, GNUNET_FS_SearchResult::meta, GNUNET_FS_SearchResult::update_search, GNUNET_FS_SearchResult::uri, and value.

Referenced by free_search_context().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ deserialize_subdownload()

static int deserialize_subdownload ( void *  cls,
const char *  filename 
)
static

Function called with a filename of serialized sub-download to deserialize.

Parameters
clsthe struct GNUNET_FS_DownloadContext * (parent)
filenamecomplete filename (absolute path)
Returns
GNUNET_OK (continue to iterate)

Definition at line 2834 of file fs_api.c.

2835 {
2836  struct GNUNET_FS_DownloadContext *parent = cls;
2837  char *serialized;
2838  char *emsg;
2839  struct GNUNET_BIO_ReadHandle *rh;
2840 
2841  serialized = get_serialization_short_name (filename);
2843  if (NULL == rh)
2844  {
2846  _ (
2847  "Failed to resume sub-download `%s': could not open file `%s'\n"),
2848  serialized,
2849  filename);
2850  GNUNET_free (serialized);
2851  return GNUNET_OK;
2852  }
2853  deserialize_download (parent->h, rh, parent, NULL, serialized);
2854  if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
2855  {
2857  _ ("Failed to resume sub-download `%s': %s\n"),
2858  serialized,
2859  emsg);
2860  GNUNET_free (emsg);
2861  }
2862  GNUNET_free (serialized);
2863  return GNUNET_OK;
2864 }

References _, deserialize_download(), GNUNET_FS_DownloadContext::emsg, GNUNET_BIO_ReadHandle::emsg, filename, get_serialization_short_name(), GNUNET_BIO_read_close(), GNUNET_BIO_read_open_file(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_OK, GNUNET_FS_DownloadContext::h, and GNUNET_FS_DownloadContext::parent.

Referenced by deserialize_download().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ free_download_context()

static void free_download_context ( struct GNUNET_FS_DownloadContext dc)
static

Free this download context and all of its descendants.

(only works during deserialization since not all possible state it taken care of).

Parameters
dccontext to free

Definition at line 2875 of file fs_api.c.

2876 {
2877  struct GNUNET_FS_DownloadContext *dcc;
2878 
2879  if (NULL != dc->meta)
2881  if (NULL != dc->uri)