GNUnet  0.10.x
Data Structures | Macros | Functions | Variables
gnunet-auto-share.c File Reference

automatically publish files on GNUnet More...

#include "platform.h"
#include "gnunet_util_lib.h"
Include dependency graph for gnunet-auto-share.c:

Go to the source code of this file.

Data Structures

struct  WorkItem
 Item in our work queue (or in the set of files/directories we have successfully published). More...
 

Macros

#define MAX_DELAY   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
 
#define MIN_DELAY   GNUNET_TIME_UNIT_MINUTES
 

Functions

static char * get_state_file ()
 Compute the name of the state database file we will use. More...
 
static void load_state ()
 Load the set of work_finished items from disk. More...
 
static int write_item (void *cls, const struct GNUNET_HashCode *key, void *value)
 Write work item from the work_finished map to the given write handle. More...
 
static void save_state ()
 Save the set of work_finished items on disk. More...
 
static void do_stop_task (void *cls)
 Task run on shutdown. More...
 
static void schedule_next_task (void)
 Decide what the next task is (working or scanning) and schedule it. More...
 
static void maint_child_death (void *cls)
 Task triggered whenever we receive a SIGCHLD (child process died). More...
 
static void sighandler_child_death ()
 Signal handler called for SIGCHLD. More...
 
static void work (void *cls)
 Function called to process work items. More...
 
static int determine_id (void *cls, const char *filename)
 Recursively scan the given file/directory structure to determine a unique ID that represents the current state of the hierarchy. More...
 
static int add_file (void *cls, const char *filename)
 Function called with a filename (or directory name) to publish (if it has changed since the last time we published it). More...
 
static void scan (void *cls)
 Periodically run task to update our view of the directory to share. More...
 
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
 Main function that will be run by the scheduler. More...
 
static int free_item (void *cls, const struct GNUNET_HashCode *key, void *value)
 Free memory associated with the work item from the work_finished map. More...
 
int main (int argc, char *const *argv)
 The main function to automatically publish content to GNUnet. More...
 

Variables

static int ret
 Global return value from 'main'. More...
 
static unsigned int verbose
 Are we running 'verbosely'? More...
 
static const struct GNUNET_CONFIGURATION_Handlecfg
 Configuration to use. More...
 
static char * cfg_filename
 Name of the configuration file. More...
 
static int disable_extractor
 Disable extractor option to use for publishing. More...
 
static int do_disable_creation_time
 Disable creation time option to use for publishing. More...
 
static struct GNUNET_SCHEDULER_Taskrun_task
 Handle for the main task that does scanning and working. More...
 
static unsigned int anonymity_level = 1
 Anonymity level option to use for publishing. More...
 
static unsigned int content_priority = 365
 Content priority option to use for publishing. More...
 
static unsigned int replication_level = 1
 Replication level option to use for publishing. More...
 
static const char * dir_name
 Top-level directory we monitor to auto-publish. More...
 
static struct WorkItemwork_head
 Head of linked list of files still to publish. More...
 
static struct WorkItemwork_tail
 Tail of linked list of files still to publish. More...
 
static struct GNUNET_CONTAINER_MultiHashMapwork_finished
 Map from the hash of the filename (!) to a struct WorkItem that was finished. More...
 
static int do_shutdown
 Set to GNUNET_YES if we are shutting down. More...
 
static struct GNUNET_TIME_Absolute start_time
 Start time of the current round; used to determine how long one iteration takes (which influences how fast we schedule the next one). More...
 
static struct GNUNET_DISK_PipeHandlesigpipe
 Pipe used to communicate 'gnunet-publish' completion (SIGCHLD) via signal. More...
 
static struct GNUNET_OS_Processpublish_proc
 Handle to the 'gnunet-publish' process that we executed. More...
 

Detailed Description

automatically publish files on GNUnet

Author
Christian Grothoff

TODO:

Definition in file gnunet-auto-share.c.

Macro Definition Documentation

◆ MAX_DELAY

Definition at line 32 of file gnunet-auto-share.c.

Referenced by schedule_next_task().

◆ MIN_DELAY

#define MIN_DELAY   GNUNET_TIME_UNIT_MINUTES

Definition at line 34 of file gnunet-auto-share.c.

Referenced by schedule_next_task().

Function Documentation

◆ get_state_file()

static char* get_state_file ( )
static

Compute the name of the state database file we will use.

Definition at line 165 of file gnunet-auto-share.c.

References dir_name, DIR_SEPARATOR, DIR_SEPARATOR_STR, GNUNET_asprintf(), and ret.

Referenced by load_state(), and save_state().

166 {
167  char *ret;
168 
169  GNUNET_asprintf (&ret,
170  "%s%s.auto-share",
171  dir_name,
172  (DIR_SEPARATOR == dir_name[strlen(dir_name)-1]) ? "" : DIR_SEPARATOR_STR);
173  return ret;
174 }
static int ret
Global return value from 'main'.
static const char * dir_name
Top-level directory we monitor to auto-publish.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
#define DIR_SEPARATOR
Definition: plibc.h:631
#define DIR_SEPARATOR_STR
Definition: plibc.h:632
Here is the call graph for this function:
Here is the caller graph for this function:

◆ load_state()

static void load_state ( )
static

Load the set of work_finished items from disk.

Definition at line 181 of file gnunet-auto-share.c.

