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,17 +190,16 @@ 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.
t.sentInitMsg = nil
t.sentInitPacket = nil
t.cond.Broadcast()
t.writtenSinceKex = 0
t.mu.Unlock()
// Unblock writers. if err != nil {
t.sentInitMsg = nil return nil, err
t.sentInitPacket = nil
t.cond.Broadcast()
t.writtenSinceKex = 0
t.mu.Unlock()
if err != nil {
return nil, err
}
} }
t.readSinceKex = 0 t.readSinceKex = 0