From a74f95cb209906901dc44cff013fa9200c4e2e4e Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Wed, 29 Feb 2012 11:11:10 +0000 Subject: [PATCH] nametore api change --- src/include/gnunet_namestore_plugin.h | 10 +++++----- src/include/gnunet_namestore_service.h | 2 +- src/namestore/gnunet-service-namestore.c | 21 ++++++++++++--------- src/namestore/namestore_api.c | 11 ++++++++--- src/namestore/plugin_namestore_sqlite.c | 21 +++++++++++++++------ src/namestore/test_namestore_api_lookup.c | 4 ++-- 6 files changed, 43 insertions(+), 26 deletions(-) diff --git a/src/include/gnunet_namestore_plugin.h b/src/include/gnunet_namestore_plugin.h index 546851339..bf43805e4 100644 --- a/src/include/gnunet_namestore_plugin.h +++ b/src/include/gnunet_namestore_plugin.h @@ -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); diff --git a/src/include/gnunet_namestore_service.h b/src/include/gnunet_namestore_service.h index 8ab2ce802..130264418 100644 --- a/src/include/gnunet_namestore_service.h +++ b/src/include/gnunet_namestore_service.h @@ -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); diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index 3640e678b..fe9165764 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c @@ -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); } diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c index 943ede519..250fa44a7 100644 --- a/src/namestore/namestore_api.c +++ b/src/namestore/namestore_api.c @@ -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; } diff --git a/src/namestore/plugin_namestore_sqlite.c b/src/namestore/plugin_namestore_sqlite.c index c29721643..0e0fc5243 100644 --- a/src/namestore/plugin_namestore_sqlite.c +++ b/src/namestore/plugin_namestore_sqlite.c @@ -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;iiterate_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)) diff --git a/src/namestore/test_namestore_api_lookup.c b/src/namestore/test_namestore_api_lookup.c index 0841fb216..fafe5f218 100644 --- a/src/namestore/test_namestore_api_lookup.c +++ b/src/namestore/test_namestore_api_lookup.c @@ -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; -- 2.25.1