use stream 0 for the crypto stream when using TLS

This commit is contained in:
Marten Seemann
2017-11-01 13:51:47 +07:00
parent 05f6e1cf8e
commit f662822486
16 changed files with 93 additions and 59 deletions

View File

@@ -45,7 +45,7 @@ func (vn VersionNumber) String() string {
case VersionTLS:
return "TLS dev version (WIP)"
default:
if vn > gquicVersion0 && vn <= maxGquicVersion {
if vn.isGQUIC() {
return fmt.Sprintf("gQUIC %d", vn.toGQUICVersion())
}
return fmt.Sprintf("%d", vn)
@@ -54,12 +54,24 @@ func (vn VersionNumber) String() string {
// ToAltSvc returns the representation of the version for the H2 Alt-Svc parameters
func (vn VersionNumber) ToAltSvc() string {
if vn > gquicVersion0 && vn <= maxGquicVersion {
if vn.isGQUIC() {
return fmt.Sprintf("%d", vn.toGQUICVersion())
}
return fmt.Sprintf("%d", vn)
}
// CryptoStreamID gets the Stream ID of the crypto stream
func (vn VersionNumber) CryptoStreamID() StreamID {
if vn.isGQUIC() {
return 1
}
return 0
}
func (vn VersionNumber) isGQUIC() bool {
return vn > gquicVersion0 && vn <= maxGquicVersion
}
func (vn VersionNumber) toGQUICVersion() int {
return int(10*(vn-gquicVersion0)/0x100) + int(vn%0x10)
}

View File

@@ -43,7 +43,13 @@ var _ = Describe("Version", func() {
Expect(VersionNumber(0x51303133).ToAltSvc()).To(Equal("13"))
Expect(VersionNumber(0x51303235).ToAltSvc()).To(Equal("25"))
Expect(VersionNumber(0x51303438).ToAltSvc()).To(Equal("48"))
})
It("tells the Stream ID of the crypto stream", func() {
Expect(Version37.CryptoStreamID()).To(Equal(StreamID(1)))
Expect(Version38.CryptoStreamID()).To(Equal(StreamID(1)))
Expect(Version39.CryptoStreamID()).To(Equal(StreamID(1)))
Expect(VersionTLS.CryptoStreamID()).To(Equal(StreamID(0)))
})
It("recognizes supported versions", func() {