2 This file is part of GNUnet.
3 Copyright (C) 2012, 2013 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
17 * @author Gabor X Toth
18 * @author Christian Grothoff
23 * @defgroup psyc PSYC service
24 * Send/receive messages in PSYC channels and access the PSYC Store.
26 * Note that clients of this API are NOT expected to understand the PSYC message
27 * format, only the semantics! Parsing (and serializing) the PSYC stream format
28 * is done within the implementation of the libgnunetpsyc library, and this API
29 * deliberately exposes as little as possible of the actual data stream format
33 * - this API does not know about PSYC's "root" and "places";
34 * there is no 'root' in GNUnet-PSYC as we're decentralized;
35 * 'places' and 'persons' are combined within the same
36 * abstraction, that of a "channel". Channels are identified
37 * and accessed in this API using a public/private key.
38 * Higher-level applications should use NAMES within GNS
39 * to obtain public keys, and the distinction between
40 * 'places' and 'persons' can then be made with the help
41 * of the naming system (and/or conventions).
42 * Channels are (as in PSYC) organized into a hierarchy; each
43 * channel master (the one with the private key) is then
44 * the operator of the multicast group (its Origin in
45 * the terminology of the multicast API).
46 * - The API supports passing large amounts of data using
47 * 'streaming' for the argument passed to a method. State
48 * and variables must fit into memory and cannot be streamed
49 * (thus, no passing of 4 GB of data in a variable;
50 * once we implement this, we might want to create a
51 * @c \#define for the maximum size of a variable).
52 * - PSYC defines standard variables, methods, etc. This
53 * library deliberately abstracts over all of these; a
54 * higher-level API should combine the naming system (GNS)
55 * and standard methods (_converse, _notice, _request,
56 * _warning, _error etc) and variables (_action, _color,
57 * _time, etc). However, this API does take over the
58 * routing variables, specifically '_context' (channel),
59 * and '_source'. We only kind-of support '_target', as
60 * the target is either everyone in the group or the
61 * origin, and never just a single member of the group;
62 * for such individual messages, an application needs to
63 * construct an 'inbox' channel where the master (only)
64 * receives messages (but never forwards; private responses
65 * would be transmitted by joining the senders 'inbox'
66 * channel -- or a inbox#bob subchannel). The
67 * goal for all of this is to keep the abstractions in this
68 * API minimal: interaction with multicast, try \& slice,
69 * state/variable/channel management. Higher-level
70 * operations belong elsewhere (so maybe this API should
71 * be called 'PSYC-low', whereas a higher-level API
72 * implementing defaults for standard methods and
73 * variables might be called 'PSYC-std' or 'PSYC-high'.
75 * In PSYC terminology this is simply called the "PSYC
76 * routing layer" and the abstractions, for instance in
77 * psyced, are quite similar. The higher one is called
78 * "PSYC entity layer." In the text rendering of the
79 * protocol the two are separated by an empty line. See
80 * http://about.psyc.eu/Spec:Packet and related. --lynX
85 #ifndef GNUNET_PSYC_SERVICE_H
86 #define GNUNET_PSYC_SERVICE_H
91 #if 0 /* keep Emacsens' auto-indent happy */
96 #include "gnunet_util_lib.h"
97 #include "gnunet_multicast_service.h"
101 # define UINT64_MAX 0xffffffffffffffffULL
106 * Version number of GNUnet-PSYC API.
108 #define GNUNET_PSYC_VERSION 0x00000000
112 * Policy flags for a channel.
114 enum GNUNET_PSYC_ChannelFlags
117 * Admission must be confirmed by the master.
119 GNUNET_PSYC_CHANNEL_ADMISSION_CONTROL = 1 << 0,
122 * Past messages are only available to slaves who were admitted at the time
123 * they were sent to the channel.
125 GNUNET_PSYC_CHANNEL_RESTRICTED_HISTORY = 1 << 1
130 * PSYC channel policies.
132 enum GNUNET_PSYC_Policy
135 * Anyone can join the channel, without announcing his presence;
136 * all messages are always public and can be distributed freely.
137 * Joins may be announced, but this is not required.
139 GNUNET_PSYC_CHANNEL_ANONYMOUS = 0,
142 * The master must approve membership to the channel, messages must only be
143 * distributed to current channel slaves. This includes the channel
144 * state as well as transient messages.
146 GNUNET_PSYC_CHANNEL_PRIVATE
147 = GNUNET_PSYC_CHANNEL_ADMISSION_CONTROL
148 | GNUNET_PSYC_CHANNEL_RESTRICTED_HISTORY
152 * Anyone can freely join the channel (no approval required);
153 * however, messages must only be distributed to current channel
154 * slaves, so the master must still acknowledge that the slave
155 * joined before transient messages are delivered. As approval is
156 * guaranteed, the presistent channel state can be synchronized freely
157 * immediately, prior to master confirmation.
159 GNUNET_PSYC_CHANNEL_OPEN
160 = GNUNET_PSYC_CHANNEL_RESTRICTED_HISTORY,
163 * The master must approve joins to the channel, but past messages can be
164 * freely distributed to slaves.
166 GNUNET_PSYC_CHANNEL_CLOSED
167 = GNUNET_PSYC_CHANNEL_ADMISSION_CONTROL,
172 enum GNUNET_PSYC_MessageFlags
175 * Default / no flags.
177 GNUNET_PSYC_MESSAGE_DEFAULT = 0,
180 * Historic message, retrieved from PSYCstore.
182 GNUNET_PSYC_MESSAGE_HISTORIC = 1 << 0,
185 * Request from slave to master.
187 GNUNET_PSYC_MESSAGE_REQUEST = 1 << 1,
190 * Message can be delivered out of order.
192 GNUNET_PSYC_MESSAGE_ORDER_ANY = 1 << 2
197 * Values for the @a state_delta field of GNUNET_PSYC_MessageHeader.
199 enum GNUNET_PSYC_StateDeltaValues
201 GNUNET_PSYC_STATE_RESET = 0,
203 GNUNET_PSYC_STATE_NOT_MODIFIED = UINT64_MAX
207 GNUNET_NETWORK_STRUCT_BEGIN
212 * Used for single-fragment messages e.g. in a join request or response.
214 struct GNUNET_PSYC_Message
217 * Message header with size and type information.
219 struct GNUNET_MessageHeader header;
221 /* Followed by concatenated PSYC message parts:
222 * messages with GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_* types
228 * Header of a PSYC message.
230 * The PSYC service adds this when delivering the message to local clients,
231 * not present on the multicast layer.
233 struct GNUNET_PSYC_MessageHeader
236 * Generic message header with size and type information.
238 struct GNUNET_MessageHeader header;
241 * Flags for this message fragment.
243 * @see enum GNUNET_PSYC_MessageFlags
245 uint32_t flags GNUNET_PACKED;
248 * Number of the message this message part belongs to.
249 * Monotonically increasing from 1.
251 uint64_t message_id GNUNET_PACKED;
254 * Byte offset of this @e fragment of the @e message.
256 uint64_t fragment_offset GNUNET_PACKED;
259 * Sending slave's public key.
260 * Not set if the message is from the master.
262 struct GNUNET_CRYPTO_EcdsaPublicKey slave_pub_key;
264 /* Followed by concatenated PSYC message parts:
265 * messages with GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_* types
271 * The method of a message.
273 struct GNUNET_PSYC_MessageMethod
276 * Type: GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_METHOD
278 struct GNUNET_MessageHeader header;
281 * OR'ed GNUNET_PSYC_MasterTransmitFlags
283 uint32_t flags GNUNET_PACKED;
286 * Number of message IDs since the last message that contained state
287 * operations. @see enum GNUNET_PSYC_StateDeltaValues
289 uint64_t state_delta GNUNET_PACKED;
291 /* Followed by NUL-terminated method name. */
296 * A modifier of a message.
298 struct GNUNET_PSYC_MessageModifier
301 * Type: GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MODIFIER
303 struct GNUNET_MessageHeader header;
308 uint32_t value_size GNUNET_PACKED;
311 * Size of name, including NUL terminator.
313 uint16_t name_size GNUNET_PACKED;
316 * enum GNUNET_PSYC_Operator
320 /* Followed by NUL-terminated name, then the value. */
324 struct GNUNET_PSYC_CountersResultMessage
327 * Type: GNUNET_MESSAGE_TYPE_PSYC_RESULT_COUNTERS
329 struct GNUNET_MessageHeader header;
332 * Status code for the operation.
334 uint32_t result_code GNUNET_PACKED;
337 * Last message ID sent to the channel.
339 uint64_t max_message_id GNUNET_PACKED;
344 * Join request sent to a PSYC master.
346 struct GNUNET_PSYC_JoinRequestMessage
349 * Type: GNUNET_MESSAGE_TYPE_PSYC_MASTER_JOIN_REQUEST
351 struct GNUNET_MessageHeader header;
353 * Public key of the joining slave.
355 struct GNUNET_CRYPTO_EcdsaPublicKey slave_pub_key;
357 /* Followed by struct GNUNET_MessageHeader join_request */
362 * Join decision sent in reply to a join request.
364 struct GNUNET_PSYC_JoinDecisionMessage
367 * Type: GNUNET_MESSAGE_TYPE_PSYC_JOIN_DECISION
369 struct GNUNET_MessageHeader header;
372 * #GNUNET_YES if the slave was admitted.
377 * Public key of the joining slave.
378 * Only set when the master is sending the decision,
379 * not set when a slave is receiving it.
381 struct GNUNET_CRYPTO_EcdsaPublicKey slave_pub_key;
383 /* Followed by struct GNUNET_MessageHeader join_response */
387 enum GNUNET_PSYC_HistoryReplayFlags
390 * Replay locally available messages.
392 GNUNET_PSYC_HISTORY_REPLAY_LOCAL = 0,
395 * Replay messages from remote peers if not found locally.
397 GNUNET_PSYC_HISTORY_REPLAY_REMOTE = 1,
401 struct GNUNET_PSYC_HistoryRequestMessage
404 * Type: GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_HISTORY_REPLAY
406 struct GNUNET_MessageHeader header;
409 * @see enum GNUNET_PSYC_HistoryReplayFlags
411 uint32_t flags GNUNET_PACKED;
414 * ID for this operation.
416 uint64_t op_id GNUNET_PACKED;
418 uint64_t start_message_id GNUNET_PACKED;
420 uint64_t end_message_id GNUNET_PACKED;
422 uint64_t message_limit GNUNET_PACKED;
424 /* Followed by NUL-terminated method name prefix. */
428 struct GNUNET_PSYC_StateRequestMessage
432 * - GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_STATE_GET
433 * - GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_STATE_GET_PREFIX
435 struct GNUNET_MessageHeader header;
437 uint32_t reserved GNUNET_PACKED;
440 * ID for this operation.
442 uint64_t op_id GNUNET_PACKED;
444 /* Followed by NUL-terminated name. */
448 /**** service -> library ****/
452 * Answer from service to client about last operation.
454 struct GNUNET_PSYC_OperationResultMessage
458 * - GNUNET_MESSAGE_TYPE_PSYC_RESULT_CODE
459 * - GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_STATE_RESULT
461 struct GNUNET_MessageHeader header;
463 uint32_t reserved GNUNET_PACKED;
468 uint64_t op_id GNUNET_PACKED;
471 * Status code for the operation.
473 uint64_t result_code GNUNET_PACKED;
476 * - on error: NUL-terminated error message
477 * - on success: one of the following message types
479 * For a STATE_RESULT, one of:
480 * - GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MODIFIER
481 * - GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MOD_CONT
482 * - GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_END
486 GNUNET_NETWORK_STRUCT_END
489 #define GNUNET_PSYC_MODIFIER_MAX_PAYLOAD \
490 GNUNET_MULTICAST_FRAGMENT_MAX_PAYLOAD \
491 - sizeof (struct GNUNET_PSYC_MessageModifier)
493 #define GNUNET_PSYC_MOD_CONT_MAX_PAYLOAD \
494 GNUNET_MULTICAST_FRAGMENT_MAX_PAYLOAD \
495 - sizeof (struct GNUNET_MessageHeader)
497 #define GNUNET_PSYC_DATA_MAX_PAYLOAD \
498 GNUNET_MULTICAST_FRAGMENT_MAX_PAYLOAD \
499 - sizeof (struct GNUNET_MessageHeader)
503 * PSYC message part processing states.
505 enum GNUNET_PSYC_MessageState
507 GNUNET_PSYC_MESSAGE_STATE_START = 0,
508 GNUNET_PSYC_MESSAGE_STATE_HEADER = 1,
509 GNUNET_PSYC_MESSAGE_STATE_METHOD = 2,
510 GNUNET_PSYC_MESSAGE_STATE_MODIFIER = 3,
511 GNUNET_PSYC_MESSAGE_STATE_MOD_CONT = 4,
512 GNUNET_PSYC_MESSAGE_STATE_DATA = 5,
513 GNUNET_PSYC_MESSAGE_STATE_END = 6,
514 GNUNET_PSYC_MESSAGE_STATE_CANCEL = 7,
515 GNUNET_PSYC_MESSAGE_STATE_ERROR = 8,
520 * Handle that identifies a join request.
522 * Used to match calls to #GNUNET_PSYC_JoinCallback to the
523 * corresponding calls to GNUNET_PSYC_join_decision().
525 struct GNUNET_PSYC_JoinHandle;
529 * Method called from PSYC upon receiving a message.
531 * @param cls Closure.
532 * @param message_id Sequence number of the message.
533 * @param flags OR'ed GNUNET_PSYC_MessageFlags
534 * @param msg Message part, one of the following types:
537 (*GNUNET_PSYC_MessageCallback) (void *cls,
538 const struct GNUNET_PSYC_MessageHeader *msg);
542 * Method called from PSYC upon receiving part of a message.
546 * @param slave_pub_key
547 * Public key of the slave sending the message.
548 * Only set for channel master.
550 * Sequence number of the message.
552 * OR'ed GNUNET_PSYC_MessageFlags
553 * @param fragment_offset
554 * Multicast message fragment offset.
555 * @param msg Message part, one of the following types:
556 * - #GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_HEADER
557 * - #GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_METHOD
558 * - #GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MODIFIER
559 * - #GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MOD_CONT
560 * - #GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_DATA
561 * or NULL if an error occurred while receiving a message.
564 (*GNUNET_PSYC_MessagePartCallback) (void *cls,
565 const struct GNUNET_PSYC_MessageHeader *msg,
566 const struct GNUNET_MessageHeader *pmsg);
570 * Method called from PSYC upon receiving a join request.
574 * @param slave_pub_key
575 * Public key of the slave requesting join.
577 * Join message sent along with the request.
579 * Join handle to use with GNUNET_PSYC_join_decision()
582 (*GNUNET_PSYC_JoinRequestCallback) (void *cls,
583 const struct GNUNET_PSYC_JoinRequestMessage *req,
584 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_pub_key,
585 const struct GNUNET_PSYC_Message *join_msg,
586 struct GNUNET_PSYC_JoinHandle *jh);
590 * Function to call with the decision made for a join request.
592 * Must be called once and only once in response to an invocation of the
593 * #GNUNET_PSYC_JoinCallback.
595 * @param jh Join request handle.
597 * #GNUNET_YES if the join is approved,
598 * #GNUNET_NO if it is disapproved,
599 * #GNUNET_SYSERR if we cannot answer the request.
600 * @param relay_count Number of relays given.
601 * @param relays Array of suggested peers that might be useful relays to use
602 * when joining the multicast group (essentially a list of peers that
603 * are already part of the multicast group and might thus be willing
604 * to help with routing). If empty, only this local peer (which must
605 * be the multicast origin) is a good candidate for building the
606 * multicast tree. Note that it is unnecessary to specify our own
607 * peer identity in this array.
608 * @param join_resp Application-dependent join response message to send along
611 * @return #GNUNET_OK on success,
612 * #GNUNET_SYSERR if @a join_resp is too large.
615 GNUNET_PSYC_join_decision (struct GNUNET_PSYC_JoinHandle *jh,
617 uint32_t relay_count,
618 const struct GNUNET_PeerIdentity *relays,
619 const struct GNUNET_PSYC_Message *join_resp);
623 * Handle for the master of a PSYC channel.
625 struct GNUNET_PSYC_Master;
629 * Function called once we are connected to the PSYC service
630 * and the channel master is started.
632 * Also called when we reconnected to the service
633 * after the connection closed unexpectedly.
638 * #GNUNET_YES if there were already messages sent to the channel,
639 * #GNUNET_NO if the message history is empty,
640 * #GNUNET_SYSERR on error.
641 * @param max_message_id
642 * Last message ID sent to the channel.
645 (*GNUNET_PSYC_MasterStartCallback) (void *cls, int result,
646 uint64_t max_message_id);
650 * Start a PSYC master channel.
652 * Will start a multicast group identified by the given ECC key. Messages
653 * received from group members will be given to the respective handler methods.
654 * If a new member wants to join a group, the "join" method handler will be
655 * invoked; the join handler must then generate a "join" message to approve the
656 * joining of the new member. The channel can also change group membership
657 * without explicit requests. Note that PSYC doesn't itself "understand" join
658 * or part messages, the respective methods must call other PSYC functions to
659 * inform PSYC about the meaning of the respective events.
661 * @param cfg Configuration to use (to connect to PSYC service).
662 * @param channel_key ECC key that will be used to sign messages for this
663 * PSYC session. The public key is used to identify the PSYC channel.
664 * Note that end-users will usually not use the private key directly, but
665 * rather look it up in GNS for places managed by other users, or select
666 * a file with the private key(s) when setting up their own channels
667 * FIXME: we'll likely want to use NOT the p521 curve here, but a cheaper
669 * @param policy Channel policy specifying join and history restrictions.
670 * Used to automate join decisions.
671 * @param master_start_cb Function to invoke after the channel master started.
672 * @param join_request_cb Function to invoke when a slave wants to join.
673 * @param message_cb Function to invoke on message parts sent to the channel
674 * and received from slaves
675 * @param cls Closure for @a method and @a join_cb.
677 * @return Handle for the channel master, NULL on error.
679 struct GNUNET_PSYC_Master *
680 GNUNET_PSYC_master_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
681 const struct GNUNET_CRYPTO_EddsaPrivateKey *channel_key,
682 enum GNUNET_PSYC_Policy policy,
683 GNUNET_PSYC_MasterStartCallback master_start_cb,
684 GNUNET_PSYC_JoinRequestCallback join_request_cb,
685 GNUNET_PSYC_MessageCallback message_cb,
686 GNUNET_PSYC_MessagePartCallback message_part_cb,
691 * Function called to provide data for a transmission via PSYC.
693 * Note that returning #GNUNET_YES or #GNUNET_SYSERR (but not #GNUNET_NO)
694 * invalidates the respective transmission handle.
696 * @param cls Closure.
697 * @param[in,out] data_size Initially set to the number of bytes available in
698 * @a data, should be set to the number of bytes written to data.
699 * @param[out] data Where to write the body of the message to give to the
700 * method. The function must copy at most @a data_size bytes to @a data.
701 * @return #GNUNET_SYSERR on error (fatal, aborts transmission)
702 * #GNUNET_NO on success, if more data is to be transmitted later.
703 * Should be used if @a data_size was not big enough to take all the
704 * data. If 0 is returned in @a data_size the transmission is paused,
705 * and can be resumed with GNUNET_PSYC_master_transmit_resume().
706 * #GNUNET_YES if this completes the transmission (all data supplied)
709 (*GNUNET_PSYC_TransmitNotifyData) (void *cls,
714 * Function called to provide a modifier for a transmission via PSYC.
716 * Note that returning #GNUNET_YES or #GNUNET_SYSERR (but not #GNUNET_NO)
717 * invalidates the respective transmission handle.
719 * @param cls Closure.
720 * @param[in,out] data_size Initially set to the number of bytes available in
721 * @a data, should be set to the number of bytes written to data.
722 * @param[out] data Where to write the modifier's name and value.
723 * The function must copy at most @a data_size bytes to @a data.
724 * When this callback is first called for a modifier, @a data should
725 * contain: "name\0value". If the whole value does not fit, subsequent
726 * calls to this function should write continuations of the value to
728 * @param[out] oper Where to write the operator of the modifier.
729 * Only needed during the first call to this callback at the beginning
730 * of the modifier. In case of subsequent calls asking for value
731 * continuations @a oper is set to #NULL.
732 * @param[out] full_value_size Where to write the full size of the value.
733 * Only needed during the first call to this callback at the beginning
734 * of the modifier. In case of subsequent calls asking for value
735 * continuations @a value_size is set to #NULL.
736 * @return #GNUNET_SYSERR on error (fatal, aborts transmission)
737 * #GNUNET_NO on success, if more data is to be transmitted later.
738 * Should be used if @a data_size was not big enough to take all the
739 * data for the modifier's value (the name must be always returned
740 * during the first call to this callback).
741 * If 0 is returned in @a data_size the transmission is paused,
742 * and can be resumed with GNUNET_PSYC_master_transmit_resume().
743 * #GNUNET_YES if this completes the modifier (the whole value is supplied).
746 (*GNUNET_PSYC_TransmitNotifyModifier) (void *cls,
750 uint32_t *full_value_size);
753 * Flags for transmitting messages to a channel by the master.
755 enum GNUNET_PSYC_MasterTransmitFlags
757 GNUNET_PSYC_MASTER_TRANSMIT_NONE = 0,
760 * Whether this message should reset the channel state,
761 * i.e. remove all previously stored state variables.
764 GNUNET_PSYC_MASTER_TRANSMIT_STATE_RESET = 1 << 0,
767 * Whether this message contains any state modifiers.
769 GNUNET_PSYC_MASTER_TRANSMIT_STATE_MODIFY = 1 << 1,
772 * Add PSYC header variable with the hash of the current channel state.
774 GNUNET_PSYC_MASTER_TRANSMIT_STATE_HASH = 1 << 2,
777 * Whether we need to increment the group generation counter after
778 * transmitting this message.
780 GNUNET_PSYC_MASTER_TRANSMIT_INC_GROUP_GEN = 1 << 3
785 * Handle for a pending PSYC transmission operation.
787 struct GNUNET_PSYC_MasterTransmitHandle;
791 * Send a message to call a method to all members in the PSYC channel.
793 * @param master Handle to the PSYC channel.
794 * @param method_name Which method should be invoked.
795 * @param notify_mod Function to call to obtain modifiers.
796 * @param notify_data Function to call to obtain fragments of the data.
797 * @param notify_cls Closure for @a notify_mod and @a notify_data.
798 * @param flags Flags for the message being transmitted.
799 * @return Transmission handle, NULL on error (i.e. more than one request queued).
801 struct GNUNET_PSYC_MasterTransmitHandle *
802 GNUNET_PSYC_master_transmit (struct GNUNET_PSYC_Master *master,
803 const char *method_name,
804 GNUNET_PSYC_TransmitNotifyModifier notify_mod,
805 GNUNET_PSYC_TransmitNotifyData notify_data,
807 enum GNUNET_PSYC_MasterTransmitFlags flags);
811 * Resume transmission to the channel.
813 * @param th Handle of the request that is being resumed.
816 GNUNET_PSYC_master_transmit_resume (struct GNUNET_PSYC_MasterTransmitHandle *th);
820 * Abort transmission request to channel.
822 * @param th Handle of the request that is being aborted.
825 GNUNET_PSYC_master_transmit_cancel (struct GNUNET_PSYC_MasterTransmitHandle *th);
831 * @param master Handle to the PSYC channel.
832 * @param method_name Which method should be invoked.
833 * @param notify_mod Function to call to obtain modifiers.
834 * @param notify_data Function to call to obtain fragments of the data.
835 * @param notify_cls Closure for @a notify_mod and @a notify_data.
836 * @param flags Flags for the message being transmitted.
837 * @return Transmission handle, NULL on error (i.e. more than one request queued).
839 struct GNUNET_PSYC_MasterTransmitHandle *
840 GNUNET_PSYC_master_relay (struct GNUNET_PSYC_Master *master,
841 uint64_t message_id);
845 * Stop a PSYC master channel.
848 * PSYC channel master to stop.
850 * Keep place active after last application disconnected.
852 * Function called after the master stopped
853 * and disconnected from the psyc service.
855 * Closure for @a part_cb.
858 GNUNET_PSYC_master_stop (struct GNUNET_PSYC_Master *master,
860 GNUNET_ContinuationCallback stop_cb,
865 * Handle for a PSYC channel slave.
867 struct GNUNET_PSYC_Slave;
871 * Function called after the slave connected to the PSYC service.
873 * Also called when reconnected to the service
874 * after the connection closed unexpectedly.
879 * #GNUNET_YES if there were already messages sent to the channel,
880 * #GNUNET_NO if the message history is empty,
881 * #GNUNET_SYSERR on error.
882 * @param max_message_id
883 * Last message ID sent to the channel.
886 (*GNUNET_PSYC_SlaveConnectCallback) (void *cls, int result,
887 uint64_t max_message_id);
891 * Method called to inform about the decision in response to a join request.
893 * If @a is_admitted is not #GNUNET_YES, then sending messages to the channel is
894 * not possible, but earlier history can be still queried.
896 * @param cls Closure.
897 * @param is_admitted #GNUNET_YES or #GNUNET_NO or #GNUNET_SYSERR
898 * @param join_msg Application-dependent join message from the origin.
901 (*GNUNET_PSYC_JoinDecisionCallback) (void *cls,
902 const struct GNUNET_PSYC_JoinDecisionMessage *dcsn,
904 const struct GNUNET_PSYC_Message *join_msg);
907 * Flags for GNUNET_PSYC_slave_join()
909 enum GNUNET_PSYC_SlaveJoinFlags
911 GNUNET_PSYC_SLAVE_JOIN_NONE = 0,
914 * Local join for history access, no network connection is established.
916 GNUNET_PSYC_SLAVE_JOIN_LOCAL = 1,
921 * Join a PSYC channel.
923 * The entity joining is always the local peer. The user must immediately use
924 * the GNUNET_PSYC_slave_transmit() functions to transmit a @e join_msg to the
925 * channel; if the join request succeeds, the channel state (and @e recent
926 * method calls) will be replayed to the joining member. There is no explicit
927 * notification on failure (as the channel may simply take days to approve,
928 * and disapproval is simply being ignored).
931 * Configuration to use.
932 * @param channel_pub_key
933 * ECC public key that identifies the channel we wish to join.
934 * @param slave_pub_key
935 * ECC private-public key pair that identifies the slave, and
936 * used by multicast to sign the join request and subsequent unicast
937 * requests sent to the master.
941 * Peer identity of the origin.
943 * Number of peers in the @a relays array.
945 * Peer identities of members of the multicast group, which serve
946 * as relays and used to join the group at.
948 * Function to invoke on message fragments received from the channel.
949 * @param message_part_cb
950 * Function to invoke on message parts received from the channel.
951 * @param slave_connect_cb
952 * Function invoked once we have connected to the PSYC service.
953 * @param join_decision_cb
954 * Function invoked once we have received a join decision.
956 * Closure for @a message_cb and @a slave_joined_cb.
960 * @return Handle for the slave, NULL on error.
962 struct GNUNET_PSYC_Slave *
963 GNUNET_PSYC_slave_join (const struct GNUNET_CONFIGURATION_Handle *cfg,
964 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_pub_key,
965 const struct GNUNET_CRYPTO_EcdsaPrivateKey *slave_pub_key,
966 enum GNUNET_PSYC_SlaveJoinFlags flags,
967 const struct GNUNET_PeerIdentity *origin,
968 uint32_t relay_count,
969 const struct GNUNET_PeerIdentity *relays,
970 GNUNET_PSYC_MessageCallback message_cb,
971 GNUNET_PSYC_MessagePartCallback message_part_cb,
972 GNUNET_PSYC_SlaveConnectCallback slave_connect_cb,
973 GNUNET_PSYC_JoinDecisionCallback join_decision_cb,
975 const struct GNUNET_PSYC_Message *join_msg);
979 * Part a PSYC channel.
981 * Will terminate the connection to the PSYC service. Polite clients should
982 * first explicitly send a part request (via GNUNET_PSYC_slave_transmit()).
987 * Keep place active after last application disconnected.
989 * Function called after the slave parted the channel
990 * and disconnected from the psyc service.
992 * Closure for @a part_cb.
995 GNUNET_PSYC_slave_part (struct GNUNET_PSYC_Slave *slave,
997 GNUNET_ContinuationCallback part_cb,
1002 * Flags for transmitting messages to the channel master by a slave.
1004 enum GNUNET_PSYC_SlaveTransmitFlags
1006 GNUNET_PSYC_SLAVE_TRANSMIT_NONE = 0
1011 * Handle for a pending PSYC transmission operation.
1013 struct GNUNET_PSYC_SlaveTransmitHandle;
1017 * Request a message to be sent to the channel master.
1019 * @param slave Slave handle.
1020 * @param method_name Which (PSYC) method should be invoked (on host).
1021 * @param notify_mod Function to call to obtain modifiers.
1022 * @param notify_data Function to call to obtain fragments of the data.
1023 * @param notify_cls Closure for @a notify.
1024 * @param flags Flags for the message being transmitted.
1025 * @return Transmission handle, NULL on error (i.e. more than one request queued).
1027 struct GNUNET_PSYC_SlaveTransmitHandle *
1028 GNUNET_PSYC_slave_transmit (struct GNUNET_PSYC_Slave *slave,
1029 const char *method_name,
1030 GNUNET_PSYC_TransmitNotifyModifier notify_mod,
1031 GNUNET_PSYC_TransmitNotifyData notify_data,
1033 enum GNUNET_PSYC_SlaveTransmitFlags flags);
1037 * Resume transmission to the master.
1039 * @param th Handle of the request that is being resumed.
1042 GNUNET_PSYC_slave_transmit_resume (struct GNUNET_PSYC_SlaveTransmitHandle *th);
1046 * Abort transmission request to master.
1048 * @param th Handle of the request that is being aborted.
1051 GNUNET_PSYC_slave_transmit_cancel (struct GNUNET_PSYC_SlaveTransmitHandle *th);
1055 * Handle to access PSYC channel operations for both the master and slaves.
1057 struct GNUNET_PSYC_Channel;
1061 * Convert a channel @a master to a @e channel handle to access the @e channel
1064 * @param master Channel master handle.
1065 * @return Channel handle, valid for as long as @a master is valid.
1067 struct GNUNET_PSYC_Channel *
1068 GNUNET_PSYC_master_get_channel (struct GNUNET_PSYC_Master *master);
1072 * Convert @a slave to a @e channel handle to access the @e channel APIs.
1074 * @param slave Slave handle.
1075 * @return Channel handle, valid for as long as @a slave is valid.
1077 struct GNUNET_PSYC_Channel *
1078 GNUNET_PSYC_slave_get_channel (struct GNUNET_PSYC_Slave *slave);
1082 * Add a slave to the channel's membership list.
1084 * Note that this will NOT generate any PSYC traffic, it will merely update the
1085 * local database to modify how we react to <em>membership test</em> queries.
1086 * The channel master still needs to explicitly transmit a @e join message to
1087 * notify other channel members and they then also must still call this function
1088 * in their respective methods handling the @e join message. This way, how @e
1089 * join and @e part operations are exactly implemented is still up to the
1090 * application; for example, there might be a @e part_all method to kick out
1093 * Note that channel slaves are explicitly trusted to execute such methods
1094 * correctly; not doing so correctly will result in either denying other slaves
1095 * access or offering access to channel data to non-members.
1099 * @param slave_pub_key
1100 * Identity of channel slave to add.
1101 * @param announced_at
1102 * ID of the message that announced the membership change.
1103 * @param effective_since
1104 * Addition of slave is in effect since this message ID.
1106 * Function to call with the result of the operation.
1107 * The @e result_code argument is #GNUNET_OK on success, or
1108 * #GNUNET_SYSERR on error. In case of an error, the @e data argument
1109 * can contain an optional error message.
1111 * Closure for @a result_cb.
1114 GNUNET_PSYC_channel_slave_add (struct GNUNET_PSYC_Channel *channel,
1115 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_pub_key,
1116 uint64_t announced_at,
1117 uint64_t effective_since,
1118 GNUNET_ResultCallback result_cb,
1123 * Remove a slave from the channel's membership list.
1125 * Note that this will NOT generate any PSYC traffic, it will merely update the
1126 * local database to modify how we react to <em>membership test</em> queries.
1127 * The channel master still needs to explicitly transmit a @e part message to
1128 * notify other channel members and they then also must still call this function
1129 * in their respective methods handling the @e part message. This way, how
1130 * @e join and @e part operations are exactly implemented is still up to the
1131 * application; for example, there might be a @e part_all message to kick out
1134 * Note that channel members are explicitly trusted to perform these
1135 * operations correctly; not doing so correctly will result in either
1136 * denying members access or offering access to channel data to
1141 * @param slave_pub_key
1142 * Identity of channel slave to remove.
1143 * @param announced_at
1144 * ID of the message that announced the membership change.
1146 * Function to call with the result of the operation.
1147 * The @e result_code argument is #GNUNET_OK on success, or
1148 * #GNUNET_SYSERR on error. In case of an error, the @e data argument
1149 * can contain an optional error message.
1151 * Closure for @a result_cb.
1154 GNUNET_PSYC_channel_slave_remove (struct GNUNET_PSYC_Channel *channel,
1155 const struct GNUNET_CRYPTO_EcdsaPublicKey
1157 uint64_t announced_at,
1158 GNUNET_ResultCallback result_cb,
1163 * History request handle.
1165 struct GNUNET_PSYC_HistoryRequest;
1169 * Request to replay a part of the message history of the channel.
1171 * Historic messages (but NOT the state at the time) will be replayed (given to
1172 * the normal method handlers) if available and if access is permitted.
1175 * Which channel should be replayed?
1176 * @param start_message_id
1177 * Earliest interesting point in history.
1178 * @param end_message_id
1179 * Last (inclusive) interesting point in history.
1180 * @param method_prefix
1181 * Retrieve only messages with a matching method prefix.
1183 * OR'ed enum GNUNET_PSYC_HistoryReplayFlags
1185 * Function to call when the requested history has been fully replayed.
1186 * Once this function has been called, the client must not call
1187 * GNUNET_PSYC_channel_history_replay_cancel() anymore.
1189 * Closure for the callbacks.
1191 * @return Handle to cancel history replay operation.
1193 struct GNUNET_PSYC_HistoryRequest *
1194 GNUNET_PSYC_channel_history_replay (struct GNUNET_PSYC_Channel *channel,
1195 uint64_t start_message_id,
1196 uint64_t end_message_id,
1197 const char *method_prefix,
1199 GNUNET_PSYC_MessageCallback message_cb,
1200 GNUNET_PSYC_MessagePartCallback message_part_cb,
1201 GNUNET_ResultCallback result_cb,
1206 * Request to replay the latest messages from the message history of the channel.
1208 * Historic messages (but NOT the state at the time) will be replayed (given to
1209 * the normal method handlers) if available and if access is permitted.
1212 * Which channel should be replayed?
1213 * @param message_limit
1214 * Maximum number of messages to replay.
1216 * OR'ed enum GNUNET_PSYC_HistoryReplayFlags
1218 * Function to call when the requested history has been fully replayed
1219 * (counting message IDs might not suffice, as some messages might be
1220 * secret and thus the listener would not know the story is finished
1221 * without being told explicitly)o once this function has been called, the
1222 * client must not call GNUNET_PSYC_channel_history_replay_cancel() anymore.
1224 * Closure for the callbacks.
1226 * @return Handle to cancel history replay operation.
1228 struct GNUNET_PSYC_HistoryRequest *
1229 GNUNET_PSYC_channel_history_replay_latest (struct GNUNET_PSYC_Channel *channel,
1230 uint64_t message_limit,
1231 const char *method_prefix,
1233 GNUNET_PSYC_MessageCallback message_cb,
1234 GNUNET_PSYC_MessagePartCallback message_part_cb,
1235 GNUNET_ResultCallback result_cb,
1240 GNUNET_PSYC_channel_history_replay_cancel (struct GNUNET_PSYC_Channel *channel,
1241 struct GNUNET_PSYC_HistoryRequest *hr);
1245 * Function called to inform a member about stored state values for a channel.
1247 * If @a full_value_size > value_size then this function is called multiple
1248 * times until the whole value arrived.
1253 * Name of the state variable.
1254 * NULL if there are no more state variables to be returned.
1256 * Value of the state variable.
1258 * Number of bytes in @a value.
1259 * @param full_value_size
1260 * Number of bytes in the full value, including continuations.
1261 * Only set for the first part of a variable,
1262 * in case of a continuation it is 0.
1265 (*GNUNET_PSYC_StateVarCallback) (void *cls,
1266 const struct GNUNET_MessageHeader *mod,
1269 uint32_t value_size,
1270 uint32_t full_value_size);
1274 * State request handle.
1276 struct GNUNET_PSYC_StateRequest;
1280 * Retrieve the best matching channel state variable.
1282 * If the requested variable name is not present in the state, the nearest
1283 * less-specific name is matched; for example, requesting "_a_b" will match "_a"
1284 * if "_a_b" does not exist.
1289 * Full name of the requested variable.
1290 * The actual variable returned might have a shorter name.
1292 * Function called once when a matching state variable is found.
1293 * Not called if there's no matching state variable.
1295 * Function called after the operation finished.
1296 * (i.e. all state variables have been returned via @a state_cb)
1298 * Closure for the callbacks.
1300 struct GNUNET_PSYC_StateRequest *
1301 GNUNET_PSYC_channel_state_get (struct GNUNET_PSYC_Channel *channel,
1302 const char *full_name,
1303 GNUNET_PSYC_StateVarCallback var_cb,
1304 GNUNET_ResultCallback result_cb,
1309 * Return all channel state variables whose name matches a given prefix.
1311 * A name matches if it starts with the given @a name_prefix, thus requesting
1312 * the empty prefix ("") will match all values; requesting "_a_b" will also
1313 * return values stored under "_a_b_c".
1315 * The @a state_cb is invoked on all matching state variables asynchronously, as
1316 * the state is stored in and retrieved from the PSYCstore,
1320 * @param name_prefix
1321 * Prefix of the state variable name to match.
1323 * Function called once when a matching state variable is found.
1324 * Not called if there's no matching state variable.
1326 * Function called after the operation finished.
1327 * (i.e. all state variables have been returned via @a state_cb)
1329 * Closure for the callbacks.
1331 struct GNUNET_PSYC_StateRequest *
1332 GNUNET_PSYC_channel_state_get_prefix (struct GNUNET_PSYC_Channel *channel,
1333 const char *name_prefix,
1334 GNUNET_PSYC_StateVarCallback var_cb,
1335 GNUNET_ResultCallback result_cb,
1339 * Cancel a state request operation.
1342 * Handle for the operation to cancel.
1345 GNUNET_PSYC_channel_state_get_cancel (struct GNUNET_PSYC_StateRequest *sr);
1349 #if 0 /* keep Emacsens' auto-indent happy */
1356 /* ifndef GNUNET_PSYC_SERVICE_H */
1359 /** @} */ /* end of group */