client_manager: add API for async operations
[oweals/gnunet.git] / src / include / gnunet_social_service.h
index 3aaea333eabb96da0fb6e34f7b5a5e7aa6da83b9..fcfc8a359bfc41b81da93d893362a8a10132053a 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
@@ -20,8 +20,8 @@
 
 /**
  * @file include/gnunet_social_service.h
- * @brief Social service; implements social functionality using the PSYC service
- * @author tg
+ * @brief Social service; implements social interactions using the PSYC service.
+ * @author Gabor X Toth
  * @author Christian Grothoff
  */
 #ifndef GNUNET_SOCIAL_SERVICE_H
@@ -36,8 +36,9 @@ extern "C"
 #endif
 
 #include "gnunet_util_lib.h"
+#include "gnunet_env_lib.h"
+#include "gnunet_identity_service.h"
 #include "gnunet_psyc_service.h"
-#include "gnunet_multicast_service.h"
 
 
 /**
@@ -47,25 +48,24 @@ extern "C"
 
 
 /**
- * Handle for a place where social interactions happen.
+ * Handle for a pseudonym of another user in the network.
  */
-struct GNUNET_SOCIAL_Place;
+struct GNUNET_SOCIAL_Nym;
 
 /**
- * Handle for a place that one of our egos hosts.
+ * Handle for a place where social interactions happen.
  */
-struct GNUNET_SOCIAL_Home;
+struct GNUNET_SOCIAL_Place;
 
 /**
- * Handle for our own presence in the network (we can of course have
- * alter-egos).
+ * Host handle for a place that we entered.
  */
-struct GNUNET_SOCIAL_Ego;
+struct GNUNET_SOCIAL_Host;
 
 /**
- * Handle for another user (who is likely pseudonymous) in the network.
+ * Guest handle for place that we entered.
  */
-struct GNUNET_SOCIAL_Nym;
+struct GNUNET_SOCIAL_Guest;
 
 /**
  * Handle to an implementation of try-and-slice.
@@ -74,34 +74,118 @@ struct GNUNET_SOCIAL_Slicer;
 
 
 /**
- * Method called from SOCIAL upon receiving a message indicating a call
- * to a 'method'.  
- *
- * @param cls closure
- * @param full_method_name original method name from PSYC (may be more
- *        specific than the registered method name due to try-and-slice matching)
- * @param message_id unique message counter for this message;
- *                   (unique only in combination with the given sender for
- *                    this channel)
- * @param data_off byte offset of 'data' in the overall data of the method
- * @param data_size number of bytes in 'data'; 
- * @param data data stream given to the method (might not be zero-terminated 
- *             if data is binary)
- * @param frag fragmentation status for the data
- */
-typedef int (*GNUNET_SOCIAL_Method)(void *cls,
-                                   const char *full_method_name,
-                                   uint64_t message_id,
-                                   uint64_t data_off,
-                                   size_t data_size,
-                                   const void *data,
-                                   enum GNUNET_PSYC_FragmentStatus frag);
+ * Function called upon receiving a message indicating a call to a @e method.
+ *
+ * This function is called one or more times for each message until all data
+ * fragments arrive from the network.
+ *
+ * @param cls
+ *        Closure.
+ * @param msg
+ *        Message part, as it arrived from the network.
+ * @param message_id
+ *        Message counter, monotonically increasing from 1.
+ * @param nym
+ *        The sender of the message.
+ *        Can be NULL if the message is not connected to a pseudonym.
+ * @param flags
+ *        OR'ed GNUNET_PSYC_MessageFlags
+ * @param method_name
+ *        Original method name from PSYC.
+ *        May be more specific than the registered method name due to
+ *        try-and-slice matching.
+ */
+typedef void
+(*GNUNET_SOCIAL_MethodCallback) (void *cls,
+                                 const struct GNUNET_PSYC_MessageMethod *msg,
+                                 uint64_t message_id,
+                                 uint32_t flags,
+                                 const struct GNUNET_SOCIAL_Nym *nym,
+                                 const char *method_name);
+
+
+/**
+ * Function called upon receiving a data fragment of a message.
+ *
+ * @param cls
+ *        Closure.
+ * @param message_id
+ *        Message ID this data fragment belongs to.
+ * @param msg
+ *        Message part, as it arrived from the network.
+ * @param oper
+ *        Operation to perform.
+ * @param name
+ *        Name of the modifier.
+ * @param value
+ *        Value of the modifier.
+ * @param value_size
+ *        Size of @value.
+ */
+typedef void
+(*GNUNET_SOCIAL_ModifierCallback) (void *cls,
+                                   const struct GNUNET_PSYC_MessageModifier *msg,
+                                   uint64_t message_id,
+                                   enum GNUNET_ENV_Operator oper,
+                                   const char *name,
+                                   const void *value,
+                                   uint16_t value_size);
+
+
+/**
+ * Function called upon receiving a data fragment of a message.
+ *
+ * @param cls
+ *        Closure.
+ * @param message_id
+ *        Message ID this data fragment belongs to.
+ * @param msg
+ *        Message part, as it arrived from the network.
+ * @param data_offset
+ *        Byte offset of @a data in the overall data of the method.
+ * @param data_size
+ *        Number of bytes in @a data.
+ * @param data
+ *        Data stream given to the method.
+ * @param end
+ *        End of message?
+ *        #GNUNET_NO     if there are further fragments,
+ *        #GNUNET_YES    if this is the last fragment,
+ *        #GNUNET_SYSERR indicates the message was cancelled by the sender.
+ */
+typedef void
+(*GNUNET_SOCIAL_DataCallback) (void *cls,
+                               const struct GNUNET_MessageHeader *msg,
+                               uint64_t message_id,
+                               uint64_t data_offset,
+                               const void *data,
+                               uint16_t data_size);
+
+
+/**
+ * End of message.
+ *
+ * @param cls
+ *        Closure.
+ * @param msg
+ *        Message part, as it arrived from the network.
+ * @param message_id
+ *        Message ID this data fragment belongs to.
+ * @param cancelled.
+ *        #GNUNET_YES if the message was cancelled,
+ *        #GNUNET_NO  if the message is complete.
+ */
+typedef void
+(*GNUNET_SOCIAL_EndOfMessageCallback) (void *cls,
+                                       const struct GNUNET_MessageHeader *msg,
+                                       uint64_t message_id,
+                                       uint8_t cancelled);
 
 
 /**
  * Create a try-and-slice instance.
  *
- * @return try-and-slice construct
+ * @return A new try-and-slice construct.
  */
 struct GNUNET_SOCIAL_Slicer *
 GNUNET_SOCIAL_slicer_create (void);
