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-10-02 17:43:58 -04:00
|
|
|
|
|
|
|
"github.com/golang/protobuf/proto"
|
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-09-21 08:39:07 -04:00
|
|
|
header, err := this.HeaderConfig.CreateAuthenticator()
|
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() {
|
|
|
|
internet.RegisterNetworkConfigCreator(v2net.Network_KCP, func() proto.Message {
|
|
|
|
return new(Config)
|
|
|
|
})
|
|
|
|
}
|