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

164 {
165  char *ret;
166 
167  GNUNET_asprintf(&ret,
168  "%s%s.auto-share",
169  dir_name,
170  (DIR_SEPARATOR == dir_name[strlen(dir_name) - 1])
171  ? ""
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_STR
Definition: platform.h:168
#define DIR_SEPARATOR
Definition: platform.h:167
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 != GNUNET_BIO_read_string(rh, "filename", &fn, 1024)) ||
202  (GNUNET_OK !=
203  GNUNET_BIO_read(rh, "id", &id, sizeof(struct GNUNET_HashCode))))
204  goto error;
205  wi = GNUNET_new(struct WorkItem);
206  wi->id = id;
207  wi->filename = fn;
209  "Loaded serialization ID for `%s' is `%s'\n",
210  wi->filename,
211  GNUNET_h2s(&id));
212  fn = NULL;
213  GNUNET_CRYPTO_hash(wi->filename, strlen(wi->filename), &id);
217  &id,
218  wi,
220  }
221  if (GNUNET_OK == GNUNET_BIO_read_close(rh, &emsg))
222  return;
223  rh = NULL;
224 error:
226  if (NULL != rh)
227  (void)GNUNET_BIO_read_close(rh, &emsg);
229  _("Failed to load state: %s\n"),
230  emsg);
231  GNUNET_free_non_null(emsg);
232 }
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:75
#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:118
#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:181
struct GNUNET_BIO_ReadHandle * GNUNET_BIO_read_open(const char *fn)
Open a file for reading.
Definition: bio.c:93
int GNUNET_BIO_read(struct GNUNET_BIO_ReadHandle *h, const char *what, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: bio.c:143
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:232
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 244 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().

245 {
246  struct GNUNET_BIO_WriteHandle *wh = cls;
247  struct WorkItem *wi = value;
248 
250  "Saving serialization ID of file `%s' with value `%s'\n",
251  wi->filename,
252  GNUNET_h2s(&wi->id));
253  if ((GNUNET_OK != GNUNET_BIO_write_string(wh, wi->filename)) ||
254  (GNUNET_OK !=
255  GNUNET_BIO_write(wh, &wi->id, sizeof(struct GNUNET_HashCode))))
256  return GNUNET_SYSERR; /* write error, abort iteration */
257  return GNUNET_OK;
258 }
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:521
char * filename
Filename of the work item.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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:378
A 512-bit hashcode.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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:481
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 265 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().

266 {
267  uint32_t n;
268  struct GNUNET_BIO_WriteHandle *wh;
269  char *fn;
270 
272  fn = get_state_file();
273  wh = GNUNET_BIO_write_open(fn);
274  if (NULL == wh)
275  {
277  _("Failed to save state to file %s\n"),
278  fn);
279  GNUNET_free(fn);
280  return;
281  }
282  if (GNUNET_OK != GNUNET_BIO_write_int32(wh, n))
283  {
284  (void)GNUNET_BIO_write_close(wh);
286  _("Failed to save state to file %s\n"),
287  fn);
288  GNUNET_free(fn);
289  return;
290  }
294  _("Failed to save state to file %s\n"),
295  fn);
296  GNUNET_free(fn);
297 }
unsigned int GNUNET_CONTAINER_multihashmap_size(const struct GNUNET_CONTAINER_MultiHashMap *map)
Get the number of key-value pairs in the map.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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:181
static char * fn
Filename of the unique file.
Handle for buffered writing.
Definition: bio.c:378
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:436
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:408
#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:580
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.
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
#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 306 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().

307 {
309  if (NULL != publish_proc)
310  {
312  return;
313  }
314  if (NULL != run_task)
315  {
317  run_task = NULL;
318  }
319 }
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:77
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:224
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
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 609 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().

610 {
612 
613  if (GNUNET_YES == do_shutdown)
614  return;
615  GNUNET_assert(NULL == run_task);
616  if (NULL == work_head)
617  {
618  /* delay by at most 4h, at least 1s, and otherwise in between depending
619  on how long it took to scan */
625  }
626  else
627  {
629  }
630 }
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:287
#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:1237
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1264
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:272
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:77
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 336 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().

