-fix time assertion introduce in last patch
[oweals/gnunet.git] / src / transport / gnunet-service-transport.c
index b64a5a1214eed28f8db956f9433d9fc4165b9cbf..a41aa7f65bca14ca98bf69895df3c8f1a424b90e 100644 (file)
@@ -329,8 +329,12 @@ connect_bl_check_cont (void *cls,
   if (GNUNET_OK == result)
   {
     /* Blacklist allows to speak to this peer, forward CONNECT to neighbours  */
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "Received CONNECT message from peer `%s' with `%s' %p\n",
+                GNUNET_i2s (peer), GST_plugins_a2s (blctx->address), blctx->session);
+
     if (GNUNET_OK != GST_neighbours_handle_connect (blctx->msg,
-          &blctx->address->peer, blctx->address, blctx->session))
+        &blctx->address->peer))
     {
       cancel_pending_blacklist_checks (blctx->address, blctx->session);
       kill_session (blctx->address->transport_name, blctx->session);
@@ -353,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.
  *
@@ -436,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,
@@ -491,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);
 }
 
@@ -646,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);
 }
 
@@ -941,35 +1009,6 @@ neighbours_changed_notification (void *cls,
   GST_clients_broadcast_peer_notification (peer, address, state, state_timeout);
 }
 
-/**
- * Function called to notify transport users that a neighbour peer changed its
- * active address.
- *
- * @param cls closure
- * @param peer peer this update is about (never NULL)
- * @param address address (never NULL)
- * @param last_validation point in time when last validation was performed
- * @param valid_until point in time how long address is valid
- * @param next_validation point in time when next validation will be performed
- * @param state state of validation notification
- */
-static void
-validation_changed_notification (void *cls,
-    const struct GNUNET_PeerIdentity *peer,
-    const struct GNUNET_HELLO_Address *address,
-    struct GNUNET_TIME_Absolute last_validation,
-    struct GNUNET_TIME_Absolute valid_until,
-    struct GNUNET_TIME_Absolute next_validation,
-    enum GNUNET_TRANSPORT_ValidationState state)
-{
-  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
-      "Notifying about change for for validation entry for peer `%s' with address `%s'\n",
-      GNUNET_i2s (peer),
-      (NULL != address) ? GST_plugins_a2s (address) : "<none>");
-
-  GST_clients_broadcast_validation_notification (peer, address,
-      last_validation, valid_until, next_validation, state);
-}
 
 /**
  * Function called when the service shuts down.  Unloads our plugins
@@ -1123,9 +1162,10 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
       &neighbours_changed_notification,
       (max_fd / 3) * 2);
   GST_clients_start (GST_server);
-  GST_validation_start (&validation_changed_notification, NULL, (max_fd / 3));
+  GST_validation_start ((max_fd / 3));
 }
 
+
 /**
  * The main function for the transport service.
  *