gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r19981 - gnunet/src/namestore
Date: Thu, 23 Feb 2012 18:27:42 +0100

Author: grothoff
Date: 2012-02-23 18:27:42 +0100 (Thu, 23 Feb 2012)
New Revision: 19981

Modified:
   gnunet/src/namestore/plugin_namestore_sqlite.c
   gnunet/src/namestore/test_plugin_namestore.c
Log:
-fixing bugs and testcase, plugin now works for updated API again

Modified: gnunet/src/namestore/plugin_namestore_sqlite.c
===================================================================
--- gnunet/src/namestore/plugin_namestore_sqlite.c      2012-02-23 17:09:02 UTC 
(rev 19980)
+++ gnunet/src/namestore/plugin_namestore_sqlite.c      2012-02-23 17:27:42 UTC 
(rev 19981)
@@ -289,9 +289,9 @@
         " zone_key BLOB NOT NULL DEFAULT ''," 
         " zone_hash BLOB NOT NULL DEFAULT ''," 
        " record_count INT NOT NULL DEFAULT 0,"
-        " record_data BLOB NOT NULL DEFAULT ''"
+        " record_data BLOB NOT NULL DEFAULT '',"
         " block_expiration_time INT8 NOT NULL DEFAULT 0," 
-        " signature BLOB NOT NULL DEFAULT ''"
+        " signature BLOB NOT NULL DEFAULT '',"
         " record_name TEXT NOT NULL DEFAULT ''," 
         " record_name_hash BLOB NOT NULL DEFAULT ''," 
        " rvalue INT8 NOT NULL DEFAULT ''"
