fires

ConnectionManager#peer:connect Emitted when a new peer is connected.

fires

ConnectionManager#peer:disconnect Emitted when a peer is disconnected.

Hierarchy

  • EventEmitter
    • ConnectionManager

Index

References

Connection

Re-exports Connection

ConnectionManagerOptions

Re-exports ConnectionManagerOptions

Libp2p

Re-exports Libp2p

Constructors

constructor

Properties

Private _autoDial

_autoDial: any

Proactively tries to connect to known peers stored in the PeerStore. It will keep the number of connections below the upper limit and sort the peers to connect based on wether we know their keys and protocols.

async

_autoDialTimeout

_autoDialTimeout: any

Private _checkMaxLimit

_checkMaxLimit: any

If the value of name has exceeded its limit, maybe close a connection

param

The name of the field to check limits for

param

The current value of the field

Private _checkMetrics

_checkMetrics: any

Checks the libp2p metrics to determine if any values have exceeded the configured maximums.

_latencyMonitor

_latencyMonitor: LatencyMonitor | undefined

_libp2p

_libp2p: Libp2p

Private _maybeDisconnectOne

_maybeDisconnectOne: any

If we have more connections than our maximum, close a connection to the lowest valued peer.

Private _onLatencyMeasure

_onLatencyMeasure: any

If the event loop is slow, maybe close a connection

param

The LatencyMonitor summary

_options

_options: any

_peerId

_peerId: string

_peerValues

_peerValues: Map<string, number>

Map of peer identifiers to their peer value for pruning connections.

_started

_started: boolean

_timer

_timer: any

connections

connections: Map<string, Connection[]>

Map of connections per peer

Static defaultMaxListeners

defaultMaxListeners: number

Static Readonly errorMonitor

errorMonitor: unique symbol

This symbol shall be used to install a listener for only monitoring 'error' events. Listeners installed using this symbol are called before the regular 'error' listeners are called.

Installing a listener using this symbol does not change the behavior once an 'error' event is emitted, therefore the process will still crash if no regular 'error' listener is installed.

Accessors

size

  • get size(): number
  • Get current number of open connections.

    Returns number

Methods

_close

  • _close(): Promise<void>
  • Cleans up the connections

    async

    Returns Promise<void>

addListener

  • addListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

emit

  • emit(event: string | symbol, ...args: any[]): boolean
  • Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

eventNames

  • eventNames(): Array<string | symbol>

get

  • Get a connection with a peer.

    Parameters

    Returns Connection | null

getAll

  • Get all open connections with a peer.

    Parameters

    Returns Connection[]

getMaxListeners

  • getMaxListeners(): number

listenerCount

  • listenerCount(event: string | symbol): number

listeners

  • listeners(event: string | symbol): Function[]

off

  • off(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

on

  • on(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

onConnect

  • Tracks the incoming connection and check the connection limit

    Parameters

    Returns void

onDisconnect

  • Removes the connection from tracking

    Parameters

    Returns void

once

  • once(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependListener

  • prependListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependOnceListener

  • prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

rawListeners

  • rawListeners(event: string | symbol): Function[]

removeAllListeners

  • removeAllListeners(event?: string | symbol): this

removeListener

  • removeListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

setMaxListeners

  • setMaxListeners(n: number): this

setPeerValue

  • setPeerValue(peerId: PeerId, value: number): void
  • Sets the value of the given peer. Peers with lower values will be disconnected first.

    Parameters

    • peerId: PeerId
    • value: number

      A number between 0 and 1

    Returns void

start

  • start(): void
  • Starts the Connection Manager. If Metrics are not enabled on libp2p only event loop and connection limits will be monitored.

    Returns void

stop

  • stop(): Promise<void>
  • Stops the Connection Manager

    async

    Returns Promise<void>

Static listenerCount

  • listenerCount(emitter: EventEmitter, event: string | symbol): number
  • deprecated

    since v4.0.0

    Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number