Skip to content
This repository has been archived by the owner on Aug 19, 2022. It is now read-only.

make the error check for not receiving a public key more explicit #34

Merged
merged 1 commit into from
Nov 12, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This previously implicitly checked if the channel was closed before returning a key. We still need to check that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this. Using a chan to return the key seems a bit error-prone...

}

conn, err := t.setupConn(tlsConn, remotePubKey)
if err != nil {
Expand All @@ -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
Expand Down