GNUnet 0.27.0
 
Loading...
Searching...
No Matches
gnunet-auto-share.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2001--2012 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
29#include "platform.h"
30#include "gnunet_util_lib.h"
31
32#define MAX_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
33
34#define MIN_DELAY GNUNET_TIME_UNIT_MINUTES
35
36
42{
46 struct WorkItem *prev;
47
51 struct WorkItem *next;
52
56 char *filename;
57
63};
64
65
69static int ret;
70
74static unsigned int verbose;
75
79static const struct GNUNET_CONFIGURATION_Handle *cfg;
80
84static char *cfg_filename;
85
90
95
100
104static unsigned int anonymity_level = 1;
105
109static unsigned int content_priority = 365;
110
114static unsigned int replication_level = 1;
115
119static const char *dir_name;
120
124static struct WorkItem *work_head;
125
129static struct WorkItem *work_tail;
130
136
140static int do_shutdown;
141
148
153
158
159
163static char *
165{
166 char *retval;
167
168 GNUNET_asprintf (&retval,
169 "%s%s.auto-share",
170 dir_name,
171 (DIR_SEPARATOR == dir_name[strlen (dir_name) - 1])
172 ? ""
174 return retval;
175}
176
177
181static void
183{
184 char *fn;
185 struct GNUNET_BIO_ReadHandle *rh;
186 uint32_t n;
187 struct GNUNET_HashCode id;
188 struct WorkItem *wi;
189 char *emsg;
190
191 emsg = NULL;
192 fn = get_state_file ();
194 GNUNET_free (fn);
195 if (NULL == rh)
196 return;
197 fn = NULL;
198 if (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "number of files",
199 (int32_t *) &n))
200 goto error;
201 while (n-- > 0)
202 {
203 struct GNUNET_BIO_ReadSpec rs[] = {
204 GNUNET_BIO_read_spec_string ("filename", &fn, 1024),
205 GNUNET_BIO_read_spec_object ("id", &id, sizeof(struct GNUNET_HashCode)),
207 };
209 goto error;
210 wi = GNUNET_new (struct WorkItem);
211 wi->id = id;
212 wi->filename = fn;
214 "Loaded serialization ID for `%s' is `%s'\n",
215 wi->filename,
216 GNUNET_h2s (&id));
217 fn = NULL;
218 GNUNET_CRYPTO_hash (wi->filename, strlen (wi->filename), &id);
222 &id,
223 wi,
225 }
226 if (GNUNET_OK == GNUNET_BIO_read_close (rh, &emsg))
227 return;
228 rh = NULL;
229error:
230 GNUNET_free (fn);
231 if (NULL != rh)
232 (void) GNUNET_BIO_read_close (rh, &emsg);
234 _ ("Failed to load state: %s\n"),
235 emsg);
236 GNUNET_free (emsg);
237}
238
239
248static int
249write_item (void *cls, const struct GNUNET_HashCode *key, void *value)
250{
251 struct GNUNET_BIO_WriteHandle *wh = cls;
252 struct WorkItem *wi = value;
253
254 struct GNUNET_BIO_WriteSpec ws[] = {
255 GNUNET_BIO_write_spec_string ("auto-share-write-item-filename",
256 wi->filename),
257 GNUNET_BIO_write_spec_object ("id", &wi->id, sizeof(struct
260 };
262 "Saving serialization ID of file `%s' with value `%s'\n",
263 wi->filename,
264 GNUNET_h2s (&wi->id));
266 return GNUNET_SYSERR; /* write error, abort iteration */
267 return GNUNET_OK;
268}
269
270
274static void
276{
277 uint32_t n;
278 struct GNUNET_BIO_WriteHandle *wh;
279 char *fn;
280
282 fn = get_state_file ();
284 if (NULL == wh)
285 {
287 _ ("Failed to save state to file %s\n"),
288 fn);
289 GNUNET_free (fn);
290 return;
291 }
292 if (GNUNET_OK != GNUNET_BIO_write_int32 (wh, "size of state", n))
293 {
294 (void) GNUNET_BIO_write_close (wh, NULL);
296 _ ("Failed to save state to file %s\n"),
297 fn);
298 GNUNET_free (fn);
299 return;
300 }
302 if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
304 _ ("Failed to save state to file %s\n"),
305 fn);
306 GNUNET_free (fn);
307}
308
309
315static void
316do_stop_task (void *cls)
317{
319 if (NULL != publish_proc)
320 {
323 SIGKILL));
324 return;
325 }
326 if (NULL != run_task)
327 {
329 run_task = NULL;
330 }
331}
332
333
337static void
338schedule_next_task (void);
339
340
347static void
349{
350 struct WorkItem *wi = cls;
351 struct GNUNET_HashCode key;
353 unsigned long code;
354 int retval;
355 char c;
356 const struct GNUNET_DISK_FileHandle *pr;
357 const struct GNUNET_SCHEDULER_TaskContext *tc;
358
359 run_task = NULL;
363 {
364 /* shutdown scheduled us, someone else will kill child,
365 we should just try again */
367 pr,
369 wi);
370 return;
371 }
372 /* consume the signal */
373 GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof(c)));
374
376 false,
377 &type,
378 &code);
379 GNUNET_assert (GNUNET_SYSERR != retval);
380 if (GNUNET_NO == retval)
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);
387 pr,
389 wi);
390 return;
391 }
392 GNUNET_assert (GNUNET_OK == retval);
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) && (0 == code))
404 {
406 _ ("Publication of `%s' done\n"),
407 wi->filename);
408 GNUNET_CRYPTO_hash (wi->filename, strlen (wi->filename), &key);
412 &key,
413 wi,
415 }
416 else
417 {
419 }
420 save_state ();
422}
423
424
429static void
431{
432 static char c;
433 int old_errno = errno; /* back-up errno */
434
436 1 ==
439 ,
440 &c,
441 sizeof(c)));
442 errno = old_errno; /* restore errno */
443}
444
445
451static void
452work (void *cls)
453{
454 static const char *argv[14];
455 static char anon_level[20];
456 static char content_prio[20];
457 static char repl_level[20];
458 struct WorkItem *wi;
459 const struct GNUNET_DISK_FileHandle *pr;
460 int argc;
461
462 run_task = NULL;
463 wi = work_head;
465 argc = 0;
466 argv[argc++] = "gnunet-publish";
467 if (verbose)
468 argv[argc++] = "-V";
470 argv[argc++] = "-D";
472 argv[argc++] = "-d";
473 argv[argc++] = "-c";
474 argv[argc++] = cfg_filename;
475 GNUNET_snprintf (anon_level, sizeof(anon_level), "%u", anonymity_level);
476 argv[argc++] = "-a";
477 argv[argc++] = anon_level;
478 GNUNET_snprintf (content_prio, sizeof(content_prio), "%u", content_priority);
479 argv[argc++] = "-p";
480 argv[argc++] = content_prio;
481 GNUNET_snprintf (repl_level, sizeof(repl_level), "%u", replication_level);
482 argv[argc++] = "-r";
483 argv[argc++] = repl_level;
484 argv[argc++] = wi->filename;
485 argv[argc] = NULL;
486 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Publishing `%s'\n"), wi->filename);
487 GNUNET_assert (NULL == publish_proc);
489 if (GNUNET_OK !=
491 "gnunet-publish",
492 (const char **) argv))
493 {
495 _ ("Failed to run `%s'\n"),
496 "gnunet-publish");
498 work_tail,
499 wi);
501 publish_proc = NULL;
502 run_task =
504 &work,
505 NULL);
506 return;
507 }
511 pr,
513 wi);
514}
515
516
525static int
526determine_id (void *cls, const char *filename)
527{
528 struct GNUNET_HashCode *id = cls;
529 struct stat sbuf;
530 struct GNUNET_HashCode fx[2];
531 struct GNUNET_HashCode ft;
532
533 if (0 != stat (filename, &sbuf))
534 {
536 return GNUNET_OK;
537 }
538 GNUNET_CRYPTO_hash (filename, strlen (filename), &fx[0]);
539 if (! S_ISDIR (sbuf.st_mode))
540 {
541 uint64_t fattr[2];
542
543 fattr[0] = GNUNET_htonll (sbuf.st_size);
544 fattr[0] = GNUNET_htonll (sbuf.st_mtime);
545
546 GNUNET_CRYPTO_hash (fattr, sizeof(fattr), &fx[1]);
547 }
548 else
549 {
550 memset (&fx[1], 1, sizeof(struct GNUNET_HashCode));
552 }
553 /* use hash here to make hierarchical structure distinct from
554 all files on the same level */
555 GNUNET_CRYPTO_hash (fx, sizeof(fx), &ft);
556 /* use XOR here so that order of the files in the directory
557 does not matter! */
558 GNUNET_CRYPTO_hash_xor (&ft, id, id);
559 return GNUNET_OK;
560}
561
562
572static int
573add_file (void *cls, const char *filename)
574{
575 struct WorkItem *wi;
576 struct GNUNET_HashCode key;
577 struct GNUNET_HashCode id;
578
579 if (GNUNET_YES == do_shutdown)
580 return GNUNET_SYSERR;
581 if ((NULL != strstr (filename, "/.auto-share")) ||
582 (NULL != strstr (filename, "\\.auto-share")))
583 return GNUNET_OK; /* skip internal file */
586 memset (&id, 0, sizeof(struct GNUNET_HashCode));
587 determine_id (&id, filename);
588 if (NULL != wi)
589 {
590 if (0 == memcmp (&id, &wi->id, sizeof(struct GNUNET_HashCode)))
591 return GNUNET_OK; /* skip: we did this one already */
592 /* contents changed, need to re-do the directory... */
594 GNUNET_YES ==
596 }
597 else
598 {
599 wi = GNUNET_new (struct WorkItem);
601 }
602 wi->id = id;
604 if (GNUNET_YES == do_shutdown)
605 return GNUNET_SYSERR;
606 return GNUNET_OK;
607}
608
609
615static void
616scan (void *cls)
617{
618 run_task = NULL;
622}
623
624
628static void
630{
631 struct GNUNET_TIME_Relative delay;
632
633 if (GNUNET_YES == do_shutdown)
634 return;
635 GNUNET_assert (NULL == run_task);
636 if (NULL == work_head)
637 {
638 /* delay by at most 4h, at least 1s, and otherwise in between depending
639 on how long it took to scan */
641 delay = GNUNET_TIME_relative_saturating_multiply (delay, 100);
642 delay = GNUNET_TIME_relative_min (delay, MAX_DELAY);
643 delay = GNUNET_TIME_relative_max (delay, MIN_DELAY);
645 }
646 else
647 {
649 }
650}
651
652
661static void
662run (void *cls,
663 char *const *args,
664 const char *cfgfile,
665 const struct GNUNET_CONFIGURATION_Handle *c)
666{
667 /* check arguments */
668 if ((NULL == args[0]) || (NULL != args[1]) ||
670 {
671 printf (_ (
672 "You must specify one and only one directory name for automatic publication.\n"));
673 ret = -1;
674 return;
675 }
676 cfg_filename = GNUNET_strdup (cfgfile);
677 cfg = c;
678 dir_name = args[0];
680 load_state ();
682 &scan,
683 NULL);
685}
686
687
696static int
697free_item (void *cls, const struct GNUNET_HashCode *key, void *value)
698{
699 struct WorkItem *wi = value;
700
701 GNUNET_free (wi->filename);
702 GNUNET_free (wi);
703 return GNUNET_OK;
704}
705
706
714int
715main (int argc, char *const *argv)
716{
719 "anonymity",
720 "LEVEL",
722 "set the desired LEVEL of sender-anonymity"),
724
726 'd',
727 "disable-creation-time",
729 "disable adding the creation time to the metadata of the uploaded file")
730 ,
732
734 'D',
735 "disable-extractor",
736 gettext_noop ("do not use libextractor to add keywords or metadata"),
738
740 "priority",
741 "PRIORITY",
743 "specify the priority of the content"),
745
747 "replication",
748 "LEVEL",
750 "set the desired replication LEVEL"),
752
754
756 };
757 struct WorkItem *wi;
758 int ok;
760
762 GNUNET_assert (NULL != sigpipe);
763 shc_chld =
765 ok =
766 (GNUNET_OK ==
769 argc,
770 argv,
771 "gnunet-auto-share [OPTIONS] FILENAME",
772 gettext_noop ("Automatically publish files from a directory on GNUnet"),
773 options,
774 &run,
775 NULL))
776 ? ret
777 : 1;
778 if (NULL != work_finished)
779 {
781 &free_item,
782 NULL);
784 }
785 while (NULL != (wi = work_head))
786 {
788 GNUNET_free (wi->filename);
789 GNUNET_free (wi);
790 }
792 shc_chld = NULL;
794 sigpipe = NULL;
796 cfg_filename = NULL;
797 return ok;
798}
799
800
801/* end of gnunet-auto-share.c */
struct GNUNET_GETOPT_CommandLineOption options[]
Definition 002.c:5
static struct GNUNET_SIGNAL_Context * shc_chld
int main()
Program to simulate results from GCP_get_desirability_of_path() for various plausible inputs.
#define gettext_noop(String)
Definition gettext.h:74
static struct GNUNET_SCHEDULER_Task * run_task
Handle for the main task that does scanning and working.
static int disable_extractor
Disable extractor option to use for publishing.
static unsigned int verbose
Are we running 'verbosely'?
static int do_shutdown
Set to GNUNET_YES if we are shutting down.
static struct WorkItem * work_head
Head of linked list of files still to publish.
#define MAX_DELAY
static void load_state()
Load the set of work_finished items from disk.
static const char * dir_name
Top-level directory we monitor to auto-publish.
static unsigned int content_priority
Content priority option to use for publishing.
static int do_disable_creation_time
Disable creation time option to use for publishing.
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...
static void schedule_next_task(void)
Decide what the next task is (working or scanning) and schedule it.
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.
static struct GNUNET_CONTAINER_MultiHashMap * work_finished
Map from the hash of the filename (!) to a struct WorkItem that was finished.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
static char * get_state_file()
Compute the name of the state database file we will use.
static char * cfg_filename
Name of the configuration file.
static void maint_child_death(void *cls)
Task triggered whenever we receive a SIGCHLD (child process died).
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 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...
static void scan(void *cls)
Periodically run task to update our view of the directory to share.
static int ret
Global return value from 'main'.
static struct WorkItem * work_tail
Tail of linked list of files still to publish.
static unsigned int anonymity_level
Anonymity level option to use for publishing.
static struct GNUNET_Process * publish_proc
Handle to the 'gnunet-publish' process that we executed.
static struct GNUNET_DISK_PipeHandle * sigpipe
Pipe used to communicate 'gnunet-publish' completion (SIGCHLD) via signal.
static void sighandler_child_death()
Signal handler called for SIGCHLD.
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.
static unsigned int replication_level
Replication level option to use for publishing.
static void do_stop_task(void *cls)
Task run on shutdown.
static void save_state()
Save the set of work_finished items on disk.
#define MIN_DELAY
static void work(void *cls)
Function called to process work items.
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.
struct GNUNET_HashCode key
The key used in the DHT.
static char * filename
static struct GNUNET_IDENTITY_Handle * id
Handle to IDENTITY.
static char * value
Value of the record to add/remove.
static uint32_t type
Type string converted to DNS type value.
enum GNUNET_GenericReturnValue GNUNET_BIO_write_close(struct GNUNET_BIO_WriteHandle *h, char **emsg)
Close an IO handle.
Definition bio.c:556
struct GNUNET_BIO_ReadSpec GNUNET_BIO_read_spec_string(const char *what, char **result, size_t max_length)
Create the specification to read a 0-terminated string.
Definition bio.c:954
struct GNUNET_BIO_WriteHandle * GNUNET_BIO_write_open_file(const char *fn)
Open a file for writing.
Definition bio.c:508
enum GNUNET_GenericReturnValue GNUNET_BIO_write_int32(struct GNUNET_BIO_WriteHandle *h, const char *what, int32_t i)
Write an (u)int32_t.
Definition bio.c:845
enum GNUNET_GenericReturnValue GNUNET_BIO_read_spec_commit(struct GNUNET_BIO_ReadHandle *h, struct GNUNET_BIO_ReadSpec *rs)
Execute the read specifications in order.
Definition bio.c:1106
struct GNUNET_BIO_ReadSpec GNUNET_BIO_read_spec_object(const char *what, void *result, size_t size)
Create the specification to read a certain amount of bytes.
Definition bio.c:906
struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_string(const char *what, const char *s)
Create the specification to write a 0-terminated string.
Definition bio.c:1199
#define GNUNET_BIO_read_spec_end()
End of specifications marker.
#define GNUNET_BIO_write_spec_end()
End of specifications marker.
struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_object(const char *what, void *source, size_t size)
Create the specification to read some bytes.
Definition bio.c:1152
enum GNUNET_GenericReturnValue GNUNET_BIO_write_spec_commit(struct GNUNET_BIO_WriteHandle *h, struct GNUNET_BIO_WriteSpec *ws)
Execute the write specifications in order.
Definition bio.c:1357
enum GNUNET_GenericReturnValue GNUNET_BIO_read_close(struct GNUNET_BIO_ReadHandle *h, char **emsg)
Close an open handle.
Definition bio.c:162
enum GNUNET_GenericReturnValue GNUNET_BIO_read_int32(struct GNUNET_BIO_ReadHandle *h, const char *what, int32_t *i)
Read an (u)int32_t.
Definition bio.c:427
struct GNUNET_BIO_ReadHandle * GNUNET_BIO_read_open_file(const char *fn)
Open a file for reading.
Definition bio.c:114
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:1703
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:745
struct GNUNET_DISK_PipeHandle * GNUNET_DISK_pipe(enum GNUNET_DISK_PipeFlags pf)
Creates an interprocess channel.
Definition disk.c:1524
enum GNUNET_GenericReturnValue GNUNET_DISK_pipe_close(struct GNUNET_DISK_PipeHandle *p)
Closes an interprocess channel.
Definition disk.c:1671
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition disk.c:466
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:704
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition disk.c:881
@ GNUNET_DISK_PF_NONE
No special options, use non-blocking read/write operations.
@ GNUNET_DISK_PIPE_END_WRITE
The writing-end of a pipe.
@ GNUNET_DISK_PIPE_END_READ
The reading-end of a pipe.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
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_GETOPT_OPTION_END
Marker for the end of the list of options.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_verbose(unsigned int *level)
Define the '-V' verbosity option.
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.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition crypto_hash.c:41
void GNUNET_CRYPTO_hash_xor(const struct GNUNET_HashCode *a, const struct GNUNET_HashCode *b, struct GNUNET_HashCode *result)
compute result = a ^ b
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
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.
enum GNUNET_GenericReturnValue 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.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
unsigned int GNUNET_CONTAINER_multihashmap_size(const struct GNUNET_CONTAINER_MultiHashMap *map)
Get the number of key-value pairs in the map.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY
There must only be one value per key; storing a value should fail if a value under the same key alrea...
#define GNUNET_log(kind,...)
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
@ GNUNET_SCHEDULER_PRIORITY_IDLE
Run when otherwise idle.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_ERROR_TYPE_INFO
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
int GNUNET_snprintf(char *buf, size_t size, const char *format,...) __attribute__((format(printf
Like snprintf, just aborts if the buffer is of insufficient size.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
enum GNUNET_GenericReturnValue GNUNET_process_run_command_argv(struct GNUNET_Process *p, const char *filename, const char **argv)
Set the command and start a process.
Definition os_process.c:840
enum GNUNET_GenericReturnValue GNUNET_process_wait(struct GNUNET_Process *proc, bool blocking, enum GNUNET_OS_ProcessStatusType *type, unsigned long *code)
Wait for a process to terminate.
void GNUNET_process_destroy(struct GNUNET_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition os_process.c:363
GNUNET_OS_ProcessStatusType
Process status types.
enum GNUNET_GenericReturnValue GNUNET_process_kill(struct GNUNET_Process *proc, int sig)
Sends a signal to the process.
Definition os_process.c:307
struct GNUNET_Process * GNUNET_process_create(enum GNUNET_OS_InheritStdioFlags std_inheritance)
Create a process handle.
Definition os_process.c:462
@ GNUNET_OS_USE_PIPE_CONTROL
Should a pipe be used to send signals to the child?
@ GNUNET_OS_PROCESS_EXITED
The process exited with a return code.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(const struct GNUNET_OS_ProjectData *pd, 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,...
Definition program.c:407
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:1667
const struct GNUNET_SCHEDULER_TaskContext * GNUNET_SCHEDULER_get_task_context(void)
Obtain the reasoning why the current task was started.
Definition scheduler.c:764
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,...
Definition scheduler.c:1345
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:986
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:1310
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:1283
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:1237
@ GNUNET_SCHEDULER_REASON_READ_READY
The reading socket is ready.
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:52
void GNUNET_SIGNAL_handler_uninstall(struct GNUNET_SIGNAL_Context *ctx)
Uninstall a previously installed signal handler.
Definition signal.c:78
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:344
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
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:438
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:529
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:352
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition time.c:111
#define GNUNET_TIME_UNIT_MINUTES
One minute.
#define DIR_SEPARATOR
Definition platform.h:166
#define DIR_SEPARATOR_STR
Definition platform.h:167
#define _(String)
GNU gettext support macro.
Definition platform.h:179
#define GNUNET_SIGCHLD
Definition platform.h:42
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
Definition scheduler.c:436
Handle for buffered reading.
Definition bio.c:69
Structure specifying a reading operation on an IO handle.
void * cls
Closure for rh.
GNUNET_BIO_ReadHandler rh
Function performing data deserialization.
Handle for buffered writing.
Definition bio.c:466
Structure specifying a writing operation on an IO handle.
GNUNET_BIO_WriteHandler wh
Function performing data serialization.
Internal representation of the hash map.
Handle used to access files (and pipes).
Handle used to manage a pipe.
Definition disk.c:69
Definition of a command line option.
A 512-bit hashcode.
Context information passed to each scheduler task.
enum GNUNET_SCHEDULER_Reason reason
Reason why the task is run now.
Entry in list of pending tasks.
Definition scheduler.c:141
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.
Item in our work queue (or in the set of files/directories we have successfully published).
char * filename
Filename of the work item.
struct WorkItem * prev
PENDING Work is kept in a linked list.
struct WorkItem * next
PENDING Work is kept in a linked list.
struct GNUNET_HashCode id
Unique identity for this work item (used to detect if we need to do the work again).