aboutsummaryrefslogtreecommitdiff
path: root/src/fs/test_gnunet_service_fs_migration.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/test_gnunet_service_fs_migration.c')
-rw-r--r--src/fs/test_gnunet_service_fs_migration.c213
1 files changed, 106 insertions, 107 deletions
diff --git a/src/fs/test_gnunet_service_fs_migration.c b/src/fs/test_gnunet_service_fs_migration.c
index f7daf6b1a..c56e89e11 100644
--- a/src/fs/test_gnunet_service_fs_migration.c
+++ b/src/fs/test_gnunet_service_fs_migration.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file fs/test_gnunet_service_fs_migration.c 22 * @file fs/test_gnunet_service_fs_migration.c
@@ -37,12 +37,12 @@
37/** 37/**
38 * How long until we give up on transmitting the message? 38 * How long until we give up on transmitting the message?
39 */ 39 */
40#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) 40#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120)
41 41
42/** 42/**
43 * How long do we give the peers for content migration? 43 * How long do we give the peers for content migration?
44 */ 44 */
45#define MIGRATION_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90) 45#define MIGRATION_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 90)
46 46
47#define SEED 42 47#define SEED 42
48 48
@@ -55,8 +55,7 @@ static struct GNUNET_TIME_Absolute start_time;
55static struct GNUNET_TESTBED_Operation *op; 55static struct GNUNET_TESTBED_Operation *op;
56 56
57 57
58struct DownloadContext 58struct DownloadContext {
59{
60 char *fn; 59 char *fn;
61 60
62 struct GNUNET_FS_Uri *uri; 61 struct GNUNET_FS_Uri *uri;
@@ -64,154 +63,154 @@ struct DownloadContext
64 63
65 64
66static void 65static void
67do_stop (void *cls) 66do_stop(void *cls)
68{ 67{
69 struct GNUNET_TIME_Relative del; 68 struct GNUNET_TIME_Relative del;
70 char *fancy; 69 char *fancy;
71 70
72 GNUNET_SCHEDULER_shutdown (); 71 GNUNET_SCHEDULER_shutdown();
73 if (0 == 72 if (0 ==
74 GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_add (start_time, 73 GNUNET_TIME_absolute_get_remaining(GNUNET_TIME_absolute_add(start_time,
75 TIMEOUT)).rel_value_us) 74 TIMEOUT)).rel_value_us)
76 { 75 {
77 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 76 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
78 "Timeout during download, shutting down with error\n"); 77 "Timeout during download, shutting down with error\n");
79 ok = 1; 78 ok = 1;
80 } 79 }
81 else 80 else
82 { 81 {
83 del = GNUNET_TIME_absolute_get_duration (start_time); 82 del = GNUNET_TIME_absolute_get_duration(start_time);
84 if (del.rel_value_us == 0) 83 if (del.rel_value_us == 0)
85 del.rel_value_us = 1; 84 del.rel_value_us = 1;
86 fancy = 85 fancy =
87 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) * 86 GNUNET_STRINGS_byte_size_fancy(((unsigned long long)FILESIZE) *
88 1000000LL / del.rel_value_us); 87 1000000LL / del.rel_value_us);
89 fprintf (stdout, 88 fprintf(stdout,
90 "Download speed was %s/s\n", 89 "Download speed was %s/s\n",
91 fancy); 90 fancy);
92 GNUNET_free (fancy); 91 GNUNET_free(fancy);
93 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 92 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
94 "Finished download, shutting down\n"); 93 "Finished download, shutting down\n");
95 } 94 }
96} 95}
97 96
98 97
99static void 98static void
100do_download (void *cls, 99do_download(void *cls,
101 const char *emsg) 100 const char *emsg)
102{ 101{
103 struct DownloadContext *dc = cls; 102 struct DownloadContext *dc = cls;
104 struct GNUNET_FS_Uri *uri = dc->uri; 103 struct GNUNET_FS_Uri *uri = dc->uri;
105 104
106 GNUNET_TESTBED_operation_done (op); 105 GNUNET_TESTBED_operation_done(op);
107 op = NULL; 106 op = NULL;
108 if (NULL != dc->fn) 107 if (NULL != dc->fn)
109 { 108 {
110 GNUNET_DISK_directory_remove (dc->fn); 109 GNUNET_DISK_directory_remove(dc->fn);
111 GNUNET_free (dc->fn); 110 GNUNET_free(dc->fn);
112 } 111 }
113 GNUNET_free (dc); 112 GNUNET_free(dc);
114 if (NULL != emsg) 113 if (NULL != emsg)
115 { 114 {
116 GNUNET_SCHEDULER_shutdown (); 115 GNUNET_SCHEDULER_shutdown();
117 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 116 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
118 "Failed to stop source daemon: %s\n", 117 "Failed to stop source daemon: %s\n",
119 emsg); 118 emsg);
120 GNUNET_FS_uri_destroy (uri); 119 GNUNET_FS_uri_destroy(uri);
121 ok = 1; 120 ok = 1;
122 return; 121 return;
123 } 122 }
124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 123 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
125 "Downloading %llu bytes\n", 124 "Downloading %llu bytes\n",
126 (unsigned long long) FILESIZE); 125 (unsigned long long)FILESIZE);
127 start_time = GNUNET_TIME_absolute_get (); 126 start_time = GNUNET_TIME_absolute_get();
128 GNUNET_FS_TEST_download (daemons[0], 127 GNUNET_FS_TEST_download(daemons[0],
129 TIMEOUT, 128 TIMEOUT,
130 1, 129 1,
131 SEED, 130 SEED,
132 uri, 131 uri,
133 VERBOSE, 132 VERBOSE,
134 &do_stop, 133 &do_stop,
135 NULL); 134 NULL);
136 GNUNET_FS_uri_destroy (uri); 135 GNUNET_FS_uri_destroy(uri);
137} 136}
138 137
139 138
140static void 139static void
141stop_source_peer (void *cls) 140stop_source_peer(void *cls)
142{ 141{
143 struct DownloadContext *dc = cls; 142 struct DownloadContext *dc = cls;
144 143
145 /* FIXME: We should not interact with testbed when shutting down */ 144 /* FIXME: We should not interact with testbed when shutting down */
146 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 145 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
147 "Stopping source peer\n"); 146 "Stopping source peer\n");
148 op = GNUNET_TESTBED_peer_stop (NULL, 147 op = GNUNET_TESTBED_peer_stop(NULL,
149 daemons[1], 148 daemons[1],
150 &do_download, dc); 149 &do_download, dc);
151 GNUNET_assert (NULL != op); 150 GNUNET_assert(NULL != op);
152} 151}
153 152
154 153
155static void 154static void
156do_wait (void *cls, 155do_wait(void *cls,
157 const struct GNUNET_FS_Uri *uri, 156 const struct GNUNET_FS_Uri *uri,
158 const char *fn) 157 const char *fn)
159{ 158{
160 struct DownloadContext *dc; 159 struct DownloadContext *dc;
161 160
162 if (NULL == uri) 161 if (NULL == uri)
163 { 162 {
164 GNUNET_SCHEDULER_shutdown (); 163 GNUNET_SCHEDULER_shutdown();
165 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 164 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
166 "Timeout during upload attempt, shutting down with error\n"); 165 "Timeout during upload attempt, shutting down with error\n");
167 ok = 1; 166 ok = 1;
168 return; 167 return;
169 } 168 }
170 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 169 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
171 "Waiting to allow content to migrate\n"); 170 "Waiting to allow content to migrate\n");
172 dc = GNUNET_new (struct DownloadContext); 171 dc = GNUNET_new(struct DownloadContext);
173 dc->uri = GNUNET_FS_uri_dup (uri); 172 dc->uri = GNUNET_FS_uri_dup(uri);
174 if (NULL != fn) 173 if (NULL != fn)
175 dc->fn = GNUNET_strdup (fn); 174 dc->fn = GNUNET_strdup(fn);
176 (void) GNUNET_SCHEDULER_add_delayed (MIGRATION_DELAY, 175 (void)GNUNET_SCHEDULER_add_delayed(MIGRATION_DELAY,
177 &stop_source_peer, 176 &stop_source_peer,
178 dc); 177 dc);
179} 178}
180 179
181 180
182static void 181static void
183do_publish (void *cls, 182do_publish(void *cls,
184 struct GNUNET_TESTBED_RunHandle *h, 183 struct GNUNET_TESTBED_RunHandle *h,
185 unsigned int num_peers, 184 unsigned int num_peers,
186 struct GNUNET_TESTBED_Peer **peers, 185 struct GNUNET_TESTBED_Peer **peers,
187 unsigned int links_succeeded, 186 unsigned int links_succeeded,
188 unsigned int links_failed) 187 unsigned int links_failed)
189{ 188{
190 unsigned int i; 189 unsigned int i;
191 190
192 GNUNET_assert (2 == num_peers); 191 GNUNET_assert(2 == num_peers);
193 for (i=0;i<num_peers;i++) 192 for (i = 0; i < num_peers; i++)
194 daemons[i] = peers[i]; 193 daemons[i] = peers[i];
195 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 194 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
196 "Publishing %llu bytes\n", 195 "Publishing %llu bytes\n",
197 (unsigned long long) FILESIZE); 196 (unsigned long long)FILESIZE);
198 GNUNET_FS_TEST_publish (daemons[1], TIMEOUT, 1, GNUNET_NO, 197 GNUNET_FS_TEST_publish(daemons[1], TIMEOUT, 1, GNUNET_NO,
199 FILESIZE, SEED, 198 FILESIZE, SEED,
200 VERBOSE, &do_wait, NULL); 199 VERBOSE, &do_wait, NULL);
201} 200}
202 201
203 202
204int 203int
205main (int argc, 204main(int argc,
206 char *argv[]) 205 char *argv[])
207{ 206{
208 (void) GNUNET_TESTBED_test_run ("test-gnunet-service-fs-migration", 207 (void)GNUNET_TESTBED_test_run("test-gnunet-service-fs-migration",
209 "fs_test_lib_data.conf", 208 "fs_test_lib_data.conf",
210 2, 209 2,
211 0, NULL, NULL, 210 0, NULL, NULL,
212 &do_publish, 211 &do_publish,
213 NULL); 212 NULL);
214 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/"); 213 GNUNET_DISK_directory_remove("/tmp/test-gnunet-service-fs-migration/");
215 return ok; 214 return ok;
216} 215}
217 216