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

feat: add peer:prune event to connection manager #367

Merged
merged 1 commit into from
Apr 11, 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
20 changes: 18 additions & 2 deletions packages/interface-connection-manager/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { Multiaddr } from '@multiformats/multiaddr'

export interface ConnectionManagerEvents {
/**
* This event will be triggered anytime a new Connection is established to another peer.
* This event will be triggered any time a new Connection is established to another peer.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently anytime is an adverb 😉

*
* @example
*
Expand All @@ -20,7 +20,7 @@ export interface ConnectionManagerEvents {
'peer:connect': CustomEvent<Connection>

/**
* This event will be triggered anytime we are disconnected from another peer, regardless of
* This event will be triggered any time we are disconnected from another peer, regardless of
* the circumstances of that disconnection. If we happen to have multiple connections to a
* peer, this event will **only** be triggered when the last connection is closed.
*
Expand All @@ -34,6 +34,22 @@ export interface ConnectionManagerEvents {
* ```
*/
'peer:disconnect': CustomEvent<Connection>

/**
* This event will be triggered when the connection manager has more connections than the
* configured limit. The event detail contains the list of PeerIds from the connections
* that were closed to bring the node back under the max connections limit.
*
* @example
*
* ```js
* libp2p.connectionManager.addEventListener('peer:prune', (event) => {
* const connection = event.detail
* // ...
* })
* ```
*/
'peer:prune': CustomEvent<PeerId[]>
}

export interface ConnectionManager extends EventEmitter<ConnectionManagerEvents> {
Expand Down