GNUnet  0.11.x
Data Structures | Macros | Functions
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_CONTAINER_MetaData *meta, struct GNUNET_FS_Uri **uri, struct GNUNET_FS_BlockOptions *bo, int *do_index, void **client_info)
 Signal the FS's progress function that we are resuming an upload. 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 informatin 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 36 of file fs_api.c.

Referenced by GNUNET_FS_start().

◆ 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 41 of file fs_api.c.

Referenced by GNUNET_FS_start().

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 50 of file fs_api.c.

References GNUNET_FS_QueueEntry::active, GNUNET_FS_Handle::active_blocks, GNUNET_FS_Handle::active_downloads, GNUNET_FS_QueueEntry::blocks, GNUNET_FS_QueueEntry::cls, GNUNET_CONTAINER_DLL_insert_after, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_TIME_absolute_get(), GNUNET_YES, GNUNET_FS_QueueEntry::h, GNUNET_FS_Handle::pending_head, GNUNET_FS_Handle::pending_tail, GNUNET_FS_Handle::running_head, GNUNET_FS_Handle::running_tail, GNUNET_FS_QueueEntry::start, GNUNET_FS_QueueEntry::start_time, and GNUNET_FS_QueueEntry::start_times.

Referenced by process_job_queue().

51 {
52  qe->active = GNUNET_YES;
53  qe->start (qe->cls);
54  qe->start_times++;
55  qe->h->active_blocks += qe->blocks;
56  qe->h->active_downloads++;
59  "Starting job %p (%u active)\n",
60  qe,
61  qe->h->active_downloads);
64  qe->h->running_tail,
65  qe->h->running_tail,
66  qe);
67 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_FS_QueueEntry * pending_head
Head of DLL of pending jobs.
Definition: fs_api.h:1113
unsigned int active_blocks
How many blocks do the active downloads have?
Definition: fs_api.h:1156
struct GNUNET_FS_QueueEntry * running_head
Head of DLL of running jobs.
Definition: fs_api.h:1103
int active
GNUNET_YES if the job is active now.
Definition: fs_api.h:490
#define GNUNET_CONTAINER_DLL_insert_after(head, tail, other, element)
Insert an element into a DLL after the given other element.
GNUNET_SCHEDULER_TaskCallback start
Function to call when the job is started.
Definition: fs_api.h:434
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
struct GNUNET_FS_QueueEntry * running_tail
Tail of DLL of running jobs.
Definition: fs_api.h:1108
struct GNUNET_FS_Handle * h
Handle to FS primary context.
Definition: fs_api.h:449
unsigned int active_downloads
How many actual downloads do we have running right now?
Definition: fs_api.h:1151
struct GNUNET_TIME_Absolute start_time
Time the job was started last.
Definition: fs_api.h:464
unsigned int blocks
How many blocks do the active downloads have?
Definition: fs_api.h:475
#define GNUNET_log(kind,...)
struct GNUNET_FS_QueueEntry * pending_tail
Tail of DLL of pending jobs.
Definition: fs_api.h:1118
void * cls
Closure for start and stop.
Definition: fs_api.h:444
unsigned int start_times
How often have we (re)started this download?
Definition: fs_api.h:485
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 77 of file fs_api.c.

References GNUNET_FS_QueueEntry::active, GNUNET_FS_Handle::active_blocks, GNUNET_FS_Handle::active_downloads, GNUNET_FS_QueueEntry::blocks, GNUNET_FS_QueueEntry::cls, 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_FS_QueueEntry::h, GNUNET_FS_Handle::pending_head, GNUNET_FS_Handle::pending_tail, GNUNET_FS_QueueEntry::run_time, GNUNET_FS_Handle::running_head, GNUNET_FS_Handle::running_tail, GNUNET_FS_QueueEntry::start_time, and GNUNET_FS_QueueEntry::stop.

Referenced by GNUNET_FS_dequeue_(), and process_job_queue().

78 {
79  qe->active = GNUNET_NO;
80  qe->stop (qe->cls);
81  GNUNET_assert (0 < qe->h->active_downloads);
82  qe->h->active_downloads--;
83  qe->h->active_blocks -= qe->blocks;
86  qe->start_time));
88  "Stopping job %p (%u active)\n",
89  qe,
90  qe->h->active_downloads);
93  qe->h->pending_tail,
94  qe->h->pending_tail,
95  qe);
96 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_FS_QueueEntry * pending_head
Head of DLL of pending jobs.
Definition: fs_api.h:1113
unsigned int active_blocks
How many blocks do the active downloads have?
Definition: fs_api.h:1156
struct GNUNET_FS_QueueEntry * running_head
Head of DLL of running jobs.
Definition: fs_api.h:1103
int active
GNUNET_YES if the job is active now.
Definition: fs_api.h:490
#define GNUNET_CONTAINER_DLL_insert_after(head, tail, other, element)
Insert an element into a DLL after the given other element.
struct GNUNET_FS_QueueEntry * running_tail
Tail of DLL of running jobs.
Definition: fs_api.h:1108
struct GNUNET_FS_Handle * h
Handle to FS primary context.
Definition: fs_api.h:449
unsigned int active_downloads
How many actual downloads do we have running right now?
Definition: fs_api.h:1151
struct GNUNET_TIME_Absolute start_time
Time the job was started last.
Definition: fs_api.h:464
struct GNUNET_TIME_Relative GNUNET_TIME_relative_add(struct GNUNET_TIME_Relative a1, struct GNUNET_TIME_Relative a2)
Add relative times together.
Definition: time.c:579
struct GNUNET_TIME_Relative run_time
Total amount of time the job has been running (except for the current run).
Definition: fs_api.h:470
unsigned int blocks
How many blocks do the active downloads have?
Definition: fs_api.h:475
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
Definition: time.c:375
#define GNUNET_log(kind,...)
GNUNET_SCHEDULER_TaskCallback stop
Function to call when the job needs to stop (or is done / dequeued).
Definition: fs_api.h:439
struct GNUNET_FS_QueueEntry * pending_tail
Tail of DLL of pending jobs.
Definition: fs_api.h:1118
void * cls
Closure for start and stop.
Definition: fs_api.h:444
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 106 of file fs_api.c.

References GNUNET_FS_Handle::active_blocks, GNUNET_FS_Handle::active_downloads, GNUNET_FS_Handle::avg_block_latency, GNUNET_FS_QueueEntry::blocks, 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_FS_Handle::max_parallel_downloads, GNUNET_FS_Handle::max_parallel_requests, GNUNET_FS_QueueEntry::next, GNUNET_FS_Handle::pending_head, GNUNET_FS_QueueEntry::priority, qe, GNUNET_FS_Handle::queue_job, GNUNET_TIME_Relative::rel_value_us, GNUNET_FS_Handle::running_head, start_job(), GNUNET_FS_QueueEntry::start_time, GNUNET_FS_QueueEntry::start_times, and stop_job().

Referenced by GNUNET_FS_dequeue_(), and GNUNET_FS_queue_().

107 {
108  struct GNUNET_FS_Handle *h = cls;
109  struct GNUNET_FS_QueueEntry *qe;
110  struct GNUNET_FS_QueueEntry *next;
111  struct GNUNET_TIME_Relative run_time;
112  struct GNUNET_TIME_Relative restart_at;
113  struct GNUNET_TIME_Relative rst;
115  unsigned int num_downloads_waiting;
116  unsigned int num_downloads_active;
117  unsigned int num_downloads_expired;
118  unsigned int num_probes_active;
119  unsigned int num_probes_waiting;
120  unsigned int num_probes_expired;
121  int num_probes_change;
122  int num_downloads_change;
123  int block_limit_hit;
124 
125  h->queue_job = NULL;
126  /* restart_at will be set to the time when it makes sense to
127  re-evaluate the job queue (unless, of course, jobs complete
128  or are added, then we'll be triggered immediately */
129  restart_at = GNUNET_TIME_UNIT_FOREVER_REL;
130  /* first, calculate some basic statistics on pending jobs */
131  num_probes_waiting = 0;
132  num_downloads_waiting = 0;
133  for (qe = h->pending_head; NULL != qe; qe = qe->next)
134  {
135  switch (qe->priority)
136  {
138  num_probes_waiting++;
139  break;
140 
142  num_downloads_waiting++;
143  break;
144 
145  default:
146  GNUNET_break (0);
147  break;
148  }
149  }
150  /* now, calculate some basic statistics on running jobs */
151  num_probes_active = 0;
152  num_probes_expired = 0;
153  num_downloads_active = 0;
154  num_downloads_expired = 0;
155  next = h->running_head;
156  while (NULL != (qe = next))
157  {
158  next = qe->next;
159  switch (qe->priority)
160  {
163  end_time = GNUNET_TIME_absolute_add (qe->start_time, run_time);
165  if (0 == rst.rel_value_us)
166  {
167  num_probes_expired++;
168  stop_job (qe);
169  }
170  else
171  {
172  num_probes_active++;
173  restart_at = GNUNET_TIME_relative_min (rst, restart_at);
174  }
175  break;
176 
178  run_time =
180  qe->blocks * qe->start_times);
181  end_time = GNUNET_TIME_absolute_add (qe->start_time, run_time);
183  if (0 == rst.rel_value_us)
184  {
185  num_downloads_expired++;
186  stop_job (qe);
187  }
188  else
189  {
190  num_downloads_active++;
191  restart_at = GNUNET_TIME_relative_min (rst, restart_at);
192  }
193  break;
194 
195  default:
196  GNUNET_break (0);
197  break;
198  }
199  }
201  num_downloads_active + num_probes_active);
203  "PA: %u, PE: %u, PW: %u; DA: %u, DE: %u, DW: %u\n",
204  num_probes_active,
205  num_probes_expired,
206  num_probes_waiting,
207  num_downloads_active,
208  num_downloads_expired,
209  num_downloads_waiting);
210  GNUNET_break (h->active_downloads + num_probes_active <=
212  /* calculate start/stop decisions */
213  if (h->active_downloads + num_downloads_waiting > h->max_parallel_downloads)
214  {
215  /* stop as many probes as there are downloads and probes */
216  num_probes_change = -GNUNET_MIN (num_probes_active, num_downloads_waiting);
217  /* start as many downloads as there are free slots, including those
218  we just opened up */
219  num_downloads_change =
220  h->max_parallel_downloads - h->active_downloads - num_probes_change;
221  }
222  else
223  {
224  /* start all downloads (we can) */
225  num_downloads_change = num_downloads_waiting;
226  /* also start probes if there is room, but use a lower cap of (mpd/4) + 1 */
227  if (1 + h->max_parallel_downloads / 4 >=
228  (h->active_downloads + num_downloads_change))
229  num_probes_change =
230  GNUNET_MIN (num_probes_waiting,
231  (1 + h->max_parallel_downloads / 4)
232  - (h->active_downloads + num_downloads_change));
233  else
234  num_probes_change = 0;
235  }
236  GNUNET_break (num_downloads_change <= num_downloads_waiting);
238  "Changing %d probes and %d/%u/%u downloads\n",
239  num_probes_change,
240  num_downloads_change,
241  (unsigned int) h->active_downloads,
242  (unsigned int) h->max_parallel_downloads);
243  /* actually stop probes */
244  next = h->running_head;
245  while (NULL != (qe = next))
246  {
247  next = qe->next;
249  continue;
250  if (num_probes_change < 0)
251  {
252  stop_job (qe);
253  num_probes_change++;
254  if (0 == num_probes_change)
255  break;
256  }
257  }
258  GNUNET_break (0 <= num_probes_change);
259 
260  /* start some more tasks if we now have empty slots */
261  block_limit_hit = GNUNET_NO;
262  next = h->pending_head;
263  while ((NULL != (qe = next)) &&
264  ((num_probes_change > 0) || (num_downloads_change > 0)))
265  {
266  next = qe->next;
267  switch (qe->priority)
268  {
270  if (num_probes_change > 0)
271  {
272  start_job (qe);
273  num_probes_change--;
275  restart_at = GNUNET_TIME_relative_min (run_time, restart_at);
276  }
277  break;
278 
280  if ((num_downloads_change > 0) &&
281  ((qe->blocks + h->active_blocks <= h->max_parallel_requests) ||
282  ((qe->blocks > h->max_parallel_requests) &&
283  (0 == h->active_downloads))))
284  {
285  start_job (qe);
286  num_downloads_change--;
287  }
288  else if (num_downloads_change > 0)
289  block_limit_hit = GNUNET_YES;
290  break;
291 
292  default:
293  GNUNET_break (0);
294  break;
295  }
296  }
297  GNUNET_break ((0 == num_downloads_change) || (GNUNET_YES == block_limit_hit));
298  GNUNET_break (0 == num_probes_change);
299 
300  GNUNET_log (
302  "AD: %u, MP: %u; %d probes and %d downloads to start, will run again in %s\n",
303  h->active_downloads,
305  num_probes_change,
306  num_downloads_change,
308 
309  /* make sure we run again, callbacks might have
310  already re-scheduled the job, so cancel such
311  an operation (if it exists) */
312  if (NULL != h->queue_job)
314  h->queue_job =
316 }
This is a probe (low priority).
Definition: fs_api.h:407
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
struct GNUNET_TIME_Relative avg_block_latency
Average time we take for a single request to be satisfied.
Definition: fs_api.h:1146
struct GNUNET_SCHEDULER_Task * queue_job
Task that processes the jobs in the running and pending queues (and moves jobs around as needed)...
Definition: fs_api.h:1134
Master context for most FS operations.
Definition: fs_api.h:1068
static struct GNUNET_TIME_Absolute end_time
At what time MUST the current hostlist request be done?
#define GNUNET_TIME_UNIT_MINUTES
One minute.
static void stop_job(struct GNUNET_FS_QueueEntry *qe)
Stop the given job (send signal, remove from active queue, update counters and state).
Definition: fs_api.c:77
struct GNUNET_FS_QueueEntry * pending_head
Head of DLL of pending jobs.
Definition: fs_api.h:1113
static void process_job_queue(void *cls)
Process the jobs in the job queue, possibly starting some and stopping others.
Definition: fs_api.c:106
unsigned int active_blocks
How many blocks do the active downloads have?
Definition: fs_api.h:1156
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_add(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
Add a given relative duration to the given start time.
Definition: time.c:395
struct GNUNET_FS_QueueEntry * running_head
Head of DLL of running jobs.
Definition: fs_api.h:1103
unsigned int max_parallel_requests
Maximum number of parallel requests.
Definition: fs_api.h:1171
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
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:1269
enum GNUNET_FS_QueuePriority priority
How important is this download?
Definition: fs_api.h:480
#define GNUNET_MIN(a, b)
Definition: gnunet_common.h:93
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:702
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:442
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
static void start_job(struct GNUNET_FS_QueueEntry *qe)
Start the given job (send signal, remove from pending queue, update counters and state).
Definition: fs_api.c:50
unsigned int active_downloads
How many actual downloads do we have running right now?
Definition: fs_api.h:1151
struct GNUNET_TIME_Relative GNUNET_TIME_relative_min(struct GNUNET_TIME_Relative t1, struct GNUNET_TIME_Relative t2)
Return the minimum of two relative time values.
Definition: time.c:272
struct GNUNET_TIME_Absolute start_time
Time the job was started last.
Definition: fs_api.h:464
unsigned int blocks
How many blocks do the active downloads have?
Definition: fs_api.h:475
struct GNUNET_FS_QueueEntry * next
This is a linked list.
Definition: fs_api.h:424
#define GNUNET_log(kind,...)
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:331
Time for absolute times used by GNUnet, in microseconds.
unsigned int max_parallel_downloads
Maximum number of parallel downloads.
Definition: fs_api.h:1166
Entry in the job queue.
Definition: fs_api.h:419
struct GNUNET_TIME_Relative GNUNET_TIME_relative_saturating_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Saturating multiply relative time by a given factor.
Definition: time.c:501
Default priority.
Definition: fs_api.h:412
unsigned int start_times
How often have we (re)started this download?
Definition: fs_api.h:485
Time for relative time used by GNUnet, in microseconds.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
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 jobs uses
priorityhow important is this download
Returns
queue handle

Definition at line 331 of file fs_api.c.

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_FS_QueueEntry::h, GNUNET_FS_Handle::pending_head, GNUNET_FS_Handle::pending_tail, GNUNET_FS_QueueEntry::priority, process_job_queue(), qe, GNUNET_FS_Handle::queue_job, GNUNET_FS_QueueEntry::queue_time, start, GNUNET_FS_QueueEntry::start, and GNUNET_FS_QueueEntry::stop.

Referenced by GNUNET_FS_download_resume(), and GNUNET_FS_download_start_downloading_().

337 {
338  struct GNUNET_FS_QueueEntry *qe;
339 
340  qe = GNUNET_new (struct GNUNET_FS_QueueEntry);
341  qe->h = h;
342  qe->start = start;
343  qe->stop = stop;
344  qe->cls = cls;
346  qe->blocks = blocks;
347  qe->priority = priority;
349  h->pending_tail,
350  h->pending_tail,
351  qe);
352  if (NULL != h->queue_job)
355  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Queueing job %p\n", qe);
356  return qe;
357 }
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
struct GNUNET_SCHEDULER_Task * queue_job
Task that processes the jobs in the running and pending queues (and moves jobs around as needed)...
Definition: fs_api.h:1134
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
struct GNUNET_FS_QueueEntry * pending_head
Head of DLL of pending jobs.
Definition: fs_api.h:1113
static void process_job_queue(void *cls)
Process the jobs in the job queue, possibly starting some and stopping others.
Definition: fs_api.c:106
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
struct GNUNET_TIME_Absolute queue_time
Time the job was originally queued.
Definition: fs_api.h:459
enum GNUNET_FS_QueuePriority priority
How important is this download?
Definition: fs_api.h:480
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:1296
#define GNUNET_CONTAINER_DLL_insert_after(head, tail, other, element)
Insert an element into a DLL after the given other element.
GNUNET_SCHEDULER_TaskCallback start
Function to call when the job is started.
Definition: fs_api.h:434
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
struct GNUNET_FS_Handle * h
Handle to FS primary context.
Definition: fs_api.h:449
unsigned int blocks
How many blocks do the active downloads have?
Definition: fs_api.h:475
#define GNUNET_log(kind,...)
GNUNET_SCHEDULER_TaskCallback stop
Function to call when the job needs to stop (or is done / dequeued).
Definition: fs_api.h:439
struct GNUNET_FS_QueueEntry * pending_tail
Tail of DLL of pending jobs.
Definition: fs_api.h:1118
void * cls
Closure for start and stop.
Definition: fs_api.h:444
Entry in the job queue.
Definition: fs_api.h:419
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
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 366 of file fs_api.c.

