mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 12:47:36 +03:00
handle the transport parameters in the packet packer
This commit is contained in:
parent
caf8da9adc
commit
9f5bfbe292
5 changed files with 31 additions and 40 deletions
|
@ -9,6 +9,7 @@ import (
|
||||||
|
|
||||||
gomock "github.com/golang/mock/gomock"
|
gomock "github.com/golang/mock/gomock"
|
||||||
ackhandler "github.com/lucas-clemente/quic-go/internal/ackhandler"
|
ackhandler "github.com/lucas-clemente/quic-go/internal/ackhandler"
|
||||||
|
handshake "github.com/lucas-clemente/quic-go/internal/handshake"
|
||||||
protocol "github.com/lucas-clemente/quic-go/internal/protocol"
|
protocol "github.com/lucas-clemente/quic-go/internal/protocol"
|
||||||
wire "github.com/lucas-clemente/quic-go/internal/wire"
|
wire "github.com/lucas-clemente/quic-go/internal/wire"
|
||||||
)
|
)
|
||||||
|
@ -46,6 +47,16 @@ func (mr *MockPackerMockRecorder) ChangeDestConnectionID(arg0 interface{}) *gomo
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ChangeDestConnectionID", reflect.TypeOf((*MockPacker)(nil).ChangeDestConnectionID), arg0)
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ChangeDestConnectionID", reflect.TypeOf((*MockPacker)(nil).ChangeDestConnectionID), arg0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HandleTransportParameters mocks base method
|
||||||
|
func (m *MockPacker) HandleTransportParameters(arg0 *handshake.TransportParameters) {
|
||||||
|
m.ctrl.Call(m, "HandleTransportParameters", arg0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// HandleTransportParameters indicates an expected call of HandleTransportParameters
|
||||||
|
func (mr *MockPackerMockRecorder) HandleTransportParameters(arg0 interface{}) *gomock.Call {
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HandleTransportParameters", reflect.TypeOf((*MockPacker)(nil).HandleTransportParameters), arg0)
|
||||||
|
}
|
||||||
|
|
||||||
// MaybePackAckPacket mocks base method
|
// MaybePackAckPacket mocks base method
|
||||||
func (m *MockPacker) MaybePackAckPacket() (*packedPacket, error) {
|
func (m *MockPacker) MaybePackAckPacket() (*packedPacket, error) {
|
||||||
ret := m.ctrl.Call(m, "MaybePackAckPacket")
|
ret := m.ctrl.Call(m, "MaybePackAckPacket")
|
||||||
|
@ -107,23 +118,3 @@ func (m *MockPacker) QueueControlFrame(arg0 wire.Frame) {
|
||||||
func (mr *MockPackerMockRecorder) QueueControlFrame(arg0 interface{}) *gomock.Call {
|
func (mr *MockPackerMockRecorder) QueueControlFrame(arg0 interface{}) *gomock.Call {
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueueControlFrame", reflect.TypeOf((*MockPacker)(nil).QueueControlFrame), arg0)
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueueControlFrame", reflect.TypeOf((*MockPacker)(nil).QueueControlFrame), arg0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetMaxPacketSize mocks base method
|
|
||||||
func (m *MockPacker) SetMaxPacketSize(arg0 protocol.ByteCount) {
|
|
||||||
m.ctrl.Call(m, "SetMaxPacketSize", arg0)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetMaxPacketSize indicates an expected call of SetMaxPacketSize
|
|
||||||
func (mr *MockPackerMockRecorder) SetMaxPacketSize(arg0 interface{}) *gomock.Call {
|
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetMaxPacketSize", reflect.TypeOf((*MockPacker)(nil).SetMaxPacketSize), arg0)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetOmitConnectionID mocks base method
|
|
||||||
func (m *MockPacker) SetOmitConnectionID() {
|
|
||||||
m.ctrl.Call(m, "SetOmitConnectionID")
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetOmitConnectionID indicates an expected call of SetOmitConnectionID
|
|
||||||
func (mr *MockPackerMockRecorder) SetOmitConnectionID() *gomock.Call {
|
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetOmitConnectionID", reflect.TypeOf((*MockPacker)(nil).SetOmitConnectionID))
|
|
||||||
}
|
|
||||||
|
|
|
@ -23,9 +23,8 @@ type packer interface {
|
||||||
PackRetransmission(packet *ackhandler.Packet) ([]*packedPacket, error)
|
PackRetransmission(packet *ackhandler.Packet) ([]*packedPacket, error)
|
||||||
PackConnectionClose(*wire.ConnectionCloseFrame) (*packedPacket, error)
|
PackConnectionClose(*wire.ConnectionCloseFrame) (*packedPacket, error)
|
||||||
|
|
||||||
SetOmitConnectionID()
|
HandleTransportParameters(*handshake.TransportParameters)
|
||||||
ChangeDestConnectionID(protocol.ConnectionID)
|
ChangeDestConnectionID(protocol.ConnectionID)
|
||||||
SetMaxPacketSize(protocol.ByteCount)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type packedPacket struct {
|
type packedPacket struct {
|
||||||
|
@ -576,14 +575,13 @@ func (p *packetPacker) canSendData(encLevel protocol.EncryptionLevel) bool {
|
||||||
return encLevel == protocol.EncryptionForwardSecure
|
return encLevel == protocol.EncryptionForwardSecure
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *packetPacker) SetOmitConnectionID() {
|
|
||||||
p.omitConnectionID = true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *packetPacker) ChangeDestConnectionID(connID protocol.ConnectionID) {
|
func (p *packetPacker) ChangeDestConnectionID(connID protocol.ConnectionID) {
|
||||||
p.destConnID = connID
|
p.destConnID = connID
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *packetPacker) SetMaxPacketSize(size protocol.ByteCount) {
|
func (p *packetPacker) HandleTransportParameters(params *handshake.TransportParameters) {
|
||||||
p.maxPacketSize = utils.MinByteCount(p.maxPacketSize, size)
|
p.omitConnectionID = params.OmitConnectionID
|
||||||
|
if params.MaxPacketSize != 0 {
|
||||||
|
p.maxPacketSize = utils.MinByteCount(p.maxPacketSize, params.MaxPacketSize)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,13 +186,17 @@ var _ = Describe("Packet packer", func() {
|
||||||
packer.version = protocol.Version43
|
packer.version = protocol.Version43
|
||||||
ph := packer.getHeader(protocol.EncryptionForwardSecure)
|
ph := packer.getHeader(protocol.EncryptionForwardSecure)
|
||||||
Expect(ph.DestConnectionID.Len()).ToNot(BeZero())
|
Expect(ph.DestConnectionID.Len()).ToNot(BeZero())
|
||||||
packer.SetOmitConnectionID()
|
packer.HandleTransportParameters(&handshake.TransportParameters{
|
||||||
|
OmitConnectionID: true,
|
||||||
|
})
|
||||||
ph = packer.getHeader(protocol.EncryptionForwardSecure)
|
ph = packer.getHeader(protocol.EncryptionForwardSecure)
|
||||||
Expect(ph.DestConnectionID.Len()).To(BeZero())
|
Expect(ph.DestConnectionID.Len()).To(BeZero())
|
||||||
})
|
})
|
||||||
|
|
||||||
It("doesn't omit the connection ID for non-forward-secure packets", func() {
|
It("doesn't omit the connection ID for non-forward-secure packets", func() {
|
||||||
packer.SetOmitConnectionID()
|
packer.HandleTransportParameters(&handshake.TransportParameters{
|
||||||
|
OmitConnectionID: true,
|
||||||
|
})
|
||||||
ph := packer.getHeader(protocol.EncryptionSecure)
|
ph := packer.getHeader(protocol.EncryptionSecure)
|
||||||
Expect(ph.DestConnectionID.Len()).ToNot(BeZero())
|
Expect(ph.DestConnectionID.Len()).ToNot(BeZero())
|
||||||
})
|
})
|
||||||
|
@ -1053,7 +1057,9 @@ var _ = Describe("Packet packer", func() {
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(p.raw).To(HaveLen(int(maxPacketSize)))
|
Expect(p.raw).To(HaveLen(int(maxPacketSize)))
|
||||||
// now reduce the maxPacketSize
|
// now reduce the maxPacketSize
|
||||||
packer.SetMaxPacketSize(maxPacketSize - 10)
|
packer.HandleTransportParameters(&handshake.TransportParameters{
|
||||||
|
MaxPacketSize: maxPacketSize - 10,
|
||||||
|
})
|
||||||
p, err = packer.PackPacket()
|
p, err = packer.PackPacket()
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(p.raw).To(HaveLen(int(maxPacketSize) - 10))
|
Expect(p.raw).To(HaveLen(int(maxPacketSize) - 10))
|
||||||
|
@ -1072,7 +1078,9 @@ var _ = Describe("Packet packer", func() {
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(p.raw).To(HaveLen(int(maxPacketSize)))
|
Expect(p.raw).To(HaveLen(int(maxPacketSize)))
|
||||||
// now try to increase the maxPacketSize
|
// now try to increase the maxPacketSize
|
||||||
packer.SetMaxPacketSize(maxPacketSize + 10)
|
packer.HandleTransportParameters(&handshake.TransportParameters{
|
||||||
|
MaxPacketSize: maxPacketSize + 10,
|
||||||
|
})
|
||||||
p, err = packer.PackPacket()
|
p, err = packer.PackPacket()
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(p.raw).To(HaveLen(int(maxPacketSize)))
|
Expect(p.raw).To(HaveLen(int(maxPacketSize)))
|
||||||
|
|
|
@ -914,12 +914,7 @@ func (s *session) handleCloseError(closeErr closeError) error {
|
||||||
func (s *session) processTransportParameters(params *handshake.TransportParameters) {
|
func (s *session) processTransportParameters(params *handshake.TransportParameters) {
|
||||||
s.peerParams = params
|
s.peerParams = params
|
||||||
s.streamsMap.UpdateLimits(params)
|
s.streamsMap.UpdateLimits(params)
|
||||||
if params.OmitConnectionID {
|
s.packer.HandleTransportParameters(params)
|
||||||
s.packer.SetOmitConnectionID()
|
|
||||||
}
|
|
||||||
if params.MaxPacketSize != 0 {
|
|
||||||
s.packer.SetMaxPacketSize(params.MaxPacketSize)
|
|
||||||
}
|
|
||||||
s.connFlowController.UpdateSendWindow(params.ConnectionFlowControlWindow)
|
s.connFlowController.UpdateSendWindow(params.ConnectionFlowControlWindow)
|
||||||
// the crypto stream is the only open stream at this moment
|
// the crypto stream is the only open stream at this moment
|
||||||
// so we don't need to update stream flow control windows
|
// so we don't need to update stream flow control windows
|
||||||
|
|
|
@ -1289,8 +1289,7 @@ var _ = Describe("Session", func() {
|
||||||
MaxPacketSize: 0x42,
|
MaxPacketSize: 0x42,
|
||||||
}
|
}
|
||||||
streamManager.EXPECT().UpdateLimits(¶ms)
|
streamManager.EXPECT().UpdateLimits(¶ms)
|
||||||
packer.EXPECT().SetOmitConnectionID()
|
packer.EXPECT().HandleTransportParameters(¶ms)
|
||||||
packer.EXPECT().SetMaxPacketSize(protocol.ByteCount(0x42))
|
|
||||||
paramsChan <- params
|
paramsChan <- params
|
||||||
Eventually(func() *handshake.TransportParameters { return sess.peerParams }).Should(Equal(¶ms))
|
Eventually(func() *handshake.TransportParameters { return sess.peerParams }).Should(Equal(¶ms))
|
||||||
// make the go routine return
|
// make the go routine return
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue