diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-07-29 16:21:44 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-07-29 16:21:44 +0000 |
commit | fda186a0d462dcbd221118c06a3ec6db6a819088 (patch) | |
tree | e951590f4e9281ce60517be8dd7ba9260c233bba /src/transport/gnunet-transport-profiler.c | |
parent | dc409687d69feaa175818d46b6601a885d87441e (diff) | |
download | gnunet-fda186a0d462dcbd221118c06a3ec6db6a819088.tar.gz gnunet-fda186a0d462dcbd221118c06a3ec6db6a819088.zip |
migrate gnunet-transport-profiler to new API
Diffstat (limited to 'src/transport/gnunet-transport-profiler.c')
-rw-r--r-- | src/transport/gnunet-transport-profiler.c | 249 |
1 files changed, 118 insertions, 131 deletions
diff --git a/src/transport/gnunet-transport-profiler.c b/src/transport/gnunet-transport-profiler.c index 99284990b..6e2ac6121 100644 --- a/src/transport/gnunet-transport-profiler.c +++ b/src/transport/gnunet-transport-profiler.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2011-2015 GNUnet e.V. | 3 | Copyright (C) 2011-2016 GNUnet e.V. |
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 |
@@ -32,6 +32,8 @@ | |||
32 | #include "gnunet_protocols.h" | 32 | #include "gnunet_protocols.h" |
33 | #include "gnunet_ats_service.h" | 33 | #include "gnunet_ats_service.h" |
34 | #include "gnunet_transport_service.h" | 34 | #include "gnunet_transport_service.h" |
35 | #include "gnunet_transport_core_service.h" | ||
36 | |||
35 | 37 | ||
36 | struct Iteration | 38 | struct Iteration |
37 | { | 39 | { |
@@ -107,7 +109,7 @@ static char *cpid; | |||
107 | /** | 109 | /** |
108 | * Handle to transport service. | 110 | * Handle to transport service. |
109 | */ | 111 | */ |
110 | static struct GNUNET_TRANSPORT_Handle *handle; | 112 | static struct GNUNET_TRANSPORT_CoreHandle *handle; |
111 | 113 | ||
112 | /** | 114 | /** |
113 | * Handle to ATS service. | 115 | * Handle to ATS service. |
@@ -132,10 +134,11 @@ static struct Iteration *itail; | |||
132 | * Global return value (0 success). | 134 | * Global return value (0 success). |
133 | */ | 135 | */ |
134 | static int ret; | 136 | static int ret; |
137 | |||
135 | /** | 138 | /** |
136 | * Handle for current transmission request. | 139 | * Handle for transmissions. |
137 | */ | 140 | */ |
138 | static struct GNUNET_TRANSPORT_TransmitHandle *th; | 141 | static struct GNUNET_MQ_Handle *mq; |
139 | 142 | ||
140 | static struct GNUNET_TRANSPORT_Blacklist *bl_handle; | 143 | static struct GNUNET_TRANSPORT_Blacklist *bl_handle; |
141 | 144 | ||
@@ -175,12 +178,7 @@ shutdown_task (void *cls) | |||
175 | GNUNET_ATS_connectivity_suggest_cancel (ats_sh); | 178 | GNUNET_ATS_connectivity_suggest_cancel (ats_sh); |
176 | ats_sh = NULL; | 179 | ats_sh = NULL; |
177 | } | 180 | } |
178 | if (NULL != th) | 181 | if (NULL != bl_handle) |
179 | { | ||
180 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | ||
181 | th = NULL; | ||
182 | } | ||
183 | if (NULL != bl_handle ) | ||
184 | { | 182 | { |
185 | GNUNET_TRANSPORT_blacklist_cancel (bl_handle); | 183 | GNUNET_TRANSPORT_blacklist_cancel (bl_handle); |
186 | bl_handle = NULL; | 184 | bl_handle = NULL; |
@@ -192,7 +190,7 @@ shutdown_task (void *cls) | |||
192 | } | 190 | } |
193 | if (NULL != handle) | 191 | if (NULL != handle) |
194 | { | 192 | { |
195 | GNUNET_TRANSPORT_disconnect (handle); | 193 | GNUNET_TRANSPORT_core_disconnect (handle); |
196 | handle = NULL; | 194 | handle = NULL; |
197 | } | 195 | } |
198 | 196 | ||
@@ -294,6 +292,7 @@ shutdown_task (void *cls) | |||
294 | FPRINTF (stdout, "\n"); | 292 | FPRINTF (stdout, "\n"); |
295 | } | 293 | } |
296 | 294 | ||
295 | |||
297 | static void | 296 | static void |
298 | iteration_done (); | 297 | iteration_done (); |
299 | 298 | ||
@@ -309,43 +308,36 @@ iteration_done (); | |||
309 | * @param buf where the callee should write the message | 308 | * @param buf where the callee should write the message |
310 | * @return number of bytes written to @a buf | 309 | * @return number of bytes written to @a buf |
311 | */ | 310 | */ |
312 | static size_t | 311 | static void |
313 | transmit_data (void *cls, | 312 | send_msg (void *cls) |
314 | size_t size, | ||
315 | void *buf) | ||
316 | { | 313 | { |
317 | struct GNUNET_MessageHeader *m = buf; | 314 | struct GNUNET_MQ_Envelope *env; |
318 | 315 | struct GNUNET_MessageHeader *m; | |
319 | th = NULL; | ||
320 | if ((NULL == buf) || (0 == size)) | ||
321 | { | ||
322 | th = NULL; | ||
323 | return 0; | ||
324 | } | ||
325 | |||
326 | itail->msgs_sent ++; | ||
327 | |||
328 | GNUNET_assert(size >= sizeof(struct GNUNET_MessageHeader)); | ||
329 | GNUNET_assert(size < GNUNET_SERVER_MAX_MESSAGE_SIZE); | ||
330 | m->size = ntohs (size); | ||
331 | m->type = ntohs (GNUNET_MESSAGE_TYPE_DUMMY); | ||
332 | memset (&m[1], 52, size - sizeof(struct GNUNET_MessageHeader)); | ||
333 | 316 | ||
317 | if (NULL == mq) | ||
318 | return; | ||
319 | env = GNUNET_MQ_msg_extra (m, | ||
320 | benchmark_size, | ||
321 | GNUNET_MESSAGE_TYPE_DUMMY); | ||
322 | memset (&m[1], | ||
323 | 52, | ||
324 | benchmark_size - sizeof(struct GNUNET_MessageHeader)); | ||
325 | |||
334 | if (itail->msgs_sent < benchmark_count) | 326 | if (itail->msgs_sent < benchmark_count) |
335 | { | 327 | { |
336 | th = GNUNET_TRANSPORT_notify_transmit_ready (handle, &pid, benchmark_size, | 328 | GNUNET_MQ_notify_sent (env, |
337 | GNUNET_TIME_UNIT_FOREVER_REL, &transmit_data, NULL ); | 329 | &send_msg, |
330 | NULL); | ||
338 | } | 331 | } |
339 | else | 332 | else |
340 | { | 333 | { |
341 | 334 | iteration_done (); | |
342 | iteration_done(); | ||
343 | return size; | ||
344 | } | 335 | } |
345 | if (verbosity > 0) | 336 | GNUNET_MQ_send (mq, |
346 | if (itail->msgs_sent % 10 == 0 ) | 337 | env); |
338 | if ( (verbosity > 0) && | ||
339 | (0 == itail->msgs_sent % 10) ) | ||
347 | FPRINTF (stdout, "."); | 340 | FPRINTF (stdout, "."); |
348 | return size; | ||
349 | } | 341 | } |
350 | 342 | ||
351 | 343 | ||
@@ -353,28 +345,22 @@ static void | |||
353 | iteration_start () | 345 | iteration_start () |
354 | { | 346 | { |
355 | struct Iteration *icur; | 347 | struct Iteration *icur; |
356 | ret = 0; | ||
357 | |||
358 | if (benchmark_send) | ||
359 | { | ||
360 | benchmark_running = GNUNET_YES; | ||
361 | icur = GNUNET_new (struct Iteration); | ||
362 | GNUNET_CONTAINER_DLL_insert_tail (ihead, itail, icur); | ||
363 | icur->start = GNUNET_TIME_absolute_get(); | ||
364 | 348 | ||
365 | if (verbosity > 0) | 349 | ret = 0; |
366 | FPRINTF (stdout, | 350 | if (! benchmark_send) |
367 | "\nStarting benchmark to `%s', starting to send %u messages in %u byte blocks\n", | ||
368 | GNUNET_i2s (&pid), | ||
369 | benchmark_count, | ||
370 | benchmark_size); | ||
371 | if (NULL == th) | ||
372 | th = GNUNET_TRANSPORT_notify_transmit_ready (handle, &pid, benchmark_size, | ||
373 | GNUNET_TIME_UNIT_FOREVER_REL, &transmit_data, NULL ); | ||
374 | else | ||
375 | GNUNET_break(0); | ||
376 | return; | 351 | return; |
377 | } | 352 | benchmark_running = GNUNET_YES; |
353 | icur = GNUNET_new (struct Iteration); | ||
354 | GNUNET_CONTAINER_DLL_insert_tail (ihead, | ||
355 | itail, | ||
356 | icur); | ||
357 | icur->start = GNUNET_TIME_absolute_get(); | ||
358 | if (verbosity > 0) | ||
359 | FPRINTF (stdout, | ||
360 | "\nStarting benchmark, starting to send %u messages in %u byte blocks\n", | ||
361 | benchmark_count, | ||
362 | benchmark_size); | ||
363 | send_msg (NULL); | ||
378 | } | 364 | } |
379 | 365 | ||
380 | 366 | ||
@@ -382,8 +368,8 @@ static void | |||
382 | iteration_done () | 368 | iteration_done () |
383 | { | 369 | { |
384 | static int it_count = 0; | 370 | static int it_count = 0; |
385 | it_count ++; | ||
386 | 371 | ||
372 | it_count++; | ||
387 | itail->dur = GNUNET_TIME_absolute_get_duration (itail->start); | 373 | itail->dur = GNUNET_TIME_absolute_get_duration (itail->start); |
388 | if (it_count == benchmark_iterations) | 374 | if (it_count == benchmark_iterations) |
389 | { | 375 | { |
@@ -391,10 +377,7 @@ iteration_done () | |||
391 | GNUNET_SCHEDULER_shutdown (); | 377 | GNUNET_SCHEDULER_shutdown (); |
392 | return; | 378 | return; |
393 | } | 379 | } |
394 | else | 380 | iteration_start (); |
395 | { | ||
396 | iteration_start (); | ||
397 | } | ||
398 | } | 381 | } |
399 | 382 | ||
400 | 383 | ||
@@ -404,10 +387,13 @@ iteration_done () | |||
404 | * | 387 | * |
405 | * @param cls closure | 388 | * @param cls closure |
406 | * @param peer the peer that connected | 389 | * @param peer the peer that connected |
390 | * @param m message queue for transmissions | ||
391 | * @return NULL | ||
407 | */ | 392 | */ |
408 | static void | 393 | static void * |
409 | notify_connect (void *cls, | 394 | notify_connect (void *cls, |
410 | const struct GNUNET_PeerIdentity *peer) | 395 | const struct GNUNET_PeerIdentity *peer, |
396 | struct GNUNET_MQ_Handle *m) | ||
411 | { | 397 | { |
412 | if (0 != memcmp (&pid, | 398 | if (0 != memcmp (&pid, |
413 | peer, | 399 | peer, |
@@ -416,14 +402,16 @@ notify_connect (void *cls, | |||
416 | FPRINTF (stdout, | 402 | FPRINTF (stdout, |
417 | "Connected to different peer `%s'\n", | 403 | "Connected to different peer `%s'\n", |
418 | GNUNET_i2s (&pid)); | 404 | GNUNET_i2s (&pid)); |
419 | return; | 405 | return NULL; |
420 | } | 406 | } |
421 | 407 | ||
422 | if (verbosity > 0) | 408 | if (verbosity > 0) |
423 | FPRINTF (stdout, | 409 | FPRINTF (stdout, |
424 | "Successfully connected to `%s'\n", | 410 | "Successfully connected to `%s'\n", |
425 | GNUNET_i2s (&pid)); | 411 | GNUNET_i2s (&pid)); |
412 | mq = m; | ||
426 | iteration_start (); | 413 | iteration_start (); |
414 | return NULL; | ||
427 | } | 415 | } |
428 | 416 | ||
429 | 417 | ||
@@ -433,18 +421,23 @@ notify_connect (void *cls, | |||
433 | * | 421 | * |
434 | * @param cls closure | 422 | * @param cls closure |
435 | * @param peer the peer that disconnected | 423 | * @param peer the peer that disconnected |
424 | * @param internal_cls NULL | ||
436 | */ | 425 | */ |
437 | static void | 426 | static void |
438 | notify_disconnect (void *cls, | 427 | notify_disconnect (void *cls, |
439 | const struct GNUNET_PeerIdentity *peer) | 428 | const struct GNUNET_PeerIdentity *peer, |
429 | void *internal_cls) | ||
440 | { | 430 | { |
441 | if (0 != memcmp (&pid, peer, sizeof(struct GNUNET_PeerIdentity))) | 431 | if (0 != memcmp (&pid, |
432 | peer, | ||
433 | sizeof(struct GNUNET_PeerIdentity))) | ||
442 | return; | 434 | return; |
435 | mq = NULL; | ||
443 | if (GNUNET_YES == benchmark_running) | 436 | if (GNUNET_YES == benchmark_running) |
444 | { | 437 | { |
445 | FPRINTF (stdout, | 438 | FPRINTF (stdout, |
446 | "Disconnected from peer `%s' while benchmarking\n", | 439 | "Disconnected from peer `%s' while benchmarking\n", |
447 | GNUNET_i2s (&pid)); | 440 | GNUNET_i2s (&pid)); |
448 | return; | 441 | return; |
449 | } | 442 | } |
450 | } | 443 | } |
@@ -454,25 +447,33 @@ notify_disconnect (void *cls, | |||
454 | * Function called by the transport for each received message. | 447 | * Function called by the transport for each received message. |
455 | * | 448 | * |
456 | * @param cls closure | 449 | * @param cls closure |
457 | * @param peer (claimed) identity of the other peer | 450 | * @param message the message |
451 | * @return #GNUNET_OK | ||
452 | */ | ||
453 | static int | ||
454 | check_dummy (void *cls, | ||
455 | const struct GNUNET_MessageHeader *message) | ||
456 | { | ||
457 | return GNUNET_OK; /* all messages are fine */ | ||
458 | } | ||
459 | |||
460 | |||
461 | /** | ||
462 | * Function called by the transport for each received message. | ||
463 | * | ||
464 | * @param cls closure | ||
458 | * @param message the message | 465 | * @param message the message |
459 | */ | 466 | */ |
460 | static void | 467 | static void |
461 | notify_receive (void *cls, | 468 | handle_dummy (void *cls, |
462 | const struct GNUNET_PeerIdentity *peer, | 469 | const struct GNUNET_MessageHeader *message) |
463 | const struct GNUNET_MessageHeader *message) | ||
464 | { | 470 | { |
465 | if (benchmark_receive) | 471 | if (! benchmark_receive) |
466 | { | ||
467 | if (GNUNET_MESSAGE_TYPE_DUMMY != ntohs (message->type)) | ||
468 | return; | ||
469 | if (verbosity > 0) | ||
470 | FPRINTF (stdout, | ||
471 | "Received %u bytes from %s\n", | ||
472 | (unsigned int) ntohs (message->size), | ||
473 | GNUNET_i2s (peer)); | ||
474 | return; | 472 | return; |
475 | } | 473 | if (verbosity > 0) |
474 | FPRINTF (stdout, | ||
475 | "Received %u bytes\n", | ||
476 | (unsigned int) ntohs (message->size)); | ||
476 | } | 477 | } |
477 | 478 | ||
478 | 479 | ||
@@ -480,7 +481,9 @@ static int | |||
480 | blacklist_cb (void *cls, | 481 | blacklist_cb (void *cls, |
481 | const struct GNUNET_PeerIdentity *peer) | 482 | const struct GNUNET_PeerIdentity *peer) |
482 | { | 483 | { |
483 | if (0 != memcmp (&pid, peer, sizeof(struct GNUNET_PeerIdentity))) | 484 | if (0 != memcmp (&pid, |
485 | peer, | ||
486 | sizeof(struct GNUNET_PeerIdentity))) | ||
484 | { | 487 | { |
485 | if (verbosity > 0) | 488 | if (verbosity > 0) |
486 | FPRINTF (stdout, | 489 | FPRINTF (stdout, |
@@ -488,31 +491,35 @@ blacklist_cb (void *cls, | |||
488 | GNUNET_i2s (peer)); | 491 | GNUNET_i2s (peer)); |
489 | return GNUNET_SYSERR; | 492 | return GNUNET_SYSERR; |
490 | } | 493 | } |
491 | |||
492 | return GNUNET_OK; | 494 | return GNUNET_OK; |
493 | } | 495 | } |
494 | 496 | ||
495 | 497 | ||
496 | |||
497 | /** | 498 | /** |
498 | * Function called with the result of the check if the 'transport' | 499 | * Main function that will be run by the scheduler. |
499 | * service is running. | ||
500 | * | 500 | * |
501 | * @param cls closure with our configuration | 501 | * @param cls closure |
502 | * @param result #GNUNET_YES if transport is running | 502 | * @param args remaining command-line arguments |
503 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
504 | * @param mycfg configuration | ||
503 | */ | 505 | */ |
504 | static void | 506 | static void |
505 | testservice_task (void *cls, int result) | 507 | run (void *cls, |
508 | char *const *args, | ||
509 | const char *cfgfile, | ||
510 | const struct GNUNET_CONFIGURATION_Handle *mycfg) | ||
506 | { | 511 | { |
507 | ret = 1; | 512 | GNUNET_MQ_hd_var_size (dummy, |
508 | 513 | GNUNET_MESSAGE_TYPE_DUMMY, | |
509 | if (GNUNET_YES != result) | 514 | struct GNUNET_MessageHeader); |
510 | { | 515 | struct GNUNET_MQ_MessageHandler handlers[] = { |
511 | FPRINTF (stderr, | 516 | make_dummy_handler (NULL), |
512 | "TRANSPORT service is not running\n"); | 517 | GNUNET_MQ_handler_end () |
513 | return; | 518 | }; |
514 | } | 519 | |
520 | cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg; | ||
515 | 521 | ||
522 | ret = 1; | ||
516 | if (GNUNET_SERVER_MAX_MESSAGE_SIZE <= benchmark_size) | 523 | if (GNUNET_SERVER_MAX_MESSAGE_SIZE <= benchmark_size) |
517 | { | 524 | { |
518 | FPRINTF (stderr, | 525 | FPRINTF (stderr, |
@@ -526,16 +533,16 @@ testservice_task (void *cls, int result) | |||
526 | "No peer identity given\n"); | 533 | "No peer identity given\n"); |
527 | return; | 534 | return; |
528 | } | 535 | } |
529 | if ((GNUNET_OK != | 536 | if (GNUNET_OK != |
530 | GNUNET_CRYPTO_eddsa_public_key_from_string (cpid, strlen (cpid), | 537 | GNUNET_CRYPTO_eddsa_public_key_from_string (cpid, |
531 | &pid.public_key))) | 538 | strlen (cpid), |
539 | &pid.public_key)) | ||
532 | { | 540 | { |
533 | FPRINTF (stderr, | 541 | FPRINTF (stderr, |
534 | "Failed to parse peer identity `%s'\n", | 542 | "Failed to parse peer identity `%s'\n", |
535 | cpid); | 543 | cpid); |
536 | return; | 544 | return; |
537 | } | 545 | } |
538 | |||
539 | if (1 == benchmark_send) | 546 | if (1 == benchmark_send) |
540 | { | 547 | { |
541 | if (verbosity > 0) | 548 | if (verbosity > 0) |
@@ -566,10 +573,13 @@ testservice_task (void *cls, int result) | |||
566 | return; | 573 | return; |
567 | } | 574 | } |
568 | 575 | ||
569 | handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, | 576 | handle = GNUNET_TRANSPORT_core_connect (cfg, |
570 | ¬ify_receive, | 577 | NULL, |
571 | ¬ify_connect, | 578 | handlers, |
572 | ¬ify_disconnect); | 579 | NULL, |
580 | ¬ify_connect, | ||
581 | ¬ify_disconnect, | ||
582 | NULL); | ||
573 | if (NULL == handle) | 583 | if (NULL == handle) |
574 | { | 584 | { |
575 | FPRINTF (stderr, | 585 | FPRINTF (stderr, |
@@ -591,29 +601,6 @@ testservice_task (void *cls, int result) | |||
591 | } | 601 | } |
592 | 602 | ||
593 | 603 | ||
594 | /** | ||
595 | * Main function that will be run by the scheduler. | ||
596 | * | ||
597 | * @param cls closure | ||
598 | * @param args remaining command-line arguments | ||
599 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
600 | * @param mycfg configuration | ||
601 | */ | ||
602 | static void | ||
603 | run (void *cls, | ||
604 | char * const *args, | ||
605 | const char *cfgfile, | ||
606 | const struct GNUNET_CONFIGURATION_Handle *mycfg) | ||
607 | { | ||
608 | cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg; | ||
609 | GNUNET_CLIENT_service_test ("transport", | ||
610 | cfg, | ||
611 | GNUNET_TIME_UNIT_SECONDS, | ||
612 | &testservice_task, | ||
613 | (void *) cfg); | ||
614 | } | ||
615 | |||
616 | |||
617 | int | 604 | int |
618 | main (int argc, char * const *argv) | 605 | main (int argc, char * const *argv) |
619 | { | 606 | { |