forked from quic-go/quic-go
create interface for the ConnectionParametersManager
This commit is contained in:
@@ -11,8 +11,8 @@ import (
|
||||
)
|
||||
|
||||
type flowControlManager struct {
|
||||
connectionParametersManager *handshake.ConnectionParametersManager
|
||||
rttStats *congestion.RTTStats
|
||||
connectionParameters handshake.ConnectionParametersManager
|
||||
rttStats *congestion.RTTStats
|
||||
|
||||
streamFlowController map[protocol.StreamID]*flowController
|
||||
contributesToConnectionFlowControl map[protocol.StreamID]bool
|
||||
@@ -29,15 +29,15 @@ var (
|
||||
var errMapAccess = errors.New("Error accessing the flowController map.")
|
||||
|
||||
// NewFlowControlManager creates a new flow control manager
|
||||
func NewFlowControlManager(connectionParametersManager *handshake.ConnectionParametersManager, rttStats *congestion.RTTStats) FlowControlManager {
|
||||
func NewFlowControlManager(connectionParameters handshake.ConnectionParametersManager, rttStats *congestion.RTTStats) FlowControlManager {
|
||||
fcm := flowControlManager{
|
||||
connectionParametersManager: connectionParametersManager,
|
||||
connectionParameters: connectionParameters,
|
||||
rttStats: rttStats,
|
||||
streamFlowController: make(map[protocol.StreamID]*flowController),
|
||||
contributesToConnectionFlowControl: make(map[protocol.StreamID]bool),
|
||||
}
|
||||
// initialize connection level flow controller
|
||||
fcm.streamFlowController[0] = newFlowController(0, connectionParametersManager, rttStats)
|
||||
fcm.streamFlowController[0] = newFlowController(0, connectionParameters, rttStats)
|
||||
fcm.contributesToConnectionFlowControl[0] = false
|
||||
return &fcm
|
||||
}
|
||||
@@ -51,7 +51,7 @@ func (f *flowControlManager) NewStream(streamID protocol.StreamID, contributesTo
|
||||
return
|
||||
}
|
||||
|
||||
f.streamFlowController[streamID] = newFlowController(streamID, f.connectionParametersManager, f.rttStats)
|
||||
f.streamFlowController[streamID] = newFlowController(streamID, f.connectionParameters, f.rttStats)
|
||||
f.contributesToConnectionFlowControl[streamID] = contributesToConnectionFlow
|
||||
}
|
||||
|
||||
|
||||
@@ -10,10 +10,10 @@ import (
|
||||
|
||||
var _ = Describe("Flow Control Manager", func() {
|
||||
var fcm *flowControlManager
|
||||
var cpm *handshake.ConnectionParametersManager
|
||||
var cpm handshake.ConnectionParametersManager
|
||||
|
||||
BeforeEach(func() {
|
||||
cpm = &handshake.ConnectionParametersManager{}
|
||||
cpm = handshake.NewConnectionParamatersManager(protocol.VersionWhatever)
|
||||
setConnectionParametersManagerWindow(cpm, "receiveStreamFlowControlWindow", 0x100)
|
||||
setConnectionParametersManagerWindow(cpm, "receiveConnectionFlowControlWindow", 0x200)
|
||||
fcm = NewFlowControlManager(cpm, &congestion.RTTStats{}).(*flowControlManager)
|
||||
|
||||
@@ -12,8 +12,8 @@ import (
|
||||
type flowController struct {
|
||||
streamID protocol.StreamID
|
||||
|
||||
connectionParametersManager *handshake.ConnectionParametersManager
|
||||
rttStats *congestion.RTTStats
|
||||
connectionParameters handshake.ConnectionParametersManager
|
||||
rttStats *congestion.RTTStats
|
||||
|
||||
bytesSent protocol.ByteCount
|
||||
sendFlowControlWindow protocol.ByteCount
|
||||
@@ -28,19 +28,19 @@ type flowController struct {
|
||||
}
|
||||
|
||||
// newFlowController gets a new flow controller
|
||||
func newFlowController(streamID protocol.StreamID, connectionParametersManager *handshake.ConnectionParametersManager, rttStats *congestion.RTTStats) *flowController {
|
||||
func newFlowController(streamID protocol.StreamID, connectionParameters handshake.ConnectionParametersManager, rttStats *congestion.RTTStats) *flowController {
|
||||
fc := flowController{
|
||||
streamID: streamID,
|
||||
connectionParametersManager: connectionParametersManager,
|
||||
rttStats: rttStats,
|
||||
streamID: streamID,
|
||||
connectionParameters: connectionParameters,
|
||||
rttStats: rttStats,
|
||||
}
|
||||
|
||||
if streamID == 0 {
|
||||
fc.receiveFlowControlWindow = connectionParametersManager.GetReceiveConnectionFlowControlWindow()
|
||||
fc.receiveFlowControlWindow = connectionParameters.GetReceiveConnectionFlowControlWindow()
|
||||
fc.receiveFlowControlWindowIncrement = fc.receiveFlowControlWindow
|
||||
fc.maxReceiveFlowControlWindowIncrement = protocol.MaxReceiveConnectionFlowControlWindow
|
||||
} else {
|
||||
fc.receiveFlowControlWindow = connectionParametersManager.GetReceiveStreamFlowControlWindow()
|
||||
fc.receiveFlowControlWindow = connectionParameters.GetReceiveStreamFlowControlWindow()
|
||||
fc.receiveFlowControlWindowIncrement = fc.receiveFlowControlWindow
|
||||
fc.maxReceiveFlowControlWindowIncrement = protocol.MaxReceiveStreamFlowControlWindow
|
||||
}
|
||||
@@ -51,9 +51,9 @@ func newFlowController(streamID protocol.StreamID, connectionParametersManager *
|
||||
func (c *flowController) getSendFlowControlWindow() protocol.ByteCount {
|
||||
if c.sendFlowControlWindow == 0 {
|
||||
if c.streamID == 0 {
|
||||
return c.connectionParametersManager.GetSendConnectionFlowControlWindow()
|
||||
return c.connectionParameters.GetSendConnectionFlowControlWindow()
|
||||
}
|
||||
return c.connectionParametersManager.GetSendStreamFlowControlWindow()
|
||||
return c.connectionParameters.GetSendStreamFlowControlWindow()
|
||||
}
|
||||
return c.sendFlowControlWindow
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
|
||||
// set private variables of the ConnectionParametersManager
|
||||
// those are normally read from the server parameter constants in the constructor of the ConnectionParametersManager
|
||||
func setConnectionParametersManagerWindow(cpm *handshake.ConnectionParametersManager, name string, value protocol.ByteCount) {
|
||||
func setConnectionParametersManagerWindow(cpm handshake.ConnectionParametersManager, name string, value protocol.ByteCount) {
|
||||
*(*protocol.ByteCount)(unsafe.Pointer(reflect.ValueOf(cpm).Elem().FieldByName(name).UnsafeAddr())) = value
|
||||
}
|
||||
|
||||
@@ -27,11 +27,11 @@ var _ = Describe("Flow controller", func() {
|
||||
})
|
||||
|
||||
Context("Constructor", func() {
|
||||
var cpm *handshake.ConnectionParametersManager
|
||||
var cpm handshake.ConnectionParametersManager
|
||||
var rttStats *congestion.RTTStats
|
||||
|
||||
BeforeEach(func() {
|
||||
cpm = &handshake.ConnectionParametersManager{}
|
||||
cpm = handshake.NewConnectionParamatersManager(protocol.VersionWhatever)
|
||||
rttStats = &congestion.RTTStats{}
|
||||
setConnectionParametersManagerWindow(cpm, "sendStreamFlowControlWindow", 1000)
|
||||
setConnectionParametersManagerWindow(cpm, "receiveStreamFlowControlWindow", 2000)
|
||||
@@ -65,13 +65,13 @@ var _ = Describe("Flow controller", func() {
|
||||
})
|
||||
|
||||
Context("send flow control", func() {
|
||||
var cpm *handshake.ConnectionParametersManager
|
||||
var cpm handshake.ConnectionParametersManager
|
||||
|
||||
BeforeEach(func() {
|
||||
cpm = &handshake.ConnectionParametersManager{}
|
||||
cpm = handshake.NewConnectionParamatersManager(protocol.VersionWhatever)
|
||||
setConnectionParametersManagerWindow(cpm, "sendStreamFlowControlWindow", 1000)
|
||||
setConnectionParametersManagerWindow(cpm, "sendConnectionFlowControlWindow", 3000)
|
||||
controller.connectionParametersManager = cpm
|
||||
controller.connectionParameters = cpm
|
||||
})
|
||||
|
||||
It("adds bytes sent", func() {
|
||||
|
||||
Reference in New Issue
Block a user