References _, WorkItem::filename, fn, get_state_file(), GNUNET_BIO_read(), GNUNET_BIO_read_close(), GNUNET_BIO_read_int32, GNUNET_BIO_read_open(), GNUNET_BIO_read_string(), GNUNET_break, GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_free_non_null, GNUNET_h2s(), GNUNET_log, GNUNET_new, GNUNET_OK, and WorkItem::id.

Referenced by run().

182 {
183  char *fn;
184  struct GNUNET_BIO_ReadHandle *rh;
185  uint32_t n;
186  struct GNUNET_HashCode id;
187  struct WorkItem *wi;
188  char *emsg;
189 
190  emsg = NULL;
191  fn = get_state_file ();
192  rh = GNUNET_BIO_read_open (fn);
193  GNUNET_free (fn);
194  if (NULL == rh)
195  return;
196  fn = NULL;
197  if (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &n))
198  goto error;
199  while (n-- > 0)
200  {
201  if ( (GNUNET_OK !=
202  GNUNET_BIO_read_string (rh, "filename", &fn, 1024)) ||
203  (GNUNET_OK !=
204  GNUNET_BIO_read (rh, "id", &id, sizeof (struct GNUNET_HashCode))) )
205  goto error;
206  wi = GNUNET_new (struct WorkItem);
207  wi->id = id;
208  wi->filename = fn;
210  "Loaded serialization ID for `%s' is `%s'\n",
211  wi->filename,
212  GNUNET_h2s (&id));
213  fn = NULL;
215  strlen (wi->filename),
216  &id);
219  &id,
220  wi,
222  }
223  if (GNUNET_OK ==
224  GNUNET_BIO_read_close (rh, &emsg))
225  return;
226  rh = NULL;
227  error:
229  if (NULL != rh)
230  (void) GNUNET_BIO_read_close (rh, &emsg);
232  _("Failed to load state: %s\n"),
233  emsg);
234  GNUNET_free_non_null (emsg);
235 }
Item in our work queue (or in the set of files/directories we have successfully published).
char * filename
Filename of the work item.
static struct GNUNET_IDENTITY_Handle * id
Handle to identity service.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
#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.
static struct GNUNET_CONTAINER_MultiHashMap * work_finished
Map from the hash of the filename (!) to a struct WorkItem that was finished.
int GNUNET_BIO_read_close(struct GNUNET_BIO_ReadHandle *h, char **emsg)
Close an open file.
Definition: bio.c:119
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define _(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
static char * fn
Filename of the unique file.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:44
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
There must only be one value per key; storing a value should fail if a value under the same key alrea...
#define GNUNET_BIO_read_int32(h, i)
Read an (u)int32_t.
int GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
struct GNUNET_HashCode id
Unique identity for this work item (used to detect if we need to do the work again).
static char * get_state_file()
Compute the name of the state database file we will use.
#define GNUNET_log(kind,...)
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:

◆ write_item()

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

Write work item from the work_finished map to the given write handle.

Parameters
clsthe struct GNUNET_BIO_WriteHandle *
keykey of the item in the map (unused)
valuethe struct WorkItem to write
Returns
GNUNET_OK to continue to iterate (if write worked)

Definition at line 247 of file gnunet-auto-share.c.

References WorkItem::filename, GNUNET_BIO_write(), GNUNET_BIO_write_string(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_OK, GNUNET_SYSERR, WorkItem::id, value, and wh.

Referenced by save_state().

250 {
251  struct GNUNET_BIO_WriteHandle *wh = cls;
252  struct WorkItem *wi = value;
253 
255  "Saving serialization ID of file `%s' with value `%s'\n",
256  wi->filename,
257  GNUNET_h2s (&wi->id));
258  if ( (GNUNET_OK !=
259  GNUNET_BIO_write_string (wh, wi->filename)) ||
260  (GNUNET_OK !=
261  GNUNET_BIO_write (wh,
262  &wi->id,
263  sizeof (struct GNUNET_HashCode))) )
264  return GNUNET_SYSERR; /* write error, abort iteration */
265  return GNUNET_OK;
266 }
Item in our work queue (or in the set of files/directories we have successfully published).
int GNUNET_BIO_write_string(struct GNUNET_BIO_WriteHandle *h, const char *s)
Write a string to a file.
Definition: bio.c:547
char * filename
Filename of the work item.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
static char * value
Value of the record to add/remove.
Handle for buffered writing.
Definition: bio.c:399
A 512-bit hashcode.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
static struct GNUNET_TESTBED_BarrierWaitHandle * wh
Our barrier wait handle.
struct GNUNET_HashCode id
Unique identity for this work item (used to detect if we need to do the work again).
#define GNUNET_log(kind,...)
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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_state()

static void save_state ( )
static

Save the set of work_finished items on disk.

Definition at line 273 of file gnunet-auto-share.c.

References _, fn, get_state_file(), GNUNET_BIO_write_close(), GNUNET_BIO_write_int32(), GNUNET_BIO_write_open(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_CONTAINER_multihashmap_size(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_OK, wh, and write_item().

Referenced by maint_child_death().

274 {
275  uint32_t n;
276  struct GNUNET_BIO_WriteHandle *wh;
277  char *fn;
278 
280  fn = get_state_file ();
281  wh = GNUNET_BIO_write_open (fn);
282  if (NULL == wh)
283  {
285  _("Failed to save state to file %s\n"),
286  fn);
287  GNUNET_free (fn);
288  return;
289  }
290  if (GNUNET_OK !=
291  GNUNET_BIO_write_int32 (wh, n))
292  {
293  (void) GNUNET_BIO_write_close (wh);
295  _("Failed to save state to file %s\n"),
296  fn);
297  GNUNET_free (fn);
298  return;
299  }
301  &write_item,
302  wh);
303  if (GNUNET_OK != GNUNET_BIO_write_close (wh))
305  _("Failed to save state to file %s\n"),
306  fn);
307  GNUNET_free (fn);
308 }
unsigned int GNUNET_CONTAINER_multihashmap_size(const struct GNUNET_CONTAINER_MultiHashMap *map)
Get the number of key-value pairs in the map.
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_HashMapIterator it, void *it_cls)
Iterate over all entries in the map.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static struct GNUNET_CONTAINER_MultiHashMap * work_finished
Map from the hash of the filename (!) to a struct WorkItem that was finished.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static char * fn
Filename of the unique file.
Handle for buffered writing.
Definition: bio.c:399
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 * get_state_file()
Compute the name of the state database file we will use.
struct GNUNET_BIO_WriteHandle * GNUNET_BIO_write_open(const char *fn)
Open a file for writing.
Definition: bio.c:430
#define GNUNET_log(kind,...)
int GNUNET_BIO_write_int32(struct GNUNET_BIO_WriteHandle *h, int32_t i)
Write an (u)int32_t.
Definition: bio.c:605
static int write_item(void *cls, const struct GNUNET_HashCode *key, void *value)
Write work item from the work_finished map to the given write handle.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_stop_task()

