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