This repository has been archived by the owner on May 11, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
udpc-protoc.h
180 lines (144 loc) · 4.05 KB
/
udpc-protoc.h
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
177
178
179
180
#ifndef UDPC_PROTOC_H
#define UDPC_PROTOC_H
#include "udpcast.h"
#define MAX_BLOCK_SIZE 1456
#define MAX_FEC_INTERLEAVE 256
/**
* This file describes the UDPCast protocol
*/
enum opCode {
/* Receiver to sender */
CMD_OK, /* all is ok, no need to retransmit anything */
CMD_RETRANSMIT, /* receiver asks for some data to be retransmitted */
CMD_GO, /* receiver tells server to start */
CMD_CONNECT_REQ, /* receiver tries to find out server's address */
CMD_DISCONNECT, /* receiver wants to disconnect itself */
CMD_UNUSED, /* obsolete version of CMD_HELLO, dating back to the
* time when we had little endianness (PC). This
* opcode contained a long unnoticed bug with parsing of
* blocksize */
/* Sender to receiver */
CMD_REQACK, /* server request acknowledgments from receiver */
CMD_CONNECT_REPLY, /* receiver tries to find out server's address */
CMD_DATA, /* a block of data */
#ifdef BB_FEATURE_UDPCAST_FEC
CMD_FEC, /* a forward-error-correction block */
#endif
CMD_HELLO_NEW, /* sender says he's up */
};
/* Sender says he's up. This is not in the enum with the others,
* because of some endianness Snafu in early versions. However,since
* 2005-12-23, new receivers now understand a CMD_HELLO_NEW which is
* in sequence. Once enough of those are out in the field, we'll send
* CMD_HELLO_NEW by default, and then phase out the old variant. */
#define CMD_HELLO 0x0500
union message {
unsigned short opCode;
struct ok {
unsigned short opCode;
short reserved;
int sliceNo;
} ok;
struct retransmit {
unsigned short opCode;
short reserved;
int sliceNo;
int rxmit;
unsigned char map[MAX_SLICE_SIZE / BITS_PER_CHAR];
} retransmit;
struct connectReq {
unsigned short opCode;
short reserved;
int capabilities;
unsigned int rcvbuf;
} connectReq;
struct go {
unsigned short opCode;
short reserved;
} go;
struct disconnect {
unsigned short opCode;
short reserved;
} disconnect;
};
struct connectReply {
unsigned short opCode;
short reserved;
int clNr;
int blockSize;
int capabilities;
unsigned char mcastAddr[16]; /* provide enough place for IPV6 */
};
struct hello {
unsigned short opCode;
short reserved;
int capabilities;
unsigned char mcastAddr[16]; /* provide enough place for IPV6 */
short blockSize;
};
union serverControlMsg {
unsigned short opCode;
short reserved;
struct hello hello;
struct connectReply connectReply;
};
struct dataBlock {
unsigned short opCode;
short reserved;
int sliceNo;
unsigned short blockNo;
unsigned short reserved2;
int bytes;
};
struct fecBlock {
unsigned short opCode;
short stripes;
int sliceNo;
unsigned short blockNo;
unsigned short reserved2;
int bytes;
};
struct reqack {
unsigned short opCode;
short reserved;
int sliceNo;
int bytes;
int rxmit;
};
union serverDataMsg {
unsigned short opCode;
struct reqack reqack;
struct dataBlock dataBlock;
struct fecBlock fecBlock;
};
/* ============================================
* Capabilities
*/
/* Does the receiver support the new CMD_DATA command, which carries
* capabilities mask?
* "new generation" receiver:
* - capabilities word included in hello/connectReq commands
* - receiver multicast capable
* - receiver can receive ASYNC and SN
*/
#define CAP_NEW_GEN 0x0001
/* Use multicast instead of Broadcast for data */
/*#define CAP_MULTICAST 0x0002*/
#ifdef BB_FEATURE_UDPCAST_FEC
/* Forward error correction */
#define CAP_FEC 0x0004
#endif
/* Supports big endians (a.k.a. network) */
#define CAP_BIG_ENDIAN 0x0008
/* Support little endians (a.k.a. PC) ==> obsolete! */
#define CAP_LITTLE_ENDIAN 0x0010
/* This transmission is asynchronous (no receiver reply) */
#define CAP_ASYNC 0x0020
/* Sender currently supports CAPABILITIES and MULTICAST */
#define SENDER_CAPABILITIES ( \
CAP_NEW_GEN | \
CAP_BIG_ENDIAN)
#define RECEIVER_CAPABILITIES ( \
CAP_NEW_GEN | \
CAP_BIG_ENDIAN)
#endif