gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet] 03/03: add GNUNET_B2S() macro; fix dht_line_test: we sign over


From: gnunet
Subject: [gnunet] 03/03: add GNUNET_B2S() macro; fix dht_line_test: we sign over query_hash, not block key
Date: Fri, 25 Feb 2022 08:49:19 +0100

This is an automated email from the git hooks/post-receive script.

martin-schanzenbach pushed a commit to branch master
in repository gnunet.

commit 5e4cbb92beb575ad5b072334b42d66feb0f0c331
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Fri Feb 25 00:46:09 2022 +0100

    add GNUNET_B2S() macro; fix dht_line_test: we sign over query_hash, not 
block key
---
 src/dht/dht_api.c                       |  7 ++-
 src/dht/gnunet-service-dht_clients.c    | 31 +++++++++--
 src/dht/gnunet-service-dht_neighbours.c | 91 +++++++++++++++++++++++++++++----
 src/dht/gnunet-service-dht_routing.c    |  3 +-
 src/dht/test_dht_topo.c                 |  1 +
 src/include/gnunet_common.h             | 27 +++++++++-
 src/util/common_logging.c               | 25 ++++++++-
 7 files changed, 168 insertions(+), 17 deletions(-)

diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c
index cae8de726..d60653dd4 100644
--- a/src/dht/dht_api.c
+++ b/src/dht/dht_api.c
@@ -1317,7 +1317,9 @@ GNUNET_DHT_verify_path (const struct GNUNET_HashCode *key,
   if (0 == get_path_len + put_path_len)
     return 0;
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              "Verifying signatures with GPL: %u PPL: %u!\n",
+              "%s is verifying signatures for %s with GPL: %u PPL: %u!\n",
+              GNUNET_i2s (me),
+              GNUNET_h2s (key),
               get_path_len,
               put_path_len);
   i = put_path_len + get_path_len - 1;
@@ -1345,7 +1347,10 @@ GNUNET_DHT_verify_path (const struct GNUNET_HashCode 
*key,
           (i >= put_path_len)
           ? &get_path[i - put_path_len].pred.public_key
           : &put_path[i].pred.public_key))
+    {
+      GNUNET_break_op (0);
       return i;
+    }
     i--;
   }
   return i;
diff --git a/src/dht/gnunet-service-dht_clients.c 
b/src/dht/gnunet-service-dht_clients.c
index db075509f..049e3d1f1 100644
--- a/src/dht/gnunet-service-dht_clients.c
+++ b/src/dht/gnunet-service-dht_clients.c
@@ -24,7 +24,6 @@
  * @author Christian Grothoff
  * @author Nathan Evans
  */
-
 #include "platform.h"
 #include "gnunet_constants.h"
 #include "gnunet_protocols.h"
@@ -35,6 +34,11 @@
 #include "dht.h"
 
 
+/**
+ * Enable slow sanity checks to debug issues.
+ */
+#define SANITY_CHECKS 1
+
 /**
  * Should routing details be logged to stderr (for debugging)?
  */
@@ -1006,7 +1010,8 @@ forward_reply (void *cls,
                  * frc->bd->put_path_length);
   GNUNET_memcpy (&paths[frc->bd->put_path_length],
                  frc->get_path,
-                 sizeof(struct GNUNET_DHT_PathElement) * frc->get_path_length);
+                 sizeof(struct GNUNET_DHT_PathElement)
+                 * frc->get_path_length);
   GNUNET_memcpy (&paths[frc->get_path_length + frc->bd->put_path_length],
                  frc->bd->data,
                  frc->bd->data_size);
@@ -1039,12 +1044,30 @@ GDS_CLIENTS_handle_reply (const struct 
GDS_DATACACHE_BlockData *bd,
     GNUNET_break (0);
     return;
   }
+#if SANITY_CHECKS
+  if (0 !=
+      GNUNET_DHT_verify_path (&bd->key,
+                              bd->data,
+                              bd->data_size,
+                              bd->expiration_time,
+                              get_path,
+                              get_path_length,
+                              bd->put_path,
+                              bd->put_path_length,
+                              &GDS_my_identity))
+  {
+    GNUNET_break_op (0);
+    return;
+  }
+#endif
   frc.bd = bd;
   frc.get_path = get_path;
   frc.get_path_length = get_path_length;
   LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Forwarding reply for query hash %s to client\n",
