|
|
@ -149,22 +149,35 @@ func (this *ReceivingQueue) Close() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type ACKList struct {
|
|
|
|
type ACKList struct {
|
|
|
|
|
|
|
|
kcp *KCP
|
|
|
|
timestamps []uint32
|
|
|
|
timestamps []uint32
|
|
|
|
numbers []uint32
|
|
|
|
numbers []uint32
|
|
|
|
|
|
|
|
nextFlush []uint32
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func NewACKList(kcp *KCP) *ACKList {
|
|
|
|
|
|
|
|
return &ACKList{
|
|
|
|
|
|
|
|
kcp: kcp,
|
|
|
|
|
|
|
|
timestamps: make([]uint32, 0, 32),
|
|
|
|
|
|
|
|
numbers: make([]uint32, 0, 32),
|
|
|
|
|
|
|
|
nextFlush: make([]uint32, 0, 32),
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *ACKList) Add(number uint32, timestamp uint32) {
|
|
|
|
func (this *ACKList) Add(number uint32, timestamp uint32) {
|
|
|
|
this.timestamps = append(this.timestamps, timestamp)
|
|
|
|
this.timestamps = append(this.timestamps, timestamp)
|
|
|
|
this.numbers = append(this.numbers, number)
|
|
|
|
this.numbers = append(this.numbers, number)
|
|
|
|
|
|
|
|
this.nextFlush = append(this.nextFlush, 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *ACKList) Clear(una uint32) bool {
|
|
|
|
func (this *ACKList) Clear(una uint32) {
|
|
|
|
count := 0
|
|
|
|
count := 0
|
|
|
|
for i := 0; i < len(this.numbers); i++ {
|
|
|
|
for i := 0; i < len(this.numbers); i++ {
|
|
|
|
if this.numbers[i] >= una {
|
|
|
|
if this.numbers[i] >= una {
|
|
|
|
if i != count {
|
|
|
|
if i != count {
|
|
|
|
this.numbers[count] = this.numbers[i]
|
|
|
|
this.numbers[count] = this.numbers[i]
|
|
|
|
this.timestamps[count] = this.timestamps[i]
|
|
|
|
this.timestamps[count] = this.timestamps[i]
|
|
|
|
|
|
|
|
this.nextFlush[count] = this.nextFlush[i]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
count++
|
|
|
|
count++
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -172,26 +185,34 @@ func (this *ACKList) Clear(una uint32) bool {
|
|
|
|
if count < len(this.numbers) {
|
|
|
|
if count < len(this.numbers) {
|
|
|
|
this.numbers = this.numbers[:count]
|
|
|
|
this.numbers = this.numbers[:count]
|
|
|
|
this.timestamps = this.timestamps[:count]
|
|
|
|
this.timestamps = this.timestamps[:count]
|
|
|
|
return true
|
|
|
|
this.nextFlush = this.nextFlush[:count]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *ACKList) AsSegment() *ACKSegment {
|
|
|
|
func (this *ACKList) Flush() bool {
|
|
|
|
count := len(this.numbers)
|
|
|
|
seg := &ACKSegment{
|
|
|
|
if count == 0 {
|
|
|
|
Conv: this.kcp.conv,
|
|
|
|
return nil
|
|
|
|
ReceivingNext: this.kcp.rcv_nxt,
|
|
|
|
|
|
|
|
ReceivingWindow: this.kcp.rcv_nxt + this.kcp.rcv_wnd,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if this.kcp.state == StateReadyToClose {
|
|
|
|
if count > 128 {
|
|
|
|
seg.Opt = SegmentOptionClose
|
|
|
|
count = 128
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
seg := &ACKSegment{
|
|
|
|
current := this.kcp.current
|
|
|
|
Count: byte(count),
|
|
|
|
for i := 0; i < len(this.numbers); i++ {
|
|
|
|
NumberList: this.numbers[:count],
|
|
|
|
if this.nextFlush[i] <= current {
|
|
|
|
TimestampList: this.timestamps[:count],
|
|
|
|
seg.Count++
|
|
|
|
|
|
|
|
seg.NumberList = append(seg.NumberList, this.numbers[i])
|
|
|
|
|
|
|
|
seg.TimestampList = append(seg.TimestampList, this.timestamps[i])
|
|
|
|
|
|
|
|
this.nextFlush[i] = current + 50
|
|
|
|
|
|
|
|
if seg.Count == 128 {
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//this.numbers = nil
|
|
|
|
if seg.Count > 0 {
|
|
|
|
//this.timestamps = nil
|
|
|
|
this.kcp.output.Write(seg)
|
|
|
|
return seg
|
|
|
|
return true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|