2 This file is part of GNUnet.
3 Copyright (C) 2001 - 2011 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @author Bartlomiej Polot
31 #if 0 /* keep Emacsens' auto-indent happy */
38 #if !defined(GNUNET_CULL_LOGGING)
39 #define CADET_TIMING_START \
40 struct GNUNET_TIME_Absolute __timestamp; \
41 __timestamp = GNUNET_TIME_absolute_get()
43 #define CADET_TIMING_END \
44 struct GNUNET_TIME_Relative __duration; \
45 __duration = GNUNET_TIME_absolute_get_duration(__timestamp); \
46 LOG(GNUNET_ERROR_TYPE_INFO, \
47 " %s duration %s\n", \
49 GNUNET_STRINGS_relative_time_to_string(__duration, GNUNET_YES));
51 #define CADET_TIMING_START
52 #define CADET_TIMING_END
57 #include "gnunet_util_lib.h"
58 #include "gnunet_peer_lib.h"
59 #include "gnunet_core_service.h"
60 #include "gnunet_cadet_service.h"
61 #include "gnunet_protocols.h"
62 #include "gnunet_cadet_service.h"
64 /******************************************************************************/
65 /************************** CONSTANTS ******************************/
66 /******************************************************************************/
69 * Minimum value for channel IDs of local clients.
71 #define GNUNET_CADET_LOCAL_CHANNEL_ID_CLI 0x80000000U
76 #define HIGH_PID 0xFF000000
81 #define LOW_PID 0x00FFFFFF
85 * Test if the two PIDs (of type `uint32_t`) are in the range where we
86 * have to worry about overflows. This is the case when @a pid is
87 * large and @a max is small, useful when comparing @a pid smaller
90 #define PID_OVERFLOW(pid, max) (((pid) > HIGH_PID) && ((max) < LOW_PID))
92 /******************************************************************************/
93 /************************** MESSAGES ******************************/
94 /******************************************************************************/
96 GNUNET_NETWORK_STRUCT_BEGIN
100 * Number uniquely identifying a channel of a client.
102 struct GNUNET_CADET_ClientChannelNumber {
104 * Values for channel numbering.
105 * Local channel numbers given by the service (incoming) are
106 * smaller than #GNUNET_CADET_LOCAL_CHANNEL_ID_CLI.
107 * Local channel numbers given by the client (created) are
108 * larger than #GNUNET_CADET_LOCAL_CHANNEL_ID_CLI.
110 uint32_t channel_of_client GNUNET_PACKED;
115 * Message for a client to create and destroy channels.
117 struct GNUNET_CADET_PortMessage {
119 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN
120 * or #GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE
122 * Size: sizeof(struct GNUNET_CADET_ChannelMessage)
124 struct GNUNET_MessageHeader header;
127 * Port to open/close.
129 struct GNUNET_HashCode port GNUNET_PACKED;
134 * Message for a client to create channels.
136 struct GNUNET_CADET_LocalChannelCreateMessage {
138 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE
140 * Size: sizeof(struct GNUNET_CADET_ChannelOpenMessageMessage)
142 struct GNUNET_MessageHeader header;
145 * ID of a channel controlled by this client.
147 struct GNUNET_CADET_ClientChannelNumber ccn;
152 struct GNUNET_PeerIdentity peer;
155 * Port of the channel.
157 struct GNUNET_HashCode port;
162 uint32_t opt GNUNET_PACKED;
167 * Message for or to a client to destroy tunnel.
169 struct GNUNET_CADET_LocalChannelDestroyMessage {
171 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY
173 struct GNUNET_MessageHeader header;
176 * ID of a channel controlled by this client.
178 struct GNUNET_CADET_ClientChannelNumber ccn;
183 * Message for cadet data traffic.
185 struct GNUNET_CADET_LocalData {
187 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA
189 struct GNUNET_MessageHeader header;
194 struct GNUNET_CADET_ClientChannelNumber ccn;
197 * Priority and preferences (an enum GNUNET_MQ_PriorityPreferences)
198 * of the message in NBO.
200 uint32_t pp GNUNET_PACKED;
209 * Message to allow the client send more data to the service
210 * (always service -> client).
212 struct GNUNET_CADET_LocalAck {
214 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK
216 struct GNUNET_MessageHeader header;
219 * ID of the channel allowed to send more data.
221 struct GNUNET_CADET_ClientChannelNumber ccn;
226 * Message to inform the client about channels in the service.
228 * TODO: split into two messages!
230 struct GNUNET_CADET_LocalInfo {
232 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL or
233 * #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER
235 struct GNUNET_MessageHeader header;
238 * ID of the channel allowed to send more data.
240 struct GNUNET_CADET_ClientChannelNumber ccn;
243 * ID of the destination of the channel (can be local peer).
245 struct GNUNET_PeerIdentity peer;
250 * Message to inform the client about channels in the service.
252 struct GNUNET_CADET_RequestPathInfoMessage {
254 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH
256 struct GNUNET_MessageHeader header;
261 uint32_t resered GNUNET_PACKED;
264 * ID of the destination of the channel (can be local peer).
266 struct GNUNET_PeerIdentity peer;
271 * Message to inform the client about channels in the service.
273 struct GNUNET_CADET_ChannelInfoMessage {
275 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL.
277 struct GNUNET_MessageHeader header;
280 * Root of the channel
282 struct GNUNET_PeerIdentity root;
285 * Destination of the channel
287 struct GNUNET_PeerIdentity dest;
294 * Message to as the service about information on a channel.
296 struct GNUNET_CADET_RequestChannelInfoMessage {
298 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_CHANNEL.
300 struct GNUNET_MessageHeader header;
303 * Target of the channel.
305 struct GNUNET_PeerIdentity target;
310 * Message to inform the client about one of the paths known to the service.
312 struct GNUNET_CADET_LocalInfoPath {
314 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH.
316 struct GNUNET_MessageHeader header;
319 * Offset of the peer that was requested.
321 uint32_t off GNUNET_PACKED;
326 * Message to inform the client about one of the peers in the service.
328 struct GNUNET_CADET_LocalInfoPeers {
330 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS
332 struct GNUNET_MessageHeader header;
337 uint16_t paths GNUNET_PACKED;
340 * Do we have a tunnel toward this peer?
342 int16_t tunnel GNUNET_PACKED;
345 * Shortest known path.
347 uint32_t best_path_length GNUNET_PACKED;
350 * ID of the peer (can be local peer).
352 struct GNUNET_PeerIdentity destination;
357 * Message to inform the client about one of the tunnels in the service.
359 * TODO: split into two messages!
361 struct GNUNET_CADET_LocalInfoTunnel {
363 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL
364 * or #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS
366 struct GNUNET_MessageHeader header;
369 * Number of channels.
371 uint32_t channels GNUNET_PACKED;
374 * ID of the destination of the tunnel (can be local peer).
376 struct GNUNET_PeerIdentity destination;
379 * Number of connections.
381 uint32_t connections GNUNET_PACKED;
386 uint16_t estate GNUNET_PACKED;
391 uint16_t cstate GNUNET_PACKED;
393 /* If TUNNEL (no 'S'): struct GNUNET_CADET_ConnectionTunnelIdentifier connection_ids[connections] */
394 /* If TUNNEL (no 'S'): uint32_t channel_ids[channels] */
398 GNUNET_NETWORK_STRUCT_END
402 * @brief Translate a fwd variable into a string representation, for logging.
404 * @param fwd Is FWD? (#GNUNET_YES or #GNUNET_NO)
406 * @return String representing FWD or BCK.
413 * Check if one pid is bigger than other, accounting for overflow.
415 * @param bigger Argument that should be bigger.
416 * @param smaller Argument that should be smaller.
418 * @return True if bigger (arg1) has a higher value than smaller (arg 2).
421 GC_is_pid_bigger(uint32_t bigger, uint32_t smaller);
425 * Get the higher ACK value out of two values, taking in account overflow.
427 * @param a First ACK value.
428 * @param b Second ACK value.
430 * @return Highest ACK value from the two.
433 GC_max_pid(uint32_t a, uint32_t b);
437 * Get the lower ACK value out of two values, taking in account overflow.
439 * @param a First ACK value.
440 * @param b Second ACK value.
442 * @return Lowest ACK value from the two.
445 GC_min_pid(uint32_t a, uint32_t b);
449 * Allocate a string with a hexdump of any binary data.
451 * @param bin Arbitrary binary data.
452 * @param len Length of @a bin in bytes.
453 * @param output Where to write the output (if *output be NULL it's allocated).
455 * @return The size of the output.
458 GC_bin2s(void *bin, unsigned int len, char **output);
462 * Convert a message type into a string to help debug
464 * FIND: "#define ([^ ]+)[ ]*([0-9]+)"
465 * REPLACE: " case \2: return "\1"; break;"
467 * @param m Message type.
469 * @return Human readable string description.
474 #if 0 /* keep Emacsens' auto-indent happy */