GNUnet  0.10.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);
63  qe->h->pending_tail,
64  qe);
66  qe->h->running_tail,
67  qe->h->running_tail,
68  qe);
69 }
#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:1132
unsigned int active_blocks
How many blocks do the active downloads have?
Definition: fs_api.h:1175
struct GNUNET_FS_QueueEntry * running_head
Head of DLL of running jobs.
Definition: fs_api.h:1122
int active
GNUNET_YES if the job is active now.
Definition: fs_api.h:503
#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:447
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:1127
struct GNUNET_FS_Handle * h
Handle to FS primary context.
Definition: fs_api.h:462
unsigned int active_downloads
How many actual downloads do we have running right now?
Definition: fs_api.h:1170
struct GNUNET_TIME_Absolute start_time
Time the job was started last.
Definition: fs_api.h:477
unsigned int blocks
How many blocks do the active downloads have?
Definition: fs_api.h:488
#define GNUNET_log(kind,...)
struct GNUNET_FS_QueueEntry * pending_tail
Tail of DLL of pending jobs.
Definition: fs_api.h:1137
#define GNUNET_YES
Definition: gnunet_common.h:80
void * cls
Closure for start and stop.
Definition: fs_api.h:457
unsigned int start_times
How often have we (re)started this download?
Definition: fs_api.h:498
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 79 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().

80 {
81  qe->active = GNUNET_NO;
82  qe->stop (qe->cls);
83  GNUNET_assert (0 < qe->h->active_downloads);
84  qe->h->active_downloads--;
85  qe->h->active_blocks -= qe->blocks;
86  qe->run_time =
89  (qe->start_time));
91  "Stopping job %p (%u active)\n",
92  qe,
93  qe->h->active_downloads);
95  qe->h->running_tail,
96  qe);
98  qe->h->pending_tail,
99  qe->h->pending_tail,
100  qe);
101 }
#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:1132
unsigned int active_blocks
How many blocks do the active downloads have?
Definition: fs_api.h:1175
#define GNUNET_NO
Definition: gnunet_common.h:81
struct GNUNET_FS_QueueEntry * running_head
Head of DLL of running jobs.
Definition: fs_api.h:1122
int active
GNUNET_YES if the job is active now.
Definition: fs_api.h:503
#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:1127
struct GNUNET_FS_Handle * h
Handle to FS primary context.
Definition: fs_api.h:462
unsigned int active_downloads
How many actual downloads do we have running right now?
Definition: fs_api.h:1170
struct GNUNET_TIME_Absolute start_time
Time the job was started last.
Definition: fs_api.h:477
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:576
struct GNUNET_TIME_Relative run_time
Total amount of time the job has been running (except for the current run).
Definition: fs_api.h:483
unsigned int blocks
How many blocks do the active downloads have?
Definition: fs_api.h:488
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
Definition: time.c:373
#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:452
struct GNUNET_FS_QueueEntry * pending_tail
Tail of DLL of pending jobs.
Definition: fs_api.h:1137
void * cls
Closure for start and stop.
Definition: fs_api.h:457
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 111 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_().

112 {
113  struct GNUNET_FS_Handle *h = cls;
114  struct GNUNET_FS_QueueEntry *qe;
115  struct GNUNET_FS_QueueEntry *next;
116  struct GNUNET_TIME_Relative run_time;
117  struct GNUNET_TIME_Relative restart_at;
118  struct GNUNET_TIME_Relative rst;
120  unsigned int num_downloads_waiting;
121  unsigned int num_downloads_active;
122  unsigned int num_downloads_expired;
123  unsigned int num_probes_active;
124  unsigned int num_probes_waiting;
125  unsigned int num_probes_expired;
126  int num_probes_change;
127  int num_downloads_change;
128  int block_limit_hit;
129 
130  h->queue_job = NULL;
131  /* restart_at will be set to the time when it makes sense to
132  re-evaluate the job queue (unless, of course, jobs complete
133  or are added, then we'll be triggered immediately */
134  restart_at = GNUNET_TIME_UNIT_FOREVER_REL;
135  /* first, calculate some basic statistics on pending jobs */
136  num_probes_waiting = 0;
137  num_downloads_waiting = 0;
138  for (qe = h->pending_head; NULL != qe; qe = qe->next)
139  {
140  switch (qe->priority)
141  {
143  num_probes_waiting++;
144  break;
146  num_downloads_waiting++;
147  break;
148  default:
149  GNUNET_break (0);
150  break;
151  }
152  }
153  /* now, calculate some basic statistics on running jobs */
154  num_probes_active = 0;
155  num_probes_expired = 0;
156  num_downloads_active = 0;
157  num_downloads_expired = 0;
158  next = h->running_head;
159  while (NULL != (qe = next))
160  {
161  next = qe->next;
162  switch (qe->priority)
163  {
166  end_time = GNUNET_TIME_absolute_add (qe->start_time, run_time);
168  if (0 == rst.rel_value_us)
169  {
170  num_probes_expired++;
171  stop_job (qe);
172  }
173  else
174  {
175  num_probes_active++;
176  restart_at = GNUNET_TIME_relative_min (rst, restart_at);
177  }
178  break;
180  run_time =
182  qe->blocks * qe->start_times);
183  end_time = GNUNET_TIME_absolute_add (qe->start_time, run_time);
185  if (0 == rst.rel_value_us)
186  {
187  num_downloads_expired++;
188  stop_job (qe);
189  }
190  else
191  {
192  num_downloads_active++;
193  restart_at = GNUNET_TIME_relative_min (rst, restart_at);
194  }
195  break;
196  default:
197  GNUNET_break (0);
198  break;
199  }
200  }
202  num_downloads_active + num_probes_active);
204  "PA: %u, PE: %u, PW: %u; DA: %u, DE: %u, DW: %u\n",
205  num_probes_active,
206  num_probes_expired,
207  num_probes_waiting,
208  num_downloads_active,
209  num_downloads_expired,
210  num_downloads_waiting);
211  GNUNET_break (h->active_downloads + num_probes_active <=
213  /* calculate start/stop decisions */
214  if (h->active_downloads + num_downloads_waiting > h->max_parallel_downloads)
215  {
216  /* stop as many probes as there are downloads and probes */
217  num_probes_change = - GNUNET_MIN (num_probes_active,
218  num_downloads_waiting);
219  /* start as many downloads as there are free slots, including those
220  we just opened up */
221  num_downloads_change = h->max_parallel_downloads - h->active_downloads - num_probes_change;
222  }
223  else
224  {
225  /* start all downloads (we can) */
226  num_downloads_change = num_downloads_waiting;
227  /* also start probes if there is room, but use a lower cap of (mpd/4) + 1 */
228  if (1 + h->max_parallel_downloads / 4 >= (h->active_downloads + num_downloads_change))
229  num_probes_change = GNUNET_MIN (num_probes_waiting,
230  (1 + h->max_parallel_downloads / 4) - (h->active_downloads + num_downloads_change));
231  else
232  num_probes_change = 0;
233  }
234  GNUNET_break (num_downloads_change <= num_downloads_waiting);
236  "Changing %d probes and %d/%u/%u downloads\n",
237  num_probes_change,
238  num_downloads_change,
239  (unsigned int) h->active_downloads,
240  (unsigned int) h->max_parallel_downloads);
241  /* actually stop probes */
242  next = h->running_head;
243  while (NULL != (qe = next))
244  {
245  next = qe->next;
247  continue;
248  if (num_probes_change < 0)
249  {
250  stop_job (qe);
251  num_probes_change++;
252  if (0 == num_probes_change)
253  break;
254  }
255  }
256  GNUNET_break (0 <= num_probes_change);
257 
258  /* start some more tasks if we now have empty slots */
259  block_limit_hit = GNUNET_NO;
260  next = h->pending_head;
261  while ( (NULL != (qe = next)) &&
262  ( (num_probes_change > 0) ||
263  (num_downloads_change > 0) ) )
264  {
265  next = qe->next;
266  switch (qe->priority)
267  {
269  if (num_probes_change > 0)
270  {
271  start_job (qe);
272  num_probes_change--;
274  restart_at = GNUNET_TIME_relative_min (run_time, restart_at);
275  }
276  break;
278  if ( (num_downloads_change > 0) &&
279  ( (qe->blocks + h->active_blocks <= h->max_parallel_requests) ||
280  ( (qe->blocks > h->max_parallel_requests) &&
281  (0 == h->active_downloads) ) ) )
282  {
283  start_job (qe);
284  num_downloads_change--;
285  }
286  else if (num_downloads_change > 0)
287  block_limit_hit = GNUNET_YES;
288  break;
289  default:
290  GNUNET_break (0);
291  break;
292  }
293  }
294  GNUNET_break ( (0 == num_downloads_change) ||
295  (GNUNET_YES == block_limit_hit) );
296  GNUNET_break (0 == num_probes_change);
297 
299  "AD: %u, MP: %u; %d probes and %d downloads to start, will run again in %s\n",
300  h->active_downloads,
302  num_probes_change,
303  num_downloads_change,
305 
306  /* make sure we run again, callbacks might have
307  already re-scheduled the job, so cancel such
308  an operation (if it exists) */
309  if (NULL != h->queue_job)
311  h->queue_job =
313 }
This is a probe (low priority).
Definition: fs_api.h:420
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:1165
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:1153
Master context for most FS operations.
Definition: fs_api.h:1087
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:79
struct GNUNET_FS_QueueEntry * pending_head
Head of DLL of pending jobs.
Definition: fs_api.h:1132
static void process_job_queue(void *cls)
Process the jobs in the job queue, possibly starting some and stopping others.
Definition: fs_api.c:111
unsigned int active_blocks
How many blocks do the active downloads have?
Definition: fs_api.h:1175
#define GNUNET_NO
Definition: gnunet_common.h:81
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_add(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
Add a given relative duration to the given start time.
Definition: time.c:393
struct GNUNET_FS_QueueEntry * running_head
Head of DLL of running jobs.
Definition: fs_api.h:1122
unsigned int max_parallel_requests
Maximum number of parallel requests.
Definition: fs_api.h:1190
#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:94
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:1246
enum GNUNET_FS_QueuePriority priority
How important is this download?
Definition: fs_api.h:493
#define GNUNET_MIN(a, b)
Definition: gnunet_common.h:83
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:727
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:439
#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:1170
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:271
struct GNUNET_TIME_Absolute start_time
Time the job was started last.
Definition: fs_api.h:477
unsigned int blocks
How many blocks do the active downloads have?
Definition: fs_api.h:488
struct GNUNET_FS_QueueEntry * next
This is a linked list.
Definition: fs_api.h:437
#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.
#define GNUNET_YES
Definition: gnunet_common.h:80
unsigned int max_parallel_downloads
Maximum number of parallel downloads.
Definition: fs_api.h:1185
Entry in the job queue.
Definition: fs_api.h:432
struct GNUNET_TIME_Relative GNUNET_TIME_relative_saturating_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Saturating multiply relative time by a given factor.
Definition: time.c:499
Default priority.
Definition: fs_api.h:425
unsigned int start_times
How often have we (re)started this download?
Definition: fs_api.h:498
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:965
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 328 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_().

334 {
335  struct GNUNET_FS_QueueEntry *qe;
336 
337  qe = GNUNET_new (struct GNUNET_FS_QueueEntry);
338  qe->h = h;
339  qe->start = start;
340  qe->stop = stop;
341  qe->cls = cls;
343  qe->blocks = blocks;
344  qe->priority = priority;
346  h->pending_tail, qe);
347  if (NULL != h->queue_job)
351  "Queueing job %p\n",
352  qe);
353  return qe;
354 }
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:1153
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:1132
static void process_job_queue(void *cls)
Process the jobs in the job queue, possibly starting some and stopping others.
Definition: fs_api.c:111
#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:94
struct GNUNET_TIME_Absolute queue_time
Time the job was originally queued.
Definition: fs_api.h:472
enum GNUNET_FS_QueuePriority priority
How important is this download?
Definition: fs_api.h:493
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:1273
#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:447
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:462
unsigned int blocks
How many blocks do the active downloads have?
Definition: fs_api.h:488
#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:452
struct GNUNET_FS_QueueEntry * pending_tail
Tail of DLL of pending jobs.
Definition: fs_api.h:1137
void * cls
Closure for start and stop.
Definition: fs_api.h:457
Entry in the job queue.
Definition: fs_api.h:432
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
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 363 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().

364 {
365  struct GNUNET_FS_Handle *h;
366 
367  h = qe->h;
369  "Dequeueing job %p\n",
370  qe);
371  if (GNUNET_YES == qe->active)
372  stop_job (qe);
374  h->pending_tail,
375  qe);
376  GNUNET_free (qe);
377  if (NULL != h->queue_job)
380  h);
381 }
#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:1153
Master context for most FS operations.
Definition: fs_api.h:1087
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:79
struct GNUNET_FS_QueueEntry * pending_head
Head of DLL of pending jobs.
Definition: fs_api.h:1132
static void process_job_queue(void *cls)
Process the jobs in the job queue, possibly starting some and stopping others.
Definition: fs_api.c:111
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
int active
GNUNET_YES if the job is active now.
Definition: fs_api.h:503
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:1273
struct GNUNET_FS_Handle * h
Handle to FS primary context.
Definition: fs_api.h:462
#define GNUNET_log(kind,...)
struct GNUNET_FS_QueueEntry * pending_tail
Tail of DLL of pending jobs.
Definition: fs_api.h:1137
#define GNUNET_YES
Definition: gnunet_common.h:80
#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:965
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 393 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().

