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