Removing all the tests for the bluetooth transport plugin.
[oweals/gnunet.git] / src / transport / gnunet-service-transport_blacklist.c
index 3f9616e9174b72240ec910a47eda67fad8588177..2bec6cb710c775c0dc3ff4fe47b217584df22b84 100644 (file)
 /**
  * @file transport/gnunet-service-transport_blacklist.c
  * @brief blacklisting implementation
- * @author Christian Grothoff
+ * @author Christian Grothoff, 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
+ * the configuration or a blacklist client can be asked.
+ *
+ * To blacklist peers using the configuration you have to add a section to your
+ * configuration containing the peer id of the peer to blacklist and the plugin
+ * if required.
+ *
+ * Example:
+ * To blacklist connections to P565... on peer AG2P... using tcp add:
+ * [transport-blacklist-AG2PHES1BARB9IJCPAMJTFPVJ5V3A72S3F2A8SBUB8DAQ2V0O3V8G6G2JU56FHGFOHMQVKBSQFV98TCGTC3RJ1NINP82G0RC00N1520]
+ * P565723JO1C2HSN6J29TAQ22MN6CI8HTMUU55T0FUQG4CMDGGEQ8UCNBKUMB94GC8R9G4FB2SF9LDOBAJ6AMINBP4JHHDD6L7VD801G = tcp
+ *
+ * To blacklist connections to P565... on peer AG2P... using all plugins add:
+ * [transport-blacklist-AG2PHES1BARB9IJCPAMJTFPVJ5V3A72S3F2A8SBUB8DAQ2V0O3V8G6G2JU56FHGFOHMQVKBSQFV98TCGTC3RJ1NINP82G0RC00N1520]
+ * P565723JO1C2HSN6J29TAQ22MN6CI8HTMUU55T0FUQG4CMDGGEQ8UCNBKUMB94GC8R9G4FB2SF9LDOBAJ6AMINBP4JHHDD6L7VD801G =
+ *
+ * You can also add a blacklist client usign the blacklist api. On a blacklist
+ * check, blacklisting first checks internally if the peer is blacklisted and
+ * if not, it asks the blacklisting clients. Clients are asked if it is OK to
+ * connect to a peer ID, the plugin is omitted.
+ *
+ * On blacklist check for (peer, plugin)
+ * - Do we have a local blacklist entry for this peer and this plugin?
+ *   - YES: disallow connection
+ * - Do we have a local blacklist entry for this peer and all plugins?
+ *   - YES: disallow connection
+ * - Does one of the clients disallow?
+ *   - YES: disallow connection
+ *
  */
 #include "platform.h"
 #include "gnunet-service-transport.h"
@@ -29,7 +60,6 @@
 #include "gnunet-service-transport_neighbours.h"
 #include "transport.h"
 
-
 /**
  * Size of the blacklist hash map.
  */
@@ -568,7 +598,6 @@ GST_blacklist_handle_reply (void *cls, struct GNUNET_SERVER_Client *client,
     }
   }
   /* check if any other bc's are waiting for this blacklister */
-  bc = bc_head;
   for (bc = bc_head; bc != NULL; bc = bc->next)
     if ((bc->bl_pos == bl) && (GNUNET_SCHEDULER_NO_TASK == bc->task))
     {
@@ -589,16 +618,21 @@ GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer,
                         const char *transport_name)
 {
        char * transport = NULL;
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+       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)
     blacklist =
       GNUNET_CONTAINER_multihashmap_create (TRANSPORT_BLACKLIST_HT_SIZE,
                                            GNUNET_NO);
-  if (NULL != transport_name)
-       transport = GNUNET_strdup ("");
 
   GNUNET_CONTAINER_multihashmap_put (blacklist, &peer->hashPubKey,
                                      transport,
@@ -621,16 +655,30 @@ test_blacklisted (void *cls, const struct GNUNET_HashCode * key, void *value)
   const char *transport_name = cls;
   char *be = value;
 
-  /* blacklist check for specific no specific transport*/
-  if (transport_name == NULL)
-    return GNUNET_NO;
-  /* all plugins for this peer were blacklisted */
+  /* Blacklist entry be:
+   *  (NULL == be): peer is blacklisted with all plugins
+   *  (NULL != be): peer is blacklisted for a specific plugin
+   *
+   * If (NULL != transport_name) we look for a transport specific entry:
+   *  if (transport_name == be) forbidden
+   *
+   */
+
+  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);
+  /* all plugins for this peer were blacklisted: disallow */
   if (NULL == value)
-       return GNUNET_NO;
+               return GNUNET_NO;
 
   /* blacklist check for specific transport */
-  if (0 == strcmp (transport_name, be))
-    return GNUNET_NO;           /* abort iteration! */
+  if ((NULL != transport_name) && (NULL != value))
+  {
+       if (0 == strcmp (transport_name, be))
+                       return GNUNET_NO;           /* plugin is blacklisted! */
+  }
   return GNUNET_OK;
 }
 
@@ -653,17 +701,23 @@ GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer,
   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");
 
+  /* Check local blacklist by iterating over hashmap
+   * If iteration is aborted, we found a matching blacklist entry */
   if ((blacklist != NULL) &&
       (GNUNET_SYSERR ==
        GNUNET_CONTAINER_multihashmap_get_multiple (blacklist, &peer->hashPubKey,
                                                    &test_blacklisted,
                                                    (void *) transport_name)))
   {
-    /* disallowed by config, disapprove instantly */
+    /* Disallowed by config, disapprove instantly */
     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");
     if (cont != NULL)
       cont (cont_cls, peer, GNUNET_NO);
     return NULL;
@@ -674,6 +728,8 @@ GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer,
     /* 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 : "");
     return NULL;
   }