GNUnet  0.20.0
gnunet-download.c File Reference

downloading for files on GNUnet More...

#include "platform.h"
#include "gnunet_fs_service.h"
Include dependency graph for gnunet-download.c:

Go to the source code of this file.


static void cleanup_task (void *cls)
static void shutdown_task (void *cls)
static void display_bar (unsigned long long x, unsigned long long n, unsigned int w)
 Display progress bar (if tty). More...
static void * progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
 Called by FS client to give information about the progress of an operation. 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...
int main (int argc, char *const *argv)
 The main function to download GNUnet. More...


static int ret
static unsigned int verbose
static int delete_incomplete
static const struct GNUNET_CONFIGURATION_Handlecfg
static struct GNUNET_FS_Handlectx
static struct GNUNET_FS_DownloadContextdc
static unsigned int anonymity = 1
static unsigned int parallelism = 16
static unsigned int request_parallelism = 4092
static int do_recursive
static char * filename
static int local_only

Detailed Description

downloading for files on GNUnet

Christian Grothoff
Krista Bennett
James Blackwell
Igor Wronsky

Definition in file gnunet-download.c.

Function Documentation

◆ cleanup_task()

static void cleanup_task ( void *  cls)

Definition at line 58 of file gnunet-download.c.

59 {
61  ctx = NULL;
62 }
static struct GNUNET_FS_Handle * ctx
void GNUNET_FS_stop(struct GNUNET_FS_Handle *h)
Close our connection with the file-sharing service.
Definition: fs_api.c:3310

References ctx, and GNUNET_FS_stop().

Referenced by progress_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shutdown_task()

static void shutdown_task ( void *  cls)

Definition at line 66 of file gnunet-download.c.

67 {
68  if (NULL != dc)
69  {
71  dc = NULL;
72  }
73 }
static struct GNUNET_FS_DownloadContext * dc
static int delete_incomplete
void GNUNET_FS_download_stop(struct GNUNET_FS_DownloadContext *dc, int do_delete)
Stop a download (aborts if download is incomplete).
Definition: fs_download.c:2254

References dc, delete_incomplete, and GNUNET_FS_download_stop().

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ display_bar()

