-
Notifications
You must be signed in to change notification settings - Fork 2
/
speed_mode.go
70 lines (56 loc) · 1.89 KB
/
speed_mode.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
package main
//
// NoDelay options
// fastest: ikcp_nodelay(kcp, 1, 20, 2, 1)
// nodelay: 0:disable(default), 1:enable
// interval: internal update timer interval in millisec, default is 100ms
// resend: 0:disable fast resend(default), 1:enable fast resend
// nc: 0:normal congestion control(default), 1:disable congestion control
/*
kcp_mode_default: []int{0, 50, 0, 0},
kcp_mode_normal: []int{0, 40, 2, 1},
kcp_mode_fast: []int{0, 30, 2, 1},
kcp_mode_fast2: []int{1, 20, 2, 1},
kcp_mode_fast3: []int{1, 10, 2, 1},
*/
type SpeedMode struct {
name string
tox_interval int
kcp_interval int
nodelay, interval, resend, nc int
wndsz int
}
// fast3 > fast2 > fast > normal > default
// like tcp
const tox_interval = 200
const kcp_interval = 75 // 50-100
var SMTcp = &SpeedMode{name: "default-tcp", tox_interval: tox_interval, kcp_interval: kcp_interval,
nodelay: 0, interval: 100, resend: 0, nc: 0, wndsz: 32}
var SMDefault = SMTcp
var SMNormal = &SpeedMode{name: "normal", tox_interval: tox_interval, kcp_interval: kcp_interval,
nodelay: 0, interval: 50, resend: 0, nc: 0, wndsz: 32}
var SMFast = &SpeedMode{name: "fast", tox_interval: tox_interval, kcp_interval: kcp_interval,
nodelay: 1, interval: 40, resend: 2, nc: 1, wndsz: 64}
var SMFast2 = &SpeedMode{name: "fast2", tox_interval: tox_interval, kcp_interval: kcp_interval,
nodelay: 1, interval: 20, resend: 2, nc: 1, wndsz: 96}
var SMFast3 = &SpeedMode{name: "fast3", tox_interval: tox_interval, kcp_interval: kcp_interval,
nodelay: 1, interval: 10, resend: 2, nc: 1, wndsz: 128}
var smuse = SMTcp
func set_speed_mode(mode string) {
switch mode {
default:
info.Printf("%s mode not found, use default\n", mode)
fallthrough
case "default":
smuse = SMTcp
case "normal":
smuse = SMNormal
case "fast":
smuse = SMFast
case "fast2":
smuse = SMFast2
case "fast3":
smuse = SMFast3
}
info.Println("switch to kcp-mode:", smuse.name)
}