2 This file is part of GNUnet.
3 Copyright (C) 2001-2017 GNUnet e.V.
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.
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.
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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @file cadet/gnunet-service-cadet.h
23 * @brief Information we track per peer.
24 * @author Bartlomiej Polot
25 * @author Christian Grothoff
27 #ifndef GNUNET_SERVICE_CADET_H
28 #define GNUNET_SERVICE_CADET_H
30 #include "gnunet_util_lib.h"
31 #include "cadet_protocol.h"
34 * A client to the CADET service. Each client gets a unique handle.
39 * A peer in the GNUnet network. Each peer we care about must have one globally
40 * unique such handle within this process.
45 * Tunnel from us to another peer. There can only be at most one
51 * Entry in the message queue of a `struct CadetTunnel`.
53 struct CadetTunnelQueueEntry;
56 * A path of peer in the GNUnet network. There must only be at most
57 * once such path. Paths may share disjoint prefixes, but must all
58 * end at a unique suffix. Paths must also not be proper subsets of
59 * other existing paths.
64 * Entry in a peer path.
66 struct CadetPeerPathEntry
69 * DLL of paths where the same @e peer is at the same offset.
71 struct CadetPeerPathEntry *next;
74 * DLL of paths where the same @e peer is at the same offset.
76 struct CadetPeerPathEntry *prev;
79 * The peer at this offset of the path.
81 struct CadetPeer *peer;
84 * Path this entry belongs to.
86 struct CadetPeerPath *path;
89 * Connection using this path, or NULL for none.
91 struct CadetConnection *cc;
94 * Path's historic score up to this point. Basically, how often did
95 * we succeed or fail to use the path up to this entry in a
96 * connection. Positive values indicate good experiences, negative
97 * 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.
151 * Client that opened the port.
153 struct CadetClient *c;
158 struct GNUNET_HashCode port;
161 * Port hashed with our PID (matches incoming OPEN messages).
163 struct GNUNET_HashCode h_port;
168 * Active path through the network (used by a tunnel). There may
169 * be at most one connection per path.
171 struct CadetConnection;
174 * Description of a segment of a `struct CadetConnection` at the
175 * intermediate peers. Routes are basically entries in a peer's
176 * routing table for forwarding traffic. At both endpoints, the
177 * routes are terminated by a `struct CadetConnection`, which knows
178 * the complete `struct CadetPath` that is formed by the individual
184 * Logical end-to-end conenction between clients. There can be
185 * any number of channels between clients.
190 * Handle to our configuration.
192 extern const struct GNUNET_CONFIGURATION_Handle *cfg;
195 * Handle to the statistics service.
197 extern struct GNUNET_STATISTICS_Handle *stats;
200 * Handle to communicate with ATS.
202 extern struct GNUNET_ATS_ConnectivityHandle *ats_ch;
207 extern struct GNUNET_PeerIdentity my_full_id;
212 extern struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key;
215 * All ports clients of this peer have opened. Maps from
216 * a hashed port to a `struct OpenPort`.
218 extern struct GNUNET_CONTAINER_MultiHashMap *open_ports;
221 * Map from `struct GNUNET_CADET_ConnectionTunnelIdentifier`
222 * hash codes to `struct CadetConnection` objects.
224 extern struct GNUNET_CONTAINER_MultiShortmap *connections;
227 * Map from ports to channels where the ports were closed at the
228 * time we got the inbound connection.
229 * Indexed by h_port, contains `struct CadetChannel`.
231 extern struct GNUNET_CONTAINER_MultiHashMap *loose_channels;
234 * Map from PIDs to `struct CadetPeer` entries.
236 extern struct GNUNET_CONTAINER_MultiPeerMap *peers;
239 * How many messages are needed to trigger an AXOLOTL ratchet advance.
241 extern unsigned long long ratchet_messages;
244 * How long until we trigger a ratched advance due to time.
246 extern struct GNUNET_TIME_Relative ratchet_time;
249 * How frequently do we send KEEPALIVE messages on idle connections?
251 extern struct GNUNET_TIME_Relative keepalive_period;
254 * Signal that shutdown is happening: prevent recovery measures.
256 extern int shutting_down;
259 * Set to non-zero values to create random drops to test retransmissions.
261 extern unsigned long long drop_percent;
265 * Send a message to a client.
267 * @param c client to get the message
268 * @param env envelope with the message
271 GSC_send_to_client (struct CadetClient *c,
272 struct GNUNET_MQ_Envelope *env);
276 * A channel was destroyed by the other peer. Tell our client.
278 * @param c client that lost a channel
279 * @param ccn channel identification number for the client
280 * @param ch the channel object
283 GSC_handle_remote_channel_destroy (struct CadetClient *c,
284 struct GNUNET_CADET_ClientChannelNumber ccn,
285 struct CadetChannel *ch);
288 * A client that created a loose channel that was not bound to a port
289 * disconnected, drop it from the #loose_channels list.
291 * @param h_port the hashed port the channel was trying to bind to
292 * @param ch the channel that was lost
295 GSC_drop_loose_channel (const struct GNUNET_HashCode *h_port,
296 struct CadetChannel *ch);
300 * Bind incoming channel to this client, and notify client
301 * about incoming connection.
303 * @param c client to bind to
304 * @param ch channel to be bound
305 * @param dest peer that establishes the connection
306 * @param port port number
307 * @param options options
308 * @return local channel number assigned to the new client
310 struct GNUNET_CADET_ClientChannelNumber
311 GSC_bind (struct CadetClient *c,
312 struct CadetChannel *ch,
313 struct CadetPeer *dest,
314 const struct GNUNET_HashCode *port,
319 * Return identifier for a client as a string.
321 * @param c client to identify
322 * @return string for debugging
325 GSC_2s (struct CadetClient *c);