nametore api change
authorMatthias Wachs <wachs@net.in.tum.de>
Wed, 29 Feb 2012 11:11:10 +0000 (11:11 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Wed, 29 Feb 2012 11:11:10 +0000 (11:11 +0000)
src/include/gnunet_namestore_plugin.h
src/include/gnunet_namestore_service.h
src/namestore/gnunet-service-namestore.c
src/namestore/namestore_api.c
src/namestore/plugin_namestore_sqlite.c
src/namestore/test_namestore_api_lookup.c

index 546851339c6e39ca239feadd54bdf29b04f4853e..bf43805e4cdfecd67f9b9fc2ac7b80d12870a76f 100644 (file)
@@ -56,7 +56,7 @@ typedef void (*GNUNET_NAMESTORE_RecordIterator) (void *cls,
                                                 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
                                                 struct GNUNET_TIME_Absolute expire,
                                                 const char *name,
-                                                unsigned int rd_count,
+                                                unsigned int rd_len,
                                                 const struct GNUNET_NAMESTORE_RecordData *rd,
                                                 const struct GNUNET_CRYPTO_RsaSignature *signature);
 
@@ -85,13 +85,13 @@ struct GNUNET_NAMESTORE_PluginFunctions
    * @param rd array of records with data to store
    * @param signature signature of the record block, NULL if signature is unavailable (i.e. 
    *        because the user queried for a particular record type only)
-   * @return GNUNET_OK on success
+   * @return GNUNET_OK on success, else GNUNET_SYSERR
    */
   int (*put_records) (void *cls, 
                      const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
                      struct GNUNET_TIME_Absolute expire,
                      const char *name,
-                     unsigned int rd_count,
+                     unsigned int rd_len,
                      const struct GNUNET_NAMESTORE_RecordData *rd,
                      const struct GNUNET_CRYPTO_RsaSignature *signature);
 
@@ -115,7 +115,7 @@ struct GNUNET_NAMESTORE_PluginFunctions
    *
    * @param cls closure (internal context for the plugin)
    * @param zone hash of public key of the zone, NULL to iterate over all zones
-   * @param name_hash hash of name, NULL to iterate over all records of the zone
+   * @param name name as '\0' terminated string, NULL to iterate over all records of the zone
    * @param offset offset in the list of all matching records
    * @param iter function to call with the result
    * @param iter_cls closure for iter
@@ -123,7 +123,7 @@ struct GNUNET_NAMESTORE_PluginFunctions
    */
   int (*iterate_records) (void *cls, 
                          const GNUNET_HashCode *zone,
-                         const GNUNET_HashCode *name_hash,
+                         const char *name,
                          uint64_t offset,
                          GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls);
 
index 8ab2ce802e947d1209c5bea60faddef1f374a86a..1302644187f2fbe3f65d8cf9b86cac28d756dff3 100644 (file)
@@ -274,7 +274,7 @@ typedef void (*GNUNET_NAMESTORE_RecordProcessor) (void *cls,
                                                  const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
                                                  struct GNUNET_TIME_Absolute expire,                       
                                                  const char *name,
-                                                 unsigned int rd_count,
+                                                 unsigned int rd_len,
                                                  const struct GNUNET_NAMESTORE_RecordData *rd,
                                                  const struct GNUNET_CRYPTO_RsaSignature *signature);
 
index 3640e678ba5626b6022361929ccbe2335b0e0b9b..fe916576478ea7966c317d08bd4fc4ccd66b9818 100644 (file)
@@ -253,8 +253,6 @@ handle_lookup_name_it (void *cls,
       copied_elements = rd_count;
       rd_selected = (struct GNUNET_NAMESTORE_RecordData *) rd;
     }
-
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "NAMESTORE_LOOKUP_NAME_RESPONSE: %p %u\n", rd_selected, copied_elements);
     rd_ser_len = GNUNET_NAMESTORE_records_serialize(&rd_ser, copied_elements, rd_selected);
   }
   else