References GNUNET_FS_QueueEntry::active, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), GNUNET_YES, h, GNUNET_FS_QueueEntry::h, GNUNET_FS_Handle::pending_head, GNUNET_FS_Handle::pending_tail, process_job_queue(), GNUNET_FS_Handle::queue_job, and stop_job().

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

367 {
368  struct GNUNET_FS_Handle *h;
369 
370  h = qe->h;
371  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Dequeueing job %p\n", qe);
372  if (GNUNET_YES == qe->active)
373  stop_job (qe);
375  GNUNET_free (qe);
376  if (NULL != h->queue_job)
379 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_SCHEDULER_Task * queue_job
Task that processes the jobs in the running and pending queues (and moves jobs around as needed)...
Definition: fs_api.h:1134
Master context for most FS operations.
Definition: fs_api.h:1068
static void stop_job(struct GNUNET_FS_QueueEntry *qe)
Stop the given job (send signal, remove from active queue, update counters and state).
Definition: fs_api.c:77
struct GNUNET_FS_QueueEntry * pending_head
Head of DLL of pending jobs.
Definition: fs_api.h:1113
static void process_job_queue(void *cls)
Process the jobs in the job queue, possibly starting some and stopping others.
Definition: fs_api.c:106
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
int active
GNUNET_YES if the job is active now.
Definition: fs_api.h:490
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:1296
struct GNUNET_FS_Handle * h
Handle to FS primary context.
Definition: fs_api.h:449
#define GNUNET_log(kind,...)
struct GNUNET_FS_QueueEntry * pending_tail
Tail of DLL of pending jobs.
Definition: fs_api.h:1118
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
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 391 of file fs_api.c.

References GNUNET_CONTAINER_DLL_insert, GNUNET_new, ret, TopLevelActivity::ssf, TopLevelActivity::ssf_cls, GNUNET_FS_Handle::top_head, and GNUNET_FS_Handle::top_tail.

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().

394 {
395  struct TopLevelActivity *ret;
396 
397  ret = GNUNET_new (struct TopLevelActivity);
398  ret->ssf = ssf;
399  ret->ssf_cls = ssf_cls;
401  return ret;
402 }
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct TopLevelActivity * top_tail
Tail of DLL of top-level activities.
Definition: fs_api.h:1098
struct TopLevelActivity * top_head
Head of DLL of top-level activities.
Definition: fs_api.h:1093
void * ssf_cls
Closure for &#39;ssf&#39; (some struct GNUNET_FS_XXXHandle*)
Definition: fs_api.h:1036
We track all of the top-level activities of FS so that we can signal &#39;suspend&#39; on shutdown...
Definition: fs_api.h:1016
SuspendSignalFunction ssf
Function to call for suspend-signalling and clean up.
Definition: fs_api.h:1031
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 412 of file fs_api.c.

References GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_FS_Handle::top_head, and GNUNET_FS_Handle::top_tail.

Referenced by GNUNET_FS_download_signal_suspend_(), GNUNET_FS_download_stop(), 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().

413 {
415  GNUNET_free (top);
416 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct TopLevelActivity * top_tail
Tail of DLL of top-level activities.
Definition: fs_api.h:1098
struct TopLevelActivity * top_head
Head of DLL of top-level activities.
Definition: fs_api.h:1093
#define GNUNET_free(ptr)
Wrapper around free.
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 457 of file fs_api.c.

References _, 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, and ret.

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

462 {
463  struct FileInfo *fi = cls;
464  ssize_t ret;
465 
466  if (UINT64_MAX == offset)
467  {
468  if (NULL != fi->fd)
469  {
471  fi->fd = NULL;
472  }
473  return 0;
474  }
475  if (0 == max)
476  {
477  if (NULL != fi->fd)
479  GNUNET_free (fi->filename);
480  GNUNET_free (fi);
481  return 0;
482  }
483  if (NULL == fi->fd)
484  {
485  fi->fd = GNUNET_DISK_file_open (fi->filename,
488  if (NULL == fi->fd)
489  {
490  GNUNET_asprintf (emsg,
491  _ ("Could not open file `%s': %s"),
492  fi->filename,
493  strerror (errno));
494  return 0;
495  }
496  }
497  if ((GNUNET_SYSERR ==
499  (-1 == (ret = GNUNET_DISK_file_read (fi->fd, buf, max))))
500  {
501  GNUNET_asprintf (emsg,
502  _ ("Could not read file `%s': %s"),
503  fi->filename,
504  strerror (errno));
505  return 0;
506  }
507  if (ret != max)
508  {
509  GNUNET_asprintf (emsg,
510  _ ("Short read reading from file `%s'!"),
511  fi->filename);
512  return 0;
513  }
514  return max;
515 }
Open the file for reading.
int GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1280
ssize_t GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: disk.c:732
Nobody is allowed to do anything to the file.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
struct GNUNET_DISK_FileHandle * fd
File descriptor, NULL if it has not yet been opened.
Definition: fs_api.c:432
off_t GNUNET_DISK_file_seek(const struct GNUNET_DISK_FileHandle *h, off_t offset, enum GNUNET_DISK_Seek whence)
Move the read/write pointer in a file.
Definition: disk.c:226
#define _(String)
GNU gettext support macro.
Definition: platform.h:184
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
static char buf[2048]
Seek an absolute position (from the start of the file).
char * filename
Name of the file to read.
Definition: fs_api.c:427
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:1203
Closure for GNUNET_FS_data_reader_file_().
Definition: fs_api.c:422
#define GNUNET_free(ptr)
Wrapper around free.
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 525 of file fs_api.c.

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

Referenced by deserialize_fi_node(), and GNUNET_FS_file_information_create_from_file().

526 {
527  struct FileInfo *fi;
528 
529  fi = GNUNET_new (struct FileInfo);
531  if (NULL == fi->filename)
532  {
533  GNUNET_free (fi);
534  return NULL;
535  }
536  return fi;
537 }
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static char * filename
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
Definition: strings.c:618
char * filename
Name of the file to read.
Definition: fs_api.c:427
Closure for GNUNET_FS_data_reader_file_().
Definition: fs_api.c:422
#define GNUNET_free(ptr)
Wrapper around free.
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 561 of file fs_api.c.

References data, GNUNET_free, and GNUNET_memcpy.

Referenced by deserialize_fi_node(), and GNUNET_FS_file_information_create_from_data().

566 {
567  char *data = cls;
568 
569  if (UINT64_MAX == offset)
570  return 0;
571  if (0 == max)
572  {
573  GNUNET_free (data);
574  return 0;
575  }
576  GNUNET_memcpy (buf, &data[offset], max);
577  return max;
578 }
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
static char buf[2048]
uint32_t data
The data value.
#define GNUNET_free(ptr)
Wrapper around free.
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 emtpy string for the directory)
Returns
NULL on error

Definition at line 591 of file fs_api.c.

References GNUNET_FS_Handle::cfg, GNUNET_FS_Handle::client_name, DIR_SEPARATOR_STR, GNUNET_FS_Handle::flags, GNUNET_asprintf(), GNUNET_CONFIGURATION_get_value_filename(), GNUNET_free, GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_OK, 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().

594 {
595  char *basename;
596  char *ret;
597 
598  if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
599  return NULL; /* persistence not requested */
601  "fs",
602  "STATE_DIR",
603  &basename))
604  return NULL;
605  GNUNET_asprintf (&ret,
606  "%s%s%s%s%s%s%s",
607  basename,
609  h->client_name,
611  ext,
613  ent);
614  GNUNET_free (basename);
615  return ret;
616 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
#define DIR_SEPARATOR_STR
Definition: platform.h:171
char * client_name
Name of our client.
Definition: fs_api.h:1078
int GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
#define GNUNET_free(ptr)
Wrapper around free.
Is persistence of operations desired? (will create SUSPEND/RESUME events).
enum GNUNET_FS_Flags flags
General flags.
Definition: fs_api.h:1161
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Definition: fs_api.h:1073
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 emtpy string for the directory)
Returns
NULL on error

Definition at line 631 of file fs_api.c.

References GNUNET_FS_Handle::cfg, GNUNET_FS_Handle::client_name, DIR_SEPARATOR_STR, GNUNET_FS_Handle::flags, GNUNET_asprintf(), GNUNET_CONFIGURATION_get_value_filename(), GNUNET_free, GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_OK, 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().

635 {
636  char *basename;
637  char *ret;
638 
639  if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
640  return NULL; /* persistence not requested */
642  "fs",
643  "STATE_DIR",
644  &basename))
645  return NULL;
646  GNUNET_asprintf (&ret,
647  "%s%s%s%s%s%s%s.dir%s%s",
648  basename,
650  h->client_name,
652  ext,
654  uni,
656  ent);
657  GNUNET_free (basename);
658  return ret;
659 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
#define DIR_SEPARATOR_STR
Definition: platform.h:171
char * client_name
Name of our client.
Definition: fs_api.h:1078
int GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
#define GNUNET_free(ptr)
Wrapper around free.
Is persistence of operations desired? (will create SUSPEND/RESUME events).
enum GNUNET_FS_Flags flags
General flags.
Definition: fs_api.h:1161
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Definition: fs_api.h:1073
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 emtpy string for the directory)
Returns
NULL on error

Definition at line 671 of file fs_api.c.

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

Referenced by deserialize_file_information(), and deserialize_search_result().

672 {
673  char *fn;
674  struct GNUNET_BIO_ReadHandle *ret;
675 
676  fn = get_serialization_file_name (h, ext, ent);
677  if (NULL == fn)
678  return NULL;
679  ret = GNUNET_BIO_read_open_file (fn);
680  GNUNET_free (fn);
681  return ret;
682 }
struct GNUNET_BIO_ReadHandle * GNUNET_BIO_read_open_file(const char *fn)
Open a file for reading.
Definition: bio.c:119
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static char * fn
Filename of the unique file.
static char * get_serialization_file_name(struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
Return the full filename where we would store state information (for serialization/deserialization).
Definition: fs_api.c:591
Handle for buffered reading.
Definition: bio.c:73
#define GNUNET_free(ptr)
Wrapper around free.
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 emtpy string for the directory)
Returns
NULL on error

Definition at line 694 of file fs_api.c.

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

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

