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
7 it under the terms of the GNU General Public License as published
8 by the Free Software Foundation; either version 3, or (at your
9 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 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNUnet; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
23 * @file cadet/gnunet-service-cadet-new_tunnels.h
24 * @brief Information we track per tunnel.
25 * @author Bartlomiej Polot
26 * @author Christian Grothoff
28 #ifndef GNUNET_SERVICE_CADET_TUNNELS_H
29 #define GNUNET_SERVICE_CADET_TUNNELS_H
31 #include "gnunet-service-cadet-new.h"
32 #include "cadet_protocol.h"
36 * How many connections would we like to have per tunnel?
38 #define DESIRED_CONNECTIONS_PER_TUNNEL 3
42 * All the connectivity states a tunnel can be in.
44 enum CadetTunnelCState
47 * Uninitialized status, should never appear in operation.
52 * No path to the peer known yet.
54 CADET_TUNNEL_SEARCHING,
57 * Request sent, not yet answered.
62 * Peer connected and ready to accept data.
67 * Tunnel being shut down, don't try to keep it alive.
75 * All the encryption states a tunnel can be in.
77 enum CadetTunnelEState
80 * Uninitialized status, should never appear in operation.
82 CADET_TUNNEL_KEY_UNINITIALIZED,
85 * Ephemeral key sent, waiting for peer's key.
87 CADET_TUNNEL_KEY_SENT,
90 * In OTR: New ephemeral key and ping sent, waiting for pong.
92 * This means that we DO have the peer's ephemeral key, otherwise the
93 * state would be KEY_SENT. We DO NOT have a valid session key (either no
94 * previous key or previous key expired).
97 * In Axolotl: Key sent and received but no deciphered traffic yet.
99 * This means that we can send traffic (otherwise we would never complete
100 * the handshake), but we don't have complete confirmation. Since the first
101 * traffic MUST be a complete channel creation 3-way handshake, no payload
102 * will be sent before confirmation.
104 CADET_TUNNEL_KEY_PING,
107 * Handshake completed: session key available.
112 * New ephemeral key and ping sent, waiting for pong. Unlike KEY_PING,
113 * we still have a valid session key and therefore we *can* still send
114 * traffic on the tunnel.
116 CADET_TUNNEL_KEY_REKEY
121 * Get the static string for the peer this tunnel is directed.
125 * @return Static string the destination peer's ID.
128 GCT_2s (const struct CadetTunnel *t);
132 * Create a tunnel to @a destionation. Must only be called
133 * from within #GCP_get_tunnel().
135 * @param destination where to create the tunnel to
136 * @return new tunnel to @a destination
139 GCT_create_tunnel (struct CadetPeer *destination);
143 * Add a @a connection to the @a tunnel.
146 * @param cid connection identifer to use for the connection
147 * @param path path to use for the connection
150 GCT_add_inbound_connection (struct CadetTunnel *t,
151 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
152 struct CadetPeerPath *path);
156 * Return the peer to which this tunnel goes.
159 * @return the destination of the tunnel
162 GCT_get_destination (struct CadetTunnel *t);
166 * Consider using the path @a p for the tunnel @a t.
167 * The tunnel destination is at offset @a off in path @a p.
169 * @param cls our tunnel
170 * @param path a path to our destination
171 * @param off offset of the destination on path @a path
174 GCT_consider_path (struct CadetTunnel *t,
175 struct CadetPeerPath *p,
180 * Add a channel to a tunnel.
184 * @return unique number identifying @a ch within @a t
186 struct GNUNET_CADET_ChannelTunnelNumber
187 GCT_add_channel (struct CadetTunnel *t,
188 struct CadetChannel *ch);
192 * Remove a channel from a tunnel.
196 * @param gid unique number identifying @a ch within @a t
199 GCT_remove_channel (struct CadetTunnel *t,
200 struct CadetChannel *ch,
201 struct GNUNET_CADET_ChannelTunnelNumber gid);
205 * Send a DESTROY message via the tunnel.
207 * @param t the tunnel to transmit over
208 * @param chid ID of the channel to destroy
211 GCT_send_channel_destroy (struct CadetTunnel *t,
212 struct GNUNET_CADET_ChannelTunnelNumber chid);
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. NULL if @c cont is NULL.
225 struct CadetTunnelQueueEntry *
226 GCT_send (struct CadetTunnel *t,
227 const struct GNUNET_MessageHeader *message,
228 GNUNET_SCHEDULER_TaskCallback 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 (struct CadetTunnel *t);
266 * Iterator over connections.
269 * @param c one of the connections
272 (*GCT_ConnectionIterator) (void *cls,
273 struct CadetConnection *c);
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 connectivity state of a tunnel.
318 * @return Tunnel's connectivity state.
320 enum CadetTunnelCState
321 GCT_get_cstate (struct CadetTunnel *t);
325 * Get the encryption state of a tunnel.
329 * @return Tunnel's encryption state.
331 enum CadetTunnelEState
332 GCT_get_estate (struct CadetTunnel *t);
338 * @param ct connection/tunnel combo that received encrypted message
339 * @param msg the key exchange message
342 GCT_handle_kx (struct CadetTConnection *ct,
343 const struct GNUNET_CADET_TunnelKeyExchangeMessage *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);