pkg/quic: add backward compatibility for qtls

Change-Id: I2560074ece5b61d9ddb236269172325e1b5de83e
This commit is contained in:
Yingrong Zhao 2021-01-27 15:17:19 -05:00
parent ca86820b8b
commit 824fd6f131
3 changed files with 49 additions and 1 deletions

View File

@ -15,6 +15,7 @@ import (
"storj.io/common/memory"
"storj.io/common/rpc"
"storj.io/storj/pkg/quic/qtls"
)
// Conn is a wrapper around a quic connection and fulfills net.Conn interface.
@ -71,7 +72,7 @@ func (c *Conn) getStream() (quic.Stream, error) {
// ConnectionState converts quic session state to tls connection state and returns tls state.
func (c *Conn) ConnectionState() tls.ConnectionState {
return c.session.ConnectionState().ConnectionState
return qtls.ToTLSConnectionState(c.session.ConnectionState())
}
// Close closes the quic connection.

29
pkg/quic/qtls/go114.go Normal file
View File

@ -0,0 +1,29 @@
// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
// +build go1.13 go1.14
package qtls
import (
"crypto/tls"
quicgo "github.com/lucas-clemente/quic-go"
)
// ToTLSConnectionState converts a quic-go connection state to tls connection
// state.
func ToTLSConnectionState(state quicgo.ConnectionState) tls.ConnectionState {
return tls.ConnectionState{
Version: state.Version,
HandshakeComplete: state.HandshakeComplete,
DidResume: state.DidResume,
CipherSuite: state.CipherSuite,
NegotiatedProtocol: state.NegotiatedProtocol,
ServerName: state.ServerName,
PeerCertificates: state.PeerCertificates,
VerifiedChains: state.VerifiedChains,
SignedCertificateTimestamps: state.SignedCertificateTimestamps,
OCSPResponse: state.OCSPResponse,
}
}

18
pkg/quic/qtls/go115.go Normal file
View File

@ -0,0 +1,18 @@
// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
// +build !go1.13 !go1.14
package qtls
import (
"crypto/tls"
quicgo "github.com/lucas-clemente/quic-go"
)
// ToTLSConnectionState converts a quic-go connection state to tls connection
// state.
func ToTLSConnectionState(state quicgo.ConnectionState) tls.ConnectionState {
return state.ConnectionState
}