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