396 {
397  struct TopLevelActivity *ret;
398 
399  ret = GNUNET_new (struct TopLevelActivity);
400  ret->ssf = ssf;
401  ret->ssf_cls = ssf_cls;
403  h->top_tail,
404  ret);
405  return ret;
406 }
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static int ret
Final status code.
Definition: gnunet-arm.c:89
struct TopLevelActivity * top_tail
Tail of DLL of top-level activities.
Definition: fs_api.h:1117
struct TopLevelActivity * top_head
Head of DLL of top-level activities.
Definition: fs_api.h:1112
void * ssf_cls
Closure for &#39;ssf&#39; (some struct GNUNET_FS_XXXHandle*)
Definition: fs_api.h:1054
We track all of the top-level activities of FS so that we can signal &#39;suspend&#39; on shutdown...
Definition: fs_api.h:1034
SuspendSignalFunction ssf
Function to call for suspend-signalling and clean up.
Definition: fs_api.h:1049
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 416 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().

418 {
420  h->top_tail,
421  top);
422  GNUNET_free (top);
423 }
#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:1117
struct TopLevelActivity * top_head
Head of DLL of top-level activities.
Definition: fs_api.h:1112
#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 464 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, ret, and STRERROR.

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

469 {
470  struct FileInfo *fi = cls;
471  ssize_t ret;
472 
473  if (UINT64_MAX == offset)
474  {
475  if (NULL != fi->fd)
476  {
478  fi->fd = NULL;
479  }
480  return 0;
481  }
482  if (0 == max)
483  {
484  if (NULL != fi->fd)
486  GNUNET_free (fi->filename);
487  GNUNET_free (fi);
488  return 0;
489  }
490  if (NULL == fi->fd)
491  {
492  fi->fd =
496  if (NULL == fi->fd)
497  {
498  GNUNET_asprintf (emsg,
499  _("Could not open file `%s': %s"),
500  fi->filename,
501  STRERROR (errno));
502  return 0;
503  }
504  }
505  if ( (GNUNET_SYSERR ==
507  (-1 == (ret = GNUNET_DISK_file_read (fi->fd, buf, max))) )
508  {
509  GNUNET_asprintf (emsg,
510  _("Could not read file `%s': %s"),
511  fi->filename,
512  STRERROR (errno));
513  return 0;
514  }
515  if (ret != max)
516  {
517  GNUNET_asprintf (emsg,
518  _("Short read reading from file `%s'!"),
519  fi->filename);
520  return 0;
521  }
522  return max;
523 }
Open the file for reading.
int GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1817
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:881
#define STRERROR(i)
Definition: plibc.h:676
Nobody is allowed to do anything to the file.
struct GNUNET_DISK_FileHandle * fd
File descriptor, NULL if it has not yet been opened.
Definition: fs_api.c:439
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:241
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
static char buf[2048]
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
Seek an absolute position (from the start of the file).
char * filename
Name of the file to read.
Definition: fs_api.c:434
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:1673
Closure for GNUNET_FS_data_reader_file_().
Definition: fs_api.c:429
#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 533 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().

534 {
535  struct FileInfo *fi;
536 
537  fi = GNUNET_new (struct FileInfo);
539  if (NULL == fi->filename)
540  {
541  GNUNET_free (fi);
542  return NULL;
543  }
544  return fi;
545 }
#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:602
char * filename
Name of the file to read.
Definition: fs_api.c:434
Closure for GNUNET_FS_data_reader_file_().
Definition: fs_api.c:429
#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 569 of file fs_api.c.

References data, GNUNET_free_non_null, and GNUNET_memcpy.

Referenced by deserialize_fi_node(), and GNUNET_FS_file_information_create_from_data().

574 {
575  char *data = cls;
576 
577  if (UINT64_MAX == offset)
578  return 0;
579  if (0 == max)
580  {
581  GNUNET_free_non_null (data);
582  return 0;
583  }
584  GNUNET_memcpy (buf, &data[offset], max);
585  return max;
586 }
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#define GNUNET_memcpy(dst, src, n)
static char buf[2048]
uint32_t data
The data value.
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 599 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().

602 {
603  char *basename;
604  char *ret;
605 
606  if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
607  return NULL; /* persistence not requested */
608  if (GNUNET_OK !=
609  GNUNET_CONFIGURATION_get_value_filename (h->cfg, "fs", "STATE_DIR",
610  &basename))
611  return NULL;
612  GNUNET_asprintf (&ret, "%s%s%s%s%s%s%s", basename, DIR_SEPARATOR_STR,
614  ent);
615  GNUNET_free (basename);
616  return ret;
617 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static int ret
Final status code.
Definition: gnunet-arm.c:89
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
char * client_name
Name of our client.
Definition: fs_api.h:1097
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 DIR_SEPARATOR_STR
Definition: plibc.h:632
#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:1180
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Definition: fs_api.h:1092
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 632 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().

636 {
637  char *basename;
638  char *ret;
639 
640  if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
641  return NULL; /* persistence not requested */
642  if (GNUNET_OK !=
643  GNUNET_CONFIGURATION_get_value_filename (h->cfg, "fs", "STATE_DIR",
644  &basename))
645  return NULL;
646  GNUNET_asprintf (&ret, "%s%s%s%s%s%s%s.dir%s%s", basename, DIR_SEPARATOR_STR,
648  uni, DIR_SEPARATOR_STR, ent);
649  GNUNET_free (basename);
650  return ret;
651 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static int ret
Final status code.
Definition: gnunet-arm.c:89
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
char * client_name
Name of our client.
Definition: fs_api.h:1097
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 DIR_SEPARATOR_STR
Definition: plibc.h:632
#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:1180
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Definition: fs_api.h:1092
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 663 of file fs_api.c.

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

Referenced by deserialize_file_information(), and deserialize_search_result().

666 {
667  char *fn;
668  struct GNUNET_BIO_ReadHandle *ret;
669 
670  fn = get_serialization_file_name (h, ext, ent);
671  if (NULL == fn)
672  return NULL;
673  ret = GNUNET_BIO_read_open (fn);
674  GNUNET_free (fn);
675  return ret;
676 }
static int ret
Final status code.
Definition: gnunet-arm.c:89
struct GNUNET_BIO_ReadHandle * GNUNET_BIO_read_open(const char *fn)
Open a file for reading.
Definition: bio.c:94
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:599
Handle for buffered reading.
Definition: bio.c:53
#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 688 of file fs_api.c.

References fn, get_serialization_file_name(), GNUNET_BIO_write_open(), 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_().

691 {
692  char *fn;
693  struct GNUNET_BIO_WriteHandle *ret;
694 
695  fn = get_serialization_file_name (h, ext, ent);
696  if (NULL == fn)
697  return NULL;
698  ret = GNUNET_BIO_write_open (fn);
699  GNUNET_break (NULL != ret);
700  GNUNET_free (fn);
701  return ret;
702 }
static int ret
Final status code.
Definition: gnunet-arm.c:89
#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:399
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:599
struct GNUNET_BIO_WriteHandle * GNUNET_BIO_write_open(const char *fn)
Open a file for writing.
Definition: bio.c:430
#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 715 of file fs_api.c.

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

Referenced by GNUNET_FS_search_result_sync_().

717 {
718  char *fn;
719  struct GNUNET_BIO_WriteHandle *ret;
720 
721  fn = get_serialization_file_name_in_dir (h, ext, uni, ent);
722  if (NULL == fn)
723  return NULL;
724  ret = GNUNET_BIO_write_open (fn);
725  GNUNET_free (fn);
726  return ret;
727 }
static int ret
Final status code.
Definition: gnunet-arm.c:89
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:632
Handle for buffered writing.
Definition: bio.c:399
struct GNUNET_BIO_WriteHandle * GNUNET_BIO_write_open(const char *fn)
Open a file for writing.
Definition: bio.c:430
#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 738 of file fs_api.c.

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

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

741 {
742  char *filename;
743 
744  if ((NULL == ent) || (0 == strlen (ent)))
745  {
746  GNUNET_break (0);
747  return;
748  }
749  filename = get_serialization_file_name (h, ext, ent);
750  if (NULL != filename)
751  {
752  if ( (0 != UNLINK (filename)) &&
753  (ENOENT != errno) )
755  GNUNET_free (filename);
756  }
757 }
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define UNLINK(f)
Definition: plibc.h:666
#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:599
#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 769 of file fs_api.c.

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

Referenced by deserialize_search_result(), and GNUNET_FS_search_result_sync_().

772 {
773  char *filename;
774 
775  if ((NULL == ent) || (0 == strlen (ent)))
776  {
777  GNUNET_break (0);
778  return;
779  }
780  filename = get_serialization_file_name_in_dir (h, ext, uni, ent);
781  if (NULL == filename)
782  return;
783  if (0 != UNLINK (filename))
785  GNUNET_free (filename);
786 }
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define UNLINK(f)
Definition: plibc.h:666
#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:632
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 797 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().

800 {
801  char *dn;
802 
803  if (NULL == uni)
804  return;
805  dn = get_serialization_file_name_in_dir (h, ext, uni, "");
806  if (NULL == dn)
807  return;
811  GNUNET_free (dn);
812 }
int GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition: disk.c:628
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#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:632
int GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
Definition: disk.c:1359
#define GNUNET_YES
Definition: gnunet_common.h:80
#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 830 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_().

832 {
833  struct GNUNET_TIME_Relative dur;
834 
835  dur = GNUNET_TIME_absolute_get_duration (timestamp);
836  return GNUNET_BIO_write_int64 (wh, dur.rel_value_us);
837 }
int GNUNET_BIO_write_int64(struct GNUNET_BIO_WriteHandle *h, int64_t i)
Write an (u)int64_t.
Definition: bio.c:623
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
Definition: time.c:373
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 855 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().

857 {
858  struct GNUNET_TIME_Relative dur;
859 
860  if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dur.rel_value_us))
861  return GNUNET_SYSERR;
863  return GNUNET_OK;
864 }
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:419
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_BIO_read_int64(h, i)
Read an (u)int64_t.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
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 1111 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, ret, and UNLINK.

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

1113 {
1115  struct GNUNET_BIO_ReadHandle *rh;
1116  char *emsg;
1117  char *fn;
1118 
1120  if (NULL == rh)
1121  return NULL;
1122  ret = deserialize_fi_node (h, filename, rh);
1123  if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
1124  {
1126  _("Failed to resume publishing information `%s': %s\n"),
1127  filename, emsg);
1128  GNUNET_free (emsg);
1129  }
1130  if (NULL == ret)
1131  {
1133  if (NULL != fn)
1134  {
1135  if (0 != UNLINK (fn))
1137  GNUNET_free (fn);
1138  }
1139  }
1140  return ret;
1141 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
Information for a file or directory that is about to be published.
Definition: fs_api.h:231
static int ret
Final status code.
Definition: gnunet-arm.c:89
int GNUNET_BIO_read_close(struct GNUNET_BIO_ReadHandle *h, char **emsg)
Close an open file.
Definition: bio.c:119
#define UNLINK(f)
Definition: plibc.h:666
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
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:892
#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:663
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:599
#define GNUNET_log(kind,...)
char * emsg
Error message, NULL if there were no errors.
Definition: bio.c:63
Handle for buffered reading.
Definition: bio.c:53
#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 892 of file fs_api.c.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_FS_BlockOptions::anonymity_level, GNUNET_FS_FileInformation::bo, GNUNET_FS_FileInformation::chk_uri, cleanup(), GNUNET_FS_BlockOptions::content_priority, GNUNET_FS_FileInformation::contents_completed, GNUNET_FS_FileInformation::contents_size, 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_free_non_null, 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().

895 {
897  struct GNUNET_FS_FileInformation *nxt;
898  char b;
899  char *ksks;
900  char *chks;
901  char *skss;
902  char *filename;
903  uint32_t dsize;
904 
905  if (GNUNET_OK != GNUNET_BIO_read (rh, "status flag", &b, sizeof (b)))
906  {
907  GNUNET_break (0);
908  return NULL;
909  }
910  ret = GNUNET_new (struct GNUNET_FS_FileInformation);
911  ret->h = h;
912  ksks = NULL;
913  chks = NULL;
914  skss = NULL;
915  filename = NULL;
916  if ((GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "metadata", &ret->meta)) ||
917  (GNUNET_OK != GNUNET_BIO_read_string (rh, "ksk-uri", &ksks, 32 * 1024)) ||
918  ( (NULL != ksks) &&
919  ( (NULL == (ret->keywords = GNUNET_FS_uri_parse (ksks, NULL))) ||
920  (GNUNET_YES != GNUNET_FS_uri_test_ksk (ret->keywords)) ) ) ||
921  (GNUNET_OK != GNUNET_BIO_read_string (rh, "chk-uri", &chks, 1024)) ||
922  ( (NULL != chks) &&
923  ( (NULL == (ret->chk_uri = GNUNET_FS_uri_parse (chks, NULL))) ||
924  (GNUNET_YES != GNUNET_FS_uri_test_chk (ret->chk_uri))) ) ||
925  (GNUNET_OK != GNUNET_BIO_read_string (rh, "sks-uri", &skss, 1024)) ||
926  ( (NULL != skss) &&
927  ( (NULL == (ret->sks_uri = GNUNET_FS_uri_parse (skss, NULL))) ||
928  (GNUNET_YES != GNUNET_FS_uri_test_sks (ret->sks_uri))) ) ||
929  (GNUNET_OK != read_start_time (rh, &ret->start_time)) ||
930  (GNUNET_OK != GNUNET_BIO_read_string (rh, "emsg", &ret->emsg, 16 * 1024))
931  || (GNUNET_OK !=
932  GNUNET_BIO_read_string (rh, "fn", &ret->filename, 16 * 1024)) ||
933  (GNUNET_OK !=
938  {
939  GNUNET_break (0);
940  goto cleanup;
941  }
942  switch (b)
943  {
944  case 0: /* file-insert */
945  if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size))
946  {
947  GNUNET_break (0);
948  goto cleanup;
949  }
950  ret->is_directory = GNUNET_NO;
951  ret->data.file.do_index = GNUNET_NO;
952  ret->data.file.have_hash = GNUNET_NO;
953  ret->data.file.index_start_confirmed = GNUNET_NO;
954  if (GNUNET_NO == ret->is_published)
955  {
956  if (NULL == ret->filename)
957  {
958  ret->data.file.reader = &GNUNET_FS_data_reader_copy_;
959  ret->data.file.reader_cls =
960  GNUNET_malloc_large (ret->data.file.file_size);
961  if (ret->data.file.reader_cls == NULL)
962  goto cleanup;
963  if (GNUNET_OK !=
964  GNUNET_BIO_read (rh, "file-data", ret->data.file.reader_cls,
965  ret->data.file.file_size))
966  {
967  GNUNET_break (0);
968  goto cleanup;
969  }
970  }
971  else
972  {
973  ret->data.file.reader = &GNUNET_FS_data_reader_file_;
974  ret->data.file.reader_cls =
976  }
977  }
978  break;
979  case 1: /* file-index, no hash */
980  if (NULL == ret->filename)
981  {
982  GNUNET_break (0);
983  goto cleanup;
984  }
985  if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size))
986  {
987  GNUNET_break (0);
988  goto cleanup;
989  }
990  ret->is_directory = GNUNET_NO;
991  ret->data.file.do_index = GNUNET_YES;
992  ret->data.file.have_hash = GNUNET_NO;
993  ret->data.file.index_start_confirmed = GNUNET_NO;
994  ret->data.file.reader = &GNUNET_FS_data_reader_file_;
995  ret->data.file.reader_cls =
997  break;
998  case 2: /* file-index-with-hash */
999  if (NULL == ret->filename)
1000  {
1001  GNUNET_break (0);
1002  goto cleanup;
1003  }
1004  if ((GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) ||
1005  (GNUNET_OK !=
1006  GNUNET_BIO_read (rh, "fileid", &ret->data.file.file_id,
1007  sizeof (struct GNUNET_HashCode))))
1008  {
1009  GNUNET_break (0);
1010  goto cleanup;
1011  }
1012  ret->is_directory = GNUNET_NO;
1013  ret->data.file.do_index = GNUNET_YES;
1014  ret->data.file.have_hash = GNUNET_YES;
1015  ret->data.file.index_start_confirmed = GNUNET_NO;
1016  ret->data.file.reader = &GNUNET_FS_data_reader_file_;
1017  ret->data.file.reader_cls =
1019  break;
1020  case 3: /* file-index-with-hash-confirmed */
1021  if (NULL == ret->filename)
1022  {
1023  GNUNET_break (0);
1024  goto cleanup;
1025  }
1026  if ((GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) ||
1027  (GNUNET_OK !=
1028  GNUNET_BIO_read (rh, "fileid", &ret->data.file.file_id,
1029  sizeof (struct GNUNET_HashCode))))
1030  {
1031  GNUNET_break (0);
1032  goto cleanup;
1033  }
1034  ret->is_directory = GNUNET_NO;
1035  ret->data.file.do_index = GNUNET_YES;
1036  ret->data.file.have_hash = GNUNET_YES;
1037  ret->data.file.index_start_confirmed = GNUNET_YES;
1038  ret->data.file.reader = &GNUNET_FS_data_reader_file_;
1039  ret->data.file.reader_cls =
1041  break;
1042  case 4: /* directory */
1043  ret->is_directory = GNUNET_YES;
1044  if ((GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dsize)) ||
1047  (NULL == (ret->data.dir.dir_data = GNUNET_malloc_large (dsize))) ||
1048  (GNUNET_OK !=
1049  GNUNET_BIO_read (rh, "dir-data", ret->data.dir.dir_data, dsize)) ||
1050  (GNUNET_OK !=
1051  GNUNET_BIO_read_string (rh, "ent-filename", &filename, 16 * 1024)))
1052  {
1053  GNUNET_break (0);
1054  goto cleanup;
1055  }
1056  ret->data.dir.dir_size = (uint32_t) dsize;
1057  if (NULL != filename)
1058  {
1059  ret->data.dir.entries = deserialize_file_information (h, filename);
1060  GNUNET_free (filename);
1061  filename = NULL;
1062  nxt = ret->data.dir.entries;
1063  while (NULL != nxt)
1064  {
1065  nxt->dir = ret;
1066  nxt = nxt->next;
1067  }
1068  }
1069  break;
1070  default:
1071  GNUNET_break (0);
1072  goto cleanup;
1073  }
1074  ret->serialization = GNUNET_strdup (fn);
1075  if (GNUNET_OK !=
1076  GNUNET_BIO_read_string (rh, "nxt-filename", &filename, 16 * 1024))
1077  {
1078  GNUNET_break (0);
1079  goto cleanup;
1080  }
1081  if (NULL != filename)
1082  {
1083  ret->next = deserialize_file_information (h, filename);
1084  GNUNET_free (filename);
1085  filename = NULL;
1086  }
1087  GNUNET_free_non_null (ksks);
1088  GNUNET_free_non_null (skss);
1089  GNUNET_free_non_null (chks);
1090  return ret;
1091 cleanup:
1092  GNUNET_free_non_null (ksks);
1093  GNUNET_free_non_null (chks);
1094  GNUNET_free_non_null (skss);
1095  GNUNET_free_non_null (filename);
1096  GNUNET_FS_file_information_destroy (ret, NULL, NULL);
1097  return NULL;
1098 }
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:371
int GNUNET_FS_uri_test_ksk(const struct GNUNET_FS_Uri *uri)
Is this a keyword URI?
Definition: fs_uri.c:1323
struct GNUNET_FS_FileInformation * dir
If this is a file in a directory, "dir" refers to the directory; otherwise NULL.
Definition: fs_api.h:243
struct GNUNET_CONTAINER_MetaData * meta
Metadata to use for the file.
Definition: fs_api.h:258
struct GNUNET_FS_FileInformation::@19::@20 file
Data for a file.
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:635
char * emsg
Error message (non-NULL if this operation failed).
Definition: fs_api.h:302
char * serialization
Under what filename is this struct serialized (for operational persistence).
Definition: fs_api.h:292
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:569
struct GNUNET_TIME_Absolute start_time
At what time did we start this upload?
Definition: fs_api.h:285
char * filename
Name of the file or directory (must be an absolute path).
Definition: fs_api.h:307
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#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:464
Information for a file or directory that is about to be published.
Definition: fs_api.h:231
int GNUNET_FS_uri_test_sks(const struct GNUNET_FS_Uri *uri)
Is this a namespace URI?
Definition: fs_uri.c:1270
struct GNUNET_FS_Handle * h
Handle to the master context.
Definition: fs_api.h:248
static int ret
Final status code.
Definition: gnunet-arm.c:89
#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:383
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:94
#define GNUNET_BIO_read_int64(h, i)
Read an (u)int64_t.
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 the contents of a binary file into a buffer.
Definition: bio.c:145
static char * fn
Filename of the unique file.
int is_directory
Is this struct for a file or directory?
Definition: fs_api.h:402
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:269
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 from a file.
Definition: bio.c:237
int GNUNET_FS_uri_test_chk(const struct GNUNET_FS_Uri *uri)
Is this a file (or directory) URI?
Definition: fs_uri.c:1345
uint64_t contents_size
Sum of all of the sizes of all of the files in the directory.
Definition: fs_api.h:393
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:1111
#define GNUNET_BIO_read_int32(h, i)
Read an (u)int32_t.
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:533
struct GNUNET_FS_FileInformation * next
Files in a directory are kept as a linked list.
Definition: fs_api.h:237
struct GNUNET_FS_BlockOptions bo
Block options for the file.
Definition: fs_api.h:280
uint32_t replication_level
How often should we try to migrate the block to other peers? Only used if "CONTENT_PUSHING" is set to...
union GNUNET_FS_FileInformation::@19 data
Data describing either the file or the directory.
static int read_start_time(struct GNUNET_BIO_ReadHandle *rh, struct GNUNET_TIME_Absolute *timestamp)
Deserialize a start-time.
Definition: fs_api.c:855
struct GNUNET_FS_Uri * keywords
Keywords to use for KBlocks.
Definition: fs_api.h:263
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 metadata container from a file.
Definition: bio.c:286
uint64_t contents_completed
How much of the directory have we published (relative to contents_size).
Definition: fs_api.h:388
#define GNUNET_YES
Definition: gnunet_common.h:80
int is_published
Are we done publishing this file?
Definition: fs_api.h:407
size_t dir_size
Size of the directory itself (in bytes); 0 if the size has not yet been calculated.
Definition: fs_api.h:377
struct GNUNET_FS_Uri * sks_uri
SKS URI for this file or directory.
Definition: fs_api.h:275
#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 1153 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().

