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: when creating dial targets, encapsulate PeerIds last #1389

Merged
merged 1 commit into from
Sep 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 14 additions & 15 deletions src/connection-manager/dialer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,23 @@ export class DefaultDialer implements Startable, Dialer {
* Multiaddrs not supported by the available transports will be filtered out.
*/
async _createDialTarget (peer: PeerId, options: AbortOptions): Promise<DialTarget> {
const knownAddrs = await pipe(
const _resolve = this._resolve.bind(this)

const addrs = await pipe(
await this.components.getPeerStore().addressBook.get(peer),
(source) => filter(source, async (address) => {
return !(await this.components.getConnectionGater().denyDialMultiaddr(peer, address.multiaddr))
}),
// Sort addresses so, for example, we try certified public address first
(source) => sort(source, this.addressSorter),
(source) => map(source, (address) => {
const ma = address.multiaddr

async function * resolve (source) {
for await (const a of source) {
yield * await _resolve(a.multiaddr, options)
}
},
// Multiaddrs not supported by the available transports will be filtered out.
(source) => filter(source, (ma) => Boolean(this.components.getTransportManager().transportForMultiaddr(ma))),
(source) => map(source, (ma) => {
if (peer.toString() === ma.getPeerId()) {
return ma
}
Expand All @@ -250,23 +258,14 @@ export class DefaultDialer implements Startable, Dialer {
async (source) => await all(source)
)

const addrs: Multiaddr[] = []
for (const a of knownAddrs) {
const resolvedAddrs = await this._resolve(a, options)
resolvedAddrs.forEach(ra => addrs.push(ra))
}

// Multiaddrs not supported by the available transports will be filtered out.
const supportedAddrs = addrs.filter(a => this.components.getTransportManager().transportForMultiaddr(a))

if (supportedAddrs.length > this.maxAddrsToDial) {
if (addrs.length > this.maxAddrsToDial) {
await this.components.getPeerStore().delete(peer)
throw errCode(new Error('dial with more addresses than allowed'), codes.ERR_TOO_MANY_ADDRESSES)
}

return {
id: peer.toString(),
addrs: supportedAddrs
addrs
}
}

Expand Down