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];
53 static struct GNUNET_TIME_Absolute start_time;
56 do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
58 struct GNUNET_TIME_Relative del;
61 GNUNET_FS_TEST_daemons_stop (2, daemons);
62 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
64 del = GNUNET_TIME_absolute_get_duration (start_time);
65 if (del.rel_value == 0)
68 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
69 1000LL / del.rel_value);
70 fprintf (stdout, "Download speed was %s/s\n", fancy);
72 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
73 "Finished download, shutting down\n",
74 (unsigned long long) FILESIZE);
78 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
79 "Timeout during download, shutting down with error\n");
86 do_download (void *cls, const char *emsg)
88 struct GNUNET_FS_Uri *uri = cls;
92 GNUNET_FS_TEST_daemons_stop (2, daemons);
93 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
94 "Failed to stop source daemon: %s\n", emsg);
95 GNUNET_FS_uri_destroy (uri);
99 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
100 "Downloading %llu bytes\n", (unsigned long long) FILESIZE);
101 start_time = GNUNET_TIME_absolute_get ();
102 GNUNET_FS_TEST_download (daemons[0],
103 TIMEOUT, 1, SEED, uri, VERBOSE, &do_stop, NULL);
104 GNUNET_FS_uri_destroy (uri);
109 stop_source_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
111 struct GNUNET_FS_Uri *uri = cls;
112 struct GNUNET_TESTING_PeerGroup *pg;
114 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping source peer\n");
115 pg = GNUNET_FS_TEST_get_group (daemons);
116 GNUNET_TESTING_daemons_vary (pg, 1, GNUNET_NO, TIMEOUT, &do_download, uri);
121 do_wait (void *cls, const struct GNUNET_FS_Uri *uri)
123 struct GNUNET_FS_Uri *d;
127 GNUNET_FS_TEST_daemons_stop (2, daemons);
128 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
129 "Timeout during upload attempt, shutting down with error\n");
133 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Waiting to allow content to migrate\n");
134 d = GNUNET_FS_uri_dup (uri);
135 (void) GNUNET_SCHEDULER_add_delayed (MIGRATION_DELAY, &stop_source_peer, d);
140 do_publish (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
142 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
144 GNUNET_FS_TEST_daemons_stop (2, daemons);
145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
146 "Timeout during connect attempt, shutting down with error\n");
150 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
151 "Publishing %llu bytes\n", (unsigned long long) FILESIZE);
152 GNUNET_FS_TEST_publish (daemons[1],
154 1, GNUNET_NO, FILESIZE, SEED,
155 VERBOSE, &do_wait, NULL);
160 do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
162 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
164 fprintf (stderr, "Daemons failed to start!\n");
169 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
170 "Daemons started, will now try to connect them\n");
171 GNUNET_FS_TEST_daemons_connect (daemons[0],
172 daemons[1], TIMEOUT, &do_publish, NULL);
179 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
181 GNUNET_FS_TEST_daemons_start ("test_gnunet_service_fs_migration_data.conf",
182 TIMEOUT, 2, daemons, &do_connect, NULL);
187 main (int argc, char *argv[])
189 char *const argvx[] = {
190 "test-gnunet-service-fs-migration",
192 "fs_test_lib_data.conf",
198 struct GNUNET_GETOPT_CommandLineOption options[] = {
199 GNUNET_GETOPT_OPTION_END
202 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/");
203 GNUNET_log_setup ("test_gnunet_service_fs_migration",
210 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
211 argvx, "test-gnunet-service-fs-migration",
212 "nohelp", options, &run, NULL);
213 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/");
217 /* end of test_gnunet_service_fs_migration.c */