Link libgnunetblockgroup to libgnunetblock
[oweals/gnunet.git] / src / util / connection.c
index 3143aa5368657a44f46560b4a1c2e9c860f2303f..e822b264f47c50f5e99705512c0b1c0c7bf8e2ed 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2009-2013 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2009-2013 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -35,9 +35,9 @@
 #include "gnunet_resolver_service.h"
 
 
-#define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__)
+#define LOG(kind,...) GNUNET_log_from (kind, "util-connection", __VA_ARGS__)
 
-#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util", syscall)
+#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-connection", syscall)
 
 
 /**
@@ -217,7 +217,7 @@ struct GNUNET_CONNECTION_Handle
   struct GNUNET_RESOLVER_RequestHandle *dns_active;
 
   /**
-   * The handle we return for GNUNET_CONNECTION_notify_transmit_ready.
+   * The handle we return for #GNUNET_CONNECTION_notify_transmit_ready().
    */
   struct GNUNET_CONNECTION_TransmitHandle nth;
 
@@ -335,16 +335,23 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb,
   struct sockaddr_in6 *v6;
   struct sockaddr *sa;
   void *uaddr;
-  struct GNUNET_CONNECTION_Credentials *gcp;
-  struct GNUNET_CONNECTION_Credentials gc;
 #ifdef SO_PEERCRED
   struct ucred uc;
   socklen_t olen;
 #endif
+  struct GNUNET_CONNECTION_Credentials *gcp;
+#if HAVE_GETPEEREID || defined(SO_PEERCRED) || HAVE_GETPEERUCRED
+  struct GNUNET_CONNECTION_Credentials gc;
+
+  gc.uid = 0;
+  gc.gid = 0;
+#endif
 
   addrlen = sizeof (addr);
   sock =
