75038407b54960a1b9ceae99655e348b5bc04f60
[oweals/gnunet.git] / src / include / gnunet_social_service.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2013 Christian Grothoff (and other contributing authors)
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 # 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 max_message_id
818  *        Last message ID sent to the place.
819  *        Or 0 if no messages have been sent to the place yet.
820  */
821 typedef void
822 (*GNUNET_SOCIAL_GuestEnterCallback) (void *cls, int result,
823                                      uint64_t max_message_id);
824
825
826 /**
827  * Function called upon a guest receives a decision about entry to the place.
828  *
829  * @param is_admitted
830  *        Is the guest admitted to the place?
831  *        #GNUNET_YES    if admitted,
832  *        #GNUNET_NO     if refused entry,
833  *        #GNUNET_SYSERR if the request could not be answered.
834  * @param data
835  *        Entry response message.
836  */
837 typedef void
838 (*GNUNET_SOCIAL_EntryDecisionCallback) (void *cls,
839                                         int is_admitted,
840                                         const struct GNUNET_PSYC_Message *entry_resp);
841
842
843 /**
844  * Request entry to a place as a guest.
845  *
846  * @param app
847  *        Application handle.
848  * @param ego
849  *        Identity of the guest.
850  * @param place_pub_key
851  *        Public key of the place to enter.
852  * @param flags
853  *        Flags for the entry.
854  * @param origin
855  *        Peer identity of the origin of the underlying multicast group.
856  * @param relay_count
857  *        Number of elements in the @a relays array.
858  * @param relays
859  *        Relays for the underlying multicast group.
860  * @param method_name
861  *        Method name for the message.
862  * @param env
863  *        Environment containing variables for the message, or NULL.
864  * @param data
865  *        Payload for the message to give to the enter callback.
866  * @param data_size
867  *        Number of bytes in @a data.
868  * @param slicer
869  *        Slicer to use for processing incoming requests from guests.
870  *
871  * @return NULL on errors, otherwise handle for the guest.
872  */
873 struct GNUNET_SOCIAL_Guest *
874 GNUNET_SOCIAL_guest_enter (const struct GNUNET_SOCIAL_App *app,
875                            const struct GNUNET_SOCIAL_Ego *ego,
876                            const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key,
877                            enum GNUNET_PSYC_SlaveJoinFlags flags,
878                            const struct GNUNET_PeerIdentity *origin,
879                            uint32_t relay_count,
880                            const struct GNUNET_PeerIdentity *relays,
881                            const struct GNUNET_PSYC_Message *entry_msg,
882                            struct GNUNET_PSYC_Slicer *slicer,
883                            GNUNET_SOCIAL_GuestEnterCallback local_enter_cb,
884                            GNUNET_SOCIAL_EntryDecisionCallback entry_dcsn_cb,
885                            void *cls);
886
887
888 /**
889  * Request entry to a place by name as a guest.
890  *
891  * @param app
892  *        Application handle.
893  * @param ego
894  *        Identity of the guest.
895  * @param gns_name
896  *        GNS name of the place to enter.  Either in the form of
897  *        'room.friend.gnu', or 'NYMPUBKEY.zkey'.  This latter case refers to
898  *        the 'PLACE' record of the empty label ("+") in the GNS zone with the
899  *        nym's public key 'NYMPUBKEY', and can be used to request entry to a
900  *        pseudonym's place directly.
901  * @param password
902  *        Password to decrypt the record, or NULL for cleartext records.
903  * @param join_msg
904  *        Entry request message.
905  * @param slicer
906  *        Slicer to use for processing incoming requests from guests.
907  * @param local_enter_cb
908  *        Called upon connection established to the social service.
909  * @param entry_decision_cb
910  *        Called upon receiving entry decision.
911  *
912  * @return NULL on errors, otherwise handle for the guest.
913  */
914 struct GNUNET_SOCIAL_Guest *
915 GNUNET_SOCIAL_guest_enter_by_name (const struct GNUNET_SOCIAL_App *app,
916                                    const struct GNUNET_SOCIAL_Ego *ego,
917                                    const char *gns_name,
918                                    const char *password,
919                                    const struct GNUNET_PSYC_Message *join_msg,
920                                    struct GNUNET_PSYC_Slicer *slicer,
921                                    GNUNET_SOCIAL_GuestEnterCallback local_enter_cb,
922                                    GNUNET_SOCIAL_EntryDecisionCallback entry_decision_cb,
923                                    void *cls);
924
925
926 /**
927  * Reconnect to an already entered place as guest.
928  *
929  * @param gconn
930  *        Guest connection handle.
931  *        @see GNUNET_SOCIAL_app_connect() & GNUNET_SOCIAL_AppGuestPlaceCallback()
932  * @param flags
933  *        Flags for the entry.
934  * @param slicer
935  *        Slicer to use for processing incoming requests from guests.
936  * @param local_enter_cb
937  *        Called upon connection established to the social service.
938  * @param entry_decision_cb
939  *        Called upon receiving entry decision.
940  *
941  * @return NULL on errors, otherwise handle for the guest.
942  */
943 struct GNUNET_SOCIAL_Guest *
944 GNUNET_SOCIAL_guest_enter_reconnect (struct GNUNET_SOCIAL_GuestConnection *gconn,
945                                      enum GNUNET_PSYC_SlaveJoinFlags flags,
946                                      struct GNUNET_PSYC_Slicer *slicer,
947                                      GNUNET_SOCIAL_GuestEnterCallback local_enter_cb,
948                                      void *cls);
949
950
951 /**
952  * Flags for talking to the host of a place.
953  */
954 enum GNUNET_SOCIAL_TalkFlags
955 {
956   GNUNET_SOCIAL_TALK_NONE = 0
957 };
958
959
960 /**
961  * A talk request.
962  */
963 struct GNUNET_SOCIAL_TalkRequest;
964
965
966 /**
967  * Talk to the host of the place.
968  *
969  * @param place
970  *        Place where we want to talk to the host.
971  * @param method_name
972  *        Method to invoke on the host.
973  * @param env
974  *        Environment containing variables for the message, or NULL.
975  * @param notify_data
976  *        Function to use to get the payload for the method.
977  * @param notify_data_cls
978  *        Closure for @a notify_data.
979  * @param flags
980  *        Flags for the message being sent.
981  *
982  * @return NULL if we are already trying to talk to the host,
983  *         otherwise handle to cancel the request.
984  */
985 struct GNUNET_SOCIAL_TalkRequest *
986 GNUNET_SOCIAL_guest_talk (struct GNUNET_SOCIAL_Guest *guest,
987                           const char *method_name,
988                           const struct GNUNET_PSYC_Environment *env,
989                           GNUNET_PSYC_TransmitNotifyData notify_data,
990                           void *notify_data_cls,
991                           enum GNUNET_SOCIAL_TalkFlags flags);
992
993
994 /**
995  * Resume talking to the host of the place.
996  *
997  * @param tr
998  *        Talk request to resume.
999  */
1000 void
1001 GNUNET_SOCIAL_guest_talk_resume (struct GNUNET_SOCIAL_TalkRequest *tr);
1002
1003
1004 /**
1005  * Cancel talking to the host of the place.
1006  *
1007  * @param tr
1008  *        Talk request to cancel.
1009  */
1010 void
1011 GNUNET_SOCIAL_guest_talk_cancel (struct GNUNET_SOCIAL_TalkRequest *tr);
1012
1013
1014 /**
1015  * Disconnect from a place.
1016  *
1017  * Invalidates guest handle.
1018  *
1019  * @param gst
1020  *        The guest to disconnect.
1021  * @param disconnect_cb
1022  *        Function called after disconnected from the service.
1023  * @param cls
1024  *        Closure for @a disconnect_cb.
1025  */
1026 void
1027 GNUNET_SOCIAL_guest_disconnect (struct GNUNET_SOCIAL_Guest *gst,
1028                                 GNUNET_ContinuationCallback disconnect_cb,
1029                                 void *cls);
1030
1031
1032 /**
1033  * Leave a place temporarily or permanently.
1034  *
1035  * Notifies the owner of the place about leaving, and destroys the place handle.
1036  *
1037  * @param place
1038  *        Place to leave.
1039  * @param env
1040  *        Optional environment for the leave message if @a keep_active
1041  *        is #GNUNET_NO.  NULL if not needed.
1042  * @param disconnect_cb
1043  *        Called upon disconnecting from the social service.
1044  */
1045 void
1046 GNUNET_SOCIAL_guest_leave (struct GNUNET_SOCIAL_Guest *gst,
1047                            struct GNUNET_PSYC_Environment *env,
1048                            GNUNET_ContinuationCallback disconnect_cb,
1049                            void *leave_cls);
1050
1051
1052 /**
1053  * Obtain handle for a place entered as guest.
1054  *
1055  * The returned handle can be used to access the place API.
1056  *
1057  * @param guest  Handle for the guest.
1058  *
1059  * @return Handle for the place, valid as long as @a guest is valid.
1060  */
1061 struct GNUNET_SOCIAL_Place *
1062 GNUNET_SOCIAL_guest_get_place (struct GNUNET_SOCIAL_Guest *guest);
1063
1064
1065 /**
1066  * A history request.
1067  */
1068 struct GNUNET_SOCIAL_HistoryRequest;
1069
1070
1071 /**
1072  * Set message processing @a flags for a @a method_prefix.
1073  *
1074  * @param plc
1075  *        Place.
1076  * @param method_prefix
1077  *        Method prefix @a flags apply to.
1078  * @param flags
1079  *        The flags that apply to a matching @a method_prefix.
1080  */
1081 void
1082 GNUNET_SOCIAL_place_msg_proc_set (struct GNUNET_SOCIAL_Place *plc,
1083                                   const char *method_prefix,
1084                                   enum GNUNET_SOCIAL_MsgProcFlags flags);
1085
1086 /**
1087  * Clear all message processing flags previously set for this place.
1088  */
1089 void
1090 GNUNET_SOCIAL_place_msg_proc_clear (struct GNUNET_SOCIAL_Place *plc);
1091
1092
1093 /**
1094  * Learn about the history of a place.
1095  *
1096  * Messages are returned through the @a slicer function
1097  * and have the #GNUNET_PSYC_MESSAGE_HISTORIC flag set.
1098  *
1099  * @param place
1100  *        Place we want to learn more about.
1101  * @param start_message_id
1102  *        First historic message we are interested in.
1103  * @param end_message_id
1104  *        Last historic message we are interested in (inclusive).
1105  * @param method_prefix
1106  *        Only retrieve messages with this method prefix.
1107  * @param flags
1108  *        OR'ed GNUNET_PSYC_HistoryReplayFlags
1109  * @param slicer
1110  *        Slicer to use for retrieved messages.
1111  *        Can be the same as the slicer of the place.
1112  * @param result_cb
1113  *        Function called after all messages retrieved.
1114  *        NULL if not needed.
1115  * @param cls Closure for @a result_cb.
1116  */
1117 struct GNUNET_SOCIAL_HistoryRequest *
1118 GNUNET_SOCIAL_place_history_replay (struct GNUNET_SOCIAL_Place *plc,
1119                                     uint64_t start_message_id,
1120                                     uint64_t end_message_id,
1121                                     const char *method_prefix,
1122                                     uint32_t flags,
1123                                     struct GNUNET_PSYC_Slicer *slicer,
1124                                     GNUNET_ResultCallback result_cb,
1125                                     void *cls);
1126
1127
1128 /**
1129  * Learn about the history of a place.
1130  *
1131  * Sends messages through the slicer function of the place where
1132  * start_message_id <= message_id <= end_message_id.
1133  * The messages will have the #GNUNET_PSYC_MESSAGE_HISTORIC flag set.
1134  *
1135  * To get the latest message, use 0 for both the start and end message ID.
1136  *
1137  * @param place
1138  *        Place we want to learn more about.
1139  * @param message_limit
1140  *        Maximum number of historic messages we are interested in.
1141  * @param result_cb
1142  *        Function called after all messages retrieved.
1143  *        NULL if not needed.
1144  * @param cls Closure for @a result_cb.
1145  */
1146 struct GNUNET_SOCIAL_HistoryRequest *
1147 GNUNET_SOCIAL_place_history_replay_latest (struct GNUNET_SOCIAL_Place *plc,
1148                                            uint64_t message_limit,
1149                                            const char *method_prefix,
1150                                            uint32_t flags,
1151                                            struct GNUNET_PSYC_Slicer *slicer,
1152                                            GNUNET_ResultCallback result_cb,
1153                                            void *cls);
1154
1155 /**
1156  * Cancel learning about the history of a place.
1157  *
1158  * @param hist
1159  *        History lesson to cancel.
1160  */
1161 void
1162 GNUNET_SOCIAL_place_history_replay_cancel (struct GNUNET_SOCIAL_HistoryRequest *hist);
1163
1164
1165 struct GNUNET_SOCIAL_LookHandle;
1166
1167
1168 /**
1169  * Look at a particular object in the place.
1170  *
1171  * The best matching object is returned (its name might be less specific than
1172  * what was requested).
1173  *
1174  * @param place
1175  *        The place to look the object at.
1176  * @param full_name
1177  *        Full name of the object.
1178  * @param value_size
1179  *        Set to the size of the returned value.
1180  *
1181  * @return NULL if there is no such object at this place.
1182  */
1183 struct GNUNET_SOCIAL_LookHandle *
1184 GNUNET_SOCIAL_place_look_at (struct GNUNET_SOCIAL_Place *plc,
1185                              const char *full_name,
1186                              GNUNET_PSYC_StateVarCallback var_cb,
1187                              GNUNET_ResultCallback result_cb,
1188                              void *cls);
1189
1190 /**
1191  * Look for objects in the place with a matching name prefix.
1192  *
1193  * @param place
1194  *        The place to look its objects at.
1195  * @param name_prefix
1196  *        Look at objects with names beginning with this value.
1197  * @param var_cb
1198  *        Function to call for each object found.
1199  * @param cls
1200  *        Closure for callback function.
1201  *
1202  * @return Handle that can be used to stop looking at objects.
1203  */
1204 struct GNUNET_SOCIAL_LookHandle *
1205 GNUNET_SOCIAL_place_look_for (struct GNUNET_SOCIAL_Place *plc,
1206                               const char *name_prefix,
1207                               GNUNET_PSYC_StateVarCallback var_cb,
1208                               GNUNET_ResultCallback result_cb,
1209                               void *cls);
1210
1211
1212 /**
1213  * Stop looking at objects.
1214  *
1215  * @param lh Look handle to stop.
1216  */
1217 void
1218 GNUNET_SOCIAL_place_look_cancel (struct GNUNET_SOCIAL_LookHandle *lh);
1219
1220
1221 /**
1222  * Advertise a @e place in the GNS zone of @a ego.
1223  *
1224  * @param app
1225  *        Application handle.
1226  * @param ego
1227  *        Ego.
1228  * @param place_pub_key
1229  *        Public key of place to add.
1230  * @param name
1231  *        The name for the PLACE record to put in the zone.
1232  * @param password
1233  *        Password used to encrypt the record or NULL to keep it cleartext.
1234  * @param relay_count
1235  *        Number of elements in the @a relays array.
1236  * @param relays
1237  *        List of relays to put in the PLACE record to advertise
1238  *        as entry points to the place in addition to the origin.
1239  * @param expiration_time
1240  *        Expiration time of the record, use 0 to remove the record.
1241  * @param result_cb
1242  *        Function called with the result of the operation.
1243  * @param result_cls
1244  *        Closure for @a result_cb
1245  *
1246  * @return #GNUNET_OK if the request was sent,
1247  *         #GNUNET_SYSERR on error, e.g. the name/password is too long.
1248  */
1249 int
1250 GNUNET_SOCIAL_zone_add_place (const struct GNUNET_SOCIAL_App *app,
1251                               const struct GNUNET_SOCIAL_Ego *ego,
1252                               const char *name,
1253                               const char *password,
1254                               const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key,
1255                               const struct GNUNET_PeerIdentity *origin,
1256                               uint32_t relay_count,
1257                               const struct GNUNET_PeerIdentity *relays,
1258                               struct GNUNET_TIME_Absolute expiration_time,
1259                               GNUNET_ResultCallback result_cb,
1260                               void *result_cls);
1261
1262
1263 /**
1264  * Add public key to the GNS zone of the @e ego.
1265  *
1266  * @param cfg
1267  *        Configuration.
1268  * @param ego
1269  *        Ego.
1270  * @param name
1271  *        The name for the PKEY record to put in the zone.
1272  * @param nym_pub_key
1273  *        Public key of nym to add.
1274  * @param expiration_time
1275  *        Expiration time of the record, use 0 to remove the record.
1276  * @param result_cb
1277  *        Function called with the result of the operation.
1278  * @param result_cls
1279  *        Closure for @a result_cb
1280  *
1281  * @return #GNUNET_OK if the request was sent,
1282  *         #GNUNET_SYSERR on error, e.g. the name is too long.
1283  */
1284 int
1285 GNUNET_SOCIAL_zone_add_nym (const struct GNUNET_SOCIAL_App *app,
1286                             const struct GNUNET_SOCIAL_Ego *ego,
1287                             const char *name,
1288                             const struct GNUNET_CRYPTO_EcdsaPublicKey *nym_pub_key,
1289                             struct GNUNET_TIME_Absolute expiration_time,
1290                             GNUNET_ResultCallback result_cb,
1291                             void *result_cls);
1292
1293
1294 #if 0                           /* keep Emacsens' auto-indent happy */
1295 {
1296 #endif
1297 #ifdef __cplusplus
1298 }
1299 #endif
1300
1301 /* ifndef GNUNET_SOCIAL_SERVICE_H */
1302 #endif
1303
1304 /** @} */  /* end of group */