diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-04-02 14:46:10 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-04-02 14:46:10 +0000 |
commit | 095dacf18578d089d59ddd67d6c60fb01bda8715 (patch) | |
tree | 3f2b68b849cc2a4cd2dcbf8d2de7324bc22de61b /src/transport/gnunet-transport.c | |
parent | 7731dd1ec8f3c9618d4e2cc8c2f31a4c942a7bf7 (diff) | |
download | gnunet-095dacf18578d089d59ddd67d6c60fb01bda8715.tar.gz gnunet-095dacf18578d089d59ddd67d6c60fb01bda8715.zip |
- "fixing" mantis 0002211
Diffstat (limited to 'src/transport/gnunet-transport.c')
-rw-r--r-- | src/transport/gnunet-transport.c | 43 |
1 files changed, 36 insertions, 7 deletions
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c index c40eb4de6..6ef273c45 100644 --- a/src/transport/gnunet-transport.c +++ b/src/transport/gnunet-transport.c | |||
@@ -40,6 +40,7 @@ | |||
40 | * Should match NAT_SERVER_TIMEOUT in 'nat_test.c'. | 40 | * Should match NAT_SERVER_TIMEOUT in 'nat_test.c'. |
41 | */ | 41 | */ |
42 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | 42 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) |
43 | #define RESOLUTION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | ||
43 | 44 | ||
44 | /** | 45 | /** |
45 | * Which peer should we connect to? | 46 | * Which peer should we connect to? |
@@ -122,6 +123,8 @@ static struct GNUNET_PeerIdentity pid; | |||
122 | */ | 123 | */ |
123 | static GNUNET_SCHEDULER_TaskIdentifier end; | 124 | static GNUNET_SCHEDULER_TaskIdentifier end; |
124 | 125 | ||
126 | static struct GNUNET_CONTAINER_MultiHashMap *peers; | ||
127 | |||
125 | /** | 128 | /** |
126 | * Selected level of verbosity. | 129 | * Selected level of verbosity. |
127 | */ | 130 | */ |
@@ -444,19 +447,31 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
444 | traffic_received += ntohs (message->size); | 447 | traffic_received += ntohs (message->size); |
445 | } | 448 | } |
446 | 449 | ||
450 | struct ResolutionContext | ||
451 | { | ||
452 | struct GNUNET_HELLO_Address *addrcp; | ||
453 | |||
454 | int printed; | ||
455 | }; | ||
456 | |||
447 | void | 457 | void |
448 | process_string (void *cls, const char *address) | 458 | process_string (void *cls, const char *address) |
449 | { | 459 | { |
450 | struct GNUNET_HELLO_Address *addrcp = cls; | 460 | struct ResolutionContext *rc = cls; |
461 | struct GNUNET_HELLO_Address *addrcp = rc->addrcp; | ||
451 | 462 | ||
452 | if ((address != NULL)) | 463 | if (address != NULL) |
453 | { | 464 | { |
454 | FPRINTF (stdout, _("Peer `%s': %s %s\n"), GNUNET_i2s (&addrcp->peer), addrcp->transport_name, address); | 465 | FPRINTF (stdout, _("Peer `%s': %s %s\n"), GNUNET_i2s (&addrcp->peer), addrcp->transport_name, address); |
466 | rc->printed = GNUNET_YES; | ||
455 | } | 467 | } |
456 | else | 468 | else |
457 | { | 469 | { |
458 | /* done */ | 470 | /* done */ |
459 | GNUNET_free (addrcp); | 471 | if (GNUNET_NO == rc->printed) |
472 | FPRINTF (stdout, _("Peer `%s': %s <unable to resolve address>\n"), GNUNET_i2s (&addrcp->peer), addrcp->transport_name); | ||
473 | GNUNET_free (rc->addrcp); | ||
474 | GNUNET_free (rc); | ||
460 | } | 475 | } |
461 | } | 476 | } |
462 | 477 | ||
@@ -472,6 +487,7 @@ process_address (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
472 | const struct GNUNET_HELLO_Address *address) | 487 | const struct GNUNET_HELLO_Address *address) |
473 | { | 488 | { |
474 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 489 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
490 | struct ResolutionContext *rc; | ||
475 | 491 | ||
476 | if (peer == NULL) | 492 | if (peer == NULL) |
477 | { | 493 | { |
@@ -485,10 +501,16 @@ process_address (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
485 | return; | 501 | return; |
486 | } | 502 | } |
487 | 503 | ||
504 | rc = GNUNET_malloc(sizeof (struct ResolutionContext)); | ||
505 | rc->addrcp = GNUNET_HELLO_address_copy(address); | ||
506 | rc->printed = GNUNET_NO; | ||
507 | |||
508 | GNUNET_assert (NULL != rc); | ||
509 | |||
488 | /* Resolve address to string */ | 510 | /* Resolve address to string */ |
489 | GNUNET_TRANSPORT_address_to_string (cfg, address, numeric, | 511 | GNUNET_TRANSPORT_address_to_string (cfg, address, numeric, |
490 | GNUNET_TIME_UNIT_MINUTES, &process_string, | 512 | RESOLUTION_TIMEOUT, &process_string, |
491 | GNUNET_HELLO_address_copy(address)); | 513 | rc); |
492 | } | 514 | } |
493 | 515 | ||
494 | 516 | ||
@@ -505,7 +527,13 @@ shutdown_task (void *cls, | |||
505 | { | 527 | { |
506 | struct GNUNET_TRANSPORT_PeerIterateContext *pic = cls; | 528 | struct GNUNET_TRANSPORT_PeerIterateContext *pic = cls; |
507 | 529 | ||
508 | GNUNET_TRANSPORT_peer_get_active_addresses_cancel (pic); | 530 | GNUNET_TRANSPORT_peer_get_active_addresses_cancel (pic); |
531 | |||
532 | if (NULL != peers) | ||
533 | { | ||
534 | GNUNET_CONTAINER_multihashmap_destroy (peers); | ||
535 | peers = NULL; | ||
536 | } | ||
509 | } | 537 | } |
510 | 538 | ||
511 | 539 | ||
@@ -562,8 +590,9 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
562 | } | 590 | } |
563 | if (iterate_connections) | 591 | if (iterate_connections) |
564 | { | 592 | { |
593 | peers = GNUNET_CONTAINER_multihashmap_create (20); | ||
565 | GNUNET_TRANSPORT_peer_get_active_addresses (cfg, NULL, GNUNET_YES, | 594 | GNUNET_TRANSPORT_peer_get_active_addresses (cfg, NULL, GNUNET_YES, |
566 | GNUNET_TIME_UNIT_MINUTES, | 595 | TIMEOUT, |
567 | &process_address, (void *) cfg); | 596 | &process_address, (void *) cfg); |
568 | } | 597 | } |
569 | if (monitor_connections) | 598 | if (monitor_connections) |