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.
18 * @file cadet/gnunet-service-cadet.h
19 * @brief Information we track per peer.
20 * @author Bartlomiej Polot
21 * @author Christian Grothoff
23 #ifndef GNUNET_SERVICE_CADET_H
24 #define GNUNET_SERVICE_CADET_H
26 #include "gnunet_util_lib.h"
27 #include "cadet_protocol.h"
30 * A client to the CADET service. Each client gets a unique handle.
35 * A peer in the GNUnet network. Each peer we care about must have one globally
36 * unique such handle within this process.
41 * Tunnel from us to another peer. There can only be at most one
47 * Entry in the message queue of a `struct CadetTunnel`.
49 struct CadetTunnelQueueEntry;
52 * A path of peer in the GNUnet network. There must only be at most
53 * once such path. Paths may share disjoint prefixes, but must all
54 * end at a unique suffix. Paths must also not be proper subsets of
55 * other existing paths.
60 * Entry in a peer path.
62 struct CadetPeerPathEntry
65 * DLL of paths where the same @e peer is at the same offset.
67 struct CadetPeerPathEntry *next;
70 * DLL of paths where the same @e peer is at the same offset.
72 struct CadetPeerPathEntry *prev;
75 * The peer at this offset of the path.
77 struct CadetPeer *peer;
80 * Path this entry belongs to.
82 struct CadetPeerPath *path;
85 * Connection using this path, or NULL for none.
87 struct CadetConnection *cc;
90 * Path's historic score up to this point. Basically, how often did
91 * we succeed or fail to use the path up to this entry in a
92 * connection. Positive values indicate good experiences, negative
93 * values bad experiences. Code updating the score must guard
101 * Entry in list of connections used by tunnel, with metadata.
103 struct CadetTConnection
108 struct CadetTConnection *next;
113 struct CadetTConnection *prev;
118 struct CadetConnection *cc;
121 * Tunnel this connection belongs to.
123 struct CadetTunnel *t;
126 * Creation time, to keep oldest connection alive.
128 struct GNUNET_TIME_Absolute created;
131 * Connection throughput, to keep fastest connection alive.
136 * Is the connection currently ready for transmission?
143 * Port opened by a client.
149 * Client that opened the port.
151 struct CadetClient *c;
156 struct GNUNET_HashCode port;
159 * Port hashed with our PID (matches incoming OPEN messages).
161 struct GNUNET_HashCode h_port;
167 * Active path through the network (used by a tunnel). There may
168 * be at most one connection per path.
170 struct CadetConnection;
173 * Description of a segment of a `struct CadetConnection` at the
174 * intermediate peers. Routes are basically entries in a peer's
175 * routing table for forwarding traffic. At both endpoints, the
176 * routes are terminated by a `struct CadetConnection`, which knows
177 * the complete `struct CadetPath` that is formed by the individual
183 * Logical end-to-end conenction between clients. There can be
184 * any number of channels between clients.
189 * Handle to our configuration.
191 extern const struct GNUNET_CONFIGURATION_Handle *cfg;
194 * Handle to the statistics service.
196 extern struct GNUNET_STATISTICS_Handle *stats;
199 * Handle to communicate with ATS.
201 extern struct GNUNET_ATS_ConnectivityHandle *ats_ch;
206 extern struct GNUNET_PeerIdentity my_full_id;
211 extern struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key;
214 * All ports clients of this peer have opened. Maps from
215 * a hashed port to a `struct OpenPort`.
217 extern struct GNUNET_CONTAINER_MultiHashMap *open_ports;
220 * Map from `struct GNUNET_CADET_ConnectionTunnelIdentifier`
221 * hash codes to `struct CadetConnection` objects.
223 extern struct GNUNET_CONTAINER_MultiShortmap *connections;
226 * Map from ports to channels where the ports were closed at the
227 * time we got the inbound connection.
228 * Indexed by h_port, contains `struct CadetChannel`.
230 extern struct GNUNET_CONTAINER_MultiHashMap *loose_channels;
233 * Map from PIDs to `struct CadetPeer` entries.
235 extern struct GNUNET_CONTAINER_MultiPeerMap *peers;
238 * How many messages are needed to trigger an AXOLOTL ratchet advance.
240 extern unsigned long long ratchet_messages;
243 * How long until we trigger a ratched advance due to time.
245 extern struct GNUNET_TIME_Relative ratchet_time;
248 * How frequently do we send KEEPALIVE messages on idle connections?
250 extern struct GNUNET_TIME_Relative keepalive_period;
253 * Signal that shutdown is happening: prevent recovery measures.
255 extern int shutting_down;
258 * Set to non-zero values to create random drops to test retransmissions.
260 extern unsigned long long drop_percent;
264 * Send a message to a client.
266 * @param c client to get the message
267 * @param env envelope with the message
270 GSC_send_to_client (struct CadetClient *c,
271 struct GNUNET_MQ_Envelope *env);
275 * A channel was destroyed by the other peer. Tell our client.
277 * @param c client that lost a channel
278 * @param ccn channel identification number for the client
279 * @param ch the channel object
282 GSC_handle_remote_channel_destroy (struct CadetClient *c,
283 struct GNUNET_CADET_ClientChannelNumber ccn,
284 struct CadetChannel *ch);
287 * A client that created a loose channel that was not bound to a port
288 * disconnected, drop it from the #loose_channels list.
290 * @param h_port the hashed port the channel was trying to bind to
291 * @param ch the channel that was lost
294 GSC_drop_loose_channel (const struct GNUNET_HashCode *h_port,
295 struct CadetChannel *ch);
299 * Bind incoming channel to this client, and notify client
300 * about incoming connection.
302 * @param c client to bind to
303 * @param ch channel to be bound
304 * @param dest peer that establishes the connection
305 * @param port port number
306 * @param options options
307 * @return local channel number assigned to the new client
309 struct GNUNET_CADET_ClientChannelNumber
310 GSC_bind (struct CadetClient *c,
311 struct CadetChannel *ch,
312 struct CadetPeer *dest,
313 const struct GNUNET_HashCode *port,
318 * Return identifier for a client as a string.
320 * @param c client to identify
321 * @return string for debugging
324 GSC_2s (struct CadetClient *c);