1154 {
1155  const char *end;
1156  const char *nxt;
1157 
1158  end = NULL;
1159  nxt = fullname;
1160  /* FIXME: we could do this faster since we know
1161  * the length of 'end'... */
1162  while ('\0' != *nxt)
1163  {
1164  if (DIR_SEPARATOR == *nxt)
1165  end = nxt + 1;
1166  nxt++;
1167  }
1168  if ((NULL == end) || (0 == strlen (end)))
1169  {
1170  GNUNET_break (0);
1171  return NULL;
1172  }
1173  GNUNET_break (6 == strlen (end));
1174  return GNUNET_strdup (end);
1175 }
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: plibc.h:631
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 1187 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_().

1189 {
1190  char *fn;
1191  char *dn;
1192  char *ret;
1193 
1194  if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
1195  return NULL; /* persistence not requested */
1196  dn = get_serialization_file_name (h, ext, "");
1197  if (NULL == dn)
1198  return NULL;
1200  {
1201  GNUNET_free (dn);
1202  return NULL;
1203  }
1204  fn = GNUNET_DISK_mktemp (dn);
1205  GNUNET_free (dn);
1206  if (NULL == fn)
1207  return NULL; /* epic fail */
1208  ret = get_serialization_short_name (fn);
1209  GNUNET_free (fn);
1210  return ret;
1211 }
int GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:833
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static int ret
Final status code.
Definition: gnunet-arm.c:89
char * GNUNET_DISK_mktemp(const char *t)
Create an (empty) temporary file on disk.
Definition: disk.c:593
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:599
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:1153
#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:1180
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 1224 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_().

1227 {
1228  char *fn;
1229  char *dn;
1230  char *ret;
1231 
1232  if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
1233  return NULL; /* persistence not requested */
1234  dn = get_serialization_file_name_in_dir (h, ext, uni, "");
1235  if (NULL == dn)
1236  return NULL;
1238  {
1239  GNUNET_free (dn);
1240  return NULL;
1241  }
1242  fn = GNUNET_DISK_mktemp (dn);
1243  GNUNET_free (dn);
1244  if (NULL == fn)
1245  return NULL; /* epic fail */
1246  ret = get_serialization_short_name (fn);
1247  GNUNET_free (fn);
1248  return ret;
1249 }
int GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:833
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static int ret
Final status code.
Definition: gnunet-arm.c:89
char * GNUNET_DISK_mktemp(const char *t)
Create an (empty) temporary file on disk.
Definition: disk.c:593
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:632
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:1153
#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:1180
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 1260 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_().