-       GNUNET_h2s (query_hash));
+       "Forwarding reply for query hash %s with GPL %u and PPL %u to client\n",
+       GNUNET_h2s (query_hash),
+       get_path_length,
+       bd->put_path_length);
   if (0 ==
       GNUNET_CONTAINER_multihashmap_get_multiple (forward_map,
                                                   query_hash,
diff --git a/src/dht/gnunet-service-dht_neighbours.c 
b/src/dht/gnunet-service-dht_neighbours.c
index 2e25b4d1e..284380647 100644
--- a/src/dht/gnunet-service-dht_neighbours.c
+++ b/src/dht/gnunet-service-dht_neighbours.c
@@ -1400,6 +1400,10 @@ GDS_NEIGHBOURS_handle_put (const struct 
GDS_DATACACHE_BlockData *bd,
                  &pp[put_path_length - 1].pred,
                  &target->id,
                  &pp[put_path_length - 1].sig);
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "Signing PUT PATH %u => %s\n",
+                  put_path_length,
+                  GNUNET_B2S (&pp[put_path_length - 1].sig));
     }
 
     GNUNET_memcpy (&pp[put_path_length],
@@ -1594,7 +1598,7 @@ GDS_NEIGHBOURS_handle_reply (struct PeerInfo *pi,
     GNUNET_break (0);
     return;
   }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "Forwarding reply for key %s to peer %s\n",
               GNUNET_h2s (query_hash),
               GNUNET_i2s (&pi->id));
@@ -1636,22 +1640,55 @@ GDS_NEIGHBOURS_handle_reply (struct PeerInfo *pi,
     {
       GNUNET_assert (0 == get_path_length);
     }
-    /* 0 == get_path_length means path is not being tracked */
-    if (0 != get_path_length)
+    /* 0 == get_path_length+ppl means path is not being tracked */
+    if (0 != (get_path_length + ppl))
     {
-      /* Note that the signature in 'get_path' was not initialized before,
+      /* Note that the last signature in 'paths' was not initialized before,
          so this is crucial to avoid sending garbage. */
-      sign_path (&bd->key,
+      sign_path (query_hash,
                  bd->data,
                  bd->data_size,
                  bd->expiration_time,
                  &paths[ppl + get_path_length - 1].pred,
                  &pi->id,
                  &paths[ppl + get_path_length - 1].sig);
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "Signing GET PATH %u/%u of %s => %s\n",
+                  ppl,
+                  get_path_length,
+                  GNUNET_h2s (query_hash),
+                  GNUNET_B2S (&paths[ppl + get_path_length - 1].sig));
     }
     GNUNET_memcpy (&paths[ppl + get_path_length],
                    bd->data,
                    bd->data_size);
+
+#if SANITY_CHECKS
+    {
+      struct GNUNET_DHT_PathElement xpaths[get_path_length + 1];
+
+      memcpy (xpaths,
+              &paths[ppl],
+              get_path_length * sizeof (struct GNUNET_DHT_PathElement));
+      xpaths[get_path_length].pred = GDS_my_identity;
+      if (0 !=
+          GNUNET_DHT_verify_path (&prm->key,
+                                  bd->data,
+                                  bd->data_size,
+                                  bd->expiration_time,
+                                  paths,
+                                  ppl,
+                                  xpaths,
+                                  get_path_length + 1,
+                                  &pi->id))
+      {
+        GNUNET_break (0);
+        return;
+      }
+    }
+#endif
+
+
     do_send (pi,
              &prm->header);
   }
@@ -2201,6 +2238,8 @@ process_reply_with_path (const struct 
GDS_DATACACHE_BlockData *bd,
                          const struct GNUNET_DHT_PathElement *get_path)
 {
   /* forward to local clients */
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Forwarding reply to local clients\n");
   GDS_CLIENTS_handle_reply (bd,
                             query_hash,
                             get_path_length,
@@ -2246,6 +2285,10 @@ check_dht_p2p_result (void *cls,
   uint16_t get_path_length = ntohs (prm->get_path_length);
   uint16_t put_path_length = ntohs (prm->put_path_length);
   uint16_t msize = ntohs (prm->header.size);
+  const struct GNUNET_DHT_PathElement *pp
+    = (const struct GNUNET_DHT_PathElement *) &prm[1];
+  const struct GNUNET_DHT_PathElement *gp
+    = &pp[put_path_length];
 
   (void) cls;
   if ( (msize <
@@ -2260,6 +2303,26 @@ check_dht_p2p_result (void *cls,
     GNUNET_break_op (0);
     return GNUNET_SYSERR;
   }
+
+#if SANITY_CHECKS
+  if (0 !=
+      GNUNET_DHT_verify_path (&prm->key,
+                              &gp[get_path_length],
+                              msize - (sizeof(struct PeerResultMessage)
+                                       + (get_path_length + put_path_length)
+                                       * sizeof(struct 
GNUNET_DHT_PathElement)),
+                              GNUNET_TIME_absolute_ntoh (prm->expiration_time),
+                              pp,
+                              put_path_length,
+                              gp,
+                              get_path_length,
+                              &GDS_my_identity))
+  {
+    GNUNET_break_op (0);
+    return GNUNET_SYSERR;
+  }
+#endif
+
   return GNUNET_OK;
 }
 
@@ -2412,13 +2475,18 @@ handle_dht_p2p_result (void *cls,
 
   /* First, check if 'peer' is already on the path, and if
      so, truncate it instead of expanding. */
-  for (unsigned int i = 0; i <= get_path_length; i++)
+  for (unsigned int i = 0; i < get_path_length; i++)
     if (0 == GNUNET_memcmp (&get_path[i].pred,
                             &peer->id))
     {
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "Truncating path at %u/%u\n",
+                  i,
+                  get_path_length);
       process_reply_with_path (&bd,
                                &prm->key,
-                               i, get_path);
+                               i,
+                               get_path);
       return;
     }
 
@@ -2433,9 +2501,14 @@ handle_dht_p2p_result (void *cls,
     memset (&xget_path[get_path_length].sig,
             0,
             sizeof (xget_path[get_path_length].sig));
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Extending GET path of length %u with %s\n",
+                get_path_length,
+                GNUNET_i2s (&peer->id));
     process_reply_with_path (&bd,
                              &prm->key,
-                             get_path_length + 1, xget_path);
+                             get_path_length + 1,
+                             xget_path);
   }
 }
 
