refactor DHT for new service API
[oweals/gnunet.git] / src / cadet / cadet.h
index 757f8c5014e8044c96b678f3b446638992771647..3ff93c2547dce7c2f5539f356d4890c281949fbf 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (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.
  *
@@ -271,7 +295,7 @@ GNUNET_NETWORK_STRUCT_END
  * @return String representing FWD or BCK.
  */
 char *
-GM_f2s (int fwd);
+GC_f2s (int fwd);
 
 
 /**
@@ -283,7 +307,7 @@ GM_f2s (int fwd);
  * @return True if bigger (arg1) has a higher value than smaller (arg 2).
  */
 int
-GM_is_pid_bigger (uint32_t bigger, uint32_t smaller);
+GC_is_pid_bigger (uint32_t bigger, uint32_t smaller);
 
 
 /**
@@ -295,7 +319,7 @@ GM_is_pid_bigger (uint32_t bigger, uint32_t smaller);
  * @return Highest ACK value from the two.
  */
 uint32_t
-GM_max_pid (uint32_t a, uint32_t b);
+GC_max_pid (uint32_t a, uint32_t b);
 
 
 /**
@@ -307,7 +331,7 @@ GM_max_pid (uint32_t a, uint32_t b);
  * @return Lowest ACK value from the two.
  */
 uint32_t
-GM_min_pid (uint32_t a, uint32_t b);
+GC_min_pid (uint32_t a, uint32_t b);
 
 
 /**
@@ -319,14 +343,27 @@ GM_min_pid (uint32_t a, uint32_t b);
  * @return A HashCode containing the original 256 bit hash right-padded with 0.
  */
 const struct GNUNET_HashCode *
-GM_h2hc (const struct GNUNET_CADET_Hash *id);
+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 *
-GM_h2s (const struct GNUNET_CADET_Hash *id);
+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
@@ -339,7 +376,7 @@ GM_h2s (const struct GNUNET_CADET_Hash *id);
  * @return Human readable string description.
  */
 const char *
-GM_m2s (uint16_t m);
+GC_m2s (uint16_t m);
 
 #if 0                           /* keep Emacsens' auto-indent happy */
 {