static void do_stop_task ( void *  cls)
static

Task run on shutdown.

Serializes our current state to disk.

Parameters
clsclosure, unused

Definition at line 317 of file gnunet-auto-share.c.

References do_shutdown, GNUNET_OS_process_kill(), GNUNET_SCHEDULER_cancel(), GNUNET_YES, and schedule_next_task().

Referenced by run().

318 {
320  if (NULL != publish_proc)
321  {
323  SIGKILL);
324  return;
325  }
326  if (NULL != run_task)
327  {
329  run_task = NULL;
330  }
331 }
static int do_shutdown
Set to GNUNET_YES if we are shutting down.
static struct GNUNET_OS_Process * publish_proc
Handle to the 'gnunet-publish' process that we executed.
#define GNUNET_YES
Definition: gnunet_common.h:80
static struct GNUNET_SCHEDULER_Task * run_task
Handle for the main task that does scanning and working.
int GNUNET_OS_process_kill(struct GNUNET_OS_Process *proc, int sig)
Sends a signal to the process.
Definition: os_priority.c:251
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:

◆ schedule_next_task()

static void schedule_next_task ( void  )
static

Decide what the next task is (working or scanning) and schedule it.

Definition at line 663 of file gnunet-auto-share.c.

References do_shutdown, GNUNET_assert, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_add_now(), GNUNET_TIME_absolute_get_duration(), GNUNET_TIME_relative_max(), GNUNET_TIME_relative_min(), GNUNET_TIME_relative_saturating_multiply(), GNUNET_YES, MAX_DELAY, MIN_DELAY, scan(), start_time, and work().

Referenced by do_stop_task(), maint_child_death(), and scan().

