2 This file is part of GNUnet.
3 (C) 2009, 2010 Christian Grothoff (and other contributing authors)
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.
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.
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.
23 * @brief common internal definitions for core service
24 * @author Christian Grothoff
27 * - bound message queue size
28 * - on disconnect from core, signal disconnect for all peers
29 * and clean up peer records
30 * - create / destroy peer records on connect/disconnect events
31 * - implement iterator API
32 * - implement re-configure API
33 * - check on peer-related events that connection is known
34 * (if not, GNUNET_break + reconnect)
35 * - handle atsi records
37 #include "gnunet_bandwidth_lib.h"
38 #include "gnunet_crypto_lib.h"
39 #include "gnunet_time_lib.h"
42 * General core debugging.
44 #define DEBUG_CORE GNUNET_NO
47 * Debugging interaction core-clients.
49 #define DEBUG_CORE_CLIENT GNUNET_NO
52 * Definition of bits in the InitMessage's options field that specify
53 * which events this client cares about. Note that inbound messages
54 * for handlers that were specifically registered are always
55 * transmitted to the client.
57 #define GNUNET_CORE_OPTION_NOTHING 0
58 #define GNUNET_CORE_OPTION_SEND_CONNECT 1
59 #define GNUNET_CORE_OPTION_SEND_DISCONNECT 2
60 #define GNUNET_CORE_OPTION_SEND_STATUS_CHANGE 4
61 #define GNUNET_CORE_OPTION_SEND_FULL_INBOUND 8
62 #define GNUNET_CORE_OPTION_SEND_HDR_INBOUND 16
63 #define GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND 32
64 #define GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND 64
68 * Message transmitted core clients to gnunet-service-core
69 * to start the interaction. This header is followed by
70 * uint16_t type values specifying which messages this
71 * client is interested in.
77 * Header with type GNUNET_MESSAGE_TYPE_CORE_INIT.
79 struct GNUNET_MessageHeader header;
82 * Options, see GNUNET_CORE_OPTION_ values.
84 uint32_t options GNUNET_PACKED;
90 * Message transmitted by the gnunet-service-core process
91 * to its clients in response to an INIT message.
93 struct InitReplyMessage
97 * Header with type GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY
99 struct GNUNET_MessageHeader header;
104 uint32_t reserved GNUNET_PACKED;
107 * Public key of the local peer.
109 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded publicKey;
115 * Message sent by the service to clients to notify them
116 * about a peer connecting.
118 struct ConnectNotifyMessage
121 * Header with type GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT
123 struct GNUNET_MessageHeader header;
126 * Number of ATS key-value pairs that follow this struct
127 * (excluding the 0-terminator).
129 uint32_t ats_count GNUNET_PACKED;
132 * Identity of the connecting peer.
134 struct GNUNET_PeerIdentity peer;
137 * First of the ATS information blocks (we must have at least
138 * one due to the 0-termination requirement).
140 struct GNUNET_TRANSPORT_ATS_Information ats;
146 * Message sent by the service to clients to notify them
147 * about a peer changing status.
149 struct PeerStatusNotifyMessage
152 * Header with type GNUNET_MESSAGE_TYPE_CORE_NOTIFY_PEER_STATUS
154 struct GNUNET_MessageHeader header;
157 * Number of ATS key-value pairs that follow this struct
158 * (excluding the 0-terminator).
160 uint32_t ats_count GNUNET_PACKED;
163 * When the peer would time out (unless we see activity)
165 struct GNUNET_TIME_AbsoluteNBO timeout;
168 * Available bandwidth from the peer.
170 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in;
173 * Available bandwidth to the peer.
175 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out;
178 * Identity of the peer.
180 struct GNUNET_PeerIdentity peer;
183 * First of the ATS information blocks (we must have at least
184 * one due to the 0-termination requirement).
186 struct GNUNET_TRANSPORT_ATS_Information ats;
192 * Message sent by the service to clients to notify them
193 * about a peer disconnecting.
195 struct DisconnectNotifyMessage
198 * Header with type GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT.
200 struct GNUNET_MessageHeader header;
205 uint32_t reserved GNUNET_PACKED;
208 * Identity of the connecting peer.
210 struct GNUNET_PeerIdentity peer;
216 * Message sent by the service to clients to notify them about
217 * messages being received or transmitted. This overall message is
218 * followed by the real message, or just the header of the real
219 * message (depending on the client's preferences). The receiver can
220 * tell if he got the full message or only a partial message by
221 * looking at the size field in the header of NotifyTrafficMessage and
222 * checking it with the size field in the message that follows.
224 struct NotifyTrafficMessage
227 * Header with type GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND
228 * or GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND.
230 struct GNUNET_MessageHeader header;
233 * Number of ATS key-value pairs that follow this struct
234 * (excluding the 0-terminator).
236 uint32_t ats_count GNUNET_PACKED;
239 * Currently observed latency.
241 struct GNUNET_TIME_RelativeNBO latency;
244 * Identity of the receiver or sender.
246 struct GNUNET_PeerIdentity peer;
249 * First of the ATS information blocks (we must have at least
250 * one due to the 0-termination requirement).
252 struct GNUNET_TRANSPORT_ATS_Information ats;
258 * Message sent to the core asking for configuration
259 * information and possibly preference changes.
261 struct RequestInfoMessage
264 * Header with type GNUNET_MESSAGE_TYPE_CORE_REQUEST_CONFIGURE
266 struct GNUNET_MessageHeader header;
271 uint32_t rim_id GNUNET_PACKED;
274 * Limit the number of bytes of outbound traffic to this
275 * peer to at most the specified amount (naturally, the
276 * amount is also limited by the receiving peer).
278 struct GNUNET_BANDWIDTH_Value32NBO limit_outbound;
281 * Number of bytes of inbound traffic to reserve, can
282 * be negative (to unreserve). NBO.
284 int32_t reserve_inbound GNUNET_PACKED;
287 * Increment the current traffic preference for the given peer by
288 * the specified amont. The traffic preference is used to determine
289 * the share of bandwidth this peer will typcially be assigned.
291 uint64_t preference_change GNUNET_PACKED;
294 * Identity of the peer being configured.
296 struct GNUNET_PeerIdentity peer;
302 * Response from the core to a "RequestInfoMessage"
303 * providing traffic status information for a peer.
305 struct ConfigurationInfoMessage
308 * Header with type GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO
310 struct GNUNET_MessageHeader header;
313 * Amount of traffic (inbound number of bytes) that was reserved in
314 * response to the configuration change request. Negative for
315 * "unreserved" bytes.
317 int32_t reserved_amount GNUNET_PACKED;
322 uint32_t rim_id GNUNET_PACKED;
325 * Available bandwidth out for this peer,
326 * 0 if we have been disconnected.
328 struct GNUNET_BANDWIDTH_Value32NBO bw_out;
331 * Current traffic preference for the peer.
332 * 0 if we have been disconnected.
337 * Identity of the peer.
339 struct GNUNET_PeerIdentity peer;
345 * Client notifying core about the maximum-priority
346 * message it has in the queue for a particular target.
348 struct SendMessageRequest
351 * Header with type GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST
353 struct GNUNET_MessageHeader header;
356 * How important is this message?
358 uint32_t priority GNUNET_PACKED;
361 * By what time would the sender really like to see this
362 * message transmitted?
364 struct GNUNET_TIME_AbsoluteNBO deadline;
367 * Identity of the intended target.
369 struct GNUNET_PeerIdentity peer;
372 * How large is the client's message queue for this peer?
374 uint32_t queue_size GNUNET_PACKED;
377 * How large is the message?
379 uint16_t size GNUNET_PACKED;
382 * Counter for this peer to match SMRs to replies.
384 uint16_t smr_id GNUNET_PACKED;
390 * Core notifying client that it is allowed to now
391 * transmit a message to the given target
392 * (response to GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST).
394 struct SendMessageReady
397 * Header with type GNUNET_MESSAGE_TYPE_CORE_SEND_READY
399 struct GNUNET_MessageHeader header;
402 * How many bytes are allowed for transmission?
403 * Guaranteed to be at least as big as the requested size,
404 * or ZERO if the request is rejected (will timeout,
405 * peer disconnected, queue full, etc.).
407 uint16_t size GNUNET_PACKED;
410 * smr_id from the request.
412 uint16_t smr_id GNUNET_PACKED;
415 * Identity of the intended target.
417 struct GNUNET_PeerIdentity peer;
423 * Client asking core to transmit a particular message to a particular
424 * target (responsde to GNUNET_MESSAGE_TYPE_CORE_SEND_READY).
429 * Header with type GNUNET_MESSAGE_TYPE_CORE_SEND
431 struct GNUNET_MessageHeader header;
434 * How important is this message?
436 uint32_t priority GNUNET_PACKED;
439 * By what time would the sender really like to see this
440 * message transmitted?
442 struct GNUNET_TIME_AbsoluteNBO deadline;
445 * Identity of the receiver or sender.
447 struct GNUNET_PeerIdentity peer;
453 * Client asking core to connect to a particular target. There is no
454 * response from the core to this type of request (however, if an
455 * actual connection is created or destroyed, be it because of this
456 * type request or not, the core generally needs to notify the
459 struct ConnectMessage
462 * Header with type GNUNET_MESSAGE_TYPE_REQUEST_CONNECT or
463 * GNUNET_MESSAGE_TYPE_REQUEST_DISCONNECT.
465 struct GNUNET_MessageHeader header;
470 uint32_t reserved GNUNET_PACKED;
475 struct GNUNET_TIME_RelativeNBO timeout;
478 * Identity of the other peer.
480 struct GNUNET_PeerIdentity peer;