-makefile for new test_stream_local (commented)
[oweals/gnunet.git] / src / transport / gnunet-service-transport_blacklist.c
index 7720e467fac2401f7a448418316dc3a6a4e26668..10362681ca183f59f2b9485d1394d281b76729d9 100644 (file)
@@ -221,14 +221,13 @@ read_blacklist_file ()
   size_t colon_pos;
   int tsize;
   struct GNUNET_PeerIdentity pid;
-  struct stat frstat;
+  uint64_t fsize;
   struct GNUNET_CRYPTO_HashAsciiEncoded enc;
   unsigned int entries_found;
   char *transport_name;
 
   if (GNUNET_OK !=
-      GNUNET_CONFIGURATION_get_value_filename (GST_cfg,
-                                               "TRANSPORT",
+      GNUNET_CONFIGURATION_get_value_filename (GST_cfg, "TRANSPORT",
                                                "BLACKLIST_FILE", &fn))
   {
 #if DEBUG_TRANSPORT
@@ -242,26 +241,27 @@ read_blacklist_file ()
     GNUNET_DISK_fn_write (fn, NULL, 0,
                           GNUNET_DISK_PERM_USER_READ |
                           GNUNET_DISK_PERM_USER_WRITE);
-  if (0 != STAT (fn, &frstat))
+  if (GNUNET_OK != GNUNET_DISK_file_size (fn,
+      &fsize, GNUNET_NO, GNUNET_YES))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 _("Could not read blacklist file `%s'\n"), fn);
     GNUNET_free (fn);
     return;
   }
-  if (frstat.st_size == 0)
+  if (fsize == 0)
   {
 #if DEBUG_TRANSPORT
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                _("Blacklist file `%s' is empty.\n"), fn);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Blacklist file `%s' is empty.\n"),
+                fn);
 #endif
     GNUNET_free (fn);
     return;
   }
   /* FIXME: use mmap */
-  data = GNUNET_malloc_large (frstat.st_size);
+  data = GNUNET_malloc_large (fsize);
   GNUNET_assert (data != NULL);
-  if (frstat.st_size != GNUNET_DISK_fn_read (fn, data, frstat.st_size))
+  if (fsize != GNUNET_DISK_fn_read (fn, data, fsize))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 _("Failed to read blacklist from `%s'\n"), fn);
@@ -271,18 +271,17 @@ read_blacklist_file ()
   }
   entries_found = 0;
   pos = 0;
-  while ((pos < frstat.st_size) && isspace ((unsigned char) data[pos]))
+  while ((pos < fsize) && isspace ((unsigned char) data[pos]))
     pos++;
-  while ((frstat.st_size >= sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) &&
+  while ((fsize >= sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) &&
          (pos <=
-          frstat.st_size - sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)))
+          fsize - sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)))
   {
     colon_pos = pos;
-    while ((colon_pos < frstat.st_size) &&
-           (data[colon_pos] != ':') &&
+    while ((colon_pos < fsize) && (data[colon_pos] != ':') &&
            (!isspace ((unsigned char) data[colon_pos])))
       colon_pos++;
-    if (colon_pos >= frstat.st_size)
+    if (colon_pos >= fsize)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                   _
@@ -300,12 +299,12 @@ read_blacklist_file ()
                   ("Syntax error in blacklist file at offset %llu, skipping bytes.\n"),
                   (unsigned long long) colon_pos);
       pos = colon_pos;
-      while ((pos < frstat.st_size) && isspace ((unsigned char) data[pos]))
+      while ((pos < fsize) && isspace ((unsigned char) data[pos]))
         pos++;
       continue;
     }
     tsize = colon_pos - pos;