@@ -110,183 +194,257 @@ GNUNET_SOCIAL_slicer_create (void);
 /**
  * Add a method to the try-and-slice instance.
  *
- * @param slicer 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
- */
-void
-GNUNET_SOCIAL_slicer_add (struct GNUNET_SOCIAL_Slicer *slicer,
-                         const char *method_name,
-                         GNUNET_SOCIAL_Method method,
-                         void *method_cls);
-
-
-/**
- * Destroy a given 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.
  *
- * @param slicer slicer to destroy
+ * @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.
  */
 void
-GNUNET_SOCIAL_slicer_destroy (struct GNUNET_SOCIAL_Slicer *slicer);
+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);
 
 
 /**
- * Create an ego using the private key from the given
- * file.  If the file does not exist, a fresh key is
- * created.
+ * Remove a registered method handler from the try-and-slice instance.
  *
- * @param keyfile name of the file with the private key for the ego,
- *                NULL for ephemeral egos
- * @return handle to the ego, NULL on error
+ * @param slicer The try-and-slice instance.
+ * @param method_name Name of the method to remove.
+ * @param method Method handler.
  */
-struct GNUNET_SOCIAL_Ego *
-GNUNET_SOCIAL_ego_create (const char *keyfile);
+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);
 
 
 /**
- * Destroy a handle to an ego.
+ * Destroy a given try-and-slice instance.
  *
- * @param ego ego to destroy
+ * @param slicer slicer to destroy
  */
 void
