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/>.
20 * @author Bartlomiej Polot
30 #if 0 /* keep Emacsens' auto-indent happy */
37 #if !defined(GNUNET_CULL_LOGGING)
38 #define CADET_TIMING_START \
39 struct GNUNET_TIME_Absolute __timestamp;\
40 __timestamp = GNUNET_TIME_absolute_get()
42 #define CADET_TIMING_END \
43 struct GNUNET_TIME_Relative __duration;\
44 __duration = GNUNET_TIME_absolute_get_duration (__timestamp);\
45 LOG (GNUNET_ERROR_TYPE_INFO, " %s duration %s\n",\
47 GNUNET_STRINGS_relative_time_to_string (__duration, GNUNET_YES));
49 #define CADET_TIMING_START
50 #define CADET_TIMING_END
55 #include "gnunet_util_lib.h"
56 #include "gnunet_peer_lib.h"
57 #include "gnunet_core_service.h"
58 #include "gnunet_cadet_service.h"
59 #include "gnunet_protocols.h"
60 #include "gnunet_cadet_service.h"
62 /******************************************************************************/
63 /************************** CONSTANTS ******************************/
64 /******************************************************************************/
67 * Minimum value for channel IDs of local clients.
69 #define GNUNET_CADET_LOCAL_CHANNEL_ID_CLI 0x80000000U
74 #define HIGH_PID 0xFF000000
79 #define LOW_PID 0x00FFFFFF
83 * Test if the two PIDs (of type `uint32_t`) are in the range where we
84 * have to worry about overflows. This is the case when @a pid is
85 * large and @a max is small, useful when comparing @a pid smaller
88 #define PID_OVERFLOW(pid, max) (((pid) > HIGH_PID) && ((max) < LOW_PID))
90 /******************************************************************************/
91 /************************** MESSAGES ******************************/
92 /******************************************************************************/
94 GNUNET_NETWORK_STRUCT_BEGIN
98 * Number uniquely identifying a channel of a client.
100 struct GNUNET_CADET_ClientChannelNumber
103 * Values for channel numbering.
104 * Local channel numbers given by the service (incoming) are
105 * smaller than #GNUNET_CADET_LOCAL_CHANNEL_ID_CLI.
106 * Local channel numbers given by the client (created) are
107 * larger than #GNUNET_CADET_LOCAL_CHANNEL_ID_CLI.
109 uint32_t channel_of_client GNUNET_PACKED;
114 * Message for a client to create and destroy channels.
116 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
139 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE
141 * Size: sizeof(struct GNUNET_CADET_ChannelOpenMessageMessage)
143 struct GNUNET_MessageHeader header;
146 * ID of a channel controlled by this client.
148 struct GNUNET_CADET_ClientChannelNumber ccn;
153 struct GNUNET_PeerIdentity peer;
156 * Port of the channel.
158 struct GNUNET_HashCode port;
163 uint32_t opt GNUNET_PACKED;
168 * Message for or to a client to destroy tunnel.
170 struct GNUNET_CADET_LocalChannelDestroyMessage
173 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY
175 struct GNUNET_MessageHeader header;
178 * ID of a channel controlled by this client.
180 struct GNUNET_CADET_ClientChannelNumber ccn;
185 * Message for cadet data traffic.
187 struct GNUNET_CADET_LocalData
190 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA
192 struct GNUNET_MessageHeader header;
197 struct GNUNET_CADET_ClientChannelNumber ccn;
206 * Message to allow the client send more data to the service
207 * (always service -> client).
209 struct GNUNET_CADET_LocalAck
212 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK
214 struct GNUNET_MessageHeader header;
217 * ID of the channel allowed to send more data.
219 struct GNUNET_CADET_ClientChannelNumber ccn;
225 * Message to inform the client about channels in the service.
227 * TODO: split into two messages!
229 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 one of the peers in the service.
252 * TODO: split into two messages!
254 struct GNUNET_CADET_LocalInfoPeer
257 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER or
258 * #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS
260 struct GNUNET_MessageHeader header;
265 uint16_t paths GNUNET_PACKED;
268 * Do we have a tunnel toward this peer?
270 int16_t tunnel GNUNET_PACKED;
273 * ID of the peer (can be local peer).
275 struct GNUNET_PeerIdentity destination;
277 /* If type == PEER (no 'S'): GNUNET_PeerIdentity paths[]
278 * (each path ends in destination) */
283 * Message to inform the client about one of the tunnels in the service.
285 * TODO: split into two messages!
287 struct GNUNET_CADET_LocalInfoTunnel
290 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL
291 * or #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS
293 struct GNUNET_MessageHeader header;
296 * Number of channels.
298 uint32_t channels GNUNET_PACKED;
301 * ID of the destination of the tunnel (can be local peer).
303 struct GNUNET_PeerIdentity destination;
306 * Number of connections.
308 uint32_t connections GNUNET_PACKED;
313 uint16_t estate GNUNET_PACKED;
318 uint16_t cstate GNUNET_PACKED;
320 /* If TUNNEL (no 'S'): struct GNUNET_CADET_ConnectionTunnelIdentifier connection_ids[connections] */
321 /* If TUNNEL (no 'S'): uint32_t channel_ids[channels] */
325 GNUNET_NETWORK_STRUCT_END
329 * @brief Translate a fwd variable into a string representation, for logging.
331 * @param fwd Is FWD? (#GNUNET_YES or #GNUNET_NO)
333 * @return String representing FWD or BCK.
340 * Check if one pid is bigger than other, accounting for overflow.
342 * @param bigger Argument that should be bigger.
343 * @param smaller Argument that should be smaller.
345 * @return True if bigger (arg1) has a higher value than smaller (arg 2).
348 GC_is_pid_bigger (uint32_t bigger, uint32_t smaller);
352 * Get the higher ACK value out of two values, taking in account overflow.
354 * @param a First ACK value.
355 * @param b Second ACK value.
357 * @return Highest ACK value from the two.
360 GC_max_pid (uint32_t a, uint32_t b);
364 * Get the lower ACK value out of two values, taking in account overflow.
366 * @param a First ACK value.
367 * @param b Second ACK value.
369 * @return Lowest ACK value from the two.
372 GC_min_pid (uint32_t a, uint32_t b);
376 * Allocate a string with a hexdump of any binary data.
378 * @param bin Arbitrary binary data.
379 * @param len Length of @a bin in bytes.
380 * @param output Where to write the output (if *output be NULL it's allocated).
382 * @return The size of the output.
391 * Convert a message type into a string to help debug
393 * FIND: "#define ([^ ]+)[ ]*([0-9]+)"
394 * REPLACE: " case \2: return "\1"; break;"
396 * @param m Message type.
398 * @return Human readable string description.
403 #if 0 /* keep Emacsens' auto-indent happy */