mirror of
https://github.com/soypat/lneto.git
synced 2026-08-28 10:29:05 +00:00
now supports partial packet acks
This commit is contained in:
+3
-3
@@ -192,7 +192,7 @@ func (rtx *ringTx) RecvACK(ack Value) error {
|
|||||||
acked := int(ack - pkt.seq)
|
acked := int(ack - pkt.seq)
|
||||||
pring := rtx.ring(pkt.off, pkt.end)
|
pring := rtx.ring(pkt.off, pkt.end)
|
||||||
buffered := pring.Buffered()
|
buffered := pring.Buffered()
|
||||||
if acked > buffered || acked <= minBufferSize {
|
if acked > buffered || acked < minBufferSize {
|
||||||
panic("unreachable")
|
panic("unreachable")
|
||||||
}
|
}
|
||||||
off := rtx.addOff(pkt.off, acked)
|
off := rtx.addOff(pkt.off, acked)
|
||||||
@@ -266,7 +266,7 @@ func (rtx *ringTx) firstPkt() int {
|
|||||||
idx := -1
|
idx := -1
|
||||||
for i := 0; i < len(rtx.packets); i++ {
|
for i := 0; i < len(rtx.packets); i++ {
|
||||||
pkt := &rtx.packets[i]
|
pkt := &rtx.packets[i]
|
||||||
if pkt.sent() && (idx == -1 || seq.LessThan(pkt.seq)) {
|
if pkt.sent() && (idx == -1 || pkt.seq.LessThan(seq)) {
|
||||||
seq = pkt.seq
|
seq = pkt.seq
|
||||||
idx = i
|
idx = i
|
||||||
}
|
}
|
||||||
@@ -279,7 +279,7 @@ func (rtx *ringTx) lastPkt() int {
|
|||||||
idx := -1
|
idx := -1
|
||||||
for i := 0; i < len(rtx.packets); i++ {
|
for i := 0; i < len(rtx.packets); i++ {
|
||||||
pkt := &rtx.packets[i]
|
pkt := &rtx.packets[i]
|
||||||
if pkt.sent() && (idx == -1 || pkt.seq.LessThan(seq)) {
|
if pkt.sent() && (idx == -1 || seq.LessThan(pkt.seq)) {
|
||||||
seq = pkt.seq
|
seq = pkt.seq
|
||||||
idx = i
|
idx = i
|
||||||
}
|
}
|
||||||
|
|||||||
+28
-2
@@ -12,9 +12,12 @@ func TestTxQueue(t *testing.T) {
|
|||||||
const bufsize = 1024
|
const bufsize = 1024
|
||||||
var msgBuf, ringBuf, readBuf, aux [bufsize]byte
|
var msgBuf, ringBuf, readBuf, aux [bufsize]byte
|
||||||
rng := rand.New(rand.NewSource(1))
|
rng := rand.New(rand.NewSource(1))
|
||||||
|
panicked := true
|
||||||
var rtx ringTx
|
var rtx ringTx
|
||||||
defer func() {
|
defer func() {
|
||||||
|
if panicked {
|
||||||
|
t.Error("panicked, rtx:\n", rtx.string())
|
||||||
|
}
|
||||||
testQueueSanity(t, &rtx)
|
testQueueSanity(t, &rtx)
|
||||||
}()
|
}()
|
||||||
increasingComplexityTests := []struct {
|
increasingComplexityTests := []struct {
|
||||||
@@ -92,7 +95,7 @@ func TestTxQueue(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
2: {
|
2: {
|
||||||
name: "ParialAcks",
|
name: "PartialAcks",
|
||||||
test: func(t *testing.T) {
|
test: func(t *testing.T) {
|
||||||
const startAck = 0
|
const startAck = 0
|
||||||
const packets = 100
|
const packets = 100
|
||||||
@@ -153,6 +156,7 @@ func TestTxQueue(t *testing.T) {
|
|||||||
t.Fatalf("subtest %d/%d %q failed, not running more complex tests until fixed", i+1, len(increasingComplexityTests), test.name)
|
t.Fatalf("subtest %d/%d %q failed, not running more complex tests until fixed", i+1, len(increasingComplexityTests), test.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
panicked = false
|
||||||
}
|
}
|
||||||
|
|
||||||
func testQueueSanity(t *testing.T, rtx *ringTx) {
|
func testQueueSanity(t *testing.T, rtx *ringTx) {
|
||||||
@@ -213,6 +217,28 @@ func testQueueSanity(t *testing.T, rtx *ringTx) {
|
|||||||
} else if !allEmpty && sentEmpty && unsentEmpty {
|
} else if !allEmpty && sentEmpty && unsentEmpty {
|
||||||
t.Fatal("all buffer not empty but sent&unsentempty")
|
t.Fatal("all buffer not empty but sent&unsentempty")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check sanenness of last/first packets.
|
||||||
|
last := rtx.lastPkt()
|
||||||
|
first := rtx.firstPkt()
|
||||||
|
if first < 0 && last >= 0 || last < 0 && first >= 0 {
|
||||||
|
t.Fatalf("found first/last(%d,%d) but did not find last/first", first, last)
|
||||||
|
}
|
||||||
|
// Check sent data or return if no sent data available.
|
||||||
|
if sent == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
lastPkt := rtx.pkt(last)
|
||||||
|
endseq, ok := rtx.endSeq()
|
||||||
|
firstPkt := rtx.pkt(first)
|
||||||
|
lastEndSeq := Add(lastPkt.seq, lastPkt.size)
|
||||||
|
if lastPkt.seq.LessThan(firstPkt.seq) {
|
||||||
|
t.Fatalf("first packet not previous to last packet seq, wanted %d<%d", firstPkt.seq, lastPkt.seq)
|
||||||
|
} else if !ok {
|
||||||
|
t.Fatal("unexpected end sequence not found")
|
||||||
|
} else if lastEndSeq != endseq {
|
||||||
|
t.Fatalf("last packet end sequence not match with got endSeq %d!=%d", lastEndSeq, endseq)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rx *ringTx) string() string {
|
func (rx *ringTx) string() string {
|
||||||
|
|||||||
Reference in New Issue
Block a user