code cleanup, more diagnostics, more statistics
authorChristian Grothoff <christian@grothoff.org>
Tue, 24 Apr 2018 21:28:24 +0000 (23:28 +0200)
committerChristian Grothoff <christian@grothoff.org>
Tue, 24 Apr 2018 21:28:24 +0000 (23:28 +0200)
src/gnsrecord/gnsrecord_crypto.c
src/include/gnunet_gnsrecord_lib.h
src/namestore/gnunet-service-namestore.c
src/zonemaster/gnunet-service-zonemaster.c

index 0fab97f066cee562ad5788972a8ea3efe1b92dd9..dd628ea767522c6c771725cff879d07b1c6a09d7 100644 (file)
@@ -85,7 +85,8 @@ GNUNET_GNSRECORD_block_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
                               const struct GNUNET_GNSRECORD_Data *rd,
                               unsigned int rd_count)
 {
-  size_t payload_len = GNUNET_GNSRECORD_records_get_size (rd_count, rd);
+  size_t payload_len = GNUNET_GNSRECORD_records_get_size (rd_count,
+                                                          rd);
   char payload[sizeof (uint32_t) + payload_len];
   struct GNUNET_GNSRECORD_Block *block;
   struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
@@ -94,14 +95,13 @@ GNUNET_GNSRECORD_block_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
   struct GNUNET_CRYPTO_SymmetricSessionKey skey;
   struct GNUNET_GNSRECORD_Data rdc[rd_count];
   uint32_t rd_count_nbo;
-  unsigned int i;
   struct GNUNET_TIME_Absolute now;
 
   if (payload_len > GNUNET_GNSRECORD_MAX_BLOCK_SIZE)
     return NULL;
   /* convert relative to absolute times */
   now = GNUNET_TIME_absolute_get ();
-  for (i=0;i<rd_count;i++)
+  for (unsigned int i=0;i<rd_count;i++)
   {
     rdc[i] = rd[i];
     if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
@@ -116,13 +116,19 @@ GNUNET_GNSRECORD_block_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
   }
   /* serialize */
   rd_count_nbo = htonl (rd_count);
-  GNUNET_memcpy (payload, &rd_count_nbo, sizeof (uint32_t));
+  GNUNET_memcpy (payload,
+                 &rd_count_nbo,
+                 sizeof (uint32_t));
   GNUNET_assert (payload_len ==
-                GNUNET_GNSRECORD_records_serialize (rd_count, rdc,
-                                                    payload_len, &payload[sizeof (uint32_t)]));
+                GNUNET_GNSRECORD_records_serialize (rd_count,
+                                                     rdc,
+                                                    payload_len,
+                                                     &payload[sizeof (uint32_t)]));
   block = GNUNET_malloc (sizeof (struct GNUNET_GNSRECORD_Block) +
-                        sizeof (uint32_t) + payload_len);
-  block->purpose.size = htonl (sizeof (uint32_t) + payload_len +
+                        sizeof (uint32_t) +
+                         payload_len);
+  block->purpose.size = htonl (sizeof (uint32_t) +
+                               payload_len +
                               sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +
                               sizeof (struct GNUNET_TIME_AbsoluteNBO));
   block->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN);
@@ -132,18 +138,23 @@ GNUNET_GNSRECORD_block_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
                                                  label,
                                                  "gns");
   GNUNET_CRYPTO_ecdsa_key_get_public (dkey,
-                                   &block->derived_key);
+                                      &block->derived_key);
   GNUNET_CRYPTO_ecdsa_key_get_public (key,
-                                   &pkey);
-  derive_block_aes_key (&iv, &skey, label, &pkey);
+                                      &pkey);
+  derive_block_aes_key (&iv,
+                        &skey,
+                        label,
+                        &pkey);
   GNUNET_break (payload_len + sizeof (uint32_t) ==
-               GNUNET_CRYPTO_symmetric_encrypt (payload, payload_len + sizeof (uint32_t),
-                                                 &skey, &iv,
+               GNUNET_CRYPTO_symmetric_encrypt (payload,
+                                                 payload_len + sizeof (uint32_t),
+                                                 &skey,
+                                                 &iv,
                                                  &block[1]));
   if (GNUNET_OK !=
       GNUNET_CRYPTO_ecdsa_sign (dkey,
-                             &block->purpose,
-                             &block->signature))
+                                &block->purpose,
+                                &block->signature))
   {
     GNUNET_break (0);
     GNUNET_free (dkey);
@@ -166,9 +177,9 @@ int
 GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block)
 {
   return GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN,
-                                  &block->purpose,
-                                  &block->signature,
-                                  &block->derived_key);
+                                     &block->purpose,
+                                     &block->signature,
+                                     &block->derived_key);
 }
 
 