-    if ((pos >= frstat.st_size) || (pos + tsize >= frstat.st_size) ||
+    if ((pos >= fsize) || (pos + tsize >= fsize) ||
         (tsize == 0))
     {
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -338,7 +337,7 @@ read_blacklist_file ()
                   ("Syntax error in blacklist file at offset %llu, skipping bytes.\n"),
                   (unsigned long long) pos);
       pos++;
-      while ((pos < frstat.st_size) && (!isspace ((unsigned char) data[pos])))
+      while ((pos < fsize) && (!isspace ((unsigned char) data[pos])))
         pos++;
       GNUNET_free_non_null (transport_name);
       continue;
@@ -354,8 +353,8 @@ read_blacklist_file ()
     }
     else
     {
-      if (0 != memcmp (&pid,
-                       &GST_my_identity, sizeof (struct GNUNET_PeerIdentity)))
+      if (0 !=
+          memcmp (&pid, &GST_my_identity, sizeof (struct GNUNET_PeerIdentity)))
       {
         entries_found++;
         GST_blacklist_add_peer (&pid, transport_name);
@@ -369,11 +368,10 @@ read_blacklist_file ()
     }
     pos = pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded);
     GNUNET_free_non_null (transport_name);
-    while ((pos < frstat.st_size) && isspace ((unsigned char) data[pos]))
+    while ((pos < fsize) && isspace ((unsigned char) data[pos]))
       pos++;
   }
-  GNUNET_STATISTICS_update (GST_stats,
-                            "# Transport entries blacklisted",
+  GNUNET_STATISTICS_update (GST_stats, "# Transport entries blacklisted",
                             entries_found, GNUNET_NO);
   GNUNET_free (data);
   GNUNET_free (fn);
@@ -389,8 +387,8 @@ void
 GST_blacklist_start (struct GNUNET_SERVER_Handle *server)
 {
   read_blacklist_file ();
-  GNUNET_SERVER_disconnect_notify (server,
-                                   &client_disconnect_notification, NULL);
+  GNUNET_SERVER_disconnect_notify (server, &client_disconnect_notification,
+                                   NULL);
 }
 
 
@@ -420,8 +418,8 @@ GST_blacklist_stop ()
 {
   if (NULL != blacklist)
   {
-    GNUNET_CONTAINER_multihashmap_iterate (blacklist,
-                                           &free_blacklist_entry, NULL);
+    GNUNET_CONTAINER_multihashmap_iterate (blacklist, &free_blacklist_entry,
+                                           NULL);
     GNUNET_CONTAINER_multihashmap_destroy (blacklist);
     blacklist = NULL;
   }
@@ -492,18 +490,18 @@ do_blacklist_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
                 GNUNET_i2s (&bc->peer));
 #endif
     bc->cont (bc->cont_cls, &bc->peer, GNUNET_OK);
+    GNUNET_CONTAINER_DLL_remove(bc_head, bc_tail, bc);
     GNUNET_free (bc);
     return;
   }
   if ((bl->bc != NULL) || (bl->waiting_for_reply != GNUNET_NO))
     return;                     /* someone else busy with this client */
   bl->bc = bc;
-  bc->th = GNUNET_SERVER_notify_transmit_ready (bl->client,
-                                                sizeof (struct
-                                                        BlacklistMessage),
-                                                GNUNET_TIME_UNIT_FOREVER_REL,
-                                                &transmit_blacklist_message,
-                                                bc);
+  bc->th =
+      GNUNET_SERVER_notify_transmit_ready (bl->client,
+                                           sizeof (struct BlacklistMessage),
+                                           GNUNET_TIME_UNIT_FOREVER_REL,
+                                           &transmit_blacklist_message, bc);
 }
 
 
@@ -517,14 +515,14 @@ do_blacklist_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  *                GNUNET_NO if we must shutdown the connection
  */
 static void