-GNUNET_SOCIAL_ego_destroy (struct GNUNET_SOCIAL_Ego *ego);
+GNUNET_SOCIAL_slicer_destroy (struct GNUNET_SOCIAL_Slicer *slicer);
 
 
 /**
- * Function called asking for nym to be admitted to the room.  Should
- * call either 'GNUNET_SOCIAL_home_admit' or
- * 'GNUNET_SOCIAL_home_reject_entry' (possibly asynchronously).  The
- * 'nym' reference remains valid until the
- * 'GNUNET_SOCIAL_FarewellCallback' is invoked for it.
+ * Function called asking for nym to be admitted to the place.
  *
- * @param cls closure
- * @param nym handle for the user who wants to join
- * @param join_msg_size number of bytes in 'join_msg'
- * @param join_msg payload given on join
- */
-typedef void (*GNUNET_SOCIAL_AnswerDoorCallback)(void *cls,
-                                                struct GNUNET_SOCIAL_Nym *nym,
-                                                size_t join_msg_size,
-                                                const void *join_msg);
-
-
-/**
- * Function called when a 'nym' leaves the room.  This is
- * also called if the 'nym' was never given permission to
- * enter (i.e. the 'nym' stopped asking to get in).
+ * Should call either GNUNET_SOCIAL_host_admit() or
+ * GNUNET_SOCIAL_host_reject_entry() (possibly asynchronously).  If this host
+ * cannot decide, it is fine to call neither function, in which case hopefully
+ * some other host of the place exists that will make the decision.  The @a nym
+ * reference remains valid until the #GNUNET_SOCIAL_FarewellCallback is invoked
+ * for it.
  *
- * @param cls closure
- * @param nym handle for the user who left
- */
-typedef void (*GNUNET_SOCIAL_FarewellCallback)(void *cls,
-                                              struct GNUNET_SOCIAL_Nym *nym);
+ * @param cls Closure.
+ * @param nym Handle for the user who wants to enter.
+ * @param method_name Method name in the entry request.
+ * @param variable_count Number of elements in the @a variables array.
+ * @param variables Variables present in the message.
+ * @param data_size Number of bytes in @a data.
+ * @param data Payload given on enter (e.g. a password).
+ */
+typedef void
+(*GNUNET_SOCIAL_AnswerDoorCallback) (void *cls,
+                                     struct GNUNET_SOCIAL_Nym *nym,
+                                     const char *method_name,
+                                     struct GNUNET_ENV_Environment *env,
+                                     size_t data_size,
+                                     const void *data);
+
+
+/**
+ * Function called when a @a nym leaves the place.
+ *
+ * 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.
+ */
+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);
 
 
 /**
- * Create a new home to host guests (nyms).
+ * Function called after the host entered the place.
  *
- * @param cfg configuration to contact the social service
- * @param home_keyfile file with the private key for the home, 
- *              created if the file does not exist; 
- *              pass NULL for ephemeral homes
- * @param join_policy what is our policy for allowing people in?
- * @param ego owner of the home (host)
- * @param slicer slicer to handle guests talking
- * @param listener_cb function to handle new nyms that want to join
- * @param farewell_cb function to handle departing nyms
- * @param cls closure for 'listener_cb' and 'farewell_cb'
- * @return handle for a new home
+ * @param cls
+ *        Closure.
+ * @param result
+ *        #GNUNET_OK on success, or
+ *        #GNUNET_SYSERR on error.
+ * @param max_message_id
+ *        Last message ID sent to the channel.
+ *        Or 0 if no messages have been sent to the place yet.
  */
-struct GNUNET_SOCIAL_Home *
-GNUNET_SOCIAL_home_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
-                          const char *home_keyfile,
-                          enum GNUNET_MULTICAST_JoinPolicy join_policy,
-                          struct GNUNET_SOCIAL_Ego *ego,
-                          struct GNUNET_SOCIAL_Slicer *slicer,
-                          GNUNET_SOCIAL_AnswerDoorCallback listener_cb,
-                          GNUNET_SOCIAL_FarewellCallback farewell_cb,
-                          void *cls);
+typedef void
+(*GNUNET_SOCIAL_HostEnterCallback) (void *cls, int result,
+                                    uint64_t max_message_id);
 
 
 /**
- * Admit 'nym' to the 'home'.  'nym' will remain valid until either
- * the home is destroyed or 'nym' leaves.
+ * Enter a place as host.
+ *
+ * A place is created upon first entering, and it is active until permanently
+ * left using GNUNET_SOCIAL_host_leave().
  *
- * @param home home to allow 'nym' to join
- * @param nym handle for the entity that wants to join
+ * @param cfg
+ *        Configuration to contact the social service.
+ * @param ego
+ *        Identity of the host.
+ * @param place_key
+ *        Private-public key pair of the place.
+ *        NULL for ephemeral places.
+ * @param policy
+ *        Policy specifying entry and history restrictions for the place.
+ * @param slicer
+ *        Slicer to handle incoming messages.
+ * @param answer_door_cb
+ *        Function to handle new nyms that want to enter.
+ * @param farewell_cb
+ *        Function to handle departing nyms.
+ * @param cls
+ *        Closure for the callbacks.
+ *
+ * @return Handle for the host.
+ */
+struct GNUNET_SOCIAL_Host *
+GNUNET_SOCIAL_host_enter (const struct GNUNET_CONFIGURATION_Handle *cfg,
+                          const struct GNUNET_IDENTITY_Ego *ego,
+                          const struct GNUNET_CRYPTO_EddsaPrivateKey *place_key,
+                          enum GNUNET_PSYC_Policy policy,
+                          struct GNUNET_SOCIAL_Slicer *slicer,
+                          GNUNET_SOCIAL_HostEnterCallback enter_cb,
+                          GNUNET_SOCIAL_AnswerDoorCallback answer_door_cb,
+                          GNUNET_SOCIAL_FarewellCallback farewell_cb,
+                          void *cls);
+
+
+/**
+ * Decision whether to admit @a nym into the place or refuse entry.
+ *
+ * @param hst
+ *        Host of the place.
+ * @param nym
+ *        Handle for the entity that wanted to enter.
+ * @param is_admitted
+ *        #GNUNET_YES    if @a nym is admitted,
+ *        #GNUNET_NO     if @a nym is refused entry,
+ *        #GNUNET_SYSERR if we cannot answer the request.
+ * @param method_name
+ *        Method name for the rejection message.
+ * @param env
+ *        Environment containing variables for the message, or NULL.
+ * @param data
+ *        Data for the rejection message to send back.
+ * @param data_size
+ *        Number of bytes in @a data for method.
+ * @return #GNUNET_OK on success,
+ *         #GNUNET_SYSERR if the message is too large.
+ */
+int
+GNUNET_SOCIAL_host_entry_decision (struct GNUNET_SOCIAL_Host *hst,
+                                   struct GNUNET_SOCIAL_Nym *nym,
+                                   int is_admitted,
+                                   const struct GNUNET_PSYC_Message *entry_resp);
+
+
+/**
+ * Throw @a nym out of the place.
+ *
+ * The @a nym reference will remain valid until the
+ * #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.
  */
 void
