replace CachingReader with io.TeeReader

This commit is contained in:
Lucas Clemente
2016-09-05 23:21:17 +02:00
parent e3b8c413a5
commit bc54c50b7e
3 changed files with 4 additions and 75 deletions

View File

@@ -3,6 +3,7 @@ package handshake
import (
"bytes"
"crypto/rand"
"io"
"net"
"sync"
@@ -70,19 +71,18 @@ func NewCryptoSetup(
// HandleCryptoStream reads and writes messages on the crypto stream
func (h *CryptoSetup) HandleCryptoStream() error {
for {
cachingReader := utils.NewCachingReader(h.cryptoStream)
messageTag, cryptoData, err := ParseHandshakeMessage(cachingReader)
var chloData bytes.Buffer
messageTag, cryptoData, err := ParseHandshakeMessage(io.TeeReader(h.cryptoStream, &chloData))
if err != nil {
return qerr.HandshakeFailed
}
if messageTag != TagCHLO {
return qerr.InvalidCryptoMessageType
}
chloData := cachingReader.Get()
utils.Debugf("Got CHLO:\n%s", printHandshakeMessage(cryptoData))
done, err := h.handleMessage(chloData, cryptoData)
done, err := h.handleMessage(chloData.Bytes(), cryptoData)
if err != nil {
return err
}