1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-02 09:17:55 -04:00
v2fly/transport/internet/kcp/config.go

71 lines
1.5 KiB
Go
Raw Normal View History

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