695 {
696  char *fn;
697  struct GNUNET_BIO_WriteHandle *ret;
698 
699  fn = get_serialization_file_name (h, ext, ent);
700  if (NULL == fn)
701  return NULL;
702  ret = GNUNET_BIO_write_open_file (fn);
703  GNUNET_break (NULL != ret);
704  GNUNET_free (fn);
705  return ret;
706 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static char * fn
Filename of the unique file.
Handle for buffered writing.
Definition: bio.c:516
struct GNUNET_BIO_WriteHandle * GNUNET_BIO_write_open_file(const char *fn)
Open a file for writing.
Definition: bio.c:559
static char * get_serialization_file_name(struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
Return the full filename where we would store state information (for serialization/deserialization).
Definition: fs_api.c:591
#define GNUNET_free(ptr)
Wrapper around free.
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 emtpy string for the directory)
Returns
NULL on error

Definition at line 719 of file fs_api.c.

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

Referenced by GNUNET_FS_search_result_sync_().

723 {
724  char *fn;
725  struct GNUNET_BIO_WriteHandle *ret;
726 
727  fn = get_serialization_file_name_in_dir (h, ext, uni, ent);
728  if (NULL == fn)
729  return NULL;
730  ret = GNUNET_BIO_write_open_file (fn);
731  GNUNET_free (fn);
732  return ret;
733 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static char * fn
Filename of the unique file.
static char * get_serialization_file_name_in_dir(struct GNUNET_FS_Handle *h, const char *ext, const char *uni, const char *ent)
Return the full filename where we would store state information (for serialization/deserialization) t...
Definition: fs_api.c:631
Handle for buffered writing.
Definition: bio.c:516
struct GNUNET_BIO_WriteHandle * GNUNET_BIO_write_open_file(const char *fn)
Open a file for writing.
Definition: bio.c:559
#define GNUNET_free(ptr)
Wrapper around free.
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 744 of file fs_api.c.

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

Referenced by deserialize_search_file(), deserialize_unindex_file(), fip_signal_stop(), free_search_context(), GNUNET_FS_download_stop(), 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().

747 {
748  char *filename;
749 
750  if ((NULL == ent) || (0 == strlen (ent)))
751  {
752  GNUNET_break (0);
753  return;
754  }
755  filename = get_serialization_file_name (h, ext, ent);
756  if (NULL != filename)
757  {
758  if ((0 != unlink (filename)) && (ENOENT != errno))
760  GNUNET_free (filename);
761  }
762 }
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
static char * filename
static char * get_serialization_file_name(struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
Return the full filename where we would store state information (for serialization/deserialization).
Definition: fs_api.c:591
#define GNUNET_free(ptr)
Wrapper around free.
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 774 of file fs_api.c.

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

Referenced by deserialize_search_result(), and GNUNET_FS_search_result_sync_().

778 {
779  char *filename;
780 
781  if ((NULL == ent) || (0 == strlen (ent)))
782  {
783  GNUNET_break (0);
784  return;
785  }
786  filename = get_serialization_file_name_in_dir (h, ext, uni, ent);
787  if (NULL == filename)
788  return;
789  if (0 != unlink (filename))
791  GNUNET_free (filename);
792 }
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
static char * get_serialization_file_name_in_dir(struct GNUNET_FS_Handle *h, const char *ext, const char *uni, const char *ent)
Return the full filename where we would store state information (for serialization/deserialization) t...
Definition: fs_api.c:631
static char * filename
#define GNUNET_free(ptr)
Wrapper around free.
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 803 of file fs_api.c.

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, and GNUNET_YES.

Referenced by free_search_context(), GNUNET_FS_download_stop(), and GNUNET_FS_search_stop().

806 {
807  char *dn;
808 
809  if (NULL == uni)
810  return;
811  dn = get_serialization_file_name_in_dir (h, ext, uni, "");
812  if (NULL == dn)
813  return;
817  GNUNET_free (dn);
818 }
int GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition: disk.c:503
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
static char * get_serialization_file_name_in_dir(struct GNUNET_FS_Handle *h, const char *ext, const char *uni, const char *ent)
Return the full filename where we would store state information (for serialization/deserialization) t...
Definition: fs_api.c:631
int GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
Definition: disk.c:1028
#define GNUNET_free(ptr)
Wrapper around free.
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 836 of file fs_api.c.

References GNUNET_BIO_write_int64(), and GNUNET_TIME_absolute_get_duration().

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

838 {
839  struct GNUNET_TIME_Relative dur;
840 
841  dur = GNUNET_TIME_absolute_get_duration (timestamp);
842  return GNUNET_BIO_write_int64 (wh, "start time", dur.rel_value_us);
843 }
int GNUNET_BIO_write_int64(struct GNUNET_BIO_WriteHandle *h, const char *what, int64_t i)
Write an (u)int64_t.
Definition: bio.c:956
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
Definition: time.c:375
Time for relative time used by GNUnet, in microseconds.
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 861 of file fs_api.c.

References deserialize_file_information(), FileInfo::filename, GNUNET_BIO_read_int64(), GNUNET_OK, GNUNET_SYSERR, GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_subtract(), h, and GNUNET_TIME_Relative::rel_value_us.

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

863 {
864  struct GNUNET_TIME_Relative dur;
865 
866  if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, "start time",
867  (int64_t *) &dur.rel_value_us))
868  return GNUNET_SYSERR;
870  return GNUNET_OK;
871 }
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_subtract(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
Subtract a given relative duration from the given start time.
Definition: time.c:422
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
int GNUNET_BIO_read_int64(struct GNUNET_BIO_ReadHandle *h, const char *what, int64_t *i)
Read an (u)int64_t.
Definition: bio.c:500
Time for relative time used by GNUnet, in microseconds.
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 infromation
Returns
NULL on error

Definition at line 1159 of file fs_api.c.

References _, deserialize_fi_node(), GNUNET_BIO_ReadHandle::emsg, fn, 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, and ret.

Referenced by deserialize_fi_node(), deserialize_publish_file(), and read_start_time().

1160 {
1162  struct GNUNET_BIO_ReadHandle *rh;
1163  char *emsg;
1164  char *fn;
1165 
1167  if (NULL == rh)
1168  return NULL;
1169  ret = deserialize_fi_node (h, filename, rh);
1170  if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
1171  {
1173  _ ("Failed to resume publishing information `%s': %s\n"),
1174  filename,
1175  emsg);
1176  GNUNET_free (emsg);
1177  }
1178  if (NULL == ret)
1179  {
1180  fn =
1182  if (NULL != fn)
1183  {
1184  if (0 != unlink (fn))
1186  GNUNET_free (fn);
1187  }
1188  }
1189  return ret;
1190 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Information for a file or directory that is about to be published.
Definition: fs_api.h:226
int GNUNET_BIO_read_close(struct GNUNET_BIO_ReadHandle *h, char **emsg)
Close an open handle.
Definition: bio.c:166
#define _(String)
GNU gettext support macro.
Definition: platform.h:184
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:898
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
static char * fn
Filename of the unique file.
static struct GNUNET_BIO_ReadHandle * get_read_handle(struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
Return a read handle for deserialization.
Definition: fs_api.c:671
static char * filename
#define GNUNET_FS_SYNC_PATH_FILE_INFO
Name of the directory with files that are being published.
Definition: fs_api.h:81
static char * get_serialization_file_name(struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
Return the full filename where we would store state information (for serialization/deserialization).
Definition: fs_api.c:591
#define GNUNET_log(kind,...)
char * emsg
Error message, NULL if there were no errors.
Definition: bio.c:88
Handle for buffered reading.
Definition: bio.c:73
#define GNUNET_free(ptr)
Wrapper around free.
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 infromation
rhhandle for reading
Returns
NULL on error

Definition at line 898 of file fs_api.c.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_FS_BlockOptions::anonymity_level, testconfigure::b, 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, GNUNET_FS_FileInformation::data, deserialize_file_information(), 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, FileInfo::filename, GNUNET_BIO_read(), GNUNET_BIO_read_int32(), GNUNET_BIO_read_int64(), GNUNET_BIO_read_meta_data(), 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_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::h, GNUNET_FS_FileInformation::is_directory, GNUNET_FS_FileInformation::is_published, GNUNET_FS_FileInformation::keywords, GNUNET_FS_FileInformation::meta, GNUNET_FS_FileInformation::next, read_start_time(), GNUNET_FS_BlockOptions::replication_level, ret, GNUNET_FS_FileInformation::serialization, GNUNET_FS_FileInformation::sks_uri, and GNUNET_FS_FileInformation::start_time.

Referenced by deserialize_file_information().

901 {
903  struct GNUNET_FS_FileInformation *nxt;
904  char b;
905  char *ksks;
906  char *chks;
907  char *skss;
908  char *filename;
909  uint32_t dsize;
910 
911  if (GNUNET_OK != GNUNET_BIO_read (rh, "status flag", &b, sizeof(b)))
912  {
913  GNUNET_break (0);
914  return NULL;
915  }
916  ret = GNUNET_new (struct GNUNET_FS_FileInformation);
917  ret->h = h;
918  ksks = NULL;
919  chks = NULL;
920  skss = NULL;
921  filename = NULL;
922  if ((GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "metadata", &ret->meta)) ||
923  (GNUNET_OK != GNUNET_BIO_read_string (rh, "ksk-uri", &ksks, 32 * 1024)) ||
924  ((NULL != ksks) &&
925  ((NULL == (ret->keywords = GNUNET_FS_uri_parse (ksks, NULL))) ||
927  (GNUNET_OK != GNUNET_BIO_read_string (rh, "chk-uri", &chks, 1024)) ||
928  ((NULL != chks) &&
929  ((NULL == (ret->chk_uri = GNUNET_FS_uri_parse (chks, NULL))) ||
930  (GNUNET_YES != GNUNET_FS_uri_test_chk (ret->chk_uri)))) ||
931  (GNUNET_OK != GNUNET_BIO_read_string (rh, "sks-uri", &skss, 1024)) ||
932  ((NULL != skss) &&
933  ((NULL == (ret->sks_uri = GNUNET_FS_uri_parse (skss, NULL))) ||
934  (GNUNET_YES != GNUNET_FS_uri_test_sks (ret->sks_uri)))) ||
935  (GNUNET_OK != read_start_time (rh, &ret->start_time)) ||
936  (GNUNET_OK !=
937  GNUNET_BIO_read_string (rh, "emsg", &ret->emsg, 16 * 1024)) ||
938  (GNUNET_OK !=
939  GNUNET_BIO_read_string (rh, "fn", &ret->filename, 16 * 1024)) ||
940  (GNUNET_OK !=
942  rh,
943  "expiration time",
944  (int64_t *) &ret->bo.expiration_time.abs_value_us)) ||
946  rh,
947  "anonymity level",
948  (int32_t *) &ret->bo.anonymity_level)) ||
950  rh,
951  "content priority",
952  (int32_t *) &ret->bo.content_priority)) ||
954  rh,
955  "replication level",
956  (int32_t *) &ret->bo.replication_level)))
957  {
958  GNUNET_break (0);
959  goto cleanup;
960  }
961  switch (b)
962  {
963  case 0: /* file-insert */
965  rh,
966  "file size",
967  (int64_t *) &ret->data.file.file_size))
968  {
969  GNUNET_break (0);
970  goto cleanup;
971  }
972  ret->is_directory = GNUNET_NO;
973  ret->data.file.do_index = GNUNET_NO;
974  ret->data.file.have_hash = GNUNET_NO;
975  ret->data.file.index_start_confirmed = GNUNET_NO;
976  if (GNUNET_NO == ret->is_published)
977  {
978  if (NULL == ret->filename)
979  {
980  ret->data.file.reader = &GNUNET_FS_data_reader_copy_;
981  ret->data.file.reader_cls =
982  GNUNET_malloc_large (ret->data.file.file_size);
983  if (ret->data.file.reader_cls == NULL)
984  goto cleanup;
985  if (GNUNET_OK != GNUNET_BIO_read (rh,
986  "file-data",
987  ret->data.file.reader_cls,
988  ret->data.file.file_size))
989  {
990  GNUNET_break (0);
991  goto cleanup;
992  }
993  }
994  else
995  {
996  ret->data.file.reader = &GNUNET_FS_data_reader_file_;
997  ret->data.file.reader_cls =
999  }
1000  }
1001  break;
1002 
1003  case 1: /* file-index, no hash */
1004  if (NULL == ret->filename)
1005  {
1006  GNUNET_break (0);
1007  goto cleanup;
1008  }
1010  rh,
1011  "file size",
1012  (int64_t *) &ret->data.file.file_size))
1013  {
1014  GNUNET_break (0);
1015  goto cleanup;
1016  }
1017  ret->is_directory = GNUNET_NO;
1018  ret->data.file.do_index = GNUNET_YES;
1019  ret->data.file.have_hash = GNUNET_NO;
1020  ret->data.file.index_start_confirmed = GNUNET_NO;
1021  ret->data.file.reader = &GNUNET_FS_data_reader_file_;
1022  ret->data.file.reader_cls =
1024  break;
1025 
1026  case 2: /* file-index-with-hash */
1027  if (NULL == ret->filename)
1028  {
1029  GNUNET_break (0);
1030  goto cleanup;
1031  }
1033  rh,
1034  "file size",
1035  (int64_t *) &ret->data.file.file_size)) ||
1036  (GNUNET_OK != GNUNET_BIO_read (rh,
1037  "fileid",
1038  &ret->data.file.file_id,
1039  sizeof(struct GNUNET_HashCode))))
1040  {
1041  GNUNET_break (0);
1042  goto cleanup;
1043  }
1044  ret->is_directory = GNUNET_NO;
1045  ret->data.file.do_index = GNUNET_YES;
1046  ret->data.file.have_hash = GNUNET_YES;
1047  ret->data.file.index_start_confirmed = GNUNET_NO;
1048  ret->data.file.reader = &GNUNET_FS_data_reader_file_;
1049  ret->data.file.reader_cls =
1051  break;
1052 
1053  case 3: /* file-index-with-hash-confirmed */
1054  if (NULL == ret->filename)
1055  {
1056  GNUNET_break (0);
1057  goto cleanup;
1058  }
1060  rh,
1061  "file size",
1062  (int64_t *) &ret->data.file.file_size)) ||
1063  (GNUNET_OK != GNUNET_BIO_read (rh,
1064  "fileid",
1065  &ret->data.file.file_id,
1066  sizeof(struct GNUNET_HashCode))))
1067  {
1068  GNUNET_break (0);
1069  goto cleanup;
1070  }
1071  ret->is_directory = GNUNET_NO;
1072  ret->data.file.do_index = GNUNET_YES;
1073  ret->data.file.have_hash = GNUNET_YES;
1074  ret->data.file.index_start_confirmed = GNUNET_YES;
1075  ret->data.file.reader = &GNUNET_FS_data_reader_file_;
1076  ret->data.file.reader_cls =
1078  break;
1079 
1080  case 4: /* directory */
1081  ret->is_directory = GNUNET_YES;
1082  if ((GNUNET_OK != GNUNET_BIO_read_int32 (rh, "dsize",
1083  (int32_t *) &dsize)) ||
1084  (GNUNET_OK !=
1086  rh,
1087  "contents completed",
1088  (int64_t *) &ret->data.dir.contents_completed)) ||
1089  (GNUNET_OK !=
1091  rh,
1092  "contents size",
1093  (int64_t *) &ret->data.dir.contents_size)) ||
1094  (NULL == (ret->data.dir.dir_data = GNUNET_malloc_large (dsize))) ||
1095  (GNUNET_OK !=
1096  GNUNET_BIO_read (rh, "dir-data", ret->data.dir.dir_data, dsize)) ||
1097  (GNUNET_OK !=
1098  GNUNET_BIO_read_string (rh, "ent-filename", &filename, 16 * 1024)))
1099  {
1100  GNUNET_break (0);
1101  goto cleanup;
1102  }
1103  ret->data.dir.dir_size = (uint32_t) dsize;
1104  if (NULL != filename)
1105  {
1106  ret->data.dir.entries = deserialize_file_information (h, filename);
1107  GNUNET_free (filename);
1108  filename = NULL;
1109  nxt = ret->data.dir.entries;
1110  while (NULL != nxt)
1111  {
1112  nxt->dir = ret;
1113  nxt = nxt->next;
1114  }
1115  }
1116  break;
1117 
1118  default:
1119  GNUNET_break (0);
1120  goto cleanup;
1121  }
1122  ret->serialization = GNUNET_strdup (fn);
1123  if (GNUNET_OK !=
1124  GNUNET_BIO_read_string (rh, "nxt-filename", &filename, 16 * 1024))
1125  {
1126  GNUNET_break (0);
1127  goto cleanup;
1128  }
1129  if (NULL != filename)
1130  {
1131  ret->next = deserialize_file_information (h, filename);
1132  GNUNET_free (filename);
1133  filename = NULL;
1134  }
1135  GNUNET_free (ksks);
1136  GNUNET_free (skss);
1137  GNUNET_free (chks);
1138  return ret;
1139 cleanup:
1140  GNUNET_free (ksks);
1141  GNUNET_free (chks);
1142  GNUNET_free (skss);
1143  GNUNET_free (filename);
1144  GNUNET_FS_file_information_destroy (ret, NULL, NULL);
1145  return NULL;
1146 }
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...
struct GNUNET_FS_FileInformation * entries
Linked list of entries in the directory.
Definition: fs_api.h:361
int GNUNET_FS_uri_test_ksk(const struct GNUNET_FS_Uri *uri)
Is this a keyword URI?
Definition: fs_uri.c:1334
struct GNUNET_FS_FileInformation * dir
If this is a file in a directory, "dir" refers to the directory; otherwise NULL.
Definition: fs_api.h:237
int GNUNET_BIO_read_int32(struct GNUNET_BIO_ReadHandle *h, const char *what, int32_t *i)
Read an (u)int32_t.
Definition: bio.c:478
struct GNUNET_CONTAINER_MetaData * meta
Metadata to use for the file.
Definition: fs_api.h:252
struct GNUNET_FS_Uri * GNUNET_FS_uri_parse(const char *uri, char **emsg)
Convert a UTF-8 String to a URI.
Definition: fs_uri.c:644
char * emsg
Error message (non-NULL if this operation failed).
Definition: fs_api.h:296
char * serialization
Under what filename is this struct serialized (for operational persistence).
Definition: fs_api.h:286
size_t GNUNET_FS_data_reader_copy_(void *cls, uint64_t offset, size_t max, void *buf, char **emsg)
Function that provides data by copying from a buffer.
Definition: fs_api.c:561
struct GNUNET_TIME_Absolute start_time
At what time did we start this upload?
Definition: fs_api.h:279
char * filename
Name of the file or directory (must be an absolute path).
Definition: fs_api.h:301
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_new(type)
Allocate a struct or union of the given type.
size_t GNUNET_FS_data_reader_file_(void *cls, uint64_t offset, size_t max, void *buf, char **emsg)
Function that provides data by reading from a file.
Definition: fs_api.c:457
Information for a file or directory that is about to be published.
Definition: fs_api.h:226
int GNUNET_FS_uri_test_sks(const struct GNUNET_FS_Uri *uri)
Is this a namespace URI?
Definition: fs_uri.c:1281
struct GNUNET_FS_Handle * h
Handle to the master context.
Definition: fs_api.h:242
union GNUNET_FS_FileInformation::@16 data
Data describing either the file or the directory.
#define GNUNET_malloc_large(size)
Wrapper around malloc.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
void * dir_data
Pointer to the data for the directory (or NULL if not available).
Definition: fs_api.h:373
uint64_t abs_value_us
The actual value.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
uint32_t anonymity_level
At which anonymity level should the block be shared? (0: no anonymity, 1: normal GAP, >1: with cover traffic).
int GNUNET_BIO_read(struct GNUNET_BIO_ReadHandle *h, const char *what, void *result, size_t len)
Read some contents into a buffer.
Definition: bio.c:287
struct GNUNET_FS_FileInformation::@16::@17 file
Data for a file.
static char * fn
Filename of the unique file.
int is_directory
Is this struct for a file or directory?
Definition: fs_api.h:390
static char * filename
static void cleanup(void *cls)
Function scheduled as very last function, cleans up after us.
struct GNUNET_FS_Uri * chk_uri
CHK for this file or directory.
Definition: fs_api.h:263
A 512-bit hashcode.
int GNUNET_BIO_read_string(struct GNUNET_BIO_ReadHandle *h, const char *what, char **result, size_t max_length)
Read 0-terminated string.
Definition: bio.c:326
int GNUNET_FS_uri_test_chk(const struct GNUNET_FS_Uri *uri)
Is this a file (or directory) URI?
Definition: fs_uri.c:1356
uint64_t contents_size
Sum of all of the sizes of all of the files in the directory.
Definition: fs_api.h:383
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:1159
void * GNUNET_FS_make_file_reader_context_(const char *filename)
Create the closure for the GNUNET_FS_data_reader_file_() callback.
Definition: fs_api.c:525
struct GNUNET_FS_FileInformation * next
Files in a directory are kept as a linked list.
Definition: fs_api.h:231
struct GNUNET_FS_BlockOptions bo
Block options for the file.
Definition: fs_api.h:274
uint32_t replication_level
How often should we try to migrate the block to other peers? Only used if "CONTENT_PUSHING" is set to...
static int read_start_time(struct GNUNET_BIO_ReadHandle *rh, struct GNUNET_TIME_Absolute *timestamp)
Deserialize a start-time.
Definition: fs_api.c:861
struct GNUNET_FS_Uri * keywords
Keywords to use for KBlocks.
Definition: fs_api.h:257
void GNUNET_FS_file_information_destroy(struct GNUNET_FS_FileInformation *fi, GNUNET_FS_FileInformationProcessor cleaner, void *cleaner_cls)
Destroy publish-structure.
uint32_t content_priority
How important is it for us to store the block? If we run out of space, the highest-priority, non-expired blocks will be kept.
int GNUNET_BIO_read_meta_data(struct GNUNET_BIO_ReadHandle *h, const char *what, struct GNUNET_CONTAINER_MetaData **result)
Read a metadata container.
Definition: bio.c:389
uint64_t contents_completed
How much of the directory have we published (relative to contents_size).
Definition: fs_api.h:378
int is_published
Are we done publishing this file?
Definition: fs_api.h:395
size_t dir_size
Size of the directory itself (in bytes); 0 if the size has not yet been calculated.
Definition: fs_api.h:367
struct GNUNET_FS_Uri * sks_uri
SKS URI for this file or directory.
Definition: fs_api.h:269
int GNUNET_BIO_read_int64(struct GNUNET_BIO_ReadHandle *h, const char *what, int64_t *i)
Read an (u)int64_t.
Definition: bio.c:500
#define GNUNET_free(ptr)
Wrapper around free.
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 1202 of file fs_api.c.

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().

