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 utilities; receiving/transmitting/logging PSYC messages
27 * @defgroup psyc-util PSYC Utilities library
28 * Receiving, transmitting, logging PSYC messages.
32 #ifndef GNUNET_PSYC_UTIL_LIB_H
33 #define GNUNET_PSYC_UTIL_LIB_H
38 #if 0 /* keep Emacsens' auto-indent happy */
43 #include "gnunet_util_lib.h"
44 #include "gnunet_env_lib.h"
45 #include "gnunet_psyc_service.h"
49 * Create a PSYC message.
52 * PSYC method for the message.
54 * Environment for the message.
56 * Data payload for the message.
60 * @return Message header with size information,
61 * followed by the message parts.
63 struct GNUNET_PSYC_Message *
64 GNUNET_PSYC_message_create (const char *method_name,
65 const struct GNUNET_ENV_Environment *env,
73 * The PSYC message to parse.
75 * The environment for the message with a list of modifiers.
76 * @param[out] method_name
77 * Pointer to the method name inside @a pmsg.
79 * Pointer to data inside @a pmsg.
80 * @param[out] data_size
81 * Size of @data is written here.
83 * @return #GNUNET_OK on success,
84 * #GNUNET_SYSERR on parse error.
87 GNUNET_PSYC_message_parse (const struct GNUNET_PSYC_MessageHeader *msg,
88 const char **method_name,
89 struct GNUNET_ENV_Environment *env,
95 GNUNET_PSYC_log_message (enum GNUNET_ErrorType kind,
96 const struct GNUNET_MessageHeader *msg);
100 GNUNET_PSYC_check_message_parts (uint16_t data_size, const char *data,
101 uint16_t *first_ptype, uint16_t *last_ptype);
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_ENV_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.
211 * @param recv Receive handle.
212 * @param msg The 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.
225 * @param data_size Size of @a data.
227 * @param[out] first_ptype Type of first message part.
228 * @param[out] last_ptype Type of last message part.
230 * @return Number of message parts found in @a data.
231 * or GNUNET_SYSERR if the message contains invalid parts.
234 GNUNET_PSYC_receive_check_parts (uint16_t data_size, const char *data,
235 uint16_t *first_ptype, uint16_t *last_ptype);
239 * Initialize PSYC message header.
242 GNUNET_PSYC_message_header_init (struct GNUNET_PSYC_MessageHeader *pmsg,
243 const struct GNUNET_MULTICAST_MessageHeader *mmsg,
248 * Create a new PSYC message header from a multicast message for sending it to clients.
250 struct GNUNET_PSYC_MessageHeader *
251 GNUNET_PSYC_message_header_create (const struct GNUNET_MULTICAST_MessageHeader *mmsg,
256 * Create a new PSYC message header from a PSYC message.
258 struct GNUNET_PSYC_MessageHeader *
259 GNUNET_PSYC_message_header_create_from_psyc (const struct GNUNET_PSYC_Message *msg);
262 #if 0 /* keep Emacsens' auto-indent happy */
269 /* ifndef GNUNET_PSYC_UTIL_LIB_H */
272 /** @} */ /* end of group */