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 connectivity states a tunnel can be in.
46 enum MeshTunnel3CState
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.
71 * All the encryption states a tunnel can be in.
73 enum MeshTunnel3EState
76 * Uninitialized status, should never appear in operation.
78 MESH_TUNNEL3_KEY_UNINITIALIZED,
81 * Ephemeral key sent, waiting for peer's key.
83 MESH_TUNNEL3_KEY_SENT,
86 * New ephemeral key and ping sent, waiting for pong.
87 * This means that we DO have the peer's ephemeral key, otherwise the
88 * state would be KEY_SENT.
90 MESH_TUNNEL3_KEY_PING,
93 * Handshake completed: session key available.
99 * Struct containing all information regarding a given peer
104 #include "gnunet-service-mesh_channel.h"
105 #include "gnunet-service-mesh_connection.h"
106 #include "gnunet-service-mesh_peer.h"
109 * Handle for messages queued but not yet sent.
111 struct MeshTunnel3Queue;
114 * Callback called when a queued message is sent.
116 * @param cls Closure.
117 * @param t Tunnel this message was on.
118 * @param type Type of message sent.
119 * @param size Size of the message.
121 typedef void (*GMT_sent) (void *cls,
122 struct MeshTunnel3 *t,
123 struct MeshTunnel3Queue *q,
124 uint16_t type, size_t size);
127 /******************************************************************************/
128 /******************************** API ***********************************/
129 /******************************************************************************/
132 * Initialize tunnel subsystem.
134 * @param c Configuration handle.
135 * @param key ECC private key, to derive all other keys and do crypto.
138 GMT_init (const struct GNUNET_CONFIGURATION_Handle *c,
139 const struct GNUNET_CRYPTO_EddsaPrivateKey *key);
142 * Shut down the tunnel subsystem.
150 * @param destination Peer this tunnel is towards.
153 GMT_new (struct MeshPeer *destination);
156 * Tunnel is empty: destroy it.
158 * Notifies all connections about the destruction.
160 * @param t Tunnel to destroy.
163 GMT_destroy_empty (struct MeshTunnel3 *t);
166 * Destroy tunnel if empty (no more channels).
168 * @param t Tunnel to destroy if empty.
171 GMT_destroy_if_empty (struct MeshTunnel3 *t);
174 * Destroy the tunnel.
176 * This function does not generate any warning traffic to clients or peers.
179 * Cancel messages belonging to this tunnel queued to neighbors.
180 * Free any allocated resources linked to the tunnel.
182 * @param t The tunnel to destroy.
185 GMT_destroy (struct MeshTunnel3 *t);
189 * Change the tunnel's connection state.
191 * @param t Tunnel whose connection state to change.
192 * @param cstate New connection state.
195 GMT_change_cstate (struct MeshTunnel3* t, enum MeshTunnel3CState cstate);
199 * Change the tunnel encryption state.
201 * @param t Tunnel whose encryption state to change.
202 * @param state New encryption state.
205 GMT_change_estate (struct MeshTunnel3* t, enum MeshTunnel3EState state);
208 * Add a connection to a tunnel.
211 * @param c Connection.
214 GMT_add_connection (struct MeshTunnel3 *t, struct MeshConnection *c);
217 * Mark a path as no longer valid for this tunnel: has been tried and failed.
219 * @param t Tunnel to update.
220 * @param path Invalid path to remove. Is destroyed after removal.
223 GMT_remove_path (struct MeshTunnel3 *t, struct MeshPeerPath *path);
226 * Remove a connection from a tunnel.
229 * @param c Connection.
232 GMT_remove_connection (struct MeshTunnel3 *t, struct MeshConnection *c);
235 * Add a channel to a tunnel.
241 GMT_add_channel (struct MeshTunnel3 *t, struct MeshChannel *ch);
244 * Remove a channel from a tunnel.
250 GMT_remove_channel (struct MeshTunnel3 *t, struct MeshChannel *ch);
253 * Search for a channel by global ID.
255 * @param t Tunnel containing the channel.
256 * @param chid Public channel number.
258 * @return channel handler, NULL if doesn't exist
261 GMT_get_channel (struct MeshTunnel3 *t, MESH_ChannelNumber chid);
264 * Decrypt and demultiplex by message type. Call appropriate handler
266 * towards a channel of a local tunnel.
268 * @param t Tunnel this message came on.
269 * @param msg Message header.
272 GMT_handle_encrypted (struct MeshTunnel3 *t,
273 const struct GNUNET_MESH_Encrypted *msg);
276 * Demultiplex an encapsulated KX message by message type.
278 * @param t Tunnel on which the message came.
279 * @param message KX message itself.
282 GMT_handle_kx (struct MeshTunnel3 *t,
283 const struct GNUNET_MessageHeader *message);
286 * @brief Use the given path for the tunnel.
287 * Update the next and prev hops (and RCs).
288 * (Re)start the path refresh in case the tunnel is locally owned.
290 * @param t Tunnel to update.
291 * @param p Path to use.
293 * @return Connection created.
295 struct MeshConnection *
296 GMT_use_path (struct MeshTunnel3 *t, struct MeshPeerPath *p);
299 * Count established (ready) connections of a tunnel.
301 * @param t Tunnel on which to count.
303 * @return Number of connections.
306 GMT_count_connections (struct MeshTunnel3 *t);
309 * Count channels of a tunnel.
311 * @param t Tunnel on which to count.
313 * @return Number of channels.
316 GMT_count_channels (struct MeshTunnel3 *t);
319 * Get the connectivity state of a tunnel.
323 * @return Tunnel's connectivity state.
325 enum MeshTunnel3CState
326 GMT_get_cstate (struct MeshTunnel3 *t);
329 * Get the maximum buffer space for a tunnel towards a local client.
333 * @return Biggest buffer space offered by any channel in the tunnel.
336 GMT_get_channels_buffer (struct MeshTunnel3 *t);
339 * Get the total buffer space for a tunnel for P2P traffic.
343 * @return Buffer space offered by all connections in the tunnel.
346 GMT_get_connections_buffer (struct MeshTunnel3 *t);
349 * Get the tunnel's destination.
353 * @return ID of the destination peer.
355 const struct GNUNET_PeerIdentity *
356 GMT_get_destination (struct MeshTunnel3 *t);
359 * Get the tunnel's next free Channel ID.
363 * @return ID of a channel free to use.
366 GMT_get_next_chid (struct MeshTunnel3 *t);
369 * Send ACK on one or more channels due to buffer in connections.
371 * @param t Channel which has some free buffer space.
374 GMT_unchoke_channels (struct MeshTunnel3 *t);
377 * Send ACK on one or more connections due to buffer space to the client.
379 * Iterates all connections of the tunnel and sends ACKs appropriately.
381 * @param t Tunnel which has some free buffer space.
384 GMT_send_connection_acks (struct MeshTunnel3 *t);
387 * Cancel a previously sent message while it's in the queue.
389 * ONLY can be called before the continuation given to the send function
390 * is called. Once the continuation is called, the message is no longer in the
393 * @param q Handle to the queue.
396 GMT_cancel (struct MeshTunnel3Queue *q);
399 * Sends an already built message on a tunnel, encrypting it and
400 * choosing the best connection.
402 * @param message Message to send. Function modifies it.
403 * @param t Tunnel on which this message is transmitted.
404 * @param force Force the tunnel to take the message (buffer overfill).
405 * @param cont Continuation to call once message is really sent.
406 * @param cont_cls Closure for @c cont.
408 * @return Handle to cancel message. NULL if @c cont is NULL.
410 struct MeshTunnel3Queue *
411 GMT_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
412 struct MeshTunnel3 *t, int force,
413 GMT_sent cont, void *cont_cls);
416 * Is the tunnel directed towards the local peer?
420 * @return #GNUNET_YES if it is loopback.
423 GMT_is_loopback (const struct MeshTunnel3 *t);
426 * Is the tunnel using this path already?
431 * @return #GNUNET_YES a connection uses this path.
434 GMT_is_path_used (const struct MeshTunnel3 *t, const struct MeshPeerPath *p);
437 * Get a cost of a path for a tunnel considering existing connections.
440 * @param path Candidate path.
442 * @return Cost of the path (path length + number of overlapping nodes)
445 GMT_get_path_cost (const struct MeshTunnel3 *t,
446 const struct MeshPeerPath *path);
449 * Get the static string for the peer this tunnel is directed.
453 * @return Static string the destination peer's ID.
456 GMT_2s (const struct MeshTunnel3 *t);
459 * Log all possible info about the tunnel state.
461 * @param t Tunnel to debug.
464 GMT_debug (const struct MeshTunnel3 *t);
466 #if 0 /* keep Emacsens' auto-indent happy */
473 /* ifndef GNUNET_MESH_SERVICE_TUNNEL_H */
475 /* end of gnunet-mesh-service_tunnel.h */