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,
133 /* FIXME: No slicer_remove for now, is it needed? */
136 * Destroy a given try-and-slice instance.
138 * @param slicer slicer to destroy
141 GNUNET_SOCIAL_slicer_destroy (struct GNUNET_SOCIAL_Slicer *slicer);
147 * Create an ego using the private key from the given file. If the file does
148 * not exist, a fresh key is created.
150 * @param keyfile Name of the file with the private key for the ego,
151 * NULL for ephemeral egos.
152 * @return Handle to the ego, NULL on error.
154 struct GNUNET_SOCIAL_Ego *
155 GNUNET_SOCIAL_ego_create (const char *keyfile);
159 * Destroy a handle to an ego.
161 * @param ego Ego to destroy.
164 GNUNET_SOCIAL_ego_destroy (struct GNUNET_SOCIAL_Ego *ego);
168 * Function called asking for nym to be admitted to the place.
170 * Should call either GNUNET_SOCIAL_home_admit() or
171 * GNUNET_SOCIAL_home_reject_entry() (possibly asynchronously). If this owner
172 * cannot decide, it is fine to call neither function, in which case hopefully
173 * some other owner of the home 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 join.
179 * @param header_length Number of modifiers in header.
180 * @param header Modifiers present in the message.
181 * @param msg_size Number of bytes in @a msg.
182 * @param msg Payload given on enter (e.g. a password).
184 typedef void (*GNUNET_SOCIAL_AnswerDoorCallback)(void *cls,
185 struct GNUNET_SOCIAL_Nym *nym,
186 size_t header_length,
187 GNUNET_PSYC_Modifier *header,
193 * Function called when a @a nym leaves the place.
195 * This is also called if the @a nym was never given permission to enter
196 * (i.e. the @a nym stopped asking to get in).
198 * @param cls Closure.
199 * @param nym Handle for the user who left.
200 * @param header_length Number of modifiers in header.
201 * @param header Modifiers present in the message.
203 typedef void (*GNUNET_SOCIAL_FarewellCallback)(void *cls,
204 struct GNUNET_SOCIAL_Nym *nym,
205 size_t header_length,
206 GNUNET_PSYC_Modifier *header);
210 * Enter a home where guests (nyms) can be hosted.
212 * A home is created upon first entering, and exists until
213 * GNUNET_SOCIAL_home_destroy() is called. It can also be left temporarily using
214 * GNUNET_SOCIAL_home_leave().
216 * @param cfg Configuration to contact the social service.
217 * @param home_keyfile File with the private key for the home,
218 * created if the file does not exist;
219 * pass NULL for ephemeral homes.
220 * @param join_policy What is our policy for allowing people in?
221 * @param ego Owner of the home (host).
222 * @param slicer Slicer to handle guests talking.
223 * @param listener_cb Function to handle new nyms that want to join.
224 * @param farewell_cb Function to handle departing nyms.
225 * @param cls Closure for @a listener_cb and @a farewell_cb.
226 * @return Handle for a new home.
228 struct GNUNET_SOCIAL_Home *
229 GNUNET_SOCIAL_home_enter (const struct GNUNET_CONFIGURATION_Handle *cfg,
230 const char *home_keyfile,
231 enum GNUNET_MULTICAST_JoinPolicy join_policy,
232 struct GNUNET_SOCIAL_Ego *ego,
233 struct GNUNET_SOCIAL_Slicer *slicer,
234 GNUNET_SOCIAL_AnswerDoorCallback listener_cb,
235 GNUNET_SOCIAL_FarewellCallback farewell_cb,
240 * Admit @a nym to the @a home.
242 * The @a nym reference will remain valid until either the home is destroyed or
245 * @param home Home to allow @a nym to join.
246 * @param nym Handle for the entity that wants to join.
249 GNUNET_SOCIAL_home_admit (struct GNUNET_SOCIAL_Home *home,
250 struct GNUNET_SOCIAL_Nym *nym);
254 * Throw @a nym out of the @a home.
256 * The @a nym reference will remain valid until the
257 * #GNUNET_SOCIAL_FarewellCallback is invoked,
258 * which should be very soon after this call.
260 * @param home Home to eject @a nym from.
261 * @param nym Handle for the entity to be ejected.
264 GNUNET_SOCIAL_home_eject (struct GNUNET_SOCIAL_Home *home,
265 struct GNUNET_SOCIAL_Nym *nym);
269 * Refuse @a nym entry into the @a home.
271 * @param home Home to disallow @a nym to join.
272 * @param nym Handle for the entity that wanted to join.
273 * @param method Method name to invoke on caller.
274 * @param message_size Number of bytes in @a message for method.
275 * @param message Rejection message to send back.
277 * FIXME: allow setting variables as well for the message
280 GNUNET_SOCIAL_home_reject_entry (struct GNUNET_SOCIAL_Home *home,
281 struct GNUNET_SOCIAL_Nym *nym,
284 const void *message);
288 * Get the identity of a user.
290 * Suitable, for example, to be used with GNUNET_NAMESTORE_zone_to_name().
292 * @param nym Pseudonym to map to a cryptographic identifier.
293 * @param[out] identity Set to the identity of the nym (short hash of the public key).
296 GNUNET_SOCIAL_nym_get_identity (struct GNUNET_SOCIAL_Nym *nym,
297 struct GNUNET_CRYPTO_ShortHashCode *identity);
301 * Obtain the (cryptographic, binary) address for the home.
303 * @param home Home to get the (public) address from.
304 * @param[out] crypto_address Address suitable for storing in GADS, i.e. in
305 * 'HEX.place' or within the respective GADS record type ("PLACE")
308 GNUNET_SOCIAL_home_get_address (struct GNUNET_SOCIAL_Home *home,
309 struct GNUNET_HashCode *crypto_address);
314 * Advertise @a home under @a name in the GADS zone of the @e ego.
316 * @param home The home to advertise.
317 * @param name The name to put in the zone.
318 * @param expiration_time Expiration time of the record, use 0 to remove the record.
321 GNUNET_SOCIAL_home_advertise (struct GNUNET_SOCIAL_Home *home,
323 GNUNET_TIME_Relative expiration_time);
327 * Handle for an announcement request.
329 struct GNUNET_SOCIAL_Announcement;
333 * Send a message to all nyms that are present in the home.
335 * This function is restricted to the home owner. Nyms can only send requests
336 * to the home owner who can decide to relay it to other guests.
338 * @param home Home to address the announcement to.
339 * @param method_name Method to use for the announcement.
340 * @param notify Function to call to get the payload of the announcement.
341 * @param notify_cls Closure for @a notify.
342 * @return NULL on error (announcement already in progress?).
344 struct GNUNET_SOCIAL_Announcement *
345 GNUNET_SOCIAL_home_announce (struct GNUNET_SOCIAL_Home *home,
346 const char *method_name,
347 const struct GNUNET_ENV_Environment *env,
348 GNUNET_CONNECTION_TransmitReadyNotify notify,
353 * Cancel announcement.
355 * @param a The announcement to cancel.
358 GNUNET_SOCIAL_home_announce_cancel (struct GNUNET_SOCIAL_Announcement *a);
362 * Convert our home to a place so we can access it via the place API.
364 * @param home Handle for the home.
365 * @return Place handle for the same home, valid as long as @a home is valid;
366 * do NOT try to GNUNET_SOCIAL_place_leave() this place, it's your home!
368 struct GNUNET_SOCIAL_Place *
369 GNUNET_SOCIAL_home_get_place (struct GNUNET_SOCIAL_Home *home);
373 * Leave a home temporarily, visitors can stay.
375 * After leaving, handling of incoming messages are left to other clients of the
376 * social service, and stops after the last client exits.
378 * @param home Home to leave temporarily (handle becomes invalid).
381 GNUNET_SOCIAL_home_away (struct GNUNET_SOCIAL_Home *home);
385 * Destroy a home, all guests will be ejected.
387 * @param home Home to destroy.
390 GNUNET_SOCIAL_home_destroy (struct GNUNET_SOCIAL_Home *home);
393 * Request entry to a place (home hosted by someone else).
395 * @param cfg Configuration to contact the social service.
396 * @param ego Owner of the home (host).
397 * @param address Address of the place to enter (GADS name, i.e. 'room.friend.gads'),
398 * if the name has the form 'HEX.place', GADS is not
399 * used and HEX is assumed to be the hash of the public
400 * key already; 'HEX.zkey' however would refer to
401 * the 'PLACE' record in the GADS zone with the public key
403 * @param msg_size Number of bytes in @a msg.
404 * @param msg Message to give to the enter callback.
405 * @param slicer Slicer to use for processing incoming requests from guests.
406 * @return NULL on errors, otherwise handle to the place.
408 struct GNUNET_SOCIAL_Place *
409 GNUNET_SOCIAL_place_enter (const struct GNUNET_CONFIGURATION_Handle *cfg,
410 struct GNUNET_SOCIAL_Ego *ego,
412 const struct GNUNET_ENV_Environment *env,
415 struct GNUNET_SOCIAL_Slicer *slicer);
418 * Request entry to a place (home hosted by someone else).
420 * @param cfg Configuration to contact the social service.
421 * @param ego Owner of the home (host).
422 * @param crypto_address Public key of the place to enter.
423 * @param peer Peer to send request to.
424 * @param slicer Slicer to use for processing incoming requests from guests.
425 * @param msg_size Number of bytes in @a msg.
426 * @param msg Message to give to the enter callback.
427 * @return NULL on errors, otherwise handle to the place.
429 struct GNUNET_SOCIAL_Place *
430 GNUNET_SOCIAL_place_enter2 (const struct GNUNET_CONFIGURATION_Handle *cfg,
431 struct GNUNET_SOCIAL_Ego *ego,
432 struct GNUNET_HashCode *crypto_address,
433 struct GNUNET_PeerIdentity *peer,
434 struct GNUNET_SOCIAL_Slicer *slicer,
435 const struct GNUNET_ENV_Environment *env,
440 struct GNUNET_SOCIAL_WatchHandle;
443 * Watch a place for changed objects.
445 * @param place Place to watch.
446 * @param object_filter Object prefix to match.
447 * @param state_cb Function to call when an object/state changes.
448 * @param state_cb_cls Closure for callback.
450 * @return Handle that can be used to cancel watching.
452 struct GNUNET_SOCIAL_WatchHandle *
453 GNUNET_SOCIAL_place_watch (struct GNUNET_SOCIAL_Place *place,
454 const char *object_filter,
455 GNUNET_PSYC_StateCallback state_cb,
460 * Cancel watching a place for changed objects.
462 * @param wh Watch handle to cancel.
465 GNUNET_SOCIAL_place_watch_cancel (struct GNUNET_SOCIAL_WatchHandle *wh);
468 struct GNUNET_SOCIAL_LookHandle;
471 * Look at all objects in the place.
473 * @param place The place to look its objects at.
474 * @param state_cb Function to call for each object found.
475 * @param state_cb_cls Closure for callback function.
477 * @return Handle that can be used to stop looking at objects.
479 struct GNUNET_SOCIAL_LookHandle *
480 GNUNET_SOCIAL_place_look (struct GNUNET_SOCIAL_Place *place,
481 GNUNET_PSYC_StateCallback state_cb,
486 * Look at matching objects in the place.
488 * @param place The place to look its objects at.
489 * @param object_filter Only look at objects with names beginning with this filter value.
490 * @param state_cb Function to call for each object found.
491 * @param state_cb_cls Closure for callback function.
493 * @return Handle that can be used to stop looking at objects.
495 struct GNUNET_SOCIAL_LookHandle *
496 GNUNET_SOCIAL_place_look_for (struct GNUNET_SOCIAL_Place *place,
497 const char *object_filter,
498 GNUNET_PSYC_StateCallback state_cb,
503 * Stop looking at objects.
505 * @param lh Look handle to stop.
508 GNUNET_SOCIAL_place_look_cancel (struct GNUNET_SOCIAL_LookHandle *lh);
513 * Look at a particular object in the place.
515 * @param place The place to look the object at.
516 * @param object_name Full name of the object.
517 * @param value_size Set to the size of the returned value.
518 * @return NULL if there is no such object at this place.
521 GNUNET_SOCIAL_place_look_at (struct GNUNET_SOCIAL_Place *place,
522 const char *object_name,
529 struct GNUNET_SOCIAL_TalkRequest;
532 * Talk to the host of the place.
534 * @param place Place where we want to talk to the host.
535 * @param method_name Method to invoke on the host.
536 * @param notify Function to use to get the payload for the method.
537 * @param notify_cls Closure for @a notify.
538 * @return NULL if we are already trying to talk to the host,
539 * otherwise handle to cancel the request.
541 struct GNUNET_SOCIAL_TalkRequest *
542 GNUNET_SOCIAL_place_talk (struct GNUNET_SOCIAL_Place *place,
543 const char *method_name,
544 const struct GNUNET_ENV_Environment *env,
545 GNUNET_CONNECTION_TransmitReadyNotify notify,
550 * Cancel talking to the host of the place.
552 * @param tr Talk request to cancel.
555 GNUNET_SOCIAL_place_talk_cancel (struct GNUNET_SOCIAL_TalkRequest *tr);
561 struct GNUNET_SOCIAL_HistoryLesson;
564 * Learn about the history of a place.
566 * Sends messages through the given slicer function where
567 * start_message_id <= message_id <= end_message_id.
569 * To get the latest message, use 0 for both the start and end message ID.
571 * @param place Place we want to learn more about.
572 * @param start_message_id First historic message we are interested in.
573 * @param end_message_id Last historic message we are interested in (inclusive).
574 * @param slicer Slicer to use to process history.
575 * FIXME: Needed? Could use the slicer of the place instead,
576 * receiving messages with the HISTORIC flag set.
577 * @return Handle to abort history lesson, never NULL (multiple lessons
578 * at the same time are allowed).
580 struct GNUNET_SOCIAL_HistoryLesson *
581 GNUNET_SOCIAL_place_get_history (struct GNUNET_SOCIAL_Place *place,
582 uint64_t start_message_id,
583 uint64_t end_message_id,
584 struct GNUNET_SOCIAL_Slicer *slicer);
588 * Stop processing messages from the history lesson.
590 * Must also be called explicitly after all of the requested messages have been
593 * @param hist History lesson to cancel.
596 GNUNET_SOCIAL_place_get_history_cancel (struct GNUNET_SOCIAL_HistoryLesson *hist);
600 * Leave a place permanently.
602 * Notifies the owner of the place about leaving, and destroys the place handle.
604 * @param place Place to leave permanently.
607 GNUNET_SOCIAL_place_leave (struct GNUNET_SOCIAL_Place *place);
611 * Leave a place temporarily.
613 * Stop following the conversation for the @a place and destroy the @a place
614 * handle. Only affects the application calling this function, other clients of
615 * the service continue receiving the messages.
617 * @param place Place to leave temporarily.
620 GNUNET_SOCIAL_place_away (struct GNUNET_SOCIAL_Place *place);
623 #if 0 /* keep Emacsens' auto-indent happy */
630 /* ifndef GNUNET_SOCIAL_SERVICE_H */
632 /* end of gnunet_social_service.h */