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.h
24 * @brief Information we track per peer.
25 * @author Bartlomiej Polot
26 * @author Christian Grothoff
28 #ifndef GNUNET_SERVICE_CADET_H
29 #define GNUNET_SERVICE_CADET_H
31 #include "gnunet_util_lib.h"
32 #include "cadet_protocol.h"
35 * A client to the CADET service. Each client gets a unique handle.
40 * A peer in the GNUnet network. Each peer we care about must have one globally
41 * unique such handle within this process.
46 * Tunnel from us to another peer. There can only be at most one
52 * Entry in the message queue of a `struct CadetTunnel`.
54 struct CadetTunnelQueueEntry;
57 * A path of peer in the GNUnet network. There must only be at most
58 * once such path. Paths may share disjoint prefixes, but must all
59 * end at a unique suffix. Paths must also not be proper subsets of
60 * other existing paths.
65 * Entry in a peer path.
67 struct CadetPeerPathEntry
70 * DLL of paths where the same @e peer is at the same offset.
72 struct CadetPeerPathEntry *next;
75 * DLL of paths where the same @e peer is at the same offset.
77 struct CadetPeerPathEntry *prev;
80 * The peer at this offset of the path.
82 struct CadetPeer *peer;
85 * Path this entry belongs to.
87 struct CadetPeerPath *path;
90 * Connection using this path, or NULL for none.
92 struct CadetConnection *cc;
95 * Path's historic score up to this point. Basically, how often did
96 * we succeed or fail to use the path up to this entry in a
97 * connection. Positive values indicate good experiences, negative
98 * values bad experiences. Code updating the score must guard
106 * Entry in list of connections used by tunnel, with metadata.
108 struct CadetTConnection
113 struct CadetTConnection *next;
118 struct CadetTConnection *prev;
123 struct CadetConnection *cc;
126 * Tunnel this connection belongs to.
128 struct CadetTunnel *t;
131 * Creation time, to keep oldest connection alive.
133 struct GNUNET_TIME_Absolute created;
136 * Connection throughput, to keep fastest connection alive.
141 * Is the connection currently ready for transmission?
148 * Port opened by a client.
154 * Client that opened the port.
156 struct CadetClient *c;
161 struct GNUNET_HashCode port;
164 * Port hashed with our PID (matches incoming OPEN messages).
166 struct GNUNET_HashCode h_port;
172 * Active path through the network (used by a tunnel). There may
173 * be at most one connection per path.
175 struct CadetConnection;
178 * Description of a segment of a `struct CadetConnection` at the
179 * intermediate peers. Routes are basically entries in a peer's
180 * routing table for forwarding traffic. At both endpoints, the
181 * routes are terminated by a `struct CadetConnection`, which knows
182 * the complete `struct CadetPath` that is formed by the individual
188 * Logical end-to-end conenction between clients. There can be
189 * any number of channels between clients.
194 * Handle to our configuration.
196 extern const struct GNUNET_CONFIGURATION_Handle *cfg;
199 * Handle to the statistics service.
201 extern struct GNUNET_STATISTICS_Handle *stats;
204 * Handle to communicate with ATS.
206 extern struct GNUNET_ATS_ConnectivityHandle *ats_ch;
211 extern struct GNUNET_PeerIdentity my_full_id;
216 extern struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key;
219 * All ports clients of this peer have opened. Maps from
220 * a hashed port to a `struct OpenPort`.
222 extern struct GNUNET_CONTAINER_MultiHashMap *open_ports;
225 * Map from `struct GNUNET_CADET_ConnectionTunnelIdentifier`
226 * hash codes to `struct CadetConnection` objects.
228 extern struct GNUNET_CONTAINER_MultiShortmap *connections;
231 * Map from ports to channels where the ports were closed at the
232 * time we got the inbound connection.
233 * Indexed by h_port, contains `struct CadetChannel`.
235 extern struct GNUNET_CONTAINER_MultiHashMap *loose_channels;
238 * Map from PIDs to `struct CadetPeer` entries.
240 extern struct GNUNET_CONTAINER_MultiPeerMap *peers;
243 * How many messages are needed to trigger an AXOLOTL ratchet advance.
245 extern unsigned long long ratchet_messages;
248 * How long until we trigger a ratched advance due to time.
250 extern struct GNUNET_TIME_Relative ratchet_time;
253 * How frequently do we send KEEPALIVE messages on idle connections?
255 extern struct GNUNET_TIME_Relative keepalive_period;
258 * Signal that shutdown is happening: prevent recovery measures.
260 extern int shutting_down;
263 * Set to non-zero values to create random drops to test retransmissions.
265 extern unsigned long long drop_percent;
269 * Send a message to a client.
271 * @param c client to get the message
272 * @param env envelope with the message
275 GSC_send_to_client (struct CadetClient *c,
276 struct GNUNET_MQ_Envelope *env);
280 * A channel was destroyed by the other peer. Tell our client.
282 * @param c client that lost a channel
283 * @param ccn channel identification number for the client
284 * @param ch the channel object
287 GSC_handle_remote_channel_destroy (struct CadetClient *c,
288 struct GNUNET_CADET_ClientChannelNumber ccn,
289 struct CadetChannel *ch);
292 * A client that created a loose channel that was not bound to a port
293 * disconnected, drop it from the #loose_channels list.
295 * @param h_port the hashed port the channel was trying to bind to
296 * @param ch the channel that was lost
299 GSC_drop_loose_channel (const struct GNUNET_HashCode *h_port,
300 struct CadetChannel *ch);
304 * Bind incoming channel to this client, and notify client
305 * about incoming connection.
307 * @param c client to bind to
308 * @param ch channel to be bound
309 * @param dest peer that establishes the connection
310 * @param port port number
311 * @param options options
312 * @return local channel number assigned to the new client
314 struct GNUNET_CADET_ClientChannelNumber
315 GSC_bind (struct CadetClient *c,
316 struct CadetChannel *ch,
317 struct CadetPeer *dest,
318 const struct GNUNET_HashCode *port,
323 * Return identifier for a client as a string.
325 * @param c client to identify
326 * @return string for debugging
329 GSC_2s (struct CadetClient *c);