2 This file is part of GNUnet.
3 (C) 2010 Christian Grothoff (and other contributing authors)
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
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file fs/test_gnunet_service_fs_migration.c
23 * @brief test content migration between two peers
24 * @author Christian Grothoff
27 #include "fs_test_lib.h"
28 #include "gnunet_testing_lib.h"
30 #define VERBOSE GNUNET_YES
33 * File-size we use for testing.
35 #define FILESIZE (2 * 32 * 1024)
38 * How long until we give up on transmitting the message?
40 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
43 * How long do we give the peers for content migration?
45 #define MIGRATION_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
49 static struct GNUNET_FS_TestDaemon *daemons[2];
53 static struct GNUNET_TIME_Absolute start_time;
57 const struct GNUNET_SCHEDULER_TaskContext *tc)
59 struct GNUNET_TIME_Relative del;
62 GNUNET_FS_TEST_daemons_stop (2,
64 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
66 del = GNUNET_TIME_absolute_get_duration (start_time);
67 if (del.rel_value == 0)
69 fancy = GNUNET_STRINGS_byte_size_fancy (((unsigned long long)FILESIZE) * 1000LL / del.rel_value);
71 "Download speed was %s/s\n",
74 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
75 "Finished download, shutting down\n",
76 (unsigned long long) FILESIZE);
80 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
81 "Timeout during download, shutting down with error\n");
88 do_download (void *cls,
91 struct GNUNET_FS_Uri *uri = cls;
95 GNUNET_FS_TEST_daemons_stop (2,
97 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
98 "Failed to stop source daemon: %s\n",
100 GNUNET_FS_uri_destroy (uri);
104 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
105 "Downloading %llu bytes\n",
106 (unsigned long long) FILESIZE);
107 start_time = GNUNET_TIME_absolute_get ();
108 GNUNET_FS_TEST_download (daemons[0],
113 GNUNET_FS_uri_destroy (uri);
118 stop_source_peer (void *cls,
119 const struct GNUNET_SCHEDULER_TaskContext *tc)
121 struct GNUNET_FS_Uri *uri = cls;
122 struct GNUNET_TESTING_PeerGroup *pg;
124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
125 "Stopping source peer\n");
126 pg = GNUNET_FS_TEST_get_group (daemons);
127 GNUNET_TESTING_daemons_vary (pg, 1, GNUNET_NO, TIMEOUT,
135 const struct GNUNET_FS_Uri *uri)
137 struct GNUNET_FS_Uri *d;
141 GNUNET_FS_TEST_daemons_stop (2,
143 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
144 "Timeout during upload attempt, shutting down with error\n");
148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
149 "Waiting to allow content to migrate\n");
150 d = GNUNET_FS_uri_dup (uri);
151 (void) GNUNET_SCHEDULER_add_delayed (MIGRATION_DELAY,
158 do_publish (void *cls,
159 const struct GNUNET_SCHEDULER_TaskContext *tc)
161 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
163 GNUNET_FS_TEST_daemons_stop (2,
165 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
166 "Timeout during connect attempt, shutting down with error\n");
170 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
171 "Publishing %llu bytes\n",
172 (unsigned long long) FILESIZE);
173 GNUNET_FS_TEST_publish (daemons[1],
175 1, GNUNET_NO, FILESIZE, SEED,
182 do_connect (void *cls,
183 const struct GNUNET_SCHEDULER_TaskContext *tc)
185 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
188 "Daemons failed to start!\n");
193 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
194 "Daemons started, will now try to connect them\n");
195 GNUNET_FS_TEST_daemons_connect (daemons[0],
207 const struct GNUNET_CONFIGURATION_Handle *cfg)
209 GNUNET_FS_TEST_daemons_start ("test_gnunet_service_fs_migration_data.conf",
219 main (int argc, char *argv[])
221 char *const argvx[] = {
222 "test-gnunet-service-fs-migration",
224 "fs_test_lib_data.conf",
230 struct GNUNET_GETOPT_CommandLineOption options[] = {
231 GNUNET_GETOPT_OPTION_END
234 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/");
235 GNUNET_log_setup ("test_gnunet_service_fs_migration",
242 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
243 argvx, "test-gnunet-service-fs-migration",
244 "nohelp", options, &run, NULL);
245 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/");
249 /* end of test_gnunet_service_fs_migration.c */