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
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @author Bartlomiej Polot
32 #if 0 /* keep Emacsens' auto-indent happy */
39 #define CADET_DEBUG GNUNET_YES
42 #include "gnunet_util_lib.h"
43 #include "gnunet_peer_lib.h"
44 #include "gnunet_core_service.h"
45 #include "gnunet_protocols.h"
46 #include <gnunet_cadet_service.h>
48 /******************************************************************************/
49 /************************** CONSTANTS ******************************/
50 /******************************************************************************/
52 #define GNUNET_CADET_LOCAL_CHANNEL_ID_CLI 0x80000000
53 #define GNUNET_CADET_LOCAL_CHANNEL_ID_SERV 0xB0000000
55 #define HIGH_PID 0xFFFF0000
56 #define LOW_PID 0x0000FFFF
58 #define PID_OVERFLOW(pid, max) (pid > HIGH_PID && max < LOW_PID)
60 /******************************************************************************/
61 /************************** MESSAGES ******************************/
62 /******************************************************************************/
64 GNUNET_NETWORK_STRUCT_BEGIN
68 * Message for a client to create and destroy channels.
70 struct GNUNET_CADET_PortMessage
73 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN
74 * or #GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE
76 * Size: sizeof(struct GNUNET_CADET_ChannelMessage)
78 struct GNUNET_MessageHeader header;
83 struct GNUNET_HashCode port GNUNET_PACKED;
87 * Type for channel numbering.
88 * - Local channel numbers given by the service (incoming) are >= 0xB0000000
89 * - Local channel numbers given by the client (created) are >= 0x80000000
90 * - Global channel numbers are < 0x80000000
92 typedef uint32_t CADET_ChannelNumber;
96 * Message for a client to create channels.
98 struct GNUNET_CADET_ChannelCreateMessage
101 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_TUNNEL_CREATE
103 * Size: sizeof(struct GNUNET_CADET_ChannelCreateMessage)
105 struct GNUNET_MessageHeader header;
108 * ID of a channel controlled by this client.
110 CADET_ChannelNumber channel_id GNUNET_PACKED;
115 struct GNUNET_PeerIdentity peer;
118 * Port of the channel.
120 struct GNUNET_HashCode port;
125 uint32_t opt GNUNET_PACKED;
130 * Message for a client to destroy channels.
132 struct GNUNET_CADET_ChannelDestroyMessage
135 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_TUNNEL_DESTROY
137 * Size: sizeof(struct GNUNET_CADET_ChannelDestroyMessage)
139 struct GNUNET_MessageHeader header;
142 * ID of a channel controlled by this client.
144 CADET_ChannelNumber channel_id GNUNET_PACKED;
149 * Message for cadet data traffic.
151 struct GNUNET_CADET_LocalData
154 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA
156 struct GNUNET_MessageHeader header;
161 uint32_t id GNUNET_PACKED;
170 * Message to allow the client send more data to the service
171 * (always service -> client).
173 struct GNUNET_CADET_LocalAck
176 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK
178 struct GNUNET_MessageHeader header;
181 * ID of the channel allowed to send more data.
183 CADET_ChannelNumber channel_id GNUNET_PACKED;
189 * Message to inform the client about channels in the service.
191 struct GNUNET_CADET_LocalInfo
194 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL or
195 * #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER
197 struct GNUNET_MessageHeader header;
200 * ID of the channel allowed to send more data.
202 CADET_ChannelNumber channel_id GNUNET_PACKED;
205 * ID of the owner of the channel (can be local peer).
207 // struct GNUNET_PeerIdentity owner;
210 * ID of the destination of the channel (can be local peer).
212 struct GNUNET_PeerIdentity peer;
217 * Message to inform the client about one of the peers in the service.
219 struct GNUNET_CADET_LocalInfoPeer
222 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER or
223 * #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS
225 struct GNUNET_MessageHeader header;
230 uint16_t paths GNUNET_PACKED;
233 * Do we have a tunnel toward this peer?
235 int16_t tunnel GNUNET_PACKED;
238 * ID of the peer (can be local peer).
240 struct GNUNET_PeerIdentity destination;
242 /* If type == PEER (no 'S'): GNUNET_PeerIdentity paths[]
243 * (each path ends in destination) */
247 * Message to inform the client about one of the tunnels in the service.
249 struct GNUNET_CADET_LocalInfoTunnel
252 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL
253 * or #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS
255 struct GNUNET_MessageHeader header;
258 * Number of channels.
260 uint32_t channels GNUNET_PACKED;
263 * ID of the destination of the tunnel (can be local peer).
265 struct GNUNET_PeerIdentity destination;
268 * Number of connections.
270 uint32_t connections GNUNET_PACKED;
275 uint16_t estate GNUNET_PACKED;
280 uint16_t cstate GNUNET_PACKED;
282 /* If TUNNEL (no 'S'): GNUNET_PeerIdentity connection_ids[connections] */
283 /* If TUNNEL (no 'S'): uint32_t channel_ids[channels] */
287 GNUNET_NETWORK_STRUCT_END
291 * @brief Translate a fwd variable into a string representation, for logging.
293 * @param fwd Is FWD? (#GNUNET_YES or #GNUNET_NO)
295 * @return String representing FWD or BCK.
302 * Check if one pid is bigger than other, accounting for overflow.
304 * @param bigger Argument that should be bigger.
305 * @param smaller Argument that should be smaller.
307 * @return True if bigger (arg1) has a higher value than smaller (arg 2).
310 GC_is_pid_bigger (uint32_t bigger, uint32_t smaller);
314 * Get the higher ACK value out of two values, taking in account overflow.
316 * @param a First ACK value.
317 * @param b Second ACK value.
319 * @return Highest ACK value from the two.
322 GC_max_pid (uint32_t a, uint32_t b);
326 * Get the lower ACK value out of two values, taking in account overflow.
328 * @param a First ACK value.
329 * @param b Second ACK value.
331 * @return Lowest ACK value from the two.
334 GC_min_pid (uint32_t a, uint32_t b);
338 * Convert a 256 bit CadetHash into a 512 HashCode to use in GNUNET_h2s,
339 * multihashmap, and other HashCode-based functions.
341 * @param id A 256 bit hash to expand.
343 * @return A HashCode containing the original 256 bit hash right-padded with 0.
345 const struct GNUNET_HashCode *
346 GC_h2hc (const struct GNUNET_CADET_Hash *id);
349 * Get a string from a Cadet Hash (256 bits).
350 * WARNING: Not reentrant (based on GNUNET_h2s).
353 GC_h2s (const struct GNUNET_CADET_Hash *id);
357 * Allocate a string with a hexdump of any binary data.
359 * @param bin Arbitrary binary data.
360 * @param len Length of @a bin in bytes.
361 * @param output Where to write the output (if *output be NULL it's allocated).
363 * @return The size of the output.
366 GC_bin2s (void *bin, unsigned int len, char **output);
369 * Convert a message type into a string to help debug
371 * FIND: "#define ([^ ]+)[ ]*([0-9]+)"
372 * REPLACE: " case \2: return "\1"; break;"
374 * @param m Message type.
376 * @return Human readable string description.
381 #if 0 /* keep Emacsens' auto-indent happy */