Hierarchy

Implements

Constructors

Properties

#private: any
configuredPubsubTopics: string[]
currentActiveParallelDialCount: number = 0
dialAttemptsForPeer: Map<string, number> = ...
dialErrorsForPeer: Map<string, any> = ...
isP2PNetworkConnected: boolean = false
keepAliveManager: KeepAliveManager
libp2p: Libp2p
onEventHandlers: {
    browser:network: (() => void);
    peer:connect: ((evt) => void);
    peer:disconnect: ((evt) => void);
    peer:discovery: ((evt) => void);
} = ...

Type declaration

  • browser:network: (() => void)
      • (): void
      • Returns void

  • peer:connect: ((evt) => void)
      • (evt): void
      • Parameters

        • evt: CustomEvent<PeerId>

        Returns void

  • peer:disconnect: ((evt) => void)
      • (evt): void
      • Parameters

        • evt: CustomEvent<PeerId>

        Returns void

  • peer:discovery: ((evt) => void)
      • (evt): void
      • Parameters

        • evt: CustomEvent<PeerInfo>

        Returns void

pendingPeerDialQueue: PeerId[] = []
instances: Map<string, ConnectionManager> = ...

Methods

  • Attempts to establish a connection with a peer and set up specified protocols. The method handles both PeerId and Multiaddr inputs, manages connection attempts, and maintains the connection state.

    The dialing process includes:

    1. Converting input to dialable peer info
    2. Managing parallel dial attempts
    3. Attempting to establish protocol-specific connections
    4. Handling connection failures and retries
    5. Updating the peer store and connection state

    Parameters

    • peer: PeerId | MultiaddrInput

      The peer to connect to, either as a PeerId or multiaddr

    Returns Promise<Connection>

    Throws

    If the multiaddr is missing a peer ID

    Throws

    If the maximum dial attempts are reached and the peer cannot be dialed

    Throws

    If there's an error deleting an undialable peer from the peer store

    Example

    // Dial using PeerId
    await connectionManager.dialPeer(peerId);

    // Dial using multiaddr with specific protocols
    await connectionManager.dialPeer(multiaddr, [
    "/vac/waku/relay/2.0.0",
    "/vac/waku/lightpush/2.0.0-beta1"
    ]);

    Remarks

    • The method implements exponential backoff through multiple dial attempts
    • Maintains a queue for parallel dial attempts (limited by maxParallelDials)
    • Integrates with the KeepAliveManager for connection maintenance
    • Updates the peer store and connection state after successful/failed attempts
    • If all dial attempts fail, triggers DNS discovery as a fallback
  • Parameters

    • event: Event

    Returns boolean

  • Internal

    Internal utility to extract a PeerId or Multiaddr from a peer input. This is used internally by the connection manager to handle different peer input formats.

    Parameters

    • peer: PeerId | MultiaddrInput

    Returns PeerId | Multiaddr

  • Checks if the peer is dialable based on the following conditions:

    1. If the peer is a bootstrap peer, it is only dialable if the number of current bootstrap connections is less than the max allowed.
    2. If the peer is not a bootstrap peer

    Parameters

    • peerId: PeerId

    Returns Promise<boolean>

  • Parameters

    • type: string

    Returns number

  • Dial a peer with specific protocols. This method is a raw proxy to the libp2p dialProtocol method.

    Parameters

    • peer: PeerId | MultiaddrInput

      The peer to connect to, either as a PeerId or multiaddr

    • protocolCodecs: string[]

      Optional array of protocol-specific codec strings to establish

    Returns Promise<Stream>

    A stream to the peer

  • Type Parameters

    • Detail

    Parameters

    Returns boolean

  • Checks if the peer should be dialed based on the following conditions:

    1. If the peer is already connected, don't dial
    2. If the peer is not part of any of the configured pubsub topics, don't dial
    3. If the peer is not dialable based on bootstrap status, don't dial
    4. If the peer is already has an active dial attempt, or has been dialed before, don't dial it

    Parameters

    • peerId: PeerId

    Returns Promise<boolean>

    true if the peer should be dialed, false otherwise