1203 {
1204  const char *end;
1205  const char *nxt;
1206 
1207  end = NULL;
1208  nxt = fullname;
1209  /* FIXME: we could do this faster since we know
1210  * the length of 'end'... */
1211  while ('\0' != *nxt)
1212  {
1213  if (DIR_SEPARATOR == *nxt)
1214  end = nxt + 1;
1215  nxt++;
1216  }
1217  if ((NULL == end) || (0 == strlen (end)))
1218  {
1219  GNUNET_break (0);
1220  return NULL;
1221  }
1222  GNUNET_break (6 == strlen (end));
1223  return GNUNET_strdup (end);
1224 }
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define DIR_SEPARATOR
Definition: platform.h:170
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 errror

Definition at line 1236 of file fs_api.c.

References GNUNET_FS_Handle::flags, fn, 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, and ret.

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

1237 {
1238  char *fn;
1239  char *dn;
1240  char *ret;
1241 
1242  if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
1243  return NULL; /* persistence not requested */
1244  dn = get_serialization_file_name (h, ext, "");
1245  if (NULL == dn)
1246  return NULL;
1248  {
1249  GNUNET_free (dn);
1250  return NULL;
1251  }
1252  fn = GNUNET_DISK_mktemp (dn);
1253  GNUNET_free (dn);
1254  if (NULL == fn)
1255  return NULL; /* epic fail */
1256  ret = get_serialization_short_name (fn);
1257  GNUNET_free (fn);
1258  return ret;
1259 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
int GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:684
char * GNUNET_DISK_mktemp(const char *t)
Create an (empty) temporary file on disk.
Definition: disk.c:468
static char * fn
Filename of the unique file.
static char * get_serialization_file_name(struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
Return the full filename where we would store state information (for serialization/deserialization).
Definition: fs_api.c:591
static 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:1202
#define GNUNET_free(ptr)
Wrapper around free.
Is persistence of operations desired? (will create SUSPEND/RESUME events).
enum GNUNET_FS_Flags flags
General flags.
Definition: fs_api.h:1161
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 errror

Definition at line 1272 of file fs_api.c.

References GNUNET_FS_Handle::flags, fn, 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, and ret.

Referenced by GNUNET_FS_search_result_sync_().

1275 {
1276  char *fn;
1277  char *dn;
1278  char *ret;
1279 
1280  if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
1281  return NULL; /* persistence not requested */
1282  dn = get_serialization_file_name_in_dir (h, ext, uni, "");
1283  if (NULL == dn)
1284  return NULL;
1286  {
1287  GNUNET_free (dn);
1288  return NULL;
1289  }
1290  fn = GNUNET_DISK_mktemp (dn);
1291  GNUNET_free (dn);
1292  if (NULL == fn)
1293  return NULL; /* epic fail */
1294  ret = get_serialization_short_name (fn);
1295  GNUNET_free (fn);
1296  return ret;
1297 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
int GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:684
char * GNUNET_DISK_mktemp(const char *t)
Create an (empty) temporary file on disk.
Definition: disk.c:468
static char * fn
Filename of the unique file.
static char * get_serialization_file_name_in_dir(struct GNUNET_FS_Handle *h, const char *ext, const char *uni, const char *ent)
Return the full filename where we would store state information (for serialization/deserialization) t...
Definition: fs_api.c:631
static 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:1202
#define GNUNET_free(ptr)
Wrapper around free.
Is persistence of operations desired? (will create SUSPEND/RESUME events).
enum GNUNET_FS_Flags flags
General flags.
Definition: fs_api.h:1161
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 1308 of file fs_api.c.

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

Referenced by GNUNET_FS_file_information_sync_().

1310 {
1311  char buf[32 * 1024];
1312  uint64_t off;
1313  size_t ret;
1314  size_t left;
1315  char *emsg;
1316 
1317  emsg = NULL;
1318  off = 0;
1319  while (off < fi->data.file.file_size)
1320  {
1321  left = GNUNET_MIN (sizeof(buf), fi->data.file.file_size - off);
1322  ret =
1323  fi->data.file.reader (fi->data.file.reader_cls, off, left, buf, &emsg);
1324  if (0 == ret)
1325  {
1326  GNUNET_free (emsg);
1327  return GNUNET_SYSERR;
1328  }
1329  if (GNUNET_OK != GNUNET_BIO_write (wh, "copied from reader", buf, ret))
1330  return GNUNET_SYSERR;
1331  off += ret;
1332  }
1333  return GNUNET_OK;
1334 }
char * emsg
Error message (non-NULL if this operation failed).
Definition: fs_api.h:296
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
union GNUNET_FS_FileInformation::@16 data
Data describing either the file or the directory.
struct GNUNET_FS_FileInformation::@16::@17 file
Data for a file.
#define GNUNET_MIN(a, b)
Definition: gnunet_common.h:93
static char buf[2048]
uint32_t data
The data value.
int GNUNET_BIO_write(struct GNUNET_BIO_WriteHandle *h, const char *what, const void *buffer, size_t n)
Write a buffer to a handle.
Definition: bio.c:795
#define GNUNET_free(ptr)
Wrapper around free.
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 1344 of file fs_api.c.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_FS_BlockOptions::anonymity_level, testconfigure::b, 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, fn, 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_meta_data(), GNUNET_BIO_write_spec_object(), GNUNET_BIO_write_spec_string(), GNUNET_BIO_write_string(), GNUNET_break, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_FS_file_information_sync_(), GNUNET_FS_SYNC_PATH_FILE_INFO, GNUNET_FS_uri_to_string(), 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_file_information_sync_(), 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().

1345 {
1346  char *fn;
1347  struct GNUNET_BIO_WriteHandle *wh;
1348  char b;
1349  char *ksks;
1350  char *chks;
1351  char *skss;
1352 
1353  if (NULL == fi->serialization)
1354  fi->serialization =
1356  if (NULL == fi->serialization)
1357  return;
1358  wh =
1360  if (NULL == wh)
1361  {
1362  GNUNET_free (fi->serialization);
1363  fi->serialization = NULL;
1364  return;
1365  }
1366  if (GNUNET_YES == fi->is_directory)
1367  b = 4;
1368  else if (GNUNET_YES == fi->data.file.index_start_confirmed)
1369  b = 3;
1370  else if (GNUNET_YES == fi->data.file.have_hash)
1371  b = 2;
1372  else if (GNUNET_YES == fi->data.file.do_index)
1373  b = 1;
1374  else
1375  b = 0;
1376  if (NULL != fi->keywords)
1377  ksks = GNUNET_FS_uri_to_string (fi->keywords);
1378  else
1379  ksks = NULL;
1380  if (NULL != fi->chk_uri)
1381  chks = GNUNET_FS_uri_to_string (fi->chk_uri);
1382  else
1383  chks = NULL;
1384  if (NULL != fi->sks_uri)
1385  skss = GNUNET_FS_uri_to_string (fi->sks_uri);
1386  else
1387  skss = NULL;
1388  struct GNUNET_BIO_WriteSpec ws1[] = {
1389  GNUNET_BIO_write_spec_object ("b", &b, sizeof (b)),
1390  GNUNET_BIO_write_spec_meta_data ("meta", fi->meta),
1391  GNUNET_BIO_write_spec_string ("ksks", ksks),
1392  GNUNET_BIO_write_spec_string ("chks", chks),
1393  GNUNET_BIO_write_spec_string ("skss", skss),
1395  };
1396  struct GNUNET_BIO_WriteSpec ws2[] = {
1397  GNUNET_BIO_write_spec_string ("emsg", fi->emsg),
1398  GNUNET_BIO_write_spec_string ("filename", fi->filename),
1400  "expiration time",
1401  (int64_t *) &fi->bo.expiration_time.abs_value_us),
1403  "anonymity level",
1404  (int32_t *) &fi->bo.anonymity_level),
1406  "content priority",
1407  (int32_t *) &fi->bo.content_priority),
1409  "replication level",
1410  (int32_t *) &fi->bo.replication_level),
1412  };
1413  if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws1)) ||
1414  (GNUNET_OK != write_start_time (wh, fi->start_time)) ||
1415  (GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws2)))
1416  {
1417  GNUNET_break (0);
1418  goto cleanup;
1419  }
1420  GNUNET_free (chks);
1421  chks = NULL;
1422  GNUNET_free (ksks);
1423  ksks = NULL;
1424  GNUNET_free (skss);
1425  skss = NULL;
1426 
1427  switch (b)
1428  {
1429  case 0: /* file-insert */
1430  if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, "file size",
1431  fi->data.file.file_size))
1432  {
1433  GNUNET_break (0);
1434  goto cleanup;
1435  }
1436  if ((GNUNET_NO == fi->is_published) && (NULL == fi->filename))
1437  if (GNUNET_OK != copy_from_reader (wh, fi))
1438  {
1439  GNUNET_break (0);
1440  goto cleanup;
1441  }
1442  break;
1443 
1444  case 1: /* file-index, no hash */
1445  if (NULL == fi->filename)
1446  {
1447  GNUNET_break (0);
1448  goto cleanup;
1449  }
1450  if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, "file size",
1451  fi->data.file.file_size))
1452  {
1453  GNUNET_break (0);
1454  goto cleanup;
1455  }
1456  break;
1457 
1458  case 2: /* file-index-with-hash */
1459  case 3: /* file-index-with-hash-confirmed */
1460  if (NULL == fi->filename)
1461  {
1462  GNUNET_break (0);
1463  goto cleanup;
1464  }
1465  if ((GNUNET_OK != GNUNET_BIO_write_int64 (wh, "file size",
1466  fi->data.file.file_size)) ||
1467  (GNUNET_OK != GNUNET_BIO_write (wh,
1468  "file id",
1469  &fi->data.file.file_id,
1470  sizeof(struct GNUNET_HashCode))))
1471  {
1472  GNUNET_break (0);
1473  goto cleanup;
1474  }
1475  break;
1476 
1477  case 4: /* directory */
1478  if ((NULL != fi->data.dir.entries) &&
1479  (NULL == fi->data.dir.entries->serialization))
1481  struct GNUNET_BIO_WriteSpec ws[] = {
1482  GNUNET_BIO_write_spec_int32 ("dir size",
1483  (int32_t *) &fi->data.dir.dir_size),
1485  "contents completed",
1486  (int64_t *) &fi->data.dir.contents_completed),
1487  GNUNET_BIO_write_spec_int64 ("contents size",
1488  (int64_t *) &fi->data.dir.contents_size),
1489  GNUNET_BIO_write_spec_object ("dir data",
1490  fi->data.dir.dir_data,
1491  (uint32_t) fi->data.dir.dir_size),
1492  GNUNET_BIO_write_spec_string ("dir entries",
1493  (fi->data.dir.entries == NULL)
1494  ? NULL
1495  : fi->data.dir.entries->serialization),
1497  };
1498  if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws)))
1499  {
1500  GNUNET_break (0);
1501  goto cleanup;
1502  }
1503  break;
1504 
1505  default:
1506  GNUNET_assert (0);
1507  goto cleanup;
1508  }
1509  if ((NULL != fi->next) && (NULL == fi->next->serialization))
1512  "serialization",
1513  (fi->next != NULL)
1514  ? fi->next->serialization
1515  : NULL))
1516  {
1517  GNUNET_break (0);
1518  goto cleanup;
1519  }
1520  if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
1521  {
1522  wh = NULL;
1523  GNUNET_break (0);
1524  goto cleanup;
1525  }
1526  return; /* done! */
1527 cleanup:
1528  if (NULL != wh)
1529  (void) GNUNET_BIO_write_close (wh, NULL);
1530  GNUNET_free (chks);
1531  GNUNET_free (ksks);
1532  GNUNET_free (skss);
1533  fn = get_serialization_file_name (fi->h,
1535  fi->serialization);
1536  if (NULL != fn)
1537  {
1538  if (0 != unlink (fn))
1540  GNUNET_free (fn);
1541  }
1542  GNUNET_free (fi->serialization);
1543  fi->serialization = NULL;
1544 }
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...
struct GNUNET_FS_FileInformation * entries
Linked list of entries in the directory.
Definition: fs_api.h:361
Structure specifying a writing operation on an IO handle.
struct GNUNET_FS_FileInformation * dir
If this is a file in a directory, "dir" refers to the directory; otherwise NULL.
Definition: fs_api.h:237
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:1344
struct GNUNET_CONTAINER_MetaData * meta
Metadata to use for the file.
Definition: fs_api.h:252
char * emsg
Error message (non-NULL if this operation failed).
Definition: fs_api.h:296
char * serialization
Under what filename is this struct serialized (for operational persistence).
Definition: fs_api.h:286
int GNUNET_BIO_write_int64(struct GNUNET_BIO_WriteHandle *h, const char *what, int64_t i)
Write an (u)int64_t.
Definition: bio.c:956
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_TIME_Absolute start_time
At what time did we start this upload?
Definition: fs_api.h:279
char * filename
Name of the file or directory (must be an absolute path).
Definition: fs_api.h:301
static struct GNUNET_BIO_WriteHandle * get_write_handle(struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
Return a write handle for serialization.
Definition: fs_api.c:694
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:1288
struct GNUNET_FS_Handle * h
Handle to the master context.
Definition: fs_api.h:242
union GNUNET_FS_FileInformation::@16 data
Data describing either the file or the directory.
void * dir_data
Pointer to the data for the directory (or NULL if not available).
Definition: fs_api.h:373
uint64_t abs_value_us
The actual value.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
char * GNUNET_FS_uri_to_string(const struct GNUNET_FS_Uri *uri)
Convert a URI to a UTF-8 String.
Definition: fs_uri.c:2027
#define GNUNET_BIO_write_spec_end()
End of specifications marker.
uint32_t anonymity_level
At which anonymity level should the block be shared? (0: no anonymity, 1: normal GAP, >1: with cover traffic).
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:1335
struct GNUNET_FS_FileInformation::@16::@17 file
Data for a file.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
static char * fn
Filename of the unique file.
int is_directory
Is this struct for a file or directory?
Definition: fs_api.h:390
static void cleanup(void *cls)
Function scheduled as very last function, cleans up after us.
Handle for buffered writing.
Definition: bio.c:516
struct GNUNET_FS_Uri * chk_uri
CHK for this file or directory.
Definition: fs_api.h:263
A 512-bit hashcode.
uint64_t contents_size
Sum of all of the sizes of all of the files in the directory.
Definition: fs_api.h:383
struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_meta_data(const char *what, const struct GNUNET_CONTAINER_MetaData *m)
Create the specification to write a metadata container.
Definition: bio.c:1381
#define GNUNET_FS_SYNC_PATH_FILE_INFO
Name of the directory with files that are being published.
Definition: fs_api.h:81
static char * get_serialization_file_name(struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
Return the full filename where we would store state information (for serialization/deserialization).
Definition: fs_api.c:591
static int write_start_time(struct GNUNET_BIO_WriteHandle *wh, struct GNUNET_TIME_Absolute timestamp)
Serialize a start-time.
Definition: fs_api.c:836
int GNUNET_BIO_write_close(struct GNUNET_BIO_WriteHandle *h, char **emsg)
Close an IO handle.
Definition: bio.c:608
static struct GNUNET_TESTBED_BarrierWaitHandle * wh
Our barrier wait handle.
struct GNUNET_FS_FileInformation * next
Files in a directory are kept as a linked list.
Definition: fs_api.h:231
struct GNUNET_FS_BlockOptions bo
Block options for the file.
Definition: fs_api.h:274
uint32_t replication_level
How often should we try to migrate the block to other peers? Only used if "CONTENT_PUSHING" is set to...
int GNUNET_BIO_write_spec_commit(struct GNUNET_BIO_WriteHandle *h, struct GNUNET_BIO_WriteSpec *ws)
Execute the write specifications in order.
Definition: bio.c:1539
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:1236
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:1426
int GNUNET_BIO_write_string(struct GNUNET_BIO_WriteHandle *h, const char *what, const char *s)
Write a 0-terminated string.
Definition: bio.c:832
struct GNUNET_FS_Uri * keywords
Keywords to use for KBlocks.
Definition: fs_api.h:257
uint32_t content_priority
How important is it for us to store the block? If we run out of space, the highest-priority, non-expired blocks will be kept.
uint64_t contents_completed
How much of the directory have we published (relative to contents_size).
Definition: fs_api.h:378
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:1471
int is_published
Are we done publishing this file?
Definition: fs_api.h:395
int GNUNET_BIO_write(struct GNUNET_BIO_WriteHandle *h, const char *what, const void *buffer, size_t n)
Write a buffer to a handle.
Definition: bio.c:795
size_t dir_size
Size of the directory itself (in bytes); 0 if the size has not yet been calculated.
Definition: fs_api.h:367
static int copy_from_reader(struct GNUNET_BIO_WriteHandle *wh, struct GNUNET_FS_FileInformation *fi)
Copy all of the data from the reader to the write handle.
Definition: fs_api.c:1308
struct GNUNET_FS_Uri * sks_uri
SKS URI for this file or directory.
Definition: fs_api.h:269
#define GNUNET_free(ptr)
Wrapper around free.
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 1556 of file fs_api.c.

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().

1557 {
1558  struct GNUNET_FS_FileInformation *r;
1559 
1560  while (NULL != pos)
1561  {
1562  if (0 == strcmp (srch, pos->serialization))
1563  return pos;
1564  if ((GNUNET_YES == pos->is_directory) &&
1565  (NULL != (r = find_file_position (pos->data.dir.entries, srch))))
1566  return r;
1567  pos = pos->next;
1568  }
1569  return NULL;
1570 }
struct GNUNET_FS_FileInformation * entries
Linked list of entries in the directory.
Definition: fs_api.h:361
struct GNUNET_FS_FileInformation * dir
If this is a file in a directory, "dir" refers to the directory; otherwise NULL.
Definition: fs_api.h:237
char * serialization
Under what filename is this struct serialized (for operational persistence).
Definition: fs_api.h:286
Information for a file or directory that is about to be published.
Definition: fs_api.h:226
union GNUNET_FS_FileInformation::@16 data
Data describing either the file or the directory.
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:1556
int is_directory
Is this struct for a file or directory?
Definition: fs_api.h:390
struct GNUNET_FS_FileInformation * next
Files in a directory are kept as a linked list.
Definition: fs_api.h:231
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_CONTAINER_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 1588 of file fs_api.c.

References GNUNET_FS_FileInformation::chk_uri, GNUNET_FS_FileInformation::emsg, 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, pc, GNUNET_FS_ProgressInfo::publish, GNUNET_FS_PublishContext::skip_next_fi_callback, GNUNET_FS_ProgressInfo::status, and GNUNET_FS_ProgressInfo::value.

Referenced by deserialize_publish_file().

1596 {
1597  struct GNUNET_FS_PublishContext *pc = cls;
1598  struct GNUNET_FS_ProgressInfo pi;
1599 
1600  if (GNUNET_YES == pc->skip_next_fi_callback)
1601  {
1603  return GNUNET_OK;
1604  }
1606  pi.value.publish.specifics.resume.message = fi->emsg;
1607  pi.value.publish.specifics.resume.chk_uri = fi->chk_uri;
1608  *client_info = GNUNET_FS_publish_make_status_ (&pi, pc, fi, 0);
1610  {
1611  /* process entries in directory */
1614  }
1615  return GNUNET_OK;
1616 }
static int fip_signal_resume(void *cls, struct GNUNET_FS_FileInformation *fi, uint64_t length, struct GNUNET_CONTAINER_MetaData *meta, struct GNUNET_FS_Uri **uri, struct GNUNET_FS_BlockOptions *bo, int *do_index, void **client_info)
Signal the FS&#39;s progress function that we are resuming an upload.
Definition: fs_api.c:1588
char * emsg
Error message (non-NULL if this operation failed).
Definition: fs_api.h:296
static struct GNUNET_PEERINFO_Handle * pi
Handle to peerinfo service.
void * GNUNET_FS_publish_make_status_(struct GNUNET_FS_ProgressInfo *pi, struct GNUNET_FS_PublishContext *pc, const struct GNUNET_FS_FileInformation *p, uint64_t offset)
Fill in all of the generic fields for a publish event and call the callback.
Definition: fs_publish.c:47
struct GNUNET_FS_Uri * chk_uri
CHK for this file or directory.
Definition: fs_api.h:263
Handle for controlling a publication process.
Definition: fs_api.h:1178
int GNUNET_FS_meta_data_test_for_directory(const struct GNUNET_CONTAINER_MetaData *md)
Does the meta-data claim that this is a directory? Checks if the mime-type is that of a GNUnet direct...
Definition: fs_directory.c:54
Notification that we have resumed sharing a file structure.
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 skip_next_fi_callback
Flag set to GNUNET_YES if the next callback from GNUNET_FS_file_information_inspect should be skipped...
Definition: fs_api.h:1298
Argument given to the progress callback with information about what is going on.
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 1628 of file fs_api.c.

References _, GNUNET_FS_PublishContext::all_done, GNUNET_FS_Handle::cfg, cleanup(), deserialize_file_information(), GNUNET_FS_PublishContext::dsh, GNUNET_FS_PublishContext::fi, GNUNET_FS_PublishContext::fi_pos, 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_FS_PublishContext::serialization, GNUNET_FS_PublishContext::top, and GNUNET_FS_PublishContext::upload_task.

Referenced by GNUNET_FS_start().

1629 {
1630  struct GNUNET_FS_Handle *h = cls;
1631  struct GNUNET_BIO_ReadHandle *rh;
1632  struct GNUNET_FS_PublishContext *pc;
1633  int32_t options;
1634  int32_t all_done;
1635  int32_t have_ns;
1636  char *fi_root;
1638  char *fi_pos;
1639  char *emsg;
1640 
1641  pc = GNUNET_new (struct GNUNET_FS_PublishContext);
1642  pc->h = h;
1644  fi_root = NULL;
1645  fi_pos = NULL;
1647  if (NULL == rh)
1648  {
1649  GNUNET_break (0);
1650  goto cleanup;
1651  }
1652  struct GNUNET_BIO_ReadSpec rs[] = {
1653  GNUNET_BIO_read_spec_string ("publish-nid", &pc->nid, 1024),
1654  GNUNET_BIO_read_spec_string ("publish-nuid", &pc->nuid, 1024),
1655  GNUNET_BIO_read_spec_int32 ("options", &options),
1656  GNUNET_BIO_read_spec_int32 ("all done", &all_done),
1657  GNUNET_BIO_read_spec_int32 ("have ns", &have_ns),
1658  GNUNET_BIO_read_spec_string ("publish-firoot", &fi_root, 128),
1659  GNUNET_BIO_read_spec_string ("publish-fipos", &fi_pos, 128),
1661  };
1662  if ((GNUNET_OK != GNUNET_BIO_read_spec_commit (rh, rs)) ||
1663  ((GNUNET_YES == have_ns) &&
1664  (GNUNET_OK != GNUNET_BIO_read (rh, "publish-ns", &ns, sizeof(ns)))))
1665  {
1666  GNUNET_break (0);
1667  goto cleanup;
1668  }
1669  pc->options = options;
1670  pc->all_done = all_done;
1671  if (NULL == fi_root)
1672  {
1673  GNUNET_break (0);
1674  goto cleanup;
1675  }
1676  pc->fi = deserialize_file_information (h, fi_root);
1677  if (NULL == pc->fi)
1678  {
1679  GNUNET_break (0);
1680  goto cleanup;
1681  }
1682  if (GNUNET_YES == have_ns)
1683  {
1685  *pc->ns = ns;
1686  }
1687  if ((0 == (pc->options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) &&
1688  (GNUNET_YES != pc->all_done))
1689  {
1690  pc->dsh = GNUNET_DATASTORE_connect (h->cfg);
1691  if (NULL == pc->dsh)
1692  goto cleanup;
1693  }
1694  if (NULL != fi_pos)
1695  {
1696  pc->fi_pos = find_file_position (pc->fi, fi_pos);
1697  GNUNET_free (fi_pos);
1698  fi_pos = NULL;
1699  if (NULL == pc->fi_pos)
1700  {
1701  /* failed to find position for resuming, outch! Will start from root! */
1702  GNUNET_break (0);
1703  if (GNUNET_YES != pc->all_done)
1704  pc->fi_pos = pc->fi;
1705  }
1706  }
1707  GNUNET_free (fi_root);
1708  fi_root = NULL;
1709  /* generate RESUME event(s) */
1711 
1712  /* re-start publishing (if needed)... */
1713  if (GNUNET_YES != pc->all_done)
1714  {
1715  GNUNET_assert (NULL == pc->upload_task);
1716  pc->upload_task =
1719  pc);
1720  }
1721  if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
1722  {
1724  _ ("Failure while resuming publishing operation `%s': %s\n"),
1725  filename,
1726  emsg);
1727  GNUNET_free (emsg);
1728  }
1730  return GNUNET_OK;
1731 cleanup:
1732  GNUNET_free (pc->nid);
1733  GNUNET_free (pc->nuid);
1734  GNUNET_free (fi_root);
1735  GNUNET_free (fi_pos);
1736  if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)))
1737  {
1739  _ ("Failed to resume publishing operation `%s': %s\n"),
1740  filename,
1741  emsg);
1742  GNUNET_free (emsg);
1743  }
1744  if (NULL != pc->fi)
1745  GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL);
1746  if (0 != unlink (filename))
1748  GNUNET_free (pc->serialization);
1749  GNUNET_free (pc);
1750  return GNUNET_OK;
1751 }
char * nid
ID of the content in the namespace, NULL if we have no namespace.
Definition: fs_api.h:1203
#define GNUNET_BIO_read_spec_end()
End of specifications marker.
struct GNUNET_SCHEDULER_Task * upload_task
ID of the task performing the upload.
Definition: fs_api.h:1258
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
static int fip_signal_resume(void *cls, struct GNUNET_FS_FileInformation *fi, uint64_t length, struct GNUNET_CONTAINER_MetaData *meta, struct GNUNET_FS_Uri **uri, struct GNUNET_FS_BlockOptions *bo, int *do_index, void **client_info)
Signal the FS&#39;s progress function that we are resuming an upload.
Definition: fs_api.c:1588
struct GNUNET_BIO_ReadHandle * GNUNET_BIO_read_open_file(const char *fn)
Open a file for reading.
Definition: bio.c:119
Master context for most FS operations.
Definition: fs_api.h:1068
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
enum GNUNET_FS_PublishOptions options
Options for publishing.
Definition: fs_api.h:1274
int GNUNET_BIO_read_spec_commit(struct GNUNET_BIO_ReadHandle *h, struct GNUNET_BIO_ReadSpec *rs)
Execute the read specifications in order.
Definition: bio.c:1242
struct GNUNET_DATASTORE_Handle * dsh
Connection to the datastore service.
Definition: fs_api.h:1235
struct GNUNET_FS_Handle * h
Handle to the global fs context.
Definition: fs_api.h:1183
#define GNUNET_new(type)
Allocate a struct or union of the given type.
char * serialization
Filename used for serializing information about this operation (should be determined using &#39;mktemp&#39;)...
Definition: fs_api.h:1214
Private ECC key encoded for transmission.
Run as background job (higher than idle, lower than default).
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:1556
int GNUNET_BIO_read_close(struct GNUNET_BIO_ReadHandle *h, char **emsg)
Close an open handle.
Definition: bio.c:166
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
#define _(String)
GNU gettext support macro.
Definition: platform.h:184
int GNUNET_BIO_read(struct GNUNET_BIO_ReadHandle *h, const char *what, void *result, size_t len)
Read some contents into a buffer.
Definition: bio.c:287
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:1223
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
char * nuid
ID for future updates, NULL if we have no namespace or no updates.
Definition: fs_api.h:1208
static struct GNUNET_NAMESTORE_Handle * ns
Handle to the namestore.
Definition: gnunet-abd.c:41
static char * filename
void GNUNET_FS_publish_main_(void *cls)
Main function that performs the upload.
Definition: fs_publish.c:1062
static void cleanup(void *cls)
Function scheduled as very last function, cleans up after us.
struct GNUNET_FS_FileInformation * fi_pos
Current position in the file-tree for the upload.
Definition: fs_api.h:1225
Structure specifying a reading operation on an IO handle.
Handle for controlling a publication process.
Definition: fs_api.h:1178
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:1045
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:1159
int all_done
Set to GNUNET_YES if all processing has completed.
Definition: fs_api.h:1291
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:1202
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:1135
struct TopLevelActivity * GNUNET_FS_make_top(struct GNUNET_FS_Handle *h, SuspendSignalFunction ssf, void *ssf_cls)
Create a top-level activity entry.
Definition: fs_api.c:391
struct TopLevelActivity * top
Our top-level activity entry (if we are top-level, otherwise NULL).
Definition: fs_api.h:1188
static struct GNUNET_FS_PublishContext * pc
Handle to FS-publishing operation.
struct GNUNET_FS_FileInformation * fi
File-structure that is being shared.
Definition: fs_api.h:1193
void GNUNET_FS_publish_signal_suspend_(void *cls)
Create SUSPEND event for the given publish operation and then clean up our state (without stop signal...
Definition: fs_publish.c:1354
struct GNUNET_CRYPTO_EcdsaPrivateKey * ns
Namespace that we are publishing in, NULL if we have no namespace.
Definition: fs_api.h:1198
void GNUNET_FS_file_information_inspect(struct GNUNET_FS_FileInformation *dir, GNUNET_FS_FileInformationProcessor proc, void *proc_cls)
Inspect a file or directory in a publish-structure.
#define GNUNET_log(kind,...)
void GNUNET_FS_file_information_destroy(struct GNUNET_FS_FileInformation *fi, GNUNET_FS_FileInformationProcessor cleaner, void *cleaner_cls)
Destroy publish-structure.
struct GNUNET_DATASTORE_Handle * GNUNET_DATASTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the datastore service.
Handle for buffered reading.
Definition: bio.c:73
#define GNUNET_free(ptr)
Wrapper around free.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Definition: fs_api.h:1073
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 1763 of file fs_api.c.

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, 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().

1764 {
1765  struct GNUNET_BIO_WriteHandle *wh;
1766  int32_t have_ns;
1767 
1768  if (NULL == pc->serialization)
1769  pc->serialization =
1771  if (NULL == pc->serialization)
1772  return;
1773  if (NULL == pc->fi)
1774  return;
1775  if (NULL == pc->fi->serialization)
1776  {
1777  GNUNET_break (0);
1778  return;
1779  }
1780  wh = get_write_handle (pc->h,
1782  pc->serialization);
1783  if (NULL == wh)
1784  {
1785  GNUNET_break (0);
1786  goto cleanup;
1787  }
1788  have_ns = (NULL != pc->ns) ? GNUNET_YES : GNUNET_NO;
1789  struct GNUNET_BIO_WriteSpec ws[] = {
1790  GNUNET_BIO_write_spec_string ("nid", pc->nid),
1791  GNUNET_BIO_write_spec_string ("nuid", pc->nuid),
1792  GNUNET_BIO_write_spec_int32 ("options", (int32_t *) &pc->options),
1793  GNUNET_BIO_write_spec_int32 ("all done", &pc->all_done),
1794  GNUNET_BIO_write_spec_int32 ("have ns", &have_ns),
1795  GNUNET_BIO_write_spec_string ("serialization", pc->fi->serialization),
1796  GNUNET_BIO_write_spec_string ("pos serialization", (NULL == pc->fi_pos)
1797  ? NULL
1798  : pc->fi_pos->serialization),
1800  };
1801  if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws)) ||
1802  ((NULL != pc->ns) &&
1803  (GNUNET_OK !=
1804  GNUNET_BIO_write (wh,
1805  "ns",
1806  pc->ns,
1807  sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey)))))
1808  {
1809  GNUNET_break (0);
1810  goto cleanup;
1811  }
1812  if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
1813  {
1814  wh = NULL;
1815  GNUNET_break (0);
1816  goto cleanup;
1817  }
1818  return;
1819 cleanup:
1820  if (NULL != wh)
1821  (void) GNUNET_BIO_write_close (wh, NULL);
1824  pc->serialization);
1825  GNUNET_free (pc->serialization);
1826  pc->serialization = NULL;
1827 }
Structure specifying a writing operation on an IO handle.
char * nid
ID of the content in the namespace, NULL if we have no namespace.
Definition: fs_api.h:1203
#define GNUNET_BIO_read_spec_end()
End of specifications marker.
char * serialization
Under what filename is this struct serialized (for operational persistence).
Definition: fs_api.h:286
static struct GNUNET_BIO_WriteHandle * get_write_handle(struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
Return a write handle for serialization.
Definition: fs_api.c:694
enum GNUNET_FS_PublishOptions options
Options for publishing.
Definition: fs_api.h:1274
struct GNUNET_FS_Handle * h
Handle to the global fs context.
Definition: fs_api.h:1183
char * serialization
Filename used for serializing information about this operation (should be determined using &#39;mktemp&#39;)...
Definition: fs_api.h:1214
Private ECC key encoded for transmission.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
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:1335
char * nuid
ID for future updates, NULL if we have no namespace or no updates.
Definition: fs_api.h:1208
static void cleanup(void *cls)
Function scheduled as very last function, cleans up after us.
struct GNUNET_FS_FileInformation * fi_pos
Current position in the file-tree for the upload.
Definition: fs_api.h:1225
Handle for buffered writing.
Definition: bio.c:516
int all_done
Set to GNUNET_YES if all processing has completed.
Definition: fs_api.h:1291
int GNUNET_BIO_write_close(struct GNUNET_BIO_WriteHandle *h, char **emsg)
Close an IO handle.
Definition: bio.c:608
static struct GNUNET_TESTBED_BarrierWaitHandle * wh
Our barrier wait handle.
struct GNUNET_FS_FileInformation * fi
File-structure that is being shared.
Definition: fs_api.h:1193
int GNUNET_BIO_write_spec_commit(struct GNUNET_BIO_WriteHandle *h, struct GNUNET_BIO_WriteSpec *ws)
Execute the write specifications in order.
Definition: bio.c:1539
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:1236
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:1426
struct GNUNET_CRYPTO_EcdsaPrivateKey * ns
Namespace that we are publishing in, NULL if we have no namespace.
Definition: fs_api.h:1198
#define GNUNET_FS_SYNC_PATH_MASTER_PUBLISH
Name of the directory with publishing operations.
Definition: fs_api.h:76
int GNUNET_BIO_write(struct GNUNET_BIO_WriteHandle *h, const char *what, const void *buffer, size_t n)
Write a buffer to a handle.
Definition: bio.c:795
void GNUNET_FS_remove_sync_file_(struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
Remove serialization/deserialization file from disk.
Definition: fs_api.c:744
#define GNUNET_free(ptr)
Wrapper around free.
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 1839 of file fs_api.c.

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, 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().

1840 {
1841  struct GNUNET_BIO_WriteHandle *wh;
1842  char *uris;
1843 
1844  if (NULL == uc->serialization)
1845  uc->serialization =
1847  if (NULL == uc->serialization)
1848  return;
1849  wh = get_write_handle (uc->h,
1851  uc->serialization);
1852  if (NULL == wh)
1853  {
1854  GNUNET_break (0);
1855  goto cleanup;
1856  }
1857  if (NULL != uc->ksk_uri)
1858  uris = GNUNET_FS_uri_to_string (uc->ksk_uri);
1859  else
1860  uris = NULL;
1861  struct GNUNET_BIO_WriteSpec ws1[] = {
1862  GNUNET_BIO_write_spec_string ("filename", uc->filename),
1863  GNUNET_BIO_write_spec_int64 ("file size", (int64_t *) &uc->file_size),
1865  };
1866  struct GNUNET_BIO_WriteSpec ws2[] = {
1867  GNUNET_BIO_write_spec_int32 ("state", (int32_t *) &uc->state),
1868  GNUNET_BIO_write_spec_object ("hashkey", &uc->chk,
1869  sizeof (struct ContentHashKey)),
1870  GNUNET_BIO_write_spec_string ("uris", uris),
1871  GNUNET_BIO_write_spec_int32 ("ksk offset", (int32_t *) &uc->ksk_offset),
1873  };
1874  if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws1)) ||
1875  (GNUNET_OK != write_start_time (wh, uc->start_time)) ||
1876  (GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws2)) ||
1877  ((uc->state == UNINDEX_STATE_FS_NOTIFY) &&
1878  (GNUNET_OK != GNUNET_BIO_write (wh,
1879  "file id",
1880  &uc->file_id,
1881  sizeof(struct GNUNET_HashCode)))) ||
1882  ((uc->state == UNINDEX_STATE_ERROR) &&
1883  (GNUNET_OK != GNUNET_BIO_write_string (wh, "emsg", uc->emsg))))
1884  {
1885  GNUNET_break (0);
1886  goto cleanup;
1887  }
1888  if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
1889  {
1890  wh = NULL;
1891  GNUNET_break (0);
1892  goto cleanup;
1893  }
1894  return;
1895 cleanup:
1896  if (NULL != wh)
1897  (void) GNUNET_BIO_write_close (wh, NULL);
1900  uc->serialization);
1901  GNUNET_free (uc->serialization);
1902  uc->serialization = NULL;
1903 }
Structure specifying a writing operation on an IO handle.
char * serialization
Short name under which we are serializing the state of this operation.
Definition: fs_api.h:1390
content hash key
Definition: fs.h:53
uint32_t ksk_offset
Current offset in KSK removal.
Definition: fs_api.h:1380
static struct GNUNET_BIO_WriteHandle * get_write_handle(struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
Return a write handle for serialization.
Definition: fs_api.c:694
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:1288
struct GNUNET_HashCode file_id
Hash of the file&#39;s contents (once computed).
Definition: fs_api.h:1458
enum UnindexState state
Current operatinonal phase.
Definition: fs_api.h:1463
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
We&#39;re notifying the FS service about the unindexing.
Definition: fs_api.h:1332
char * GNUNET_FS_uri_to_string(const struct GNUNET_FS_Uri *uri)
Convert a URI to a UTF-8 String.
Definition: fs_uri.c:2027
#define GNUNET_BIO_write_spec_end()
End of specifications marker.
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:1335
#define GNUNET_FS_SYNC_PATH_MASTER_UNINDEX
Name of the directory with unindex operations.
Definition: fs_api.h:86
struct GNUNET_TIME_Absolute start_time
When did we start?
Definition: fs_api.h:1453
static void cleanup(void *cls)
Function scheduled as very last function, cleans up after us.
Handle for buffered writing.
Definition: bio.c:516
We&#39;ve encountered a fatal error.
Definition: fs_api.h:1342
struct GNUNET_FS_Uri * ksk_uri
Keywords found (telling us which KBlocks to remove).
Definition: fs_api.h:1375
A 512-bit hashcode.
char * filename
Name of the file that we are unindexing.
Definition: fs_api.h:1385
static int write_start_time(struct GNUNET_BIO_WriteHandle *wh, struct GNUNET_TIME_Absolute timestamp)
Serialize a start-time.
Definition: fs_api.c:836
int GNUNET_BIO_write_close(struct GNUNET_BIO_WriteHandle *h, char **emsg)
Close an IO handle.
Definition: bio.c:608
static struct GNUNET_TESTBED_BarrierWaitHandle * wh
Our barrier wait handle.
int GNUNET_BIO_write_spec_commit(struct GNUNET_BIO_WriteHandle *h, struct GNUNET_BIO_WriteSpec *ws)
Execute the write specifications in order.
Definition: bio.c:1539
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:1236
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:1426
int GNUNET_BIO_write_string(struct GNUNET_BIO_WriteHandle *h, const char *what, const char *s)
Write a 0-terminated string.
Definition: bio.c:832
struct ContentHashKey chk
The content hash key of the last block we processed, will in the end be set to the CHK from the URI...
Definition: fs_api.h:1355
char * emsg
Error message, NULL on success.
Definition: fs_api.h:1438
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:1471
struct GNUNET_FS_Handle * h
Global FS context.
Definition: fs_api.h:1360
int GNUNET_BIO_write(struct GNUNET_BIO_WriteHandle *h, const char *what, const void *buffer, size_t n)
Write a buffer to a handle.
Definition: bio.c:795
void GNUNET_FS_remove_sync_file_(struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
Remove serialization/deserialization file from disk.
Definition: fs_api.c:744
#define GNUNET_free(ptr)
Wrapper around free.
uint64_t file_size
Overall size of the file.
Definition: fs_api.h:1448
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 1914 of file fs_api.c.

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, and DownloadRequest::state.

Referenced by GNUNET_FS_download_sync_().

1916 {
1917  unsigned int i;
1918  struct GNUNET_BIO_WriteSpec ws[] = {
1919  GNUNET_BIO_write_spec_int32 ("state", (int32_t *) &dr->state),
1920  GNUNET_BIO_write_spec_int64 ("offset", (int64_t *) &dr->offset),
1921  GNUNET_BIO_write_spec_int32 ("num children", (int32_t *) &dr->num_children),
1922  GNUNET_BIO_write_spec_int32 ("depth", (int32_t *) &dr->depth),
1924  };
1925 
1926  if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws)))
1927  return GNUNET_NO;
1928  if ((BRS_CHK_SET == dr->state) &&
1929  (GNUNET_OK !=
1930  GNUNET_BIO_write (wh, "hashkey",
1931  &dr->chk, sizeof(struct ContentHashKey))))
1932  return GNUNET_NO;
1933  for (i = 0; i < dr->num_children; i++)
1934  if (GNUNET_NO == write_download_request (wh, dr->children[i]))
1935  return GNUNET_NO;
1936  return GNUNET_YES;
1937 }
Structure specifying a writing operation on an IO handle.
content hash key
Definition: fs.h:53
struct DownloadRequest ** children
Array (!) of child-requests, or NULL for the bottom of the tree.
Definition: fs_api.h:1684
uint64_t offset
Offset of the corresponding block.
Definition: fs_api.h:1697
struct ContentHashKey chk
CHK for the request for this block (set during reconstruction to what we have on disk, later to what we want to have).
Definition: fs_api.h:1690
enum BlockRequestState state
State in the FSM.
Definition: fs_api.h:1717
unsigned int num_children
Number of entries in children array.
Definition: fs_api.h:1702
#define GNUNET_BIO_write_spec_end()
End of specifications marker.
int GNUNET_BIO_write_spec_commit(struct GNUNET_BIO_WriteHandle *h, struct GNUNET_BIO_WriteSpec *ws)
Execute the write specifications in order.
Definition: bio.c:1539
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:1426
static int write_download_request(struct GNUNET_BIO_WriteHandle *wh, struct DownloadRequest *dr)
Serialize a download request.
Definition: fs_api.c:1914
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:1471
int GNUNET_BIO_write(struct GNUNET_BIO_WriteHandle *h, const char *what, const void *buffer, size_t n)
Write a buffer to a handle.
Definition: bio.c:795
unsigned int depth
Depth of the corresponding block in the tree.
Definition: fs_api.h:1707
We&#39;ve determined the real, desired CHK for this block (full tree reconstruction failed), request is now pending.
Definition: fs_api.h:1645
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 1947 of file fs_api.c.

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, and DownloadRequest::state.

