Fix perf_crypto_rsa.c after various changes
[oweals/gnunet.git] / src / util / client.c
index f74b8b1616d96fa1d07b605d0ced96394d42ec1d..d00e8bbd0622110b2c89a6758f791b6e0fa2e6df 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2001-2013 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2001-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
@@ -29,6 +29,7 @@
 #include "platform.h"
 #include "gnunet_protocols.h"
 #include "gnunet_util_lib.h"
+#include "gnunet_socks.h"
 
 
 /**
@@ -339,6 +340,10 @@ do_connect (const char *service_name,
   char *hostname;
   unsigned long long port;
 
+  /* Never use a local source if a proxy is configured */
+  if (GNUNET_YES == GNUNET_SOCKS_check_service (service_name,cfg))
+    return GNUNET_SOCKS_do_connect (service_name,cfg);
+
   connection = NULL;
   if (0 == (attempt % 2))
   {
@@ -573,12 +578,10 @@ receive_helper (void *cls,
 /**
  * Continuation to call the receive callback.
  *
- * @param cls  our handle to the client connection
- * @param tc scheduler context
+ * @param cls our handle to the client connection
  */
 static void
-receive_task (void *cls,
-              const struct GNUNET_SCHEDULER_TaskContext *tc)
+receive_task (void *cls)
 {
   struct GNUNET_CLIENT_Connection *client = cls;
   GNUNET_CLIENT_MessageHandler handler = client->receiver_handler;
@@ -608,7 +611,8 @@ receive_task (void *cls,
   GNUNET_assert (GNUNET_YES == client->msg_complete);
   GNUNET_assert (client->received_pos >= msize);
   memcpy (msg, cmsg, msize);
-  memmove (client->received_buf, &client->received_buf[msize],
+  memmove (client->received_buf,
+          &client->received_buf[msize],
            client->received_pos - msize);
   client->received_pos -= msize;
   client->msg_complete = GNUNET_NO;
@@ -652,7 +656,8 @@ GNUNET_CLIENT_receive (struct GNUNET_CLIENT_Connection *client,
        (GNUNET_SYSERR == client->in_receive) )
   {
     GNUNET_assert (NULL == client->receive_task);
-    client->receive_task = GNUNET_SCHEDULER_add_now (&receive_task, client);
+    client->receive_task = GNUNET_SCHEDULER_add_now (&receive_task,
+                                                    client);
     return;
   }
   LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -700,7 +705,7 @@ struct GNUNET_CLIENT_TestHandle
   /**
    * ID of task used for asynchronous operations.
    */
-  struct GNUNET_SCHEDULER_Task * task;
+  struct GNUNET_SCHEDULER_Task *task;
 
   /**
    * Final result to report back (once known).
@@ -741,11 +746,9 @@ GNUNET_CLIENT_service_test_cancel (struct GNUNET_CLIENT_TestHandle *th)
  * and then cleans up.
  *
  * @param cls the `struct GNUNET_CLIENT_TestHandle`
- * @param tc scheduler context
  */
 static void
-report_result (void *cls,
-              const struct GNUNET_SCHEDULER_TaskContext *tc)
+report_result (void *cls)
 {
   struct GNUNET_CLIENT_TestHandle *th = cls;
 
@@ -1075,24 +1078,14 @@ client_notify (void *cls, size_t size, void *buf);
  * service after a while.
  *
  * @param cls our `struct GNUNET_CLIENT_TransmitHandle` of the request
- * @param tc unused
  */
 static void
-client_delayed_retry (void *cls,
-                     const struct GNUNET_SCHEDULER_TaskContext *tc)
+client_delayed_retry (void *cls)
 {
   struct GNUNET_CLIENT_TransmitHandle *th = cls;
   struct GNUNET_TIME_Relative delay;
 
   th->reconnect_task = NULL;
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-  {
-    /* give up, was shutdown */
-    th->client->th = NULL;
-    th->notify (th->notify_cls, 0, NULL);
-    GNUNET_free (th);
-    return;
-  }
   th->client->connection =
     do_connect (th->client->service_name,
                th->client->cfg,
@@ -1111,13 +1104,16 @@ client_delayed_retry (void *cls,
     GNUNET_assert (NULL == th->th);
     GNUNET_assert (NULL == th->reconnect_task);
     th->reconnect_task =
-        GNUNET_SCHEDULER_add_delayed (delay, &client_delayed_retry, th);
+        GNUNET_SCHEDULER_add_delayed (delay,
+                                     &client_delayed_retry,
+                                     th);
     return;
   }
   th->th =
       GNUNET_CONNECTION_notify_transmit_ready (th->client->connection, th->size,
                                                GNUNET_TIME_absolute_get_remaining
-                                               (th->timeout), &client_notify,
+                                               (th->timeout),
+                                              &client_notify,
                                                th);
   if (NULL == th->th)
   {
@@ -1159,8 +1155,7 @@ client_notify (void *cls,
     delay.rel_value_us /= 2;
     if ( (GNUNET_YES != th->auto_retry) ||
          (0 == --th->attempts_left) ||
-         (delay.rel_value_us < 1)||
-         (0 != (GNUNET_SCHEDULER_get_reason() & GNUNET_SCHEDULER_REASON_SHUTDOWN)))
+         (delay.rel_value_us < 1) )
     {
       LOG (GNUNET_ERROR_TYPE_DEBUG,
            "Transmission failed %u times, giving up.\n",
@@ -1194,7 +1189,9 @@ client_notify (void *cls,
     GNUNET_assert (NULL == th->reconnect_task);
     GNUNET_assert (NULL == th->th);
     th->reconnect_task =
-        GNUNET_SCHEDULER_add_delayed (delay, &client_delayed_retry, th);
+        GNUNET_SCHEDULER_add_delayed (delay,
+                                     &client_delayed_retry,
+                                     th);
     return 0;
   }
   GNUNET_assert (size >= th->size);