@@ -319,12 +317,11 @@ static void handle_lookup_name (void *cls,
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_LOOKUP_NAME");
   struct LookupNameContext lnc;
   struct GNUNET_NAMESTORE_Client *nc;
-  GNUNET_HashCode name_hash;
   size_t name_len;
   char * name;
   uint32_t id = 0;
   uint32_t type = 0;
-
+  int res;
 
   if (ntohs (message->size) < sizeof (struct LookupNameMessage))
   {
@@ -353,17 +350,23 @@ static void handle_lookup_name (void *cls,
     return;
   }
 
-  name = GNUNET_malloc (name_len);
-  memcpy (name, &ln_msg[1], name_len);
+  name = (char *) &ln_msg[1];
+  if (name[name_len -1] != '\0')
+  {
+    GNUNET_break_op (0);
+    GNUNET_SERVER_receive_done (client, GNUNET_OK);
+    return;
+  }
+
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking up record for name `%s'\n", name);
-  GNUNET_CRYPTO_hash(name, name_len-1, &name_hash);
-  GNUNET_free (name);
 
   /* do the actual lookup */
   lnc.id = id;
   lnc.nc = nc;
   lnc.record_type = type;
-  GSN_database->iterate_records(GSN_database->cls, &ln_msg->zone, &ln_msg->zone, 0, &handle_lookup_name_it, &lnc);
+  res = GSN_database->iterate_records(GSN_database->cls, &ln_msg->zone, name, 0, &handle_lookup_name_it, &lnc);
+
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ITERATE RESULTS: %u\n" , res);
 
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }
index 943ede51912d44c9f0e39f22f9134cdd03a682db..250fa44a7ab46c03e97e048486fab90e41c2086d 100644 (file)
@@ -205,24 +205,29 @@ handle_lookup_name_response (struct GNUNET_NAMESTORE_QueueEntry *qe,
   struct GNUNET_CRYPTO_RsaSignature *signature = NULL;
   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded dummy;
   struct GNUNET_TIME_Absolute expire;
+  size_t exp_msg_len;
   size_t msg_len = 0;
   size_t name_len = 0;
   size_t rd_len = 0;
   int contains_sig = GNUNET_NO;
   int rd_count = 0;
 
-  rd_len = ntohs (msg->rd_len);
+  rd_len = ntohl (msg->rd_len);
   msg_len = ntohs (msg->header.size);
   name_len = ntohs (msg->name_len);
   contains_sig = ntohs (msg->contains_sig);
   expire = GNUNET_TIME_absolute_ntoh(msg->expire);
 
-  if (msg_len != sizeof (struct LookupNameResponseMessage) +
+  exp_msg_len = sizeof (struct LookupNameResponseMessage) +
       sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
       name_len +
       rd_len +
-      contains_sig * sizeof (struct GNUNET_CRYPTO_RsaSignature))
+      contains_sig * sizeof (struct GNUNET_CRYPTO_RsaSignature);
+
+  if (msg_len != exp_msg_len)
   {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message size describes with `%u' bytes but calculated size is %u bytes \n",
+                msg_len, exp_msg_len);
     GNUNET_break_op (0);
     return;
   }
index c2972164302e602a1ab4584f003431cb1b20ff7c..0e0fc5243e505dd27650c60ad4db740e7bfb973a 100644 (file)
@@ -490,6 +490,7 @@ namestore_sqlite_put_records (void *cls,
   (void) namestore_sqlite_remove_records (plugin, &zone, name);
   name_len = strlen (name);
   GNUNET_CRYPTO_hash (name, name_len, &nh);
+
   rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
   data_size = rd_count * sizeof (struct DbRecord);
   for (i=0;i<rd_count;i++)  
@@ -564,7 +565,7 @@ namestore_sqlite_put_records (void *cls,
  *
  * @param cls closure (internal context for the plugin)
  * @param zone hash of public key of the zone, NULL to iterate over all zones
- * @param name_hash hash of name, NULL to iterate over all records of the zone
+ * @param name name as string, NULL to iterate over all records of the zone
  * @param offset offset in the list of all matching records
  * @param iter function to call with the result
  * @param iter_cls closure for iter
@@ -573,26 +574,33 @@ namestore_sqlite_put_records (void *cls,
 static int 
 namestore_sqlite_iterate_records (void *cls, 
                                  const GNUNET_HashCode *zone,
-                                 const GNUNET_HashCode *name_hash,
+                                 const char *name,
                                  uint64_t offset,
                                  GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
 {
   struct Plugin *plugin = cls;
   sqlite3_stmt *stmt;
+  GNUNET_HashCode name_hase;
   unsigned int boff;
   int ret;
   int sret;
 
   if (NULL == zone)
-    if (NULL == name_hash)
+    if (NULL == name)
       stmt = plugin->iterate_all;
     else
+    {
+      GNUNET_CRYPTO_hash (name, strlen(name), &name_hase);
       stmt = plugin->iterate_by_name;
+    }
   else
-    if (NULL == name_hash)
+    if (NULL == name)
       stmt = plugin->iterate_by_zone;
     else
+    {
+      GNUNET_CRYPTO_hash (name, strlen(name), &name_hase);
       stmt = plugin->iterate_records;
+    }
 
   boff = 0;
   if ( (NULL != zone) &&
@@ -608,11 +616,12 @@ namestore_sqlite_iterate_records (void *cls,
                  "sqlite3_reset");
     return GNUNET_SYSERR;
   }      
-  if ( (NULL != name_hash) &&
+  if ( (NULL != name) &&
        (SQLITE_OK != sqlite3_bind_blob (stmt, ++boff, 
-                                       name_hash, sizeof (GNUNET_HashCode), 
+                                       &name_hase, sizeof (GNUNET_HashCode),
                                        SQLITE_STATIC)) )
   {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ITERATE NAME HASH: `%s'", GNUNET_h2s_full(&name_hase));
     LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
                "sqlite3_bind_XXXX");
     if (SQLITE_OK != sqlite3_reset (stmt))
index 0841fb2165494a109416c5f8342c4eaebd0b22ab..fafe5f2184804c32c4ba6f8f6f2b3de1894f08ba 100644 (file)
@@ -141,7 +141,7 @@ void name_lookup_proc (void *cls,
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to lookup records for name `%s'\n", name);
       res = 1;
     }
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup done for name %s'\n", name);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Lookup done for name %s'\n", name);
   }
 
   GNUNET_SCHEDULER_add_now(&end, NULL);
@@ -198,7 +198,7 @@ run (void *cls, char *const *args, const char *cfgfile,
   GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey);
 
   /* create random zone hash */
-  GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &zone);
+  GNUNET_CRYPTO_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &zone);
 
   struct GNUNET_CRYPTO_RsaSignature signature;