move GNUNET_TRANSPORT_ATS_ to GNUNET_ATS_
[oweals/gnunet.git] / src / core / core.h
1 /*
2      This file is part of GNUnet.
3      (C) 2009, 2010 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 core/core.h
23  * @brief common internal definitions for core service
24  * @author Christian Grothoff
25  */
26 #ifndef CORE_H
27 #define CORE_H
28
29 #include "gnunet_bandwidth_lib.h"
30 #include "gnunet_transport_service.h"
31 #include "gnunet_crypto_lib.h"
32 #include "gnunet_time_lib.h"
33
34 /**
35  * General core debugging.
36  */
37 #define DEBUG_CORE GNUNET_EXTRA_LOGGING
38
39 /**
40  * Definition of bits in the InitMessage's options field that specify
41  * which events this client cares about.  Note that inbound messages
42  * for handlers that were specifically registered are always
43  * transmitted to the client.
44  */
45 #define GNUNET_CORE_OPTION_NOTHING             0
46 #define GNUNET_CORE_OPTION_SEND_CONNECT        1
47 #define GNUNET_CORE_OPTION_SEND_DISCONNECT     2
48 #define GNUNET_CORE_OPTION_SEND_STATUS_CHANGE  4
49 #define GNUNET_CORE_OPTION_SEND_FULL_INBOUND   8
50 #define GNUNET_CORE_OPTION_SEND_HDR_INBOUND   16
51 #define GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND 32
52 #define GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND  64
53
54
55 /**
56  * Message transmitted core clients to gnunet-service-core
57  * to start the interaction.  This header is followed by
58  * uint16_t type values specifying which messages this
59  * client is interested in.
60  */
61 struct InitMessage
62 {
63
64   /**
65    * Header with type GNUNET_MESSAGE_TYPE_CORE_INIT.
66    */
67   struct GNUNET_MessageHeader header;
68
69   /**
70    * Options, see GNUNET_CORE_OPTION_ values.
71    */
72   uint32_t options GNUNET_PACKED;
73
74 };
75
76
77 /**
78  * Message transmitted by the gnunet-service-core process
79  * to its clients in response to an INIT message.
80  */
81 struct InitReplyMessage
82 {
83
84   /**
85    * Header with type GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY
86    */
87   struct GNUNET_MessageHeader header;
88
89   /**
90    * Always zero.
91    */
92   uint32_t reserved GNUNET_PACKED;
93
94   /**
95    * Public key of the local peer.
96    */
97   struct GNUNET_PeerIdentity my_identity;
98
99 };
100
101
102 /**
103  * Message sent by the service to clients to notify them
104  * about a peer connecting.
105  */
106 struct ConnectNotifyMessage
107 {
108   /**
109    * Header with type GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT
110    */
111   struct GNUNET_MessageHeader header;
112
113   /**
114    * Number of ATS key-value pairs that follow this struct
115    * (excluding the 0-terminator).
116    */
117   uint32_t ats_count GNUNET_PACKED;
118
119   /**
120    * Identity of the connecting peer.
121    */
122   struct GNUNET_PeerIdentity peer;
123
124   /**
125    * First of the ATS information blocks (we must have at least
126    * one due to the 0-termination requirement).
127    */
128   struct GNUNET_ATS_Information ats;
129
130 };
131
132
133 /**
134  * Message sent by the service to clients to notify them
135  * about a peer changing status.
136  */
137 struct PeerStatusNotifyMessage
138 {
139   /**
140    * Header with type GNUNET_MESSAGE_TYPE_CORE_NOTIFY_PEER_STATUS
141    */
142   struct GNUNET_MessageHeader header;
143
144   /**
145    * Number of ATS key-value pairs that follow this struct
146    * (excluding the 0-terminator).
147    */
148   uint32_t ats_count GNUNET_PACKED;
149
150   /**
151    * When the peer would time out (unless we see activity)
152    */
153   struct GNUNET_TIME_AbsoluteNBO timeout;
154
155   /**
156    * Available bandwidth from the peer.
157    */
158   struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in;
159
160   /**
161    * Available bandwidth to the peer.
162    */
163   struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out;
164
165   /**
166    * Identity of the peer.
167    */
168   struct GNUNET_PeerIdentity peer;
169
170   /**
171    * First of the ATS information blocks (we must have at least
172    * one due to the 0-termination requirement).
173    */
174   struct GNUNET_ATS_Information ats;
175
176 };
177
178
179 /**
180  * Message sent by the service to clients to notify them
181  * about a peer disconnecting.
182  */
183 struct DisconnectNotifyMessage
184 {
185   /**
186    * Header with type GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT.
187    */
188   struct GNUNET_MessageHeader header;
189
190   /**
191    * Always zero.
192    */
193   uint32_t reserved GNUNET_PACKED;
194
195   /**
196    * Identity of the connecting peer.
197    */
198   struct GNUNET_PeerIdentity peer;
199
200 };
201
202
203 /**
204  * Message sent by the service to clients to notify them about
205  * messages being received or transmitted.  This overall message is
206  * followed by the real message, or just the header of the real
207  * message (depending on the client's preferences).  The receiver can
208  * tell if he got the full message or only a partial message by
209  * looking at the size field in the header of NotifyTrafficMessage and
210  * checking it with the size field in the message that follows.
211  */
212 struct NotifyTrafficMessage
213 {
214   /**
215    * Header with type GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND
216    * or GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND.
217    */
218   struct GNUNET_MessageHeader header;
219
220   /**
221    * Number of ATS key-value pairs that follow this struct
222    * (excluding the 0-terminator).
223    */
224   uint32_t ats_count GNUNET_PACKED;
225
226   /**
227    * Identity of the receiver or sender.
228    */
229   struct GNUNET_PeerIdentity peer;
230
231   /**
232    * First of the ATS information blocks (we must have at least
233    * one due to the 0-termination requirement).
234    */
235   struct GNUNET_ATS_Information ats;
236
237 };
238
239
240 /**
241  * Client notifying core about the maximum-priority
242  * message it has in the queue for a particular target.
243  */
244 struct SendMessageRequest
245 {
246   /**
247    * Header with type GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST
248    */
249   struct GNUNET_MessageHeader header;
250
251   /**
252    * How important is this message?
253    */
254   uint32_t priority GNUNET_PACKED;
255
256   /**
257    * By what time would the sender really like to see this
258    * message transmitted?
259    */
260   struct GNUNET_TIME_AbsoluteNBO deadline;
261
262   /**
263    * Identity of the intended target.
264    */
265   struct GNUNET_PeerIdentity peer;
266
267   /**
268    * How large is the client's message queue for this peer?
269    */
270   uint32_t queue_size GNUNET_PACKED;
271
272   /**
273    * How large is the message?
274    */
275   uint16_t size GNUNET_PACKED;
276
277   /**
278    * Counter for this peer to match SMRs to replies.
279    */
280   uint16_t smr_id GNUNET_PACKED;
281
282 };
283
284
285 /**
286  * Core notifying client that it is allowed to now
287  * transmit a message to the given target
288  * (response to GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST).
289  */
290 struct SendMessageReady
291 {
292   /**
293    * Header with type GNUNET_MESSAGE_TYPE_CORE_SEND_READY
294    */
295   struct GNUNET_MessageHeader header;
296
297   /**
298    * How many bytes are allowed for transmission?
299    * Guaranteed to be at least as big as the requested size,
300    * or ZERO if the request is rejected (will timeout,
301    * peer disconnected, queue full, etc.).
302    */
303   uint16_t size GNUNET_PACKED;
304
305   /**
306    * smr_id from the request.
307    */
308   uint16_t smr_id GNUNET_PACKED;
309
310   /**
311    * Identity of the intended target.
312    */
313   struct GNUNET_PeerIdentity peer;
314
315 };
316
317
318 /**
319  * Client asking core to transmit a particular message to a particular
320  * target (response to GNUNET_MESSAGE_TYPE_CORE_SEND_READY).
321  */
322 struct SendMessage
323 {
324   /**
325    * Header with type GNUNET_MESSAGE_TYPE_CORE_SEND
326    */
327   struct GNUNET_MessageHeader header;
328
329   /**
330    * How important is this message?
331    */
332   uint32_t priority GNUNET_PACKED;
333
334   /**
335    * By what time would the sender really like to see this
336    * message transmitted?
337    */
338   struct GNUNET_TIME_AbsoluteNBO deadline;
339
340   /**
341    * Identity of the receiver or sender.
342    */
343   struct GNUNET_PeerIdentity peer;
344
345   /**
346    * GNUNET_YES if corking is allowed, GNUNET_NO if not.
347    */
348   uint32_t cork GNUNET_PACKED;
349
350   /**
351    * Always 0.
352    */
353   uint64_t reserved GNUNET_PACKED;
354
355 };
356
357
358 /**
359  * Client asking core to connect to a particular target.  There is no
360  * response from the core to this type of request (however, if an
361  * actual connection is created or destroyed, be it because of this
362  * type request or not, the core generally needs to notify the
363  * clients).
364  */
365 struct ConnectMessage
366 {
367   /**
368    * Header with type GNUNET_MESSAGE_TYPE_REQUEST_CONNECT or
369    * GNUNET_MESSAGE_TYPE_REQUEST_DISCONNECT.
370    */
371   struct GNUNET_MessageHeader header;
372
373   /**
374    * For alignment.
375    */
376   uint32_t reserved GNUNET_PACKED;
377
378   /**
379    * Identity of the other peer.
380    */
381   struct GNUNET_PeerIdentity peer;
382
383 };
384
385 #endif
386 /* end of core.h */