diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-09-09 13:28:48 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-09-09 13:28:48 +0000 |
commit | 9d732bb204de9177aad6ae70c910cbf2615d81a3 (patch) | |
tree | 44ddd6e9e1dad749db51003acfa46d7835593dc6 /src/fs/perf_gnunet_service_fs_p2p.c | |
parent | a1d7926951beb7466a1462e43b9933530e5825f7 (diff) | |
download | gnunet-9d732bb204de9177aad6ae70c910cbf2615d81a3.tar.gz gnunet-9d732bb204de9177aad6ae70c910cbf2615d81a3.zip |
make fs tests build against new testbed library -- they do not pass yet
Diffstat (limited to 'src/fs/perf_gnunet_service_fs_p2p.c')
-rw-r--r-- | src/fs/perf_gnunet_service_fs_p2p.c | 200 |
1 files changed, 115 insertions, 85 deletions
diff --git a/src/fs/perf_gnunet_service_fs_p2p.c b/src/fs/perf_gnunet_service_fs_p2p.c index 22068732d..a7eb5ad16 100644 --- a/src/fs/perf_gnunet_service_fs_p2p.c +++ b/src/fs/perf_gnunet_service_fs_p2p.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2010 Christian Grothoff (and other contributing authors) | 3 | (C) 2010, 2012 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published |
@@ -25,7 +25,7 @@ | |||
25 | */ | 25 | */ |
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "fs_test_lib.h" | 27 | #include "fs_test_lib.h" |
28 | #include "gnunet_testing_lib.h" | 28 | #include "gnunet_testbed_service.h" |
29 | 29 | ||
30 | #define VERBOSE GNUNET_NO | 30 | #define VERBOSE GNUNET_NO |
31 | 31 | ||
@@ -43,7 +43,7 @@ | |||
43 | 43 | ||
44 | #define SEED 42 | 44 | #define SEED 42 |
45 | 45 | ||
46 | static struct GNUNET_FS_TestDaemon *daemons[NUM_DAEMONS]; | 46 | static struct GNUNET_TESTBED_Peer *daemons[NUM_DAEMONS]; |
47 | 47 | ||
48 | static int ok; | 48 | static int ok; |
49 | 49 | ||
@@ -51,12 +51,6 @@ static struct GNUNET_TIME_Absolute start_time; | |||
51 | 51 | ||
52 | static const char *progname; | 52 | static const char *progname; |
53 | 53 | ||
54 | static void | ||
55 | do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
56 | { | ||
57 | GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons); | ||
58 | } | ||
59 | |||
60 | 54 | ||
61 | /** | 55 | /** |
62 | * Master context for 'stat_run'. | 56 | * Master context for 'stat_run'. |
@@ -64,6 +58,7 @@ do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
64 | struct StatMaster | 58 | struct StatMaster |
65 | { | 59 | { |
66 | struct GNUNET_STATISTICS_Handle *stat; | 60 | struct GNUNET_STATISTICS_Handle *stat; |
61 | struct GNUNET_TESTBED_Operation *op; | ||
67 | unsigned int daemon; | 62 | unsigned int daemon; |
68 | unsigned int value; | 63 | unsigned int value; |
69 | }; | 64 | }; |
@@ -130,7 +125,10 @@ print_stat (void *cls, const char *subsystem, const char *name, uint64_t value, | |||
130 | * Function that gathers stats from all daemons. | 125 | * Function that gathers stats from all daemons. |
131 | */ | 126 | */ |
132 | static void | 127 | static void |
133 | stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 128 | stat_run (void *cls, |
129 | struct GNUNET_TESTBED_Operation *op, | ||
130 | void *ca_result, | ||
131 | const char *emsg); | ||
134 | 132 | ||
135 | 133 | ||
136 | /** | 134 | /** |
@@ -143,7 +141,41 @@ get_done (void *cls, int success) | |||
143 | 141 | ||
144 | GNUNET_break (GNUNET_OK == success); | 142 | GNUNET_break (GNUNET_OK == success); |
145 | sm->value++; | 143 | sm->value++; |
146 | GNUNET_SCHEDULER_add_now (&stat_run, sm); | 144 | stat_run (sm, sm->op, sm->stat, NULL); |
145 | } | ||
146 | |||
147 | |||
148 | /** | ||
149 | * Adapter function called to establish a connection to | ||
150 | * statistics service. | ||
151 | * | ||
152 | * @param cls closure | ||
153 | * @param cfg configuration of the peer to connect to; will be available until | ||
154 | * GNUNET_TESTBED_operation_done() is called on the operation returned | ||
155 | * from GNUNET_TESTBED_service_connect() | ||
156 | * @return service handle to return in 'op_result', NULL on error | ||
157 | */ | ||
158 | static void * | ||
159 | statistics_connect_adapter (void *cls, | ||
160 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
161 | { | ||
162 | return GNUNET_STATISTICS_create ("<driver>", | ||
163 | cfg); | ||
164 | } | ||
165 | |||
166 | |||
167 | /** | ||
168 | * Adapter function called to destroy a connection to | ||
169 | * statistics service. | ||
170 | * | ||
171 | * @param cls closure | ||
172 | * @param op_result service handle returned from the connect adapter | ||
173 | */ | ||
174 | static void | ||
175 | statistics_disconnect_adapter (void *cls, | ||
176 | void *op_result) | ||
177 | { | ||
178 | GNUNET_STATISTICS_destroy (op_result, GNUNET_NO); | ||
147 | } | 179 | } |
148 | 180 | ||
149 | 181 | ||
@@ -151,10 +183,23 @@ get_done (void *cls, int success) | |||
151 | * Function that gathers stats from all daemons. | 183 | * Function that gathers stats from all daemons. |
152 | */ | 184 | */ |
153 | static void | 185 | static void |
154 | stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 186 | stat_run (void *cls, |
187 | struct GNUNET_TESTBED_Operation *op, | ||
188 | void *ca_result, | ||
189 | const char *emsg) | ||
155 | { | 190 | { |
156 | struct StatMaster *sm = cls; | 191 | struct StatMaster *sm = cls; |
157 | 192 | ||
193 | if (NULL != emsg) | ||
194 | { | ||
195 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
196 | "Failed to statistics service: %s\n", | ||
197 | emsg); | ||
198 | GNUNET_SCHEDULER_shutdown (); | ||
199 | return; | ||
200 | } | ||
201 | sm->stat = ca_result; | ||
202 | |||
158 | if (stats[sm->value].name != NULL) | 203 | if (stats[sm->value].name != NULL) |
159 | { | 204 | { |
160 | GNUNET_STATISTICS_get (sm->stat, | 205 | GNUNET_STATISTICS_get (sm->stat, |
@@ -167,20 +212,23 @@ stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
167 | sm); | 212 | sm); |
168 | return; | 213 | return; |
169 | } | 214 | } |
170 | GNUNET_STATISTICS_destroy (sm->stat, GNUNET_NO); | 215 | GNUNET_TESTBED_operation_done (sm->op); |
171 | sm->value = 0; | 216 | sm->value = 0; |
172 | sm->daemon++; | 217 | sm->daemon++; |
173 | if (sm->daemon == NUM_DAEMONS) | 218 | if (NUM_DAEMONS == sm->daemon) |
174 | { | 219 | { |
175 | GNUNET_free (sm); | 220 | GNUNET_free (sm); |
176 | GNUNET_SCHEDULER_add_now (&do_stop, NULL); | 221 | GNUNET_SCHEDULER_shutdown (); |
177 | return; | 222 | return; |
178 | } | 223 | } |
179 | sm->stat = | 224 | sm->op = |
180 | GNUNET_STATISTICS_create ("<driver>", | 225 | GNUNET_TESTBED_service_connect (NULL, |
181 | GNUNET_FS_TEST_get_configuration (daemons, | 226 | daemons[sm->daemon], |
182 | sm->daemon)); | 227 | "statistics", |
183 | GNUNET_SCHEDULER_add_now (&stat_run, sm); | 228 | &stat_run, sm, |
229 | &statistics_connect_adapter, | ||
230 | &statistics_disconnect_adapter, | ||
231 | NULL); | ||
184 | } | 232 | } |
185 | 233 | ||
186 | 234 | ||
@@ -191,32 +239,33 @@ do_report (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
191 | char *fancy; | 239 | char *fancy; |
192 | struct StatMaster *sm; | 240 | struct StatMaster *sm; |
193 | 241 | ||
194 | if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) | 242 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) |
195 | { | ||
196 | del = GNUNET_TIME_absolute_get_duration (start_time); | ||
197 | if (del.rel_value == 0) | ||
198 | del.rel_value = 1; | ||
199 | fancy = | ||
200 | GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) * | ||
201 | 1000LL / del.rel_value); | ||
202 | FPRINTF (stdout, "Download speed was %s/s\n", fancy); | ||
203 | GNUNET_free (fancy); | ||
204 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished download, shutting down\n", | ||
205 | (unsigned long long) FILESIZE); | ||
206 | sm = GNUNET_malloc (sizeof (struct StatMaster)); | ||
207 | sm->stat = | ||
208 | GNUNET_STATISTICS_create ("<driver>", | ||
209 | GNUNET_FS_TEST_get_configuration (daemons, | ||
210 | sm->daemon)); | ||
211 | GNUNET_SCHEDULER_add_now (&stat_run, sm); | ||
212 | } | ||
213 | else | ||
214 | { | 243 | { |
215 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 244 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
216 | "Timeout during download, shutting down with error\n"); | 245 | "Timeout during download, shutting down with error\n"); |
217 | ok = 1; | 246 | ok = 1; |
218 | GNUNET_SCHEDULER_add_now (&do_stop, NULL); | 247 | GNUNET_SCHEDULER_shutdown (); |
248 | return; | ||
219 | } | 249 | } |
250 | del = GNUNET_TIME_absolute_get_duration (start_time); | ||
251 | if (del.rel_value == 0) | ||
252 | del.rel_value = 1; | ||
253 | fancy = | ||
254 | GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) * | ||
255 | 1000LL / del.rel_value); | ||
256 | FPRINTF (stdout, "Download speed was %s/s\n", fancy); | ||
257 | GNUNET_free (fancy); | ||
258 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished download, shutting down\n", | ||
259 | (unsigned long long) FILESIZE); | ||
260 | sm = GNUNET_malloc (sizeof (struct StatMaster)); | ||
261 | sm->op = | ||
262 | GNUNET_TESTBED_service_connect (NULL, | ||
263 | daemons[sm->daemon], | ||
264 | "statistics", | ||
265 | &stat_run, sm, | ||
266 | &statistics_connect_adapter, | ||
267 | &statistics_disconnect_adapter, | ||
268 | NULL); | ||
220 | } | 269 | } |
221 | 270 | ||
222 | 271 | ||
@@ -226,8 +275,8 @@ do_download (void *cls, const struct GNUNET_FS_Uri *uri) | |||
226 | int anonymity; | 275 | int anonymity; |
227 | 276 | ||
228 | if (NULL == uri) | 277 | if (NULL == uri) |
229 | { | 278 | { |
230 | GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons); | 279 | GNUNET_SCHEDULER_shutdown (); |
231 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 280 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
232 | "Timeout during upload attempt, shutting down with error\n"); | 281 | "Timeout during upload attempt, shutting down with error\n"); |
233 | ok = 1; | 282 | ok = 1; |
@@ -246,14 +295,16 @@ do_download (void *cls, const struct GNUNET_FS_Uri *uri) | |||
246 | 295 | ||
247 | 296 | ||
248 | static void | 297 | static void |
249 | do_publish (void *cls, const char *emsg) | 298 | do_publish (void *cls, |
299 | struct GNUNET_TESTBED_Operation *op, | ||
300 | const char *emsg) | ||
250 | { | 301 | { |
251 | int do_index; | 302 | int do_index; |
252 | int anonymity; | 303 | int anonymity; |
253 | 304 | ||
254 | if (NULL != emsg) | 305 | if (NULL != emsg) |
255 | { | 306 | { |
256 | GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons); | 307 | GNUNET_SCHEDULER_shutdown (); |
257 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error trying to connect: %s\n", emsg); | 308 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error trying to connect: %s\n", emsg); |
258 | ok = 1; | 309 | ok = 1; |
259 | return; | 310 | return; |
@@ -276,53 +327,32 @@ do_publish (void *cls, const char *emsg) | |||
276 | 327 | ||
277 | 328 | ||
278 | static void | 329 | static void |
279 | do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 330 | do_connect (void *cls, |
331 | unsigned int num_peers, | ||
332 | struct GNUNET_TESTBED_Peer **peers) | ||
280 | { | 333 | { |
281 | struct GNUNET_TESTING_PeerGroup *pg; | 334 | unsigned int i; |
282 | 335 | ||
283 | GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)); | 336 | GNUNET_assert (NUM_DAEMONS == num_peers); |
284 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 337 | for (i=0;i<num_peers;i++) |
285 | "Daemons started, will now try to connect them\n"); | 338 | daemons[i] = peers[i]; |
286 | pg = GNUNET_FS_TEST_get_group (daemons); | 339 | GNUNET_TESTBED_overlay_connect (NULL, |
287 | GNUNET_break ((NUM_DAEMONS - 1) * 2 == | 340 | &do_publish, |
288 | (GNUNET_TESTING_create_topology | 341 | NULL, |
289 | (pg, GNUNET_TESTING_TOPOLOGY_LINE, | 342 | peers[0], |
290 | GNUNET_TESTING_TOPOLOGY_NONE, NULL))); | 343 | peers[1]); |
291 | GNUNET_TESTING_connect_topology (pg, GNUNET_TESTING_TOPOLOGY_LINE, | 344 | // FIXME: was supposed to connect in line... |
292 | GNUNET_TESTING_TOPOLOGY_OPTION_NONE, 0.0, | ||
293 | TIMEOUT, NUM_DAEMONS, &do_publish, NULL); | ||
294 | } | ||
295 | |||
296 | |||
297 | static void | ||
298 | run (void *cls, char *const *args, const char *cfgfile, | ||
299 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
300 | { | ||
301 | GNUNET_FS_TEST_daemons_start ("perf_gnunet_service_fs_p2p.conf", TIMEOUT, NUM_DAEMONS, | ||
302 | daemons, &do_connect, NULL); | ||
303 | } | 345 | } |
304 | 346 | ||
305 | 347 | ||
306 | int | 348 | int |
307 | main (int argc, char *argv[]) | 349 | main (int argc, char *argv[]) |
308 | { | 350 | { |
309 | char *const argvx[] = { | 351 | GNUNET_TESTBED_test_run ("perf-gnunet-service-fs-p2p", |
310 | "perf-gnunet-service-fs-p2p", | 352 | "perf_gnunet_service_fs_p2p.conf", |
311 | "-c", | 353 | NUM_DAEMONS, |
312 | "perf_gnunet_service_fs_p2p.conf", | 354 | 0, NULL, NULL, |
313 | NULL | 355 | &do_connect, NULL); |
314 | }; | ||
315 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
316 | GNUNET_GETOPT_OPTION_END | ||
317 | }; | ||
318 | progname = argv[0]; | ||
319 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); | ||
320 | GNUNET_log_setup ("perf_gnunet_service_fs_p2p_index", | ||
321 | "WARNING", | ||
322 | NULL); | ||
323 | GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx, | ||
324 | "perf-gnunet-service-fs-p2p-index", "nohelp", options, | ||
325 | &run, NULL); | ||
326 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); | 356 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); |
327 | return ok; | 357 | return ok; |
328 | } | 358 | } |