From: Matthias Wachs Date: Wed, 7 Sep 2011 16:07:48 +0000 (+0000) Subject: porting gnunet-transport-list-connections to binary address X-Git-Tag: initial-import-from-subversion-38251~17200 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=230c72bb1a9aae87bbbd0f1da505f33fc42b1b99;p=oweals%2Fgnunet.git porting gnunet-transport-list-connections to binary address --- diff --git a/src/include/gnunet_transport_service.h b/src/include/gnunet_transport_service.h index 6c443cee8..8435271f9 100644 --- a/src/include/gnunet_transport_service.h +++ b/src/include/gnunet_transport_service.h @@ -446,7 +446,7 @@ typedef void (*GNUNET_TRANSPORT_NotifyDisconnect) (void *cls, /** - * Function to call with a human-readable format of an address + * Function to call with a binary format of an address * * @param cls closure * @param address NULL on error, otherwise 0-terminated printable UTF-8 string @@ -455,6 +455,25 @@ typedef void (*GNUNET_TRANSPORT_AddressLookUpCallback) (void *cls, const char *address); +/** + * Function to call with a binary format of an address + * + * @param cls closure + * @param peer peer identity + * @param transport transport plugin + * @param addr address + * @param addrlen address length + */ +typedef void (*GNUNET_TRANSPORT_AddressLookUpBinaryCallback) (void *cls, + const struct + GNUNET_PeerIdentity + * peer, + const char + *transport, + const void *addr, + size_t addrlen); + + /** * Connect to the transport service. Note that the connection may * complete (or fail) asynchronously. @@ -672,7 +691,7 @@ GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle void GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TIME_Relative timeout, - GNUNET_TRANSPORT_AddressLookUpCallback + GNUNET_TRANSPORT_AddressLookUpBinaryCallback peer_address_callback, void *peer_address_callback_cls); diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c index 140b15454..8676f335e 100644 --- a/src/transport/gnunet-service-transport_clients.c +++ b/src/transport/gnunet-service-transport_clients.c @@ -625,18 +625,42 @@ clients_handle_set_quota (void *cls, struct GNUNET_SERVER_Client *client, * @param address the resolved name, NULL to indicate the last response */ static void -transmit_address_to_client (void *cls, const char *address) +transmit_address_to_client (void *cls, const char *buf) { struct GNUNET_SERVER_TransmitContext *tc = cls; - if (NULL == address) + if (NULL == buf) { GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); return; } - GNUNET_SERVER_transmit_context_append_data (tc, address, strlen (address) + 1, + GNUNET_SERVER_transmit_context_append_data (tc, buf, strlen (buf + 1), + GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); +} + + +/** + * Take the given address and append it to the set of results sent back to + * the client. + * + * @param cls the transmission context used ('struct GNUNET_SERVER_TransmitContext*') + * @param address the resolved name, NULL to indicate the last response + */ +static void +transmit_binary_to_client (void *cls, void *buf, size_t size) +{ + struct GNUNET_SERVER_TransmitContext *tc = cls; + + if (NULL == buf) + { + GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, + GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); + GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); + return; + } + GNUNET_SERVER_transmit_context_append_data (tc, buf, size, GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); } @@ -781,18 +805,22 @@ clients_handle_peer_address_lookup (void *cls, * @param ats_count number of entries in ats (excluding 0-termination) */ static void -output_addresses (void *cls, const struct GNUNET_PeerIdentity *neighbour, +output_addresses (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_TRANSPORT_ATS_Information *ats, uint32_t ats_count) { struct GNUNET_SERVER_TransmitContext *tc = cls; - char *addr_buf; + struct AddressIterateResponseMessage msg; + size_t size; - /* FIXME: move to a binary format!!! */ - GNUNET_asprintf (&addr_buf, "%s: %s", GNUNET_i2s (neighbour), - GST_plugins_a2s ("FIXME", NULL, 0)); - transmit_address_to_client (tc, addr_buf); - GNUNET_free (addr_buf); + size = + sizeof (struct AddressIterateResponseMessage) - + sizeof (struct GNUNET_MessageHeader); + memcpy (&msg.peer, peer, sizeof (struct GNUNET_PeerIdentity)); + msg.addrlen = ntohs (0); + msg.pluginlen = ntohs (0); + + transmit_binary_to_client (tc, &msg, size); } diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c index 8f7d34b5d..9c6aaba67 100644 --- a/src/transport/gnunet-service-transport_neighbours.c +++ b/src/transport/gnunet-service-transport_neighbours.c @@ -403,10 +403,8 @@ disconnect_neighbour (struct NeighbourMapEntry *n) GNUNET_assert (neighbours_connected > 0); neighbours_connected--; - GNUNET_STATISTICS_update (GST_stats, - gettext_noop - ("# peers connected"), - -1, GNUNET_NO); + GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), -1, + GNUNET_NO); disconnect_notify_cb (callback_cls, &n->id); } GNUNET_assert (GNUNET_YES == @@ -597,10 +595,8 @@ try_connect_using_address (void *cls, const struct GNUNET_PeerIdentity *target, return; neighbours_connected++; - GNUNET_STATISTICS_update (GST_stats, - gettext_noop - ("# peers connected"), - 1, GNUNET_NO); + GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1, + GNUNET_NO); connect_notify_cb (callback_cls, target, n->ats, n->ats_count); } diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c index 395f4e87a..56b4037b4 100644 --- a/src/transport/gnunet-service-transport_validation.c +++ b/src/transport/gnunet-service-transport_validation.c @@ -409,6 +409,7 @@ add_valid_address (void *cls, const char *tname, ve = find_validation_entry (&public_key, &pid, tname, addr, addrlen); ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until, expiration); struct GNUNET_TRANSPORT_ATS_Information ats; + ats.type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); ats.value = htonl (0); @@ -918,7 +919,6 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender, if (ntohs (hdr->size) < sizeof (struct TransportPongMessage)) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "SIZE!\n"); GNUNET_break_op (0); return; } @@ -983,6 +983,7 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender, /* validity achieved, remember it! */ ve->valid_until = GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION); struct GNUNET_TRANSPORT_ATS_Information ats; + ats.type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); ats.value = htonl (0); GNUNET_ATS_address_update (GST_ats, &ve->pid, ve->valid_until, ve->transport_name, NULL, ve->addr, ve->addrlen, &ats, 1); /* FIXME: compute and add latency here... */ diff --git a/src/transport/gnunet-transport-list-connections.c b/src/transport/gnunet-transport-list-connections.c index 0542a5cd9..64b67dcd4 100644 --- a/src/transport/gnunet-transport-list-connections.c +++ b/src/transport/gnunet-transport-list-connections.c @@ -53,13 +53,22 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg; * @param address NULL on error, otherwise 0-terminated printable UTF-8 string */ static void -process_address (void *cls, const char *address) +process_address (void *cls, const struct GNUNET_PeerIdentity *peer, + const char *transport, const void *addr, size_t addrlen) { #if VERBOSE connection_count++; #endif - if (address != NULL) - fprintf (stdout, "%s\n", address); + if ((peer != NULL) || (transport != NULL) || + ((addr != NULL) && (addrlen > 0))) + fprintf (stdout, "Peer `%s' plugin: `%s' address `%s'\n", + (peer != NULL) ? GNUNET_i2s (peer) : "", + (transport != NULL) ? transport : "", ((addr != NULL) && + (addrlen > 0) && + (transport != + NULL)) ? + "how do i resolve the name without transport service?" : + ""); } diff --git a/src/transport/transport_api_address_iterate.c b/src/transport/transport_api_address_iterate.c index 833b82d7e..da333798f 100644 --- a/src/transport/transport_api_address_iterate.c +++ b/src/transport/transport_api_address_iterate.c @@ -47,7 +47,7 @@ struct AddressLookupCtx /** * Function to call with the human-readable address. */ - GNUNET_TRANSPORT_AddressLookUpCallback cb; + GNUNET_TRANSPORT_AddressLookUpBinaryCallback cb; /** * Closure for cb. @@ -78,41 +78,50 @@ peer_address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg) { struct AddressLookupCtx *alucb = cls; - const char *address; + struct AddressIterateResponseMessage *address; uint16_t size; + if (msg == NULL) { - alucb->cb (alucb->cb_cls, NULL); + alucb->cb (alucb->cb_cls, NULL, NULL, NULL, 0); GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); GNUNET_free (alucb); return; } + GNUNET_break (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); size = ntohs (msg->size); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message type %u size %u\n", + ntohs (msg->type), size); if (size == sizeof (struct GNUNET_MessageHeader)) { /* done! */ - alucb->cb (alucb->cb_cls, NULL); + alucb->cb (alucb->cb_cls, NULL, NULL, NULL, 0); GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); GNUNET_free (alucb); return; } - address = (const char *) &msg[1]; - if (address[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0') + if (size != sizeof (struct AddressIterateResponseMessage)) { /* invalid reply */ GNUNET_break (0); - alucb->cb (alucb->cb_cls, NULL); + alucb->cb (alucb->cb_cls, NULL, NULL, NULL, 0); GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); GNUNET_free (alucb); return; } + + address = (struct AddressIterateResponseMessage *) msg; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "PEER: %s\n", + GNUNET_i2s (&address->peer)); + + /* expect more replies */ GNUNET_CLIENT_receive (alucb->client, &peer_address_response_processor, alucb, GNUNET_TIME_absolute_get_remaining (alucb->timeout)); - alucb->cb (alucb->cb_cls, address); + alucb->cb (alucb->cb_cls, &address->peer, NULL, NULL, 0); } @@ -127,7 +136,7 @@ peer_address_response_processor (void *cls, void GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TIME_Relative timeout, - GNUNET_TRANSPORT_AddressLookUpCallback + GNUNET_TRANSPORT_AddressLookUpBinaryCallback peer_address_callback, void *peer_address_callback_cls) { @@ -139,12 +148,12 @@ GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, client = GNUNET_CLIENT_connect ("transport", cfg); if (client == NULL) { - peer_address_callback (peer_address_callback_cls, NULL); + peer_address_callback (peer_address_callback_cls, NULL, NULL, NULL, 0); return; } abs_timeout = GNUNET_TIME_relative_to_absolute (timeout); - msg.header.size = htons (sizeof (struct AddressLookupMessage)); + msg.header.size = htons (sizeof (struct AddressIterateMessage)); msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE); msg.timeout = GNUNET_TIME_absolute_hton (abs_timeout); peer_address_lookup_cb = GNUNET_malloc (sizeof (struct AddressLookupCtx));