664 {
666 
667  if (GNUNET_YES == do_shutdown)
668  return;
669  GNUNET_assert (NULL == run_task);
670  if (NULL == work_head)
671  {
672  /* delay by at most 4h, at least 1s, and otherwise in between depending
673  on how long it took to scan */
677  MAX_DELAY);
679  MIN_DELAY);
681  &scan,
682  NULL);
683  }
684  else
685  {
687  NULL);
688  }
689 }
struct GNUNET_TIME_Relative GNUNET_TIME_relative_max(struct GNUNET_TIME_Relative t1, struct GNUNET_TIME_Relative t2)
Return the maximum of two relative time values.
Definition: time.c:286
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define MIN_DELAY
static void work(void *cls)
Function called to process work items.
static int do_shutdown
Set to GNUNET_YES if we are shutting down.
#define MAX_DELAY
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
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 struct GNUNET_TIME_Absolute start_time
Start time of the current round; used to determine how long one iteration takes (which influences how...
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
static struct WorkItem * work_head
Head of linked list of files still to publish.
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
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_YES
Definition: gnunet_common.h:80
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
static void scan(void *cls)
Periodically run task to update our view of the directory to share.
static struct GNUNET_SCHEDULER_Task * run_task
Handle for the main task that does scanning and working.
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:

◆ maint_child_death()

static void maint_child_death ( void *  cls)
static

Task triggered whenever we receive a SIGCHLD (child process died).

Parameters
clsthe struct WorkItem we were working on

Definition at line 348 of file gnunet-auto-share.c.

References _, do_shutdown, WorkItem::filename, GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CRYPTO_hash(), GNUNET_DISK_file_read(), GNUNET_DISK_PIPE_END_READ, GNUNET_DISK_pipe_handle(), GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_OS_process_destroy(), GNUNET_OS_PROCESS_EXITED, GNUNET_OS_process_status(), GNUNET_SCHEDULER_add_read_file(), GNUNET_SCHEDULER_get_task_context(), GNUNET_SCHEDULER_REASON_READ_READY, GNUNET_SYSERR, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, GNUNET_SCHEDULER_TaskContext::reason, ret, save_state(), schedule_next_task(), tc, and type.

Referenced by work().

349 {
350  struct WorkItem *wi = cls;
351  struct GNUNET_HashCode key;
353  unsigned long code;
354  int ret;
355  char c;
356  const struct GNUNET_DISK_FileHandle *pr;
357  const struct GNUNET_SCHEDULER_TaskContext *tc;
358 
359  run_task = NULL;
364  {
365  /* shutdown scheduled us, someone else will kill child,
366  we should just try again */
367  run_task =
369  pr,
370  &maint_child_death, wi);
371  return;
372  }
373  /* consume the signal */
374  GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof (c)));
375 
377  &type,
378  &code);
379  GNUNET_assert (GNUNET_SYSERR != ret);
380  if (GNUNET_NO == ret)
381  {
382  /* process still running? Then where did the SIGCHLD come from?
383  Well, let's declare it spurious (kernel bug?) and keep rolling.
384  */
385  GNUNET_break (0);
386  run_task =
388  pr,
389  &maint_child_death, wi);
390  return;
391  }
392  GNUNET_assert (GNUNET_OK == ret);
393 
395  publish_proc = NULL;
396 
397  if (GNUNET_YES == do_shutdown)
398  {
399  GNUNET_free (wi->filename);
400  GNUNET_free (wi);
401  return;
402  }
403  if ( (GNUNET_OS_PROCESS_EXITED == type) &&
404  (0 == code) )
405  {
407  _("Publication of `%s' done\n"),
408  wi->filename);
410  strlen (wi->filename),
411  &key);
414  &key,
415  wi,
417  }
418  else
419  {
421  work_tail,
422  wi);
423  }
424  save_state ();
426 }
const struct GNUNET_SCHEDULER_TaskContext * GNUNET_SCHEDULER_get_task_context(void)
Obtain the reasoning why the current task was started.
Definition: scheduler.c:746
static int ret
Global return value from &#39;main&#39;.
Item in our work queue (or in the set of files/directories we have successfully published).
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition: os_priority.c:364
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
int GNUNET_OS_process_status(struct GNUNET_OS_Process *proc, enum GNUNET_OS_ProcessStatusType *type, unsigned long *code)
Retrieve the status of a process, waiting on it if dead.
Definition: os_priority.c:1719
The reading socket is ready.
Context information passed to each scheduler task.
char * filename
Filename of the work item.
static void maint_child_death(void *cls)
Task triggered whenever we receive a SIGCHLD (child process died).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
Definition: scheduler.c:417
#define GNUNET_NO
Definition: gnunet_common.h:81
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_file(struct GNUNET_TIME_Relative delay, const struct GNUNET_DISK_FileHandle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1643
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static struct GNUNET_CONTAINER_MultiHashMap * work_finished
Map from the hash of the filename (!) to a struct WorkItem that was finished.
enum GNUNET_SCHEDULER_Reason reason
Reason why the task is run now.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
const struct GNUNET_DISK_FileHandle * GNUNET_DISK_pipe_handle(const struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd n)
Get the handle to a particular pipe end.
Definition: disk.c:2641
static void schedule_next_task(void)
Decide what the next task is (working or scanning) and schedule it.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static int do_shutdown
Set to GNUNET_YES if we are shutting down.
static struct GNUNET_OS_Process * publish_proc
Handle to the &#39;gnunet-publish&#39; process that we executed.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:44
GNUNET_OS_ProcessStatusType
Process status types.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
The reading-end of a pipe.
The process exited with a return code.
A 512-bit hashcode.
There must only be one value per key; storing a value should fail if a value under the same key alrea...
struct GNUNET_HashCode key
The key used in the DHT.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
static void save_state()
Save the set of work_finished items on disk.
static struct WorkItem * work_head
Head of linked list of files still to publish.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
static struct GNUNET_DISK_PipeHandle * sigpipe
Pipe used to communicate &#39;gnunet-publish&#39; completion (SIGCHLD) via signal.
int GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
#define GNUNET_log(kind,...)
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
#define GNUNET_YES
Definition: gnunet_common.h:80
Handle used to access files (and pipes).
static struct GNUNET_SCHEDULER_Task * run_task
Handle for the main task that does scanning and working.
#define GNUNET_free(ptr)
Wrapper around free.
static struct WorkItem * work_tail
Tail of linked list of files still to publish.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sighandler_child_death()

static void sighandler_child_death ( )
static

Signal handler called for SIGCHLD.

Triggers the respective handler by writing to the trigger pipe.

Definition at line 434 of file gnunet-auto-share.c.

References GNUNET_break, GNUNET_DISK_file_write(), GNUNET_DISK_PIPE_END_WRITE, and GNUNET_DISK_pipe_handle().

Referenced by main().

435 {
436  static char c;
437  int old_errno = errno; /* back-up errno */
438 
439  GNUNET_break (1 ==
441  (sigpipe,
443  &c, sizeof (c)));
444  errno = old_errno; /* restore errno */
445 }
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
const struct GNUNET_DISK_FileHandle * GNUNET_DISK_pipe_handle(const struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd n)
Get the handle to a particular pipe end.
Definition: disk.c:2641
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: disk.c:1049
The writing-end of a pipe.
static struct GNUNET_DISK_PipeHandle * sigpipe
Pipe used to communicate &#39;gnunet-publish&#39; completion (SIGCHLD) via signal.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ work()

static void work ( void *  cls)
static

Function called to process work items.

Parameters
clsclosure, NULL

Definition at line 454 of file gnunet-auto-share.c.

References _, anonymity_level, cfg_filename, content_priority, disable_extractor, do_disable_creation_time, WorkItem::filename, GNUNET_assert, GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_DLL_remove, GNUNET_DISK_PIPE_END_READ, GNUNET_DISK_pipe_handle(), GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_OS_start_process_vap(), GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_add_read_file(), GNUNET_snprintf(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TIME_UNIT_MINUTES, GNUNET_YES, maint_child_death(), replication_level, verbose, and work_head.

Referenced by dns_post_request_handler(), and schedule_next_task().

455 {
456  static char *argv[14];
457  static char anon_level[20];
458  static char content_prio[20];
459  static char repl_level[20];
460  struct WorkItem *wi;
461  const struct GNUNET_DISK_FileHandle *pr;
462  int argc;
463 
464  run_task = NULL;
465  wi = work_head;
467  work_tail,
468  wi);
469  argc = 0;
470  argv[argc++] = "gnunet-publish";
471  if (verbose)
472  argv[argc++] = "-V";
473  if (disable_extractor)
474  argv[argc++] = "-D";
476  argv[argc++] = "-d";
477  argv[argc++] = "-c";
478  argv[argc++] = cfg_filename;
479  GNUNET_snprintf (anon_level, sizeof (anon_level),
480  "%u", anonymity_level);
481  argv[argc++] = "-a";
482  argv[argc++] = anon_level;
483  GNUNET_snprintf (content_prio, sizeof (content_prio),
484  "%u", content_priority);
485  argv[argc++] = "-p";
486  argv[argc++] = content_prio;
487  GNUNET_snprintf (repl_level, sizeof (repl_level),
488  "%u", replication_level);
489  argv[argc++] = "-r";
490  argv[argc++] = repl_level;
491  argv[argc++] = wi->filename;
492  argv[argc] = NULL;
494  _("Publishing `%s'\n"),
495  wi->filename);
496  GNUNET_assert (NULL == publish_proc);
498  0, NULL, NULL, NULL,
499  "gnunet-publish",
500  argv);
501  if (NULL == publish_proc)
502  {
504  _("Failed to run `%s'\n"),
505  "gnunet-publish");
507  work_tail,
508  wi);
510  &work,
511  NULL);
512  return;
513  }
516  run_task =
518  pr,
519  &maint_child_death, wi);
520 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
static char * cfg_filename
Name of the configuration file.
Item in our work queue (or in the set of files/directories we have successfully published).
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
int GNUNET_snprintf(char *buf, size_t size, const char *format,...)
Like snprintf, just aborts if the buffer is of insufficient size.
static unsigned int verbose
Are we running &#39;verbosely&#39;?
#define GNUNET_TIME_UNIT_MINUTES
One minute.
char * filename
Filename of the work item.
static void maint_child_death(void *cls)
Task triggered whenever we receive a SIGCHLD (child process died).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_file(struct GNUNET_TIME_Relative delay, const struct GNUNET_DISK_FileHandle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1643
static void work(void *cls)
Function called to process work items.
static unsigned int anonymity_level
Anonymity level option to use for publishing.
const struct GNUNET_DISK_FileHandle * GNUNET_DISK_pipe_handle(const struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd n)
Get the handle to a particular pipe end.
Definition: disk.c:2641
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static struct GNUNET_OS_Process * publish_proc
Handle to the &#39;gnunet-publish&#39; process that we executed.
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
struct GNUNET_OS_Process * GNUNET_OS_start_process_vap(int pipe_control, enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, struct GNUNET_DISK_PipeHandle *pipe_stderr, const char *filename, char *const argv[])
Start a process.
Definition: os_priority.c:1321
static int disable_extractor
Disable extractor option to use for publishing.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
The reading-end of a pipe.
static unsigned int content_priority
Content priority option to use for publishing.
static struct WorkItem * work_head
Head of linked list of files still to publish.
static struct GNUNET_DISK_PipeHandle * sigpipe
Pipe used to communicate &#39;gnunet-publish&#39; completion (SIGCHLD) via signal.
static int do_disable_creation_time
Disable creation time option to use for publishing.
#define GNUNET_log(kind,...)
static unsigned int replication_level
Replication level option to use for publishing.
#define GNUNET_YES
Definition: gnunet_common.h:80
Handle used to access files (and pipes).
static struct GNUNET_SCHEDULER_Task * run_task
Handle for the main task that does scanning and working.
static struct WorkItem * work_tail
Tail of linked list of files still to publish.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ determine_id()

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

Recursively scan the given file/directory structure to determine a unique ID that represents the current state of the hierarchy.

Parameters
clswhere to store the unique ID we are computing
filenamefile to scan
Returns
GNUNET_OK (always)

Definition at line 532 of file gnunet-auto-share.c.

References GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_hash_xor(), GNUNET_DISK_directory_scan(), GNUNET_ERROR_TYPE_WARNING, GNUNET_htonll(), GNUNET_log_strerror_file, GNUNET_OK, and STAT.

Referenced by add_file().

534 {
535  struct GNUNET_HashCode *id = cls;
536  struct stat sbuf;
537  struct GNUNET_HashCode fx[2];
538  struct GNUNET_HashCode ft;
539 
540  if (0 != STAT (filename, &sbuf))
541  {
543  "stat",
544  filename);
545  return GNUNET_OK;
546  }
548  strlen (filename),
549  &fx[0]);
550  if (!S_ISDIR (sbuf.st_mode))
551  {
552  uint64_t fattr[2];
553 
554  fattr[0] = GNUNET_htonll (sbuf.st_size);
555  fattr[0] = GNUNET_htonll (sbuf.st_mtime);
556 
557  GNUNET_CRYPTO_hash (fattr,
558  sizeof (fattr),
559  &fx[1]);
560  }
561  else
562  {
563  memset (&fx[1],
564  1,
565  sizeof (struct GNUNET_HashCode));
567  &determine_id,
568  &fx[1]);
569  }
570  /* use hash here to make hierarchical structure distinct from
571  all files on the same level */
572  GNUNET_CRYPTO_hash (fx,
573  sizeof (fx),
574  &ft);
575  /* use XOR here so that order of the files in the directory
576  does not matter! */
578  id,
579  id);
580  return GNUNET_OK;
581 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define STAT(p, b)
Definition: plibc.h:663
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition: disk.c:1233
static int determine_id(void *cls, const char *filename)
Recursively scan the given file/directory structure to determine a unique ID that represents the curr...
#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...
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:44
static char * filename
A 512-bit hashcode.
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:35
void GNUNET_CRYPTO_hash_xor(const struct GNUNET_HashCode *a, const struct GNUNET_HashCode *b, struct GNUNET_HashCode *result)
compute result = a ^ b
Definition: crypto_hash.c:193
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_file()

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