-GNUNET_SOCIAL_home_admit (struct GNUNET_SOCIAL_Home *home,
-                         struct GNUNET_SOCIAL_Nym *nym);
+GNUNET_SOCIAL_host_eject (struct GNUNET_SOCIAL_Host *host,
+                          struct GNUNET_SOCIAL_Nym *nym);
 
 
 /**
- * Throw 'nym' out of the 'home'.  'nym' will remain valid
- * until the 'GNUNET_SOCIAL_FarewellCallback' is invoked, which
- * should be very soon after this call.
+ * Get the public key of a @a nym.
  *
- * @param home home to allow 'nym' to join
- * @param nym handle for the entity that wants to join
+ * Suitable, for example, to be used with GNUNET_NAMESTORE_zone_to_name().
+ *
+ * @param nym
+ *        Pseudonym to map to a cryptographic identifier.
+ *
+ * @return Public key of nym;
  */
-void
-GNUNET_SOCIAL_home_evict (struct GNUNET_SOCIAL_Home *home,
-                         struct GNUNET_SOCIAL_Nym *nym);
+struct GNUNET_CRYPTO_EcdsaPublicKey *
+GNUNET_SOCIAL_nym_get_key (struct GNUNET_SOCIAL_Nym *nym);
 
 
 /**
- * Refuse 'nym' entry into the 'home'.
+ * Obtain the private-public key pair of the host.
  *
- * @param home home to disallow 'nym' to join
- * @param nym handle for the entity that wanted to join
+ * @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.
  */
 void
-GNUNET_SOCIAL_home_reject_entry (struct GNUNET_SOCIAL_Home *home,
-                                struct GNUNET_SOCIAL_Nym *nym);
+GNUNET_SOCIAL_host_get_key (struct GNUNET_SOCIAL_Host *host,
+                            struct GNUNET_CRYPTO_EddsaPrivateKey *host_key);
 
 
 /**
- * Get the identity of a user (suitable, for example, to be used
- * with 'GNUNET_NAMESTORE_zone_to_name').
+ * Advertise the place in the GNS zone of the @e ego of the @a host.
  *
- * @param nym pseydonym to map to a cryptographic identifier
- * @param identity set to the identity of the nym (short hash of the public key)
+ * @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.
  */
 void
-GNUNET_SOCIAL_nym_get_identity (struct GNUNET_SOCIAL_Nym *nym,
-                               struct GNUNET_CRYPTO_ShortHashCode *identity);
+GNUNET_SOCIAL_host_advertise (struct GNUNET_SOCIAL_Host *host,
+                              const char *name,
+                              size_t peer_count,
+                              const struct GNUNET_PeerIdentity *peers,
+                              struct GNUNET_TIME_Relative expiration_time,
+                              const char *password);
 
 
 /**
- * Obtain the (cryptographic, binary) address for the home.
- * 
- * @param home home to get the (public) address from
- * @param crypto_address address suitable for storing in GADS,
- *        i.e. in 'HEX.place' or within the respective GADS record type ("PLACE")
+ * Flags for announcements by a host.
  */
