added test_stream_big to make check tests
[oweals/gnunet.git] / src / stream / stream_protocol.h
index 20dae355bb688448daef078c280e637759cbdcf0..d1c43b778ea93a41986f8f6d0a78bdcaf8cc2296 100644 (file)
@@ -35,93 +35,26 @@ extern "C"
 #endif
 #endif
 
-#include <sys/types.h>
+#include "gnunet_util_lib.h"
 
-#include "gnunet_stream_lib.h"
-#include "gnunet_mesh_service.h"
-
-
-/**
- * Stream message types
- */
-enum GNUNET_STREAM_MessageType
-  {
-    /**
-     * Message containing data
-     */
-    GNUNET_STREAM_MESSAGE_DATA,
-
-    /**
-     * ACK message
-     */
-    GNUNET_STREAM_MESSAGE_ACK,
-
-    /**
-     * Handshake hello message
-     */
-    GNUNET_STREAM_MESSAGE_HELLO,
-
-    /**
-     * Handshake hello acknowledgement message
-     */
-    GNUNET_STREAM_MESSAGE_HELLO_ACK,
-
-    /**
-     * Transmit close message (data transmission no longer possible after this
-     * message) 
-     */
-    GNUNET_STREAM_MESSAGE_TRANSMIT_CLOSE,
-
-    /**
-     * Transmit close acknowledgement message
-     */
-    GNUNET_STREAM_MESSAGE_TRANSMIT_CLOSE_ACK,
-    
-    /**
-     * Receive close message (data is no loger read by the receiver after this
-     * message) 
-     */
-    GNUNET_STREAM_MESSAGE_RECEIVE_CLOSE,
-
-    /**
-     * Receive close acknowledgement message
-     */
-    GNUNET_STREAM_MESSAGE_RECEIVE_CLOSE_ACK,
-
-    /**
-     * Stream close message (data is no longer sent or read after this message)
-     */
-    GNUNET_STREAM_MESSAGE_CLOSE,
-
-    /**
-     * Close acknowledgement message
-     */
-    GNUNET_STREAM_MESSAGE_CLOSE_ACK
-  };
+GNUNET_NETWORK_STRUCT_BEGIN
 
 
 /**
  * The stream message header
- *
- * The message can be of Data, Acknowledgement or both
+ * All messages of STREAM should commonly have this as header
  */
 struct GNUNET_STREAM_MessageHeader
 {
   /**
-   * The GNUNET message header
+   * The GNUNET message header, types are from GNUNET_MESSAGE_TYPE_STREAM_*-range.
    */
   struct GNUNET_MessageHeader header;
 
   /**
-   * A number which identifies a session
-   */
-  uint16_t session_id;
-
-  /**
-   * The message type
-   * ? Should we rather use the type field in GNUNET_MessageHeader ?
+   * A number which identifies a session between the two peers. FIXME: not needed
    */
-  enum GNUNET_STREAM_MessageType type;
+  uint32_t session_id GNUNET_PACKED;
 
 };
 
@@ -132,54 +65,126 @@ struct GNUNET_STREAM_MessageHeader
  */
 struct GNUNET_STREAM_DataMessage
 {
+
+  /**
+   * Type is  GNUNET_MESSAGE_TYPE_STREAM_DATA 
+   */
+  struct GNUNET_STREAM_MessageHeader header;
+
   /**
-   * Sequence number; Always starts with 0 and should wrap around. 
-   * Immune to Sequence Prediction Attack as we take cover under GNUNET's secure
-   * messaging
+   * Sequence number; starts with a random value.  (Just in case
+   * someone breaks mesh and is able to try to do a Sequence
+   * Prediction Attack on us.)
    */
-  uint32_t seq;
+  uint32_t sequence_number GNUNET_PACKED;
 
   /**
    * number of milliseconds to the soft deadline for sending acknowledgement
    * measured from the time this message is received. It is optimal for the
    * communication to send the ack within the soft deadline
    */
-  uint16_t ack_deadline;
+  struct GNUNET_TIME_RelativeNBO ack_deadline;
+
+  /**
+   * Offset of the packet in the overall stream, modulo 2^32; allows
+   * the receiver to calculate where in the destination buffer the
+   * message should be placed.  In network byte order.
+   */
+  uint32_t offset GNUNET_PACKED;
 
   /**
    * The data should be appended here
    */
 };
 
+
+/**
+ * Number of bits in GNUNET_STREAM_AckBitmap
+ */
+#define GNUNET_STREAM_ACK_BITMAP_BIT_LENGTH 64
+
 /**
  * The Selective Acknowledgement Bitmap
- * 
- * ? WARNING ? Possibility for Denial of Service ??
- * ? Receiver may force the sender to mantain a buffer of ~ 64*64k !??
  */
 typedef uint64_t GNUNET_STREAM_AckBitmap;
 
 
 /**
- * The Acknowledgment Message, should be prefixed with Stream Message header
- * with its type set to GNUNET_STREAM_MESSAGE_ACK
+ * The Acknowledgment Message to confirm receipt of DATA.
  */
 struct GNUNET_STREAM_AckMessage
 {
+
   /**
-   * The sequence number of the Data Message upto which the receiver has filled
-   * its buffer without any missing packets
+   * Type is  GNUNET_MESSAGE_TYPE_STREAM_ACK
    */
-  uint32_t base_seq;
+  struct GNUNET_STREAM_MessageHeader header;
 
   /**
    * The Selective Acknowledgement Bitmap. Computed relative to the base_seq
    * (bit n corresponds to the Data message with sequence number base_seq+n)
    */
-  GNUNET_STREAM_AckBitmap bitmap;
+  GNUNET_STREAM_AckBitmap bitmap GNUNET_PACKED;
+
+  /**
+   * The sequence number of the next Data Message receiver is
+   * anticipating. Data messages less than this number are received by receiver
+   */
+  uint32_t base_sequence_number GNUNET_PACKED;
+
+  /**
+   * Available buffer space past the last acknowledged buffer (for flow control),
+   * in bytes.
+   */
+  uint32_t receive_window_remaining GNUNET_PACKED;
 };
 
 
+/**
+ * Message for Acknowledging HELLO
+ */
+struct GNUNET_STREAM_HelloAckMessage
+{
+  /**
+   * The stream message header
+   */
+  struct GNUNET_STREAM_MessageHeader header;
+
+  /**
+   * The selected sequence number. Following data tranmissions from the sender
+   * start with this sequence
+   */
+  uint32_t sequence_number GNUNET_PACKED;
+
+  /**
+   * The size(in bytes) of the receive window on the peer sending this message
+   *
+   * FIXME: Remove if not needed
+   */
+  uint32_t receiver_window_size GNUNET_PACKED;
+};
+
+
+/**
+ * The Transmit close message(used to signal transmission is closed)
+ */
+struct GNUNET_STREAM_TransmitCloseMessage
+{
+  /**
+   * The stream message header
+   */
+  struct GNUNET_STREAM_MessageHeader header;
+
+  /**
+   * The last sequence number of the packet after which the transmission has
+   * ended 
+   */
+  uint32_t final_sequence_number GNUNET_PACKED;
+};
+
+GNUNET_NETWORK_STRUCT_END
+
+
 #if 0                           /** keep Emacsens' auto-indent happy */
 {
 #endif