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 #if !defined(GNUNET_CULL_LOGGING)
40 #define CADET_TIMING_START \
41 struct GNUNET_TIME_Absolute __timestamp;\
42 __timestamp = GNUNET_TIME_absolute_get()
44 #define CADET_TIMING_END \
45 struct GNUNET_TIME_Relative __duration;\
46 __duration = GNUNET_TIME_absolute_get_duration (__timestamp);\
47 LOG (GNUNET_ERROR_TYPE_INFO, " %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_protocols.h"
61 #include <gnunet_cadet_service.h>
63 /******************************************************************************/
64 /************************** CONSTANTS ******************************/
65 /******************************************************************************/
67 #define GNUNET_CADET_LOCAL_CHANNEL_ID_CLI 0x80000000
68 #define GNUNET_CADET_LOCAL_CHANNEL_ID_SERV 0xB0000000
70 #define HIGH_PID 0xFFFF0000
71 #define LOW_PID 0x0000FFFF
73 #define PID_OVERFLOW(pid, max) (pid > HIGH_PID && max < LOW_PID)
75 /******************************************************************************/
76 /************************** MESSAGES ******************************/
77 /******************************************************************************/
79 GNUNET_NETWORK_STRUCT_BEGIN
83 * Message for a client to create and destroy channels.
85 struct GNUNET_CADET_PortMessage
88 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN
89 * or #GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE
91 * Size: sizeof(struct GNUNET_CADET_ChannelMessage)
93 struct GNUNET_MessageHeader header;
98 struct GNUNET_HashCode port GNUNET_PACKED;
102 * Type for channel numbering.
103 * - Local channel numbers given by the service (incoming) are >= 0xB0000000
104 * - Local channel numbers given by the client (created) are >= 0x80000000
105 * - Global channel numbers are < 0x80000000
107 typedef uint32_t CADET_ChannelNumber;
111 * Message for a client to create channels.
113 struct GNUNET_CADET_ChannelCreateMessage
116 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_TUNNEL_CREATE
118 * Size: sizeof(struct GNUNET_CADET_ChannelCreateMessage)
120 struct GNUNET_MessageHeader header;
123 * ID of a channel controlled by this client.
125 CADET_ChannelNumber channel_id GNUNET_PACKED;
130 struct GNUNET_PeerIdentity peer;
133 * Port of the channel.
135 struct GNUNET_HashCode port;
140 uint32_t opt GNUNET_PACKED;
145 * Message for a client to destroy channels.
147 struct GNUNET_CADET_ChannelDestroyMessage
150 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_TUNNEL_DESTROY
152 * Size: sizeof(struct GNUNET_CADET_ChannelDestroyMessage)
154 struct GNUNET_MessageHeader header;
157 * ID of a channel controlled by this client.
159 CADET_ChannelNumber channel_id GNUNET_PACKED;
164 * Message for cadet data traffic.
166 struct GNUNET_CADET_LocalData
169 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA
171 struct GNUNET_MessageHeader header;
176 uint32_t id GNUNET_PACKED;
185 * Message to allow the client send more data to the service
186 * (always service -> client).
188 struct GNUNET_CADET_LocalAck
191 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK
193 struct GNUNET_MessageHeader header;
196 * ID of the channel allowed to send more data.
198 CADET_ChannelNumber channel_id GNUNET_PACKED;
204 * Message to inform the client about channels in the service.
206 struct GNUNET_CADET_LocalInfo
209 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL or
210 * #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER
212 struct GNUNET_MessageHeader header;
215 * ID of the channel allowed to send more data.
217 CADET_ChannelNumber channel_id GNUNET_PACKED;
220 * ID of the owner of the channel (can be local peer).
222 // struct GNUNET_PeerIdentity owner;
225 * ID of the destination of the channel (can be local peer).
227 struct GNUNET_PeerIdentity peer;
232 * Message to inform the client about one of the peers in the service.
234 struct GNUNET_CADET_LocalInfoPeer
237 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER or
238 * #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS
240 struct GNUNET_MessageHeader header;
245 uint16_t paths GNUNET_PACKED;
248 * Do we have a tunnel toward this peer?
250 int16_t tunnel GNUNET_PACKED;
253 * ID of the peer (can be local peer).
255 struct GNUNET_PeerIdentity destination;
257 /* If type == PEER (no 'S'): GNUNET_PeerIdentity paths[]
258 * (each path ends in destination) */
262 * Message to inform the client about one of the tunnels in the service.
264 struct GNUNET_CADET_LocalInfoTunnel
267 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL
268 * or #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS
270 struct GNUNET_MessageHeader header;
273 * Number of channels.
275 uint32_t channels GNUNET_PACKED;
278 * ID of the destination of the tunnel (can be local peer).
280 struct GNUNET_PeerIdentity destination;
283 * Number of connections.
285 uint32_t connections GNUNET_PACKED;
290 uint16_t estate GNUNET_PACKED;
295 uint16_t cstate GNUNET_PACKED;
297 /* If TUNNEL (no 'S'): GNUNET_PeerIdentity connection_ids[connections] */
298 /* If TUNNEL (no 'S'): uint32_t channel_ids[channels] */
302 GNUNET_NETWORK_STRUCT_END
306 * @brief Translate a fwd variable into a string representation, for logging.
308 * @param fwd Is FWD? (#GNUNET_YES or #GNUNET_NO)
310 * @return String representing FWD or BCK.
317 * Check if one pid is bigger than other, accounting for overflow.
319 * @param bigger Argument that should be bigger.
320 * @param smaller Argument that should be smaller.
322 * @return True if bigger (arg1) has a higher value than smaller (arg 2).
325 GC_is_pid_bigger (uint32_t bigger, uint32_t smaller);
329 * Get the higher ACK value out of two values, taking in account overflow.
331 * @param a First ACK value.
332 * @param b Second ACK value.
334 * @return Highest ACK value from the two.
337 GC_max_pid (uint32_t a, uint32_t b);
341 * Get the lower ACK value out of two values, taking in account overflow.
343 * @param a First ACK value.
344 * @param b Second ACK value.
346 * @return Lowest ACK value from the two.
349 GC_min_pid (uint32_t a, uint32_t b);
353 * Convert a 256 bit CadetHash into a 512 HashCode to use in GNUNET_h2s,
354 * multihashmap, and other HashCode-based functions.
356 * @param id A 256 bit hash to expand.
358 * @return A HashCode containing the original 256 bit hash right-padded with 0.
360 const struct GNUNET_HashCode *
361 GC_h2hc (const struct GNUNET_CADET_Hash *id);
364 * Get a string from a Cadet Hash (256 bits).
365 * WARNING: Not reentrant (based on GNUNET_h2s).
368 GC_h2s (const struct GNUNET_CADET_Hash *id);
372 * Allocate a string with a hexdump of any binary data.
374 * @param bin Arbitrary binary data.
375 * @param len Length of @a bin in bytes.
376 * @param output Where to write the output (if *output be NULL it's allocated).
378 * @return The size of the output.
381 GC_bin2s (void *bin, unsigned int len, char **output);
384 * Convert a message type into a string to help debug
386 * FIND: "#define ([^ ]+)[ ]*([0-9]+)"
387 * REPLACE: " case \2: return "\1"; break;"
389 * @param m Message type.
391 * @return Human readable string description.
396 #if 0 /* keep Emacsens' auto-indent happy */