mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 20:57:36 +03:00
return a quic.ConnectionState from Session.ConnectionState()
This commit is contained in:
parent
021f70aac5
commit
356c69944e
7 changed files with 26 additions and 22 deletions
|
@ -250,7 +250,7 @@ func (c *client) doRequest(
|
||||||
return nil, newConnError(errorGeneralProtocolError, err)
|
return nil, newConnError(errorGeneralProtocolError, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
connState := qtls.ToTLSConnectionState(c.session.ConnectionState())
|
connState := qtls.ToTLSConnectionState(c.session.ConnectionState().TLS)
|
||||||
res := &http.Response{
|
res := &http.Response{
|
||||||
Proto: "HTTP/3",
|
Proto: "HTTP/3",
|
||||||
ProtoMajor: 3,
|
ProtoMajor: 3,
|
||||||
|
|
|
@ -16,7 +16,6 @@ import (
|
||||||
mockquic "github.com/lucas-clemente/quic-go/internal/mocks/quic"
|
mockquic "github.com/lucas-clemente/quic-go/internal/mocks/quic"
|
||||||
|
|
||||||
"github.com/lucas-clemente/quic-go/internal/protocol"
|
"github.com/lucas-clemente/quic-go/internal/protocol"
|
||||||
"github.com/lucas-clemente/quic-go/internal/qtls"
|
|
||||||
"github.com/lucas-clemente/quic-go/internal/utils"
|
"github.com/lucas-clemente/quic-go/internal/utils"
|
||||||
"github.com/marten-seemann/qpack"
|
"github.com/marten-seemann/qpack"
|
||||||
|
|
||||||
|
@ -240,7 +239,7 @@ var _ = Describe("Client", func() {
|
||||||
gomock.InOrder(
|
gomock.InOrder(
|
||||||
sess.EXPECT().HandshakeComplete().Return(handshakeCtx),
|
sess.EXPECT().HandshakeComplete().Return(handshakeCtx),
|
||||||
sess.EXPECT().OpenStreamSync(context.Background()).Return(str, nil),
|
sess.EXPECT().OpenStreamSync(context.Background()).Return(str, nil),
|
||||||
sess.EXPECT().ConnectionState().Return(qtls.ConnectionState{}),
|
sess.EXPECT().ConnectionState().Return(quic.ConnectionState{}),
|
||||||
)
|
)
|
||||||
str.EXPECT().Write(gomock.Any()).AnyTimes().DoAndReturn(func(p []byte) (int, error) { return len(p), nil })
|
str.EXPECT().Write(gomock.Any()).AnyTimes().DoAndReturn(func(p []byte) (int, error) { return len(p), nil })
|
||||||
str.EXPECT().Close()
|
str.EXPECT().Close()
|
||||||
|
@ -410,7 +409,7 @@ var _ = Describe("Client", func() {
|
||||||
req := request.WithContext(ctx)
|
req := request.WithContext(ctx)
|
||||||
sess.EXPECT().HandshakeComplete().Return(handshakeCtx)
|
sess.EXPECT().HandshakeComplete().Return(handshakeCtx)
|
||||||
sess.EXPECT().OpenStreamSync(ctx).Return(str, nil)
|
sess.EXPECT().OpenStreamSync(ctx).Return(str, nil)
|
||||||
sess.EXPECT().ConnectionState().Return(qtls.ConnectionState{})
|
sess.EXPECT().ConnectionState().Return(quic.ConnectionState{})
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
str.EXPECT().Close().MaxTimes(1)
|
str.EXPECT().Close().MaxTimes(1)
|
||||||
|
|
||||||
|
@ -473,7 +472,7 @@ var _ = Describe("Client", func() {
|
||||||
|
|
||||||
It("decompresses the response", func() {
|
It("decompresses the response", func() {
|
||||||
sess.EXPECT().OpenStreamSync(context.Background()).Return(str, nil)
|
sess.EXPECT().OpenStreamSync(context.Background()).Return(str, nil)
|
||||||
sess.EXPECT().ConnectionState().Return(qtls.ConnectionState{})
|
sess.EXPECT().ConnectionState().Return(quic.ConnectionState{})
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
rw := newResponseWriter(buf, utils.DefaultLogger)
|
rw := newResponseWriter(buf, utils.DefaultLogger)
|
||||||
rw.Header().Set("Content-Encoding", "gzip")
|
rw.Header().Set("Content-Encoding", "gzip")
|
||||||
|
@ -499,7 +498,7 @@ var _ = Describe("Client", func() {
|
||||||
|
|
||||||
It("only decompresses the response if the response contains the right content-encoding header", func() {
|
It("only decompresses the response if the response contains the right content-encoding header", func() {
|
||||||
sess.EXPECT().OpenStreamSync(context.Background()).Return(str, nil)
|
sess.EXPECT().OpenStreamSync(context.Background()).Return(str, nil)
|
||||||
sess.EXPECT().ConnectionState().Return(qtls.ConnectionState{})
|
sess.EXPECT().ConnectionState().Return(quic.ConnectionState{})
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
rw := newResponseWriter(buf, utils.DefaultLogger)
|
rw := newResponseWriter(buf, utils.DefaultLogger)
|
||||||
rw.Write([]byte("not gzipped"))
|
rw.Write([]byte("not gzipped"))
|
||||||
|
|
|
@ -170,7 +170,7 @@ var _ = Describe("Handshake tests", func() {
|
||||||
data, err := ioutil.ReadAll(str)
|
data, err := ioutil.ReadAll(str)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(data).To(Equal(PRData))
|
Expect(data).To(Equal(PRData))
|
||||||
Expect(sess.ConnectionState().CipherSuite).To(Equal(suiteID))
|
Expect(sess.ConnectionState().TLS.CipherSuite).To(Equal(suiteID))
|
||||||
Expect(sess.CloseWithError(0, "")).To(Succeed())
|
Expect(sess.CloseWithError(0, "")).To(Succeed())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -369,7 +369,7 @@ var _ = Describe("Handshake tests", func() {
|
||||||
sess, err := ln.Accept(context.Background())
|
sess, err := ln.Accept(context.Background())
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
cs := sess.ConnectionState()
|
cs := sess.ConnectionState()
|
||||||
Expect(cs.NegotiatedProtocol).To(Equal(alpn))
|
Expect(cs.TLS.NegotiatedProtocol).To(Equal(alpn))
|
||||||
close(done)
|
close(done)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -381,7 +381,7 @@ var _ = Describe("Handshake tests", func() {
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
defer sess.CloseWithError(0, "")
|
defer sess.CloseWithError(0, "")
|
||||||
cs := sess.ConnectionState()
|
cs := sess.ConnectionState()
|
||||||
Expect(cs.NegotiatedProtocol).To(Equal(alpn))
|
Expect(cs.TLS.NegotiatedProtocol).To(Equal(alpn))
|
||||||
Eventually(done).Should(BeClosed())
|
Eventually(done).Should(BeClosed())
|
||||||
Expect(ln.Close()).To(Succeed())
|
Expect(ln.Close()).To(Succeed())
|
||||||
})
|
})
|
||||||
|
|
|
@ -65,11 +65,11 @@ var _ = Describe("TLS session resumption", func() {
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
var sessionKey string
|
var sessionKey string
|
||||||
Eventually(puts).Should(Receive(&sessionKey))
|
Eventually(puts).Should(Receive(&sessionKey))
|
||||||
Expect(sess.ConnectionState().DidResume).To(BeFalse())
|
Expect(sess.ConnectionState().TLS.DidResume).To(BeFalse())
|
||||||
|
|
||||||
serverSess, err := server.Accept(context.Background())
|
serverSess, err := server.Accept(context.Background())
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(serverSess.ConnectionState().DidResume).To(BeFalse())
|
Expect(serverSess.ConnectionState().TLS.DidResume).To(BeFalse())
|
||||||
|
|
||||||
sess, err = quic.DialAddr(
|
sess, err = quic.DialAddr(
|
||||||
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
|
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
|
||||||
|
@ -78,11 +78,11 @@ var _ = Describe("TLS session resumption", func() {
|
||||||
)
|
)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(gets).To(Receive(Equal(sessionKey)))
|
Expect(gets).To(Receive(Equal(sessionKey)))
|
||||||
Expect(sess.ConnectionState().DidResume).To(BeTrue())
|
Expect(sess.ConnectionState().TLS.DidResume).To(BeTrue())
|
||||||
|
|
||||||
serverSess, err = server.Accept(context.Background())
|
serverSess, err = server.Accept(context.Background())
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(serverSess.ConnectionState().DidResume).To(BeTrue())
|
Expect(serverSess.ConnectionState().TLS.DidResume).To(BeTrue())
|
||||||
})
|
})
|
||||||
|
|
||||||
It("doesn't use session resumption, if the config disables it", func() {
|
It("doesn't use session resumption, if the config disables it", func() {
|
||||||
|
@ -104,11 +104,11 @@ var _ = Describe("TLS session resumption", func() {
|
||||||
)
|
)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Consistently(puts).ShouldNot(Receive())
|
Consistently(puts).ShouldNot(Receive())
|
||||||
Expect(sess.ConnectionState().DidResume).To(BeFalse())
|
Expect(sess.ConnectionState().TLS.DidResume).To(BeFalse())
|
||||||
|
|
||||||
serverSess, err := server.Accept(context.Background())
|
serverSess, err := server.Accept(context.Background())
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(serverSess.ConnectionState().DidResume).To(BeFalse())
|
Expect(serverSess.ConnectionState().TLS.DidResume).To(BeFalse())
|
||||||
|
|
||||||
sess, err = quic.DialAddr(
|
sess, err = quic.DialAddr(
|
||||||
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
|
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
|
||||||
|
@ -116,10 +116,10 @@ var _ = Describe("TLS session resumption", func() {
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(sess.ConnectionState().DidResume).To(BeFalse())
|
Expect(sess.ConnectionState().TLS.DidResume).To(BeFalse())
|
||||||
|
|
||||||
serverSess, err = server.Accept(context.Background())
|
serverSess, err = server.Accept(context.Background())
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(serverSess.ConnectionState().DidResume).To(BeFalse())
|
Expect(serverSess.ConnectionState().TLS.DidResume).To(BeFalse())
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -86,7 +86,7 @@ var _ = Describe("0-RTT", func() {
|
||||||
data, err := ioutil.ReadAll(str)
|
data, err := ioutil.ReadAll(str)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(data).To(Equal(testdata))
|
Expect(data).To(Equal(testdata))
|
||||||
Expect(sess.ConnectionState().Used0RTT).To(Equal(expect0RTT))
|
Expect(sess.ConnectionState().TLS.Used0RTT).To(Equal(expect0RTT))
|
||||||
close(done)
|
close(done)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ var _ = Describe("0-RTT", func() {
|
||||||
_, err = str.Write(testdata)
|
_, err = str.Write(testdata)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(str.Close()).To(Succeed())
|
Expect(str.Close()).To(Succeed())
|
||||||
Expect(sess.ConnectionState().Used0RTT).To(Equal(expect0RTT))
|
Expect(sess.ConnectionState().TLS.Used0RTT).To(Equal(expect0RTT))
|
||||||
Eventually(done).Should(BeClosed())
|
Eventually(done).Should(BeClosed())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -141,8 +141,6 @@ type StreamError interface {
|
||||||
ErrorCode() ErrorCode
|
ErrorCode() ErrorCode
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConnectionState = handshake.ConnectionState
|
|
||||||
|
|
||||||
// A Session is a QUIC connection between two peers.
|
// A Session is a QUIC connection between two peers.
|
||||||
type Session interface {
|
type Session interface {
|
||||||
// AcceptStream returns the next stream opened by the peer, blocking until one is available.
|
// AcceptStream returns the next stream opened by the peer, blocking until one is available.
|
||||||
|
@ -264,6 +262,11 @@ type Config struct {
|
||||||
Tracer logging.Tracer
|
Tracer logging.Tracer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ConnectionState records basic details about a QUIC connection
|
||||||
|
type ConnectionState struct {
|
||||||
|
TLS handshake.ConnectionState
|
||||||
|
}
|
||||||
|
|
||||||
// A Listener for incoming QUIC connections
|
// A Listener for incoming QUIC connections
|
||||||
type Listener interface {
|
type Listener interface {
|
||||||
// Close the server. All active sessions will be closed.
|
// Close the server. All active sessions will be closed.
|
||||||
|
|
|
@ -633,7 +633,9 @@ func (s *session) Context() context.Context {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *session) ConnectionState() ConnectionState {
|
func (s *session) ConnectionState() ConnectionState {
|
||||||
return s.cryptoStreamHandler.ConnectionState()
|
return ConnectionState{
|
||||||
|
TLS: s.cryptoStreamHandler.ConnectionState(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Time when the next keep-alive packet should be sent.
|
// Time when the next keep-alive packet should be sent.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue