From 31645233a5fa9f91a1328eac7dbb6372da2478e2 Mon Sep 17 00:00:00 2001 From: thegwan Date: Wed, 23 Oct 2019 17:45:40 +0000 Subject: [PATCH] reduce code duplication --- lib/ssh/handshake.go | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/lib/ssh/handshake.go b/lib/ssh/handshake.go index 166bbc3..d66526b 100644 --- a/lib/ssh/handshake.go +++ b/lib/ssh/handshake.go @@ -176,17 +176,10 @@ func (t *handshakeTransport) readOnePacket() ([]byte, error) { if p[0] != msgKexInit { return p, nil } - t.mu.Lock() firstKex := t.sessionID == nil - if t.config.HelloOnly { - t.sentInitMsg = nil - t.sentInitPacket = nil - t.cond.Broadcast() - t.writtenSinceKex = 0 - t.mu.Unlock() - } else { + if !t.config.HelloOnly { err = t.enterKeyExchangeLocked(p) if err != nil { // drop connection @@ -197,17 +190,16 @@ func (t *handshakeTransport) readOnePacket() ([]byte, error) { if debugHandshake { log.Printf("%s exited key exchange (first %v), err %v", t.id(), firstKex, err) } + } + // Unblock writers. + t.sentInitMsg = nil + t.sentInitPacket = nil + t.cond.Broadcast() + t.writtenSinceKex = 0 + t.mu.Unlock() - // Unblock writers. - t.sentInitMsg = nil - t.sentInitPacket = nil - t.cond.Broadcast() - t.writtenSinceKex = 0 - t.mu.Unlock() - - if err != nil { - return nil, err - } + if err != nil { + return nil, err } t.readSinceKex = 0