2 This file is part of GNUnet.
3 Copyright (C) 2012 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 * @file cadet/cadet_common.c
23 * @brief CADET helper functions
24 * @author Bartlomiej Polot
30 * @brief Translate a fwd variable into a string representation, for logging.
32 * @param fwd Is FWD? (#GNUNET_YES or #GNUNET_NO)
34 * @return String representing FWD or BCK.
39 if (GNUNET_YES == fwd)
43 else if (GNUNET_NO == fwd)
49 /* Not an error, can happen with CONNECTION_BROKEN messages. */
56 * Test if @a bigger is larger than @a smaller.
57 * Considers the case that @a bigger just overflowed
58 * and is thus tiny while @a smaller is still below
62 GC_is_pid_bigger (uint32_t bigger,
65 return (PID_OVERFLOW (smaller, bigger) ||
66 ( (bigger > smaller) &&
67 (! PID_OVERFLOW (bigger, smaller))) );
72 GC_max_pid (uint32_t a, uint32_t b)
74 if (GC_is_pid_bigger(a, b))
81 GC_min_pid (uint32_t a, uint32_t b)
83 if (GC_is_pid_bigger(a, b))
90 * Allocate a string with a hexdump of any binary data.
92 * @param bin Arbitrary binary data.
93 * @param len Length of @a bin in bytes.
94 * @param output Where to write the output (if *output be NULL it's allocated).
96 * @return The size of the output.
99 GC_bin2s (void *bin, unsigned int len, char **output)
108 *output = GNUNET_malloc (s_len);
111 for (i = 0; i < len; i++)
113 SPRINTF (&buf[2 * i], "%2X", data[i]);
115 buf[s_len - 1] = '\0';
121 #if !defined(GNUNET_CULL_LOGGING)
125 static char buf[2][16];
133 * Used to mark the "payload" of a non-payload message.
140 * Request the creation of a path
142 case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE:
147 * Request the modification of an existing path
149 case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_ACK:
154 * Notify that a connection of a path is no longer valid
156 case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN:
161 * At some point, the route will spontaneously change
163 case GNUNET_MESSAGE_TYPE_CADET_PATH_CHANGED:
168 * Transport payload data.
170 case GNUNET_MESSAGE_TYPE_CADET_DATA:
175 * Confirm receipt of payload data.
177 case GNUNET_MESSAGE_TYPE_CADET_DATA_ACK:
182 * Key exchange message.
184 case GNUNET_MESSAGE_TYPE_CADET_KX:
191 case GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED:
196 * Request the destuction of a path
198 case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY:
203 * ACK for a data packet.
205 case GNUNET_MESSAGE_TYPE_CADET_ACK:
212 case GNUNET_MESSAGE_TYPE_CADET_POLL:
217 * Announce origin is still alive.
219 case GNUNET_MESSAGE_TYPE_CADET_KEEPALIVE:
226 case GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN:
233 case GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE:
238 * Ask the cadet service to create a new tunnel
240 case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_CREATE:
245 * Ask the cadet service to destroy a tunnel
247 case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY:
252 * Confirm the creation of a channel.
254 case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_ACK:
259 * Confirm the creation of a channel.
261 case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_NACK:
266 * Local payload traffic
268 case GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA:
273 * Local ACK for data.
275 case GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK:
280 * Local monitoring of channels.
282 case GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNELS:
287 * Local monitoring of a channel.
289 case GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL:
294 * Local monitoring of service.
296 case GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS:
301 * Local monitoring of service.
303 case GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL:
308 * Local information about all connections of service.
310 case GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CONNECTIONS:
315 * Local information of service about a specific connection.
317 case GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CONNECTION:
322 * Local information about all peers known to the service.
324 case GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS:
329 * Local information of service about a specific peer.
331 case GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER:
336 * Traffic (net-cat style) used by the Command Line Interface.
338 case GNUNET_MESSAGE_TYPE_CADET_CLI:
345 case GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_DUMP:
350 * Used to mark the "payload" of a non-payload message.
358 SPRINTF (buf[idx], "{UNK: %5u}", m);
361 SPRINTF (buf[idx], "{%10s}", s);