use new shortmap to simplify CADET logic a bit
[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
33 /**
34  * A client to the CADET service.  Each client gets a unique handle.
35  */
36 struct CadetClient;
37
38 /**
39  * A peer in the GNUnet network.  Each peer we care about must have one globally
40  * unique such handle within this process.
41  */
42 struct CadetPeer;
43
44 /**
45  * Tunnel from us to another peer.  There can only be at most one
46  * tunnel per peer.
47  */
48 struct CadetTunnel;
49
50 /**
51  * Entry in the message queue of a `struct CadetTunnel`.
52  */
53 struct CadetTunnelQueueEntry;
54
55 /**
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.
60  */
61 struct CadetPeerPath;
62
63 /**
64  * Entry in a peer path.
65  */
66 struct CadetPeerPathEntry
67 {
68   /**
69    * DLL of paths where the same @e peer is at the same offset.
70    */
71   struct CadetPeerPathEntry *next;
72
73   /**
74    * DLL of paths where the same @e peer is at the same offset.
75    */
76   struct CadetPeerPathEntry *prev;
77
78   /**
79    * The peer at this offset of the path.
80    */
81   struct CadetPeer *peer;
82
83   /**
84    * Path this entry belongs to.
85    */
86   struct CadetPeerPath *path;
87
88   /**
89    * Connection using this path, or NULL for none.
90    */
91   struct CadetConnection *cc;
92
93   /**
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
98    * against overflows.
99    */
100   int score;
101
102 };
103
104 /**
105  * Entry in list of connections used by tunnel, with metadata.
106  */
107 struct CadetTConnection;
108
109 /**
110  * Active path through the network (used by a tunnel).  There may
111  * be at most one connection per path.
112  */
113 struct CadetConnection;
114
115 /**
116  * Logical end-to-end conenction between clients.  There can be
117  * any number of channels between clients.
118  */
119 struct CadetChannel;
120
121 /**
122  * Handle to the statistics service.
123  */
124 extern struct GNUNET_STATISTICS_Handle *stats;
125
126 /**
127  * Handle to communicate with ATS.
128  */
129 extern struct GNUNET_ATS_ConnectivityHandle *ats_ch;
130
131 /**
132  * Local peer own ID.
133  */
134 extern struct GNUNET_PeerIdentity my_full_id;
135
136 /**
137  * Own private key.
138  */
139 extern struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key;
140
141 /**
142  * All ports clients of this peer have opened.
143  */
144 extern struct GNUNET_CONTAINER_MultiHashMap *open_ports;
145
146 /**
147  * Map from `struct GNUNET_CADET_ConnectionTunnelIdentifier`
148  * hash codes to `struct CadetConnection` objects.
149  */
150 extern struct GNUNET_CONTAINER_MultiShortmap *connections;
151
152 /**
153  * Map from ports to channels where the ports were closed at the
154  * time we got the inbound connection.
155  * Indexed by port, contains `struct CadetChannel`.
156  */
157 extern struct GNUNET_CONTAINER_MultiHashMap *loose_channels;
158
159 /**
160  * Map from PIDs to `struct CadetPeer` entries.
161  */
162 extern struct GNUNET_CONTAINER_MultiPeerMap *peers;
163
164 /**
165  * How many messages are needed to trigger an AXOLOTL ratchet advance.
166  */
167 extern unsigned long long ratchet_messages;
168
169 /**
170  * How long until we trigger a ratched advance due to time.
171  */
172 extern struct GNUNET_TIME_Relative ratchet_time;
173
174
175
176 /**
177  * Send a message to a client.
178  *
179  * @param c client to get the message
180  * @param env envelope with the message
181  */
182 void
183 GSC_send_to_client (struct CadetClient *c,
184                     struct GNUNET_MQ_Envelope *env);
185
186
187 /**
188  * Bind incoming channel to this client, and notify client
189  * about incoming connection.
190  *
191  * @param c client to bind to
192  * @param ch channel to be bound
193  * @param dest peer that establishes the connection
194  * @param port port number
195  * @param options options
196  * @return local channel number assigned to the new client
197  */
198 struct GNUNET_CADET_ClientChannelNumber
199 GSC_bind (struct CadetClient *c,
200           struct CadetChannel *ch,
201           struct CadetPeer *dest,
202           const struct GNUNET_HashCode *port,
203           uint32_t options);
204
205
206 /**
207  * Return identifier for a client as a string.
208  *
209  * @param c client to identify
210  * @return string for debugging
211  */
212 const char *
213 GSC_2s (struct CadetClient *c);
214
215
216 #endif