aboutsummaryrefslogtreecommitdiff
path: root/src/datastore
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:46:35 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:46:35 +0000
commit502af2167f7c218366666ca4944bd7cc54b5b19a (patch)
treea91fec5cc9769d260640bd91c6633cb9cf395524 /src/datastore
parent03af5a603b7cc53432249d5854cd412aa90dde0d (diff)
indentation
Diffstat (limited to 'src/datastore')
-rw-r--r--src/datastore/datastore.h4
-rw-r--r--src/datastore/datastore_api.c1150
-rw-r--r--src/datastore/gnunet-service-datastore.c1289
-rw-r--r--src/datastore/perf_datastore_api.c340
-rw-r--r--src/datastore/perf_plugin_datastore.c467
-rw-r--r--src/datastore/plugin_datastore_mysql.c1070
-rw-r--r--src/datastore/plugin_datastore_postgres.c791
-rw-r--r--src/datastore/plugin_datastore_sqlite.c1072
-rw-r--r--src/datastore/plugin_datastore_template.c51
-rw-r--r--src/datastore/test_datastore_api.c718
-rw-r--r--src/datastore/test_datastore_api_management.c309
-rw-r--r--src/datastore/test_plugin_datastore.c324
12 files changed, 3514 insertions, 4071 deletions
diff --git a/src/datastore/datastore.h b/src/datastore/datastore.h
index 200473be92..39a680e423 100644
--- a/src/datastore/datastore.h
+++ b/src/datastore/datastore.h
@@ -213,7 +213,7 @@ struct DataMessage
* Priority of the item (NBO), zero for remove.
*/
uint32_t priority GNUNET_PACKED;
-
+
/**
* Desired anonymity level (NBO), zero for remove.
*/
@@ -236,7 +236,7 @@ struct DataMessage
* the key and content).
*/
uint64_t uid;
-
+
/**
* Expiration time (NBO); zero for remove.
*/
diff --git a/src/datastore/datastore_api.c b/src/datastore/datastore_api.c
index f355dfab5a..85e402a4d9 100644
--- a/src/datastore/datastore_api.c
+++ b/src/datastore/datastore_api.c
@@ -82,7 +82,7 @@ union QueueContext
{
struct StatusContext sc;
-
+
struct ResultContext rc;
};
@@ -121,7 +121,7 @@ struct GNUNET_DATASTORE_QueueEntry
* Function to call after transmission of the request.
*/
GNUNET_DATASTORE_ContinuationWithStatus cont;
-
+
/**
* Closure for 'cont'.
*/
@@ -167,7 +167,7 @@ struct GNUNET_DATASTORE_QueueEntry
* multiple of 64 bits.
*/
int was_transmitted;
-
+
};
/**
@@ -250,22 +250,19 @@ struct GNUNET_DATASTORE_Handle
* @return handle to use to access the service
*/
struct GNUNET_DATASTORE_Handle *
-GNUNET_DATASTORE_connect (const struct
- GNUNET_CONFIGURATION_Handle
- *cfg)
+GNUNET_DATASTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct GNUNET_CLIENT_Connection *c;
struct GNUNET_DATASTORE_Handle *h;
-
+
c = GNUNET_CLIENT_connect ("datastore", cfg);
if (c == NULL)
- return NULL; /* oops */
- h = GNUNET_malloc (sizeof(struct GNUNET_DATASTORE_Handle) +
- GNUNET_SERVER_MAX_MESSAGE_SIZE - 1);
+ return NULL; /* oops */
+ h = GNUNET_malloc (sizeof (struct GNUNET_DATASTORE_Handle) +
+ GNUNET_SERVER_MAX_MESSAGE_SIZE - 1);
h->client = c;
h->cfg = cfg;
- h->stats = GNUNET_STATISTICS_create ("datastore-api",
- cfg);
+ h->stats = GNUNET_STATISTICS_create ("datastore-api", cfg);
return h;
}
@@ -279,26 +276,24 @@ GNUNET_DATASTORE_connect (const struct
* @return number of bytes written to buf
*/
static size_t
-transmit_drop (void *cls,
- size_t size,
- void *buf)
+transmit_drop (void *cls, size_t size, void *buf)
{
struct GNUNET_DATASTORE_Handle *h = cls;
struct GNUNET_MessageHeader *hdr;
-
+
if (buf == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to transmit request to drop database.\n"));
- GNUNET_DATASTORE_disconnect (h, GNUNET_NO);
- return 0;
- }
- GNUNET_assert (size >= sizeof(struct GNUNET_MessageHeader));
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to transmit request to drop database.\n"));
+ GNUNET_DATASTORE_disconnect (h, GNUNET_NO);
+ return 0;
+ }
+ GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader));
hdr = buf;
- hdr->size = htons(sizeof(struct GNUNET_MessageHeader));
- hdr->type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_DROP);
+ hdr->size = htons (sizeof (struct GNUNET_MessageHeader));
+ hdr->type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_DROP);
GNUNET_DATASTORE_disconnect (h, GNUNET_NO);
- return sizeof(struct GNUNET_MessageHeader);
+ return sizeof (struct GNUNET_MessageHeader);
}
@@ -310,55 +305,51 @@ transmit_drop (void *cls,
* @param drop set to GNUNET_YES to delete all data in datastore (!)
*/
void
-GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h,
- int drop)
+GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h, int drop)
{
struct GNUNET_DATASTORE_QueueEntry *qe;
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Datastore disconnect\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Datastore disconnect\n");
#endif
if (NULL != h->th)
- {
- GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
- h->th = NULL;
- }
+ {
+ GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
+ h->th = NULL;
+ }
if (h->client != NULL)
- {
- GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
- h->client = NULL;
- }
+ {
+ GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
+ h->client = NULL;
+ }
if (h->reconnect_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (h->reconnect_task);
- h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (h->reconnect_task);
+ h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
+ }
while (NULL != (qe = h->queue_head))
+ {
+ GNUNET_assert (NULL != qe->response_proc);
+ qe->response_proc (h, NULL);
+ }
+ if (GNUNET_YES == drop)
+ {
+ h->client = GNUNET_CLIENT_connect ("datastore", h->cfg);
+ if (h->client != NULL)
{
- GNUNET_assert (NULL != qe->response_proc);
- qe->response_proc (h, NULL);
- }
- if (GNUNET_YES == drop)
- {
- h->client = GNUNET_CLIENT_connect ("datastore", h->cfg);
- if (h->client != NULL)
- {
- if (NULL !=
- GNUNET_CLIENT_notify_transmit_ready (h->client,
- sizeof(struct GNUNET_MessageHeader),
- GNUNET_TIME_UNIT_MINUTES,
- GNUNET_YES,
- &transmit_drop,
- h))
- return;
- GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
- h->client = NULL;
- }
- GNUNET_break (0);
+ if (NULL !=
+ GNUNET_CLIENT_notify_transmit_ready (h->client,
+ sizeof (struct
+ GNUNET_MessageHeader),
+ GNUNET_TIME_UNIT_MINUTES,
+ GNUNET_YES, &transmit_drop, h))
+ return;
+ GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
+ h->client = NULL;
}
- GNUNET_STATISTICS_destroy (h->stats,
- GNUNET_NO);
+ GNUNET_break (0);
+ }
+ GNUNET_STATISTICS_destroy (h->stats, GNUNET_NO);
h->stats = NULL;
GNUNET_free (h);
}
@@ -371,20 +362,18 @@ GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h,
* @param tc scheduler context
*/
static void
-timeout_queue_entry (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+timeout_queue_entry (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_DATASTORE_QueueEntry *qe = cls;
GNUNET_STATISTICS_update (qe->h->stats,
- gettext_noop ("# queue entry timeouts"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# queue entry timeouts"),
+ 1, GNUNET_NO);
qe->task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_assert (qe->was_transmitted == GNUNET_NO);
+ GNUNET_assert (qe->was_transmitted == GNUNET_NO);
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Timeout of request in datastore queue\n");
+ "Timeout of request in datastore queue\n");
#endif
qe->response_proc (qe->h, NULL);
}
@@ -406,12 +395,12 @@ timeout_queue_entry (void *cls,
*/
static struct GNUNET_DATASTORE_QueueEntry *
make_queue_entry (struct GNUNET_DATASTORE_Handle *h,
- size_t msize,
- unsigned int queue_priority,
- unsigned int max_queue_size,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_CLIENT_MessageHandler response_proc,
- const union QueueContext *qc)
+ size_t msize,
+ unsigned int queue_priority,
+ unsigned int max_queue_size,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_CLIENT_MessageHandler response_proc,
+ const union QueueContext *qc)
{
struct GNUNET_DATASTORE_QueueEntry *ret;
struct GNUNET_DATASTORE_QueueEntry *pos;
@@ -419,21 +408,18 @@ make_queue_entry (struct GNUNET_DATASTORE_Handle *h,
c = 0;
pos = h->queue_head;
- while ( (pos != NULL) &&
- (c < max_queue_size) &&
- (pos->priority >= queue_priority) )
- {
- c++;
- pos = pos->next;
- }
+ while ((pos != NULL) &&
+ (c < max_queue_size) && (pos->priority >= queue_priority))
+ {
+ c++;
+ pos = pos->next;
+ }
if (c >= max_queue_size)
- {
- GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# queue overflows"),
- 1,
- GNUNET_NO);
- return NULL;
- }
+ {
+ GNUNET_STATISTICS_update (h->stats,
+ gettext_noop ("# queue overflows"), 1, GNUNET_NO);
+ return NULL;
+ }
ret = GNUNET_malloc (sizeof (struct GNUNET_DATASTORE_QueueEntry) + msize);
ret->h = h;
ret->response_proc = response_proc;
@@ -444,61 +430,49 @@ make_queue_entry (struct GNUNET_DATASTORE_Handle *h,
ret->message_size = msize;
ret->was_transmitted = GNUNET_NO;
if (pos == NULL)
- {
- /* append at the tail */
- pos = h->queue_tail;
- }
+ {
+ /* append at the tail */
+ pos = h->queue_tail;
+ }
else
- {
- pos = pos->prev;
- /* do not insert at HEAD if HEAD query was already
- transmitted and we are still receiving replies! */
- if ( (pos == NULL) &&
- (h->queue_head->was_transmitted) )
- pos = h->queue_head;
- }
+ {
+ pos = pos->prev;
+ /* do not insert at HEAD if HEAD query was already
+ * transmitted and we are still receiving replies! */
+ if ((pos == NULL) && (h->queue_head->was_transmitted))
+ pos = h->queue_head;
+ }
c++;
GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# queue entries created"),
- 1,
- GNUNET_NO);
- GNUNET_CONTAINER_DLL_insert_after (h->queue_head,
- h->queue_tail,
- pos,
- ret);
+ gettext_noop ("# queue entries created"),
+ 1, GNUNET_NO);
+ GNUNET_CONTAINER_DLL_insert_after (h->queue_head, h->queue_tail, pos, ret);
h->queue_size++;
- ret->task = GNUNET_SCHEDULER_add_delayed (timeout,
- &timeout_queue_entry,
- ret);
+ ret->task = GNUNET_SCHEDULER_add_delayed (timeout, &timeout_queue_entry, ret);
pos = ret->next;
- while (pos != NULL)
+ while (pos != NULL)
+ {
+ if ((pos->max_queue < h->queue_size) && (pos->was_transmitted == GNUNET_NO))
{
- if ( (pos->max_queue < h->queue_size) &&
- (pos->was_transmitted == GNUNET_NO) )
- {
- GNUNET_assert (pos->response_proc != NULL);
- /* move 'pos' element to head so that it will be
- killed on 'NULL' call below */
+ GNUNET_assert (pos->response_proc != NULL);
+ /* move 'pos' element to head so that it will be
+ * killed on 'NULL' call below */
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Dropping request from datastore queue\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Dropping request from datastore queue\n");
#endif
- GNUNET_CONTAINER_DLL_remove (h->queue_head,
- h->queue_tail,
- pos);
- GNUNET_CONTAINER_DLL_insert (h->queue_head,
- h->queue_tail,
- pos);
- GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# Requests dropped from datastore queue"),
- 1,
- GNUNET_NO);
- GNUNET_assert (h->queue_head == pos);
- pos->response_proc (h, NULL);
- break;
- }
- pos = pos->next;
+ GNUNET_CONTAINER_DLL_remove (h->queue_head, h->queue_tail, pos);
+ GNUNET_CONTAINER_DLL_insert (h->queue_head, h->queue_tail, pos);
+ GNUNET_STATISTICS_update (h->stats,
+ gettext_noop
+ ("# Requests dropped from datastore queue"), 1,
+ GNUNET_NO);
+ GNUNET_assert (h->queue_head == pos);
+ pos->response_proc (h, NULL);
+ break;
}
+ pos = pos->next;
+ }
return ret;
}
@@ -509,8 +483,7 @@ make_queue_entry (struct GNUNET_DATASTORE_Handle *h,
*
* @param h handle to the datastore
*/
-static void
-process_queue (struct GNUNET_DATASTORE_Handle *h);
+static void process_queue (struct GNUNET_DATASTORE_Handle *h);
/**
@@ -520,8 +493,7 @@ process_queue (struct GNUNET_DATASTORE_Handle *h);
* @param tc scheduler context
*/
static void
-try_reconnect (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+try_reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_DATASTORE_Handle *h = cls;
@@ -534,18 +506,17 @@ try_reconnect (void *cls,
h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
h->client = GNUNET_CLIENT_connect ("datastore", h->cfg);
if (h->client == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "DATASTORE reconnect failed (fatally)\n");
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "DATASTORE reconnect failed (fatally)\n");
+ return;
+ }
GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# datastore connections (re)created"),
- 1,
- GNUNET_NO);
+ gettext_noop
+ ("# datastore connections (re)created"), 1,
+ GNUNET_NO);
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Reconnected to DATASTORE\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reconnected to DATASTORE\n");
#endif
process_queue (h);
}
@@ -561,25 +532,23 @@ static void
do_disconnect (struct GNUNET_DATASTORE_Handle *h)
{
if (h->client == NULL)
- {
+ {
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "client NULL in disconnect, will not try to reconnect\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "client NULL in disconnect, will not try to reconnect\n");
#endif
- return;
- }
+ return;
+ }
#if 0
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# reconnected to DATASTORE"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# reconnected to DATASTORE"),
+ 1, GNUNET_NO);
#endif
GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
h->skip_next_messages = 0;
h->client = NULL;
h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->retry_time,
- &try_reconnect,
- h);
+ &try_reconnect, h);
}
@@ -590,30 +559,28 @@ do_disconnect (struct GNUNET_DATASTORE_Handle *h)
* @param cls the 'struct GNUNET_DATASTORE_Handle'
* @param msg the received message
*/
-static void
-receive_cb (void *cls,
- const struct GNUNET_MessageHeader *msg)
+static void
+receive_cb (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_DATASTORE_Handle *h = cls;
struct GNUNET_DATASTORE_QueueEntry *qe;
h->in_receive = GNUNET_NO;
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Receiving reply from datastore\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving reply from datastore\n");
#endif
if (h->skip_next_messages > 0)
- {
- h->skip_next_messages--;
- process_queue (h);
- return;
- }
+ {
+ h->skip_next_messages--;
+ process_queue (h);
+ return;
+ }
if (NULL == (qe = h->queue_head))
- {
- GNUNET_break (0);
- process_queue (h);
- return;
- }
+ {
+ GNUNET_break (0);
+ process_queue (h);
+ return;
+ }
qe->response_proc (h, msg);
}
@@ -627,9 +594,7 @@ receive_cb (void *cls,
* @return number of bytes written to buf
*/
static size_t
-transmit_request (void *cls,
- size_t size,
- void *buf)
+transmit_request (void *cls, size_t size, void *buf)
{
struct GNUNET_DATASTORE_Handle *h = cls;
struct GNUNET_DATASTORE_QueueEntry *qe;
@@ -637,27 +602,25 @@ transmit_request (void *cls,
h->th = NULL;
if (NULL == (qe = h->queue_head))
- return 0; /* no entry in queue */
+ return 0; /* no entry in queue */
if (buf == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to transmit request to DATASTORE.\n"));
- GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# transmission request failures"),
- 1,
- GNUNET_NO);
- do_disconnect (h);
- return 0;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to transmit request to DATASTORE.\n"));
+ GNUNET_STATISTICS_update (h->stats,
+ gettext_noop ("# transmission request failures"),
+ 1, GNUNET_NO);
+ do_disconnect (h);
+ return 0;
+ }
if (size < (msize = qe->message_size))
- {
- process_queue (h);
- return 0;
- }
- #if DEBUG_DATASTORE
+ {
+ process_queue (h);
+ return 0;
+ }
+#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting %u byte request to DATASTORE\n",
- msize);
+ "Transmitting %u byte request to DATASTORE\n", msize);
#endif
memcpy (buf, &qe[1], msize);
qe->was_transmitted = GNUNET_YES;
@@ -666,13 +629,11 @@ transmit_request (void *cls,
GNUNET_assert (GNUNET_NO == h->in_receive);
h->in_receive = GNUNET_YES;
GNUNET_CLIENT_receive (h->client,
- &receive_cb,
- h,
- GNUNET_TIME_absolute_get_remaining (qe->timeout));
+ &receive_cb,
+ h, GNUNET_TIME_absolute_get_remaining (qe->timeout));
GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# bytes sent to datastore"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# bytes sent to datastore"),
+ 1, GNUNET_NO);
return msize;
}
@@ -689,53 +650,47 @@ process_queue (struct GNUNET_DATASTORE_Handle *h)
struct GNUNET_DATASTORE_QueueEntry *qe;
if (NULL == (qe = h->queue_head))
- {
+ {
#if DEBUG_DATASTORE > 1
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Queue empty\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Queue empty\n");
#endif
- return; /* no entry in queue */
- }
+ return; /* no entry in queue */
+ }
if (qe->was_transmitted == GNUNET_YES)
- {
+ {
#if DEBUG_DATASTORE > 1
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Head request already transmitted\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Head request already transmitted\n");
#endif
- return; /* waiting for replies */
- }
+ return; /* waiting for replies */
+ }
if (h->th != NULL)
- {
+ {
#if DEBUG_DATASTORE > 1
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Pending transmission request\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Pending transmission request\n");
#endif
- return; /* request pending */
- }
+ return; /* request pending */
+ }
if (h->client == NULL)
- {
+ {
#if DEBUG_DATASTORE > 1
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Not connected\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Not connected\n");
#endif
- return; /* waiting for reconnect */
- }
+ return; /* waiting for reconnect */
+ }
if (GNUNET_YES == h->in_receive)
- {
- /* wait for response to previous query */
- return;
- }
+ {
+ /* wait for response to previous query */
+ return;
+ }
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Queueing %u byte request to DATASTORE\n",
- qe->message_size);
+ "Queueing %u byte request to DATASTORE\n", qe->message_size);
#endif
h->th = GNUNET_CLIENT_notify_transmit_ready (h->client,
- qe->message_size,
- GNUNET_TIME_absolute_get_remaining (qe->timeout),
- GNUNET_YES,
- &transmit_request,
- h);
+ qe->message_size,
+ GNUNET_TIME_absolute_get_remaining
+ (qe->timeout), GNUNET_YES,
+ &transmit_request, h);
GNUNET_assert (GNUNET_NO == h->in_receive);
GNUNET_break (NULL != h->th);
}
@@ -767,16 +722,14 @@ free_queue_entry (struct GNUNET_DATASTORE_QueueEntry *qe)
{
struct GNUNET_DATASTORE_Handle *h = qe->h;
- GNUNET_CONTAINER_DLL_remove (h->queue_head,
- h->queue_tail,
- qe);
+ GNUNET_CONTAINER_DLL_remove (h->queue_head, h->queue_tail, qe);
if (qe->task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (qe->task);
- qe->task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (qe->task);
+ qe->task = GNUNET_SCHEDULER_NO_TASK;
+ }
h->queue_size--;
- qe->was_transmitted = GNUNET_SYSERR; /* use-after-free warning */
+ qe->was_transmitted = GNUNET_SYSERR; /* use-after-free warning */
GNUNET_free (qe);
}
@@ -788,10 +741,8 @@ free_queue_entry (struct GNUNET_DATASTORE_QueueEntry *qe)
* @param cls closure
* @param msg message received, NULL on timeout or fatal error
*/
-static void
-process_status_message (void *cls,
- const struct
- GNUNET_MessageHeader * msg)
+static void
+process_status_message (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_DATASTORE_Handle *h = cls;
struct GNUNET_DATASTORE_QueueEntry *qe;
@@ -802,74 +753,68 @@ process_status_message (void *cls,
int was_transmitted;
if (NULL == (qe = h->queue_head))
- {
- GNUNET_break (0);
- do_disconnect (h);
- return;
- }
+ {
+ GNUNET_break (0);
+ do_disconnect (h);
+ return;
+ }
rc = qe->qc.sc;
if (msg == NULL)
- {
- was_transmitted = qe->was_transmitted;
- free_queue_entry (qe);
- if (was_transmitted == GNUNET_YES)
- do_disconnect (h);
- else
- process_queue (h);
- if (rc.cont != NULL)
- rc.cont (rc.cont_cls,
- GNUNET_SYSERR,
- _("Failed to receive status response from database."));
- return;
- }
+ {
+ was_transmitted = qe->was_transmitted;
+ free_queue_entry (qe);
+ if (was_transmitted == GNUNET_YES)
+ do_disconnect (h);
+ else
+ process_queue (h);
+ if (rc.cont != NULL)
+ rc.cont (rc.cont_cls,
+ GNUNET_SYSERR,
+ _("Failed to receive status response from database."));
+ return;
+ }
GNUNET_assert (GNUNET_YES == qe->was_transmitted);
free_queue_entry (qe);
- if ( (ntohs(msg->size) < sizeof(struct StatusMessage)) ||
- (ntohs(msg->type) != GNUNET_MESSAGE_TYPE_DATASTORE_STATUS) )
- {
- GNUNET_break (0);
- h->retry_time = GNUNET_TIME_UNIT_ZERO;
- do_disconnect (h);
- if (rc.cont != NULL)
- rc.cont (rc.cont_cls,
- GNUNET_SYSERR,
- _("Error reading response from datastore service"));
- return;
- }
- sm = (const struct StatusMessage*) msg;
- status = ntohl(sm->status);
+ if ((ntohs (msg->size) < sizeof (struct StatusMessage)) ||
+ (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_DATASTORE_STATUS))
+ {
+ GNUNET_break (0);
+ h->retry_time = GNUNET_TIME_UNIT_ZERO;
+ do_disconnect (h);
+ if (rc.cont != NULL)
+ rc.cont (rc.cont_cls,
+ GNUNET_SYSERR,
+ _("Error reading response from datastore service"));
+ return;
+ }
+ sm = (const struct StatusMessage *) msg;
+ status = ntohl (sm->status);
emsg = NULL;
- if (ntohs(msg->size) > sizeof(struct StatusMessage))
- {
- emsg = (const char*) &sm[1];
- if (emsg[ntohs(msg->size) - sizeof(struct StatusMessage) - 1] != '\0')
- {
- GNUNET_break (0);
- emsg = _("Invalid error message received from datastore service");
- }
- }
- if ( (status == GNUNET_SYSERR) &&
- (emsg == NULL) )
+ if (ntohs (msg->size) > sizeof (struct StatusMessage))
+ {
+ emsg = (const char *) &sm[1];
+ if (emsg[ntohs (msg->size) - sizeof (struct StatusMessage) - 1] != '\0')
{
GNUNET_break (0);
emsg = _("Invalid error message received from datastore service");
}
+ }
+ if ((status == GNUNET_SYSERR) && (emsg == NULL))
+ {
+ GNUNET_break (0);
+ emsg = _("Invalid error message received from datastore service");
+ }
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received status %d/%s\n",
- (int) status,
- emsg);
+ "Received status %d/%s\n", (int) status, emsg);
#endif
GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# status messages received"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# status messages received"),
+ 1, GNUNET_NO);
h->retry_time.rel_value = 0;
process_queue (h);
if (rc.cont != NULL)
- rc.cont (rc.cont_cls,
- status,
- emsg);
+ rc.cont (rc.cont_cls, status, emsg);
}
@@ -901,20 +846,20 @@ process_status_message (void *cls,
*/
struct GNUNET_DATASTORE_QueueEntry *
GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
- uint32_t rid,
+ uint32_t rid,
const GNUNET_HashCode * key,
size_t size,
const void *data,
enum GNUNET_BLOCK_Type type,
uint32_t priority,
uint32_t anonymity,
- uint32_t replication,
+ uint32_t replication,
struct GNUNET_TIME_Absolute expiration,
- unsigned int queue_priority,
- unsigned int max_queue_size,
+ unsigned int queue_priority,
+ unsigned int max_queue_size,
struct GNUNET_TIME_Relative timeout,
- GNUNET_DATASTORE_ContinuationWithStatus cont,
- void *cont_cls)
+ GNUNET_DATASTORE_ContinuationWithStatus cont,
+ void *cont_cls)
{
struct GNUNET_DATASTORE_QueueEntry *qe;
struct DataMessage *dm;
@@ -923,42 +868,41 @@ GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asked to put %u bytes of data under key `%s' for %llu ms\n",
- size,
- GNUNET_h2s (key),
- GNUNET_TIME_absolute_get_remaining (expiration).rel_value);
+ "Asked to put %u bytes of data under key `%s' for %llu ms\n",
+ size,
+ GNUNET_h2s (key),
+ GNUNET_TIME_absolute_get_remaining (expiration).rel_value);
#endif
- msize = sizeof(struct DataMessage) + size;
+ msize = sizeof (struct DataMessage) + size;
GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
qc.sc.cont = cont;
qc.sc.cont_cls = cont_cls;
qe = make_queue_entry (h, msize,
- queue_priority, max_queue_size, timeout,
- &process_status_message, &qc);
+ queue_priority, max_queue_size, timeout,
+ &process_status_message, &qc);
if (qe == NULL)
- {
+ {
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Could not create queue entry for PUT\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Could not create queue entry for PUT\n");
#endif
- return NULL;
- }
+ return NULL;
+ }
GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# PUT requests executed"),
- 1,
- GNUNET_NO);
- dm = (struct DataMessage* ) &qe[1];
- dm->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_PUT);
- dm->header.size = htons(msize);
- dm->rid = htonl(rid);
- dm->size = htonl( (uint32_t) size);
- dm->type = htonl(type);
- dm->priority = htonl(priority);
- dm->anonymity = htonl(anonymity);
+ gettext_noop ("# PUT requests executed"),
+ 1, GNUNET_NO);
+ dm = (struct DataMessage *) &qe[1];
+ dm->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_PUT);
+ dm->header.size = htons (msize);
+ dm->rid = htonl (rid);
+ dm->size = htonl ((uint32_t) size);
+ dm->type = htonl (type);
+ dm->priority = htonl (priority);
+ dm->anonymity = htonl (anonymity);
dm->replication = htonl (replication);
dm->reserved = htonl (0);
- dm->uid = GNUNET_htonll(0);
- dm->expiration = GNUNET_TIME_absolute_hton(expiration);
+ dm->uid = GNUNET_htonll (0);
+ dm->expiration = GNUNET_TIME_absolute_hton (expiration);
dm->key = *key;
memcpy (&dm[1], data, size);
process_queue (h);
@@ -987,13 +931,13 @@ GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
*/
struct GNUNET_DATASTORE_QueueEntry *
GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h,
- uint64_t amount,
- uint32_t entries,
- unsigned int queue_priority,
- unsigned int max_queue_size,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_DATASTORE_ContinuationWithStatus cont,
- void *cont_cls)
+ uint64_t amount,
+ uint32_t entries,
+ unsigned int queue_priority,
+ unsigned int max_queue_size,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_DATASTORE_ContinuationWithStatus cont,
+ void *cont_cls)
{
struct GNUNET_DATASTORE_QueueEntry *qe;
struct ReserveMessage *rm;
@@ -1003,32 +947,30 @@ GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h,
cont = &drop_status_cont;
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asked to reserve %llu bytes of data and %u entries\n",
- (unsigned long long) amount,
- (unsigned int) entries);
+ "Asked to reserve %llu bytes of data and %u entries\n",
+ (unsigned long long) amount, (unsigned int) entries);
#endif
qc.sc.cont = cont;
qc.sc.cont_cls = cont_cls;
- qe = make_queue_entry (h, sizeof(struct ReserveMessage),
- queue_priority, max_queue_size, timeout,
- &process_status_message, &qc);
+ qe = make_queue_entry (h, sizeof (struct ReserveMessage),
+ queue_priority, max_queue_size, timeout,
+ &process_status_message, &qc);
if (qe == NULL)
- {
+ {
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Could not create queue entry to reserve\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Could not create queue entry to reserve\n");
#endif
- return NULL;
- }
+ return NULL;
+ }
GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# RESERVE requests executed"),
- 1,
- GNUNET_NO);
- rm = (struct ReserveMessage*) &qe[1];
- rm->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE);
- rm->header.size = htons(sizeof (struct ReserveMessage));
- rm->entries = htonl(entries);
- rm->amount = GNUNET_htonll(amount);
+ gettext_noop ("# RESERVE requests executed"),
+ 1, GNUNET_NO);
+ rm = (struct ReserveMessage *) &qe[1];
+ rm->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE);
+ rm->header.size = htons (sizeof (struct ReserveMessage));
+ rm->entries = htonl (entries);
+ rm->amount = GNUNET_htonll (amount);
process_queue (h);
return qe;
}
@@ -1057,12 +999,12 @@ GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h,
*/
struct GNUNET_DATASTORE_QueueEntry *
GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h,
- uint32_t rid,
- unsigned int queue_priority,
- unsigned int max_queue_size,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_DATASTORE_ContinuationWithStatus cont,
- void *cont_cls)
+ uint32_t rid,
+ unsigned int queue_priority,
+ unsigned int max_queue_size,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_DATASTORE_ContinuationWithStatus cont,
+ void *cont_cls)
{
struct GNUNET_DATASTORE_QueueEntry *qe;
struct ReleaseReserveMessage *rrm;
@@ -1071,31 +1013,29 @@ GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h,
if (cont == NULL)
cont = &drop_status_cont;
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asked to release reserve %d\n",
- rid);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asked to release reserve %d\n", rid);
#endif
qc.sc.cont = cont;
qc.sc.cont_cls = cont_cls;
- qe = make_queue_entry (h, sizeof(struct ReleaseReserveMessage),
- queue_priority, max_queue_size, timeout,
- &process_status_message, &qc);
+ qe = make_queue_entry (h, sizeof (struct ReleaseReserveMessage),
+ queue_priority, max_queue_size, timeout,
+ &process_status_message, &qc);
if (qe == NULL)
- {
+ {
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Could not create queue entry to release reserve\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Could not create queue entry to release reserve\n");
#endif
- return NULL;
- }
+ return NULL;
+ }
GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# RELEASE RESERVE requests executed"),
- 1,
- GNUNET_NO);
- rrm = (struct ReleaseReserveMessage*) &qe[1];
- rrm->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE);
- rrm->header.size = htons(sizeof (struct ReleaseReserveMessage));
- rrm->rid = htonl(rid);
+ gettext_noop
+ ("# RELEASE RESERVE requests executed"), 1,
+ GNUNET_NO);
+ rrm = (struct ReleaseReserveMessage *) &qe[1];
+ rrm->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE);
+ rrm->header.size = htons (sizeof (struct ReleaseReserveMessage));
+ rrm->rid = htonl (rid);
process_queue (h);
return qe;
}
@@ -1120,14 +1060,14 @@ GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h,
*/
struct GNUNET_DATASTORE_QueueEntry *
GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h,
- uint64_t uid,
- uint32_t priority,
- struct GNUNET_TIME_Absolute expiration,
- unsigned int queue_priority,
- unsigned int max_queue_size,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_DATASTORE_ContinuationWithStatus cont,
- void *cont_cls)
+ uint64_t uid,
+ uint32_t priority,
+ struct GNUNET_TIME_Absolute expiration,
+ unsigned int queue_priority,
+ unsigned int max_queue_size,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_DATASTORE_ContinuationWithStatus cont,
+ void *cont_cls)
{
struct GNUNET_DATASTORE_QueueEntry *qe;
struct UpdateMessage *um;
@@ -1137,34 +1077,33 @@ GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h,
cont = &drop_status_cont;
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asked to update entry %llu raising priority by %u and expiration to %llu\n",
- uid,
- (unsigned int) priority,
- (unsigned long long) expiration.abs_value);
+ "Asked to update entry %llu raising priority by %u and expiration to %llu\n",
+ uid,
+ (unsigned int) priority,
+ (unsigned long long) expiration.abs_value);
#endif
qc.sc.cont = cont;
qc.sc.cont_cls = cont_cls;
- qe = make_queue_entry (h, sizeof(struct UpdateMessage),
- queue_priority, max_queue_size, timeout,
- &process_status_message, &qc);
+ qe = make_queue_entry (h, sizeof (struct UpdateMessage),
+ queue_priority, max_queue_size, timeout,
+ &process_status_message, &qc);
if (qe == NULL)
- {
+ {
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Could not create queue entry for UPDATE\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Could not create queue entry for UPDATE\n");
#endif
- return NULL;
- }
+ return NULL;
+ }
GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# UPDATE requests executed"),
- 1,
- GNUNET_NO);
- um = (struct UpdateMessage*) &qe[1];
- um->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_UPDATE);
- um->header.size = htons(sizeof (struct UpdateMessage));
- um->priority = htonl(priority);
- um->expiration = GNUNET_TIME_absolute_hton(expiration);
- um->uid = GNUNET_htonll(uid);
+ gettext_noop ("# UPDATE requests executed"),
+ 1, GNUNET_NO);
+ um = (struct UpdateMessage *) &qe[1];
+ um->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_UPDATE);
+ um->header.size = htons (sizeof (struct UpdateMessage));
+ um->priority = htonl (priority);
+ um->expiration = GNUNET_TIME_absolute_hton (expiration);
+ um->uid = GNUNET_htonll (uid);
process_queue (h);
return qe;
}
@@ -1193,14 +1132,14 @@ GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h,
*/
struct GNUNET_DATASTORE_QueueEntry *
GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
- const GNUNET_HashCode *key,
- size_t size,
- const void *data,
- unsigned int queue_priority,
- unsigned int max_queue_size,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_DATASTORE_ContinuationWithStatus cont,
- void *cont_cls)
+ const GNUNET_HashCode * key,
+ size_t size,
+ const void *data,
+ unsigned int queue_priority,
+ unsigned int max_queue_size,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_DATASTORE_ContinuationWithStatus cont,
+ void *cont_cls)
{
struct GNUNET_DATASTORE_QueueEntry *qe;
struct DataMessage *dm;
@@ -1211,39 +1150,37 @@ GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
cont = &drop_status_cont;
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asked to remove %u bytes under key `%s'\n",
- size,
- GNUNET_h2s (key));
+ "Asked to remove %u bytes under key `%s'\n",
+ size, GNUNET_h2s (key));
#endif
qc.sc.cont = cont;
qc.sc.cont_cls = cont_cls;
- msize = sizeof(struct DataMessage) + size;
+ msize = sizeof (struct DataMessage) + size;
GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
qe = make_queue_entry (h, msize,
- queue_priority, max_queue_size, timeout,
- &process_status_message, &qc);
+ queue_priority, max_queue_size, timeout,
+ &process_status_message, &qc);
if (qe == NULL)
- {
+ {
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Could not create queue entry for REMOVE\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Could not create queue entry for REMOVE\n");
#endif
- return NULL;
- }
+ return NULL;
+ }
GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# REMOVE requests executed"),
- 1,
- GNUNET_NO);
- dm = (struct DataMessage*) &qe[1];
- dm->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE);
- dm->header.size = htons(msize);
- dm->rid = htonl(0);
- dm->size = htonl(size);
- dm->type = htonl(0);
- dm->priority = htonl(0);
- dm->anonymity = htonl(0);
- dm->uid = GNUNET_htonll(0);
- dm->expiration = GNUNET_TIME_absolute_hton(GNUNET_TIME_UNIT_ZERO_ABS);
+ gettext_noop ("# REMOVE requests executed"),
+ 1, GNUNET_NO);
+ dm = (struct DataMessage *) &qe[1];
+ dm->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE);
+ dm->header.size = htons (msize);
+ dm->rid = htonl (0);
+ dm->size = htonl (size);
+ dm->type = htonl (0);
+ dm->priority = htonl (0);
+ dm->anonymity = htonl (0);
+ dm->uid = GNUNET_htonll (0);
+ dm->expiration = GNUNET_TIME_absolute_hton (GNUNET_TIME_UNIT_ZERO_ABS);
dm->key = *key;
memcpy (&dm[1], data, size);
process_queue (h);
@@ -1258,9 +1195,8 @@ GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
* @param cls closure
* @param msg message received, NULL on timeout or fatal error
*/
-static void
-process_result_message (void *cls,
- const struct GNUNET_MessageHeader *msg)
+static void
+process_result_message (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_DATASTORE_Handle *h = cls;
struct GNUNET_DATASTORE_QueueEntry *qe;
@@ -1269,104 +1205,98 @@ process_result_message (void *cls,
int was_transmitted;
if (msg == NULL)
+ {
+ qe = h->queue_head;
+ GNUNET_assert (NULL != qe);
+ rc = qe->qc.rc;
+ was_transmitted = qe->was_transmitted;
+ free_queue_entry (qe);
+ if (was_transmitted == GNUNET_YES)
{
- qe = h->queue_head;
- GNUNET_assert (NULL != qe);
- rc = qe->qc.rc;
- was_transmitted = qe->was_transmitted;
- free_queue_entry (qe);
- if (was_transmitted == GNUNET_YES)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to receive response from database.\n"));
- do_disconnect (h);
- }
- else
- {
- process_queue (h);
- }
- if (rc.proc != NULL)
- rc.proc (rc.proc_cls,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to receive response from database.\n"));
+ do_disconnect (h);
}
- if (ntohs(msg->type) == GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END)
+ else
{
- GNUNET_break (ntohs(msg->size) == sizeof(struct GNUNET_MessageHeader));
- qe = h->queue_head;
- rc = qe->qc.rc;
- GNUNET_assert (GNUNET_YES == qe->was_transmitted);
- free_queue_entry (qe);
-#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received end of result set, new queue size is %u\n",
- h->queue_size);
-#endif
- if (rc.proc != NULL)
- rc.proc (rc.proc_cls,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- h->retry_time.rel_value = 0;
- h->result_count = 0;
process_queue (h);
- return;
}
+ if (rc.proc != NULL)
+ rc.proc (rc.proc_cls,
+ NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
+ if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END)
+ {
+ GNUNET_break (ntohs (msg->size) == sizeof (struct GNUNET_MessageHeader));
+ qe = h->queue_head;
+ rc = qe->qc.rc;
+ GNUNET_assert (GNUNET_YES == qe->was_transmitted);
+ free_queue_entry (qe);
+#if DEBUG_DATASTORE
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received end of result set, new queue size is %u\n",
+ h->queue_size);
+#endif
+ if (rc.proc != NULL)
+ rc.proc (rc.proc_cls,
+ NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ h->retry_time.rel_value = 0;
+ h->result_count = 0;
+ process_queue (h);
+ return;
+ }
qe = h->queue_head;
GNUNET_assert (NULL != qe);
rc = qe->qc.rc;
if (GNUNET_YES != qe->was_transmitted)
- {
- GNUNET_break (0);
- free_queue_entry (qe);
- h->retry_time = GNUNET_TIME_UNIT_ZERO;
- do_disconnect (h);
- if (rc.proc != NULL)
- rc.proc (rc.proc_cls,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
- if ( (ntohs(msg->size) < sizeof(struct DataMessage)) ||
- (ntohs(msg->type) != GNUNET_MESSAGE_TYPE_DATASTORE_DATA) ||
- (ntohs(msg->size) != sizeof(struct DataMessage) + ntohl (((const struct DataMessage*)msg)->size)) )
- {
- GNUNET_break (0);
- free_queue_entry (qe);
- h->retry_time = GNUNET_TIME_UNIT_ZERO;
- do_disconnect (h);
- if (rc.proc != NULL)
- rc.proc (rc.proc_cls,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
+ {
+ GNUNET_break (0);
+ free_queue_entry (qe);
+ h->retry_time = GNUNET_TIME_UNIT_ZERO;
+ do_disconnect (h);
+ if (rc.proc != NULL)
+ rc.proc (rc.proc_cls,
+ NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
+ if ((ntohs (msg->size) < sizeof (struct DataMessage)) ||
+ (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_DATASTORE_DATA) ||
+ (ntohs (msg->size) !=
+ sizeof (struct DataMessage) +
+ ntohl (((const struct DataMessage *) msg)->size)))
+ {
+ GNUNET_break (0);
+ free_queue_entry (qe);
+ h->retry_time = GNUNET_TIME_UNIT_ZERO;
+ do_disconnect (h);
+ if (rc.proc != NULL)
+ rc.proc (rc.proc_cls,
+ NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# Results received"),
- 1,
- GNUNET_NO);
- dm = (const struct DataMessage*) msg;
+ gettext_noop ("# Results received"), 1, GNUNET_NO);
+ dm = (const struct DataMessage *) msg;
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received result %llu with type %u and size %u with key %s\n",
- (unsigned long long) GNUNET_ntohll(dm->uid),
- ntohl(dm->type),
- ntohl(dm->size),
- GNUNET_h2s(&dm->key));
+ "Received result %llu with type %u and size %u with key %s\n",
+ (unsigned long long) GNUNET_ntohll (dm->uid),
+ ntohl (dm->type), ntohl (dm->size), GNUNET_h2s (&dm->key));
#endif
free_queue_entry (qe);
h->retry_time.rel_value = 0;
process_queue (h);
if (rc.proc != NULL)
rc.proc (rc.proc_cls,
- &dm->key,
- ntohl(dm->size),
- &dm[1],
- ntohl(dm->type),
- ntohl(dm->priority),
- ntohl(dm->anonymity),
- GNUNET_TIME_absolute_ntoh(dm->expiration),
- GNUNET_ntohll(dm->uid));
+ &dm->key,
+ ntohl (dm->size),
+ &dm[1],
+ ntohl (dm->type),
+ ntohl (dm->priority),
+ ntohl (dm->anonymity),
+ GNUNET_TIME_absolute_ntoh (dm->expiration),
+ GNUNET_ntohll (dm->uid));
}
@@ -1391,11 +1321,11 @@ process_result_message (void *cls,
*/
struct GNUNET_DATASTORE_QueueEntry *
GNUNET_DATASTORE_get_for_replication (struct GNUNET_DATASTORE_Handle *h,
- unsigned int queue_priority,
- unsigned int max_queue_size,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_DATASTORE_DatumProcessor proc,
- void *proc_cls)
+ unsigned int queue_priority,
+ unsigned int max_queue_size,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_DATASTORE_DatumProcessor proc,
+ void *proc_cls)
{
struct GNUNET_DATASTORE_QueueEntry *qe;
struct GNUNET_MessageHeader *m;
@@ -1404,29 +1334,29 @@ GNUNET_DATASTORE_get_for_replication (struct GNUNET_DATASTORE_Handle *h,
GNUNET_assert (NULL != proc);
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asked to get replication entry in %llu ms\n",
- (unsigned long long) timeout.rel_value);
+ "Asked to get replication entry in %llu ms\n",
+ (unsigned long long) timeout.rel_value);
#endif
qc.rc.proc = proc;
qc.rc.proc_cls = proc_cls;
- qe = make_queue_entry (h, sizeof(struct GNUNET_MessageHeader),
- queue_priority, max_queue_size, timeout,
- &process_result_message, &qc);
+ qe = make_queue_entry (h, sizeof (struct GNUNET_MessageHeader),
+ queue_priority, max_queue_size, timeout,
+ &process_result_message, &qc);
if (qe == NULL)
- {
+ {
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Could not create queue entry for GET REPLICATION\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Could not create queue entry for GET REPLICATION\n");
#endif
- return NULL;
- }
+ return NULL;
+ }
GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# GET REPLICATION requests executed"),
- 1,
- GNUNET_NO);
- m = (struct GNUNET_MessageHeader*) &qe[1];
- m->type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_GET_REPLICATION);
- m->size = htons(sizeof (struct GNUNET_MessageHeader));
+ gettext_noop
+ ("# GET REPLICATION requests executed"), 1,
+ GNUNET_NO);
+ m = (struct GNUNET_MessageHeader *) &qe[1];
+ m->type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_GET_REPLICATION);
+ m->size = htons (sizeof (struct GNUNET_MessageHeader));
process_queue (h);
return qe;
}
@@ -1454,13 +1384,13 @@ GNUNET_DATASTORE_get_for_replication (struct GNUNET_DATASTORE_Handle *h,
*/
struct GNUNET_DATASTORE_QueueEntry *
GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h,
- uint64_t offset,
- unsigned int queue_priority,
- unsigned int max_queue_size,
- struct GNUNET_TIME_Relative timeout,
- enum GNUNET_BLOCK_Type type,
- GNUNET_DATASTORE_DatumProcessor proc,
- void *proc_cls)
+ uint64_t offset,
+ unsigned int queue_priority,
+ unsigned int max_queue_size,
+ struct GNUNET_TIME_Relative timeout,
+ enum GNUNET_BLOCK_Type type,
+ GNUNET_DATASTORE_DatumProcessor proc,
+ void *proc_cls)
{
struct GNUNET_DATASTORE_QueueEntry *qe;
struct GetZeroAnonymityMessage *m;
@@ -1470,31 +1400,30 @@ GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h,
GNUNET_assert (type != GNUNET_BLOCK_TYPE_ANY);
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asked to get %llu-th zero-anonymity entry of type %d in %llu ms\n",
- (unsigned long long) offset,
- type,
- (unsigned long long) timeout.rel_value);
+ "Asked to get %llu-th zero-anonymity entry of type %d in %llu ms\n",
+ (unsigned long long) offset,
+ type, (unsigned long long) timeout.rel_value);
#endif
qc.rc.proc = proc;
qc.rc.proc_cls = proc_cls;
- qe = make_queue_entry (h, sizeof(struct GetZeroAnonymityMessage),
- queue_priority, max_queue_size, timeout,
- &process_result_message, &qc);
+ qe = make_queue_entry (h, sizeof (struct GetZeroAnonymityMessage),
+ queue_priority, max_queue_size, timeout,
+ &process_result_message, &qc);
if (qe == NULL)
- {
+ {
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Could not create queue entry for zero-anonymity procation\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Could not create queue entry for zero-anonymity procation\n");
#endif
- return NULL;
- }
+ return NULL;
+ }
GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# GET ZERO ANONYMITY requests executed"),
- 1,
- GNUNET_NO);
- m = (struct GetZeroAnonymityMessage*) &qe[1];
- m->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY);
- m->header.size = htons(sizeof (struct GetZeroAnonymityMessage));
+ gettext_noop
+ ("# GET ZERO ANONYMITY requests executed"), 1,
+ GNUNET_NO);
+ m = (struct GetZeroAnonymityMessage *) &qe[1];
+ m->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY);
+ m->header.size = htons (sizeof (struct GetZeroAnonymityMessage));
m->type = htonl ((uint32_t) type);
m->offset = GNUNET_htonll (offset);
process_queue (h);
@@ -1525,14 +1454,13 @@ GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h,
*/
struct GNUNET_DATASTORE_QueueEntry *
GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h,
- uint64_t offset,
- const GNUNET_HashCode * key,
- enum GNUNET_BLOCK_Type type,
- unsigned int queue_priority,
- unsigned int max_queue_size,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_DATASTORE_DatumProcessor proc,
- void *proc_cls)
+ uint64_t offset,
+ const GNUNET_HashCode * key,
+ enum GNUNET_BLOCK_Type type,
+ unsigned int queue_priority,
+ unsigned int max_queue_size,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_DATASTORE_DatumProcessor proc, void *proc_cls)
{
struct GNUNET_DATASTORE_QueueEntry *qe;
struct GetMessage *gm;
@@ -1541,41 +1469,39 @@ GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h,
GNUNET_assert (NULL != proc);
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asked to look for data of type %u under key `%s'\n",
- (unsigned int) type,
- GNUNET_h2s (key));
+ "Asked to look for data of type %u under key `%s'\n",
+ (unsigned int) type, GNUNET_h2s (key));
#endif
qc.rc.proc = proc;
qc.rc.proc_cls = proc_cls;
- qe = make_queue_entry (h, sizeof(struct GetMessage),
- queue_priority, max_queue_size, timeout,
- &process_result_message, &qc);
+ qe = make_queue_entry (h, sizeof (struct GetMessage),
+ queue_priority, max_queue_size, timeout,
+ &process_result_message, &qc);
if (qe == NULL)
- {
+ {
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Could not queue request for `%s'\n",
- GNUNET_h2s (key));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Could not queue request for `%s'\n", GNUNET_h2s (key));
#endif
- return NULL;
- }
+ return NULL;
+ }
GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# GET requests executed"),
- 1,
- GNUNET_NO);
- gm = (struct GetMessage*) &qe[1];
- gm->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_GET);
- gm->type = htonl(type);
+ gettext_noop ("# GET requests executed"),
+ 1, GNUNET_NO);
+ gm = (struct GetMessage *) &qe[1];
+ gm->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_GET);
+ gm->type = htonl (type);
gm->offset = GNUNET_htonll (offset);
if (key != NULL)
- {
- gm->header.size = htons(sizeof (struct GetMessage));
- gm->key = *key;
- }
+ {
+ gm->header.size = htons (sizeof (struct GetMessage));
+ gm->key = *key;
+ }
else
- {
- gm->header.size = htons(sizeof (struct GetMessage) - sizeof(GNUNET_HashCode));
- }
+ {
+ gm->header.size =
+ htons (sizeof (struct GetMessage) - sizeof (GNUNET_HashCode));
+ }
process_queue (h);
return qe;
}
@@ -1595,18 +1521,16 @@ GNUNET_DATASTORE_cancel (struct GNUNET_DATASTORE_QueueEntry *qe)
GNUNET_assert (GNUNET_SYSERR != qe->was_transmitted);
h = qe->h;
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Pending DATASTORE request %p cancelled (%d, %d)\n",
- qe,
- qe->was_transmitted,
- h->queue_head == qe);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Pending DATASTORE request %p cancelled (%d, %d)\n",
+ qe, qe->was_transmitted, h->queue_head == qe);
#endif
- if (GNUNET_YES == qe->was_transmitted)
- {
- free_queue_entry (qe);
- h->skip_next_messages++;
- return;
- }
+ if (GNUNET_YES == qe->was_transmitted)
+ {
+ free_queue_entry (qe);
+ h->skip_next_messages++;
+ return;
+ }
free_queue_entry (qe);
process_queue (h);
}
diff --git a/src/datastore/gnunet-service-datastore.c b/src/datastore/gnunet-service-datastore.c
index 39354acaf4..c01de58918 100644
--- a/src/datastore/gnunet-service-datastore.c
+++ b/src/datastore/gnunet-service-datastore.c
@@ -92,7 +92,7 @@ struct DatastorePlugin
/**
* Linked list of active reservations.
*/
-struct ReservationList
+struct ReservationList
{
/**
@@ -161,7 +161,7 @@ static unsigned long long cache_size;
* How much space have we currently reserved?
*/
static unsigned long long reserved;
-
+
/**
* How much data are we currently storing
* in the database?
@@ -202,13 +202,10 @@ static struct GNUNET_STATISTICS_Handle *stats;
* Synchronize our utilization statistics with the
* statistics service.
*/
-static void
+static void
sync_stats ()
{
- GNUNET_STATISTICS_set (stats,
- QUOTA_STAT_NAME,
- payload,
- GNUNET_YES);
+ GNUNET_STATISTICS_set (stats, QUOTA_STAT_NAME, payload, GNUNET_YES);
lastSync = 0;
}
@@ -217,24 +214,24 @@ sync_stats ()
/**
* Context for transmitting replies to clients.
*/
-struct TransmitCallbackContext
+struct TransmitCallbackContext
{
-
+
/**
* We keep these in a doubly-linked list (for cleanup).
*/
struct TransmitCallbackContext *next;
-
+
/**
* We keep these in a doubly-linked list (for cleanup).
*/
struct TransmitCallbackContext *prev;
-
+
/**
* The message that we're asked to transmit.
*/
struct GNUNET_MessageHeader *msg;
-
+
/**
* Handle for the transmission request.
*/
@@ -247,7 +244,7 @@ struct TransmitCallbackContext
};
-
+
/**
* Head of the doubly-linked list (for cleanup).
*/
@@ -278,10 +275,9 @@ static struct GNUNET_STATISTICS_GetHandle *stat_get;
*
* @param cls not used
* @param tc task context
- */
+ */
static void
-delete_expired (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+delete_expired (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
/**
@@ -304,55 +300,46 @@ delete_expired (void *cls,
* (continue on call to "next", of course),
* GNUNET_NO to delete the item and continue (if supported)
*/
-static int
+static int
expired_processor (void *cls,
- const GNUNET_HashCode * key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute
- expiration,
- uint64_t uid)
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct GNUNET_TIME_Absolute now;
- if (key == NULL)
- {
- expired_kill_task
- = GNUNET_SCHEDULER_add_delayed (MAX_EXPIRE_DELAY,
- &delete_expired,
- NULL);
- return GNUNET_SYSERR;
- }
+ if (key == NULL)
+ {
+ expired_kill_task
+ = GNUNET_SCHEDULER_add_delayed (MAX_EXPIRE_DELAY,
+ &delete_expired, NULL);
+ return GNUNET_SYSERR;
+ }
now = GNUNET_TIME_absolute_get ();
if (expiration.abs_value > now.abs_value)
- {
- /* finished processing */
- expired_kill_task
- = GNUNET_SCHEDULER_add_delayed (MAX_EXPIRE_DELAY,
- &delete_expired,
- NULL);
- return GNUNET_SYSERR;
- }
+ {
+ /* finished processing */
+ expired_kill_task
+ = GNUNET_SCHEDULER_add_delayed (MAX_EXPIRE_DELAY,
+ &delete_expired, NULL);
+ return GNUNET_SYSERR;
+ }
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Deleting content `%s' of type %u that expired %llu ms ago\n",
- GNUNET_h2s (key),
- type,
- (unsigned long long) (now.abs_value - expiration.abs_value));
+ "Deleting content `%s' of type %u that expired %llu ms ago\n",
+ GNUNET_h2s (key),
+ type,
+ (unsigned long long) (now.abs_value - expiration.abs_value));
#endif
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# bytes expired"),
- size,
- GNUNET_YES);
- GNUNET_CONTAINER_bloomfilter_remove (filter,
- key);
- expired_kill_task
- = GNUNET_SCHEDULER_add_delayed (MIN_EXPIRE_DELAY,
- &delete_expired,
- NULL);
+ gettext_noop ("# bytes expired"), size, GNUNET_YES);
+ GNUNET_CONTAINER_bloomfilter_remove (filter, key);
+ expired_kill_task
+ = GNUNET_SCHEDULER_add_delayed (MIN_EXPIRE_DELAY, &delete_expired, NULL);
return GNUNET_NO;
}
@@ -365,15 +352,12 @@ expired_processor (void *cls,
*
* @param cls not used
* @param tc task context
- */
+ */
static void
-delete_expired (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+delete_expired (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
expired_kill_task = GNUNET_SCHEDULER_NO_TASK;
- plugin->api->get_expiration (plugin->api->cls,
- &expired_processor,
- NULL);
+ plugin->api->get_expiration (plugin->api->cls, &expired_processor, NULL);
}
@@ -396,39 +380,34 @@ delete_expired (void *cls,
* (continue on call to "next", of course),
* GNUNET_NO to delete the item and continue (if supported)
*/
-static int
+static int
quota_processor (void *cls,
- const GNUNET_HashCode * key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute expiration,
- uint64_t uid)
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
unsigned long long *need = cls;
if (NULL == key)
- return GNUNET_SYSERR;
+ return GNUNET_SYSERR;
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Deleting %llu bytes of low-priority content `%s' of type %u (still trying to free another %llu bytes)\n",
- (unsigned long long) (size + GNUNET_DATASTORE_ENTRY_OVERHEAD),
- GNUNET_h2s (key),
- type,
- *need);
+ "Deleting %llu bytes of low-priority content `%s' of type %u (still trying to free another %llu bytes)\n",
+ (unsigned long long) (size + GNUNET_DATASTORE_ENTRY_OVERHEAD),
+ GNUNET_h2s (key), type, *need);
#endif
if (size + GNUNET_DATASTORE_ENTRY_OVERHEAD > *need)
*need = 0;
else
*need -= size + GNUNET_DATASTORE_ENTRY_OVERHEAD;
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# bytes purged (low-priority)"),
- size,
- GNUNET_YES);
- GNUNET_CONTAINER_bloomfilter_remove (filter,
- key);
+ gettext_noop ("# bytes purged (low-priority)"),
+ size, GNUNET_YES);
+ GNUNET_CONTAINER_bloomfilter_remove (filter, key);
return GNUNET_NO;
}
@@ -452,18 +431,14 @@ manage_space (unsigned long long need)
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asked to free up %llu bytes of cache space\n",
- need);
+ "Asked to free up %llu bytes of cache space\n", need);
#endif
last = 0;
- while ( (need > 0) &&
- (last != need) )
- {
- last = need;
- plugin->api->get_expiration (plugin->api->cls,
- &quota_processor,
- &need);
- }
+ while ((need > 0) && (last != need))
+ {
+ last = need;
+ plugin->api->get_expiration (plugin->api->cls, &quota_processor, &need);
+ }
}
@@ -479,27 +454,24 @@ manage_space (unsigned long long need)
* @return number of bytes written to buf
*/
static size_t
-transmit_callback (void *cls,
- size_t size, void *buf)
+transmit_callback (void *cls, size_t size, void *buf)
{
struct TransmitCallbackContext *tcc = cls;
size_t msize;
-
+
tcc->th = NULL;
- GNUNET_CONTAINER_DLL_remove (tcc_head,
- tcc_tail,
- tcc);
- msize = ntohs(tcc->msg->size);
+ GNUNET_CONTAINER_DLL_remove (tcc_head, tcc_tail, tcc);
+ msize = ntohs (tcc->msg->size);
if (size == 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Transmission to client failed!\n"));
- GNUNET_SERVER_receive_done (tcc->client, GNUNET_SYSERR);
- GNUNET_SERVER_client_drop (tcc->client);
- GNUNET_free (tcc->msg);
- GNUNET_free (tcc);
- return 0;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Transmission to client failed!\n"));
+ GNUNET_SERVER_receive_done (tcc->client, GNUNET_SYSERR);
+ GNUNET_SERVER_client_drop (tcc->client);
+ GNUNET_free (tcc->msg);
+ GNUNET_free (tcc);
+ return 0;
+ }
GNUNET_assert (size >= msize);
memcpy (buf, tcc->msg, msize);
GNUNET_SERVER_receive_done (tcc->client, GNUNET_OK);
@@ -517,41 +489,37 @@ transmit_callback (void *cls,
* @param msg message to transmit, will be freed!
*/
static void
-transmit (struct GNUNET_SERVER_Client *client,
- struct GNUNET_MessageHeader *msg)
+transmit (struct GNUNET_SERVER_Client *client, struct GNUNET_MessageHeader *msg)
{
struct TransmitCallbackContext *tcc;
if (GNUNET_YES == cleaning_done)
- {
+ {
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Shutdown in progress, aborting transmission.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Shutdown in progress, aborting transmission.\n");
#endif
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- GNUNET_free (msg);
- return;
- }
- tcc = GNUNET_malloc (sizeof(struct TransmitCallbackContext));
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ GNUNET_free (msg);
+ return;
+ }
+ tcc = GNUNET_malloc (sizeof (struct TransmitCallbackContext));
tcc->msg = msg;
tcc->client = client;
if (NULL ==
(tcc->th = GNUNET_SERVER_notify_transmit_ready (client,
- ntohs(msg->size),
- GNUNET_TIME_UNIT_FOREVER_REL,
- &transmit_callback,
- tcc)))
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- GNUNET_free (msg);
- GNUNET_free (tcc);
- return;
- }
+ ntohs (msg->size),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &transmit_callback, tcc)))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ GNUNET_free (msg);
+ GNUNET_free (tcc);
+ return;
+ }
GNUNET_SERVER_client_keep (client);
- GNUNET_CONTAINER_DLL_insert (tcc_head,
- tcc_tail,
- tcc);
+ GNUNET_CONTAINER_DLL_insert (tcc_head, tcc_tail, tcc);
}
@@ -563,27 +531,23 @@ transmit (struct GNUNET_SERVER_Client *client,
* @param msg optional error message (can be NULL)
*/
static void
-transmit_status (struct GNUNET_SERVER_Client *client,
- int code,
- const char *msg)
+transmit_status (struct GNUNET_SERVER_Client *client, int code, const char *msg)
{
struct StatusMessage *sm;
size_t slen;
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting `%s' message with value %d and message `%s'\n",
- "STATUS",
- code,
- msg != NULL ? msg : "(none)");
+ "Transmitting `%s' message with value %d and message `%s'\n",
+ "STATUS", code, msg != NULL ? msg : "(none)");
#endif
- slen = (msg == NULL) ? 0 : strlen(msg) + 1;
- sm = GNUNET_malloc (sizeof(struct StatusMessage) + slen);
- sm->header.size = htons(sizeof(struct StatusMessage) + slen);
- sm->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_STATUS);
- sm->status = htonl(code);
+ slen = (msg == NULL) ? 0 : strlen (msg) + 1;
+ sm = GNUNET_malloc (sizeof (struct StatusMessage) + slen);
+ sm->header.size = htons (sizeof (struct StatusMessage) + slen);
+ sm->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_STATUS);
+ sm->status = htonl (code);
if (slen > 0)
- memcpy (&sm[1], msg, slen);
+ memcpy (&sm[1], msg, slen);
transmit (client, &sm->header);
}
@@ -609,62 +573,59 @@ transmit_status (struct GNUNET_SERVER_Client *client,
*/
static int
transmit_item (void *cls,
- const GNUNET_HashCode * key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute
- expiration, uint64_t uid)
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct GNUNET_SERVER_Client *client = cls;
struct GNUNET_MessageHeader *end;
struct DataMessage *dm;
if (key == NULL)
- {
- /* transmit 'DATA_END' */
+ {
+ /* transmit 'DATA_END' */
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting `%s' message\n",
- "DATA_END");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmitting `%s' message\n", "DATA_END");
#endif
- end = GNUNET_malloc (sizeof(struct GNUNET_MessageHeader));
- end->size = htons(sizeof(struct GNUNET_MessageHeader));
- end->type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END);
- transmit (client, end);
- GNUNET_SERVER_client_drop (client);
- return GNUNET_OK;
- }
- GNUNET_assert (sizeof (struct DataMessage) + size < GNUNET_SERVER_MAX_MESSAGE_SIZE);
- dm = GNUNET_malloc (sizeof(struct DataMessage) + size);
- dm->header.size = htons(sizeof(struct DataMessage) + size);
- dm->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_DATA);
- dm->rid = htonl(0);
- dm->size = htonl(size);
- dm->type = htonl(type);
- dm->priority = htonl(priority);
- dm->anonymity = htonl(anonymity);
+ end = GNUNET_malloc (sizeof (struct GNUNET_MessageHeader));
+ end->size = htons (sizeof (struct GNUNET_MessageHeader));
+ end->type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END);
+ transmit (client, end);
+ GNUNET_SERVER_client_drop (client);
+ return GNUNET_OK;
+ }
+ GNUNET_assert (sizeof (struct DataMessage) + size <
+ GNUNET_SERVER_MAX_MESSAGE_SIZE);
+ dm = GNUNET_malloc (sizeof (struct DataMessage) + size);
+ dm->header.size = htons (sizeof (struct DataMessage) + size);
+ dm->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_DATA);
+ dm->rid = htonl (0);
+ dm->size = htonl (size);
+ dm->type = htonl (type);
+ dm->priority = htonl (priority);
+ dm->anonymity = htonl (anonymity);
dm->replication = htonl (0);
dm->reserved = htonl (0);
- dm->expiration = GNUNET_TIME_absolute_hton(expiration);
- dm->uid = GNUNET_htonll(uid);
+ dm->expiration = GNUNET_TIME_absolute_hton (expiration);
+ dm->uid = GNUNET_htonll (uid);
dm->key = *key;
memcpy (&dm[1], data, size);
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting `%s' message for `%s' of type %u with expiration %llu (now: %llu)\n",
- "DATA",
- GNUNET_h2s (key),
- type,
- (unsigned long long) expiration.abs_value,
- (unsigned long long) GNUNET_TIME_absolute_get ().abs_value);
+ "Transmitting `%s' message for `%s' of type %u with expiration %llu (now: %llu)\n",
+ "DATA",
+ GNUNET_h2s (key),
+ type,
+ (unsigned long long) expiration.abs_value,
+ (unsigned long long) GNUNET_TIME_absolute_get ().abs_value);
#endif
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# results found"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# results found"), 1, GNUNET_NO);
transmit (client, &dm->header);
GNUNET_SERVER_client_drop (client);
return GNUNET_OK;
@@ -680,15 +641,15 @@ transmit_item (void *cls,
*/
static void
handle_reserve (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
/**
* Static counter to produce reservation identifiers.
*/
static int reservation_gen;
- const struct ReserveMessage *msg = (const struct ReserveMessage*) message;
+ const struct ReserveMessage *msg = (const struct ReserveMessage *) message;
struct ReservationList *e;
unsigned long long used;
unsigned long long req;
@@ -696,51 +657,48 @@ handle_reserve (void *cls,
uint32_t entries;
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Processing `%s' request\n",
- "RESERVE");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing `%s' request\n", "RESERVE");
#endif
- amount = GNUNET_ntohll(msg->amount);
- entries = ntohl(msg->entries);
+ amount = GNUNET_ntohll (msg->amount);
+ entries = ntohl (msg->entries);
used = payload + reserved;
- req = amount + ((unsigned long long) GNUNET_DATASTORE_ENTRY_OVERHEAD) * entries;
+ req =
+ amount + ((unsigned long long) GNUNET_DATASTORE_ENTRY_OVERHEAD) * entries;
if (used + req > quota)
+ {
+ if (quota < used)
+ used = quota; /* cheat a bit for error message (to avoid negative numbers) */
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Insufficient space (%llu bytes are available) to satisfy `%s' request for %llu bytes\n"),
+ quota - used, "RESERVE", req);
+ if (cache_size < req)
{
- if (quota < used)
- used = quota; /* cheat a bit for error message (to avoid negative numbers) */
+ /* TODO: document this in the FAQ; essentially, if this
+ * message happens, the insertion request could be blocked
+ * by less-important content from migration because it is
+ * larger than 1/8th of the overall available space, and
+ * we only reserve 1/8th for "fresh" insertions */
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Insufficient space (%llu bytes are available) to satisfy `%s' request for %llu bytes\n"),
- quota - used,
- "RESERVE",
- req);
- if (cache_size < req)
- {
- /* TODO: document this in the FAQ; essentially, if this
- message happens, the insertion request could be blocked
- by less-important content from migration because it is
- larger than 1/8th of the overall available space, and
- we only reserve 1/8th for "fresh" insertions */
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("The requested amount (%llu bytes) is larger than the cache size (%llu bytes)\n"),
- req,
- cache_size);
- transmit_status (client, 0,
- gettext_noop ("Insufficient space to satisfy request and "
- "requested amount is larger than cache size"));
- }
- else
- {
- transmit_status (client, 0,
- gettext_noop ("Insufficient space to satisfy request"));
- }
- return;
+ _
+ ("The requested amount (%llu bytes) is larger than the cache size (%llu bytes)\n"),
+ req, cache_size);
+ transmit_status (client, 0,
+ gettext_noop
+ ("Insufficient space to satisfy request and "
+ "requested amount is larger than cache size"));
}
+ else
+ {
+ transmit_status (client, 0,
+ gettext_noop ("Insufficient space to satisfy request"));
+ }
+ return;
+ }
reserved += req;
GNUNET_STATISTICS_set (stats,
- gettext_noop ("# reserved"),
- reserved,
- GNUNET_NO);
- e = GNUNET_malloc (sizeof(struct ReservationList));
+ gettext_noop ("# reserved"), reserved, GNUNET_NO);
+ e = GNUNET_malloc (sizeof (struct ReservationList));
e->next = reservations;
reservations = e;
e->client = client;
@@ -748,7 +706,7 @@ handle_reserve (void *cls,
e->entries = entries;
e->rid = ++reservation_gen;
if (reservation_gen < 0)
- reservation_gen = 0; /* wrap around */
+ reservation_gen = 0; /* wrap around */
transmit_status (client, e->rid, NULL);
}
@@ -762,52 +720,53 @@ handle_reserve (void *cls,
*/
static void
handle_release_reserve (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
- const struct ReleaseReserveMessage *msg = (const struct ReleaseReserveMessage*) message;
+ const struct ReleaseReserveMessage *msg =
+ (const struct ReleaseReserveMessage *) message;
struct ReservationList *pos;
struct ReservationList *prev;
struct ReservationList *next;
- int rid = ntohl(msg->rid);
+ int rid = ntohl (msg->rid);
unsigned long long rem;
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Processing `%s' request\n",
- "RELEASE_RESERVE");
+ "Processing `%s' request\n", "RELEASE_RESERVE");
#endif
next = reservations;
prev = NULL;
while (NULL != (pos = next))
+ {
+ next = pos->next;
+ if (rid == pos->rid)
{
- next = pos->next;
- if (rid == pos->rid)
- {
- if (prev == NULL)
- reservations = next;
- else
- prev->next = next;
- rem = pos->amount + ((unsigned long long) GNUNET_DATASTORE_ENTRY_OVERHEAD) * pos->entries;
- GNUNET_assert (reserved >= rem);
- reserved -= rem;
- GNUNET_STATISTICS_set (stats,
- gettext_noop ("# reserved"),
- reserved,
- GNUNET_NO);
+ if (prev == NULL)
+ reservations = next;
+ else
+ prev->next = next;
+ rem =
+ pos->amount +
+ ((unsigned long long) GNUNET_DATASTORE_ENTRY_OVERHEAD) * pos->entries;
+ GNUNET_assert (reserved >= rem);
+ reserved -= rem;
+ GNUNET_STATISTICS_set (stats,
+ gettext_noop ("# reserved"), reserved, GNUNET_NO);
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Returning %llu remaining reserved bytes to storage pool\n",
- rem);
-#endif
- GNUNET_free (pos);
- transmit_status (client, GNUNET_OK, NULL);
- return;
- }
- prev = pos;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Returning %llu remaining reserved bytes to storage pool\n",
+ rem);
+#endif
+ GNUNET_free (pos);
+ transmit_status (client, GNUNET_OK, NULL);
+ return;
}
+ prev = pos;
+ }
GNUNET_break (0);
- transmit_status (client, GNUNET_SYSERR, gettext_noop ("Could not find matching reservation"));
+ transmit_status (client, GNUNET_SYSERR,
+ gettext_noop ("Could not find matching reservation"));
}
@@ -823,19 +782,19 @@ check_data (const struct GNUNET_MessageHeader *message)
uint32_t dsize;
const struct DataMessage *dm;
- size = ntohs(message->size);
- if (size < sizeof(struct DataMessage))
- {
- GNUNET_break (0);
- return NULL;
- }
+ size = ntohs (message->size);
+ if (size < sizeof (struct DataMessage))
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
dm = (const struct DataMessage *) message;
- dsize = ntohl(dm->size);
- if (size != dsize + sizeof(struct DataMessage))
- {
- GNUNET_break (0);
- return NULL;
- }
+ dsize = ntohl (dm->size);
+ if (size != dsize + sizeof (struct DataMessage))
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
return dm;
}
@@ -853,8 +812,8 @@ struct PutContext
#if ! HAVE_UNALIGNED_64_ACCESS
void *reserved;
-#endif
-
+#endif
+
/* followed by the 'struct DataMessage' */
};
@@ -863,54 +822,46 @@ struct PutContext
* Actually put the data message.
*/
static void
-execute_put (struct GNUNET_SERVER_Client *client,
- const struct DataMessage *dm)
+execute_put (struct GNUNET_SERVER_Client *client, const struct DataMessage *dm)
{
uint32_t size;
char *msg;
int ret;
- size = ntohl(dm->size);
+ size = ntohl (dm->size);
msg = NULL;
ret = plugin->api->put (plugin->api->cls,
- &dm->key,
- size,
- &dm[1],
- ntohl(dm->type),
- ntohl(dm->priority),
- ntohl(dm->anonymity),
- ntohl(dm->replication),
- GNUNET_TIME_absolute_ntoh(dm->expiration),
- &msg);
+ &dm->key,
+ size,
+ &dm[1],
+ ntohl (dm->type),
+ ntohl (dm->priority),
+ ntohl (dm->anonymity),
+ ntohl (dm->replication),
+ GNUNET_TIME_absolute_ntoh (dm->expiration), &msg);
if (GNUNET_OK == ret)
- {
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# bytes stored"),
- size,
- GNUNET_YES);
- GNUNET_CONTAINER_bloomfilter_add (filter,
- &dm->key);
+ {
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# bytes stored"),
+ size, GNUNET_YES);
+ GNUNET_CONTAINER_bloomfilter_add (filter, &dm->key);
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Successfully stored %u bytes of type %u under key `%s'\n",
- size,
- ntohl(dm->type),
- GNUNET_h2s (&dm->key));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Successfully stored %u bytes of type %u under key `%s'\n",
+ size, ntohl (dm->type), GNUNET_h2s (&dm->key));
#endif
- }
- transmit_status (client,
- ret,
- msg);
+ }
+ transmit_status (client, ret, msg);
GNUNET_free_non_null (msg);
if (quota - reserved - cache_size < payload)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Need %llu bytes more space (%llu allowed, using %llu)\n"),
- (unsigned long long) size + GNUNET_DATASTORE_ENTRY_OVERHEAD,
- (unsigned long long) (quota - reserved - cache_size),
- (unsigned long long) payload);
- manage_space (size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Need %llu bytes more space (%llu allowed, using %llu)\n"),
+ (unsigned long long) size + GNUNET_DATASTORE_ENTRY_OVERHEAD,
+ (unsigned long long) (quota - reserved - cache_size),
+ (unsigned long long) payload);
+ manage_space (size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
+ }
}
@@ -934,56 +885,51 @@ execute_put (struct GNUNET_SERVER_Client *client,
*/
static int
check_present (void *cls,
- const GNUNET_HashCode * key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute
- expiration, uint64_t uid)
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct PutContext *pc = cls;
const struct DataMessage *dm;
- dm = (const struct DataMessage*) &pc[1];
+ dm = (const struct DataMessage *) &pc[1];
if (key == NULL)
- {
- execute_put (pc->client, dm);
- GNUNET_SERVER_client_drop (pc->client);
- GNUNET_free (pc);
- return GNUNET_OK;
- }
- if ( (GNUNET_BLOCK_TYPE_FS_DBLOCK == type) ||
- (GNUNET_BLOCK_TYPE_FS_IBLOCK == type) ||
- ( (size == ntohl(dm->size)) &&
- (0 == memcmp (&dm[1],
- data,
- size)) ) )
- {
+ {
+ execute_put (pc->client, dm);
+ GNUNET_SERVER_client_drop (pc->client);
+ GNUNET_free (pc);
+ return GNUNET_OK;
+ }
+ if ((GNUNET_BLOCK_TYPE_FS_DBLOCK == type) ||
+ (GNUNET_BLOCK_TYPE_FS_IBLOCK == type) ||
+ ((size == ntohl (dm->size)) && (0 == memcmp (&dm[1], data, size))))
+ {
#if DEBUG_MYSQL
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Result already present in datastore\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Result already present in datastore\n");
#endif
- /* FIXME: change API to allow increasing 'replication' counter */
- if ( (ntohl (dm->priority) > 0) ||
- (GNUNET_TIME_absolute_ntoh(dm->expiration).abs_value >
- expiration.abs_value) )
- plugin->api->update (plugin->api->cls,
- uid,
- (int32_t) ntohl(dm->priority),
- GNUNET_TIME_absolute_ntoh(dm->expiration),
- NULL);
- transmit_status (pc->client, GNUNET_NO, NULL);
- GNUNET_SERVER_client_drop (pc->client);
- GNUNET_free (pc);
- }
+ /* FIXME: change API to allow increasing 'replication' counter */
+ if ((ntohl (dm->priority) > 0) ||
+ (GNUNET_TIME_absolute_ntoh (dm->expiration).abs_value >
+ expiration.abs_value))
+ plugin->api->update (plugin->api->cls,
+ uid,
+ (int32_t) ntohl (dm->priority),
+ GNUNET_TIME_absolute_ntoh (dm->expiration), NULL);
+ transmit_status (pc->client, GNUNET_NO, NULL);
+ GNUNET_SERVER_client_drop (pc->client);
+ GNUNET_free (pc);
+ }
else
- {
- execute_put (pc->client, dm);
- GNUNET_SERVER_client_drop (pc->client);
- GNUNET_free (pc);
- }
+ {
+ execute_put (pc->client, dm);
+ GNUNET_SERVER_client_drop (pc->client);
+ GNUNET_free (pc);
+ }
return GNUNET_OK;
}
@@ -997,8 +943,8 @@ check_present (void *cls,
*/
static void
handle_put (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
const struct DataMessage *dm = check_data (message);
int rid;
@@ -1007,59 +953,50 @@ handle_put (void *cls,
GNUNET_HashCode vhash;
uint32_t size;
- if ( (dm == NULL) ||
- (ntohl(dm->type) == 0) )
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ if ((dm == NULL) || (ntohl (dm->type) == 0))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Processing `%s' request for `%s' of type %u\n",
- "PUT",
- GNUNET_h2s (&dm->key),
- ntohl (dm->type));
+ "Processing `%s' request for `%s' of type %u\n",
+ "PUT", GNUNET_h2s (&dm->key), ntohl (dm->type));
#endif
- rid = ntohl(dm->rid);
- size = ntohl(dm->size);
+ rid = ntohl (dm->rid);
+ size = ntohl (dm->size);
if (rid > 0)
+ {
+ pos = reservations;
+ while ((NULL != pos) && (rid != pos->rid))
+ pos = pos->next;
+ GNUNET_break (pos != NULL);
+ if (NULL != pos)
{
- pos = reservations;
- while ( (NULL != pos) &&
- (rid != pos->rid) )
- pos = pos->next;
- GNUNET_break (pos != NULL);
- if (NULL != pos)
- {
- GNUNET_break (pos->entries > 0);
- GNUNET_break (pos->amount >= size);
- pos->entries--;
- pos->amount -= size;
- reserved -= (size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
- GNUNET_STATISTICS_set (stats,
- gettext_noop ("# reserved"),
- reserved,
- GNUNET_NO);
- }
- }
- if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (filter,
- &dm->key))
- {
- GNUNET_CRYPTO_hash (&dm[1], size, &vhash);
- pc = GNUNET_malloc (sizeof (struct PutContext) + size + sizeof (struct DataMessage));
- pc->client = client;
- GNUNET_SERVER_client_keep (client);
- memcpy (&pc[1], dm, size + sizeof (struct DataMessage));
- plugin->api->get_key (plugin->api->cls,
- 0,
- &dm->key,
- &vhash,
- ntohl (dm->type),
- &check_present,
- pc);
- return;
+ GNUNET_break (pos->entries > 0);
+ GNUNET_break (pos->amount >= size);
+ pos->entries--;
+ pos->amount -= size;
+ reserved -= (size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
+ GNUNET_STATISTICS_set (stats,
+ gettext_noop ("# reserved"), reserved, GNUNET_NO);
}
+ }
+ if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (filter, &dm->key))
+ {
+ GNUNET_CRYPTO_hash (&dm[1], size, &vhash);
+ pc = GNUNET_malloc (sizeof (struct PutContext) + size +
+ sizeof (struct DataMessage));
+ pc->client = client;
+ GNUNET_SERVER_client_keep (client);
+ memcpy (&pc[1], dm, size + sizeof (struct DataMessage));
+ plugin->api->get_key (plugin->api->cls,
+ 0,
+ &dm->key,
+ &vhash, ntohl (dm->type), &check_present, pc);
+ return;
+ }
execute_put (client, dm);
}
@@ -1073,60 +1010,52 @@ handle_put (void *cls,
*/
static void
handle_get (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
const struct GetMessage *msg;
uint16_t size;
- size = ntohs(message->size);
- if ( (size != sizeof(struct GetMessage)) &&
- (size != sizeof(struct GetMessage) - sizeof(GNUNET_HashCode)) )
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
- msg = (const struct GetMessage*) message;
+ size = ntohs (message->size);
+ if ((size != sizeof (struct GetMessage)) &&
+ (size != sizeof (struct GetMessage) - sizeof (GNUNET_HashCode)))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
+ msg = (const struct GetMessage *) message;
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Processing `%s' request for `%s' of type %u\n",
- "GET",
- GNUNET_h2s (&msg->key),
- ntohl (msg->type));
+ "Processing `%s' request for `%s' of type %u\n",
+ "GET", GNUNET_h2s (&msg->key), ntohl (msg->type));
#endif
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# GET requests received"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# GET requests received"),
+ 1, GNUNET_NO);
GNUNET_SERVER_client_keep (client);
- if ( (size == sizeof(struct GetMessage)) &&
- (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test (filter,
- &msg->key)) )
- {
- /* don't bother database... */
+ if ((size == sizeof (struct GetMessage)) &&
+ (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test (filter, &msg->key)))
+ {
+ /* don't bother database... */
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Empty result set for `%s' request for `%s' (bloomfilter).\n",
- "GET",
- GNUNET_h2s (&msg->key));
-#endif
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# requests filtered by bloomfilter"),
- 1,
- GNUNET_NO);
- transmit_item (client,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Empty result set for `%s' request for `%s' (bloomfilter).\n",
+ "GET", GNUNET_h2s (&msg->key));
+#endif
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# requests filtered by bloomfilter"), 1,
+ GNUNET_NO);
+ transmit_item (client, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS,
+ 0);
+ return;
+ }
plugin->api->get_key (plugin->api->cls,
- GNUNET_ntohll (msg->offset),
- ((size == sizeof(struct GetMessage)) ? &msg->key : NULL),
- NULL,
- ntohl(msg->type),
- &transmit_item,
- client);
+ GNUNET_ntohll (msg->offset),
+ ((size ==
+ sizeof (struct GetMessage)) ? &msg->key : NULL), NULL,
+ ntohl (msg->type), &transmit_item, client);
}
@@ -1139,30 +1068,28 @@ handle_get (void *cls,
*/
static void
handle_update (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
const struct UpdateMessage *msg;
int ret;
char *emsg;
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# UPDATE requests received"),
- 1,
- GNUNET_NO);
- msg = (const struct UpdateMessage*) message;
+ gettext_noop ("# UPDATE requests received"),
+ 1, GNUNET_NO);
+ msg = (const struct UpdateMessage *) message;
emsg = NULL;
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Processing `%s' request for %llu\n",
- "UPDATE",
- (unsigned long long) GNUNET_ntohll (msg->uid));
+ "Processing `%s' request for %llu\n",
+ "UPDATE", (unsigned long long) GNUNET_ntohll (msg->uid));
#endif
ret = plugin->api->update (plugin->api->cls,
- GNUNET_ntohll(msg->uid),
- (int32_t) ntohl(msg->priority),
- GNUNET_TIME_absolute_ntoh(msg->expiration),
- &emsg);
+ GNUNET_ntohll (msg->uid),
+ (int32_t) ntohl (msg->priority),
+ GNUNET_TIME_absolute_ntoh (msg->expiration),
+ &emsg);
transmit_status (client, ret, emsg);
GNUNET_free_non_null (emsg);
}
@@ -1177,22 +1104,19 @@ handle_update (void *cls,
*/
static void
handle_get_replication (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Processing `%s' request\n",
- "GET_REPLICATION");
+ "Processing `%s' request\n", "GET_REPLICATION");
#endif
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# GET REPLICATION requests received"),
- 1,
- GNUNET_NO);
+ gettext_noop
+ ("# GET REPLICATION requests received"), 1,
+ GNUNET_NO);
GNUNET_SERVER_client_keep (client);
- plugin->api->get_replication (plugin->api->cls,
- &transmit_item,
- client);
+ plugin->api->get_replication (plugin->api->cls, &transmit_item, client);
}
@@ -1205,34 +1129,32 @@ handle_get_replication (void *cls,
*/
static void
handle_get_zero_anonymity (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
- const struct GetZeroAnonymityMessage * msg = (const struct GetZeroAnonymityMessage*) message;
+ const struct GetZeroAnonymityMessage *msg =
+ (const struct GetZeroAnonymityMessage *) message;
enum GNUNET_BLOCK_Type type;
type = (enum GNUNET_BLOCK_Type) ntohl (msg->type);
if (type == GNUNET_BLOCK_TYPE_ANY)
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Processing `%s' request\n",
- "GET_ZERO_ANONYMITY");
+ "Processing `%s' request\n", "GET_ZERO_ANONYMITY");
#endif
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# GET ZERO ANONYMITY requests received"),
- 1,
- GNUNET_NO);
+ gettext_noop
+ ("# GET ZERO ANONYMITY requests received"), 1,
+ GNUNET_NO);
GNUNET_SERVER_client_keep (client);
plugin->api->get_zero_anonymity (plugin->api->cls,
- GNUNET_ntohll (msg->offset),
- type,
- &transmit_item,
- client);
+ GNUNET_ntohll (msg->offset),
+ type, &transmit_item, client);
}
@@ -1242,43 +1164,36 @@ handle_get_zero_anonymity (void *cls,
*/
static int
remove_callback (void *cls,
- const GNUNET_HashCode * key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute
- expiration, uint64_t uid)
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct GNUNET_SERVER_Client *client = cls;
if (key == NULL)
- {
+ {
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No further matches for `%s' request.\n",
- "REMOVE");
-#endif
- transmit_status (client, GNUNET_NO, _("Content not found"));
- GNUNET_SERVER_client_drop (client);
- return GNUNET_OK; /* last item */
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "No further matches for `%s' request.\n", "REMOVE");
+#endif
+ transmit_status (client, GNUNET_NO, _("Content not found"));
+ GNUNET_SERVER_client_drop (client);
+ return GNUNET_OK; /* last item */
+ }
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Item %llu matches `%s' request for key `%s' and type %u.\n",
- (unsigned long long) uid,
- "REMOVE",
- GNUNET_h2s (key),
- type);
-#endif
+ "Item %llu matches `%s' request for key `%s' and type %u.\n",
+ (unsigned long long) uid, "REMOVE", GNUNET_h2s (key), type);
+#endif
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# bytes removed (explicit request)"),
- size,
- GNUNET_YES);
- GNUNET_CONTAINER_bloomfilter_remove (filter,
- key);
- transmit_status (client, GNUNET_OK, NULL);
+ gettext_noop ("# bytes removed (explicit request)"),
+ size, GNUNET_YES);
+ GNUNET_CONTAINER_bloomfilter_remove (filter, key);
+ transmit_status (client, GNUNET_OK, NULL);
GNUNET_SERVER_client_drop (client);
return GNUNET_NO;
}
@@ -1293,40 +1208,34 @@ remove_callback (void *cls,
*/
static void
handle_remove (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
const struct DataMessage *dm = check_data (message);
GNUNET_HashCode vhash;
if (dm == NULL)
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Processing `%s' request for `%s' of type %u\n",
- "REMOVE",
- GNUNET_h2s (&dm->key),
- ntohl (dm->type));
+ "Processing `%s' request for `%s' of type %u\n",
+ "REMOVE", GNUNET_h2s (&dm->key), ntohl (dm->type));
#endif
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# REMOVE requests received"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# REMOVE requests received"),
+ 1, GNUNET_NO);
GNUNET_SERVER_client_keep (client);
- GNUNET_CRYPTO_hash (&dm[1],
- ntohl(dm->size),
- &vhash);
+ GNUNET_CRYPTO_hash (&dm[1], ntohl (dm->size), &vhash);
plugin->api->get_key (plugin->api->cls,
- 0,
- &dm->key,
- &vhash,
- (enum GNUNET_BLOCK_Type) ntohl(dm->type),
- &remove_callback,
- client);
+ 0,
+ &dm->key,
+ &vhash,
+ (enum GNUNET_BLOCK_Type) ntohl (dm->type),
+ &remove_callback, client);
}
@@ -1339,13 +1248,11 @@ handle_remove (void *cls,
*/
static void
handle_drop (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Processing `%s' request\n",
- "DROP");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing `%s' request\n", "DROP");
#endif
do_drop = GNUNET_YES;
GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -1361,20 +1268,18 @@ handle_drop (void *cls,
* 0 for "reset to empty"
*/
static void
-disk_utilization_change_cb (void *cls,
- int delta)
+disk_utilization_change_cb (void *cls, int delta)
{
- if ( (delta < 0) &&
- (payload < -delta) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Datastore payload inaccurate (%lld < %lld). Trying to fix.\n"),
- (long long) payload,
- (long long) -delta);
- payload = plugin->api->estimate_size (plugin->api->cls);
- sync_stats ();
- return;
- }
+ if ((delta < 0) && (payload < -delta))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Datastore payload inaccurate (%lld < %lld). Trying to fix.\n"),
+ (long long) payload, (long long) -delta);
+ payload = plugin->api->estimate_size (plugin->api->cls);
+ sync_stats ();
+ return;
+ }
payload += delta;
lastSync++;
if (lastSync >= MAX_STAT_SYNC_LAG)
@@ -1394,32 +1299,28 @@ disk_utilization_change_cb (void *cls,
*/
static int
process_stat_in (void *cls,
- const char *subsystem,
- const char *name,
- uint64_t value,
- int is_persistent)
+ const char *subsystem,
+ const char *name, uint64_t value, int is_persistent)
{
GNUNET_assert (stats_worked == GNUNET_NO);
stats_worked = GNUNET_YES;
payload += value;
#if DEBUG_SQLITE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Notification from statistics about existing payload (%llu), new payload is %llu\n",
- abs_value,
- payload);
+ "Notification from statistics about existing payload (%llu), new payload is %llu\n",
+ abs_value, payload);
#endif
return GNUNET_OK;
}
static void
-process_stat_done (void *cls,
- int success)
+process_stat_done (void *cls, int success)
{
struct DatastorePlugin *plugin = cls;
stat_get = NULL;
- if (stats_worked == GNUNET_NO)
+ if (stats_worked == GNUNET_NO)
payload = plugin->api->estimate_size (plugin->api->cls);
}
@@ -1428,7 +1329,7 @@ process_stat_done (void *cls,
* Load the datastore plugin.
*/
static struct DatastorePlugin *
-load_plugin ()
+load_plugin ()
{
struct DatastorePlugin *ret;
char *libname;
@@ -1437,14 +1338,13 @@ load_plugin ()
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
"DATASTORE", "DATABASE", &name))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("No `%s' specified for `%s' in configuration!\n"),
- "DATABASE",
- "DATASTORE");
- return NULL;
- }
- ret = GNUNET_malloc (sizeof(struct DatastorePlugin));
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("No `%s' specified for `%s' in configuration!\n"),
+ "DATABASE", "DATASTORE");
+ return NULL;
+ }
+ ret = GNUNET_malloc (sizeof (struct DatastorePlugin));
ret->env.cfg = cfg;
ret->env.duc = &disk_utilization_change_cb;
ret->env.cls = NULL;
@@ -1455,14 +1355,14 @@ load_plugin ()
ret->lib_name = libname;
ret->api = GNUNET_PLUGIN_load (libname, &ret->env);
if (ret->api == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to load datastore plugin for `%s'\n"), name);
- GNUNET_free (ret->short_name);
- GNUNET_free (libname);
- GNUNET_free (ret);
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to load datastore plugin for `%s'\n"), name);
+ GNUNET_free (ret->short_name);
+ GNUNET_free (libname);
+ GNUNET_free (ret);
+ return NULL;
+ }
return ret;
}
@@ -1492,30 +1392,29 @@ unload_plugin (struct DatastorePlugin *plug)
* statistics.
*/
static void
-unload_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+unload_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (GNUNET_YES == do_drop)
plugin->api->drop (plugin->api->cls);
unload_plugin (plugin);
plugin = NULL;
if (filter != NULL)
- {
- GNUNET_CONTAINER_bloomfilter_free (filter);
- filter = NULL;
- }
+ {
+ GNUNET_CONTAINER_bloomfilter_free (filter);
+ filter = NULL;
+ }
if (lastSync > 0)
sync_stats ();
if (stat_get != NULL)
- {
- GNUNET_STATISTICS_get_cancel (stat_get);
- stat_get = NULL;
- }
+ {
+ GNUNET_STATISTICS_get_cancel (stat_get);
+ stat_get = NULL;
+ }
if (stats != NULL)
- {
- GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
- stats = NULL;
- }
+ {
+ GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
+ stats = NULL;
+ }
}
@@ -1524,33 +1423,29 @@ unload_task (void *cls,
* the transport and core.
*/
static void
-cleaning_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct TransmitCallbackContext *tcc;
cleaning_done = GNUNET_YES;
while (NULL != (tcc = tcc_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (tcc_head, tcc_tail, tcc);
+ if (tcc->th != NULL)
{
- GNUNET_CONTAINER_DLL_remove (tcc_head,
- tcc_tail,
- tcc);
- if (tcc->th != NULL)
- {
- GNUNET_CONNECTION_notify_transmit_ready_cancel (tcc->th);
- GNUNET_SERVER_client_drop (tcc->client);
- }
- GNUNET_free (tcc->msg);
- GNUNET_free (tcc);
+ GNUNET_CONNECTION_notify_transmit_ready_cancel (tcc->th);
+ GNUNET_SERVER_client_drop (tcc->client);
}
+ GNUNET_free (tcc->msg);
+ GNUNET_free (tcc);
+ }
if (expired_kill_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (expired_kill_task);
- expired_kill_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (expired_kill_task);
+ expired_kill_task = GNUNET_SCHEDULER_NO_TASK;
+ }
GNUNET_SCHEDULER_add_continuation (&unload_task,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
@@ -1563,8 +1458,7 @@ cleaning_task (void *cls,
* @param client identification of the client
*/
static void
-cleanup_reservations (void *cls,
- struct GNUNET_SERVER_Client *client)
+cleanup_reservations (void *cls, struct GNUNET_SERVER_Client *client)
{
struct ReservationList *pos;
struct ReservationList *prev;
@@ -1575,27 +1469,25 @@ cleanup_reservations (void *cls,
prev = NULL;
pos = reservations;
while (NULL != pos)
+ {
+ next = pos->next;
+ if (pos->client == client)
{
- next = pos->next;
- if (pos->client == client)
- {
- if (prev == NULL)
- reservations = next;
- else
- prev->next = next;
- reserved -= pos->amount + pos->entries * GNUNET_DATASTORE_ENTRY_OVERHEAD;
- GNUNET_free (pos);
- }
+ if (prev == NULL)
+ reservations = next;
else
- {
- prev = pos;
- }
- pos = next;
+ prev->next = next;
+ reserved -= pos->amount + pos->entries * GNUNET_DATASTORE_ENTRY_OVERHEAD;
+ GNUNET_free (pos);
+ }
+ else
+ {
+ prev = pos;
}
+ pos = next;
+ }
GNUNET_STATISTICS_set (stats,
- gettext_noop ("# reserved"),
- reserved,
- GNUNET_NO);
+ gettext_noop ("# reserved"), reserved, GNUNET_NO);
}
@@ -1612,21 +1504,24 @@ run (void *cls,
const struct GNUNET_CONFIGURATION_Handle *c)
{
static const struct GNUNET_SERVER_MessageHandler handlers[] = {
- {&handle_reserve, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE,
- sizeof(struct ReserveMessage) },
- {&handle_release_reserve, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE,
- sizeof(struct ReleaseReserveMessage) },
- {&handle_put, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_PUT, 0 },
- {&handle_update, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_UPDATE,
- sizeof (struct UpdateMessage) },
- {&handle_get, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_GET, 0 },
- {&handle_get_replication, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_GET_REPLICATION,
- sizeof(struct GNUNET_MessageHeader) },
- {&handle_get_zero_anonymity, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY,
- sizeof(struct GetZeroAnonymityMessage) },
- {&handle_remove, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE, 0 },
- {&handle_drop, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_DROP,
- sizeof(struct GNUNET_MessageHeader) },
+ {&handle_reserve, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE,
+ sizeof (struct ReserveMessage)},
+ {&handle_release_reserve, NULL,
+ GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE,
+ sizeof (struct ReleaseReserveMessage)},
+ {&handle_put, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_PUT, 0},
+ {&handle_update, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_UPDATE,
+ sizeof (struct UpdateMessage)},
+ {&handle_get, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_GET, 0},
+ {&handle_get_replication, NULL,
+ GNUNET_MESSAGE_TYPE_DATASTORE_GET_REPLICATION,
+ sizeof (struct GNUNET_MessageHeader)},
+ {&handle_get_zero_anonymity, NULL,
+ GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY,
+ sizeof (struct GetZeroAnonymityMessage)},
+ {&handle_remove, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE, 0},
+ {&handle_drop, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_DROP,
+ sizeof (struct GNUNET_MessageHeader)},
{NULL, NULL, 0, 0}
};
char *fn;
@@ -1634,81 +1529,72 @@ run (void *cls,
cfg = c;
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg,
- "DATASTORE", "QUOTA", &quota))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("No `%s' specified for `%s' in configuration!\n"),
- "QUOTA",
- "DATASTORE");
- return;
- }
+ GNUNET_CONFIGURATION_get_value_number (cfg, "DATASTORE", "QUOTA", &quota))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("No `%s' specified for `%s' in configuration!\n"),
+ "QUOTA", "DATASTORE");
+ return;
+ }
stats = GNUNET_STATISTICS_create ("datastore", cfg);
+ GNUNET_STATISTICS_set (stats, gettext_noop ("# quota"), quota, GNUNET_NO);
+ cache_size = quota / 8; /* Or should we make this an option? */
GNUNET_STATISTICS_set (stats,
- gettext_noop ("# quota"),
- quota,
- GNUNET_NO);
- cache_size = quota / 8; /* Or should we make this an option? */
- GNUNET_STATISTICS_set (stats,
- gettext_noop ("# cache size"),
- cache_size,
- GNUNET_NO);
- bf_size = quota / 32; /* 8 bit per entry, 1 bit per 32 kb in DB */
+ gettext_noop ("# cache size"), cache_size, GNUNET_NO);
+ bf_size = quota / 32; /* 8 bit per entry, 1 bit per 32 kb in DB */
fn = NULL;
- if ( (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- "DATASTORE",
- "BLOOMFILTER",
- &fn)) ||
- (GNUNET_OK !=
- GNUNET_DISK_directory_create_for_file (fn)) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Could not use specified filename `%s' for bloomfilter.\n"),
- fn != NULL ? fn : "");
- GNUNET_free_non_null (fn);
- fn = NULL;
- }
+ if ((GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "DATASTORE",
+ "BLOOMFILTER",
+ &fn)) ||
+ (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Could not use specified filename `%s' for bloomfilter.\n"),
+ fn != NULL ? fn : "");
+ GNUNET_free_non_null (fn);
+ fn = NULL;
+ }
if (fn != NULL)
- filter = GNUNET_CONTAINER_bloomfilter_load (fn, bf_size, 5); /* approx. 3% false positives at max use */
+ filter = GNUNET_CONTAINER_bloomfilter_load (fn, bf_size, 5); /* approx. 3% false positives at max use */
else
- filter = GNUNET_CONTAINER_bloomfilter_init (NULL, bf_size, 5); /* approx. 3% false positives at max use */
+ filter = GNUNET_CONTAINER_bloomfilter_init (NULL, bf_size, 5); /* approx. 3% false positives at max use */
GNUNET_free_non_null (fn);
if (filter == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to initialize bloomfilter.\n"));
+ if (stats != NULL)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to initialize bloomfilter.\n"));
- if (stats != NULL)
- {
- GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
- stats = NULL;
- }
- return;
+ GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
+ stats = NULL;
}
+ return;
+ }
plugin = load_plugin ();
if (NULL == plugin)
+ {
+ GNUNET_CONTAINER_bloomfilter_free (filter);
+ filter = NULL;
+ if (stats != NULL)
{
- GNUNET_CONTAINER_bloomfilter_free (filter);
- filter = NULL;
- if (stats != NULL)
- {
- GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
- stats = NULL;
- }
- return;
+ GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
+ stats = NULL;
}
+ return;
+ }
stat_get = GNUNET_STATISTICS_get (stats,
- "datastore",
- QUOTA_STAT_NAME,
- GNUNET_TIME_UNIT_SECONDS,
- &process_stat_done,
- &process_stat_in,
- plugin);
+ "datastore",
+ QUOTA_STAT_NAME,
+ GNUNET_TIME_UNIT_SECONDS,
+ &process_stat_done,
+ &process_stat_in, plugin);
GNUNET_SERVER_disconnect_notify (server, &cleanup_reservations, NULL);
GNUNET_SERVER_add_handlers (server, handlers);
expired_kill_task
- = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
- &delete_expired, NULL);
+ = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &delete_expired, NULL);
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
&cleaning_task, NULL);
}
@@ -1730,8 +1616,7 @@ main (int argc, char *const *argv)
GNUNET_SERVICE_run (argc,
argv,
"datastore",
- GNUNET_SERVICE_OPTION_NONE,
- &run, NULL)) ? 0 : 1;
+ GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
return ret;
}
diff --git a/src/datastore/perf_datastore_api.c b/src/datastore/perf_datastore_api.c
index 9d7755342e..9d567aacda 100644
--- a/src/datastore/perf_datastore_api.c
+++ b/src/datastore/perf_datastore_api.c
@@ -84,13 +84,13 @@ static struct GNUNET_TIME_Absolute start_time;
static int ok;
enum RunPhase
- {
- RP_DONE = 0,
- RP_PUT,
- RP_CUT,
- RP_REPORT,
- RP_ERROR
- };
+{
+ RP_DONE = 0,
+ RP_PUT,
+ RP_CUT,
+ RP_REPORT,
+ RP_ERROR
+};
struct CpsRunContext
@@ -105,28 +105,23 @@ struct CpsRunContext
static void
-run_continuation (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
static void
-check_success (void *cls,
- int success,
- const char *msg)
+check_success (void *cls, int success, const char *msg)
{
struct CpsRunContext *crc = cls;
if (GNUNET_OK != success)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Check success failed: `%s'\n", msg);
- crc->phase = RP_ERROR;
- GNUNET_SCHEDULER_add_now (&run_continuation,
- crc);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Check success failed: `%s'\n", msg);
+ crc->phase = RP_ERROR;
+ GNUNET_SCHEDULER_add_now (&run_continuation, crc);
+ return;
+ }
#if REPORT_ID
fprintf (stderr, "I");
#endif
@@ -135,17 +130,16 @@ check_success (void *cls,
stored_entries++;
crc->j++;
if (crc->j >= PUT_10)
- {
- crc->j = 0;
- crc->i++;
- if (crc->i == ITERATIONS)
- crc->phase = RP_DONE;
- else
- crc->phase = RP_CUT;
- }
+ {
+ crc->j = 0;
+ crc->i++;
+ if (crc->i == ITERATIONS)
+ crc->phase = RP_DONE;
+ else
+ crc->phase = RP_CUT;
+ }
GNUNET_SCHEDULER_add_continuation (&run_continuation,
- crc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
@@ -157,41 +151,35 @@ check_success (void *cls,
* @param success GNUNET_SYSERR on failure
* @param msg NULL on success, otherwise an error message
*/
-static void
-remove_next(void *cls,
- int success,
- const char *msg)
+static void
+remove_next (void *cls, int success, const char *msg)
{
struct CpsRunContext *crc = cls;
if (GNUNET_OK != success)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "remove_next failed: `%s'\n", msg);
- crc->phase = RP_ERROR;
- GNUNET_SCHEDULER_add_now (&run_continuation,
- crc);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "remove_next failed: `%s'\n", msg);
+ crc->phase = RP_ERROR;
+ GNUNET_SCHEDULER_add_now (&run_continuation, crc);
+ return;
+ }
#if REPORT_ID
fprintf (stderr, "D");
#endif
GNUNET_assert (GNUNET_OK == success);
- GNUNET_SCHEDULER_add_now (&run_continuation,
- crc);
+ GNUNET_SCHEDULER_add_now (&run_continuation, crc);
}
-static void
+static void
delete_value (void *cls,
- const GNUNET_HashCode *key,
- size_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute
- expiration, uint64_t uid)
+ const GNUNET_HashCode * key,
+ size_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct CpsRunContext *crc = cls;
@@ -203,19 +191,16 @@ delete_value (void *cls,
if (stored_bytes < MAX_SIZE)
crc->phase = RP_PUT;
GNUNET_assert (NULL !=
- GNUNET_DATASTORE_remove (datastore,
- key,
- size,
- data,
- 1, 1, TIMEOUT,
- &remove_next,
- crc));
+ GNUNET_DATASTORE_remove (datastore,
+ key,
+ size,
+ data,
+ 1, 1, TIMEOUT, &remove_next, crc));
}
static void
-run_continuation (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct CpsRunContext *crc = cls;
size_t size;
@@ -227,133 +212,127 @@ run_continuation (void *cls,
ok = (int) crc->phase;
switch (crc->phase)
- {
- case RP_PUT:
- memset (&key, 256 - crc->i, sizeof (GNUNET_HashCode));
- i = crc->j;
- k = crc->i;
- /* most content is 32k */
- size = 32 * 1024;
- if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /* but some of it is less! */
- size = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 32 * 1024);
- crc->size = size = size - (size & 7); /* always multiple of 8 */
- GNUNET_CRYPTO_hash (&key, sizeof (GNUNET_HashCode), &key);
- memset (data, i, size);
- if (i > 255)
- memset (data, i - 255, size / 2);
- data[0] = k;
- GNUNET_assert (NULL !=
- GNUNET_DATASTORE_put (datastore,
- 0,
- &key,
- size,
- data,
- i+1,
- GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100),
- i, 0,
- GNUNET_TIME_relative_to_absolute
- (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
- GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000))),
- 1, 1, TIMEOUT,
- &check_success,
- crc));
- break;
- case RP_CUT:
- /* trim down below MAX_SIZE again */
- GNUNET_assert (NULL !=
- GNUNET_DATASTORE_get_for_replication (datastore,
- 1, 1, TIMEOUT,
- &delete_value,
- crc));
- break;
- case RP_REPORT:
- printf (
+ {
+ case RP_PUT:
+ memset (&key, 256 - crc->i, sizeof (GNUNET_HashCode));
+ i = crc->j;
+ k = crc->i;
+ /* most content is 32k */
+ size = 32 * 1024;
+ if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /* but some of it is less! */
+ size = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 32 * 1024);
+ crc->size = size = size - (size & 7); /* always multiple of 8 */
+ GNUNET_CRYPTO_hash (&key, sizeof (GNUNET_HashCode), &key);
+ memset (data, i, size);
+ if (i > 255)
+ memset (data, i - 255, size / 2);
+ data[0] = k;
+ GNUNET_assert (NULL !=
+ GNUNET_DATASTORE_put (datastore,
+ 0,
+ &key,
+ size,
+ data,
+ i + 1,
+ GNUNET_CRYPTO_random_u32
+ (GNUNET_CRYPTO_QUALITY_WEAK, 100), i,
+ 0,
+ GNUNET_TIME_relative_to_absolute
+ (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS,
+ GNUNET_CRYPTO_random_u32
+ (GNUNET_CRYPTO_QUALITY_WEAK, 1000))),
+ 1, 1, TIMEOUT, &check_success, crc));
+ break;
+ case RP_CUT:
+ /* trim down below MAX_SIZE again */
+ GNUNET_assert (NULL !=
+ GNUNET_DATASTORE_get_for_replication (datastore,
+ 1, 1, TIMEOUT,
+ &delete_value, crc));
+ break;
+ case RP_REPORT:
+ printf (
#if REPORT_ID
- "\n"
+ "\n"
#endif
- "Stored %llu kB / %lluk ops / %llu ops/s\n",
- stored_bytes / 1024, /* used size in k */
- stored_ops / 1024, /* total operations (in k) */
- 1000 * stored_ops / (1 + GNUNET_TIME_absolute_get_duration(start_time).rel_value));
- crc->phase = RP_PUT;
- crc->j = 0;
- GNUNET_SCHEDULER_add_continuation (&run_continuation,
- crc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- break;
- case RP_DONE:
- GNUNET_snprintf (gstr, sizeof (gstr),
- "DATASTORE-%s",
- plugin_name);
- if ( (crc->i == ITERATIONS) &&
- (stored_ops > 0) )
- GAUGER (gstr,
- "PUT operation duration",
- GNUNET_TIME_absolute_get_duration(start_time).rel_value / stored_ops,
- "ms/operation");
- GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
- GNUNET_free (crc);
- ok = 0;
- break;
- case RP_ERROR:
- GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
- GNUNET_free (crc);
- ok = 1;
- break;
- default:
- GNUNET_assert (0);
- }
+ "Stored %llu kB / %lluk ops / %llu ops/s\n", stored_bytes / 1024, /* used size in k */
+ stored_ops / 1024, /* total operations (in k) */
+ 1000 * stored_ops / (1 +
+ GNUNET_TIME_absolute_get_duration
+ (start_time).rel_value));
+ crc->phase = RP_PUT;
+ crc->j = 0;
+ GNUNET_SCHEDULER_add_continuation (&run_continuation,
+ crc,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ case RP_DONE:
+ GNUNET_snprintf (gstr, sizeof (gstr), "DATASTORE-%s", plugin_name);
+ if ((crc->i == ITERATIONS) && (stored_ops > 0))
+ GAUGER (gstr,
+ "PUT operation duration",
+ GNUNET_TIME_absolute_get_duration (start_time).rel_value /
+ stored_ops, "ms/operation");
+ GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
+ GNUNET_free (crc);
+ ok = 0;
+ break;
+ case RP_ERROR:
+ GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
+ GNUNET_free (crc);
+ ok = 1;
+ break;
+ default:
+ GNUNET_assert (0);
+ }
}
static void
-run_tests (void *cls,
- int success,
- const char *msg)
+run_tests (void *cls, int success, const char *msg)
{
struct CpsRunContext *crc = cls;
if (success != GNUNET_YES)
- {
- fprintf (stderr,
- "Test 'put' operation failed with error `%s' database likely not setup, skipping test.",
- msg);
- GNUNET_free (crc);
- return;
- }
+ {
+ fprintf (stderr,
+ "Test 'put' operation failed with error `%s' database likely not setup, skipping test.",
+ msg);
+ GNUNET_free (crc);
+ return;
+ }
GNUNET_SCHEDULER_add_continuation (&run_continuation,
- crc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct CpsRunContext *crc;
static GNUNET_HashCode zkey;
datastore = GNUNET_DATASTORE_connect (cfg);
start_time = GNUNET_TIME_absolute_get ();
- crc = GNUNET_malloc(sizeof(struct CpsRunContext));
+ crc = GNUNET_malloc (sizeof (struct CpsRunContext));
crc->cfg = cfg;
crc->phase = RP_PUT;
if (NULL ==
GNUNET_DATASTORE_put (datastore, 0,
- &zkey, 4, "TEST",
- GNUNET_BLOCK_TYPE_TEST,
- 0, 0, 0, GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS),
- 0, 1, GNUNET_TIME_UNIT_MINUTES,
- &run_tests, crc))
- {
- fprintf (stderr,
- "Test 'put' operation failed.\n");
- ok = 1;
- GNUNET_free (crc);
- }
+ &zkey, 4, "TEST",
+ GNUNET_BLOCK_TYPE_TEST,
+ 0, 0, 0,
+ GNUNET_TIME_relative_to_absolute
+ (GNUNET_TIME_UNIT_SECONDS), 0, 1,
+ GNUNET_TIME_UNIT_MINUTES, &run_tests, crc))
+ {
+ fprintf (stderr, "Test 'put' operation failed.\n");
+ ok = 1;
+ GNUNET_free (crc);
+ }
}
@@ -362,7 +341,8 @@ check ()
{
struct GNUNET_OS_Process *proc;
char cfg_name[128];
- char *const argv[] = {
+
+ char *const argv[] = {
"perf-datastore-api",
"-c",
cfg_name,
@@ -376,25 +356,24 @@ check ()
};
GNUNET_snprintf (cfg_name,
- sizeof (cfg_name),
- "test_datastore_api_data_%s.conf",
- plugin_name);
+ sizeof (cfg_name),
+ "test_datastore_api_data_%s.conf", plugin_name);
proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfg_name, NULL);
+ "-c", cfg_name, NULL);
GNUNET_assert (NULL != proc);
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
argv, "perf-datastore-api", "nohelp",
options, &run, NULL);
- sleep (1); /* give datastore chance to process 'DROP' */
+ sleep (1); /* give datastore chance to process 'DROP' */
if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- ok = 1;
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ ok = 1;
+ }
GNUNET_OS_process_wait (proc);
GNUNET_OS_process_close (proc);
proc = NULL;
@@ -412,21 +391,20 @@ main (int argc, char *argv[])
sleep (1);
/* determine name of plugin to use */
plugin_name = argv[0];
- while (NULL != (pos = strstr(plugin_name, "_")))
- plugin_name = pos+1;
- if (NULL != (pos = strstr(plugin_name, ".")))
+ while (NULL != (pos = strstr (plugin_name, "_")))
+ plugin_name = pos + 1;
+ if (NULL != (pos = strstr (plugin_name, ".")))
pos[0] = 0;
else
pos = (char *) plugin_name;
GNUNET_snprintf (dir_name,
- sizeof (dir_name),
- "/tmp/test-gnunet-datastore-%s",
- plugin_name);
+ sizeof (dir_name),
+ "/tmp/test-gnunet-datastore-%s", plugin_name);
GNUNET_DISK_directory_remove (dir_name);
GNUNET_log_setup ("perf-datastore-api",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
"WARNING",
#endif
diff --git a/src/datastore/perf_plugin_datastore.c b/src/datastore/perf_plugin_datastore.c
index 3829c7af5a..f8a3705e46 100644
--- a/src/datastore/perf_plugin_datastore.c
+++ b/src/datastore/perf_plugin_datastore.c
@@ -61,14 +61,14 @@ static const char *plugin_name;
static int ok;
enum RunPhase
- {
- RP_ERROR = 0,
- RP_PUT,
- RP_REP_GET,
- RP_ZA_GET,
- RP_EXP_GET,
- RP_DONE
- };
+{
+ RP_ERROR = 0,
+ RP_PUT,
+ RP_REP_GET,
+ RP_ZA_GET,
+ RP_EXP_GET,
+ RP_DONE
+};
struct CpsRunContext
@@ -77,7 +77,7 @@ struct CpsRunContext
struct GNUNET_TIME_Absolute start;
struct GNUNET_TIME_Absolute end;
const struct GNUNET_CONFIGURATION_Handle *cfg;
- struct GNUNET_DATASTORE_PluginFunctions * api;
+ struct GNUNET_DATASTORE_PluginFunctions *api;
enum RunPhase phase;
unsigned int cnt;
unsigned int iter;
@@ -94,15 +94,13 @@ struct CpsRunContext
* 0 for "reset to empty"
*/
static void
-disk_utilization_change_cb (void *cls,
- int delta)
+disk_utilization_change_cb (void *cls, int delta)
{
}
-
+
static void
-putValue (struct GNUNET_DATASTORE_PluginFunctions * api,
- int i, int k)
+putValue (struct GNUNET_DATASTORE_PluginFunctions *api, int i, int k)
{
char value[65536];
size_t size;
@@ -113,7 +111,7 @@ putValue (struct GNUNET_DATASTORE_PluginFunctions * api,
/* most content is 32k */
size = 32 * 1024;
- if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /* but some of it is less! */
+ if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /* but some of it is less! */
size = 8 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 32 * 1024);
size = size - (size & 7); /* always multiple of 8 */
@@ -127,46 +125,38 @@ putValue (struct GNUNET_DATASTORE_PluginFunctions * api,
memcpy (&value[4], &i, sizeof (i));
msg = NULL;
prio = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
- if (GNUNET_OK != api->put (api->cls,
- &key,
- size,
- value,
- 1 + i % 4 /* type */,
- prio,
- i % 4 /* anonymity */,
- 0 /* replication */,
- GNUNET_TIME_relative_to_absolute
- (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
- 60 * 60 * 60 * 1000 +
- GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000))),
- &msg))
- {
- fprintf (stderr, "ERROR: `%s'\n", msg);
- GNUNET_free_non_null (msg);
- return;
- }
+ if (GNUNET_OK != api->put (api->cls, &key, size, value, 1 + i % 4 /* type */ ,
+ prio, i % 4 /* anonymity */ ,
+ 0 /* replication */ ,
+ GNUNET_TIME_relative_to_absolute
+ (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS,
+ 60 * 60 * 60 * 1000 +
+ GNUNET_CRYPTO_random_u32
+ (GNUNET_CRYPTO_QUALITY_WEAK, 1000))), &msg))
+ {
+ fprintf (stderr, "ERROR: `%s'\n", msg);
+ GNUNET_free_non_null (msg);
+ return;
+ }
ic++;
stored_bytes += size;
stored_ops++;
stored_entries++;
}
-static void
-test (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+static void test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
static int
iterate_zeros (void *cls,
- const GNUNET_HashCode * key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute
- expiration,
- uint64_t uid)
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct CpsRunContext *crc = cls;
int i;
@@ -175,38 +165,37 @@ iterate_zeros (void *cls,
GNUNET_assert (key != NULL);
GNUNET_assert (size >= 8);
memcpy (&i, &cdata[4], sizeof (i));
- hits[i/8] |= (1 << (i % 8));
+ hits[i / 8] |= (1 << (i % 8));
-#if VERBOSE
+#if VERBOSE
fprintf (stderr, "Found result type=%u, priority=%u, size=%u, expire=%llu\n",
- type, priority, size,
- (unsigned long long) expiration.abs_value);
+ type, priority, size, (unsigned long long) expiration.abs_value);
#endif
crc->cnt++;
if (crc->cnt == PUT_10 / 4 - 1)
- {
- unsigned int bc;
-
- bc = 0;
- for (i = 0;i<PUT_10;i++)
- if (0 != (hits[i/8] & (1 << (i % 8))))
- bc++;
-
- crc->end = GNUNET_TIME_absolute_get();
- printf ("%s took %llu ms yielding %u/%u items\n",
- "Select random zero-anonymity item",
- (unsigned long long) (crc->end.abs_value - crc->start.abs_value),
- bc,
- crc->cnt);
- if (crc->cnt > 0)
- GAUGER (category,
- "Select random zero-anonymity item",
- (crc->end.abs_value - crc->start.abs_value) / crc->cnt, "ms/item");
- memset (hits, 0, sizeof (hits));
- crc->phase++;
- crc->cnt = 0;
- crc->start = GNUNET_TIME_absolute_get ();
- }
+ {
+ unsigned int bc;
+
+ bc = 0;
+ for (i = 0; i < PUT_10; i++)
+ if (0 != (hits[i / 8] & (1 << (i % 8))))
+ bc++;
+
+ crc->end = GNUNET_TIME_absolute_get ();
+ printf ("%s took %llu ms yielding %u/%u items\n",
+ "Select random zero-anonymity item",
+ (unsigned long long) (crc->end.abs_value - crc->start.abs_value),
+ bc, crc->cnt);
+ if (crc->cnt > 0)
+ GAUGER (category,
+ "Select random zero-anonymity item",
+ (crc->end.abs_value - crc->start.abs_value) / crc->cnt,
+ "ms/item");
+ memset (hits, 0, sizeof (hits));
+ crc->phase++;
+ crc->cnt = 0;
+ crc->start = GNUNET_TIME_absolute_get ();
+ }
GNUNET_SCHEDULER_add_now (&test, crc);
return GNUNET_OK;
}
@@ -214,15 +203,13 @@ iterate_zeros (void *cls,
static int
expiration_get (void *cls,
- const GNUNET_HashCode * key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute
- expiration,
- uint64_t uid)
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct CpsRunContext *crc = cls;
int i;
@@ -230,36 +217,35 @@ expiration_get (void *cls,
GNUNET_assert (size >= 8);
memcpy (&i, &cdata[4], sizeof (i));
- hits[i/8] |= (1 << (i % 8));
+ hits[i / 8] |= (1 << (i % 8));
crc->cnt++;
if (PUT_10 <= crc->cnt)
- {
- unsigned int bc;
-
- bc = 0;
- for (i = 0;i<PUT_10;i++)
- if (0 != (hits[i/8] & (1 << (i % 8))))
- bc++;
-
- crc->end = GNUNET_TIME_absolute_get();
- printf ("%s took %llu ms yielding %u/%u items\n",
- "Selecting and deleting by expiration",
- (unsigned long long) (crc->end.abs_value - crc->start.abs_value),
- bc,
- (unsigned int) PUT_10);
- if (crc->cnt > 0)
- GAUGER (category,
- "Selecting and deleting by expiration",
- (crc->end.abs_value - crc->start.abs_value) / crc->cnt,
- "ms/item");
- memset (hits, 0, sizeof (hits));
- if (++crc->iter == ITERATIONS)
- crc->phase++;
- else
- crc->phase = RP_PUT;
- crc->cnt = 0;
- crc->start = GNUNET_TIME_absolute_get ();
- }
+ {
+ unsigned int bc;
+
+ bc = 0;
+ for (i = 0; i < PUT_10; i++)
+ if (0 != (hits[i / 8] & (1 << (i % 8))))
+ bc++;
+
+ crc->end = GNUNET_TIME_absolute_get ();
+ printf ("%s took %llu ms yielding %u/%u items\n",
+ "Selecting and deleting by expiration",
+ (unsigned long long) (crc->end.abs_value - crc->start.abs_value),
+ bc, (unsigned int) PUT_10);
+ if (crc->cnt > 0)
+ GAUGER (category,
+ "Selecting and deleting by expiration",
+ (crc->end.abs_value - crc->start.abs_value) / crc->cnt,
+ "ms/item");
+ memset (hits, 0, sizeof (hits));
+ if (++crc->iter == ITERATIONS)
+ crc->phase++;
+ else
+ crc->phase = RP_PUT;
+ crc->cnt = 0;
+ crc->start = GNUNET_TIME_absolute_get ();
+ }
GNUNET_SCHEDULER_add_now (&test, crc);
return GNUNET_NO;
}
@@ -267,15 +253,13 @@ expiration_get (void *cls,
static int
replication_get (void *cls,
- const GNUNET_HashCode * key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute
- expiration,
- uint64_t uid)
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct CpsRunContext *crc = cls;
int i;
@@ -284,35 +268,34 @@ replication_get (void *cls,
GNUNET_assert (NULL != key);
GNUNET_assert (size >= 8);
memcpy (&i, &cdata[4], sizeof (i));
- hits[i/8] |= (1 << (i % 8));
+ hits[i / 8] |= (1 << (i % 8));
crc->cnt++;
if (PUT_10 <= crc->cnt)
- {
- unsigned int bc;
-
- bc = 0;
- for (i = 0;i<PUT_10;i++)
- if (0 != (hits[i/8] & (1 << (i % 8))))
- bc++;
-
- crc->end = GNUNET_TIME_absolute_get();
- printf ("%s took %llu ms yielding %u/%u items\n",
- "Selecting random item for replication",
- (unsigned long long) (crc->end.abs_value - crc->start.abs_value),
- bc,
- (unsigned int) PUT_10);
- if (crc->cnt > 0)
- GAUGER (category,
- "Selecting random item for replication",
- (crc->end.abs_value - crc->start.abs_value) / crc->cnt,
- "ms/item");
- memset (hits, 0, sizeof (hits));
- crc->phase++;
- crc->offset = 0;
- crc->cnt = 0;
- crc->start = GNUNET_TIME_absolute_get ();
- }
-
+ {
+ unsigned int bc;
+
+ bc = 0;
+ for (i = 0; i < PUT_10; i++)
+ if (0 != (hits[i / 8] & (1 << (i % 8))))
+ bc++;
+
+ crc->end = GNUNET_TIME_absolute_get ();
+ printf ("%s took %llu ms yielding %u/%u items\n",
+ "Selecting random item for replication",
+ (unsigned long long) (crc->end.abs_value - crc->start.abs_value),
+ bc, (unsigned int) PUT_10);
+ if (crc->cnt > 0)
+ GAUGER (category,
+ "Selecting random item for replication",
+ (crc->end.abs_value - crc->start.abs_value) / crc->cnt,
+ "ms/item");
+ memset (hits, 0, sizeof (hits));
+ crc->phase++;
+ crc->offset = 0;
+ crc->cnt = 0;
+ crc->start = GNUNET_TIME_absolute_get ();
+ }
+
GNUNET_SCHEDULER_add_now (&test, crc);
return GNUNET_OK;
}
@@ -326,8 +309,8 @@ replication_get (void *cls,
* @param cfg configuration to use
*/
static void
-unload_plugin (struct GNUNET_DATASTORE_PluginFunctions * api,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+unload_plugin (struct GNUNET_DATASTORE_PluginFunctions *api,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
char *name;
char *libname;
@@ -335,13 +318,12 @@ unload_plugin (struct GNUNET_DATASTORE_PluginFunctions * api,
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
"DATASTORE", "DATABASE", &name))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("No `%s' specified for `%s' in configuration!\n"),
- "DATABASE",
- "DATASTORE");
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("No `%s' specified for `%s' in configuration!\n"),
+ "DATABASE", "DATASTORE");
+ return;
+ }
GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name);
GNUNET_break (NULL == GNUNET_PLUGIN_unload (libname, api));
GNUNET_free (libname);
@@ -365,76 +347,66 @@ cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
static void
-test (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
+test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
struct CpsRunContext *crc = cls;
int j;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- GNUNET_break (0);
- crc->phase = RP_ERROR;
- }
+ {
+ GNUNET_break (0);
+ crc->phase = RP_ERROR;
+ }
#if VERBOSE
- fprintf (stderr, "In phase %d, iteration %u\n",
- crc->phase,
- crc->cnt);
+ fprintf (stderr, "In phase %d, iteration %u\n", crc->phase, crc->cnt);
#endif
switch (crc->phase)
+ {
+ case RP_ERROR:
+ GNUNET_break (0);
+ crc->api->drop (crc->api->cls);
+ ok = 1;
+ GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &cleaning_task, crc);
+ break;
+ case RP_PUT:
+ crc->start = GNUNET_TIME_absolute_get ();
+ for (j = 0; j < PUT_10; j++)
+ putValue (crc->api, j, crc->i);
+ crc->end = GNUNET_TIME_absolute_get ();
{
- case RP_ERROR:
- GNUNET_break (0);
- crc->api->drop (crc->api->cls);
- ok = 1;
- GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
- &cleaning_task, crc);
- break;
- case RP_PUT:
- crc->start = GNUNET_TIME_absolute_get ();
- for (j=0;j<PUT_10;j++)
- putValue (crc->api, j, crc->i);
- crc->end = GNUNET_TIME_absolute_get ();
- {
- printf ("%s took %llu ms for %llu items\n",
- "Storing an item",
- (unsigned long long) (crc->end.abs_value - crc->start.abs_value),
- PUT_10);
- if (PUT_10 > 0)
- GAUGER (category,
- "Storing an item",
- (crc->end.abs_value - crc->start.abs_value) / PUT_10,
- "ms/item");
- }
- crc->i++;
- crc->start = GNUNET_TIME_absolute_get ();
- crc->phase++;
- GNUNET_SCHEDULER_add_now (&test, crc);
- break;
- case RP_REP_GET:
- crc->api->get_replication (crc->api->cls,
- &replication_get,
- crc);
- break;
- case RP_ZA_GET:
- crc->api->get_zero_anonymity (crc->api->cls,
- crc->offset++,
- 1,
- &iterate_zeros,
- crc);
- break;
- case RP_EXP_GET:
- crc->api->get_expiration (crc->api->cls,
- &expiration_get,
- crc);
- break;
- case RP_DONE:
- crc->api->drop (crc->api->cls);
- ok = 0;
- GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
- &cleaning_task, crc);
- break;
+ printf ("%s took %llu ms for %llu items\n",
+ "Storing an item",
+ (unsigned long long) (crc->end.abs_value - crc->start.abs_value),
+ PUT_10);
+ if (PUT_10 > 0)
+ GAUGER (category,
+ "Storing an item",
+ (crc->end.abs_value - crc->start.abs_value) / PUT_10,
+ "ms/item");
}
+ crc->i++;
+ crc->start = GNUNET_TIME_absolute_get ();
+ crc->phase++;
+ GNUNET_SCHEDULER_add_now (&test, crc);
+ break;
+ case RP_REP_GET:
+ crc->api->get_replication (crc->api->cls, &replication_get, crc);
+ break;
+ case RP_ZA_GET:
+ crc->api->get_zero_anonymity (crc->api->cls,
+ crc->offset++, 1, &iterate_zeros, crc);
+ break;
+ case RP_EXP_GET:
+ crc->api->get_expiration (crc->api->cls, &expiration_get, crc);
+ break;
+ case RP_DONE:
+ crc->api->drop (crc->api->cls);
+ ok = 0;
+ GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &cleaning_task, crc);
+ break;
+ }
}
@@ -445,20 +417,19 @@ static struct GNUNET_DATASTORE_PluginFunctions *
load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
{
static struct GNUNET_DATASTORE_PluginEnvironment env;
- struct GNUNET_DATASTORE_PluginFunctions * ret;
+ struct GNUNET_DATASTORE_PluginFunctions *ret;
char *name;
char *libname;
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
"DATASTORE", "DATABASE", &name))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("No `%s' specified for `%s' in configuration!\n"),
- "DATABASE",
- "DATASTORE");
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("No `%s' specified for `%s' in configuration!\n"),
+ "DATABASE", "DATASTORE");
+ return NULL;
+ }
env.cfg = cfg;
env.duc = &disk_utilization_change_cb;
env.cls = NULL;
@@ -466,12 +437,10 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
_("Loading `%s' datastore plugin\n"), name);
GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name);
if (NULL == (ret = GNUNET_PLUGIN_load (libname, &env)))
- {
- fprintf (stderr,
- "Failed to load plugin `%s'!\n",
- name);
- return NULL;
- }
+ {
+ fprintf (stderr, "Failed to load plugin `%s'!\n", name);
+ return NULL;
+ }
GNUNET_free (libname);
GNUNET_free (name);
return ret;
@@ -481,20 +450,19 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *c)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
{
struct GNUNET_DATASTORE_PluginFunctions *api;
struct CpsRunContext *crc;
api = load_plugin (c);
if (api == NULL)
- {
- fprintf (stderr,
- "Could not initialize plugin, assuming database not configured. Test not run!\n");
- return;
- }
- crc = GNUNET_malloc(sizeof(struct CpsRunContext));
+ {
+ fprintf (stderr,
+ "Could not initialize plugin, assuming database not configured. Test not run!\n");
+ return;
+ }
+ crc = GNUNET_malloc (sizeof (struct CpsRunContext));
crc->api = api;
crc->cfg = c;
crc->phase = RP_PUT;
@@ -507,7 +475,8 @@ static int
check ()
{
char cfg_name[128];
- char *const argv[] = {
+
+ char *const argv[] = {
"perf-plugin-datastore",
"-c",
cfg_name,
@@ -520,13 +489,10 @@ check ()
GNUNET_GETOPT_OPTION_END
};
- GNUNET_snprintf (category, sizeof (category),
- "DATASTORE-%s",
- plugin_name);
+ GNUNET_snprintf (category, sizeof (category), "DATASTORE-%s", plugin_name);
GNUNET_snprintf (cfg_name,
- sizeof (cfg_name),
- "perf_plugin_datastore_data_%s.conf",
- plugin_name);
+ sizeof (cfg_name),
+ "perf_plugin_datastore_data_%s.conf", plugin_name);
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
argv, "perf-plugin-datastore", "nohelp",
options, &run, NULL);
@@ -546,17 +512,16 @@ main (int argc, char *argv[])
sleep (1);
/* determine name of plugin to use */
plugin_name = argv[0];
- while (NULL != (pos = strstr(plugin_name, "_")))
- plugin_name = pos+1;
- if (NULL != (pos = strstr(plugin_name, ".")))
+ while (NULL != (pos = strstr (plugin_name, "_")))
+ plugin_name = pos + 1;
+ if (NULL != (pos = strstr (plugin_name, ".")))
pos[0] = 0;
else
pos = (char *) plugin_name;
GNUNET_snprintf (dir_name,
- sizeof (dir_name),
- "/tmp/perf-gnunet-datastore-%s",
- plugin_name);
+ sizeof (dir_name),
+ "/tmp/perf-gnunet-datastore-%s", plugin_name);
GNUNET_DISK_directory_remove (dir_name);
GNUNET_log_setup ("perf-plugin-datastore",
#if VERBOSE
@@ -574,5 +539,3 @@ main (int argc, char *argv[])
}
/* end of perf_plugin_datastore.c */
-
-
diff --git a/src/datastore/plugin_datastore_mysql.c b/src/datastore/plugin_datastore_mysql.c
index 3d0da61a0c..a9b0399819 100644
--- a/src/datastore/plugin_datastore_mysql.c
+++ b/src/datastore/plugin_datastore_mysql.c
@@ -164,7 +164,7 @@ struct GNUNET_MysqlStatementHandle
/**
* Context for all functions in this plugin.
*/
-struct Plugin
+struct Plugin
{
/**
* Our execution environment.
@@ -175,7 +175,7 @@ struct Plugin
* Handle to talk to MySQL.
*/
MYSQL *dbf;
-
+
/**
* We keep all prepared statements in a DLL. This is the head.
*/
@@ -196,13 +196,13 @@ struct Plugin
*/
#define INSERT_ENTRY "INSERT INTO gn090 (repl,type,prio,anonLevel,expire,rvalue,hash,vhash,value) VALUES (?,?,?,?,?,?,?,?,?)"
struct GNUNET_MysqlStatementHandle *insert_entry;
-
+
#define DELETE_ENTRY_BY_UID "DELETE FROM gn090 WHERE uid=?"
struct GNUNET_MysqlStatementHandle *delete_entry_by_uid;
#define COUNT_ENTRY_BY_HASH "SELECT count(*) FROM gn090 FORCE INDEX (idx_hash) WHERE hash=?"
struct GNUNET_MysqlStatementHandle *count_entry_by_hash;
-
+
#define SELECT_ENTRY_BY_HASH "SELECT type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX (idx_hash) WHERE hash=? ORDER BY uid LIMIT 1 OFFSET ?"
struct GNUNET_MysqlStatementHandle *select_entry_by_hash;
@@ -211,16 +211,16 @@ struct Plugin
#define SELECT_ENTRY_BY_HASH_AND_VHASH "SELECT type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX (idx_hash_vhash) WHERE hash=? AND vhash=? ORDER BY uid LIMIT 1 OFFSET ?"
struct GNUNET_MysqlStatementHandle *select_entry_by_hash_and_vhash;
-
+
#define COUNT_ENTRY_BY_HASH_AND_TYPE "SELECT count(*) FROM gn090 FORCE INDEX (idx_hash_type_uid) WHERE hash=? AND type=?"
struct GNUNET_MysqlStatementHandle *count_entry_by_hash_and_type;
#define SELECT_ENTRY_BY_HASH_AND_TYPE "SELECT type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX (idx_hash_type_uid) WHERE hash=? AND type=? ORDER BY uid LIMIT 1 OFFSET ?"
struct GNUNET_MysqlStatementHandle *select_entry_by_hash_and_type;
-
+
#define COUNT_ENTRY_BY_HASH_VHASH_AND_TYPE "SELECT count(*) FROM gn090 FORCE INDEX (idx_hash_vhash) WHERE hash=? AND vhash=? AND type=?"
struct GNUNET_MysqlStatementHandle *count_entry_by_hash_vhash_and_type;
-
+
#define SELECT_ENTRY_BY_HASH_VHASH_AND_TYPE "SELECT type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX (idx_hash_vhash) WHERE hash=? AND vhash=? AND type=? ORDER BY uid ASC LIMIT 1 OFFSET ?"
struct GNUNET_MysqlStatementHandle *select_entry_by_hash_vhash_and_type;
@@ -274,6 +274,7 @@ get_my_cnf_path (const struct GNUNET_CONFIGURATION_Handle *cfg)
char *cnffile;
char *home_dir;
struct stat st;
+
#ifndef WINDOWS
struct passwd *pw;
#endif
@@ -282,44 +283,47 @@ get_my_cnf_path (const struct GNUNET_CONFIGURATION_Handle *cfg)
#ifndef WINDOWS
pw = getpwuid (getuid ());
if (!pw)
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
- "getpwuid");
- return NULL;
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "getpwuid");
+ return NULL;
+ }
if (GNUNET_YES ==
- GNUNET_CONFIGURATION_have_value (cfg,
- "datastore-mysql", "CONFIG"))
- {
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- "datastore-mysql", "CONFIG", &cnffile));
- configured = GNUNET_YES;
- }
+ GNUNET_CONFIGURATION_have_value (cfg, "datastore-mysql", "CONFIG"))
+ {
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "datastore-mysql",
+ "CONFIG",
+ &cnffile));
+ configured = GNUNET_YES;
+ }
else
- {
- home_dir = GNUNET_strdup (pw->pw_dir);
+ {
+ home_dir = GNUNET_strdup (pw->pw_dir);
+ GNUNET_asprintf (&cnffile, "%s/.my.cnf", home_dir);
+ GNUNET_free (home_dir);
+ configured = GNUNET_NO;
+ }
#else
- home_dir = (char *) GNUNET_malloc (_MAX_PATH + 1);
- plibc_conv_to_win_path ("~/", home_dir);
+ home_dir = (char *) GNUNET_malloc (_MAX_PATH + 1);
+ plibc_conv_to_win_path ("~/", home_dir);
+ GNUNET_asprintf (&cnffile, "%s/.my.cnf", home_dir);
+ GNUNET_free (home_dir);
+ configured = GNUNET_NO;
#endif
- GNUNET_asprintf (&cnffile, "%s/.my.cnf", home_dir);
- GNUNET_free (home_dir);
- configured = GNUNET_NO;
- }
+
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Trying to use file `%s' for MySQL configuration.\n"),
- cnffile);
+ _("Trying to use file `%s' for MySQL configuration.\n"), cnffile);
if ((0 != STAT (cnffile, &st)) ||
(0 != ACCESS (cnffile, R_OK)) || (!S_ISREG (st.st_mode)))
- {
- if (configured == GNUNET_YES)
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not access file `%s': %s\n"), cnffile,
- STRERROR (errno));
- GNUNET_free (cnffile);
- return NULL;
- }
+ {
+ if (configured == GNUNET_YES)
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Could not access file `%s': %s\n"), cnffile,
+ STRERROR (errno));
+ GNUNET_free (cnffile);
+ return NULL;
+ }
return cnffile;
}
@@ -336,18 +340,18 @@ iclose (struct Plugin *plugin)
struct GNUNET_MysqlStatementHandle *s;
for (s = plugin->shead; s != NULL; s = s->next)
+ {
+ if (s->valid)
{
- if (s->valid)
- {
- mysql_stmt_close (s->statement);
- s->valid = GNUNET_NO;
- }
+ mysql_stmt_close (s->statement);
+ s->valid = GNUNET_NO;
}
+ }
if (plugin->dbf != NULL)
- {
- mysql_close (plugin->dbf);
- plugin->dbf = NULL;
- }
+ {
+ mysql_close (plugin->dbf);
+ plugin->dbf = NULL;
+ }
return GNUNET_OK;
}
@@ -378,75 +382,79 @@ iopen (struct Plugin *plugin)
mysql_options (plugin->dbf, MYSQL_READ_DEFAULT_GROUP, "client");
reconnect = 0;
mysql_options (plugin->dbf, MYSQL_OPT_RECONNECT, &reconnect);
- timeout = 120; /* in seconds */
+ timeout = 120; /* in seconds */
mysql_options (plugin->dbf,
MYSQL_OPT_CONNECT_TIMEOUT, (const void *) &timeout);
- mysql_options(plugin->dbf, MYSQL_SET_CHARSET_NAME, "UTF8");
- timeout = 60; /* in seconds */
+ mysql_options (plugin->dbf, MYSQL_SET_CHARSET_NAME, "UTF8");
+ timeout = 60; /* in seconds */
mysql_options (plugin->dbf, MYSQL_OPT_READ_TIMEOUT, (const void *) &timeout);
mysql_options (plugin->dbf, MYSQL_OPT_WRITE_TIMEOUT, (const void *) &timeout);
mysql_dbname = NULL;
if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg,
- "datastore-mysql", "DATABASE"))
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
- "datastore-mysql", "DATABASE",
- &mysql_dbname));
+ "datastore-mysql",
+ "DATABASE"))
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
+ "datastore-mysql",
+ "DATABASE",
+ &mysql_dbname));
else
mysql_dbname = GNUNET_strdup ("gnunet");
mysql_user = NULL;
if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg,
- "datastore-mysql", "USER"))
- {
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
- "datastore-mysql", "USER",
- &mysql_user));
- }
+ "datastore-mysql", "USER"))
+ {
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
+ "datastore-mysql",
+ "USER", &mysql_user));
+ }
mysql_password = NULL;
if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg,
- "datastore-mysql", "PASSWORD"))
- {
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
- "datastore-mysql", "PASSWORD",
- &mysql_password));
- }
+ "datastore-mysql",
+ "PASSWORD"))
+ {
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
+ "datastore-mysql",
+ "PASSWORD",
+ &mysql_password));
+ }
mysql_server = NULL;
if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg,
- "datastore-mysql", "HOST"))
- {
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
- "datastore-mysql", "HOST",
- &mysql_server));
- }
+ "datastore-mysql", "HOST"))
+ {
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
+ "datastore-mysql",
+ "HOST",
+ &mysql_server));
+ }
mysql_port = 0;
if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg,
- "datastore-mysql", "PORT"))
- {
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg, "datastore-mysql",
- "PORT", &mysql_port));
- }
+ "datastore-mysql", "PORT"))
+ {
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg,
+ "datastore-mysql",
+ "PORT", &mysql_port));
+ }
GNUNET_assert (mysql_dbname != NULL);
- mysql_real_connect (plugin->dbf,
- mysql_server,
- mysql_user, mysql_password,
- mysql_dbname,
- (unsigned int) mysql_port, NULL,
- CLIENT_IGNORE_SIGPIPE);
+ mysql_real_connect (plugin->dbf,
+ mysql_server,
+ mysql_user, mysql_password,
+ mysql_dbname,
+ (unsigned int) mysql_port, NULL, CLIENT_IGNORE_SIGPIPE);
GNUNET_free_non_null (mysql_server);
GNUNET_free_non_null (mysql_user);
GNUNET_free_non_null (mysql_password);
GNUNET_free (mysql_dbname);
if (mysql_error (plugin->dbf)[0])
- {
- LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR,
- "mysql_real_connect", plugin);
- return GNUNET_SYSERR;
- }
+ {
+ LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR, "mysql_real_connect", plugin);
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -459,19 +467,17 @@ iopen (struct Plugin *plugin)
* @return GNUNET_OK on success, GNUNET_SYSERR on error
*/
static int
-run_statement (struct Plugin *plugin,
- const char *statement)
+run_statement (struct Plugin *plugin, const char *statement)
{
if ((NULL == plugin->dbf) && (GNUNET_OK != iopen (plugin)))
return GNUNET_SYSERR;
mysql_query (plugin->dbf, statement);
if (mysql_error (plugin->dbf)[0])
- {
- LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR,
- "mysql_query", plugin);
- iclose (plugin);
- return GNUNET_SYSERR;
- }
+ {
+ LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR, "mysql_query", plugin);
+ iclose (plugin);
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -484,16 +490,13 @@ run_statement (struct Plugin *plugin,
* @return NULL on error
*/
static struct GNUNET_MysqlStatementHandle *
-prepared_statement_create (struct Plugin *plugin,
- const char *statement)
+prepared_statement_create (struct Plugin *plugin, const char *statement)
{
struct GNUNET_MysqlStatementHandle *ret;
ret = GNUNET_malloc (sizeof (struct GNUNET_MysqlStatementHandle));
ret->query = GNUNET_strdup (statement);
- GNUNET_CONTAINER_DLL_insert (plugin->shead,
- plugin->stail,
- ret);
+ GNUNET_CONTAINER_DLL_insert (plugin->shead, plugin->stail, ret);
return ret;
}
@@ -506,36 +509,30 @@ prepared_statement_create (struct Plugin *plugin,
* @return GNUNET_OK on success
*/
static int
-prepare_statement (struct Plugin *plugin,
- struct GNUNET_MysqlStatementHandle *ret)
+prepare_statement (struct Plugin *plugin,
+ struct GNUNET_MysqlStatementHandle *ret)
{
if (GNUNET_YES == ret->valid)
return GNUNET_OK;
- if ((NULL == plugin->dbf) &&
- (GNUNET_OK != iopen (plugin)))
+ if ((NULL == plugin->dbf) && (GNUNET_OK != iopen (plugin)))
return GNUNET_SYSERR;
ret->statement = mysql_stmt_init (plugin->dbf);
if (ret->statement == NULL)
- {
- iclose (plugin);
- return GNUNET_SYSERR;
- }
- if (mysql_stmt_prepare (ret->statement,
- ret->query,
- strlen (ret->query)))
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
- "mysql",
- _("Failed to prepare statement `%s'\n"),
- ret->query);
- LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR,
- "mysql_stmt_prepare",
- plugin);
- mysql_stmt_close (ret->statement);
- ret->statement = NULL;
- iclose (plugin);
- return GNUNET_SYSERR;
- }
+ {
+ iclose (plugin);
+ return GNUNET_SYSERR;
+ }
+ if (mysql_stmt_prepare (ret->statement, ret->query, strlen (ret->query)))
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "mysql",
+ _("Failed to prepare statement `%s'\n"), ret->query);
+ LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR, "mysql_stmt_prepare", plugin);
+ mysql_stmt_close (ret->statement);
+ ret->statement = NULL;
+ iclose (plugin);
+ return GNUNET_SYSERR;
+ }
ret->valid = GNUNET_YES;
return GNUNET_OK;
@@ -553,8 +550,7 @@ prepare_statement (struct Plugin *plugin,
*/
static int
init_params (struct Plugin *plugin,
- struct GNUNET_MysqlStatementHandle *s,
- va_list ap)
+ struct GNUNET_MysqlStatementHandle *s, va_list ap)
{
MYSQL_BIND qbind[MAX_PARAM];
unsigned int pc;
@@ -563,69 +559,72 @@ init_params (struct Plugin *plugin,
pc = mysql_stmt_param_count (s->statement);
if (pc > MAX_PARAM)
- {
- /* increase internal constant! */
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
+ {
+ /* increase internal constant! */
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
memset (qbind, 0, sizeof (qbind));
off = 0;
ft = 0;
while ((pc > 0) && (-1 != (int) (ft = va_arg (ap, enum enum_field_types))))
+ {
+ qbind[off].buffer_type = ft;
+ switch (ft)
{
- qbind[off].buffer_type = ft;
- switch (ft)
- {
- case MYSQL_TYPE_FLOAT:
- qbind[off].buffer = va_arg (ap, float *);
- break;
- case MYSQL_TYPE_LONGLONG:
- qbind[off].buffer = va_arg (ap, unsigned long long *);
- qbind[off].is_unsigned = va_arg (ap, int);
- break;
- case MYSQL_TYPE_LONG:
- qbind[off].buffer = va_arg (ap, unsigned int *);
- qbind[off].is_unsigned = va_arg (ap, int);
- break;
- case MYSQL_TYPE_VAR_STRING:
- case MYSQL_TYPE_STRING:
- case MYSQL_TYPE_BLOB:
- qbind[off].buffer = va_arg (ap, void *);
- qbind[off].buffer_length = va_arg (ap, unsigned long);
- qbind[off].length = va_arg (ap, unsigned long *);
- break;
- default:
- /* unsupported type */
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- pc--;
- off++;
- }
- if (! ( (pc == 0) && (-1 != (int) ft) && (va_arg (ap, int) == -1) ) )
- {
- GNUNET_assert (0);
+ case MYSQL_TYPE_FLOAT:
+ qbind[off].buffer = va_arg (ap, float *);
+
+ break;
+ case MYSQL_TYPE_LONGLONG:
+ qbind[off].buffer = va_arg (ap, unsigned long long *);
+ qbind[off].is_unsigned = va_arg (ap, int);
+
+ break;
+ case MYSQL_TYPE_LONG:
+ qbind[off].buffer = va_arg (ap, unsigned int *);
+ qbind[off].is_unsigned = va_arg (ap, int);
+
+ break;
+ case MYSQL_TYPE_VAR_STRING:
+ case MYSQL_TYPE_STRING:
+ case MYSQL_TYPE_BLOB:
+ qbind[off].buffer = va_arg (ap, void *);
+ qbind[off].buffer_length = va_arg (ap, unsigned long);
+ qbind[off].length = va_arg (ap, unsigned long *);
+
+ break;
+ default:
+ /* unsupported type */
+ GNUNET_break (0);
return GNUNET_SYSERR;
}
+ pc--;
+ off++;
+ }
+ if (!((pc == 0) && (-1 != (int) ft) && (va_arg (ap, int) == -1)))
+ {
+ GNUNET_assert (0);
+ return GNUNET_SYSERR;
+ }
if (mysql_stmt_bind_param (s->statement, qbind))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("`%s' failed at %s:%d with error: %s\n"),
- "mysql_stmt_bind_param",
- __FILE__, __LINE__, mysql_stmt_error (s->statement));
- iclose (plugin);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("`%s' failed at %s:%d with error: %s\n"),
+ "mysql_stmt_bind_param",
+ __FILE__, __LINE__, mysql_stmt_error (s->statement));
+ iclose (plugin);
+ return GNUNET_SYSERR;
+ }
if (mysql_stmt_execute (s->statement))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("`%s' for `%s' failed at %s:%d with error: %s\n"),
- "mysql_stmt_execute",
- s->query,
- __FILE__, __LINE__, mysql_stmt_error (s->statement));
- iclose (plugin);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("`%s' for `%s' failed at %s:%d with error: %s\n"),
+ "mysql_stmt_execute",
+ s->query, __FILE__, __LINE__, mysql_stmt_error (s->statement));
+ iclose (plugin);
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -645,51 +644,50 @@ init_params (struct Plugin *plugin,
*/
static int
prepared_statement_run_select_va (struct Plugin *plugin,
- struct GNUNET_MysqlStatementHandle *s,
- unsigned int result_size,
- MYSQL_BIND *results,
- va_list ap)
+ struct GNUNET_MysqlStatementHandle *s,
+ unsigned int result_size,
+ MYSQL_BIND * results, va_list ap)
{
int ret;
unsigned int rsize;
if (GNUNET_OK != prepare_statement (plugin, s))
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
if (GNUNET_OK != init_params (plugin, s, ap))
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
rsize = mysql_stmt_field_count (s->statement);
if (rsize > result_size)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
if (mysql_stmt_bind_result (s->statement, results))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("`%s' failed at %s:%d with error: %s\n"),
- "mysql_stmt_bind_result",
- __FILE__, __LINE__, mysql_stmt_error (s->statement));
- iclose (plugin);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("`%s' failed at %s:%d with error: %s\n"),
+ "mysql_stmt_bind_result",
+ __FILE__, __LINE__, mysql_stmt_error (s->statement));
+ iclose (plugin);
+ return GNUNET_SYSERR;
+ }
ret = mysql_stmt_fetch (s->statement);
if (ret == MYSQL_NO_DATA)
return GNUNET_NO;
if (ret != 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("`%s' failed at %s:%d with error: %s\n"),
- "mysql_stmt_fetch",
- __FILE__, __LINE__, mysql_stmt_error (s->statement));
- iclose (plugin);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("`%s' failed at %s:%d with error: %s\n"),
+ "mysql_stmt_fetch",
+ __FILE__, __LINE__, mysql_stmt_error (s->statement));
+ iclose (plugin);
+ return GNUNET_SYSERR;
+ }
mysql_stmt_reset (s->statement);
return GNUNET_OK;
}
@@ -711,18 +709,15 @@ prepared_statement_run_select_va (struct Plugin *plugin,
*/
static int
prepared_statement_run_select (struct Plugin *plugin,
- struct GNUNET_MysqlStatementHandle *s,
- unsigned int result_size,
- MYSQL_BIND *results,
- ...)
+ struct GNUNET_MysqlStatementHandle *s,
+ unsigned int result_size,
+ MYSQL_BIND * results, ...)
{
va_list ap;
int ret;
va_start (ap, results);
- ret = prepared_statement_run_select_va (plugin, s,
- result_size, results,
- ap);
+ ret = prepared_statement_run_select_va (plugin, s, result_size, results, ap);
va_end (ap);
return ret;
}
@@ -743,8 +738,8 @@ prepared_statement_run_select (struct Plugin *plugin,
*/
static int
prepared_statement_run (struct Plugin *plugin,
- struct GNUNET_MysqlStatementHandle *s,
- unsigned long long *insert_id, ...)
+ struct GNUNET_MysqlStatementHandle *s,
+ unsigned long long *insert_id, ...)
{
va_list ap;
int affected;
@@ -753,10 +748,10 @@ prepared_statement_run (struct Plugin *plugin,
return GNUNET_SYSERR;
va_start (ap, insert_id);
if (GNUNET_OK != init_params (plugin, s, ap))
- {
- va_end (ap);
- return GNUNET_SYSERR;
- }
+ {
+ va_end (ap);
+ return GNUNET_SYSERR;
+ }
va_end (ap);
affected = mysql_stmt_affected_rows (s->statement);
if (NULL != insert_id)
@@ -774,26 +769,22 @@ prepared_statement_run (struct Plugin *plugin,
* @return GNUNET_OK on success, GNUNET_NO if no such value exists, GNUNET_SYSERR on error
*/
static int
-do_delete_entry (struct Plugin *plugin,
- unsigned long long uid)
+do_delete_entry (struct Plugin *plugin, unsigned long long uid)
{
int ret;
-
+
#if DEBUG_MYSQL
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Deleting value %llu from gn090 table\n",
- uid);
+ "Deleting value %llu from gn090 table\n", uid);
#endif
ret = prepared_statement_run (plugin,
- plugin->delete_entry_by_uid,
- NULL,
- MYSQL_TYPE_LONGLONG, &uid, GNUNET_YES,
- -1);
+ plugin->delete_entry_by_uid,
+ NULL,
+ MYSQL_TYPE_LONGLONG, &uid, GNUNET_YES, -1);
if (ret >= 0)
return GNUNET_OK;
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Deleting value %llu from gn090 table failed\n",
- uid);
+ "Deleting value %llu from gn090 table failed\n", uid);
return ret;
}
@@ -817,11 +808,8 @@ mysql_plugin_estimate_size (void *cls)
cbind[0].buffer_type = MYSQL_TYPE_LONGLONG;
cbind[0].buffer = &total;
cbind[0].is_unsigned = GNUNET_NO;
- if (GNUNET_OK !=
- prepared_statement_run_select (plugin,
- plugin->get_size,
- 1, cbind,
- -1))
+ if (GNUNET_OK !=
+ prepared_statement_run_select (plugin, plugin->get_size, 1, cbind, -1))
return 0;
return total;
}
@@ -844,61 +832,58 @@ mysql_plugin_estimate_size (void *cls)
*/
static int
mysql_plugin_put (void *cls,
- const GNUNET_HashCode * key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- uint32_t replication,
- struct GNUNET_TIME_Absolute expiration,
- char **msg)
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ uint32_t replication,
+ struct GNUNET_TIME_Absolute expiration, char **msg)
{
struct Plugin *plugin = cls;
unsigned int irepl = replication;
unsigned int ipriority = priority;
unsigned int ianonymity = anonymity;
unsigned long long lexpiration = expiration.abs_value;
- unsigned long long lrvalue = (unsigned long long) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
- UINT64_MAX);
+ unsigned long long lrvalue =
+ (unsigned long long) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
+ UINT64_MAX);
unsigned long hashSize;
unsigned long hashSize2;
unsigned long lsize;
GNUNET_HashCode vhash;
if (size > MAX_DATUM_SIZE)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
hashSize = sizeof (GNUNET_HashCode);
hashSize2 = sizeof (GNUNET_HashCode);
lsize = size;
GNUNET_CRYPTO_hash (data, size, &vhash);
if (GNUNET_OK !=
prepared_statement_run (plugin,
- plugin->insert_entry,
- NULL,
- MYSQL_TYPE_LONG, &irepl, GNUNET_YES,
- MYSQL_TYPE_LONG, &type, GNUNET_YES,
- MYSQL_TYPE_LONG, &ipriority, GNUNET_YES,
- MYSQL_TYPE_LONG, &ianonymity, GNUNET_YES,
- MYSQL_TYPE_LONGLONG, &lexpiration, GNUNET_YES,
- MYSQL_TYPE_LONGLONG, &lrvalue, GNUNET_YES,
- MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
- MYSQL_TYPE_BLOB, &vhash, hashSize2, &hashSize2,
- MYSQL_TYPE_BLOB, data, lsize, &lsize,
- -1))
- return GNUNET_SYSERR;
+ plugin->insert_entry,
+ NULL,
+ MYSQL_TYPE_LONG, &irepl, GNUNET_YES,
+ MYSQL_TYPE_LONG, &type, GNUNET_YES,
+ MYSQL_TYPE_LONG, &ipriority, GNUNET_YES,
+ MYSQL_TYPE_LONG, &ianonymity, GNUNET_YES,
+ MYSQL_TYPE_LONGLONG, &lexpiration, GNUNET_YES,
+ MYSQL_TYPE_LONGLONG, &lrvalue, GNUNET_YES,
+ MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
+ MYSQL_TYPE_BLOB, &vhash, hashSize2, &hashSize2,
+ MYSQL_TYPE_BLOB, data, lsize, &lsize, -1))
+ return GNUNET_SYSERR;
#if DEBUG_MYSQL
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Inserted value `%s' with size %u into gn090 table\n",
- GNUNET_h2s (key),
- (unsigned int) size);
+ "Inserted value `%s' with size %u into gn090 table\n",
+ GNUNET_h2s (key), (unsigned int) size);
#endif
if (size > 0)
- plugin->env->duc (plugin->env->cls,
- size);
+ plugin->env->duc (plugin->env->cls, size);
return GNUNET_OK;
}
@@ -928,10 +913,8 @@ mysql_plugin_put (void *cls,
*/
static int
mysql_plugin_update (void *cls,
- uint64_t uid,
- int delta,
- struct GNUNET_TIME_Absolute expire,
- char **msg)
+ uint64_t uid,
+ int delta, struct GNUNET_TIME_Absolute expire, char **msg)
{
struct Plugin *plugin = cls;
unsigned long long vkey = uid;
@@ -940,25 +923,21 @@ mysql_plugin_update (void *cls,
#if DEBUG_MYSQL
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Updating value %llu adding %d to priority and maxing exp at %llu\n",
- vkey,
- delta,
- lexpire);
+ "Updating value %llu adding %d to priority and maxing exp at %llu\n",
+ vkey, delta, lexpire);
#endif
ret = prepared_statement_run (plugin,
- plugin->update_entry,
- NULL,
- MYSQL_TYPE_LONG, &delta, GNUNET_NO,
- MYSQL_TYPE_LONGLONG, &lexpire, GNUNET_YES,
- MYSQL_TYPE_LONGLONG, &lexpire, GNUNET_YES,
- MYSQL_TYPE_LONGLONG, &vkey, GNUNET_YES,
- -1);
+ plugin->update_entry,
+ NULL,
+ MYSQL_TYPE_LONG, &delta, GNUNET_NO,
+ MYSQL_TYPE_LONGLONG, &lexpire, GNUNET_YES,
+ MYSQL_TYPE_LONGLONG, &lexpire, GNUNET_YES,
+ MYSQL_TYPE_LONGLONG, &vkey, GNUNET_YES, -1);
if (ret != GNUNET_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to update value %llu\n",
- vkey);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to update value %llu\n", vkey);
+ }
return ret;
}
@@ -973,11 +952,10 @@ mysql_plugin_update (void *cls,
* @param proc_cls closure for proc
* @param ... arguments to initialize stmt
*/
-static void
+static void
execute_select (struct Plugin *plugin,
- struct GNUNET_MysqlStatementHandle *stmt,
- PluginDatumProcessor proc, void *proc_cls,
- ...)
+ struct GNUNET_MysqlStatementHandle *stmt,
+ PluginDatumProcessor proc, void *proc_cls, ...)
{
va_list ap;
int ret;
@@ -1020,51 +998,36 @@ execute_select (struct Plugin *plugin,
rbind[6].is_unsigned = 1;
va_start (ap, proc_cls);
- ret = prepared_statement_run_select_va (plugin,
- stmt,
- 7, rbind,
- ap);
+ ret = prepared_statement_run_select_va (plugin, stmt, 7, rbind, ap);
va_end (ap);
if (ret <= 0)
- {
- proc (proc_cls,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
- GNUNET_assert (size <= sizeof(value));
- if ( (rbind[4].buffer_length != sizeof (GNUNET_HashCode)) ||
- (hashSize != sizeof (GNUNET_HashCode)) )
- {
- GNUNET_break (0);
- proc (proc_cls,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
+ {
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
+ GNUNET_assert (size <= sizeof (value));
+ if ((rbind[4].buffer_length != sizeof (GNUNET_HashCode)) ||
+ (hashSize != sizeof (GNUNET_HashCode)))
+ {
+ GNUNET_break (0);
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
#if DEBUG_MYSQL
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Found %u-byte value under key `%s' with prio %u, anon %u, expire %llu selecting from gn090 table\n",
- (unsigned int) size,
- GNUNET_h2s (&key),
- priority,
- anonymity,
- exp);
+ "Found %u-byte value under key `%s' with prio %u, anon %u, expire %llu selecting from gn090 table\n",
+ (unsigned int) size, GNUNET_h2s (&key), priority, anonymity, exp);
#endif
GNUNET_assert (size < MAX_DATUM_SIZE);
expiration.abs_value = exp;
- ret = proc (proc_cls,
- &key,
- size, value,
- type, priority, anonymity, expiration,
- uid);
+ ret = proc (proc_cls,
+ &key, size, value, type, priority, anonymity, expiration, uid);
if (ret == GNUNET_NO)
- {
- do_delete_entry (plugin, uid);
- if (size != 0)
- plugin->env->duc (plugin->env->cls,
- - size);
- }
+ {
+ do_delete_entry (plugin, uid);
+ if (size != 0)
+ plugin->env->duc (plugin->env->cls, -size);
+ }
}
@@ -1089,11 +1052,11 @@ execute_select (struct Plugin *plugin,
*/
static void
mysql_plugin_get_key (void *cls,
- uint64_t offset,
- const GNUNET_HashCode *key,
- const GNUNET_HashCode *vhash,
- enum GNUNET_BLOCK_Type type,
- PluginDatumProcessor proc, void *proc_cls)
+ uint64_t offset,
+ const GNUNET_HashCode * key,
+ const GNUNET_HashCode * vhash,
+ enum GNUNET_BLOCK_Type type,
+ PluginDatumProcessor proc, void *proc_cls)
{
struct Plugin *plugin = cls;
int ret;
@@ -1113,115 +1076,107 @@ mysql_plugin_get_key (void *cls,
cbind[0].buffer = &total;
cbind[0].is_unsigned = GNUNET_NO;
if (type != 0)
+ {
+ if (vhash != NULL)
{
- if (vhash != NULL)
- {
- ret =
- prepared_statement_run_select (plugin,
- plugin->count_entry_by_hash_vhash_and_type,
- 1, cbind,
- MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
- MYSQL_TYPE_BLOB, vhash, hashSize2, &hashSize2,
- MYSQL_TYPE_LONG, &type, GNUNET_YES,
- -1);
- }
- else
- {
- ret =
- prepared_statement_run_select (plugin,
- plugin->count_entry_by_hash_and_type,
- 1, cbind,
- MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
- MYSQL_TYPE_LONG, &type, GNUNET_YES,
- -1);
- }
+ ret =
+ prepared_statement_run_select (plugin,
+ plugin->
+ count_entry_by_hash_vhash_and_type, 1,
+ cbind, MYSQL_TYPE_BLOB, key, hashSize,
+ &hashSize, MYSQL_TYPE_BLOB, vhash,
+ hashSize2, &hashSize2, MYSQL_TYPE_LONG,
+ &type, GNUNET_YES, -1);
}
+ else
+ {
+ ret =
+ prepared_statement_run_select (plugin,
+ plugin->count_entry_by_hash_and_type,
+ 1, cbind,
+ MYSQL_TYPE_BLOB, key, hashSize,
+ &hashSize, MYSQL_TYPE_LONG, &type,
+ GNUNET_YES, -1);
+ }
+ }
else
+ {
+ if (vhash != NULL)
{
- if (vhash != NULL)
- {
- ret =
- prepared_statement_run_select (plugin,
- plugin->count_entry_by_hash_and_vhash,
- 1, cbind,
- MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
- MYSQL_TYPE_BLOB, vhash, hashSize2, &hashSize2,
- -1);
-
- }
- else
- {
- ret =
- prepared_statement_run_select (plugin,
- plugin->count_entry_by_hash,
- 1, cbind,
- MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
- -1);
- }
+ ret =
+ prepared_statement_run_select (plugin,
+ plugin->count_entry_by_hash_and_vhash,
+ 1, cbind,
+ MYSQL_TYPE_BLOB, key, hashSize,
+ &hashSize, MYSQL_TYPE_BLOB, vhash,
+ hashSize2, &hashSize2, -1);
+
}
- if ((ret != GNUNET_OK) || (0 >= total))
+ else
{
- proc (proc_cls,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
+ ret =
+ prepared_statement_run_select (plugin,
+ plugin->count_entry_by_hash,
+ 1, cbind,
+ MYSQL_TYPE_BLOB, key, hashSize,
+ &hashSize, -1);
}
+ }
+ if ((ret != GNUNET_OK) || (0 >= total))
+ {
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
offset = offset % total;
off = (unsigned long long) offset;
#if DEBUG_MYSQL
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Obtaining %llu/%lld result for GET `%s'\n",
- off,
- total,
- GNUNET_h2s (key));
+ "Obtaining %llu/%lld result for GET `%s'\n",
+ off, total, GNUNET_h2s (key));
#endif
if (type != GNUNET_BLOCK_TYPE_ANY)
+ {
+ if (NULL != vhash)
{
- if (NULL != vhash)
- {
- execute_select (plugin,
- plugin->select_entry_by_hash_vhash_and_type,
- proc, proc_cls,
- MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
- MYSQL_TYPE_BLOB, vhash, hashSize, &hashSize,
- MYSQL_TYPE_LONG, &type, GNUNET_YES,
- MYSQL_TYPE_LONGLONG, &off, GNUNET_YES,
- -1);
- }
- else
- {
- execute_select (plugin,
- plugin->select_entry_by_hash_and_type,
- proc, proc_cls,
- MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
- MYSQL_TYPE_LONG, &type, GNUNET_YES,
- MYSQL_TYPE_LONGLONG, &off, GNUNET_YES,
- -1);
- }
+ execute_select (plugin,
+ plugin->select_entry_by_hash_vhash_and_type,
+ proc, proc_cls,
+ MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
+ MYSQL_TYPE_BLOB, vhash, hashSize, &hashSize,
+ MYSQL_TYPE_LONG, &type, GNUNET_YES,
+ MYSQL_TYPE_LONGLONG, &off, GNUNET_YES, -1);
+ }
+ else
+ {
+ execute_select (plugin,
+ plugin->select_entry_by_hash_and_type,
+ proc, proc_cls,
+ MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
+ MYSQL_TYPE_LONG, &type, GNUNET_YES,
+ MYSQL_TYPE_LONGLONG, &off, GNUNET_YES, -1);
}
+ }
else
+ {
+ if (NULL != vhash)
{
- if (NULL != vhash)
- {
- execute_select (plugin,
- plugin->select_entry_by_hash_and_vhash,
- proc, proc_cls,
- MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
- MYSQL_TYPE_BLOB, vhash, hashSize, &hashSize,
- MYSQL_TYPE_LONGLONG, &off, GNUNET_YES,
- -1);
- }
- else
- {
- execute_select (plugin,
- plugin->select_entry_by_hash,
- proc, proc_cls,
- MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
- MYSQL_TYPE_LONGLONG, &off, GNUNET_YES,
- -1);
- }
+ execute_select (plugin,
+ plugin->select_entry_by_hash_and_vhash,
+ proc, proc_cls,
+ MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
+ MYSQL_TYPE_BLOB, vhash, hashSize, &hashSize,
+ MYSQL_TYPE_LONGLONG, &off, GNUNET_YES, -1);
}
+ else
+ {
+ execute_select (plugin,
+ plugin->select_entry_by_hash,
+ proc, proc_cls,
+ MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
+ MYSQL_TYPE_LONGLONG, &off, GNUNET_YES, -1);
+ }
+ }
}
@@ -1237,21 +1192,22 @@ mysql_plugin_get_key (void *cls,
*/
static void
mysql_plugin_get_zero_anonymity (void *cls,
- uint64_t offset,
- enum GNUNET_BLOCK_Type type,
- PluginDatumProcessor proc, void *proc_cls)
+ uint64_t offset,
+ enum GNUNET_BLOCK_Type type,
+ PluginDatumProcessor proc, void *proc_cls)
{
struct Plugin *plugin = cls;
- unsigned long long rvalue = (unsigned long long) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
- UINT64_MAX);
+ unsigned long long rvalue =
+ (unsigned long long) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
+ UINT64_MAX);
+
execute_select (plugin,
- plugin->zero_iter,
- proc, proc_cls,
- MYSQL_TYPE_LONG, &type, GNUNET_YES,
- MYSQL_TYPE_LONGLONG, &rvalue, GNUNET_YES,
- MYSQL_TYPE_LONG, &type, GNUNET_YES,
- MYSQL_TYPE_LONGLONG, &rvalue, GNUNET_YES,
- -1);
+ plugin->zero_iter,
+ proc, proc_cls,
+ MYSQL_TYPE_LONG, &type, GNUNET_YES,
+ MYSQL_TYPE_LONGLONG, &rvalue, GNUNET_YES,
+ MYSQL_TYPE_LONG, &type, GNUNET_YES,
+ MYSQL_TYPE_LONGLONG, &rvalue, GNUNET_YES, -1);
}
@@ -1260,17 +1216,17 @@ mysql_plugin_get_zero_anonymity (void *cls,
*/
struct ReplCtx
{
-
+
/**
* Plugin handle.
*/
struct Plugin *plugin;
-
+
/**
* Function to call for the result (or the NULL).
*/
PluginDatumProcessor proc;
-
+
/**
* Closure for proc.
*/
@@ -1300,14 +1256,13 @@ struct ReplCtx
*/
static int
repl_proc (void *cls,
- const GNUNET_HashCode *key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute expiration,
- uint64_t uid)
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct ReplCtx *rc = cls;
struct Plugin *plugin = rc->plugin;
@@ -1316,25 +1271,21 @@ repl_proc (void *cls,
int iret;
ret = rc->proc (rc->proc_cls,
- key,
- size, data,
- type, priority, anonymity, expiration,
- uid);
+ key, size, data, type, priority, anonymity, expiration, uid);
if (NULL != key)
+ {
+ oid = (unsigned long long) uid;
+ iret = prepared_statement_run (plugin,
+ plugin->dec_repl,
+ NULL,
+ MYSQL_TYPE_LONGLONG, &oid, GNUNET_YES, -1);
+ if (iret == GNUNET_SYSERR)
{
- oid = (unsigned long long) uid;
- iret = prepared_statement_run (plugin,
- plugin->dec_repl,
- NULL,
- MYSQL_TYPE_LONGLONG, &oid, GNUNET_YES,
- -1);
- if (iret == GNUNET_SYSERR)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to reduce replication counter\n");
- return GNUNET_SYSERR;
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to reduce replication counter\n");
+ return GNUNET_SYSERR;
}
+ }
return ret;
}
@@ -1352,14 +1303,14 @@ repl_proc (void *cls,
*/
static void
mysql_plugin_get_replication (void *cls,
- PluginDatumProcessor proc, void *proc_cls)
+ PluginDatumProcessor proc, void *proc_cls)
{
struct Plugin *plugin = cls;
struct ReplCtx rc;
unsigned long long rvalue;
unsigned long repl;
MYSQL_BIND results;
-
+
rc.plugin = plugin;
rc.proc = proc;
rc.proc_cls = proc_cls;
@@ -1369,28 +1320,19 @@ mysql_plugin_get_replication (void *cls,
results.is_unsigned = GNUNET_YES;
if (1 !=
- prepared_statement_run_select (plugin,
- plugin->max_repl,
- 1,
- &results,
- -1))
- {
- proc (proc_cls,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
-
- rvalue = (unsigned long long) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
- UINT64_MAX);
- execute_select (plugin,
- plugin->select_replication,
- &repl_proc, &rc,
- MYSQL_TYPE_LONG, &repl, GNUNET_YES,
- MYSQL_TYPE_LONGLONG, &rvalue, GNUNET_YES,
- MYSQL_TYPE_LONG, &repl, GNUNET_YES,
- MYSQL_TYPE_LONGLONG, &rvalue, GNUNET_YES,
- -1);
+ prepared_statement_run_select (plugin, plugin->max_repl, 1, &results, -1))
+ {
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
+
+ rvalue =
+ (unsigned long long) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
+ UINT64_MAX);
+ execute_select (plugin, plugin->select_replication, &repl_proc, &rc,
+ MYSQL_TYPE_LONG, &repl, GNUNET_YES, MYSQL_TYPE_LONGLONG,
+ &rvalue, GNUNET_YES, MYSQL_TYPE_LONG, &repl, GNUNET_YES,
+ MYSQL_TYPE_LONGLONG, &rvalue, GNUNET_YES, -1);
}
@@ -1400,17 +1342,17 @@ mysql_plugin_get_replication (void *cls,
*/
struct ExpiCtx
{
-
+
/**
* Plugin handle.
*/
struct Plugin *plugin;
-
+
/**
* Function to call for the result (or the NULL).
*/
PluginDatumProcessor proc;
-
+
/**
* Closure for proc.
*/
@@ -1441,31 +1383,25 @@ struct ExpiCtx
*/
static int
expi_proc (void *cls,
- const GNUNET_HashCode *key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute expiration,
- uint64_t uid)
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct ExpiCtx *rc = cls;
struct Plugin *plugin = rc->plugin;
-
+
if (NULL == key)
- {
- execute_select (plugin,
- plugin->select_priority,
- rc->proc, rc->proc_cls,
- -1);
- return GNUNET_SYSERR;
- }
+ {
+ execute_select (plugin,
+ plugin->select_priority, rc->proc, rc->proc_cls, -1);
+ return GNUNET_SYSERR;
+ }
return rc->proc (rc->proc_cls,
- key,
- size, data,
- type, priority, anonymity, expiration,
- uid);
+ key, size, data, type, priority, anonymity, expiration, uid);
}
@@ -1479,21 +1415,19 @@ expi_proc (void *cls,
*/
static void
mysql_plugin_get_expiration (void *cls,
- PluginDatumProcessor proc, void *proc_cls)
+ PluginDatumProcessor proc, void *proc_cls)
{
struct Plugin *plugin = cls;
long long nt;
struct ExpiCtx rc;
-
+
rc.plugin = plugin;
rc.proc = proc;
rc.proc_cls = proc_cls;
- nt = (long long) GNUNET_TIME_absolute_get().abs_value;
+ nt = (long long) GNUNET_TIME_absolute_get ().abs_value;
execute_select (plugin,
- plugin->select_expiration,
- expi_proc, &rc,
- MYSQL_TYPE_LONGLONG, &nt, GNUNET_YES,
- -1);
+ plugin->select_expiration,
+ expi_proc, &rc, MYSQL_TYPE_LONGLONG, &nt, GNUNET_YES, -1);
}
@@ -1503,14 +1437,13 @@ mysql_plugin_get_expiration (void *cls,
*
* @param cls the "struct Plugin*"
*/
-static void
+static void
mysql_plugin_drop (void *cls)
{
struct Plugin *plugin = cls;
- if (GNUNET_OK != run_statement (plugin,
- "DROP TABLE gn090"))
- return; /* error */
+ if (GNUNET_OK != run_statement (plugin, "DROP TABLE gn090"))
+ return; /* error */
plugin->env->duc (plugin->env->cls, 0);
}
@@ -1532,12 +1465,12 @@ libgnunet_plugin_datastore_mysql_init (void *cls)
plugin->env = env;
plugin->cnffile = get_my_cnf_path (env->cfg);
if (GNUNET_OK != iopen (plugin))
- {
- iclose (plugin);
- GNUNET_free_non_null (plugin->cnffile);
- GNUNET_free (plugin);
- return NULL;
- }
+ {
+ iclose (plugin);
+ GNUNET_free_non_null (plugin->cnffile);
+ GNUNET_free (plugin);
+ return NULL;
+ }
#define MRUNS(a) (GNUNET_OK != run_statement (plugin, a) )
#define PINIT(a,b) (NULL == (a = prepared_statement_create(plugin, b)))
if (MRUNS ("CREATE TABLE IF NOT EXISTS gn090 ("
@@ -1565,29 +1498,32 @@ libgnunet_plugin_datastore_mysql_init (void *cls)
PINIT (plugin->insert_entry, INSERT_ENTRY) ||
PINIT (plugin->delete_entry_by_uid, DELETE_ENTRY_BY_UID) ||
PINIT (plugin->select_entry_by_hash, SELECT_ENTRY_BY_HASH) ||
- PINIT (plugin->select_entry_by_hash_and_vhash, SELECT_ENTRY_BY_HASH_AND_VHASH)
- || PINIT (plugin->select_entry_by_hash_and_type, SELECT_ENTRY_BY_HASH_AND_TYPE)
- || PINIT (plugin->select_entry_by_hash_vhash_and_type,
- SELECT_ENTRY_BY_HASH_VHASH_AND_TYPE)
- || PINIT (plugin->count_entry_by_hash, COUNT_ENTRY_BY_HASH)
- || PINIT (plugin->get_size, SELECT_SIZE)
- || PINIT (plugin->count_entry_by_hash_and_vhash, COUNT_ENTRY_BY_HASH_AND_VHASH)
- || PINIT (plugin->count_entry_by_hash_and_type, COUNT_ENTRY_BY_HASH_AND_TYPE)
+ PINIT (plugin->select_entry_by_hash_and_vhash,
+ SELECT_ENTRY_BY_HASH_AND_VHASH) ||
+ PINIT (plugin->select_entry_by_hash_and_type,
+ SELECT_ENTRY_BY_HASH_AND_TYPE) ||
+ PINIT (plugin->select_entry_by_hash_vhash_and_type,
+ SELECT_ENTRY_BY_HASH_VHASH_AND_TYPE) ||
+ PINIT (plugin->count_entry_by_hash, COUNT_ENTRY_BY_HASH) ||
+ PINIT (plugin->get_size, SELECT_SIZE) ||
+ PINIT (plugin->count_entry_by_hash_and_vhash,
+ COUNT_ENTRY_BY_HASH_AND_VHASH) ||
+ PINIT (plugin->count_entry_by_hash_and_type, COUNT_ENTRY_BY_HASH_AND_TYPE)
|| PINIT (plugin->count_entry_by_hash_vhash_and_type,
- COUNT_ENTRY_BY_HASH_VHASH_AND_TYPE)
- || PINIT (plugin->update_entry, UPDATE_ENTRY)
- || PINIT (plugin->dec_repl, DEC_REPL)
- || PINIT (plugin->zero_iter, SELECT_IT_NON_ANONYMOUS)
- || PINIT (plugin->select_expiration, SELECT_IT_EXPIRATION)
- || PINIT (plugin->select_priority, SELECT_IT_PRIORITY)
- || PINIT (plugin->max_repl, SELECT_MAX_REPL)
- || PINIT (plugin->select_replication, SELECT_IT_REPLICATION) )
- {
- iclose (plugin);
- GNUNET_free_non_null (plugin->cnffile);
- GNUNET_free (plugin);
- return NULL;
- }
+ COUNT_ENTRY_BY_HASH_VHASH_AND_TYPE) ||
+ PINIT (plugin->update_entry, UPDATE_ENTRY) ||
+ PINIT (plugin->dec_repl, DEC_REPL) ||
+ PINIT (plugin->zero_iter, SELECT_IT_NON_ANONYMOUS) ||
+ PINIT (plugin->select_expiration, SELECT_IT_EXPIRATION) ||
+ PINIT (plugin->select_priority, SELECT_IT_PRIORITY) ||
+ PINIT (plugin->max_repl, SELECT_MAX_REPL) ||
+ PINIT (plugin->select_replication, SELECT_IT_REPLICATION))
+ {
+ iclose (plugin);
+ GNUNET_free_non_null (plugin->cnffile);
+ GNUNET_free (plugin);
+ return NULL;
+ }
#undef PINIT
#undef MRUNS
@@ -1621,13 +1557,11 @@ libgnunet_plugin_datastore_mysql_done (void *cls)
iclose (plugin);
while (NULL != (s = plugin->shead))
- {
- GNUNET_CONTAINER_DLL_remove (plugin->shead,
- plugin->stail,
- s);
- GNUNET_free (s->query);
- GNUNET_free (s);
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (plugin->shead, plugin->stail, s);
+ GNUNET_free (s->query);
+ GNUNET_free (s);
+ }
GNUNET_free_non_null (plugin->cnffile);
GNUNET_free (plugin);
GNUNET_free (api);
diff --git a/src/datastore/plugin_datastore_postgres.c b/src/datastore/plugin_datastore_postgres.c
index 056138d970..b79178dac3 100644
--- a/src/datastore/plugin_datastore_postgres.c
+++ b/src/datastore/plugin_datastore_postgres.c
@@ -46,7 +46,7 @@
/**
* Context for all functions in this plugin.
*/
-struct Plugin
+struct Plugin
{
/**
* Our execution environment.
@@ -76,27 +76,28 @@ struct Plugin
*/
static int
check_result (struct Plugin *plugin,
- PGresult * ret,
+ PGresult * ret,
int expected_status,
const char *command, const char *args, int line)
{
if (ret == NULL)
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "datastore-postgres",
- "Postgres failed to allocate result for `%s:%s' at %d\n",
- command, args, line);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "datastore-postgres",
+ "Postgres failed to allocate result for `%s:%s' at %d\n",
+ command, args, line);
+ return GNUNET_SYSERR;
+ }
if (PQresultStatus (ret) != expected_status)
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "datastore-postgres",
- _("`%s:%s' failed at %s:%d with error: %s"),
- command, args, __FILE__, line, PQerrorMessage (plugin->dbh));
- PQclear (ret);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "datastore-postgres",
+ _("`%s:%s' failed at %s:%d with error: %s"),
+ command, args, __FILE__, line,
+ PQerrorMessage (plugin->dbh));
+ PQclear (ret);
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -108,14 +109,13 @@ check_result (struct Plugin *plugin,
* @param line code line for error reporting
*/
static int
-pq_exec (struct Plugin *plugin,
- const char *sql, int line)
+pq_exec (struct Plugin *plugin, const char *sql, int line)
{
PGresult *ret;
+
ret = PQexec (plugin->dbh, sql);
if (GNUNET_OK != check_result (plugin,
- ret,
- PGRES_COMMAND_OK, "PQexec", sql, line))
+ ret, PGRES_COMMAND_OK, "PQexec", sql, line))
return GNUNET_SYSERR;
PQclear (ret);
return GNUNET_OK;
@@ -133,13 +133,13 @@ pq_exec (struct Plugin *plugin,
*/
static int
pq_prepare (struct Plugin *plugin,
- const char *name, const char *sql, int nparams, int line)
+ const char *name, const char *sql, int nparams, int line)
{
PGresult *ret;
+
ret = PQprepare (plugin->dbh, name, sql, nparams, NULL);
if (GNUNET_OK !=
- check_result (plugin,
- ret, PGRES_COMMAND_OK, "PQprepare", sql, line))
+ check_result (plugin, ret, PGRES_COMMAND_OK, "PQprepare", sql, line))
return GNUNET_SYSERR;
PQclear (ret);
return GNUNET_OK;
@@ -160,28 +160,27 @@ init_connection (struct Plugin *plugin)
/* Open database and precompile statements */
conninfo = NULL;
(void) GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
- "datastore-postgres",
- "CONFIG",
- &conninfo);
+ "datastore-postgres",
+ "CONFIG", &conninfo);
plugin->dbh = PQconnectdb (conninfo == NULL ? "" : conninfo);
if (NULL == plugin->dbh)
- {
- /* FIXME: warn about out-of-memory? */
- GNUNET_free_non_null (conninfo);
- return GNUNET_SYSERR;
- }
+ {
+ /* FIXME: warn about out-of-memory? */
+ GNUNET_free_non_null (conninfo);
+ return GNUNET_SYSERR;
+ }
if (PQstatus (plugin->dbh) != CONNECTION_OK)
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
- "datastore-postgres",
- _("Unable to initialize Postgres with configuration `%s': %s"),
- conninfo,
- PQerrorMessage (plugin->dbh));
- PQfinish (plugin->dbh);
- plugin->dbh = NULL;
- GNUNET_free_non_null (conninfo);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "datastore-postgres",
+ _
+ ("Unable to initialize Postgres with configuration `%s': %s"),
+ conninfo, PQerrorMessage (plugin->dbh));
+ PQfinish (plugin->dbh);
+ plugin->dbh = NULL;
+ GNUNET_free_non_null (conninfo);
+ return GNUNET_SYSERR;
+ }
GNUNET_free_non_null (conninfo);
ret = PQexec (plugin->dbh,
"CREATE TABLE gn090 ("
@@ -194,176 +193,169 @@ init_connection (struct Plugin *plugin)
" hash BYTEA NOT NULL DEFAULT '',"
" vhash BYTEA NOT NULL DEFAULT '',"
" value BYTEA NOT NULL DEFAULT '')" "WITH OIDS");
- if ( (ret == NULL) ||
- ( (PQresultStatus (ret) != PGRES_COMMAND_OK) &&
- (0 != strcmp ("42P07", /* duplicate table */
- PQresultErrorField
- (ret,
- PG_DIAG_SQLSTATE)))))
+ if ((ret == NULL) || ((PQresultStatus (ret) != PGRES_COMMAND_OK) && (0 != strcmp ("42P07", /* duplicate table */
+ PQresultErrorField
+ (ret,
+ PG_DIAG_SQLSTATE)))))
+ {
+ (void) check_result (plugin,
+ ret, PGRES_COMMAND_OK, "CREATE TABLE", "gn090",
+ __LINE__);
+ PQfinish (plugin->dbh);
+ plugin->dbh = NULL;
+ return GNUNET_SYSERR;
+ }
+ if (PQresultStatus (ret) == PGRES_COMMAND_OK)
+ {
+ if ((GNUNET_OK !=
+ pq_exec (plugin, "CREATE INDEX idx_hash ON gn090 (hash)", __LINE__)) ||
+ (GNUNET_OK !=
+ pq_exec (plugin, "CREATE INDEX idx_hash_vhash ON gn090 (hash,vhash)",
+ __LINE__))
+ || (GNUNET_OK !=
+ pq_exec (plugin, "CREATE INDEX idx_prio ON gn090 (prio)", __LINE__))
+ || (GNUNET_OK !=
+ pq_exec (plugin, "CREATE INDEX idx_expire ON gn090 (expire)",
+ __LINE__)) ||
+ (GNUNET_OK !=
+ pq_exec (plugin,
+ "CREATE INDEX idx_prio_anon ON gn090 (prio,anonLevel)",
+ __LINE__)) ||
+ (GNUNET_OK !=
+ pq_exec (plugin,
+ "CREATE INDEX idx_prio_hash_anon ON gn090 (prio,hash,anonLevel)",
+ __LINE__)) ||
+ (GNUNET_OK !=
+ pq_exec (plugin, "CREATE INDEX idx_repl_rvalue ON gn090 (repl,rvalue)",
+ __LINE__)) ||
+ (GNUNET_OK !=
+ pq_exec (plugin, "CREATE INDEX idx_expire_hash ON gn090 (expire,hash)",
+ __LINE__)))
{
- (void) check_result (plugin,
- ret, PGRES_COMMAND_OK, "CREATE TABLE", "gn090", __LINE__);
+ PQclear (ret);
PQfinish (plugin->dbh);
plugin->dbh = NULL;
return GNUNET_SYSERR;
}
- if (PQresultStatus (ret) == PGRES_COMMAND_OK)
- {
- if ((GNUNET_OK !=
- pq_exec (plugin, "CREATE INDEX idx_hash ON gn090 (hash)", __LINE__)) ||
- (GNUNET_OK !=
- pq_exec (plugin, "CREATE INDEX idx_hash_vhash ON gn090 (hash,vhash)",
- __LINE__))
- || (GNUNET_OK !=
- pq_exec (plugin, "CREATE INDEX idx_prio ON gn090 (prio)", __LINE__))
- || (GNUNET_OK !=
- pq_exec (plugin, "CREATE INDEX idx_expire ON gn090 (expire)", __LINE__))
- || (GNUNET_OK !=
- pq_exec (plugin, "CREATE INDEX idx_prio_anon ON gn090 (prio,anonLevel)",
- __LINE__))
- || (GNUNET_OK !=
- pq_exec
- (plugin, "CREATE INDEX idx_prio_hash_anon ON gn090 (prio,hash,anonLevel)",
- __LINE__))
- || (GNUNET_OK !=
- pq_exec
- (plugin, "CREATE INDEX idx_repl_rvalue ON gn090 (repl,rvalue)",
- __LINE__))
- || (GNUNET_OK !=
- pq_exec (plugin, "CREATE INDEX idx_expire_hash ON gn090 (expire,hash)",
- __LINE__)))
- {
- PQclear (ret);
- PQfinish (plugin->dbh);
- plugin->dbh = NULL;
- return GNUNET_SYSERR;
- }
- }
+ }
PQclear (ret);
ret = PQexec (plugin->dbh,
"ALTER TABLE gn090 ALTER value SET STORAGE EXTERNAL");
- if (GNUNET_OK !=
+ if (GNUNET_OK !=
check_result (plugin,
- ret, PGRES_COMMAND_OK,
- "ALTER TABLE", "gn090", __LINE__))
- {
- PQfinish (plugin->dbh);
- plugin->dbh = NULL;
- return GNUNET_SYSERR;
- }
+ ret, PGRES_COMMAND_OK, "ALTER TABLE", "gn090", __LINE__))
+ {
+ PQfinish (plugin->dbh);
+ plugin->dbh = NULL;
+ return GNUNET_SYSERR;
+ }
PQclear (ret);
- ret = PQexec (plugin->dbh,
- "ALTER TABLE gn090 ALTER hash SET STORAGE PLAIN");
+ ret = PQexec (plugin->dbh, "ALTER TABLE gn090 ALTER hash SET STORAGE PLAIN");
if (GNUNET_OK !=
check_result (plugin,
- ret, PGRES_COMMAND_OK,
- "ALTER TABLE", "gn090", __LINE__))
- {
- PQfinish (plugin->dbh);
- plugin->dbh = NULL;
- return GNUNET_SYSERR;
- }
+ ret, PGRES_COMMAND_OK, "ALTER TABLE", "gn090", __LINE__))
+ {
+ PQfinish (plugin->dbh);
+ plugin->dbh = NULL;
+ return GNUNET_SYSERR;
+ }
PQclear (ret);
- ret = PQexec (plugin->dbh,
- "ALTER TABLE gn090 ALTER vhash SET STORAGE PLAIN");
+ ret = PQexec (plugin->dbh, "ALTER TABLE gn090 ALTER vhash SET STORAGE PLAIN");
if (GNUNET_OK !=
check_result (plugin,
- ret, PGRES_COMMAND_OK, "ALTER TABLE", "gn090", __LINE__))
- {
- PQfinish (plugin->dbh);
- plugin->dbh = NULL;
- return GNUNET_SYSERR;
- }
+ ret, PGRES_COMMAND_OK, "ALTER TABLE", "gn090", __LINE__))
+ {
+ PQfinish (plugin->dbh);
+ plugin->dbh = NULL;
+ return GNUNET_SYSERR;
+ }
PQclear (ret);
if ((GNUNET_OK !=
pq_prepare (plugin,
- "getvt",
+ "getvt",
"SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 "
"WHERE hash=$1 AND vhash=$2 AND type=$3 "
- "ORDER BY oid ASC LIMIT 1 OFFSET $4",
+ "ORDER BY oid ASC LIMIT 1 OFFSET $4",
4,
__LINE__)) ||
(GNUNET_OK !=
pq_prepare (plugin,
- "gett",
+ "gett",
"SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 "
"WHERE hash=$1 AND type=$2 "
- "ORDER BY oid ASC LIMIT 1 OFFSET $3",
+ "ORDER BY oid ASC LIMIT 1 OFFSET $3",
3,
__LINE__)) ||
(GNUNET_OK !=
pq_prepare (plugin,
- "getv",
+ "getv",
"SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 "
"WHERE hash=$1 AND vhash=$2 "
- "ORDER BY oid ASC LIMIT 1 OFFSET $3",
+ "ORDER BY oid ASC LIMIT 1 OFFSET $3",
3,
__LINE__)) ||
(GNUNET_OK !=
pq_prepare (plugin,
- "get",
+ "get",
"SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 "
"WHERE hash=$1 "
- "ORDER BY oid ASC LIMIT 1 OFFSET $2",
+ "ORDER BY oid ASC LIMIT 1 OFFSET $2",
2,
__LINE__)) ||
(GNUNET_OK !=
pq_prepare (plugin,
- "put",
+ "put",
"INSERT INTO gn090 (repl, type, prio, anonLevel, expire, rvalue, hash, vhash, value) "
"VALUES ($1, $2, $3, $4, $5, RANDOM(), $6, $7, $8)",
9,
__LINE__)) ||
(GNUNET_OK !=
pq_prepare (plugin,
- "update",
+ "update",
"UPDATE gn090 SET prio = prio + $1, expire = CASE WHEN expire < $2 THEN $2 ELSE expire END "
"WHERE oid = $3",
3,
__LINE__)) ||
(GNUNET_OK !=
pq_prepare (plugin,
- "decrepl",
+ "decrepl",
"UPDATE gn090 SET repl = GREATEST (repl - 1, 0) "
"WHERE oid = $1",
1,
__LINE__)) ||
(GNUNET_OK !=
pq_prepare (plugin,
- "select_non_anonymous",
- "SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 "
- "WHERE anonLevel = 0 AND type = $1 ORDER BY oid DESC LIMIT 1 OFFSET $2",
+ "select_non_anonymous",
+ "SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 "
+ "WHERE anonLevel = 0 AND type = $1 ORDER BY oid DESC LIMIT 1 OFFSET $2",
1,
__LINE__)) ||
(GNUNET_OK !=
pq_prepare (plugin,
- "select_expiration_order",
- "(SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 "
- "WHERE expire < $1 ORDER BY prio ASC LIMIT 1) "
- "UNION "
- "(SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 "
- "ORDER BY prio ASC LIMIT 1) "
- "ORDER BY expire ASC LIMIT 1",
+ "select_expiration_order",
+ "(SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 "
+ "WHERE expire < $1 ORDER BY prio ASC LIMIT 1) "
+ "UNION "
+ "(SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 "
+ "ORDER BY prio ASC LIMIT 1) "
+ "ORDER BY expire ASC LIMIT 1",
1,
__LINE__)) ||
(GNUNET_OK !=
pq_prepare (plugin,
- "select_replication_order",
- "SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 " \
- "ORDER BY repl DESC,RANDOM() LIMIT 1",
+ "select_replication_order",
+ "SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 "
+ "ORDER BY repl DESC,RANDOM() LIMIT 1",
0,
__LINE__)) ||
(GNUNET_OK !=
pq_prepare (plugin,
- "delrow",
- "DELETE FROM gn090 " "WHERE oid=$1",
- 1,
- __LINE__)))
- {
- PQfinish (plugin->dbh);
- plugin->dbh = NULL;
- return GNUNET_SYSERR;
- }
+ "delrow", "DELETE FROM gn090 " "WHERE oid=$1", 1, __LINE__)))
+ {
+ PQfinish (plugin->dbh);
+ plugin->dbh = NULL;
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -377,8 +369,7 @@ init_connection (struct Plugin *plugin)
* @return GNUNET_OK on success
*/
static int
-delete_by_rowid (struct Plugin *plugin,
- unsigned int rowid)
+delete_by_rowid (struct Plugin *plugin, unsigned int rowid)
{
uint32_t browid;
const char *paramValues[] = { (const char *) &browid };
@@ -392,11 +383,11 @@ delete_by_rowid (struct Plugin *plugin,
1, paramValues, paramLengths, paramFormats, 1);
if (GNUNET_OK !=
check_result (plugin,
- ret, PGRES_COMMAND_OK, "PQexecPrepared", "delrow",
+ ret, PGRES_COMMAND_OK, "PQexecPrepared", "delrow",
__LINE__))
- {
- return GNUNET_SYSERR;
- }
+ {
+ return GNUNET_SYSERR;
+ }
PQclear (ret);
return GNUNET_OK;
}
@@ -417,25 +408,23 @@ postgres_plugin_estimate_size (void *cls)
PGresult *ret;
ret = PQexecParams (plugin->dbh,
- "SELECT SUM(LENGTH(value))+256*COUNT(*) FROM gn090",
- 0, NULL, NULL, NULL, NULL, 1);
+ "SELECT SUM(LENGTH(value))+256*COUNT(*) FROM gn090",
+ 0, NULL, NULL, NULL, NULL, 1);
if (GNUNET_OK != check_result (plugin,
- ret,
+ ret,
PGRES_TUPLES_OK,
- "PQexecParams",
- "get_size",
- __LINE__))
- {
- return 0;
- }
+ "PQexecParams", "get_size", __LINE__))
+ {
+ return 0;
+ }
if ((PQntuples (ret) != 1) ||
(PQnfields (ret) != 1) ||
(PQgetlength (ret, 0, 0) != sizeof (unsigned long long)))
- {
- GNUNET_break (0);
- PQclear (ret);
- return 0;
- }
+ {
+ GNUNET_break (0);
+ PQclear (ret);
+ return 0;
+ }
total = GNUNET_ntohll (*(const unsigned long long *) PQgetvalue (ret, 0, 0));
PQclear (ret);
return total;
@@ -459,15 +448,14 @@ postgres_plugin_estimate_size (void *cls)
*/
static int
postgres_plugin_put (void *cls,
- const GNUNET_HashCode * key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- uint32_t replication,
- struct GNUNET_TIME_Absolute expiration,
- char **msg)
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ uint32_t replication,
+ struct GNUNET_TIME_Absolute expiration, char **msg)
{
struct Plugin *plugin = cls;
GNUNET_HashCode vhash;
@@ -477,6 +465,7 @@ postgres_plugin_put (void *cls,
uint32_t banon = htonl (anonymity);
uint32_t brepl = htonl (replication);
uint64_t bexpi = GNUNET_TIME_absolute_hton (expiration).abs_value__;
+
const char *paramValues[] = {
(const char *) &brepl,
(const char *) &btype,
@@ -510,9 +499,8 @@ postgres_plugin_put (void *cls,
plugin->env->duc (plugin->env->cls, size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
#if DEBUG_POSTGRES
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "datastore-postgres",
- "Stored %u bytes in database\n",
- (unsigned int) size);
+ "datastore-postgres",
+ "Stored %u bytes in database\n", (unsigned int) size);
#endif
return GNUNET_OK;
}
@@ -528,11 +516,10 @@ postgres_plugin_put (void *cls,
* @param res result from exec
* @param line line number for error messages
*/
-static void
+static void
process_result (struct Plugin *plugin,
- PluginDatumProcessor proc, void *proc_cls,
- PGresult *res,
- int line)
+ PluginDatumProcessor proc, void *proc_cls,
+ PGresult * res, int line)
{
int iret;
enum GNUNET_BLOCK_Type type;
@@ -544,115 +531,98 @@ process_result (struct Plugin *plugin,
GNUNET_HashCode key;
if (GNUNET_OK != check_result (plugin,
- res,
- PGRES_TUPLES_OK,
- "PQexecPrepared",
- "select",
- line))
- {
+ res,
+ PGRES_TUPLES_OK,
+ "PQexecPrepared", "select", line))
+ {
#if DEBUG_POSTGRES
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "datastore-postgres",
- "Ending iteration (postgres error)\n");
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "datastore-postgres",
+ "Ending iteration (postgres error)\n");
#endif
- proc (proc_cls,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
if (0 == PQntuples (res))
- {
- /* no result */
+ {
+ /* no result */
#if DEBUG_POSTGRES
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "datastore-postgres",
- "Ending iteration (no more results)\n");
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "datastore-postgres",
+ "Ending iteration (no more results)\n");
#endif
- proc (proc_cls,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- PQclear (res);
- return;
- }
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ PQclear (res);
+ return;
+ }
if ((1 != PQntuples (res)) ||
(7 != PQnfields (res)) ||
(sizeof (uint32_t) != PQfsize (res, 0)) ||
(sizeof (uint32_t) != PQfsize (res, 6)))
- {
- GNUNET_break (0);
- proc (proc_cls,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- PQclear (res);
- return;
- }
+ {
+ GNUNET_break (0);
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ PQclear (res);
+ return;
+ }
rowid = ntohl (*(uint32_t *) PQgetvalue (res, 0, 6));
if ((sizeof (uint32_t) != PQfsize (res, 0)) ||
(sizeof (uint32_t) != PQfsize (res, 1)) ||
(sizeof (uint32_t) != PQfsize (res, 2)) ||
(sizeof (uint64_t) != PQfsize (res, 3)) ||
- (sizeof (GNUNET_HashCode) != PQgetlength (res, 0, 4)) )
- {
- GNUNET_break (0);
- PQclear (res);
- delete_by_rowid (plugin, rowid);
- proc (proc_cls,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
+ (sizeof (GNUNET_HashCode) != PQgetlength (res, 0, 4)))
+ {
+ GNUNET_break (0);
+ PQclear (res);
+ delete_by_rowid (plugin, rowid);
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
type = ntohl (*(uint32_t *) PQgetvalue (res, 0, 0));
priority = ntohl (*(uint32_t *) PQgetvalue (res, 0, 1));
- anonymity = ntohl ( *(uint32_t *) PQgetvalue (res, 0, 2));
- expiration_time.abs_value = GNUNET_ntohll (*(uint64_t *) PQgetvalue (res, 0, 3));
- memcpy (&key,
- PQgetvalue (res, 0, 4),
- sizeof (GNUNET_HashCode));
+ anonymity = ntohl (*(uint32_t *) PQgetvalue (res, 0, 2));
+ expiration_time.abs_value =
+ GNUNET_ntohll (*(uint64_t *) PQgetvalue (res, 0, 3));
+ memcpy (&key, PQgetvalue (res, 0, 4), sizeof (GNUNET_HashCode));
size = PQgetlength (res, 0, 5);
#if DEBUG_POSTGRES
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "datastore-postgres",
- "Found result of size %u bytes and type %u in database\n",
- (unsigned int) size,
- (unsigned int) type);
+ "datastore-postgres",
+ "Found result of size %u bytes and type %u in database\n",
+ (unsigned int) size, (unsigned int) type);
#endif
iret = proc (proc_cls,
- &key,
- size,
- PQgetvalue (res, 0, 5),
- (enum GNUNET_BLOCK_Type) type,
- priority,
- anonymity,
- expiration_time,
- rowid);
+ &key,
+ size,
+ PQgetvalue (res, 0, 5),
+ (enum GNUNET_BLOCK_Type) type,
+ priority, anonymity, expiration_time, rowid);
PQclear (res);
if (iret == GNUNET_NO)
- {
+ {
#if DEBUG_POSTGRES
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Processor asked for item %u to be removed.\n",
- rowid);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Processor asked for item %u to be removed.\n", rowid);
#endif
- if (GNUNET_OK == delete_by_rowid (plugin, rowid))
- {
+ if (GNUNET_OK == delete_by_rowid (plugin, rowid))
+ {
#if DEBUG_POSTGRES
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "datastore-postgres",
- "Deleting %u bytes from database\n",
- (unsigned int) size);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "datastore-postgres",
+ "Deleting %u bytes from database\n",
+ (unsigned int) size);
#endif
- plugin->env->duc (plugin->env->cls,
- - (size + GNUNET_DATASTORE_ENTRY_OVERHEAD));
+ plugin->env->duc (plugin->env->cls,
+ -(size + GNUNET_DATASTORE_ENTRY_OVERHEAD));
#if DEBUG_POSTGRES
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "datastore-postgres",
- "Deleted %u bytes from database\n",
- (unsigned int) size);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "datastore-postgres",
+ "Deleted %u bytes from database\n", (unsigned int) size);
#endif
- }
}
+ }
}
@@ -677,11 +647,11 @@ process_result (struct Plugin *plugin,
*/
static void
postgres_plugin_get_key (void *cls,
- uint64_t offset,
- const GNUNET_HashCode *key,
- const GNUNET_HashCode *vhash,
- enum GNUNET_BLOCK_Type type,
- PluginDatumProcessor proc, void *proc_cls)
+ uint64_t offset,
+ const GNUNET_HashCode * key,
+ const GNUNET_HashCode * vhash,
+ enum GNUNET_BLOCK_Type type,
+ PluginDatumProcessor proc, void *proc_cls)
{
struct Plugin *plugin = cls;
const int paramFormats[] = { 1, 1, 1, 1, 1 };
@@ -695,121 +665,92 @@ postgres_plugin_get_key (void *cls,
uint32_t btype;
GNUNET_assert (key != NULL);
- paramValues[0] = (const char*) key;
+ paramValues[0] = (const char *) key;
paramLengths[0] = sizeof (GNUNET_HashCode);
btype = htonl (type);
if (type != 0)
+ {
+ if (vhash != NULL)
+ {
+ paramValues[1] = (const char *) vhash;
+ paramLengths[1] = sizeof (GNUNET_HashCode);
+ paramValues[2] = (const char *) &btype;
+ paramLengths[2] = sizeof (btype);
+ paramValues[3] = (const char *) &blimit_off;
+ paramLengths[3] = sizeof (blimit_off);
+ nparams = 4;
+ pname = "getvt";
+ ret = PQexecParams (plugin->dbh,
+ "SELECT count(*) FROM gn090 WHERE hash=$1 AND vhash=$2 AND type=$3",
+ 3, NULL, paramValues, paramLengths, paramFormats, 1);
+ }
+ else
{
- if (vhash != NULL)
- {
- paramValues[1] = (const char *) vhash;
- paramLengths[1] = sizeof (GNUNET_HashCode);
- paramValues[2] = (const char *) &btype;
- paramLengths[2] = sizeof (btype);
- paramValues[3] = (const char *) &blimit_off;
- paramLengths[3] = sizeof (blimit_off);
- nparams = 4;
- pname = "getvt";
- ret = PQexecParams (plugin->dbh,
- "SELECT count(*) FROM gn090 WHERE hash=$1 AND vhash=$2 AND type=$3",
- 3,
- NULL,
- paramValues,
- paramLengths,
- paramFormats, 1);
- }
- else
- {
- paramValues[1] = (const char *) &btype;
- paramLengths[1] = sizeof (btype);
- paramValues[2] = (const char *) &blimit_off;
- paramLengths[2] = sizeof (blimit_off);
- nparams = 3;
- pname = "gett";
- ret = PQexecParams (plugin->dbh,
- "SELECT count(*) FROM gn090 WHERE hash=$1 AND type=$2",
- 2,
- NULL,
- paramValues,
- paramLengths,
- paramFormats, 1);
- }
+ paramValues[1] = (const char *) &btype;
+ paramLengths[1] = sizeof (btype);
+ paramValues[2] = (const char *) &blimit_off;
+ paramLengths[2] = sizeof (blimit_off);
+ nparams = 3;
+ pname = "gett";
+ ret = PQexecParams (plugin->dbh,
+ "SELECT count(*) FROM gn090 WHERE hash=$1 AND type=$2",
+ 2, NULL, paramValues, paramLengths, paramFormats, 1);
}
+ }
else
+ {
+ if (vhash != NULL)
{
- if (vhash != NULL)
- {
- paramValues[1] = (const char *) vhash;
- paramLengths[1] = sizeof (GNUNET_HashCode);
- paramValues[2] = (const char *) &blimit_off;
- paramLengths[2] = sizeof (blimit_off);
- nparams = 3;
- pname = "getv";
- ret = PQexecParams (plugin->dbh,
- "SELECT count(*) FROM gn090 WHERE hash=$1 AND vhash=$2",
- 2,
- NULL,
- paramValues,
- paramLengths,
- paramFormats, 1);
- }
- else
- {
- paramValues[1] = (const char *) &blimit_off;
- paramLengths[1] = sizeof (blimit_off);
- nparams = 2;
- pname = "get";
- ret = PQexecParams (plugin->dbh,
- "SELECT count(*) FROM gn090 WHERE hash=$1",
- 1,
- NULL,
- paramValues,
- paramLengths,
- paramFormats, 1);
- }
+ paramValues[1] = (const char *) vhash;
+ paramLengths[1] = sizeof (GNUNET_HashCode);
+ paramValues[2] = (const char *) &blimit_off;
+ paramLengths[2] = sizeof (blimit_off);
+ nparams = 3;
+ pname = "getv";
+ ret = PQexecParams (plugin->dbh,
+ "SELECT count(*) FROM gn090 WHERE hash=$1 AND vhash=$2",
+ 2, NULL, paramValues, paramLengths, paramFormats, 1);
}
- if (GNUNET_OK != check_result (plugin,
- ret,
- PGRES_TUPLES_OK,
- "PQexecParams",
- pname,
- __LINE__))
+ else
{
- proc (proc_cls,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
+ paramValues[1] = (const char *) &blimit_off;
+ paramLengths[1] = sizeof (blimit_off);
+ nparams = 2;
+ pname = "get";
+ ret = PQexecParams (plugin->dbh,
+ "SELECT count(*) FROM gn090 WHERE hash=$1",
+ 1, NULL, paramValues, paramLengths, paramFormats, 1);
}
+ }
+ if (GNUNET_OK != check_result (plugin,
+ ret,
+ PGRES_TUPLES_OK,
+ "PQexecParams", pname, __LINE__))
+ {
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
if ((PQntuples (ret) != 1) ||
(PQnfields (ret) != 1) ||
(PQgetlength (ret, 0, 0) != sizeof (unsigned long long)))
- {
- GNUNET_break (0);
- PQclear (ret);
- proc (proc_cls,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
+ {
+ GNUNET_break (0);
+ PQclear (ret);
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
total = GNUNET_ntohll (*(const unsigned long long *) PQgetvalue (ret, 0, 0));
PQclear (ret);
if (total == 0)
- {
- proc (proc_cls,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
+ {
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
blimit_off = GNUNET_htonll (offset % total);
ret = PQexecPrepared (plugin->dbh,
- pname,
- nparams,
- paramValues,
- paramLengths,
- paramFormats, 1);
- process_result (plugin,
- proc, proc_cls,
- ret, __LINE__);
+ pname,
+ nparams, paramValues, paramLengths, paramFormats, 1);
+ process_result (plugin, proc, proc_cls, ret, __LINE__);
}
@@ -826,29 +767,24 @@ postgres_plugin_get_key (void *cls,
*/
static void
postgres_plugin_get_zero_anonymity (void *cls,
- uint64_t offset,
- enum GNUNET_BLOCK_Type type,
- PluginDatumProcessor proc, void *proc_cls)
+ uint64_t offset,
+ enum GNUNET_BLOCK_Type type,
+ PluginDatumProcessor proc, void *proc_cls)
{
struct Plugin *plugin = cls;
uint32_t btype;
uint64_t boff;
const int paramFormats[] = { 1, 1 };
int paramLengths[] = { sizeof (btype), sizeof (boff) };
- const char *paramValues[] = { (const char*) &btype, (const char*) &boff };
+ const char *paramValues[] = { (const char *) &btype, (const char *) &boff };
PGresult *ret;
btype = htonl ((uint32_t) type);
boff = GNUNET_htonll (offset);
ret = PQexecPrepared (plugin->dbh,
- "select_non_anonymous",
- 2,
- paramValues,
- paramLengths,
- paramFormats, 1);
- process_result (plugin,
- proc, proc_cls,
- ret, __LINE__);
+ "select_non_anonymous",
+ 2, paramValues, paramLengths, paramFormats, 1);
+ process_result (plugin, proc, proc_cls, ret, __LINE__);
}
@@ -857,17 +793,17 @@ postgres_plugin_get_zero_anonymity (void *cls,
*/
struct ReplCtx
{
-
+
/**
* Plugin handle.
*/
struct Plugin *plugin;
-
+
/**
* Function to call for the result (or the NULL).
*/
PluginDatumProcessor proc;
-
+
/**
* Closure for proc.
*/
@@ -898,14 +834,13 @@ struct ReplCtx
*/
static int
repl_proc (void *cls,
- const GNUNET_HashCode *key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute expiration,
- uint64_t uid)
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct ReplCtx *rc = cls;
struct Plugin *plugin = rc->plugin;
@@ -914,31 +849,27 @@ repl_proc (void *cls,
uint32_t boid;
ret = rc->proc (rc->proc_cls,
- key,
- size, data,
- type, priority, anonymity, expiration,
- uid);
+ key, size, data, type, priority, anonymity, expiration, uid);
if (NULL != key)
- {
- boid = htonl ( (uint32_t) uid);
- const char *paramValues[] = {
- (const char *) &boid,
- };
- int paramLengths[] = {
- sizeof (boid),
- };
- const int paramFormats[] = { 1 };
- qret = PQexecPrepared (plugin->dbh,
- "decrepl",
- 1, paramValues, paramLengths, paramFormats, 1);
- if (GNUNET_OK != check_result (plugin,
- qret,
- PGRES_COMMAND_OK,
- "PQexecPrepared",
- "decrepl", __LINE__))
- return GNUNET_SYSERR;
- PQclear (qret);
- }
+ {
+ boid = htonl ((uint32_t) uid);
+ const char *paramValues[] = {
+ (const char *) &boid,
+ };
+ int paramLengths[] = {
+ sizeof (boid),
+ };
+ const int paramFormats[] = { 1 };
+ qret = PQexecPrepared (plugin->dbh,
+ "decrepl",
+ 1, paramValues, paramLengths, paramFormats, 1);
+ if (GNUNET_OK != check_result (plugin,
+ qret,
+ PGRES_COMMAND_OK,
+ "PQexecPrepared", "decrepl", __LINE__))
+ return GNUNET_SYSERR;
+ PQclear (qret);
+ }
return ret;
}
@@ -955,7 +886,7 @@ repl_proc (void *cls,
*/
static void
postgres_plugin_get_replication (void *cls,
- PluginDatumProcessor proc, void *proc_cls)
+ PluginDatumProcessor proc, void *proc_cls)
{
struct Plugin *plugin = cls;
struct ReplCtx rc;
@@ -965,12 +896,8 @@ postgres_plugin_get_replication (void *cls,
rc.proc = proc;
rc.proc_cls = proc_cls;
ret = PQexecPrepared (plugin->dbh,
- "select_replication_order",
- 0,
- NULL, NULL, NULL, 1);
- process_result (plugin,
- &repl_proc, &rc,
- ret, __LINE__);
+ "select_replication_order", 0, NULL, NULL, NULL, 1);
+ process_result (plugin, &repl_proc, &rc, ret, __LINE__);
}
@@ -984,26 +911,20 @@ postgres_plugin_get_replication (void *cls,
*/
static void
postgres_plugin_get_expiration (void *cls,
- PluginDatumProcessor proc, void *proc_cls)
+ PluginDatumProcessor proc, void *proc_cls)
{
struct Plugin *plugin = cls;
uint64_t btime;
const int paramFormats[] = { 1 };
int paramLengths[] = { sizeof (btime) };
- const char *paramValues[] = { (const char*) &btime };
+ const char *paramValues[] = { (const char *) &btime };
PGresult *ret;
-
+
btime = GNUNET_htonll (GNUNET_TIME_absolute_get ().abs_value);
ret = PQexecPrepared (plugin->dbh,
- "select_expiration_order",
- 1,
- paramValues,
- paramLengths,
- paramFormats,
- 1);
- process_result (plugin,
- proc, proc_cls,
- ret, __LINE__);
+ "select_expiration_order",
+ 1, paramValues, paramLengths, paramFormats, 1);
+ process_result (plugin, proc, proc_cls, ret, __LINE__);
}
@@ -1032,15 +953,16 @@ postgres_plugin_get_expiration (void *cls,
*/
static int
postgres_plugin_update (void *cls,
- uint64_t uid,
- int delta, struct GNUNET_TIME_Absolute expire,
- char **msg)
+ uint64_t uid,
+ int delta, struct GNUNET_TIME_Absolute expire,
+ char **msg)
{
struct Plugin *plugin = cls;
PGresult *ret;
int32_t bdelta = (int32_t) htonl ((uint32_t) delta);
- uint32_t boid = htonl ( (uint32_t) uid);
+ uint32_t boid = htonl ((uint32_t) uid);
uint64_t bexpire = GNUNET_TIME_absolute_hton (expire).abs_value__;
+
const char *paramValues[] = {
(const char *) &bdelta,
(const char *) &bexpire,
@@ -1057,7 +979,7 @@ postgres_plugin_update (void *cls,
"update",
3, paramValues, paramLengths, paramFormats, 1);
if (GNUNET_OK != check_result (plugin,
- ret,
+ ret,
PGRES_COMMAND_OK,
"PQexecPrepared", "update", __LINE__))
return GNUNET_SYSERR;
@@ -1069,7 +991,7 @@ postgres_plugin_update (void *cls,
/**
* Drop database.
*/
-static void
+static void
postgres_plugin_drop (void *cls)
{
struct Plugin *plugin = cls;
@@ -1094,10 +1016,10 @@ libgnunet_plugin_datastore_postgres_init (void *cls)
plugin = GNUNET_malloc (sizeof (struct Plugin));
plugin->env = env;
if (GNUNET_OK != init_connection (plugin))
- {
- GNUNET_free (plugin);
- return NULL;
- }
+ {
+ GNUNET_free (plugin);
+ return NULL;
+ }
api = GNUNET_malloc (sizeof (struct GNUNET_DATASTORE_PluginFunctions));
api->cls = plugin;
api->estimate_size = &postgres_plugin_estimate_size;
@@ -1109,8 +1031,7 @@ libgnunet_plugin_datastore_postgres_init (void *cls)
api->get_zero_anonymity = &postgres_plugin_get_zero_anonymity;
api->drop = &postgres_plugin_drop;
GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
- "datastore-postgres",
- _("Postgres database running\n"));
+ "datastore-postgres", _("Postgres database running\n"));
return api;
}
@@ -1125,7 +1046,7 @@ libgnunet_plugin_datastore_postgres_done (void *cls)
{
struct GNUNET_DATASTORE_PluginFunctions *api = cls;
struct Plugin *plugin = api->cls;
-
+
PQfinish (plugin->dbh);
GNUNET_free (plugin);
GNUNET_free (api);
diff --git a/src/datastore/plugin_datastore_sqlite.c b/src/datastore/plugin_datastore_sqlite.c
index f551f048d6..075d316234 100644
--- a/src/datastore/plugin_datastore_sqlite.c
+++ b/src/datastore/plugin_datastore_sqlite.c
@@ -1,22 +1,22 @@
/*
- This file is part of GNUnet
- (C) 2009, 2011 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.
-*/
+ * This file is part of GNUnet
+ * (C) 2009, 2011 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 datastore/plugin_datastore_sqlite.c
@@ -65,7 +65,7 @@
/**
* Context for all functions in this plugin.
*/
-struct Plugin
+struct Plugin
{
/**
* Our execution environment.
@@ -139,25 +139,17 @@ struct Plugin
* @return 0 on success
*/
static int
-sq_prepare (sqlite3 * dbh,
- const char *zSql,
- sqlite3_stmt ** ppStmt)
+sq_prepare (sqlite3 * dbh, const char *zSql, sqlite3_stmt ** ppStmt)
{
char *dummy;
int result;
result = sqlite3_prepare_v2 (dbh,
- zSql,
- strlen (zSql),
- ppStmt,
- (const char **) &dummy);
+ zSql,
+ strlen (zSql), ppStmt, (const char **) &dummy);
#if DEBUG_SQLITE && 0
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "sqlite",
- "Prepared `%s' / %p: %d\n",
- zSql,
- *ppStmt,
- result);
+ "sqlite", "Prepared `%s' / %p: %d\n", zSql, *ppStmt, result);
#endif
return result;
}
@@ -172,35 +164,40 @@ static void
create_indices (sqlite3 * dbh)
{
/* create indices */
- if ( (SQLITE_OK !=
- sqlite3_exec (dbh,
- "CREATE INDEX IF NOT EXISTS idx_hash ON gn090 (hash)", NULL, NULL, NULL)) ||
- (SQLITE_OK !=
- sqlite3_exec (dbh,
- "CREATE INDEX IF NOT EXISTS idx_hash_vhash ON gn090 (hash,vhash)", NULL,
- NULL, NULL)) ||
- (SQLITE_OK !=
- sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS idx_expire_repl ON gn090 (expire ASC,repl DESC)", NULL, NULL,
- NULL)) ||
- (SQLITE_OK !=
- sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS idx_comb ON gn090 (anonLevel ASC,expire ASC,prio,type,hash)",
- NULL, NULL, NULL)) ||
- (SQLITE_OK !=
- sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS idx_anon_type_hash ON gn090 (anonLevel ASC,type,hash)",
- NULL, NULL, NULL)) ||
- (SQLITE_OK !=
- sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS idx_expire ON gn090 (expire ASC)",
- NULL, NULL, NULL)) ||
- (SQLITE_OK !=
- sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS idx_repl_rvalue ON gn090 (repl,rvalue)",
- NULL, NULL, NULL)) ||
- (SQLITE_OK !=
- sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS idx_repl ON gn090 (repl DESC)",
- NULL, NULL, NULL)) )
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
- "sqlite",
- "Failed to create indices: %s\n",
- sqlite3_errmsg (dbh));
+ if ((SQLITE_OK !=
+ sqlite3_exec (dbh,
+ "CREATE INDEX IF NOT EXISTS idx_hash ON gn090 (hash)",
+ NULL, NULL, NULL)) ||
+ (SQLITE_OK !=
+ sqlite3_exec (dbh,
+ "CREATE INDEX IF NOT EXISTS idx_hash_vhash ON gn090 (hash,vhash)",
+ NULL, NULL, NULL)) ||
+ (SQLITE_OK !=
+ sqlite3_exec (dbh,
+ "CREATE INDEX IF NOT EXISTS idx_expire_repl ON gn090 (expire ASC,repl DESC)",
+ NULL, NULL, NULL)) ||
+ (SQLITE_OK !=
+ sqlite3_exec (dbh,
+ "CREATE INDEX IF NOT EXISTS idx_comb ON gn090 (anonLevel ASC,expire ASC,prio,type,hash)",
+ NULL, NULL, NULL)) ||
+ (SQLITE_OK !=
+ sqlite3_exec (dbh,
+ "CREATE INDEX IF NOT EXISTS idx_anon_type_hash ON gn090 (anonLevel ASC,type,hash)",
+ NULL, NULL, NULL)) ||
+ (SQLITE_OK !=
+ sqlite3_exec (dbh,
+ "CREATE INDEX IF NOT EXISTS idx_expire ON gn090 (expire ASC)",
+ NULL, NULL, NULL)) ||
+ (SQLITE_OK !=
+ sqlite3_exec (dbh,
+ "CREATE INDEX IF NOT EXISTS idx_repl_rvalue ON gn090 (repl,rvalue)",
+ NULL, NULL, NULL)) ||
+ (SQLITE_OK !=
+ sqlite3_exec (dbh,
+ "CREATE INDEX IF NOT EXISTS idx_repl ON gn090 (repl DESC)",
+ NULL, NULL, NULL)))
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "sqlite",
+ "Failed to create indices: %s\n", sqlite3_errmsg (dbh));
}
@@ -225,56 +222,55 @@ create_indices (sqlite3 * dbh)
*/
static int
database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct Plugin *plugin)
+ struct Plugin *plugin)
{
sqlite3_stmt *stmt;
char *afsdir;
+
#if ENULL_DEFINED
char *e;
#endif
-
- if (GNUNET_OK !=
+
+ if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (cfg,
- "datastore-sqlite",
- "FILENAME",
- &afsdir))
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
- "sqlite",
- _("Option `%s' in section `%s' missing in configuration!\n"),
- "FILENAME",
- "datastore-sqlite");
- return GNUNET_SYSERR;
- }
+ "datastore-sqlite",
+ "FILENAME", &afsdir))
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "sqlite",
+ _
+ ("Option `%s' in section `%s' missing in configuration!\n"),
+ "FILENAME", "datastore-sqlite");
+ return GNUNET_SYSERR;
+ }
if (GNUNET_OK != GNUNET_DISK_file_test (afsdir))
+ {
+ if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (afsdir))
{
- if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (afsdir))
- {
- GNUNET_break (0);
- GNUNET_free (afsdir);
- return GNUNET_SYSERR;
- }
- /* database is new or got deleted, reset payload to zero! */
- plugin->env->duc (plugin->env->cls, 0);
+ GNUNET_break (0);
+ GNUNET_free (afsdir);
+ return GNUNET_SYSERR;
}
+ /* database is new or got deleted, reset payload to zero! */
+ plugin->env->duc (plugin->env->cls, 0);
+ }
#ifdef ENABLE_NLS
plugin->fn = GNUNET_STRINGS_to_utf8 (afsdir, strlen (afsdir),
- nl_langinfo (CODESET));
+ nl_langinfo (CODESET));
#else
- plugin->fn = GNUNET_STRINGS_to_utf8 (afsdir, strlen (afsdir),
- "UTF-8"); /* good luck */
+ plugin->fn = GNUNET_STRINGS_to_utf8 (afsdir, strlen (afsdir), "UTF-8"); /* good luck */
#endif
GNUNET_free (afsdir);
-
+
/* Open database and precompile statements */
if (sqlite3_open (plugin->fn, &plugin->dbh) != SQLITE_OK)
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
- "sqlite",
- _("Unable to initialize SQLite: %s.\n"),
- sqlite3_errmsg (plugin->dbh));
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "sqlite",
+ _("Unable to initialize SQLite: %s.\n"),
+ sqlite3_errmsg (plugin->dbh));
+ return GNUNET_SYSERR;
+ }
CHECK (SQLITE_OK ==
sqlite3_exec (plugin->dbh,
"PRAGMA temp_store=MEMORY", NULL, NULL, ENULL));
@@ -294,8 +290,8 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
sqlite3_exec (plugin->dbh,
"PRAGMA count_changes=OFF", NULL, NULL, ENULL));
CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA page_size=4092", NULL, NULL, ENULL));
+ sqlite3_exec (plugin->dbh,
+ "PRAGMA page_size=4092", NULL, NULL, ENULL));
CHECK (SQLITE_OK == sqlite3_busy_timeout (plugin->dbh, BUSY_TIMEOUT_MS));
@@ -305,62 +301,60 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
sq_prepare (plugin->dbh,
"SELECT 1 FROM sqlite_master WHERE tbl_name = 'gn090'",
&stmt));
- if ( (sqlite3_step (stmt) == SQLITE_DONE) &&
- (sqlite3_exec (plugin->dbh,
- "CREATE TABLE gn090 ("
- " repl INT4 NOT NULL DEFAULT 0,"
- " type INT4 NOT NULL DEFAULT 0,"
- " prio INT4 NOT NULL DEFAULT 0,"
- " anonLevel INT4 NOT NULL DEFAULT 0,"
- " expire INT8 NOT NULL DEFAULT 0,"
- " rvalue INT8 NOT NULL,"
- " hash TEXT NOT NULL DEFAULT '',"
- " vhash TEXT NOT NULL DEFAULT '',"
- " value BLOB NOT NULL DEFAULT '')", NULL, NULL,
- NULL) != SQLITE_OK) )
- {
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR,
- "sqlite3_exec");
- sqlite3_finalize (stmt);
- return GNUNET_SYSERR;
- }
+ if ((sqlite3_step (stmt) == SQLITE_DONE) &&
+ (sqlite3_exec (plugin->dbh,
+ "CREATE TABLE gn090 ("
+ " repl INT4 NOT NULL DEFAULT 0,"
+ " type INT4 NOT NULL DEFAULT 0,"
+ " prio INT4 NOT NULL DEFAULT 0,"
+ " anonLevel INT4 NOT NULL DEFAULT 0,"
+ " expire INT8 NOT NULL DEFAULT 0,"
+ " rvalue INT8 NOT NULL,"
+ " hash TEXT NOT NULL DEFAULT '',"
+ " vhash TEXT NOT NULL DEFAULT '',"
+ " value BLOB NOT NULL DEFAULT '')", NULL, NULL,
+ NULL) != SQLITE_OK))
+ {
+ LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_exec");
+ sqlite3_finalize (stmt);
+ return GNUNET_SYSERR;
+ }
sqlite3_finalize (stmt);
create_indices (plugin->dbh);
if ((sq_prepare (plugin->dbh,
"UPDATE gn090 "
- "SET prio = prio + ?, expire = MAX(expire,?) WHERE _ROWID_ = ?",
+ "SET prio = prio + ?, expire = MAX(expire,?) WHERE _ROWID_ = ?",
&plugin->updPrio) != SQLITE_OK) ||
(sq_prepare (plugin->dbh,
"UPDATE gn090 "
- "SET repl = MAX (0, repl - 1) WHERE _ROWID_ = ?",
+ "SET repl = MAX (0, repl - 1) WHERE _ROWID_ = ?",
&plugin->updRepl) != SQLITE_OK) ||
(sq_prepare (plugin->dbh,
- "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ "
- "FROM gn090 INDEXED BY idx_repl_rvalue "
- "WHERE repl=?2 AND"
- " (rvalue>=?1 OR"
- " NOT EXISTS (SELECT 1 FROM gn090 INDEXED BY idx_repl_rvalue WHERE repl=?2 AND rvalue>=?1 LIMIT 1))"
- " ORDER BY rvalue ASC"
- " LIMIT 1",
+ "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ "
+ "FROM gn090 INDEXED BY idx_repl_rvalue "
+ "WHERE repl=?2 AND"
+ " (rvalue>=?1 OR"
+ " NOT EXISTS (SELECT 1 FROM gn090 INDEXED BY idx_repl_rvalue WHERE repl=?2 AND rvalue>=?1 LIMIT 1))"
+ " ORDER BY rvalue ASC"
+ " LIMIT 1",
&plugin->selRepl) != SQLITE_OK) ||
(sq_prepare (plugin->dbh,
- "SELECT MAX(repl) "
- "FROM gn090 INDEXED BY idx_repl_rvalue",
+ "SELECT MAX(repl) "
+ "FROM gn090 INDEXED BY idx_repl_rvalue",
&plugin->maxRepl) != SQLITE_OK) ||
(sq_prepare (plugin->dbh,
- "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ "
- "FROM gn090 INDEXED BY idx_expire"
- " WHERE NOT EXISTS (SELECT 1 FROM gn090 WHERE expire < ?1 LIMIT 1) OR (expire < ?1) "
- " ORDER BY expire ASC LIMIT 1",
+ "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ "
+ "FROM gn090 INDEXED BY idx_expire"
+ " WHERE NOT EXISTS (SELECT 1 FROM gn090 WHERE expire < ?1 LIMIT 1) OR (expire < ?1) "
+ " ORDER BY expire ASC LIMIT 1",
&plugin->selExpi) != SQLITE_OK) ||
- (sq_prepare (plugin->dbh,
- "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ "
- "FROM gn090 INDEXED BY idx_anon_type_hash "
- "WHERE (anonLevel = 0 AND type=?1) "
- "ORDER BY hash DESC LIMIT 1 OFFSET ?2",
- &plugin->selZeroAnon) != SQLITE_OK) ||
+ (sq_prepare (plugin->dbh,
+ "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ "
+ "FROM gn090 INDEXED BY idx_anon_type_hash "
+ "WHERE (anonLevel = 0 AND type=?1) "
+ "ORDER BY hash DESC LIMIT 1 OFFSET ?2",
+ &plugin->selZeroAnon) != SQLITE_OK) ||
(sq_prepare (plugin->dbh,
"INSERT INTO gn090 (repl, type, prio, "
"anonLevel, expire, rvalue, hash, vhash, value) "
@@ -369,11 +363,10 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
(sq_prepare (plugin->dbh,
"DELETE FROM gn090 WHERE _ROWID_ = ?",
&plugin->delRow) != SQLITE_OK))
- {
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR, "precompiling");
- return GNUNET_SYSERR;
- }
+ {
+ LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR, "precompiling");
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -388,6 +381,7 @@ static void
database_shutdown (struct Plugin *plugin)
{
int result;
+
#if SQLITE_VERSION_NUMBER >= 3007000
sqlite3_stmt *stmt;
#endif
@@ -408,36 +402,35 @@ database_shutdown (struct Plugin *plugin)
sqlite3_finalize (plugin->selZeroAnon);
if (plugin->insertContent != NULL)
sqlite3_finalize (plugin->insertContent);
- result = sqlite3_close(plugin->dbh);
+ result = sqlite3_close (plugin->dbh);
#if SQLITE_VERSION_NUMBER >= 3007000
if (result == SQLITE_BUSY)
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
+ "sqlite",
+ _
+ ("Tried to close sqlite without finalizing all prepared statements.\n"));
+ stmt = sqlite3_next_stmt (plugin->dbh, NULL);
+ while (stmt != NULL)
{
- GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
- "sqlite",
- _("Tried to close sqlite without finalizing all prepared statements.\n"));
- stmt = sqlite3_next_stmt(plugin->dbh, NULL);
- while (stmt != NULL)
- {
#if DEBUG_SQLITE
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "sqlite", "Closing statement %p\n", stmt);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "sqlite", "Closing statement %p\n", stmt);
#endif
- result = sqlite3_finalize(stmt);
+ result = sqlite3_finalize (stmt);
#if DEBUG_SQLITE
- if (result != SQLITE_OK)
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "sqlite",
- "Failed to close statement %p: %d\n", stmt, result);
+ if (result != SQLITE_OK)
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "sqlite",
+ "Failed to close statement %p: %d\n", stmt, result);
#endif
- stmt = sqlite3_next_stmt(plugin->dbh, NULL);
- }
- result = sqlite3_close(plugin->dbh);
+ stmt = sqlite3_next_stmt (plugin->dbh, NULL);
}
+ result = sqlite3_close (plugin->dbh);
+ }
#endif
if (SQLITE_OK != result)
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR,
- "sqlite3_close");
+ LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_close");
GNUNET_free_non_null (plugin->fn);
}
@@ -451,34 +444,34 @@ database_shutdown (struct Plugin *plugin)
* @param rid the ID of the row to delete
*/
static int
-delete_by_rowid (struct Plugin* plugin,
- unsigned long long rid)
+delete_by_rowid (struct Plugin *plugin, unsigned long long rid)
{
- if (SQLITE_OK !=
- sqlite3_bind_int64 (plugin->delRow, 1, rid))
- {
+ if (SQLITE_OK != sqlite3_bind_int64 (plugin->delRow, 1, rid))
+ {
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_bind_XXXX");
+ if (SQLITE_OK != sqlite3_reset (plugin->delRow))
LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite3_bind_XXXX");
- if (SQLITE_OK != sqlite3_reset (plugin->delRow))
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
- return GNUNET_SYSERR;
- }
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_reset");
+ return GNUNET_SYSERR;
+ }
if (SQLITE_DONE != sqlite3_step (plugin->delRow))
- {
+ {
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "sqlite3_step");
+ if (SQLITE_OK != sqlite3_reset (plugin->delRow))
LOG_SQLITE (plugin, NULL,
GNUNET_ERROR_TYPE_ERROR |
- GNUNET_ERROR_TYPE_BULK, "sqlite3_step");
- if (SQLITE_OK != sqlite3_reset (plugin->delRow))
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR |
- GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
- return GNUNET_SYSERR;
- }
+ GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
+ return GNUNET_SYSERR;
+ }
if (SQLITE_OK != sqlite3_reset (plugin->delRow))
LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR |
- GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
+ GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
return GNUNET_OK;
}
@@ -500,15 +493,14 @@ delete_by_rowid (struct Plugin* plugin,
*/
static int
sqlite_plugin_put (void *cls,
- const GNUNET_HashCode *key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- uint32_t replication,
- struct GNUNET_TIME_Absolute expiration,
- char ** msg)
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ uint32_t replication,
+ struct GNUNET_TIME_Absolute expiration, char **msg)
{
struct Plugin *plugin = cls;
int n;
@@ -521,13 +513,14 @@ sqlite_plugin_put (void *cls,
return GNUNET_SYSERR;
#if DEBUG_SQLITE
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "sqlite",
- "Storing in database block with type %u/key `%s'/priority %u/expiration in %llu ms (%lld).\n",
- type,
- GNUNET_h2s(key),
- priority,
- (unsigned long long) GNUNET_TIME_absolute_get_remaining (expiration).rel_value,
- (long long) expiration.abs_value);
+ "sqlite",
+ "Storing in database block with type %u/key `%s'/priority %u/expiration in %llu ms (%lld).\n",
+ type,
+ GNUNET_h2s (key),
+ priority,
+ (unsigned long long)
+ GNUNET_TIME_absolute_get_remaining (expiration).rel_value,
+ (long long) expiration.abs_value);
#endif
GNUNET_CRYPTO_hash (data, size, &vhash);
stmt = plugin->insertContent;
@@ -545,55 +538,54 @@ sqlite_plugin_put (void *cls,
sqlite3_bind_blob (stmt, 8, &vhash, sizeof (GNUNET_HashCode),
SQLITE_TRANSIENT))
|| (SQLITE_OK !=
- sqlite3_bind_blob (stmt, 9, data, size,
- SQLITE_TRANSIENT)))
- {
- LOG_SQLITE (plugin,
- msg,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite3_bind_XXXX");
- if (SQLITE_OK != sqlite3_reset (stmt))
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
- return GNUNET_SYSERR;
- }
+ sqlite3_bind_blob (stmt, 9, data, size, SQLITE_TRANSIENT)))
+ {
+ LOG_SQLITE (plugin,
+ msg,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_bind_XXXX");
+ if (SQLITE_OK != sqlite3_reset (stmt))
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_reset");
+ return GNUNET_SYSERR;
+ }
n = sqlite3_step (stmt);
switch (n)
- {
- case SQLITE_DONE:
- plugin->env->duc (plugin->env->cls,
- size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
+ {
+ case SQLITE_DONE:
+ plugin->env->duc (plugin->env->cls, size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
#if DEBUG_SQLITE
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "sqlite",
- "Stored new entry (%u bytes)\n",
- size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "sqlite",
+ "Stored new entry (%u bytes)\n",
+ size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
#endif
- ret = GNUNET_OK;
- break;
- case SQLITE_BUSY:
- GNUNET_break (0);
- LOG_SQLITE (plugin, msg,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "sqlite3_step");
- ret = GNUNET_SYSERR;
- break;
- default:
- LOG_SQLITE (plugin, msg,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "sqlite3_step");
- if (SQLITE_OK != sqlite3_reset (stmt))
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR |
- GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
- database_shutdown (plugin);
- database_setup (plugin->env->cfg,
- plugin);
- return GNUNET_SYSERR;
- }
+ ret = GNUNET_OK;
+ break;
+ case SQLITE_BUSY:
+ GNUNET_break (0);
+ LOG_SQLITE (plugin, msg,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_step");
+ ret = GNUNET_SYSERR;
+ break;
+ default:
+ LOG_SQLITE (plugin, msg,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_step");
+ if (SQLITE_OK != sqlite3_reset (stmt))
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
+ database_shutdown (plugin);
+ database_setup (plugin->env->cfg, plugin);
+ return GNUNET_SYSERR;
+ }
if (SQLITE_OK != sqlite3_reset (stmt))
LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR |
- GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
+ GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
return ret;
}
@@ -623,52 +615,51 @@ sqlite_plugin_put (void *cls,
*/
static int
sqlite_plugin_update (void *cls,
- uint64_t uid,
- int delta, struct GNUNET_TIME_Absolute expire,
- char **msg)
+ uint64_t uid,
+ int delta, struct GNUNET_TIME_Absolute expire, char **msg)
{
struct Plugin *plugin = cls;
int n;
- if ( (SQLITE_OK !=
- sqlite3_bind_int (plugin->updPrio, 1, delta)) ||
- (SQLITE_OK !=
- sqlite3_bind_int64 (plugin->updPrio, 2, expire.abs_value)) ||
- (SQLITE_OK !=
- sqlite3_bind_int64 (plugin->updPrio, 3, uid)) )
- {
- LOG_SQLITE (plugin, msg,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite3_bind_XXXX");
- if (SQLITE_OK != sqlite3_reset (plugin->updPrio))
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
- return GNUNET_SYSERR;
+ if ((SQLITE_OK !=
+ sqlite3_bind_int (plugin->updPrio, 1, delta)) ||
+ (SQLITE_OK !=
+ sqlite3_bind_int64 (plugin->updPrio, 2, expire.abs_value)) ||
+ (SQLITE_OK != sqlite3_bind_int64 (plugin->updPrio, 3, uid)))
+ {
+ LOG_SQLITE (plugin, msg,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_bind_XXXX");
+ if (SQLITE_OK != sqlite3_reset (plugin->updPrio))
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_reset");
+ return GNUNET_SYSERR;
- }
+ }
n = sqlite3_step (plugin->updPrio);
if (SQLITE_OK != sqlite3_reset (plugin->updPrio))
LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
- switch (n)
- {
- case SQLITE_DONE:
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_reset");
+ switch (n)
+ {
+ case SQLITE_DONE:
#if DEBUG_SQLITE
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "sqlite",
- "Block updated\n");
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", "Block updated\n");
#endif
- return GNUNET_OK;
- case SQLITE_BUSY:
- LOG_SQLITE (plugin, msg,
- GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
- "sqlite3_step");
- return GNUNET_NO;
- default:
- LOG_SQLITE (plugin, msg,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "sqlite3_step");
- return GNUNET_SYSERR;
- }
+ return GNUNET_OK;
+ case SQLITE_BUSY:
+ LOG_SQLITE (plugin, msg,
+ GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_step");
+ return GNUNET_NO;
+ default:
+ LOG_SQLITE (plugin, msg,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_step");
+ return GNUNET_SYSERR;
+ }
}
@@ -683,8 +674,7 @@ sqlite_plugin_update (void *cls,
*/
static void
execute_get (struct Plugin *plugin,
- sqlite3_stmt *stmt,
- PluginDatumProcessor proc, void *proc_cls)
+ sqlite3_stmt * stmt, PluginDatumProcessor proc, void *proc_cls)
{
int n;
struct GNUNET_TIME_Absolute expiration;
@@ -694,80 +684,74 @@ execute_get (struct Plugin *plugin,
n = sqlite3_step (stmt);
switch (n)
+ {
+ case SQLITE_ROW:
+ size = sqlite3_column_bytes (stmt, 5);
+ rowid = sqlite3_column_int64 (stmt, 6);
+ if (sqlite3_column_bytes (stmt, 4) != sizeof (GNUNET_HashCode))
{
- case SQLITE_ROW:
- size = sqlite3_column_bytes (stmt, 5);
- rowid = sqlite3_column_int64 (stmt, 6);
- if (sqlite3_column_bytes (stmt, 4) != sizeof (GNUNET_HashCode))
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
- "sqlite",
- _("Invalid data in database. Trying to fix (by deletion).\n"));
- if (SQLITE_OK != sqlite3_reset (stmt))
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR |
- GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
- if (GNUNET_OK == delete_by_rowid (plugin, rowid))
- plugin->env->duc (plugin->env->cls,
- - (size + GNUNET_DATASTORE_ENTRY_OVERHEAD));
- break;
- }
- expiration.abs_value = sqlite3_column_int64 (stmt, 3);
-#if DEBUG_SQLITE
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "sqlite",
- "Found reply in database with expiration %llu\n",
- (unsigned long long) expiration.abs_value);
-#endif
- ret = proc (proc_cls,
- sqlite3_column_blob (stmt, 4) /* key */,
- size,
- sqlite3_column_blob (stmt, 5) /* data */,
- sqlite3_column_int (stmt, 0) /* type */,
- sqlite3_column_int (stmt, 1) /* priority */,
- sqlite3_column_int (stmt, 2) /* anonymity */,
- expiration,
- rowid);
- if (SQLITE_OK != sqlite3_reset (stmt))
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR |
- GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
- if ( (GNUNET_NO == ret) &&
- (GNUNET_OK == delete_by_rowid (plugin, rowid)) )
- plugin->env->duc (plugin->env->cls,
- - (size + GNUNET_DATASTORE_ENTRY_OVERHEAD));
- return;
- case SQLITE_DONE:
- /* database must be empty */
- if (SQLITE_OK != sqlite3_reset (stmt))
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR |
- GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
- break;
- case SQLITE_BUSY:
- case SQLITE_ERROR:
- case SQLITE_MISUSE:
- default:
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "sqlite3_step");
+ GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
+ "sqlite",
+ _
+ ("Invalid data in database. Trying to fix (by deletion).\n"));
if (SQLITE_OK != sqlite3_reset (stmt))
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR |
- GNUNET_ERROR_TYPE_BULK,
- "sqlite3_reset");
- GNUNET_break (0);
- database_shutdown (plugin);
- database_setup (plugin->env->cfg,
- plugin);
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
+ if (GNUNET_OK == delete_by_rowid (plugin, rowid))
+ plugin->env->duc (plugin->env->cls,
+ -(size + GNUNET_DATASTORE_ENTRY_OVERHEAD));
break;
}
+ expiration.abs_value = sqlite3_column_int64 (stmt, 3);
+#if DEBUG_SQLITE
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "sqlite",
+ "Found reply in database with expiration %llu\n",
+ (unsigned long long) expiration.abs_value);
+#endif
+ ret = proc (proc_cls, sqlite3_column_blob (stmt, 4) /* key */ ,
+ size, sqlite3_column_blob (stmt, 5) /* data */ ,
+ sqlite3_column_int (stmt, 0) /* type */ ,
+ sqlite3_column_int (stmt, 1) /* priority */ ,
+ sqlite3_column_int (stmt, 2) /* anonymity */ ,
+ expiration, rowid);
+ if (SQLITE_OK != sqlite3_reset (stmt))
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
+ if ((GNUNET_NO == ret) && (GNUNET_OK == delete_by_rowid (plugin, rowid)))
+ plugin->env->duc (plugin->env->cls,
+ -(size + GNUNET_DATASTORE_ENTRY_OVERHEAD));
+ return;
+ case SQLITE_DONE:
+ /* database must be empty */
+ if (SQLITE_OK != sqlite3_reset (stmt))
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
+ break;
+ case SQLITE_BUSY:
+ case SQLITE_ERROR:
+ case SQLITE_MISUSE:
+ default:
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_step");
+ if (SQLITE_OK != sqlite3_reset (stmt))
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
+ GNUNET_break (0);
+ database_shutdown (plugin);
+ database_setup (plugin->env->cfg, plugin);
+ break;
+ }
if (SQLITE_OK != sqlite3_reset (stmt))
LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR |
- GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
- proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
}
@@ -787,31 +771,28 @@ execute_get (struct Plugin *plugin,
*/
static void
sqlite_plugin_get_zero_anonymity (void *cls,
- uint64_t offset,
- enum GNUNET_BLOCK_Type type,
- PluginDatumProcessor proc,
- void *proc_cls)
+ uint64_t offset,
+ enum GNUNET_BLOCK_Type type,
+ PluginDatumProcessor proc, void *proc_cls)
{
struct Plugin *plugin = cls;
sqlite3_stmt *stmt;
GNUNET_assert (type != GNUNET_BLOCK_TYPE_ANY);
stmt = plugin->selZeroAnon;
- if ( (SQLITE_OK != sqlite3_bind_int (stmt, 1, type)) ||
- (SQLITE_OK != sqlite3_bind_int64 (stmt, 2, offset)) )
- {
+ if ((SQLITE_OK != sqlite3_bind_int (stmt, 1, type)) ||
+ (SQLITE_OK != sqlite3_bind_int64 (stmt, 2, offset)))
+ {
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_bind_XXXX");
+ if (SQLITE_OK != sqlite3_reset (stmt))
LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "sqlite3_bind_XXXX");
- if (SQLITE_OK != sqlite3_reset (stmt))
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR |
- GNUNET_ERROR_TYPE_BULK,
- "sqlite3_reset");
- proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
+ GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
execute_get (plugin, stmt, proc, proc_cls);
}
@@ -836,11 +817,11 @@ sqlite_plugin_get_zero_anonymity (void *cls,
*/
static void
sqlite_plugin_get_key (void *cls,
- uint64_t offset,
- const GNUNET_HashCode *key,
- const GNUNET_HashCode *vhash,
- enum GNUNET_BLOCK_Type type,
- PluginDatumProcessor proc, void *proc_cls)
+ uint64_t offset,
+ const GNUNET_HashCode * key,
+ const GNUNET_HashCode * vhash,
+ enum GNUNET_BLOCK_Type type,
+ PluginDatumProcessor proc, void *proc_cls)
{
struct Plugin *plugin = cls;
int ret;
@@ -855,48 +836,47 @@ sqlite_plugin_get_key (void *cls,
GNUNET_snprintf (scratch, sizeof (scratch),
"SELECT count(*) FROM gn090 WHERE hash=?%s%s",
vhash == NULL ? "" : " AND vhash=?",
- type == 0 ? "" : " AND type=?");
+ type == 0 ? "" : " AND type=?");
if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK)
- {
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite_prepare");
- proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
+ {
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite_prepare");
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
sqoff = 1;
ret = sqlite3_bind_blob (stmt, sqoff++,
key, sizeof (GNUNET_HashCode), SQLITE_TRANSIENT);
if ((vhash != NULL) && (ret == SQLITE_OK))
ret = sqlite3_bind_blob (stmt, sqoff++,
- vhash,
- sizeof (GNUNET_HashCode), SQLITE_TRANSIENT);
+ vhash, sizeof (GNUNET_HashCode), SQLITE_TRANSIENT);
if ((type != 0) && (ret == SQLITE_OK))
ret = sqlite3_bind_int (stmt, sqoff++, type);
if (SQLITE_OK != ret)
- {
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR, "sqlite_bind");
- sqlite3_finalize (stmt);
- proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
+ {
+ LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite_bind");
+ sqlite3_finalize (stmt);
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
ret = sqlite3_step (stmt);
if (ret != SQLITE_ROW)
- {
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR| GNUNET_ERROR_TYPE_BULK,
- "sqlite_step");
- sqlite3_finalize (stmt);
- proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
+ {
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite_step");
+ sqlite3_finalize (stmt);
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
total = sqlite3_column_int (stmt, 0);
sqlite3_finalize (stmt);
if (0 == total)
- {
- proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
+ {
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
limit_off = (int) (offset % total);
if (limit_off < 0)
limit_off += total;
@@ -907,36 +887,33 @@ sqlite_plugin_get_key (void *cls,
vhash == NULL ? "" : " AND vhash=?",
type == 0 ? "" : " AND type=?");
if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK)
- {
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR |
- GNUNET_ERROR_TYPE_BULK, "sqlite_prepare");
- proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
+ {
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "sqlite_prepare");
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
sqoff = 1;
ret = sqlite3_bind_blob (stmt,
- sqoff++,
- key,
- sizeof (GNUNET_HashCode),
- SQLITE_TRANSIENT);
+ sqoff++,
+ key, sizeof (GNUNET_HashCode), SQLITE_TRANSIENT);
if ((vhash != NULL) && (ret == SQLITE_OK))
ret = sqlite3_bind_blob (stmt,
- sqoff++,
- vhash,
- sizeof (GNUNET_HashCode), SQLITE_TRANSIENT);
+ sqoff++,
+ vhash, sizeof (GNUNET_HashCode), SQLITE_TRANSIENT);
if ((type != 0) && (ret == SQLITE_OK))
ret = sqlite3_bind_int (stmt, sqoff++, type);
if (ret == SQLITE_OK)
ret = sqlite3_bind_int64 (stmt, sqoff++, limit_off);
if (ret != SQLITE_OK)
- {
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR |
- GNUNET_ERROR_TYPE_BULK, "sqlite_bind");
- proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
+ {
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "sqlite_bind");
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
execute_get (plugin, stmt, proc, proc_cls);
sqlite3_finalize (stmt);
}
@@ -948,12 +925,12 @@ sqlite_plugin_get_key (void *cls,
*/
struct ReplCtx
{
-
+
/**
* Function to call for the result (or the NULL).
*/
PluginDatumProcessor proc;
-
+
/**
* Closure for proc.
*/
@@ -992,28 +969,24 @@ struct ReplCtx
*/
static int
repl_proc (void *cls,
- const GNUNET_HashCode *key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute expiration,
- uint64_t uid)
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct ReplCtx *rc = cls;
int ret;
ret = rc->proc (rc->proc_cls,
- key,
- size, data,
- type, priority, anonymity, expiration,
- uid);
+ key, size, data, type, priority, anonymity, expiration, uid);
if (key != NULL)
- {
- rc->uid = uid;
- rc->have_uid = GNUNET_YES;
- }
+ {
+ rc->uid = uid;
+ rc->have_uid = GNUNET_YES;
+ }
return ret;
}
@@ -1030,7 +1003,7 @@ repl_proc (void *cls,
*/
static void
sqlite_plugin_get_replication (void *cls,
- PluginDatumProcessor proc, void *proc_cls)
+ PluginDatumProcessor proc, void *proc_cls)
{
struct Plugin *plugin = cls;
struct ReplCtx rc;
@@ -1040,76 +1013,77 @@ sqlite_plugin_get_replication (void *cls,
#if DEBUG_SQLITE
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "sqlite",
- "Getting random block based on replication order.\n");
+ "sqlite",
+ "Getting random block based on replication order.\n");
#endif
rc.have_uid = GNUNET_NO;
rc.proc = proc;
rc.proc_cls = proc_cls;
stmt = plugin->maxRepl;
if (SQLITE_ROW != sqlite3_step (stmt))
- {
- if (SQLITE_OK != sqlite3_reset (stmt))
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR |
- GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
- /* DB empty */
- proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
+ {
+ if (SQLITE_OK != sqlite3_reset (stmt))
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
+ /* DB empty */
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
repl = sqlite3_column_int (stmt, 0);
if (SQLITE_OK != sqlite3_reset (stmt))
LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR |
- GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
+ GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
stmt = plugin->selRepl;
rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
if (SQLITE_OK != sqlite3_bind_int64 (stmt, 1, rvalue))
- {
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite3_bind_XXXX");
- if (SQLITE_OK != sqlite3_reset (stmt))
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
- proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
+ {
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_bind_XXXX");
+ if (SQLITE_OK != sqlite3_reset (stmt))
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_reset");
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
if (SQLITE_OK != sqlite3_bind_int (stmt, 2, repl))
- {
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite3_bind_XXXX");
- if (SQLITE_OK != sqlite3_reset (stmt))
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
- proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
- execute_get (plugin, stmt, &repl_proc, &rc);
+ {
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_bind_XXXX");
+ if (SQLITE_OK != sqlite3_reset (stmt))
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_reset");
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
+ execute_get (plugin, stmt, &repl_proc, &rc);
if (GNUNET_YES == rc.have_uid)
+ {
+ if (SQLITE_OK != sqlite3_bind_int64 (plugin->updRepl, 1, rc.uid))
{
- if (SQLITE_OK !=
- sqlite3_bind_int64 (plugin->updRepl, 1, rc.uid))
- {
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite3_bind_XXXX");
- if (SQLITE_OK != sqlite3_reset (plugin->updRepl))
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR |
- GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
- return;
- }
- if (SQLITE_DONE != sqlite3_step (plugin->updRepl))
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR |
- GNUNET_ERROR_TYPE_BULK, "sqlite3_step");
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_bind_XXXX");
if (SQLITE_OK != sqlite3_reset (plugin->updRepl))
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR |
- GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
+ return;
}
+ if (SQLITE_DONE != sqlite3_step (plugin->updRepl))
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "sqlite3_step");
+ if (SQLITE_OK != sqlite3_reset (plugin->updRepl))
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
+ }
}
@@ -1124,7 +1098,7 @@ sqlite_plugin_get_replication (void *cls,
*/
static void
sqlite_plugin_get_expiration (void *cls,
- PluginDatumProcessor proc, void *proc_cls)
+ PluginDatumProcessor proc, void *proc_cls)
{
struct Plugin *plugin = cls;
sqlite3_stmt *stmt;
@@ -1132,22 +1106,23 @@ sqlite_plugin_get_expiration (void *cls,
#if DEBUG_SQLITE
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "sqlite",
- "Getting random block based on expiration and priority order.\n");
+ "sqlite",
+ "Getting random block based on expiration and priority order.\n");
#endif
now = GNUNET_TIME_absolute_get ();
stmt = plugin->selExpi;
if (SQLITE_OK != sqlite3_bind_int64 (stmt, 1, now.abs_value))
- {
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite3_bind_XXXX");
- if (SQLITE_OK != sqlite3_reset (stmt))
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
- proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
+ {
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_bind_XXXX");
+ if (SQLITE_OK != sqlite3_reset (stmt))
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_reset");
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
execute_get (plugin, stmt, proc, proc_cls);
}
@@ -1157,10 +1132,11 @@ sqlite_plugin_get_expiration (void *cls,
*
* @param cls our plugin context
*/
-static void
+static void
sqlite_plugin_drop (void *cls)
{
struct Plugin *plugin = cls;
+
plugin->drop_on_shutdown = GNUNET_YES;
}
@@ -1179,48 +1155,40 @@ sqlite_plugin_estimate_size (void *cls)
sqlite3_stmt *stmt;
uint64_t pages;
uint64_t page_size;
+
#if ENULL_DEFINED
char *e;
#endif
if (SQLITE_VERSION_NUMBER < 3006000)
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
- "datastore-sqlite",
- _("sqlite version to old to determine size, assuming zero\n"));
- return 0;
- }
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "VACUUM", NULL, NULL, ENULL));
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA auto_vacuum=INCREMENTAL", NULL, NULL, ENULL));
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
+ "datastore-sqlite",
+ _
+ ("sqlite version to old to determine size, assuming zero\n"));
+ return 0;
+ }
+ CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh, "VACUUM", NULL, NULL, ENULL));
CHECK (SQLITE_OK ==
- sq_prepare (plugin->dbh,
- "PRAGMA page_count",
- &stmt));
- if (SQLITE_ROW ==
- sqlite3_step (stmt))
+ sqlite3_exec (plugin->dbh,
+ "PRAGMA auto_vacuum=INCREMENTAL", NULL, NULL, ENULL));
+ CHECK (SQLITE_OK == sq_prepare (plugin->dbh, "PRAGMA page_count", &stmt));
+ if (SQLITE_ROW == sqlite3_step (stmt))
pages = sqlite3_column_int64 (stmt, 0);
else
pages = 0;
sqlite3_finalize (stmt);
- CHECK (SQLITE_OK ==
- sq_prepare (plugin->dbh,
- "PRAGMA page_size",
- &stmt));
- CHECK (SQLITE_ROW ==
- sqlite3_step (stmt));
+ CHECK (SQLITE_OK == sq_prepare (plugin->dbh, "PRAGMA page_size", &stmt));
+ CHECK (SQLITE_ROW == sqlite3_step (stmt));
page_size = sqlite3_column_int64 (stmt, 0);
sqlite3_finalize (stmt);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Using sqlite page utilization to estimate payload (%llu pages of size %llu bytes)\n"),
- (unsigned long long) pages,
- (unsigned long long) page_size);
- return pages * page_size;
+ _
+ ("Using sqlite page utilization to estimate payload (%llu pages of size %llu bytes)\n"),
+ (unsigned long long) pages, (unsigned long long) page_size);
+ return pages * page_size;
}
-
+
/**
* Entry point for the plugin.
@@ -1236,15 +1204,14 @@ libgnunet_plugin_datastore_sqlite_init (void *cls)
struct GNUNET_DATASTORE_PluginFunctions *api;
if (plugin.env != NULL)
- return NULL; /* can only initialize once! */
- memset (&plugin, 0, sizeof(struct Plugin));
+ return NULL; /* can only initialize once! */
+ memset (&plugin, 0, sizeof (struct Plugin));
plugin.env = env;
- if (GNUNET_OK !=
- database_setup (env->cfg, &plugin))
- {
- database_shutdown (&plugin);
- return NULL;
- }
+ if (GNUNET_OK != database_setup (env->cfg, &plugin))
+ {
+ database_shutdown (&plugin);
+ return NULL;
+ }
api = GNUNET_malloc (sizeof (struct GNUNET_DATASTORE_PluginFunctions));
api->cls = &plugin;
api->estimate_size = &sqlite_plugin_estimate_size;
@@ -1276,8 +1243,7 @@ libgnunet_plugin_datastore_sqlite_done (void *cls)
#if DEBUG_SQLITE
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "sqlite",
- "sqlite plugin is done\n");
+ "sqlite", "sqlite plugin is done\n");
#endif
fn = NULL;
@@ -1285,24 +1251,20 @@ libgnunet_plugin_datastore_sqlite_done (void *cls)
fn = GNUNET_strdup (plugin->fn);
#if DEBUG_SQLITE
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "sqlite",
- "Shutting down database\n");
+ "sqlite", "Shutting down database\n");
#endif
database_shutdown (plugin);
- plugin->env = NULL;
+ plugin->env = NULL;
GNUNET_free (api);
if (fn != NULL)
- {
- if (0 != UNLINK(fn))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "unlink",
- fn);
- GNUNET_free (fn);
- }
+ {
+ if (0 != UNLINK (fn))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
+ GNUNET_free (fn);
+ }
#if DEBUG_SQLITE
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "sqlite",
- "sqlite plugin is finished\n");
+ "sqlite", "sqlite plugin is finished\n");
#endif
return NULL;
}
diff --git a/src/datastore/plugin_datastore_template.c b/src/datastore/plugin_datastore_template.c
index 8975c0a701..7ab4691409 100644
--- a/src/datastore/plugin_datastore_template.c
+++ b/src/datastore/plugin_datastore_template.c
@@ -31,7 +31,7 @@
/**
* Context for all functions in this plugin.
*/
-struct Plugin
+struct Plugin
{
/**
* Our execution environment.
@@ -47,7 +47,7 @@ struct Plugin
* @param cls our "struct Plugin*"
* @return number of bytes used on disk
*/
-static unsigned long long
+static unsigned long long
template_plugin_estimate_size (void *cls)
{
GNUNET_break (0);
@@ -72,15 +72,14 @@ template_plugin_estimate_size (void *cls)
*/
static int
template_plugin_put (void *cls,
- const GNUNET_HashCode * key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- uint32_t replication,
- struct GNUNET_TIME_Absolute expiration,
- char **msg)
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ uint32_t replication,
+ struct GNUNET_TIME_Absolute expiration, char **msg)
{
GNUNET_break (0);
*msg = GNUNET_strdup ("not implemented");
@@ -108,11 +107,11 @@ template_plugin_put (void *cls,
*/
static void
template_plugin_get_key (void *cls,
- uint64_t offset,
- const GNUNET_HashCode * key,
- const GNUNET_HashCode * vhash,
- enum GNUNET_BLOCK_Type type,
- PluginDatumProcessor proc, void *proc_cls)
+ uint64_t offset,
+ const GNUNET_HashCode * key,
+ const GNUNET_HashCode * vhash,
+ enum GNUNET_BLOCK_Type type,
+ PluginDatumProcessor proc, void *proc_cls)
{
GNUNET_break (0);
}
@@ -132,7 +131,7 @@ template_plugin_get_key (void *cls,
*/
static void
template_plugin_get_replication (void *cls,
- PluginDatumProcessor proc, void *proc_cls)
+ PluginDatumProcessor proc, void *proc_cls)
{
GNUNET_break (0);
}
@@ -148,7 +147,7 @@ template_plugin_get_replication (void *cls,
*/
static void
template_plugin_get_expiration (void *cls,
- PluginDatumProcessor proc, void *proc_cls)
+ PluginDatumProcessor proc, void *proc_cls)
{
GNUNET_break (0);
}
@@ -179,10 +178,9 @@ template_plugin_get_expiration (void *cls,
*/
static int
template_plugin_update (void *cls,
- uint64_t uid,
- int delta,
- struct GNUNET_TIME_Absolute expire,
- char **msg)
+ uint64_t uid,
+ int delta,
+ struct GNUNET_TIME_Absolute expire, char **msg)
{
GNUNET_break (0);
*msg = GNUNET_strdup ("not implemented");
@@ -204,10 +202,9 @@ template_plugin_update (void *cls,
*/
static void
template_plugin_get_zero_anonymity (void *cls,
- uint64_t offset,
- enum GNUNET_BLOCK_Type type,
- PluginDatumProcessor proc,
- void *proc_cls)
+ uint64_t offset,
+ enum GNUNET_BLOCK_Type type,
+ PluginDatumProcessor proc, void *proc_cls)
{
GNUNET_break (0);
}
@@ -216,7 +213,7 @@ template_plugin_get_zero_anonymity (void *cls,
/**
* Drop database.
*/
-static void
+static void
template_plugin_drop (void *cls)
{
GNUNET_break (0);
diff --git a/src/datastore/test_datastore_api.c b/src/datastore/test_datastore_api.c
index f25ee08c24..39b7a1ae23 100644
--- a/src/datastore/test_datastore_api.c
+++ b/src/datastore/test_datastore_api.c
@@ -63,34 +63,35 @@ get_size (int i)
static const void *
get_data (int i)
{
- static char buf[60000];
+ static char buf[60000];
+
memset (buf, i, 8 * i);
return buf;
}
static int
-get_type(int i)
+get_type (int i)
{
- return i+1;
+ return i + 1;
}
-static int
+static int
get_priority (int i)
{
- return i+1;
+ return i + 1;
}
static int
-get_anonymity(int i)
+get_anonymity (int i)
{
return i;
}
-static struct GNUNET_TIME_Absolute
+static struct GNUNET_TIME_Absolute
get_expiration (int i)
{
struct GNUNET_TIME_Absolute av;
@@ -100,22 +101,22 @@ get_expiration (int i)
}
enum RunPhase
- {
- RP_DONE = 0,
- RP_PUT = 1,
- RP_GET = 2,
- RP_DEL = 3,
- RP_DO_DEL = 4,
- RP_DELVALIDATE = 5,
- RP_RESERVE = 6,
- RP_PUT_MULTIPLE = 7,
- RP_PUT_MULTIPLE_NEXT = 8,
- RP_GET_MULTIPLE = 9,
- RP_GET_MULTIPLE_NEXT = 10,
- RP_UPDATE = 11,
- RP_UPDATE_VALIDATE = 12,
- RP_ERROR
- };
+{
+ RP_DONE = 0,
+ RP_PUT = 1,
+ RP_GET = 2,
+ RP_DEL = 3,
+ RP_DO_DEL = 4,
+ RP_DELVALIDATE = 5,
+ RP_RESERVE = 6,
+ RP_PUT_MULTIPLE = 7,
+ RP_PUT_MULTIPLE_NEXT = 8,
+ RP_GET_MULTIPLE = 9,
+ RP_GET_MULTIPLE_NEXT = 10,
+ RP_UPDATE = 11,
+ RP_UPDATE_VALIDATE = 12,
+ RP_ERROR
+};
struct CpsRunContext
@@ -134,62 +135,52 @@ struct CpsRunContext
static void
-run_continuation (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
static void
-check_success (void *cls,
- int success,
- const char *msg)
+check_success (void *cls, int success, const char *msg)
{
struct CpsRunContext *crc = cls;
if (GNUNET_OK != success)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Operation %d/%d not successfull: `%s'\n",
- crc->phase,
- crc->i,
- msg);
- crc->phase = RP_ERROR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Operation %d/%d not successfull: `%s'\n",
+ crc->phase, crc->i, msg);
+ crc->phase = RP_ERROR;
+ }
GNUNET_free_non_null (crc->data);
crc->data = NULL;
GNUNET_SCHEDULER_add_continuation (&run_continuation,
- crc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
static void
-get_reserved (void *cls,
- int success,
- const char *msg)
+get_reserved (void *cls, int success, const char *msg)
{
struct CpsRunContext *crc = cls;
+
if (0 >= success)
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Error obtaining reservation: `%s'\n",
- msg);
+ "Error obtaining reservation: `%s'\n", msg);
GNUNET_assert (0 < success);
crc->rid = success;
GNUNET_SCHEDULER_add_continuation (&run_continuation,
- crc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
-static void
+static void
check_value (void *cls,
- const GNUNET_HashCode * key,
- size_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute expiration,
- uint64_t uid)
+ const GNUNET_HashCode * key,
+ size_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct CpsRunContext *crc = cls;
int i;
@@ -197,46 +188,42 @@ check_value (void *cls,
i = crc->i;
#if 0
fprintf (stderr,
- "Check value got `%s' of size %u, type %d, expire %llu\n",
- GNUNET_h2s (key),
- (unsigned int) size,
- type,
- (unsigned long long) expiration.abs_value);
+ "Check value got `%s' of size %u, type %d, expire %llu\n",
+ GNUNET_h2s (key),
+ (unsigned int) size,
+ type, (unsigned long long) expiration.abs_value);
fprintf (stderr,
- "Check value iteration %d wants size %u, type %d, expire %llu\n",
- i,
- (unsigned int) get_size (i),
- get_type (i),
- (unsigned long long) get_expiration(i).abs_value);
+ "Check value iteration %d wants size %u, type %d, expire %llu\n",
+ i,
+ (unsigned int) get_size (i),
+ get_type (i), (unsigned long long) get_expiration (i).abs_value);
#endif
GNUNET_assert (size == get_size (i));
- GNUNET_assert (0 == memcmp (data, get_data(i), size));
+ GNUNET_assert (0 == memcmp (data, get_data (i), size));
GNUNET_assert (type == get_type (i));
GNUNET_assert (priority == get_priority (i));
- GNUNET_assert (anonymity == get_anonymity(i));
- GNUNET_assert (expiration.abs_value == get_expiration(i).abs_value);
+ GNUNET_assert (anonymity == get_anonymity (i));
+ GNUNET_assert (expiration.abs_value == get_expiration (i).abs_value);
crc->offset++;
if (crc->i == 0)
- {
- crc->phase = RP_DEL;
- crc->i = ITERATIONS;
- }
+ {
+ crc->phase = RP_DEL;
+ crc->i = ITERATIONS;
+ }
GNUNET_SCHEDULER_add_continuation (&run_continuation,
- crc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
-static void
+static void
delete_value (void *cls,
- const GNUNET_HashCode *key,
- size_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute
- expiration, uint64_t uid)
+ const GNUNET_HashCode * key,
+ size_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct CpsRunContext *crc = cls;
@@ -248,21 +235,19 @@ delete_value (void *cls,
memcpy (crc->data, data, size);
crc->phase = RP_DO_DEL;
GNUNET_SCHEDULER_add_continuation (&run_continuation,
- crc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
-static void
+static void
check_nothing (void *cls,
- const GNUNET_HashCode *key,
- size_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute
- expiration, uint64_t uid)
+ const GNUNET_HashCode * key,
+ size_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct CpsRunContext *crc = cls;
@@ -270,352 +255,310 @@ check_nothing (void *cls,
if (crc->i == 0)
crc->phase = RP_RESERVE;
GNUNET_SCHEDULER_add_continuation (&run_continuation,
- crc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
-static void
+static void
check_multiple (void *cls,
- const GNUNET_HashCode * key,
- size_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute
- expiration, uint64_t uid)
+ const GNUNET_HashCode * key,
+ size_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct CpsRunContext *crc = cls;
GNUNET_assert (key != NULL);
switch (crc->phase)
- {
- case RP_GET_MULTIPLE:
- crc->phase = RP_GET_MULTIPLE_NEXT;
- crc->first_uid = uid;
- crc->offset++;
- break;
- case RP_GET_MULTIPLE_NEXT:
- GNUNET_assert (uid != crc->first_uid);
- crc->phase = RP_UPDATE;
- break;
- default:
- GNUNET_break (0);
- crc->phase = RP_ERROR;
- break;
- }
+ {
+ case RP_GET_MULTIPLE:
+ crc->phase = RP_GET_MULTIPLE_NEXT;
+ crc->first_uid = uid;
+ crc->offset++;
+ break;
+ case RP_GET_MULTIPLE_NEXT:
+ GNUNET_assert (uid != crc->first_uid);
+ crc->phase = RP_UPDATE;
+ break;
+ default:
+ GNUNET_break (0);
+ crc->phase = RP_ERROR;
+ break;
+ }
if (priority == get_priority (42))
crc->uid = uid;
GNUNET_SCHEDULER_add_continuation (&run_continuation,
- crc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
-static void
+static void
check_update (void *cls,
- const GNUNET_HashCode * key,
- size_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute
- expiration, uint64_t uid)
+ const GNUNET_HashCode * key,
+ size_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct CpsRunContext *crc = cls;
GNUNET_assert (key != NULL);
- if ( (anonymity == get_anonymity (42)) &&
- (size == get_size (42)) &&
- (priority == get_priority (42) + 100) )
- crc->phase = RP_DONE;
+ if ((anonymity == get_anonymity (42)) &&
+ (size == get_size (42)) && (priority == get_priority (42) + 100))
+ crc->phase = RP_DONE;
else
- {
- GNUNET_assert (size == get_size (43));
- crc->offset++;
- }
+ {
+ GNUNET_assert (size == get_size (43));
+ crc->offset++;
+ }
GNUNET_SCHEDULER_add_continuation (&run_continuation,
- crc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
static void
-run_continuation (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct CpsRunContext *crc = cls;
+
ok = (int) crc->phase;
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Test in phase %u\n", crc->phase);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test in phase %u\n", crc->phase);
#endif
switch (crc->phase)
- {
- case RP_PUT:
+ {
+ case RP_PUT:
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Executing `%s' number %u\n",
- "PUT",
- crc->i);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Executing `%s' number %u\n", "PUT", crc->i);
#endif
- GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
- GNUNET_DATASTORE_put (datastore,
- 0,
- &crc->key,
- get_size (crc->i),
- get_data (crc->i),
- get_type (crc->i),
- get_priority (crc->i),
- get_anonymity (crc->i),
- 0,
- get_expiration (crc->i),
- 1, 1, TIMEOUT,
- &check_success,
- crc);
- crc->i++;
- if (crc->i == ITERATIONS)
- crc->phase = RP_GET;
- break;
- case RP_GET:
- crc->i--;
+ GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
+ GNUNET_DATASTORE_put (datastore,
+ 0,
+ &crc->key,
+ get_size (crc->i),
+ get_data (crc->i),
+ get_type (crc->i),
+ get_priority (crc->i),
+ get_anonymity (crc->i),
+ 0,
+ get_expiration (crc->i),
+ 1, 1, TIMEOUT, &check_success, crc);
+ crc->i++;
+ if (crc->i == ITERATIONS)
+ crc->phase = RP_GET;
+ break;
+ case RP_GET:
+ crc->i--;
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Executing `%s' number %u\n",
- "GET",
- crc->i);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Executing `%s' number %u\n", "GET", crc->i);
#endif
- GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
- GNUNET_DATASTORE_get_key (datastore,
- crc->offset,
- &crc->key,
- get_type (crc->i),
- 1, 1, TIMEOUT,
- &check_value,
- crc);
- break;
- case RP_DEL:
- crc->i--;
+ GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
+ GNUNET_DATASTORE_get_key (datastore,
+ crc->offset,
+ &crc->key,
+ get_type (crc->i),
+ 1, 1, TIMEOUT, &check_value, crc);
+ break;
+ case RP_DEL:
+ crc->i--;
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Executing `%s' number %u\n",
- "DEL",
- crc->i);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Executing `%s' number %u\n", "DEL", crc->i);
#endif
- crc->data = NULL;
- GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
- GNUNET_assert (NULL !=
- GNUNET_DATASTORE_get_key (datastore,
- crc->offset,
- &crc->key,
- get_type (crc->i),
- 1, 1, TIMEOUT,
- &delete_value,
- crc));
- break;
- case RP_DO_DEL:
+ crc->data = NULL;
+ GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
+ GNUNET_assert (NULL !=
+ GNUNET_DATASTORE_get_key (datastore,
+ crc->offset,
+ &crc->key,
+ get_type (crc->i),
+ 1, 1, TIMEOUT,
+ &delete_value, crc));
+ break;
+ case RP_DO_DEL:
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Executing `%s' number %u\n",
- "DO_DEL",
- crc->i);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Executing `%s' number %u\n", "DO_DEL", crc->i);
#endif
- if (crc->i == 0)
- {
- crc->i = ITERATIONS;
- crc->phase = RP_DELVALIDATE;
- }
- else
- {
- crc->phase = RP_DEL;
- }
- GNUNET_assert (NULL !=
- GNUNET_DATASTORE_remove (datastore,
- &crc->key,
- crc->size,
- crc->data,
- 1, 1, TIMEOUT,
- &check_success,
- crc));
- break;
- case RP_DELVALIDATE:
- crc->i--;
+ if (crc->i == 0)
+ {
+ crc->i = ITERATIONS;
+ crc->phase = RP_DELVALIDATE;
+ }
+ else
+ {
+ crc->phase = RP_DEL;
+ }
+ GNUNET_assert (NULL !=
+ GNUNET_DATASTORE_remove (datastore,
+ &crc->key,
+ crc->size,
+ crc->data,
+ 1, 1, TIMEOUT,
+ &check_success, crc));
+ break;
+ case RP_DELVALIDATE:
+ crc->i--;
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Executing `%s' number %u\n",
- "DEL-VALIDATE",
- crc->i);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Executing `%s' number %u\n", "DEL-VALIDATE", crc->i);
#endif
- GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
- GNUNET_assert (NULL !=
- GNUNET_DATASTORE_get_key (datastore,
- crc->offset,
- &crc->key,
- get_type (crc->i),
- 1, 1, TIMEOUT,
- &check_nothing,
- crc));
- break;
- case RP_RESERVE:
- crc->phase = RP_PUT_MULTIPLE;
- GNUNET_DATASTORE_reserve (datastore,
- 128*1024,
- 2,
- 1, 1, TIMEOUT,
- &get_reserved,
- crc);
- break;
- case RP_PUT_MULTIPLE:
- crc->phase = RP_PUT_MULTIPLE_NEXT;
- GNUNET_DATASTORE_put (datastore,
- crc->rid,
- &crc->key,
- get_size (42),
- get_data (42),
- get_type (42),
- get_priority (42),
- get_anonymity (42),
- 0,
- get_expiration (42),
- 1, 1, TIMEOUT,
- &check_success,
- crc);
- break;
- case RP_PUT_MULTIPLE_NEXT:
- crc->phase = RP_GET_MULTIPLE;
- GNUNET_DATASTORE_put (datastore,
- crc->rid,
- &crc->key,
- get_size (43),
- get_data (43),
- get_type (42),
- get_priority (43),
- get_anonymity (43),
- 0,
- get_expiration (43),
- 1, 1, TIMEOUT,
- &check_success,
- crc);
- break;
- case RP_GET_MULTIPLE:
- GNUNET_assert (NULL !=
- GNUNET_DATASTORE_get_key (datastore,
- crc->offset,
- &crc->key,
- get_type (42),
- 1, 1, TIMEOUT,
- &check_multiple,
- crc));
- break;
- case RP_GET_MULTIPLE_NEXT:
- GNUNET_assert (NULL !=
- GNUNET_DATASTORE_get_key (datastore,
- crc->offset,
- &crc->key,
- get_type (42),
- 1, 1, TIMEOUT,
- &check_multiple,
- crc));
- break;
- case RP_UPDATE:
- GNUNET_assert (crc->uid > 0);
- crc->phase = RP_UPDATE_VALIDATE;
- GNUNET_DATASTORE_update (datastore,
- crc->uid,
- 100,
- get_expiration (42),
- 1, 1, TIMEOUT,
- &check_success,
- crc);
- break;
- case RP_UPDATE_VALIDATE:
- GNUNET_assert (NULL !=
- GNUNET_DATASTORE_get_key (datastore,
- crc->offset,
- &crc->key,
- get_type (42),
- 1, 1, TIMEOUT,
- &check_update,
- crc));
- break;
- case RP_DONE:
+ GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
+ GNUNET_assert (NULL !=
+ GNUNET_DATASTORE_get_key (datastore,
+ crc->offset,
+ &crc->key,
+ get_type (crc->i),
+ 1, 1, TIMEOUT,
+ &check_nothing, crc));
+ break;
+ case RP_RESERVE:
+ crc->phase = RP_PUT_MULTIPLE;
+ GNUNET_DATASTORE_reserve (datastore,
+ 128 * 1024, 2, 1, 1, TIMEOUT, &get_reserved, crc);
+ break;
+ case RP_PUT_MULTIPLE:
+ crc->phase = RP_PUT_MULTIPLE_NEXT;
+ GNUNET_DATASTORE_put (datastore,
+ crc->rid,
+ &crc->key,
+ get_size (42),
+ get_data (42),
+ get_type (42),
+ get_priority (42),
+ get_anonymity (42),
+ 0,
+ get_expiration (42),
+ 1, 1, TIMEOUT, &check_success, crc);
+ break;
+ case RP_PUT_MULTIPLE_NEXT:
+ crc->phase = RP_GET_MULTIPLE;
+ GNUNET_DATASTORE_put (datastore,
+ crc->rid,
+ &crc->key,
+ get_size (43),
+ get_data (43),
+ get_type (42),
+ get_priority (43),
+ get_anonymity (43),
+ 0,
+ get_expiration (43),
+ 1, 1, TIMEOUT, &check_success, crc);
+ break;
+ case RP_GET_MULTIPLE:
+ GNUNET_assert (NULL !=
+ GNUNET_DATASTORE_get_key (datastore,
+ crc->offset,
+ &crc->key,
+ get_type (42),
+ 1, 1, TIMEOUT,
+ &check_multiple, crc));
+ break;
+ case RP_GET_MULTIPLE_NEXT:
+ GNUNET_assert (NULL !=
+ GNUNET_DATASTORE_get_key (datastore,
+ crc->offset,
+ &crc->key,
+ get_type (42),
+ 1, 1, TIMEOUT,
+ &check_multiple, crc));
+ break;
+ case RP_UPDATE:
+ GNUNET_assert (crc->uid > 0);
+ crc->phase = RP_UPDATE_VALIDATE;
+ GNUNET_DATASTORE_update (datastore,
+ crc->uid,
+ 100,
+ get_expiration (42),
+ 1, 1, TIMEOUT, &check_success, crc);
+ break;
+ case RP_UPDATE_VALIDATE:
+ GNUNET_assert (NULL !=
+ GNUNET_DATASTORE_get_key (datastore,
+ crc->offset,
+ &crc->key,
+ get_type (42),
+ 1, 1, TIMEOUT,
+ &check_update, crc));
+ break;
+ case RP_DONE:
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Finished, disconnecting\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished, disconnecting\n");
#endif
- GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
- GNUNET_free (crc);
- ok = 0;
- break;
- case RP_ERROR:
- GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
- GNUNET_free (crc);
- ok = 43;
- break;
- }
+ GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
+ GNUNET_free (crc);
+ ok = 0;
+ break;
+ case RP_ERROR:
+ GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
+ GNUNET_free (crc);
+ ok = 43;
+ break;
+ }
}
static void
-run_tests (void *cls,
- int32_t success,
- const char *msg)
+run_tests (void *cls, int32_t success, const char *msg)
{
struct CpsRunContext *crc = cls;
switch (success)
- {
- case GNUNET_YES:
- GNUNET_SCHEDULER_add_continuation (&run_continuation,
- crc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- return;
- case GNUNET_NO:
- fprintf (stderr,
- "Test 'put' operation failed, key already exists (!?)\n");
- GNUNET_free (crc);
- return;
- case GNUNET_SYSERR:
- fprintf (stderr,
- "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n",
- msg);
- GNUNET_free (crc);
- return;
- default:
- GNUNET_assert (0);
- }
+ {
+ case GNUNET_YES:
+ GNUNET_SCHEDULER_add_continuation (&run_continuation,
+ crc,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ return;
+ case GNUNET_NO:
+ fprintf (stderr, "Test 'put' operation failed, key already exists (!?)\n");
+ GNUNET_free (crc);
+ return;
+ case GNUNET_SYSERR:
+ fprintf (stderr,
+ "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n",
+ msg);
+ GNUNET_free (crc);
+ return;
+ default:
+ GNUNET_assert (0);
+ }
}
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct CpsRunContext *crc;
static GNUNET_HashCode zkey;
- crc = GNUNET_malloc(sizeof(struct CpsRunContext));
+ crc = GNUNET_malloc (sizeof (struct CpsRunContext));
crc->cfg = cfg;
crc->phase = RP_PUT;
now = GNUNET_TIME_absolute_get ();
datastore = GNUNET_DATASTORE_connect (cfg);
if (NULL ==
GNUNET_DATASTORE_put (datastore, 0,
- &zkey, 4, "TEST",
- GNUNET_BLOCK_TYPE_TEST,
- 0, 0, 0, GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS),
- 0, 1, GNUNET_TIME_UNIT_MINUTES,
- &run_tests, crc))
- {
- fprintf (stderr,
- "Test 'put' operation failed.\n");
- ok = 1;
- GNUNET_free (crc);
- }
+ &zkey, 4, "TEST",
+ GNUNET_BLOCK_TYPE_TEST,
+ 0, 0, 0,
+ GNUNET_TIME_relative_to_absolute
+ (GNUNET_TIME_UNIT_SECONDS), 0, 1,
+ GNUNET_TIME_UNIT_MINUTES, &run_tests, crc))
+ {
+ fprintf (stderr, "Test 'put' operation failed.\n");
+ ok = 1;
+ GNUNET_free (crc);
+ }
}
@@ -623,6 +566,7 @@ static int
check ()
{
char cfg_name[128];
+
#if START_DATASTORE
struct GNUNET_OS_Process *proc;
#endif
@@ -639,28 +583,27 @@ check ()
GNUNET_GETOPT_OPTION_END
};
GNUNET_snprintf (cfg_name,
- sizeof (cfg_name),
- "test_datastore_api_data_%s.conf",
- plugin_name);
+ sizeof (cfg_name),
+ "test_datastore_api_data_%s.conf", plugin_name);
#if START_DATASTORE
proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfg_name, NULL);
+ "-c", cfg_name, NULL);
#endif
GNUNET_assert (NULL != proc);
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
argv, "test-datastore-api", "nohelp",
options, &run, NULL);
#if START_DATASTORE
- sleep (1); /* give datastore chance to receive 'DROP' request */
+ sleep (1); /* give datastore chance to receive 'DROP' request */
if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- ok = 1;
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ ok = 1;
+ }
GNUNET_OS_process_wait (proc);
GNUNET_OS_process_close (proc);
proc = NULL;
@@ -680,17 +623,16 @@ main (int argc, char *argv[])
sleep (1);
/* determine name of plugin to use */
plugin_name = argv[0];
- while (NULL != (pos = strstr(plugin_name, "_")))
- plugin_name = pos+1;
- if (NULL != (pos = strstr(plugin_name, ".")))
+ while (NULL != (pos = strstr (plugin_name, "_")))
+ plugin_name = pos + 1;
+ if (NULL != (pos = strstr (plugin_name, ".")))
pos[0] = 0;
else
pos = (char *) plugin_name;
GNUNET_snprintf (dir_name,
- sizeof (dir_name),
- "/tmp/test-gnunet-datastore-%s",
- plugin_name);
+ sizeof (dir_name),
+ "/tmp/test-gnunet-datastore-%s", plugin_name);
GNUNET_DISK_directory_remove (dir_name);
GNUNET_log_setup ("test-datastore-api",
#if VERBOSE
diff --git a/src/datastore/test_datastore_api_management.c b/src/datastore/test_datastore_api_management.c
index ca1df2cf9f..b2146a9150 100644
--- a/src/datastore/test_datastore_api_management.c
+++ b/src/datastore/test_datastore_api_management.c
@@ -47,7 +47,7 @@ static struct GNUNET_TIME_Absolute now;
static int ok;
-static const char* plugin_name;
+static const char *plugin_name;
static size_t
get_size (int i)
@@ -59,34 +59,35 @@ get_size (int i)
static const void *
get_data (int i)
{
- static char buf[60000];
+ static char buf[60000];
+
memset (buf, i, 8 + 8 * (i % 256));
return buf;
}
static int
-get_type(int i)
+get_type (int i)
{
return 1;
}
-static int
+static int
get_priority (int i)
{
- return i+1;
+ return i + 1;
}
static int
-get_anonymity(int i)
+get_anonymity (int i)
{
return i;
}
-static struct GNUNET_TIME_Absolute
+static struct GNUNET_TIME_Absolute
get_expiration (int i)
{
struct GNUNET_TIME_Absolute av;
@@ -96,12 +97,12 @@ get_expiration (int i)
}
enum RunPhase
- {
- RP_PUT,
- RP_GET,
- RP_DONE,
- RP_GET_FAIL
- };
+{
+ RP_PUT,
+ RP_GET,
+ RP_DONE,
+ RP_GET_FAIL
+};
struct CpsRunContext
@@ -117,77 +118,70 @@ struct CpsRunContext
static void
-run_continuation (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
static void
-check_success (void *cls,
- int success,
- const char *msg)
+check_success (void *cls, int success, const char *msg)
{
struct CpsRunContext *crc = cls;
+
if (GNUNET_OK != success)
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%s\n", msg);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", msg);
GNUNET_assert (GNUNET_OK == success);
GNUNET_free_non_null (crc->data);
crc->data = NULL;
GNUNET_SCHEDULER_add_continuation (&run_continuation,
- crc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
-static void
+static void
check_value (void *cls,
- const GNUNET_HashCode * key,
- size_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute expiration,
- uint64_t uid)
+ const GNUNET_HashCode * key,
+ size_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct CpsRunContext *crc = cls;
int i;
if (NULL == key)
- {
- crc->phase = RP_GET_FAIL;
- GNUNET_SCHEDULER_add_continuation (&run_continuation,
- crc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- return;
- }
+ {
+ crc->phase = RP_GET_FAIL;
+ GNUNET_SCHEDULER_add_continuation (&run_continuation,
+ crc,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ return;
+ }
i = crc->i;
GNUNET_assert (size == get_size (i));
- GNUNET_assert (0 == memcmp (data, get_data(i), size));
+ GNUNET_assert (0 == memcmp (data, get_data (i), size));
GNUNET_assert (type == get_type (i));
GNUNET_assert (priority == get_priority (i));
- GNUNET_assert (anonymity == get_anonymity(i));
- GNUNET_assert (expiration.abs_value == get_expiration(i).abs_value);
+ GNUNET_assert (anonymity == get_anonymity (i));
+ GNUNET_assert (expiration.abs_value == get_expiration (i).abs_value);
crc->offset++;
crc->i--;
if (crc->i == 0)
crc->phase = RP_DONE;
GNUNET_SCHEDULER_add_continuation (&run_continuation,
- crc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
-static void
+static void
check_nothing (void *cls,
- const GNUNET_HashCode * key,
- size_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute
- expiration, uint64_t uid)
+ const GNUNET_HashCode * key,
+ size_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct CpsRunContext *crc = cls;
@@ -195,143 +189,125 @@ check_nothing (void *cls,
if (0 == --crc->i)
crc->phase = RP_DONE;
GNUNET_SCHEDULER_add_continuation (&run_continuation,
- crc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
static void
-run_continuation (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct CpsRunContext *crc = cls;
+
ok = (int) crc->phase;
switch (crc->phase)
- {
- case RP_PUT:
+ {
+ case RP_PUT:
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Executing `%s' number %u\n",
- "PUT",
- crc->i);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Executing `%s' number %u\n", "PUT", crc->i);
#endif
- GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
- GNUNET_DATASTORE_put (datastore,
- 0,
- &crc->key,
- get_size (crc->i),
- get_data (crc->i),
- get_type (crc->i),
- get_priority (crc->i),
- get_anonymity (crc->i),
- 0,
- get_expiration (crc->i),
- 1, 1, TIMEOUT,
- &check_success,
- crc);
- crc->i++;
- if (crc->i == ITERATIONS)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Sleeping to give datastore time to clean up\n");
- sleep (1);
- crc->phase = RP_GET;
- crc->i--;
- }
- break;
- case RP_GET:
+ GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
+ GNUNET_DATASTORE_put (datastore,
+ 0,
+ &crc->key,
+ get_size (crc->i),
+ get_data (crc->i),
+ get_type (crc->i),
+ get_priority (crc->i),
+ get_anonymity (crc->i),
+ 0,
+ get_expiration (crc->i),
+ 1, 1, TIMEOUT, &check_success, crc);
+ crc->i++;
+ if (crc->i == ITERATIONS)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Sleeping to give datastore time to clean up\n");
+ sleep (1);
+ crc->phase = RP_GET;
+ crc->i--;
+ }
+ break;
+ case RP_GET:
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Executing `%s' number %u\n",
- "GET",
- crc->i);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Executing `%s' number %u\n", "GET", crc->i);
#endif
- GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
- GNUNET_DATASTORE_get_key (datastore,
- crc->offset++,
- &crc->key,
- get_type (crc->i),
- 1, 1, TIMEOUT,
- &check_value,
- crc);
- break;
- case RP_GET_FAIL:
+ GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
+ GNUNET_DATASTORE_get_key (datastore,
+ crc->offset++,
+ &crc->key,
+ get_type (crc->i),
+ 1, 1, TIMEOUT, &check_value, crc);
+ break;
+ case RP_GET_FAIL:
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Executing `%s' number %u\n",
- "GET(f)",
- crc->i);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Executing `%s' number %u\n", "GET(f)", crc->i);
#endif
- GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
- GNUNET_DATASTORE_get_key (datastore,
- crc->offset++,
- &crc->key,
- get_type (crc->i),
- 1, 1, TIMEOUT,
- &check_nothing,
- crc);
- break;
- case RP_DONE:
- GNUNET_assert (0 == crc->i);
+ GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
+ GNUNET_DATASTORE_get_key (datastore,
+ crc->offset++,
+ &crc->key,
+ get_type (crc->i),
+ 1, 1, TIMEOUT, &check_nothing, crc);
+ break;
+ case RP_DONE:
+ GNUNET_assert (0 == crc->i);
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Finished, disconnecting\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished, disconnecting\n");
#endif
- GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
- GNUNET_free (crc);
- ok = 0;
- }
+ GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
+ GNUNET_free (crc);
+ ok = 0;
+ }
}
static void
-run_tests (void *cls,
- int success,
- const char *msg)
+run_tests (void *cls, int success, const char *msg)
{
struct CpsRunContext *crc = cls;
if (success != GNUNET_YES)
- {
- fprintf (stderr,
- "Test 'put' operation failed with error `%s' database likely not setup, skipping test.",
- msg);
- GNUNET_free (crc);
- return;
- }
+ {
+ fprintf (stderr,
+ "Test 'put' operation failed with error `%s' database likely not setup, skipping test.",
+ msg);
+ GNUNET_free (crc);
+ return;
+ }
GNUNET_SCHEDULER_add_continuation (&run_continuation,
- crc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct CpsRunContext *crc;
static GNUNET_HashCode zkey;
- crc = GNUNET_malloc(sizeof(struct CpsRunContext));
+ crc = GNUNET_malloc (sizeof (struct CpsRunContext));
crc->cfg = cfg;
crc->phase = RP_PUT;
now = GNUNET_TIME_absolute_get ();
datastore = GNUNET_DATASTORE_connect (cfg);
if (NULL ==
GNUNET_DATASTORE_put (datastore, 0,
- &zkey, 4, "TEST",
- GNUNET_BLOCK_TYPE_TEST,
- 0, 0, 0, GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS),
- 0, 1, GNUNET_TIME_UNIT_MINUTES,
- &run_tests, crc))
- {
- fprintf (stderr,
- "Test 'put' operation failed.\n");
- GNUNET_free (crc);
- ok = 1;
- }
+ &zkey, 4, "TEST",
+ GNUNET_BLOCK_TYPE_TEST,
+ 0, 0, 0,
+ GNUNET_TIME_relative_to_absolute
+ (GNUNET_TIME_UNIT_SECONDS), 0, 1,
+ GNUNET_TIME_UNIT_MINUTES, &run_tests, crc))
+ {
+ fprintf (stderr, "Test 'put' operation failed.\n");
+ GNUNET_free (crc);
+ ok = 1;
+ }
}
@@ -341,7 +317,8 @@ check ()
{
struct GNUNET_OS_Process *proc;
char cfg_name[128];
- char *const argv[] = {
+
+ char *const argv[] = {
"test-datastore-api-management",
"-c",
cfg_name,
@@ -354,25 +331,24 @@ check ()
GNUNET_GETOPT_OPTION_END
};
GNUNET_snprintf (cfg_name,
- sizeof (cfg_name),
- "test_datastore_api_data_%s.conf",
- plugin_name);
+ sizeof (cfg_name),
+ "test_datastore_api_data_%s.conf", plugin_name);
proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfg_name, NULL);
+ "-c", cfg_name, NULL);
GNUNET_assert (NULL != proc);
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
argv, "test-datastore-api-management", "nohelp",
options, &run, NULL);
- sleep (1); /* give datastore chance to process 'DROP' request */
+ sleep (1); /* give datastore chance to process 'DROP' request */
if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- ok = 1;
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ ok = 1;
+ }
GNUNET_OS_process_wait (proc);
GNUNET_OS_process_close (proc);
proc = NULL;
@@ -385,24 +361,23 @@ int
main (int argc, char *argv[])
{
int ret;
-
+
char *pos;
char dir_name[128];
sleep (1);
/* determine name of plugin to use */
plugin_name = argv[0];
- while (NULL != (pos = strstr(plugin_name, "_")))
- plugin_name = pos+1;
- if (NULL != (pos = strstr(plugin_name, ".")))
+ while (NULL != (pos = strstr (plugin_name, "_")))
+ plugin_name = pos + 1;
+ if (NULL != (pos = strstr (plugin_name, ".")))
pos[0] = 0;
else
pos = (char *) plugin_name;
GNUNET_snprintf (dir_name,
- sizeof (dir_name),
- "/tmp/test-gnunet-datastore-%s",
- plugin_name);
+ sizeof (dir_name),
+ "/tmp/test-gnunet-datastore-%s", plugin_name);
GNUNET_DISK_directory_remove (dir_name);
GNUNET_log_setup ("test-datastore-api-management",
#if VERBOSE
diff --git a/src/datastore/test_plugin_datastore.c b/src/datastore/test_plugin_datastore.c
index 6ac2d7a6e0..15cca61f1a 100644
--- a/src/datastore/test_plugin_datastore.c
+++ b/src/datastore/test_plugin_datastore.c
@@ -46,22 +46,22 @@ static const char *plugin_name;
static int ok;
enum RunPhase
- {
- RP_ERROR = 0,
- RP_PUT,
- RP_GET,
- RP_UPDATE,
- RP_ITER_ZERO,
- RP_REPL_GET,
- RP_EXPI_GET,
- RP_DROP
- };
+{
+ RP_ERROR = 0,
+ RP_PUT,
+ RP_GET,
+ RP_UPDATE,
+ RP_ITER_ZERO,
+ RP_REPL_GET,
+ RP_EXPI_GET,
+ RP_DROP
+};
struct CpsRunContext
{
const struct GNUNET_CONFIGURATION_Handle *cfg;
- struct GNUNET_DATASTORE_PluginFunctions * api;
+ struct GNUNET_DATASTORE_PluginFunctions *api;
enum RunPhase phase;
unsigned int cnt;
unsigned int i;
@@ -78,27 +78,23 @@ struct CpsRunContext
* 0 for "reset to empty"
*/
static void
-disk_utilization_change_cb (void *cls,
- int delta)
+disk_utilization_change_cb (void *cls, int delta)
{
/* do nothing */
}
static void
-gen_key (int i,
- GNUNET_HashCode *key)
+gen_key (int i, GNUNET_HashCode * key)
{
memset (key, 0, sizeof (GNUNET_HashCode));
key->bits[0] = (unsigned int) i;
GNUNET_CRYPTO_hash (key, sizeof (GNUNET_HashCode), key);
}
-
+
static void
-put_value (struct GNUNET_DATASTORE_PluginFunctions * api,
- int i,
- int k)
+put_value (struct GNUNET_DATASTORE_PluginFunctions *api, int i, int k)
{
char value[65536];
size_t size;
@@ -109,7 +105,7 @@ put_value (struct GNUNET_DATASTORE_PluginFunctions * api,
/* most content is 32k */
size = 32 * 1024;
- if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /* but some of it is less! */
+ if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /* but some of it is less! */
size = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 32 * 1024);
size = size - (size & 7); /* always multiple of 8 */
@@ -122,37 +118,31 @@ put_value (struct GNUNET_DATASTORE_PluginFunctions * api,
msg = NULL;
prio = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
#if VERBOSE
- fprintf (stderr,
- "putting type %u, anon %u under key %s\n",
- i+1, i, GNUNET_h2s (&key));
+ fprintf (stderr,
+ "putting type %u, anon %u under key %s\n",
+ i + 1, i, GNUNET_h2s (&key));
#endif
- if (GNUNET_OK != api->put (api->cls,
- &key,
- size,
- value,
- i + 1 /* type */,
- prio,
- i /* anonymity */,
- 0 /* replication */,
- GNUNET_TIME_relative_to_absolute
- (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
- 60 * 60 * 60 * 1000 +
- GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000))),
- &msg))
- {
- fprintf (stderr, "ERROR: `%s'\n", msg);
- GNUNET_free_non_null (msg);
- return;
- }
+ if (GNUNET_OK != api->put (api->cls, &key, size, value, i + 1 /* type */ ,
+ prio, i /* anonymity */ ,
+ 0 /* replication */ ,
+ GNUNET_TIME_relative_to_absolute
+ (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS,
+ 60 * 60 * 60 * 1000 +
+ GNUNET_CRYPTO_random_u32
+ (GNUNET_CRYPTO_QUALITY_WEAK, 1000))), &msg))
+ {
+ fprintf (stderr, "ERROR: `%s'\n", msg);
+ GNUNET_free_non_null (msg);
+ return;
+ }
stored_bytes += size;
stored_ops++;
stored_entries++;
}
-static void
-test (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+static void test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
static uint64_t guid;
@@ -160,28 +150,25 @@ static uint64_t guid;
static int
iterate_one_shot (void *cls,
- const GNUNET_HashCode * key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute
- expiration,
- uint64_t uid)
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct CpsRunContext *crc = cls;
-
+
GNUNET_assert (key != NULL);
guid = uid;
crc->phase++;
#if VERBOSE
fprintf (stderr,
- "Found result type=%u, priority=%u, size=%u, expire=%llu, key %s\n",
- type, priority, size,
- (unsigned long long) expiration.abs_value,
- GNUNET_h2s (key));
-#endif
+ "Found result type=%u, priority=%u, size=%u, expire=%llu, key %s\n",
+ type, priority, size,
+ (unsigned long long) expiration.abs_value, GNUNET_h2s (key));
+#endif
GNUNET_SCHEDULER_add_now (&test, crc);
return GNUNET_OK;
}
@@ -195,8 +182,8 @@ iterate_one_shot (void *cls,
* @param cfg configuration to use
*/
static void
-unload_plugin (struct GNUNET_DATASTORE_PluginFunctions * api,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+unload_plugin (struct GNUNET_DATASTORE_PluginFunctions *api,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
char *name;
char *libname;
@@ -204,13 +191,12 @@ unload_plugin (struct GNUNET_DATASTORE_PluginFunctions * api,
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
"DATASTORE", "DATABASE", &name))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("No `%s' specified for `%s' in configuration!\n"),
- "DATABASE",
- "DATASTORE");
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("No `%s' specified for `%s' in configuration!\n"),
+ "DATABASE", "DATASTORE");
+ return;
+ }
GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name);
GNUNET_break (NULL == GNUNET_PLUGIN_unload (libname, api));
GNUNET_free (libname);
@@ -224,8 +210,7 @@ unload_plugin (struct GNUNET_DATASTORE_PluginFunctions * api,
* the transport and core.
*/
static void
-cleaning_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct CpsRunContext *crc = cls;
@@ -235,9 +220,8 @@ cleaning_task (void *cls,
static void
-test (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
+test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
struct CpsRunContext *crc = cls;
int j;
unsigned long long os;
@@ -245,91 +229,76 @@ test (void *cls,
GNUNET_HashCode key;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Test aborted.\n");
- crc->phase = RP_ERROR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Test aborted.\n");
+ crc->phase = RP_ERROR;
+ }
#if VERBOSE
- fprintf (stderr, "In phase %d, iteration %u\n",
- crc->phase,
- crc->cnt);
+ fprintf (stderr, "In phase %d, iteration %u\n", crc->phase, crc->cnt);
#endif
switch (crc->phase)
+ {
+ case RP_ERROR:
+ ok = 1;
+ GNUNET_break (0);
+ crc->api->drop (crc->api->cls);
+ GNUNET_SCHEDULER_add_now (&cleaning_task, crc);
+ break;
+ case RP_PUT:
+ os = 0;
+ for (j = 0; j < PUT_10; j++)
{
- case RP_ERROR:
- ok = 1;
- GNUNET_break (0);
- crc->api->drop (crc->api->cls);
- GNUNET_SCHEDULER_add_now (&cleaning_task, crc);
- break;
- case RP_PUT:
- os = 0;
- for (j=0;j<PUT_10;j++)
- {
- put_value (crc->api, j, crc->i);
- cs = crc->api->estimate_size (crc->api->cls);
- GNUNET_assert (os <= cs);
- os = cs;
- }
+ put_value (crc->api, j, crc->i);
+ cs = crc->api->estimate_size (crc->api->cls);
+ GNUNET_assert (os <= cs);
+ os = cs;
+ }
+ crc->phase++;
+ GNUNET_SCHEDULER_add_now (&test, crc);
+ break;
+ case RP_GET:
+ if (crc->cnt == 1)
+ {
+ crc->cnt = 0;
crc->phase++;
GNUNET_SCHEDULER_add_now (&test, crc);
break;
- case RP_GET:
- if (crc->cnt == 1)
- {
- crc->cnt = 0;
- crc->phase++;
- GNUNET_SCHEDULER_add_now (&test, crc);
- break;
- }
- gen_key (5, &key);
- crc->api->get_key (crc->api->cls,
- crc->offset++,
- &key, NULL,
- GNUNET_BLOCK_TYPE_ANY,
- &iterate_one_shot,
- crc);
- break;
- case RP_UPDATE:
- GNUNET_assert (GNUNET_OK ==
- crc->api->update (crc->api->cls,
- guid, 1,
- GNUNET_TIME_UNIT_ZERO_ABS,
- NULL));
+ }
+ gen_key (5, &key);
+ crc->api->get_key (crc->api->cls,
+ crc->offset++,
+ &key, NULL,
+ GNUNET_BLOCK_TYPE_ANY, &iterate_one_shot, crc);
+ break;
+ case RP_UPDATE:
+ GNUNET_assert (GNUNET_OK ==
+ crc->api->update (crc->api->cls,
+ guid, 1, GNUNET_TIME_UNIT_ZERO_ABS, NULL));
+ crc->phase++;
+ GNUNET_SCHEDULER_add_now (&test, crc);
+ break;
+
+ case RP_ITER_ZERO:
+ if (crc->cnt == 1)
+ {
+ crc->cnt = 0;
crc->phase++;
GNUNET_SCHEDULER_add_now (&test, crc);
break;
-
- case RP_ITER_ZERO:
- if (crc->cnt == 1)
- {
- crc->cnt = 0;
- crc->phase++;
- GNUNET_SCHEDULER_add_now (&test, crc);
- break;
- }
- crc->api->get_zero_anonymity (crc->api->cls,
- 0,
- 1,
- &iterate_one_shot,
- crc);
- break;
- case RP_REPL_GET:
- crc->api->get_replication (crc->api->cls,
- &iterate_one_shot,
- crc);
- break;
- case RP_EXPI_GET:
- crc->api->get_expiration (crc->api->cls,
- &iterate_one_shot,
- crc);
- break;
- case RP_DROP:
- crc->api->drop (crc->api->cls);
- GNUNET_SCHEDULER_add_now (&cleaning_task, crc);
- break;
}
+ crc->api->get_zero_anonymity (crc->api->cls, 0, 1, &iterate_one_shot, crc);
+ break;
+ case RP_REPL_GET:
+ crc->api->get_replication (crc->api->cls, &iterate_one_shot, crc);
+ break;
+ case RP_EXPI_GET:
+ crc->api->get_expiration (crc->api->cls, &iterate_one_shot, crc);
+ break;
+ case RP_DROP:
+ crc->api->drop (crc->api->cls);
+ GNUNET_SCHEDULER_add_now (&cleaning_task, crc);
+ break;
+ }
}
@@ -340,20 +309,19 @@ static struct GNUNET_DATASTORE_PluginFunctions *
load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
{
static struct GNUNET_DATASTORE_PluginEnvironment env;
- struct GNUNET_DATASTORE_PluginFunctions * ret;
+ struct GNUNET_DATASTORE_PluginFunctions *ret;
char *name;
char *libname;
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
"DATASTORE", "DATABASE", &name))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("No `%s' specified for `%s' in configuration!\n"),
- "DATABASE",
- "DATASTORE");
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("No `%s' specified for `%s' in configuration!\n"),
+ "DATABASE", "DATASTORE");
+ return NULL;
+ }
env.cfg = cfg;
env.duc = &disk_utilization_change_cb;
env.cls = NULL;
@@ -361,12 +329,10 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
_("Loading `%s' datastore plugin\n"), name);
GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name);
if (NULL == (ret = GNUNET_PLUGIN_load (libname, &env)))
- {
- fprintf (stderr,
- "Failed to load plugin `%s'!\n",
- name);
- return NULL;
- }
+ {
+ fprintf (stderr, "Failed to load plugin `%s'!\n", name);
+ return NULL;
+ }
GNUNET_free (libname);
GNUNET_free (name);
return ret;
@@ -376,20 +342,19 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *c)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
{
struct GNUNET_DATASTORE_PluginFunctions *api;
struct CpsRunContext *crc;
api = load_plugin (c);
if (api == NULL)
- {
- fprintf (stderr,
- "Could not initialize plugin, assuming database not configured. Test not run!\n");
- return;
- }
- crc = GNUNET_malloc(sizeof(struct CpsRunContext));
+ {
+ fprintf (stderr,
+ "Could not initialize plugin, assuming database not configured. Test not run!\n");
+ return;
+ }
+ crc = GNUNET_malloc (sizeof (struct CpsRunContext));
crc->api = api;
crc->cfg = c;
crc->phase = RP_PUT;
@@ -401,7 +366,8 @@ static int
check ()
{
char cfg_name[128];
- char *const argv[] = {
+
+ char *const argv[] = {
"test-plugin-datastore",
"-c",
cfg_name,
@@ -415,9 +381,8 @@ check ()
};
GNUNET_snprintf (cfg_name,
- sizeof (cfg_name),
- "test_plugin_datastore_data_%s.conf",
- plugin_name);
+ sizeof (cfg_name),
+ "test_plugin_datastore_data_%s.conf", plugin_name);
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
argv, "test-plugin-datastore", "nohelp",
options, &run, NULL);
@@ -437,17 +402,16 @@ main (int argc, char *argv[])
sleep (1);
/* determine name of plugin to use */
plugin_name = argv[0];
- while (NULL != (pos = strstr(plugin_name, "_")))
- plugin_name = pos+1;
- if (NULL != (pos = strstr(plugin_name, ".")))
+ while (NULL != (pos = strstr (plugin_name, "_")))
+ plugin_name = pos + 1;
+ if (NULL != (pos = strstr (plugin_name, ".")))
pos[0] = 0;
else
pos = (char *) plugin_name;
GNUNET_snprintf (dir_name,
- sizeof (dir_name),
- "/tmp/test-gnunet-datastore-plugin-%s",
- plugin_name);
+ sizeof (dir_name),
+ "/tmp/test-gnunet-datastore-plugin-%s", plugin_name);
GNUNET_DISK_directory_remove (dir_name);
GNUNET_log_setup ("test-plugin-datastore",
#if VERBOSE
@@ -465,5 +429,3 @@ main (int argc, char *argv[])
}
/* end of test_plugin_datastore.c */
-
-