-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandshake.go
More file actions
68 lines (58 loc) · 1.56 KB
/
handshake.go
File metadata and controls
68 lines (58 loc) · 1.56 KB
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
package main
import (
"encoding/binary"
"fmt"
)
func writeHandshakePacket(tun *tunnelCon) {
var buf []byte
buf = binary.AppendUvarint(buf, CLIENT_KEY)
buf = binary.AppendUvarint(buf, protocolVersion)
tun.con.Write(buf)
}
func readHandshakePacket(tun *tunnelCon) error {
//Read key
key, err := binary.ReadUvarint(tun.frameReader)
if err != nil {
return fmt.Errorf("unable to read key: %v", err)
}
if key != SERVER_KEY {
return fmt.Errorf("incorrect key: %X", key)
}
//Protocol version
proto, err := binary.ReadUvarint(tun.frameReader)
if err != nil {
return fmt.Errorf("unable to read protocol version: %v", err)
}
if proto != protocolVersion {
doLog("protocol version not compatible: %v.", proto)
doLog("Please download a new version from %v", downloadURL)
openInBrowser(downloadURL)
select {}
}
//Compression level
cl, err := binary.ReadUvarint(tun.frameReader)
if err != nil {
return fmt.Errorf("unable to read compressionLevel: %v", err)
}
compressionLevel = int(cl)
if compressionLevel > MaxCompression {
compressionLevel = MaxCompression
}
//Batching Interval
bm, err := binary.ReadUvarint(tun.frameReader)
if err != nil {
return fmt.Errorf("unable to read batch interval: %v", err)
}
batchingMicroseconds = int(bm)
//Server ID
sid, err := binary.ReadUvarint(tun.frameReader)
if err != nil {
return fmt.Errorf("unable to read server id: %v", err)
}
serverID = int(sid)
if debugLog {
doLog("Proto: %v, Compress: %v, BatchMicro: %v, ", proto, compressionLevel, batchingMicroseconds)
}
handleForwardedPorts(tun)
return nil
}