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