/*
This file is part of GNUnet
- Copyright (C) 2004-2013 GNUnet e.V.
+ Copyright (C) 2004-2013, 2016 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
GNUNET_DATASTORE_ContinuationWithStatus cont;
/**
- * Closure for cont.
+ * Closure for @e cont.
*/
void *cont_cls;
GNUNET_DATASTORE_DatumProcessor proc;
/**
- * Closure for proc.
+ * Closure for @e proc.
*/
void *proc_cls;
GNUNET_DATASTORE_ContinuationWithStatus cont;
/**
- * Closure for 'cont'.
+ * Closure for @e cont.
*/
void *cont_cls;
/**
* Task for timeout signalling.
*/
- struct GNUNET_SCHEDULER_Task * task;
+ struct GNUNET_SCHEDULER_Task *task;
/**
* Timeout for the current operation.
/**
* Has this message been transmitted to the service?
- * Only ever GNUNET_YES for the head of the queue.
+ * Only ever #GNUNET_YES for the head of the queue.
* Note that the overall struct should end at a
* multiple of 64 bits.
*/
};
-
/**
* Connect to the datastore service.
*
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);
+ h = GNUNET_new (struct GNUNET_DATASTORE_Handle);
h->client = c;
h->cfg = cfg;
h->stats = GNUNET_STATISTICS_create ("datastore-api", cfg);
{
struct GNUNET_DATASTORE_Handle *h = cls;
- GNUNET_DATASTORE_disconnect (h, GNUNET_NO);
+ GNUNET_DATASTORE_disconnect (h,
+ GNUNET_NO);
}
hdr = buf;
hdr->size = htons (sizeof (struct GNUNET_MessageHeader));
hdr->type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_DROP);
- GNUNET_SCHEDULER_add_now (&disconnect_after_drop, h);
+ GNUNET_SCHEDULER_add_now (&disconnect_after_drop,
+ h);
return sizeof (struct GNUNET_MessageHeader);
}
{
struct GNUNET_DATASTORE_QueueEntry *qe;
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Datastore disconnect\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Datastore disconnect\n");
if (NULL != h->th)
{
GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
GNUNET_MessageHeader),
GNUNET_TIME_UNIT_SECONDS,
GNUNET_YES,
- &transmit_drop, h))
+ &transmit_drop,
+ h))
return;
GNUNET_CLIENT_disconnect (h->client);
h->client = NULL;
struct GNUNET_DATASTORE_Handle *h = qe->h;
GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# queue entry timeouts"), 1,
+ gettext_noop ("# queue entry timeouts"),
+ 1,
GNUNET_NO);
qe->task = NULL;
GNUNET_assert (GNUNET_NO == qe->was_transmitted);
}
if (c >= max_queue_size)
{
- GNUNET_STATISTICS_update (h->stats, gettext_noop ("# queue overflows"), 1,
+ GNUNET_STATISTICS_update (h->stats,
+ gettext_noop ("# queue overflows"),
+ 1,
GNUNET_NO);
return NULL;
}
}
c++;
#if INSANE_STATISTICS
- GNUNET_STATISTICS_update (h->stats, gettext_noop ("# queue entries created"),
+ GNUNET_STATISTICS_update (h->stats,
+ gettext_noop ("# queue entries created"),
1, GNUNET_NO);
#endif
- GNUNET_CONTAINER_DLL_insert_after (h->queue_head, h->queue_tail, pos, ret);
+ 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);
for (pos = ret->next; NULL != pos; pos = pos->next)
{
if ((pos->max_queue < h->queue_size) && (pos->was_transmitted == GNUNET_NO))
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Dropping request from datastore queue\n");
/* response_proc's expect request at the head of the queue! */
- GNUNET_CONTAINER_DLL_remove (h->queue_head, h->queue_tail, pos);
- GNUNET_CONTAINER_DLL_insert (h->queue_head, h->queue_tail, pos);
+ 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,
h->skip_next_messages = 0;
h->client = NULL;
h->reconnect_task =
- GNUNET_SCHEDULER_add_delayed (h->retry_time, &try_reconnect, h);
+ GNUNET_SCHEDULER_add_delayed (h->retry_time,
+ &try_reconnect,
+ h);
}
"Queueing %u byte request to DATASTORE\n",
qe->message_size);
h->th
- = GNUNET_CLIENT_notify_transmit_ready (h->client, qe->message_size,
+ = GNUNET_CLIENT_notify_transmit_ready (h->client,
+ qe->message_size,
GNUNET_TIME_absolute_get_remaining (qe->timeout),
GNUNET_YES,
- &transmit_request, h);
+ &transmit_request,
+ h);
GNUNET_assert (GNUNET_NO == h->in_receive);
GNUNET_break (NULL != h->th);
}
{
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 != NULL)
{
GNUNET_SCHEDULER_cancel (qe->task);
union QueueContext qc;
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Asked to put %u bytes of data under key `%s' for %s\n", size,
+ "Asked to put %u bytes of data under key `%s' for %s\n",
+ size,
GNUNET_h2s (key),
GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (expiration),
GNUNET_YES));
queue_priority,
max_queue_size,
timeout,
- &process_status_message, &qc);
+ &process_status_message,
+ &qc);
if (qe == NULL)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Could not create queue entry for PUT\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Could not create queue entry for PUT\n");
return NULL;
}
- GNUNET_STATISTICS_update (h->stats, gettext_noop ("# PUT requests executed"),
- 1, GNUNET_NO);
+ 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);
* (or rather, will already have been invoked)
*/
struct GNUNET_DATASTORE_QueueEntry *
-GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h, uint64_t amount,
+GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h,
+ uint64_t amount,
uint32_t entries,
GNUNET_DATASTORE_ContinuationWithStatus cont,
void *cont_cls)
cont = &drop_status_cont;
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Asked to reserve %llu bytes of data and %u entries\n",
- (unsigned long long) amount, (unsigned int) entries);
+ (unsigned long long) amount,
+ (unsigned int) entries);
qc.sc.cont = cont;
qc.sc.cont_cls = cont_cls;
qe = make_queue_entry (h,
UINT_MAX,
UINT_MAX,
GNUNET_TIME_UNIT_FOREVER_REL,
- &process_status_message, &qc);
+ &process_status_message,
+ &qc);
if (NULL == qe)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
return NULL;
}
GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# RESERVE requests executed"), 1,
+ gettext_noop ("# RESERVE requests executed"),
+ 1,
GNUNET_NO);
rm = (struct ReserveMessage *) &qe[1];
rm->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE);
*/
struct GNUNET_DATASTORE_QueueEntry *
GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h,
- uint32_t rid, unsigned int queue_priority,
+ uint32_t rid,
+ unsigned int queue_priority,
unsigned int max_queue_size,
struct GNUNET_TIME_Relative timeout,
GNUNET_DATASTORE_ContinuationWithStatus cont,
if (cont == NULL)
cont = &drop_status_cont;
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Asked to release reserve %d\n", rid);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Asked to release reserve %d\n",
+ rid);
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)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
* (or rather, will already have been invoked)
*/
struct GNUNET_DATASTORE_QueueEntry *
-GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h, uint64_t uid,
+GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h,
+ uint64_t uid,
uint32_t priority,
struct GNUNET_TIME_Absolute expiration,
unsigned int queue_priority,
*/
struct GNUNET_DATASTORE_QueueEntry *
GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
- const struct GNUNET_HashCode * key, size_t size,
- const void *data, unsigned int queue_priority,
+ const struct 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,
if (cont == NULL)
cont = &drop_status_cont;
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Asked to remove %u bytes under key `%s'\n",
- size, GNUNET_h2s (key));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Asked to remove %u bytes under key `%s'\n",
+ size,
+ GNUNET_h2s (key));
qc.sc.cont = cont;
qc.sc.cont_cls = cont_cls;
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);
+ qe = make_queue_entry (h,
+ msize,
+ queue_priority,
+ max_queue_size,
+ timeout,
+ &process_status_message,
+ &qc);
if (qe == NULL)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Could not create queue entry for REMOVE\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Could not create queue entry for REMOVE\n");
return NULL;
}
GNUNET_STATISTICS_update (h->stats,
GNUNET_assert (type != GNUNET_BLOCK_TYPE_ANY);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Asked to get %llu-th zero-anonymity entry of type %d in %s\n",
- (unsigned long long) offset, type,
- GNUNET_STRINGS_relative_time_to_string (timeout, GNUNET_YES));
+ (unsigned long long) offset,
+ type,
+ GNUNET_STRINGS_relative_time_to_string (timeout,
+ GNUNET_YES));
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 (NULL == qe)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
struct GNUNET_DATASTORE_QueueEntry *
GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h,
uint64_t offset,
- const struct GNUNET_HashCode * key,
+ const struct GNUNET_HashCode *key,
enum GNUNET_BLOCK_Type type,
unsigned int queue_priority,
unsigned int max_queue_size,
&qc);
if (qe == NULL)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Could not queue request for `%s'\n",
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Could not queue request for `%s'\n",
GNUNET_h2s (key));
return NULL;
}
GNUNET_assert (GNUNET_SYSERR != qe->was_transmitted);
h = qe->h;
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Pending DATASTORE request %p cancelled (%d, %d)\n", qe,
- qe->was_transmitted, h->queue_head == qe);
+ "Pending DATASTORE request %p cancelled (%d, %d)\n",
+ qe,
+ qe->was_transmitted,
+ h->queue_head == qe);
if (GNUNET_YES == qe->was_transmitted)
{
free_queue_entry (qe);