/*
* This file is part of GNUnet
- * (C) 2013 Christian Grothoff (and other contributing authors)
+ * Copyright (C) 2013 Christian Grothoff (and other contributing authors)
*
* GNUnet is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
*
* 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.
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
*/
/**
* @author Christian Grothoff
*/
+#include <inttypes.h>
+
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_constants.h"
/**
* Operation ID.
*/
- uint32_t op_id;
+ uint64_t op_id;
/**
* Message to send to the PSYCstore service.
/**
* Task doing exponential back-off trying to reconnect.
*/
- GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
+ struct GNUNET_SCHEDULER_Task * reconnect_task;
/**
* Time for next connect retry.
struct GNUNET_TIME_Relative reconnect_delay;
/**
- * Are we polling for incoming messages right now?
+ * Last operation ID used.
*/
- int in_receive;
+ uint64_t last_op_id;
/**
- * The last operation id used for a PSYCstore operation.
+ * Are we polling for incoming messages right now?
*/
- uint32_t last_op_id_used;
-
+ uint8_t in_receive;
};
* @param h Handle to the PSYCstore service.
* @return next operation id to use
*/
-static uint32_t
+static uint64_t
get_next_op_id (struct GNUNET_PSYCSTORE_Handle *h)
{
- return h->last_op_id_used++;
+ return h->last_op_id++;
}
* @return OperationHandle if found, or NULL otherwise.
*/
static struct GNUNET_PSYCSTORE_OperationHandle *
-find_op_by_id (struct GNUNET_PSYCSTORE_Handle *h, uint32_t op_id)
+find_op_by_id (struct GNUNET_PSYCSTORE_Handle *h, uint64_t op_id)
{
struct GNUNET_PSYCSTORE_OperationHandle *op = h->op_head;
while (NULL != op)
static void
reschedule_connect (struct GNUNET_PSYCSTORE_Handle *h)
{
- GNUNET_assert (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK);
+ GNUNET_assert (h->reconnect_task == NULL);
if (NULL != h->th)
{
return;
}
if (size == sizeof (struct OperationResult))
- str = NULL;
+ str = "";
- op = find_op_by_id (h, ntohl (opres->op_id));
+ op = find_op_by_id (h, GNUNET_ntohll (opres->op_id));
if (NULL == op)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "No callback registered for operation with ID %ld.\n",
- type, ntohl (opres->op_id));
+ "No callback registered for operation with ID %" PRIu64 ".\n",
+ type, GNUNET_ntohll (opres->op_id));
}
else
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Received result message (type %d) with operation ID: %ld\n",
+ "Received result message (type %d) with operation ID: %" PRIu64 "\n",
type, op->op_id);
+ int64_t result_code = GNUNET_ntohll (opres->result_code) + INT64_MIN;
GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
if (NULL != op->res_cb)
{
- const struct StateModifyRequest *smreq;
const struct StateSyncRequest *ssreq;
switch (ntohs (op->msg->type))
{
- case GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_MODIFY:
- smreq = (const struct StateModifyRequest *) op->msg;
- if (!(smreq->flags & STATE_OP_LAST
- || GNUNET_OK != ntohl (opres->result_code)))
- op->res_cb = NULL;
- break;
case GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_SYNC:
ssreq = (const struct StateSyncRequest *) op->msg;
if (!(ssreq->flags & STATE_OP_LAST
- || GNUNET_OK != ntohl (opres->result_code)))
+ || GNUNET_OK != result_code))
op->res_cb = NULL;
break;
}
}
if (NULL != op->res_cb)
- op->res_cb (op->cls, ntohl (opres->result_code), str);
+ op->res_cb (op->cls, result_code, str, size - sizeof (*opres));
GNUNET_free (op);
}
break;
cres = (const struct CountersResult *) msg;
- op = find_op_by_id (h, ntohl (cres->op_id));
+ op = find_op_by_id (h, GNUNET_ntohll (cres->op_id));
if (NULL == op)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "No callback registered for operation with ID %ld.\n",
- type, ntohl (cres->op_id));
+ "No callback registered for operation with ID %" PRIu64 ".\n",
+ type, GNUNET_ntohll (cres->op_id));
}
else
{
GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
if (NULL != op->data_cb)
((GNUNET_PSYCSTORE_CountersCallback)
- op->data_cb) (op->cls, ntohl (cres->result_code),
+ op->data_cb) (op->cls,
+ ntohl (cres->result_code) + INT32_MIN,
GNUNET_ntohll (cres->max_fragment_id),
GNUNET_ntohll (cres->max_message_id),
GNUNET_ntohll (cres->max_group_generation),
return;
}
- op = find_op_by_id (h, ntohl (fres->op_id));
+ op = find_op_by_id (h, GNUNET_ntohll (fres->op_id));
if (NULL == op)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "No callback registered for operation with ID %ld.\n",
- type, ntohl (fres->op_id));
+ "No callback registered for operation with ID %" PRIu64 ".\n",
+ type, GNUNET_ntohll (fres->op_id));
}
else
{
return;
}
- op = find_op_by_id (h, ntohl (sres->op_id));
+ op = find_op_by_id (h, GNUNET_ntohll (sres->op_id));
if (NULL == op)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "No callback registered for operation with ID %ld.\n",
- type, ntohl (sres->op_id));
+ "No callback registered for operation with ID %" PRIu64 ".\n",
+ type, GNUNET_ntohll (sres->op_id));
}
else
{
return 0;
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Sending message of type %d to PSYCstore service. ID: %u\n",
+ "Sending message of type %d to PSYCstore service. ID: %" PRIu64 "\n",
ntohs (op->msg->type), op->op_id);
memcpy (buf, op->msg, ret);
{
struct GNUNET_PSYCSTORE_Handle *h = cls;
- h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
+ h->reconnect_task = NULL;
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Connecting to PSYCstore service.\n");
GNUNET_assert (NULL == h->client);
GNUNET_PSYCSTORE_disconnect (struct GNUNET_PSYCSTORE_Handle *h)
{
GNUNET_assert (NULL != h);
- if (h->reconnect_task != GNUNET_SCHEDULER_NO_TASK)
+ if (h->reconnect_task != NULL)
{
GNUNET_SCHEDULER_cancel (h->reconnect_task);
- h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
+ h->reconnect_task = NULL;
}
if (NULL != h->th)
{
: effective_since == 0);
struct MembershipStoreRequest *req;
- struct GNUNET_PSYCSTORE_OperationHandle *op
- = GNUNET_malloc (sizeof (*op) + sizeof (*req));
+ struct GNUNET_PSYCSTORE_OperationHandle *
+ op = GNUNET_malloc (sizeof (*op) + sizeof (*req));
op->h = h;
op->res_cb = rcb;
op->cls = rcb_cls;
req->group_generation = GNUNET_htonll (group_generation);
op->op_id = get_next_op_id (h);
- req->op_id = htonl (op->op_id);
+ req->op_id = GNUNET_htonll (op->op_id);
GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op);
transmit_next (h);
void *rcb_cls)
{
struct MembershipTestRequest *req;
- struct GNUNET_PSYCSTORE_OperationHandle *op
- = GNUNET_malloc (sizeof (*op) + sizeof (*req));
+ struct GNUNET_PSYCSTORE_OperationHandle *
+ op = GNUNET_malloc (sizeof (*op) + sizeof (*req));
op->h = h;
op->res_cb = rcb;
op->cls = rcb_cls;
req->group_generation = GNUNET_htonll (group_generation);
op->op_id = get_next_op_id (h);
- req->op_id = htonl (op->op_id);
+ req->op_id = GNUNET_htonll (op->op_id);
GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op);
transmit_next (h);
{
uint16_t size = ntohs (msg->header.size);
struct FragmentStoreRequest *req;
- struct GNUNET_PSYCSTORE_OperationHandle *op
- = GNUNET_malloc (sizeof (*op) + sizeof (*req) + size);
+ struct GNUNET_PSYCSTORE_OperationHandle *
+ op = GNUNET_malloc (sizeof (*op) + sizeof (*req) + size);
op->h = h;
op->res_cb = rcb;
op->cls = rcb_cls;
memcpy (&req[1], msg, size);
op->op_id = get_next_op_id (h);
- req->op_id = htonl (op->op_id);
+ req->op_id = GNUNET_htonll (op->op_id);
GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op);
transmit_next (h);
/**
- * Retrieve a message fragment by fragment ID.
+ * Retrieve message fragments by fragment ID range.
*
* @param h
* Handle for the PSYCstore.
* The slave requesting the fragment. If not NULL, a membership test is
* performed first and the fragment is only returned if the slave has
* access to it.
- * @param fragment_id
- * Fragment ID to retrieve. Use 0 to get the latest message fragment.
- * @param fcb
+ * @param first_fragment_id
+ * First fragment ID to retrieve.
+ * Use 0 to get the latest message fragment.
+ * @param last_fragment_id
+ * Last consecutive fragment ID to retrieve.
+ * Use 0 to get the latest message fragment.
+ * @param fragment_limit
+ * Maximum number of fragments to retrieve.
+ * @param fragment_cb
* Callback to call with the retrieved fragments.
* @param rcb
* Callback to call with the result of the operation.
GNUNET_PSYCSTORE_fragment_get (struct GNUNET_PSYCSTORE_Handle *h,
const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
- uint64_t fragment_id,
- GNUNET_PSYCSTORE_FragmentCallback fcb,
+ uint64_t first_fragment_id,
+ uint64_t last_fragment_id,
+ GNUNET_PSYCSTORE_FragmentCallback fragment_cb,
GNUNET_PSYCSTORE_ResultCallback rcb,
void *cls)
{
struct FragmentGetRequest *req;
- struct GNUNET_PSYCSTORE_OperationHandle *op
- = GNUNET_malloc (sizeof (*op) + sizeof (*req));
+ struct GNUNET_PSYCSTORE_OperationHandle *
+ op = GNUNET_malloc (sizeof (*op) + sizeof (*req));
op->h = h;
- op->data_cb = (DataCallback) fcb;
+ op->data_cb = (DataCallback) fragment_cb;
op->res_cb = rcb;
op->cls = cls;
req->header.type = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_FRAGMENT_GET);
req->header.size = htons (sizeof (*req));
req->channel_key = *channel_key;
- req->fragment_id = GNUNET_htonll (fragment_id);
+ req->first_fragment_id = GNUNET_htonll (first_fragment_id);
+ req->last_fragment_id = GNUNET_htonll (last_fragment_id);
if (NULL != slave_key)
{
req->slave_key = *slave_key;
}
op->op_id = get_next_op_id (h);
- req->op_id = htonl (op->op_id);
+ req->op_id = GNUNET_htonll (op->op_id);
GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op);
transmit_next (h);
/**
- * Retrieve all fragments of a message.
+ * Retrieve latest message fragments.
*
* @param h
* Handle for the PSYCstore.
* @param channel_key
* The channel we are interested in.
* @param slave_key
- * The slave requesting the message. If not NULL, a membership test is
- * performed first and the message is only returned if the slave has
+ * The slave requesting the fragment. If not NULL, a membership test is
+ * performed first and the fragment is only returned if the slave has
* access to it.
- * @param message_id
- * Message ID to retrieve. Use 0 to get the latest message.
- * @param fcb
+ * @param first_fragment_id
+ * First fragment ID to retrieve.
+ * Use 0 to get the latest message fragment.
+ * @param last_fragment_id
+ * Last consecutive fragment ID to retrieve.
+ * Use 0 to get the latest message fragment.
+ * @param fragment_limit
+ * Maximum number of fragments to retrieve.
+ * @param fragment_cb
* Callback to call with the retrieved fragments.
* @param rcb
* Callback to call with the result of the operation.
* @return Handle that can be used to cancel the operation.
*/
struct GNUNET_PSYCSTORE_OperationHandle *
+GNUNET_PSYCSTORE_fragment_get_latest (struct GNUNET_PSYCSTORE_Handle *h,
+ const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
+ const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
+ uint64_t fragment_limit,
+ GNUNET_PSYCSTORE_FragmentCallback fragment_cb,
+ GNUNET_PSYCSTORE_ResultCallback rcb,
+ void *cls)
+{
+ struct FragmentGetRequest *req;
+ struct GNUNET_PSYCSTORE_OperationHandle *
+ op = GNUNET_malloc (sizeof (*op) + sizeof (*req));
+ op->h = h;
+ op->data_cb = (DataCallback) fragment_cb;
+ op->res_cb = rcb;
+ op->cls = cls;
+
+ req = (struct FragmentGetRequest *) &op[1];
+ op->msg = (struct GNUNET_MessageHeader *) req;
+ req->header.type = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_FRAGMENT_GET);
+ req->header.size = htons (sizeof (*req));
+ req->channel_key = *channel_key;
+ req->fragment_limit = GNUNET_ntohll (fragment_limit);
+ if (NULL != slave_key)
+ {
+ req->slave_key = *slave_key;
+ req->do_membership_test = GNUNET_YES;
+ }
+
+ op->op_id = get_next_op_id (h);
+ req->op_id = GNUNET_htonll (op->op_id);
+
+ GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op);
+ transmit_next (h);
+
+ return op;
+}
+
+
+/**
+ * Retrieve all fragments of messages in a message ID range.
+ *
+ * @param h
+ * Handle for the PSYCstore.
+ * @param channel_key
+ * The channel we are interested in.
+ * @param slave_key
+ * The slave requesting the message.
+ * If not NULL, a membership test is performed first
+ * and the message is only returned if the slave has access to it.
+ * @param first_message_id
+ * First message ID to retrieve.
+ * @param last_message_id
+ * Last consecutive message ID to retrieve.
+ * @param method_prefix
+ * Retrieve only messages with a matching method prefix.
+ * @todo Implement method_prefix query.
+ * @param fragment_cb
+ * Callback to call with the retrieved fragments.
+ * @param result_cb
+ * Callback to call with the result of the operation.
+ * @param cls
+ * Closure for the callbacks.
+ *
+ * @return Handle that can be used to cancel the operation.
+ */
+struct GNUNET_PSYCSTORE_OperationHandle *
GNUNET_PSYCSTORE_message_get (struct GNUNET_PSYCSTORE_Handle *h,
const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
- uint64_t message_id,
- GNUNET_PSYCSTORE_FragmentCallback fcb,
+ uint64_t first_message_id,
+ uint64_t last_message_id,
+ const char *method_prefix,
+ GNUNET_PSYCSTORE_FragmentCallback fragment_cb,
GNUNET_PSYCSTORE_ResultCallback rcb,
void *cls)
{
struct MessageGetRequest *req;
- struct GNUNET_PSYCSTORE_OperationHandle *op
- = GNUNET_malloc (sizeof (*op) + sizeof (*req));
+ if (NULL == method_prefix)
+ method_prefix = "";
+ uint16_t method_size = strnlen (method_prefix,
+ GNUNET_SERVER_MAX_MESSAGE_SIZE
+ - sizeof (*req)) + 1;
+
+ struct GNUNET_PSYCSTORE_OperationHandle *
+ op = GNUNET_malloc (sizeof (*op) + sizeof (*req));
op->h = h;
- op->data_cb = (DataCallback) fcb;
+ op->data_cb = (DataCallback) fragment_cb;
op->res_cb = rcb;
op->cls = cls;
req = (struct MessageGetRequest *) &op[1];
op->msg = (struct GNUNET_MessageHeader *) req;
req->header.type = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_MESSAGE_GET);
- req->header.size = htons (sizeof (*req));
+ req->header.size = htons (sizeof (*req) + method_size);
req->channel_key = *channel_key;
- req->message_id = GNUNET_htonll (message_id);
+ req->first_message_id = GNUNET_htonll (first_message_id);
+ req->last_message_id = GNUNET_htonll (last_message_id);
+ if (NULL != slave_key)
+ {
+ req->slave_key = *slave_key;
+ req->do_membership_test = GNUNET_YES;
+ }
+ memcpy (&req[1], method_prefix, method_size);
+ ((char *) &req[1])[method_size - 1] = '\0';
+
+ op->op_id = get_next_op_id (h);
+ req->op_id = GNUNET_htonll (op->op_id);
+
+ GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op);
+ transmit_next (h);
+
+ return op;
+}
+
+
+/**
+ * Retrieve all fragments of the latest messages.
+ *
+ * @param h
+ * Handle for the PSYCstore.
+ * @param channel_key
+ * The channel we are interested in.
+ * @param slave_key
+ * The slave requesting the message.
+ * If not NULL, a membership test is performed first
+ * and the message is only returned if the slave has access to it.
+ * @param message_limit
+ * Maximum number of messages to retrieve.
+ * @param method_prefix
+ * Retrieve only messages with a matching method prefix.
+ * @todo Implement method_prefix query.
+ * @param fragment_cb
+ * Callback to call with the retrieved fragments.
+ * @param result_cb
+ * Callback to call with the result of the operation.
+ * @param cls
+ * Closure for the callbacks.
+ *
+ * @return Handle that can be used to cancel the operation.
+ */
+struct GNUNET_PSYCSTORE_OperationHandle *
+GNUNET_PSYCSTORE_message_get_latest (struct GNUNET_PSYCSTORE_Handle *h,
+ const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
+ const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
+ uint64_t message_limit,
+ const char *method_prefix,
+ GNUNET_PSYCSTORE_FragmentCallback fragment_cb,
+ GNUNET_PSYCSTORE_ResultCallback rcb,
+ void *cls)
+{
+ struct MessageGetRequest *req;
+
+ if (NULL == method_prefix)
+ method_prefix = "";
+ uint16_t method_size = strnlen (method_prefix,
+ GNUNET_SERVER_MAX_MESSAGE_SIZE
+ - sizeof (*req)) + 1;
+ GNUNET_assert ('\0' == method_prefix[method_size - 1]);
+
+ struct GNUNET_PSYCSTORE_OperationHandle *
+ op = GNUNET_malloc (sizeof (*op) + sizeof (*req) + method_size);
+ op->h = h;
+ op->data_cb = (DataCallback) fragment_cb;
+ op->res_cb = rcb;
+ op->cls = cls;
+
+ req = (struct MessageGetRequest *) &op[1];
+ op->msg = (struct GNUNET_MessageHeader *) req;
+ req->header.type = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_MESSAGE_GET);
+ req->header.size = htons (sizeof (*req) + method_size);
+ req->channel_key = *channel_key;
+ req->message_limit = GNUNET_ntohll (message_limit);
if (NULL != slave_key)
{
req->slave_key = *slave_key;
}
op->op_id = get_next_op_id (h);
- req->op_id = htonl (op->op_id);
+ req->op_id = GNUNET_htonll (op->op_id);
+ memcpy (&req[1], method_prefix, method_size);
GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op);
transmit_next (h);
* Message ID to retrieve. Use 0 to get the latest message.
* @param fragment_offset
* Offset of the fragment to retrieve.
- * @param fcb
+ * @param fragment_cb
* Callback to call with the retrieved fragments.
- * @param rcb
+ * @param result_cb
* Callback to call with the result of the operation.
* @param cls
* Closure for the callbacks.
const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
uint64_t message_id,
uint64_t fragment_offset,
- GNUNET_PSYCSTORE_FragmentCallback fcb,
+ GNUNET_PSYCSTORE_FragmentCallback fragment_cb,
GNUNET_PSYCSTORE_ResultCallback rcb,
void *cls)
{
struct MessageGetFragmentRequest *req;
- struct GNUNET_PSYCSTORE_OperationHandle *op
- = GNUNET_malloc (sizeof (*op) + sizeof (*req));
+ struct GNUNET_PSYCSTORE_OperationHandle *
+ op = GNUNET_malloc (sizeof (*op) + sizeof (*req));
op->h = h;
- op->data_cb = (DataCallback) fcb;
+ op->data_cb = (DataCallback) fragment_cb;
op->res_cb = rcb;
op->cls = cls;
}
op->op_id = get_next_op_id (h);
- req->op_id = htonl (op->op_id);
+ req->op_id = GNUNET_htonll (op->op_id);
GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op);
transmit_next (h);
* The current value of counters are needed when a channel master is restarted,
* so that it can continue incrementing the counters from their last value.
*
- * @param h Handle for the PSYCstore.
- * @param channel_key Public key that identifies the channel.
- * @param ccb Callback to call with the result.
- * @param ccb_cls Closure for the @a ccb callback.
+ * @param h
+ * Handle for the PSYCstore.
+ * @param channel_key
+ * Public key that identifies the channel.
+ * @param ccb
+ * Callback to call with the result.
+ * @param ccb_cls
+ * Closure for the @a ccb callback.
*
* @return Handle that can be used to cancel the operation.
*/
void *ccb_cls)
{
struct OperationRequest *req;
- struct GNUNET_PSYCSTORE_OperationHandle *op
- = GNUNET_malloc (sizeof (*op) + sizeof (*req));
+ struct GNUNET_PSYCSTORE_OperationHandle *
+ op = GNUNET_malloc (sizeof (*op) + sizeof (*req));
op->h = h;
op->data_cb = ccb;
op->cls = ccb_cls;
req->channel_key = *channel_key;
op->op_id = get_next_op_id (h);
- req->op_id = htonl (op->op_id);
+ req->op_id = GNUNET_htonll (op->op_id);
GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op);
transmit_next (h);
* An error is returned if there are missing messages containing state
* operations before the current one.
*
- * @param h Handle for the PSYCstore.
- * @param channel_key The channel we are interested in.
- * @param message_id ID of the message that contains the @a modifiers.
- * @param state_delta Value of the _state_delta PSYC header variable of the message.
- * @param modifier_count Number of elements in the @a modifiers array.
- * @param modifiers List of modifiers to apply.
- * @param rcb Callback to call with the result of the operation.
- * @param rcb_cls Closure for the @a rcb callback.
+ * @param h
+ * Handle for the PSYCstore.
+ * @param channel_key
+ * The channel we are interested in.
+ * @param message_id
+ * ID of the message that contains the @a modifiers.
+ * @param state_delta
+ * Value of the _state_delta PSYC header variable of the message.
+ * @param rcb
+ * Callback to call with the result of the operation.
+ * @param rcb_cls
+ * Closure for the @a rcb callback.
*
* @return Handle that can be used to cancel the operation.
*/
const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
uint64_t message_id,
uint64_t state_delta,
- size_t modifier_count,
- const struct GNUNET_ENV_Modifier *modifiers,
GNUNET_PSYCSTORE_ResultCallback rcb,
void *rcb_cls)
{
struct GNUNET_PSYCSTORE_OperationHandle *op = NULL;
- size_t i;
+ struct StateModifyRequest *req;
- for (i = 0; i < modifier_count; i++) {
- struct StateModifyRequest *req;
- uint16_t name_size = strlen (modifiers[i].name) + 1;
-
- op = GNUNET_malloc (sizeof (*op) + sizeof (*req) + name_size +
- modifiers[i].value_size);
- op->h = h;
- op->res_cb = rcb;
- op->cls = rcb_cls;
+ op = GNUNET_malloc (sizeof (*op) + sizeof (*req));
+ op->h = h;
+ op->res_cb = rcb;
+ op->cls = rcb_cls;
- req = (struct StateModifyRequest *) &op[1];
- op->msg = (struct GNUNET_MessageHeader *) req;
- req->header.type = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_MODIFY);
- req->header.size = htons (sizeof (*req) + name_size
- + modifiers[i].value_size);
- req->channel_key = *channel_key;
- req->message_id = GNUNET_htonll (message_id);
- req->state_delta = GNUNET_htonll (state_delta);
- req->oper = modifiers[i].oper;
- req->name_size = htons (name_size);
- req->flags
- = 0 == i
- ? STATE_OP_FIRST
- : modifier_count - 1 == i
- ? STATE_OP_LAST
- : 0;
+ req = (struct StateModifyRequest *) &op[1];
+ op->msg = (struct GNUNET_MessageHeader *) req;
+ req->header.type = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_MODIFY);
+ req->header.size = htons (sizeof (*req));
+ req->channel_key = *channel_key;
+ req->message_id = GNUNET_htonll (message_id);
+ req->state_delta = GNUNET_htonll (state_delta);
- memcpy (&req[1], modifiers[i].name, name_size);
- memcpy ((char *) &req[1] + name_size, modifiers[i].value, modifiers[i].value_size);
+ op->op_id = get_next_op_id (h);
+ req->op_id = GNUNET_htonll (op->op_id);
- op->op_id = get_next_op_id (h);
- req->op_id = htonl (op->op_id);
+ GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op);
+ transmit_next (h);
- GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op);
- transmit_next (h);
- }
return op;
/* FIXME: only the last operation is returned,
* operation_cancel() should be able to cancel all of them.
/**
* Store synchronized state.
*
- * @param h Handle for the PSYCstore.
- * @param channel_key The channel we are interested in.
- * @param message_id ID of the message that contains the state_hash PSYC header variable.
- * @param modifier_count Number of elements in the @a modifiers array.
- * @param modifiers Full state to store.
- * @param rcb Callback to call with the result of the operation.
- * @param rcb_cls Closure for the callback.
+ * @param h
+ * Handle for the PSYCstore.
+ * @param channel_key
+ * The channel we are interested in.
+ * @param max_state_message_id
+ * ID of the last stateful message before @a state_hash_message_id.
+ * @param state_hash_message_id
+ * ID of the message that contains the state_hash PSYC header variable.
+ * @param modifier_count
+ * Number of elements in the @a modifiers array.
+ * @param modifiers
+ * Full state to store.
+ * @param rcb
+ * Callback to call with the result of the operation.
+ * @param rcb_cls
+ * Closure for the callback.
*
* @return Handle that can be used to cancel the operation.
*/
struct GNUNET_PSYCSTORE_OperationHandle *
GNUNET_PSYCSTORE_state_sync (struct GNUNET_PSYCSTORE_Handle *h,
const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
- uint64_t message_id,
+ uint64_t max_state_message_id,
+ uint64_t state_hash_message_id,
size_t modifier_count,
const struct GNUNET_ENV_Modifier *modifiers,
GNUNET_PSYCSTORE_ResultCallback rcb,
req->header.size = htons (sizeof (*req) + name_size
+ modifiers[i].value_size);
req->channel_key = *channel_key;
- req->message_id = GNUNET_htonll (message_id);
+ req->max_state_message_id = GNUNET_htonll (max_state_message_id);
+ req->state_hash_message_id = GNUNET_htonll (state_hash_message_id);
req->name_size = htons (name_size);
req->flags
= (0 == i)
memcpy ((char *) &req[1] + name_size, modifiers[i].value, modifiers[i].value_size);
op->op_id = get_next_op_id (h);
- req->op_id = htonl (op->op_id);
+ req->op_id = GNUNET_htonll (op->op_id);
GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op);
transmit_next (h);
*
* Delete all state variables stored for the given channel.
*
- * @param h Handle for the PSYCstore.
- * @param channel_key The channel we are interested in.
- * @param rcb Callback to call with the result of the operation.
- * @param rcb_cls Closure for the callback.
+ * @param h
+ * Handle for the PSYCstore.
+ * @param channel_key
+ * The channel we are interested in.
+ * @param rcb
+ * Callback to call with the result of the operation.
+ * @param rcb_cls
+ * Closure for the callback.
*
* @return Handle that can be used to cancel the operation.
*/
void *rcb_cls)
{
struct OperationRequest *req;
- struct GNUNET_PSYCSTORE_OperationHandle *op
- = GNUNET_malloc (sizeof (*op) + sizeof (*req));
+ struct GNUNET_PSYCSTORE_OperationHandle *
+ op = GNUNET_malloc (sizeof (*op) + sizeof (*req));
op->h = h;
op->res_cb = rcb;
op->cls = rcb_cls;
req->channel_key = *channel_key;
op->op_id = get_next_op_id (h);
- req->op_id = htonl (op->op_id);
+ req->op_id = GNUNET_htonll (op->op_id);
GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op);
transmit_next (h);
/**
* Update signed values of state variables in the state store.
*
- * @param h Handle for the PSYCstore.
- * @param channel_key The channel we are interested in.
- * @param message_id Message ID that contained the state @a hash.
- * @param hash Hash of the serialized full state.
- * @param rcb Callback to call with the result of the operation.
- * @param rcb_cls Closure for the callback.
- *
+ * @param h
+ * Handle for the PSYCstore.
+ * @param channel_key
+ * The channel we are interested in.
+ * @param message_id
+ * Message ID that contained the state @a hash.
+ * @param hash
+ * Hash of the serialized full state.
+ * @param rcb
+ * Callback to call with the result of the operation.
+ * @param rcb_cls
+ * Closure for the callback.
*/
struct GNUNET_PSYCSTORE_OperationHandle *
GNUNET_PSYCSTORE_state_hash_update (struct GNUNET_PSYCSTORE_Handle *h,
void *rcb_cls)
{
struct StateHashUpdateRequest *req;
- struct GNUNET_PSYCSTORE_OperationHandle *op
- = GNUNET_malloc (sizeof (*op) + sizeof (*req));
+ struct GNUNET_PSYCSTORE_OperationHandle *
+ op = GNUNET_malloc (sizeof (*op) + sizeof (*req));
op->h = h;
op->res_cb = rcb;
op->cls = rcb_cls;
req->hash = *hash;
op->op_id = get_next_op_id (h);
- req->op_id = htonl (op->op_id);
+ req->op_id = GNUNET_htonll (op->op_id);
GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op);
transmit_next (h);
/**
* Retrieve the best matching state variable.
*
- * @param h Handle for the PSYCstore.
- * @param channel_key The channel we are interested in.
- * @param name Name of variable to match, the returned variable might be less specific.
- * @param scb Callback to return the matching state variable.
- * @param rcb Callback to call with the result of the operation.
- * @param cls Closure for the callbacks.
+ * @param h
+ * Handle for the PSYCstore.
+ * @param channel_key
+ * The channel we are interested in.
+ * @param name
+ * Name of variable to match, the returned variable might be less specific.
+ * @param scb
+ * Callback to return the matching state variable.
+ * @param rcb
+ * Callback to call with the result of the operation.
+ * @param cls
+ * Closure for the callbacks.
*
* @return Handle that can be used to cancel the operation.
*/
{
size_t name_size = strlen (name) + 1;
struct OperationRequest *req;
- struct GNUNET_PSYCSTORE_OperationHandle *op
- = GNUNET_malloc (sizeof (*op) + sizeof (*req) + name_size);
+ struct GNUNET_PSYCSTORE_OperationHandle *
+ op = GNUNET_malloc (sizeof (*op) + sizeof (*req) + name_size);
op->h = h;
op->data_cb = (DataCallback) scb;
op->res_cb = rcb;
memcpy (&req[1], name, name_size);
op->op_id = get_next_op_id (h);
- req->op_id = htonl (op->op_id);
+ req->op_id = GNUNET_htonll (op->op_id);
GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op);
transmit_next (h);
/**
* Retrieve all state variables for a channel with the given prefix.
*
- * @param h Handle for the PSYCstore.
- * @param channel_key The channel we are interested in.
- * @param name_prefix Prefix of state variable names to match.
- * @param scb Callback to return matching state variables.
- * @param rcb Callback to call with the result of the operation.
- * @param cls Closure for the callbacks.
+ * @param h
+ * Handle for the PSYCstore.
+ * @param channel_key
+ * The channel we are interested in.
+ * @param name_prefix
+ * Prefix of state variable names to match.
+ * @param scb
+ * Callback to return matching state variables.
+ * @param rcb
+ * Callback to call with the result of the operation.
+ * @param cls
+ * Closure for the callbacks.
*
* @return Handle that can be used to cancel the operation.
*/
{
size_t name_size = strlen (name_prefix) + 1;
struct OperationRequest *req;
- struct GNUNET_PSYCSTORE_OperationHandle *op
- = GNUNET_malloc (sizeof (*op) + sizeof (*req) + name_size);
+ struct GNUNET_PSYCSTORE_OperationHandle *
+ op = GNUNET_malloc (sizeof (*op) + sizeof (*req) + name_size);
op->h = h;
op->data_cb = (DataCallback) scb;
op->res_cb = rcb;
memcpy (&req[1], name_prefix, name_size);
op->op_id = get_next_op_id (h);
- req->op_id = htonl (op->op_id);
+ req->op_id = GNUNET_htonll (op->op_id);
GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op);
transmit_next (h);