From 6d99e0c26d6cb6dc6e00f21b9a75327f30886f4f Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 5 Aug 2011 08:37:59 +0000 Subject: use relative timeouts over network --- src/transport/gnunet-service-transport.c | 6 +- src/transport/gnunet-service-transport_clients.c | 81 ++++++++++++++++++++++++ src/transport/transport.h | 6 +- src/transport/transport_api_address_lookup.c | 6 +- 4 files changed, 89 insertions(+), 10 deletions(-) (limited to 'src/transport') diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 269d21f63..6fd17e72d 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c @@ -5870,6 +5870,8 @@ transmit_address_to_client (void *cls, const char *address) } else { + 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); } } @@ -5893,7 +5895,6 @@ handle_address_lookup (void *cls, const char *address; uint16_t size; struct GNUNET_SERVER_TransmitContext *tc; - struct GNUNET_TIME_Absolute timeout; struct GNUNET_TIME_Relative rtimeout; int32_t numeric; @@ -5921,8 +5922,7 @@ handle_address_lookup (void *cls, GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } - timeout = GNUNET_TIME_absolute_ntoh (alum->timeout); - rtimeout = GNUNET_TIME_absolute_get_remaining (timeout); + rtimeout = GNUNET_TIME_relative_ntoh (alum->timeout); numeric = ntohl (alum->numeric_only); lsPlugin = find_transport (nameTransport); if (NULL == lsPlugin) diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c index 2e345a9c0..1cf3d0959 100644 --- a/src/transport/gnunet-service-transport_clients.c +++ b/src/transport/gnunet-service-transport_clients.c @@ -27,6 +27,7 @@ #include "gnunet-service-transport_clients.h" #include "gnunet-service-transport_hello.h" #include "gnunet-service-transport_neighbours.h" +#include "gnunet-service-transport_plugins.h" #include "gnunet-service-transport.h" #include "transport.h" @@ -472,6 +473,33 @@ GST_clients_handle_set_quota (void *cls, } +/** + * 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_address_to_client (void *cls, + const char *address) +{ + struct GNUNET_SERVER_TransmitContext *tc = cls; + + if (NULL == address) + { + 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_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); +} + + /** * Client asked to resolve an address. Process the request. * @@ -484,6 +512,59 @@ GST_clients_handle_address_lookup (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message) { + const struct AddressLookupMessage *alum; + struct GNUNET_TRANSPORT_PluginFunctions *papi; + const char *plugin_name; + const char *address; + uint32_t address_len; + uint16_t size; + struct GNUNET_SERVER_TransmitContext *tc; + struct GNUNET_TIME_Relative rtimeout; + int32_t numeric; + + size = ntohs (message->size); + if (size < sizeof (struct AddressLookupMessage)) + { + GNUNET_break (0); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; + } + alum = (const struct AddressLookupMessage *) message; + address_len = ntohl (alum->addrlen); + if (size <= sizeof (struct AddressLookupMessage) + address_len) + { + GNUNET_break (0); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; + } + address = (const char *) &alum[1]; + plugin_name = (const char *) &address[address_len]; + if (plugin_name + [size - sizeof (struct AddressLookupMessage) - address_len - 1] != '\0') + { + GNUNET_break (0); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; + } + rtimeout = GNUNET_TIME_relative_ntoh (alum->timeout); + numeric = ntohl (alum->numeric_only); + papi = GST_plugins_find (plugin_name); + if (NULL == papi) + { + tc = GNUNET_SERVER_transmit_context_create (client); + GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, + GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); + GNUNET_SERVER_transmit_context_run (tc, rtimeout); + return; + } + GNUNET_SERVER_disable_receive_done_warning (client); + tc = GNUNET_SERVER_transmit_context_create (client); + papi->address_pretty_printer (papi->cls, + plugin_name, + address, address_len, + numeric, + rtimeout, + &transmit_address_to_client, tc); } diff --git a/src/transport/transport.h b/src/transport/transport.h index 1c6aaa2a9..5384e7395 100644 --- a/src/transport/transport.h +++ b/src/transport/transport.h @@ -165,8 +165,8 @@ struct TransportRequestConnectMessage }; /** - * Message used to set a particular bandwidth quota. Send TO the - * service to set an incoming quota, send FROM the service to update + * Message used to set a particular bandwidth quota. Sent TO the + * service to set an incoming quota, sent FROM the service to update * an outgoing quota. */ struct QuotaSetMessage @@ -311,7 +311,7 @@ struct AddressLookupMessage /** * timeout to give up. */ - struct GNUNET_TIME_AbsoluteNBO timeout; + struct GNUNET_TIME_RelativeNBO timeout; /** * Length of the (binary) address in bytes, in big-endian. diff --git a/src/transport/transport_api_address_lookup.c b/src/transport/transport_api_address_lookup.c index c6244c28f..619e60a43 100644 --- a/src/transport/transport_api_address_lookup.c +++ b/src/transport/transport_api_address_lookup.c @@ -131,7 +131,6 @@ GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, size_t slen; size_t len; struct AddressLookupMessage *msg; - struct GNUNET_TIME_Absolute abs_timeout; struct AddressLookupCtx *aluCB; struct GNUNET_CLIENT_Connection *client; char *addrbuf; @@ -150,12 +149,11 @@ GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, aluc (aluc_cls, NULL); return; } - abs_timeout = GNUNET_TIME_relative_to_absolute (timeout); msg = GNUNET_malloc (len); msg->header.size = htons (len); msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP); msg->numeric_only = htonl (numeric); - msg->timeout = GNUNET_TIME_absolute_hton (abs_timeout); + msg->timeout = GNUNET_TIME_relative_hton (timeout); msg->addrlen = htonl (addressLen); addrbuf = (char *) &msg[1]; memcpy (addrbuf, address, addressLen); @@ -163,7 +161,7 @@ GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, aluCB = GNUNET_malloc (sizeof (struct AddressLookupCtx)); aluCB->cb = aluc; aluCB->cb_cls = aluc_cls; - aluCB->timeout = abs_timeout; + aluCB->timeout = GNUNET_TIME_relative_to_absolute (timeout); aluCB->client = client; GNUNET_assert (GNUNET_OK == GNUNET_CLIENT_transmit_and_get_response (client, -- cgit v1.2.3