-      GNUNET_NETWORK_socket_accept (lsock, (struct sockaddr *) &addr, &addrlen);
+      GNUNET_NETWORK_socket_accept (lsock,
+                                   (struct sockaddr *) &addr,
+                                   &addrlen);
   if (NULL == sock)
   {
     if (EAGAIN != errno)
@@ -360,7 +367,8 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb,
 
   sa = (struct sockaddr *) addr;
   v6 = (struct sockaddr_in6 *) addr;
-  if ((AF_INET6 == sa->sa_family) && (IN6_IS_ADDR_V4MAPPED (&v6->sin6_addr)))
+  if ( (AF_INET6 == sa->sa_family) &&
+       (IN6_IS_ADDR_V4MAPPED (&v6->sin6_addr)) )
   {
     /* convert to V4 address */
     v4 = GNUNET_new (struct sockaddr_in);
@@ -369,7 +377,7 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb,
 #if HAVE_SOCKADDR_IN_SIN_LEN
     v4->sin_len = (u_char) sizeof (struct sockaddr_in);
 #endif
-    memcpy (&v4->sin_addr,
+    GNUNET_memcpy (&v4->sin_addr,
             &((char *) &v6->sin6_addr)[sizeof (struct in6_addr) -
                                        sizeof (struct in_addr)],
             sizeof (struct in_addr));
@@ -380,24 +388,28 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb,
   else
   {
     uaddr = GNUNET_malloc (addrlen);
-    memcpy (uaddr, addr, addrlen);
+    GNUNET_memcpy (uaddr, addr, addrlen);
   }
   gcp = NULL;
-  gc.uid = 0;
-  gc.gid = 0;
   if (AF_UNIX == sa->sa_family)
   {
 #if HAVE_GETPEEREID
     /* most BSDs */
-    if (0 == getpeereid (GNUNET_NETWORK_get_fd (sock), &gc.uid, &gc.gid))
+    if (0 == getpeereid (GNUNET_NETWORK_get_fd (sock),
+                        &gc.uid,
+                        &gc.gid))
       gcp = &gc;
 #else
 #ifdef SO_PEERCRED
     /* largely traditional GNU/Linux */
     olen = sizeof (uc);
-    if ((0 ==
-         getsockopt (GNUNET_NETWORK_get_fd (sock), SOL_SOCKET, SO_PEERCRED, &uc,
-                     &olen)) && (olen == sizeof (uc)))
+    if ( (0 ==
+         getsockopt (GNUNET_NETWORK_get_fd (sock),
+                     SOL_SOCKET,
+                     SO_PEERCRED,
+                     &uc,
+                     &olen)) &&
+        (olen == sizeof (uc)) )
     {
       gc.uid = uc.uid;
       gc.gid = uc.gid;
@@ -421,8 +433,11 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb,
 #endif
   }
 
-  if ((NULL != access_cb) &&
-      (GNUNET_YES != (aret = access_cb (access_cb_cls, gcp, uaddr, addrlen))))
+  if ( (NULL != access_cb) &&
+       (GNUNET_YES != (aret = access_cb (access_cb_cls,
+                                        gcp,
+                                        uaddr,
+                                        addrlen))) )
   {
     if (GNUNET_NO == aret)
       LOG (GNUNET_ERROR_TYPE_INFO,
@@ -444,7 +459,9 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb,
   connection->sock = sock;
   LOG (GNUNET_ERROR_TYPE_INFO,
        _("Accepting connection from `%s': %p\n"),
-       GNUNET_a2s (uaddr, addrlen), connection);
+       GNUNET_a2s (uaddr,
+                  addrlen),
+       connection);
   return connection;
 }
 
@@ -465,7 +482,7 @@ GNUNET_CONNECTION_get_address (struct GNUNET_CONNECTION_Handle *connection,
   if ((NULL == connection->addr) || (0 == connection->addrlen))
     return GNUNET_NO;
   *addr = GNUNET_malloc (connection->addrlen);
-  memcpy (*addr, connection->addr, connection->addrlen);
+  GNUNET_memcpy (*addr, connection->addr, connection->addrlen);
   *addrlen = connection->addrlen;
   return GNUNET_OK;
 }
@@ -554,7 +571,9 @@ signal_transmit_error (struct GNUNET_CONNECTION_Handle *connection,
     return;                     /* nobody to tell about it */
   notify = connection->nth.notify_ready;
   connection->nth.notify_ready = NULL;
-  notify (connection->nth.notify_ready_cls, 0, NULL);
+  notify (connection->nth.notify_ready_cls,
+         0,
+         NULL);
 }
 
 
@@ -606,10 +625,9 @@ connect_fail_continuation (struct GNUNET_CONNECTION_Handle *connection)
  * We are ready to transmit (or got a timeout).
  *
  * @param cls our connection handle
- * @param tc task context describing why we are here
  */
 static void
-transmit_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
+transmit_ready (void *cls);
 
 
 /**
@@ -617,10 +635,9 @@ transmit_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
  * to read.
  *
  * @param cls connection to read from
- * @param tc scheduler context
  */
 static void
-receive_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
+receive_ready (void *cls);
 
 
 /**
@@ -633,7 +650,8 @@ connect_success_continuation (struct GNUNET_CONNECTION_Handle *connection)
 {
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Connection to `%s' succeeded! (%p)\n",
-       GNUNET_a2s (connection->addr, connection->addrlen),
+       GNUNET_a2s (connection->addr,
+                  connection->addrlen),
        connection);
   /* trigger jobs that waited for the connection */
   if (NULL != connection->receiver)
@@ -644,7 +662,8 @@ connect_success_continuation (struct GNUNET_CONNECTION_Handle *connection)
     GNUNET_assert (NULL == connection->read_task);
     connection->read_task =
       GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining
-                                     (connection->receive_timeout), connection->sock,
+                                     (connection->receive_timeout),
+                                    connection->sock,
                                      &receive_ready, connection);
   }
   if (NULL != connection->nth.notify_ready)
@@ -668,34 +687,41 @@ connect_success_continuation (struct GNUNET_CONNECTION_Handle *connection)
  * Scheduler let us know that we're either ready to write on the
  * socket OR connect timed out.  Do the right thing.
  *
- * @param cls the "struct AddressProbe*" with the address that we are probing
- * @param tc success or failure info about the connect attempt.
+ * @param cls the `struct AddressProbe *` with the address that we are probing
  */
 static void
-connect_probe_continuation (void *cls,
-                            const struct GNUNET_SCHEDULER_TaskContext *tc)
+connect_probe_continuation (void *cls)
 {
   struct AddressProbe *ap = cls;
   struct GNUNET_CONNECTION_Handle *connection = ap->connection;
+  const struct GNUNET_SCHEDULER_TaskContext *tc;
   struct AddressProbe *pos;
   int error;
   socklen_t len;
 
   GNUNET_assert (NULL != ap->sock);
-  GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, ap);
+  GNUNET_CONTAINER_DLL_remove (connection->ap_head,
+                              connection->ap_tail,
+                              ap);
   len = sizeof (error);
   errno = 0;
   error = 0;
-  if ((0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) ||
-      (GNUNET_OK !=
-       GNUNET_NETWORK_socket_getsockopt (ap->sock, SOL_SOCKET, SO_ERROR, &error,
-                                         &len)) || (0 != error))
+  tc = GNUNET_SCHEDULER_get_task_context ();
+  if ( (0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) ||
+       (GNUNET_OK !=
+       GNUNET_NETWORK_socket_getsockopt (ap->sock,
+                                         SOL_SOCKET,
+                                         SO_ERROR,
+                                         &error,
+                                         &len)) ||
+       (0 != error) )
   {
-    GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock));
+    GNUNET_break (GNUNET_OK ==
+                 GNUNET_NETWORK_socket_close (ap->sock));
     GNUNET_free (ap);
-    if ((NULL == connection->ap_head) &&
-        (GNUNET_NO == connection->dns_active) &&
-        (NULL == connection->proxy_handshake))
+    if ( (NULL == connection->ap_head) &&
+        (GNUNET_NO == connection->dns_active) &&
+        (NULL == connection->proxy_handshake) )
       connect_fail_continuation (connection);
     return;
   }
