Forráskód Böngészése

Fix receiving update

v2ray 9 éve
szülő
commit
71c9bd678c
2 módosított fájl, 14 hozzáadás és 5 törlés
  1. 7 2
      transport/internet/kcp/kcp.go
  2. 7 3
      transport/internet/kcp/receiving.go

+ 7 - 2
transport/internet/kcp/kcp.go

@@ -183,6 +183,7 @@ func (kcp *KCP) DumpReceivingBuf() {
 		kcp.rcv_queue = append(kcp.rcv_queue, seg)
 		kcp.rcv_buf.Advance()
 		kcp.rcv_nxt++
+		kcp.receivingUpdated = true
 	}
 }
 
@@ -288,8 +289,9 @@ func (kcp *KCP) HandleReceivingNext(receivingNext uint32) {
 }
 
 func (kcp *KCP) HandleSendingNext(sendingNext uint32) {
-	kcp.acklist.Clear(sendingNext)
-	kcp.receivingUpdated = true
+	if kcp.acklist.Clear(sendingNext) {
+		kcp.receivingUpdated = true
+	}
 }
 
 func (kcp *KCP) parse_data(newseg *DataSegment) {
@@ -325,6 +327,7 @@ func (kcp *KCP) Input(data []byte) int {
 			kcp.HandleOption(seg.Opt)
 			kcp.HandleSendingNext(seg.SendingNext)
 			kcp.acklist.Add(seg.Number, seg.Timestamp)
+			kcp.receivingUpdated = true
 			kcp.parse_data(seg)
 			kcp.lastPayloadTime = kcp.current
 		case *ACKSegment:
@@ -407,6 +410,7 @@ func (kcp *KCP) flush() {
 	lost := false
 
 	// flush acknowledges
+	//if kcp.receivingUpdated {
 	ackSeg := kcp.acklist.AsSegment()
 	if ackSeg != nil {
 		ackSeg.Conv = kcp.conv
@@ -415,6 +419,7 @@ func (kcp *KCP) flush() {
 		kcp.output.Write(ackSeg)
 		kcp.receivingUpdated = false
 	}
+	//}
 
 	// calculate window size
 	cwnd := _imin_(kcp.snd_una+kcp.snd_wnd, kcp.rmt_wnd)

+ 7 - 3
transport/internet/kcp/receiving.go

@@ -59,7 +59,7 @@ func (this *ACKList) Add(number uint32, timestamp uint32) {
 	this.numbers = append(this.numbers, number)
 }
 
-func (this *ACKList) Clear(una uint32) {
+func (this *ACKList) Clear(una uint32) bool {
 	count := 0
 	for i := 0; i < len(this.numbers); i++ {
 		if this.numbers[i] >= una {
@@ -70,8 +70,12 @@ func (this *ACKList) Clear(una uint32) {
 			count++
 		}
 	}
-	this.numbers = this.numbers[:count]
-	this.timestamps = this.timestamps[:count]
+	if count < len(this.numbers) {
+		this.numbers = this.numbers[:count]
+		this.timestamps = this.timestamps[:count]
+		return true
+	}
+	return false
 }
 
 func (this *ACKList) AsSegment() *ACKSegment {