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 2, 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, 5)
43 * How long do we give the peers for content migration?
45 #define MIGRATION_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
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",
107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
108 "Downloading %llu bytes\n",
109 (unsigned long long) FILESIZE);
110 start_time = GNUNET_TIME_absolute_get ();
111 GNUNET_FS_TEST_download (sched,
121 stop_source_peer (void *cls,
122 const struct GNUNET_SCHEDULER_TaskContext *tc)
124 struct GNUNET_FS_Uri *uri = cls;
125 struct GNUNET_TESTING_PeerGroup *pg;
127 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
128 "Stopping source peer\n");
129 pg = GNUNET_FS_TEST_get_group (daemons);
130 GNUNET_TESTING_daemons_vary (pg, 1, GNUNET_NO, TIMEOUT,
138 const struct GNUNET_FS_Uri *uri)
140 struct GNUNET_FS_Uri *d;
144 GNUNET_FS_TEST_daemons_stop (sched,
147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
148 "Timeout during upload attempt, shutting down with error\n");
152 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
153 "Waiting to allow content to migrate\n");
154 d = GNUNET_FS_uri_dup (uri);
155 GNUNET_SCHEDULER_add_delayed (sched,
163 do_publish (void *cls,
164 const struct GNUNET_SCHEDULER_TaskContext *tc)
166 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
168 GNUNET_FS_TEST_daemons_stop (sched,
171 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
172 "Timeout during connect attempt, shutting down with error\n");
176 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
177 "Publishing %llu bytes\n",
178 (unsigned long long) FILESIZE);
179 GNUNET_FS_TEST_publish (sched,
182 1, GNUNET_NO, FILESIZE, SEED,
189 do_connect (void *cls,
190 const struct GNUNET_SCHEDULER_TaskContext *tc)
192 GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE));
193 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
194 "Daemons started, will now try to connect them\n");
195 GNUNET_FS_TEST_daemons_connect (sched,
206 struct GNUNET_SCHEDULER_Handle *s,
209 const struct GNUNET_CONFIGURATION_Handle *cfg)
212 GNUNET_FS_TEST_daemons_start (sched,
213 "test_gnunet_service_fs_migration_data.conf",
223 main (int argc, char *argv[])
225 char *const argvx[] = {
226 "test-gnunet-service-fs-migration",
228 "fs_test_lib_data.conf",
234 struct GNUNET_GETOPT_CommandLineOption options[] = {
235 GNUNET_GETOPT_OPTION_END
238 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/");
239 GNUNET_log_setup ("test_gnunet_service_fs_migration",
246 system ("netstat -ntpl");
247 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
248 argvx, "test-gnunet-service-fs-migration",
249 "nohelp", options, &run, NULL);
250 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/");
254 /* end of test_gnunet_service_fs_migration.c */