[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r33210 - in gnunet/src: include peerstore
From: |
gnunet |
Subject: |
[GNUnet-SVN] r33210 - in gnunet/src: include peerstore |
Date: |
Wed, 7 May 2014 16:14:38 +0200 |
Author: otarabai
Date: 2014-05-07 16:14:38 +0200 (Wed, 07 May 2014)
New Revision: 33210
Modified:
gnunet/src/include/gnunet_peerstore_service.h
gnunet/src/include/gnunet_protocols.h
gnunet/src/peerstore/peerstore.h
gnunet/src/peerstore/peerstore_api.c
gnunet/src/peerstore/plugin_peerstore_sqlite.c
Log:
PEERSTORE api update
Modified: gnunet/src/include/gnunet_peerstore_service.h
===================================================================
--- gnunet/src/include/gnunet_peerstore_service.h 2014-05-07 13:45:22 UTC
(rev 33209)
+++ gnunet/src/include/gnunet_peerstore_service.h 2014-05-07 14:14:38 UTC
(rev 33210)
@@ -53,17 +53,8 @@
* @param cls closure
* @param emsg error message, NULL on success
*/
-typedef void (*GNUNET_PEERSTORE_Continuation)(void *cls,
- const char *emsg);
+typedef void (*GNUNET_PEERSTORE_Continuation)(void *cls, const char *emsg);
-/**
- * Continuation called after an Add is completed
- *
- * @param cls closure
- * @param success #GNUNET_YES / #GNUNET_NO
- */
-typedef void (*GNUNET_PEERSTORE_AddContinuation)(void *cls, int success);
-
#if 0 /* keep Emacsens' auto-indent happy */
{
#endif
Modified: gnunet/src/include/gnunet_protocols.h
===================================================================
--- gnunet/src/include/gnunet_protocols.h 2014-05-07 13:45:22 UTC (rev
33209)
+++ gnunet/src/include/gnunet_protocols.h 2014-05-07 14:14:38 UTC (rev
33210)
@@ -2454,12 +2454,17 @@
#define GNUNET_MESSAGE_TYPE_SENSOR_END 803
+/*******************************************************************************
+ * PEERSTORE message types
+
******************************************************************************/
+
+#define GNUNET_MESSAGE_TYPE_PEERSTORE_ADD 820
+
+
/**
- * Next available: 830
+ * Next available: 840
*/
-
-
/*******************************************************************************
* SOCIAL message types
******************************************************************************/
Modified: gnunet/src/peerstore/peerstore.h
===================================================================
--- gnunet/src/peerstore/peerstore.h 2014-05-07 13:45:22 UTC (rev 33209)
+++ gnunet/src/peerstore/peerstore.h 2014-05-07 14:14:38 UTC (rev 33210)
@@ -28,5 +28,39 @@
GNUNET_NETWORK_STRUCT_BEGIN
+/**
+ * Message carrying a peerstore entry
+ */
+struct AddEntryMessage
+{
+ /**
+ * Type will be GNUNET_MESSAGE_TYPE_PEERINFO_GET
+ */
+ struct GNUNET_MessageHeader header;
+
+ /**
+ * Peer Identity
+ */
+ struct GNUNET_PeerIdentity peer;
+
+ /**
+ * Size of the sub_system string
+ * Allocated at position 0 after this struct
+ */
+ size_t sub_system_size;
+
+ /**
+ * Size of value blob
+ * Allocated at position 1 after this struct
+ */
+ size_t value_size;
+
+ /**
+ * Lifetime of entry
+ */
+ struct GNUNET_TIME_Relative lifetime;
+
+};
+
GNUNET_NETWORK_STRUCT_END
Modified: gnunet/src/peerstore/peerstore_api.c
===================================================================
--- gnunet/src/peerstore/peerstore_api.c 2014-05-07 13:45:22 UTC (rev
33209)
+++ gnunet/src/peerstore/peerstore_api.c 2014-05-07 14:14:38 UTC (rev
33210)
@@ -34,7 +34,7 @@
/******************************************************************************/
/**
- * Handle to the peerstore service.
+ * Handle to the PEERSTORE service.
*/
struct GNUNET_PEERSTORE_Handle
{
@@ -52,12 +52,12 @@
/**
* Head of transmission queue.
*/
- struct GNUNET_PEERSTORE_AddContext *rc_head;
+ struct GNUNET_PEERSTORE_AddContext *ac_head;
/**
* Tail of transmission queue.
*/
- struct GNUNET_PEERSTORE_AddContext *rc_tail;
+ struct GNUNET_PEERSTORE_AddContext *ac_tail;
/**
* Handle for the current transmission request, or NULL if none is pending.
@@ -140,6 +140,21 @@
/******************************************************************************/
/**
+ * Task scheduled to re-try connecting to the peerstore service.
+ *
+ * @param cls the 'struct GNUNET_PEERSTORE_Handle'
+ * @param tc scheduler context
+ */
+static void
+reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct GNUNET_PEERSTORE_Handle *h = cls;
+
+ h->r_task = GNUNET_SCHEDULER_NO_TASK;
+ reconnect (h);
+}
+
+/**
* Connect to the PEERSTORE service.
*
* @return NULL on error
@@ -176,21 +191,6 @@
}
/**
- * Task scheduled to re-try connecting to the PEERSTORE service.
- *
- * @param cls the 'struct GNUNET_PEERSTORE_Handle'
- * @param tc scheduler context
- */
-static void
-reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- struct GNUNET_PEERSTORE_Handle *h = cls;
-
- h->r_task = GNUNET_SCHEDULER_NO_TASK;
- reconnect (h);
-}
-
-/**
* Close the existing connection to PEERSTORE and reconnect.
*
* @param h handle to the service
@@ -238,25 +238,25 @@
do_transmit (void *cls, size_t size, void *buf)
{
struct GNUNET_PEERSTORE_Handle *h = cls;
- struct GNUNET_PEERSTORE_AddContext *rc = h->rc_head;
+ struct GNUNET_PEERSTORE_AddContext *ac = h->ac_head;
size_t ret;
h->th = NULL;
- if (NULL == rc)
+ if (NULL == ac)
return 0; /* request was cancelled in the meantime */
if (NULL == buf)
{
- /* PEERSTORE service died */
+ /* peerstore service died */
LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
"Failed to transmit message to `%s' service.\n", "PEERSTORE");
- GNUNET_CONTAINER_DLL_remove (h->rc_head, h->rc_tail, rc);
+ GNUNET_CONTAINER_DLL_remove (h->ac_head, h->ac_tail, ac);
reconnect (h);
- if (NULL != rc->cont)
- rc->cont (rc->cont_cls, _("failed to transmit request (service down?)"));
- GNUNET_free (rc);
+ if (NULL != ac->cont)
+ ac->cont (ac->cont_cls, _("failed to transmit request (service down?)"));
+ GNUNET_free (ac);
return 0;
}
- ret = rc->size;
+ ret = ac->size;
if (size < ret)
{
/* change in head of queue (i.e. cancel + add), try again */
@@ -265,12 +265,12 @@
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Transmitting request of size %u to `%s' service.\n", ret, "PEERSTORE");
- memcpy (buf, &rc[1], ret);
- GNUNET_CONTAINER_DLL_remove (h->rc_head, h->rc_tail, rc);
+ memcpy (buf, &ac[1], ret);
+ GNUNET_CONTAINER_DLL_remove (h->ac_head, h->ac_tail, ac);
trigger_transmit (h);
- if (NULL != rc->cont)
- rc->cont (rc->cont_cls, NULL);
- GNUNET_free (rc);
+ if (NULL != ac->cont)
+ ac->cont (ac->cont_cls, NULL);
+ GNUNET_free (ac);
return ret;
}
@@ -283,9 +283,9 @@
static void
trigger_transmit (struct GNUNET_PEERSTORE_Handle *h)
{
- struct GNUNET_PEERSTORE_AddContext *rc;
+ struct GNUNET_PEERSTORE_AddContext *ac;
- if (NULL == (rc = h->rc_head))
+ if (NULL == (ac = h->ac_head))
return; /* no requests queued */
if (NULL != h->th)
return; /* request already pending */
@@ -296,16 +296,57 @@
return;
}
h->th =
- GNUNET_CLIENT_notify_transmit_ready (h->client, rc->size,
+ GNUNET_CLIENT_notify_transmit_ready (h->client, ac->size,
GNUNET_TIME_UNIT_FOREVER_REL,
GNUNET_YES,
&do_transmit, h);
}
/******************************************************************************/
-/******************* STORE FUNCTIONS
*********************/
+/******************* ADD FUNCTIONS
*********************/
/******************************************************************************/
+struct GNUNET_PEERSTORE_AddContext *
+GNUNET_PEERSTORE_add (struct GNUNET_PEERSTORE_Handle *h,
+ const struct GNUNET_PeerIdentity *peer,
+ const char *sub_system,
+ const void *value,
+ size_t size,
+ struct GNUNET_TIME_Relative lifetime,
+ GNUNET_PEERSTORE_Continuation cont,
+ void *cont_cls)
+{
+ struct GNUNET_PEERSTORE_AddContext *ac;
+ struct AddEntryMessage *entry;
+ char *ss;
+ void *val;
+ size_t sub_system_size;
+ size_t request_size;
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Storing value (size: %lu) for subsytem `%s' and peer `%s'",
+ size, sub_system, GNUNET_i2s (peer));
+ sub_system_size = strlen(sub_system);
+ request_size = sizeof(struct AddEntryMessage) + sub_system_size + size;
+ ac = GNUNET_malloc(sizeof(struct GNUNET_PEERSTORE_AddContext) +
request_size);
+ ac->h = h;
+ ac->size = request_size;
+ entry = (struct AddEntryMessage *)&ac[1];
+ entry->header.size = htons(request_size);
+ entry->header.type = htons(GNUNET_MESSAGE_TYPE_PEERSTORE_ADD);
+ entry->peer = *peer;
+ entry->sub_system_size = sub_system_size;
+ entry->value_size = size;
+ entry->lifetime = lifetime;
+ ss = (char *)&entry[1];
+ memcpy(ss, sub_system, sub_system_size);
+ val = ss + sub_system_size;
+ memcpy(val, value, size);
+ GNUNET_CONTAINER_DLL_insert_tail(h->ac_head, h->ac_tail, ac);
+ trigger_transmit (h);
+ return ac;
+}
+
+
/* end of peerstore_api.c */
Modified: gnunet/src/peerstore/plugin_peerstore_sqlite.c
===================================================================
--- gnunet/src/peerstore/plugin_peerstore_sqlite.c 2014-05-07 13:45:22 UTC
(rev 33209)
+++ gnunet/src/peerstore/plugin_peerstore_sqlite.c 2014-05-07 14:14:38 UTC
(rev 33210)
@@ -85,26 +85,26 @@
* One key can store multiple values.
*
* @param cls closure (internal context for the plugin)
+ * @param peer peer identity
* @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)
+ const struct GNUNET_PeerIdentity *peer,
+ const char *sub_system,
+ 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)
+ if(SQLITE_OK != sqlite3_bind_blob(stmt, 2, peer, sizeof(struct
GNUNET_PeerIdentity), SQLITE_STATIC)
+ || SQLITE_OK != sqlite3_bind_text(stmt, 1, sub_system,
sizeof(sub_system), 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");
@@ -227,15 +227,15 @@
sql_exec (plugin->dbh,
"CREATE TABLE IF NOT EXISTS peerstoredata (\n"
+ " peer_id BLOB NOT NULL,\n"
" sub_system TEXT NOT NULL,\n"
- " peer_id BLOB NOT NULL,\n"
" value BLOB NULL"
");");
/* Prepare statements */
sql_prepare (plugin->dbh,
- "INSERT INTO peerstoredata (sub_system, peer_id, value) VALUES
(?,?,?);",
+ "INSERT INTO peerstoredata (peer_id, sub_system, value) VALUES
(?,?,?);",
&plugin->insert_peerstoredata);
return GNUNET_OK;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r33210 - in gnunet/src: include peerstore,
gnunet <=