aboutsummaryrefslogtreecommitdiff
path: root/src/service/cadet/gnunet-service-cadet_tunnels.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/service/cadet/gnunet-service-cadet_tunnels.h')
-rw-r--r--src/service/cadet/gnunet-service-cadet_tunnels.h391
1 files changed, 391 insertions, 0 deletions
diff --git a/src/service/cadet/gnunet-service-cadet_tunnels.h b/src/service/cadet/gnunet-service-cadet_tunnels.h
new file mode 100644
index 000000000..e893955a0
--- /dev/null
+++ b/src/service/cadet/gnunet-service-cadet_tunnels.h
@@ -0,0 +1,391 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2001-2017 GNUnet e.V.
4
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.
9
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.
14
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/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file cadet/gnunet-service-cadet_tunnels.h
23 * @brief Information we track per tunnel.
24 * @author Bartlomiej Polot
25 * @author Christian Grothoff
26 */
27#ifndef GNUNET_SERVICE_CADET_TUNNELS_H
28#define GNUNET_SERVICE_CADET_TUNNELS_H
29
30#include "gnunet-service-cadet.h"
31#include "cadet_protocol.h"
32
33
34/**
35 * How many connections would we like to have per tunnel?
36 */
37#define DESIRED_CONNECTIONS_PER_TUNNEL 3
38
39
40/**
41 * All the encryption states a tunnel can be in.
42 */
43enum CadetTunnelEState
44{
45 /**
46 * Uninitialized status, we need to send KX. We will stay
47 * in this state until the first connection is up.
48 */
49 CADET_TUNNEL_KEY_UNINITIALIZED,
50
51 /**
52 * KX message sent, waiting for other peer's KX_AUTH.
53 */
54 CADET_TUNNEL_KEY_AX_SENT,
55
56 /**
57 * KX message received, trying to send back KX_AUTH.
58 */
59 CADET_TUNNEL_KEY_AX_RECV,
60
61 /**
62 * KX message sent and received, trying to send back KX_AUTH.
63 */
64 CADET_TUNNEL_KEY_AX_SENT_AND_RECV,
65
66 /**
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
69 * the other peer.
70 *
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!
74 */
75 CADET_TUNNEL_KEY_AX_AUTH_SENT,
76
77 /**
78 * Handshake completed: session key available.
79 */
80 CADET_TUNNEL_KEY_OK
81};
82
83/**
84 * Am I Alice or Betty (some call her Bob), or talking to myself?
85 *
86 * @param other the other peer
87 * @return #GNUNET_YES for Alice, #GNUNET_NO for Betty, #GNUNET_SYSERR if talking to myself
88 */
89int
90GCT_alice_or_betty (const struct GNUNET_PeerIdentity *other);
91
92/**
93 * Get the static string for the peer this tunnel is directed.
94 *
95 * @param t Tunnel.
96 *
97 * @return Static string the destination peer's ID.
98 */
99const char *
100GCT_2s (const struct CadetTunnel *t);
101
102
103/**
104 * Create a tunnel to @a destination. Must only be called
105 * from within #GCP_get_tunnel().
106 *
107 * @param destination where to create the tunnel to
108 * @return new tunnel to @a destination
109 */
110struct CadetTunnel *
111GCT_create_tunnel (struct CadetPeer *destination);
112
113
114/**
115 * Destroys the tunnel @a t now, without delay. Used during shutdown.
116 *
117 * @param t tunnel to destroy
118 */
119void
120GCT_destroy_tunnel_now (struct CadetTunnel *t);
121
122
123/**
124 * Add a @a connection to the @a tunnel.
125 *
126 * @param t a tunnel
127 * @param cid connection identifier 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)
131 */
132int
133GCT_add_inbound_connection (struct CadetTunnel *t,
134 const struct
135 GNUNET_CADET_ConnectionTunnelIdentifier *cid,
136 struct CadetPeerPath *path);
137
138
139/**
140 * We lost a connection, remove it from our list and clean up
141 * the connection object itself.
142 *
143 * @param ct binding of connection to tunnel of the connection that was lost.
144 */
145void
146GCT_connection_lost (struct CadetTConnection *ct);
147
148
149/**
150 * Return the peer to which this tunnel goes.
151 *
152 * @param t a tunnel
153 * @return the destination of the tunnel
154 */
155struct CadetPeer *
156GCT_get_destination (struct CadetTunnel *t);
157
158
159/**
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.
162 *
163 * @param t our tunnel
164 * @param p a path to our destination
165 * @param off offset of the destination on path @a path
166 */
167void
168GCT_consider_path (struct CadetTunnel *t,
169 struct CadetPeerPath *p,
170 unsigned int off);
171
172
173/**
174 * Add a channel to a tunnel.
175 *
176 * @param t Tunnel.
177 * @param ch Channel
178 * @return unique number identifying @a ch within @a t
179 */
180struct GNUNET_CADET_ChannelTunnelNumber
181GCT_add_channel (struct CadetTunnel *t,
182 struct CadetChannel *ch);
183
184
185/**
186 * Remove a channel from a tunnel.
187 *
188 * @param t Tunnel.
189 * @param ch Channel
190 * @param ctn unique number identifying @a ch within @a t
191 */
192void
193GCT_remove_channel (struct CadetTunnel *t,
194 struct CadetChannel *ch,
195 struct GNUNET_CADET_ChannelTunnelNumber ctn);
196
197
198/**
199 * Send a DESTROY message via the tunnel.
200 *
201 * @param t the tunnel to transmit over
202 * @param ctn ID of the channel to destroy
203 */
204void
205GCT_send_channel_destroy (struct CadetTunnel *t,
206 struct GNUNET_CADET_ChannelTunnelNumber ctn);
207
208
209/**
210 * Function called when a transmission requested using #GCT_send is done.
211 *
212 * @param cls closure
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)
216 */
217typedef void
218(*GCT_SendContinuation)(void *cls,
219 const struct
220 GNUNET_CADET_ConnectionTunnelIdentifier *cid);
221
222
223/**
224 * Sends an already built message on a tunnel, encrypting it and
225 * choosing the best connection if not provided.
226 *
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.
232 */
233struct CadetTunnelQueueEntry *
234GCT_send (struct CadetTunnel *t,
235 const struct GNUNET_MessageHeader *message,
236 GCT_SendContinuation cont,
237 void *cont_cls,
238 struct GNUNET_CADET_ChannelTunnelNumber *ctn);
239
240
241/**
242 * Cancel a previously sent message while it's in the queue.
243 *
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!
247 *
248 * @param q Handle to the queue entry to cancel.
249 */
250void
251GCT_send_cancel (struct CadetTunnelQueueEntry *q);
252
253
254/**
255 * Returns the number of channels using a tunnel.
256 *
257 * @param t Tunnel in question.
258 * @return Number of channels using the tunnel.
259 */
260unsigned int
261GCT_count_channels (struct CadetTunnel *t);
262
263
264/**
265 * Counts the number of connections created for a tunnel,
266 * including busy connections.
267 *
268 * @param t Tunnel to be counted.
269 * @return Number of connections created for the tunnel.
270 */
271unsigned int
272GCT_count_any_connections (const struct CadetTunnel *t);
273
274
275/**
276 * Iterator over connections.
277 *
278 * @param cls closure
279 * @param ct one of the connections
280 */
281typedef void
282(*GCT_ConnectionIterator) (void *cls,
283 struct CadetTConnection *ct);
284
285
286/**
287 * Iterate over all connections of a tunnel.
288 *
289 * @param t Tunnel whose connections to iterate.
290 * @param iter Iterator.
291 * @param iter_cls Closure for @c iter.
292 */
293void
294GCT_iterate_connections (struct CadetTunnel *t,
295 GCT_ConnectionIterator iter,
296 void *iter_cls);
297
298
299/**
300 * Iterator over channels.
301 *
302 * @param cls closure
303 * @param ch one of the channels
304 */
305typedef void
306(*GCT_ChannelIterator) (void *cls,
307 struct CadetChannel *ch);
308
309
310/**
311 * Iterate over all channels of a tunnel.
312 *
313 * @param t Tunnel whose channels to iterate.
314 * @param iter Iterator.
315 * @param iter_cls Closure for @c iter.
316 */
317void
318GCT_iterate_channels (struct CadetTunnel *t,
319 GCT_ChannelIterator iter,
320 void *iter_cls);
321
322
323/**
324 * Get the encryption state of a tunnel.
325 *
326 * @param t Tunnel.
327 *
328 * @return Tunnel's encryption state.
329 */
330enum CadetTunnelEState
331GCT_get_estate (struct CadetTunnel *t);
332
333/**
334 * Change the tunnel encryption state.
335 * If the encryption state changes to OK, stop the rekey task.
336 *
337 * @param t Tunnel whose encryption state to change, or NULL.
338 * @param state New encryption state.
339 */
340void
341GCT_change_estate (struct CadetTunnel *t,
342 enum CadetTunnelEState state);
343
344/**
345 * Handle KX message that lacks authentication (and which will thus
346 * only be considered authenticated after we respond with our own
347 * KX_AUTH and finally successfully decrypt the payload).
348 *
349 * @param ct connection/tunnel combo that received encrypted message
350 * @param msg the key exchange message
351 */
352void
353GCT_handle_kx (struct CadetTConnection *ct,
354 const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg);
355
356
357/**
358 * Handle KX_AUTH message.
359 *
360 * @param ct connection/tunnel combo that received encrypted message
361 * @param msg the key exchange message
362 */
363void
364GCT_handle_kx_auth (struct CadetTConnection *ct,
365 const struct
366 GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg);
367
368
369/**
370 * Handle encrypted message.
371 *
372 * @param ct connection/tunnel combo that received encrypted message
373 * @param msg the encrypted message to decrypt
374 */
375void
376GCT_handle_encrypted (struct CadetTConnection *ct,
377 const struct GNUNET_CADET_TunnelEncryptedMessage *msg);
378
379
380/**
381 * Log all possible info about the tunnel state.
382 *
383 * @param t Tunnel to debug.
384 * @param level Debug level to use.
385 */
386void
387GCT_debug (const struct CadetTunnel *t,
388 enum GNUNET_ErrorType level);
389
390
391#endif