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 full_method_name Original method name from PSYC (may be more
77 * specific than the registered method name due to try-and-slice matching).
79 * @param message_id Unique message counter for this message
80 * (unique only in combination with the given sender for
82 * @param modifier_count Number of elements in the @a modifiers array.
83 * @param modifiers Modifiers present in the message. FIXME: use environment instead?
84 * @param data_offset Byte offset of @a data in the overall data of the method.
85 * @param data_size Number of bytes in @a data.
86 * @param data Data stream given to the method (might not be zero-terminated
88 * @param flags Message flags indicating fragmentation status.
90 typedef int (*GNUNET_SOCIAL_Method)(void *cls,
91 const char *full_method_name,
93 size_t modifier_count,
94 GNUNET_PSYC_Modifier *modifiers,
98 enum GNUNET_PSYC_MessageFlags flags);
102 * Create a try-and-slice instance.
104 * @return A new try-and-slice construct.
106 struct GNUNET_SOCIAL_Slicer *
107 GNUNET_SOCIAL_slicer_create (void);
111 * Add a method to the try-and-slice instance.
113 * A slicer processes messages and calls methods that match a message. A match
114 * happens whenever the method name of a message starts with the method_name
115 * parameter given here.
117 * @param slicer The try-and-slice instance to extend.
118 * @param method_name Name of the given method, use empty string for default.
119 * @param method Method to invoke.
120 * @param method_cls Closure for method.
123 GNUNET_SOCIAL_slicer_add (struct GNUNET_SOCIAL_Slicer *slicer,
124 const char *method_name,
125 GNUNET_SOCIAL_Method method,
130 * Remove a registered method from the try-and-slice instance.
132 * @param slicer The try-and-slice instance.
133 * @param method_name Name of the method to remove.
134 * @param method Method handler.
137 GNUNET_SOCIAL_slicer_remove (struct GNUNET_SOCIAL_Slicer *slicer,
138 const char *method_name,
139 GNUNET_SOCIAL_Method method);
142 * Destroy a given try-and-slice instance.
144 * @param slicer slicer to destroy
147 GNUNET_SOCIAL_slicer_destroy (struct GNUNET_SOCIAL_Slicer *slicer);
151 * Function called asking for nym to be admitted to the place.
153 * Should call either GNUNET_SOCIAL_home_admit() or
154 * GNUNET_SOCIAL_home_reject_entry() (possibly asynchronously). If this owner
155 * cannot decide, it is fine to call neither function, in which case hopefully
156 * some other owner of the home exists that will make the decision. The @a nym
157 * reference remains valid until the #GNUNET_SOCIAL_FarewellCallback is invoked
160 * @param cls Closure.
161 * @param nym Handle for the user who wants to enter.
162 * @param variable_count Number of elements in the @a variables array.
163 * @param variables Variables present in the message.
164 * @param data_size Number of bytes in @a data.
165 * @param data Payload given on enter (e.g. a password).
167 typedef void (*GNUNET_SOCIAL_AnswerDoorCallback)(void *cls,
168 struct GNUNET_SOCIAL_Nym *nym,
169 size_t variable_count,
170 GNUNET_PSYC_Modifier *variables,
176 * Function called when a @a nym leaves the place.
178 * This is also called if the @a nym was never given permission to enter
179 * (i.e. the @a nym stopped asking to get in).
181 * @param cls Closure.
182 * @param nym Handle for the user who left.
183 * @param variable_count Number of elements in the @a variables array.
184 * @param variables Variables present in the message.
186 typedef void (*GNUNET_SOCIAL_FarewellCallback)(void *cls,
187 struct GNUNET_SOCIAL_Nym *nym,
188 size_t variable_count,
189 GNUNET_PSYC_Modifier *variables);
193 * Enter a home where guests (nyms) can be hosted.
195 * A home is created upon first entering, and exists until
196 * GNUNET_SOCIAL_home_destroy() is called. It can also be left temporarily using
197 * GNUNET_SOCIAL_home_leave().
199 * @param cfg Configuration to contact the social service.
200 * @param home_keyfile File with the private-public key pair of the home,
201 * created if the file does not exist; pass NULL for ephemeral homes.
202 * @param policy Policy specifying entry and history restrictions of the home.
203 * @param ego Owner of the home (host).
204 * @param slicer Slicer to handle guests talking.
205 * @param listener_cb Function to handle new nyms that want to enter.
206 * @param farewell_cb Function to handle departing nyms.
207 * @param cls Closure for @a listener_cb and @a farewell_cb.
208 * @return Handle for a new home.
210 struct GNUNET_SOCIAL_Home *
211 GNUNET_SOCIAL_home_enter (const struct GNUNET_CONFIGURATION_Handle *cfg,
212 const char *home_keyfile,
213 enum GNUNET_PSYC_Policy policy,
214 struct GNUNET_IDENTITY_Ego *ego,
215 struct GNUNET_SOCIAL_Slicer *slicer,
216 GNUNET_SOCIAL_AnswerDoorCallback listener_cb,
217 GNUNET_SOCIAL_FarewellCallback farewell_cb,
222 * Admit @a nym to the @a home.
224 * The @a nym reference will remain valid until either the home is destroyed or
227 * @param home Home to allow @a nym to enter.
228 * @param nym Handle for the entity that wants to enter.
231 GNUNET_SOCIAL_home_admit (struct GNUNET_SOCIAL_Home *home,
232 struct GNUNET_SOCIAL_Nym *nym);
236 * Throw @a nym out of the @a home.
238 * The @a nym reference will remain valid until the
239 * #GNUNET_SOCIAL_FarewellCallback is invoked,
240 * which should be very soon after this call.
242 * @param home Home to eject @a nym from.
243 * @param nym Handle for the entity to be ejected.
246 GNUNET_SOCIAL_home_eject (struct GNUNET_SOCIAL_Home *home,
247 struct GNUNET_SOCIAL_Nym *nym);
251 * Refuse @a nym entry into the @a home.
253 * @param home Home to disallow @a nym to enter.
254 * @param nym Handle for the entity that wanted to enter.
255 * @param method_name Method name for the rejection message.
256 * @param env Environment containing variables for the message, or NULL.
257 * @param data_size Number of bytes in @a data for method.
258 * @param data Data for the rejection message to send back.
261 GNUNET_SOCIAL_home_reject_entry (struct GNUNET_SOCIAL_Home *home,
262 struct GNUNET_SOCIAL_Nym *nym,
263 const char *method_name,
264 const struct GNUNET_ENV_Environment *env,
270 * Get the public key of a nym.
272 * Suitable, for example, to be used with GNUNET_NAMESTORE_zone_to_name().
274 * @param nym Pseudonym to map to a cryptographic identifier.
275 * @param[out] nym_key Set to the public key of the nym.
278 GNUNET_SOCIAL_nym_get_key (struct GNUNET_SOCIAL_Nym *nym,
279 struct GNUNET_CRYPTO_EccPublicKey *nym_key);
283 * Obtain the private-public key pair of the home.
285 * @param home Home to get the key of.
286 * @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.
289 GNUNET_SOCIAL_home_get_key (struct GNUNET_SOCIAL_Home *home,
290 struct GNUNET_CRYPTO_EccPrivateKey *home_key);
294 * Advertise @a home under @a name in the GADS zone of the @e ego.
296 * @param home The home to advertise.
297 * @param name The name to put in the zone.
298 * @param expiration_time Expiration time of the record, use 0 to remove the record.
301 GNUNET_SOCIAL_home_advertise (struct GNUNET_SOCIAL_Home *home,
303 GNUNET_TIME_Relative expiration_time);
307 * Flags for announcements in a home.
309 enum GNUNET_PSYC_AnnouncementFlags
312 * Whether this announcement removes all objects from the home.
314 * New objects can be still added to the now empty home using the @e env
315 * parameter of the same announcement.
317 GNUNET_SOCIAL_ANNOUNCEMENT_CLEAR_OBJECTS = 1 << 0
322 * Handle for an announcement request.
324 struct GNUNET_SOCIAL_Announcement;
328 * Send a message to all nyms that are present in the home.
330 * This function is restricted to the home owner. Nyms can only send requests
331 * to the home owner who can decide to relay it to other guests.
333 * @param home Home to address the announcement to.
334 * @param method_name Method to use for the announcement.
335 * @param env Environment containing variables for the message and operations on
336 * objects of the home, or NULL.
337 * @param notify Function to call to get the payload of the announcement.
338 * @param notify_cls Closure for @a notify.
339 * @param flags Flags for this announcement.
340 * @return NULL on error (announcement already in progress?).
342 struct GNUNET_SOCIAL_Announcement *
343 GNUNET_SOCIAL_home_announce (struct GNUNET_SOCIAL_Home *home,
344 const char *method_name,
345 const struct GNUNET_ENV_Environment *env,
346 GNUNET_CONNECTION_TransmitReadyNotify notify,
348 GNUNET_SOCIAL_AnnouncementFlags flags);
352 * Cancel announcement.
354 * @param a The announcement to cancel.
357 GNUNET_SOCIAL_home_announce_cancel (struct GNUNET_SOCIAL_Announcement *a);
361 * Convert our home to a place so we can access it via the place API.
363 * @param home Handle for the home.
364 * @return Place handle for the same home, valid as long as @a home is valid;
365 * do NOT try to GNUNET_SOCIAL_place_leave() this place, it's your home!
367 struct GNUNET_SOCIAL_Place *
368 GNUNET_SOCIAL_home_get_place (struct GNUNET_SOCIAL_Home *home);
372 * Leave a home temporarily, visitors can stay.
374 * After leaving, handling of incoming messages are left to other clients of the
375 * social service, and stops after the last client exits.
377 * @param home Home to leave temporarily (handle becomes invalid).
380 GNUNET_SOCIAL_home_away (struct GNUNET_SOCIAL_Home *home);
386 * Invalidates home handle.
387 * Guests will be disconnected until the home is restarted.
389 * @param home Home to leave.
392 GNUNET_SOCIAL_home_leave (struct GNUNET_SOCIAL_Home *home);
395 * Request entry to a place (home hosted by someone else).
397 * @param cfg Configuration to contact the social service.
398 * @param ego Owner of the home (host).
399 * @param address GADS name of the place to enter. Either in the form of
400 * 'room.friend.gads', or 'NYMPUBKEY.zkey'. This latter case refers to
401 * the 'PLACE' record of the empty label ("+") in the GADS zone with the
402 * nym's public key 'NYMPUBKEY', and can be used to request entry to a
403 * pseudonym's place directly.
404 * @param env Environment containing variables for the message, or NULL.
405 * @param data_size Number of bytes in @a data.
406 * @param data Payload for the message to give to the enter callback.
407 * @param slicer Slicer to use for processing incoming requests from guests.
408 * @return NULL on errors, otherwise handle to the place.
410 struct GNUNET_SOCIAL_Place *
411 GNUNET_SOCIAL_place_enter (const struct GNUNET_CONFIGURATION_Handle *cfg,
412 struct GNUNET_IDENTITY_Ego *ego,
414 const struct GNUNET_ENV_Environment *env,
417 struct GNUNET_SOCIAL_Slicer *slicer);
420 * Request entry to a place (home hosted by someone else).
422 * @param cfg Configuration to contact the social service.
423 * @param ego Owner of the home (host).
424 * @param crypto_address Public key of the place to enter.
425 * @param peer Peer to send request to.
426 * @param slicer Slicer to use for processing incoming requests from guests.
427 * @param env Environment containing variables for the message, or NULL.
428 * @param data_size Number of bytes in @a data.
429 * @param data Payload for the message to give to the enter callback.
430 * @return NULL on errors, otherwise handle to the place.
432 struct GNUNET_SOCIAL_Place *
433 GNUNET_SOCIAL_place_enter2 (const struct GNUNET_CONFIGURATION_Handle *cfg,
434 struct GNUNET_IDENTITY_Ego *ego,
435 struct GNUNET_CRYPTO_EccPublicKey *crypto_address,
436 struct GNUNET_PeerIdentity *peer,
437 struct GNUNET_SOCIAL_Slicer *slicer,
438 const struct GNUNET_ENV_Environment *env,
443 struct GNUNET_SOCIAL_WatchHandle;
446 * Watch a place for changed objects.
448 * @param place Place to watch.
449 * @param object_filter Object prefix to match.
450 * @param state_cb Function to call when an object/state changes.
451 * @param state_cb_cls Closure for callback.
453 * @return Handle that can be used to cancel watching.
455 struct GNUNET_SOCIAL_WatchHandle *
456 GNUNET_SOCIAL_place_watch (struct GNUNET_SOCIAL_Place *place,
457 const char *object_filter,
458 GNUNET_PSYC_StateCallback state_cb,
463 * Cancel watching a place for changed objects.
465 * @param wh Watch handle to cancel.
468 GNUNET_SOCIAL_place_watch_cancel (struct GNUNET_SOCIAL_WatchHandle *wh);
471 struct GNUNET_SOCIAL_LookHandle;
474 * Look at all objects in the place.
476 * @param place The place to look its objects at.
477 * @param state_cb Function to call for each object found.
478 * @param state_cb_cls Closure for callback function.
480 * @return Handle that can be used to stop looking at objects.
482 struct GNUNET_SOCIAL_LookHandle *
483 GNUNET_SOCIAL_place_look (struct GNUNET_SOCIAL_Place *place,
484 GNUNET_PSYC_StateCallback state_cb,
489 * Look at matching objects in the place.
491 * @param place The place to look its objects at.
492 * @param object_filter Only look at objects with names beginning with this filter value.
493 * @param state_cb Function to call for each object found.
494 * @param state_cb_cls Closure for callback function.
496 * @return Handle that can be used to stop looking at objects.
498 struct GNUNET_SOCIAL_LookHandle *
499 GNUNET_SOCIAL_place_look_for (struct GNUNET_SOCIAL_Place *place,
500 const char *object_filter,
501 GNUNET_PSYC_StateCallback state_cb,
506 * Stop looking at objects.
508 * @param lh Look handle to stop.
511 GNUNET_SOCIAL_place_look_cancel (struct GNUNET_SOCIAL_LookHandle *lh);
516 * Look at a particular object in the place.
518 * @param place The place to look the object at.
519 * @param object_name Full name of the object.
520 * @param value_size Set to the size of the returned value.
521 * @return NULL if there is no such object at this place.
524 GNUNET_SOCIAL_place_look_at (struct GNUNET_SOCIAL_Place *place,
525 const char *object_name,
530 * Flags for talking to the host of a place.
532 enum GNUNET_SOCIAL_TalkFlags;
538 struct GNUNET_SOCIAL_TalkRequest;
541 * Talk to the host of the place.
543 * @param place Place where we want to talk to the host.
544 * @param method_name Method to invoke on the host.
545 * @param env Environment containing variables for the message, or NULL.
546 * @param notify Function to use to get the payload for the method.
547 * @param notify_cls Closure for @a notify.
548 * @param flags Flags for the message being sent.
549 * @return NULL if we are already trying to talk to the host,
550 * otherwise handle to cancel the request.
552 struct GNUNET_SOCIAL_TalkRequest *
553 GNUNET_SOCIAL_place_talk (struct GNUNET_SOCIAL_Place *place,
554 const char *method_name,
555 const struct GNUNET_ENV_Environment *env,
556 GNUNET_CONNECTION_TransmitReadyNotify notify,
558 GNUNET_SOCIAL_TalkFlags flags);
562 * Cancel talking to the host of the place.
564 * @param tr Talk request to cancel.
567 GNUNET_SOCIAL_place_talk_cancel (struct GNUNET_SOCIAL_TalkRequest *tr);
573 struct GNUNET_SOCIAL_HistoryLesson;
576 * Learn about the history of a place.
578 * Sends messages through the slicer function of the place where
579 * start_message_id <= message_id <= end_message_id.
580 * The messages will have the #GNUNET_PSYC_MESSAGE_HISTORIC flag set.
582 * To get the latest message, use 0 for both the start and end message ID.
584 * @param place Place we want to learn more about.
585 * @param start_message_id First historic message we are interested in.
586 * @param end_message_id Last historic message we are interested in (inclusive).
587 * @param slicer Slicer to use to process history. Can be the same as the
588 * slicer of the place, as the HISTORIC flag allows distinguishing
589 * old messages from fresh ones.
590 * @param finish_cb Function called after the last message if the history lesson
591 * is passed through the @a slicer. NULL if not needed.
592 * @param finish_cb_cls Closure for @a finish_cb.
593 * @return Handle to abort history lesson, never NULL (multiple lessons
594 * at the same time are allowed).
596 struct GNUNET_SOCIAL_HistoryLesson *
597 GNUNET_SOCIAL_place_get_history (struct GNUNET_SOCIAL_Place *place,
598 uint64_t start_message_id,
599 uint64_t end_message_id,
600 const struct GNUNET_SOCIAL_Slicer *slicer,
601 void (*finish_cb)(void *),
602 void *finish_cb_cls);
606 * Stop processing messages from the history lesson.
608 * Must not be called after the finish callback of the history lesson is called.
610 * @param hist History lesson to cancel.
613 GNUNET_SOCIAL_place_get_history_cancel (struct GNUNET_SOCIAL_HistoryLesson *hist);
617 * Leave a place permanently.
619 * Notifies the owner of the place about leaving, and destroys the place handle.
621 * @param place Place to leave permanently.
624 GNUNET_SOCIAL_place_leave (struct GNUNET_SOCIAL_Place *place);
628 * Leave a place temporarily.
630 * Stop following the conversation for the @a place and destroy the @a place
631 * handle. Only affects the application calling this function, other clients of
632 * the service continue receiving the messages.
634 * @param place Place to leave temporarily.
637 GNUNET_SOCIAL_place_away (struct GNUNET_SOCIAL_Place *place);
640 #if 0 /* keep Emacsens' auto-indent happy */
647 /* ifndef GNUNET_SOCIAL_SERVICE_H */
649 /* end of gnunet_social_service.h */