96 lines
1.9 KiB
Go
Raw Normal View History

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