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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, 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 data fragment of a message.
113 * Message ID this data fragment belongs to.
115 * Message part, as it arrived from the network.
117 * Operation to perform.
119 * Name of the modifier.
121 * Value of the modifier.
126 (*GNUNET_SOCIAL_ModifierCallback) (void *cls,
127 const struct GNUNET_PSYC_MessageModifier *msg,
129 enum GNUNET_ENV_Operator oper,
132 uint16_t value_size);
136 * Function called upon receiving a data fragment of a message.
141 * Message ID this data fragment belongs to.
143 * Message part, as it arrived from the network.
145 * Byte offset of @a data in the overall data of the method.
147 * Number of bytes in @a data.
149 * Data stream given to the method.
152 * #GNUNET_NO if there are further fragments,
153 * #GNUNET_YES if this is the last fragment,
154 * #GNUNET_SYSERR indicates the message was cancelled by the sender.
157 (*GNUNET_SOCIAL_DataCallback) (void *cls,
158 const struct GNUNET_MessageHeader *msg,
160 uint64_t data_offset,
171 * Message part, as it arrived from the network.
173 * Message ID this data fragment belongs to.
175 * #GNUNET_YES if the message was cancelled,
176 * #GNUNET_NO if the message is complete.
179 (*GNUNET_SOCIAL_EndOfMessageCallback) (void *cls,
180 const struct GNUNET_MessageHeader *msg,
186 * Create a try-and-slice instance.
188 * @return A new try-and-slice construct.
190 struct GNUNET_SOCIAL_Slicer *
191 GNUNET_SOCIAL_slicer_create (void);
195 * Add a method to the try-and-slice instance.
197 * A slicer processes messages and calls methods that match a message. A match
198 * happens whenever the method name of a message starts with the method_name
199 * parameter given here.
201 * @param slicer The try-and-slice instance to extend.
202 * @param method_name Name of the given method, use empty string for default.
203 * @param method Method to invoke.
204 * @param method_cls Closure for method.
207 GNUNET_SOCIAL_slicer_add (struct GNUNET_SOCIAL_Slicer *slicer,
208 const char *method_name,
209 GNUNET_SOCIAL_MethodCallback method_cb,
210 GNUNET_SOCIAL_ModifierCallback modifier_cb,
211 GNUNET_SOCIAL_DataCallback data_cb,
212 GNUNET_SOCIAL_EndOfMessageCallback eom_cb,
217 * Remove a registered method handler from the try-and-slice instance.
219 * @param slicer The try-and-slice instance.
220 * @param method_name Name of the method to remove.
221 * @param method Method handler.
224 GNUNET_SOCIAL_slicer_remove (struct GNUNET_SOCIAL_Slicer *slicer,
225 const char *method_name,
226 GNUNET_SOCIAL_MethodCallback method_cb,
227 GNUNET_SOCIAL_ModifierCallback modifier_cb,
228 GNUNET_SOCIAL_DataCallback data_cb,
229 GNUNET_SOCIAL_EndOfMessageCallback eom_cb);
233 * Destroy a given try-and-slice instance.
235 * @param slicer slicer to destroy
238 GNUNET_SOCIAL_slicer_destroy (struct GNUNET_SOCIAL_Slicer *slicer);
242 * Function called asking for nym to be admitted to the place.
244 * Should call either GNUNET_SOCIAL_host_admit() or
245 * GNUNET_SOCIAL_host_reject_entry() (possibly asynchronously). If this host
246 * cannot decide, it is fine to call neither function, in which case hopefully
247 * some other host of the place exists that will make the decision. The @a nym
248 * reference remains valid until the #GNUNET_SOCIAL_FarewellCallback is invoked
251 * @param cls Closure.
252 * @param nym Handle for the user who wants to enter.
253 * @param method_name Method name in the entry request.
254 * @param variable_count Number of elements in the @a variables array.
255 * @param variables Variables present in the message.
256 * @param data_size Number of bytes in @a data.
257 * @param data Payload given on enter (e.g. a password).
260 (*GNUNET_SOCIAL_AnswerDoorCallback) (void *cls,
261 struct GNUNET_SOCIAL_Nym *nym,
262 const char *method_name,
263 struct GNUNET_ENV_Environment *env,
269 * Function called when a @a nym leaves the place.
271 * This is also called if the @a nym was never given permission to enter
272 * (i.e. the @a nym stopped asking to get in).
274 * @param cls Closure.
275 * @param nym Handle for the user who left.
276 * @param variable_count Number of elements in the @a variables array.
277 * @param variables Variables present in the message.
280 (*GNUNET_SOCIAL_FarewellCallback) (void *cls,
281 struct GNUNET_SOCIAL_Nym *nym,
282 struct GNUNET_ENV_Environment *env,
283 size_t variable_count,
284 struct GNUNET_ENV_Modifier *variables);
288 * Function called after the host entered the place.
293 * #GNUNET_OK on success, or
294 * #GNUNET_SYSERR on error.
295 * @param max_message_id
296 * Last message ID sent to the channel.
297 * Or 0 if no messages have been sent to the place yet.
300 (*GNUNET_SOCIAL_HostEnterCallback) (void *cls, int result,
301 uint64_t max_message_id);
305 * Enter a place as host.
307 * A place is created upon first entering, and it is active until permanently
308 * left using GNUNET_SOCIAL_host_leave().
311 * Configuration to contact the social service.
313 * Identity of the host.
315 * Private-public key pair of the place.
316 * NULL for ephemeral places.
318 * Policy specifying entry and history restrictions for the place.
320 * Slicer to handle incoming messages.
321 * @param answer_door_cb
322 * Function to handle new nyms that want to enter.
324 * Function to handle departing nyms.
326 * Closure for the callbacks.
328 * @return Handle for the host.
330 struct GNUNET_SOCIAL_Host *
331 GNUNET_SOCIAL_host_enter (const struct GNUNET_CONFIGURATION_Handle *cfg,
332 const struct GNUNET_IDENTITY_Ego *ego,
333 const struct GNUNET_CRYPTO_EddsaPrivateKey *place_key,
334 enum GNUNET_PSYC_Policy policy,
335 struct GNUNET_SOCIAL_Slicer *slicer,
336 GNUNET_SOCIAL_HostEnterCallback enter_cb,
337 GNUNET_SOCIAL_AnswerDoorCallback answer_door_cb,
338 GNUNET_SOCIAL_FarewellCallback farewell_cb,
343 * Decision whether to admit @a nym into the place or refuse entry.
348 * Handle for the entity that wanted to enter.
350 * #GNUNET_YES if @a nym is admitted,
351 * #GNUNET_NO if @a nym is refused entry,
352 * #GNUNET_SYSERR if we cannot answer the request.
354 * Method name for the rejection message.
356 * Environment containing variables for the message, or NULL.
358 * Data for the rejection message to send back.
360 * Number of bytes in @a data for method.
361 * @return #GNUNET_OK on success,
362 * #GNUNET_SYSERR if the message is too large.
365 GNUNET_SOCIAL_host_entry_decision (struct GNUNET_SOCIAL_Host *hst,
366 struct GNUNET_SOCIAL_Nym *nym,
368 const struct GNUNET_PSYC_Message *entry_resp);
372 * Throw @a nym out of the place.
374 * The @a nym reference will remain valid until the
375 * #GNUNET_SOCIAL_FarewellCallback is invoked,
376 * which should be very soon after this call.
378 * @param host Host of the place.
379 * @param nym Handle for the entity to be ejected.
382 GNUNET_SOCIAL_host_eject (struct GNUNET_SOCIAL_Host *host,
383 struct GNUNET_SOCIAL_Nym *nym);
387 * Get the public key of a @a nym.
389 * Suitable, for example, to be used with GNUNET_NAMESTORE_zone_to_name().
392 * Pseudonym to map to a cryptographic identifier.
394 * @return Public key of nym;
396 struct GNUNET_CRYPTO_EcdsaPublicKey *
397 GNUNET_SOCIAL_nym_get_key (struct GNUNET_SOCIAL_Nym *nym);
401 * Obtain the private-public key pair of the host.
403 * @param host Host to get the key of.
404 * @param[out] host_key Set to the private-public key pair of the host. The
405 * public part is suitable for storing in GNS within a "PLACE"
406 * record, along with peer IDs to join at.
409 GNUNET_SOCIAL_host_get_key (struct GNUNET_SOCIAL_Host *host,
410 struct GNUNET_CRYPTO_EddsaPrivateKey *host_key);
414 * Advertise the place in the GNS zone of the @e ego of the @a host.
416 * @param host Host of the place.
417 * @param name The name for the PLACE record to put in the zone.
418 * @param peer_count Number of elements in the @a peers array.
419 * @param peers List of peers in the PLACE record that can be used to send join
421 * @param expiration_time Expiration time of the record, use 0 to remove the record.
422 * @param password Password used to encrypt the record.
425 GNUNET_SOCIAL_host_advertise (struct GNUNET_SOCIAL_Host *host,
428 const struct GNUNET_PeerIdentity *peers,
429 struct GNUNET_TIME_Relative expiration_time,
430 const char *password);
434 * Flags for announcements by a host.
436 enum GNUNET_SOCIAL_AnnounceFlags
438 GNUNET_SOCIAL_ANNOUNCE_NONE = 0,
441 * Whether this announcement removes all objects from the place.
443 * New objects can be still added to the now empty place using the @e env
444 * parameter of the same announcement.
446 GNUNET_SOCIAL_ANNOUNCE_CLEAR_OBJECTS = 1 << 0
451 * Handle for an announcement request.
453 struct GNUNET_SOCIAL_Announcement;
457 * Send a message to all nyms that are present in the place.
459 * This function is restricted to the host. Nyms can only send requests
460 * to the host who can decide to relay it to everyone in the place.
465 * Method to use for the announcement.
467 * Environment containing variables for the message and operations
468 * on objects of the place.
469 * Has to remain available until the first call to @a notify_data.
472 * Function to call to get the payload of the announcement.
473 * @param notify_data_cls
474 * Closure for @a notify.
476 * Flags for this announcement.
478 * @return NULL on error (another announcement already in progress?).
480 struct GNUNET_SOCIAL_Announcement *
481 GNUNET_SOCIAL_host_announce (struct GNUNET_SOCIAL_Host *host,
482 const char *method_name,
483 const struct GNUNET_ENV_Environment *env,
484 GNUNET_PSYC_TransmitNotifyData notify_data,
485 void *notify_data_cls,
486 enum GNUNET_SOCIAL_AnnounceFlags flags);
490 * Resume transmitting announcement.
493 * The announcement to resume.
496 GNUNET_SOCIAL_host_announce_resume (struct GNUNET_SOCIAL_Announcement *a);
500 * Cancel announcement.
503 * The announcement to cancel.
506 GNUNET_SOCIAL_host_announce_cancel (struct GNUNET_SOCIAL_Announcement *a);
510 * Obtain handle for a hosted place.
512 * The returned handle can be used to access the place API.
515 * Handle for the host.
517 * @return Handle for the hosted place, valid as long as @a host is valid.
519 struct GNUNET_SOCIAL_Place *
520 GNUNET_SOCIAL_host_get_place (struct GNUNET_SOCIAL_Host *host);
524 * Stop hosting a place.
526 * Invalidates host handle.
529 * Host leaving the place.
531 * Keep the place active after last host disconnected.
533 * Function called after the host left the place
534 * and disconnected from the social service.
536 * Closure for @a leave_cb.
539 GNUNET_SOCIAL_host_leave (struct GNUNET_SOCIAL_Host *host,
541 GNUNET_ContinuationCallback leave_cb,
546 * Function called after the guest entered the local copy of the place.
548 * History and object query functions can be used after this call,
549 * but new messages can't be sent or received.
554 * #GNUNET_OK on success, or
555 * #GNUNET_SYSERR on error, e.g. could not connect to the service, or
556 * could not resolve GNS name.
557 * @param max_message_id
558 * Last message ID sent to the place.
559 * Or 0 if no messages have been sent to the place yet.
562 (*GNUNET_SOCIAL_GuestEnterCallback) (void *cls, int result,
563 uint64_t max_message_id);
567 * Function called upon a guest receives a decision about entry to the place.
570 * Is the guest admitted to the place?
571 * #GNUNET_YES if admitted,
572 * #GNUNET_NO if refused entry
573 * #GNUNET_SYSERR if the request could not be answered.
575 * Method for the message sent along with the decision.
576 * NULL if no message was sent.
578 * Environment with variables for the message.
579 * NULL if there are no variables.
580 * It has to be freed using GNUNET_ENV_environment_destroy()
581 * when it is not needed anymore.
585 * Payload of the message.
588 (*GNUNET_SOCIAL_EntryDecisionCallback) (void *cls,
590 const struct GNUNET_PSYC_Message *entry_resp);
594 * Request entry to a place as a guest.
596 * @param cfg Configuration to contact the social service.
597 * @param ego Identity of the guest.
598 * @param crypto_address Public key of the place to enter.
599 * @param origin Peer identity of the origin of the underlying multicast group.
600 * @param relay_count Number of elements in the @a relays array.
601 * @param relays Relays for the underlying multicast group.
602 * @param method_name Method name for the message.
603 * @param env Environment containing variables for the message, or NULL.
604 * @param data Payload for the message to give to the enter callback.
605 * @param data_size Number of bytes in @a data.
606 * @param slicer Slicer to use for processing incoming requests from guests.
608 * @return NULL on errors, otherwise handle for the guest.
610 struct GNUNET_SOCIAL_Guest *
611 GNUNET_SOCIAL_guest_enter (const struct GNUNET_CONFIGURATION_Handle *cfg,
612 const struct GNUNET_IDENTITY_Ego *ego,
613 const struct GNUNET_CRYPTO_EddsaPublicKey *place_key,
614 const struct GNUNET_PeerIdentity *origin,
615 uint32_t relay_count,
616 const struct GNUNET_PeerIdentity *relays,
617 const struct GNUNET_PSYC_Message *entry_msg,
618 struct GNUNET_SOCIAL_Slicer *slicer,
619 GNUNET_SOCIAL_GuestEnterCallback local_enter_cb,
620 GNUNET_SOCIAL_EntryDecisionCallback entry_decision_cb,
625 * Request entry to a place as a guest using a GNS name.
627 * @param cfg Configuration to contact the social service.
628 * @param ego Identity of the guest.
629 * @param address GNS name of the place to enter. Either in the form of
630 * 'room.friend.gnu', or 'NYMPUBKEY.zkey'. This latter case refers to
631 * the 'PLACE' record of the empty label ("+") in the GNS zone with the
632 * nym's public key 'NYMPUBKEY', and can be used to request entry to a
633 * pseudonym's place directly.
634 * @param method_name Method name for the message.
635 * @param env Environment containing variables for the message, or NULL.
636 * @param data Payload for the message to give to the enter callback.
637 * @param data_size Number of bytes in @a data.
638 * @param slicer Slicer to use for processing incoming requests from guests.
640 * @return NULL on errors, otherwise handle for the guest.
642 struct GNUNET_SOCIAL_Guest *
643 GNUNET_SOCIAL_guest_enter_by_name (const struct GNUNET_CONFIGURATION_Handle *cfg,
644 struct GNUNET_IDENTITY_Ego *ego,
646 const struct GNUNET_PSYC_Message *join_msg,
647 struct GNUNET_SOCIAL_Slicer *slicer,
648 GNUNET_SOCIAL_GuestEnterCallback local_enter_cb,
649 GNUNET_SOCIAL_EntryDecisionCallback entry_decision_cb,
654 * Flags for talking to the host of a place.
656 enum GNUNET_SOCIAL_TalkFlags
658 GNUNET_SOCIAL_TALK_NONE = 0
665 struct GNUNET_SOCIAL_TalkRequest;
669 * Talk to the host of the place.
672 * Place where we want to talk to the host.
674 * Method to invoke on the host.
676 * Environment containing variables for the message, or NULL.
678 * Function to use to get the payload for the method.
679 * @param notify_data_cls
680 * Closure for @a notify_data.
682 * Flags for the message being sent.
684 * @return NULL if we are already trying to talk to the host,
685 * otherwise handle to cancel the request.
687 struct GNUNET_SOCIAL_TalkRequest *
688 GNUNET_SOCIAL_guest_talk (struct GNUNET_SOCIAL_Guest *guest,
689 const char *method_name,
690 const struct GNUNET_ENV_Environment *env,
691 GNUNET_PSYC_TransmitNotifyData notify_data,
692 void *notify_data_cls,
693 enum GNUNET_SOCIAL_TalkFlags flags);
697 * Resume talking to the host of the place.
700 * Talk request to resume.
703 GNUNET_SOCIAL_guest_talk_resume (struct GNUNET_SOCIAL_TalkRequest *tr);
707 * Cancel talking to the host of the place.
710 * Talk request to cancel.
713 GNUNET_SOCIAL_guest_talk_cancel (struct GNUNET_SOCIAL_TalkRequest *tr);
717 * Leave a place permanently.
719 * Notifies the owner of the place about leaving, and destroys the place handle.
722 * Place to leave permanently.
724 * Keep place active after last application disconnected.
726 * Function called after the guest left the place
727 * and disconnected from the social service.
729 * Closure for @a leave_cb.
732 GNUNET_SOCIAL_guest_leave (struct GNUNET_SOCIAL_Guest *guest,
734 GNUNET_ContinuationCallback leave_cb,
739 * Obtain handle for a place entered as guest.
741 * The returned handle can be used to access the place API.
743 * @param guest Handle for the guest.
745 * @return Handle for the place, valid as long as @a guest is valid.
747 struct GNUNET_SOCIAL_Place *
748 GNUNET_SOCIAL_guest_get_place (struct GNUNET_SOCIAL_Guest *guest);
754 struct GNUNET_SOCIAL_HistoryRequest;
758 * Learn about the history of a place.
760 * Messages are returned through the @a slicer function
761 * and have the #GNUNET_PSYC_MESSAGE_HISTORIC flag set.
764 * Place we want to learn more about.
765 * @param start_message_id
766 * First historic message we are interested in.
767 * @param end_message_id
768 * Last historic message we are interested in (inclusive).
769 * @param method_prefix
770 * Only retrieve messages with this method prefix.
772 * OR'ed GNUNET_PSYC_HistoryReplayFlags
774 * Slicer to use for retrieved messages.
775 * Can be the same as the slicer of the place.
777 * Function called after all messages retrieved.
778 * NULL if not needed.
779 * @param cls Closure for @a result_cb.
781 struct GNUNET_SOCIAL_HistoryRequest *
782 GNUNET_SOCIAL_place_history_replay (struct GNUNET_SOCIAL_Place *plc,
783 uint64_t start_message_id,
784 uint64_t end_message_id,
785 const char *method_prefix,
787 struct GNUNET_SOCIAL_Slicer *slicer,
788 GNUNET_ResultCallback result_cb,
793 * Learn about the history of a place.
795 * Sends messages through the slicer function of the place where
796 * start_message_id <= message_id <= end_message_id.
797 * The messages will have the #GNUNET_PSYC_MESSAGE_HISTORIC flag set.
799 * To get the latest message, use 0 for both the start and end message ID.
802 * Place we want to learn more about.
803 * @param message_limit
804 * Maximum number of historic messages we are interested in.
806 * Function called after all messages retrieved.
807 * NULL if not needed.
808 * @param cls Closure for @a result_cb.
810 struct GNUNET_SOCIAL_HistoryRequest *
811 GNUNET_SOCIAL_place_history_replay_latest (struct GNUNET_SOCIAL_Place *plc,
812 uint64_t message_limit,
813 const char *method_prefix,
815 struct GNUNET_SOCIAL_Slicer *slicer,
816 GNUNET_ResultCallback result_cb,
820 * Cancel learning about the history of a place.
823 * History lesson to cancel.
826 GNUNET_SOCIAL_place_history_replay_cancel (struct GNUNET_SOCIAL_HistoryRequest *hist);
829 struct GNUNET_SOCIAL_WatchHandle;
832 * Watch a place for changed objects.
836 * @param object_filter
837 * Object prefix to match.
839 * Function to call when an object/state var changes.
841 * Closure for callback.
843 * @return Handle that can be used to cancel watching.
845 struct GNUNET_SOCIAL_WatchHandle *
846 GNUNET_SOCIAL_place_watch (struct GNUNET_SOCIAL_Place *place,
847 const char *object_filter,
848 GNUNET_PSYC_StateVarCallback var_cb,
853 * Cancel watching a place for changed objects.
855 * @param wh Watch handle to cancel.
858 GNUNET_SOCIAL_place_watch_cancel (struct GNUNET_SOCIAL_WatchHandle *wh);
861 struct GNUNET_SOCIAL_LookHandle;
865 * Look at a particular object in the place.
867 * The best matching object is returned (its name might be less specific than
868 * what was requested).
871 * The place to look the object at.
873 * Full name of the object.
875 * Set to the size of the returned value.
877 * @return NULL if there is no such object at this place.
879 struct GNUNET_SOCIAL_LookHandle *
880 GNUNET_SOCIAL_place_look_at (struct GNUNET_SOCIAL_Place *plc,
881 const char *full_name,
882 GNUNET_PSYC_StateVarCallback var_cb,
883 GNUNET_ResultCallback result_cb,
887 * Look for objects in the place with a matching name prefix.
890 * The place to look its objects at.
892 * Look at objects with names beginning with this value.
894 * Function to call for each object found.
896 * Closure for callback function.
898 * @return Handle that can be used to stop looking at objects.
900 struct GNUNET_SOCIAL_LookHandle *
901 GNUNET_SOCIAL_place_look_for (struct GNUNET_SOCIAL_Place *plc,
902 const char *name_prefix,
903 GNUNET_PSYC_StateVarCallback var_cb,
904 GNUNET_ResultCallback result_cb,
909 * Stop looking at objects.
911 * @param lh Look handle to stop.
914 GNUNET_SOCIAL_place_look_cancel (struct GNUNET_SOCIAL_LookHandle *lh);
917 #if 0 /* keep Emacsens' auto-indent happy */
924 /* ifndef GNUNET_SOCIAL_SERVICE_H */
926 /* end of gnunet_social_service.h */