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 functionality 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_psyc_lib.h"
40 #include "gnunet_psyc_service.h"
41 #include "gnunet_multicast_service.h"
45 * Version number of GNUnet Social API.
47 #define GNUNET_SOCIAL_VERSION 0x00000000
51 * Handle for another user (who is likely pseudonymous) in the network.
53 struct GNUNET_SOCIAL_Nym;
56 * Handle for a place where social interactions happen.
58 struct GNUNET_SOCIAL_Place;
61 * Handle for a place that one of our egos hosts.
63 struct GNUNET_SOCIAL_Home;
66 * Handle to an implementation of try-and-slice.
68 struct GNUNET_SOCIAL_Slicer;
72 * Method called from SOCIAL upon receiving a message indicating a call
76 * @param nym The sender of the message. NULL for the ego's own messages to the home.
77 * @param full_method_name Original method name from PSYC (may be more
78 * specific than the registered method name due to try-and-slice matching).
80 * @param message_id Unique message counter for this message
81 * (unique only in combination with the given sender for
83 * @param modifier_count Number of elements in the @a modifiers array.
84 * @param modifiers Modifiers present in the message. FIXME: use environment instead?
85 * @param data_offset Byte offset of @a data in the overall data of the method.
86 * @param data_size Number of bytes in @a data.
87 * @param data Data stream given to the method (might not be zero-terminated
89 * @param flags Message flags indicating fragmentation status.
91 typedef int (*GNUNET_SOCIAL_Method)(void *cls,
92 struct GNUNET_SOCIAL_Nym *nym,
93 const char *full_method_name,
95 size_t modifier_count,
96 GNUNET_PSYC_Modifier *modifiers,
100 enum GNUNET_PSYC_MessageFlags flags);
104 * Create a try-and-slice instance.
106 * @return A new try-and-slice construct.
108 struct GNUNET_SOCIAL_Slicer *
109 GNUNET_SOCIAL_slicer_create (void);
113 * Add a method to the try-and-slice instance.
115 * A slicer processes messages and calls methods that match a message. A match
116 * happens whenever the method name of a message starts with the method_name
117 * parameter given here.
119 * @param slicer The try-and-slice instance to extend.
120 * @param method_name Name of the given method, use empty string for default.
121 * @param method Method to invoke.
122 * @param method_cls Closure for method.
125 GNUNET_SOCIAL_slicer_add (struct GNUNET_SOCIAL_Slicer *slicer,
126 const char *method_name,
127 GNUNET_SOCIAL_Method method,
132 * Remove a registered method from the try-and-slice instance.
134 * @param slicer The try-and-slice instance.
135 * @param method_name Name of the method to remove.
136 * @param method Method handler.
139 GNUNET_SOCIAL_slicer_remove (struct GNUNET_SOCIAL_Slicer *slicer,
140 const char *method_name,
141 GNUNET_SOCIAL_Method method);
144 * Destroy a given try-and-slice instance.
146 * @param slicer slicer to destroy
149 GNUNET_SOCIAL_slicer_destroy (struct GNUNET_SOCIAL_Slicer *slicer);
153 * Function called asking for nym to be admitted to the place.
155 * Should call either GNUNET_SOCIAL_home_admit() or
156 * GNUNET_SOCIAL_home_reject_entry() (possibly asynchronously). If this owner
157 * cannot decide, it is fine to call neither function, in which case hopefully
158 * some other owner of the home exists that will make the decision. The @a nym
159 * reference remains valid until the #GNUNET_SOCIAL_FarewellCallback is invoked
162 * @param cls Closure.
163 * @param nym Handle for the user who wants to enter.
164 * @param method_name Method name in the entry request.
165 * @param variable_count Number of elements in the @a variables array.
166 * @param variables Variables present in the message.
167 * @param data_size Number of bytes in @a data.
168 * @param data Payload given on enter (e.g. a password).
170 typedef void (*GNUNET_SOCIAL_AnswerDoorCallback)(void *cls,
171 struct GNUNET_SOCIAL_Nym *nym,
172 size_t variable_count,
173 const char *method_name,
174 GNUNET_PSYC_Modifier *variables,
180 * Function called when a @a nym leaves the place.
182 * This is also called if the @a nym was never given permission to enter
183 * (i.e. the @a nym stopped asking to get in).
185 * @param cls Closure.
186 * @param nym Handle for the user who left.
187 * @param variable_count Number of elements in the @a variables array.
188 * @param variables Variables present in the message.
190 typedef void (*GNUNET_SOCIAL_FarewellCallback)(void *cls,
191 struct GNUNET_SOCIAL_Nym *nym,
192 size_t variable_count,
193 GNUNET_PSYC_Modifier *variables);
197 * Enter a home where guests (nyms) can be hosted.
199 * A home is created upon first entering, and exists until
200 * GNUNET_SOCIAL_home_destroy() is called. It can also be left temporarily using
201 * GNUNET_SOCIAL_home_leave().
203 * @param cfg Configuration to contact the social service.
204 * @param home_keyfile File with the private-public key pair of the home,
205 * created if the file does not exist; pass NULL for ephemeral homes.
206 * @param policy Policy specifying entry and history restrictions of the home.
207 * @param ego Owner of the home (host).
208 * @param slicer Slicer to handle guests talking.
209 * @param listener_cb Function to handle new nyms that want to enter.
210 * @param farewell_cb Function to handle departing nyms.
211 * @param cls Closure for @a listener_cb and @a farewell_cb.
212 * @return Handle for a new home.
214 struct GNUNET_SOCIAL_Home *
215 GNUNET_SOCIAL_home_enter (const struct GNUNET_CONFIGURATION_Handle *cfg,
216 const char *home_keyfile,
217 enum GNUNET_PSYC_Policy policy,
218 struct GNUNET_IDENTITY_Ego *ego,
219 struct GNUNET_SOCIAL_Slicer *slicer,
220 GNUNET_SOCIAL_AnswerDoorCallback listener_cb,
221 GNUNET_SOCIAL_FarewellCallback farewell_cb,
226 * Admit @a nym to the @a home.
228 * The @a nym reference will remain valid until either the home is destroyed or
231 * @param home Home to allow @a nym to enter.
232 * @param nym Handle for the entity that wants to enter.
235 GNUNET_SOCIAL_home_admit (struct GNUNET_SOCIAL_Home *home,
236 struct GNUNET_SOCIAL_Nym *nym);
240 * Throw @a nym out of the @a home.
242 * The @a nym reference will remain valid until the
243 * #GNUNET_SOCIAL_FarewellCallback is invoked,
244 * which should be very soon after this call.
246 * @param home Home to eject @a nym from.
247 * @param nym Handle for the entity to be ejected.
250 GNUNET_SOCIAL_home_eject (struct GNUNET_SOCIAL_Home *home,
251 struct GNUNET_SOCIAL_Nym *nym);
255 * Refuse @a nym entry into the @a home.
257 * @param home Home to disallow @a nym to enter.
258 * @param nym Handle for the entity that wanted to enter.
259 * @param method_name Method name for the rejection message.
260 * @param env Environment containing variables for the message, or NULL.
261 * @param data_size Number of bytes in @a data for method.
262 * @param data Data for the rejection message to send back.
265 GNUNET_SOCIAL_home_reject_entry (struct GNUNET_SOCIAL_Home *home,
266 struct GNUNET_SOCIAL_Nym *nym,
267 const char *method_name,
268 const struct GNUNET_ENV_Environment *env,
274 * Get the public key of a nym.
276 * Suitable, for example, to be used with GNUNET_NAMESTORE_zone_to_name().
278 * @param nym Pseudonym to map to a cryptographic identifier.
279 * @param[out] nym_key Set to the public key of the nym.
282 GNUNET_SOCIAL_nym_get_key (struct GNUNET_SOCIAL_Nym *nym,
283 struct GNUNET_CRYPTO_EccPublicKey *nym_key);
287 * Obtain the private-public key pair of the home.
289 * @param home Home to get the key of.
290 * @param[out] home_key Set to the private-public key pair of the home. The public part is suitable for storing in GADS within a "PLACE" record, along with peer IDs to join at.
293 GNUNET_SOCIAL_home_get_key (struct GNUNET_SOCIAL_Home *home,
294 struct GNUNET_CRYPTO_EccPrivateKey *home_key);
298 * Advertise @a home under @a name in the GADS zone of the @e ego.
300 * @param home The home to advertise.
301 * @param name The name for the PLACE record to put in the zone.
302 * @param peer_count Number of elements in the @a peers array.
303 * @param peers List of peers in the PLACE record that can be used to send join
305 * @param expiration_time Expiration time of the record, use 0 to remove the record.
306 * @param password Password used to encrypt the record.
309 GNUNET_SOCIAL_home_advertise (struct GNUNET_SOCIAL_Home *home,
312 const struct GNUNET_PeerIdentity *peers,
313 GNUNET_TIME_Relative expiration_time,
314 const char *password);
318 * Flags for announcements in a home.
320 enum GNUNET_PSYC_AnnouncementFlags
323 * Whether this announcement removes all objects from the home.
325 * New objects can be still added to the now empty home using the @e env
326 * parameter of the same announcement.
328 GNUNET_SOCIAL_ANNOUNCEMENT_CLEAR_OBJECTS = 1 << 0
333 * Handle for an announcement request.
335 struct GNUNET_SOCIAL_Announcement;
339 * Send a message to all nyms that are present in the home.
341 * This function is restricted to the home owner. Nyms can only send requests
342 * to the home owner who can decide to relay it to other guests.
344 * @param home Home to address the announcement to.
345 * @param method_name Method to use for the announcement.
346 * @param env Environment containing variables for the message and operations on
347 * objects of the home, or NULL.
348 * @param notify Function to call to get the payload of the announcement.
349 * @param notify_cls Closure for @a notify.
350 * @param flags Flags for this announcement.
351 * @return NULL on error (announcement already in progress?).
353 struct GNUNET_SOCIAL_Announcement *
354 GNUNET_SOCIAL_home_announce (struct GNUNET_SOCIAL_Home *home,
355 const char *method_name,
356 const struct GNUNET_ENV_Environment *env,
357 GNUNET_CONNECTION_TransmitReadyNotify notify,
359 GNUNET_SOCIAL_AnnouncementFlags flags);
363 * Cancel announcement.
365 * @param a The announcement to cancel.
368 GNUNET_SOCIAL_home_announce_cancel (struct GNUNET_SOCIAL_Announcement *a);
372 * Convert our home to a place so we can access it via the place API.
374 * @param home Handle for the home.
375 * @return Place handle for the same home, valid as long as @a home is valid;
376 * do NOT try to GNUNET_SOCIAL_place_leave() this place, it's your home!
378 struct GNUNET_SOCIAL_Place *
379 GNUNET_SOCIAL_home_get_place (struct GNUNET_SOCIAL_Home *home);
383 * Leave a home temporarily, visitors can stay.
385 * After leaving, handling of incoming messages are left to other clients of the
386 * social service, and stops after the last client exits.
388 * @param home Home to leave temporarily (handle becomes invalid).
391 GNUNET_SOCIAL_home_away (struct GNUNET_SOCIAL_Home *home);
397 * Invalidates home handle.
398 * Guests will be disconnected until the home is restarted.
400 * @param home Home to leave.
403 GNUNET_SOCIAL_home_leave (struct GNUNET_SOCIAL_Home *home);
406 * Request entry to a place (home hosted by someone else).
408 * @param cfg Configuration to contact the social service.
409 * @param ego Owner of the home (host).
410 * @param address GADS name of the place to enter. Either in the form of
411 * 'room.friend.gnu', or 'NYMPUBKEY.zkey'. This latter case refers to
412 * the 'PLACE' record of the empty label ("+") in the GADS zone with the
413 * nym's public key 'NYMPUBKEY', and can be used to request entry to a
414 * pseudonym's place directly.
415 * @param method_name Method name for the message.
416 * @param env Environment containing variables for the message, or NULL.
417 * @param data_size Number of bytes in @a data.
418 * @param data Payload for the message to give to the enter callback.
419 * @param slicer Slicer to use for processing incoming requests from guests.
420 * @return NULL on errors, otherwise handle to the place.
422 struct GNUNET_SOCIAL_Place *
423 GNUNET_SOCIAL_place_enter (const struct GNUNET_CONFIGURATION_Handle *cfg,
424 struct GNUNET_IDENTITY_Ego *ego,
426 const char *method_name,
427 const struct GNUNET_ENV_Environment *env,
430 struct GNUNET_SOCIAL_Slicer *slicer);
433 * Request entry to a place (home hosted by someone else).
435 * @param cfg Configuration to contact the social service.
436 * @param ego Owner of the home (host).
437 * @param crypto_address Public key of the place to enter.
438 * @param origin Peer identity of the origin of the underlying multicast group.
439 * @param relay_count Number of elements in the @a relays array.
440 * @param relays Relays for the underlying multicast group.
441 * @param method_name Method name for the message.
442 * @param env Environment containing variables for the message, or NULL.
443 * @param data_size Number of bytes in @a data.
444 * @param data Payload for the message to give to the enter callback.
445 * @param slicer Slicer to use for processing incoming requests from guests.
446 * @return NULL on errors, otherwise handle to the place.
448 struct GNUNET_SOCIAL_Place *
449 GNUNET_SOCIAL_place_enter2 (const struct GNUNET_CONFIGURATION_Handle *cfg,
450 struct GNUNET_IDENTITY_Ego *ego,
451 struct GNUNET_CRYPTO_EccPublicKey *crypto_address,
452 struct GNUNET_PeerIdentity *origin,
454 struct GNUNET_PeerIdentity *relays,
455 const char *method_name,
456 const struct GNUNET_ENV_Environment *env,
459 struct GNUNET_SOCIAL_Slicer *slicer);
462 struct GNUNET_SOCIAL_WatchHandle;
465 * Watch a place for changed objects.
467 * @param place Place to watch.
468 * @param object_filter Object prefix to match.
469 * @param state_cb Function to call when an object/state changes.
470 * @param state_cb_cls Closure for callback.
472 * @return Handle that can be used to cancel watching.
474 struct GNUNET_SOCIAL_WatchHandle *
475 GNUNET_SOCIAL_place_watch (struct GNUNET_SOCIAL_Place *place,
476 const char *object_filter,
477 GNUNET_PSYC_StateCallback state_cb,
482 * Cancel watching a place for changed objects.
484 * @param wh Watch handle to cancel.
487 GNUNET_SOCIAL_place_watch_cancel (struct GNUNET_SOCIAL_WatchHandle *wh);
490 struct GNUNET_SOCIAL_LookHandle;
494 * Look at objects in the place with a matching name prefix.
496 * @param place The place to look its objects at.
497 * @param name_prefix Look at objects with names beginning with this value.
498 * @param state_cb Function to call for each object found.
499 * @param state_cb_cls Closure for callback function.
501 * @return Handle that can be used to stop looking at objects.
503 struct GNUNET_SOCIAL_LookHandle *
504 GNUNET_SOCIAL_place_look (struct GNUNET_SOCIAL_Place *place,
505 const char *name_prefix,
506 GNUNET_PSYC_StateCallback state_cb,
511 * Stop looking at objects.
513 * @param lh Look handle to stop.
516 GNUNET_SOCIAL_place_look_cancel (struct GNUNET_SOCIAL_LookHandle *lh);
521 * Look at a particular object in the place.
523 * The best matching object is returned (its name might be less specific than
524 * what was requested).
526 * @param place The place to look the object at.
527 * @param full_name Full name of the object.
528 * @param value_size Set to the size of the returned value.
529 * @return NULL if there is no such object at this place.
532 GNUNET_SOCIAL_place_look_at (struct GNUNET_SOCIAL_Place *place,
533 const char *full_name,
538 * Flags for talking to the host of a place.
540 enum GNUNET_SOCIAL_TalkFlags;
546 struct GNUNET_SOCIAL_TalkRequest;
549 * Talk to the host of the place.
551 * @param place Place where we want to talk to the host.
552 * @param method_name Method to invoke on the host.
553 * @param env Environment containing variables for the message, or NULL.
554 * @param notify Function to use to get the payload for the method.
555 * @param notify_cls Closure for @a notify.
556 * @param flags Flags for the message being sent.
557 * @return NULL if we are already trying to talk to the host,
558 * otherwise handle to cancel the request.
560 struct GNUNET_SOCIAL_TalkRequest *
561 GNUNET_SOCIAL_place_talk (struct GNUNET_SOCIAL_Place *place,
562 const char *method_name,
563 const struct GNUNET_ENV_Environment *env,
564 GNUNET_CONNECTION_TransmitReadyNotify notify,
566 GNUNET_SOCIAL_TalkFlags flags);
570 * Cancel talking to the host of the place.
572 * @param tr Talk request to cancel.
575 GNUNET_SOCIAL_place_talk_cancel (struct GNUNET_SOCIAL_TalkRequest *tr);
581 struct GNUNET_SOCIAL_HistoryLesson;
584 * Learn about the history of a place.
586 * Sends messages through the slicer function of the place where
587 * start_message_id <= message_id <= end_message_id.
588 * The messages will have the #GNUNET_PSYC_MESSAGE_HISTORIC flag set.
590 * To get the latest message, use 0 for both the start and end message ID.
592 * @param place Place we want to learn more about.
593 * @param start_message_id First historic message we are interested in.
594 * @param end_message_id Last historic message we are interested in (inclusive).
595 * @param slicer Slicer to use to process history. Can be the same as the
596 * slicer of the place, as the HISTORIC flag allows distinguishing
597 * old messages from fresh ones.
598 * @param finish_cb Function called after the last message if the history lesson
599 * is passed through the @a slicer. NULL if not needed.
600 * @param finish_cb_cls Closure for @a finish_cb.
601 * @return Handle to abort history lesson, never NULL (multiple lessons
602 * at the same time are allowed).
604 struct GNUNET_SOCIAL_HistoryLesson *
605 GNUNET_SOCIAL_place_get_history (struct GNUNET_SOCIAL_Place *place,
606 uint64_t start_message_id,
607 uint64_t end_message_id,
608 const struct GNUNET_SOCIAL_Slicer *slicer,
609 void (*finish_cb)(void *),
610 void *finish_cb_cls);
614 * Stop processing messages from the history lesson.
616 * Must not be called after the finish callback of the history lesson is called.
618 * @param hist History lesson to cancel.
621 GNUNET_SOCIAL_place_get_history_cancel (struct GNUNET_SOCIAL_HistoryLesson *hist);
625 * Leave a place permanently.
627 * Notifies the owner of the place about leaving, and destroys the place handle.
629 * @param place Place to leave permanently.
632 GNUNET_SOCIAL_place_leave (struct GNUNET_SOCIAL_Place *place);
636 * Leave a place temporarily.
638 * Stop following the conversation for the @a place and destroy the @a place
639 * handle. Only affects the application calling this function, other clients of
640 * the service continue receiving the messages.
642 * @param place Place to leave temporarily.
645 GNUNET_SOCIAL_place_away (struct GNUNET_SOCIAL_Place *place);
648 #if 0 /* keep Emacsens' auto-indent happy */
655 /* ifndef GNUNET_SOCIAL_SERVICE_H */
657 /* end of gnunet_social_service.h */