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