use relative timeouts over network
authorChristian Grothoff <christian@grothoff.org>
Fri, 5 Aug 2011 08:37:59 +0000 (08:37 +0000)
committerChristian Grothoff <christian@grothoff.org>
Fri, 5 Aug 2011 08:37:59 +0000 (08:37 +0000)
src/transport/gnunet-service-transport.c
src/transport/gnunet-service-transport_clients.c
src/transport/transport.h
src/transport/transport_api_address_lookup.c

index 269d21f63d73a0c7d17d63833d55a2155f14788b..6fd17e72dd1f56595642d2ac5bc4cbbc096633db 100644 (file)
@@ -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)
index 2e345a9c011e96b08aa693c5ffae2f3b00afe0c8..1cf3d09592725e6b5468592edcd1ffbd76e6e096 100644 (file)
@@ -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);
 }
 
 
index 1c6aaa2a96ee1608487cba7587cc77fa40a6a12b..5384e7395f40da203d8e46978adcdf93d5a0542a 100644 (file)
@@ -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.
index c6244c28ffa0b915832bbe58aad87c8ede900e1e..619e60a43fdf76e3d38d5ad92250688e51d0cb6f 100644 (file)
@@ -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,