-bringing copyright tags up to FSF standard
[oweals/gnunet.git] / src / transport / gnunet-service-transport_blacklist.c
index 2bec6cb710c775c0dc3ff4fe47b217584df22b84..195e3439f4df162043faa488dd86f4aa03028926 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2010,2011 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2010,2011 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -21,7 +21,8 @@
 /**
  * @file transport/gnunet-service-transport_blacklist.c
  * @brief blacklisting implementation
- * @author Christian Grothoff, Matthias Wachs
+ * @author Christian Grothoff
+ * @author Matthias Wachs
  * @details This is the blacklisting component of transport service. With
  * blacklisting it is possible to deny connections to specific peers of
  * to use a specific plugin to a specific peer. Peers can be blacklisted using
@@ -100,10 +101,15 @@ struct Blacklisters
   struct GST_BlacklistCheck *bc;
 
   /**
-   * Set to GNUNET_YES if we're currently waiting for a reply.
+   * Set to #GNUNET_YES if we're currently waiting for a reply.
    */
   int waiting_for_reply;
 
+  /**
+   * #GNUNET_YES if we have to call receive_done for this client
+   */
+  int call_receive_done;
+
 };
 
 
@@ -135,7 +141,7 @@ struct GST_BlacklistCheck
   GST_BlacklistTestContinuation cont;
 
   /**
-   * Closure for cont.
+   * Closure for @e cont.
    */
   void *cont_cls;
 
@@ -153,7 +159,7 @@ struct GST_BlacklistCheck
   /**
    * Current task performing the check.
    */
-  GNUNET_SCHEDULER_TaskIdentifier task;
+  struct GNUNET_SCHEDULER_Task * task;
 
 };
 
@@ -182,13 +188,13 @@ static struct Blacklisters *bl_tail;
  * Hashmap of blacklisted peers.  Values are of type 'char *' (transport names),
  * can be NULL if we have no static blacklist.
  */
-static struct GNUNET_CONTAINER_MultiHashMap *blacklist;
+static struct GNUNET_CONTAINER_MultiPeerMap *blacklist;
 
 
 /**
  * Perform next action in the blacklist check.
  *
- * @param cls the 'struct BlacklistCheck*'
+ * @param cls the `struct BlacklistCheck*`
  * @param tc unused
  */
 static void
@@ -208,7 +214,7 @@ client_disconnect_notification (void *cls, struct GNUNET_SERVER_Client *client)
   struct Blacklisters *bl;
   struct GST_BlacklistCheck *bc;
 
-  if (client == NULL)
+  if (NULL == client)
     return;
   for (bl = bl_head; bl != NULL; bl = bl->next)
   {
@@ -224,9 +230,8 @@ client_disconnect_notification (void *cls, struct GNUNET_SERVER_Client *client)
         GNUNET_SERVER_notify_transmit_ready_cancel (bc->th);
         bc->th = NULL;
       }
-      if (bc->task == GNUNET_SCHEDULER_NO_TASK)
+      if (bc->task == NULL)
         bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
-      break;
     }
     GNUNET_CONTAINER_DLL_remove (bl_head, bl_tail, bl);
     GNUNET_SERVER_client_drop (bl->client);
@@ -244,8 +249,9 @@ client_disconnect_notification (void *cls, struct GNUNET_SERVER_Client *client)
  * @param option name of the option
  * @param value value of the option
  */
-static void 
-blacklist_cfg_iter (void *cls, const char *section,
+static void
+blacklist_cfg_iter (void *cls,
+                    const char *section,
                    const char *option,
                    const char *value)
 {
@@ -254,17 +260,19 @@ blacklist_cfg_iter (void *cls, const char *section,
   char *plugs;
   char *pos;
 
-  if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string2 (option,
-                                                   strlen (option), 
-                                                   &peer.hashPubKey))
+  if (GNUNET_OK !=
+      GNUNET_CRYPTO_eddsa_public_key_from_string (option,
+                                                  strlen (option),
+                                                  &peer.public_key))
     return;
-  
+
   if ((NULL == value) || (0 == strcmp(value, "")))
   {
     /* Blacklist whole peer */
     GST_blacklist_add_peer (&peer, NULL);
     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-               _("Adding blacklisting entry for peer `%s'\n"), GNUNET_i2s (&peer));
+               _("Adding blacklisting entry for peer `%s'\n"),
+                GNUNET_i2s (&peer));
   }
   else
   {
@@ -295,13 +303,17 @@ read_blacklist_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg,
   char cfg_sect[512];
   unsigned int res = 0;
 
-  GNUNET_snprintf (cfg_sect, 
+  GNUNET_snprintf (cfg_sect,
                   sizeof (cfg_sect),
-                  "transport-blacklist-%s", 
+                  "transport-blacklist-%s",
                   GNUNET_i2s_full (my_id));
-  GNUNET_CONFIGURATION_iterate_section_values (cfg, cfg_sect, &blacklist_cfg_iter, &res);
+  GNUNET_CONFIGURATION_iterate_section_values (cfg,
+                                               cfg_sect,
+                                               &blacklist_cfg_iter,
+                                               &res);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Loaded %u blacklisting entries from configuration\n", res);
+              "Loaded %u blacklisting entries from configuration\n",
+              res);
 }
 
 
