mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-03 07:56:42 -05:00
refine rto and wnd, temporarily disable congestion control
This commit is contained in:
parent
576b16c2f7
commit
4beeba933c
@ -283,13 +283,10 @@ func (kcp *KCP) update_ack(rtt int32) {
|
|||||||
kcp.rx_srtt = 1
|
kcp.rx_srtt = 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rto = kcp.rx_srtt + _imax_(1, 4*kcp.rx_rttval)
|
rto = kcp.rx_srtt + _imax_(kcp.interval, 4*kcp.rx_rttval)
|
||||||
if rto > IKCP_RTO_MAX {
|
if rto > IKCP_RTO_MAX {
|
||||||
rto = IKCP_RTO_MAX
|
rto = IKCP_RTO_MAX
|
||||||
}
|
}
|
||||||
if rto < kcp.rx_minrto {
|
|
||||||
rto = kcp.rx_minrto
|
|
||||||
}
|
|
||||||
kcp.rx_rto = rto
|
kcp.rx_rto = rto
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -403,7 +400,7 @@ func (kcp *KCP) parse_data(newseg *Segment) {
|
|||||||
|
|
||||||
// Input when you received a low level packet (eg. UDP packet), call it
|
// Input when you received a low level packet (eg. UDP packet), call it
|
||||||
func (kcp *KCP) Input(data []byte) int {
|
func (kcp *KCP) Input(data []byte) int {
|
||||||
una := kcp.snd_una
|
//una := kcp.snd_una
|
||||||
if len(data) < IKCP_OVERHEAD {
|
if len(data) < IKCP_OVERHEAD {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
@ -440,7 +437,10 @@ func (kcp *KCP) Input(data []byte) int {
|
|||||||
return -3
|
return -3
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if kcp.rmt_wnd < uint32(wnd) {
|
||||||
kcp.rmt_wnd = uint32(wnd)
|
kcp.rmt_wnd = uint32(wnd)
|
||||||
|
}
|
||||||
|
//kcp.rmt_wnd = uint32(wnd)
|
||||||
kcp.parse_una(una)
|
kcp.parse_una(una)
|
||||||
kcp.shrink_buf()
|
kcp.shrink_buf()
|
||||||
|
|
||||||
@ -489,6 +489,7 @@ func (kcp *KCP) Input(data []byte) int {
|
|||||||
kcp.parse_fastack(maxack)
|
kcp.parse_fastack(maxack)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
if _itimediff(kcp.snd_una, una) > 0 {
|
if _itimediff(kcp.snd_una, una) > 0 {
|
||||||
if kcp.cwnd < kcp.rmt_wnd {
|
if kcp.cwnd < kcp.rmt_wnd {
|
||||||
mss := kcp.mss
|
mss := kcp.mss
|
||||||
@ -509,24 +510,17 @@ func (kcp *KCP) Input(data []byte) int {
|
|||||||
kcp.incr = kcp.rmt_wnd * mss
|
kcp.incr = kcp.rmt_wnd * mss
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (kcp *KCP) wnd_unused() int32 {
|
|
||||||
if len(kcp.rcv_queue) < int(kcp.rcv_wnd) {
|
|
||||||
return int32(int(kcp.rcv_wnd) - len(kcp.rcv_queue))
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// flush pending data
|
// flush pending data
|
||||||
func (kcp *KCP) flush() {
|
func (kcp *KCP) flush() {
|
||||||
current := kcp.current
|
current := kcp.current
|
||||||
buffer := kcp.buffer
|
buffer := kcp.buffer
|
||||||
change := 0
|
change := 0
|
||||||
lost := false
|
//lost := false
|
||||||
|
|
||||||
if kcp.updated == 0 {
|
if kcp.updated == 0 {
|
||||||
return
|
return
|
||||||
@ -534,7 +528,7 @@ func (kcp *KCP) flush() {
|
|||||||
var seg Segment
|
var seg Segment
|
||||||
seg.conv = kcp.conv
|
seg.conv = kcp.conv
|
||||||
seg.cmd = IKCP_CMD_ACK
|
seg.cmd = IKCP_CMD_ACK
|
||||||
seg.wnd = uint32(kcp.wnd_unused())
|
seg.wnd = uint32(kcp.rcv_nxt + kcp.rcv_wnd)
|
||||||
seg.una = kcp.rcv_nxt
|
seg.una = kcp.rcv_nxt
|
||||||
|
|
||||||
// flush acknowledges
|
// flush acknowledges
|
||||||
@ -552,6 +546,7 @@ func (kcp *KCP) flush() {
|
|||||||
kcp.acklist = nil
|
kcp.acklist = nil
|
||||||
|
|
||||||
// probe window size (if remote window size equals zero)
|
// probe window size (if remote window size equals zero)
|
||||||
|
/*
|
||||||
if kcp.rmt_wnd == 0 {
|
if kcp.rmt_wnd == 0 {
|
||||||
if kcp.probe_wait == 0 {
|
if kcp.probe_wait == 0 {
|
||||||
kcp.probe_wait = IKCP_PROBE_INIT
|
kcp.probe_wait = IKCP_PROBE_INIT
|
||||||
@ -572,9 +567,10 @@ func (kcp *KCP) flush() {
|
|||||||
} else {
|
} else {
|
||||||
kcp.ts_probe = 0
|
kcp.ts_probe = 0
|
||||||
kcp.probe_wait = 0
|
kcp.probe_wait = 0
|
||||||
}
|
}*/
|
||||||
|
|
||||||
// flush window probing commands
|
// flush window probing commands
|
||||||
|
/*
|
||||||
if (kcp.probe & IKCP_ASK_SEND) != 0 {
|
if (kcp.probe & IKCP_ASK_SEND) != 0 {
|
||||||
seg.cmd = IKCP_CMD_WASK
|
seg.cmd = IKCP_CMD_WASK
|
||||||
size := len(buffer) - len(ptr)
|
size := len(buffer) - len(ptr)
|
||||||
@ -583,9 +579,10 @@ func (kcp *KCP) flush() {
|
|||||||
ptr = buffer
|
ptr = buffer
|
||||||
}
|
}
|
||||||
ptr = seg.encode(ptr)
|
ptr = seg.encode(ptr)
|
||||||
}
|
}*/
|
||||||
|
|
||||||
// flush window probing commands
|
// flush window probing commands
|
||||||
|
/*
|
||||||
if (kcp.probe & IKCP_ASK_TELL) != 0 {
|
if (kcp.probe & IKCP_ASK_TELL) != 0 {
|
||||||
seg.cmd = IKCP_CMD_WINS
|
seg.cmd = IKCP_CMD_WINS
|
||||||
size := len(buffer) - len(ptr)
|
size := len(buffer) - len(ptr)
|
||||||
@ -596,17 +593,18 @@ func (kcp *KCP) flush() {
|
|||||||
ptr = seg.encode(ptr)
|
ptr = seg.encode(ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
kcp.probe = 0
|
kcp.probe = 0*/
|
||||||
|
|
||||||
// calculate window size
|
// calculate window size
|
||||||
cwnd := _imin_(kcp.snd_wnd, kcp.rmt_wnd)
|
|
||||||
|
cwnd := _imin_(kcp.snd_nxt+kcp.snd_wnd, kcp.rmt_wnd)
|
||||||
if kcp.congestionControl {
|
if kcp.congestionControl {
|
||||||
cwnd = _imin_(kcp.cwnd, cwnd)
|
cwnd = _imin_(kcp.cwnd, cwnd)
|
||||||
}
|
}
|
||||||
|
|
||||||
count = 0
|
count = 0
|
||||||
for k := range kcp.snd_queue {
|
for k := range kcp.snd_queue {
|
||||||
if _itimediff(kcp.snd_nxt, kcp.snd_una+cwnd) >= 0 {
|
if _itimediff(kcp.snd_nxt, cwnd) >= 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
newseg := kcp.snd_queue[k]
|
newseg := kcp.snd_queue[k]
|
||||||
@ -631,10 +629,10 @@ func (kcp *KCP) flush() {
|
|||||||
if kcp.fastresend <= 0 {
|
if kcp.fastresend <= 0 {
|
||||||
resent = 0xffffffff
|
resent = 0xffffffff
|
||||||
}
|
}
|
||||||
rtomin := (kcp.rx_rto >> 3)
|
//rtomin := (kcp.rx_rto >> 3)
|
||||||
if kcp.nodelay != 0 {
|
//if kcp.nodelay != 0 {
|
||||||
rtomin = 0
|
// rtomin = 0
|
||||||
}
|
//}
|
||||||
|
|
||||||
// flush data segments
|
// flush data segments
|
||||||
for _, segment := range kcp.snd_buf {
|
for _, segment := range kcp.snd_buf {
|
||||||
@ -643,23 +641,23 @@ func (kcp *KCP) flush() {
|
|||||||
needsend = true
|
needsend = true
|
||||||
segment.xmit++
|
segment.xmit++
|
||||||
segment.rto = kcp.rx_rto
|
segment.rto = kcp.rx_rto
|
||||||
segment.resendts = current + segment.rto + rtomin
|
segment.resendts = current + segment.rto + kcp.interval
|
||||||
} else if _itimediff(current, segment.resendts) >= 0 {
|
} else if _itimediff(current, segment.resendts) >= 0 {
|
||||||
needsend = true
|
needsend = true
|
||||||
segment.xmit++
|
segment.xmit++
|
||||||
kcp.xmit++
|
kcp.xmit++
|
||||||
if kcp.nodelay == 0 {
|
//if kcp.nodelay == 0 {
|
||||||
segment.rto += kcp.rx_rto
|
segment.rto += kcp.rx_rto
|
||||||
} else {
|
//} else {
|
||||||
segment.rto += kcp.rx_rto / 2
|
// segment.rto += kcp.rx_rto / 2
|
||||||
}
|
//}
|
||||||
segment.resendts = current + segment.rto
|
segment.resendts = current + segment.rto + kcp.interval
|
||||||
lost = true
|
//lost = true
|
||||||
} else if segment.fastack >= resent {
|
} else if segment.fastack >= resent {
|
||||||
needsend = true
|
needsend = true
|
||||||
segment.xmit++
|
segment.xmit++
|
||||||
segment.fastack = 0
|
segment.fastack = 0
|
||||||
segment.resendts = current + segment.rto
|
segment.resendts = current + segment.rto + kcp.interval
|
||||||
change++
|
change++
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -694,6 +692,7 @@ func (kcp *KCP) flush() {
|
|||||||
|
|
||||||
// update ssthresh
|
// update ssthresh
|
||||||
// rate halving, https://tools.ietf.org/html/rfc6937
|
// rate halving, https://tools.ietf.org/html/rfc6937
|
||||||
|
/*
|
||||||
if change != 0 {
|
if change != 0 {
|
||||||
inflight := kcp.snd_nxt - kcp.snd_una
|
inflight := kcp.snd_nxt - kcp.snd_una
|
||||||
kcp.ssthresh = inflight / 2
|
kcp.ssthresh = inflight / 2
|
||||||
@ -702,9 +701,10 @@ func (kcp *KCP) flush() {
|
|||||||
}
|
}
|
||||||
kcp.cwnd = kcp.ssthresh + resent
|
kcp.cwnd = kcp.ssthresh + resent
|
||||||
kcp.incr = kcp.cwnd * kcp.mss
|
kcp.incr = kcp.cwnd * kcp.mss
|
||||||
}
|
}*/
|
||||||
|
|
||||||
// congestion control, https://tools.ietf.org/html/rfc5681
|
// congestion control, https://tools.ietf.org/html/rfc5681
|
||||||
|
/*
|
||||||
if lost {
|
if lost {
|
||||||
kcp.ssthresh = cwnd / 2
|
kcp.ssthresh = cwnd / 2
|
||||||
if kcp.ssthresh < IKCP_THRESH_MIN {
|
if kcp.ssthresh < IKCP_THRESH_MIN {
|
||||||
@ -717,7 +717,7 @@ func (kcp *KCP) flush() {
|
|||||||
if kcp.cwnd < 1 {
|
if kcp.cwnd < 1 {
|
||||||
kcp.cwnd = 1
|
kcp.cwnd = 1
|
||||||
kcp.incr = kcp.mss
|
kcp.incr = kcp.mss
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update updates state (call it repeatedly, every 10ms-100ms), or you can ask
|
// Update updates state (call it repeatedly, every 10ms-100ms), or you can ask
|
||||||
|
Loading…
Reference in New Issue
Block a user