Documentation
    Preparing search index...

    Interface IConnectionManager

    interface IConnectionManager {
        dial(
            peer: PeerId | MultiaddrInput,
            protocolCodecs: string[],
        ): Promise<Stream>;
        getConnectedPeers(codec?: string): Promise<Peer[]>;
        hangUp(peer: PeerId | MultiaddrInput): Promise<boolean>;
        hasShardInfo(peerId: PeerId): Promise<boolean>;
        isPeerOnShard(peerId: PeerId, shardId: number): Promise<boolean>;
        isPeerOnTopic(peerId: PeerId, pubsubTopic: string): Promise<boolean>;
        start(): void;
        stop(): void;
    }

    Implemented by

    Index

    Methods

    • Connects to a peer using specific protocol codecs. This is a direct proxy to libp2p's dialProtocol method.

      Parameters

      • peer: PeerId | MultiaddrInput

        The peer to connect to (PeerId or multiaddr)

      • protocolCodecs: string[]

        Array of protocol codec strings to establish

      Returns Promise<Stream>

      Promise resolving to a Stream connection to the peer

      Error if the connection cannot be established

      const stream = await connectionManager.dial(
      peerId,
      ["/vac/waku/store/2.0.0-beta4"]
      );
    • Retrieves a list of currently connected peers, optionally filtered by protocol codec. Results are sorted by ping time (lowest first).

      Parameters

      • Optionalcodec: string

        Optional protocol codec to filter peers by

      Returns Promise<Peer[]>

      Promise resolving to an array of connected Peer objects

      // Get all connected peers
      const allPeers = await connectionManager.getConnectedPeers();

      // Get peers supporting a specific protocol
      const storePeers = await connectionManager.getConnectedPeers(
      "/vac/waku/store/2.0.0-beta4"
      );
    • Terminates the connection to a specific peer.

      Parameters

      • peer: PeerId | MultiaddrInput

        The peer to disconnect from (PeerId or multiaddr)

      Returns Promise<boolean>

      Promise resolving to true if disconnection was successful, false otherwise

      const success = await connectionManager.hangUp(peerId);
      if (success) {
      console.log("Peer disconnected successfully");
      }
    • Checks if a peer has shard info.

      Parameters

      • peerId: PeerId

        The peer to check

      Returns Promise<boolean>

      Promise resolving to true if the peer has shard info, false otherwise

    • Returns true if the passed peer is on the passed pubsub topic

      Parameters

      • peerId: PeerId
      • pubsubTopic: string

      Returns Promise<boolean>

    • Starts network monitoring, dialing discovered peers, keep-alive management, and connection limiting.

      Returns void

      const connectionManager = new ConnectionManager(options);
      connectionManager.start();