@@ -310,7 +310,7 @@
   if ((sq_prepare
        (plugin->dbh,
         "INSERT INTO ns090records (" ALL ", zone_hash, record_name_hash, 
rvalue) VALUES "
-       "(?, ?, ?, ?, ?, ?)",
+       "(?, ?, ?, ?, ?, ?, ?, ?, ?)",
         &plugin->put_records) != SQLITE_OK) ||
       (sq_prepare
        (plugin->dbh,
@@ -319,22 +319,22 @@
       (sq_prepare
        (plugin->dbh,
         "SELECT " ALL
-       "FROM ns090records WHERE zone_hash=? AND record_name_hash=? ORDER BY 
rvalue OFFSET ? LIMIT 1",
+       " FROM ns090records WHERE zone_hash=? AND record_name_hash=? ORDER BY 
rvalue LIMIT 1 OFFSET ?",
         &plugin->iterate_records) != SQLITE_OK) ||
       (sq_prepare
        (plugin->dbh,
         "SELECT " ALL
-       "FROM ns090records WHERE zone_hash=? ORDER BY rvalue OFFSET ? LIMIT 1",
+       " FROM ns090records WHERE zone_hash=? ORDER BY rvalue  LIMIT 1 OFFSET 
?",
         &plugin->iterate_by_zone) != SQLITE_OK) ||
       (sq_prepare
        (plugin->dbh,
         "SELECT " ALL 
-       "FROM ns090records WHERE record_name_hash=? ORDER BY rvalue OFFSET ? 
LIMIT 1",
+       " FROM ns090records WHERE record_name_hash=? ORDER BY rvalue LIMIT 1 
OFFSET ?",
         &plugin->iterate_by_name) != SQLITE_OK) ||
       (sq_prepare
        (plugin->dbh,
         "SELECT " ALL
-       "FROM ns090records ORDER BY rvalue OFFSET ? LIMIT 1",
+       " FROM ns090records ORDER BY rvalue LIMIT 1 OFFSET ?",
         &plugin->iterate_all) != SQLITE_OK) ||
       (sq_prepare
        (plugin->dbh,
@@ -645,16 +645,16 @@
     const char *name;
       
     ret = GNUNET_YES;
-    zone_key =  sqlite3_column_blob (plugin->iterate_records, 0);
-    name = (const char*) sqlite3_column_text (plugin->iterate_records, 1);
-    record_count = sqlite3_column_int (plugin->iterate_records, 2);
-    data_size = sqlite3_column_bytes (plugin->iterate_records, 3);
-    data = sqlite3_column_blob (plugin->iterate_records, 3);
-    expiration.abs_value = (uint64_t) sqlite3_column_int64 
(plugin->iterate_records, 4);
-    sig =  sqlite3_column_blob (plugin->iterate_records, 5);
+    zone_key =  sqlite3_column_blob (stmt, 0);
+    name = (const char*) sqlite3_column_text (stmt, 1);
+    record_count = sqlite3_column_int (stmt, 2);
+    data_size = sqlite3_column_bytes (stmt, 3);
+    data = sqlite3_column_blob (stmt, 3);
+    expiration.abs_value = (uint64_t) sqlite3_column_int64 (stmt, 4);
+    sig = sqlite3_column_blob (stmt, 5);
 
-    if ( (sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) != 
sqlite3_column_bytes (plugin->iterate_records, 0)) ||
-        (sizeof (struct GNUNET_CRYPTO_RsaSignature) != sqlite3_column_bytes 
(plugin->iterate_records, 5)) ||
+    if ( (sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) != 
sqlite3_column_bytes (stmt, 0)) ||
+        (sizeof (struct GNUNET_CRYPTO_RsaSignature) != sqlite3_column_bytes 
(stmt, 5)) ||
         (sizeof (struct DbRecord) * record_count > data_size) )
     {
       GNUNET_break (0);
@@ -670,7 +670,7 @@
       off = record_count * sizeof (struct DbRecord);
       for (i=0;i<record_count;i++)
       {
-       if (off + db[i].data_size > data_size)
+       if (off + ntohl (db[i].data_size) > data_size)
        {
          GNUNET_break (0);
          ret = GNUNET_SYSERR;
@@ -690,10 +690,10 @@
   }
   else
   {
+    if (SQLITE_DONE != sret)
+      LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite_step");
     iter (iter_cls, NULL, GNUNET_TIME_UNIT_ZERO_ABS, NULL, 0, NULL, NULL);
   }
-  if (SQLITE_DONE != sret)
-    LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite_step");
   if (SQLITE_OK != sqlite3_reset (stmt))
     LOG_SQLITE (plugin,
                GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,

Modified: gnunet/src/namestore/test_plugin_namestore.c
===================================================================
--- gnunet/src/namestore/test_plugin_namestore.c        2012-02-23 17:09:02 UTC 
(rev 19980)
+++ gnunet/src/namestore/test_plugin_namestore.c        2012-02-23 17:27:42 UTC 
(rev 19981)
@@ -102,6 +102,28 @@
             const struct GNUNET_NAMESTORE_RecordData *rd,
             const struct GNUNET_CRYPTO_RsaSignature *signature)
 {
+  int *idp = cls;
+  int id = *idp;
+  struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded tzone_key;
+  char tname[64];
+  unsigned int trd_count = 1 + (id % 1024);
+  struct GNUNET_CRYPTO_RsaSignature tsignature;
+  unsigned int i;
+
+  GNUNET_snprintf (tname, sizeof (tname),
+                  "a%u", (unsigned int ) id);
+  for (i=0;i<trd_count;i++)
+  {
+    GNUNET_assert (rd[i].data_size == id % 10);
+    GNUNET_assert (0 == memcmp ("Hello World", rd[i].data, id % 10));
+    GNUNET_assert (rd[i].record_type == 1 + (id % 13));
+    GNUNET_assert (rd[i].flags == (id  % 7));
+  }
+  memset (&tzone_key, (id % 241), sizeof (tzone_key));
+  memset (&tsignature, (id % 243), sizeof (tsignature));
+  GNUNET_assert (0 == strcmp (name, tname));
+  GNUNET_assert (0 == memcmp (&tzone_key, zone_key, sizeof (struct 
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)));
+  GNUNET_assert (0 == memcmp (&tsignature, signature, sizeof (struct 
GNUNET_CRYPTO_RsaSignature)));
 }
 
 
@@ -117,6 +139,34 @@
 static void
 put_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id)
 {
+  struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded zone_key;
+  struct GNUNET_TIME_Absolute expire;
+  char name[64];
+  unsigned int rd_count = 1 + (id % 1024);
+  struct GNUNET_NAMESTORE_RecordData rd[rd_count];
+  struct GNUNET_CRYPTO_RsaSignature signature;
+  unsigned int i;
+
+  GNUNET_snprintf (name, sizeof (name),
+                  "a%u", (unsigned int ) id);
+  expire = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES);
+  for (i=0;i<rd_count;i++)
+  {
+    rd[i].data = "Hello World";
+    rd[i].data_size = id % 10;
+    rd[i].expiration = GNUNET_TIME_relative_to_absolute 
(GNUNET_TIME_UNIT_MINUTES);
+    rd[i].record_type = 1 + (id % 13);
+    rd[i].flags = (id  % 7);    
+  }
+  memset (&zone_key, (id % 241), sizeof (zone_key));
+  memset (&signature, (id % 243), sizeof (signature));
+  GNUNET_assert (GNUNET_OK == nsp->put_records (nsp->cls,
+                                               &zone_key,
+                                               expire,
+                                               name,
+                                               rd_count,
+                                               rd,
+                                               &signature));
 }
 
 
@@ -125,6 +175,7 @@
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   struct GNUNET_NAMESTORE_PluginFunctions *nsp;  
+  struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded zone_key;
   GNUNET_HashCode zone;
   
   ok = 0;
@@ -139,7 +190,8 @@
   put_record (nsp, 1);
   get_record (nsp, 1);
 
-  memset (&zone, 42, sizeof (zone));  
+  memset (&zone_key, 1, sizeof (zone_key));
+  GNUNET_CRYPTO_hash (&zone_key, sizeof (zone_key), &zone);  
   nsp->delete_zone (nsp->cls, &zone);
   unload_plugin (nsp);
 }




reply via email to

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