-fix time assertion introduce in last patch
[oweals/gnunet.git] / src / util / connection.c
index 3290abcfc37b964affac6b28a77a68557f089211..fb20617fd82cd90a055d58267aa9abfc9c49b6c6 100644 (file)
@@ -30,9 +30,7 @@
  * These rules should apply in general, but for this
  * module they are VERY, VERY important.
  */
-
 #include "platform.h"
-#include "gnunet_common.h"
 #include "gnunet_util_lib.h"
 #include "gnunet_resolver_service.h"
 
@@ -421,7 +419,8 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access,
       (GNUNET_YES != (aret = access (access_cls, gcp, uaddr, addrlen))))
   {
     if (GNUNET_NO == aret)
-      LOG (GNUNET_ERROR_TYPE_INFO, _("Access denied to `%s'\n"),
+      LOG (GNUNET_ERROR_TYPE_INFO,
+           _("Access denied to `%s'\n"),
            GNUNET_a2s (uaddr, addrlen));
     GNUNET_break (GNUNET_OK ==
                   GNUNET_NETWORK_socket_shutdown (sock, SHUT_RDWR));
@@ -435,7 +434,7 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access,
   connection->addr = uaddr;
   connection->addrlen = addrlen;
   connection->sock = sock;
-  LOG (GNUNET_ERROR_TYPE_INFO, 
+  LOG (GNUNET_ERROR_TYPE_INFO,
        _("Accepting connection from `%s': %p\n"),
        GNUNET_a2s (uaddr, addrlen), connection);
   return connection;
@@ -475,7 +474,7 @@ signal_receive_error (struct GNUNET_CONNECTION_Handle *connection, int errcode)
   GNUNET_CONNECTION_Receiver receiver;
 
   LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Receive encounters error (%s), connection closed (%p)\n", 
+       "Receive encounters error (%s), connection closed (%p)\n",
        STRERROR (errcode),
        connection);
   GNUNET_assert (NULL != (receiver = connection->receiver));
@@ -610,14 +609,14 @@ receive_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
 static void
 connect_success_continuation (struct GNUNET_CONNECTION_Handle *connection)
 {
-  LOG (GNUNET_ERROR_TYPE_DEBUG, 
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Connection to `%s' succeeded! (%p)\n",
        GNUNET_a2s (connection->addr, connection->addrlen), connection);
   /* trigger jobs that waited for the connection */
   if (NULL != connection->receiver)
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG,
-         "Connection succeeded, starting with receiving data (%p)\n", 
+         "Connection succeeded, starting with receiving data (%p)\n",
         connection);
     GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == connection->read_task);
     connection->read_task =
@@ -828,22 +827,23 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct
 #ifdef AF_UNIX
   struct GNUNET_CONNECTION_Handle *connection;
   struct sockaddr_un *un;
-  size_t slen;
 
   GNUNET_assert (0 < strlen (unixpath));        /* sanity check */
   un = GNUNET_new (struct sockaddr_un);
   un->sun_family = AF_UNIX;
-  slen = strlen (unixpath);
-  if (slen >= sizeof (un->sun_path))
-    slen = sizeof (un->sun_path) - 1;
-  memcpy (un->sun_path, unixpath, slen);
-  un->sun_path[slen] = '\0';
-  slen = sizeof (struct sockaddr_un);
-#if HAVE_SOCKADDR_IN_SIN_LEN
-  un->sun_len = (u_char) slen;
+  strncpy (un->sun_path, unixpath, sizeof (un->sun_path) - 1);
+#ifdef LINUX
+  {
+    int abstract;
+
+    abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg, "TESTING",
+                                                     "USE_ABSTRACT_SOCKETS");
+    if (GNUNET_YES == abstract)
+      un->sun_path[0] = '\0';
+  }
 #endif
-#if LINUX
-  un->sun_path[0] = '\0';
+#if HAVE_SOCKADDR_IN_SIN_LEN
+  un->sun_len = (u_char) sizeof (struct sockaddr_un);
 #endif
   connection = GNUNET_new (struct GNUNET_CONNECTION_Handle);
   connection->cfg = cfg;
@@ -852,7 +852,7 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct
   connection->port = 0;
   connection->hostname = NULL;
   connection->addr = (struct sockaddr *) un;
-  connection->addrlen = slen;
+  connection->addrlen = sizeof (struct sockaddr_un);
   connection->sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0);
   if (NULL == connection->sock)
   {
@@ -991,10 +991,10 @@ GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection)
   if ( (NULL != connection->sock) &&
        (GNUNET_YES != connection->persist) )
   {
-    if ((GNUNET_YES != GNUNET_NETWORK_socket_shutdown (connection->sock, SHUT_RDWR)) && 
-       (ENOTCONN != errno) && 
+    if ((GNUNET_YES != GNUNET_NETWORK_socket_shutdown (connection->sock, SHUT_RDWR)) &&
+       (ENOTCONN != errno) &&
        (ECONNRESET != errno) )
-      LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "shutdown");    
+      LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "shutdown");
   }
   if (NULL != connection->sock)
   {
@@ -1288,7 +1288,7 @@ transmit_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
     return;
   }
   GNUNET_assert (NULL != connection->sock);
-  if (NULL == tc->write_ready) 
+  if (NULL == tc->write_ready)
   {
     /* special circumstances (in particular, PREREQ_DONE after
      * connect): not yet ready to write, but no "fatal" error either.
@@ -1402,7 +1402,7 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connec
   connection->nth.notify_size = size;
   connection->nth.transmit_timeout = GNUNET_TIME_relative_to_absolute (timeout);
   GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == connection->nth.timeout_task);
-  if ((NULL == connection->sock) && 
+  if ((NULL == connection->sock) &&
       (NULL == connection->ap_head) &&
       (NULL == connection->dns_active))
   {