343679b2ee71ab894724b5049135b27a88d71a9b
[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
41 #define DEBUG_TRANSPORT_TIMEOUT GNUNET_NO
42
43 #define DEBUG_TRANSPORT_DISCONNECT GNUNET_NO
44
45 /**
46  * For how long do we allow unused bandwidth
47  * from the past to carry over into the future? (in seconds)
48  */
49 #define MAX_BANDWIDTH_CARRY_S 5
50
51 /**
52  * How often do we (at most) do a full quota
53  * recalculation? (in ms)
54  */
55 #define MIN_QUOTA_REFRESH_TIME 2000
56
57 /**
58  * Message from the transport service to the library
59  * asking to check if both processes agree about this
60  * peers identity.
61  */
62 struct StartMessage
63 {
64
65   /**
66    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_START
67    */
68   struct GNUNET_MessageHeader header;
69
70   /**
71    * Should the 'self' field be checked?
72    */
73   uint32_t do_check;
74
75   /**
76    * Identity we think we have.  If it does not match, the
77    * receiver should print out an error message and disconnect.
78    */
79   struct GNUNET_PeerIdentity self;
80
81 };
82
83
84 /**
85  * Message from the transport service to the library
86  * informing about neighbors.
87  */
88 struct ConnectInfoMessage
89 {
90
91   /**
92    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT
93    */
94   struct GNUNET_MessageHeader header;
95
96   /**
97    * Number of ATS key-value pairs that follow this struct
98    * (excluding the 0-terminator).
99    */
100   uint32_t ats_count GNUNET_PACKED;
101
102   /**
103    * Identity of the new neighbour.
104    */
105   struct GNUNET_PeerIdentity id;
106
107   /**
108    * First of the ATS information blocks (we must have at least
109    * one due to the 0-termination requirement).
110    */
111   struct GNUNET_TRANSPORT_ATS_Information ats;
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    * Identity of the peer we would like to connect to.
154    */
155   struct GNUNET_PeerIdentity peer;
156 };
157
158 /**
159  * Message used to set a particular bandwidth quota.  Send TO the
160  * service to set an incoming quota, send FROM the service to update
161  * an outgoing quota.
162  */
163 struct QuotaSetMessage
164 {
165
166   /**
167    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_NEIGHBOUR_INFO
168    */
169   struct GNUNET_MessageHeader header;
170
171   /**
172    * Quota.
173    */
174   struct GNUNET_BANDWIDTH_Value32NBO quota;
175
176   /**
177    * About which peer are we talking here?
178    */
179   struct GNUNET_PeerIdentity peer;
180
181 };
182
183
184 /**
185  * Message used to notify the transport API about a message
186  * received from the network.  The actual message follows.
187  */
188 struct InboundMessage
189 {
190
191   /**
192    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_RECV
193    */
194   struct GNUNET_MessageHeader header;
195
196   /**
197    * Always zero.
198    */
199   uint32_t reserved GNUNET_PACKED;
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    * First of the ATS information blocks (we must have at least
214    * one due to the 0-termination requirement).
215    */
216   struct GNUNET_TRANSPORT_ATS_Information ats;
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_LOOKUP
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   int32_t numeric_only GNUNET_PACKED;
301
302   /**
303    * timeout to give up.
304    */
305   struct GNUNET_TIME_AbsoluteNBO timeout;
306
307   /**
308    * Length of the (binary) address in bytes, in big-endian.
309    */
310   uint32_t addrlen GNUNET_PACKED;
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 /**
319  * Change in blacklisting (either request or notification,
320  * depending on which direction it is going).
321  */
322 struct BlacklistMessage
323 {
324
325   /**
326    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY or
327    * GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY.
328    */
329   struct GNUNET_MessageHeader header;
330
331   /**
332    * 0 for the query, GNUNET_OK (allowed) or GNUNET_SYSERR (disallowed)
333    * for the response.
334    */
335   uint32_t is_allowed GNUNET_PACKED;
336
337   /**
338    * Which peer is being blacklisted or queried?
339    */
340   struct GNUNET_PeerIdentity peer;
341
342 };
343
344
345 /* end of transport.h */
346 #endif