remove port from transport section because it was getting in the way of making sense...
[oweals/gnunet.git] / src / transport / gnunet-service-transport.c
index 3a6fcf9251bf7b2747a44803eaf56b5c8387c5dd..1d0e0cc15a4f29c537bda29471168a02ca33b4bb 100644 (file)
@@ -4,7 +4,7 @@
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 2, or (at your
+     by the Free Software Foundation; either version 3, or (at your
      option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
@@ -43,8 +43,6 @@
 
 #define DEBUG_PING_PONG GNUNET_NO
 
-#define SIGN_USELESS GNUNET_NO
-
 #define DEBUG_TRANSPORT_HELLO GNUNET_YES
 
 /**
@@ -57,7 +55,7 @@
  * How many messages can we have pending for a given client process
  * before we start to drop incoming messages?  We typically should
  * have only one client and so this would be the primary buffer for
- * messages, so the number should be chosen rather generously.
 * messages, so the number should be chosen rather generously.
  *
  * The expectation here is that most of the time the queue is large
  * enough so that a drop is virtually never required.  Note that
@@ -80,8 +78,8 @@
 #define MAX_CONNECT_RETRY 3
 
 /**
- * Limit on the number of ready-to-run tasks when validating 
- * HELLOs.  If more tasks are ready to run, we will drop 
+ * Limit on the number of ready-to-run tasks when validating
+ * HELLOs.  If more tasks are ready to run, we will drop
  * HELLOs instead of validating them.
  */
 #define MAX_HELLO_LOAD 4
@@ -208,7 +206,7 @@ struct ForeignAddressList
   unsigned int connect_attempts;
 
   /**
-   * DV distance to this peer (1 if no DV is used). 
+   * DV distance to this peer (1 if no DV is used).
    * FIXME: need to set this from transport plugins!
    */
   uint32_t distance;
@@ -230,7 +228,7 @@ struct ForeignAddressList
    * successfully transmit or receive data to a peer via a particular
    * address, we set this to GNUNET_YES.  If we later get an error
    * (disconnect notification, transmission failure, timeout), we set
-   * it back to GNUNET_NO.  
+   * it back to GNUNET_NO.
    */
   int8_t connected;
 
@@ -481,7 +479,7 @@ struct NeighbourList
    * Buffer for at most one payload message used when we receive
    * payload data before our PING-PONG has succeeded.  We then
    * store such messages in this intermediary buffer until the
-   * connection is fully up.  
+   * connection is fully up.
    */
   struct GNUNET_MessageHeader *pre_connect_message_buffer;
 
@@ -549,7 +547,7 @@ struct NeighbourList
   unsigned int quota_violation_count;
 
   /**
-   * DV distance to this peer (1 if no DV is used). 
+   * DV distance to this peer (1 if no DV is used).
    */
   uint32_t distance;
 
@@ -645,7 +643,7 @@ struct TransportPongMessage
 
   /**
    * Size of address appended to this message (part of what is
-   * being signed, hence not redundant). 
+   * being signed, hence not redundant).
    */
   uint32_t addrlen;
 
@@ -700,7 +698,7 @@ struct TransportClient
 
   /**
    * Current transmit request handle.
-   */ 
+   */
   struct GNUNET_CONNECTION_TransmitHandle *th;
 
   /**
@@ -809,7 +807,7 @@ struct CheckHelloValidatedContext
    * NULL after we are done processing peerinfo's information.
    */
   struct GNUNET_PEERINFO_IteratorContext *piter;
-  
+
   /**
    * Was a HELLO known for this peer to peerinfo?
    */
@@ -926,7 +924,7 @@ static void try_transmission_to_peer (struct NeighbourList *neighbour);
 
 /**
  * Find an entry in the neighbour list for a particular peer.
- *  
+ *
  * @return NULL if not found.
  */
 static struct NeighbourList *
@@ -992,11 +990,11 @@ add_peer_to_blacklist (struct GNUNET_PeerIdentity *peer, char *transport_name)
   plugin = find_transport(transport_name);
   if (plugin == NULL) /* Nothing to do */
     return;
-  if (plugin->blacklist == NULL)    
-    plugin->blacklist = GNUNET_CONTAINER_multihashmap_create(TRANSPORT_BLACKLIST_HT_SIZE);    
+  if (plugin->blacklist == NULL)
+    plugin->blacklist = GNUNET_CONTAINER_multihashmap_create(TRANSPORT_BLACKLIST_HT_SIZE);
   GNUNET_assert(plugin->blacklist != NULL);
   GNUNET_CONTAINER_multihashmap_put(plugin->blacklist, &peer->hashPubKey,
-                                   NULL, 
+                                   NULL,
                                    GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
 }
 
@@ -1108,7 +1106,10 @@ read_blacklist_file (const struct GNUNET_CONFIGURATION_Handle *cfg)
           GNUNET_free (data);
           return;
         }
-      tsize = tsize;
+
+      if (tsize < 1)
+        continue;
+
       transport_name = GNUNET_malloc(tsize + 1);
       memcpy(transport_name, &data[pos], tsize);
       pos = colon_pos + 1;
@@ -1195,7 +1196,7 @@ transmit_to_client_callback (void *cls, size_t size, void *buf)
          GNUNET_STATISTICS_update (stats,
                                    gettext_noop ("# bytes discarded (could not transmit to client)"),
                                    ntohs (((const struct GNUNET_MessageHeader*)&q[1])->size),
-                                   GNUNET_NO);      
+                                   GNUNET_NO);
          GNUNET_CONTAINER_DLL_remove (client->message_queue_head,
                                       client->message_queue_tail,
                                       q);
@@ -1262,7 +1263,7 @@ a2s (const char *plugin,
   return p->api->address_to_string (p->api->cls,
                                    addr,
                                    addr_len);
-}   
+}
 
 
 /**
@@ -1339,7 +1340,7 @@ transmit_to_client (struct TransportClient *client,
                   ("Dropping message of type %u and size %u, have %u messages pending (%u is the soft limit)\n"),
                  ntohs (msg->type),
                  ntohs (msg->size),
-                  client->message_count, 
+                  client->message_count,
                  MAX_PENDING);
       GNUNET_STATISTICS_update (stats,
                                gettext_noop ("# messages dropped due to slow client"),
@@ -1354,7 +1355,7 @@ transmit_to_client (struct TransportClient *client,
   GNUNET_CONTAINER_DLL_insert_after (client->message_queue_head,
                                     client->message_queue_tail,
                                     client->message_queue_tail,
-                                    q);                                     
+                                    q);                                
   client->message_count++;
   if (client->th == NULL)
     {
@@ -1388,7 +1389,7 @@ transmit_send_ok (struct TransportClient *client,
   send_ok_msg.success = htonl (result);
   send_ok_msg.latency = GNUNET_TIME_relative_hton (n->latency);
   send_ok_msg.peer = n->id;
-  transmit_to_client (client, &send_ok_msg.header, GNUNET_NO); 
+  transmit_to_client (client, &send_ok_msg.header, GNUNET_NO);
 }
 
 
@@ -1413,7 +1414,7 @@ transmit_send_continuation (void *cls,
 {
   struct MessageQueue *mq = cls;
   struct NeighbourList *n;
-  
+
   GNUNET_STATISTICS_update (stats,
                            gettext_noop ("# bytes pending with plugins"),
                            - (int64_t) mq->message_buf_size,
@@ -1423,27 +1424,27 @@ transmit_send_continuation (void *cls,
       GNUNET_STATISTICS_update (stats,
                                gettext_noop ("# bytes successfully transmitted by plugins"),
                                mq->message_buf_size,
-                               GNUNET_NO);      
+                               GNUNET_NO);
     }
   else
     {
       GNUNET_STATISTICS_update (stats,
                                gettext_noop ("# bytes with transmission failure by plugins"),
                                mq->message_buf_size,
-                               GNUNET_NO);      
-    }  
+                               GNUNET_NO);
+    }
   n = find_neighbour(&mq->neighbour_id);
   GNUNET_assert (n != NULL);
   if (mq->specific_address != NULL)
     {
-      if (result == GNUNET_OK)    
+      if (result == GNUNET_OK)
        {
          mq->specific_address->timeout =
            GNUNET_TIME_relative_to_absolute
            (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
          if (mq->specific_address->validated == GNUNET_YES)
            mark_address_connected (mq->specific_address);
-       }    
+       }
       else
        {
          if (mq->specific_address->connected != GNUNET_NO)
@@ -1461,8 +1462,8 @@ transmit_send_continuation (void *cls,
                                        GNUNET_NO);
              mq->specific_address->connected = GNUNET_NO;
            }
-       }    
-      if (! mq->internal_msg) 
+       }
+      if (! mq->internal_msg)
        mq->specific_address->in_transmit = GNUNET_NO;
     }
   if (mq->client != NULL)
@@ -1495,7 +1496,7 @@ find_ready_address(struct NeighbourList *neighbour)
       addresses = head->addresses;
       while (addresses != NULL)
         {
-          if ( (addresses->timeout.value < now.value) && 
+          if ( (addresses->timeout.value < now.value) &&
               (addresses->connected == GNUNET_YES) )
             {
 #if DEBUG_TRANSPORT
@@ -1530,13 +1531,13 @@ find_ready_address(struct NeighbourList *neighbour)
                        (unsigned long long) addresses->timeout.value,
                        (unsigned int) addresses->distance);
 #endif
-          if ( ( (best_address == NULL) || 
+          if ( ( (best_address == NULL) ||
                 (addresses->connected == GNUNET_YES) ||
                 (best_address->connected == GNUNET_NO) ) &&
               (addresses->in_transmit == GNUNET_NO) &&
-              ( (best_address == NULL) || 
+              ( (best_address == NULL) ||
                 (addresses->latency.value < best_address->latency.value)) )
-           best_address = addresses;            
+           best_address = addresses;
          /* FIXME: also give lower-latency addresses that are not
             connected a chance some times... */
           addresses = addresses->next;
