-allow caller ID to differ from zone used for resolution
[oweals/gnunet.git] / src / transport / gnunet-service-transport.c
index 906ed29703d33c56094e1cd2d21f188dc6051d56..936742e7be62413d0a6515aa8413d138b023992a 100644 (file)
@@ -357,6 +357,36 @@ connect_bl_check_cont (void *cls,
   GNUNET_free (blctx);
 }
 
+/**
+ * Black list check result for try_connect call
+ * If connection to the peer is allowed request adddress and
+ *
+ * @param cls blc_ctx bl context
+ * @param peer the peer
+ * @param result the result
+ */
+static void
+connect_transport_bl_check_cont (void *cls,
+    const struct GNUNET_PeerIdentity *peer, int result)
+{
+  struct BlacklistCheckContext *blctx = cls;
+
+  GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, blctx);
+  blctx->blc = NULL;
+
+  if (GNUNET_OK == result)
+  {
+    /* Blacklist allows to speak to this transport */
+    GST_ats_add_address(blctx->address, blctx->session, blctx->ats, blctx->ats_count);
+  }
+
+  if (NULL != blctx->address)
+    GNUNET_HELLO_address_free (blctx->address);
+  GNUNET_free (blctx->msg);
+  GNUNET_free (blctx);
+}
+
+
 /**
  * Function called by the transport for each received message.
  *
@@ -440,6 +470,18 @@ GST_receive_callback (void *cls,
     {
       blctx->blc = blc;
     }
+
+    blctx = GNUNET_new (struct BlacklistCheckContext);
+    blctx->address = GNUNET_HELLO_address_copy (address);
+    blctx->session = session;
+    blctx->msg = GNUNET_malloc (ntohs(message->size));
+    memcpy (blctx->msg, message, ntohs(message->size));
+    GNUNET_CONTAINER_DLL_insert (bc_head, bc_tail, blctx);
+    if (NULL != (blc = GST_blacklist_test_allowed (&address->peer,
+        address->transport_name, &connect_transport_bl_check_cont, blctx)))
+    {
+      blctx->blc = blc;
+    }
     break;
   case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT_ACK:
     if (GNUNET_OK != GST_neighbours_handle_connect_ack (message,
@@ -495,6 +537,28 @@ static void
 plugin_env_address_change_notification (void *cls, int add_remove,
     const struct GNUNET_HELLO_Address *address)
 {
+  static int addresses = 0;
+  struct GNUNET_STATISTICS_Handle *cfg = GST_stats;
+
+  if (GNUNET_YES == add_remove)
+  {
+    addresses ++;
+    GNUNET_STATISTICS_update (cfg, "# transport addresses", 1, GNUNET_NO);
+  }
+  else if (GNUNET_NO == add_remove)
+  {
+    if (0 == addresses)
+      GNUNET_break (0);
+    else
+    {
+      addresses --;
+      GNUNET_STATISTICS_update (cfg, "# transport addresses", -1, GNUNET_NO);
+    }
+  }
+
+  GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+      "Transport now has %u addresses to communicate\n", addresses);
+
   GST_hello_modify_addresses (add_remove, address);
 }
 
@@ -650,10 +714,10 @@ GST_ats_add_address (const struct GNUNET_HELLO_Address *address,
   ats2[0].value = htonl (net);
   memcpy (&ats2[1], ats, sizeof(struct GNUNET_ATS_Information) * ats_count);
   GNUNET_log(GNUNET_ERROR_TYPE_INFO,
-      "Notifying ATS about peer `%s''s new address `%s' session %p in network %s %u\n",
+      "Notifying ATS about peer `%s''s new address `%s' session %p in network %s\n",
       GNUNET_i2s (&address->peer),
       (0 == address->address_length) ? "<inbound>" : GST_plugins_a2s (address),
-      session, GNUNET_ATS_print_network_type (net), net);
+      session, GNUNET_ATS_print_network_type (net));
   GNUNET_ATS_address_add (GST_ats, address, session, ats2, ats_count + 1);
 }