Lock seqbuf for at least the duration of the RTT

This commit is contained in:
Nonoo 2020-11-22 14:01:59 +01:00
parent 7b6194a702
commit b06ea77b59
2 changed files with 10 additions and 2 deletions

View file

@ -27,6 +27,8 @@ type pkt7Type struct {
periodicStopFinishedChan chan bool
}
var controlStreamLatency time.Duration
func (p *pkt7Type) isPkt7(r []byte) bool {
return len(r) == 21 && bytes.Equal(r[1:6], []byte{0x00, 0x00, 0x00, 0x07, 0x00}) // Note that the first byte can be 0x15 or 0x00, so we ignore that.
}
@ -54,6 +56,8 @@ func (p *pkt7Type) handle(s *streamCommon, r []byte) error {
p.latency += time.Since(p.lastSendAt)
p.latency /= 2
statusLog.reportRTTLatency(p.latency)
controlStreamLatency = p.latency
}
}

View file

@ -228,8 +228,12 @@ func (s *seqBuf) add(seq seqNum, data []byte) error {
func (s *seqBuf) checkLockTimeout() (timeout bool, shouldRetryIn time.Duration) {
timeSinceLastInvalidSeq := time.Since(s.lockedAt)
if s.length > timeSinceLastInvalidSeq {
shouldRetryIn = s.length - timeSinceLastInvalidSeq
lockDuration := s.length
if lockDuration < controlStreamLatency*2 {
lockDuration = controlStreamLatency * 2
}
if lockDuration > timeSinceLastInvalidSeq {
shouldRetryIn = lockDuration - timeSinceLastInvalidSeq
return
}