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: peerRouting.findPeer() trying to find self #941

Merged
merged 5 commits into from
May 12, 2021
Merged

fix: peerRouting.findPeer() trying to find self #941

merged 5 commits into from
May 12, 2021

Conversation

zeim839
Copy link
Contributor

@zeim839 zeim839 commented May 11, 2021

Resolves an issue where nodes running findPeer() on themselves return abstract aggregateErrors instead of something "more suitable" like ERR_DIALED_SELF. Original issue can be found here.

This is accomplished by comparing the _idB58String of the ID parameter to this._peerId._idB58String at peer-routing.js. if the two values are equal, an error is thrown alerting the user of the mistake. For example:

async findPeer (id, options) { // eslint-disable-line require-await
    ...

    if (id._idB58String == this._peerId._idB58String) throw errCode(new Error('Cannot search for self'), 'ERR_DIALED_SELF')
    
   ...
}

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.

src/peer-routing.js Outdated Show resolved Hide resolved
zeim839 and others added 2 commits May 12, 2021 13:00
Co-authored-by: Vasco Santos <vasco.santos@ua.pt>
@zeim839
Copy link
Contributor Author

zeim839 commented May 12, 2021

@vasco-santos Added the requested tests to the best of my knowledge. They both pass. Let me know if there's anything else I need to change/improve.

test/peer-routing/peer-routing.node.js Outdated Show resolved Hide resolved
test/peer-routing/peer-routing.node.js Outdated Show resolved Hide resolved
src/peer-routing.js Outdated Show resolved Hide resolved
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.

LGTM (pushed commit fixing linting)

Thanks @zeim839

@vasco-santos vasco-santos merged commit a79c6b5 into libp2p:master May 12, 2021
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.

3 participants