aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/plugin_namestore_postgres.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-10-28 14:02:20 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-10-28 14:02:20 +0000
commit39dceb2cfe324e3f1b44958e3cf4cb936ab76881 (patch)
treebe84fba9fed2e859805475b6bff5a8bd3915e854 /src/namestore/plugin_namestore_postgres.c
parent50a4192766dd96f383020f9b2989b047155e4db3 (diff)
downloadgnunet-39dceb2cfe324e3f1b44958e3cf4cb936ab76881.tar.gz
gnunet-39dceb2cfe324e3f1b44958e3cf4cb936ab76881.zip
extended plugin api to support lookup function
added new index to both plugins implemented lookup functionality in both plugins namestore uses lookup function
Diffstat (limited to 'src/namestore/plugin_namestore_postgres.c')
-rw-r--r--src/namestore/plugin_namestore_postgres.c51
1 files changed, 48 insertions, 3 deletions
diff --git a/src/namestore/plugin_namestore_postgres.c b/src/namestore/plugin_namestore_postgres.c
index e84413400..cf52e0bac 100644
--- a/src/namestore/plugin_namestore_postgres.c
+++ b/src/namestore/plugin_namestore_postgres.c
@@ -86,8 +86,9 @@ create_indices (PGconn * dbh)
86 GNUNET_POSTGRES_exec (dbh, 86 GNUNET_POSTGRES_exec (dbh,
87 "CREATE INDEX ir_pkey_iter ON ns097records (zone_private_key,rvalue)")) || 87 "CREATE INDEX ir_pkey_iter ON ns097records (zone_private_key,rvalue)")) ||
88 (GNUNET_OK != 88 (GNUNET_OK !=
89 GNUNET_POSTGRES_exec (dbh, 89 GNUNET_POSTGRES_exec (dbh, "CREATE INDEX it_iter ON ns097records (rvalue)")) ||
90 "CREATE INDEX it_iter ON ns097records (rvalue)")) ) 90 (GNUNET_OK !=
91 GNUNET_POSTGRES_exec (dbh, "CREATE INDEX ir_label ON ns097records (label)")) )
91 LOG (GNUNET_ERROR_TYPE_ERROR, 92 LOG (GNUNET_ERROR_TYPE_ERROR,
92 _("Failed to create indices\n")); 93 _("Failed to create indices\n"));
93} 94}
@@ -178,7 +179,12 @@ database_setup (struct Plugin *plugin)
178 GNUNET_POSTGRES_prepare (plugin->dbh, 179 GNUNET_POSTGRES_prepare (plugin->dbh,
179 "iterate_all_zones", 180 "iterate_all_zones",
180 "SELECT record_count,record_data,label,zone_private_key" 181 "SELECT record_count,record_data,label,zone_private_key"
181 " FROM ns097records ORDER BY rvalue LIMIT 1 OFFSET $1", 1))) 182 " FROM ns097records ORDER BY rvalue LIMIT 1 OFFSET $1", 1)) ||
183 (GNUNET_OK !=
184 GNUNET_POSTGRES_prepare (plugin->dbh,
185 "lookup_label",
186 "SELECT record_count,record_data,label,zone_private_key"
187 " FROM ns097records WHERE records zone_private_key=$1 AND label=$2", 2)))
182 { 188 {
183 PQfinish (plugin->dbh); 189 PQfinish (plugin->dbh);
184 plugin->dbh = NULL; 190 plugin->dbh = NULL;
@@ -370,6 +376,44 @@ get_record_and_call_iterator (struct Plugin *plugin,
370 376
371 377
372/** 378/**
379 * Lookup records in the datastore for which we are the authority.
380 *
381 * @param cls closure (internal context for the plugin)
382 * @param zone private key of the zone
383 * @param label name of the record in the zone
384 * @param iter function to call with the result
385 * @param iter_cls closure for @a iter
386 * @return #GNUNET_OK on success, else #GNUNET_SYSERR
387 */
388static int
389namestore_postgres_lookup_records (void *cls,
390 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, const char *label,
391 GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
392{
393 struct Plugin *plugin = cls;
394 const char *paramValues[] = {
395 (const char *) zone,
396 label
397 };
398 int paramLengths[] = {
399 sizeof (*zone),
400 strlen (label)
401 };
402 const int paramFormats[] = { 1, 1 };
403 PGresult *res;
404
405 res = PQexecPrepared (plugin->dbh,
406 "lookup_label", 2,
407 paramValues, paramLengths, paramFormats,
408 1);
409 return get_record_and_call_iterator (plugin,
410 res,
411 zone,
412 iter, iter_cls);
413}
414
415
416/**
373 * Iterate over the results for a particular key and zone in the 417 * Iterate over the results for a particular key and zone in the
374 * datastore. Will return at most one result to the iterator. 418 * datastore. Will return at most one result to the iterator.
375 * 419 *
@@ -515,6 +559,7 @@ libgnunet_plugin_namestore_postgres_init (void *cls)
515 api->store_records = &namestore_postgres_store_records; 559 api->store_records = &namestore_postgres_store_records;
516 api->iterate_records = &namestore_postgres_iterate_records; 560 api->iterate_records = &namestore_postgres_iterate_records;
517 api->zone_to_name = &namestore_postgres_zone_to_name; 561 api->zone_to_name = &namestore_postgres_zone_to_name;
562 api->lookup_records = &namestore_postgres_lookup_records;
518 LOG (GNUNET_ERROR_TYPE_INFO, 563 LOG (GNUNET_ERROR_TYPE_INFO,
519 _("Postgres database running\n")); 564 _("Postgres database running\n"));
520 return api; 565 return api;