From 56c32ea37a52b239494a7f91933e60eb7caf30f3 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Tue, 29 Nov 2011 18:04:01 +0000 Subject: - finale commit for the api change --- src/transport/gnunet-service-transport_clients.c | 62 +++++++++++++++++----- .../gnunet-service-transport_neighbours.c | 20 +++++++ .../gnunet-service-transport_neighbours.h | 10 ++++ src/transport/gnunet-transport.c | 43 ++++++++++----- src/transport/transport.conf | 3 +- src/transport/transport_api_address_lookup.c | 57 +++++++++++++------- src/transport/transport_api_address_to_string.c | 13 +++-- 7 files changed, 156 insertions(+), 52 deletions(-) (limited to 'src/transport') 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 transmit_address_to_client (void *cls, const char *buf) { struct GNUNET_SERVER_TransmitContext *tc = cls; - if (NULL == buf) { 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 tc); } +#if 0 + +THIS FUNCTIONALITY IS NOT USED ANYWHERE! /** * Send an address to the client. @@ -749,16 +751,15 @@ send_address_to_client (void *cls, /** - * Client asked to obtain information about a peer's addresses. + * Client asked to obtain information about all addresses of a peer. * Process the request. - * FIXME: use better name! * * @param cls unused * @param client the client * @param message the peer address information request */ static void -clients_handle_peer_address_lookup (void *cls, +clients_handle_peer_address_iterate (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message) { @@ -768,13 +769,15 @@ clients_handle_peer_address_lookup (void *cls, peer_address_lookup = (const struct PeerAddressLookupMessage *) message; GNUNET_break (ntohl (peer_address_lookup->reserved) == 0); tc = GNUNET_SERVER_transmit_context_create (client); + GST_validation_get_addresses (&peer_address_lookup->peer, &send_address_to_client, tc); + GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE); GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); } - +#endif /** * Output the active address of connected neighbours to the given client. @@ -811,15 +814,14 @@ output_addresses (void *cls, const struct GNUNET_PeerIdentity *peer, memcpy(&addr[alen], address->transport_name, tlen); transmit_binary_to_client (tc, msg, size); - - 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)); GNUNET_free (msg); } /** - * Client asked to obtain information about all actively used addresses. - * Process the request. FIXME: use better name! + * Client asked to obtain information about all actively used addresses + * of connected peers + * Process the request. * * @param cls unused * @param client the client @@ -830,11 +832,41 @@ clients_handle_address_iterate (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message) { struct GNUNET_SERVER_TransmitContext *tc; + struct AddressIterateMessage * msg; + struct GNUNET_PeerIdentity dummy; + struct GNUNET_HELLO_Address * address; + GNUNET_SERVER_disable_receive_done_warning (client); tc = GNUNET_SERVER_transmit_context_create (client); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "clients_handle_address_iterate: \n"); - GST_neighbours_iterate (&output_addresses, tc); + + if (ntohs (message->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE) + { + GNUNET_break_op(0); + return; + } + if (ntohs (message->size) != sizeof (struct AddressIterateMessage)) + { + GNUNET_break_op(0); + return; + } + + msg = (struct AddressIterateMessage *) message; + memset (&dummy, 0, sizeof (struct GNUNET_PeerIdentity)); + + if (0 == memcmp (&msg->peer, &dummy, sizeof (struct GNUNET_PeerIdentity))) + { + /* iterate over all neighbours */ + GST_neighbours_iterate (&output_addresses, tc); + } + else + { + /* just return one neighbour */ + address = GST_neighbour_get_current_address(&msg->peer); + if (address != NULL) + output_addresses(tc, &msg->peer, NULL, 0, address); + } + GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE); GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); @@ -859,12 +891,16 @@ GST_clients_start (struct GNUNET_SERVER_Handle *server) {&clients_handle_request_connect, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT, sizeof (struct TransportRequestConnectMessage)}, + /* converts a binary address to a human readable address */ {&clients_handle_address_to_string, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING, 0}, - {&clients_handle_peer_address_lookup, NULL, +#if 0 + /* Not used at the moment, gets all addresses of a peer */ + {&clients_handle_peer_address_iterate, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP, sizeof (struct PeerAddressLookupMessage)}, - {&clients_handle_address_iterate, NULL, +#endif + {&clients_handle_address_iterate, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE, sizeof (struct AddressIterateMessage)}, {&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) return n->latency; } +/** + * Obtain current address information for the given neighbour. + * + * @param peer + * @return address currently used + */ +struct GNUNET_HELLO_Address * +GST_neighbour_get_current_address (const struct GNUNET_PeerIdentity *peer) +{ + struct NeighbourMapEntry *n; + + n = lookup_neighbour (peer); + if ( (NULL == n) || + ( (n->address == NULL) && (n->session == NULL) ) ) + return NULL; + + return n->address; +} + + /** * 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 @@ -284,6 +284,16 @@ struct GNUNET_TIME_Relative GST_neighbour_get_latency (const struct GNUNET_PeerIdentity *peer); +/** + * Obtain current address information for the given neighbour. + * + * @param peer + * @return address currently used + */ +struct GNUNET_HELLO_Address * +GST_neighbour_get_current_address (const struct GNUNET_PeerIdentity *peer); + + /** * We received a disconnect message from the given peer, * validate and process. 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 @@ -75,6 +75,11 @@ static int iterate_connections; */ static int test_configuration; +/** + * Option -n. + */ +static int numeric; + /** * Global return value (0 success). */ @@ -150,7 +155,6 @@ struct TestContext }; -struct GNUNET_CONFIGURATION_Handle * cfg; /** * Display the result of the test. @@ -436,7 +440,17 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, void process_string (void *cls, const char *address) { - fprintf (stdout, _("process_string\n")); + struct GNUNET_PeerIdentity * peer = cls; + + if ((address != NULL)) + { + fprintf (stdout, _("Peer `%s' : %s\n"), GNUNET_i2s(peer), address); + } + else + { + /* done */ + GNUNET_free (peer); + } } /** @@ -451,23 +465,24 @@ void process_string (void *cls, static void process_address (void *cls, const struct GNUNET_HELLO_Address *address) { + const struct GNUNET_CONFIGURATION_Handle * cfg = cls; + if (address == NULL) { + /* done */ return; } - fprintf (stdout, _("Peer `%s'\n"), - GNUNET_i2s (&address->peer)); + struct GNUNET_PeerIdentity * peer = GNUNET_malloc(sizeof (struct GNUNET_PeerIdentity)); + *peer = address->peer; /* Resolve address to string */ - /* GNUNET_TRANSPORT_address_to_string (cfg, - address, - GNUNET_NO, - GNUNET_TIME_UNIT_MINUTES, - &process_string, - NULL); - */ + address, + numeric, + GNUNET_TIME_UNIT_MINUTES, + &process_string, + peer); } @@ -483,7 +498,6 @@ static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { - cfg = cfg; if (test_configuration) { do_test_configuration (cfg); @@ -525,7 +539,7 @@ run (void *cls, char *const *args, const char *cfgfile, if (iterate_connections) { GNUNET_TRANSPORT_address_iterate (cfg, GNUNET_TIME_UNIT_MINUTES, - &process_address, NULL); + &process_address, (void *)cfg); } } @@ -550,6 +564,9 @@ main (int argc, char *const *argv) {'t', "test", NULL, gettext_noop ("test transport configuration (involves external server)"), 0, &GNUNET_GETOPT_set_one, &test_configuration}, + {'n', "numeric", NULL, + gettext_noop ("do not resolve hostnames"), + 0, &GNUNET_GETOPT_set_one, &numeric}, GNUNET_GETOPT_OPTION_VERBOSE (&verbosity), GNUNET_GETOPT_OPTION_END }; 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 # BINDTO = # REJECT_FROM = # REJECT_FROM6 = -# PREFIX = +PREFIX = valgrind --leak-check=full + [transport-tcp] # 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 @@ /** * Context for the address lookup. */ -struct GNUNET_TRANSPORT_PeerAddressLookupContext +struct GNUNET_TRANSPORT_PeerIterateContext { /** - * Function to call with the human-readable address. + * Function to call with the binary address. */ - GNUNET_TRANSPORT_AddressLookUpCallback cb; + GNUNET_TRANSPORT_PeerIterateCallback cb; /** * Closure for cb. @@ -76,11 +76,12 @@ static void peer_address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg) { - struct GNUNET_TRANSPORT_PeerAddressLookupContext *pal_ctx = cls; - struct AddressIterateResponseMessage *air_msg = (struct AddressIterateResponseMessage *) &msg[1]; - const struct GNUNET_HELLO_Address *address; + struct GNUNET_TRANSPORT_PeerIterateContext *pal_ctx = cls; + struct AddressIterateResponseMessage *air_msg; + struct GNUNET_HELLO_Address *address; uint16_t size; - if (air_msg == NULL) + + if (msg == NULL) { pal_ctx->cb (pal_ctx->cb_cls, NULL); GNUNET_CLIENT_disconnect (pal_ctx->client, GNUNET_NO); @@ -98,6 +99,16 @@ peer_address_response_processor (void *cls, return; } + if (size < sizeof (struct GNUNET_MessageHeader) + sizeof (struct AddressIterateResponseMessage)) + { + GNUNET_break_op (0); + pal_ctx->cb (pal_ctx->cb_cls, NULL ); + GNUNET_CLIENT_disconnect (pal_ctx->client, GNUNET_NO); + GNUNET_free (pal_ctx); + return; + } + + air_msg = (struct AddressIterateResponseMessage *) &msg[1]; size_t tlen = ntohl(air_msg->pluginlen); size_t alen = ntohl(air_msg->addrlen); @@ -113,7 +124,7 @@ peer_address_response_processor (void *cls, char * addr = (char *) &air_msg[1]; char * transport_name = &addr[alen]; - if (transport_name[tlen] != '\0') + if (transport_name[tlen-1] != '\0') { GNUNET_break_op (0); pal_ctx->cb (pal_ctx->cb_cls, NULL ); @@ -122,8 +133,6 @@ peer_address_response_processor (void *cls, return; } - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "peer %s transport_name: %s\n",GNUNET_i2s(&air_msg->peer), transport_name); - address = GNUNET_HELLO_address_allocate(&air_msg->peer, transport_name, addr, alen); /* expect more replies */ @@ -131,28 +140,36 @@ peer_address_response_processor (void *cls, GNUNET_TIME_absolute_get_remaining (pal_ctx->timeout)); pal_ctx->cb (pal_ctx->cb_cls, address); + GNUNET_free (address); } /** - * Return all the known addresses for a peer. + * Return all the known addresses for a specific peer or all peers. + * Returns continously all address if one_shot is set to GNUNET_NO + * + * CHANGE: Returns the address(es) that we are currently using for this + * peer. Upon completion, the 'AddressLookUpCallback' is called one more + * time with 'NULL' for the address and the peer. After this, the operation must no + * longer be explicitly cancelled. * * @param cfg configuration to use - * @param peer peer identity to look up the addresses of + * @param peer peer identity to look up the addresses of, CHANGE: allow NULL for all (connected) peers + * @param one_shot GNUNET_YES to return the current state and then end (with NULL+NULL), + * GNUNET_NO to monitor the set of addresses used (continuously, must be explicitly cancelled) * @param timeout how long is the lookup allowed to take at most * @param peer_address_callback function to call with the results * @param peer_address_callback_cls closure for peer_address_callback - * @return handle to cancel the operation, NULL on error */ -struct GNUNET_TRANSPORT_PeerAddressLookupContext * +struct GNUNET_TRANSPORT_PeerIterateContext * GNUNET_TRANSPORT_peer_get_active_addresses (const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_PeerIdentity *peer, int one_shot, struct GNUNET_TIME_Relative timeout, - GNUNET_TRANSPORT_AddressLookUpCallback peer_address_callback, + GNUNET_TRANSPORT_PeerIterateCallback peer_address_callback, void *peer_address_callback_cls) { - struct GNUNET_TRANSPORT_PeerAddressLookupContext *pal_ctx; + struct GNUNET_TRANSPORT_PeerIterateContext *pal_ctx; struct AddressIterateMessage msg; struct GNUNET_CLIENT_Connection *client; struct GNUNET_TIME_Absolute abs_timeout; @@ -174,7 +191,7 @@ GNUNET_TRANSPORT_peer_get_active_addresses (const struct GNUNET_CONFIGURATION_Ha else memcpy (&msg.peer, peer , sizeof (struct GNUNET_PeerIdentity)); - pal_ctx = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PeerAddressLookupContext)); + pal_ctx = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PeerIterateContext)); pal_ctx->cb = peer_address_callback; pal_ctx->cb_cls = peer_address_callback_cls; pal_ctx->timeout = abs_timeout; @@ -195,7 +212,7 @@ GNUNET_TRANSPORT_peer_get_active_addresses (const struct GNUNET_CONFIGURATION_Ha */ void GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct - GNUNET_TRANSPORT_PeerAddressLookupContext + GNUNET_TRANSPORT_PeerIterateContext *alc) { GNUNET_CLIENT_disconnect (alc->client, GNUNET_NO); @@ -203,7 +220,7 @@ GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct } /** - * Return all the known addresses for all peers. + * Return all addresses for all peers. * * @param cfg configuration to use * @param timeout how long is the lookup allowed to take at most @@ -213,7 +230,7 @@ GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct void GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TIME_Relative timeout, - GNUNET_TRANSPORT_AddressLookUpCallback + GNUNET_TRANSPORT_PeerIterateCallback peer_address_callback, void *peer_address_callback_cls) { 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) return; } GNUNET_break (ntohs (msg->type) == - GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE); + GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); size = ntohs (msg->size); if (size == sizeof (struct GNUNET_MessageHeader)) { @@ -131,8 +131,7 @@ GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cf char *addrbuf; GNUNET_assert (address != NULL); - alen = GNUNET_HELLO_address_get_size (address); - len = sizeof (struct AddressLookupMessage) + alen; + len = sizeof (struct AddressLookupMessage) + GNUNET_HELLO_address_get_size (address); if (len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) { GNUNET_break (0); @@ -144,6 +143,8 @@ GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cf return NULL; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_TRANSPORT_address_to_string\n"); + + alen = address->address_length; msg = GNUNET_malloc (len); msg->header.size = htons (len); 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 msg->timeout = GNUNET_TIME_relative_hton (timeout); msg->addrlen = htonl (alen); addrbuf = (char *) &msg[1]; - memcpy (addrbuf, address, alen); + memcpy (addrbuf, address->address, alen); + strcpy (&addrbuf[alen], address->transport_name); + alc = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_AddressToStringContext)); alc->cb = aluc; alc->cb_cls = aluc_cls; @@ -183,4 +186,4 @@ GNUNET_TRANSPORT_address_to_string_cancel (struct -/* end of transport_api_address_lookup.c */ +/* end of transport_api_address_to_string.c */ -- cgit v1.2.3