Skip to content

Commit

Permalink
do not update_ack() when the input packet is recovered from FEC
Browse files Browse the repository at this point in the history
  • Loading branch information
xtaci committed Aug 10, 2016
1 parent 71efae5 commit 83cecdd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions kcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ func (kcp *KCP) parse_data(newseg *Segment) {
}

// 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, update_ack bool) int {
una := kcp.snd_una
if len(data) < IKCP_OVERHEAD {
return -1
Expand Down Expand Up @@ -507,7 +507,7 @@ func (kcp *KCP) Input(data []byte) int {
kcp.shrink_buf()

if cmd == IKCP_CMD_ACK {
if _itimediff(kcp.current, ts) >= 0 {
if update_ack && _itimediff(kcp.current, ts) >= 0 {
kcp.update_ack(_itimediff(kcp.current, ts))
}
kcp.parse_ack(sn)
Expand Down
4 changes: 2 additions & 2 deletions kcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func test(mode int) {
break
}
// 如果 p2收到udp,则作为下层协议输入到kcp2
kcp2.Input(buffer[:hr])
kcp2.Input(buffer[:hr], true)
}

// 处理虚拟网络:检测是否有udp包从p2->p1
Expand All @@ -215,7 +215,7 @@ func test(mode int) {
break
}
// 如果 p1收到udp,则作为下层协议输入到kcp1
kcp1.Input(buffer[:hr])
kcp1.Input(buffer[:hr], true)
//println("@@@@", hr, r)
}

Expand Down
6 changes: 3 additions & 3 deletions sess.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ func (s *UDPSession) kcpInput(data []byte) {
sz := binary.LittleEndian.Uint16(recovers[k])
if int(sz) <= len(recovers[k]) && sz >= 2 {
s.kcp.current = currentMs()
s.kcp.Input(recovers[k][2:sz])
s.kcp.Input(recovers[k][2:sz], false)
atomic.AddUint64(&DefaultSnmp.FECRecovered, 1)
} else {
atomic.AddUint64(&DefaultSnmp.FECErrs, 1)
Expand All @@ -543,12 +543,12 @@ func (s *UDPSession) kcpInput(data []byte) {
}
if f.flag == typeData {
s.kcp.current = currentMs()
s.kcp.Input(data[fecHeaderSizePlus2:])
s.kcp.Input(data[fecHeaderSizePlus2:], true)
}

} else {
s.kcp.current = currentMs()
s.kcp.Input(data)
s.kcp.Input(data, true)
}

if s.ackNoDelay {
Expand Down

0 comments on commit 83cecdd

Please sign in to comment.