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.
84 * Am I Alice or Betty (some call her Bob), or talking to myself?
86 * @param other the other peer
87 * @return #GNUNET_YES for Alice, #GNUNET_NO for Betty, #GNUNET_SYSERR if talking to myself
90 GCT_alice_or_betty (const struct GNUNET_PeerIdentity *other);
93 * Get the static string for the peer this tunnel is directed.
97 * @return Static string the destination peer's ID.
100 GCT_2s (const struct CadetTunnel *t);
104 * Create a tunnel to @a destionation. Must only be called
105 * from within #GCP_get_tunnel().
107 * @param destination where to create the tunnel to
108 * @return new tunnel to @a destination
111 GCT_create_tunnel (struct CadetPeer *destination);
115 * Destroys the tunnel @a t now, without delay. Used during shutdown.
117 * @param t tunnel to destroy
120 GCT_destroy_tunnel_now (struct CadetTunnel *t);
124 * Add a @a connection to the @a tunnel.
127 * @param cid connection identifer to use for the connection
128 * @param path path to use for the connection
129 * @return #GNUNET_OK on success,
130 * #GNUNET_SYSERR on failure (duplicate connection)
133 GCT_add_inbound_connection (struct CadetTunnel *t,
135 GNUNET_CADET_ConnectionTunnelIdentifier *cid,
136 struct CadetPeerPath *path);
140 * We lost a connection, remove it from our list and clean up
141 * the connection object itself.
143 * @param ct binding of connection to tunnel of the connection that was lost.
146 GCT_connection_lost (struct CadetTConnection *ct);
150 * Return the peer to which this tunnel goes.
153 * @return the destination of the tunnel
156 GCT_get_destination (struct CadetTunnel *t);
160 * Consider using the path @a p for the tunnel @a t.
161 * The tunnel destination is at offset @a off in path @a p.
163 * @param cls our tunnel
164 * @param path a path to our destination
165 * @param off offset of the destination on path @a path
168 GCT_consider_path (struct CadetTunnel *t,
169 struct CadetPeerPath *p,
174 * Add a channel to a tunnel.
178 * @return unique number identifying @a ch within @a t
180 struct GNUNET_CADET_ChannelTunnelNumber
181 GCT_add_channel (struct CadetTunnel *t,
182 struct CadetChannel *ch);
186 * Remove a channel from a tunnel.
190 * @param ctn unique number identifying @a ch within @a t
193 GCT_remove_channel (struct CadetTunnel *t,
194 struct CadetChannel *ch,
195 struct GNUNET_CADET_ChannelTunnelNumber ctn);
199 * Send a DESTROY message via the tunnel.
201 * @param t the tunnel to transmit over
202 * @param ctn ID of the channel to destroy
205 GCT_send_channel_destroy (struct CadetTunnel *t,
206 struct GNUNET_CADET_ChannelTunnelNumber ctn);
210 * Function called when a transmission requested using #GCT_send is done.
213 * @param ctn identifier of the connection used for transmission, NULL if
214 * the transmission failed (to be used to match ACKs to the
215 * respective connection for connection performance evaluation)
218 (*GCT_SendContinuation)(void *cls,
220 GNUNET_CADET_ConnectionTunnelIdentifier *cid);
224 * Sends an already built message on a tunnel, encrypting it and
225 * choosing the best connection if not provided.
227 * @param message Message to send. Function modifies it.
228 * @param t Tunnel on which this message is transmitted.
229 * @param cont Continuation to call once message is really sent.
230 * @param cont_cls Closure for @c cont.
231 * @return Handle to cancel message.
233 struct CadetTunnelQueueEntry *
234 GCT_send (struct CadetTunnel *t,
235 const struct GNUNET_MessageHeader *message,
236 GCT_SendContinuation cont,
238 struct GNUNET_CADET_ChannelTunnelNumber *ctn);
242 * Cancel a previously sent message while it's in the queue.
244 * ONLY can be called before the continuation given to the send
245 * function is called. Once the continuation is called, the message is
246 * no longer in the queue!
248 * @param q Handle to the queue entry to cancel.
251 GCT_send_cancel (struct CadetTunnelQueueEntry *q);
255 * Return the number of channels using a tunnel.
257 * @param t tunnel to count obtain the number of channels for
258 * @return number of channels using the tunnel
261 GCT_count_channels (struct CadetTunnel *t);
265 * Return the number of connections available for a tunnel.
267 * @param t tunnel to count obtain the number of connections for
268 * @return number of connections available for the tunnel
271 GCT_count_any_connections (const struct CadetTunnel *t);
275 * Iterator over connections.
278 * @param ct one of the connections
281 (*GCT_ConnectionIterator) (void *cls,
282 struct CadetTConnection *ct);
286 * Iterate over all connections of a tunnel.
288 * @param t Tunnel whose connections to iterate.
289 * @param iter Iterator.
290 * @param iter_cls Closure for @c iter.
293 GCT_iterate_connections (struct CadetTunnel *t,
294 GCT_ConnectionIterator iter,
299 * Iterator over channels.
302 * @param ch one of the channels
305 (*GCT_ChannelIterator) (void *cls,
306 struct CadetChannel *ch);
310 * Iterate over all channels of a tunnel.
312 * @param t Tunnel whose channels to iterate.
313 * @param iter Iterator.
314 * @param iter_cls Closure for @c iter.
317 GCT_iterate_channels (struct CadetTunnel *t,
318 GCT_ChannelIterator iter,
323 * Get the encryption state of a tunnel.
327 * @return Tunnel's encryption state.
329 enum CadetTunnelEState
330 GCT_get_estate (struct CadetTunnel *t);
333 * Change the tunnel encryption state.
334 * If the encryption state changes to OK, stop the rekey task.
336 * @param t Tunnel whose encryption state to change, or NULL.
337 * @param state New encryption state.
340 GCT_change_estate (struct CadetTunnel *t,
341 enum CadetTunnelEState state);
346 * @param ct connection/tunnel combo that received encrypted message
347 * @param msg the key exchange message
350 GCT_handle_kx (struct CadetTConnection *ct,
351 const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg);
355 * Handle KX_AUTH message.
357 * @param ct connection/tunnel combo that received encrypted message
358 * @param msg the key exchange message
361 GCT_handle_kx_auth (struct CadetTConnection *ct,
363 GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg);
367 * Handle encrypted message.
369 * @param ct connection/tunnel combo that received encrypted message
370 * @param msg the encrypted message to decrypt
373 GCT_handle_encrypted (struct CadetTConnection *ct,
374 const struct GNUNET_CADET_TunnelEncryptedMessage *msg);
378 * Log all possible info about the tunnel state.
380 * @param t Tunnel to debug.
381 * @param level Debug level to use.
384 GCT_debug (const struct CadetTunnel *t,
385 enum GNUNET_ErrorType level);