Function called with a filename (or directory name) to publish (if it has changed since the last time we published it).

This function is called for the top-level files only.

Parameters
clsclosure, NULL
filenamecomplete filename (absolute path)
Returns
GNUNET_OK to continue to iterate, GNUNET_SYSERR during shutdown

Definition at line 594 of file gnunet-auto-share.c.

References determine_id(), do_shutdown, WorkItem::filename, GNUNET_assert, GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_multihashmap_get(), GNUNET_CONTAINER_multihashmap_remove(), GNUNET_CRYPTO_hash(), GNUNET_new, GNUNET_OK, GNUNET_strdup, GNUNET_SYSERR, GNUNET_YES, and WorkItem::id.

Referenced by scan().

596 {
597  struct WorkItem *wi;
598  struct GNUNET_HashCode key;
599  struct GNUNET_HashCode id;
600 
601  if (GNUNET_YES == do_shutdown)
602  return GNUNET_SYSERR;
603  if ( (NULL != strstr (filename,
604  "/.auto-share")) ||
605  (NULL != strstr (filename,
606  "\\.auto-share")) )
607  return GNUNET_OK; /* skip internal file */
609  strlen (filename),
610  &key);
612  &key);
613  memset (&id, 0, sizeof (struct GNUNET_HashCode));
614  determine_id (&id, filename);
615  if (NULL != wi)
616  {
617  if (0 == memcmp (&id,
618  &wi->id,
619  sizeof (struct GNUNET_HashCode)))
620  return GNUNET_OK; /* skip: we did this one already */
621  /* contents changed, need to re-do the directory... */
624  &key,
625  wi));
626  }
627  else
628  {
629  wi = GNUNET_new (struct WorkItem);
631  }
632  wi->id = id;
634  work_tail,
635  wi);
636  if (GNUNET_YES == do_shutdown)
637  return GNUNET_SYSERR;
638  return GNUNET_OK;
639 }
Item in our work queue (or in the set of files/directories we have successfully published).
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
char * filename
Filename of the work item.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_IDENTITY_Handle * id
Handle to identity service.
#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.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
static struct GNUNET_CONTAINER_MultiHashMap * work_finished
Map from the hash of the filename (!) to a struct WorkItem that was finished.
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
static int do_shutdown
Set to GNUNET_YES if we are shutting down.
static int determine_id(void *cls, const char *filename)
Recursively scan the given file/directory structure to determine a unique ID that represents the curr...
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:44
static char * filename
int GNUNET_CONTAINER_multihashmap_remove(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
Remove the given key-value pair from the map.
A 512-bit hashcode.
struct GNUNET_HashCode key
The key used in the DHT.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
static struct WorkItem * work_head
Head of linked list of files still to publish.
struct GNUNET_HashCode id
Unique identity for this work item (used to detect if we need to do the work again).
#define GNUNET_YES
Definition: gnunet_common.h:80
static struct WorkItem * work_tail
Tail of linked list of files still to publish.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ scan()

static void scan ( void *  cls)
static

Periodically run task to update our view of the directory to share.

Parameters
clsNULL

Definition at line 648 of file gnunet-auto-share.c.

References add_file(), dir_name, GNUNET_DISK_directory_scan(), GNUNET_TIME_absolute_get(), schedule_next_task(), and start_time.

Referenced by run(), and schedule_next_task().

649 {
650  run_task = NULL;
653  &add_file,
654  NULL);
656 }
static const char * dir_name
Top-level directory we monitor to auto-publish.
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition: disk.c:1233
static void schedule_next_task(void)
Decide what the next task is (working or scanning) and schedule it.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
static struct GNUNET_TIME_Absolute start_time
Start time of the current round; used to determine how long one iteration takes (which influences how...
static struct GNUNET_SCHEDULER_Task * run_task
Handle for the main task that does scanning and working.
static int add_file(void *cls, const char *filename)
Function called with a filename (or directory name) to publish (if it has changed since the last time...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

static void run ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle c 
)
static

Main function that will be run by the scheduler.

Parameters
clsclosure
argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)
cconfiguration

