PSYC(store), Multicast: use ECDSA slave/member keys; PSYC: add GNUNET_PSYC_message_cr...
[oweals/gnunet.git] / src / include / gnunet_psyc_util_lib.h
1 /*
2      This file is part of GNUnet.
3      (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., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file include/gnunet_psyc_service.h
23  * @brief PSYC utilities; receiving/transmitting/logging PSYC messages.
24  * @author Gabor X Toth
25  */
26
27 #ifndef GNUNET_PSYC_UTIL_LIB_H
28 #define GNUNET_PSYC_UTIL_LIB_H
29
30 #ifdef __cplusplus
31 extern "C"
32 {
33 #if 0                           /* keep Emacsens' auto-indent happy */
34 }
35 #endif
36 #endif
37
38 #include "gnunet_util_lib.h"
39 #include "gnunet_env_lib.h"
40 #include "gnunet_psyc_service.h"
41
42
43 /**
44  * Create a PSYC message.
45  *
46  * @param method_name
47  *        PSYC method for the message.
48  * @param env
49  *        Environment for the message.
50  * @param data
51  *        Data payload for the message.
52  * @param data_size
53  *        Size of @a data.
54  *
55  * @return Message header with size information,
56  *         followed by the message parts.
57  */
58 struct GNUNET_MessageHeader *
59 GNUNET_PSYC_message_create (const char *method_name,
60                             const struct GNUNET_ENV_Environment *env,
61                             const void *data,
62                             size_t data_size);
63
64
65 void
66 GNUNET_PSYC_log_message (enum GNUNET_ErrorType kind,
67                          const struct GNUNET_MessageHeader *msg);
68
69
70 int
71 GNUNET_PSYC_check_message_parts (uint16_t data_size, const char *data,
72                                  uint16_t *first_ptype, uint16_t *last_ptype);
73
74
75 struct GNUNET_PSYC_TransmitHandle;
76
77 /**
78  * Create a transmission handle.
79  */
80 struct GNUNET_PSYC_TransmitHandle *
81 GNUNET_PSYC_transmit_create ();
82
83
84 /**
85  * Destroy a transmission handle.
86  */
87 void
88 GNUNET_PSYC_transmit_destroy (struct GNUNET_PSYC_TransmitHandle *tmit);
89
90
91 /**
92  * Transmit a message.
93  *
94  * @param tmit         Transmission handle.
95  * @param method_name  Which method should be invoked.
96  * @param env          Environment for the message.
97  *   Should stay available until the first call to notify_data.
98  *   Can be NULL if there are no modifiers or @a notify_mod is provided instead.
99  * @param notify_mod   Function to call to obtain modifiers.
100  *   Can be NULL if there are no modifiers or @a env is provided instead.
101  * @param notify_data  Function to call to obtain fragments of the data.
102  * @param notify_cls   Closure for @a notify_mod and @a notify_data.
103  * @param flags        Flags for the message being transmitted.
104  *
105  * @return #GNUNET_OK if the transmission was started.
106  *         #GNUNET_SYSERR if another transmission is already going on.
107  */
108 int
109 GNUNET_PSYC_transmit_message (struct GNUNET_PSYC_TransmitHandle *tmit,
110                               const char *method_name,
111                               const struct GNUNET_ENV_Environment *env,
112                               GNUNET_PSYC_TransmitNotifyModifier notify_mod,
113                               GNUNET_PSYC_TransmitNotifyData notify_data,
114                               void *notify_cls,
115                               uint32_t flags);
116
117
118 /**
119  * Resume transmission.
120  *
121  * @param tmit  Transmission handle.
122  */
123 void
124 GNUNET_PSYC_transmit_resume (struct GNUNET_PSYC_TransmitHandle *tmit);
125
126
127 /**
128  * Abort transmission request.
129  *
130  * @param tmit  Transmission handle.
131  */
132 void
133 GNUNET_PSYC_transmit_cancel (struct GNUNET_PSYC_TransmitHandle *tmit);
134
135
136 /**
137  * Got acknowledgement of a transmitted message part, continue transmission.
138  *
139  * @param tmit  Transmission handle.
140  */
141 void
142 GNUNET_PSYC_transmit_got_ack (struct GNUNET_PSYC_TransmitHandle *tmit);
143
144
145 struct GNUNET_PSYC_ReceiveHandle;
146
147
148 /**
149  * Create handle for receiving messages.
150  */
151 struct GNUNET_PSYC_ReceiveHandle *
152 GNUNET_PSYC_receive_create (GNUNET_PSYC_MessageCallback message_cb,
153                             GNUNET_PSYC_MessageCallback hist_message_cb,
154                             void *cb_cls);
155
156
157 /**
158  * Destroy handle for receiving messages.
159  */
160 void
161 GNUNET_PSYC_receive_destroy (struct GNUNET_PSYC_ReceiveHandle *recv);
162
163
164 /**
165  * Reset stored data related to the last received message.
166  */
167 void
168 GNUNET_PSYC_receive_reset (struct GNUNET_PSYC_ReceiveHandle *recv);
169
170
171 /**
172  * Handle incoming PSYC message.
173  *
174  * @param recv  Receive handle.
175  * @param msg   The message.
176  *
177  * @return #GNUNET_OK on success,
178  *         #GNUNET_SYSERR on receive error.
179  */
180 int
181 GNUNET_PSYC_receive_message (struct GNUNET_PSYC_ReceiveHandle *recv,
182                              const struct GNUNET_PSYC_MessageHeader *msg);
183
184
185 /**
186  * Check if @a data contains a series of valid message parts.
187  *
188  * @param      data_size    Size of @a data.
189  * @param      data         Data.
190  * @param[out] first_ptype  Type of first message part.
191  * @param[out] last_ptype   Type of last message part.
192  *
193  * @return Number of message parts found in @a data.
194  *         or GNUNET_SYSERR if the message contains invalid parts.
195  */
196 int
197 GNUNET_PSYC_receive_check_parts (uint16_t data_size, const char *data,
198                                  uint16_t *first_ptype, uint16_t *last_ptype);
199
200
201 #if 0                           /* keep Emacsens' auto-indent happy */
202 {
203 #endif
204 #ifdef __cplusplus
205 }
206 #endif
207
208 /* ifndef GNUNET_PSYC_UTIL_LIB_H */
209 #endif
210 /* end of gnunet_psyc_util_lib.h */