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