1262 {
1263  char buf[32 * 1024];
1264  uint64_t off;
1265  size_t ret;
1266  size_t left;
1267  char *emsg;
1268 
1269  emsg = NULL;
1270  off = 0;
1271  while (off < fi->data.file.file_size)
1272  {
1273  left = GNUNET_MIN (sizeof (buf), fi->data.file.file_size - off);
1274  ret =
1275  fi->data.file.reader (fi->data.file.reader_cls, off, left, buf, &emsg);
1276  if (0 == ret)
1277  {
1278  GNUNET_free (emsg);
1279  return GNUNET_SYSERR;
1280  }
1281  if (GNUNET_OK != GNUNET_BIO_write (wh, buf, ret))
1282  return GNUNET_SYSERR;
1283  off += ret;
1284  }
1285  return GNUNET_OK;
1286 }
struct GNUNET_FS_FileInformation::@19::@20 file
Data for a file.
char * emsg
Error message (non-NULL if this operation failed).
Definition: fs_api.h:302
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_MIN(a, b)
Definition: gnunet_common.h:83
static char buf[2048]
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
union GNUNET_FS_FileInformation::@19 data
Data describing either the file or the directory.
int GNUNET_BIO_write(struct GNUNET_BIO_WriteHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: bio.c:505
uint32_t data
The data value.
#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 1296 of file fs_api.c.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_FS_BlockOptions::anonymity_level, GNUNET_FS_FileInformation::bo, GNUNET_FS_FileInformation::chk_uri, cleanup(), GNUNET_FS_BlockOptions::content_priority, GNUNET_FS_FileInformation::contents_completed, GNUNET_FS_FileInformation::contents_size, copy_from_reader(), GNUNET_FS_FileInformation::data, GNUNET_FS_FileInformation::dir, GNUNET_FS_FileInformation::dir_data, GNUNET_FS_FileInformation::dir_size, GNUNET_FS_FileInformation::emsg, entries, 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_int32(), GNUNET_BIO_write_int64(), GNUNET_BIO_write_meta_data(), GNUNET_BIO_write_string(), GNUNET_break, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_free_non_null, 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, UNLINK, 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().

1297 {
1298  char *fn;
1299  struct GNUNET_BIO_WriteHandle *wh;
1300  char b;
1301  char *ksks;
1302  char *chks;
1303  char *skss;
1304 
1305  if (NULL == fi->serialization)
1306  fi->serialization =
1308  if (NULL == fi->serialization)
1309  return;
1311  fi->serialization);
1312  if (NULL == wh)
1313  {
1314  GNUNET_free (fi->serialization);
1315  fi->serialization = NULL;
1316  return;
1317  }
1318  if (GNUNET_YES == fi->is_directory)
1319  b = 4;
1320  else if (GNUNET_YES == fi->data.file.index_start_confirmed)
1321  b = 3;
1322  else if (GNUNET_YES == fi->data.file.have_hash)
1323  b = 2;
1324  else if (GNUNET_YES == fi->data.file.do_index)
1325  b = 1;
1326  else
1327  b = 0;
1328  if (NULL != fi->keywords)
1329  ksks = GNUNET_FS_uri_to_string (fi->keywords);
1330  else
1331  ksks = NULL;
1332  if (NULL != fi->chk_uri)
1333  chks = GNUNET_FS_uri_to_string (fi->chk_uri);
1334  else
1335  chks = NULL;
1336  if (NULL != fi->sks_uri)
1337  skss = GNUNET_FS_uri_to_string (fi->sks_uri);
1338  else
1339  skss = NULL;
1340  if ((GNUNET_OK != GNUNET_BIO_write (wh, &b, sizeof (b))) ||
1341  (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, fi->meta)) ||
1342  (GNUNET_OK != GNUNET_BIO_write_string (wh, ksks)) ||
1343  (GNUNET_OK != GNUNET_BIO_write_string (wh, chks)) ||
1344  (GNUNET_OK != GNUNET_BIO_write_string (wh, skss)) ||
1345  (GNUNET_OK != write_start_time (wh, fi->start_time)) ||
1346  (GNUNET_OK != GNUNET_BIO_write_string (wh, fi->emsg)) ||
1347  (GNUNET_OK != GNUNET_BIO_write_string (wh, fi->filename)) ||
1348  (GNUNET_OK !=
1353  {
1354  GNUNET_break (0);
1355  goto cleanup;
1356  }
1357  GNUNET_free_non_null (chks);
1358  chks = NULL;
1359  GNUNET_free_non_null (ksks);
1360  ksks = NULL;
1361  GNUNET_free_non_null (skss);
1362  skss = NULL;
1363 
1364  switch (b)
1365  {
1366  case 0: /* file-insert */
1367  if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size))
1368  {
1369  GNUNET_break (0);
1370  goto cleanup;
1371  }
1372  if ((GNUNET_NO == fi->is_published) && (NULL == fi->filename))
1373  if (GNUNET_OK != copy_from_reader (wh, fi))
1374  {
1375  GNUNET_break (0);
1376  goto cleanup;
1377  }
1378  break;
1379  case 1: /* file-index, no hash */
1380  if (NULL == fi->filename)
1381  {
1382  GNUNET_break (0);
1383  goto cleanup;
1384  }
1385  if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size))
1386  {
1387  GNUNET_break (0);
1388  goto cleanup;
1389  }
1390  break;
1391  case 2: /* file-index-with-hash */
1392  case 3: /* file-index-with-hash-confirmed */
1393  if (NULL == fi->filename)
1394  {
1395  GNUNET_break (0);
1396  goto cleanup;
1397  }
1398  if ((GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) ||
1399  (GNUNET_OK !=
1400  GNUNET_BIO_write (wh, &fi->data.file.file_id,
1401  sizeof (struct GNUNET_HashCode))))
1402  {
1403  GNUNET_break (0);
1404  goto cleanup;
1405  }
1406  break;
1407  case 4: /* directory */
1408  if ( (NULL != fi->data.dir.entries) &&
1409  (NULL == fi->data.dir.entries->serialization) )
1411  if ((GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->data.dir.dir_size)) ||
1414  (GNUNET_OK !=
1415  GNUNET_BIO_write (wh, fi->data.dir.dir_data,
1416  (uint32_t) fi->data.dir.dir_size)) ||
1417  (GNUNET_OK !=
1419  (fi->data.dir.entries ==
1420  NULL) ? NULL : fi->data.dir.
1421  entries->serialization)))
1422  {
1423  GNUNET_break (0);
1424  goto cleanup;
1425  }
1426  break;
1427  default:
1428  GNUNET_assert (0);
1429  goto cleanup;
1430  }
1431  if ( (NULL != fi->next) &&
1432  (NULL == fi->next->serialization) )
1434  if (GNUNET_OK !=
1436  (fi->next !=
1437  NULL) ? fi->next->serialization : NULL))
1438  {
1439  GNUNET_break (0);
1440  goto cleanup;
1441  }
1442  if (GNUNET_OK != GNUNET_BIO_write_close (wh))
1443  {
1444  wh = NULL;
1445  GNUNET_break (0);
1446  goto cleanup;
1447  }
1448  return; /* done! */
1449 cleanup:
1450  if (NULL != wh)
1451  (void) GNUNET_BIO_write_close (wh);
1452  GNUNET_free_non_null (chks);
1453  GNUNET_free_non_null (ksks);
1454  GNUNET_free_non_null (skss);
1456  fi->serialization);
1457  if (NULL != fn)
1458  {
1459  if (0 != UNLINK (fn))
1461  GNUNET_free (fn);
1462  }
1463  GNUNET_free (fi->serialization);
1464  fi->serialization = NULL;
1465 }
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:371
int GNUNET_BIO_write_meta_data(struct GNUNET_BIO_WriteHandle *h, const struct GNUNET_CONTAINER_MetaData *m)
Write metadata container to a file.
Definition: bio.c:569
struct GNUNET_FS_FileInformation * dir
If this is a file in a directory, "dir" refers to the directory; otherwise NULL.
Definition: fs_api.h:243
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:1296
struct GNUNET_CONTAINER_MetaData * meta
Metadata to use for the file.
Definition: fs_api.h:258
struct GNUNET_FS_FileInformation::@19::@20 file
Data for a file.
char * emsg
Error message (non-NULL if this operation failed).
Definition: fs_api.h:302
char * serialization
Under what filename is this struct serialized (for operational persistence).
Definition: fs_api.h:292
int GNUNET_BIO_write_string(struct GNUNET_BIO_WriteHandle *h, const char *s)
Write a string to a file.
Definition: bio.c:547
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
int GNUNET_BIO_write_int64(struct GNUNET_BIO_WriteHandle *h, int64_t i)
Write an (u)int64_t.
Definition: bio.c:623
struct GNUNET_TIME_Absolute start_time
At what time did we start this upload?
Definition: fs_api.h:285
char * filename
Name of the file or directory (must be an absolute path).
Definition: fs_api.h:307
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:688
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
struct GNUNET_FS_Handle * h
Handle to the master context.
Definition: fs_api.h:248
void * dir_data
Pointer to the data for the directory (or NULL if not available).
Definition: fs_api.h:383
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...
#define UNLINK(f)
Definition: plibc.h:666
char * GNUNET_FS_uri_to_string(const struct GNUNET_FS_Uri *uri)
Convert a URI to a UTF-8 String.
Definition: fs_uri.c:1988
uint32_t anonymity_level
At which anonymity level should the block be shared? (0: no anonymity, 1: normal GAP, >1: with cover traffic).
#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.
struct ListEntry * entries
List of peers in the list.
int is_directory
Is this struct for a file or directory?
Definition: fs_api.h:402
static void cleanup(void *cls)
Function scheduled as very last function, cleans up after us.
Handle for buffered writing.
Definition: bio.c:399
struct GNUNET_FS_Uri * chk_uri
CHK for this file or directory.
Definition: fs_api.h:269
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:393
#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:599
static int write_start_time(struct GNUNET_BIO_WriteHandle *wh, struct GNUNET_TIME_Absolute timestamp)
Serialize a start-time.
Definition: fs_api.c:830
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:237
int GNUNET_BIO_write_close(struct GNUNET_BIO_WriteHandle *h)
Close an open file for writing.
Definition: bio.c:457
struct GNUNET_FS_BlockOptions bo
Block options for the file.
Definition: fs_api.h:280
uint32_t replication_level
How often should we try to migrate the block to other peers? Only used if "CONTENT_PUSHING" is set to...
union GNUNET_FS_FileInformation::@19 data
Data describing either the file or the directory.
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:1187
struct GNUNET_FS_Uri * keywords
Keywords to use for KBlocks.
Definition: fs_api.h:263
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_write_int32(struct GNUNET_BIO_WriteHandle *h, int32_t i)
Write an (u)int32_t.
Definition: bio.c:605
uint64_t contents_completed
How much of the directory have we published (relative to contents_size).
Definition: fs_api.h:388
#define GNUNET_YES
Definition: gnunet_common.h:80
int GNUNET_BIO_write(struct GNUNET_BIO_WriteHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: bio.c:505
int is_published
Are we done publishing this file?
Definition: fs_api.h:407
size_t dir_size
Size of the directory itself (in bytes); 0 if the size has not yet been calculated.
Definition: fs_api.h:377
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:1260
struct GNUNET_FS_Uri * sks_uri
SKS URI for this file or directory.
Definition: fs_api.h:275
#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 1478 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().

1480 {
1481  struct GNUNET_FS_FileInformation *r;
1482 
1483  while (NULL != pos)
1484  {
1485  if (0 == strcmp (srch, pos->serialization))
1486  return pos;
1487  if ( (GNUNET_YES == pos->is_directory) &&
1488  (NULL != (r = find_file_position (pos->data.dir.entries, srch))) )
1489  return r;
1490  pos = pos->next;
1491  }
1492  return NULL;
1493 }
struct GNUNET_FS_FileInformation * entries
Linked list of entries in the directory.
Definition: fs_api.h:371
struct GNUNET_FS_FileInformation * dir
If this is a file in a directory, "dir" refers to the directory; otherwise NULL.
Definition: fs_api.h:243
char * serialization
Under what filename is this struct serialized (for operational persistence).
Definition: fs_api.h:292
Information for a file or directory that is about to be published.
Definition: fs_api.h:231
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:1478
int is_directory
Is this struct for a file or directory?
Definition: fs_api.h:402
struct GNUNET_FS_FileInformation * next
Files in a directory are kept as a linked list.
Definition: fs_api.h:237
union GNUNET_FS_FileInformation::@19 data
Data describing either the file or the directory.
#define GNUNET_YES
Definition: gnunet_common.h:80
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 1511 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().

1519 {
1520  struct GNUNET_FS_PublishContext *pc = cls;
1521  struct GNUNET_FS_ProgressInfo pi;
1522 
1523  if (GNUNET_YES == pc->skip_next_fi_callback)
1524  {
1526  return GNUNET_OK;
1527  }
1529  pi.value.publish.specifics.resume.message = fi->emsg;
1530  pi.value.publish.specifics.resume.chk_uri = fi->chk_uri;
1531  *client_info = GNUNET_FS_publish_make_status_ (&pi, pc, fi, 0);
1533  {
1534  /* process entries in directory */
1537  }
1538  return GNUNET_OK;
1539 }
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:1511
char * emsg
Error message (non-NULL if this operation failed).
Definition: fs_api.h:302
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
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:269
Handle for controlling a publication process.
Definition: fs_api.h:1198
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.
#define GNUNET_YES
Definition: gnunet_common.h:80
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:1318
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 1551 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_int32, GNUNET_BIO_read_open(), GNUNET_BIO_read_string(), GNUNET_break, GNUNET_DATASTORE_connect(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_free_non_null, 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, UNLINK, and GNUNET_FS_PublishContext::upload_task.

Referenced by GNUNET_FS_start().

1553 {
1554  struct GNUNET_FS_Handle *h = cls;
1555  struct GNUNET_BIO_ReadHandle *rh;
1556  struct GNUNET_FS_PublishContext *pc;
1557  int32_t options;
1558  int32_t all_done;
1559  int32_t have_ns;
1560  char *fi_root;
1562  char *fi_pos;
1563  char *emsg;
1564 
1565  pc = GNUNET_new (struct GNUNET_FS_PublishContext);
1566  pc->h = h;
1568  fi_root = NULL;
1569  fi_pos = NULL;
1571  if (NULL == rh)
1572  {
1573  GNUNET_break (0);
1574  goto cleanup;
1575  }
1576  if ((GNUNET_OK != GNUNET_BIO_read_string (rh, "publish-nid", &pc->nid, 1024))
1577  || (GNUNET_OK !=
1578  GNUNET_BIO_read_string (rh, "publish-nuid", &pc->nuid, 1024)) ||
1579  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &options)) ||
1580  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &all_done)) ||
1581  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &have_ns)) ||
1582  (GNUNET_OK !=
1583  GNUNET_BIO_read_string (rh, "publish-firoot", &fi_root, 128)) ||
1584  (GNUNET_OK != GNUNET_BIO_read_string (rh, "publish-fipos", &fi_pos, 128))
1585  || ( (GNUNET_YES == have_ns) &&
1586  (GNUNET_OK != GNUNET_BIO_read (rh, "publish-ns", &ns, sizeof (ns)))) )
1587  {
1588  GNUNET_break (0);
1589  goto cleanup;
1590  }
1591  pc->options = options;
1592  pc->all_done = all_done;
1593  if (NULL == fi_root)
1594  {
1595  GNUNET_break (0);
1596  goto cleanup;
1597  }
1598  pc->fi = deserialize_file_information (h, fi_root);
1599  if (NULL == pc->fi)
1600  {
1601  GNUNET_break (0);
1602  goto cleanup;
1603  }
1604  if (GNUNET_YES == have_ns)
1605  {
1607  *pc->ns = ns;
1608  }
1609  if ((0 == (pc->options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) &&
1610  (GNUNET_YES != pc->all_done))
1611  {
1612  pc->dsh = GNUNET_DATASTORE_connect (h->cfg);
1613  if (NULL == pc->dsh)
1614  goto cleanup;
1615  }
1616  if (NULL != fi_pos)
1617  {
1618  pc->fi_pos = find_file_position (pc->fi, fi_pos);
1619  GNUNET_free (fi_pos);
1620  fi_pos = NULL;
1621  if (NULL == pc->fi_pos)
1622  {
1623  /* failed to find position for resuming, outch! Will start from root! */
1624  GNUNET_break (0);
1625  if (GNUNET_YES != pc->all_done)
1626  pc->fi_pos = pc->fi;
1627  }
1628  }
1629  GNUNET_free (fi_root);
1630  fi_root = NULL;
1631  /* generate RESUME event(s) */
1633 
1634  /* re-start publishing (if needed)... */
1635  if (GNUNET_YES != pc->all_done)
1636  {
1637  GNUNET_assert (NULL == pc->upload_task);
1638  pc->upload_task =
1642  }
1643  if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
1644  {
1646  _("Failure while resuming publishing operation `%s': %s\n"),
1647  filename, emsg);
1648  GNUNET_free (emsg);
1649  }
1650  pc->top = GNUNET_FS_make_top (h,
1652  pc);
1653  return GNUNET_OK;
1654 cleanup:
1655  GNUNET_free_non_null (pc->nid);
1656  GNUNET_free_non_null (pc->nuid);
1657  GNUNET_free_non_null (fi_root);
1658  GNUNET_free_non_null (fi_pos);
1659  if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)))
1660  {
1662  _("Failed to resume publishing operation `%s': %s\n"), filename,
1663  emsg);
1664  GNUNET_free (emsg);
1665  }
1666  if (NULL != pc->fi)
1667  GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL);
1668  if (0 != UNLINK (filename))
1670  GNUNET_free (pc->serialization);
1671  GNUNET_free (pc);
1672  return GNUNET_OK;
1673 }
char * nid
ID of the content in the namespace, NULL if we have no namespace.
Definition: fs_api.h:1223
struct GNUNET_SCHEDULER_Task * upload_task
ID of the task performing the upload.
Definition: fs_api.h:1278
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:1511
Master context for most FS operations.
Definition: fs_api.h:1087
#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:1294
struct GNUNET_DATASTORE_Handle * dsh
Connection to the datastore service.
Definition: fs_api.h:1255
struct GNUNET_FS_Handle * h
Handle to the global fs context.
Definition: fs_api.h:1203
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#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:1234
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:1478
int GNUNET_BIO_read_close(struct GNUNET_BIO_ReadHandle *h, char **emsg)
Close an open file.
Definition: bio.c:119
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
#define UNLINK(f)
Definition: plibc.h:666
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
struct GNUNET_BIO_ReadHandle * GNUNET_BIO_read_open(const char *fn)
Open a file for reading.
Definition: bio.c:94
int GNUNET_BIO_read(struct GNUNET_BIO_ReadHandle *h, const char *what, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: bio.c:145
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:1200
#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:1228
static char * filename
void GNUNET_FS_publish_main_(void *cls)
Main function that performs the upload.
Definition: fs_publish.c:1053
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:1245
Handle for controlling a publication process.
Definition: fs_api.h:1198
int GNUNET_BIO_read_string(struct GNUNET_BIO_ReadHandle *h, const char *what, char **result, size_t max_length)
Read 0-terminated string from a file.
Definition: bio.c:237
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:1111
#define GNUNET_BIO_read_int32(h, i)
Read an (u)int32_t.
int all_done
Set to GNUNET_YES if all processing has completed.
Definition: fs_api.h:1311
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:1153
static struct GNUNET_NAMESTORE_Handle * ns
Handle to the namestore.
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:393
struct TopLevelActivity * top
Our top-level activity entry (if we are top-level, otherwise NULL).
Definition: fs_api.h:1208
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:1213
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:1343
struct GNUNET_CRYPTO_EcdsaPrivateKey * ns
Namespace that we are publishing in, NULL if we have no namespace.
Definition: fs_api.h:1218
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.
#define GNUNET_YES
Definition: gnunet_common.h:80
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:53
#define GNUNET_free(ptr)
Wrapper around free.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Definition: fs_api.h:1092
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 1685 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_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_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().

1686 {
1687  struct GNUNET_BIO_WriteHandle *wh;
1688  int32_t have_ns;
1689 
1690  if (NULL == pc->serialization)
1691  pc->serialization =
1694  if (NULL == pc->serialization)
1695  return;
1696  if (NULL == pc->fi)
1697  return;
1698  if (NULL == pc->fi->serialization)
1699  {
1700  GNUNET_break (0);
1701  return;
1702  }
1704  pc->serialization);
1705  if (NULL == wh)
1706  {
1707  GNUNET_break (0);
1708  goto cleanup;
1709  }
1710  have_ns = (NULL != pc->ns) ? GNUNET_YES : GNUNET_NO;
1711  if ((GNUNET_OK != GNUNET_BIO_write_string (wh, pc->nid)) ||
1712  (GNUNET_OK != GNUNET_BIO_write_string (wh, pc->nuid)) ||
1713  (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pc->options)) ||
1714  (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pc->all_done)) ||
1715  (GNUNET_OK != GNUNET_BIO_write_int32 (wh, have_ns)) ||
1717  (GNUNET_OK !=
1719  (NULL == pc->fi_pos) ? NULL : pc->fi_pos->serialization)) ||
1720  ( (NULL != pc->ns) &&
1721  (GNUNET_OK != GNUNET_BIO_write (wh,
1722  pc->ns,
1723  sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)) ) ))
1724  {
1725  GNUNET_break (0);
1726  goto cleanup;
1727  }
1728  if (GNUNET_OK != GNUNET_BIO_write_close (wh))
1729  {
1730  wh = NULL;
1731  GNUNET_break (0);
1732  goto cleanup;
1733  }
1734  return;
1735 cleanup:
1736  if (NULL != wh)
1737  (void) GNUNET_BIO_write_close (wh);
1739  pc->serialization);
1740  GNUNET_free (pc->serialization);
1741  pc->serialization = NULL;
1742 }
char * nid
ID of the content in the namespace, NULL if we have no namespace.
Definition: fs_api.h:1223
char * serialization
Under what filename is this struct serialized (for operational persistence).
Definition: fs_api.h:292
int GNUNET_BIO_write_string(struct GNUNET_BIO_WriteHandle *h, const char *s)
Write a string to a file.
Definition: bio.c:547
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:688
enum GNUNET_FS_PublishOptions options
Options for publishing.
Definition: fs_api.h:1294
#define GNUNET_NO
Definition: gnunet_common.h:81
struct GNUNET_FS_Handle * h
Handle to the global fs context.
Definition: fs_api.h:1203
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
char * serialization
Filename used for serializing information about this operation (should be determined using &#39;mktemp&#39;)...
Definition: fs_api.h:1234
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...
char * nuid
ID for future updates, NULL if we have no namespace or no updates.
Definition: fs_api.h:1228
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:1245
Handle for buffered writing.
Definition: bio.c:399
int all_done
Set to GNUNET_YES if all processing has completed.
Definition: fs_api.h:1311
static struct GNUNET_TESTBED_BarrierWaitHandle * wh
Our barrier wait handle.
int GNUNET_BIO_write_close(struct GNUNET_BIO_WriteHandle *h)
Close an open file for writing.
Definition: bio.c:457
struct GNUNET_FS_FileInformation * fi
File-structure that is being shared.
Definition: fs_api.h:1213
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:1187
struct GNUNET_CRYPTO_EcdsaPrivateKey * ns
Namespace that we are publishing in, NULL if we have no namespace.
Definition: fs_api.h:1218
#define GNUNET_FS_SYNC_PATH_MASTER_PUBLISH
Name of the directory with publishing operations.
Definition: fs_api.h:76
int GNUNET_BIO_write_int32(struct GNUNET_BIO_WriteHandle *h, int32_t i)
Write an (u)int32_t.
Definition: bio.c:605
#define GNUNET_YES
Definition: gnunet_common.h:80
int GNUNET_BIO_write(struct GNUNET_BIO_WriteHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: bio.c:505
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:738
#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 1754 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_int32(), GNUNET_BIO_write_int64(), 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().

1755 {
1756  struct GNUNET_BIO_WriteHandle *wh;
1757  char *uris;
1758 
1759  if (NULL == uc->serialization)
1760  uc->serialization =
1763  if (NULL == uc->serialization)
1764  return;
1766  uc->serialization);
1767  if (NULL == wh)
1768  {
1769  GNUNET_break (0);
1770  goto cleanup;
1771  }
1772  if (NULL != uc->ksk_uri)
1773  uris = GNUNET_FS_uri_to_string (uc->ksk_uri);
1774  else
1775  uris = NULL;
1776  if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uc->filename)) ||
1777  (GNUNET_OK != GNUNET_BIO_write_int64 (wh, uc->file_size)) ||
1778  (GNUNET_OK != write_start_time (wh, uc->start_time)) ||
1779  (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) uc->state)) ||
1780  (GNUNET_OK !=
1781  GNUNET_BIO_write (wh, &uc->chk, sizeof (struct ContentHashKey))) ||
1782  (GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) ||
1783  (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) uc->ksk_offset)) ||
1784  ((uc->state == UNINDEX_STATE_FS_NOTIFY) &&
1785  (GNUNET_OK !=
1786  GNUNET_BIO_write (wh, &uc->file_id, sizeof (struct GNUNET_HashCode)))) ||
1787  ((uc->state == UNINDEX_STATE_ERROR) &&
1788  (GNUNET_OK != GNUNET_BIO_write_string (wh, uc->emsg))))
1789  {
1790  GNUNET_break (0);
1791  goto cleanup;
1792  }
1793  if (GNUNET_OK != GNUNET_BIO_write_close (wh))
1794  {
1795  wh = NULL;
1796  GNUNET_break (0);
1797  goto cleanup;
1798  }
1799  return;
1800 cleanup:
1801  if (NULL != wh)
1802  (void) GNUNET_BIO_write_close (wh);
1804  uc->serialization);
1805  GNUNET_free (uc->serialization);
1806  uc->serialization = NULL;
1807 }
char * serialization
Short name under which we are serializing the state of this operation.
Definition: fs_api.h:1411
content hash key
Definition: fs.h:53
uint32_t ksk_offset
Current offset in KSK removal.
Definition: fs_api.h:1401
int GNUNET_BIO_write_string(struct GNUNET_BIO_WriteHandle *h, const char *s)
Write a string to a file.
Definition: bio.c:547
int GNUNET_BIO_write_int64(struct GNUNET_BIO_WriteHandle *h, int64_t i)
Write an (u)int64_t.
Definition: bio.c:623
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:688
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
struct GNUNET_HashCode file_id
Hash of the file&#39;s contents (once computed).
Definition: fs_api.h:1479
enum UnindexState state
Current operatinonal phase.
Definition: fs_api.h:1484
#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:1352
char * GNUNET_FS_uri_to_string(const struct GNUNET_FS_Uri *uri)
Convert a URI to a UTF-8 String.
Definition: fs_uri.c:1988
#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:1474
static void cleanup(void *cls)
Function scheduled as very last function, cleans up after us.
Handle for buffered writing.
Definition: bio.c:399
We&#39;ve encountered a fatal error.
Definition: fs_api.h:1362
struct GNUNET_FS_Uri * ksk_uri
Keywords found (telling us which KBlocks to remove).
Definition: fs_api.h:1396
A 512-bit hashcode.
char * filename
Name of the file that we are unindexing.
Definition: fs_api.h:1406
static int write_start_time(struct GNUNET_BIO_WriteHandle *wh, struct GNUNET_TIME_Absolute timestamp)
Serialize a start-time.
Definition: fs_api.c:830
static struct GNUNET_TESTBED_BarrierWaitHandle * wh
Our barrier wait handle.
int GNUNET_BIO_write_close(struct GNUNET_BIO_WriteHandle *h)
Close an open file for writing.
Definition: bio.c:457
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:1187
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:1376
int GNUNET_BIO_write_int32(struct GNUNET_BIO_WriteHandle *h, int32_t i)
Write an (u)int32_t.
Definition: bio.c:605
char * emsg
Error message, NULL on success.
Definition: fs_api.h:1459
int GNUNET_BIO_write(struct GNUNET_BIO_WriteHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: bio.c:505
struct GNUNET_FS_Handle * h
Global FS context.
Definition: fs_api.h:1381
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:738
#define GNUNET_free(ptr)
Wrapper around free.
uint64_t file_size
Overall size of the file.
Definition: fs_api.h:1469
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 1818 of file fs_api.c.

References BRS_CHK_SET, DownloadRequest::children, DownloadRequest::chk, DownloadRequest::depth, GNUNET_BIO_write(), GNUNET_BIO_write_int32(), GNUNET_BIO_write_int64(), GNUNET_NO, GNUNET_OK, GNUNET_YES, DownloadRequest::num_children, DownloadRequest::offset, and DownloadRequest::state.

Referenced by GNUNET_FS_download_sync_().

1820 {
1821  unsigned int i;
1822 
1823  if ((GNUNET_OK != GNUNET_BIO_write_int32 (wh, dr->state)) ||
1824  (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dr->offset)) ||
1826  (GNUNET_OK != GNUNET_BIO_write_int32 (wh, dr->depth)))
1827  return GNUNET_NO;
1828  if ((BRS_CHK_SET == dr->state) &&
1829  (GNUNET_OK !=
1830  GNUNET_BIO_write (wh, &dr->chk, sizeof (struct ContentHashKey))))
1831  return GNUNET_NO;
1832  for (i = 0; i < dr->num_children; i++)
1833  if (GNUNET_NO == write_download_request (wh, dr->children[i]))
1834  return GNUNET_NO;
1835  return GNUNET_YES;
1836 }
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:1709
int GNUNET_BIO_write_int64(struct GNUNET_BIO_WriteHandle *h, int64_t i)
Write an (u)int64_t.
Definition: bio.c:623
uint64_t offset
Offset of the corresponding block.
Definition: fs_api.h:1722
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
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:1715
enum BlockRequestState state
State in the FSM.
Definition: fs_api.h:1742
unsigned int num_children
Number of entries in children array.
Definition: fs_api.h:1727
static int write_download_request(struct GNUNET_BIO_WriteHandle *wh, struct DownloadRequest *dr)
Serialize a download request.
Definition: fs_api.c:1818
int GNUNET_BIO_write_int32(struct GNUNET_BIO_WriteHandle *h, int32_t i)
Write an (u)int32_t.
Definition: bio.c:605
#define GNUNET_YES
Definition: gnunet_common.h:80
int GNUNET_BIO_write(struct GNUNET_BIO_WriteHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: bio.c:505
unsigned int depth
Depth of the corresponding block in the tree.
Definition: fs_api.h:1732
We&#39;ve determined the real, desired CHK for this block (full tree reconstruction failed), request is now pending.
Definition: fs_api.h:1669
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 1846 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_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().

1847 {
1848  struct DownloadRequest *dr;
1849  unsigned int i;
1850 
1851  dr = GNUNET_new (struct DownloadRequest);
1852  if ((GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->state)) ||
1853  (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dr->offset)) ||
1854  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->num_children)) ||
1855  (dr->num_children > CHK_PER_INODE) ||
1856  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->depth)) ||
1857  ( (0 == dr->depth) &&
1858  (dr->num_children > 0) ) ||
1859  ((dr->depth > 0) && (0 == dr->num_children)))
1860  {
1861  GNUNET_break (0);
1862  dr->num_children = 0;
1863  goto cleanup;
1864  }
1865  if (dr->num_children > 0)
1866  dr->children =
1867  GNUNET_malloc (dr->num_children * sizeof (struct DownloadRequest *));
1868  switch (dr->state)
1869  {
1870  case BRS_INIT:
1871  case BRS_RECONSTRUCT_DOWN:
1873  case BRS_RECONSTRUCT_UP:
1874  break;
1875  case BRS_CHK_SET:
1876  if (GNUNET_OK !=
1877  GNUNET_BIO_read (rh, "chk", &dr->chk, sizeof (struct ContentHashKey)))
1878  goto cleanup;
1879  break;
1880  case BRS_DOWNLOAD_DOWN:
1881  case BRS_DOWNLOAD_UP:
1882  case BRS_ERROR:
1883  break;
1884  default:
1885  GNUNET_break (0);
1886  goto cleanup;
1887  }
1888  for (i = 0; i < dr->num_children; i++)
1889  {
1890  if (NULL == (dr->children[i] = read_download_request (rh)))
1891  goto cleanup;
1892  dr->children[i]->parent = dr;
1893  }
1894  return dr;
1895 cleanup:
1897  return NULL;
1898 }
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:1709
uint64_t offset
Offset of the corresponding block.
Definition: fs_api.h:1722
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#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:1715
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:1660
enum BlockRequestState state
State in the FSM.
Definition: fs_api.h:1742
unsigned int num_children
Number of entries in children array.
Definition: fs_api.h:1727
#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:1636
#define GNUNET_BIO_read_int64(h, i)
Read an (u)int64_t.
int GNUNET_BIO_read(struct GNUNET_BIO_ReadHandle *h, const char *what, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: bio.c:145
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:1644
#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.
We&#39;ve calculated the CHK bottom-up based on the meta data.
Definition: fs_api.h:1652
static struct DownloadRequest * read_download_request(struct GNUNET_BIO_ReadHandle *rh)
Read a download request tree.
Definition: fs_api.c:1846
We&#39;ve successfully downloaded this block, but the children still need to be either downloaded or veri...
Definition: fs_api.h:1678
This block and all of its children have been downloaded successfully (full completion propagates up)...
Definition: fs_api.h:1684
#define GNUNET_BIO_read_int32(h, i)
Read an (u)int32_t.
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:1691
void GNUNET_FS_free_download_request_(struct DownloadRequest *dr)
(recursively) free download request structure
Definition: fs_download.c:992
struct DownloadRequest * parent
Parent in the CHK-tree.
Definition: fs_api.h:1704
Information about an active download request.
Definition: fs_api.h:1698
unsigned int depth
Depth of the corresponding block in the tree.
Definition: fs_api.h:1732
We&#39;ve determined the real, desired CHK for this block (full tree reconstruction failed), request is now pending.
Definition: fs_api.h:1669
#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 1911 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_().

1914 {
1915  char *par;
1916  char *epar;
1917 
1918  if (dc->parent == NULL)
1919  return get_serialization_file_name (dc->h,
1920  (dc->search != NULL) ?
1923  uni);
1924  if (NULL == dc->parent->serialization)
1925  return NULL;
1926  par = get_download_sync_filename (dc->parent, dc->parent->serialization, "");
1927  if (NULL == par)
1928  return NULL;
1929  GNUNET_asprintf (&epar, "%s.dir%s%s%s", par, DIR_SEPARATOR_STR, uni, ext);
1930  GNUNET_free (par);
1931  return epar;
1932 }
struct GNUNET_FS_Handle * h
Global FS context.
Definition: fs_api.h:1774
#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:1790
#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:1842
struct GNUNET_FS_SearchResult * search
Associated search (used when downloading files based on search results), or NULL for none...
Definition: fs_api.h:1796
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:599
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:1911
#define DIR_SEPARATOR_STR
Definition: plibc.h:632
#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 1944 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_int32(), GNUNET_BIO_write_int64(), GNUNET_BIO_write_meta_data(), GNUNET_BIO_write_open(), GNUNET_BIO_write_string(), GNUNET_break, GNUNET_DISK_directory_create_for_file(), GNUNET_DISK_mktemp(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_free_non_null, 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, UNLINK, 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().

1945 {
1946  struct GNUNET_BIO_WriteHandle *wh;
1947  char *uris;
1948  char *fn;
1949  char *dir;
1950 
1951  if (0 != (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE))
1952  return; /* we don't sync probes */
1953  if (NULL == dc->serialization)
1954  {
1955  dir = get_download_sync_filename (dc, "", "");
1956  if (NULL == dir)
1957  return;
1959  {
1960  GNUNET_free (dir);
1961  return;
1962  }
1963  fn = GNUNET_DISK_mktemp (dir);
1964  GNUNET_free (dir);
1965  if (NULL == fn)
1966  return;
1968  }
1969  else
1970  {
1971  fn = get_download_sync_filename (dc, dc->serialization, "");
1972  if (NULL == fn)
1973  {
1974  GNUNET_free (dc->serialization);
1975  dc->serialization = NULL;
1976  GNUNET_free (fn);
1977  return;
1978  }
1979  }
1980  wh = GNUNET_BIO_write_open (fn);
1981  if (NULL == wh)
1982  {
1983  GNUNET_free (dc->serialization);
1984  dc->serialization = NULL;
1985  GNUNET_free (fn);
1986  return;
1987  }
1990  uris = GNUNET_FS_uri_to_string (dc->uri);
1991  if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) ||
1992  (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, dc->meta)) ||
1993  (GNUNET_OK != GNUNET_BIO_write_string (wh, dc->emsg)) ||
1994  (GNUNET_OK != GNUNET_BIO_write_string (wh, dc->filename)) ||
1997  (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dc->offset)) ||
1998  (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dc->length)) ||
1999  (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dc->completed)) ||
2000  (GNUNET_OK != write_start_time (wh, dc->start_time)) ||
2001  (GNUNET_OK != GNUNET_BIO_write_int32 (wh, dc->anonymity)) ||
2002  (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) dc->options)) ||
2003  (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) dc->has_finished)))
2004  {
2005  GNUNET_break (0);
2006  goto cleanup;
2007  }
2008  if (NULL == dc->emsg)
2009  {
2010  GNUNET_assert (dc->top_request != NULL);
2012  {
2013  GNUNET_break (0);
2014  goto cleanup;
2015  }
2016  }
2017  GNUNET_free_non_null (uris);
2018  uris = NULL;
2019  if (GNUNET_OK != GNUNET_BIO_write_close (wh))
2020  {
2021  wh = NULL;
2022  GNUNET_break (0);
2023  goto cleanup;
2024  }
2025  GNUNET_free (fn);
2026  return;
2027 cleanup:
2028  if (NULL != wh)
2029  (void) GNUNET_BIO_write_close (wh);
2030  GNUNET_free_non_null (uris);
2031  if (0 != UNLINK (fn))
2033  GNUNET_free (fn);
2034  GNUNET_free (dc->serialization);
2035  dc->serialization = NULL;
2036 }
int GNUNET_BIO_write_meta_data(struct GNUNET_BIO_WriteHandle *h, const struct GNUNET_CONTAINER_MetaData *m)
Write metadata container to a file.
Definition: bio.c:569
static char * dir
Set to the directory where runtime files are stored.
Definition: gnunet-arm.c:84
enum GNUNET_FS_DownloadOptions options
Options for the download.
Definition: fs_api.h:1949
int GNUNET_BIO_write_string(struct GNUNET_BIO_WriteHandle *h, const char *s)
Write a string to a file.
Definition: bio.c:547
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
int GNUNET_BIO_write_int64(struct GNUNET_BIO_WriteHandle *h, int64_t i)
Write an (u)int64_t.
Definition: bio.c:623
struct DownloadRequest * top_request
Top-level download request.
Definition: fs_api.h:1882
int GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:833
char * filename
Where are we writing the data (name of the file, can be NULL!).
Definition: fs_api.h:1848
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
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:1855
#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:1924
#define UNLINK(f)
Definition: plibc.h:666
int GNUNET_FS_uri_test_loc(const struct GNUNET_FS_Uri *uri)
Is this a location URI?
Definition: fs_uri.c:1381
char * GNUNET_FS_uri_to_string(const struct GNUNET_FS_Uri *uri)
Convert a URI to a UTF-8 String.
Definition: fs_uri.c:1988
uint64_t length
How many bytes starting from offset are desired? This is NOT the overall length of the file! ...
Definition: fs_api.h:1910
char * GNUNET_DISK_mktemp(const char *t)
Create an (empty) temporary file on disk.
Definition: disk.c:593
char * serialization
Random portion of filename we use for syncing state of this download.
Definition: fs_api.h:1842
#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:399
uint64_t offset
What is the first offset that we&#39;re interested in?
Definition: fs_api.h:1904
int GNUNET_FS_uri_test_chk(const struct GNUNET_FS_Uri *uri)
Is this a file (or directory) URI?
Definition: fs_uri.c:1345
char * emsg
Error message, NULL if we&#39;re doing OK.
Definition: fs_api.h:1836
int has_finished
Flag set upon transitive completion (includes child downloads).
Definition: fs_api.h:1956
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:1911
static int write_start_time(struct GNUNET_BIO_WriteHandle *wh, struct GNUNET_TIME_Absolute timestamp)
Serialize a start-time.
Definition: fs_api.c:830
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:1153
int GNUNET_BIO_write_close(struct GNUNET_BIO_WriteHandle *h)
Close an open file for writing.
Definition: bio.c:457
struct GNUNET_BIO_WriteHandle * GNUNET_BIO_write_open(const char *fn)
Open a file for writing.
Definition: bio.c:430
static int write_download_request(struct GNUNET_BIO_WriteHandle *wh, struct DownloadRequest *dr)
Serialize a download request.
Definition: fs_api.c:1818
uint32_t anonymity
Desired level of anonymity.
Definition: fs_api.h:1939
int GNUNET_BIO_write_int32(struct GNUNET_BIO_WriteHandle *h, int32_t i)
Write an (u)int32_t.
Definition: bio.c:605
struct GNUNET_CONTAINER_MetaData * meta
Known meta-data for the file (can be NULL).
Definition: fs_api.h:1831
#define GNUNET_YES
Definition: gnunet_common.h:80
struct GNUNET_TIME_Absolute start_time
Time download was started.
Definition: fs_api.h:1929
uint64_t completed
How many bytes have we already received within the specified range (DBlocks only).
Definition: fs_api.h:1916
struct GNUNET_FS_Uri * uri
URI that identifies the file that we are downloading.
Definition: fs_api.h:1826
#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 2048 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_int32(), GNUNET_BIO_write_meta_data(), GNUNET_BIO_write_string(), GNUNET_break, GNUNET_free, GNUNET_free_non_null, 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().

