mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 10:08:15 -05:00
refine kcp constructor
This commit is contained in:
parent
a2abdc3d2f
commit
94fb16fdfa
@ -22,6 +22,10 @@ func (this *Config) GetSendingWindowSize() uint32 {
|
||||
return size
|
||||
}
|
||||
|
||||
func (this *Config) GetSendingQueueSize() uint32 {
|
||||
return this.WriteBuffer / this.Mtu
|
||||
}
|
||||
|
||||
func (this *Config) GetReceivingWindowSize() uint32 {
|
||||
size := this.DownlinkCapacity * 1024 * 1024 / this.Mtu / (1000 / this.Tti) / 2
|
||||
if size == 0 {
|
||||
@ -30,6 +34,10 @@ func (this *Config) GetReceivingWindowSize() uint32 {
|
||||
return size
|
||||
}
|
||||
|
||||
func (this *Config) GetReceivingQueueSize() uint32 {
|
||||
return this.ReadBuffer / this.Mtu
|
||||
}
|
||||
|
||||
func DefaultConfig() Config {
|
||||
return Config{
|
||||
Mtu: 1350,
|
||||
|
@ -51,7 +51,6 @@ type Connection struct {
|
||||
writer io.WriteCloser
|
||||
since int64
|
||||
terminateOnce signal.Once
|
||||
writeBufferSize uint32
|
||||
}
|
||||
|
||||
// NewConnection create a new KCP connection between local and remote.
|
||||
@ -63,13 +62,12 @@ func NewConnection(conv uint16, writerCloser io.WriteCloser, local *net.UDPAddr,
|
||||
conn.block = block
|
||||
conn.writer = writerCloser
|
||||
conn.since = nowMillisec()
|
||||
conn.writeBufferSize = effectiveConfig.WriteBuffer / effectiveConfig.Mtu
|
||||
|
||||
authWriter := &AuthenticationWriter{
|
||||
Authenticator: block,
|
||||
Writer: writerCloser,
|
||||
}
|
||||
conn.kcp = NewKCP(conv, effectiveConfig.GetSendingWindowSize(), effectiveConfig.GetReceivingWindowSize(), conn.writeBufferSize, authWriter)
|
||||
conn.kcp = NewKCP(conv, authWriter)
|
||||
conn.kcp.NoDelay(effectiveConfig.Tti, 2, effectiveConfig.Congestion)
|
||||
conn.kcp.current = conn.Elapsed()
|
||||
|
||||
|
@ -65,22 +65,22 @@ type KCP struct {
|
||||
|
||||
// NewKCP create a new kcp control object, 'conv' must equal in two endpoint
|
||||
// from the same connection.
|
||||
func NewKCP(conv uint16, sendingWindowSize uint32, receivingWindowSize uint32, sendingQueueSize uint32, output *AuthenticationWriter) *KCP {
|
||||
func NewKCP(conv uint16, output *AuthenticationWriter) *KCP {
|
||||
log.Debug("KCP|Core: creating KCP ", conv)
|
||||
kcp := new(KCP)
|
||||
kcp.conv = conv
|
||||
kcp.snd_wnd = sendingWindowSize
|
||||
kcp.rcv_wnd = receivingWindowSize
|
||||
kcp.snd_wnd = effectiveConfig.GetSendingWindowSize()
|
||||
kcp.rcv_wnd = effectiveConfig.GetReceivingWindowSize()
|
||||
kcp.rmt_wnd = IKCP_WND_RCV
|
||||
kcp.mss = output.Mtu() - DataSegmentOverhead
|
||||
kcp.rx_rto = IKCP_RTO_DEF
|
||||
kcp.interval = IKCP_INTERVAL
|
||||
kcp.output = NewSegmentWriter(output)
|
||||
kcp.rcv_buf = NewReceivingWindow(receivingWindowSize)
|
||||
kcp.snd_queue = NewSendingQueue(sendingQueueSize)
|
||||
kcp.rcv_buf = NewReceivingWindow(effectiveConfig.GetReceivingWindowSize())
|
||||
kcp.snd_queue = NewSendingQueue(effectiveConfig.GetSendingQueueSize())
|
||||
kcp.rcv_queue = NewReceivingQueue()
|
||||
kcp.acklist = NewACKList(kcp)
|
||||
kcp.snd_buf = NewSendingWindow(kcp, sendingWindowSize)
|
||||
kcp.snd_buf = NewSendingWindow(kcp, effectiveConfig.GetSendingWindowSize())
|
||||
kcp.cwnd = kcp.snd_wnd
|
||||
return kcp
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ type ReceivingQueue struct {
|
||||
|
||||
func NewReceivingQueue() *ReceivingQueue {
|
||||
return &ReceivingQueue{
|
||||
queue: make(chan *alloc.Buffer, effectiveConfig.ReadBuffer/effectiveConfig.Mtu),
|
||||
queue: make(chan *alloc.Buffer, effectiveConfig.GetReceivingQueueSize()),
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user