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_NO
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];
51 static struct GNUNET_SCHEDULER_Handle *sched;
55 static struct GNUNET_TIME_Absolute start_time;
59 const struct GNUNET_SCHEDULER_TaskContext *tc)
61 struct GNUNET_TIME_Relative del;
64 GNUNET_FS_TEST_daemons_stop (sched,
67 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
69 del = GNUNET_TIME_absolute_get_duration (start_time);
72 fancy = GNUNET_STRINGS_byte_size_fancy (((unsigned long long)FILESIZE) * 1000LL / del.value);
74 "Download speed was %s/s\n",
77 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
78 "Finished download, shutting down\n",
79 (unsigned long long) FILESIZE);
83 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
84 "Timeout during download, shutting down with error\n");
91 do_download (void *cls,
94 struct GNUNET_FS_Uri *uri = cls;
98 GNUNET_FS_TEST_daemons_stop (sched,
101 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
102 "Failed to stop source daemon: %s\n",
104 GNUNET_FS_uri_destroy (uri);
108 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
109 "Downloading %llu bytes\n",
110 (unsigned long long) FILESIZE);
111 start_time = GNUNET_TIME_absolute_get ();
112 GNUNET_FS_TEST_download (sched,
118 GNUNET_FS_uri_destroy (uri);
123 stop_source_peer (void *cls,
124 const struct GNUNET_SCHEDULER_TaskContext *tc)
126 struct GNUNET_FS_Uri *uri = cls;
127 struct GNUNET_TESTING_PeerGroup *pg;
129 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
130 "Stopping source peer\n");
131 pg = GNUNET_FS_TEST_get_group (daemons);
132 GNUNET_TESTING_daemons_vary (pg, 1, GNUNET_NO, TIMEOUT,
140 const struct GNUNET_FS_Uri *uri)
142 struct GNUNET_FS_Uri *d;
146 GNUNET_FS_TEST_daemons_stop (sched,
149 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
150 "Timeout during upload attempt, shutting down with error\n");
154 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
155 "Waiting to allow content to migrate\n");
156 d = GNUNET_FS_uri_dup (uri);
157 (void) GNUNET_SCHEDULER_add_delayed (sched,
165 do_publish (void *cls,
166 const struct GNUNET_SCHEDULER_TaskContext *tc)
168 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
170 GNUNET_FS_TEST_daemons_stop (sched,
173 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
174 "Timeout during connect attempt, shutting down with error\n");
178 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
179 "Publishing %llu bytes\n",
180 (unsigned long long) FILESIZE);
181 GNUNET_FS_TEST_publish (sched,
184 1, GNUNET_NO, FILESIZE, SEED,
191 do_connect (void *cls,
192 const struct GNUNET_SCHEDULER_TaskContext *tc)
194 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
197 "Daemons failed to start!\n");
202 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
203 "Daemons started, will now try to connect them\n");
204 GNUNET_FS_TEST_daemons_connect (sched,
215 struct GNUNET_SCHEDULER_Handle *s,
218 const struct GNUNET_CONFIGURATION_Handle *cfg)
221 GNUNET_FS_TEST_daemons_start (sched,
222 "test_gnunet_service_fs_migration_data.conf",
232 main (int argc, char *argv[])
234 char *const argvx[] = {
235 "test-gnunet-service-fs-migration",
237 "fs_test_lib_data.conf",
243 struct GNUNET_GETOPT_CommandLineOption options[] = {
244 GNUNET_GETOPT_OPTION_END
247 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/");
248 GNUNET_log_setup ("test_gnunet_service_fs_migration",
255 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
256 argvx, "test-gnunet-service-fs-migration",
257 "nohelp", options, &run, NULL);
258 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/");
262 /* end of test_gnunet_service_fs_migration.c */