Merge pull request #888 from lucas-clemente/fix-887

open the crypto stream during session setup
This commit is contained in:
Marten Seemann
2017-10-20 05:25:06 -05:00
committed by GitHub
2 changed files with 16 additions and 14 deletions

View File

@@ -258,21 +258,24 @@ func (s *session) setup(
) )
s.unpacker = &packetUnpacker{aead: s.cryptoSetup, version: s.version} s.unpacker = &packetUnpacker{aead: s.cryptoSetup, version: s.version}
// open the crypto stream
if s.perspective == protocol.PerspectiveServer {
_, _ = s.GetOrOpenStream(1)
_, _ = s.AcceptStream() // don't expose the crypto stream
} else {
_, _ = s.OpenStream()
}
return s, handshakeChan, nil return s, handshakeChan, nil
} }
// run the session main loop // run the session main loop
func (s *session) run() error { func (s *session) run() error {
// Start the crypto stream handler defer s.ctxCancel()
var cryptoStream Stream
if s.perspective == protocol.PerspectiveServer {
cryptoStream, _ = s.GetOrOpenStream(1)
_, _ = s.AcceptStream() // don't expose the crypto stream
} else {
cryptoStream, _ = s.OpenStream()
}
// Start the crypto stream handler
go func() { go func() {
cryptoStream, _ := s.GetOrOpenStream(1)
if err := s.cryptoSetup.HandleCryptoStream(cryptoStream); err != nil { if err := s.cryptoSetup.HandleCryptoStream(cryptoStream); err != nil {
s.Close(err) s.Close(err)
} }
@@ -366,7 +369,6 @@ runLoop:
s.handshakeChan <- handshakeEvent{err: closeErr.err} s.handshakeChan <- handshakeEvent{err: closeErr.err}
} }
s.handleCloseError(closeErr) s.handleCloseError(closeErr)
defer s.ctxCancel()
return closeErr.err return closeErr.err
} }

View File

@@ -208,7 +208,7 @@ var _ = Describe("Session", func() {
) )
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
sess = pSess.(*session) sess = pSess.(*session)
Expect(sess.streamsMap.openStreams).To(BeEmpty()) // the crypto stream is opened in session.run() Expect(sess.streamsMap.openStreams).To(HaveLen(1)) // 1 stream: the crypto stream
sess.connParams = &mockParamsNegotiator{} sess.connParams = &mockParamsNegotiator{}
}) })
@@ -684,15 +684,15 @@ var _ = Describe("Session", func() {
}() }()
Consistently(strChan).ShouldNot(Receive()) Consistently(strChan).ShouldNot(Receive())
err := sess.handleStreamFrame(&wire.StreamFrame{ err := sess.handleStreamFrame(&wire.StreamFrame{
StreamID: 3, StreamID: 5,
Data: []byte("foobar"), Data: []byte("foobar"),
}) })
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
var str Stream var str Stream
Eventually(strChan).Should(Receive(&str)) Eventually(strChan).Should(Receive(&str))
Expect(str.StreamID()).To(Equal(protocol.StreamID(1)))
Eventually(strChan).Should(Receive(&str))
Expect(str.StreamID()).To(Equal(protocol.StreamID(3))) Expect(str.StreamID()).To(Equal(protocol.StreamID(3)))
Eventually(strChan).Should(Receive(&str))
Expect(str.StreamID()).To(Equal(protocol.StreamID(5)))
}) })
It("stops accepting when the session is closed", func() { It("stops accepting when the session is closed", func() {
@@ -1684,7 +1684,7 @@ var _ = Describe("Client Session", func() {
) )
sess = sessP.(*session) sess = sessP.(*session)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(sess.streamsMap.openStreams).To(BeEmpty()) // the crypto stream is opened in session.run() Expect(sess.streamsMap.openStreams).To(HaveLen(1))
}) })
AfterEach(func() { AfterEach(func() {