forked from bigeasy/udt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
packetdefs.js
59 lines (55 loc) · 1.38 KB
/
packetdefs.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
52
53
54
55
56
57
58
59
var packet = require('packet');
exports.MAX_SEQ_NO = Math.pow(2, 31) - 1;
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: ''
, negativeack: ''
, ack2: ''
, shutdown: ''
, keepalive: ''
, statistics: '\
b32 => rtt \
, b32 => rttVariance \
, b32 => availableBufferSize \
, b32 => receivingRate \
, b32 => linkCapacity \
'
, messagedrop: '\
b32 => firstSequence \
, b32 => lastSequence \
'
};
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]);
}