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

feat: expose dial queue inspection method #374

Merged
merged 1 commit into from
Apr 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions packages/interface-libp2p/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,35 @@ export interface LookupFunction {
(key: string): Promise<Uint8Array | null>
}

export type PendingDialStatus = 'queued' | 'active' | 'error' | 'success'

/**
* An item in the dial queue
*/
export interface PendingDial {
/**
* A unique identifier for this dial
*/
id: string

/**
* The current status of the dial
*/
status: PendingDialStatus

/**
* If known, this is the peer id that libp2p expects to be dialling
*/
peerId?: PeerId

/**
* The list of multiaddrs that will be dialled. The returned connection will
* use the first address that succeeds, all other dials part of this pending
* dial will be cancelled.
*/
multiaddrs: Multiaddr[]
}

/**
* Libp2p nodes implement this interface.
*/
Expand Down Expand Up @@ -323,6 +352,19 @@ export interface Libp2p extends Startable, EventEmitter<Libp2pEvents> {
*/
getConnections: (peerId?: PeerId) => Connection[]

/**
* Return the list of dials currently in progress or queued to start
*
* @example
*
* ```js
* for (const pendingDial of libp2p.getDialQueue()) {
* console.log(pendingDial)
* }
* ```
*/
getDialQueue: () => PendingDial[]

/**
* Return a list of all peers we currently have a connection open to
*/
Expand Down