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"
82 #include "gnunet-service-mesh_peer.h"
85 /******************************************************************************/
86 /******************************** API ***********************************/
87 /******************************************************************************/
90 * Initialize tunnel subsystem.
92 * @param c Configuration handle.
93 * @param key ECC private key, to derive all other keys and do crypto.
96 GMT_init (const struct GNUNET_CONFIGURATION_Handle *c,
97 const struct GNUNET_CRYPTO_EddsaPrivateKey *key);
100 * Shut down the tunnel subsystem.
108 * @param destination Peer this tunnel is towards.
111 GMT_new (struct MeshPeer *destination);
114 * Tunnel is empty: destroy it.
116 * Notifies all connections about the destruction.
118 * @param t Tunnel to destroy.
121 GMT_destroy_empty (struct MeshTunnel3 *t);
124 * Destroy tunnel if empty (no more channels).
126 * @param t Tunnel to destroy if empty.
129 GMT_destroy_if_empty (struct MeshTunnel3 *t);
132 * Destroy the tunnel.
134 * This function does not generate any warning traffic to clients or peers.
137 * Cancel messages belonging to this tunnel queued to neighbors.
138 * Free any allocated resources linked to the tunnel.
140 * @param t The tunnel to destroy.
143 GMT_destroy (struct MeshTunnel3 *t);
146 * Change the tunnel state.
148 * @param t Tunnel whose state to change.
149 * @param state New state.
152 GMT_change_state (struct MeshTunnel3* t, enum MeshTunnel3State state);
155 * Add a connection to a tunnel.
158 * @param c Connection.
161 GMT_add_connection (struct MeshTunnel3 *t, struct MeshConnection *c);
164 * Remove a connection from a tunnel.
167 * @param c Connection.
170 GMT_remove_connection (struct MeshTunnel3 *t, struct MeshConnection *c);
173 * Add a channel to a tunnel.
179 GMT_add_channel (struct MeshTunnel3 *t, struct MeshChannel *ch);
182 * Remove a channel from a tunnel.
188 GMT_remove_channel (struct MeshTunnel3 *t, struct MeshChannel *ch);
191 * Search for a channel by global ID.
193 * @param t Tunnel containing the channel.
194 * @param chid Public channel number.
196 * @return channel handler, NULL if doesn't exist
199 GMT_get_channel (struct MeshTunnel3 *t, MESH_ChannelNumber chid);
202 * Decrypt and demultiplex by message type. Call appropriate handler
204 * towards a channel of a local tunnel.
206 * @param t Tunnel this message came on.
207 * @param msgh Message header.
208 * @param fwd Is this message fwd?
211 GMT_handle_encrypted (struct MeshTunnel3 *t,
212 const struct GNUNET_MESH_Encrypted *msg,
216 * Cache a message to be sent once tunnel is online.
218 * @param t Tunnel to hold the message.
219 * @param ch Channel the message is about.
220 * @param msg Message itself (copy will be made).
221 * @param fwd Is this fwd?
224 GMT_queue_data (struct MeshTunnel3 *t,
225 struct MeshChannel *ch,
226 struct GNUNET_MessageHeader *msg,
230 * Send all cached messages that we can, tunnel is online.
232 * @param t Tunnel that holds the messages.
233 * @param fwd Is this fwd?
236 GMT_send_queued_data (struct MeshTunnel3 *t, int fwd);
239 * @brief Use the given path for the tunnel.
240 * Update the next and prev hops (and RCs).
241 * (Re)start the path refresh in case the tunnel is locally owned.
243 * @param t Tunnel to update.
244 * @param p Path to use.
246 * @return Connection created.
248 struct MeshConnection *
249 GMT_use_path (struct MeshTunnel3 *t, struct MeshPeerPath *p);
252 * Count established (ready) connections of a tunnel.
254 * @param t Tunnel on which to count.
256 * @return Number of connections.
259 GMT_count_connections (struct MeshTunnel3 *t);
262 * Count channels of a tunnel.
264 * @param t Tunnel on which to count.
266 * @return Number of channels.
269 GMT_count_channels (struct MeshTunnel3 *t);
272 * Get the state of a tunnel.
276 * @return Tunnel's state.
278 enum MeshTunnel3State
279 GMT_get_state (struct MeshTunnel3 *t);
282 * Get the total buffer space for a tunnel.
285 * @param fwd Is this for FWD traffic?
287 * @return Buffer space offered by all connections in the tunnel.
290 GMT_get_buffer (struct MeshTunnel3 *t, int fwd);
293 * Get the tunnel's destination.
297 * @return ID of the destination peer.
299 const struct GNUNET_PeerIdentity *
300 GMT_get_destination (struct MeshTunnel3 *t);
303 * Get the tunnel's next free Channel ID.
307 * @return ID of a channel free to use.
310 GMT_get_next_chid (struct MeshTunnel3 *t);
313 * Send ACK on one or more connections due to buffer space to the client.
315 * Iterates all connections of the tunnel and sends ACKs appropriately.
317 * @param ch Channel which has some free buffer space.
318 * @param fwd Is this in for FWD traffic? (ACK goes dest->root)
321 GMT_send_acks (struct MeshTunnel3 *t, unsigned int buffer, int fwd);
324 * Sends an already built message on a tunnel, encrypting it and
325 * choosing the best connection.
327 * @param message Message to send. Function modifies it.
328 * @param t Tunnel on which this message is transmitted.
329 * @param ch Channel on which this message is transmitted.
330 * @param fwd Is this a fwd message?
333 GMT_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
334 struct MeshTunnel3 *t,
335 struct MeshChannel *ch,
339 * Is the tunnel directed towards the local peer?
343 * @return GNUNET_YES if it is loopback.
346 GMT_is_loopback (const struct MeshTunnel3 *t);
349 * Is the tunnel using this path already?
354 * @return GNUNET_YES a connection uses this path.
357 GMT_is_path_used (const struct MeshTunnel3 *t, const struct MeshPeerPath *p);
360 * Get a cost of a path for a tunnel considering existing connections.
363 * @param path Candidate path.
365 * @return Cost of the path (path length + number of overlapping nodes)
368 GMT_get_path_cost (const struct MeshTunnel3 *t,
369 const struct MeshPeerPath *path);
372 * Get the static string for the peer this tunnel is directed.
376 * @return Static string the destination peer's ID.
379 GMT_2s (const struct MeshTunnel3 *t);
381 #if 0 /* keep Emacsens' auto-indent happy */
388 /* ifndef GNUNET_MESH_SERVICE_TUNNEL_H */
390 /* end of gnunet-mesh-service_tunnel.h */