-only trigger check config if we actually need it
[oweals/gnunet.git] / src / fs / gnunet-service-fs_lc.c
index ef30ba32a03e78e5258a9a0a616cb5ba7f48a85d..e61442aa3664a100be87b1db1987e6769e341cfc 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2011 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2011 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
 
      You should have received a copy of the GNU General Public License
      along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
 */
-
 /**
  * @file fs/gnunet-service-fs_lc.c
  * @brief API to handle 'local clients'
  * @author Christian Grothoff
  */
-
 #include "platform.h"
 #include "gnunet-service-fs.h"
 #include "gnunet-service-fs_lc.h"
@@ -61,7 +59,7 @@ struct ClientRequest
   /**
    * Task scheduled to destroy the request.
    */
-  GNUNET_SCHEDULER_TaskIdentifier kill_task;
+  struct GNUNET_SCHEDULER_Task * kill_task;
 
 };
 
@@ -150,7 +148,6 @@ struct GSF_LocalClient
  */
 static struct GSF_LocalClient *client_head;
 
-
 /**
  * Head of linked list of our local clients.
  */
@@ -176,7 +173,9 @@ GSF_local_client_lookup_ (struct GNUNET_SERVER_Client *client)
     return pos;
   pos = GNUNET_new (struct GSF_LocalClient);
   pos->client = client;
-  GNUNET_CONTAINER_DLL_insert (client_head, client_tail, pos);
+  GNUNET_CONTAINER_DLL_insert (client_head,
+                               client_tail,
+                               pos);
   return pos;
 }
 
@@ -185,21 +184,23 @@ GSF_local_client_lookup_ (struct GNUNET_SERVER_Client *client)
  * Free the given client request.
  *
  * @param cls the client request to free
- * @param tc task context
  */
 static void
-client_request_destroy (void *cls,
-                        const struct GNUNET_SCHEDULER_TaskContext *tc)
+client_request_destroy (void *cls)
 {
   struct ClientRequest *cr = cls;
   struct GSF_LocalClient *lc;
 
-  cr->kill_task = GNUNET_SCHEDULER_NO_TASK;
+  cr->kill_task = NULL;
   lc = cr->lc;
-  GNUNET_CONTAINER_DLL_remove (lc->cr_head, lc->cr_tail, cr);
-  GSF_pending_request_cancel_ (cr->pr, GNUNET_YES);
+  GNUNET_CONTAINER_DLL_remove (lc->cr_head,
+                               lc->cr_tail,
+                               cr);
+  GSF_pending_request_cancel_ (cr->pr,
+                               GNUNET_YES);
   GNUNET_STATISTICS_update (GSF_stats,
-                            gettext_noop ("# client searches active"), -1,
+                            gettext_noop ("# client searches active"),
+                            -1,
                             GNUNET_NO);
   GNUNET_free (cr);
 }
