- debug
[oweals/gnunet.git] / src / mesh / gnunet-service-mesh_channel.h
1 /*
2      This file is part of GNUnet.
3      (C) 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 mesh/gnunet-service-mesh_channel.h
23  * @brief mesh service; dealing with end-to-end channels
24  * @author Bartlomiej Polot
25  *
26  * All functions in this file should use the prefix GMCH (Gnunet Mesh CHannel)
27  */
28
29 #ifndef GNUNET_SERVICE_MESH_CHANNEL_H
30 #define GNUNET_SERVICE_MESH_CHANNEL_H
31
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #if 0                           /* keep Emacsens' auto-indent happy */
36 }
37 #endif
38 #endif
39
40 #include "platform.h"
41 #include "gnunet_util_lib.h"
42
43 #include "mesh_protocol_enc.h"
44 #include "mesh_enc.h"
45
46 /**
47  * Struct containing all information regarding a channel to a remote client.
48  */
49 struct MeshChannel;
50
51
52 #include "gnunet-service-mesh_tunnel.h"
53 #include "gnunet-service-mesh_local.h"
54
55
56 /**
57  * Get channel ID.
58  *
59  * @param ch Channel.
60  *
61  * @return ID
62  */
63 MESH_ChannelNumber
64 GMCH_get_id (const struct MeshChannel *ch);
65
66 /**
67  * Get the channel tunnel.
68  *
69  * @param ch Channel to get the tunnel from.
70  *
71  * @return tunnel of the channel.
72  */
73 struct MeshTunnel3 *
74 GMCH_get_tunnel (const struct MeshChannel *ch);
75
76 /**
77  * Get free buffer space towards the client on a specific channel.
78  *
79  * @param ch Channel.
80  * @param fwd Is query about FWD traffic?
81  *
82  * @return Free buffer space [0 - 64]
83  */
84 unsigned int
85 GMCH_get_buffer (struct MeshChannel *ch, int fwd);
86
87
88 /**
89  * Get flow control status of end point: is client allow to send?
90  *
91  * @param ch Channel.
92  * @param fwd Is query about FWD traffic? (Request root status).
93  *
94  * @return GNUNET_YES if client is allowed to send us data.
95  */
96 int
97 GMCH_get_allowed (struct MeshChannel *ch, int fwd);
98
99
100 /**
101  * Is the root client for this channel on this peer?
102  *
103  * @param ch Channel.
104  * @param fwd Is this for fwd traffic?
105  *
106  * @return GNUNET_YES in case it is.
107  */
108 int
109 GMCH_is_origin (struct MeshChannel *ch, int fwd);
110
111 /**
112  * Is the destination client for this channel on this peer?
113  *
114  * @param ch Channel.
115  * @param fwd Is this for fwd traffic?
116  *
117  * @return GNUNET_YES in case it is.
118  */
119 int
120 GMCH_is_terminal (struct MeshChannel *ch, int fwd);
121
122 /**
123  * Send data on a channel.
124  *
125  * If the destination is local, send it to client, otherwise encrypt and
126  * send to next hop.
127  *
128  * @param ch Channel
129  * @param msg Message.
130  * @param fwd Is this a fwd (root->dest) message?
131  */
132 void
133 GMCH_send_data (struct MeshChannel *ch,
134                 const struct GNUNET_MESH_Data *msg,
135                 int fwd);
136
137 /**
138  * Send an end-to-end ACK message for the most recent in-sequence payload.
139  *
140  * If channel is not reliable, do nothing.
141  *
142  * @param ch Channel this is about.
143  * @param fwd Is for FWD traffic? (ACK dest->owner)
144  */
145 void
146 GMCH_send_data_ack (struct MeshChannel *ch, int fwd);
147
148 /**
149  * Notify the destination client that a new incoming channel was created.
150  *
151  * @param ch Channel that was created.
152  */
153 void
154 GMCH_send_create (struct MeshChannel *ch);
155
156 /**
157  * Notify a client that the channel is no longer valid.
158  *
159  * @param ch Channel that is destroyed.
160  */
161 void
162 GMCH_send_destroy (struct MeshChannel *ch);
163
164 /**
165  * Allow a client to send us more data, in case it was choked.
166  *
167  * @param ch Channel.
168  * @param fwd Is this about FWD traffic? (Root client).
169  */
170 void
171 GMCH_allow_client (struct MeshChannel *ch, int fwd);
172
173 /**
174  * Log channel info.
175  *
176  * @param ch Channel.
177  */
178 void
179 GMCH_debug (struct MeshChannel *ch);
180
181 /**
182  * Handle an ACK given by a client.
183  *
184  * Mark client as ready and send him any buffered data we could have for him.
185  *
186  * @param ch Channel.
187  * @param fwd Is this a "FWD ACK"? (FWD ACKs are sent by root and go BCK)
188  */
189 void
190 GMCH_handle_local_ack (struct MeshChannel *ch, int fwd);
191
192 /**
193  * Handle data given by a client.
194  *
195  * Check whether the client is allowed to send in this tunnel, save if channel
196  * is reliable and send an ACK to the client if there is still buffer space
197  * in the tunnel.
198  *
199  * @param ch Channel.
200  * @param fwd Is this a FWD data?
201  *
202  * @return GNUNET_OK if everything goes well, GNUNET_SYSERR in case of en error.
203  */
204 int
205 GMCH_handle_local_data (struct MeshChannel *ch,
206                         struct MeshClient *c,
207                         struct GNUNET_MessageHeader *message,
208                         int fwd);
209
210 /**
211  * Handle a channel destroy requested by a client.
212  *
213  * Destroy the channel and the tunnel in case this was the last channel.
214  *
215  * @param ch Channel.
216  * @param c Client that requested the destruction (to avoid notifying him).
217  */
218 void
219 GMCH_handle_local_destroy (struct MeshChannel *ch,
220                            struct MeshClient *c);
221
222 /**
223  * Handle a channel create requested by a client.
224  *
225  * Create the channel and the tunnel in case this was the first0 channel.
226  *
227  * @param c Client that requested the creation (will be the root).
228  * @param msg Create Channel message.
229  *
230  * @return GNUNET_OK if everything went fine, GNUNET_SYSERR otherwise.
231  */
232 int
233 GMCH_handle_local_create (struct MeshClient *c,
234                           struct GNUNET_MESH_ChannelMessage *msg);
235
236 /**
237  * Handler for mesh network payload traffic.
238  *
239  * @param ch Channel for the message.
240  * @param message Unencryted data message.
241  * @param fwd Is this FWD traffic? GNUNET_YES : GNUNET_NO;
242  */
243 void
244 GMCH_handle_data (struct MeshChannel *ch,
245                   const struct GNUNET_MESH_Data *msg,
246                   int fwd);
247
248 /**
249  * Handler for mesh network traffic end-to-end ACKs.
250  *
251  * @param t Tunnel on which we got this message.
252  * @param message Data message.
253  * @param fwd Is this a fwd ACK? (dest->orig)
254  */
255 void
256 GMCH_handle_data_ack (struct MeshChannel *ch,
257                       const struct GNUNET_MESH_DataACK *msg,
258                       int fwd);
259
260 /**
261  * Handler for channel create messages.
262  *
263  * @param t Tunnel this channel will be in.
264  * @param msg Message.
265  * @param fwd Is this FWD traffic? GNUNET_YES : GNUNET_NO;
266  */
267 struct MeshChannel *
268 GMCH_handle_create (struct MeshTunnel3 *t,
269                     const struct GNUNET_MESH_ChannelCreate *msg,
270                     int fwd);
271
272 /**
273  * Handler for channel ack messages.
274  *
275  * @param t Tunnel this channel is to be created in.
276  * @param msg Message.
277  * @param fwd Is this FWD traffic? GNUNET_YES : GNUNET_NO;
278  */
279 void
280 GMCH_handle_ack (struct MeshChannel *ch,
281                  const struct GNUNET_MESH_ChannelManage *msg,
282                  int fwd);
283
284 /**
285  * Handler for channel destroy messages.
286  *
287  * @param t Tunnel this channel is to be destroyed of.
288  * @param msg Message.
289  * @param fwd Is this FWD traffic? GNUNET_YES : GNUNET_NO;
290  */
291 void
292 GMCH_handle_destroy (struct MeshChannel *ch,
293                      const struct GNUNET_MESH_ChannelManage *msg,
294                      int fwd);
295
296 /**
297  * Sends an already built message on a channel.
298  *
299  * If the channel is on a loopback tunnel, notifies the appropriate destination
300  * client locally.
301  *
302  * On a normal channel passes the message to the tunnel for encryption and
303  * sending on a connection.
304  *
305  * @param message Message to send. Function makes a copy of it.
306  * @param ch Channel on which this message is transmitted.
307  * @param fwd Is this a fwd message?
308  */
309 void
310 GMCH_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
311                             struct MeshChannel *ch, int fwd);
312
313 /**
314  * Get the static string for identification of the channel.
315  *
316  * @param ch Channel.
317  *
318  * @return Static string with the channel IDs.
319  */
320 const char *
321 GMCH_2s (const struct MeshChannel *ch);
322
323
324 #if 0                           /* keep Emacsens' auto-indent happy */
325 {
326 #endif
327 #ifdef __cplusplus
328 }
329 #endif
330
331 /* ifndef GNUNET_SERVICE_MESH_CHANNEL_H */
332 #endif
333 /* end of gnunet-service-mesh_channel.h */