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"
96 struct MeshTunnel3Queue;
99 * Callback called when a queued message is sent.
101 * @param cls Closure.
102 * @param t Tunnel this message was on.
103 * @param type Type of message sent.
104 * @param fwd Was this a FWD going message?
105 * @param size Size of the message.
107 typedef void (*GMT_sent) (void *cls,
108 struct MeshTunnel3 *t,
109 struct MeshTunnel3Queue *q,
110 uint16_t type, int fwd, size_t size);
113 /******************************************************************************/
114 /******************************** API ***********************************/
115 /******************************************************************************/
118 * Initialize tunnel subsystem.
120 * @param c Configuration handle.
121 * @param key ECC private key, to derive all other keys and do crypto.
124 GMT_init (const struct GNUNET_CONFIGURATION_Handle *c,
125 const struct GNUNET_CRYPTO_EddsaPrivateKey *key);
128 * Shut down the tunnel subsystem.
136 * @param destination Peer this tunnel is towards.
139 GMT_new (struct MeshPeer *destination);
142 * Tunnel is empty: destroy it.
144 * Notifies all connections about the destruction.
146 * @param t Tunnel to destroy.
149 GMT_destroy_empty (struct MeshTunnel3 *t);
152 * Destroy tunnel if empty (no more channels).
154 * @param t Tunnel to destroy if empty.
157 GMT_destroy_if_empty (struct MeshTunnel3 *t);
160 * Destroy the tunnel.
162 * This function does not generate any warning traffic to clients or peers.
165 * Cancel messages belonging to this tunnel queued to neighbors.
166 * Free any allocated resources linked to the tunnel.
168 * @param t The tunnel to destroy.
171 GMT_destroy (struct MeshTunnel3 *t);
174 * Change the tunnel state.
176 * @param t Tunnel whose state to change.
177 * @param state New state.
180 GMT_change_state (struct MeshTunnel3* t, enum MeshTunnel3State state);
183 * Add a connection to a tunnel.
186 * @param c Connection.
189 GMT_add_connection (struct MeshTunnel3 *t, struct MeshConnection *c);
192 * Remove a connection from a tunnel.
195 * @param c Connection.
198 GMT_remove_connection (struct MeshTunnel3 *t, struct MeshConnection *c);
201 * Add a channel to a tunnel.
207 GMT_add_channel (struct MeshTunnel3 *t, struct MeshChannel *ch);
210 * Remove a channel from a tunnel.
216 GMT_remove_channel (struct MeshTunnel3 *t, struct MeshChannel *ch);
219 * Search for a channel by global ID.
221 * @param t Tunnel containing the channel.
222 * @param chid Public channel number.
224 * @return channel handler, NULL if doesn't exist
227 GMT_get_channel (struct MeshTunnel3 *t, MESH_ChannelNumber chid);
230 * Decrypt and demultiplex by message type. Call appropriate handler
232 * towards a channel of a local tunnel.
234 * @param t Tunnel this message came on.
235 * @param msg Message header.
238 GMT_handle_encrypted (struct MeshTunnel3 *t,
239 const struct GNUNET_MESH_Encrypted *msg);
242 * Demultiplex an encapsulated KX message by message type.
244 * @param t Tunnel on which the message came.
245 * @param message KX message itself.
248 GMT_handle_kx (struct MeshTunnel3 *t,
249 const struct GNUNET_MessageHeader *message);
252 * @brief Use the given path for the tunnel.
253 * Update the next and prev hops (and RCs).
254 * (Re)start the path refresh in case the tunnel is locally owned.
256 * @param t Tunnel to update.
257 * @param p Path to use.
259 * @return Connection created.
261 struct MeshConnection *
262 GMT_use_path (struct MeshTunnel3 *t, struct MeshPeerPath *p);
265 * Count established (ready) connections of a tunnel.
267 * @param t Tunnel on which to count.
269 * @return Number of connections.
272 GMT_count_connections (struct MeshTunnel3 *t);
275 * Count channels of a tunnel.
277 * @param t Tunnel on which to count.
279 * @return Number of channels.
282 GMT_count_channels (struct MeshTunnel3 *t);
285 * Get the state of a tunnel.
289 * @return Tunnel's state.
291 enum MeshTunnel3State
292 GMT_get_state (struct MeshTunnel3 *t);
295 * Get the maximum buffer space for a tunnel towards a local client.
299 * @return Biggest buffer space offered by any channel in the tunnel.
302 GMT_get_channels_buffer (struct MeshTunnel3 *t);
305 * Get the total buffer space for a tunnel for P2P traffic.
309 * @return Buffer space offered by all connections in the tunnel.
312 GMT_get_connections_buffer (struct MeshTunnel3 *t);
315 * Get the tunnel's destination.
319 * @return ID of the destination peer.
321 const struct GNUNET_PeerIdentity *
322 GMT_get_destination (struct MeshTunnel3 *t);
325 * Get the tunnel's next free Channel ID.
329 * @return ID of a channel free to use.
332 GMT_get_next_chid (struct MeshTunnel3 *t);
335 * Send ACK on one or more channels due to buffer in connections.
337 * @param t Channel which has some free buffer space.
340 GMT_unchoke_channels (struct MeshTunnel3 *t);
343 * Send ACK on one or more connections due to buffer space to the client.
345 * Iterates all connections of the tunnel and sends ACKs appropriately.
347 * @param t Tunnel which has some free buffer space.
350 GMT_send_connection_acks (struct MeshTunnel3 *t);
353 * Sends an already built message on a tunnel, encrypting it and
354 * choosing the best connection.
356 * @param message Message to send. Function modifies it.
357 * @param t Tunnel on which this message is transmitted.
358 * @param ch Channel on which this message is transmitted.
359 * @param fwd Is this a fwd message on @c ch?
362 GMT_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
363 struct MeshTunnel3 *t,
364 struct MeshChannel *ch,
368 * Is the tunnel directed towards the local peer?
372 * @return #GNUNET_YES if it is loopback.
375 GMT_is_loopback (const struct MeshTunnel3 *t);
378 * Is the tunnel using this path already?
383 * @return #GNUNET_YES a connection uses this path.
386 GMT_is_path_used (const struct MeshTunnel3 *t, const struct MeshPeerPath *p);
389 * Get a cost of a path for a tunnel considering existing connections.
392 * @param path Candidate path.
394 * @return Cost of the path (path length + number of overlapping nodes)
397 GMT_get_path_cost (const struct MeshTunnel3 *t,
398 const struct MeshPeerPath *path);
401 * Get the static string for the peer this tunnel is directed.
405 * @return Static string the destination peer's ID.
408 GMT_2s (const struct MeshTunnel3 *t);
410 #if 0 /* keep Emacsens' auto-indent happy */
417 /* ifndef GNUNET_MESH_SERVICE_TUNNEL_H */
419 /* end of gnunet-mesh-service_tunnel.h */