[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r34060 - in gnunet/src: include psycstore
From: |
gnunet |
Subject: |
[GNUnet-SVN] r34060 - in gnunet/src: include psycstore |
Date: |
Sun, 27 Jul 2014 13:35:43 +0200 |
Author: tg
Date: 2014-07-27 13:35:43 +0200 (Sun, 27 Jul 2014)
New Revision: 34060
Modified:
gnunet/src/include/gnunet_psycstore_service.h
gnunet/src/psycstore/gnunet-service-psycstore.c
gnunet/src/psycstore/psycstore.h
gnunet/src/psycstore/psycstore_api.c
gnunet/src/psycstore/test_psycstore.c
Log:
psycstore: add option to perform membership test when retrieving fragment or
message
Modified: gnunet/src/include/gnunet_psycstore_service.h
===================================================================
--- gnunet/src/include/gnunet_psycstore_service.h 2014-07-27 01:23:58 UTC
(rev 34059)
+++ gnunet/src/include/gnunet_psycstore_service.h 2014-07-27 11:35:43 UTC
(rev 34060)
@@ -46,6 +46,11 @@
#define GNUNET_PSYCSTORE_VERSION 0x00000000
/**
+ * Membership test failed.
+ */
+#define GNUNET_PSYCSTORE_MEMBERSHIP_TEST_FAILED -2
+
+/**
* Flags for stored messages.
*/
enum GNUNET_PSYCSTORE_MessageFlags
@@ -217,18 +222,29 @@
/**
* Retrieve a message fragment by fragment ID.
*
- * @param h Handle for the PSYCstore.
- * @param channel_key The channel we are interested in.
- * @param fragment_id Fragment ID to check. Use 0 to get the latest message
fragment.
- * @param fcb Callback to call with the retrieved fragment.
- * @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 slave_key
+ * 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
+ * Callback to call with the retrieved fragments.
+ * @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.
*/
struct GNUNET_PSYCSTORE_OperationHandle *
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,
GNUNET_PSYCSTORE_ResultCallback rcb,
@@ -238,18 +254,29 @@
/**
* Retrieve all fragments of a message.
*
- * @param h Handle for the PSYCstore.
- * @param channel_key The channel we are interested in.
- * @param message_id Message ID to check. Use 0 to get the latest message.
- * @param fcb Callback to call with the retrieved fragments.
- * @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 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_id
+ * Message ID to retrieve. Use 0 to get the latest message.
+ * @param fcb
+ * Callback to call with the retrieved fragments.
+ * @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.
*/
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,
GNUNET_PSYCSTORE_ResultCallback rcb,
@@ -273,6 +300,7 @@
struct GNUNET_PSYCSTORE_OperationHandle *
GNUNET_PSYCSTORE_message_get_fragment (struct GNUNET_PSYCSTORE_Handle *h,
const struct
GNUNET_CRYPTO_EddsaPublicKey *channel_key,
+ const struct
GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
uint64_t message_id,
uint64_t fragment_offset,
GNUNET_PSYCSTORE_FragmentCallback fcb,
Modified: gnunet/src/psycstore/gnunet-service-psycstore.c
===================================================================
--- gnunet/src/psycstore/gnunet-service-psycstore.c 2014-07-27 01:23:58 UTC
(rev 34059)
+++ gnunet/src/psycstore/gnunet-service-psycstore.c 2014-07-27 11:35:43 UTC
(rev 34060)
@@ -122,11 +122,43 @@
GNUNET_free (res);
}
+enum
+{
+ MEMBERSHIP_TEST_NOT_NEEDED = 0,
+ MEMBERSHIP_TEST_NEEDED = 1,
+ MEMBERSHIP_TEST_DONE = 2,
+} MessageMembershipTest;
struct SendClosure
{
struct GNUNET_SERVER_Client *client;
+
+ /**
+ * Channel's public key.
+ */
+ struct GNUNET_CRYPTO_EddsaPublicKey channel_key;
+
+ /**
+ * Slave's public key.
+ */
+ struct GNUNET_CRYPTO_EcdsaPublicKey slave_key;
+
+ /**
+ * Operation ID.
+ */
uint64_t op_id;
+
+ /**
+ * Membership test result.
+ */
+ int membership_test_result;
+
+ /**
+ * Do membership test with @a slave_key before returning fragment?
+ * @see enum MessageMembershipTest
+ */
+ uint8_t membership_test;
+
};
@@ -136,6 +168,24 @@
{
struct SendClosure *sc = cls;
struct FragmentResult *res;
+
+ if (MEMBERSHIP_TEST_NEEDED == sc->membership_test)
+ {
+ sc->membership_test = MEMBERSHIP_TEST_DONE;
+ sc->membership_test_result
+ = db->membership_test (db->cls, &sc->channel_key, &sc->slave_key,
+ GNUNET_ntohll (msg->message_id));
+ switch (sc->membership_test_result)
+ {
+ case GNUNET_YES:
+ break;
+
+ case GNUNET_NO:
+ case GNUNET_SYSERR:
+ return GNUNET_NO;
+ }
+ }
+
size_t msg_size = ntohs (msg->header.size);
res = GNUNET_malloc (sizeof (struct FragmentResult) + msg_size);
@@ -152,7 +202,7 @@
GNUNET_SERVER_notification_context_unicast (nc, sc->client, &res->header,
GNUNET_NO);
GNUNET_free (res);
- return GNUNET_OK;
+ return GNUNET_YES;
}
@@ -255,9 +305,12 @@
struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *msg)
{
- const struct FragmentGetRequest *req
- = (const struct FragmentGetRequest *) msg;
- struct SendClosure sc = { .op_id = req->op_id, .client = client };
+ const struct FragmentGetRequest *
+ req = (const struct FragmentGetRequest *) msg;
+ struct SendClosure
+ sc = { .op_id = req->op_id, .client = client,
+ .channel_key = req->channel_key, .slave_key = req->slave_key,
+ .membership_test = req->do_membership_test };
int ret = db->fragment_get (db->cls, &req->channel_key,
GNUNET_ntohll (req->fragment_id),
@@ -266,6 +319,22 @@
{
case GNUNET_YES:
case GNUNET_NO:
+ if (MEMBERSHIP_TEST_DONE == sc.membership_test)
+ {
+ switch (sc.membership_test_result)
+ {
+ case GNUNET_YES:
+ break;
+
+ case GNUNET_NO:
+ ret = GNUNET_PSYCSTORE_MEMBERSHIP_TEST_FAILED;
+ break;
+
+ case GNUNET_SYSERR:
+ ret = GNUNET_SYSERR;
+ break;
+ }
+ }
break;
default:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -282,8 +351,13 @@
struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *msg)
{
- const struct MessageGetRequest *req = (const struct MessageGetRequest *) msg;
- struct SendClosure sc = { .op_id = req->op_id, .client = client };
+ const struct MessageGetRequest *
+ req = (const struct MessageGetRequest *) msg;
+ struct SendClosure
+ sc = { .op_id = req->op_id, .client = client,
+ .channel_key = req->channel_key, .slave_key = req->slave_key,
+ .membership_test = req->do_membership_test };
+
uint64_t ret_frags = 0;
int64_t ret = db->message_get (db->cls, &req->channel_key,
GNUNET_ntohll (req->message_id),
@@ -309,11 +383,13 @@
struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *msg)
{
- const struct MessageGetFragmentRequest *req =
- (const struct MessageGetFragmentRequest *) msg;
+ const struct MessageGetFragmentRequest *
+ req = (const struct MessageGetFragmentRequest *) msg;
+ struct SendClosure
+ sc = { .op_id = req->op_id, .client = client,
+ .channel_key = req->channel_key, .slave_key = req->slave_key,
+ .membership_test = req->do_membership_test };
- struct SendClosure sc = { .op_id = req->op_id, .client = client };
-
int ret = db->message_get_fragment (db->cls, &req->channel_key,
GNUNET_ntohll (req->message_id),
GNUNET_ntohll (req->fragment_offset),
Modified: gnunet/src/psycstore/psycstore.h
===================================================================
--- gnunet/src/psycstore/psycstore.h 2014-07-27 01:23:58 UTC (rev 34059)
+++ gnunet/src/psycstore/psycstore.h 2014-07-27 11:35:43 UTC (rev 34060)
@@ -264,7 +264,21 @@
*/
struct GNUNET_CRYPTO_EddsaPublicKey channel_key;
+ /**
+ * Slave's public key.
+ */
+ struct GNUNET_CRYPTO_EcdsaPublicKey slave_key;
+
+ /**
+ * Fragment ID to request.
+ */
uint64_t fragment_id GNUNET_PACKED;
+
+ /**
+ * Do membership test with @a slave_key before returning fragment?
+ * #GNUNET_YES or #GNUNET_NO
+ */
+ uint8_t do_membership_test;
};
@@ -288,7 +302,21 @@
*/
struct GNUNET_CRYPTO_EddsaPublicKey channel_key;
+ /**
+ * Slave's public key.
+ */
+ struct GNUNET_CRYPTO_EcdsaPublicKey slave_key;
+
+ /**
+ * Message ID to request.
+ */
uint64_t message_id GNUNET_PACKED;
+
+ /**
+ * Do membership test with @a slave_key before returning fragment?
+ * #GNUNET_YES or #GNUNET_NO
+ */
+ uint8_t do_membership_test;
};
@@ -312,9 +340,26 @@
*/
struct GNUNET_CRYPTO_EddsaPublicKey channel_key;
+ /**
+ * Slave's public key.
+ */
+ struct GNUNET_CRYPTO_EcdsaPublicKey slave_key;
+
+ /**
+ * Requested message ID.
+ */
uint64_t message_id GNUNET_PACKED;
+ /**
+ * Requested fragment offset.
+ */
uint64_t fragment_offset GNUNET_PACKED;
+
+ /**
+ * Do membership test with @a slave_key before returning fragment?
+ * #GNUNET_YES or #GNUNET_NO
+ */
+ uint8_t do_membership_test;
};
Modified: gnunet/src/psycstore/psycstore_api.c
===================================================================
--- gnunet/src/psycstore/psycstore_api.c 2014-07-27 01:23:58 UTC (rev
34059)
+++ gnunet/src/psycstore/psycstore_api.c 2014-07-27 11:35:43 UTC (rev
34060)
@@ -804,18 +804,29 @@
/**
* Retrieve a message fragment by fragment ID.
*
- * @param h Handle for the PSYCstore.
- * @param channel_key The channel we are interested in.
- * @param fragment_id Fragment ID to check. Use 0 to get the latest message
fragment.
- * @param fcb Callback to call with the retrieved fragments.
- * @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 slave_key
+ * 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
+ * Callback to call with the retrieved fragments.
+ * @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.
*/
struct GNUNET_PSYCSTORE_OperationHandle *
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,
GNUNET_PSYCSTORE_ResultCallback rcb,
@@ -835,6 +846,11 @@
req->header.size = htons (sizeof (*req));
req->channel_key = *channel_key;
req->fragment_id = GNUNET_htonll (fragment_id);
+ 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 = htonl (op->op_id);
@@ -849,18 +865,29 @@
/**
* Retrieve all fragments of a message.
*
- * @param h Handle for the PSYCstore.
- * @param channel_key The channel we are interested in.
- * @param message_id Message ID to check. Use 0 to get the latest message.
- * @param fcb Callback to call with the retrieved fragments.
- * @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 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_id
+ * Message ID to retrieve. Use 0 to get the latest message.
+ * @param fcb
+ * Callback to call with the retrieved fragments.
+ * @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.
*/
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,
GNUNET_PSYCSTORE_ResultCallback rcb,
@@ -880,6 +907,11 @@
req->header.size = htons (sizeof (*req));
req->channel_key = *channel_key;
req->message_id = GNUNET_htonll (message_id);
+ 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 = htonl (op->op_id);
@@ -895,19 +927,31 @@
* Retrieve a fragment of message specified by its message ID and fragment
* offset.
*
- * @param h Handle for the PSYCstore.
- * @param channel_key The channel we are interested in.
- * @param message_id Message ID to check. Use 0 to get the latest message.
- * @param fragment_offset Offset of the fragment to retrieve.
- * @param fcb Callback to call with the retrieved fragments.
- * @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 slave_key
+ * The slave requesting the message fragment. If not NULL, a membership
+ * test is performed first and the message 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 fragment_offset
+ * Offset of the fragment to retrieve.
+ * @param fcb
+ * Callback to call with the retrieved fragments.
+ * @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.
*/
struct GNUNET_PSYCSTORE_OperationHandle *
GNUNET_PSYCSTORE_message_get_fragment (struct GNUNET_PSYCSTORE_Handle *h,
const struct
GNUNET_CRYPTO_EddsaPublicKey *channel_key,
+ const struct
GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
uint64_t message_id,
uint64_t fragment_offset,
GNUNET_PSYCSTORE_FragmentCallback fcb,
@@ -929,6 +973,11 @@
req->channel_key = *channel_key;
req->message_id = GNUNET_htonll (message_id);
req->fragment_offset = GNUNET_htonll (fragment_offset);
+ 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 = htonl (op->op_id);
Modified: gnunet/src/psycstore/test_psycstore.c
===================================================================
--- gnunet/src/psycstore/test_psycstore.c 2014-07-27 01:23:58 UTC (rev
34059)
+++ gnunet/src/psycstore/test_psycstore.c 2014-07-27 11:35:43 UTC (rev
34060)
@@ -331,7 +331,6 @@
GNUNET_assert (result > 0 && fcls->n && fcls->n_expected);
-
modifiers[0] = (struct GNUNET_ENV_Modifier) {
.oper = '=',
.name = "_sync_foo",
@@ -361,7 +360,7 @@
fcls->n = 0;
fcls->n_expected = 3;
- op = GNUNET_PSYCSTORE_message_get (h, &channel_pub_key,
+ op = GNUNET_PSYCSTORE_message_get (h, &channel_pub_key, &slave_pub_key,
GNUNET_ntohll (fcls->msg[0]->message_id),
&fragment_result,
&message_get_result, fcls);
@@ -378,7 +377,7 @@
fcls->n = 1;
fcls->n_expected = 2;
- op = GNUNET_PSYCSTORE_message_get_fragment (h, &channel_pub_key,
+ op = GNUNET_PSYCSTORE_message_get_fragment (h, &channel_pub_key,
&slave_pub_key,
GNUNET_ntohll
(fcls->msg[1]->message_id),
GNUNET_ntohll
(fcls->msg[1]->fragment_offset),
&fragment_result,
@@ -396,10 +395,10 @@
GNUNET_assert (GNUNET_OK == result);
if ((intptr_t) cls == GNUNET_YES)
- {
+ { /* last fragment */
fcls.n = 0;
fcls.n_expected = 1;
- op = GNUNET_PSYCSTORE_fragment_get (h, &channel_pub_key,
+ op = GNUNET_PSYCSTORE_fragment_get (h, &channel_pub_key, &slave_pub_key,
GNUNET_ntohll
(fcls.msg[0]->fragment_id),
&fragment_result,
&fragment_get_result, &fcls);
@@ -408,12 +407,8 @@
void
-membership_test_result (void *cls, int64_t result, const char *err_msg)
+fragment_store ()
{
- op = NULL;
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "membership_test:\t%d\n", result);
- GNUNET_assert (GNUNET_OK == result);
-
struct GNUNET_MULTICAST_MessageHeader *msg;
fcls.flags[0] = GNUNET_PSYCSTORE_MESSAGE_STATE;
fcls.msg[0] = msg = GNUNET_malloc (sizeof (*msg) + sizeof (channel_pub_key));
@@ -461,7 +456,19 @@
&fragment_store_result, (void *)
GNUNET_YES);
}
+
void
+membership_test_result (void *cls, int64_t result, const char *err_msg)
+{
+ op = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "membership_test:\t%d\n", result);
+ GNUNET_assert (GNUNET_OK == result);
+
+ fragment_store ();
+}
+
+
+void
membership_store_result (void *cls, int64_t result, const char *err_msg)
{
op = NULL;
@@ -469,7 +476,7 @@
GNUNET_assert (GNUNET_OK == result);
op = GNUNET_PSYCSTORE_membership_test (h, &channel_pub_key, &slave_pub_key,
- 4, 1,
+ INT64_MAX - 10, 2,
&membership_test_result, NULL);
}
@@ -502,7 +509,8 @@
GNUNET_CRYPTO_ecdsa_key_get_public (slave_key, &slave_pub_key);
op = GNUNET_PSYCSTORE_membership_store (h, &channel_pub_key, &slave_pub_key,
- GNUNET_YES, 4, 2, 1,
+ GNUNET_YES, INT64_MAX - 5,
+ INT64_MAX - 10, 2,
&membership_store_result, NULL);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r34060 - in gnunet/src: include psycstore,
gnunet <=