- dead code
[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.h"
44 #include "mesh.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 an end-to-end ACK message for the most recent in-sequence payload.
124  *
125  * If channel is not reliable, do nothing.
126  *
127  * @param ch Channel this is about.
128  * @param fwd Is for FWD traffic? (ACK dest->owner)
129  */
130 void
131 GMCH_send_data_ack (struct MeshChannel *ch, int fwd);
132
133 /**
134  * Notify the destination client that a new incoming channel was created.
135  *
136  * @param ch Channel that was created.
137  */
138 void
139 GMCH_send_create (struct MeshChannel *ch);
140
141 /**
142  * Notify a client that the channel is no longer valid.
143  *
144  * @param ch Channel that is destroyed.
145  */
146 void
147 GMCH_send_destroy (struct MeshChannel *ch);
148
149 /**
150  * Allow a client to send us more data, in case it was choked.
151  *
152  * @param ch Channel.
153  * @param fwd Is this about FWD traffic? (Root client).
154  */
155 void
156 GMCH_allow_client (struct MeshChannel *ch, int fwd);
157
158 /**
159  * Log channel info.
160  *
161  * @param ch Channel.
162  */
163 void
164 GMCH_debug (struct MeshChannel *ch);
165
166 /**
167  * Handle an ACK given by a client.
168  *
169  * Mark client as ready and send him any buffered data we could have for him.
170  *
171  * @param ch Channel.
172  * @param fwd Is this a "FWD ACK"? (FWD ACKs are sent by root and go BCK)
173  */
174 void
175 GMCH_handle_local_ack (struct MeshChannel *ch, int fwd);
176
177 /**
178  * Handle data given by a client.
179  *
180  * Check whether the client is allowed to send in this tunnel, save if channel
181  * is reliable and send an ACK to the client if there is still buffer space
182  * in the tunnel.
183  *
184  * @param ch Channel.
185  * @param c Client which sent the data.
186  * @param message Message.
187  * @param fwd Is this a FWD data?
188  *
189  * @return GNUNET_OK if everything goes well, GNUNET_SYSERR in case of en error.
190  */
191 int
192 GMCH_handle_local_data (struct MeshChannel *ch,
193                         struct MeshClient *c,
194                         struct GNUNET_MessageHeader *message,
195                         int fwd);
196
197 /**
198  * Handle a channel destroy requested by a client.
199  *
200  * Destroy the channel and the tunnel in case this was the last channel.
201  *
202  * @param ch Channel.
203  * @param c Client that requested the destruction (to avoid notifying him).
204  */
205 void
206 GMCH_handle_local_destroy (struct MeshChannel *ch,
207                            struct MeshClient *c);
208
209 /**
210  * Handle a channel create requested by a client.
211  *
212  * Create the channel and the tunnel in case this was the first0 channel.
213  *
214  * @param c Client that requested the creation (will be the root).
215  * @param msg Create Channel message.
216  *
217  * @return GNUNET_OK if everything went fine, GNUNET_SYSERR otherwise.
218  */
219 int
220 GMCH_handle_local_create (struct MeshClient *c,
221                           struct GNUNET_MESH_ChannelMessage *msg);
222
223 /**
224  * Handler for mesh network payload traffic.
225  *
226  * @param ch Channel for the message.
227  * @param msg Unencryted data message.
228  * @param fwd Is this message fwd? This only is meaningful in loopback channels.
229  *            #GNUNET_YES if message is FWD on the respective channel (loopback)
230  *            #GNUNET_NO if message is BCK on the respective channel (loopback)
231  *            #GNUNET_SYSERR if message on a one-ended channel (remote)
232  */
233 void
234 GMCH_handle_data (struct MeshChannel *ch,
235                   const struct GNUNET_MESH_Data *msg,
236                   int fwd);
237
238 /**
239  * Handler for mesh network traffic end-to-end ACKs.
240  *
241  * @param ch Channel on which we got this message.
242  * @param msg Data message.
243  * @param fwd Is this message fwd? This only is meaningful in loopback channels.
244  *            #GNUNET_YES if message is FWD on the respective channel (loopback)
245  *            #GNUNET_NO if message is BCK on the respective channel (loopback)
246  *            #GNUNET_SYSERR if message on a one-ended channel (remote)
247  */
248 void
249 GMCH_handle_data_ack (struct MeshChannel *ch,
250                       const struct GNUNET_MESH_DataACK *msg,
251                       int fwd);
252
253 /**
254  * Handler for channel create messages.
255  *
256  * Does not have fwd parameter because it's always 'FWD': channel is incoming.
257  *
258  * @param t Tunnel this channel will be in.
259  * @param msg Channel crate message.
260  */
261 struct MeshChannel *
262 GMCH_handle_create (struct MeshTunnel3 *t,
263                     const struct GNUNET_MESH_ChannelCreate *msg);
264
265 /**
266  * Handler for channel NACK messages.
267  *
268  * NACK messages always go dest -> root, no need for 'fwd' or 'msg' parameter.
269  *
270  * @param ch Channel.
271  */
272 void
273 GMCH_handle_nack (struct MeshChannel *ch);
274
275 /**
276  * Handler for channel ack messages.
277  *
278  * @param ch Channel this channel is to be created in.
279  * @param msg Message.
280  * @param fwd Is this message fwd? This only is meaningful in loopback channels.
281  *            #GNUNET_YES if message is FWD on the respective channel (loopback)
282  *            #GNUNET_NO if message is BCK on the respective channel (loopback)
283  *            #GNUNET_SYSERR if message on a one-ended channel (remote)
284  */
285 void
286 GMCH_handle_ack (struct MeshChannel *ch,
287                  const struct GNUNET_MESH_ChannelManage *msg,
288                  int fwd);
289
290 /**
291  * Handler for channel destroy messages.
292  *
293  * @param ch Channel this channel is to be destroyed of.
294  * @param msg Message.
295  * @param fwd Is this message fwd? This only is meaningful in loopback channels.
296  *            #GNUNET_YES if message is FWD on the respective channel (loopback)
297  *            #GNUNET_NO if message is BCK on the respective channel (loopback)
298  *            #GNUNET_SYSERR if message on a one-ended channel (remote)
299  */
300 void
301 GMCH_handle_destroy (struct MeshChannel *ch,
302                      const struct GNUNET_MESH_ChannelManage *msg,
303                      int fwd);
304
305 /**
306  * Sends an already built message on a channel.
307  *
308  * If the channel is on a loopback tunnel, notifies the appropriate destination
309  * client locally.
310  *
311  * On a normal channel passes the message to the tunnel for encryption and
312  * sending on a connection.
313  *
314  * @param message Message to send. Function makes a copy of it.
315  * @param ch Channel on which this message is transmitted.
316  * @param fwd Is this a fwd message?
317  */
318 void
319 GMCH_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
320                             struct MeshChannel *ch, int fwd);
321
322 /**
323  * Get the static string for identification of the channel.
324  *
325  * @param ch Channel.
326  *
327  * @return Static string with the channel IDs.
328  */
329 const char *
330 GMCH_2s (const struct MeshChannel *ch);
331
332
333 #if 0                           /* keep Emacsens' auto-indent happy */
334 {
335 #endif
336 #ifdef __cplusplus
337 }
338 #endif
339
340 /* ifndef GNUNET_SERVICE_MESH_CHANNEL_H */
341 #endif
342 /* end of gnunet-service-mesh_channel.h */