pass the crypto stream to the crypto setup constructor

The crypto stream is opened during the session setup. Passing it to the
crypto setup directly helps simplify the constructor.
This commit is contained in:
Marten Seemann
2017-10-21 09:48:25 +07:00
parent a88da29433
commit 282b423f7d
10 changed files with 75 additions and 74 deletions

View File

@@ -67,6 +67,7 @@ var ErrNSTPExperiment = qerr.Error(qerr.InvalidCryptoMessageParameter, "NSTP exp
// NewCryptoSetup creates a new CryptoSetup instance for a server
func NewCryptoSetup(
cryptoStream io.ReadWriter,
connID protocol.ConnectionID,
remoteAddr net.Addr,
version protocol.VersionNumber,
@@ -78,6 +79,7 @@ func NewCryptoSetup(
aeadChanged chan<- protocol.EncryptionLevel,
) (CryptoSetup, error) {
return &cryptoSetupServer{
cryptoStream: cryptoStream,
connID: connID,
remoteAddr: remoteAddr,
version: version,
@@ -95,9 +97,7 @@ func NewCryptoSetup(
}
// HandleCryptoStream reads and writes messages on the crypto stream
func (h *cryptoSetupServer) HandleCryptoStream(stream io.ReadWriter) error {
h.cryptoStream = stream
func (h *cryptoSetupServer) HandleCryptoStream() error {
for {
var chloData bytes.Buffer
message, err := ParseHandshakeMessage(io.TeeReader(h.cryptoStream, &chloData))