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: make getPeerId return the target peer id from relay addrs #325

Merged
merged 3 commits into from
Jul 28, 2023

Conversation

achingbrain
Copy link
Member

If a p2p-circuit address doesn't contain the /p2p/QmFoo tuple for the target peer, getPeerId returns the peer id of the relay which is not what you'd expect.

The fix here is for relay addresses, to return the peer id of the target and never the relay.

Fixes #319

If a p2p-circuit address doesn't contain the `/p2p/QmFoo` tuple for
the target peer, `getPeerId` returns the peer id of the relay which
is not what you'd expect.

The fix here is for relay addresses, to return the peer id of the
target and never the relay.

Fixes #319
@achingbrain achingbrain requested a review from SgtPooki May 11, 2023 07:52
Copy link

@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

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

approved, but questions/concerns.

Comment on lines +661 to 669
if (code === names.p2p.code) {
tuples.push([code, name])
}

// if this is a p2p-circuit address, return the target peer id if present
// not the peer id of the relay
if (code === names['p2p-circuit'].code) {
tuples = []
}

Choose a reason for hiding this comment

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

i find it confusing that we push to tuples and then empty tuples if p2p-circuit is found.

Could this result in (eventually longer and currently unknown) multiaddr tuples being removed that shouldn't? Instead, should we just not call tuples.push if it's the p2p-circuit case for the current code?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think so, because circuit relay addresses are not supposed to be relayed themselves so whatever is after p2p-circuit should be what we are interested in.

We reset the tuples because whatever was before the p2p-circuit tuple is the relay address and we're trying to extract the PeerId of the target, not the relay.

It's trying to handle the case of:

/ip4/foo/p2p/QmRelay/p2p-circuit -> should return null not QmRelay

Comment on lines +1000 to +1004
it('does not extract a peer Id from a circuit relay multiaddr where only the relay peer id is present', () => {
expect(
multiaddr('/ip4/127.0.0.1/tcp/123/p2p/bafzbeigweq4zr4x4ky2dvv7nanbkw6egutvrrvzw6g3h2rftp7gidyhtt4/p2p-circuit').getPeerId()
).to.be.null()
})

Choose a reason for hiding this comment

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

the positive test case (peerId of relayed peer exists) already exists in the tests from what I can see. However, do we need to check a case where we have something like

/ip4/127.0.0.1/tcp/123/p2p/bafzbeigweq4zr4x4ky2dvv7nanbkw6egutvrrvzw6g3h2rftp7gidyhtt4/p2p-circuit/p2p/bafzbeidt255unskpefjmqb2rc27vjuyxopkxgaylxij6pw35hhys4vnyp4

to make sure the correct peer ID is returned when there are two?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we have this in the 'extracts the correct peer Id from a circuit multiaddr' test?

@achingbrain achingbrain changed the title fix: make getPeerId return the target peer id from relay addresses fix: make getPeerId return the target peer id from relay addrs Jul 28, 2023
@achingbrain achingbrain merged commit 2b0e353 into master Jul 28, 2023
17 checks passed
@achingbrain achingbrain deleted the fix/return-relay-target-peer-id branch July 28, 2023 17:52
github-actions bot pushed a commit that referenced this pull request Jul 28, 2023
## [12.1.5](v12.1.4...v12.1.5) (2023-07-28)

### Bug Fixes

* make getPeerId return the target peer id from relay addrs ([#325](#325)) ([2b0e353](2b0e353)), closes [#319](#319)
@github-actions
Copy link

🎉 This PR is included in version 12.1.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

getPeerId can return an unexpected peer id
2 participants