new operation queue for limiting overlay connects
[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 /**
60  * Similiar to GNUNET_TRANSPORT_NotifyDisconnect but in and out quotas are
61  * included here. These values are not required outside transport_api
62  *
63  * @param cls closure
64  * @param peer the peer that connected
65  * @param ats performance data
66  * @param ats_count number of entries in ats (excluding 0-termination)
67  * @param bandwidth_in inbound bandwidth in NBO
68  * @param bandwidth_out outbound bandwidth in NBO
69  *
70  */
71
72 typedef void (*NotifyConnect) (void *cls,
73                               const struct GNUNET_PeerIdentity *peer,
74                               const struct GNUNET_ATS_Information *ats,
75                               uint32_t ats_count,
76                               struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
77                               struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out);
78
79 GNUNET_NETWORK_STRUCT_BEGIN
80
81 /**
82  * Message from the transport service to the library
83  * asking to check if both processes agree about this
84  * peers identity.
85  */
86 struct StartMessage
87 {
88
89   /**
90    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_START
91    */
92   struct GNUNET_MessageHeader header;
93
94   /**
95    * 0: no options
96    * 1: The 'self' field should be checked
97    * 2: this client is interested in payload traffic
98    */
99   uint32_t options;
100
101   /**
102    * Identity we think we have.  If it does not match, the
103    * receiver should print out an error message and disconnect.
104    */
105   struct GNUNET_PeerIdentity self;
106
107 };
108
109
110 /**
111  * Message from the transport service to the library
112  * informing about neighbors.
113  */
114 struct ConnectInfoMessage
115 {
116
117   /**
118    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT
119    */
120   struct GNUNET_MessageHeader header;
121
122   /**
123    * Number of ATS key-value pairs that follow this struct
124    * (excluding the 0-terminator).
125    */
126   uint32_t ats_count GNUNET_PACKED;
127
128   /**
129    * Identity of the new neighbour.
130    */
131   struct GNUNET_PeerIdentity id;
132
133   /**
134    * Current inbound quota for this peer
135    */
136   struct GNUNET_BANDWIDTH_Value32NBO quota_in;
137
138   /**
139    * Current outbound quota for this peer
140    */
141   struct GNUNET_BANDWIDTH_Value32NBO quota_out;
142 };
143
144
145 /**
146  * Message from the transport service to the library
147  * informing about disconnects.
148  */
149 struct DisconnectInfoMessage
150 {
151
152   /**
153    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT
154    */
155   struct GNUNET_MessageHeader header;
156
157   /**
158    * Reserved, always zero.
159    */
160   uint32_t reserved GNUNET_PACKED;
161
162   /**
163    * Who got disconnected?
164    */
165   struct GNUNET_PeerIdentity peer;
166
167 };
168
169 /**
170  * Message type for sending a request connect message
171  * to the transport service.  Must be done before transport
172  * api will allow messages to be queued/sent to transport
173  * service for transmission to a peer.
174  */
175 struct TransportRequestConnectMessage
176 {
177   /**
178    *  Message header
179    */
180   struct GNUNET_MessageHeader header;
181
182   /**
183    * For alignment.
184    */
185   uint32_t reserved;
186
187   /**
188    * Identity of the peer we would like to connect to.
189    */
190   struct GNUNET_PeerIdentity peer;
191 };
192
193 /**
194  * Message used to set a particular bandwidth quota.  Sent TO the
195  * service to set an incoming quota, sent FROM the service to update
196  * an outgoing quota.
197  */
198 struct QuotaSetMessage
199 {
200
201   /**
202    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA
203    */
204   struct GNUNET_MessageHeader header;
205
206   /**
207    * Quota.
208    */
209   struct GNUNET_BANDWIDTH_Value32NBO quota;
210
211   /**
212    * About which peer are we talking here?
213    */
214   struct GNUNET_PeerIdentity peer;
215
216 };
217
218
219 /**
220  * Message used to notify the transport API about a message
221  * received from the network.  The actual message follows.
222  */
223 struct InboundMessage
224 {
225
226   /**
227    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_RECV
228    */
229   struct GNUNET_MessageHeader header;
230
231   /**
232    * Number of ATS key-value pairs that follow this struct
233    * (excluding the 0-terminator).
234    */
235   uint32_t ats_count GNUNET_PACKED;
236
237   /**
238    * Which peer sent the message?
239    */
240   struct GNUNET_PeerIdentity peer;
241
242 };
243
244
245 /**
246  * Message used to notify the transport API that it can
247  * send another message to the transport service.
248  */
249 struct SendOkMessage
250 {
251
252   /**
253    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK
254    */
255   struct GNUNET_MessageHeader header;
256
257   /**
258    * GNUNET_OK if the transmission succeeded,
259    * GNUNET_SYSERR if it failed (i.e. network disconnect);
260    * in either case, it is now OK for this client to
261    * send us another message for the given peer.
262    */
263   uint32_t success GNUNET_PACKED;
264
265
266   /**
267    * Size of message sent
268    */
269   uint32_t bytes_msg GNUNET_PACKED;
270
271   /**
272    * Size of message sent over wire
273    * Includes plugin and protocol specific overhead
274    */
275   uint32_t bytes_physical GNUNET_PACKED;
276
277   /**
278    * Latency estimate.
279    */
280   struct GNUNET_TIME_RelativeNBO latency;
281
282   /**
283    * Which peer can send more now?
284    */
285   struct GNUNET_PeerIdentity peer;
286
287 };
288
289
290 /**
291  * Message used to notify the transport service about a message
292  * to be transmitted to another peer.  The actual message follows.
293  */
294 struct OutboundMessage
295 {
296
297   /**
298    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_SEND
299    */
300   struct GNUNET_MessageHeader header;
301
302   /**
303    * Message priority.
304    */
305   uint32_t priority GNUNET_PACKED;
306
307   /**
308    * Allowed delay.
309    */
310   struct GNUNET_TIME_RelativeNBO timeout;
311
312   /**
313    * Which peer should receive the message?
314    */
315   struct GNUNET_PeerIdentity peer;
316
317 };
318
319
320 /**
321  * Message from the library to the transport service
322  * asking for converting a transport address to a
323  * human-readable UTF-8 string.
324  */
325 struct AddressLookupMessage
326 {
327
328   /**
329    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING
330    */
331   struct GNUNET_MessageHeader header;
332
333   /**
334    * Should the conversion use numeric IP addresses (otherwise
335    * a reverse DNS lookup is OK -- if applicable).
336    */
337   int16_t numeric_only GNUNET_PACKED;
338
339   /**
340    * Length of the (binary) address in bytes, in big-endian.
341    */
342   uint16_t addrlen GNUNET_PACKED;
343
344   /**
345    * timeout to give up.
346    */
347   struct GNUNET_TIME_RelativeNBO timeout;
348
349   /* followed by 'addrlen' bytes of the actual address, then
350    * followed by the 0-terminated name of the transport */
351 };
352
353
354 /**
355  * Message from the library to the transport service
356  * asking for human readable addresses known for a peer.
357  */
358 struct PeerAddressLookupMessage
359 {
360   /**
361    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP
362    */
363   struct GNUNET_MessageHeader header;
364
365   /**
366    * For alignment.
367    */
368   uint32_t reserved;
369
370   /**
371    * timeout to give up.  FIXME: remove in the future.
372    */
373   struct GNUNET_TIME_RelativeNBO timeout;
374
375   /**
376    * The identity of the peer to look up.
377    */
378   struct GNUNET_PeerIdentity peer;
379 };
380
381
382 /**
383  * Message from the library to the transport service
384  * asking for binary addresses known for a peer.
385  */
386 struct AddressIterateMessage
387 {
388   /**
389    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE
390    */
391   struct GNUNET_MessageHeader header;
392
393   /**
394    * One shot call or continous replies?
395    */
396   uint32_t one_shot;
397
398   /**
399    * timeout to give up.  FIXME: remove in the future
400    */
401   struct GNUNET_TIME_AbsoluteNBO timeout;
402
403   /**
404    * The identity of the peer to look up.
405    */
406   struct GNUNET_PeerIdentity peer;
407
408 };
409
410
411 /**
412  * Message from the transport service to the library
413  * containing binary addresses known for a peer.
414  * Memory layout:
415  * [AddressIterateResponseMessage][address[addrlen]][transportname[pluginlen]]
416  */
417 struct AddressIterateResponseMessage
418 {
419   /**
420    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE
421    */
422   struct GNUNET_MessageHeader header;
423
424   /**
425    * For alignment.
426    */
427   uint32_t reserved;
428
429     /**
430    * Peer identity
431    */
432   struct GNUNET_PeerIdentity peer;
433
434   /**
435    * address length
436    */
437   uint32_t addrlen GNUNET_PACKED;
438
439   /**
440    * length of the plugin name
441    */
442   uint32_t pluginlen GNUNET_PACKED;
443
444 };
445
446
447 /**
448  * Change in blacklisting (either request or notification,
449  * depending on which direction it is going).
450  */
451 struct BlacklistMessage
452 {
453
454   /**
455    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY or
456    * GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY.
457    */
458   struct GNUNET_MessageHeader header;
459
460   /**
461    * 0 for the query, GNUNET_OK (allowed) or GNUNET_SYSERR (disallowed)
462    * for the response.
463    */
464   uint32_t is_allowed GNUNET_PACKED;
465
466   /**
467    * Which peer is being blacklisted or queried?
468    */
469   struct GNUNET_PeerIdentity peer;
470
471 };
472 GNUNET_NETWORK_STRUCT_END
473
474 /* end of transport.h */
475 #endif