much work on connection/route/peer-level queue management
[oweals/gnunet.git] / src / cadet / gnunet-service-cadet-new.h
1
2 /*
3      This file is part of GNUnet.
4      Copyright (C) 2001-2017 GNUnet e.V.
5
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.
10
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.
15
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.
20 */
21
22 /**
23  * @file cadet/gnunet-service-cadet-new.h
24  * @brief Information we track per peer.
25  * @author Bartlomiej Polot
26  * @author Christian Grothoff
27  */
28 #ifndef GNUNET_SERVICE_CADET_H
29 #define GNUNET_SERVICE_CADET_H
30
31 #include "gnunet_util_lib.h"
32 #define NEW_CADET 1
33
34 /**
35  * A client to the CADET service.  Each client gets a unique handle.
36  */
37 struct CadetClient;
38
39 /**
40  * A peer in the GNUnet network.  Each peer we care about must have one globally
41  * unique such handle within this process.
42  */
43 struct CadetPeer;
44
45 /**
46  * Tunnel from us to another peer.  There can only be at most one
47  * tunnel per peer.
48  */
49 struct CadetTunnel;
50
51 /**
52  * Entry in the message queue of a `struct CadetTunnel`.
53  */
54 struct CadetTunnelQueueEntry;
55
56 /**
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.
61  */
62 struct CadetPeerPath;
63
64 /**
65  * Entry in a peer path.
66  */
67 struct CadetPeerPathEntry
68 {
69   /**
70    * DLL of paths where the same @e peer is at the same offset.
71    */
72   struct CadetPeerPathEntry *next;
73
74   /**
75    * DLL of paths where the same @e peer is at the same offset.
76    */
77   struct CadetPeerPathEntry *prev;
78
79   /**
80    * The peer at this offset of the path.
81    */
82   struct CadetPeer *peer;
83
84   /**
85    * Path this entry belongs to.
86    */
87   struct CadetPeerPath *path;
88
89   /**
90    * Connection using this path, or NULL for none.
91    */
92   struct CadetConnection *cc;
93
94   /**
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
99    * against overflows.
100    */
101   int score;
102
103 };
104
105 /**
106  * Entry in list of connections used by tunnel, with metadata.
107  */
108 struct CadetTConnection
109 {
110   /**
111    * Next in DLL.
112    */
113   struct CadetTConnection *next;
114
115   /**
116    * Prev in DLL.
117    */
118   struct CadetTConnection *prev;
119
120   /**
121    * Connection handle.
122    */
123   struct CadetConnection *cc;
124
125   /**
126    * Tunnel this connection belongs to.
127    */
128   struct CadetTunnel *t;
129
130   /**
131    * Creation time, to keep oldest connection alive.
132    */
133   struct GNUNET_TIME_Absolute created;
134
135   /**
136    * Connection throughput, to keep fastest connection alive.
137    */
138   uint32_t throughput;
139
140   /**
141    * Is the connection currently ready for transmission?
142    */
143   int is_ready;
144 };
145
146
147 /**
148  * Active path through the network (used by a tunnel).  There may
149  * be at most one connection per path.
150  */
151 struct CadetConnection;
152
153 /**
154  * Description of a segment of a `struct CadetConnection` at the
155  * intermediate peers.  Routes are basically entries in a peer's
156  * routing table for forwarding traffic.  At both endpoints, the
157  * routes are terminated by a `struct CadetConnection`, which knows
158  * the complete `struct CadetPath` that is formed by the individual
159  * routes.
160  */
161 struct CadetRoute;
162
163 /**
164  * Logical end-to-end conenction between clients.  There can be
165  * any number of channels between clients.
166  */
167 struct CadetChannel;
168
169 /**
170  * Handle to the statistics service.
171  */
172 extern struct GNUNET_STATISTICS_Handle *stats;
173
174 /**
175  * Handle to communicate with ATS.
176  */
177 extern struct GNUNET_ATS_ConnectivityHandle *ats_ch;
178
179 /**
180  * Local peer own ID.
181  */
182 extern struct GNUNET_PeerIdentity my_full_id;
183
184 /**
185  * Own private key.
186  */
187 extern struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key;
188
189 /**
190  * All ports clients of this peer have opened.
191  */
192 extern struct GNUNET_CONTAINER_MultiHashMap *open_ports;
193
194 /**
195  * Map from `struct GNUNET_CADET_ConnectionTunnelIdentifier`
196  * hash codes to `struct CadetConnection` objects.
197  */
198 extern struct GNUNET_CONTAINER_MultiShortmap *connections;
199
200 /**
201  * Map from ports to channels where the ports were closed at the
202  * time we got the inbound connection.
203  * Indexed by port, contains `struct CadetChannel`.
204  */
205 extern struct GNUNET_CONTAINER_MultiHashMap *loose_channels;
206
207 /**
208  * Map from PIDs to `struct CadetPeer` entries.
209  */
210 extern struct GNUNET_CONTAINER_MultiPeerMap *peers;
211
212 /**
213  * How many messages are needed to trigger an AXOLOTL ratchet advance.
214  */
215 extern unsigned long long ratchet_messages;
216
217 /**
218  * How long until we trigger a ratched advance due to time.
219  */
220 extern struct GNUNET_TIME_Relative ratchet_time;
221
222
223
224 /**
225  * Send a message to a client.
226  *
227  * @param c client to get the message
228  * @param env envelope with the message
229  */
230 void
231 GSC_send_to_client (struct CadetClient *c,
232                     struct GNUNET_MQ_Envelope *env);
233
234
235 /**
236  * Bind incoming channel to this client, and notify client
237  * about incoming connection.
238  *
239  * @param c client to bind to
240  * @param ch channel to be bound
241  * @param dest peer that establishes the connection
242  * @param port port number
243  * @param options options
244  * @return local channel number assigned to the new client
245  */
246 struct GNUNET_CADET_ClientChannelNumber
247 GSC_bind (struct CadetClient *c,
248           struct CadetChannel *ch,
249           struct CadetPeer *dest,
250           const struct GNUNET_HashCode *port,
251           uint32_t options);
252
253
254 /**
255  * Return identifier for a client as a string.
256  *
257  * @param c client to identify
258  * @return string for debugging
259  */
260 const char *
261 GSC_2s (struct CadetClient *c);
262
263
264 #endif