f57d2b59782cf00c0de562912245064bf35cc2cc
[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 #include "gnunet_bandwidth_lib.h"
27 #include "gnunet_crypto_lib.h"
28 #include "gnunet_time_lib.h"
29
30 /**
31  * General core debugging.
32  */
33 #define DEBUG_CORE GNUNET_EXTRA_LOGGING
34
35 /**
36  * Debugging interaction core-clients.
37  */
38 #define DEBUG_CORE_CLIENT GNUNET_EXTRA_LOGGING
39
40 /**
41  * Definition of bits in the InitMessage's options field that specify
42  * which events this client cares about.  Note that inbound messages
43  * for handlers that were specifically registered are always
44  * transmitted to the client.
45  */
46 #define GNUNET_CORE_OPTION_NOTHING             0
47 #define GNUNET_CORE_OPTION_SEND_CONNECT        1
48 #define GNUNET_CORE_OPTION_SEND_DISCONNECT     2
49 #define GNUNET_CORE_OPTION_SEND_STATUS_CHANGE  4
50 #define GNUNET_CORE_OPTION_SEND_FULL_INBOUND   8
51 #define GNUNET_CORE_OPTION_SEND_HDR_INBOUND   16
52 #define GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND 32
53 #define GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND  64
54
55
56 /**
57  * Message transmitted core clients to gnunet-service-core
58  * to start the interaction.  This header is followed by
59  * uint16_t type values specifying which messages this
60  * client is interested in.
61  */
62 struct InitMessage
63 {
64
65   /**
66    * Header with type GNUNET_MESSAGE_TYPE_CORE_INIT.
67    */
68   struct GNUNET_MessageHeader header;
69
70   /**
71    * Options, see GNUNET_CORE_OPTION_ values.
72    */
73   uint32_t options GNUNET_PACKED;
74
75 };
76
77
78 /**
79  * Message transmitted by the gnunet-service-core process
80  * to its clients in response to an INIT message.
81  */
82 struct InitReplyMessage
83 {
84
85   /**
86    * Header with type GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY
87    */
88   struct GNUNET_MessageHeader header;
89
90   /**
91    * Always zero.
92    */
93   uint32_t reserved GNUNET_PACKED;
94
95   /**
96    * Public key of the local peer.
97    */
98   struct GNUNET_PeerIdentity my_identity;
99
100 };
101
102
103 /**
104  * Message sent by the service to clients to notify them
105  * about a peer connecting.
106  */
107 struct ConnectNotifyMessage
108 {
109   /**
110    * Header with type GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT
111    */
112   struct GNUNET_MessageHeader header;
113
114   /**
115    * Number of ATS key-value pairs that follow this struct
116    * (excluding the 0-terminator).
117    */
118   uint32_t ats_count GNUNET_PACKED;
119
120   /**
121    * Identity of the connecting peer.
122    */
123   struct GNUNET_PeerIdentity peer;
124
125   /**
126    * First of the ATS information blocks (we must have at least
127    * one due to the 0-termination requirement).
128    */
129   struct GNUNET_TRANSPORT_ATS_Information ats;
130
131 };
132
133
134 /**
135  * Message sent by the service to clients to notify them
136  * about a peer changing status.
137  */
138 struct PeerStatusNotifyMessage
139 {
140   /**
141    * Header with type GNUNET_MESSAGE_TYPE_CORE_NOTIFY_PEER_STATUS
142    */
143   struct GNUNET_MessageHeader header;
144
145   /**
146    * Number of ATS key-value pairs that follow this struct
147    * (excluding the 0-terminator).
148    */
149   uint32_t ats_count GNUNET_PACKED;
150
151   /**
152    * When the peer would time out (unless we see activity)
153    */
154   struct GNUNET_TIME_AbsoluteNBO timeout;
155
156   /**
157    * Available bandwidth from the peer.
158    */
159   struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in;
160
161   /**
162    * Available bandwidth to the peer.
163    */
164   struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out;
165
166   /**
167    * Identity of the peer.
168    */
169   struct GNUNET_PeerIdentity peer;
170
171   /**
172    * First of the ATS information blocks (we must have at least
173    * one due to the 0-termination requirement).
174    */
175   struct GNUNET_TRANSPORT_ATS_Information ats;
176
177 };
178
179
180 /**
181  * Message sent by the service to clients to notify them
182  * about a peer disconnecting.
183  */
184 struct DisconnectNotifyMessage
185 {
186   /**
187    * Header with type GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT.
188    */
189   struct GNUNET_MessageHeader header;
190
191   /**
192    * Always zero.
193    */
194   uint32_t reserved GNUNET_PACKED;
195
196   /**
197    * Identity of the connecting peer.
198    */
199   struct GNUNET_PeerIdentity peer;
200
201 };
202
203
204 /**
205  * Message sent by the service to clients to notify them about
206  * messages being received or transmitted.  This overall message is
207  * followed by the real message, or just the header of the real
208  * message (depending on the client's preferences).  The receiver can
209  * tell if he got the full message or only a partial message by
210  * looking at the size field in the header of NotifyTrafficMessage and
211  * checking it with the size field in the message that follows.
212  */
213 struct NotifyTrafficMessage
214 {
215   /**
216    * Header with type GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND
217    * or GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND.
218    */
219   struct GNUNET_MessageHeader header;
220
221   /**
222    * Number of ATS key-value pairs that follow this struct
223    * (excluding the 0-terminator).
224    */
225   uint32_t ats_count GNUNET_PACKED;
226
227   /**
228    * Identity of the receiver or sender.
229    */
230   struct GNUNET_PeerIdentity peer;
231
232   /**
233    * First of the ATS information blocks (we must have at least
234    * one due to the 0-termination requirement).
235    */
236   struct GNUNET_TRANSPORT_ATS_Information ats;
237
238 };
239
240
241 /**
242  * Message sent to the core asking for configuration
243  * information and possibly preference changes.
244  */
245 struct RequestInfoMessage
246 {
247   /**
248    * Header with type GNUNET_MESSAGE_TYPE_CORE_REQUEST_CONFIGURE
249    */
250   struct GNUNET_MessageHeader header;
251
252   /**
253    * Unique request ID.
254    */
255   uint32_t rim_id GNUNET_PACKED;
256
257   /**
258    * Reserved, always zero.
259    */
260   uint32_t reserved GNUNET_PACKED;
261
262   /**
263    * Number of bytes of inbound traffic to reserve, can
264    * be negative (to unreserve).  NBO.
265    */
266   int32_t reserve_inbound GNUNET_PACKED;
267
268   /**
269    * Increment the current traffic preference for the given peer by
270    * the specified amont.  The traffic preference is used to determine
271    * the share of bandwidth this peer will typcially be assigned.
272    */
273   uint64_t preference_change GNUNET_PACKED;
274
275   /**
276    * Identity of the peer being configured.
277    */
278   struct GNUNET_PeerIdentity peer;
279
280 };
281
282
283 /**
284  * Response from the core to a "RequestInfoMessage"
285  * providing traffic status information for a peer.
286  */
287 struct ConfigurationInfoMessage
288 {
289   /**
290    * Header with type GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO
291    */
292   struct GNUNET_MessageHeader header;
293
294   /**
295    * Amount of traffic (inbound number of bytes) that was reserved in
296    * response to the configuration change request.  Negative for
297    * "unreserved" bytes.
298    */
299   int32_t reserved_amount GNUNET_PACKED;
300
301   /**
302    * If the reservation request could not be satisfied (reserved_amount
303    * was zero), how long should the client wait until retrying? 0 if
304    * bandwidth was reserved.
305    */
306   struct GNUNET_TIME_RelativeNBO reserve_delay;
307
308   /**
309    * Unique request ID.
310    */
311   uint32_t rim_id GNUNET_PACKED;
312
313   /**
314    * Available bandwidth out for this peer,
315    * 0 if we have been disconnected.
316    */
317   struct GNUNET_BANDWIDTH_Value32NBO bw_out;
318
319   /**
320    * Current traffic preference for the peer.
321    * 0 if we have been disconnected.
322    */
323   uint64_t preference;
324
325   /**
326    * Identity of the peer.
327    */
328   struct GNUNET_PeerIdentity peer;
329
330 };
331
332
333 /**
334  * Client notifying core about the maximum-priority
335  * message it has in the queue for a particular target.
336  */
337 struct SendMessageRequest
338 {
339   /**
340    * Header with type GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST
341    */
342   struct GNUNET_MessageHeader header;
343
344   /**
345    * How important is this message?
346    */
347   uint32_t priority GNUNET_PACKED;
348
349   /**
350    * By what time would the sender really like to see this
351    * message transmitted?
352    */
353   struct GNUNET_TIME_AbsoluteNBO deadline;
354
355   /**
356    * Identity of the intended target.
357    */
358   struct GNUNET_PeerIdentity peer;
359
360   /**
361    * How large is the client's message queue for this peer?
362    */
363   uint32_t queue_size GNUNET_PACKED;
364
365   /**
366    * How large is the message?
367    */
368   uint16_t size GNUNET_PACKED;
369
370   /**
371    * Counter for this peer to match SMRs to replies.
372    */
373   uint16_t smr_id GNUNET_PACKED;
374
375 };
376
377
378 /**
379  * Core notifying client that it is allowed to now
380  * transmit a message to the given target
381  * (response to GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST).
382  */
383 struct SendMessageReady
384 {
385   /**
386    * Header with type GNUNET_MESSAGE_TYPE_CORE_SEND_READY
387    */
388   struct GNUNET_MessageHeader header;
389
390   /**
391    * How many bytes are allowed for transmission?
392    * Guaranteed to be at least as big as the requested size,
393    * or ZERO if the request is rejected (will timeout,
394    * peer disconnected, queue full, etc.).
395    */
396   uint16_t size GNUNET_PACKED;
397
398   /**
399    * smr_id from the request.
400    */
401   uint16_t smr_id GNUNET_PACKED;
402
403   /**
404    * Identity of the intended target.
405    */
406   struct GNUNET_PeerIdentity peer;
407
408 };
409
410
411 /**
412  * Client asking core to transmit a particular message to a particular
413  * target (response to GNUNET_MESSAGE_TYPE_CORE_SEND_READY).
414  */
415 struct SendMessage
416 {
417   /**
418    * Header with type GNUNET_MESSAGE_TYPE_CORE_SEND
419    */
420   struct GNUNET_MessageHeader header;
421
422   /**
423    * How important is this message?
424    */
425   uint32_t priority GNUNET_PACKED;
426
427   /**
428    * By what time would the sender really like to see this
429    * message transmitted?
430    */
431   struct GNUNET_TIME_AbsoluteNBO deadline;
432
433   /**
434    * Identity of the receiver or sender.
435    */
436   struct GNUNET_PeerIdentity peer;
437
438   /**
439    * GNUNET_YES if corking is allowed, GNUNET_NO if not.
440    */
441   uint32_t cork GNUNET_PACKED;
442
443   /**
444    * Always 0.
445    */
446   uint64_t reserved GNUNET_PACKED;
447
448 };
449
450
451 /**
452  * Client asking core to connect to a particular target.  There is no
453  * response from the core to this type of request (however, if an
454  * actual connection is created or destroyed, be it because of this
455  * type request or not, the core generally needs to notify the
456  * clients).
457  */
458 struct ConnectMessage
459 {
460   /**
461    * Header with type GNUNET_MESSAGE_TYPE_REQUEST_CONNECT or
462    * GNUNET_MESSAGE_TYPE_REQUEST_DISCONNECT.
463    */
464   struct GNUNET_MessageHeader header;
465
466   /**
467    * For alignment.
468    */
469   uint32_t reserved GNUNET_PACKED;
470
471   /**
472    * Identity of the other peer.
473    */
474   struct GNUNET_PeerIdentity peer;
475
476 };
477
478 /* end of core.h */