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
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @author Gabor X Toth
25 * PSYC message utilities; receiving/transmitting/logging PSYC messages
27 * @defgroup psyc-util-message PSYC Utilities library: Messages
28 * Receiving, transmitting, logging PSYC messages.
32 #ifndef GNUNET_PSYC_MESSAGE_H
33 #define GNUNET_PSYC_MESSAGE_H
38 #if 0 /* keep Emacsens' auto-indent happy */
44 #include "gnunet_util_lib.h"
45 #include "gnunet_psyc_util_lib.h"
46 #include "gnunet_psyc_service.h"
50 * Create a PSYC message.
53 * PSYC method for the message.
55 * Environment for the message.
57 * Data payload for the message.
61 * @return Message header with size information,
62 * followed by the message parts.
66 struct GNUNET_PSYC_Message *
67 GNUNET_PSYC_message_create (const char *method_name,
68 const struct GNUNET_PSYC_Environment *env,
76 * The PSYC message to parse.
78 * The environment for the message with a list of modifiers.
79 * @param[out] method_name
80 * Pointer to the method name inside @a pmsg.
82 * Pointer to data inside @a pmsg.
83 * @param[out] data_size
84 * Size of @data is written here.
86 * @return #GNUNET_OK on success,
87 * #GNUNET_SYSERR on parse error.
92 GNUNET_PSYC_message_parse (const struct GNUNET_PSYC_MessageHeader *msg,
93 const char **method_name,
94 struct GNUNET_PSYC_Environment *env,
100 GNUNET_PSYC_log_message (enum GNUNET_ErrorType kind,
101 const struct GNUNET_MessageHeader *msg);
104 struct GNUNET_PSYC_TransmitHandle;
107 * Create a transmission handle.
109 struct GNUNET_PSYC_TransmitHandle *
110 GNUNET_PSYC_transmit_create ();
114 * Destroy a transmission handle.
117 GNUNET_PSYC_transmit_destroy (struct GNUNET_PSYC_TransmitHandle *tmit);
121 * Transmit a message.
124 * Transmission handle.
126 * Which method should be invoked.
128 * Environment for the message.
129 * Should stay available until the first call to notify_data.
130 * Can be NULL if there are no modifiers or @a notify_mod is
133 * Function to call to obtain modifiers.
134 * Can be NULL if there are no modifiers or @a env is provided instead.
136 * Function to call to obtain fragments of the data.
138 * Closure for @a notify_mod and @a notify_data.
140 * Flags for the message being transmitted.
142 * @return #GNUNET_OK if the transmission was started.
143 * #GNUNET_SYSERR if another transmission is already going on.
146 GNUNET_PSYC_transmit_message (struct GNUNET_PSYC_TransmitHandle *tmit,
147 const char *method_name,
148 const struct GNUNET_PSYC_Environment *env,
149 GNUNET_PSYC_TransmitNotifyModifier notify_mod,
150 GNUNET_PSYC_TransmitNotifyData notify_data,
156 * Resume transmission.
158 * @param tmit Transmission handle.
161 GNUNET_PSYC_transmit_resume (struct GNUNET_PSYC_TransmitHandle *tmit);
165 * Abort transmission request.
167 * @param tmit Transmission handle.
170 GNUNET_PSYC_transmit_cancel (struct GNUNET_PSYC_TransmitHandle *tmit);
174 * Got acknowledgement of a transmitted message part, continue transmission.
176 * @param tmit Transmission handle.
179 GNUNET_PSYC_transmit_got_ack (struct GNUNET_PSYC_TransmitHandle *tmit);
182 struct GNUNET_PSYC_ReceiveHandle;
186 * Create handle for receiving messages.
188 struct GNUNET_PSYC_ReceiveHandle *
189 GNUNET_PSYC_receive_create (GNUNET_PSYC_MessageCallback message_cb,
190 GNUNET_PSYC_MessagePartCallback message_part_cb,
195 * Destroy handle for receiving messages.
198 GNUNET_PSYC_receive_destroy (struct GNUNET_PSYC_ReceiveHandle *recv);
202 * Reset stored data related to the last received message.
205 GNUNET_PSYC_receive_reset (struct GNUNET_PSYC_ReceiveHandle *recv);
209 * Handle incoming PSYC message.
216 * @return #GNUNET_OK on success,
217 * #GNUNET_SYSERR on receive error.
220 GNUNET_PSYC_receive_message (struct GNUNET_PSYC_ReceiveHandle *recv,
221 const struct GNUNET_PSYC_MessageHeader *msg);
225 * Check if @a data contains a series of valid message parts.
231 * @param[out] first_ptype
232 * Type of first message part.
233 * @param[out] last_ptype
234 * Type of last message part.
236 * @return Number of message parts found in @a data.
237 * or GNUNET_SYSERR if the message contains invalid parts.
240 GNUNET_PSYC_receive_check_parts (uint16_t data_size, const char *data,
241 uint16_t *first_ptype, uint16_t *last_ptype);
245 * Initialize PSYC message header.
248 GNUNET_PSYC_message_header_init (struct GNUNET_PSYC_MessageHeader *pmsg,
249 const struct GNUNET_MULTICAST_MessageHeader *mmsg,
254 * Create a new PSYC message header from a multicast message for sending it to clients.
256 struct GNUNET_PSYC_MessageHeader *
257 GNUNET_PSYC_message_header_create (const struct GNUNET_MULTICAST_MessageHeader *mmsg,
262 * Create a new PSYC message header from a PSYC message.
264 struct GNUNET_PSYC_MessageHeader *
265 GNUNET_PSYC_message_header_create_from_psyc (const struct GNUNET_PSYC_Message *msg);
268 #if 0 /* keep Emacsens' auto-indent happy */
275 /* ifndef GNUNET_PSYC_MESSAGE_H */
278 /** @} */ /* end of group */