forked from quic-go/quic-go
remove the tls.Config from the quic.Config
The tls.Config now is a separate parameter to all Listen and Dial functions in the quic package.
This commit is contained in:
@@ -28,7 +28,8 @@ type roundTripperOpts struct {
|
||||
type client struct {
|
||||
mutex sync.RWMutex
|
||||
|
||||
dialAddr func(hostname string, config *quic.Config) (quic.Session, error)
|
||||
dialAddr func(hostname string, tlsConf *tls.Config, config *quic.Config) (quic.Session, error)
|
||||
tlsConf *tls.Config
|
||||
config *quic.Config
|
||||
opts *roundTripperOpts
|
||||
|
||||
@@ -55,8 +56,8 @@ func newClient(tlsConfig *tls.Config, hostname string, opts *roundTripperOpts) *
|
||||
hostname: authorityAddr("https", hostname),
|
||||
responses: make(map[protocol.StreamID]chan *http.Response),
|
||||
encryptionLevel: protocol.EncryptionUnencrypted,
|
||||
tlsConf: tlsConfig,
|
||||
config: &quic.Config{
|
||||
TLSConfig: tlsConfig,
|
||||
RequestConnectionIDTruncation: true,
|
||||
},
|
||||
opts: opts,
|
||||
@@ -67,7 +68,7 @@ func newClient(tlsConfig *tls.Config, hostname string, opts *roundTripperOpts) *
|
||||
// dial dials the connection
|
||||
func (c *client) dial() error {
|
||||
var err error
|
||||
c.session, err = c.dialAddr(c.hostname, c.config)
|
||||
c.session, err = c.dialAddr(c.hostname, c.tlsConf, c.config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ var _ = Describe("Client", func() {
|
||||
It("saves the TLS config", func() {
|
||||
tlsConf := &tls.Config{InsecureSkipVerify: true}
|
||||
client = newClient(tlsConf, "", &roundTripperOpts{})
|
||||
Expect(client.config.TLSConfig).To(Equal(tlsConf))
|
||||
Expect(client.tlsConf).To(Equal(tlsConf))
|
||||
})
|
||||
|
||||
It("adds the port to the hostname, if none is given", func() {
|
||||
@@ -56,7 +56,7 @@ var _ = Describe("Client", func() {
|
||||
It("dials", func(done Done) {
|
||||
client = newClient(nil, "localhost:1337", &roundTripperOpts{})
|
||||
session.streamsToOpen = []quic.Stream{newMockStream(3), newMockStream(5)}
|
||||
client.dialAddr = func(hostname string, conf *quic.Config) (quic.Session, error) {
|
||||
client.dialAddr = func(hostname string, _ *tls.Config, _ *quic.Config) (quic.Session, error) {
|
||||
return session, nil
|
||||
}
|
||||
close(headerStream.unblockRead)
|
||||
@@ -68,7 +68,7 @@ var _ = Describe("Client", func() {
|
||||
It("errors when dialing fails", func() {
|
||||
testErr := errors.New("handshake error")
|
||||
client = newClient(nil, "localhost:1337", &roundTripperOpts{})
|
||||
client.dialAddr = func(hostname string, conf *quic.Config) (quic.Session, error) {
|
||||
client.dialAddr = func(hostname string, _ *tls.Config, _ *quic.Config) (quic.Session, error) {
|
||||
return nil, testErr
|
||||
}
|
||||
_, err := client.RoundTrip(req)
|
||||
@@ -78,7 +78,7 @@ var _ = Describe("Client", func() {
|
||||
It("errors if the header stream has the wrong stream ID", func() {
|
||||
client = newClient(nil, "localhost:1337", &roundTripperOpts{})
|
||||
session.streamsToOpen = []quic.Stream{&mockStream{id: 2}}
|
||||
client.dialAddr = func(hostname string, conf *quic.Config) (quic.Session, error) {
|
||||
client.dialAddr = func(hostname string, _ *tls.Config, _ *quic.Config) (quic.Session, error) {
|
||||
return session, nil
|
||||
}
|
||||
_, err := client.RoundTrip(req)
|
||||
@@ -89,7 +89,7 @@ var _ = Describe("Client", func() {
|
||||
testErr := errors.New("you shall not pass")
|
||||
client = newClient(nil, "localhost:1337", &roundTripperOpts{})
|
||||
session.streamOpenErr = testErr
|
||||
client.dialAddr = func(hostname string, conf *quic.Config) (quic.Session, error) {
|
||||
client.dialAddr = func(hostname string, _ *tls.Config, _ *quic.Config) (quic.Session, error) {
|
||||
return session, nil
|
||||
}
|
||||
_, err := client.RoundTrip(req)
|
||||
@@ -98,7 +98,7 @@ var _ = Describe("Client", func() {
|
||||
|
||||
It("returns a request when dial fails", func() {
|
||||
testErr := errors.New("dial error")
|
||||
client.dialAddr = func(hostname string, conf *quic.Config) (quic.Session, error) {
|
||||
client.dialAddr = func(hostname string, _ *tls.Config, _ *quic.Config) (quic.Session, error) {
|
||||
return nil, testErr
|
||||
}
|
||||
request, err := http.NewRequest("https", "https://quic.clemente.io:1337/file1.dat", nil)
|
||||
@@ -140,7 +140,7 @@ var _ = Describe("Client", func() {
|
||||
BeforeEach(func() {
|
||||
var err error
|
||||
client.encryptionLevel = protocol.EncryptionForwardSecure
|
||||
client.dialAddr = func(hostname string, conf *quic.Config) (quic.Session, error) {
|
||||
client.dialAddr = func(hostname string, _ *tls.Config, _ *quic.Config) (quic.Session, error) {
|
||||
return session, nil
|
||||
}
|
||||
dataStream = newMockStream(5)
|
||||
|
||||
@@ -84,16 +84,15 @@ func (s *Server) serveImpl(tlsConfig *tls.Config, conn *net.UDPConn) error {
|
||||
}
|
||||
|
||||
config := quic.Config{
|
||||
TLSConfig: tlsConfig,
|
||||
Versions: protocol.SupportedVersions,
|
||||
Versions: protocol.SupportedVersions,
|
||||
}
|
||||
|
||||
var ln quic.Listener
|
||||
var err error
|
||||
if conn == nil {
|
||||
ln, err = quic.ListenAddr(s.Addr, &config)
|
||||
ln, err = quic.ListenAddr(s.Addr, tlsConfig, &config)
|
||||
} else {
|
||||
ln, err = quic.Listen(conn, &config)
|
||||
ln, err = quic.Listen(conn, tlsConfig, &config)
|
||||
}
|
||||
if err != nil {
|
||||
s.listenerMutex.Unlock()
|
||||
|
||||
Reference in New Issue
Block a user