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

Commit 973263f

Browse files
authored
feat: expose dial queue inspection method (#374)
1 parent 18c5622 commit 973263f

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

packages/interface-libp2p/src/index.ts

+42
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,35 @@ export interface LookupFunction {
8484
(key: string): Promise<Uint8Array | null>
8585
}
8686

87+
export type PendingDialStatus = 'queued' | 'active' | 'error' | 'success'
88+
89+
/**
90+
* An item in the dial queue
91+
*/
92+
export interface PendingDial {
93+
/**
94+
* A unique identifier for this dial
95+
*/
96+
id: string
97+
98+
/**
99+
* The current status of the dial
100+
*/
101+
status: PendingDialStatus
102+
103+
/**
104+
* If known, this is the peer id that libp2p expects to be dialling
105+
*/
106+
peerId?: PeerId
107+
108+
/**
109+
* The list of multiaddrs that will be dialled. The returned connection will
110+
* use the first address that succeeds, all other dials part of this pending
111+
* dial will be cancelled.
112+
*/
113+
multiaddrs: Multiaddr[]
114+
}
115+
87116
/**
88117
* Libp2p nodes implement this interface.
89118
*/
@@ -323,6 +352,19 @@ export interface Libp2p extends Startable, EventEmitter<Libp2pEvents> {
323352
*/
324353
getConnections: (peerId?: PeerId) => Connection[]
325354

355+
/**
356+
* Return the list of dials currently in progress or queued to start
357+
*
358+
* @example
359+
*
360+
* ```js
361+
* for (const pendingDial of libp2p.getDialQueue()) {
362+
* console.log(pendingDial)
363+
* }
364+
* ```
365+
*/
366+
getDialQueue: () => PendingDial[]
367+
326368
/**
327369
* Return a list of all peers we currently have a connection open to
328370
*/

0 commit comments

Comments
 (0)