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