static void display_bar ( unsigned long long  x,
unsigned long long  n,
unsigned int  w 

Display progress bar (if tty).

xcurrent position in the download
ntotal size of the download
wdesired number of steps in the progress bar

Definition at line 84 of file gnunet-download.c.

85 {
86  char buf[w + 20];
87  unsigned int p;
88  unsigned int endeq;
89  float ratio_complete;
91  if (0 == isatty (1))
92  return;
93  ratio_complete = x / (float) n;
94  endeq = ratio_complete * w;
95  GNUNET_snprintf (buf, sizeof(buf), "%3d%% [", (int) (ratio_complete * 100));
96  for (p = 0; p < endeq; p++)
97  strcat (buf, "=");
98  for (p = endeq; p < w; p++)
99  strcat (buf, " ");
100  strcat (buf, "]\r");
101  printf ("%s", buf);
102  fflush (stdout);
103 }
static char buf[2048]
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-uri.c:38
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.

References buf, GNUNET_snprintf(), and p.

Referenced by progress_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ progress_cb()

static void* progress_cb ( void *  cls,
const struct GNUNET_FS_ProgressInfo info 

Called by FS client to give information about the progress of an operation.

infodetails about the event, specifying the event type and various bits about the event
client-context (for the next progress call for this operation; should be set to NULL for SUSPEND and STOPPED events). The value returned will be passed to future callbacks in the respective field in the struct GNUNET_FS_ProgressInfo

Definition at line 120 of file gnunet-download.c.

121 {
122  char *s;
123  const char *s2;
124  char *t;
126  switch (info->status)
127  {
129  if (verbose > 1)
130  fprintf (stderr,
131  _ ("Starting download `%s'.\n"),
132  info->;
133  break;
136  if (verbose)
137  {
138  s = GNUNET_strdup (
139  GNUNET_STRINGS_relative_time_to_string (info->,
140  GNUNET_YES));
141  if (info->
142  .rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
143  s2 = _ ("<unknown time>");
144  else
145  s2 = GNUNET_STRINGS_relative_time_to_string (info->
146  .specifics.progress
147  .block_download_duration,
150  info-> * 1000LL
151  / (info-> + 1));
152  fprintf (
153  stdout,
154  _ (
155  "Downloading `%s' at %llu/%llu (%s remaining, %s/s). Block took %s to download\n"),
156  info->,
157  (unsigned long long) info->,
158  (unsigned long long) info->,
159  s,
160  t,
161  s2);
162  GNUNET_free (s);
163  GNUNET_free (t);
164  }
165  else
166  {
167  display_bar (info->,
168  info->,
169  60);
170  }
171  break;
174  if (0 != isatty (1))
175  fprintf (stdout, "\n");
176  fprintf (stderr,
177  _ ("Error downloading: %s.\n"),
178  info->;
180  break;
184  info-> * 1000
185  / (info-> + 1));
186  if (0 != isatty (1))
187  fprintf (stdout, "\n");
188  fprintf (stdout,
189  _ ("Downloading `%s' done (%s/s).\n"),
190  info->,
191  s);
192  GNUNET_free (s);
193  if (info-> == dc)
195  break;
198  if (info-> == dc)
200  break;
204  break;
206  default:
207  fprintf (stderr, _ ("Unexpected status: %d\n"), info->status);
208  break;
209  }
210  return NULL;
211 }
static unsigned int verbose
static void display_bar(unsigned long long x, unsigned long long n, unsigned int w)
Display progress bar (if tty).
static void cleanup_task(void *cls)
#define info
static struct GNUNET_SCHEDULER_Task * t
Main task.
Notification that this download is no longer actively being pursued (back in the queue).
Notification that this download encountered an error.
Notification that this download completed.
Notification that we have started this download.
Notification about progress with this download.
Notification that this download is now actively being pursued (as opposed to waiting in the queue).
Notification that this download was stopped (final event with respect to this action).
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:562
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:1299
char * GNUNET_STRINGS_byte_size_fancy(unsigned long long size)
Convert a given filesize into a fancy human-readable format.
Definition: strings.c:106
Constant used to specify "forever".
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:569
#define _(String)
GNU gettext support macro.
Definition: platform.h:178


Referenced by run().

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 

Main function that will be run by the scheduler.

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

Definition at line 223 of file gnunet-download.c.

227 {
228  struct GNUNET_FS_Uri *uri;
229  char *emsg;
232  if (NULL == args[0])
233  {
234  fprintf (stderr, "%s", _ ("You need to specify a URI argument.\n"));
235  return;
236  }
237  uri = GNUNET_FS_uri_parse (args[0], &emsg);
238  if (NULL == uri)
239  {
240  fprintf (stderr, _ ("Failed to parse URI: %s\n"), emsg);
241  GNUNET_free (emsg);
242  ret = 1;
243  return;
244  }
246  {
247  fprintf (stderr, "%s", _ ("Only CHK or LOC URIs supported.\n"));
248  ret = 1;
250  return;
251  }
252  if (NULL == filename)
253  {
254  fprintf (stderr, "%s", _ ("Target filename must be specified.\n"));
255  ret = 1;
257  return;
258  }
259  cfg = c;
261  "gnunet-download",
262  &progress_cb,
263  NULL,
266  parallelism,
270  if (NULL == ctx)
271  {
272  fprintf (stderr, _ ("Could not initialize `%s' subsystem.\n"), "FS");
274  ret = 1;
275  return;
276  }
278  if (do_recursive)
280  if (local_only)
283  uri,
284  NULL,
285  filename,
286  NULL,
287  0,
289  anonymity,
290  options,
291  NULL,
292  NULL);
294  if (dc == NULL)
295  {
297  ctx = NULL;
298  return;
299  }
301 }
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
static unsigned int anonymity
static int do_recursive
static const struct GNUNET_CONFIGURATION_Handle * cfg
static void shutdown_task(void *cls)
static int ret
static unsigned int request_parallelism
static void * progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *info)
Called by FS client to give information about the progress of an operation.
static unsigned int parallelism
static int local_only
static char * filename
static struct GNUNET_FS_Uri * uri
Value of URI provided on command-line (when not publishing a file but just creating UBlocks to refer ...
struct GNUNET_FS_Uri * GNUNET_FS_uri_parse(const char *uri, char **emsg)
Convert a UTF-8 String to a URI.
Definition: fs_uri.c:637
Options for downloading.
uint64_t GNUNET_FS_uri_chk_get_file_size(const struct GNUNET_FS_Uri *uri)
What is the size of the file that this URI refers to?
Definition: fs_uri.c:1360
int GNUNET_FS_uri_test_loc(const struct GNUNET_FS_Uri *uri)
Is this a location URI?
Definition: fs_uri.c:1384
void GNUNET_FS_uri_destroy(struct GNUNET_FS_Uri *uri)
Free URI.
Definition: fs_uri.c:677
struct GNUNET_FS_DownloadContext * GNUNET_FS_download_start(struct GNUNET_FS_Handle *h, const struct GNUNET_FS_Uri *uri, const struct GNUNET_FS_MetaData *meta, const char *filename, const char *tempname, uint64_t offset, uint64_t length, uint32_t anonymity, enum GNUNET_FS_DownloadOptions options, void *cctx, struct GNUNET_FS_DownloadContext *parent)
Download parts of a file.
Definition: fs_download.c:2100
struct GNUNET_FS_Handle * GNUNET_FS_start(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *client_name, GNUNET_FS_ProgressCallback upcb, void *upcb_cls, enum GNUNET_FS_Flags flags,...)
Setup a connection to the file-sharing service.
Definition: fs_api.c:3244
int GNUNET_FS_uri_test_chk(const struct GNUNET_FS_Uri *uri)
Is this a file (or directory) URI?
Definition: fs_uri.c:1346
No special flags set.
No options (use defaults for everything).
Do a recursive download (that is, automatically trigger the download of files in directories).
Only download from the local host, do not access remote systems (no P2P)
Select the desired amount of parallelism (this option should be followed by an "unsigned int" giving ...
Last option in the VARARG list.
Maximum number of requests that should be pending at a given point in time (invidivual downloads may ...
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:1334
A Universal Resource Identifier (URI), opaque.
Definition: fs_api.h:167

References _, anonymity, consensus-simulation::args, cfg, ctx, dc, do_recursive, filename, GNUNET_free, GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY, GNUNET_FS_DOWNLOAD_OPTION_NONE, GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE, GNUNET_FS_download_start(), GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM, GNUNET_FS_OPTIONS_END, GNUNET_FS_OPTIONS_REQUEST_PARALLELISM, GNUNET_FS_start(), GNUNET_FS_stop(), GNUNET_FS_uri_chk_get_file_size(), GNUNET_FS_uri_destroy(), GNUNET_FS_uri_parse(), GNUNET_FS_uri_test_chk(), GNUNET_FS_uri_test_loc(), GNUNET_SCHEDULER_add_shutdown(), local_only, options, parallelism, progress_cb(), request_parallelism, ret, shutdown_task(), and uri.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *const *  argv 

The main function to download GNUnet.

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

Definition at line 312 of file gnunet-download.c.

313 {
316  "anonymity",
317  "LEVEL",
318  gettext_noop (
319  "set the desired LEVEL of receiver-anonymity"),
320  &anonymity),
323  'D',
324  "delete-incomplete",
325  gettext_noop ("delete incomplete downloads (when aborted with CTRL-C)"),
329  'n',
330  "no-network",
331  gettext_noop ("only search the local peer (no P2P network search)"),
332  &local_only),
334  "output",
335  "FILENAME",
336  gettext_noop ("write the file to FILENAME"),
337  &filename),
339  'p',
340  "parallelism",
342  gettext_noop (
343  "set the maximum number of parallel downloads that is allowed"),
344  &parallelism),
346  'r',
347  "request-parallelism",
348  "REQUESTS",
349  gettext_noop (
350  "set the maximum number of parallel requests for blocks that is allowed"),
353  "recursive",
354  gettext_noop (
355  "download a GNUnet directory recursively"),
356  &do_recursive),
358  'V',
359  "verbose",
360  gettext_noop ("be verbose (print progress information)"),
361  &verbose),
364  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
365  return 2;
367  ret =
368  (GNUNET_OK ==
370  argc,
371  argv,
372  "gnunet-download [OPTIONS] URI",
373  gettext_noop (
374  "Download files from GNUnet using a GNUnet CHK or LOC URI (gnunet://fs/chk/...)"),
375  options,
376  &run,
377  NULL))
378  ? ret
379  : 1;
380  GNUNET_free_nz ((void *) argv);
381  return ret;
382 }
Definition: 002.c:13
#define gettext_noop(String)
Definition: gettext.h:70
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.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_increment_uint(char shortName, const char *name, const char *description, unsigned int *val)
Increment val each time the option flag is given by one.
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.
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.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_string(char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
Allow user to specify a string.
#define GNUNET_free_nz(ptr)
Wrapper around free.
enum GNUNET_GenericReturnValue 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,...
Definition: program.c:400
enum GNUNET_GenericReturnValue GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1222
Definition of a command line option.

References anonymity, delete_incomplete, do_recursive, filename, gettext_noop, GNUNET_free_nz, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_flag(), GNUNET_GETOPT_option_increment_uint(), GNUNET_GETOPT_option_string(), GNUNET_GETOPT_option_uint(), GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_STRINGS_get_utf8_args(), local_only, options, parallelism, request_parallelism, ret, run(), and verbose.

Here is the call graph for this function:

Variable Documentation

◆ ret

int ret

Definition at line 32 of file gnunet-download.c.

Referenced by main(), and run().

◆ verbose

unsigned int verbose

Definition at line 34 of file gnunet-download.c.

Referenced by main(), and progress_cb().

◆ delete_incomplete

int delete_incomplete

Definition at line 36 of file gnunet-download.c.

Referenced by main(), and shutdown_task().

◆ cfg

const struct GNUNET_CONFIGURATION_Handle* cfg

Definition at line 38 of file gnunet-download.c.

Referenced by run().

◆ ctx

struct GNUNET_FS_Handle* ctx

Definition at line 40 of file gnunet-download.c.

Referenced by cleanup_task(), and run().

◆ dc

◆ anonymity

◆ parallelism

unsigned int parallelism = 16

Definition at line 46 of file gnunet-download.c.

Referenced by adapt_parallelism(), main(), and run().

◆ request_parallelism

unsigned int request_parallelism = 4092

Definition at line 48 of file gnunet-download.c.

Referenced by main(), and run().

◆ do_recursive

int do_recursive

Definition at line 50 of file gnunet-download.c.

Referenced by main(), and run().

◆ filename

char* filename

Definition at line 52 of file gnunet-download.c.

Referenced by add_file(), callback_scan_for_members(), callback_scan_for_operations(), callback_scan_for_rooms(), callback_scan_for_sessions(), check_index_info(), create_download_context(), database_setup(), deserialize_download_file(), deserialize_fi_node(), deserialize_file_information(), deserialize_publish_file(), deserialize_search_file(), deserialize_search_result(), deserialize_subdownload(), deserialize_unindex_file(), determine_id(), directory_scan_cb(), expand_tree(), extract_filename(), file_name_cb(), find_libraries(), gen_topo_from_file(), get_ego_filename(), GNUNET_ATS_solver_logging_write_to_disk(), GNUNET_ATS_solvers_experimentation_load(), GNUNET_CONTAINER_bloomfilter_load(), GNUNET_CRYPTO_hash_file(), GNUNET_FS_add_to_index(), GNUNET_FS_directory_list_contents(), GNUNET_FS_directory_scan_start(), GNUNET_FS_download_start(), GNUNET_FS_download_start_from_search(), GNUNET_FS_file_information_create_empty_directory(), GNUNET_FS_file_information_create_from_file(), GNUNET_FS_file_information_set_filename(), GNUNET_FS_make_file_reader_context_(), GNUNET_FS_remove_sync_file_(), GNUNET_FS_unindex_start(), GNUNET_FS_uri_ksk_create_from_meta_data(), GNUNET_HOSTLIST_client_start(), GNUNET_OS_process_status(), GNUNET_OS_start_process(), GNUNET_OS_start_process_v(), GNUNET_OS_start_process_va(), GNUNET_OS_start_process_vap(), GNUNET_STRINGS_get_short_name(), GNUNET_TESTBED_hosts_load_from_file(), GNUNET_TESTBED_overlay_configure_topology_va(), GNUNET_TESTBED_underlay_construct_(), GNUNET_TESTING_get_topo_from_file(), GNUNET_TRANSPORT_TESTING_get_config_name(), GNUNET_TRANSPORT_TESTING_get_test_name(), GNUNET_TRANSPORT_TESTING_get_test_plugin_name(), GNUNET_TRANSPORT_TESTING_main_(), GNUNET_xgrow_(), GNUNET_xmalloc_(), GNUNET_xmalloc_unchecked_(), GNUNET_xmemdup_(), GNUNET_xnew_array_2d_(), GNUNET_xnew_array_3d_(), GNUNET_xrealloc_(), GNUNET_xstrdup_(), GNUNET_xstrndup_(), handle_index_info(), hosts_directory_scan_callback(), iface_proc(), iter_check_config(), iter_testbed_path(), iterate_save_rooms(), load_file(), load_hostlist_file(), load_message_store(), load_message_store_entries(), load_message_store_links(), load_search_strings(), main(), policy_filename_cb(), preprocess_file(), print_indexed(), print_key(), print_search_result(), process_ego_file(), process_helper_msgs(), progress_cb(), read_from_file(), read_jwk_from_file(), REGEX_TEST_automaton_save_graph(), REGEX_TEST_read_from_file(), remove_sync_file_in_dir(), run(), run_process_and_wait(), save_hostlist_file(), save_message_store(), scan(), scan_callback(), start_process(), trigger_recursive_download(), and write_jwk_to_file().

◆ local_only

int local_only

Definition at line 54 of file gnunet-download.c.

Referenced by main(), and run().