Referenced by deserialize_download().

1948 {
1949  struct DownloadRequest *dr;
1950  unsigned int i;
1951 
1952  dr = GNUNET_new (struct DownloadRequest);
1953  struct GNUNET_BIO_ReadSpec rs[] = {
1954  GNUNET_BIO_read_spec_int32 ("state", (int32_t *) &dr->state),
1955  GNUNET_BIO_read_spec_int64 ("offset", (int64_t *) &dr->offset),
1956  GNUNET_BIO_read_spec_int32 ("num children", (int32_t *) &dr->num_children),
1958  };
1959  if ((GNUNET_OK != GNUNET_BIO_read_spec_commit (rh, rs)) ||
1960  (dr->num_children > CHK_PER_INODE) ||
1961  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "depth",
1962  (int32_t *) &dr->depth)) ||
1963  ((0 == dr->depth) && (dr->num_children > 0)) ||
1964  ((dr->depth > 0) && (0 == dr->num_children)))
1965  {
1966  GNUNET_break (0);
1967  dr->num_children = 0;
1968  goto cleanup;
1969  }
1970  if (dr->num_children > 0)
1971  dr->children =
1972  GNUNET_malloc (dr->num_children * sizeof(struct DownloadRequest *));
1973  switch (dr->state)
1974  {
1975  case BRS_INIT:
1976  case BRS_RECONSTRUCT_DOWN:
1978  case BRS_RECONSTRUCT_UP:
1979  break;
1980 
1981  case BRS_CHK_SET:
1982  if (GNUNET_OK !=
1983  GNUNET_BIO_read (rh, "chk", &dr->chk, sizeof(struct ContentHashKey)))
1984  goto cleanup;
1985  break;
1986 
1987  case BRS_DOWNLOAD_DOWN:
1988  case BRS_DOWNLOAD_UP:
1989  case BRS_ERROR:
1990  break;
1991 
1992  default:
1993  GNUNET_break (0);
1994  goto cleanup;
1995  }
1996  for (i = 0; i < dr->num_children; i++)
1997  {
1998  if (NULL == (dr->children[i] = read_download_request (rh)))
1999  goto cleanup;
2000  dr->children[i]->parent = dr;
2001  }
2002  return dr;
2003 cleanup:
2005  return NULL;
2006 }
#define GNUNET_BIO_read_spec_end()
End of specifications marker.
int GNUNET_BIO_read_int32(struct GNUNET_BIO_ReadHandle *h, const char *what, int32_t *i)
Read an (u)int32_t.
Definition: bio.c:478
content hash key
Definition: fs.h:53
struct DownloadRequest ** children
Array (!) of child-requests, or NULL for the bottom of the tree.
Definition: fs_api.h:1684
uint64_t offset
Offset of the corresponding block.
Definition: fs_api.h:1697
int GNUNET_BIO_read_spec_commit(struct GNUNET_BIO_ReadHandle *h, struct GNUNET_BIO_ReadSpec *rs)
Execute the read specifications in order.
Definition: bio.c:1242
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct ContentHashKey chk
CHK for the request for this block (set during reconstruction to what we have on disk, later to what we want to have).
Definition: fs_api.h:1690
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:1179
We&#39;ve calculated the CHK bottom-up based on what we have on disk, which may not be what the desired C...
Definition: fs_api.h:1636
enum BlockRequestState state
State in the FSM.
Definition: fs_api.h:1717
unsigned int num_children
Number of entries in children array.
Definition: fs_api.h:1702
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
Initial state, block has only been allocated (since it is relevant to the overall download request)...
Definition: fs_api.h:1612
int GNUNET_BIO_read(struct GNUNET_BIO_ReadHandle *h, const char *what, void *result, size_t len)
Read some contents into a buffer.
Definition: bio.c:287
We&#39;ve checked the block on the path down the tree, and the content on disk did match the desired CHK...
Definition: fs_api.h:1620
#define CHK_PER_INODE
Pick a multiple of 2 here to achive 8-byte alignment! We also probably want DBlocks to have (roughly)...
Definition: fs_api.h:43
static void cleanup(void *cls)
Function scheduled as very last function, cleans up after us.
Structure specifying a reading operation on an IO handle.
We&#39;ve calculated the CHK bottom-up based on the meta data.
Definition: fs_api.h:1628
static struct DownloadRequest * read_download_request(struct GNUNET_BIO_ReadHandle *rh)
Read a download request tree.
Definition: fs_api.c:1947
We&#39;ve successfully downloaded this block, but the children still need to be either downloaded or veri...
Definition: fs_api.h:1654
This block and all of its children have been downloaded successfully (full completion propagates up)...
Definition: fs_api.h:1660
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:1135
We got a block back that matched the query but did not hash to the key (malicious publisher or hash c...
Definition: fs_api.h:1667
void GNUNET_FS_free_download_request_(struct DownloadRequest *dr)
(recursively) free download request structure
Definition: fs_download.c:996
struct DownloadRequest * parent
Parent in the CHK-tree.
Definition: fs_api.h:1679
Information about an active download request.
Definition: fs_api.h:1674
unsigned int depth
Depth of the corresponding block in the tree.
Definition: fs_api.h:1707
We&#39;ve determined the real, desired CHK for this block (full tree reconstruction failed), request is now pending.
Definition: fs_api.h:1645
#define GNUNET_malloc(size)
Wrapper around malloc.
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 2019 of file fs_api.c.

References 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_().

2022 {
2023  char *par;
2024  char *epar;
2025 
2026  if (dc->parent == NULL)
2027  return get_serialization_file_name (dc->h,
2028  (dc->search != NULL)
2031  uni);
2032  if (NULL == dc->parent->serialization)
2033  return NULL;
2034  par = get_download_sync_filename (dc->parent, dc->parent->serialization, "");
2035  if (NULL == par)
2036  return NULL;
2037  GNUNET_asprintf (&epar, "%s.dir%s%s%s", par, DIR_SEPARATOR_STR, uni, ext);
2038  GNUNET_free (par);
2039  return epar;
2040 }
struct GNUNET_FS_Handle * h
Global FS context.
Definition: fs_api.h:1747
#define GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD
Name of the directory with downloads that are part of another download or a search.
Definition: fs_api.h:71
struct GNUNET_FS_DownloadContext * parent
Parent download (used when downloading files in directories).
Definition: fs_api.h:1763
#define GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD
Name of the directory with master downloads (not associated with search or part of another download)...
Definition: fs_api.h:65
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
char * serialization
Random portion of filename we use for syncing state of this download.
Definition: fs_api.h:1815
#define DIR_SEPARATOR_STR
Definition: platform.h:171
struct GNUNET_FS_SearchResult * search
Associated search (used when downloading files based on search results), or NULL for none...
Definition: fs_api.h:1769
static char * get_serialization_file_name(struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
Return the full filename where we would store state information (for serialization/deserialization).
Definition: fs_api.c:591
static 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:2019
#define GNUNET_free(ptr)
Wrapper around free.
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 2052 of file fs_api.c.

References GNUNET_FS_DownloadContext::anonymity, cleanup(), GNUNET_FS_DownloadContext::completed, dir, GNUNET_FS_DownloadContext::emsg, GNUNET_FS_DownloadContext::filename, fn, 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_meta_data(), 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_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().

2053 {
2054  struct GNUNET_BIO_WriteHandle *wh;
2055  char *uris;
2056  char *fn;
2057  char *dir;
2058 
2059  if (0 != (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE))
2060  return; /* we don't sync probes */
2061  if (NULL == dc->serialization)
2062  {
2063  dir = get_download_sync_filename (dc, "", "");
2064  if (NULL == dir)
2065  return;
2067  {
2068  GNUNET_free (dir);
2069  return;
2070  }
2071  fn = GNUNET_DISK_mktemp (dir);
2072  GNUNET_free (dir);
2073  if (NULL == fn)
2074  return;
2076  }
2077  else
2078  {
2079  fn = get_download_sync_filename (dc, dc->serialization, "");
2080  if (NULL == fn)
2081  {
2082  GNUNET_free (dc->serialization);
2083  dc->serialization = NULL;
2084  GNUNET_free (fn);
2085  return;
2086  }
2087  }
2088  wh = GNUNET_BIO_write_open_file (fn);
2089  if (NULL == wh)
2090  {
2091  GNUNET_free (dc->serialization);
2092  dc->serialization = NULL;
2093  GNUNET_free (fn);
2094  return;
2095  }
2098  uris = GNUNET_FS_uri_to_string (dc->uri);
2099  struct GNUNET_BIO_WriteSpec ws1[] = {
2100  GNUNET_BIO_write_spec_string ("uris", uris),
2101  GNUNET_BIO_write_spec_meta_data ("metadata", dc->meta),
2102  GNUNET_BIO_write_spec_string ("emsg", dc->emsg),
2103  GNUNET_BIO_write_spec_string ("filename", dc->filename),
2104  GNUNET_BIO_write_spec_string ("temp filename", dc->temp_filename),
2105  GNUNET_BIO_write_spec_int64 ("old file size",
2106  (int64_t *) &dc->old_file_size),
2107  GNUNET_BIO_write_spec_int64 ("offset", (int64_t *) &dc->offset),
2108  GNUNET_BIO_write_spec_int64 ("length", (int64_t *) &dc->length),
2109  GNUNET_BIO_write_spec_int64 ("completed", (int64_t *) &dc->completed),
2111  };
2112  struct GNUNET_BIO_WriteSpec ws2[] = {
2113  GNUNET_BIO_write_spec_int32 ("anonymity", (int32_t *) &dc->anonymity),
2114  GNUNET_BIO_write_spec_int32 ("options", (int32_t *) &dc->options),
2115  GNUNET_BIO_write_spec_int32 ("has finished", (int32_t *) &dc->has_finished),
2117  };
2118  if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws1)) ||
2119  (GNUNET_OK != write_start_time (wh, dc->start_time)) ||
2120  (GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws2)))
2121  {
2122  GNUNET_break (0);
2123  goto cleanup;
2124  }
2125  if (NULL == dc->emsg)
2126  {
2127  GNUNET_assert (dc->top_request != NULL);
2129  {
2130  GNUNET_break (0);
2131  goto cleanup;
2132  }
2133  }
2134  GNUNET_free (uris);
2135  uris = NULL;
2136  if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
2137  {
2138  wh = NULL;
2139  GNUNET_break (0);
2140  goto cleanup;
2141  }
2142  GNUNET_free (fn);
2143  return;
2144 cleanup:
2145  if (NULL != wh)
2146  (void) GNUNET_BIO_write_close (wh, NULL);
2147  GNUNET_free (uris);
2148  if (0 != unlink (fn))
2150  GNUNET_free (fn);
2151  GNUNET_free (dc->serialization);
2152  dc->serialization = NULL;
2153 }
Structure specifying a writing operation on an IO handle.
static char * dir
Set to the directory where runtime files are stored.
Definition: gnunet-arm.c:89
enum GNUNET_FS_DownloadOptions options
Options for the download.
Definition: fs_api.h:1922
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct DownloadRequest * top_request
Top-level download request.
Definition: fs_api.h:1855
int GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:684
char * filename
Where are we writing the data (name of the file, can be NULL!).
Definition: fs_api.h:1821
char * temp_filename
Where are we writing the data temporarily (name of the file, can be NULL!); used if we do not have a ...
Definition: fs_api.h:1828
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
uint64_t old_file_size
What was the size of the file on disk that we&#39;re downloading before we started? Used to detect if the...
Definition: fs_api.h:1897
int GNUNET_FS_uri_test_loc(const struct GNUNET_FS_Uri *uri)
Is this a location URI?
Definition: fs_uri.c:1394
char * GNUNET_FS_uri_to_string(const struct GNUNET_FS_Uri *uri)
Convert a URI to a UTF-8 String.
Definition: fs_uri.c:2027
#define GNUNET_BIO_write_spec_end()
End of specifications marker.
uint64_t length
How many bytes starting from offset are desired? This is NOT the overall length of the file! ...
Definition: fs_api.h:1883
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:1335
char * GNUNET_DISK_mktemp(const char *t)
Create an (empty) temporary file on disk.
Definition: disk.c:468
char * serialization
Random portion of filename we use for syncing state of this download.
Definition: fs_api.h:1815
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
static char * fn
Filename of the unique file.
Internal option used to flag this download as a &#39;probe&#39; for a search result.
static void cleanup(void *cls)
Function scheduled as very last function, cleans up after us.
Handle for buffered writing.
Definition: bio.c:516
uint64_t offset
What is the first offset that we&#39;re interested in?
Definition: fs_api.h:1877
int GNUNET_FS_uri_test_chk(const struct GNUNET_FS_Uri *uri)
Is this a file (or directory) URI?
Definition: fs_uri.c:1356
struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_meta_data(const char *what, const struct GNUNET_CONTAINER_MetaData *m)
Create the specification to write a metadata container.
Definition: bio.c:1381
struct GNUNET_BIO_WriteHandle * GNUNET_BIO_write_open_file(const char *fn)
Open a file for writing.
Definition: bio.c:559
char * emsg
Error message, NULL if we&#39;re doing OK.
Definition: fs_api.h:1809
int has_finished
Flag set upon transitive completion (includes child downloads).
Definition: fs_api.h:1929
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:2019
static int write_start_time(struct GNUNET_BIO_WriteHandle *wh, struct GNUNET_TIME_Absolute timestamp)
Serialize a start-time.
Definition: fs_api.c:836
int GNUNET_BIO_write_close(struct GNUNET_BIO_WriteHandle *h, char **emsg)
Close an IO handle.
Definition: bio.c:608
static struct GNUNET_TESTBED_BarrierWaitHandle * wh
Our barrier wait handle.
static char * get_serialization_short_name(const char *fullname)
Given a serialization name (full absolute path), return the basename of the file (without the path)...
Definition: fs_api.c:1202
int GNUNET_BIO_write_spec_commit(struct GNUNET_BIO_WriteHandle *h, struct GNUNET_BIO_WriteSpec *ws)
Execute the write specifications in order.
Definition: bio.c:1539
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:1426
static int write_download_request(struct GNUNET_BIO_WriteHandle *wh, struct DownloadRequest *dr)
Serialize a download request.
Definition: fs_api.c:1914
uint32_t anonymity
Desired level of anonymity.
Definition: fs_api.h:1912
struct GNUNET_CONTAINER_MetaData * meta
Known meta-data for the file (can be NULL).
Definition: fs_api.h:1804
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:1471
struct GNUNET_TIME_Absolute start_time
Time download was started.
Definition: fs_api.h:1902
uint64_t completed
How many bytes have we already received within the specified range (DBlocks only).
Definition: fs_api.h:1889
struct GNUNET_FS_Uri * uri
URI that identifies the file that we are downloading.
Definition: fs_api.h:1799
#define GNUNET_free(ptr)
Wrapper around free.
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 2165 of file fs_api.c.

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_meta_data(), 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_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_download_stop(), GNUNET_FS_search_probe_progress_(), probe_failure_handler(), probe_success_handler(), process_ksk_result(), and process_sks_result().

