1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-03 06:30:42 +00:00
v2fly/transport/internet/kcp/config.go

78 lines
1.6 KiB
Go
Raw Normal View History

2016-06-14 20:54:08 +00:00
package kcp
2016-06-11 09:30:38 +00:00
2016-08-06 19:59:22 +00:00
import (
2016-08-20 18:55:45 +00:00
"v2ray.com/core/transport/internet"
2016-08-06 19:59:22 +00:00
)
2016-06-11 09:30:38 +00:00
type Config struct {
2016-06-25 19:35:18 +00:00
Mtu uint32 // Maximum transmission unit
Tti uint32
UplinkCapacity uint32
DownlinkCapacity uint32
2016-06-20 14:10:47 +00:00
Congestion bool
2016-06-25 21:17:04 +00:00
WriteBuffer uint32
2016-06-30 12:51:49 +00:00
ReadBuffer uint32
2016-08-06 19:59:22 +00:00
HeaderType string
HeaderConfig internet.AuthenticatorConfig
2016-06-11 09:30:38 +00:00
}
2016-06-14 20:54:08 +00:00
func (this *Config) Apply() {
effectiveConfig = *this
2016-06-11 09:30:38 +00:00
}
2016-06-14 20:54:08 +00:00
2016-08-06 19:59:22 +00:00
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
}
2016-07-04 11:37:42 +00:00
func (this *Config) GetSendingInFlightSize() uint32 {
2016-06-29 14:46:26 +00:00
size := this.UplinkCapacity * 1024 * 1024 / this.Mtu / (1000 / this.Tti) / 2
if size == 0 {
size = 8
}
return size
2016-06-20 14:10:47 +00:00
}
2016-07-04 11:37:42 +00:00
func (this *Config) GetSendingWindowSize() uint32 {
return this.GetSendingInFlightSize() * 4
}
2016-07-02 09:19:32 +00:00
func (this *Config) GetSendingQueueSize() uint32 {
return this.WriteBuffer / this.Mtu
}
2016-06-25 19:35:18 +00:00
func (this *Config) GetReceivingWindowSize() uint32 {
2016-06-29 14:46:26 +00:00
size := this.DownlinkCapacity * 1024 * 1024 / this.Mtu / (1000 / this.Tti) / 2
if size == 0 {
size = 8
}
return size
2016-06-20 14:10:47 +00:00
}
2016-07-02 09:19:32 +00:00
func (this *Config) GetReceivingQueueSize() uint32 {
return this.ReadBuffer / this.Mtu
}
2016-06-17 14:57:48 +00:00
func DefaultConfig() Config {
return Config{
2016-06-20 14:10:47 +00:00
Mtu: 1350,
2016-08-23 21:32:36 +00:00
Tti: 50,
2016-06-20 14:10:47 +00:00
UplinkCapacity: 5,
DownlinkCapacity: 20,
Congestion: false,
WriteBuffer: 1 * 1024 * 1024,
ReadBuffer: 1 * 1024 * 1024,
2016-06-14 20:54:08 +00:00
}
2016-06-17 14:57:48 +00:00
}
var (
effectiveConfig = DefaultConfig()
2016-06-14 20:54:08 +00:00
)