4310b5cae8cca4ba4468431d083b74670a52d305
[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 2, 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 GNUNET_YES
34
35 /**
36  * For how long do we allow unused bandwidth
37  * from the past to carry over into the future? (in ms)
38  */
39 #define MAX_BANDWIDTH_CARRY 5000
40
41 /**
42  * How often do we (at most) do a full quota
43  * recalculation? (in ms)
44  */
45 #define MIN_QUOTA_REFRESH_TIME 2000
46
47 /**
48  * Message from the transport service to the library
49  * informing about neighbors.
50  */
51 struct ConnectInfoMessage
52 {
53
54   /**
55    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT
56    */
57   struct GNUNET_MessageHeader header;
58
59   /**
60    * Transport distance metric (i.e. hops for DV)
61    */
62   uint32_t distance;
63
64   /**
65    * Latency estimate.
66    */
67   struct GNUNET_TIME_RelativeNBO latency;
68
69   /**
70    * Identity of the new neighbour.
71    */
72   struct GNUNET_PeerIdentity id;
73
74 };
75
76
77 /**
78  * Message from the transport service to the library
79  * informing about disconnects.
80  */
81 struct DisconnectInfoMessage
82 {
83
84   /**
85    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT
86    */
87   struct GNUNET_MessageHeader header;
88
89   /**
90    * Reserved, always zero.
91    */
92   uint32_t reserved GNUNET_PACKED;
93
94   /**
95    * Who got disconnected?
96    */
97   struct GNUNET_PeerIdentity peer;
98
99 };
100
101
102 /**
103  * Message used to set a particular bandwidth quota.  Send
104  * TO the service to set an incoming quota, send FROM the
105  * service to update an outgoing quota.
106  */
107 struct QuotaSetMessage
108 {
109
110   /**
111    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_NEIGHBOUR_INFO
112    */
113   struct GNUNET_MessageHeader header;
114
115   /**
116    * Quota in bytes per ms, 0 to drop everything;
117    * in network byte order.
118    */
119   uint32_t quota_in GNUNET_PACKED;
120
121   /**
122    * About which peer are we talking here?
123    */
124   struct GNUNET_PeerIdentity peer;
125
126 };
127
128
129 /**
130  * Message used to notify the transport API about a message
131  * received from the network.  The actual message follows.
132  */
133 struct InboundMessage
134 {
135
136   /**
137    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_RECV
138    */
139   struct GNUNET_MessageHeader header;
140
141   /**
142    * Always zero.
143    */
144   uint32_t reserved GNUNET_PACKED;
145
146   /**
147    * Latency estimate.
148    */
149   struct GNUNET_TIME_RelativeNBO latency;
150
151   /**
152    * Which peer sent the message?
153    */
154   struct GNUNET_PeerIdentity peer;
155
156   /**
157    * Distance metric.
158    */
159   uint32_t distance;
160
161 };
162
163
164 /**
165  * Message used to notify the transport API that it can
166  * send another message to the transport service.
167  */
168 struct SendOkMessage
169 {
170
171   /**
172    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK
173    */
174   struct GNUNET_MessageHeader header;
175
176   /**
177    * GNUNET_OK if the transmission succeeded,
178    * GNUNET_SYSERR if it failed (i.e. network disconnect);
179    * in either case, it is now OK for this client to
180    * send us another message for the given peer.
181    */
182   uint32_t success GNUNET_PACKED;
183
184   /**
185    * Latency estimate.
186    */
187   struct GNUNET_TIME_RelativeNBO latency;
188
189   /**
190    * Which peer can send more now?
191    */
192   struct GNUNET_PeerIdentity peer;
193
194 };
195
196
197 /**
198  * Message used to notify the transport service about a message
199  * to be transmitted to another peer.  The actual message follows.
200  */
201 struct OutboundMessage
202 {
203
204   /**
205    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_SEND
206    */
207   struct GNUNET_MessageHeader header;
208
209   /**
210    * Message priority.
211    */
212   uint32_t priority GNUNET_PACKED;
213
214   /**
215    * Allowed delay.
216    */
217   struct GNUNET_TIME_RelativeNBO timeout;
218
219   /**
220    * Which peer should receive the message?
221    */
222   struct GNUNET_PeerIdentity peer;
223
224 };
225
226
227 /**
228  * Message from the library to the transport service
229  * asking for converting a transport address to a
230  * human-readable UTF-8 string.
231  */
232 struct AddressLookupMessage
233 {
234
235   /**
236    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP
237    */
238   struct GNUNET_MessageHeader header;
239
240   /**
241    * Should the conversion use numeric IP addresses (otherwise
242    * a reverse DNS lookup is OK -- if applicable).
243    */
244   int32_t numeric_only GNUNET_PACKED;
245
246   /**
247    * timeout to give up.
248    */
249   struct GNUNET_TIME_AbsoluteNBO timeout;
250
251   /**
252    * Length of the (binary) address in bytes, in big-endian.
253    */
254   uint32_t addrlen GNUNET_PACKED;
255
256   /* followed by 'addrlen' bytes of the actual address, then
257      followed by the 0-terminated name of the transport */
258 };
259
260
261
262 /**
263  * Change in blacklisting (either request or notification,
264  * depending on which direction it is going).
265  */
266 struct BlacklistMessage
267 {
268
269   /**
270    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST
271    */
272   struct GNUNET_MessageHeader header;
273
274   /**
275    * Reserved (for alignment).
276    */
277   uint32_t reserved GNUNET_PACKED;
278
279   /**
280    * Which peer is being blacklisted (or has seen its
281    * blacklisting expire)?
282    */
283   struct GNUNET_PeerIdentity peer;
284
285   /**
286    * Until what time is this peer blacklisted (zero for
287    * no longer blacklisted).
288    */
289   struct GNUNET_TIME_AbsoluteNBO until;
290
291 };
292
293
294 /* end of transport.h */
295 #endif