diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-11-24 22:49:37 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-11-24 22:49:37 +0000 |
commit | 36af7ef06904dfeb143ffe322caac8ab09cedd70 (patch) | |
tree | b5a60725de659179c62b808a18f7365af507548b /src/fs/test_fs_download.c | |
parent | 8a5f6d9ccecf75d0faf56dd0d3b6c48a9041275d (diff) | |
download | gnunet-36af7ef06904dfeb143ffe322caac8ab09cedd70.tar.gz gnunet-36af7ef06904dfeb143ffe322caac8ab09cedd70.zip |
combining test_fs_download.c and test_fs_download_index.c into one file, adding additional test test_fs_download_stream
Diffstat (limited to 'src/fs/test_fs_download.c')
-rw-r--r-- | src/fs/test_fs_download.c | 94 |
1 files changed, 78 insertions, 16 deletions
diff --git a/src/fs/test_fs_download.c b/src/fs/test_fs_download.c index 6d3ccff6e..e1c2fbd68 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, 2009, 2011 Christian Grothoff (and other contributing authors) | 3 | (C) 2004, 2005, 2006, 2008, 2009, 2011, 2012 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 |
@@ -45,6 +45,9 @@ | |||
45 | */ | 45 | */ |
46 | #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) | 46 | #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) |
47 | 47 | ||
48 | static unsigned int anonymity_level; | ||
49 | |||
50 | static int indexed; | ||
48 | 51 | ||
49 | static struct GNUNET_TIME_Absolute start; | 52 | static struct GNUNET_TIME_Absolute start; |
50 | 53 | ||
@@ -58,6 +61,8 @@ static GNUNET_SCHEDULER_TaskIdentifier timeout_kill; | |||
58 | 61 | ||
59 | static char *fn; | 62 | static char *fn; |
60 | 63 | ||
64 | static char *fn1; | ||
65 | |||
61 | static int err; | 66 | static int err; |
62 | 67 | ||
63 | 68 | ||
@@ -141,18 +146,22 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) | |||
141 | (1 + | 146 | (1 + |
142 | GNUNET_TIME_absolute_get_duration | 147 | GNUNET_TIME_absolute_get_duration |
143 | (start).rel_value) / 1024LL)); | 148 | (start).rel_value) / 1024LL)); |
144 | GAUGER ("FS", "Publishing speed (insertion)", | 149 | GAUGER ("FS", |
145 | (unsigned long long) (FILESIZE * 1000LL / | 150 | (GNUNET_YES == indexed) |
146 | (1 + | 151 | ? "Publishing speed (indexing)" |
147 | GNUNET_TIME_absolute_get_duration | 152 | : "Publishing speed (insertion)", |
148 | (start).rel_value) / 1024LL), "kb/s"); | 153 | (unsigned long long) (FILESIZE * 1000LL / |
154 | (1 + | ||
155 | GNUNET_TIME_absolute_get_duration | ||
156 | (start).rel_value) / 1024LL), "kb/s"); | ||
149 | fn = GNUNET_DISK_mktemp ("gnunet-download-test-dst"); | 157 | fn = GNUNET_DISK_mktemp ("gnunet-download-test-dst"); |
150 | start = GNUNET_TIME_absolute_get (); | 158 | start = GNUNET_TIME_absolute_get (); |
151 | download = | 159 | download = |
152 | GNUNET_FS_download_start (fs, | 160 | GNUNET_FS_download_start (fs, |
153 | event->value.publish.specifics. | 161 | event->value.publish.specifics. |
154 | completed.chk_uri, NULL, fn, NULL, 0, | 162 | completed.chk_uri, NULL, fn, NULL, 0, |
155 | FILESIZE, 1, GNUNET_FS_DOWNLOAD_OPTION_NONE, | 163 | FILESIZE, anonymity_level, |
164 | GNUNET_FS_DOWNLOAD_OPTION_NONE, | ||
156 | "download", NULL); | 165 | "download", NULL); |
157 | GNUNET_assert (download != NULL); | 166 | GNUNET_assert (download != NULL); |
158 | break; | 167 | break; |
@@ -163,7 +172,10 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) | |||
163 | (1 + | 172 | (1 + |
164 | GNUNET_TIME_absolute_get_duration | 173 | GNUNET_TIME_absolute_get_duration |
165 | (start).rel_value) / 1024LL)); | 174 | (start).rel_value) / 1024LL)); |
166 | GAUGER ("FS", "Local download speed (inserted)", | 175 | GAUGER ("FS", |
176 | (GNUNET_YES == indexed) | ||
177 | ? "Local download speed (indexed)" | ||
178 | : "Local download speed (inserted)", | ||
167 | (unsigned long long) (FILESIZE * 1000LL / | 179 | (unsigned long long) (FILESIZE * 1000LL / |
168 | (1 + | 180 | (1 + |
169 | GNUNET_TIME_absolute_get_duration | 181 | GNUNET_TIME_absolute_get_duration |
@@ -235,6 +247,7 @@ run (void *cls, | |||
235 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 247 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
236 | struct GNUNET_TESTING_Peer *peer) | 248 | struct GNUNET_TESTING_Peer *peer) |
237 | { | 249 | { |
250 | const char *binary_name = cls; | ||
238 | const char *keywords[] = { | 251 | const char *keywords[] = { |
239 | "down_foo", | 252 | "down_foo", |
240 | "down_bar", | 253 | "down_bar", |
@@ -246,7 +259,14 @@ run (void *cls, | |||
246 | size_t i; | 259 | size_t i; |
247 | struct GNUNET_FS_BlockOptions bo; | 260 | struct GNUNET_FS_BlockOptions bo; |
248 | 261 | ||
249 | fs = GNUNET_FS_start (cfg, "test-fs-download", &progress_cb, NULL, | 262 | if (GNUNET_YES == |
263 | GNUNET_CONFIGURATION_get_value_yesno (cfg, | ||
264 | "download-test", | ||
265 | "USE_STREAM")) | ||
266 | anonymity_level = 0; | ||
267 | else | ||
268 | anonymity_level = 1; | ||
269 | fs = GNUNET_FS_start (cfg, binary_name, &progress_cb, NULL, | ||
250 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); | 270 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); |
251 | GNUNET_assert (NULL != fs); | 271 | GNUNET_assert (NULL != fs); |
252 | buf = GNUNET_malloc (FILESIZE); | 272 | buf = GNUNET_malloc (FILESIZE); |
@@ -255,12 +275,34 @@ run (void *cls, | |||
255 | meta = GNUNET_CONTAINER_meta_data_create (); | 275 | meta = GNUNET_CONTAINER_meta_data_create (); |
256 | kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); | 276 | kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); |
257 | bo.content_priority = 42; | 277 | bo.content_priority = 42; |
258 | bo.anonymity_level = 1; | 278 | bo.anonymity_level = anonymity_level; |
259 | bo.replication_level = 0; | 279 | bo.replication_level = 0; |
260 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); | 280 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); |
261 | fi = GNUNET_FS_file_information_create_from_data (fs, "publish-context", | 281 | |
262 | FILESIZE, buf, kuri, meta, | 282 | if (GNUNET_YES == |
263 | GNUNET_NO, &bo); | 283 | GNUNET_CONFIGURATION_get_value_yesno (cfg, |
284 | "download-test", | ||
285 | "USE_INDEX")) | ||
286 | { | ||
287 | fn1 = GNUNET_DISK_mktemp ("gnunet-download-indexed-test"); | ||
288 | GNUNET_assert (FILESIZE == | ||
289 | GNUNET_DISK_fn_write (fn1, buf, FILESIZE, | ||
290 | GNUNET_DISK_PERM_USER_READ | | ||
291 | GNUNET_DISK_PERM_USER_WRITE)); | ||
292 | GNUNET_free (buf); | ||
293 | fi = GNUNET_FS_file_information_create_from_file (fs, "publish-context", fn1, | ||
294 | kuri, meta, GNUNET_YES, | ||
295 | &bo); | ||
296 | indexed = GNUNET_YES; | ||
297 | } | ||
298 | else | ||
299 | { | ||
300 | fi = GNUNET_FS_file_information_create_from_data (fs, "publish-context", | ||
301 | FILESIZE, buf, kuri, meta, | ||
302 | GNUNET_NO, &bo); | ||
303 | /* note: buf will be free'd as part of 'fi' now */ | ||
304 | indexed = GNUNET_NO; | ||
305 | } | ||
264 | GNUNET_FS_uri_destroy (kuri); | 306 | GNUNET_FS_uri_destroy (kuri); |
265 | GNUNET_CONTAINER_meta_data_destroy (meta); | 307 | GNUNET_CONTAINER_meta_data_destroy (meta); |
266 | GNUNET_assert (NULL != fi); | 308 | GNUNET_assert (NULL != fi); |
@@ -277,10 +319,30 @@ run (void *cls, | |||
277 | int | 319 | int |
278 | main (int argc, char *argv[]) | 320 | main (int argc, char *argv[]) |
279 | { | 321 | { |
280 | if (0 != GNUNET_TESTING_peer_run ("test-fs-download", | 322 | const char *binary_name; |
281 | "test_fs_download_data.conf", | 323 | const char *config_name; |
282 | &run, NULL)) | 324 | |
325 | binary_name = "test-fs-download"; | ||
326 | config_name = "test_fs_download_data.conf"; | ||
327 | if (NULL != strstr (argv[0], "indexed")) | ||
328 | { | ||
329 | binary_name = "test-fs-download-indexed"; | ||
330 | config_name = "test_fs_download_indexed.conf"; | ||
331 | } | ||
332 | if (NULL != strstr (argv[0], "stream")) | ||
333 | { | ||
334 | binary_name = "test-fs-download-stream"; | ||
335 | config_name = "test_fs_download_stream.conf"; | ||
336 | } | ||
337 | if (0 != GNUNET_TESTING_peer_run (binary_name, | ||
338 | config_name, | ||
339 | &run, (void *) binary_name)) | ||
283 | return 1; | 340 | return 1; |
341 | if (NULL != fn1) | ||
342 | { | ||
343 | UNLINK (fn1); | ||
344 | GNUNET_free (fn1); | ||
345 | } | ||
284 | return err; | 346 | return err; |
285 | } | 347 | } |
286 | 348 | ||