gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [gnunet] branch master updated: enable caching of non-exist


From: gnunet
Subject: [GNUnet-SVN] [gnunet] branch master updated: enable caching of non-existence of NICKs, also properly remove cache entries if NICK record itself is removed
Date: Sat, 22 Jun 2019 10:04:38 +0200

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

grothoff pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new f471e085d enable caching of non-existence of NICKs, also properly 
remove cache entries if NICK record itself is removed
f471e085d is described below

commit f471e085db2b47fc5187f732244db549eb974640
Author: Christian Grothoff <address@hidden>
AuthorDate: Sat Jun 22 10:03:32 2019 +0200

    enable caching of non-existence of NICKs, also properly remove cache 
entries if NICK record itself is removed
---
 src/namestore/gnunet-service-namestore.c | 47 ++++++++++++++++++++++----------
 1 file changed, 33 insertions(+), 14 deletions(-)

diff --git a/src/namestore/gnunet-service-namestore.c 
b/src/namestore/gnunet-service-namestore.c
index 1de3a3edf..4d23b91c6 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -23,12 +23,6 @@
  * @brief namestore for the GNUnet naming system
  * @author Matthias Wachs
  * @author Christian Grothoff
- *
- * TODO:
- * - "get_nick_record" is a bottleneck, introduce a cache to
- *   avoid looking it up again and again (for the same few
- *   zones that the user will typically manage!)
- * - run testcases, make sure everything works!
  */
 #include "platform.h"
 #include "gnunet_util_lib.h"
@@ -562,13 +556,20 @@ cache_nick (const struct GNUNET_CRYPTO_EcdsaPrivateKey 
*zone,
   }
   GNUNET_free_non_null (oldest->rd);
   oldest->zone = *zone;
-  oldest->rd = GNUNET_malloc (sizeof (*nick) +
-                             nick->data_size);
-  *oldest->rd = *nick;
-  oldest->rd->data = &oldest->rd[1];
-  memcpy (&oldest->rd[1],
-         nick->data,
-         nick->data_size);
+  if (NULL != nick)
+  {
+    oldest->rd = GNUNET_malloc (sizeof (*nick) +
+                               nick->data_size);
+    *oldest->rd = *nick;
+    oldest->rd->data = &oldest->rd[1];
+    memcpy (&oldest->rd[1],
+           nick->data,
+           nick->data_size);
+  }
+  else
+  {
+    oldest->rd = NULL;
+  }
   oldest->last_used = GNUNET_TIME_absolute_get ();
 }
 
@@ -592,8 +593,10 @@ get_nick_record (const struct 
GNUNET_CRYPTO_EcdsaPrivateKey *zone)
     struct NickCache *pos = &nick_cache[i];
     if ( (NULL != pos->rd) &&
         (0 == GNUNET_memcmp (zone,
-                      &pos->zone)) )
+                             &pos->zone)) )
     {
+      if (NULL == pos->rd)
+       return NULL;
       nick = GNUNET_malloc (sizeof (*nick) +
                            pos->rd->data_size);
       *nick = *pos->rd;
@@ -631,6 +634,9 @@ get_nick_record (const struct GNUNET_CRYPTO_EcdsaPrivateKey 
*zone)
                  "No nick name set for zone `%s'\n",
                  GNUNET_GNSRECORD_z2s (&pub));
     }
+    /* update cache */
+    cache_nick (zone,
+               NULL);
     return NULL;
   }
 
@@ -1615,8 +1621,10 @@ handle_record_store (void *cls,
          #GNUNET_GNS_EMPTY_LABEL_AT label */
       struct GNUNET_GNSRECORD_Data rd_clean[GNUNET_NZL(rd_count)];
       unsigned int rd_clean_off;
+      int have_nick;
 
       rd_clean_off = 0;
+      have_nick = GNUNET_NO;
       for (unsigned int i=0;i<rd_count;i++)
       {
         rd_clean[rd_clean_off] = rd[i];
@@ -1628,8 +1636,19 @@ handle_record_store (void *cls,
        if ( (0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT,
                            conv_name)) &&
             (GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) )
+       {
          cache_nick (&rp_msg->private_key,
                      &rd[i]);
+         have_nick = GNUNET_YES;
+       }
+      }
+      if ( (0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT,
+                        conv_name)) &&
+          (GNUNET_NO == have_nick) )
+      {
+       /* remove nick record from cache, in case we have one there */
+       cache_nick (&rp_msg->private_key,
+                   NULL);
       }
       res = GSN_database->store_records (GSN_database->cls,
                                         &rp_msg->private_key,

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

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