Skip to content

Commit 4f533a0

Browse files
committed
fix: do not dial bootstrap nodes
Updates the bootstrap module to only discover the bootstrap nodes but not dial them. Invidiual protocols that require bootstrapping (e.g. KAD-DHT) can then react to the disovery and choose to dial the peers. This cuts down on unecessary dials for lightweight nodes and brings the bootstrap module in line with other peer discovery mechanisms.
1 parent 6f96de8 commit 4f533a0

File tree

3 files changed

+0
-73
lines changed

3 files changed

+0
-73
lines changed

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

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -104,50 +104,4 @@ describe('bootstrap', () => {
104104

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

packages/peer-discovery-bootstrap/src/index.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import { peerIdFromString } from '@libp2p/peer-id'
3737
import { P2P } from '@multiformats/mafmt'
3838
import { multiaddr } from '@multiformats/multiaddr'
3939
import type { ComponentLogger, Logger, PeerDiscovery, PeerDiscoveryEvents, PeerInfo, PeerStore, Startable } from '@libp2p/interface'
40-
import type { ConnectionManager } from '@libp2p/interface-internal'
4140

4241
const DEFAULT_BOOTSTRAP_TAG_NAME = 'bootstrap'
4342
const DEFAULT_BOOTSTRAP_TAG_VALUE = 50
@@ -77,7 +76,6 @@ export interface BootstrapInit {
7776
export interface BootstrapComponents {
7877
peerStore: PeerStore
7978
logger: ComponentLogger
80-
connectionManager: ConnectionManager
8179
}
8280

8381
/**
@@ -183,10 +181,6 @@ class Bootstrap extends TypedEventEmitter<PeerDiscoveryEvents> implements PeerDi
183181
}
184182

185183
this.safeDispatchEvent('peer', { detail: peerData })
186-
this.components.connectionManager.openConnection(peerData.id)
187-
.catch(err => {
188-
this.log.error('could not dial bootstrap peer %p', peerData.id, err)
189-
})
190184
}
191185
}
192186

packages/peer-discovery-bootstrap/test/bootstrap.spec.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,27 +57,6 @@ describe('bootstrap', () => {
5757
await stop(r)
5858
})
5959

60-
it('should dial bootstrap peers', async function () {
61-
this.timeout(5 * 1000)
62-
const r = bootstrap({
63-
list: peerList,
64-
timeout: 100
65-
})(components)
66-
67-
await start(r)
68-
69-
await new Promise<void>(resolve => {
70-
const interval = setInterval(() => {
71-
if (components.connectionManager.openConnection.callCount === 1) {
72-
clearInterval(interval)
73-
resolve()
74-
}
75-
}, 100)
76-
})
77-
78-
await stop(r)
79-
})
80-
8160
it('should tag bootstrap peers', async function () {
8261
this.timeout(5 * 1000)
8362

0 commit comments

Comments
 (0)