Skip to content

Commit 0863a7a

Browse files
achingbrainSgtPooki
andcommitted
fix!: remove autodialer (#2639)
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>
1 parent 8d18c3d commit 0863a7a

32 files changed

+532
-937
lines changed

doc/CONFIGURATION.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,7 @@ const node = await createLibp2p({
626626
noise()
627627
],
628628
connectionManager: {
629-
maxConnections: Infinity,
630-
minConnections: 0
629+
maxConnections: Infinity
631630
}
632631
})
633632
```

doc/LIMITS.md

-6
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@ const node = await createLibp2p({
3838
*/
3939
maxConnections: 100,
4040

41-
/**
42-
* If the number of open connections goes below this number, the node
43-
* will try to connect to randomly selected peers from the peer store
44-
*/
45-
minConnections: 50,
46-
4741
/**
4842
* How many connections can be open but not yet upgraded
4943
*/

interop/test/fixtures/get-libp2p.ts

-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ const IP = process.env.ip ?? '0.0.0.0'
2525
export async function getLibp2p (): Promise<Libp2p<{ ping: PingService }>> {
2626
const options: Libp2pOptions<{ ping: PingService, identify: Identify }> = {
2727
start: true,
28-
connectionManager: {
29-
minConnections: 0
30-
},
3128
connectionGater: {
3229
denyDialMultiaddr: async () => false
3330
},

packages/integration-tests/.aegir.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ export default {
2424
const peerId = await createEd25519PeerId()
2525
const libp2p = await createLibp2p({
2626
connectionManager: {
27-
inboundConnectionThreshold: Infinity,
28-
minConnections: 0
27+
inboundConnectionThreshold: Infinity
2928
},
3029
addresses: {
3130
listen: [

packages/integration-tests/test/bootstrap.spec.ts

+51
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
import { bootstrap } from '@libp2p/bootstrap'
44
import { TypedEventEmitter, peerDiscoverySymbol } from '@libp2p/interface'
5+
import { mplex } from '@libp2p/mplex'
56
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
7+
import { plaintext } from '@libp2p/plaintext'
68
import { webSockets } from '@libp2p/websockets'
9+
import * as Filter from '@libp2p/websockets/filters'
710
import { multiaddr } from '@multiformats/multiaddr'
811
import { expect } from 'aegir/chai'
912
import { createLibp2p } from 'libp2p'
@@ -103,4 +106,52 @@ describe('bootstrap', () => {
103106

104107
return deferred.promise
105108
})
109+
110+
it('bootstrap should dial all peers in the list', async () => {
111+
const deferred = defer()
112+
113+
const bootstrappers = [
114+
`${process.env.RELAY_MULTIADDR}`
115+
]
116+
117+
libp2p = await createLibp2p({
118+
connectionEncryption: [
119+
plaintext()
120+
],
121+
transports: [
122+
webSockets({
123+
filter: Filter.all
124+
})
125+
],
126+
streamMuxers: [
127+
mplex()
128+
],
129+
peerDiscovery: [
130+
bootstrap({
131+
list: bootstrappers
132+
})
133+
],
134+
connectionGater: {
135+
denyDialMultiaddr: () => false
136+
}
137+
})
138+
139+
const expectedPeers = new Set(
140+
bootstrappers.map(ma => multiaddr(ma).getPeerId())
141+
)
142+
143+
libp2p.addEventListener('connection:open', (evt) => {
144+
const { remotePeer } = evt.detail
145+
146+
expectedPeers.delete(remotePeer.toString())
147+
if (expectedPeers.size === 0) {
148+
libp2p.removeEventListener('connection:open')
149+
deferred.resolve()
150+
}
151+
})
152+
153+
await libp2p.start()
154+
155+
return deferred.promise
156+
})
106157
})

packages/integration-tests/test/circuit-relay.node.ts

-3
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ async function createClient (options: Libp2pOptions = {}): Promise<Libp2p> {
4242
connectionEncryption: [
4343
plaintext()
4444
],
45-
connectionManager: {
46-
minConnections: 0
47-
},
4845
services: {
4946
identify: identify()
5047
},

packages/integration-tests/test/fetch.spec.ts

-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ async function createNode (): Promise<Libp2p<{ fetch: Fetch }>> {
1111
return createLibp2p(createBaseOptions({
1212
services: {
1313
fetch: fetch()
14-
},
15-
connectionManager: {
16-
minConnections: 0
1714
}
1815
}))
1916
}

packages/integration-tests/test/interop.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,7 @@ async function createJsPeer (options: SpawnOptions): Promise<Daemon> {
135135
},
136136
transports: [tcp(), circuitRelayTransport()],
137137
streamMuxers: [],
138-
connectionEncryption: [noise()],
139-
connectionManager: {
140-
minConnections: 0
141-
}
138+
connectionEncryption: [noise()]
142139
}
143140

144141
if (options.noListen !== true) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/* eslint-env mocha */
2+
3+
import { KEEP_ALIVE, type Libp2p } from '@libp2p/interface'
4+
import { expect } from 'aegir/chai'
5+
import { createLibp2p } from 'libp2p'
6+
import pWaitFor from 'p-wait-for'
7+
import { createBaseOptions } from './fixtures/base-options.js'
8+
9+
describe('peers', () => {
10+
let nodes: Libp2p[]
11+
12+
beforeEach(async () => {
13+
nodes = await Promise.all([
14+
createLibp2p(createBaseOptions()),
15+
createLibp2p(createBaseOptions()),
16+
createLibp2p(createBaseOptions())
17+
])
18+
})
19+
20+
afterEach(async () => Promise.all(nodes.map(async n => { await n.stop() })))
21+
22+
it('should redial a peer tagged with KEEP_ALIVE', async () => {
23+
await nodes[0].dial(nodes[1].getMultiaddrs())
24+
25+
expect(nodes[0].getConnections(nodes[1].peerId)).to.not.be.empty()
26+
27+
await nodes[0].peerStore.merge(nodes[1].peerId, {
28+
tags: {
29+
[KEEP_ALIVE]: {
30+
value: 1
31+
}
32+
}
33+
})
34+
35+
await Promise.all(
36+
nodes[0].getConnections(nodes[1].peerId).map(async conn => conn.close())
37+
)
38+
39+
await pWaitFor(async () => {
40+
return nodes[0].getConnections(nodes[1].peerId).length > 0
41+
}, {
42+
interval: 100,
43+
timeout: {
44+
milliseconds: 5000,
45+
message: 'Did not reconnect to peer tagged with KEEP_ALIVE'
46+
}
47+
})
48+
})
49+
50+
it('should store the multiaddr for a peer after a successful dial', async () => {
51+
await nodes[0].dial(nodes[1].getMultiaddrs())
52+
53+
expect(nodes[0].getConnections(nodes[1].peerId)).to.not.be.empty()
54+
55+
const peer = await nodes[0].peerStore.get(nodes[1].peerId)
56+
expect(peer.addresses).to.not.be.empty()
57+
expect(peer.metadata.get('last-dial-success')).to.be.ok()
58+
})
59+
})

packages/libp2p/.aegir.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ export default {
2020
const peerId = await createEd25519PeerId()
2121
const libp2p = await createLibp2p({
2222
connectionManager: {
23-
inboundConnectionThreshold: Infinity,
24-
minConnections: 0
23+
inboundConnectionThreshold: Infinity
2524
},
2625
addresses: {
2726
listen: [

packages/libp2p/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
"merge-options": "^3.0.4",
108108
"multiformats": "^13.1.0",
109109
"p-defer": "^4.0.1",
110+
"p-retry": "^6.2.0",
110111
"progress-events": "^1.0.0",
111112
"race-event": "^1.3.0",
112113
"race-signal": "^1.0.2",

0 commit comments

Comments
 (0)