aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-transport.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-06-12 09:02:14 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-06-12 09:02:14 +0000
commit661ec1fee1a5066ee6fba67dfae70cc85c288961 (patch)
tree55350501a1103fdd65105ee49f1c9b73d39de2d7 /src/transport/gnunet-transport.c
parentdd42cc68d1030dd1ad4ef39e947ac2e0a8963d4a (diff)
downloadgnunet-661ec1fee1a5066ee6fba67dfae70cc85c288961.tar.gz
gnunet-661ec1fee1a5066ee6fba67dfae70cc85c288961.zip
monitor mode implemented correctly
Diffstat (limited to 'src/transport/gnunet-transport.c')
-rw-r--r--src/transport/gnunet-transport.c95
1 files changed, 76 insertions, 19 deletions
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c
index d07afccea..6bc7a2086 100644
--- a/src/transport/gnunet-transport.c
+++ b/src/transport/gnunet-transport.c
@@ -83,6 +83,11 @@ static int test_configuration;
83static int monitor_connections; 83static int monitor_connections;
84 84
85/** 85/**
86 *
87 */
88static int monitor_connections_counter;
89
90/**
86 * Option -n. 91 * Option -n.
87 */ 92 */
88static int numeric; 93static int numeric;
@@ -412,17 +417,60 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
412{ 417{
413 if (verbosity > 0) 418 if (verbosity > 0)
414 FPRINTF (stdout, _("Disconnected from %s\n"), GNUNET_i2s (peer)); 419 FPRINTF (stdout, _("Disconnected from %s\n"), GNUNET_i2s (peer));
415 if ((0 == memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity))) && 420}
416 (NULL != th)) 421
417 { 422/**
418 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); 423 * Function called to notify transport users that another
419 th = NULL; 424 * peer connected to us.
420 GNUNET_SCHEDULER_cancel (end); 425 *
421 end = GNUNET_SCHEDULER_add_now (&do_disconnect, NULL); 426 * @param cls closure
422 } 427 * @param peer the peer that connected
428 * @param ats performance data
429 * @param ats_count number of entries in ats (excluding 0-termination)
430 */
431static void
432monitor_notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
433 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
434{
435 monitor_connections_counter ++;
436 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get();
437 char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
438 FPRINTF (stdout, _("%24s: %-17s %4s (%u connections in total)\n"),
439 now_str,
440 _("Connected to"),
441 GNUNET_i2s (peer),
442 monitor_connections_counter);
443
444 GNUNET_free (now_str);
445}
446
447
448/**
449 * Function called to notify transport users that another
450 * peer disconnected from us.
451 *
452 * @param cls closure
453 * @param peer the peer that disconnected
454 */
455static void
456monitor_notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
457{
458 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get();
459 char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
460
461 GNUNET_assert (monitor_connections_counter > 0);
462 monitor_connections_counter --;
463
464 FPRINTF (stdout, _("%24s: %-17s %4s (%u connections in total)\n"),
465 now_str,
466 _("Disconnected from"),
467 GNUNET_i2s (peer),
468 monitor_connections_counter);
469 GNUNET_free (now_str);
423} 470}
424 471
425 472
473
426/** 474/**
427 * Function called by the transport for each received message. 475 * Function called by the transport for each received message.
428 * 476 *
@@ -526,9 +574,11 @@ static void
526shutdown_task (void *cls, 574shutdown_task (void *cls,
527 const struct GNUNET_SCHEDULER_TaskContext *tc) 575 const struct GNUNET_SCHEDULER_TaskContext *tc)
528{ 576{
529 struct GNUNET_TRANSPORT_PeerIterateContext *pic = cls; 577 if (NULL != handle)
530 578 {
531 GNUNET_TRANSPORT_peer_get_active_addresses_cancel (pic); 579 GNUNET_TRANSPORT_disconnect(handle);
580 handle = NULL;
581 }
532 582
533 if (NULL != peers) 583 if (NULL != peers)
534 { 584 {
@@ -598,14 +648,21 @@ run (void *cls, char *const *args, const char *cfgfile,
598 } 648 }
599 if (monitor_connections) 649 if (monitor_connections)
600 { 650 {
601 struct GNUNET_TRANSPORT_PeerIterateContext *pic; 651 monitor_connections_counter = 0;
602 652 handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, NULL,
603 pic = GNUNET_TRANSPORT_peer_get_active_addresses (cfg, NULL, GNUNET_NO, 653 &monitor_notify_connect,
604 GNUNET_TIME_UNIT_FOREVER_REL, 654 &monitor_notify_disconnect);
605 &process_address, (void *) cfg); 655 if (NULL == handle)
606 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 656 {
607 &shutdown_task, 657 FPRINTF (stderr, _("Failed to connect to transport service\n"));
608 pic); 658 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
659 }
660 else
661 {
662 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
663 &shutdown_task,
664 NULL);
665 }
609 } 666 }
610} 667}
611 668