database_shutdown (struct Plugin *plugin)
{
struct GNUNET_DISK_FileHandle *fh;
-
+
fh = GNUNET_DISK_file_open (plugin->fn,
GNUNET_DISK_OPEN_CREATE |
GNUNET_DISK_OPEN_TRUNCATE |
* @return #GNUNET_OK on success, else #GNUNET_SYSERR
*/
static int
-namestore_store_records (void *cls,
- const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
- const char *label,
- unsigned int rd_count,
- const struct GNUNET_GNSRECORD_Data *rd)
+namestore_flat_store_records (void *cls,
+ const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
+ const char *label,
+ unsigned int rd_count,
+ const struct GNUNET_GNSRECORD_Data *rd)
{
struct Plugin *plugin = cls;
uint64_t rvalue;
* @return #GNUNET_OK on success, else #GNUNET_SYSERR
*/
static int
-namestore_lookup_records (void *cls,
- const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
- const char *label,
- GNUNET_NAMESTORE_RecordIterator iter,
- void *iter_cls)
+namestore_flat_lookup_records (void *cls,
+ const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
+ const char *label,
+ GNUNET_NAMESTORE_RecordIterator iter,
+ void *iter_cls)
{
struct Plugin *plugin = cls;
struct FlatFileEntry *entry;
* @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error
*/
static int
-namestore_iterate_records (void *cls,
- const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
- uint64_t offset,
- GNUNET_NAMESTORE_RecordIterator iter,
- void *iter_cls)
+namestore_flat_iterate_records (void *cls,
+ const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
+ uint64_t offset,
+ GNUNET_NAMESTORE_RecordIterator iter,
+ void *iter_cls)
{
struct Plugin *plugin = cls;
* @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error
*/
static int
-namestore_zone_to_name (void *cls,
- const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
- const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone,
- GNUNET_NAMESTORE_RecordIterator iter,
- void *iter_cls)
+namestore_flat_zone_to_name (void *cls,
+ const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
+ const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone,
+ GNUNET_NAMESTORE_RecordIterator iter,
+ void *iter_cls)
{
struct Plugin *plugin = cls;
}
+/**
+ * Start a transaction.
+ *
+ * @param cls closure
+ * @return #GNUNET_OK on success, #GNUNET_NO if transactions are not supported,
+ * #GNUNET_SYSERR on internal errors
+ */
+static int
+namestore_flat_begin_transaction (void *cls)
+{
+ return GNUNET_NO;
+}
+
+
+/**
+ * Try to commit a transaction.
+ *
+ * @param cls closure
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
+ */
+static int
+namestore_flat_commit_transaction (void *cls)
+{
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+}
+
+
+/**
+ * Rollback a transaction.
+ *
+ * @param cls closure
+ */
+static void
+namestore_flat_rollback_transaction (void *cls)
+{
+ GNUNET_break (0);
+}
+
+
/**
* Entry point for the plugin.
*
}
api = GNUNET_new (struct GNUNET_NAMESTORE_PluginFunctions);
api->cls = &plugin;
- api->store_records = &namestore_store_records;
- api->iterate_records = &namestore_iterate_records;
- api->zone_to_name = &namestore_zone_to_name;
- api->lookup_records = &namestore_lookup_records;
+ api->store_records = &namestore_flat_store_records;
+ api->iterate_records = &namestore_flat_iterate_records;
+ api->zone_to_name = &namestore_flat_zone_to_name;
+ api->lookup_records = &namestore_flat_lookup_records;
+ api->begin_transaction = &namestore_flat_begin_transaction;
+ api->commit_transaction = &namestore_flat_commit_transaction;
+ api->rollback_transaction = &namestore_flat_rollback_transaction;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_("flat file database running\n"));
return api;
data_size,
data);
if ( (ret < 0) ||
- (data_size != (size_t) ret) )
+ (data_size != (size_t) ret) )
{
GNUNET_break (0);
return GNUNET_SYSERR;
}
+/**
+ * Start a transaction.
+ *
+ * @param cls closure
+ * @return #GNUNET_OK on success, #GNUNET_NO if transactions are not supported,
+ * #GNUNET_SYSERR on internal errors
+ */
+static int
+namestore_postgres_begin_transaction (void *cls)
+{
+ struct Plugin *plugin = cls;
+ PGresult *result;
+ ExecStatusType ex;
+
+ result = PQexec (plugin->dbh,
+ "START TRANSACTION ISOLATION LEVEL SERIALIZABLE");
+ if (PGRES_COMMAND_OK !=
+ (ex = PQresultStatus (result)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to start transaction (%s): %s\n",
+ PQresStatus (ex),
+ PQerrorMessage (plugin->dbh));
+ GNUNET_break (0);
+ PQclear (result);
+ return GNUNET_SYSERR;
+ }
+ PQclear (result);
+ return GNUNET_OK;
+}
+
+
+/**
+ * Try to commit a transaction.
+ *
+ * @param cls closure
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
+ */
+static int
+namestore_postgres_commit_transaction (void *cls)
+{
+ struct Plugin *plugin = cls;
+ PGresult *result;
+ ExecStatusType status;
+ int ret;
+
+ result = PQexec (plugin->dbh,
+ "COMMIT");
+ status = PQresultStatus (result);
+ ret = (PGRES_COMMAND_OK == status) ? GNUNET_OK : GNUNET_SYSERR;
+ PQclear (result);
+ return ret;
+}
+
+
+/**
+ * Rollback a transaction.
+ *
+ * @param cls closure
+ */
+static void
+namestore_postgres_rollback_transaction (void *cls)
+{
+ struct Plugin *plugin = cls;
+ PGresult *result;
+
+ result = PQexec (plugin->dbh,
+ "ROLLBACK");
+ GNUNET_break (PGRES_COMMAND_OK ==
+ PQresultStatus (result));
+ PQclear (result);
+}
+
+
/**
* Entry point for the plugin.
*
api->iterate_records = &namestore_postgres_iterate_records;
api->zone_to_name = &namestore_postgres_zone_to_name;
api->lookup_records = &namestore_postgres_lookup_records;
+ api->begin_transaction = &namestore_postgres_begin_transaction;
+ api->commit_transaction = &namestore_postgres_commit_transaction;
+ api->rollback_transaction = &namestore_postgres_rollback_transaction;
LOG (GNUNET_ERROR_TYPE_INFO,
"Postgres namestore plugin running\n");
return api;
}
+/**
+ * Start a transaction.
+ *
+ * @param cls closure
+ * @return #GNUNET_OK on success, #GNUNET_NO if transactions are not supported,
+ * #GNUNET_SYSERR on internal errors
+ */
+static int
+namestore_sqlite_begin_transaction (void *cls)
+{
+ return GNUNET_NO;
+}
+
+
+/**
+ * Try to commit a transaction.
+ *
+ * @param cls closure
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
+ */
+static int
+namestore_sqlite_commit_transaction (void *cls)
+{
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+}
+
+
+/**
+ * Rollback a transaction.
+ *
+ * @param cls closure
+ */
+static void
+namestore_sqlite_rollback_transaction (void *cls)
+{
+ GNUNET_break (0);
+}
+
+
+
/**
* Entry point for the plugin.
*
api->iterate_records = &namestore_sqlite_iterate_records;
api->zone_to_name = &namestore_sqlite_zone_to_name;
api->lookup_records = &namestore_sqlite_lookup_records;
+ api->begin_transaction = &namestore_sqlite_begin_transaction;
+ api->commit_transaction = &namestore_sqlite_commit_transaction;
+ api->rollback_transaction = &namestore_sqlite_rollback_transaction;
LOG (GNUNET_ERROR_TYPE_INFO,
_("Sqlite database running\n"));
return api;