3 This file is part of GNUnet.
4 Copyright (C) 2001-2017 GNUnet e.V.
6 GNUnet is free software: you can redistribute it and/or modify it
7 under the terms of the GNU Affero General Public License as published
8 by the Free Software Foundation, either version 3 of the License,
9 or (at your option) any later version.
11 GNUnet is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Affero General Public License for more details.
16 You should have received a copy of the GNU Affero General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * @file cadet/gnunet-service-cadet_tunnels.h
22 * @brief Information we track per tunnel.
23 * @author Bartlomiej Polot
24 * @author Christian Grothoff
26 #ifndef GNUNET_SERVICE_CADET_TUNNELS_H
27 #define GNUNET_SERVICE_CADET_TUNNELS_H
29 #include "gnunet-service-cadet.h"
30 #include "cadet_protocol.h"
34 * How many connections would we like to have per tunnel?
36 #define DESIRED_CONNECTIONS_PER_TUNNEL 3
40 * All the encryption states a tunnel can be in.
42 enum CadetTunnelEState
45 * Uninitialized status, we need to send KX. We will stay
46 * in this state until the first connection is up.
48 CADET_TUNNEL_KEY_UNINITIALIZED,
51 * KX message sent, waiting for other peer's KX_AUTH.
53 CADET_TUNNEL_KEY_AX_SENT,
56 * KX message received, trying to send back KX_AUTH.
58 CADET_TUNNEL_KEY_AX_RECV,
61 * KX message sent and received, trying to send back KX_AUTH.
63 CADET_TUNNEL_KEY_AX_SENT_AND_RECV,
66 * KX received and we sent KX_AUTH back, but we got no traffic yet,
67 * so we're waiting for either KX_AUTH or ENCRYPED traffic from
70 * We will not yet send traffic, as this might have been a replay.
71 * The other (initiating) peer should send a CHANNEL_OPEN next
72 * anyway, and then we are in business!
74 CADET_TUNNEL_KEY_AX_AUTH_SENT,
77 * 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 options options for the connection
121 * @param path path to use for the connection
122 * @return #GNUNET_OK on success,
123 * #GNUNET_SYSERR on failure (duplicate connection)
126 GCT_add_inbound_connection (struct CadetTunnel *t,
127 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
128 enum GNUNET_CADET_ChannelOption options,
129 struct CadetPeerPath *path);
133 * We lost a connection, remove it from our list and clean up
134 * the connection object itself.
136 * @param ct binding of connection to tunnel of the connection that was lost.
139 GCT_connection_lost (struct CadetTConnection *ct);
143 * Return the peer to which this tunnel goes.
146 * @return the destination of the tunnel
149 GCT_get_destination (struct CadetTunnel *t);
153 * Consider using the path @a p for the tunnel @a t.
154 * The tunnel destination is at offset @a off in path @a p.
156 * @param cls our tunnel
157 * @param path a path to our destination
158 * @param off offset of the destination on path @a path
161 GCT_consider_path (struct CadetTunnel *t,
162 struct CadetPeerPath *p,
167 * Add a channel to a tunnel.
171 * @return unique number identifying @a ch within @a t
173 struct GNUNET_CADET_ChannelTunnelNumber
174 GCT_add_channel (struct CadetTunnel *t,
175 struct CadetChannel *ch);
179 * Remove a channel from a tunnel.
183 * @param ctn unique number identifying @a ch within @a t
186 GCT_remove_channel (struct CadetTunnel *t,
187 struct CadetChannel *ch,
188 struct GNUNET_CADET_ChannelTunnelNumber ctn);
192 * Send a DESTROY message via the tunnel.
194 * @param t the tunnel to transmit over
195 * @param ctn ID of the channel to destroy
198 GCT_send_channel_destroy (struct CadetTunnel *t,
199 struct GNUNET_CADET_ChannelTunnelNumber ctn);
203 * Function called when a transmission requested using #GCT_send is done.
206 * @param ctn identifier of the connection used for transmission, NULL if
207 * the transmission failed (to be used to match ACKs to the
208 * respective connection for connection performance evaluation)
211 (*GCT_SendContinuation)(void *cls,
212 const struct 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,
343 const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg);
347 * Handle encrypted message.
349 * @param ct connection/tunnel combo that received encrypted message
350 * @param msg the encrypted message to decrypt
353 GCT_handle_encrypted (struct CadetTConnection *ct,
354 const struct GNUNET_CADET_TunnelEncryptedMessage *msg);
358 * Log all possible info about the tunnel state.
360 * @param t Tunnel to debug.
361 * @param level Debug level to use.
364 GCT_debug (const struct CadetTunnel *t,
365 enum GNUNET_ErrorType level);