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