@@ -703,7 +729,7 @@ connect_probe_continuation (void *cls,
   connection->sock = ap->sock;
   GNUNET_assert (NULL == connection->addr);
   connection->addr = GNUNET_malloc (ap->addrlen);
-  memcpy (connection->addr, ap->addr, ap->addrlen);
+  GNUNET_memcpy (connection->addr, ap->addr, ap->addrlen);
   connection->addrlen = ap->addrlen;
   GNUNET_free (ap);
   /* cancel all other attempts */
@@ -711,7 +737,9 @@ connect_probe_continuation (void *cls,
   {
     GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock));
     GNUNET_SCHEDULER_cancel (pos->task);
-    GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, pos);
+    GNUNET_CONTAINER_DLL_remove (connection->ap_head,
+                                connection->ap_tail,
+                                pos);
     GNUNET_free (pos);
   }
   connect_success_continuation (connection);
@@ -738,7 +766,7 @@ try_connect_using_address (void *cls,
   if (NULL == addr)
   {
     connection->dns_active = NULL;
-    if ((NULL == connection->ap_head) && 
+    if ((NULL == connection->ap_head) &&
         (NULL == connection->sock) &&
         (NULL == connection->proxy_handshake))
       connect_fail_continuation (connection);
@@ -756,7 +784,7 @@ try_connect_using_address (void *cls,
        connection->port);
   ap = GNUNET_malloc (sizeof (struct AddressProbe) + addrlen);
   ap->addr = (const struct sockaddr *) &ap[1];
-  memcpy (&ap[1], addr, addrlen);
+  GNUNET_memcpy (&ap[1], addr, addrlen);
   ap->addrlen = addrlen;
   ap->connection = connection;
 
@@ -773,7 +801,8 @@ try_connect_using_address (void *cls,
     GNUNET_free (ap);
     return;                     /* not supported by us */
   }
-  ap->sock = GNUNET_NETWORK_socket_create (ap->addr->sa_family, SOCK_STREAM, 0);
+  ap->sock = GNUNET_NETWORK_socket_create (ap->addr->sa_family,
+                                          SOCK_STREAM, 0);
   if (NULL == ap->sock)
   {
     GNUNET_free (ap);
@@ -784,7 +813,9 @@ try_connect_using_address (void *cls,
        GNUNET_a2s (ap->addr, ap->addrlen),
        connection);
   if ((GNUNET_OK !=
-       GNUNET_NETWORK_socket_connect (ap->sock, ap->addr, ap->addrlen)) &&
+       GNUNET_NETWORK_socket_connect (ap->sock,
+                                     ap->addr,
+                                     ap->addrlen)) &&
       (EINPROGRESS != errno))
   {
     /* maybe refused / unsupported address, try next */
@@ -796,17 +827,15 @@ try_connect_using_address (void *cls,
   GNUNET_CONTAINER_DLL_insert (connection->ap_head, connection->ap_tail, ap);
   delay = GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT;
   if (NULL != connection->nth.notify_ready)
-    delay =
-        GNUNET_TIME_relative_min (delay,
-                                  GNUNET_TIME_absolute_get_remaining (connection->nth.transmit_timeout));
+    delay = GNUNET_TIME_relative_min (delay,
+                                     GNUNET_TIME_absolute_get_remaining (connection->nth.transmit_timeout));
   if (NULL != connection->receiver)
-    delay =
-        GNUNET_TIME_relative_min (delay,
-                                  GNUNET_TIME_absolute_get_remaining
-                                  (connection->receive_timeout));
-  ap->task =
-      GNUNET_SCHEDULER_add_write_net (delay, ap->sock,
-                                      &connect_probe_continuation, ap);
+    delay = GNUNET_TIME_relative_min (delay,
+                                     GNUNET_TIME_absolute_get_remaining (connection->receive_timeout));
+  ap->task = GNUNET_SCHEDULER_add_write_net (delay,
+                                            ap->sock,
+                                            &connect_probe_continuation,
+                                            ap);
 }
 
 
@@ -835,9 +864,11 @@ GNUNET_CONNECTION_create_from_connect (const struct GNUNET_CONFIGURATION_Handle
   connection->port = port;
   connection->hostname = GNUNET_strdup (hostname);
   connection->dns_active =
-      GNUNET_RESOLVER_ip_get (connection->hostname, AF_UNSPEC,
+      GNUNET_RESOLVER_ip_get (connection->hostname,
+                             AF_UNSPEC,
                               GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT,
-                              &try_connect_using_address, connection);
+                              &try_connect_using_address,
+                             connection);
   return connection;
 }
 
@@ -867,13 +898,14 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct GNUNET_CONFIGURA
   {
     int abstract;
 
-    abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg, "TESTING",
+    abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg,
+                                                    "TESTING",
                                                      "USE_ABSTRACT_SOCKETS");
     if (GNUNET_YES == abstract)
       un->sun_path[0] = '\0';
   }
 #endif
-#if HAVE_SOCKADDR_IN_SIN_LEN
+#if HAVE_SOCKADDR_UN_SUN_LEN
   un->sun_len = (u_char) sizeof (struct sockaddr_un);
 #endif
   connection = GNUNET_new (struct GNUNET_CONNECTION_Handle);
@@ -884,7 +916,9 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct GNUNET_CONFIGURA
   connection->hostname = NULL;
   connection->addr = (struct sockaddr *) un;
   connection->addrlen = sizeof (struct sockaddr_un);
-  connection->sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0);
+  connection->sock = GNUNET_NETWORK_socket_create (AF_UNIX,
+                                                  SOCK_STREAM,
+                                                  0);
   if (NULL == connection->sock)
   {
     GNUNET_free (connection->addr);
@@ -893,11 +927,14 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct GNUNET_CONFIGURA
     return NULL;
   }
   if ( (GNUNET_OK !=
-       GNUNET_NETWORK_socket_connect (connection->sock, connection->addr, connection->addrlen)) &&
+       GNUNET_NETWORK_socket_connect (connection->sock,
+                                      connection->addr,
+                                      connection->addrlen)) &&
        (EINPROGRESS != errno) )
   {
     /* Just return; we expect everything to work eventually so don't fail HARD */
-    GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (connection->sock));
+    GNUNET_break (GNUNET_OK ==
+                 GNUNET_NETWORK_socket_close (connection->sock));
     connection->sock = NULL;
     return connection;
   }
