refactor DHT for new service API
[oweals/gnunet.git] / src / cadet / cadet.h
index 72f92470e1005bd650f0b19035061056cae6e9f9..3ff93c2547dce7c2f5539f356d4890c281949fbf 100644 (file)
@@ -1,6 +1,6 @@
 /*
      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
@@ -14,8 +14,8 @@
 
      You should have received a copy of the GNU General Public License
      along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
 */
 
 /**
@@ -63,22 +63,25 @@ extern "C"
 
 GNUNET_NETWORK_STRUCT_BEGIN
 
+
 /**
- * Message for a client to register to the service
+ * Message for a client to create and destroy channels.
  */
-struct GNUNET_CADET_ClientConnect
+struct GNUNET_CADET_PortMessage
 {
-    /**
-     * Type: GNUNET_MESSAGE_TYPE_CADET_LOCAL_CONNECT
-     *
-     * Size: sizeof(struct GNUNET_CADET_ClientConnect) +
-     *       sizeof(CADET_ApplicationType) * applications +
-     *       sizeof(uint16_t) * types
-     */
+  /**
+   * 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;
-  /* uint32_t                 list_ports[]           */
-};
 
+  /**
+   * Port to open/close.
+   */
+  struct GNUNET_HashCode port GNUNET_PACKED;
+};
 
 /**
  * Type for channel numbering.
@@ -90,57 +93,76 @@ typedef uint32_t CADET_ChannelNumber;
 
 
 /**
- * Message for a client to create and destroy channels.
+ * Message for a client to create channels.
  */
-struct GNUNET_CADET_ChannelMessage
+struct GNUNET_CADET_ChannelCreateMessage
 {
-    /**
-     * Type: GNUNET_MESSAGE_TYPE_CADET_LOCAL_TUNNEL_[CREATE|DESTROY]
-     *
-     * Size: sizeof(struct GNUNET_CADET_ChannelMessage)
-     */
+  /**
+   * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_TUNNEL_CREATE
+   *
+   * Size: sizeof(struct GNUNET_CADET_ChannelCreateMessage)
+   */
   struct GNUNET_MessageHeader header;
 
-    /**
-     * ID of a channel controlled by this client.
-     */
+  /**
+   * ID of a channel controlled by this client.
+   */
   CADET_ChannelNumber channel_id GNUNET_PACKED;
 
-    /**
-     * 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 a client to destroy channels.
+ */
+struct GNUNET_CADET_ChannelDestroyMessage
+{
+  /**
+   * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_TUNNEL_DESTROY
+   *
+   * Size: sizeof(struct GNUNET_CADET_ChannelDestroyMessage)
+   */
+  struct GNUNET_MessageHeader header;
+  
+  /**
+   * ID of a channel controlled by this client.
+   */
+  CADET_ChannelNumber channel_id GNUNET_PACKED;
+};
+
+
 /**
  * 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
-     */
+  /**
+   * ID of the channel
+   */
   uint32_t id GNUNET_PACKED;
 
-    /**
-     * Payload follows
-     */
+  /**
+   * Payload follows
+   */
 };
 
 
@@ -150,14 +172,14 @@ struct GNUNET_CADET_LocalData
  */
 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.
-     */
+  /**
+   * ID of the channel allowed to send more data.
+   */
   CADET_ChannelNumber channel_id GNUNET_PACKED;
 
 };
@@ -169,7 +191,8 @@ struct GNUNET_CADET_LocalAck
 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;
 
@@ -196,7 +219,8 @@ struct GNUNET_CADET_LocalInfo
 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;
 
@@ -211,7 +235,7 @@ struct GNUNET_CADET_LocalInfoPeer
   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;
 
@@ -225,7 +249,8 @@ struct GNUNET_CADET_LocalInfoPeer
 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;
 
@@ -262,7 +287,6 @@ struct GNUNET_CADET_LocalInfoTunnel
 GNUNET_NETWORK_STRUCT_END
 
 
-
 /**
  * @brief Translate a fwd variable into a string representation, for logging.
  *
@@ -328,6 +352,19 @@ GC_h2hc (const struct GNUNET_CADET_Hash *id);
 const char *
 GC_h2s (const struct GNUNET_CADET_Hash *id);
 
+
+/**
+ * Allocate a string with a hexdump of any binary data.
+ *
+ * @param bin Arbitrary binary data.
+ * @param len Length of @a bin in bytes.
+ * @param output Where to write the output (if *output be NULL it's allocated).
+ *
+ * @return The size of the output.
+ */
+size_t
+GC_bin2s (void *bin, unsigned int len, char **output);
+
 /**
  * Convert a message type into a string to help debug
  * Generated with: