-more datacache integration work
[oweals/gnunet.git] / src / include / gnunet_psycstore_service.h
index 40d553b982736a5e74a4774e41ba81e94c991df0..2cb155f69cac4325a9e26ec5a46f1afc4d7e6781 100644 (file)
@@ -1,6 +1,6 @@
 /*
      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
@@ -45,6 +45,11 @@ extern "C"
  */
 #define GNUNET_PSYCSTORE_VERSION 0x00000000
 
+/**
+ * Membership test failed.
+ */
+#define GNUNET_PSYCSTORE_MEMBERSHIP_TEST_FAILED -2
+
 /**
  * Flags for stored messages.
  */
@@ -102,9 +107,10 @@ struct GNUNET_PSYCSTORE_OperationHandle;
 /**
  * Function called with the result of an asynchronous operation.
  *
- * @param result #GNUNET_SYSERR on error,
+ * @param result
  *        #GNUNET_YES on success or if the peer was a member,
- *        #GNUNET_NO if the peer was not a member
+ *        #GNUNET_NO if the peer was not a member,
+ *        #GNUNET_SYSERR on error,
  */
 typedef void
 (*GNUNET_PSYCSTORE_ResultCallback) (void *cls,
@@ -116,25 +122,34 @@ typedef void
  * Store join/leave events for a PSYC channel in order to be able to answer
  * membership test queries later.
  *
- * @param h Handle for the PSYCstore.
- * @param channel_key The channel where the event happened.
- * @param slave_key Public key of joining/leaving slave.
- * @param did_join #GNUNET_YES on join, #GNUNET_NO on part.
- * @param announced_at ID of the message that announced the membership change.
- * @param effective_since Message ID this membership change is in effect since.
+ * @param h
+ *        Handle for the PSYCstore.
+ * @param channel_key
+ *        The channel where the event happened.
+ * @param slave_key
+ *        Public key of joining/leaving slave.
+ * @param did_join
+ *        #GNUNET_YES on join, #GNUNET_NO on part.
+ * @param announced_at
+ *        ID of the message that announced the membership change.
+ * @param effective_since
+ *        Message ID this membership change is in effect since.
  *        For joins it is <= announced_at, for parts it is always 0.
- * @param group_generation In case of a part, the last group generation the
- *        slave has access to.  It has relevance when a larger message have
- *        fragments with different group generations.
- * @param rcb Callback to call with the result of the storage operation.
- * @param rcb_cls Closure for the callback.
+ * @param group_generation
+ *        In case of a part, the last group generation the slave has access to.
+ *        It has relevance when a larger message have fragments with different
+ *        group generations.
+ * @param rcb
+ *        Callback to call with the result of the storage operation.
+ * @param rcb_cls
+ *        Closure for the callback.
  *
  * @return Operation handle that can be used to cancel the operation.
  */
 struct GNUNET_PSYCSTORE_OperationHandle *
 GNUNET_PSYCSTORE_membership_store (struct GNUNET_PSYCSTORE_Handle *h,
                                    const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
-                                   const struct GNUNET_CRYPTO_EddsaPublicKey *slave_key,
+                                   const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
                                    int did_join,
                                    uint64_t announced_at,
                                    uint64_t effective_since,
@@ -151,22 +166,29 @@ GNUNET_PSYCSTORE_membership_store (struct GNUNET_PSYCSTORE_Handle *h,
  * is also used when handling join requests to determine whether the slave is
  * currently admitted to the channel.
  *
- * @param h Handle for the PSYCstore.
- * @param channel_key The channel we are interested in.
- * @param slave_key Public key of slave whose membership to check.
- * @param message_id Message ID for which to do the membership test.
- * @param group_generation Group generation of the fragment of the message to
- *        test.  It has relevance if the message consists of multiple fragments
- *        with different group generations.
- * @param rcb Callback to call with the test result.
- * @param rcb_cls Closure for the callback.
+ * @param h
+ *        Handle for the PSYCstore.
+ * @param channel_key
+ *        The channel we are interested in.
+ * @param slave_key
+ *        Public key of slave whose membership to check.
+ * @param message_id
+ *        Message ID for which to do the membership test.
+ * @param group_generation
+ *        Group generation of the fragment of the message to test.
+ *        It has relevance if the message consists of multiple fragments with
+ *        different group generations.
+ * @param rcb
+ *        Callback to call with the test result.
+ * @param rcb_cls
+ *        Closure for the callback.
  *
  * @return Operation handle that can be used to cancel the operation.
  */
 struct GNUNET_PSYCSTORE_OperationHandle *
 GNUNET_PSYCSTORE_membership_test (struct GNUNET_PSYCSTORE_Handle *h,
                                   const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
-                                  const struct GNUNET_CRYPTO_EddsaPublicKey *slave_key,
+                                  const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
                                   uint64_t message_id,
                                   uint64_t group_generation,
                                   GNUNET_PSYCSTORE_ResultCallback rcb,
@@ -178,7 +200,7 @@ GNUNET_PSYCSTORE_membership_test (struct GNUNET_PSYCSTORE_Handle *h,
  *
  * @param h Handle for the PSYCstore.
  * @param channel_key The channel the message belongs to.
- * @param message Message to store.
+ * @param msg Message to store.
  * @param psycstore_flags Flags indicating whether the PSYC message contains
  *        state modifiers.
  * @param rcb Callback to call with the result of the operation.
@@ -189,8 +211,8 @@ GNUNET_PSYCSTORE_membership_test (struct GNUNET_PSYCSTORE_Handle *h,
 struct GNUNET_PSYCSTORE_OperationHandle *
 GNUNET_PSYCSTORE_fragment_store (struct GNUNET_PSYCSTORE_Handle *h,
                                  const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
-                                 const struct GNUNET_MULTICAST_MessageHeader *message,
-                                 uint32_t psycstore_flags,
+                                 const struct GNUNET_MULTICAST_MessageHeader *msg,
+                                 enum GNUNET_PSYCSTORE_MessageFlags psycstore_flags,
                                  GNUNET_PSYCSTORE_ResultCallback rcb,
                                  void *rcb_cls);
 
@@ -214,68 +236,182 @@ typedef int
 
 
 /**
- * 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.
+ * Retrieve message fragments by fragment ID range.
+ *
+ * @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 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_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_fragment_get (struct GNUNET_PSYCSTORE_Handle *h,
                                const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
-                               uint64_t fragment_id,
-                               GNUNET_PSYCSTORE_FragmentCallback fcb,
-                               GNUNET_PSYCSTORE_ResultCallback rcb,
+                               const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
+                               uint64_t first_message_id,
+                               uint64_t last_message_id,
+                               GNUNET_PSYCSTORE_FragmentCallback fragment_cb,
+                               GNUNET_PSYCSTORE_ResultCallback result_cb,
                                void *cls);
 
 
 /**
- * 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 fragment.  If not NULL, a membership test is
+ *        performed first and the fragment is only returned if the slave has
+ *        access to it.
+ * @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.
+ * @param cls
+ *        Closure for the callbacks.
  *
- * @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.
+ * @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);
+
+
+/**
+ * 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.
+ *        Use 0 to get the latest message.
+ * @param last_message_id
+ *        Last consecutive message ID to retrieve.
+ *        Use 0 to get the latest message.
+ * @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,
-                              uint64_t message_id,
-                              GNUNET_PSYCSTORE_FragmentCallback fcb,
-                              GNUNET_PSYCSTORE_ResultCallback rcb,
+                              const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
+                              uint64_t first_message_id,
+                              uint64_t last_message_id,
+                              GNUNET_PSYCSTORE_FragmentCallback fragment_cb,
+                              GNUNET_PSYCSTORE_ResultCallback result_cb,
                               void *cls);
 
 
+/**
+ * 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 fragment_cb
+ *        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_latest (struct GNUNET_PSYCSTORE_Handle *h,
+                                     const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
+                                     const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
+                                     uint64_t message_limit,
+                                     GNUNET_PSYCSTORE_FragmentCallback fragment_cb,
+                                     GNUNET_PSYCSTORE_ResultCallback rcb,
+                                     void *cls);
+
+
 /**
  * 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 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_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,
-                                       GNUNET_PSYCSTORE_ResultCallback rcb,
+                                       GNUNET_PSYCSTORE_FragmentCallback fragment_cb,
+                                       GNUNET_PSYCSTORE_ResultCallback result_cb,
                                        void *cls);
 
 
@@ -315,7 +451,7 @@ typedef void
  * @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 callback.
+ * @param ccb_cls Closure for the @a ccb callback.
  *
  * @return Handle that can be used to cancel the operation.
  */
@@ -339,7 +475,7 @@ GNUNET_PSYCSTORE_counters_get (struct GNUNET_PSYCSTORE_Handle *h,
  * @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 callback.
+ * @param rcb_cls Closure for the @a rcb callback.
  *
  * @return Handle that can be used to cancel the operation.
  */