session end function must include address to notify address
[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    * Always zero.
115    */
116   uint32_t reserved GNUNET_PACKED;
117
118   /**
119    * Identity of the connecting peer.
120    */
121   struct GNUNET_PeerIdentity peer;
122
123 };
124
125
126 /**
127  * Message sent by the service to clients to notify them
128  * about a peer disconnecting.
129  */
130 struct DisconnectNotifyMessage
131 {
132   /**
133    * Header with type GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT.
134    */
135   struct GNUNET_MessageHeader header;
136
137   /**
138    * Always zero.
139    */
140   uint32_t reserved GNUNET_PACKED;
141
142   /**
143    * Identity of the connecting peer.
144    */
145   struct GNUNET_PeerIdentity peer;
146
147 };
148
149
150 /**
151  * Message sent by the service to clients to notify them about
152  * messages being received or transmitted.  This overall message is
153  * followed by the real message, or just the header of the real
154  * message (depending on the client's preferences).  The receiver can
155  * tell if he got the full message or only a partial message by
156  * looking at the size field in the header of NotifyTrafficMessage and
157  * checking it with the size field in the message that follows.
158  */
159 struct NotifyTrafficMessage
160 {
161   /**
162    * Header with type GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND
163    * or GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND.
164    */
165   struct GNUNET_MessageHeader header;
166
167   /**
168    * Identity of the receiver or sender.
169    */
170   struct GNUNET_PeerIdentity peer;
171
172   /* Followed by payload (message or just header), variable size */
173 };
174
175
176 /**
177  * Client notifying core about the maximum-priority
178  * message it has in the queue for a particular target.
179  */
180 struct SendMessageRequest
181 {
182   /**
183    * Header with type #GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST
184    */
185   struct GNUNET_MessageHeader header;
186
187   /**
188    * How important is this message?
189    */
190   uint32_t priority GNUNET_PACKED;
191
192   /**
193    * By what time would the sender really like to see this
194    * message transmitted?
195    */
196   struct GNUNET_TIME_AbsoluteNBO deadline;
197
198   /**
199    * Identity of the intended target.
200    */
201   struct GNUNET_PeerIdentity peer;
202
203   /**
204    * Always zero.
205    */
206   uint32_t reserved GNUNET_PACKED;
207
208   /**
209    * How large is the message?
210    */
211   uint16_t size GNUNET_PACKED;
212
213   /**
214    * Counter for this peer to match SMRs to replies.
215    */
216   uint16_t smr_id GNUNET_PACKED;
217
218 };
219
220
221 /**
222  * Core notifying client that it is allowed to now
223  * transmit a message to the given target
224  * (response to #GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST).
225  */
226 struct SendMessageReady
227 {
228   /**
229    * Header with type #GNUNET_MESSAGE_TYPE_CORE_SEND_READY
230    */
231   struct GNUNET_MessageHeader header;
232
233   /**
234    * How many bytes are allowed for transmission?
235    * Guaranteed to be at least as big as the requested size,
236    * or ZERO if the request is rejected (will timeout,
237    * peer disconnected, queue full, etc.).
238    */
239   uint16_t size GNUNET_PACKED;
240
241   /**
242    * smr_id from the request.
243    */
244   uint16_t smr_id GNUNET_PACKED;
245
246   /**
247    * Identity of the intended target.
248    */
249   struct GNUNET_PeerIdentity peer;
250
251 };
252
253
254 /**
255  * Client asking core to transmit a particular message to a particular
256  * target (response to #GNUNET_MESSAGE_TYPE_CORE_SEND_READY).
257  */
258 struct SendMessage
259 {
260   /**
261    * Header with type #GNUNET_MESSAGE_TYPE_CORE_SEND
262    */
263   struct GNUNET_MessageHeader header;
264
265   /**
266    * How important is this message?
267    */
268   uint32_t priority GNUNET_PACKED;
269
270   /**
271    * By what time would the sender really like to see this
272    * message transmitted?
273    */
274   struct GNUNET_TIME_AbsoluteNBO deadline;
275
276   /**
277    * Identity of the intended receiver.
278    */
279   struct GNUNET_PeerIdentity peer;
280
281   /**
282    * #GNUNET_YES if corking is allowed, #GNUNET_NO if not.
283    */
284   uint32_t cork GNUNET_PACKED;
285
286   /**
287    * Always 0.
288    */
289   uint32_t reserved GNUNET_PACKED;
290
291 };
292
293
294 GNUNET_NETWORK_STRUCT_END
295 #endif
296 /* end of core.h */