send stream counts, not stream IDs, in the transport parameters

This commit is contained in:
Marten Seemann
2018-03-15 09:18:36 +01:00
parent 1fffb88553
commit b40942d39e
10 changed files with 83 additions and 74 deletions

View File

@@ -9,14 +9,14 @@ type transportParameterID uint16
const quicTLSExtensionType = 26
const (
initialMaxStreamDataParameterID transportParameterID = 0x0
initialMaxDataParameterID transportParameterID = 0x1
initialMaxStreamIDBiDiParameterID transportParameterID = 0x2
idleTimeoutParameterID transportParameterID = 0x3
omitConnectionIDParameterID transportParameterID = 0x4
maxPacketSizeParameterID transportParameterID = 0x5
statelessResetTokenParameterID transportParameterID = 0x6
initialMaxStreamIDUniParameterID transportParameterID = 0x8
initialMaxStreamDataParameterID transportParameterID = 0x0
initialMaxDataParameterID transportParameterID = 0x1
initialMaxStreamsBiDiParameterID transportParameterID = 0x2
idleTimeoutParameterID transportParameterID = 0x3
omitConnectionIDParameterID transportParameterID = 0x4
maxPacketSizeParameterID transportParameterID = 0x5
statelessResetTokenParameterID transportParameterID = 0x6
initialMaxStreamsUniParameterID transportParameterID = 0x8
)
type transportParameter struct {

View File

@@ -66,11 +66,11 @@ var _ = Describe("TLS Extension Handler, for the client", func() {
BeforeEach(func() {
fakeBody = &tlsExtensionBody{data: []byte("foobar foobar")}
parameters = map[transportParameterID][]byte{
initialMaxStreamDataParameterID: {0x11, 0x22, 0x33, 0x44},
initialMaxDataParameterID: {0x22, 0x33, 0x44, 0x55},
initialMaxStreamIDBiDiParameterID: {0x33, 0x44, 0x55, 0x66},
idleTimeoutParameterID: {0x13, 0x37},
statelessResetTokenParameterID: bytes.Repeat([]byte{0}, 16),
initialMaxStreamDataParameterID: {0x11, 0x22, 0x33, 0x44},
initialMaxDataParameterID: {0x22, 0x33, 0x44, 0x55},
initialMaxStreamsBiDiParameterID: {0x33, 0x44},
idleTimeoutParameterID: {0x13, 0x37},
statelessResetTokenParameterID: bytes.Repeat([]byte{0}, 16),
}
})

View File

@@ -77,10 +77,10 @@ var _ = Describe("TLS Extension Handler, for the server", func() {
BeforeEach(func() {
fakeBody = &tlsExtensionBody{data: []byte("foobar foobar")}
parameters = map[transportParameterID][]byte{
initialMaxStreamDataParameterID: {0x11, 0x22, 0x33, 0x44},
initialMaxDataParameterID: {0x22, 0x33, 0x44, 0x55},
initialMaxStreamIDBiDiParameterID: {0x33, 0x44, 0x55, 0x66},
idleTimeoutParameterID: {0x13, 0x37},
initialMaxStreamDataParameterID: {0x11, 0x22, 0x33, 0x44},
initialMaxDataParameterID: {0x22, 0x33, 0x44, 0x55},
initialMaxStreamsBiDiParameterID: {0x33, 0x44},
idleTimeoutParameterID: {0x13, 0x37},
}
})

View File

@@ -114,12 +114,12 @@ var _ = Describe("Transport Parameters", func() {
p := &TransportParameters{
StreamFlowControlWindow: 0x1234,
ConnectionFlowControlWindow: 0x4321,
MaxBidiStreamID: 1337,
MaxUniStreamID: 7331,
MaxBidiStreams: 1337,
MaxUniStreams: 7331,
OmitConnectionID: true,
IdleTimeout: 42 * time.Second,
}
Expect(p.String()).To(Equal("&handshake.TransportParameters{StreamFlowControlWindow: 0x1234, ConnectionFlowControlWindow: 0x4321, MaxBidiStreamID: 1337, MaxUniStreamID: 7331, OmitConnectionID: true, IdleTimeout: 42s}"))
Expect(p.String()).To(Equal("&handshake.TransportParameters{StreamFlowControlWindow: 0x1234, ConnectionFlowControlWindow: 0x4321, MaxBidiStreams: 1337, MaxUniStreams: 7331, OmitConnectionID: true, IdleTimeout: 42s}"))
})
Context("parsing", func() {
@@ -127,12 +127,12 @@ var _ = Describe("Transport Parameters", func() {
BeforeEach(func() {
parameters = map[transportParameterID][]byte{
initialMaxStreamDataParameterID: {0x11, 0x22, 0x33, 0x44},
initialMaxDataParameterID: {0x22, 0x33, 0x44, 0x55},
initialMaxStreamIDBiDiParameterID: {0x33, 0x44, 0x55, 0x66},
initialMaxStreamIDUniParameterID: {0x44, 0x55, 0x66, 0x77},
idleTimeoutParameterID: {0x13, 0x37},
maxPacketSizeParameterID: {0x73, 0x31},
initialMaxStreamDataParameterID: {0x11, 0x22, 0x33, 0x44},
initialMaxDataParameterID: {0x22, 0x33, 0x44, 0x55},
initialMaxStreamsBiDiParameterID: {0x33, 0x44},
initialMaxStreamsUniParameterID: {0x44, 0x55},
idleTimeoutParameterID: {0x13, 0x37},
maxPacketSizeParameterID: {0x73, 0x31},
}
})
It("reads parameters", func() {
@@ -140,8 +140,8 @@ var _ = Describe("Transport Parameters", func() {
Expect(err).ToNot(HaveOccurred())
Expect(params.StreamFlowControlWindow).To(Equal(protocol.ByteCount(0x11223344)))
Expect(params.ConnectionFlowControlWindow).To(Equal(protocol.ByteCount(0x22334455)))
Expect(params.MaxBidiStreamID).To(Equal(protocol.StreamID(0x33445566)))
Expect(params.MaxUniStreamID).To(Equal(protocol.StreamID(0x44556677)))
Expect(params.MaxBidiStreams).To(Equal(uint16(0x3344)))
Expect(params.MaxUniStreams).To(Equal(uint16(0x4455)))
Expect(params.IdleTimeout).To(Equal(0x1337 * time.Second))
Expect(params.OmitConnectionID).To(BeFalse())
Expect(params.MaxPacketSize).To(Equal(protocol.ByteCount(0x7331)))
@@ -194,15 +194,15 @@ var _ = Describe("Transport Parameters", func() {
})
It("rejects the parameters if the initial_max_stream_id_bidi has the wrong length", func() {
parameters[initialMaxStreamIDBiDiParameterID] = []byte{0x11, 0x22, 0x33, 0x44, 0x55} // should be 4 bytes
parameters[initialMaxStreamsBiDiParameterID] = []byte{0x11, 0x22, 0x33} // should be 2 bytes
_, err := readTransportParameters(paramsMapToList(parameters))
Expect(err).To(MatchError("wrong length for initial_max_stream_id_bidi: 5 (expected 4)"))
Expect(err).To(MatchError("wrong length for initial_max_stream_id_bidi: 3 (expected 2)"))
})
It("rejects the parameters if the initial_max_stream_id_bidi has the wrong length", func() {
parameters[initialMaxStreamIDUniParameterID] = []byte{0x11, 0x22, 0x33, 0x44, 0x55} // should be 4 bytes
parameters[initialMaxStreamsUniParameterID] = []byte{0x11, 0x22, 0x33} // should be 2 bytes
_, err := readTransportParameters(paramsMapToList(parameters))
Expect(err).To(MatchError("wrong length for initial_max_stream_id_uni: 5 (expected 4)"))
Expect(err).To(MatchError("wrong length for initial_max_stream_id_uni: 3 (expected 2)"))
})
It("rejects the parameters if the initial_idle_timeout has the wrong length", func() {
@@ -252,8 +252,8 @@ var _ = Describe("Transport Parameters", func() {
StreamFlowControlWindow: 0xdeadbeef,
ConnectionFlowControlWindow: 0xdecafbad,
IdleTimeout: 0xcafe * time.Second,
MaxBidiStreamID: 0xbadf000d,
MaxUniStreamID: 0xface,
MaxBidiStreams: 0x1234,
MaxUniStreams: 0x4321,
}
})
@@ -262,8 +262,8 @@ var _ = Describe("Transport Parameters", func() {
Expect(values).To(HaveLen(6))
Expect(values).To(HaveKeyWithValue(initialMaxStreamDataParameterID, []byte{0xde, 0xad, 0xbe, 0xef}))
Expect(values).To(HaveKeyWithValue(initialMaxDataParameterID, []byte{0xde, 0xca, 0xfb, 0xad}))
Expect(values).To(HaveKeyWithValue(initialMaxStreamIDBiDiParameterID, []byte{0xba, 0xdf, 0x00, 0x0d}))
Expect(values).To(HaveKeyWithValue(initialMaxStreamIDUniParameterID, []byte{0x0, 0x0, 0xfa, 0xce}))
Expect(values).To(HaveKeyWithValue(initialMaxStreamsBiDiParameterID, []byte{0x12, 0x34}))
Expect(values).To(HaveKeyWithValue(initialMaxStreamsUniParameterID, []byte{0x43, 0x21}))
Expect(values).To(HaveKeyWithValue(idleTimeoutParameterID, []byte{0xca, 0xfe}))
Expect(values).To(HaveKeyWithValue(maxPacketSizeParameterID, []byte{0x5, 0xac})) // 1452 = 0x5ac
})

View File

@@ -22,9 +22,9 @@ type TransportParameters struct {
MaxPacketSize protocol.ByteCount
MaxBidiStreamID protocol.StreamID // only used for IETF QUIC
MaxUniStreamID protocol.StreamID // only used for IETF QUIC
MaxStreams uint32 // only used for gQUIC
MaxUniStreams uint16 // only used for IETF QUIC
MaxBidiStreams uint16 // only used for IETF QUIC
MaxStreams uint32 // only used for gQUIC
OmitConnectionID bool
IdleTimeout time.Duration
@@ -116,18 +116,16 @@ func readTransportParameters(paramsList []transportParameter) (*TransportParamet
return nil, fmt.Errorf("wrong length for initial_max_data: %d (expected 4)", len(p.Value))
}
params.ConnectionFlowControlWindow = protocol.ByteCount(binary.BigEndian.Uint32(p.Value))
case initialMaxStreamIDBiDiParameterID:
if len(p.Value) != 4 {
return nil, fmt.Errorf("wrong length for initial_max_stream_id_bidi: %d (expected 4)", len(p.Value))
case initialMaxStreamsBiDiParameterID:
if len(p.Value) != 2 {
return nil, fmt.Errorf("wrong length for initial_max_stream_id_bidi: %d (expected 2)", len(p.Value))
}
// TODO(#1154): validate the stream ID
params.MaxBidiStreamID = protocol.StreamID(binary.BigEndian.Uint32(p.Value))
case initialMaxStreamIDUniParameterID:
if len(p.Value) != 4 {
return nil, fmt.Errorf("wrong length for initial_max_stream_id_uni: %d (expected 4)", len(p.Value))
params.MaxBidiStreams = binary.BigEndian.Uint16(p.Value)
case initialMaxStreamsUniParameterID:
if len(p.Value) != 2 {
return nil, fmt.Errorf("wrong length for initial_max_stream_id_uni: %d (expected 2)", len(p.Value))
}
// TODO(#1154): validate the stream ID
params.MaxUniStreamID = protocol.StreamID(binary.BigEndian.Uint32(p.Value))
params.MaxUniStreams = binary.BigEndian.Uint16(p.Value)
case idleTimeoutParameterID:
foundIdleTimeout = true
if len(p.Value) != 2 {
@@ -164,10 +162,10 @@ func (p *TransportParameters) getTransportParameters() []transportParameter {
binary.BigEndian.PutUint32(initialMaxStreamData, uint32(p.StreamFlowControlWindow))
initialMaxData := make([]byte, 4)
binary.BigEndian.PutUint32(initialMaxData, uint32(p.ConnectionFlowControlWindow))
initialMaxBidiStreamID := make([]byte, 4)
binary.BigEndian.PutUint32(initialMaxBidiStreamID, uint32(p.MaxBidiStreamID))
initialMaxUniStreamID := make([]byte, 4)
binary.BigEndian.PutUint32(initialMaxUniStreamID, uint32(p.MaxUniStreamID))
initialMaxBidiStreamID := make([]byte, 2)
binary.BigEndian.PutUint16(initialMaxBidiStreamID, p.MaxBidiStreams)
initialMaxUniStreamID := make([]byte, 2)
binary.BigEndian.PutUint16(initialMaxUniStreamID, p.MaxUniStreams)
idleTimeout := make([]byte, 2)
binary.BigEndian.PutUint16(idleTimeout, uint16(p.IdleTimeout/time.Second))
maxPacketSize := make([]byte, 2)
@@ -175,8 +173,8 @@ func (p *TransportParameters) getTransportParameters() []transportParameter {
params := []transportParameter{
{initialMaxStreamDataParameterID, initialMaxStreamData},
{initialMaxDataParameterID, initialMaxData},
{initialMaxStreamIDBiDiParameterID, initialMaxBidiStreamID},
{initialMaxStreamIDUniParameterID, initialMaxUniStreamID},
{initialMaxStreamsBiDiParameterID, initialMaxBidiStreamID},
{initialMaxStreamsUniParameterID, initialMaxUniStreamID},
{idleTimeoutParameterID, idleTimeout},
{maxPacketSizeParameterID, maxPacketSize},
}
@@ -189,5 +187,5 @@ func (p *TransportParameters) getTransportParameters() []transportParameter {
// String returns a string representation, intended for logging.
// It should only used for IETF QUIC.
func (p *TransportParameters) String() string {
return fmt.Sprintf("&handshake.TransportParameters{StreamFlowControlWindow: %#x, ConnectionFlowControlWindow: %#x, MaxBidiStreamID: %d, MaxUniStreamID: %d, OmitConnectionID: %t, IdleTimeout: %s}", p.StreamFlowControlWindow, p.ConnectionFlowControlWindow, p.MaxBidiStreamID, p.MaxUniStreamID, p.OmitConnectionID, p.IdleTimeout)
return fmt.Sprintf("&handshake.TransportParameters{StreamFlowControlWindow: %#x, ConnectionFlowControlWindow: %#x, MaxBidiStreams: %d, MaxUniStreams: %d, OmitConnectionID: %t, IdleTimeout: %s}", p.StreamFlowControlWindow, p.ConnectionFlowControlWindow, p.MaxBidiStreams, p.MaxUniStreams, p.OmitConnectionID, p.IdleTimeout)
}