Commit 8f066b56 authored by Marten Seemann's avatar Marten Seemann
Browse files

use the new quic-go stream deadline

Support for stream deadlines was added in
https://github.com/lucas-clemente/quic-go/pull/579.
parent 2619ea23
...@@ -46,28 +46,19 @@ func newQuicConn(sess quic.Session, t tpt.Transport) (*quicConn, error) { ...@@ -46,28 +46,19 @@ func newQuicConn(sess quic.Session, t tpt.Transport) (*quicConn, error) {
raddr: raddr, raddr: raddr,
transport: t, transport: t,
} }
go c.watchClosed() go c.watchClosed()
return c, nil return c, nil
} }
func (c *quicConn) AcceptStream() (smux.Stream, error) { func (c *quicConn) AcceptStream() (smux.Stream, error) {
str, err := c.sess.AcceptStream() return c.sess.AcceptStream()
if err != nil {
return nil, err
}
return &quicStream{Stream: str}, nil
} }
// OpenStream opens a new stream // OpenStream opens a new stream
// It blocks until a new stream can be opened (when limited by the QUIC maximum stream limit) // It blocks until a new stream can be opened (when limited by the QUIC maximum stream limit)
func (c *quicConn) OpenStream() (smux.Stream, error) { func (c *quicConn) OpenStream() (smux.Stream, error) {
str, err := c.sess.OpenStreamSync() return c.sess.OpenStreamSync()
if err != nil {
return nil, err
}
return &quicStream{Stream: str}, nil
} }
func (c *quicConn) Serve(handler smux.StreamHandler) { func (c *quicConn) Serve(handler smux.StreamHandler) {
......
...@@ -3,6 +3,7 @@ package libp2pquic ...@@ -3,6 +3,7 @@ package libp2pquic
import ( import (
"errors" "errors"
"net" "net"
"time"
smux "github.com/jbenet/go-stream-muxer" smux "github.com/jbenet/go-stream-muxer"
quic "github.com/lucas-clemente/quic-go" quic "github.com/lucas-clemente/quic-go"
...@@ -21,6 +22,9 @@ func (s *mockStream) Reset(error) { return } ...@@ -21,6 +22,9 @@ func (s *mockStream) Reset(error) { return }
func (s *mockStream) Read([]byte) (int, error) { return 0, nil } func (s *mockStream) Read([]byte) (int, error) { return 0, nil }
func (s *mockStream) Write([]byte) (int, error) { return 0, nil } func (s *mockStream) Write([]byte) (int, error) { return 0, nil }
func (s *mockStream) StreamID() protocol.StreamID { return s.id } func (s *mockStream) StreamID() protocol.StreamID { return s.id }
func (s *mockStream) SetReadDeadline(time.Time) error { panic("not implemented") }
func (s *mockStream) SetWriteDeadline(time.Time) error { panic("not implemented") }
func (s *mockStream) SetDeadline(time.Time) error { panic("not implemented") }
var _ quic.Stream = &mockStream{} var _ quic.Stream = &mockStream{}
...@@ -97,7 +101,7 @@ var _ = Describe("Conn", func() { ...@@ -97,7 +101,7 @@ var _ = Describe("Conn", func() {
sess.streamToOpen = s sess.streamToOpen = s
str, err := conn.OpenStream() str, err := conn.OpenStream()
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(str.(*quicStream).Stream).To(Equal(s)) Expect(str).To(Equal(s))
}) })
It("errors when it can't open a stream", func() { It("errors when it can't open a stream", func() {
...@@ -114,7 +118,7 @@ var _ = Describe("Conn", func() { ...@@ -114,7 +118,7 @@ var _ = Describe("Conn", func() {
sess.streamToAccept = s sess.streamToAccept = s
str, err := conn.AcceptStream() str, err := conn.AcceptStream()
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(str.(*quicStream).Stream).To(Equal(s)) Expect(str).To(Equal(s))
}) })
It("errors when it can't open a stream", func() { It("errors when it can't open a stream", func() {
...@@ -150,7 +154,7 @@ var _ = Describe("Conn", func() { ...@@ -150,7 +154,7 @@ var _ = Describe("Conn", func() {
returned = true returned = true
}() }()
Eventually(func() bool { return handlerCalled }).Should(BeTrue()) Eventually(func() bool { return handlerCalled }).Should(BeTrue())
Expect(handlerCalledWith.(*quicStream).Stream).To(Equal(str)) Expect(handlerCalledWith).To(Equal(str))
// make the go-routine return // make the go-routine return
sess.streamAcceptErr = errors.New("stop test") sess.streamAcceptErr = errors.New("stop test")
}) })
......
package libp2pquic
import (
"time"
smux "github.com/jbenet/go-stream-muxer"
quic "github.com/lucas-clemente/quic-go"
)
// The quicStream is a very thin wrapper for a quic.Stream, adding some methods
// required to fulfill the smux.Stream interface
// TODO: this can be removed once the quic.Stream supports deadlines (quic-go#514)
type quicStream struct {
quic.Stream
}
var _ smux.Stream = &quicStream{}
func (s *quicStream) SetDeadline(time.Time) error {
return nil
}
func (s *quicStream) SetReadDeadline(time.Time) error {
return nil
}
func (s *quicStream) SetWriteDeadline(time.Time) error {
return nil
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment