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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
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_testbed_service.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, 90)
49 static struct GNUNET_TESTBED_Peer *daemons[2];
53 static struct GNUNET_TIME_Absolute start_time;
55 static struct GNUNET_TESTBED_Operation *op;
58 struct DownloadContext
62 struct GNUNET_FS_Uri *uri;
69 struct GNUNET_TIME_Relative del;
72 GNUNET_SCHEDULER_shutdown ();
74 GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_add (start_time,
75 TIMEOUT)).rel_value_us)
77 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
78 "Timeout during download, shutting down with error\n");
83 del = GNUNET_TIME_absolute_get_duration (start_time);
84 if (del.rel_value_us == 0)
87 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
88 1000000LL / del.rel_value_us);
90 "Download speed was %s/s\n",
93 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
94 "Finished download, shutting down\n");
100 do_download (void *cls,
103 struct DownloadContext *dc = cls;
104 struct GNUNET_FS_Uri *uri = dc->uri;
106 GNUNET_TESTBED_operation_done (op);
110 GNUNET_DISK_directory_remove (dc->fn);
111 GNUNET_free (dc->fn);
116 GNUNET_SCHEDULER_shutdown ();
117 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
118 "Failed to stop source daemon: %s\n",
120 GNUNET_FS_uri_destroy (uri);
124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
125 "Downloading %llu bytes\n",
126 (unsigned long long) FILESIZE);
127 start_time = GNUNET_TIME_absolute_get ();
128 GNUNET_FS_TEST_download (daemons[0],
136 GNUNET_FS_uri_destroy (uri);
141 stop_source_peer (void *cls)
143 struct DownloadContext *dc = cls;
145 /* FIXME: We should not interact with testbed when shutting down */
146 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
147 "Stopping source peer\n");
148 op = GNUNET_TESTBED_peer_stop (NULL,
151 GNUNET_assert (NULL != op);
157 const struct GNUNET_FS_Uri *uri,
160 struct DownloadContext *dc;
164 GNUNET_SCHEDULER_shutdown ();
165 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
166 "Timeout during upload attempt, shutting down with error\n");
170 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
171 "Waiting to allow content to migrate\n");
172 dc = GNUNET_new (struct DownloadContext);
173 dc->uri = GNUNET_FS_uri_dup (uri);
175 dc->fn = GNUNET_strdup (fn);
176 (void) GNUNET_SCHEDULER_add_delayed (MIGRATION_DELAY,
183 do_publish (void *cls,
184 struct GNUNET_TESTBED_RunHandle *h,
185 unsigned int num_peers,
186 struct GNUNET_TESTBED_Peer **peers,
187 unsigned int links_succeeded,
188 unsigned int links_failed)
192 GNUNET_assert (2 == num_peers);
193 for (i=0;i<num_peers;i++)
194 daemons[i] = peers[i];
195 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
196 "Publishing %llu bytes\n",
197 (unsigned long long) FILESIZE);
198 GNUNET_FS_TEST_publish (daemons[1], TIMEOUT, 1, GNUNET_NO,
200 VERBOSE, &do_wait, NULL);
208 (void) GNUNET_TESTBED_test_run ("test-gnunet-service-fs-migration",
209 "fs_test_lib_data.conf",
214 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/");
218 /* end of test_gnunet_service_fs_migration.c */