-
Notifications
You must be signed in to change notification settings - Fork 510
feat: resolve multiaddrs before dial #782
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
Conversation
| * @param {Multiaddr} ma | ||
| * @returns {Promise<Array<Multiaddr>>} | ||
| */ | ||
| async _resolve (ma) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once we support recursion in multiaddr, as well as dns4+dns6 resolution, we will not need this function, only the function below
16a0032 to
79d2852
Compare
src/dialer/index.js
Outdated
| */ | ||
| async _resolve (ma) { | ||
| // TODO: recursive logic should live in multiaddr once dns4/dns6 support is in place | ||
| const resolvableProto = ma.protos().find((p) => p.resolvable) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should simplify this for now and only resolve if ma.protoNames().includes('dnsaddr'). The checks below don't account for dns addresses. If new resolvable addresses are added, we may need to account for them further, so I would just simplify this for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I agree!
|
Just tested this out with a direct dial from libp2p: |
|
|
||
| const addrs = [] | ||
| for (const a of knownAddrs) { | ||
| const resolvedAddrs = await this._resolve(a) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolve can throw, we shouldn't let a single address failure stop the whole dial, we need to catch it
| return [ma] | ||
| } | ||
|
|
||
| const resolvedMultiaddrs = await this._resolveRecord(ma) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can throw which will stop the whole dial, we should let individual addresses fail.
| [`dnsaddr=${relayedAddr(peerId)}`] | ||
| ] | ||
|
|
||
| describe('Dialing (resolvable addresses)', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a test where the resolve throws for and address to ensure we can still succeed if others pass.
5ae4f29 to
4e0a78e
Compare
4e0a78e to
2019f74
Compare
2019f74 to
389d0db
Compare
3b3911b to
336ee0c
Compare
|
I merged in @mburns PR and tested out the example with the new |
Per #772 (comment) we should get the |
Still investigating the unreachable hosts, they should be back up shortly. |
|
Thanks @mburns ! Everything seems great not 🎉 |
jacobheun
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM just two minor nits
test/dialing/resolver.spec.js
Outdated
| let firstCall = false | ||
| let secondCall = false | ||
|
|
||
| const stub = sinon.stub(Resolver.prototype, 'resolveTxt') | ||
| stub.callsFake(() => { | ||
| if (!firstCall) { | ||
| firstCall = true | ||
| // Return an array of dnsaddr | ||
| return Promise.resolve(getDnsaddrStub(remoteId)) | ||
| } else if (!secondCall) { | ||
| secondCall = true | ||
| // Address failed to resolve | ||
| return Promise.reject(new Error()) | ||
| } | ||
| return Promise.resolve(getDnsRelayedAddrStub(remoteId)) | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to use sinon to simplify this a bit, something like:
| let firstCall = false | |
| let secondCall = false | |
| const stub = sinon.stub(Resolver.prototype, 'resolveTxt') | |
| stub.callsFake(() => { | |
| if (!firstCall) { | |
| firstCall = true | |
| // Return an array of dnsaddr | |
| return Promise.resolve(getDnsaddrStub(remoteId)) | |
| } else if (!secondCall) { | |
| secondCall = true | |
| // Address failed to resolve | |
| return Promise.reject(new Error()) | |
| } | |
| return Promise.resolve(getDnsRelayedAddrStub(remoteId)) | |
| }) | |
| const stub = sinon.stub(Resolver.prototype, 'resolveTxt') | |
| stub.onCall(0).callsFake(() => Promise.resolve(getDnsaddrStub(remoteId))) | |
| stub.onCall(1).callsFake(() => Promise.reject(new Error())) | |
| stub.callsFake(() => Promise.resolve(getDnsRelayedAddrStub(remoteId))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, that works. I did not understand that I could use callsFake for the "other" calls, which was making things difficult 👍
Co-authored-by: Jacob Heun <[email protected]>
ff56987 to
33fac9a
Compare
Adds the new `dnsaddr` multiaddrs for browser bootstrapping peers per libp2p/js-libp2p#772 and libp2p/js-libp2p#782


This PR adds the ability to resolve multiaddrs before dialling. The multiaddr resolvers are customizable within the dialer configuration and come with a default for
dnsaddr. At this moment, we do not resolvedns4anddns6per #772 (comment) . I will make sure to create an issue to track this.Needs: