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
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, 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_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",
95 (unsigned long long) FILESIZE);
101 do_download (void *cls,
104 struct DownloadContext *dc = cls;
105 struct GNUNET_FS_Uri *uri = dc->uri;
107 GNUNET_TESTBED_operation_done (op);
111 GNUNET_DISK_directory_remove (dc->fn);
112 GNUNET_free (dc->fn);
117 GNUNET_SCHEDULER_shutdown ();
118 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
119 "Failed to stop source daemon: %s\n",
121 GNUNET_FS_uri_destroy (uri);
125 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
126 "Downloading %llu bytes\n",
127 (unsigned long long) FILESIZE);
128 start_time = GNUNET_TIME_absolute_get ();
129 GNUNET_FS_TEST_download (daemons[0],
137 GNUNET_FS_uri_destroy (uri);
142 stop_source_peer (void *cls)
144 struct DownloadContext *dc = cls;
146 /* FIXME: We should not interact with testbed when shutting down */
147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
148 "Stopping source peer\n");
149 op = GNUNET_TESTBED_peer_stop (NULL,
152 GNUNET_assert (NULL != op);
158 const struct GNUNET_FS_Uri *uri,
161 struct DownloadContext *dc;
165 GNUNET_SCHEDULER_shutdown ();
166 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
167 "Timeout during upload attempt, shutting down with error\n");
171 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
172 "Waiting to allow content to migrate\n");
173 dc = GNUNET_new (struct DownloadContext);
174 dc->uri = GNUNET_FS_uri_dup (uri);
176 dc->fn = GNUNET_strdup (fn);
177 (void) GNUNET_SCHEDULER_add_delayed (MIGRATION_DELAY,
184 do_publish (void *cls,
185 struct GNUNET_TESTBED_RunHandle *h,
186 unsigned int num_peers,
187 struct GNUNET_TESTBED_Peer **peers,
188 unsigned int links_succeeded,
189 unsigned int links_failed)
193 GNUNET_assert (2 == num_peers);
194 for (i=0;i<num_peers;i++)
195 daemons[i] = peers[i];
196 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
197 "Publishing %llu bytes\n",
198 (unsigned long long) FILESIZE);
199 GNUNET_FS_TEST_publish (daemons[1], TIMEOUT, 1, GNUNET_NO,
201 VERBOSE, &do_wait, NULL);
209 (void) GNUNET_TESTBED_test_run ("test-gnunet-service-fs-migration",
210 "fs_test_lib_data.conf",
215 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/");
219 /* end of test_gnunet_service_fs_migration.c */