Skip to content

Commit

Permalink
fix!: remove autodialer (#2639)
Browse files Browse the repository at this point in the history
The autodialer is a feature from an older time when the DHT was less reliable and we didn't have things like the random walk component.

There's not a lot of benefit in opening connections to any old peer, instead protocols now have better ways of targetting the kind of peers they require.

Actively dialing peers harms platforms where connections are extremely expensive such as react-native so this feature has been removed.

Closes #2621
Fixes #2418

BREAKING CHANGE: the autodialer has been removed as well as the corresponding config keys

---------

Co-authored-by: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com>
  • Loading branch information
achingbrain and SgtPooki committed Sep 6, 2024
1 parent 0d20426 commit ab90179
Show file tree
Hide file tree
Showing 32 changed files with 532 additions and 937 deletions.
3 changes: 1 addition & 2 deletions doc/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -626,8 +626,7 @@ const node = await createLibp2p({
noise()
],
connectionManager: {
maxConnections: Infinity,
minConnections: 0
maxConnections: Infinity
}
})
```
Expand Down
6 changes: 0 additions & 6 deletions doc/LIMITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ const node = await createLibp2p({
*/
maxConnections: 100,

/**
* If the number of open connections goes below this number, the node
* will try to connect to randomly selected peers from the peer store
*/
minConnections: 50,

/**
* How many connections can be open but not yet upgraded
*/
Expand Down
3 changes: 0 additions & 3 deletions interop/test/fixtures/get-libp2p.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ const IP = process.env.ip ?? '0.0.0.0'
export async function getLibp2p (): Promise<Libp2p<{ ping: PingService }>> {
const options: Libp2pOptions<{ ping: PingService, identify: Identify }> = {
start: true,
connectionManager: {
minConnections: 0
},
connectionGater: {
denyDialMultiaddr: async () => false
},
Expand Down
3 changes: 1 addition & 2 deletions packages/integration-tests/.aegir.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ export default {
const peerId = await createEd25519PeerId()
const libp2p = await createLibp2p({
connectionManager: {
inboundConnectionThreshold: Infinity,
minConnections: 0
inboundConnectionThreshold: Infinity
},
addresses: {
listen: [
Expand Down
51 changes: 51 additions & 0 deletions packages/integration-tests/test/bootstrap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import { bootstrap } from '@libp2p/bootstrap'
import { TypedEventEmitter, peerDiscoverySymbol } from '@libp2p/interface'
import { mplex } from '@libp2p/mplex'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
import { plaintext } from '@libp2p/plaintext'
import { webSockets } from '@libp2p/websockets'
import * as Filter from '@libp2p/websockets/filters'
import { multiaddr } from '@multiformats/multiaddr'
import { expect } from 'aegir/chai'
import { createLibp2p } from 'libp2p'
Expand Down Expand Up @@ -103,4 +106,52 @@ describe('bootstrap', () => {

return deferred.promise
})

it('bootstrap should dial all peers in the list', async () => {
const deferred = defer()

const bootstrappers = [
`${process.env.RELAY_MULTIADDR}`
]

libp2p = await createLibp2p({
connectionEncryption: [
plaintext()
],
transports: [
webSockets({
filter: Filter.all
})
],
streamMuxers: [
mplex()
],
peerDiscovery: [
bootstrap({
list: bootstrappers
})
],
connectionGater: {
denyDialMultiaddr: () => false
}
})

const expectedPeers = new Set(
bootstrappers.map(ma => multiaddr(ma).getPeerId())
)

libp2p.addEventListener('connection:open', (evt) => {
const { remotePeer } = evt.detail

expectedPeers.delete(remotePeer.toString())
if (expectedPeers.size === 0) {
libp2p.removeEventListener('connection:open')
deferred.resolve()
}
})

await libp2p.start()

return deferred.promise
})
})
3 changes: 0 additions & 3 deletions packages/integration-tests/test/circuit-relay.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ async function createClient (options: Libp2pOptions = {}): Promise<Libp2p> {
connectionEncryption: [
plaintext()
],
connectionManager: {
minConnections: 0
},
services: {
identify: identify()
},
Expand Down
3 changes: 0 additions & 3 deletions packages/integration-tests/test/fetch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ async function createNode (): Promise<Libp2p<{ fetch: Fetch }>> {
return createLibp2p(createBaseOptions({
services: {
fetch: fetch()
},
connectionManager: {
minConnections: 0
}
}))
}
Expand Down
5 changes: 1 addition & 4 deletions packages/integration-tests/test/interop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,7 @@ async function createJsPeer (options: SpawnOptions): Promise<Daemon> {
},
transports: [tcp(), circuitRelayTransport()],
streamMuxers: [],
connectionEncryption: [noise()],
connectionManager: {
minConnections: 0
}
connectionEncryption: [noise()]
}

if (options.noListen !== true) {
Expand Down
59 changes: 59 additions & 0 deletions packages/integration-tests/test/peers.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* eslint-env mocha */

import { KEEP_ALIVE, type Libp2p } from '@libp2p/interface'
import { expect } from 'aegir/chai'
import { createLibp2p } from 'libp2p'
import pWaitFor from 'p-wait-for'
import { createBaseOptions } from './fixtures/base-options.js'

describe('peers', () => {
let nodes: Libp2p[]

beforeEach(async () => {
nodes = await Promise.all([
createLibp2p(createBaseOptions()),
createLibp2p(createBaseOptions()),
createLibp2p(createBaseOptions())
])
})

afterEach(async () => Promise.all(nodes.map(async n => { await n.stop() })))

it('should redial a peer tagged with KEEP_ALIVE', async () => {
await nodes[0].dial(nodes[1].getMultiaddrs())

expect(nodes[0].getConnections(nodes[1].peerId)).to.not.be.empty()

await nodes[0].peerStore.merge(nodes[1].peerId, {
tags: {
[KEEP_ALIVE]: {
value: 1
}
}
})

await Promise.all(
nodes[0].getConnections(nodes[1].peerId).map(async conn => conn.close())
)

await pWaitFor(async () => {
return nodes[0].getConnections(nodes[1].peerId).length > 0
}, {
interval: 100,
timeout: {
milliseconds: 5000,
message: 'Did not reconnect to peer tagged with KEEP_ALIVE'
}
})
})

it('should store the multiaddr for a peer after a successful dial', async () => {
await nodes[0].dial(nodes[1].getMultiaddrs())

expect(nodes[0].getConnections(nodes[1].peerId)).to.not.be.empty()

const peer = await nodes[0].peerStore.get(nodes[1].peerId)
expect(peer.addresses).to.not.be.empty()
expect(peer.metadata.get('last-dial-success')).to.be.ok()
})
})
3 changes: 1 addition & 2 deletions packages/libp2p/.aegir.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ export default {
const peerId = await createEd25519PeerId()
const libp2p = await createLibp2p({
connectionManager: {
inboundConnectionThreshold: Infinity,
minConnections: 0
inboundConnectionThreshold: Infinity
},
addresses: {
listen: [
Expand Down
1 change: 1 addition & 0 deletions packages/libp2p/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"merge-options": "^3.0.4",
"multiformats": "^13.1.0",
"p-defer": "^4.0.1",
"p-retry": "^6.2.0",
"progress-events": "^1.0.0",
"race-event": "^1.3.0",
"race-signal": "^1.0.2",
Expand Down
Loading

0 comments on commit ab90179

Please sign in to comment.