2 This file is part of GNUnet.
3 (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 counter, monotonically increasing from 1.
87 * The sender of the message.
88 * Can be NULL if the message is not connected to a pseudonym.
90 * OR'ed GNUNET_PSYC_MessageFlags
92 * Original method name from PSYC.
93 * May be more specific than the registered method name due to
94 * try-and-slice matching.
96 * Environment with operations and variables for the message.
97 * Only set for the first call of this function for each @a message_id,
98 * NULL when notifying about further data fragments.
99 * It has to be freed using GNUNET_ENV_environment_destroy()
100 * when it is not needed anymore.
102 * Byte offset of @a data in the overall data of the method.
104 * Number of bytes in @a data.
106 * Data stream given to the method.
109 * #GNUNET_NO if there are further fragments,
110 * #GNUNET_YES if this is the last fragment,
111 * #GNUNET_SYSERR indicates the message was cancelled by the sender.
114 (*GNUNET_SOCIAL_MethodCallback) (void *cls,
117 const struct GNUNET_SOCIAL_Nym *nym,
118 const char *method_name,
119 struct GNUNET_ENV_Environment *env,
120 uint64_t data_offset,
127 * Create a try-and-slice instance.
129 * @return A new try-and-slice construct.
131 struct GNUNET_SOCIAL_Slicer *
132 GNUNET_SOCIAL_slicer_create (void);
136 * Add a method to the try-and-slice instance.
138 * A slicer processes messages and calls methods that match a message. A match
139 * happens whenever the method name of a message starts with the method_name
140 * parameter given here.
142 * @param slicer The try-and-slice instance to extend.
143 * @param method_name Name of the given method, use empty string for default.
144 * @param method Method to invoke.
145 * @param method_cls Closure for method.
148 GNUNET_SOCIAL_slicer_add (struct GNUNET_SOCIAL_Slicer *slicer,
149 const char *method_name,
150 GNUNET_SOCIAL_MethodCallback method_cb,
155 * Remove a registered method from the try-and-slice instance.
157 * @param slicer The try-and-slice instance.
158 * @param method_name Name of the method to remove.
159 * @param method Method handler.
162 GNUNET_SOCIAL_slicer_remove (struct GNUNET_SOCIAL_Slicer *slicer,
163 const char *method_name,
164 GNUNET_SOCIAL_MethodCallback method_cb);
167 * Destroy a given try-and-slice instance.
169 * @param slicer slicer to destroy
172 GNUNET_SOCIAL_slicer_destroy (struct GNUNET_SOCIAL_Slicer *slicer);
176 * Function called asking for nym to be admitted to the place.
178 * Should call either GNUNET_SOCIAL_host_admit() or
179 * GNUNET_SOCIAL_host_reject_entry() (possibly asynchronously). If this host
180 * cannot decide, it is fine to call neither function, in which case hopefully
181 * some other host of the place exists that will make the decision. The @a nym
182 * reference remains valid until the #GNUNET_SOCIAL_FarewellCallback is invoked
185 * @param cls Closure.
186 * @param nym Handle for the user who wants to enter.
187 * @param method_name Method name in the entry request.
188 * @param variable_count Number of elements in the @a variables array.
189 * @param variables Variables present in the message.
190 * @param data_size Number of bytes in @a data.
191 * @param data Payload given on enter (e.g. a password).
194 (*GNUNET_SOCIAL_AnswerDoorCallback) (void *cls,
195 struct GNUNET_SOCIAL_Nym *nym,
196 const char *method_name,
197 struct GNUNET_ENV_Environment *env,
203 * Function called when a @a nym leaves the place.
205 * This is also called if the @a nym was never given permission to enter
206 * (i.e. the @a nym stopped asking to get in).
208 * @param cls Closure.
209 * @param nym Handle for the user who left.
210 * @param variable_count Number of elements in the @a variables array.
211 * @param variables Variables present in the message.
214 (*GNUNET_SOCIAL_FarewellCallback) (void *cls,
215 struct GNUNET_SOCIAL_Nym *nym,
216 struct GNUNET_ENV_Environment *env,
217 size_t variable_count,
218 struct GNUNET_ENV_Modifier *variables);
222 * Function called after the host entered the place.
224 * @param cls Closure.
225 * @param max_message_id Last message ID sent to the channel.
226 * Or 0 if no messages have been sent to the place yet.
229 (*GNUNET_SOCIAL_HostEnterCallback) (void *cls, uint64_t max_message_id);
233 * Enter a place as host.
235 * A place is created upon first entering, and it is active until permanently
236 * left using GNUNET_SOCIAL_host_leave().
239 * Configuration to contact the social service.
241 * Identity of the host.
243 * Private-public key pair of the place.
244 * NULL for ephemeral places.
246 * Policy specifying entry and history restrictions for the place.
248 * Slicer to handle incoming messages.
249 * @param answer_door_cb
250 * Function to handle new nyms that want to enter.
252 * Function to handle departing nyms.
254 * Closure for the callbacks.
256 * @return Handle for the host.
258 struct GNUNET_SOCIAL_Host *
259 GNUNET_SOCIAL_host_enter (const struct GNUNET_CONFIGURATION_Handle *cfg,
260 struct GNUNET_IDENTITY_Ego *ego,
261 const struct GNUNET_CRYPTO_EddsaPrivateKey *place_key,
262 enum GNUNET_PSYC_Policy policy,
263 struct GNUNET_SOCIAL_Slicer *slicer,
264 GNUNET_SOCIAL_HostEnterCallback enter_cb,
265 GNUNET_SOCIAL_AnswerDoorCallback answer_door_cb,
266 GNUNET_SOCIAL_FarewellCallback farewell_cb,
271 * Admit @a nym to the place.
273 * The @a nym reference will remain valid until either the @a host or @a nym
276 * @param host Host of the place.
277 * @param nym Handle for the entity that wants to enter.
280 GNUNET_SOCIAL_host_admit (struct GNUNET_SOCIAL_Host *host,
281 struct GNUNET_SOCIAL_Nym *nym);
285 * Throw @a nym out of the place.
287 * The @a nym reference will remain valid until the
288 * #GNUNET_SOCIAL_FarewellCallback is invoked,
289 * which should be very soon after this call.
291 * @param host Host of the place.
292 * @param nym Handle for the entity to be ejected.
295 GNUNET_SOCIAL_host_eject (struct GNUNET_SOCIAL_Host *host,
296 struct GNUNET_SOCIAL_Nym *nym);
300 * Refuse @a nym entry into the place.
302 * @param host Host of the place.
303 * @param nym Handle for the entity that wanted to enter.
304 * @param method_name Method name for the rejection message.
305 * @param env Environment containing variables for the message, or NULL.
306 * @param data Data for the rejection message to send back.
307 * @param data_size Number of bytes in @a data for method.
310 GNUNET_SOCIAL_host_refuse_entry (struct GNUNET_SOCIAL_Host *host,
311 struct GNUNET_SOCIAL_Nym *nym,
312 const char *method_name,
313 const struct GNUNET_ENV_Environment *env,
319 * Get the public key of a @a nym.
321 * Suitable, for example, to be used with GNUNET_NAMESTORE_zone_to_name().
323 * @param nym Pseudonym to map to a cryptographic identifier.
324 * @param[out] nym_key Set to the public key of the nym.
327 GNUNET_SOCIAL_nym_get_key (struct GNUNET_SOCIAL_Nym *nym,
328 struct GNUNET_CRYPTO_EddsaPublicKey *nym_key);
332 * Obtain the private-public key pair of the host.
334 * @param host Host to get the key of.
335 * @param[out] host_key Set to the private-public key pair of the host. The
336 * public part is suitable for storing in GNS within a "PLACE"
337 * record, along with peer IDs to join at.
340 GNUNET_SOCIAL_host_get_key (struct GNUNET_SOCIAL_Host *host,
341 struct GNUNET_CRYPTO_EddsaPrivateKey *host_key);
345 * Advertise the place in the GNS zone of the @e ego of the @a host.
347 * @param host Host of the place.
348 * @param name The name for the PLACE record to put in the zone.
349 * @param peer_count Number of elements in the @a peers array.
350 * @param peers List of peers in the PLACE record that can be used to send join
352 * @param expiration_time Expiration time of the record, use 0 to remove the record.
353 * @param password Password used to encrypt the record.
356 GNUNET_SOCIAL_host_advertise (struct GNUNET_SOCIAL_Host *host,
359 const struct GNUNET_PeerIdentity *peers,
360 struct GNUNET_TIME_Relative expiration_time,
361 const char *password);
365 * Flags for announcements by a host.
367 enum GNUNET_SOCIAL_AnnounceFlags
369 GNUNET_SOCIAL_ANNOUNCE_NONE = 0,
372 * Whether this announcement removes all objects from the place.
374 * New objects can be still added to the now empty place using the @e env
375 * parameter of the same announcement.
377 GNUNET_SOCIAL_ANNOUNCE_CLEAR_OBJECTS = 1 << 0
382 * Handle for an announcement request.
384 struct GNUNET_SOCIAL_Announcement;
388 * Send a message to all nyms that are present in the place.
390 * This function is restricted to the host. Nyms can only send requests
391 * to the host who can decide to relay it to everyone in the place.
396 * Method to use for the announcement.
398 * Environment containing variables for the message and operations
399 * on objects of the place.
400 * Has to remain available until the first call to @a notify_data.
403 * Function to call to get the payload of the announcement.
404 * @param notify_data_cls
405 * Closure for @a notify.
407 * Flags for this announcement.
409 * @return NULL on error (another announcement already in progress?).
411 struct GNUNET_SOCIAL_Announcement *
412 GNUNET_SOCIAL_host_announce (struct GNUNET_SOCIAL_Host *host,
413 const char *method_name,
414 const struct GNUNET_ENV_Environment *env,
415 GNUNET_PSYC_TransmitNotifyData notify_data,
416 void *notify_data_cls,
417 enum GNUNET_SOCIAL_AnnounceFlags flags);
421 * Cancel announcement.
423 * @param a The announcement to cancel.
426 GNUNET_SOCIAL_host_announce_cancel (struct GNUNET_SOCIAL_Announcement *a);
430 * Obtain handle for a hosted place.
432 * The returned handle can be used to access the place API.
434 * @param host Handle for the host.
436 * @return Handle for the hosted place, valid as long as @a host is valid.
438 struct GNUNET_SOCIAL_Place *
439 GNUNET_SOCIAL_host_get_place (struct GNUNET_SOCIAL_Host *host);
443 * Stop hosting a place.
445 * Invalidates host handle.
447 * @param host Host leaving the place.
448 * @param keep_active Keep the place active after last host disconnected.
451 GNUNET_SOCIAL_host_leave (struct GNUNET_SOCIAL_Host *host, int keep_active);
455 * Function called after the guest entered the local copy of the place.
457 * History and object query functions can be used after this call,
458 * but new messages can't be sent or received.
463 * #GNUNET_OK on success, or
464 * #GNUNET_SYSERR on error, e.g. could not connect to the service, or
465 * could not resolve GNS name.
466 * @param max_message_id
467 * Last message ID sent to the place.
468 * Or 0 if no messages have been sent to the place yet.
471 (*GNUNET_SOCIAL_GuestEnterCallback) (void *cls, int result,
472 uint64_t max_message_id);
476 * Function called upon a guest receives a decision about entry to the place.
479 * Is the guest admitted to the place?
480 * #GNUNET_YES if admitted,
481 * #GNUNET_NO if refused entry
482 * #GNUNET_SYSERR if the request could not be answered.
484 * Method for the message sent along with the decision.
485 * NULL if no message was sent.
487 * Environment with variables for the message.
488 * NULL if there are no variables.
489 * It has to be freed using GNUNET_ENV_environment_destroy()
490 * when it is not needed anymore.
494 * Payload of the message.
497 (*GNUNET_SOCIAL_EntryDecisionCallback) (void *cls,
499 const char *method_name,
500 struct GNUNET_ENV_Environment *env,
506 * Request entry to a place as a guest.
508 * @param cfg Configuration to contact the social service.
509 * @param ego Identity of the guest.
510 * @param crypto_address Public key of the place to enter.
511 * @param origin Peer identity of the origin of the underlying multicast group.
512 * @param relay_count Number of elements in the @a relays array.
513 * @param relays Relays for the underlying multicast group.
514 * @param method_name Method name for the message.
515 * @param env Environment containing variables for the message, or NULL.
516 * @param data Payload for the message to give to the enter callback.
517 * @param data_size Number of bytes in @a data.
518 * @param slicer Slicer to use for processing incoming requests from guests.
520 * @return NULL on errors, otherwise handle for the guest.
522 struct GNUNET_SOCIAL_Guest *
523 GNUNET_SOCIAL_guest_enter (const struct GNUNET_CONFIGURATION_Handle *cfg,
524 struct GNUNET_IDENTITY_Ego *ego,
525 struct GNUNET_CRYPTO_EddsaPublicKey *place_key,
526 struct GNUNET_PeerIdentity *origin,
527 uint32_t relay_count,
528 struct GNUNET_PeerIdentity *relays,
529 const char *method_name,
530 const struct GNUNET_ENV_Environment *env,
533 struct GNUNET_SOCIAL_Slicer *slicer,
534 GNUNET_SOCIAL_GuestEnterCallback local_enter_cb,
535 GNUNET_SOCIAL_EntryDecisionCallback entry_decision_cb,
540 * Request entry to a place as a guest using a GNS name.
542 * @param cfg Configuration to contact the social service.
543 * @param ego Identity of the guest.
544 * @param address GNS name of the place to enter. Either in the form of
545 * 'room.friend.gnu', or 'NYMPUBKEY.zkey'. This latter case refers to
546 * the 'PLACE' record of the empty label ("+") in the GNS zone with the
547 * nym's public key 'NYMPUBKEY', and can be used to request entry to a
548 * pseudonym's place directly.
549 * @param method_name Method name for the message.
550 * @param env Environment containing variables for the message, or NULL.
551 * @param data Payload for the message to give to the enter callback.
552 * @param data_size Number of bytes in @a data.
553 * @param slicer Slicer to use for processing incoming requests from guests.
555 * @return NULL on errors, otherwise handle for the guest.
557 struct GNUNET_SOCIAL_Guest *
558 GNUNET_SOCIAL_guest_enter_by_name (const struct GNUNET_CONFIGURATION_Handle *cfg,
559 struct GNUNET_IDENTITY_Ego *ego,
561 const char *method_name,
562 const struct GNUNET_ENV_Environment *env,
565 struct GNUNET_SOCIAL_Slicer *slicer,
566 GNUNET_SOCIAL_GuestEnterCallback local_enter_cb,
567 GNUNET_SOCIAL_EntryDecisionCallback entry_decision_cb,
572 * Flags for talking to the host of a place.
574 enum GNUNET_SOCIAL_TalkFlags
576 GNUNET_SOCIAL_TALK_NONE = 0
583 struct GNUNET_SOCIAL_TalkRequest;
587 * Talk to the host of the place.
590 * Place where we want to talk to the host.
592 * Method to invoke on the host.
594 * Environment containing variables for the message, or NULL.
596 * Function to use to get the payload for the method.
597 * @param notify_data_cls
598 * Closure for @a notify_data.
600 * Flags for the message being sent.
602 * @return NULL if we are already trying to talk to the host,
603 * otherwise handle to cancel the request.
605 struct GNUNET_SOCIAL_TalkRequest *
606 GNUNET_SOCIAL_guest_talk (struct GNUNET_SOCIAL_Guest *guest,
607 const char *method_name,
608 const struct GNUNET_ENV_Environment *env,
609 GNUNET_PSYC_TransmitNotifyData notify_data,
610 void *notify_data_cls,
611 enum GNUNET_SOCIAL_TalkFlags flags);
615 * Cancel talking to the host of the place.
617 * @param tr Talk request to cancel.
620 GNUNET_SOCIAL_guest_talk_cancel (struct GNUNET_SOCIAL_TalkRequest *tr);
624 * Leave a place permanently.
626 * Notifies the owner of the place about leaving, and destroys the place handle.
628 * @param place Place to leave permanently.
629 * @param keep_active Keep place active after last application disconnected.
632 GNUNET_SOCIAL_guest_leave (struct GNUNET_SOCIAL_Guest *guest, int keep_active);
636 * Obtain handle for a place entered as guest.
638 * The returned handle can be used to access the place API.
640 * @param guest Handle for the guest.
642 * @return Handle for the place, valid as long as @a guest is valid.
644 struct GNUNET_SOCIAL_Place *
645 GNUNET_SOCIAL_guest_get_place (struct GNUNET_SOCIAL_Guest *guest);
651 struct GNUNET_SOCIAL_HistoryLesson;
654 * Learn about the history of a place.
656 * Sends messages through the slicer function of the place where
657 * start_message_id <= message_id <= end_message_id.
658 * The messages will have the #GNUNET_PSYC_MESSAGE_HISTORIC flag set.
660 * To get the latest message, use 0 for both the start and end message ID.
662 * @param place Place we want to learn more about.
663 * @param start_message_id First historic message we are interested in.
664 * @param end_message_id Last historic message we are interested in (inclusive).
665 * @param slicer Slicer to use to process history. Can be the same as the
666 * slicer of the place, as the HISTORIC flag allows distinguishing
667 * old messages from fresh ones.
668 * @param finish_cb Function called after the last message in the history lesson
669 * is passed through the @a slicer. NULL if not needed.
670 * @param finish_cb_cls Closure for @a finish_cb.
671 * @return Handle to abort history lesson, never NULL (multiple lessons
672 * at the same time are allowed).
674 struct GNUNET_SOCIAL_HistoryLesson *
675 GNUNET_SOCIAL_place_get_history (struct GNUNET_SOCIAL_Place *place,
676 uint64_t start_message_id,
677 uint64_t end_message_id,
678 const struct GNUNET_SOCIAL_Slicer *slicer,
679 void (*finish_cb)(void *),
680 void *finish_cb_cls);
684 * Stop processing messages from the history lesson.
686 * Must not be called after the finish callback of the history lesson is called.
688 * @param hist History lesson to cancel.
691 GNUNET_SOCIAL_place_get_history_cancel (struct GNUNET_SOCIAL_HistoryLesson *hist);
694 struct GNUNET_SOCIAL_WatchHandle;
697 * Watch a place for changed objects.
699 * @param place Place to watch.
700 * @param object_filter Object prefix to match.
701 * @param state_cb Function to call when an object/state changes.
702 * @param state_cb_cls Closure for callback.
704 * @return Handle that can be used to cancel watching.
706 struct GNUNET_SOCIAL_WatchHandle *
707 GNUNET_SOCIAL_place_watch (struct GNUNET_SOCIAL_Place *place,
708 const char *object_filter,
709 GNUNET_PSYC_StateCallback state_cb,
714 * Cancel watching a place for changed objects.
716 * @param wh Watch handle to cancel.
719 GNUNET_SOCIAL_place_watch_cancel (struct GNUNET_SOCIAL_WatchHandle *wh);
722 struct GNUNET_SOCIAL_LookHandle;
726 * Look at objects in the place with a matching name prefix.
728 * @param place The place to look its objects at.
729 * @param name_prefix Look at objects with names beginning with this value.
730 * @param state_cb Function to call for each object found.
731 * @param state_cb_cls Closure for callback function.
733 * @return Handle that can be used to stop looking at objects.
735 struct GNUNET_SOCIAL_LookHandle *
736 GNUNET_SOCIAL_place_look (struct GNUNET_SOCIAL_Place *place,
737 const char *name_prefix,
738 GNUNET_PSYC_StateCallback state_cb,
743 * Stop looking at objects.
745 * @param lh Look handle to stop.
748 GNUNET_SOCIAL_place_look_cancel (struct GNUNET_SOCIAL_LookHandle *lh);
753 * Look at a particular object in the place.
755 * The best matching object is returned (its name might be less specific than
756 * what was requested).
758 * @param place The place to look the object at.
759 * @param full_name Full name of the object.
760 * @param value_size Set to the size of the returned value.
761 * @return NULL if there is no such object at this place.
764 GNUNET_SOCIAL_place_look_at (struct GNUNET_SOCIAL_Place *place,
765 const char *full_name,
769 #if 0 /* keep Emacsens' auto-indent happy */
776 /* ifndef GNUNET_SOCIAL_SERVICE_H */
778 /* end of gnunet_social_service.h */