2 This file is part of GNUnet.
3 Copyright (C) 2013 GNUnet e.V.
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.
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.
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.
22 * @file cadet/gnunet-service-cadet_channel.h
23 * @brief cadet service; dealing with end-to-end channels
24 * @author Bartlomiej Polot
26 * All functions in this file should use the prefix GMCH (Gnunet Cadet CHannel)
29 #ifndef GNUNET_SERVICE_CADET_CHANNEL_H
30 #define GNUNET_SERVICE_CADET_CHANNEL_H
35 #if 0 /* keep Emacsens' auto-indent happy */
41 #include "gnunet_util_lib.h"
43 #include "cadet_protocol.h"
47 * Struct containing all information regarding a channel to a remote client.
52 #include "gnunet-service-cadet_tunnel.h"
53 #include "gnunet-service-cadet_local.h"
57 * Destroy a channel and free all resources.
59 * @param ch Channel to destroy.
62 GCCH_destroy (struct CadetChannel *ch);
66 * Get the channel's public ID.
70 * @return ID used to identify the channel with the remote peer.
72 struct GNUNET_CADET_ChannelTunnelNumber
73 GCCH_get_id (const struct CadetChannel *ch);
77 * Get the channel tunnel.
79 * @param ch Channel to get the tunnel from.
81 * @return tunnel of the channel.
84 GCCH_get_tunnel (const struct CadetChannel *ch);
88 * Get free buffer space towards the client on a specific channel.
91 * @param fwd Is query about FWD traffic?
93 * @return Free buffer space [0 - 64]
96 GCCH_get_buffer (struct CadetChannel *ch, int fwd);
100 * Get flow control status of end point: is client allow to send?
103 * @param fwd Is query about FWD traffic? (Request root status).
105 * @return #GNUNET_YES if client is allowed to send us data.
108 GCCH_get_allowed (struct CadetChannel *ch, int fwd);
112 * Is the root client for this channel on this peer?
115 * @param fwd Is this for fwd traffic?
117 * @return #GNUNET_YES in case it is.
120 GCCH_is_origin (struct CadetChannel *ch, int fwd);
123 * Is the destination client for this channel on this peer?
126 * @param fwd Is this for fwd traffic?
128 * @return #GNUNET_YES in case it is.
131 GCCH_is_terminal (struct CadetChannel *ch, int fwd);
134 * Send an end-to-end ACK message for the most recent in-sequence payload.
136 * If channel is not reliable, do nothing.
138 * @param ch Channel this is about.
139 * @param fwd Is for FWD traffic? (ACK dest->owner)
142 GCCH_send_data_ack (struct CadetChannel *ch, int fwd);
145 * Notify the destination client that a new incoming channel was created.
147 * @param ch Channel that was created.
150 GCCH_send_create (struct CadetChannel *ch);
153 * Allow a client to send us more data, in case it was choked.
156 * @param fwd Is this about FWD traffic? (Root client).
159 GCCH_allow_client (struct CadetChannel *ch, int fwd);
165 * @param level Debug level to use.
168 GCCH_debug (struct CadetChannel *ch, enum GNUNET_ErrorType level);
171 * Handle an ACK given by a client.
173 * Mark client as ready and send him any buffered data we could have for him.
176 * @param fwd Is this a "FWD ACK"? (FWD ACKs are sent by root and go BCK)
179 GCCH_handle_local_ack (struct CadetChannel *ch, int fwd);
182 * Handle data given by a client.
184 * Check whether the client is allowed to send in this tunnel, save if channel
185 * is reliable and send an ACK to the client if there is still buffer space
189 * @param c Client which sent the data.
190 * @param fwd Is this a FWD data?
191 * @param message Data message.
192 * @param size Size of data.
194 * @return GNUNET_OK if everything goes well, GNUNET_SYSERR in case of en error.
197 GCCH_handle_local_data (struct CadetChannel *ch,
198 struct CadetClient *c, int fwd,
199 const struct GNUNET_MessageHeader *message,
203 * Handle a channel destroy requested by a client.
205 * Destroy the channel and the tunnel in case this was the last channel.
208 * @param c Client that requested the destruction (to avoid notifying him).
209 * @param is_root Is the request coming from root?
212 GCCH_handle_local_destroy (struct CadetChannel *ch,
213 struct CadetClient *c,
218 * Handle a channel create requested by a client.
220 * Create the channel and the tunnel in case this was the first0 channel.
222 * @param c Client that requested the creation (will be the root).
223 * @param msg Create Channel message.
225 * @return #GNUNET_OK if everything went fine, #GNUNET_SYSERR otherwise.
228 GCCH_handle_local_create (struct CadetClient *c,
229 struct GNUNET_CADET_LocalChannelCreateMessage *msg);
232 * Handler for cadet network payload traffic.
234 * @param ch Channel for the message.
235 * @param msg Unencryted data message.
236 * @param fwd Is this message fwd? This only is meaningful in loopback channels.
237 * #GNUNET_YES if message is FWD on the respective channel (loopback)
238 * #GNUNET_NO if message is BCK on the respective channel (loopback)
239 * #GNUNET_SYSERR if message on a one-ended channel (remote)
242 GCCH_handle_data (struct CadetChannel *ch,
243 const struct GNUNET_CADET_ChannelAppDataMessage *msg,
248 * Handler for cadet network traffic end-to-end ACKs.
250 * @param ch Channel on which we got this message.
251 * @param msg Data message.
252 * @param fwd Is this message fwd? This only is meaningful in loopback channels.
253 * #GNUNET_YES if message is FWD on the respective channel (loopback)
254 * #GNUNET_NO if message is BCK on the respective channel (loopback)
255 * #GNUNET_SYSERR if message on a one-ended channel (remote)
258 GCCH_handle_data_ack (struct CadetChannel *ch,
259 const struct GNUNET_CADET_ChannelDataAckMessage *msg,
264 * Handler for channel create messages.
266 * Does not have fwd parameter because it's always 'FWD': channel is incoming.
268 * @param t Tunnel this channel will be in.
269 * @param msg Channel crate message.
271 struct CadetChannel *
272 GCCH_handle_create (struct CadetTunnel *t,
273 const struct GNUNET_CADET_ChannelOpenMessage *msg);
277 * Handler for channel NACK messages.
279 * NACK messages always go dest -> root, no need for 'fwd' or 'msg' parameter.
284 GCCH_handle_nack (struct CadetChannel *ch);
288 * Handler for channel ack messages.
290 * @param ch Channel this channel is to be created in.
291 * @param msg Message.
292 * @param fwd Is this message fwd? This only is meaningful in loopback channels.
293 * #GNUNET_YES if message is FWD on the respective channel (loopback)
294 * #GNUNET_NO if message is BCK on the respective channel (loopback)
295 * #GNUNET_SYSERR if message on a one-ended channel (remote)
298 GCCH_handle_ack (struct CadetChannel *ch,
299 const struct GNUNET_CADET_ChannelManageMessage *msg,
304 * Handler for channel destroy messages.
306 * @param ch Channel this channel is to be destroyed of.
307 * @param msg Message.
308 * @param fwd Is this message fwd? This only is meaningful in loopback channels.
309 * #GNUNET_YES if message is FWD on the respective channel (loopback)
310 * #GNUNET_NO if message is BCK on the respective channel (loopback)
311 * #GNUNET_SYSERR if message on a one-ended channel (remote)
314 GCCH_handle_destroy (struct CadetChannel *ch,
315 const struct GNUNET_CADET_ChannelManageMessage *msg,
320 * Sends an already built message on a channel.
322 * If the channel is on a loopback tunnel, notifies the appropriate destination
325 * On a normal channel passes the message to the tunnel for encryption and
326 * sending on a connection.
328 * This function DOES NOT save the message for retransmission.
330 * @param message Message to send. Function makes a copy of it.
331 * @param ch Channel on which this message is transmitted.
332 * @param fwd Is this a fwd message?
333 * @param existing_copy This is a retransmission, don't save a copy.
336 GCCH_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
337 struct CadetChannel *ch, int fwd,
338 void *existing_copy);
342 * Get the static string for identification of the channel.
344 * @param ch Channel.i
346 * @return Static string with the channel IDs.
349 GCCH_2s (const struct CadetChannel *ch);
354 #if 0 /* keep Emacsens' auto-indent happy */
361 /* ifndef GNUNET_SERVICE_CADET_CHANNEL_H */
363 /* end of gnunet-service-cadet_channel.h */