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