aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-download.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:46:35 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:46:35 +0000
commit502af2167f7c218366666ca4944bd7cc54b5b19a (patch)
treea91fec5cc9769d260640bd91c6633cb9cf395524 /src/fs/gnunet-download.c
parent03af5a603b7cc53432249d5854cd412aa90dde0d (diff)
downloadgnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.tar.gz
gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.zip
indentation
Diffstat (limited to 'src/fs/gnunet-download.c')
-rw-r--r--src/fs/gnunet-download.c235
1 files changed, 107 insertions, 128 deletions
diff --git a/src/fs/gnunet-download.c b/src/fs/gnunet-download.c
index ccfa9c417..fc0b768d9 100644
--- a/src/fs/gnunet-download.c
+++ b/src/fs/gnunet-download.c
@@ -53,8 +53,7 @@ static char *filename;
53static int local_only; 53static int local_only;
54 54
55static void 55static void
56cleanup_task (void *cls, 56cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
57 const struct GNUNET_SCHEDULER_TaskContext *tc)
58{ 57{
59 GNUNET_FS_stop (ctx); 58 GNUNET_FS_stop (ctx);
60 ctx = NULL; 59 ctx = NULL;
@@ -62,17 +61,16 @@ cleanup_task (void *cls,
62 61
63 62
64static void 63static void
65shutdown_task (void *cls, 64shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
66 const struct GNUNET_SCHEDULER_TaskContext *tc)
67{ 65{
68 struct GNUNET_FS_DownloadContext *d; 66 struct GNUNET_FS_DownloadContext *d;
69 67
70 if (dc != NULL) 68 if (dc != NULL)
71 { 69 {
72 d = dc; 70 d = dc;
73 dc = NULL; 71 dc = NULL;
74 GNUNET_FS_download_stop (d, delete_incomplete); 72 GNUNET_FS_download_stop (d, delete_incomplete);
75 } 73 }
76} 74}
77 75
78 76
@@ -90,67 +88,64 @@ shutdown_task (void *cls,
90 * field in the GNUNET_FS_ProgressInfo struct. 88 * field in the GNUNET_FS_ProgressInfo struct.
91 */ 89 */
92static void * 90static void *
93progress_cb (void *cls, 91progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
94 const struct GNUNET_FS_ProgressInfo *info)
95{ 92{
96 char *s; 93 char *s;
97 char *t; 94 char *t;
98 95
99 switch (info->status) 96 switch (info->status)
100 { 97 {
101 case GNUNET_FS_STATUS_DOWNLOAD_START: 98 case GNUNET_FS_STATUS_DOWNLOAD_START:
102 if (verbose > 1) 99 if (verbose > 1)
103 fprintf (stderr,
104 _("Starting download `%s'.\n"),
105 info->value.download.filename);
106 break;
107 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
108 if (verbose)
109 {
110 s = GNUNET_STRINGS_relative_time_to_string(info->value.download.eta);
111 t = GNUNET_STRINGS_byte_size_fancy(info->value.download.completed * 1000LL / (info->value.download.duration.rel_value + 1));
112 fprintf (stdout,
113 _("Downloading `%s' at %llu/%llu (%s remaining, %s/s)\n"),
114 info->value.download.filename,
115 (unsigned long long) info->value.download.completed,
116 (unsigned long long) info->value.download.size,
117 s,
118 t);
119 GNUNET_free (s);
120 GNUNET_free (t);
121 }
122 break;
123 case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
124 fprintf (stderr, 100 fprintf (stderr,
125 _("Error downloading: %s.\n"), 101 _("Starting download `%s'.\n"), info->value.download.filename);
126 info->value.download.specifics.error.message); 102 break;
127 GNUNET_SCHEDULER_shutdown (); 103 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
128 break; 104 if (verbose)
129 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: 105 {
130 s = GNUNET_STRINGS_byte_size_fancy(info->value.download.completed * 1000 / (info->value.download.duration.rel_value + 1)); 106 s = GNUNET_STRINGS_relative_time_to_string (info->value.download.eta);
107 t = GNUNET_STRINGS_byte_size_fancy (info->value.download.completed *
108 1000LL /
109 (info->value.download.
110 duration.rel_value + 1));
131 fprintf (stdout, 111 fprintf (stdout,
132 _("Downloading `%s' done (%s/s).\n"), 112 _("Downloading `%s' at %llu/%llu (%s remaining, %s/s)\n"),
133 info->value.download.filename, 113 info->value.download.filename,
134 s); 114 (unsigned long long) info->value.download.completed,
115 (unsigned long long) info->value.download.size, s, t);
135 GNUNET_free (s); 116 GNUNET_free (s);
136 if (info->value.download.dc == dc) 117 GNUNET_free (t);
137 GNUNET_SCHEDULER_shutdown ();
138 break;
139 case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
140 if (info->value.download.dc == dc)
141 GNUNET_SCHEDULER_add_continuation (&cleanup_task,
142 NULL,
143 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
144 break;
145 case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
146 case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
147 break;
148 default:
149 fprintf (stderr,
150 _("Unexpected status: %d\n"),
151 info->status);
152 break;
153 } 118 }
119 break;
120 case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
121 fprintf (stderr,
122 _("Error downloading: %s.\n"),
123 info->value.download.specifics.error.message);
124 GNUNET_SCHEDULER_shutdown ();
125 break;
126 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
127 s = GNUNET_STRINGS_byte_size_fancy (info->value.download.completed * 1000 /
128 (info->value.download.
129 duration.rel_value + 1));
130 fprintf (stdout, _("Downloading `%s' done (%s/s).\n"),
131 info->value.download.filename, s);
132 GNUNET_free (s);
133 if (info->value.download.dc == dc)
134 GNUNET_SCHEDULER_shutdown ();
135 break;
136 case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
137 if (info->value.download.dc == dc)
138 GNUNET_SCHEDULER_add_continuation (&cleanup_task,
139 NULL,
140 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
141 break;
142 case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
143 case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
144 break;
145 default:
146 fprintf (stderr, _("Unexpected status: %d\n"), info->status);
147 break;
148 }
154 return NULL; 149 return NULL;
155} 150}
156 151
@@ -166,92 +161,77 @@ progress_cb (void *cls,
166static void 161static void
167run (void *cls, 162run (void *cls,
168 char *const *args, 163 char *const *args,
169 const char *cfgfile, 164 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
170 const struct GNUNET_CONFIGURATION_Handle *c)
171{ 165{
172 struct GNUNET_FS_Uri *uri; 166 struct GNUNET_FS_Uri *uri;
173 char *emsg; 167 char *emsg;
174 enum GNUNET_FS_DownloadOptions options; 168 enum GNUNET_FS_DownloadOptions options;
175 169
176 if (NULL == args[0]) 170 if (NULL == args[0])
177 { 171 {
178 fprintf (stderr, 172 fprintf (stderr, _("You need to specify a URI argument.\n"));
179 _("You need to specify a URI argument.\n")); 173 return;
180 return; 174 }
181 } 175 uri = GNUNET_FS_uri_parse (args[0], &emsg);
182 uri = GNUNET_FS_uri_parse (args[0],
183 &emsg);
184 if (NULL == uri) 176 if (NULL == uri)
185 { 177 {
186 fprintf (stderr, 178 fprintf (stderr, _("Failed to parse URI: %s\n"), emsg);
187 _("Failed to parse URI: %s\n"), 179 GNUNET_free (emsg);
188 emsg); 180 ret = 1;
189 GNUNET_free (emsg); 181 return;
190 ret = 1; 182 }
191 return; 183 if ((!GNUNET_FS_uri_test_chk (uri)) && (!GNUNET_FS_uri_test_loc (uri)))
192 } 184 {
193 if ( (! GNUNET_FS_uri_test_chk (uri)) && 185 fprintf (stderr, _("Only CHK or LOC URIs supported.\n"));
194 (! GNUNET_FS_uri_test_loc (uri)) ) 186 ret = 1;
195 { 187 GNUNET_FS_uri_destroy (uri);
196 fprintf (stderr, 188 return;
197 _("Only CHK or LOC URIs supported.\n")); 189 }
198 ret = 1;
199 GNUNET_FS_uri_destroy (uri);
200 return;
201 }
202 if (NULL == filename) 190 if (NULL == filename)
203 { 191 {
204 fprintf (stderr, 192 fprintf (stderr, _("Target filename must be specified.\n"));
205 _("Target filename must be specified.\n")); 193 ret = 1;
206 ret = 1; 194 GNUNET_FS_uri_destroy (uri);
207 GNUNET_FS_uri_destroy (uri); 195 return;
208 return; 196 }
209 }
210 cfg = c; 197 cfg = c;
211 ctx = GNUNET_FS_start (cfg, 198 ctx = GNUNET_FS_start (cfg,
212 "gnunet-download", 199 "gnunet-download",
213 &progress_cb, 200 &progress_cb,
214 NULL, 201 NULL,
215 GNUNET_FS_FLAGS_NONE, 202 GNUNET_FS_FLAGS_NONE,
216 GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM, 203 GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM,
217 parallelism, 204 parallelism,
218 GNUNET_FS_OPTIONS_REQUEST_PARALLELISM, 205 GNUNET_FS_OPTIONS_REQUEST_PARALLELISM,
219 request_parallelism, 206 request_parallelism, GNUNET_FS_OPTIONS_END);
220 GNUNET_FS_OPTIONS_END);
221 if (NULL == ctx) 207 if (NULL == ctx)
222 { 208 {
223 fprintf (stderr, 209 fprintf (stderr, _("Could not initialize `%s' subsystem.\n"), "FS");
224 _("Could not initialize `%s' subsystem.\n"), 210 GNUNET_FS_uri_destroy (uri);
225 "FS"); 211 ret = 1;
226 GNUNET_FS_uri_destroy (uri); 212 return;
227 ret = 1; 213 }
228 return;
229 }
230 options = GNUNET_FS_DOWNLOAD_OPTION_NONE; 214 options = GNUNET_FS_DOWNLOAD_OPTION_NONE;
231 if (do_recursive) 215 if (do_recursive)
232 options |= GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE; 216 options |= GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE;
233 if (local_only) 217 if (local_only)
234 options |= GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY; 218 options |= GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY;
235 dc = GNUNET_FS_download_start (ctx, 219 dc = GNUNET_FS_download_start (ctx,
236 uri, 220 uri,
237 NULL, 221 NULL,
238 filename, NULL, 222 filename, NULL,
239 0, 223 0,
240 GNUNET_FS_uri_chk_get_file_size (uri), 224 GNUNET_FS_uri_chk_get_file_size (uri),
241 anonymity, 225 anonymity, options, NULL, NULL);
242 options,
243 NULL,
244 NULL);
245 GNUNET_FS_uri_destroy (uri); 226 GNUNET_FS_uri_destroy (uri);
246 if (dc == NULL) 227 if (dc == NULL)
247 { 228 {
248 GNUNET_FS_stop (ctx); 229 GNUNET_FS_stop (ctx);
249 ctx = NULL; 230 ctx = NULL;
250 return; 231 return;
251 } 232 }
252 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 233 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
253 &shutdown_task, 234 &shutdown_task, NULL);
254 NULL);
255} 235}
256 236
257 237
@@ -304,4 +284,3 @@ main (int argc, char *const *argv)
304} 284}
305 285
306/* end of gnunet-download.c */ 286/* end of gnunet-download.c */
307