@@ -942,7 +979,7 @@ GNUNET_CONNECTION_connect_socket (struct GNUNET_NETWORK_Handle *s,
   }
   connection = GNUNET_CONNECTION_create_from_existing (s);
   connection->addr = GNUNET_malloc (addrlen);
-  memcpy (connection->addr, serv_addr, addrlen);
+  GNUNET_memcpy (connection->addr, serv_addr, addrlen);
   connection->addrlen = addrlen;
   LOG (GNUNET_ERROR_TYPE_INFO,
        "Trying to connect to `%s' (%p)\n",
@@ -973,10 +1010,13 @@ GNUNET_CONNECTION_create_from_sockaddr (int af_family,
   s = GNUNET_NETWORK_socket_create (af_family, SOCK_STREAM, 0);
   if (NULL == s)
   {
-    LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, "socket");
+    LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
+                 "socket");
     return NULL;
   }
-  return GNUNET_CONNECTION_connect_socket (s, serv_addr, addrlen);
+  return GNUNET_CONNECTION_connect_socket (s,
+                                          serv_addr,
+                                          addrlen);
 }
 
 
@@ -991,8 +1031,8 @@ GNUNET_CONNECTION_create_from_sockaddr (int af_family,
 int
 GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *connection)
 {
-  if ((NULL != connection->ap_head) || 
-      (NULL != connection->dns_active) || 
+  if ((NULL != connection->ap_head) ||
+      (NULL != connection->dns_active) ||
       (NULL != connection->proxy_handshake))
     return GNUNET_YES;          /* still trying to connect */
   if ( (0 != connection->destroy_later) ||
@@ -1056,7 +1096,9 @@ GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection)
   {
     GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock));
     GNUNET_SCHEDULER_cancel (pos->task);
-    GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, pos);
+    GNUNET_CONTAINER_DLL_remove (connection->ap_head,
+                                connection->ap_tail,
+                                pos);
     GNUNET_free (pos);
   }
   if ( (NULL != connection->sock) &&
@@ -1095,33 +1137,26 @@ GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection)
  * or have data ready to read.
  *
  * @param cls connection to read from
