-sane defaults
[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 <sys/types.h>
39
40 #include "gnunet_stream_lib.h"
41 #include "gnunet_mesh_service.h"
42
43
44 /**
45  * Stream message types
46  */
47 enum GNUNET_STREAM_MessageType
48   {
49     /**
50      * Message containing data
51      */
52     GNUNET_STREAM_MESSAGE_DATA,
53
54     /**
55      * ACK message
56      */
57     GNUNET_STREAM_MESSAGE_ACK,
58
59     /**
60      * Handshake hello message
61      */
62     GNUNET_STREAM_MESSAGE_HELLO,
63
64     /**
65      * Handshake hello acknowledgement message
66      */
67     GNUNET_STREAM_MESSAGE_HELLO_ACK,
68
69     /**
70      * Reset message
71      */
72     GNUNET_STREAM_MESSAGE_RESET,
73
74     /**
75      * Transmit close message (data transmission no longer possible after this
76      * message) 
77      */
78     GNUNET_STREAM_MESSAGE_TRANSMIT_CLOSE,
79
80     /**
81      * Transmit close acknowledgement message
82      */
83     GNUNET_STREAM_MESSAGE_TRANSMIT_CLOSE_ACK,
84     
85     /**
86      * Receive close message (data is no loger read by the receiver after this
87      * message) 
88      */
89     GNUNET_STREAM_MESSAGE_RECEIVE_CLOSE,
90
91     /**
92      * Receive close acknowledgement message
93      */
94     GNUNET_STREAM_MESSAGE_RECEIVE_CLOSE_ACK,
95
96     /**
97      * Stream close message (data is no longer sent or read after this message)
98      */
99     GNUNET_STREAM_MESSAGE_CLOSE,
100
101     /**
102      * Close acknowledgement message
103      */
104     GNUNET_STREAM_MESSAGE_CLOSE_ACK
105   };
106
107
108 /**
109  * The stream message header
110  *
111  * The message can be of Data, Acknowledgement or both
112  */
113 struct GNUNET_STREAM_MessageHeader
114 {
115   /**
116    * The GNUNET message header
117    */
118   struct GNUNET_MessageHeader header;
119
120   /**
121    * A number which identifies a session
122    */
123   uint16_t session_id;
124
125   /**
126    * The message type
127    * ? Should we rather use the type field in GNUNET_MessageHeader ?
128    */
129   enum GNUNET_STREAM_MessageType type;
130
131 };
132
133
134 /**
135  * The Data message, should be prefixed with stream header with its type set to
136  * GNUNET_STREAM_Data 
137  */
138 struct GNUNET_STREAM_DataMessage
139 {
140   /**
141    * Sequence number; Always starts with 0 and should wrap around. 
142    * Immune to Sequence Prediction Attack as we take cover under GNUNET's secure
143    * messaging
144    */
145   uint32_t seq;
146
147   /**
148    * number of milliseconds to the soft deadline for sending acknowledgement
149    * measured from the time this message is received. It is optimal for the
150    * communication to send the ack within the soft deadline
151    */
152   uint16_t ack_deadline;
153
154   /**
155    * The data should be appended here
156    */
157 };
158
159 /**
160  * The Selective Acknowledgement Bitmap
161  * 
162  * ? WARNING ? Possibility for Denial of Service ??
163  * ? Receiver may force the sender to mantain a buffer of ~ 64*64k !??
164  */
165 typedef uint64_t GNUNET_STREAM_AckBitmap;
166
167
168 /**
169  * The Acknowledgment Message, should be prefixed with Stream Message header
170  * with its type set to GNUNET_STREAM_MESSAGE_ACK
171  */
172 struct GNUNET_STREAM_AckMessage
173 {
174   /**
175    * The sequence number of the Data Message upto which the receiver has filled
176    * its buffer without any missing packets
177    */
178   uint32_t base_seq;
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
188 /**
189  * Various states in the Protocol
190  */
191 enum GNUNET_STREAM_ProtocolState
192   {
193     GNUNET_STREAM_PROTOCOL_INIT,
194
195     GNUNET_STREAM_PROTOCOL_LISTEN,
196
197     GNUNET_STREAM_PROTOCOL_HANDSHAKE_WAIT,
198
199     GNUNET_STREAM_PROTOCOL_DATA_WAIT,
200
201     GNUNET_STREAM_PROTOCOL_READ_CLOSE_WAIT,
202
203     GNUNET_STREAM_PROTOCOL_WRITE_CLOSE_WAIT,
204
205     GNUNET_STREAM_PROTOCOL_CLOSE_WAIT
206     
207   }
208
209
210 #if 0                           /** keep Emacsens' auto-indent happy */
211 {
212 #endif
213 #ifdef __cplusplus
214 }
215 #endif
216
217 #endif  /* STREAM_PROTOCOL_H */