- use different enum to prevent collisions
[oweals/gnunet.git] / src / mesh / gnunet-service-mesh_tunnel.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_tunnel.h
23  * @brief mesh service; dealing with tunnels and crypto
24  * @author Bartlomiej Polot
25  *
26  * All functions in this file should use the prefix GMT (Gnunet Mesh Tunnel)
27  */
28
29 #ifndef GNUNET_SERVICE_MESH_TUNNEL_H
30 #define GNUNET_SERVICE_MESH_TUNNEL_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  * All the states a tunnel can be in.
45  */
46 enum MeshTunnel3State
47 {
48     /**
49      * Uninitialized status, should never appear in operation.
50      */
51   MESH_TUNNEL3_NEW,
52
53     /**
54      * Path to the peer not known yet
55      */
56   MESH_TUNNEL3_SEARCHING,
57
58     /**
59      * Request sent, not yet answered.
60      */
61   MESH_TUNNEL3_WAITING,
62
63     /**
64      * Peer connected and ready to accept data
65      */
66   MESH_TUNNEL3_READY,
67
68     /**
69      * Peer connected previosly but not responding
70      */
71   MESH_TUNNEL3_RECONNECTING
72 };
73
74 /**
75  * Struct containing all information regarding a given peer
76  */
77 struct MeshTunnel3;
78
79
80 #include "gnunet-service-mesh_channel.h"
81 #include "gnunet-service-mesh_connection.h"
82
83
84 /******************************************************************************/
85 /********************************    API    ***********************************/
86 /******************************************************************************/
87
88 /**
89  * Initialize tunnel subsystem.
90  *
91  * @param c Configuration handle.
92  * @param id Peer identity.
93  * @param key ECC private key, to derive all other keys and do crypto.
94  */
95 void
96 GMT_init (const struct GNUNET_CONFIGURATION_Handle *c,
97           const struct GNUNET_PeerIdentity *id,
98           const struct GNUNET_CRYPTO_EccPrivateKey *key);
99
100 /**
101  * Shut down the tunnel subsystem.
102  */
103 void
104 GMT_shutdown (void);
105
106 /**
107  * Tunnel is empty: destroy it.
108  *
109  * Notifies all connections about the destruction.
110  *
111  * @param t Tunnel to destroy.
112  */
113 void
114 GMT_destroy_empty (struct MeshTunnel3 *t);
115
116 /**
117  * Destroy tunnel if empty (no more channels).
118  *
119  * @param t Tunnel to destroy if empty.
120  */
121 void
122 GMT_destroy_if_empty (struct MeshTunnel3 *t);
123
124 /**
125  * Destroy the tunnel.
126  *
127  * This function does not generate any warning traffic to clients or peers.
128  *
129  * Tasks:
130  * Cancel messages belonging to this tunnel queued to neighbors.
131  * Free any allocated resources linked to the tunnel.
132  *
133  * @param t The tunnel to destroy.
134  */
135 void
136 GMT_destroy (struct MeshTunnel3 *t);
137
138 /**
139  * Change the tunnel state.
140  *
141  * @param t Tunnel whose state to change.
142  * @param state New state.
143  */
144 void
145 GMT_change_state (struct MeshTunnel3* t, enum MeshTunnel3State state);
146
147 /**
148  * Add a connection to a tunnel.
149  *
150  * @param t Tunnel.
151  * @param c Connection.
152  */
153 void
154 GMT_add_connection (struct MeshTunnel3 *t, struct MeshConnection *c);
155
156 /**
157  * Remove a connection from a tunnel.
158  *
159  * @param t Tunnel.
160  * @param c Connection.
161  */
162 void
163 GMT_remove_connection (struct MeshTunnel3 *t, struct MeshConnection *c);
164
165 /**
166  * Add a channel to a tunnel.
167  *
168  * @param t Tunnel.
169  * @param ch Channel.
170  */
171 void
172 GMT_add_channel (struct MeshTunnel3 *t, struct MeshChannel *ch);
173
174 /**
175  * Remove a channel from a tunnel.
176  *
177  * @param t Tunnel.
178  * @param ch Channel.
179  */
180 void
181 GMT_remove_channel (struct MeshTunnel3 *t, struct MeshChannel *ch);
182
183 /**
184  * Search for a channel by global ID.
185  *
186  * @param t Tunnel containing the channel.
187  * @param chid Public channel number.
188  *
189  * @return channel handler, NULL if doesn't exist
190  */
191 struct MeshChannel *
192 GMT_get_channel (struct MeshTunnel3 *t, MESH_ChannelNumber chid);
193
194
195 /**
196  * Cache a message to be sent once tunnel is online.
197  *
198  * @param t Tunnel to hold the message.
199  * @param ch Channel the message is about.
200  * @param msg Message itself (copy will be made).
201  * @param fwd Is this fwd?
202  */
203 void
204 GMT_queue_data (struct MeshTunnel3 *t,
205                 struct MeshChannel *ch,
206                 struct GNUNET_MessageHeader *msg,
207                 int fwd);
208
209 /**
210  * Send all cached messages that we can, tunnel is online.
211  *
212  * @param t Tunnel that holds the messages.
213  * @param fwd Is this fwd?
214  */
215 void
216 GMT_send_queued_data (struct MeshTunnel3 *t, int fwd);
217
218 /**
219  * Count established (ready) connections of a tunnel.
220  *
221  * @param t Tunnel on which to count.
222  *
223  * @return Number of connections.
224  */
225 unsigned int
226 GMT_count_connections (struct MeshTunnel3 *t);
227
228 /**
229  * Count channels of a tunnel.
230  *
231  * @param t Tunnel on which to count.
232  *
233  * @return Number of channels.
234  */
235 unsigned int
236 GMT_count_channels (struct MeshTunnel3 *t);
237
238 /**
239  * Get the state of a tunnel.
240  *
241  * @param t Tunnel.
242  *
243  * @return Tunnel's state.
244  */
245 enum MeshTunnel3State
246 GMT_get_state (struct MeshTunnel3 *t);
247
248 /**
249  * Get the total buffer space for a tunnel.
250  *
251  * @param t Tunnel.
252  * @param fwd Is this for FWD traffic?
253  *
254  * @return Buffer space offered by all connections in the tunnel.
255  */
256 unsigned int
257 GMT_get_buffer (struct MeshTunnel3 *t, int fwd);
258
259 /**
260  * Get the tunnel's destination.
261  *
262  * @param t Tunnel.
263  *
264  * @return ID of the destination peer.
265  */
266 const struct GNUNET_PeerIdentity *
267 GMT_get_destination (struct MeshTunnel3 *t);
268
269 /**
270  * Get the tunnel's next free Channel ID.
271  *
272  * @param t Tunnel.
273  *
274  * @return ID of a channel free to use.
275  */
276 MESH_ChannelNumber
277 GMT_get_next_chid (struct MeshTunnel3 *t);
278
279 /**
280  * Sends an already built message on a tunnel, encrypting it and
281  * choosing the best connection.
282  *
283  * @param message Message to send. Function modifies it.
284  * @param t Tunnel on which this message is transmitted.
285  * @param ch Channel on which this message is transmitted.
286  * @param fwd Is this a fwd message?
287  */
288 void
289 GMT_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
290                            struct MeshTunnel3 *t,
291                            struct MeshChannel *ch,
292                            int fwd);
293
294 /**
295  * Is the tunnel directed towards the local peer?
296  *
297  * @param t Tunnel.
298  *
299  * @return GNUNET_YES if it is loopback.
300  */
301 int
302 GMT_is_loopback (const struct MeshTunnel3 *t);
303
304 /**
305  * Get the static string for the peer this tunnel is directed.
306  *
307  * @param t Tunnel.
308  *
309  * @return Static string the destination peer's ID.
310  */
311 const char *
312 GMT_2s (const struct MeshTunnel3 *t);
313
314 #if 0                           /* keep Emacsens' auto-indent happy */
315 {
316 #endif
317 #ifdef __cplusplus
318 }
319 #endif
320
321 /* ifndef GNUNET_MESH_SERVICE_TUNNEL_H */
322 #endif
323 /* end of gnunet-mesh-service_tunnel.h */