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