@@ -320,7 +332,8 @@ GST_blacklist_start (struct GNUNET_SERVER_Handle *server,
   GNUNET_assert (NULL != cfg);
   GNUNET_assert (NULL != my_id);
   read_blacklist_configuration (cfg, my_id);
-  GNUNET_SERVER_disconnect_notify (server, &client_disconnect_notification,
+  GNUNET_SERVER_disconnect_notify (server,
+                                   &client_disconnect_notification,
                                    NULL);
 }
 
@@ -331,10 +344,12 @@ GST_blacklist_start (struct GNUNET_SERVER_Handle *server,
  * @param cls unused
  * @param key host identity (unused)
  * @param value the blacklist entry
- * @return GNUNET_OK (continue to iterate)
+ * @return #GNUNET_OK (continue to iterate)
  */
 static int
-free_blacklist_entry (void *cls, const struct GNUNET_HashCode * key, void *value)
+free_blacklist_entry (void *cls,
+                     const struct GNUNET_PeerIdentity *key,
+                     void *value)
 {
   char *be = value;
 
@@ -349,23 +364,23 @@ free_blacklist_entry (void *cls, const struct GNUNET_HashCode * key, void *value
 void
 GST_blacklist_stop ()
 {
-  if (NULL != blacklist)
-  {
-    GNUNET_CONTAINER_multihashmap_iterate (blacklist, &free_blacklist_entry,
-                                           NULL);
-    GNUNET_CONTAINER_multihashmap_destroy (blacklist);
-    blacklist = NULL;
-  }
+  if (NULL == blacklist)
+    return;
+  GNUNET_CONTAINER_multipeermap_iterate (blacklist,
+                                         &free_blacklist_entry,
+                                         NULL);
+  GNUNET_CONTAINER_multipeermap_destroy (blacklist);
+  blacklist = NULL;
 }
 
 
 /**
  * Transmit blacklist query to the client.
  *
- * @param cls the 'struct GST_BlacklistCheck'
+ * @param cls the `struct GST_BlacklistCheck`
  * @param size number of bytes allowed
  * @param buf where to copy the message
- * @return number of bytes copied to buf
+ * @return number of bytes copied to @a buf
  */
 static size_t
 transmit_blacklist_message (void *cls, size_t size, void *buf)
@@ -377,7 +392,7 @@ transmit_blacklist_message (void *cls, size_t size, void *buf)
   bc->th = NULL;
   if (size == 0)
   {
-    GNUNET_assert (bc->task == GNUNET_SCHEDULER_NO_TASK);
+    GNUNET_assert (bc->task == NULL);
     bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                 "Failed to send blacklist test for peer `%s' to client\n",
@@ -385,15 +400,20 @@ transmit_blacklist_message (void *cls, size_t size, void *buf)
     return 0;
   }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Sending blacklist test for peer `%s' to client\n",
-              GNUNET_i2s (&bc->peer));
+              "Sending blacklist test for peer `%s' to client %p\n",
+              GNUNET_i2s (&bc->peer), bc->bl_pos->client);
   bl = bc->bl_pos;
   bm.header.size = htons (sizeof (struct BlacklistMessage));
   bm.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY);
   bm.is_allowed = htonl (0);
   bm.peer = bc->peer;
   memcpy (buf, &bm, sizeof (bm));
-  GNUNET_SERVER_receive_done (bl->client, GNUNET_OK);
+  if (GNUNET_YES == bl->call_receive_done)
+  {
+    GNUNET_SERVER_receive_done (bl->client, GNUNET_OK);
+    bl->call_receive_done = GNUNET_NO;
+  }
+
   bl->waiting_for_reply = GNUNET_YES;
   return sizeof (bm);
 }
@@ -402,22 +422,24 @@ transmit_blacklist_message (void *cls, size_t size, void *buf)
 /**
  * Perform next action in the blacklist check.
  *
- * @param cls the 'struct GST_BlacklistCheck*'
+ * @param cls the `struct GST_BlacklistCheck *`
  * @param tc unused
  */
 static void
-do_blacklist_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_blacklist_check (void *cls,
+                    const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct GST_BlacklistCheck *bc = cls;
   struct Blacklisters *bl;
 
-  bc->task = GNUNET_SCHEDULER_NO_TASK;
+  bc->task = NULL;
   bl = bc->bl_pos;
   if (bl == NULL)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "No other blacklist clients active, will allow neighbour `%s'\n",
                 GNUNET_i2s (&bc->peer));
+
     bc->cont (bc->cont_cls, &bc->peer, GNUNET_OK);
     GNUNET_CONTAINER_DLL_remove(bc_head, bc_tail, bc);
     GNUNET_free (bc);
@@ -440,11 +462,12 @@ do_blacklist_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  *
  * @param cls unused
  * @param peer the neighbour that was investigated
- * @param allowed GNUNET_OK if we can keep it,
- *                GNUNET_NO if we must shutdown the connection
+ * @param allowed #GNUNET_OK if we can keep it,
+ *                #GNUNET_NO if we must shutdown the connection
  */
 static void
-confirm_or_drop_neighbour (void *cls, const struct GNUNET_PeerIdentity *peer,
+confirm_or_drop_neighbour (void *cls,
+                           const struct GNUNET_PeerIdentity *peer,
                            int allowed)
 {
   if (GNUNET_OK == allowed)
@@ -477,24 +500,31 @@ struct TestConnectionContext
  * Test if an existing connection is still acceptable given a new
  * blacklisting client.
  *
- * @param cls the 'struct TestConnectionContest'
- * @param neighbour neighbour's identity
+ * @param cls the `struct TestConnectionContext *`
+ * @param peer identity of the peer
  * @param address the address
- * @param bandwidth_in inbound quota in NBO
- * @param bandwidth_out outbound quota in NBO
+ * @param state current state this peer is in
+ * @param state_timeout timeout for the current state of the peer
+ * @param bandwidth_in bandwidth assigned inbound
+ * @param bandwidth_out bandwidth assigned outbound
  */
 static void
-test_connection_ok (void *cls, const struct GNUNET_PeerIdentity *neighbour,
-                    const struct GNUNET_HELLO_Address *address,
-                    struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
-                    struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
+test_connection_ok (void *cls,
+                    const struct GNUNET_PeerIdentity *peer,
+                   const struct GNUNET_HELLO_Address *address,
+                   enum GNUNET_TRANSPORT_PeerState state,
+                   struct GNUNET_TIME_Absolute state_timeout,
+                   struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
+                   struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
 {
   struct TestConnectionContext *tcc = cls;
   struct GST_BlacklistCheck *bc;
 
-  bc = GNUNET_malloc (sizeof (struct GST_BlacklistCheck));
-  GNUNET_CONTAINER_DLL_insert (bc_head, bc_tail, bc);
-  bc->peer = *neighbour;
+  bc = GNUNET_new (struct GST_BlacklistCheck);
+  GNUNET_CONTAINER_DLL_insert (bc_head,
+                              bc_tail,
+                              bc);
+  bc->peer = *peer;
   bc->cont = &confirm_or_drop_neighbour;
   bc->cont_cls = NULL;
   bc->bl_pos = tcc->bl;
@@ -524,22 +554,26 @@ GST_blacklist_handle_init (void *cls, struct GNUNET_SERVER_Client *client,
   struct Blacklisters *bl;
   struct TestConnectionContext tcc;
 
-  bl = bl_head;
-  while (bl != NULL)
-  {
+  for (bl = bl_head; NULL != bl; bl = bl->next)
     if (bl->client == client)
     {
       GNUNET_break (0);
       GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
       return;
     }
-    bl = bl->next;
-  }
+
   GNUNET_SERVER_client_mark_monitor (client);
-  bl = GNUNET_malloc (sizeof (struct Blacklisters));
+  bl = GNUNET_new (struct Blacklisters);
   bl->client = client;
+  bl->call_receive_done = GNUNET_YES;
   GNUNET_SERVER_client_keep (client);
-  GNUNET_CONTAINER_DLL_insert_after (bl_head, bl_tail, bl_tail, bl);
+  GNUNET_CONTAINER_DLL_insert_after (bl_head,
+                                     bl_tail,
+                                     bl_tail,
+                                     bl);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "New blacklist client %p\n",
+              client);
 
   /* confirm that all existing connections are OK! */
   tcc.bl = bl;
@@ -567,16 +601,23 @@ GST_blacklist_handle_reply (void *cls, struct GNUNET_SERVER_Client *client,
   bl = bl_head;
   while ((bl != NULL) && (bl->client != client))
     bl = bl->next;
-  if (bl == NULL)
+  if (NULL == bl)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Blacklist client disconnected\n");
-    /* FIXME: other error handling here!? */
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Blacklist client disconnected\n");
     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
     return;
   }
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Blacklist client %p sent reply for `%s'\n",
+              client,
+              GNUNET_i2s(&msg->peer));
+
   bc = bl->bc;
   bl->bc = NULL;
   bl->waiting_for_reply = GNUNET_NO;
+  bl->call_receive_done = GNUNET_YES; /* Remember to call receive_done */
   if (NULL != bc)
   {
     /* only run this if the blacklist check has not been
@@ -587,19 +628,24 @@ GST_blacklist_handle_reply (void *cls, struct GNUNET_SERVER_Client *client,
                   "Blacklist check failed, peer not allowed\n");
       bc->cont (bc->cont_cls, &bc->peer, GNUNET_NO);
       GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, bc);
+      GNUNET_SERVER_receive_done (bl->client, GNUNET_OK);
+      bl->call_receive_done = GNUNET_NO;
       GNUNET_free (bc);
+      return;
     }
     else
     {
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   "Blacklist check succeeded, continuing with checks\n");
+      GNUNET_SERVER_receive_done (bl->client, GNUNET_OK);
+      bl->call_receive_done = GNUNET_NO;
       bc->bl_pos = bc->bl_pos->next;
       bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
     }
   }
-  /* check if any other bc's are waiting for this blacklister */
+  /* check if any other blacklist checks are waiting for this blacklister */
   for (bc = bc_head; bc != NULL; bc = bc->next)
-    if ((bc->bl_pos == bl) && (GNUNET_SCHEDULER_NO_TASK == bc->task))
+    if ((bc->bl_pos == bl) && (NULL == bc->task))
     {
       bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
       break;
@@ -617,24 +663,25 @@ void
 GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer,
                         const char *transport_name)
 {
-       char * transport = NULL;
-       if (NULL != transport_name)
-       {
-                       GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              "Adding peer `%s' with plugin `%s' to blacklist\n",
-              GNUNET_i2s (peer), transport_name);
-                       transport = GNUNET_strdup (transport_name);
-       }
-       else
-               GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-            "Adding peer `%s' with all plugins to blacklist\n",
-            GNUNET_i2s (peer));
-  if (blacklist == NULL)
+  char *transport = NULL;
+
+  if (NULL != transport_name)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+               "Adding peer `%s' with plugin `%s' to blacklist\n",
+               GNUNET_i2s (peer), transport_name);
+    transport = GNUNET_strdup (transport_name);
+  }
+  else
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+               "Adding peer `%s' with all plugins to blacklist\n",
+               GNUNET_i2s (peer));
+  if (NULL == blacklist)
     blacklist =
