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