v2ray-core/transport/internet/kcp/config.go

96 lines
1.9 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-10-02 21:43:58 +00:00
v2net "v2ray.com/core/common/net"
2016-08-20 18:55:45 +00:00
"v2ray.com/core/transport/internet"
2016-08-06 19:59:22 +00:00
)
2016-09-21 19:08:05 +00: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 19:59:22 +00:00
func (this *Config) GetAuthenticator() (internet.Authenticator, error) {
auth := NewSimpleAuthenticator()
if this.HeaderConfig != nil {
2016-10-16 12:22:21 +00:00
rawConfig, err := this.HeaderConfig.GetInstance()
if err != nil {
return nil, err
}
header, err := internet.CreateAuthenticator(this.HeaderConfig.Type, rawConfig)
2016-08-06 19:59:22 +00:00
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-09-21 19:08:05 +00:00
size := this.UplinkCapacity.GetValue() * 1024 * 1024 / this.Mtu.GetValue() / (1000 / this.Tti.GetValue()) / 2
2016-08-24 05:50:33 +00:00
if size < 8 {
2016-06-29 14:46:26 +00:00
size = 8
}
return size
2016-06-20 14:10:47 +00:00
}
2016-08-24 21:54:39 +00:00
func (this *Config) GetSendingBufferSize() uint32 {
2016-11-19 00:49:54 +00:00
return this.WriteBuffer.GetSize() / this.Mtu.GetValue()
2016-07-02 09:19:32 +00:00
}
2016-08-25 07:45:56 +00:00
func (this *Config) GetReceivingInFlightSize() uint32 {
2016-09-21 19:08:05 +00:00
size := this.DownlinkCapacity.GetValue() * 1024 * 1024 / this.Mtu.GetValue() / (1000 / this.Tti.GetValue()) / 2
2016-08-24 05:50:33 +00:00
if size < 8 {
2016-06-29 14:46:26 +00:00
size = 8
}
return size
2016-06-20 14:10:47 +00:00
}
2016-08-25 07:45:56 +00:00
func (this *Config) GetReceivingBufferSize() uint32 {
2016-11-19 00:49:54 +00:00
return this.ReadBuffer.GetSize() / this.Mtu.GetValue()
2016-06-17 14:57:48 +00:00
}
2016-10-02 21:43:58 +00:00
func init() {
2016-10-16 12:22:21 +00:00
internet.RegisterNetworkConfigCreator(v2net.Network_KCP, func() interface{} {
2016-10-02 21:43:58 +00:00
return new(Config)
})
}