@@ -224,9 +235,7 @@ GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block,
     }
     {
       struct GNUNET_GNSRECORD_Data rd[rd_count];
-      unsigned int i;
       unsigned int j;
-      unsigned int k;
       struct GNUNET_TIME_Absolute now;
 
       if (GNUNET_OK !=
@@ -241,7 +250,7 @@ GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block,
       /* hide expired records */
       now = GNUNET_TIME_absolute_get ();
       j = 0;
-      for (i=0;i<rd_count;i++)
+      for (unsigned int i=0;i<rd_count;i++)
       {
         if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
         {
@@ -254,7 +263,7 @@ GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block,
         {
           int include_record = GNUNET_YES;
           /* Shadow record, figure out if we have a not expired active record */
-          for (k=0;k<rd_count;k++)
+          for (unsigned int k=0;k<rd_count;k++)
           {
             if (k == i)
               continue;
@@ -283,7 +292,9 @@ GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block,
       }
       rd_count = j;
       if (NULL != proc)
-       proc (proc_cls, rd_count, (0 != rd_count) ? rd : NULL);
+       proc (proc_cls,
+              rd_count,
+              (0 != rd_count) ? rd : NULL);
     }
   }
   return GNUNET_OK;
@@ -323,8 +334,13 @@ GNUNET_GNSRECORD_query_from_public_key (const struct GNUNET_CRYPTO_EcdsaPublicKe
 {
   struct GNUNET_CRYPTO_EcdsaPublicKey pd;
 
-  GNUNET_CRYPTO_ecdsa_public_key_derive (pub, label, "gns", &pd);
-  GNUNET_CRYPTO_hash (&pd, sizeof (pd), query);
+  GNUNET_CRYPTO_ecdsa_public_key_derive (pub,
+                                         label,
+                                         "gns",
+                                         &pd);
+  GNUNET_CRYPTO_hash (&pd,
+                      sizeof (pd),
+                      query);
 }
 
 
index d03b4db3b0478b21107f45b873fa198490d2a58c..f07bd3ef30906cca355ab8cbf0d6dd3d93bb2ed3 100644 (file)
@@ -342,9 +342,10 @@ GNUNET_NETWORK_STRUCT_END
  * @param rd_count number of entries in @a rd array
  * @param rd array of records with data to store
  */
-typedef void (*GNUNET_GNSRECORD_RecordCallback) (void *cls,
-                                                unsigned int rd_count,
-                                                const struct GNUNET_GNSRECORD_Data *rd);
+typedef void
+(*GNUNET_GNSRECORD_RecordCallback) (void *cls,
+                                    unsigned int rd_count,
+                                    const struct GNUNET_GNSRECORD_Data *rd);
 
 
 
index 3ba4f9ec3311df2f1c332c4a2873005b8f180755..cc41f071d6f154c6dea88f571da82b3b77eac9a4 100644 (file)
@@ -31,6 +31,7 @@
 #include "gnunet_namecache_service.h"
 #include "gnunet_namestore_service.h"
 #include "gnunet_namestore_plugin.h"
+#include "gnunet_statistics_service.h"
 #include "gnunet_signatures.h"
 #include "namestore.h"
 
@@ -205,6 +206,11 @@ static const struct GNUNET_CRYPTO_EcdsaPrivateKey zero;
  */
 static const struct GNUNET_CONFIGURATION_Handle *GSN_cfg;
 
+/**
+ * Handle to the statistics service
+ */
+static struct GNUNET_STATISTICS_Handle *statistics;
+
 /**
  * Namecache handle.
  */
@@ -280,6 +286,12 @@ cleanup_task (void *cls)
     GNUNET_notification_context_destroy (monitor_nc);
     monitor_nc = NULL;
   }
+  if (NULL != statistics)
+  {
+    GNUNET_STATISTICS_destroy (statistics,
+                               GNUNET_NO);
+    statistics = NULL;
+  }
 }
 
 
@@ -582,6 +594,10 @@ send_lookup_response (struct NamestoreClient *nc,
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Sending RECORD_RESULT message with %u records\n",
              res_count);
+  GNUNET_STATISTICS_update (statistics,
+                            "Record sets sent to clients",
+                            1,
+                            GNUNET_NO);
   GNUNET_MQ_send (nc->mq,
                  env);
   if (rd != res)
@@ -707,6 +723,10 @@ refresh_block (struct NamestoreClient *nc,
               name,
               res_count,
               GNUNET_GNSRECORD_z2s (&pkey));
+  GNUNET_STATISTICS_update (statistics,
+                            "Namecache updates pushed",
+                            1,
+                            GNUNET_NO);
   cop = GNUNET_new (struct CacheOperation);
   cop->nc = nc;
   cop->rid = rid;
@@ -774,7 +794,8 @@ lookup_it (void *cls,
   unsigned int rdc_res;
 
   (void) private_key;
-  if (0 == strcmp (label, rlc->label))
+  if (0 == strcmp (label,
+                   rlc->label))
   {
     rlc->found = GNUNET_YES;
     if (0 != rd_count)
@@ -1332,7 +1353,8 @@ zone_iterate_proc (void *cls,
   struct ZoneIterationProcResult *proc = cls;
   int do_refresh_block;
 
-  if ((NULL == zone_key) && (NULL == name))
+  if ( (NULL == zone_key) &&
+       (NULL == name) )
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "Iteration done\n");
@@ -1391,11 +1413,14 @@ run_zone_iteration_round (struct ZoneIteration *zi)
   {
     if (GNUNET_SYSERR ==
        (ret = GSN_database->iterate_records (GSN_database->cls,
-                                             (0 == memcmp (&zi->zone, &zero, sizeof (zero)))
+                                             (0 == memcmp (&zi->zone,
+                                                            &zero,
+                                                            sizeof (zero)))
                                              ? NULL
                                              : &zi->zone,
                                              zi->offset,
-                                             &zone_iterate_proc, &proc)))
+                                             &zone_iterate_proc,
+                                              &proc)))
     {
       GNUNET_break (0);
       break;
@@ -1503,6 +1528,10 @@ handle_iteration_next (void *cls,
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Received ZONE_ITERATION_NEXT message\n");
+  GNUNET_STATISTICS_update (statistics,
+                            "Iteration NEXT messages received",
+                            1,
+                            GNUNET_NO);
   rid = ntohl (zis_msg->gns_header.r_id);
   for (zi = nc->op_head; NULL != zi; zi = zi->next)
     if (zi->request_id == rid)
@@ -1569,6 +1598,10 @@ monitor_iterate_cb (void *cls,
     monitor_sync (zm);
     return;
   }
+  GNUNET_STATISTICS_update (statistics,
+                            "Monitor notifications sent",
+                            1,
+                            GNUNET_NO);
   send_lookup_response (zm->nc,
                        0,
                        zone_key,
@@ -1684,6 +1717,8 @@ run (void *cls,
   GSN_database = GNUNET_PLUGIN_load (db_lib_name,
                                      (void *) GSN_cfg);
   GNUNET_free (database);
+  statistics = GNUNET_STATISTICS_create ("namestore",
+                                         cfg);
   GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
                                 NULL);
   if (NULL == GSN_database)
index b3a2cb8b3965d3311093a88e6777dadfaa63f08d..bf11f7d20d98920d712c85e6464b829d8142c646 100644 (file)
@@ -336,11 +336,10 @@ convert_records_for_export (const struct GNUNET_GNSRECORD_Data *rd,
 {
   struct GNUNET_TIME_Absolute now;
   unsigned int rd_public_count;
-  unsigned int i;
 
   rd_public_count = 0;
   now = GNUNET_TIME_absolute_get ();
-  for (i=0;i<rd_count;i++)
+  for (unsigned int i=0;i<rd_count;i++)
     if (0 == (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE))
     {
       rd_public[rd_public_count] = rd[i];
@@ -401,6 +400,10 @@ perform_dht_put (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
   GNUNET_GNSRECORD_query_from_private_key (key,
                                            label,
                                            &query);
+  GNUNET_STATISTICS_update (statistics,
+                            "DHT put operations initiated",
+                            1,
+                            GNUNET_NO);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Storing %u record(s) for label `%s' in DHT with expiration `%s' under key %s\n",
               rd_public_count,
@@ -424,10 +427,13 @@ perform_dht_put (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
 
 /**
  * We encountered an error in our zone iteration.
+ *
+ * @param cls NULL
  */
 static void
 zone_iteration_error (void *cls)
 {
+  (void) cls;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Got disconnected from namestore database, retrying.\n");
   namestore_iter = NULL;
@@ -451,10 +457,13 @@ zone_iteration_error (void *cls)
 
 /**
  * Zone iteration is completed.
+ *
+ * @param cls NULL
  */
 static void
 zone_iteration_finished (void *cls)
 {
+  (void) cls;
   /* we're done with one iteration, calculate when to do the next one */
   namestore_iter = NULL;
   last_num_public_records = num_public_records;
@@ -533,10 +542,10 @@ put_gns_record (void *cls,
   struct GNUNET_GNSRECORD_Data rd_public[rd_count];
   unsigned int rd_public_count;
 
+  (void) cls;
   rd_public_count = convert_records_for_export (rd,
                                                 rd_count,
                                                 rd_public);
-
   if (0 == rd_public_count)
   {
     GNUNET_assert (NULL == zone_publish_task);
@@ -571,7 +580,10 @@ static void
 publish_zone_dht_start (void *cls)
 {
   zone_publish_task = NULL;
-
+  GNUNET_STATISTICS_update (statistics,
+                            "Full zone iterations launched",
+                            1,
+                            GNUNET_NO);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Starting DHT zone update!\n");
   /* start counting again */
@@ -610,6 +622,10 @@ handle_monitor_event (void *cls,
   unsigned int rd_public_count;
   struct MonitorActivity *ma;
 
+  GNUNET_STATISTICS_update (statistics,
+                            "Namestore monitor events received",
+                            1,
+                            GNUNET_NO);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Received %u records for label `%s' via namestore monitor\n",
               rd_count,
@@ -648,22 +664,28 @@ handle_monitor_event (void *cls,
 static void
 monitor_sync_event (void *cls)
 {
+  (void) cls;
   if ( (NULL == zone_publish_task) &&
        (NULL == namestore_iter) )
-  zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
-                                                NULL);
+    zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
+                                                  NULL);
 }
 
 
 /**
- * The zone monitor is now in SYNC with the current state of the
- * name store.  Start to perform periodic iterations.
+ * The zone monitor encountered an IPC error trying to to get in
+ * sync. Restart from the beginning.
  *
  * @param cls NULL
  */
 static void
 handle_monitor_error (void *cls)
 {
+  (void) cls;
+  GNUNET_STATISTICS_update (statistics,
+                            "Namestore monitor errors encountered",
+                            1,
+                            GNUNET_NO);
   if (NULL != zone_publish_task)
   {
     GNUNET_SCHEDULER_cancel (zone_publish_task);
@@ -698,6 +720,7 @@ run (void *cls,
 {
   unsigned long long max_parallel_bg_queries = 128;
 
+  (void) cls;
   min_relative_record_time = GNUNET_TIME_UNIT_FOREVER_REL;
   namestore_handle = GNUNET_NAMESTORE_connect (c);
   if (NULL == namestore_handle)
@@ -733,7 +756,7 @@ run (void *cls,
                 max_parallel_bg_queries);
   }
   if (0 == max_parallel_bg_queries)
-    max_parallel_bg_queries = 1;         
+    max_parallel_bg_queries = 1;
   dht_handle = GNUNET_DHT_connect (c,
                                    (unsigned int) max_parallel_bg_queries);
   if (NULL == dht_handle)
@@ -746,7 +769,8 @@ run (void *cls,
 
   /* Schedule periodic put for our records. */
   first_zone_iteration = GNUNET_YES;\
-  statistics = GNUNET_STATISTICS_create ("zonemaster", c);
+  statistics = GNUNET_STATISTICS_create ("zonemaster",
+                                         c);
   zmon = GNUNET_NAMESTORE_zone_monitor_start (c,
                                               NULL,
                                               GNUNET_NO,