aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2014-03-14 15:49:17 +0000
committerBart Polot <bart@net.in.tum.de>2014-03-14 15:49:17 +0000
commit3bbb7996efbbf9fa82abfd71ee0e3c62d7181e35 (patch)
treef2b28be32af886cd43440ed52f3a839b9ba260b9 /src
parent61d423e7d79c80b179bc09da17a6fe87967b6144 (diff)
downloadgnunet-3bbb7996efbbf9fa82abfd71ee0e3c62d7181e35.tar.gz
gnunet-3bbb7996efbbf9fa82abfd71ee0e3c62d7181e35.zip
- use ping-pong to avoid collisions
Diffstat (limited to 'src')
-rw-r--r--src/mesh/gnunet-mesh-profiler.c142
1 files changed, 119 insertions, 23 deletions
diff --git a/src/mesh/gnunet-mesh-profiler.c b/src/mesh/gnunet-mesh-profiler.c
index 512461ed2..b95b6f4ab 100644
--- a/src/mesh/gnunet-mesh-profiler.c
+++ b/src/mesh/gnunet-mesh-profiler.c
@@ -29,10 +29,13 @@
29#include "gnunet_statistics_service.h" 29#include "gnunet_statistics_service.h"
30 30
31 31
32#define PING 1
33#define PONG 2
34
32/** 35/**
33 * How namy peers to run 36 * How namy peers to run
34 */ 37 */
35#define TOTAL_PEERS 1000 38#define TOTAL_PEERS 10
36 39
37/** 40/**
38 * How long until we give up on connecting the peers? 41 * How long until we give up on connecting the peers?
@@ -208,7 +211,7 @@ show_end_data (void)
208static void 211static void
209shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 212shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
210{ 213{
211 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending test.\n"); 214 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Ending test.\n");
212 shutdown_handle = GNUNET_SCHEDULER_NO_TASK; 215 shutdown_handle = GNUNET_SCHEDULER_NO_TASK;
213} 216}
214 217
@@ -302,7 +305,7 @@ stats_iterator (void *cls, const struct GNUNET_TESTBED_Peer *peer,
302 uint32_t i; 305 uint32_t i;
303 306
304 i = GNUNET_TESTBED_get_index (peer); 307 i = GNUNET_TESTBED_get_index (peer);
305 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " %u - %s [%s]: %llu\n", 308 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " STATS %u - %s [%s]: %llu\n",
306 i, subsystem, name, value); 309 i, subsystem, name, value);
307 310
308 return GNUNET_OK; 311 return GNUNET_OK;
@@ -351,18 +354,30 @@ finish_profiler (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
351/** 354/**
352 * Transmit ready callback. 355 * Transmit ready callback.
353 * 356 *
354 * @param cls Closure (peer). 357 * @param cls Closure (unused).
355 * @param size Size of the tranmist buffer. 358 * @param size Size of the tranmist buffer.
356 * @param buf Pointer to the beginning of the buffer. 359 * @param buf Pointer to the beginning of the buffer.
357 * 360 *
358 * @return Number of bytes written to buf. 361 * @return Number of bytes written to buf.
359 */ 362 */
360static size_t 363static size_t
361tmt_rdy (void *cls, size_t size, void *buf); 364tmt_ping_rdy (void *cls, size_t size, void *buf);
365
366/**
367 * Transmit ready callback.
368 *
369 * @param cls Closure (unused).
370 * @param size Size of the tranmist buffer.
371 * @param buf Pointer to the beginning of the buffer.
372 *
373 * @return Number of bytes written to buf.
374 */
375static size_t
376tmt_pong_rdy (void *cls, size_t size, void *buf);
362 377
363 378
364/** 379/**
365 * @brief Send data to destination 380 * @brief Send a ping to destination
366 * 381 *
367 * @param cls Closure (peer). 382 * @param cls Closure (peer).
368 * @param tc Task context. 383 * @param tc Task context.
@@ -376,24 +391,38 @@ ping (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
376 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0) 391 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
377 return; 392 return;
378 393
379 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%u -> %u\n", 394 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u -> %u\n",
380 get_index (peer), get_index (peer->dest)); 395 get_index (peer), get_index (peer->dest));
381 396
382 GNUNET_MESH_notify_transmit_ready (peer->ch, GNUNET_NO, 397 GNUNET_MESH_notify_transmit_ready (peer->ch, GNUNET_NO,
383 GNUNET_TIME_UNIT_FOREVER_REL, 398 GNUNET_TIME_UNIT_FOREVER_REL,
384 size_payload, &tmt_rdy, peer); 399 size_payload, &tmt_ping_rdy, peer);
400}
401
402/**
403 * @brief Reply with a pong to origin.
404 *
405 * @param cls Closure (peer).
406 * @param tc Task context.
407 */
408static void
409pong (struct GNUNET_MESH_Channel *channel)
410{
411 GNUNET_MESH_notify_transmit_ready (channel, GNUNET_NO,
412 GNUNET_TIME_UNIT_FOREVER_REL,
413 size_payload, &tmt_pong_rdy, NULL);
385} 414}
386 415
387 416
388/** 417/**
389 * Transmit ready callback 418 * Transmit ready callback
390 * 419 *
391 * @param cls Closure (peer). 420 * @param cls Closure (unused).
392 * @param size Size of the buffer we have. 421 * @param size Size of the buffer we have.
393 * @param buf Buffer to copy data to. 422 * @param buf Buffer to copy data to.
394 */ 423 */
395size_t 424size_t
396tmt_rdy (void *cls, size_t size, void *buf) 425tmt_ping_rdy (void *cls, size_t size, void *buf)
397{ 426{
398 struct MeshPeer *peer = (struct MeshPeer *) cls; 427 struct MeshPeer *peer = (struct MeshPeer *) cls;
399 struct GNUNET_MessageHeader *msg = buf; 428 struct GNUNET_MessageHeader *msg = buf;
@@ -412,7 +441,7 @@ tmt_rdy (void *cls, size_t size, void *buf)
412 return 0; 441 return 0;
413 } 442 }
414 msg->size = htons (size); 443 msg->size = htons (size);
415 msg->type = htons ((long) cls); 444 msg->type = htons (PING);
416 data = (uint32_t *) &msg[1]; 445 data = (uint32_t *) &msg[1];
417 *data = htonl (peer->data_sent); 446 *data = htonl (peer->data_sent);
418 if (0 == peer->data_sent) 447 if (0 == peer->data_sent)
@@ -435,7 +464,32 @@ tmt_rdy (void *cls, size_t size, void *buf)
435 464
436 465
437/** 466/**
438 * Function is called whenever a message is received. 467 * Transmit ready callback
468 *
469 * @param cls Closure (unused).
470 * @param size Size of the buffer we have.
471 * @param buf Buffer to copy data to.
472 */
473size_t
474tmt_pong_rdy (void *cls, size_t size, void *buf)
475{
476 struct GNUNET_MessageHeader *msg = buf;
477 size_t size_payload = sizeof (struct GNUNET_MessageHeader);
478
479 if (size < size_payload || NULL == buf)
480 {
481 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Cannot send PONG\n");
482 return 0;
483 }
484 msg->size = htons (size_payload);
485 msg->type = htons (PONG);
486
487 return size_payload;
488}
489
490
491/**
492 * Function is called whenever a PING message is received.
439 * 493 *
440 * @param cls closure (peer #, set from GNUNET_MESH_connect) 494 * @param cls closure (peer #, set from GNUNET_MESH_connect)
441 * @param channel connection to the other end 495 * @param channel connection to the other end
@@ -445,9 +499,35 @@ tmt_rdy (void *cls, size_t size, void *buf)
445 * GNUNET_SYSERR to close it (signal serious error) 499 * GNUNET_SYSERR to close it (signal serious error)
446 */ 500 */
447int 501int
448data_callback (void *cls, struct GNUNET_MESH_Channel *channel, 502ping_handler (void *cls, struct GNUNET_MESH_Channel *channel,
449 void **channel_ctx, 503 void **channel_ctx,
450 const struct GNUNET_MessageHeader *message) 504 const struct GNUNET_MessageHeader *message)
505{
506 long n = (long) cls;
507
508 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%u got PING\n", n);
509 GNUNET_MESH_receive_done (channel);
510 if (GNUNET_NO == test_finished)
511 pong (channel);
512
513 return GNUNET_OK;
514}
515
516
517/**
518 * Function is called whenever a PONG message is received.
519 *
520 * @param cls closure (peer #, set from GNUNET_MESH_connect)
521 * @param channel connection to the other end
522 * @param channel_ctx place to store local state associated with the channel
523 * @param message the actual message
524 * @return GNUNET_OK to keep the connection open,
525 * GNUNET_SYSERR to close it (signal serious error)
526 */
527int
528pong_handler (void *cls, struct GNUNET_MESH_Channel *channel,
529 void **channel_ctx,
530 const struct GNUNET_MessageHeader *message)
451{ 531{
452 long n = (long) cls; 532 long n = (long) cls;
453 struct MeshPeer *peer; 533 struct MeshPeer *peer;
@@ -471,7 +551,8 @@ data_callback (void *cls, struct GNUNET_MESH_Channel *channel,
471 * Handlers, for diverse services 551 * Handlers, for diverse services
472 */ 552 */
473static struct GNUNET_MESH_MessageHandler handlers[] = { 553static struct GNUNET_MESH_MessageHandler handlers[] = {
474 {&data_callback, 1, sizeof (struct GNUNET_MessageHeader)}, 554 {&ping_handler, PING, sizeof (struct GNUNET_MessageHeader)},
555 {&pong_handler, PONG, sizeof (struct GNUNET_MessageHeader)},
475 {NULL, 0, 0} 556 {NULL, 0, 0}
476}; 557};
477 558
@@ -540,6 +621,20 @@ channel_cleaner (void *cls, const struct GNUNET_MESH_Channel *channel,
540} 621}
541 622
542 623
624static struct MeshPeer *
625select_random_peer (struct MeshPeer *peer)
626{
627 unsigned int r;
628
629 do
630 {
631 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, TOTAL_PEERS);
632 } while (NULL != peers[r].incoming);
633 peers[r].incoming = peer;
634
635 return &peers[r];
636}
637
543/** 638/**
544 * START THE TESTCASE ITSELF, AS WE ARE CONNECTED TO THE MESH SERVICES. 639 * START THE TESTCASE ITSELF, AS WE ARE CONNECTED TO THE MESH SERVICES.
545 * 640 *
@@ -569,13 +664,13 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
569 flags = GNUNET_MESH_OPTION_DEFAULT; 664 flags = GNUNET_MESH_OPTION_DEFAULT;
570 for (i = 0; i < TOTAL_PEERS; i++) 665 for (i = 0; i < TOTAL_PEERS; i++)
571 { 666 {
572 unsigned int r; 667
573 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, TOTAL_PEERS); 668 peers[i].dest = select_random_peer (&peers[i]);
574 peers[i].dest = &peers[r];
575 peers[i].ch = GNUNET_MESH_channel_create (peers[i].mesh, NULL, 669 peers[i].ch = GNUNET_MESH_channel_create (peers[i].mesh, NULL,
576 &peers[i].dest->id, 670 &peers[i].dest->id,
577 1, flags); 671 1, flags);
578 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%u => %u\n", i, r); 672 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u => %u\n",
673 i, get_index (peers[i].dest));
579 peers[i].ping_task = GNUNET_SCHEDULER_add_delayed (delay_ms_rnd (2000), 674 peers[i].ping_task = GNUNET_SCHEDULER_add_delayed (delay_ms_rnd (2000),
580 &ping, &peers[i]); 675 &ping, &peers[i]);
581 } 676 }
@@ -606,7 +701,7 @@ peer_id_cb (void *cls,
606 return; 701 return;
607 } 702 }
608 peers[n].id = *(pinfo->result.id); 703 peers[n].id = *(pinfo->result.id);
609 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " %u id: %s\n", 704 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " %u id: %s\n",
610 n, GNUNET_i2s (&peers[n].id)); 705 n, GNUNET_i2s (&peers[n].id));
611 GNUNET_break (GNUNET_OK == 706 GNUNET_break (GNUNET_OK ==
612 GNUNET_CONTAINER_multipeermap_put (ids, &peers[n].id, &peers[n], 707 GNUNET_CONTAINER_multipeermap_put (ids, &peers[n].id, &peers[n],
@@ -642,7 +737,7 @@ tmain (void *cls,
642 test_ctx = ctx; 737 test_ctx = ctx;
643 GNUNET_assert (TOTAL_PEERS == num_peers); 738 GNUNET_assert (TOTAL_PEERS == num_peers);
644 peers_running = num_peers; 739 peers_running = num_peers;
645 testbed_handles = testbed_handles; 740 testbed_handles = testbed_peers;
646 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 741 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
647 &finish_profiler, NULL); 742 &finish_profiler, NULL);
648 disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME, 743 disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
@@ -652,6 +747,7 @@ tmain (void *cls,
652 &shutdown_task, NULL); 747 &shutdown_task, NULL);
653 for (i = 0; i < TOTAL_PEERS; i++) 748 for (i = 0; i < TOTAL_PEERS; i++)
654 { 749 {
750 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "requesting id %ld\n", i);
655 peers[i].mesh = meshes[i]; 751 peers[i].mesh = meshes[i];
656 peers[i].op = 752 peers[i].op =
657 GNUNET_TESTBED_peer_get_information (testbed_handles[i], 753 GNUNET_TESTBED_peer_get_information (testbed_handles[i],
@@ -695,5 +791,5 @@ main (int argc, char *argv[])
695 return 0; 791 return 0;
696} 792}
697 793
698/* end of test_mesh_small.c */ 794/* end of gnunet-mesh-profiler.c */
699 795