print active/inactive information
[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 void
44 GNUNET_PSYC_log_message (enum GNUNET_ErrorType kind,
45                          const struct GNUNET_MessageHeader *msg);
46
47
48 int
49 GNUNET_PSYC_check_message_parts (uint16_t data_size, const char *data,
50                                  uint16_t *first_ptype, uint16_t *last_ptype);
51
52
53 struct GNUNET_PSYC_TransmitHandle;
54
55 /**
56  * Create a transmission handle.
57  */
58 struct GNUNET_PSYC_TransmitHandle *
59 GNUNET_PSYC_transmit_create ();
60
61
62 /**
63  * Destroy a transmission handle.
64  */
65 void
66 GNUNET_PSYC_transmit_destroy (struct GNUNET_PSYC_TransmitHandle *tmit);
67
68
69 /**
70  * Transmit a message.
71  *
72  * @param tmit         Transmission handle.
73  * @param method_name  Which method should be invoked.
74  * @param env          Environment for the message.
75  *   Should stay available until the first call to notify_data.
76  *   Can be NULL if there are no modifiers or @a notify_mod is provided instead.
77  * @param notify_mod   Function to call to obtain modifiers.
78  *   Can be NULL if there are no modifiers or @a env is provided instead.
79  * @param notify_data  Function to call to obtain fragments of the data.
80  * @param notify_cls   Closure for @a notify_mod and @a notify_data.
81  * @param flags        Flags for the message being transmitted.
82  *
83  * @return #GNUNET_OK if the transmission was started.
84  *         #GNUNET_SYSERR if another transmission is already going on.
85  */
86 int
87 GNUNET_PSYC_transmit_message (struct GNUNET_PSYC_TransmitHandle *tmit,
88                               const char *method_name,
89                               const struct GNUNET_ENV_Environment *env,
90                               GNUNET_PSYC_TransmitNotifyModifier notify_mod,
91                               GNUNET_PSYC_TransmitNotifyData notify_data,
92                               void *notify_cls,
93                               uint32_t flags);
94
95
96 /**
97  * Resume transmission.
98  *
99  * @param tmit  Transmission handle.
100  */
101 void
102 GNUNET_PSYC_transmit_resume (struct GNUNET_PSYC_TransmitHandle *tmit);
103
104
105 /**
106  * Abort transmission request.
107  *
108  * @param tmit  Transmission handle.
109  */
110 void
111 GNUNET_PSYC_transmit_cancel (struct GNUNET_PSYC_TransmitHandle *tmit);
112
113
114 /**
115  * Got acknowledgement of a transmitted message part, continue transmission.
116  *
117  * @param tmit  Transmission handle.
118  */
119 void
120 GNUNET_PSYC_transmit_got_ack (struct GNUNET_PSYC_TransmitHandle *tmit);
121
122
123 struct GNUNET_PSYC_ReceiveHandle;
124
125
126 /**
127  * Create handle for receiving messages.
128  */
129 struct GNUNET_PSYC_ReceiveHandle *
130 GNUNET_PSYC_receive_create (GNUNET_PSYC_MessageCallback message_cb,
131                             GNUNET_PSYC_MessageCallback hist_message_cb,
132                             void *cb_cls);
133
134
135 /**
136  * Destroy handle for receiving messages.
137  */
138 void
139 GNUNET_PSYC_receive_destroy (struct GNUNET_PSYC_ReceiveHandle *recv);
140
141
142 /**
143  * Reset stored data related to the last received message.
144  */
145 void
146 GNUNET_PSYC_receive_reset (struct GNUNET_PSYC_ReceiveHandle *recv);
147
148
149 /**
150  * Handle incoming PSYC message.
151  *
152  * @param recv  Receive handle.
153  * @param msg   The message.
154  *
155  * @return #GNUNET_OK on success,
156  *         #GNUNET_SYSERR on receive error.
157  */
158 int
159 GNUNET_PSYC_receive_message (struct GNUNET_PSYC_ReceiveHandle *recv,
160                              const struct GNUNET_PSYC_MessageHeader *msg);
161
162
163 /**
164  * Check if @a data contains a series of valid message parts.
165  *
166  * @param      data_size    Size of @a data.
167  * @param      data         Data.
168  * @param[out] first_ptype  Type of first message part.
169  * @param[out] last_ptype   Type of last message part.
170  *
171  * @return Number of message parts found in @a data.
172  *         or GNUNET_SYSERR if the message contains invalid parts.
173  */
174 int
175 GNUNET_PSYC_receive_check_parts (uint16_t data_size, const char *data,
176                                  uint16_t *first_ptype, uint16_t *last_ptype);
177
178
179 #if 0                           /* keep Emacsens' auto-indent happy */
180 {
181 #endif
182 #ifdef __cplusplus
183 }
184 #endif
185
186 /* ifndef GNUNET_PSYC_UTIL_LIB_H */
187 #endif
188 /* end of gnunet_psyc_util_lib.h */