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