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.h
22 * @brief Information we track per peer.
23 * @author Bartlomiej Polot
24 * @author Christian Grothoff
26 #ifndef GNUNET_SERVICE_CADET_H
27 #define GNUNET_SERVICE_CADET_H
29 #include "gnunet_util_lib.h"
30 #include "cadet_protocol.h"
33 * A client to the CADET service. Each client gets a unique handle.
38 * A peer in the GNUnet network. Each peer we care about must have one globally
39 * unique such handle within this process.
44 * Tunnel from us to another peer. There can only be at most one
50 * Entry in the message queue of a `struct CadetTunnel`.
52 struct CadetTunnelQueueEntry;
55 * A path of peer in the GNUnet network. There must only be at most
56 * once such path. Paths may share disjoint prefixes, but must all
57 * end at a unique suffix. Paths must also not be proper subsets of
58 * other existing paths.
63 * Entry in a peer path.
65 struct CadetPeerPathEntry
68 * DLL of paths where the same @e peer is at the same offset.
70 struct CadetPeerPathEntry *next;
73 * DLL of paths where the same @e peer is at the same offset.
75 struct CadetPeerPathEntry *prev;
78 * The peer at this offset of the path.
80 struct CadetPeer *peer;
83 * Path this entry belongs to.
85 struct CadetPeerPath *path;
88 * Connection using this path, or NULL for none.
90 struct CadetConnection *cc;
93 * Path's historic score up to this point. Basically, how often did
94 * we succeed or fail to use the path up to this entry in a
95 * connection. Positive values indicate good experiences, negative
96 * values bad experiences. Code updating the score must guard
104 * Entry in list of connections used by tunnel, with metadata.
106 struct CadetTConnection
111 struct CadetTConnection *next;
116 struct CadetTConnection *prev;
121 struct CadetConnection *cc;
124 * Tunnel this connection belongs to.
126 struct CadetTunnel *t;
129 * Creation time, to keep oldest connection alive.
131 struct GNUNET_TIME_Absolute created;
134 * Connection throughput, to keep fastest connection alive.
139 * Is the connection currently ready for transmission?
146 * Port opened by a client.
152 * Client that opened the port.
154 struct CadetClient *c;
159 struct GNUNET_HashCode port;
162 * Port hashed with our PID (matches incoming OPEN messages).
164 struct GNUNET_HashCode h_port;
170 * Active path through the network (used by a tunnel). There may
171 * be at most one connection per path.
173 struct CadetConnection;
176 * Description of a segment of a `struct CadetConnection` at the
177 * intermediate peers. Routes are basically entries in a peer's
178 * routing table for forwarding traffic. At both endpoints, the
179 * routes are terminated by a `struct CadetConnection`, which knows
180 * the complete `struct CadetPath` that is formed by the individual
186 * Logical end-to-end conenction between clients. There can be
187 * any number of channels between clients.
192 * Handle to our configuration.
194 extern const struct GNUNET_CONFIGURATION_Handle *cfg;
197 * Handle to the statistics service.
199 extern struct GNUNET_STATISTICS_Handle *stats;
202 * Handle to communicate with ATS.
204 extern struct GNUNET_ATS_ConnectivityHandle *ats_ch;
209 extern struct GNUNET_PeerIdentity my_full_id;
214 extern struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key;
217 * All ports clients of this peer have opened. Maps from
218 * a hashed port to a `struct OpenPort`.
220 extern struct GNUNET_CONTAINER_MultiHashMap *open_ports;
223 * Map from `struct GNUNET_CADET_ConnectionTunnelIdentifier`
224 * hash codes to `struct CadetConnection` objects.
226 extern struct GNUNET_CONTAINER_MultiShortmap *connections;
229 * Map from ports to channels where the ports were closed at the
230 * time we got the inbound connection.
231 * Indexed by h_port, contains `struct CadetChannel`.
233 extern struct GNUNET_CONTAINER_MultiHashMap *loose_channels;
236 * Map from PIDs to `struct CadetPeer` entries.
238 extern struct GNUNET_CONTAINER_MultiPeerMap *peers;
241 * How many messages are needed to trigger an AXOLOTL ratchet advance.
243 extern unsigned long long ratchet_messages;
246 * How long until we trigger a ratched advance due to time.
248 extern struct GNUNET_TIME_Relative ratchet_time;
251 * How frequently do we send KEEPALIVE messages on idle connections?
253 extern struct GNUNET_TIME_Relative keepalive_period;
256 * Signal that shutdown is happening: prevent recovery measures.
258 extern int shutting_down;
261 * Set to non-zero values to create random drops to test retransmissions.
263 extern unsigned long long drop_percent;
267 * Send a message to a client.
269 * @param c client to get the message
270 * @param env envelope with the message
273 GSC_send_to_client (struct CadetClient *c,
274 struct GNUNET_MQ_Envelope *env);
278 * A channel was destroyed by the other peer. Tell our client.
280 * @param c client that lost a channel
281 * @param ccn channel identification number for the client
282 * @param ch the channel object
285 GSC_handle_remote_channel_destroy (struct CadetClient *c,
286 struct GNUNET_CADET_ClientChannelNumber ccn,
287 struct CadetChannel *ch);
290 * A client that created a loose channel that was not bound to a port
291 * disconnected, drop it from the #loose_channels list.
293 * @param h_port the hashed port the channel was trying to bind to
294 * @param ch the channel that was lost
297 GSC_drop_loose_channel (const struct GNUNET_HashCode *h_port,
298 struct CadetChannel *ch);
302 * Bind incoming channel to this client, and notify client
303 * about incoming connection.
305 * @param c client to bind to
306 * @param ch channel to be bound
307 * @param dest peer that establishes the connection
308 * @param port port number
309 * @param options options
310 * @return local channel number assigned to the new client
312 struct GNUNET_CADET_ClientChannelNumber
313 GSC_bind (struct CadetClient *c,
314 struct CadetChannel *ch,
315 struct CadetPeer *dest,
316 const struct GNUNET_HashCode *port,
321 * Return identifier for a client as a string.
323 * @param c client to identify
324 * @return string for debugging
327 GSC_2s (struct CadetClient *c);