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 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.
17 * @author Bartlomiej Polot
27 #if 0 /* keep Emacsens' auto-indent happy */
34 #if !defined(GNUNET_CULL_LOGGING)
35 #define CADET_TIMING_START \
36 struct GNUNET_TIME_Absolute __timestamp;\
37 __timestamp = GNUNET_TIME_absolute_get()
39 #define CADET_TIMING_END \
40 struct GNUNET_TIME_Relative __duration;\
41 __duration = GNUNET_TIME_absolute_get_duration (__timestamp);\
42 LOG (GNUNET_ERROR_TYPE_INFO, " %s duration %s\n",\
44 GNUNET_STRINGS_relative_time_to_string (__duration, GNUNET_YES));
46 #define CADET_TIMING_START
47 #define CADET_TIMING_END
52 #include "gnunet_util_lib.h"
53 #include "gnunet_peer_lib.h"
54 #include "gnunet_core_service.h"
55 #include "gnunet_cadet_service.h"
56 #include "gnunet_protocols.h"
57 #include "gnunet_cadet_service.h"
59 /******************************************************************************/
60 /************************** CONSTANTS ******************************/
61 /******************************************************************************/
64 * Minimum value for channel IDs of local clients.
66 #define GNUNET_CADET_LOCAL_CHANNEL_ID_CLI 0x80000000U
71 #define HIGH_PID 0xFF000000
76 #define LOW_PID 0x00FFFFFF
80 * Test if the two PIDs (of type `uint32_t`) are in the range where we
81 * have to worry about overflows. This is the case when @a pid is
82 * large and @a max is small, useful when comparing @a pid smaller
85 #define PID_OVERFLOW(pid, max) (((pid) > HIGH_PID) && ((max) < LOW_PID))
87 /******************************************************************************/
88 /************************** MESSAGES ******************************/
89 /******************************************************************************/
91 GNUNET_NETWORK_STRUCT_BEGIN
95 * Number uniquely identifying a channel of a client.
97 struct GNUNET_CADET_ClientChannelNumber
100 * Values for channel numbering.
101 * Local channel numbers given by the service (incoming) are
102 * smaller than #GNUNET_CADET_LOCAL_CHANNEL_ID_CLI.
103 * Local channel numbers given by the client (created) are
104 * larger than #GNUNET_CADET_LOCAL_CHANNEL_ID_CLI.
106 uint32_t channel_of_client GNUNET_PACKED;
111 * Message for a client to create and destroy channels.
113 struct GNUNET_CADET_PortMessage
116 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN
117 * or #GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE
119 * Size: sizeof(struct GNUNET_CADET_ChannelMessage)
121 struct GNUNET_MessageHeader header;
124 * Port to open/close.
126 struct GNUNET_HashCode port GNUNET_PACKED;
131 * Message for a client to create channels.
133 struct GNUNET_CADET_LocalChannelCreateMessage
136 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE
138 * Size: sizeof(struct GNUNET_CADET_ChannelOpenMessageMessage)
140 struct GNUNET_MessageHeader header;
143 * ID of a channel controlled by this client.
145 struct GNUNET_CADET_ClientChannelNumber ccn;
150 struct GNUNET_PeerIdentity peer;
153 * Port of the channel.
155 struct GNUNET_HashCode port;
160 uint32_t opt GNUNET_PACKED;
165 * Message for or to a client to destroy tunnel.
167 struct GNUNET_CADET_LocalChannelDestroyMessage
170 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY
172 struct GNUNET_MessageHeader header;
175 * ID of a channel controlled by this client.
177 struct GNUNET_CADET_ClientChannelNumber ccn;
182 * Message for cadet data traffic.
184 struct GNUNET_CADET_LocalData
187 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA
189 struct GNUNET_MessageHeader header;
194 struct GNUNET_CADET_ClientChannelNumber ccn;
203 * Message to allow the client send more data to the service
204 * (always service -> client).
206 struct GNUNET_CADET_LocalAck
209 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK
211 struct GNUNET_MessageHeader header;
214 * ID of the channel allowed to send more data.
216 struct GNUNET_CADET_ClientChannelNumber ccn;
222 * Message to inform the client about channels in the service.
224 * TODO: split into two messages!
226 struct GNUNET_CADET_LocalInfo
229 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL or
230 * #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER
232 struct GNUNET_MessageHeader header;
235 * ID of the channel allowed to send more data.
237 struct GNUNET_CADET_ClientChannelNumber ccn;
240 * ID of the destination of the channel (can be local peer).
242 struct GNUNET_PeerIdentity peer;
247 * Message to inform the client about one of the peers in the service.
249 * TODO: split into two messages!
251 struct GNUNET_CADET_LocalInfoPeer
254 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER or
255 * #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS
257 struct GNUNET_MessageHeader header;
262 uint16_t paths GNUNET_PACKED;
265 * Do we have a tunnel toward this peer?
267 int16_t tunnel GNUNET_PACKED;
270 * ID of the peer (can be local peer).
272 struct GNUNET_PeerIdentity destination;
274 /* If type == PEER (no 'S'): GNUNET_PeerIdentity paths[]
275 * (each path ends in destination) */
280 * Message to inform the client about one of the tunnels in the service.
282 * TODO: split into two messages!
284 struct GNUNET_CADET_LocalInfoTunnel
287 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL
288 * or #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS
290 struct GNUNET_MessageHeader header;
293 * Number of channels.
295 uint32_t channels GNUNET_PACKED;
298 * ID of the destination of the tunnel (can be local peer).
300 struct GNUNET_PeerIdentity destination;
303 * Number of connections.
305 uint32_t connections GNUNET_PACKED;
310 uint16_t estate GNUNET_PACKED;
315 uint16_t cstate GNUNET_PACKED;
317 /* If TUNNEL (no 'S'): struct GNUNET_CADET_ConnectionTunnelIdentifier connection_ids[connections] */
318 /* If TUNNEL (no 'S'): uint32_t channel_ids[channels] */
322 GNUNET_NETWORK_STRUCT_END
326 * @brief Translate a fwd variable into a string representation, for logging.
328 * @param fwd Is FWD? (#GNUNET_YES or #GNUNET_NO)
330 * @return String representing FWD or BCK.
337 * Check if one pid is bigger than other, accounting for overflow.
339 * @param bigger Argument that should be bigger.
340 * @param smaller Argument that should be smaller.
342 * @return True if bigger (arg1) has a higher value than smaller (arg 2).
345 GC_is_pid_bigger (uint32_t bigger, uint32_t smaller);
349 * Get the higher ACK value out of two values, taking in account overflow.
351 * @param a First ACK value.
352 * @param b Second ACK value.
354 * @return Highest ACK value from the two.
357 GC_max_pid (uint32_t a, uint32_t b);
361 * Get the lower ACK value out of two values, taking in account overflow.
363 * @param a First ACK value.
364 * @param b Second ACK value.
366 * @return Lowest ACK value from the two.
369 GC_min_pid (uint32_t a, uint32_t b);
373 * Allocate a string with a hexdump of any binary data.
375 * @param bin Arbitrary binary data.
376 * @param len Length of @a bin in bytes.
377 * @param output Where to write the output (if *output be NULL it's allocated).
379 * @return The size of the output.
388 * Convert a message type into a string to help debug
390 * FIND: "#define ([^ ]+)[ ]*([0-9]+)"
391 * REPLACE: " case \2: return "\1"; break;"
393 * @param m Message type.
395 * @return Human readable string description.
400 #if 0 /* keep Emacsens' auto-indent happy */