Skip to content

Commit

Permalink
feat!: remove autodialer
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

BREAKING CHANGE: the autodialer has been removed as well as the corresponding config keys
  • Loading branch information
achingbrain committed Jul 31, 2024
1 parent 944935f commit 319ddba
Show file tree
Hide file tree
Showing 27 changed files with 117 additions and 896 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 @@ -12,9 +12,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 @@ -134,10 +134,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
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
Loading

0 comments on commit 319ddba

Please sign in to comment.