gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r33465 - in gnunet/src: dv include transport


From: gnunet
Subject: [GNUnet-SVN] r33465 - in gnunet/src: dv include transport
Date: Mon, 2 Jun 2014 11:40:12 +0200

Author: wachs
Date: 2014-06-02 11:40:12 +0200 (Mon, 02 Jun 2014)
New Revision: 33465

Modified:
   gnunet/src/dv/plugin_transport_dv.c
   gnunet/src/include/gnunet_transport_plugin.h
   gnunet/src/transport/gnunet-service-transport_clients.c
   gnunet/src/transport/plugin_transport_bluetooth.c
   gnunet/src/transport/plugin_transport_http_common.c
   gnunet/src/transport/plugin_transport_tcp.c
   gnunet/src/transport/plugin_transport_template.c
   gnunet/src/transport/plugin_transport_udp.c
   gnunet/src/transport/plugin_transport_unix.c
   gnunet/src/transport/plugin_transport_wlan.c
   gnunet/src/transport/transport_api_address_to_string.c
Log:
fix semantic for address_to_string


Modified: gnunet/src/dv/plugin_transport_dv.c
===================================================================
--- gnunet/src/dv/plugin_transport_dv.c 2014-06-02 00:13:38 UTC (rev 33464)
+++ gnunet/src/dv/plugin_transport_dv.c 2014-06-02 09:40:12 UTC (rev 33465)
@@ -649,8 +649,11 @@
 {
   if ( (0 == addrlen) &&
        (0 == strcmp (type, "dv")) )
-    asc (asc_cls, "dv");
-  asc (asc_cls, NULL);
+    asc (asc_cls, "dv", GNUNET_OK);
+  else
+    asc (asc_cls, NULL, GNUNET_SYSERR);
+
+  asc (asc_cls, NULL, GNUNET_OK);
 }
 
 

Modified: gnunet/src/include/gnunet_transport_plugin.h
===================================================================
--- gnunet/src/include/gnunet_transport_plugin.h        2014-06-02 00:13:38 UTC 
(rev 33464)
+++ gnunet/src/include/gnunet_transport_plugin.h        2014-06-02 09:40:12 UTC 
(rev 33465)
@@ -415,12 +415,14 @@
  * each human-readable address obtained.
  *
  * @param cls closure
- * @param address one of the names for the host, NULL
- *        on the last call to the callback
+ * @param address one of the names for the host, NULL on last callback
+ * @param res GNUNET_OK if conversion was successful, GNUNET_SYSERR on failure,
+ *      GNUNET_OK on last callback
  */
 typedef void
 (*GNUNET_TRANSPORT_AddressStringCallback) (void *cls,
-                                           const char *address);
+                                           const char *address,
+                                           int res);
 
 
 /**
@@ -612,9 +614,7 @@
   GNUNET_TRANSPORT_QueryKeepaliveFactorFunction query_keepalive_factor;
 
   /**
-   * Function to pretty-print addresses.  NOTE: this function is not
-   * yet used by transport-service, but will be used in the future
-   * once the transport-API has been completed.
+   * Function to pretty-print addresses.
    */
   GNUNET_TRANSPORT_AddressPrettyPrinter address_pretty_printer;
 