@@ -2540,7 +2613,7 @@ GDS_u_receive (void *cls,
     GNUNET_break_op (0);
     return;
   }
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Handling message of type %u from peer %s\n",
               ntohs (mh->type),
               GNUNET_i2s (&t->pi->id));
diff --git a/src/dht/gnunet-service-dht_routing.c 
b/src/dht/gnunet-service-dht_routing.c
index ec3f5b46f..c07b06c5e 100644
--- a/src/dht/gnunet-service-dht_routing.c
+++ b/src/dht/gnunet-service-dht_routing.c
@@ -198,7 +198,8 @@ process (void *cls,
       GDS_NEIGHBOURS_handle_reply (pi,
                                    &bdx,
                                    query_hash,
-                                   get_path_length, pc->get_path);
+                                   get_path_length,
+                                   pc->get_path);
     }
     break;
   case GNUNET_BLOCK_REPLY_OK_DUPLICATE:
diff --git a/src/dht/test_dht_topo.c b/src/dht/test_dht_topo.c
index eb7e80d3b..30e7749ca 100644
--- a/src/dht/test_dht_topo.c
+++ b/src/dht/test_dht_topo.c
@@ -380,6 +380,7 @@ dht_get_handler (void *cls,
                               put_path_length,
                               &get_op->me))
   {
+    GNUNET_break (0);
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Path signature verification failed!\n");
   }
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h
index 4472d3ee8..9bcd99c7b 100644
--- a/src/include/gnunet_common.h
+++ b/src/include/gnunet_common.h
@@ -622,6 +622,31 @@ void
 GNUNET_abort_ (void) GNUNET_NORETURN;
 
 
+/**
+ * Convert a buffer to an 8-character string
+ * representative of the contents. This is used
+ * for logging binary data when debugging.
+ *
+ * @param buf buffer to log
+ * @param buf_size number of bytes in @a buf
+ * @return text representation of buf, valid until next
+ *         call to this function
+ */
+const char *
+GNUNET_b2s (const void *buf,
+           size_t buf_size);
+
+
+/**
+ * Convert a fixed-sized object to a string using
+ * #GNUNET_b2s().
+ *
+ * @param obj address of object to convert
+ * @return string representing the binary obj buffer
+ */
+#define GNUNET_B2S(obj) GNUNET_b2s ((obj), sizeof (*(obj)))
+
+
 /**
  * @ingroup logging
  * Ignore the next @a n calls to the log function.
@@ -1240,7 +1265,7 @@ GNUNET_is_zero_ (const void *a,
  * @return GNUNET_YES if a is zero, GNUNET_NO otherwise
  */
 #define GNUNET_is_zero(a)           \
-  GNUNET_is_zero_ (a, sizeof (*a))
+  GNUNET_is_zero_ ((a), sizeof (*(a)))
 
 
 /**
diff --git a/src/util/common_logging.c b/src/util/common_logging.c
index cba37cd2f..b07f3fc0b 100644
--- a/src/util/common_logging.c
+++ b/src/util/common_logging.c
@@ -321,6 +321,28 @@ log_rotate (const char *new_name)
 }
 
 
+const char *
+GNUNET_b2s (const void *buf,
+            size_t buf_size)
+{
+  static GNUNET_THREAD_LOCAL char ret[9];
+  struct GNUNET_HashCode hc;
+  char *tmp;
+
+  GNUNET_CRYPTO_hash (buf,
+                      buf_size,
+                      &hc);
+  tmp = GNUNET_STRINGS_data_to_string_alloc (&hc,
+                                             sizeof (hc));
+  memcpy (ret,
+          tmp,
+          8);
+  GNUNET_free (tmp);
+  ret[8] = '\0';
+  return ret;
+}
+
+
 /**
  * Setup the log file.
  *
@@ -1015,7 +1037,8 @@ mylog (enum GNUNET_ErrorType kind,
     else
     {
       /* RFC 3339 timestamp, with snprintf placeholder for microseconds */
-      if (0 == strftime (date2, DATE_STR_SIZE, "%Y-%m-%dT%H:%M:%S.%%06u%z", 
tmptr))
+      if (0 == strftime (date2, DATE_STR_SIZE, "%Y-%m-%dT%H:%M:%S.%%06u%z",
+                         tmptr))
         abort ();
       /* Fill in microseconds */
       if (0 > snprintf (date, sizeof(date), date2, timeofday.tv_usec))

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]