reduce code duplication

This commit is contained in:
thegwan 2019-10-23 17:45:40 +00:00
parent 86e24ff81f
commit 31645233a5

@ -176,17 +176,10 @@ func (t *handshakeTransport) readOnePacket() ([]byte, error) {
if p[0] != msgKexInit { if p[0] != msgKexInit {
return p, nil return p, nil
} }
t.mu.Lock() t.mu.Lock()
firstKex := t.sessionID == nil firstKex := t.sessionID == nil
if t.config.HelloOnly { if !t.config.HelloOnly {
t.sentInitMsg = nil
t.sentInitPacket = nil
t.cond.Broadcast()
t.writtenSinceKex = 0
t.mu.Unlock()
} else {
err = t.enterKeyExchangeLocked(p) err = t.enterKeyExchangeLocked(p)
if err != nil { if err != nil {
// drop connection // drop connection
@ -197,7 +190,7 @@ func (t *handshakeTransport) readOnePacket() ([]byte, error) {
if debugHandshake { if debugHandshake {
log.Printf("%s exited key exchange (first %v), err %v", t.id(), firstKex, err) log.Printf("%s exited key exchange (first %v), err %v", t.id(), firstKex, err)
} }
}
// Unblock writers. // Unblock writers.
t.sentInitMsg = nil t.sentInitMsg = nil
t.sentInitPacket = nil t.sentInitPacket = nil
@ -208,7 +201,6 @@ func (t *handshakeTransport) readOnePacket() ([]byte, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
}
t.readSinceKex = 0 t.readSinceKex = 0
// By default, a key exchange is hidden from higher layers by // By default, a key exchange is hidden from higher layers by