diff options
Diffstat (limited to 'src/plugin/namestore/plugin_namestore_postgres.c')
-rw-r--r-- | src/plugin/namestore/plugin_namestore_postgres.c | 105 |
1 files changed, 21 insertions, 84 deletions
diff --git a/src/plugin/namestore/plugin_namestore_postgres.c b/src/plugin/namestore/plugin_namestore_postgres.c index 1dc526dc2..e4c350a3e 100644 --- a/src/plugin/namestore/plugin_namestore_postgres.c +++ b/src/plugin/namestore/plugin_namestore_postgres.c | |||
@@ -23,9 +23,7 @@ | |||
23 | * @brief postgres-based namestore backend | 23 | * @brief postgres-based namestore backend |
24 | * @author Christian Grothoff | 24 | * @author Christian Grothoff |
25 | */ | 25 | */ |
26 | #include "platform.h" | ||
27 | #include "gnunet_namestore_plugin.h" | 26 | #include "gnunet_namestore_plugin.h" |
28 | #include "gnunet_namestore_service.h" | ||
29 | #include "gnunet_gnsrecord_lib.h" | 27 | #include "gnunet_gnsrecord_lib.h" |
30 | #include "gnunet_pq_lib.h" | 28 | #include "gnunet_pq_lib.h" |
31 | 29 | ||
@@ -122,8 +120,8 @@ database_prepare (struct Plugin *plugin) | |||
122 | struct GNUNET_PQ_PreparedStatement ps[] = { | 120 | struct GNUNET_PQ_PreparedStatement ps[] = { |
123 | GNUNET_PQ_make_prepare ("store_records", | 121 | GNUNET_PQ_make_prepare ("store_records", |
124 | "INSERT INTO namestore.ns098records" | 122 | "INSERT INTO namestore.ns098records" |
125 | " (zone_private_key, pkey, rvalue, record_count, record_data, label)" | 123 | " (zone_private_key, pkey, rvalue, record_count, record_data, label, editor_hint)" |
126 | " VALUES ($1, $2, $3, $4, $5, $6)" | 124 | " VALUES ($1, $2, $3, $4, $5, $6, '')" |
127 | " ON CONFLICT ON CONSTRAINT zl" | 125 | " ON CONFLICT ON CONSTRAINT zl" |
128 | " DO UPDATE" | 126 | " DO UPDATE" |
129 | " SET pkey=$2,rvalue=$3,record_count=$4,record_data=$5" | 127 | " SET pkey=$2,rvalue=$3,record_count=$4,record_data=$5" |
@@ -133,20 +131,22 @@ database_prepare (struct Plugin *plugin) | |||
133 | "DELETE FROM namestore.ns098records " | 131 | "DELETE FROM namestore.ns098records " |
134 | "WHERE zone_private_key=$1 AND label=$2"), | 132 | "WHERE zone_private_key=$1 AND label=$2"), |
135 | GNUNET_PQ_make_prepare ("zone_to_name", | 133 | GNUNET_PQ_make_prepare ("zone_to_name", |
136 | "SELECT seq,record_count,record_data,label FROM namestore.ns098records" | 134 | "SELECT seq,record_count,record_data,label,editor_hint FROM namestore.ns098records" |
137 | " WHERE zone_private_key=$1 AND pkey=$2"), | 135 | " WHERE zone_private_key=$1 AND pkey=$2"), |
138 | GNUNET_PQ_make_prepare ("iterate_zone", | 136 | GNUNET_PQ_make_prepare ("iterate_zone", |
139 | "SELECT seq,record_count,record_data,label FROM namestore.ns098records " | 137 | "SELECT seq,record_count,record_data,label,editor_hint FROM namestore.ns098records " |
140 | "WHERE zone_private_key=$1 AND seq > $2 ORDER BY seq ASC LIMIT $3"), | 138 | "WHERE zone_private_key=$1 AND seq > $2 ORDER BY seq ASC LIMIT $3"), |
141 | GNUNET_PQ_make_prepare ("iterate_all_zones", | 139 | GNUNET_PQ_make_prepare ("iterate_all_zones", |
142 | "SELECT seq,record_count,record_data,label,zone_private_key" | 140 | "SELECT seq,record_count,record_data,label,editor_hint,zone_private_key" |
143 | " FROM namestore.ns098records WHERE seq > $1 ORDER BY seq ASC LIMIT $2"), | 141 | " FROM namestore.ns098records WHERE seq > $1 ORDER BY seq ASC LIMIT $2"), |
144 | GNUNET_PQ_make_prepare ("lookup_label", | 142 | GNUNET_PQ_make_prepare ("lookup_label", |
145 | "SELECT seq,record_count,record_data,label " | 143 | "SELECT seq,record_count,record_data,label,editor_hint " |
146 | "FROM namestore.ns098records WHERE zone_private_key=$1 AND label=$2"), | 144 | "FROM namestore.ns098records WHERE zone_private_key=$1 AND label=$2"), |
147 | GNUNET_PQ_make_prepare ("edit_set", | 145 | GNUNET_PQ_make_prepare ("edit_set", |
148 | "SELECT seq,record_count,record_data,label " | 146 | "UPDATE namestore.ns098records" |
149 | "FROM namestore.ns098records WHERE zone_private_key=$1 AND label=$2 FOR UPDATE NOWAIT"), | 147 | "SET editor_hint=$3" |
148 | "WHERE zone_private_key=$1 AND label=$2" | ||
149 | "RETURNING seq,record_count,record_data,label,editor_hint "), | ||
150 | GNUNET_PQ_PREPARED_STATEMENT_END | 150 | GNUNET_PQ_PREPARED_STATEMENT_END |
151 | }; | 151 | }; |
152 | 152 | ||
@@ -377,12 +377,14 @@ parse_result_call_iterator (void *cls, | |||
377 | size_t data_size; | 377 | size_t data_size; |
378 | uint32_t record_count; | 378 | uint32_t record_count; |
379 | char *label; | 379 | char *label; |
380 | char *editor_hint; | ||
380 | struct GNUNET_CRYPTO_PrivateKey zk; | 381 | struct GNUNET_CRYPTO_PrivateKey zk; |
381 | struct GNUNET_PQ_ResultSpec rs_with_zone[] = { | 382 | struct GNUNET_PQ_ResultSpec rs_with_zone[] = { |
382 | GNUNET_PQ_result_spec_uint64 ("seq", &serial), | 383 | GNUNET_PQ_result_spec_uint64 ("seq", &serial), |
383 | GNUNET_PQ_result_spec_uint32 ("record_count", &record_count), | 384 | GNUNET_PQ_result_spec_uint32 ("record_count", &record_count), |
384 | GNUNET_PQ_result_spec_variable_size ("record_data", &data, &data_size), | 385 | GNUNET_PQ_result_spec_variable_size ("record_data", &data, &data_size), |
385 | GNUNET_PQ_result_spec_string ("label", &label), | 386 | GNUNET_PQ_result_spec_string ("label", &label), |
387 | GNUNET_PQ_result_spec_string ("editor_hint", &editor_hint), | ||
386 | GNUNET_PQ_result_spec_auto_from_type ("zone_private_key", &zk), | 388 | GNUNET_PQ_result_spec_auto_from_type ("zone_private_key", &zk), |
387 | GNUNET_PQ_result_spec_end | 389 | GNUNET_PQ_result_spec_end |
388 | }; | 390 | }; |
@@ -391,6 +393,7 @@ parse_result_call_iterator (void *cls, | |||
391 | GNUNET_PQ_result_spec_uint32 ("record_count", &record_count), | 393 | GNUNET_PQ_result_spec_uint32 ("record_count", &record_count), |
392 | GNUNET_PQ_result_spec_variable_size ("record_data", &data, &data_size), | 394 | GNUNET_PQ_result_spec_variable_size ("record_data", &data, &data_size), |
393 | GNUNET_PQ_result_spec_string ("label", &label), | 395 | GNUNET_PQ_result_spec_string ("label", &label), |
396 | GNUNET_PQ_result_spec_string ("editor_hint", &editor_hint), | ||
394 | GNUNET_PQ_result_spec_end | 397 | GNUNET_PQ_result_spec_end |
395 | }; | 398 | }; |
396 | struct GNUNET_PQ_ResultSpec *rs; | 399 | struct GNUNET_PQ_ResultSpec *rs; |
@@ -430,6 +433,7 @@ parse_result_call_iterator (void *cls, | |||
430 | } | 433 | } |
431 | pc->iter (pc->iter_cls, | 434 | pc->iter (pc->iter_cls, |
432 | serial, | 435 | serial, |
436 | editor_hint, | ||
433 | (NULL == pc->zone_key) ? &zk : pc->zone_key, | 437 | (NULL == pc->zone_key) ? &zk : pc->zone_key, |
434 | label, | 438 | label, |
435 | record_count, | 439 | record_count, |
@@ -459,13 +463,15 @@ lookup_records (void *cls, | |||
459 | const char *label, | 463 | const char *label, |
460 | GNUNET_NAMESTORE_RecordIterator iter, | 464 | GNUNET_NAMESTORE_RecordIterator iter, |
461 | void *iter_cls, | 465 | void *iter_cls, |
462 | const char*method) | 466 | const char *method, |
467 | const char *editor_hint) | ||
463 | { | 468 | { |
464 | struct Plugin *plugin = cls; | 469 | struct Plugin *plugin = cls; |
465 | GNUNET_assert (GNUNET_OK == database_prepare (plugin)); | 470 | GNUNET_assert (GNUNET_OK == database_prepare (plugin)); |
466 | struct GNUNET_PQ_QueryParam params[] = { | 471 | struct GNUNET_PQ_QueryParam params[] = { |
467 | GNUNET_PQ_query_param_auto_from_type (zone), | 472 | GNUNET_PQ_query_param_auto_from_type (zone), |
468 | GNUNET_PQ_query_param_string (label), | 473 | GNUNET_PQ_query_param_string (label), |
474 | GNUNET_PQ_query_param_string (editor_hint), | ||
469 | GNUNET_PQ_query_param_end | 475 | GNUNET_PQ_query_param_end |
470 | }; | 476 | }; |
471 | struct ParserContext pc; | 477 | struct ParserContext pc; |
@@ -510,7 +516,7 @@ namestore_postgres_lookup_records (void *cls, | |||
510 | GNUNET_NAMESTORE_RecordIterator iter, | 516 | GNUNET_NAMESTORE_RecordIterator iter, |
511 | void *iter_cls) | 517 | void *iter_cls) |
512 | { | 518 | { |
513 | return lookup_records (cls, zone, label, iter, iter_cls, "lookup_label"); | 519 | return lookup_records (cls, zone, label, iter, iter_cls, "lookup_label", ""); |
514 | } | 520 | } |
515 | 521 | ||
516 | 522 | ||
@@ -526,13 +532,15 @@ namestore_postgres_lookup_records (void *cls, | |||
526 | */ | 532 | */ |
527 | static int | 533 | static int |
528 | namestore_postgres_edit_records (void *cls, | 534 | namestore_postgres_edit_records (void *cls, |
535 | const char *editor_hint, | ||
529 | const struct | 536 | const struct |
530 | GNUNET_CRYPTO_PrivateKey *zone, | 537 | GNUNET_CRYPTO_PrivateKey *zone, |
531 | const char *label, | 538 | const char *label, |
532 | GNUNET_NAMESTORE_RecordIterator iter, | 539 | GNUNET_NAMESTORE_RecordIterator iter, |
533 | void *iter_cls) | 540 | void *iter_cls) |
534 | { | 541 | { |
535 | return lookup_records (cls, zone, label, iter, iter_cls, "edit_set"); | 542 | return lookup_records (cls, zone, label, iter, iter_cls, "edit_set", |
543 | (NULL == editor_hint) ? "" : editor_hint); | ||
536 | } | 544 | } |
537 | 545 | ||
538 | 546 | ||
@@ -650,74 +658,6 @@ namestore_postgres_zone_to_name (void *cls, | |||
650 | 658 | ||
651 | 659 | ||
652 | /** | 660 | /** |
653 | * Begin a transaction for a client. | ||
654 | * | ||
655 | * @param cls closure (internal context for the plugin) | ||
656 | * @param emsg error message set of return code is #GNUNET_SYSERR | ||
657 | * @return #GNUNET_YES on success, #GNUNET_SYSERR if transaction cannot be started. | ||
658 | */ | ||
659 | static enum GNUNET_GenericReturnValue | ||
660 | namestore_postgres_transaction_begin (void *cls, | ||
661 | char **emsg) | ||
662 | { | ||
663 | struct Plugin *plugin = cls; | ||
664 | GNUNET_assert (GNUNET_OK == database_prepare (plugin)); | ||
665 | struct GNUNET_PQ_ExecuteStatement es[] = { | ||
666 | GNUNET_PQ_make_execute ("BEGIN"), | ||
667 | GNUNET_PQ_EXECUTE_STATEMENT_END | ||
668 | }; | ||
669 | |||
670 | return GNUNET_PQ_exec_statements (plugin->dbh, es); | ||
671 | } | ||
672 | |||
673 | |||
674 | /** | ||
675 | * Commit a transaction for a client. | ||
676 | * This releases the lock on the database. | ||
677 | * | ||
678 | * @param cls closure (internal context for the plugin) | ||
679 | * @param emsg error message set of return code is #GNUNET_SYSERR | ||
680 | * @return #GNUNET_YES on success, #GNUNET_SYSERR if transaction cannot be started. | ||
681 | */ | ||
682 | static enum GNUNET_GenericReturnValue | ||
683 | namestore_postgres_transaction_rollback (void *cls, | ||
684 | char **emsg) | ||
685 | { | ||
686 | struct Plugin *plugin = cls; | ||
687 | GNUNET_assert (GNUNET_OK == database_prepare (plugin)); | ||
688 | struct GNUNET_PQ_ExecuteStatement es[] = { | ||
689 | GNUNET_PQ_make_execute ("ROLLBACK"), | ||
690 | GNUNET_PQ_EXECUTE_STATEMENT_END | ||
691 | }; | ||
692 | |||
693 | return GNUNET_PQ_exec_statements (plugin->dbh, es); | ||
694 | } | ||
695 | |||
696 | |||
697 | /** | ||
698 | * Roll back a transaction for a client. | ||
699 | * This releases the lock on the database. | ||
700 | * | ||
701 | * @param cls closure (internal context for the plugin) | ||
702 | * @param emsg error message set of return code is #GNUNET_SYSERR | ||
703 | * @return #GNUNET_YES on success, #GNUNET_SYSERR if transaction cannot be started. | ||
704 | */ | ||
705 | static enum GNUNET_GenericReturnValue | ||
706 | namestore_postgres_transaction_commit (void *cls, | ||
707 | char **emsg) | ||
708 | { | ||
709 | struct Plugin *plugin = cls; | ||
710 | GNUNET_assert (GNUNET_OK == database_prepare (plugin)); | ||
711 | struct GNUNET_PQ_ExecuteStatement es[] = { | ||
712 | GNUNET_PQ_make_execute ("COMMIT"), | ||
713 | GNUNET_PQ_EXECUTE_STATEMENT_END | ||
714 | }; | ||
715 | |||
716 | return GNUNET_PQ_exec_statements (plugin->dbh, es); | ||
717 | } | ||
718 | |||
719 | |||
720 | /** | ||
721 | * Shutdown database connection and associate data | 661 | * Shutdown database connection and associate data |
722 | * structures. | 662 | * structures. |
723 | * | 663 | * |
@@ -760,9 +700,6 @@ libgnunet_plugin_namestore_postgres_init (void *cls) | |||
760 | api->iterate_records = &namestore_postgres_iterate_records; | 700 | api->iterate_records = &namestore_postgres_iterate_records; |
761 | api->zone_to_name = &namestore_postgres_zone_to_name; | 701 | api->zone_to_name = &namestore_postgres_zone_to_name; |
762 | api->lookup_records = &namestore_postgres_lookup_records; | 702 | api->lookup_records = &namestore_postgres_lookup_records; |
763 | api->transaction_begin = &namestore_postgres_transaction_begin; | ||
764 | api->transaction_commit = &namestore_postgres_transaction_commit; | ||
765 | api->transaction_rollback = &namestore_postgres_transaction_rollback; | ||
766 | api->edit_records = &namestore_postgres_edit_records; | 703 | api->edit_records = &namestore_postgres_edit_records; |
767 | LOG (GNUNET_ERROR_TYPE_INFO, | 704 | LOG (GNUNET_ERROR_TYPE_INFO, |
768 | "Postgres namestore plugin running\n"); | 705 | "Postgres namestore plugin running\n"); |