Modified: gnunet/src/transport/gnunet-service-transport_clients.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport_clients.c     2014-06-02 
00:13:38 UTC (rev 33464)
+++ gnunet/src/transport/gnunet-service-transport_clients.c     2014-06-02 
09:40:12 UTC (rev 33465)
@@ -858,48 +858,62 @@
  *
  * @param cls the transmission context used ('struct 
GNUNET_SERVER_TransmitContext*')
  * @param buf text to transmit
+ * @param res GNUNET_OK if conversion was successful, GNUNET_SYSERR on error
  */
 static void
-transmit_address_to_client (void *cls, const char *buf)
+transmit_address_to_client (void *cls, const char *buf, int res)
 {
   struct AddressToStringContext *actx = cls;
   struct AddressToStringResultMessage *atsm;
   size_t len;
 
-  if (NULL != buf)
+  if (NULL == buf)
   {
-    len = sizeof (struct AddressToStringResultMessage) + strlen (buf) + 1;
+    GNUNET_assert ((res == GNUNET_OK) ||  (res == GNUNET_SYSERR));
+
+    len = sizeof (struct AddressToStringResultMessage);
     atsm = GNUNET_malloc (len);
     atsm->header.size = ntohs (len);
     atsm->header.type = ntohs 
(GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
-    atsm->res = htonl (GNUNET_YES);
-    atsm->addr_len = htonl (strlen (buf) + 1);
-    memcpy (&atsm[1], buf, strlen (buf) + 1);
+
+    if (GNUNET_OK == res)
+    {
+      /* done, transmit */
+      atsm->res = htonl (GNUNET_YES);
+      atsm->addr_len = htonl (0);
+      GNUNET_SERVER_transmit_context_append_message (actx->tc,
+          (const struct GNUNET_MessageHeader *) atsm);
+
+      GNUNET_SERVER_transmit_context_run (actx->tc, 
GNUNET_TIME_UNIT_FOREVER_REL);
+      GNUNET_CONTAINER_DLL_remove (a2s_head, a2s_tail, actx);
+      GNUNET_free (actx);
+    }
+    if (GNUNET_SYSERR == res)
+    {
+      /* address conversion failed */
+
+      atsm->res = htonl (GNUNET_NO);
+      atsm->addr_len = htonl (0);
+      GNUNET_SERVER_transmit_context_append_message (actx->tc,
+          (const struct GNUNET_MessageHeader *) atsm);
+      GNUNET_free (atsm);
+    }
   }
   else
   {
-    len = sizeof (struct AddressToStringResultMessage);
-
+    GNUNET_assert (res == GNUNET_OK);
+    /* succesful conversion, append*/
+    len = sizeof (struct AddressToStringResultMessage) + strlen (buf) + 1;
     atsm = GNUNET_malloc (len);
     atsm->header.size = ntohs (len);
     atsm->header.type = ntohs 
(GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
-    atsm->res = htonl (GNUNET_NO);
-    atsm->addr_len = htonl (0);
-
-    /* BUG HUNTING */
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Failed to convert address for client 
%p\n", actx->tc);
+    atsm->res = htonl (GNUNET_YES);
+    atsm->addr_len = htonl (strlen (buf) + 1);
+    memcpy (&atsm[1], buf, strlen (buf) + 1);
+    GNUNET_SERVER_transmit_context_append_message (actx->tc,
+        (const struct GNUNET_MessageHeader *) atsm);
+    GNUNET_free (atsm);
   }
-
-  if (NULL == buf)
-  {
-    /* Address could not be converted */
-    GNUNET_SERVER_transmit_context_append_message (actx->tc, (const struct 
GNUNET_MessageHeader *)atsm);
-    GNUNET_SERVER_transmit_context_run (actx->tc, 
GNUNET_TIME_UNIT_FOREVER_REL);
-    GNUNET_CONTAINER_DLL_remove (a2s_head, a2s_tail, actx);
-    GNUNET_free (actx);
-    return;
-  }
-  GNUNET_SERVER_transmit_context_append_message (actx->tc, (const struct 
GNUNET_MessageHeader *) atsm);
 }
 
 

Modified: gnunet/src/transport/plugin_transport_bluetooth.c
===================================================================
--- gnunet/src/transport/plugin_transport_bluetooth.c   2014-06-02 00:13:38 UTC 
(rev 33464)
+++ gnunet/src/transport/plugin_transport_bluetooth.c   2014-06-02 09:40:12 UTC 
(rev 33465)
@@ -1719,15 +1719,15 @@
   if (sizeof (struct WlanAddress) != addrlen)
   {
     /* invalid address  */
-    LOG (GNUNET_ERROR_TYPE_WARNING,
-        _("Bluetooth address with invalid size encountered\n"));
-    asc (asc_cls, NULL);
-    return;
+    asc (asc_cls, NULL, GNUNET_SYSERR);
   }
-  ret = GNUNET_strdup (bluetooth_plugin_address_to_string(NULL, addr, 
addrlen));
-  asc (asc_cls, ret);
-  GNUNET_free (ret);
-  asc (asc_cls, NULL);
+  else
+  {
+    ret = GNUNET_strdup (bluetooth_plugin_address_to_string(NULL, addr, 
addrlen));
+    asc (asc_cls, ret, GNUNET_OK);
+    GNUNET_free (ret);
+  }
+  asc (asc_cls, NULL, GNUNET_OK);
 }
 
 

Modified: gnunet/src/transport/plugin_transport_http_common.c
===================================================================
--- gnunet/src/transport/plugin_transport_http_common.c 2014-06-02 00:13:38 UTC 
(rev 33464)
+++ gnunet/src/transport/plugin_transport_http_common.c 2014-06-02 09:40:12 UTC 
(rev 33465)
@@ -208,17 +208,14 @@
 {
   const struct HttpAddress *address = addr;
 
-  if (NULL ==
-      http_common_plugin_address_to_string (NULL, type,
-                                            address, addrlen))
-  {
-    asc (asc_cls, NULL);
-    return;
-  }
-  asc (asc_cls, http_common_plugin_address_to_string (NULL,
-                                                      type,
-                                                      address, addrlen));
-  asc (asc_cls, NULL);
+  if (NULL
+      == http_common_plugin_address_to_string (NULL, type, address, addrlen))
+    asc (asc_cls, NULL, GNUNET_SYSERR);
+  else
+    asc (asc_cls,
+        http_common_plugin_address_to_string (NULL, type, address, addrlen),
+        GNUNET_OK);
+  asc (asc_cls, NULL, GNUNET_OK);
 }
 
 

Modified: gnunet/src/transport/plugin_transport_tcp.c
===================================================================
--- gnunet/src/transport/plugin_transport_tcp.c 2014-06-02 00:13:38 UTC (rev 
33464)
+++ gnunet/src/transport/plugin_transport_tcp.c 2014-06-02 09:40:12 UTC (rev 
33465)
@@ -1690,8 +1690,8 @@
 
   if (NULL == hostname)
   {
-    ppc->asc (ppc->asc_cls, NULL );
-    GNUNET_CONTAINER_DLL_remove(ppc_dll_head, ppc_dll_tail, ppc);
+    ppc->asc (ppc->asc_cls, NULL, GNUNET_OK); /* Final call, done */
+    GNUNET_CONTAINER_DLL_remove (ppc_dll_head, ppc_dll_tail, ppc);
     GNUNET_SCHEDULER_cancel (ppc->timeout_task);
     ppc->timeout_task = GNUNET_SCHEDULER_NO_TASK;
     ppc->resolver_handle = NULL;
@@ -1703,6 +1703,7 @@
       break;
   if (NULL == cur)
   {
+    ppc->asc (ppc->asc_cls, NULL, GNUNET_SYSERR);
     GNUNET_break(0);
     return;
   }
@@ -1713,7 +1714,7 @@
   else
     GNUNET_asprintf (&ret, "%s.%u.%s:%d", PLUGIN_NAME, ppc->options, hostname,
         ppc->port);
-  ppc->asc (ppc->asc_cls, ret);
+  ppc->asc (ppc->asc_cls, ret, GNUNET_OK);
   GNUNET_free(ret);
 }
 
@@ -1730,6 +1731,7 @@
  * @param timeout after how long should we give up?
  * @param asc function to call on each string
  * @param asc_cls closure for asc
+ *
  */
 static void
 tcp_plugin_address_pretty_printer (void *cls, const char *type,
@@ -1774,7 +1776,8 @@
   else
   {
     /* invalid address */
-    asc (asc_cls, NULL );
+    asc (asc_cls, NULL, GNUNET_SYSERR);
+    asc (asc_cls, NULL, GNUNET_OK);
     return;
   }
   ppc = GNUNET_new (struct PrettyPrinterContext);

Modified: gnunet/src/transport/plugin_transport_template.c
===================================================================
--- gnunet/src/transport/plugin_transport_template.c    2014-06-02 00:13:38 UTC 
(rev 33464)
+++ gnunet/src/transport/plugin_transport_template.c    2014-06-02 09:40:12 UTC 
(rev 33465)
@@ -276,11 +276,8 @@
                                         GNUNET_TRANSPORT_AddressStringCallback
                                         asc, void *asc_cls)
 {
-  if (0 == addrlen)
-  {
-    asc (asc_cls, TRANSPORT_SESSION_INBOUND_STRING);
-  }
-  asc (asc_cls, NULL);
+  asc (asc_cls, "converted address", GNUNET_OK); /* return address */
+  asc (asc_cls, NULL, GNUNET_OK); /* done */
 }
 
 

Modified: gnunet/src/transport/plugin_transport_udp.c
===================================================================
--- gnunet/src/transport/plugin_transport_udp.c 2014-06-02 00:13:38 UTC (rev 
33464)
+++ gnunet/src/transport/plugin_transport_udp.c 2014-06-02 09:40:12 UTC (rev 
33465)
@@ -749,7 +749,7 @@
 
   if (hostname == NULL )
   {
-    ppc->asc (ppc->asc_cls, NULL );
+    ppc->asc (ppc->asc_cls, NULL, GNUNET_OK); /* Final call, done */
     GNUNET_CONTAINER_DLL_remove(ppc_dll_head, ppc_dll_tail, ppc);
     GNUNET_SCHEDULER_cancel (ppc->timeout_task);
     ppc->timeout_task = GNUNET_SCHEDULER_NO_TASK;
@@ -758,13 +758,12 @@
     return;
   }
   for (cur = ppc_dll_head; (NULL != cur); cur = cur->next)
-  {
     if (cur == ppc)
       break;
-  }
   if (NULL == cur)
   {
-    GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Invalid callback for PPC %p \n", ppc);
+    ppc->asc (ppc->asc_cls, NULL, GNUNET_SYSERR);
+    GNUNET_break(0);
     return;
   }
 
@@ -774,7 +773,7 @@
   else
     GNUNET_asprintf (&ret, "%s.%u.%s:%d", PLUGIN_NAME, ppc->options, hostname,
         ppc->port);
-  ppc->asc (ppc->asc_cls, ret);
+  ppc->asc (ppc->asc_cls, ret, GNUNET_OK);
   GNUNET_free(ret);
 }
 
@@ -847,7 +846,8 @@
   {
     /* invalid address */
     GNUNET_break_op(0);
-    asc (asc_cls, NULL );
+    asc (asc_cls, NULL , GNUNET_SYSERR);
+    asc (asc_cls, NULL, GNUNET_OK);
     return;
   }
   ppc = GNUNET_new (struct PrettyPrinterContext);

Modified: gnunet/src/transport/plugin_transport_unix.c
===================================================================
--- gnunet/src/transport/plugin_transport_unix.c        2014-06-02 00:13:38 UTC 
(rev 33464)
+++ gnunet/src/transport/plugin_transport_unix.c        2014-06-02 09:40:12 UTC 
(rev 33465)
@@ -1421,18 +1421,11 @@
 {
   if ((NULL != addr) && (addrlen > 0))
   {
-    asc (asc_cls, unix_address_to_string (NULL, addr, addrlen));
+    asc (asc_cls, unix_address_to_string (NULL, addr, addrlen), GNUNET_OK);
   }
-  else if (0 == addrlen)
-  {
-    asc (asc_cls, TRANSPORT_SESSION_INBOUND_STRING);
-  }
   else
-  {
-    GNUNET_break (0);
-    asc (asc_cls, "<invalid UNIX address>");
-  }
-  asc (asc_cls, NULL);
+    asc (asc_cls, NULL, GNUNET_SYSERR);
+  asc (asc_cls, NULL, GNUNET_OK);
 }
 
 

Modified: gnunet/src/transport/plugin_transport_wlan.c
===================================================================
--- gnunet/src/transport/plugin_transport_wlan.c        2014-06-02 00:13:38 UTC 
(rev 33464)
+++ gnunet/src/transport/plugin_transport_wlan.c        2014-06-02 09:40:12 UTC 
(rev 33465)
@@ -1725,15 +1725,15 @@
   if (sizeof (struct WlanAddress) != addrlen)
   {
     /* invalid address  */
-    LOG (GNUNET_ERROR_TYPE_WARNING,
-        _("WLAN address with invalid size encountered\n"));
-    asc (asc_cls, NULL);
-    return;
+    asc (asc_cls, NULL, GNUNET_SYSERR);
   }
-  ret = GNUNET_strdup (wlan_plugin_address_to_string(NULL, addr, addrlen));
-  asc (asc_cls, ret);
-  GNUNET_free (ret);
-  asc (asc_cls, NULL);
+  else
+  {
+    ret = GNUNET_strdup (wlan_plugin_address_to_string(NULL, addr, addrlen));
+    asc (asc_cls, ret, GNUNET_OK);
+    GNUNET_free (ret);
+  }
+  asc (asc_cls, NULL, GNUNET_OK);
 }
 
 

Modified: gnunet/src/transport/transport_api_address_to_string.c
===================================================================
--- gnunet/src/transport/transport_api_address_to_string.c      2014-06-02 
00:13:38 UTC (rev 33464)
+++ gnunet/src/transport/transport_api_address_to_string.c      2014-06-02 
09:40:12 UTC (rev 33465)
@@ -106,7 +106,7 @@
   {
     GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Client %p failed to resolve address 
\n",
         alucb->client);
-
+    GNUNET_break (0);
     alucb->cb (alucb->cb_cls, empty_str, GNUNET_SYSERR);
 
     /* expect more replies */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]