aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2011-11-29 18:04:01 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2011-11-29 18:04:01 +0000
commit56c32ea37a52b239494a7f91933e60eb7caf30f3 (patch)
tree5c8c8ef6b577da4931ec3e546b2fb60ed0e8f029
parent5ca85864950a1fe92613f5ed3a69cd08d248423e (diff)
downloadgnunet-56c32ea37a52b239494a7f91933e60eb7caf30f3.tar.gz
gnunet-56c32ea37a52b239494a7f91933e60eb7caf30f3.zip
- finale commit for the api change
-rw-r--r--src/core/gnunet-core-list-connections.c7
-rw-r--r--src/include/gnunet_transport_service.h16
-rw-r--r--src/transport/gnunet-service-transport_clients.c62
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c20
-rw-r--r--src/transport/gnunet-service-transport_neighbours.h10
-rw-r--r--src/transport/gnunet-transport.c43
-rw-r--r--src/transport/transport.conf3
-rw-r--r--src/transport/transport_api_address_lookup.c57
-rw-r--r--src/transport/transport_api_address_to_string.c13
9 files changed, 167 insertions, 64 deletions
diff --git a/src/core/gnunet-core-list-connections.c b/src/core/gnunet-core-list-connections.c
index 8f00c0a18..71c7d40d5 100644
--- a/src/core/gnunet-core-list-connections.c
+++ b/src/core/gnunet-core-list-connections.c
@@ -100,7 +100,7 @@ static void
100process_resolved_address (void *cls, const struct GNUNET_HELLO_Address *address) 100process_resolved_address (void *cls, const struct GNUNET_HELLO_Address *address)
101{ 101{
102 struct PrintContext *pc = cls; 102 struct PrintContext *pc = cls;
103 struct AddressStringList *new_address; 103// struct AddressStringList *new_address;
104 104
105 if (address == NULL) 105 if (address == NULL)
106 { 106 {
@@ -108,14 +108,17 @@ process_resolved_address (void *cls, const struct GNUNET_HELLO_Address *address)
108 return; 108 return;
109 } 109 }
110 110
111 /* This does exactly the same as gnunet-transport -i !*/
112 /*
111 new_address = GNUNET_malloc (sizeof (struct AddressStringList)); 113 new_address = GNUNET_malloc (sizeof (struct AddressStringList));
112#if VERBOSE 114#if VERBOSE
113 fprintf (stderr, "Received address %s\n", address); 115 fprintf (stderr, "Received address %s\n", address);
114#endif 116#endif
115 // FIXME : GNUNET_TRANSPORT_address_to_string 117
116 new_address->address_string = GNUNET_strdup ("FIXME"); 118 new_address->address_string = GNUNET_strdup ("FIXME");
117 GNUNET_CONTAINER_DLL_insert (pc->address_list_head, pc->address_list_tail, 119 GNUNET_CONTAINER_DLL_insert (pc->address_list_head, pc->address_list_tail,
118 new_address); 120 new_address);
121 */
119} 122}
120 123
121 124
diff --git a/src/include/gnunet_transport_service.h b/src/include/gnunet_transport_service.h
index 98436065b..830a061f4 100644
--- a/src/include/gnunet_transport_service.h
+++ b/src/include/gnunet_transport_service.h
@@ -115,7 +115,7 @@ typedef void (*GNUNET_TRANSPORT_AddressToStringCallback) (void *cls,
115 * @param address address 115 * @param address address
116 */ 116 */
117// FIXME: use NULL for address on disconnect IF in monitor mode (one_shot = NO) 117// FIXME: use NULL for address on disconnect IF in monitor mode (one_shot = NO)
118typedef void (*GNUNET_TRANSPORT_AddressLookUpCallback) (void *cls, 118typedef void (*GNUNET_TRANSPORT_PeerIterateCallback) (void *cls,
119 const struct GNUNET_HELLO_Address *address); 119 const struct GNUNET_HELLO_Address *address);
120 120
121 121
@@ -322,12 +322,12 @@ GNUNET_TRANSPORT_address_to_string_cancel (struct
322 * @param peer_address_callback function to call with the results 322 * @param peer_address_callback function to call with the results
323 * @param peer_address_callback_cls closure for peer_address_callback 323 * @param peer_address_callback_cls closure for peer_address_callback
324 */ 324 */
325struct GNUNET_TRANSPORT_PeerAddressLookupContext * 325struct GNUNET_TRANSPORT_PeerIterateContext *
326GNUNET_TRANSPORT_peer_get_active_addresses (const struct GNUNET_CONFIGURATION_Handle *cfg, 326GNUNET_TRANSPORT_peer_get_active_addresses (const struct GNUNET_CONFIGURATION_Handle *cfg,
327 const struct GNUNET_PeerIdentity *peer, 327 const struct GNUNET_PeerIdentity *peer,
328 int one_shot, 328 int one_shot,
329 struct GNUNET_TIME_Relative timeout, 329 struct GNUNET_TIME_Relative timeout,
330 GNUNET_TRANSPORT_AddressLookUpCallback peer_address_callback, 330 GNUNET_TRANSPORT_PeerIterateCallback peer_address_callback,
331 void *peer_address_callback_cls); 331 void *peer_address_callback_cls);
332 332
333 333
@@ -338,16 +338,12 @@ GNUNET_TRANSPORT_peer_get_active_addresses (const struct GNUNET_CONFIGURATION_Ha
338 */ 338 */
339void 339void
340GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct 340GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct
341 GNUNET_TRANSPORT_PeerAddressLookupContext 341 GNUNET_TRANSPORT_PeerIterateContext
342*alc); 342*alc);
343 343
344 344
345/** 345/**
346 * Return all the known addresses. FIXME: document better! 346 * Return all the known addresses.
347 *
348 * FIXME: remove, replace with new 'peer_address_lookup' API
349 *
350 *
351 * @param cfg configuration to use 347 * @param cfg configuration to use
352 * @param timeout how long is the lookup allowed to take at most 348 * @param timeout how long is the lookup allowed to take at most
353 * @param peer_address_callback function to call with the results 349 * @param peer_address_callback function to call with the results
@@ -356,7 +352,7 @@ GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct
356void 352void
357GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, 353GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
358 struct GNUNET_TIME_Relative timeout, 354 struct GNUNET_TIME_Relative timeout,
359 GNUNET_TRANSPORT_AddressLookUpCallback 355 GNUNET_TRANSPORT_PeerIterateCallback
360 peer_address_callback, 356 peer_address_callback,
361 void *peer_address_callback_cls); 357 void *peer_address_callback_cls);
362 358
diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c
index 7c50218e0..d787c7aab 100644
--- a/src/transport/gnunet-service-transport_clients.c
+++ b/src/transport/gnunet-service-transport_clients.c
@@ -612,7 +612,6 @@ 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
616 if (NULL == buf) 615 if (NULL == buf)
617 { 616 {
618 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, 617 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
@@ -712,6 +711,9 @@ clients_handle_address_to_string (void *cls, struct GNUNET_SERVER_Client *client
712 tc); 711 tc);
713} 712}
714 713
714#if 0
715
716THIS FUNCTIONALITY IS NOT USED ANYWHERE!
715 717
716/** 718/**
717 * Send an address to the client. 719 * Send an address to the client.
@@ -749,16 +751,15 @@ send_address_to_client (void *cls,
749 751
750 752
751/** 753/**
752 * Client asked to obtain information about a peer's addresses. 754 * Client asked to obtain information about all addresses of a peer.
753 * Process the request. 755 * Process the request.
754 * FIXME: use better name!
755 * 756 *
756 * @param cls unused 757 * @param cls unused
757 * @param client the client 758 * @param client the client
758 * @param message the peer address information request 759 * @param message the peer address information request
759 */ 760 */
760static void 761static void
761clients_handle_peer_address_lookup (void *cls, 762clients_handle_peer_address_iterate (void *cls,
762 struct GNUNET_SERVER_Client *client, 763 struct GNUNET_SERVER_Client *client,
763 const struct GNUNET_MessageHeader *message) 764 const struct GNUNET_MessageHeader *message)
764{ 765{
@@ -768,13 +769,15 @@ clients_handle_peer_address_lookup (void *cls,
768 peer_address_lookup = (const struct PeerAddressLookupMessage *) message; 769 peer_address_lookup = (const struct PeerAddressLookupMessage *) message;
769 GNUNET_break (ntohl (peer_address_lookup->reserved) == 0); 770 GNUNET_break (ntohl (peer_address_lookup->reserved) == 0);
770 tc = GNUNET_SERVER_transmit_context_create (client); 771 tc = GNUNET_SERVER_transmit_context_create (client);
772
771 GST_validation_get_addresses (&peer_address_lookup->peer, 773 GST_validation_get_addresses (&peer_address_lookup->peer,
772 &send_address_to_client, tc); 774 &send_address_to_client, tc);
775
773 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, 776 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
774 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE); 777 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE);
775 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); 778 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
776} 779}
777 780#endif
778 781
779/** 782/**
780 * Output the active address of connected neighbours to the given client. 783 * Output the active address of connected neighbours to the given client.
@@ -811,15 +814,14 @@ output_addresses (void *cls, const struct GNUNET_PeerIdentity *peer,
811 memcpy(&addr[alen], address->transport_name, tlen); 814 memcpy(&addr[alen], address->transport_name, tlen);
812 815
813 transmit_binary_to_client (tc, msg, size); 816 transmit_binary_to_client (tc, msg, size);
814
815 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "output_addresses: peer `%s' transport %s address %s %s\n",GNUNET_i2s(&msg->peer), &addr[alen], GNUNET_a2s((struct sockaddr *) addr, alen), GNUNET_a2s((struct sockaddr *) address->address, address->address_length));
816 GNUNET_free (msg); 817 GNUNET_free (msg);
817} 818}
818 819
819 820
820/** 821/**
821 * Client asked to obtain information about all actively used addresses. 822 * Client asked to obtain information about all actively used addresses
822 * Process the request. FIXME: use better name! 823 * of connected peers
824 * Process the request.
823 * 825 *
824 * @param cls unused 826 * @param cls unused
825 * @param client the client 827 * @param client the client
@@ -830,11 +832,41 @@ clients_handle_address_iterate (void *cls, struct GNUNET_SERVER_Client *client,
830 const struct GNUNET_MessageHeader *message) 832 const struct GNUNET_MessageHeader *message)
831{ 833{
832 struct GNUNET_SERVER_TransmitContext *tc; 834 struct GNUNET_SERVER_TransmitContext *tc;
835 struct AddressIterateMessage * msg;
836 struct GNUNET_PeerIdentity dummy;
837 struct GNUNET_HELLO_Address * address;
838
833 839
834 GNUNET_SERVER_disable_receive_done_warning (client); 840 GNUNET_SERVER_disable_receive_done_warning (client);
835 tc = GNUNET_SERVER_transmit_context_create (client); 841 tc = GNUNET_SERVER_transmit_context_create (client);
836 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "clients_handle_address_iterate: \n"); 842
837 GST_neighbours_iterate (&output_addresses, tc); 843 if (ntohs (message->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE)
844 {
845 GNUNET_break_op(0);
846 return;
847 }
848 if (ntohs (message->size) != sizeof (struct AddressIterateMessage))
849 {
850 GNUNET_break_op(0);
851 return;
852 }
853
854 msg = (struct AddressIterateMessage *) message;
855 memset (&dummy, 0, sizeof (struct GNUNET_PeerIdentity));
856
857 if (0 == memcmp (&msg->peer, &dummy, sizeof (struct GNUNET_PeerIdentity)))
858 {
859 /* iterate over all neighbours */
860 GST_neighbours_iterate (&output_addresses, tc);
861 }
862 else
863 {
864 /* just return one neighbour */
865 address = GST_neighbour_get_current_address(&msg->peer);
866 if (address != NULL)
867 output_addresses(tc, &msg->peer, NULL, 0, address);
868 }
869
838 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, 870 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
839 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE); 871 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE);
840 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); 872 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
@@ -859,12 +891,16 @@ GST_clients_start (struct GNUNET_SERVER_Handle *server)
859 {&clients_handle_request_connect, NULL, 891 {&clients_handle_request_connect, NULL,
860 GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT, 892 GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT,
861 sizeof (struct TransportRequestConnectMessage)}, 893 sizeof (struct TransportRequestConnectMessage)},
894 /* converts a binary address to a human readable address */
862 {&clients_handle_address_to_string, NULL, 895 {&clients_handle_address_to_string, NULL,
863 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING, 0}, 896 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING, 0},
864 {&clients_handle_peer_address_lookup, NULL, 897#if 0
898 /* Not used at the moment, gets all addresses of a peer */
899 {&clients_handle_peer_address_iterate, NULL,
865 GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP, 900 GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP,
866 sizeof (struct PeerAddressLookupMessage)}, 901 sizeof (struct PeerAddressLookupMessage)},
867 {&clients_handle_address_iterate, NULL, 902#endif
903 {&clients_handle_address_iterate, NULL,
868 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE, 904 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE,
869 sizeof (struct AddressIterateMessage)}, 905 sizeof (struct AddressIterateMessage)},
870 {&GST_blacklist_handle_init, NULL, 906 {&GST_blacklist_handle_init, NULL,
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index 6f1aa7431..3024d8bc1 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -1561,6 +1561,26 @@ GST_neighbour_get_latency (const struct GNUNET_PeerIdentity *peer)
1561 return n->latency; 1561 return n->latency;
1562} 1562}
1563 1563
1564/**
1565 * Obtain current address information for the given neighbour.
1566 *
1567 * @param peer
1568 * @return address currently used
1569 */
1570struct GNUNET_HELLO_Address *
1571GST_neighbour_get_current_address (const struct GNUNET_PeerIdentity *peer)
1572{
1573 struct NeighbourMapEntry *n;
1574
1575 n = lookup_neighbour (peer);
1576 if ( (NULL == n) ||
1577 ( (n->address == NULL) && (n->session == NULL) ) )
1578 return NULL;
1579
1580 return n->address;
1581}
1582
1583
1564 1584
1565/** 1585/**
1566 * Create an entry in the neighbour map for the given peer 1586 * Create an entry in the neighbour map for the given peer
diff --git a/src/transport/gnunet-service-transport_neighbours.h b/src/transport/gnunet-service-transport_neighbours.h
index 31777343d..e85f1a4d0 100644
--- a/src/transport/gnunet-service-transport_neighbours.h
+++ b/src/transport/gnunet-service-transport_neighbours.h
@@ -285,6 +285,16 @@ GST_neighbour_get_latency (const struct GNUNET_PeerIdentity *peer);
285 285
286 286
287/** 287/**
288 * Obtain current address information for the given neighbour.
289 *
290 * @param peer
291 * @return address currently used
292 */
293struct GNUNET_HELLO_Address *
294GST_neighbour_get_current_address (const struct GNUNET_PeerIdentity *peer);
295
296
297/**
288 * We received a disconnect message from the given peer, 298 * We received a disconnect message from the given peer,
289 * validate and process. 299 * validate and process.
290 * 300 *
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c
index 58d20e16d..9097311a6 100644
--- a/src/transport/gnunet-transport.c
+++ b/src/transport/gnunet-transport.c
@@ -76,6 +76,11 @@ static int iterate_connections;
76static int test_configuration; 76static int test_configuration;
77 77
78/** 78/**
79 * Option -n.
80 */
81static int numeric;
82
83/**
79 * Global return value (0 success). 84 * Global return value (0 success).
80 */ 85 */
81static int ret; 86static int ret;
@@ -150,7 +155,6 @@ struct TestContext
150 155
151}; 156};
152 157
153struct GNUNET_CONFIGURATION_Handle * cfg;
154 158
155/** 159/**
156 * Display the result of the test. 160 * Display the result of the test.
@@ -436,7 +440,17 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
436void process_string (void *cls, 440void process_string (void *cls,
437 const char *address) 441 const char *address)
438{ 442{
439 fprintf (stdout, _("process_string\n")); 443 struct GNUNET_PeerIdentity * peer = cls;
444
445 if ((address != NULL))
446 {
447 fprintf (stdout, _("Peer `%s' : %s\n"), GNUNET_i2s(peer), address);
448 }
449 else
450 {
451 /* done */
452 GNUNET_free (peer);
453 }
440} 454}
441 455
442/** 456/**
@@ -451,23 +465,24 @@ void process_string (void *cls,
451static void 465static void
452process_address (void *cls, const struct GNUNET_HELLO_Address *address) 466process_address (void *cls, const struct GNUNET_HELLO_Address *address)
453{ 467{
468 const struct GNUNET_CONFIGURATION_Handle * cfg = cls;
469
454 if (address == NULL) 470 if (address == NULL)
455 { 471 {
472 /* done */
456 return; 473 return;
457 } 474 }
458 475
459 fprintf (stdout, _("Peer `%s'\n"), 476 struct GNUNET_PeerIdentity * peer = GNUNET_malloc(sizeof (struct GNUNET_PeerIdentity));
460 GNUNET_i2s (&address->peer)); 477 *peer = address->peer;
461 478
462 /* Resolve address to string */ 479 /* Resolve address to string */
463 /*
464 GNUNET_TRANSPORT_address_to_string (cfg, 480 GNUNET_TRANSPORT_address_to_string (cfg,
465 address, 481 address,
466 GNUNET_NO, 482 numeric,
467 GNUNET_TIME_UNIT_MINUTES, 483 GNUNET_TIME_UNIT_MINUTES,
468 &process_string, 484 &process_string,
469 NULL); 485 peer);
470 */
471} 486}
472 487
473 488
@@ -483,7 +498,6 @@ static void
483run (void *cls, char *const *args, const char *cfgfile, 498run (void *cls, char *const *args, const char *cfgfile,
484 const struct GNUNET_CONFIGURATION_Handle *cfg) 499 const struct GNUNET_CONFIGURATION_Handle *cfg)
485{ 500{
486 cfg = cfg;
487 if (test_configuration) 501 if (test_configuration)
488 { 502 {
489 do_test_configuration (cfg); 503 do_test_configuration (cfg);
@@ -525,7 +539,7 @@ run (void *cls, char *const *args, const char *cfgfile,
525 if (iterate_connections) 539 if (iterate_connections)
526 { 540 {
527 GNUNET_TRANSPORT_address_iterate (cfg, GNUNET_TIME_UNIT_MINUTES, 541 GNUNET_TRANSPORT_address_iterate (cfg, GNUNET_TIME_UNIT_MINUTES,
528 &process_address, NULL); 542 &process_address, (void *)cfg);
529 } 543 }
530} 544}
531 545
@@ -550,6 +564,9 @@ main (int argc, char *const *argv)
550 {'t', "test", NULL, 564 {'t', "test", NULL,
551 gettext_noop ("test transport configuration (involves external server)"), 565 gettext_noop ("test transport configuration (involves external server)"),
552 0, &GNUNET_GETOPT_set_one, &test_configuration}, 566 0, &GNUNET_GETOPT_set_one, &test_configuration},
567 {'n', "numeric", NULL,
568 gettext_noop ("do not resolve hostnames"),
569 0, &GNUNET_GETOPT_set_one, &numeric},
553 GNUNET_GETOPT_OPTION_VERBOSE (&verbosity), 570 GNUNET_GETOPT_OPTION_VERBOSE (&verbosity),
554 GNUNET_GETOPT_OPTION_END 571 GNUNET_GETOPT_OPTION_END
555 }; 572 };
diff --git a/src/transport/transport.conf b/src/transport/transport.conf
index 7fe3d9532..2aa69268a 100644
--- a/src/transport/transport.conf
+++ b/src/transport/transport.conf
@@ -22,7 +22,8 @@ UNIX_MATCH_GID = YES
22# BINDTO = 22# BINDTO =
23# REJECT_FROM = 23# REJECT_FROM =
24# REJECT_FROM6 = 24# REJECT_FROM6 =
25# PREFIX = 25PREFIX = valgrind --leak-check=full
26
26 27
27[transport-tcp] 28[transport-tcp]
28# Use 0 to ONLY advertise as a peer behind NAT (no port binding) 29# Use 0 to ONLY advertise as a peer behind NAT (no port binding)
diff --git a/src/transport/transport_api_address_lookup.c b/src/transport/transport_api_address_lookup.c
index 5904de5e2..489ba8a5a 100644
--- a/src/transport/transport_api_address_lookup.c
+++ b/src/transport/transport_api_address_lookup.c
@@ -42,12 +42,12 @@
42/** 42/**
43 * Context for the address lookup. 43 * Context for the address lookup.
44 */ 44 */
45struct GNUNET_TRANSPORT_PeerAddressLookupContext 45struct GNUNET_TRANSPORT_PeerIterateContext
46{ 46{
47 /** 47 /**
48 * Function to call with the human-readable address. 48 * Function to call with the binary address.
49 */ 49 */
50 GNUNET_TRANSPORT_AddressLookUpCallback cb; 50 GNUNET_TRANSPORT_PeerIterateCallback cb;
51 51
52 /** 52 /**
53 * Closure for cb. 53 * Closure for cb.
@@ -76,11 +76,12 @@ static void
76peer_address_response_processor (void *cls, 76peer_address_response_processor (void *cls,
77 const struct GNUNET_MessageHeader *msg) 77 const struct GNUNET_MessageHeader *msg)
78{ 78{
79 struct GNUNET_TRANSPORT_PeerAddressLookupContext *pal_ctx = cls; 79 struct GNUNET_TRANSPORT_PeerIterateContext *pal_ctx = cls;
80 struct AddressIterateResponseMessage *air_msg = (struct AddressIterateResponseMessage *) &msg[1]; 80 struct AddressIterateResponseMessage *air_msg;
81 const struct GNUNET_HELLO_Address *address; 81 struct GNUNET_HELLO_Address *address;
82 uint16_t size; 82 uint16_t size;
83 if (air_msg == NULL) 83
84 if (msg == NULL)
84 { 85 {
85 pal_ctx->cb (pal_ctx->cb_cls, NULL); 86 pal_ctx->cb (pal_ctx->cb_cls, NULL);
86 GNUNET_CLIENT_disconnect (pal_ctx->client, GNUNET_NO); 87 GNUNET_CLIENT_disconnect (pal_ctx->client, GNUNET_NO);
@@ -98,6 +99,16 @@ peer_address_response_processor (void *cls,
98 return; 99 return;
99 } 100 }
100 101
102 if (size < sizeof (struct GNUNET_MessageHeader) + sizeof (struct AddressIterateResponseMessage))
103 {
104 GNUNET_break_op (0);
105 pal_ctx->cb (pal_ctx->cb_cls, NULL );
106 GNUNET_CLIENT_disconnect (pal_ctx->client, GNUNET_NO);
107 GNUNET_free (pal_ctx);
108 return;
109 }
110
111 air_msg = (struct AddressIterateResponseMessage *) &msg[1];
101 size_t tlen = ntohl(air_msg->pluginlen); 112 size_t tlen = ntohl(air_msg->pluginlen);
102 size_t alen = ntohl(air_msg->addrlen); 113 size_t alen = ntohl(air_msg->addrlen);
103 114
@@ -113,7 +124,7 @@ peer_address_response_processor (void *cls,
113 char * addr = (char *) &air_msg[1]; 124 char * addr = (char *) &air_msg[1];
114 char * transport_name = &addr[alen]; 125 char * transport_name = &addr[alen];
115 126
116 if (transport_name[tlen] != '\0') 127 if (transport_name[tlen-1] != '\0')
117 { 128 {
118 GNUNET_break_op (0); 129 GNUNET_break_op (0);
119 pal_ctx->cb (pal_ctx->cb_cls, NULL ); 130 pal_ctx->cb (pal_ctx->cb_cls, NULL );
@@ -122,8 +133,6 @@ peer_address_response_processor (void *cls,
122 return; 133 return;
123 } 134 }
124 135
125 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "peer %s transport_name: %s\n",GNUNET_i2s(&air_msg->peer), transport_name);
126
127 address = GNUNET_HELLO_address_allocate(&air_msg->peer, transport_name, addr, alen); 136 address = GNUNET_HELLO_address_allocate(&air_msg->peer, transport_name, addr, alen);
128 137
129 /* expect more replies */ 138 /* expect more replies */
@@ -131,28 +140,36 @@ peer_address_response_processor (void *cls,
131 GNUNET_TIME_absolute_get_remaining (pal_ctx->timeout)); 140 GNUNET_TIME_absolute_get_remaining (pal_ctx->timeout));
132 141
133 pal_ctx->cb (pal_ctx->cb_cls, address); 142 pal_ctx->cb (pal_ctx->cb_cls, address);
143 GNUNET_free (address);
134} 144}
135 145
136 146
137/** 147/**
138 * Return all the known addresses for a peer. 148 * Return all the known addresses for a specific peer or all peers.
149 * Returns continously all address if one_shot is set to GNUNET_NO
150 *
151 * CHANGE: Returns the address(es) that we are currently using for this
152 * peer. Upon completion, the 'AddressLookUpCallback' is called one more
153 * time with 'NULL' for the address and the peer. After this, the operation must no
154 * longer be explicitly cancelled.
139 * 155 *
140 * @param cfg configuration to use 156 * @param cfg configuration to use
141 * @param peer peer identity to look up the addresses of 157 * @param peer peer identity to look up the addresses of, CHANGE: allow NULL for all (connected) peers
158 * @param one_shot GNUNET_YES to return the current state and then end (with NULL+NULL),
159 * GNUNET_NO to monitor the set of addresses used (continuously, must be explicitly cancelled)
142 * @param timeout how long is the lookup allowed to take at most 160 * @param timeout how long is the lookup allowed to take at most
143 * @param peer_address_callback function to call with the results 161 * @param peer_address_callback function to call with the results
144 * @param peer_address_callback_cls closure for peer_address_callback 162 * @param peer_address_callback_cls closure for peer_address_callback
145 * @return handle to cancel the operation, NULL on error
146 */ 163 */
147struct GNUNET_TRANSPORT_PeerAddressLookupContext * 164struct GNUNET_TRANSPORT_PeerIterateContext *
148GNUNET_TRANSPORT_peer_get_active_addresses (const struct GNUNET_CONFIGURATION_Handle *cfg, 165GNUNET_TRANSPORT_peer_get_active_addresses (const struct GNUNET_CONFIGURATION_Handle *cfg,
149 const struct GNUNET_PeerIdentity *peer, 166 const struct GNUNET_PeerIdentity *peer,
150 int one_shot, 167 int one_shot,
151 struct GNUNET_TIME_Relative timeout, 168 struct GNUNET_TIME_Relative timeout,
152 GNUNET_TRANSPORT_AddressLookUpCallback peer_address_callback, 169 GNUNET_TRANSPORT_PeerIterateCallback peer_address_callback,
153 void *peer_address_callback_cls) 170 void *peer_address_callback_cls)
154{ 171{
155 struct GNUNET_TRANSPORT_PeerAddressLookupContext *pal_ctx; 172 struct GNUNET_TRANSPORT_PeerIterateContext *pal_ctx;
156 struct AddressIterateMessage msg; 173 struct AddressIterateMessage msg;
157 struct GNUNET_CLIENT_Connection *client; 174 struct GNUNET_CLIENT_Connection *client;
158 struct GNUNET_TIME_Absolute abs_timeout; 175 struct GNUNET_TIME_Absolute abs_timeout;
@@ -174,7 +191,7 @@ GNUNET_TRANSPORT_peer_get_active_addresses (const struct GNUNET_CONFIGURATION_Ha
174 else 191 else
175 memcpy (&msg.peer, peer , sizeof (struct GNUNET_PeerIdentity)); 192 memcpy (&msg.peer, peer , sizeof (struct GNUNET_PeerIdentity));
176 193
177 pal_ctx = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PeerAddressLookupContext)); 194 pal_ctx = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PeerIterateContext));
178 pal_ctx->cb = peer_address_callback; 195 pal_ctx->cb = peer_address_callback;
179 pal_ctx->cb_cls = peer_address_callback_cls; 196 pal_ctx->cb_cls = peer_address_callback_cls;
180 pal_ctx->timeout = abs_timeout; 197 pal_ctx->timeout = abs_timeout;
@@ -195,7 +212,7 @@ GNUNET_TRANSPORT_peer_get_active_addresses (const struct GNUNET_CONFIGURATION_Ha
195 */ 212 */
196void 213void
197GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct 214GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct
198 GNUNET_TRANSPORT_PeerAddressLookupContext 215 GNUNET_TRANSPORT_PeerIterateContext
199 *alc) 216 *alc)
200{ 217{
201 GNUNET_CLIENT_disconnect (alc->client, GNUNET_NO); 218 GNUNET_CLIENT_disconnect (alc->client, GNUNET_NO);
@@ -203,7 +220,7 @@ GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct
203} 220}
204 221
205/** 222/**
206 * Return all the known addresses for all peers. 223 * Return all addresses for all peers.
207 * 224 *
208 * @param cfg configuration to use 225 * @param cfg configuration to use
209 * @param timeout how long is the lookup allowed to take at most 226 * @param timeout how long is the lookup allowed to take at most
@@ -213,7 +230,7 @@ GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct
213void 230void
214GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, 231GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
215 struct GNUNET_TIME_Relative timeout, 232 struct GNUNET_TIME_Relative timeout,
216 GNUNET_TRANSPORT_AddressLookUpCallback 233 GNUNET_TRANSPORT_PeerIterateCallback
217 peer_address_callback, 234 peer_address_callback,
218 void *peer_address_callback_cls) 235 void *peer_address_callback_cls)
219{ 236{
diff --git a/src/transport/transport_api_address_to_string.c b/src/transport/transport_api_address_to_string.c
index 2e5a34ce2..87ee9ad83 100644
--- a/src/transport/transport_api_address_to_string.c
+++ b/src/transport/transport_api_address_to_string.c
@@ -76,7 +76,7 @@ address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
76 return; 76 return;
77 } 77 }
78 GNUNET_break (ntohs (msg->type) == 78 GNUNET_break (ntohs (msg->type) ==
79 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE); 79 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
80 size = ntohs (msg->size); 80 size = ntohs (msg->size);
81 if (size == sizeof (struct GNUNET_MessageHeader)) 81 if (size == sizeof (struct GNUNET_MessageHeader))
82 { 82 {
@@ -131,8 +131,7 @@ GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cf
131 char *addrbuf; 131 char *addrbuf;
132 132
133 GNUNET_assert (address != NULL); 133 GNUNET_assert (address != NULL);
134 alen = GNUNET_HELLO_address_get_size (address); 134 len = sizeof (struct AddressLookupMessage) + GNUNET_HELLO_address_get_size (address);
135 len = sizeof (struct AddressLookupMessage) + alen;
136 if (len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 135 if (len >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
137 { 136 {
138 GNUNET_break (0); 137 GNUNET_break (0);
@@ -144,6 +143,8 @@ GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cf
144 return NULL; 143 return NULL;
145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 144 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
146 "GNUNET_TRANSPORT_address_to_string\n"); 145 "GNUNET_TRANSPORT_address_to_string\n");
146
147 alen = address->address_length;
147 msg = GNUNET_malloc (len); 148 msg = GNUNET_malloc (len);
148 msg->header.size = htons (len); 149 msg->header.size = htons (len);
149 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING); 150 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING);
@@ -151,7 +152,9 @@ GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cf
151 msg->timeout = GNUNET_TIME_relative_hton (timeout); 152 msg->timeout = GNUNET_TIME_relative_hton (timeout);
152 msg->addrlen = htonl (alen); 153 msg->addrlen = htonl (alen);
153 addrbuf = (char *) &msg[1]; 154 addrbuf = (char *) &msg[1];
154 memcpy (addrbuf, address, alen); 155 memcpy (addrbuf, address->address, alen);
156 strcpy (&addrbuf[alen], address->transport_name);
157
155 alc = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_AddressToStringContext)); 158 alc = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_AddressToStringContext));
156 alc->cb = aluc; 159 alc->cb = aluc;
157 alc->cb_cls = aluc_cls; 160 alc->cb_cls = aluc_cls;
@@ -183,4 +186,4 @@ GNUNET_TRANSPORT_address_to_string_cancel (struct
183 186
184 187
185 188
186/* end of transport_api_address_lookup.c */ 189/* end of transport_api_address_to_string.c */