From 27e03a0a2fc644841719cce58a267e3cfcd6d85f Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Thu, 1 Aug 2019 09:18:41 +0700 Subject: [PATCH] make the error check for not receiving a public key more explicit --- transport.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/transport.go b/transport.go index 2dc4257..c563d09 100644 --- a/transport.go +++ b/transport.go @@ -105,6 +105,9 @@ func (t *Transport) handshake( case remotePubKey = <-keyCh: default: } + if remotePubKey == nil { + return nil, errors.New("go-libp2p-tls BUG: expected remote pub key to be set") + } conn, err := t.setupConn(tlsConn, remotePubKey) if err != nil { @@ -118,10 +121,6 @@ func (t *Transport) handshake( } func (t *Transport) setupConn(tlsConn *tls.Conn, remotePubKey ci.PubKey) (sec.SecureConn, error) { - if remotePubKey == nil { - return nil, errors.New("go-libp2p-tls BUG: expected remote pub key to be set") - } - remotePeerID, err := peer.IDFromPublicKey(remotePubKey) if err != nil { return nil, err