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
20 * PSYC message utilities; receiving/transmitting/logging PSYC messages
22 * @defgroup psyc-util-message PSYC Utilities library: Messages
23 * Receiving, transmitting, logging PSYC messages.
27 #ifndef GNUNET_PSYC_MESSAGE_H
28 #define GNUNET_PSYC_MESSAGE_H
33 #if 0 /* keep Emacsens' auto-indent happy */
39 #include "gnunet_util_lib.h"
40 #include "gnunet_psyc_util_lib.h"
41 #include "gnunet_psyc_service.h"
45 * Create a PSYC message.
48 * PSYC method for the message.
50 * Environment for the message.
52 * Data payload for the message.
56 * @return Message header with size information,
57 * followed by the message parts.
61 struct GNUNET_PSYC_Message *
62 GNUNET_PSYC_message_create (const char *method_name,
63 const struct GNUNET_PSYC_Environment *env,
71 * The PSYC message to parse.
73 * The environment for the message with a list of modifiers.
74 * @param[out] method_name
75 * Pointer to the method name inside @a pmsg.
77 * Pointer to data inside @a pmsg.
78 * @param[out] data_size
79 * Size of @data is written here.
81 * @return #GNUNET_OK on success,
82 * #GNUNET_SYSERR on parse error.
87 GNUNET_PSYC_message_parse (const struct GNUNET_PSYC_MessageHeader *msg,
88 const char **method_name,
89 struct GNUNET_PSYC_Environment *env,
95 GNUNET_PSYC_log_message (enum GNUNET_ErrorType kind,
96 const struct GNUNET_MessageHeader *msg);
99 struct GNUNET_PSYC_TransmitHandle;
102 * Create a transmission handle.
104 struct GNUNET_PSYC_TransmitHandle *
105 GNUNET_PSYC_transmit_create (struct GNUNET_MQ_Handle *mq);
109 * Destroy a transmission handle.
112 GNUNET_PSYC_transmit_destroy (struct GNUNET_PSYC_TransmitHandle *tmit);
116 * Transmit a message.
119 * Transmission handle.
121 * Which method should be invoked.
123 * Environment for the message.
124 * Should stay available until the first call to notify_data.
125 * Can be NULL if there are no modifiers or @a notify_mod is
128 * Function to call to obtain modifiers.
129 * Can be NULL if there are no modifiers or @a env is provided instead.
131 * Function to call to obtain fragments of the data.
133 * Closure for @a notify_mod and @a notify_data.
135 * Flags for the message being transmitted.
137 * @return #GNUNET_OK if the transmission was started.
138 * #GNUNET_SYSERR if another transmission is already going on.
141 GNUNET_PSYC_transmit_message (struct GNUNET_PSYC_TransmitHandle *tmit,
142 const char *method_name,
143 const struct GNUNET_PSYC_Environment *env,
144 GNUNET_PSYC_TransmitNotifyModifier notify_mod,
145 GNUNET_PSYC_TransmitNotifyData notify_data,
151 * Resume transmission.
153 * @param tmit Transmission handle.
156 GNUNET_PSYC_transmit_resume (struct GNUNET_PSYC_TransmitHandle *tmit);
160 * Abort transmission request.
162 * @param tmit Transmission handle.
165 GNUNET_PSYC_transmit_cancel (struct GNUNET_PSYC_TransmitHandle *tmit);
169 * Got acknowledgement of a transmitted message part, continue transmission.
171 * @param tmit Transmission handle.
174 GNUNET_PSYC_transmit_got_ack (struct GNUNET_PSYC_TransmitHandle *tmit);
177 struct GNUNET_PSYC_ReceiveHandle;
181 * Create handle for receiving messages.
183 struct GNUNET_PSYC_ReceiveHandle *
184 GNUNET_PSYC_receive_create (GNUNET_PSYC_MessageCallback message_cb,
185 GNUNET_PSYC_MessagePartCallback message_part_cb,
190 * Destroy handle for receiving messages.
193 GNUNET_PSYC_receive_destroy (struct GNUNET_PSYC_ReceiveHandle *recv);
197 * Reset stored data related to the last received message.
200 GNUNET_PSYC_receive_reset (struct GNUNET_PSYC_ReceiveHandle *recv);
204 * Handle incoming PSYC message.
211 * @return #GNUNET_OK on success,
212 * #GNUNET_SYSERR on receive error.
215 GNUNET_PSYC_receive_message (struct GNUNET_PSYC_ReceiveHandle *recv,
216 const struct GNUNET_PSYC_MessageHeader *msg);
220 * Check if @a data contains a series of valid message parts.
226 * @param[out] first_ptype
227 * Type of first message part.
228 * @param[out] last_ptype
229 * 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 */