- fixes
[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 key ECC private key, to derive all other keys and do crypto.
93  */
94 void
95 GMT_init (const struct GNUNET_CONFIGURATION_Handle *c,
96           const struct GNUNET_CRYPTO_EddsaPrivateKey *key);
97
98 /**
99  * Shut down the tunnel subsystem.
100  */
101 void
102 GMT_shutdown (void);
103
104 /**
105  * Tunnel is empty: destroy it.
106  *
107  * Notifies all connections about the destruction.
108  *
109  * @param t Tunnel to destroy.
110  */
111 void
112 GMT_destroy_empty (struct MeshTunnel3 *t);
113
114 /**
115  * Destroy tunnel if empty (no more channels).
116  *
117  * @param t Tunnel to destroy if empty.
118  */
119 void
120 GMT_destroy_if_empty (struct MeshTunnel3 *t);
121
122 /**
123  * Destroy the tunnel.
124  *
125  * This function does not generate any warning traffic to clients or peers.
126  *
127  * Tasks:
128  * Cancel messages belonging to this tunnel queued to neighbors.
129  * Free any allocated resources linked to the tunnel.
130  *
131  * @param t The tunnel to destroy.
132  */
133 void
134 GMT_destroy (struct MeshTunnel3 *t);
135
136 /**
137  * Change the tunnel state.
138  *
139  * @param t Tunnel whose state to change.
140  * @param state New state.
141  */
142 void
143 GMT_change_state (struct MeshTunnel3* t, enum MeshTunnel3State state);
144
145 /**
146  * Add a connection to a tunnel.
147  *
148  * @param t Tunnel.
149  * @param c Connection.
150  */
151 void
152 GMT_add_connection (struct MeshTunnel3 *t, struct MeshConnection *c);
153
154 /**
155  * Remove a connection from a tunnel.
156  *
157  * @param t Tunnel.
158  * @param c Connection.
159  */
160 void
161 GMT_remove_connection (struct MeshTunnel3 *t, struct MeshConnection *c);
162
163 /**
164  * Add a channel to a tunnel.
165  *
166  * @param t Tunnel.
167  * @param ch Channel.
168  */
169 void
170 GMT_add_channel (struct MeshTunnel3 *t, struct MeshChannel *ch);
171
172 /**
173  * Remove a channel from a tunnel.
174  *
175  * @param t Tunnel.
176  * @param ch Channel.
177  */
178 void
179 GMT_remove_channel (struct MeshTunnel3 *t, struct MeshChannel *ch);
180
181 /**
182  * Search for a channel by global ID.
183  *
184  * @param t Tunnel containing the channel.
185  * @param chid Public channel number.
186  *
187  * @return channel handler, NULL if doesn't exist
188  */
189 struct MeshChannel *
190 GMT_get_channel (struct MeshTunnel3 *t, MESH_ChannelNumber chid);
191
192
193 /**
194  * Cache a message to be sent once tunnel is online.
195  *
196  * @param t Tunnel to hold the message.
197  * @param ch Channel the message is about.
198  * @param msg Message itself (copy will be made).
199  * @param fwd Is this fwd?
200  */
201 void
202 GMT_queue_data (struct MeshTunnel3 *t,
203                 struct MeshChannel *ch,
204                 struct GNUNET_MessageHeader *msg,
205                 int fwd);
206
207 /**
208  * Send all cached messages that we can, tunnel is online.
209  *
210  * @param t Tunnel that holds the messages.
211  * @param fwd Is this fwd?
212  */
213 void
214 GMT_send_queued_data (struct MeshTunnel3 *t, int fwd);
215
216 /**
217  * Count established (ready) connections of a tunnel.
218  *
219  * @param t Tunnel on which to count.
220  *
221  * @return Number of connections.
222  */
223 unsigned int
224 GMT_count_connections (struct MeshTunnel3 *t);
225
226 /**
227  * Count channels of a tunnel.
228  *
229  * @param t Tunnel on which to count.
230  *
231  * @return Number of channels.
232  */
233 unsigned int
234 GMT_count_channels (struct MeshTunnel3 *t);
235
236 /**
237  * Get the state of a tunnel.
238  *
239  * @param t Tunnel.
240  *
241  * @return Tunnel's state.
242  */
243 enum MeshTunnel3State
244 GMT_get_state (struct MeshTunnel3 *t);
245
246 /**
247  * Get the total buffer space for a tunnel.
248  *
249  * @param t Tunnel.
250  * @param fwd Is this for FWD traffic?
251  *
252  * @return Buffer space offered by all connections in the tunnel.
253  */
254 unsigned int
255 GMT_get_buffer (struct MeshTunnel3 *t, int fwd);
256
257 /**
258  * Get the tunnel's destination.
259  *
260  * @param t Tunnel.
261  *
262  * @return ID of the destination peer.
263  */
264 const struct GNUNET_PeerIdentity *
265 GMT_get_destination (struct MeshTunnel3 *t);
266
267 /**
268  * Get the tunnel's next free Channel ID.
269  *
270  * @param t Tunnel.
271  *
272  * @return ID of a channel free to use.
273  */
274 MESH_ChannelNumber
275 GMT_get_next_chid (struct MeshTunnel3 *t);
276
277 /**
278  * Sends an already built message on a tunnel, encrypting it and
279  * choosing the best connection.
280  *
281  * @param message Message to send. Function modifies it.
282  * @param t Tunnel on which this message is transmitted.
283  * @param ch Channel on which this message is transmitted.
284  * @param fwd Is this a fwd message?
285  */
286 void
287 GMT_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
288                            struct MeshTunnel3 *t,
289                            struct MeshChannel *ch,
290                            int fwd);
291
292 /**
293  * Is the tunnel directed towards the local peer?
294  *
295  * @param t Tunnel.
296  *
297  * @return GNUNET_YES if it is loopback.
298  */
299 int
300 GMT_is_loopback (const struct MeshTunnel3 *t);
301
302 /**
303  * Get the static string for the peer this tunnel is directed.
304  *
305  * @param t Tunnel.
306  *
307  * @return Static string the destination peer's ID.
308  */
309 const char *
310 GMT_2s (const struct MeshTunnel3 *t);
311
312 #if 0                           /* keep Emacsens' auto-indent happy */
313 {
314 #endif
315 #ifdef __cplusplus
316 }
317 #endif
318
319 /* ifndef GNUNET_MESH_SERVICE_TUNNEL_H */
320 #endif
321 /* end of gnunet-mesh-service_tunnel.h */