doxygen: group/module definitions (part 2)
[oweals/gnunet.git] / src / include / gnunet_psyc_util_lib.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2012, 2013 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19 */
20
21 /**
22  * @author Gabor X Toth
23  *
24  * @file
25  * PSYC utilities; receiving/transmitting/logging PSYC messages
26  *
27  * @defgroup psyc-util  PSYC Utilities library
28  * Receiving, transmitting, logging PSYC messages.
29  * @{
30  */
31
32 #ifndef GNUNET_PSYC_UTIL_LIB_H
33 #define GNUNET_PSYC_UTIL_LIB_H
34
35 #ifdef __cplusplus
36 extern "C"
37 {
38 #if 0                           /* keep Emacsens' auto-indent happy */
39 }
40 #endif
41 #endif
42
43 #include "gnunet_util_lib.h"
44 #include "gnunet_env_lib.h"
45 #include "gnunet_psyc_service.h"
46
47
48 /**
49  * Create a PSYC message.
50  *
51  * @param method_name
52  *        PSYC method for the message.
53  * @param env
54  *        Environment for the message.
55  * @param data
56  *        Data payload for the message.
57  * @param data_size
58  *        Size of @a data.
59  *
60  * @return Message header with size information,
61  *         followed by the message parts.
62  */
63 struct GNUNET_PSYC_Message *
64 GNUNET_PSYC_message_create (const char *method_name,
65                             const struct GNUNET_ENV_Environment *env,
66                             const void *data,
67                             size_t data_size);
68
69 /**
70  * Parse PSYC message.
71  *
72  * @param msg
73  *        The PSYC message to parse.
74  * @param env
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.
78  * @param[out] data
79  *        Pointer to data inside @a pmsg.
80  * @param[out] data_size
81  *        Size of @data is written here.
82  *
83  * @return #GNUNET_OK on success,
84  *         #GNUNET_SYSERR on parse error.
85  */
86 int
87 GNUNET_PSYC_message_parse (const struct GNUNET_PSYC_MessageHeader *msg,
88                            const char **method_name,
89                            struct GNUNET_ENV_Environment *env,
90                            const void **data,
91                            uint16_t *data_size);
92
93
94 void
95 GNUNET_PSYC_log_message (enum GNUNET_ErrorType kind,
96                          const struct GNUNET_MessageHeader *msg);
97
98
99 int
100 GNUNET_PSYC_check_message_parts (uint16_t data_size, const char *data,
101                                  uint16_t *first_ptype, uint16_t *last_ptype);
102
103
104 struct GNUNET_PSYC_TransmitHandle;
105
106 /**
107  * Create a transmission handle.
108  */
109 struct GNUNET_PSYC_TransmitHandle *
110 GNUNET_PSYC_transmit_create ();
111
112
113 /**
114  * Destroy a transmission handle.
115  */
116 void
117 GNUNET_PSYC_transmit_destroy (struct GNUNET_PSYC_TransmitHandle *tmit);
118
119
120 /**
121  * Transmit a message.
122  *
123  * @param tmit
124  *        Transmission handle.
125  * @param method_name
126  *        Which method should be invoked.
127  * @param env
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
131  *        provided instead.
132  * @param notify_mod
133  *        Function to call to obtain modifiers.
134  *        Can be NULL if there are no modifiers or @a env is provided instead.
135  * @param notify_data
136  *        Function to call to obtain fragments of the data.
137  * @param notify_cls
138  *        Closure for @a notify_mod and @a notify_data.
139  * @param flags
140  *        Flags for the message being transmitted.
141  *
142  * @return #GNUNET_OK if the transmission was started.
143  *         #GNUNET_SYSERR if another transmission is already going on.
144  */
145 int
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,
151                               void *notify_cls,
152                               uint32_t flags);
153
154
155 /**
156  * Resume transmission.
157  *
158  * @param tmit  Transmission handle.
159  */
160 void
161 GNUNET_PSYC_transmit_resume (struct GNUNET_PSYC_TransmitHandle *tmit);
162
163
164 /**
165  * Abort transmission request.
166  *
167  * @param tmit  Transmission handle.
168  */
169 void
170 GNUNET_PSYC_transmit_cancel (struct GNUNET_PSYC_TransmitHandle *tmit);
171
172
173 /**
174  * Got acknowledgement of a transmitted message part, continue transmission.
175  *
176  * @param tmit  Transmission handle.
177  */
178 void
179 GNUNET_PSYC_transmit_got_ack (struct GNUNET_PSYC_TransmitHandle *tmit);
180
181
182 struct GNUNET_PSYC_ReceiveHandle;
183
184
185 /**
186  * Create handle for receiving messages.
187  */
188 struct GNUNET_PSYC_ReceiveHandle *
189 GNUNET_PSYC_receive_create (GNUNET_PSYC_MessageCallback message_cb,
190                             GNUNET_PSYC_MessagePartCallback message_part_cb,
191                             void *cb_cls);
192
193
194 /**
195  * Destroy handle for receiving messages.
196  */
197 void
198 GNUNET_PSYC_receive_destroy (struct GNUNET_PSYC_ReceiveHandle *recv);
199
200
201 /**
202  * Reset stored data related to the last received message.
203  */
204 void
205 GNUNET_PSYC_receive_reset (struct GNUNET_PSYC_ReceiveHandle *recv);
206
207
208 /**
209  * Handle incoming PSYC message.
210  *
211  * @param recv  Receive handle.
212  * @param msg   The message.
213  *
214  * @return #GNUNET_OK on success,
215  *         #GNUNET_SYSERR on receive error.
216  */
217 int
218 GNUNET_PSYC_receive_message (struct GNUNET_PSYC_ReceiveHandle *recv,
219                              const struct GNUNET_PSYC_MessageHeader *msg);
220
221
222 /**
223  * Check if @a data contains a series of valid message parts.
224  *
225  * @param      data_size    Size of @a data.
226  * @param      data         Data.
227  * @param[out] first_ptype  Type of first message part.
228  * @param[out] last_ptype   Type of last message part.
229  *
230  * @return Number of message parts found in @a data.
231  *         or GNUNET_SYSERR if the message contains invalid parts.
232  */
233 int
234 GNUNET_PSYC_receive_check_parts (uint16_t data_size, const char *data,
235                                  uint16_t *first_ptype, uint16_t *last_ptype);
236
237
238 /**
239  * Initialize PSYC message header.
240  */
241 void
242 GNUNET_PSYC_message_header_init (struct GNUNET_PSYC_MessageHeader *pmsg,
243                                  const struct GNUNET_MULTICAST_MessageHeader *mmsg,
244                                  uint32_t flags);
245
246
247 /**
248  * Create a new PSYC message header from a multicast message for sending it to clients.
249  */
250 struct GNUNET_PSYC_MessageHeader *
251 GNUNET_PSYC_message_header_create (const struct GNUNET_MULTICAST_MessageHeader *mmsg,
252                                    uint32_t flags);
253
254
255 /**
256  * Create a new PSYC message header from a PSYC message.
257  */
258 struct GNUNET_PSYC_MessageHeader *
259 GNUNET_PSYC_message_header_create_from_psyc (const struct GNUNET_PSYC_Message *msg);
260
261
262 #if 0                           /* keep Emacsens' auto-indent happy */
263 {
264 #endif
265 #ifdef __cplusplus
266 }
267 #endif
268
269 /* ifndef GNUNET_PSYC_UTIL_LIB_H */
270 #endif
271
272 /** @} */  /* end of group */