mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-07 06:07:36 +03:00
42 lines
933 B
Go
42 lines
933 B
Go
package quic
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/lucas-clemente/quic-go/frames"
|
|
"github.com/lucas-clemente/quic-go/protocol"
|
|
)
|
|
|
|
type blockedManager struct {
|
|
blockedStreams map[protocol.StreamID]protocol.ByteCount
|
|
mutex sync.RWMutex
|
|
}
|
|
|
|
func newBlockedManager() *blockedManager {
|
|
return &blockedManager{
|
|
blockedStreams: make(map[protocol.StreamID]protocol.ByteCount),
|
|
}
|
|
}
|
|
|
|
func (m *blockedManager) AddBlockedStream(streamID protocol.StreamID, offset protocol.ByteCount) {
|
|
m.mutex.Lock()
|
|
defer m.mutex.Unlock()
|
|
|
|
m.blockedStreams[streamID] = offset
|
|
}
|
|
|
|
func (m *blockedManager) GetBlockedFrame(streamID protocol.StreamID, offset protocol.ByteCount) *frames.BlockedFrame {
|
|
m.mutex.RLock()
|
|
defer m.mutex.RUnlock()
|
|
|
|
blockedOffset, ok := m.blockedStreams[streamID]
|
|
if !ok {
|
|
return nil
|
|
}
|
|
if blockedOffset > offset {
|
|
return nil
|
|
}
|
|
|
|
delete(m.blockedStreams, streamID)
|
|
return &frames.BlockedFrame{StreamID: streamID}
|
|
}
|