2166 {
2167  struct GNUNET_BIO_WriteHandle *wh;
2168  char *uris;
2169 
2170  if (NULL == sr->sc)
2171  return;
2172  uris = NULL;
2173  if (NULL == sr->serialization)
2174  sr->serialization =
2176  (sr->sc->psearch_result == NULL)
2179  sr->sc->serialization);
2180  if (NULL == sr->serialization)
2181  return;
2182  wh = get_write_handle_in_dir (sr->h,
2183  (sr->sc->psearch_result == NULL)
2186  sr->sc->serialization,
2187  sr->serialization);
2188  if (NULL == wh)
2189  {
2190  GNUNET_break (0);
2191  goto cleanup;
2192  }
2193  uris = GNUNET_FS_uri_to_string (sr->uri);
2194  struct GNUNET_BIO_WriteSpec ws[] = {
2195  GNUNET_BIO_write_spec_string ("uris", uris),
2196  GNUNET_BIO_write_spec_string ("download serialization",
2197  (sr->download != NULL)
2198  ? sr->download->serialization
2199  : NULL),
2200  GNUNET_BIO_write_spec_string ("update search serialization",
2201  (sr->update_search != NULL)
2203  : NULL),
2204  GNUNET_BIO_write_spec_meta_data ("metadata", sr->meta),
2205  GNUNET_BIO_write_spec_object ("key", &sr->key,
2206  sizeof(struct GNUNET_HashCode)),
2207  GNUNET_BIO_write_spec_int32 ("mandatory missing",
2208  (int32_t *) &sr->mandatory_missing),
2209  GNUNET_BIO_write_spec_int32 ("optional support",
2210  (int32_t *) &sr->optional_support),
2211  GNUNET_BIO_write_spec_int32 ("availability success",
2212  (int32_t *) &sr->availability_success),
2213  GNUNET_BIO_write_spec_int32 ("availability trials",
2214  (int32_t *) &sr->availability_trials),
2216  };
2217  if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws)))
2218  {
2219  GNUNET_break (0);
2220  goto cleanup;
2221  }
2222  if ((NULL != sr->uri) && (GNUNET_FS_URI_KSK == sr->sc->uri->type) &&
2223  (GNUNET_OK !=
2224  GNUNET_BIO_write (wh,
2225  "keyword bitmap",
2226  sr->keyword_bitmap,
2227  (sr->sc->uri->data.ksk.keywordCount + 7) / 8)))
2228  {
2229  GNUNET_break (0);
2230  goto cleanup;
2231  }
2232  if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
2233  {
2234  wh = NULL;
2235  GNUNET_break (0);
2236  goto cleanup;
2237  }
2238  GNUNET_free (uris);
2239  return;
2240 cleanup:
2241  GNUNET_free (uris);
2242  if (NULL != wh)
2243  (void) GNUNET_BIO_write_close (wh, NULL);
2245  (NULL == sr->sc->psearch_result)
2248  sr->sc->serialization,
2249  sr->serialization);
2250  GNUNET_free (sr->serialization);
2251  sr->serialization = NULL;
2252 }
uint32_t optional_support
Number of optional keywords under which this result was also found.
Definition: fs_api.h:601
Structure specifying a writing operation on an IO handle.
struct GNUNET_FS_DownloadContext * download
ID of an associated download based on this search result (or NULL for none).
Definition: fs_api.h:545
struct GNUNET_FS_SearchResult * psearch_result
For update-searches, link to the search result that triggered the update search; otherwise NULL...
Definition: fs_api.h:1530
static char * make_serialization_file_name_in_dir(struct GNUNET_FS_Handle *h, const char *ext, const char *uni)
Create a new random name for serialization.
Definition: fs_api.c:1272
struct GNUNET_FS_SearchContext * sc
Search context this result belongs to; can be NULL for probes that come from a directory result...
Definition: fs_api.h:518
uint8_t * keyword_bitmap
Bitmap that specifies precisely which keywords have been matched already.
Definition: fs_api.h:561
static void remove_sync_file_in_dir(struct GNUNET_FS_Handle *h, const char *ext, const char *uni, const char *ent)
Remove serialization/deserialization file from disk.
Definition: fs_api.c:774
Keyword search key (query with keywords).
Definition: fs_api.h:153
struct GNUNET_FS_Uri * uri
URI to which this search result refers to.
Definition: fs_api.h:523
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:1288
static struct GNUNET_BIO_WriteHandle * get_write_handle_in_dir(struct GNUNET_FS_Handle *h, const char *ext, const char *uni, const char *ent)
Return a write handle for serialization.
Definition: fs_api.c:719
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_FS_Uri * uri
List of keywords that we&#39;re looking for.
Definition: fs_api.h:1524
struct GNUNET_FS_SearchContext * update_search
If this search result triggered an update search, this field links to the update search.
Definition: fs_api.h:551
char * GNUNET_FS_uri_to_string(const struct GNUNET_FS_Uri *uri)
Convert a URI to a UTF-8 String.
Definition: fs_uri.c:2027
#define GNUNET_BIO_write_spec_end()
End of specifications marker.
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:1335
char * serialization
Name of the file on disk we use for persistence.
Definition: fs_api.h:1545
char * serialization
Random portion of filename we use for syncing state of this download.
Definition: fs_api.h:1815
uint32_t availability_trials
Number of availability trials that we have performed for this search result.
Definition: fs_api.h:612
struct GNUNET_FS_Handle * h
File-sharing context this result belongs to.
Definition: fs_api.h:502
uint32_t availability_success
Number of availability tests that have succeeded for this result.
Definition: fs_api.h:606
static void cleanup(void *cls)
Function scheduled as very last function, cleans up after us.
Handle for buffered writing.
Definition: bio.c:516
A 512-bit hashcode.
#define GNUNET_FS_SYNC_PATH_CHILD_SEARCH
Name of the directory with sub-searches (namespace-updates).
Definition: fs_api.h:59
struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_meta_data(const char *what, const struct GNUNET_CONTAINER_MetaData *m)
Create the specification to write a metadata container.
Definition: bio.c:1381
int GNUNET_BIO_write_close(struct GNUNET_BIO_WriteHandle *h, char **emsg)
Close an IO handle.
Definition: bio.c:608
static struct GNUNET_TESTBED_BarrierWaitHandle * wh
Our barrier wait handle.
struct GNUNET_CONTAINER_MetaData * meta
Metadata for the search result.
Definition: fs_api.h:528
enum GNUNET_FS_UriType type
Type of the URI.
Definition: fs_api.h:170
struct GNUNET_HashCode key
Key for the search result based on the URI.
Definition: fs_api.h:566
union GNUNET_FS_Uri::@13 data
#define GNUNET_FS_SYNC_PATH_MASTER_SEARCH
Name of the directory with top-level searches.
Definition: fs_api.h:54
uint32_t mandatory_missing
Number of mandatory keywords for which we have NOT yet found the search result; when this value hits ...
Definition: fs_api.h:595
int GNUNET_BIO_write_spec_commit(struct GNUNET_BIO_WriteHandle *h, struct GNUNET_BIO_WriteSpec *ws)
Execute the write specifications in order.
Definition: bio.c:1539
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:1426
struct GNUNET_FS_Uri::@13::@14 ksk
char * serialization
Name under which this search result is stored on disk.
Definition: fs_api.h:556
int GNUNET_BIO_write(struct GNUNET_BIO_WriteHandle *h, const char *what, const void *buffer, size_t n)
Write a buffer to a handle.
Definition: bio.c:795
#define GNUNET_free(ptr)
Wrapper around free.
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 2264 of file fs_api.c.

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, 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().

