psyc api: no state events, those are handled in social
[oweals/gnunet.git] / src / include / gnunet_psyc_service.h
1 /*
2      This file is part of GNUnet.
3      (C) 2012, 2013 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19 */
20
21 /** 
22  * @file include/gnunet_psyc_service.h
23  * @brief PSYC service; high-level access to the PSYC protocol
24  *        note that clients of this API are NOT expected to
25  *        understand the PSYC message format, only the semantics!
26  *        Parsing (and serializing) the PSYC stream format is done
27  *        within the implementation of the libgnunetpsyc library,
28  *        and this API deliberately exposes as little as possible
29  *        of the actual data stream format to the application!
30  * @author Christian Grothoff
31  * @author Gabor X Toth
32  *
33  * NOTE:
34  * - this API does not know about psyc's "root" and "places";
35  *   there is no 'root' in GNUnet-Psyc as we're decentralized;
36  *   'places' and 'persons' are combined within the same 
37  *   abstraction, that of a "channel".  Channels are identified
38  *   and accessed in this API using a public/private key.  
39  *   Higher-level applications should use NAMES within GADS
40  *   to obtain public keys, and the distinction between 
41  *   'places' and 'persons' can then be made with the help
42  *   of the naming system (and/or conventions).
43  *   Channels are (as in PSYC) organized into a hierarchy; each
44  *   channel owner (the one with the private key) is then
45  *   the operator of the multicast group (its Origin in 
46  *   the terminology of the multicast API).
47  * - The API supports passing large amounts of data using
48  *   'streaming' for the argument passed to a method.  State
49  *   and variables must fit into memory and cannot be streamed
50  *   (thus, no passing of 4 GB of data in a variable; 
51  *   once we implement this, we might want to create a
52  *   @c \#define for the maximum size of a variable).
53  * - PSYC defines standard variables, methods, etc.  This
54  *   library deliberately abstracts over all of these; a
55  *   higher-level API should combine the naming system (GADS)
56  *   and standard methods (message, join, part, warn,
57  *   fail, error) and variables (action, color, time,
58  *   tag, etc.).  However, this API does take over the
59  *   routing variables, specifically 'context' (channel),
60  *   and 'source'.  We only kind-of support 'target', as
61  *   the target is either everyone in the group or the
62  *   origin, and never just a single member of the group;
63  *   for such individual messages, an application needs to
64  *   construct an 'inbox' channel where the owner (only)
65  *   receives messages (but never forwards; private responses
66  *   would be transmitted by joining the senders 'inbox'
67  *   channel -- or a inbox#bob subchannel).  The
68  *   goal for all of this is to keep the abstractions in this 
69  *   API minimal: interaction with multicast, try \& slice,
70  *   state/variable/channel management.  Higher-level
71  *   operations belong elsewhere (so maybe this API should
72  *   be called 'PSYC-low', whereas a higher-level API
73  *   implementing defaults for standard methods and
74  *   variables might be called 'PSYC-std' or 'PSYC-high'.
75  *
76  * Idee (lynx): 
77  * - rename "channel" to "master"
78  * - rename "member" to "slave"
79  * - rename "group" to "channel"
80  */
81
82 #ifndef GNUNET_PSYC_SERVICE_H
83 #define GNUNET_PSYC_SERVICE_H
84
85 #ifdef __cplusplus
86 extern "C"
87 {
88 #if 0                           /* keep Emacsens' auto-indent happy */
89 }
90 #endif
91 #endif
92
93 #include "gnunet_util_lib.h"
94 #include "gnunet_psyc_lib.h"
95 #include "gnunet_multicast_service.h"
96
97
98 /** 
99  * Version number of GNUnet-PSYC API.
100  */
101 #define GNUNET_PSYC_VERSION 0x00000000
102
103
104 /** 
105  * Information flags for data fragments set via PSYC.
106  */
107 enum GNUNET_PSYC_FragmentStatus
108 {
109   /** 
110    * This is the first part of data for the given method call.
111    */
112   GNUNET_PSYC_FS_FIRST = 1,
113   
114   /** 
115    * This is the last part of data for the given method call.
116    */
117   GNUNET_PSYC_FS_LAST = 2,
118
119   /** 
120    * OR'ed flags if payload is not fragmented.
121    */
122   GNUNET_PSYC_FS_NOT_FRAGMENTED = (GNUNET_PSYC_FS_FIRST | GNUNET_PSYC_FS_LAST)
123 };
124
125
126 /** 
127  * Handle that identifies a join request.
128  *
129  * Used to match calls to #GNUNET_PSYC_JoinCallback to the
130  * corresponding calls to GNUNET_PSYC_join_decision().
131  */
132 struct GNUNET_PSYC_JoinHandle;
133
134 /** 
135  * Handle that identifies a part request.
136  *
137  * Used to match calls to #GNUNET_PSYC_PartCallback to the
138  * corresponding calls to GNUNET_PSYC_part_ack().
139  */
140 struct GNUNET_PSYC_PartHandle;
141
142
143 /** 
144  * Method called from PSYC upon receiving a message indicating a call
145  * to a @e method.  
146  *
147  * @param cls Closure.
148  * @param sender Who transmitted the message (origin, except for messages
149  *        from one of the members to the origin).
150  * @param message_id Unique message counter for this message;
151  *                   (unique only in combination with the given sender for
152  *                    this channel).
153  * @param group_generation Group generation counter for this message
154  *                   (always zero for messages from members to channel owner); FIXME: needed?
155  * @param method_name Original method name from PSYC (may be more
156  *        specific than the registered method name due to try-and-slice matching).
157  *        FIXME: no try-and-slice for methods defined here.
158  * @param header_length Number of modifiers in header.
159  * @param header Modifiers present in the message.
160  * @param data_off Byte offset of @a data in the overall data of the method.
161  * @param data_size Number of bytes in @a data.
162  * @param data Data stream given to the method (might not be zero-terminated 
163  *             if data is binary).
164  * @param frag Fragmentation status for the data.
165  */
166 typedef int (*GNUNET_PSYC_Method)(void *cls,
167                                   const struct GNUNET_PeerIdentity *sender,
168                                   uint64_t message_id,
169                                   uint64_t group_generation,
170                                   const char *method_name,
171                                   uint64_t data_off,
172                                   size_t data_size,
173                                   const void *data,
174                                   enum GNUNET_PSYC_FragmentStatus frag);
175
176
177 /** 
178  * Method called from PSYC upon receiving a join request.
179  *
180  * @param cls Closure.
181  * @param peer Peer requesting to join.
182  * @param method_name Method name in the join request.
183  * @param header_length Number of modifiers in header.
184  * @param header Modifiers present in the message.
185  * @param data_size Number of bytes in @a data.
186  * @param data Data stream given to the method (might not be zero-terminated 
187  *             if data is binary).
188  */
189 typedef int (*GNUNET_PSYC_JoinCallback)(void *cls,
190                                         const struct GNUNET_PeerIdentity *peer,
191                                         const char *method_name,
192                                         size_t header_length,
193                                         GNUNET_PSYC_Modifier *header,
194                                         size_t data_size,
195                                         const void *data,
196                                         struct GNUNET_PSYC_JoinHandle *jh);
197
198
199 /** 
200  * Method called from PSYC upon receiving a part request.
201  *
202  * @param cls Closure.
203  * @param peer Peer requesting to leave.
204  * @param method_name Method name in the part request.
205  * @param header_length Number of modifiers in header.
206  * @param header Modifiers present in the message.
207  * @param data_size Number of bytes in @a data.
208  * @param data Data stream given to the method (might not be zero-terminated 
209  *             if data is binary).
210  */
211 typedef int (*GNUNET_PSYC_PartCallback)(void *cls,
212                                         const struct GNUNET_PeerIdentity *peer,
213                                         const char *method_name,
214                                         size_t header_length,
215                                         GNUNET_PSYC_Modifier *header,
216                                         size_t data_size,
217                                         const void *data,
218                                         struct GNUNET_PSYC_PartHandle *ph);
219
220
221 /** 
222  * Function to call with the decision made for a join request.
223  *
224  * Must be called once and only once in response to an invocation of the
225  * #GNUNET_PSYC_JoinCallback.
226  *
227  * @param jh Join request handle.
228  * @param is_admitted #GNUNET_YES if joining is approved,
229  *        #GNUNET_NO if it is disapproved
230  * @param method_name Method name for the message transmitted with the response.
231  * @param data_size Size of @a data.
232  * @param data Data of the message.
233  */
234 void
235 GNUNET_PSYC_join_decision (struct GNUNET_PSYC_JoinHandle *jh,
236                            int is_admitted,
237                            const char *method_name,
238                            size_t data_size,
239                            const void *data);
240
241
242 /** 
243  * Send a part acknowledgment.
244  *
245  * @param ph Part handle.
246  */
247 void
248 GNUNET_PSYC_part_ack (struct GNUNET_PSYC_PartHandle *ph);
249
250
251 /** 
252  * Handle for the channel of a PSYC group.
253  */
254 struct GNUNET_PSYC_Channel;
255
256
257 /** 
258  * Create a PSYC channel.
259  *
260  * Will create a multicast group identified by the given ECC key.  Messages
261  * received from group members will be given to the respective handler methods.
262  * If a new member wants to join a group, the "join" method handler will be
263  * invoked; the join handler must then generate a "join" message to approve the
264  * joining of the new member.  The channel can also change group membership
265  * without explicit requests.  Note that PSYC doesn't itself "understand" join
266  * or part messages, the respective methods must call other PSYC functions to
267  * inform PSYC about the meaning of the respective events.
268  *
269  * @param cfg Configuration to use (to connect to PSYC service).
270  * @param priv_key ECC key that will be used to sign messages for this
271  *                 PSYC session; public key is used to identify the
272  *                 PSYC group; FIXME: we'll likely want to use
273  *                 NOT the p521 curve here, but a cheaper one in the future
274  *                 Note that end-users will usually not use the private key
275  *                 directly, but rather look it up in GADS for groups 
276  *                 managed by other users, or select a file with the private
277  *                 key(s) when setting up their own channels
278  * @param join_policy What is the membership policy of the group?
279  *                 Used to automate group management decisions.
280  * @param method_cb Function to invoke on messages received from members.
281  * @param join_cb Function to invoke when a peer wants to join.
282  * @param part_cb Function to invoke when a peer wants to part.
283  * @param cls Closure for the callbacks.
284  * @return Handle for the channel, NULL on error.
285  */
286 struct GNUNET_PSYC_Channel *
287 GNUNET_PSYC_channel_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
288                             const struct GNUNET_CRYPTO_EccPrivateKey *priv_key,
289                             enum GNUNET_MULTICAST_JoinPolicy join_policy,
290                             GNUNET_PSYC_Method method_cb,
291                             GNUNET_PSYC_JoinCallback join_cb,
292                             GNUNET_PSYC_PartCallback part_cb,
293                             void *cls);
294
295
296 /** 
297  * Modify channel state (or set a transient variable).
298  *
299  * The state of a channel must fit into the memory of each member (and the
300  * channel); large values that require streaming must only be passed as the
301  * stream arguments to methods.  State modifications might not be transmitted to
302  * group members until the next call to GNUNET_PSYC_channel_transmit().
303  * Variable updates must be given just before the call to the respective method
304  * that needs the variables.
305  *
306  * @param channel Handle to the PSYC group / channel.
307  * @param oper Kind of update operation (add, remove, replace, delete).
308  * @param name Name of the state or transient variable to modify.
309  * @param value_size Number of bytes in @a value.
310  * @param value Value of state variable.
311  * @return #GNUNET_OK on success, #GNUNET_SYSERR on internal error
312  *        (i.e. state too large).
313  */
314 int
315 GNUNET_PSYC_channel_state_modify (struct GNUNET_PSYC_Channel *channel,
316                                   enum GNUNET_PSYC_Operator oper,
317                                   const char *name,
318                                   size_t value_size,
319                                   const void *value);
320
321
322 /** 
323  * Function called to provide data for a transmission via PSYC.
324  *
325  * Note that returning #GNUNET_OK or #GNUNET_SYSERR (but not #GNUNET_NO)
326  * invalidates the respective transmission handle.
327  *
328  * @param cls Closure.
329  * @param message_id Set to the unique message ID that was generated for
330  *        this message.
331  * @param group_generation Set to the group generation used for this
332   *        message.
333  * @param data_size[in,out] Initially set to the number of bytes available in @a data,
334  *        should be set to the number of bytes written to data (IN/OUT).
335  * @param[out] data Where to write the body of the message to give to the method;
336  *        function must copy at most @a *data_size bytes to @a data.
337  * @return #GNUNET_SYSERR on error (fatal, aborts transmission)
338  *         #GNUNET_NO on success, if more data is to be transmitted later 
339  *         (should be used if @a *data_size was not big enough to take all the data)
340  *         #GNUNET_YES if this completes the transmission (all data supplied)
341  */
342 typedef int (*GNUNET_PSYC_ChannelReadyNotify)(void *cls,
343                                               uint64_t message_id,
344                                               uint64_t group_generation,
345                                               size_t *data_size,
346                                               void *data);
347
348
349 /** 
350  * Handle for a pending PSYC transmission operation. 
351  */
352 struct GNUNET_PSYC_ChannelTransmitHandle;
353
354
355 /** 
356  * Send a message to call a method to all members in the PSYC channel.
357  *
358  * @param channel Handle to the PSYC multicast group.
359  * @param increment_group_generation #GNUNET_YES if we need to increment
360  *        the group generation counter after transmitting this message.
361  * @param method_name Which method should be invoked.
362  * @param notify Function to call to obtain the arguments.
363  * @param notify_cls Closure for @a notify.
364  * @return Transmission handle, NULL on error (i.e. more than one request queued).
365  */
366 struct GNUNET_PSYC_ChannelTransmitHandle *
367 GNUNET_PSYC_channel_transmit (struct GNUNET_PSYC_Channel *channel,
368                               int increment_group_generation,
369                               const char *method_name,
370                               GNUNET_PSYC_ChannelReadyNotify notify,
371                               void *notify_cls);
372
373
374 /** 
375  * Abort transmission request to channel.
376  *
377  * @param th Handle of the request that is being aborted.
378  */
379 void
380 GNUNET_PSYC_channel_transmit_cancel (struct GNUNET_PSYC_ChannelTransmitHandle *th);
381
382
383 /** 
384  * Destroy a PSYC channel.
385  *
386  * @param channel PSYC channel to terminate.
387  */
388 tvoid
389 GNUNET_PSYC_channel_destroy (struct GNUNET_PSYC_Channel *channel);
390
391
392 /** 
393  * Handle to access PSYC group operations for all members.
394  */
395 struct GNUNET_PSYC_Group;
396
397
398 /** 
399  * Convert @a channel to a @e group handle to access the @e group APIs.
400  * 
401  * @param channel Channel handle.
402  * @return Group handle, valid for as long as @a channel is valid.
403  */ 
404 struct GNUNET_PSYC_Group *
405 GNUNET_PSYC_channel_get_group (struct GNUNET_PSYC_Channel *channel);
406
407
408 /** 
409  * Convert @a member to a @e group handle to access the @e group APIs.
410  * 
411  * @param member Membership handle.
412  * @return Group handle, valid for as long as @a member is valid.
413  */ 
414 struct GNUNET_PSYC_Group *
415 GNUNET_PSYC_member_get_group (struct GNUNET_PSYC_Member *member);
416
417
418 /** 
419  * Add a member to the group.
420  *
421  * Note that this will NOT generate any PSYC traffic, it will merely update the
422  * local data base to modify how we react to <em>membership test</em> queries.  The
423  * channel still needs to explicitly transmit a @e join message to notify other
424  * group members and they then also must still call this function in their
425  * respective methods handling the @e join message.  This way, how @e join and
426  * @e part operations are exactly implemented is still up to the application;
427  * for example, there might be a @e part_all method to kick out everyone.
428  *
429  * Note that group members are explicitly trusted to execute such methods
430  * correctly; not doing so correctly will result in either denying members
431  * access or offering access to group data to non-members.
432  *
433  * @param group Group handle.
434  * @param member Which peer to add.
435  * @param message_id Message ID for the message that changed the membership.
436  * @param group_generation The generation ID where the change went into effect.
437  */
438 void
439 GNUNET_PSYC_group_member_add (struct GNUNET_PSYC_Group *group,
440                               const struct GNUNET_PeerIdentity *member,
441                               uint64_t message_id,
442                               uint64_t group_generation);
443
444
445 /** 
446  * Remove a member from the group.
447  *
448  * Note that this will NOT generate any PSYC traffic, it will merely update the
449  * local data base to modify how we react to <em>membership test</em> queries.  The
450  * channel still needs to explicitly transmit a @e part message to notify other
451  * group members and they then also must still call this function in their
452  * respective methods handling the @e part message.  This way, how @e join and
453  * @e part operations are exactly implemented is still up to the application;
454  * for example, there might be a @e part_all message to kick out everyone.
455  *
456  * Note that group members are explicitly trusted to perform these
457  * operations correctly; not doing so correctly will result in either
458  * denying members access or offering access to group data to
459  * non-members.
460  *
461  * @param group Group handle.
462  * @param member Which peer to remove.
463  * @param message_id Message ID for the message that changed the membership.
464  * @param group_generation The generation ID where the change went into effect.
465  */
466 void
467 GNUNET_PSYC_group_member_remove (struct GNUNET_PSYC_Group *group,
468                                  const struct GNUNET_PeerIdentity *member,
469                                  uint64_t message_id,
470                                  uint64_t group_generation);
471
472
473 /** 
474  * Function called to inform a member about stored state values for a channel.
475  *
476  * @param cls Closure.
477  * @param name Name of the state variable.
478  * @param value Value of the state variable.
479  * @param value_size Number of bytes in @a value.
480  */
481 typedef void (*GNUNET_PSYC_StateCallback)(void *cls,
482                                           const char *name,
483                                           size_t value_size,
484                                           const void *value);
485
486
487 /** 
488  * Join a PSYC group.
489  *
490  * The entity joining is always the local peer.  The user must immediately use
491  * the GNUNET_PSYC_member_to_origin() (and possibly
492  * GNUNET_PSYC_member_variable_set()) functions to transmit a @e join_msg to
493  * the channel; if the join request succeeds, the channel state (and @e recent
494  * method calls) will be replayed to the joining member.  There is no explicit
495  * notification on failure (as the channel may simply take days to approve, a-v/snd
496  * disapproval is simply being ignored).
497  *
498  * @param cfg Configuration to use.
499  * @param pub_key ECC key that identifies the channel we wish to join
500  * @param origin Peer identity of the origin.
501  * @param method Function to invoke on messages received from the channel,
502  *                typically at least contains functions for @e join and @e part.
503  * @param method_cls Closure for @a method.
504  * @return Handle for the member, NULL on error.
505  */
506 struct GNUNET_PSYC_Member *
507 GNUNET_PSYC_member_join (const struct GNUNET_CONFIGURATION_Handle *cfg, 
508                          const struct GNUNET_CRYPTO_EccPublicKey *pub_key,
509                          const struct GNUNET_PeerIdentity *origin,
510                          GNUNET_PSYC_Method method,
511                          void *method_cls);
512
513
514 /** 
515  * Part a PSYC group.
516  *
517  * Will terminate the connection to the PSYC service.  Polite clients should
518  * first explicitly send a @e part request (via GNUNET_PSYC_member_to_origin()).
519  *
520  * @param member membership handle
521  */
522 void
523 GNUNET_PSYC_member_part (struct GNUNET_PSYC_Member *member);
524
525
526 /** 
527  * Function called to provide data for a transmission to the channel
528  * owner (aka the @e host of the channel).
529  *
530  * Note that returning #GNUNET_OK or #GNUNET_SYSERR (but not #GNUNET_NO)
531  * invalidates the respective transmission handle.
532  *
533  * @param cls Closure.
534  * @param data_size[in,out] Initially set to the number of bytes available in @a data,
535  *        should be set to the number of bytes written to data (IN/OUT).
536  * @param[out] data Where to write the body of the message to give to the method;
537  *        function must copy at most @a *data_size bytes to @a data.
538  * @return #GNUNET_SYSERR on error (fatal, aborts transmission).
539  *         #GNUNET_NO on success, if more data is to be transmitted later.
540  *         #GNUNET_YES if this completes the transmission (all data supplied).
541  */
542 typedef int (*GNUNET_PSYC_MemberReadyNotify)(void *cls,
543                                              size_t *data_size,
544                                              char *data);
545
546
547 /** 
548  * Handle for a pending PSYC transmission operation.
549  */
550 struct GNUNET_PSYC_MemberTransmitHandle;
551
552
553 /** 
554  * Request a message to be sent to the channel origin.
555  *
556  * @param member Membership handle.
557  * @param method_name Which (PSYC) method should be invoked (on host).
558  * @param notify Function to call when we are allowed to transmit (to get data).
559  * @param notify_cls Closure for @a notify.
560  * @return Transmission handle, NULL on error (i.e. more than one request queued).
561  */
562 struct GNUNET_PSYC_MemberTransmitHandle *
563 GNUNET_PSYC_member_to_origin (struct GNUNET_PSYC_Member *member,
564                               const char *method_name,
565                               GNUNET_PSYC_MemberReadyNotify notify,
566                               void *notify_cls);
567
568
569 /** 
570  * Set a (temporary, ":") variable for the next message being transmitted
571  * via GNUNET_PSYC_member_to_origin().
572  *
573  * If GNUNET_PSYC_member_to_origin() is called and then cancelled, all
574  * variables that were set using this function will be unset (lost/forgotten).
575  * To clear a variable state after setting it, you can also call this function
576  * again with NULL/0 for the @a value.
577  *
578  * @param member Membership handle.
579  * @param name Name of the variable to set.
580  * @param value_size Number of bytes in @a value.
581  * @param value Value to set for the given variable.
582  */
583 uint64_t
584 GNUNET_PSYC_member_variable_set (struct GNUNET_PSYC_Member *member,
585                                  const char *name,
586                                  size_t value_size,
587                                  const void *value);
588
589
590 /** 
591  * Abort transmission request to origin.
592  *
593  * @param th Handle of the request that is being aborted.
594  */
595 void
596 GNUNET_PSYC_member_to_origin_cancel (struct GNUNET_PSYC_MemberTransmitHandle *th);
597
598
599 /** 
600  * Handle to a story telling operation.
601  */
602 struct GNUNET_PSYC_Story;
603
604
605 /** 
606  * Request to be told the message history of the channel.
607  *
608  * Historic messages (but NOT the state at the time) will be replayed (given to
609  * the normal method handlers) if available and if access is permitted.
610  *
611  * To get the latest message, use 0 for both the start and end message ID.
612  *
613  * @param member Which channel should be replayed?
614  * @param start_message_id Earliest interesting point in history.
615  * @param end_message_id Last (exclusive) interesting point in history.
616  * @param method Function to invoke on messages received from the story.
617  * @param method_cls Closure for @a method.
618  * @param finish_cb Function to call when the requested story has been fully 
619  *        told (counting message IDs might not suffice, as some messages
620  *        might be secret and thus the listener would not know the story is 
621  *        finished without being told explicitly); once this function
622  *        has been called, the client must not call
623  *        GNUNET_PSYC_member_story_tell_cancel() anymore.
624  * @param finish_cb_cls Closure to finish_cb.
625  * @return Handle to cancel story telling operation.
626  */
627 struct GNUNET_PSYC_Story *
628 GNUNET_PSYC_member_story_tell (struct GNUNET_PSYC_Member *member,
629                                uint64_t start_message_id,
630                                uint64_t end_message_id,
631                                GNUNET_PSYC_Method method,
632                                void *method_cls,
633                                void (*finish_cb)(void *),
634                                void *finish_cb_cls);
635
636
637 /** 
638  * Abort story telling.
639  *
640  * This function must not be called from within method handlers (as given to
641  * GNUNET_PSYC_member_join()) of the member.
642  *
643  * @param story Story telling operation to stop.
644  */
645 void
646 GNUNET_PSYC_member_story_tell_cancel (struct GNUNET_PSYC_Story *story);
647
648
649 /** 
650  * Call the given callback on all matching values (including variables) in the
651  * channel state.
652  *
653  * The callback is invoked synchronously on all matching states (as the state is
654  * fully replicated in the library in this process; channel states should be
655  * small, large data is to be passed as streaming data to methods).
656  *
657  * A name matches if it includes the @a state_name prefix, thus requesting the
658  * empty state ("") will match all values; requesting "_a_b" will also return
659  * values stored under "_a_b_c".
660  *
661  * @param member Membership handle.
662  * @param state_name Name of the state to query (full name 
663  *        might be longer, this is only the prefix that must match).
664  * @param cb Function to call on the matching state values.
665  * @param cb_cls Closure for @a cb.
666  * @return Message ID for which the state was returned (last seen
667  *         message ID).
668  */
669 uint64_t
670 GNUNET_PSYC_member_state_get_all (struct GNUNET_PSYC_Member *member,
671                                   const char *state_name,
672                                   GNUNET_PSYC_StateCallback cb,
673                                   void *cb_cls);
674
675
676 /** 
677  * Obtain the current value of the best-matching value in the state
678  * (including variables).
679  *
680  * Note that variables are only valid during a #GNUNET_PSYC_Method invocation, as
681  * variables are only valid for the duration of a method invocation.
682  *
683  * If the requested variable name does not have an exact state in
684  * the state, the nearest less-specific name is matched; for example,
685  * requesting "_a_b" will match "_a" if "_a_b" does not exist.
686  *
687  * @param member Membership handle.
688  * @param variable_name Name of the variable to query.
689  * @param[out] return_value_size Set to number of bytes in variable, 
690  *        needed as variables might contain binary data and
691  *        might also not be 0-terminated; set to 0 on errors.
692  * @return NULL on error (no matching state or variable), pointer
693           to the respective value otherwise.
694  */
695 const void *
696 GNUNET_PSYC_member_state_get (struct GNUNET_PSYC_Member *member,
697                               const char *variable_name,
698                               size_t *return_value_size);
699
700
701 #if 0                           /* keep Emacsens' auto-indent happy */
702 {
703 #endif
704 #ifdef __cplusplus
705 }
706 #endif
707
708 /* ifndef GNUNET_PSYC_SERVICE_H */
709 #endif
710 /* end of gnunet_psyc_service.h */