2 This file is part of GNUnet.
3 Copyright (C) 2010, 2012, 2015 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., 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;
68 const struct GNUNET_SCHEDULER_TaskContext *tc)
70 struct GNUNET_TIME_Relative del;
73 GNUNET_SCHEDULER_shutdown ();
75 GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_add (start_time,
76 TIMEOUT)).rel_value_us)
78 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
79 "Timeout during download, shutting down with error\n");
84 del = GNUNET_TIME_absolute_get_duration (start_time);
85 if (del.rel_value_us == 0)
88 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
89 1000000LL / del.rel_value_us);
91 "Download speed was %s/s\n",
94 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
95 "Finished download, shutting down\n",
96 (unsigned long long) FILESIZE);
102 do_download (void *cls,
105 struct DownloadContext *dc = cls;
106 struct GNUNET_FS_Uri *uri = dc->uri;
108 GNUNET_TESTBED_operation_done (op);
112 GNUNET_DISK_directory_remove (dc->fn);
113 GNUNET_free (dc->fn);
118 GNUNET_SCHEDULER_shutdown ();
119 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
120 "Failed to stop source daemon: %s\n",
122 GNUNET_FS_uri_destroy (uri);
126 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
127 "Downloading %llu bytes\n",
128 (unsigned long long) FILESIZE);
129 start_time = GNUNET_TIME_absolute_get ();
130 GNUNET_FS_TEST_download (daemons[0],
138 GNUNET_FS_uri_destroy (uri);
143 stop_source_peer (void *cls,
144 const struct GNUNET_SCHEDULER_TaskContext *tc)
146 struct DownloadContext *dc = cls;
148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
149 "Stopping source peer\n");
150 op = GNUNET_TESTBED_peer_stop (NULL, daemons[1], &do_download, dc);
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, &stop_source_peer, dc);
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, FILESIZE, SEED,
197 VERBOSE, &do_wait, NULL);
205 (void) GNUNET_TESTBED_test_run ("test-gnunet-service-fs-migration",
206 "fs_test_lib_data.conf",
211 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/");
215 /* end of test_gnunet_service_fs_migration.c */