@@ -209,7 +210,7 @@ client_request_destroy (void *cls,
  * Handle a reply to a pending request.  Also called if a request
  * expires (then with data == NULL).  The handler may be called
  * many times (depending on the request type), but will not be
- * called during or after a call to GSF_pending_request_cancel
+ * called during or after a call to #GSF_pending_request_cancel()
  * and will also not be called anymore after a call signalling
  * expiration.
  *
@@ -217,19 +218,21 @@ client_request_destroy (void *cls,
  * @param eval evaluation of the result
  * @param pr handle to the original pending request
  * @param reply_anonymity_level anonymity level for the reply, UINT32_MAX for "unknown"
- * @param expiration when does 'data' expire?
+ * @param expiration when does @a data expire?
  * @param last_transmission when was the last time we've tried to download this block? (FOREVER if unknown)
  * @param type type of the block
  * @param data response data, NULL on request expiration
- * @param data_len number of bytes in @e data
+ * @param data_len number of bytes in @a data
  */
 static void
-client_response_handler (void *cls, enum GNUNET_BLOCK_EvaluationResult eval,
+client_response_handler (void *cls,
+                         enum GNUNET_BLOCK_EvaluationResult eval,
                          struct GSF_PendingRequest *pr,
                          uint32_t reply_anonymity_level,
                          struct GNUNET_TIME_Absolute expiration,
                          struct GNUNET_TIME_Absolute last_transmission,
-                         enum GNUNET_BLOCK_Type type, const void *data,
+                         enum GNUNET_BLOCK_Type type,
+                         const void *data,
                          size_t data_len)
 {
   struct ClientRequest *cr = cls;
@@ -241,7 +244,7 @@ client_response_handler (void *cls, enum GNUNET_BLOCK_EvaluationResult eval,
   if (NULL == data)
   {
     /* local-only request, with no result, clean up. */
-    if (GNUNET_SCHEDULER_NO_TASK == cr->kill_task)
+    if (NULL == cr->kill_task)
       cr->kill_task = GNUNET_SCHEDULER_add_now (&client_request_destroy,
                                                 cr);
     return;
@@ -276,7 +279,7 @@ client_response_handler (void *cls, enum GNUNET_BLOCK_EvaluationResult eval,
   }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Queued reply to query `%s' for local client\n",
-              GNUNET_h2s (&prd->query), (unsigned int) prd->type);
+              GNUNET_h2s (&prd->query));
   if (GNUNET_BLOCK_EVALUATION_OK_LAST != eval)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -284,7 +287,7 @@ client_response_handler (void *cls, enum GNUNET_BLOCK_EvaluationResult eval,
                (int) eval);
     return;
   }
-  if (GNUNET_SCHEDULER_NO_TASK == cr->kill_task)
+  if (NULL == cr->kill_task)
     cr->kill_task = GNUNET_SCHEDULER_add_now (&client_request_destroy, cr);
 }
 
@@ -326,7 +329,8 @@ GSF_local_client_start_search_handler_ (struct GNUNET_SERVER_Client *client,
     return GNUNET_SYSERR;
   }
   GNUNET_STATISTICS_update (GSF_stats,
-                            gettext_noop ("# client searches received"), 1,
+                            gettext_noop ("# client searches received"),
+                            1,
                             GNUNET_NO);
   sc = (msize - sizeof (struct SearchMessage)) / sizeof (struct GNUNET_HashCode);
   sm = (const struct SearchMessage *) message;
@@ -348,7 +352,9 @@ GSF_local_client_start_search_handler_ (struct GNUNET_SERVER_Client *client,
         (SEARCH_MESSAGE_OPTION_CONTINUED was always set) and that have a
         matching query and type */
       if ((GNUNET_YES != prd->has_started) &&
-         (0 != memcmp (&prd->query, &sm->query, sizeof (struct GNUNET_HashCode))) &&
+         (0 != memcmp (&prd->query,
+                        &sm->query,
+                        sizeof (struct GNUNET_HashCode))) &&
           (prd->type == type))
         break;
       cr = cr->next;
@@ -358,7 +364,9 @@ GSF_local_client_start_search_handler_ (struct GNUNET_SERVER_Client *client,
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Have existing request, merging content-seen lists.\n");
-    GSF_pending_request_update_ (cr->pr, (const struct GNUNET_HashCode *) &sm[1], sc);
+    GSF_pending_request_update_ (cr->pr,
+                                 (const struct GNUNET_HashCode *) &sm[1],
+                                 sc);
     GNUNET_STATISTICS_update (GSF_stats,
                               gettext_noop
                               ("# client searches updated (merged content seen list)"),
@@ -371,7 +379,9 @@ GSF_local_client_start_search_handler_ (struct GNUNET_SERVER_Client *client,
                               GNUNET_NO);
     cr = GNUNET_new (struct ClientRequest);
     cr->lc = lc;
-    GNUNET_CONTAINER_DLL_insert (lc->cr_head, lc->cr_tail, cr);
+    GNUNET_CONTAINER_DLL_insert (lc->cr_head,
+                                 lc->cr_tail,
+                                 cr);
     options = GSF_PRO_LOCAL_REQUEST;
     if (0 != (SEARCH_MESSAGE_OPTION_LOOPBACK_ONLY & ntohl (sm->options)))
       options |= GSF_PRO_LOCAL_ONLY;
@@ -405,13 +415,15 @@ GSF_local_client_start_search_handler_ (struct GNUNET_SERVER_Client *client,
  * If we were able to transmit messages and there are still more
  * pending, ask core again for further calls to this function.
  *
- * @param cls closure, pointer to the 'struct GSF_LocalClient'
- * @param size number of bytes available in buf
+ * @param cls closure, pointer to the `struct GSF_LocalClient`
+ * @param size number of bytes available in @a buf
  * @param buf where the callee should write the message
- * @return number of bytes written to buf
+ * @return number of bytes written to @a buf
  */
 static size_t
-transmit_to_client (void *cls, size_t size, void *buf)
+transmit_to_client (void *cls,
+                    size_t size,
+                    void *buf)
 {
   struct GSF_LocalClient *lc = cls;
   char *cbuf = buf;
@@ -458,8 +470,12 @@ GSF_local_client_transmit_ (struct GSF_LocalClient *lc,
   res = GNUNET_malloc (sizeof (struct ClientResponse) + msize);
   res->lc = lc;
   res->msize = msize;
-  memcpy (&res[1], msg, msize);
-  GNUNET_CONTAINER_DLL_insert_tail (lc->res_head, lc->res_tail, res);
+  memcpy (&res[1],
+          msg,
+          msize);
+  GNUNET_CONTAINER_DLL_insert_tail (lc->res_head,
+                                    lc->res_tail,
+                                    res);
   if (NULL == lc->th)
     lc->th =
         GNUNET_SERVER_notify_transmit_ready (lc->client, msize,
@@ -476,7 +492,8 @@ GSF_local_client_transmit_ (struct GSF_LocalClient *lc,
  * @param client handle of the client
  */
 void
-GSF_client_disconnect_handler_ (void *cls, struct GNUNET_SERVER_Client *client)
+GSF_client_disconnect_handler_ (void *cls,
+                                struct GNUNET_SERVER_Client *client)
 {
   struct GSF_LocalClient *pos;
   struct ClientRequest *cr;
@@ -489,9 +506,9 @@ GSF_client_disconnect_handler_ (void *cls, struct GNUNET_SERVER_Client *client)
     return;
   while (NULL != (cr = pos->cr_head))
   {
-    if (GNUNET_SCHEDULER_NO_TASK != cr->kill_task)
+    if (NULL != cr->kill_task)
       GNUNET_SCHEDULER_cancel (cr->kill_task);
-    client_request_destroy (cr, NULL);
+    client_request_destroy (cr);
   }
   while (NULL != (res = pos->res_head))
   {