2 This file is part of GNUnet.
3 (C) 2010, 2012 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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, 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;
67 do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
69 struct GNUNET_TIME_Relative del;
72 GNUNET_SCHEDULER_shutdown ();
73 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
75 del = GNUNET_TIME_absolute_get_duration (start_time);
76 if (del.rel_value == 0)
79 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
80 1000LL / del.rel_value);
81 FPRINTF (stdout, "Download speed was %s/s\n", fancy);
83 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished download, shutting down\n",
84 (unsigned long long) FILESIZE);
88 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
89 "Timeout during download, shutting down with error\n");
96 do_download (void *cls,
99 struct DownloadContext *dc = cls;
100 struct GNUNET_FS_Uri *uri = dc->uri;
102 GNUNET_TESTBED_operation_done (op);
106 GNUNET_DISK_directory_remove (dc->fn);
107 GNUNET_free (dc->fn);
112 GNUNET_SCHEDULER_shutdown ();
113 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to stop source daemon: %s\n",
115 GNUNET_FS_uri_destroy (uri);
119 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n",
120 (unsigned long long) FILESIZE);
121 start_time = GNUNET_TIME_absolute_get ();
122 GNUNET_FS_TEST_download (daemons[0], TIMEOUT, 1, SEED, uri, VERBOSE, &do_stop,
124 GNUNET_FS_uri_destroy (uri);
129 stop_source_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
131 struct DownloadContext *dc = cls;
133 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping source peer\n");
134 op = GNUNET_TESTBED_peer_stop (NULL, daemons[1], &do_download, dc);
135 GNUNET_assert (NULL != op);
140 do_wait (void *cls, const struct GNUNET_FS_Uri *uri,
143 struct DownloadContext *dc;
147 GNUNET_SCHEDULER_shutdown ();
148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
149 "Timeout during upload attempt, shutting down with error\n");
153 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Waiting to allow content to migrate\n");
154 dc = GNUNET_malloc (sizeof (struct DownloadContext));
155 dc->uri = GNUNET_FS_uri_dup (uri);
157 dc->fn = GNUNET_strdup (fn);
158 (void) GNUNET_SCHEDULER_add_delayed (MIGRATION_DELAY, &stop_source_peer, dc);
163 do_publish (void *cls,
164 unsigned int num_peers,
165 struct GNUNET_TESTBED_Peer **peers,
166 unsigned int links_succeeded,
167 unsigned int links_failed)
171 GNUNET_assert (2 == num_peers);
172 for (i=0;i<num_peers;i++)
173 daemons[i] = peers[i];
174 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n",
175 (unsigned long long) FILESIZE);
176 GNUNET_FS_TEST_publish (daemons[1], TIMEOUT, 1, GNUNET_NO, FILESIZE, SEED,
177 VERBOSE, &do_wait, NULL);
182 main (int argc, char *argv[])
184 (void) GNUNET_TESTBED_test_run ("test-gnunet-service-fs-migration",
185 "fs_test_lib_data.conf",
190 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/");
194 /* end of test_gnunet_service_fs_migration.c */