/**
* Entry in our priority queue.
*/
-struct QueueEntry
+struct GNUNET_DATASTORE_QueueEntry
{
/**
* This is a linked list.
*/
- struct QueueEntry *next;
+ struct GNUNET_DATASTORE_QueueEntry *next;
/**
* This is a linked list.
*/
- struct QueueEntry *prev;
+ struct GNUNET_DATASTORE_QueueEntry *prev;
/**
* Handle to the master context.
/**
* Current head of priority queue.
*/
- struct QueueEntry *queue_head;
+ struct GNUNET_DATASTORE_QueueEntry *queue_head;
/**
* Current tail of priority queue.
*/
- struct QueueEntry *queue_tail;
+ struct GNUNET_DATASTORE_QueueEntry *queue_tail;
/**
* Task for trying to reconnect.
void GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h,
int drop)
{
- struct QueueEntry *qe;
+ struct GNUNET_DATASTORE_QueueEntry *qe;
if (h->client != NULL)
- GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
+ {
+ GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
+ h->client = NULL;
+ }
if (h->reconnect_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel (h->sched,
- h->reconnect_task);
- h->client = NULL;
+ {
+ GNUNET_SCHEDULER_cancel (h->sched,
+ h->reconnect_task);
+ h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
+ }
while (NULL != (qe = h->queue_head))
{
- GNUNET_CONTAINER_DLL_remove (h->queue_head,
- h->queue_tail,
- qe);
- if (NULL != qe->response_proc)
- qe->response_proc (qe, NULL);
- GNUNET_free (qe);
+ GNUNET_assert (NULL != qe->response_proc);
+ qe->response_proc (qe, NULL);
}
if (GNUNET_YES == drop)
{
/**
* A request has timed out (before being transmitted to the service).
*
- * @param cls the 'struct QueueEntry'
+ * @param cls the 'struct GNUNET_DATASTORE_QueueEntry'
* @param tc scheduler context
*/
static void
timeout_queue_entry (void *cls,
const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- struct QueueEntry *qe = cls;
- struct GNUNET_DATASTORE_Handle *h = qe->h;
+ struct GNUNET_DATASTORE_QueueEntry *qe = cls;
qe->task = GNUNET_SCHEDULER_NO_TASK;
GNUNET_assert (qe->was_transmitted == GNUNET_NO);
- GNUNET_CONTAINER_DLL_remove (h->queue_head,
- h->queue_tail,
- qe);
- if (qe->cont != NULL)
- qe->cont (qe->cont_cls, GNUNET_NO, _("timeout"));
- if (qe->response_proc != NULL)
- qe->response_proc (qe, NULL);
- GNUNET_free (qe);
+ qe->response_proc (qe, NULL);
}
* @param max_queue_size at what queue size should this request be dropped
* (if other requests of higher priority are in the queue)
* @param timeout timeout for the operation
- * @param cont continuation to call when done with request transmission (can be NULL)
- * @param cont_cls closure for cont
* @param response_proc function to call with replies (can be NULL)
* @param client_ctx client context (NOT a closure for response_proc)
* @return NULL if the queue is full (and this entry was dropped)
*/
-static struct QueueEntry *
+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_DATASTORE_ContinuationWithStatus cont,
- void *cont_cls,
GNUNET_CLIENT_MessageHandler response_proc,
void *client_ctx)
{
- struct QueueEntry *ret;
- struct QueueEntry *pos;
+ struct GNUNET_DATASTORE_QueueEntry *ret;
+ struct GNUNET_DATASTORE_QueueEntry *pos;
unsigned int c;
c = 0;
c++;
pos = pos->next;
}
- if (c >= max_queue_size)
- return NULL;
+ ret = GNUNET_malloc (sizeof (struct GNUNET_DATASTORE_QueueEntry) + msize);
+ ret->h = h;
+ ret->response_proc = response_proc;
+ ret->client_ctx = client_ctx;
+ ret->timeout = GNUNET_TIME_relative_to_absolute (timeout);
+ ret->priority = queue_priority;
+ ret->max_queue = max_queue_size;
+ ret->message_size = msize;
+ ret->was_transmitted = GNUNET_NO;
if (pos == NULL)
{
/* append at the tail */
(h->queue_head->was_transmitted) )
pos = h->queue_head;
}
- ret = GNUNET_malloc (sizeof (struct QueueEntry) + msize);
+ c++;
GNUNET_CONTAINER_DLL_insert_after (h->queue_head,
h->queue_tail,
pos,
ret);
- ret->h = h;
- ret->response_proc = response_proc;
- ret->client_ctx = client_ctx;
- ret->cont = cont;
- ret->cont_cls = cont_cls;
+ h->queue_size++;
+ if (c > max_queue_size)
+ {
+ response_proc (ret, NULL);
+ GNUNET_free (ret);
+ return NULL;
+ }
ret->task = GNUNET_SCHEDULER_add_delayed (h->sched,
timeout,
&timeout_queue_entry,
ret);
- ret->timeout = GNUNET_TIME_relative_to_absolute (timeout);
- ret->priority = queue_priority;
- ret->max_queue = max_queue_size;
- ret->message_size = msize;
- ret->was_transmitted = GNUNET_NO;
- h->queue_size++;
- c++;
pos = ret->next;
while (pos != NULL)
{
if (pos->max_queue < h->queue_size)
{
- GNUNET_CONTAINER_DLL_remove (h->queue_head,
- h->queue_tail,
- pos);
- GNUNET_SCHEDULER_cancel (h->sched,
- pos->task);
- if (pos->cont != NULL)
- pos->cont (pos->cont_cls, GNUNET_NO, _("Message queue full"));
- if (pos->response_proc != NULL)
- pos->response_proc (pos, NULL);
- GNUNET_free (pos);
- h->queue_size--;
+ GNUNET_assert (pos->response_proc != NULL);
+ pos->response_proc (pos, NULL);
break;
}
pos = pos->next;
* Disconnect from the service and then try reconnecting to the datastore service
* after some delay.
*
- * @param cls the 'struct GNUNET_DATASTORE_Handle'
- * @param tc scheduler context
+ * @param h handle to datastore to disconnect and reconnect
*/
static void
do_disconnect (struct GNUNET_DATASTORE_Handle *h)
{
+ if (h->client == NULL)
+ return;
GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
h->client = NULL;
h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->sched,
void *buf)
{
struct GNUNET_DATASTORE_Handle *h = cls;
- struct QueueEntry *qe;
+ struct GNUNET_DATASTORE_QueueEntry *qe;
size_t msize;
h->th = NULL;
}
memcpy (buf, &qe[1], msize);
qe->was_transmitted = GNUNET_YES;
- if (qe->cont != NULL)
- qe->cont (qe->cont_cls, GNUNET_OK, NULL);
GNUNET_SCHEDULER_cancel (h->sched,
qe->task);
qe->task = GNUNET_SCHEDULER_NO_TASK;
- if (qe->response_proc == NULL)
- {
- GNUNET_CONTAINER_DLL_remove (h->queue_head,
- h->queue_tail,
- qe);
- GNUNET_free (qe);
- process_queue (h);
- }
- else
- {
- GNUNET_CLIENT_receive (h->client,
- qe->response_proc,
- qe,
- GNUNET_TIME_absolute_get_remaining (qe->timeout));
- }
+ GNUNET_CLIENT_receive (h->client,
+ qe->response_proc,
+ qe,
+ GNUNET_TIME_absolute_get_remaining (qe->timeout));
return msize;
}
static void
process_queue (struct GNUNET_DATASTORE_Handle *h)
{
- struct QueueEntry *qe;
+ struct GNUNET_DATASTORE_QueueEntry *qe;
if (NULL == (qe = h->queue_head))
return; /* no entry in queue */
}
-/**
- * Store an item in the datastore. If the item is already present,
- * the priorities are summed up and the higher expiration time and
- * lower anonymity level is used.
- *
- * @param h handle to the datastore
- * @param rid reservation ID to use (from "reserve"); use 0 if no
- * prior reservation was made
- * @param key key for the value
- * @param size number of bytes in data
- * @param data content stored
- * @param type type of the content
- * @param priority priority of the content
- * @param anonymity anonymity-level for the content
- * @param expiration expiration time for the content
- * @param queue_priority ranking of this request in the priority queue
- * @param max_queue_size at what queue size should this request be dropped
- * (if other requests of higher priority are in the queue)
- * @param timeout timeout for the operation
- * @param cont continuation to call when done
- * @param cont_cls closure for cont
- */
-void
-GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
- int rid,
- 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,
- unsigned int queue_priority,
- unsigned int max_queue_size,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_DATASTORE_ContinuationWithStatus cont,
- void *cont_cls)
-{
- struct QueueEntry *qe;
- struct DataMessage *dm;
- size_t msize;
-
-#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asked to put %u bytes of data under key `%s'\n",
- size,
- GNUNET_h2s (key));
-#endif
- 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,
- cont, cont_cls, NULL, NULL);
- if (qe == NULL)
- return;
- 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(size);
- dm->type = htonl(type);
- dm->priority = htonl(priority);
- dm->anonymity = htonl(anonymity);
- dm->uid = GNUNET_htonll(0);
- dm->expiration = GNUNET_TIME_absolute_hton(expiration);
- dm->key = *key;
- memcpy (&dm[1], data, size);
- process_queue (h);
-}
/**
};
+/**
+ * Dummy continuation used to do nothing (but be non-zero).
+ *
+ * @param cls closure
+ * @param result result
+ * @param emsg error message
+ */
+static void
+drop_status_cont (void *cls, int result, const char *emsg)
+{
+ /* do nothing */
+}
+
+
+static void
+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);
+ if (qe->task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (h->sched,
+ qe->task);
+ qe->task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ h->queue_size--;
+ GNUNET_free (qe);
+}
+
/**
* Type of a function to call when we receive a message
* from the service.
const struct
GNUNET_MessageHeader * msg)
{
- struct QueueEntry *qe = cls;
+ struct GNUNET_DATASTORE_QueueEntry *qe = cls;
struct GNUNET_DATASTORE_Handle *h = qe->h;
struct StatusContext *rc = qe->client_ctx;
const struct StatusMessage *sm;
const char *emsg;
int32_t status;
- GNUNET_CONTAINER_DLL_remove (h->queue_head,
- h->queue_tail,
- qe);
- GNUNET_free (qe);
+ free_queue_entry (qe);
if (msg == NULL)
- {
+ {
+ if (NULL == h->client)
+ return; /* forced disconnect */
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
_("Failed to receive response from database.\n"));
do_disconnect (h);
}
+/**
+ * Store an item in the datastore. If the item is already present,
+ * the priorities are summed up and the higher expiration time and
+ * lower anonymity level is used.
+ *
+ * @param h handle to the datastore
+ * @param rid reservation ID to use (from "reserve"); use 0 if no
+ * prior reservation was made
+ * @param key key for the value
+ * @param size number of bytes in data
+ * @param data content stored
+ * @param type type of the content
+ * @param priority priority of the content
+ * @param anonymity anonymity-level for the content
+ * @param expiration expiration time for the content
+ * @param queue_priority ranking of this request in the priority queue
+ * @param max_queue_size at what queue size should this request be dropped
+ * (if other requests of higher priority are in the queue)
+ * @param timeout timeout for the operation
+ * @param cont continuation to call when done
+ * @param cont_cls closure for cont
+ * @return NULL if the entry was not queued, otherwise a handle that can be used to
+ * cancel; note that even if NULL is returned, the callback will be invoked
+ * (or rather, will already have been invoked)
+ */
+struct GNUNET_DATASTORE_QueueEntry *
+GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
+ int rid,
+ 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,
+ unsigned int queue_priority,
+ unsigned int max_queue_size,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_DATASTORE_ContinuationWithStatus cont,
+ void *cont_cls)
+{
+ struct StatusContext *scont;
+ struct GNUNET_DATASTORE_QueueEntry *qe;
+ struct DataMessage *dm;
+ size_t msize;
+
+#if DEBUG_DATASTORE
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Asked to put %u bytes of data under key `%s'\n",
+ size,
+ GNUNET_h2s (key));
+#endif
+ msize = sizeof(struct DataMessage) + size;
+ GNUNET_assert (msize <= GNUNET_SERVER_MAX_MESSAGE_SIZE);
+ scont = GNUNET_malloc (sizeof (struct StatusContext));
+ scont->cont = cont;
+ scont->cont_cls = cont_cls;
+ qe = make_queue_entry (h, msize,
+ queue_priority, max_queue_size, timeout,
+ &process_status_message, scont);
+ if (qe == NULL)
+ return NULL;
+ 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(size);
+ dm->type = htonl(type);
+ dm->priority = htonl(priority);
+ dm->anonymity = htonl(anonymity);
+ dm->uid = GNUNET_htonll(0);
+ dm->expiration = GNUNET_TIME_absolute_hton(expiration);
+ dm->key = *key;
+ memcpy (&dm[1], data, size);
+ process_queue (h);
+ return qe;
+}
+
+
/**
* Reserve space in the datastore. This function should be used
* to avoid "out of space" failures during a longer sequence of "put"
* @param cont continuation to call when done; "success" will be set to
* a positive reservation value if space could be reserved.
* @param cont_cls closure for cont
+ * @return NULL if the entry was not queued, otherwise a handle that can be used to
+ * cancel; note that even if NULL is returned, the callback will be invoked
+ * (or rather, will already have been invoked)
*/
-void
+struct GNUNET_DATASTORE_QueueEntry *
GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h,
uint64_t amount,
uint32_t entries,
GNUNET_DATASTORE_ContinuationWithStatus cont,
void *cont_cls)
{
- struct QueueEntry *qe;
+ struct GNUNET_DATASTORE_QueueEntry *qe;
struct ReserveMessage *rm;
struct StatusContext *scont;
+ if (cont == NULL)
+ cont = &drop_status_cont;
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Asked to reserve %llu bytes of data and %u entries'\n",
scont->cont_cls = cont_cls;
qe = make_queue_entry (h, sizeof(struct ReserveMessage),
queue_priority, max_queue_size, timeout,
- NULL, NULL, &process_status_message, scont);
+ &process_status_message, scont);
if (qe == NULL)
- return;
+ return NULL;
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;
}
* @param timeout how long to wait at most for a response
* @param cont continuation to call when done
* @param cont_cls closure for cont
+ * @return NULL if the entry was not queued, otherwise a handle that can be used to
+ * cancel; note that even if NULL is returned, the callback will be invoked
+ * (or rather, will already have been invoked)
*/
-void
+struct GNUNET_DATASTORE_QueueEntry *
GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h,
int rid,
unsigned int queue_priority,
GNUNET_DATASTORE_ContinuationWithStatus cont,
void *cont_cls)
{
- struct QueueEntry *qe;
+ struct GNUNET_DATASTORE_QueueEntry *qe;
struct ReleaseReserveMessage *rrm;
struct StatusContext *scont;
+ if (cont == NULL)
+ 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 release reserve %d\n",
+ rid);
#endif
scont = GNUNET_malloc (sizeof (struct StatusContext));
scont->cont = cont;
scont->cont_cls = cont_cls;
qe = make_queue_entry (h, sizeof(struct ReleaseReserveMessage),
queue_priority, max_queue_size, timeout,
- NULL, NULL, &process_status_message, scont);
+ &process_status_message, scont);
if (qe == NULL)
- return;
+ return NULL;
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;
}
* @param timeout how long to wait at most for a response
* @param cont continuation to call when done
* @param cont_cls closure for cont
+ * @return NULL if the entry was not queued, otherwise a handle that can be used to
+ * cancel; note that even if NULL is returned, the callback will be invoked
+ * (or rather, will already have been invoked)
*/
-void
+struct GNUNET_DATASTORE_QueueEntry *
GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h,
unsigned long long uid,
uint32_t priority,
GNUNET_DATASTORE_ContinuationWithStatus cont,
void *cont_cls)
{
- struct QueueEntry *qe;
+ struct GNUNET_DATASTORE_QueueEntry *qe;
struct UpdateMessage *um;
struct StatusContext *scont;
+ if (cont == NULL)
+ 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",
scont->cont_cls = cont_cls;
qe = make_queue_entry (h, sizeof(struct UpdateMessage),
queue_priority, max_queue_size, timeout,
- NULL, NULL, &process_status_message, scont);
+ &process_status_message, scont);
if (qe == NULL)
- return;
+ return NULL;
um = (struct UpdateMessage*) &qe[1];
um->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_UPDATE);
um->header.size = htons(sizeof (struct UpdateMessage));
um->expiration = GNUNET_TIME_absolute_hton(expiration);
um->uid = GNUNET_htonll(uid);
process_queue (h);
+ return qe;
}
* @param timeout how long to wait at most for a response
* @param cont continuation to call when done
* @param cont_cls closure for cont
+ * @return NULL if the entry was not queued, otherwise a handle that can be used to
+ * cancel; note that even if NULL is returned, the callback will be invoked
+ * (or rather, will already have been invoked)
*/
-void
+struct GNUNET_DATASTORE_QueueEntry *
GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
const GNUNET_HashCode *key,
uint32_t size,
GNUNET_DATASTORE_ContinuationWithStatus cont,
void *cont_cls)
{
- struct QueueEntry *qe;
+ struct GNUNET_DATASTORE_QueueEntry *qe;
struct DataMessage *dm;
size_t msize;
struct StatusContext *scont;
+ if (cont == NULL)
+ cont = &drop_status_cont;
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Asked to remove %u bytes under key `%s'\n",
GNUNET_assert (msize <= GNUNET_SERVER_MAX_MESSAGE_SIZE);
qe = make_queue_entry (h, msize,
queue_priority, max_queue_size, timeout,
- NULL, NULL, &process_status_message, scont);
+ &process_status_message, scont);
if (qe == NULL)
- return;
+ return NULL;
dm = (struct DataMessage*) &qe[1];
dm->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE);
dm->header.size = htons(msize);
dm->key = *key;
memcpy (&dm[1], data, size);
process_queue (h);
+ return qe;
}
*/
void *iter_cls;
- /**
- * Automatically get the next result, or wait for a call to
- * GNUNET_DATASTORE_get_next? GNUNET_YES means we automatically
- * get the next one (if there are more).
- */
- int get_next;
-
};
process_result_message (void *cls,
const struct GNUNET_MessageHeader * msg)
{
- struct QueueEntry *qe = cls;
+ struct GNUNET_DATASTORE_QueueEntry *qe = cls;
struct GNUNET_DATASTORE_Handle *h = qe->h;
struct ResultContext *rc = qe->client_ctx;
const struct DataMessage *dm;
+ GNUNET_assert (h->queue_head == qe);
if (msg == NULL)
{
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
_("Failed to receive response from datastore\n"));
#endif
- GNUNET_CONTAINER_DLL_remove (h->queue_head,
- h->queue_tail,
- qe);
- GNUNET_free (qe);
+ free_queue_entry (qe);
do_disconnect (h);
rc->iter (rc->iter_cls,
NULL, 0, NULL, 0, 0, 0,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received end of result set\n");
#endif
- GNUNET_CONTAINER_DLL_remove (h->queue_head,
- h->queue_tail,
- qe);
- GNUNET_free (qe);
+ free_queue_entry (qe);
rc->iter (rc->iter_cls,
NULL, 0, NULL, 0, 0, 0,
GNUNET_TIME_UNIT_ZERO_ABS, 0);
(ntohs(msg->size) != sizeof(struct DataMessage) + ntohl (((const struct DataMessage*)msg)->size)) )
{
GNUNET_break (0);
- GNUNET_CONTAINER_DLL_remove (h->queue_head,
- h->queue_tail,
- qe);
- GNUNET_free (qe);
+ free_queue_entry (qe);
h->retry_time = GNUNET_TIME_UNIT_ZERO;
do_disconnect (h);
rc->iter (rc->iter_cls,
ntohl(dm->anonymity),
GNUNET_TIME_absolute_ntoh(dm->expiration),
GNUNET_ntohll(dm->uid));
- if (rc->get_next == GNUNET_YES)
- GNUNET_CLIENT_receive (h->client,
- qe->response_proc,
- qe,
- GNUNET_TIME_absolute_get_remaining (qe->timeout));
}
* will be called once with a value (if available)
* and always once with a value of NULL.
* @param iter_cls closure for iter
+ * @return NULL if the entry was not queued, otherwise a handle that can be used to
+ * cancel; note that even if NULL is returned, the callback will be invoked
+ * (or rather, will already have been invoked)
*/
-void
+struct GNUNET_DATASTORE_QueueEntry *
GNUNET_DATASTORE_get_random (struct GNUNET_DATASTORE_Handle *h,
unsigned int queue_priority,
unsigned int max_queue_size,
GNUNET_DATASTORE_Iterator iter,
void *iter_cls)
{
- struct QueueEntry *qe;
+ struct GNUNET_DATASTORE_QueueEntry *qe;
struct GNUNET_MessageHeader *m;
struct ResultContext *rcont;
rcont = GNUNET_malloc (sizeof (struct ResultContext));
rcont->iter = iter;
rcont->iter_cls = iter_cls;
- rcont->get_next = GNUNET_YES;
qe = make_queue_entry (h, sizeof(struct GNUNET_MessageHeader),
queue_priority, max_queue_size, timeout,
- NULL, NULL, &process_result_message, rcont);
+ &process_result_message, rcont);
if (qe == NULL)
- return;
+ return NULL;
m = (struct GNUNET_MessageHeader*) &qe[1];
m->type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_GET_RANDOM);
m->size = htons(sizeof (struct GNUNET_MessageHeader));
process_queue (h);
+ return qe;
}
* @param iter function to call on each matching value;
* will be called once with a NULL value at the end
* @param iter_cls closure for iter
+ * @return NULL if the entry was not queued, otherwise a handle that can be used to
+ * cancel; note that even if NULL is returned, the callback will be invoked
+ * (or rather, will already have been invoked)
*/
-void
+struct GNUNET_DATASTORE_QueueEntry *
GNUNET_DATASTORE_get (struct GNUNET_DATASTORE_Handle *h,
const GNUNET_HashCode * key,
enum GNUNET_BLOCK_Type type,
GNUNET_DATASTORE_Iterator iter,
void *iter_cls)
{
- struct QueueEntry *qe;
+ struct GNUNET_DATASTORE_QueueEntry *qe;
struct GetMessage *gm;
struct ResultContext *rcont;
rcont = GNUNET_malloc (sizeof (struct ResultContext));
rcont->iter = iter;
rcont->iter_cls = iter_cls;
- rcont->get_next = GNUNET_NO;
qe = make_queue_entry (h, sizeof(struct GetMessage),
queue_priority, max_queue_size, timeout,
- NULL, NULL, &process_result_message, rcont);
+ &process_result_message, rcont);
if (qe == NULL)
- return;
+ return NULL;
gm = (struct GetMessage*) &qe[1];
gm->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_GET);
gm->type = htonl(type);
gm->header.size = htons(sizeof (struct GetMessage) - sizeof(GNUNET_HashCode));
}
process_queue (h);
+ return qe;
}
GNUNET_DATASTORE_get_next (struct GNUNET_DATASTORE_Handle *h,
int more)
{
- struct QueueEntry *qe = h->queue_head;
+ struct GNUNET_DATASTORE_QueueEntry *qe = h->queue_head;
struct ResultContext *rc = qe->client_ctx;
GNUNET_assert (NULL != qe);
GNUNET_assert (&process_result_message == qe->response_proc);
- GNUNET_assert (rc->get_next == GNUNET_NO);
if (GNUNET_YES == more)
{
GNUNET_CLIENT_receive (h->client,
GNUNET_TIME_absolute_get_remaining (qe->timeout));
return;
}
- GNUNET_CONTAINER_DLL_remove (h->queue_head,
- h->queue_tail,
- qe);
- GNUNET_free (qe);
+ free_queue_entry (qe);
h->retry_time = GNUNET_TIME_UNIT_ZERO;
do_disconnect (h);
rc->iter (rc->iter_cls,
}
+/**
+ * Cancel a datastore operation. The final callback from the
+ * operation must not have been done yet.
+ *
+ * @param qe operation to cancel
+ */
+void
+GNUNET_DATASTORE_cancel (struct GNUNET_DATASTORE_QueueEntry *qe)
+{
+ struct GNUNET_DATASTORE_Handle *h;
+ int reconnect;
+
+ h = qe->h;
+ reconnect = qe->was_transmitted;
+ free_queue_entry (qe);
+ h->queue_size--;
+ if (reconnect)
+ {
+ h->retry_time = GNUNET_TIME_UNIT_ZERO;
+ do_disconnect (h);
+ }
+}
+
+
/* end of datastore_api.c */