@@ -1548,7 +1549,7 @@ find_ready_address(struct NeighbourList *neighbour)
 #if DEBUG_TRANSPORT
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   "Best address found (`%s') has latency of %llu ms.\n",
-                 (best_address->addrlen > 0) 
+                 (best_address->addrlen > 0)
                  ? a2s (best_address->ready_list->plugin->short_name,
                       best_address->addr,
                       best_address->addrlen)
@@ -1612,11 +1613,11 @@ try_transmission_to_peer (struct NeighbourList *neighbour)
   force_address = GNUNET_YES;
   if (mq->specific_address == NULL)
     {
-      mq->specific_address = find_ready_address(neighbour); 
+      mq->specific_address = find_ready_address(neighbour);
       GNUNET_STATISTICS_update (stats,
                                gettext_noop ("# transport selected peer address freely"),
                                1,
-                               GNUNET_NO); 
+                               GNUNET_NO);
       force_address = GNUNET_NO;
     }
   if (mq->specific_address == NULL)
@@ -1624,7 +1625,7 @@ try_transmission_to_peer (struct NeighbourList *neighbour)
       GNUNET_STATISTICS_update (stats,
                                gettext_noop ("# transport failed to selected peer address"),
                                1,
-                               GNUNET_NO); 
+                               GNUNET_NO);
       timeout = GNUNET_TIME_absolute_get_remaining (mq->timeout);
       if (timeout.value == 0)
        {
@@ -1641,14 +1642,14 @@ try_transmission_to_peer (struct NeighbourList *neighbour)
          GNUNET_STATISTICS_update (stats,
                                    gettext_noop ("# bytes discarded (no destination address available)"),
                                    mq->message_buf_size,
-                                   GNUNET_NO);      
+                                   GNUNET_NO);
          if (mq->client != NULL)
            transmit_send_ok (mq->client, neighbour, GNUNET_NO);
          GNUNET_CONTAINER_DLL_remove (neighbour->messages_head,
                                       neighbour->messages_tail,
                                       mq);
          GNUNET_free (mq);
