2 This file is part of GNUnet.
3 Copyright (C) 2012, 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., 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.
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.
88 GNUNET_PSYC_message_parse (const struct GNUNET_PSYC_MessageHeader *msg,
89 const char **method_name,
90 struct GNUNET_PSYC_Environment *env,
96 GNUNET_PSYC_log_message (enum GNUNET_ErrorType kind,
97 const struct GNUNET_MessageHeader *msg);
101 GNUNET_PSYC_check_message_parts (uint16_t data_size, const char *data,
102 uint16_t *first_ptype, uint16_t *last_ptype);
105 struct GNUNET_PSYC_TransmitHandle;
108 * Create a transmission handle.
110 struct GNUNET_PSYC_TransmitHandle *
111 GNUNET_PSYC_transmit_create ();
115 * Destroy a transmission handle.
118 GNUNET_PSYC_transmit_destroy (struct GNUNET_PSYC_TransmitHandle *tmit);
122 * Transmit a message.
125 * Transmission handle.
127 * Which method should be invoked.
129 * Environment for the message.
130 * Should stay available until the first call to notify_data.
131 * Can be NULL if there are no modifiers or @a notify_mod is
134 * Function to call to obtain modifiers.
135 * Can be NULL if there are no modifiers or @a env is provided instead.
137 * Function to call to obtain fragments of the data.
139 * Closure for @a notify_mod and @a notify_data.
141 * Flags for the message being transmitted.
143 * @return #GNUNET_OK if the transmission was started.
144 * #GNUNET_SYSERR if another transmission is already going on.
147 GNUNET_PSYC_transmit_message (struct GNUNET_PSYC_TransmitHandle *tmit,
148 const char *method_name,
149 const struct GNUNET_PSYC_Environment *env,
150 GNUNET_PSYC_TransmitNotifyModifier notify_mod,
151 GNUNET_PSYC_TransmitNotifyData notify_data,
157 * Resume transmission.
159 * @param tmit Transmission handle.
162 GNUNET_PSYC_transmit_resume (struct GNUNET_PSYC_TransmitHandle *tmit);
166 * Abort transmission request.
168 * @param tmit Transmission handle.
171 GNUNET_PSYC_transmit_cancel (struct GNUNET_PSYC_TransmitHandle *tmit);
175 * Got acknowledgement of a transmitted message part, continue transmission.
177 * @param tmit Transmission handle.
180 GNUNET_PSYC_transmit_got_ack (struct GNUNET_PSYC_TransmitHandle *tmit);
183 struct GNUNET_PSYC_ReceiveHandle;
187 * Create handle for receiving messages.
189 struct GNUNET_PSYC_ReceiveHandle *
190 GNUNET_PSYC_receive_create (GNUNET_PSYC_MessageCallback message_cb,
191 GNUNET_PSYC_MessagePartCallback message_part_cb,
196 * Destroy handle for receiving messages.
199 GNUNET_PSYC_receive_destroy (struct GNUNET_PSYC_ReceiveHandle *recv);
203 * Reset stored data related to the last received message.
206 GNUNET_PSYC_receive_reset (struct GNUNET_PSYC_ReceiveHandle *recv);
210 * Handle incoming PSYC message.
212 * @param recv Receive handle.
213 * @param msg The message.
215 * @return #GNUNET_OK on success,
216 * #GNUNET_SYSERR on receive error.
219 GNUNET_PSYC_receive_message (struct GNUNET_PSYC_ReceiveHandle *recv,
220 const struct GNUNET_PSYC_MessageHeader *msg);
224 * Check if @a data contains a series of valid message parts.
226 * @param data_size Size of @a data.
228 * @param[out] first_ptype Type of first message part.
229 * @param[out] last_ptype Type of last message part.
231 * @return Number of message parts found in @a data.
232 * or GNUNET_SYSERR if the message contains invalid parts.
235 GNUNET_PSYC_receive_check_parts (uint16_t data_size, const char *data,
236 uint16_t *first_ptype, uint16_t *last_ptype);
240 * Initialize PSYC message header.
243 GNUNET_PSYC_message_header_init (struct GNUNET_PSYC_MessageHeader *pmsg,
244 const struct GNUNET_MULTICAST_MessageHeader *mmsg,
249 * Create a new PSYC message header from a multicast message for sending it to clients.
251 struct GNUNET_PSYC_MessageHeader *
252 GNUNET_PSYC_message_header_create (const struct GNUNET_MULTICAST_MessageHeader *mmsg,
257 * Create a new PSYC message header from a PSYC message.
259 struct GNUNET_PSYC_MessageHeader *
260 GNUNET_PSYC_message_header_create_from_psyc (const struct GNUNET_PSYC_Message *msg);
263 #if 0 /* keep Emacsens' auto-indent happy */
270 /* ifndef GNUNET_PSYC_MESSAGE_H */
273 /** @} */ /* end of group */