SET service: accurate results for symmetric mode
[oweals/gnunet.git] / src / include / gnunet_social_service.h
index 4864543fd7576820f7e77854f14224960a17e8b8..edb762a1ee5df6dd7e6fa983276763de8fd746a2 100644 (file)
@@ -38,6 +38,7 @@ extern "C"
 #include "gnunet_util_lib.h"
 #include "gnunet_env_lib.h"
 #include "gnunet_identity_service.h"
+#include "gnunet_namestore_service.h"
 #include "gnunet_psyc_service.h"
 
 
@@ -105,7 +106,7 @@ typedef void
 
 
 /**
- * Function called upon receiving a data fragment of a message.
+ * Function called upon receiving a modifier of a message.
  *
  * @param cls
  *        Closure.
@@ -115,8 +116,10 @@ typedef void
  *        Message part, as it arrived from the network.
  * @param oper
  *        Operation to perform.
+ *        0 in case of a modifier continuation.
  * @param name
  *        Name of the modifier.
+ *        NULL in case of a modifier continuation.
  * @param value
  *        Value of the modifier.
  * @param value_size
@@ -124,12 +127,13 @@ typedef void
  */
 typedef void
 (*GNUNET_SOCIAL_ModifierCallback) (void *cls,
-                                   const struct GNUNET_PSYC_MessageModifier *msg,
+                                   const struct GNUNET_MessageHeader *msg,
                                    uint64_t message_id,
                                    enum GNUNET_ENV_Operator oper,
                                    const char *name,
                                    const void *value,
-                                   uint16_t value_size);
+                                   uint16_t value_size,
+                                   uint16_t full_value_size);
 
 
 /**
@@ -185,6 +189,9 @@ typedef void
 /**
  * Create a try-and-slice instance.
  *
+ * A slicer processes incoming messages and notifies callbacks about matching
+ * methods or modifiers encountered.
+ *
  * @return A new try-and-slice construct.
  */
 struct GNUNET_SOCIAL_Slicer *
@@ -194,45 +201,107 @@ GNUNET_SOCIAL_slicer_create (void);
 /**
  * Add a method to the try-and-slice instance.
  *
- * A slicer processes messages and calls methods that match a message. A match
- * happens whenever the method name of a message starts with the method_name
- * parameter given here.
+ * The callbacks are called for messages with a matching @a method_name prefix.
  *
- * @param slicer The try-and-slice instance to extend.
- * @param method_name Name of the given method, use empty string for default.
- * @param method Method to invoke.
- * @param method_cls Closure for method.
+ * @param slicer
+ *        The try-and-slice instance to extend.
+ * @param method_name
+ *        Name of the given method, use empty string to match all.
+ * @param method_cb
+ *        Method handler invoked upon a matching message.
+ * @param modifier_cb
+ *        Modifier handler, invoked after @a method_cb
+ *        for each modifier in the message.
+ * @param data_cb
+ *        Data handler, invoked after @a modifier_cb for each data fragment.
+ * @param eom_cb
+ *        Invoked upon reaching the end of a matching message.
+ * @param cls
+ *        Closure for the callbacks.
  */
 void
