gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r29783 - gnunet/src/namestore


From: gnunet
Subject: [GNUnet-SVN] r29783 - gnunet/src/namestore
Date: Wed, 2 Oct 2013 14:15:36 +0200

Author: grothoff
Date: 2013-10-02 14:15:35 +0200 (Wed, 02 Oct 2013)
New Revision: 29783

Modified:
   gnunet/src/namestore/gnunet-service-namestore.c
   gnunet/src/namestore/namestore_api_common.c
   gnunet/src/namestore/plugin_namestore_sqlite.c
Log:
-address #3050, refresh encrypted blocks from plaintext blocks during 
iteration, compute block expiration time correctly

Modified: gnunet/src/namestore/gnunet-service-namestore.c
===================================================================
--- gnunet/src/namestore/gnunet-service-namestore.c     2013-10-02 11:45:07 UTC 
(rev 29782)
+++ gnunet/src/namestore/gnunet-service-namestore.c     2013-10-02 12:15:35 UTC 
(rev 29783)
@@ -552,6 +552,45 @@
 
 
 /**
+ * We just touched the plaintext information about a name in our zone;
+ * refresh the corresponding (encrypted) block in the namestore.
+ *
+ * @param zone_key private key of the zone
+ * @param name label for the records
+ * @param rd_count number of records
+ * @param rd records stored under the given @a name
+ */
+static void
+refresh_block (const struct GNUNET_CRYPTO_EccPrivateKey *zone_key,
+               const char *name,
+               unsigned int rd_count,
+               const struct GNUNET_NAMESTORE_RecordData *rd)
+{
+  struct GNUNET_NAMESTORE_Block *block;
+  
+  if (0 == rd_count)
+    block = GNUNET_NAMESTORE_block_create (zone_key,
+                                           GNUNET_TIME_UNIT_ZERO_ABS,
+                                           name,
+                                           rd, rd_count);
+  else
+    block = GNUNET_NAMESTORE_block_create (zone_key,
+                                           
GNUNET_NAMESTORE_record_get_expiration_time (rd_count,
+                                                                               
         rd),
+                                           name,
+                                           rd, rd_count);
+  if (GNUNET_OK !=
+      GSN_database->cache_block (GSN_database->cls,
+                                 block))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                _("Failed to cache encrypted block of my own zone!\n"));
+  }
+  GNUNET_free (block);
+}    
+
+
+/**
  * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE message
  *
  * @param cls unused
@@ -577,6 +616,7 @@
   unsigned int rd_count;
   int res;
   struct GNUNET_CRYPTO_EccPublicSignKey pubkey;
+  struct ZoneMonitor *zm;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
              "Received `%s' message\n", 
@@ -644,7 +684,10 @@
                conv_name,
                GNUNET_NAMESTORE_z2s (&pubkey));
 
-    if ((rd_count == 0) && (GNUNET_NO == GSN_database->iterate_records 
(GSN_database->cls, &rp_msg->private_key, 0, NULL, 0)))
+    if ( (0 == rd_count) && 
+         (GNUNET_NO == 
+          GSN_database->iterate_records (GSN_database->cls, 
+                                         &rp_msg->private_key, 0, NULL, 0)) )
     {
       /* This name does not exist, so cannot be removed */
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -660,39 +703,20 @@
                                         rd_count, rd);
       if (GNUNET_OK == res)
       {
-       struct ZoneMonitor *zm;
-       struct GNUNET_NAMESTORE_Block *block;
-       
-       if (0 == rd_count)
-         block = GNUNET_NAMESTORE_block_create (&rp_msg->private_key,
-                                                GNUNET_TIME_UNIT_ZERO_ABS,
-                                                conv_name,
-                                                rd, rd_count);
-       else
-         block = GNUNET_NAMESTORE_block_create (&rp_msg->private_key,
-                                                GNUNET_TIME_UNIT_FOREVER_ABS,
-                                                conv_name,
-                                                rd, rd_count);
-       if (GNUNET_OK !=
-           GSN_database->cache_block (GSN_database->cls,
-                                      block))
-       {
-         GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                     _("Failed to cache encrypted block of my own zone!\n"));
-         res = GNUNET_SYSERR;
-       }
-       GNUNET_free (block);
-       
-       for (zm = monitor_head; NULL != zm; zm = zm->next)    
-         if (0 == memcmp (&rp_msg->private_key, &zm->zone,
-                          sizeof (struct GNUNET_CRYPTO_EccPrivateKey)))
-           send_lookup_response (monitor_nc,
-                                 zm->nc->client,
-                                 zm->request_id,
-                                 &rp_msg->private_key,
-                                 conv_name,
-                                 rd_count, rd);
-      }    
+        refresh_block (&rp_msg->private_key,
+                       conv_name,
+                       rd_count, rd);
+  
+        for (zm = monitor_head; NULL != zm; zm = zm->next)    
+          if (0 == memcmp (&rp_msg->private_key, &zm->zone,
+                           sizeof (struct GNUNET_CRYPTO_EccPrivateKey)))
+            send_lookup_response (monitor_nc,
+                                  zm->nc->client,
+                                  zm->request_id,
+                                  &rp_msg->private_key,
+                                  conv_name,
+                                  rd_count, rd);
+      }
       GNUNET_free (conv_name);
     }
   }
