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