/**
* How long until we give up on transmitting the message?
*/
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
/**
* How long should our test-content live?
struct PeerContext
{
struct GNUNET_CONFIGURATION_Handle *cfg;
- struct GNUNET_PeerIdentity id;
#if START_ARM
pid_t arm_pid;
#endif
static struct GNUNET_FS_PublishContext *publish;
+static GNUNET_SCHEDULER_TaskIdentifier timeout_kill;
+
static char *fn;
+static int err;
+
+static void
+timeout_kill_task (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ if (download != NULL)
+ {
+ GNUNET_FS_download_stop (download, GNUNET_YES);
+ download = NULL;
+ }
+ else if (publish != NULL)
+ {
+ GNUNET_FS_publish_stop (publish);
+ publish = NULL;
+ }
+ timeout_kill = GNUNET_SCHEDULER_NO_TASK;
+ err = 1;
+}
static void
abort_publish_task (void *cls,
const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- GNUNET_FS_publish_stop (publish);
- publish = NULL;
+ if (publish != NULL)
+ {
+ GNUNET_FS_publish_stop (publish);
+ publish = NULL;
+ }
}
+static void
+stop_fs_task (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ GNUNET_FS_stop (fs);
+ fs = NULL;
+}
static void
abort_download_task (void *cls,
{
uint64_t size;
- GNUNET_FS_download_stop (download, GNUNET_YES);
- download = NULL;
+ if (download != NULL)
+ {
+ GNUNET_FS_download_stop (download, GNUNET_YES);
+ download = NULL;
+ }
GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_size (fn, &size, GNUNET_YES));
GNUNET_assert (size == FILESIZE);
GNUNET_DISK_directory_remove (fn);
GNUNET_free (fn);
fn = NULL;
+ GNUNET_SCHEDULER_cancel (sched, timeout_kill);
+ timeout_kill = GNUNET_SCHEDULER_NO_TASK;
}
break;
case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
printf ("Publishing complete, %llu kbps.\n",
- (unsigned long long) (FILESIZE * 1000 / (1+GNUNET_TIME_absolute_get_duration (start).value) / 1024));
- fn = GNUNET_DISK_mktemp ("gnunet-download-test-dstXXXXXX");
+ (unsigned long long) (FILESIZE * 1000LL / (1+GNUNET_TIME_absolute_get_duration (start).value) / 1024LL));
+ fn = GNUNET_DISK_mktemp ("gnunet-download-test-dst");
start = GNUNET_TIME_absolute_get ();
download = GNUNET_FS_download_start (fs,
event->value.publish.specifics.completed.chk_uri,
NULL,
- fn,
+ fn, NULL,
0,
FILESIZE,
1,
break;
case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
printf ("Download complete, %llu kbps.\n",
- (unsigned long long) (FILESIZE * 1000 / (1+GNUNET_TIME_absolute_get_duration (start).value) / 1024));
- GNUNET_SCHEDULER_add_continuation (sched,
- GNUNET_NO,
- &abort_download_task,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ (unsigned long long) (FILESIZE * 1000LL / (1+GNUNET_TIME_absolute_get_duration (start).value) / 1024LL));
+ GNUNET_SCHEDULER_add_now (sched,
+ &abort_download_task,
+ NULL);
break;
case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
GNUNET_assert (download == event->value.download.dc);
event->value.publish.specifics.error.message);
GNUNET_break (0);
GNUNET_SCHEDULER_add_continuation (sched,
- GNUNET_NO,
&abort_publish_task,
NULL,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
fprintf (stderr,
"Error downloading file: %s\n",
event->value.download.specifics.error.message);
- GNUNET_SCHEDULER_add_continuation (sched,
- GNUNET_NO,
- &abort_download_task,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ GNUNET_SCHEDULER_add_now (sched,
+ &abort_download_task,
+ NULL);
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
+ case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
break;
case GNUNET_FS_STATUS_PUBLISH_START:
GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx));
GNUNET_assert (publish == event->value.publish.sc);
GNUNET_assert (FILESIZE == event->value.publish.size);
GNUNET_assert (1 == event->value.publish.anonymity);
- GNUNET_FS_stop (fs);
- fs = NULL;
+ GNUNET_SCHEDULER_add_now (sched,
+ &stop_fs_task,
+ NULL);
break;
case GNUNET_FS_STATUS_DOWNLOAD_START:
GNUNET_assert (download == NULL);
case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
GNUNET_assert (download == event->value.download.dc);
GNUNET_SCHEDULER_add_continuation (sched,
- GNUNET_NO,
&abort_publish_task,
NULL,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
{
p->cfg = GNUNET_CONFIGURATION_create ();
#if START_ARM
- p->arm_pid = GNUNET_OS_start_process ("gnunet-service-arm",
+ p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
"gnunet-service-arm",
#if VERBOSE
"-L", "DEBUG",
#endif
"-c", cfgname, NULL);
- sleep (1); /* allow ARM to start */
#endif
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
- GNUNET_ARM_start_services (p->cfg, sched, "core", NULL);
}
buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
meta = GNUNET_CONTAINER_meta_data_create ();
kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords);
- fi = GNUNET_FS_file_information_create_from_data ("publish-context",
+ fi = GNUNET_FS_file_information_create_from_data (fs,
+ "publish-context",
FILESIZE,
buf,
kuri,
GNUNET_FS_uri_destroy (kuri);
GNUNET_CONTAINER_meta_data_destroy (meta);
GNUNET_assert (NULL != fi);
+ timeout_kill = GNUNET_SCHEDULER_add_delayed (sched,
+ TIMEOUT,
+ &timeout_kill_task,
+ NULL);
start = GNUNET_TIME_absolute_get ();
publish = GNUNET_FS_publish_start (fs,
fi,
argvx, "test-fs-download",
"nohelp", options, &run, NULL);
stop_arm (&p1);
- return 0;
+ GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-download/");
+ return err;
}
/* end of test_fs_download.c */