-      GNUNET_CONTAINER_multihashmap_create (TRANSPORT_BLACKLIST_HT_SIZE,
+      GNUNET_CONTAINER_multipeermap_create (TRANSPORT_BLACKLIST_HT_SIZE,
                                            GNUNET_NO);
 
-  GNUNET_CONTAINER_multihashmap_put (blacklist, &peer->hashPubKey,
+  GNUNET_CONTAINER_multipeermap_put (blacklist, peer,
                                      transport,
                                      GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
 }
@@ -647,10 +694,12 @@ GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer,
  * @param cls the transport name to match (const char*)
  * @param key the key (unused)
  * @param value the 'char *' (name of a blacklisted transport)
- * @return GNUNET_OK if the entry does not match, GNUNET_NO if it matches
+ * @return #GNUNET_OK if the entry does not match, #GNUNET_NO if it matches
  */
 static int
-test_blacklisted (void *cls, const struct GNUNET_HashCode * key, void *value)
+test_blacklisted (void *cls,
+                 const struct GNUNET_PeerIdentity *key,
+                 void *value)
 {
   const char *transport_name = cls;
   char *be = value;
@@ -665,10 +714,10 @@ test_blacklisted (void *cls, const struct GNUNET_HashCode * key, void *value)
    */
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                                               "Comparing BL request for peer `%4s':`%s' with BL entry: `%s'\n",
-               GNUNET_h2s (key),
-               (NULL == transport_name) ? "unspecified" : transport_name,
-               (NULL == be) ? "all plugins" : be);
+             "Comparing BL request for peer `%4s':`%s' with BL entry: `%s'\n",
+             GNUNET_i2s (key),
+             (NULL == transport_name) ? "unspecified" : transport_name,
+             (NULL == be) ? "all plugins" : be);
   /* all plugins for this peer were blacklisted: disallow */
   if (NULL == value)
                return GNUNET_NO;
@@ -689,26 +738,29 @@ test_blacklisted (void *cls, const struct GNUNET_HashCode * key, void *value)
  * @param peer the identity of the peer to test
  * @param transport_name name of the transport to test, never NULL
  * @param cont function to call with result
- * @param cont_cls closure for 'cont'
+ * @param cont_cls closure for @a cont
  * @return handle to the blacklist check, NULL if the decision
- *        was made instantly and 'cont' was already called
+ *        was made instantly and @a cont was already called
  */
 struct GST_BlacklistCheck *
 GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer,
                             const char *transport_name,
-                            GST_BlacklistTestContinuation cont, void *cont_cls)
+                            GST_BlacklistTestContinuation cont,
+                            void *cont_cls)
 {
   struct GST_BlacklistCheck *bc;
 
-  GNUNET_assert (peer != NULL);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Blacklist check for peer `%s':%s\n",
-               GNUNET_i2s (peer), (NULL != transport_name) ? transport_name : "unspecified");
+  GNUNET_assert (NULL != peer);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Blacklist check for peer `%s':%s\n",
+              GNUNET_i2s (peer),
+              (NULL != transport_name) ? transport_name : "unspecified");
 
   /* Check local blacklist by iterating over hashmap
    * If iteration is aborted, we found a matching blacklist entry */