-GNUNET_SOCIAL_slicer_add (struct GNUNET_SOCIAL_Slicer *slicer,
-                          const char *method_name,
-                          GNUNET_SOCIAL_MethodCallback method_cb,
-                          GNUNET_SOCIAL_ModifierCallback modifier_cb,
-                          GNUNET_SOCIAL_DataCallback data_cb,
-                          GNUNET_SOCIAL_EndOfMessageCallback eom_cb,
-                          void *cls);
+GNUNET_SOCIAL_slicer_method_add (struct GNUNET_SOCIAL_Slicer *slicer,
+                                 const char *method_name,
+                                 GNUNET_SOCIAL_MethodCallback method_cb,
+                                 GNUNET_SOCIAL_ModifierCallback modifier_cb,
+                                 GNUNET_SOCIAL_DataCallback data_cb,
+                                 GNUNET_SOCIAL_EndOfMessageCallback eom_cb,
+                                 void *cls);
+
+/**
+ * Remove a registered method from the try-and-slice instance.
+ *
+ * Removes one matching handler registered with the given
+ * @a method_name and callbacks.
+ *
+ * @param slicer
+ *        The try-and-slice instance.
+ * @param method_name
+ *        Name of the method to remove.
+ * @param method_cb
+ *        Method handler.
+ * @param modifier_cb
+ *        Modifier handler.
+ * @param data_cb
+ *        Data handler.
+ * @param eom_cb
+ *        End of message handler.
+ *
+ * @return #GNUNET_OK if a method handler was removed,
+ *         #GNUNET_NO if no handler matched the given method name and callbacks.
+ */
+int
+GNUNET_SOCIAL_slicer_method_remove (struct GNUNET_SOCIAL_Slicer *slicer,
+                                    const char *method_name,
+                                    GNUNET_SOCIAL_MethodCallback method_cb,
+                                    GNUNET_SOCIAL_ModifierCallback modifier_cb,
+                                    GNUNET_SOCIAL_DataCallback data_cb,
+                                    GNUNET_SOCIAL_EndOfMessageCallback eom_cb);
 
 
 /**
- * Remove a registered method handler from the try-and-slice instance.
+ * Watch a place for changed objects.
  *
- * @param slicer The try-and-slice instance.
- * @param method_name Name of the method to remove.
- * @param method Method handler.
+ * @param slicer
+ *        The try-and-slice instance.
+ * @param object_filter
+ *        Object prefix to match.
+ * @param modifier_cb
+ *        Function to call when encountering a state modifier.
+ * @param cls
+ *        Closure for callback.
+ */
+void
+GNUNET_SOCIAL_slicer_modifier_add (struct GNUNET_SOCIAL_Slicer *slicer,
+                                   const char *object_filter,
+                                   GNUNET_SOCIAL_ModifierCallback modifier_cb,
+                                   void *cls);
+
+
+/**
+ * Remove a registered modifier from the try-and-slice instance.
+ *
+ * Removes one matching handler registered with the given
+ * @a object_filter and callback.
+ *
+ * @param slicer
+ *        The try-and-slice instance.
+ * @param object_filter
+ *        Object prefix to match.
+ * @param modifier_cb
+ *        Function to call when encountering a state modifier changes.
  */
 int
-GNUNET_SOCIAL_slicer_remove (struct GNUNET_SOCIAL_Slicer *slicer,
-                             const char *method_name,
-                             GNUNET_SOCIAL_MethodCallback method_cb,
-                             GNUNET_SOCIAL_ModifierCallback modifier_cb,
-                             GNUNET_SOCIAL_DataCallback data_cb,
-                             GNUNET_SOCIAL_EndOfMessageCallback eom_cb);
+GNUNET_SOCIAL_slicer_modifier_remove (struct GNUNET_SOCIAL_Slicer *slicer,
+                                      const char *object_filter,
+                                      GNUNET_SOCIAL_ModifierCallback modifier_cb);
 
 
 /**
  * Destroy a given try-and-slice instance.
  *
- * @param slicer slicer to destroy
+ * @param slicer
+ *        Slicer to destroy
  */
 void
 GNUNET_SOCIAL_slicer_destroy (struct GNUNET_SOCIAL_Slicer *slicer);
@@ -271,17 +340,15 @@ typedef void
  * This is also called if the @a nym was never given permission to enter
  * (i.e. the @a nym stopped asking to get in).
  *
- * @param cls   Closure.
- * @param nym Handle for the user who left.
- * @param variable_count Number of elements in the @a variables array.
- * @param variables Variables present in the message.
+ * @param cls
+ *        Closure.
+ * @param nym
+ *        Handle for the user who left.
  */
 typedef void
 (*GNUNET_SOCIAL_FarewellCallback) (void *cls,
-                                   struct GNUNET_SOCIAL_Nym *nym,
-                                   struct GNUNET_ENV_Environment *env,
-                                   size_t variable_count,
-                                   struct GNUNET_ENV_Modifier *variables);
+                                   const struct GNUNET_SOCIAL_Nym *nym,
+                                   struct GNUNET_ENV_Environment *env);
 
 
 /**
@@ -375,12 +442,14 @@ GNUNET_SOCIAL_host_entry_decision (struct GNUNET_SOCIAL_Host *hst,
  * #GNUNET_SOCIAL_FarewellCallback is invoked,
  * which should be very soon after this call.
  *
- * @param host  Host of the place.
- * @param nym  Handle for the entity to be ejected.
+ * @param host
+ *        Host of the place.
+ * @param nym
+ *        Handle for the entity to be ejected.
  */
 void
 GNUNET_SOCIAL_host_eject (struct GNUNET_SOCIAL_Host *host,
-                          struct GNUNET_SOCIAL_Nym *nym);
+                          const struct GNUNET_SOCIAL_Nym *nym);
 
 
 /**
@@ -391,43 +460,55 @@ GNUNET_SOCIAL_host_eject (struct GNUNET_SOCIAL_Host *host,
  * @param nym
  *        Pseudonym to map to a cryptographic identifier.
  *
- * @return Public key of nym;
+ * @return Public key of nym.
  */
