-check if /dev/net/tun exists and skip test otherwise
[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  * The stream message header
43  *
44  * The message can be of Data, Acknowledgement or both
45  */
46 struct GNUNET_STREAM_MessageHeader
47 {
48   /**
49    * The GNUNET message header, types are from GNUNET_MESSAGE_TYPE_STREAM_*-range.
50    */
51   struct GNUNET_MessageHeader header;
52
53   /**
54    * A number which identifies a session between the two peers.
55    */
56   uint32_t session_id;
57
58 };
59
60
61 /**
62  * The Data message, should be prefixed with stream header with its type set to
63  * GNUNET_STREAM_Data 
64  */
65 struct GNUNET_STREAM_DataMessage
66 {
67
68   /**
69    * Type is  GNUNET_MESSAGE_TYPE_STREAM_DATA 
70    */
71   struct GNUNET_STREAM_MessageHeader header;
72
73   /**
74    * number of milliseconds to the soft deadline for sending acknowledgement
75    * measured from the time this message is received. It is optimal for the
76    * communication to send the ack within the soft deadline
77    */
78   struct GNUNET_TIME_RelativeNBO ack_deadline;
79
80   /**
81    * Sequence number; starts with a random value.  (Just in case
82    * someone breaks mesh and is able to try to do a Sequence
83    * Prediction Attack on us.)
84    */
85   uint32_t sequence_number;
86
87   /**
88    * Offset of the packet in the overall stream, modulo 2^32; allows
89    * the receiver to calculate where in the destination buffer the
90    * message should be placed.
91    */
92   uint32_t offset;
93
94   /**
95    * The data should be appended here
96    */
97 };
98
99 /**
100  * The Selective Acknowledgement Bitmap
101  */
102 typedef uint64_t GNUNET_STREAM_AckBitmap;
103
104
105 /**
106  * The Acknowledgment Message to confirm receipt of DATA.
107  */
108 struct GNUNET_STREAM_AckMessage
109 {
110
111   /**
112    * Type is  GNUNET_MESSAGE_TYPE_STREAM_ACK
113    */
114   struct GNUNET_STREAM_MessageHeader header;
115
116   /**
117    * The Selective Acknowledgement Bitmap. Computed relative to the base_seq
118    * (bit n corresponds to the Data message with sequence number base_seq+n)
119    */
120   GNUNET_STREAM_AckBitmap bitmap;
121
122   /**
123    * The sequence number of the Data Message upto which the receiver has filled
124    * its buffer without any missing packets
125    */
126   uint32_t base_sequence_number;
127
128   /**
129    * Available buffer space past the last acknowledged buffer (for flow control),
130    * in bytes.
131    */
132   uint32_t receive_window_remaining;
133 };
134
135
136 /**
137  * states in the Protocol
138  */
139 enum GNUNET_STREAM_State
140   {
141     GNUNET_STREAM_STATE_INIT,
142
143     GNUNET_STREAM_STATE_LISTEN,
144
145     GNUNET_STREAM_STATE_HANDSHAKE_WAIT,
146
147     GNUNET_STREAM_STATE_ESTABLISHED,
148
149     GNUNET_STREAM_STATE_RECEIVE_CLOSE_WAIT,
150
151     GNUNET_STREAM_STATE_RECEIVE_CLOSED,
152
153     GNUNET_STREAM_STATE_TRANSMIT_CLOSE_WAIT,
154
155     GNUNET_STREAM_STATE_TRANSMIT_CLOSED,
156
157     GNUNET_STREAM_STATE_CLOSE_WAIT,
158
159     GNUNET_STREAM_STATE_CLOSED 
160   }
161
162
163 #if 0                           /** keep Emacsens' auto-indent happy */
164 {
165 #endif
166 #ifdef __cplusplus
167 }
168 #endif
169
170 #endif  /* STREAM_PROTOCOL_H */