aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-download.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/gnunet-download.c')
-rw-r--r--src/fs/gnunet-download.c120
1 files changed, 115 insertions, 5 deletions
diff --git a/src/fs/gnunet-download.c b/src/fs/gnunet-download.c
index c6bb7c115..681608d6b 100644
--- a/src/fs/gnunet-download.c
+++ b/src/fs/gnunet-download.c
@@ -26,21 +26,26 @@
26 * @author Igor Wronsky 26 * @author Igor Wronsky
27 * 27 *
28 * TODO: 28 * TODO:
29 * - all 29 * - many command-line options
30 */ 30 */
31#include "platform.h" 31#include "platform.h"
32#include "gnunet_fs_service.h" 32#include "gnunet_fs_service.h"
33 33
34static int ret; 34static int ret;
35 35
36static int verbose;
37
38static int delete_incomplete;
39
36static const struct GNUNET_CONFIGURATION_Handle *cfg; 40static const struct GNUNET_CONFIGURATION_Handle *cfg;
37 41
38static struct GNUNET_FS_Handle *ctx; 42static struct GNUNET_FS_Handle *ctx;
39 43
40static struct GNUNET_TIME_Absolute start_time; 44static struct GNUNET_FS_DownloadContext *dc;
41 45
42static unsigned int anonymity = 1; 46static unsigned int anonymity = 1;
43 47
48static char *filename;
44 49
45/** 50/**
46 * Called by FS client to give information about the progress of an 51 * Called by FS client to give information about the progress of an
@@ -59,6 +64,44 @@ static void *
59progress_cb (void *cls, 64progress_cb (void *cls,
60 const struct GNUNET_FS_ProgressInfo *info) 65 const struct GNUNET_FS_ProgressInfo *info)
61{ 66{
67 switch (info->status)
68 {
69 case GNUNET_FS_STATUS_DOWNLOAD_START:
70 break;
71 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
72 if (verbose)
73 fprintf (stdout,
74 _("Downloading `%s' at %llu/%llu (%s remaining, %s/s)\n"),
75 info->value.download.filename,
76 (unsigned long long) info->value.download.completed,
77 (unsigned long long) info->value.download.length,
78 GNUNET_STRINGS_relative_time_to_string(info->value.download.eta),
79 GNUNET_STRINGS_byte_size_fancy(info->value.download.completed * 1000 / (info->value.download.duration.value + 1)));
80 break;
81 case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
82 fprintf (stderr,
83 _("Error downloading: %s.\n"),
84 info->value.download.specifics.error.message);
85 GNUNET_FS_file_download_stop (dc, delete_incomplete);
86 break;
87 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
88 fprintf (stdout,
89 _("Downloading `%s' done (%s/s).\n"),
90 info->value.download.filename,
91 GNUNET_STRINGS_byte_size_fancy(info->value.download.completed * 1000 / (info->value.download.duration.value + 1)));
92 if (info->value.download.dc == dc)
93 GNUNET_FS_file_download_stop (dc, delete_incomplete);
94 break;
95 case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
96 if (info->value.download.dc == dc)
97 GNUNET_FS_stop (ctx);
98 break;
99 default:
100 fprintf (stderr,
101 _("Unexpected status: %d\n"),
102 info->status);
103 break;
104 }
62 return NULL; 105 return NULL;
63} 106}
64 107
@@ -79,23 +122,66 @@ run (void *cls,
79 const char *cfgfile, 122 const char *cfgfile,
80 const struct GNUNET_CONFIGURATION_Handle *c) 123 const struct GNUNET_CONFIGURATION_Handle *c)
81{ 124{
125 struct GNUNET_FS_Uri *uri;
126 char *emsg;
127 enum GNUNET_FS_DownloadOptions options;
128
82 /* FIXME: check arguments */ 129 /* FIXME: check arguments */
130 uri = GNUNET_FS_uri_parse (args[0],
131 &emsg);
132 if (NULL == uri)
133 {
134 fprintf (stderr,
135 _("Failed to parse URI: %s\n"),
136 emsg);
137 GNUNET_free (emsg);
138 ret = 1;
139 return;
140 }
141 if (! GNUNET_FS_uri_test_chk (uri))
142 {
143 fprintf (stderr,
144 "Only CHK URIs supported right now.\n");
145 ret = 1;
146 GNUNET_FS_uri_destroy (uri);
147 return;
148 }
149 if (NULL == filename)
150 {
151 fprintf (stderr,
152 "Target filename must be specified.\n");
153 ret = 1;
154 GNUNET_FS_uri_destroy (uri);
155 return;
156 }
83 cfg = c; 157 cfg = c;
84 ctx = GNUNET_FS_start (sched, 158 ctx = GNUNET_FS_start (sched,
85 cfg, 159 cfg,
86 "gnunet-download", 160 "gnunet-download",
87 &progress_cb, 161 &progress_cb,
88 NULL); 162 NULL,
163 GNUNET_FS_FLAGS_NONE,
164 GNUNET_FS_OPTIONS_END);
89 if (NULL == ctx) 165 if (NULL == ctx)
90 { 166 {
91 fprintf (stderr, 167 fprintf (stderr,
92 _("Could not initialize `%s' subsystem.\n"), 168 _("Could not initialize `%s' subsystem.\n"),
93 "FS"); 169 "FS");
170 GNUNET_FS_uri_destroy (uri);
94 ret = 1; 171 ret = 1;
95 return; 172 return;
96 } 173 }
97 start_time = GNUNET_TIME_absolute_get (); 174 options = GNUNET_FS_DOWNLOAD_OPTION_NONE;
98 // FIXME: start download 175 dc = GNUNET_FS_file_download_start (ctx,
176 uri,
177 NULL,
178 filename,
179 0,
180 GNUNET_FS_uri_chk_get_file_size (uri),
181 anonymity,
182 options,
183 NULL);
184 GNUNET_FS_uri_destroy (uri);
99} 185}
100 186
101 187
@@ -106,7 +192,31 @@ static struct GNUNET_GETOPT_CommandLineOption options[] = {
106 {'a', "anonymity", "LEVEL", 192 {'a', "anonymity", "LEVEL",
107 gettext_noop ("set the desired LEVEL of receiver-anonymity"), 193 gettext_noop ("set the desired LEVEL of receiver-anonymity"),
108 1, &GNUNET_GETOPT_set_uint, &anonymity}, 194 1, &GNUNET_GETOPT_set_uint, &anonymity},
195#if 0
109 // FIXME: options! 196 // FIXME: options!
197 {'d', "directory", NULL,
198 gettext_noop
199 ("download a GNUnet directory that has already been downloaded. Requires that a filename of an existing file is specified instead of the URI. The download will only download the top-level files in the directory unless the `-R' option is also specified."),
200 0, &GNUNET_getopt_configure_set_one, &do_directory},
201 {'D', "delete-incomplete", NULL,
202 gettext_noop ("delete incomplete downloads (when aborted with CTRL-C)"),
203 0, &GNUNET_getopt_configure_set_one, &do_delete_incomplete},
204#endif
205 {'o', "output", "FILENAME",
206 gettext_noop ("write the file to FILENAME"),
207 1, &GNUNET_GETOPT_set_string, &filename},
208#if 0
209 {'p', "parallelism", "DOWNLOADS",
210 gettext_noop
211 ("set the maximum number of parallel downloads that are allowed"),
212 1, &GNUNET_getopt_configure_set_uint, &parallelism},
213 {'R', "recursive", NULL,
214 gettext_noop ("download a GNUnet directory recursively"),
215 0, &GNUNET_getopt_configure_set_one, &do_recursive},
216#endif
217 {'V', "verbose", NULL,
218 gettext_noop ("be verbose (print progress information)"),
219 0, &GNUNET_GETOPT_set_one, &verbose},
110 GNUNET_GETOPT_OPTION_END 220 GNUNET_GETOPT_OPTION_END
111}; 221};
112 222