-confirm_or_drop_neighbour (void *cls,
-                           const struct GNUNET_PeerIdentity *peer, int allowed)
+confirm_or_drop_neighbour (void *cls, const struct GNUNET_PeerIdentity *peer,
+                           int allowed)
 {
   if (GNUNET_OK == allowed)
     return;                     /* we're done */
   GNUNET_STATISTICS_update (GST_stats,
-                            gettext_noop ("# disconnects due to blacklist"),
-                            1, GNUNET_NO);
+                            gettext_noop ("# disconnects due to blacklist"), 1,
+                            GNUNET_NO);
   GST_neighbours_force_disconnect (peer);
 }
 
@@ -551,15 +549,16 @@ struct TestConnectionContext
  * blacklisting client.
  *
  * @param cls the 'struct TestConnectionContest'
- * @param pid neighbour's identity
+ * @param neighbour neighbour's identity
  * @param ats performance data
  * @param ats_count number of entries in ats (excluding 0-termination)
+ * @param address the address
  */
 static void
-test_connection_ok (void *cls,
-                    const struct GNUNET_PeerIdentity *neighbour,
-                    const struct GNUNET_TRANSPORT_ATS_Information *ats,
-                    uint32_t ats_count)
+test_connection_ok (void *cls, const struct GNUNET_PeerIdentity *neighbour,
+                    const struct GNUNET_ATS_Information *ats,
+                    uint32_t ats_count,
+                    const struct GNUNET_HELLO_Address *address)
 {
   struct TestConnectionContext *tcc = cls;
   struct GST_BlacklistCheck *bc;
@@ -591,8 +590,7 @@ test_connection_ok (void *cls,
  * @param message the blacklist-init message that was sent
  */
 void
-GST_blacklist_handle_init (void *cls,
-                           struct GNUNET_SERVER_Client *client,
+GST_blacklist_handle_init (void *cls, struct GNUNET_SERVER_Client *client,
                            const struct GNUNET_MessageHeader *message)
 {
   struct Blacklisters *bl;
@@ -629,8 +627,7 @@ GST_blacklist_handle_init (void *cls,
  * @param message the blacklist-init message that was sent
  */
 void
-GST_blacklist_handle_reply (void *cls,
-                            struct GNUNET_SERVER_Client *client,
+GST_blacklist_handle_reply (void *cls, struct GNUNET_SERVER_Client *client,
                             const struct GNUNET_MessageHeader *message)
 {
   const struct BlacklistMessage *msg =
@@ -655,7 +652,7 @@ GST_blacklist_handle_reply (void *cls,
   bl->waiting_for_reply = GNUNET_NO;
   if (NULL != bc)
   {
-    /* only run this if the blacklist check has not been 
+    /* only run this if the blacklist check has not been
      * cancelled in the meantime... */
     if (ntohl (msg->is_allowed) == GNUNET_SYSERR)
     {
@@ -690,7 +687,7 @@ GST_blacklist_handle_reply (void *cls,
 
 /**
  * Add the given peer to the blacklist (for the given transport).
- * 
+ *
  * @param peer peer to blacklist
  * @param transport_name transport to blacklist for this peer, NULL for all
  */
@@ -727,6 +724,11 @@ test_blacklisted (void *cls, const 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;
+
+  /* blacklist check for specific transport */
   if (0 == strcmp (transport_name, be))
     return GNUNET_NO;           /* abort iteration! */
   return GNUNET_OK;
@@ -750,10 +752,11 @@ GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer,
 {
   struct GST_BlacklistCheck *bc;
 
+  GNUNET_assert (peer != NULL);
+
   if ((blacklist != NULL) &&
       (GNUNET_SYSERR ==
-       GNUNET_CONTAINER_multihashmap_get_multiple (blacklist,
-                                                   &peer->hashPubKey,
+       GNUNET_CONTAINER_multihashmap_get_multiple (blacklist, &peer->hashPubKey,
                                                    &test_blacklisted,
                                                    (void *) transport_name)))
   {
@@ -788,7 +791,7 @@ GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer,
 
 /**
  * Cancel a blacklist check.
- * 
+ *
  * @param bc check to cancel
  */
 void