- * @param tc scheduler context
  */
 static void
-receive_ready (void *cls,
-               const struct GNUNET_SCHEDULER_TaskContext *tc)
+receive_ready (void *cls)
 {
   struct GNUNET_CONNECTION_Handle *connection = cls;
+  const struct GNUNET_SCHEDULER_TaskContext *tc;
   char buffer[connection->max];
   ssize_t ret;
   GNUNET_CONNECTION_Receiver receiver;
 
   connection->read_task = NULL;
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-  {
-    /* ignore shutdown request, go again immediately */
-    connection->read_task =
-        GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining
-                                       (connection->receive_timeout), connection->sock,
-                                       &receive_ready, connection);
-    return;
-  }
+  tc = GNUNET_SCHEDULER_get_task_context ();
   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG,
         "Receive from `%s' encounters error: timeout (%s, %p)\n",
-        GNUNET_a2s (connection->addr, connection->addrlen),
-        GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (connection->receive_timeout), GNUNET_YES),
+        GNUNET_a2s (connection->addr,
+                    connection->addrlen),
+        GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (connection->receive_timeout),
+                                                GNUNET_YES),
         connection);
     signal_receive_timeout (connection);
     return;
@@ -1132,7 +1167,8 @@ receive_ready (void *cls,
     signal_receive_error (connection, ECONNREFUSED);
     return;
   }
