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_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 0x80000000
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
105 * Values for channel numbering.
106 * Local channel numbers given by the service (incoming) are
107 * smaller than #GNUNET_CADET_LOCAL_CHANNEL_ID_CLI.
108 * Local channel numbers given by the client (created) are
109 * larger than #GNUNET_CADET_LOCAL_CHANNEL_ID_CLI.
111 uint32_t channel_of_client GNUNET_PACKED;
116 * Message for a client to create and destroy channels.
118 struct GNUNET_CADET_PortMessage
121 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN
122 * or #GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE
124 * Size: sizeof(struct GNUNET_CADET_ChannelMessage)
126 struct GNUNET_MessageHeader header;
129 * Port to open/close.
131 struct GNUNET_HashCode port GNUNET_PACKED;
136 * Message for a client to create channels.
138 struct GNUNET_CADET_ChannelCreateMessageMessage
141 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_TUNNEL_CREATE
143 * Size: sizeof(struct GNUNET_CADET_ChannelCreateMessageMessage)
145 struct GNUNET_MessageHeader header;
148 * ID of a channel controlled by this client.
150 struct GNUNET_CADET_ClientChannelNumber channel_id;
155 struct GNUNET_PeerIdentity peer;
158 * Port of the channel.
160 struct GNUNET_HashCode port;
165 uint32_t opt GNUNET_PACKED;
170 * Message for a client to destroy channels.
172 struct GNUNET_CADET_ChannelDestroyMessage
175 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_TUNNEL_DESTROY
177 * Size: sizeof(struct GNUNET_CADET_ChannelDestroyMessage)
179 struct GNUNET_MessageHeader header;
182 * ID of a channel controlled by this client.
184 struct GNUNET_CADET_ClientChannelNumber channel_id;
189 * Message for cadet data traffic.
191 struct GNUNET_CADET_LocalData
194 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA
196 struct GNUNET_MessageHeader header;
201 struct GNUNET_CADET_ClientChannelNumber id;
210 * Message to allow the client send more data to the service
211 * (always service -> client).
213 struct GNUNET_CADET_LocalAck
216 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK
218 struct GNUNET_MessageHeader header;
221 * ID of the channel allowed to send more data.
223 struct GNUNET_CADET_ClientChannelNumber channel_id;
229 * Message to inform the client about channels in the service.
231 struct GNUNET_CADET_LocalInfo
234 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL or
235 * #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER
237 struct GNUNET_MessageHeader header;
240 * ID of the channel allowed to send more data.
242 struct GNUNET_CADET_ClientChannelNumber channel_id;
245 * ID of the owner of the channel (can be local peer).
247 // struct GNUNET_PeerIdentity owner;
250 * ID of the destination of the channel (can be local peer).
252 struct GNUNET_PeerIdentity peer;
257 * Message to inform the client about one of the peers in the service.
259 struct GNUNET_CADET_LocalInfoPeer
262 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER or
263 * #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS
265 struct GNUNET_MessageHeader header;
270 uint16_t paths GNUNET_PACKED;
273 * Do we have a tunnel toward this peer?
275 int16_t tunnel GNUNET_PACKED;
278 * ID of the peer (can be local peer).
280 struct GNUNET_PeerIdentity destination;
282 /* If type == PEER (no 'S'): GNUNET_PeerIdentity paths[]
283 * (each path ends in destination) */
288 * Message to inform the client about one of the tunnels in the service.
290 struct GNUNET_CADET_LocalInfoTunnel
293 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL
294 * or #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS
296 struct GNUNET_MessageHeader header;
299 * Number of channels.
301 uint32_t channels GNUNET_PACKED;
304 * ID of the destination of the tunnel (can be local peer).
306 struct GNUNET_PeerIdentity destination;
309 * Number of connections.
311 uint32_t connections GNUNET_PACKED;
316 uint16_t estate GNUNET_PACKED;
321 uint16_t cstate GNUNET_PACKED;
323 /* If TUNNEL (no 'S'): struct GNUNET_CADET_ConnectionTunnelIdentifier connection_ids[connections] */
324 /* If TUNNEL (no 'S'): uint32_t channel_ids[channels] */
328 GNUNET_NETWORK_STRUCT_END
332 * @brief Translate a fwd variable into a string representation, for logging.
334 * @param fwd Is FWD? (#GNUNET_YES or #GNUNET_NO)
336 * @return String representing FWD or BCK.
343 * Check if one pid is bigger than other, accounting for overflow.
345 * @param bigger Argument that should be bigger.
346 * @param smaller Argument that should be smaller.
348 * @return True if bigger (arg1) has a higher value than smaller (arg 2).
351 GC_is_pid_bigger (uint32_t bigger, uint32_t smaller);
355 * Get the higher ACK value out of two values, taking in account overflow.
357 * @param a First ACK value.
358 * @param b Second ACK value.
360 * @return Highest ACK value from the two.
363 GC_max_pid (uint32_t a, uint32_t b);
367 * Get the lower ACK value out of two values, taking in account overflow.
369 * @param a First ACK value.
370 * @param b Second ACK value.
372 * @return Lowest ACK value from the two.
375 GC_min_pid (uint32_t a, uint32_t b);
379 * Allocate a string with a hexdump of any binary data.
381 * @param bin Arbitrary binary data.
382 * @param len Length of @a bin in bytes.
383 * @param output Where to write the output (if *output be NULL it's allocated).
385 * @return The size of the output.
394 * Convert a message type into a string to help debug
396 * FIND: "#define ([^ ]+)[ ]*([0-9]+)"
397 * REPLACE: " case \2: return "\1"; break;"
399 * @param m Message type.
401 * @return Human readable string description.
406 #if 0 /* keep Emacsens' auto-indent happy */