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