/*
This file is part of GNUnet.
- Copyright (C) 2001 - 2011 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2001 - 2011 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
#include <stdint.h>
-#define CADET_DEBUG GNUNET_YES
+#if !defined(GNUNET_CULL_LOGGING)
+ #define CADET_TIMING_START \
+ struct GNUNET_TIME_Absolute __timestamp;\
+ __timestamp = GNUNET_TIME_absolute_get()
+
+ #define CADET_TIMING_END \
+ struct GNUNET_TIME_Relative __duration;\
+ __duration = GNUNET_TIME_absolute_get_duration (__timestamp);\
+ LOG (GNUNET_ERROR_TYPE_INFO, " %s duration %s\n",\
+ __FUNCTION__,\
+ GNUNET_STRINGS_relative_time_to_string (__duration, GNUNET_YES));
+#else
+ #define CADET_TIMING_START
+ #define CADET_TIMING_END
+#endif
+
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_peer_lib.h"
#include "gnunet_core_service.h"
+#include "gnunet_cadet_service.h"
#include "gnunet_protocols.h"
#include <gnunet_cadet_service.h>
/************************** CONSTANTS ******************************/
/******************************************************************************/
-#define GNUNET_CADET_LOCAL_CHANNEL_ID_CLI 0x80000000
-#define GNUNET_CADET_LOCAL_CHANNEL_ID_SERV 0xB0000000
+/**
+ * Minimum value for channel IDs of local clients.
+ */
+#define GNUNET_CADET_LOCAL_CHANNEL_ID_CLI 0x80000000U
+
+/**
+ * FIXME.
+ */
+#define HIGH_PID 0xFF000000
+
+/**
+ * FIXME.
+ */
+#define LOW_PID 0x00FFFFFF
-#define HIGH_PID 0xFFFF0000
-#define LOW_PID 0x0000FFFF
-#define PID_OVERFLOW(pid, max) (pid > HIGH_PID && max < LOW_PID)
+/**
+ * Test if the two PIDs (of type `uint32_t`) are in the range where we
+ * have to worry about overflows. This is the case when @a pid is
+ * large and @a max is small, useful when comparing @a pid smaller
+ * than @a max.
+ */
+#define PID_OVERFLOW(pid, max) (((pid) > HIGH_PID) && ((max) < LOW_PID))
/******************************************************************************/
/************************** MESSAGES ******************************/
GNUNET_NETWORK_STRUCT_BEGIN
+
/**
- * Message for a client to register to the service
+ * Number uniquely identifying a channel of a client.
*/
-struct GNUNET_CADET_ClientConnect
+struct GNUNET_CADET_ClientChannelNumber
{
- /**
- * Type: GNUNET_MESSAGE_TYPE_CADET_LOCAL_CONNECT
- *
- * Size: sizeof(struct GNUNET_CADET_ClientConnect) +
- * sizeof(CADET_ApplicationType) * applications +
- * sizeof(uint16_t) * types
- */
- struct GNUNET_MessageHeader header;
- /* uint32_t list_ports[] */
+ /**
+ * Values for channel numbering.
+ * Local channel numbers given by the service (incoming) are
+ * smaller than #GNUNET_CADET_LOCAL_CHANNEL_ID_CLI.
+ * Local channel numbers given by the client (created) are
+ * larger than #GNUNET_CADET_LOCAL_CHANNEL_ID_CLI.
+ */
+ uint32_t channel_of_client GNUNET_PACKED;
};
/**
- * Type for channel numbering.
- * - Local channel numbers given by the service (incoming) are >= 0xB0000000
- * - Local channel numbers given by the client (created) are >= 0x80000000
- * - Global channel numbers are < 0x80000000
+ * Message for a client to create and destroy channels.
*/
-typedef uint32_t CADET_ChannelNumber;
+struct GNUNET_CADET_PortMessage
+{
+ /**
+ * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN
+ * or #GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE
+ *
+ * Size: sizeof(struct GNUNET_CADET_ChannelMessage)
+ */
+ struct GNUNET_MessageHeader header;
+
+ /**
+ * Port to open/close.
+ */
+ struct GNUNET_HashCode port GNUNET_PACKED;
+};
/**
- * Message for a client to create and destroy channels.
+ * Message for a client to create channels.
*/
-struct GNUNET_CADET_ChannelMessage
+struct GNUNET_CADET_LocalChannelCreateMessage
{
- /**
- * Type: GNUNET_MESSAGE_TYPE_CADET_LOCAL_TUNNEL_[CREATE|DESTROY]
- *
- * Size: sizeof(struct GNUNET_CADET_ChannelMessage)
- */
+ /**
+ * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE
+ *
+ * Size: sizeof(struct GNUNET_CADET_ChannelOpenMessageMessage)
+ */
struct GNUNET_MessageHeader header;
- /**
- * ID of a channel controlled by this client.
- */
- CADET_ChannelNumber channel_id GNUNET_PACKED;
+ /**
+ * ID of a channel controlled by this client.
+ */
+ struct GNUNET_CADET_ClientChannelNumber ccn;
- /**
- * Channel's peer
- */
+ /**
+ * Channel's peer
+ */
struct GNUNET_PeerIdentity peer;
- /**
- * Port of the channel.
- */
- uint32_t port GNUNET_PACKED;
+ /**
+ * Port of the channel.
+ */
+ struct GNUNET_HashCode port;
- /**
- * Options.
- */
+ /**
+ * Options.
+ */
uint32_t opt GNUNET_PACKED;
};
+/**
+ * Message for or to a client to destroy tunnel.
+ */
+struct GNUNET_CADET_LocalChannelDestroyMessage
+{
+ /**
+ * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY
+ */
+ struct GNUNET_MessageHeader header;
+
+ /**
+ * ID of a channel controlled by this client.
+ */
+ struct GNUNET_CADET_ClientChannelNumber ccn;
+};
+
+
/**
* Message for cadet data traffic.
*/
struct GNUNET_CADET_LocalData
{
- /**
- * Type: GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA
- */
+ /**
+ * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA
+ */
struct GNUNET_MessageHeader header;
- /**
- * ID of the channel
- */
- uint32_t id GNUNET_PACKED;
+ /**
+ * ID of the channel
+ */
+ struct GNUNET_CADET_ClientChannelNumber ccn;
- /**
- * Payload follows
- */
+ /**
+ * Payload follows
+ */
};
*/
struct GNUNET_CADET_LocalAck
{
- /**
- * Type: GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK
- */
+ /**
+ * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK
+ */
struct GNUNET_MessageHeader header;
- /**
- * ID of the channel allowed to send more data.
- */
- CADET_ChannelNumber channel_id GNUNET_PACKED;
+ /**
+ * ID of the channel allowed to send more data.
+ */
+ struct GNUNET_CADET_ClientChannelNumber ccn;
};
/**
* Message to inform the client about channels in the service.
+ *
+ * TODO: split into two messages!
*/
struct GNUNET_CADET_LocalInfo
{
/**
- * Type: GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO[_TUNNEL,_PEER]
+ * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL or
+ * #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER
*/
struct GNUNET_MessageHeader header;
/**
* ID of the channel allowed to send more data.
*/
- CADET_ChannelNumber channel_id GNUNET_PACKED;
-
- /**
- * ID of the owner of the channel (can be local peer).
- */
-// struct GNUNET_PeerIdentity owner;
+ struct GNUNET_CADET_ClientChannelNumber ccn;
/**
* ID of the destination of the channel (can be local peer).
/**
* Message to inform the client about one of the peers in the service.
+ *
+ * TODO: split into two messages!
*/
struct GNUNET_CADET_LocalInfoPeer
{
/**
- * Type: GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER[S]
+ * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER or
+ * #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS
*/
struct GNUNET_MessageHeader header;
int16_t tunnel GNUNET_PACKED;
/**
- * ID of the destination of the tunnel (can be local peer).
+ * ID of the peer (can be local peer).
*/
struct GNUNET_PeerIdentity destination;
* (each path ends in destination) */
};
+
/**
* Message to inform the client about one of the tunnels in the service.
+ *
+ * TODO: split into two messages!
*/
struct GNUNET_CADET_LocalInfoTunnel
{
/**
- * Type: GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL[S]
+ * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL
+ * or #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS
*/
struct GNUNET_MessageHeader header;
*/
uint16_t cstate GNUNET_PACKED;
- /* If TUNNEL (no 'S'): GNUNET_PeerIdentity connection_ids[connections] */
+ /* If TUNNEL (no 'S'): struct GNUNET_CADET_ConnectionTunnelIdentifier connection_ids[connections] */
/* If TUNNEL (no 'S'): uint32_t channel_ids[channels] */
};
GNUNET_NETWORK_STRUCT_END
-
/**
* @brief Translate a fwd variable into a string representation, for logging.
*
GC_min_pid (uint32_t a, uint32_t b);
-/**
- * Convert a 256 bit CadetHash into a 512 HashCode to use in GNUNET_h2s,
- * multihashmap, and other HashCode-based functions.
- *
- * @param id A 256 bit hash to expand.
- *
- * @return A HashCode containing the original 256 bit hash right-padded with 0.
- */
-const struct GNUNET_HashCode *
-GC_h2hc (const struct GNUNET_CADET_Hash *id);
-
-/**
- * Get a string from a Cadet Hash (256 bits).
- * WARNING: Not reentrant (based on GNUNET_h2s).
- */
-const char *
-GC_h2s (const struct GNUNET_CADET_Hash *id);
-
-
/**
* Allocate a string with a hexdump of any binary data.
*
* @return The size of the output.
*/
size_t
-GC_bin2s (void *bin, unsigned int len, char **output);
+GC_bin2s (void *bin,
+ unsigned int len,
+ char **output);
+
/**
* Convert a message type into a string to help debug