more work on peers, paths and tunnels
[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 /**
106  * Active path through the network (used by a tunnel).  There may
107  * be at most one connection per path.
108  */
109 struct CadetConnection;
110
111 /**
112  * Logical end-to-end conenction between clients.  There can be
113  * any number of channels between clients.
114  */
115 struct CadetChannel;
116
117 /**
118  * Handle to the statistics service.
119  */
120 extern struct GNUNET_STATISTICS_Handle *stats;
121
122 /**
123  * Handle to communicate with ATS.
124  */
125 extern struct GNUNET_ATS_ConnectivityHandle *ats_ch;
126
127 /**
128  * Local peer own ID.
129  */
130 extern struct GNUNET_PeerIdentity my_full_id;
131
132 /**
133  * Own private key.
134  */
135 extern struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key;
136
137 /**
138  * All ports clients of this peer have opened.
139  */
140 extern struct GNUNET_CONTAINER_MultiHashMap *open_ports;
141
142 /**
143  * Map from ports to channels where the ports were closed at the
144  * time we got the inbound connection.
145  * Indexed by port, contains `struct CadetChannel`.
146  */
147 extern struct GNUNET_CONTAINER_MultiHashMap *loose_channels;
148
149 /**
150  * Map from PIDs to `struct CadetPeer` entries.
151  */
152 extern struct GNUNET_CONTAINER_MultiPeerMap *peers;
153
154
155 /**
156  * Send a message to a client.
157  *
158  * @param c client to get the message
159  * @param env envelope with the message
160  */
161 void
162 GSC_send_to_client (struct CadetClient *c,
163                     struct GNUNET_MQ_Envelope *env);
164
165
166 /**
167  * Bind incoming channel to this client, and notify client
168  * about incoming connection.
169  *
170  * @param c client to bind to
171  * @param ch channel to be bound
172  * @param dest peer that establishes the connection
173  * @param port port number
174  * @param options options
175  * @return local channel number assigned to the new client
176  */
177 struct GNUNET_CADET_ClientChannelNumber
178 GSC_bind (struct CadetClient *c,
179           struct CadetChannel *ch,
180           struct CadetPeer *dest,
181           const struct GNUNET_HashCode *port,
182           uint32_t options);
183
184
185 /**
186  * Return identifier for a client as a string.
187  *
188  * @param c client to identify
189  * @return string for debugging
190  */
191 const char *
192 GSC_2s (struct CadetClient *c);
193
194
195 #endif