2 This file is part of GNUnet.
3 Copyright (C) 2012 Christian Grothoff (and other contributing authors)
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. */
55 GC_is_pid_bigger (uint32_t bigger, uint32_t smaller)
57 return (GNUNET_YES == PID_OVERFLOW (smaller, bigger) ||
58 (bigger > smaller && GNUNET_NO == PID_OVERFLOW (bigger, smaller)));
63 GC_max_pid (uint32_t a, uint32_t b)
65 if (GC_is_pid_bigger(a, b))
72 GC_min_pid (uint32_t a, uint32_t b)
74 if (GC_is_pid_bigger(a, b))
80 const struct GNUNET_HashCode *
81 GC_h2hc (const struct GNUNET_CADET_Hash *id)
83 static struct GNUNET_HashCode hc;
84 memcpy (&hc, id, sizeof (*id));
91 GC_h2s (const struct GNUNET_CADET_Hash *id)
95 memcpy (s, GNUNET_h2s_full (GC_h2hc (id)), 52);
102 #if !defined(GNUNET_CULL_LOGGING)
106 static char buf[2][16];
114 * Used to mark the "payload" of a non-payload message.
121 * Request the creation of a path
123 case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE:
128 * Request the modification of an existing path
130 case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_ACK:
135 * Notify that a connection of a path is no longer valid
137 case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN:
142 * At some point, the route will spontaneously change
144 case GNUNET_MESSAGE_TYPE_CADET_PATH_CHANGED:
149 * Transport payload data.
151 case GNUNET_MESSAGE_TYPE_CADET_DATA:
156 * Confirm receipt of payload data.
158 case GNUNET_MESSAGE_TYPE_CADET_DATA_ACK:
163 * Key exchange encapsulation.
165 case GNUNET_MESSAGE_TYPE_CADET_KX:
170 * Axolotl key exchange message.
172 case GNUNET_MESSAGE_TYPE_CADET_AX_KX:
179 case GNUNET_MESSAGE_TYPE_CADET_KX_EPHEMERAL:
184 * Answer to session key challenge.
186 case GNUNET_MESSAGE_TYPE_CADET_KX_PONG:
191 * Request the destuction of a path
193 case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY:
198 * ACK for a data packet.
200 case GNUNET_MESSAGE_TYPE_CADET_ACK:
207 case GNUNET_MESSAGE_TYPE_CADET_POLL:
212 * Announce origin is still alive.
214 case GNUNET_MESSAGE_TYPE_CADET_KEEPALIVE:
219 * Connect to the cadet service, specifying subscriptions
221 case GNUNET_MESSAGE_TYPE_CADET_LOCAL_CONNECT:
226 * Ask the cadet service to create a new tunnel
228 case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_CREATE:
233 * Ask the cadet service to destroy a tunnel
235 case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY:
240 * Confirm the creation of a channel.
242 case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_ACK:
247 * Confirm the creation of a channel.
249 case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_NACK:
254 * OTR encrypted payload.
256 case GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED:
261 * Axolotl encrypted payload.
263 case GNUNET_MESSAGE_TYPE_CADET_AX:
268 * Local payload traffic
270 case GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA:
275 * Local ACK for data.
277 case GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK:
282 * Local monitoring of channels.
284 case GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNELS:
289 * Local monitoring of a channel.
291 case GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL:
296 * Local monitoring of service.
298 case GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS:
303 * Local monitoring of service.
305 case GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL:
310 * Local information about all connections of service.
312 case GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CONNECTIONS:
317 * Local information of service about a specific connection.
319 case GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CONNECTION:
324 * Local information about all peers known to the service.
326 case GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS:
331 * Local information of service about a specific peer.
333 case GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER:
338 * Traffic (net-cat style) used by the Command Line Interface.
340 case GNUNET_MESSAGE_TYPE_CADET_CLI:
347 case GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_DUMP:
352 SPRINTF (buf[idx], "%u (UNKNOWN)", m);
355 SPRINTF (buf[idx], "{%10s}", s);