2049 {
2050  struct GNUNET_BIO_WriteHandle *wh;
2051  char *uris;
2052 
2053  if (NULL == sr->sc)
2054  return;
2055  uris = NULL;
2056  if (NULL == sr->serialization)
2057  sr->serialization =
2059  (sr->sc->psearch_result ==
2060  NULL) ?
2063  sr->sc->serialization);
2064  if (NULL == sr->serialization)
2065  return;
2066  wh = get_write_handle_in_dir (sr->h,
2067  (sr->sc->psearch_result ==
2070  sr->sc->serialization, sr->serialization);
2071  if (NULL == wh)
2072  {
2073  GNUNET_break (0);
2074  goto cleanup;
2075  }
2076  uris = GNUNET_FS_uri_to_string (sr->uri);
2077  if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) ||
2078  (GNUNET_OK !=
2080  sr->download !=
2081  NULL ? sr->download->serialization : NULL)) ||
2082  (GNUNET_OK !=
2084  sr->update_search !=
2085  NULL ? sr->update_search->serialization : NULL))
2086  || (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, sr->meta)) ||
2087  (GNUNET_OK != GNUNET_BIO_write (wh, &sr->key, sizeof (struct GNUNET_HashCode)))
2092  {
2093  GNUNET_break (0);
2094  goto cleanup;
2095  }
2096  if ( (NULL != sr->uri) &&
2097  (GNUNET_FS_URI_KSK == sr->sc->uri->type) &&
2099  (sr->sc->uri->data.ksk.keywordCount + 7) / 8)) )
2100  {
2101  GNUNET_break (0);
2102  goto cleanup;
2103  }
2104  if (GNUNET_OK != GNUNET_BIO_write_close (wh))
2105  {
2106  wh = NULL;
2107  GNUNET_break (0);
2108  goto cleanup;
2109  }
2110  GNUNET_free_non_null (uris);
2111  return;
2112 cleanup:
2113  GNUNET_free_non_null (uris);
2114  if (NULL != wh)
2115  (void) GNUNET_BIO_write_close (wh);
2117  (NULL == sr->sc->psearch_result)
2120  sr->sc->serialization, sr->serialization);
2121  GNUNET_free (sr->serialization);
2122  sr->serialization = NULL;
2123 }
uint32_t optional_support
Number of optional keywords under which this result was also found.
Definition: fs_api.h:616
int GNUNET_BIO_write_meta_data(struct GNUNET_BIO_WriteHandle *h, const struct GNUNET_CONTAINER_MetaData *m)
Write metadata container to a file.
Definition: bio.c:569
struct GNUNET_FS_DownloadContext * download
ID of an associated download based on this search result (or NULL for none).
Definition: fs_api.h:560
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:1554
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:1224
int GNUNET_BIO_write_string(struct GNUNET_BIO_WriteHandle *h, const char *s)
Write a string to a file.
Definition: bio.c:547
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:533
uint8_t * keyword_bitmap
Bitmap that specifies precisely which keywords have been matched already.
Definition: fs_api.h:576
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:769
Keyword search key (query with keywords).
Definition: fs_api.h:156
struct GNUNET_FS_Uri * uri
URI to which this search result refers to.
Definition: fs_api.h:538
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
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:715
#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:1548
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:566
char * GNUNET_FS_uri_to_string(const struct GNUNET_FS_Uri *uri)
Convert a URI to a UTF-8 String.
Definition: fs_uri.c:1988
char * serialization
Name of the file on disk we use for persistence.
Definition: fs_api.h:1569
char * serialization
Random portion of filename we use for syncing state of this download.
Definition: fs_api.h:1842
uint32_t availability_trials
Number of availability trials that we have performed for this search result.
Definition: fs_api.h:627
struct GNUNET_FS_Handle * h
File-sharing context this result belongs to.
Definition: fs_api.h:517
struct GNUNET_FS_Uri::@16::@17 ksk
uint32_t availability_success
Number of availability tests that have succeeded for this result.
Definition: fs_api.h:621
union GNUNET_FS_Uri::@16 data
static void cleanup(void *cls)
Function scheduled as very last function, cleans up after us.
Handle for buffered writing.
Definition: bio.c:399
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
static struct GNUNET_TESTBED_BarrierWaitHandle * wh
Our barrier wait handle.
struct GNUNET_CONTAINER_MetaData * meta
Metadata for the search result.
Definition: fs_api.h:543
enum GNUNET_FS_UriType type
Type of the URI.
Definition: fs_api.h:173
int GNUNET_BIO_write_close(struct GNUNET_BIO_WriteHandle *h)
Close an open file for writing.
Definition: bio.c:457
struct GNUNET_HashCode key
Key for the search result based on the URI.
Definition: fs_api.h:581
#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:610
int GNUNET_BIO_write_int32(struct GNUNET_BIO_WriteHandle *h, int32_t i)
Write an (u)int32_t.
Definition: bio.c:605
int GNUNET_BIO_write(struct GNUNET_BIO_WriteHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: bio.c:505
char * serialization
Name under which this search result is stored on disk.
Definition: fs_api.h:571
#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 2135 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_free_non_null, 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().

2136 {
2137  struct GNUNET_BIO_WriteHandle *wh;
2138  char *uris;
2139  char in_pause;
2140  const char *category;
2141 
2142  category =
2143  (NULL == sc->psearch_result)
2146  if (NULL == sc->serialization)
2147  sc->serialization = make_serialization_file_name (sc->h, category);
2148  if (NULL == sc->serialization)
2149  return;
2150  uris = NULL;
2151  wh = get_write_handle (sc->h, category, sc->serialization);
2152  if (NULL == wh)
2153  {
2154  GNUNET_break (0);
2155  goto cleanup;
2156  }
2159  uris = GNUNET_FS_uri_to_string (sc->uri);
2160  in_pause = (sc->task != NULL) ? 'r' : '\0';
2161  if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) ||
2162  (GNUNET_OK != write_start_time (wh, sc->start_time)) ||
2163  (GNUNET_OK != GNUNET_BIO_write_string (wh, sc->emsg)) ||
2164  (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) sc->options)) ||
2165  (GNUNET_OK != GNUNET_BIO_write (wh, &in_pause, sizeof (in_pause))) ||
2167  {
2168  GNUNET_break (0);
2169  goto cleanup;
2170  }
2171  GNUNET_free (uris);
2172  uris = NULL;
2173  if (GNUNET_OK != GNUNET_BIO_write_close (wh))
2174  {
2175  wh = NULL;
2176  GNUNET_break (0);
2177  goto cleanup;
2178  }
2179  return;
2180 cleanup:
2181  if (NULL != wh)
2182  (void) GNUNET_BIO_write_close (wh);
2183  GNUNET_free_non_null (uris);
2184  GNUNET_FS_remove_sync_file_ (sc->h, category, sc->serialization);
2185  GNUNET_free (sc->serialization);
2186  sc->serialization = NULL;
2187 }
int GNUNET_FS_uri_test_ksk(const struct GNUNET_FS_Uri *uri)
Is this a keyword URI?
Definition: fs_uri.c:1323
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:1606
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:1554
enum GNUNET_FS_SearchOptions options
Options for the search.
Definition: fs_api.h:1621
int GNUNET_BIO_write_string(struct GNUNET_BIO_WriteHandle *h, const char *s)
Write a string to a file.
Definition: bio.c:547
char * emsg
Error message (non-NULL if this operation failed).
Definition: fs_api.h:1574
struct GNUNET_TIME_Absolute start_time
When did we start?
Definition: fs_api.h:1593
#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:688
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
int GNUNET_FS_uri_test_sks(const struct GNUNET_FS_Uri *uri)
Is this a namespace URI?
Definition: fs_uri.c:1270
#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:1548
uint32_t anonymity
Anonymity level for the search.
Definition: fs_api.h:1611
char * GNUNET_FS_uri_to_string(const struct GNUNET_FS_Uri *uri)
Convert a URI to a UTF-8 String.
Definition: fs_uri.c:1988
char * serialization
Name of the file on disk we use for persistence.
Definition: fs_api.h:1569
static void cleanup(void *cls)
Function scheduled as very last function, cleans up after us.
Handle for buffered writing.
Definition: bio.c:399
#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:830
static struct GNUNET_TESTBED_BarrierWaitHandle * wh
Our barrier wait handle.
int GNUNET_BIO_write_close(struct GNUNET_BIO_WriteHandle *h)
Close an open file for writing.
Definition: bio.c:457
#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:1187
struct GNUNET_FS_Handle * h
Handle to the global FS context.
Definition: fs_api.h:1538
int GNUNET_BIO_write_int32(struct GNUNET_BIO_WriteHandle *h, int32_t i)
Write an (u)int32_t.
Definition: bio.c:605
#define GNUNET_YES
Definition: gnunet_common.h:80
int GNUNET_BIO_write(struct GNUNET_BIO_WriteHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: bio.c:505
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:738
#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 2199 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(), GNUNET_BIO_read_string(), GNUNET_break, GNUNET_CRYPTO_hash_file(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_free_non_null, 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().

2201 {
2202  struct GNUNET_FS_Handle *h = cls;
2203  struct GNUNET_BIO_ReadHandle *rh;
2204  struct GNUNET_FS_UnindexContext *uc;
2205  struct GNUNET_FS_ProgressInfo pi;
2206  char *emsg;
2207  char *uris;
2208  uint32_t state;
2209 
2210  uc = GNUNET_new (struct GNUNET_FS_UnindexContext);
2211  uc->h = h;
2214  if (NULL == rh)
2215  {
2216  GNUNET_break (0);
2217  goto cleanup;
2218  }
2219  uris = NULL;
2220  if ((GNUNET_OK !=
2221  GNUNET_BIO_read_string (rh, "unindex-fn", &uc->filename, 10 * 1024)) ||
2222  (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &uc->file_size)) ||
2223  (GNUNET_OK != read_start_time (rh, &uc->start_time)) ||
2224  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &state)) ||
2225  (GNUNET_OK != GNUNET_BIO_read (rh, "uri", &uc->chk, sizeof (struct ContentHashKey))) ||
2226  (GNUNET_OK != GNUNET_BIO_read_string (rh, "unindex-kskuri", &uris, 10 * 1024)) ||
2227  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &uc->ksk_offset)) )
2228  {
2229  GNUNET_free_non_null (uris);
2230  GNUNET_break (0);
2231  goto cleanup;
2232  }
2233  if (NULL != uris)
2234  {
2235  uc->ksk_uri = GNUNET_FS_uri_parse (uris, &emsg);
2236  GNUNET_free (uris);
2237  if (NULL == uc->ksk_uri)
2238  {
2239  GNUNET_break (0);
2240  GNUNET_free_non_null (emsg);
2241  goto cleanup;
2242  }
2243  }
2244  if ( (uc->ksk_offset > 0) &&
2245  ( (NULL == uc->ksk_uri) ||
2246  (uc->ksk_offset > uc->ksk_uri->data.ksk.keywordCount) ) )
2247  {
2248  GNUNET_break (0);
2249  goto cleanup;
2250  }
2251  uc->state = (enum UnindexState) state;
2252  switch (state)
2253  {
2254  case UNINDEX_STATE_HASHING:
2255  break;
2257  if (GNUNET_OK !=
2258  GNUNET_BIO_read (rh, "unindex-hash", &uc->file_id,
2259  sizeof (struct GNUNET_HashCode)))
2260  {
2261  GNUNET_break (0);
2262  goto cleanup;
2263  }
2264  break;
2268  break;
2270  break;
2271  case UNINDEX_STATE_ERROR:
2272  if (GNUNET_OK !=
2273  GNUNET_BIO_read_string (rh, "unindex-emsg", &uc->emsg, 10 * 1024))
2274  {
2275  GNUNET_break (0);
2276  goto cleanup;
2277  }
2278  break;
2279  default:
2280  GNUNET_break (0);
2281  goto cleanup;
2282  }
2283  uc->top = GNUNET_FS_make_top (h,
2285  uc);
2287  pi.value.unindex.specifics.resume.message = uc->emsg;
2289  (uc->state ==
2290  UNINDEX_STATE_COMPLETE) ? uc->file_size : 0);
2291  switch (uc->state)
2292  {
2293  case UNINDEX_STATE_HASHING:
2294  uc->fhc =
2298  break;
2302  break;
2305  break;
2308  break;
2311  break;
2313  case UNINDEX_STATE_ERROR:
2314  /* no need to resume any operation, we were done */
2315  break;
2316  default:
2317  break;
2318  }
2319  if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
2320  {
2322  _("Failure while resuming unindexing operation `%s': %s\n"),
2323  filename, emsg);
2324  GNUNET_free (emsg);
2325  }
2326  return GNUNET_OK;
2327 cleanup:
2329  if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)))
2330  {
2332  _("Failed to resume unindexing operation `%s': %s\n"),
2333  filename,
2334  emsg);
2335  GNUNET_free (emsg);
2336  }
2337  if (NULL != uc->serialization)
2339  uc->serialization);
2341  GNUNET_free (uc);
2342  return GNUNET_OK;
2343 }
char * serialization
Short name under which we are serializing the state of this operation.
Definition: fs_api.h:1411
content hash key
Definition: fs.h:53
uint32_t ksk_offset
Current offset in KSK removal.
Definition: fs_api.h:1401
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:635
Master context for most FS operations.
Definition: fs_api.h:1087
We&#39;re done.
Definition: fs_api.h:1357
void GNUNET_FS_unindex_do_remove_(struct GNUNET_FS_UnindexContext *uc)
Connect to the datastore and remove the blocks.
Definition: fs_unindex.c:645
static struct GNUNET_FS_UnindexContext * uc
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#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:1479
enum UnindexState state
Current operatinonal phase.
Definition: fs_api.h:1484
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:1369
int GNUNET_BIO_read_close(struct GNUNET_BIO_ReadHandle *h, char **emsg)
Close an open file.
Definition: bio.c:119
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_CRYPTO_FileHashContext * fhc
Context for hashing of the file.
Definition: fs_api.h:1464
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
Find out which keywords apply.
Definition: fs_api.h:1341
We&#39;re notifying the FS service about the unindexing.
Definition: fs_api.h:1352
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
struct GNUNET_BIO_ReadHandle * GNUNET_BIO_read_open(const char *fn)
Open a file for reading.
Definition: bio.c:94
#define GNUNET_BIO_read_int64(h, i)
Read an (u)int64_t.
int GNUNET_BIO_read(struct GNUNET_BIO_ReadHandle *h, const char *what, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: bio.c:145
struct TopLevelActivity * top
Our top-level activity entry.
Definition: fs_api.h:1386
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:576
struct GNUNET_FS_Uri::@16::@17 ksk
We&#39;re telling the datastore to remove KBlocks.
Definition: fs_api.h:1346
UnindexState
Phases of unindex processing (state machine).
Definition: fs_api.h:1325
union GNUNET_FS_Uri::@16 data
struct GNUNET_TIME_Absolute start_time
When did we start?
Definition: fs_api.h:1474
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:1362
struct GNUNET_FS_Uri * ksk_uri
Keywords found (telling us which KBlocks to remove).
Definition: fs_api.h:1396
A 512-bit hashcode.
char * filename
Name of the file that we are unindexing.
Definition: fs_api.h:1406
int GNUNET_BIO_read_string(struct GNUNET_BIO_ReadHandle *h, const char *what, char **result, size_t max_length)
Read 0-terminated string from a file.
Definition: bio.c:237
Run when otherwise idle.
#define GNUNET_BIO_read_int32(h, i)
Read an (u)int32_t.
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:1153
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:723
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:393
We&#39;re currently hashing the file.
Definition: fs_api.h:1330
#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:1336
static int read_start_time(struct GNUNET_BIO_ReadHandle *rh, struct GNUNET_TIME_Absolute *timestamp)
Deserialize a start-time.
Definition: fs_api.c:855
void GNUNET_FS_unindex_do_extract_keywords_(struct GNUNET_FS_UnindexContext *uc)
Extract the keywords for KBlock removal.
Definition: fs_unindex.c:404
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:1376
#define GNUNET_log(kind,...)
char * emsg
Error message, NULL on success.
Definition: fs_api.h:1459
Notification that we resumed unindexing of a file.
struct GNUNET_FS_Handle * h
Global FS context.
Definition: fs_api.h:1381
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:690
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:738
Handle for buffered reading.
Definition: bio.c:53
#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:1469
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 2760 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_int64, GNUNET_BIO_read_meta_data(), 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_free_non_null, 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().

2765 {
2766  struct GNUNET_FS_DownloadContext *dc;
2767  char *emsg;
2768  char *uris;
2769  char *dn;
2770  uint32_t options;
2771  uint32_t status;
2772 
2773  uris = NULL;
2774  emsg = NULL;
2775  dc = GNUNET_new (struct GNUNET_FS_DownloadContext);
2776  dc->parent = parent;
2777  dc->h = h;
2779  if ((GNUNET_OK !=
2780  GNUNET_BIO_read_string (rh, "download-uri", &uris, 10 * 1024)) ||
2781  (NULL == (dc->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
2782  ((GNUNET_YES != GNUNET_FS_uri_test_chk (dc->uri)) &&
2783  (GNUNET_YES != GNUNET_FS_uri_test_loc (dc->uri))) ||
2784  (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "download-meta", &dc->meta))
2785  || (GNUNET_OK !=
2786  GNUNET_BIO_read_string (rh, "download-emsg", &dc->emsg, 10 * 1024)) ||
2787  (GNUNET_OK !=
2788  GNUNET_BIO_read_string (rh, "download-fn", &dc->filename, 10 * 1024)) ||
2789  (GNUNET_OK !=
2790  GNUNET_BIO_read_string (rh, "download-tfn", &dc->temp_filename,
2791  10 * 1024)) ||
2792  (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->old_file_size)) ||
2793  (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->offset)) ||
2794  (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->length)) ||
2795  (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->completed)) ||
2796  (GNUNET_OK != read_start_time (rh, &dc->start_time)) ||
2797  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dc->anonymity)) ||
2798  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &options)) ||
2799  (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &status)))
2800  {
2801  GNUNET_break (0);
2802  goto cleanup;
2803  }
2804  dc->options = (enum GNUNET_FS_DownloadOptions) options;
2805  dc->active =
2807  dc->has_finished = (int) status;
2808  dc->treedepth =
2810  if (GNUNET_FS_uri_test_loc (dc->uri))
2813  &dc->target));
2814  if (NULL == dc->emsg)
2815  {
2817  if (NULL == dc->top_request)
2818  {
2819  GNUNET_break (0);
2820  goto cleanup;
2821  }
2822  }
2823  dn = get_download_sync_filename (dc,
2824  dc->serialization,
2825  ".dir");
2826  if (NULL != dn)
2827  {
2828  if (GNUNET_YES ==
2830  GNUNET_YES))
2833  dc);
2834  GNUNET_free (dn);
2835  }
2836  if (NULL != parent)
2837  {
2839  parent->child_tail,
2840  dc);
2841  }
2842  if (NULL != search)
2843  {
2844  dc->search = search;
2845  search->download = dc;
2846  }
2847  if ( (NULL == parent) &&
2848  (NULL == search) )
2849  {
2850  dc->top
2851  = GNUNET_FS_make_top (dc->h,
2853  dc);
2855  }
2856  GNUNET_free (uris);
2857  GNUNET_assert (NULL == dc->job_queue);
2859  dc);
2860  return;
2861 cleanup:
2862  GNUNET_free_non_null (uris);
2863  GNUNET_free_non_null (emsg);
2864  free_download_context (dc);
2865 }
int GNUNET_FS_uri_loc_get_peer_identity(const struct GNUNET_FS_Uri *uri, struct GNUNET_PeerIdentity *peer)
Obtain the identity of the peer offering the data.
Definition: fs_uri.c:810
Context for controlling a download.
Definition: fs_api.h:1768
struct GNUNET_FS_DownloadContext * download
ID of an associated download based on this search result (or NULL for none).
Definition: fs_api.h:560
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
enum GNUNET_FS_DownloadOptions options
Options for the download.
Definition: fs_api.h:1949
struct GNUNET_FS_Handle * h
Global FS context.
Definition: fs_api.h:1774
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
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:635
struct GNUNET_FS_DownloadContext * child_head
Head of list of child downloads.
Definition: fs_api.h:1801
#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:1882
struct GNUNET_FS_DownloadContext * parent
Parent download (used when downloading files in directories).
Definition: fs_api.h:1790
int GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition: disk.c:628
#define GNUNET_NO
Definition: gnunet_common.h:81
char * filename
Where are we writing the data (name of the file, can be NULL!).
Definition: fs_api.h:1848
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition: disk.c:1233
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:1855
#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...
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
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:1924
int GNUNET_FS_uri_test_loc(const struct GNUNET_FS_Uri *uri)
Is this a location URI?
Definition: fs_uri.c:1381
uint64_t length
How many bytes starting from offset are desired? This is NOT the overall length of the file! ...
Definition: fs_api.h:1910
#define GNUNET_BIO_read_int64(h, i)
Read an (u)int64_t.
unsigned int GNUNET_FS_compute_depth(uint64_t flen)
Compute the depth of the CHK tree.
Definition: fs_tree.c:126
void GNUNET_FS_download_signal_suspend_(void *cls)
Create SUSPEND event for the given download operation and then clean up our state (without stop signa...
Definition: fs_download.c:1953
char * serialization
Random portion of filename we use for syncing state of this download.
Definition: fs_api.h:1842
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:1273
static void free_download_context(struct GNUNET_FS_DownloadContext *dc)
Free this download context and all of its descendants.
Definition: fs_api.c:2724
uint16_t status
See PRISM_STATUS_*-constants.
static void cleanup(void *cls)
Function scheduled as very last function, cleans up after us.
struct GNUNET_CONTAINER_MultiHashMap * active
Map of active requests (those waiting for a response).
Definition: fs_api.h:1877
static void signal_download_resume(struct GNUNET_FS_DownloadContext *dc)
Send the &#39;resume&#39; signal to the callback; also actually resume the download (put it in the queue)...
Definition: fs_api.c:2529
uint64_t offset
What is the first offset that we&#39;re interested in?
Definition: fs_api.h:1904
struct TopLevelActivity * top
Our top-level activity entry (if we are top-level, otherwise NULL).
Definition: fs_api.h:1779
void GNUNET_FS_download_start_task_(void *cls)
Task that creates the initial (top-level) download request for the file.
Definition: fs_download.c:1802
static struct DownloadRequest * read_download_request(struct GNUNET_BIO_ReadHandle *rh)
Read a download request tree.
Definition: fs_api.c:1846
int GNUNET_BIO_read_string(struct GN