-struct GNUNET_CRYPTO_EcdsaPublicKey *
-GNUNET_SOCIAL_nym_get_key (struct GNUNET_SOCIAL_Nym *nym);
+const struct GNUNET_CRYPTO_EcdsaPublicKey *
+GNUNET_SOCIAL_nym_get_key (const struct GNUNET_SOCIAL_Nym *nym);
 
 
 /**
- * Obtain the private-public key pair of the host.
+ * Get the hash of the public key of a @a nym.
+ *
+ * @param nym
+ *        Pseudonym to map to a cryptographic identifier.
  *
- * @param host  Host to get the key of.
- * @param[out] host_key  Set to the private-public key pair of the host.  The
- *                 public part is suitable for storing in GNS within a "PLACE"
- *                 record, along with peer IDs to join at.
+ * @return Hash of the public key of nym.
  */
-void
-GNUNET_SOCIAL_host_get_key (struct GNUNET_SOCIAL_Host *host,
-                            struct GNUNET_CRYPTO_EddsaPrivateKey *host_key);
+const struct GNUNET_HashCode *
+GNUNET_SOCIAL_nym_get_key_hash (const struct GNUNET_SOCIAL_Nym *nym);
 
 
 /**
  * Advertise the place in the GNS zone of the @e ego of the @a host.
  *
- * @param host  Host of the place.
- * @param name The name for the PLACE record to put in the zone.
- * @param peer_count Number of elements in the @a peers array.
- * @param peers List of peers in the PLACE record that can be used to send join
- *        requests to.
- * @param expiration_time Expiration time of the record, use 0 to remove the record.
- * @param password Password used to encrypt the record.
+ * @param hst
+ *        Host of the place.
+ * @param name
+ *        The name for the PLACE record to put in the zone.
+ * @param peer_count
+ *        Number of elements in the @a peers array.
+ * @param peers
+ *        List of peers to put in the PLACE record to advertise
+ *        as entry points to the place in addition to the origin.
+ * @param expiration_time
+ *        Expiration time of the record, use 0 to remove the record.
+ * @param password
+ *        Password used to encrypt the record.
+ *        FIXME: not implemented yet.
+ * @param result_cb
+ *        Function called with the result of the operation.
+ * @param result_cls
+ *        Closure for @a result_cb
  */
 void
 GNUNET_SOCIAL_host_advertise (struct GNUNET_SOCIAL_Host *host,
                               const char *name,
-                              size_t peer_count,
+                              uint32_t peer_count,
                               const struct GNUNET_PeerIdentity *peers,
-                              struct GNUNET_TIME_Relative expiration_time,
-                              const char *password);
+                              struct GNUNET_TIME_Absolute expiration_time,
+                              const char *password,
+                              GNUNET_NAMESTORE_ContinuationWithStatus result_cb,
+                              void *result_cls);
 
 
 /**
@@ -622,27 +703,35 @@ GNUNET_SOCIAL_guest_enter (const struct GNUNET_CONFIGURATION_Handle *cfg,
 
 
 /**
- * Request entry to a place as a guest using a GNS name.
+ * Request entry to a place by name as a guest.
  *
- * @param cfg  Configuration to contact the social service.
- * @param ego  Identity of the guest.
- * @param address GNS name of the place to enter.  Either in the form of
+ * @param cfg
+ *        Configuration to contact the social service.
+ * @param ego
+ *        Identity of the guest.
+ * @param gns_name
+ *        GNS name of the place to enter.  Either in the form of
  *        'room.friend.gnu', or 'NYMPUBKEY.zkey'.  This latter case refers to
  *        the 'PLACE' record of the empty label ("+") in the GNS zone with the
  *        nym's public key 'NYMPUBKEY', and can be used to request entry to a
  *        pseudonym's place directly.
- * @param method_name Method name for the message.
- * @param env Environment containing variables for the message, or NULL.
- * @param data Payload for the message to give to the enter callback.
- * @param data_size Number of bytes in @a data.
- * @param slicer Slicer to use for processing incoming requests from guests.
+ * @param password
+ *        Password to decrypt the record, or NULL for cleartext records.
+ * @param join_msg
+ *        Entry request message.
+ * @param slicer
+ *        Slicer to use for processing incoming requests from guests.
+ * @param local_enter_cb
+ *        Called upon connection established to the social service.
+ * @param entry_decision_cb
+ *        Called upon receiving entry decision.
  *
  * @return NULL on errors, otherwise handle for the guest.
  */
 struct GNUNET_SOCIAL_Guest *
 GNUNET_SOCIAL_guest_enter_by_name (const struct GNUNET_CONFIGURATION_Handle *cfg,
-                                   struct GNUNET_IDENTITY_Ego *ego,
-                                   char *gns_name,
+                                   const struct GNUNET_IDENTITY_Ego *ego,
+                                   const char *gns_name, const char *password,
                                    const struct GNUNET_PSYC_Message *join_msg,
                                    struct GNUNET_SOCIAL_Slicer *slicer,
                                    GNUNET_SOCIAL_GuestEnterCallback local_enter_cb,
@@ -714,23 +803,25 @@ GNUNET_SOCIAL_guest_talk_cancel (struct GNUNET_SOCIAL_TalkRequest *tr);
 
 
 /**
- * Leave a place permanently.
+ * Leave a place temporarily or permanently.
  *
  * Notifies the owner of the place about leaving, and destroys the place handle.
  *
  * @param place
- *        Place to leave permanently.
+ *        Place to leave.
  * @param keep_active
  *        Keep place active after last application disconnected.
+ *        #GNUNET_YES or #GNUNET_NO
+ * @param env
+ *        Optional environment for the leave message if @a keep_active
+ *        is #GNUNET_NO.  NULL if not needed.
  * @param leave_cb
- *        Function called after the guest left the place
- *        and disconnected from the social service.
- * @param leave_cls
- *        Closure for @a leave_cb.
+ *        Called upon disconnecting from the social service.
  */
 void
-GNUNET_SOCIAL_guest_leave (struct GNUNET_SOCIAL_Guest *guest,
+GNUNET_SOCIAL_guest_leave (struct GNUNET_SOCIAL_Guest *gst,
                            int keep_active,
+                           struct GNUNET_ENV_Environment *env,
                            GNUNET_ContinuationCallback leave_cb,
                            void *leave_cls);
 
@@ -826,38 +917,6 @@ void
 GNUNET_SOCIAL_place_history_replay_cancel (struct GNUNET_SOCIAL_HistoryRequest *hist);
 
 
-struct GNUNET_SOCIAL_WatchHandle;
-
-/**
- * Watch a place for changed objects.
- *
- * @param place
- *        Place to watch.
- * @param object_filter
- *        Object prefix to match.
- * @param var_cb
- *        Function to call when an object/state var changes.
- * @param cls
- *        Closure for callback.
- *
- * @return Handle that can be used to cancel watching.
- */
-struct GNUNET_SOCIAL_WatchHandle *
-GNUNET_SOCIAL_place_watch (struct GNUNET_SOCIAL_Place *place,
-                           const char *object_filter,
-                           GNUNET_PSYC_StateVarCallback var_cb,
-                           void *cls);
-
-
-/**
- * Cancel watching a place for changed objects.
- *
- * @param wh Watch handle to cancel.
- */
-void
-GNUNET_SOCIAL_place_watch_cancel (struct GNUNET_SOCIAL_WatchHandle *wh);
-
-
 struct GNUNET_SOCIAL_LookHandle;
 
 
@@ -914,6 +973,34 @@ void
 GNUNET_SOCIAL_place_look_cancel (struct GNUNET_SOCIAL_LookHandle *lh);
 
 
+/**
+ * Add public key to the GNS zone of the @e ego.
+ *
+ * @param cfg
+ *        Configuration.
+ * @param ego
+ *        Ego.
+ * @param name
+ *        The name for the PKEY record to put in the zone.
+ * @param pub_key
+ *        Public key to add.
+ * @param expiration_time
+ *        Expiration time of the record, use 0 to remove the record.
+ * @param result_cb
+ *        Function called with the result of the operation.
+ * @param result_cls
+ *        Closure for @a result_cb
+ */
+void
+GNUNET_SOCIAL_zone_add_pkey (const struct GNUNET_CONFIGURATION_Handle *cfg,
+                             const struct GNUNET_IDENTITY_Ego *ego,
+                             const char *name,
+                             const struct GNUNET_CRYPTO_EcdsaPublicKey *pub_key,
+                             struct GNUNET_TIME_Absolute expiration_time,
+                             GNUNET_NAMESTORE_ContinuationWithStatus result_cb,
+                             void *result_cls);
+
+
 #if 0                           /* keep Emacsens' auto-indent happy */
 {
 #endif