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