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.c111
1 files changed, 68 insertions, 43 deletions
diff --git a/src/fs/gnunet-download.c b/src/fs/gnunet-download.c
index 5279ce459..63895d4b2 100644
--- a/src/fs/gnunet-download.c
+++ b/src/fs/gnunet-download.c
@@ -26,7 +26,7 @@
26 * @author Igor Wronsky 26 * @author Igor Wronsky
27 * 27 *
28 * TODO: 28 * TODO:
29 * - many command-line options 29 * - download-directory option support (do_directory)
30 */ 30 */
31#include "platform.h" 31#include "platform.h"
32#include "gnunet_fs_service.h" 32#include "gnunet_fs_service.h"
@@ -47,6 +47,12 @@ static struct GNUNET_FS_DownloadContext *dc;
47 47
48static unsigned int anonymity = 1; 48static unsigned int anonymity = 1;
49 49
50static unsigned int parallelism = 16;
51
52static int do_recursive;
53
54static int do_directory;
55
50static char *filename; 56static char *filename;
51 57
52 58
@@ -127,8 +133,15 @@ progress_cb (void *cls,
127 info->value.download.filename, 133 info->value.download.filename,
128 s); 134 s);
129 GNUNET_free (s); 135 GNUNET_free (s);
130 if (info->value.download.dc == dc) 136 if (do_directory)
131 GNUNET_SCHEDULER_shutdown (sched); 137 {
138 GNUNET_break (0); //FIXME: not implemented
139 }
140 else
141 {
142 if (info->value.download.dc == dc)
143 GNUNET_SCHEDULER_shutdown (sched);
144 }
132 break; 145 break;
133 case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: 146 case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
134 if (info->value.download.dc == dc) 147 if (info->value.download.dc == dc)
@@ -168,25 +181,31 @@ run (void *cls,
168 enum GNUNET_FS_DownloadOptions options; 181 enum GNUNET_FS_DownloadOptions options;
169 182
170 sched = s; 183 sched = s;
171 /* FIXME: check arguments */ 184 if (do_directory)
172 uri = GNUNET_FS_uri_parse (args[0],
173 &emsg);
174 if (NULL == uri)
175 { 185 {
176 fprintf (stderr, 186 GNUNET_break (0); //FIXME: not implemented
177 _("Failed to parse URI: %s\n"),
178 emsg);
179 GNUNET_free (emsg);
180 ret = 1;
181 return;
182 } 187 }
183 if (! GNUNET_FS_uri_test_chk (uri)) 188 else
184 { 189 {
185 fprintf (stderr, 190 uri = GNUNET_FS_uri_parse (args[0],
186 "Only CHK URIs supported right now.\n"); 191 &emsg);
187 ret = 1; 192 if (NULL == uri)
188 GNUNET_FS_uri_destroy (uri); 193 {
189 return; 194 fprintf (stderr,
195 _("Failed to parse URI: %s\n"),
196 emsg);
197 GNUNET_free (emsg);
198 ret = 1;
199 return;
200 }
201 if (! GNUNET_FS_uri_test_chk (uri))
202 {
203 fprintf (stderr,
204 "Only CHK URIs supported right now.\n");
205 ret = 1;
206 GNUNET_FS_uri_destroy (uri);
207 return;
208 }
190 } 209 }
191 if (NULL == filename) 210 if (NULL == filename)
192 { 211 {
@@ -203,6 +222,8 @@ run (void *cls,
203 &progress_cb, 222 &progress_cb,
204 NULL, 223 NULL,
205 GNUNET_FS_FLAGS_NONE, 224 GNUNET_FS_FLAGS_NONE,
225 GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM,
226 parallelism,
206 GNUNET_FS_OPTIONS_END); 227 GNUNET_FS_OPTIONS_END);
207 if (NULL == ctx) 228 if (NULL == ctx)
208 { 229 {
@@ -214,22 +235,31 @@ run (void *cls,
214 return; 235 return;
215 } 236 }
216 options = GNUNET_FS_DOWNLOAD_OPTION_NONE; 237 options = GNUNET_FS_DOWNLOAD_OPTION_NONE;
217 dc = GNUNET_FS_download_start (ctx, 238 if (do_recursive)
218 uri, 239 options |= GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE;
219 NULL, 240 if (do_directory)
220 filename,
221 0,
222 GNUNET_FS_uri_chk_get_file_size (uri),
223 anonymity,
224 options,
225 NULL,
226 NULL);
227 GNUNET_FS_uri_destroy (uri);
228 if (dc == NULL)
229 { 241 {
230 GNUNET_FS_stop (ctx); 242 GNUNET_break (0); //FIXME: not implemented
231 ctx = NULL; 243 }
232 return; 244 else
245 {
246 dc = GNUNET_FS_download_start (ctx,
247 uri,
248 NULL,
249 filename,
250 0,
251 GNUNET_FS_uri_chk_get_file_size (uri),
252 anonymity,
253 options,
254 NULL,
255 NULL);
256 GNUNET_FS_uri_destroy (uri);
257 if (dc == NULL)
258 {
259 GNUNET_FS_stop (ctx);
260 ctx = NULL;
261 return;
262 }
233 } 263 }
234 GNUNET_SCHEDULER_add_delayed (sched, 264 GNUNET_SCHEDULER_add_delayed (sched,
235 GNUNET_TIME_UNIT_FOREVER_REL, 265 GNUNET_TIME_UNIT_FOREVER_REL,
@@ -245,28 +275,23 @@ static struct GNUNET_GETOPT_CommandLineOption options[] = {
245 {'a', "anonymity", "LEVEL", 275 {'a', "anonymity", "LEVEL",
246 gettext_noop ("set the desired LEVEL of receiver-anonymity"), 276 gettext_noop ("set the desired LEVEL of receiver-anonymity"),
247 1, &GNUNET_GETOPT_set_uint, &anonymity}, 277 1, &GNUNET_GETOPT_set_uint, &anonymity},
248#if 0
249 // FIXME: options!
250 {'d', "directory", NULL, 278 {'d', "directory", NULL,
251 gettext_noop 279 gettext_noop
252 ("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."), 280 ("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."),
253 0, &GNUNET_getopt_configure_set_one, &do_directory}, 281 0, &GNUNET_GETOPT_set_one, &do_directory},
254 {'D', "delete-incomplete", NULL, 282 {'D', "delete-incomplete", NULL,
255 gettext_noop ("delete incomplete downloads (when aborted with CTRL-C)"), 283 gettext_noop ("delete incomplete downloads (when aborted with CTRL-C)"),
256 0, &GNUNET_getopt_configure_set_one, &do_delete_incomplete}, 284 0, &GNUNET_GETOPT_set_one, &delete_incomplete},
257#endif
258 {'o', "output", "FILENAME", 285 {'o', "output", "FILENAME",
259 gettext_noop ("write the file to FILENAME"), 286 gettext_noop ("write the file to FILENAME"),
260 1, &GNUNET_GETOPT_set_string, &filename}, 287 1, &GNUNET_GETOPT_set_string, &filename},
261#if 0
262 {'p', "parallelism", "DOWNLOADS", 288 {'p', "parallelism", "DOWNLOADS",
263 gettext_noop 289 gettext_noop
264 ("set the maximum number of parallel downloads that are allowed"), 290 ("set the maximum number of parallel downloads that are allowed"),
265 1, &GNUNET_getopt_configure_set_uint, &parallelism}, 291 1, &GNUNET_GETOPT_set_uint, &parallelism},
266 {'R', "recursive", NULL, 292 {'R', "recursive", NULL,
267 gettext_noop ("download a GNUnet directory recursively"), 293 gettext_noop ("download a GNUnet directory recursively"),
268 0, &GNUNET_getopt_configure_set_one, &do_recursive}, 294 0, &GNUNET_GETOPT_set_one, &do_recursive},
269#endif
270 {'V', "verbose", NULL, 295 {'V', "verbose", NULL,
271 gettext_noop ("be verbose (print progress information)"), 296 gettext_noop ("be verbose (print progress information)"),
272 0, &GNUNET_GETOPT_set_one, &verbose}, 297 0, &GNUNET_GETOPT_set_one, &verbose},