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.
83 * @param message_id Message counter, monotonically increasing from 1.
84 * @param nym The sender of the message. Can be NULL if the message is not
85 * connected to a pseudonym.
86 * @param flags OR'ed GNUNET_PSYC_MessageFlags
87 * @param method_name Original method name from PSYC (may be more specific
88 * than the registered method name due to try-and-slice matching).
89 * @param env Environment containing variables for the message and operations
90 * on objects of the place, or NULL.
91 * Only set for the first call of this function for each @a message_id,
92 * NULL when notifying about further data fragments.
93 * @param data_offset Byte offset of @a data in the overall data of the method.
94 * @param data_size Number of bytes in @a data.
95 * @param data Data stream given to the method (might not be zero-terminated
97 * @param end End of message?
98 * #GNUNET_NO if there are further fragments,
99 * #GNUNET_YES if this is the last fragment,
100 * #GNUNET_SYSERR indicates the message was cancelled by the sender.
102 * @return #GNUNET_YES the application keeps @a env for further use,
103 * #GNUNET_NO @a env is free()'d after the function returns.
106 (*GNUNET_SOCIAL_MethodCallback) (void *cls,
109 const struct GNUNET_SOCIAL_Nym *nym,
110 const char *method_name,
111 struct GNUNET_ENV_Environment *env,
112 uint64_t data_offset,
119 * Create a try-and-slice instance.
121 * @return A new try-and-slice construct.
123 struct GNUNET_SOCIAL_Slicer *
124 GNUNET_SOCIAL_slicer_create (void);
128 * Add a method to the try-and-slice instance.
130 * A slicer processes messages and calls methods that match a message. A match
131 * happens whenever the method name of a message starts with the method_name
132 * parameter given here.
134 * @param slicer The try-and-slice instance to extend.
135 * @param method_name Name of the given method, use empty string for default.
136 * @param method Method to invoke.
137 * @param method_cls Closure for method.
140 GNUNET_SOCIAL_slicer_add (struct GNUNET_SOCIAL_Slicer *slicer,
141 const char *method_name,
142 GNUNET_SOCIAL_MethodCallback method_cb,
147 * Remove a registered method from the try-and-slice instance.
149 * @param slicer The try-and-slice instance.
150 * @param method_name Name of the method to remove.
151 * @param method Method handler.
154 GNUNET_SOCIAL_slicer_remove (struct GNUNET_SOCIAL_Slicer *slicer,
155 const char *method_name,
156 GNUNET_SOCIAL_MethodCallback method_cb);
159 * Destroy a given try-and-slice instance.
161 * @param slicer slicer to destroy
164 GNUNET_SOCIAL_slicer_destroy (struct GNUNET_SOCIAL_Slicer *slicer);
168 * Function called asking for nym to be admitted to the place.
170 * Should call either GNUNET_SOCIAL_host_admit() or
171 * GNUNET_SOCIAL_host_reject_entry() (possibly asynchronously). If this host
172 * cannot decide, it is fine to call neither function, in which case hopefully
173 * some other host of the place exists that will make the decision. The @a nym
174 * reference remains valid until the #GNUNET_SOCIAL_FarewellCallback is invoked
177 * @param cls Closure.
178 * @param nym Handle for the user who wants to enter.
179 * @param method_name Method name in the entry request.
180 * @param variable_count Number of elements in the @a variables array.
181 * @param variables Variables present in the message.
182 * @param data Payload given on enter (e.g. a password).
183 * @param data_size Number of bytes in @a data.
186 (*GNUNET_SOCIAL_AnswerDoorCallback) (void *cls,
187 struct GNUNET_SOCIAL_Nym *nym,
188 size_t variable_count,
189 const char *method_name,
190 struct GNUNET_ENV_Modifier *variables,
196 * Function called when a @a nym leaves the place.
198 * This is also called if the @a nym was never given permission to enter
199 * (i.e. the @a nym stopped asking to get in).
201 * @param cls Closure.
202 * @param nym Handle for the user who left.
203 * @param variable_count Number of elements in the @a variables array.
204 * @param variables Variables present in the message.
207 (*GNUNET_SOCIAL_FarewellCallback) (void *cls,
208 struct GNUNET_SOCIAL_Nym *nym,
209 size_t variable_count,
210 struct GNUNET_ENV_Modifier *variables);
214 * Enter a place as host.
216 * A place is created upon first entering, and it is active until permanently
217 * left using GNUNET_SOCIAL_host_leave().
219 * @param cfg Configuration to contact the social service.
220 * @param place_keyfile File with the private-public key pair of the place,
221 * created if the file does not exist; pass NULL for ephemeral places.
222 * @param policy Policy specifying entry and history restrictions of the place.
223 * @param ego Identity of the host.
224 * @param slicer Slicer to handle incoming messages.
225 * @param listener_cb Function to handle new nyms that want to enter.
226 * @param farewell_cb Function to handle departing nyms.
227 * @param cls Closure for @a listener_cb and @a farewell_cb.
229 * @return Handle for the host.
231 struct GNUNET_SOCIAL_Host *
232 GNUNET_SOCIAL_host_enter (const struct GNUNET_CONFIGURATION_Handle *cfg,
233 const char *place_keyfile,
234 enum GNUNET_PSYC_Policy policy,
235 struct GNUNET_IDENTITY_Ego *ego,
236 struct GNUNET_SOCIAL_Slicer *slicer,
237 GNUNET_SOCIAL_AnswerDoorCallback listener_cb,
238 GNUNET_SOCIAL_FarewellCallback farewell_cb,
243 * Admit @a nym to the place.
245 * The @a nym reference will remain valid until either the @a host or @a nym
248 * @param host Host of the place.
249 * @param nym Handle for the entity that wants to enter.
252 GNUNET_SOCIAL_host_admit (struct GNUNET_SOCIAL_Host *host,
253 struct GNUNET_SOCIAL_Nym *nym);
257 * Throw @a nym out of the place.
259 * The @a nym reference will remain valid until the
260 * #GNUNET_SOCIAL_FarewellCallback is invoked,
261 * which should be very soon after this call.
263 * @param host Host of the place.
264 * @param nym Handle for the entity to be ejected.
267 GNUNET_SOCIAL_host_eject (struct GNUNET_SOCIAL_Host *host,
268 struct GNUNET_SOCIAL_Nym *nym);
272 * Refuse @a nym entry into the place.
274 * @param host Host of the place.
275 * @param nym Handle for the entity that wanted to enter.
276 * @param method_name Method name for the rejection message.
277 * @param env Environment containing variables for the message, or NULL.
278 * @param data Data for the rejection message to send back.
279 * @param data_size Number of bytes in @a data for method.
282 GNUNET_SOCIAL_host_refuse_entry (struct GNUNET_SOCIAL_Host *host,
283 struct GNUNET_SOCIAL_Nym *nym,
284 const char *method_name,
285 const struct GNUNET_ENV_Environment *env,
291 * Get the public key of a @a nym.
293 * Suitable, for example, to be used with GNUNET_NAMESTORE_zone_to_name().
295 * @param nym Pseudonym to map to a cryptographic identifier.
296 * @param[out] nym_key Set to the public key of the nym.
299 GNUNET_SOCIAL_nym_get_key (struct GNUNET_SOCIAL_Nym *nym,
300 struct GNUNET_CRYPTO_EddsaPublicKey *nym_key);
304 * Obtain the private-public key pair of the host.
306 * @param host Host to get the key of.
307 * @param[out] host_key Set to the private-public key pair of the host. The
308 * public part is suitable for storing in GNS within a "PLACE"
309 * record, along with peer IDs to join at.
312 GNUNET_SOCIAL_host_get_key (struct GNUNET_SOCIAL_Host *host,
313 struct GNUNET_CRYPTO_EddsaPrivateKey *host_key);
317 * Advertise the place in the GNS zone of the @e ego of the @a host.
319 * @param host Host of the place.
320 * @param name The name for the PLACE record to put in the zone.
321 * @param peer_count Number of elements in the @a peers array.
322 * @param peers List of peers in the PLACE record that can be used to send join
324 * @param expiration_time Expiration time of the record, use 0 to remove the record.
325 * @param password Password used to encrypt the record.
328 GNUNET_SOCIAL_host_advertise (struct GNUNET_SOCIAL_Host *host,
331 const struct GNUNET_PeerIdentity *peers,
332 struct GNUNET_TIME_Relative expiration_time,
333 const char *password);
337 * Flags for announcements by a host.
339 enum GNUNET_SOCIAL_AnnounceFlags
341 GNUNET_SOCIAL_ANNOUNCE_NONE = 0,
344 * Whether this announcement removes all objects from the place.
346 * New objects can be still added to the now empty place using the @e env
347 * parameter of the same announcement.
349 GNUNET_SOCIAL_ANNOUNCE_CLEAR_OBJECTS = 1 << 0
354 * Handle for an announcement request.
356 struct GNUNET_SOCIAL_Announcement;
360 * Send a message to all nyms that are present in the place.
362 * This function is restricted to the host. Nyms can only send requests
363 * to the host who can decide to relay it to everyone in the place.
365 * @param host Host of the place.
366 * @param method_name Method to use for the announcement.
367 * @param env Environment containing variables for the message and operations
368 * on objects of the place. Can be NULL.
369 * @param notify Function to call to get the payload of the announcement.
370 * @param notify_cls Closure for @a notify.
371 * @param flags Flags for this announcement.
373 * @return NULL on error (announcement already in progress?).
375 struct GNUNET_SOCIAL_Announcement *
376 GNUNET_SOCIAL_host_announce (struct GNUNET_SOCIAL_Host *host,
377 const char *method_name,
378 const struct GNUNET_ENV_Environment *env,
379 GNUNET_CONNECTION_TransmitReadyNotify notify,
381 enum GNUNET_SOCIAL_AnnounceFlags flags);
385 * Cancel announcement.
387 * @param a The announcement to cancel.
390 GNUNET_SOCIAL_host_announce_cancel (struct GNUNET_SOCIAL_Announcement *a);
394 * Obtain handle for a hosted place.
396 * The returned handle can be used to access the place API.
398 * @param host Handle for the host.
400 * @return Handle for the hosted place, valid as long as @a host is valid.
402 struct GNUNET_SOCIAL_Place *
403 GNUNET_SOCIAL_host_get_place (struct GNUNET_SOCIAL_Host *host);
407 * Stop hosting a place.
409 * Invalidates host handle.
411 * @param host Host leaving the place.
412 * @param keep_active Keep the place active after last host disconnected.
415 GNUNET_SOCIAL_host_leave (struct GNUNET_SOCIAL_Host *host, int keep_active);
419 * Request entry to a place as a guest.
421 * @param cfg Configuration to contact the social service.
422 * @param ego Identity of the guest.
423 * @param address GNS name of the place to enter. Either in the form of
424 * 'room.friend.gnu', or 'NYMPUBKEY.zkey'. This latter case refers to
425 * the 'PLACE' record of the empty label ("+") in the GNS zone with the
426 * nym's public key 'NYMPUBKEY', and can be used to request entry to a
427 * pseudonym's place directly.
428 * @param method_name Method name for the message.
429 * @param env Environment containing variables for the message, or NULL.
430 * @param data Payload for the message to give to the enter callback.
431 * @param data_size Number of bytes in @a data.
432 * @param slicer Slicer to use for processing incoming requests from guests.
434 * @return NULL on errors, otherwise handle for the guest.
436 struct GNUNET_SOCIAL_Guest *
437 GNUNET_SOCIAL_guest_enter (const struct GNUNET_CONFIGURATION_Handle *cfg,
438 struct GNUNET_IDENTITY_Ego *ego,
440 const char *method_name,
441 const struct GNUNET_ENV_Environment *env,
444 struct GNUNET_SOCIAL_Slicer *slicer);
447 * Request entry to a place as a guest.
449 * @param cfg Configuration to contact the social service.
450 * @param ego Identity of the guest.
451 * @param crypto_address Public key of the place to enter.
452 * @param origin Peer identity of the origin of the underlying multicast group.
453 * @param relay_count Number of elements in the @a relays array.
454 * @param relays Relays for the underlying multicast group.
455 * @param method_name Method name for the message.
456 * @param env Environment containing variables for the message, or NULL.
457 * @param data Payload for the message to give to the enter callback.
458 * @param data_size Number of bytes in @a data.
459 * @param slicer Slicer to use for processing incoming requests from guests.
461 * @return NULL on errors, otherwise handle for the guest.
463 struct GNUNET_SOCIAL_Guest *
464 GNUNET_SOCIAL_guest_enter2 (const struct GNUNET_CONFIGURATION_Handle *cfg,
465 struct GNUNET_IDENTITY_Ego *ego,
466 struct GNUNET_CRYPTO_EddsaPublicKey *crypto_address,
467 struct GNUNET_PeerIdentity *origin,
469 struct GNUNET_PeerIdentity *relays,
470 const char *method_name,
471 const struct GNUNET_ENV_Environment *env,
474 struct GNUNET_SOCIAL_Slicer *slicer);
478 * Flags for talking to the host of a place.
480 enum GNUNET_SOCIAL_TalkFlags
482 GNUNET_SOCIAL_TALK_NONE = 0
489 struct GNUNET_SOCIAL_TalkRequest;
493 * Talk to the host of the place.
495 * @param place Place where we want to talk to the host.
496 * @param method_name Method to invoke on the host.
497 * @param env Environment containing variables for the message, or NULL.
498 * @param notify Function to use to get the payload for the method.
499 * @param notify_cls Closure for @a notify.
500 * @param flags Flags for the message being sent.
502 * @return NULL if we are already trying to talk to the host,
503 * otherwise handle to cancel the request.
505 struct GNUNET_SOCIAL_TalkRequest *
506 GNUNET_SOCIAL_guest_talk (struct GNUNET_SOCIAL_Place *place,
507 const char *method_name,
508 const struct GNUNET_ENV_Environment *env,
509 GNUNET_CONNECTION_TransmitReadyNotify notify,
511 enum GNUNET_SOCIAL_TalkFlags flags);
515 * Cancel talking to the host of the place.
517 * @param tr Talk request to cancel.
520 GNUNET_SOCIAL_guest_talk_cancel (struct GNUNET_SOCIAL_TalkRequest *tr);
524 * Leave a place permanently.
526 * Notifies the owner of the place about leaving, and destroys the place handle.
528 * @param place Place to leave permanently.
529 * @param keep_active Keep place active after last application disconnected.
532 GNUNET_SOCIAL_guest_leave (struct GNUNET_SOCIAL_Place *place, int keep_active);
536 * Obtain handle for a place entered as guest.
538 * The returned handle can be used to access the place API.
540 * @param guest Handle for the guest.
542 * @return Handle for the place, valid as long as @a guest is valid.
544 struct GNUNET_SOCIAL_Place *
545 GNUNET_SOCIAL_guest_get_place (struct GNUNET_SOCIAL_Host *guest);
551 struct GNUNET_SOCIAL_HistoryLesson;
554 * Learn about the history of a place.
556 * Sends messages through the slicer function of the place where
557 * start_message_id <= message_id <= end_message_id.
558 * The messages will have the #GNUNET_PSYC_MESSAGE_HISTORIC flag set.
560 * To get the latest message, use 0 for both the start and end message ID.
562 * @param place Place we want to learn more about.
563 * @param start_message_id First historic message we are interested in.
564 * @param end_message_id Last historic message we are interested in (inclusive).
565 * @param slicer Slicer to use to process history. Can be the same as the
566 * slicer of the place, as the HISTORIC flag allows distinguishing
567 * old messages from fresh ones.
568 * @param finish_cb Function called after the last message in the history lesson
569 * is passed through the @a slicer. NULL if not needed.
570 * @param finish_cb_cls Closure for @a finish_cb.
571 * @return Handle to abort history lesson, never NULL (multiple lessons
572 * at the same time are allowed).
574 struct GNUNET_SOCIAL_HistoryLesson *
575 GNUNET_SOCIAL_place_get_history (struct GNUNET_SOCIAL_Place *place,
576 uint64_t start_message_id,
577 uint64_t end_message_id,
578 const struct GNUNET_SOCIAL_Slicer *slicer,
579 void (*finish_cb)(void *),
580 void *finish_cb_cls);
584 * Stop processing messages from the history lesson.
586 * Must not be called after the finish callback of the history lesson is called.
588 * @param hist History lesson to cancel.
591 GNUNET_SOCIAL_place_get_history_cancel (struct GNUNET_SOCIAL_HistoryLesson *hist);
594 struct GNUNET_SOCIAL_WatchHandle;
597 * Watch a place for changed objects.
599 * @param place Place to watch.
600 * @param object_filter Object prefix to match.
601 * @param state_cb Function to call when an object/state changes.
602 * @param state_cb_cls Closure for callback.
604 * @return Handle that can be used to cancel watching.
606 struct GNUNET_SOCIAL_WatchHandle *
607 GNUNET_SOCIAL_place_watch (struct GNUNET_SOCIAL_Place *place,
608 const char *object_filter,
609 GNUNET_PSYC_StateCallback state_cb,
614 * Cancel watching a place for changed objects.
616 * @param wh Watch handle to cancel.
619 GNUNET_SOCIAL_place_watch_cancel (struct GNUNET_SOCIAL_WatchHandle *wh);
622 struct GNUNET_SOCIAL_LookHandle;
626 * Look at objects in the place with a matching name prefix.
628 * @param place The place to look its objects at.
629 * @param name_prefix Look at objects with names beginning with this value.
630 * @param state_cb Function to call for each object found.
631 * @param state_cb_cls Closure for callback function.
633 * @return Handle that can be used to stop looking at objects.
635 struct GNUNET_SOCIAL_LookHandle *
636 GNUNET_SOCIAL_place_look (struct GNUNET_SOCIAL_Place *place,
637 const char *name_prefix,
638 GNUNET_PSYC_StateCallback state_cb,
643 * Stop looking at objects.
645 * @param lh Look handle to stop.
648 GNUNET_SOCIAL_place_look_cancel (struct GNUNET_SOCIAL_LookHandle *lh);
653 * Look at a particular object in the place.
655 * The best matching object is returned (its name might be less specific than
656 * what was requested).
658 * @param place The place to look the object at.
659 * @param full_name Full name of the object.
660 * @param value_size Set to the size of the returned value.
661 * @return NULL if there is no such object at this place.
664 GNUNET_SOCIAL_place_look_at (struct GNUNET_SOCIAL_Place *place,
665 const char *full_name,
669 #if 0 /* keep Emacsens' auto-indent happy */
676 /* ifndef GNUNET_SOCIAL_SERVICE_H */
678 /* end of gnunet_social_service.h */