- one catch-all ack handles renedered obsolete
[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 /**
44  * Struct containing all information regarding a channel to a remote client.
45  */
46 struct MeshChannel;
47
48
49 #include "gnunet-service-mesh_tunnel.h"
50
51
52 /**
53  * Get channel ID.
54  *
55  * @param ch Channel.
56  *
57  * @return ID
58  */
59 MESH_ChannelNumber
60 GMCH_get_id (const struct MeshChannel *ch);
61
62 /**
63  * Get the channel tunnel.
64  *
65  * @param ch Channel to get the tunnel from.
66  *
67  * @return tunnel of the channel.
68  */
69 struct MeshTunnel3 *
70 GMCH_get_tunnel (const struct MeshChannel *ch);
71
72 /**
73  * Get free buffer space towards the client on a specific channel.
74  *
75  * @param ch Channel.
76  * @param fwd Is query about FWD traffic?
77  *
78  * @return Free buffer space [0 - 64]
79  */
80 unsigned int
81 GMCH_get_buffer (struct MeshChannel *ch, int fwd);
82
83 /**
84  * Is the root client for this channel on this peer?
85  *
86  * @param ch Channel.
87  * @param fwd Is this for fwd traffic?
88  *
89  * @return GNUNET_YES in case it is.
90  */
91 int
92 GMCH_is_origin (struct MeshChannel *ch, int fwd);
93
94 /**
95  * Is the destination client for this channel on this peer?
96  *
97  * @param ch Channel.
98  * @param fwd Is this for fwd traffic?
99  *
100  * @return GNUNET_YES in case it is.
101  */
102 int
103 GMCH_is_terminal (struct MeshChannel *ch, int fwd);
104
105 /**
106  * Send an end-to-end ACK message for the most recent in-sequence payload.
107  *
108  * If channel is not reliable, do nothing.
109  *
110  * @param ch Channel this is about.
111  * @param fwd Is for FWD traffic? (ACK dest->owner)
112  */
113 void
114 GMCH_send_ack (struct MeshChannel *ch, int fwd);
115
116 /**
117  * Send data on a channel.
118  *
119  * If the destination is local, send it to client, otherwise encrypt and
120  * send to next hop.
121  *
122  * @param ch Channel
123  * @param msg Message.
124  * @param fwd Is this a fwd (root->dest) message?
125  */
126 void
127 GMCH_send_data (struct MeshChannel *ch,
128                 const struct GNUNET_MESH_Data *msg,
129                 int fwd);
130
131 /**
132  * Notify the destination client that a new incoming channel was created.
133  *
134  * @param ch Channel that was created.
135  */
136 void
137 GMCH_send_create (struct MeshChannel *ch);
138
139
140 /**
141  * Notify a client that the channel is no longer valid.
142  *
143  * @param ch Channel that is destroyed.
144  */
145 void
146 GMCH_send_destroy (struct MeshChannel *ch);
147
148
149 /**
150  * Log channel info.
151  *
152  * @param ch Channel.
153  */
154 void
155 GMCH_debug (struct MeshChannel *ch);
156
157
158 /**
159  * Handler for mesh network payload traffic.
160  *
161  * @param ch Channel for the message.
162  * @param message Unencryted data message.
163  * @param fwd Is this FWD traffic? GNUNET_YES : GNUNET_NO;
164  */
165 void
166 GMCH_handle_data (struct MeshChannel *ch,
167                   const struct GNUNET_MESH_Data *msg,
168                   int fwd);
169
170
171 /**
172  * Handler for mesh network traffic end-to-end ACKs.
173  *
174  * @param t Tunnel on which we got this message.
175  * @param message Data message.
176  * @param fwd Is this a fwd ACK? (dest->orig)
177  */
178 void
179 GMCH_handle_data_ack (struct MeshChannel *ch,
180                       const struct GNUNET_MESH_DataACK *msg,
181                       int fwd);
182
183
184 /**
185  * Handler for channel create messages.
186  *
187  * @param t Tunnel this channel is to be created in.
188  * @param msg Message.
189  * @param fwd Is this FWD traffic? GNUNET_YES : GNUNET_NO;
190  */
191 struct MeshChannel *
192 GMCH_handle_create (const struct GNUNET_MESH_ChannelCreate *msg,
193                     int fwd);
194
195
196 /**
197  * Handler for channel ack messages.
198  *
199  * @param t Tunnel this channel is to be created in.
200  * @param msg Message.
201  * @param fwd Is this FWD traffic? GNUNET_YES : GNUNET_NO;
202  */
203 void
204 GMCH_handle_ack (struct MeshChannel *ch,
205                  const struct GNUNET_MESH_ChannelManage *msg,
206                  int fwd);
207
208
209 /**
210  * Handler for channel destroy messages.
211  *
212  * @param t Tunnel this channel is to be destroyed of.
213  * @param msg Message.
214  * @param fwd Is this FWD traffic? GNUNET_YES : GNUNET_NO;
215  */
216 void
217 GMCH_handle_destroy (struct MeshChannel *ch,
218                      const struct GNUNET_MESH_ChannelManage *msg,
219                      int fwd);
220
221
222
223 /**
224  * Sends an already built message on a channel, properly registering
225  * all used resources and encrypting the message with the tunnel's key.
226  *
227  * @param message Message to send. Function makes a copy of it.
228  * @param ch Channel on which this message is transmitted.
229  * @param fwd Is this a fwd message?
230  */
231 void
232 GMCH_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
233                             struct MeshChannel *ch, int fwd);
234
235
236 #if 0                           /* keep Emacsens' auto-indent happy */
237 {
238 #endif
239 #ifdef __cplusplus
240 }
241 #endif
242
243 /* ifndef GNUNET_SERVICE_MESH_CHANNEL_H */
244 #endif
245 /* end of gnunet-service-mesh_channel.h */