Fixes for the TX seqbuf

This commit is contained in:
Nonoo 2020-10-29 22:30:42 +01:00
parent 2253c87cfc
commit a9be72afba

View file

@ -2,6 +2,9 @@ package main
import "time"
// This value is sent to the transceiver and - according to my observations - it will use
// this is it's RX buf length. Note that if it is set to larger than 500-600ms then audio TX
// won't work (small radio memory?)
const txSeqBufLength = 300 * time.Millisecond
type txSeqBufStruct struct {
@ -18,7 +21,9 @@ func (s *txSeqBufStruct) add(seq seqNum, p []byte) {
}
func (s *txSeqBufStruct) purgeOldEntries() {
for len(s.entries) > 0 && time.Since(s.entries[0].addedAt) > txSeqBufLength*2 {
// We keep much more entries than the specified length of the TX seqbuf, so we can serve
// any requests coming from the server.
for len(s.entries) > 0 && time.Since(s.entries[0].addedAt) > txSeqBufLength*10 {
s.entries = s.entries[1:]
}
}
@ -31,7 +36,8 @@ func (s *txSeqBufStruct) get(seq seqNum) (d []byte) {
// Searching from backwards, as we expect most queries for latest entries.
for i := len(s.entries) - 1; i >= 0; i-- {
if s.entries[i].seq == seq {
d = s.entries[i].data
d := make([]byte, len(s.entries[i].data))
copy(d, s.entries[i].data)
break
}
}