@@ -279,9 +279,9 @@ type (
279
279
payloadOffset int // FEC payload offset
280
280
281
281
// caches
282
- shardCache [][]byte
283
- encodeCache [][]byte
284
- tsCache [] int64
282
+ shardCache [][]byte
283
+ encodeCache [][]byte
284
+ tsLatestPacket int64
285
285
286
286
// RS encoder
287
287
codec reedsolomon.Encoder
@@ -309,7 +309,6 @@ func newFECEncoder(dataShards, parityShards, offset, minRTO int) *fecEncoder {
309
309
// caches
310
310
enc .encodeCache = make ([][]byte , enc .shardSize )
311
311
enc .shardCache = make ([][]byte , enc .shardSize )
312
- enc .tsCache = make ([]int64 , enc .shardSize )
313
312
for k := range enc .shardCache {
314
313
enc .shardCache [k ] = make ([]byte , mtuLimit )
315
314
}
@@ -329,7 +328,6 @@ func (enc *fecEncoder) encode(b []byte, rto uint32) (ps [][]byte) {
329
328
sz := len (b )
330
329
enc .shardCache [enc .shardCount ] = enc .shardCache [enc .shardCount ][:sz ]
331
330
copy (enc .shardCache [enc .shardCount ][enc .payloadOffset :], b [enc .payloadOffset :])
332
- enc .tsCache [enc .shardCount ] = time .Now ().UnixMilli ()
333
331
enc .shardCount ++
334
332
335
333
// track max datashard length
@@ -338,9 +336,10 @@ func (enc *fecEncoder) encode(b []byte, rto uint32) (ps [][]byte) {
338
336
}
339
337
340
338
// Generation of Reed-Solomon Erasure Code
339
+ now := time .Now ().UnixMilli ()
341
340
if enc .shardCount == enc .dataShards {
342
341
// 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 ) {
344
343
// fill '0' into the tail of each datashard
345
344
for i := 0 ; i < enc .dataShards ; i ++ {
346
345
shard := enc .shardCache [i ]
@@ -369,6 +368,8 @@ func (enc *fecEncoder) encode(b []byte, rto uint32) (ps [][]byte) {
369
368
enc .maxSize = 0
370
369
}
371
370
371
+ enc .tsLatestPacket = now
372
+
372
373
return
373
374
}
374
375
0 commit comments