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