2 This file is part of GNUnet.
3 (C) 2013 Christian Grothoff (and other contributing authors)
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.
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.
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.
22 * @file mesh/gnunet-service-mesh_tunnel.h
23 * @brief mesh service; dealing with tunnels and crypto
24 * @author Bartlomiej Polot
26 * All functions in this file should use the prefix GMT (Gnunet Mesh Tunnel)
29 #ifndef GNUNET_SERVICE_MESH_TUNNEL_H
30 #define GNUNET_SERVICE_MESH_TUNNEL_H
35 #if 0 /* keep Emacsens' auto-indent happy */
41 #include "gnunet_util_lib.h"
44 * All the states a tunnel can be in.
49 * Uninitialized status, should never appear in operation.
54 * Path to the peer not known yet
56 MESH_TUNNEL3_SEARCHING,
59 * Request sent, not yet answered.
64 * Peer connected and ready to accept data
69 * Peer connected previosly but not responding
71 MESH_TUNNEL3_RECONNECTING
75 * Struct containing all information regarding a given peer
80 #include "gnunet-service-mesh_channel.h"
81 #include "gnunet-service-mesh_connection.h"
84 /******************************************************************************/
85 /******************************** API ***********************************/
86 /******************************************************************************/
89 * Initialize tunnel subsystem.
91 * @param c Configuration handle.
92 * @param key ECC private key, to derive all other keys and do crypto.
95 GMT_init (const struct GNUNET_CONFIGURATION_Handle *c,
96 const struct GNUNET_CRYPTO_EddsaPrivateKey *key);
99 * Shut down the tunnel subsystem.
107 * @param destination Peer this tunnel is towards.
110 GMT_new (struct MeshPeer *destination);
113 * Tunnel is empty: destroy it.
115 * Notifies all connections about the destruction.
117 * @param t Tunnel to destroy.
120 GMT_destroy_empty (struct MeshTunnel3 *t);
123 * Destroy tunnel if empty (no more channels).
125 * @param t Tunnel to destroy if empty.
128 GMT_destroy_if_empty (struct MeshTunnel3 *t);
131 * Destroy the tunnel.
133 * This function does not generate any warning traffic to clients or peers.
136 * Cancel messages belonging to this tunnel queued to neighbors.
137 * Free any allocated resources linked to the tunnel.
139 * @param t The tunnel to destroy.
142 GMT_destroy (struct MeshTunnel3 *t);
145 * Change the tunnel state.
147 * @param t Tunnel whose state to change.
148 * @param state New state.
151 GMT_change_state (struct MeshTunnel3* t, enum MeshTunnel3State state);
154 * Add a connection to a tunnel.
157 * @param c Connection.
160 GMT_add_connection (struct MeshTunnel3 *t, struct MeshConnection *c);
163 * Remove a connection from a tunnel.
166 * @param c Connection.
169 GMT_remove_connection (struct MeshTunnel3 *t, struct MeshConnection *c);
172 * Add a channel to a tunnel.
178 GMT_add_channel (struct MeshTunnel3 *t, struct MeshChannel *ch);
181 * Remove a channel from a tunnel.
187 GMT_remove_channel (struct MeshTunnel3 *t, struct MeshChannel *ch);
190 * Search for a channel by global ID.
192 * @param t Tunnel containing the channel.
193 * @param chid Public channel number.
195 * @return channel handler, NULL if doesn't exist
198 GMT_get_channel (struct MeshTunnel3 *t, MESH_ChannelNumber chid);
202 * Cache a message to be sent once tunnel is online.
204 * @param t Tunnel to hold the message.
205 * @param ch Channel the message is about.
206 * @param msg Message itself (copy will be made).
207 * @param fwd Is this fwd?
210 GMT_queue_data (struct MeshTunnel3 *t,
211 struct MeshChannel *ch,
212 struct GNUNET_MessageHeader *msg,
216 * Send all cached messages that we can, tunnel is online.
218 * @param t Tunnel that holds the messages.
219 * @param fwd Is this fwd?
222 GMT_send_queued_data (struct MeshTunnel3 *t, int fwd);
225 * @brief Use the given path for the tunnel.
226 * Update the next and prev hops (and RCs).
227 * (Re)start the path refresh in case the tunnel is locally owned.
229 * @param t Tunnel to update.
230 * @param p Path to use.
232 * @return Connection created.
234 struct MeshConnection *
235 GMT_use_path (struct MeshTunnel3 *t, struct MeshPeerPath *p);
238 * Count established (ready) connections of a tunnel.
240 * @param t Tunnel on which to count.
242 * @return Number of connections.
245 GMT_count_connections (struct MeshTunnel3 *t);
248 * Count channels of a tunnel.
250 * @param t Tunnel on which to count.
252 * @return Number of channels.
255 GMT_count_channels (struct MeshTunnel3 *t);
258 * Get the state of a tunnel.
262 * @return Tunnel's state.
264 enum MeshTunnel3State
265 GMT_get_state (struct MeshTunnel3 *t);
268 * Get the total buffer space for a tunnel.
271 * @param fwd Is this for FWD traffic?
273 * @return Buffer space offered by all connections in the tunnel.
276 GMT_get_buffer (struct MeshTunnel3 *t, int fwd);
279 * Get the tunnel's destination.
283 * @return ID of the destination peer.
285 const struct GNUNET_PeerIdentity *
286 GMT_get_destination (struct MeshTunnel3 *t);
289 * Get the tunnel's next free Channel ID.
293 * @return ID of a channel free to use.
296 GMT_get_next_chid (struct MeshTunnel3 *t);
299 * Sends an already built message on a tunnel, encrypting it and
300 * choosing the best connection.
302 * @param message Message to send. Function modifies it.
303 * @param t Tunnel on which this message is transmitted.
304 * @param ch Channel on which this message is transmitted.
305 * @param fwd Is this a fwd message?
308 GMT_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
309 struct MeshTunnel3 *t,
310 struct MeshChannel *ch,
314 * Is the tunnel directed towards the local peer?
318 * @return GNUNET_YES if it is loopback.
321 GMT_is_loopback (const struct MeshTunnel3 *t);
324 * Is the tunnel using this path already?
329 * @return GNUNET_YES a connection uses this path.
332 GMT_is_path_used (const struct MeshTunnel3 *t, const struct MeshPeerPath *p);
335 * Get a cost of a path for a tunnel considering existing connections.
338 * @param path Candidate path.
340 * @return Cost of the path (path length + number of overlapping nodes)
343 GMT_get_path_cost (const struct MeshTunnel3 *t,
344 const struct MeshPeerPath *path);
347 * Get the static string for the peer this tunnel is directed.
351 * @return Static string the destination peer's ID.
354 GMT_2s (const struct MeshTunnel3 *t);
356 #if 0 /* keep Emacsens' auto-indent happy */
363 /* ifndef GNUNET_MESH_SERVICE_TUNNEL_H */
365 /* end of gnunet-mesh-service_tunnel.h */