2 This file is part of GNUnet.
3 Copyright (C) 2013 Christian Grothoff (and other contributing authors)
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.
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.
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.
22 * @file include/gnunet_social_service.h
23 * @brief Social service; implements social interactions using the PSYC service.
24 * @author Gabor X Toth
25 * @author Christian Grothoff
27 #ifndef GNUNET_SOCIAL_SERVICE_H
28 #define GNUNET_SOCIAL_SERVICE_H
33 #if 0 /* keep Emacsens' auto-indent happy */
38 #include "gnunet_util_lib.h"
39 #include "gnunet_env_lib.h"
40 #include "gnunet_identity_service.h"
41 #include "gnunet_psyc_service.h"
45 * Version number of GNUnet Social API.
47 #define GNUNET_SOCIAL_VERSION 0x00000000
51 * Handle for a pseudonym of another user in the network.
53 struct GNUNET_SOCIAL_Nym;
56 * Handle for a place where social interactions happen.
58 struct GNUNET_SOCIAL_Place;
61 * Host handle for a place that we entered.
63 struct GNUNET_SOCIAL_Host;
66 * Guest handle for place that we entered.
68 struct GNUNET_SOCIAL_Guest;
71 * Handle to an implementation of try-and-slice.
73 struct GNUNET_SOCIAL_Slicer;
77 * Function called upon receiving a message indicating a call to a @e method.
79 * This function is called one or more times for each message until all data
80 * fragments arrive from the network.
85 * Message part, as it arrived from the network.
87 * Message counter, monotonically increasing from 1.
89 * The sender of the message.
90 * Can be NULL if the message is not connected to a pseudonym.
92 * OR'ed GNUNET_PSYC_MessageFlags
94 * Original method name from PSYC.
95 * May be more specific than the registered method name due to
96 * try-and-slice matching.
99 (*GNUNET_SOCIAL_MethodCallback) (void *cls,
100 const struct GNUNET_PSYC_MessageMethod *msg,
103 const struct GNUNET_SOCIAL_Nym *nym,
104 const char *method_name);
108 * Function called upon receiving a modifier of a message.
113 * Message ID this data fragment belongs to.
115 * Message part, as it arrived from the network.
117 * Operation to perform.
118 * 0 in case of a modifier continuation.
120 * Name of the modifier.
121 * NULL in case of a modifier continuation.
123 * Value of the modifier.
128 (*GNUNET_SOCIAL_ModifierCallback) (void *cls,
129 const struct GNUNET_MessageHeader *msg,
131 enum GNUNET_ENV_Operator oper,
135 uint16_t full_value_size);
139 * Function called upon receiving a data fragment of a message.
144 * Message ID this data fragment belongs to.
146 * Message part, as it arrived from the network.
148 * Byte offset of @a data in the overall data of the method.
150 * Number of bytes in @a data.
152 * Data stream given to the method.
155 * #GNUNET_NO if there are further fragments,
156 * #GNUNET_YES if this is the last fragment,
157 * #GNUNET_SYSERR indicates the message was cancelled by the sender.
160 (*GNUNET_SOCIAL_DataCallback) (void *cls,
161 const struct GNUNET_MessageHeader *msg,
163 uint64_t data_offset,
174 * Message part, as it arrived from the network.
176 * Message ID this data fragment belongs to.
178 * #GNUNET_YES if the message was cancelled,
179 * #GNUNET_NO if the message is complete.
182 (*GNUNET_SOCIAL_EndOfMessageCallback) (void *cls,
183 const struct GNUNET_MessageHeader *msg,
189 * Create a try-and-slice instance.
191 * A slicer processes incoming messages and notifies callbacks about matching
192 * methods or modifiers encountered.
194 * @return A new try-and-slice construct.
196 struct GNUNET_SOCIAL_Slicer *
197 GNUNET_SOCIAL_slicer_create (void);
201 * Add a method to the try-and-slice instance.
203 * The callbacks are called for messages with a matching @a method_name prefix.
206 * The try-and-slice instance to extend.
208 * Name of the given method, use empty string to match all.
210 * Method handler invoked upon a matching message.
212 * Modifier handler, invoked after @a method_cb
213 * for each modifier in the message.
215 * Data handler, invoked after @a modifier_cb for each data fragment.
217 * Invoked upon reaching the end of a matching message.
219 * Closure for the callbacks.
222 GNUNET_SOCIAL_slicer_method_add (struct GNUNET_SOCIAL_Slicer *slicer,
223 const char *method_name,
224 GNUNET_SOCIAL_MethodCallback method_cb,
225 GNUNET_SOCIAL_ModifierCallback modifier_cb,
226 GNUNET_SOCIAL_DataCallback data_cb,
227 GNUNET_SOCIAL_EndOfMessageCallback eom_cb,
231 * Remove a registered method from the try-and-slice instance.
233 * Removes one matching handler registered with the given
234 * @a method_name and callbacks.
237 * The try-and-slice instance.
239 * Name of the method to remove.
247 * End of message handler.
249 * @return #GNUNET_OK if a method handler was removed,
250 * #GNUNET_NO if no handler matched the given method name and callbacks.
253 GNUNET_SOCIAL_slicer_method_remove (struct GNUNET_SOCIAL_Slicer *slicer,
254 const char *method_name,
255 GNUNET_SOCIAL_MethodCallback method_cb,
256 GNUNET_SOCIAL_ModifierCallback modifier_cb,
257 GNUNET_SOCIAL_DataCallback data_cb,
258 GNUNET_SOCIAL_EndOfMessageCallback eom_cb);
262 * Watch a place for changed objects.
265 * The try-and-slice instance.
266 * @param object_filter
267 * Object prefix to match.
269 * Function to call when encountering a state modifier.
271 * Closure for callback.
274 GNUNET_SOCIAL_slicer_modifier_add (struct GNUNET_SOCIAL_Slicer *slicer,
275 const char *object_filter,
276 GNUNET_SOCIAL_ModifierCallback modifier_cb,
281 * Remove a registered modifier from the try-and-slice instance.
283 * Removes one matching handler registered with the given
284 * @a object_filter and callback.
287 * The try-and-slice instance.
288 * @param object_filter
289 * Object prefix to match.
291 * Function to call when encountering a state modifier changes.
294 GNUNET_SOCIAL_slicer_modifier_remove (struct GNUNET_SOCIAL_Slicer *slicer,
295 const char *object_filter,
296 GNUNET_SOCIAL_ModifierCallback modifier_cb);
300 * Destroy a given try-and-slice instance.
306 GNUNET_SOCIAL_slicer_destroy (struct GNUNET_SOCIAL_Slicer *slicer);
310 * Function called asking for nym to be admitted to the place.
312 * Should call either GNUNET_SOCIAL_host_admit() or
313 * GNUNET_SOCIAL_host_reject_entry() (possibly asynchronously). If this host
314 * cannot decide, it is fine to call neither function, in which case hopefully
315 * some other host of the place exists that will make the decision. The @a nym
316 * reference remains valid until the #GNUNET_SOCIAL_FarewellCallback is invoked
319 * @param cls Closure.
320 * @param nym Handle for the user who wants to enter.
321 * @param method_name Method name in the entry request.
322 * @param variable_count Number of elements in the @a variables array.
323 * @param variables Variables present in the message.
324 * @param data_size Number of bytes in @a data.
325 * @param data Payload given on enter (e.g. a password).
328 (*GNUNET_SOCIAL_AnswerDoorCallback) (void *cls,
329 struct GNUNET_SOCIAL_Nym *nym,
330 const char *method_name,
331 struct GNUNET_ENV_Environment *env,
337 * Function called when a @a nym leaves the place.
339 * This is also called if the @a nym was never given permission to enter
340 * (i.e. the @a nym stopped asking to get in).
345 * Handle for the user who left.
348 (*GNUNET_SOCIAL_FarewellCallback) (void *cls,
349 const struct GNUNET_SOCIAL_Nym *nym,
350 struct GNUNET_ENV_Environment *env);
354 * Function called after the host entered the place.
359 * #GNUNET_OK on success, or
360 * #GNUNET_SYSERR on error.
361 * @param max_message_id
362 * Last message ID sent to the channel.
363 * Or 0 if no messages have been sent to the place yet.
366 (*GNUNET_SOCIAL_HostEnterCallback) (void *cls, int result,
367 uint64_t max_message_id);
371 * Enter a place as host.
373 * A place is created upon first entering, and it is active until permanently
374 * left using GNUNET_SOCIAL_host_leave().
377 * Configuration to contact the social service.
379 * Identity of the host.
381 * Private-public key pair of the place.
382 * NULL for ephemeral places.
384 * Policy specifying entry and history restrictions for the place.
386 * Slicer to handle incoming messages.
387 * @param answer_door_cb
388 * Function to handle new nyms that want to enter.
390 * Function to handle departing nyms.
392 * Closure for the callbacks.
394 * @return Handle for the host.
396 struct GNUNET_SOCIAL_Host *
397 GNUNET_SOCIAL_host_enter (const struct GNUNET_CONFIGURATION_Handle *cfg,
398 const struct GNUNET_IDENTITY_Ego *ego,
399 const struct GNUNET_CRYPTO_EddsaPrivateKey *place_key,
400 enum GNUNET_PSYC_Policy policy,
401 struct GNUNET_SOCIAL_Slicer *slicer,
402 GNUNET_SOCIAL_HostEnterCallback enter_cb,
403 GNUNET_SOCIAL_AnswerDoorCallback answer_door_cb,
404 GNUNET_SOCIAL_FarewellCallback farewell_cb,
409 * Decision whether to admit @a nym into the place or refuse entry.
414 * Handle for the entity that wanted to enter.
416 * #GNUNET_YES if @a nym is admitted,
417 * #GNUNET_NO if @a nym is refused entry,
418 * #GNUNET_SYSERR if we cannot answer the request.
420 * Method name for the rejection message.
422 * Environment containing variables for the message, or NULL.
424 * Data for the rejection message to send back.
426 * Number of bytes in @a data for method.
427 * @return #GNUNET_OK on success,
428 * #GNUNET_SYSERR if the message is too large.
431 GNUNET_SOCIAL_host_entry_decision (struct GNUNET_SOCIAL_Host *hst,
432 struct GNUNET_SOCIAL_Nym *nym,
434 const struct GNUNET_PSYC_Message *entry_resp);
438 * Throw @a nym out of the place.
440 * The @a nym reference will remain valid until the
441 * #GNUNET_SOCIAL_FarewellCallback is invoked,
442 * which should be very soon after this call.
447 * Handle for the entity to be ejected.
450 GNUNET_SOCIAL_host_eject (struct GNUNET_SOCIAL_Host *host,
451 const struct GNUNET_SOCIAL_Nym *nym);
455 * Get the public key of a @a nym.
457 * Suitable, for example, to be used with GNUNET_NAMESTORE_zone_to_name().
460 * Pseudonym to map to a cryptographic identifier.
462 * @return Public key of nym;
464 const struct GNUNET_CRYPTO_EcdsaPublicKey *
465 GNUNET_SOCIAL_nym_get_key (const struct GNUNET_SOCIAL_Nym *nym);
469 * Advertise the place in the GNS zone of the @e ego of the @a host.
471 * @param host Host of the place.
472 * @param name The name for the PLACE record to put in the zone.
473 * @param peer_count Number of elements in the @a peers array.
474 * @param peers List of peers in the PLACE record that can be used to send join
476 * @param expiration_time Expiration time of the record, use 0 to remove the record.
477 * @param password Password used to encrypt the record.
480 GNUNET_SOCIAL_host_advertise (struct GNUNET_SOCIAL_Host *host,
483 const struct GNUNET_PeerIdentity *peers,
484 struct GNUNET_TIME_Relative expiration_time,
485 const char *password);
489 * Flags for announcements by a host.
491 enum GNUNET_SOCIAL_AnnounceFlags
493 GNUNET_SOCIAL_ANNOUNCE_NONE = 0,
496 * Whether this announcement removes all objects from the place.
498 * New objects can be still added to the now empty place using the @e env
499 * parameter of the same announcement.
501 GNUNET_SOCIAL_ANNOUNCE_CLEAR_OBJECTS = 1 << 0
506 * Handle for an announcement request.
508 struct GNUNET_SOCIAL_Announcement;
512 * Send a message to all nyms that are present in the place.
514 * This function is restricted to the host. Nyms can only send requests
515 * to the host who can decide to relay it to everyone in the place.
520 * Method to use for the announcement.
522 * Environment containing variables for the message and operations
523 * on objects of the place.
524 * Has to remain available until the first call to @a notify_data.
527 * Function to call to get the payload of the announcement.
528 * @param notify_data_cls
529 * Closure for @a notify.
531 * Flags for this announcement.
533 * @return NULL on error (another announcement already in progress?).
535 struct GNUNET_SOCIAL_Announcement *
536 GNUNET_SOCIAL_host_announce (struct GNUNET_SOCIAL_Host *host,
537 const char *method_name,
538 const struct GNUNET_ENV_Environment *env,
539 GNUNET_PSYC_TransmitNotifyData notify_data,
540 void *notify_data_cls,
541 enum GNUNET_SOCIAL_AnnounceFlags flags);
545 * Resume transmitting announcement.
548 * The announcement to resume.
551 GNUNET_SOCIAL_host_announce_resume (struct GNUNET_SOCIAL_Announcement *a);
555 * Cancel announcement.
558 * The announcement to cancel.
561 GNUNET_SOCIAL_host_announce_cancel (struct GNUNET_SOCIAL_Announcement *a);
565 * Obtain handle for a hosted place.
567 * The returned handle can be used to access the place API.
570 * Handle for the host.
572 * @return Handle for the hosted place, valid as long as @a host is valid.
574 struct GNUNET_SOCIAL_Place *
575 GNUNET_SOCIAL_host_get_place (struct GNUNET_SOCIAL_Host *host);
579 * Stop hosting a place.
581 * Invalidates host handle.
584 * Host leaving the place.
586 * Keep the place active after last host disconnected.
588 * Function called after the host left the place
589 * and disconnected from the social service.
591 * Closure for @a leave_cb.
594 GNUNET_SOCIAL_host_leave (struct GNUNET_SOCIAL_Host *host,
596 GNUNET_ContinuationCallback leave_cb,
601 * Function called after the guest entered the local copy of the place.
603 * History and object query functions can be used after this call,
604 * but new messages can't be sent or received.
609 * #GNUNET_OK on success, or
610 * #GNUNET_SYSERR on error, e.g. could not connect to the service, or
611 * could not resolve GNS name.
612 * @param max_message_id
613 * Last message ID sent to the place.
614 * Or 0 if no messages have been sent to the place yet.
617 (*GNUNET_SOCIAL_GuestEnterCallback) (void *cls, int result,
618 uint64_t max_message_id);
622 * Function called upon a guest receives a decision about entry to the place.
625 * Is the guest admitted to the place?
626 * #GNUNET_YES if admitted,
627 * #GNUNET_NO if refused entry
628 * #GNUNET_SYSERR if the request could not be answered.
630 * Method for the message sent along with the decision.
631 * NULL if no message was sent.
633 * Environment with variables for the message.
634 * NULL if there are no variables.
635 * It has to be freed using GNUNET_ENV_environment_destroy()
636 * when it is not needed anymore.
640 * Payload of the message.
643 (*GNUNET_SOCIAL_EntryDecisionCallback) (void *cls,
645 const struct GNUNET_PSYC_Message *entry_resp);
649 * Request entry to a place as a guest.
651 * @param cfg Configuration to contact the social service.
652 * @param ego Identity of the guest.
653 * @param crypto_address Public key of the place to enter.
654 * @param origin Peer identity of the origin of the underlying multicast group.
655 * @param relay_count Number of elements in the @a relays array.
656 * @param relays Relays for the underlying multicast group.
657 * @param method_name Method name for the message.
658 * @param env Environment containing variables for the message, or NULL.
659 * @param data Payload for the message to give to the enter callback.
660 * @param data_size Number of bytes in @a data.
661 * @param slicer Slicer to use for processing incoming requests from guests.
663 * @return NULL on errors, otherwise handle for the guest.
665 struct GNUNET_SOCIAL_Guest *
666 GNUNET_SOCIAL_guest_enter (const struct GNUNET_CONFIGURATION_Handle *cfg,
667 const struct GNUNET_IDENTITY_Ego *ego,
668 const struct GNUNET_CRYPTO_EddsaPublicKey *place_key,
669 const struct GNUNET_PeerIdentity *origin,
670 uint32_t relay_count,
671 const struct GNUNET_PeerIdentity *relays,
672 const struct GNUNET_PSYC_Message *entry_msg,
673 struct GNUNET_SOCIAL_Slicer *slicer,
674 GNUNET_SOCIAL_GuestEnterCallback local_enter_cb,
675 GNUNET_SOCIAL_EntryDecisionCallback entry_decision_cb,
680 * Request entry to a place as a guest using a GNS name.
682 * @param cfg Configuration to contact the social service.
683 * @param ego Identity of the guest.
684 * @param address GNS name of the place to enter. Either in the form of
685 * 'room.friend.gnu', or 'NYMPUBKEY.zkey'. This latter case refers to
686 * the 'PLACE' record of the empty label ("+") in the GNS zone with the
687 * nym's public key 'NYMPUBKEY', and can be used to request entry to a
688 * pseudonym's place directly.
689 * @param method_name Method name for the message.
690 * @param env Environment containing variables for the message, or NULL.
691 * @param data Payload for the message to give to the enter callback.
692 * @param data_size Number of bytes in @a data.
693 * @param slicer Slicer to use for processing incoming requests from guests.
695 * @return NULL on errors, otherwise handle for the guest.
697 struct GNUNET_SOCIAL_Guest *
698 GNUNET_SOCIAL_guest_enter_by_name (const struct GNUNET_CONFIGURATION_Handle *cfg,
699 struct GNUNET_IDENTITY_Ego *ego,
701 const struct GNUNET_PSYC_Message *join_msg,
702 struct GNUNET_SOCIAL_Slicer *slicer,
703 GNUNET_SOCIAL_GuestEnterCallback local_enter_cb,
704 GNUNET_SOCIAL_EntryDecisionCallback entry_decision_cb,
709 * Flags for talking to the host of a place.
711 enum GNUNET_SOCIAL_TalkFlags
713 GNUNET_SOCIAL_TALK_NONE = 0
720 struct GNUNET_SOCIAL_TalkRequest;
724 * Talk to the host of the place.
727 * Place where we want to talk to the host.
729 * Method to invoke on the host.
731 * Environment containing variables for the message, or NULL.
733 * Function to use to get the payload for the method.
734 * @param notify_data_cls
735 * Closure for @a notify_data.
737 * Flags for the message being sent.
739 * @return NULL if we are already trying to talk to the host,
740 * otherwise handle to cancel the request.
742 struct GNUNET_SOCIAL_TalkRequest *
743 GNUNET_SOCIAL_guest_talk (struct GNUNET_SOCIAL_Guest *guest,
744 const char *method_name,
745 const struct GNUNET_ENV_Environment *env,
746 GNUNET_PSYC_TransmitNotifyData notify_data,
747 void *notify_data_cls,
748 enum GNUNET_SOCIAL_TalkFlags flags);
752 * Resume talking to the host of the place.
755 * Talk request to resume.
758 GNUNET_SOCIAL_guest_talk_resume (struct GNUNET_SOCIAL_TalkRequest *tr);
762 * Cancel talking to the host of the place.
765 * Talk request to cancel.
768 GNUNET_SOCIAL_guest_talk_cancel (struct GNUNET_SOCIAL_TalkRequest *tr);
772 * Leave a place temporarily or permanently.
774 * Notifies the owner of the place about leaving, and destroys the place handle.
779 * Keep place active after last application disconnected.
780 * #GNUNET_YES or #GNUNET_NO
782 * Optional environment for the leave message if @a keep_active
783 * is #GNUNET_NO. NULL if not needed.
785 * Called upon disconnecting from the social service.
788 GNUNET_SOCIAL_guest_leave (struct GNUNET_SOCIAL_Guest *gst,
790 struct GNUNET_ENV_Environment *env,
791 GNUNET_ContinuationCallback leave_cb,
796 * Obtain handle for a place entered as guest.
798 * The returned handle can be used to access the place API.
800 * @param guest Handle for the guest.
802 * @return Handle for the place, valid as long as @a guest is valid.
804 struct GNUNET_SOCIAL_Place *
805 GNUNET_SOCIAL_guest_get_place (struct GNUNET_SOCIAL_Guest *guest);
811 struct GNUNET_SOCIAL_HistoryRequest;
815 * Learn about the history of a place.
817 * Messages are returned through the @a slicer function
818 * and have the #GNUNET_PSYC_MESSAGE_HISTORIC flag set.
821 * Place we want to learn more about.
822 * @param start_message_id
823 * First historic message we are interested in.
824 * @param end_message_id
825 * Last historic message we are interested in (inclusive).
826 * @param method_prefix
827 * Only retrieve messages with this method prefix.
829 * OR'ed GNUNET_PSYC_HistoryReplayFlags
831 * Slicer to use for retrieved messages.
832 * Can be the same as the slicer of the place.
834 * Function called after all messages retrieved.
835 * NULL if not needed.
836 * @param cls Closure for @a result_cb.
838 struct GNUNET_SOCIAL_HistoryRequest *
839 GNUNET_SOCIAL_place_history_replay (struct GNUNET_SOCIAL_Place *plc,
840 uint64_t start_message_id,
841 uint64_t end_message_id,
842 const char *method_prefix,
844 struct GNUNET_SOCIAL_Slicer *slicer,
845 GNUNET_ResultCallback result_cb,
850 * Learn about the history of a place.
852 * Sends messages through the slicer function of the place where
853 * start_message_id <= message_id <= end_message_id.
854 * The messages will have the #GNUNET_PSYC_MESSAGE_HISTORIC flag set.
856 * To get the latest message, use 0 for both the start and end message ID.
859 * Place we want to learn more about.
860 * @param message_limit
861 * Maximum number of historic messages we are interested in.
863 * Function called after all messages retrieved.
864 * NULL if not needed.
865 * @param cls Closure for @a result_cb.
867 struct GNUNET_SOCIAL_HistoryRequest *
868 GNUNET_SOCIAL_place_history_replay_latest (struct GNUNET_SOCIAL_Place *plc,
869 uint64_t message_limit,
870 const char *method_prefix,
872 struct GNUNET_SOCIAL_Slicer *slicer,
873 GNUNET_ResultCallback result_cb,
877 * Cancel learning about the history of a place.
880 * History lesson to cancel.
883 GNUNET_SOCIAL_place_history_replay_cancel (struct GNUNET_SOCIAL_HistoryRequest *hist);
886 struct GNUNET_SOCIAL_LookHandle;
890 * Look at a particular object in the place.
892 * The best matching object is returned (its name might be less specific than
893 * what was requested).
896 * The place to look the object at.
898 * Full name of the object.
900 * Set to the size of the returned value.
902 * @return NULL if there is no such object at this place.
904 struct GNUNET_SOCIAL_LookHandle *
905 GNUNET_SOCIAL_place_look_at (struct GNUNET_SOCIAL_Place *plc,
906 const char *full_name,
907 GNUNET_PSYC_StateVarCallback var_cb,
908 GNUNET_ResultCallback result_cb,
912 * Look for objects in the place with a matching name prefix.
915 * The place to look its objects at.
917 * Look at objects with names beginning with this value.
919 * Function to call for each object found.
921 * Closure for callback function.
923 * @return Handle that can be used to stop looking at objects.
925 struct GNUNET_SOCIAL_LookHandle *
926 GNUNET_SOCIAL_place_look_for (struct GNUNET_SOCIAL_Place *plc,
927 const char *name_prefix,
928 GNUNET_PSYC_StateVarCallback var_cb,
929 GNUNET_ResultCallback result_cb,
934 * Stop looking at objects.
936 * @param lh Look handle to stop.
939 GNUNET_SOCIAL_place_look_cancel (struct GNUNET_SOCIAL_LookHandle *lh);
942 #if 0 /* keep Emacsens' auto-indent happy */
949 /* ifndef GNUNET_SOCIAL_SERVICE_H */
951 /* end of gnunet_social_service.h */