@@ -914,6 +938,8 @@
                        const struct GNUNET_NAMESTORE_RecordData *rd)
 {
   struct ZoneIterationProcResult *proc = cls;
+  unsigned int i;
+  int do_refresh_block;
 
   if ((NULL == zone_key) && (NULL == name))
   {
@@ -937,6 +963,20 @@
                        name,
                        rd_count,
                        rd);
+  do_refresh_block = GNUNET_NO;
+  for (i=0;i<rd_count;i++)
+    if(  (0 != (rd[i].flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION)) &&
+         (0 == (rd[i].flags & GNUNET_NAMESTORE_RF_PENDING)) )
+    {
+      do_refresh_block = GNUNET_YES;
+      break;
+    }
+  if (GNUNET_YES == do_refresh_block)
+    refresh_block (zone_key,
+                   name,
+                   rd_count,
+                   rd);
+
 }
 
 

Modified: gnunet/src/namestore/namestore_api_common.c
===================================================================
--- gnunet/src/namestore/namestore_api_common.c 2013-10-02 11:45:07 UTC (rev 
29782)
+++ gnunet/src/namestore/namestore_api_common.c 2013-10-02 12:15:35 UTC (rev 
29783)
@@ -276,7 +276,7 @@
 
 /**
  * Returns the expiration time of the given block of records. The block
- * expiration time is the expiration time of the block with smallest
+ * expiration time is the expiration time of the record with smallest
  * expiration time.
  *
  * @param rd_count number of records given in @a rd

Modified: gnunet/src/namestore/plugin_namestore_sqlite.c
===================================================================
--- gnunet/src/namestore/plugin_namestore_sqlite.c      2013-10-02 11:45:07 UTC 
(rev 29782)
+++ gnunet/src/namestore/plugin_namestore_sqlite.c      2013-10-02 12:15:35 UTC 
(rev 29783)
@@ -77,6 +77,11 @@
   sqlite3_stmt *cache_block;
 
   /**
+   * Precompiled SQL for deleting an older block
+   */
+  sqlite3_stmt *delete_block;
+
+  /**
    * Precompiled SQL for looking up a block
    */
   sqlite3_stmt *lookup_block;
@@ -305,6 +310,10 @@
         &plugin->expire_blocks) != SQLITE_OK) ||
       (sq_prepare
        (plugin->dbh,
+        "DELETE FROM ns096blocks WHERE query=? AND expiration_time<=?",
+        &plugin->delete_block) != SQLITE_OK) ||
+      (sq_prepare
+       (plugin->dbh,
         "SELECT block FROM ns096blocks WHERE query=? ORDER BY expiration_time 
DESC LIMIT 1",
         &plugin->lookup_block) != SQLITE_OK) ||
       (sq_prepare
@@ -357,6 +366,8 @@
     sqlite3_finalize (plugin->lookup_block);
   if (NULL != plugin->expire_blocks)
     sqlite3_finalize (plugin->expire_blocks);
+  if (NULL != plugin->delete_block)
+    sqlite3_finalize (plugin->delete_block);
   if (NULL != plugin->store_records)
     sqlite3_finalize (plugin->store_records);
   if (NULL != plugin->delete_records)
@@ -470,6 +481,41 @@
     GNUNET_break (0);
     return GNUNET_SYSERR;
   }
+
+  /* delete old version of the block */
+  if ( (SQLITE_OK != 
+        sqlite3_bind_blob (plugin->delete_block, 1, 
+                           &query, sizeof (struct GNUNET_HashCode), 
+                           SQLITE_STATIC)) ||
+       (SQLITE_OK != 
+        sqlite3_bind_int64 (plugin->delete_block,
+                            2, dval)) )
+  {
+    LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+                "sqlite3_bind_XXXX");
+    if (SQLITE_OK != sqlite3_reset (plugin->delete_block))
+      LOG_SQLITE (plugin,
+                  GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+                  "sqlite3_reset");
+    return GNUNET_SYSERR;
+  }
+  n = sqlite3_step (plugin->delete_block);
+  switch (n)
+  {
+  case SQLITE_DONE:
+    GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", "Old block deleted\n");
+    break;
+  case SQLITE_BUSY:
+    LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
+                "sqlite3_step");
+    break;
+  default:
+    LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+                "sqlite3_step");
+    break;
+  }
+
+  /* insert new version of the block */
   if ((SQLITE_OK != 
        sqlite3_bind_blob (plugin->cache_block, 1, 
                          &query, sizeof (struct GNUNET_HashCode), 




reply via email to

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