2265 {
2266  struct GNUNET_BIO_WriteHandle *wh;
2267  char *uris;
2268  char in_pause;
2269  const char *category;
2270 
2271  category = (NULL == sc->psearch_result) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
2273  if (NULL == sc->serialization)
2274  sc->serialization = make_serialization_file_name (sc->h, category);
2275  if (NULL == sc->serialization)
2276  return;
2277  uris = NULL;
2278  wh = get_write_handle (sc->h, category, sc->serialization);
2279  if (NULL == wh)
2280  {
2281  GNUNET_break (0);
2282  goto cleanup;
2283  }
2286  uris = GNUNET_FS_uri_to_string (sc->uri);
2287  in_pause = (sc->task != NULL) ? 'r' : '\0';
2288  if ((GNUNET_OK != GNUNET_BIO_write_string (wh, "uris", uris)) ||
2289  (GNUNET_OK != write_start_time (wh, sc->start_time)) ||
2290  (GNUNET_OK != GNUNET_BIO_write_string (wh, "emsg", sc->emsg)) ||
2291  (GNUNET_OK != GNUNET_BIO_write_int32 (wh, "options",
2292  (uint32_t) sc->options)) ||
2293  (GNUNET_OK != GNUNET_BIO_write (wh, "in pause",
2294  &in_pause, sizeof(in_pause))) ||
2295  (GNUNET_OK != GNUNET_BIO_write_int32 (wh, "anonymity", sc->anonymity)))
2296  {
2297  GNUNET_break (0);
2298  goto cleanup;
2299  }
2300  GNUNET_free (uris);
2301  uris = NULL;
2302  if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
2303  {
2304  wh = NULL;
2305  GNUNET_break (0);
2306  goto cleanup;
2307  }
2308  return;
2309 cleanup:
2310  if (NULL != wh)
2311  (void) GNUNET_BIO_write_close (wh, NULL);
2312  GNUNET_free (uris);
2313  GNUNET_FS_remove_sync_file_ (sc->h, category, sc->serialization);
2314  GNUNET_free (sc->serialization);
2315  sc->serialization = NULL;
2316 }
int GNUNET_FS_uri_test_ksk(const struct GNUNET_FS_Uri *uri)
Is this a keyword URI?
Definition: fs_uri.c:1334
struct GNUNET_SCHEDULER_Task * task
ID of a task that is using this struct and that must be cancelled when the search is being stopped (i...
Definition: fs_api.h:1582
struct GNUNET_FS_SearchResult * psearch_result
For update-searches, link to the search result that triggered the update search; otherwise NULL...
Definition: fs_api.h:1530
enum GNUNET_FS_SearchOptions options
Options for the search.
Definition: fs_api.h:1597
char * emsg
Error message (non-NULL if this operation failed).
Definition: fs_api.h:1550
struct GNUNET_TIME_Absolute start_time
When did we start?
Definition: fs_api.h:1569
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_BIO_WriteHandle * get_write_handle(struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
Return a write handle for serialization.
Definition: fs_api.c:694
int GNUNET_FS_uri_test_sks(const struct GNUNET_FS_Uri *uri)
Is this a namespace URI?
Definition: fs_uri.c:1281
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_FS_Uri * uri
List of keywords that we&#39;re looking for.
Definition: fs_api.h:1524
uint32_t anonymity
Anonymity level for the search.
Definition: fs_api.h:1587
char * GNUNET_FS_uri_to_string(const struct GNUNET_FS_Uri *uri)
Convert a URI to a UTF-8 String.
Definition: fs_uri.c:2027
char * serialization
Name of the file on disk we use for persistence.
Definition: fs_api.h:1545
static void cleanup(void *cls)
Function scheduled as very last function, cleans up after us.
Handle for buffered writing.
Definition: bio.c:516
#define GNUNET_FS_SYNC_PATH_CHILD_SEARCH
Name of the directory with sub-searches (namespace-updates).
Definition: fs_api.h:59
static int write_start_time(struct GNUNET_BIO_WriteHandle *wh, struct GNUNET_TIME_Absolute timestamp)
Serialize a start-time.
Definition: fs_api.c:836
int GNUNET_BIO_write_close(struct GNUNET_BIO_WriteHandle *h, char **emsg)
Close an IO handle.
Definition: bio.c:608
static struct GNUNET_TESTBED_BarrierWaitHandle * wh
Our barrier wait handle.
int GNUNET_BIO_write_int32(struct GNUNET_BIO_WriteHandle *h, const char *what, int32_t i)
Write an (u)int32_t.
Definition: bio.c:936
#define GNUNET_FS_SYNC_PATH_MASTER_SEARCH
Name of the directory with top-level searches.
Definition: fs_api.h:54
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:1236
int GNUNET_BIO_write_string(struct GNUNET_BIO_WriteHandle *h, const char *what, const char *s)
Write a 0-terminated string.
Definition: bio.c:832
struct GNUNET_FS_Handle * h
Handle to the global FS context.
Definition: fs_api.h:1514
int GNUNET_BIO_write(struct GNUNET_BIO_WriteHandle *h, const char *what, const void *buffer, size_t n)
Write a buffer to a handle.
Definition: bio.c:795
void GNUNET_FS_remove_sync_file_(struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
Remove serialization/deserialization file from disk.
Definition: fs_api.c:744
#define GNUNET_free(ptr)
Wrapper around free.
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 2328 of file fs_api.c.

References _, GNUNET_FS_UnindexContext::chk, cleanup(), GNUNET_FS_Uri::data, deserialize_download(), deserialize_search(), GNUNET_FS_UnindexContext::emsg, GNUNET_FS_UnindexContext::fhc, GNUNET_FS_UnindexContext::file_id, GNUNET_FS_UnindexContext::file_size, GNUNET_FS_UnindexContext::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, GNUNET_FS_SearchContext::psearch_result, read_start_time(), GNUNET_FS_ProgressInfo::search, GNUNET_FS_UnindexContext::serialization, GNUNET_FS_SearchContext::serialization, GNUNET_FS_UnindexContext::start_time, state, GNUNET_FS_UnindexContext::state, GNUNET_FS_ProgressInfo::status, GNUNET_FS_UnindexContext::top, uc, GNUNET_FS_ProgressInfo::unindex, UNINDEX_STATE_COMPLETE, UNINDEX_STATE_DS_REMOVE, UNINDEX_STATE_DS_REMOVE_KBLOCKS, UNINDEX_STATE_ERROR, UNINDEX_STATE_EXTRACT_KEYWORDS, UNINDEX_STATE_FS_NOTIFY, UNINDEX_STATE_HASHING, and GNUNET_FS_ProgressInfo::value.

Referenced by GNUNET_FS_start().

2329 {
2330  struct GNUNET_FS_Handle *h = cls;
2331  struct GNUNET_BIO_ReadHandle *rh;
2332  struct GNUNET_FS_UnindexContext *uc;
2333  struct GNUNET_FS_ProgressInfo pi;
2334  char *emsg;
2335  char *uris;
2336  uint32_t state;
2337 
2338  uc = GNUNET_new (struct GNUNET_FS_UnindexContext);
2339  uc->h = h;
2342  if (NULL == rh)
2343  {
2344  GNUNET_break (0);
2345  goto cleanup;
2346  }
2347  uris = NULL;
2348  if ((GNUNET_OK !=
2349  GNUNET_BIO_read_string (rh, "unindex-fn", &uc->filename, 10 * 1024)) ||
2350  (GNUNET_OK != GNUNET_BIO_read_int64 (rh, "file size",
2351  (int64_t *) &uc->file_size)) ||
2352  (GNUNET_OK != read_start_time (rh, &uc->start_time)) ||
2353  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "state",
2354  (int32_t *) &state)) ||
2355  (GNUNET_OK !=
2356  GNUNET_BIO_read (rh, "uri", &uc->chk, sizeof(struct ContentHashKey))) ||
2357  (GNUNET_OK !=
2358  GNUNET_BIO_read_string (rh, "unindex-kskuri", &uris, 10 * 1024)) ||
2359  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "ksk offset",
2360  (int32_t *) &uc->ksk_offset)))
2361  {
2362  GNUNET_free (uris);
2363  GNUNET_break (0);
2364  goto cleanup;
2365  }
2366  if (NULL != uris)
2367  {
2368  uc->ksk_uri = GNUNET_FS_uri_parse (uris, &emsg);
2369  GNUNET_free (uris);
2370  if (NULL == uc->ksk_uri)
2371  {
2372  GNUNET_break (0);
2373  GNUNET_free (emsg);
2374  goto cleanup;
2375  }
2376  }
2377  if ((uc->ksk_offset > 0) &&
2378  ((NULL == uc->ksk_uri) ||
2379  (uc->ksk_offset > uc->ksk_uri->data.ksk.keywordCount)))
2380  {
2381  GNUNET_break (0);
2382  goto cleanup;
2383  }
2384  uc->state = (enum UnindexState) state;
2385  switch (state)
2386  {
2387  case UNINDEX_STATE_HASHING:
2388  break;
2389 
2391  if (GNUNET_OK != GNUNET_BIO_read (rh,
2392  "unindex-hash",
2393  &uc->file_id,
2394  sizeof(struct GNUNET_HashCode)))
2395  {
2396  GNUNET_break (0);
2397  goto cleanup;
2398  }
2399  break;
2400 
2404  break;
2405 
2407  break;
2408 
2409  case UNINDEX_STATE_ERROR:
2410  if (GNUNET_OK !=
2411  GNUNET_BIO_read_string (rh, "unindex-emsg", &uc->emsg, 10 * 1024))
2412  {
2413  GNUNET_break (0);
2414  goto cleanup;
2415  }
2416  break;
2417 
2418  default:
2419  GNUNET_break (0);
2420  goto cleanup;
2421  }
2424  pi.value.unindex.specifics.resume.message = uc->emsg;
2426  uc,
2427  (uc->state == UNINDEX_STATE_COMPLETE)
2428  ? uc->file_size
2429  : 0);
2430  switch (uc->state)
2431  {
2432  case UNINDEX_STATE_HASHING:
2434  uc->filename,
2437  uc);
2438  break;
2439 
2443  break;
2444 
2447  break;
2448 
2451  break;
2452 
2455  break;
2456 
2458  case UNINDEX_STATE_ERROR:
2459  /* no need to resume any operation, we were done */
2460  break;
2461 
2462  default:
2463  break;
2464  }
2465  if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
2466  {
2468  _ ("Failure while resuming unindexing operation `%s': %s\n"),
2469  filename,
2470  emsg);
2471  GNUNET_free (emsg);
2472  }
2473  return GNUNET_OK;
2474 cleanup:
2475  GNUNET_free (uc->filename);
2476  if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)))
2477  {
2479  _ ("Failed to resume unindexing operation `%s': %s\n"),
2480  filename,
2481  emsg);
2482  GNUNET_free (emsg);
2483  }
2484  if (NULL != uc->serialization)
2487  uc->serialization);
2488  GNUNET_free (uc->serialization);
2489  GNUNET_free (uc);
2490  return GNUNET_OK;
2491 }
char * serialization
Short name under which we are serializing the state of this operation.
Definition: fs_api.h:1390
int GNUNET_BIO_read_int32(struct GNUNET_BIO_ReadHandle *h, const char *what, int32_t *i)
Read an (u)int32_t.
Definition: bio.c:478
content hash key
Definition: fs.h:53
uint32_t ksk_offset
Current offset in KSK removal.
Definition: fs_api.h:1380
struct GNUNET_BIO_ReadHandle * GNUNET_BIO_read_open_file(const char *fn)
Open a file for reading.
Definition: bio.c:119
struct GNUNET_FS_Uri * GNUNET_FS_uri_parse(const char *uri, char **emsg)
Convert a UTF-8 String to a URI.
Definition: fs_uri.c:644
Master context for most FS operations.
Definition: fs_api.h:1068
We&#39;re done.
Definition: fs_api.h:1337
void GNUNET_FS_unindex_do_remove_(struct GNUNET_FS_UnindexContext *uc)
Connect to the datastore and remove the blocks.
Definition: fs_unindex.c:649
static struct GNUNET_FS_UnindexContext * uc
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_HashCode file_id
Hash of the file&#39;s contents (once computed).
Definition: fs_api.h:1458
enum UnindexState state
Current operatinonal phase.
Definition: fs_api.h:1463
struct GNUNET_CRYPTO_FileHashContext * GNUNET_CRYPTO_hash_file(enum GNUNET_SCHEDULER_Priority priority, const char *filename, size_t blocksize, GNUNET_CRYPTO_HashCompletedCallback callback, void *callback_cls)
Compute the hash of an entire file.
static struct GNUNET_PEERINFO_Handle * pi
Handle to peerinfo service.
Handle for controlling an unindexing operation.
Definition: fs_api.h:1349
int GNUNET_BIO_read_close(struct GNUNET_BIO_ReadHandle *h, char **emsg)
Close an open handle.
Definition: bio.c:166
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_CRYPTO_FileHashContext * fhc
Context for hashing of the file.
Definition: fs_api.h:1443
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
Find out which keywords apply.
Definition: fs_api.h:1321
We&#39;re notifying the FS service about the unindexing.
Definition: fs_api.h:1332
#define _(String)
GNU gettext support macro.
Definition: platform.h:184
int GNUNET_BIO_read(struct GNUNET_BIO_ReadHandle *h, const char *what, void *result, size_t len)
Read some contents into a buffer.
Definition: bio.c:287
struct TopLevelActivity * top
Our top-level activity entry.
Definition: fs_api.h:1365
enum State state
current state of profiling
#define GNUNET_FS_SYNC_PATH_MASTER_UNINDEX
Name of the directory with unindex operations.
Definition: fs_api.h:86
void GNUNET_FS_unindex_do_remove_kblocks_(struct GNUNET_FS_UnindexContext *uc)
If necessary, connect to the datastore and remove the KBlocks.
Definition: fs_unindex.c:580
We&#39;re telling the datastore to remove KBlocks.
Definition: fs_api.h:1326
UnindexState
Phases of unindex processing (state machine).
Definition: fs_api.h:1305
struct GNUNET_TIME_Absolute start_time
When did we start?
Definition: fs_api.h:1453
static char * filename
static void cleanup(void *cls)
Function scheduled as very last function, cleans up after us.
We&#39;ve encountered a fatal error.
Definition: fs_api.h:1342
struct GNUNET_FS_Uri * ksk_uri
Keywords found (telling us which KBlocks to remove).
Definition: fs_api.h:1375
A 512-bit hashcode.
char * filename
Name of the file that we are unindexing.
Definition: fs_api.h:1385
int GNUNET_BIO_read_string(struct GNUNET_BIO_ReadHandle *h, const char *what, char **result, size_t max_length)
Read 0-terminated string.
Definition: bio.c:326
Run when otherwise idle.
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:1202
void GNUNET_FS_unindex_make_status_(struct GNUNET_FS_ProgressInfo *pi, struct GNUNET_FS_UnindexContext *uc, uint64_t offset)
Fill in all of the generic fields for an unindex event and call the callback.
Definition: fs_unindex.c:84
void GNUNET_FS_unindex_signal_suspend_(void *cls)
Create SUSPEND event for the given unindex operation and then clean up our state (without stop signal...
Definition: fs_unindex.c:727
union GNUNET_FS_Uri::@13 data
struct TopLevelActivity * GNUNET_FS_make_top(struct GNUNET_FS_Handle *h, SuspendSignalFunction ssf, void *ssf_cls)
Create a top-level activity entry.
Definition: fs_api.c:391
We&#39;re currently hashing the file.
Definition: fs_api.h:1310
#define HASHING_BLOCKSIZE
Blocksize to use when hashing files for indexing (blocksize for IO, not for the DBlocks).
Definition: fs.h:47
We&#39;re telling the datastore to delete the respective DBlocks and IBlocks.
Definition: fs_api.h:1316
static int read_start_time(struct GNUNET_BIO_ReadHandle *rh, struct GNUNET_TIME_Absolute *timestamp)
Deserialize a start-time.
Definition: fs_api.c:861
void GNUNET_FS_unindex_do_extract_keywords_(struct GNUNET_FS_UnindexContext *uc)
Extract the keywords for KBlock removal.
Definition: fs_unindex.c:406
struct GNUNET_FS_Uri::@13::@14 ksk
struct ContentHashKey chk
The content hash key of the last block we processed, will in the end be set to the CHK from the URI...
Definition: fs_api.h:1355
#define GNUNET_log(kind,...)
char * emsg
Error message, NULL on success.
Definition: fs_api.h:1438
Notification that we resumed unindexing of a file.
struct GNUNET_FS_Handle * h
Global FS context.
Definition: fs_api.h:1360
void GNUNET_FS_unindex_process_hash_(void *cls, const struct GNUNET_HashCode *file_id)
Function called once the hash of the file that is being unindexed has been computed.
Definition: fs_unindex.c:694
int GNUNET_BIO_read_int64(struct GNUNET_BIO_ReadHandle *h, const char *what, int64_t *i)
Read an (u)int64_t.
Definition: bio.c:500
void GNUNET_FS_remove_sync_file_(struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
Remove serialization/deserialization file from disk.
Definition: fs_api.c:744
Handle for buffered reading.
Definition: bio.c:73
#define GNUNET_free(ptr)
Wrapper around free.
Argument given to the progress callback with information about what is going on.
uint64_t file_size
Overall size of the file.
Definition: fs_api.h:1448
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 2925 of file fs_api.c.

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_meta_data(), 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_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, 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_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(), deserialize_subdownload(), and deserialize_unindex_file().

2930 {
2931  struct GNUNET_FS_DownloadContext *dc;
2932  char *emsg;
2933  char *uris;
2934  char *dn;
2935  uint32_t options;
2936  uint32_t status;
2937 
2938  uris = NULL;
2939  emsg = NULL;
2940  dc = GNUNET_new (struct GNUNET_FS_DownloadContext);
2941  dc->parent = parent;
2942  dc->h = h;
2944  struct GNUNET_BIO_ReadSpec rs[] = {
2945  GNUNET_BIO_read_spec_meta_data ("download-meta", &dc->meta),
2946  GNUNET_BIO_read_spec_string ("download-emsg", &dc->emsg, 10 * 1024),
2947  GNUNET_BIO_read_spec_string ("download-fn", &dc->filename, 10 * 1024),
2948  GNUNET_BIO_read_spec_string ("download-tfn",
2949  &dc->temp_filename, 10 * 1024),
2950  GNUNET_BIO_read_spec_int64 ("old file size",
2951  (int64_t *) &dc->old_file_size),
2952  GNUNET_BIO_read_spec_int64 ("offset",
2953  (int64_t *) &dc->offset),
2954  GNUNET_BIO_read_spec_int64 ("length",
2955  (int64_t *) &dc->length),
2956  GNUNET_BIO_read_spec_int64 ("completed",
2957  (int64_t *) &dc->completed),
2959  };