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