3b0c4d3ef19a46ae6e648b3746d0974d8f66702a
[oweals/gnunet.git] / src / transport / transport.h
1 /*
2      This file is part of GNUnet.
3      (C) 2009 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      option) any later version.
9
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      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file transport/transport.h
23  * @brief common internal definitions for transport service
24  * @author Christian Grothoff
25  */
26 #ifndef TRANSPORT_H
27 #define TRANSPORT_H
28
29 #include "gnunet_crypto_lib.h"
30 #include "gnunet_time_lib.h"
31 #include "gnunet_transport_service.h"
32
33 /* Minimum time between to calculations*/
34 #define ATS_MIN_INTERVAL  GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 250)
35 #define ATS_EXEC_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1)
36 #define ATS_MAX_EXEC_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 500)
37
38 struct ATS_info
39 {
40         struct GNUNET_CONTAINER_MultiHashMap * peers;
41         /**
42          * Time of last execution
43          */
44         struct GNUNET_TIME_Absolute last;
45         /**
46          * Minimum intervall between two executions
47          */
48         struct GNUNET_TIME_Relative min_delta;
49         /**
50          * Regular intervall when execution is triggered
51          */
52         struct GNUNET_TIME_Relative exec_intervall;
53         /**
54          * Maximum execution time per calculation
55          */
56         struct GNUNET_TIME_Relative max_exec_duration;
57
58         GNUNET_SCHEDULER_TaskIdentifier ats_task;
59 };
60
61 struct ATS_peer
62 {
63         struct GNUNET_PeerIdentity peer;
64         struct NeighbourList * n;
65         double f;
66         int     t;
67 };
68
69 #define DEBUG_TRANSPORT GNUNET_NO
70 #define DEBUG_TRANSPORT_TIMEOUT GNUNET_NO
71 #define DEBUG_TRANSPORT_DISCONNECT GNUNET_NO
72
73 /**
74  * For how long do we allow unused bandwidth
75  * from the past to carry over into the future? (in seconds)
76  */
77 #define MAX_BANDWIDTH_CARRY_S 5
78
79 /**
80  * How often do we (at most) do a full quota
81  * recalculation? (in ms)
82  */
83 #define MIN_QUOTA_REFRESH_TIME 2000
84
85 /**
86  * Message from the transport service to the library
87  * asking to check if both processes agree about this
88  * peers identity.
89  */
90 struct StartMessage
91 {
92
93   /**
94    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_START
95    */
96   struct GNUNET_MessageHeader header;
97
98   /**
99    * Should the 'self' field be checked?
100    */
101   uint32_t do_check;
102
103   /**
104    * Identity we think we have.  If it does not match, the
105    * receiver should print out an error message and disconnect.
106    */
107   struct GNUNET_PeerIdentity self;
108
109 };
110
111
112 /**
113  * Message from the transport service to the library
114  * informing about neighbors.
115  */
116 struct ConnectInfoMessage
117 {
118
119   /**
120    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT
121    */
122   struct GNUNET_MessageHeader header;
123
124   /**
125    * Number of ATS key-value pairs that follow this struct
126    * (excluding the 0-terminator).
127    */
128   uint32_t ats_count GNUNET_PACKED;
129
130   /**
131    * Identity of the new neighbour.
132    */
133   struct GNUNET_PeerIdentity id;
134
135   /**
136    * First of the ATS information blocks (we must have at least
137    * one due to the 0-termination requirement).
138    */
139   struct GNUNET_TRANSPORT_ATS_Information ats;
140 };
141
142
143 /**
144  * Message from the transport service to the library
145  * informing about disconnects.
146  */
147 struct DisconnectInfoMessage
148 {
149
150   /**
151    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT
152    */
153   struct GNUNET_MessageHeader header;
154
155   /**
156    * Reserved, always zero.
157    */
158   uint32_t reserved GNUNET_PACKED;
159
160   /**
161    * Who got disconnected?
162    */
163   struct GNUNET_PeerIdentity peer;
164
165 };
166
167 /**
168  * Message type for sending a request connect message
169  * to the transport service.  Must be done before transport
170  * api will allow messages to be queued/sent to transport
171  * service for transmission to a peer.
172  */
173 struct TransportRequestConnectMessage
174 {
175   /**
176    *  Message header
177    */
178   struct GNUNET_MessageHeader header;
179
180   /**
181    * Identity of the peer we would like to connect to.
182    */
183   struct GNUNET_PeerIdentity peer;
184 };
185
186 /**
187  * Message used to set a particular bandwidth quota.  Send TO the
188  * service to set an incoming quota, send FROM the service to update
189  * an outgoing quota.
190  */
191 struct QuotaSetMessage
192 {
193
194   /**
195    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_NEIGHBOUR_INFO
196    */
197   struct GNUNET_MessageHeader header;
198
199   /**
200    * Quota.
201    */
202   struct GNUNET_BANDWIDTH_Value32NBO quota;
203
204   /**
205    * About which peer are we talking here?
206    */
207   struct GNUNET_PeerIdentity peer;
208
209 };
210
211
212 /**
213  * Message used to notify the transport API about a message
214  * received from the network.  The actual message follows.
215  */
216 struct InboundMessage
217 {
218
219   /**
220    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_RECV
221    */
222   struct GNUNET_MessageHeader header;
223
224   /**
225    * Always zero.
226    */
227   uint32_t reserved GNUNET_PACKED;
228
229   /**
230    * Number of ATS key-value pairs that follow this struct
231    * (excluding the 0-terminator).
232    */
233   uint32_t ats_count GNUNET_PACKED;
234
235   /**
236    * Which peer sent the message?
237    */
238   struct GNUNET_PeerIdentity peer;
239
240   /**
241    * First of the ATS information blocks (we must have at least
242    * one due to the 0-termination requirement).
243    */
244   struct GNUNET_TRANSPORT_ATS_Information ats;
245 };
246
247
248 /**
249  * Message used to notify the transport API that it can
250  * send another message to the transport service.
251  */
252 struct SendOkMessage
253 {
254
255   /**
256    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK
257    */
258   struct GNUNET_MessageHeader header;
259
260   /**
261    * GNUNET_OK if the transmission succeeded,
262    * GNUNET_SYSERR if it failed (i.e. network disconnect);
263    * in either case, it is now OK for this client to
264    * send us another message for the given peer.
265    */
266   uint32_t success GNUNET_PACKED;
267
268   /**
269    * Latency estimate.
270    */
271   struct GNUNET_TIME_RelativeNBO latency;
272
273   /**
274    * Which peer can send more now?
275    */
276   struct GNUNET_PeerIdentity peer;
277
278 };
279
280
281 /**
282  * Message used to notify the transport service about a message
283  * to be transmitted to another peer.  The actual message follows.
284  */
285 struct OutboundMessage
286 {
287
288   /**
289    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_SEND
290    */
291   struct GNUNET_MessageHeader header;
292
293   /**
294    * Message priority.
295    */
296   uint32_t priority GNUNET_PACKED;
297
298   /**
299    * Allowed delay.
300    */
301   struct GNUNET_TIME_RelativeNBO timeout;
302
303   /**
304    * Which peer should receive the message?
305    */
306   struct GNUNET_PeerIdentity peer;
307
308 };
309
310
311 /**
312  * Message from the library to the transport service
313  * asking for converting a transport address to a
314  * human-readable UTF-8 string.
315  */
316 struct AddressLookupMessage
317 {
318
319   /**
320    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP
321    */
322   struct GNUNET_MessageHeader header;
323
324   /**
325    * Should the conversion use numeric IP addresses (otherwise
326    * a reverse DNS lookup is OK -- if applicable).
327    */
328   int32_t numeric_only GNUNET_PACKED;
329
330   /**
331    * timeout to give up.
332    */
333   struct GNUNET_TIME_AbsoluteNBO timeout;
334
335   /**
336    * Length of the (binary) address in bytes, in big-endian.
337    */
338   uint32_t addrlen GNUNET_PACKED;
339
340   /* followed by 'addrlen' bytes of the actual address, then
341      followed by the 0-terminated name of the transport */
342 };
343
344
345
346 /**
347  * Change in blacklisting (either request or notification,
348  * depending on which direction it is going).
349  */
350 struct BlacklistMessage
351 {
352
353   /**
354    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY or
355    * GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY.
356    */
357   struct GNUNET_MessageHeader header;
358
359   /**
360    * 0 for the query, GNUNET_OK (allowed) or GNUNET_SYSERR (disallowed)
361    * for the response.
362    */
363   uint32_t is_allowed GNUNET_PACKED;
364
365   /**
366    * Which peer is being blacklisted or queried?
367    */
368   struct GNUNET_PeerIdentity peer;
369
370 };
371
372
373 /* end of transport.h */
374 #endif