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