1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-03 06:30:42 +00:00
v2fly/transport/internet/kcp/config.go

103 lines
1.8 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-11-27 20:39:09 +00:00
func (v *MTU) GetValue() uint32 {
if v == nil {
2016-09-21 19:08:05 +00:00
return 1350
}
2016-11-27 20:39:09 +00:00
return v.Value
2016-09-21 19:08:05 +00:00
}
2016-11-27 20:39:09 +00:00
func (v *TTI) GetValue() uint32 {
if v == nil {
2016-09-21 19:08:05 +00:00
return 50
}
2016-11-27 20:39:09 +00:00
return v.Value
2016-09-21 19:08:05 +00:00
}
2016-11-27 20:39:09 +00:00
func (v *UplinkCapacity) GetValue() uint32 {
if v == nil {
2016-09-21 19:08:05 +00:00
return 5
}
2016-11-27 20:39:09 +00:00
return v.Value
2016-09-21 19:08:05 +00:00
}
2016-11-27 20:39:09 +00:00
func (v *DownlinkCapacity) GetValue() uint32 {
if v == nil {
2016-09-21 19:08:05 +00:00
return 20
}
2016-11-27 20:39:09 +00:00
return v.Value
2016-09-21 19:08:05 +00:00
}
2016-11-27 20:39:09 +00:00
func (v *WriteBuffer) GetSize() uint32 {
if v == nil {
2016-11-30 20:36:40 +00:00
return 2 * 1024 * 1024
2016-09-21 19:08:05 +00:00
}
2016-11-27 20:39:09 +00:00
return v.Size
2016-09-21 19:08:05 +00:00
}
2016-11-27 20:39:09 +00:00
func (v *ReadBuffer) GetSize() uint32 {
if v == nil {
2016-11-30 20:36:40 +00:00
return 2 * 1024 * 1024
2016-09-21 19:08:05 +00:00
}
2016-11-27 20:39:09 +00:00
return v.Size
2016-09-21 19:08:05 +00:00
}
2016-11-27 20:39:09 +00:00
func (v *Config) GetAuthenticator() (internet.Authenticator, error) {
2016-08-06 19:59:22 +00:00
auth := NewSimpleAuthenticator()
2016-11-27 20:39:09 +00:00
if v.HeaderConfig != nil {
rawConfig, err := v.HeaderConfig.GetInstance()
2016-10-16 12:22:21 +00:00
if err != nil {
return nil, err
}
2016-11-27 20:39:09 +00:00
header, err := internet.CreateAuthenticator(v.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-11-27 20:39:09 +00:00
func (v *Config) GetSendingInFlightSize() uint32 {
2016-11-30 20:36:40 +00:00
size := v.UplinkCapacity.GetValue() * 1024 * 1024 / v.Mtu.GetValue() / (1000 / v.Tti.GetValue())
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-11-27 20:39:09 +00:00
func (v *Config) GetSendingBufferSize() uint32 {
return v.WriteBuffer.GetSize() / v.Mtu.GetValue()
2016-07-02 09:19:32 +00:00
}
2016-11-27 20:39:09 +00:00
func (v *Config) GetReceivingInFlightSize() uint32 {
2016-11-30 20:36:40 +00:00
size := v.DownlinkCapacity.GetValue() * 1024 * 1024 / v.Mtu.GetValue() / (1000 / v.Tti.GetValue())
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-11-27 20:39:09 +00:00
func (v *Config) GetReceivingBufferSize() uint32 {
return v.ReadBuffer.GetSize() / v.Mtu.GetValue()
2016-06-17 14:57:48 +00:00
}
2016-11-27 07:58:31 +00:00
func (o *ConnectionReuse) IsEnabled() bool {
if o == nil {
return true
}
return o.Enable
}
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)
})
}