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