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 encryption states a tunnel can be in.
44 enum CadetTunnelEState
47 * Uninitialized status, we need to send KX. We will stay
48 * in this state until the first connection is up.
50 CADET_TUNNEL_KEY_UNINITIALIZED,
53 * Ephemeral key sent, waiting for peer's key.
55 CADET_TUNNEL_KEY_SENT,
58 * Key received and we sent ours back, but we got no traffic yet.
59 * We will not yet send traffic, as this might have been a replay.
60 * The other (initiating) peer should send a CHANNEL_OPEN next
63 CADET_TUNNEL_KEY_PING,
66 * Handshake completed: session key available.
71 * New ephemeral key and ping sent, waiting for pong. Unlike KEY_PING,
72 * we still have a valid session key and therefore we *can* still send
73 * traffic on the tunnel.
75 CADET_TUNNEL_KEY_REKEY
80 * Get the static string for the peer this tunnel is directed.
84 * @return Static string the destination peer's ID.
87 GCT_2s (const struct CadetTunnel *t);
91 * Create a tunnel to @a destionation. Must only be called
92 * from within #GCP_get_tunnel().
94 * @param destination where to create the tunnel to
95 * @return new tunnel to @a destination
98 GCT_create_tunnel (struct CadetPeer *destination);
102 * Destroys the tunnel @a t now, without delay. Used during shutdown.
104 * @param t tunnel to destroy
107 GCT_destroy_tunnel_now (struct CadetTunnel *t);
111 * Add a @a connection to the @a tunnel.
114 * @param cid connection identifer to use for the connection
115 * @param path path to use for the connection
118 GCT_add_inbound_connection (struct CadetTunnel *t,
119 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
120 struct CadetPeerPath *path);
124 * Return the peer to which this tunnel goes.
127 * @return the destination of the tunnel
130 GCT_get_destination (struct CadetTunnel *t);
134 * Consider using the path @a p for the tunnel @a t.
135 * The tunnel destination is at offset @a off in path @a p.
137 * @param cls our tunnel
138 * @param path a path to our destination
139 * @param off offset of the destination on path @a path
142 GCT_consider_path (struct CadetTunnel *t,
143 struct CadetPeerPath *p,
148 * Add a channel to a tunnel.
152 * @return unique number identifying @a ch within @a t
154 struct GNUNET_CADET_ChannelTunnelNumber
155 GCT_add_channel (struct CadetTunnel *t,
156 struct CadetChannel *ch);
160 * Remove a channel from a tunnel.
164 * @param ctn unique number identifying @a ch within @a t
167 GCT_remove_channel (struct CadetTunnel *t,
168 struct CadetChannel *ch,
169 struct GNUNET_CADET_ChannelTunnelNumber ctn);
173 * Send a DESTROY message via the tunnel.
175 * @param t the tunnel to transmit over
176 * @param ctn ID of the channel to destroy
179 GCT_send_channel_destroy (struct CadetTunnel *t,
180 struct GNUNET_CADET_ChannelTunnelNumber ctn);
184 * Sends an already built message on a tunnel, encrypting it and
185 * choosing the best connection if not provided.
187 * @param message Message to send. Function modifies it.
188 * @param t Tunnel on which this message is transmitted.
189 * @param cont Continuation to call once message is really sent.
190 * @param cont_cls Closure for @c cont.
191 * @return Handle to cancel message. NULL if @c cont is NULL.
193 struct CadetTunnelQueueEntry *
194 GCT_send (struct CadetTunnel *t,
195 const struct GNUNET_MessageHeader *message,
196 GNUNET_SCHEDULER_TaskCallback cont,
201 * Cancel a previously sent message while it's in the queue.
203 * ONLY can be called before the continuation given to the send
204 * function is called. Once the continuation is called, the message is
205 * no longer in the queue!
207 * @param q Handle to the queue entry to cancel.
210 GCT_send_cancel (struct CadetTunnelQueueEntry *q);
214 * Return the number of channels using a tunnel.
216 * @param t tunnel to count obtain the number of channels for
217 * @return number of channels using the tunnel
220 GCT_count_channels (struct CadetTunnel *t);
224 * Return the number of connections available for a tunnel.
226 * @param t tunnel to count obtain the number of connections for
227 * @return number of connections available for the tunnel
230 GCT_count_any_connections (struct CadetTunnel *t);
234 * Iterator over connections.
237 * @param c one of the connections
240 (*GCT_ConnectionIterator) (void *cls,
241 struct CadetConnection *c);
245 * Iterate over all connections of a tunnel.
247 * @param t Tunnel whose connections to iterate.
248 * @param iter Iterator.
249 * @param iter_cls Closure for @c iter.
252 GCT_iterate_connections (struct CadetTunnel *t,
253 GCT_ConnectionIterator iter,
258 * Iterator over channels.
261 * @param ch one of the channels
264 (*GCT_ChannelIterator) (void *cls,
265 struct CadetChannel *ch);
269 * Iterate over all channels of a tunnel.
271 * @param t Tunnel whose channels to iterate.
272 * @param iter Iterator.
273 * @param iter_cls Closure for @c iter.
276 GCT_iterate_channels (struct CadetTunnel *t,
277 GCT_ChannelIterator iter,
282 * Get the encryption state of a tunnel.
286 * @return Tunnel's encryption state.
288 enum CadetTunnelEState
289 GCT_get_estate (struct CadetTunnel *t);
295 * @param ct connection/tunnel combo that received encrypted message
296 * @param msg the key exchange message
299 GCT_handle_kx (struct CadetTConnection *ct,
300 const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg);
304 * Handle encrypted message.
306 * @param ct connection/tunnel combo that received encrypted message
307 * @param msg the encrypted message to decrypt
310 GCT_handle_encrypted (struct CadetTConnection *ct,
311 const struct GNUNET_CADET_TunnelEncryptedMessage *msg);
315 * Log all possible info about the tunnel state.
317 * @param t Tunnel to debug.
318 * @param level Debug level to use.
321 GCT_debug (const struct CadetTunnel *t,
322 enum GNUNET_ErrorType level);