- distribute peers equally among island nodes on SuperMUC
[oweals/gnunet.git] / src / stream / stream.h
1 /*
2      This file is part of GNUnet.
3      (C) 2008--2013 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.h
23  * @brief P2P protocol for the stream connections
24  * @author Sree Harsha Totakura
25  */
26
27 #ifndef STREAM_H
28 #define STREAM_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 GNUNET_NETWORK_STRUCT_BEGIN
41
42
43 /**
44  * The HELLO message to begin the handshake
45  */
46 struct GNUNET_STREAM_HelloMessage
47 {
48   /**
49    * Type is GNUNET_MESSAGE_TYPE_STREAM_HELLO
50    */
51   struct GNUNET_MessageHeader header;
52
53   /**
54    * The application port number
55    */
56   uint64_t port GNUNET_PACKED;;
57 };
58
59 /**
60  * The Data message, should be prefixed with stream header with its type set to
61  * GNUNET_STREAM_Data 
62  */
63 struct GNUNET_STREAM_DataMessage
64 {
65
66   /**
67    * Type is  GNUNET_MESSAGE_TYPE_STREAM_DATA 
68    */
69   struct GNUNET_MessageHeader header;
70
71   /**
72    * Sequence number; starts with a random value.  (Just in case
73    * someone breaks mesh and is able to try to do a Sequence
74    * Prediction Attack on us.)
75    */
76   uint32_t sequence_number GNUNET_PACKED;
77
78   /**
79    * number of milliseconds to the soft deadline for sending acknowledgement
80    * measured from the time this message is received. It is optimal for the
81    * communication to send the ack within the soft deadline
82    */
83   struct GNUNET_TIME_RelativeNBO ack_deadline;
84
85   /**
86    * Offset of the packet in the overall stream, modulo 2^32; allows
87    * the receiver to calculate where in the destination buffer the
88    * message should be placed.  In network byte order.
89    */
90   uint32_t offset GNUNET_PACKED;
91
92   /**
93    * The data should be appended here
94    */
95 };
96
97
98 /**
99  * Number of bits in GNUNET_STREAM_AckBitmap
100  */
101 #define GNUNET_STREAM_ACK_BITMAP_BIT_LENGTH 64
102
103 /**
104  * The Selective Acknowledgement Bitmap
105  */
106 typedef uint64_t GNUNET_STREAM_AckBitmap;
107
108
109 /**
110  * The Acknowledgment Message to confirm receipt of DATA.
111  */
112 struct GNUNET_STREAM_AckMessage
113 {
114
115   /**
116    * Type is  GNUNET_MESSAGE_TYPE_STREAM_ACK
117    */
118   struct GNUNET_MessageHeader header;
119
120   /**
121    * The sequence number of the next Data Message receiver is
122    * anticipating. Data messages less than this number are received by receiver
123    */
124   uint32_t base_sequence_number GNUNET_PACKED;
125
126   /**
127    * The Selective Acknowledgement Bitmap. Computed relative to the base_seq
128    * (bit n corresponds to the Data message with sequence number base_seq+n)
129    */
130   GNUNET_STREAM_AckBitmap bitmap GNUNET_PACKED;
131
132   /**
133    * Available buffer space past the last acknowledged buffer (for flow control),
134    * in bytes.
135    */
136   uint32_t receive_window_remaining GNUNET_PACKED;
137 };
138
139
140 /**
141  * Message for Acknowledging HELLO
142  */
143 struct GNUNET_STREAM_HelloAckMessage
144 {
145   /**
146    * The stream message header
147    */
148   struct GNUNET_MessageHeader header;
149
150   /**
151    * The selected sequence number. Following data tranmissions from the sender
152    * start with this sequence
153    */
154   uint32_t sequence_number GNUNET_PACKED;
155
156   /**
157    * The size(in bytes) of the receive window on the peer sending this message
158    *
159    * FIXME: Remove if not needed
160    */
161   uint32_t receiver_window_size GNUNET_PACKED;
162 };
163
164 GNUNET_NETWORK_STRUCT_END
165
166
167 #if 0                           /** keep Emacsens' auto-indent happy */
168 {
169 #endif
170 #ifdef __cplusplus
171 }
172 #endif
173
174 #endif  /* STREAM.H */
175
176 /* End of stream.h  */