Documentation
    Preparing search index...

    Platform-agnostic libp2p transport for peerkit.

    Owns the protocol logic (access handshake, agents, messages) on top of a caller-supplied Libp2p instance. Platform-specific packages (e.g. @peerkit/transport-libp2p-nodejs) build the libp2p instance with the appropriate transports/services and pass it in.

    Implements

    Index

    Constructors

    Methods

    • Establish a connection to a known peer by its full address.

      If the connection is routed through a relay, the address must include the relay address.

      Parameters

      • nodeAddress: string

        The dialable address of the node to connect to

      Returns Promise<void>

    • Connect to a list of relay addresses in parallel. Failures are logged but do not throw. On success, ConnectedToRelayCallback fires once the dialable relay-circuit address has been received.

      Fire-and-forget. Platform factories typically call this during bootstrap.

      Parameters

      • relays: string[]

      Returns Promise<void>

    • Create a new bi-directional byte stream on an open connection.

      Allows for reusing an open connection for exchaning any kind of data, e.g. audio or video data.

      Parameters

      • nodeId: string

        The node ID of the connection to create a stream for

      • protocol: string

        The name and version of the stream protocol

      Returns Promise<IStream>

    • Disconnect from the peer.

      Parameters

      • nodeId: string

        The node ID to disconnect from

      Returns Promise<void>

    • Return the transport's actual dial addresses after startup.

      Each string is a fully-qualified address that peers can use to connect, including the node's identity suffix where the transport requires it.

      Use this to obtain the relay's dial address rather than constructing it from config.

      Returns string[]

    • Is there an active connection to the provided node?

      Parameters

      • nodeId: string

        The node ID to check

      Returns boolean

    • Is the connection to the provided node a direct connection?

      false means the connection is relayed.

      Parameters

      • nodeId: string

        The node ID of the connection to check

      Returns boolean

    • Register a handler for incoming streams on the given protocol.

      The handler is called once per incoming stream, after the access check has passed. Can be called after transport construction.

      Parameters

      • protocol: string

        The protocol identifier to handle

      • handler: CustomStreamCreatedCallback

        Called with the initiating peer's NodeId and the stream

      Returns void

    • Send an opaque application message to a peer. The peer must be connected and have been granted access.

      Parameters

      • nodeId: string

        The ID of the target node

      • data: Uint8Array

        The message to send to the node

      Returns Promise<void>

    • Send opaque agent-info bytes to a peer. The peer must be connected and have been granted access.

      Parameters

      • nodeId: string

        The ID of the target node

      • data: Uint8Array

        The list of agents to send to the node

      Returns Promise<void>