diff options
author | Christian Grothoff <christian@grothoff.org> | 2009-10-18 18:00:12 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2009-10-18 18:00:12 +0000 |
commit | c3bb2fde588bc1f9d822bc5dfbbb930e52a21b83 (patch) | |
tree | a0f4a183b6dded627a1a133a4c1e3cf8c2a2ff2f /src | |
parent | c871949ce934d896718de59775c8b0b7285720c1 (diff) | |
download | gnunet-c3bb2fde588bc1f9d822bc5dfbbb930e52a21b83.tar.gz gnunet-c3bb2fde588bc1f9d822bc5dfbbb930e52a21b83.zip |
minor consistency improvements to FS API and another testcase that compiles but does not yet run
Diffstat (limited to 'src')
-rw-r--r-- | src/core/test_core_api.c | 1 | ||||
-rw-r--r-- | src/core/test_core_api_data.conf | 2 | ||||
-rw-r--r-- | src/fs/Makefile.am | 9 | ||||
-rw-r--r-- | src/fs/fs_download.c | 24 | ||||
-rw-r--r-- | src/fs/fs_file_information.c | 2 | ||||
-rw-r--r-- | src/fs/fs_search.c | 2 | ||||
-rw-r--r-- | src/fs/fs_unindex.c | 4 | ||||
-rw-r--r-- | src/fs/gnunet-download.c | 24 | ||||
-rw-r--r-- | src/fs/gnunet-unindex.c | 4 | ||||
-rw-r--r-- | src/fs/test_fs_download.c | 454 | ||||
-rw-r--r-- | src/fs/test_fs_download_data.conf | 33 | ||||
-rw-r--r-- | src/include/gnunet_fs_service.h | 33 |
12 files changed, 299 insertions, 293 deletions
diff --git a/src/core/test_core_api.c b/src/core/test_core_api.c index d72af8254..89aa34f5b 100644 --- a/src/core/test_core_api.c +++ b/src/core/test_core_api.c | |||
@@ -363,7 +363,6 @@ check () | |||
363 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 363 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
364 | GNUNET_GETOPT_OPTION_END | 364 | GNUNET_GETOPT_OPTION_END |
365 | }; | 365 | }; |
366 | // sleep (1); /* for 'make check': allow previous processes to fully terminate */ | ||
367 | ok = 1; | 366 | ok = 1; |
368 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 367 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
369 | argv, "test-core-api", "nohelp", options, &run, &ok); | 368 | argv, "test-core-api", "nohelp", options, &run, &ok); |
diff --git a/src/core/test_core_api_data.conf b/src/core/test_core_api_data.conf index 7a35faaf0..cd85c85a4 100644 --- a/src/core/test_core_api_data.conf +++ b/src/core/test_core_api_data.conf | |||
@@ -1,5 +1,5 @@ | |||
1 | [PATHS] | 1 | [PATHS] |
2 | SERVICEHOME = /tmp/test-gnunetd-core-master/ | 2 | SERVICEHOME = /tmp/test-gnunetd-fs-download/ |
3 | 3 | ||
4 | [resolver] | 4 | [resolver] |
5 | PORT = 2464 | 5 | PORT = 2464 |
diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am index e2f2e6267..85470e4d9 100644 --- a/src/fs/Makefile.am +++ b/src/fs/Makefile.am | |||
@@ -104,6 +104,7 @@ gnunet_unindex_LDADD = \ | |||
104 | check_PROGRAMS = \ | 104 | check_PROGRAMS = \ |
105 | test_fs_collection \ | 105 | test_fs_collection \ |
106 | test_fs_directory \ | 106 | test_fs_directory \ |
107 | test_fs_download \ | ||
107 | test_fs_getopt \ | 108 | test_fs_getopt \ |
108 | test_fs_uri | 109 | test_fs_uri |
109 | 110 | ||
@@ -123,6 +124,13 @@ test_fs_directory_LDADD = \ | |||
123 | $(top_builddir)/src/fs/libgnunetfs.la \ | 124 | $(top_builddir)/src/fs/libgnunetfs.la \ |
124 | $(top_builddir)/src/util/libgnunetutil.la | 125 | $(top_builddir)/src/util/libgnunetutil.la |
125 | 126 | ||
127 | test_fs_download_SOURCES = \ | ||
128 | test_fs_download.c | ||
129 | test_fs_download_LDADD = \ | ||
130 | $(top_builddir)/src/fs/libgnunetfs.la \ | ||
131 | $(top_builddir)/src/arm/libgnunetarm.la \ | ||
132 | $(top_builddir)/src/util/libgnunetutil.la | ||
133 | |||
126 | test_fs_getopt_SOURCES = \ | 134 | test_fs_getopt_SOURCES = \ |
127 | test_fs_getopt.c | 135 | test_fs_getopt.c |
128 | test_fs_getopt_LDADD = \ | 136 | test_fs_getopt_LDADD = \ |
@@ -137,4 +145,5 @@ test_fs_uri_LDADD = \ | |||
137 | 145 | ||
138 | EXTRA_DIST = \ | 146 | EXTRA_DIST = \ |
139 | test_fs_collection_data.conf \ | 147 | test_fs_collection_data.conf \ |
148 | test_fs_download_data.conf \ | ||
140 | test_fs_uri_data.conf | 149 | test_fs_uri_data.conf |
diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c index f36807e77..346857c24 100644 --- a/src/fs/fs_download.c +++ b/src/fs/fs_download.c | |||
@@ -144,7 +144,7 @@ make_download_status (struct GNUNET_FS_ProgressInfo *pi, | |||
144 | = dc->uri; | 144 | = dc->uri; |
145 | pi->value.download.filename | 145 | pi->value.download.filename |
146 | = dc->filename; | 146 | = dc->filename; |
147 | pi->value.download.length | 147 | pi->value.download.size |
148 | = dc->length; | 148 | = dc->length; |
149 | pi->value.download.duration | 149 | pi->value.download.duration |
150 | = GNUNET_TIME_absolute_get_duration (dc->start_time); | 150 | = GNUNET_TIME_absolute_get_duration (dc->start_time); |
@@ -649,15 +649,15 @@ try_reconnect (struct GNUNET_FS_DownloadContext *dc) | |||
649 | * @return context that can be used to control this download | 649 | * @return context that can be used to control this download |
650 | */ | 650 | */ |
651 | struct GNUNET_FS_DownloadContext * | 651 | struct GNUNET_FS_DownloadContext * |
652 | GNUNET_FS_file_download_start (struct GNUNET_FS_Handle *h, | 652 | GNUNET_FS_download_start (struct GNUNET_FS_Handle *h, |
653 | const struct GNUNET_FS_Uri *uri, | 653 | const struct GNUNET_FS_Uri *uri, |
654 | const struct GNUNET_CONTAINER_MetaData *meta, | 654 | const struct GNUNET_CONTAINER_MetaData *meta, |
655 | const char *filename, | 655 | const char *filename, |
656 | uint64_t offset, | 656 | uint64_t offset, |
657 | uint64_t length, | 657 | uint64_t length, |
658 | uint32_t anonymity, | 658 | uint32_t anonymity, |
659 | enum GNUNET_FS_DownloadOptions options, | 659 | enum GNUNET_FS_DownloadOptions options, |
660 | struct GNUNET_FS_DownloadContext *parent) | 660 | struct GNUNET_FS_DownloadContext *parent) |
661 | { | 661 | { |
662 | struct GNUNET_FS_ProgressInfo pi; | 662 | struct GNUNET_FS_ProgressInfo pi; |
663 | struct GNUNET_FS_DownloadContext *dc; | 663 | struct GNUNET_FS_DownloadContext *dc; |
@@ -766,8 +766,8 @@ free_entry (void *cls, | |||
766 | * @param do_delete delete files of incomplete downloads | 766 | * @param do_delete delete files of incomplete downloads |
767 | */ | 767 | */ |
768 | void | 768 | void |
769 | GNUNET_FS_file_download_stop (struct GNUNET_FS_DownloadContext *dc, | 769 | GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, |
770 | int do_delete) | 770 | int do_delete) |
771 | { | 771 | { |
772 | struct GNUNET_FS_ProgressInfo pi; | 772 | struct GNUNET_FS_ProgressInfo pi; |
773 | 773 | ||
diff --git a/src/fs/fs_file_information.c b/src/fs/fs_file_information.c index c20af5ea6..9bdc30262 100644 --- a/src/fs/fs_file_information.c +++ b/src/fs/fs_file_information.c | |||
@@ -265,7 +265,7 @@ data_reader_copy(void *cls, | |||
265 | * @param client_info initial value for the client-info value for this entry | 265 | * @param client_info initial value for the client-info value for this entry |
266 | * @param length length of the file | 266 | * @param length length of the file |
267 | * @param data data for the file (should not be used afterwards by | 267 | * @param data data for the file (should not be used afterwards by |
268 | * the caller; caller will "free") | 268 | * the caller; callee will "free") |
269 | * @param keywords under which keywords should this file be available | 269 | * @param keywords under which keywords should this file be available |
270 | * directly; can be NULL | 270 | * directly; can be NULL |
271 | * @param meta metadata for the file | 271 | * @param meta metadata for the file |
diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c index 85d65f483..52153dcb0 100644 --- a/src/fs/fs_search.c +++ b/src/fs/fs_search.c | |||
@@ -914,7 +914,7 @@ search_result_free (void *cls, | |||
914 | GNUNET_CONTAINER_meta_data_destroy (sr->meta); | 914 | GNUNET_CONTAINER_meta_data_destroy (sr->meta); |
915 | if (sr->probe_ctx != NULL) | 915 | if (sr->probe_ctx != NULL) |
916 | { | 916 | { |
917 | GNUNET_FS_file_download_stop (sr->probe_ctx, GNUNET_YES); | 917 | GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES); |
918 | h->active_probes--; | 918 | h->active_probes--; |
919 | /* FIXME: trigger starting of new | 919 | /* FIXME: trigger starting of new |
920 | probes here!? Maybe not -- could | 920 | probes here!? Maybe not -- could |
diff --git a/src/fs/fs_unindex.c b/src/fs/fs_unindex.c index 53814e186..4a57c7d59 100644 --- a/src/fs/fs_unindex.c +++ b/src/fs/fs_unindex.c | |||
@@ -392,8 +392,8 @@ process_hash (void *cls, | |||
392 | * @return NULL on error, otherwise handle | 392 | * @return NULL on error, otherwise handle |
393 | */ | 393 | */ |
394 | struct GNUNET_FS_UnindexContext * | 394 | struct GNUNET_FS_UnindexContext * |
395 | GNUNET_FS_unindex (struct GNUNET_FS_Handle *h, | 395 | GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h, |
396 | const char *filename) | 396 | const char *filename) |
397 | { | 397 | { |
398 | struct GNUNET_FS_UnindexContext *ret; | 398 | struct GNUNET_FS_UnindexContext *ret; |
399 | struct GNUNET_FS_ProgressInfo pi; | 399 | struct GNUNET_FS_ProgressInfo pi; |
diff --git a/src/fs/gnunet-download.c b/src/fs/gnunet-download.c index 00565b1a3..b4e787cfa 100644 --- a/src/fs/gnunet-download.c +++ b/src/fs/gnunet-download.c | |||
@@ -74,7 +74,7 @@ progress_cb (void *cls, | |||
74 | _("Downloading `%s' at %llu/%llu (%s remaining, %s/s)\n"), | 74 | _("Downloading `%s' at %llu/%llu (%s remaining, %s/s)\n"), |
75 | info->value.download.filename, | 75 | info->value.download.filename, |
76 | (unsigned long long) info->value.download.completed, | 76 | (unsigned long long) info->value.download.completed, |
77 | (unsigned long long) info->value.download.length, | 77 | (unsigned long long) info->value.download.size, |
78 | GNUNET_STRINGS_relative_time_to_string(info->value.download.eta), | 78 | GNUNET_STRINGS_relative_time_to_string(info->value.download.eta), |
79 | GNUNET_STRINGS_byte_size_fancy(info->value.download.completed * 1000 / (info->value.download.duration.value + 1))); | 79 | GNUNET_STRINGS_byte_size_fancy(info->value.download.completed * 1000 / (info->value.download.duration.value + 1))); |
80 | break; | 80 | break; |
@@ -82,7 +82,7 @@ progress_cb (void *cls, | |||
82 | fprintf (stderr, | 82 | fprintf (stderr, |
83 | _("Error downloading: %s.\n"), | 83 | _("Error downloading: %s.\n"), |
84 | info->value.download.specifics.error.message); | 84 | info->value.download.specifics.error.message); |
85 | GNUNET_FS_file_download_stop (dc, delete_incomplete); | 85 | GNUNET_FS_download_stop (dc, delete_incomplete); |
86 | break; | 86 | break; |
87 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: | 87 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: |
88 | fprintf (stdout, | 88 | fprintf (stdout, |
@@ -90,7 +90,7 @@ progress_cb (void *cls, | |||
90 | info->value.download.filename, | 90 | info->value.download.filename, |
91 | GNUNET_STRINGS_byte_size_fancy(info->value.download.completed * 1000 / (info->value.download.duration.value + 1))); | 91 | GNUNET_STRINGS_byte_size_fancy(info->value.download.completed * 1000 / (info->value.download.duration.value + 1))); |
92 | if (info->value.download.dc == dc) | 92 | if (info->value.download.dc == dc) |
93 | GNUNET_FS_file_download_stop (dc, delete_incomplete); | 93 | GNUNET_FS_download_stop (dc, delete_incomplete); |
94 | break; | 94 | break; |
95 | case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: | 95 | case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: |
96 | if (info->value.download.dc == dc) | 96 | if (info->value.download.dc == dc) |
@@ -172,15 +172,15 @@ run (void *cls, | |||
172 | return; | 172 | return; |
173 | } | 173 | } |
174 | options = GNUNET_FS_DOWNLOAD_OPTION_NONE; | 174 | options = GNUNET_FS_DOWNLOAD_OPTION_NONE; |
175 | dc = GNUNET_FS_file_download_start (ctx, | 175 | dc = GNUNET_FS_download_start (ctx, |
176 | uri, | 176 | uri, |
177 | NULL, | 177 | NULL, |
178 | filename, | 178 | filename, |
179 | 0, | 179 | 0, |
180 | GNUNET_FS_uri_chk_get_file_size (uri), | 180 | GNUNET_FS_uri_chk_get_file_size (uri), |
181 | anonymity, | 181 | anonymity, |
182 | options, | 182 | options, |
183 | NULL); | 183 | NULL); |
184 | GNUNET_FS_uri_destroy (uri); | 184 | GNUNET_FS_uri_destroy (uri); |
185 | } | 185 | } |
186 | 186 | ||
diff --git a/src/fs/gnunet-unindex.c b/src/fs/gnunet-unindex.c index e6af09172..cce08bb20 100644 --- a/src/fs/gnunet-unindex.c +++ b/src/fs/gnunet-unindex.c | |||
@@ -132,8 +132,8 @@ run (void *cls, | |||
132 | ret = 1; | 132 | ret = 1; |
133 | return; | 133 | return; |
134 | } | 134 | } |
135 | uc = GNUNET_FS_unindex (ctx, | 135 | uc = GNUNET_FS_unindex_start (ctx, |
136 | args[0]); | 136 | args[0]); |
137 | if (NULL == uc) | 137 | if (NULL == uc) |
138 | { | 138 | { |
139 | fprintf (stderr, | 139 | fprintf (stderr, |
diff --git a/src/fs/test_fs_download.c b/src/fs/test_fs_download.c index 302dfaaa2..dbdc12fec 100644 --- a/src/fs/test_fs_download.c +++ b/src/fs/test_fs_download.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2004, 2005, 2006, 2008 Christian Grothoff (and other contributing authors) | 3 | (C) 2004, 2005, 2006, 2008, 2009 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -19,306 +19,268 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file applications/fs/fsui/download_persistence_test.c | 22 | * @file fs/test_fs_download.c |
23 | * @brief testcase for fsui download persistence (upload-download) | 23 | * @brief simple testcase for download |
24 | * @author Christian Grothoff | 24 | * @author Christian Grothoff |
25 | */ | 25 | */ |
26 | 26 | ||
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_util.h" | 28 | #include "gnunet_util_lib.h" |
29 | #include "gnunet_fsui_lib.h" | 29 | #include "gnunet_arm_service.h" |
30 | #include "gnunet_fs_service.h" | ||
30 | 31 | ||
31 | #define DEBUG_VERBOSE GNUNET_NO | 32 | #define DEBUG_VERBOSE 42 |
33 | //GNUNET_NO | ||
32 | 34 | ||
33 | #define CHECK(a) if (!(a)) { ok = GNUNET_NO; GNUNET_GE_BREAK(ectx, 0); goto FAILURE; } | 35 | #define START_ARM GNUNET_YES |
34 | 36 | ||
35 | static volatile int suspendRestart = 0; | 37 | #define FILESIZE (1024 * 1024 * 2) |
36 | 38 | ||
37 | static struct GNUNET_GE_Context *ectx; | 39 | /** |
40 | * How long until we give up on transmitting the message? | ||
41 | */ | ||
42 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) | ||
43 | |||
44 | /** | ||
45 | * How long should our test-content live? | ||
46 | */ | ||
47 | #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) | ||
38 | 48 | ||
39 | static char * | 49 | struct PeerContext |
40 | makeName (unsigned int i) | ||
41 | { | 50 | { |
42 | char *fn; | 51 | struct GNUNET_CONFIGURATION_Handle *cfg; |
43 | 52 | struct GNUNET_PeerIdentity id; | |
44 | fn = | 53 | #if START_ARM |
45 | GNUNET_malloc (strlen | 54 | pid_t arm_pid; |
46 | ("/tmp/gnunet-fsui-download_persistence_test/FSUITEST") + | 55 | #endif |
47 | 14); | 56 | }; |
48 | GNUNET_snprintf (fn, | 57 | |
49 | strlen | 58 | static struct PeerContext p1; |
50 | ("/tmp/gnunet-fsui-download_persistence_test/FSUITEST") + | 59 | |
51 | 14, | 60 | |
52 | "/tmp/gnunet-fsui-download_persistence_test/FSUITEST%u", | 61 | static struct GNUNET_SCHEDULER_Handle *sched; |
53 | i); | 62 | |
54 | GNUNET_disk_directory_create_for_file (NULL, fn); | 63 | static struct GNUNET_FS_Handle *fs; |
55 | return fn; | 64 | |
56 | } | 65 | static struct GNUNET_FS_DownloadContext *download; |
66 | |||
67 | static struct GNUNET_FS_PublishContext *publish; | ||
68 | |||
69 | static char *fn; | ||
57 | 70 | ||
58 | static volatile enum GNUNET_FSUI_EventType lastEvent; | ||
59 | static volatile enum GNUNET_FSUI_EventType waitForEvent; | ||
60 | static volatile int download_done; | ||
61 | static struct GNUNET_FSUI_Context *ctx; | ||
62 | static struct GNUNET_ECRS_URI *upURI; | ||
63 | static struct GNUNET_FSUI_DownloadList *download; | ||
64 | 71 | ||
65 | static void * | 72 | static void * |
66 | eventCallback (void *cls, const GNUNET_FSUI_Event * event) | 73 | progress_cb (void *cls, |
74 | const struct GNUNET_FS_ProgressInfo *event) | ||
67 | { | 75 | { |
68 | switch (event->type) | 76 | |
77 | switch (event->status) | ||
69 | { | 78 | { |
70 | case GNUNET_FSUI_download_suspended: | 79 | case GNUNET_FS_STATUS_DOWNLOAD_SUSPEND: |
71 | download = NULL; | 80 | GNUNET_break (0); |
72 | break; | 81 | break; |
73 | case GNUNET_FSUI_download_resumed: | 82 | case GNUNET_FS_STATUS_DOWNLOAD_RESUME: |
74 | #if DEBUG_VERBOSE | 83 | GNUNET_break (0); |
75 | printf ("Download resuming\n"); | ||
76 | #endif | ||
77 | download = event->data.DownloadResumed.dc.pos; | ||
78 | break; | 84 | break; |
79 | case GNUNET_FSUI_upload_progress: | 85 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: |
80 | #if DEBUG_VERBOSE > 1 | 86 | #if DEBUG_VERBOSE > 1 |
81 | printf ("Upload is progressing (%llu/%llu)...\n", | 87 | printf ("Publish is progressing (%llu/%llu)...\n", |
82 | event->data.UploadProgress.completed, | 88 | (unsigned long long) event->value.publish.completed, |
83 | event->data.UploadProgress.total); | 89 | (unsigned long long) event->value.publish.size); |
84 | #endif | 90 | #endif |
85 | break; | 91 | break; |
86 | case GNUNET_FSUI_upload_completed: | 92 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: |
87 | upURI = GNUNET_ECRS_uri_duplicate (event->data.UploadCompleted.uri); | ||
88 | #if DEBUG_VERBOSE | 93 | #if DEBUG_VERBOSE |
89 | printf ("Upload complete.\n"); | 94 | printf ("Publish complete.\n"); |
90 | #endif | 95 | #endif |
96 | GNUNET_FS_publish_stop (publish); | ||
97 | publish = NULL; | ||
98 | fn = GNUNET_DISK_mktemp ("gnunet-download-test-dstXXXXXX"); | ||
99 | download = GNUNET_FS_download_start (fs, | ||
100 | event->value.publish.specifics.completed.chk_uri, | ||
101 | NULL, | ||
102 | fn, | ||
103 | 0, | ||
104 | FILESIZE, | ||
105 | 1, | ||
106 | GNUNET_FS_DOWNLOAD_OPTION_NONE, | ||
107 | NULL); | ||
108 | GNUNET_assert (download != NULL); | ||
91 | break; | 109 | break; |
92 | case GNUNET_FSUI_download_completed: | 110 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: |
93 | #if DEBUG_VERBOSE | 111 | #if DEBUG_VERBOSE |
94 | printf ("Download complete.\n"); | 112 | printf ("Download complete.\n"); |
95 | #endif | 113 | #endif |
96 | download_done = 1; | 114 | GNUNET_FS_download_stop (download, GNUNET_YES); |
115 | download = NULL; | ||
97 | break; | 116 | break; |
98 | case GNUNET_FSUI_download_progress: | 117 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: |
99 | #if DEBUG_VERBOSE > 1 | 118 | #if DEBUG_VERBOSE > 1 |
100 | printf ("Download is progressing (%llu/%llu)...\n", | 119 | printf ("Download is progressing (%llu/%llu)...\n", |
101 | event->data.DownloadProgress.completed, | 120 | (unsigned long long) event->value.download.completed, |
102 | event->data.DownloadProgress.total); | 121 | (unsigned long long) event->value.download.size); |
103 | #endif | 122 | #endif |
104 | break; | 123 | break; |
105 | case GNUNET_FSUI_unindex_progress: | 124 | case GNUNET_FS_STATUS_UNINDEX_PROGRESS: |
106 | #if DEBUG_VERBOSE > 1 | 125 | GNUNET_break (0); |
107 | printf ("Unindex is progressing (%llu/%llu)...\n", | ||
108 | event->data.UnindexProgress.completed, | ||
109 | event->data.UnindexProgress.total); | ||
110 | #endif | ||
111 | break; | 126 | break; |
112 | case GNUNET_FSUI_unindex_completed: | 127 | case GNUNET_FS_STATUS_UNINDEX_COMPLETED: |
113 | #if DEBUG_VERBOSE | 128 | GNUNET_break (0); |
114 | printf ("Unindex complete.\n"); | ||
115 | #endif | ||
116 | break; | 129 | break; |
117 | case GNUNET_FSUI_unindex_error: | 130 | case GNUNET_FS_STATUS_UNINDEX_ERROR: |
118 | case GNUNET_FSUI_upload_error: | 131 | GNUNET_break (0); |
119 | case GNUNET_FSUI_download_error: | 132 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
120 | fprintf (stderr, "Received ERROR: %d\n", event->type); | 133 | GNUNET_break (0); |
121 | GNUNET_GE_BREAK (ectx, 0); | 134 | case GNUNET_FS_STATUS_DOWNLOAD_ERROR: |
135 | GNUNET_break (0); | ||
122 | break; | 136 | break; |
123 | case GNUNET_FSUI_download_aborted: | 137 | case GNUNET_FS_STATUS_UNINDEX_SUSPEND: |
124 | #if DEBUG_VERBOSE | 138 | GNUNET_break (0); |
125 | printf ("Received download aborted event.\n"); | ||
126 | #endif | ||
127 | break; | 139 | break; |
128 | case GNUNET_FSUI_unindex_suspended: | 140 | case GNUNET_FS_STATUS_PUBLISH_SUSPEND: |
129 | case GNUNET_FSUI_upload_suspended: | 141 | GNUNET_break (0); |
130 | #if DEBUG_VERBOSE | 142 | break; |
131 | fprintf (stderr, "Received SUSPENDING: %d\n", event->type); | 143 | case GNUNET_FS_STATUS_PUBLISH_START: |
132 | #endif | 144 | /* FIXME: add checks here... */ |
145 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | ||
146 | /* FIXME: add checks here... */ | ||
147 | case GNUNET_FS_STATUS_DOWNLOAD_START: | ||
148 | /* FIXME: add checks here... */ | ||
149 | break; | ||
150 | case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: | ||
151 | /* FIXME: add checks here... */ | ||
152 | GNUNET_FS_stop (fs); | ||
153 | fs = NULL; | ||
154 | break; | ||
155 | case GNUNET_FS_STATUS_UNINDEX_START: | ||
156 | GNUNET_break (0); | ||
133 | break; | 157 | break; |
134 | case GNUNET_FSUI_upload_started: | 158 | case GNUNET_FS_STATUS_UNINDEX_STOPPED: |
135 | case GNUNET_FSUI_upload_stopped: | 159 | GNUNET_break (0); |
136 | case GNUNET_FSUI_download_started: | ||
137 | case GNUNET_FSUI_download_stopped: | ||
138 | case GNUNET_FSUI_unindex_started: | ||
139 | case GNUNET_FSUI_unindex_stopped: | ||
140 | break; | 160 | break; |
141 | default: | 161 | default: |
142 | printf ("Unexpected event: %d\n", event->type); | 162 | printf ("Unexpected event: %d\n", |
163 | event->status); | ||
143 | break; | 164 | break; |
144 | } | 165 | } |
145 | if (lastEvent == waitForEvent) | ||
146 | return NULL; /* ignore all other events */ | ||
147 | lastEvent = event->type; | ||
148 | return NULL; | 166 | return NULL; |
149 | } | 167 | } |
150 | 168 | ||
151 | #define FILESIZE (1024 * 1024 * 2) | ||
152 | 169 | ||
153 | #define START_DAEMON 1 | 170 | static void |
171 | setup_peer (struct PeerContext *p, const char *cfgname) | ||
172 | { | ||
173 | p->cfg = GNUNET_CONFIGURATION_create (); | ||
174 | #if START_ARM | ||
175 | p->arm_pid = GNUNET_OS_start_process ("gnunet-service-arm", | ||
176 | "gnunet-service-arm", | ||
177 | #if VERBOSE | ||
178 | "-L", "DEBUG", | ||
179 | #endif | ||
180 | "-c", cfgname, NULL); | ||
181 | sleep (1); /* allow ARM to start */ | ||
182 | #endif | ||
183 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | ||
184 | GNUNET_ARM_start_services (p->cfg, sched, "core", NULL); | ||
185 | } | ||
186 | |||
154 | 187 | ||
155 | int | 188 | static void |
156 | main (int argc, char *argv[]) | 189 | stop_arm (struct PeerContext *p) |
157 | { | 190 | { |
158 | #if START_DAEMON | 191 | #if START_ARM |
159 | pid_t daemon; | 192 | if (0 != PLIBC_KILL (p->arm_pid, SIGTERM)) |
193 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
194 | if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK) | ||
195 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | ||
196 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
197 | "ARM process %u stopped\n", p->arm_pid); | ||
160 | #endif | 198 | #endif |
161 | int ok; | 199 | GNUNET_CONFIGURATION_destroy (p->cfg); |
162 | int i; | 200 | } |
163 | char *fn = NULL; | 201 | |
164 | char *keywords[] = { | 202 | |
203 | static void | ||
204 | run (void *cls, | ||
205 | struct GNUNET_SCHEDULER_Handle *s, | ||
206 | char *const *args, | ||
207 | const char *cfgfile, | ||
208 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
209 | { | ||
210 | const char *keywords[] = { | ||
165 | "down_foo", | 211 | "down_foo", |
166 | "down_bar", | 212 | "down_bar", |
167 | }; | 213 | }; |
168 | int prog; | ||
169 | char *buf; | 214 | char *buf; |
170 | struct GNUNET_MetaData *meta = NULL; | 215 | struct GNUNET_CONTAINER_MetaData *meta; |
171 | struct GNUNET_ECRS_URI *kuri = NULL; | 216 | struct GNUNET_FS_Uri *kuri; |
172 | struct GNUNET_GC_Configuration *cfg; | 217 | struct GNUNET_FS_FileInformation *fi; |
173 | struct GNUNET_FSUI_UnindexList *unindex = NULL; | 218 | size_t i; |
174 | struct GNUNET_FSUI_UploadList *upload = NULL; | ||
175 | |||
176 | ok = GNUNET_YES; | ||
177 | cfg = GNUNET_GC_create (); | ||
178 | if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf")) | ||
179 | { | ||
180 | GNUNET_GC_free (cfg); | ||
181 | return -1; | ||
182 | } | ||
183 | #if START_DAEMON | ||
184 | GNUNET_disk_directory_remove (NULL, | ||
185 | "/tmp/gnunet-fsui-download_persistence_test/"); | ||
186 | daemon = GNUNET_daemon_start (NULL, cfg, "peer.conf", GNUNET_NO); | ||
187 | GNUNET_GE_ASSERT (NULL, daemon > 0); | ||
188 | CHECK (GNUNET_OK == | ||
189 | GNUNET_wait_for_daemon_running (NULL, cfg, | ||
190 | 30 * GNUNET_CRON_SECONDS)); | ||
191 | GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS); /* give apps time to start */ | ||
192 | /* ACTUAL TEST CODE */ | ||
193 | #endif | ||
194 | ctx = GNUNET_FSUI_start (NULL, | ||
195 | cfg, "fsuidownload_persistence_test", 32, | ||
196 | GNUNET_YES, &eventCallback, NULL); | ||
197 | CHECK (ctx != NULL); | ||
198 | 219 | ||
199 | /* upload */ | 220 | sched = s; |
200 | fn = makeName (42); | 221 | setup_peer (&p1, "test_fs_download_data.conf"); |
222 | fs = GNUNET_FS_start (sched, | ||
223 | cfg, | ||
224 | "test-fs-download", | ||
225 | &progress_cb, | ||
226 | NULL, | ||
227 | GNUNET_FS_FLAGS_NONE, | ||
228 | GNUNET_FS_OPTIONS_END); | ||
229 | GNUNET_assert (NULL != fs); | ||
201 | buf = GNUNET_malloc (FILESIZE); | 230 | buf = GNUNET_malloc (FILESIZE); |
202 | for (i = 0; i < FILESIZE; i++) | 231 | for (i = 0; i < FILESIZE; i++) |
203 | buf[i] = GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 256); | 232 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); |
204 | GNUNET_disk_file_write (ectx, fn, buf, FILESIZE, "600"); | 233 | meta = GNUNET_CONTAINER_meta_data_create (); |
205 | GNUNET_free (buf); | 234 | kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); |
206 | meta = GNUNET_meta_data_create (); | 235 | fi = GNUNET_FS_file_information_create_from_data ("file-to-publish", |
207 | kuri = | 236 | FILESIZE, |
208 | GNUNET_ECRS_keyword_command_line_to_uri (ectx, 2, | 237 | buf, |
209 | (const char **) keywords); | 238 | kuri, |
210 | waitForEvent = GNUNET_FSUI_upload_completed; | 239 | meta, |
211 | upload = GNUNET_FSUI_upload_start (ctx, | 240 | GNUNET_NO, |
212 | fn, | 241 | 1, |
213 | (GNUNET_FSUI_DirectoryScanCallback) & | 242 | 42, |
214 | GNUNET_disk_directory_scan, NULL, 0, 0, | 243 | GNUNET_TIME_relative_to_absolute (LIFETIME)); |
215 | GNUNET_YES, GNUNET_NO, GNUNET_NO, | 244 | GNUNET_FS_uri_destroy (kuri); |
216 | GNUNET_get_time () + | 245 | GNUNET_CONTAINER_meta_data_destroy (meta); |
217 | 5 * GNUNET_CRON_HOURS, meta, kuri, kuri); | 246 | GNUNET_assert (NULL != fi); |
218 | CHECK (upload != NULL); | 247 | publish = GNUNET_FS_publish_start (fs, |
219 | GNUNET_ECRS_uri_destroy (kuri); | 248 | "publish-context", |
220 | kuri = NULL; | 249 | fi, |
221 | prog = 0; | 250 | NULL, NULL, NULL, |
222 | while (lastEvent != GNUNET_FSUI_upload_completed) | 251 | GNUNET_FS_PUBLISH_OPTION_NONE); |
223 | { | 252 | GNUNET_assert (publish != NULL); |
224 | prog++; | 253 | } |
225 | CHECK (prog < 5000); | 254 | |
226 | GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS); | 255 | |
227 | if (GNUNET_shutdown_test () == GNUNET_YES) | 256 | int |
228 | break; | 257 | main (int argc, char *argv[]) |
229 | } | 258 | { |
230 | GNUNET_FSUI_upload_stop (upload); | 259 | char *const argvx[] = { |
231 | 260 | "test-fs-download", | |
232 | /* download */ | 261 | "-c", |
233 | waitForEvent = GNUNET_FSUI_download_completed; | 262 | "test_fs_download_data.conf", |
234 | GNUNET_free (fn); | 263 | #if VERBOSE |
235 | fn = makeName (43); | 264 | "-L", "DEBUG", |
236 | download_done = 0; | ||
237 | download = GNUNET_FSUI_download_start (ctx, | ||
238 | 0, | ||
239 | GNUNET_NO, | ||
240 | upURI, meta, fn, NULL, NULL); | ||
241 | CHECK (download != NULL); | ||
242 | GNUNET_free (fn); | ||
243 | suspendRestart = 4; | ||
244 | prog = 0; | ||
245 | while (download_done == 0) | ||
246 | { | ||
247 | prog++; | ||
248 | CHECK (prog < 1000); | ||
249 | GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS); | ||
250 | if ((suspendRestart > 0) | ||
251 | && (GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 4) == 0)) | ||
252 | { | ||
253 | #if 1 | ||
254 | #if DEBUG_VERBOSE | ||
255 | printf ("Testing FSUI suspend-resume\n"); | ||
256 | #endif | ||
257 | GNUNET_FSUI_stop (ctx); /* download possibly incomplete | ||
258 | at this point, thus testing resume */ | ||
259 | ctx = GNUNET_FSUI_start (NULL, | ||
260 | cfg, | ||
261 | "fsuidownload_persistence_test", | ||
262 | 32, GNUNET_YES, &eventCallback, NULL); | ||
263 | #if DEBUG_VERBOSE | ||
264 | printf ("Resumed...\n"); | ||
265 | #endif | ||
266 | #endif | 265 | #endif |
267 | suspendRestart--; | 266 | NULL |
268 | } | 267 | }; |
269 | if (GNUNET_shutdown_test () == GNUNET_YES) | 268 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
270 | break; | 269 | GNUNET_GETOPT_OPTION_END |
271 | } | 270 | }; |
272 | GNUNET_FSUI_download_stop (download); | 271 | |
273 | download = NULL; | 272 | GNUNET_log_setup ("test_fs_download", |
274 | 273 | #if VERBOSE | |
275 | /* unindex */ | 274 | "DEBUG", |
276 | waitForEvent = GNUNET_FSUI_unindex_completed; | 275 | #else |
277 | fn = makeName (42); | 276 | "WARNING", |
278 | unindex = GNUNET_FSUI_unindex_start (ctx, fn); | ||
279 | CHECK (unindex != NULL); | ||
280 | prog = 0; | ||
281 | while (lastEvent != GNUNET_FSUI_unindex_completed) | ||
282 | { | ||
283 | prog++; | ||
284 | CHECK (prog < 5000); | ||
285 | GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS); | ||
286 | CHECK (lastEvent != GNUNET_FSUI_unindex_error); | ||
287 | if (GNUNET_shutdown_test () == GNUNET_YES) | ||
288 | break; | ||
289 | } | ||
290 | CHECK (lastEvent == GNUNET_FSUI_unindex_completed); | ||
291 | /* END OF TEST CODE */ | ||
292 | FAILURE: | ||
293 | if (meta != NULL) | ||
294 | GNUNET_meta_data_destroy (meta); | ||
295 | if (ctx != NULL) | ||
296 | { | ||
297 | if (unindex != NULL) | ||
298 | GNUNET_FSUI_unindex_stop (unindex); | ||
299 | if (download != NULL) | ||
300 | GNUNET_FSUI_download_stop (download); | ||
301 | GNUNET_FSUI_stop (ctx); | ||
302 | } | ||
303 | if (fn != NULL) | ||
304 | { | ||
305 | UNLINK (fn); | ||
306 | GNUNET_free (fn); | ||
307 | } | ||
308 | if (kuri != NULL) | ||
309 | GNUNET_ECRS_uri_destroy (kuri); | ||
310 | fn = makeName (43); | ||
311 | /* TODO: verify file 'fn(42)' == file 'fn(43)' */ | ||
312 | UNLINK (fn); | ||
313 | GNUNET_free (fn); | ||
314 | if (upURI != NULL) | ||
315 | GNUNET_ECRS_uri_destroy (upURI); | ||
316 | |||
317 | #if START_DAEMON | ||
318 | GNUNET_GE_BREAK (NULL, GNUNET_OK == GNUNET_daemon_stop (NULL, daemon)); | ||
319 | #endif | 277 | #endif |
320 | GNUNET_GC_free (cfg); | 278 | NULL); |
321 | return (ok == GNUNET_YES) ? 0 : 1; | 279 | GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, |
280 | argvx, "test-fs-download", | ||
281 | "nohelp", options, &run, NULL); | ||
282 | stop_arm (&p1); | ||
283 | return 0; | ||
322 | } | 284 | } |
323 | 285 | ||
324 | /* end of download_persistence_test.c */ | 286 | /* end of test_fs_download.c */ |
diff --git a/src/fs/test_fs_download_data.conf b/src/fs/test_fs_download_data.conf new file mode 100644 index 000000000..8af0d26f2 --- /dev/null +++ b/src/fs/test_fs_download_data.conf | |||
@@ -0,0 +1,33 @@ | |||
1 | [PATHS] | ||
2 | SERVICEHOME = /tmp/gnunet-test-fs-download/ | ||
3 | |||
4 | [gnunetd] | ||
5 | HOSTKEY = $SERVICEHOME/.hostkey | ||
6 | |||
7 | [TESTING] | ||
8 | WEAKRANDOM = YES | ||
9 | |||
10 | [resolver] | ||
11 | PORT = 42464 | ||
12 | |||
13 | [transport] | ||
14 | PORT = 42465 | ||
15 | PLUGINS = | ||
16 | |||
17 | [arm] | ||
18 | PORT = 42466 | ||
19 | |||
20 | [statistics] | ||
21 | PORT = 42467 | ||
22 | |||
23 | [peerinfo] | ||
24 | PORT = 42469 | ||
25 | |||
26 | [core] | ||
27 | PORT = 42470 | ||
28 | |||
29 | [fs] | ||
30 | PORT = 42471 | ||
31 | |||
32 | [testing] | ||
33 | WEAKRANDOM = YES | ||
diff --git a/src/include/gnunet_fs_service.h b/src/include/gnunet_fs_service.h index 5449f6324..21ffe299a 100644 --- a/src/include/gnunet_fs_service.h +++ b/src/include/gnunet_fs_service.h | |||
@@ -891,7 +891,7 @@ struct GNUNET_FS_ProgressInfo | |||
891 | * is NOT necessarily the size from the | 891 | * is NOT necessarily the size from the |
892 | * URI since we may be doing a partial download. | 892 | * URI since we may be doing a partial download. |
893 | */ | 893 | */ |
894 | uint64_t length; | 894 | uint64_t size; |
895 | 895 | ||
896 | /** | 896 | /** |
897 | * At what time do we expect to finish the download? | 897 | * At what time do we expect to finish the download? |
@@ -1590,7 +1590,7 @@ GNUNET_FS_file_information_create_from_file (void *client_info, | |||
1590 | * | 1590 | * |
1591 | * @param length length of the file | 1591 | * @param length length of the file |
1592 | * @param data data for the file (should not be used afterwards by | 1592 | * @param data data for the file (should not be used afterwards by |
1593 | * the caller; caller will "free") | 1593 | * the caller; callee will "free") |
1594 | * @param keywords under which keywords should this file be available | 1594 | * @param keywords under which keywords should this file be available |
1595 | * directly; can be NULL | 1595 | * directly; can be NULL |
1596 | * @param meta metadata for the file | 1596 | * @param meta metadata for the file |
@@ -2017,9 +2017,10 @@ GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h, | |||
2017 | * @param filename file to unindex | 2017 | * @param filename file to unindex |
2018 | * @return NULL on error, otherwise handle | 2018 | * @return NULL on error, otherwise handle |
2019 | */ | 2019 | */ |
2020 | // FIXME: add a "void *" context for the client to arguments!? | ||
2020 | struct GNUNET_FS_UnindexContext * | 2021 | struct GNUNET_FS_UnindexContext * |
2021 | GNUNET_FS_unindex (struct GNUNET_FS_Handle *h, | 2022 | GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h, |
2022 | const char *filename); | 2023 | const char *filename); |
2023 | 2024 | ||
2024 | 2025 | ||
2025 | /** | 2026 | /** |
@@ -2156,6 +2157,7 @@ GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace, | |||
2156 | * @param anonymity desired level of anonymity | 2157 | * @param anonymity desired level of anonymity |
2157 | * @return context that can be used to control the search | 2158 | * @return context that can be used to control the search |
2158 | */ | 2159 | */ |
2160 | // FIXME: add a "void *" context for the client to arguments!? | ||
2159 | struct GNUNET_FS_SearchContext * | 2161 | struct GNUNET_FS_SearchContext * |
2160 | GNUNET_FS_search_start (struct GNUNET_FS_Handle *h, | 2162 | GNUNET_FS_search_start (struct GNUNET_FS_Handle *h, |
2161 | const struct GNUNET_FS_Uri *uri, | 2163 | const struct GNUNET_FS_Uri *uri, |
@@ -2243,16 +2245,17 @@ enum GNUNET_FS_DownloadOptions | |||
2243 | * for top-level downloads; useful for manually-triggered recursive downloads) | 2245 | * for top-level downloads; useful for manually-triggered recursive downloads) |
2244 | * @return context that can be used to control this download | 2246 | * @return context that can be used to control this download |
2245 | */ | 2247 | */ |
2248 | // FIXME: add a "void *" context for the client to arguments!? | ||
2246 | struct GNUNET_FS_DownloadContext * | 2249 | struct GNUNET_FS_DownloadContext * |
2247 | GNUNET_FS_file_download_start (struct GNUNET_FS_Handle *h, | 2250 | GNUNET_FS_download_start (struct GNUNET_FS_Handle *h, |
2248 | const struct GNUNET_FS_Uri *uri, | 2251 | const struct GNUNET_FS_Uri *uri, |
2249 | const struct GNUNET_CONTAINER_MetaData *meta, | 2252 | const struct GNUNET_CONTAINER_MetaData *meta, |
2250 | const char *filename, | 2253 | const char *filename, |
2251 | uint64_t offset, | 2254 | uint64_t offset, |
2252 | uint64_t length, | 2255 | uint64_t length, |
2253 | uint32_t anonymity, | 2256 | uint32_t anonymity, |
2254 | enum GNUNET_FS_DownloadOptions options, | 2257 | enum GNUNET_FS_DownloadOptions options, |
2255 | struct GNUNET_FS_DownloadContext *parent); | 2258 | struct GNUNET_FS_DownloadContext *parent); |
2256 | 2259 | ||
2257 | 2260 | ||
2258 | /** | 2261 | /** |
@@ -2262,8 +2265,8 @@ GNUNET_FS_file_download_start (struct GNUNET_FS_Handle *h, | |||
2262 | * @param do_delete delete files of incomplete downloads | 2265 | * @param do_delete delete files of incomplete downloads |
2263 | */ | 2266 | */ |
2264 | void | 2267 | void |
2265 | GNUNET_FS_file_download_stop (struct GNUNET_FS_DownloadContext *dc, | 2268 | GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, |
2266 | int do_delete); | 2269 | int do_delete); |
2267 | 2270 | ||
2268 | 2271 | ||
2269 | /** | 2272 | /** |