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