aboutsummaryrefslogtreecommitdiff
path: root/src/fs/perf_gnunet_service_fs_p2p_respect.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-09-09 13:28:48 +0000
committerChristian Grothoff <christian@grothoff.org>2012-09-09 13:28:48 +0000
commit9d732bb204de9177aad6ae70c910cbf2615d81a3 (patch)
tree44ddd6e9e1dad749db51003acfa46d7835593dc6 /src/fs/perf_gnunet_service_fs_p2p_respect.c
parenta1d7926951beb7466a1462e43b9933530e5825f7 (diff)
downloadgnunet-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_respect.c')
-rw-r--r--src/fs/perf_gnunet_service_fs_p2p_respect.c210
1 files changed, 121 insertions, 89 deletions
diff --git a/src/fs/perf_gnunet_service_fs_p2p_respect.c b/src/fs/perf_gnunet_service_fs_p2p_respect.c
index 58fe34eef..3030749e2 100644
--- a/src/fs/perf_gnunet_service_fs_p2p_respect.c
+++ b/src/fs/perf_gnunet_service_fs_p2p_respect.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2010, 2011 Christian Grothoff (and other contributing authors) 3 (C) 2010, 2011, 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
@@ -45,7 +45,7 @@
45 */ 45 */
46#include "platform.h" 46#include "platform.h"
47#include "fs_test_lib.h" 47#include "fs_test_lib.h"
48#include "gnunet_testing_lib.h" 48#include "gnunet_testbed_service.h"
49 49
50#define VERBOSE GNUNET_NO 50#define VERBOSE GNUNET_NO
51 51
@@ -74,7 +74,7 @@
74 */ 74 */
75#define SEED2 43 75#define SEED2 43
76 76
77static struct GNUNET_FS_TestDaemon *daemons[NUM_DAEMONS]; 77static struct GNUNET_TESTBED_Peer *daemons[NUM_DAEMONS];
78 78
79static int ok; 79static int ok;
80 80
@@ -86,12 +86,6 @@ static struct GNUNET_FS_Uri *uri1;
86 86
87static struct GNUNET_FS_Uri *uri2; 87static struct GNUNET_FS_Uri *uri2;
88 88
89static void
90do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
91{
92 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
93}
94
95 89
96/** 90/**
97 * Master context for 'stat_run'. 91 * Master context for 'stat_run'.
@@ -99,6 +93,7 @@ do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
99struct StatMaster 93struct StatMaster
100{ 94{
101 struct GNUNET_STATISTICS_Handle *stat; 95 struct GNUNET_STATISTICS_Handle *stat;
96 struct GNUNET_TESTBED_Operation *op;
102 unsigned int daemon; 97 unsigned int daemon;
103 unsigned int value; 98 unsigned int value;
104}; 99};
@@ -163,7 +158,10 @@ print_stat (void *cls, const char *subsystem, const char *name, uint64_t value,
163 * Function that gathers stats from all daemons. 158 * Function that gathers stats from all daemons.
164 */ 159 */
165static void 160static void
166stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 161stat_run (void *cls,
162 struct GNUNET_TESTBED_Operation *op,
163 void *ca_result,
164 const char *emsg);
167 165
168 166
169/** 167/**
@@ -176,7 +174,42 @@ get_done (void *cls, int success)
176 174
177 GNUNET_break (GNUNET_OK == success); 175 GNUNET_break (GNUNET_OK == success);
178 sm->value++; 176 sm->value++;
179 GNUNET_SCHEDULER_add_now (&stat_run, sm); 177 stat_run (sm, sm->op, sm->stat, NULL);
178}
179
180
181
182/**
183 * Adapter function called to establish a connection to
184 * statistics service.
185 *
186 * @param cls closure
187 * @param cfg configuration of the peer to connect to; will be available until
188 * GNUNET_TESTBED_operation_done() is called on the operation returned
189 * from GNUNET_TESTBED_service_connect()
190 * @return service handle to return in 'op_result', NULL on error
191 */
192static void *
193statistics_connect_adapter (void *cls,
194 const struct GNUNET_CONFIGURATION_Handle *cfg)
195{
196 return GNUNET_STATISTICS_create ("<driver>",
197 cfg);
198}
199
200
201/**
202 * Adapter function called to destroy a connection to
203 * statistics service.
204 *
205 * @param cls closure
206 * @param op_result service handle returned from the connect adapter
207 */
208static void
209statistics_disconnect_adapter (void *cls,
210 void *op_result)
211{
212 GNUNET_STATISTICS_destroy (op_result, GNUNET_NO);
180} 213}
181 214
182 215
@@ -184,7 +217,10 @@ get_done (void *cls, int success)
184 * Function that gathers stats from all daemons. 217 * Function that gathers stats from all daemons.
185 */ 218 */
186static void 219static void
187stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 220stat_run (void *cls,
221 struct GNUNET_TESTBED_Operation *op,
222 void *ca_result,
223 const char *emsg)
188{ 224{
189 struct StatMaster *sm = cls; 225 struct StatMaster *sm = cls;
190 226
@@ -200,20 +236,23 @@ stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
200 sm); 236 sm);
201 return; 237 return;
202 } 238 }
203 GNUNET_STATISTICS_destroy (sm->stat, GNUNET_NO); 239 GNUNET_TESTBED_operation_done (sm->op);
204 sm->value = 0; 240 sm->value = 0;
205 sm->daemon++; 241 sm->daemon++;
206 if (sm->daemon == NUM_DAEMONS) 242 if (NUM_DAEMONS == sm->daemon)
207 { 243 {
208 GNUNET_free (sm); 244 GNUNET_free (sm);
209 GNUNET_SCHEDULER_add_now (&do_stop, NULL); 245 GNUNET_SCHEDULER_shutdown ();
210 return; 246 return;
211 } 247 }
212 sm->stat = 248 sm->op =
213 GNUNET_STATISTICS_create ("<driver>", 249 GNUNET_TESTBED_service_connect (NULL,
214 GNUNET_FS_TEST_get_configuration (daemons, 250 daemons[sm->daemon],
215 sm->daemon)); 251 "statistics",
216 GNUNET_SCHEDULER_add_now (&stat_run, sm); 252 &stat_run, sm,
253 &statistics_connect_adapter,
254 &statistics_disconnect_adapter,
255 NULL);
217} 256}
218 257
219 258
@@ -226,36 +265,37 @@ do_report (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
226 char *fancy; 265 char *fancy;
227 struct StatMaster *sm; 266 struct StatMaster *sm;
228 267
229 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) 268 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
230 {
231 del = GNUNET_TIME_absolute_get_duration (start_time);
232 if (del.rel_value == 0)
233 del.rel_value = 1;
234 fancy =
235 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
236 1000LL / del.rel_value);
237 FPRINTF (stderr, "Download speed of type `%s' was %s/s\n", type, fancy);
238 GNUNET_free (fancy);
239 if (NUM_DAEMONS != ++download_counter)
240 return; /* more downloads to come */
241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
242 "Finished all downloads, shutting down\n",
243 (unsigned long long) FILESIZE);
244 sm = GNUNET_malloc (sizeof (struct StatMaster));
245 sm->stat =
246 GNUNET_STATISTICS_create ("<driver>",
247 GNUNET_FS_TEST_get_configuration (daemons,
248 sm->daemon));
249 GNUNET_SCHEDULER_add_now (&stat_run, sm);
250 }
251 else
252 { 269 {
253 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 270 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
254 "Timeout during download for type `%s', shutting down with error\n", 271 "Timeout during download for type `%s', shutting down with error\n",
255 type); 272 type);
256 ok = 1; 273 ok = 1;
257 GNUNET_SCHEDULER_add_now (&do_stop, NULL); 274 GNUNET_SCHEDULER_shutdown ();
275 return;
258 } 276 }
277 del = GNUNET_TIME_absolute_get_duration (start_time);
278 if (del.rel_value == 0)
279 del.rel_value = 1;
280 fancy =
281 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
282 1000LL / del.rel_value);
283 FPRINTF (stderr, "Download speed of type `%s' was %s/s\n", type, fancy);
284 GNUNET_free (fancy);
285 if (NUM_DAEMONS != ++download_counter)
286 return; /* more downloads to come */
287 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
288 "Finished all downloads, shutting down\n",
289 (unsigned long long) FILESIZE);
290 sm = GNUNET_malloc (sizeof (struct StatMaster));
291 sm->op =
292 GNUNET_TESTBED_service_connect (NULL,
293 daemons[sm->daemon],
294 "statistics",
295 &stat_run, sm,
296 &statistics_connect_adapter,
297 &statistics_disconnect_adapter,
298 NULL);
259} 299}
260 300
261 301
@@ -267,7 +307,7 @@ do_downloads (void *cls, const struct GNUNET_FS_Uri *u2)
267 307
268 if (NULL == u2) 308 if (NULL == u2)
269 { 309 {
270 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons); 310 GNUNET_SCHEDULER_shutdown ();
271 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 311 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
272 "Timeout during upload attempt, shutting down with error\n"); 312 "Timeout during upload attempt, shutting down with error\n");
273 ok = 1; 313 ok = 1;
@@ -298,14 +338,15 @@ do_downloads (void *cls, const struct GNUNET_FS_Uri *u2)
298 338
299 339
300static void 340static void
301do_publish2 (void *cls, const struct GNUNET_FS_Uri *u1) 341do_publish2 (void *cls,
342 const struct GNUNET_FS_Uri *u1)
302{ 343{
303 int do_index; 344 int do_index;
304 int anonymity; 345 int anonymity;
305 346
306 if (NULL == u1) 347 if (NULL == u1)
307 { 348 {
308 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons); 349 GNUNET_SCHEDULER_shutdown ();
309 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 350 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
310 "Timeout during upload attempt, shutting down with error\n"); 351 "Timeout during upload attempt, shutting down with error\n");
311 ok = 1; 352 ok = 1;
@@ -329,18 +370,23 @@ do_publish2 (void *cls, const struct GNUNET_FS_Uri *u1)
329} 370}
330 371
331static void 372static void
332do_publish1 (void *cls, const char *emsg) 373do_publish1 (void *cls,
374 struct GNUNET_TESTBED_Operation *op,
375 const char *emsg)
333{ 376{
377 unsigned int *coco = cls;
334 int do_index; 378 int do_index;
335 int anonymity; 379 int anonymity;
336 380
337 if (NULL != emsg) 381 if (NULL != emsg)
338 { 382 {
339 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons); 383 GNUNET_SCHEDULER_shutdown ();
340 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error trying to connect: %s\n", emsg); 384 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error trying to connect: %s\n", emsg);
341 ok = 1; 385 ok = 1;
342 return; 386 return;
343 } 387 }
388 if (0 != (--(*coco)))
389 return; /* more connections to be created */
344 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", 390 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n",
345 (unsigned long long) FILESIZE); 391 (unsigned long long) FILESIZE);
346 if (NULL != strstr (progname, "index")) 392 if (NULL != strstr (progname, "index"))
@@ -351,7 +397,6 @@ do_publish1 (void *cls, const char *emsg)
351 anonymity = 0; 397 anonymity = 0;
352 else 398 else
353 anonymity = 1; 399 anonymity = 1;
354
355 GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity, 400 GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity,
356 do_index, FILESIZE, SEED1, VERBOSE, &do_publish2, 401 do_index, FILESIZE, SEED1, VERBOSE, &do_publish2,
357 NULL); 402 NULL);
@@ -359,51 +404,38 @@ do_publish1 (void *cls, const char *emsg)
359 404
360 405
361static void 406static void
362do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 407do_connect (void *cls,
408 unsigned int num_peers,
409 struct GNUNET_TESTBED_Peer **peers)
363{ 410{
364 struct GNUNET_TESTING_PeerGroup *pg; 411 static unsigned int coco;
365 412 unsigned int i;
366 GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)); 413 unsigned int j;
367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 414
368 "Daemons started, will now try to connect them\n"); 415 GNUNET_assert (NUM_DAEMONS == num_peers);
369 pg = GNUNET_FS_TEST_get_group (daemons); 416 for (i=0;i<num_peers;i++)
370 GNUNET_TESTING_create_topology (pg, GNUNET_TESTING_TOPOLOGY_CLIQUE, 417 daemons[i] = peers[i];
371 GNUNET_TESTING_TOPOLOGY_NONE, NULL); 418 for (i=0;i<NUM_DAEMONS;i++)
372 GNUNET_TESTING_connect_topology (pg, GNUNET_TESTING_TOPOLOGY_CLIQUE, 419 for (j=i+1;j<NUM_DAEMONS;j++)
373 GNUNET_TESTING_TOPOLOGY_OPTION_NONE, 0.0, 420 {
374 TIMEOUT, NUM_DAEMONS, &do_publish1, NULL); 421 coco++;
375} 422 GNUNET_TESTBED_overlay_connect (NULL,
376 423 &do_publish1,
377 424 &coco,
378static void 425 peers[i],
379run (void *cls, char *const *args, const char *cfgfile, 426 peers[j]);
380 const struct GNUNET_CONFIGURATION_Handle *cfg) 427 }
381{
382 GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf", TIMEOUT, NUM_DAEMONS,
383 daemons, &do_connect, NULL);
384} 428}
385 429
386 430
387int 431int
388main (int argc, char *argv[]) 432main (int argc, char *argv[])
389{ 433{
390 char *const argvx[] = { 434 GNUNET_TESTBED_test_run ("perf-gnunet-service-fs-p2p-respect",
391 "perf-gnunet-service-fs-p2p", 435 "perf_gnunet_service_fs_p2p.conf",
392 "-c", 436 NUM_DAEMONS,
393 "fs_test_lib_data.conf", 437 0, NULL, NULL,
394 NULL 438 &do_connect, NULL);
395 };
396 struct GNUNET_GETOPT_CommandLineOption options[] = {
397 GNUNET_GETOPT_OPTION_END
398 };
399 progname = argv[0];
400 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
401 GNUNET_log_setup ("perf_gnunet_service_fs_p2p_respect",
402 "WARNING",
403 NULL);
404 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
405 "perf-gnunet-service-fs-p2p-respect", "nohelp", options,
406 &run, NULL);
407 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); 439 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
408 return ok; 440 return ok;
409} 441}