1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 10:08:15 -05:00

update kcp sending worker

This commit is contained in:
Darien Raymond 2016-11-13 22:27:58 +01:00
parent 2115089d67
commit 0cd9f5165f
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

View File

@ -77,14 +77,14 @@ func (this *SendingWindow) Clear(una uint32) {
} }
} }
func (this *SendingWindow) Remove(idx uint32) { func (this *SendingWindow) Remove(idx uint32) bool {
if this.len == 0 { if this.len == 0 {
return return false
} }
pos := (this.start + idx) % this.cap pos := (this.start + idx) % this.cap
if !this.inuse[pos] { if !this.inuse[pos] {
return return false
} }
this.inuse[pos] = false this.inuse[pos] = false
this.totalInFlightSize-- this.totalInFlightSize--
@ -105,6 +105,7 @@ func (this *SendingWindow) Remove(idx uint32) {
this.next[this.prev[pos]] = this.next[pos] this.next[this.prev[pos]] = this.next[pos]
this.prev[this.next[pos]] = this.prev[pos] this.prev[this.next[pos]] = this.prev[pos]
} }
return true
} }
func (this *SendingWindow) HandleFastAck(number uint32, rto uint32) { func (this *SendingWindow) HandleFastAck(number uint32, rto uint32) {
@ -219,14 +220,17 @@ func (this *SendingWorker) FindFirstUnacknowledged() {
} }
// Private: Visible for testing. // Private: Visible for testing.
func (this *SendingWorker) ProcessAck(number uint32) { func (this *SendingWorker) ProcessAck(number uint32) bool {
// number < this.firstUnacknowledged || number >= this.nextNumber // number < this.firstUnacknowledged || number >= this.nextNumber
if number-this.firstUnacknowledged > 0x7FFFFFFF || number-this.nextNumber < 0x7FFFFFFF { if number-this.firstUnacknowledged > 0x7FFFFFFF || number-this.nextNumber < 0x7FFFFFFF {
return return false
} }
this.window.Remove(number - this.firstUnacknowledged) removed := this.window.Remove(number - this.firstUnacknowledged)
this.FindFirstUnacknowledged() if removed {
this.FindFirstUnacknowledged()
}
return removed
} }
func (this *SendingWorker) ProcessSegment(current uint32, seg *AckSegment, rto uint32) { func (this *SendingWorker) ProcessSegment(current uint32, seg *AckSegment, rto uint32) {
@ -239,21 +243,25 @@ func (this *SendingWorker) ProcessSegment(current uint32, seg *AckSegment, rto u
this.remoteNextNumber = seg.ReceivingWindow this.remoteNextNumber = seg.ReceivingWindow
} }
this.ProcessReceivingNextWithoutLock(seg.ReceivingNext) this.ProcessReceivingNextWithoutLock(seg.ReceivingNext)
if current-seg.Timestamp < 10000 {
this.conn.roundTrip.Update(current-seg.Timestamp, current)
}
var maxack uint32 var maxack uint32
var maxackRemoved bool
for i := 0; i < int(seg.Count); i++ { for i := 0; i < int(seg.Count); i++ {
number := seg.NumberList[i] number := seg.NumberList[i]
this.ProcessAck(number) removed := this.ProcessAck(number)
if maxack < number { if maxack < number {
maxack = number maxack = number
maxackRemoved = removed
} }
} }
this.window.HandleFastAck(maxack, rto) if maxackRemoved {
this.window.HandleFastAck(maxack, rto)
if current-seg.Timestamp < 10000 {
this.conn.roundTrip.Update(current-seg.Timestamp, current)
}
}
} }
func (this *SendingWorker) Push(b []byte) int { func (this *SendingWorker) Push(b []byte) int {