Definition at line 701 of file gnunet-auto-share.c.

References _, cfg_filename, dir_name, do_stop_task(), GNUNET_CONTAINER_multihashmap_create(), GNUNET_DISK_directory_test(), GNUNET_NO, GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_add_with_priority(), GNUNET_SCHEDULER_PRIORITY_IDLE, GNUNET_strdup, GNUNET_YES, load_state(), ret, and scan().

Referenced by main().

705 {
706  /* check arguments */
707  if ( (NULL == args[0]) ||
708  (NULL != args[1]) ||
709  (GNUNET_YES !=
711  GNUNET_YES)) )
712  {
713  printf (_("You must specify one and only one directory name for automatic publication.\n"));
714  ret = -1;
715  return;
716  }
717  cfg_filename = GNUNET_strdup (cfgfile);
718  cfg = c;
719  dir_name = args[0];
721  GNUNET_NO);
722  load_state ();
724  &scan,
725  NULL);
727  NULL);
728 }
static char * cfg_filename
Name of the configuration file.
static int ret
Global return value from &#39;main&#39;.
static const char * dir_name
Top-level directory we monitor to auto-publish.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1293
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
static void do_stop_task(void *cls)
Task run on shutdown.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
static struct GNUNET_CONTAINER_MultiHashMap * work_finished
Map from the hash of the filename (!) to a struct WorkItem that was finished.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static void load_state()
Load the set of work_finished items from disk.
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
Run when otherwise idle.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
#define GNUNET_YES
Definition: gnunet_common.h:80
static void scan(void *cls)
Periodically run task to update our view of the directory to share.
static struct GNUNET_SCHEDULER_Task * run_task
Handle for the main task that does scanning and working.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ free_item()

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

