2 This file is part of GNUnet.
3 Copyright (C) 2001-2017 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @file cadet/gnunet-service-cadet_tunnels.h
23 * @brief Information we track per tunnel.
24 * @author Bartlomiej Polot
25 * @author Christian Grothoff
27 #ifndef GNUNET_SERVICE_CADET_TUNNELS_H
28 #define GNUNET_SERVICE_CADET_TUNNELS_H
30 #include "gnunet-service-cadet.h"
31 #include "cadet_protocol.h"
35 * How many connections would we like to have per tunnel?
37 #define DESIRED_CONNECTIONS_PER_TUNNEL 3
41 * All the encryption states a tunnel can be in.
43 enum CadetTunnelEState
46 * Uninitialized status, we need to send KX. We will stay
47 * in this state until the first connection is up.
49 CADET_TUNNEL_KEY_UNINITIALIZED,
52 * KX message sent, waiting for other peer's KX_AUTH.
54 CADET_TUNNEL_KEY_AX_SENT,
57 * KX message received, trying to send back KX_AUTH.
59 CADET_TUNNEL_KEY_AX_RECV,
62 * KX message sent and received, trying to send back KX_AUTH.
64 CADET_TUNNEL_KEY_AX_SENT_AND_RECV,
67 * KX received and we sent KX_AUTH back, but we got no traffic yet,
68 * so we're waiting for either KX_AUTH or ENCRYPED traffic from
71 * We will not yet send traffic, as this might have been a replay.
72 * The other (initiating) peer should send a CHANNEL_OPEN next
73 * anyway, and then we are in business!
75 CADET_TUNNEL_KEY_AX_AUTH_SENT,
78 * Handshake completed: session key available.
85 * Get the static string for the peer this tunnel is directed.
89 * @return Static string the destination peer's ID.
92 GCT_2s (const struct CadetTunnel *t);
96 * Create a tunnel to @a destionation. Must only be called
97 * from within #GCP_get_tunnel().
99 * @param destination where to create the tunnel to
100 * @return new tunnel to @a destination
103 GCT_create_tunnel (struct CadetPeer *destination);
107 * Destroys the tunnel @a t now, without delay. Used during shutdown.
109 * @param t tunnel to destroy
112 GCT_destroy_tunnel_now (struct CadetTunnel *t);
116 * Add a @a connection to the @a tunnel.
119 * @param cid connection identifer to use for the connection
120 * @param path path to use for the connection
121 * @return #GNUNET_OK on success,
122 * #GNUNET_SYSERR on failure (duplicate connection)
125 GCT_add_inbound_connection (struct CadetTunnel *t,
127 GNUNET_CADET_ConnectionTunnelIdentifier *cid,
128 struct CadetPeerPath *path);
132 * We lost a connection, remove it from our list and clean up
133 * the connection object itself.
135 * @param ct binding of connection to tunnel of the connection that was lost.
138 GCT_connection_lost (struct CadetTConnection *ct);
142 * Return the peer to which this tunnel goes.
145 * @return the destination of the tunnel
148 GCT_get_destination (struct CadetTunnel *t);
152 * Consider using the path @a p for the tunnel @a t.
153 * The tunnel destination is at offset @a off in path @a p.
155 * @param cls our tunnel
156 * @param path a path to our destination
157 * @param off offset of the destination on path @a path
160 GCT_consider_path (struct CadetTunnel *t,
161 struct CadetPeerPath *p,
166 * Add a channel to a tunnel.
170 * @return unique number identifying @a ch within @a t
172 struct GNUNET_CADET_ChannelTunnelNumber
173 GCT_add_channel (struct CadetTunnel *t,
174 struct CadetChannel *ch);
178 * Remove a channel from a tunnel.
182 * @param ctn unique number identifying @a ch within @a t
185 GCT_remove_channel (struct CadetTunnel *t,
186 struct CadetChannel *ch,
187 struct GNUNET_CADET_ChannelTunnelNumber ctn);
191 * Send a DESTROY message via the tunnel.
193 * @param t the tunnel to transmit over
194 * @param ctn ID of the channel to destroy
197 GCT_send_channel_destroy (struct CadetTunnel *t,
198 struct GNUNET_CADET_ChannelTunnelNumber ctn);
202 * Function called when a transmission requested using #GCT_send is done.
205 * @param ctn identifier of the connection used for transmission, NULL if
206 * the transmission failed (to be used to match ACKs to the
207 * respective connection for connection performance evaluation)
210 (*GCT_SendContinuation)(void *cls,
212 GNUNET_CADET_ConnectionTunnelIdentifier *cid);
216 * Sends an already built message on a tunnel, encrypting it and
217 * choosing the best connection if not provided.
219 * @param message Message to send. Function modifies it.
220 * @param t Tunnel on which this message is transmitted.
221 * @param cont Continuation to call once message is really sent.
222 * @param cont_cls Closure for @c cont.
223 * @return Handle to cancel message.
225 struct CadetTunnelQueueEntry *
226 GCT_send (struct CadetTunnel *t,
227 const struct GNUNET_MessageHeader *message,
228 GCT_SendContinuation cont,
233 * Cancel a previously sent message while it's in the queue.
235 * ONLY can be called before the continuation given to the send
236 * function is called. Once the continuation is called, the message is
237 * no longer in the queue!
239 * @param q Handle to the queue entry to cancel.
242 GCT_send_cancel (struct CadetTunnelQueueEntry *q);
246 * Return the number of channels using a tunnel.
248 * @param t tunnel to count obtain the number of channels for
249 * @return number of channels using the tunnel
252 GCT_count_channels (struct CadetTunnel *t);
256 * Return the number of connections available for a tunnel.
258 * @param t tunnel to count obtain the number of connections for
259 * @return number of connections available for the tunnel
262 GCT_count_any_connections (const struct CadetTunnel *t);
266 * Iterator over connections.
269 * @param ct one of the connections
272 (*GCT_ConnectionIterator) (void *cls,
273 struct CadetTConnection *ct);
277 * Iterate over all connections of a tunnel.
279 * @param t Tunnel whose connections to iterate.
280 * @param iter Iterator.
281 * @param iter_cls Closure for @c iter.
284 GCT_iterate_connections (struct CadetTunnel *t,
285 GCT_ConnectionIterator iter,
290 * Iterator over channels.
293 * @param ch one of the channels
296 (*GCT_ChannelIterator) (void *cls,
297 struct CadetChannel *ch);
301 * Iterate over all channels of a tunnel.
303 * @param t Tunnel whose channels to iterate.
304 * @param iter Iterator.
305 * @param iter_cls Closure for @c iter.
308 GCT_iterate_channels (struct CadetTunnel *t,
309 GCT_ChannelIterator iter,
314 * Get the encryption state of a tunnel.
318 * @return Tunnel's encryption state.
320 enum CadetTunnelEState
321 GCT_get_estate (struct CadetTunnel *t);
327 * @param ct connection/tunnel combo that received encrypted message
328 * @param msg the key exchange message
331 GCT_handle_kx (struct CadetTConnection *ct,
332 const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg);
336 * Handle KX_AUTH message.
338 * @param ct connection/tunnel combo that received encrypted message
339 * @param msg the key exchange message
342 GCT_handle_kx_auth (struct CadetTConnection *ct,
344 GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg);
348 * Handle encrypted message.
350 * @param ct connection/tunnel combo that received encrypted message
351 * @param msg the encrypted message to decrypt
354 GCT_handle_encrypted (struct CadetTConnection *ct,
355 const struct GNUNET_CADET_TunnelEncryptedMessage *msg);
359 * Log all possible info about the tunnel state.
361 * @param t Tunnel to debug.
362 * @param level Debug level to use.
365 GCT_debug (const struct CadetTunnel *t,
366 enum GNUNET_ErrorType level);