Skip to content

Commit 0e5741b

Browse files
committed
use latest packet compare
1 parent 97999b9 commit 0e5741b

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

fec.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,9 @@ type (
279279
payloadOffset int // FEC payload offset
280280

281281
// caches
282-
shardCache [][]byte
283-
encodeCache [][]byte
284-
tsCache []int64
282+
shardCache [][]byte
283+
encodeCache [][]byte
284+
tsLatestPacket int64
285285

286286
// RS encoder
287287
codec reedsolomon.Encoder
@@ -309,7 +309,6 @@ func newFECEncoder(dataShards, parityShards, offset, minRTO int) *fecEncoder {
309309
// caches
310310
enc.encodeCache = make([][]byte, enc.shardSize)
311311
enc.shardCache = make([][]byte, enc.shardSize)
312-
enc.tsCache = make([]int64, enc.shardSize)
313312
for k := range enc.shardCache {
314313
enc.shardCache[k] = make([]byte, mtuLimit)
315314
}
@@ -329,7 +328,6 @@ func (enc *fecEncoder) encode(b []byte, rto uint32) (ps [][]byte) {
329328
sz := len(b)
330329
enc.shardCache[enc.shardCount] = enc.shardCache[enc.shardCount][:sz]
331330
copy(enc.shardCache[enc.shardCount][enc.payloadOffset:], b[enc.payloadOffset:])
332-
enc.tsCache[enc.shardCount] = time.Now().UnixMilli()
333331
enc.shardCount++
334332

335333
// track max datashard length
@@ -338,9 +336,10 @@ func (enc *fecEncoder) encode(b []byte, rto uint32) (ps [][]byte) {
338336
}
339337

340338
// Generation of Reed-Solomon Erasure Code
339+
now := time.Now().UnixMilli()
341340
if enc.shardCount == enc.dataShards {
342341
// generate the rs-code only if the data is continuous.
343-
if enc.tsCache[enc.shardCount-1]-enc.tsCache[0] < int64(rto) {
342+
if now-enc.tsLatestPacket < int64(rto) {
344343
// fill '0' into the tail of each datashard
345344
for i := 0; i < enc.dataShards; i++ {
346345
shard := enc.shardCache[i]
@@ -369,6 +368,8 @@ func (enc *fecEncoder) encode(b []byte, rto uint32) (ps [][]byte) {
369368
enc.maxSize = 0
370369
}
371370

371+
enc.tsLatestPacket = now
372+
372373
return
373374
}
374375

0 commit comments

Comments
 (0)