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