Free memory associated with the work item from the work_finished map.

Parameters
clsNULL (unused)
keykey of the item in the map (unused)
valuethe struct WorkItem to free
Returns
GNUNET_OK to continue to iterate

Definition at line 740 of file gnunet-auto-share.c.

References WorkItem::filename, GNUNET_free, GNUNET_OK, and value.

Referenced by main().

743 {
744  struct WorkItem *wi = value;
745 
746  GNUNET_free (wi->filename);
747  GNUNET_free (wi);
748  return GNUNET_OK;
749 }
Item in our work queue (or in the set of files/directories we have successfully published).
char * filename
Filename of the work item.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static char * value
Value of the record to add/remove.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *const *  argv 
)

The main function to automatically publish content to GNUnet.

Parameters
argcnumber of arguments from the command line
argvcommand line arguments
Returns
0 ok, 1 on error

Definition at line 760 of file gnunet-auto-share.c.

References anonymity_level, cfg_filename, content_priority, disable_extractor, do_disable_creation_time, WorkItem::filename, free_item(), gettext_noop, GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_DISK_pipe(), GNUNET_DISK_pipe_close(), GNUNET_free, GNUNET_free_non_null, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_flag(), GNUNET_GETOPT_option_uint(), GNUNET_GETOPT_option_verbose(), GNUNET_NO, GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_SIGCHLD, GNUNET_SIGNAL_handler_install(), GNUNET_SIGNAL_handler_uninstall(), GNUNET_STRINGS_get_utf8_args(), ok, replication_level, ret, run(), sighandler_child_death(), and verbose.

761 {
763 
765  "anonymity",
766  "LEVEL",
767  gettext_noop ("set the desired LEVEL of sender-anonymity"),
768  &anonymity_level),
769 
771  "disable-creation-time",
772  gettext_noop ("disable adding the creation time to the metadata of the uploaded file"),
774 
776  "disable-extractor",
777  gettext_noop ("do not use libextractor to add keywords or metadata"),
779 
781  "priority",
782  "PRIORITY",
783  gettext_noop ("specify the priority of the content"),
785 
787  "replication",
788  "LEVEL",
789  gettext_noop ("set the desired replication LEVEL"),
791 
793 
795  };
796  struct WorkItem *wi;
797  int ok;
798  struct GNUNET_SIGNAL_Context *shc_chld;
799 
800  if (GNUNET_OK !=
801  GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
802  return 2;
805  GNUNET_assert (NULL != sigpipe);
806  shc_chld =
809  ok = (GNUNET_OK ==
810  GNUNET_PROGRAM_run (argc, argv,
811  "gnunet-auto-share [OPTIONS] FILENAME",
813  ("Automatically publish files from a directory on GNUnet"),
814  options, &run, NULL)) ? ret : 1;
815  if (NULL != work_finished)
816  {
818  &free_item,
819  NULL);
821  }
822  while (NULL != (wi = work_head))
823  {
825  work_tail,
826  wi);
827  GNUNET_free (wi->filename);
828  GNUNET_free (wi);
829  }
831  shc_chld = NULL;
833  sigpipe = NULL;
835  cfg_filename = NULL;
836  GNUNET_free ((void*) argv);
837  return ok;
838 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
static char * cfg_filename
Name of the configuration file.
static int ret
Global return value from &#39;main&#39;.
Item in our work queue (or in the set of files/directories we have successfully published).
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define GNUNET_SIGCHLD
Definition: platform.h:46
static unsigned int verbose
Are we running &#39;verbosely&#39;?
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_verbose(unsigned int *level)
Define the &#39;-V&#39; verbosity option.
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1521
char * filename
Filename of the work item.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static int ok
Return value from &#39;main&#39; (0 == success)
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_HashMapIterator it, void *it_cls)
Iterate over all entries in the map.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
void GNUNET_SIGNAL_handler_uninstall(struct GNUNET_SIGNAL_Context *ctx)
Uninstall a previously installed signal hander.
Definition: signal.c:99
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
Definition of a command line option.
static struct GNUNET_CONTAINER_MultiHashMap * work_finished
Map from the hash of the filename (!) to a struct WorkItem that was finished.
static unsigned int anonymity_level
Anonymity level option to use for publishing.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
static int disable_extractor
Disable extractor option to use for publishing.
struct GNUNET_DISK_PipeHandle * GNUNET_DISK_pipe(int blocking_read, int blocking_write, int inherit_read, int inherit_write)
Creates an interprocess channel.
Definition: disk.c:2289
static void sighandler_child_death()
Signal handler called for SIGCHLD.
struct GNUNET_SIGNAL_Context * GNUNET_SIGNAL_handler_install(int signal, GNUNET_SIGNAL_Handler handler)
Install a signal handler that will be run if the given signal is received.
Definition: signal.c:59
static unsigned int content_priority
Content priority option to use for publishing.
static struct WorkItem * work_head
Head of linked list of files still to publish.
static struct GNUNET_DISK_PipeHandle * sigpipe
Pipe used to communicate &#39;gnunet-publish&#39; completion (SIGCHLD) via signal.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
Main function that will be run by the scheduler.
int GNUNET_DISK_pipe_close(struct GNUNET_DISK_PipeHandle *p)
Closes an interprocess channel.
Definition: disk.c:2603
static int do_disable_creation_time
Disable creation time option to use for publishing.
static int free_item(void *cls, const struct GNUNET_HashCode *key, void *value)
Free memory associated with the work item from the work_finished map.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_flag(char shortName, const char *name, const char *description, int *val)
Allow user to specify a flag (which internally means setting an integer to 1/GNUNET_YES/GNUNET_OK.
int GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration, parse options).
Definition: program.c:361
static unsigned int replication_level
Replication level option to use for publishing.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_uint(char shortName, const char *name, const char *argumentHelp, const char *description, unsigned int *val)
Allow user to specify an unsigned int.
#define GNUNET_free(ptr)
Wrapper around free.
static struct WorkItem * work_tail
Tail of linked list of files still to publish.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:

