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
50 * Handle for our own presence in the network (we can of course have
53 struct GNUNET_SOCIAL_Ego;
56 * Handle for another user (who is likely pseudonymous) in the network.
58 struct GNUNET_SOCIAL_Nym;
61 * Handle for a place where social interactions happen.
63 struct GNUNET_SOCIAL_Place;
66 * Handle for a place that one of our egos hosts.
68 struct GNUNET_SOCIAL_Home;
71 * Handle to an implementation of try-and-slice.
73 struct GNUNET_SOCIAL_Slicer;
77 * Method called from SOCIAL upon receiving a message indicating a call
81 * @param full_method_name Original method name from PSYC (may be more
82 * specific than the registered method name due to try-and-slice matching).
84 * @param message_id Unique message counter for this message
85 * (unique only in combination with the given sender for
87 * @param header_length Number of modifiers in header.
88 * @param header Modifiers present in the message. FIXME: use environment instead?
89 * @param data_offset Byte offset of @a data in the overall data of the method.
90 * @param data_size Number of bytes in @a data.
91 * @param data Data stream given to the method (might not be zero-terminated
93 * @param flags Message flags indicating fragmentation status.
95 typedef int (*GNUNET_SOCIAL_Method)(void *cls,
96 const char *full_method_name,
99 GNUNET_PSYC_Modifier *header,
100 uint64_t data_offset,
103 enum GNUNET_PSYC_MessageFlags flags);
107 * Create a try-and-slice instance.
109 * @return A new try-and-slice construct.
111 struct GNUNET_SOCIAL_Slicer *
112 GNUNET_SOCIAL_slicer_create (void);
116 * Add a method to the try-and-slice instance.
118 * A slicer processes messages and calls methods that match a message. A match
119 * happens whenever the method name of a message starts with the method_name
120 * parameter given here.
122 * @param slicer The try-and-slice instance to extend.
123 * @param method_name Name of the given method, use empty string for default.
124 * @param method Method to invoke.
125 * @param method_cls Closure for method.
128 GNUNET_SOCIAL_slicer_add (struct GNUNET_SOCIAL_Slicer *slicer,
129 const char *method_name,
130 GNUNET_SOCIAL_Method method,
135 * Remove a registered method from the try-and-slice instance.
137 * @param slicer The try-and-slice instance.
138 * @param method_name Name of the method to remove.
139 * @param method Method handler.
142 GNUNET_SOCIAL_slicer_remove (struct GNUNET_SOCIAL_Slicer *slicer,
143 const char *method_name,
144 GNUNET_SOCIAL_Method method);
147 * Destroy a given try-and-slice instance.
149 * @param slicer slicer to destroy
152 GNUNET_SOCIAL_slicer_destroy (struct GNUNET_SOCIAL_Slicer *slicer);
156 * Create an ego using the given private key.
158 * The identity service is used to manage egos, the
159 * GNUNET_IDENTITY_ego_get_key() function returns an ego's private key that can
160 * be passed into this function.
162 * @param key Private key for the ego, NULL for ephemeral egos.
163 * @return Handle to the ego, NULL on error.
165 struct GNUNET_SOCIAL_Ego *
166 GNUNET_SOCIAL_ego_create (const struct GNUNET_CRYPTO_EccPrivateKey *key);
170 * Destroy a handle to an ego.
172 * @param ego Ego to destroy.
175 GNUNET_SOCIAL_ego_destroy (struct GNUNET_SOCIAL_Ego *ego);
179 * Function called asking for nym to be admitted to the place.
181 * Should call either GNUNET_SOCIAL_home_admit() or
182 * GNUNET_SOCIAL_home_reject_entry() (possibly asynchronously). If this owner
183 * cannot decide, it is fine to call neither function, in which case hopefully
184 * some other owner of the home exists that will make the decision. The @a nym
185 * reference remains valid until the #GNUNET_SOCIAL_FarewellCallback is invoked
188 * @param cls Closure.
189 * @param nym Handle for the user who wants to enter.
190 * @param header_length Number of modifiers in header.
191 * @param header Modifiers present in the message.
192 * @param data_size Number of bytes in @a data.
193 * @param data Payload given on enter (e.g. a password).
195 typedef void (*GNUNET_SOCIAL_AnswerDoorCallback)(void *cls,
196 struct GNUNET_SOCIAL_Nym *nym,
197 size_t header_length,
198 GNUNET_PSYC_Modifier *header,
204 * Function called when a @a nym leaves the place.
206 * This is also called if the @a nym was never given permission to enter
207 * (i.e. the @a nym stopped asking to get in).
209 * @param cls Closure.
210 * @param nym Handle for the user who left.
211 * @param header_length Number of modifiers in header.
212 * @param header Modifiers present in the message.
214 typedef void (*GNUNET_SOCIAL_FarewellCallback)(void *cls,
215 struct GNUNET_SOCIAL_Nym *nym,
216 size_t header_length,
217 GNUNET_PSYC_Modifier *header);
221 * Enter a home where guests (nyms) can be hosted.
223 * A home is created upon first entering, and exists until
224 * GNUNET_SOCIAL_home_destroy() is called. It can also be left temporarily using
225 * GNUNET_SOCIAL_home_leave().
227 * @param cfg Configuration to contact the social service.
228 * @param home_keyfile File with the private-public key pair of the home,
229 * created if the file does not exist; pass NULL for ephemeral homes.
230 * @param policy Policy specifying entry and history restrictions of the home.
231 * @param ego Owner of the home (host).
232 * @param slicer Slicer to handle guests talking.
233 * @param listener_cb Function to handle new nyms that want to enter.
234 * @param farewell_cb Function to handle departing nyms.
235 * @param cls Closure for @a listener_cb and @a farewell_cb.
236 * @return Handle for a new home.
238 struct GNUNET_SOCIAL_Home *
239 GNUNET_SOCIAL_home_enter (const struct GNUNET_CONFIGURATION_Handle *cfg,
240 const char *home_keyfile,
241 enum GNUNET_MULTICAST_GroupPolicy policy,
242 struct GNUNET_SOCIAL_Ego *ego,
243 struct GNUNET_SOCIAL_Slicer *slicer,
244 GNUNET_SOCIAL_AnswerDoorCallback listener_cb,
245 GNUNET_SOCIAL_FarewellCallback farewell_cb,
250 * Admit @a nym to the @a home.
252 * The @a nym reference will remain valid until either the home is destroyed or
255 * @param home Home to allow @a nym to enter.
256 * @param nym Handle for the entity that wants to enter.
259 GNUNET_SOCIAL_home_admit (struct GNUNET_SOCIAL_Home *home,
260 struct GNUNET_SOCIAL_Nym *nym);
264 * Throw @a nym out of the @a home.
266 * The @a nym reference will remain valid until the
267 * #GNUNET_SOCIAL_FarewellCallback is invoked,
268 * which should be very soon after this call.
270 * @param home Home to eject @a nym from.
271 * @param nym Handle for the entity to be ejected.
274 GNUNET_SOCIAL_home_eject (struct GNUNET_SOCIAL_Home *home,
275 struct GNUNET_SOCIAL_Nym *nym);
279 * Refuse @a nym entry into the @a home.
281 * @param home Home to disallow @a nym to enter.
282 * @param nym Handle for the entity that wanted to enter.
283 * @param method_name Method name for the rejection message.
284 * @param env Environment containing variables for the message, or NULL.
285 * @param data_size Number of bytes in @a data for method.
286 * @param data Data for the rejection message to send back.
289 GNUNET_SOCIAL_home_reject_entry (struct GNUNET_SOCIAL_Home *home,
290 struct GNUNET_SOCIAL_Nym *nym,
291 const char *method_name,
292 const struct GNUNET_ENV_Environment *env,
298 * Get the public key of a nym.
300 * Suitable, for example, to be used with GNUNET_NAMESTORE_zone_to_name().
302 * @param nym Pseudonym to map to a cryptographic identifier.
303 * @param[out] identity Set to the public key of the nym.
306 GNUNET_SOCIAL_nym_get_key (struct GNUNET_SOCIAL_Nym *nym,
307 struct GNUNET_CRYPTO_EccPublicKey *nym_key);
311 * Obtain the private-public key pair of the home.
313 * @param home Home to get the key of.
314 * @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.
317 GNUNET_SOCIAL_home_get_key (struct GNUNET_SOCIAL_Home *home,
318 struct GNUNET_CRYPTO_EccPrivateKey *home_key);
322 * Advertise @a home under @a name in the GADS zone of the @e ego.
324 * @param home The home to advertise.
325 * @param name The name to put in the zone.
326 * @param expiration_time Expiration time of the record, use 0 to remove the record.
329 GNUNET_SOCIAL_home_advertise (struct GNUNET_SOCIAL_Home *home,
331 GNUNET_TIME_Relative expiration_time);
335 * Handle for an announcement request.
337 struct GNUNET_SOCIAL_Announcement;
341 * Send a message to all nyms that are present in the home.
343 * This function is restricted to the home owner. Nyms can only send requests
344 * to the home owner who can decide to relay it to other guests.
346 * @param home Home to address the announcement to.
347 * @param method_name Method to use for the announcement.
348 * @param env Environment containing variables for the message and operations on
349 * objects of the home, or NULL.
350 * @param notify Function to call to get the payload of the announcement.
351 * @param notify_cls Closure for @a notify.
352 * @param clear_objects #GNUNET_YES to remove all objects from the home, #GNUNET_NO otherwise.
353 * New objects can be added to the now empty home using the @a env parameter.
354 * @return NULL on error (announcement already in progress?).
356 struct GNUNET_SOCIAL_Announcement *
357 GNUNET_SOCIAL_home_announce (struct GNUNET_SOCIAL_Home *home,
358 const char *method_name,
359 const struct GNUNET_ENV_Environment *env,
360 GNUNET_CONNECTION_TransmitReadyNotify notify,
366 * Cancel announcement.
368 * @param a The announcement to cancel.
371 GNUNET_SOCIAL_home_announce_cancel (struct GNUNET_SOCIAL_Announcement *a);
375 * Convert our home to a place so we can access it via the place API.
377 * @param home Handle for the home.
378 * @return Place handle for the same home, valid as long as @a home is valid;
379 * do NOT try to GNUNET_SOCIAL_place_leave() this place, it's your home!
381 struct GNUNET_SOCIAL_Place *
382 GNUNET_SOCIAL_home_get_place (struct GNUNET_SOCIAL_Home *home);
386 * Leave a home temporarily, visitors can stay.
388 * After leaving, handling of incoming messages are left to other clients of the
389 * social service, and stops after the last client exits.
391 * @param home Home to leave temporarily (handle becomes invalid).
394 GNUNET_SOCIAL_home_away (struct GNUNET_SOCIAL_Home *home);
400 * Invalidates home handle.
401 * Guests will be disconnected until the home is restarted.
403 * @param home Home to leave.
406 GNUNET_SOCIAL_home_leave (struct GNUNET_SOCIAL_Home *home);
409 * Request entry to a place (home hosted by someone else).
411 * @param cfg Configuration to contact the social service.
412 * @param ego Owner of the home (host).
413 * @param address GADS name of the place to enter. Either in the form of
414 * 'room.friend.gads', or 'NYMPUBKEY.zkey'. This latter case refers to
415 * the 'PLACE' record of the empty label ("+") in the GADS zone with the
416 * nym's public key 'NYMPUBKEY', and can be used to request entry to a
417 * pseudonym's place directly.
418 * @param env Environment containing variables for the message, or NULL.
419 * @param data_size Number of bytes in @a data.
420 * @param data Payload for the message to give to the enter callback.
421 * @param slicer Slicer to use for processing incoming requests from guests.
422 * @return NULL on errors, otherwise handle to the place.
424 struct GNUNET_SOCIAL_Place *
425 GNUNET_SOCIAL_place_enter (const struct GNUNET_CONFIGURATION_Handle *cfg,
426 struct GNUNET_SOCIAL_Ego *ego,
428 const struct GNUNET_ENV_Environment *env,
431 struct GNUNET_SOCIAL_Slicer *slicer);
434 * Request entry to a place (home hosted by someone else).
436 * @param cfg Configuration to contact the social service.
437 * @param ego Owner of the home (host).
438 * @param crypto_address Public key of the place to enter.
439 * @param peer Peer to send request to.
440 * @param slicer Slicer to use for processing incoming requests from guests.
441 * @param env Environment containing variables for the message, or NULL.
442 * @param data_size Number of bytes in @a data.
443 * @param data Payload for the message to give to the enter callback.
444 * @return NULL on errors, otherwise handle to the place.
446 struct GNUNET_SOCIAL_Place *
447 GNUNET_SOCIAL_place_enter2 (const struct GNUNET_CONFIGURATION_Handle *cfg,
448 struct GNUNET_SOCIAL_Ego *ego,
449 struct GNUNET_CRYPTO_EccPublicKey *crypto_address,
450 struct GNUNET_PeerIdentity *peer,
451 struct GNUNET_SOCIAL_Slicer *slicer,
452 const struct GNUNET_ENV_Environment *env,
457 struct GNUNET_SOCIAL_WatchHandle;
460 * Watch a place for changed objects.
462 * @param place Place to watch.
463 * @param object_filter Object prefix to match.
464 * @param state_cb Function to call when an object/state changes.
465 * @param state_cb_cls Closure for callback.
467 * @return Handle that can be used to cancel watching.
469 struct GNUNET_SOCIAL_WatchHandle *
470 GNUNET_SOCIAL_place_watch (struct GNUNET_SOCIAL_Place *place,
471 const char *object_filter,
472 GNUNET_PSYC_StateCallback state_cb,
477 * Cancel watching a place for changed objects.
479 * @param wh Watch handle to cancel.
482 GNUNET_SOCIAL_place_watch_cancel (struct GNUNET_SOCIAL_WatchHandle *wh);
485 struct GNUNET_SOCIAL_LookHandle;
488 * Look at all objects in the place.
490 * @param place The place to look its objects at.
491 * @param state_cb Function to call for each object found.
492 * @param state_cb_cls Closure for callback function.
494 * @return Handle that can be used to stop looking at objects.
496 struct GNUNET_SOCIAL_LookHandle *
497 GNUNET_SOCIAL_place_look (struct GNUNET_SOCIAL_Place *place,
498 GNUNET_PSYC_StateCallback state_cb,
503 * Look at matching objects in the place.
505 * @param place The place to look its objects at.
506 * @param object_filter Only look at objects with names beginning with this filter value.
507 * @param state_cb Function to call for each object found.
508 * @param state_cb_cls Closure for callback function.
510 * @return Handle that can be used to stop looking at objects.
512 struct GNUNET_SOCIAL_LookHandle *
513 GNUNET_SOCIAL_place_look_for (struct GNUNET_SOCIAL_Place *place,
514 const char *object_filter,
515 GNUNET_PSYC_StateCallback state_cb,
520 * Stop looking at objects.
522 * @param lh Look handle to stop.
525 GNUNET_SOCIAL_place_look_cancel (struct GNUNET_SOCIAL_LookHandle *lh);
530 * Look at a particular object in the place.
532 * @param place The place to look the object at.
533 * @param object_name Full name of the object.
534 * @param value_size Set to the size of the returned value.
535 * @return NULL if there is no such object at this place.
538 GNUNET_SOCIAL_place_look_at (struct GNUNET_SOCIAL_Place *place,
539 const char *object_name,
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 * @return NULL if we are already trying to talk to the host,
557 * otherwise handle to cancel the request.
559 struct GNUNET_SOCIAL_TalkRequest *
560 GNUNET_SOCIAL_place_talk (struct GNUNET_SOCIAL_Place *place,
561 const char *method_name,
562 const struct GNUNET_ENV_Environment *env,
563 GNUNET_CONNECTION_TransmitReadyNotify notify,
568 * Cancel talking to the host of the place.
570 * @param tr Talk request to cancel.
573 GNUNET_SOCIAL_place_talk_cancel (struct GNUNET_SOCIAL_TalkRequest *tr);
579 struct GNUNET_SOCIAL_HistoryLesson;
582 * Learn about the history of a place.
584 * Sends messages through the slicer function of the place where
585 * start_message_id <= message_id <= end_message_id.
586 * The messages will have the #GNUNET_PSYC_MESSAGE_HISTORIC flag set.
588 * To get the latest message, use 0 for both the start and end message ID.
590 * @param place Place we want to learn more about.
591 * @param start_message_id First historic message we are interested in.
592 * @param end_message_id Last historic message we are interested in (inclusive).
593 * @param slicer Slicer to use to process history. Can be the same as the
594 * slicer of the place, as the HISTORIC flag allows distinguishing
595 * old messages from fresh ones.
596 * @param finish_cb Function called after the last message if the history lesson
597 * is passed through the @a slicer. NULL if not needed.
598 * @param finish_cb_cls Closure for @a finish_cb.
599 * @return Handle to abort history lesson, never NULL (multiple lessons
600 * at the same time are allowed).
602 struct GNUNET_SOCIAL_HistoryLesson *
603 GNUNET_SOCIAL_place_get_history (struct GNUNET_SOCIAL_Place *place,
604 uint64_t start_message_id,
605 uint64_t end_message_id,
606 const struct GNUNET_SOCIAL_Slicer *slicer,
607 void (*finish_cb)(void *),
608 void *finish_cb_cls);
612 * Stop processing messages from the history lesson.
614 * Must not be called after the finish callback of the history lesson is called.
616 * @param hist History lesson to cancel.
619 GNUNET_SOCIAL_place_get_history_cancel (struct GNUNET_SOCIAL_HistoryLesson *hist);
623 * Leave a place permanently.
625 * Notifies the owner of the place about leaving, and destroys the place handle.
627 * @param place Place to leave permanently.
630 GNUNET_SOCIAL_place_leave (struct GNUNET_SOCIAL_Place *place);
634 * Leave a place temporarily.
636 * Stop following the conversation for the @a place and destroy the @a place
637 * handle. Only affects the application calling this function, other clients of
638 * the service continue receiving the messages.
640 * @param place Place to leave temporarily.
643 GNUNET_SOCIAL_place_away (struct GNUNET_SOCIAL_Place *place);
646 #if 0 /* keep Emacsens' auto-indent happy */
653 /* ifndef GNUNET_SOCIAL_SERVICE_H */
655 /* end of gnunet_social_service.h */