summaryrefslogtreecommitdiff
path: root/src/fs/perf_gnunet_service_fs_p2p_respect.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/perf_gnunet_service_fs_p2p_respect.c')
-rw-r--r--src/fs/perf_gnunet_service_fs_p2p_respect.c331
1 files changed, 167 insertions, 164 deletions
diff --git a/src/fs/perf_gnunet_service_fs_p2p_respect.c b/src/fs/perf_gnunet_service_fs_p2p_respect.c
index 91ec9c66d..fc17235fa 100644
--- a/src/fs/perf_gnunet_service_fs_p2p_respect.c
+++ b/src/fs/perf_gnunet_service_fs_p2p_respect.c
@@ -57,7 +57,7 @@
57/** 57/**
58 * How long until we give up on transmitting the message? 58 * How long until we give up on transmitting the message?
59 */ 59 */
60#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 30) 60#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30)
61 61
62/** 62/**
63 * Number of daemons in clique, must be at least 3 (!). 63 * Number of daemons in clique, must be at least 3 (!).
@@ -93,14 +93,16 @@ static char *fn2;
93/** 93/**
94 * Master context for 'stat_run'. 94 * Master context for 'stat_run'.
95 */ 95 */
96struct StatMaster { 96struct StatMaster
97{
97 struct GNUNET_STATISTICS_Handle *stat; 98 struct GNUNET_STATISTICS_Handle *stat;
98 struct GNUNET_TESTBED_Operation *op; 99 struct GNUNET_TESTBED_Operation *op;
99 unsigned int daemon; 100 unsigned int daemon;
100 unsigned int value; 101 unsigned int value;
101}; 102};
102 103
103struct StatValues { 104struct StatValues
105{
104 const char *subsystem; 106 const char *subsystem;
105 const char *name; 107 const char *name;
106}; 108};
@@ -134,19 +136,19 @@ static struct StatValues stats[] = {
134 136
135 137
136static void 138static void
137cleanup() 139cleanup ()
138{ 140{
139 GNUNET_SCHEDULER_shutdown(); 141 GNUNET_SCHEDULER_shutdown ();
140 if (NULL != fn1) 142 if (NULL != fn1)
141 { 143 {
142 GNUNET_DISK_directory_remove(fn1); 144 GNUNET_DISK_directory_remove (fn1);
143 GNUNET_free(fn1); 145 GNUNET_free (fn1);
144 } 146 }
145 if (NULL != fn2) 147 if (NULL != fn2)
146 { 148 {
147 GNUNET_DISK_directory_remove(fn2); 149 GNUNET_DISK_directory_remove (fn2);
148 GNUNET_free(fn2); 150 GNUNET_free (fn2);
149 } 151 }
150} 152}
151 153
152 154
@@ -161,13 +163,13 @@ cleanup()
161 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration 163 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
162 */ 164 */
163static int 165static int
164print_stat(void *cls, const char *subsystem, const char *name, uint64_t value, 166print_stat (void *cls, const char *subsystem, const char *name, uint64_t value,
165 int is_persistent) 167 int is_persistent)
166{ 168{
167 struct StatMaster *sm = cls; 169 struct StatMaster *sm = cls;
168 170
169 fprintf(stderr, "Peer %2u: %12s/%50s = %12llu\n", sm->daemon, subsystem, 171 fprintf (stderr, "Peer %2u: %12s/%50s = %12llu\n", sm->daemon, subsystem,
170 name, (unsigned long long)value); 172 name, (unsigned long long) value);
171 return GNUNET_OK; 173 return GNUNET_OK;
172} 174}
173 175
@@ -176,23 +178,23 @@ print_stat(void *cls, const char *subsystem, const char *name, uint64_t value,
176 * Function that gathers stats from all daemons. 178 * Function that gathers stats from all daemons.
177 */ 179 */
178static void 180static void
179stat_run(void *cls, 181stat_run (void *cls,
180 struct GNUNET_TESTBED_Operation *op, 182 struct GNUNET_TESTBED_Operation *op,
181 void *ca_result, 183 void *ca_result,
182 const char *emsg); 184 const char *emsg);
183 185
184 186
185/** 187/**
186 * Function called when GET operation on stats is done. 188 * Function called when GET operation on stats is done.
187 */ 189 */
188static void 190static void
189get_done(void *cls, int success) 191get_done (void *cls, int success)
190{ 192{
191 struct StatMaster *sm = cls; 193 struct StatMaster *sm = cls;
192 194
193 GNUNET_break(GNUNET_OK == success); 195 GNUNET_break (GNUNET_OK == success);
194 sm->value++; 196 sm->value++;
195 stat_run(sm, sm->op, sm->stat, NULL); 197 stat_run (sm, sm->op, sm->stat, NULL);
196} 198}
197 199
198 200
@@ -208,11 +210,11 @@ get_done(void *cls, int success)
208 * @return service handle to return in 'op_result', NULL on error 210 * @return service handle to return in 'op_result', NULL on error
209 */ 211 */
210static void * 212static void *
211statistics_connect_adapter(void *cls, 213statistics_connect_adapter (void *cls,
212 const struct GNUNET_CONFIGURATION_Handle *cfg) 214 const struct GNUNET_CONFIGURATION_Handle *cfg)
213{ 215{
214 return GNUNET_STATISTICS_create("<driver>", 216 return GNUNET_STATISTICS_create ("<driver>",
215 cfg); 217 cfg);
216} 218}
217 219
218 220
@@ -224,10 +226,10 @@ statistics_connect_adapter(void *cls,
224 * @param op_result service handle returned from the connect adapter 226 * @param op_result service handle returned from the connect adapter
225 */ 227 */
226static void 228static void
227statistics_disconnect_adapter(void *cls, 229statistics_disconnect_adapter (void *cls,
228 void *op_result) 230 void *op_result)
229{ 231{
230 GNUNET_STATISTICS_destroy(op_result, GNUNET_NO); 232 GNUNET_STATISTICS_destroy (op_result, GNUNET_NO);
231} 233}
232 234
233 235
@@ -235,49 +237,49 @@ statistics_disconnect_adapter(void *cls,
235 * Function that gathers stats from all daemons. 237 * Function that gathers stats from all daemons.
236 */ 238 */
237static void 239static void
238stat_run(void *cls, 240stat_run (void *cls,
239 struct GNUNET_TESTBED_Operation *op, 241 struct GNUNET_TESTBED_Operation *op,
240 void *ca_result, 242 void *ca_result,
241 const char *emsg) 243 const char *emsg)
242{ 244{
243 struct StatMaster *sm = cls; 245 struct StatMaster *sm = cls;
244 246
245 sm->stat = ca_result; 247 sm->stat = ca_result;
246 GNUNET_assert(NULL != sm->stat); 248 GNUNET_assert (NULL != sm->stat);
247 if (NULL != stats[sm->value].name) 249 if (NULL != stats[sm->value].name)
248 { 250 {
249 GNUNET_STATISTICS_get(sm->stat, 251 GNUNET_STATISTICS_get (sm->stat,
250#if 0 252#if 0
251 NULL, NULL, 253 NULL, NULL,
252#else 254#else
253 stats[sm->value].subsystem, stats[sm->value].name, 255 stats[sm->value].subsystem, stats[sm->value].name,
254#endif 256#endif
255 &get_done, &print_stat, 257 &get_done, &print_stat,
256 sm); 258 sm);
257 return; 259 return;
258 } 260 }
259 GNUNET_TESTBED_operation_done(sm->op); 261 GNUNET_TESTBED_operation_done (sm->op);
260 sm->value = 0; 262 sm->value = 0;
261 sm->daemon++; 263 sm->daemon++;
262 if (NUM_DAEMONS == sm->daemon) 264 if (NUM_DAEMONS == sm->daemon)
263 { 265 {
264 GNUNET_free(sm); 266 GNUNET_free (sm);
265 cleanup(); 267 cleanup ();
266 return; 268 return;
267 } 269 }
268 sm->op = 270 sm->op =
269 GNUNET_TESTBED_service_connect(NULL, 271 GNUNET_TESTBED_service_connect (NULL,
270 daemons[sm->daemon], 272 daemons[sm->daemon],
271 "statistics", 273 "statistics",
272 &stat_run, sm, 274 &stat_run, sm,
273 &statistics_connect_adapter, 275 &statistics_connect_adapter,
274 &statistics_disconnect_adapter, 276 &statistics_disconnect_adapter,
275 NULL); 277 NULL);
276} 278}
277 279
278 280
279static void 281static void
280do_report(void *cls) 282do_report (void *cls)
281{ 283{
282 static int download_counter; 284 static int download_counter;
283 const char *type = cls; 285 const char *type = cls;
@@ -286,62 +288,63 @@ do_report(void *cls)
286 struct StatMaster *sm; 288 struct StatMaster *sm;
287 289
288 if (0 == 290 if (0 ==
289 GNUNET_TIME_absolute_get_remaining(GNUNET_TIME_absolute_add(start_time, 291 GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_add (start_time,
290 TIMEOUT)).rel_value_us) 292 TIMEOUT)).
291 { 293 rel_value_us)
292 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 294 {
293 "Timeout during download for type `%s', shutting down with error\n", 295 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
294 type); 296 "Timeout during download for type `%s', shutting down with error\n",
295 ok = 1; 297 type);
296 cleanup(); 298 ok = 1;
297 return; 299 cleanup ();
298 } 300 return;
299 del = GNUNET_TIME_absolute_get_duration(start_time); 301 }
302 del = GNUNET_TIME_absolute_get_duration (start_time);
300 if (del.rel_value_us == 0) 303 if (del.rel_value_us == 0)
301 del.rel_value_us = 1; 304 del.rel_value_us = 1;
302 fancy = 305 fancy =
303 GNUNET_STRINGS_byte_size_fancy(((unsigned long long)FILESIZE) * 306 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE)
304 1000000LL / del.rel_value_us); 307 * 1000000LL / del.rel_value_us);
305 fprintf(stderr, "Download speed of type `%s' was %s/s\n", type, fancy); 308 fprintf (stderr, "Download speed of type `%s' was %s/s\n", type, fancy);
306 GNUNET_free(fancy); 309 GNUNET_free (fancy);
307 if (NUM_DAEMONS != ++download_counter) 310 if (NUM_DAEMONS != ++download_counter)
308 return; /* more downloads to come */ 311 return; /* more downloads to come */
309 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 312 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
310 "Finished all downloads, getting statistics\n"); 313 "Finished all downloads, getting statistics\n");
311 sm = GNUNET_new(struct StatMaster); 314 sm = GNUNET_new (struct StatMaster);
312 sm->op = 315 sm->op =
313 GNUNET_TESTBED_service_connect(NULL, 316 GNUNET_TESTBED_service_connect (NULL,
314 daemons[sm->daemon], 317 daemons[sm->daemon],
315 "statistics", 318 "statistics",
316 &stat_run, sm, 319 &stat_run, sm,
317 &statistics_connect_adapter, 320 &statistics_connect_adapter,
318 &statistics_disconnect_adapter, 321 &statistics_disconnect_adapter,
319 NULL); 322 NULL);
320} 323}
321 324
322 325
323static void 326static void
324do_downloads(void *cls, const struct GNUNET_FS_Uri *u2, 327do_downloads (void *cls, const struct GNUNET_FS_Uri *u2,
325 const char *fn) 328 const char *fn)
326{ 329{
327 int anonymity; 330 int anonymity;
328 unsigned int i; 331 unsigned int i;
329 332
330 if (NULL == u2) 333 if (NULL == u2)
331 { 334 {
332 cleanup(); 335 cleanup ();
333 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 336 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
334 "Timeout during upload attempt, shutting down with error\n"); 337 "Timeout during upload attempt, shutting down with error\n");
335 ok = 1; 338 ok = 1;
336 return; 339 return;
337 } 340 }
338 if (NULL != fn) 341 if (NULL != fn)
339 fn2 = GNUNET_strdup(fn); 342 fn2 = GNUNET_strdup (fn);
340 uri2 = GNUNET_FS_uri_dup(u2); 343 uri2 = GNUNET_FS_uri_dup (u2);
341 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n", 344 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n",
342 (unsigned long long)FILESIZE); 345 (unsigned long long) FILESIZE);
343 start_time = GNUNET_TIME_absolute_get(); 346 start_time = GNUNET_TIME_absolute_get ();
344 if (NULL != strstr(progname, "dht")) 347 if (NULL != strstr (progname, "dht"))
345 anonymity = 0; 348 anonymity = 0;
346 else 349 else
347 anonymity = 1; 350 anonymity = 1;
@@ -349,127 +352,127 @@ do_downloads(void *cls, const struct GNUNET_FS_Uri *u2,
349 * these peers do participate in sharing, they just 352 * these peers do participate in sharing, they just
350 * don't have to offer anything *initially*. */ 353 * don't have to offer anything *initially*. */
351 for (i = 0; i < NUM_DAEMONS - 2; i++) 354 for (i = 0; i < NUM_DAEMONS - 2; i++)
352 GNUNET_FS_TEST_download(daemons[i], TIMEOUT, anonymity, 355 GNUNET_FS_TEST_download (daemons[i], TIMEOUT, anonymity,
353 0 == (i % 2) ? SEED1 : SEED2, 356 0 == (i % 2) ? SEED1 : SEED2,
354 0 == (i % 2) ? uri1 : uri2, VERBOSE, &do_report, 357 0 == (i % 2) ? uri1 : uri2, VERBOSE, &do_report,
355 "leach"); 358 "leach");
356 /* mutual downloads of (primary) sharing peers */ 359 /* mutual downloads of (primary) sharing peers */
357 GNUNET_FS_TEST_download(daemons[NUM_DAEMONS - 2], TIMEOUT, anonymity, SEED1, 360 GNUNET_FS_TEST_download (daemons[NUM_DAEMONS - 2], TIMEOUT, anonymity, SEED1,
358 uri1, VERBOSE, &do_report, "seeder 2"); 361 uri1, VERBOSE, &do_report, "seeder 2");
359 GNUNET_FS_TEST_download(daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity, SEED2, 362 GNUNET_FS_TEST_download (daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity, SEED2,
360 uri2, VERBOSE, &do_report, "seeder 1"); 363 uri2, VERBOSE, &do_report, "seeder 1");
361} 364}
362 365
363 366
364static void 367static void
365do_publish2(void *cls, 368do_publish2 (void *cls,
366 const struct GNUNET_FS_Uri *u1, 369 const struct GNUNET_FS_Uri *u1,
367 const char *fn) 370 const char *fn)
368{ 371{
369 int do_index; 372 int do_index;
370 int anonymity; 373 int anonymity;
371 374
372 if (NULL == u1) 375 if (NULL == u1)
373 { 376 {
374 cleanup(); 377 cleanup ();
375 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 378 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
376 "Timeout during upload attempt, shutting down with error\n"); 379 "Timeout during upload attempt, shutting down with error\n");
377 ok = 1; 380 ok = 1;
378 return; 381 return;
379 } 382 }
380 if (NULL != fn) 383 if (NULL != fn)
381 fn1 = GNUNET_strdup(fn); 384 fn1 = GNUNET_strdup (fn);
382 uri1 = GNUNET_FS_uri_dup(u1); 385 uri1 = GNUNET_FS_uri_dup (u1);
383 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", 386 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n",
384 (unsigned long long)FILESIZE); 387 (unsigned long long) FILESIZE);
385 if (NULL != strstr(progname, "index")) 388 if (NULL != strstr (progname, "index"))
386 do_index = GNUNET_YES; 389 do_index = GNUNET_YES;
387 else 390 else
388 do_index = GNUNET_NO; 391 do_index = GNUNET_NO;
389 if (NULL != strstr(progname, "dht")) 392 if (NULL != strstr (progname, "dht"))
390 anonymity = 0; 393 anonymity = 0;
391 else 394 else
392 anonymity = 1; 395 anonymity = 1;
393 396
394 GNUNET_FS_TEST_publish(daemons[NUM_DAEMONS - 2], TIMEOUT, anonymity, 397 GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 2], TIMEOUT, anonymity,
395 do_index, FILESIZE, SEED2, VERBOSE, &do_downloads, 398 do_index, FILESIZE, SEED2, VERBOSE, &do_downloads,
396 NULL); 399 NULL);
397} 400}
398 401
399 402
400static void 403static void
401do_publish1(void *cls, 404do_publish1 (void *cls,
402 struct GNUNET_TESTBED_Operation *op, 405 struct GNUNET_TESTBED_Operation *op,
403 const char *emsg) 406 const char *emsg)
404{ 407{
405 unsigned int *coco = cls; 408 unsigned int *coco = cls;
406 int do_index; 409 int do_index;
407 int anonymity; 410 int anonymity;
408 411
409 GNUNET_TESTBED_operation_done(op); 412 GNUNET_TESTBED_operation_done (op);
410 if (NULL != emsg) 413 if (NULL != emsg)
411 { 414 {
412 cleanup(); 415 cleanup ();
413 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Error trying to connect: %s\n", emsg); 416 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error trying to connect: %s\n", emsg);
414 ok = 1; 417 ok = 1;
415 return; 418 return;
416 } 419 }
417 if (0 != (--(*coco))) 420 if (0 != (--(*coco)))
418 return; /* more connections to be created */ 421 return; /* more connections to be created */
419 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", 422 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n",
420 (unsigned long long)FILESIZE); 423 (unsigned long long) FILESIZE);
421 if (NULL != strstr(progname, "index")) 424 if (NULL != strstr (progname, "index"))
422 do_index = GNUNET_YES; 425 do_index = GNUNET_YES;
423 else 426 else
424 do_index = GNUNET_NO; 427 do_index = GNUNET_NO;
425 if (NULL != strstr(progname, "dht")) 428 if (NULL != strstr (progname, "dht"))
426 anonymity = 0; 429 anonymity = 0;
427 else 430 else
428 anonymity = 1; 431 anonymity = 1;
429 GNUNET_FS_TEST_publish(daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity, 432 GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity,
430 do_index, FILESIZE, SEED1, VERBOSE, &do_publish2, 433 do_index, FILESIZE, SEED1, VERBOSE, &do_publish2,
431 NULL); 434 NULL);
432} 435}
433 436
434 437
435static void 438static void
436do_connect(void *cls, 439do_connect (void *cls,
437 struct GNUNET_TESTBED_RunHandle *h, 440 struct GNUNET_TESTBED_RunHandle *h,
438 unsigned int num_peers, 441 unsigned int num_peers,
439 struct GNUNET_TESTBED_Peer **peers, 442 struct GNUNET_TESTBED_Peer **peers,
440 unsigned int links_succeeded, 443 unsigned int links_succeeded,
441 unsigned int links_failed) 444 unsigned int links_failed)
442{ 445{
443 static unsigned int coco; 446 static unsigned int coco;
444 unsigned int i; 447 unsigned int i;
445 unsigned int j; 448 unsigned int j;
446 449
447 GNUNET_assert(NUM_DAEMONS == num_peers); 450 GNUNET_assert (NUM_DAEMONS == num_peers);
448 for (i = 0; i < num_peers; i++) 451 for (i = 0; i < num_peers; i++)
449 daemons[i] = peers[i]; 452 daemons[i] = peers[i];
450 for (i = 0; i < NUM_DAEMONS; i++) 453 for (i = 0; i < NUM_DAEMONS; i++)
451 for (j = i + 1; j < NUM_DAEMONS; j++) 454 for (j = i + 1; j < NUM_DAEMONS; j++)
452 { 455 {
453 coco++; 456 coco++;
454 GNUNET_TESTBED_overlay_connect(NULL, 457 GNUNET_TESTBED_overlay_connect (NULL,
455 &do_publish1, 458 &do_publish1,
456 &coco, 459 &coco,
457 peers[i], 460 peers[i],
458 peers[j]); 461 peers[j]);
459 } 462 }
460} 463}
461 464
462 465
463int 466int
464main(int argc, char *argv[]) 467main (int argc, char *argv[])
465{ 468{
466 progname = argv[0]; 469 progname = argv[0];
467 (void)GNUNET_TESTBED_test_run("perf-gnunet-service-fs-p2p-respect", 470 (void) GNUNET_TESTBED_test_run ("perf-gnunet-service-fs-p2p-respect",
468 "perf_gnunet_service_fs_p2p.conf", 471 "perf_gnunet_service_fs_p2p.conf",
469 NUM_DAEMONS, 472 NUM_DAEMONS,
470 0, NULL, NULL, 473 0, NULL, NULL,
471 &do_connect, NULL); 474 &do_connect, NULL);
472 GNUNET_DISK_directory_remove("/tmp/gnunet-test-fs-lib/"); 475 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
473 return ok; 476 return ok;
474} 477}
475 478