Variable Documentation

◆ ret

int ret
static

Global return value from 'main'.

Definition at line 70 of file gnunet-auto-share.c.

Referenced by get_state_file(), main(), maint_child_death(), and run().

◆ verbose

unsigned int verbose
static

Are we running 'verbosely'?

Definition at line 75 of file gnunet-auto-share.c.

Referenced by main(), and work().

◆ cfg

const struct GNUNET_CONFIGURATION_Handle* cfg
static

Configuration to use.

Definition at line 80 of file gnunet-auto-share.c.

◆ cfg_filename

char* cfg_filename
static

Name of the configuration file.

Definition at line 85 of file gnunet-auto-share.c.

Referenced by GNUNET_SERVICE_run_(), GNUNET_TESTBED_barrier_wait(), main(), run(), and work().

◆ disable_extractor

int disable_extractor
static

Disable extractor option to use for publishing.

Definition at line 90 of file gnunet-auto-share.c.

Referenced by main(), and work().

◆ do_disable_creation_time

int do_disable_creation_time
static

Disable creation time option to use for publishing.

Definition at line 95 of file gnunet-auto-share.c.

Referenced by main(), and work().

◆ run_task

struct GNUNET_SCHEDULER_Task* run_task
static

Handle for the main task that does scanning and working.

Definition at line 100 of file gnunet-auto-share.c.

◆ anonymity_level

unsigned int anonymity_level = 1
static

Anonymity level option to use for publishing.

Definition at line 105 of file gnunet-auto-share.c.

Referenced by GSF_pending_request_create_(), main(), and work().

◆ content_priority

unsigned int content_priority = 365
static

Content priority option to use for publishing.

Definition at line 110 of file gnunet-auto-share.c.

Referenced by main(), and work().

◆ replication_level

unsigned int replication_level = 1
static

Replication level option to use for publishing.

Definition at line 115 of file gnunet-auto-share.c.

Referenced by main(), and work().

◆ dir_name

const char* dir_name
static

Top-level directory we monitor to auto-publish.

Definition at line 120 of file gnunet-auto-share.c.

Referenced by get_state_file(), run(), and scan().

◆ work_head

struct WorkItem* work_head
static

Head of linked list of files still to publish.

Definition at line 125 of file gnunet-auto-share.c.

Referenced by work().

◆ work_tail

struct WorkItem* work_tail
static

Tail of linked list of files still to publish.

Definition at line 130 of file gnunet-auto-share.c.

◆ work_finished

struct GNUNET_CONTAINER_MultiHashMap* work_finished
static

Map from the hash of the filename (!) to a struct WorkItem that was finished.

Definition at line 136 of file gnunet-auto-share.c.

◆ do_shutdown

int do_shutdown
static

Set to GNUNET_YES if we are shutting down.

Definition at line 141 of file gnunet-auto-share.c.

Referenced by add_file(), do_stop_task(), maint_child_death(), and schedule_next_task().

◆ start_time

struct GNUNET_TIME_Absolute start_time
static

Start time of the current round; used to determine how long one iteration takes (which influences how fast we schedule the next one).

Definition at line 148 of file gnunet-auto-share.c.

Referenced by scan(), schedule_next_task(), and shutdown_task().

◆ sigpipe

struct GNUNET_DISK_PipeHandle* sigpipe
static

Pipe used to communicate 'gnunet-publish' completion (SIGCHLD) via signal.

Definition at line 153 of file gnunet-auto-share.c.

◆ publish_proc

struct GNUNET_OS_Process* publish_proc
static

Handle to the 'gnunet-publish' process that we executed.

Definition at line 158 of file gnunet-auto-share.c.