-void
-GNUNET_SOCIAL_home_get_address (struct GNUNET_SOCIAL_Home *home,
-                               struct GNUNET_HashCode *crypto_address);
-
+enum GNUNET_SOCIAL_AnnounceFlags
+{
+  GNUNET_SOCIAL_ANNOUNCE_NONE = 0,
 
-/**
- * (re)decorate the home by changing objects in it.  If
- * the operation is 'GNUNET_PSYC_SOT_SET_VARIABLE' then
- * the decoration only applies to the next announcement
- * by the home owner.
- *
- * @param home the home to decorate
- * @param operation operation to perform on the object
- * @param object_name name of the object to modify
- * @param object_value_size size of the given 'object_value'
- * @param object_value value to use for the modification
- */
-void
-GNUNET_SOCIAL_home_decorate (struct GNUNET_SOCIAL_Home *home,
-                            enum GNUNET_PSYC_Operator operation,
-                            const char *object_name,
-                            size_t object_value_size,
-                            const void *object_value);
+  /**
+   * Whether this announcement removes all objects from the place.
+   *
+   * New objects can be still added to the now empty place using the @e env
+   * parameter of the same announcement.
+   */
+  GNUNET_SOCIAL_ANNOUNCE_CLEAR_OBJECTS = 1 << 0
+};
 
 
 /**
@@ -296,244 +454,427 @@ struct GNUNET_SOCIAL_Announcement;
 
 
 /**
- * This function allows the home owner to send a message to all
- * nyms that are present in the home.
+ * Send a message to all nyms that are present in the place.
+ *
+ * This function is restricted to the host.  Nyms can only send requests
+ * to the host who can decide to relay it to everyone in the place.
+ *
+ * @param host
+ *        Host of the place.
+ * @param method_name
+ *        Method to use for the announcement.
+ * @param env
+ *        Environment containing variables for the message and operations
+ *        on objects of the place.
+ *        Has to remain available until the first call to @a notify_data.
+ *        Can be NULL.
+ * @param notify_data
+ *        Function to call to get the payload of the announcement.
+ * @param notify_data_cls
+ *        Closure for @a notify.
+ * @param flags
+ *        Flags for this announcement.
  *
- * @param home home to address the announcement to
- * @param full_method_name method to use for the announcement
- * @param notify function to call to get the payload of the announcement
- * @param notify_cls closure for 'notify'
- * @return NULL on error (announcement already in progress?)
+ * @return NULL on error (another announcement already in progress?).
  */
 struct GNUNET_SOCIAL_Announcement *
-GNUNET_SOCIAL_place_announce (struct GNUNET_SOCIAL_Home *home,
-                             const char *full_method_name,
-                             GNUNET_PSYC_OriginReadyNotify notify,
-                             void *notify_cls);
+GNUNET_SOCIAL_host_announce (struct GNUNET_SOCIAL_Host *host,
+                             const char *method_name,
+                             const struct GNUNET_ENV_Environment *env,
+                             GNUNET_PSYC_TransmitNotifyData notify_data,
+                             void *notify_data_cls,
+                             enum GNUNET_SOCIAL_AnnounceFlags flags);
 
 
 /**
- * Cancel announcement.
+ * Resume transmitting announcement.
  *
- * @param a the announcement to cancel
+ * @param a
+ *        The announcement to resume.
  */
 void
-GNUNET_SOCIAL_place_announce_cancel (struct GNUNET_SOCIAL_Announcement *a);
+GNUNET_SOCIAL_host_announce_resume (struct GNUNET_SOCIAL_Announcement *a);
 
 
 /**
- * Convert our home to a place so we can access it via the place API.
+ * Cancel announcement.
  *
- * @param home handle for the home
- * @return place handle for the same home, valid as long as 'home' is valid;
- *         do NOT try to 'GNUNET_SOCIAL_place_leave' this place, it's your home!
+ * @param a
+ *        The announcement to cancel.
  */
-struct GNUNET_SOCIAL_Place *
-GNUNET_SOCIAL_home_to_place (struct GNUNET_SOCIAL_Home *home);
+void
+GNUNET_SOCIAL_host_announce_cancel (struct GNUNET_SOCIAL_Announcement *a);
 
 
 /**
- * Leave a home, visitors can stay.
+ * Obtain handle for a hosted place.
  *
- * @param home home to leave (handle becomes invalid).
+ * The returned handle can be used to access the place API.
+ *
+ * @param host
+ *        Handle for the host.
+ *
+ * @return Handle for the hosted place, valid as long as @a host is valid.
  */
-void
-GNUNET_SOCIAL_home_leave (struct GNUNET_SOCIAL_Home *home);
+struct GNUNET_SOCIAL_Place *
+GNUNET_SOCIAL_host_get_place (struct GNUNET_SOCIAL_Host *host);
 
 
 /**
- * Destroy a home, all guests will be evicted.
+ * Stop hosting a place.
  *
- * @param home home to destroy
+ * Invalidates host handle.
+ *
+ * @param host
+ *        Host leaving the place.
+ * @param keep_active
+ *        Keep the place active after last host disconnected.
+ * @param leave_cb
+ *        Function called after the host left the place
+ *        and disconnected from the social service.
+ * @param leave_cls
+ *        Closure for @a leave_cb.
  */
 void
