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);
126 typedef void (*GMT_conn_iter) (void *cls, struct MeshConnection *c);
127 typedef void (*GMT_chan_iter) (void *cls, struct MeshChannel *ch);
130 /******************************************************************************/
131 /******************************** API ***********************************/
132 /******************************************************************************/
135 * Initialize tunnel subsystem.
137 * @param c Configuration handle.
138 * @param key ECC private key, to derive all other keys and do crypto.
141 GMT_init (const struct GNUNET_CONFIGURATION_Handle *c,
142 const struct GNUNET_CRYPTO_EddsaPrivateKey *key);
145 * Shut down the tunnel subsystem.
153 * @param destination Peer this tunnel is towards.
156 GMT_new (struct MeshPeer *destination);
159 * Tunnel is empty: destroy it.
161 * Notifies all connections about the destruction.
163 * @param t Tunnel to destroy.
166 GMT_destroy_empty (struct MeshTunnel3 *t);
169 * Destroy tunnel if empty (no more channels).
171 * @param t Tunnel to destroy if empty.
174 GMT_destroy_if_empty (struct MeshTunnel3 *t);
177 * Destroy the tunnel.
179 * This function does not generate any warning traffic to clients or peers.
182 * Cancel messages belonging to this tunnel queued to neighbors.
183 * Free any allocated resources linked to the tunnel.
185 * @param t The tunnel to destroy.
188 GMT_destroy (struct MeshTunnel3 *t);
192 * Change the tunnel's connection state.
194 * @param t Tunnel whose connection state to change.
195 * @param cstate New connection state.
198 GMT_change_cstate (struct MeshTunnel3* t, enum MeshTunnel3CState cstate);
202 * Change the tunnel encryption state.
204 * @param t Tunnel whose encryption state to change.
205 * @param state New encryption state.
208 GMT_change_estate (struct MeshTunnel3* t, enum MeshTunnel3EState state);
211 * Add a connection to a tunnel.
214 * @param c Connection.
217 GMT_add_connection (struct MeshTunnel3 *t, struct MeshConnection *c);
220 * Mark a path as no longer valid for this tunnel: has been tried and failed.
222 * @param t Tunnel to update.
223 * @param path Invalid path to remove. Is destroyed after removal.
226 GMT_remove_path (struct MeshTunnel3 *t, struct MeshPeerPath *path);
229 * Remove a connection from a tunnel.
232 * @param c Connection.
235 GMT_remove_connection (struct MeshTunnel3 *t, struct MeshConnection *c);
238 * Add a channel to a tunnel.
244 GMT_add_channel (struct MeshTunnel3 *t, struct MeshChannel *ch);
247 * Remove a channel from a tunnel.
253 GMT_remove_channel (struct MeshTunnel3 *t, struct MeshChannel *ch);
256 * Search for a channel by global ID.
258 * @param t Tunnel containing the channel.
259 * @param chid Public channel number.
261 * @return channel handler, NULL if doesn't exist
264 GMT_get_channel (struct MeshTunnel3 *t, MESH_ChannelNumber chid);
267 * Decrypt and demultiplex by message type. Call appropriate handler
269 * towards a channel of a local tunnel.
271 * @param t Tunnel this message came on.
272 * @param msg Message header.
275 GMT_handle_encrypted (struct MeshTunnel3 *t,
276 const struct GNUNET_MESH_Encrypted *msg);
279 * Demultiplex an encapsulated KX message by message type.
281 * @param t Tunnel on which the message came.
282 * @param message KX message itself.
285 GMT_handle_kx (struct MeshTunnel3 *t,
286 const struct GNUNET_MessageHeader *message);
289 * @brief Use the given path for the tunnel.
290 * Update the next and prev hops (and RCs).
291 * (Re)start the path refresh in case the tunnel is locally owned.
293 * @param t Tunnel to update.
294 * @param p Path to use.
296 * @return Connection created.
298 struct MeshConnection *
299 GMT_use_path (struct MeshTunnel3 *t, struct MeshPeerPath *p);
302 * Count established (ready) connections of a tunnel.
304 * @param t Tunnel on which to count.
306 * @return Number of connections.
309 GMT_count_connections (struct MeshTunnel3 *t);
312 * Count channels of a tunnel.
314 * @param t Tunnel on which to count.
316 * @return Number of channels.
319 GMT_count_channels (struct MeshTunnel3 *t);
322 * Get the connectivity state of a tunnel.
326 * @return Tunnel's connectivity state.
328 enum MeshTunnel3CState
329 GMT_get_cstate (struct MeshTunnel3 *t);
332 * Get the encryption state of a tunnel.
336 * @return Tunnel's encryption state.
338 enum MeshTunnel3EState
339 GMT_get_estate (struct MeshTunnel3 *t);
342 * Get the maximum buffer space for a tunnel towards a local client.
346 * @return Biggest buffer space offered by any channel in the tunnel.
349 GMT_get_channels_buffer (struct MeshTunnel3 *t);
352 * Get the total buffer space for a tunnel for P2P traffic.
356 * @return Buffer space offered by all connections in the tunnel.
359 GMT_get_connections_buffer (struct MeshTunnel3 *t);
362 * Get the tunnel's destination.
366 * @return ID of the destination peer.
368 const struct GNUNET_PeerIdentity *
369 GMT_get_destination (struct MeshTunnel3 *t);
372 * Get the tunnel's next free Channel ID.
376 * @return ID of a channel free to use.
379 GMT_get_next_chid (struct MeshTunnel3 *t);
382 * Send ACK on one or more channels due to buffer in connections.
384 * @param t Channel which has some free buffer space.
387 GMT_unchoke_channels (struct MeshTunnel3 *t);
390 * Send ACK on one or more connections due to buffer space to the client.
392 * Iterates all connections of the tunnel and sends ACKs appropriately.
394 * @param t Tunnel which has some free buffer space.
397 GMT_send_connection_acks (struct MeshTunnel3 *t);
400 * Cancel a previously sent message while it's in the queue.
402 * ONLY can be called before the continuation given to the send function
403 * is called. Once the continuation is called, the message is no longer in the
406 * @param q Handle to the queue.
409 GMT_cancel (struct MeshTunnel3Queue *q);
412 * Sends an already built message on a tunnel, encrypting it and
413 * choosing the best connection.
415 * @param message Message to send. Function modifies it.
416 * @param t Tunnel on which this message is transmitted.
417 * @param force Force the tunnel to take the message (buffer overfill).
418 * @param cont Continuation to call once message is really sent.
419 * @param cont_cls Closure for @c cont.
421 * @return Handle to cancel message. NULL if @c cont is NULL.
423 struct MeshTunnel3Queue *
424 GMT_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
425 struct MeshTunnel3 *t, int force,
426 GMT_sent cont, void *cont_cls);
429 * Is the tunnel directed towards the local peer?
433 * @return #GNUNET_YES if it is loopback.
436 GMT_is_loopback (const struct MeshTunnel3 *t);
439 * Is the tunnel using this path already?
444 * @return #GNUNET_YES a connection uses this path.
447 GMT_is_path_used (const struct MeshTunnel3 *t, const struct MeshPeerPath *p);
450 * Get a cost of a path for a tunnel considering existing connections.
453 * @param path Candidate path.
455 * @return Cost of the path (path length + number of overlapping nodes)
458 GMT_get_path_cost (const struct MeshTunnel3 *t,
459 const struct MeshPeerPath *path);
462 * Get the static string for the peer this tunnel is directed.
466 * @return Static string the destination peer's ID.
469 GMT_2s (const struct MeshTunnel3 *t);
472 * Log all possible info about the tunnel state.
474 * @param t Tunnel to debug.
477 GMT_debug (const struct MeshTunnel3 *t);
480 GMT_iterate_all (void *cls, GNUNET_CONTAINER_PeerMapIterator iter);
483 GMT_count_all (void);
486 GMT_iterate_connections (struct MeshTunnel3 *t, GMT_conn_iter iter, void *cls);
489 GMT_iterate_channels (struct MeshTunnel3 *t, GMT_chan_iter iter, void *cls);
491 #if 0 /* keep Emacsens' auto-indent happy */
498 /* ifndef GNUNET_MESH_SERVICE_TUNNEL_H */
500 /* end of gnunet-mesh-service_tunnel.h */