b8b452dfab52a064f7d6ab72b3a59588cb2da0d9
[oweals/gnunet.git] / src / include / gnunet_social_service.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2013 GNUnet e.V.
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18      Boston, MA 02110-1301, USA.
19 */
20
21 /**
22  * @author Gabor X Toth
23  * @author Christian Grothoff
24  *
25  * @file
26  * Social service; implements social interactions through the PSYC service.
27  */
28
29 /** @defgroup social Social service
30 Social interactions through the PSYC service.
31
32 # Overview
33
34 The social service provides an API for social interactions based on a one-to-many messaging model.
35 It manages subscriptions of applications to places, provides messaging functionality in places,
36 allows access to the local message history and manages the GNS zone of _egos_ (user identities).
37
38 The service stores private and public keys of subscribed places, as well as files received in subscribed places.
39
40 # Concepts and terminology
41
42 ## Ego, Nym
43
44 An _ego_ is an identity of a user, a private-public key pair.
45 A _nym_ is an identity of another user in the network, identified by its public key.
46 Each user can have multiple identities.
47
48 struct GNUNET_SOCIAL_Ego and struct GNUNET_SOCIAL_Nym represents one of these identities.
49
50 ## Place, Host, Guest
51
52 A _place_ is where social interactions happen.  It is owned and created by an _ego_.
53 Creating a new place happens by an _ego_ entering a new place as a _host_,
54 where _guests_ can enter later to receive messages sent to the place.
55
56 A place is identified by its public key.
57
58 - struct GNUNET_SOCIAL_Host represents a place entered as host,
59 - struct GNUNET_SOCIAL_Guest is used for a place entered as guest.
60 - A struct GNUNET_SOCIAL_Place can be obtained for both a host and guest place
61   using GNUNET_SOCIAL_host_get_place() and GNUNET_SOCIAL_guest_get_place()
62   and can be used with API functions common to hosts and guests.
63
64 ## History
65
66 Messages sent to places are stored locally by the PSYCstore service, and can be queried any time.
67 GNUNET_SOCIAL_history_replay_latest() retrieves the latest N messages sent to the place,
68 while GNUNET_SOCIAL_history_replay() is used to query a given message ID range.
69
70 ## GNU Name System
71
72 The GNU Name System is used for assigning human-readable names to nyms and places.
73 There's a _GNS zone_ corresponding to each _nym_.
74 An _ego_ can publish PKEY and PLACE records in its own zone, pointing to nyms and places, respectively.
75
76 ## Announcement, talk request
77
78 The host can _announce_ messages to the place, using GNUNET_SOCIAL_host_announce().
79 Guests can send _talk_ requests to the host, using GNUNET_SOCIAL_guest_talk().
80 The host receives talk requests of guests and can _relay_ them to the place,
81 or process it using a message handler function.
82
83 # Using the API
84
85 ## Connecting to the service
86
87 A client first establishes an _application connection_ to the service using
88 GNUNET_SOCIAL_app_connect() providing its _application ID_, then receives the
89 public keys of subscribed places and available egos and in response.
90
91 ## Reconnecting to places
92
93 Then the application can reconnect to its subscribed places by establishing
94 _place connections_ with GNUNET_SOCIAL_host_enter_reconnect() and
95 GNUNET_SOCIAL_guest_enter_reconnect().
96
97 ## Subscribing to a place
98
99 Entering and subscribing a new host or guest place is done using
100 GNUNET_SOCIAL_host_enter() and GNUNET_SOCIAL_guest_enter().
101
102 ## Disconnecting from a place
103
104 An application can disconnect from a place while the social service keeps its
105 network connection active, using GNUNET_SOCIAL_host_disconnect() and
106 GNUNET_SOCIAL_guest_disconnect().
107
108 ## Leaving a place
109
110 To permanently leave a place, see GNUNET_SOCIAL_host_leave() and GNUNET_SOCIAL_guest_leave().
111 When leaving a place its network connections are closed and all applications are unsubscribed from the place.
112
113 # Message methods
114
115 ## _message
116
117 A message sent to the place.
118
119 ### Environment
120
121 #### _id_reply_to
122 Message ID this message is in reply to.
123
124 #### _id_thread
125 Thread ID, the first message ID in the thread.
126
127 #### _nym_author
128 Nym of the author.
129
130 #### _sig_author
131 Signature of the message body and its variables by the author.
132
133 ## Data
134
135 Message body.
136
137 ## _notice_place
138
139 Notification about a place.
140
141 TODO: Applications can decide to auto-subscribe to certain places,
142 e.g. files under a given size.
143
144 ### Environment
145
146 #### Using GNS
147
148 ##### _gns_place
149 GNS name of the place in a globally unique .zkey zone
150
151 #### Without GNS
152
153 ##### _key_pub_place
154 Public key of place
155
156 ##### _peer_origin
157 Peer ID of origin
158
159 ##### _list_peer_relays
160 List of peer IDs of relays
161
162 ## _notice_place_file
163
164 Notification about a place hosting a file.
165
166 ### Environment
167
168 The environment of _notice_place above, plus the following:
169
170 #### _size_file
171 Size of file
172
173 #### _mime_file
174 MIME type of file
175
176 #### _name_file
177 Name of file
178
179 #### _description_file
180 Description of file
181
182 ## _file
183
184 Messages with a _file method contain a file,
185 which is saved to disk upon receipt at the following location:
186 $GNUNET_DATA_HOME/social/files/<H(place_pub)>/<message_id>
187
188 ### Environment
189
190 #### _size_file
191 Size of file
192
193 #### _mime_file
194 MIME type of file
195
196 #### _name_file
197 Name of file
198
199 #### _description_file
200 Description of file
201
202 @{
203 */
204
205
206 #ifndef GNUNET_SOCIAL_SERVICE_H
207 #define GNUNET_SOCIAL_SERVICE_H
208
209 #ifdef __cplusplus
210 extern "C"
211 {
212 #if 0                           /* keep Emacsens' auto-indent happy */
213 }
214 #endif
215 #endif
216
217 #include <stdint.h>
218 #include "gnunet_util_lib.h"
219 #include "gnunet_psyc_util_lib.h"
220 #include "gnunet_identity_service.h"
221 #include "gnunet_namestore_service.h"
222 #include "gnunet_psyc_service.h"
223
224
225 /**
226  * Version number of GNUnet Social API.
227  */
228 #define GNUNET_SOCIAL_VERSION 0x00000000
229
230 /**
231  * Maximum size of client ID including '\0' terminator.
232  */
233 #define GNUNET_SOCIAL_APP_MAX_ID_SIZE 256
234
235 enum GNUNET_SOCIAL_MsgProcFlags {
236   GNUNET_SOCIAL_MSG_PROC_NONE = 0,
237   GNUNET_SOCIAL_MSG_PROC_RELAY = 1,
238   GNUNET_SOCIAL_MSG_PROC_SAVE= 2,
239 };
240
241 /**
242  * Handle for an application.
243  */
244 struct GNUNET_SOCIAL_App;
245
246 /**
247  * Handle for an ego (own identity)
248  */
249 struct GNUNET_SOCIAL_Ego;
250
251 /**
252  * Handle for a pseudonym of another user in the network.
253  */
254 struct GNUNET_SOCIAL_Nym;
255
256 /**
257  * Handle for a place where social interactions happen.
258  */
259 struct GNUNET_SOCIAL_Place;
260
261 /**
262  * Host handle for a place that we entered.
263  */
264 struct GNUNET_SOCIAL_Host;
265
266 /**
267  * Guest handle for place that we entered.
268  */
269 struct GNUNET_SOCIAL_Guest;
270
271 /**
272  * Handle that can be used to reconnect to a place as host.
273  */
274 struct GNUNET_SOCIAL_HostConnection;
275
276 /**
277  * Handle that can be used to reconnect to a place as guest.
278  */
279 struct GNUNET_SOCIAL_GuestConnection;
280
281 /**
282  * Notification about an available identity.
283  *
284  * @param cls
285  *        Closure.
286  * @param pub_key
287  *        Public key of ego.
288  * @param name
289  *        Name of ego.
290  */
291 typedef void
292 (*GNUNET_SOCIAL_AppEgoCallback) (void *cls,
293                                  struct GNUNET_SOCIAL_Ego *ego,
294                                  const struct GNUNET_CRYPTO_EcdsaPublicKey *ego_pub_key,
295                                  const char *name);
296
297
298 /**
299  * Entry status of a place.
300  */
301 enum GNUNET_SOCIAL_PlaceState
302 {
303   /**
304    * Place was once entered but left since.
305    */
306   GNUNET_SOCIAL_PLACE_STATE_ARCHIVED = 0,
307   /**
308    * Place is entered but not subscribed.
309    */
310   GNUNET_SOCIAL_PLACE_STATE_ENTERED = 1,
311   /**
312    * Place is entered and subscribed.
313    */
314   GNUNET_SOCIAL_PLACE_STATE_SUBSCRIBED = 2,
315 };
316
317
318 /**
319  * Notification about a home.
320  *
321  * @param cls
322  *        Closure.
323  * @param hconn
324  *        Host connection, to be used with GNUNET_SOCIAL_host_enter_reconnect()
325  * @param ego
326  *        Ego used to enter the place.
327  * @param place_pub_key
328  *        Public key of the place.
329  * @param place_state
330  *        @see enum GNUNET_SOCIAL_PlaceState
331  */
332 typedef void
333 (*GNUNET_SOCIAL_AppHostPlaceCallback) (void *cls,
334                                        struct GNUNET_SOCIAL_HostConnection *hconn,
335                                        struct GNUNET_SOCIAL_Ego *ego,
336                                        const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key,
337                                        enum GNUNET_SOCIAL_PlaceState place_state);
338
339 /**
340  * Notification about a place.
341  *
342  * @param cls
343  *        Closure.
344  * @param gconn
345  *        Guest connection, to be used with GNUNET_SOCIAL_guest_enter_reconnect()
346  * @param ego
347  *        Ego used to enter the place.
348  * @param place_pub_key
349  *        Public key of the place.
350  * @param place_state
351  *        @see enum GNUNET_SOCIAL_PlaceState
352  */
353 typedef void
354 (*GNUNET_SOCIAL_AppGuestPlaceCallback) (void *cls,
355                                         struct GNUNET_SOCIAL_GuestConnection *gconn,
356                                         struct GNUNET_SOCIAL_Ego *ego,
357                                         const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key,
358                                         enum GNUNET_SOCIAL_PlaceState place_state);
359
360
361 /**
362  * Establish application connection to the social service.
363  *
364  * The @host_place_cb and @guest_place_cb functions are
365  * initially called for each entered places,
366  * then later each time a new place is entered with the current app ID.
367  *
368  * @param cfg
369  *        Configuration.
370  * @param ego_cb
371  *        Function to notify about an available ego.
372  * @param host_cb
373  *        Function to notify about a place entered as host.
374  * @param guest_cb
375  *        Function to notify about a place entered as guest.
376  * @param cls
377  *        Closure for the callbacks.
378  *
379  * @return Handle that can be used to stop listening.
380  */
381 struct GNUNET_SOCIAL_App *
382 GNUNET_SOCIAL_app_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
383                            const char *id,
384                            GNUNET_SOCIAL_AppEgoCallback ego_cb,
385                            GNUNET_SOCIAL_AppHostPlaceCallback host_cb,
386                            GNUNET_SOCIAL_AppGuestPlaceCallback guest_cb,
387                            void *cls);
388
389
390 /**
391  * Disconnect app.
392  *
393  * @param c
394  *        App handle.
395  */
396 void
397 GNUNET_SOCIAL_app_disconnect (struct GNUNET_SOCIAL_App *app);
398
399
400 /**
401  * Get the public key of @a ego.
402  *
403  * @param ego
404  *        Ego.
405  *
406  * @return Public key of ego.
407  */
408 const struct GNUNET_CRYPTO_EcdsaPublicKey *
409 GNUNET_SOCIAL_ego_get_pub_key (const struct GNUNET_SOCIAL_Ego *ego);
410
411
412 /**
413  * Get the name of @a ego.
414  *
415  * @param ego
416  *        Ego.
417  *
418  * @return Public key of @a ego.
419  */
420 const char *
421 GNUNET_SOCIAL_ego_get_name (const struct GNUNET_SOCIAL_Ego *ego);
422
423
424 /**
425  * Get the public key of a @a nym.
426  *
427  * Suitable, for example, to be used with GNUNET_SOCIAL_zone_add_nym().
428  *
429  * @param nym
430  *        Pseudonym to map to a cryptographic identifier.
431  *
432  * @return Public key of nym.
433  */
434 const struct GNUNET_CRYPTO_EcdsaPublicKey *
435 GNUNET_SOCIAL_nym_get_pub_key (const struct GNUNET_SOCIAL_Nym *nym);
436
437
438 /**
439  * Get the hash of the public key of a @a nym.
440  *
441  * @param nym
442  *        Pseudonym to map to a cryptographic identifier.
443  *
444  * @return Hash of the public key of nym.
445  */
446 const struct GNUNET_HashCode *
447 GNUNET_SOCIAL_nym_get_pub_key_hash (const struct GNUNET_SOCIAL_Nym *nym);
448
449
450 /**
451  * Function called asking for nym to be admitted to the place.
452  *
453  * Should call either GNUNET_SOCIAL_host_admit() or
454  * GNUNET_SOCIAL_host_reject_entry() (possibly asynchronously).  If this host
455  * cannot decide, it is fine to call neither function, in which case hopefully
456  * some other host of the place exists that will make the decision.  The @a nym
457  * reference remains valid until the #GNUNET_SOCIAL_FarewellCallback is invoked
458  * for it.
459  *
460  * @param cls Closure.
461  * @param nym Handle for the user who wants to enter.
462  * @param method_name Method name in the entry request.
463  * @param variable_count Number of elements in the @a variables array.
464  * @param variables Variables present in the message.
465  * @param data_size Number of bytes in @a data.
466  * @param data Payload given on enter (e.g. a password).
467  */
468 typedef void
469 (*GNUNET_SOCIAL_AnswerDoorCallback) (void *cls,
470                                      struct GNUNET_SOCIAL_Nym *nym,
471                                      const char *method_name,
472                                      struct GNUNET_PSYC_Environment *env,
473                                      size_t data_size,
474                                      const void *data);
475
476
477 /**
478  * Function called when a @a nym leaves the place.
479  *
480  * This is also called if the @a nym was never given permission to enter
481  * (i.e. the @a nym stopped asking to get in).
482  *
483  * @param cls
484  *        Closure.
485  * @param nym
486  *        Handle for the user who left.
487  */
488 typedef void
489 (*GNUNET_SOCIAL_FarewellCallback) (void *cls,
490                                    const struct GNUNET_SOCIAL_Nym *nym,
491                                    struct GNUNET_PSYC_Environment *env);
492
493
494 /**
495  * Function called after the host entered a home.
496  *
497  * @param cls
498  *        Closure.
499  * @param result
500  *        #GNUNET_OK on success, or
501  *        #GNUNET_SYSERR on error.
502  * @param place_pub_key
503  *        Public key of home.
504  * @param max_message_id
505  *        Last message ID sent to the channel.
506  *        Or 0 if no messages have been sent to the place yet.
507  */
508 typedef void
509 (*GNUNET_SOCIAL_HostEnterCallback) (void *cls, int result,
510                                     const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key,
511                                     uint64_t max_message_id);
512
513
514 /**
515  * Enter a place as host.
516  *
517  * A place is created upon first entering, and it is active until permanently
518  * left using GNUNET_SOCIAL_host_leave().
519  *
520  * @param cfg
521  *        Configuration to contact the social service.
522  * @param ego
523  *        Identity of the host.
524  * @param place_key
525  *        Private-public key pair of the place.
526  *        NULL for ephemeral places.
527  * @param policy
528  *        Policy specifying entry and history restrictions for the place.
529  * @param slicer
530  *        Slicer to handle incoming messages.
531  * @param enter_cb
532  *        Function called when the place is entered and ready to use.
533  * @param answer_door_cb
534  *        Function to handle new nyms that want to enter.
535  * @param farewell_cb
536  *        Function to handle departing nyms.
537  * @param cls
538  *        Closure for the callbacks.
539  *
540  * @return Handle for the host.
541  */
542 struct GNUNET_SOCIAL_Host *
543 GNUNET_SOCIAL_host_enter (const struct GNUNET_SOCIAL_App *app,
544                           const struct GNUNET_SOCIAL_Ego *ego,
545                           enum GNUNET_PSYC_Policy policy,
546                           struct GNUNET_PSYC_Slicer *slicer,
547                           GNUNET_SOCIAL_HostEnterCallback enter_cb,
548                           GNUNET_SOCIAL_AnswerDoorCallback answer_door_cb,
549                           GNUNET_SOCIAL_FarewellCallback farewell_cb,
550                           void *cls);
551
552
553 /**
554  * Reconnect to an already entered place as host.
555  *
556  * @param hconn
557  *        Host connection handle.
558  *        @see GNUNET_SOCIAL_app_connect() & GNUNET_SOCIAL_AppHostPlaceCallback()
559  * @param slicer
560  *        Slicer to handle incoming messages.
561  * @param enter_cb
562  *        Function called when the place is entered and ready to use.
563  * @param answer_door_cb
564  *        Function to handle new nyms that want to enter.
565  * @param farewell_cb
566  *        Function to handle departing nyms.
567  * @param cls
568  *        Closure for the callbacks.
569  *
570  * @return Handle for the host.
571  */
572 struct GNUNET_SOCIAL_Host *
573 GNUNET_SOCIAL_host_enter_reconnect (struct GNUNET_SOCIAL_HostConnection *hconn,
574                                     struct GNUNET_PSYC_Slicer *slicer,
575                                     GNUNET_SOCIAL_HostEnterCallback enter_cb,
576                                     GNUNET_SOCIAL_AnswerDoorCallback answer_door_cb,
577                                     GNUNET_SOCIAL_FarewellCallback farewell_cb,
578                                     void *cls);
579
580
581 /**
582  * Decision whether to admit @a nym into the place or refuse entry.
583  *
584  * @param hst
585  *        Host of the place.
586  * @param nym
587  *        Handle for the entity that wanted to enter.
588  * @param is_admitted
589  *        #GNUNET_YES    if @a nym is admitted,
590  *        #GNUNET_NO     if @a nym is refused entry,
591  *        #GNUNET_SYSERR if we cannot answer the request.
592  * @param method_name
593  *        Method name for the rejection message.
594  * @param env
595  *        Environment containing variables for the message, or NULL.
596  * @param data
597  *        Data for the rejection message to send back.
598  * @param data_size
599  *        Number of bytes in @a data for method.
600  * @return #GNUNET_OK on success,
601  *         #GNUNET_SYSERR if the message is too large.
602  */
603 int
604 GNUNET_SOCIAL_host_entry_decision (struct GNUNET_SOCIAL_Host *hst,
605                                    struct GNUNET_SOCIAL_Nym *nym,
606                                    int is_admitted,
607                                    const struct GNUNET_PSYC_Message *entry_resp);
608
609
610 /**
611  * Throw @a nym out of the place.
612  *
613  * Sends a _notice_place_leave announcement to the home.
614  *
615  * The @a nym reference will remain valid until the
616  * #GNUNET_SOCIAL_FarewellCallback is invoked,
617  * which should be very soon after this call.
618  *
619  * @param host
620  *        Host of the place.
621  * @param nym
622  *        Handle for the entity to be ejected.
623  * @param env
624  *        Environment for the message or NULL.
625  *        _nym is set to @e nym regardless whether an @e env is provided.
626  */
627 void
628 GNUNET_SOCIAL_host_eject (struct GNUNET_SOCIAL_Host *host,
629                           const struct GNUNET_SOCIAL_Nym *nym,
630                           struct GNUNET_PSYC_Environment *env);
631
632
633 /**
634  * Flags for announcements by a host.
635  */
636 enum GNUNET_SOCIAL_AnnounceFlags
637 {
638   GNUNET_SOCIAL_ANNOUNCE_NONE = 0,
639
640   /**
641    * Whether this announcement removes all objects from the place.
642    *
643    * New objects can be still added to the now empty place using the @e env
644    * parameter of the same announcement.
645    */
646   GNUNET_SOCIAL_ANNOUNCE_CLEAR_OBJECTS = 1 << 0
647 };
648
649
650 /**
651  * Handle for an announcement request.
652  */
653 struct GNUNET_SOCIAL_Announcement;
654
655
656 /**
657  * Send a message to all nyms that are present in the place.
658  *
659  * This function is restricted to the host.  Nyms can only send requests
660  * to the host who can decide to relay it to everyone in the place.
661  *
662  * @param host
663  *        Host of the place.
664  * @param method_name
665  *        Method to use for the announcement.
666  * @param env
667  *        Environment containing variables for the message and operations
668  *        on objects of the place.
669  *        Has to remain available until the first call to @a notify_data.
670  *        Can be NULL.
671  * @param notify_data
672  *        Function to call to get the payload of the announcement.
673  * @param notify_data_cls
674  *        Closure for @a notify.
675  * @param flags
676  *        Flags for this announcement.
677  *
678  * @return NULL on error (another announcement already in progress?).
679  */
680 struct GNUNET_SOCIAL_Announcement *
681 GNUNET_SOCIAL_host_announce (struct GNUNET_SOCIAL_Host *host,
682                              const char *method_name,
683                              const struct GNUNET_PSYC_Environment *env,
684                              GNUNET_PSYC_TransmitNotifyData notify_data,
685                              void *notify_data_cls,
686                              enum GNUNET_SOCIAL_AnnounceFlags flags);
687
688
689 /**
690  * Resume transmitting announcement.
691  *
692  * @param a
693  *        The announcement to resume.
694  */
695 void
696 GNUNET_SOCIAL_host_announce_resume (struct GNUNET_SOCIAL_Announcement *a);
697
698
699 /**
700  * Cancel announcement.
701  *
702  * @param a
703  *        The announcement to cancel.
704  */
705 void
706 GNUNET_SOCIAL_host_announce_cancel (struct GNUNET_SOCIAL_Announcement *a);
707
708
709 /**
710  * Allow relaying messages from guests matching a given @a method_prefix.
711  *
712  * @param host
713  *        The host.
714  * @param method_prefix
715  *        Method prefix to allow.
716  */
717 void
718 GNUNET_SOCIAL_host_relay_allow_method (struct GNUNET_SOCIAL_Host *host,
719                                        const char *method_prefix);
720
721
722 /**
723  * Allow relaying changes to objects of the place.
724  *
725  * Only applies to messages with an allowed method name.
726  * @see GNUNET_SCOIAL_host_relay_allow_method()
727  *
728  * @param host
729  *        The host.
730  * @param object_prefix
731  *        Object prefix to allow modifying.
732  */
733 void
734 GNUNET_SOCIAL_host_relay_allow_method (struct GNUNET_SOCIAL_Host *host,
735                                        const char *object_prefix);
736
737
738 /**
739  * Stop relaying messages from guests.
740  *
741  * Remove all allowed relay rules.
742  *
743  *
744  *
745  */
746 void
747 GNUNET_SOCIAL_host_relay_stop (struct GNUNET_SOCIAL_Host *host);
748
749
750 /**
751  * Obtain handle for a hosted place.
752  *
753  * The returned handle can be used to access the place API.
754  *
755  * @param host
756  *        Handle for the host.
757  *
758  * @return Handle for the hosted place, valid as long as @a host is valid.
759  */
760 struct GNUNET_SOCIAL_Place *
761 GNUNET_SOCIAL_host_get_place (struct GNUNET_SOCIAL_Host *host);
762
763
764 /**
765  * Disconnect from a home.
766  *
767  * Invalidates host handle.
768  *
769  * @param hst
770  *        The host to disconnect.
771  * @param disconnect_cb
772  *        Function called after disconnected from the service.
773  * @param cls
774  *        Closure for @a disconnect_cb.
775  */
776 void
777 GNUNET_SOCIAL_host_disconnect (struct GNUNET_SOCIAL_Host *hst,
778                                GNUNET_ContinuationCallback disconnect_cb,
779                                void *cls);
780
781
782 /**
783  * Stop hosting a home.
784  *
785  * Sends a _notice_place_closed announcement to the home.
786  * Invalidates host handle.
787  *
788  * @param hst
789  *        Host leaving.
790  * @param env
791  *        Environment for the message or NULL.
792  * @param disconnect_cb
793  *        Function called after the host left the place
794  *        and disconnected from the service.
795  * @param cls
796  *        Closure for @a disconnect_cb.
797  */
798 void
799 GNUNET_SOCIAL_host_leave (struct GNUNET_SOCIAL_Host *hst,
800                           const struct GNUNET_PSYC_Environment *env,
801                           GNUNET_ContinuationCallback disconnect_cb,
802                           void *cls);
803
804
805 /**
806  * Function called after the guest entered the local copy of the place.
807  *
808  * History and object query functions can be used after this call,
809  * but new messages can't be sent or received.
810  *
811  * @param cls
812  *        Closure.
813  * @param result
814  *        #GNUNET_OK on success, or
815  *        #GNUNET_SYSERR on error, e.g. could not connect to the service, or
816  *        could not resolve GNS name.
817  * @param place_pub_key
818  *        Public key of place.
819  * @param max_message_id
820  *        Last message ID sent to the place.
821  *        Or 0 if no messages have been sent to the place yet.
822  */
823 typedef void
824 (*GNUNET_SOCIAL_GuestEnterCallback) (void *cls, int result,
825                                      const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key,
826                                      uint64_t max_message_id);
827
828
829 /**
830  * Function called upon a guest receives a decision about entry to the place.
831  *
832  * @param is_admitted
833  *        Is the guest admitted to the place?
834  *        #GNUNET_YES    if admitted,
835  *        #GNUNET_NO     if refused entry,
836  *        #GNUNET_SYSERR if the request could not be answered.
837  * @param data
838  *        Entry response message.
839  */
840 typedef void
841 (*GNUNET_SOCIAL_EntryDecisionCallback) (void *cls,
842                                         int is_admitted,
843                                         const struct GNUNET_PSYC_Message *entry_resp);
844
845
846 /**
847  * Request entry to a place as a guest.
848  *
849  * @param app
850  *        Application handle.
851  * @param ego
852  *        Identity of the guest.
853  * @param place_pub_key
854  *        Public key of the place to enter.
855  * @param flags
856  *        Flags for the entry.
857  * @param origin
858  *        Peer identity of the origin of the underlying multicast group.
859  * @param relay_count
860  *        Number of elements in the @a relays array.
861  * @param relays
862  *        Relays for the underlying multicast group.
863  * @param method_name
864  *        Method name for the message.
865  * @param env
866  *        Environment containing variables for the message, or NULL.
867  * @param data
868  *        Payload for the message to give to the enter callback.
869  * @param data_size
870  *        Number of bytes in @a data.
871  * @param slicer
872  *        Slicer to use for processing incoming requests from guests.
873  *
874  * @return NULL on errors, otherwise handle for the guest.
875  */
876 struct GNUNET_SOCIAL_Guest *
877 GNUNET_SOCIAL_guest_enter (const struct GNUNET_SOCIAL_App *app,
878                            const struct GNUNET_SOCIAL_Ego *ego,
879                            const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key,
880                            enum GNUNET_PSYC_SlaveJoinFlags flags,
881                            const struct GNUNET_PeerIdentity *origin,
882                            uint32_t relay_count,
883                            const struct GNUNET_PeerIdentity *relays,
884                            const struct GNUNET_PSYC_Message *entry_msg,
885                            struct GNUNET_PSYC_Slicer *slicer,
886                            GNUNET_SOCIAL_GuestEnterCallback local_enter_cb,
887                            GNUNET_SOCIAL_EntryDecisionCallback entry_dcsn_cb,
888                            void *cls);
889
890
891 /**
892  * Request entry to a place by name as a guest.
893  *
894  * @param app
895  *        Application handle.
896  * @param ego
897  *        Identity of the guest.
898  * @param gns_name
899  *        GNS name of the place to enter.  Either in the form of
900  *        'room.friend.gnu', or 'NYMPUBKEY.zkey'.  This latter case refers to
901  *        the 'PLACE' record of the empty label ("+") in the GNS zone with the
902  *        nym's public key 'NYMPUBKEY', and can be used to request entry to a
903  *        pseudonym's place directly.
904  * @param password
905  *        Password to decrypt the record, or NULL for cleartext records.
906  * @param join_msg
907  *        Entry request message.
908  * @param slicer
909  *        Slicer to use for processing incoming requests from guests.
910  * @param local_enter_cb
911  *        Called upon connection established to the social service.
912  * @param entry_decision_cb
913  *        Called upon receiving entry decision.
914  *
915  * @return NULL on errors, otherwise handle for the guest.
916  */
917 struct GNUNET_SOCIAL_Guest *
918 GNUNET_SOCIAL_guest_enter_by_name (const struct GNUNET_SOCIAL_App *app,
919                                    const struct GNUNET_SOCIAL_Ego *ego,
920                                    const char *gns_name,
921                                    const char *password,
922                                    const struct GNUNET_PSYC_Message *join_msg,
923                                    struct GNUNET_PSYC_Slicer *slicer,
924                                    GNUNET_SOCIAL_GuestEnterCallback local_enter_cb,
925                                    GNUNET_SOCIAL_EntryDecisionCallback entry_decision_cb,
926                                    void *cls);
927
928
929 /**
930  * Reconnect to an already entered place as guest.
931  *
932  * @param gconn
933  *        Guest connection handle.
934  *        @see GNUNET_SOCIAL_app_connect() & GNUNET_SOCIAL_AppGuestPlaceCallback()
935  * @param flags
936  *        Flags for the entry.
937  * @param slicer
938  *        Slicer to use for processing incoming requests from guests.
939  * @param local_enter_cb
940  *        Called upon connection established to the social service.
941  * @param entry_decision_cb
942  *        Called upon receiving entry decision.
943  *
944  * @return NULL on errors, otherwise handle for the guest.
945  */
946 struct GNUNET_SOCIAL_Guest *
947 GNUNET_SOCIAL_guest_enter_reconnect (struct GNUNET_SOCIAL_GuestConnection *gconn,
948                                      enum GNUNET_PSYC_SlaveJoinFlags flags,
949                                      struct GNUNET_PSYC_Slicer *slicer,
950                                      GNUNET_SOCIAL_GuestEnterCallback local_enter_cb,
951                                      void *cls);
952
953
954 /**
955  * Flags for talking to the host of a place.
956  */
957 enum GNUNET_SOCIAL_TalkFlags
958 {
959   GNUNET_SOCIAL_TALK_NONE = 0
960 };
961
962
963 /**
964  * A talk request.
965  */
966 struct GNUNET_SOCIAL_TalkRequest;
967
968
969 /**
970  * Talk to the host of the place.
971  *
972  * @param place
973  *        Place where we want to talk to the host.
974  * @param method_name
975  *        Method to invoke on the host.
976  * @param env
977  *        Environment containing variables for the message, or NULL.
978  * @param notify_data
979  *        Function to use to get the payload for the method.
980  * @param notify_data_cls
981  *        Closure for @a notify_data.
982  * @param flags
983  *        Flags for the message being sent.
984  *
985  * @return NULL if we are already trying to talk to the host,
986  *         otherwise handle to cancel the request.
987  */
988 struct GNUNET_SOCIAL_TalkRequest *
989 GNUNET_SOCIAL_guest_talk (struct GNUNET_SOCIAL_Guest *guest,
990                           const char *method_name,
991                           const struct GNUNET_PSYC_Environment *env,
992                           GNUNET_PSYC_TransmitNotifyData notify_data,
993                           void *notify_data_cls,
994                           enum GNUNET_SOCIAL_TalkFlags flags);
995
996
997 /**
998  * Resume talking to the host of the place.
999  *
1000  * @param tr
1001  *        Talk request to resume.
1002  */
1003 void
1004 GNUNET_SOCIAL_guest_talk_resume (struct GNUNET_SOCIAL_TalkRequest *tr);
1005
1006
1007 /**
1008  * Cancel talking to the host of the place.
1009  *
1010  * @param tr
1011  *        Talk request to cancel.
1012  */
1013 void
1014 GNUNET_SOCIAL_guest_talk_cancel (struct GNUNET_SOCIAL_TalkRequest *tr);
1015
1016
1017 /**
1018  * Disconnect from a place.
1019  *
1020  * Invalidates guest handle.
1021  *
1022  * @param gst
1023  *        The guest to disconnect.
1024  * @param disconnect_cb
1025  *        Function called after disconnected from the service.
1026  * @param cls
1027  *        Closure for @a disconnect_cb.
1028  */
1029 void
1030 GNUNET_SOCIAL_guest_disconnect (struct GNUNET_SOCIAL_Guest *gst,
1031                                 GNUNET_ContinuationCallback disconnect_cb,
1032                                 void *cls);
1033
1034
1035 /**
1036  * Leave a place temporarily or permanently.
1037  *
1038  * Notifies the owner of the place about leaving, and destroys the place handle.
1039  *
1040  * @param place
1041  *        Place to leave.
1042  * @param env
1043  *        Optional environment for the leave message if @a keep_active
1044  *        is #GNUNET_NO.  NULL if not needed.
1045  * @param disconnect_cb
1046  *        Called upon disconnecting from the social service.
1047  */
1048 void
1049 GNUNET_SOCIAL_guest_leave (struct GNUNET_SOCIAL_Guest *gst,
1050                            struct GNUNET_PSYC_Environment *env,
1051                            GNUNET_ContinuationCallback disconnect_cb,
1052                            void *leave_cls);
1053
1054
1055 /**
1056  * Obtain handle for a place entered as guest.
1057  *
1058  * The returned handle can be used to access the place API.
1059  *
1060  * @param guest  Handle for the guest.
1061  *
1062  * @return Handle for the place, valid as long as @a guest is valid.
1063  */
1064 struct GNUNET_SOCIAL_Place *
1065 GNUNET_SOCIAL_guest_get_place (struct GNUNET_SOCIAL_Guest *guest);
1066
1067
1068 /**
1069  * A history request.
1070  */
1071 struct GNUNET_SOCIAL_HistoryRequest;
1072
1073
1074 /**
1075  * Get the public key of a place.
1076  *
1077  * @param plc
1078  *        Place.
1079  *
1080  * @return Public key of the place.
1081  */
1082 const struct GNUNET_CRYPTO_EddsaPublicKey *
1083 GNUNET_SOCIAL_place_get_pub_key (const struct GNUNET_SOCIAL_Place *plc);
1084
1085
1086 /**
1087  * Set message processing @a flags for a @a method_prefix.
1088  *
1089  * @param plc
1090  *        Place.
1091  * @param method_prefix
1092  *        Method prefix @a flags apply to.
1093  * @param flags
1094  *        The flags that apply to a matching @a method_prefix.
1095  */
1096 void
1097 GNUNET_SOCIAL_place_msg_proc_set (struct GNUNET_SOCIAL_Place *plc,
1098                                   const char *method_prefix,
1099                                   enum GNUNET_SOCIAL_MsgProcFlags flags);
1100
1101 /**
1102  * Clear all message processing flags previously set for this place.
1103  */
1104 void
1105 GNUNET_SOCIAL_place_msg_proc_clear (struct GNUNET_SOCIAL_Place *plc);
1106
1107
1108 /**
1109  * Learn about the history of a place.
1110  *
1111  * Messages are returned through the @a slicer function
1112  * and have the #GNUNET_PSYC_MESSAGE_HISTORIC flag set.
1113  *
1114  * @param place
1115  *        Place we want to learn more about.
1116  * @param start_message_id
1117  *        First historic message we are interested in.
1118  * @param end_message_id
1119  *        Last historic message we are interested in (inclusive).
1120  * @param method_prefix
1121  *        Only retrieve messages with this method prefix.
1122  * @param flags
1123  *        OR'ed GNUNET_PSYC_HistoryReplayFlags
1124  * @param slicer
1125  *        Slicer to use for retrieved messages.
1126  *        Can be the same as the slicer of the place.
1127  * @param result_cb
1128  *        Function called after all messages retrieved.
1129  *        NULL if not needed.
1130  * @param cls Closure for @a result_cb.
1131  */
1132 struct GNUNET_SOCIAL_HistoryRequest *
1133 GNUNET_SOCIAL_place_history_replay (struct GNUNET_SOCIAL_Place *plc,
1134                                     uint64_t start_message_id,
1135                                     uint64_t end_message_id,
1136                                     const char *method_prefix,
1137                                     uint32_t flags,
1138                                     struct GNUNET_PSYC_Slicer *slicer,
1139                                     GNUNET_ResultCallback result_cb,
1140                                     void *cls);
1141
1142
1143 /**
1144  * Learn about the history of a place.
1145  *
1146  * Sends messages through the slicer function of the place where
1147  * start_message_id <= message_id <= end_message_id.
1148  * The messages will have the #GNUNET_PSYC_MESSAGE_HISTORIC flag set.
1149  *
1150  * To get the latest message, use 0 for both the start and end message ID.
1151  *
1152  * @param place
1153  *        Place we want to learn more about.
1154  * @param message_limit
1155  *        Maximum number of historic messages we are interested in.
1156  * @param result_cb
1157  *        Function called after all messages retrieved.
1158  *        NULL if not needed.
1159  * @param cls Closure for @a result_cb.
1160  */
1161 struct GNUNET_SOCIAL_HistoryRequest *
1162 GNUNET_SOCIAL_place_history_replay_latest (struct GNUNET_SOCIAL_Place *plc,
1163                                            uint64_t message_limit,
1164                                            const char *method_prefix,
1165                                            uint32_t flags,
1166                                            struct GNUNET_PSYC_Slicer *slicer,
1167                                            GNUNET_ResultCallback result_cb,
1168                                            void *cls);
1169
1170 /**
1171  * Cancel learning about the history of a place.
1172  *
1173  * @param hist
1174  *        History lesson to cancel.
1175  */
1176 void
1177 GNUNET_SOCIAL_place_history_replay_cancel (struct GNUNET_SOCIAL_HistoryRequest *hist);
1178
1179
1180 struct GNUNET_SOCIAL_LookHandle;
1181
1182
1183 /**
1184  * Look at a particular object in the place.
1185  *
1186  * The best matching object is returned (its name might be less specific than
1187  * what was requested).
1188  *
1189  * @param place
1190  *        The place to look the object at.
1191  * @param full_name
1192  *        Full name of the object.
1193  * @param value_size
1194  *        Set to the size of the returned value.
1195  *
1196  * @return NULL if there is no such object at this place.
1197  */
1198 struct GNUNET_SOCIAL_LookHandle *
1199 GNUNET_SOCIAL_place_look_at (struct GNUNET_SOCIAL_Place *plc,
1200                              const char *full_name,
1201                              GNUNET_PSYC_StateVarCallback var_cb,
1202                              GNUNET_ResultCallback result_cb,
1203                              void *cls);
1204
1205 /**
1206  * Look for objects in the place with a matching name prefix.
1207  *
1208  * @param place
1209  *        The place to look its objects at.
1210  * @param name_prefix
1211  *        Look at objects with names beginning with this value.
1212  * @param var_cb
1213  *        Function to call for each object found.
1214  * @param cls
1215  *        Closure for callback function.
1216  *
1217  * @return Handle that can be used to stop looking at objects.
1218  */
1219 struct GNUNET_SOCIAL_LookHandle *
1220 GNUNET_SOCIAL_place_look_for (struct GNUNET_SOCIAL_Place *plc,
1221                               const char *name_prefix,
1222                               GNUNET_PSYC_StateVarCallback var_cb,
1223                               GNUNET_ResultCallback result_cb,
1224                               void *cls);
1225
1226
1227 /**
1228  * Stop looking at objects.
1229  *
1230  * @param lh Look handle to stop.
1231  */
1232 void
1233 GNUNET_SOCIAL_place_look_cancel (struct GNUNET_SOCIAL_LookHandle *lh);
1234
1235
1236 /**
1237  * Advertise a @e place in the GNS zone of @a ego.
1238  *
1239  * @param app
1240  *        Application handle.
1241  * @param ego
1242  *        Ego.
1243  * @param place_pub_key
1244  *        Public key of place to add.
1245  * @param name
1246  *        The name for the PLACE record to put in the zone.
1247  * @param password
1248  *        Password used to encrypt the record or NULL to keep it cleartext.
1249  * @param relay_count
1250  *        Number of elements in the @a relays array.
1251  * @param relays
1252  *        List of relays to put in the PLACE record to advertise
1253  *        as entry points to the place in addition to the origin.
1254  * @param expiration_time
1255  *        Expiration time of the record, use 0 to remove the record.
1256  * @param result_cb
1257  *        Function called with the result of the operation.
1258  * @param result_cls
1259  *        Closure for @a result_cb
1260  *
1261  * @return #GNUNET_OK if the request was sent,
1262  *         #GNUNET_SYSERR on error, e.g. the name/password is too long.
1263  */
1264 int
1265 GNUNET_SOCIAL_zone_add_place (const struct GNUNET_SOCIAL_App *app,
1266                               const struct GNUNET_SOCIAL_Ego *ego,
1267                               const char *name,
1268                               const char *password,
1269                               const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key,
1270                               const struct GNUNET_PeerIdentity *origin,
1271                               uint32_t relay_count,
1272                               const struct GNUNET_PeerIdentity *relays,
1273                               struct GNUNET_TIME_Absolute expiration_time,
1274                               GNUNET_ResultCallback result_cb,
1275                               void *result_cls);
1276
1277
1278 /**
1279  * Add public key to the GNS zone of the @e ego.
1280  *
1281  * @param cfg
1282  *        Configuration.
1283  * @param ego
1284  *        Ego.
1285  * @param name
1286  *        The name for the PKEY record to put in the zone.
1287  * @param nym_pub_key
1288  *        Public key of nym to add.
1289  * @param expiration_time
1290  *        Expiration time of the record, use 0 to remove the record.
1291  * @param result_cb
1292  *        Function called with the result of the operation.
1293  * @param result_cls
1294  *        Closure for @a result_cb
1295  *
1296  * @return #GNUNET_OK if the request was sent,
1297  *         #GNUNET_SYSERR on error, e.g. the name is too long.
1298  */
1299 int
1300 GNUNET_SOCIAL_zone_add_nym (const struct GNUNET_SOCIAL_App *app,
1301                             const struct GNUNET_SOCIAL_Ego *ego,
1302                             const char *name,
1303                             const struct GNUNET_CRYPTO_EcdsaPublicKey *nym_pub_key,
1304                             struct GNUNET_TIME_Absolute expiration_time,
1305                             GNUNET_ResultCallback result_cb,
1306                             void *result_cls);
1307
1308
1309 #if 0                           /* keep Emacsens' auto-indent happy */
1310 {
1311 #endif
1312 #ifdef __cplusplus
1313 }
1314 #endif
1315
1316 /* ifndef GNUNET_SOCIAL_SERVICE_H */
1317 #endif
1318
1319 /** @} */  /* end of group */