337 {
338  struct WorkItem *wi = cls;
339  struct GNUNET_HashCode key;
341  unsigned long code;
342  int ret;
343  char c;
344  const struct GNUNET_DISK_FileHandle *pr;
345  const struct GNUNET_SCHEDULER_TaskContext *tc;
346 
347  run_task = NULL;
351  {
352  /* shutdown scheduled us, someone else will kill child,
353  we should just try again */
355  pr,
357  wi);
358  return;
359  }
360  /* consume the signal */
361  GNUNET_break(0 < GNUNET_DISK_file_read(pr, &c, sizeof(c)));
362 
363  ret = GNUNET_OS_process_status(publish_proc, &type, &code);
365  if (GNUNET_NO == ret)
366  {
367  /* process still running? Then where did the SIGCHLD come from?
368  Well, let's declare it spurious (kernel bug?) and keep rolling.
369  */
370  GNUNET_break(0);
372  pr,
374  wi);
375  return;
376  }
377  GNUNET_assert(GNUNET_OK == ret);
378 
380  publish_proc = NULL;
381 
382  if (GNUNET_YES == do_shutdown)
383  {
384  GNUNET_free(wi->filename);
385  GNUNET_free(wi);
386  return;
387  }
388  if ((GNUNET_OS_PROCESS_EXITED == type) && (0 == code))
389  {
391  _("Publication of `%s' done\n"),
392  wi->filename);
393  GNUNET_CRYPTO_hash(wi->filename, strlen(wi->filename), &key);
397  &key,
398  wi,
400  }
401  else
402  {
404  }
405  save_state();
407 }
const struct GNUNET_SCHEDULER_TaskContext * GNUNET_SCHEDULER_get_task_context(void)
Obtain the reasoning why the current task was started.
Definition: scheduler.c:737
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:286
ssize_t GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: disk.c:729
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:963
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:410
#define GNUNET_NO
Definition: gnunet_common.h:78
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:1615
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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:1744
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:181
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:76
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:77
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 415 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().

416 {
417  static char c;
418  int old_errno = errno; /* back-up errno */
419 
420  GNUNET_break(
421  1 ==
424  &c,
425  sizeof(c)));
426  errno = old_errno; /* restore errno */
427 }
#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:1744
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:817
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 436 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().

437 {
438  static char *argv[14];
439  static char anon_level[20];
440  static char content_prio[20];
441  static char repl_level[20];
442  struct WorkItem *wi;
443  const struct GNUNET_DISK_FileHandle *pr;
444  int argc;
445 
446  run_task = NULL;
447  wi = work_head;
449  argc = 0;
450  argv[argc++] = "gnunet-publish";
451  if (verbose)
452  argv[argc++] = "-V";
453  if (disable_extractor)
454  argv[argc++] = "-D";
456  argv[argc++] = "-d";
457  argv[argc++] = "-c";
458  argv[argc++] = cfg_filename;
459  GNUNET_snprintf(anon_level, sizeof(anon_level), "%u", anonymity_level);
460  argv[argc++] = "-a";
461  argv[argc++] = anon_level;
462  GNUNET_snprintf(content_prio, sizeof(content_prio), "%u", content_priority);
463  argv[argc++] = "-p";
464  argv[argc++] = content_prio;
465  GNUNET_snprintf(repl_level, sizeof(repl_level), "%u", replication_level);
466  argv[argc++] = "-r";
467  argv[argc++] = repl_level;
468  argv[argc++] = wi->filename;
469  argv[argc] = NULL;
470  GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Publishing `%s'\n"), wi->filename);
471  GNUNET_assert(NULL == publish_proc);
473  0,
474  NULL,
475  NULL,
476  NULL,
477  "gnunet-publish",
478  argv);
479  if (NULL == publish_proc)
480  {
482  _("Failed to run `%s'\n"),
483  "gnunet-publish");
485  run_task =
487  return;
488  }
491  pr,
493  wi);
494 }
#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:1615
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:1744
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
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:1237
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:607
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:77
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 506 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, and GNUNET_OK.

Referenced by add_file().

