Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dialer.connectToPeer to throw a clean error #673

Closed

Conversation

dthorpe
Copy link

@dthorpe dthorpe commented Jun 16, 2020

when dialTarget.addrs is undefined

Fixes #672

Copy link
Member

@vasco-santos vasco-santos left a comment

Choose a reason for hiding this comment

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

@dthorpe Thanks for having the time to fix this.
I left some feedback

@@ -96,6 +96,14 @@ describe('Dialing (direct, TCP)', () => {
.and.to.have.nested.property('._errors[0].code', ErrorCodes.ERR_TRANSPORT_UNAVAILABLE)
})

it('should fail appropriately if peer has no addresses', async () => {
const dialer = new Dialer({ transportManager: localTM, peerStore })
const peer = new PeerId(Buffer.from('QmfEa1LrSt2R7KiZ31yPo3TT8ipfyDfrMRkaQix3rcXeTo'))
Copy link
Member

Choose a reason for hiding this comment

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

Can you use the createPeerId function already required to create the PeerId? We try to use that because it creates a PeerId from a JSON which already have everything computed and the tests will be faster to run.

Copy link
Author

Choose a reason for hiding this comment

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

k

@@ -111,6 +111,7 @@
"libp2p-tcp": "^0.14.1",
"libp2p-webrtc-star": "^0.18.0",
"libp2p-websockets": "^0.13.1",
"mocha": "^8.0.1",
Copy link
Member

Choose a reason for hiding this comment

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

What is the reason to require mocha here?

Copy link
Author

Choose a reason for hiding this comment

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

seemed to be required to run the unit tests in intellij. 🤷

Copy link
Member

Choose a reason for hiding this comment

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

This is strange. I do not have intellij to test this out, but running the tests in the CLI does not require mocha as we are not using it

@@ -70,7 +70,7 @@ class Dialer {
async connectToPeer (peer, options = {}) {
const dialTarget = this._createDialTarget(peer)

if (!dialTarget.addrs.length) {
if (!dialTarget.addrs || !dialTarget.addrs.length) {
Copy link
Member

Choose a reason for hiding this comment

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

What do you think on doing the following in the this._createDialTarget?

let addrs = this.peerStore.addressBook.getMultiaddrsForPeer(id) || []

I think it would be cleaner.

@vasco-santos
Copy link
Member

@dthorpe will you be able to finish this review, or should I take it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dialer.connectToPeer fails badly if no addrs
2 participants