diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/nse/gnunet-nse-profiler.c | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/nse/gnunet-nse-profiler.c')
-rw-r--r-- | src/nse/gnunet-nse-profiler.c | 640 |
1 files changed, 321 insertions, 319 deletions
diff --git a/src/nse/gnunet-nse-profiler.c b/src/nse/gnunet-nse-profiler.c index eaa06b8ed..c97798772 100644 --- a/src/nse/gnunet-nse-profiler.c +++ b/src/nse/gnunet-nse-profiler.c | |||
@@ -36,18 +36,19 @@ | |||
36 | /** | 36 | /** |
37 | * Generic loggins shorthand | 37 | * Generic loggins shorthand |
38 | */ | 38 | */ |
39 | #define LOG(kind, ...) GNUNET_log(kind, __VA_ARGS__) | 39 | #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) |
40 | 40 | ||
41 | /** | 41 | /** |
42 | * Debug logging shorthand | 42 | * Debug logging shorthand |
43 | */ | 43 | */ |
44 | #define LOG_DEBUG(...) LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | 44 | #define LOG_DEBUG(...) LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) |
45 | 45 | ||
46 | 46 | ||
47 | /** | 47 | /** |
48 | * Information we track for a peer in the testbed. | 48 | * Information we track for a peer in the testbed. |
49 | */ | 49 | */ |
50 | struct NSEPeer { | 50 | struct NSEPeer |
51 | { | ||
51 | /** | 52 | /** |
52 | * Prev reference in DLL. | 53 | * Prev reference in DLL. |
53 | */ | 54 | */ |
@@ -83,7 +84,8 @@ struct NSEPeer { | |||
83 | /** | 84 | /** |
84 | * Operation map entry | 85 | * Operation map entry |
85 | */ | 86 | */ |
86 | struct OpListEntry { | 87 | struct OpListEntry |
88 | { | ||
87 | /** | 89 | /** |
88 | * DLL next ptr | 90 | * DLL next ptr |
89 | */ | 91 | */ |
@@ -229,26 +231,26 @@ static struct GNUNET_SCHEDULER_Task *round_task; | |||
229 | * STATISTICS that we keep to selected peers. | 231 | * STATISTICS that we keep to selected peers. |
230 | */ | 232 | */ |
231 | static void | 233 | static void |
232 | close_monitor_connections() | 234 | close_monitor_connections () |
233 | { | 235 | { |
234 | struct NSEPeer *pos; | 236 | struct NSEPeer *pos; |
235 | struct OpListEntry *oplist_entry; | 237 | struct OpListEntry *oplist_entry; |
236 | 238 | ||
237 | while (NULL != (pos = peer_head)) | 239 | while (NULL != (pos = peer_head)) |
238 | { | 240 | { |
239 | if (NULL != pos->nse_op) | 241 | if (NULL != pos->nse_op) |
240 | GNUNET_TESTBED_operation_done(pos->nse_op); | 242 | GNUNET_TESTBED_operation_done (pos->nse_op); |
241 | if (NULL != pos->stat_op) | 243 | if (NULL != pos->stat_op) |
242 | GNUNET_TESTBED_operation_done(pos->stat_op); | 244 | GNUNET_TESTBED_operation_done (pos->stat_op); |
243 | GNUNET_CONTAINER_DLL_remove(peer_head, peer_tail, pos); | 245 | GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, pos); |
244 | GNUNET_free(pos); | 246 | GNUNET_free (pos); |
245 | } | 247 | } |
246 | while (NULL != (oplist_entry = oplist_head)) | 248 | while (NULL != (oplist_entry = oplist_head)) |
247 | { | 249 | { |
248 | GNUNET_CONTAINER_DLL_remove(oplist_head, oplist_tail, oplist_entry); | 250 | GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, oplist_entry); |
249 | GNUNET_TESTBED_operation_done(oplist_entry->op); | 251 | GNUNET_TESTBED_operation_done (oplist_entry->op); |
250 | GNUNET_free(oplist_entry); | 252 | GNUNET_free (oplist_entry); |
251 | } | 253 | } |
252 | } | 254 | } |
253 | 255 | ||
254 | 256 | ||
@@ -258,30 +260,30 @@ close_monitor_connections() | |||
258 | * @param cls unused | 260 | * @param cls unused |
259 | */ | 261 | */ |
260 | static void | 262 | static void |
261 | shutdown_task(void *cls) | 263 | shutdown_task (void *cls) |
262 | { | 264 | { |
263 | LOG_DEBUG("Ending test.\n"); | 265 | LOG_DEBUG ("Ending test.\n"); |
264 | close_monitor_connections(); | 266 | close_monitor_connections (); |
265 | if (NULL != round_task) | 267 | if (NULL != round_task) |
266 | { | 268 | { |
267 | GNUNET_SCHEDULER_cancel(round_task); | 269 | GNUNET_SCHEDULER_cancel (round_task); |
268 | round_task = NULL; | 270 | round_task = NULL; |
269 | } | 271 | } |
270 | if (NULL != data_file) | 272 | if (NULL != data_file) |
271 | { | 273 | { |
272 | GNUNET_DISK_file_close(data_file); | 274 | GNUNET_DISK_file_close (data_file); |
273 | data_file = NULL; | 275 | data_file = NULL; |
274 | } | 276 | } |
275 | if (NULL != output_file) | 277 | if (NULL != output_file) |
276 | { | 278 | { |
277 | GNUNET_DISK_file_close(output_file); | 279 | GNUNET_DISK_file_close (output_file); |
278 | output_file = NULL; | 280 | output_file = NULL; |
279 | } | 281 | } |
280 | if (NULL != testing_cfg) | 282 | if (NULL != testing_cfg) |
281 | { | 283 | { |
282 | GNUNET_CONFIGURATION_destroy(testing_cfg); | 284 | GNUNET_CONFIGURATION_destroy (testing_cfg); |
283 | testing_cfg = NULL; | 285 | testing_cfg = NULL; |
284 | } | 286 | } |
285 | } | 287 | } |
286 | 288 | ||
287 | 289 | ||
@@ -295,35 +297,35 @@ shutdown_task(void *cls) | |||
295 | * of the size estimation values seen | 297 | * of the size estimation values seen |
296 | */ | 298 | */ |
297 | static void | 299 | static void |
298 | handle_estimate(void *cls, | 300 | handle_estimate (void *cls, |
299 | struct GNUNET_TIME_Absolute timestamp, | 301 | struct GNUNET_TIME_Absolute timestamp, |
300 | double estimate, | 302 | double estimate, |
301 | double std_dev) | 303 | double std_dev) |
302 | { | 304 | { |
303 | struct NSEPeer *peer = cls; | 305 | struct NSEPeer *peer = cls; |
304 | char output_buffer[512]; | 306 | char output_buffer[512]; |
305 | size_t size; | 307 | size_t size; |
306 | 308 | ||
307 | if (NULL == output_file) | 309 | if (NULL == output_file) |
308 | { | 310 | { |
309 | fprintf(stderr, | 311 | fprintf (stderr, |
310 | "Received network size estimate from peer %p. Size: %f std.dev. %f\n", | 312 | "Received network size estimate from peer %p. Size: %f std.dev. %f\n", |
311 | peer, | 313 | peer, |
312 | estimate, | 314 | estimate, |
313 | std_dev); | 315 | std_dev); |
314 | return; | 316 | return; |
315 | } | 317 | } |
316 | size = GNUNET_snprintf(output_buffer, | 318 | size = GNUNET_snprintf (output_buffer, |
317 | sizeof(output_buffer), | 319 | sizeof(output_buffer), |
318 | "%p %llu %llu %f %f %f\n", | 320 | "%p %llu %llu %f %f %f\n", |
319 | peer, | 321 | peer, |
320 | peers_running, | 322 | peers_running, |
321 | (unsigned long long)timestamp.abs_value_us, | 323 | (unsigned long long) timestamp.abs_value_us, |
322 | GNUNET_NSE_log_estimate_to_n(estimate), | 324 | GNUNET_NSE_log_estimate_to_n (estimate), |
323 | estimate, | 325 | estimate, |
324 | std_dev); | 326 | std_dev); |
325 | if (size != GNUNET_DISK_file_write(output_file, output_buffer, size)) | 327 | if (size != GNUNET_DISK_file_write (output_file, output_buffer, size)) |
326 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n"); | 328 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n"); |
327 | } | 329 | } |
328 | 330 | ||
329 | 331 | ||
@@ -338,11 +340,11 @@ handle_estimate(void *cls, | |||
338 | * @return service handle to return in 'op_result', NULL on error | 340 | * @return service handle to return in 'op_result', NULL on error |
339 | */ | 341 | */ |
340 | static void * | 342 | static void * |
341 | nse_connect_adapter(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | 343 | nse_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) |
342 | { | 344 | { |
343 | struct NSEPeer *current_peer = cls; | 345 | struct NSEPeer *current_peer = cls; |
344 | 346 | ||
345 | return GNUNET_NSE_connect(cfg, &handle_estimate, current_peer); | 347 | return GNUNET_NSE_connect (cfg, &handle_estimate, current_peer); |
346 | } | 348 | } |
347 | 349 | ||
348 | 350 | ||
@@ -354,9 +356,9 @@ nse_connect_adapter(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
354 | * @param op_result service handle returned from the connect adapter | 356 | * @param op_result service handle returned from the connect adapter |
355 | */ | 357 | */ |
356 | static void | 358 | static void |
357 | nse_disconnect_adapter(void *cls, void *op_result) | 359 | nse_disconnect_adapter (void *cls, void *op_result) |
358 | { | 360 | { |
359 | GNUNET_NSE_disconnect(op_result); | 361 | GNUNET_NSE_disconnect (op_result); |
360 | } | 362 | } |
361 | 363 | ||
362 | 364 | ||
@@ -371,40 +373,40 @@ nse_disconnect_adapter(void *cls, void *op_result) | |||
371 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration | 373 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration |
372 | */ | 374 | */ |
373 | static int | 375 | static int |
374 | stat_iterator(void *cls, | 376 | stat_iterator (void *cls, |
375 | const char *subsystem, | 377 | const char *subsystem, |
376 | const char *name, | 378 | const char *name, |
377 | uint64_t value, | 379 | uint64_t value, |
378 | int is_persistent) | 380 | int is_persistent) |
379 | { | 381 | { |
380 | char *output_buffer; | 382 | char *output_buffer; |
381 | struct GNUNET_TIME_Absolute now; | 383 | struct GNUNET_TIME_Absolute now; |
382 | int size; | 384 | int size; |
383 | unsigned int flag; | 385 | unsigned int flag; |
384 | 386 | ||
385 | GNUNET_assert(NULL != data_file); | 387 | GNUNET_assert (NULL != data_file); |
386 | now = GNUNET_TIME_absolute_get(); | 388 | now = GNUNET_TIME_absolute_get (); |
387 | flag = strcasecmp(subsystem, "core"); | 389 | flag = strcasecmp (subsystem, "core"); |
388 | if (0 != flag) | 390 | if (0 != flag) |
389 | flag = 1; | 391 | flag = 1; |
390 | size = GNUNET_asprintf(&output_buffer, | 392 | size = GNUNET_asprintf (&output_buffer, |
391 | "%llu %llu %u\n", | 393 | "%llu %llu %u\n", |
392 | now.abs_value_us / 1000LL / 1000LL, | 394 | now.abs_value_us / 1000LL / 1000LL, |
393 | value, | 395 | value, |
394 | flag); | 396 | flag); |
395 | if (0 > size) | 397 | if (0 > size) |
396 | { | 398 | { |
397 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Error formatting output buffer.\n"); | 399 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Error formatting output buffer.\n"); |
398 | GNUNET_free(output_buffer); | 400 | GNUNET_free (output_buffer); |
399 | return GNUNET_SYSERR; | 401 | return GNUNET_SYSERR; |
400 | } | 402 | } |
401 | if (size != GNUNET_DISK_file_write(data_file, output_buffer, (size_t)size)) | 403 | if (size != GNUNET_DISK_file_write (data_file, output_buffer, (size_t) size)) |
402 | { | 404 | { |
403 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n"); | 405 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n"); |
404 | GNUNET_free(output_buffer); | 406 | GNUNET_free (output_buffer); |
405 | return GNUNET_SYSERR; | 407 | return GNUNET_SYSERR; |
406 | } | 408 | } |
407 | GNUNET_free(output_buffer); | 409 | GNUNET_free (output_buffer); |
408 | return GNUNET_OK; | 410 | return GNUNET_OK; |
409 | } | 411 | } |
410 | 412 | ||
@@ -419,11 +421,11 @@ stat_iterator(void *cls, | |||
419 | * @return service handle to return in 'op_result', NULL on error | 421 | * @return service handle to return in 'op_result', NULL on error |
420 | */ | 422 | */ |
421 | static void * | 423 | static void * |
422 | stat_connect_adapter(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | 424 | stat_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) |
423 | { | 425 | { |
424 | struct NSEPeer *peer = cls; | 426 | struct NSEPeer *peer = cls; |
425 | 427 | ||
426 | peer->sh = GNUNET_STATISTICS_create("nse-profiler", cfg); | 428 | peer->sh = GNUNET_STATISTICS_create ("nse-profiler", cfg); |
427 | return peer->sh; | 429 | return peer->sh; |
428 | } | 430 | } |
429 | 431 | ||
@@ -435,23 +437,23 @@ stat_connect_adapter(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
435 | * @param op_result service handle returned from the connect adapter | 437 | * @param op_result service handle returned from the connect adapter |
436 | */ | 438 | */ |
437 | static void | 439 | static void |
438 | stat_disconnect_adapter(void *cls, void *op_result) | 440 | stat_disconnect_adapter (void *cls, void *op_result) |
439 | { | 441 | { |
440 | struct NSEPeer *peer = cls; | 442 | struct NSEPeer *peer = cls; |
441 | 443 | ||
442 | GNUNET_break(GNUNET_OK == | 444 | GNUNET_break (GNUNET_OK == |
443 | GNUNET_STATISTICS_watch_cancel(peer->sh, | 445 | GNUNET_STATISTICS_watch_cancel (peer->sh, |
444 | "core", | 446 | "core", |
445 | "# peers connected", | 447 | "# peers connected", |
446 | stat_iterator, | 448 | stat_iterator, |
447 | peer)); | 449 | peer)); |
448 | GNUNET_break(GNUNET_OK == | 450 | GNUNET_break (GNUNET_OK == |
449 | GNUNET_STATISTICS_watch_cancel(peer->sh, | 451 | GNUNET_STATISTICS_watch_cancel (peer->sh, |
450 | "nse", | 452 | "nse", |
451 | "# peers connected", | 453 | "# peers connected", |
452 | stat_iterator, | 454 | stat_iterator, |
453 | peer)); | 455 | peer)); |
454 | GNUNET_STATISTICS_destroy(op_result, GNUNET_NO); | 456 | GNUNET_STATISTICS_destroy (op_result, GNUNET_NO); |
455 | peer->sh = NULL; | 457 | peer->sh = NULL; |
456 | } | 458 | } |
457 | 459 | ||
@@ -467,29 +469,29 @@ stat_disconnect_adapter(void *cls, void *op_result) | |||
467 | * operation has executed successfully. | 469 | * operation has executed successfully. |
468 | */ | 470 | */ |
469 | static void | 471 | static void |
470 | stat_comp_cb(void *cls, | 472 | stat_comp_cb (void *cls, |
471 | struct GNUNET_TESTBED_Operation *op, | 473 | struct GNUNET_TESTBED_Operation *op, |
472 | void *ca_result, | 474 | void *ca_result, |
473 | const char *emsg) | 475 | const char *emsg) |
474 | { | 476 | { |
475 | struct GNUNET_STATISTICS_Handle *sh = ca_result; | 477 | struct GNUNET_STATISTICS_Handle *sh = ca_result; |
476 | struct NSEPeer *peer = cls; | 478 | struct NSEPeer *peer = cls; |
477 | 479 | ||
478 | if (NULL != emsg) | 480 | if (NULL != emsg) |
479 | { | 481 | { |
480 | GNUNET_break(0); | 482 | GNUNET_break (0); |
481 | return; | 483 | return; |
482 | } | 484 | } |
483 | GNUNET_break(GNUNET_OK == GNUNET_STATISTICS_watch(sh, | 485 | GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch (sh, |
484 | "core", | 486 | "core", |
485 | "# peers connected", | 487 | "# peers connected", |
486 | stat_iterator, | 488 | stat_iterator, |
487 | peer)); | 489 | peer)); |
488 | GNUNET_break(GNUNET_OK == GNUNET_STATISTICS_watch(sh, | 490 | GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch (sh, |
489 | "nse", | 491 | "nse", |
490 | "# peers connected", | 492 | "# peers connected", |
491 | stat_iterator, | 493 | stat_iterator, |
492 | peer)); | 494 | peer)); |
493 | } | 495 | } |
494 | 496 | ||
495 | 497 | ||
@@ -498,7 +500,7 @@ stat_comp_cb(void *cls, | |||
498 | * all of the running peers. | 500 | * all of the running peers. |
499 | */ | 501 | */ |
500 | static void | 502 | static void |
501 | connect_nse_service() | 503 | connect_nse_service () |
502 | { | 504 | { |
503 | struct NSEPeer *current_peer; | 505 | struct NSEPeer *current_peer; |
504 | unsigned int i; | 506 | unsigned int i; |
@@ -506,39 +508,39 @@ connect_nse_service() | |||
506 | 508 | ||
507 | if (0 == connection_limit) | 509 | if (0 == connection_limit) |
508 | return; | 510 | return; |
509 | LOG_DEBUG("Connecting to nse service of peers\n"); | 511 | LOG_DEBUG ("Connecting to nse service of peers\n"); |
510 | connections = 0; | 512 | connections = 0; |
511 | for (i = 0; i < num_peers_in_round[current_round]; i++) | 513 | for (i = 0; i < num_peers_in_round[current_round]; i++) |
512 | { | 514 | { |
513 | if ((num_peers_in_round[current_round] > connection_limit) && | 515 | if ((num_peers_in_round[current_round] > connection_limit) && |
514 | (0 != (i % (num_peers_in_round[current_round] / connection_limit)))) | 516 | (0 != (i % (num_peers_in_round[current_round] / connection_limit)))) |
515 | continue; | 517 | continue; |
516 | LOG_DEBUG("Connecting to nse service of peer %d\n", i); | 518 | LOG_DEBUG ("Connecting to nse service of peer %d\n", i); |
517 | current_peer = GNUNET_new(struct NSEPeer); | 519 | current_peer = GNUNET_new (struct NSEPeer); |
518 | current_peer->daemon = daemons[i]; | 520 | current_peer->daemon = daemons[i]; |
519 | current_peer->nse_op = | 521 | current_peer->nse_op = |
520 | GNUNET_TESTBED_service_connect(NULL, | 522 | GNUNET_TESTBED_service_connect (NULL, |
521 | current_peer->daemon, | 523 | current_peer->daemon, |
522 | "nse", | 524 | "nse", |
523 | NULL, | 525 | NULL, |
524 | NULL, | 526 | NULL, |
525 | &nse_connect_adapter, | 527 | &nse_connect_adapter, |
526 | &nse_disconnect_adapter, | 528 | &nse_disconnect_adapter, |
527 | current_peer); | 529 | current_peer); |
528 | if (NULL != data_file) | 530 | if (NULL != data_file) |
529 | current_peer->stat_op = | 531 | current_peer->stat_op = |
530 | GNUNET_TESTBED_service_connect(NULL, | 532 | GNUNET_TESTBED_service_connect (NULL, |
531 | current_peer->daemon, | 533 | current_peer->daemon, |
532 | "statistics", | 534 | "statistics", |
533 | stat_comp_cb, | 535 | stat_comp_cb, |
534 | current_peer, | 536 | current_peer, |
535 | &stat_connect_adapter, | 537 | &stat_connect_adapter, |
536 | &stat_disconnect_adapter, | 538 | &stat_disconnect_adapter, |
537 | current_peer); | 539 | current_peer); |
538 | GNUNET_CONTAINER_DLL_insert(peer_head, peer_tail, current_peer); | 540 | GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, current_peer); |
539 | if (++connections == connection_limit) | 541 | if (++connections == connection_limit) |
540 | break; | 542 | break; |
541 | } | 543 | } |
542 | } | 544 | } |
543 | 545 | ||
544 | 546 | ||
@@ -548,7 +550,7 @@ connect_nse_service() | |||
548 | * @param cls NULL, unused | 550 | * @param cls NULL, unused |
549 | */ | 551 | */ |
550 | static void | 552 | static void |
551 | next_round(void *cls); | 553 | next_round (void *cls); |
552 | 554 | ||
553 | 555 | ||
554 | /** | 556 | /** |
@@ -559,11 +561,11 @@ next_round(void *cls); | |||
559 | * @param cls unused, NULL | 561 | * @param cls unused, NULL |
560 | */ | 562 | */ |
561 | static void | 563 | static void |
562 | finish_round(void *cls) | 564 | finish_round (void *cls) |
563 | { | 565 | { |
564 | LOG(GNUNET_ERROR_TYPE_INFO, "Have %u connections\n", total_connections); | 566 | LOG (GNUNET_ERROR_TYPE_INFO, "Have %u connections\n", total_connections); |
565 | close_monitor_connections(); | 567 | close_monitor_connections (); |
566 | round_task = GNUNET_SCHEDULER_add_now(&next_round, NULL); | 568 | round_task = GNUNET_SCHEDULER_add_now (&next_round, NULL); |
567 | } | 569 | } |
568 | 570 | ||
569 | 571 | ||
@@ -573,11 +575,11 @@ finish_round(void *cls) | |||
573 | * specified delay before finishing the round). | 575 | * specified delay before finishing the round). |
574 | */ | 576 | */ |
575 | static void | 577 | static void |
576 | run_round() | 578 | run_round () |
577 | { | 579 | { |
578 | LOG_DEBUG("Running round %u\n", current_round); | 580 | LOG_DEBUG ("Running round %u\n", current_round); |
579 | connect_nse_service(); | 581 | connect_nse_service (); |
580 | GNUNET_SCHEDULER_add_delayed(wait_time, &finish_round, NULL); | 582 | GNUNET_SCHEDULER_add_delayed (wait_time, &finish_round, NULL); |
581 | } | 583 | } |
582 | 584 | ||
583 | 585 | ||
@@ -585,12 +587,12 @@ run_round() | |||
585 | * Creates an oplist entry and adds it to the oplist DLL | 587 | * Creates an oplist entry and adds it to the oplist DLL |
586 | */ | 588 | */ |
587 | static struct OpListEntry * | 589 | static struct OpListEntry * |
588 | make_oplist_entry() | 590 | make_oplist_entry () |
589 | { | 591 | { |
590 | struct OpListEntry *entry; | 592 | struct OpListEntry *entry; |
591 | 593 | ||
592 | entry = GNUNET_new(struct OpListEntry); | 594 | entry = GNUNET_new (struct OpListEntry); |
593 | GNUNET_CONTAINER_DLL_insert_tail(oplist_head, oplist_tail, entry); | 595 | GNUNET_CONTAINER_DLL_insert_tail (oplist_head, oplist_tail, entry); |
594 | return entry; | 596 | return entry; |
595 | } | 597 | } |
596 | 598 | ||
@@ -603,25 +605,25 @@ make_oplist_entry() | |||
603 | * @param emsg NULL on success; otherwise an error description | 605 | * @param emsg NULL on success; otherwise an error description |
604 | */ | 606 | */ |
605 | static void | 607 | static void |
606 | manage_service_cb(void *cls, | 608 | manage_service_cb (void *cls, |
607 | struct GNUNET_TESTBED_Operation *op, | 609 | struct GNUNET_TESTBED_Operation *op, |
608 | const char *emsg) | 610 | const char *emsg) |
609 | { | 611 | { |
610 | struct OpListEntry *entry = cls; | 612 | struct OpListEntry *entry = cls; |
611 | 613 | ||
612 | GNUNET_TESTBED_operation_done(entry->op); | 614 | GNUNET_TESTBED_operation_done (entry->op); |
613 | if (NULL != emsg) | 615 | if (NULL != emsg) |
614 | { | 616 | { |
615 | LOG(GNUNET_ERROR_TYPE_ERROR, "Failed to start/stop NSE at a peer\n"); | 617 | LOG (GNUNET_ERROR_TYPE_ERROR, "Failed to start/stop NSE at a peer\n"); |
616 | GNUNET_SCHEDULER_shutdown(); | 618 | GNUNET_SCHEDULER_shutdown (); |
617 | return; | 619 | return; |
618 | } | 620 | } |
619 | GNUNET_assert(0 != entry->delta); | 621 | GNUNET_assert (0 != entry->delta); |
620 | peers_running += entry->delta; | 622 | peers_running += entry->delta; |
621 | GNUNET_CONTAINER_DLL_remove(oplist_head, oplist_tail, entry); | 623 | GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry); |
622 | GNUNET_free(entry); | 624 | GNUNET_free (entry); |
623 | if (num_peers_in_round[current_round] == peers_running) | 625 | if (num_peers_in_round[current_round] == peers_running) |
624 | run_round(); | 626 | run_round (); |
625 | } | 627 | } |
626 | 628 | ||
627 | 629 | ||
@@ -630,35 +632,35 @@ manage_service_cb(void *cls, | |||
630 | * peers for the round | 632 | * peers for the round |
631 | */ | 633 | */ |
632 | static void | 634 | static void |
633 | adjust_running_peers() | 635 | adjust_running_peers () |
634 | { | 636 | { |
635 | struct OpListEntry *entry; | 637 | struct OpListEntry *entry; |
636 | unsigned int i; | 638 | unsigned int i; |
637 | 639 | ||
638 | /* start peers if we have too few */ | 640 | /* start peers if we have too few */ |
639 | for (i = peers_running; i < num_peers_in_round[current_round]; i++) | 641 | for (i = peers_running; i < num_peers_in_round[current_round]; i++) |
640 | { | 642 | { |
641 | entry = make_oplist_entry(); | 643 | entry = make_oplist_entry (); |
642 | entry->delta = 1; | 644 | entry->delta = 1; |
643 | entry->op = GNUNET_TESTBED_peer_manage_service(NULL, | 645 | entry->op = GNUNET_TESTBED_peer_manage_service (NULL, |
644 | daemons[i], | 646 | daemons[i], |
645 | "nse", | 647 | "nse", |
646 | &manage_service_cb, | 648 | &manage_service_cb, |
647 | entry, | 649 | entry, |
648 | 1); | 650 | 1); |
649 | } | 651 | } |
650 | /* stop peers if we have too many */ | 652 | /* stop peers if we have too many */ |
651 | for (i = num_peers_in_round[current_round]; i < peers_running; i++) | 653 | for (i = num_peers_in_round[current_round]; i < peers_running; i++) |
652 | { | 654 | { |
653 | entry = make_oplist_entry(); | 655 | entry = make_oplist_entry (); |
654 | entry->delta = -1; | 656 | entry->delta = -1; |
655 | entry->op = GNUNET_TESTBED_peer_manage_service(NULL, | 657 | entry->op = GNUNET_TESTBED_peer_manage_service (NULL, |
656 | daemons[i], | 658 | daemons[i], |
657 | "nse", | 659 | "nse", |
658 | &manage_service_cb, | 660 | &manage_service_cb, |
659 | entry, | 661 | entry, |
660 | 0); | 662 | 0); |
661 | } | 663 | } |
662 | } | 664 | } |
663 | 665 | ||
664 | 666 | ||
@@ -669,25 +671,25 @@ adjust_running_peers() | |||
669 | * @param cls NULL, unused | 671 | * @param cls NULL, unused |
670 | */ | 672 | */ |
671 | static void | 673 | static void |
672 | next_round(void *cls) | 674 | next_round (void *cls) |
673 | { | 675 | { |
674 | round_task = NULL; | 676 | round_task = NULL; |
675 | LOG_DEBUG("Disconnecting nse service of peers\n"); | 677 | LOG_DEBUG ("Disconnecting nse service of peers\n"); |
676 | current_round++; | 678 | current_round++; |
677 | if (current_round == num_rounds) | 679 | if (current_round == num_rounds) |
678 | { | 680 | { |
679 | /* this was the last round, terminate */ | 681 | /* this was the last round, terminate */ |
680 | ok = 0; | 682 | ok = 0; |
681 | GNUNET_SCHEDULER_shutdown(); | 683 | GNUNET_SCHEDULER_shutdown (); |
682 | return; | 684 | return; |
683 | } | 685 | } |
684 | if (num_peers_in_round[current_round] == peers_running) | 686 | if (num_peers_in_round[current_round] == peers_running) |
685 | { | 687 | { |
686 | /* no need to churn, just run next round */ | 688 | /* no need to churn, just run next round */ |
687 | run_round(); | 689 | run_round (); |
688 | return; | 690 | return; |
689 | } | 691 | } |
690 | adjust_running_peers(); | 692 | adjust_running_peers (); |
691 | } | 693 | } |
692 | 694 | ||
693 | 695 | ||
@@ -699,22 +701,22 @@ next_round(void *cls) | |||
699 | * @param event information on what is happening | 701 | * @param event information on what is happening |
700 | */ | 702 | */ |
701 | static void | 703 | static void |
702 | master_controller_cb(void *cls, | 704 | master_controller_cb (void *cls, |
703 | const struct GNUNET_TESTBED_EventInformation *event) | 705 | const struct GNUNET_TESTBED_EventInformation *event) |
704 | { | 706 | { |
705 | switch (event->type) | 707 | switch (event->type) |
706 | { | 708 | { |
707 | case GNUNET_TESTBED_ET_CONNECT: | 709 | case GNUNET_TESTBED_ET_CONNECT: |
708 | total_connections++; | 710 | total_connections++; |
709 | break; | 711 | break; |
710 | 712 | ||
711 | case GNUNET_TESTBED_ET_DISCONNECT: | 713 | case GNUNET_TESTBED_ET_DISCONNECT: |
712 | total_connections--; | 714 | total_connections--; |
713 | break; | 715 | break; |
714 | 716 | ||
715 | default: | 717 | default: |
716 | break; | 718 | break; |
717 | } | 719 | } |
718 | } | 720 | } |
719 | 721 | ||
720 | 722 | ||
@@ -732,28 +734,28 @@ master_controller_cb(void *cls, | |||
732 | * failed | 734 | * failed |
733 | */ | 735 | */ |
734 | static void | 736 | static void |
735 | test_master(void *cls, | 737 | test_master (void *cls, |
736 | struct GNUNET_TESTBED_RunHandle *h, | 738 | struct GNUNET_TESTBED_RunHandle *h, |
737 | unsigned int num_peers_, | 739 | unsigned int num_peers_, |
738 | struct GNUNET_TESTBED_Peer **peers, | 740 | struct GNUNET_TESTBED_Peer **peers, |
739 | unsigned int links_succeeded, | 741 | unsigned int links_succeeded, |
740 | unsigned int links_failed) | 742 | unsigned int links_failed) |
741 | { | 743 | { |
742 | if (NULL == peers) | 744 | if (NULL == peers) |
743 | { | 745 | { |
744 | GNUNET_SCHEDULER_shutdown(); | 746 | GNUNET_SCHEDULER_shutdown (); |
745 | return; | 747 | return; |
746 | } | 748 | } |
747 | daemons = peers; | 749 | daemons = peers; |
748 | GNUNET_break(num_peers_ == num_peers); | 750 | GNUNET_break (num_peers_ == num_peers); |
749 | peers_running = num_peers; | 751 | peers_running = num_peers; |
750 | if (num_peers_in_round[current_round] == peers_running) | 752 | if (num_peers_in_round[current_round] == peers_running) |
751 | { | 753 | { |
752 | /* no need to churn, just run the starting round */ | 754 | /* no need to churn, just run the starting round */ |
753 | run_round(); | 755 | run_round (); |
754 | return; | 756 | return; |
755 | } | 757 | } |
756 | adjust_running_peers(); | 758 | adjust_running_peers (); |
757 | } | 759 | } |
758 | 760 | ||
759 | 761 | ||
@@ -766,75 +768,75 @@ test_master(void *cls, | |||
766 | * @param cfg configuration handle | 768 | * @param cfg configuration handle |
767 | */ | 769 | */ |
768 | static void | 770 | static void |
769 | run(void *cls, | 771 | run (void *cls, |
770 | char *const *args, | 772 | char *const *args, |
771 | const char *cfgfile, | 773 | const char *cfgfile, |
772 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 774 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
773 | { | 775 | { |
774 | char *tok; | 776 | char *tok; |
775 | uint64_t event_mask; | 777 | uint64_t event_mask; |
776 | unsigned int num; | 778 | unsigned int num; |
777 | 779 | ||
778 | ok = 1; | 780 | ok = 1; |
779 | testing_cfg = GNUNET_CONFIGURATION_dup(cfg); | 781 | testing_cfg = GNUNET_CONFIGURATION_dup (cfg); |
780 | LOG_DEBUG("Starting daemons.\n"); | 782 | LOG_DEBUG ("Starting daemons.\n"); |
781 | if (NULL == num_peer_spec) | 783 | if (NULL == num_peer_spec) |
784 | { | ||
785 | fprintf (stderr, "You need to specify the number of peers to run\n"); | ||
786 | return; | ||
787 | } | ||
788 | for (tok = strtok (num_peer_spec, ","); NULL != tok; tok = strtok (NULL, ",")) | ||
789 | { | ||
790 | if (1 != sscanf (tok, "%u", &num)) | ||
782 | { | 791 | { |
783 | fprintf(stderr, "You need to specify the number of peers to run\n"); | 792 | fprintf (stderr, "You need to specify numbers, not `%s'\n", tok); |
784 | return; | 793 | return; |
785 | } | 794 | } |
786 | for (tok = strtok(num_peer_spec, ","); NULL != tok; tok = strtok(NULL, ",")) | 795 | if (0 == num) |
787 | { | ||
788 | if (1 != sscanf(tok, "%u", &num)) | ||
789 | { | ||
790 | fprintf(stderr, "You need to specify numbers, not `%s'\n", tok); | ||
791 | return; | ||
792 | } | ||
793 | if (0 == num) | ||
794 | { | ||
795 | fprintf(stderr, "Refusing to run a round with 0 peers\n"); | ||
796 | return; | ||
797 | } | ||
798 | GNUNET_array_append(num_peers_in_round, num_rounds, num); | ||
799 | num_peers = GNUNET_MAX(num_peers, num); | ||
800 | } | ||
801 | if (0 == num_peers) | ||
802 | { | 796 | { |
803 | fprintf(stderr, "Refusing to run a testbed with no rounds\n"); | 797 | fprintf (stderr, "Refusing to run a round with 0 peers\n"); |
804 | return; | 798 | return; |
805 | } | 799 | } |
800 | GNUNET_array_append (num_peers_in_round, num_rounds, num); | ||
801 | num_peers = GNUNET_MAX (num_peers, num); | ||
802 | } | ||
803 | if (0 == num_peers) | ||
804 | { | ||
805 | fprintf (stderr, "Refusing to run a testbed with no rounds\n"); | ||
806 | return; | ||
807 | } | ||
806 | if ((NULL != data_filename) && | 808 | if ((NULL != data_filename) && |
807 | (NULL == | 809 | (NULL == |
808 | (data_file = GNUNET_DISK_file_open(data_filename, | 810 | (data_file = GNUNET_DISK_file_open (data_filename, |
809 | GNUNET_DISK_OPEN_READWRITE | | 811 | GNUNET_DISK_OPEN_READWRITE |
810 | GNUNET_DISK_OPEN_TRUNCATE | | 812 | | GNUNET_DISK_OPEN_TRUNCATE |
811 | GNUNET_DISK_OPEN_CREATE, | 813 | | GNUNET_DISK_OPEN_CREATE, |
812 | GNUNET_DISK_PERM_USER_READ | | 814 | GNUNET_DISK_PERM_USER_READ |
813 | GNUNET_DISK_PERM_USER_WRITE)))) | 815 | | GNUNET_DISK_PERM_USER_WRITE)))) |
814 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "open", data_filename); | 816 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", data_filename); |
815 | 817 | ||
816 | if ((NULL != output_filename) && | 818 | if ((NULL != output_filename) && |
817 | (NULL == | 819 | (NULL == |
818 | (output_file = GNUNET_DISK_file_open(output_filename, | 820 | (output_file = GNUNET_DISK_file_open (output_filename, |
819 | GNUNET_DISK_OPEN_READWRITE | | 821 | GNUNET_DISK_OPEN_READWRITE |
820 | GNUNET_DISK_OPEN_CREATE, | 822 | | GNUNET_DISK_OPEN_CREATE, |
821 | GNUNET_DISK_PERM_USER_READ | | 823 | GNUNET_DISK_PERM_USER_READ |
822 | GNUNET_DISK_PERM_USER_WRITE)))) | 824 | | GNUNET_DISK_PERM_USER_WRITE)))) |
823 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "open", output_filename); | 825 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", output_filename); |
824 | event_mask = 0LL; | 826 | event_mask = 0LL; |
825 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START); | 827 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START); |
826 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP); | 828 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP); |
827 | event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); | 829 | event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); |
828 | event_mask |= (1LL << GNUNET_TESTBED_ET_DISCONNECT); | 830 | event_mask |= (1LL << GNUNET_TESTBED_ET_DISCONNECT); |
829 | GNUNET_TESTBED_run(hosts_file, | 831 | GNUNET_TESTBED_run (hosts_file, |
830 | cfg, | 832 | cfg, |
831 | num_peers, | 833 | num_peers, |
832 | event_mask, | 834 | event_mask, |
833 | master_controller_cb, | 835 | master_controller_cb, |
834 | NULL, /* master_controller_cb cls */ | 836 | NULL, /* master_controller_cb cls */ |
835 | &test_master, | 837 | &test_master, |
836 | NULL); /* test_master cls */ | 838 | NULL); /* test_master cls */ |
837 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); | 839 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
838 | } | 840 | } |
839 | 841 | ||
840 | 842 | ||
@@ -844,73 +846,73 @@ run(void *cls, | |||
844 | * @return 0 on success | 846 | * @return 0 on success |
845 | */ | 847 | */ |
846 | int | 848 | int |
847 | main(int argc, char *const *argv) | 849 | main (int argc, char *const *argv) |
848 | { | 850 | { |
849 | struct GNUNET_GETOPT_CommandLineOption options[] = | 851 | struct GNUNET_GETOPT_CommandLineOption options[] = |
850 | { GNUNET_GETOPT_option_uint( | 852 | { GNUNET_GETOPT_option_uint ( |
851 | 'C', | 853 | 'C', |
852 | "connections", | 854 | "connections", |
853 | "COUNT", | 855 | "COUNT", |
854 | gettext_noop( | 856 | gettext_noop ( |
855 | "limit to the number of connections to NSE services, 0 for none"), | 857 | "limit to the number of connections to NSE services, 0 for none"), |
856 | &connection_limit), | 858 | &connection_limit), |
857 | GNUNET_GETOPT_option_string( | 859 | GNUNET_GETOPT_option_string ( |
858 | 'd', | 860 | 'd', |
859 | "details", | 861 | "details", |
860 | "FILENAME", | 862 | "FILENAME", |
861 | gettext_noop( | 863 | gettext_noop ( |
862 | "name of the file for writing connection information and statistics"), | 864 | "name of the file for writing connection information and statistics"), |
863 | &data_filename), | 865 | &data_filename), |
864 | 866 | ||
865 | GNUNET_GETOPT_option_string( | 867 | GNUNET_GETOPT_option_string ( |
866 | 'H', | 868 | 'H', |
867 | "hosts", | 869 | "hosts", |
868 | "FILENAME", | 870 | "FILENAME", |
869 | gettext_noop( | 871 | gettext_noop ( |
870 | "name of the file with the login information for the testbed"), | 872 | "name of the file with the login information for the testbed"), |
871 | &hosts_file), | 873 | &hosts_file), |
872 | 874 | ||
873 | GNUNET_GETOPT_option_string( | 875 | GNUNET_GETOPT_option_string ( |
874 | 'o', | 876 | 'o', |
875 | "output", | 877 | "output", |
876 | "FILENAME", | 878 | "FILENAME", |
877 | gettext_noop("name of the file for writing the main results"), | 879 | gettext_noop ("name of the file for writing the main results"), |
878 | &output_filename), | 880 | &output_filename), |
879 | 881 | ||
880 | 882 | ||
881 | GNUNET_GETOPT_option_string( | 883 | GNUNET_GETOPT_option_string ( |
882 | 'p', | 884 | 'p', |
883 | "peers", | 885 | "peers", |
884 | "NETWORKSIZESPEC", | 886 | "NETWORKSIZESPEC", |
885 | gettext_noop( | 887 | gettext_noop ( |
886 | "Number of peers to run in each round, separated by commas"), | 888 | "Number of peers to run in each round, separated by commas"), |
887 | &num_peer_spec), | 889 | &num_peer_spec), |
888 | 890 | ||
889 | GNUNET_GETOPT_option_increment_uint( | 891 | GNUNET_GETOPT_option_increment_uint ( |
890 | 'V', | 892 | 'V', |
891 | "verbose", | 893 | "verbose", |
892 | gettext_noop("be verbose (print progress information)"), | 894 | gettext_noop ("be verbose (print progress information)"), |
893 | &verbose), | 895 | &verbose), |
894 | 896 | ||
895 | GNUNET_GETOPT_option_relative_time('w', | 897 | GNUNET_GETOPT_option_relative_time ('w', |
896 | "wait", | 898 | "wait", |
897 | "DELAY", | 899 | "DELAY", |
898 | gettext_noop("delay between rounds"), | 900 | gettext_noop ("delay between rounds"), |
899 | &wait_time), | 901 | &wait_time), |
900 | GNUNET_GETOPT_OPTION_END }; | 902 | GNUNET_GETOPT_OPTION_END }; |
901 | 903 | ||
902 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) | 904 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
903 | return 2; | 905 | return 2; |
904 | if ( | 906 | if ( |
905 | GNUNET_OK != | 907 | GNUNET_OK != |
906 | GNUNET_PROGRAM_run(argc, | 908 | GNUNET_PROGRAM_run (argc, |
907 | argv, | 909 | argv, |
908 | "nse-profiler", | 910 | "nse-profiler", |
909 | gettext_noop( | 911 | gettext_noop ( |
910 | "Measure quality and performance of the NSE service."), | 912 | "Measure quality and performance of the NSE service."), |
911 | options, | 913 | options, |
912 | &run, | 914 | &run, |
913 | NULL)) | 915 | NULL)) |
914 | ok = 1; | 916 | ok = 1; |
915 | return ok; | 917 | return ok; |
916 | } | 918 | } |