Skip to content

Commit ca30192

Browse files
authored
fix!: do not auto-dial peers (#1397)
Currently whenever a new peer is discovered we automatically dial them if we are below the connection manager connection limit. This is incredibly resource intensive and does not necessarily result in high-quality connections (e.g. KAD close, relays or supporting protocols we are interested in). Now that we can search the DHT for peers, this is no longer necessary so remove the functionality. BREAKING CHANGE: the old behaviour was to dial any peer we discover, now we just add them to the peer store instead
1 parent 90d3528 commit ca30192

File tree

5 files changed

+11
-81
lines changed

5 files changed

+11
-81
lines changed

examples/libp2p-in-the-browser/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ document.addEventListener('DOMContentLoaded', async () => {
5454
libp2p.addEventListener('peer:discovery', (evt) => {
5555
const peer = evt.detail
5656
log(`Found peer ${peer.id.toString()}`)
57+
58+
// dial them when we discover them
59+
libp2p.dial(evt.detail.id).catch(err => {
60+
log(`Could not dial ${evt.detail.id}`, err)
61+
})
5762
})
5863

5964
// Listen for new connections to peers

examples/peer-and-content-routing/1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const createNode = async () => {
3838
])
3939

4040
// The DHT routing tables need a moment to populate
41-
await delay(100)
41+
await delay(1000)
4242

4343
const peer = await node1.peerRouting.findPeer(node3.peerId)
4444

examples/webrtc-direct/dialer.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ document.addEventListener('DOMContentLoaded', async () => {
3131
// Listen for new peers
3232
libp2p.addEventListener('peer:discovery', (evt) => {
3333
log(`Found peer ${evt.detail.id.toString()}`)
34+
35+
// dial them when we discover them
36+
libp2p.dial(evt.detail.id).catch(err => {
37+
log(`Could not dial ${evt.detail.id}`, err)
38+
})
3439
})
3540

3641
// Listen for new connections to peers

src/connection-manager/dialer/auto-dialer.ts

Lines changed: 0 additions & 65 deletions
This file was deleted.

src/libp2p.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import { PeerRecordUpdater } from './peer-record-updater.js'
2626
import { DHTPeerRouting } from './dht/dht-peer-routing.js'
2727
import { PersistentPeerStore } from '@libp2p/peer-store'
2828
import { DHTContentRouting } from './dht/dht-content-routing.js'
29-
import { AutoDialer } from './connection-manager/dialer/auto-dialer.js'
3029
import { Initializable, Components, isInitializable } from '@libp2p/components'
3130
import type { PeerId } from '@libp2p/interface-peer-id'
3231
import type { Connection } from '@libp2p/interface-connection'
@@ -238,20 +237,6 @@ export class Libp2pNode extends EventEmitter<Libp2pEvents> implements Libp2p {
238237
...init.ping
239238
}))
240239

241-
const autoDialer = this.configureComponent(new AutoDialer(this.components, {
242-
enabled: init.connectionManager.autoDial !== false,
243-
minConnections: init.connectionManager.minConnections,
244-
dialTimeout: init.connectionManager.dialTimeout ?? 30000
245-
}))
246-
247-
this.addEventListener('peer:discovery', evt => {
248-
if (!this.isStarted()) {
249-
return
250-
}
251-
252-
autoDialer.handle(evt)
253-
})
254-
255240
// Discovery modules
256241
for (const service of init.peerDiscovery ?? []) {
257242
this.configureComponent(service)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy