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