-  GNUNET_assert (GNUNET_NETWORK_fdset_isset (tc->read_ready, connection->sock));
+  GNUNET_assert (GNUNET_NETWORK_fdset_isset (tc->read_ready,
+                                            connection->sock));
 RETRY:
   ret = GNUNET_NETWORK_socket_recv (connection->sock,
                                     buffer,
@@ -1163,8 +1199,8 @@ RETRY:
 
 
 /**
- * Receive data from the given connection.  Note that this function will
- * call @a receiver asynchronously using the scheduler.  It will
+ * Receive data from the given connection.  Note that this function
+ * will call @a receiver asynchronously using the scheduler.  It will
  * "immediately" return.  Note that there MUST only be one active
  * receive call per connection at any given point in time (so do not
  * call receive again until the receiver callback has been invoked).
@@ -1204,7 +1240,10 @@ GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *connection,
       (NULL == connection->proxy_handshake))
   {
     connection->receiver = NULL;
-    receiver (receiver_cls, NULL, 0, NULL, 0, ETIMEDOUT);
+    receiver (receiver_cls,
+             NULL, 0,
+             NULL, 0,
+             ETIMEDOUT);
     return;
   }
 }
@@ -1296,11 +1335,9 @@ process_notify (struct GNUNET_CONNECTION_Handle *connection)
  * This task notifies the client about the timeout.
  *
  * @param cls the `struct GNUNET_CONNECTION_Handle`
- * @param tc scheduler context
  */
 static void
-transmit_timeout (void *cls,
-                  const struct GNUNET_SCHEDULER_TaskContext *tc)
+transmit_timeout (void *cls)
 {
   struct GNUNET_CONNECTION_Handle *connection = cls;
   GNUNET_CONNECTION_TransmitReadyNotify notify;
@@ -1316,7 +1353,9 @@ transmit_timeout (void *cls,
   notify = connection->nth.notify_ready;
   GNUNET_assert (NULL != notify);
   connection->nth.notify_ready = NULL;
-  notify (connection->nth.notify_ready_cls, 0, NULL);
+  notify (connection->nth.notify_ready_cls,
+         0,
+         NULL);
 }
 
 
@@ -1327,11 +1366,9 @@ transmit_timeout (void *cls,
  * This task notifies the client about the error.
  *
  * @param cls the `struct GNUNET_CONNECTION_Handle`
- * @param tc scheduler context
  */
 static void
-connect_error (void *cls,
-               const struct GNUNET_SCHEDULER_TaskContext *tc)
+connect_error (void *cls)
 {
   struct GNUNET_CONNECTION_Handle *connection = cls;
   GNUNET_CONNECTION_TransmitReadyNotify notify;
@@ -1345,7 +1382,9 @@ connect_error (void *cls,
   connection->write_task = NULL;
   notify = connection->nth.notify_ready;
   connection->nth.notify_ready = NULL;
-  notify (connection->nth.notify_ready_cls, 0, NULL);
+  notify (connection->nth.notify_ready_cls,
+         0,
+         NULL);
 }
 
 
@@ -1353,14 +1392,13 @@ connect_error (void *cls,
  * We are ready to transmit (or got a timeout).
  *
  * @param cls our connection handle
- * @param tc task context describing why we are here
  */
 static void
-transmit_ready (void *cls,
-                const struct GNUNET_SCHEDULER_TaskContext *tc)
+transmit_ready (void *cls)
 {
   struct GNUNET_CONNECTION_Handle *connection = cls;
   GNUNET_CONNECTION_TransmitReadyNotify notify;
+  const struct GNUNET_SCHEDULER_TaskContext *tc;
   ssize_t ret;
   size_t have;
 
@@ -1370,21 +1408,7 @@ transmit_ready (void *cls,
   GNUNET_assert (NULL != connection->write_task);
   connection->write_task = NULL;
   GNUNET_assert (NULL == connection->nth.timeout_task);
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-  {
-    if (NULL != connection->sock)
-      goto SCHEDULE_WRITE;      /* ignore shutdown, go again immediately */
-    LOG (GNUNET_ERROR_TYPE_DEBUG,
-         "Transmit to `%s' fails, shutdown happened (%p).\n",
-         GNUNET_a2s (connection->addr, connection->addrlen), connection);
-    notify = connection->nth.notify_ready;
-    if (NULL != notify)
-    {
-      connection->nth.notify_ready = NULL;
-      notify (connection->nth.notify_ready_cls, 0, NULL);
-    }
-    return;
-  }
+  tc = GNUNET_SCHEDULER_get_task_context ();
   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1406,7 +1430,8 @@ transmit_ready (void *cls,
      * Hence retry.  */
     goto SCHEDULE_WRITE;
   }
-  if (!GNUNET_NETWORK_fdset_isset (tc->write_ready, connection->sock))
+  if (! GNUNET_NETWORK_fdset_isset (tc->write_ready,
+                                   connection->sock))
   {
     GNUNET_assert (NULL == connection->write_task);
     /* special circumstances (in particular, shutdown): not yet ready
@@ -1450,7 +1475,11 @@ RETRY:
   }
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Connection transmitted %u/%u bytes to `%s' (%p)\n",
-       (unsigned int) ret, have, GNUNET_a2s (connection->addr, connection->addrlen), connection);
+       (unsigned int) ret,
+       have,
+       GNUNET_a2s (connection->addr,
+                  connection->addrlen),
+       connection);
   connection->write_buffer_pos += ret;
   if (connection->write_buffer_pos == connection->write_buffer_off)
   {
@@ -1458,21 +1487,25 @@ RETRY:
     connection->write_buffer_pos = 0;
     connection->write_buffer_off = 0;
   }
-  if ((0 == connection->write_buffer_off) && (NULL == connection->nth.notify_ready))
+  if ( (0 == connection->write_buffer_off) &&
+       (NULL == connection->nth.notify_ready) )
     return;                     /* all data sent! */
   /* not done writing, schedule more */
 SCHEDULE_WRITE:
   LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Re-scheduling transmit_ready (more to do) (%p).\n", connection);
+       "Re-scheduling transmit_ready (more to do) (%p).\n",
+       connection);
   have = connection->write_buffer_off - connection->write_buffer_pos;
-  GNUNET_assert ((NULL != connection->nth.notify_ready) || (have > 0));
+  GNUNET_assert ( (NULL != connection->nth.notify_ready) ||
+                 (have > 0) );
   if (NULL == connection->write_task)
     connection->write_task =
         GNUNET_SCHEDULER_add_write_net ((connection->nth.notify_ready ==
                                          NULL) ? GNUNET_TIME_UNIT_FOREVER_REL :
                                         GNUNET_TIME_absolute_get_remaining
                                         (connection->nth.transmit_timeout),
-                                        connection->sock, &transmit_ready, connection);
+                                        connection->sock,
+                                       &transmit_ready, connection);
 }
 
 
@@ -1494,8 +1527,8 @@ struct GNUNET_CONNECTION_TransmitHandle *
 GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connection,
                                          size_t size,
                                          struct GNUNET_TIME_Relative timeout,
-                                         GNUNET_CONNECTION_TransmitReadyNotify
-                                         notify, void *notify_cls)
+                                         GNUNET_CONNECTION_TransmitReadyNotify notify,
+                                        void *notify_cls)
 {
   if (NULL != connection->nth.notify_ready)
   {
@@ -1535,7 +1568,8 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connec
     connection->write_task =
         GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining
                                         (connection->nth.transmit_timeout),
-                                        connection->sock, &transmit_ready, connection);
+                                        connection->sock,
+                                       &transmit_ready, connection);
     return &connection->nth;
   }
   /* not yet connected, wait for connection */
@@ -1544,7 +1578,8 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connec
        connection);
   connection->nth.timeout_task =
     GNUNET_SCHEDULER_add_delayed (timeout,
-                                  &transmit_timeout, connection);
+                                  &transmit_timeout,
+                                 connection);
   return &connection->nth;
 }
 
