-
Notifications
You must be signed in to change notification settings - Fork 7
/
sendpacket.go
98 lines (81 loc) · 2.57 KB
/
sendpacket.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
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
package main
import (
"bytes"
"encoding/binary"
"log"
"net"
)
var txSeqNum uint32
func sendKeepalive(conn net.Conn) {
//log.Println("sending keepalive")
var rd rewindData
copy(rd.Sign[:], []byte(rewindProtocolSign))
rd.PacketType = rewindPacketTypeKeepAlive
rd.PayloadLength = uint16(rewindVersionDataLength)
rd.SeqNum = txSeqNum
txSeqNum++
var rvd rewindVersionData
rvd.RemoteID = settings.AppID
rvd.RewindService = rewindServiceSimpleApplication
copy(rvd.Description[:], []byte(rewindVersionDescription))
var buf bytes.Buffer
binary.Write(&buf, binary.LittleEndian, &rd)
binary.Write(&buf, binary.LittleEndian, &rvd)
writtenBytes, err := conn.Write(buf.Bytes())
if writtenBytes != rewindDataLength+int(rd.PayloadLength) || err != nil {
log.Println("warning: can't send udp packet", err)
}
}
func sendChallengeResponse(conn net.Conn, resp [32]byte) {
log.Println("sending challenge response")
var rd rewindData
copy(rd.Sign[:], []byte(rewindProtocolSign))
rd.PacketType = rewindPacketTypeAuthentication
rd.PayloadLength = 32
rd.SeqNum = txSeqNum
txSeqNum++
var buf bytes.Buffer
binary.Write(&buf, binary.LittleEndian, &rd)
buf.Write(resp[:])
writtenBytes, err := conn.Write(buf.Bytes())
if writtenBytes != rewindDataLength+int(rd.PayloadLength) || err != nil {
log.Println("warning: can't send udp packet", err)
}
}
func sendConfiguration(conn net.Conn, conf uint32) {
log.Println("sending configuration")
var rd rewindData
copy(rd.Sign[:], []byte(rewindProtocolSign))
rd.PacketType = rewindPacketTypeConfiguration
rd.PayloadLength = 4
rd.SeqNum = txSeqNum
txSeqNum++
var rcd rewindConfigurationData
rcd.Options = conf
var buf bytes.Buffer
binary.Write(&buf, binary.LittleEndian, &rd)
binary.Write(&buf, binary.LittleEndian, &rcd)
writtenBytes, err := conn.Write(buf.Bytes())
if writtenBytes != rewindDataLength+int(rd.PayloadLength) || err != nil {
log.Println("warning: can't send udp packet", err)
}
}
func sendSubscription(conn net.Conn, dstID uint32, sessionType uint32) {
log.Println("sending subscription")
var rd rewindData
copy(rd.Sign[:], []byte(rewindProtocolSign))
rd.PacketType = rewindPacketTypeSubscription
rd.PayloadLength = 8
rd.SeqNum = txSeqNum
txSeqNum++
var rsd rewindSubscriptionData
rsd.DstID = dstID
rsd.SessionType = sessionType
var buf bytes.Buffer
binary.Write(&buf, binary.LittleEndian, &rd)
binary.Write(&buf, binary.LittleEndian, &rsd)
writtenBytes, err := conn.Write(buf.Bytes())
if writtenBytes != rewindDataLength+int(rd.PayloadLength) || err != nil {
log.Println("warning: can't send udp packet", err)
}
}