new operation queue for limiting overlay connects
[oweals/gnunet.git] / src / transport / gnunet-service-transport_validation.c
index 49bfdd31719f1d828c9da84b4d3b7eb07ef561d0..ab334013dce5d698f559b3cb10206cb61d1ab12c 100644 (file)
@@ -34,7 +34,7 @@
 #include "gnunet_peerinfo_service.h"
 #include "gnunet_signatures.h"
 
-#define KEEP_093_COMPATIBILITY GNUNET_YES
+#define KEEP_093_COMPATIBILITY GNUNET_NO
 
 /**
  * How long is a PONG signature valid?  We'll recycle a signature until
@@ -696,7 +696,8 @@ process_peerinfo_hello (void *cls, const struct GNUNET_PeerIdentity *peer,
 void
 GST_validation_start ()
 {
-  validation_map = GNUNET_CONTAINER_multihashmap_create (VALIDATION_MAP_SIZE);
+  validation_map = GNUNET_CONTAINER_multihashmap_create (VALIDATION_MAP_SIZE,
+                                                        GNUNET_NO);
   pnc = GNUNET_PEERINFO_notify (GST_cfg, &process_peerinfo_hello, NULL);
 }
 
@@ -819,7 +820,7 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
   sig_cache = NULL;
   sig_cache_exp = NULL;
 
-  if (0 < alen)
+  if (alen > 0)
   {
     addrend = memchr (addr, '\0', alen);
     if (NULL == addrend)
@@ -885,6 +886,14 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
     sig_cache_exp = &no_address_signature_expiration;
   }
 
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "I am `%s', sending PONG to peer `%s'\n",
+             GNUNET_h2s (&GST_my_identity.hashPubKey),
+              GNUNET_i2s (sender));
+
+  /* message with structure:
+   * [TransportPongMessage][Transport name][Address] */
+
   pong = GNUNET_malloc (sizeof (struct TransportPongMessage) + alen + slen);
   pong->header.size =
       htons (sizeof (struct TransportPongMessage) + alen + slen);
@@ -894,9 +903,9 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
              sizeof (uint32_t) + sizeof (struct GNUNET_TIME_AbsoluteNBO) +
              alen + slen);
   pong->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN);
-  pong->challenge = ping->challenge;
+  memcpy (&pong->challenge, &ping->challenge, sizeof (ping->challenge));
   pong->addrlen = htonl (alen + slen);
-  memcpy (&pong[1], addr, slen);
+  memcpy (&pong[1], addr, slen);   /* Copy transport plugin */
 #if KEEP_093_COMPATIBILITY
   if (GNUNET_YES == buggy)
   {
@@ -907,7 +916,7 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
     }
     else if (alen <= (idsize + strlen (address.transport_name) + 1))
     {
-      memcpy (&((char *) &pong[1])[slen], &GST_my_identity, alen);
+      memcpy (&((char *) &pong[1])[slen], &GST_my_identity, idsize);
       memcpy (&((char *) &pong[1])[slen + idsize], address.transport_name, alen-idsize);
     }
     else
@@ -926,7 +935,11 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
   else
   {
 #endif
-    memcpy (&((char *) &pong[1])[slen], addrend, alen);
+    if (alen > 0)
+    {
+        GNUNET_assert (NULL != addrend);
+        memcpy (&((char *) &pong[1])[slen], addrend, alen);
+    }
     if (GNUNET_TIME_absolute_get_remaining (*sig_cache_exp).rel_value <
         PONG_SIGNATURE_LIFETIME.rel_value / 4)
     {
@@ -1096,6 +1109,9 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
                             gettext_noop ("# PONG messages received"), 1,
                             GNUNET_NO);
 
+  /* message with structure:
+   * [TransportPongMessage][Transport name][Address] */
+
   pong = (const struct TransportPongMessage *) hdr;
   tname = (const char *) &pong[1];
   size = ntohs (hdr->size) - sizeof (struct TransportPongMessage);
@@ -1134,6 +1150,10 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
                                 &ve->public_key))
   {
     GNUNET_break_op (0);
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+               "Invalid signature on address %s:%s from peer `%s'\n",
+               tname, GST_plugins_a2s (ve->address),
+               GNUNET_i2s (sender));
     return;
   }