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 * Ephemeral key sent, waiting for peer's key.
66 MESH_TUNNEL3_KEY_SENT,
69 * Peer connected and ready to accept data.
74 * Peer connected previosly but not responding.
76 MESH_TUNNEL3_RECONNECTING,
79 * New ephemeral key and ping sent, waiting for pong.
80 * This means that we DO have the peer's ephemeral key, otherwise the
81 * state would be KEY_SENT.
87 * Struct containing all information regarding a given peer
92 #include "gnunet-service-mesh_channel.h"
93 #include "gnunet-service-mesh_connection.h"
94 #include "gnunet-service-mesh_peer.h"
97 * Handle for messages queued but not yet sent.
99 struct MeshTunnel3Queue;
102 * Callback called when a queued message is sent.
104 * @param cls Closure.
105 * @param t Tunnel this message was on.
106 * @param type Type of message sent.
107 * @param size Size of the message.
109 typedef void (*GMT_sent) (void *cls,
110 struct MeshTunnel3 *t,
111 struct MeshTunnel3Queue *q,
112 uint16_t type, size_t size);
115 /******************************************************************************/
116 /******************************** API ***********************************/
117 /******************************************************************************/
120 * Initialize tunnel subsystem.
122 * @param c Configuration handle.
123 * @param key ECC private key, to derive all other keys and do crypto.
126 GMT_init (const struct GNUNET_CONFIGURATION_Handle *c,
127 const struct GNUNET_CRYPTO_EddsaPrivateKey *key);
130 * Shut down the tunnel subsystem.
138 * @param destination Peer this tunnel is towards.
141 GMT_new (struct MeshPeer *destination);
144 * Tunnel is empty: destroy it.
146 * Notifies all connections about the destruction.
148 * @param t Tunnel to destroy.
151 GMT_destroy_empty (struct MeshTunnel3 *t);
154 * Destroy tunnel if empty (no more channels).
156 * @param t Tunnel to destroy if empty.
159 GMT_destroy_if_empty (struct MeshTunnel3 *t);
162 * Destroy the tunnel.
164 * This function does not generate any warning traffic to clients or peers.
167 * Cancel messages belonging to this tunnel queued to neighbors.
168 * Free any allocated resources linked to the tunnel.
170 * @param t The tunnel to destroy.
173 GMT_destroy (struct MeshTunnel3 *t);
176 * Change the tunnel state.
178 * @param t Tunnel whose state to change.
179 * @param state New state.
182 GMT_change_state (struct MeshTunnel3* t, enum MeshTunnel3State state);
185 * Add a connection to a tunnel.
188 * @param c Connection.
191 GMT_add_connection (struct MeshTunnel3 *t, struct MeshConnection *c);
194 * Remove a connection from a tunnel.
197 * @param c Connection.
200 GMT_remove_connection (struct MeshTunnel3 *t, struct MeshConnection *c);
203 * Add a channel to a tunnel.
209 GMT_add_channel (struct MeshTunnel3 *t, struct MeshChannel *ch);
212 * Remove a channel from a tunnel.
218 GMT_remove_channel (struct MeshTunnel3 *t, struct MeshChannel *ch);
221 * Search for a channel by global ID.
223 * @param t Tunnel containing the channel.
224 * @param chid Public channel number.
226 * @return channel handler, NULL if doesn't exist
229 GMT_get_channel (struct MeshTunnel3 *t, MESH_ChannelNumber chid);
232 * Decrypt and demultiplex by message type. Call appropriate handler
234 * towards a channel of a local tunnel.
236 * @param t Tunnel this message came on.
237 * @param msg Message header.
240 GMT_handle_encrypted (struct MeshTunnel3 *t,
241 const struct GNUNET_MESH_Encrypted *msg);
244 * Demultiplex an encapsulated KX message by message type.
246 * @param t Tunnel on which the message came.
247 * @param message KX message itself.
250 GMT_handle_kx (struct MeshTunnel3 *t,
251 const struct GNUNET_MessageHeader *message);
254 * @brief Use the given path for the tunnel.
255 * Update the next and prev hops (and RCs).
256 * (Re)start the path refresh in case the tunnel is locally owned.
258 * @param t Tunnel to update.
259 * @param p Path to use.
261 * @return Connection created.
263 struct MeshConnection *
264 GMT_use_path (struct MeshTunnel3 *t, struct MeshPeerPath *p);
267 * Count established (ready) connections of a tunnel.
269 * @param t Tunnel on which to count.
271 * @return Number of connections.
274 GMT_count_connections (struct MeshTunnel3 *t);
277 * Count channels of a tunnel.
279 * @param t Tunnel on which to count.
281 * @return Number of channels.
284 GMT_count_channels (struct MeshTunnel3 *t);
287 * Get the state of a tunnel.
291 * @return Tunnel's state.
293 enum MeshTunnel3State
294 GMT_get_state (struct MeshTunnel3 *t);
297 * Get the maximum buffer space for a tunnel towards a local client.
301 * @return Biggest buffer space offered by any channel in the tunnel.
304 GMT_get_channels_buffer (struct MeshTunnel3 *t);
307 * Get the total buffer space for a tunnel for P2P traffic.
311 * @return Buffer space offered by all connections in the tunnel.
314 GMT_get_connections_buffer (struct MeshTunnel3 *t);
317 * Get the tunnel's destination.
321 * @return ID of the destination peer.
323 const struct GNUNET_PeerIdentity *
324 GMT_get_destination (struct MeshTunnel3 *t);
327 * Get the tunnel's next free Channel ID.
331 * @return ID of a channel free to use.
334 GMT_get_next_chid (struct MeshTunnel3 *t);
337 * Send ACK on one or more channels due to buffer in connections.
339 * @param t Channel which has some free buffer space.
342 GMT_unchoke_channels (struct MeshTunnel3 *t);
345 * Send ACK on one or more connections due to buffer space to the client.
347 * Iterates all connections of the tunnel and sends ACKs appropriately.
349 * @param t Tunnel which has some free buffer space.
352 GMT_send_connection_acks (struct MeshTunnel3 *t);
355 * Sends an already built message on a tunnel, encrypting it and
356 * choosing the best connection.
358 * @param message Message to send. Function modifies it.
359 * @param t Tunnel on which this message is transmitted.
360 * @param ch Channel on which this message is transmitted.
361 * @param fwd Is this a fwd message on @c ch?
362 * @param cont Continuation to call once message is really sent.
363 * @param cls Closure for @c cont.
365 * @return Handle to cancel message. NULL if @c cont is NULL.
367 struct MeshTunnel3Queue *
368 GMT_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
369 struct MeshTunnel3 *t,
370 struct MeshChannel *ch, int fwd,
371 GMT_sent cont, void *cls);
374 * Is the tunnel directed towards the local peer?
378 * @return #GNUNET_YES if it is loopback.
381 GMT_is_loopback (const struct MeshTunnel3 *t);
384 * Is the tunnel using this path already?
389 * @return #GNUNET_YES a connection uses this path.
392 GMT_is_path_used (const struct MeshTunnel3 *t, const struct MeshPeerPath *p);
395 * Get a cost of a path for a tunnel considering existing connections.
398 * @param path Candidate path.
400 * @return Cost of the path (path length + number of overlapping nodes)
403 GMT_get_path_cost (const struct MeshTunnel3 *t,
404 const struct MeshPeerPath *path);
407 * Get the static string for the peer this tunnel is directed.
411 * @return Static string the destination peer's ID.
414 GMT_2s (const struct MeshTunnel3 *t);
416 #if 0 /* keep Emacsens' auto-indent happy */
423 /* ifndef GNUNET_MESH_SERVICE_TUNNEL_H */
425 /* end of gnunet-mesh-service_tunnel.h */