[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r33144 - in gnunet/src: include peerstore
From: |
gnunet |
Subject: |
[GNUnet-SVN] r33144 - in gnunet/src: include peerstore |
Date: |
Sun, 27 Apr 2014 20:40:04 +0200 |
Author: otarabai
Date: 2014-04-27 20:40:04 +0200 (Sun, 27 Apr 2014)
New Revision: 33144
Modified:
gnunet/src/include/gnunet_peerstore_plugin.h
gnunet/src/peerstore/gnunet-service-peerstore.c
gnunet/src/peerstore/plugin_peerstore_sqlite.c
Log:
PEERSTORE sqlite plugin store function
Modified: gnunet/src/include/gnunet_peerstore_plugin.h
===================================================================
--- gnunet/src/include/gnunet_peerstore_plugin.h 2014-04-27 17:45:49 UTC
(rev 33143)
+++ gnunet/src/include/gnunet_peerstore_plugin.h 2014-04-27 18:40:04 UTC
(rev 33144)
@@ -49,6 +49,25 @@
*/
void *cls;
+ /**
+ * Store a record in the peerstore.
+ * Key is the combination of sub system and peer identity.
+ * One key can store multiple values.
+ *
+ * @param cls closure (internal context for the plugin)
+ * @param sub_system name of the GNUnet sub system responsible
+ * @param peer peer identity
+ * @param value value to be stored
+ * @param size size of value to be stored
+ * @return #GNUNET_OK on success, else #GNUNET_SYSERR
+ */
+ int
+ (*store_record) (void *cls,
+ const char *sub_system,
+ const struct GNUNET_PeerIdentity *peer,
+ const void *value,
+ size_t size);
+
};
Modified: gnunet/src/peerstore/gnunet-service-peerstore.c
===================================================================
--- gnunet/src/peerstore/gnunet-service-peerstore.c 2014-04-27 17:45:49 UTC
(rev 33143)
+++ gnunet/src/peerstore/gnunet-service-peerstore.c 2014-04-27 18:40:04 UTC
(rev 33144)
@@ -33,6 +33,11 @@
static const struct GNUNET_CONFIGURATION_Handle *cfg;
/**
+ * Database plugin library name
+ */
+char *db_lib_name;
+
+/**
* Database handle
*/
static struct GNUNET_PEERSTORE_PluginFunctions *db;
@@ -47,6 +52,12 @@
shutdown_task (void *cls,
const struct GNUNET_SCHEDULER_TaskContext *tc)
{
+ if(NULL != db_lib_name)
+ {
+ GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, db));
+ GNUNET_free (db_lib_name);
+ db_lib_name = NULL;
+ }
}
@@ -79,7 +90,6 @@
{NULL, NULL, 0, 0}
};
char *database;
- char *db_lib_name;
cfg = c;
if (GNUNET_OK !=
Modified: gnunet/src/peerstore/plugin_peerstore_sqlite.c
===================================================================
--- gnunet/src/peerstore/plugin_peerstore_sqlite.c 2014-04-27 17:45:49 UTC
(rev 33143)
+++ gnunet/src/peerstore/plugin_peerstore_sqlite.c 2014-04-27 18:40:04 UTC
(rev 33144)
@@ -80,6 +80,51 @@
};
/**
+ * Store a record in the peerstore.
+ * Key is the combination of sub system and peer identity.
+ * One key can store multiple values.
+ *
+ * @param cls closure (internal context for the plugin)
+ * @param sub_system name of the GNUnet sub system responsible
+ * @param peer peer identity
+ * @param value value to be stored
+ * @param size size of value to be stored
+ * @return #GNUNET_OK on success, else #GNUNET_SYSERR
+ */
+static int
+peerstore_sqlite_store_record (void *cls,
+ const char *sub_system,
+ const struct GNUNET_PeerIdentity *peer,
+ const void *value,
+ size_t size)
+{
+ struct Plugin *plugin = cls;
+ sqlite3_stmt *stmt = plugin->insert_peerstoredata;
+
+ //FIXME: check if value exists with the same key first
+
+ if(SQLITE_OK != sqlite3_bind_text(stmt, 1, sub_system, sizeof(sub_system),
SQLITE_STATIC)
+ || SQLITE_OK != sqlite3_bind_blob(stmt, 2, peer, sizeof(struct
GNUNET_PeerIdentity), SQLITE_STATIC)
+ || SQLITE_OK != sqlite3_bind_blob(stmt, 3, value, size, SQLITE_STATIC))
+ LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_bind");
+ else if (SQLITE_DONE != sqlite3_step (stmt))
+ {
+ LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_step");
+ }
+ if (SQLITE_OK != sqlite3_reset (stmt))
+ {
+ LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_reset");
+ return GNUNET_SYSERR;
+ }
+
+ return GNUNET_OK;
+}
+
+
+/**
* @brief Prepare a SQL statement
*
* @param dbh handle to the database
@@ -243,7 +288,8 @@
}
api = GNUNET_new (struct GNUNET_PEERSTORE_PluginFunctions);
api->cls = &plugin;
- LOG(GNUNET_ERROR_TYPE_INFO, "Sqlite plugin is running\n");
+ api->store_record = &peerstore_sqlite_store_record;
+ LOG(GNUNET_ERROR_TYPE_DEBUG, "Sqlite plugin is running\n");
return api;
}
@@ -262,7 +308,7 @@
database_shutdown (plugin);
plugin->cfg = NULL;
GNUNET_free (api);
- LOG (GNUNET_ERROR_TYPE_INFO, "Sqlite plugin is finished\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Sqlite plugin is finished\n");
return NULL;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r33144 - in gnunet/src: include peerstore,
gnunet <=