From 9f63cdbd91b8bd46870f0566945bd183c72a25f6 Mon Sep 17 00:00:00 2001 From: Lucas Clemente Date: Sat, 14 May 2016 13:35:43 +0200 Subject: [PATCH] add stream.StreamID() --- h2quic/response_writer_test.go | 4 ++++ handshake/crypto_setup_test.go | 2 ++ stream.go | 4 ++++ stream_test.go | 4 ++++ utils/utils.go | 3 +++ 5 files changed, 17 insertions(+) diff --git a/h2quic/response_writer_test.go b/h2quic/response_writer_test.go index b622b2e48..90851817b 100644 --- a/h2quic/response_writer_test.go +++ b/h2quic/response_writer_test.go @@ -4,16 +4,20 @@ import ( "bytes" "net/http" + "github.com/lucas-clemente/quic-go/protocol" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) type mockStream struct { + id protocol.StreamID bytes.Buffer } func (mockStream) Close() error { return nil } +func (s mockStream) StreamID() protocol.StreamID { return s.id } + var _ = Describe("Response Writer", func() { var ( w *responseWriter diff --git a/handshake/crypto_setup_test.go b/handshake/crypto_setup_test.go index 3110a5129..e505b9d1a 100644 --- a/handshake/crypto_setup_test.go +++ b/handshake/crypto_setup_test.go @@ -92,6 +92,8 @@ func (s *mockStream) Close() error { panic("not implemented") } +func (s mockStream) StreamID() protocol.StreamID { panic("not implemented") } + var _ = Describe("Crypto setup", func() { var ( kex *mockKEX diff --git a/stream.go b/stream.go index 66c8b4321..bd20ee741 100644 --- a/stream.go +++ b/stream.go @@ -213,3 +213,7 @@ func (s *stream) RegisterError(err error) { func (s *stream) finishedReading() bool { return atomic.LoadInt32(&s.eof) != 0 } + +func (s *stream) StreamID() protocol.StreamID { + return s.streamID +} diff --git a/stream_test.go b/stream_test.go index dddae4a4a..dfaa40cd0 100644 --- a/stream_test.go +++ b/stream_test.go @@ -33,6 +33,10 @@ var _ = Describe("Stream", func() { str, _ = newStream(handler, cpm, 1337) }) + It("gets stream id", func() { + Expect(str.StreamID()).To(Equal(protocol.StreamID(1337))) + }) + Context("reading", func() { It("reads a single StreamFrame", func() { frame := frames.StreamFrame{ diff --git a/utils/utils.go b/utils/utils.go index af17da2bd..179ba4b05 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -4,6 +4,8 @@ import ( "bytes" "crypto/rand" "io" + + "github.com/lucas-clemente/quic-go/protocol" ) // ReadStream is the read part of a QUIC stream @@ -18,6 +20,7 @@ type Stream interface { io.ByteReader io.Writer io.Closer + StreamID() protocol.StreamID } // ReadUintN reads N bytes