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.
17 * @file fs/test_gnunet_service_fs_migration.c
18 * @brief test content migration between two peers
19 * @author Christian Grothoff
22 #include "fs_test_lib.h"
23 #include "gnunet_testbed_service.h"
25 #define VERBOSE GNUNET_NO
28 * File-size we use for testing.
30 #define FILESIZE (2 * 32 * 1024)
33 * How long until we give up on transmitting the message?
35 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
38 * How long do we give the peers for content migration?
40 #define MIGRATION_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90)
44 static struct GNUNET_TESTBED_Peer *daemons[2];
48 static struct GNUNET_TIME_Absolute start_time;
50 static struct GNUNET_TESTBED_Operation *op;
53 struct DownloadContext
57 struct GNUNET_FS_Uri *uri;
64 struct GNUNET_TIME_Relative del;
67 GNUNET_SCHEDULER_shutdown ();
69 GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_add (start_time,
70 TIMEOUT)).rel_value_us)
72 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
73 "Timeout during download, shutting down with error\n");
78 del = GNUNET_TIME_absolute_get_duration (start_time);
79 if (del.rel_value_us == 0)
82 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
83 1000000LL / del.rel_value_us);
85 "Download speed was %s/s\n",
88 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
89 "Finished download, shutting down\n");
95 do_download (void *cls,
98 struct DownloadContext *dc = cls;
99 struct GNUNET_FS_Uri *uri = dc->uri;
101 GNUNET_TESTBED_operation_done (op);
105 GNUNET_DISK_directory_remove (dc->fn);
106 GNUNET_free (dc->fn);
111 GNUNET_SCHEDULER_shutdown ();
112 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
113 "Failed to stop source daemon: %s\n",
115 GNUNET_FS_uri_destroy (uri);
119 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
120 "Downloading %llu bytes\n",
121 (unsigned long long) FILESIZE);
122 start_time = GNUNET_TIME_absolute_get ();
123 GNUNET_FS_TEST_download (daemons[0],
131 GNUNET_FS_uri_destroy (uri);
136 stop_source_peer (void *cls)
138 struct DownloadContext *dc = cls;
140 /* FIXME: We should not interact with testbed when shutting down */
141 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
142 "Stopping source peer\n");
143 op = GNUNET_TESTBED_peer_stop (NULL,
146 GNUNET_assert (NULL != op);
152 const struct GNUNET_FS_Uri *uri,
155 struct DownloadContext *dc;
159 GNUNET_SCHEDULER_shutdown ();
160 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
161 "Timeout during upload attempt, shutting down with error\n");
165 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
166 "Waiting to allow content to migrate\n");
167 dc = GNUNET_new (struct DownloadContext);
168 dc->uri = GNUNET_FS_uri_dup (uri);
170 dc->fn = GNUNET_strdup (fn);
171 (void) GNUNET_SCHEDULER_add_delayed (MIGRATION_DELAY,
178 do_publish (void *cls,
179 struct GNUNET_TESTBED_RunHandle *h,
180 unsigned int num_peers,
181 struct GNUNET_TESTBED_Peer **peers,
182 unsigned int links_succeeded,
183 unsigned int links_failed)
187 GNUNET_assert (2 == num_peers);
188 for (i=0;i<num_peers;i++)
189 daemons[i] = peers[i];
190 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
191 "Publishing %llu bytes\n",
192 (unsigned long long) FILESIZE);
193 GNUNET_FS_TEST_publish (daemons[1], TIMEOUT, 1, GNUNET_NO,
195 VERBOSE, &do_wait, NULL);
203 (void) GNUNET_TESTBED_test_run ("test-gnunet-service-fs-migration",
204 "fs_test_lib_data.conf",
209 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/");
213 /* end of test_gnunet_service_fs_migration.c */