aboutsummaryrefslogtreecommitdiff
path: root/src/fs/test_fs_download_persistence.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
commit5746309cb4be2073d550ad7a6885e918631dbc38 (patch)
tree89455bc4aadf977816b38df13f990372cd81d71a /src/fs/test_fs_download_persistence.c
parent6fd3e715cae09fa6e657c96f1c6f9711ee51f42f (diff)
downloadgnunet-5746309cb4be2073d550ad7a6885e918631dbc38.tar.gz
gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.zip
indentation
Diffstat (limited to 'src/fs/test_fs_download_persistence.c')
-rw-r--r--src/fs/test_fs_download_persistence.c86
1 files changed, 34 insertions, 52 deletions
diff --git a/src/fs/test_fs_download_persistence.c b/src/fs/test_fs_download_persistence.c
index d484f9587..5b2a53f80 100644
--- a/src/fs/test_fs_download_persistence.c
+++ b/src/fs/test_fs_download_persistence.c
@@ -132,10 +132,7 @@ restart_fs_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
132{ 132{
133 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Restarting FS.\n"); 133 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Restarting FS.\n");
134 GNUNET_FS_stop (fs); 134 GNUNET_FS_stop (fs);
135 fs = GNUNET_FS_start (cfg, 135 fs = GNUNET_FS_start (cfg, "test-fs-download-persistence", &progress_cb, NULL,
136 "test-fs-download-persistence",
137 &progress_cb,
138 NULL,
139 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); 136 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END);
140} 137}
141 138
@@ -174,26 +171,22 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
174 (unsigned long long) event->value.publish.completed, 171 (unsigned long long) event->value.publish.completed,
175 (unsigned long long) event->value.publish.size, 172 (unsigned long long) event->value.publish.size,
176 event->value.publish.specifics.progress.depth, 173 event->value.publish.specifics.progress.depth,
177 (unsigned long long) event->value.publish.specifics. 174 (unsigned long long) event->value.publish.specifics.progress.
178 progress.offset); 175 offset);
179#endif 176#endif
180 break; 177 break;
181 case GNUNET_FS_STATUS_PUBLISH_COMPLETED: 178 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
182 printf ("Publishing complete, %llu kbps.\n", 179 printf ("Publishing complete, %llu kbps.\n",
183 (unsigned long long) (FILESIZE * 1000LL / 180 (unsigned long long) (FILESIZE * 1000LL /
184 (1 + 181 (1 +
185 GNUNET_TIME_absolute_get_duration 182 GNUNET_TIME_absolute_get_duration (start).
186 (start).rel_value) / 1024LL)); 183 rel_value) / 1024LL));
187 fn = GNUNET_DISK_mktemp ("gnunet-download-test-dst"); 184 fn = GNUNET_DISK_mktemp ("gnunet-download-test-dst");
188 start = GNUNET_TIME_absolute_get (); 185 start = GNUNET_TIME_absolute_get ();
189 GNUNET_assert (download == NULL); 186 GNUNET_assert (download == NULL);
190 GNUNET_FS_download_start (fs, 187 GNUNET_FS_download_start (fs,
191 event->value.publish.specifics.completed.chk_uri, 188 event->value.publish.specifics.completed.chk_uri,
192 NULL, 189 NULL, fn, NULL, 0, FILESIZE, 1,
193 fn, NULL,
194 0,
195 FILESIZE,
196 1,
197 GNUNET_FS_DOWNLOAD_OPTION_NONE, "download", NULL); 190 GNUNET_FS_DOWNLOAD_OPTION_NONE, "download", NULL);
198 break; 191 break;
199 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: 192 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
@@ -201,8 +194,8 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
201 printf ("Download complete, %llu kbps.\n", 194 printf ("Download complete, %llu kbps.\n",
202 (unsigned long long) (FILESIZE * 1000LL / 195 (unsigned long long) (FILESIZE * 1000LL /
203 (1 + 196 (1 +
204 GNUNET_TIME_absolute_get_duration 197 GNUNET_TIME_absolute_get_duration (start).
205 (start).rel_value) / 1024LL)); 198 rel_value) / 1024LL));
206 GNUNET_SCHEDULER_add_now (&abort_download_task, NULL); 199 GNUNET_SCHEDULER_add_now (&abort_download_task, NULL);
207 break; 200 break;
208 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: 201 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
@@ -213,22 +206,19 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
213 (unsigned long long) event->value.download.completed, 206 (unsigned long long) event->value.download.completed,
214 (unsigned long long) event->value.download.size, 207 (unsigned long long) event->value.download.size,
215 event->value.download.specifics.progress.depth, 208 event->value.download.specifics.progress.depth,
216 (unsigned long long) event->value.download.specifics. 209 (unsigned long long) event->value.download.specifics.progress.
217 progress.offset); 210 offset);
218#endif 211#endif
219 break; 212 break;
220 case GNUNET_FS_STATUS_PUBLISH_ERROR: 213 case GNUNET_FS_STATUS_PUBLISH_ERROR:
221 fprintf (stderr, 214 fprintf (stderr, "Error publishing file: %s\n",
222 "Error publishing file: %s\n",
223 event->value.publish.specifics.error.message); 215 event->value.publish.specifics.error.message);
224 GNUNET_break (0); 216 GNUNET_break (0);
225 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, 217 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, NULL,
226 NULL,
227 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 218 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
228 break; 219 break;
229 case GNUNET_FS_STATUS_DOWNLOAD_ERROR: 220 case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
230 fprintf (stderr, 221 fprintf (stderr, "Error downloading file: %s\n",
231 "Error downloading file: %s\n",
232 event->value.download.specifics.error.message); 222 event->value.download.specifics.error.message);
233 GNUNET_SCHEDULER_add_now (&abort_download_task, NULL); 223 GNUNET_SCHEDULER_add_now (&abort_download_task, NULL);
234 break; 224 break;
@@ -287,8 +277,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
287 break; 277 break;
288 case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: 278 case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
289 GNUNET_assert (download == event->value.download.dc); 279 GNUNET_assert (download == event->value.download.dc);
290 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, 280 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, NULL,
291 NULL,
292 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 281 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
293 download = NULL; 282 download = NULL;
294 break; 283 break;
@@ -305,12 +294,13 @@ setup_peer (struct PeerContext *p, const char *cfgname)
305{ 294{
306 p->cfg = GNUNET_CONFIGURATION_create (); 295 p->cfg = GNUNET_CONFIGURATION_create ();
307#if START_ARM 296#if START_ARM
308 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 297 p->arm_proc =
309 "gnunet-service-arm", 298 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
299 "gnunet-service-arm",
310#if VERBOSE 300#if VERBOSE
311 "-L", "DEBUG", 301 "-L", "DEBUG",
312#endif 302#endif
313 "-c", cfgname, NULL); 303 "-c", cfgname, NULL);
314#endif 304#endif
315 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 305 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
316} 306}
@@ -326,8 +316,7 @@ stop_arm (struct PeerContext *p)
326 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 316 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
327 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) 317 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
328 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 318 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
329 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 319 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
330 "ARM process %u stopped\n",
331 GNUNET_OS_process_get_pid (p->arm_proc)); 320 GNUNET_OS_process_get_pid (p->arm_proc));
332 GNUNET_OS_process_close (p->arm_proc); 321 GNUNET_OS_process_close (p->arm_proc);
333 p->arm_proc = NULL; 322 p->arm_proc = NULL;
@@ -338,9 +327,8 @@ stop_arm (struct PeerContext *p)
338 327
339 328
340static void 329static void
341run (void *cls, 330run (void *cls, char *const *args, const char *cfgfile,
342 char *const *args, 331 const struct GNUNET_CONFIGURATION_Handle *c)
343 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
344{ 332{
345 const char *keywords[] = { 333 const char *keywords[] = {
346 "down_foo", 334 "down_foo",
@@ -355,10 +343,7 @@ run (void *cls,
355 343
356 cfg = c; 344 cfg = c;
357 setup_peer (&p1, "test_fs_download_data.conf"); 345 setup_peer (&p1, "test_fs_download_data.conf");
358 fs = GNUNET_FS_start (cfg, 346 fs = GNUNET_FS_start (cfg, "test-fs-download-persistence", &progress_cb, NULL,
359 "test-fs-download-persistence",
360 &progress_cb,
361 NULL,
362 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); 347 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END);
363 GNUNET_assert (NULL != fs); 348 GNUNET_assert (NULL != fs);
364 buf = GNUNET_malloc (FILESIZE); 349 buf = GNUNET_malloc (FILESIZE);
@@ -370,21 +355,18 @@ run (void *cls,
370 bo.anonymity_level = 1; 355 bo.anonymity_level = 1;
371 bo.replication_level = 0; 356 bo.replication_level = 0;
372 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); 357 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
373 fi = GNUNET_FS_file_information_create_from_data (fs, 358 fi = GNUNET_FS_file_information_create_from_data (fs, "publish-context",
374 "publish-context", 359 FILESIZE, buf, kuri, meta,
375 FILESIZE, 360 GNUNET_NO, &bo);
376 buf,
377 kuri, meta, GNUNET_NO, &bo);
378 GNUNET_FS_uri_destroy (kuri); 361 GNUNET_FS_uri_destroy (kuri);
379 GNUNET_CONTAINER_meta_data_destroy (meta); 362 GNUNET_CONTAINER_meta_data_destroy (meta);
380 GNUNET_assert (NULL != fi); 363 GNUNET_assert (NULL != fi);
381 timeout_kill = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 364 timeout_kill =
382 &timeout_kill_task, NULL); 365 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_kill_task, NULL);
383 start = GNUNET_TIME_absolute_get (); 366 start = GNUNET_TIME_absolute_get ();
384 publish = GNUNET_FS_publish_start (fs, 367 publish =
385 fi, 368 GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL,
386 NULL, NULL, NULL, 369 GNUNET_FS_PUBLISH_OPTION_NONE);
387 GNUNET_FS_PUBLISH_OPTION_NONE);
388 GNUNET_assert (publish != NULL); 370 GNUNET_assert (publish != NULL);
389} 371}
390 372
@@ -412,9 +394,9 @@ main (int argc, char *argv[])
412#endif 394#endif
413 NULL); 395 NULL);
414 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-download/"); 396 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-download/");
415 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 397 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
416 argvx, "test-fs-download-persistence", 398 "test-fs-download-persistence", "nohelp", options, &run,
417 "nohelp", options, &run, NULL); 399 NULL);
418 stop_arm (&p1); 400 stop_arm (&p1);
419 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-download/"); 401 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-download/");
420 return err; 402 return err;