aboutsummaryrefslogtreecommitdiff
path: root/src/stream/stream.h
blob: d9ba09f11cc2a1236aa4740c7b82c9a3dd0cdc70 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
     This file is part of GNUnet.
     (C) 2008--2013 Christian Grothoff (and other contributing authors)

     GNUnet is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published
     by the Free Software Foundation; either version 3, or (at your
     option) any later version.

     GNUnet is distributed in the hope that it will be useful, but
     WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     General Public License for more details.

     You should have received a copy of the GNU General Public License
     along with GNUnet; see the file COPYING.  If not, write to the
     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
     Boston, MA 02111-1307, USA.
*/

/**
 * @file stream/stream.h
 * @brief P2P protocol for the stream connections
 * @author Sree Harsha Totakura
 */

#ifndef STREAM_H
#define STREAM_H

#ifdef	__cplusplus
extern "C"
{
#if 0                           /* keep Emacsens' auto-indent happy */
}
#endif
#endif

#include "gnunet_util_lib.h"

GNUNET_NETWORK_STRUCT_BEGIN


/**
 * The HELLO message to begin the handshake
 */
struct GNUNET_STREAM_HelloMessage
{
  /**
   * Type is GNUNET_MESSAGE_TYPE_STREAM_HELLO
   */
  struct GNUNET_MessageHeader header;

  /**
   * The application port number
   */
  uint64_t port GNUNET_PACKED;;
};

/**
 * The Data message, should be prefixed with stream header with its type set to
 * GNUNET_STREAM_Data 
 */
struct GNUNET_STREAM_DataMessage
{

  /**
   * Type is  GNUNET_MESSAGE_TYPE_STREAM_DATA 
   */
  struct GNUNET_MessageHeader header;

  /**
   * 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 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
   */
  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
 */
typedef uint64_t GNUNET_STREAM_AckBitmap;


/**
 * The Acknowledgment Message to confirm receipt of DATA.
 */
struct GNUNET_STREAM_AckMessage
{

  /**
   * Type is  GNUNET_MESSAGE_TYPE_STREAM_ACK
   */
  struct GNUNET_MessageHeader header;

  /**
   * 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;

  /**
   * 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_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_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;
};

GNUNET_NETWORK_STRUCT_END


#if 0                           /** keep Emacsens' auto-indent happy */
{
#endif
#ifdef __cplusplus
}
#endif

#endif  /* STREAM.H */

/* End of stream.h  */