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