aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-11-29 20:03:12 +0000
committerChristian Grothoff <christian@grothoff.org>2011-11-29 20:03:12 +0000
commit75bbeaffe2a1467b6f9f4d80bc4d87ed0d9f14a8 (patch)
tree63885d0e8e55d47ecae25cef37181597115c8980 /src/transport
parent56c32ea37a52b239494a7f91933e60eb7caf30f3 (diff)
downloadgnunet-75bbeaffe2a1467b6f9f4d80bc4d87ed0d9f14a8.tar.gz
gnunet-75bbeaffe2a1467b6f9f4d80bc4d87ed0d9f14a8.zip
-cleaning up message format and code related to recent transport address stringification code
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/gnunet-service-transport_clients.c175
-rw-r--r--src/transport/gnunet-transport.c28
-rw-r--r--src/transport/transport.h22
-rw-r--r--src/transport/transport_api_address_lookup.c98
-rw-r--r--src/transport/transport_api_address_to_string.c15
5 files changed, 116 insertions, 222 deletions
diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c
index d787c7aab..2aea7aa7e 100644
--- a/src/transport/gnunet-service-transport_clients.c
+++ b/src/transport/gnunet-service-transport_clients.c
@@ -612,6 +612,7 @@ static void
612transmit_address_to_client (void *cls, const char *buf) 612transmit_address_to_client (void *cls, const char *buf)
613{ 613{
614 struct GNUNET_SERVER_TransmitContext *tc = cls; 614 struct GNUNET_SERVER_TransmitContext *tc = cls;
615
615 if (NULL == buf) 616 if (NULL == buf)
616 { 617 {
617 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, 618 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
@@ -625,31 +626,6 @@ transmit_address_to_client (void *cls, const char *buf)
625 626
626 627
627/** 628/**
628 * Take the given address and append it to the set of results sent back to
629 * the client.
630 *
631 * @param cls the transmission context used ('struct GNUNET_SERVER_TransmitContext*')
632 * @param buf data to transmit
633 * @param size number of bytes in buf
634 */
635static void
636transmit_binary_to_client (void *cls, void *buf, size_t size)
637{
638 struct GNUNET_SERVER_TransmitContext *tc = cls;
639
640 if (NULL == buf)
641 {
642 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
643 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE);
644 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
645 return;
646 }
647 GNUNET_SERVER_transmit_context_append_data (tc, buf, size,
648 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE);
649}
650
651
652/**
653 * Client asked to resolve an address. Process the request. 629 * Client asked to resolve an address. Process the request.
654 * 630 *
655 * @param cls unused 631 * @param cls unused
@@ -658,7 +634,7 @@ transmit_binary_to_client (void *cls, void *buf, size_t size)
658 */ 634 */
659static void 635static void
660clients_handle_address_to_string (void *cls, struct GNUNET_SERVER_Client *client, 636clients_handle_address_to_string (void *cls, struct GNUNET_SERVER_Client *client,
661 const struct GNUNET_MessageHeader *message) 637 const struct GNUNET_MessageHeader *message)
662{ 638{
663 const struct AddressLookupMessage *alum; 639 const struct AddressLookupMessage *alum;
664 struct GNUNET_TRANSPORT_PluginFunctions *papi; 640 struct GNUNET_TRANSPORT_PluginFunctions *papi;
@@ -678,7 +654,7 @@ clients_handle_address_to_string (void *cls, struct GNUNET_SERVER_Client *client
678 return; 654 return;
679 } 655 }
680 alum = (const struct AddressLookupMessage *) message; 656 alum = (const struct AddressLookupMessage *) message;
681 address_len = ntohl (alum->addrlen); 657 address_len = ntohs (alum->addrlen);
682 if (size <= sizeof (struct AddressLookupMessage) + address_len) 658 if (size <= sizeof (struct AddressLookupMessage) + address_len)
683 { 659 {
684 GNUNET_break (0); 660 GNUNET_break (0);
@@ -695,7 +671,7 @@ clients_handle_address_to_string (void *cls, struct GNUNET_SERVER_Client *client
695 return; 671 return;
696 } 672 }
697 rtimeout = GNUNET_TIME_relative_ntoh (alum->timeout); 673 rtimeout = GNUNET_TIME_relative_ntoh (alum->timeout);
698 numeric = ntohl (alum->numeric_only); 674 numeric = ntohs (alum->numeric_only);
699 tc = GNUNET_SERVER_transmit_context_create (client); 675 tc = GNUNET_SERVER_transmit_context_create (client);
700 papi = GST_plugins_find (plugin_name); 676 papi = GST_plugins_find (plugin_name);
701 if (NULL == papi) 677 if (NULL == papi)
@@ -711,73 +687,6 @@ clients_handle_address_to_string (void *cls, struct GNUNET_SERVER_Client *client
711 tc); 687 tc);
712} 688}
713 689
714#if 0
715
716THIS FUNCTIONALITY IS NOT USED ANYWHERE!
717
718/**
719 * Send an address to the client.
720 *
721 * @param cls our 'struct GNUNET_SERVER_TransmitContext' (for sending)
722 * @param public_key public key for the peer, never NULL
723 * @param valid_until until what time do we consider the address valid?
724 * @param validation_block is FOREVER if the address is for an unsupported plugin (from PEERINFO)
725 * is ZERO if the address is considered valid (no validation needed)
726 * is a time in the future if we're currently denying re-validation
727 * @param address address to transmit
728 */
729static void
730send_address_to_client (void *cls,
731 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
732 *public_key,
733 struct GNUNET_TIME_Absolute valid_until,
734 struct GNUNET_TIME_Absolute validation_block,
735 const struct GNUNET_HELLO_Address *address)
736{
737 struct GNUNET_SERVER_TransmitContext *tc = cls;
738 char *addr_buf;
739
740 /* FIXME: move to a binary format!!! */
741 GNUNET_asprintf (&addr_buf, "%s --- %s, %s",
742 GST_plugins_a2s (address),
743 (GNUNET_YES ==
744 GST_neighbours_test_connected (&address->peer)) ? "CONNECTED" :
745 "DISCONNECTED",
746 (GNUNET_TIME_absolute_get_remaining (valid_until).rel_value >
747 0) ? "VALIDATED" : "UNVALIDATED");
748 transmit_address_to_client (tc, addr_buf);
749 GNUNET_free (addr_buf);
750}
751
752
753/**
754 * Client asked to obtain information about all addresses of a peer.
755 * Process the request.
756 *
757 * @param cls unused
758 * @param client the client
759 * @param message the peer address information request
760 */
761static void
762clients_handle_peer_address_iterate (void *cls,
763 struct GNUNET_SERVER_Client *client,
764 const struct GNUNET_MessageHeader *message)
765{
766 const struct PeerAddressLookupMessage *peer_address_lookup;
767 struct GNUNET_SERVER_TransmitContext *tc;
768
769 peer_address_lookup = (const struct PeerAddressLookupMessage *) message;
770 GNUNET_break (ntohl (peer_address_lookup->reserved) == 0);
771 tc = GNUNET_SERVER_transmit_context_create (client);
772
773 GST_validation_get_addresses (&peer_address_lookup->peer,
774 &send_address_to_client, tc);
775
776 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
777 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE);
778 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
779}
780#endif
781 690
782/** 691/**
783 * Output the active address of connected neighbours to the given client. 692 * Output the active address of connected neighbours to the given client.
@@ -789,9 +698,9 @@ clients_handle_peer_address_iterate (void *cls,
789 * @param address the address 698 * @param address the address
790 */ 699 */
791static void 700static void
792output_addresses (void *cls, const struct GNUNET_PeerIdentity *peer, 701output_address (void *cls, const struct GNUNET_PeerIdentity *peer,
793 const struct GNUNET_ATS_Information *ats, uint32_t ats_count, 702 const struct GNUNET_ATS_Information *ats, uint32_t ats_count,
794 const struct GNUNET_HELLO_Address *address) 703 const struct GNUNET_HELLO_Address *address)
795{ 704{
796 struct GNUNET_SERVER_TransmitContext *tc = cls; 705 struct GNUNET_SERVER_TransmitContext *tc = cls;
797 struct AddressIterateResponseMessage *msg; 706 struct AddressIterateResponseMessage *msg;
@@ -802,19 +711,23 @@ output_addresses (void *cls, const struct GNUNET_PeerIdentity *peer,
802 711
803 tlen = strlen (address->transport_name) + 1; 712 tlen = strlen (address->transport_name) + 1;
804 alen = address->address_length; 713 alen = address->address_length;
805
806 size = (sizeof (struct AddressIterateResponseMessage) + alen + tlen); 714 size = (sizeof (struct AddressIterateResponseMessage) + alen + tlen);
807 msg = GNUNET_malloc (size); 715 {
808 msg->addrlen = htonl (alen); 716 char buf[size];
809 msg->pluginlen = htonl (tlen); 717
810 msg->peer = *peer; 718 msg = (struct AddressIterateResponseMessage*) buf;
811 719 msg->reserved = htonl (0);
812 addr = (char *) &msg[1]; 720 msg->peer = *peer;
813 memcpy(addr,address->address, alen); 721 msg->addrlen = htonl (alen);
814 memcpy(&addr[alen], address->transport_name, tlen); 722 msg->pluginlen = htonl (tlen);
815 723 addr = (char *) &msg[1];
816 transmit_binary_to_client (tc, msg, size); 724 memcpy (addr,address->address, alen);
817 GNUNET_free (msg); 725 memcpy (&addr[alen], address->transport_name, tlen);
726 GNUNET_SERVER_transmit_context_append_data (tc,
727 &buf[sizeof(struct GNUNET_MessageHeader)],
728 size - sizeof (struct GNUNET_MessageHeader),
729 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE);
730 }
818} 731}
819 732
820 733
@@ -831,44 +744,47 @@ static void
831clients_handle_address_iterate (void *cls, struct GNUNET_SERVER_Client *client, 744clients_handle_address_iterate (void *cls, struct GNUNET_SERVER_Client *client,
832 const struct GNUNET_MessageHeader *message) 745 const struct GNUNET_MessageHeader *message)
833{ 746{
747 static struct GNUNET_PeerIdentity all_zeros;
834 struct GNUNET_SERVER_TransmitContext *tc; 748 struct GNUNET_SERVER_TransmitContext *tc;
835 struct AddressIterateMessage * msg; 749 struct AddressIterateMessage * msg;
836 struct GNUNET_PeerIdentity dummy; 750 struct GNUNET_HELLO_Address *address;
837 struct GNUNET_HELLO_Address * address;
838
839
840 GNUNET_SERVER_disable_receive_done_warning (client);
841 tc = GNUNET_SERVER_transmit_context_create (client);
842 751
843 if (ntohs (message->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE) 752 if (ntohs (message->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE)
844 { 753 {
845 GNUNET_break_op(0); 754 GNUNET_break (0);
755 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
846 return; 756 return;
847 } 757 }
848 if (ntohs (message->size) != sizeof (struct AddressIterateMessage)) 758 if (ntohs (message->size) != sizeof (struct AddressIterateMessage))
849 { 759 {
850 GNUNET_break_op(0); 760 GNUNET_break (0);
761 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
851 return; 762 return;
852 } 763 }
853
854 msg = (struct AddressIterateMessage *) message; 764 msg = (struct AddressIterateMessage *) message;
855 memset (&dummy, 0, sizeof (struct GNUNET_PeerIdentity)); 765 if (GNUNET_YES != ntohl (msg->one_shot))
856 766 {
857 if (0 == memcmp (&msg->peer, &dummy, sizeof (struct GNUNET_PeerIdentity))) 767 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
768 "Address monitoring not implemented\n");
769 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
770 return;
771 }
772 GNUNET_SERVER_disable_receive_done_warning (client);
773 tc = GNUNET_SERVER_transmit_context_create (client);
774 if (0 == memcmp (&msg->peer, &all_zeros, sizeof (struct GNUNET_PeerIdentity)))
858 { 775 {
859 /* iterate over all neighbours */ 776 /* iterate over all neighbours */
860 GST_neighbours_iterate (&output_addresses, tc); 777 GST_neighbours_iterate (&output_address, tc);
861 } 778 }
862 else 779 else
863 { 780 {
864 /* just return one neighbour */ 781 /* just return one neighbour */
865 address = GST_neighbour_get_current_address(&msg->peer); 782 address = GST_neighbour_get_current_address(&msg->peer);
866 if (address != NULL) 783 if (address != NULL)
867 output_addresses(tc, &msg->peer, NULL, 0, address); 784 output_address (tc, &msg->peer, NULL, 0, address);
868 } 785 }
869
870 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, 786 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
871 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE); 787 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE);
872 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); 788 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
873} 789}
874 790
@@ -891,15 +807,8 @@ GST_clients_start (struct GNUNET_SERVER_Handle *server)
891 {&clients_handle_request_connect, NULL, 807 {&clients_handle_request_connect, NULL,
892 GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT, 808 GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT,
893 sizeof (struct TransportRequestConnectMessage)}, 809 sizeof (struct TransportRequestConnectMessage)},
894 /* converts a binary address to a human readable address */
895 {&clients_handle_address_to_string, NULL, 810 {&clients_handle_address_to_string, NULL,
896 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING, 0}, 811 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING, 0},
897#if 0
898 /* Not used at the moment, gets all addresses of a peer */
899 {&clients_handle_peer_address_iterate, NULL,
900 GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP,
901 sizeof (struct PeerAddressLookupMessage)},
902#endif
903 {&clients_handle_address_iterate, NULL, 812 {&clients_handle_address_iterate, NULL,
904 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE, 813 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE,
905 sizeof (struct AddressIterateMessage)}, 814 sizeof (struct AddressIterateMessage)},
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c
index 9097311a6..66f02b104 100644
--- a/src/transport/gnunet-transport.c
+++ b/src/transport/gnunet-transport.c
@@ -444,7 +444,7 @@ void process_string (void *cls,
444 444
445 if ((address != NULL)) 445 if ((address != NULL))
446 { 446 {
447 fprintf (stdout, _("Peer `%s' : %s\n"), GNUNET_i2s(peer), address); 447 fprintf (stdout, _("Peer `%s': %s\n"), GNUNET_i2s(peer), address);
448 } 448 }
449 else 449 else
450 { 450 {
@@ -463,26 +463,29 @@ void process_string (void *cls,
463 * @param addrlen number of bytes in addr 463 * @param addrlen number of bytes in addr
464 */ 464 */
465static void 465static void
466process_address (void *cls, const struct GNUNET_HELLO_Address *address) 466process_address (void *cls,
467 const struct GNUNET_PeerIdentity *peer,
468 const struct GNUNET_HELLO_Address *address)
467{ 469{
468 const struct GNUNET_CONFIGURATION_Handle * cfg = cls; 470 const struct GNUNET_CONFIGURATION_Handle * cfg = cls;
471 struct GNUNET_PeerIdentity *peercp;
469 472
470 if (address == NULL) 473 if ( (address == NULL) || (peer == NULL) )
471 { 474 {
472 /* done */ 475 /* done */
473 return; 476 return;
474 } 477 }
475 478
476 struct GNUNET_PeerIdentity * peer = GNUNET_malloc(sizeof (struct GNUNET_PeerIdentity)); 479 peercp = GNUNET_malloc(sizeof (struct GNUNET_PeerIdentity));
477 *peer = address->peer; 480 *peercp = *peer;
478 481
479 /* Resolve address to string */ 482 /* Resolve address to string */
480 GNUNET_TRANSPORT_address_to_string (cfg, 483 GNUNET_TRANSPORT_address_to_string (cfg,
481 address, 484 address,
482 numeric, 485 numeric,
483 GNUNET_TIME_UNIT_MINUTES, 486 GNUNET_TIME_UNIT_MINUTES,
484 &process_string, 487 &process_string,
485 peer); 488 peercp);
486} 489}
487 490
488 491
@@ -538,8 +541,9 @@ run (void *cls, char *const *args, const char *cfgfile,
538 } 541 }
539 if (iterate_connections) 542 if (iterate_connections)
540 { 543 {
541 GNUNET_TRANSPORT_address_iterate (cfg, GNUNET_TIME_UNIT_MINUTES, 544 GNUNET_TRANSPORT_peer_get_active_addresses (cfg, NULL, GNUNET_YES,
542 &process_address, (void *)cfg); 545 GNUNET_TIME_UNIT_MINUTES,
546 &process_address, (void *)cfg);
543 } 547 }
544} 548}
545 549
diff --git a/src/transport/transport.h b/src/transport/transport.h
index 97620a9b6..bfcf9fe6e 100644
--- a/src/transport/transport.h
+++ b/src/transport/transport.h
@@ -295,17 +295,17 @@ struct AddressLookupMessage
295 * Should the conversion use numeric IP addresses (otherwise 295 * Should the conversion use numeric IP addresses (otherwise
296 * a reverse DNS lookup is OK -- if applicable). 296 * a reverse DNS lookup is OK -- if applicable).
297 */ 297 */
298 int32_t numeric_only GNUNET_PACKED; 298 int16_t numeric_only GNUNET_PACKED;
299 299
300 /** 300 /**
301 * timeout to give up. 301 * Length of the (binary) address in bytes, in big-endian.
302 */ 302 */
303 struct GNUNET_TIME_RelativeNBO timeout; 303 uint16_t addrlen GNUNET_PACKED;
304 304
305 /** 305 /**
306 * Length of the (binary) address in bytes, in big-endian. 306 * timeout to give up.
307 */ 307 */
308 uint32_t addrlen GNUNET_PACKED; 308 struct GNUNET_TIME_RelativeNBO timeout;
309 309
310 /* followed by 'addrlen' bytes of the actual address, then 310 /* followed by 'addrlen' bytes of the actual address, then
311 * followed by the 0-terminated name of the transport */ 311 * followed by the 0-terminated name of the transport */
@@ -352,9 +352,9 @@ struct AddressIterateMessage
352 struct GNUNET_MessageHeader header; 352 struct GNUNET_MessageHeader header;
353 353
354 /** 354 /**
355 * For alignment. 355 * One shot call or continous replies?
356 */ 356 */
357 uint32_t reserved; 357 uint32_t one_shot;
358 358
359 /** 359 /**
360 * timeout to give up. FIXME: remove in the future 360 * timeout to give up. FIXME: remove in the future
@@ -366,13 +366,9 @@ struct AddressIterateMessage
366 */ 366 */
367 struct GNUNET_PeerIdentity peer; 367 struct GNUNET_PeerIdentity peer;
368 368
369 /**
370 * One shot call or continous replies?
371 */
372 uint32_t one_shot;
373
374}; 369};
375 370
371
376/** 372/**
377 * Message from the transport service to the library 373 * Message from the transport service to the library
378 * containing binary addresses known for a peer. 374 * containing binary addresses known for a peer.
@@ -382,7 +378,7 @@ struct AddressIterateMessage
382struct AddressIterateResponseMessage 378struct AddressIterateResponseMessage
383{ 379{
384 /** 380 /**
385 * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY 381 * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE
386 */ 382 */
387 struct GNUNET_MessageHeader header; 383 struct GNUNET_MessageHeader header;
388 384
diff --git a/src/transport/transport_api_address_lookup.c b/src/transport/transport_api_address_lookup.c
index 489ba8a5a..7cd61e896 100644
--- a/src/transport/transport_api_address_lookup.c
+++ b/src/transport/transport_api_address_lookup.c
@@ -65,6 +65,7 @@ struct GNUNET_TRANSPORT_PeerIterateContext
65 struct GNUNET_TIME_Absolute timeout; 65 struct GNUNET_TIME_Absolute timeout;
66}; 66};
67 67
68
68/** 69/**
69 * Function called with responses from the service. 70 * Function called with responses from the service.
70 * 71 *
@@ -79,13 +80,16 @@ peer_address_response_processor (void *cls,
79 struct GNUNET_TRANSPORT_PeerIterateContext *pal_ctx = cls; 80 struct GNUNET_TRANSPORT_PeerIterateContext *pal_ctx = cls;
80 struct AddressIterateResponseMessage *air_msg; 81 struct AddressIterateResponseMessage *air_msg;
81 struct GNUNET_HELLO_Address *address; 82 struct GNUNET_HELLO_Address *address;
83 const char *addr;
84 const char *transport_name;
82 uint16_t size; 85 uint16_t size;
86 size_t alen;
87 size_t tlen;
83 88
84 if (msg == NULL) 89 if (msg == NULL)
85 { 90 {
86 pal_ctx->cb (pal_ctx->cb_cls, NULL); 91 pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL);
87 GNUNET_CLIENT_disconnect (pal_ctx->client, GNUNET_NO); 92 GNUNET_TRANSPORT_peer_get_active_addresses_cancel (pal_ctx);
88 GNUNET_free (pal_ctx);
89 return; 93 return;
90 } 94 }
91 size = ntohs (msg->size); 95 size = ntohs (msg->size);
@@ -93,54 +97,53 @@ peer_address_response_processor (void *cls,
93 if (size == sizeof (struct GNUNET_MessageHeader)) 97 if (size == sizeof (struct GNUNET_MessageHeader))
94 { 98 {
95 /* done! */ 99 /* done! */
96 pal_ctx->cb (pal_ctx->cb_cls, NULL ); 100 pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL);
97 GNUNET_CLIENT_disconnect (pal_ctx->client, GNUNET_NO); 101 GNUNET_TRANSPORT_peer_get_active_addresses_cancel (pal_ctx);
98 GNUNET_free (pal_ctx);
99 return; 102 return;
100 } 103 }
101 104
102 if (size < sizeof (struct GNUNET_MessageHeader) + sizeof (struct AddressIterateResponseMessage)) 105 if ( (size < sizeof (struct GNUNET_MessageHeader) + sizeof (struct AddressIterateResponseMessage)) ||
106 (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE) )
103 { 107 {
104 GNUNET_break_op (0); 108 GNUNET_break (0);
105 pal_ctx->cb (pal_ctx->cb_cls, NULL ); 109 pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL);
106 GNUNET_CLIENT_disconnect (pal_ctx->client, GNUNET_NO); 110 GNUNET_TRANSPORT_peer_get_active_addresses_cancel (pal_ctx);
107 GNUNET_free (pal_ctx);
108 return; 111 return;
109 } 112 }
110 113
111 air_msg = (struct AddressIterateResponseMessage *) &msg[1]; 114 air_msg = (struct AddressIterateResponseMessage *) msg;
112 size_t tlen = ntohl(air_msg->pluginlen); 115 tlen = ntohl(air_msg->pluginlen);
113 size_t alen = ntohl(air_msg->addrlen); 116 alen = ntohl(air_msg->addrlen);
114 117
115 if (size != sizeof (struct GNUNET_MessageHeader) + sizeof (struct AddressIterateResponseMessage) + tlen + alen) 118 if (size != sizeof (struct AddressIterateResponseMessage) + tlen + alen)
116 { 119 {
117 GNUNET_break_op (0); 120 GNUNET_break (0);
118 pal_ctx->cb (pal_ctx->cb_cls, NULL ); 121 pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL);
119 GNUNET_CLIENT_disconnect (pal_ctx->client, GNUNET_NO); 122 GNUNET_TRANSPORT_peer_get_active_addresses_cancel (pal_ctx);
120 GNUNET_free (pal_ctx);
121 return; 123 return;
122 } 124 }
123 125
124 char * addr = (char *) &air_msg[1]; 126 addr = (const char *) &air_msg[1];
125 char * transport_name = &addr[alen]; 127 transport_name = &addr[alen];
126 128
127 if (transport_name[tlen-1] != '\0') 129 if (transport_name[tlen-1] != '\0')
128 { 130 {
129 GNUNET_break_op (0); 131 GNUNET_break_op (0);
130 pal_ctx->cb (pal_ctx->cb_cls, NULL ); 132 pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL);
131 GNUNET_CLIENT_disconnect (pal_ctx->client, GNUNET_NO); 133 GNUNET_TRANSPORT_peer_get_active_addresses_cancel (pal_ctx);
132 GNUNET_free (pal_ctx);
133 return; 134 return;
134 } 135 }
135 136
136 address = GNUNET_HELLO_address_allocate(&air_msg->peer, transport_name, addr, alen);
137
138 /* expect more replies */ 137 /* expect more replies */
139 GNUNET_CLIENT_receive (pal_ctx->client, &peer_address_response_processor, pal_ctx, 138 GNUNET_CLIENT_receive (pal_ctx->client,
139 &peer_address_response_processor, pal_ctx,
140 GNUNET_TIME_absolute_get_remaining (pal_ctx->timeout)); 140 GNUNET_TIME_absolute_get_remaining (pal_ctx->timeout));
141 141
142 pal_ctx->cb (pal_ctx->cb_cls, address); 142 /* notify client */
143 GNUNET_free (address); 143 address = GNUNET_HELLO_address_allocate (&air_msg->peer,
144 transport_name, addr, alen);
145 pal_ctx->cb (pal_ctx->cb_cls, &air_msg->peer, address);
146 GNUNET_HELLO_address_free (address);
144} 147}
145 148
146 149
@@ -174,23 +177,24 @@ GNUNET_TRANSPORT_peer_get_active_addresses (const struct GNUNET_CONFIGURATION_Ha
174 struct GNUNET_CLIENT_Connection *client; 177 struct GNUNET_CLIENT_Connection *client;
175 struct GNUNET_TIME_Absolute abs_timeout; 178 struct GNUNET_TIME_Absolute abs_timeout;
176 179
177 client = GNUNET_CLIENT_connect ("transport", cfg); 180 if (GNUNET_YES != one_shot)
178 if (client == NULL)
179 { 181 {
180 peer_address_callback (peer_address_callback_cls, NULL); 182 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
183 "Address monitoring not implemented\n");
181 return NULL; 184 return NULL;
182 } 185 }
183 186 client = GNUNET_CLIENT_connect ("transport", cfg);
187 if (client == NULL)
188 return NULL;
184 abs_timeout = GNUNET_TIME_relative_to_absolute (timeout); 189 abs_timeout = GNUNET_TIME_relative_to_absolute (timeout);
185
186 msg.header.size = htons (sizeof (struct AddressIterateMessage)); 190 msg.header.size = htons (sizeof (struct AddressIterateMessage));
187 msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE); 191 msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE);
192 msg.one_shot = htonl (one_shot);
188 msg.timeout = GNUNET_TIME_absolute_hton (abs_timeout); 193 msg.timeout = GNUNET_TIME_absolute_hton (abs_timeout);
189 if (peer == NULL) 194 if (peer == NULL)
190 memset (&msg.peer, 0 , sizeof (struct GNUNET_PeerIdentity)); 195 memset (&msg.peer, 0 , sizeof (struct GNUNET_PeerIdentity));
191 else 196 else
192 memcpy (&msg.peer, peer , sizeof (struct GNUNET_PeerIdentity)); 197 msg.peer = *peer;
193
194 pal_ctx = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PeerIterateContext)); 198 pal_ctx = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PeerIterateContext));
195 pal_ctx->cb = peer_address_callback; 199 pal_ctx->cb = peer_address_callback;
196 pal_ctx->cb_cls = peer_address_callback_cls; 200 pal_ctx->cb_cls = peer_address_callback_cls;
@@ -219,27 +223,5 @@ GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct
219 GNUNET_free (alc); 223 GNUNET_free (alc);
220} 224}
221 225
222/**
223 * Return all addresses for all peers.
224 *
225 * @param cfg configuration to use
226 * @param timeout how long is the lookup allowed to take at most
227 * @param peer_address_callback function to call with the results
228 * @param peer_address_callback_cls closure for peer_address_callback
229 */
230void
231GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
232 struct GNUNET_TIME_Relative timeout,
233 GNUNET_TRANSPORT_PeerIterateCallback
234 peer_address_callback,
235 void *peer_address_callback_cls)
236{
237 GNUNET_TRANSPORT_peer_get_active_addresses (cfg,
238 NULL,
239 GNUNET_YES,
240 timeout,
241 peer_address_callback,
242 peer_address_callback_cls);
243}
244 226
245/* end of transport_api_peer_address_lookup.c */ 227/* end of transport_api_peer_address_lookup.c */
diff --git a/src/transport/transport_api_address_to_string.c b/src/transport/transport_api_address_to_string.c
index 87ee9ad83..5c44c288b 100644
--- a/src/transport/transport_api_address_to_string.c
+++ b/src/transport/transport_api_address_to_string.c
@@ -125,13 +125,16 @@ GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cf
125{ 125{
126 size_t len; 126 size_t len;
127 size_t alen; 127 size_t alen;
128 size_t slen;
128 struct AddressLookupMessage *msg; 129 struct AddressLookupMessage *msg;
129 struct GNUNET_TRANSPORT_AddressToStringContext *alc; 130 struct GNUNET_TRANSPORT_AddressToStringContext *alc;
130 struct GNUNET_CLIENT_Connection *client; 131 struct GNUNET_CLIENT_Connection *client;
131 char *addrbuf; 132 char *addrbuf;
132 133
133 GNUNET_assert (address != NULL); 134 GNUNET_assert (address != NULL);
134 len = sizeof (struct AddressLookupMessage) + GNUNET_HELLO_address_get_size (address); 135 alen = address->address_length;
136 slen = strlen (address->transport_name) + 1;
137 len = sizeof (struct AddressLookupMessage) + alen + slen;
135 if (len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 138 if (len >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
136 { 139 {
137 GNUNET_break (0); 140 GNUNET_break (0);
@@ -141,19 +144,19 @@ GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cf
141 client = GNUNET_CLIENT_connect ("transport", cfg); 144 client = GNUNET_CLIENT_connect ("transport", cfg);
142 if (client == NULL) 145 if (client == NULL)
143 return NULL; 146 return NULL;
147#if DEBUG_TRANSPORT
144 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
145 "GNUNET_TRANSPORT_address_to_string\n"); 149 "GNUNET_TRANSPORT_address_to_string\n");
146 150#endif
147 alen = address->address_length;
148 msg = GNUNET_malloc (len); 151 msg = GNUNET_malloc (len);
149 msg->header.size = htons (len); 152 msg->header.size = htons (len);
150 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING); 153 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING);
151 msg->numeric_only = htonl (numeric); 154 msg->numeric_only = htons ((int16_t) numeric);
155 msg->addrlen = htons ((uint16_t) alen);
152 msg->timeout = GNUNET_TIME_relative_hton (timeout); 156 msg->timeout = GNUNET_TIME_relative_hton (timeout);
153 msg->addrlen = htonl (alen);
154 addrbuf = (char *) &msg[1]; 157 addrbuf = (char *) &msg[1];
155 memcpy (addrbuf, address->address, alen); 158 memcpy (addrbuf, address->address, alen);
156 strcpy (&addrbuf[alen], address->transport_name); 159 memcpy (&addrbuf[alen], address->transport_name, slen);
157 160
158 alc = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_AddressToStringContext)); 161 alc = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_AddressToStringContext));
159 alc->cb = aluc; 162 alc->cb = aluc;