You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
v2ray-core/transport/internet/kcp/config.go

111 lines
2.2 KiB

package kcp
import (
"crypto/cipher"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/transport/internet"
)
8 years ago
// GetValue returns the value of MTU settings.
8 years ago
func (v *MTU) GetValue() uint32 {
if v == nil {
return 1350
}
8 years ago
return v.Value
}
8 years ago
// GetValue returns the value of TTI settings.
8 years ago
func (v *TTI) GetValue() uint32 {
if v == nil {
return 50
}
8 years ago
return v.Value
}
8 years ago
// GetValue returns the value of UplinkCapacity settings.
8 years ago
func (v *UplinkCapacity) GetValue() uint32 {
if v == nil {
return 5
}
8 years ago
return v.Value
}
8 years ago
// GetValue returns the value of DownlinkCapacity settings.
8 years ago
func (v *DownlinkCapacity) GetValue() uint32 {
if v == nil {
return 20
}
8 years ago
return v.Value
}
8 years ago
// GetSize returns the size of WriterBuffer in bytes.
8 years ago
func (v *WriteBuffer) GetSize() uint32 {
if v == nil {
return 2 * 1024 * 1024
}
8 years ago
return v.Size
}
8 years ago
// GetSize returns the size of ReadBuffer in bytes.
8 years ago
func (v *ReadBuffer) GetSize() uint32 {
if v == nil {
return 2 * 1024 * 1024
}
8 years ago
return v.Size
}
8 years ago
// GetSecurity returns the security settings.
func (v *Config) GetSecurity() (cipher.AEAD, error) {
return NewSimpleAuthenticator(), nil
}
func (v *Config) GetPackerHeader() (internet.PacketHeader, error) {
8 years ago
if v.HeaderConfig != nil {
rawConfig, err := v.HeaderConfig.GetInstance()
if err != nil {
return nil, err
}
return internet.CreatePacketHeader(v.HeaderConfig.Type, rawConfig)
}
return nil, nil
}
8 years ago
func (v *Config) GetSendingInFlightSize() uint32 {
size := v.UplinkCapacity.GetValue() * 1024 * 1024 / v.Mtu.GetValue() / (1000 / v.Tti.GetValue())
if size < 8 {
size = 8
}
return size
}
8 years ago
func (v *Config) GetSendingBufferSize() uint32 {
return v.WriteBuffer.GetSize() / v.Mtu.GetValue()
}
8 years ago
func (v *Config) GetReceivingInFlightSize() uint32 {
size := v.DownlinkCapacity.GetValue() * 1024 * 1024 / v.Mtu.GetValue() / (1000 / v.Tti.GetValue())
if size < 8 {
size = 8
}
return size
}
8 years ago
func (v *Config) GetReceivingBufferSize() uint32 {
return v.ReadBuffer.GetSize() / v.Mtu.GetValue()
}
func (o *ConnectionReuse) IsEnabled() bool {
if o == nil {
return true
}
return o.Enable
}
func init() {
internet.RegisterNetworkConfigCreator(v2net.Network_KCP, func() interface{} {
return new(Config)
})
}