mirror of
https://github.com/nonoo/kappanhang.git
synced 2025-12-06 08:02:00 +01:00
Lock seqbuf for at least the duration of the RTT
This commit is contained in:
parent
7b6194a702
commit
b06ea77b59
4
pkt7.go
4
pkt7.go
|
|
@ -27,6 +27,8 @@ type pkt7Type struct {
|
||||||
periodicStopFinishedChan chan bool
|
periodicStopFinishedChan chan bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var controlStreamLatency time.Duration
|
||||||
|
|
||||||
func (p *pkt7Type) isPkt7(r []byte) bool {
|
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.
|
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 += time.Since(p.lastSendAt)
|
||||||
p.latency /= 2
|
p.latency /= 2
|
||||||
statusLog.reportRTTLatency(p.latency)
|
statusLog.reportRTTLatency(p.latency)
|
||||||
|
|
||||||
|
controlStreamLatency = p.latency
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -228,8 +228,12 @@ func (s *seqBuf) add(seq seqNum, data []byte) error {
|
||||||
|
|
||||||
func (s *seqBuf) checkLockTimeout() (timeout bool, shouldRetryIn time.Duration) {
|
func (s *seqBuf) checkLockTimeout() (timeout bool, shouldRetryIn time.Duration) {
|
||||||
timeSinceLastInvalidSeq := time.Since(s.lockedAt)
|
timeSinceLastInvalidSeq := time.Since(s.lockedAt)
|
||||||
if s.length > timeSinceLastInvalidSeq {
|
lockDuration := s.length
|
||||||
shouldRetryIn = s.length - timeSinceLastInvalidSeq
|
if lockDuration < controlStreamLatency*2 {
|
||||||
|
lockDuration = controlStreamLatency * 2
|
||||||
|
}
|
||||||
|
if lockDuration > timeSinceLastInvalidSeq {
|
||||||
|
shouldRetryIn = lockDuration - timeSinceLastInvalidSeq
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue