-
Notifications
You must be signed in to change notification settings - Fork 9
/
common.js
51 lines (48 loc) · 1.23 KB
/
common.js
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
var packet = require('packet');
var packets = exports.packets =
{ header: '\
b8( \
&0x80/1: \
b16{b1 => control, b15 => type}, x16{0} \
, -b32 => additional \
, b32 => timestamp \
, b32 => destination \
| \
b32{b1 => control, b31 => sequence} \
, b32{b2 => position, b1 => inOrder, b29 => number} \
, b32 => timestamp \
, b32 => destination \
) \
'
, handshake: '\
-b32 => version \
, -b32 => socketType \
, b32 => sequence \
, -b32 => maxPacketSize \
, -b32 => windowSize \
, -b32 => connectionType \
, b32 => socketId \
, b32 => synCookie \
, b32 => address \
, x96{0} \
'
, acknowledgement: '\
b32 => sequence \
'
, statistics: '\
b32 => rtt \
, b32 => rttVariance \
, b32 => availableBufferSize \
, b32 => receivingRate \
, b32 => linkCapacity \
'
}
var parser = exports.parser = packet.createParser();
var serializer = exports.serializer = packet.createSerializer();
// TODO: Ugly. Parser cannot parse an empty packet.
serializer.packet('header', packets.header);
for (var name in packets) {
parser.packet(name, packets[name]);
if (name == 'header') continue;
serializer.packet(name, packets.header + ',' + packets[name]);
}