forked from v2fly/v2ray-core
-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
73 lines (63 loc) · 1.61 KB
/
config.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
package kcp
import (
"v2ray.com/core/transport/internet"
)
type Config struct {
Mtu uint32 // Maximum transmission unit
Tti uint32
UplinkCapacity uint32
DownlinkCapacity uint32
Congestion bool
WriteBuffer uint32
ReadBuffer uint32
HeaderType string
HeaderConfig internet.AuthenticatorConfig
}
func (this *Config) Apply() {
effectiveConfig = *this
}
func (this *Config) GetAuthenticator() (internet.Authenticator, error) {
auth := NewSimpleAuthenticator()
if this.HeaderConfig != nil {
header, err := internet.CreateAuthenticator(this.HeaderType, this.HeaderConfig)
if err != nil {
return nil, err
}
auth = internet.NewAuthenticatorChain(header, auth)
}
return auth, nil
}
func (this *Config) GetSendingInFlightSize() uint32 {
size := this.UplinkCapacity * 1024 * 1024 / this.Mtu / (1000 / this.Tti) / 2
if size < 8 {
size = 8
}
return size
}
func (this *Config) GetSendingBufferSize() uint32 {
return this.GetSendingInFlightSize() + this.WriteBuffer/this.Mtu
}
func (this *Config) GetReceivingInFlightSize() uint32 {
size := this.DownlinkCapacity * 1024 * 1024 / this.Mtu / (1000 / this.Tti) / 2
if size < 8 {
size = 8
}
return size
}
func (this *Config) GetReceivingBufferSize() uint32 {
return this.GetReceivingInFlightSize() + this.ReadBuffer/this.Mtu
}
func DefaultConfig() Config {
return Config{
Mtu: 1350,
Tti: 50,
UplinkCapacity: 5,
DownlinkCapacity: 20,
Congestion: false,
WriteBuffer: 1 * 1024 * 1024,
ReadBuffer: 1 * 1024 * 1024,
}
}
var (
effectiveConfig = DefaultConfig()
)