diff --git a/flowcontrol/flow_controller.go b/flowcontrol/flow_controller.go index 343eaa58..d242f878 100644 --- a/flowcontrol/flow_controller.go +++ b/flowcontrol/flow_controller.go @@ -1,8 +1,6 @@ package flowcontrol import ( - "sync" - "github.com/lucas-clemente/quic-go/handshake" "github.com/lucas-clemente/quic-go/protocol" ) @@ -19,8 +17,6 @@ type flowController struct { highestReceived protocol.ByteCount receiveFlowControlWindow protocol.ByteCount receiveFlowControlWindowIncrement protocol.ByteCount - - mutex sync.RWMutex } // newFlowController gets a new flow controller @@ -52,18 +48,12 @@ func (c *flowController) getSendFlowControlWindow() protocol.ByteCount { } func (c *flowController) AddBytesSent(n protocol.ByteCount) { - c.mutex.Lock() - defer c.mutex.Unlock() - c.bytesSent += n } // UpdateSendWindow should be called after receiving a WindowUpdateFrame // it returns true if the window was actually updated func (c *flowController) UpdateSendWindow(newOffset protocol.ByteCount) bool { - c.mutex.Lock() - defer c.mutex.Unlock() - if newOffset > c.sendFlowControlWindow { c.sendFlowControlWindow = newOffset return true @@ -73,9 +63,6 @@ func (c *flowController) UpdateSendWindow(newOffset protocol.ByteCount) bool { // TODO: remove once the Stream doesn't use it anymore func (c *flowController) SendWindowSize() protocol.ByteCount { - c.mutex.RLock() - defer c.mutex.RUnlock() - sendFlowControlWindow := c.getSendFlowControlWindow() if c.bytesSent > sendFlowControlWindow { // should never happen, but make sure we don't do an underflow here @@ -85,18 +72,12 @@ func (c *flowController) SendWindowSize() protocol.ByteCount { } func (c *flowController) SendWindowOffset() protocol.ByteCount { - c.mutex.RLock() - defer c.mutex.RUnlock() - return c.getSendFlowControlWindow() } // UpdateHighestReceived updates the highestReceived value, if the byteOffset is higher // Should **only** be used for the stream-level FlowController func (c *flowController) UpdateHighestReceived(byteOffset protocol.ByteCount) protocol.ByteCount { - c.mutex.Lock() - defer c.mutex.Unlock() - if byteOffset > c.highestReceived { increment := byteOffset - c.highestReceived c.highestReceived = byteOffset @@ -108,25 +89,16 @@ func (c *flowController) UpdateHighestReceived(byteOffset protocol.ByteCount) pr // IncrementHighestReceived adds an increment to the highestReceived value // Should **only** be used for the connection-level FlowController func (c *flowController) IncrementHighestReceived(increment protocol.ByteCount) { - c.mutex.Lock() - defer c.mutex.Unlock() - c.highestReceived += increment } func (c *flowController) AddBytesRead(n protocol.ByteCount) { - c.mutex.Lock() - defer c.mutex.Unlock() - c.bytesRead += n } // MaybeTriggerWindowUpdate determines if it is necessary to send a WindowUpdate // if so, it returns true and the offset of the window func (c *flowController) MaybeTriggerWindowUpdate() (bool, protocol.ByteCount) { - c.mutex.Lock() - defer c.mutex.Unlock() - diff := c.receiveFlowControlWindow - c.bytesRead // Chromium implements the same threshold if diff < (c.receiveFlowControlWindowIncrement / 2) { @@ -137,9 +109,6 @@ func (c *flowController) MaybeTriggerWindowUpdate() (bool, protocol.ByteCount) { } func (c *flowController) CheckFlowControlViolation() bool { - c.mutex.Lock() - defer c.mutex.Unlock() - if c.highestReceived > c.receiveFlowControlWindow { return true }