1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-23 02:26:49 -05:00
v2fly/transport/internet/kcp/config.go

96 lines
1.9 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-10-02 17:43:58 -04:00
v2net "v2ray.com/core/common/net"
2016-08-20 14:55:45 -04:00
"v2ray.com/core/transport/internet"
2016-08-06 15:59:22 -04:00
)
2016-09-21 15:08:05 -04:00
func (this *MTU) GetValue() uint32 {
if this == nil {
return 1350
}
return this.Value
}
func (this *TTI) GetValue() uint32 {
if this == nil {
return 50
}
return this.Value
}
func (this *UplinkCapacity) GetValue() uint32 {
if this == nil {
return 5
}
return this.Value
}
func (this *DownlinkCapacity) GetValue() uint32 {
if this == nil {
return 20
}
return this.Value
}
func (this *WriteBuffer) GetSize() uint32 {
if this == nil {
return 1 * 1024 * 1024
}
return this.Size
}
func (this *ReadBuffer) GetSize() uint32 {
if this == nil {
return 1 * 1024 * 1024
}
return this.Size
}
2016-08-06 15:59:22 -04:00
func (this *Config) GetAuthenticator() (internet.Authenticator, error) {
auth := NewSimpleAuthenticator()
if this.HeaderConfig != nil {
2016-10-16 08:22:21 -04:00
rawConfig, err := this.HeaderConfig.GetInstance()
if err != nil {
return nil, err
}
header, err := internet.CreateAuthenticator(this.HeaderConfig.Type, rawConfig)
2016-08-06 15:59:22 -04:00
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-09-21 15:08:05 -04:00
size := this.UplinkCapacity.GetValue() * 1024 * 1024 / this.Mtu.GetValue() / (1000 / this.Tti.GetValue()) / 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-09-21 15:08:05 -04:00
return this.GetSendingInFlightSize() + this.WriteBuffer.GetSize()/this.Mtu.GetValue()
2016-07-02 05:19:32 -04:00
}
2016-08-25 03:45:56 -04:00
func (this *Config) GetReceivingInFlightSize() uint32 {
2016-09-21 15:08:05 -04:00
size := this.DownlinkCapacity.GetValue() * 1024 * 1024 / this.Mtu.GetValue() / (1000 / this.Tti.GetValue()) / 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-25 03:45:56 -04:00
func (this *Config) GetReceivingBufferSize() uint32 {
2016-09-21 15:08:05 -04:00
return this.GetReceivingInFlightSize() + this.ReadBuffer.GetSize()/this.Mtu.GetValue()
2016-06-17 10:57:48 -04:00
}
2016-10-02 17:43:58 -04:00
func init() {
2016-10-16 08:22:21 -04:00
internet.RegisterNetworkConfigCreator(v2net.Network_KCP, func() interface{} {
2016-10-02 17:43:58 -04:00
return new(Config)
})
}