[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r30436 - gnunet/src/namestore
From: |
gnunet |
Subject: |
[GNUnet-SVN] r30436 - gnunet/src/namestore |
Date: |
Mon, 28 Oct 2013 15:02:20 +0100 |
Author: wachs
Date: 2013-10-28 15:02:20 +0100 (Mon, 28 Oct 2013)
New Revision: 30436
Modified:
gnunet/src/namestore/gnunet-service-namestore.c
gnunet/src/namestore/namestore.h
gnunet/src/namestore/namestore_api.c
gnunet/src/namestore/plugin_namestore_postgres.c
gnunet/src/namestore/plugin_namestore_sqlite.c
Log:
extended plugin api to support lookup function
added new index to both plugins
implemented lookup functionality in both plugins
namestore uses lookup function
Modified: gnunet/src/namestore/gnunet-service-namestore.c
===================================================================
--- gnunet/src/namestore/gnunet-service-namestore.c 2013-10-28 09:36:31 UTC
(rev 30435)
+++ gnunet/src/namestore/gnunet-service-namestore.c 2013-10-28 14:02:20 UTC
(rev 30436)
@@ -623,7 +623,6 @@
uint32_t name_len;
size_t src_size;
size_t res_size;
- int offset;
int res;
if (ntohs (message->size) < sizeof (struct LabelLookupMessage))
@@ -664,15 +663,8 @@
rlc.rd_ser_len = 0;
rlc.res_rd = NULL;
- offset = 0;
- do
- {
- /* changee this call */
- res = GSN_database->iterate_records (GSN_database->cls,
- &ll_msg->zone, offset, &lookup_it, &rlc);
- offset++;
- }
- while ((GNUNET_NO == rlc.found) && (GNUNET_OK == res));
+ res = GSN_database->lookup_records (GSN_database->cls,
+ &ll_msg->zone, name_tmp, &lookup_it, &rlc);
res_size = sizeof (struct LabelLookupResponseMessage) + name_len +
rlc.rd_ser_len;
llr_msg = GNUNET_malloc (res_size);
@@ -684,6 +676,10 @@
llr_msg->rd_count = htons (rlc.res_rd_count);
llr_msg->rd_len = htons (rlc.rd_ser_len);
res_name = (char *) &llr_msg[1];
+ if ((GNUNET_YES == rlc.found) && (GNUNET_OK == res))
+ llr_msg->found = ntohs (GNUNET_YES);
+ else
+ llr_msg->found = ntohs (GNUNET_NO);
memcpy (&llr_msg[1], name_tmp, name_len);
memcpy (&res_name[name_len], rlc.res_rd, rlc.rd_ser_len);
Modified: gnunet/src/namestore/namestore.h
===================================================================
--- gnunet/src/namestore/namestore.h 2013-10-28 09:36:31 UTC (rev 30435)
+++ gnunet/src/namestore/namestore.h 2013-10-28 14:02:20 UTC (rev 30436)
@@ -168,9 +168,10 @@
uint16_t rd_count GNUNET_PACKED;
/**
- * always zero (for alignment)
+ * Was the label found in the database??
+ * GNUNET_YES or GNUNET_NO
*/
- uint16_t reserved GNUNET_PACKED;
+ uint16_t found GNUNET_PACKED;
/**
* The private key of the authority.
Modified: gnunet/src/namestore/namestore_api.c
===================================================================
--- gnunet/src/namestore/namestore_api.c 2013-10-28 09:36:31 UTC (rev
30435)
+++ gnunet/src/namestore/namestore_api.c 2013-10-28 14:02:20 UTC (rev
30436)
@@ -300,6 +300,7 @@
size_t name_len;
size_t rd_len;
unsigned int rd_count;
+ int found;
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Received `%s'\n",
@@ -309,7 +310,7 @@
rd_count = ntohs (msg->rd_count);
msg_len = ntohs (msg->gns_header.header.size);
name_len = ntohs (msg->name_len);
- GNUNET_break (0 == ntohs (msg->reserved));
+ found = ntohs (msg->found);
exp_msg_len = sizeof (struct LabelLookupResponseMessage) + name_len + rd_len;
if (msg_len != exp_msg_len)
{
@@ -323,6 +324,17 @@
GNUNET_break (0);
return GNUNET_SYSERR;
}
+ if (GNUNET_NO == found)
+ {
+ /* label was not in namestore */
+ if (NULL != qe->proc)
+ qe->proc (qe->proc_cls,
+ &msg->private_key,
+ name,
+ 0, NULL);
+ return GNUNET_OK;
+ }
+
rd_tmp = &name[name_len];
{
struct GNUNET_GNSRECORD_Data rd[rd_count];
Modified: gnunet/src/namestore/plugin_namestore_postgres.c
===================================================================
--- gnunet/src/namestore/plugin_namestore_postgres.c 2013-10-28 09:36:31 UTC
(rev 30435)
+++ gnunet/src/namestore/plugin_namestore_postgres.c 2013-10-28 14:02:20 UTC
(rev 30436)
@@ -86,8 +86,9 @@
GNUNET_POSTGRES_exec (dbh,
"CREATE INDEX ir_pkey_iter ON ns097records
(zone_private_key,rvalue)")) ||
(GNUNET_OK !=
- GNUNET_POSTGRES_exec (dbh,
- "CREATE INDEX it_iter ON ns097records
(rvalue)")) )
+ GNUNET_POSTGRES_exec (dbh, "CREATE INDEX it_iter ON ns097records
(rvalue)")) ||
+ (GNUNET_OK !=
+ GNUNET_POSTGRES_exec (dbh, "CREATE INDEX ir_label ON ns097records
(label)")) )
LOG (GNUNET_ERROR_TYPE_ERROR,
_("Failed to create indices\n"));
}
@@ -178,7 +179,12 @@
GNUNET_POSTGRES_prepare (plugin->dbh,
"iterate_all_zones",
"SELECT
record_count,record_data,label,zone_private_key"
- " FROM ns097records ORDER BY rvalue LIMIT 1
OFFSET $1", 1)))
+ " FROM ns097records ORDER BY rvalue LIMIT 1
OFFSET $1", 1)) ||
+ (GNUNET_OK !=
+ GNUNET_POSTGRES_prepare (plugin->dbh,
+ "lookup_label",
+ "SELECT
record_count,record_data,label,zone_private_key"
+ " FROM ns097records WHERE records
zone_private_key=$1 AND label=$2", 2)))
{
PQfinish (plugin->dbh);
plugin->dbh = NULL;
@@ -370,6 +376,44 @@
/**
+ * Lookup records in the datastore for which we are the authority.
+ *
+ * @param cls closure (internal context for the plugin)
+ * @param zone private key of the zone
+ * @param label name of the record in the zone
+ * @param iter function to call with the result
+ * @param iter_cls closure for @a iter
+ * @return #GNUNET_OK on success, else #GNUNET_SYSERR
+ */
+static int
+namestore_postgres_lookup_records (void *cls,
+ const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, const char *label,
+ GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
+{
+ struct Plugin *plugin = cls;
+ const char *paramValues[] = {
+ (const char *) zone,
+ label
+ };
+ int paramLengths[] = {
+ sizeof (*zone),
+ strlen (label)
+ };
+ const int paramFormats[] = { 1, 1 };
+ PGresult *res;
+
+ res = PQexecPrepared (plugin->dbh,
+ "lookup_label", 2,
+ paramValues, paramLengths, paramFormats,
+ 1);
+ return get_record_and_call_iterator (plugin,
+ res,
+ zone,
+ iter, iter_cls);
+}
+
+
+/**
* Iterate over the results for a particular key and zone in the
* datastore. Will return at most one result to the iterator.
*
@@ -515,6 +559,7 @@
api->store_records = &namestore_postgres_store_records;
api->iterate_records = &namestore_postgres_iterate_records;
api->zone_to_name = &namestore_postgres_zone_to_name;
+ api->lookup_records = &namestore_postgres_lookup_records;
LOG (GNUNET_ERROR_TYPE_INFO,
_("Postgres database running\n"));
return api;
Modified: gnunet/src/namestore/plugin_namestore_sqlite.c
===================================================================
--- gnunet/src/namestore/plugin_namestore_sqlite.c 2013-10-28 09:36:31 UTC
(rev 30435)
+++ gnunet/src/namestore/plugin_namestore_sqlite.c 2013-10-28 14:02:20 UTC
(rev 30436)
@@ -97,6 +97,10 @@
*/
sqlite3_stmt *zone_to_name;
+ /**
+ * Precompiled SQL to lookup records based on label.
+ */
+ sqlite3_stmt *lookup_label;
};
@@ -278,7 +282,12 @@
(plugin->dbh,
"SELECT record_count,record_data,label,zone_private_key"
" FROM ns097records ORDER BY rvalue LIMIT 1 OFFSET ?",
- &plugin->iterate_all_zones) != SQLITE_OK)
+ &plugin->iterate_all_zones) != SQLITE_OK) ||
+ (sq_prepare
+ (plugin->dbh,
+ "SELECT record_count,record_data,label,zone_private_key"
+ " FROM ns097records WHERE zone_private_key=? AND label=?",
+ &plugin->lookup_label) != SQLITE_OK)
)
{
LOG_SQLITE (plugin,GNUNET_ERROR_TYPE_ERROR, "precompiling");
@@ -309,6 +318,8 @@
sqlite3_finalize (plugin->iterate_all_zones);
if (NULL != plugin->zone_to_name)
sqlite3_finalize (plugin->zone_to_name);
+ if (NULL != plugin->zone_to_name)
+ sqlite3_finalize (plugin->lookup_label);
result = sqlite3_close (plugin->dbh);
if (result == SQLITE_BUSY)
{
@@ -536,7 +547,52 @@
return ret;
}
+/**
+ * Lookup records in the datastore for which we are the authority.
+ *
+ * @param cls closure (internal context for the plugin)
+ * @param zone private key of the zone
+ * @param label name of the record in the zone
+ * @param iter function to call with the result
+ * @param iter_cls closure for @a iter
+ * @return #GNUNET_OK on success, else #GNUNET_SYSERR
+ */
+static int
+namestore_sqlite_lookup_records (void *cls,
+ const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, const char *label,
+ GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
+{
+ struct Plugin *plugin = cls;
+ sqlite3_stmt *stmt;
+ int err;
+ if (NULL == zone)
+ {
+ return GNUNET_SYSERR;
+ }
+ else
+ {
+ stmt = plugin->lookup_label;
+ err = ( (SQLITE_OK != sqlite3_bind_blob (stmt, 1,
+ zone, sizeof (struct
GNUNET_CRYPTO_EcdsaPrivateKey),
+ SQLITE_STATIC)) ||
+ (SQLITE_OK != sqlite3_bind_text (stmt, 2,
+ label, -1, SQLITE_STATIC)) );
+ }
+ if (err)
+ {
+ LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_bind_XXXX");
+ if (SQLITE_OK != sqlite3_reset (stmt))
+ LOG_SQLITE (plugin,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_reset");
+ return GNUNET_SYSERR;
+ }
+ return get_record_and_call_iterator (plugin, stmt, zone, iter, iter_cls);
+}
+
+
/**
* Iterate over the results for a particular key and zone in the
* datastore. Will return at most one result to the iterator.
@@ -658,6 +714,7 @@
api->store_records = &namestore_sqlite_store_records;
api->iterate_records = &namestore_sqlite_iterate_records;
api->zone_to_name = &namestore_sqlite_zone_to_name;
+ api->lookup_records = &namestore_sqlite_lookup_records;
LOG (GNUNET_ERROR_TYPE_INFO,
_("Sqlite database running\n"));
return api;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r30436 - gnunet/src/namestore,
gnunet <=