-adding some rudimentary logging
[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_STATUS_CHANGE  4
47 #define GNUNET_CORE_OPTION_SEND_FULL_INBOUND   8
48 #define GNUNET_CORE_OPTION_SEND_HDR_INBOUND   16
49 #define GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND 32
50 #define GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND  64
51
52
53 GNUNET_NETWORK_STRUCT_BEGIN
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
126
127 /**
128  * Message sent by the service to clients to notify them
129  * about a peer changing status.
130  */
131 struct PeerStatusNotifyMessage
132 {
133   /**
134    * Header with type GNUNET_MESSAGE_TYPE_CORE_NOTIFY_PEER_STATUS
135    */
136   struct GNUNET_MessageHeader header;
137
138   /**
139    * Number of ATS key-value pairs that follow this struct
140    * (excluding the 0-terminator).
141    */
142   uint32_t ats_count GNUNET_PACKED;
143
144   /**
145    * When the peer would time out (unless we see activity)
146    */
147   struct GNUNET_TIME_AbsoluteNBO timeout;
148
149   /**
150    * Available bandwidth from the peer.
151    */
152   struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in;
153
154   /**
155    * Available bandwidth to the peer.
156    */
157   struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out;
158
159   /**
160    * Identity of the peer.
161    */
162   struct GNUNET_PeerIdentity peer;
163
164   /**
165    * First of the ATS information blocks (we must have at least
166    * one due to the 0-termination requirement).
167    */
168   struct GNUNET_ATS_Information ats;
169
170 };
171
172
173 /**
174  * Message sent by the service to clients to notify them
175  * about a peer disconnecting.
176  */
177 struct DisconnectNotifyMessage
178 {
179   /**
180    * Header with type GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT.
181    */
182   struct GNUNET_MessageHeader header;
183
184   /**
185    * Always zero.
186    */
187   uint32_t reserved GNUNET_PACKED;
188
189   /**
190    * Identity of the connecting peer.
191    */
192   struct GNUNET_PeerIdentity peer;
193
194 };
195
196
197 /**
198  * Message sent by the service to clients to notify them about
199  * messages being received or transmitted.  This overall message is
200  * followed by the real message, or just the header of the real
201  * message (depending on the client's preferences).  The receiver can
202  * tell if he got the full message or only a partial message by
203  * looking at the size field in the header of NotifyTrafficMessage and
204  * checking it with the size field in the message that follows.
205  */
206 struct NotifyTrafficMessage
207 {
208   /**
209    * Header with type GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND
210    * or GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND.
211    */
212   struct GNUNET_MessageHeader header;
213
214   /**
215    * Number of ATS key-value pairs that follow this struct
216    * (excluding the 0-terminator).
217    */
218   uint32_t ats_count GNUNET_PACKED;
219
220   /**
221    * Identity of the receiver or sender.
222    */
223   struct GNUNET_PeerIdentity peer;
224
225   /**
226    * First of the ATS information blocks (we must have at least
227    * one due to the 0-termination requirement).
228    */
229   struct GNUNET_ATS_Information ats;
230
231 };
232
233
234 /**
235  * Client notifying core about the maximum-priority
236  * message it has in the queue for a particular target.
237  */
238 struct SendMessageRequest
239 {
240   /**
241    * Header with type GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST
242    */
243   struct GNUNET_MessageHeader header;
244
245   /**
246    * How important is this message?
247    */
248   uint32_t priority GNUNET_PACKED;
249
250   /**
251    * By what time would the sender really like to see this
252    * message transmitted?
253    */
254   struct GNUNET_TIME_AbsoluteNBO deadline;
255
256   /**
257    * Identity of the intended target.
258    */
259   struct GNUNET_PeerIdentity peer;
260
261   /**
262    * How large is the client's message queue for this peer?
263    */
264   uint32_t queue_size GNUNET_PACKED;
265
266   /**
267    * How large is the message?
268    */
269   uint16_t size GNUNET_PACKED;
270
271   /**
272    * Counter for this peer to match SMRs to replies.
273    */
274   uint16_t smr_id GNUNET_PACKED;
275
276 };
277
278
279 /**
280  * Core notifying client that it is allowed to now
281  * transmit a message to the given target
282  * (response to GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST).
283  */
284 struct SendMessageReady
285 {
286   /**
287    * Header with type GNUNET_MESSAGE_TYPE_CORE_SEND_READY
288    */
289   struct GNUNET_MessageHeader header;
290
291   /**
292    * How many bytes are allowed for transmission?
293    * Guaranteed to be at least as big as the requested size,
294    * or ZERO if the request is rejected (will timeout,
295    * peer disconnected, queue full, etc.).
296    */
297   uint16_t size GNUNET_PACKED;
298
299   /**
300    * smr_id from the request.
301    */
302   uint16_t smr_id GNUNET_PACKED;
303
304   /**
305    * Identity of the intended target.
306    */
307   struct GNUNET_PeerIdentity peer;
308
309 };
310
311
312 /**
313  * Client asking core to transmit a particular message to a particular
314  * target (response to GNUNET_MESSAGE_TYPE_CORE_SEND_READY).
315  */
316 struct SendMessage
317 {
318   /**
319    * Header with type GNUNET_MESSAGE_TYPE_CORE_SEND
320    */
321   struct GNUNET_MessageHeader header;
322
323   /**
324    * How important is this message?
325    */
326   uint32_t priority GNUNET_PACKED;
327
328   /**
329    * By what time would the sender really like to see this
330    * message transmitted?
331    */
332   struct GNUNET_TIME_AbsoluteNBO deadline;
333
334   /**
335    * Identity of the receiver or sender.
336    */
337   struct GNUNET_PeerIdentity peer;
338
339   /**
340    * GNUNET_YES if corking is allowed, GNUNET_NO if not.
341    */
342   uint32_t cork GNUNET_PACKED;
343
344   /**
345    * Always 0.
346    */
347   uint64_t reserved GNUNET_PACKED;
348
349 };
350
351
352 /**
353  * Client asking core to connect to a particular target.  There is no
354  * response from the core to this type of request (however, if an
355  * actual connection is created or destroyed, be it because of this
356  * type request or not, the core generally needs to notify the
357  * clients).
358  */
359 struct ConnectMessage
360 {
361   /**
362    * Header with type GNUNET_MESSAGE_TYPE_REQUEST_CONNECT or
363    * GNUNET_MESSAGE_TYPE_REQUEST_DISCONNECT.
364    */
365   struct GNUNET_MessageHeader header;
366
367   /**
368    * For alignment.
369    */
370   uint32_t reserved GNUNET_PACKED;
371
372   /**
373    * Identity of the other peer.
374    */
375   struct GNUNET_PeerIdentity peer;
376
377 };
378 GNUNET_NETWORK_STRUCT_END
379 #endif
380 /* end of core.h */