-GNUNET_SOCIAL_home_destroy (struct GNUNET_SOCIAL_Home *home);
+GNUNET_SOCIAL_host_leave (struct GNUNET_SOCIAL_Host *host,
+                          int keep_active,
+                          GNUNET_ContinuationCallback leave_cb,
+                          void *leave_cls);
+
+
+/**
+ * Function called after the guest entered the local copy of the place.
+ *
+ * History and object query functions can be used after this call,
+ * but new messages can't be sent or received.
+ *
+ * @param cls
+ *        Closure.
+ * @param result
+ *        #GNUNET_OK on success, or
+ *        #GNUNET_SYSERR on error, e.g. could not connect to the service, or
+ *        could not resolve GNS name.
+ * @param max_message_id
+ *        Last message ID sent to the place.
+ *        Or 0 if no messages have been sent to the place yet.
+ */
+typedef void
+(*GNUNET_SOCIAL_GuestEnterCallback) (void *cls, int result,
+                                     uint64_t max_message_id);
+
+
+/**
+ * Function called upon a guest receives a decision about entry to the place.
+ *
+ * @param is_admitted
+ *   Is the guest admitted to the place?
+ *   #GNUNET_YES    if admitted,
+ *   #GNUNET_NO     if refused entry
+ *   #GNUNET_SYSERR if the request could not be answered.
+ * @param method_name
+ *   Method for the message sent along with the decision.
+ *   NULL if no message was sent.
+ * @param env
+ *   Environment with variables for the message.
+ *   NULL if there are no variables.
+ *   It has to be freed using GNUNET_ENV_environment_destroy()
+ *   when it is not needed anymore.
+ * @param data_size
+ *   Size of @data.
+ * @param data
+ *   Payload of the message.
+ */
+typedef void
+(*GNUNET_SOCIAL_EntryDecisionCallback) (void *cls,
+                                        int is_admitted,
+                                        const struct GNUNET_PSYC_Message *entry_resp);
+
+
+/**
+ * Request entry to a place as a guest.
+ *
+ * @param cfg Configuration to contact the social service.
+ * @param ego  Identity of the guest.
+ * @param crypto_address Public key of the place to enter.
+ * @param origin Peer identity of the origin of the underlying multicast group.
+ * @param relay_count Number of elements in the @a relays array.
+ * @param relays Relays for the underlying multicast group.
+ * @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.
+ *
+ * @return NULL on errors, otherwise handle for the guest.
+ */
+struct GNUNET_SOCIAL_Guest *
+GNUNET_SOCIAL_guest_enter (const struct GNUNET_CONFIGURATION_Handle *cfg,
+                           const struct GNUNET_IDENTITY_Ego *ego,
+                           const struct GNUNET_CRYPTO_EddsaPublicKey *place_key,
+                           const struct GNUNET_PeerIdentity *origin,
+                           uint32_t relay_count,
+                           const struct GNUNET_PeerIdentity *relays,
+                           const struct GNUNET_PSYC_Message *entry_msg,
+                           struct GNUNET_SOCIAL_Slicer *slicer,
+                           GNUNET_SOCIAL_GuestEnterCallback local_enter_cb,
+                           GNUNET_SOCIAL_EntryDecisionCallback entry_decision_cb,
+                           void *cls);
+
+
+/**
+ * Request entry to a place as a guest using a GNS name.
+ *
+ * @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
+ *        '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.
+ *
+ * @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_PSYC_Message *join_msg,
+                                   struct GNUNET_SOCIAL_Slicer *slicer,
+                                   GNUNET_SOCIAL_GuestEnterCallback local_enter_cb,
+                                   GNUNET_SOCIAL_EntryDecisionCallback entry_decision_cb,
+                                   void *cls);
+
+
+/**
+ * Flags for talking to the host of a place.
+ */
+enum GNUNET_SOCIAL_TalkFlags
+{
+  GNUNET_SOCIAL_TALK_NONE = 0
+};
 
 
 /**
- * Join a place (home hosted by someone else).
- *
- * @param cfg configuration to contact the social service
- * @param ego owner of the home (host)
- * @param address address of the place to join (GADS name, i.e. 'room.friend.gads'),
- *        if the name has the form 'HEX.place', GADS is not
- *        used and HEX is assumed to be the hash of the public
- *        key already; 'HEX.zkey' however would refer to
- *        the 'PLACE' record in the GADS zone with the public key
- *        'HEX'.
- * @param join_msg_size number of bytes in 'join_msg'
- * @param join_msg message to give to the join callback
- * @return NULL on errors, otherwise handle to the place
+ * A talk request.
  */
-struct GNUNET_SOCIAL_Place *
-GNUNET_SOCIAL_place_join (const struct GNUNET_CONFIGURATION_Handle *cfg,
-                         struct GNUNET_SOCIAL_Ego *ego,
-                         const char *address,
-                         struct GNUNET_SOCIAL_Slicer *slicer,
-                         size_t join_msg_size,
-                         const void *join_msg);
+struct GNUNET_SOCIAL_TalkRequest;
 
 
 /**
+ * Talk to the host of the place.
  *
- */
-struct GNUNET_SOCIAL_WatchHandle;
-
-/**
- * 
+ * @param place
+ *        Place where we want to talk to the host.
+ * @param method_name
+ *        Method to invoke on the host.
+ * @param env
+ *        Environment containing variables for the message, or NULL.
+ * @param notify_data
+ *        Function to use to get the payload for the method.
+ * @param notify_data_cls
+ *        Closure for @a notify_data.
+ * @param flags
+ *        Flags for the message being sent.
  *
- * @param
- * @param
- * @param
- * @param
+ * @return NULL if we are already trying to talk to the host,
+ *         otherwise handle to cancel the request.
  */