-         return;               /* nobody ready */ 
+         return;               /* nobody ready */
        }
       GNUNET_STATISTICS_update (stats,
                                gettext_noop ("# message delivery deferred (no address)"),
@@ -1670,7 +1671,7 @@ try_transmission_to_peer (struct NeighbourList *neighbour)
 #endif
       /* FIXME: might want to trigger peerinfo lookup here
         (unless that's already pending...) */
-      return;    
+      return;
     }
   GNUNET_CONTAINER_DLL_remove (neighbour->messages_head,
                               neighbour->messages_tail,
@@ -1685,7 +1686,7 @@ try_transmission_to_peer (struct NeighbourList *neighbour)
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Sending message of size %u for `%4s' to `%s' via plugin `%s'\n",
               mq->message_buf_size,
-              GNUNET_i2s (&neighbour->id), 
+              GNUNET_i2s (&neighbour->id),
              (mq->specific_address->addr != NULL)
              ? a2s (mq->plugin->short_name,
                     mq->specific_address->addr,
@@ -1716,7 +1717,7 @@ try_transmission_to_peer (struct NeighbourList *neighbour)
     {
       /* failure, but 'send' would not call continuation in this case,
         so we need to do it here! */
-      transmit_send_continuation (mq, 
+      transmit_send_continuation (mq,
                                  &mq->neighbour_id,
                                  GNUNET_SYSERR);
     }
@@ -1772,6 +1773,7 @@ transmit_to_peer (struct TransportClient *client,
   mq = GNUNET_malloc (sizeof (struct MessageQueue) + message_buf_size);
   mq->specific_address = peer_address;
   mq->client = client;
+  /* FIXME: this memcpy can be up to 7% of our total runtime! */
   memcpy (&mq[1], message_buf, message_buf_size);
   mq->message_buf = (const char*) &mq[1];
   mq->message_buf_size = message_buf_size;
@@ -1779,7 +1781,7 @@ transmit_to_peer (struct TransportClient *client,
   mq->internal_msg = is_internal;
   mq->priority = priority;
   mq->timeout = GNUNET_TIME_relative_to_absolute (timeout);
-  if (is_internal)    
+  if (is_internal)
     GNUNET_CONTAINER_DLL_insert (neighbour->messages_head,
                                 neighbour->messages_tail,
                                 mq);
@@ -1881,7 +1883,7 @@ refresh_hello ()
                                GNUNET_NO);
       transmit_to_peer (NULL, NULL, 0,
                        HELLO_ADDRESS_EXPIRATION,
-                        (const char *) our_hello, 
+                        (const char *) our_hello,
                        GNUNET_HELLO_size(our_hello),
                         GNUNET_NO, npos);
       npos = npos->next;
@@ -1938,7 +1940,7 @@ update_addresses (struct TransportPlugin *plugin, int fresh)
           if (prev == NULL)
             plugin->addresses = pos->next;
           else
-            prev->next = pos->next;  
+            prev->next = pos->next;
           GNUNET_free (pos);
         }
       else
@@ -1992,7 +1994,7 @@ expire_address_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  * @param value value in the hash map ('struct ValidationEntry*')
  * @return GNUNET_YES (we should continue to iterate)
  */
-static int 
+static int
 remove_session_validations (void *cls,
                            const GNUNET_HashCode * key,
                            void *value)
@@ -2006,15 +2008,72 @@ remove_session_validations (void *cls,
 }
 
 
+/**
+ * We've been disconnected from the other peer (for some
+ * connection-oriented transport).  Either quickly
+ * re-establish the connection or signal the disconnect
+ * to the CORE.
+ *
+ * Only signal CORE level disconnect if ALL addresses
+ * for the peer are exhausted.
+ *
+ * @param p overall plugin context
+ * @param nl neighbour that was disconnected
+ */
+static void
+try_fast_reconnect (struct TransportPlugin *p,
+                   struct NeighbourList *nl)
+{
+  /* FIXME-MW: fast reconnect / transport switching not implemented... */
+  /* Note: the idea here is to hide problems with transports (or
+     switching between plugins) from the core to eliminate the need to
+     re-negotiate session keys and the like; OTOH, we should tell core
+     quickly (much faster than timeout) `if a connection was lost and
+     could not be re-established (i.e. other peer went down or is
+     unable / refuses to communicate);
+
+     So we should consider:
+     1) ideally: our own willingness / need to connect
+     2) prior failures to connect to this peer (by plugin)
+     3) ideally: reasons why other peer terminated (as far as knowable)
+
+     Most importantly, it must be POSSIBLE for another peer to terminate
+     a connection for a while (without us instantly re-establishing it).
+     Similarly, if another peer is gone we should quickly notify CORE.
+     OTOH, if there was a minor glitch (i.e. crash of gnunet-service-transport
+     on the other end), we should reconnect in such a way that BOTH CORE
+     services never even notice.
+     Furthermore, the same mechanism (or small variation) could be used
+     to switch to a better-performing plugin (ATS).
+
+     Finally, this needs to be tested throughly... */                                                          
+
+  /*
+   * GNUNET_NO in the call below makes transport disconnect the peer,
+   * even if only a single address (out of say, six) went away.  This
+   * function must be careful to ONLY disconnect if the peer is gone,
+   * not just a specifi address.
+   *
+   * More specifically, half the places it was used had it WRONG.
+   */
+
+  /* No reconnect, signal disconnect instead! */
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+            "Disconnecting peer `%4s', %s\n", GNUNET_i2s(&nl->id),
+            "try_fast_reconnect");
+  disconnect_neighbour (nl, GNUNET_YES);
+}
+
+
 /**
  * Function that will be called whenever the plugin internally
  * cleans up a session pointer and hence the service needs to
  * discard all of those sessions as well.  Plugins that do not
  * use sessions can simply omit calling this function and always
  * use NULL wherever a session pointer is needed.
- * 
+ *
  * @param cls closure
- * @param peer which peer was the session for 
+ * @param peer which peer was the session for
  * @param session which session is being destoyed
  */
 static void
@@ -2033,7 +2092,7 @@ plugin_env_session_end  (void *cls,
                                         session);
   nl = find_neighbour (peer);
   if (nl == NULL)
-    return;
+    return; /* was never marked as connected */
   rl = nl->plugins;
   while (rl != NULL)
     {
@@ -2042,7 +2101,7 @@ plugin_env_session_end  (void *cls,
       rl = rl->next;
     }
   if (rl == NULL)
-    return;
+    return; /* was never marked as connected */
   prev = NULL;
   pos = rl->addresses;
   while ( (pos != NULL) &&
@@ -2052,10 +2111,15 @@ plugin_env_session_end  (void *cls,
       pos = pos->next;
     }
   if (pos == NULL)
-    return;
+    return; /* was never marked as connected */
   pos->session = NULL;
   if (pos->addrlen != 0)
-    return;
+    {
+      if (nl->received_pong != GNUNET_NO)
+       try_fast_reconnect (p, nl);
+      return;
+    }
+  /* was inbound connection, free 'pos' */
   if (prev == NULL)
     rl->addresses = pos->next;
   else
@@ -2068,17 +2132,31 @@ plugin_env_session_end  (void *cls,
     }
   GNUNET_free (pos);
   if (nl->received_pong == GNUNET_NO)
-    return; /* nothing to do */
+    return; /* nothing to do, never connected... */
   /* check if we have any validated addresses left */
   pos = rl->addresses;
   while (pos != NULL)
     {
       if (pos->validated)
-       return;
+       {
+         try_fast_reconnect (p, nl);
+         return;
+       }
       pos = pos->next;
     }
   /* no valid addresses left, signal disconnect! */
-  disconnect_neighbour (nl, GNUNET_NO);  
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+            "Disconnecting peer `%4s', %s\n", GNUNET_i2s(&nl->id),
+            "plugin_env_session_end");
+  /* FIXME: This doesn't mean there are no addresses left for this PEER,
+   * it means there aren't any left for this PLUGIN/PEER combination! So
+   * calling disconnect_neighbor here with GNUNET_NO forces disconnect
+   * when it isn't necessary. Using GNUNET_YES at least checks to see
+   * if there are any addresses that work first, so as not to overdo it.
+   * --NE
+   */
+  disconnect_neighbour (nl, GNUNET_YES);
 }
 
 
@@ -2258,7 +2336,7 @@ static struct ForeignAddressList *
 add_peer_address (struct NeighbourList *neighbour,
                  const char *tname,
                  struct Session *session,
-                 const char *addr, 
+                 const char *addr,
                  uint16_t addrlen)
 {
   struct ReadyList *head;
@@ -2294,7 +2372,7 @@ add_peer_address (struct NeighbourList *neighbour,
   ret->latency = GNUNET_TIME_relative_get_forever();
   ret->distance = -1;
   ret->timeout = GNUNET_TIME_relative_to_absolute
-    (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 
+    (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
   ret->ready_list = head;
   ret->next = head->addresses;
   head->addresses = ret;
@@ -2432,7 +2510,7 @@ check_address_exists (void *cls,
  * @param value value in the hash map (validation to abort)
  * @return GNUNET_YES (always)
  */
-static int 
+static int
 abort_validation (void *cls,
                  const GNUNET_HashCode * key,
                  void *value)
@@ -2542,12 +2620,12 @@ add_to_foreign_address_list (void *cls,
   GNUNET_STATISTICS_update (stats,
                            gettext_noop ("# valid peer addresses returned by PEERINFO"),
                            1,
-                           GNUNET_NO);      
+                           GNUNET_NO);
   try = GNUNET_NO;
   fal = find_peer_address (n, tname, NULL, addr, addrlen);
   if (fal == NULL)
     {
-#if DEBUG_TRANSPORT
+#if DEBUG_TRANSPORT_HELLO
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                  "Adding address `%s' (%s) for peer `%4s' due to PEERINFO data for %llums.\n",
                  a2s (tname, addr, addrlen),
@@ -2561,7 +2639,7 @@ add_to_foreign_address_list (void *cls,
          GNUNET_STATISTICS_update (stats,
                                    gettext_noop ("# previously validated addresses lacking transport"),
                                    1,
-                                   GNUNET_NO); 
+                                   GNUNET_NO);
        }
       else
        {
@@ -2578,18 +2656,18 @@ add_to_foreign_address_list (void *cls,
     }
   if (fal == NULL)
     {
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                  "Failed to add new address for `%4s'\n",
                  GNUNET_i2s (&n->id));
       return GNUNET_OK;
     }
   if (fal->validated == GNUNET_NO)
     {
-      fal->validated = GNUNET_YES;  
+      fal->validated = GNUNET_YES;
       GNUNET_STATISTICS_update (stats,
                                gettext_noop ("# peer addresses considered valid"),
                                1,
-                               GNUNET_NO);      
+                               GNUNET_NO);
     }
   if (try == GNUNET_YES)
     {
@@ -2608,21 +2686,23 @@ add_to_foreign_address_list (void *cls,
  * @param cls closure ('struct NeighbourList*')
  * @param peer id of the peer, NULL for last call
  * @param h hello message for the peer (can be NULL)
- * @param trust amount of trust we have in the peer (not used)
  */
 static void
 add_hello_for_peer (void *cls,
                    const struct GNUNET_PeerIdentity *peer,
-                   const struct GNUNET_HELLO_Message *h, 
-                   uint32_t trust)
+                   const struct GNUNET_HELLO_Message *h)
 {
   struct NeighbourList *n = cls;
 
   if (peer == NULL)
     {
+      GNUNET_STATISTICS_update (stats,
+                                gettext_noop ("# outstanding peerinfo iterate requests"),
+                                -1,
+                                GNUNET_NO);
       n->piter = NULL;
       return;
-    } 
+    }
   if (h == NULL)
     return; /* no HELLO available */
 #if DEBUG_TRANSPORT
@@ -2645,7 +2725,7 @@ add_hello_for_peer (void *cls,
 
 /**
  * Create a fresh entry in our neighbour list for the given peer.
- * Will try to transmit our current HELLO to the new neighbour. 
+ * Will try to transmit our current HELLO to the new neighbour.
  * Do not call this function directly, use 'setup_peer_check_blacklist.
  *
  * @param peer the peer for which we create the entry
@@ -2701,9 +2781,22 @@ setup_new_neighbour (const struct GNUNET_PeerIdentity *peer,
                                                   &neighbour_timeout_task, n);
   if (do_hello)
     {
+      GNUNET_STATISTICS_update (stats,
+                                gettext_noop ("# peerinfo new neighbor iterate requests"),
+                                1,
+                                GNUNET_NO);
+      GNUNET_STATISTICS_update (stats,
+                                gettext_noop ("# outstanding peerinfo iterate requests"),
+                                1,
+                                GNUNET_NO);
       n->piter = GNUNET_PEERINFO_iterate (peerinfo, peer,
-                                         0, GNUNET_TIME_UNIT_FOREVER_REL,
+                                         GNUNET_TIME_UNIT_FOREVER_REL,
                                          &add_hello_for_peer, n);
+
+      GNUNET_STATISTICS_update (stats,
+                                gettext_noop ("# HELLO's sent to new neighbors"),
+                                1,
+                                GNUNET_NO);
       transmit_to_peer (NULL, NULL, 0,
                        HELLO_ADDRESS_EXPIRATION,
                        (const char *) our_hello, GNUNET_HELLO_size(our_hello),
@@ -2715,7 +2808,7 @@ setup_new_neighbour (const struct GNUNET_PeerIdentity *peer,
 
 /**
  * Function called after we have checked if communicating
- * with a given peer is acceptable.  
+ * with a given peer is acceptable.
  *
  * @param cls closure
  * @param n NULL if communication is not acceptable
@@ -2769,12 +2862,12 @@ static struct Blacklisters *bl_tail;
  */
 struct BlacklistCheck
 {
-  
+
   /**
    * This is a linked list.
    */
   struct BlacklistCheck *next;
-  
+
   /**
    * This is a linked list.
    */
@@ -2833,7 +2926,7 @@ static struct BlacklistCheck *bc_tail;
  * Perform next action in the blacklist check.
  *
  * @param cls the 'struct BlacklistCheck*'
- * @param tc unused 
+ * @param tc unused
  */
 static void
 do_blacklist_check (void *cls,
@@ -2871,7 +2964,7 @@ transmit_blacklist_message (void *cls,
   bm.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY);
   bm.is_allowed = htonl (0);
   bm.peer = bc->peer;
-  memcpy (buf, &bm, sizeof (bm)); 
+  memcpy (buf, &bm, sizeof (bm));
   GNUNET_SERVER_receive_done (bl->client, GNUNET_OK);
   return sizeof (bm);
 }
@@ -2881,7 +2974,7 @@ transmit_blacklist_message (void *cls,
  * Perform next action in the blacklist check.
  *
  * @param cls the 'struct BlacklistCheck*'
- * @param tc unused 
+ * @param tc unused
  */
 static void
 do_blacklist_check (void *cls,
@@ -2899,14 +2992,14 @@ do_blacklist_check (void *cls,
       GNUNET_free (bc);
       return;
     }
-  if (bl->bc == NULL) 
+  if (bl->bc == NULL)
     {
       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);
     }
 }
 
@@ -2935,13 +3028,16 @@ setup_peer_check_blacklist (const struct GNUNET_PeerIdentity *peer,
   n = find_neighbour(peer);
   if (n != NULL)
     {
-      cont (cont_cls, n);
+      if (cont != NULL)
+        cont (cont_cls, n);
       return;
     }
   if (bl_head == NULL)
     {
-      cont (cont_cls,
-           setup_new_neighbour (peer, do_hello));
+      if (cont != NULL)
+        cont (cont_cls, setup_new_neighbour (peer, do_hello));
+      else
+        setup_new_neighbour(peer, do_hello);
       return;
     }
   bc = GNUNET_malloc (sizeof (struct BlacklistCheck));
@@ -2958,7 +3054,7 @@ setup_peer_check_blacklist (const struct GNUNET_PeerIdentity *peer,
 
 
 /**
- * Function called with the result of querying a new blacklister about 
+ * Function called with the result of querying a new blacklister about
  * it being allowed (or not) to continue to talk to an existing neighbour.
  *
  * @param cls the original 'struct NeighbourList'
@@ -2971,7 +3067,12 @@ confirm_or_drop_neighbour (void *cls,
   struct NeighbourList * orig = cls;
 
   if (n == NULL)
-    disconnect_neighbour (orig, GNUNET_NO);
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Disconnecting peer `%4s', %s\n", GNUNET_i2s(&orig->id),
+              "confirm_or_drop_neighboUr");
+      disconnect_neighbour (orig, GNUNET_NO);
+    }
 }
 
 
@@ -3046,16 +3147,16 @@ handle_blacklist_reply (void *cls,
   bl = bl_head;
   while ( (bl != NULL) &&
          (bl->client != client) )
-    bl = bl->next;  
+    bl = bl->next;
   if (bl == NULL)
     {
       GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
       return;
     }
   bc = bl->bc;
-  bl->bc = NULL;  
+  bl->bc = NULL;
   if (ntohl (msg->is_allowed) == GNUNET_SYSERR)
-    {    
+    {
       bc->cont (bc->cont_cls, NULL);
       GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, bc);
       GNUNET_free (bc);
@@ -3065,7 +3166,7 @@ handle_blacklist_reply (void *cls,
       bc->bl_pos = bc->bl_pos->next;
       bc->task = GNUNET_SCHEDULER_add_now (sched,
                                           &do_blacklist_check,
-                                          bc);      
+                                          bc);
     }
   /* check if any other bc's are waiting for this blacklister */
   bc = bc_head;
@@ -3075,7 +3176,7 @@ handle_blacklist_reply (void *cls,
           (GNUNET_SCHEDULER_NO_TASK == bc->task) )
        bc->task = GNUNET_SCHEDULER_add_now (sched,
                                             &do_blacklist_check,
-                                            bc);      
+                                            bc);
       bc = bc->next;
     }
 }
@@ -3087,8 +3188,8 @@ handle_blacklist_reply (void *cls,
  * @param cls our 'struct PeriodicValidationContext*'
  * @param tc task context
  */
-static void 
-send_periodic_ping (void *cls, 
+static void
+send_periodic_ping (void *cls,
                    const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct ForeignAddressList *peer_address = cls;
@@ -3104,13 +3205,13 @@ send_periodic_ping (void *cls,
 
   peer_address->revalidate_task = GNUNET_SCHEDULER_NO_TASK;
   if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
-    return; 
+    return;
   tp = peer_address->ready_list->plugin;
   neighbour = peer_address->ready_list->neighbour;
   if (GNUNET_YES != neighbour->public_key_valid)
     {
       /* no public key yet, try again later */
-      schedule_next_ping (peer_address);     
+      schedule_next_ping (peer_address);
       return;
     }
   caec.addr = peer_address->addr;
@@ -3138,7 +3239,7 @@ send_periodic_ping (void *cls,
                   tp->short_name,
                   GNUNET_i2s (&neighbour->id));
 #endif
-      schedule_next_ping (peer_address);     
+      schedule_next_ping (peer_address);
       return;
     }
   va = GNUNET_malloc (sizeof (struct ValidationEntry) + peer_address->addrlen);
@@ -3154,7 +3255,7 @@ send_periodic_ping (void *cls,
       va->addrlen = peer_address->addrlen;
     }
   memcpy(&va->publicKey,
-        &neighbour->publicKey, 
+        &neighbour->publicKey,
         sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
 
   va->timeout_task = GNUNET_SCHEDULER_add_delayed (sched,
@@ -3165,28 +3266,40 @@ send_periodic_ping (void *cls,
                                      &neighbour->id.hashPubKey,
                                      va,
                                      GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
-  hello_size = GNUNET_HELLO_size(our_hello);
+
+  if (peer_address->validated != GNUNET_YES)
+    hello_size = GNUNET_HELLO_size(our_hello);
+  else
+    hello_size = 0;
+
   tsize = sizeof(struct TransportPingMessage) + hello_size;
+
   if (peer_address->addr != NULL)
     {
       slen = strlen (tp->short_name) + 1;
       tsize += slen + peer_address->addrlen;
     }
+  else
+    {
+      slen = 0; /* make gcc happy */
+    }
   message_buf = GNUNET_malloc(tsize);
   ping.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_PING);
   ping.challenge = htonl(va->challenge);
   memcpy(&ping.target, &neighbour->id, sizeof(struct GNUNET_PeerIdentity));
-  memcpy(message_buf, our_hello, hello_size);
+  if (peer_address->validated != GNUNET_YES)
+    memcpy(message_buf, our_hello, hello_size);
+
   if (peer_address->addr != NULL)
     {
-      ping.header.size = htons(sizeof(struct TransportPingMessage) + 
-                              peer_address->addrlen + 
+      ping.header.size = htons(sizeof(struct TransportPingMessage) +
+                              peer_address->addrlen +
                               slen);
       memcpy(&message_buf[hello_size + sizeof (struct TransportPingMessage)],
-            tp->short_name, 
+            tp->short_name,
             slen);
       memcpy(&message_buf[hello_size + sizeof (struct TransportPingMessage) + slen],
-            peer_address->addr, 
+            peer_address->addr,
             peer_address->addrlen);
     }
   else
@@ -3200,7 +3313,7 @@ send_periodic_ping (void *cls,
 #if DEBUG_TRANSPORT_REVALIDATION
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Performing re-validation of address `%s' via `%s' for peer `%4s' sending `%s' (%u bytes) and `%s'\n",
-              (peer_address->addr != NULL) 
+              (peer_address->addr != NULL)
              ? a2s (peer_address->plugin->short_name,
                     peer_address->addr,
                     peer_address->addrlen)
@@ -3210,6 +3323,13 @@ send_periodic_ping (void *cls,
               "HELLO", hello_size,
               "PING");
 #endif
+  if (peer_address->validated != GNUNET_YES)
+    GNUNET_STATISTICS_update (stats,
+                              gettext_noop ("# PING+HELLO messages sent"),
+                              1,
+                              GNUNET_NO);
+
+
   GNUNET_STATISTICS_update (stats,
                            gettext_noop ("# PING messages sent for re-validation"),
                            1,
@@ -3245,12 +3365,12 @@ schedule_next_ping (struct ForeignAddressList *fal)
     {
       delay = GNUNET_TIME_UNIT_ZERO;
       fal->estimated = GNUNET_YES;
-    }                              
+    }                          
   if (GNUNET_YES == fal->connected)
     {
       delay = GNUNET_TIME_relative_min (delay,
                                        CONNECTED_LATENCY_EVALUATION_MAX_DELAY);
-    }  
+    }
   /* FIXME: also adjust delay based on how close the last
      observed latency is to the latency of the best alternative */
   /* bound how fast we can go */
@@ -3258,9 +3378,9 @@ schedule_next_ping (struct ForeignAddressList *fal)
                                    GNUNET_TIME_UNIT_SECONDS);
   /* randomize a bit (to avoid doing all at the same time) */
   delay.value += GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000);
-  fal->revalidate_task = GNUNET_SCHEDULER_add_delayed(sched, 
+  fal->revalidate_task = GNUNET_SCHEDULER_add_delayed(sched,
                                                      delay,
-                                                     &send_periodic_ping, 
+                                                     &send_periodic_ping,
                                                      fal);
 }
 
@@ -3285,16 +3405,22 @@ handle_payload_message (const struct GNUNET_MessageHeader *message,
   msize = ntohs (message->size);
   if (n->received_pong == GNUNET_NO)
     {
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "Received message of type %u and size %u from `%4s', but no pong yet!!\n",
+                  ntohs (message->type),
+                  ntohs (message->size),
+                  GNUNET_i2s (&n->id));
       GNUNET_free_non_null (n->pre_connect_message_buffer);
       n->pre_connect_message_buffer = GNUNET_malloc (msize);
       memcpy (n->pre_connect_message_buffer, message, msize);
       return;
     }
+
 #if DEBUG_TRANSPORT
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Received message of type %u and size %u from `%4s', sending to all clients.\n",
-             ntohs (message->type), 
-             ntohs (message->size), 
+             ntohs (message->type),
+             ntohs (message->size),
              GNUNET_i2s (&n->id));
 #endif
   if (GNUNET_YES == GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker,
@@ -3302,8 +3428,8 @@ handle_payload_message (const struct GNUNET_MessageHeader *message,
     {
       n->quota_violation_count++;
 #if DEBUG_TRANSPORT
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,                       
-                 "Bandwidth quota (%u b/s) violation detected (total of %u).\n", 
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,                     
+                 "Bandwidth quota (%u b/s) violation detected (total of %u).\n",
                  n->in_tracker.available_bytes_per_s__,
                  n->quota_violation_count);
 #endif
@@ -3311,7 +3437,7 @@ handle_payload_message (const struct GNUNET_MessageHeader *message,
       GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker,
                                        - 32 * 1024);           
     }
-  else 
+  else
     {
       if (n->quota_violation_count > 0)
        {
@@ -3383,15 +3509,18 @@ check_pending_validation (void *cls,
   addr = (const char*) &pong[1];
   slen = strlen (ve->transport_name) + 1;
   if ( (ps - sizeof (struct TransportPongMessage) != ve->addrlen + slen) ||
-       (ve->challenge != challenge) ||       
+       (ve->challenge != challenge) ||
        (addr[slen-1] != '\0') ||
-       (0 != strcmp (addr, ve->transport_name)) || 
-       (ntohl (pong->purpose.size) 
+       (0 != strcmp (addr, ve->transport_name)) ||
+       (ntohl (pong->purpose.size)
        != sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
        sizeof (uint32_t) +
        sizeof (struct GNUNET_TIME_AbsoluteNBO) +
        sizeof (struct GNUNET_PeerIdentity) + ve->addrlen + slen) )
-    return GNUNET_YES;
+    {
+      return GNUNET_YES;
+    }
+
   alen = ps - sizeof (struct TransportPongMessage) - slen;
   switch (ntohl (pong->purpose.purpose))
     {
@@ -3400,24 +3529,26 @@ check_pending_validation (void *cls,
           (0 != memcmp (&addr[slen],
                         ve->addr,
                         ve->addrlen)) )
-       return GNUNET_YES; /* different entry, keep trying! */
-      if ( (0 != memcmp (&pong->pid,
-                        key,
-                        sizeof (struct GNUNET_PeerIdentity))) ||
-          (ve->addrlen == 0) )
+        {
+          return GNUNET_YES; /* different entry, keep trying! */
+        }
+      if (0 != memcmp (&pong->pid,
+                      key,
+                      sizeof (struct GNUNET_PeerIdentity)))
        {
          GNUNET_break_op (0);
          return GNUNET_NO;
        }
       if (GNUNET_OK !=
          GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN,
-                                   &pong->purpose, 
+                                   &pong->purpose,
                                    &pong->signature,
-                                   &ve->publicKey)) 
+                                   &ve->publicKey))
        {
          GNUNET_break_op (0);
          return GNUNET_NO;
        }
+
 #if DEBUG_TRANSPORT
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                  "Confirmed validity of address, peer `%4s' has address `%s' (%s).\n",
@@ -3429,8 +3560,10 @@ check_pending_validation (void *cls,
 #endif
       break;
     case GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_USING:
-      if (ve->addrlen != 0) 
-       return GNUNET_YES; /* different entry, keep trying */
+      if (ve->addrlen != 0)
+        {
+          return GNUNET_YES; /* different entry, keep trying */
+        }
       if ( (0 != memcmp (&pong->pid,
                         &my_identity,
                         sizeof (struct GNUNET_PeerIdentity))) ||
@@ -3457,22 +3590,23 @@ check_pending_validation (void *cls,
        }
       if (oal == NULL)
        {
-         GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+         GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                      _("Not accepting PONG with address `%s' since I cannot confirm having this address.\n"),
                      a2s (ve->transport_name,
                           &addr[slen],
                           alen));
-         return GNUNET_NO;       
+         return GNUNET_NO;     
        }
       if (GNUNET_OK !=
          GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_USING,
-                                   &pong->purpose, 
+                                   &pong->purpose,
                                    &pong->signature,
-                                   &ve->publicKey)) 
+                                   &ve->publicKey))
        {
          GNUNET_break_op (0);
          return GNUNET_NO;
        }
+
 #if DEBUG_TRANSPORT
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                  "Confirmed that peer `%4s' is talking to us using address `%s' (%s) for us.\n",
@@ -3529,7 +3663,7 @@ check_pending_validation (void *cls,
       GNUNET_STATISTICS_update (stats,
                                gettext_noop ("# peer addresses considered valid"),
                                1,
-                               GNUNET_NO);      
+                               GNUNET_NO);
       fal->latency = GNUNET_TIME_absolute_get_duration (ve->send_time);
       schedule_next_ping (fal);
       if (n->latency.value == GNUNET_TIME_UNIT_FOREVER_REL.value)
@@ -3667,7 +3801,7 @@ transmit_hello_and_ping (void *cls,
     {
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                   "Failed to add peer `%4s' for plugin `%s'\n",
-                  GNUNET_i2s (&neighbour->id), 
+                  GNUNET_i2s (&neighbour->id),
                  va->transport_name);
       GNUNET_break (GNUNET_OK ==
                    GNUNET_CONTAINER_multihashmap_remove (validation_map,
@@ -3697,7 +3831,7 @@ transmit_hello_and_ping (void *cls,
 #if DEBUG_TRANSPORT
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Performing validation of address `%s' via `%s' for peer `%4s' sending `%s' (%u bytes) and `%s' (%u bytes)\n",
-             (va->addrlen == 0) 
+             (va->addrlen == 0)
              ? "<inbound>"
              : a2s (va->transport_name,
                     (const void*) &va[1], va->addrlen),
@@ -3710,7 +3844,7 @@ transmit_hello_and_ping (void *cls,
   GNUNET_STATISTICS_update (stats,
                            gettext_noop ("# PING messages sent for initial validation"),
                            1,
-                           GNUNET_NO);      
+                           GNUNET_NO);
   transmit_to_peer (NULL, peer_address,
                    GNUNET_SCHEDULER_PRIORITY_DEFAULT,
                    HELLO_VERIFICATION_TIMEOUT,
@@ -3736,7 +3870,7 @@ static int
 run_validation (void *cls,
                 const char *tname,
                 struct GNUNET_TIME_Absolute expiration,
-                const void *addr, 
+                const void *addr,
                uint16_t addrlen)
 {
   struct CheckHelloValidatedContext *chvc = cls;
@@ -3752,7 +3886,7 @@ run_validation (void *cls,
   GNUNET_STATISTICS_update (stats,
                            gettext_noop ("# peer addresses scheduled for validation"),
                            1,
-                           GNUNET_NO);      
+                           GNUNET_NO);
   tp = find_transport (tname);
   if (tp == NULL)
     {
@@ -3764,7 +3898,7 @@ run_validation (void *cls,
       GNUNET_STATISTICS_update (stats,
                                gettext_noop ("# peer addresses not validated (plugin not available)"),
                                1,
-                               GNUNET_NO);      
+                               GNUNET_NO);
       return GNUNET_OK;
     }
   /* check if this is one of our own addresses */
@@ -3780,7 +3914,7 @@ run_validation (void *cls,
          GNUNET_STATISTICS_update (stats,
                                    gettext_noop ("# peer addresses not validated (loopback)"),
                                    1,
-                                   GNUNET_NO);      
+                                   GNUNET_NO);
          return GNUNET_OK;
        }
       oal = oal->next;
@@ -3795,8 +3929,8 @@ run_validation (void *cls,
     {
 #if DEBUG_TRANSPORT
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  "Attempted to validate blacklisted peer `%s' using `%s'!\n", 
-                 GNUNET_i2s(&id), 
+                  "Attempted to validate blacklisted peer `%s' using `%s'!\n",
+                 GNUNET_i2s(&id),
                  tname);
 #endif
       return GNUNET_OK;
@@ -3826,7 +3960,7 @@ run_validation (void *cls,
       GNUNET_STATISTICS_update (stats,
                                gettext_noop ("# peer addresses not validated (in progress)"),
                                1,
-                               GNUNET_NO);      
+                               GNUNET_NO);
       return GNUNET_OK;
     }
   va = GNUNET_malloc (sizeof (struct ValidationEntry) + addrlen);
@@ -3863,13 +3997,11 @@ run_validation (void *cls,
  * @param cls closure
  * @param peer id of the peer, NULL for last call
  * @param h hello message for the peer (can be NULL)
- * @param trust amount of trust we have in the peer (not used)
  */
 static void
 check_hello_validated (void *cls,
                        const struct GNUNET_PeerIdentity *peer,
-                       const struct GNUNET_HELLO_Message *h, 
-                      uint32_t trust)
+                       const struct GNUNET_HELLO_Message *h)
 {
   struct CheckHelloValidatedContext *chvc = cls;
   struct GNUNET_HELLO_Message *plain_hello;
@@ -3879,6 +4011,10 @@ check_hello_validated (void *cls,
 
   if (peer == NULL)
     {
+      GNUNET_STATISTICS_update (stats,
+                                gettext_noop ("# outstanding peerinfo iterate requests"),
+                                -1,
+                                GNUNET_NO);
       chvc->piter = NULL;
       if (GNUNET_NO == chvc->hello_known)
        {
@@ -3889,11 +4025,11 @@ check_hello_validated (void *cls,
                              sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
                              &target.hashPubKey);
          plain_hello = GNUNET_HELLO_create (&pk,
-                                            NULL, 
+                                            NULL,
                                             NULL);
          GNUNET_PEERINFO_add_peer (peerinfo, plain_hello);
          GNUNET_free (plain_hello);
-#if DEBUG_TRANSPORT
+#if DEBUG_TRANSPORT_HELLO
          GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                      "PEERINFO had no `%s' message for peer `%4s', full validation needed.\n",
                      "HELLO",
@@ -3902,10 +4038,10 @@ check_hello_validated (void *cls,
          GNUNET_STATISTICS_update (stats,
                                    gettext_noop ("# new HELLOs requiring full validation"),
                                    1,
-                                   GNUNET_NO);      
+                                   GNUNET_NO);
          GNUNET_HELLO_iterate_addresses (chvc->hello,
-                                         GNUNET_NO, 
-                                         &run_validation, 
+                                         GNUNET_NO,
+                                         &run_validation,
                                          chvc);
        }
       else
@@ -3913,7 +4049,7 @@ check_hello_validated (void *cls,
          GNUNET_STATISTICS_update (stats,
                                    gettext_noop ("# duplicate HELLO (peer known)"),
                                    1,
-                                   GNUNET_NO);      
+                                   GNUNET_NO);
        }
       chvc->ve_count--;
       if (chvc->ve_count == 0)
@@ -3921,13 +4057,13 @@ check_hello_validated (void *cls,
          GNUNET_CONTAINER_DLL_remove (chvc_head,
                                       chvc_tail,
                                       chvc);
-         GNUNET_free (chvc);     
+         GNUNET_free (chvc);   
        }
       return;
-    } 
+    }
   if (h == NULL)
     return;
-#if DEBUG_TRANSPORT
+#if DEBUG_TRANSPORT_HELLO
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "PEERINFO had `%s' message for peer `%4s', validating only new addresses.\n",
              "HELLO",
@@ -3937,6 +4073,11 @@ check_hello_validated (void *cls,
   n = find_neighbour (peer);
   if (n != NULL)
     {
+#if DEBUG_TRANSPORT_HELLO
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "Calling hello_iterate_addresses for %s!\n",
+                  GNUNET_i2s (peer));
+#endif
       GNUNET_HELLO_iterate_addresses (h,
                                      GNUNET_NO,
                                      &add_to_foreign_address_list,
@@ -3945,19 +4086,24 @@ check_hello_validated (void *cls,
     }
   else
     {
+#if DEBUG_TRANSPORT_HELLO
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "No existing neighbor record for %s!\n",
+                  GNUNET_i2s (peer));
+#endif
       GNUNET_STATISTICS_update (stats,
                                gettext_noop ("# no existing neighbour record (validating HELLO)"),
                                1,
-                               GNUNET_NO);      
+                               GNUNET_NO);
     }
   GNUNET_STATISTICS_update (stats,
                            gettext_noop ("# HELLO validations (update case)"),
                            1,
-                           GNUNET_NO);      
+                           GNUNET_NO);
   GNUNET_HELLO_iterate_new_addresses (chvc->hello,
                                      h,
                                      GNUNET_TIME_relative_to_absolute (HELLO_REVALIDATION_START_TIME),
-                                     &run_validation, 
+                                     &run_validation,
                                      chvc);
 }
 
@@ -3978,7 +4124,7 @@ process_hello (struct TransportPlugin *plugin,
   const struct GNUNET_HELLO_Message *hello;
   struct CheckHelloValidatedContext *chvc;
   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded publicKey;
-#if DEBUG_TRANSPORT_HELLO
+#if DEBUG_TRANSPORT_HELLO > 2
   char *my_id;
 #endif
   hsize = ntohs (message->size);
@@ -3991,7 +4137,8 @@ process_hello (struct TransportPlugin *plugin,
   GNUNET_STATISTICS_update (stats,
                            gettext_noop ("# HELLOs received for validation"),
                            1,
-                           GNUNET_NO);      
+                           GNUNET_NO);
+
   /* first, check if load is too high */
   if (GNUNET_SCHEDULER_get_load (sched,
                                 GNUNET_SCHEDULER_PRIORITY_BACKGROUND) > MAX_HELLO_LOAD)
@@ -3999,7 +4146,7 @@ process_hello (struct TransportPlugin *plugin,
       GNUNET_STATISTICS_update (stats,
                                gettext_noop ("# HELLOs ignored due to high load"),
                                1,
-                               GNUNET_NO);      
+                               GNUNET_NO);
 #if DEBUG_TRANSPORT_HELLO
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   "Ignoring `%s' for `%4s', load too high.\n",
@@ -4020,9 +4167,18 @@ process_hello (struct TransportPlugin *plugin,
       GNUNET_break_op (0);
       return GNUNET_SYSERR;
     }
+
   GNUNET_CRYPTO_hash (&publicKey,
                       sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
                       &target.hashPubKey);
+
+#if DEBUG_TRANSPORT_HELLO
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Received `%s' message for `%4s'\n",
+              "HELLO",
+              GNUNET_i2s (&target));
+#endif
+
   if (0 == memcmp (&my_identity,
                   &target,
                   sizeof (struct GNUNET_PeerIdentity)))
@@ -4030,8 +4186,8 @@ process_hello (struct TransportPlugin *plugin,
       GNUNET_STATISTICS_update (stats,
                                gettext_noop ("# HELLOs ignored for validation (is my own HELLO)"),
                                1,
-                               GNUNET_NO);      
-      return GNUNET_OK;      
+                               GNUNET_NO);
+      return GNUNET_OK;
     }
   chvc = chvc_head;
   while (NULL != chvc)
@@ -4040,10 +4196,10 @@ process_hello (struct TransportPlugin *plugin,
                               chvc->hello,
                               GNUNET_TIME_absolute_get ()).value > 0)
        {
-#if DEBUG_TRANSPORT_HELLO
+#if DEBUG_TRANSPORT_HELLO > 2
          GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                      "Received duplicate `%s' message for `%4s'; ignored\n",
-                     "HELLO", 
+                     "HELLO",
                      GNUNET_i2s (&target));
 #endif
          return GNUNET_OK; /* validation already pending */
@@ -4053,7 +4209,7 @@ process_hello (struct TransportPlugin *plugin,
                                   GNUNET_HELLO_size(hello)));
       chvc = chvc->next;
     }
-#if DEBUG_TRANSPORT_HELLO
+#if DEBUG_TRANSPORT_HELLO > 2
   if (plugin != NULL)
     {
       my_id = GNUNET_strdup(GNUNET_i2s(plugin->env.my_identity));
@@ -4076,9 +4232,16 @@ process_hello (struct TransportPlugin *plugin,
                               chvc);
   /* finally, check if HELLO was previously validated
      (continuation will then schedule actual validation) */
+  GNUNET_STATISTICS_update (stats,
+                            gettext_noop ("# peerinfo process hello iterate requests"),
+                            1,
+                            GNUNET_NO);
+  GNUNET_STATISTICS_update (stats,
+                            gettext_noop ("# outstanding peerinfo iterate requests"),
+                            1,
+                            GNUNET_NO);
   chvc->piter = GNUNET_PEERINFO_iterate (peerinfo,
                                          &target,
-                                         0,
                                          HELLO_VERIFICATION_TIMEOUT,
                                          &check_hello_validated, chvc);
   return GNUNET_OK;
@@ -4094,9 +4257,9 @@ process_hello (struct TransportPlugin *plugin,
  * gone.
  *
  * @param n the neighbour list entry for the peer
- * @param check should we just check if all plugins
- *        disconnected or must we ask all plugins to
- *        disconnect?
+ * @param check GNUNET_YES to check if ALL addresses for this peer
+ *              are gone, GNUNET_NO to force a disconnect of the peer
+ *              regardless of whether other addresses exist.
  */
 static void
 disconnect_neighbour (struct NeighbourList *n, int check)
@@ -4117,7 +4280,12 @@ disconnect_neighbour (struct NeighbourList *n, int check)
           while (peer_addresses != NULL)
             {
               if (GNUNET_YES == peer_addresses->connected)
-                return;             /* still connected */
+                {
+                  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                            "NOT Disconnecting from `%4s', still have live addresses!\n",
+                            GNUNET_i2s (&n->id));
+                  return;             /* still connected */
+                }
               peer_addresses = peer_addresses->next;
             }
           rpos = rpos->next;
@@ -4159,12 +4327,12 @@ disconnect_neighbour (struct NeighbourList *n, int check)
            GNUNET_STATISTICS_update (stats,
                                      gettext_noop ("# connected addresses"),
                                      -1,
-                                     GNUNET_NO); 
+                                     GNUNET_NO);
          if (GNUNET_YES == peer_pos->validated)
            GNUNET_STATISTICS_update (stats,
                                      gettext_noop ("# peer addresses considered valid"),
                                      -1,
-                                     GNUNET_NO);      
+                                     GNUNET_NO);
          if (GNUNET_SCHEDULER_NO_TASK != peer_pos->revalidate_task)
            {
              GNUNET_SCHEDULER_cancel (sched,
@@ -4190,7 +4358,7 @@ disconnect_neighbour (struct NeighbourList *n, int check)
       GNUNET_CONTAINER_DLL_remove (n->messages_head,
                                   n->messages_tail,
                                   mq);
-      GNUNET_assert (0 == memcmp(&mq->neighbour_id, 
+      GNUNET_assert (0 == memcmp(&mq->neighbour_id,
                                 &n->id,
                                 sizeof(struct GNUNET_PeerIdentity)));
       GNUNET_free (mq);
@@ -4208,6 +4376,10 @@ disconnect_neighbour (struct NeighbourList *n, int check)
   if (n->piter != NULL)
     {
       GNUNET_PEERINFO_iterate_cancel (n->piter);
+      GNUNET_STATISTICS_update (stats,
+                                gettext_noop ("# outstanding peerinfo iterate requests"),
+                                -1,
+                                GNUNET_NO);
       n->piter = NULL;
     }
   /* finally, free n itself */
@@ -4222,9 +4394,9 @@ disconnect_neighbour (struct NeighbourList *n, int check)
 
 /**
  * We have received a PING message from someone.  Need to send a PONG message
- * in response to the peer by any means necessary. 
+ * in response to the peer by any means necessary.
  */
-static int 
+static int
 handle_ping(void *cls, const struct GNUNET_MessageHeader *message,
            const struct GNUNET_PeerIdentity *peer,
            struct Session *session,
@@ -4255,17 +4427,23 @@ handle_ping(void *cls, const struct GNUNET_MessageHeader *message,
                    sizeof (struct GNUNET_PeerIdentity)))
     {
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                  _("Received `%s' message not destined for me!\n"), 
-                 "PING");
+                  _("Received `%s' message from `%s' destined for `%s' which is not me!\n"),
+                 "PING",
+                 (sender_address != NULL)
+                 ? a2s (plugin->short_name,
+                        (const struct sockaddr *)sender_address,
+                        sender_address_len)
+                 : "<inbound>",
+                 GNUNET_i2s (&ping->target));
       return GNUNET_SYSERR;
     }
 #if DEBUG_PING_PONG
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
              "Processing `%s' from `%s'\n",
-             "PING", 
-             (sender_address != NULL) 
+             "PING",
+             (sender_address != NULL)
              ? a2s (plugin->short_name,
-                    (const struct sockaddr *)sender_address, 
+                    (const struct sockaddr *)sender_address,
                     sender_address_len)
              : "<inbound>");
 #endif
@@ -4277,7 +4455,7 @@ handle_ping(void *cls, const struct GNUNET_MessageHeader *message,
   alen = ntohs (message->size) - sizeof (struct TransportPingMessage);
   slen = strlen (plugin->short_name) + 1;
   if (alen == 0)
-    {      
+    {
       /* peer wants to confirm that we have an outbound connection to him */
       if (session == NULL)
        {
@@ -4297,14 +4475,14 @@ handle_ping(void *cls, const struct GNUNET_MessageHeader *message,
       pong->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_USING);
       pong->challenge = ping->challenge;
       pong->addrlen = htonl(sender_address_len + slen);
-      memcpy(&pong->pid, 
+      memcpy(&pong->pid,
             peer,
             sizeof(struct GNUNET_PeerIdentity));
-      memcpy (&pong[1], 
-             plugin->short_name, 
+      memcpy (&pong[1],
+             plugin->short_name,
              slen);
-      memcpy (&((char*)&pong[1])[slen], 
-             sender_address, 
+      memcpy (&((char*)&pong[1])[slen],
+             sender_address,
              sender_address_len);
       if (GNUNET_TIME_absolute_get_remaining (session_header->pong_sig_expires).value < PONG_SIGNATURE_LIFETIME.value / 4)
        {
@@ -4326,7 +4504,7 @@ handle_ping(void *cls, const struct GNUNET_MessageHeader *message,
        }
       memcpy (&pong->signature,
              &session_header->pong_signature,
-             sizeof (struct GNUNET_CRYPTO_RsaSignature));    
+             sizeof (struct GNUNET_CRYPTO_RsaSignature));
 
 
     }
@@ -4335,6 +4513,18 @@ handle_ping(void *cls, const struct GNUNET_MessageHeader *message,
       /* peer wants to confirm that this is one of our addresses */
       addr += slen;
       alen -= slen;
+      if (GNUNET_OK !=
+         plugin->api->check_address (plugin->api->cls,
+                                     addr,
+                                     alen))
+       {
+         GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                     _("Not confirming PING with address `%s' since I cannot confirm having this address.\n"),
+                     a2s (plugin->short_name,
+                          addr,
+                          alen));
+         return GNUNET_NO;
+       }
       oal = plugin->addresses;
       while (NULL != oal)
        {
@@ -4345,15 +4535,6 @@ handle_ping(void *cls, const struct GNUNET_MessageHeader *message,
            break;
          oal = oal->next;
        }
-      if (oal == NULL)
-       {
-         GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                     _("Not confirming PING with address `%s' since I cannot confirm having this address.\n"),
-                     a2s (plugin->short_name,
-                          addr,
-                          alen));
-         return GNUNET_NO;
-       }
       pong = GNUNET_malloc (sizeof (struct TransportPongMessage) + alen + slen);
       pong->header.size = htons (sizeof (struct TransportPongMessage) + alen + slen);
       pong->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PONG);
@@ -4365,12 +4546,13 @@ handle_ping(void *cls, const struct GNUNET_MessageHeader *message,
       pong->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN);
       pong->challenge = ping->challenge;
       pong->addrlen = htonl(alen + slen);
-      memcpy(&pong->pid, 
-            &my_identity, 
+      memcpy(&pong->pid,
+            &my_identity,
             sizeof(struct GNUNET_PeerIdentity));
       memcpy (&pong[1], plugin->short_name, slen);
-      memcpy (&((char*)&pong[1])[slen], &oal[1], alen);
-      if (GNUNET_TIME_absolute_get_remaining (oal->pong_sig_expires).value < PONG_SIGNATURE_LIFETIME.value / 4)
+      memcpy (&((char*)&pong[1])[slen], addr, alen);
+      if ( (oal != NULL) &&
+          (GNUNET_TIME_absolute_get_remaining (oal->pong_sig_expires).value < PONG_SIGNATURE_LIFETIME.value / 4) )
        {
          /* create / update cached sig */
 #if DEBUG_TRANSPORT
@@ -4383,15 +4565,28 @@ handle_ping(void *cls, const struct GNUNET_MessageHeader *message,
          GNUNET_assert (GNUNET_OK ==
                         GNUNET_CRYPTO_rsa_sign (my_private_key,
                                                 &pong->purpose,
-                                                &oal->pong_signature));
+                                                &oal->pong_signature));        
+         memcpy (&pong->signature,
+                 &oal->pong_signature,
+                 sizeof (struct GNUNET_CRYPTO_RsaSignature));
+       }
+      else if (oal == NULL)
+       {
+         /* not using cache (typically DV-only) */
+         pong->expiration = GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (PONG_SIGNATURE_LIFETIME));
+         GNUNET_assert (GNUNET_OK ==
+                        GNUNET_CRYPTO_rsa_sign (my_private_key,
+                                                &pong->purpose,
+                                                &pong->signature));    
        }
       else
        {
+         /* can used cached version */
          pong->expiration = GNUNET_TIME_absolute_hton (oal->pong_sig_expires);
+         memcpy (&pong->signature,
+                 &oal->pong_signature,
+                 sizeof (struct GNUNET_CRYPTO_RsaSignature));
        }
-      memcpy (&pong->signature,
-             &oal->pong_signature,
-             sizeof (struct GNUNET_CRYPTO_RsaSignature));    
     }
   n = find_neighbour(peer);
   GNUNET_assert (n != NULL);
@@ -4406,7 +4601,7 @@ handle_ping(void *cls, const struct GNUNET_MessageHeader *message,
                                           peer,
                                           (const char*) pong,
                                           ntohs (pong->header.size),
-                                          TRANSPORT_PONG_PRIORITY, 
+                                          TRANSPORT_PONG_PRIORITY,
                                           HELLO_VERIFICATION_TIMEOUT,
                                           fal->session,
                                           fal->addr,
@@ -4418,7 +4613,7 @@ handle_ping(void *cls, const struct GNUNET_MessageHeader *message,
              GNUNET_STATISTICS_update (stats,
                                        gettext_noop ("# PONGs unicast via reliable transport"),
                                        1,
-                                       GNUNET_NO);      
+                                       GNUNET_NO);
              GNUNET_free (pong);
              return GNUNET_OK;
            }
@@ -4430,7 +4625,7 @@ handle_ping(void *cls, const struct GNUNET_MessageHeader *message,
   GNUNET_STATISTICS_update (stats,
                            gettext_noop ("# PONGs multicast to all available addresses"),
                            1,
-                           GNUNET_NO);      
+                           GNUNET_NO);
   rl = n->plugins;
   while (rl != NULL)
     {
@@ -4438,11 +4633,11 @@ handle_ping(void *cls, const struct GNUNET_MessageHeader *message,
       while (fal != NULL)
        {
          transmit_to_peer(NULL, fal,
-                          TRANSPORT_PONG_PRIORITY, 
+                          TRANSPORT_PONG_PRIORITY,
                           HELLO_VERIFICATION_TIMEOUT,
-                          (const char *)pong, 
-                          ntohs(pong->header.size), 
-                          GNUNET_YES, 
+                          (const char *)pong,
+                          ntohs(pong->header.size),
+                          GNUNET_YES,
                           n);
          fal = fal->next;
        }
@@ -4484,7 +4679,6 @@ plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
   uint16_t msize;
   struct NeighbourList *n;
   struct GNUNET_TIME_Relative ret;
-
   if (is_blacklisted (peer, plugin))
     return GNUNET_TIME_UNIT_FOREVER_REL;
 
@@ -4500,11 +4694,11 @@ plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
     {
       if ( (session != NULL) ||
           (sender_address != NULL) )
-       peer_address = add_peer_address (n, 
+       peer_address = add_peer_address (n,
                                         plugin->short_name,
                                         session,
-                                        sender_address, 
-                                        sender_address_len);  
+                                        sender_address,
+                                        sender_address_len);
       if (peer_address != NULL)
        {
          peer_address->distance = distance;
@@ -4517,7 +4711,7 @@ plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
          schedule_next_ping (peer_address);
        }
       /* update traffic received amount ... */
-      msize = ntohs (message->size);      
+      msize = ntohs (message->size);
       GNUNET_STATISTICS_update (stats,
                                gettext_noop ("# bytes received from other peers"),
                                msize,
@@ -4538,7 +4732,7 @@ plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
          GNUNET_log (GNUNET_ERROR_TYPE_WARNING |
                      GNUNET_ERROR_TYPE_BULK,
                      _
-                     ("Dropping incoming message due to repeated bandwidth quota (%u b/s) violations (total of %u).\n"), 
+                     ("Dropping incoming message due to repeated bandwidth quota (%u b/s) violations (total of %u).\n"),
                      n->in_tracker.available_bytes_per_s__,
                      n->quota_violation_count);
          GNUNET_STATISTICS_update (stats,
@@ -4547,11 +4741,12 @@ plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
                                    GNUNET_NO);
          return GNUNET_CONSTANTS_QUOTA_VIOLATION_TIMEOUT;
        }
+
 #if DEBUG_PING_PONG
           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                       "Received message of type %u and size %u from `%4s', sending to all clients.\n",
-                      ntohs (message->type), 
-                      ntohs (message->size), 
+                      ntohs (message->type),
+                      ntohs (message->size),
                      GNUNET_i2s (peer));
 #endif
       switch (ntohs (message->type))
@@ -4573,11 +4768,11 @@ plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
          handle_payload_message (message, n);
          break;
        }
-    }  
+    }
   ret = GNUNET_BANDWIDTH_tracker_get_delay (&n->in_tracker, 0);
   if (ret.value > 0)
     {
-      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                  "Throttling read (%llu bytes excess at %u b/s), waiting %llums before reading more.\n",
                  (unsigned long long) n->in_tracker.consumption_since_last_update__,
                  (unsigned int) n->in_tracker.available_bytes_per_s__,
@@ -4585,7 +4780,7 @@ plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
       GNUNET_STATISTICS_update (stats,
                                gettext_noop ("# ms throttling suggested"),
                                (int64_t) ret.value,
-                               GNUNET_NO);      
+                               GNUNET_NO);
     }
   return ret;
 }
@@ -4603,10 +4798,12 @@ handle_start (void *cls,
               struct GNUNET_SERVER_Client *client,
               const struct GNUNET_MessageHeader *message)
 {
+  const struct StartMessage *start;
   struct TransportClient *c;
   struct ConnectInfoMessage cim;
   struct NeighbourList *n;
 
+  start = (const struct StartMessage*) message;
 #if DEBUG_TRANSPORT
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Received `%s' request from client\n", "START");
@@ -4623,6 +4820,17 @@ handle_start (void *cls,
         }
       c = c->next;
     }
+  if ( (GNUNET_NO != ntohl (start->do_check)) &&
+       (0 != memcmp (&start->self,
+                    &my_identity,
+                    sizeof (struct GNUNET_PeerIdentity))) )
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                 _("Rejecting control connection from peer `%s', which is not me!\n"),
+                 GNUNET_i2s (&start->self));
+      GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+      return;
+    }
   c = GNUNET_malloc (sizeof (struct TransportClient));
   c->next = clients;
   clients = c;
@@ -4639,7 +4847,7 @@ handle_start (void *cls,
       /* tell new client about all existing connections */
       cim.header.size = htons (sizeof (struct ConnectInfoMessage));
       cim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
-      n = neighbours; 
+      n = neighbours;
       while (n != NULL)
        {
          if (GNUNET_YES == n->received_pong)
@@ -4673,7 +4881,7 @@ handle_hello (void *cls,
   GNUNET_STATISTICS_update (stats,
                            gettext_noop ("# HELLOs received from clients"),
                            1,
-                           GNUNET_NO);      
+                           GNUNET_NO);
   ret = process_hello (NULL, message);
   GNUNET_SERVER_receive_done (client, ret);
 }
@@ -4683,7 +4891,7 @@ handle_hello (void *cls,
  * Closure for 'transmit_client_message'; followed by
  * 'msize' bytes of the actual message.
  */
-struct TransmitClientMessageContext 
+struct TransmitClientMessageContext
 {
   /**
    * Client on whom's behalf we are sending.
@@ -4694,7 +4902,7 @@ struct TransmitClientMessageContext
    * Timeout for the transmission.
    */
   struct GNUNET_TIME_Absolute timeout;
-  
+
   /**
    * Message priority.
    */
@@ -4702,7 +4910,7 @@ struct TransmitClientMessageContext
 
   /**
    * Size of the message in bytes.
-   */ 
+   */
   uint16_t msize;
 };
 
@@ -4726,7 +4934,7 @@ transmit_client_message (void *cls,
 
   if (n != NULL)
     {
-      transmit_to_peer (tc, NULL, tcmc->priority, 
+      transmit_to_peer (tc, NULL, tcmc->priority,
                        GNUNET_TIME_absolute_get_remaining (tcmc->timeout),
                        (char *)&tcmc[1],
                        tcmc->msize, GNUNET_NO, n);
@@ -4766,22 +4974,23 @@ handle_send (void *cls,
   GNUNET_STATISTICS_update (stats,
                            gettext_noop ("# payload received for other peers"),
                            size,
-                           GNUNET_NO);      
+                           GNUNET_NO);
   obm = (const struct OutboundMessage *) message;
   obmm = (const struct GNUNET_MessageHeader *) &obm[1];
   msize = size - sizeof (struct OutboundMessage);
-#if DEBUG_TRANSPORT
+
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Received `%s' request from client with target `%4s' and message of type %u and size %u\n",
               "SEND", GNUNET_i2s (&obm->peer),
               ntohs (obmm->type),
               msize);
-#endif
+
   tcmc = GNUNET_malloc (sizeof (struct TransmitClientMessageContext) + msize);
   tcmc->client = client;
   tcmc->priority = ntohl (obm->priority);
   tcmc->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_ntoh (obm->timeout));
   tcmc->msize = msize;
+  /* FIXME: this memcpy can be up to 7% of our total runtime */
   memcpy (&tcmc[1], obmm, msize);
   GNUNET_SERVER_client_keep (client);
   setup_peer_check_blacklist (&obm->peer, GNUNET_YES,
@@ -4790,6 +4999,31 @@ handle_send (void *cls,
 }
 
 
+/**
+ * Handle request connect message
+ *
+ * @param cls closure (always NULL)
+ * @param client identification of the client
+ * @param message the actual message
+ */
+static void
+handle_request_connect (void *cls,
+                        struct GNUNET_SERVER_Client *client,
+                        const struct GNUNET_MessageHeader *message)
+{
+  const struct TransportRequestConnectMessage *trcm =
+    (const struct TransportRequestConnectMessage *) message;
+
+  GNUNET_STATISTICS_update (stats,
+                            gettext_noop ("# REQUEST CONNECT messages received"),
+                            1,
+                            GNUNET_NO);
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received a request connect message for peer %s\n", GNUNET_i2s(&trcm->peer));
+  setup_peer_check_blacklist (&trcm->peer, GNUNET_YES,
+                              NULL, NULL);
+  GNUNET_SERVER_receive_done (client, GNUNET_OK);
+}
+
 /**
  * Handle SET_QUOTA-message.
  *
@@ -4805,11 +5039,11 @@ handle_set_quota (void *cls,
   const struct QuotaSetMessage *qsm =
     (const struct QuotaSetMessage *) message;
   struct NeighbourList *n;
-  
+
   GNUNET_STATISTICS_update (stats,
                            gettext_noop ("# SET QUOTA messages received"),
                            1,
-                           GNUNET_NO);      
+                           GNUNET_NO);
   n = find_neighbour (&qsm->peer);
   if (n == NULL)
     {
@@ -4817,21 +5051,26 @@ handle_set_quota (void *cls,
       GNUNET_STATISTICS_update (stats,
                                gettext_noop ("# SET QUOTA messages ignored (no such peer)"),
                                1,
-                               GNUNET_NO);      
+                               GNUNET_NO);
       return;
     }
 #if DEBUG_TRANSPORT
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Received `%s' request (new quota %u, old quota %u) from client for peer `%4s'\n",
-              "SET_QUOTA", 
+              "SET_QUOTA",
              (unsigned int) ntohl (qsm->quota.value__),
              (unsigned int) n->in_tracker.available_bytes_per_s__,
              GNUNET_i2s (&qsm->peer));
 #endif
   GNUNET_BANDWIDTH_tracker_update_quota (&n->in_tracker,
                                         qsm->quota);
-  if (0 == ntohl (qsm->quota.value__)) 
-    disconnect_neighbour (n, GNUNET_NO);    
+  if (0 == ntohl (qsm->quota.value__))
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Disconnecting peer `%4s', %s\n", GNUNET_i2s(&n->id),
+                "SET_QUOTA");
+      disconnect_neighbour (n, GNUNET_NO);
+    }
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }
 
@@ -4839,7 +5078,7 @@ handle_set_quota (void *cls,
 /**
  * Take the given address and append it to the set of results sent back to
  * the client.
- * 
+ *
  * @param cls the transmission context used ('struct GNUNET_SERVER_TransmitContext*')
  * @param address the resolved name, NULL to indicate the last response
  */
@@ -4922,7 +5161,7 @@ handle_address_lookup (void *cls,
   tc = GNUNET_SERVER_transmit_context_create (client);
   lsPlugin->api->address_pretty_printer (lsPlugin->api->cls,
                                         nameTransport,
-                                         address, addressLen, 
+                                         address, addressLen,
                                         numeric,
                                          rtimeout,
                                          &transmit_address_to_client, tc);
@@ -4938,6 +5177,7 @@ create_environment (struct TransportPlugin *plug)
   plug->env.cfg = cfg;
   plug->env.sched = sched;
   plug->env.my_identity = &my_identity;
+  plug->env.our_hello = &our_hello;
   plug->env.cls = plug;
   plug->env.receive = &plugin_env_receive;
   plug->env.notify_address = &plugin_env_notify_address;
@@ -4951,7 +5191,7 @@ create_environment (struct TransportPlugin *plug)
  * Start the specified transport (load the plugin).
  */
 static void
-start_transport (struct GNUNET_SERVER_Handle *server, 
+start_transport (struct GNUNET_SERVER_Handle *server,
                 const char *name)
 {
   struct TransportPlugin *plug;
@@ -5017,7 +5257,7 @@ client_disconnect_notification (void *cls,
                  if (bc->th != NULL)
                    {
                      GNUNET_CONNECTION_notify_transmit_ready_cancel (bc->th);
-                     bc->th = NULL;                  
+                     bc->th = NULL;            
                    }
                  if (bc->task == GNUNET_SCHEDULER_NO_TASK)
                    bc->task = GNUNET_SCHEDULER_add_now (sched,
@@ -5088,7 +5328,12 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   struct CheckHelloValidatedContext *chvc;
 
   while (neighbours != NULL)
-    disconnect_neighbour (neighbours, GNUNET_NO);
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Disconnecting peer `%4s', %s\n", GNUNET_i2s(&neighbours->id),
+              "SHUTDOWN_TASK");
+      disconnect_neighbour (neighbours, GNUNET_NO);
+    }
 #if DEBUG_TRANSPORT
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Transport service is unloading plugins...\n");
@@ -5098,7 +5343,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
       plugins = plug->next;
       if (plug->address_update_task != GNUNET_SCHEDULER_NO_TASK)
        {
-         GNUNET_SCHEDULER_cancel (plug->env.sched, 
+         GNUNET_SCHEDULER_cancel (plug->env.sched,
                                   plug->address_update_task);
          plug->address_update_task = GNUNET_SCHEDULER_NO_TASK;
        }
@@ -5127,7 +5372,13 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
     {
       chvc_head = chvc->next;
       if (chvc->piter != NULL)
-       GNUNET_PEERINFO_iterate_cancel (chvc->piter);      
+        {
+          GNUNET_PEERINFO_iterate_cancel (chvc->piter);
+          GNUNET_STATISTICS_update (stats,
+                                    gettext_noop ("# outstanding peerinfo iterate requests"),
+                                    -1,
+                                    GNUNET_NO);
+        }
       else
        GNUNET_break (0);
       GNUNET_assert (chvc->ve_count == 0);
@@ -5168,11 +5419,13 @@ run (void *cls,
 {
   static const struct GNUNET_SERVER_MessageHandler handlers[] = {
     {&handle_start, NULL,
-     GNUNET_MESSAGE_TYPE_TRANSPORT_START, 0},
+     GNUNET_MESSAGE_TYPE_TRANSPORT_START, sizeof (struct StartMessage)},
     {&handle_hello, NULL,
      GNUNET_MESSAGE_TYPE_HELLO, 0},
     {&handle_send, NULL,
      GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, 0},
+    {&handle_request_connect, NULL,
+     GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT, sizeof(struct TransportRequestConnectMessage)},
     {&handle_set_quota, NULL,
      GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA, sizeof (struct QuotaSetMessage)},
     {&handle_address_lookup, NULL,
@@ -5223,7 +5476,7 @@ run (void *cls,
   if (peerinfo == NULL)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                 _("Could not access PEERINFO service.  Exiting.\n"));     
+                 _("Could not access PEERINFO service.  Exiting.\n")); 
       GNUNET_SCHEDULER_shutdown (s);
       if (stats != NULL)
        {