@@ -1581,14 +1616,15 @@ GNUNET_CONNECTION_notify_transmit_ready_cancel (struct GNUNET_CONNECTION_Transmi
 struct GNUNET_CONNECTION_Handle *
 GNUNET_CONNECTION_create_proxied_from_handshake (struct GNUNET_CONNECTION_Handle *cph)
 {
-  struct GNUNET_CONNECTION_Handle * proxied = GNUNET_CONNECTION_create_from_existing(NULL);
+  struct GNUNET_CONNECTION_Handle *proxied = GNUNET_CONNECTION_create_from_existing (NULL);
+
   proxied->proxy_handshake = cph;
   return proxied;
 }
 
 
 /**
- * Activate proxied connection and destroy initial proxy handshake connection. 
+ * Activate proxied connection and destroy initial proxy handshake connection.
  * There must not be any pending requests for reading or writing to the
  * proxy hadshake connection at this time.
  *
@@ -1598,11 +1634,12 @@ void
 GNUNET_CONNECTION_acivate_proxied (struct GNUNET_CONNECTION_Handle *proxied)
 {
   struct GNUNET_CONNECTION_Handle *cph = proxied->proxy_handshake;
+
   GNUNET_assert (NULL != cph);
   GNUNET_assert (NULL == proxied->sock);
   GNUNET_assert (NULL != cph->sock);
-  proxied->sock=cph->sock;
-  cph->sock=NULL;
+  proxied->sock = cph->sock;
+  cph->sock = NULL;
   GNUNET_CONNECTION_destroy (cph);
   connect_success_continuation (proxied);
 }