-struct GNUNET_SOCIAL_WatchHandle *
-GNUNET_SOCIAL_place_watch (struct GNUNET_SOCIAL_Place *place,
-                          const char *object_filter,
-                          GNUNET_PSYC_StateCallback state_cb,
-                          void *state_cb_cls);
+struct GNUNET_SOCIAL_TalkRequest *
+GNUNET_SOCIAL_guest_talk (struct GNUNET_SOCIAL_Guest *guest,
+                          const char *method_name,
+                          const struct GNUNET_ENV_Environment *env,
+                          GNUNET_PSYC_TransmitNotifyData notify_data,
+                          void *notify_data_cls,
+                          enum GNUNET_SOCIAL_TalkFlags flags);
 
 
 /**
- * 
+ * Resume talking to the host of the place.
  *
- * @param
+ * @param tr
+ *        Talk request to resume.
  */
 void
-GNUNET_SOCIAL_place_watch_cancel (struct GNUNET_SOCIAL_WatchHandle *wh);
+GNUNET_SOCIAL_guest_talk_resume (struct GNUNET_SOCIAL_TalkRequest *tr);
 
 
 /**
+ * Cancel talking to the host of the place.
  *
+ * @param tr
+ *        Talk request to cancel.
  */
-struct GNUNET_SOCIAL_LookHandle;
+void
+GNUNET_SOCIAL_guest_talk_cancel (struct GNUNET_SOCIAL_TalkRequest *tr);
+
 
 /**
- * Look at all objects in the place.
+ * Leave a place permanently.
+ *
+ * Notifies the owner of the place about leaving, and destroys the place handle.
  *
+ * @param place
+ *        Place to leave permanently.
+ * @param keep_active
+ *        Keep place active after last application disconnected.
+ * @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.
  */
-struct GNUNET_SOCIAL_LookHandle *
-GNUNET_SOCIAL_place_look (struct GNUNET_SOCIAL_Place *place,
-                         GNUNET_PSYC_StateCallback state_cb,
-                         void *state_cb_cls);
+void
+GNUNET_SOCIAL_guest_leave (struct GNUNET_SOCIAL_Guest *guest,
+                           int keep_active,
+                           GNUNET_ContinuationCallback leave_cb,
+                           void *leave_cls);
 
 
 /**
- * Look at matching objects in the place.
+ * Obtain handle for a place entered as guest.
+ *
+ * The returned handle can be used to access the place API.
  *
+ * @param guest  Handle for the guest.
+ *
+ * @return Handle for the place, valid as long as @a guest is valid.
  */
-struct GNUNET_SOCIAL_LookHandle *
-GNUNET_SOCIAL_place_look_for (struct GNUNET_SOCIAL_Place *place,
-                             const char *object_filter,
-                             GNUNET_PSYC_StateCallback state_cb,
-                             void *state_cb_cls);
+struct GNUNET_SOCIAL_Place *
+GNUNET_SOCIAL_guest_get_place (struct GNUNET_SOCIAL_Guest *guest);
 
 
 /**
- * 
- *
+ * A history lesson.
  */
-void
-GNUNET_SOCIAL_place_look_cancel (struct GNUNET_SOCIAL_LookHandle *lh);
-
-
+struct GNUNET_SOCIAL_HistoryLesson;
 
 /**
- * Look at a particular object in the place.
+ * Learn about the history of a place.
+ *
+ * Sends messages through the slicer function of the place where
+ * start_message_id <= message_id <= end_message_id.
+ * The messages will have the #GNUNET_PSYC_MESSAGE_HISTORIC flag set.
+ *
+ * To get the latest message, use 0 for both the start and end message ID.
  *
- * @param
- * @param
- * @param
- * @return
+ * @param place Place we want to learn more about.
+ * @param start_message_id First historic message we are interested in.
+ * @param end_message_id Last historic message we are interested in (inclusive).
+ * @param slicer Slicer to use to process history.  Can be the same as the
+ *               slicer of the place, as the HISTORIC flag allows distinguishing
+ *               old messages from fresh ones.
+ * @param finish_cb Function called after the last message in the history lesson
+ *              is passed through the @a slicer. NULL if not needed.
+ * @param finish_cb_cls Closure for @a finish_cb.
+ * @return Handle to abort history lesson, never NULL (multiple lessons
+ *         at the same time are allowed).
  */
