towards fixing blacklisting APIs and implementation
[oweals/gnunet.git] / src / core / core.h
1 /*
2      This file is part of GNUnet.
3      (C) 2009 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 2, 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_crypto_lib.h"
27 #include "gnunet_time_lib.h"
28
29 /**
30  * General core debugging.
31  */
32 #define DEBUG_CORE GNUNET_YES
33
34 /**
35  * Debugging interaction core-clients.
36  */
37 #define DEBUG_CORE_CLIENT GNUNET_NO
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_CONNECT        1
47 #define GNUNET_CORE_OPTION_SEND_DISCONNECT     2
48 #define GNUNET_CORE_OPTION_SEND_FULL_INBOUND   4
49 #define GNUNET_CORE_OPTION_SEND_HDR_INBOUND    8
50 #define GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND 16
51 #define GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND  32
52
53
54 /**
55  * Message transmitted core clients to gnunet-service-core
56  * to start the interaction.  This header is followed by
57  * uint16_t type values specifying which messages this
58  * client is interested in.
59  */
60 struct InitMessage
61 {
62
63   /**
64    * Header with type GNUNET_MESSAGE_TYPE_CORE_INIT.
65    */
66   struct GNUNET_MessageHeader header;
67
68   /**
69    * Options, see GNUNET_CORE_OPTION_ values.
70    */
71   uint32_t options GNUNET_PACKED;
72
73 };
74
75
76 /**
77  * Message transmitted by the gnunet-service-core process
78  * to its clients in response to an INIT message.
79  */
80 struct InitReplyMessage
81 {
82
83   /**
84    * Header with type GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY
85    */
86   struct GNUNET_MessageHeader header;
87
88   /**
89    * Always zero.
90    */
91   uint32_t reserved GNUNET_PACKED;
92
93   /**
94    * Public key of the local peer.
95    */
96   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded publicKey;
97
98 };
99
100
101 /**
102  * Message sent by the service to clients to notify them
103  * about a peer connecting or disconnecting.
104  */
105 struct ConnectNotifyMessage
106 {
107   /**
108    * Header with type GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT
109    * or GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT.
110    */
111   struct GNUNET_MessageHeader header;
112
113   /**
114    * Distance to the peer.
115    */
116   uint32_t distance GNUNET_PACKED;
117
118   /**
119    * Currently observed latency.
120    */
121   struct GNUNET_TIME_RelativeNBO latency;
122
123   /**
124    * Identity of the connecting peer.
125    */
126   struct GNUNET_PeerIdentity peer;
127
128 };
129
130
131
132 /**
133  * Message sent by the service to clients to notify them
134  * about a peer disconnecting.
135  */
136 struct DisconnectNotifyMessage
137 {
138   /**
139    * Header with type GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT.
140    */
141   struct GNUNET_MessageHeader header;
142
143   /**
144    * Always zero.
145    */
146   uint32_t reserved GNUNET_PACKED;
147
148   /**
149    * Identity of the connecting peer.
150    */
151   struct GNUNET_PeerIdentity peer;
152
153 };
154
155
156
157 /**
158  * Message sent by the service to clients to notify them about
159  * messages being received or transmitted.  This overall message is
160  * followed by the real message, or just the header of the real
161  * message (depending on the client's preferences).  The receiver can
162  * tell if he got the full message or only a partial message by
163  * looking at the size field in the header of NotifyTrafficMessage and
164  * checking it with the size field in the message that follows.
165  */
166 struct NotifyTrafficMessage
167 {
168   /**
169    * Header with type GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND
170    * or GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND.
171    */
172   struct GNUNET_MessageHeader header;
173
174   /**
175    * Distance to the peer.
176    */
177   uint32_t distance GNUNET_PACKED;
178
179   /**
180    * Currently observed latency.
181    */
182   struct GNUNET_TIME_RelativeNBO latency;
183
184   /**
185    * Identity of the receiver or sender.
186    */
187   struct GNUNET_PeerIdentity peer;
188
189 };
190
191
192 /**
193  * Message sent to the core asking for configuration
194  * information and possibly preference changes.
195  */
196 struct RequestInfoMessage
197 {
198   /**
199    * Header with type GNUNET_MESSAGE_TYPE_CORE_REQUEST_CONFIGURE
200    */
201   struct GNUNET_MessageHeader header;
202
203   /**
204    * Always zero.
205    */
206   uint32_t reserved GNUNET_PACKED;
207
208   /**
209    * Limit the number of bytes of outbound traffic to this
210    * peer to at most the specified amount (naturally, the
211    * amount is also limited by the receiving peer).
212    */
213   struct GNUNET_BANDWIDTH_Value32NBO limit_outbound;
214
215   /**
216    * Number of bytes of inbound traffic to reserve, can
217    * be negative (to unreserve).  NBO.
218    */
219   int32_t reserve_inbound GNUNET_PACKED;
220
221   /**
222    * Increment the current traffic preference for the given peer by
223    * the specified amont.  The traffic preference is used to determine
224    * the share of bandwidth this peer will typcially be assigned.
225    */
226   uint64_t preference_change GNUNET_PACKED;
227
228   /**
229    * Identity of the peer being configured.
230    */
231   struct GNUNET_PeerIdentity peer;
232
233 };
234
235
236 /**
237  * Response from the core to a "RequestInfoMessage"
238  * providing traffic status information for a peer.
239  */
240 struct ConfigurationInfoMessage
241 {
242   /**
243    * Header with type GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO
244    */
245   struct GNUNET_MessageHeader header;
246
247   /**
248    * Amount of traffic (inbound number of bytes) that was reserved in
249    * response to the configuration change request.  Negative for
250    * "unreserved" bytes.
251    */
252   int32_t reserved_amount GNUNET_PACKED;
253
254   /**
255    * Available bandwidth in for this peer.
256    * 0 if we have been disconnected.
257    */
258   struct GNUNET_BANDWIDTH_Value32NBO bw_in;
259
260   /**
261    * Available bandwidth out for this peer,
262    * 0 if we have been disconnected.
263    */
264   struct GNUNET_BANDWIDTH_Value32NBO bw_out;
265
266   /**
267    * Current traffic preference for the peer.
268    * 0 if we have been disconnected.
269    */
270   uint64_t preference;
271
272   /**
273    * Identity of the receiver or sender.
274    */
275   struct GNUNET_PeerIdentity peer;
276
277 };
278
279
280 /**
281  * Client asking core to transmit a particular message to
282  * a particular target.  
283  */
284 struct SendMessage
285 {
286   /**
287    * Header with type GNUNET_MESSAGE_TYPE_CORE_SEND
288    */
289   struct GNUNET_MessageHeader header;
290
291   /**
292    * How important is this message?
293    */
294   uint32_t priority GNUNET_PACKED;
295
296   /**
297    * By what time would the sender really like to see this
298    * message transmitted?
299    */
300   struct GNUNET_TIME_AbsoluteNBO deadline;
301
302   /**
303    * Identity of the receiver or sender.
304    */
305   struct GNUNET_PeerIdentity peer;
306
307 };
308
309
310 /**
311  * Client asking core to connect to a particular target.  There is no
312  * response from the core to this type of request (however, if an
313  * actual connection is created or destroyed, be it because of this
314  * type request or not, the core generally needs to notify the
315  * clients).
316  */
317 struct ConnectMessage
318 {
319   /**
320    * Header with type GNUNET_MESSAGE_TYPE_REQUEST_CONNECT or
321    * GNUNET_MESSAGE_TYPE_REQUEST_DISCONNECT.
322    */
323   struct GNUNET_MessageHeader header;
324
325   /**
326    * For alignment.
327    */
328   uint32_t reserved GNUNET_PACKED;
329
330   /**
331    * When to time out.
332    */
333   struct GNUNET_TIME_RelativeNBO timeout;
334
335   /**
336    * Identity of the other peer.
337    */
338   struct GNUNET_PeerIdentity peer;
339
340 };
341
342 /* end of core.h */