[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r33283 - in gnunet/src: include peerstore
From: |
gnunet |
Subject: |
[GNUnet-SVN] r33283 - in gnunet/src: include peerstore |
Date: |
Wed, 14 May 2014 18:40:45 +0200 |
Author: otarabai
Date: 2014-05-14 18:40:45 +0200 (Wed, 14 May 2014)
New Revision: 33283
Added:
gnunet/src/peerstore/peerstore_common.c
gnunet/src/peerstore/peerstore_common.h
Modified:
gnunet/src/include/gnunet_peerstore_plugin.h
gnunet/src/include/gnunet_protocols.h
gnunet/src/include/gnunet_sensor_service.h
gnunet/src/peerstore/Makefile.am
gnunet/src/peerstore/gnunet-service-peerstore.c
gnunet/src/peerstore/peerstore.h
gnunet/src/peerstore/peerstore_api.c
gnunet/src/peerstore/plugin_peerstore_sqlite.c
Log:
peerstore helper file
Modified: gnunet/src/include/gnunet_peerstore_plugin.h
===================================================================
--- gnunet/src/include/gnunet_peerstore_plugin.h 2014-05-14 14:06:29 UTC
(rev 33282)
+++ gnunet/src/include/gnunet_peerstore_plugin.h 2014-05-14 16:40:45 UTC
(rev 33283)
@@ -48,8 +48,9 @@
* @param size size of stored value
*/
typedef void (*GNUNET_PEERSTORE_RecordIterator) (void *cls,
+ const char *sub_system,
const struct GNUNET_PeerIdentity *peer,
- const char *sub_system,
+ const char *key,
const void *value,
size_t size);
@@ -86,19 +87,21 @@
/**
* Iterate over the records given an optional peer id
- * and/or sub system.
+ * and/or key.
*
* @param cls closure (internal context for the plugin)
+ * @param sub_system name of sub system
* @param peer Peer identity (can be NULL)
- * @param sub_system name of sub system (can be NULL)
+ * @param key entry key string (can be NULL)
* @param iter function to call with the result
* @param iter_cls closure for @a iter
- * @return #GNUNET_OK on success, #GNUNET_NO if there were no results,
#GNUNET_SYSERR on error
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
(*iterate_records) (void *cls,
+ const char *sub_system,
const struct GNUNET_PeerIdentity *peer,
- const char *sub_system,
+ const char *key,
GNUNET_PEERSTORE_RecordIterator iter, void *iter_cls);
};
Modified: gnunet/src/include/gnunet_protocols.h
===================================================================
--- gnunet/src/include/gnunet_protocols.h 2014-05-14 14:06:29 UTC (rev
33282)
+++ gnunet/src/include/gnunet_protocols.h 2014-05-14 16:40:45 UTC (rev
33283)
@@ -2472,7 +2472,12 @@
#define GNUNET_MESSAGE_TYPE_PEERSTORE_STORE_RESULT_OK 821
#define GNUNET_MESSAGE_TYPE_PEERSTORE_STORE_RESULT_FAIL 822
+/**
+ * Iteration request
+ */
+#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE 823
+
/**
* Next available: 840
*/
Modified: gnunet/src/include/gnunet_sensor_service.h
===================================================================
--- gnunet/src/include/gnunet_sensor_service.h 2014-05-14 14:06:29 UTC (rev
33282)
+++ gnunet/src/include/gnunet_sensor_service.h 2014-05-14 16:40:45 UTC (rev
33283)
@@ -46,7 +46,7 @@
/**
* Structure containing brief info about sensor
*/
-struct SensorInfoShort
+struct SensorInfoShort //FIXME: rename
{
/*
Modified: gnunet/src/peerstore/Makefile.am
===================================================================
--- gnunet/src/peerstore/Makefile.am 2014-05-14 14:06:29 UTC (rev 33282)
+++ gnunet/src/peerstore/Makefile.am 2014-05-14 16:40:45 UTC (rev 33283)
@@ -27,20 +27,23 @@
libgnunetpeerstore.la
gnunet_peerstore_SOURCES = \
- gnunet-peerstore.c
+ gnunet-peerstore.c
gnunet_peerstore_LDADD = \
$(top_builddir)/src/util/libgnunetutil.la \
libgnunetpeerstore.la \
$(GN_LIBINTL)
gnunet_service_peerstore_SOURCES = \
- gnunet-service-peerstore.c
+ gnunet-service-peerstore.c \
+ peerstore_common.c
+gnunet_service_peerstore_CFLAGS = $(AM_CFLAGS)
gnunet_service_peerstore_LDADD = \
$(top_builddir)/src/util/libgnunetutil.la \
$(GN_LIBINTL)
libgnunetpeerstore_la_SOURCES = \
- peerstore_api.c
+ peerstore_api.c \
+ peerstore_common.c
libgnunetpeerstore_la_LIBADD = \
$(top_builddir)/src/util/libgnunetutil.la
libgnunetpeerstore_la_LDFLAGS = \
Modified: gnunet/src/peerstore/gnunet-service-peerstore.c
===================================================================
--- gnunet/src/peerstore/gnunet-service-peerstore.c 2014-05-14 14:06:29 UTC
(rev 33282)
+++ gnunet/src/peerstore/gnunet-service-peerstore.c 2014-05-14 16:40:45 UTC
(rev 33283)
@@ -27,6 +27,7 @@
#include "gnunet_util_lib.h"
#include "peerstore.h"
#include "gnunet_peerstore_plugin.h"
+#include "peerstore_common.h"
//TODO: GNUNET_SERVER_receive_done() ?
//TODO: implement value lifetime
@@ -79,6 +80,20 @@
}
/**
+ * Handle an iterate request from client
+ *
+ * @param cls unused
+ * @param client identification of the client
+ * @param message the actual message
+ */
+void handle_iterate (void *cls,
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
+{
+
+}
+
+/**
* Handle a store request from client
*
* @param cls unused
@@ -89,49 +104,46 @@
struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
- struct StoreRequestMessage *req;
- uint16_t req_size;
- uint16_t ss_size;
- uint16_t key_size;
- uint16_t value_size;
- char *sub_system;
- char *key;
- void *value;
+ struct GNUNET_PEERSTORE_Record *record;
uint16_t response_type;
struct GNUNET_SERVER_TransmitContext *tc;
- req_size = ntohs(message->size);
- if(req_size < sizeof(struct StoreRequestMessage))
+ record = PEERSTORE_parse_record_message(message);
+ if(NULL == record)
{
- GNUNET_break(0);
+ GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Malformed store request from
client\n");
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
}
- req = (struct StoreRequestMessage *)message;
- ss_size = ntohs(req->sub_system_size);
- key_size = ntohs(req->key_size);
- value_size = ntohs(req->value_size);
- if(ss_size + key_size + value_size + sizeof(struct StoreRequestMessage)
- != req_size)
+ if(NULL == record->sub_system)
{
- GNUNET_break(0);
+ GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Sub system not supplied in client
store request\n");
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
}
- sub_system = (char *)&req[1];
- key = sub_system + ss_size;
- value = key + key_size;
+ if(NULL == record->peer)
+ {
+ GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Peer id not supplied in client store
request\n");
+ GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
+ return;
+ }
+ if(NULL == record->key)
+ {
+ GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Key not supplied in client store
request\n");
+ GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
+ return;
+ }
GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Received a store request (size: %lu) for
sub system `%s', peer `%s', key `%s'\n",
- value_size,
- sub_system,
- GNUNET_i2s (&req->peer),
- key);
+ record->value_size,
+ record->sub_system,
+ GNUNET_i2s (record->peer),
+ record->key);
if(GNUNET_OK == db->store_record(db->cls,
- sub_system,
- &req->peer,
- key,
- value,
- value_size))
+ record->sub_system,
+ record->peer,
+ record->key,
+ record->value,
+ record->value_size))
{
response_type = GNUNET_MESSAGE_TYPE_PEERSTORE_STORE_RESULT_OK;
}
@@ -161,6 +173,7 @@
{
static const struct GNUNET_SERVER_MessageHandler handlers[] = {
{&handle_store, NULL, GNUNET_MESSAGE_TYPE_PEERSTORE_STORE, 0},
+ {&handle_iterate, NULL, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE, 0},
{NULL, NULL, 0, 0}
};
char *database;
Modified: gnunet/src/peerstore/peerstore.h
===================================================================
--- gnunet/src/peerstore/peerstore.h 2014-05-14 14:06:29 UTC (rev 33282)
+++ gnunet/src/peerstore/peerstore.h 2014-05-14 16:40:45 UTC (rev 33283)
@@ -23,15 +23,18 @@
* @author Omar Tarabai
*/
+#ifndef PEERSTORE_H_
+#define PEERSTORE_H_
+
#include "gnunet_peerstore_service.h"
GNUNET_NETWORK_STRUCT_BEGIN
/**
- * Message carrying a PEERSTORE store request
+ * Message carrying a PEERSTORE record message
*/
-struct StoreRequestMessage
+struct StoreRecordMessage
{
/**
@@ -40,10 +43,9 @@
struct GNUNET_MessageHeader header;
/**
- * Size of the sub_system string
- * Allocated at position 0 after this struct
+ * #GNUNET_YES if peer id value set, #GNUNET_NO otherwise
*/
- size_t sub_system_size;
+ uint16_t peer_set;
/**
* Peer Identity
@@ -51,6 +53,12 @@
struct GNUNET_PeerIdentity peer;
/**
+ * Size of the sub_system string
+ * Allocated at position 0 after this struct
+ */
+ size_t sub_system_size;
+
+ /**
* Size of the key string
* Allocated at position 1 after this struct
*/
@@ -70,3 +78,5 @@
};
GNUNET_NETWORK_STRUCT_END
+
+#endif
Modified: gnunet/src/peerstore/peerstore_api.c
===================================================================
--- gnunet/src/peerstore/peerstore_api.c 2014-05-14 14:06:29 UTC (rev
33282)
+++ gnunet/src/peerstore/peerstore_api.c 2014-05-14 16:40:45 UTC (rev
33283)
@@ -26,6 +26,7 @@
#include "platform.h"
#include "gnunet_util_lib.h"
#include "peerstore.h"
+#include "peerstore_common.h"
#define LOG(kind,...) GNUNET_log_from (kind, "peerstore-api",__VA_ARGS__)
@@ -209,11 +210,7 @@
void *cont_cls)
{
struct GNUNET_PEERSTORE_StoreContext *sc;
- struct StoreRequestMessage *srm;
- size_t ss_size;
- size_t key_size;
- size_t request_size;
- void *dummy;
+ struct StoreRecordMessage *srm;
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Storing value (size: %lu) for subsytem `%s', peer `%s', key `%s'\n",
@@ -222,26 +219,12 @@
sc->cont = cont;
sc->cont_cls = cont_cls;
sc->h = h;
- ss_size = strlen(sub_system) + 1;
- key_size = strlen(key) + 1;
- request_size = sizeof(struct StoreRequestMessage) +
- ss_size +
- key_size +
- size;
- srm = GNUNET_malloc(request_size);
- srm->header.size = htons(request_size);
- srm->header.type = htons(GNUNET_MESSAGE_TYPE_PEERSTORE_STORE);
- srm->key_size = htons(key_size);
- srm->lifetime = lifetime;
- srm->peer = *peer;
- srm->sub_system_size = htons(ss_size);
- srm->value_size = htons(size);
- dummy = &srm[1];
- memcpy(dummy, sub_system, ss_size);
- dummy += ss_size;
- memcpy(dummy, key, key_size);
- dummy += key_size;
- memcpy(dummy, value, size);
+ srm = PEERSTORE_create_record_message(sub_system,
+ peer,
+ key,
+ value,
+ size,
+ lifetime);
GNUNET_CLIENT_transmit_and_get_response(h->client,
(const struct GNUNET_MessageHeader *)srm,
GNUNET_TIME_UNIT_FOREVER_REL,
Added: gnunet/src/peerstore/peerstore_common.c
===================================================================
--- gnunet/src/peerstore/peerstore_common.c (rev 0)
+++ gnunet/src/peerstore/peerstore_common.c 2014-05-14 16:40:45 UTC (rev
33283)
@@ -0,0 +1,139 @@
+/*
+ This file is part of GNUnet
+ (C) 2012-2013 Christian Grothoff (and other contributing authors)
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+ */
+/**
+ * @file peerstore/peerstore_common.c
+ * @brief Helper peerstore functions
+ * @author Omar Tarabai
+ */
+
+#include "peerstore_common.h"
+
+/**
+ * Creates a record message ready to be sent
+ *
+ * @param sub_system sub system string
+ * @param peer Peer identity (can be NULL)
+ * @param key record key string (can be NULL)
+ * @param value record value BLOB (can be NULL)
+ * @param value_size record value size in bytes (set to 0 if value is NULL)
+ * @param lifetime relative time after which the record expires
+ * @return pointer to record message struct
+ */
+struct StoreRecordMessage *
+PEERSTORE_create_record_message(const char *sub_system,
+ const struct GNUNET_PeerIdentity *peer,
+ const char *key,
+ const void *value,
+ size_t value_size,
+ struct GNUNET_TIME_Relative lifetime)
+{
+ struct StoreRecordMessage *srm;
+ size_t ss_size;
+ size_t key_size;
+ size_t request_size;
+ void *dummy;
+
+ ss_size = strlen(sub_system) + 1;
+ if(NULL == key)
+ key_size = 0;
+ else
+ key_size = strlen(key) + 1;
+ request_size = sizeof(struct StoreRecordMessage) +
+ ss_size +
+ key_size +
+ value_size;
+ srm = GNUNET_malloc(request_size);
+ srm->header.size = htons(request_size);
+ srm->header.type = htons(GNUNET_MESSAGE_TYPE_PEERSTORE_STORE);
+ srm->key_size = htons(key_size);
+ srm->lifetime = lifetime;
+ if(NULL == peer)
+ srm->peer_set = htons(GNUNET_NO);
+ else
+ {
+ srm->peer_set = htons(GNUNET_YES);
+ srm->peer = *peer;
+ }
+ srm->sub_system_size = htons(ss_size);
+ srm->value_size = htons(value_size);
+ dummy = &srm[1];
+ memcpy(dummy, sub_system, ss_size);
+ dummy += ss_size;
+ memcpy(dummy, key, key_size);
+ dummy += key_size;
+ memcpy(dummy, value, value_size);
+ return srm;
+
+}
+
+/**
+ * Parses a message carrying a record
+ *
+ * @param message the actual message
+ * @return Pointer to record or NULL if error
+ */
+struct GNUNET_PEERSTORE_Record *
+PEERSTORE_parse_record_message(const struct GNUNET_MessageHeader *message)
+{
+ struct StoreRecordMessage *srm;
+ struct GNUNET_PEERSTORE_Record *record;
+ uint16_t req_size;
+ uint16_t ss_size;
+ uint16_t key_size;
+ uint16_t value_size;
+ char *dummy;
+
+ req_size = ntohs(message->size);
+ if(req_size < sizeof(struct StoreRecordMessage))
+ return NULL;
+ srm = (struct StoreRecordMessage *)message;
+ ss_size = ntohs(srm->sub_system_size);
+ key_size = ntohs(srm->key_size);
+ value_size = ntohs(srm->value_size);
+ if(ss_size + key_size + value_size + sizeof(struct StoreRecordMessage)
+ != req_size)
+ return NULL;
+ record = GNUNET_new(struct GNUNET_PEERSTORE_Record);
+ if(GNUNET_YES == ntohs(srm->peer_set))
+ {
+ record->peer = GNUNET_new(struct GNUNET_PeerIdentity);
+ memcpy(record->peer, &srm->peer, sizeof(struct GNUNET_PeerIdentity));
+ }
+ record->lifetime = srm->lifetime;
+ dummy = (char *)&srm[1];
+ if(ss_size > 0)
+ {
+ record->sub_system = GNUNET_strdup(dummy);
+ dummy += ss_size;
+ }
+ if(key_size > 0)
+ {
+ record->key = GNUNET_strdup(dummy);
+ dummy += key_size;
+ }
+ if(value_size > 0)
+ {
+ record->value = GNUNET_malloc(value_size);
+ memcpy(record->value, dummy, value_size);
+ }
+ record->value_size = value_size;
+
+ return record;
+}
Added: gnunet/src/peerstore/peerstore_common.h
===================================================================
--- gnunet/src/peerstore/peerstore_common.h (rev 0)
+++ gnunet/src/peerstore/peerstore_common.h 2014-05-14 16:40:45 UTC (rev
33283)
@@ -0,0 +1,93 @@
+/*
+ This file is part of GNUnet
+ (C)
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+ */
+
+/**
+ * @file peerstore/peerstore_common.h
+ * @brief Helper peerstore functions
+ * @author Omar Tarabai
+ */
+
+#include "peerstore.h"
+
+/**
+ * PEERSTORE single record
+ */
+struct GNUNET_PEERSTORE_Record
+{
+
+ /**
+ * Responsible sub system string
+ */
+ char *sub_system;
+
+ /**
+ * Peer Identity
+ */
+ struct GNUNET_PeerIdentity *peer;
+
+ /**
+ * Record key string
+ */
+ char *key;
+
+ /**
+ * Record value BLOB
+ */
+ void *value;
+
+ /**
+ * Size of value BLOB
+ */
+ size_t value_size;
+
+ /**
+ * Lifetime of record
+ */
+ struct GNUNET_TIME_Relative lifetime;
+
+};
+
+/**
+ * Creates a record message ready to be sent
+ *
+ * @param sub_system sub system string
+ * @param peer Peer identity (can be NULL)
+ * @param key record key string (can be NULL)
+ * @param value record value BLOB (can be NULL)
+ * @param value_size record value size in bytes (set to 0 if value is NULL)
+ * @param lifetime relative time after which the record expires
+ * @return pointer to record message struct
+ */
+struct StoreRecordMessage *
+PEERSTORE_create_record_message(const char *sub_system,
+ const struct GNUNET_PeerIdentity *peer,
+ const char *key,
+ const void *value,
+ size_t value_size,
+ struct GNUNET_TIME_Relative lifetime);
+
+/**
+ * Parses a message carrying a record
+ *
+ * @param message the actual message
+ * @return Pointer to record or NULL if error
+ */
+struct GNUNET_PEERSTORE_Record *
+PEERSTORE_parse_record_message(const struct GNUNET_MessageHeader *message);
Modified: gnunet/src/peerstore/plugin_peerstore_sqlite.c
===================================================================
--- gnunet/src/peerstore/plugin_peerstore_sqlite.c 2014-05-14 14:06:29 UTC
(rev 33282)
+++ gnunet/src/peerstore/plugin_peerstore_sqlite.c 2014-05-14 16:40:45 UTC
(rev 33283)
@@ -90,101 +90,67 @@
/**
* Precompiled SQL for selecting from peerstoredata
*/
- sqlite3_stmt *select_peerstoredata_by_ss;
+ sqlite3_stmt *select_peerstoredata_by_key;
/**
* Precompiled SQL for selecting from peerstoredata
*/
- sqlite3_stmt *select_peerstoredata_by_both;
+ sqlite3_stmt *select_peerstoredata_by_all;
};
/**
- * The given 'sqlite' statement has been prepared to be run.
- * It will return a record which should be given to the iterator.
- * Runs the statement and parses the returned record.
- *
- * @param plugin plugin context
- * @param stmt to run (and then clean up)
- * @param iter iterator to call with the result
- * @param iter_cls closure for @a iter
- * @return #GNUNET_OK on success, #GNUNET_NO if there were no results,
#GNUNET_SYSERR on error
- */
-static int
-get_record_and_call_iterator (struct Plugin *plugin,
- sqlite3_stmt *stmt,
- GNUNET_PEERSTORE_RecordIterator iter, void *iter_cls)
-{
- int ret;
- int sret;
- const struct GNUNET_PeerIdentity *pid;
- const char *sub_system;
- const void *value;
- size_t value_size;
-
- ret = GNUNET_NO;
- if (SQLITE_ROW == (sret = sqlite3_step (stmt)))
- {
- pid = sqlite3_column_blob(stmt, 0);
- sub_system = (const char*) sqlite3_column_text(stmt, 1);
- value = sqlite3_column_blob(stmt, 2);
- value_size = sqlite3_column_bytes(stmt, 2);
- if (NULL != iter)
- iter (iter_cls, pid, sub_system, value, value_size);
- ret = GNUNET_YES;
- }
- else
- {
- if (SQLITE_DONE != sret)
- LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite_step");
- }
- if (SQLITE_OK != sqlite3_reset (stmt))
- LOG_SQLITE (plugin,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "sqlite3_reset");
- return ret;
-
-}
-
-/**
* Iterate over the records given an optional peer id
- * and/or sub system.
+ * and/or key.
*
* @param cls closure (internal context for the plugin)
+ * @param sub_system name of sub system
* @param peer Peer identity (can be NULL)
- * @param sub_system name of sub system (can be NULL)
+ * @param key entry key string (can be NULL)
* @param iter function to call with the result
* @param iter_cls closure for @a iter
- * @return #GNUNET_OK on success, #GNUNET_NO if there were no results,
#GNUNET_SYSERR on error
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
static int
peerstore_sqlite_iterate_records (void *cls,
+ const char *sub_system,
const struct GNUNET_PeerIdentity *peer,
- const char *sub_system,
+ const char *key,
GNUNET_PEERSTORE_RecordIterator iter, void *iter_cls)
{
struct Plugin *plugin = cls;
sqlite3_stmt *stmt;
int err = 0;
+ int sret;
+ const char *ret_sub_system;
+ const struct GNUNET_PeerIdentity *ret_peer;
+ const char *ret_key;
+ const void *ret_value;
+ size_t ret_value_size;
- if(NULL == sub_system && NULL == peer)
+ if(NULL == peer && NULL == key)
+ {
stmt = plugin->select_peerstoredata;
- else if(NULL == sub_system)
+ err = (SQLITE_OK != sqlite3_bind_text(stmt, 1, sub_system,
strlen(sub_system) + 1, SQLITE_STATIC));
+ }
+ else if(NULL == key)
{
stmt = plugin->select_peerstoredata_by_pid;
- err = (SQLITE_OK != sqlite3_bind_blob(stmt, 1, peer, sizeof(struct
GNUNET_PeerIdentity), SQLITE_STATIC));
+ err = (SQLITE_OK != sqlite3_bind_text(stmt, 1, sub_system,
strlen(sub_system) + 1, SQLITE_STATIC))
+ || (SQLITE_OK != sqlite3_bind_blob(stmt, 2, peer, sizeof(struct
GNUNET_PeerIdentity), SQLITE_STATIC));
}
else if(NULL == peer)
{
- stmt = plugin->select_peerstoredata_by_ss;
- err = (SQLITE_OK != sqlite3_bind_text(stmt, 1, sub_system,
strlen(sub_system) + 1, SQLITE_STATIC));
+ stmt = plugin->select_peerstoredata_by_key;
+ err = (SQLITE_OK != sqlite3_bind_text(stmt, 1, sub_system,
strlen(sub_system) + 1, SQLITE_STATIC))
+ || (SQLITE_OK != sqlite3_bind_text(stmt, 3, key, strlen(key) + 1,
SQLITE_STATIC));
}
else
{
- stmt = plugin->select_peerstoredata_by_both;
- err =
- (SQLITE_OK != sqlite3_bind_blob(stmt, 1, peer, sizeof(struct
GNUNET_PeerIdentity), SQLITE_STATIC))
- || (SQLITE_OK != sqlite3_bind_text(stmt, 2, sub_system,
strlen(sub_system) + 1, SQLITE_STATIC));
+ stmt = plugin->select_peerstoredata_by_all;
+ err = (SQLITE_OK != sqlite3_bind_text(stmt, 1, sub_system,
strlen(sub_system) + 1, SQLITE_STATIC))
+ || (SQLITE_OK != sqlite3_bind_blob(stmt, 2, peer, sizeof(struct
GNUNET_PeerIdentity), SQLITE_STATIC))
+ || (SQLITE_OK != sqlite3_bind_text(stmt, 3, key, strlen(key) + 1,
SQLITE_STATIC));
}
if (err)
@@ -197,7 +163,31 @@
"sqlite3_reset");
return GNUNET_SYSERR;
}
- return get_record_and_call_iterator (plugin, stmt, iter, iter_cls);
+ while (SQLITE_ROW == (sret = sqlite3_step (stmt)))
+ {
+ ret_sub_system = (const char *)sqlite3_column_text(stmt, 0);
+ ret_peer = sqlite3_column_blob(stmt, 1);
+ ret_key = (const char *)sqlite3_column_text(stmt, 2);
+ ret_value = sqlite3_column_blob(stmt, 3);
+ ret_value_size = sqlite3_column_bytes(stmt, 3);
+ if (NULL != iter)
+ iter (iter_cls, ret_sub_system, ret_peer, ret_key, ret_value,
ret_value_size);
+ }
+ if (SQLITE_DONE != sret)
+ {
+ LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite_step");
+ err = 1;
+ }
+ if (SQLITE_OK != sqlite3_reset (stmt))
+ {
+ LOG_SQLITE (plugin,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_reset");
+ err = 1;
+ }
+ if(err)
+ return GNUNET_SYSERR;
+ return GNUNET_OK;
}
/**
@@ -362,17 +352,25 @@
"INSERT INTO peerstoredata (sub_system, peer_id, key, value) VALUES
(?,?,?,?);",
&plugin->insert_peerstoredata);
sql_prepare(plugin->dbh,
- "SELECT peer_id, sub_system, value FROM peerstoredata",
+ "SELECT peer_id, sub_system, value FROM peerstoredata"
+ " WHERE sub_system = ?",
&plugin->select_peerstoredata);
sql_prepare(plugin->dbh,
- "SELECT peer_id, sub_system, value FROM peerstoredata WHERE peer_id = ?",
+ "SELECT peer_id, sub_system, value FROM peerstoredata"
+ " WHERE sub_system = ?"
+ " AND peer_id = ?",
&plugin->select_peerstoredata_by_pid);
sql_prepare(plugin->dbh,
- "SELECT peer_id, sub_system, value FROM peerstoredata WHERE sub_system =
?",
- &plugin->select_peerstoredata_by_ss);
+ "SELECT peer_id, sub_system, value FROM peerstoredata"
+ " WHERE sub_system = ?"
+ " AND key = ?",
+ &plugin->select_peerstoredata_by_key);
sql_prepare(plugin->dbh,
- "SELECT peer_id, sub_system, value FROM peerstoredata WHERE peer_id = ?
AND sub_system = ?",
- &plugin->select_peerstoredata_by_both);
+ "SELECT peer_id, sub_system, value FROM peerstoredata"
+ " WHERE sub_system = ?"
+ " AND peer_id = ?"
+ " AND key = ?",
+ &plugin->select_peerstoredata_by_all);
return GNUNET_OK;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r33283 - in gnunet/src: include peerstore,
gnunet <=