[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r8588 - in gnunet/src: datastore include
From: |
gnunet |
Subject: |
[GNUnet-SVN] r8588 - in gnunet/src: datastore include |
Date: |
Tue, 16 Jun 2009 14:32:40 -0600 |
Author: grothoff
Date: 2009-06-16 14:32:40 -0600 (Tue, 16 Jun 2009)
New Revision: 8588
Modified:
gnunet/src/datastore/datastore.h
gnunet/src/datastore/datastore_api.c
gnunet/src/datastore/gnunet-service-datastore.c
gnunet/src/datastore/plugin_datastore.h
gnunet/src/datastore/plugin_datastore_sqlite.c
gnunet/src/datastore/plugin_datastore_template.c
gnunet/src/include/gnunet_datastore_service.h
gnunet/src/include/gnunet_protocols.h
Log:
improving datastore API
Modified: gnunet/src/datastore/datastore.h
===================================================================
--- gnunet/src/datastore/datastore.h 2009-06-16 20:13:13 UTC (rev 8587)
+++ gnunet/src/datastore/datastore.h 2009-06-16 20:32:40 UTC (rev 8588)
@@ -33,10 +33,10 @@
* Message from datastore service informing client about
* the current size of the datastore.
*/
-struct SizeMessage
+struct ReserveMessage
{
/**
- * Type is GNUNET_MESSAGE_TYPE_DATASTORE_SIZE.
+ * Type is GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE.
*/
struct GNUNET_MessageHeader header;
@@ -46,13 +46,59 @@
uint32_t reserved GNUNET_PACKED;
/**
- * Size of the datastore in bytes.
+ * Number of bytes to reserve.
*/
uint64_t size GNUNET_PACKED;
+
+ /**
+ * Number of items to reserve.
+ */
+ uint64_t items GNUNET_PACKED;
};
/**
+ * Message from datastore service informing client about
+ * the success or failure of a requested operation.
+ * This header is optionally followed by a variable-size,
+ * 0-terminated error message.
+ */
+struct StatusMessage
+{
+ /**
+ * Type is GNUNET_MESSAGE_TYPE_DATASTORE_STATUS.
+ */
+ struct GNUNET_MessageHeader header;
+
+ /**
+ * Status code.
+ */
+ int32_t status GNUNET_PACKED;
+
+};
+
+
+/**
+ * Message from datastore client informing service that
+ * the remainder of the reserved bytes can now be released
+ * for other requests.
+ */
+struct ReleaseReserveMessage
+{
+ /**
+ * Type is GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE.
+ */
+ struct GNUNET_MessageHeader header;
+
+ /**
+ * Reservation id.
+ */
+ int32_t rid GNUNET_PACKED;
+
+};
+
+
+/**
* Message to the datastore service asking about specific
* content.
*/
@@ -80,6 +126,35 @@
/**
+ * Message to the datastore service requesting an update
+ * to the priority or expiration for some content.
+ */
+struct UpdateMessage
+{
+ /**
+ * Type is GNUNET_MESSAGE_TYPE_DATASTORE_UPDATE.
+ */
+ struct GNUNET_MessageHeader header;
+
+ /**
+ * Desired priority increase.
+ */
+ int32_t priority GNUNET_PACKED;
+
+ /**
+ * Desired new expiration time.
+ */
+ struct GNUNET_TIME_AbsoluteNBO expiration;
+
+ /**
+ * Unique ID for the content.
+ */
+ uint64_t uid;
+
+};
+
+
+/**
* Message transmitting content from or to the datastore
* service.
*/
@@ -94,9 +169,9 @@
struct GNUNET_MessageHeader header;
/**
- * Always zero.
+ * Reservation ID to use; use zero for none.
*/
- uint32_t reserved GNUNET_PACKED;
+ uint32_t rid GNUNET_PACKED;
/**
* Number of bytes in the item (NBO).
@@ -117,6 +192,11 @@
* Desired anonymity level (NBO), zero for remove.
*/
uint32_t anonymity GNUNET_PACKED;
+
+ /**
+ * Unique ID for the content (can be used for UPDATE).
+ */
+ uint64_t uid;
/**
* Expiration time (NBO); zero for remove.
Modified: gnunet/src/datastore/datastore_api.c
===================================================================
--- gnunet/src/datastore/datastore_api.c 2009-06-16 20:13:13 UTC (rev
8587)
+++ gnunet/src/datastore/datastore_api.c 2009-06-16 20:32:40 UTC (rev
8588)
@@ -26,7 +26,6 @@
* TODO:
* 1) clarify API (wrt. efficient UPDATE of priority/expiration after GET)
* 2) implement INIT
- * 3) implement SIZE handling (=> API impact?)
* 4) implement DROP
* 5) implement PUT
* 6) implement GET
@@ -93,17 +92,6 @@
*/
void *response_proc_cls;
- /**
- * Current size of the datastore (cached).
- */
- unsigned long long size;
-
- /**
- * Set to GNUNET_YES if we have received the size
- * from the datastore.
- */
- int ready;
-
};
@@ -129,7 +117,6 @@
return NULL; /* oops */
h = GNUNET_malloc (sizeof(struct GNUNET_DATASTORE_Handle));
h->client = c;
- /* FIXME: send 'join' request */
return h;
}
@@ -154,19 +141,6 @@
/**
- * Get the current on-disk size of the datastore.
- * @param h handle to the datastore
- * @return size estimate, -1 if datastore is not available (yet)
- */
-unsigned long long GNUNET_DATASTORE_size (struct GNUNET_DATASTORE_Handle *h)
-{
- if (GNUNET_YES != h->ready)
- return (unsigned long long) -1LL;
- return h->size;
-}
-
-
-/**
* 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.
@@ -179,21 +153,93 @@
* @param priority priority of the content
* @param anonymity anonymity-level for the content
* @param expiration expiration time for the content
+ * @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,
uint32_t type,
uint32_t priority,
uint32_t anonymity,
- struct GNUNET_TIME_Absolute expiration)
+ struct GNUNET_TIME_Absolute expiration,
+ GNUNET_DATASTORE_ContinuationWithStatus cont,
+ void *cont_cls)
{
+ cont (cont_cls, GNUNET_SYSERR, "not implemented");
}
/**
+ * Reserve space in the datastore. This function should be used
+ * to avoid "out of space" failures during a longer sequence of "put"
+ * operations (for example, when a file is being inserted).
+ *
+ * @param h handle to the datastore
+ * @param amount how much space (in bytes) should be reserved (for content
only)
+ * @param entries how many entries will be created (to calculate per-entry
overhead)
+ * @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
+ */
+void
+GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h,
+ uint64_t amount,
+ uint64_t entries,
+ GNUNET_DATASTORE_ContinuationWithStatus cont,
+ void *cont_cls)
+{
+ cont (cont_cls, GNUNET_SYSERR, "not implemented");
+}
+
+
+/**
+ * Signal that all of the data for which a reservation was made has
+ * been stored and that whatever excess space might have been reserved
+ * can now be released.
+ *
+ * @param h handle to the datastore
+ * @param rid reservation ID (value of "success" in original continuation
+ * from the "reserve" function).
+ * @param cont continuation to call when done
+ * @param cont_cls closure for cont
+ */
+void
+GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h,
+ int rid,
+ GNUNET_DATASTORE_ContinuationWithStatus cont,
+ void *cont_cls)
+{
+ cont (cont_cls, GNUNET_OK, NULL);
+}
+
+
+/**
+ * Update a value in the datastore.
+ *
+ * @param h handle to the datastore
+ * @param uid identifier for the value
+ * @param priority how much to increase the priority of the value
+ * @param expiration new expiration value should be MAX of existing and this
argument
+ * @param cont continuation to call when done
+ * @param cont_cls closure for cont
+ */
+void
+GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h,
+ unsigned long long uid,
+ uint32_t priority,
+ struct GNUNET_TIME_Absolute expiration,
+ GNUNET_DATASTORE_ContinuationWithStatus cont,
+ void *cont_cls)
+{
+ cont (cont_cls, GNUNET_SYSERR, "not implemented");
+}
+
+
+/**
* Iterate over the results for a particular key
* in the datastore.
*
@@ -210,6 +256,9 @@
uint32_t type,
GNUNET_DATASTORE_Iterator iter, void *iter_cls)
{
+ static struct GNUNET_TIME_Absolute zero;
+ iter (iter_cls,
+ NULL, 0, NULL, 0, 0, 0, zero, 0);
}
@@ -240,12 +289,17 @@
* @param key key for the value
* @param size number of bytes in data
* @param data content stored
+ * @param cont continuation to call when done
+ * @param cont_cls closure for cont
*/
void
GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
const GNUNET_HashCode * key,
- uint32_t size, const void *data)
+ uint32_t size, const void *data,
+ GNUNET_DATASTORE_ContinuationWithStatus cont,
+ void *cont_cls)
{
+ cont (cont_cls, GNUNET_SYSERR, "not implemented");
}
Modified: gnunet/src/datastore/gnunet-service-datastore.c
===================================================================
--- gnunet/src/datastore/gnunet-service-datastore.c 2009-06-16 20:13:13 UTC
(rev 8587)
+++ gnunet/src/datastore/gnunet-service-datastore.c 2009-06-16 20:32:40 UTC
(rev 8588)
@@ -92,18 +92,28 @@
/**
- * Transmit the size of the current datastore to the client.
+ * Transmit a status code to the client.
+ *
+ * @param client receiver of the response
+ * @param code status code
+ * @param msg optional error message (can be NULL)
*/
static void
-transmit_size (struct GNUNET_SERVER_Client *client)
+transmit_status (struct GNUNET_SERVER_Client *client,
+ int code,
+ const char *msg)
{
- struct SizeMessage sm;
-
- sm.header.size = htons(sizeof(struct SizeMessage));
- sm.header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_SIZE);
- sm.reserved = htonl(0);
- sm.size = GNUNET_htonll(plugin->api->get_size (plugin->api->cls));
- transmit (client, &sm.header);
+ struct StatusMessage *sm;
+ size_t slen;
+
+ 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);
+ memcpy (&sm[1], msg, slen);
+ transmit (client, &sm->header);
+ GNUNET_free (sm);
}
@@ -148,16 +158,16 @@
transmit (client, &end);
return GNUNET_OK;
}
- /* FIXME: make use of 'uid' for efficient priority/expiration update! */
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->reserved = htonl(0);
+ dm->rid = htonl(0);
dm->size = htonl(size);
dm->type = htonl(type);
dm->priority = htonl(priority);
dm->anonymity = htonl(anonymity);
dm->expiration = GNUNET_TIME_absolute_hton(expiration);
+ dm->uid = GNUNET_htonll(uid);
dm->key = *key;
memcpy (&dm[1], data, size);
transmit (client, &dm->header);
@@ -167,23 +177,40 @@
/**
- * Handle INIT-message.
+ * Handle RESERVE-message.
*
* @param cls closure
* @param client identification of the client
* @param message the actual message
*/
static void
-handle_init (void *cls,
+handle_reserve (void *cls,
struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
- transmit_size (client);
+ transmit_status (client, GNUNET_SYSERR, "not implemented");
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
}
/**
+ * Handle RELEASE_RESERVE-message.
+ *
+ * @param cls closure
+ * @param client identification of the client
+ * @param message the actual message
+ */
+static void
+handle_release_reserve (void *cls,
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
+{
+ transmit_status (client, GNUNET_SYSERR, "not implemented");
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+}
+
+
+/**
* Check that the given message is a valid data message.
*
* @return NULL if the message is not well-formed, otherwise the message
@@ -208,8 +235,7 @@
GNUNET_break (0);
return NULL;
}
- if ( (ntohl(dm->type) == 0) ||
- (ntohl(dm->reserved) != 0) )
+ if (ntohl(dm->type) == 0)
{
GNUNET_break (0);
return NULL;
@@ -231,21 +257,33 @@
const struct GNUNET_MessageHeader *message)
{
const struct DataMessage *dm = check_data (message);
+ char *msg;
+ int ret;
+ int rid;
+
if (dm == NULL)
{
GNUNET_break (0);
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
- plugin->api->put (plugin->api->cls,
- &dm->key,
- ntohl(dm->size),
- &dm[1],
- ntohl(dm->type),
- ntohl(dm->priority),
- ntohl(dm->anonymity),
- GNUNET_TIME_absolute_ntoh(dm->expiration));
- transmit_size (client);
+ rid = ntohl(dm->rid);
+ if (rid > 0)
+ {
+ /* FIXME: find reservation, update remaining! */
+ }
+ msg = NULL;
+ ret = plugin->api->put (plugin->api->cls,
+ &dm->key,
+ ntohl(dm->size),
+ &dm[1],
+ ntohl(dm->type),
+ ntohl(dm->priority),
+ ntohl(dm->anonymity),
+ GNUNET_TIME_absolute_ntoh(dm->expiration),
+ &msg);
+ transmit_status (client, ret, msg);
+ GNUNET_free_non_null (msg);
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
}
@@ -285,6 +323,35 @@
/**
+ * Handle UPDATE-message.
+ *
+ * @param cls closure
+ * @param client identification of the client
+ * @param message the actual message
+ */
+static void
+handle_update (void *cls,
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
+{
+ const struct UpdateMessage *msg;
+ int ret;
+ char *emsg;
+
+ msg = (const struct UpdateMessage*) message;
+ emsg = NULL;
+ ret = plugin->api->update (plugin->api->cls,
+ 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);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+}
+
+
+/**
* Handle GET_RANDOM-message.
*
* @param cls closure
@@ -319,6 +386,8 @@
struct GNUNET_TIME_Absolute
expiration, unsigned long long uid)
{
+ int *found = cls;
+ *found = GNUNET_YES;
return GNUNET_NO;
}
@@ -337,6 +406,7 @@
{
const struct DataMessage *dm = check_data (message);
GNUNET_HashCode vhash;
+ int found;
if (dm == NULL)
{
@@ -344,6 +414,7 @@
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
+ found = GNUNET_NO;
GNUNET_CRYPTO_hash (&dm[1],
ntohl(dm->size),
&vhash);
@@ -352,8 +423,11 @@
&vhash,
ntohl(dm->type),
&remove_callback,
- NULL);
- transmit_size (client);
+ &found);
+ if (GNUNET_YES == found)
+ transmit_status (client, GNUNET_OK, NULL);
+ else
+ transmit_status (client, GNUNET_SYSERR, _("Content not found"));
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
@@ -380,9 +454,13 @@
* service.
*/
static struct GNUNET_SERVER_MessageHandler handlers[] = {
- {&handle_init, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_INIT,
- 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_random, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_GET_RANDOM,
sizeof(struct GNUNET_MessageHeader) },
Modified: gnunet/src/datastore/plugin_datastore.h
===================================================================
--- gnunet/src/datastore/plugin_datastore.h 2009-06-16 20:13:13 UTC (rev
8587)
+++ gnunet/src/datastore/plugin_datastore.h 2009-06-16 20:32:40 UTC (rev
8588)
@@ -73,8 +73,10 @@
* @param priority priority of the content
* @param anonymity anonymity-level for the content
* @param expiration expiration time for the content
+ * @param msg set to an error message (on failure)
+ * @return GNUNET_OK on success, GNUNET_SYSERR on failure
*/
-typedef void
+typedef int
(*GNUNET_DATASTORE_Put) (void *cls,
const GNUNET_HashCode * key,
uint32_t size,
@@ -82,7 +84,8 @@
uint32_t type,
uint32_t priority,
uint32_t anonymity,
- struct GNUNET_TIME_Absolute expiration);
+ struct GNUNET_TIME_Absolute expiration,
+ char **msg);
/**
@@ -129,11 +132,14 @@
* @param expire new expiration time should be the
* MAX of any existing expiration time and
* this value
+ * @param msg set to an error message (on error)
+ * @return GNUNET_OK on success
*/
-typedef void
+typedef int
(*GNUNET_DATASTORE_Update) (void *cls,
unsigned long long uid,
- int delta, struct GNUNET_TIME_Absolute expire);
+ int delta, struct GNUNET_TIME_Absolute expire,
+ char **msg);
/**
Modified: gnunet/src/datastore/plugin_datastore_sqlite.c
===================================================================
--- gnunet/src/datastore/plugin_datastore_sqlite.c 2009-06-16 20:13:13 UTC
(rev 8587)
+++ gnunet/src/datastore/plugin_datastore_sqlite.c 2009-06-16 20:32:40 UTC
(rev 8588)
@@ -62,8 +62,10 @@
* @param priority priority of the content
* @param anonymity anonymity-level for the content
* @param expiration expiration time for the content
+ * @param msg set to an error message
+ * @return GNUNET_OK on success
*/
-static void
+static int
sqlite_plugin_put (void *cls,
const GNUNET_HashCode * key,
uint32_t size,
@@ -71,8 +73,11 @@
uint32_t type,
uint32_t priority,
uint32_t anonymity,
- struct GNUNET_TIME_Absolute expiration)
+ struct GNUNET_TIME_Absolute expiration,
+ char ** msg)
{
+ *msg = GNUNET_strdup("not implemented");
+ return GNUNET_SYSERR;
}
@@ -100,6 +105,8 @@
uint32_t type,
GNUNET_DATASTORE_Iterator iter, void *iter_cls)
{
+ static struct GNUNET_TIME_Absolute zero;
+ iter (iter_cls, NULL, 0, NULL, 0, 0, 0, zero, 0);
}
@@ -122,12 +129,17 @@
* @param expire new expiration time should be the
* MAX of any existing expiration time and
* this value
+ * @param msg set to an error message
+ * @return GNUNET_OK on success
*/
-static void
+static int
sqlite_plugin_update (void *cls,
unsigned long long uid,
- int delta, struct GNUNET_TIME_Absolute expire)
+ int delta, struct GNUNET_TIME_Absolute expire,
+ char **msg)
{
+ *msg = GNUNET_strdup ("not implemented");
+ return GNUNET_SYSERR;
}
@@ -147,10 +159,11 @@
GNUNET_DATASTORE_Iterator iter,
void *iter_cls)
{
+ static struct GNUNET_TIME_Absolute zero;
+ iter (iter_cls, NULL, 0, NULL, 0, 0, 0, zero, 0);
}
-
/**
* Select a subset of the items in the datastore and call
* the given iterator for each of them.
@@ -167,6 +180,8 @@
GNUNET_DATASTORE_Iterator iter,
void *iter_cls)
{
+ static struct GNUNET_TIME_Absolute zero;
+ iter (iter_cls, NULL, 0, NULL, 0, 0, 0, zero, 0);
}
@@ -187,6 +202,8 @@
GNUNET_DATASTORE_Iterator iter,
void *iter_cls)
{
+ static struct GNUNET_TIME_Absolute zero;
+ iter (iter_cls, NULL, 0, NULL, 0, 0, 0, zero, 0);
}
@@ -207,6 +224,8 @@
GNUNET_DATASTORE_Iterator iter,
void *iter_cls)
{
+ static struct GNUNET_TIME_Absolute zero;
+ iter (iter_cls, NULL, 0, NULL, 0, 0, 0, zero, 0);
}
@@ -227,6 +246,8 @@
GNUNET_DATASTORE_Iterator iter,
void *iter_cls)
{
+ static struct GNUNET_TIME_Absolute zero;
+ iter (iter_cls, NULL, 0, NULL, 0, 0, 0, zero, 0);
}
Modified: gnunet/src/datastore/plugin_datastore_template.c
===================================================================
--- gnunet/src/datastore/plugin_datastore_template.c 2009-06-16 20:13:13 UTC
(rev 8587)
+++ gnunet/src/datastore/plugin_datastore_template.c 2009-06-16 20:32:40 UTC
(rev 8588)
@@ -62,8 +62,10 @@
* @param priority priority of the content
* @param anonymity anonymity-level for the content
* @param expiration expiration time for the content
+ * @param msg set to error message
+ * @return GNUNET_OK on success
*/
-static void
+static int
template_plugin_put (void *cls,
const GNUNET_HashCode * key,
uint32_t size,
@@ -71,8 +73,11 @@
uint32_t type,
uint32_t priority,
uint32_t anonymity,
- struct GNUNET_TIME_Absolute expiration)
+ struct GNUNET_TIME_Absolute expiration,
+ char **msg)
{
+ *msg = GNUNET_strdup ("not implemented");
+ return GNUNET_SYSERR;
}
@@ -122,12 +127,17 @@
* @param expire new expiration time should be the
* MAX of any existing expiration time and
* this value
+ * @param msg set to error message
+ * @return GNUNET_OK on success
*/
-static void
+static int
template_plugin_update (void *cls,
- unsigned long long uid,
- int delta, struct GNUNET_TIME_Absolute expire)
+ unsigned long long uid,
+ int delta, struct GNUNET_TIME_Absolute expire,
+ char **msg)
{
+ *msg = GNUNET_strdup ("not implemented");
+ return GNUNET_SYSERR;
}
Modified: gnunet/src/include/gnunet_datastore_service.h
===================================================================
--- gnunet/src/include/gnunet_datastore_service.h 2009-06-16 20:13:13 UTC
(rev 8587)
+++ gnunet/src/include/gnunet_datastore_service.h 2009-06-16 20:32:40 UTC
(rev 8588)
@@ -49,33 +49,6 @@
/**
- * An iterator over a set of items stored in the datastore.
- *
- * @param cls closure
- * @param key key for the content
- * @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 uid unique identifier for the datum;
- * maybe 0 if no unique identifier is available
- *
- * @return GNUNET_SYSERR to abort the iteration, GNUNET_OK to continue,
- * GNUNET_NO to delete the item and continue (if supported)
- */
-typedef int (*GNUNET_DATASTORE_Iterator) (void *cls,
- const GNUNET_HashCode * key,
- uint32_t size,
- const void *data,
- uint32_t type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute
- expiration, unsigned long long uid);
-
-/**
* Connect to the datastore service.
*
* @param cfg configuration to use
@@ -102,11 +75,36 @@
/**
- * Get the current on-disk size of the datastore.
+ * Continuation called to notify client about result of the
+ * operation.
+ *
+ * @param cls closure
+ * @param success GNUNET_SYSERR on failure
+ * @param msg NULL on success, otherwise an error message
+ */
+typedef void (*GNUNET_DATASTORE_ContinuationWithStatus)(void *cls,
+ int success,
+ const char *msg);
+
+
+/**
+ * Reserve space in the datastore. This function should be used
+ * to avoid "out of space" failures during a longer sequence of "put"
+ * operations (for example, when a file is being inserted).
+ *
* @param h handle to the datastore
- * @return size estimate, -1 if datastore is not available (yet)
+ * @param amount how much space (in bytes) should be reserved (for content
only)
+ * @param entries how many entries will be created (to calculate per-entry
overhead)
+ * @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
*/
-unsigned long long GNUNET_DATASTORE_size (struct GNUNET_DATASTORE_Handle *h);
+void
+GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h,
+ uint64_t amount,
+ uint64_t entries,
+ GNUNET_DATASTORE_ContinuationWithStatus cont,
+ void *cont_cls);
/**
@@ -115,6 +113,8 @@
* 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
@@ -122,18 +122,89 @@
* @param priority priority of the content
* @param anonymity anonymity-level for the content
* @param expiration expiration time for the content
+ * @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,
uint32_t type,
uint32_t priority,
uint32_t anonymity,
- struct GNUNET_TIME_Absolute expiration);
+ struct GNUNET_TIME_Absolute expiration,
+ GNUNET_DATASTORE_ContinuationWithStatus cont,
+ void *cont_cls);
+
/**
+ * Signal that all of the data for which a reservation was made has
+ * been stored and that whatever excess space might have been reserved
+ * can now be released.
+ *
+ * @param h handle to the datastore
+ * @param rid reservation ID (value of "success" in original continuation
+ * from the "reserve" function).
+ * @param cont continuation to call when done
+ * @param cont_cls closure for cont
+ */
+void
+GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h,
+ int rid,
+ GNUNET_DATASTORE_ContinuationWithStatus cont,
+ void *cont_cls);
+
+
+/**
+ * Update a value in the datastore.
+ *
+ * @param h handle to the datastore
+ * @param uid identifier for the value
+ * @param priority how much to increase the priority of the value
+ * @param expiration new expiration value should be MAX of existing and this
argument
+ * @param cont continuation to call when done
+ * @param cont_cls closure for cont
+ */
+void
+GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h,
+ unsigned long long uid,
+ uint32_t priority,
+ struct GNUNET_TIME_Absolute expiration,
+ GNUNET_DATASTORE_ContinuationWithStatus cont,
+ void *cont_cls);
+
+
+/**
+ * An iterator over a set of items stored in the datastore.
+ *
+ * @param cls closure
+ * @param key key for the content
+ * @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 uid unique identifier for the datum;
+ * maybe 0 if no unique identifier is available
+ *
+ * @return GNUNET_SYSERR to abort the iteration, GNUNET_OK to continue,
+ * GNUNET_NO to delete the item and continue (if supported)
+ */
+typedef int (*GNUNET_DATASTORE_Iterator) (void *cls,
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ uint32_t type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute
+ expiration, unsigned long long uid);
+
+
+/**
* Iterate over the results for a particular key
* in the datastore.
*
@@ -172,11 +243,15 @@
* @param key key for the value
* @param size number of bytes in data
* @param data content stored
+ * @param cont continuation to call when done
+ * @param cont_cls closure for cont
*/
void
GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
const GNUNET_HashCode *key,
- uint32_t size, const void *data);
+ uint32_t size, const void *data,
+ GNUNET_DATASTORE_ContinuationWithStatus cont,
+ void *cont_cls);
#if 0 /* keep Emacsens' auto-indent happy */
Modified: gnunet/src/include/gnunet_protocols.h
===================================================================
--- gnunet/src/include/gnunet_protocols.h 2009-06-16 20:13:13 UTC (rev
8587)
+++ gnunet/src/include/gnunet_protocols.h 2009-06-16 20:32:40 UTC (rev
8588)
@@ -306,51 +306,62 @@
/**
* Message sent by datastore client on join.
*/
-#define GNUNET_MESSAGE_TYPE_DATASTORE_INIT 92
+#define GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE 92
/**
- * Message sent by datastore to client informing about size.
- * (in response to JOIN, PUT and REMOVE requests).
+ * Message sent by datastore client on join.
*/
-#define GNUNET_MESSAGE_TYPE_DATASTORE_SIZE 93
+#define GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE 93
/**
+ * Message sent by datastore to client informing about status
+ * processing a request
+ * (in response to RESERVE, RELEASE_RESERVE, PUT, UPDATE and REMOVE requests).
+ */
+#define GNUNET_MESSAGE_TYPE_DATASTORE_STATUS 94
+
+/**
* Message sent by datastore client to store data.
*/
-#define GNUNET_MESSAGE_TYPE_DATASTORE_PUT 94
+#define GNUNET_MESSAGE_TYPE_DATASTORE_PUT 95
/**
+ * Message sent by datastore client to update data.
+ */
+#define GNUNET_MESSAGE_TYPE_DATASTORE_UPDATE 96
+
+/**
* Message sent by datastore client to get data.
*/
-#define GNUNET_MESSAGE_TYPE_DATASTORE_GET 95
+#define GNUNET_MESSAGE_TYPE_DATASTORE_GET 97
/**
* Message sent by datastore client to get random data.
*/
-#define GNUNET_MESSAGE_TYPE_DATASTORE_GET_RANDOM 96
+#define GNUNET_MESSAGE_TYPE_DATASTORE_GET_RANDOM 98
/**
* Message sent by datastore to client providing requested data
* (in response to GET or GET_RANDOM request).
*/
-#define GNUNET_MESSAGE_TYPE_DATASTORE_DATA 97
+#define GNUNET_MESSAGE_TYPE_DATASTORE_DATA 99
/**
* Message sent by datastore to client signaling end of matching data.
* This message will also be sent for "GET_RANDOM", even though
* "GET_RANDOM" returns at most one data item.
*/
-#define GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END 98
+#define GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END 100
/**
* Message sent by datastore client to remove data.
*/
-#define GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE 99
+#define GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE 101
/**
* Message sent by datastore client to drop the database.
*/
-#define GNUNET_MESSAGE_TYPE_DATASTORE_DROP 100
+#define GNUNET_MESSAGE_TYPE_DATASTORE_DROP 102
/*
TODO:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r8588 - in gnunet/src: datastore include,
gnunet <=