507 {
508  struct GNUNET_HashCode *id = cls;
509  struct stat sbuf;
510  struct GNUNET_HashCode fx[2];
511  struct GNUNET_HashCode ft;
512 
513  if (0 != stat(filename, &sbuf))
514  {
516  return GNUNET_OK;
517  }
518  GNUNET_CRYPTO_hash(filename, strlen(filename), &fx[0]);
519  if (!S_ISDIR(sbuf.st_mode))
520  {
521  uint64_t fattr[2];
522 
523  fattr[0] = GNUNET_htonll(sbuf.st_size);
524  fattr[0] = GNUNET_htonll(sbuf.st_mtime);
525 
526  GNUNET_CRYPTO_hash(fattr, sizeof(fattr), &fx[1]);
527  }
528  else
529  {
530  memset(&fx[1], 1, sizeof(struct GNUNET_HashCode));
532  }
533  /* use hash here to make hierarchical structure distinct from
534  all files on the same level */
535  GNUNET_CRYPTO_hash(fx, sizeof(fx), &ft);
536  /* use XOR here so that order of the files in the directory
537  does not matter! */
538  GNUNET_CRYPTO_hash_xor(&ft, id, id);
539  return GNUNET_OK;
540 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition: disk.c:909
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 553 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().

554 {
555  struct WorkItem *wi;
556  struct GNUNET_HashCode key;
557  struct GNUNET_HashCode id;
558 
559  if (GNUNET_YES == do_shutdown)
560  return GNUNET_SYSERR;
561  if ((NULL != strstr(filename, "/.auto-share")) ||
562  (NULL != strstr(filename, "\\.auto-share")))
563  return GNUNET_OK; /* skip internal file */
566  memset(&id, 0, sizeof(struct GNUNET_HashCode));
567  determine_id(&id, filename);
568  if (NULL != wi)
569  {
570  if (0 == memcmp(&id, &wi->id, sizeof(struct GNUNET_HashCode)))
571  return GNUNET_OK; /* skip: we did this one already */
572  /* contents changed, need to re-do the directory... */
574  GNUNET_YES ==
576  }
577  else
578  {
579  wi = GNUNET_new(struct WorkItem);
581  }
582  wi->id = id;
584  if (GNUNET_YES == do_shutdown)
585  return GNUNET_SYSERR;
586  return GNUNET_OK;
587 }
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:75
#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:76
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:77
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 596 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().

597 {
598  run_task = NULL;
602 }
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:909
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 642 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().

646 {
647  /* check arguments */
648  if ((NULL == args[0]) || (NULL != args[1]) ||
650  {
651  printf(_(
652  "You must specify one and only one directory name for automatic publication.\n"));
653  ret = -1;
654  return;
655  }
656  cfg_filename = GNUNET_strdup(cfgfile);
657  cfg = c;
658  dir_name = args[0];
660  load_state();
662  &scan,
663  NULL);
665 }
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:1284
int GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition: disk.c:500
#define GNUNET_NO
Definition: gnunet_common.h:78
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:181
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:1191
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:77
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 677 of file gnunet-auto-share.c.

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

Referenced by main().

678 {
679  struct WorkItem *wi = value;
680 
681  GNUNET_free(wi->filename);
682  GNUNET_free(wi);
683  return GNUNET_OK;
684 }
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:75
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 695 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.

696 {
699  "anonymity",
700  "LEVEL",
701  gettext_noop(
702  "set the desired LEVEL of sender-anonymity"),
703  &anonymity_level),
704 
706  'd',
707  "disable-creation-time",
708  gettext_noop(
709  "disable adding the creation time to the metadata of the uploaded file"),
711 
713  'D',
714  "disable-extractor",
715  gettext_noop("do not use libextractor to add keywords or metadata"),
717 
719  "priority",
720  "PRIORITY",
721  gettext_noop(
722  "specify the priority of the content"),
724 
726  "replication",
727  "LEVEL",
728  gettext_noop(
729  "set the desired replication LEVEL"),
731 
733 
735  };
736  struct WorkItem *wi;
737  int ok;
738  struct GNUNET_SIGNAL_Context *shc_chld;
739 
740  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
741  return 2;
743  GNUNET_assert(NULL != sigpipe);
744  shc_chld =
746  ok =
747  (GNUNET_OK ==
749  argc,
750  argv,
751  "gnunet-auto-share [OPTIONS] FILENAME",
752  gettext_noop("Automatically publish files from a directory on GNUnet"),
753  options,
754  &run,
755  NULL))
756  ? ret
757  : 1;
758  if (NULL != work_finished)
759  {
761  &free_item,
762  NULL);
764  }
765  while (NULL != (wi = work_head))
766  {
768  GNUNET_free(wi->filename);
769  GNUNET_free(wi);
770  }
772  shc_chld = NULL;
774  sigpipe = NULL;
776  cfg_filename = NULL;
777  GNUNET_free((void *)argv);
778  return ok;
779 }
#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:42
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:1439
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)
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
void GNUNET_SIGNAL_handler_uninstall(struct GNUNET_SIGNAL_Context *ctx)
Uninstall a previously installed signal hander.
Definition: signal.c:75
#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:1518
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:50
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:1706
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:367
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.
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
#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 68 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 73 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 78 of file gnunet-auto-share.c.

◆ cfg_filename

char* cfg_filename
static

Name of the configuration file.

Definition at line 83 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 88 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 93 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 98 of file gnunet-auto-share.c.

◆ anonymity_level

unsigned int anonymity_level = 1
static

Anonymity level option to use for publishing.

Definition at line 103 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 108 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 113 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 118 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 123 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 128 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 134 of file gnunet-auto-share.c.

◆ do_shutdown

int do_shutdown
static

Set to GNUNET_YES if we are shutting down.

Definition at line 139 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 146 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 151 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 156 of file gnunet-auto-share.c.