-const void *
-GNUNET_SOCIAL_place_look_at (struct GNUNET_SOCIAL_Place *place,
-                            const char *object_name,
-                            size_t *value_size);
+struct GNUNET_SOCIAL_HistoryLesson *
+GNUNET_SOCIAL_place_get_history (struct GNUNET_SOCIAL_Place *place,
+                                 uint64_t start_message_id,
+                                 uint64_t end_message_id,
+                                 const struct GNUNET_SOCIAL_Slicer *slicer,
+                                 void (*finish_cb)(void *),
+                                 void *finish_cb_cls);
 
 
 /**
- * Frame the (next) talk by setting some variables for it.
+ * Stop processing messages from the history lesson.
  *
- * @param
- * @param
- * @param
- * @param
+ * Must not be called after the finish callback of the history lesson is called.
+ *
+ * @param hist History lesson to cancel.
  */
 void
-GNUNET_SOCIAL_place_frame_talk (struct GNUNET_SOCIAL_Place *place,
-                               const char *variable_name,
-                               size_t value_size,
-                               const void *value);
-
+GNUNET_SOCIAL_place_get_history_cancel (struct GNUNET_SOCIAL_HistoryLesson *hist);
 
-/**
- *
- */
-struct GNUNET_SOCIAL_TalkRequest;
 
+struct GNUNET_SOCIAL_WatchHandle;
 
 /**
- * Talk to the host of the place.
+ * Watch a place for changed objects.
  *
- * @param 
- * @param 
- * @param 
- * @param cb_cls closure for 'cb'
- * @return NULL if we are already trying to talk to the host,
- *         otherwise handle to cancel the request
+ * @param place
+ *        Place to watch.
+ * @param object_filter
+ *        Object prefix to match.
+ * @param state_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_TalkRequest *
-GNUNET_SOCIAL_place_talk (struct GNUNET_SOCIAL_Place *place,
-                         const char *method_name,
-                         GNUNET_PSYC_OriginReadyNotify cb,
-                         void *cb_cls);
+struct GNUNET_SOCIAL_WatchHandle *
+GNUNET_SOCIAL_place_watch (struct GNUNET_SOCIAL_Place *place,
+                           const char *object_filter,
+                           GNUNET_PSYC_StateVarCallback state_var_cb,
+                           void *cls);
 
 
 /**
- * 
+ * Cancel watching a place for changed objects.
  *
- * @param
+ * @param wh Watch handle to cancel.
  */
 void
-GNUNET_SOCIAL_place_talk_cancel (struct GNUNET_SOCIAL_TalkRequest *tr);
-               
+GNUNET_SOCIAL_place_watch_cancel (struct GNUNET_SOCIAL_WatchHandle *wh);
 
-struct GNUNET_SOCIAL_HistoryLesson;
+
+struct GNUNET_SOCIAL_LookHandle;
 
 
 /**
- * 
- * @param
- * @param
- * @param
- * @param
- * @return
+ * Look at objects in the place with a matching name prefix.
+ *
+ * @param place
+ *        The place to look its objects at.
+ * @param name_prefix
+ *        Look at objects with names beginning with this value.
+ * @param state_var_cb
+ *        Function to call for each object found.
+ * @param cls
+ *        Closure for callback function.
+ *
+ * @return Handle that can be used to stop looking at objects.
  */
-struct GNUNET_SOCIAL_HistoryLesson *
-GNUNET_SOCIAL_place_get_history (struct GNUNET_SOCIAL_Place *place,
-                                uint64_t start_message_id,
-                                uint64_t end_message_id,
-                                struct GNUNET_SOCIAL_Slicer *slicer);
+struct GNUNET_SOCIAL_LookHandle *
+GNUNET_SOCIAL_place_look (struct GNUNET_SOCIAL_Place *place,
+                          const char *name_prefix,
+                          GNUNET_PSYC_StateVarCallback state_var_cb,
+                          void *cls);
 
 
 /**
- * 
+ * Stop looking at objects.
  *
- * @param
+ * @param lh Look handle to stop.
  */
 void
-GNUNET_SOCIAL_place_get_history_cancel (struct GNUNET_SOCIAL_HistoryLesson *hist);
+GNUNET_SOCIAL_place_look_cancel (struct GNUNET_SOCIAL_LookHandle *lh);
+
+
 
-         
 /**
- * Leave a place (destroys the place handle).
+ * Look at a particular object in the place.
  *
- * @param place place to leave
+ * The best matching object is returned (its name might be less specific than
+ * what was requested).
+ *
+ * @param place The place to look the object at.
+ * @param full_name Full name of the object.
+ * @param value_size Set to the size of the returned value.
+ * @return NULL if there is no such object at this place.
  */
-void
-GNUNET_SOCIAL_place_leave (struct GNUNET_SOCIAL_Place *place);
-
+const void *
+GNUNET_SOCIAL_place_look_at (struct GNUNET_SOCIAL_Place *place,
+                             const char *full_name,
+                             size_t *value_size);
 
 
 #if 0                           /* keep Emacsens' auto-indent happy */