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