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