mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-18 07:17:32 -05:00
cleanup
This commit is contained in:
parent
bf7b8798a9
commit
be714f76f1
@ -8,61 +8,61 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// GetMTUValue returns the value of MTU settings.
|
// GetMTUValue returns the value of MTU settings.
|
||||||
func (v *Config) GetMTUValue() uint32 {
|
func (c *Config) GetMTUValue() uint32 {
|
||||||
if v == nil || v.Mtu == nil {
|
if c == nil || c.Mtu == nil {
|
||||||
return 1350
|
return 1350
|
||||||
}
|
}
|
||||||
return v.Mtu.Value
|
return c.Mtu.Value
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetTTIValue returns the value of TTI settings.
|
// GetTTIValue returns the value of TTI settings.
|
||||||
func (v *Config) GetTTIValue() uint32 {
|
func (c *Config) GetTTIValue() uint32 {
|
||||||
if v == nil || v.Tti == nil {
|
if c == nil || c.Tti == nil {
|
||||||
return 50
|
return 50
|
||||||
}
|
}
|
||||||
return v.Tti.Value
|
return c.Tti.Value
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUplinkCapacityValue returns the value of UplinkCapacity settings.
|
// GetUplinkCapacityValue returns the value of UplinkCapacity settings.
|
||||||
func (v *Config) GetUplinkCapacityValue() uint32 {
|
func (c *Config) GetUplinkCapacityValue() uint32 {
|
||||||
if v == nil || v.UplinkCapacity == nil {
|
if c == nil || c.UplinkCapacity == nil {
|
||||||
return 5
|
return 5
|
||||||
}
|
}
|
||||||
return v.UplinkCapacity.Value
|
return c.UplinkCapacity.Value
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDownlinkCapacityValue returns the value of DownlinkCapacity settings.
|
// GetDownlinkCapacityValue returns the value of DownlinkCapacity settings.
|
||||||
func (v *Config) GetDownlinkCapacityValue() uint32 {
|
func (c *Config) GetDownlinkCapacityValue() uint32 {
|
||||||
if v == nil || v.DownlinkCapacity == nil {
|
if c == nil || c.DownlinkCapacity == nil {
|
||||||
return 20
|
return 20
|
||||||
}
|
}
|
||||||
return v.DownlinkCapacity.Value
|
return c.DownlinkCapacity.Value
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetWriteBufferSize returns the size of WriterBuffer in bytes.
|
// GetWriteBufferSize returns the size of WriterBuffer in bytes.
|
||||||
func (v *Config) GetWriteBufferSize() uint32 {
|
func (c *Config) GetWriteBufferSize() uint32 {
|
||||||
if v == nil || v.WriteBuffer == nil {
|
if c == nil || c.WriteBuffer == nil {
|
||||||
return 2 * 1024 * 1024
|
return 2 * 1024 * 1024
|
||||||
}
|
}
|
||||||
return v.WriteBuffer.Size
|
return c.WriteBuffer.Size
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetReadBufferSize returns the size of ReadBuffer in bytes.
|
// GetReadBufferSize returns the size of ReadBuffer in bytes.
|
||||||
func (v *Config) GetReadBufferSize() uint32 {
|
func (c *Config) GetReadBufferSize() uint32 {
|
||||||
if v == nil || v.ReadBuffer == nil {
|
if c == nil || c.ReadBuffer == nil {
|
||||||
return 2 * 1024 * 1024
|
return 2 * 1024 * 1024
|
||||||
}
|
}
|
||||||
return v.ReadBuffer.Size
|
return c.ReadBuffer.Size
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSecurity returns the security settings.
|
// GetSecurity returns the security settings.
|
||||||
func (v *Config) GetSecurity() (cipher.AEAD, error) {
|
func (*Config) GetSecurity() (cipher.AEAD, error) {
|
||||||
return NewSimpleAuthenticator(), nil
|
return NewSimpleAuthenticator(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Config) GetPackerHeader() (internet.PacketHeader, error) {
|
func (c *Config) GetPackerHeader() (internet.PacketHeader, error) {
|
||||||
if v.HeaderConfig != nil {
|
if c.HeaderConfig != nil {
|
||||||
rawConfig, err := v.HeaderConfig.GetInstance()
|
rawConfig, err := c.HeaderConfig.GetInstance()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -72,28 +72,28 @@ func (v *Config) GetPackerHeader() (internet.PacketHeader, error) {
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Config) GetSendingInFlightSize() uint32 {
|
func (c *Config) GetSendingInFlightSize() uint32 {
|
||||||
size := v.GetUplinkCapacityValue() * 1024 * 1024 / v.GetMTUValue() / (1000 / v.GetTTIValue())
|
size := c.GetUplinkCapacityValue() * 1024 * 1024 / c.GetMTUValue() / (1000 / c.GetTTIValue())
|
||||||
if size < 8 {
|
if size < 8 {
|
||||||
size = 8
|
size = 8
|
||||||
}
|
}
|
||||||
return size
|
return size
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Config) GetSendingBufferSize() uint32 {
|
func (c *Config) GetSendingBufferSize() uint32 {
|
||||||
return v.GetWriteBufferSize() / v.GetMTUValue()
|
return c.GetWriteBufferSize() / c.GetMTUValue()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Config) GetReceivingInFlightSize() uint32 {
|
func (c *Config) GetReceivingInFlightSize() uint32 {
|
||||||
size := v.GetDownlinkCapacityValue() * 1024 * 1024 / v.GetMTUValue() / (1000 / v.GetTTIValue())
|
size := c.GetDownlinkCapacityValue() * 1024 * 1024 / c.GetMTUValue() / (1000 / c.GetTTIValue())
|
||||||
if size < 8 {
|
if size < 8 {
|
||||||
size = 8
|
size = 8
|
||||||
}
|
}
|
||||||
return size
|
return size
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Config) GetReceivingBufferSize() uint32 {
|
func (c *Config) GetReceivingBufferSize() uint32 {
|
||||||
return v.GetReadBufferSize() / v.GetMTUValue()
|
return c.GetReadBufferSize() / c.GetMTUValue()
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -18,8 +18,10 @@ var (
|
|||||||
ErrClosedConnection = newError("Connection closed.")
|
ErrClosedConnection = newError("Connection closed.")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// State of the connection
|
||||||
type State int32
|
type State int32
|
||||||
|
|
||||||
|
// Is returns true if current State is one of the candidates.
|
||||||
func (s State) Is(states ...State) bool {
|
func (s State) Is(states ...State) bool {
|
||||||
for _, state := range states {
|
for _, state := range states {
|
||||||
if s == state {
|
if s == state {
|
||||||
@ -30,12 +32,12 @@ func (s State) Is(states ...State) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
StateActive State = 0
|
StateActive State = 0 // Connection is active
|
||||||
StateReadyToClose State = 1
|
StateReadyToClose State = 1 // Connection is closed locally
|
||||||
StatePeerClosed State = 2
|
StatePeerClosed State = 2 // Connection is closed on remote
|
||||||
StateTerminating State = 3
|
StateTerminating State = 3 // Connection is ready to be destroyed locally
|
||||||
StatePeerTerminating State = 4
|
StatePeerTerminating State = 4 // Connection is ready to be destroyed on remote
|
||||||
StateTerminated State = 5
|
StateTerminated State = 5 // Connection is detroyed.
|
||||||
)
|
)
|
||||||
|
|
||||||
func nowMillisec() int64 {
|
func nowMillisec() int64 {
|
||||||
@ -52,66 +54,66 @@ type RoundTripInfo struct {
|
|||||||
updatedTimestamp uint32
|
updatedTimestamp uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *RoundTripInfo) UpdatePeerRTO(rto uint32, current uint32) {
|
func (info *RoundTripInfo) UpdatePeerRTO(rto uint32, current uint32) {
|
||||||
v.Lock()
|
info.Lock()
|
||||||
defer v.Unlock()
|
defer info.Unlock()
|
||||||
|
|
||||||
if current-v.updatedTimestamp < 3000 {
|
if current-info.updatedTimestamp < 3000 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
v.updatedTimestamp = current
|
info.updatedTimestamp = current
|
||||||
v.rto = rto
|
info.rto = rto
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *RoundTripInfo) Update(rtt uint32, current uint32) {
|
func (info *RoundTripInfo) Update(rtt uint32, current uint32) {
|
||||||
if rtt > 0x7FFFFFFF {
|
if rtt > 0x7FFFFFFF {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
v.Lock()
|
info.Lock()
|
||||||
defer v.Unlock()
|
defer info.Unlock()
|
||||||
|
|
||||||
// https://tools.ietf.org/html/rfc6298
|
// https://tools.ietf.org/html/rfc6298
|
||||||
if v.srtt == 0 {
|
if info.srtt == 0 {
|
||||||
v.srtt = rtt
|
info.srtt = rtt
|
||||||
v.variation = rtt / 2
|
info.variation = rtt / 2
|
||||||
} else {
|
} else {
|
||||||
delta := rtt - v.srtt
|
delta := rtt - info.srtt
|
||||||
if v.srtt > rtt {
|
if info.srtt > rtt {
|
||||||
delta = v.srtt - rtt
|
delta = info.srtt - rtt
|
||||||
}
|
}
|
||||||
v.variation = (3*v.variation + delta) / 4
|
info.variation = (3*info.variation + delta) / 4
|
||||||
v.srtt = (7*v.srtt + rtt) / 8
|
info.srtt = (7*info.srtt + rtt) / 8
|
||||||
if v.srtt < v.minRtt {
|
if info.srtt < info.minRtt {
|
||||||
v.srtt = v.minRtt
|
info.srtt = info.minRtt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var rto uint32
|
var rto uint32
|
||||||
if v.minRtt < 4*v.variation {
|
if info.minRtt < 4*info.variation {
|
||||||
rto = v.srtt + 4*v.variation
|
rto = info.srtt + 4*info.variation
|
||||||
} else {
|
} else {
|
||||||
rto = v.srtt + v.variation
|
rto = info.srtt + info.variation
|
||||||
}
|
}
|
||||||
|
|
||||||
if rto > 10000 {
|
if rto > 10000 {
|
||||||
rto = 10000
|
rto = 10000
|
||||||
}
|
}
|
||||||
v.rto = rto * 5 / 4
|
info.rto = rto * 5 / 4
|
||||||
v.updatedTimestamp = current
|
info.updatedTimestamp = current
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *RoundTripInfo) Timeout() uint32 {
|
func (info *RoundTripInfo) Timeout() uint32 {
|
||||||
v.RLock()
|
info.RLock()
|
||||||
defer v.RUnlock()
|
defer info.RUnlock()
|
||||||
|
|
||||||
return v.rto
|
return info.rto
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *RoundTripInfo) SmoothedTime() uint32 {
|
func (info *RoundTripInfo) SmoothedTime() uint32 {
|
||||||
v.RLock()
|
info.RLock()
|
||||||
defer v.RUnlock()
|
defer info.RUnlock()
|
||||||
|
|
||||||
return v.srtt
|
return info.srtt
|
||||||
}
|
}
|
||||||
|
|
||||||
type Updater struct {
|
type Updater struct {
|
||||||
@ -162,12 +164,6 @@ func (u *Updater) SetInterval(d time.Duration) {
|
|||||||
atomic.StoreInt64(&u.interval, int64(d))
|
atomic.StoreInt64(&u.interval, int64(d))
|
||||||
}
|
}
|
||||||
|
|
||||||
type SystemConnection interface {
|
|
||||||
net.Conn
|
|
||||||
Reset(func([]Segment))
|
|
||||||
Overhead() int
|
|
||||||
}
|
|
||||||
|
|
||||||
type ConnMetadata struct {
|
type ConnMetadata struct {
|
||||||
LocalAddr net.Addr
|
LocalAddr net.Addr
|
||||||
RemoteAddr net.Addr
|
RemoteAddr net.Addr
|
||||||
|
Loading…
Reference in New Issue
Block a user