automatically publish files on GNUnet More...
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_Handle * | cfg |
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_Task * | run_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 WorkItem * | work_head |
Head of linked list of files still to publish. More... | |
static struct WorkItem * | work_tail |
Tail of linked list of files still to publish. More... | |
static struct GNUNET_CONTAINER_MultiHashMap * | work_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_PipeHandle * | sigpipe |
Pipe used to communicate 'gnunet-publish' completion (SIGCHLD) via signal. More... | |
static struct GNUNET_OS_Process * | publish_proc |
Handle to the 'gnunet-publish' process that we executed. More... | |
automatically publish files on GNUnet
TODO:
Definition in file gnunet-auto-share.c.
#define MAX_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4) |
Definition at line 32 of file gnunet-auto-share.c.
#define MIN_DELAY GNUNET_TIME_UNIT_MINUTES |
Definition at line 34 of file gnunet-auto-share.c.
|
static |
Compute the name of the state database file we will use.
Definition at line 164 of file gnunet-auto-share.c.
References dir_name, DIR_SEPARATOR, DIR_SEPARATOR_STR, and GNUNET_asprintf().
Referenced by load_state(), and save_state().
|
static |
Load the set of work_finished items from disk.
Definition at line 182 of file gnunet-auto-share.c.
References _, WorkItem::filename, get_state_file(), GNUNET_BIO_read_close(), GNUNET_BIO_read_int32(), GNUNET_BIO_read_open_file(), GNUNET_BIO_read_spec_commit(), GNUNET_BIO_read_spec_end, GNUNET_BIO_read_spec_object(), GNUNET_BIO_read_spec_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_h2s(), GNUNET_log, GNUNET_new, GNUNET_OK, WorkItem::id, id, GNUNET_BIO_ReadSpec::rh, and work_finished.
Referenced by run().
|
static |
Write work item from the work_finished map to the given write handle.
cls | the struct GNUNET_BIO_WriteHandle * |
key | key of the item in the map (unused) |
value | the struct WorkItem to write |
Definition at line 249 of file gnunet-auto-share.c.
References WorkItem::filename, GNUNET_BIO_write_spec_commit(), GNUNET_BIO_write_spec_end, GNUNET_BIO_write_spec_object(), GNUNET_BIO_write_spec_string(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_OK, GNUNET_SYSERR, WorkItem::id, value, and GNUNET_BIO_WriteSpec::wh.
Referenced by save_state().
|
static |
Save the set of work_finished items on disk.
Definition at line 275 of file gnunet-auto-share.c.
References _, get_state_file(), GNUNET_BIO_write_close(), GNUNET_BIO_write_int32(), GNUNET_BIO_write_open_file(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_CONTAINER_multihashmap_size(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_OK, work_finished, and write_item().
Referenced by maint_child_death().
|
static |
Task run on shutdown.
Serializes our current state to disk.
cls | closure, unused |
Definition at line 316 of file gnunet-auto-share.c.
References do_shutdown, GNUNET_OS_process_kill(), GNUNET_SCHEDULER_cancel(), GNUNET_YES, publish_proc, and run_task.
Referenced by run().
|
static |
Decide what the next task is (working or scanning) and schedule it.
Definition at line 619 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, run_task, scan(), start_time, work(), and work_head.
Referenced by maint_child_death(), and scan().
|
static |
Task triggered whenever we receive a SIGCHLD (child process died).
cls | the struct WorkItem we were working on |
Definition at line 346 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, key, maint_child_death(), publish_proc, GNUNET_SCHEDULER_TaskContext::reason, run_task, save_state(), schedule_next_task(), sigpipe, tc, type, work_finished, work_head, and work_tail.
Referenced by maint_child_death(), and work().
|
static |
Signal handler called for SIGCHLD.
Triggers the respective handler by writing to the trigger pipe.
Definition at line 425 of file gnunet-auto-share.c.
References GNUNET_break, GNUNET_DISK_file_write(), GNUNET_DISK_PIPE_END_WRITE, GNUNET_DISK_pipe_handle(), and sigpipe.
Referenced by main().
|
static |
Function called to process work items.
cls | closure, NULL |
Definition at line 447 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_OS_USE_PIPE_CONTROL, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_add_read_file(), GNUNET_snprintf(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TIME_UNIT_MINUTES, maint_child_death(), publish_proc, replication_level, run_task, sigpipe, verbose, work(), work_head, and work_tail.
Referenced by dns_post_request_handler(), schedule_next_task(), and work().
|
static |
Recursively scan the given file/directory structure to determine a unique ID that represents the current state of the hierarchy.
cls | where to store the unique ID we are computing |
filename | file to scan |
Definition at line 516 of file gnunet-auto-share.c.
References determine_id(), filename, 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(), and determine_id().
|
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.
cls | closure, NULL |
filename | complete filename (absolute path) |
Definition at line 563 of file gnunet-auto-share.c.
References determine_id(), do_shutdown, WorkItem::filename, 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, WorkItem::id, id, key, work_finished, work_head, and work_tail.
Referenced by scan().
|
static |
Periodically run task to update our view of the directory to share.
cls | NULL |
Definition at line 606 of file gnunet-auto-share.c.
References add_file(), dir_name, GNUNET_DISK_directory_scan(), GNUNET_TIME_absolute_get(), run_task, schedule_next_task(), and start_time.
Referenced by run(), and schedule_next_task().
|
static |
Main function that will be run by the scheduler.
cls | closure |
args | remaining command-line arguments |
cfgfile | name of the configuration file used (for saving, can be NULL!) |
c | configuration |
Definition at line 652 of file gnunet-auto-share.c.
References _, consensus-simulation::args, cfg, 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, run_task, scan(), and work_finished.
Referenced by main().
|
static |
Free memory associated with the work item from the work_finished map.
cls | NULL (unused) |
key | key of the item in the map (unused) |
value | the struct WorkItem to free |
Definition at line 687 of file gnunet-auto-share.c.
References WorkItem::filename, GNUNET_free, GNUNET_OK, and value.
Referenced by main().
int main | ( | int | argc, |
char *const * | argv | ||
) |
The main function to automatically publish content to GNUnet.
argc | number of arguments from the command line |
argv | command line arguments |
Definition at line 705 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_PF_NONE, GNUNET_DISK_pipe(), GNUNET_DISK_pipe_close(), GNUNET_free, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_flag(), GNUNET_GETOPT_option_uint(), GNUNET_GETOPT_option_verbose(), GNUNET_OK, GNUNET_OS_project_data_gnunet(), GNUNET_PROGRAM_run(), GNUNET_SIGCHLD, GNUNET_SIGNAL_handler_install(), GNUNET_SIGNAL_handler_uninstall(), options, replication_level, ret, run(), shc_chld, sighandler_child_death(), sigpipe, verbose, work_finished, work_head, and work_tail.
|
static |
Global return value from 'main'.
Definition at line 69 of file gnunet-auto-share.c.
|
static |
Are we running 'verbosely'?
Definition at line 74 of file gnunet-auto-share.c.
|
static |
|
static |
Name of the configuration file.
Definition at line 84 of file gnunet-auto-share.c.
Referenced by GNUNET_DISK_purge_cfg_dir(), GNUNET_PROGRAM_conf_and_options(), GNUNET_SERVICE_run_(), GNUNET_TRANSPORT_TESTING_transport_communicator_service_start(), main(), run(), and work().
|
static |
Disable extractor option to use for publishing.
Definition at line 89 of file gnunet-auto-share.c.
Referenced by GNUNET_FS_directory_scan_start(), main(), and work().
|
static |
Disable creation time option to use for publishing.
Definition at line 94 of file gnunet-auto-share.c.
|
static |
Handle for the main task that does scanning and working.
Definition at line 99 of file gnunet-auto-share.c.
Referenced by do_stop_task(), maint_child_death(), run(), scan(), schedule_next_task(), and work().
|
static |
Anonymity level option to use for publishing.
Definition at line 104 of file gnunet-auto-share.c.
Referenced by GSF_pending_request_create_(), main(), and work().
|
static |
Content priority option to use for publishing.
Definition at line 109 of file gnunet-auto-share.c.
|
static |
Replication level option to use for publishing.
Definition at line 114 of file gnunet-auto-share.c.
Referenced by check_dht_local_put(), handle_dht_local_put(), main(), and work().
|
static |
Top-level directory we monitor to auto-publish.
Definition at line 119 of file gnunet-auto-share.c.
Referenced by get_state_file(), GNUNET_DISK_directory_scan(), run(), and scan().
|
static |
Head of linked list of files still to publish.
Definition at line 124 of file gnunet-auto-share.c.
Referenced by add_file(), main(), maint_child_death(), schedule_next_task(), and work().
|
static |
Tail of linked list of files still to publish.
Definition at line 129 of file gnunet-auto-share.c.
Referenced by add_file(), main(), maint_child_death(), and work().
|
static |
Map from the hash of the filename (!) to a struct WorkItem
that was finished.
Definition at line 135 of file gnunet-auto-share.c.
Referenced by add_file(), load_state(), main(), maint_child_death(), run(), and save_state().
|
static |
Set to GNUNET_YES if we are shutting down.
Definition at line 140 of file gnunet-auto-share.c.
Referenced by add_file(), do_stop_task(), maint_child_death(), and schedule_next_task().
|
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 147 of file gnunet-auto-share.c.
Referenced by run(), scan(), and schedule_next_task().
|
static |
Pipe used to communicate 'gnunet-publish' completion (SIGCHLD) via signal.
Definition at line 152 of file gnunet-auto-share.c.
Referenced by main(), maint_child_death(), sighandler_child_death(), and work().
|
static |
Handle to the 'gnunet-publish' process that we executed.
Definition at line 157 of file gnunet-auto-share.c.
Referenced by do_stop_task(), maint_child_death(), and work().