- fixing compile error
[oweals/gnunet.git] / src / stream / stream_protocol.h
1 /*
2      This file is part of GNUnet.
3      (C) 2012 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file stream/stream_protocol.h
23  * @brief P2P protocol for the stream connections
24  * @author Sree Harsha Totakura
25  */
26
27 #ifndef STREAM_PROTOCOL_H
28 #define STREAM_PROTOCOL_H
29
30 #ifdef  __cplusplus
31 extern "C"
32 {
33 #if 0                           /* keep Emacsens' auto-indent happy */
34 }
35 #endif
36 #endif
37
38 #include "gnunet_util_lib.h"
39
40
41 /**
42  * Stream message types
43  */
44 enum GNUNET_STREAM_MessageType
45   {
46     /**
47      * Message containing data
48      */
49     GNUNET_STREAM_MESSAGE_DATA,
50
51     /**
52      * ACK message
53      */
54     GNUNET_STREAM_MESSAGE_ACK,
55
56     /**
57      * Handshake hello message
58      */
59     GNUNET_STREAM_MESSAGE_HELLO,
60
61     /**
62      * Handshake hello acknowledgement message
63      */
64     GNUNET_STREAM_MESSAGE_HELLO_ACK,
65
66     /**
67      * Reset message
68      */
69     GNUNET_STREAM_MESSAGE_RESET,
70
71     /**
72      * Transmit close message (data transmission no longer possible after this
73      * message) 
74      */
75     GNUNET_STREAM_MESSAGE_TRANSMIT_CLOSE,
76
77     /**
78      * Transmit close acknowledgement message
79      */
80     GNUNET_STREAM_MESSAGE_TRANSMIT_CLOSE_ACK,
81     
82     /**
83      * Receive close message (data is no loger read by the receiver after this
84      * message) 
85      */
86     GNUNET_STREAM_MESSAGE_RECEIVE_CLOSE,
87
88     /**
89      * Receive close acknowledgement message
90      */
91     GNUNET_STREAM_MESSAGE_RECEIVE_CLOSE_ACK,
92
93     /**
94      * Stream close message (data is no longer sent or read after this message)
95      */
96     GNUNET_STREAM_MESSAGE_CLOSE,
97
98     /**
99      * Close acknowledgement message
100      */
101     GNUNET_STREAM_MESSAGE_CLOSE_ACK
102   };
103
104
105 /**
106  * The stream message header
107  *
108  * The message can be of Data, Acknowledgement or both
109  */
110 struct GNUNET_STREAM_MessageHeader
111 {
112   /**
113    * The GNUNET message header, types are from GNUNET_MESSAGE_TYPE_STREAM_*-range.
114    */
115   struct GNUNET_MessageHeader header;
116
117   /**
118    * A number which identifies a session between the two peers.
119    */
120   uint32_t session_id;
121
122 };
123
124
125 /**
126  * The Data message, should be prefixed with stream header with its type set to
127  * GNUNET_STREAM_Data 
128  */
129 struct GNUNET_STREAM_DataMessage
130 {
131
132   /**
133    * Type is  GNUNET_MESSAGE_TYPE_STREAM_DATA 
134    */
135   struct GNUNET_STREAM_MessageHeader header;
136
137   /**
138    * number of milliseconds to the soft deadline for sending acknowledgement
139    * measured from the time this message is received. It is optimal for the
140    * communication to send the ack within the soft deadline
141    */
142   struct GNUNET_TIME_RelativeNBO ack_deadline;
143
144   /**
145    * Sequence number; starts with a random value.  (Just in case
146    * someone breaks mesh and is able to try to do a Sequence
147    * Prediction Attack on us.)
148    */
149   uint32_t sequence_number;
150
151   /**
152    * Offset of the packet in the overall stream, modulo 2^32; allows
153    * the receiver to calculate where in the destination buffer the
154    * message should be placed.
155    */
156   uint32_t offset;
157
158   /**
159    * The data should be appended here
160    */
161 };
162
163 /**
164  * The Selective Acknowledgement Bitmap
165  */
166 typedef uint64_t GNUNET_STREAM_AckBitmap;
167
168
169 /**
170  * The Acknowledgment Message to confirm receipt of DATA.
171  */
172 struct GNUNET_STREAM_AckMessage
173 {
174
175   /**
176    * Type is  GNUNET_MESSAGE_TYPE_STREAM_ACK
177    */
178   struct GNUNET_STREAM_MessageHeader header;
179
180   /**
181    * The Selective Acknowledgement Bitmap. Computed relative to the base_seq
182    * (bit n corresponds to the Data message with sequence number base_seq+n)
183    */
184   GNUNET_STREAM_AckBitmap bitmap;
185
186   /**
187    * The sequence number of the Data Message upto which the receiver has filled
188    * its buffer without any missing packets
189    */
190   uint32_t base_sequence_number;
191
192   /**
193    * Available buffer space past the last acknowledged buffer (for flow control),
194    * in bytes.
195    */
196   uint32_t receive_window_remaining;
197 };
198
199
200 /**
201  * states in the Protocol
202  */
203 enum GNUNET_STREAM_State
204   {
205     GNUNET_STREAM_STATE_INIT,
206
207     GNUNET_STREAM_STATE_LISTEN,
208
209     GNUNET_STREAM_STATE_HANDSHAKE_WAIT,
210
211     GNUNET_STREAM_STATE_ESTABLISHED,
212
213     GNUNET_STREAM_STATE_RECEIVE_CLOSE_WAIT,
214
215     GNUNET_STREAM_STATE_RECEIVE_CLOSED,
216
217     GNUNET_STREAM_STATE_TRANSMIT_CLOSE_WAIT,
218
219     GNUNET_STREAM_STATE_TRANSMIT_CLOSED,
220
221     GNUNET_STREAM_STATE_CLOSE_WAIT,
222
223     GNUNET_STREAM_STATE_CLOSED 
224   }
225
226
227 #if 0                           /** keep Emacsens' auto-indent happy */
228 {
229 #endif
230 #ifdef __cplusplus
231 }
232 #endif
233
234 #endif  /* STREAM_PROTOCOL_H */