2 This file is part of GNUnet.
3 Copyright (C) 2010, 2012, 2015 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * @file fs/test_gnunet_service_fs_migration.c
21 * @brief test content migration between two peers
22 * @author Christian Grothoff
25 #include "fs_test_lib.h"
26 #include "gnunet_testbed_service.h"
28 #define VERBOSE GNUNET_NO
31 * File-size we use for testing.
33 #define FILESIZE (2 * 32 * 1024)
36 * How long until we give up on transmitting the message?
38 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
41 * How long do we give the peers for content migration?
43 #define MIGRATION_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90)
47 static struct GNUNET_TESTBED_Peer *daemons[2];
51 static struct GNUNET_TIME_Absolute start_time;
53 static struct GNUNET_TESTBED_Operation *op;
56 struct DownloadContext
60 struct GNUNET_FS_Uri *uri;
67 struct GNUNET_TIME_Relative del;
70 GNUNET_SCHEDULER_shutdown ();
72 GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_add (start_time,
73 TIMEOUT)).rel_value_us)
75 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
76 "Timeout during download, shutting down with error\n");
81 del = GNUNET_TIME_absolute_get_duration (start_time);
82 if (del.rel_value_us == 0)
85 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
86 1000000LL / del.rel_value_us);
88 "Download speed was %s/s\n",
91 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
92 "Finished download, shutting down\n");
98 do_download (void *cls,
101 struct DownloadContext *dc = cls;
102 struct GNUNET_FS_Uri *uri = dc->uri;
104 GNUNET_TESTBED_operation_done (op);
108 GNUNET_DISK_directory_remove (dc->fn);
109 GNUNET_free (dc->fn);
114 GNUNET_SCHEDULER_shutdown ();
115 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
116 "Failed to stop source daemon: %s\n",
118 GNUNET_FS_uri_destroy (uri);
122 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
123 "Downloading %llu bytes\n",
124 (unsigned long long) FILESIZE);
125 start_time = GNUNET_TIME_absolute_get ();
126 GNUNET_FS_TEST_download (daemons[0],
134 GNUNET_FS_uri_destroy (uri);
139 stop_source_peer (void *cls)
141 struct DownloadContext *dc = cls;
143 /* FIXME: We should not interact with testbed when shutting down */
144 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
145 "Stopping source peer\n");
146 op = GNUNET_TESTBED_peer_stop (NULL,
149 GNUNET_assert (NULL != op);
155 const struct GNUNET_FS_Uri *uri,
158 struct DownloadContext *dc;
162 GNUNET_SCHEDULER_shutdown ();
163 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
164 "Timeout during upload attempt, shutting down with error\n");
168 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
169 "Waiting to allow content to migrate\n");
170 dc = GNUNET_new (struct DownloadContext);
171 dc->uri = GNUNET_FS_uri_dup (uri);
173 dc->fn = GNUNET_strdup (fn);
174 (void) GNUNET_SCHEDULER_add_delayed (MIGRATION_DELAY,
181 do_publish (void *cls,
182 struct GNUNET_TESTBED_RunHandle *h,
183 unsigned int num_peers,
184 struct GNUNET_TESTBED_Peer **peers,
185 unsigned int links_succeeded,
186 unsigned int links_failed)
190 GNUNET_assert (2 == num_peers);
191 for (i=0;i<num_peers;i++)
192 daemons[i] = peers[i];
193 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
194 "Publishing %llu bytes\n",
195 (unsigned long long) FILESIZE);
196 GNUNET_FS_TEST_publish (daemons[1], TIMEOUT, 1, GNUNET_NO,
198 VERBOSE, &do_wait, NULL);
206 (void) GNUNET_TESTBED_test_run ("test-gnunet-service-fs-migration",
207 "fs_test_lib_data.conf",
212 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/");
216 /* end of test_gnunet_service_fs_migration.c */