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.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * @author Gabor X Toth
23 * PSYC message utilities; receiving/transmitting/logging PSYC messages
25 * @defgroup psyc-util-message PSYC Utilities library: Messages
26 * Receiving, transmitting, logging PSYC messages.
30 #ifndef GNUNET_PSYC_MESSAGE_H
31 #define GNUNET_PSYC_MESSAGE_H
36 #if 0 /* keep Emacsens' auto-indent happy */
42 #include "gnunet_util_lib.h"
43 #include "gnunet_psyc_util_lib.h"
44 #include "gnunet_psyc_service.h"
48 * Create a PSYC message.
51 * PSYC method for the message.
53 * Environment for the message.
55 * Data payload for the message.
59 * @return Message header with size information,
60 * followed by the message parts.
64 struct GNUNET_PSYC_Message *
65 GNUNET_PSYC_message_create (const char *method_name,
66 const struct GNUNET_PSYC_Environment *env,
74 * The PSYC message to parse.
76 * The environment for the message with a list of modifiers.
77 * @param[out] method_name
78 * Pointer to the method name inside @a pmsg.
80 * Pointer to data inside @a pmsg.
81 * @param[out] data_size
82 * Size of @data is written here.
84 * @return #GNUNET_OK on success,
85 * #GNUNET_SYSERR on parse error.
90 GNUNET_PSYC_message_parse (const struct GNUNET_PSYC_MessageHeader *msg,
91 const char **method_name,
92 struct GNUNET_PSYC_Environment *env,
98 GNUNET_PSYC_log_message (enum GNUNET_ErrorType kind,
99 const struct GNUNET_MessageHeader *msg);
102 struct GNUNET_PSYC_TransmitHandle;
105 * Create a transmission handle.
107 struct GNUNET_PSYC_TransmitHandle *
108 GNUNET_PSYC_transmit_create (struct GNUNET_MQ_Handle *mq);
112 * Destroy a transmission handle.
115 GNUNET_PSYC_transmit_destroy (struct GNUNET_PSYC_TransmitHandle *tmit);
119 * Transmit a message.
122 * Transmission handle.
124 * Which method should be invoked.
126 * Environment for the message.
127 * Should stay available until the first call to notify_data.
128 * Can be NULL if there are no modifiers or @a notify_mod is
131 * Function to call to obtain modifiers.
132 * Can be NULL if there are no modifiers or @a env is provided instead.
134 * Function to call to obtain fragments of the data.
136 * Closure for @a notify_mod and @a notify_data.
138 * Flags for the message being transmitted.
140 * @return #GNUNET_OK if the transmission was started.
141 * #GNUNET_SYSERR if another transmission is already going on.
144 GNUNET_PSYC_transmit_message (struct GNUNET_PSYC_TransmitHandle *tmit,
145 const char *method_name,
146 const struct GNUNET_PSYC_Environment *env,
147 GNUNET_PSYC_TransmitNotifyModifier notify_mod,
148 GNUNET_PSYC_TransmitNotifyData notify_data,
154 * Resume transmission.
156 * @param tmit Transmission handle.
159 GNUNET_PSYC_transmit_resume (struct GNUNET_PSYC_TransmitHandle *tmit);
163 * Abort transmission request.
165 * @param tmit Transmission handle.
168 GNUNET_PSYC_transmit_cancel (struct GNUNET_PSYC_TransmitHandle *tmit);
172 * Got acknowledgement of a transmitted message part, continue transmission.
174 * @param tmit Transmission handle.
177 GNUNET_PSYC_transmit_got_ack (struct GNUNET_PSYC_TransmitHandle *tmit);
180 struct GNUNET_PSYC_ReceiveHandle;
184 * Create handle for receiving messages.
186 struct GNUNET_PSYC_ReceiveHandle *
187 GNUNET_PSYC_receive_create (GNUNET_PSYC_MessageCallback message_cb,
188 GNUNET_PSYC_MessagePartCallback message_part_cb,
193 * Destroy handle for receiving messages.
196 GNUNET_PSYC_receive_destroy (struct GNUNET_PSYC_ReceiveHandle *recv);
200 * Reset stored data related to the last received message.
203 GNUNET_PSYC_receive_reset (struct GNUNET_PSYC_ReceiveHandle *recv);
207 * Handle incoming PSYC message.
214 * @return #GNUNET_OK on success,
215 * #GNUNET_SYSERR on receive error.
218 GNUNET_PSYC_receive_message (struct GNUNET_PSYC_ReceiveHandle *recv,
219 const struct GNUNET_PSYC_MessageHeader *msg);
223 * Check if @a data contains a series of valid message parts.
229 * @param[out] first_ptype
230 * Type of first message part.
231 * @param[out] last_ptype
232 * Type of last message part.
234 * @return Number of message parts found in @a data.
235 * or GNUNET_SYSERR if the message contains invalid parts.
238 GNUNET_PSYC_receive_check_parts (uint16_t data_size, const char *data,
239 uint16_t *first_ptype, uint16_t *last_ptype);
243 * Initialize PSYC message header.
246 GNUNET_PSYC_message_header_init (struct GNUNET_PSYC_MessageHeader *pmsg,
247 const struct GNUNET_MULTICAST_MessageHeader *mmsg,
252 * Create a new PSYC message header from a multicast message for sending it to clients.
254 struct GNUNET_PSYC_MessageHeader *
255 GNUNET_PSYC_message_header_create (const struct GNUNET_MULTICAST_MessageHeader *mmsg,
260 * Create a new PSYC message header from a PSYC message.
262 struct GNUNET_PSYC_MessageHeader *
263 GNUNET_PSYC_message_header_create_from_psyc (const struct GNUNET_PSYC_Message *msg);
266 #if 0 /* keep Emacsens' auto-indent happy */
273 /* ifndef GNUNET_PSYC_MESSAGE_H */
276 /** @} */ /* end of group */