-  if ((blacklist != NULL) &&
+  if ((NULL != blacklist) &&
       (GNUNET_SYSERR ==
-       GNUNET_CONTAINER_multihashmap_get_multiple (blacklist, &peer->hashPubKey,
+       GNUNET_CONTAINER_multipeermap_get_multiple (blacklist, peer,
                                                    &test_blacklisted,
                                                    (void *) transport_name)))
   {
@@ -716,25 +768,29 @@ GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer,
     GNUNET_STATISTICS_update (GST_stats,
                               gettext_noop ("# disconnects due to blacklist"),
                               1, GNUNET_NO);
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Disallowing connection to peer `%s' on transport %s\n",
-               GNUNET_i2s (peer), (NULL != transport_name) ? transport_name : "unspecified");
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                _("Disallowing connection to peer `%s' on transport %s\n"),
+               GNUNET_i2s (peer),
+                (NULL != transport_name) ? transport_name : "unspecified");
     if (cont != NULL)
       cont (cont_cls, peer, GNUNET_NO);
     return NULL;
   }
 
-  if (bl_head == NULL)
+  if (NULL == bl_head)
   {
     /* no blacklist clients, approve instantly */
     if (cont != NULL)
       cont (cont_cls, peer, GNUNET_OK);
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Allowing connection to peer `%s' %s\n",
-               GNUNET_i2s (peer), (NULL != transport_name) ? transport_name : "");
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Allowing connection to peer `%s' %s\n",
+               GNUNET_i2s (peer),
+                (NULL != transport_name) ? transport_name : "");
     return NULL;
   }
 
   /* need to query blacklist clients */
-  bc = GNUNET_malloc (sizeof (struct GST_BlacklistCheck));
+  bc = GNUNET_new (struct GST_BlacklistCheck);
   GNUNET_CONTAINER_DLL_insert (bc_head, bc_tail, bc);
   bc->peer = *peer;
   bc->cont = cont;
@@ -753,8 +809,10 @@ GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer,
 void
 GST_blacklist_test_cancel (struct GST_BlacklistCheck *bc)
 {
-  GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, bc);
-  if (bc->bl_pos != NULL)
+  GNUNET_CONTAINER_DLL_remove (bc_head,
+                               bc_tail,
+                               bc);
+  if (NULL != bc->bl_pos)
   {
     if (bc->bl_pos->bc == bc)
     {
@@ -762,10 +820,10 @@ GST_blacklist_test_cancel (struct GST_BlacklistCheck *bc)
       bc->bl_pos->bc = NULL;
     }
   }
-  if (GNUNET_SCHEDULER_NO_TASK != bc->task)
+  if (NULL != bc->task)
   {
     GNUNET_SCHEDULER_cancel (bc->task);
-    bc->task = GNUNET_SCHEDULER_NO_TASK;
+    bc->task = NULL;
   }
   if (NULL != bc->th)
   {