Skip to content
This repository was archived by the owner on Jun 26, 2023. It is now read-only.

Commit b93d051

Browse files
authored
fix: remove connection manager options (#208)
It's in the libp2p module, no need to make it part of the API here. Also start components in parallel
1 parent 24c8fb8 commit b93d051

File tree

2 files changed

+38
-93
lines changed

2 files changed

+38
-93
lines changed

packages/libp2p-interfaces/src/components.ts

+38-38
Original file line numberDiff line numberDiff line change
@@ -124,63 +124,63 @@ export class Components implements Startable {
124124
}
125125

126126
async beforeStart () {
127-
for (const obj of Object.values(this).filter(obj => isStartable(obj))) {
128-
const startable = obj as Startable
129-
130-
if (startable.beforeStart != null) {
131-
await startable.beforeStart()
132-
}
133-
}
127+
await Promise.all(
128+
Object.values(this).filter(obj => isStartable(obj)).map(async (startable: Startable) => {
129+
if (startable.beforeStart != null) {
130+
await startable.beforeStart()
131+
}
132+
})
133+
)
134134
}
135135

136136
async start () {
137-
for (const obj of Object.values(this).filter(obj => isStartable(obj))) {
138-
const startable = obj as Startable
139-
140-
await startable.start()
141-
}
137+
await Promise.all(
138+
Object.values(this).filter(obj => isStartable(obj)).map(async (startable: Startable) => {
139+
await startable.start()
140+
})
141+
)
142142

143143
this.started = true
144144
}
145145

146146
async afterStart () {
147-
for (const obj of Object.values(this).filter(obj => isStartable(obj))) {
148-
const startable = obj as Startable
149-
150-
if (startable.afterStart != null) {
151-
await startable.afterStart()
152-
}
153-
}
147+
await Promise.all(
148+
Object.values(this).filter(obj => isStartable(obj)).map(async (startable: Startable) => {
149+
if (startable.afterStart != null) {
150+
await startable.afterStart()
151+
}
152+
})
153+
)
154154
}
155155

156156
async beforeStop () {
157-
for (const obj of Object.values(this).filter(obj => isStartable(obj))) {
158-
const startable = obj as Startable
159-
160-
if (startable.beforeStop != null) {
161-
await startable.beforeStop()
162-
}
163-
}
157+
await Promise.all(
158+
Object.values(this).filter(obj => isStartable(obj)).map(async (startable: Startable) => {
159+
if (startable.beforeStop != null) {
160+
await startable.beforeStop()
161+
}
162+
})
163+
)
164164
}
165165

166166
async stop () {
167-
for (const obj of Object.values(this).filter(obj => isStartable(obj))) {
168-
const startable = obj as Startable
169-
170-
await startable.stop()
171-
}
167+
await Promise.all(
168+
Object.values(this).filter(obj => isStartable(obj)).map(async (startable: Startable) => {
169+
await startable.stop()
170+
})
171+
)
172172

173173
this.started = false
174174
}
175175

176176
async afterStop () {
177-
for (const obj of Object.values(this).filter(obj => isStartable(obj))) {
178-
const startable = obj as Startable
179-
180-
if (startable.afterStop != null) {
181-
await startable.afterStop()
182-
}
183-
}
177+
await Promise.all(
178+
Object.values(this).filter(obj => isStartable(obj)).map(async (startable: Startable) => {
179+
if (startable.afterStop != null) {
180+
await startable.afterStop()
181+
}
182+
})
183+
)
184184
}
185185

186186
setPeerId (peerId: PeerId) {

packages/libp2p-interfaces/src/connection-manager/index.ts

-55
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,6 @@
11
import type { AbortOptions, EventEmitter } from '../index.js'
22
import type { Connection } from '../connection/index.js'
33
import type { PeerId } from '../peer-id/index.js'
4-
import type { AddressSorter } from '../peer-store/index.js'
5-
import type { Resolver } from '@multiformats/multiaddr'
6-
7-
export interface ConnectionManagerInit {
8-
/**
9-
* If true, try to connect to all discovered peers up to the connection manager limit
10-
*/
11-
autoDial?: boolean
12-
13-
/**
14-
* The maximum number of connections to keep open
15-
*/
16-
maxConnections: number
17-
18-
/**
19-
* The minimum number of connections to keep open
20-
*/
21-
minConnections: number
22-
23-
/**
24-
* How long to wait between attempting to keep our number of concurrent connections
25-
* above minConnections
26-
*/
27-
autoDialInterval: number
28-
29-
/**
30-
* Sort the known addresses of a peer before trying to dial
31-
*/
32-
addressSorter?: AddressSorter
33-
34-
/**
35-
* Number of max concurrent dials
36-
*/
37-
maxParallelDials?: number
38-
39-
/**
40-
* Number of max addresses to dial for a given peer
41-
*/
42-
maxAddrsToDial?: number
43-
44-
/**
45-
* How long a dial attempt is allowed to take
46-
*/
47-
dialTimeout?: number
48-
49-
/**
50-
* Number of max concurrent dials per peer
51-
*/
52-
maxDialsPerPeer?: number
53-
54-
/**
55-
* Multiaddr resolvers to use when dialing
56-
*/
57-
resolvers?: Record<string, Resolver>
58-
}
594

605
export interface ConnectionManagerEvents {
616
'peer:connect': CustomEvent<Connection>

0 commit comments

Comments
 (0)