remove speed bumps
[oweals/gnunet.git] / src / core / core.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2009-2014 GNUnet e.V.
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., 51 Franklin Street, Fifth Floor,
18      Boston, MA 02110-1301, 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
47 /**
48  * Client cares about connectivity changes.
49  */
50 #define GNUNET_CORE_OPTION_SEND_STATUS_CHANGE  4
51
52 /**
53  * Client wants all inbound messages in full.
54  */
55 #define GNUNET_CORE_OPTION_SEND_FULL_INBOUND   8
56
57 /**
58  * Client just wants the 4-byte message headers of
59  * all inbound messages.
60  */
61 #define GNUNET_CORE_OPTION_SEND_HDR_INBOUND   16
62
63 /**
64  * Client wants all outbound messages in full.
65  */
66 #define GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND 32
67
68 /**
69  * Client just wants the 4-byte message headers of
70  * all outbound messages.
71  */
72 #define GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND  64
73
74
75 GNUNET_NETWORK_STRUCT_BEGIN
76
77 /**
78  * Message transmitted core clients to gnunet-service-core
79  * to start the interaction.  This header is followed by
80  * uint16_t type values specifying which messages this
81  * client is interested in.
82  */
83 struct InitMessage
84 {
85
86   /**
87    * Header with type #GNUNET_MESSAGE_TYPE_CORE_INIT.
88    */
89   struct GNUNET_MessageHeader header;
90
91   /**
92    * Options, see GNUNET_CORE_OPTION_ values.
93    */
94   uint32_t options GNUNET_PACKED;
95
96 };
97
98
99 /**
100  * Message transmitted by the gnunet-service-core process
101  * to its clients in response to an INIT message.
102  */
103 struct InitReplyMessage
104 {
105
106   /**
107    * Header with type #GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY
108    */
109   struct GNUNET_MessageHeader header;
110
111   /**
112    * Always zero.
113    */
114   uint32_t reserved GNUNET_PACKED;
115
116   /**
117    * Public key of the local peer.
118    */
119   struct GNUNET_PeerIdentity my_identity;
120
121 };
122
123
124 /**
125  * Message sent by the service to clients to notify them
126  * about a peer connecting.
127  */
128 struct ConnectNotifyMessage
129 {
130   /**
131    * Header with type #GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT
132    */
133   struct GNUNET_MessageHeader header;
134
135   /**
136    * Always zero.
137    */
138   uint32_t reserved GNUNET_PACKED;
139
140   /**
141    * Identity of the connecting peer.
142    */
143   struct GNUNET_PeerIdentity peer;
144
145 };
146
147
148 /**
149  * Message sent by the service to clients to notify them
150  * about a peer disconnecting.
151  */
152 struct DisconnectNotifyMessage
153 {
154   /**
155    * Header with type #GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT.
156    */
157   struct GNUNET_MessageHeader header;
158
159   /**
160    * Always zero.
161    */
162   uint32_t reserved GNUNET_PACKED;
163
164   /**
165    * Identity of the connecting peer.
166    */
167   struct GNUNET_PeerIdentity peer;
168
169 };
170
171
172 /**
173  * Message sent by the service to clients to notify them about
174  * messages being received or transmitted.  This overall message is
175  * followed by the real message, or just the header of the real
176  * message (depending on the client's preferences).  The receiver can
177  * tell if he got the full message or only a partial message by
178  * looking at the size field in the header of NotifyTrafficMessage and
179  * checking it with the size field in the message that follows.
180  */
181 struct NotifyTrafficMessage
182 {
183   /**
184    * Header with type #GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND
185    * or #GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND.
186    */
187   struct GNUNET_MessageHeader header;
188
189   /**
190    * Identity of the receiver or sender.
191    */
192   struct GNUNET_PeerIdentity peer;
193
194   /* Followed by payload (message or just header), variable size */
195 };
196
197
198 /**
199  * Client notifying core about the maximum-priority
200  * message it has in the queue for a particular target.
201  */
202 struct SendMessageRequest
203 {
204   /**
205    * Header with type #GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST
206    */
207   struct GNUNET_MessageHeader header;
208
209   /**
210    * How important is this message?
211    */
212   uint32_t priority GNUNET_PACKED;
213
214   /**
215    * By what time would the sender really like to see this
216    * message transmitted?
217    */
218   struct GNUNET_TIME_AbsoluteNBO deadline;
219
220   /**
221    * Identity of the intended target.
222    */
223   struct GNUNET_PeerIdentity peer;
224
225   /**
226    * Always zero.
227    */
228   uint32_t reserved GNUNET_PACKED;
229
230   /**
231    * How large is the message?
232    */
233   uint16_t size GNUNET_PACKED;
234
235   /**
236    * Counter for this peer to match SMRs to replies.
237    */
238   uint16_t smr_id GNUNET_PACKED;
239
240 };
241
242
243 /**
244  * Core notifying client that it is allowed to now
245  * transmit a message to the given target
246  * (response to #GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST).
247  */
248 struct SendMessageReady
249 {
250   /**
251    * Header with type #GNUNET_MESSAGE_TYPE_CORE_SEND_READY
252    */
253   struct GNUNET_MessageHeader header;
254
255   /**
256    * How many bytes are allowed for transmission?
257    * Guaranteed to be at least as big as the requested size,
258    * or ZERO if the request is rejected (will timeout,
259    * peer disconnected, queue full, etc.).
260    */
261   uint16_t size GNUNET_PACKED;
262
263   /**
264    * smr_id from the request.
265    */
266   uint16_t smr_id GNUNET_PACKED;
267
268   /**
269    * Identity of the intended target.
270    */
271   struct GNUNET_PeerIdentity peer;
272
273 };
274
275
276 /**
277  * Client asking core to transmit a particular message to a particular
278  * target (response to #GNUNET_MESSAGE_TYPE_CORE_SEND_READY).
279  */
280 struct SendMessage
281 {
282   /**
283    * Header with type #GNUNET_MESSAGE_TYPE_CORE_SEND
284    */
285   struct GNUNET_MessageHeader header;
286
287   /**
288    * How important is this message?
289    */
290   uint32_t priority GNUNET_PACKED;
291
292   /**
293    * By what time would the sender really like to see this
294    * message transmitted?
295    */
296   struct GNUNET_TIME_AbsoluteNBO deadline;
297
298   /**
299    * Identity of the intended receiver.
300    */
301   struct GNUNET_PeerIdentity peer;
302
303   /**
304    * #GNUNET_YES if corking is allowed, #GNUNET_NO if not.
305    */
306   uint32_t cork GNUNET_PACKED;
307
308   /**
309    * Always 0.
310    */
311   uint32_t reserved GNUNET_PACKED;
312
313 };
314
315
316 /**
317  * Message sent by the service to monitor clients to notify them
318  * about a peer changing status.
319  */
320 struct MonitorNotifyMessage
321 {
322   /**
323    * Header with type #GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY
324    */
325   struct GNUNET_MessageHeader header;
326
327   /**
328    * New peer state, an `enum GNUNET_CORE_KxState` in NBO.
329    */
330   uint32_t state GNUNET_PACKED;
331
332   /**
333    * Identity of the peer.
334    */
335   struct GNUNET_PeerIdentity peer;
336
337   /**
338    * How long will we stay in this state (if nothing else happens)?
339    */
340   struct GNUNET_TIME_AbsoluteNBO timeout;
341
342 };
343
344
345 GNUNET_NETWORK_STRUCT_END
346 #endif
347 /* end of core.h */