-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathprotocol.go
52 lines (39 loc) · 1.08 KB
/
protocol.go
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
package gouxp
import (
"encoding/binary"
)
// gouxp packet format:
// |--MAC--|--PROTO TYPE--|-----------------USER DATA-----------------|
// | 16byte| 2byte | ... |
// |-------KCP HEADER-------|-------DATA-------|
// MAC: check data integrity
// packet protocol:
// raw data -> kcp data -> [compress] -> [crypto] -> fec
const (
macSize uint16 = 16
protoSize uint16 = 2
PacketHeaderSize uint16 = macSize + protoSize
)
type ProtoType uint16
const (
protoTypeHandshake ProtoType = 0x0C
protoTypeHeartbeat ProtoType = 0x0D
protoTypeData ProtoType = 0x0E
)
type PlaintextData []byte
func (p PlaintextData) Type() ProtoType {
return ProtoType(binary.LittleEndian.Uint16(p))
}
func (p PlaintextData) Data() []byte {
return p[protoSize:]
}
var ConvID uint32 = 555
const (
// | header: 18bytes | convID: 4bytes | crypto public key: 8bytes |
handshakeBufferSize = PacketHeaderSize + 4 + 8
heartbeatBufferSize = PacketHeaderSize + 4
)
var logger Logger
func SetDebugLogger(l Logger) {
logger = l
}