diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:54:06 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:54:06 +0000 |
commit | 5746309cb4be2073d550ad7a6885e918631dbc38 (patch) | |
tree | 89455bc4aadf977816b38df13f990372cd81d71a /src/fs/test_fs_download.c | |
parent | 6fd3e715cae09fa6e657c96f1c6f9711ee51f42f (diff) | |
download | gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.tar.gz gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.zip |
indentation
Diffstat (limited to 'src/fs/test_fs_download.c')
-rw-r--r-- | src/fs/test_fs_download.c | 94 |
1 files changed, 42 insertions, 52 deletions
diff --git a/src/fs/test_fs_download.c b/src/fs/test_fs_download.c index d37b94c03..34625ff2e 100644 --- a/src/fs/test_fs_download.c +++ b/src/fs/test_fs_download.c | |||
@@ -140,42 +140,42 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) | |||
140 | (unsigned long long) event->value.publish.completed, | 140 | (unsigned long long) event->value.publish.completed, |
141 | (unsigned long long) event->value.publish.size, | 141 | (unsigned long long) event->value.publish.size, |
142 | event->value.publish.specifics.progress.depth, | 142 | event->value.publish.specifics.progress.depth, |
143 | (unsigned long long) event->value.publish.specifics. | 143 | (unsigned long long) event->value.publish.specifics.progress. |
144 | progress.offset); | 144 | offset); |
145 | #endif | 145 | #endif |
146 | break; | 146 | break; |
147 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | 147 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: |
148 | printf ("Publishing complete, %llu kb/s.\n", | 148 | printf ("Publishing complete, %llu kb/s.\n", |
149 | (unsigned long long) (FILESIZE * 1000LL / | 149 | (unsigned long long) (FILESIZE * 1000LL / |
150 | (1 + | 150 | (1 + |
151 | GNUNET_TIME_absolute_get_duration | 151 | GNUNET_TIME_absolute_get_duration (start). |
152 | (start).rel_value) / 1024LL)); | 152 | rel_value) / 1024LL)); |
153 | GAUGER ("FS", "Publishing speed (insertion)", | 153 | GAUGER ("FS", "Publishing speed (insertion)", |
154 | (unsigned long long) (FILESIZE * 1000LL / | 154 | (unsigned long long) (FILESIZE * 1000LL / |
155 | (1 + | 155 | (1 + |
156 | GNUNET_TIME_absolute_get_duration | 156 | GNUNET_TIME_absolute_get_duration (start). |
157 | (start).rel_value) / 1024LL), "kb/s"); | 157 | rel_value) / 1024LL), "kb/s"); |
158 | fn = GNUNET_DISK_mktemp ("gnunet-download-test-dst"); | 158 | fn = GNUNET_DISK_mktemp ("gnunet-download-test-dst"); |
159 | start = GNUNET_TIME_absolute_get (); | 159 | start = GNUNET_TIME_absolute_get (); |
160 | download = GNUNET_FS_download_start (fs, | 160 | download = |
161 | event->value.publish. | 161 | GNUNET_FS_download_start (fs, |
162 | specifics.completed.chk_uri, NULL, fn, | 162 | event->value.publish.specifics.completed. |
163 | NULL, 0, FILESIZE, 1, | 163 | chk_uri, NULL, fn, NULL, 0, FILESIZE, 1, |
164 | GNUNET_FS_DOWNLOAD_OPTION_NONE, | 164 | GNUNET_FS_DOWNLOAD_OPTION_NONE, "download", |
165 | "download", NULL); | 165 | NULL); |
166 | GNUNET_assert (download != NULL); | 166 | GNUNET_assert (download != NULL); |
167 | break; | 167 | break; |
168 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: | 168 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: |
169 | printf ("Download complete, %llu kb/s.\n", | 169 | printf ("Download complete, %llu kb/s.\n", |
170 | (unsigned long long) (FILESIZE * 1000LL / | 170 | (unsigned long long) (FILESIZE * 1000LL / |
171 | (1 + | 171 | (1 + |
172 | GNUNET_TIME_absolute_get_duration | 172 | GNUNET_TIME_absolute_get_duration (start). |
173 | (start).rel_value) / 1024LL)); | 173 | rel_value) / 1024LL)); |
174 | GAUGER ("FS", "Local download speed (inserted)", | 174 | GAUGER ("FS", "Local download speed (inserted)", |
175 | (unsigned long long) (FILESIZE * 1000LL / | 175 | (unsigned long long) (FILESIZE * 1000LL / |
176 | (1 + | 176 | (1 + |
177 | GNUNET_TIME_absolute_get_duration | 177 | GNUNET_TIME_absolute_get_duration (start). |
178 | (start).rel_value) / 1024LL), "kb/s"); | 178 | rel_value) / 1024LL), "kb/s"); |
179 | GNUNET_SCHEDULER_add_now (&abort_download_task, NULL); | 179 | GNUNET_SCHEDULER_add_now (&abort_download_task, NULL); |
180 | break; | 180 | break; |
181 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: | 181 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: |
@@ -185,22 +185,19 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) | |||
185 | (unsigned long long) event->value.download.completed, | 185 | (unsigned long long) event->value.download.completed, |
186 | (unsigned long long) event->value.download.size, | 186 | (unsigned long long) event->value.download.size, |
187 | event->value.download.specifics.progress.depth, | 187 | event->value.download.specifics.progress.depth, |
188 | (unsigned long long) event->value.download.specifics. | 188 | (unsigned long long) event->value.download.specifics.progress. |
189 | progress.offset); | 189 | offset); |
190 | #endif | 190 | #endif |
191 | break; | 191 | break; |
192 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 192 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
193 | fprintf (stderr, | 193 | fprintf (stderr, "Error publishing file: %s\n", |
194 | "Error publishing file: %s\n", | ||
195 | event->value.publish.specifics.error.message); | 194 | event->value.publish.specifics.error.message); |
196 | GNUNET_break (0); | 195 | GNUNET_break (0); |
197 | GNUNET_SCHEDULER_add_continuation (&abort_publish_task, | 196 | GNUNET_SCHEDULER_add_continuation (&abort_publish_task, NULL, |
198 | NULL, | ||
199 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 197 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
200 | break; | 198 | break; |
201 | case GNUNET_FS_STATUS_DOWNLOAD_ERROR: | 199 | case GNUNET_FS_STATUS_DOWNLOAD_ERROR: |
202 | fprintf (stderr, | 200 | fprintf (stderr, "Error downloading file: %s\n", |
203 | "Error downloading file: %s\n", | ||
204 | event->value.download.specifics.error.message); | 201 | event->value.download.specifics.error.message); |
205 | GNUNET_SCHEDULER_add_now (&abort_download_task, NULL); | 202 | GNUNET_SCHEDULER_add_now (&abort_download_task, NULL); |
206 | break; | 203 | break; |
@@ -231,8 +228,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) | |||
231 | break; | 228 | break; |
232 | case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: | 229 | case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: |
233 | GNUNET_assert (download == event->value.download.dc); | 230 | GNUNET_assert (download == event->value.download.dc); |
234 | GNUNET_SCHEDULER_add_continuation (&abort_publish_task, | 231 | GNUNET_SCHEDULER_add_continuation (&abort_publish_task, NULL, |
235 | NULL, | ||
236 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 232 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
237 | break; | 233 | break; |
238 | default: | 234 | default: |
@@ -248,12 +244,13 @@ setup_peer (struct PeerContext *p, const char *cfgname) | |||
248 | { | 244 | { |
249 | p->cfg = GNUNET_CONFIGURATION_create (); | 245 | p->cfg = GNUNET_CONFIGURATION_create (); |
250 | #if START_ARM | 246 | #if START_ARM |
251 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", | 247 | p->arm_proc = |
252 | "gnunet-service-arm", | 248 | GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", |
249 | "gnunet-service-arm", | ||
253 | #if VERBOSE | 250 | #if VERBOSE |
254 | "-L", "DEBUG", | 251 | "-L", "DEBUG", |
255 | #endif | 252 | #endif |
256 | "-c", cfgname, NULL); | 253 | "-c", cfgname, NULL); |
257 | #endif | 254 | #endif |
258 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 255 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
259 | } | 256 | } |
@@ -269,8 +266,7 @@ stop_arm (struct PeerContext *p) | |||
269 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 266 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
270 | if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) | 267 | if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) |
271 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | 268 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); |
272 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 269 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n", |
273 | "ARM process %u stopped\n", | ||
274 | GNUNET_OS_process_get_pid (p->arm_proc)); | 270 | GNUNET_OS_process_get_pid (p->arm_proc)); |
275 | GNUNET_OS_process_close (p->arm_proc); | 271 | GNUNET_OS_process_close (p->arm_proc); |
276 | p->arm_proc = NULL; | 272 | p->arm_proc = NULL; |
@@ -281,9 +277,8 @@ stop_arm (struct PeerContext *p) | |||
281 | 277 | ||
282 | 278 | ||
283 | static void | 279 | static void |
284 | run (void *cls, | 280 | run (void *cls, char *const *args, const char *cfgfile, |
285 | char *const *args, | 281 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
286 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
287 | { | 282 | { |
288 | const char *keywords[] = { | 283 | const char *keywords[] = { |
289 | "down_foo", | 284 | "down_foo", |
@@ -297,10 +292,8 @@ run (void *cls, | |||
297 | struct GNUNET_FS_BlockOptions bo; | 292 | struct GNUNET_FS_BlockOptions bo; |
298 | 293 | ||
299 | setup_peer (&p1, "test_fs_download_data.conf"); | 294 | setup_peer (&p1, "test_fs_download_data.conf"); |
300 | fs = GNUNET_FS_start (cfg, | 295 | fs = GNUNET_FS_start (cfg, "test-fs-download", &progress_cb, NULL, |
301 | "test-fs-download", | 296 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); |
302 | &progress_cb, | ||
303 | NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); | ||
304 | GNUNET_assert (NULL != fs); | 297 | GNUNET_assert (NULL != fs); |
305 | buf = GNUNET_malloc (FILESIZE); | 298 | buf = GNUNET_malloc (FILESIZE); |
306 | for (i = 0; i < FILESIZE; i++) | 299 | for (i = 0; i < FILESIZE; i++) |
@@ -311,21 +304,18 @@ run (void *cls, | |||
311 | bo.anonymity_level = 1; | 304 | bo.anonymity_level = 1; |
312 | bo.replication_level = 0; | 305 | bo.replication_level = 0; |
313 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); | 306 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); |
314 | fi = GNUNET_FS_file_information_create_from_data (fs, | 307 | fi = GNUNET_FS_file_information_create_from_data (fs, "publish-context", |
315 | "publish-context", | 308 | FILESIZE, buf, kuri, meta, |
316 | FILESIZE, | 309 | GNUNET_NO, &bo); |
317 | buf, | ||
318 | kuri, meta, GNUNET_NO, &bo); | ||
319 | GNUNET_FS_uri_destroy (kuri); | 310 | GNUNET_FS_uri_destroy (kuri); |
320 | GNUNET_CONTAINER_meta_data_destroy (meta); | 311 | GNUNET_CONTAINER_meta_data_destroy (meta); |
321 | GNUNET_assert (NULL != fi); | 312 | GNUNET_assert (NULL != fi); |
322 | timeout_kill = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 313 | timeout_kill = |
323 | &timeout_kill_task, NULL); | 314 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_kill_task, NULL); |
324 | start = GNUNET_TIME_absolute_get (); | 315 | start = GNUNET_TIME_absolute_get (); |
325 | publish = GNUNET_FS_publish_start (fs, | 316 | publish = |
326 | fi, | 317 | GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL, |
327 | NULL, NULL, NULL, | 318 | GNUNET_FS_PUBLISH_OPTION_NONE); |
328 | GNUNET_FS_PUBLISH_OPTION_NONE); | ||
329 | GNUNET_assert (publish != NULL); | 319 | GNUNET_assert (publish != NULL); |
330 | } | 320 | } |
331 | 321 | ||
@@ -353,8 +343,8 @@ main (int argc, char *argv[]) | |||
353 | "WARNING", | 343 | "WARNING", |
354 | #endif | 344 | #endif |
355 | NULL); | 345 | NULL); |
356 | GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, | 346 | GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx, |
357 | argvx, "test-fs-download", "nohelp", options, &run, NULL); | 347 | "test-fs-download", "nohelp", options, &run, NULL); |
358 | stop_arm (&p1); | 348 | stop_arm (&p1); |
359 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-download/"); | 349 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-download/"); |
360 | return err; | 350 | return err; |